diff options
author | Marek Polacek <polacek@redhat.com> | 2013-11-27 08:02:48 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2013-11-27 08:02:48 +0000 |
commit | 14a981b922e03f200af99b1db09f599842d8eb7d (patch) | |
tree | 7b0bd7c1d1c52fe4a301a4ef1b40bb08444d2459 /gcc/ubsan.c | |
parent | 199299e8e54ad29fd3b140adae78e08bbbfef8c4 (diff) | |
download | gcc-14a981b922e03f200af99b1db09f599842d8eb7d.zip gcc-14a981b922e03f200af99b1db09f599842d8eb7d.tar.gz gcc-14a981b922e03f200af99b1db09f599842d8eb7d.tar.bz2 |
ubsan.c (ubsan_type_descriptor): If varpool_get_node returns NULL for a decl, recreate that decl.
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
Diffstat (limited to 'gcc/ubsan.c')
-rw-r--r-- | gcc/ubsan.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/gcc/ubsan.c b/gcc/ubsan.c index 468a3b1..fa6b42a 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -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 |