The following fixes an ICE that occurs when with -flto you disable
debug at compile-time but enable it at link-time.  Then we end up
adding a second DW_AT_type to VLA DIEs - the following guards against
this.

Bootstrap and regtest running on x86_64-unknown-linux-gnu, testing in
progress.

Darwin support might be the vehicle exercising this -g0 vs. -g
combination a lot...

Richard.

2018-03-01  Richard Biener  <rguent...@suse.de>

        PR debug/84645
        * dwarf2out.c (gen_variable_die): Properly handle late VLA
        type annotation with LTO when debug was disabled at compile-time.

        * gfortran.dg/lto/pr84645_0.f90: New testcase.

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c     (revision 258097)
+++ gcc/dwarf2out.c     (working copy)
@@ -23527,10 +23527,12 @@ gen_variable_die (tree decl, tree origin
 
          /* ???  In LTRANS we cannot annotate early created variably
             modified type DIEs without copying them and adjusting all
-            references to them.  Thus we dumped them again, also add a
-            reference to them.  */
+            references to them.  Thus we dumped them again.  Also add a
+            reference to them but beware of -g0 compile and -g link
+            in which case the reference will be already present.  */
          tree type = TREE_TYPE (decl_or_origin);
          if (in_lto_p
+             && ! get_AT (var_die, DW_AT_type)
              && variably_modified_type_p
                   (type, decl_function_context (decl_or_origin)))
            {
Index: gcc/testsuite/gfortran.dg/lto/pr84645_0.f90
===================================================================
--- gcc/testsuite/gfortran.dg/lto/pr84645_0.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/lto/pr84645_0.f90 (working copy)
@@ -0,0 +1,17 @@
+! { dg-lto-do link }
+! { dg-lto-options { { -flto -g0 } } }
+! { dg-extra-ld-options { -g } }
+program nml_test
+  implicit none
+  type t
+    integer :: c1
+    integer :: c2(3)
+  end type t
+  call test2(2) 
+contains
+  subroutine test2(n)
+    integer :: n
+    type(t) :: x12(n)
+    namelist /nml2/ x12
+  end subroutine test2
+end program nml_test

Reply via email to