public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/108741] New: [OpenMP] Wrong code for lastprivate with pointer iteration variable
@ 2023-02-09 12:35 burnus at gcc dot gnu.org
  2023-02-09 12:39 ` [Bug fortran/108741] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2023-02-09 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108741
           Summary: [OpenMP] Wrong code for lastprivate with pointer
                    iteration variable
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

The motivation is Fortran code, based on
  libgomp/testsuite/libgomp.fortran/non-rectangular-loop-3.f90
for PR107424 and with the patch applied from
  https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610584.html

However, the issue is preexisting and probably fails already since
ever.

It shows also up with a questionable C code, which tries to mimic the Fortran
code. The problem is that '**a0' in the loop body points to invalid memory.

//----- (questionable) C testcase ------

void foo(int **a1) {
  int j, a0;
  #pragma omp simd collapse(2) lastprivate(a0,a1,j)
  for (a0 = 1; a0 <= 10; a0++)
    for (j = 1; j <= 20; j++)
      **a1 = a0;    /// Segfaults here as *a0 points to invalid memory
  if (**a1 != 10 || j != 21 || a0 != 11)
    __builtin_abort ();
}

int main() {
  int *a1, a2;
  a2 = 5;
  a1 = &a2;
  foo (&a1);
  return 0;
}


! Fortran testcase
  implicit none
  integer, pointer :: a1
  allocate(a1)
  call o(a1)
contains
  subroutine o(a1)
    implicit none
    integer :: j
    integer, pointer :: a1
    !$omp simd collapse(2) lastprivate(a1,j)
      do a1 = 1, 10
        do j = 1, 20
        end do
      end do
    if (a1 /= 11 .or. j /= 21) error stop
  end
end

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

* [Bug fortran/108741] [OpenMP] Wrong code for lastprivate with pointer iteration variable
  2023-02-09 12:35 [Bug fortran/108741] New: [OpenMP] Wrong code for lastprivate with pointer iteration variable burnus at gcc dot gnu.org
@ 2023-02-09 12:39 ` jakub at gcc dot gnu.org
  2023-02-09 14:12 ` burnus at gcc dot gnu.org
  2023-02-09 14:12 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-09 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
  #pragma omp simd collapse(2) lastprivate(a0,a1,j)
  for (a0 = 1; a0 <= 10; a0++)
    for (j = 1; j <= 20; j++)
      **a1 = a0;    /// Segfaults here as *a0 points to invalid memory
You mean *a1.  That testcase is invalid, when a1 is lastprivate, it's
privatized copy
is uninitialized at the start and a1 is assigned the last iteration's value.

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

* [Bug fortran/108741] [OpenMP] Wrong code for lastprivate with pointer iteration variable
  2023-02-09 12:35 [Bug fortran/108741] New: [OpenMP] Wrong code for lastprivate with pointer iteration variable burnus at gcc dot gnu.org
  2023-02-09 12:39 ` [Bug fortran/108741] " jakub at gcc dot gnu.org
@ 2023-02-09 14:12 ` burnus at gcc dot gnu.org
  2023-02-09 14:12 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2023-02-09 14:12 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
As Jakub pointed out, for Fortran there is in OpenMP 5.2 in [106:26]:
  "The initial status of a private pointer is undefined."

(And C/C++ is for obvious reasons invalid).

Contrary to what I thought I had tested, it does work just fine for ALLOCATABLE

=> Close as invalid.

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

* [Bug fortran/108741] [OpenMP] Wrong code for lastprivate with pointer iteration variable
  2023-02-09 12:35 [Bug fortran/108741] New: [OpenMP] Wrong code for lastprivate with pointer iteration variable burnus at gcc dot gnu.org
  2023-02-09 12:39 ` [Bug fortran/108741] " jakub at gcc dot gnu.org
  2023-02-09 14:12 ` burnus at gcc dot gnu.org
@ 2023-02-09 14:12 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2023-02-09 14:12 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

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

end of thread, other threads:[~2023-02-09 14:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 12:35 [Bug fortran/108741] New: [OpenMP] Wrong code for lastprivate with pointer iteration variable burnus at gcc dot gnu.org
2023-02-09 12:39 ` [Bug fortran/108741] " jakub at gcc dot gnu.org
2023-02-09 14:12 ` burnus at gcc dot gnu.org
2023-02-09 14:12 ` burnus at gcc dot gnu.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).