From: Steven G. Kargl Date: Mon, 21 Sep 2015 18:09:13 +0000 (+0000) Subject: re PR fortran/67615 (ICE on using arithmetic if with array instead of scalar) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e2eb0806eaed00661cf7bc5b5d60798aa37dc712;p=gcc.git re PR fortran/67615 (ICE on using arithmetic if with array instead of scalar) 2015-09-21 Steven G. Kargl PR fortran/67615 * resolve.c (gfc_resolve_code): Check for scalar expression in arithmetic-if. 2015-09-21 Steven G. Kargl PR fortran/67615 * gfortran.dg/pr67615.f90: new test. From-SVN: r227981 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index ee6db56529d..a3b44423344 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2015-09-21 Steven G. Kargl + + PR fortran/67615 + * resolve.c (gfc_resolve_code): Check for scalar expression in + arithmetic-if. + 2015-09-17 Paul Thomas PR fortran/52846 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index a3041589df9..da8aaa1ae7b 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -10377,15 +10377,18 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) } case EXEC_ARITHMETIC_IF: - if (t - && code->expr1->ts.type != BT_INTEGER - && code->expr1->ts.type != BT_REAL) - gfc_error ("Arithmetic IF statement at %L requires a numeric " - "expression", &code->expr1->where); + { + gfc_expr *e = code->expr1; - resolve_branch (code->label1, code); - resolve_branch (code->label2, code); - resolve_branch (code->label3, code); + if (t && (e->rank > 0 + || !(e->ts.type == BT_REAL || e->ts.type == BT_INTEGER))) + gfc_error ("Arithmetic IF statement at %L requires a scalar " + "REAL or INTEGER expression", &code->expr1->where); + + resolve_branch (code->label1, code); + resolve_branch (code->label2, code); + resolve_branch (code->label3, code); + } break; case EXEC_IF: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7afd523d80a..8e642a852a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-21 Steven G. Kargl + + PR fortran/67615 + * gfortran.dg/pr67615.f90: new test. + 2015-09-21 Jeff Law * gcc.target/h8300/andsi3_ashift_n_lower.c: New test. diff --git a/gcc/testsuite/gfortran.dg/pr67615.f90 b/gcc/testsuite/gfortran.dg/pr67615.f90 new file mode 100644 index 00000000000..fb95958007f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr67615.f90 @@ -0,0 +1,33 @@ +! { dg-do compile } +! { dg-options "-std=legacy" } +! PR fortran/67615 +! +program foo + + implicit none + + integer i(2), j + real x + complex z + + j = 2 + if (j) 10, 20, 30 + + x = -1 + if (x) 10, 20, 30 + + z = (1,2) + if (z) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + + i = [1, 2] + if (i) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + + if ( [1] ) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + if ( [1, -1] ) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + if ( [real :: 1, -1] ) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + +10 stop +20 stop +30 stop + +end program foo