[Bug fortran/45425] Bounds check applied before MASK of WHERE construct
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45425 Andrew Pinski changed: What|Removed |Added Keywords||diagnostic Last reconfirmed|2010-08-28 19:51:18 |2021-12-17 Known to fail|| --- Comment #4 from Andrew Pinski --- We also now get a warning since GCC 8 too: /app/example.f90:10:10: 8 | do i = 2, 2 | 2 9 | where (mask) 10 | A = b(i) | 1 Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2) /app/example.f90:10:10: 8 | do i = 2, 2 | 2 9 | where (mask) 10 | A = b(i) | 1 Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
[Bug fortran/45425] Bounds check applied before MASK of WHERE construct
--- Comment #2 from burnus at gcc dot gnu dot org 2010-08-28 15:40 --- The error message is generated in gfc_conv_array_ref it's called via gfc_trans_where_3 - gfc_conv_loop_setup - gfc_add_loop_ss_code - gfc_conv_variable Thus, the condition (mask) ends up at gfc_add_ss_to_loop (loop, css); and the bounds check is added via gfc_conv_loop_setup (loop, tdst-where); Thus, it ends up at loop-pre which comes before the actual loop. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45425
[Bug fortran/45425] Bounds check applied before MASK of WHERE construct
--- Comment #3 from mikael at gcc dot gnu dot org 2010-08-28 17:42 --- Ouch! We need some sort of lazy evaluation. Like (pseudo-code) bool scalar_ever_evaluated = false; whatever_type scalar_value; while(1) { /* loop handling stuff */ if (scalar_ever_evaluated) { scalar_value = whatever complicated expression; scalar_ever_evaluated = true; } /* normal code using scalar_value */ } We have to move back se-pre into se-expr so that it is not moved outside the loop. Or move it outside the loop conditionally and conditionally add se-pre inside the loop while evaluating the scalar. BTW I thought there was already some where-specific code generation for scalar values. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45425
[Bug fortran/45425] Bounds check applied before MASK of WHERE construct
-- tkoenig at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Last reconfirmed|-00-00 00:00:00 |2010-08-28 19:51:18 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45425
[Bug fortran/45425] Bounds check applied before MASK of WHERE construct
--- Comment #1 from burnus at gcc dot gnu dot org 2010-08-27 11:58 --- Confirm, the bounds checks are misplaces. Simplified test case: implicit none integer :: A(1), i,b(1) logical :: mask(1) mask = .false. b = 5 do i = 2, 2 where (mask) A = b(i) end where end do end If one looks at the dump of the internal representation (-fdump-tree-original) one sees that WHERE itself is properly handled - only the bounds check is outside of the WHERE loop and thus outside of the MASK: if (__builtin_expect (i = 0, 0)) _gfortran_runtime_error_at (...); [...] S.1 = 1; while (1) { if (S.1 1) goto L.4; if (mask[S.1 + -1]) { a[S.1 + -1] = b[i + -1]; } S.1 = S.1 + 1; } -- burnus at gcc dot gnu dot org changed: What|Removed |Added OtherBugsDependingO||27766 nThis|| Keywords||wrong-code Known to fail||4.1.2 4.6.0 Summary|where mask not applied |Bounds check applied before |before where clause |MASK of WHERE construct |evaluated | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45425