From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F08683856DC8; Thu, 15 Jun 2023 17:07:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F08683856DC8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686848826; bh=N+Z79mSRgQ8kmPYiEGZjmqgqxSbB8VbNwei4NJhYqYA=; h=From:To:Subject:Date:From; b=y1rcVD1roghHeB4uaXW8QPbnlZWfQ8coQc6JR0UOIAGYq1JmoU38gWCy6MZAKfwOZ X9qxvldeJisXcEYWpwUE1WZwYjMLm20APHp9kcC2UKgWgAWSIWxmuEt02CsSN1y1ZD n24/UDZMMVUhfgdm1JjcgRtCBunbcpX6wl9iQG00= From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBtaWRkbGUtZW5kLzExMDI3MF0gTmV3OiBbT3Blbk1QXSBP?= =?UTF-8?B?cGVuTVAgNS4yIOKAkyBmaXJzdHByaXZhdGUgb2YgcG9pbnRlciBzaGFsbCBy?= =?UTF-8?B?ZXRhaW4gdGhlIHZhbHVlIGlmIHBvaW50ZWUgaXMgbm90IG1hcHBlZA==?= Date: Thu, 15 Jun 2023 17:07:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: openmp, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110270 Bug ID: 110270 Summary: [OpenMP] OpenMP 5.2 =E2=80=93 firstprivate of pointer s= hall 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=3D55328&action=3Dedit C/C++ testcase Testcase =E2=86=92 See attachment =E2=80=94 another one would be libgomp.c-c++-common/requires-unified-addr-1.c with the 'defaultmap's remov= ed 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" (l= ast paragraph) has: "If a matching mapped list item is not found, the pointer retains its origi= nal 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. =E2=86=92 Usage case 'p2' is one where it seems to make sense to keep the v= alue =E2=86=92 The issue came up with (unified-)shared memory where mapping stil= l has to work =E2=80=93 at least as long as omp_target_associate_ptr does not fail= when host/device pointers differ as this really requires keeping track of mapp= ing. =E2=86=92 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 =E2=80=93 in line with the last quote: map(alloc:MEM[(char *)p3] [len: 0]) map(firstprivate:p3 [pointer assign, b= ias: 0]) which in lower_omp_target is changed to: if (OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c)) ... tkind_zero =3D 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.=