diff mbox

Fix ubsan ICE (PR sanitizer/60569)

Message ID 20140319111357.GI6523@redhat.com
State New
Headers show

Commit Message

Marek Polacek March 19, 2014, 11:13 a.m. UTC
Apparently with LTO we can get a TYPE_NAME without a DECL_NAME,
so check that it exists before accessing it.
Note that the test has to be run; only compiling wasn't enough
to provoke the ICE.

Ran ubsan testsuite on x86_64-linux, ok for trunk?

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.
testsuite/
	* g++.dg/ubsan/pr60569.C: New test.


	Marek

Comments

Jakub Jelinek March 19, 2014, 11:17 a.m. UTC | #1
On Wed, Mar 19, 2014 at 12:13:57PM +0100, Marek Polacek wrote:
> Apparently with LTO we can get a TYPE_NAME without a DECL_NAME,
> so check that it exists before accessing it.
> Note that the test has to be run; only compiling wasn't enough
> to provoke the ICE.

??  Shouldn't // { dg-do link } be sufficient?

> --- gcc/ubsan.c
> +++ gcc/ubsan.c
> @@ -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)));
>      }

This looks good to me.

	Jakub
Marek Polacek March 19, 2014, 11:30 a.m. UTC | #2
On Wed, Mar 19, 2014 at 12:17:19PM +0100, Jakub Jelinek wrote:
> On Wed, Mar 19, 2014 at 12:13:57PM +0100, Marek Polacek wrote:
> > Apparently with LTO we can get a TYPE_NAME without a DECL_NAME,
> > so check that it exists before accessing it.
> > Note that the test has to be run; only compiling wasn't enough
> > to provoke the ICE.
> 
> ??  Shouldn't // { dg-do link } be sufficient?

Ah, forgot about that, it is sufficient.  Ok with dg-do link instead
of dg-do run?
 
> > --- gcc/ubsan.c
> > +++ gcc/ubsan.c
> > @@ -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)));
> >      }
> 
> This looks good to me.

Thanks.

	Marek
diff mbox

Patch

diff --git gcc/testsuite/g++.dg/ubsan/pr60569.C gcc/testsuite/g++.dg/ubsan/pr60569.C
index e69de29..df6b7a4 100644
--- gcc/testsuite/g++.dg/ubsan/pr60569.C
+++ gcc/testsuite/g++.dg/ubsan/pr60569.C
@@ -0,0 +1,21 @@ 
+// PR sanitizer/60569
+// { dg-do run }
+// { 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 ()
+{
+}
diff --git gcc/ubsan.c gcc/ubsan.c
index 7c7a893..22470da 100644
--- gcc/ubsan.c
+++ gcc/ubsan.c
@@ -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)));
     }