re PR sanitizer/66343 ("Error: .Lubsan_type3 already defined" with UBSan and precompi...
authorJakub Jelinek <jakub@redhat.com>
Wed, 5 Oct 2016 19:04:39 +0000 (21:04 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 5 Oct 2016 19:04:39 +0000 (21:04 +0200)
PR sanitizer/66343
* ubsan.c (ubsan_create_data): Call initialize_sanitizer_builtins here.
(ubsan_instrument_float_cast): And not here.

* c-ubsan.c (ubsan_instrument_return): Don't call
initialize_sanitizer_builtins here.

* gcc.dg/pch/pr66343-3.c: New test.
* gcc.dg/pch/pr66343-3.hs: New file.

From-SVN: r240804

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-ubsan.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pch/pr66343-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pch/pr66343-3.hs [new file with mode: 0644]
gcc/ubsan.c

index 8f7eb38f21e346beb653385e134bce56445245b9..9be5e48c5673b478d638af72f55164fe23ab9f15 100644 (file)
@@ -1,5 +1,9 @@
 2016-10-05  Jakub Jelinek  <jakub@redhat.com>
 
+       PR sanitizer/66343
+       * ubsan.c (ubsan_create_data): Call initialize_sanitizer_builtins here.
+       (ubsan_instrument_float_cast): And not here.
+
        PR sanitizer/66343
        * ubsan.c (ubsan_ids): New GTY(()) array.
        (ubsan_type_descriptor, ubsan_create_data): Use ubsan_ids
index 2bfce86c443e20abc729dafcefca13d9131cd7cf..6474a6dd6f64ec97240f511de722975aa2d18818 100644 (file)
@@ -1,3 +1,9 @@
+2016-10-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/66343
+       * c-ubsan.c (ubsan_instrument_return): Don't call
+       initialize_sanitizer_builtins here.
+
 2016-10-05  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        * c-common.c (c_common_truthvalue_conversion): Warn also for suspicious
index df7b9328d4caa52352947273bd41aa0a4861324d..482cce19f3c387a0ca0430a5acb4049963503f70 100644 (file)
@@ -235,9 +235,6 @@ ubsan_instrument_return (location_t loc)
 {
   if (flag_sanitize_undefined_trap_on_error)
     return build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0);
-  /* It is possible that PCH zapped table with definitions of sanitizer
-     builtins.  Reinitialize them if needed.  */
-  initialize_sanitizer_builtins ();
 
   tree data = ubsan_create_data ("__ubsan_missing_return_data", 1, &loc,
                                 NULL_TREE, NULL_TREE);
index fabe4c8db820ab0323b030f88cf015585daa0b5a..8a7e21e98d5eca1837225ca010e10e5ddd19de09 100644 (file)
@@ -1,5 +1,9 @@
 2016-10-05  Jakub Jelinek  <jakub@redhat.com>
 
+       PR sanitizer/66343
+       * gcc.dg/pch/pr66343-3.c: New test.
+       * gcc.dg/pch/pr66343-3.hs: New file.
+
        PR sanitizer/66343
        * gcc.dg/pch/pr66343-1.c: New test.
        * gcc.dg/pch/pr66343-1.hs: New file.
diff --git a/gcc/testsuite/gcc.dg/pch/pr66343-3.c b/gcc/testsuite/gcc.dg/pch/pr66343-3.c
new file mode 100644 (file)
index 0000000..67186e2
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR sanitizer/66343 */
+/* { dg-do assemble } */
+/* { dg-options "-fsanitize=undefined" } */
+
+#include "pr66343-3.h"
+
+void
+bar (int a, int b)
+{
+  a / b;
+}
+
+/* Hack to turn off PCH assembly comparison, as it is incompatible
+   with dg-do assemble.  The target condition will be always false.  */
+/* { dg-error "" "" { target { lp64 && { ! lp64 } } } } */
diff --git a/gcc/testsuite/gcc.dg/pch/pr66343-3.hs b/gcc/testsuite/gcc.dg/pch/pr66343-3.hs
new file mode 100644 (file)
index 0000000..2f86a02
--- /dev/null
@@ -0,0 +1,4 @@
+/* PR sanitizer/66343 */
+/* { dg-options "-fno-sanitize=undefined" } */
+
+/* Empty.  */
index 059c6aa4a93cffab1c3446f16afa26ebe10464a1..8818de4f372e1d61e1c1f73b6fb7a3c9d47ea9b2 100644 (file)
@@ -511,6 +511,10 @@ ubsan_create_data (const char *name, int loccnt, const location_t *ploc, ...)
   size_t i = 0;
   int j;
 
+  /* It is possible that PCH zapped table with definitions of sanitizer
+     builtins.  Reinitialize them if needed.  */
+  initialize_sanitizer_builtins ();
+
   /* Firstly, create a pointer to type descriptor type.  */
   tree td_type = ubsan_get_type_descriptor_type ();
   td_type = build_pointer_type (td_type);
@@ -1589,7 +1593,6 @@ ubsan_instrument_float_cast (location_t loc, tree type, tree expr)
     {
       location_t *loc_ptr = NULL;
       unsigned num_locations = 0;
-      initialize_sanitizer_builtins ();
       /* Figure out if we can propagate location to ubsan_data and use new
          style handlers in libubsan.  */
       if (ubsan_use_new_style_p (loc))