I finally reproduced the bug on native darwin and it is caused
by early -g making dwarf2out.c to set self-DECL_ABSTRACT_ORIGIN
which late dwarf2out.c barfs on when we do not have actual
early DIEs available.

The "fix" is to not make late dwarf2out.c think it has already
emitted early DIEs.

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

Richard.

2019-01-24  Richard Biener  <rguent...@suse.de>

        PR lto/87187
        * tree-streamer-out.c (write_ts_decl_common_tree_pointers):
        When in "legacy" debug mode make sure to reset self-origins.

Index: gcc/tree-streamer-out.c
===================================================================
--- gcc/tree-streamer-out.c     (revision 268234)
+++ gcc/tree-streamer-out.c     (working copy)
@@ -603,7 +603,16 @@ write_ts_decl_common_tree_pointers (stru
      special handling in LTO, it must be handled by streamer hooks.  */
 
   stream_write_tree (ob, DECL_ATTRIBUTES (expr), ref_p);
-  stream_write_tree (ob, DECL_ABSTRACT_ORIGIN (expr), ref_p);
+
+  /* On non-early-LTO enabled targets we claim we compiled with -g0
+     but dwarf2out still did its set_decl_origin_self game fooling
+     itself late.  Und that here since we won't have access to the
+     early generated abstract DIEs.  */
+  tree ao = DECL_ABSTRACT_ORIGIN (expr);
+  if (debug_info_level == DINFO_LEVEL_NONE
+      && ao == expr)
+    ao = NULL_TREE;
+  stream_write_tree (ob, ao, ref_p);
 
   if ((VAR_P (expr) || TREE_CODE (expr) == PARM_DECL)
       && DECL_HAS_VALUE_EXPR_P (expr))

Reply via email to