]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: add check for type of upper bound in case range
authorHarald Anlauf <anlauf@gmx.de>
Mon, 6 Dec 2021 22:15:11 +0000 (23:15 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 7 Dec 2021 17:23:25 +0000 (18:23 +0100)
gcc/fortran/ChangeLog:

PR fortran/103591
* match.c (match_case_selector): Check type of upper bound in case
range.

gcc/testsuite/ChangeLog:

PR fortran/103591
* gfortran.dg/select_9.f90: New test.

gcc/fortran/match.c
gcc/testsuite/gfortran.dg/select_9.f90 [new file with mode: 0644]

index 2bf21434a42a017ef93c52b5384ca21d771a5eaf..52bc5af75422d8ce92c653396adc6b2b1d8c2fb2 100644 (file)
@@ -6075,6 +6075,15 @@ match_case_selector (gfc_case **cp)
          m = gfc_match_init_expr (&c->high);
          if (m == MATCH_ERROR)
            goto cleanup;
+         if (m == MATCH_YES
+             && c->high->ts.type != BT_LOGICAL
+             && c->high->ts.type != BT_INTEGER
+             && c->high->ts.type != BT_CHARACTER)
+           {
+             gfc_error ("Expression in CASE selector at %L cannot be %s",
+                        &c->high->where, gfc_typename (c->high));
+             goto cleanup;
+           }
          /* MATCH_NO is fine.  It's OK if nothing is there!  */
        }
     }
diff --git a/gcc/testsuite/gfortran.dg/select_9.f90 b/gcc/testsuite/gfortran.dg/select_9.f90
new file mode 100644 (file)
index 0000000..c580e81
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR fortran/103591 - ICE in gfc_compare_string
+! Contributed by G.Steinmetz
+
+program p
+  integer :: n
+  select case (n)
+  case ('1':2.)   ! { dg-error "cannot be REAL" }
+  end select
+end