diff gcc/testsuite/gfortran.dg/dec_union_6.f90 @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gfortran.dg/dec_union_6.f90	Fri Oct 27 22:46:09 2017 +0900
@@ -0,0 +1,59 @@
+! { dg-do run }
+! { dg-options "-fdec-structure" }
+!
+! sub0 and sub1 test a regression where calling gfc_use_derived from
+! gfc_find_component on the structure type symbol being parsed caused the
+! symbol to be freed and swapped for the previously seen type symbol, leaving
+! dangling pointers and causing all sorts of mayhem.
+!
+
+subroutine sub0 (u)
+  structure /s/
+    union ! U0
+      map ! M0
+        integer i
+      end map
+    end union
+  end structure
+  record /s/ u
+  u.i = 0
+end subroutine sub0
+
+subroutine sub1 ()
+  structure /s/
+    union ! U1
+      map ! M1
+        integer i
+      end map
+    end union
+  end structure
+  record /s/ u
+  interface ! matches the declaration of sub0 above
+    subroutine sub0 (u)
+      structure /s/
+        union ! U2
+          map ! M2
+            integer i ! gfc_find_component should not call gfc_use_derived
+          end map     ! here, otherwise this structure's type symbol is freed
+        end union     ! out from under it
+      end structure
+      record /s/ u
+    end subroutine sub0
+  end interface
+  call sub0(u)
+end subroutine
+
+! If sub0 and sub1 aren't used they may be omitted
+structure /s/
+  union ! U1
+    map ! M3
+      integer i
+    end map
+  end union
+end structure
+record /s/ u
+
+call sub0(u)
+call sub1()
+
+end