aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-07-28 12:42:14 +0200
committerJakub Jelinek <jakub@redhat.com>2022-07-28 12:43:13 +0200
commitf64eb636677d714781b4543f111b1c9239328db6 (patch)
treeb365d582214c402540c809b66b405d97cdd05d28 /gcc/gimple.cc
parent0652087375e7813f06140f1bb5e18375f45d28ff (diff)
downloadgcc-f64eb636677d714781b4543f111b1c9239328db6.zip
gcc-f64eb636677d714781b4543f111b1c9239328db6.tar.gz
gcc-f64eb636677d714781b4543f111b1c9239328db6.tar.bz2
gimple, internal-fn: Add IFN_TRAP and use it for __builtin_unreachable [PR106099]
__builtin_unreachable and __ubsan_handle_builtin_unreachable don't use vops, they are marked const/leaf/noreturn/nothrow/cold. But __builtin_trap uses vops, isn't const, just leaf/noreturn/nothrow/cold. This is I believe so that when users explicitly use __builtin_trap in their sources they get stores visible at the trap side. -fsanitize=unreachable -fsanitize-undefined-trap-on-error used to transform __builtin_unreachable to __builtin_trap even in the past, but the sanopt pass has TODO_update_ssa, so it worked fine. Now that gimple_build_builtin_unreachable can build a __builtin_trap call right away, we can run into problems that whenever we need it we would need to either manually or through TODO_update* ensure the vops being updated. Though, as it is originally __builtin_unreachable which is just implemented as trap, I think for this case it is fine to avoid vops. For this the patch introduces IFN_TRAP, which has ECF_* flags like __builtin_unreachable and is expanded as __builtin_trap. 2022-07-28 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/106099 * internal-fn.def (TRAP): New internal fn. * internal-fn.h (expand_TRAP): Declare. * internal-fn.cc (expand_TRAP): Define. * gimple.cc (gimple_build_builtin_unreachable): For BUILT_IN_TRAP, use internal fn rather than builtin. * gcc.dg/ubsan/pr106099.c: New test.
Diffstat (limited to 'gcc/gimple.cc')
-rw-r--r--gcc/gimple.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/gcc/gimple.cc b/gcc/gimple.cc
index 9b15639..cd5ad0c 100644
--- a/gcc/gimple.cc
+++ b/gcc/gimple.cc
@@ -430,7 +430,16 @@ gimple_build_builtin_unreachable (location_t loc)
{
tree data = NULL_TREE;
tree fn = sanitize_unreachable_fn (&data, loc);
- gcall *g = gimple_build_call (fn, data != NULL_TREE, data);
+ gcall *g;
+ if (DECL_FUNCTION_CODE (fn) != BUILT_IN_TRAP)
+ g = gimple_build_call (fn, data != NULL_TREE, data);
+ else
+ {
+ /* Instead of __builtin_trap use .TRAP, so that it doesn't
+ need vops. */
+ gcc_checking_assert (data == NULL_TREE);
+ g = gimple_build_call_internal (IFN_TRAP, 0);
+ }
gimple_set_location (g, loc);
return g;
}