diff options
author | Jakub Jelinek <jakub@redhat.com> | 2015-11-26 10:52:48 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2015-11-26 10:52:48 +0100 |
commit | 62775f0d9a513654b62e8a83e13c8d1324635ee4 (patch) | |
tree | a5817c2d93ec5378d7f944232b39f405296aa94f /gcc | |
parent | bf8e1b52f72d079d99173a6742f0070c632cc736 (diff) | |
download | gcc-62775f0d9a513654b62e8a83e13c8d1324635ee4.zip gcc-62775f0d9a513654b62e8a83e13c8d1324635ee4.tar.gz gcc-62775f0d9a513654b62e8a83e13c8d1324635ee4.tar.bz2 |
re PR c++/68508 (Internal compiler error with parentheses around return value in C++14 with ASan enabled)
PR c++/68508
* cp-tree.h (cp_ubsan_maybe_instrument_downcast): Add INTYPE argument.
* cp-ubsan.c (cp_ubsan_maybe_instrument_downcast): Likewise. Use
it instead of or in addition to TREE_TYPE (op). Use
is_properly_derived_from, return NULL_TREE if TREE_TYPE (intype) and
TREE_TYPE (type) are the same type minus qualifiers.
* typeck.c (build_static_cast_1): Adjust callers.
* g++.dg/ubsan/pr68508.C: New test.
From-SVN: r230928
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 2 | ||||
-rw-r--r-- | gcc/cp/cp-ubsan.c | 7 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ubsan/pr68508.C | 15 |
6 files changed, 39 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 82a29a3..90d86dc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2015-11-26 Jakub Jelinek <jakub@redhat.com> + + PR c++/68508 + * cp-tree.h (cp_ubsan_maybe_instrument_downcast): Add INTYPE argument. + * cp-ubsan.c (cp_ubsan_maybe_instrument_downcast): Likewise. Use + it instead of or in addition to TREE_TYPE (op). Use + is_properly_derived_from, return NULL_TREE if TREE_TYPE (intype) and + TREE_TYPE (type) are the same type minus qualifiers. + * typeck.c (build_static_cast_1): Adjust callers. + 2015-11-25 Martin Sebor <msebor@redhat.com> PR c++/67876 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1672291..caa601d 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6854,7 +6854,7 @@ extern bool cilk_valid_spawn (tree); /* In cp-ubsan.c */ extern void cp_ubsan_maybe_instrument_member_call (tree); extern void cp_ubsan_instrument_member_accesses (tree *); -extern tree cp_ubsan_maybe_instrument_downcast (location_t, tree, tree); +extern tree cp_ubsan_maybe_instrument_downcast (location_t, tree, tree, tree); extern tree cp_ubsan_maybe_instrument_cast_to_vbase (location_t, tree, tree); /* -- end of C++ */ diff --git a/gcc/cp/cp-ubsan.c b/gcc/cp/cp-ubsan.c index e780c2e..6ffeb16 100644 --- a/gcc/cp/cp-ubsan.c +++ b/gcc/cp/cp-ubsan.c @@ -243,13 +243,14 @@ cp_ubsan_instrument_member_accesses (tree *t_p) /* Instrument downcast. */ tree -cp_ubsan_maybe_instrument_downcast (location_t loc, tree type, tree op) +cp_ubsan_maybe_instrument_downcast (location_t loc, tree type, + tree intype, tree op) { if (!POINTER_TYPE_P (type) + || !POINTER_TYPE_P (intype) || !POINTER_TYPE_P (TREE_TYPE (op)) - || !CLASS_TYPE_P (TREE_TYPE (type)) || !CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (op))) - || !DERIVED_FROM_P (TREE_TYPE (TREE_TYPE (op)), TREE_TYPE (type))) + || !is_properly_derived_from (TREE_TYPE (type), TREE_TYPE (intype))) return NULL_TREE; return cp_ubsan_maybe_instrument_vptr (loc, op, TREE_TYPE (type), true, diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 9517890..1d2943f 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6590,7 +6590,8 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, if (flag_sanitize & SANITIZE_VPTR) { tree ubsan_check - = cp_ubsan_maybe_instrument_downcast (input_location, type, expr); + = cp_ubsan_maybe_instrument_downcast (input_location, type, + intype, expr); if (ubsan_check) expr = ubsan_check; } @@ -6737,7 +6738,8 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, if (flag_sanitize & SANITIZE_VPTR) { tree ubsan_check - = cp_ubsan_maybe_instrument_downcast (input_location, type, expr); + = cp_ubsan_maybe_instrument_downcast (input_location, type, + intype, expr); if (ubsan_check) expr = ubsan_check; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9d022fc..2e9f962 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-26 Jakub Jelinek <jakub@redhat.com> + + PR c++/68508 + * g++.dg/ubsan/pr68508.C: New test. + 2015-11-25 Martin Sebor <msebor@redhat.com> PR c++/67876 diff --git a/gcc/testsuite/g++.dg/ubsan/pr68508.C b/gcc/testsuite/g++.dg/ubsan/pr68508.C new file mode 100644 index 0000000..ffe8f00 --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr68508.C @@ -0,0 +1,15 @@ +// PR c++/68508 +// { dg-do compile } +// { dg-options "-std=c++14 -fsanitize=vptr" } + +struct A +{ + virtual int foo () { return 0; } +}; + +const A & +bar () +{ + static A x = A (); + return (x); +} |