From 09d3f04eaea862476be3c74fd84f06ec1afb1e68 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Thu, 25 Oct 2018 14:18:28 +0200 Subject: [PATCH] ipa-devirt.c (odr_types_equivalent_p): Do not ICE if one of types is anonymous. * ipa-devirt.c (odr_types_equivalent_p): Do not ICE if one of types is anonymous. * g++.dg/lto/odr-1_0.C: New test. * g++.dg/lto/odr-1_1.C: New test. From-SVN: r265484 --- gcc/ChangeLog | 5 +++++ gcc/ipa-devirt.c | 7 +++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/lto/odr-1_0.C | 8 ++++++++ gcc/testsuite/g++.dg/lto/odr-1_1.C | 12 ++++++++++++ 5 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/g++.dg/lto/odr-1_0.C create mode 100644 gcc/testsuite/g++.dg/lto/odr-1_1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ea92a4286cc..2490eef47a5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-10-25 Jan Hubicka + + * ipa-devirt.c (odr_types_equivalent_p): Do not ICE if one of types + is anonymous. + 2018-10-25 Richard Biener PR tree-optimization/87665 diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index 9564d651b2b..466b61e5513 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -1265,6 +1265,13 @@ odr_types_equivalent_p (tree t1, tree t2, bool warn, bool *warned, /* Check first for the obvious case of pointer identity. */ if (t1 == t2) return true; + if ((type_with_linkage_p (t1) && type_in_anonymous_namespace_p (t1)) + != (type_with_linkage_p (t2) && type_in_anonymous_namespace_p (t2))) + { + warn_odr (t1, t2, NULL, NULL, warn, warned, + G_("one of types is in anonymous namespace while other is not")); + return false; + } gcc_assert (!type_with_linkage_p (t1) || !type_in_anonymous_namespace_p (t1)); gcc_assert (!type_with_linkage_p (t2) || !type_in_anonymous_namespace_p (t2)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 23b21906534..cdda13204d3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ +2018-10-25 Jan Hubicka + + * g++.dg/lto/odr-1_0.C: New test. + * g++.dg/lto/odr-1_1.C: New test. + 2018-10-25 Thomas Preud'homme + * gcc.dg/sibcall-9.c: Make v static. * gcc.dg/sibcall-10.c: Likewise. diff --git a/gcc/testsuite/g++.dg/lto/odr-1_0.C b/gcc/testsuite/g++.dg/lto/odr-1_0.C new file mode 100644 index 00000000000..c59f169e4dc --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/odr-1_0.C @@ -0,0 +1,8 @@ +// PR c++/82414 +// { dg-lto-do link } +struct a { // { dg-lto-warning "8: type 'struct a' violates the C\\+\\+ One Definition Rule" } + struct b *ptr; // { dg-lto-message "13: the first difference of corresponding definitions is field 'ptr'" } +}; +void test(struct a *) // { dg-lto-warning "6: warning: 'test' violates the C++ One Definition Rule" } +{ +} diff --git a/gcc/testsuite/g++.dg/lto/odr-1_1.C b/gcc/testsuite/g++.dg/lto/odr-1_1.C new file mode 100644 index 00000000000..5cd6f6c0ebc --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/odr-1_1.C @@ -0,0 +1,12 @@ +namespace { + struct b; + } +struct a { + struct b *ptr; +}; +void test(struct a *); +int +main(void) +{ + test (0); +} -- 2.30.2