From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 9C611383F21D for ; Tue, 13 Dec 2022 10:41:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9C611383F21D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id E33441FE4C for ; Tue, 13 Dec 2022 10:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1670928070; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Rzbz9K57ivsE/qcmtlga7MR90Q0BXADbGuNBK6ynzg0=; b=a1XncAIFEY8cHIfz9ntp7R/TtHPresWVEUPh88YjT8wNsQU3xeB6Th4tCqtEepVRXvxP4I 1I7TV0KYK5VMBPy+F7E2CaU8greNG8CremDQZYh6GGYN1MlvWbLnX+BIaAVbU/TEwtbRvp PZxVKHP6Sf8ggR+IdPT86t6TGZKeNts= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1670928070; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Rzbz9K57ivsE/qcmtlga7MR90Q0BXADbGuNBK6ynzg0=; b=mO/8ccdFYH8K+MOJbIyjY9VcLbESUrjGfKOKgme4xOK9w5xGyIqNu1pv6jSxHXe4AiainQ yP0L4XJZt6aJU3DA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id DE1262C141 for ; Tue, 13 Dec 2022 10:41:10 +0000 (UTC) Date: Tue, 13 Dec 2022 10:41:10 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/108076 - if-conversion and forced labels User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,MISSING_MID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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: Message-ID: <20221213104110.KsgFi9RLylex-_3okAnOmKe2yC5pTwyehQfkw66ExxU@z> When doing if-conversion we simply throw away labels without checking whether they are possibly targets of non-local gotos or have their address taken. The following rectifies this and refuses to if-convert such loops. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/108076 * tree-if-conv.cc (if_convertible_loop_p_1): Reject blocks with non-local or forced labels that we later remove labels from. * gcc.dg/torture/pr108076.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr108076.c | 17 +++++++++++++++++ gcc/tree-if-conv.cc | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr108076.c diff --git a/gcc/testsuite/gcc.dg/torture/pr108076.c b/gcc/testsuite/gcc.dg/torture/pr108076.c new file mode 100644 index 00000000000..ebe2e51bee0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108076.c @@ -0,0 +1,17 @@ +/* { dg-do link } */ + +static void *j; +int v, g; +__attribute__((__leaf__)) int atoi (const char *); + +int +main () +{ + j = &&lab1; + &&lab2; + atoi ("42"); +lab1: +lab2: + if (v) + goto *j; +} diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 64b20b4a9e1..0807201cefb 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -1433,10 +1433,20 @@ if_convertible_loop_p_1 (class loop *loop, vec *refs) basic_block bb = ifc_bbs[i]; gimple_stmt_iterator gsi; + bool may_have_nonlocal_labels + = bb_with_exit_edge_p (loop, bb) || bb == loop->latch; for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) switch (gimple_code (gsi_stmt (gsi))) { case GIMPLE_LABEL: + if (!may_have_nonlocal_labels) + { + tree label + = gimple_label_label (as_a (gsi_stmt (gsi))); + if (DECL_NONLOCAL (label) || FORCED_LABEL (label)) + return false; + } + /* Fallthru. */ case GIMPLE_ASSIGN: case GIMPLE_CALL: case GIMPLE_DEBUG: @@ -2627,8 +2637,8 @@ remove_conditions_and_labels (loop_p loop) basic_block bb = ifc_bbs[i]; if (bb_with_exit_edge_p (loop, bb) - || bb == loop->latch) - continue; + || bb == loop->latch) + continue; for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); ) switch (gimple_code (gsi_stmt (gsi))) -- 2.35.3