From patchwork Wed May 18 08:43:10 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: 1632663 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=GBhGhMo4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4L36FW4TRYz9s2R for ; Wed, 18 May 2022 18:52:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C33EC385781D for ; Wed, 18 May 2022 08:52:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C33EC385781D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652863964; bh=OHE6zPkOxnm6I5JnKfbqY2qFCdMNP1G4at6RJsXzSMg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=GBhGhMo40gaHGuicAB7hOO1htj0hUauhcVDKf1vTpqo7ONZVE+/SGV+UY6uuQbuH0 amobh6x2SvzcDx5Y9HiCj7VLqzBlGpH3RJN6qAytmTggd1KRDh0MU7D0eSImH8+AKV N+4fn9Qe0DtLYStFCwko55Lv105xcxoczaty1nYo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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-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 Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. 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