]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix fortran common-related error recovery ICE.
authormikael <mikael@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 4 Oct 2015 12:30:16 +0000 (12:30 +0000)
committermikael <mikael@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 4 Oct 2015 12:30:16 +0000 (12:30 +0000)
Upon reverting a symbol in a common block (after throwing an error),
the compiler was ICEing because the symbol's common_block field was set,
but the symbol was not in the common block's list of symbols.

Fixed by both adding the symbol to the common block list and setting
the symbol's common_block field at the same time.
Furthermore, the gfc_add_in_common call is delayed and its result is
ignored, so that its error messages are ignored and the compiler has
the opportunity to give a better error message.
Another gfc_add_in_common call is added later during resolution
to emit again the missing errors.

PR fortran/67758
gcc/fortran/
* match.c (gfc_match_common): Delay the common_block pointer
assignment after error checking.
Delay the call to gfc_add_in_common attribute after the handling
of array specs.
* resolve.c (resolve_common_vars): Call gfc_add_in_common again.
gcc/testsuite/
* gfortran.dg/common_24.f: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@228457 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/match.c
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/common_24.f [new file with mode: 0644]

index 014d67c621f7cbbf12c546ff1e2a28a70ac40587..cdf27b2e295815e3161bac970ae6704a1bf2bbef 100644 (file)
@@ -1,3 +1,12 @@
+2015-10-04  Mikael Morin  <mikael@gcc.gnu.org>
+
+       PR fortran/67758
+       * match.c (gfc_match_common): Delay the common_block pointer
+       assignment after error checking.
+       Delay the call to gfc_add_in_common attribute after the handling
+       of array specs.
+       * resolve.c (resolve_common_vars): Call gfc_add_in_common again.
+
 2015-10-04  Mikael Morin  <mikael@gcc.gnu.org>
 
        * resolve.c (resolve_common_vars): Move access to the common
 
        * resolve.c (nonscalar_typebound_assign): Fix typos in comment.
 
-
 2015-09-21  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/67615
index a50ec2d13515aee8b334801cec82fb454bd76a16..2363004208bb4f700dbcc321974247fe276c6216 100644 (file)
@@ -4330,10 +4330,6 @@ gfc_match_common (void)
          if (m == MATCH_NO)
            goto syntax;
 
-          /* Store a ref to the common block for error checking.  */
-          sym->common_block = t;
-          sym->common_block->refs++;
-
           /* See if we know the current common block is bind(c), and if
              so, then see if we can check if the symbol is (which it'll
              need to be).  This can happen if the bind(c) attr stmt was
@@ -4376,8 +4372,8 @@ gfc_match_common (void)
                goto cleanup;
            }
 
-         if (!gfc_add_in_common (&sym->attr, sym->name, NULL))
-           goto cleanup;
+         sym->common_block = t;
+         sym->common_block->refs++;
 
          if (tail != NULL)
            tail->common_next = sym;
@@ -4416,6 +4412,10 @@ gfc_match_common (void)
 
            }
 
+         /* Add the in_common attribute, but ignore the reported errors
+            if any, and continue matching.  */
+         gfc_add_in_common (&sym->attr, sym->name, NULL);
+
          sym->common_head = t;
 
          /* Check to see if the symbol is already in an equivalence group.
index 614d8a99072cc4f22f7b6f1d808f419d6804853b..e75c29302288effc7f4017a42a653401130b8ece 100644 (file)
@@ -918,6 +918,12 @@ resolve_common_vars (gfc_common_head *common_block, bool named_common)
 
   for (; csym; csym = csym->common_next)
     {
+      /* gfc_add_in_common may have been called before, but the reported errors
+        have been ignored to continue parsing.
+        We do the checks again here.  */
+      if (!csym->attr.use_assoc)
+       gfc_add_in_common (&csym->attr, csym->name, &common_block->where);
+
       if (csym->value || csym->attr.data)
        {
          if (!csym->ns->is_block_data)
index 47b79f00b055391c75142e5e66c51211df8415d3..85d593da93fbda97d4e4812215b4be9bbfb9d3d4 100644 (file)
@@ -1,3 +1,8 @@
+2015-10-04  Mikael Morin  <mikael@gcc.gnu.org>
+
+       PR fortran/67758
+       * gfortran.dg/common_24.f: New.
+
 2015-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        * gcc.target/arm/pr67756.c: Fixed warnings.
diff --git a/gcc/testsuite/gfortran.dg/common_24.f b/gcc/testsuite/gfortran.dg/common_24.f
new file mode 100644 (file)
index 0000000..ea37c2a
--- /dev/null
@@ -0,0 +1,11 @@
+c { dg-do compile }
+c PR fortran/67758
+c
+c Check the absence of ICE after emitting the error message
+c
+c Contributed by Ilya Enkovich <ienkovich@gcc.gnu.org>
+
+      COMMON /FMCOM / X(80 000 000)
+      CALL T(XX(A))
+      COMMON /FMCOM / XX(80 000 000) ! { dg-error "Unexpected COMMON" }
+      END