aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-02-02 10:54:54 +0100
committerJakub Jelinek <jakub@redhat.com>2023-02-02 10:54:54 +0100
commitd2423144eb36a68fd0da9224857ce807714874a7 (patch)
tree8e7cf8009eb3608cb87336a6a533f1d121863ba7 /gcc/tree.cc
parent209f02b0a9e9adc0bf0247cb5eef04e0f175d64e (diff)
downloadgcc-d2423144eb36a68fd0da9224857ce807714874a7.zip
gcc-d2423144eb36a68fd0da9224857ce807714874a7.tar.gz
gcc-d2423144eb36a68fd0da9224857ce807714874a7.tar.bz2
Replace IFN_TRAP with BUILT_IN_UNREACHABLE_TRAP [PR107300]
For PR106099 I've added IFN_TRAP as an alternative to __builtin_trap meant for __builtin_unreachable purposes (e.g. with -funreachable-traps or some sanitizers) which doesn't need vops because __builtin_unreachable doesn't need them either. This works in various cases, but unfortunately IPA likes to decide on the redirection to unreachable just by tweaking the cgraph edge to point to a different FUNCTION_DECL. As internal functions don't have a decl, this causes problems like in the following testcase. The following patch fixes it by removing IFN_TRAP again and replacing it with user inaccessible BUILT_IN_UNREACHABLE_TRAP, so that e.g. builtin_decl_unreachable can return it directly and we don't need to tweak it later in wherever we actually replace the call stmt. 2023-02-02 Jakub Jelinek <jakub@redhat.com> PR ipa/107300 * builtins.def (BUILT_IN_UNREACHABLE_TRAP): New builtin. * internal-fn.def (TRAP): Remove. * internal-fn.cc (expand_TRAP): Remove. * tree.cc (build_common_builtin_nodes): Define BUILT_IN_UNREACHABLE_TRAP if not yet defined. (builtin_decl_unreachable): Use BUILT_IN_UNREACHABLE_TRAP instead of BUILT_IN_TRAP. * gimple.cc (gimple_build_builtin_unreachable): Remove emitting internal function for BUILT_IN_TRAP. * asan.cc (maybe_instrument_call): Handle BUILT_IN_UNREACHABLE_TRAP. * cgraph.cc (cgraph_edge::verify_corresponds_to_fndecl): Handle BUILT_IN_UNREACHABLE_TRAP instead of BUILT_IN_TRAP. * ipa-devirt.cc (possible_polymorphic_call_target_p): Handle BUILT_IN_UNREACHABLE_TRAP. * builtins.cc (expand_builtin, is_inexpensive_builtin): Likewise. * tree-cfg.cc (verify_gimple_call, pass_warn_function_return::execute): Likewise. * attribs.cc (decl_attributes): Don't report exclusions on BUILT_IN_UNREACHABLE_TRAP either. * gcc.dg/pr107300.c: New test.
Diffstat (limited to 'gcc/tree.cc')
-rw-r--r--gcc/tree.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 80c0967..41ccbf3 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -9758,6 +9758,7 @@ build_common_builtin_nodes (void)
if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
|| !builtin_decl_explicit_p (BUILT_IN_TRAP)
+ || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
|| !builtin_decl_explicit_p (BUILT_IN_ABORT))
{
ftype = build_function_type (void_type_node, void_list_node);
@@ -9767,6 +9768,12 @@ build_common_builtin_nodes (void)
"__builtin_unreachable",
ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
| ECF_CONST | ECF_COLD);
+ if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
+ local_define_builtin ("__builtin_unreachable trap", ftype,
+ BUILT_IN_UNREACHABLE_TRAP,
+ "__builtin_unreachable trap",
+ ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
+ | ECF_CONST | ECF_COLD);
if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
"abort",
@@ -10908,7 +10915,7 @@ builtin_decl_unreachable ()
if (sanitize_flags_p (SANITIZE_UNREACHABLE)
? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
: flag_unreachable_traps)
- fncode = BUILT_IN_TRAP;
+ fncode = BUILT_IN_UNREACHABLE_TRAP;
/* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
in the sanopt pass. */