]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ubsan.c (ubsan_type_descriptor): If varpool_get_node returns NULL for a decl, recreat...
authorMarek Polacek <polacek@redhat.com>
Wed, 27 Nov 2013 08:02:48 +0000 (08:02 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 27 Nov 2013 08:02:48 +0000 (08:02 +0000)
2013-11-27  Marek Polacek  <polacek@redhat.com>

* ubsan.c (ubsan_type_descriptor): If varpool_get_node returns NULL
for a decl, recreate that decl.  Save into the hash table VAR_DECLs
rather than ADDR_EXPRs.
testsuite/
* c-c++-common/ubsan/undefined-1.c: New test.

From-SVN: r205433

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/undefined-1.c [new file with mode: 0644]
gcc/ubsan.c

index 851f746bbfd6546fc470f65d39e3b21c9304c3fa..736b2c2b8f91b9e2cd3d6157848dd433f7a67be2 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-27  Marek Polacek  <polacek@redhat.com>
+
+       * ubsan.c (ubsan_type_descriptor): If varpool_get_node returns NULL
+       for a decl, recreate that decl.  Save into the hash table VAR_DECLs
+       rather than ADDR_EXPRs.
+
 2013-11-27  Alexander Ivchenko  <alexander.ivchenko@intel.com>
 
        * config/ia64/hpux.h (TARGET_LIBC_HAS_FUNCTION): Fix typo.
index a2a81170166ec5137d7d8e2f5af2465dbcf7f1ff..61fe795127f93a2b1d79372d2c000506de95b1f0 100644 (file)
@@ -1,3 +1,7 @@
+2013-11-27  Marek Polacek  <polacek@redhat.com>
+
+       * c-c++-common/ubsan/undefined-1.c: New test.
+
 2013-11-26  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/59014
diff --git a/gcc/testsuite/c-c++-common/ubsan/undefined-1.c b/gcc/testsuite/c-c++-common/ubsan/undefined-1.c
new file mode 100644 (file)
index 0000000..1229b71
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+int
+foo (int x, int y)
+{
+  const int z = 2;
+  if (z & 1)
+    return x << y;
+  return 0;
+}
+
+int
+bar (int x, int y)
+{
+  return x + y;
+}
+
+int
+main (void)
+{
+  foo (3, 2);
+  bar (12, 42);
+  return 0;
+}
index 468a3b1b15060248bbc111976d55ff60d30302a4..fa6b42a868f2423447faca3a8a7ca28b8d976936 100644 (file)
@@ -272,8 +272,12 @@ ubsan_type_descriptor (tree type, bool want_pointer_type_p)
   type = TYPE_MAIN_VARIANT (type);
 
   tree decl = decl_for_type_lookup (type);
-  if (decl != NULL_TREE)
-    return decl;
+  /* It is possible that some of the earlier created DECLs were found
+     unused, in that case they weren't emitted and varpool_get_node
+     returns NULL node on them.  But now we really need them.  Thus,
+     renew them here.  */
+  if (decl != NULL_TREE && varpool_get_node (decl))
+    return build_fold_addr_expr (decl);
 
   tree dtype = ubsan_type_descriptor_type ();
   tree type2 = type;
@@ -372,11 +376,10 @@ ubsan_type_descriptor (tree type, bool want_pointer_type_p)
   DECL_INITIAL (decl) = ctor;
   rest_of_decl_compilation (decl, 1, 0);
 
-  /* Save the address of the VAR_DECL into the hash table.  */
-  decl = build_fold_addr_expr (decl);
+  /* Save the VAR_DECL into the hash table.  */
   decl_for_type_insert (type, decl);
 
-  return decl;
+  return build_fold_addr_expr (decl);
 }
 
 /* Create a structure for the ubsan library.  NAME is a name of the new