public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/45425] Bounds check applied before MASK of WHERE construct
       [not found] <bug-45425-4@http.gcc.gnu.org/bugzilla/>
@ 2021-12-18  1:26 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-18  1:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45425

Andrew Pinski <pinskia at gcc dot gnu.org> 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 <pinskia at gcc dot gnu.org> ---
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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/45425] Bounds check applied before MASK of WHERE construct
  2010-08-27 10:03 [Bug fortran/45425] New: where mask not applied before where clause evaluated aronaldg at gmail dot com
                   ` (2 preceding siblings ...)
  2010-08-28 17:43 ` mikael at gcc dot gnu dot org
@ 2010-08-28 19:51 ` tkoenig at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2010-08-28 19:51 UTC (permalink / raw)
  To: gcc-bugs



-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-08-28 19:51:18
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45425


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/45425] Bounds check applied before MASK of WHERE construct
  2010-08-27 10:03 [Bug fortran/45425] New: where mask not applied before where clause evaluated aronaldg at gmail dot com
  2010-08-27 11:58 ` [Bug fortran/45425] Bounds check applied before MASK of WHERE construct burnus at gcc dot gnu dot org
  2010-08-28 15:40 ` burnus at gcc dot gnu dot org
@ 2010-08-28 17:43 ` mikael at gcc dot gnu dot org
  2010-08-28 19:51 ` tkoenig at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: mikael at gcc dot gnu dot org @ 2010-08-28 17:43 UTC (permalink / raw)
  To: gcc-bugs



------- 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/45425] Bounds check applied before MASK of WHERE construct
  2010-08-27 10:03 [Bug fortran/45425] New: where mask not applied before where clause evaluated aronaldg at gmail dot com
  2010-08-27 11:58 ` [Bug fortran/45425] Bounds check applied before MASK of WHERE construct burnus at gcc dot gnu dot org
@ 2010-08-28 15:40 ` burnus at gcc dot gnu dot org
  2010-08-28 17:43 ` mikael at gcc dot gnu dot org
  2010-08-28 19:51 ` tkoenig at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-28 15:40 UTC (permalink / raw)
  To: gcc-bugs



------- 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/45425] Bounds check applied before MASK of WHERE construct
  2010-08-27 10:03 [Bug fortran/45425] New: where mask not applied before where clause evaluated aronaldg at gmail dot com
@ 2010-08-27 11:58 ` burnus at gcc dot gnu dot org
  2010-08-28 15:40 ` burnus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-27 11:58 UTC (permalink / raw)
  To: gcc-bugs



------- 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-18  1:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-45425-4@http.gcc.gnu.org/bugzilla/>
2021-12-18  1:26 ` [Bug fortran/45425] Bounds check applied before MASK of WHERE construct pinskia at gcc dot gnu.org
2010-08-27 10:03 [Bug fortran/45425] New: where mask not applied before where clause evaluated aronaldg at gmail dot com
2010-08-27 11:58 ` [Bug fortran/45425] Bounds check applied before MASK of WHERE construct burnus at gcc dot gnu dot org
2010-08-28 15:40 ` burnus at gcc dot gnu dot org
2010-08-28 17:43 ` mikael at gcc dot gnu dot org
2010-08-28 19:51 ` tkoenig at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).