diff mbox

[committed] Fix for multiple anonymous structures conflict with -fdec-structure

Message ID CAE4aFAnfVwxyhkvY99EJUg3E5XB6VM76RV=B3Yq2mrBt-iBoKA@mail.gmail.com
State New
Headers show

Commit Message

Fritz Reese Aug. 23, 2016, 7:41 p.m. UTC
Found another silly typo in my structure/union patch.

With anonymous nested structures, as with unions and maps (which are
inherently anonymous), a static counter is used to give each type
definition a unique name. Due to a typo the counter for anonymous
structures was not static, therefore was simply zero for each
invocation of decl.c (gfc_match_structure_decl). Thus only one
anonymous structure declaration could be used per program, as multiple
anonymous structure definitions would be given the same name, causing
the compiler to complain about conflicting type definitions.

Committed the attached as obvious as r239709 - includes testcase
exhibiting the regression.

---
Fritz Reese

2016-08-23  Fritz Reese  <fritzoreese@gmail.com>

        gcc/fortran/
        * decl.c (gfc_match_structure_decl): Make gfc_structure_id static.

        gcc/testsuite/gfortran.dg/
        * dec_structure_12.f90: New testcase.
diff mbox

Patch

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 66158b9..24bd374 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -8626,7 +8626,7 @@  match
 gfc_match_structure_decl (void)
 {
     /* Counter used to give unique internal names to anonymous structures.  */
-    int gfc_structure_id = 0;
+    static unsigned int gfc_structure_id = 0;
     char name[GFC_MAX_SYMBOL_LEN + 1];
     gfc_symbol *sym;
     match m;
diff --git a/gcc/testsuite/gfortran.dg/dec_structure_12.f90 b/gcc/testsuite/gfortran.dg/dec_structure_12.f90
new file mode 100644
index 0000000..b6cc5aa
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_structure_12.f90
@@ -0,0 +1,27 @@ 
+! { dg-do "compile" }
+! { dg-options "-fdec-structure" }
+!
+! Test a regression where multiple anonymous structures failed to
+! receive unique internal names.
+!
+
+implicit none
+
+structure /s/
+
+  structure record0 ! (2)
+    integer i
+  end structure
+
+  structure record1 ! regression: Type definition was already defined at (2)
+    real r
+  end structure
+
+end structure
+
+record /s/ var
+
+var.record0.i = 0
+var.record1.r = 0.0
+
+end