{"id":2229525,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229525/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/247a5e24-d719-4214-b811-7f3bd46be8f9@baylibre.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<247a5e24-d719-4214-b811-7f3bd46be8f9@baylibre.com>","date":"2026-04-28T12:23:25","name":"[committed] libgomp.fortran/map-subarray-6.f90: Fix and robustify","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c7fa363bbe08e921a56b61223b04d8459a90f2b5","submitter":{"id":87873,"url":"http://patchwork.ozlabs.org/api/1.1/people/87873/?format=json","name":"Tobias Burnus","email":"tburnus@baylibre.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/247a5e24-d719-4214-b811-7f3bd46be8f9@baylibre.com/mbox/","series":[{"id":501836,"url":"http://patchwork.ozlabs.org/api/1.1/series/501836/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=501836","date":"2026-04-28T12:23:25","name":"[committed] libgomp.fortran/map-subarray-6.f90: Fix and robustify","version":1,"mbox":"http://patchwork.ozlabs.org/series/501836/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229525/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229525/checks/","tags":{},"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=baylibre-com.20251104.gappssmtp.com\n header.i=@baylibre-com.20251104.gappssmtp.com header.a=rsa-sha256\n header.s=20251104 header.b=zuYC+HL/;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=baylibre-com.20251104.gappssmtp.com\n header.i=@baylibre-com.20251104.gappssmtp.com header.a=rsa-sha256\n header.s=20251104 header.b=zuYC+HL/","sourceware.org;\n dmarc=none (p=none dis=none) header.from=baylibre.com","sourceware.org; spf=pass smtp.mailfrom=baylibre.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.128.67"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4fkH3yfdz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 22:24:06 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 011564B92095\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 12:24:04 +0000 (GMT)","from mail-wm1-f67.google.com (mail-wm1-f67.google.com\n [209.85.128.67])\n by sourceware.org (Postfix) with ESMTPS id 344DB4B920FA\n for <gcc-patches@gcc.gnu.org>; Tue, 28 Apr 2026 12:23:28 +0000 (GMT)","by mail-wm1-f67.google.com with SMTP id\n 5b1f17b1804b1-4891f625344so102912385e9.0\n for <gcc-patches@gcc.gnu.org>; Tue, 28 Apr 2026 05:23:28 -0700 (PDT)","from ?IPV6:2001:16b8:26c1:2000:5099:e445:3044:9f7?\n (200116b826c120005099e445304409f7.dip.versatel-1u1.de.\n [2001:16b8:26c1:2000:5099:e445:3044:9f7])\n by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-48a773f1fa0sm54398005e9.14.2026.04.28.05.23.26\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Tue, 28 Apr 2026 05:23:26 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 011564B92095","OpenDKIM Filter v2.11.0 sourceware.org 344DB4B920FA"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 344DB4B920FA","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 344DB4B920FA","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777379008; cv=none;\n b=RFIYiiW573cSZtNoJZlygxwtcqu6BpYn9sC4r73EkFSyJ29+R3fbr7LYKCA2j1nNnEvNVRHdjyILTJ4iYa2DH7I8F6ohz23sHcyaX7cKbcJSV2X9Vg3wwji+stdja9EAM2SOd33uC9tfQW6egJH2LTSbNdPEYYKtrqXjsRbcHy4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777379008; c=relaxed/simple;\n bh=SeJqLF7dWy6j1ynz2tbGb3NRDszFLD0+XHGqeqoALMY=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject;\n b=cU/vUVB6jhDw/Yq4ftNKdUK7mD/cqdGapQy6tjd5GK5hvf7ORBske9QFoy7k1tGv+NFv5zjYN8cakWvl1qLvE+DxH+emi2NqBgZ23hAlzhCnKDVtuq23hkVYhN8ez36ryr+9HiAiGNZBh/pEZvlho4rjJozhJD8c08RC4pOwe5s=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=baylibre-com.20251104.gappssmtp.com; s=20251104; t=1777379007;\n x=1777983807;\n darn=gcc.gnu.org;\n h=subject:from:to:content-language:user-agent:mime-version:date\n :message-id:from:to:cc:subject:date:message-id:reply-to;\n bh=a/Oj8rzjMo3A9bVTAt4jTu2D5eEiBrjlMpnXgxIEZ5I=;\n b=zuYC+HL/uW75BW+j0UkkiyOg1If5deJyySrAjQ1JR2Q03uf7tOBZHwbneLz9nHN0NB\n 9acjTC9QXj7miucHd45Vh2eRNyiK1W2w+y1j6O44IDR152rXkG5SE8d4bgQi3IwRkY98\n wypSWDpkisaKu+A4O7r9Wy8ADR1TXtSQYsAaDYyD+9ebEs+KuGc248Gck+fBIDKQdDuv\n EWzFcgsjtztFcVx3TuvRwj+Cf0le328UOteIIp63SI03oPJrqljqWCKtsV0k1JEhhd3w\n Uup8iixTedtxq3pcEHYbXwKu/H4MuqygKyUWgR9TbrnlUjRS7PfnTB2Uq8ozFuUgKAGT\n obCA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777379007; x=1777983807;\n h=subject:from:to:content-language:user-agent:mime-version:date\n :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=a/Oj8rzjMo3A9bVTAt4jTu2D5eEiBrjlMpnXgxIEZ5I=;\n b=ruWUHoQ5amF4jrPGf7PImAPrZ1wvDguqJCzGnv59oHHQ2RgDdCZ0ZyOoeVXpN9PdVj\n HEHOcfmDJMQeiPO+SBv0WZ3wXoUE9yvlhQczfcuMV1WZmv0cql7GQEqwdUtnjcuDZu4d\n RO4R+jk1A8iOUZqGf82QZruGGHwqNJnsfsJsEMzje7LRYXruBhfLpKRRxlJ564I8bWqn\n zJ3oDiLZPjutvcfy7l7Bq9siI2G3n967nSaDsP/ADKI+BKVZKevDST9m4TPkxkkDsf1j\n mxHiPwiJR9003ZyyM3PMig2beqTBt6iJ6kicctNZi4Rmb3/qgRPOeHCYNrODOUOss8Pv\n +48w==","X-Gm-Message-State":"AOJu0YyTsDc4p4lKG9KyyvhCREFw8qvii1UR9SZoyEiK/yVh8BaQePwJ\n YWMxk3LUb2FAvSqzMbry4GHXqjwr1OLxSpMSgu78Mr0ymZ6NsRElyKLFOtjDUO6tE0tCIkcGvWv\n buBxoTljjPg==","X-Gm-Gg":"AeBDievI49VSSJjfeQnjmiMDCtiVP0nvYJGnP4I3h/zWKMI24QIfsjNZZJQSw+CukDM\n rnn1GymuoNgI7a3DNoFT2oDukZl5sNRt3GRLiD+4/lOpBdzieFkqT60py+SP5Vo61wm+gxnnZ8P\n CfnJXjC3HA9RwIlLmhxT4l3LEMJ2OwSDjKNM7IlmwRQhVVYARwi3cVjmXACEtVa9zeguqeUuCwY\n fFFm8WB0WLen/EHP9R5AEFXLqExKnHAd4a7Am7J/4tgoSyPVhjHB1D6L5yaj3Q8VTEiJL5FAy/R\n +Bd6u+hnvcN86ESlpPRoiLUwjUDuOWGHGFzOTu1SPUgpP5MQ+KeJc21owmTeBrzImhn+PtSTB0A\n Tq5d/msbJOjqmp7SLHAZFr7VWHz83Rp0HjOUzdzjPNJd2mRXvwFQXJX2Aj/Hxl+J+e+A7EAbPKO\n zc0oXNxg4kU5DOB1wLhWr709OtxkmOGEmm1N7wwn0hMuaajatICvojoePsjQ+pKtbSNd204f7vv\n LYJ3PZclswDiATry89rZV6ipKdFLY9Qq478m4ZCLwGofHewSEvPMpqct5LRfgyF7msGB9fO","X-Received":"by 2002:a05:600c:5492:b0:489:1abb:5559 with SMTP id\n 5b1f17b1804b1-48a789221e6mr34016885e9.5.1777379006995;\n Tue, 28 Apr 2026 05:23:26 -0700 (PDT)","Content-Type":"multipart/mixed; boundary=\"------------pZeIUPCNTjEIn9otgwzelHgi\"","Message-ID":"<247a5e24-d719-4214-b811-7f3bd46be8f9@baylibre.com>","Date":"Tue, 28 Apr 2026 14:23:25 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Content-Language":"en-US","To":"gcc-patches <gcc-patches@gcc.gnu.org>,\n \"fortran@gcc.gnu.org\" <fortran@gcc.gnu.org>","From":"Tobias Burnus <tburnus@baylibre.com>","Subject":"[committed] libgomp.fortran/map-subarray-6.f90: Fix and robustify","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"This started by me trying to understand a\n   FAIL: libgomp.fortran/map-subarray-6.f90   -O1  execution test\n\nI think the problem was that the execution did *not* fail\nbecause var%p2 was *by chance* having the \"right\" value,\nviolating the 'dg-should-fail' condition.\n\nThe reason for that was that 'p2 = 0' initialized an implicitly\ndeclared variable - instead of var%p2.\n\nI think the idea for the test is/was that no pointer attachment\nactually happens - such that it crashes when trying to access the\nvariable. Obviously, this will fail when the host memory is accessible.\n\nThere are some other tricky parts: By mapping tgt/tgt2, the copy\nback will actually overwrite the var%p / var%p2 = ... assignment\n(unless on the host or using self mapping).\nOr not - as 'map(tgt)' is actually removed, if 'tgt' is not used!\n\n\nI hope that the attached version actually tests everything possible,\nwith the caveat that for nvptx the host accessible is not detected.\nThat's https://gcc.gnu.org/PR113216\n\nThis has only the effect that some code is skipped - the code does\nnot try to access the memory if GCC reports it is inaccessible,\neven if it actually is. (If it isn't, this prevents crashing the code).\n\n\nI have committed the testcase as r17-144-ga61760c4e555f9\nFollow-up comments are still welcome :-)\n\nThanks,\n\nTobias","diff":"commit a61760c4e555f9f5af2ea1ca3aa7abc2e578eed1\nAuthor: Tobias Burnus <tburnus@baylibre.com>\nDate:   Tue Apr 28 14:15:21 2026 +0200\n\n    libgomp.fortran/map-subarray-6.f90: Fix and robustify\n    \n    Changes:\n    * Actually initialize the proper variable.\n    * Handle the three cases explicitly: self mapping/host fallback, mapping\n      but host accessible and mapping and (potentially) not host accessible.\n      Hence, remove 'dg-should-fail' - as the code should now always run.\n    * Add more checks for not pointer attaching, using values outside mapped\n      range.\n    * Add several comments and handle the case that 'tgt' is actually removed\n      during gimplification as unused. (Two cases: once the result with 'tgt'\n      removed - and once using 'tgt'/'tgt2' in the target region - and checking\n      then for the result).\n    \n    libgomp/ChangeLog:\n    \n            * testsuite/libgomp.fortran/map-subarray-6.f90: Fix, extend, and\n            robustify.\n---\n .../testsuite/libgomp.fortran/map-subarray-6.f90   | 146 +++++++++++++++++++--\n 1 file changed, 137 insertions(+), 9 deletions(-)\n\ndiff --git a/libgomp/testsuite/libgomp.fortran/map-subarray-6.f90 b/libgomp/testsuite/libgomp.fortran/map-subarray-6.f90\nindex 9f0edf70890..243e88b70bd 100644\n--- a/libgomp/testsuite/libgomp.fortran/map-subarray-6.f90\n+++ b/libgomp/testsuite/libgomp.fortran/map-subarray-6.f90\n@@ -1,5 +1,9 @@\n ! { dg-do run }\n \n+use iso_c_binding\n+use omp_lib\n+implicit none\n+\n type t\n   integer, pointer :: p(:)\n   integer, pointer :: p2(:)\n@@ -7,20 +11,144 @@ end type t\n \n type(t) :: var\n integer, target :: tgt(5), tgt2(1000)\n+logical :: host_accessible, self_mapping\n+integer(c_intptr_t) :: ip, ip2\n+\n+ip = transfer(c_loc(tgt), ip)\n+ip2 = transfer(c_loc(tgt2), ip2)\n+\n var%p => tgt\n var%p2 => tgt2\n \n-p = 0\n-p2 = 0\n+! 'map(var)' shall never do any pointer attachment - even if the pointer\n+! variables are mapped to the device.\n+!\n+! There are three case:\n+!\n+! 1. Host fallback or self mapping: In the target region, the values are modified on the host\n+! 2. Host memory inaccessible: var's pointers point to the host version (inaccessible);\n+!    tgt and tgt2 are mapped from/to the device but are inaccessible via var's pointers.\n+! 3. No selfmapping but variables are accessible on the host:\n+!    Modifying var%p and var%p2 changes the value on the host - but copying back tgt and\n+!    tgt2 will set the value prior to the copy in.\n \n-!$omp target map(tgt, tgt2(4:6), var)\n-  var%p(1) = 5\n-  var%p2(5) = 7\n+! NOTE: Due to PR libgomp/113216, omp_target_is_accessible will report .false. on Nvptx\n+! even if host access to the device is possible. - This will reduce the test coverage\n+! but will not cause a fail.\n+\n+host_accessible = omp_target_is_accessible(c_loc(tgt), c_sizeof(tgt), omp_default_device) /= 0\n+!host_accessible = .true.  ! set this manually on nvptx with USM support, until fixed\n+\n+self_mapping = .false.\n+!$omp target map(to: self_mapping)\n+  self_mapping = .true.\n !$omp end target\n \n-if (var%p(1).ne.5) stop 1\n-if (var%p2(5).ne.7) stop 2\n+print *, (self_mapping ? '' : 'NO '), 'self mapping, ', &\n+         (host_accessible ? '' : 'NOT '), 'host accessible'\n \n-end\n+var%p = 1\n+var%p2 = 2\n+\n+! The following is slightly tricky as well: As 'tgt' is not used, it is optimized away\n+! by during gimplification! - Hence, 'tgt' is also not copied back.\n+! For 'tgt2(4:6)', the expression is too complex for the gimplifier - hence, it\n+! is copied back ...\n+\n+!$omp target map(tgt, tgt2(4:6),var) firstprivate(host_accessible, ip, ip2)\n+  ! No pointer attachment = points to the host\n+  if (ip /= transfer(c_loc(var%p), ip)) stop 1\n+  if (ip2 /= transfer(c_loc(var%p2), ip2)) stop 2\n+\n+  if (lbound(var%p,1) /= 1 .or. ubound(var%p,1) /= 5 .or. .not.associated(var%p)) &\n+    stop 3\n+  if (lbound(var%p2,1) /= 1 .or. ubound(var%p2,1) /= 1000 .or. .not.associated(var%p2)) &\n+    stop 4\n+\n+  if (omp_is_initial_device() .or. host_accessible) then\n+    if (any (var%p /= 1)) stop 5\n+    if (any (var%p2 /= 2)) stop 6\n+    var%p(1) = 5\n+    var%p2(5) = 6\n+    var%p2(22) = 7\n+  end if\n+!$omp end target\n \n-! { dg-shouldfail \"\" { offload_device_nonshared_as } }\n+if (omp_get_default_device() == omp_get_num_devices() &\n+    .or. omp_get_default_device() == omp_initial_device &\n+    .or. host_accessible) then\n+  if (self_mapping) then\n+    if (var%p(1) /= 5) stop 7\n+    if (var%p2(5) /= 6) stop 8\n+    if (var%p2(22) /= 7) stop 9\n+  else\n+    if (var%p(1) /= 5) stop 10  ! NO copy back - hence, value is 5\n+    if (var%p2(5) /= 2) stop 11\n+    if (var%p2(22) /= 7) stop 12\n+  endif\n+  if (any (var%p(2:) /= 1)) stop 13\n+  if (any (var%p2(:4) /= 2) &\n+      .or. any (var%p2(6:21) /= 2) &\n+      .or. any (var%p2(23:) /= 2)) &\n+    stop 14\n+else\n+  if (any(var%p /= 1)) stop 15\n+  if (any(var%p2 /= 2)) stop 16\n+end if\n+\n+\n+! The same - but now using tgt / tgt2 inside the region\n+\n+var%p = 1\n+var%p2 = 2\n+\n+!$omp target map(tgt, tgt2(4:6),var) firstprivate(host_accessible, ip, ip2)\n+  ! No pointer attachment = points to the host\n+  if (ip /= transfer(c_loc(var%p), ip)) stop 17\n+  if (ip2 /= transfer(c_loc(var%p2), ip2)) stop 18\n+\n+  if (omp_is_initial_device() .or. self_mapping) then\n+    if (.not. c_associated(c_loc(var%p), c_loc(tgt))) stop 19\n+    if (.not. c_associated(c_loc(var%p2), c_loc(tgt2))) stop 20\n+  else\n+    if (c_associated(c_loc(var%p), c_loc(tgt))) stop 21\n+    if (c_associated(c_loc(var%p2), c_loc(tgt2))) stop 22\n+  endif\n+\n+  if (lbound(var%p,1) /= 1 .or. ubound(var%p,1) /= 5 .or. .not.associated(var%p)) &\n+    stop 23\n+  if (lbound(var%p2,1) /= 1 .or. ubound(var%p2,1) /= 1000 .or. .not.associated(var%p2)) &\n+    stop 24\n+\n+  if (omp_is_initial_device() .or. host_accessible) then\n+    if (any (var%p /= 1)) stop 25\n+    if (any (var%p2 /= 2)) stop 26\n+    var%p(1) = 5\n+    var%p2(5) = 6\n+    var%p2(22) = 7\n+  end if\n+!$omp end target\n+\n+if (omp_get_default_device() == omp_get_num_devices() &\n+    .or. omp_get_default_device() == omp_initial_device &\n+    .or. host_accessible) then\n+  if (self_mapping) then\n+    if (var%p(1) /= 5) stop 27\n+    if (var%p2(5) /= 6) stop 28\n+    if (var%p2(22) /= 7) stop 29\n+  else\n+    if (var%p(1) /= 1) stop 30  ! NOW tgt is copied back\n+    if (var%p2(5) /= 2) stop 31\n+    if (var%p2(22) /= 7) stop 32\n+  endif\n+  if (any (var%p(2:) /= 1)) stop 33\n+  if (any (var%p2(:4) /= 2) &\n+      .or. any (var%p2(6:21) /= 2) &\n+      .or. any (var%p2(23:) /= 2)) &\n+    stop 34\n+else\n+  if (any(var%p /= 1)) stop 35\n+  if (any(var%p2 /= 2)) stop 36\n+end if\n+\n+end\n","prefixes":["committed"]}