if ((!slot || !*slot) && in_lto_p && can_be_vtable_hashed_p (type))
{
hash = hash_odr_vtable (type);
+ if (!odr_vtable_hash)
+ odr_vtable_hash = new odr_vtable_hash_type (23);
vtable_slot = odr_vtable_hash->find_slot_with_hash (type, hash,
insert ? INSERT : NO_INSERT);
}
"%i duplicates overall\n", num_all_types, num_types, num_duplicates);
}
-/* Save some WPA->ltrans streaming by freeing enum values. */
+/* Save some WPA->ltrans streaming by freeing stuff needed only for good
+ ODR warnings.
+ We free TYPE_VALUES of enums and also make TYPE_DECLs to not point back
+ to the type (which is needed to keep them in the same SCC and preserve
+ location information to output warnings) and subsequently we make all
+ TYPE_DECLS of same assembler name equivalent. */
static void
-free_enum_values ()
+free_odr_warning_data ()
{
- static bool enum_values_freed = false;
- if (enum_values_freed || !flag_wpa || !odr_types_ptr)
+ static bool odr_data_freed = false;
+
+ if (odr_data_freed || !flag_wpa || !odr_types_ptr)
return;
- enum_values_freed = true;
- unsigned int i;
- for (i = 0; i < odr_types.length (); i++)
+
+ odr_data_freed = true;
+
+ for (unsigned int i = 0; i < odr_types.length (); i++)
if (odr_types[i])
{
- if (TREE_CODE (odr_types[i]->type) == ENUMERAL_TYPE)
- TYPE_VALUES (odr_types[i]->type) = NULL;
+ tree t = odr_types[i]->type;
+
+ if (TREE_CODE (t) == ENUMERAL_TYPE)
+ TYPE_VALUES (t) = NULL;
+ TREE_TYPE (TYPE_NAME (t)) = void_type_node;
+
if (odr_types[i]->types)
for (unsigned int j = 0; j < odr_types[i]->types->length (); j++)
- if (TREE_CODE ((*odr_types[i]->types)[j]) == ENUMERAL_TYPE)
- TYPE_VALUES ((*odr_types[i]->types)[j]) = NULL;
+ {
+ tree td = (*odr_types[i]->types)[j];
+
+ if (TREE_CODE (td) == ENUMERAL_TYPE)
+ TYPE_VALUES (td) = NULL;
+ TYPE_NAME (td) = TYPE_NAME (t);
+ }
}
- enum_values_freed = true;
+ odr_data_freed = true;
}
/* Initialize IPA devirt and build inheritance tree graph. */
if (odr_hash)
{
- free_enum_values ();
+ free_odr_warning_data ();
return;
}
timevar_push (TV_IPA_INHERITANCE);
dump_type_inheritance_graph (inheritance_dump_file);
dump_end (TDI_inheritance, inheritance_dump_file);
}
- free_enum_values ();
+ free_odr_warning_data ();
timevar_pop (TV_IPA_INHERITANCE);
}
return array;
}
+/* Return CTX after removal of contexts that are not relevant */
+
+static tree
+fld_decl_context (tree ctx)
+{
+ /* Variably modified types are needed for tree_is_indexable to decide
+ whether the type needs to go to local or global section.
+ This code is semi-broken but for now it is easiest to keep contexts
+ as expected. */
+ if (ctx && TYPE_P (ctx)
+ && !variably_modified_type_p (ctx, NULL_TREE))
+ {
+ while (ctx && TYPE_P (ctx))
+ ctx = TYPE_CONTEXT (ctx);
+ }
+ return ctx;
+}
+
/* For T being aggregate type try to turn it into a incomplete variant.
Return T if no simplification is possible. */
}
else
TYPE_VALUES (copy) = NULL;
+
+ /* Build copy of TYPE_DECL in TYPE_NAME if necessary.
+ This is needed for ODR violation warnings to come out right (we
+ want duplicate TYPE_DECLs whenever the type is duplicated because
+ of ODR violation. Because lang data in the TYPE_DECL may not
+ have been freed yet, rebuild it from scratch and copy relevant
+ fields. */
+ TYPE_NAME (copy) = fld_simplified_type_name (copy);
+ tree name = TYPE_NAME (copy);
+
+ if (name && TREE_CODE (name) == TYPE_DECL)
+ {
+ gcc_checking_assert (TREE_TYPE (name) == t);
+ tree name2 = build_decl (DECL_SOURCE_LOCATION (name), TYPE_DECL,
+ DECL_NAME (name), copy);
+ if (DECL_ASSEMBLER_NAME_SET_P (name))
+ SET_DECL_ASSEMBLER_NAME (name2, DECL_ASSEMBLER_NAME (name));
+ SET_DECL_ALIGN (name2, 0);
+ DECL_CONTEXT (name2) = fld_decl_context
+ (DECL_CONTEXT (name));
+ TYPE_NAME (copy) = name2;
+ }
}
return copy;
}
if (TREE_CODE (type) == ENUMERAL_TYPE)
{
/* Type values are used only for C++ ODR checking. Drop them
- for all type variants and non-ODR types. */
+ for all type variants and non-ODR types.
+ For ODR types the data is freed in free_odr_warning_data. */
if (TYPE_MAIN_VARIANT (type) != type
|| !type_with_linkage_p (type))
TYPE_VALUES (type) = NULL;
TYPE_CONTEXT (type) = ctx;
}
- /* Drop TYPE_DECLs in TYPE_NAME in favor of the identifier in the
- TYPE_DECL if the type doesn't have linkage.
- this must match fld_ */
- if (type != TYPE_MAIN_VARIANT (type) || ! type_with_linkage_p (type))
- TYPE_STUB_DECL (type) = NULL;
+ TYPE_STUB_DECL (type) = NULL;
TYPE_NAME (type) = fld_simplified_type_name (type);
}
e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
See cp/mangle.c:write_builtin_type for details. */
- if (flag_lto_odr_type_mering
- && TREE_CODE (decl) == TYPE_DECL
- && DECL_NAME (decl)
- && decl == TYPE_NAME (TREE_TYPE (decl))
- && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
- && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
- && (type_with_linkage_p (TREE_TYPE (decl))
- || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
- && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
- return !DECL_ASSEMBLER_NAME_SET_P (decl);
+ if (TREE_CODE (decl) == TYPE_DECL)
+ {
+ if (flag_lto_odr_type_mering
+ && DECL_NAME (decl)
+ && decl == TYPE_NAME (TREE_TYPE (decl))
+ && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
+ && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
+ && (type_with_linkage_p (TREE_TYPE (decl))
+ || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
+ && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
+ return !DECL_ASSEMBLER_NAME_SET_P (decl);
+ return false;
+ }
/* Only FUNCTION_DECLs and VAR_DECLs are considered. */
if (!VAR_OR_FUNCTION_DECL_P (decl))
return false;
{
DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
DECL_VISIBILITY_SPECIFIED (decl) = 0;
- /* TREE_PUBLIC is used to tell if type is anonymous. */
+ TREE_PUBLIC (decl) = 0;
+ TREE_PRIVATE (decl) = 0;
+ DECL_ARTIFICIAL (decl) = 0;
TYPE_DECL_SUPPRESS_DEBUG (decl) = 0;
DECL_INITIAL (decl) = NULL_TREE;
DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
DECL_MODE (decl) = VOIDmode;
- TREE_TYPE (decl) = void_type_node;
SET_DECL_ALIGN (decl, 0);
+ /* TREE_TYPE is cleared at WPA time in free_odr_warning_data. */
}
else if (TREE_CODE (decl) == FIELD_DECL)
{
if (TREE_CODE (decl) != FIELD_DECL
&& ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
|| !DECL_VIRTUAL_P (decl)))
- {
- tree ctx = DECL_CONTEXT (decl);
- /* Variably modified types are needed for tree_is_indexable to decide
- whether the type needs to go to local or global section.
- This code is semi-broken but for now it is easiest to keep contexts
- as expected. */
- if (ctx && TYPE_P (ctx)
- && !variably_modified_type_p (ctx, NULL_TREE))
- {
- while (ctx && TYPE_P (ctx))
- ctx = TYPE_CONTEXT (ctx);
- DECL_CONTEXT (decl) = ctx;
- }
- }
+ DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
}