diff mbox

PR fortran/62135

Message ID CABu31nNejj+0QWpWTLDvywn1RWwM3N7G0WTm-VY9iyfH+OeDRg@mail.gmail.com
State New
Headers show

Commit Message

Steven Bosscher Aug. 21, 2014, 10:07 p.m. UTC
Hello,

Low-hanging fruit, almost embarassing to fix. But then again I caused
this bug -- in 1999 or so :-)

Will commit after testing.

Ciao!
Steven


fortran/
        * resolve.c (resolve_select): Fix list traversal in case the
        last element of the CASE list was dropped as unreachable code.

testsuite/
        * gfortran.dg/pr62135.f90: New test.

Comments

Steve Kargl Aug. 21, 2014, 10:14 p.m. UTC | #1
On Fri, Aug 22, 2014 at 12:07:21AM +0200, Steven Bosscher wrote:
> Hello,
> 
> Low-hanging fruit, almost embarassing to fix. But then again I caused
> this bug -- in 1999 or so :-)
> 
> Will commit after testing.
> 

I already approved the patch in the PR.  In my comment
on the PR I had assumed you were bored and found a Fortran
bug to fix.  Now, I see it is just guilt!
diff mbox

Patch

Index: fortran/resolve.c
===================================================================
--- fortran/resolve.c   (revision 214292)
+++ fortran/resolve.c   (working copy)
@@ -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: testsuite/gfortran.dg/pr62135.f90
===================================================================
--- testsuite/gfortran.dg/pr62135.f90   (revision 0)
+++ testsuite/gfortran.dg/pr62135.f90   (working copy)
@@ -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
+