]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: properly initialize UBSAN built-ins
authorMartin Liska <mliska@suse.cz>
Thu, 23 Jun 2022 12:43:50 +0000 (14:43 +0200)
committerMartin Liska <mliska@suse.cz>
Thu, 23 Jun 2022 13:28:27 +0000 (15:28 +0200)
PR c++/106062

gcc/ChangeLog:

* ubsan.cc (sanitize_unreachable_fn): Change order of calls
in order to initialize UBSAN built-ins.

gcc/testsuite/ChangeLog:

* gfortran.dg/ubsan/pr106062.f90: New test.

gcc/testsuite/gfortran.dg/ubsan/pr106062.f90 [new file with mode: 0644]
gcc/ubsan.cc

diff --git a/gcc/testsuite/gfortran.dg/ubsan/pr106062.f90 b/gcc/testsuite/gfortran.dg/ubsan/pr106062.f90
new file mode 100644 (file)
index 0000000..879a67e
--- /dev/null
@@ -0,0 +1,11 @@
+! PR c++/106062
+! { dg-do compile }
+! { dg-options "-O2 -fsanitize=undefined" }
+
+call test (reshape ((/ 'a', 'b', 'c', 'd' /), (/ 2, 2 /)))
+contains
+  subroutine test (a)
+    character (*), dimension (:, :) :: a
+    if (len (a) .ne. 1) STOP 
+  end  
+end
index f15026872a136c87bc569d6d6128a0b581762d87..b6c4301dfaf036f6f4a03a8df198c76a3c702b2d 100644 (file)
@@ -654,9 +654,10 @@ sanitize_unreachable_fn (tree *data, location_t loc)
     }
   else if (san)
     {
-      fn = builtin_decl_explicit (BUILT_IN_UBSAN_HANDLE_BUILTIN_UNREACHABLE);
+      /* Call ubsan_create_data first as it initializes SANITIZER built-ins.  */
       *data = ubsan_create_data ("__ubsan_unreachable_data", 1, &loc,
                                 NULL_TREE, NULL_TREE);
+      fn = builtin_decl_explicit (BUILT_IN_UBSAN_HANDLE_BUILTIN_UNREACHABLE);
       *data = build_fold_addr_expr_loc (loc, *data);
     }
   else