PR sanitizer/60569
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Mar 2014 12:25:04 +0000 (12:25 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Mar 2014 12:25:04 +0000 (12:25 +0000)
* ubsan.c (ubsan_type_descriptor): Check that DECL_NAME is nonnull
before accessing it.
testsuite/
* g++.dg/ubsan/pr60569.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@208681 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ubsan/pr60569.C [new file with mode: 0644]
gcc/ubsan.c

index 9b85e2d..3ab789a 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-19  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/60569
+       * ubsan.c (ubsan_type_descriptor): Check that DECL_NAME is nonnull
+       before accessing it.
+
 2014-03-19  Richard Biener  <rguenther@suse.de>
 
        PR lto/59543
index 36e53f8..9891638 100644 (file)
@@ -1,3 +1,8 @@
+2014-03-19  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/60569
+       * g++.dg/ubsan/pr60569.C: New test.
+
 2014-03-19  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * gcc.dg/tls/pr58595.c: Require tls_runtime instead of tls.
diff --git a/gcc/testsuite/g++.dg/ubsan/pr60569.C b/gcc/testsuite/g++.dg/ubsan/pr60569.C
new file mode 100644 (file)
index 0000000..df57c06
--- /dev/null
@@ -0,0 +1,21 @@
+// PR sanitizer/60569
+// { dg-do link }
+// { dg-require-effective-target lto }
+// { dg-options "-fsanitize=undefined -flto" }
+
+struct A
+{
+  void foo ();
+  struct
+  {
+    int i;
+    void bar () { i = 0; }
+  } s;
+};
+
+void A::foo () { s.bar (); }
+
+int
+main ()
+{
+}
index 7c7a893..22470da 100644 (file)
@@ -318,7 +318,7 @@ ubsan_type_descriptor (tree type, bool want_pointer_type_p)
     {
       if (TREE_CODE (TYPE_NAME (type2)) == IDENTIFIER_NODE)
        tname = IDENTIFIER_POINTER (TYPE_NAME (type2));
-      else
+      else if (DECL_NAME (TYPE_NAME (type2)) != NULL)
        tname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type2)));
     }