From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 285393856DFC for ; Mon, 5 Sep 2022 07:26:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 285393856DFC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x42f.google.com with SMTP id t7so5044358wrm.10 for ; Mon, 05 Sep 2022 00:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date; bh=5ZBDOO1VoiZxqJWsqsDRzGqRK9DGGIYRcfJS/aMK1OA=; b=jI9Ef0LvMIqXPEuocZCDIwqDF7hdaUvU361bH9Sd7KirwLtQmi6fbfNq6YIs6LgJFp WX3rT+0NwSmTNg2gFJrX19QyVw3bTfO1jQKAT/W3zx47nzBYqGYE2XqNgMlHtrjUXpou D9ZxWJN3CkVdOcMByB3WtBIcK8v2xe+W90QH0XI6ENs8mdQbTyFCkdKkMvYK2kwic58r 5RD2LwJeNXgGl3KPAnvS/+lMXBQwE5CdJEFR/DvD01lYSJKzMdpTbuUHgly0/SOFyVxP earGaTocvB6YPSI264ThJ439pJQgBWUfuuLqzG11+A2+R2dmevELkFMV6SOzqs0mXyJk vjdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=5ZBDOO1VoiZxqJWsqsDRzGqRK9DGGIYRcfJS/aMK1OA=; b=k5dT3KqzZMlxDCnfMXi6uMGeawb8Th16DYSc0Y15BnIVGM9DQ8IQNB1Hv58Zg285w/ QeaIeRo4S+bHnGL0nqKqapP03TCdF/r/Gpw0tWP1ZRStfHydij84sMUIsUuXghOwZy4U NosVbEkXJndcsIsnAvyDJexaFqwzr8h25WEoUXxCsuR2vagVlwlKSXQNLvuUtfW9nNhX TBHFZJQSk18HqOYJD0wPIPvEl8zB217FaeOM/UHX19s33KIvQj9FYdLZl2EPD6QVWfpy 2IjfXlIwgom4v6KKJexhYJetNQN46/3f+d/LsW3Tm+5d2bqKNIUXLE1CO/872Vf6stAx QNHQ== X-Gm-Message-State: ACgBeo3uL39uGl8wphxgExL1ejJvSU8K4m55H8D1h9Z8fSVFxanFb67z 91HCSsMCDh2t/jLwY/yp0vtpb0iTx/+fng== X-Google-Smtp-Source: AA6agR69nrD97uVCzzK96kLnzV8VvWmjN2S3VlhJ+lDCeWB2jtQ4tuTYoj0/RBz2zariRmHDGTYuPg== X-Received: by 2002:adf:e199:0:b0:228:60f6:f775 with SMTP id az25-20020adfe199000000b0022860f6f775mr4777003wrb.478.1662362764998; Mon, 05 Sep 2022 00:26:04 -0700 (PDT) Received: from poulhies-Precision-5550 (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id i14-20020a05600c354e00b003a5dde32e4bsm16773910wmq.37.2022.09.05.00.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:26:04 -0700 (PDT) Date: Mon, 5 Sep 2022 09:26:03 +0200 From: Marc =?iso-8859-1?Q?Poulhi=E8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Suppress warnings in trivial subprograms with finalization Message-ID: <20220905072603.GA1174684@poulhies-Precision-5550> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="FCuugMFkClbJLl1L" Content-Disposition: inline X-Spam-Status: No, score=-12.5 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 List-Id: --FCuugMFkClbJLl1L Content-Type: text/plain; charset=us-ascii Content-Disposition: inline There are heuristics for suppressing warnings about unused objects in trivial cases. In particular, we try to suppress warnings here: function F (A : Integer) return Some_Type; X : Some_Type; begin raise Not_Yet_Implemented; return X; end F; But it doesn't work if Some_Type is controlled. This patch fixes that bug. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Use First_Real_Statement to deal with this case. Note that First_Real_Statement is likely to be removed as part of this ticket, so this is a temporary fix. --FCuugMFkClbJLl1L Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -5409,14 +5409,20 @@ package body Sem_Ch6 is -- we have a special test to set X as apparently assigned to suppress -- the warning. - declare - Stm : Node_Id; + -- If X above is controlled, we need to use First_Real_Statement to skip + -- generated finalization-related code. Otherwise (First_Real_Statement + -- is Empty), we just get the first statement. + declare + Stm : Node_Id := First_Real_Statement (HSS); begin + if No (Stm) then + Stm := First (Statements (HSS)); + end if; + -- Skip call markers installed by the ABE mechanism, labels, and -- Push_xxx_Error_Label to find the first real statement. - Stm := First (Statements (HSS)); while Nkind (Stm) in N_Call_Marker | N_Label | N_Push_xxx_Label loop Next (Stm); end loop; --FCuugMFkClbJLl1L--