aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJan Hubicka <hubicka@ucw.cz>2019-07-18 15:08:34 +0200
committerJan Hubicka <hubicka@gcc.gnu.org>2019-07-18 13:08:34 +0000
commitb01659aa867a8fee932ef389f5066495f531da77 (patch)
treec3b88991d6d9777e8b430b6e22e4e6b621e177af /gcc
parent3796e3b399875dac8e6d100c7fe662a91a39ba42 (diff)
downloadgcc-b01659aa867a8fee932ef389f5066495f531da77.zip
gcc-b01659aa867a8fee932ef389f5066495f531da77.tar.gz
gcc-b01659aa867a8fee932ef389f5066495f531da77.tar.bz2
lto-common.c (gimple_register_canonical_type_1): Do not look for non-ODR conflicts of types in anonymous namespaces.
* lto-common.c (gimple_register_canonical_type_1): Do not look for non-ODR conflicts of types in anonymous namespaces. (unify_scc): Do not merge anonymous namespace types. * g++.dg/lto/alias-5_0.C: New testcase. * g++.dg/lto/alias-5_1.C: New. * g++.dg/lto/alias-5_2.c: New. From-SVN: r273571
Diffstat (limited to 'gcc')
-rw-r--r--gcc/lto/ChangeLog6
-rw-r--r--gcc/lto/lto-common.c27
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/lto/alias-5_0.C35
-rw-r--r--gcc/testsuite/g++.dg/lto/alias-5_1.C9
-rw-r--r--gcc/testsuite/g++.dg/lto/alias-5_2.c7
6 files changed, 81 insertions, 9 deletions
diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog
index 83d166d..22e7739 100644
--- a/gcc/lto/ChangeLog
+++ b/gcc/lto/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-18 Jan Hubicka <hubicka@ucw.cz>
+
+ * lto-common.c (gimple_register_canonical_type_1): Do not look for
+ non-ODR conflicts of types in anonymous namespaces.
+ (unify_scc): Do not merge anonymous namespace types.
+
2019-07-09 Martin Sebor <msebor@redhat.com>
PR c++/61339
diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c
index c9d9781..ef2d02a 100644
--- a/gcc/lto/lto-common.c
+++ b/gcc/lto/lto-common.c
@@ -418,13 +418,19 @@ gimple_register_canonical_type_1 (tree t, hashval_t hash)
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;
@@ -1640,11 +1646,14 @@ unify_scc (class data_in *data_in, unsigned from,
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. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0bbbd8a..0f47604 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-18 Jan Hubicka <hubicka@ucw.cz>
+
+ * g++.dg/lto/alias-5_0.C: New testcase.
+ * g++.dg/lto/alias-5_1.C: New.
+ * g++.dg/lto/alias-5_2.c: New.
+
2019-07-18 Bin Cheng <bin.linux@linux.alibaba.com>
PR tree-optimization/91137
diff --git a/gcc/testsuite/g++.dg/lto/alias-5_0.C b/gcc/testsuite/g++.dg/lto/alias-5_0.C
new file mode 100644
index 0000000..779cc39
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/alias-5_0.C
@@ -0,0 +1,35 @@
+/* { 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;
+}
diff --git a/gcc/testsuite/g++.dg/lto/alias-5_1.C b/gcc/testsuite/g++.dg/lto/alias-5_1.C
new file mode 100644
index 0000000..f12bd56
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/alias-5_1.C
@@ -0,0 +1,9 @@
+namespace {
+ __attribute__((used))
+ struct a {int a;} *p,**ptr=&p,q;
+};
+void
+set2()
+{
+ *ptr=&q;
+}
diff --git a/gcc/testsuite/g++.dg/lto/alias-5_2.c b/gcc/testsuite/g++.dg/lto/alias-5_2.c
new file mode 100644
index 0000000..d126833
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/alias-5_2.c
@@ -0,0 +1,7 @@
+ __attribute__((used))
+ struct a {int a;} *p,**ptr=&p,q;
+void
+set3()
+{
+ *ptr=&q;
+}