* [PATCH] cgraph: Adjust verify_corresponds_to_fndecl [PR106061]
@ 2023-01-27 9:02 Jakub Jelinek
2023-01-27 9:59 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-01-27 9:02 UTC (permalink / raw)
To: Jan Hubicka, Richard Biener; +Cc: gcc-patches
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2023-01-27 Jakub Jelinek <jakub@redhat.com>
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.
--- gcc/cgraph.cc.jj 2023-01-19 09:58:50.000000000 +0100
+++ gcc/cgraph.cc 2023-01-26 15:30:50.422759246 +0100
@@ -3248,9 +3248,11 @@ cgraph_edge::verify_corresponds_to_fndec
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
--- gcc/testsuite/gcc.dg/pr106061.c.jj 2023-01-26 15:40:06.002721103 +0100
+++ gcc/testsuite/gcc.dg/pr106061.c 2023-01-26 15:41:32.553468886 +0100
@@ -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);
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] cgraph: Adjust verify_corresponds_to_fndecl [PR106061]
2023-01-27 9:02 [PATCH] cgraph: Adjust verify_corresponds_to_fndecl [PR106061] Jakub Jelinek
@ 2023-01-27 9:59 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-01-27 9:59 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Jan Hubicka, gcc-patches
On Fri, 27 Jan 2023, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2023-01-27 Jakub Jelinek <jakub@redhat.com>
>
> 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.
>
> --- gcc/cgraph.cc.jj 2023-01-19 09:58:50.000000000 +0100
> +++ gcc/cgraph.cc 2023-01-26 15:30:50.422759246 +0100
> @@ -3248,9 +3248,11 @@ cgraph_edge::verify_corresponds_to_fndec
> 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
> --- gcc/testsuite/gcc.dg/pr106061.c.jj 2023-01-26 15:40:06.002721103 +0100
> +++ gcc/testsuite/gcc.dg/pr106061.c 2023-01-26 15:41:32.553468886 +0100
> @@ -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);
> +}
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-27 9:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 9:02 [PATCH] cgraph: Adjust verify_corresponds_to_fndecl [PR106061] Jakub Jelinek
2023-01-27 9:59 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).