This adds a workaround for LTO decl merging prevailing a
non-ultimate origin decl, breaking invariants of the middle-end.
In the future (GCC 10) I hope to have DIE references here so
this will not be an issue there anymore.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

>From ff035da8314ea8e0889b99bb338e67dd5dae455b Mon Sep 17 00:00:00 2001
From: Richard Guenther <rguent...@suse.de>
Date: Wed, 7 Nov 2018 08:56:52 +0100
Subject: [PATCH] fix-pr87906

2018-11-07  Richard Biener  <rguent...@suse.de>

        PR lto/87906
        * tree-streamer-in.c (lto_input_ts_block_tree_pointers): Fixup
        BLOCK_ABSTRACT_ORIGIN to be the ultimate origin.

        * g++.dg/lto/pr87906_0.C: New testcase.
        * g++.dg/lto/pr87906_1.C: Likewise.

diff --git a/gcc/testsuite/g++.dg/lto/pr87906_0.C 
b/gcc/testsuite/g++.dg/lto/pr87906_0.C
new file mode 100644
index 00000000000..08e7ed3ba07
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr87906_0.C
@@ -0,0 +1,35 @@
+// { dg-lto-do link }
+// { dg-lto-options { { -O -fPIC -flto } } }
+// { dg-extra-ld-options "-shared -nostdlib" }
+
+namespace com {
+namespace sun {
+namespace star {}
+} // namespace sun
+} // namespace com
+namespace a = com::sun::star;
+namespace com {
+namespace sun {
+namespace star {
+namespace uno {
+class a {
+public:
+  ~a();
+};
+
+class b {
+public:
+  ~b();
+  a c;
+};
+class c {
+  b e;
+};
+class RuntimeException : b {};
+} // namespace uno
+} // namespace star
+} // namespace sun
+} // namespace com
+template <typename> void d(int) { throw a::uno::RuntimeException(); }
+int f;
+void g() { d<a::uno::b>(f); }
diff --git a/gcc/testsuite/g++.dg/lto/pr87906_1.C 
b/gcc/testsuite/g++.dg/lto/pr87906_1.C
new file mode 100644
index 00000000000..ee5849fd604
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr87906_1.C
@@ -0,0 +1,23 @@
+namespace com {
+namespace sun {
+namespace star {
+namespace uno {
+class a {
+public:
+  ~a();
+};
+class b {
+public:
+~b();
+  a c;
+};
+class RuntimeException : b {};
+} // namespace uno
+class C : uno::RuntimeException {};
+} // namespace star
+} // namespace sun
+} // namespace com
+using com::sun::star::C;
+using com::sun::star::uno::RuntimeException;
+void d() { throw RuntimeException(); }
+void e() { C(); }
diff --git a/gcc/tree-streamer-in.c b/gcc/tree-streamer-in.c
index bd98ed0b128..5c989a221cd 100644
--- a/gcc/tree-streamer-in.c
+++ b/gcc/tree-streamer-in.c
@@ -915,6 +915,12 @@ lto_input_ts_block_tree_pointers (struct lto_input_block 
*ib,
 
   BLOCK_SUPERCONTEXT (expr) = stream_read_tree (ib, data_in);
   BLOCK_ABSTRACT_ORIGIN (expr) = stream_read_tree (ib, data_in);
+  /* We may end up prevailing a decl with DECL_ORIGIN (t) != t here
+     which breaks the invariant that BLOCK_ABSTRACT_ORIGIN is the
+     ultimate origin.  Fixup here.
+     ???  This should get fixed with moving to DIE references.  */
+  if (DECL_P (BLOCK_ORIGIN (expr)))
+    BLOCK_ABSTRACT_ORIGIN (expr) = DECL_ORIGIN (BLOCK_ABSTRACT_ORIGIN (expr));
   /* Do not stream BLOCK_NONLOCALIZED_VARS.  We cannot handle debug information
      for early inlined BLOCKs so drop it on the floor instead of ICEing in
      dwarf2out.c.  */

Reply via email to