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);
+ /* Anonymous namespace types never conflict with non-C++ types. */
+ if (type_with_linkage_p (t) && type_in_anonymous_namespace_p (t))
+ slot = NULL;
+ else
+ {
+ /* 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;
tree t = streamer_tree_cache_get_tree (cache, from + i);
scc->entries[i] = t;
/* Do not merge SCCs with local entities inside them. Also do
- not merge TRANSLATION_UNIT_DECLs. */
+ not merge TRANSLATION_UNIT_DECLs and anonymous namespace types. */
if (TREE_CODE (t) == TRANSLATION_UNIT_DECL
|| (VAR_OR_FUNCTION_DECL_P (t)
&& !(TREE_PUBLIC (t) || DECL_EXTERNAL (t)))
- || TREE_CODE (t) == LABEL_DECL)
+ || TREE_CODE (t) == LABEL_DECL
+ || (TYPE_P (t)
+ && type_with_linkage_p (TYPE_MAIN_VARIANT (t))
+ && type_in_anonymous_namespace_p (TYPE_MAIN_VARIANT (t))))
{
/* Avoid doing any work for these cases and do not worry to
record the SCCs for further merging. */
--- /dev/null
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -O3 -flto } } } */
+/* This testcase tests that anonymous namespaces in different TUs are treated
+ as different types by LTO TBAA and that they never alias with structurally
+ same C types. */
+namespace {
+ __attribute__((used))
+ struct a {int a;} *p,**ptr=&p;
+};
+void
+set1()
+{
+ *ptr=0;
+}
+void
+get1()
+{
+ if (!__builtin_constant_p (*ptr==0))
+ __builtin_abort ();
+}
+extern void set2();
+extern "C" void set3();
+int n = 1;
+int
+main()
+{
+ for (int i = 0; i < n; i++)
+ {
+ set1();
+ set2();
+ set3();
+ get1();
+ }
+ return 0;
+}