bool odr_violated;
/* Set when virtual table without RTTI previaled table with. */
bool rtti_broken;
+ /* Set when the canonical type is determined using the type name. */
+ bool tbaa_enabled;
};
/* Return TRUE if all derived types of T are known and thus
val->types_set->add (type);
+ if (!odr_hash)
+ return NULL;
+
gcc_checking_assert (can_be_name_hashed_p (type)
&& can_be_name_hashed_p (val->type));
return t->type;
}
+/* Set tbaa_enabled flag for TYPE. */
+
+void
+enable_odr_based_tbaa (tree type)
+{
+ odr_type t = get_odr_type (type, true);
+ t->tbaa_enabled = true;
+}
+
+/* True if canonical type of TYPE is determined using ODR name. */
+
+bool
+odr_based_tbaa_p (const_tree type)
+{
+ if (!RECORD_OR_UNION_TYPE_P (type))
+ return false;
+ odr_type t = get_odr_type (const_cast <tree> (type), false);
+ if (!t || !t->tbaa_enabled)
+ return false;
+ return true;
+}
+
+/* Set TYPE_CANONICAL of type and all its variants and duplicates
+ to CANONICAL. */
+
+void
+set_type_canonical_for_odr_type (tree type, tree canonical)
+{
+ odr_type t = get_odr_type (type, false);
+ unsigned int i;
+ tree tt;
+
+ for (tree t2 = t->type; t2; t2 = TYPE_NEXT_VARIANT (t2))
+ TYPE_CANONICAL (t2) = canonical;
+ if (t->types)
+ FOR_EACH_VEC_ELT (*t->types, i, tt)
+ for (tree t2 = tt; t2; t2 = TYPE_NEXT_VARIANT (t2))
+ TYPE_CANONICAL (t2) = canonical;
+}
+
/* Return true if we reported some ODR violation on TYPE. */
bool
/* Top-level LTO routines.
- Copyright (C) 2009-2018 Free Software Foundation, Inc.
+ Copyright (C) 2009-2019 Free Software Foundation, Inc.
Contributed by CodeSourcery, Inc.
This file is part of GCC.
#include "attribs.h"
#include "builtins.h"
#include "lto-common.h"
+#include "tree-pretty-print.h"
+
+/* True when no new types are going to be streamd from the global stream. */
+
+static bool type_streaming_finished = false;
GTY(()) tree first_personality_decl;
static unsigned long num_canonical_type_hash_entries;
static unsigned long num_canonical_type_hash_queries;
+/* Types postponed for registration to the canonical type table.
+ During streaming we postpone all TYPE_CXX_ODR_P types so we can alter
+ decide whether there is conflict with non-ODR type or not. */
+static GTY(()) vec<tree, va_gc> *types_to_register = NULL;
+
static void iterative_hash_canonical_type (tree type, inchash::hash &hstate);
static hashval_t gimple_canonical_type_hash (const void *p);
-static void gimple_register_canonical_type_1 (tree t, hashval_t hash);
+static hashval_t gimple_register_canonical_type_1 (tree t, hashval_t hash);
/* Returning a hash value for gimple type TYPE.
optimal order. To avoid quadratic behavior also register the
type here. */
v = hash_canonical_type (type);
- gimple_register_canonical_type_1 (type, v);
+ v = gimple_register_canonical_type_1 (type, v);
}
- hstate.add_int (v);
+ hstate.merge_hash (v);
}
/* Returns the hash for a canonical type P. */
/* Main worker for gimple_register_canonical_type. */
-static void
+static hashval_t
gimple_register_canonical_type_1 (tree t, hashval_t hash)
{
void **slot;
&& type_with_alias_set_p (t)
&& canonical_type_used_p (t));
+ /* ODR types for which there is no ODR violation and we did not record
+ structurally equivalent non-ODR type can be treated as unique by their
+ name.
+
+ hash passed to gimple_register_canonical_type_1 is a structural hash
+ that we can use to lookup structurally equivalent non-ODR type.
+ In case we decide to treat type as unique ODR type we recompute hash based
+ on name and let TBAA machinery know about our decision. */
+ if (RECORD_OR_UNION_TYPE_P (t)
+ && odr_type_p (t) && !odr_type_violation_reported_p (t))
+ {
+ /* Here we rely on fact that all non-ODR types was inserted into
+ canonical type hash and thus we can safely detect conflicts between
+ ODR types and interoperable non-ODR types. */
+ gcc_checking_assert (type_streaming_finished
+ && TYPE_MAIN_VARIANT (t) == t);
+ slot = htab_find_slot_with_hash (gimple_canonical_types, t, hash,
+ NO_INSERT);
+ if (slot && !TYPE_CXX_ODR_P (*(tree *)slot))
+ {
+ tree nonodr = *(tree *)slot;
+ if (symtab->dump_file)
+ {
+ fprintf (symtab->dump_file,
+ "ODR and non-ODR type conflict: ");
+ print_generic_expr (symtab->dump_file, t);
+ fprintf (symtab->dump_file, " and ");
+ print_generic_expr (symtab->dump_file, nonodr);
+ fprintf (symtab->dump_file, " mangled:%s\n",
+ IDENTIFIER_POINTER
+ (DECL_ASSEMBLER_NAME (TYPE_NAME (t))));
+ }
+ /* Set canonical for T and all other ODR equivalent duplicates
+ including incomplete structures. */
+ set_type_canonical_for_odr_type (t, nonodr);
+ }
+ else
+ {
+ tree prevail = prevailing_odr_type (t);
+
+ if (symtab->dump_file)
+ {
+ fprintf (symtab->dump_file,
+ "New canonical ODR type: ");
+ print_generic_expr (symtab->dump_file, t);
+ fprintf (symtab->dump_file, " mangled:%s\n",
+ IDENTIFIER_POINTER
+ (DECL_ASSEMBLER_NAME (TYPE_NAME (t))));
+ }
+ /* Set canonical for T and all other ODR equivalent duplicates
+ including incomplete structures. */
+ set_type_canonical_for_odr_type (t, prevail);
+ enable_odr_based_tbaa (t);
+ if (!type_in_anonymous_namespace_p (t))
+ hash = htab_hash_string (IDENTIFIER_POINTER
+ (DECL_ASSEMBLER_NAME
+ (TYPE_NAME (t))));
+ else
+ hash = TYPE_UID (t);
+
+ /* All variants of t now have TYPE_CANONICAL set to prevail.
+ Update canonical type hash cache accordingly. */
+ num_canonical_type_hash_entries++;
+ bool existed_p = canonical_type_hash_cache->put (prevail, hash);
+ gcc_checking_assert (!existed_p);
+ }
+ return hash;
+ }
+
slot = htab_find_slot_with_hash (gimple_canonical_types, t, hash, INSERT);
if (*slot)
{
bool existed_p = canonical_type_hash_cache->put (t, hash);
gcc_assert (!existed_p);
}
+ return hash;
}
/* Register type T in the global type table gimple_types and set
gimple_register_canonical_type (node);
}
+/* Finish canonical type calculation: after all units has been streamed in we
+ can check if given ODR type structurally conflicts with a non-ODR type. In
+ the first case we set type canonical according to the canonical type hash.
+ In the second case we use type names. */
+
+static void
+lto_register_canonical_types_for_odr_types ()
+{
+ tree t;
+ unsigned int i;
+
+ if (!types_to_register)
+ return;
+
+ type_streaming_finished = true;
+
+ /* Be sure that no types derived from ODR types was
+ not inserted into the hash table. */
+ if (flag_checking)
+ FOR_EACH_VEC_ELT (*types_to_register, i, t)
+ gcc_assert (!TYPE_CANONICAL (t));
+
+ /* Register all remaining types. */
+ FOR_EACH_VEC_ELT (*types_to_register, i, t)
+ if (!TYPE_CANONICAL (t))
+ gimple_register_canonical_type (t);
+}
+
/* Remember trees that contains references to declarations. */
vec <tree, va_gc> *tree_with_vars;
}
+
/* Read all the symbols from buffer DATA, using descriptors in DECL_DATA.
RESOLUTIONS is the set of symbols picked by the linker (read from the
resolution file when the linker plugin is being used). */
num_prevailing_types++;
lto_fixup_prevailing_type (t);
- /* Compute the canonical type of all types.
+ /* Compute the canonical type of all non-ODR types.
+ Delay ODR types for the end of merging process - the canonical
+ type for those can be computed using the (unique) name however
+ we want to do this only if units in other languages do not
+ contain structurally equivalent type.
+
Because SCC components are streamed in random (hash) order
we may have encountered the type before while registering
type canonical of a derived type in the same SCC. */
if (!TYPE_CANONICAL (t))
- gimple_register_canonical_type (t);
+ {
+ if (!RECORD_OR_UNION_TYPE_P (t)
+ || !TYPE_CXX_ODR_P (t))
+ gimple_register_canonical_type (t);
+ else if (COMPLETE_TYPE_P (t))
+ vec_safe_push (types_to_register, t);
+ }
if (TYPE_MAIN_VARIANT (t) == t && odr_type_p (t))
register_odr_type (t);
}
ggc_free(decl_data);
real_file_decl_data = NULL;
+ lto_register_canonical_types_for_odr_types ();
+
if (resolution_file_name)
fclose (resolution);