]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/62135 (ICE with invalid SELECT CASE selector)
authorSteven Bosscher <steven@gcc.gnu.org>
Fri, 22 Aug 2014 18:43:50 +0000 (18:43 +0000)
committerSteven Bosscher <steven@gcc.gnu.org>
Fri, 22 Aug 2014 18:43:50 +0000 (18:43 +0000)
fortran/
PR fortran/62135
* resolve.c (resolve_select): Fix list traversal in case the
last element of the CASE list was dropped as unreachable code.

testsuite/
PR fortran/62135
* gfortran.dg/pr62135.f90: New test.

From-SVN: r214351

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr62135.f90 [new file with mode: 0644]

index 1ced6fa187d94c66209757cdbcf404d32797b070..27ef1314b00971fe84d379013af562cc02dd9eeb 100644 (file)
@@ -1,3 +1,9 @@
+2014-08-22  Steven Bosscher  <steven@gcc.gnu.org>
+
+       PR fortran/62135
+       * resolve.c (resolve_select): Fix list traversal in case the
+       last element of the CASE list was dropped as unreachable code.
+
 2014-08-22  Joost VandeVondele  <Joost.VandeVondele@mat.ethz.ch>
 
        PR fortran/61234
index 32ff9dd00945c58e575ab0f295246b0fb49be0e0..52aae90ecc465416356b0a67edf9f18f0761a3db 100644 (file)
@@ -7761,7 +7761,7 @@ resolve_select (gfc_code *code, bool select_type)
        /* Strip all other unreachable cases.  */
        if (body->ext.block.case_list)
          {
-           for (cp = body->ext.block.case_list; cp->next; cp = cp->next)
+           for (cp = body->ext.block.case_list; cp && cp->next; cp = cp->next)
              {
                if (cp->next->unreachable)
                  {
index b47e090442360f3041d59fb6dd2cfda2e975ef99..a6415d6e4099f5e8cda4d69916a6b1e981d92a16 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-22  Steven Bosscher  <steven@gcc.gnu.org>
+
+       PR fortran/62135
+       * gfortran.dg/pr62135.f90: New test.
+
 2014-08-22  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        * g++.dg/warn/wdate-time.C: Remove.
diff --git a/gcc/testsuite/gfortran.dg/pr62135.f90 b/gcc/testsuite/gfortran.dg/pr62135.f90
new file mode 100644 (file)
index 0000000..d5e674b
--- /dev/null
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! { dg-options -Wsurprising }
+
+   PROGRAM PR62135
+      IMPLICIT NONE
+      CHARACTER*1 :: choice
+      choice = 'x'
+      SELECT CASE (choice)
+         ! This triggered an ICE: an unreachable case clause
+         ! as the last of a list.
+         CASE ('2':'7','9':'0') ! { dg-warning "can never be matched" }
+            WRITE(*,*) "barf"
+         CASE DEFAULT
+            CONTINUE
+      END SELECT
+   END PROGRAM PR62135
+