diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9b85e2d0824748354c99173a089067daaaea1fdd..3ab789a42a144b4462e10ef9cec2774cd3bd8bff 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 36e53f8c0c20326ab959a3d2917b0d105a08c7f5..9891638a802b5896e2562173b0cff5a62827a200 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000000000000000000000000000000000000..df57c06bed6ae97db23e38743b536e480cd5963d --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr60569.C @@ -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 () +{ +} diff --git a/gcc/ubsan.c b/gcc/ubsan.c index 7c7a893aca6495b8b210b3fb5d6efb6c89bffa5c..22470dafeb2d1664312c943ffa5451080114baa8 100644 --- a/gcc/ubsan.c +++ b/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))); }