From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id A4D36385782C for ; Wed, 18 May 2022 08:43:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4D36385782C Received: by mail-wm1-x32b.google.com with SMTP id bd25-20020a05600c1f1900b0039485220e16so2197349wmb.0 for ; Wed, 18 May 2022 01:43:12 -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=OHE6zPkOxnm6I5JnKfbqY2qFCdMNP1G4at6RJsXzSMg=; b=txKysCqsKSopvHEtMW3IhyiPkZlPuDnwY2fWWdUTCpy1BVXlwBVTWZNgztcGksMhl3 KbUgXYSAlknYDFmTtiYbqWgVWmY6MKuJWyog5g9CocrSIT3xPWzry5NlZShD2O7PZxUq tC9CKikdYfvRs2PlwhcHesEcXxgBcTbnY31SC29GI+/bvvHg2cxEScbmA2wED1t1JKJP PNI2gCkm3AM1MccZQU3T323ruK1BGKwxc/DlzkBatrVk6LeeKDNWEDGhzuxDc28xpiUy FugbMLLhN7WzphNTSTczicKcqjfQymOSxX7TlAZpeH4ZhYoGjIssoCrKszGZKPbkkOg3 2Org== X-Gm-Message-State: AOAM531R+F04WMhty5i2cUhPZ7CpEduGUOJoXT8eSOsXKWPM0qYDTYEl oI2TQGuZdyTmE29LOUXpzg1QJmXsfeHveQ== X-Google-Smtp-Source: ABdhPJyzT5sLgnMJ4JsJCo3HC/zRTyzbz38f+HcygNw5n63ldRIBn9kUBnNwvl8G8v75HBlZJyrfPg== X-Received: by 2002:a7b:cb48:0:b0:394:b64:8b88 with SMTP id v8-20020a7bcb48000000b003940b648b88mr35161005wmj.183.1652863391438; Wed, 18 May 2022 01:43:11 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id n7-20020adfc607000000b0020c6a524fe0sm1308830wrg.98.2022.05.18.01.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 01:43:10 -0700 (PDT) Date: Wed, 18 May 2022 08:43:10 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Rework optimization skipping pragma check in object declaration Message-ID: <20220518084310.GA3318962@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="RnlQjJ0d97Da+TV1" 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-List-Received-Date: Wed, 18 May 2022 08:43:14 -0000 --RnlQjJ0d97Da+TV1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline When an object declaration is initialized with a type conversion: Var : Typ := Typ (Value); we skip the check for Typ's predicate as it is already checked during the type conversion. This is not correct when Var's subtype and the target subtype of the conversion do not statically match: Var : Typ := OtherTyp (Value); In such case, we can't skip the check of Typ's predicate. Fix minor typos in comment. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch3.adb (Analyze_Object_Declaration): Skip predicate check for type conversion if object's subtype and expression's subtype statically match. * exp_prag.adb (Expand_Pragma_Check): Typo fix in comment. --RnlQjJ0d97Da+TV1 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" 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 @@ -285,7 +285,7 @@ package body Exp_Prag is -- expression is not usually the best choice here, because it points to -- the location of the topmost tree node, which may be an operator in -- the middle of the source text of the expression. For example, it gets - -- located on the last AND keyword in a chain of boolean expressiond + -- located on the last AND keyword in a chain of boolean expressions -- AND'ed together. It is best to put the message on the first character -- of the condition, which is the effect of the First_Node call here. -- This source location is used to build the default exception message, diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -4572,11 +4572,15 @@ package body Sem_Ch3 is null; -- Do not generate a predicate check if the initialization expression - -- is a type conversion because the conversion has been subjected to - -- the same check. This is a small optimization which avoid redundant + -- is a type conversion whose target subtype statically matches the + -- object's subtype because the conversion has been subjected to the + -- same check. This is a small optimization which avoids redundant -- checks. - elsif Present (E) and then Nkind (E) = N_Type_Conversion then + elsif Present (E) + and then Nkind (E) in N_Type_Conversion + and then Subtypes_Statically_Match (Etype (Subtype_Mark (E)), T) + then null; else --RnlQjJ0d97Da+TV1--