The following code produces an ICE for me: program test implicit none integer :: i i = 3 print *, "chk", 3/(i-i) end program test This should presumably produce Error: Division by zero at compile time (or run time if we're not being clever). Produced with: GNU Fortran (Debian 4.6.1-4) 4.6.1 Copyright (C) 2011 Free Software Foundation, Inc. Thanks, Jonathan.
-fdump-tree-original: static integer(kind=4) C.1534 = 3 / 0; _gfortran_transfer_integer_write (&dt_parm.0, &C.1534, 4); It gives with 4.7 the ICE: internal compiler error: in copy_constant, at varasm.c:3031 I think it is - at least in general - not be detectable in the front end but only in the ME. A similar C test case works (cf. below for a simpler version); I think there is no compiler option to print a warning -- at least -Wall -Wextra don't. int main () { int i = 3; printf ("%d\n", 3/(i-i)); return 0; }
Here's a variation on the original code, which removes the print statement. One does not need to wade through gfortran IO structure. program test implicit none integer i i = 3 call foo (3 / (i - i)) end program test subroutine foo(j) j = j * 1 end subroutine foo The dump shows foo (integer(kind=4) & restrict j) { *j = NON_LVALUE_EXPR <*j>; } test () { integer(kind=4) i; i = 3; { static integer(kind=4) C.1729 = 3 / 0; foo (&C.1729); } } An equivalent C program compiles and gives a nearly identical dump, but dies with a Floating exception(?) troutmask:sgk[247] cat dw.c void foo (int *j) { *j = *j * 2; } int main() { static int i = 3; i = 3 / (i - i); foo(&i); return 0; } troutmask:sgk[248] ~/work/4x/bin/gcc -o z dw.c && ./z Floating exception (core dumped)
The ICE has been fixed between revisions r250529 and r250610.
Fixed.