From patchwork Tue Jun 2 08:45:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 136285 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 850414BA23CE for ; Tue, 2 Jun 2026 09:35:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 850414BA23CE Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Vkpm/kIk 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 0241D4BA2E32 for ; Tue, 2 Jun 2026 08:46:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0241D4BA2E32 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0241D4BA2E32 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780389998; cv=none; b=igJPAc5TCRLiYqKFHQFePNYJIezkq5Qe84Mvc7ygRGP26ehFAaYjfP2wtLJVeb2GjiDtnQKmwlPcz8qzdmZE+2a3PR1cyX8rkdj6vRTNwNdFv+DLxFeNhtdWT126gm9VnrQ16y//BS85LOU1GXgbG/Sk1wgEwHamhrHUBbSEpro= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780389998; c=relaxed/simple; bh=XcXPVTI2KDYM4ad+GX9tZntfkjdQgMfuMFkLvhmVIW4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=t5ls0RjxaqHh1+Kl2j43UN9UQUkrJAqqWDRmXyqWJKk1dXWVKgBrKPYyGvDXsNO6cPIZzWMGWK1One8ZWBXNZqCoyTDd8ObJBbHGr11YJXtV2hot4IHDt/Xc+jeT/bm/YF7eO911HwbYsAxww70H3wqQXln//Ykf2htE0InLFBw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Vkpm/kIk DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0241D4BA2E32 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4906238c62eso90274205e9.3 for ; Tue, 02 Jun 2026 01:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1780389997; x=1780994797; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=REgRCVfP5i/WcSI9G6vdOrkF5e9rMrhPlathKbxoPeQ=; b=Vkpm/kIkxS8WWp1t8CEorvcsbj6AtFS0wxQafqMdmFUYB8y4eJHLVntPGH9SRilhvE vwlf5+ns5yqG0+sc3aYPbhAoe+NyM3MroFb1En+lzDvIbRLX3aplWaKsuTKpsazWRKDy vOPccauBwcR1xZQEDW93IaDFiBjjmCrvNaBOEGeoXgmYEWwBBrFAyvu3W8rKzu23yts8 0Wl41md2toIVA5Erm1O9jDEToEOVqkN5uV3VnM6wSuhgO/8CFYqFkiUiEVMRC5y3YWgY kz0nk0ulyBiSOpvpicL3qRSk8HnBI/TJFmR0lWv7Deup71bCg7tjhEf23PPSwPBzD3XU 1OXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780389997; x=1780994797; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=REgRCVfP5i/WcSI9G6vdOrkF5e9rMrhPlathKbxoPeQ=; b=LFX5PoV8coi1UGTzXMqhQH9f4nfdmGzOwtY2gwv437VyAaverEOxgaohBUE8qoONAO hSmr9IX5zSJqUiaGzqie8t+LuMvH0qT70NIS+J6+2wbgJws6uWna4ggHmSONWOw/i6oE EvuCptMUSIbUBr+rhx7cd/PCrpTEVUv2i8TdSBJPl7mAt2/r+eZFt8E+JS3GdcCDlnwJ i2ttQaHvL0a7QpP0sO8TXJumP0IuazPJ/Ve3xclu5jrIb391JBlOXJBZLi5zjiXqdMEL itCy8LV8kCbkc1nq1Zz9Wev0mSrZGTmBwpyoNdx3eT3JQOxcPb+KvMEPsq6z6g+GTynD SuNQ== X-Gm-Message-State: AOJu0YwCbFQm96ty7ezmt74ou84EKd6cBUqstLPzm52LkNX0VDFcLuDV tx5QgcFrZ/vSkglCJIs1SLewr+BQF0n5PEDcfPfJJ+sfU1T3QkkzLIYl1NIhrKjIgeoeCM4KJKl kHKg= X-Gm-Gg: Acq92OGfFAz38SAi4f20rMEGOlDGnhTZPte5FWmpFinMlVdyEBPsIOlTZx7EKd1f/+j tnNbw2EJeMAsCrRZExUPXimTXlWN3gHlweEMnl5Lj2yxn1xRDTiWNjCn8QK3j8ynT0Tb2Qq3yx8 yNe2bQAB/V/vx1o7IzBLLTqPnrPs6sT1SWsgrsEEXdEX5vrcDC2nU0KioghUqZDCU+DV0C+bVr+ gbAoGn3ssLm/czNOnZuUIoL2MbrGJ8yAZm41JZQfwVUCKIZV7b8JLt1IbnvsABG4198n8oPWpih x8gF4PR/FAZH0BiMjlXcSW45yuL0mVWFJSxH4C1tzds64FuNFgQnCy/ssvAVd1htqxdsRpHImbt ha+/SiI76lcWDUST2Wt0NEMonwjq+iOJ3fwv8ZwsDr4notIXt0v7juv1O2ofP1dRISg2WGO0JWJ 2KspaiME2IOb7w8ED7j3sL8JF6HXLcn+1T8H5r7mXpc5I70gvzWPUh4Vicl8TiKIoANfHzjyEFo 8PM/iPC7IAYhh6D X-Received: by 2002:a05:600c:1988:b0:490:44eb:c1dd with SMTP id 5b1f17b1804b1-490a294fe9cmr251626765e9.29.1780389996863; Tue, 02 Jun 2026 01:46:36 -0700 (PDT) Received: from mecano.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490ab55d39csm33907625e9.35.2026.06.02.01.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:46:36 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?Marc_Poulhi=C3=A8s?= Subject: [COMMITTED 50/51] ada: Avoid definition of unused label for LOOP_STMT Date: Tue, 2 Jun 2026 10:45:38 +0200 Message-ID: <20260602084541.3829876-50-poulhies@adacore.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260602084541.3829876-1-poulhies@adacore.com> References: <20260602084541.3829876-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org The gimplification of LOOP_STMT has a systematic end label definition, that may be unused. For example, an endless loop maybe gimplified to: : # USE = anything # CLB = anything totoD.5747 (); goto ; : Later, the gimple_seq_may_fallthru() will decide that this block can fallthru as the last statement is a single label that may be jumped to from somewhere else. Only defining this label if we also emit jumps to it helps the compiler correctly decide if the block can fallthru or not. In particular, if a function, with a local object needing finalization and the No_Return aspect, is an endless loop then the spurious warning that the function is still returning is not emitted anymore. gcc/ada/ChangeLog: * gcc-interface/trans.cc (gnat_to_gnu) : Mark the label tree as used. (gnat_gimplify_stmt) : Do not emit end label definition in unused. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/trans.cc | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index 5140ed8bbfd..7df32d67ea9 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -7993,13 +7993,17 @@ gnat_to_gnu (Node_Id gnat_node) break; case N_Exit_Statement: - gnu_result - = build2 (EXIT_STMT, void_type_node, - (Present (Condition (gnat_node)) - ? gnat_to_gnu (Condition (gnat_node)) : NULL_TREE), - (Present (Name (gnat_node)) - ? get_gnu_tree (Entity (Name (gnat_node))) - : LOOP_STMT_LABEL (gnu_loop_stack->last ()->stmt))); + { + tree end_loop_label = Present (Name (gnat_node)) + ? get_gnu_tree (Entity (Name (gnat_node))) + : LOOP_STMT_LABEL (gnu_loop_stack->last ()->stmt); + gnu_result + = build2 (EXIT_STMT, void_type_node, + (Present (Condition (gnat_node)) + ? gnat_to_gnu (Condition (gnat_node)) : NULL_TREE), + end_loop_label); + TREE_USED (end_loop_label) = 1; + } break; case N_Simple_Return_Statement: @@ -9532,6 +9536,8 @@ gnat_gimplify_stmt (tree *stmt_p) gnu_cond = build3 (COND_EXPR, void_type_node, gnu_cond, NULL_TREE, build1 (GOTO_EXPR, void_type_node, gnu_end_label)); + + TREE_USED (gnu_end_label) = 1; } /* Set to emit the statements of the loop. */ @@ -9541,8 +9547,9 @@ gnat_gimplify_stmt (tree *stmt_p) end label if there's a top condition, then the update if it's at the top, then the body of the loop, then a conditional jump to the end label if there's a bottom condition, then the update if - it's at the bottom, and finally a jump to the start label and the - definition of the end label. */ + it's at the bottom, and finally a jump to the start label and if + there's a top or bottom condition, the definition of the end + label. */ append_to_statement_list (build1 (LABEL_EXPR, void_type_node, gnu_start_label), stmt_p); @@ -9565,9 +9572,10 @@ gnat_gimplify_stmt (tree *stmt_p) SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (gnu_end_label)); append_to_statement_list (t, stmt_p); - append_to_statement_list (build1 (LABEL_EXPR, void_type_node, - gnu_end_label), - stmt_p); + if (TREE_USED (gnu_end_label)) + append_to_statement_list (build1 (LABEL_EXPR, void_type_node, + gnu_end_label), + stmt_p); return GS_OK; }