From patchwork Fri Jan 7 16:27:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 49713 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A96473857C40 for ; Fri, 7 Jan 2022 16:46:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A96473857C40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641573993; bh=qro+afcM7m+nZI3gl7ZCdv40LYFKwH+9BNUVmXb7+a4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kTdPjNDbVehZLg2Fr4n2ei4tgkqxzjU1VMAWRN3S/eTH6j+2Oatp1mpj03s3zCXPF f48MhI5d72MHd5a3Usf3FaYa0CI9RAn1cIMBLdxVvvKCJ3hna2kFCNF3IcCNErz1yc DNa6j8cSij7URTXNWK9fLLzh/EinEWGc9nPyX6m8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id B3FA93857C62 for ; Fri, 7 Jan 2022 16:27:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B3FA93857C62 Received: by mail-wm1-x32d.google.com with SMTP id q141-20020a1ca793000000b00347b48dfb53so1122218wme.0 for ; Fri, 07 Jan 2022 08:27:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=qro+afcM7m+nZI3gl7ZCdv40LYFKwH+9BNUVmXb7+a4=; b=hUhrOcb3+pz3UckDsR/69066mpZ4DEskXTC7wBdzEs4OlY+I0KyaA36LO8H9yUTRy3 11NWIqjI38phLYW538hfPAXeCxxCs5fyq3F/YTr6gTOnBbTfBetD9ATsq0Hv9Uekzjds VHqWjB4a65XoqwDEj7X5B2ywOijPI2cMkkqCKoW+glkdlmrPvbThwAAL2L49CwPi6Jzq 3ZEbo7C0HvFrmeVIUyJSsW/Gzbu0gYVj/UieYeDiavCrW1zeT4SAB3IqR5S5hhcXAEJE g9r4NRFl4/4YFYO0laZrC/VgkNerXwS0/TqBMA8VPc8zEaQbs04+pO+22yJpgcXdNt14 G74Q== X-Gm-Message-State: AOAM531krPKeV1x8UenaJ4lTRFrfOlO7cmkWhmF83lfvY7j0KGz0PK2k 2uhcayTER7XM9T2ZDsDm84v+cYy49oaIPQ== X-Google-Smtp-Source: ABdhPJzj1Pewv4Jt/kdz5XaWzin3iquFcloEv80cnmEPrP1a9dJR+QBj5jfng9gB2y5/f78bDh0fZg== X-Received: by 2002:a7b:cb44:: with SMTP id v4mr11794151wmj.20.1641572836782; Fri, 07 Jan 2022 08:27:16 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id y8sm6394449wma.19.2022.01.07.08.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 08:27:16 -0800 (PST) Date: Fri, 7 Jan 2022 16:27:15 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix a couple of issues with pragma Inspection_Point Message-ID: <20220107162715.GA948628@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Eric Botcazou Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The first issue is that the pragma may require the address of the objects subject to it to have their address taken, like Asm_Input and Asm_Output, so these objects need to be specifically marked. The second issue is that the detection of unfrozen objects was not robust enough and would miss objects that are explicit arguments of the pragma. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_prag.adb (Expand_Pragma_Inspection_Point): Do a single pass over the arguments of the pragma. Set the Address_Taken flag on them and use the Has_Delayed_Freeze flag to spot those which have their elaboration delayed. Reuse the location variable Loc. diff --git a/gcc/ada/exp_prag.adb b/gcc/ada/exp_prag.adb --- a/gcc/ada/exp_prag.adb +++ b/gcc/ada/exp_prag.adb @@ -2354,12 +2354,13 @@ package body Exp_Prag is procedure Expand_Pragma_Inspection_Point (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); + A : List_Id; Assoc : Node_Id; - S : Entity_Id; E : Entity_Id; + Rip : Boolean; + S : Entity_Id; - Remove_Inspection_Point : Boolean := False; begin if No (Pragma_Argument_Associations (N)) then A := New_List; @@ -2389,45 +2390,47 @@ package body Exp_Prag is Set_Pragma_Argument_Associations (N, A); end if; - -- Expand the arguments of the pragma. Expanding an entity reference - -- is a noop, except in a protected operation, where a reference may - -- have to be transformed into a reference to the corresponding prival. - -- Are there other pragmas that may require this ??? + -- Process the arguments of the pragma and expand them. Expanding an + -- entity reference is a noop, except in a protected operation, where + -- a reference may have to be transformed into a reference to the + -- corresponding prival. Are there other pragmas that require this ??? + Rip := False; Assoc := First (Pragma_Argument_Associations (N)); while Present (Assoc) loop - Expand (Expression (Assoc)); - Next (Assoc); - end loop; + -- The back end may need to take the address of the object - -- If any of the references have a freeze node, it must appear before - -- pragma Inspection_Point, otherwise the entity won't be available when - -- Gigi processes Inspection_Point. - -- When this requirement isn't met, turn the pragma into a no-op. + Set_Address_Taken (Entity (Expression (Assoc))); - Assoc := First (Pragma_Argument_Associations (N)); - while Present (Assoc) loop + Expand (Expression (Assoc)); + + -- If any of the objects have a freeze node, it must appear before + -- pragma Inspection_Point, otherwise the entity won't be elaborated + -- when Gigi processes the pragma. - if Present (Freeze_Node (Entity (Expression (Assoc)))) and then - not Is_Frozen (Entity (Expression (Assoc))) + if Has_Delayed_Freeze (Entity (Expression (Assoc))) + and then not Is_Frozen (Entity (Expression (Assoc))) then - Error_Msg_NE ("??inspection point references unfrozen object &", - Assoc, - Entity (Expression (Assoc))); - Remove_Inspection_Point := True; + Error_Msg_NE + ("??inspection point references unfrozen object &", + Assoc, + Entity (Expression (Assoc))); + Rip := True; end if; Next (Assoc); end loop; - if Remove_Inspection_Point then + -- When the above requirement isn't met, turn the pragma into a no-op + + if Rip then Error_Msg_N ("\pragma will be ignored", N); -- We can't just remove the pragma from the tree as it might be -- iterated over by the caller. Turn it into a null statement -- instead. - Rewrite (N, Make_Null_Statement (Sloc (N))); + Rewrite (N, Make_Null_Statement (Loc)); end if; end Expand_Pragma_Inspection_Point;