From patchwork Tue May 17 08:27:27 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: 1632108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=UhZFaXvR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L2Tn21mQBz9s0r for ; Tue, 17 May 2022 18:29:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71A863857C50 for ; Tue, 17 May 2022 08:29:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71A863857C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652776163; bh=g3nCPWyV6JPKjnYtBS9k9YPwtMfHSjuyoqjv75ONljE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=UhZFaXvRXdxYYYpAXJyJmbbzL+rhuXzIQTGQ0wmgVaUrWIbfJXzqVcveQ6VYNzxoZ TnlEaRrr8MTAJ/TyVQ2/jcTnf9RexBN4fwUBBupyPYrJggzncEp6keCwIc0XDZlCpP Qsoj2vsc2e/TwW60npMRW+MuWn418f4YcRX16Jyg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 6D2073857822 for ; Tue, 17 May 2022 08:27:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D2073857822 Received: by mail-wr1-x435.google.com with SMTP id j25so22641038wrc.9 for ; Tue, 17 May 2022 01:27:29 -0700 (PDT) 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=g3nCPWyV6JPKjnYtBS9k9YPwtMfHSjuyoqjv75ONljE=; b=Myc8suv9CejG/g2BEavQXAnj1dgI+DbOeCwoGajj51Bb2NprKLe++lDSfgn7YDMIIl G3Nq+04KtGSz6ZeGFGm2N6viuQW36o5QqYoofA1EJmq5KhCHlYsxMpbmIr/YyvFCLdQX 7AEZZ+0vo7I29TYi+PIrxA6sLPQSKxNRmK9xOmzry1Rt8C3Z3yK6+ZGqhPGn+j/S7KSp 3e0NtJKtfEmwC2HzWTx2YnUw2wQ0caXQMt5Hr/5Q5FussczVTEdcaFlB1bN17RX6q4Jm Fyif5aDuiaTVeLOaLcLRNreFk9sddOlSy1mVLjd5+5nQwYQRWjXWvc++7EGJqRGZ1K4A 8sIg== X-Gm-Message-State: AOAM533lmMeqoqo+0++1VybNfp1E0lR7A9ScyfYqQajFL/44gR1+15Om hPdPC8R6akwwfQpQLu2VMd4j1H3f4sDGPmpb X-Google-Smtp-Source: ABdhPJyoRg6zs3Fe5VNM8qE7l20YS99rLFvvhWBKaXy4JX0vJxFjpAuyi/KfkMTl+qejP18I3tNVCQ== X-Received: by 2002:adf:dc4d:0:b0:20d:2a1:553e with SMTP id m13-20020adfdc4d000000b0020d02a1553emr10441258wrj.636.1652776048143; Tue, 17 May 2022 01:27:28 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id l4-20020a05600c47c400b003942a244ec1sm1248057wmo.6.2022.05.17.01.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:27:27 -0700 (PDT) Date: Tue, 17 May 2022 08:27:27 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Enable current value propagation within pragma expressions Message-ID: <20220517082727.GA1087192@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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Piotr Trojanek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch fixes an odd incomplete optimization within pragma expressions. For example, in this code: X := True; pragma Assert (X = True); pragma Assert (X); the first assertion was eliminated by the frontend (regardless of the optimization switches), while the second assertion was only eliminated by the backend and only with switch -O1 or similar. The problem was that the current value propagation was disabled for references immediately within pragma argument associations. This was meant to avoid a crash when such a reference appears in pragma Inspection_Point, but this wasn't a proper fix. The proper solution is rather to not expand references in pragma Inspection_Point at all. Actually, this expansion was enabled to avoid a yet another crash, when the parameter of pragma Inspection_Point is a prival (i.e. a renaming of private protected component). It turns out that none of these suspicious problematic fixes is no longer necessary. Cleanup related to fixes of current value propagation in expansion of attribute Loop_Entry. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch2.adb (Expand_Current_Value): Remove special case for references immediately within pragma argument associations. * exp_prag.adb (Expand_Pragma_Inspection_Point): Remove special case for privals. diff --git a/gcc/ada/exp_ch2.adb b/gcc/ada/exp_ch2.adb --- a/gcc/ada/exp_ch2.adb +++ b/gcc/ada/exp_ch2.adb @@ -150,13 +150,6 @@ package body Exp_Ch2 is and then OK_To_Do_Constant_Replacement (E) - -- Do not replace occurrences in pragmas (where names typically - -- appear not as values, but as simply names. If there are cases - -- where values are required, it is only a very minor efficiency - -- issue that they do not get replaced when they could be). - - and then Nkind (Parent (N)) /= N_Pragma_Argument_Association - -- Do not replace the prefixes of attribute references, since this -- causes trouble with cases like 4'Size. Also for Name_Asm_Input and -- Name_Asm_Output, don't do replacement anywhere, since we can have 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 @@ -34,7 +34,6 @@ with Elists; use Elists; with Errout; use Errout; with Exp_Ch11; use Exp_Ch11; with Exp_Util; use Exp_Util; -with Expander; use Expander; with Inline; use Inline; with Lib; use Lib; with Namet; use Namet; @@ -2390,10 +2389,7 @@ package body Exp_Prag is Set_Pragma_Argument_Associations (N, A); end if; - -- 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 ??? + -- Process the arguments of the pragma Rip := False; Assoc := First (Pragma_Argument_Associations (N)); @@ -2402,8 +2398,6 @@ package body Exp_Prag is Set_Address_Taken (Entity (Expression (Assoc))); - 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.