From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id E5E5E3858C60; Fri, 27 Jan 2023 10:17:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5E5E3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674814638; bh=zDDCjpXxFH94qS3ToferYxj8tq3XLrF5KXSqnk7Fd+U=; h=From:To:Subject:Date:From; b=DKqGWgQI5XBN1bvdQu0InP7yw/lc3MnsxS8qZvZcIgvYAXn4LUIaJmtVVZbQ2/44C ctluY4t/MFtyP3MqtIovOgz/xsG2HMmkSwF3rmqlG6htRjeyajGDVfuXjSdpLpBvH6 ijDzSn9PaPt9Zi1tctW68KITdvyKNAGCE9QjzfGU= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5436] cgraph: Adjust verify_corresponds_to_fndecl [PR106061] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 9b9a1ac14cdca6eef8dbcab0d33f3c03774a6c77 X-Git-Newrev: bd246ac68239d944b01c213c39d6e212362c1b40 Message-Id: <20230127101718.E5E5E3858C60@sourceware.org> Date: Fri, 27 Jan 2023 10:17:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bd246ac68239d944b01c213c39d6e212362c1b40 commit r13-5436-gbd246ac68239d944b01c213c39d6e212362c1b40 Author: Jakub Jelinek Date: Fri Jan 27 11:16:43 2023 +0100 cgraph: Adjust verify_corresponds_to_fndecl [PR106061] IPA passes redirect some calls in what it determines to be unreachable code to builtin_decl_unreachable. But that function returns sometimes builtin_decl_explicit (BUILT_IN_UNREACHABLE) (which was what GCC 12 and earlier did always), or builtin_decl_explicit (BUILT_IN_TRAP) (e.g. for -funreachable-traps, -O0, -Og). Now the cgraph verification code has a code to verify cgraph edges and has there an exception for these redirections to BUILT_IN_UNREACHABLE, but doesn't have for BUILT_IN_TRAP, so e.g. the following testcase ICEs during that verification. The following patch just adds BUILT_IN_TRAP to those exceptions. 2023-01-27 Jakub Jelinek PR ipa/106061 * cgraph.cc (cgraph_edge::verify_corresponds_to_fndecl): Allow redirection of calls to __builtin_trap in addition to redirection to __builtin_unreachable. * gcc.dg/pr106061.c: New test. Diff: --- gcc/cgraph.cc | 6 ++++-- gcc/testsuite/gcc.dg/pr106061.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 5f72ace9b57..b810237c919 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -3248,9 +3248,11 @@ cgraph_edge::verify_corresponds_to_fndecl (tree decl) node = node->ultimate_alias_target (); /* Optimizers can redirect unreachable calls or calls triggering undefined - behavior to builtin_unreachable. */ + behavior to __builtin_unreachable or __builtin_trap. */ - if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE)) + if (fndecl_built_in_p (callee->decl, BUILT_IN_NORMAL) + && (DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE + || DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_TRAP)) return false; if (callee->former_clone_of != node->decl diff --git a/gcc/testsuite/gcc.dg/pr106061.c b/gcc/testsuite/gcc.dg/pr106061.c new file mode 100644 index 00000000000..bba8d29bf47 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106061.c @@ -0,0 +1,18 @@ +/* PR ipa/106061 */ +/* { dg-do compile } */ +/* { dg-options "-Og" } */ + +extern void foo (void); + +inline void +bar (int x) +{ + if (x) + foo (); +} + +void +baz (void) +{ + bar (0); +}