@@ -269,8 +269,12 @@ ubsan_type_descriptor (tree type, bool w
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;
@@ -369,11 +373,10 @@ ubsan_type_descriptor (tree type, bool w
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
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+int
+foo (int x, int y)
+{
+ if (2 & 1)
+ return x << y;
+ return 0;
+}
+
+int
+bar (int x, int y)
+{
+ return x + y;
+}
+
+int
+main (void)
+{
+ foo (3, 2);
+ bar (12, 42);
+ return 0;
+}