]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ubsan: Fix up another spot that should have been BUILT_IN_UNREACHABLE_TRAPS [PR108655]
authorJakub Jelinek <jakub@redhat.com>
Mon, 6 Feb 2023 08:05:56 +0000 (09:05 +0100)
committerJakub Jelinek <jakub@redhat.com>
Mon, 6 Feb 2023 08:05:56 +0000 (09:05 +0100)
We ICE on the following testcase, because ivcanon calls
gimple_build_builtin_unreachable but doesn't expect it would need vops.
BUILT_IN_UNREACHABLE_TRAP I've introduced yesterday doesn't need
vops and should be used in that case instead of BUILT_IN_TRAP which
needs them.

2023-02-06  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/108655
* ubsan.cc (sanitize_unreachable_fn): For -funreachable-traps
or -fsanitize=unreachable -fsanitize-trap=unreachable return
BUILT_IN_UNREACHABLE_TRAP decl rather than BUILT_IN_TRAP.

* gcc.dg/pr108655.c: New test.

gcc/testsuite/gcc.dg/pr108655.c [new file with mode: 0644]
gcc/ubsan.cc

diff --git a/gcc/testsuite/gcc.dg/pr108655.c b/gcc/testsuite/gcc.dg/pr108655.c
new file mode 100644 (file)
index 0000000..f407616
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR tree-optimization/108655 */
+/* { dg-do compile } */
+/* { dg-options "-w -O1 -funreachable-traps" } */
+
+void
+foo (void)
+{
+  int i, j;
+  for (; i;)
+    ;
+  for (; i < 6;)
+    for (j = 0; j < 6; ++j)
+      i += j;
+  __builtin_trap ();
+}
index 6dec2c3078a5e3d27340ae72b42283e89fad55b7..c2f2e75b300a54cfb7ded8f9abe6fe6b5d900b99 100644 (file)
@@ -649,7 +649,7 @@ sanitize_unreachable_fn (tree *data, location_t loc)
       ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
       : flag_unreachable_traps)
     {
-      fn = builtin_decl_explicit (BUILT_IN_TRAP);
+      fn = builtin_decl_explicit (BUILT_IN_UNREACHABLE_TRAP);
       *data = NULL_TREE;
     }
   else if (san)