https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66459
Thomas Koenig <tkoenig at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2015-06-08 00:00:00 |2019-2-3 CC| |tkoenig at gcc dot gnu.org Component|fortran |middle-end --- Comment #4 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- The code that gfortran generates is correct, it is just that the middle-end does not quite understand it and generates a warning for it. The -fdump-tree-original dump shows if (*l) { { [...] w.dtype = {.elem_len=4, .rank=2, .type=1}; D.3881 = (integer(kind=8)) MAX_EXPR <*m, 0>; D.3882 = NON_LVALUE_EXPR <__builtin_expect ((integer(kind=8)) (D.3881 == 0), 0, 46) ? 0 : __builtin_expect ((integer(kind=8)) (9223372036854775807 / D.3881 <= 0), 0, 41) ? 1 : 0>; D.3883 = NON_LVALUE_EXPR <D.3881>; D.3884 = (integer(kind=8)) MAX_EXPR <*n, 0>; D.3885 = (__builtin_expect ((integer(kind=8)) (D.3884 == 0), 0, 46) ? 0 : __builtin_expect ((integer(kind=8)) (9223372036854775807 / D.3884 < D.3883), 0, 41) ? 1 : 0) + D.3882; D.3886 = D.3883 * D.3884; D.3887 = D.3886; D.3888 = (__builtin_expect ((integer(kind=8)) ((unsigned long) D.3886 > 4611686018427387903), 0, 41) ? 1 : 0) + D.3885; D.3889 = ~NON_LVALUE_EXPR <D.3883>; if (D.3891) { size.0 = 0; } else { size.0 = (unsigned long) D.3886 * 4; } overflow.1 = D.3888; if (__builtin_expect ((integer(kind=8)) (overflow.1 != 0), 0, 41)) { _gfortran_runtime_error (&"Ganzzahl\xc3\xbcberlauf bei der Berechnung des zu reservierenden Speichers"[1]{lb: 1 sz: 1}); } else { if (__builtin_expect ((integer(kind=8)) (w.data != 0B), 0, 43)) { _gfortran_runtime_error_at (&"At line 9 of file b.f"[1]{lb: 1 sz: 1}, &"Versuch, bereits reservierte Variable \xc2\xbb%s\xc2\xab zu reservieren"[1]{lb: 1 sz: 1}, &"w"[1]{lb: 1 sz: 1}); } else { w.data = (void * restrict) __builtin_malloc (MAX_EXPR <size.0, 1>); if (__builtin_expect ((integer(kind=8)) (w.data == 0B), 0, 42)) { _gfortran_os_error (&"Reservierung w\xc3\xbcrde Speichergrenze \xc3\xbcberschreiten"[1]{lb: 1 sz: 1}); } } } w.dim[0].lbound = 1; w.dim[0].ubound = (integer(kind=8)) *m; w.dim[0].stride = 1; w.dim[1].lbound = 1; w.dim[1].ubound = (integer(kind=8)) *n; w.dim[1].stride = D.3883; w.offset = D.3889; } } and then if ((integer(kind=4)[0:] * restrict) w.data != 0B) { (*(integer(kind=4)[0:] * restrict) w.data)[(w.offset + (integer(kind=8)) i * w.dim[1].stride) + (integer(kind=8)) j] = 0; Now, the thing is that, on leaving the if (*l) block, data has to be non-zero, otherwise _gfortran_os_error would have been called (which is marked with TREE_THIS_VOLATILE, hence noreturn). So, the variables Is there something the Fortran front end can do better? If not, I think this is better classified as a middle-end bug.