public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/110270] New: [OpenMP] OpenMP 5.2 – firstprivate of pointer shall retain the value if pointee is not mapped
Date: Thu, 15 Jun 2023 17:07:03 +0000	[thread overview]
Message-ID: <bug-110270-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110270
           Summary: [OpenMP] OpenMP 5.2 – firstprivate of pointer shall
                    retain the value if pointee is not mapped
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: openmp, wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

Created attachment 55328
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55328&action=edit
C/C++ testcase

Testcase → See attachment — another one would be
libgomp.c-c++-common/requires-unified-addr-1.c with the 'defaultmap's removed
or changed to  either 'defaultmap(default)' or 'defaultmap(default:pointer)'.

 * * *

The following quote is from a section that is marked as "C / C++" only.

OpenMP 5.2's "5.8.6 Pointer Initialization for Device Data Environments" (last
paragraph) has:

"If a matching mapped list item is not found, the pointer retains its original
value as per the firstprivate semantics described in Section 5.4.4."


OpenMP 5.1's 2.21.7.2 had:

"If a matching mapped list item is not found, the assigned initial value of the
pointer is NULL unless otherwise specified (see Section 2.5.1)."

* * *

The attached testcase shows that 'p1' and 'p2' are NULL instead of the
expected value.

→ Usage case 'p2' is one where it seems to make sense to keep the value
→ The issue came up with (unified-)shared memory where mapping still has to
  work – at least as long as omp_target_associate_ptr does not fail when
  host/device pointers differ as this really requires keeping track of mapping.
→ See OpenMP Issue #2604 for the spec change.


* * *

Note that firstprivate(p1,p1) / defaultmap(firstprivate:pointer)
are different to the (implicit) 'defaultmap(default:pointer)' used in the
attached testcase due to the wording quoted above, which only applies with
'default'.

Related: PR109837 (requires unified_address testcase), which provides the
existing testcase mentioned above.

Cf. also "5.8.1 Implicit Data-Mapping Attribute Rules" which has:

"A variable that is of type pointer [...] is treated as if it is the
base pointer of a zero-length array section that had appeared as a
list item in a map clause."

* * *

On the technical side, GCC creates – in line with the last quote:
 map(alloc:MEM[(char *)p3] [len: 0]) map(firstprivate:p3 [pointer assign, bias:
0])
which in lower_omp_target is changed to:
  if (OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c))
...
    tkind_zero = GOMP_MAP_ZERO_LEN_ARRAY_SECTION;

TODO/Expected:
In libgomp, we now need to ensure that the pointer's value gets copied and is
not set to NULL.

             reply	other threads:[~2023-06-15 17:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 17:07 burnus at gcc dot gnu.org [this message]
2023-06-19  7:09 ` [Bug middle-end/110270] " cvs-commit at gcc dot gnu.org
2023-06-19  7:14 ` burnus at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110270-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).