[gcc r16-663] Improve constant bitmasks.

2025-05-15 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:65cd212bd4c533351a09e6974f40ae5d7effca84

commit r16-663-g65cd212bd4c533351a09e6974f40ae5d7effca84
Author: Andrew MacLeod 
Date:   Wed May 14 11:12:22 2025 -0400

Improve constant bitmasks.

bitmasks for constants are created only for trailing zeros. It is no
additional work to also include leading 1's in the value that are also
known.
  before :  [5, 7]  mask 0x7 value 0x0
  after  :  [5, 7]  mask 0x3 value 0x4

PR tree-optimization/116546
* value-range.cc (irange_bitmask::irange_bitmask): Include
leading ones in the bitmask.

Diff:
---
 gcc/value-range.cc | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 48a1521b81ec..64d10f41168b 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -47,9 +47,11 @@ irange_bitmask::irange_bitmask (tree type,
   else
 {
   wide_int xorv = min ^ max;
-  xorv = wi::mask (prec - wi::clz (xorv), false, prec);
-  m_value = wi::zero (prec);
-  m_mask = min | xorv;
+  // Mask will have leading zeros for all leading bits that are
+  // common, both zeros and ones.
+  m_mask = wi::mask (prec - wi::clz (xorv), false, prec);
+  // Now set value to those bits which are known, and zero the rest.
+  m_value = ~m_mask & min;
 }
 }


[gcc r16-665] Enhance bitwise_and::op1_range

2025-05-15 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:ac55655ce45a237a6a01e0cce50211841603c2ec

commit r16-665-gac55655ce45a237a6a01e0cce50211841603c2ec
Author: Andrew MacLeod 
Date:   Wed May 14 11:32:58 2025 -0400

Enhance bitwise_and::op1_range

Any known bits from the LHS range can be used to specify known bits in
the non-mask operand.

PR tree-optimization/116546
gcc/
* range-op.cc (operator_bitwise_and::op1_range): Utilize bitmask
from the LHS to improve op1's bitmask.

gcc/testsuite/
* gcc.dg/pr116546.c: New.

Diff:
---
 gcc/range-op.cc | 22 +++-
 gcc/testsuite/gcc.dg/pr116546.c | 46 +
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 06d357f5199f..e2b9c82bc7b7 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3716,14 +3716,34 @@ operator_bitwise_and::op1_range (irange &r, tree type,
   return true;
 }
 
+  if (!op2.singleton_p (mask))
+return true;
+
   // For 0 = op1 & MASK, op1 is ~MASK.
-  if (lhs.zero_p () && op2.singleton_p ())
+  if (lhs.zero_p ())
 {
   wide_int nz = wi::bit_not (op2.get_nonzero_bits ());
   int_range<2> tmp (type);
   tmp.set_nonzero_bits (nz);
   r.intersect (tmp);
 }
+
+  irange_bitmask lhs_bm = lhs.get_bitmask ();
+  // given   [5,7]  mask 0x3 value 0x4 =  N &  [7, 7] mask 0x0 value 0x7
+  // Nothing is known about the bits not specified in the mask value (op2),
+  //  Start with the mask, 1's will occur where values were masked.
+  wide_int op1_mask = ~mask;
+  // Any bits that are unknown on the LHS are also unknown in op1,
+  // so union the current mask with the LHS mask.
+  op1_mask |= lhs_bm.mask ();
+  // The resulting zeros correspond to known bits in the LHS mask, and
+  // the LHS value should tell us what they are.  Mask off any
+  // extraneous values thats are not convered by the mask.
+  wide_int op1_value = lhs_bm.value () & ~op1_mask;
+  irange_bitmask op1_bm (op1_value, op1_mask);
+  // INtersect this mask with anything already known about the value.
+  op1_bm.intersect (r.get_bitmask ());
+  r.update_bitmask (op1_bm);
   return true;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr116546.c b/gcc/testsuite/gcc.dg/pr116546.c
new file mode 100644
index ..b82dc27f4522
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116546.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+extern long foo (void);
+extern long bar (void);
+
+long
+test1 (long n)
+{
+  n &= 7;
+  if (n == 4) {
+if (n & 4)
+  return foo ();
+else
+  return bar ();
+  }
+  return 0;
+}
+
+long
+test2 (long n)
+{
+  n &= 7;
+  if (n > 4) {
+if (n & 4)
+  return foo ();
+else
+  return bar ();
+  }
+  return 0;
+}
+
+long
+test3 (long n)
+{
+  n &= 7;
+  if (n >= 4) {
+if (n & 4)
+  return foo ();
+else
+  return bar ();
+  }
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "bar" "evrp" } } */


[gcc r16-664] Allow bitmask intersection to process unknown masks.

2025-05-15 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:b3327649bffd32af962662dce054b94be2d7330d

commit r16-664-gb3327649bffd32af962662dce054b94be2d7330d
Author: Andrew MacLeod 
Date:   Wed May 14 11:13:15 2025 -0400

Allow bitmask intersection to process unknown masks.

bitmask_intersection should not return immediately if the current mask is
unknown.  Unknown may mean its the default for a range, and this may
interact in intersting ways with the other bitmask.

PR tree-optimization/116546
* value-range.cc (irange::intersect_bitmask): Allow unknown
bitmasks to be processed.

Diff:
---
 gcc/value-range.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 64d10f41168b..ed3760fa6ff6 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -2434,7 +2434,7 @@ irange::intersect_bitmask (const irange &r)
 {
   gcc_checking_assert (!undefined_p () && !r.undefined_p ());
 
-  if (r.m_bitmask.unknown_p () || m_bitmask == r.m_bitmask)
+  if (m_bitmask == r.m_bitmask)
 return false;
 
   irange_bitmask bm = get_bitmask ();


[gcc r16-662] Turn get_bitmask_from_range into an irange_bitmask constructor.

2025-05-15 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:e4c6a0214c3ea8aa73e50b1496eb7a8aa5eda635

commit r16-662-ge4c6a0214c3ea8aa73e50b1496eb7a8aa5eda635
Author: Andrew MacLeod 
Date:   Tue May 13 13:23:16 2025 -0400

Turn get_bitmask_from_range into an irange_bitmask constructor.

There are other places where this is interesting, so move the static
function into a constructor for class irange_bitmask.

* value-range.cc (irange_bitmask::irange_bitmask): Rename from
get_bitmask_from_range and tweak.
(prange::set): Use new constructor.
(prange::intersect): Use new constructor.
(irange::get_bitmask): Likewise.
* value-range.h (irange_bitmask): New constructor prototype.

Diff:
---
 gcc/value-range.cc | 32 
 gcc/value-range.h  |  2 ++
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index d2c14e7900df..48a1521b81ec 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -31,25 +31,26 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "gimple-range.h"
 
-// Return the bitmask inherent in a range.
+// Return the bitmask inherent in a range :   TYPE [MIN, MAX].
+// This use to be get_bitmask_from_range ().
 
-static irange_bitmask
-get_bitmask_from_range (tree type,
-   const wide_int &min, const wide_int &max)
+irange_bitmask::irange_bitmask (tree type,
+   const wide_int &min, const wide_int &max)
 {
   unsigned prec = TYPE_PRECISION (type);
-
   // All the bits of a singleton are known.
   if (min == max)
 {
-  wide_int mask = wi::zero (prec);
-  wide_int value = min;
-  return irange_bitmask (value, mask);
+  m_mask = wi::zero (prec);
+  m_value = min;
+}
+  else
+{
+  wide_int xorv = min ^ max;
+  xorv = wi::mask (prec - wi::clz (xorv), false, prec);
+  m_value = wi::zero (prec);
+  m_mask = min | xorv;
 }
-
-  wide_int xorv = min ^ max;
-  xorv = wi::mask (prec - wi::clz (xorv), false, prec);
-  return irange_bitmask (wi::zero (prec), min | xorv);
 }
 
 void
@@ -469,7 +470,7 @@ prange::set (tree type, const wide_int &min, const wide_int 
&max,
 }
 
   m_kind = VR_RANGE;
-  m_bitmask = get_bitmask_from_range (type, min, max);
+  m_bitmask = irange_bitmask (type, min, max);
   if (flag_checking)
 verify_range ();
 }
@@ -583,7 +584,7 @@ prange::intersect (const vrange &v)
 }
 
   // Intersect all bitmasks: the old one, the new one, and the other operand's.
-  irange_bitmask new_bitmask = get_bitmask_from_range (m_type, m_min, m_max);
+  irange_bitmask new_bitmask (m_type, m_min, m_max);
   m_bitmask.intersect (new_bitmask);
   m_bitmask.intersect (r.m_bitmask);
   if (varying_compatible_p ())
@@ -2396,8 +2397,7 @@ irange::get_bitmask () const
   // in the mask.
   //
   // See also the note in irange_bitmask::intersect.
-  irange_bitmask bm
-= get_bitmask_from_range (type (), lower_bound (), upper_bound ());
+  irange_bitmask bm (type (), lower_bound (), upper_bound ());
   if (!m_bitmask.unknown_p ())
 bm.intersect (m_bitmask);
   return bm;
diff --git a/gcc/value-range.h b/gcc/value-range.h
index f6942989a6f3..74cdf29ddcb3 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -136,6 +136,8 @@ public:
   irange_bitmask () { /* uninitialized */ }
   irange_bitmask (unsigned prec) { set_unknown (prec); }
   irange_bitmask (const wide_int &value, const wide_int &mask);
+  irange_bitmask (tree type, const wide_int &min, const wide_int &max);
+
   wide_int value () const { return m_value; }
   wide_int mask () const { return m_mask; }
   void set_unknown (unsigned prec);


[gcc r16-661] Check for casts becoming UNDEFINED.

2025-05-15 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:4291071a6aa3b50800ad5fc70b5fb83cb9398237

commit r16-661-g4291071a6aa3b50800ad5fc70b5fb83cb9398237
Author: Andrew MacLeod 
Date:   Thu May 15 11:06:05 2025 -0400

Check for casts becoming UNDEFINED.

In various situations a cast that is ultimately unreahcable may produce
an UNDEFINED result, and we can't check the bounds in this case.

PR tree-optimization/120277
gcc/
* range-op-ptr.cc (operator_cast::fold_range): Check if the cast
if UNDEFINED before setting bounds.

gcc/testsuite/
* gcc.dg/pr120277.c: New.

Diff:
---
 gcc/range-op-ptr.cc | 10 --
 gcc/testsuite/gcc.dg/pr120277.c | 21 +
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc
index 36e9dfc20baf..6aadc9cf2c95 100644
--- a/gcc/range-op-ptr.cc
+++ b/gcc/range-op-ptr.cc
@@ -602,8 +602,14 @@ operator_cast::fold_range (prange &r, tree type,
   int_range<2> tmp = inner;
   tree pointer_uint_type = make_unsigned_type (TYPE_PRECISION (type));
   range_cast (tmp, pointer_uint_type);
-  r.set (type, tmp.lower_bound (), tmp.upper_bound ());
-  r.update_bitmask (tmp.get_bitmask ());
+  // Casts may cause ranges to become UNDEFINED based on bitmasks.
+  if (tmp.undefined_p ())
+r.set_varying (type);
+  else
+{
+  r.set (type, tmp.lower_bound (), tmp.upper_bound ());
+  r.update_bitmask (tmp.get_bitmask ());
+}
   return true;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr120277.c b/gcc/testsuite/gcc.dg/pr120277.c
new file mode 100644
index ..f291e920db16
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr120277.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int a, b;
+int c(int d, long e) {
+  switch (d) {
+  case 129:
+a = 1;
+  case 128:
+break;
+  default:
+return 1;
+  }
+  *(int *)e = 0;
+}
+void f(int d, long e) { c(d, e); }
+void g() {
+  int h = b * sizeof(int);
+  f(h + 7, h);
+}
+void main() {}


[gcc r15-9686] Update cpplib zh_CN.po

2025-05-15 Thread Joseph Myers via Gcc-cvs
https://gcc.gnu.org/g:f8ed7ab547789232ba659b32010598152217eee7

commit r15-9686-gf8ed7ab547789232ba659b32010598152217eee7
Author: Joseph Myers 
Date:   Thu May 15 17:20:54 2025 +

Update cpplib zh_CN.po

* zh_CN.po: Update.

Diff:
---
 libcpp/po/zh_CN.po | 61 +++---
 1 file changed, 30 insertions(+), 31 deletions(-)

diff --git a/libcpp/po/zh_CN.po b/libcpp/po/zh_CN.po
index 467575b7fb71..2262520d6f9e 100644
--- a/libcpp/po/zh_CN.po
+++ b/libcpp/po/zh_CN.po
@@ -2,22 +2,24 @@
 # Copyright (C) 2005 Free Software Foundation, Inc.
 # This file is distributed under the same license as the gcc package.
 # Meng Jie , 2005-2010.
+# Boyuan Yang <073p...@gmail.com>, 2025.
+# Anbang LI , 2025.
 # Zhanhaoxiang Zhang , 2024, 2025.
 #
 msgid ""
 msgstr ""
-"Project-Id-Version: cpplib 15-b20250216\n"
+"Project-Id-Version: cpplib 15.1-b20250316\n"
 "Report-Msgid-Bugs-To: https://gcc.gnu.org/bugs/\n";
 "POT-Creation-Date: 2025-03-14 22:05+\n"
-"PO-Revision-Date: 2025-02-20 18:32+0800\n"
-"Last-Translator: Zhanhaoxiang Zhang \n"
+"PO-Revision-Date: 2025-05-15 12:47-0400\n"
+"Last-Translator: Boyuan Yang <073p...@gmail.com>\n"
 "Language-Team: Chinese (simplified) \n"
 "Language: zh_CN\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "X-Bugs: Report translation errors to the Language-Team address.\n"
-"X-Generator: Poedit 3.5\n"
+"X-Generator: Poedit 3.6\n"
 
 #: charset.cc:759
 #, gcc-internal-format, gfc-internal-format
@@ -49,12 +51,12 @@ msgstr "字符 0x%lx 在执行字符集中不是单字节的"
 
 #: charset.cc:1549
 msgid "universal character names are only valid in C++ and C99"
-msgstr "Unicode 字符名只在 C++ 和 C99 中有效"
+msgstr "通用字符名只在 C++ 和 C99 中有效"
 
 #: charset.cc:1553
 #, gcc-internal-format
 msgid "C99%'s universal character names are incompatible with C90"
-msgstr "C99 的 Unicode 字符名与 C90 不兼容"
+msgstr "C99 的通用字符名与 C90 不兼容"
 
 #: charset.cc:1556
 #, gcc-internal-format
@@ -64,29 +66,29 @@ msgstr "%<\\%c%> 的意义与在传统 C 中不同"
 #: charset.cc:1595
 #, gcc-internal-format
 msgid "%<\\N%> not followed by %<{%>"
-msgstr "%<\\N%> 后没有 %<{%>"
+msgstr "%<\\N%> 后面没有 %<{%>"
 
 #: charset.cc:1625
 msgid "empty named universal character escape sequence; treating it as 
separate tokens"
-msgstr "空的命名 Unicode 字符转义序列;将其视为独立 token 处理"
+msgstr "空命名通用字符转义序列; 将其视为单独的词元"
 
 #: charset.cc:1632
 msgid "empty named universal character escape sequence"
-msgstr "空的命名 Unicode 字符转义序列"
+msgstr "空的命名通用字符转义序列"
 
 #: charset.cc:1639
 msgid "named universal character escapes are only valid in C++23"
-msgstr "命名 Unicode 字符转义序列(named universal character escapes)仅在 C++23 中有效"
+msgstr "命名通用字符转义仅在 C++23 中有效"
 
 #: charset.cc:1659
 #, gcc-internal-format
 msgid "%<\\N{%.*s}%> is not a valid universal character; treating it as 
separate tokens"
-msgstr "%<\\N{%.*s}%> 不是一个有效的 Unicode 字符;将其视为独立 token 处理"
+msgstr "%<\\N{%.*s}%> 不是有效的通用字符; 将其视为独立的词元"
 
 #: charset.cc:1665
 #, gcc-internal-format
 msgid "%<\\N{%.*s}%> is not a valid universal character"
-msgstr "%<\\N{%.*s}%> 不是一个有效的 Unicode 字符"
+msgstr "%<\\N{%.*s}%> 不是一个有效的通用字符"
 
 #: charset.cc:1675
 #, gcc-internal-format
@@ -96,7 +98,7 @@ msgstr "你是说 %<\\N{%s}%> 吗?"
 #: charset.cc:1693
 #, gcc-internal-format
 msgid "%<\\N{%> not terminated with %<}%> after %.*s; treating it as separate 
tokens"
-msgstr "在 %.*s 之后 %<\\N{%> 未以 %<}%> 结束;将其视为独立 token 处理"
+msgstr "在 %.*s 之后 %<\\N{%> 未以 %<}%> 结束;将其视为独立词元"
 
 #: charset.cc:1702
 #, gcc-internal-format
@@ -110,7 +112,7 @@ msgstr "在 %<_cpp_valid_ucn%> 中但不是一个 UCN"
 
 #: charset.cc:1753
 msgid "empty delimited escape sequence; treating it as separate tokens"
-msgstr "空的带分隔符的转义序列;将其视为独立 token 处理"
+msgstr "空的带分隔符的转义序列;将其视为独立词元"
 
 #: charset.cc:1760 charset.cc:2163 charset.cc:2280
 msgid "empty delimited escape sequence"
@@ -128,12 +130,12 @@ msgstr "带分隔符的转义序列仅在 C2Y 中有效"
 #: charset.cc:1794
 #, gcc-internal-format
 msgid "%<\\u{%> not terminated with %<}%> after %.*s; treating it as separate 
tokens"
-msgstr "在 %.*s 之后 %<\\u{%> 未以 %<}%> 结束;将其视为独立 token 处理"
+msgstr "在 %.*s 之后 %<\\u{%> 未以 %<}%> 结束;将其视为独立词元"
 
 #: charset.cc:1806
 #, gcc-internal-format
 msgid "incomplete universal character name %.*s"
-msgstr "不完全的 Unicode 字符名 %.*s"
+msgstr "不完整的通用字符名 %.*s"
 
 #: charset.cc:1810
 #, gcc-internal-format
@@ -143,12 +145,12 @@ msgstr "在 %.*s 之后 %<\\u{%> 未以 %<}%> 结束"
 #: charset.cc:1818
 #, gcc-internal-format
 msgid "%.*s is not a valid universal character"
-msgstr "%.*s 不是一个有效的 Unicode 字符"
+msgstr "%.*s 不是一个有效的通用字符"
 
 #: charset.cc:1834 charset.cc:1838
 #, gcc-internal-format
 msgid "%.*s is not a valid universal character name before C23"
-msgstr "在C23之前,%.*s 不是一个有效的 Unicode 字符名"
+msgstr "在C23之前,%.*s 不是一个有效的通用字符名"
 
 #: charset.cc:1854 lex.cc:2096
 #, gcc-internal-format
@@ -158,17 +160,17 @@ msgstr "%<$%> 出现在标识符或数字中"
 #: charset.cc:1864
 #, gcc-internal-format
 msgid "universal character %.*s is not valid in an identifier"
-msgstr "Unicode 字符 %.*s 在标识符中无效"
+msgstr "通用字

[gcc r16-666] Update cpplib zh_CN.po

2025-05-15 Thread Joseph Myers via Gcc-cvs
https://gcc.gnu.org/g:e0fe14e33e12dd2de3b006569a8148fb4f1fa387

commit r16-666-ge0fe14e33e12dd2de3b006569a8148fb4f1fa387
Author: Joseph Myers 
Date:   Thu May 15 17:19:48 2025 +

Update cpplib zh_CN.po

* zh_CN.po: Update.

Diff:
---
 libcpp/po/zh_CN.po | 61 +++---
 1 file changed, 30 insertions(+), 31 deletions(-)

diff --git a/libcpp/po/zh_CN.po b/libcpp/po/zh_CN.po
index 467575b7fb71..2262520d6f9e 100644
--- a/libcpp/po/zh_CN.po
+++ b/libcpp/po/zh_CN.po
@@ -2,22 +2,24 @@
 # Copyright (C) 2005 Free Software Foundation, Inc.
 # This file is distributed under the same license as the gcc package.
 # Meng Jie , 2005-2010.
+# Boyuan Yang <073p...@gmail.com>, 2025.
+# Anbang LI , 2025.
 # Zhanhaoxiang Zhang , 2024, 2025.
 #
 msgid ""
 msgstr ""
-"Project-Id-Version: cpplib 15-b20250216\n"
+"Project-Id-Version: cpplib 15.1-b20250316\n"
 "Report-Msgid-Bugs-To: https://gcc.gnu.org/bugs/\n";
 "POT-Creation-Date: 2025-03-14 22:05+\n"
-"PO-Revision-Date: 2025-02-20 18:32+0800\n"
-"Last-Translator: Zhanhaoxiang Zhang \n"
+"PO-Revision-Date: 2025-05-15 12:47-0400\n"
+"Last-Translator: Boyuan Yang <073p...@gmail.com>\n"
 "Language-Team: Chinese (simplified) \n"
 "Language: zh_CN\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "X-Bugs: Report translation errors to the Language-Team address.\n"
-"X-Generator: Poedit 3.5\n"
+"X-Generator: Poedit 3.6\n"
 
 #: charset.cc:759
 #, gcc-internal-format, gfc-internal-format
@@ -49,12 +51,12 @@ msgstr "字符 0x%lx 在执行字符集中不是单字节的"
 
 #: charset.cc:1549
 msgid "universal character names are only valid in C++ and C99"
-msgstr "Unicode 字符名只在 C++ 和 C99 中有效"
+msgstr "通用字符名只在 C++ 和 C99 中有效"
 
 #: charset.cc:1553
 #, gcc-internal-format
 msgid "C99%'s universal character names are incompatible with C90"
-msgstr "C99 的 Unicode 字符名与 C90 不兼容"
+msgstr "C99 的通用字符名与 C90 不兼容"
 
 #: charset.cc:1556
 #, gcc-internal-format
@@ -64,29 +66,29 @@ msgstr "%<\\%c%> 的意义与在传统 C 中不同"
 #: charset.cc:1595
 #, gcc-internal-format
 msgid "%<\\N%> not followed by %<{%>"
-msgstr "%<\\N%> 后没有 %<{%>"
+msgstr "%<\\N%> 后面没有 %<{%>"
 
 #: charset.cc:1625
 msgid "empty named universal character escape sequence; treating it as 
separate tokens"
-msgstr "空的命名 Unicode 字符转义序列;将其视为独立 token 处理"
+msgstr "空命名通用字符转义序列; 将其视为单独的词元"
 
 #: charset.cc:1632
 msgid "empty named universal character escape sequence"
-msgstr "空的命名 Unicode 字符转义序列"
+msgstr "空的命名通用字符转义序列"
 
 #: charset.cc:1639
 msgid "named universal character escapes are only valid in C++23"
-msgstr "命名 Unicode 字符转义序列(named universal character escapes)仅在 C++23 中有效"
+msgstr "命名通用字符转义仅在 C++23 中有效"
 
 #: charset.cc:1659
 #, gcc-internal-format
 msgid "%<\\N{%.*s}%> is not a valid universal character; treating it as 
separate tokens"
-msgstr "%<\\N{%.*s}%> 不是一个有效的 Unicode 字符;将其视为独立 token 处理"
+msgstr "%<\\N{%.*s}%> 不是有效的通用字符; 将其视为独立的词元"
 
 #: charset.cc:1665
 #, gcc-internal-format
 msgid "%<\\N{%.*s}%> is not a valid universal character"
-msgstr "%<\\N{%.*s}%> 不是一个有效的 Unicode 字符"
+msgstr "%<\\N{%.*s}%> 不是一个有效的通用字符"
 
 #: charset.cc:1675
 #, gcc-internal-format
@@ -96,7 +98,7 @@ msgstr "你是说 %<\\N{%s}%> 吗?"
 #: charset.cc:1693
 #, gcc-internal-format
 msgid "%<\\N{%> not terminated with %<}%> after %.*s; treating it as separate 
tokens"
-msgstr "在 %.*s 之后 %<\\N{%> 未以 %<}%> 结束;将其视为独立 token 处理"
+msgstr "在 %.*s 之后 %<\\N{%> 未以 %<}%> 结束;将其视为独立词元"
 
 #: charset.cc:1702
 #, gcc-internal-format
@@ -110,7 +112,7 @@ msgstr "在 %<_cpp_valid_ucn%> 中但不是一个 UCN"
 
 #: charset.cc:1753
 msgid "empty delimited escape sequence; treating it as separate tokens"
-msgstr "空的带分隔符的转义序列;将其视为独立 token 处理"
+msgstr "空的带分隔符的转义序列;将其视为独立词元"
 
 #: charset.cc:1760 charset.cc:2163 charset.cc:2280
 msgid "empty delimited escape sequence"
@@ -128,12 +130,12 @@ msgstr "带分隔符的转义序列仅在 C2Y 中有效"
 #: charset.cc:1794
 #, gcc-internal-format
 msgid "%<\\u{%> not terminated with %<}%> after %.*s; treating it as separate 
tokens"
-msgstr "在 %.*s 之后 %<\\u{%> 未以 %<}%> 结束;将其视为独立 token 处理"
+msgstr "在 %.*s 之后 %<\\u{%> 未以 %<}%> 结束;将其视为独立词元"
 
 #: charset.cc:1806
 #, gcc-internal-format
 msgid "incomplete universal character name %.*s"
-msgstr "不完全的 Unicode 字符名 %.*s"
+msgstr "不完整的通用字符名 %.*s"
 
 #: charset.cc:1810
 #, gcc-internal-format
@@ -143,12 +145,12 @@ msgstr "在 %.*s 之后 %<\\u{%> 未以 %<}%> 结束"
 #: charset.cc:1818
 #, gcc-internal-format
 msgid "%.*s is not a valid universal character"
-msgstr "%.*s 不是一个有效的 Unicode 字符"
+msgstr "%.*s 不是一个有效的通用字符"
 
 #: charset.cc:1834 charset.cc:1838
 #, gcc-internal-format
 msgid "%.*s is not a valid universal character name before C23"
-msgstr "在C23之前,%.*s 不是一个有效的 Unicode 字符名"
+msgstr "在C23之前,%.*s 不是一个有效的通用字符名"
 
 #: charset.cc:1854 lex.cc:2096
 #, gcc-internal-format
@@ -158,17 +160,17 @@ msgstr "%<$%> 出现在标识符或数字中"
 #: charset.cc:1864
 #, gcc-internal-format
 msgid "universal character %.*s is not valid in an identifier"
-msgstr "Unicode 字符 %.*s 在标识符中无效"
+msgstr "通用字符

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression PR100103

2025-05-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:ca8f3f1bf59d0cfc386b2c93afc9a2be8bdf3e61

commit ca8f3f1bf59d0cfc386b2c93afc9a2be8bdf3e61
Author: Mikael Morin 
Date:   Thu May 15 18:41:26 2025 +0200

Correction régression PR100103

Diff:
---
 gcc/fortran/trans-descriptor.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index f5401dc39294..1bded77e00a9 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -3530,6 +3530,9 @@ gfc_class_array_data_assign (stmtblock_t *block, tree 
lhs_desc, tree rhs_desc,
   gfc_conv_descriptor_dtype_set (block, lhs_desc,
 gfc_conv_descriptor_dtype_get (rhs_desc));
 
+  gfc_conv_descriptor_span_set (block, lhs_desc,
+   gfc_conv_descriptor_span_get (rhs_desc));
+
   /* Assign the dimension as range-ref.  */
   tmp = gfc_conv_descriptor_dimensions_get (lhs_desc);
   tmp2 = gfc_conv_descriptor_dimensions_get (rhs_desc);


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression select_type_50

2025-05-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:c48991de146e5827e9c647f2176e4d51e80c36ff

commit c48991de146e5827e9c647f2176e4d51e80c36ff
Author: Mikael Morin 
Date:   Thu May 15 19:29:10 2025 +0200

Correction régression select_type_50

Diff:
---
 gcc/fortran/trans-expr.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index f4838f2d48c7..ba32bd9bfd07 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -830,7 +830,9 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
   var = gfc_create_var (tmp, "class");
 
   /* Set the vptr.  */
-  if (opt_vptr_src)
+  if (parmse->class_container)
+gfc_class_set_vptr (&parmse->pre, var, parmse->class_container);
+  else if (opt_vptr_src)
 gfc_class_set_vptr (&parmse->pre, var, opt_vptr_src);
   else
 gfc_reset_vptr (&parmse->pre, e, var);


[gcc r15-9687] Do not dump non-interoperable types with -fc-prototypes.

2025-05-15 Thread Thomas Koenig via Gcc-cvs
https://gcc.gnu.org/g:c6ec3a9bddb4224a2369b0284ade4b474cd4b0ce

commit r15-9687-gc6ec3a9bddb4224a2369b0284ade4b474cd4b0ce
Author: Thomas Koenig 
Date:   Tue May 13 19:02:06 2025 +0200

Do not dump non-interoperable types with -fc-prototypes.

gcc/fortran/ChangeLog:

PR fortran/120107
* dump-parse-tree.cc (write_type): Do not dump non-interoperable
types.

(cherry picked from commit fa0dff8e99e81bc7a3db1dc57d4fc340e0525b1d)

Diff:
---
 gcc/fortran/dump-parse-tree.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index 9501bccb803b..558a2853cc43 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -4380,10 +4380,11 @@ write_type (gfc_symbol *sym)
 {
   gfc_component *c;
 
-  /* Don't dump our iso c module, nor vtypes.  */
+  /* Don't dump types that are not interoperable, our very own ISO C Binding
+ module, or vtypes.  */
 
   if (sym->from_intmod == INTMOD_ISO_C_BINDING || sym->attr.flavor != 
FL_DERIVED
-  || sym->attr.vtype)
+  || sym->attr.vtype || !sym->attr.is_bind_c)
 return;
 
   fprintf (dumpfile, "typedef struct %s {\n", sym->name);


[gcc r15-9688] Fix explicit arrays with non-constant size for -fc-prototypes.

2025-05-15 Thread Thomas Koenig via Gcc-cvs
https://gcc.gnu.org/g:a85776f7f64271d628ae0a04f02717ee6572e6e8

commit r15-9688-ga85776f7f64271d628ae0a04f02717ee6572e6e8
Author: Thomas Koenig 
Date:   Wed May 14 20:11:48 2025 +0200

Fix explicit arrays with non-constant size for -fc-prototypes.

gcc/fortran/ChangeLog:

PR fortran/120139
* dump-parse-tree.cc (get_c_type_name): If no constant
size of an array exists, output an asterisk.

(cherry picked from commit 4f9c7b5258f2af89bba8e954c277981d2e2ee1ef)

Diff:
---
 gcc/fortran/dump-parse-tree.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index 558a2853cc43..3c1060375304 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -4336,6 +4336,8 @@ get_c_type_name (gfc_typespec *ts, gfc_array_spec *as, 
const char **pre,
  mpz_clear (sz);
  *asterisk = false;
}
+  else
+   *asterisk = true;
 }
   return ret;
 }


[gcc r16-667] cobol: One additional edit to testsuite/cobol.dg/group1/check_88.cob [PR120251]

2025-05-15 Thread Robert Dubner via Gcc-cvs
https://gcc.gnu.org/g:fae53928595341981f08ded4edcbba07ee1d5d04

commit r16-667-gfae53928595341981f08ded4edcbba07ee1d5d04
Author: Robert Dubner 
Date:   Thu May 15 13:33:16 2025 -0400

cobol: One additional edit to testsuite/cobol.dg/group1/check_88.cob 
[PR120251]

Missed one edit.  This fixes that.

gcc/testsuite/ChangeLog:

PR cobol/120251
* cobol.dg/group1/check_88.cob: One final regex "." instead of "ß"

Diff:
---
 gcc/testsuite/cobol.dg/group1/check_88.cob | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/cobol.dg/group1/check_88.cob 
b/gcc/testsuite/cobol.dg/group1/check_88.cob
index 18a299fc282b..f1d0685e478a 100644
--- a/gcc/testsuite/cobol.dg/group1/check_88.cob
+++ b/gcc/testsuite/cobol.dg/group1/check_88.cob
@@ -17,7 +17,7 @@
 *> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} }
 *> { dg-output { (\n|\r\n|\r)} }
 *> { dg-output {There should be no spaces before the final quote(\n|\r\n|\r)} }
-*> { dg-output {".* Bundesstraße"(\n|\r\n|\r)} }
+*> { dg-output {".* Bundesstra.e"(\n|\r\n|\r)} }
 *> { dg-output { (\n|\r\n|\r)} }
 *> { dg-output {   IsLow   ""(\n|\r\n|\r)} }
 *> { dg-output {   IsZero  "000"(\n|\r\n|\r)} }


[gcc r15-9689] Update gcc zh_CN.po

2025-05-15 Thread Joseph Myers via Gcc-cvs
https://gcc.gnu.org/g:2384010230d48767a184fa6e245979e44dc8153d

commit r15-9689-g2384010230d48767a184fa6e245979e44dc8153d
Author: Joseph Myers 
Date:   Thu May 15 18:04:00 2025 +

Update gcc zh_CN.po

* zh_CN.po: Update.

Diff:
---
 gcc/po/zh_CN.po | 341 
 1 file changed, 145 insertions(+), 196 deletions(-)

diff --git a/gcc/po/zh_CN.po b/gcc/po/zh_CN.po
index a5073c1b6212..3f9023f7d039 100644
--- a/gcc/po/zh_CN.po
+++ b/gcc/po/zh_CN.po
@@ -4,7 +4,7 @@
 # Meng Jie , 2005-2014.
 # Jeff Bai , 2015.
 # Mingye Wang (Arthur2e5) , 2015, 2016.
-# Boyuan Yang <073p...@gmail.com>, 2019, 2023, 2024.
+# Boyuan Yang <073p...@gmail.com>, 2019, 2023-2025.
 # Zixing Zhou , 2023.
 # Zhanhaoxiang Zhang , 2024.
 #
@@ -33,11 +33,11 @@
 #
 msgid ""
 msgstr ""
-"Project-Id-Version: gcc 14.2.0\n"
+"Project-Id-Version: gcc 15.1.0\n"
 "Report-Msgid-Bugs-To: https://gcc.gnu.org/bugs/\n";
 "POT-Creation-Date: 2025-04-23 19:27+\n"
-"PO-Revision-Date: 2025-01-09 15:04+0800\n"
-"Last-Translator: Zhanhaoxiang Zhang \n"
+"PO-Revision-Date: 2025-05-15 13:53-0400\n"
+"Last-Translator: Boyuan Yang <073p...@gmail.com>\n"
 "Language-Team: Chinese (simplified) \n"
 "Language: zh_CN\n"
 "MIME-Version: 1.0\n"
@@ -45,7 +45,7 @@ msgstr ""
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=1; plural=0;\n"
 "X-Bugs: Report translation errors to the Language-Team address.\n"
-"X-Generator: Poedit 3.5\n"
+"X-Generator: Poedit 3.6\n"
 
 #: cif-code.def:39
 msgid "function not considered for inlining"
@@ -317,10 +317,8 @@ msgid "-E or -x required when input is from standard input"
 msgstr "当输入来自标准输入设备时,需要 -E 或 -x"
 
 #: config/darwin.h:153
-#, fuzzy
-#| msgid " conflicting code gen style switches are used"
 msgid "conflicting code generation switches"
-msgstr "使用了相互冲突的代码生成风格"
+msgstr "使用了相互冲突的代码生成开关"
 
 #: config/darwin.h:158
 msgid "-bundle_loader not allowed with -dynamiclib"
@@ -831,10 +829,9 @@ msgid "Issue debug information for compiler-generated 
auxiliary variables."
 msgstr ""
 
 #: fortran/lang.opt:486
-#, fuzzy, no-c-format
-#| msgid "Enable Plan 9 language extensions"
+#, no-c-format
 msgid "Enable all DEC language extensions."
-msgstr "启用九号计划语言扩展"
+msgstr "启用所有 DEC 语言扩展。"
 
 #: fortran/lang.opt:490
 #, fuzzy, no-c-format
@@ -868,9 +865,9 @@ msgid "Enable legacy math intrinsics for compatibility."
 msgstr ""
 
 #: fortran/lang.opt:515
-#, fuzzy, no-c-format
+#, no-c-format
 msgid "Enable support for DEC STRUCTURE/RECORD."
-msgstr "启用对巨型对象的支持"
+msgstr "启用对 DEC STRUCTURE/RECORD 的支持。"
 
 #: fortran/lang.opt:519
 #, no-c-format
@@ -1257,10 +1254,9 @@ msgid "Does nothing.  Preserved for backward 
compatibility."
 msgstr "不起作用。为向前兼容保留的选项。"
 
 #: fortran/lang.opt:911
-#, fuzzy, no-c-format
-#| msgid "Statically link the GNU Fortran helper library (libgfortran)"
+#, no-c-format
 msgid "Statically link the GNU Fortran helper library (libgfortran)."
-msgstr "静态链接 GNU Fortran 助手库(libgfortran)"
+msgstr "静态链接 GNU Fortran 助手库(libgfortran)。"
 
 #: fortran/lang.opt:915
 #, fuzzy, no-c-format
@@ -1296,7 +1292,7 @@ msgstr "遵循 ISO Fortran 2023 标准。"
 #: fortran/lang.opt:939
 #, no-c-format
 msgid "Enable experimental Fortran 202y features."
-msgstr ""
+msgstr "启用实验性的 Fortuan 202y 特性。"
 
 #: fortran/lang.opt:943
 #, no-c-format
@@ -1670,7 +1666,7 @@ msgstr "当把函数转换为不兼容类型时给出警告"
 #: c-family/c.opt:410
 #, no-c-format
 msgid "-Wbidi-chars=[none|unpaired|any|ucn] Warn about UTF-8 bidirectional 
control characters."
-msgstr ""
+msgstr "-Wbidi-chars=[none|unpaired|any|ucn] 对 UTF-8 双向控制字符给出警告。"
 
 #: c-family/c.opt:433
 #, no-c-format
@@ -1703,10 +1699,9 @@ msgid "Deprecated in favor of -Wc11-c23-compat."
 msgstr "已弃用,请改用 -Wc11-c23-compat。"
 
 #: c-family/c.opt:457
-#, fuzzy, no-c-format
-#| msgid "Warn about features not present in ISO C11, but present in ISO C23."
+#, no-c-format
 msgid "Warn about features not present in ISO C23, but present in ISO C2Y."
-msgstr "对 ISO C11 中不存在但 ISO C23 中存在的特性给出警告。"
+msgstr "对 ISO C23 中不存在但 ISO C2Y 中存在的特性给出警告。"
 
 #: c-family/c.opt:461
 #, no-c-format
@@ -1869,10 +1864,9 @@ msgid "Warn for implicit type conversions that may 
change a value."
 msgstr "当隐式类型转换可能改变值时给出警告"
 
 #: c-family/c.opt:590
-#, fuzzy, no-c-format
-#| msgid "Warn for converting NULL from/to a non-pointer type"
+#, no-c-format
 msgid "Warn for converting NULL from/to a non-pointer type."
-msgstr "将 NULL 转换为非指针类型时给出警告"
+msgstr "对 NULL 和非指针类型之间的转换给出警告。"
 
 #: c-family/c.opt:598
 #, fuzzy, no-c-format
@@ -1880,10 +1874,9 @@ msgid "Warn when performing class template argument 
deduction on a type with no
 msgstr "%qE不是类型%qT的有效模板实参,因为对象%qD没有外部链接"
 
 #: c-family/c.opt:603
-#, fuzzy, no-c-format
-#| msgid "Warn when all constructors and destructors are private"
+#, no-c-format
 msgid "Warn when all constructors and destructors are private."
-msgstr "当所有构造函数和析构函数都是私有时给出警告"
+msgstr "当所有构造函数和析构函数都是私有时给出警告。"
 
 #: c-family/c.opt:607
 #, no-c-format
@@ -1893,7 +1886,7 @@ msgstr "对悬空的 

[gcc r16-668] Update gcc zh_CN.po

2025-05-15 Thread Joseph Myers via Gcc-cvs
https://gcc.gnu.org/g:e87c5efabc3002acc41859fb81e698af8fa8412a

commit r16-668-ge87c5efabc3002acc41859fb81e698af8fa8412a
Author: Joseph Myers 
Date:   Thu May 15 18:02:26 2025 +

Update gcc zh_CN.po

* zh_CN.po: Update.

Diff:
---
 gcc/po/zh_CN.po | 341 
 1 file changed, 145 insertions(+), 196 deletions(-)

diff --git a/gcc/po/zh_CN.po b/gcc/po/zh_CN.po
index a5073c1b6212..3f9023f7d039 100644
--- a/gcc/po/zh_CN.po
+++ b/gcc/po/zh_CN.po
@@ -4,7 +4,7 @@
 # Meng Jie , 2005-2014.
 # Jeff Bai , 2015.
 # Mingye Wang (Arthur2e5) , 2015, 2016.
-# Boyuan Yang <073p...@gmail.com>, 2019, 2023, 2024.
+# Boyuan Yang <073p...@gmail.com>, 2019, 2023-2025.
 # Zixing Zhou , 2023.
 # Zhanhaoxiang Zhang , 2024.
 #
@@ -33,11 +33,11 @@
 #
 msgid ""
 msgstr ""
-"Project-Id-Version: gcc 14.2.0\n"
+"Project-Id-Version: gcc 15.1.0\n"
 "Report-Msgid-Bugs-To: https://gcc.gnu.org/bugs/\n";
 "POT-Creation-Date: 2025-04-23 19:27+\n"
-"PO-Revision-Date: 2025-01-09 15:04+0800\n"
-"Last-Translator: Zhanhaoxiang Zhang \n"
+"PO-Revision-Date: 2025-05-15 13:53-0400\n"
+"Last-Translator: Boyuan Yang <073p...@gmail.com>\n"
 "Language-Team: Chinese (simplified) \n"
 "Language: zh_CN\n"
 "MIME-Version: 1.0\n"
@@ -45,7 +45,7 @@ msgstr ""
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=1; plural=0;\n"
 "X-Bugs: Report translation errors to the Language-Team address.\n"
-"X-Generator: Poedit 3.5\n"
+"X-Generator: Poedit 3.6\n"
 
 #: cif-code.def:39
 msgid "function not considered for inlining"
@@ -317,10 +317,8 @@ msgid "-E or -x required when input is from standard input"
 msgstr "当输入来自标准输入设备时,需要 -E 或 -x"
 
 #: config/darwin.h:153
-#, fuzzy
-#| msgid " conflicting code gen style switches are used"
 msgid "conflicting code generation switches"
-msgstr "使用了相互冲突的代码生成风格"
+msgstr "使用了相互冲突的代码生成开关"
 
 #: config/darwin.h:158
 msgid "-bundle_loader not allowed with -dynamiclib"
@@ -831,10 +829,9 @@ msgid "Issue debug information for compiler-generated 
auxiliary variables."
 msgstr ""
 
 #: fortran/lang.opt:486
-#, fuzzy, no-c-format
-#| msgid "Enable Plan 9 language extensions"
+#, no-c-format
 msgid "Enable all DEC language extensions."
-msgstr "启用九号计划语言扩展"
+msgstr "启用所有 DEC 语言扩展。"
 
 #: fortran/lang.opt:490
 #, fuzzy, no-c-format
@@ -868,9 +865,9 @@ msgid "Enable legacy math intrinsics for compatibility."
 msgstr ""
 
 #: fortran/lang.opt:515
-#, fuzzy, no-c-format
+#, no-c-format
 msgid "Enable support for DEC STRUCTURE/RECORD."
-msgstr "启用对巨型对象的支持"
+msgstr "启用对 DEC STRUCTURE/RECORD 的支持。"
 
 #: fortran/lang.opt:519
 #, no-c-format
@@ -1257,10 +1254,9 @@ msgid "Does nothing.  Preserved for backward 
compatibility."
 msgstr "不起作用。为向前兼容保留的选项。"
 
 #: fortran/lang.opt:911
-#, fuzzy, no-c-format
-#| msgid "Statically link the GNU Fortran helper library (libgfortran)"
+#, no-c-format
 msgid "Statically link the GNU Fortran helper library (libgfortran)."
-msgstr "静态链接 GNU Fortran 助手库(libgfortran)"
+msgstr "静态链接 GNU Fortran 助手库(libgfortran)。"
 
 #: fortran/lang.opt:915
 #, fuzzy, no-c-format
@@ -1296,7 +1292,7 @@ msgstr "遵循 ISO Fortran 2023 标准。"
 #: fortran/lang.opt:939
 #, no-c-format
 msgid "Enable experimental Fortran 202y features."
-msgstr ""
+msgstr "启用实验性的 Fortuan 202y 特性。"
 
 #: fortran/lang.opt:943
 #, no-c-format
@@ -1670,7 +1666,7 @@ msgstr "当把函数转换为不兼容类型时给出警告"
 #: c-family/c.opt:410
 #, no-c-format
 msgid "-Wbidi-chars=[none|unpaired|any|ucn] Warn about UTF-8 bidirectional 
control characters."
-msgstr ""
+msgstr "-Wbidi-chars=[none|unpaired|any|ucn] 对 UTF-8 双向控制字符给出警告。"
 
 #: c-family/c.opt:433
 #, no-c-format
@@ -1703,10 +1699,9 @@ msgid "Deprecated in favor of -Wc11-c23-compat."
 msgstr "已弃用,请改用 -Wc11-c23-compat。"
 
 #: c-family/c.opt:457
-#, fuzzy, no-c-format
-#| msgid "Warn about features not present in ISO C11, but present in ISO C23."
+#, no-c-format
 msgid "Warn about features not present in ISO C23, but present in ISO C2Y."
-msgstr "对 ISO C11 中不存在但 ISO C23 中存在的特性给出警告。"
+msgstr "对 ISO C23 中不存在但 ISO C2Y 中存在的特性给出警告。"
 
 #: c-family/c.opt:461
 #, no-c-format
@@ -1869,10 +1864,9 @@ msgid "Warn for implicit type conversions that may 
change a value."
 msgstr "当隐式类型转换可能改变值时给出警告"
 
 #: c-family/c.opt:590
-#, fuzzy, no-c-format
-#| msgid "Warn for converting NULL from/to a non-pointer type"
+#, no-c-format
 msgid "Warn for converting NULL from/to a non-pointer type."
-msgstr "将 NULL 转换为非指针类型时给出警告"
+msgstr "对 NULL 和非指针类型之间的转换给出警告。"
 
 #: c-family/c.opt:598
 #, fuzzy, no-c-format
@@ -1880,10 +1874,9 @@ msgid "Warn when performing class template argument 
deduction on a type with no
 msgstr "%qE不是类型%qT的有效模板实参,因为对象%qD没有外部链接"
 
 #: c-family/c.opt:603
-#, fuzzy, no-c-format
-#| msgid "Warn when all constructors and destructors are private"
+#, no-c-format
 msgid "Warn when all constructors and destructors are private."
-msgstr "当所有构造函数和析构函数都是私有时给出警告"
+msgstr "当所有构造函数和析构函数都是私有时给出警告。"
 
 #: c-family/c.opt:607
 #, no-c-format
@@ -1893,7 +1886,7 @@ msgstr "对悬空的 e

[gcc r13-9658] crypto/tls: fix Config.Time in tests using expired certificates

2025-05-15 Thread Sam James via Gcc-cvs
https://gcc.gnu.org/g:9ad74a57904744418a7319a492a698ddbfb787ca

commit r13-9658-g9ad74a57904744418a7319a492a698ddbfb787ca
Author: Ian Lance Taylor 
Date:   Sat Jan 4 15:54:58 2025 -0800

crypto/tls: fix Config.Time in tests using expired certificates

This is a backport of https://go.dev/cl/640237 from the main repo.

Fixes PR go/118286

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/640435
(cherry picked from commit ed1493e12ed75e837e9b9aa794ed24daf397df7c)

Diff:
---
 libgo/go/crypto/tls/handshake_client_test.go | 28 
 libgo/go/crypto/tls/handshake_server_test.go |  2 ++
 libgo/go/crypto/tls/handshake_test.go|  5 +
 libgo/go/crypto/tls/tls_test.go  |  4 +---
 4 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/libgo/go/crypto/tls/handshake_client_test.go 
b/libgo/go/crypto/tls/handshake_client_test.go
index 0950bb0ac453..40409a42c5b8 100644
--- a/libgo/go/crypto/tls/handshake_client_test.go
+++ b/libgo/go/crypto/tls/handshake_client_test.go
@@ -881,6 +881,7 @@ func testResumption(t *testing.T, version uint16) {
MaxVersion:   version,
CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, 
TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Certificates: testConfig.Certificates,
+   Time: testTime,
}
 
issuer, err := x509.ParseCertificate(testRSACertificateIssuer)
@@ -897,6 +898,7 @@ func testResumption(t *testing.T, version uint16) {
ClientSessionCache: NewLRUClientSessionCache(32),
RootCAs:rootCAs,
ServerName: "example.golang",
+   Time:   testTime,
}
 
testResumeState := func(test string, didResume bool) {
@@ -944,20 +946,20 @@ func testResumption(t *testing.T, version uint16) {
}
 
// An old session ticket can resume, but the server will provide a 
ticket encrypted with a fresh key.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*time.Hour + time.Minute) }
testResumeState("ResumeWithOldTicket", true)
if bytes.Equal(ticket[:ticketKeyNameLen], 
getTicket()[:ticketKeyNameLen]) {
t.Fatal("old first ticket matches the fresh one")
}
 
// Now the session tickey key is expired, so a full handshake should 
occur.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*8*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*8*time.Hour + time.Minute) }
testResumeState("ResumeWithExpiredTicket", false)
if bytes.Equal(ticket, getTicket()) {
t.Fatal("expired first ticket matches the fresh one")
}
 
-   serverConfig.Time = func() time.Time { return time.Now() } // reset the 
time back
+   serverConfig.Time = func() time.Time { return testTime() } // reset the 
time back
key1 := randomKey()
serverConfig.SetSessionTicketKeys([][32]byte{key1})
 
@@ -974,11 +976,11 @@ func testResumption(t *testing.T, version uint16) {
testResumeState("KeyChangeFinish", true)
 
// Age the session ticket a bit, but not yet expired.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*time.Hour + time.Minute) }
testResumeState("OldSessionTicket", true)
ticket = getTicket()
// Expire the session ticket, which would force a full handshake.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*8*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*8*time.Hour + 2*time.Minute) }
testResumeState("ExpiredSessionTicket", false)
if bytes.Equal(ticket, getTicket()) {
t.Fatal("new ticket wasn't provided after old ticket expired")
@@ -988,7 +990,7 @@ func testResumption(t *testing.T, version uint16) {
d := 0 * time.Hour
for i := 0; i < 13; i++ {
d += 12 * time.Hour
-   serverConfig.Time = func() time.Time { return time.Now().Add(d) 
}
+   serverConfig.Time = func() time.Time { return testTime().Add(d) 
}
testResumeState("OldSessionTicket", true)
}
// Expire it (now a little more than 7 days) and make sure a full
@@ -996,7 +998,7 @@ func testResumption(t *testing.T, version uint16) {
// TLS 1.3 since the client should be using a fresh ticket sent over
// by the server.
d += 12 * time.Hour
-   serverConfig.Time = func() time.Time { return time.Now().Add(d) }
+   serverConfig.Time = func() time.Time { return testTime().Add(d) }
if version == VersionTLS13 {
testResumeState(

[gcc r12-11099] crypto/tls: fix Config.Time in tests using expired certificates

2025-05-15 Thread Sam James via Gcc-cvs
https://gcc.gnu.org/g:b1c65033b01d43d36b5b7f3713b6e409792bd51c

commit r12-11099-gb1c65033b01d43d36b5b7f3713b6e409792bd51c
Author: Ian Lance Taylor 
Date:   Sat Jan 4 15:54:58 2025 -0800

crypto/tls: fix Config.Time in tests using expired certificates

This is a backport of https://go.dev/cl/640237 from the main repo.

Fixes PR go/118286

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/640435
(cherry picked from commit ed1493e12ed75e837e9b9aa794ed24daf397df7c)

Diff:
---
 libgo/go/crypto/tls/handshake_client_test.go | 28 
 libgo/go/crypto/tls/handshake_server_test.go |  2 ++
 libgo/go/crypto/tls/handshake_test.go|  5 +
 libgo/go/crypto/tls/tls_test.go  |  4 +---
 4 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/libgo/go/crypto/tls/handshake_client_test.go 
b/libgo/go/crypto/tls/handshake_client_test.go
index 0950bb0ac453..40409a42c5b8 100644
--- a/libgo/go/crypto/tls/handshake_client_test.go
+++ b/libgo/go/crypto/tls/handshake_client_test.go
@@ -881,6 +881,7 @@ func testResumption(t *testing.T, version uint16) {
MaxVersion:   version,
CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, 
TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Certificates: testConfig.Certificates,
+   Time: testTime,
}
 
issuer, err := x509.ParseCertificate(testRSACertificateIssuer)
@@ -897,6 +898,7 @@ func testResumption(t *testing.T, version uint16) {
ClientSessionCache: NewLRUClientSessionCache(32),
RootCAs:rootCAs,
ServerName: "example.golang",
+   Time:   testTime,
}
 
testResumeState := func(test string, didResume bool) {
@@ -944,20 +946,20 @@ func testResumption(t *testing.T, version uint16) {
}
 
// An old session ticket can resume, but the server will provide a 
ticket encrypted with a fresh key.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*time.Hour + time.Minute) }
testResumeState("ResumeWithOldTicket", true)
if bytes.Equal(ticket[:ticketKeyNameLen], 
getTicket()[:ticketKeyNameLen]) {
t.Fatal("old first ticket matches the fresh one")
}
 
// Now the session tickey key is expired, so a full handshake should 
occur.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*8*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*8*time.Hour + time.Minute) }
testResumeState("ResumeWithExpiredTicket", false)
if bytes.Equal(ticket, getTicket()) {
t.Fatal("expired first ticket matches the fresh one")
}
 
-   serverConfig.Time = func() time.Time { return time.Now() } // reset the 
time back
+   serverConfig.Time = func() time.Time { return testTime() } // reset the 
time back
key1 := randomKey()
serverConfig.SetSessionTicketKeys([][32]byte{key1})
 
@@ -974,11 +976,11 @@ func testResumption(t *testing.T, version uint16) {
testResumeState("KeyChangeFinish", true)
 
// Age the session ticket a bit, but not yet expired.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*time.Hour + time.Minute) }
testResumeState("OldSessionTicket", true)
ticket = getTicket()
// Expire the session ticket, which would force a full handshake.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*8*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*8*time.Hour + 2*time.Minute) }
testResumeState("ExpiredSessionTicket", false)
if bytes.Equal(ticket, getTicket()) {
t.Fatal("new ticket wasn't provided after old ticket expired")
@@ -988,7 +990,7 @@ func testResumption(t *testing.T, version uint16) {
d := 0 * time.Hour
for i := 0; i < 13; i++ {
d += 12 * time.Hour
-   serverConfig.Time = func() time.Time { return time.Now().Add(d) 
}
+   serverConfig.Time = func() time.Time { return testTime().Add(d) 
}
testResumeState("OldSessionTicket", true)
}
// Expire it (now a little more than 7 days) and make sure a full
@@ -996,7 +998,7 @@ func testResumption(t *testing.T, version uint16) {
// TLS 1.3 since the client should be using a fresh ticket sent over
// by the server.
d += 12 * time.Hour
-   serverConfig.Time = func() time.Time { return time.Now().Add(d) }
+   serverConfig.Time = func() time.Time { return testTime().Add(d) }
if version == VersionTLS13 {
testResumeState

[gcc r14-11786] crypto/tls: fix Config.Time in tests using expired certificates

2025-05-15 Thread Sam James via Gcc-cvs
https://gcc.gnu.org/g:ebef63ee3a34475ec224ddf0fbc64ccb31033d8d

commit r14-11786-gebef63ee3a34475ec224ddf0fbc64ccb31033d8d
Author: Ian Lance Taylor 
Date:   Sat Jan 4 15:54:58 2025 -0800

crypto/tls: fix Config.Time in tests using expired certificates

This is a backport of https://go.dev/cl/640237 from the main repo.

Fixes PR go/118286

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/640435
(cherry picked from commit ed1493e12ed75e837e9b9aa794ed24daf397df7c)

Diff:
---
 libgo/go/crypto/tls/handshake_client_test.go | 28 
 libgo/go/crypto/tls/handshake_server_test.go |  2 ++
 libgo/go/crypto/tls/handshake_test.go|  5 +
 libgo/go/crypto/tls/tls_test.go  |  4 +---
 4 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/libgo/go/crypto/tls/handshake_client_test.go 
b/libgo/go/crypto/tls/handshake_client_test.go
index 0950bb0ac453..40409a42c5b8 100644
--- a/libgo/go/crypto/tls/handshake_client_test.go
+++ b/libgo/go/crypto/tls/handshake_client_test.go
@@ -881,6 +881,7 @@ func testResumption(t *testing.T, version uint16) {
MaxVersion:   version,
CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, 
TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Certificates: testConfig.Certificates,
+   Time: testTime,
}
 
issuer, err := x509.ParseCertificate(testRSACertificateIssuer)
@@ -897,6 +898,7 @@ func testResumption(t *testing.T, version uint16) {
ClientSessionCache: NewLRUClientSessionCache(32),
RootCAs:rootCAs,
ServerName: "example.golang",
+   Time:   testTime,
}
 
testResumeState := func(test string, didResume bool) {
@@ -944,20 +946,20 @@ func testResumption(t *testing.T, version uint16) {
}
 
// An old session ticket can resume, but the server will provide a 
ticket encrypted with a fresh key.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*time.Hour + time.Minute) }
testResumeState("ResumeWithOldTicket", true)
if bytes.Equal(ticket[:ticketKeyNameLen], 
getTicket()[:ticketKeyNameLen]) {
t.Fatal("old first ticket matches the fresh one")
}
 
// Now the session tickey key is expired, so a full handshake should 
occur.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*8*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*8*time.Hour + time.Minute) }
testResumeState("ResumeWithExpiredTicket", false)
if bytes.Equal(ticket, getTicket()) {
t.Fatal("expired first ticket matches the fresh one")
}
 
-   serverConfig.Time = func() time.Time { return time.Now() } // reset the 
time back
+   serverConfig.Time = func() time.Time { return testTime() } // reset the 
time back
key1 := randomKey()
serverConfig.SetSessionTicketKeys([][32]byte{key1})
 
@@ -974,11 +976,11 @@ func testResumption(t *testing.T, version uint16) {
testResumeState("KeyChangeFinish", true)
 
// Age the session ticket a bit, but not yet expired.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*time.Hour + time.Minute) }
testResumeState("OldSessionTicket", true)
ticket = getTicket()
// Expire the session ticket, which would force a full handshake.
-   serverConfig.Time = func() time.Time { return 
time.Now().Add(24*8*time.Hour + time.Minute) }
+   serverConfig.Time = func() time.Time { return 
testTime().Add(24*8*time.Hour + 2*time.Minute) }
testResumeState("ExpiredSessionTicket", false)
if bytes.Equal(ticket, getTicket()) {
t.Fatal("new ticket wasn't provided after old ticket expired")
@@ -988,7 +990,7 @@ func testResumption(t *testing.T, version uint16) {
d := 0 * time.Hour
for i := 0; i < 13; i++ {
d += 12 * time.Hour
-   serverConfig.Time = func() time.Time { return time.Now().Add(d) 
}
+   serverConfig.Time = func() time.Time { return testTime().Add(d) 
}
testResumeState("OldSessionTicket", true)
}
// Expire it (now a little more than 7 days) and make sure a full
@@ -996,7 +998,7 @@ func testResumption(t *testing.T, version uint16) {
// TLS 1.3 since the client should be using a fresh ticket sent over
// by the server.
d += 12 * time.Hour
-   serverConfig.Time = func() time.Time { return time.Now().Add(d) }
+   serverConfig.Time = func() time.Time { return testTime().Add(d) }
if version == VersionTLS13 {
testResumeState

[gcc r16-649] tighten type verification for CONJ_EXPR

2025-05-15 Thread Alexander Monakov via Gcc-cvs
https://gcc.gnu.org/g:5c012971969db94f88335d9bacd192d318564daa

commit r16-649-g5c012971969db94f88335d9bacd192d318564daa
Author: Alexander Monakov 
Date:   Mon May 12 23:23:31 2025 +0300

tighten type verification for CONJ_EXPR

As a followup to PAREN_EXPR verification, let's ensure that CONJ_EXPR is
only used with COMPLEX_TYPE.  While at it, move the whole block towards
the end of the switch, because unlike the other entries it needs to
break out of the switch, not immediately return from the function,
as after the switch we check that types of LHS and RHS match.

Refactor a bit to avoid repeated blocks with debug_generic_expr.

gcc/ChangeLog:

* tree-cfg.cc (verify_gimple_assign_unary): Accept only
COMPLEX_TYPE for CONJ_EXPR.

Diff:
---
 gcc/tree-cfg.cc | 47 +--
 1 file changed, 21 insertions(+), 26 deletions(-)

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 928459a38b2a..b342b147716a 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -3867,32 +3867,6 @@ verify_gimple_assign_unary (gassign *stmt)
 
   return false;
 
-case NEGATE_EXPR:
-case ABS_EXPR:
-case BIT_NOT_EXPR:
-case CONJ_EXPR:
-  /* Disallow pointer and offset types for many of the unary gimple. */
-  if (POINTER_TYPE_P (lhs_type)
- || TREE_CODE (lhs_type) == OFFSET_TYPE)
-   {
- error ("invalid types for %qs", code_name);
- debug_generic_expr (lhs_type);
- debug_generic_expr (rhs1_type);
- return true;
-   }
-  break;
-
-case PAREN_EXPR:
-  /* Disallow non arthmetic types on PAREN_EXPR. */
-  if (AGGREGATE_TYPE_P (lhs_type))
-   {
- error ("invalid types for %qs", code_name);
- debug_generic_expr (lhs_type);
- debug_generic_expr (rhs1_type);
- return true;
-   }
-  break;
-
 case ABSU_EXPR:
   if (!ANY_INTEGRAL_TYPE_P (lhs_type)
  || !TYPE_UNSIGNED (lhs_type)
@@ -3918,6 +3892,27 @@ verify_gimple_assign_unary (gassign *stmt)
}
   return false;
 
+case CONJ_EXPR:
+  if (TREE_CODE (lhs_type) != COMPLEX_TYPE)
+   {
+diagnose_unary_lhs:
+ error ("invalid type for %qs", code_name);
+ debug_generic_expr (lhs_type);
+ return true;
+   }
+  break;
+
+case NEGATE_EXPR:
+case ABS_EXPR:
+case BIT_NOT_EXPR:
+  if (POINTER_TYPE_P (lhs_type) || TREE_CODE (lhs_type) == OFFSET_TYPE)
+   goto diagnose_unary_lhs;
+  /* FALLTHRU */
+case PAREN_EXPR:
+  if (AGGREGATE_TYPE_P (lhs_type))
+   goto diagnose_unary_lhs;
+  break;
+
 default:
   gcc_unreachable ();
 }


[gcc r14-11787] c++: Fix up handling of for/while loops with declarations in condition [PR86769]

2025-05-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:24cd4753e470ec122d232c9da825274bce0bae15

commit r14-11787-g24cd4753e470ec122d232c9da825274bce0bae15
Author: Jakub Jelinek 
Date:   Fri Feb 7 17:07:23 2025 +0100

c++: Fix up handling of for/while loops with declarations in condition 
[PR86769]

As the following testcase show (note, just for-{3,4,6,7,8}.C, 
constexpr-86769.C
and stmtexpr27.C FAIL without the patch, the rest is just that I couldn't
find coverage for some details and so added tests we don't regress or for5.C
is from Marek's attempt in the PR), we weren't correctly handling for/while
loops with declarations as conditions.

The C++ FE has the simplify_loop_decl_cond function which transforms
such loops as mentioned in the comment:
while (A x = 42) { }
for (; A x = 42;) { }
   becomes
while (true) { A x = 42; if (!x) break; }
for (;;) { A x = 42; if (!x) break; }
For for loops this is not enough, as the x declaration should be
still in scope when expr (if any) is executed, and injecting the
expr expression into the body in the FE needs to have the continue
label in between, something normally added by the c-family
genericization.  One of my thoughts was to just add there an artificial
label plus the expr expression in the FE and tell c-family about that
label, so that it doesn't create it but uses what has been emitted.

Unfortunately break/continue are resolved to labels only at c-family
genericization time and by moving the condition (and its preparation
statements such as the DECL_EXPR) into the body (and perhaps by also
moving there the (increment) expr as well) we resolve incorrectly any
break/continue statement appearing in cond (or newly perhaps also expr)
expression(s).  While in standard C++ one can't have something like that
there, with statement expressions they are possible there, and we actually
have testsuite coverage that when they appear outside of the body of the
loop they bind to an outer loop rather than the inner one.  When the FE
moves everything into the body, c-family can't distinguish any more between
the user body vs. the condition/preparation statements vs. expr expression.

So, the following patch instead keeps them separate and does the merging
only at the c-family loop genericization time.  For that the patch
introduces two new operands of FOR_STMT and WHILE_STMT, *_COND_PREP
which is forced to be a BIND_EXPR which contains the preparation statements
like DECL_EXPR, and the initialization of that variable, so basically what
{FOR,WHILE}_BODY has when we encounter the function dealing with this,
except one optional CLEANUP_STMT at the end which holds cleanups for the
variable if it needs to be destructed.  This CLEANUP_STMT is removed and
the actual cleanup saved into another new operand, *_COND_CLEANUP.

The c-family loop genericization handles such loops roughly the way
https://eel.is/c++draft/stmt.for and https://eel.is/c++draft/stmt.while
specifies, so the body is (if *_COND_CLEANUP is non-NULL)
{ A x = 42; try { if (!x) break; body; cont_label: expr; } finally { 
cleanup; } }
and otherwise
{ A x = 42; if (!x) break; body; cont_label: expr; }
i.e. the *_COND, *_BODY, optional continue label, FOR_EXPR  are appended
into the body of the *_COND_PREP BIND_EXPR.

And when doing constexpr evaluation of such FOR/WHILE loops, we treat
it similarly, first evaluate *_COND_PREP except the
  for (tree decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
destroy_value_checked (ctx, decl, non_constant_p);
part of BIND_EXPR handling for it, then evaluate *_COND (and decide based
on whether it was false or true like before), then *_BODY, then FOR_EXPR,
then *_COND_CLEANUP (similarly to the way how CLEANUP_STMT handling handles
that) and finally do those destroy_value_checked.

Note, the constexpr-86769.C testcase FAILs with both clang++ and MSVC (note,
the rest of tests PASS with clang++) but I believe it must be just a bug
in those compilers, new int is done in all the constructors and delete is
done in the destructor, so when clang++ reports one of the new int weren't
deallocated during constexpr evaluation I don't see how that would be
possible.  When the same test has all the constexpr stuff, all the new int
are properly deleted at runtime when compiled by both compilers and valgrind
is happy about it, no leaks.

2025-02-07  Jakub Jelinek  
Jason Merrill  

PR c++/86769
gcc/c-family/
* c-common.def (FOR_STMT): Add 2 operands and document them.
(WHILE_STMT): Likewise.
* c-common.h (WHILE_COND_PREP, WHILE_COND_CLEANUP): Define.
(FOR_COND_PREP, FOR_COND_CLEANUP): Define.
  

[gcc r14-11789] i386: Change RTL representation of bt[lq] [PR118623]

2025-05-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:aa4cd614456de65ee3417acb83c6cff0640144e9

commit r14-11789-gaa4cd614456de65ee3417acb83c6cff0640144e9
Author: Jakub Jelinek 
Date:   Mon Feb 10 10:40:22 2025 +0100

i386: Change RTL representation of bt[lq] [PR118623]

The following testcase is miscompiled because of RTL represententation
of bt{l,q} insn followed by e.g. j{c,nc} being misleading to what it
actually does.
Let's look e.g. at
(define_insn_and_split "*jcc_bt"
  [(set (pc)
(if_then_else (match_operator 0 "bt_comparison_operator"
[(zero_extract:SWI48
   (match_operand:SWI48 1 "nonimmediate_operand")
   (const_int 1)
   (match_operand:QI 2 "nonmemory_operand"))
 (const_int 0)])
  (label_ref (match_operand 3))
  (pc)))
   (clobber (reg:CC FLAGS_REG))]
  "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
   && (CONST_INT_P (operands[2])
   ? (INTVAL (operands[2]) < GET_MODE_BITSIZE (mode)
  && INTVAL (operands[2])
   >= (optimize_function_for_size_p (cfun) ? 8 : 32))
   : !memory_operand (operands[1], mode))
   && ix86_pre_reload_split ()"
  "#"
  "&& 1"
  [(set (reg:CCC FLAGS_REG)
(compare:CCC
  (zero_extract:SWI48
(match_dup 1)
(const_int 1)
(match_dup 2))
  (const_int 0)))
   (set (pc)
(if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
  (label_ref (match_dup 3))
  (pc)))]
{
  operands[0] = shallow_copy_rtx (operands[0]);
  PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
})
The define_insn part in RTL describes exactly what it does,
jumps to op3 if bit op2 in op1 is set (for op0 NE) or not set (for op0 EQ).
The problem is with what it splits into.
put_condition_code %C1 for CCCmode comparisons emits c for EQ and LTU,
nc for NE and GEU and ICEs otherwise.
CCCmode is used mainly for carry out of add/adc, borrow out of sub/sbb,
in those cases e.g. for add we have
(set (reg:CCC flags) (compare:CCC (plus:M x y) x))
and use (ltu (reg:CCC flags) (const_int 0)) for carry set and
(geu (reg:CCC flags) (const_int 0)) for carry not set.  These cases
model in RTL what is actually happening, compare in infinite precision
x from the result of finite precision addition in M mode and if it is
less than unsigned (i.e. overflow happened), carry is set.
Another use of CCCmode is in UNSPEC_* patterns, those are used with
(eq (reg:CCC flags) (const_int 0)) for carry set and ne for unset,
given the UNSPEC no big deal, the middle-end doesn't know what means
set or unset.
But for the bt{l,q}; j{c,nc} case the above splits it into
(set (reg:CCC flags) (compare:CCC (zero_extract) (const_int 0)))
for bt and
(set (pc) (if_then_else (eq (reg:CCC flags) (const_int 0)) (label_ref) 
(pc)))
for the bit set case (so that the jump expands to jc) and ne for
the bit not set case (so that the jump expands to jnc).
Similarly for the different splitters for cmov and set{c,nc} etc.
The problem is that when the middle-end reads this RTL, it feels
the exact opposite to it.  If zero_extract is 1, flags is set
to comparison of 1 and 0 and that would mean using ne ne in the
if_then_else, and vice versa.

So, in order to better describe in RTL what is actually happening,
one possibility would be to swap the behavior of put_condition_code
and use NE + LTU -> c and EQ + GEU -> nc rather than the current
EQ + LTU -> c and NE + GEU -> nc; and adjust everything.  The
following patch uses a more limited approach, instead of representing
bt{l,q}; j{c,nc} case as written above it uses
(set (reg:CCC flags) (compare:CCC (const_int 0) (zero_extract)))
and
(set (pc) (if_then_else (ltu (reg:CCC flags) (const_int 0)) (label_ref) 
(pc)))
which uses the existing put_condition_code but describes what the
insns actually do in RTL clearly.  If zero_extract is 1,
then flags are LTU, 0U < 1U, if zero_extract is 0, then flags are GEU,
0U >= 0U.  The patch adjusts the *bt define_insn and all the
splitters to it and its comparisons/conditional moves/setXX.

2025-02-10  Jakub Jelinek  

PR target/118623
* config/i386/i386.md (*bt): Represent bt as
compare:CCC of const0_rtx and zero_extract rather than
zero_extract and const0_rtx.
(*bt_mask): Likewise.
(*jcc_bt): Likewise.  Use LTU and GEU as flags test
instead of EQ and NE.
(*jcc_bt_mask): Likewise.
(*jcc_bt_mask_1): Likewise.
(Help combine recogniz

[gcc r14-11788] c++: Fix up regressions caused by for/while loops with declarations [PR118822]

2025-05-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:db73411a72cf2052dddcf9fa0523588599a73537

commit r14-11788-gdb73411a72cf2052dddcf9fa0523588599a73537
Author: Jakub Jelinek 
Date:   Thu Feb 13 10:21:29 2025 +0100

c++: Fix up regressions caused by for/while loops with declarations 
[PR118822]

The recent PR86769 r15-7426 changes regressed the following two testcases,
the first one is more important as it is derived from real-world code.

The first problem is that the chosen
prep = do_pushlevel (sk_block);
// emit something
body = push_stmt_list ();
// emit further stuff
body = pop_stmt_list (body);
prep = do_poplevel (prep);
way of constructing the {FOR,WHILE}_COND_PREP and {FOR,WHILE}_BODY
isn't reliable.  If during parsing a label is seen in the body and then
some decl with destructors, sk_cleanup transparent scope is added, but
the correspondiong result from push_stmt_list is saved in
*current_binding_level and pop_stmt_list then pops even that statement list
but only do_poplevel actually attempts to pop the sk_cleanup scope and so we
ICE.
The reason for not doing do_pushlevel (sk_block); do_pushlevel (sk_block);
is that variables should be in the same scope (otherwise various e.g.
redeclaration*.C tests FAIL) and doing do_pushlevel (sk_block); do_pushlevel
(sk_cleanup); wouldn't work either as do_poplevel would silently unwind even
the cleanup one.

So, the following patch changes the earlier approach.  Nothing is removed
from the {FOR,WHILE}_COND_PREP subtrees while doing adjust_loop_decl_cond,
push_stmt_list isn't called either; all it does is remember as an integer
the number of cleanups (CLEANUP_STMT at the end of the STATEMENT_LISTs)
from querying stmt_list_stack and finding the initial *body_p in there
(that integer is stored into {FOR,WHILE}_COND_CLEANUP), and temporarily
{FOR,WHILE}_BODY is set to the last statement (if any) in the innermost
STATEMENT_LIST at the adjust_loop_decl_cond time; then at
finish_{for,while}_stmt a new finish_loop_cond_prep routine takes care of
do_poplevel for the scope (which is in {FOR,WHILE}_COND_PREP) and finds
given {FOR,WHILE}_COND_CLEANUP number and {FOR,WHILE}_BODY tree the right
spot where body statements start and moves that into {FOR,WHILE}_BODY.
Finally genericize_c_loop then inserts the cond, body, continue label, expr
into the right subtree of {FOR,WHILE}_COND_PREP.
The constexpr evaluation unfortunately had to be changed as well, because
we don't want to evaluate everything in BIND_EXPR_BODY (*_COND_PREP ())
right away, we want to evaluate it with the exception of the CLEANUP_STMT
cleanups at the end (given {FOR,WHILE}_COND_CLEANUP levels), and defer
the evaluation of the cleanups until after cond, body, expr are evaluated.

2025-02-13  Jakub Jelinek  

PR c++/118822
gcc/
* tree-iterator.h (tsi_split_stmt_list): Declare.
* tree-iterator.cc (tsi_split_stmt_list): New function.
gcc/c-family/
* c-common.h (WHILE_COND_CLEANUP): Change description in comment.
(FOR_COND_CLEANUP): Likewise.
* c-gimplify.cc (genericize_c_loop): Adjust for COND_CLEANUP
being CLEANUP_STMT/TRY_FINALLY_EXPR trailing nesting depth
instead of actual cleanup.
gcc/cp/
* semantics.cc (adjust_loop_decl_cond): Allow multiple trailing
CLEANUP_STMT levels in *BODY_P.  Set *CLEANUP_P to the number
of levels rather than one particular cleanup, keep the cleanups
in *PREP_P.  Set *BODY_P to the last stmt in the cur_stmt_list
or NULL if *CLEANUP_P and the innermost cur_stmt_list is empty.
(finish_loop_cond_prep): New function.
(finish_while_stmt, finish_for_stmt): Use it.  Don't call
set_one_cleanup_loc.
* constexpr.cc (cxx_eval_loop_expr): Adjust handling of
{FOR,WHILE}_COND_{PREP,CLEANUP}.
gcc/testsuite/
* g++.dg/expr/for9.C: New test.

(cherry picked from commit 26baa2c09b39abf037afad349a318dc5734eae25)

Diff:
---
 gcc/c-family/c-common.h  |   6 +-
 gcc/c-family/c-gimplify.cc   |  41 +
 gcc/cp/constexpr.cc  |  97 ++---
 gcc/cp/semantics.cc  | 128 ---
 gcc/testsuite/g++.dg/expr/for9.C |  25 
 gcc/tree-iterator.cc |  22 +++
 gcc/tree-iterator.h  |   1 +
 7 files changed, 251 insertions(+), 69 deletions(-)

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 41f7ca3ef012..8d8bead50306 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1492,7 +1492,8 @@ extern tree build_userdef_literal (tree suffix_id, tree 
value,
 
 /* WHILE_STMT accessors.  These give access to the condition of the
while statement and the b

[gcc r16-650] libstdc++: build testsuite with -Wabi

2025-05-15 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:f28ff1e4f1c91f46d80e26dd77917e47cdd41bbe

commit r16-650-gf28ff1e4f1c91f46d80e26dd77917e47cdd41bbe
Author: Jason Merrill 
Date:   Thu May 1 10:20:25 2025 -0400

libstdc++: build testsuite with -Wabi

I added this locally to check whether the PR120012 fix affects libstdc++ (it
doesn't) but it seems more generally useful to catch whether compiler
ABI changes have library impact.

libstdc++-v3/ChangeLog:

* testsuite/lib/libstdc++.exp: Add -Wabi.

Diff:
---
 libstdc++-v3/testsuite/lib/libstdc++.exp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
b/libstdc++-v3/testsuite/lib/libstdc++.exp
index fbc9f7f13e64..da1f4245e4b8 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -586,6 +586,7 @@ proc v3_target_compile { source dest type options } {
 global tool
 
 lappend options "additional_flags=-fdiagnostics-plain-output"
+lappend options "additional_flags=-Wabi=20";
 
 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
lappend options "libs=${gluefile}"


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression pr117797

2025-05-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:adc44bd18c07895123f6752956f417eebcaa5acb

commit adc44bd18c07895123f6752956f417eebcaa5acb
Author: Mikael Morin 
Date:   Wed May 14 22:23:14 2025 +0200

Correction régression pr117797

Diff:
---
 gcc/fortran/trans-array.cc | 5 +
 gcc/fortran/trans-expr.cc  | 9 -
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index ccf8ab9e698e..49be412e609b 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -2800,6 +2800,9 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, 
bool subscript,
&& se.expr
&& GFC_CLASS_TYPE_P (TREE_TYPE (se.expr)))
  {
+   if (!ss->info->class_container
+   && se.class_container)
+ ss->info->class_container = se.class_container;
tree tmp = gfc_class_data_get (se.expr);
info->descriptor = tmp;
info->data = gfc_conv_descriptor_data_get (tmp);
@@ -3622,6 +3625,8 @@ gfc_conv_scalarized_array_ref (gfc_se * se, gfc_array_ref 
* ar, bool tmp_array =
   gfc_array_info *info = &ss->info->data.array;
   se->expr = build_array_ref_dim (ss, index, info->lbound[ss->dim[n]],
  info->spacing[ss->dim[n]], tmp_array);
+  if (ss->info->class_container)
+se->class_container = ss->info->class_container;
 }
 
 
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index f2727f2ea071..f4838f2d48c7 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -8652,6 +8652,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 one is necessary to ensure no memory leakage.  */
  se->expr = gfc_evaluate_now (se->expr, &se->pre);
 
+ se->class_container = se->expr;
+
  /* Finalize the result, if necessary.  */
  attr = expr->value.function.esym
 ? CLASS_DATA (expr->value.function.esym->result)->attr
@@ -10393,7 +10395,12 @@ trans_class_vptr_len_assignment (stmtblock_t *block, 
gfc_expr * le,
   if (!DECL_P (rse->expr))
{
  if (re->ts.type == BT_CLASS && !GFC_CLASS_TYPE_P (TREE_TYPE 
(rse->expr)))
-   class_expr = gfc_get_class_from_expr (rse->expr);
+   {
+ if (rse->class_container)
+   class_expr = rse->class_container;
+ else
+   class_expr = gfc_get_class_from_expr (rse->expr);
+   }
 
  if (rse->loop)
pre = &rse->loop->pre;


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression alloc_comp_auto_array_1

2025-05-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:640cd6aeedb0434fd7f7bebb098eefdd90937cd8

commit 640cd6aeedb0434fd7f7bebb098eefdd90937cd8
Author: Mikael Morin 
Date:   Thu May 15 16:30:28 2025 +0200

Correction régression alloc_comp_auto_array_1

Diff:
---
 gcc/fortran/trans-array.cc | 58 +++---
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 49be412e609b..6501adcb66d4 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6277,7 +6277,8 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, tree 
* poffset,
   tree eltype = gfc_get_element_type (type);
   tree elem_len = fold_convert_loc (input_location, gfc_array_index_type,
TYPE_SIZE_UNIT (eltype));
-  size = elem_len;
+  gcc_assert (INTEGER_CST_P (elem_len));
+  size = gfc_index_one_node;
   offset = gfc_index_zero_node;
   tree spacing = GFC_TYPE_ARRAY_SPACING (type, 0);
   if (spacing && VAR_P (spacing))
@@ -6309,39 +6310,38 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, 
tree * poffset,
}
   /* The offset of this dimension.  offset = offset - lbound * sm.  */
   tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-lbound, size);
+lbound, spacing);
   offset = fold_build2_loc (input_location, MINUS_EXPR, 
gfc_array_index_type,
offset, tmp);
 
-  /* The size of this dimension, and the stride of the next.  */
-  tree spacing;
+  /* Calculate spacing = size * (ubound + 1 - lbound).  */
+  tmp = gfc_conv_array_extent_dim (lbound, ubound, nullptr);
+  size = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, size, tmp);
+
+  tree array_info;
   if (dim + 1 < as->rank)
-spacing = GFC_TYPE_ARRAY_SPACING (type, dim + 1);
+   array_info = GFC_TYPE_ARRAY_SPACING (type, dim + 1);
   else
-   spacing = GFC_TYPE_ARRAY_SIZE (type);
+   array_info = GFC_TYPE_ARRAY_SIZE (type);
 
-  if (ubound != NULL_TREE && !(spacing && INTEGER_CST_P (spacing)))
+  if (!(array_info && INTEGER_CST_P (array_info)))
{
- /* Calculate spacing = size * (ubound + 1 - lbound).  */
- tmp = gfc_conv_array_extent_dim (lbound, ubound, nullptr);
- tmp = fold_build2_loc (input_location, MULT_EXPR,
-gfc_array_index_type, size, tmp);
- if (spacing)
-   gfc_add_modify (pblock, spacing, tmp);
+ if (dim + 1 < as->rank)
+   {
+ tmp = fold_build2_loc (input_location, MULT_EXPR,
+gfc_array_index_type, spacing, tmp);
+ spacing = array_info;
+   }
  else
-   spacing = gfc_evaluate_now (tmp, pblock);
+   {
+ tmp = size;
+ spacing = NULL_TREE;
+   }
 
- /* Make sure that negative size arrays are translated
-to being zero size.  */
- tmp = fold_build2_loc (input_location, GE_EXPR, logical_type_node,
-spacing, gfc_index_zero_node);
- tmp = fold_build3_loc (input_location, COND_EXPR,
-gfc_array_index_type, tmp,
-spacing, gfc_index_zero_node);
- gfc_add_modify (pblock, spacing, tmp);
+ gcc_assert (array_info);
+ gfc_add_modify (pblock, array_info, tmp);
}
-
-  size = spacing;
 }
 
   gfc_trans_array_cobounds (type, pblock, sym);
@@ -6441,6 +6441,11 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * 
sym,
 
   if (sym->attr.omp_allocate)
 {
+  /* The size is the number of elements in the array, so multiply by the
+size of an element to get the total size.  */
+  tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type));
+  size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
+ size, fold_convert (gfc_array_index_type, tmp));
   size = gfc_evaluate_now (size, &init);
 
   tree omp_alloc = lookup_attribute ("omp allocate",
@@ -6459,6 +6464,11 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * 
sym,
 }
   else
 {
+  /* The size is the number of elements in the array, so multiply by the
+size of an element to get the total size.  */
+  tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type));
+  size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
+ size, fold_convert (gfc_array_index_type, tmp));
   /* Allocate memory to hold the data.  */
   tmp = gfc_call_malloc (&init, TREE_TYPE (decl), size);
   gfc_add_modify (&init, decl, tmp);


[gcc r16-652] c++: -fimplicit-constexpr and modules

2025-05-15 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:9694bb129c0dbf54138d94caa28d692842fdc233

commit r16-652-g9694bb129c0dbf54138d94caa28d692842fdc233
Author: Jason Merrill 
Date:   Fri May 9 19:13:49 2025 -0400

c++: -fimplicit-constexpr and modules

Import didn't like differences in DECL_DECLARED_CONSTEXPR_P due to implicit
constexpr, breaking several g++.dg/modules tests; we should handle that
along with DECL_MAYBE_DELETED.  For which we need to stream the bit.

gcc/cp/ChangeLog:

* module.cc (trees_out::lang_decl_bools): Stream implicit_constexpr.
(trees_in::lang_decl_bools): Likewise.
(trees_in::is_matching_decl): Check it.

Diff:
---
 gcc/cp/module.cc | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index e7782627a492..4f9c3788380a 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -6024,7 +6024,7 @@ trees_out::lang_decl_bools (tree t, bits_out& bits)
   WB (lang->u.fn.has_dependent_explicit_spec_p);
   WB (lang->u.fn.immediate_fn_p);
   WB (lang->u.fn.maybe_deleted);
-  /* We do not stream lang->u.fn.implicit_constexpr.  */
+  WB (lang->u.fn.implicit_constexpr);
   WB (lang->u.fn.escalated_p);
   WB (lang->u.fn.xobj_func);
   goto lds_min;
@@ -6095,7 +6095,7 @@ trees_in::lang_decl_bools (tree t, bits_in& bits)
   RB (lang->u.fn.has_dependent_explicit_spec_p);
   RB (lang->u.fn.immediate_fn_p);
   RB (lang->u.fn.maybe_deleted);
-  /* We do not stream lang->u.fn.implicit_constexpr.  */
+  RB (lang->u.fn.implicit_constexpr);
   RB (lang->u.fn.escalated_p);
   RB (lang->u.fn.xobj_func);
   goto lds_min;
@@ -12193,13 +12193,23 @@ trees_in::is_matching_decl (tree existing, tree decl, 
bool is_typedef)
 
   /* Similarly if EXISTING has undeduced constexpr, but DECL's
 is already deduced.  */
-  if (DECL_MAYBE_DELETED (e_inner) && !DECL_MAYBE_DELETED (d_inner)
- && DECL_DECLARED_CONSTEXPR_P (d_inner))
-   DECL_DECLARED_CONSTEXPR_P (e_inner) = true;
-  else if (!DECL_MAYBE_DELETED (e_inner) && DECL_MAYBE_DELETED (d_inner))
-   /* Nothing to do.  */;
+  if (DECL_DECLARED_CONSTEXPR_P (e_inner)
+ == DECL_DECLARED_CONSTEXPR_P (d_inner))
+   /* Already matches.  */;
+  else if (DECL_DECLARED_CONSTEXPR_P (d_inner)
+  && (DECL_MAYBE_DELETED (e_inner)
+  || decl_implicit_constexpr_p (d_inner)))
+   /* DECL was deduced, copy to EXISTING.  */
+   {
+ DECL_DECLARED_CONSTEXPR_P (e_inner) = true;
+ if (decl_implicit_constexpr_p (d_inner))
+   DECL_LANG_SPECIFIC (e_inner)->u.fn.implicit_constexpr = true;
+   }
   else if (DECL_DECLARED_CONSTEXPR_P (e_inner)
-  != DECL_DECLARED_CONSTEXPR_P (d_inner))
+  && (DECL_MAYBE_DELETED (d_inner)
+  || decl_implicit_constexpr_p (e_inner)))
+   /* EXISTING was deduced, leave it alone.  */;
+  else
{
  mismatch_msg = G_("conflicting % for imported "
"declaration %#qD");


[gcc r16-653] c++: use normal std list for module tests

2025-05-15 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:9a2083f025fae3559474b961943484d764c2e6dd

commit r16-653-g9a2083f025fae3559474b961943484d764c2e6dd
Author: Jason Merrill 
Date:   Mon Nov 18 19:48:41 2024 +0100

c++: use normal std list for module tests

The modules tests have used their own version of the code to run tests under
multiple standard versions; they should use the same one as other tests.

I'm not sure about continuing to run modules tests in C++17 mode, but I
guess we might as well for now.

gcc/testsuite/ChangeLog:

* lib/g++-dg.exp (g++-std-flags): Factor out of g++-dg-runtest.
* g++.dg/modules/modules.exp: Use it instead of a copy.

Diff:
---
 gcc/testsuite/g++.dg/modules/modules.exp |  39 ++
 gcc/testsuite/lib/g++-dg.exp | 129 +--
 2 files changed, 78 insertions(+), 90 deletions(-)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp
index 81d0bebdfe5a..73b5de1397fa 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -36,7 +36,6 @@ if ![info exists DEFAULT_CXXFLAGS] then {
 set DEFAULT_CXXFLAGS " -pedantic-errors -Wno-long-long"
 }
 set DEFAULT_MODFLAGS $DEFAULT_CXXFLAGS
-set MOD_STD_LIST { 17 2a 2b }
 
 dg-init
 
@@ -261,44 +260,16 @@ proc srcdir {} {
 return $testdir
 }
 
-# Return set of std options to iterate over, taken from g++-dg.exp & compat.exp
+# Return set of std options to iterate over.
 proc module-init { src } {
-set tmp [dg-get-options $src]
-set option_list {}
-set have_std 0
-set std_prefix "-std=c++"
+set option_list [g++-std-flags $src]
 global extra_tool_flags
 set extra_tool_flags {}
-global MOD_STD_LIST
 
-foreach op $tmp {
-   switch [lindex $op 0] {
-   "dg-options" {
-   set std_prefix "-std=gnu++"
-   if { [string match "*-std=*" [lindex $op 2]] } {
-   set have_std 1
-   }
-   eval lappend extra_tool_flags [lindex $op 2]
-   }
-   "dg-additional-options" {
-   if { [string match "*-std=*" [lindex $op 2]] } {
-   set have_std 1
-   }
-   eval lappend extra_tool_flags [lindex $op 2]
-   }
-   }
-}
-
-if { $have_std } {
-   lappend option_list ""
-} elseif { [string match "*xtreme*" $src] } {
+if { [llength $option_list]
+&& [string match "*xtreme*" $src] } {
# Only run the xtreme tests once.
-   set x [lindex $MOD_STD_LIST end]
-   lappend option_list "${std_prefix}$x"
-} else {
-   foreach x $MOD_STD_LIST {
-   lappend option_list "${std_prefix}$x"
-   }
+   set option_list [lrange [lsort $option_list] end end]
 }
 
 return $option_list
diff --git a/gcc/testsuite/lib/g++-dg.exp b/gcc/testsuite/lib/g++-dg.exp
index 26bda651e01e..eb7a9714bc4d 100644
--- a/gcc/testsuite/lib/g++-dg.exp
+++ b/gcc/testsuite/lib/g++-dg.exp
@@ -27,6 +27,78 @@ proc g++-dg-prune { system text } {
 return [gcc-dg-prune $system $text]
 }
 
+# Return a list of -std flags to use for TEST.
+proc g++-std-flags { test } {
+# If the testcase specifies a standard, use that one.
+# If not, run it under several standards, allowing GNU extensions
+# if there's a dg-options line.
+if ![search_for $test "-std=*++"] {
+   if [search_for $test "dg-options"] {
+   set std_prefix "-std=gnu++"
+   } else {
+   set std_prefix "-std=c++"
+   }
+
+   set low 0
+   # Some directories expect certain minimums.
+   if { [string match "*/modules/*" $test] } { set low 17 }
+
+   # See g++.exp for the initial value of this list.
+   global gpp_std_list
+   if { [llength $gpp_std_list] > 0 } {
+   set std_list {}
+   foreach ver $gpp_std_list {
+   set cmpver $ver
+   if { $ver == 98 } { set cmpver 03 }
+   if { $ver ni $std_list
+&& $cmpver >= $low } {
+   lappend std_list $ver
+   }
+   }
+   } else {
+   # If the test mentions specific C++ versions, test those.
+   set lines [get_matching_lines $test {\{ dg* c++[0-9][0-9]}]
+   set std_list {}
+   foreach line $lines {
+   regexp {c\+\+([0-9][0-9])} $line -> ver
+   lappend std_list $ver
+
+   if { $ver == 98 } {
+   # Leave low alone.
+   } elseif { [regexp {dg-do|dg-require-effective-target} $line] } 
{
+   set low $ver
+   }
+   }
+   #verbose "low: $low" 1
+
+   set std_list [lsort -unique $std_list]
+
+   # If fewer than 3 specific versions are mentioned, add more.
+   # The order of this list is significant: first $cxx_default,
+   # then the oldest and newest, 

[gcc r16-651] c++: one more PR99599 tweak

2025-05-15 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:2ee1fce9fc35de21b28823ccae433c90a0ce270b

commit r16-651-g2ee1fce9fc35de21b28823ccae433c90a0ce270b
Author: Jason Merrill 
Date:   Wed May 14 10:23:32 2025 -0400

c++: one more PR99599 tweak

Patrick pointed out that if the parm/arg types aren't complete yet at this
point, it would affect the type_has_converting_constructor and
TYPE_HAS_CONVERSION tests.  I don't have a testcase, but it makes sense for
safety.

PR c++/99599

gcc/cp/ChangeLog:

* pt.cc (conversion_may_instantiate_p): Make sure
classes are complete.

Diff:
---
 gcc/cp/pt.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 0d64a1cfb128..e0857fc26d07 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -23529,13 +23529,13 @@ conversion_may_instantiate_p (tree to, tree from)
 
   /* Converting to a non-aggregate class type will consider its
  user-declared constructors, which might induce instantiation.  */
-  if (CLASS_TYPE_P (to)
+  if (CLASS_TYPE_P (complete_type (to))
   && type_has_converting_constructor (to))
 return true;
 
   /* Similarly, converting from a class type will consider its conversion
  functions.  */
-  if (CLASS_TYPE_P (from)
+  if (CLASS_TYPE_P (complete_type (from))
   && TYPE_HAS_CONVERSION (from))
 return true;


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Mise à jour dump coarray_lib_this_image_1

2025-05-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:08630b0731375c4d8e84a6254ed50f8106af14e9

commit 08630b0731375c4d8e84a6254ed50f8106af14e9
Author: Mikael Morin 
Date:   Wed May 14 20:56:59 2025 +0200

Mise à jour dump coarray_lib_this_image_1

Diff:
---
 gcc/testsuite/gfortran.dg/coarray_lib_this_image_1.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gfortran.dg/coarray_lib_this_image_1.f90 
b/gcc/testsuite/gfortran.dg/coarray_lib_this_image_1.f90
index 63cca3e32c7a..c81fff8fc166 100644
--- a/gcc/testsuite/gfortran.dg/coarray_lib_this_image_1.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_lib_this_image_1.f90
@@ -16,7 +16,7 @@ contains
   end subroutine bar
 end
 
-! { dg-final { scan-tree-dump-times "bar \\(real\\(kind=4\\)\\\[2\\\] \\* 
restrict x, void \\* restrict caf_token.., integer\\(kind=\[48\]\\) 
caf_offset..\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times {bar \(real\(kind=4\)\[(?:1:)?2\] \* 
restrict x, void \* restrict caf_token.., integer\(kind=[48]\) caf_offset..\)} 
1 "original" } }
 ! { dg-final { scan-tree-dump-times "mylcobound = 5;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "parm...dim\\\[1\\\].lbound = 5;" 1 
"original" } }
 ! { dg-final { scan-tree-dump-times "myucobound =\[^\n\r\]* 
parm...dim\\\[1\\\].lbound \\+ \[^\n\r]*_gfortran_caf_num_images \\(0, -1\\).? 
\\+ -?\[0-9\]+\\);" 1 "original" } }


[gcc r16-654] c++: unifying specializations of non-primary tmpls [PR120161]

2025-05-15 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:0c430503f2849ebb20105695b8ad40d43d797c7b

commit r16-654-g0c430503f2849ebb20105695b8ad40d43d797c7b
Author: Patrick Palka 
Date:   Thu May 15 11:07:53 2025 -0400

c++: unifying specializations of non-primary tmpls [PR120161]

Here unification of P=Wrap::type, A=Wrap::type wrongly
succeeds ever since r14-4112 which made the RECORD_TYPE case of unify
no longer recurse into template arguments for non-primary templates
(since they're a non-deduced context) and so the int/long mismatch that
makes the two types distinct goes unnoticed.

In the case of (comparing specializations of) a non-primary template,
unify should still go on to compare the types directly before returning
success.

PR c++/120161

gcc/cp/ChangeLog:

* pt.cc (unify) : When comparing specializations
of a non-primary template, still perform a type comparison.

gcc/testsuite/ChangeLog:

* g++.dg/template/unify13.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/pt.cc|  6 +++---
 gcc/testsuite/g++.dg/template/unify13.C | 18 ++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index e0857fc26d07..1973d25b61a0 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -25785,10 +25785,10 @@ unify (tree tparms, tree targs, tree parm, tree arg, 
int strict,
  INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (parm)),
  INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (t)),
  UNIFY_ALLOW_NONE, explain_p);
- else
-   return unify_success (explain_p);
+ gcc_checking_assert (t == arg);
}
-  else if (!same_type_ignoring_top_level_qualifiers_p (parm, arg))
+
+  if (!same_type_ignoring_top_level_qualifiers_p (parm, arg))
return unify_type_mismatch (explain_p, parm, arg);
   return unify_success (explain_p);
 
diff --git a/gcc/testsuite/g++.dg/template/unify13.C 
b/gcc/testsuite/g++.dg/template/unify13.C
new file mode 100644
index ..ec7ca9d17a44
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/unify13.C
@@ -0,0 +1,18 @@
+// PR c++/120161
+
+template
+struct mp_list { };
+
+template
+struct Wrap { struct type { }; };
+
+struct A : mp_list::type, void>
+ , mp_list::type, void> { };
+
+template
+void f(mp_list::type, U>*);
+
+int main() {
+  A a;
+  f(&a);
+}


[gcc r16-655] [RISC-V][PR target/120223] Don't use bset/binv for XTHEADBS

2025-05-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:87d0daab1ec9d5c901295e8045cbd67f80b2fa23

commit r16-655-g87d0daab1ec9d5c901295e8045cbd67f80b2fa23
Author: Jeff Law 
Date:   Thu May 15 09:03:13 2025 -0600

[RISC-V][PR target/120223] Don't use bset/binv for XTHEADBS

Thead has the XTHEADBB extension which has a lot of overlap with Zbb.  I 
made
the incorrect assumption that XTHEADBS would largely be like Zbs when
generalizing Shreya's work.

As a result we can't use the operation synthesis code for IOR/XOR because we
don't have binv/bset like capabilities.  I should have double checked on
XTHEADBS, my bad.

Anyway, the fix is trivial.  Don't allow bset/binv based on XTHEADBS.

Already spun in my tester.  Spinning in the pre-commit CI system now.

PR target/120223
gcc/
* config/riscv/riscv.cc (synthesize_ior_xor): XTHEADBS does not have
single bit manipulations.

gcc/testsuite/

* gcc.target/riscv/pr120223.c: New test.

Diff:
---
 gcc/config/riscv/riscv.cc | 4 ++--
 gcc/testsuite/gcc.target/riscv/pr120223.c | 4 
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index d28aee4b4398..d996965d0953 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -14227,7 +14227,7 @@ synthesize_ior_xor (rtx_code code, rtx operands[3])
 {
   /* Trivial cases that don't need synthesis.  */
   if (SMALL_OPERAND (INTVAL (operands[2]))
- || ((TARGET_ZBS || TARGET_XTHEADBS || TARGET_ZBKB)
+ || ((TARGET_ZBS || TARGET_ZBKB)
 && single_bit_mask_operand (operands[2], word_mode)))
 return false;
 
@@ -14264,7 +14264,7 @@ synthesize_ior_xor (rtx_code code, rtx operands[3])
   /* If we're flipping all but a small number of bits we can pre-flip
  the outliers, then flip all the bits, which would restore those
  bits that were pre-flipped. */
-  if ((TARGET_ZBS || TARGET_XTHEADBS || TARGET_ZBKB)
+  if ((TARGET_ZBS || TARGET_ZBKB)
   && budget < 0
   && code == XOR
   && popcount_hwi (~INTVAL (operands[2])) < original_budget)
diff --git a/gcc/testsuite/gcc.target/riscv/pr120223.c 
b/gcc/testsuite/gcc.target/riscv/pr120223.c
new file mode 100644
index ..fae21b6d1ece
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr120223.c
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-mcpu=thead-c906" }  */
+long foo(long x) { return x ^ 0x8000; }
+


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression char_allocation_1

2025-05-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a6453e6a7250ab3be353c7582f733e6f61a16bf6

commit a6453e6a7250ab3be353c7582f733e6f61a16bf6
Author: Mikael Morin 
Date:   Thu May 15 17:25:01 2025 +0200

Correction régression char_allocation_1

Diff:
---
 gcc/fortran/trans-array.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 415d353b1394..0e478e1d3121 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6277,7 +6277,6 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, tree 
* poffset,
   tree eltype = gfc_get_element_type (type);
   tree elem_len = fold_convert_loc (input_location, gfc_array_index_type,
TYPE_SIZE_UNIT (eltype));
-  gcc_assert (INTEGER_CST_P (elem_len));
   size = gfc_index_one_node;
   offset = gfc_index_zero_node;
   tree spacing = GFC_TYPE_ARRAY_SPACING (type, 0);


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression bind_c_char_9

2025-05-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:3a432b11ac97ca20fd49a0bcddb4a82cb4011750

commit 3a432b11ac97ca20fd49a0bcddb4a82cb4011750
Author: Mikael Morin 
Date:   Thu May 15 17:09:34 2025 +0200

Correction régression bind_c_char_9

Diff:
---
 gcc/fortran/trans-array.cc | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 6501adcb66d4..415d353b1394 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6299,6 +6299,18 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, 
tree * poffset,
  gfc_add_block_to_block (pblock, &se.finalblock);
  gfc_add_modify (pblock, lbound, se.expr);
}
+  /* The offset of this dimension.  offset = offset - lbound * sm.  */
+  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
+lbound, spacing);
+  offset = fold_build2_loc (input_location, MINUS_EXPR, 
gfc_array_index_type,
+   offset, tmp);
+  if (as->type == AS_ASSUMED_SIZE
+ && dim == as->rank - 1)
+   {
+ size = NULL_TREE;
+ break;
+   }
+
   ubound = GFC_TYPE_ARRAY_UBOUND (type, dim);
   if (as->upper[dim] && !INTEGER_CST_P (ubound))
{
@@ -6308,11 +6320,6 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, 
tree * poffset,
  gfc_add_block_to_block (pblock, &se.finalblock);
  gfc_add_modify (pblock, ubound, se.expr);
}
-  /* The offset of this dimension.  offset = offset - lbound * sm.  */
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-lbound, spacing);
-  offset = fold_build2_loc (input_location, MINUS_EXPR, 
gfc_array_index_type,
-   offset, tmp);
 
   /* Calculate spacing = size * (ubound + 1 - lbound).  */
   tmp = gfc_conv_array_extent_dim (lbound, ubound, nullptr);


[gcc r16-657] libstdc++: Micro-optimization in std::arg overload for scalars

2025-05-15 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:270d23c5b201c8e000f60e05d17577498f409441

commit r16-657-g270d23c5b201c8e000f60e05d17577498f409441
Author: Jonathan Wakely 
Date:   Mon May 12 12:56:17 2025 +0100

libstdc++: Micro-optimization in std::arg overload for scalars

Use __builtin_signbit directly instead of std::signbit.

libstdc++-v3/ChangeLog:

* include/std/complex (arg(T)): Use __builtin_signbit instead of
std::signbit.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/std/complex | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex
index 67f37d4ec2b7..d9d2d8afda89 100644
--- a/libstdc++-v3/include/std/complex
+++ b/libstdc++-v3/include/std/complex
@@ -2532,8 +2532,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 {
   typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
 #if (_GLIBCXX11_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC)
-  return std::signbit(__x) ? __type(3.1415926535897932384626433832795029L)
-  : __type();
+  return __builtin_signbit(__type(__x))
+  ? __type(3.1415926535897932384626433832795029L) : __type();
 #else
   return std::arg(std::complex<__type>(__x));
 #endif


[gcc r16-656] libstdc++: Deprecate non-standard std::fabs(const complex&) [PR120235]

2025-05-15 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6dbcbd96e90159e87a339b98192b7e6e5534b0d7

commit r16-656-g6dbcbd96e90159e87a339b98192b7e6e5534b0d7
Author: Jonathan Wakely 
Date:   Mon May 12 11:34:01 2025 +0100

libstdc++: Deprecate non-standard std::fabs(const complex&) [PR120235]

There was an overload of fabs for std::complex in TR1 and in some C++0x
drafts, but it was removed from the working draft by LWG 595.

Since we've been providing it for decades we should deprecate it before
removing it.

libstdc++-v3/ChangeLog:

PR libstdc++/120235
* doc/html/*: Regenerate.
* doc/xml/manual/evolution.xml: Document deprecation.
* include/std/complex: Replace references to TR1 subclauses with
corresponding C++11 subclauses.
(fabs): Add deprecated attribute.
* testsuite/26_numerics/complex/fabs_neg.cc: New test.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/doc/html/index.html   |  2 +-
 libstdc++-v3/doc/html/manual/api.html  |  5 -
 libstdc++-v3/doc/html/manual/appendix.html |  2 +-
 libstdc++-v3/doc/html/manual/appendix_porting.html |  2 +-
 libstdc++-v3/doc/html/manual/index.html|  2 +-
 libstdc++-v3/doc/xml/manual/evolution.xml  |  9 -
 libstdc++-v3/include/std/complex   | 22 +++---
 .../testsuite/26_numerics/complex/fabs_neg.cc  | 13 +
 8 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/libstdc++-v3/doc/html/index.html b/libstdc++-v3/doc/html/index.html
index d465fb6c7f57..dd31cff31819 100644
--- a/libstdc++-v3/doc/html/index.html
+++ b/libstdc++-v3/doc/html/index.html
@@ -142,7 +142,7 @@
 Existing tests
 
 C++11 Requirements Test Sequence Descriptions
-ABI Policy and 
GuidelinesThe C++ 
InterfaceVersioningGoalsHistoryPrerequisitesConfiguringChecking 
ActiveAllowed 
ChangesProhibited ChangesImplementationTestingSingle ABI 
TestingMultiple ABI 
TestingOutstanding 
IssuesAPI Evolution and Deprecation 
History3.03.13.23.33.44.04.14.24.34.44.54.64.74.84.955.3677.27.38910111212.31313.3class="constant">14href="manual/api.html#api.rel_151">class="constant">15class="section">Backwards 
 >Compatibilityhref="manual/backwards.html#backwards.first">Firstclass="section">href="manual/backwards.html#backwards.second">Secondclass="section">href="manual/backwards.html#backwards.third">Third class="section">href="manual/backwards.html#backwards.third.headers">Pre-ISO headers 
 >removedhref="manual/backwards.html#backwards.third.hash">Extension headers hash_map, 
 >hash_set moved to ext or backwardsclass="section">No ios::nocreate/ios::noreplace.
+ABI Policy and 
GuidelinesThe C++ 
InterfaceVersioningGoalsHistoryPrerequisitesConfiguringChecking 
ActiveAllowed 
ChangesProhibited ChangesImplementationTestingSingle ABI 
TestingMultiple ABI 
TestingOutstanding 
IssuesAPI Evolution and Deprecation 
History3.03.13.23.33.44.04.14.24.34.44.54.64.74.84.955.3677.27.38910111212.31313.3class="constant">14href="manual/api.html#api.rel_151">class="constant">15href="manual/api.html#api.rel_16">class="constant">16class="section">Backwards 
 >Compatibilityhref="manual/backwards.html#backwards.first">Firstclass="section">href="manual/backwards.html#backwards.second">Secondclass="section">href="manual/backwards.html#backwards.third">Third class="section">href="manual/backwards.html#backwards.third.headers">Pre-ISO headers 
 >removedhref="manual/backwards.html#backwards.third.hash">Extension headers hash_map, 
 >hash_set moved to ext o
 r backwardsNo ios::nocreate/ios::noreplace.
 
 No stream::attach(int fd)
 
diff --git a/libstdc++-v3/doc/html/manual/api.html 
b/libstdc++-v3/doc/html/manual/api.html
index 09afdb3e7033..4441d9cdbae0 100644
--- a/libstdc++-v3/doc/html/manual/api.html
+++ b/libstdc++-v3/doc/html/manual/api.html
@@ -490,7 +490,7 @@ to provide the symbols for the experimental C++ Contracts 
support.
 header were added to the static library libstdc++exp.a.
 14
-Deprecate the non-standard overload that allows std::setfill
+Deprecated the non-standard overload that allows std::setfill
 to be used with std::basic_istream.
 
   The extension allowing std::basic_string to be 
instantiated
@@ -509,4 +509,7 @@ and removed in C++20:
 
 Nested result_type and argument_type removed from
 std::hash specializations for C++20.
+16
+Deprecated the non-standard overload of std::fabs for
+std::complex arguments.
 Prev Up NextABI Policy and Guidelines Home Backwards 
Compatibility
\ No newline at end of file
diff --git a/libstdc++-v3/doc/html/manual/appendix.html 
b/libstdc++-v3/doc/html/manual/appendix.html
index 69a0e0018f37..e71ea5423a0a 100644
--- a/libstdc++-v3/doc/html/manual/appendix.html
+++ b/libstdc++-v3/doc/html/manual/appendix.html
@@ -16,7 +16,7 @@
 Existing tests
 
 C++11 Requirements Test Sequence Descriptions
-ABI Policy and GuidelinesThe C++ 
InterfaceVersioningGoalsHistoryP

[gcc r16-658] libstdc++: Fix std::format_kind primary template for Clang [PR120190]

2025-05-15 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:c65725eccbabf3b9b5965f27fff2d3b9f6c75930

commit r16-658-gc65725eccbabf3b9b5965f27fff2d3b9f6c75930
Author: Jonathan Wakely 
Date:   Thu May 15 11:01:05 2025 +0100

libstdc++: Fix std::format_kind primary template for Clang [PR120190]

Although Clang trunk has been adjusted to handle our std::format_kind
definition (because they need to be able to compile the GCC 15.1.0
release), it's probably better to not rely on something that they might
start diagnosing again in future.

Define the primary template in terms of an immediately invoked function
expression, so that we can put a static_assert(false) in the body.

libstdc++-v3/ChangeLog:

PR libstdc++/120190
* include/std/format (format_kind): Adjust primary template to
not depend on itself.
* testsuite/std/format/ranges/format_kind_neg.cc: Adjust
expected errors. Check more invalid specializations.

Reviewed-by: Tomasz Kamiński 
Reviewed-by: Daniel Krügler 

Diff:
---
 libstdc++-v3/include/std/format   | 19 ++-
 .../testsuite/std/format/ranges/format_kind_neg.cc| 15 ++-
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index bfda5895e0c0..b1823db83bc9 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -5464,13 +5464,22 @@ namespace __format
 debug_string
   };
 
-  /// @cond undocumented
+  /** @brief A constant determining how a range should be formatted.
+   *
+   * The primary template of `std::format_kind` cannot be instantiated.
+   * There is a partial specialization for input ranges and you can
+   * specialize the variable template for your own cv-unqualified types
+   * that satisfy the `ranges::input_range` concept.
+   *
+   * @since C++23
+   */
   template
-constexpr auto format_kind =
-__primary_template_not_defined(
-  format_kind<_Rg> // you can specialize this for non-const input ranges
-);
+constexpr auto format_kind = []{
+  static_assert(false, "cannot use primary template of 
'std::format_kind'");
+  return type_identity<_Rg>{};
+}();
 
+  /// @cond undocumented
   template
 consteval range_format
 __fmt_kind()
diff --git a/libstdc++-v3/testsuite/std/format/ranges/format_kind_neg.cc 
b/libstdc++-v3/testsuite/std/format/ranges/format_kind_neg.cc
index bf8619d3d276..0d761ae11185 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/format_kind_neg.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/format_kind_neg.cc
@@ -5,9 +5,14 @@
 
 #include 
 
-template struct Tester { };
+void test()
+{
+  (void) std::format_kind; // { dg-error "here" }
+  (void) std::format_kind; // { dg-error "here" }
+  (void) std::format_kind; // { dg-error "here" }
+  (void) std::format_kind; // { dg-error "here" }
+  (void) std::format_kind; // { dg-error "here" }
+  (void) std::format_kind; // { dg-error "here" }
+}
 
-Tester> t; // { dg-error "here" }
-
-// { dg-error "use of 'std::format_kind" "" { target *-*-* } 0 }
-// { dg-error "primary_template_not_defined" "" { target *-*-* } 0 }
+// { dg-error "cannot use primary template of 'std::format_kind'" "" { target 
*-*-* } 0 }


[gcc r16-659] libstdc++: Fix class mandate for extents.

2025-05-15 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:0babc6f29f7c29215674b3ee58d5dd17ce7b3849

commit r16-659-g0babc6f29f7c29215674b3ee58d5dd17ce7b3849
Author: Luc Grosheintz 
Date:   Wed May 14 21:13:52 2025 +0200

libstdc++: Fix class mandate for extents.

The standard states that the IndexType must be a signed or unsigned
integer. This mandate was implemented using `std::is_integral_v`. Which
also includes (among others) char and bool, which neither signed nor
unsigned integers.

libstdc++-v3/ChangeLog:

* include/std/mdspan: Implement the mandate for extents as
signed or unsigned integer and not any interal type. Remove
leading underscores from names in static_assert message.
* testsuite/23_containers/mdspan/extents/class_mandates_neg.cc:
Check that extents and extents are invalid.
Adjust dg-prune-output pattern.
* testsuite/23_containers/mdspan/extents/misc.cc: Update
tests to avoid `char` and `bool` as IndexType.

Reviewed-by: Tomasz Kamiński 
Reviewed-by: Jonathan Wakely 

Diff:
---
 libstdc++-v3/include/std/mdspan  |  5 +++--
 .../23_containers/mdspan/extents/class_mandates_neg.cc   | 12 
 libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc  |  8 
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
index aee96dda7cd0..47cfa405e442 100644
--- a/libstdc++-v3/include/std/mdspan
+++ b/libstdc++-v3/include/std/mdspan
@@ -163,10 +163,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class extents
 {
-  static_assert(is_integral_v<_IndexType>, "_IndexType must be integral.");
+  static_assert(__is_standard_integer<_IndexType>::value,
+   "IndexType must be a signed or unsigned integer type");
   static_assert(
  (__mdspan::__valid_static_extent<_Extents, _IndexType> && ...),
- "Extents must either be dynamic or representable as _IndexType");
+ "Extents must either be dynamic or representable as IndexType");
 
 public:
   using index_type = _IndexType;
diff --git 
a/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc 
b/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc
index b654e3920a8a..f9c1c0196669 100644
--- a/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc
@@ -1,8 +1,12 @@
 // { dg-do compile { target c++23 } }
 #include
 
-std::extents e1; // { dg-error "from here" }
-std::extents e2;// { dg-error "from here" }
-// { dg-prune-output "dynamic or representable as _IndexType" }
-// { dg-prune-output "must be integral" }
+#include 
+
+std::extents e1; // { dg-error "from here" }
+std::extents e2; // { dg-error "from here" }
+std::extents e3; // { dg-error "from here" }
+std::extents e4;   // { dg-error "from here" }
+// { dg-prune-output "dynamic or representable as IndexType" }
+// { dg-prune-output "signed or unsigned integer" }
 // { dg-prune-output "invalid use of incomplete type" }
diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc 
b/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc
index 1620475a..e71fdc542305 100644
--- a/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc
@@ -1,6 +1,7 @@
 // { dg-do run { target c++23 } }
 #include 
 
+#include 
 #include 
 
 constexpr size_t dyn = std::dynamic_extent;
@@ -20,7 +21,6 @@ static_assert(std::is_same_v::rank_type, size_t>);
 static_assert(std::is_unsigned_v::size_type>);
 static_assert(std::is_unsigned_v::size_type>);
 
-static_assert(std::is_same_v::index_type, char>);
 static_assert(std::is_same_v::index_type, int>);
 static_assert(std::is_same_v::index_type,
  unsigned int>);
@@ -49,7 +49,7 @@ static_assert(check_rank_return_types());
 
 // Check that the static extents don't take up space.
 static_assert(sizeof(std::extents) == sizeof(int));
-static_assert(sizeof(std::extents) == sizeof(char));
+static_assert(sizeof(std::extents) == sizeof(short));
 
 template
 class Container
@@ -58,7 +58,7 @@ class Container
   [[no_unique_address]] std::extents b0;
 };
 
-static_assert(sizeof(Container>) == sizeof(int));
+static_assert(sizeof(Container>) == sizeof(int));
 static_assert(sizeof(Container>) == sizeof(int));
 
 // operator=
@@ -103,7 +103,7 @@ test_deduction_all()
   test_deduction<0>();
   test_deduction<1>(1);
   test_deduction<2>(1.0, 2.0f);
-  test_deduction<3>(int(1), char(2), size_t(3));
+  test_deduction<3>(int(1), short(2), size_t(3));
   return true;
 }


[gcc/devel/omp/gcc-15] Non-contiguous array support patches [PR76739]

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:509286d4aa77f193f22e9427d3ceb86ad07f5ccf

commit 509286d4aa77f193f22e9427d3ceb86ad07f5ccf
Author: Chung-Lin Tang 
Date:   Sat Apr 12 16:22:37 2025 +

Non-contiguous array support patches [PR76739]

This is based on OG14 commit b143c1c447945ce05903ff1360ead97774dfce4b,
which was based from v4, posted upstream here:
https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543437.html

It also incorporates a number of follow-up bug and bit-rot fixes, OG14
commits
e11726d3467543de45448097dde27ba34bf04bfe
87ea4de1c4a360d5d62357491a41811213f4528c
151fc161d0ed640048444ca18f9325e3d2e03e99
628a000bdbf63252c2ede13ccab8e99a19769866
11263c048d39ab1d6a11067b18674bf8307bbbf5
8c1068bbe3e52529bede5466a43af8d98f38dac2

gcc/c/ChangeLog
PR other/76739
* c-typeck.cc (handle_omp_array_sections_1): Add 'bool 
&non_contiguous'
parameter, adjust recursive call site, add cases for allowing
pointer based multi-dimensional arrays for OpenACC.  Reject
non-DECL base-pointer cases as unsupported.
(handle_omp_array_sections): Adjust handle_omp_array_sections_1 
call,
handle non-contiguous case to create dynamic array map.

gcc/cp/ChangeLog
PR other/76739
* semantics.cc (handle_omp_array_sections_1): Add 'bool 
&non_contiguous'
parameter, adjust recursive call site, add cases for allowing
pointer based multi-dimensional arrays for OpenACC.  Reject
non-DECL base-pointer cases as unsupported.
(handle_omp_array_sections): Adjust handle_omp_array_sections_1 
call,
handle non-contiguous case to create dynamic array map.

gcc/fortran/ChangeLog
PR other/76739
* f95-lang.cc (DEF_FUNCTION_TYPE_VAR_5): New symbol.
* types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR): New type.

gcc/ChangeLog
PR other/76739
* builtin-types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR): New type.
* gimplify.cc (omp_group_base): Handle GOMP_MAP_NONCONTIG_ARRAY_*.
(gimplify_scan_omp_clauses): Handle OMP_TARGET_UPDATE.
(gimplify_adjust_omp_clauses): Skip gimplification of
OMP_CLAUSE_SIZE of non-contiguous array maps (which is a TREE_LIST).
* omp-builtins.def (BUILT_IN_GOACC_DATA_START): Adjust function type
to new BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR.
* omp-expand.cc (expand_omp_target): Add non-contiguous array
descriptor pointers to variadic arguments.
* omp-low.cc (append_field_to_record_type): New function.
(create_noncontig_array_descr_type): Likewise.
(create_noncontig_array_descr_init_code): Likewise.
(scan_sharing_clauses): For non-contiguous array map kinds, check 
for
supported dimension structure, and install non-contiguous array
variable into current omp_context.
(reorder_noncontig_array_clauses): New function.
(scan_omp_target): Call reorder_noncontig_array_clauses to place
non-contiguous array map clauses at beginning of clause sequence.
(lower_omp_target): Add handling for non-contiguous array map kinds,
add all created non-contiguous array descriptors to
gimple_omp_target_data_arg.
* tree-pretty-print.cc (dump_omp_clause): Handle
GOMP_MAP_NONCONTIG_ARRAY_*.

gcc/testsuite/ChangeLog
PR other/76739
* c-c++-common/goacc/data-clause-1.c (foo): Remove expected message.
* c-c++-common/goacc/noncontig_array-1.c: New test.
* g++.dg/goacc/data-clause-1.C (foo): Remove expected message.

include/ChangeLog
PR other/76739
* gomp-constants.h (GOMP_MAP_FLAG_SPECIAL_3): Define.
(enum gomp_map_kind): Add GOMP_MAP_NONCONTIG_ARRAY,
GOMP_MAP_NONCONTIG_ARRAY_TO, GOMP_MAP_NONCONTIG_ARRAY_FROM,
GOMP_MAP_NONCONTIG_ARRAY_TOFROM, GOMP_MAP_NONCONTIG_ARRAY_FORCE_TO,
GOMP_MAP_NONCONTIG_ARRAY_FORCE_FROM,
GOMP_MAP_NONCONTIG_ARRAY_FORCE_TOFROM,
GOMP_MAP_NONCONTIG_ARRAY_ALLOC, 
GOMP_MAP_NONCONTIG_ARRAY_FORCE_ALLOC,
GOMP_MAP_NONCONTIG_ARRAY_FORCE_PRESENT.
(GOMP_MAP_NONCONTIG_ARRAY_P): Define.

libgomp/ChangeLog
PR other/76739
* libgomp.h (gomp_map_vars_openacc): New function declaration.
* libgomp_g.h (GOACC_data_start): Add variadic '...' to declaration.
* oacc-int.h (struct goacc_ncarray_dim): New struct declaration.
(struct goacc_ncarray_descr_type): Likewise.
(struct goacc_ncarray): Likewise.
(struct goacc_ncarray_info): Likewise.
(goacc_noncontig_array_create_ptrblock): New function declaration.
* oacc-p

[gcc/devel/omp/gcc-15] libgomp: Merge 'gomp_map_vars_openacc' into 'goacc_map_vars' [PR76739]

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:130451de0f379ff2097f1f4cbacd5dc2152baf84

commit 130451de0f379ff2097f1f4cbacd5dc2152baf84
Author: Thomas Schwinge 
Date:   Sat Apr 12 17:52:13 2025 +

libgomp: Merge 'gomp_map_vars_openacc' into 'goacc_map_vars' [PR76739]

Upstream has 'goacc_map_vars'; merge the new 'gomp_map_vars_openacc' into 
it.
(Maybe the latter didn't exist yet when the former was originally added?)
No functional change.

Clean-up for og12 commit 15d0f61a7fecdc8fd12857c40879ea3730f6d99f
"Merge non-contiguous array support patches".

libgomp/ChangeLog
PR other/76739
* libgomp.h (goacc_map_vars): Add 'struct goacc_ncarray_info *'
formal parameter.
(gomp_map_vars_openacc): Remove.
* target.c (goacc_map_vars): Adjust.
(gomp_map_vars_openacc): Remove.
* oacc-mem.c (acc_map_data, goacc_enter_datum)
(goacc_enter_data_internal): Adjust.
* oacc-parallel.c (GOACC_parallel_keyed, GOACC_data_start):
Adjust.

Diff:
---
 libgomp/libgomp.h   |  9 -
 libgomp/oacc-mem.c  |  8 
 libgomp/oacc-parallel.c | 10 +-
 libgomp/target.c| 17 +++--
 4 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index 326efcc46726..34a41e86565e 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -1475,15 +1475,14 @@ extern void gomp_attach_pointer (struct 
gomp_device_descr *,
 extern void gomp_detach_pointer (struct gomp_device_descr *,
 struct goacc_asyncqueue *, splay_tree_key,
 uintptr_t, bool, struct gomp_coalesce_buf *);
+struct goacc_ncarray_info;
 extern struct target_mem_desc *goacc_map_vars (struct gomp_device_descr *,
   struct goacc_asyncqueue *,
   size_t, void **, void **,
-  size_t *, void *, bool,
+  size_t *, void *,
+  struct goacc_ncarray_info *,
+  bool,
   enum gomp_map_vars_kind);
-extern struct target_mem_desc *gomp_map_vars_openacc (struct gomp_device_descr 
*,
- struct goacc_asyncqueue *,
- size_t, void **, size_t *,
- unsigned short *, void *);
 extern void goacc_unmap_vars (struct target_mem_desc *, bool,
  struct goacc_asyncqueue *);
 extern void gomp_init_device (struct gomp_device_descr *);
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 718252b44ba7..6062f2061a26 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -403,7 +403,7 @@ acc_map_data (void *h, void *d, size_t s)
 
   struct target_mem_desc *tgt
= goacc_map_vars (acc_dev, NULL, mapnum, &hostaddrs, &devaddrs, &sizes,
- &kinds, true, GOMP_MAP_VARS_ENTER_DATA);
+ &kinds, NULL, true, GOMP_MAP_VARS_ENTER_DATA);
   assert (tgt);
   assert (tgt->list_count == 1);
   splay_tree_key n = tgt->list[0].key;
@@ -568,7 +568,7 @@ goacc_enter_datum (void **hostaddrs, size_t *sizes, void 
*kinds, int async)
 
   struct target_mem_desc *tgt
= goacc_map_vars (acc_dev, aq, mapnum, hostaddrs, NULL, sizes,
- kinds, true, GOMP_MAP_VARS_ENTER_DATA);
+ kinds, NULL, true, GOMP_MAP_VARS_ENTER_DATA);
   assert (tgt);
   assert (tgt->list_count == 1);
   n = tgt->list[0].key;
@@ -1206,7 +1206,7 @@ goacc_enter_data_internal (struct gomp_device_descr 
*acc_dev, size_t mapnum,
  gomp_mutex_unlock (&acc_dev->lock);
  struct target_mem_desc *tgt_ __attribute__((unused))
= goacc_map_vars (acc_dev, aq, groupnum, &hostaddrs[i], NULL,
- &sizes[i], &kinds[i], true,
+ &sizes[i], &kinds[i], NULL, true,
  GOMP_MAP_VARS_ENTER_DATA);
  assert (tgt_ == NULL);
  gomp_mutex_lock (&acc_dev->lock);
@@ -1257,7 +1257,7 @@ goacc_enter_data_internal (struct gomp_device_descr 
*acc_dev, size_t mapnum,
 
  struct target_mem_desc *tgt
= goacc_map_vars (acc_dev, aq, groupnum, &hostaddrs[i], NULL,
- &sizes[i], &kinds[i], true,
+ &sizes[i], &kinds[i], NULL, true,
  GOMP_MAP_VARS_ENTER_DATA);
  assert (tgt);
 
diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index 3ed099f35b91..ca6e40b310cd 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -468,8 +

[gcc/devel/omp/gcc-15] Identify OMP development branch in output of 'gcc --version'

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:089a139c758cfab3ba9a72c5038d981d8e996367

commit 089a139c758cfab3ba9a72c5038d981d8e996367
Author: Sandra Loosemore 
Date:   Sat Apr 12 15:43:34 2025 +

Identify OMP development branch in output of 'gcc --version'

gcc/ChangeLog
* Makefile.in (REVISION_s): Change default message.

Diff:
---
 gcc/Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 55b4cd7dbed3..72e53b968d89 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -965,7 +965,7 @@ ifdef REVISION_c
 REVISION_s  := \
   "\"$(if $(DEVPHASE_c)$(filter-out 0,$(PATCHLEVEL_c)), $(REVISION_c))\""
 else
-REVISION_s  := "\"\""
+REVISION_s  := "\" [OG15]\""
 endif
 
 # Shorthand variables for dependency lists.


[gcc/devel/omp/gcc-15] OpenACC: Pass pre-allocated 'ptrblock' to 'goacc_noncontig_array_create_ptrblock' [PR76739]

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:1f60b10dd70e20a87213dfa74108419743413bce

commit 1f60b10dd70e20a87213dfa74108419743413bce
Author: Thomas Schwinge 
Date:   Sat Apr 12 17:58:05 2025 +

OpenACC: Pass pre-allocated 'ptrblock' to 
'goacc_noncontig_array_create_ptrblock' [PR76739]

... to simplify later changes.  No functional change.

Follow-up for og12 commit 15d0f61a7fecdc8fd12857c40879ea3730f6d99f
"Merge non-contiguous array support patches".

libgomp/ChangeLog

PR other/76739
* target.c (gomp_map_vars_internal): Pass pre-allocated 'ptrblock'
to 'goacc_noncontig_array_create_ptrblock'.
* oacc-parallel.c (goacc_noncontig_array_create_ptrblock): Adjust.
* oacc-int.h (goacc_noncontig_array_create_ptrblock): Adjust.

Diff:
---
 libgomp/oacc-int.h  | 3 ++-
 libgomp/oacc-parallel.c | 5 ++---
 libgomp/target.c| 5 +++--
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/libgomp/oacc-int.h b/libgomp/oacc-int.h
index 1d11240bf06a..a24de9d727bf 100644
--- a/libgomp/oacc-int.h
+++ b/libgomp/oacc-int.h
@@ -213,7 +213,8 @@ struct goacc_ncarray_info
   struct goacc_ncarray ncarray[];
 };
 
-extern void *goacc_noncontig_array_create_ptrblock (struct goacc_ncarray *, 
void *);
+extern void goacc_noncontig_array_create_ptrblock (struct goacc_ncarray *,
+  void *, void *);
 
 
 #ifdef HAVE_ATTRIBUTE_VISIBILITY
diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index 6b60705f6ca8..1d17a79886b4 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -165,13 +165,13 @@ goacc_process_noncontiguous_arrays (size_t mapnum, void 
**hostaddrs,
   return nca_info;
 }
 
-void *
+void
 goacc_noncontig_array_create_ptrblock (struct goacc_ncarray *nca,
+  void *ptrblock,
   void *tgt_ptrblock_addr)
 {
   struct goacc_ncarray_descr_type *descr = nca->descr;
   void **tgt_data_rows = nca->tgt_data_rows;
-  void *ptrblock = gomp_malloc (nca->ptrblock_size);
   void **curr_dim_ptrblock = (void **) ptrblock;
   size_t n = 1;
 
@@ -210,7 +210,6 @@ goacc_noncontig_array_create_ptrblock (struct goacc_ncarray 
*nca,
   curr_dim_ptrblock = next_dim_ptrblock;
 }
   assert (n == nca->data_row_num);
-  return ptrblock;
 }
 
 /* Handle the mapping pair that are presented when a
diff --git a/libgomp/target.c b/libgomp/target.c
index d4d4a4cfe2d8..5837b43163f4 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1995,8 +1995,9 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
 accelerator side ptrblock and copy it in.  */
  if (nca->ptrblock_size)
{
- void *ptrblock = goacc_noncontig_array_create_ptrblock
-   (nca, target_ptrblock);
+ void *ptrblock = gomp_malloc (nca->ptrblock_size);
+ goacc_noncontig_array_create_ptrblock
+   (nca, ptrblock, target_ptrblock);
  gomp_copy_host2dev (devicep, aq, target_ptrblock, ptrblock,
  nca->ptrblock_size, false, cbufp);
  if (aq)


[gcc/devel/omp/gcc-15] Various OpenACC reduction enhancements - FE changes

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:98aafd1bba946e9a5da0b464bf81b928977b2bc6

commit 98aafd1bba946e9a5da0b464bf81b928977b2bc6
Author: Julian Brown 
Date:   Sun Apr 13 23:15:27 2025 +

Various OpenACC reduction enhancements - FE changes

gcc/c/ChangeLog
* c-parser.cc (c_parser_omp_variable_list): New c_omp_region_type
argument.  Use it to specialize handling of OMP_CLAUSE_REDUCTION for
OpenACC.
(c_parser_omp_var_list_parens): Add region-type argument to call.
(c_parser_oacc_data_clause): Likewise.
(c_parser_oacc_data_clause_deviceptr): Likewise.
(c_parser_omp_clause_reduction): Change is_omp boolean parameter to
c_omp_region_type.  Update call to c_parser_omp_variable_list.
(c_parser_omp_clause_map): Update call to
c_parser_omp_variable_list.
(c_parser_omp_clause_from_to): Likewise.
(c_parser_omp_clause_init): Likewise.
(c_parser_oacc_all_clauses): Update calls to
c_parser_omp_clause_reduction.
(c_parser_omp_all_clauses): Likewise.
(c_parser_oacc_cache): Update call to c_parser_omp_variable_list.
* c-typeck.cc (c_finish_omp_clauses): Emit an error on orphan 
OpenACC
gang reductions.  Suppress user-defined reduction error for OpenACC.

gcc/cp/ChangeLog
* parser.cc (cp_parser_omp_var_list_no_open):  New c_omp_region_type
argument.  Use it to specialize handling of OMP_CLAUSE_REDUCTION for
OpenACC.
(cp_parser_omp_var_list): Add c_omp_region_type argument. Update 
call
to cp_parser_omp_var_list_no_open.
(cp_parser_oacc_data_clause): Update call to
cp_parser_omp_var_list_no_open.
(cp_parser_omp_clause_reduction): Change is_omp boolean parameter to
c_omp_region_type.  Update call to cp_parser_omp_var_list_no_open.
(cp_parser_omp_clause_from_to): Update call to
cp_parser_omp_clause_var_list_no_open.
(cp_parser_omp_clause_map): Likewise.
(cp_parser_omp_clause_init): Likewise.
(cp_parser_oacc_all_clauses): Update call to
cp_parser_omp_clause_reduction.
(cp_parser_omp_all_clauses): Likewise.
* semantics.cc (finish_omp_reduction_clause): Add c_omp_region_type
argument.  Suppress user-defined reduction error for OpenACC.
(finish_omp_clauses): Update call to finish_omp_reduction_clause.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_omp_clause_copy_ctor): Permit reductions.

Co-Authored-By: Cesar Philippidis 
Co-Authored-By: Nathan Sidwell 
Co-Authored-By: Kwok Cheung Yeung  

Diff:
---
 gcc/c/c-parser.cc   | 44 +---
 gcc/c/c-typeck.cc   |  7 +--
 gcc/cp/parser.cc| 31 +--
 gcc/cp/semantics.cc | 13 -
 gcc/fortran/trans-openmp.cc |  3 ++-
 5 files changed, 57 insertions(+), 41 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 22ec0f849b74..372a15ca7971 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -16332,7 +16332,7 @@ c_parser_oacc_wait_list (c_parser *parser, location_t 
clause_loc, tree list)
in TREE_PURPOSE and the location in TREE_VALUE (accessible using
EXPR_LOCATION); return the list created.
 
-   The optional ALLOW_DEREF argument is true if list items can use the deref
+   The optional MAP_LVALUE argument is true if list items can use the deref
(->) operator.  */
 
 struct omp_dim
@@ -16348,6 +16348,7 @@ static tree
 c_parser_omp_variable_list (c_parser *parser,
location_t clause_loc,
enum omp_clause_code kind, tree list,
+   enum c_omp_region_type ort = C_ORT_OMP,
bool map_lvalue = false)
 {
   auto_vec dims;
@@ -16620,7 +16621,8 @@ c_parser_omp_variable_list (c_parser *parser,
case OMP_CLAUSE_HAS_DEVICE_ADDR:
  array_section_p = false;
  dims.truncate (0);
- while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
+ while ((ort != C_ORT_ACC || kind != OMP_CLAUSE_REDUCTION)
+&& c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
{
  location_t loc = UNKNOWN_LOCATION;
  tree low_bound = NULL_TREE, length = NULL_TREE;
@@ -16754,12 +16756,14 @@ c_parser_omp_variable_list (c_parser *parser,
 }
 
 /* Similarly, but expect leading and trailing parenthesis.  This is a very
-   common case for OpenACC and OpenMP clauses.  The optional ALLOW_DEREF
+   common case for OpenACC and OpenMP clauses.  The optional MAP_LVALUE
argument is true if list items can use the deref (->) operator.  */
 
 static tree
 c_parser_omp_var_list_parens (c_parser *parser

[gcc/devel/omp/gcc-15] Add OpenACC Fortran support for deviceptr and variable in common blocks

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:92f424738cc6fd394d539308ba395d83adefffc4

commit 92f424738cc6fd394d539308ba395d83adefffc4
Author: Cesar Philippidis 
Date:   Wed Apr 23 03:01:28 2025 +

Add OpenACC Fortran support for deviceptr and variable in common blocks

This is a merge of these OG14 commits:
987bb4c25b4076eb54f043644bdf9988378be90d
9e8395708c0027ad1de871bae870c4b0185a74fd
2adb0ec35cd47b34d47c961f6ae46089e3e02cbc
4d29174a9602e6ea783ba0e9a7b1e38fb6913db5

gcc/fortran/ChangeLog
* openmp.cc (gfc_match_omp_map_clause): Re-write handling of the
deviceptr clause.  Add new common_blocks argument.  Propagate it to
gfc_match_omp_variable_list.
(gfc_match_omp_clauses): Update calls to gfc_match_omp_map_clauses.
(resolve_positive_int_expr): Promote the warning to an error.
(check_array_not_assumed): Remove pointer check.
(resolve_oacc_nested_loops): Error on do concurrent loops.
* trans-openmp.cc (gfc_omp_finish_clause): Don't create pointer data
mappings for deviceptr clauses.
(gfc_trans_omp_clauses): Likewise.

gcc/ChangeLog
* gimplify.cc (enum gimplify_omp_var_data): Add GOVD_DEVICETPR.
(oacc_default_clause): Privatize fortran common blocks.
(omp_notice_variable): Add GOVD_DEVICEPTR attribute when 
appropriate.
Defer the expansion of DECL_VALUE_EXPR for common block decls.
(gimplify_scan_omp_clauses): Add GOVD_DEVICEPTR attribute when
appropriate.
(gimplify_adjust_omp_clauses_1): Set GOMP_MAP_FORCE_DEVICEPTR for
implicit deviceptr mappings.

gcc/testsuite/ChangeLog
* c-c++-common/goacc/deviceptr-4.c: Update.
* gfortran.dg/goacc/loop-2-kernels-tile.f95: Update.
* gfortran.dg/goacc/loop-2-parallel-tile.f95: Update.
* gfortran.dg/goacc/loop-2-serial-tile.f95: Update.
* gfortran.dg/goacc/sie.f95: Update.
* gfortran.dg/goacc/tile-1.f90: Update.
* gfortran.dg/gomp/num-teams-2.f90: Update.
* gfortran.dg/gomp/pr67500.f90: Update.
* gfortran.dg/gomp/pr77516.f90: Update.

libgomp/ChangeLog
* oacc-parallel.c (GOACC_parallel_keyed): Handle Fortran deviceptr
clause.
(GOACC_data_start): Likewise.
* testsuite/libgomp.oacc-fortran/deviceptr-1.f90: New test.

Co-Authored-By: James Norris  
Co-Authored-By: Julian Brown 
Co-Authored-By: Tobias Burnus 
Co-Authored-By: Thomas Schwinge 

Diff:
---
 gcc/fortran/openmp.cc  |   5 +-
 gcc/fortran/trans-openmp.cc|   9 +
 gcc/gimplify.cc|  12 +-
 gcc/testsuite/c-c++-common/goacc/deviceptr-4.c |   2 +-
 .../gfortran.dg/goacc/loop-2-kernels-tile.f95  |   4 +-
 .../gfortran.dg/goacc/loop-2-parallel-tile.f95 |   4 +-
 .../gfortran.dg/goacc/loop-2-serial-tile.f95   |   4 +-
 gcc/testsuite/gfortran.dg/goacc/sie.f95|  36 ++--
 gcc/testsuite/gfortran.dg/goacc/tile-1.f90 |  16 +-
 gcc/testsuite/gfortran.dg/gomp/num-teams-2.f90 |  12 +-
 gcc/testsuite/gfortran.dg/gomp/pr67500.f90 |   8 +-
 gcc/testsuite/gfortran.dg/gomp/pr77516.f90 |   2 +-
 libgomp/oacc-parallel.c|   2 +
 .../testsuite/libgomp.oacc-fortran/deviceptr-1.f90 | 197 +
 14 files changed, 265 insertions(+), 48 deletions(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index df829403c34f..1cf1a81cb4c3 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -8215,9 +8215,8 @@ resolve_positive_int_expr (gfc_expr *expr, const char 
*clause)
   if (expr->expr_type == EXPR_CONSTANT
   && expr->ts.type == BT_INTEGER
   && mpz_sgn (expr->value.integer) <= 0)
-gfc_warning ((flag_openmp || flag_openmp_simd) ? OPT_Wopenmp : 0,
-"INTEGER expression of %s clause at %L must be positive",
-clause, &expr->where);
+gfc_error ("INTEGER expression of %s clause at %L must be positive",
+  clause, &expr->where);
 }
 
 static void
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 0b8150fb9777..22c8f9c9d0a7 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -1605,6 +1605,9 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool 
openacc)
   return;
 }
 
+  if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR)
+return;
+
   tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE;
   tree present = gfc_omp_check_optional_argument (decl, true);
   tree orig_decl = NULL_TREE;
@@ -4184,6 +4187,12 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
  OMP_CLAUSE_SIZE (node2) = size_int (0);
  goto finalize_map_clause;
   

[gcc/devel/omp/gcc-15] git_update_version.py: Support vendor-branch version bumps

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:dbd927be10e2daf0c995f43cd28cf1d1883cac42

commit dbd927be10e2daf0c995f43cd28cf1d1883cac42
Author: Tobias Burnus 
Date:   Thu May 15 00:34:05 2025 +

git_update_version.py: Support vendor-branch version bumps

contrib/ChangeLog:

* gcc-changelog/git_repository.py (parse_git_revisions): Optional
exclude_branch_name argument
* gcc-changelog/git_update_version.py: Add --suffix, 
--exclude-branch
and --last-commit to handle vendor branches.

Diff:
---
 contrib/gcc-changelog/git_repository.py |  7 +++-
 contrib/gcc-changelog/git_update_version.py | 54 +++--
 2 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/contrib/gcc-changelog/git_repository.py 
b/contrib/gcc-changelog/git_repository.py
index 2b2efffe77af..dc658af83b9b 100755
--- a/contrib/gcc-changelog/git_repository.py
+++ b/contrib/gcc-changelog/git_repository.py
@@ -31,7 +31,8 @@ except ImportError:
 from git_commit import GitCommit, GitInfo, decode_path
 
 
-def parse_git_revisions(repo_path, revisions, ref_name=None):
+def parse_git_revisions(repo_path, revisions, ref_name=None,
+exclude_branch_name=None):
 repo = Repo(repo_path)
 
 def commit_to_info(commit):
@@ -67,6 +68,8 @@ def parse_git_revisions(repo_path, revisions, ref_name=None):
 except ValueError:
 return None
 
+exclude_branch = (repo.commit(exclude_branch_name)
+  if exclude_branch_name is not None else None)
 parsed_commits = []
 if '..' in revisions:
 commits = list(repo.iter_commits(revisions))
@@ -74,6 +77,8 @@ def parse_git_revisions(repo_path, revisions, ref_name=None):
 commits = [repo.commit(revisions)]
 
 for commit in commits:
+if exclude_branch is not None and repo.is_ancestor(commit, 
exclude_branch):
+continue
 git_commit = GitCommit(commit_to_info(commit.hexsha),
commit_to_info_hook=commit_to_info,
ref_name=ref_name)
diff --git a/contrib/gcc-changelog/git_update_version.py 
b/contrib/gcc-changelog/git_update_version.py
index 8e36c7458367..ec5951ca2686 100755
--- a/contrib/gcc-changelog/git_update_version.py
+++ b/contrib/gcc-changelog/git_update_version.py
@@ -23,6 +23,8 @@ import datetime
 import logging
 import os
 import re
+import shutil
+import sys
 
 from git import Repo
 
@@ -62,14 +64,14 @@ def read_timestamp(path):
 return f.read()
 
 
-def prepend_to_changelog_files(repo, folder, git_commit, add_to_git):
+def prepend_to_changelog_files(repo, folder, git_commit, add_to_git, suffix):
 if not git_commit.success:
 logging.info(f"While processing {git_commit.info.hexsha}:")
 for error in git_commit.errors:
 logging.info(error)
 raise AssertionError()
 for entry, output in git_commit.to_changelog_entries(use_commit_ts=True):
-full_path = os.path.join(folder, entry, 'ChangeLog')
+full_path = os.path.join(folder, entry, 'ChangeLog' + suffix)
 logging.info('writing to %s' % full_path)
 if os.path.exists(full_path):
 with open(full_path) as f:
@@ -89,7 +91,10 @@ active_refs = ['master',
'releases/gcc-12', 'releases/gcc-13', 'releases/gcc-14']
 
 parser = argparse.ArgumentParser(description='Update DATESTAMP and generate '
- 'ChangeLog entries')
+ 'ChangeLog entries',
+ epilog='For vendor branches, only; e.g: -s 
.suffix '
+ '-x releases/gcc-15 -l '
+ '`git log -1 --pretty=format:%H --grep 
"Vendor Bump"`')
 parser.add_argument('-g', '--git-path', default='.',
 help='Path to git repository')
 parser.add_argument('-p', '--push', action='store_true',
@@ -102,18 +107,31 @@ parser.add_argument('-c', '--current', 
action='store_true',
 help='Modify current branch (--push argument is ignored)')
 parser.add_argument('-i', '--ignore', action='append',
 help='list of commits to ignore')
+# Useful only for vendor branches
+parser.add_argument('-s', '--suffix', default="",
+help='suffix for the ChangeLog and DATESTAMP files')
+parser.add_argument('-l', '--last-commit',
+help='hash of the last DATESTAMP commit')
+parser.add_argument('-x', '--exclude-branch',
+help='commits to be ignored if in this branch')
 args = parser.parse_args()
 
 repo = Repo(args.git_path)
 origin = repo.remotes['origin']
 
 
-def update_current_branch(ref_name=None):
+def update_current_branch(ref_name=None, suffix="", last_commit_ref=None,
+  exclude_branch=None):
 commit = repo.head.commit
 commit_count = 1
+last_commit = (repo.commit(last_commit_ref)
+   

[gcc/devel/omp/gcc-15] Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:8f1fe6c2b2f17d02561435ad301f7fdc3271a90b

commit 8f1fe6c2b2f17d02561435ad301f7fdc3271a90b
Author: Cesar Philippidis 
Date:   Tue Feb 26 15:10:21 2019 -0800

Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

Incorporates these commits from OG14 branch:
a743b0947593f38fd93fa1bc5f8dd3c50ba5c498
6f759e76f00d70bf1d44a25767c73ec2de855452
61d66e2e494655a34cca7289ae584d2644f1a65f

gcc/ChangeLog
* omp-low.cc (maybe_lookup_field_in_outer_ctx): New function.
(convert_to_firstprivate_int): New function.
(convert_from_firstprivate_int): New function.
(lower_omp_target): Enable GOMP_MAP_FIRSTPRIVATE_INT in OpenACC.
Remove unused variable.

libgomp/ChangeLog
* testsuite/libgomp.oacc-c++/firstprivate-int.C: New test.
* testsuite/libgomp.oacc-c-c++-common/firstprivate-int.c: New
test.
* testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c: XFAIL
execution test.
* testsuite/libgomp.oacc-fortran/firstprivate-int.f90: New test.

Co-Authored-By: Julian Brown  
Co-Authored-By: Tobias Burnus 
Co-Authored-By: Kwok Cheung Yeung 

Diff:
---
 gcc/omp-low.cc | 147 +--
 .../testsuite/libgomp.oacc-c++/firstprivate-int.C  |  83 
 .../data-firstprivate-1.c  |   6 +
 .../libgomp.oacc-c-c++-common/firstprivate-int.c   |  67 +++
 .../libgomp.oacc-fortran/firstprivate-int.f90  | 209 +
 5 files changed, 500 insertions(+), 12 deletions(-)

diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 35c6b0705d5c..b6b53a7b3ec4 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -4652,6 +4652,19 @@ maybe_lookup_decl_in_outer_ctx (tree decl, omp_context 
*ctx)
   return t ? t : decl;
 }
 
+/* Returns true if DECL is present inside a field that encloses CTX.  */
+
+static bool
+maybe_lookup_field_in_outer_ctx (tree decl, omp_context *ctx)
+{
+  omp_context *up;
+
+  for (up = ctx->outer; up; up = up->outer)
+if (maybe_lookup_field (decl, up))
+  return true;
+
+  return false;
+}
 
 /* Construct the initialization value for reduction operation OP.  */
 
@@ -12870,6 +12883,74 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, 
omp_context *ctx)
 }
 }
 
+/* Helper function for lower_omp_target.  Converts VAR to something that can
+   be represented by a POINTER_SIZED_INT_NODE.  Any new instructions are
+   appended to GS.  This is used to optimize firstprivate variables, so that
+   small types (less precision than POINTER_SIZE) do not require additional
+   data mappings.  */
+
+static tree
+convert_to_firstprivate_int (tree var, gimple_seq *gs)
+{
+  tree type = TREE_TYPE (var), new_type = NULL_TREE;
+
+  if (omp_privatize_by_reference (var))
+{
+  type = TREE_TYPE (type);
+  tree tmp = create_tmp_var (type);
+  gimplify_assign (tmp, build_simple_mem_ref (var), gs);
+  var = tmp;
+}
+
+  if (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type))
+return fold_convert (pointer_sized_int_node, var);
+
+  gcc_assert (tree_to_uhwi (TYPE_SIZE (type)) <= POINTER_SIZE);
+
+  new_type = lang_hooks.types.type_for_size (tree_to_uhwi (TYPE_SIZE (type)),
+true);
+  tree tmp = create_tmp_var (new_type);
+  var = fold_build1 (VIEW_CONVERT_EXPR, new_type, var);
+  gimplify_assign (tmp, var, gs);
+
+  return fold_convert (pointer_sized_int_node, tmp);
+}
+
+/* Like convert_to_firstprivate_int, but restore the original type.  */
+
+static tree
+convert_from_firstprivate_int (tree var, bool is_ref, gimple_seq *gs)
+{
+  tree type = TREE_TYPE (var);
+  tree new_type = NULL_TREE;
+  tree tmp = NULL_TREE;
+
+  gcc_assert (TREE_CODE (var) == MEM_REF);
+  var = TREE_OPERAND (var, 0);
+
+  if (INTEGRAL_TYPE_P (var) || POINTER_TYPE_P (type))
+return fold_convert (type, var);
+
+  gcc_assert (tree_to_uhwi (TYPE_SIZE (type)) <= POINTER_SIZE);
+
+  new_type = lang_hooks.types.type_for_size (tree_to_uhwi (TYPE_SIZE (type)),
+true);
+
+  tmp = create_tmp_var (new_type);
+  var = fold_convert (new_type, var);
+  gimplify_assign (tmp, var, gs);
+  var = fold_build1 (VIEW_CONVERT_EXPR, type, tmp);
+
+  if (is_ref)
+{
+  tmp = create_tmp_var (build_pointer_type (type));
+  gimplify_assign (tmp, build_fold_addr_expr (var), gs);
+  var = tmp;
+}
+
+  return var;
+}
+
 /* Lower the GIMPLE_OMP_TARGET in the current statement
in GSI_P.  CTX holds context information for the directive.  */
 
@@ -13111,6 +13192,9 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, 
omp_context *ctx)
  {
tree var_type = TREE_TYPE (var);
tree new_var = lookup_decl (var, ctx);
+   tree inner_type
+ = omp_privatize_by_reference (new_var)
+   ? TREE_TYPE (var_type) : var_type;
bool rcv_b

[gcc/devel/omp/gcc-15] Adjustments and additions to testcases

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:9f379125df4a72ba99fa8e5804146a056069fd24

commit 9f379125df4a72ba99fa8e5804146a056069fd24
Author: Cesar Philippidis 
Date:   Tue Feb 26 13:18:36 2019 -0800

Adjustments and additions to testcases

gcc/testsuite/ChangeLog
* g++.dg/goacc/loop-1.c: New test.
* g++.dg/goacc/loop-2.c: New test.
* g++.dg/goacc/loop-3.c: New test.

libgomp/ChangeLog
* testsuite/libgomp.oacc-fortran/data-3.f90: Update parallel
regions to denote variables copyied in via acc enter data as
present.
* testsuite/libgomp.oacc-c-c++-common/subr.h: Reimplement.
* testsuite/libgomp.oacc-c-c++-common/subr.ptx: Regenerated PTX.
* testsuite/libgomp.oacc-c-c++-common/timer.h: Removed.
* testsuite/libgomp.oacc-c-c++-common/lib-69.c: Change async checks.
* testsuite/libgomp.oacc-c-c++-common/lib-70.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-72.c: Rework kernel i/f 
and
change async checks.
* testsuite/libgomp.oacc-c-c++-common/lib-73.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-74.c: Rework kernel i/f 
and
timing checks.
* testsuite/libgomp.oacc-c-c++-common/lib-75.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-76.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-78.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-79.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-81.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-82.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/lib-93.c: New test.

Co-Authored-By: James Norris  
Co-Authored-By: Tom de Vries  
Co-Authored-By: Julian Brown 
Co-Authored-By: Tobias Burnus 

Diff:
---
 gcc/testsuite/g++.dg/goacc/loop-1.c|  23 +++
 gcc/testsuite/g++.dg/goacc/loop-2.c|  70 +++
 gcc/testsuite/g++.dg/goacc/loop-3.c|  43 
 .../testsuite/libgomp.oacc-c-c++-common/lib-69.c   |  55 +
 .../testsuite/libgomp.oacc-c-c++-common/lib-70.c   |  79 +++-
 .../testsuite/libgomp.oacc-c-c++-common/lib-72.c   |  60 +-
 .../testsuite/libgomp.oacc-c-c++-common/lib-73.c   |  64 +-
 .../testsuite/libgomp.oacc-c-c++-common/lib-74.c   |  87 +++-
 .../testsuite/libgomp.oacc-c-c++-common/lib-75.c   |  81 ++--
 .../testsuite/libgomp.oacc-c-c++-common/lib-76.c   |  80 ++--
 .../testsuite/libgomp.oacc-c-c++-common/lib-78.c   |  83 +++-
 .../testsuite/libgomp.oacc-c-c++-common/lib-79.c   |  83 ++--
 .../testsuite/libgomp.oacc-c-c++-common/lib-81.c   | 102 --
 .../testsuite/libgomp.oacc-c-c++-common/lib-82.c   |  43 +---
 .../testsuite/libgomp.oacc-c-c++-common/lib-93.c   |  19 ++
 libgomp/testsuite/libgomp.oacc-c-c++-common/subr.h |  45 +
 .../testsuite/libgomp.oacc-c-c++-common/subr.ptx   | 222 -
 .../testsuite/libgomp.oacc-c-c++-common/timer.h| 103 --
 libgomp/testsuite/libgomp.oacc-fortran/data-3.f90  |  12 +-
 19 files changed, 461 insertions(+), 893 deletions(-)

diff --git a/gcc/testsuite/g++.dg/goacc/loop-1.c 
b/gcc/testsuite/g++.dg/goacc/loop-1.c
new file mode 100644
index ..51b20b0e2da0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/goacc/loop-1.c
@@ -0,0 +1,23 @@
+void
+f (int i, float j, int k)
+{
+#pragma acc parallel num_gangs (i) num_workers (i) vector_length (i)
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc parallel num_gangs (j) /* { dg-error "'num_gangs' expression must 
be integral" } */
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc parallel num_workers (j) /* { dg-error "'num_workers' expression 
must be integral" } */
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc parallel vector_length (j) /* { dg-error "'vector_length' 
expression must be integral" } */
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+}
diff --git a/gcc/testsuite/g++.dg/goacc/loop-2.c 
b/gcc/testsuite/g++.dg/goacc/loop-2.c
new file mode 100644
index ..ddfb4804353a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/goacc/loop-2.c
@@ -0,0 +1,70 @@
+void
+f (int i, int j, int k)
+{
+#pragma acc kernels
+#pragma acc loop gang
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc kernels
+#pragma acc loop gang (num: 10)
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc kernels
+#pragma acc loop gang (static: 10)
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc kernels
+#pragma acc loop gang (static: 5, num: 10)
+  for (i = 0; i < 20; ++i)
+;
+
+
+#pragma acc kernels
+#pragma acc loop gang (static: 5, num: 10, *) /* { dg-error "duplicate operand 
to clause" } */
+  for (i = 0; i < 20; ++i)
+;
+
+#pragma acc kernels
+#pragma acc loop gang (static: 5, num: 10, static: *) /* { dg-error "duplicate 
'num' argument" } */
+  for (i = 0; i < 20; ++i

[gcc/devel/omp/gcc-15] Given OpenACC 'async', defer 'free' of non-contiguous array support data structures [PR76739]

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:27cfb2b1363eeb4716dcdc58a070d36e68ece766

commit 27cfb2b1363eeb4716dcdc58a070d36e68ece766
Author: Thomas Schwinge 
Date:   Sat Apr 12 17:54:45 2025 +

Given OpenACC 'async', defer 'free' of non-contiguous array support data 
structures [PR76739]

Fix-up for og12 commit 15d0f61a7fecdc8fd12857c40879ea3730f6d99f
"Merge non-contiguous array support patches".

libgomp/ChangeLog
PR other/76739
* oacc-parallel.c (GOACC_parallel_keyed): Given OpenACC 'async',
defer 'free' of non-contiguous array support data structures.
* target.c (gomp_map_vars_internal): Likewise.

Diff:
---
 libgomp/oacc-parallel.c | 5 -
 libgomp/target.c| 6 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index ca6e40b310cd..6b60705f6ca8 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -470,7 +470,10 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (void *),
   struct target_mem_desc *tgt
   = goacc_map_vars (acc_dev, aq, mapnum, hostaddrs, NULL, sizes, kinds,
nca_info, true, GOMP_MAP_VARS_TARGET);
-  free (nca_info);
+  if (aq == NULL)
+free (nca_info);
+  else
+acc_dev->openacc.async.queue_callback_func (aq, free, nca_info);
 
   if (profiling_p)
 {
diff --git a/libgomp/target.c b/libgomp/target.c
index 9a16c2af8013..d4d4a4cfe2d8 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1999,7 +1999,11 @@ gomp_map_vars_internal (struct gomp_device_descr 
*devicep,
(nca, target_ptrblock);
  gomp_copy_host2dev (devicep, aq, target_ptrblock, ptrblock,
  nca->ptrblock_size, false, cbufp);
- free (ptrblock);
+ if (aq)
+   /* Free once the transfer has completed.  */
+   devicep->openacc.async.queue_callback_func (aq, free, 
ptrblock);
+ else
+   free (ptrblock);
}
}
}


[gcc/devel/omp/gcc-15] Various OpenACC reduction enhancements - ME and nvptx changes

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:bf57265a41ca35df1d61d922c8797caebd8ed50d

commit bf57265a41ca35df1d61d922c8797caebd8ed50d
Author: Julian Brown 
Date:   Sun Apr 13 23:34:17 2025 +

Various OpenACC reduction enhancements - ME and nvptx changes

gcc/ChangeLog
* config/nvptx/nvptx.cc (nvptx_propagate_unified): New.
(nvptx_split_blocks): Call it for cond_uni insn.
(nvptx_expand_cond_uni): New.
(enum nvptx_builtins): Add NVPTX_BUILTIN_COND_UNI.
(nvptx_init_builtins): Initialize it.
(nvptx_expand_builtin): Handle NVPTX_BUILTIN_COND_UNI.
(nvptx_generate_vector_shuffle): Change integral SHIFT operand to
tree BITS operand.
(nvptx_vector_reduction): New.
(nvptx_adjust_reduction_type): New.
(nvptx_goacc_reduction_setup): Use it to adjust the type of 
ref_to_res.
(nvptx_goacc_reduction_init): Don't update LHS if it doesn't exist.
(nvptx_goacc_reduction_fini): Call nvptx_vector_reduction for 
vector.
Use it to adjust the type of ref_to_res.
(nvptx_goacc_reduction_teardown): Call nvptx_adjust_reduction_type.
* config/nvptx/nvptx.md (cond_uni): New pattern.
* gimplify.cc (gimplify_adjust_omp_clauses): Add DECL_P check
for OMP_CLAUSE_TASK_REDUCTION.
* omp-low.cc (lower_oacc_reductions): Handle
GOMP_MAP_FIRSTPRIVATE_POINTER.
* omp-offload.cc (default_goacc_reduction): Likewise.

Co-Authored-By: Cesar Philippidis 

Diff:
---
 gcc/config/nvptx/nvptx.cc | 231 +-
 gcc/config/nvptx/nvptx.md |   7 ++
 gcc/gimplify.cc   |   8 +-
 gcc/omp-low.cc|  29 +-
 gcc/omp-offload.cc|  11 +++
 5 files changed, 257 insertions(+), 29 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index f8939715dee2..fcd6a676b955 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -3581,6 +3581,52 @@ nvptx_mach_vector_length ()
   return cfun->machine->axis_dim[MACH_VECTOR_LENGTH];
 }
 
+/* UNIFIED is a cond_uni insn.  Find the branch insn it affects, and
+   mark that as unified.  We expect to be in a single block.  */
+
+static void
+nvptx_propagate_unified (rtx_insn *unified)
+{
+  rtx_insn *probe = unified;
+  rtx cond_reg = SET_DEST (PATTERN (unified));
+  rtx pat = NULL_RTX;
+
+  /* Find the comparison.  (We could skip this and simply scan to he
+ blocks' terminating branch, if we didn't care for self
+ checking.)  */
+  for (;;)
+{
+  probe = next_real_insn (probe);
+  if (!probe)
+   break;
+  pat = PATTERN (probe);
+
+  if (GET_CODE (pat) == SET
+ && GET_RTX_CLASS (GET_CODE (SET_SRC (pat))) == RTX_COMPARE
+ && XEXP (SET_SRC (pat), 0) == cond_reg)
+   break;
+  gcc_assert (NONJUMP_INSN_P (probe));
+}
+  gcc_assert (pat);
+  rtx pred_reg = SET_DEST (pat);
+
+  /* Find the branch.  */
+  do
+probe = NEXT_INSN (probe);
+  while (!JUMP_P (probe));
+
+  pat = PATTERN (probe);
+  rtx itec = XEXP (SET_SRC (pat), 0);
+  gcc_assert (XEXP (itec, 0) == pred_reg);
+
+  /* Mark the branch's condition as unified.  */
+  rtx unspec = gen_rtx_UNSPEC (BImode, gen_rtvec (1, pred_reg),
+  UNSPEC_BR_UNIFIED);
+  bool ok = validate_change (probe, &XEXP (itec, 0), unspec, false);
+
+  gcc_assert (ok);
+}
+
 /* Loop structure of the function.  The entire function is described as
a NULL loop.  */
 /* See also 'gcc/omp-oacc-neuter-broadcast.cc:struct parallel_g'.  */
@@ -3684,6 +3730,9 @@ nvptx_split_blocks (bb_insn_map_t *map)
continue;
  switch (recog_memoized (insn))
{
+   case CODE_FOR_cond_uni:
+ nvptx_propagate_unified (insn);
+ /* FALLTHROUGH */
default:
  seen_insn = true;
  continue;
@@ -6319,6 +6368,20 @@ nvptx_expand_cmp_swap (tree exp, rtx target,
   return target;
 }
 
+/* Expander for the compare unified builtin.  */
+
+static rtx
+nvptx_expand_cond_uni (tree exp, rtx target, machine_mode mode, int ignore)
+{
+  if (ignore)
+return target;
+
+  rtx src = expand_expr (CALL_EXPR_ARG (exp, 0), NULL_RTX, mode, 
EXPAND_NORMAL);
+
+  emit_insn (gen_cond_uni (target, src));
+
+  return target;
+}
 
 /* Codes for all the NVPTX builtins.  */
 enum nvptx_builtins
@@ -6336,6 +6399,7 @@ enum nvptx_builtins
   NVPTX_BUILTIN_BAR_RED_POPC,
   NVPTX_BUILTIN_BREV,
   NVPTX_BUILTIN_BREVLL,
+  NVPTX_BUILTIN_COND_UNI,
   NVPTX_BUILTIN_MAX
 };
 
@@ -6456,6 +6520,7 @@ nvptx_init_builtins (void)
   DEF (CMP_SWAPLL, "cmp_swapll", (LLUINT, PTRVOID, LLUINT, LLUINT, NULL_TREE));
   DEF (MEMBAR_GL, "membar_gl", (VOID, VOID, NULL_TREE));
   DEF (MEMBAR_CTA, "membar_cta", (VOID, VOID, NULL_TREE));
+  DEF (COND_UNI, "cond_uni", (integer_type_node, integer_type_node, 
NULL_TREE));
 
   DEF (BAR_RED_AND, "bar_r

[gcc/devel/omp/gcc-15] Various OpenACC reduction enhancements - test cases

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:b40270176bd5abd0efa1eeef8f5120a495c4d0c3

commit b40270176bd5abd0efa1eeef8f5120a495c4d0c3
Author: Julian Brown 
Date:   Sun Apr 13 23:54:16 2025 +

Various OpenACC reduction enhancements - test cases

gcc/testsuite/ChangeLog
* c-c++-common/goacc/reduction-9.c: New.
* g++.dg/goacc/reductions-1.C: New.
* gcc.dg/goacc/loop-processing-1.c: Update.

libgomp/ChangeLog
* testsuite/libgomp.oacc-c-c++-common/par-reduction-3.c: New.
* testsuite/libgomp.oacc-c-c++-common/reduction-cplx-flt-2.c: New.
* testsuite/libgomp.oacc-fortran/reduction-9.f90: New.

Co-Authored-By: Cesar Philippidis  
Co-Authored-By: Nathan Sidwell  

Diff:
---
 gcc/testsuite/c-c++-common/goacc/reduction-9.c | 111 +
 gcc/testsuite/g++.dg/goacc/reductions-1.C  | 548 +
 gcc/testsuite/gcc.dg/goacc/loop-processing-1.c |   2 +-
 .../libgomp.oacc-c-c++-common/par-reduction-3.c|  29 ++
 .../reduction-cplx-flt-2.c |  32 ++
 .../testsuite/libgomp.oacc-fortran/reduction-9.f90 |  54 ++
 6 files changed, 775 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/goacc/reduction-9.c 
b/gcc/testsuite/c-c++-common/goacc/reduction-9.c
new file mode 100644
index ..eba1d028d980
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/reduction-9.c
@@ -0,0 +1,111 @@
+/* Exercise invalid reductions on array and struct members.  */
+
+void
+test_parallel ()
+{
+  struct {
+int a;
+float b[5];
+  } s1, s2[10];
+
+  int i;
+  double z[100];
+
+#pragma acc parallel reduction(+:s1.a) /* { dg-error "expected '\\\)' before 
'\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.a += 1;
+
+#pragma acc parallel reduction(+:s1.b[3]) /* { dg-error "expected '\\\)' 
before '\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.b[3] += 1;
+
+#pragma acc parallel reduction(+:s2[2].a) /* { dg-error "expected '\\\)' 
before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[2].a += 1;
+
+#pragma acc parallel reduction(+:s2[3].b[4]) /* { dg-error "expected '\\\)' 
before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[3].b[4] += 1;
+
+#pragma acc parallel reduction(+:z[5]) /* { dg-error "expected '\\\)' before 
'\\\[' token" } */
+  for (i = 0; i < 10; i++)
+z[5] += 1;
+}
+
+void
+test_combined ()
+{
+  struct {
+int a;
+float b[5];
+  } s1, s2[10];
+
+  int i;
+  double z[100];
+
+#pragma acc parallel loop reduction(+:s1.a) /* { dg-error "expected '\\\)' 
before '\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.a += 1;
+
+#pragma acc parallel loop reduction(+:s1.b[3]) /* { dg-error "expected '\\\)' 
before '\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.b[3] += 1;
+
+#pragma acc parallel loop reduction(+:s2[2].a) /* { dg-error "expected '\\\)' 
before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[2].a += 1;
+
+#pragma acc parallel loop reduction(+:s2[3].b[4]) /* { dg-error "expected 
'\\\)' before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[3].b[4] += 1;
+
+#pragma acc parallel loop reduction(+:z[5]) /* { dg-error "expected '\\\)' 
before '\\\[' token" } */
+  for (i = 0; i < 10; i++)
+z[5] += 1;
+
+}
+
+void
+test_loops ()
+{
+  struct {
+int a;
+float b[5];
+  } s1, s2[10];
+
+  int i;
+  double z[100];
+
+#pragma acc parallel
+  {
+#pragma acc loop reduction(+:s1.a) /* { dg-error "expected '\\\)' before 
'\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.a += 1;
+
+#pragma acc loop reduction(+:s1.b[3]) /* { dg-error "expected '\\\)' before 
'\\\.' token" } */
+  for (i = 0; i < 10; i++)
+s1.b[3] += 1;
+
+#pragma acc loop reduction(+:s2[2].a) /* { dg-error "expected '\\\)' before 
'\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[2].a += 1;
+
+#pragma acc loop reduction(+:s2[3].b[4]) /* { dg-error "expected '\\\)' before 
'\\\[' token" } */
+  for (i = 0; i < 10; i++)
+s2[3].b[4] += 1;
+
+#pragma acc loop reduction(+:z[5]) /* { dg-error "expected '\\\)' before 
'\\\[' token" } */
+  for (i = 0; i < 10; i++)
+z[5] += 1;
+  }
+}
+
+int
+main ()
+{
+  test_parallel ();
+  test_combined ();
+  test_loops ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/goacc/reductions-1.C 
b/gcc/testsuite/g++.dg/goacc/reductions-1.C
new file mode 100644
index ..18f43f458586
--- /dev/null
+++ b/gcc/testsuite/g++.dg/goacc/reductions-1.C
@@ -0,0 +1,548 @@
+// Test for invalid reduction variables.
+
+class C1
+{
+  int b, d[10];
+
+public:
+  int a, c[10];
+
+  C1 () { a = 0; b = 0; }
+  int& get_b () { return b; }
+  int* get_d () { return d; }
+};
+
+template 
+class C2
+{
+  T b, d[10];
+
+public:
+  T a, c[10];
+
+  C2 () { a = 0; b = 0; }
+  T& get_b () { return b; }
+  T* get_d () { return d; }
+};
+
+struct S1
+{
+  int a, b, c[10], d[10];
+
+  S1 () { a = 0; b = 0; }
+  int& get_b () { return b; }
+  int* get_d () { return d; }
+};
+
+template 
+struct S2
+{
+  T a

[gcc/devel/omp/gcc-15] Add changes to profiling interface from OG8 branch

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:63caf6bc2f914518dbfcd242164f5e990982bdf9

commit 63caf6bc2f914518dbfcd242164f5e990982bdf9
Author: Thomas Schwinge 
Date:   Fri Jun 21 10:40:38 2019 -0700

Add changes to profiling interface from OG8 branch

This bundles up the parts of the profiling code from the OG8 branch that 
were
not included in the upstream patch.

libgomp/ChangeLog
* Makefile.am (libgomp_la_SOURCES): Add
oacc-profiling-acc_register_library.c.
* Makefile.in: Regenerate.
* libgomp.texi: Remove paragraph about acc_register_library.
* oacc-init.c (get_property_any): Add profiling code.
* oacc-parallel.c (GOACC_parallel_keyed_internal): Set device_api 
for
profiling.
* oacc-profiling-acc_register_library.c: New file.
* oacc-profiling.c (goacc_profiling_initialize): Call
acc_register_library.  Avoid duplicate registration.
(acc_register_library): Remove.
* config/nvptx/oacc-profiling-acc_register_library.c:
New empty file.
* config/nvptx/oacc-profiling.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-dispatch-1.c: Remove
call to acc_register_library.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-init-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: 
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-parallel-1.c: 
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-valid_bytes-1.c:
Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-version-1.c: 
Likewise.

Co-Authored-By: Maciej W. Rozycki  

Diff:
---
 libgomp/Makefile.am|  2 +-
 libgomp/Makefile.in|  7 ++--
 .../nvptx/oacc-profiling-acc_register_library.c|  0
 libgomp/config/nvptx/oacc-profiling.c  |  0
 libgomp/libgomp.texi   |  8 -
 libgomp/oacc-init.c| 21 +++-
 libgomp/oacc-parallel.c|  2 ++
 libgomp/oacc-profiling-acc_register_library.c  | 39 ++
 libgomp/oacc-profiling.c   | 32 +++---
 .../acc_prof-dispatch-1.c  |  2 --
 .../libgomp.oacc-c-c++-common/acc_prof-init-1.c|  2 --
 .../libgomp.oacc-c-c++-common/acc_prof-kernels-1.c | 19 +++
 .../acc_prof-parallel-1.c  |  2 --
 .../acc_prof-valid_bytes-1.c   |  2 --
 .../libgomp.oacc-c-c++-common/acc_prof-version-1.c |  2 --
 15 files changed, 100 insertions(+), 40 deletions(-)

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index e3202aeb0e05..a2e531b31496 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -70,7 +70,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \
oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c target-indirect.c
+   oacc-target.c target-indirect.c oacc-profiling-acc_register_library.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 2a0a842af52d..b4a65a756e7b 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -219,7 +219,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \
oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
-   oacc-target.lo target-indirect.lo $(am__objects_1)
+   oacc-target.lo oacc-profiling-acc_register_library.lo \
+   target-indirect.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -552,7 +553,8 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c target-indirect.c $(am__append_3)
+   oacc-target.c oacc-profiling-acc_register_library.c \
+   target-indirect.c $(am__append_3)
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -768,6 +770,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-mem.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-parallel.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEP

[gcc/devel/omp/gcc-15] Enable firstprivate OpenACC reductions

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:4566c9843f93d28f50dbe500b1b649a7731d1cd1

commit 4566c9843f93d28f50dbe500b1b649a7731d1cd1
Author: Cesar Philippidis 
Date:   Tue Feb 26 15:59:03 2019 -0800

Enable firstprivate OpenACC reductions

gcc/ChangeLog
* gimplify.cc (omp_add_variable): Enable firstprivate reduction
variables.

gcc/testsuite/ChangeLog
* c-c++-common/goacc/reduction-10.c: New test.

libgomp/ChangeLog
* testsuite/libgomp.oacc-c-c++-common/privatize-reduction-1.c: New
test.
* testsuite/libgomp.oacc-c-c++-common/privatize-reduction-2.c: New
test.

Co-Authored-By: Chung-Lin Tang  

Diff:
---
 gcc/gimplify.cc| 19 +++--
 gcc/testsuite/c-c++-common/goacc/reduction-10.c| 93 ++
 .../privatize-reduction-1.c| 41 ++
 .../privatize-reduction-2.c| 23 ++
 4 files changed, 169 insertions(+), 7 deletions(-)

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 6b45dc5427ec..8afa9932916b 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -8673,20 +8673,27 @@ omp_add_variable (struct gimplify_omp_ctx *ctx, tree 
decl, unsigned int flags)
   else
 splay_tree_insert (ctx->variables, (splay_tree_key)decl, flags);
 
-  /* For reductions clauses in OpenACC loop directives, by default create a
- copy clause on the enclosing parallel construct for carrying back the
- results.  */
+  /* For OpenACC loop directives, when a reduction clause is placed on
+ the outermost acc loop within an acc parallel or kernels
+ construct, it must have an implied copy data mapping. E.g.
+
+   #pragma acc parallel
+{
+  #pragma acc loop reduction (+:sum)
+
+ a copy clause for sum should be added on the enclosing parallel
+ construct for carrying back the results.  */
   if (ctx->region_type == ORT_ACC && (flags & GOVD_REDUCTION))
 {
   struct gimplify_omp_ctx *outer_ctx = ctx->outer_context;
-  while (outer_ctx)
+  if (outer_ctx)
{
  n = splay_tree_lookup (outer_ctx->variables, (splay_tree_key)decl);
  if (n != NULL)
{
  /* Ignore local variables and explicitly declared clauses.  */
  if (n->value & (GOVD_LOCAL | GOVD_EXPLICIT))
-   break;
+   ;
  else if (outer_ctx->region_type == ORT_ACC_KERNELS)
{
  /* According to the OpenACC spec, such a reduction variable
@@ -8706,9 +8713,7 @@ omp_add_variable (struct gimplify_omp_ctx *ctx, tree 
decl, unsigned int flags)
{
  splay_tree_insert (outer_ctx->variables, (splay_tree_key)decl,
 GOVD_MAP | GOVD_SEEN);
- break;
}
- outer_ctx = outer_ctx->outer_context;
}
 }
 }
diff --git a/gcc/testsuite/c-c++-common/goacc/reduction-10.c 
b/gcc/testsuite/c-c++-common/goacc/reduction-10.c
new file mode 100644
index ..579aa561479d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/reduction-10.c
@@ -0,0 +1,93 @@
+/* { dg-additional-options "-fdump-tree-gimple" } */
+
+#define n 1000
+
+int
+main(void)
+{
+  int i, j;
+  int result, array[n];
+
+#pragma acc parallel loop reduction (+:result)
+  for (i = 0; i < n; i++)
+result ++;
+
+#pragma acc parallel
+#pragma acc loop reduction (+:result)
+  for (i = 0; i < n; i++)
+result ++;
+
+#pragma acc parallel
+#pragma acc loop
+  for (i = 0; i < n; i++)
+{
+  result = i;
+
+#pragma acc loop reduction(+:result)
+  for (j = 0; j < n; j++)
+   result ++;
+
+  array[i] = result;
+}
+
+#pragma acc parallel
+#pragma acc loop
+  for (i = 0; i < n; i++)
+{
+  result = i;
+
+#pragma acc loop worker vector reduction(+:result)
+  for (j = 0; j < n; j++)
+   result ++;
+
+  array[i] = result;
+}
+
+#pragma acc parallel
+#pragma acc loop // { dg-warning "insufficient partitioning" }
+  for (i = 0; i < n; i++)
+{
+  result = i;
+
+#pragma acc loop gang reduction(+:result)
+  for (j = 0; j < n; j++)
+   result ++;
+
+  array[i] = result;
+}
+
+#pragma acc parallel copy(result)
+#pragma acc loop // { dg-warning "insufficient partitioning" }
+  for (i = 0; i < n; i++)
+{
+  result = i;
+
+#pragma acc loop gang reduction(+:result)
+  for (j = 0; j < n; j++)
+   result ++;
+
+  array[i] = result;
+}
+  
+#pragma acc kernels
+#pragma acc loop
+  for (i = 0; i < n; i++)
+{
+  result = i;
+
+#pragma acc loop reduction(+:result)
+  for (j = 0; j < n; j++)
+   result ++;
+
+  array[i] = result;
+}
+
+  return 0;
+}
+
+/* Check that default copy maps are generated for loop reductions.  */
+/* { dg-final { scan-tree-dump-times "reduction..:result. map.tofrom:result 
.len: 4.." 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "oacc_parallel

[gcc/devel/omp/gcc-15] Don't mark OpenACC auto loops as independent inside acc parallel regions

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:928a71527927b7ab638b886e11cb02221faa0b97

commit 928a71527927b7ab638b886e11cb02221faa0b97
Author: Cesar Philippidis 
Date:   Tue Feb 26 15:55:23 2019 -0800

Don't mark OpenACC auto loops as independent inside acc parallel regions

gcc/ChangeLog
* omp-low.cc (lower_oacc_head_mark): Don't mark OpenACC auto
loops as independent inside acc parallel regions.

gcc/testsuite/ChangeLog
* c-c++-common/goacc/loop-auto-1.c: Adjust test case to conform to
the new behavior of the auto clause in OpenACC 2.5.
* c-c++-common/goacc/loop-auto-2.c: Likewise.
* gcc.dg/goacc/loop-processing-1.c: Likewise.
* c-c++-common/goacc/loop-auto-3.c: New test.
* gfortran.dg/goacc/loop-auto-1.f90: New test.

libgomp/ChangeLog
* testsuite/libgomp.oacc-c-c++-common/loop-auto-1.c: Adjust test 
case
to conform to the new behavior of the auto clause in OpenACC 2.5.

Diff:
---
 gcc/omp-low.cc |  6 +-
 gcc/testsuite/c-c++-common/goacc/loop-auto-1.c | 50 ++--
 gcc/testsuite/c-c++-common/goacc/loop-auto-2.c |  4 +-
 gcc/testsuite/c-c++-common/goacc/loop-auto-3.c | 78 +++
 gcc/testsuite/gcc.dg/goacc/loop-processing-1.c |  2 +-
 gcc/testsuite/gfortran.dg/goacc/loop-auto-1.f90| 88 ++
 .../libgomp.oacc-c-c++-common/loop-auto-1.c| 20 ++---
 7 files changed, 208 insertions(+), 40 deletions(-)

diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index b6b53a7b3ec4..387517cf0679 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -8584,8 +8584,10 @@ lower_oacc_head_mark (location_t loc, tree ddvar, tree 
clauses,
   else
 gcc_unreachable ();
 
-  /* In a parallel region, loops are implicitly INDEPENDENT.  */
-  if (!tgt || is_oacc_parallel_or_serial (tgt))
+  /* In a parallel region, loops without auto and seq clauses are
+ implicitly INDEPENDENT.  */
+  if ((!tgt || is_oacc_parallel_or_serial (tgt))
+  && !(tag & (OLF_SEQ | OLF_AUTO)))
 tag |= OLF_INDEPENDENT;
 
   /* Loops inside OpenACC 'kernels' decomposed parts' regions are expected to
diff --git a/gcc/testsuite/c-c++-common/goacc/loop-auto-1.c 
b/gcc/testsuite/c-c++-common/goacc/loop-auto-1.c
index 124befc40022..dcad07f11c88 100644
--- a/gcc/testsuite/c-c++-common/goacc/loop-auto-1.c
+++ b/gcc/testsuite/c-c++-common/goacc/loop-auto-1.c
@@ -10,7 +10,7 @@ void Foo ()
 #pragma acc loop seq
for (int jx = 0; jx < 10; jx++) {}
 
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int jx = 0; jx < 10; jx++) {}
   }
 
@@ -20,7 +20,7 @@ void Foo ()
 #pragma acc loop auto
for (int jx = 0; jx < 10; jx++) {}
 
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int jx = 0; jx < 10; jx++)
  {
 #pragma acc loop vector
@@ -51,7 +51,7 @@ void Foo ()
 #pragma acc loop vector
for (int jx = 0; jx < 10; jx++)
  {
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int kx = 0; kx < 10; kx++) {}
  }
 
@@ -64,27 +64,27 @@ void Foo ()
 
   }
 
-#pragma acc loop auto
+#pragma acc loop auto independent
 for (int ix = 0; ix < 10; ix++)
   {
-#pragma acc loop auto
+#pragma acc loop auto independent
for (int jx = 0; jx < 10; jx++)
  {
-#pragma acc loop auto
+#pragma acc loop auto independent
for (int kx = 0; kx < 10; kx++) {}
  }
   }
 
-#pragma acc loop auto
+#pragma acc loop auto independent
 for (int ix = 0; ix < 10; ix++)
   {
-#pragma acc loop auto
+#pragma acc loop auto independent
for (int jx = 0; jx < 10; jx++)
  {
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int kx = 0; kx < 10; kx++)
  {
-#pragma acc loop auto
+#pragma acc loop auto independent
for (int lx = 0; lx < 10; lx++) {}
  }
  }
@@ -101,7 +101,7 @@ void Gang (void)
 #pragma acc loop seq
for (int jx = 0; jx < 10; jx++) {}
 
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int jx = 0; jx < 10; jx++) {}
   }
 
@@ -111,7 +111,7 @@ void Gang (void)
 #pragma acc loop auto
for (int jx = 0; jx < 10; jx++) {}
 
-#pragma acc loop auto /* { dg-warning "insufficient partitioning" } */
+#pragma acc loop auto independent /* { dg-warning "insufficient partitioning" 
} */
for (int jx = 0; jx <

[gcc/devel/omp/gcc-15] Handle references in OpenACC "private" clauses

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:3f1fd7de5e4de061acfeffb07d37b2f9b5c78d16

commit 3f1fd7de5e4de061acfeffb07d37b2f9b5c78d16
Author: Julian Brown 
Date:   Fri Sep 20 13:53:10 2019 -0700

Handle references in OpenACC "private" clauses

Combination of OG14 commits
141a592bf147c91c28de7864fa12259687e827e3
8d7562192cc814c6d0d48b424d7751762871a37b
+ new testsuite fixes to add xfails for tests that already failed on OG14.

gcc/ChangeLog
* gimplify.cc (localize_reductions): Rewrite references for
OMP_CLAUSE_PRIVATE also.  Do not create local variable for
privatized arrays as the size is not directly known by the type.

gcc/testsuite/ChangeLog
* gfortran.dg/goacc/privatization-1-compute-loop.f90: Add xfails.
* gfortran.dg/goacc/privatization-1-compute.f90: Likewise.

libgomp/ChangeLog
* testsuite/libgomp.oacc-c++/privatized-ref-3.C: Add xfails.
* testsuite/libgomp.oacc-fortran/optional-private.f90: Likewise.
* testsuite/libgomp.oacc-fortran/privatized-ref-1.f95: Likewise.

Co-Authored-By: Tobias Burnus 
Co-Authored-By: Sandra Loosemore 

Diff:
---
 gcc/gimplify.cc  | 16 
 .../gfortran.dg/goacc/privatization-1-compute-loop.f90   |  6 ++
 .../gfortran.dg/goacc/privatization-1-compute.f90| 12 ++--
 libgomp/testsuite/libgomp.oacc-c++/privatized-ref-3.C|  8 
 .../testsuite/libgomp.oacc-fortran/optional-private.f90  |  4 ++--
 .../testsuite/libgomp.oacc-fortran/privatized-ref-1.f95  |  8 
 6 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 2a351b000fe1..bd458161ddae 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -16243,6 +16243,22 @@ localize_reductions (tree clauses, tree body)
 
OMP_CLAUSE_REDUCTION_PRIVATE_DECL (c) = new_var;
   }
+else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE)
+  {
+   var = OMP_CLAUSE_DECL (c);
+
+   if (!lang_hooks.decls.omp_privatize_by_reference (var))
+ continue;
+   type = TREE_TYPE (TREE_TYPE (var));
+   if (TREE_CODE (type) == ARRAY_TYPE)
+ continue;
+   new_var = create_tmp_var (type, IDENTIFIER_POINTER (DECL_NAME (var)));
+
+   pr.ref_var = var;
+   pr.local_var = new_var;
+
+   walk_tree (&body, localize_reductions_r, &pr, NULL);
+  }
 }
 
 
diff --git a/gcc/testsuite/gfortran.dg/goacc/privatization-1-compute-loop.f90 
b/gcc/testsuite/gfortran.dg/goacc/privatization-1-compute-loop.f90
index ad5e11abf913..c3fc774c9835 100644
--- a/gcc/testsuite/gfortran.dg/goacc/privatization-1-compute-loop.f90
+++ b/gcc/testsuite/gfortran.dg/goacc/privatization-1-compute-loop.f90
@@ -40,7 +40,8 @@ contains
   ! (See C/C++ example.)
 
   a = g (i, j, a, c)
-  ! { dg-warning {'a' is used uninitialized} TODO { xfail *-*-* } .-1 }
+  ! { dg-warning {'a\.[0-9]+' is used uninitialized} "" { target *-*-* 
} .-1 }
+  ! { dg-note {'a\.[0-9]+' was declared here} "" { target *-*-* } 
l_loop$c_loop }
   x = a
   !$acc atomic write
   y = a
@@ -51,9 +52,6 @@ contains
 ! { dg-note {variable 'j\.[0-9]+' declared in block isn't candidate for 
adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
l_compute$c_compute }
 ! { dg-note {variable 'i\.[0-9]+' in 'private' clause isn't candidate for 
adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
l_loop$c_loop }
 ! { dg-note {variable 'j\.[0-9]+' in 'private' clause isn't candidate for 
adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
l_loop$c_loop }
-! { dg-note {variable 'i' in 'private' clause isn't candidate for 
adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
l_loop$c_loop }
-! { dg-note {variable 'j' in 'private' clause isn't candidate for 
adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
l_loop$c_loop }
-! { dg-note {variable 'a' in 'private' clause isn't candidate for 
adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
l_loop$c_loop }
 ! { dg-note {variable 'x' in 'private' clause isn't candidate for 
adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
l_loop$c_loop }
 ! { dg-note {variable 'y' in 'private' clause is candidate for adjusting 
OpenACC privatization level} "" { target *-*-* } l_loop$c_loop }
 ! { dg-note {variable 'C\.[0-9]+' declared in block potentially has 
improper OpenACC privatization level: 'const_decl'} "TODO" { target *-*-* } 
l_loop$c_loop }
diff --git a/gcc/testsuite/gfortran.dg/goacc/privatization-1-compute.f90 
b/gcc/testsuite/gfortran.dg/goacc/privatization-1-compute.f90
index 68d084dd492b..d4d548afee2f 100644
--- a/gcc/testsuite/gfortran.dg/goacc/privatization-1-compute.f90
+++ b/gcc/testsu

[gcc/devel/omp/gcc-15] Fortran "declare create"/allocate support for OpenACC

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:e361f9db605ec2601de633e302b4a77ff8764948

commit e361f9db605ec2601de633e302b4a77ff8764948
Author: Cesar Philippidis 
Date:   Thu Apr 17 14:10:11 2025 +

Fortran "declare create"/allocate support for OpenACC

This patch incorporates these commits from OG14 branch:
65be1389eeda9b3b97f6587721215c3f31bd7f98
9d43e819d88f97c7ade7f8c95c35ea3464ea7771
f2cf2b994c4d8c871fad5502ffb9aaee9ea4f4e0
2770ce41615557e595065ce0c5db71e9f3d82b0a
a29e58f4b314862a72730119f85e9125879abf0b
ffd990543f805ed448aaa355d190f37103f8f1f0

gcc/ChangeLog
* gimplify.cc (omp_group_base): Handle GOMP_MAP_DECLARE_ALLOCATE
and GOMP_MAP_DECLARE_DEALLOCATE.
(gimplify_adjust_omp_clauses): Likewise.
* omp-low.cc (scan_sharing_clauses): Update handling of OpenACC 
declare
create, declare copyin and declare deviceptr to have local 
lifetimes.
(convert_to_firstprivate_int): Handle pointer types.
(convert_from_firstprivate_int): Likewise.  Create local storage for
the values being pointed to.  Add new orig_type argument.  Use
VIEW_CONVERT also for vectors.
(lower_omp_target): Handle GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}.
Add orig_type argument to convert_from_firstprivate_int call.
Allow pointer types with GOMP_MAP_FIRSTPRIVATE_INT.  Don't privatize
firstprivate VLAs.
* tree-pretty-print.cc (dump_omp_clause): Handle
GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}.

gcc/fortran/ChangeLog
* gfortran.h (enum gfc_omp_map_op): Add OMP_MAP_DECLARE_ALLOCATE,
OMP_MAP_DECLARE_DEALLOCATE.
(gfc_omp_clauses): Add update_allocatable.
* trans-array.cc (gfc_array_allocate): Call
gfc_trans_oacc_declare_allocate for decls that have 
oacc_declare_create
attribute set.
* trans-decl.cc (find_module_oacc_declare_clauses): Relax
oacc_declare_create to OMP_MAP_ALLOC, and oacc_declare_copyin to
OMP_MAP_TO, in order to match OpenACC 2.5 semantics.
* trans-openmp.cc (gfc_omp_check_optional_argument): Handle non-decl
case.
(gfc_trans_omp_clauses): Use GOMP_MAP_ALWAYS_POINTER (for update
directive) or GOMP_MAP_FIRSTPRIVATE_POINTER (otherwise) for
allocatable scalar decls.  Handle 
OMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}
clauses.
(gfc_trans_oacc_executable_directive): Use GOMP_MAP_ALWAYS_POINTER
for allocatable scalar data clauses inside acc update directives.
(gfc_trans_oacc_declare_allocate): New function.
* trans-stmt.cc (gfc_trans_allocate): Call
gfc_trans_oacc_declare_allocate for decls with oacc_declare_create
attribute set.
(gfc_trans_deallocate): Likewise.
* trans.h (gfc_trans_oacc_declare_allocate): Declare.

gcc/testsuite/ChangeLog
* gfortran.dg/goacc/declare-allocatable-1.f90: New test.
* gfortran.dg/goacc/declare-3.f95: Adjust expected dump output.

include/ChangeLog
* gomp-constants.h (enum gomp_map_kind): Define
GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE} and GOMP_MAP_FLAG_SPECIAL_4.

libgomp/ChangeLog
* libgomp.h (gomp_acc_declare_allocate): Remove prototype.
* oacc-mem.c (gomp_acc_declare_allocate): New function.
(find_group_last): Handle GOMP_MAP_DECLARE_ALLOCATE and
GOMP_MAP_DECLARE_DEALLOCATE groupings.
(goacc_enter_data_internal): Fix kind check for
GOMP_MAP_DECLARE_ALLOCATE. Pass new pointer argument to
gomp_acc_declare_allocate.   Unlock mutex before calling
gomp_acc_declare_allocate and relock it afterwards.
(goacc_exit_data_internal): Unlock device mutex around
gomp_acc_declare_allocate call. Pass new pointer argument. Handle
group pointer mapping for deallocate.
* testsuite/libgomp.oacc-fortran/allocatable-scalar.f90: New test.
* 
testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90:
Adjust.
* testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90:
Likewise.
* testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90:
Likewise.
* testsuite/libgomp.oacc-fortran/declare-allocatable-2.f90: New 
test.
* testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90: New 
test.
* testsuite/libgomp.oacc-fortran/declare-allocatable-4.f90: New 
test.
* 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90:
Adjust.
* 
testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-runtime.f90:
Likewise.
* 
testsuite/libgomp.oacc

[gcc/devel/omp/gcc-15] libgomp, nvptx: Cuda pinned memory

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:86086c93cddee91aa5a5deda1f1a0ade0d868d66

commit 86086c93cddee91aa5a5deda1f1a0ade0d868d66
Author: Andrew Stubbs 
Date:   Fri Apr 18 21:48:33 2025 +

libgomp, nvptx: Cuda pinned memory

https://patchwork.sourceware.org/project/gcc/list/?series=35022

This patch was already approved, in the v3 posting by Tobias Burnus
(with one caveat about initialization location), but wasn't committed at
that time as I didn't want to disentangle it from the textual
dependencies on the other patches in the series.

--

Use Cuda to pin memory, instead of Linux mlock, when available.

There are two advantages: firstly, this gives a significant speed boost for
NVPTX offloading, and secondly, it side-steps the usual OS ulimit/rlimit
setting.

The design adds a device independent plugin API for allocating pinned 
memory,
and then implements it for NVPTX.  At present, the other supported devices 
do
not have equivalent capabilities (or requirements).

libgomp/ChangeLog:

* config/linux/allocator.c: Include assert.h.
(using_device_for_page_locked): New variable.
(linux_memspace_alloc): Add init0 parameter. Support device pinning.
(linux_memspace_calloc): Set init0 to true.
(linux_memspace_free): Support device pinning.
(linux_memspace_realloc): Support device pinning.
(MEMSPACE_ALLOC): Set init0 to false.
* libgomp-plugin.h
(GOMP_OFFLOAD_page_locked_host_alloc): New prototype.
(GOMP_OFFLOAD_page_locked_host_free): Likewise.
* libgomp.h (gomp_page_locked_host_alloc): Likewise.
(gomp_page_locked_host_free): Likewise.
(struct gomp_device_descr): Add page_locked_host_alloc_func and
page_locked_host_free_func.
* libgomp.texi: Adjust the docs for the pinned trait.
* libgomp_g.h (GOMP_enable_pinned_mode): New prototype.
* plugin/plugin-nvptx.c
(GOMP_OFFLOAD_page_locked_host_alloc): New function.
(GOMP_OFFLOAD_page_locked_host_free): Likewise.
* target.c (device_for_page_locked): New variable.
(get_device_for_page_locked): New function.
(gomp_page_locked_host_alloc): Likewise.
(gomp_page_locked_host_free): Likewise.
(gomp_load_plugin_for_device): Add page_locked_host_alloc and
page_locked_host_free.
* testsuite/libgomp.c/alloc-pinned-1.c: Change expectations for 
NVPTX
devices.
* testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-3.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-4.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-6.c: Likewise.

Co-Authored-By: Thomas Schwinge 

Diff:
---
 libgomp/config/linux/allocator.c | 141 ---
 libgomp/libgomp-plugin.h |   2 +
 libgomp/libgomp.h|   4 +
 libgomp/libgomp.texi |  11 ++-
 libgomp/libgomp_g.h  |   1 +
 libgomp/plugin/plugin-nvptx.c|  42 
 libgomp/target.c | 136 ++
 libgomp/testsuite/libgomp.c/alloc-pinned-1.c |  26 +
 libgomp/testsuite/libgomp.c/alloc-pinned-2.c |  26 +
 libgomp/testsuite/libgomp.c/alloc-pinned-3.c |  45 +++--
 libgomp/testsuite/libgomp.c/alloc-pinned-4.c |  44 -
 libgomp/testsuite/libgomp.c/alloc-pinned-5.c |  26 +
 libgomp/testsuite/libgomp.c/alloc-pinned-6.c |  34 ++-
 13 files changed, 488 insertions(+), 50 deletions(-)

diff --git a/libgomp/config/linux/allocator.c b/libgomp/config/linux/allocator.c
index 0138d3fa517a..06b38cc2c6ea 100644
--- a/libgomp/config/linux/allocator.c
+++ b/libgomp/config/linux/allocator.c
@@ -36,6 +36,11 @@
 
 /* Implement malloc routines that can handle pinned memory on Linux.

+   Given that pinned memory is typically used to help host <-> device memory
+   transfers, we attempt to allocate such memory using a device (really:
+   libgomp plugin), but fall back to mmap plus mlock if no suitable device is
+   available.
+
It's possible to use mlock on any heap memory, but using munlock is
problematic if there are multiple pinned allocations on the same page.
Tracking all that manually would be possible, but adds overhead. This may
@@ -49,6 +54,7 @@
 #define _GNU_SOURCE
 #include 
 #include 
+#include 
 #include "libgomp.h"
 #ifdef HAVE_INTTYPES_H
 # include   /* For PRIu64.  */
@@ -68,50 +74,92 @@ GOMP_enable_pinned_mode ()
 always_pinned_mode = true;
 }
 
+static int using_device_for_page_locked
+  = /* uninitialized */ -1;
+
 static void *
-linux_memspace_alloc (omp_memspace_handle_t memspace, size_t size

[gcc/devel/omp/gcc-15] libgomp: fine-grained pinned memory allocator

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:59ebc6007887151cdb0f7d00108b86a5921ec5a4

commit 59ebc6007887151cdb0f7d00108b86a5921ec5a4
Author: Andrew Stubbs 
Date:   Fri Apr 18 21:56:19 2025 +

libgomp: fine-grained pinned memory allocator

https://patchwork.sourceware.org/project/gcc/list/?series=35022

This patch introduces a new custom memory allocator for use with pinned
memory (in the case where the Cuda allocator isn't available).  In future,
this allocator will also be used for Unified Shared Memory.  Both memories
are incompatible with the system malloc because allocated memory cannot
share a page with memory allocated for other purposes.

This means that small allocations will no longer consume an entire page of
pinned memory.  Unfortunately, it also means that pinned memory pages will
never be unmapped (although they may be reused).

The implementation is not perfect; there are various corner cases 
(especially
related to extending onto new pages) where allocations and reallocations may
be sub-optimal, but it should still be a step forward in support for small
allocations.

I have considered using libmemkind's "fixed" memory but rejected it for 
three
reasons: 1) libmemkind may not always be present at runtime, 2) there's no
currently documented means to extend a "fixed" kind one page at a time
(although the code appears to have an undocumented function that may do the
job, and/or extending libmemkind to support the MAP_LOCKED mmap flag with 
its
regular kinds would be straight-forward), 3) USM benefits from having the
metadata located in different memory and using an external implementation 
makes
it hard to guarantee this.

libgomp/ChangeLog:

* Makefile.am (libgomp_la_SOURCES): Add usmpin-allocator.c.
* Makefile.in: Regenerate.
* config/linux/allocator.c: Include unistd.h.
(pin_ctx): New variable.
(ctxlock): New variable.
(linux_init_pin_ctx): New function.
(linux_memspace_alloc): Use usmpin-allocator for pinned memory.
(linux_memspace_free): Likewise.
(linux_memspace_realloc): Likewise.
* libgomp.h (usmpin_init_context): New prototype.
(usmpin_register_memory): New prototype.
(usmpin_alloc): New prototype.
(usmpin_free): New prototype.
(usmpin_realloc): New prototype.
* testsuite/libgomp.c/alloc-pinned-8.c: New test.
* usmpin-allocator.c: New file.

Diff:
---
 libgomp/Makefile.am  |   3 +-
 libgomp/Makefile.in  |  11 +-
 libgomp/config/linux/allocator.c |  97 +---
 libgomp/libgomp.h|  10 +
 libgomp/testsuite/libgomp.c/alloc-pinned-8.c | 122 ++
 libgomp/usmpin-allocator.c   | 319 +++
 6 files changed, 525 insertions(+), 37 deletions(-)

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index a2e531b31496..a8a833257c77 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -70,7 +70,8 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \
oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c target-indirect.c oacc-profiling-acc_register_library.c
+   oacc-target.c target-indirect.c oacc-profiling-acc_register_library.c \
+   usmpin-allocator.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index b4a65a756e7b..87fbd7748fd1 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -219,8 +219,9 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \
oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
-   oacc-target.lo oacc-profiling-acc_register_library.lo \
-   target-indirect.lo $(am__objects_1)
+   oacc-target.lo target-indirect.lo \
+   oacc-profiling-acc_register_library.lo usmpin-allocator.lo \
+   $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -553,8 +554,9 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c oacc-profiling-acc_register_library.c \
-   target-indirect.c $(am__append_3)
+   oacc-target.c target-indirect.c \
+   oacc-profiling-acc_register_library.c usmpi

[gcc/devel/omp/gcc-15] nvptx: remove erroneous stack deletion

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:adc63e59f99f856ff4cd6b1fdb2331b16f603e41

commit adc63e59f99f856ff4cd6b1fdb2331b16f603e41
Author: Andrew Stubbs 
Date:   Tue Feb 23 21:35:08 2021 +

nvptx: remove erroneous stack deletion

The stacks are not supposed to be deleted every time memory is allocated, 
only
when there is insufficient memory.  The unconditional call here seems to be 
in
error, and is causing a costly reallocation of the stacks before every 
launch.

libgomp/

* plugin/plugin-nvptx.c (GOMP_OFFLOAD_alloc): Remove early call to
nvptx_stacks_free.

Diff:
---
 libgomp/plugin/plugin-nvptx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index a5cf859db197..d5953c39a6b9 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -1799,8 +1799,6 @@ GOMP_OFFLOAD_alloc (int ord, size_t size)
   ptx_dev->free_blocks = NULL;
   pthread_mutex_unlock (&ptx_dev->free_blocks_lock);
 
-  nvptx_stacks_free (ptx_dev, false);
-
   while (blocks)
 {
   tmp = blocks->next;


[gcc/devel/omp/gcc-15] openmp: -foffload-memory=pinned

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:e13ab24bf919a7c4dc30dcfc9fafa9c6349a90a7

commit e13ab24bf919a7c4dc30dcfc9fafa9c6349a90a7
Author: Andrew Stubbs 
Date:   Wed Jun 12 11:42:21 2024 +

openmp: -foffload-memory=pinned

https://patchwork.sourceware.org/project/gcc/list/?series=35022

Implement the -foffload-memory=pinned option such that libgomp is
instructed to enable fully-pinned memory at start-up.  The option is
intended to provide a performance boost to certain offload programs without
modifying the code.

This feature only works on Linux, at present, and simply calls mlockall to
enable always-on memory pinning.  It requires that the ulimit feature is
set high enough to accommodate all the program's memory usage.

In this mode the ompx_gnu_pinned_memory_alloc feature is disabled as it is 
not
needed and may conflict.

gcc/ChangeLog:

* omp-builtins.def (BUILT_IN_GOMP_ENABLE_PINNED_MODE): New.
* omp-low.cc (omp_enable_pinned_mode): New function.
(execute_lower_omp): Call omp_enable_pinned_mode.

libgomp/ChangeLog:

* config/linux/allocator.c (always_pinned_mode): New variable.
(GOMP_enable_pinned_mode): New function.
(linux_memspace_alloc): Disable pinning when always_pinned_mode set.
(linux_memspace_calloc): Likewise.
(linux_memspace_free): Likewise.
(linux_memspace_realloc): Likewise.
* libgomp.map: Add GOMP_enable_pinned_mode.
* testsuite/libgomp.c/alloc-pinned-7.c: New test.
* testsuite/libgomp.c-c++-common/alloc-pinned-1.c: New test.

Diff:
---
 gcc/omp-builtins.def   |  3 +
 gcc/omp-low.cc | 66 ++
 libgomp/config/linux/allocator.c   | 26 +
 libgomp/libgomp.map|  1 +
 .../libgomp.c-c++-common/alloc-pinned-1.c  | 28 +
 libgomp/testsuite/libgomp.c/alloc-pinned-7.c   | 63 +
 6 files changed, 187 insertions(+)

diff --git a/gcc/omp-builtins.def b/gcc/omp-builtins.def
index 4e7f8524ad56..332f4bae2dec 100644
--- a/gcc/omp-builtins.def
+++ b/gcc/omp-builtins.def
@@ -493,3 +493,6 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_WARNING, "GOMP_warning",
  BT_FN_VOID_CONST_PTR_SIZE, ATTR_NOTHROW_LEAF_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ERROR, "GOMP_error",
  BT_FN_VOID_CONST_PTR_SIZE, 
ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ENABLE_PINNED_MODE,
+ "GOMP_enable_pinned_mode",
+ BT_FN_VOID, ATTR_NOTHROW_LIST)
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 604b0fe6243d..cd3302790eac 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -15484,6 +15484,68 @@ lower_omp (gimple_seq *body, omp_context *ctx)
   input_location = saved_location;
 }
 
+/* Emit a constructor function to enable -foffload-memory=pinned
+   at runtime.  Libgomp handles the OS mode setting, but we need to trigger
+   it by calling GOMP_enable_pinned mode before the program proper runs.  */
+
+static void
+omp_enable_pinned_mode ()
+{
+  static bool visited = false;
+  if (visited)
+return;
+  visited = true;
+
+  /* Create a new function like this:
+
+   static void __attribute__((constructor))
+   __set_pinned_mode ()
+   {
+GOMP_enable_pinned_mode ();
+   }
+  */
+
+  tree name = get_identifier ("__set_pinned_mode");
+  tree voidfntype = build_function_type_list (void_type_node, NULL_TREE);
+  tree decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, name, voidfntype);
+
+  TREE_STATIC (decl) = 1;
+  TREE_USED (decl) = 1;
+  DECL_ARTIFICIAL (decl) = 1;
+  DECL_IGNORED_P (decl) = 0;
+  TREE_PUBLIC (decl) = 0;
+  DECL_UNINLINABLE (decl) = 1;
+  DECL_EXTERNAL (decl) = 0;
+  DECL_CONTEXT (decl) = NULL_TREE;
+  DECL_INITIAL (decl) = make_node (BLOCK);
+  BLOCK_SUPERCONTEXT (DECL_INITIAL (decl)) = decl;
+  DECL_STATIC_CONSTRUCTOR (decl) = 1;
+  DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("constructor"),
+ NULL_TREE, NULL_TREE);
+
+  tree t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
+  void_type_node);
+  DECL_ARTIFICIAL (t) = 1;
+  DECL_IGNORED_P (t) = 1;
+  DECL_CONTEXT (t) = decl;
+  DECL_RESULT (decl) = t;
+
+  push_struct_function (decl);
+  init_tree_ssa (cfun);
+
+  tree calldecl = builtin_decl_explicit (BUILT_IN_GOMP_ENABLE_PINNED_MODE);
+  gcall *call = gimple_build_call (calldecl, 0);
+
+  gimple_seq seq = NULL;
+  gimple_seq_add_stmt (&seq, call);
+  gimple_set_body (decl, gimple_build_bind (NULL_TREE, seq, NULL));
+
+  cfun->function_end_locus = UNKNOWN_LOCATION;
+  cfun->curr_properties |= PROP_gimple_any;
+  pop_cfun ();
+  cgraph_node::add_new_function (decl, true);
+}
+
 /* Main entry point.  */
 
 static unsigned int
@@ -15540,6 +15602,10 @@ execute_lower

[gcc/devel/omp/gcc-15] OpenMP 5.0: Allow multiple clauses mapping same variable

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:36d4c7cc19ebe08be4a421411e602630a763650e

commit 36d4c7cc19ebe08be4a421411e602630a763650e
Author: Chung-Lin Tang 
Date:   Mon Feb 1 03:16:47 2021 -0800

OpenMP 5.0: Allow multiple clauses mapping same variable

This is a merge of:
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562081.html

This patch now allows multiple clauses on the same construct to map
the same variable, which was not valid in OpenMP 4.5, but now allowed
in 5.0.

This may possibly reverted/updated when a final patch is approved
for mainline.

gcc/c/ChangeLog
* c-typeck.cc (c_finish_omp_clauses): Adjust to allow duplicate
mapped variables for OpenMP.

gcc/cp/ChangeLog
* semantics.cc (finish_omp_clauses): Adjust to allow duplicate
mapped variables for OpenMP.

gcc/ChangeLog

* omp-low.cc (install_var_field): Add new 'tree key_expr = 
NULL_TREE'
default parameter. Set splay-tree lookup key to key_expr instead of
var if key_expr is non-NULL. Adjust call to install_parm_decl.
Update comments.
(scan_sharing_clauses): Use clause tree expression as splay-tree key
for map/to/from and OpenACC firstprivate cases when installing the
variable field into the send/receive record type.
(maybe_lookup_field_in_outer_ctx): Add code to search through
construct clauses instead of entirely based on splay-tree lookup.
(lower_oacc_reductions): Adjust to find map-clause of reduction
variable, then create receiver-ref.
(lower_omp_target): Adjust to lookup var field using clause 
expression.

gcc/testsuite/ChangeLog

* c-c++-common/gomp/clauses-2.c: Adjust testcase.
* c-c++-common/gomp/map-6.c: Adjust testcase.

Co-Authored-By: Paul-Antoine Arras 

Diff:
---
 gcc/c/c-typeck.cc   |  2 +-
 gcc/cp/semantics.cc |  2 +-
 gcc/omp-low.cc  | 89 +++--
 gcc/testsuite/c-c++-common/gomp/clauses-2.c |  2 +-
 gcc/testsuite/c-c++-common/gomp/map-6.c |  4 +-
 5 files changed, 65 insertions(+), 34 deletions(-)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index ad37baed2231..e390ad7d15f0 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -17147,7 +17147,7 @@ c_finish_omp_clauses (tree clauses, enum 
c_omp_region_type ort)
  }
else if (bitmap_bit_p (&map_head, DECL_UID (t))
 && !bitmap_bit_p (&map_field_head, DECL_UID (t))
-&& ort != C_ORT_OMP
+&& ort != C_ORT_OMP && ort != C_ORT_OMP_TARGET
 && ort != C_ORT_OMP_EXIT_DATA)
  {
if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 4f7c314e0b46..d37825e34102 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -9189,7 +9189,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type 
ort)
  bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
else if (bitmap_bit_p (&map_head, DECL_UID (t))
 && !bitmap_bit_p (&map_field_head, DECL_UID (t))
-&& ort != C_ORT_OMP
+&& ort != C_ORT_OMP && ort != C_ORT_OMP_TARGET
 && ort != C_ORT_OMP_EXIT_DATA)
  {
if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 0d6f947c2910..604b0fe6243d 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -780,24 +780,28 @@ build_sender_ref (tree var, omp_context *ctx)
   return build_sender_ref ((splay_tree_key) var, ctx);
 }
 
-/* Add a new field for VAR inside the structure CTX->SENDER_DECL.  If
-   BASE_POINTERS_RESTRICT, declare the field with restrict.  */
-
 static void
-install_var_field (tree var, bool by_ref, int mask, omp_context *ctx)
+install_var_field (tree var, bool by_ref, int mask, omp_context *ctx,
+  tree key_expr = NULL_TREE)
 {
   tree field, type, sfield = NULL_TREE;
   splay_tree_key key = (splay_tree_key) var;
 
-  if ((mask & 16) != 0)
-{
-  key = (splay_tree_key) &DECL_NAME (var);
-  gcc_checking_assert (key != (splay_tree_key) var);
-}
-  if ((mask & 8) != 0)
+  if (key_expr)
+/* Allow user to explicitly set the expression used as the key.  */
+key = (splay_tree_key) key_expr;
+  else
 {
-  key = (splay_tree_key) &DECL_UID (var);
-  gcc_checking_assert (key != (splay_tree_key) var);
+  if ((mask & 16) != 0)
+   {
+ key = (splay_tree_key) &DECL_NAME (var);
+ gcc_checking_assert (key != (splay_tree_key) var);
+   }
+  if ((mask & 8) != 0)
+   {
+ key = (splay_tree_key) &DECL_UID (var);
+ gcc_checking_assert (key != (splay_tree_key) 

[gcc/devel/omp/gcc-15] vect: WORKAROUND vectorizer bug

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:103758a6d5a021b8d703887bbdc990e2b6986c73

commit 103758a6d5a021b8d703887bbdc990e2b6986c73
Author: Andrew Stubbs 
Date:   Fri Oct 21 14:19:31 2022 +0100

vect: WORKAROUND vectorizer bug

This patch disables vectorization of memory accesses to non-default address
spaces where the pointer size is different to the usual pointer size.  This
condition typically occurs in OpenACC programs on amdgcn, where LDS memory 
is
used for broadcasting gang-private variables between threads. In particular,
see libgomp.oacc-c-c++-common/private-variables.c

The problem is that the address space information is dropped from the 
various
types in the middle-end and eventually it triggers an ICE trying to do an
address conversion.  That ICE can be avoided by defining
POINTERS_EXTEND_UNSIGNED, but that just produces wrong RTL code later on.

A correct solution would ensure that all the vectypes have the correct 
address
spaces, but I don't have time for that right now.

gcc/ChangeLog:

* tree-vect-data-refs.cc (vect_analyze_data_refs): Workaround an
address-space bug.

Diff:
---
 gcc/tree-vect-data-refs.cc | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index 3ba271b9e692..d6cd93a3fe04 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -5035,7 +5035,21 @@ vect_analyze_data_refs (vec_info *vinfo, poly_uint64 
*min_vf, bool *fatal)
   /* Set vectype for STMT.  */
   scalar_type = TREE_TYPE (DR_REF (dr));
   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type);
-  if (!vectype)
+
+  /* FIXME: If the object is in an address-space in which the pointer size
+is different to the default address space then vectorizing here will
+lead to an ICE down the road because the address space information
+gets lost.  This work-around fixes the problem until we have a proper
+solution.  */
+  tree base_object = DR_REF (dr);
+  tree op = (TREE_CODE (base_object) == COMPONENT_REF
+|| TREE_CODE (base_object) == ARRAY_REF
+? TREE_OPERAND (base_object, 0) : base_object);
+  addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (op));
+  bool addr_space_bug = (!ADDR_SPACE_GENERIC_P (as)
+&& targetm.addr_space.pointer_mode (as) != Pmode);
+
+  if (!vectype || addr_space_bug)
 {
   if (dump_enabled_p ())
 {


[gcc/devel/omp/gcc-15] omp-oacc-kernels-decompose.cc: fix -fcompare-debug with GIMPLE_DEBUG

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:6505ad1b940441074b7556048907941a26cea495

commit 6505ad1b940441074b7556048907941a26cea495
Author: Tobias Burnus 
Date:   Fri Oct 21 15:31:25 2022 +0200

omp-oacc-kernels-decompose.cc: fix -fcompare-debug with GIMPLE_DEBUG

GIMPLE_DEBUG were put in a parallel region of its own, which is not
only pointless but also breaks -fcompare-debug. With this commit,
they are handled like simple assignments: those placed are places
into the same body as the loop such that only one parallel region
remains as without debugging. This fixes the existing testcase
libgomp.oacc-c-c++-common/kernels-loop-g.c.

Note: GIMPLE_DEBUG are only accepted with -fcompare-debug; if they
appear otherwise, decompose_kernels_region_body rejects them with
a sorry (unchanged).

Also note that there are still many xfailed tests in the
c-c++-common/goacc/kernels-decompose-pr* testcases that were added
in mainline commit c14ea6a72fb1ae66e3d32ac8329558497c6e4403.

gcc/ChangeLog
* omp-oacc-kernels-decompose.cc (top_level_omp_for_in_stmt,
decompose_kernels_region_body): Handle GIMPLE_DEBUG like
simple assignment.

gcc/testsuite/ChangeLog
* c-c++-common/goacc/kernels-decompose-pr103836-1-2.c: Adjust 
xfails.
* c-c++-common/goacc/kernels-decompose-pr103836-1-3.c: Likewise.
* c-c++-common/goacc/kernels-decompose-pr103836-1-4.c: Likewise.
* c-c++-common/goacc/kernels-decompose-pr104061-1-2.c: Likewise.
* c-c++-common/goacc/kernels-decompose-pr104061-1-3.c: Likewise.
* c-c++-common/goacc/kernels-decompose-pr104061-1-4.c: Likewise.

Co-Authored-By: Sandra Loosemore 

Diff:
---
 gcc/omp-oacc-kernels-decompose.cc  |  5 +++--
 .../goacc/kernels-decompose-pr103836-1-2.c |  2 +-
 .../goacc/kernels-decompose-pr103836-1-3.c |  4 ++--
 .../goacc/kernels-decompose-pr103836-1-4.c |  4 ++--
 .../goacc/kernels-decompose-pr104061-1-2.c | 18 +-
 .../goacc/kernels-decompose-pr104061-1-3.c | 12 ++--
 .../goacc/kernels-decompose-pr104061-1-4.c | 12 ++--
 7 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/gcc/omp-oacc-kernels-decompose.cc 
b/gcc/omp-oacc-kernels-decompose.cc
index fc3a3b352d3a..5d7289ade75d 100644
--- a/gcc/omp-oacc-kernels-decompose.cc
+++ b/gcc/omp-oacc-kernels-decompose.cc
@@ -120,7 +120,8 @@ top_level_omp_for_in_stmt (gimple *stmt)
  for (gsi = gsi_start (body); !gsi_end_p (gsi); gsi_next (&gsi))
{
  gimple *body_stmt = gsi_stmt (gsi);
- if (gimple_code (body_stmt) == GIMPLE_ASSIGN)
+ if (gimple_code (body_stmt) == GIMPLE_ASSIGN
+ || gimple_code (body_stmt) == GIMPLE_DEBUG)
continue;
  else if (gimple_code (body_stmt) == GIMPLE_OMP_FOR
   && gsi_one_before_end_p (gsi))
@@ -1363,7 +1364,7 @@ decompose_kernels_region_body (gimple *kernels_region, 
tree kernels_clauses)
= (gimple_code (stmt) == GIMPLE_ASSIGN
   && TREE_CODE (gimple_assign_lhs (stmt)) == VAR_DECL
   && DECL_ARTIFICIAL (gimple_assign_lhs (stmt)));
- if (!is_simple_assignment)
+ if (!is_simple_assignment && gimple_code (stmt) != GIMPLE_DEBUG)
only_simple_assignments = false;
}
 }
diff --git a/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr103836-1-2.c 
b/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr103836-1-2.c
index 83690b6d1abc..a3afb79b753f 100644
--- a/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr103836-1-2.c
+++ b/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr103836-1-2.c
@@ -16,7 +16,7 @@ f_acc_kernels (void)
 #pragma acc kernels /* { dg-line l_compute1 } */
   /* { dg-note {variable 'i\.0' declared in block isn't candidate for 
adjusting OpenACC privatization level: not addressable} {} { xfail c++ } 
l_compute1 } */
   {
-/* { dg-bogus {note: beginning 'gang-single' part in OpenACC 'kernels' 
region} {w/ debug} { xfail c++ } .-1 } */
+/* { dg-bogus {note: beginning 'gang-single' part in OpenACC 'kernels' 
region} {w/ debug} { target *-*-* } .-1 } */
 
 /* { dg-note {forwarded loop nest in OpenACC 'kernels' region to 
'parloops' for analysis} {} { target *-*-* } .+1 } */
 #pragma acc loop /* { dg-line l_loop_i1 } */
diff --git a/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr103836-1-3.c 
b/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr103836-1-3.c
index 35892a01d642..8cbf69f301c8 100644
--- a/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr103836-1-3.c
+++ b/gcc/testsuite/c-c++-common/goacc/kernels-decompose-pr103836-1-3.c
@@ -1,7 +1,7 @@
 /* { dg-additional-options "--param openacc-kernels=decompose" } */
 
 /* { dg-additional-options "-fcompare-debug" } -- w/o debug compiled first.

[gcc/devel/omp/gcc-15] openacc: Adjust loop lowering for AMD GCN

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:9796420d0100c48ccb8e35283f940781c3119aac

commit 9796420d0100c48ccb8e35283f940781c3119aac
Author: Julian Brown 
Date:   Fri Apr 18 21:00:09 2025 +

openacc: Adjust loop lowering for AMD GCN

This patch adjusts OpenACC loop lowering in the AMD GCN target compiler
in such a way that the autovectorizer can vectorize the "vector" dimension
of those loops in more cases.

Rather than generating "SIMT" code that executes a scalar instruction
stream for each lane of a vector in lockstep, for GCN we model the GPU
like a typical CPU, with separate instructions to operate on scalar and
vector data. That means that unlike other offload targets, we rely on
the autovectorizer to handle the innermost OpenACC parallelism level,
which is "vector".

Because of this, the OpenACC builtin functions to return the current
vector lane and the vector width return 0 and 1 respectively, despite
the native vector width being 64 elements wide.

This allows generated code to work with our chosen compilation model,
but the way loops are lowered in omp-offload.c:oacc_xform_loop does not
understand the discrepancy between logical (OpenACC) and physical vector
sizes correctly. That means that if a loop is partitioned over e.g. the
worker AND vector dimensions, we actually lower with unit vector size --
meaning that if we then autovectorize, we end up trying to vectorize
over the "worker" dimension rather than the vector one! Then, because
the number of workers is not fixed at compile time, that means the
autovectorizer has a hard time analysing the loop and thus vectorization
often fails entirely.

We can fix this by deducing the true vector width in oacc_xform_loop,
and using that when we are on a "non-SIMT" offload target. We can then
rearrange how loops are lowered in that function so that the loop form
fed to the autovectorizer is more amenable to vectorization -- namely,
the innermost step is set to process each loop iteration sequentially.

For some benchmarks, allowing vectorization to succeed leads to quite
impressive performance improvements -- I've observed between 2.5x and
40x on one machine/GPU combination.

The low-level builtins available to user code (__builtin_goacc_parlevel_id
and __builtin_goacc_parlevel_size) continue to return 0/1 respectively
for the vector dimension for AMD GCN, even if their containing loop is
vectorized -- that's a quirk that we might possibly want to address at
some later date.

Only non-"chunking" loops are handled at present. "Chunking" loops are
still lowered as before.

gcc/ChangeLog
* omp-offload.cc (oacc_thread_numbers): Add VF_BY_VECTORIZER 
parameter.
Add overloaded wrapper for previous arguments & behaviour.
(oacc_xform_loop): Lower vector loops to iterate a multiple of
omp_max_vf times over contiguous steps on non-SIMT targets.

libgomp/ChangeLog
* testsuite/libgomp.oacc-c-c++-common/loop-gwv-1.c: Adjust for loop
lowering changes.
* testsuite/libgomp.oacc-c-c++-common/loop-wv-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/loop-red-gwv-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/loop-red-wv-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/routine-gwv-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/routine-wv-1.c: Likewise.

Diff:
---
 gcc/omp-offload.cc | 159 -
 .../libgomp.oacc-c-c++-common/loop-gwv-1.c |  15 +-
 .../libgomp.oacc-c-c++-common/loop-red-gwv-1.c |  17 ++-
 .../libgomp.oacc-c-c++-common/loop-red-wv-1.c  |  16 +++
 .../libgomp.oacc-c-c++-common/loop-wv-1.c  |  16 +++
 .../libgomp.oacc-c-c++-common/routine-gwv-1.c  |  17 ++-
 .../libgomp.oacc-c-c++-common/routine-wv-1.c   |  16 +++
 7 files changed, 213 insertions(+), 43 deletions(-)

diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc
index 536bfb7889ce..28f9fa3fe7b5 100644
--- a/gcc/omp-offload.cc
+++ b/gcc/omp-offload.cc
@@ -521,11 +521,13 @@ oacc_dim_call (bool pos, int dim, gimple_seq *seq)
 }
 
 /* Find the number of threads (POS = false), or thread number (POS =
-   true) for an OpenACC region partitioned as MASK.  Setup code
+   true) for an OpenACC region partitioned as MASK.  If VF_BY_VECTORIZER is
+   true, use that as the vectorization factor for the auto-vectorized
+   dimension size, instead of calling the builtin function.  Setup code
required for the calculation is added to SEQ.  */
 
 static tree
-oacc_thread_numbers (bool pos, int mask, gimple_seq *seq)
+oacc_thread_numbers (bool pos, int mask, tree vf_by_vectorizer, gimple_seq 
*seq)
 {
   tree res = pos ? NULL_TREE : build_int_cst (unsigned_type_node, 1);
   unsigned ix;
@@ -538,13 +540,15 @@ oac

[gcc/devel/omp/gcc-15] DWARF: late code range fixup

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:6e115c050c648c8e3cf4f3cb3c5dae6feb348205

commit 6e115c050c648c8e3cf4f3cb3c5dae6feb348205
Author: Andrew Stubbs 
Date:   Sun Dec 6 19:23:55 2020 +

DWARF: late code range fixup

Ensure that the parent DWARF subprograms of offload kernel functions have a
code range, and are therefore not discarded by GDB.  This is only necessary
when the parent function does not actually exist in the final binary, which 
is
commonly the case within the offload device's binary.

gcc/

* dwarf2out.cc (notional_parents_list): New file variable.
(gen_subprogram_die): Record offload kernel functions in
notional_parents_list.
(fixup_notional_parents): New function.
(dwarf2out_finish): Call fixup_notional_parents.
(dwarf2out_c_finalize): Reset notional_parents_list.

Diff:
---
 gcc/dwarf2out.cc | 61 ++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 69e9d775d0d2..1473f731a6aa 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -3466,6 +3466,12 @@ static GTY(()) limbo_die_node *limbo_die_list;
DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set.  */
 static GTY(()) limbo_die_node *deferred_asm_name;
 
+/* A list of DIEs for which we may have to add a notional code range to the
+   parent DIE.  This happens for parents of nested offload kernels, and is
+   necessary because the parents don't exist on the offload target, yet GDB
+   expects parents of real functions to also appear to exist.  */
+static GTY(()) limbo_die_node *notional_parents_list;
+
 struct dwarf_file_hasher : ggc_ptr_hash
 {
   typedef const char *compare_type;
@@ -23945,8 +23951,24 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
  if (fde->dw_fde_begin)
{
  /* We have already generated the labels.  */
- add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
- fde->dw_fde_end, false);
+ add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
+ fde->dw_fde_end, false);
+
+/* Offload kernel functions are nested within a parent function
+   that doesn't actually exist within the offload object.  GDB
+   will ignore the function and everything nested within unless
+   we give the parent a code range.  We can't do it here because
+   that breaks the case where the parent actually does exist (as
+   it does on the host-side), so we defer the fixup for later.  */
+if (lookup_attribute ("omp target entrypoint",
+  DECL_ATTRIBUTES (decl)))
+  {
+limbo_die_node *node = ggc_cleared_alloc ();
+node->die = subr_die;
+node->created_for = decl;
+node->next = notional_parents_list;
+notional_parents_list = node;
+  }
}
  else
{
@@ -32369,6 +32391,37 @@ flush_limbo_die_list (void)
 }
 }
 
+/* Add a code range to the notional parent function (which does not actually
+   exist) so that GDB does not ignore all the child functions.  The actual
+   values do not matter, but need to be valid labels, so we simply copy those
+   from the child function.
+
+   Typically this occurs when we have an offload kernel, where the parent
+   function only exists in the host-side portion of the code.  */
+
+static void
+fixup_notional_parents (void)
+{
+  limbo_die_node *node;
+
+  while ((node = notional_parents_list))
+{
+  dw_die_ref die = node->die;
+  dw_die_ref parent = die->die_parent;
+  notional_parents_list = node->next;
+
+  if (parent
+ && parent->die_tag == DW_TAG_subprogram
+ && !get_AT_low_pc (parent))
+   {
+ dw_attr_node *low = get_AT (die, DW_AT_low_pc);
+ dw_attr_node *high = get_AT (die, DW_AT_high_pc);
+
+ add_AT_low_high_pc (parent, AT_lbl (low), AT_lbl (high), false);
+   }
+}
+}
+
 /* Reset DIEs so we can output them again.  */
 
 static void
@@ -32440,6 +32493,9 @@ dwarf2out_finish (const char *filename)
   /* Flush out any latecomers to the limbo party.  */
   flush_limbo_die_list ();
 
+  /* Insert an notional parent code ranges.  */
+  fixup_notional_parents ();
+
   if (inline_entry_data_table)
 gcc_assert (inline_entry_data_table->is_empty ());
 
@@ -33518,6 +33574,7 @@ dwarf2out_cc_finalize (void)
   single_comp_unit_die = NULL;
   comdat_type_list = NULL;
   limbo_die_list = NULL;
+  notional_parents_list = NULL;
   file_table = NULL;
   decl_die_table = NULL;
   common_block_die_table = NULL;


[gcc/devel/omp/gcc-15] openmp: Add -foffload-memory

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:6c86aec56567424416e52372473c8f0694ce65a9

commit 6c86aec56567424416e52372473c8f0694ce65a9
Author: Andrew Stubbs 
Date:   Fri Apr 18 21:39:54 2025 +

openmp: Add -foffload-memory

https://patchwork.sourceware.org/project/gcc/list/?series=35022

Add a new option.  It's inactive until I add some follow-up patches.

gcc/ChangeLog:

* common.opt: Add -foffload-memory and its enum values.
* coretypes.h (enum offload_memory): New.
* doc/invoke.texi: Document -foffload-memory.

Diff:
---
 gcc/common.opt  | 16 
 gcc/coretypes.h |  7 +++
 gcc/doc/invoke.texi | 15 +++
 3 files changed, 38 insertions(+)

diff --git a/gcc/common.opt b/gcc/common.opt
index e3fa0dacec4c..c3bbadd8d154 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2423,6 +2423,22 @@ foffload-abi-host-opts=
 Common Joined MissingArgError(option missing after %qs)
 -foffload-abi-host-opts=  Specify host ABI options.
 
+foffload-memory=
+Common Joined RejectNegative Enum(offload_memory) Var(flag_offload_memory) 
Init(OFFLOAD_MEMORY_NONE)
+-foffload-memory=[none|unified|pinned] Use an offload memory optimization.
+
+Enum
+Name(offload_memory) Type(enum offload_memory) UnknownError(Unknown offload 
memory option %qs)
+
+EnumValue
+Enum(offload_memory) String(none) Value(OFFLOAD_MEMORY_NONE)
+
+EnumValue
+Enum(offload_memory) String(unified) Value(OFFLOAD_MEMORY_UNIFIED)
+
+EnumValue
+Enum(offload_memory) String(pinned) Value(OFFLOAD_MEMORY_PINNED)
+
 fomit-frame-pointer
 Common Var(flag_omit_frame_pointer) Optimization
 When possible do not generate stack frames.
diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index a11ebd1509b5..3d483a58f52a 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -228,6 +228,13 @@ enum offload_abi {
   OFFLOAD_ABI_ILP32
 };
 
+/* Types of memory optimization for an offload device.  */
+enum offload_memory {
+  OFFLOAD_MEMORY_NONE,
+  OFFLOAD_MEMORY_UNIFIED,
+  OFFLOAD_MEMORY_PINNED
+};
+
 /* Types of profile update methods.  */
 enum profile_update {
   PROFILE_UPDATE_SINGLE,
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index f55f7896d20a..3135821beea4 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -302,6 +302,7 @@ Objective-C and Objective-C++ Dialects}.
 @item OpenMP and OpenACC Options
 @xref{OpenMP and OpenACC Options,,Options Controlling OpenMP and OpenACC}.
 @gccoptlist{-foffload=@var{arg}  -foffload-options=@var{arg}
+-foffload-memory=@var{arg}
 -fopenacc  -fopenacc-dim=@var{geom}
 -fopenmp  -fopenmp-simd  
-fopenmp-target-simd-clone@r{[}=@var{device-type}@r{]}}
 
@@ -5235,6 +5236,20 @@ Typical command lines are
 -foffload-options=amdgcn-amdhsa=-march=gfx906
 @end smallexample
 
+@opindex foffload-memory
+@cindex OpenMP offloading memory modes
+@item -foffload-memory=none
+@itemx -foffload-memory=unified
+@itemx -foffload-memory=pinned
+Enable a memory optimization mode to use with OpenMP.  The default behavior,
+@option{-foffload-memory=none}, is to do nothing special (unless enabled via
+a requires directive in the code).  @option{-foffload-memory=unified} is
+equivalent to @code{#pragma omp requires unified_shared_memory}.
+@option{-foffload-memory=pinned} forces all host memory to be pinned (this
+mode may require the user to increase the ulimit setting for locked memory).
+All translation units must select the same setting to avoid undefined
+behavior.
+
 @opindex fopenacc
 @cindex OpenACC accelerator programming
 @item -fopenacc


[gcc/devel/omp/gcc-15] libgomp amdgcn: Fix issues with dynamic OpenMP thread scaling

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:48db8148b94ab2d93d9d5301f44950adf2a9c786

commit 48db8148b94ab2d93d9d5301f44950adf2a9c786
Author: Andrew Stubbs 
Date:   Tue Aug 3 13:45:35 2021 +0100

libgomp amdgcn: Fix issues with dynamic OpenMP thread scaling

libgomp/ChangeLog:

* config/gcn/bar.h (gomp_barrier_init): Limit thread count to the
actual physical number.
* config/gcn/team.c (gomp_team_start): Don't attempt to set up
threads that do not exist.

Diff:
---
 libgomp/config/gcn/bar.h  | 3 +++
 libgomp/config/gcn/team.c | 4 
 2 files changed, 7 insertions(+)

diff --git a/libgomp/config/gcn/bar.h b/libgomp/config/gcn/bar.h
index b62d3af6dee4..4402b10d7e43 100644
--- a/libgomp/config/gcn/bar.h
+++ b/libgomp/config/gcn/bar.h
@@ -55,6 +55,9 @@ typedef unsigned int gomp_barrier_state_t;
 
 static inline void gomp_barrier_init (gomp_barrier_t *bar, unsigned count)
 {
+  unsigned actual_thread_count = __builtin_gcn_dim_size (1);
+  if (count > actual_thread_count)
+count = actual_thread_count;
   bar->total = count;
   bar->awaited = count;
   bar->awaited_final = count;
diff --git a/libgomp/config/gcn/team.c b/libgomp/config/gcn/team.c
index 40827ce8560c..939ee8773256 100644
--- a/libgomp/config/gcn/team.c
+++ b/libgomp/config/gcn/team.c
@@ -209,6 +209,10 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned 
nthreads,
   if (nthreads == 1)
 return;
 
+  unsigned actual_thread_count = __builtin_gcn_dim_size (1);
+  if (nthreads > actual_thread_count)
+nthreads = actual_thread_count;
+
   /* Release existing idle threads.  */
   for (unsigned i = 1; i < nthreads; ++i)
 {


[gcc/devel/omp/gcc-15] OpenMP: C++ "declare mapper" support

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:b7f04b07a970dd664f3f554352b4b6138498e4c0

commit b7f04b07a970dd664f3f554352b4b6138498e4c0
Author: Julian Brown 
Date:   Sun Apr 20 21:59:22 2025 +

OpenMP: C++ "declare mapper" support

This patch adds support for OpenMP 5.0 "declare mapper" functionality
for C++.  I've merged it to og13 based on the last version
posted upstream, with some minor changes due to the newly-added
'present' map modifier support.  There's also a fix to splay-tree
traversal in gimplify.cc:omp_instantiate_implicit_mappers, and this patch
omits the rearrangement of gimplify.cc:gimplify_{scan,adjust}_omp_clauses
that I separated out into its own patch and applied (to og13) already.

2023-06-30  Julian Brown  

gcc/c-family/
* c-common.h (c_omp_region_type): Add C_ORT_DECLARE_MAPPER and
C_ORT_OMP_DECLARE_MAPPER codes.
(omp_mapper_list): Add forward declaration.
(c_omp_find_nested_mappers, c_omp_instantiate_mappers): Add 
prototypes.
* c-omp.cc (c_omp_find_nested_mappers): New function.
(remap_mapper_decl_info): New struct.
(remap_mapper_decl_1, omp_instantiate_mapper,
c_omp_instantiate_mappers): New functions.

gcc/cp/
* constexpr.cc (reduced_constant_expression_p): Add 
OMP_DECLARE_MAPPER
case.
(cxx_eval_constant_expression, potential_constant_expression_1):
Likewise.
* cp-gimplify.cc (cxx_omp_finish_mapper_clauses): New function.
* cp-objcp-common.h (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES,
LANG_HOOKS_OMP_MAPPER_LOOKUP, 
LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE,
LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define langhooks.
* cp-tree.h (lang_decl_base): Add omp_declare_mapper_p field.  
Recount
spare bits comment.
(DECL_OMP_DECLARE_MAPPER_P): New macro.
(omp_mapper_id): Add prototype.
(cp_check_omp_declare_mapper): Add prototype.
(omp_instantiate_mappers): Add prototype.
(cxx_omp_finish_mapper_clauses): Add prototype.
(cxx_omp_mapper_lookup): Add prototype.
(cxx_omp_extract_mapper_directive): Add prototype.
(cxx_omp_map_array_section): Add prototype.
* decl.cc (check_initializer): Add OpenMP declare mapper support.
(cp_finish_decl): Set DECL_INITIAL for OpenMP declare mapper var 
decls
as appropriate.
* decl2.cc (mark_used): Instantiate OpenMP "declare mapper" magic 
var
decls.
* error.cc (dump_omp_declare_mapper): New function.
(dump_simple_decl): Use above.
* parser.cc (cp_parser_omp_clause_map): Add KIND parameter.  Support
"mapper" modifier.
(cp_parser_omp_all_clauses): Add KIND argument to
cp_parser_omp_clause_map call.
(cp_parser_omp_target): Call omp_instantiate_mappers before
finish_omp_clauses.
(cp_parser_omp_declare_mapper): New function.
(cp_parser_omp_declare): Add "declare mapper" support.
* pt.cc (tsubst_decl): Adjust name of "declare mapper" magic var 
decls
once we know their type.
(tsubst_omp_clauses): Call omp_instantiate_mappers before
finish_omp_clauses, for target regions.
(tsubst_expr): Support OMP_DECLARE_MAPPER nodes.
(instantiate_decl): Instantiate initialiser (i.e definition) for 
OpenMP
declare mappers.
* semantics.cc (gimplify.h): Include.
(omp_mapper_id, omp_mapper_lookup, omp_extract_mapper_directive,
cxx_omp_map_array_section, cp_check_omp_declare_mapper): New 
functions.
(finish_omp_clauses): Delete GOMP_MAP_PUSH_MAPPER_NAME and
GOMP_MAP_POP_MAPPER_NAME artificial clauses.
(omp_target_walk_data): Add MAPPERS field.
(finish_omp_target_clauses_r): Scan for uses of struct/union/class 
type
variables.
(finish_omp_target_clauses): Create artificial mapper binding 
clauses
for used structs/unions/classes in offload region.

gcc/fortran/
* parse.cc (tree.h, fold-const.h, tree-hash-traits.h): Add includes
(for additions to omp-general.h).

gcc/
* gimplify.cc (gimplify_omp_ctx): Add IMPLICIT_MAPPERS field.
(new_omp_context): Initialise IMPLICIT_MAPPERS hash map.
(delete_omp_context): Delete IMPLICIT_MAPPERS hash map.
(instantiate_mapper_info): New structs.
(remap_mapper_decl_1, omp_mapper_copy_decl, omp_instantiate_mapper,
omp_instantiate_implicit_mappers): New functions.
(gimplify_scan_omp_clauses): Handle MAPPER_BINDING clauses.
(gimplify_adjust_omp_clauses): Instantiate implicit declared 
mappers.
(gimplify_

[gcc/devel/omp/gcc-15] OpenACC: Improve implicit mapping for non-lexically nested offload regions

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:87548cbb46416486888daad14c606dffa8e58204

commit 87548cbb46416486888daad14c606dffa8e58204
Author: Julian Brown 
Date:   Sun Apr 20 00:00:54 2025 +

OpenACC: Improve implicit mapping for non-lexically nested offload regions

This patch enables use of the OMP_CLAUSE_RUNTIME_IMPLICIT_P flag for
OpenACC.

This allows code like this to work correctly:

  int arr[100];
  [...]
  #pragma acc enter data copyin(arr[20:10])

  /* No explicit mapping of 'arr' here.  */
  #pragma acc parallel
  { /* use of arr[20:10]... */ }

  #pragma acc exit data copyout(arr[20:10])

Otherwise, the implicit "copy" ("present_or_copy") on the parallel
corresponds to the whole array, and that fails at runtime when the
subarray is mapped.

The numbering of the GOMP_MAP_IMPLICIT bit clashes with the OpenACC
"non-contiguous" dynamic array support, so the GOMP_MAP_NONCONTIG_ARRAY_P
macro has been adjusted to account for that.

gcc/
* gimplify.cc (gimplify_adjust_omp_clauses_1): Set
OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P for OpenACC also.

gcc/testsuite/
* c-c++-common/goacc/combined-reduction.c: Adjust scan output.
* c-c++-common/goacc/implied-copy-1.c: Likewise.
* c-c++-common/goacc/reduction-1.c: Adjust patterns.
* c-c++-common/goacc/reduction-2.c: Likewise.
* c-c++-common/goacc/reduction-3.c: Likewise.
* c-c++-common/goacc/reduction-4.c: Likewise.
* c-c++-common/goacc/reduction-10.c: Likewise.
* gfortran.dg/goacc/common-block-3.f90: Likewise.
* gfortran.dg/goacc/implied-copy-1.f90: Likewise.
* gfortran.dg/goacc/loop-tree-1.f90: Likewise.
* gfortran.dg/goacc/private-explicit-kernels-1.f95: Likewise.
* gfortran.dg/goacc/private-predetermined-kernels-1.f95: Likewise.

include/
* gomp-constants.h (GOMP_MAP_NONCONTIG_ARRAY_P): Tweak condition.

libgomp/
* testsuite/libgomp.oacc-c-c++-common/implicit-mapping-1.c: New 
test.

Co-Authored-By: Thomas Schwinge 
Co-Authored-By: Sandra Loosemore 

Diff:
---
 gcc/gimplify.cc|  5 +
 .../c-c++-common/goacc/combined-reduction.c|  2 +-
 gcc/testsuite/c-c++-common/goacc/implied-copy-1.c  |  4 ++--
 gcc/testsuite/c-c++-common/goacc/reduction-1.c |  4 ++--
 gcc/testsuite/c-c++-common/goacc/reduction-10.c|  9 
 gcc/testsuite/c-c++-common/goacc/reduction-2.c |  4 ++--
 gcc/testsuite/c-c++-common/goacc/reduction-3.c |  4 ++--
 gcc/testsuite/c-c++-common/goacc/reduction-4.c |  4 ++--
 gcc/testsuite/gfortran.dg/goacc/common-block-3.f90 |  8 +++
 gcc/testsuite/gfortran.dg/goacc/implied-copy-1.f90 |  4 ++--
 gcc/testsuite/gfortran.dg/goacc/loop-tree-1.f90|  2 +-
 .../goacc/private-explicit-kernels-1.f95   |  8 +++
 .../goacc/private-predetermined-kernels-1.f95  |  8 +++
 include/gomp-constants.h   |  3 ++-
 .../libgomp.oacc-c-c++-common/implicit-mapping-1.c | 25 ++
 15 files changed, 59 insertions(+), 35 deletions(-)

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 00fb34f71827..a83af5fa4d3e 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -14858,10 +14858,7 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void 
*data)
  gcc_unreachable ();
}
   OMP_CLAUSE_SET_MAP_KIND (clause, kind);
-  /* Setting of the implicit flag for the runtime is currently disabled for
-OpenACC.  */
-  if ((gimplify_omp_ctxp->region_type & ORT_ACC) == 0)
-   OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (clause) = 1;
+  OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (clause) = 1;
   if (DECL_SIZE (decl)
  && !poly_int_tree_p (DECL_SIZE (decl)))
{
diff --git a/gcc/testsuite/c-c++-common/goacc/combined-reduction.c 
b/gcc/testsuite/c-c++-common/goacc/combined-reduction.c
index 0a541402d9d4..75fef98b0bb9 100644
--- a/gcc/testsuite/c-c++-common/goacc/combined-reduction.c
+++ b/gcc/testsuite/c-c++-common/goacc/combined-reduction.c
@@ -33,7 +33,7 @@ main ()
 
 /* { dg-final { scan-tree-dump-times "omp target oacc_parallel reduction.+:v1. 
map.tofrom:v1" 1 "gimple" } } */
 /* { dg-final { scan-tree-dump-times "acc loop reduction.+:v1. private.i." 1 
"gimple" } } */
-/* { dg-final { scan-tree-dump-times "omp target oacc_kernels 
map.force_tofrom:n .len: 4.. map.force_tofrom:v1 .len: 4.." 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "omp target oacc_kernels 
map.force_tofrom:n .len: 4. .runtime_implicit.. map.force_tofrom:v1 .len: 4. 
.runtime_implicit.." 1 "gimple" } } */
 /* { dg-final { scan-tree-dump-times "acc loop reduction.+:v1. private.i." 1 
"gimple" } } */
 /* { dg-final { scan-tree-dump-times "omp target oacc_serial reduction.+:v1. 
map.tofrom:v1" 1 "gimple" } } */
 /* { dg-final { 

[gcc/devel/omp/gcc-15] OpenMP: Fortran "!$omp declare mapper" support

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:80070581ff2949ae982e041f23710c0221661a28

commit 80070581ff2949ae982e041f23710c0221661a28
Author: Julian Brown 
Date:   Wed Apr 23 03:22:33 2025 +

OpenMP: Fortran "!$omp declare mapper" support

This patch implements "omp declare mapper" functionality for Fortran,
following the equivalent support for C and C++.  This version of the
patch has been merged to og13 and contains various fixes for e.g.:

  * Mappers with deferred-length strings

  * Array descriptors not being appropriately transferred
to the offload target (see "OMP_MAP_POINTER_ONLY" and
gimplify.cc:omp_maybe_get_descriptor_from_ptr).

2023-06-30  Julian Brown  

gcc/fortran/
* dump-parse-tree.cc (show_attr): Show omp_udm_artificial_var flag.
(show_omp_namelist): Support OMP_MAP_POINTER_ONLY and OMP_MAP_UNSET.
* f95-lang.cc (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES,
LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE,
LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define language hooks.
* gfortran.h (gfc_statement): Add ST_OMP_DECLARE_MAPPER.
(symbol_attribute): Add omp_udm_artificial_var attribute.
(gfc_omp_map_op): Add OMP_MAP_POINTER_ONLY and OMP_MAP_UNSET.
(gfc_omp_namelist): Add udm pointer to u2 union.
(gfc_omp_udm): New struct.
(gfc_omp_namelist_udm): New struct.
(gfc_symtree): Add omp_udm pointer.
(gfc_namespace): Add omp_udm_root symtree. Add omp_udm_ns flag.
(gfc_free_omp_namelist): Update prototype.
(gfc_free_omp_udm, gfc_omp_udm_find, gfc_find_omp_udm,
gfc_resolve_omp_udms): Add prototypes.
* match.cc (gfc_free_omp_namelist): Change FREE_NS and FREE_ALIGN
parameters to LIST number, to handle freeing user-defined mapper
namelists safely.
* match.h (gfc_match_omp_declare_mapper): Add prototype.
* module.cc (ab_attribute): Add AB_OMP_DECLARE_MAPPER_VAR.
(attr_bits): Add OMP_DECLARE_MAPPER_VAR.
(mio_symbol_attribute): Read/write AB_OMP_DECLARE_MAPPER_VAR 
attribute.
Set referenced attr on read.
(omp_map_clause_ops, omp_map_cardinality): New arrays.
(load_omp_udms, check_omp_declare_mappers): New functions.
(read_module): Load and check OMP declare mappers.
(write_omp_udm, write_omp_udms): New functions.
(write_module): Write OMP declare mappers.
* openmp.cc (gfc_free_omp_clauses, gfc_match_omp_variable_list,
gfc_match_omp_to_link, gfc_match_omp_depend_sink,
gfc_match_omp_clause_reduction): Update calls to 
gfc_free_omp_namelist.
(gfc_free_omp_udm, gfc_find_omp_udm, gfc_omp_udm_find,
gfc_match_omp_declare_mapper): New functions.
(gfc_match_omp_clauses): Add DEFAULT_MAP_OP parameter. Update calls 
to
gfc_free_omp_namelist.  Add declare mapper support.
(resolve_omp_clauses): Add declare mapper support.  Update calls to
gfc_free_omp_namelist.
(gfc_resolve_omp_udm, gfc_resolve_omp_udms): New functions.
* parse.cc (decode_omp_directive): Add declare mapper support.
(case_omp_decl): Add ST_OMP_DECLARE_MAPPER case.
(gfc_ascii_statement): Add ST_OMP_DECLARE_MAPPER case.
* resolve.cc (resolve_types): Call gfc_resolve_omp_udms.
* st.cc (gfc_free_statement): Update call to gfc_free_omp_namelist.
* symbol.cc (free_omp_udm_tree): New function.
(gfc_free_namespace): Call above.
* trans-decl.cc (omp_declare_mapper_ns): New global.
(gfc_finish_var_decl, gfc_generate_function_code): Support declare
mappers.
(gfc_trans_deferred_vars): Ignore artificial declare-mapper vars.
* trans-openmp.cc (tree-iterator.h): Include.
(toc_directive): New enum.
(gfc_trans_omp_array_section): Change OP and OPENMP parameters to
toc_directive CD ('clause directive').
(gfc_omp_finish_mapper_clauses, gfc_omp_extract_mapper_directive,
gfc_omp_map_array_section): New functions.
(omp_clause_directive): New enum.
(gfc_trans_omp_clauses): Remove DECLARE_SIMD and OPENACC parameters.
Replace with toc_directive CD, defaulting to TOC_OPENMP.  Add 
declare
mapper support and OMP_MAP_POINTER_ONLY support.
(gfc_trans_omp_construct, gfc_trans_oacc_executable_directive,
gfc_trans_oacc_combined_directive): Update calls to
gfc_trans_omp_clauses.
(gfc_subst_replace, gfc_subst_prepend_ref): New variables.
(gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var,
gfc_trans_omp_instantiate_mapper, gfc_trans_omp_instantiate_mappers,
gfc_r

[gcc/devel/omp/gcc-15] OpenMP: Reprocess expanded clauses after 'declare mapper' instantiation

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:9c46ffc29646d1c0b16446e8b7e8b294cae49792

commit 9c46ffc29646d1c0b16446e8b7e8b294cae49792
Author: Julian Brown 
Date:   Thu Apr 24 14:31:21 2025 +

OpenMP: Reprocess expanded clauses after 'declare mapper' instantiation

This patch reprocesses expanded clauses after 'declare mapper'
instantiation -- checking things such as duplicated clauses, illegal
use of strided accesses, and so forth.  Two functions are broken out
of the 'resolve_omp_clauses' function and reused in a new function
'resolve_omp_mapper_clauses', called after mapper instantiation.

This improves diagnostic output.

2023-08-10  Julian Brown  

gcc/fortran/
* gfortran.h (gfc_omp_clauses): Add NS field.
* openmp.cc (verify_omp_clauses_symbol_dups,
omp_verify_map_motion_clauses): New functions, broken out of...
(resolve_omp_clauses): Here.  Record namespace containing clauses.
Call above functions.
(resolve_omp_mapper_clauses): New function, using helper functions
broken out above.
(gfc_resolve_omp_directive): Add NS parameter to resolve_omp_clauses
calls.
(gfc_omp_instantiate_mappers): Call resolve_omp_mapper_clauses if we
instantiate any mappers.

gcc/testsuite/
* gfortran.dg/gomp/declare-mapper-26.f90: New test.
* gfortran.dg/gomp/declare-mapper-29.f90: New test.

Diff:
---
 gcc/fortran/gfortran.h |1 +
 gcc/fortran/openmp.cc  | 1211 +++-
 .../gfortran.dg/gomp/declare-mapper-26.f90 |   28 +
 .../gfortran.dg/gomp/declare-mapper-29.f90 |   22 +
 4 files changed, 691 insertions(+), 571 deletions(-)

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 02d7631e544f..848555e60706 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1644,6 +1644,7 @@ typedef struct gfc_omp_clauses
   struct gfc_omp_assumptions *assume;
   struct gfc_expr_list *sizes_list;
   const char *critical_name;
+  gfc_namespace *ns;
   enum gfc_omp_default_sharing default_sharing;
   enum gfc_omp_atomic_op atomic_op;
   enum gfc_omp_defaultmap defaultmap[OMP_DEFAULTMAP_CAT_NUM];
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 3e5960f1a19b..356fc5936dc5 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -8812,263 +8812,15 @@ gfc_resolve_omp_assumptions (gfc_omp_assumptions 
*assume)
 &el->expr->where);
 }
 
-
-/* OpenMP directive resolving routines.  */
+/* Check OMP_CLAUSES for duplicate symbols and various other constraints.
+   Helper function for resolve_omp_clauses and resolve_omp_mapper_clauses.  */
 
 static void
-resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
-gfc_namespace *ns, bool openacc = false)
+verify_omp_clauses_symbol_dups (gfc_code *code, gfc_omp_clauses *omp_clauses,
+   gfc_namespace *ns, bool openacc)
 {
-  gfc_omp_namelist *n, *last;
-  gfc_expr_list *el;
+  gfc_omp_namelist *n;
   int list;
-  int ifc;
-  bool if_without_mod = false;
-  gfc_omp_linear_op linear_op = OMP_LINEAR_DEFAULT;
-  static const char *clause_names[]
-= { "PRIVATE", "FIRSTPRIVATE", "LASTPRIVATE", "COPYPRIVATE", "SHARED",
-   "COPYIN", "UNIFORM", "AFFINITY", "ALIGNED", "LINEAR", "DEPEND", "MAP",
-   "TO", "FROM", "INCLUSIVE", "EXCLUSIVE",
-   "REDUCTION", "REDUCTION" /*inscan*/, "REDUCTION" /*task*/,
-   "IN_REDUCTION", "TASK_REDUCTION",
-   "DEVICE_RESIDENT", "LINK", "USE_DEVICE",
-   "CACHE", "IS_DEVICE_PTR", "USE_DEVICE_PTR", "USE_DEVICE_ADDR",
-   "NONTEMPORAL", "ALLOCATE", "HAS_DEVICE_ADDR", "ENTER",
-   "USES_ALLOCATORS", "INIT", "USE", "DESTROY", "INTEROP", "ADJUST_ARGS" };
-  STATIC_ASSERT (ARRAY_SIZE (clause_names) == OMP_LIST_NUM);
-
-  if (omp_clauses == NULL)
-return;
-
-  if (ns == NULL)
-ns = gfc_current_ns;
-
-  if (omp_clauses->orderedc && omp_clauses->orderedc < omp_clauses->collapse)
-gfc_error ("ORDERED clause parameter is less than COLLAPSE at %L",
-  &code->loc);
-  if (omp_clauses->order_concurrent && omp_clauses->ordered)
-gfc_error ("ORDER clause must not be used together with ORDERED at %L",
-  &code->loc);
-  if (omp_clauses->if_expr)
-{
-  gfc_expr *expr = omp_clauses->if_expr;
-  if (!gfc_resolve_expr (expr)
- || expr->ts.type != BT_LOGICAL || expr->rank != 0)
-   gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
-  &expr->where);
-  if_without_mod = true;
-}
-  for (ifc = 0; ifc < OMP_IF_LAST; ifc++)
-if (omp_clauses->if_exprs[ifc])
-  {
-   gfc_expr *expr = omp_clauses->if_exprs[ifc];
-   bool ok = true;
-   if (!gfc_resolve_expr (expr)
-   || expr->ts.type != BT_LOGICAL || expr->rank != 0)
- gfc_error ("IF 

[gcc/devel/omp/gcc-15] OpenMP: Move Fortran 'declare mapper' instantiation code

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:0b097544ca3abd8faf2078777fd50ca4a154dba5

commit 0b097544ca3abd8faf2078777fd50ca4a154dba5
Author: Julian Brown 
Date:   Tue Apr 22 04:29:50 2025 +

OpenMP: Move Fortran 'declare mapper' instantiation code

This patch moves the code for explicit 'declare mapper' directive
instantiation in the Fortran front-end to openmp.cc from trans-openmp.cc.
The transformation takes place entirely in the front end's own
representation and doesn't involve middle-end trees at all. Also, having
the code in openmp.cc is more convenient for the following patch that
introduces the 'resolve_omp_mapper_clauses' function.

2023-08-10  Julian Brown  

gcc/fortran/
* gfortran.h (toc_directive): Move here.
(gfc_omp_instantiate_mappers, gfc_get_location): Add prototypes.
* openmp.cc (omp_split_map_op, omp_join_map_op, 
omp_map_decayed_kind,
omp_basic_map_kind_name, gfc_subst_replace, gfc_subst_prepend_ref,
gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var): Move
here.
(gfc_omp_instantiate_mapper, gfc_omp_instantiate_mappers): Move here
and rename.
* trans-openmp.cc (toc_directive, omp_split_map_op, omp_join_map_op,
omp_map_decayed_kind, gfc_subst_replace, gfc_subst_prepend_ref,
gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var,
gfc_trans_omp_instantiate_mapper, 
gfc_trans_omp_instantiate_mappers):
Remove from here.
(gfc_trans_omp_target, gfc_trans_omp_target_data,
gfc_trans_omp_target_enter_data, gfc_trans_omp_target_exit_data):
Rename calls to gfc_omp_instantiate_mappers.

Diff:
---
 gcc/fortran/gfortran.h  |  17 ++
 gcc/fortran/openmp.cc   | 436 
 gcc/fortran/trans-openmp.cc | 389 +--
 3 files changed, 458 insertions(+), 384 deletions(-)

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 5d9d5460069b..02d7631e544f 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3405,6 +3405,19 @@ typedef struct gfc_finalizer
 gfc_finalizer;
 #define gfc_get_finalizer() XCNEW (gfc_finalizer)
 
+/* Control clause translation per-directive for gfc_trans_omp_clauses.  Also
+   used for gfc_omp_instantiate_mappers.  */
+
+enum toc_directive
+{
+  TOC_OPENMP,
+  TOC_OPENMP_DECLARE_SIMD,
+  TOC_OPENMP_DECLARE_MAPPER,
+  TOC_OPENMP_EXIT_DATA,
+  TOC_OPENACC,
+  TOC_OPENACC_DECLARE,
+  TOC_OPENACC_EXIT_DATA
+};
 
 / Function prototypes */
 
@@ -3904,6 +3917,9 @@ void gfc_resolve_omp_do_blocks (gfc_code *, gfc_namespace 
*);
 void gfc_resolve_omp_declare (gfc_namespace *);
 void gfc_resolve_omp_udrs (gfc_symtree *);
 void gfc_resolve_omp_udms (gfc_symtree *);
+void gfc_omp_instantiate_mappers (gfc_code *, gfc_omp_clauses *,
+ toc_directive = TOC_OPENMP,
+ int = OMP_LIST_MAP);
 void gfc_omp_save_and_clear_state (struct gfc_omp_saved_state *);
 void gfc_omp_restore_state (struct gfc_omp_saved_state *);
 void gfc_free_expr_list (gfc_expr_list *);
@@ -4160,6 +4176,7 @@ bool gfc_convert_to_structure_constructor (gfc_expr *, 
gfc_symbol *,
 /* trans.cc */
 void gfc_generate_code (gfc_namespace *);
 void gfc_generate_module_code (gfc_namespace *);
+location_t gfc_get_location (locus *);
 
 /* trans-intrinsic.cc */
 bool gfc_inline_intrinsic_function_p (gfc_expr *);
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index e9b4da3be89e..3e5960f1a19b 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -13520,6 +13520,442 @@ gfc_resolve_omp_udrs (gfc_symtree *st)
 gfc_resolve_omp_udr (omp_udr);
 }
 
+static enum gfc_omp_map_op
+omp_split_map_op (enum gfc_omp_map_op op, bool *force_p, bool *always_p,
+ bool *present_p)
+{
+  *force_p = *always_p = *present_p = false;
+
+  switch (op)
+{
+case OMP_MAP_FORCE_ALLOC:
+case OMP_MAP_FORCE_TO:
+case OMP_MAP_FORCE_FROM:
+case OMP_MAP_FORCE_TOFROM:
+case OMP_MAP_FORCE_PRESENT:
+  *force_p = true;
+  break;
+case OMP_MAP_ALWAYS_TO:
+case OMP_MAP_ALWAYS_FROM:
+case OMP_MAP_ALWAYS_TOFROM:
+  *always_p = true;
+  break;
+case OMP_MAP_ALWAYS_PRESENT_TO:
+case OMP_MAP_ALWAYS_PRESENT_FROM:
+case OMP_MAP_ALWAYS_PRESENT_TOFROM:
+  *always_p = true;
+  /* Fallthrough.  */
+case OMP_MAP_PRESENT_ALLOC:
+case OMP_MAP_PRESENT_TO:
+case OMP_MAP_PRESENT_FROM:
+case OMP_MAP_PRESENT_TOFROM:
+  *present_p = true;
+  break;
+default:
+  ;
+}
+
+  switch (op)
+{
+case OMP_MAP_ALLOC:
+case OMP_MAP_FORCE_ALLOC:
+case OMP_MAP_PRESENT_ALLOC:
+  return OMP_MAP_ALLOC;
+case OMP_MAP_TO:
+case OMP_MAP_FORCE_TO:
+case OMP_MAP_ALWAYS_TO:
+case OMP_MAP_PRESENT_T

[gcc/devel/omp/gcc-15] OpenMP: Support OpenMP 5.0 "declare mapper" directives for C

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:69fd51954fcfb3dbb4972cb873221a30b6262849

commit 69fd51954fcfb3dbb4972cb873221a30b6262849
Author: Julian Brown 
Date:   Mon Apr 21 02:08:35 2025 +

OpenMP: Support OpenMP 5.0 "declare mapper" directives for C

This patch adds support for "declare mapper" directives (and the "mapper"
modifier on "map" clauses) for C.

gcc/c/
* c-decl.cc (c_omp_mapper_id, c_omp_mapper_decl, 
c_omp_mapper_lookup,
c_omp_extract_mapper_directive, c_omp_map_array_section,
c_omp_scan_mapper_bindings_r, c_omp_scan_mapper_bindings): New
functions.
* c-objc-common.h (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES,
LANG_HOOKS_OMP_MAPPER_LOOKUP, 
LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE,
LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define langhooks for C.
* c-parser.cc (c_parser_omp_clause_map): Add KIND parameter.  Handle
mapper modifier.
(c_parser_omp_all_clauses): Update call to c_parser_omp_clause_map 
with
new kind argument.
(c_parser_omp_target): Instantiate explicit mappers and record 
bindings
for implicit mappers.
(c_parser_omp_declare_mapper): Parse "declare mapper" directives.
(c_parser_omp_declare): Support "declare mapper".
* c-tree.h (c_omp_finish_mapper_clauses, c_omp_mapper_lookup,
c_omp_extract_mapper_directive, c_omp_map_array_section,
c_omp_mapper_id, c_omp_mapper_decl, c_omp_scan_mapper_bindings,
c_omp_instantiate_mappers): Add prototypes.
* c-typeck.cc (c_finish_omp_clauses): Handle 
GOMP_MAP_PUSH_MAPPER_NAME
and GOMP_MAP_POP_MAPPER_NAME.
(c_omp_finish_mapper_clauses): New function (langhook).

gcc/testsuite/
* c-c++-common/gomp/declare-mapper-3.c: Enable for C.
* c-c++-common/gomp/declare-mapper-4.c: Likewise.
* c-c++-common/gomp/declare-mapper-5.c: Likewise.
* c-c++-common/gomp/declare-mapper-6.c: Likewise.
* c-c++-common/gomp/declare-mapper-7.c: Likewise.
* c-c++-common/gomp/declare-mapper-8.c: Likewise.
* c-c++-common/gomp/declare-mapper-9.c: Likewise.
* c-c++-common/gomp/declare-mapper-12.c: Enable for C.
* gcc.dg/gomp/declare-mapper-10.c: New test.
* gcc.dg/gomp/declare-mapper-11.c: New test.

libgomp/
* testsuite/libgomp.c-c++-common/declare-mapper-9.c: Enable for C.
* testsuite/libgomp.c-c++-common/declare-mapper-10.c: Likewise.
* testsuite/libgomp.c-c++-common/declare-mapper-11.c: Likewise.
* testsuite/libgomp.c-c++-common/declare-mapper-12.c: Likewise.
* testsuite/libgomp.c-c++-common/declare-mapper-13.c: Likewise.
* testsuite/libgomp.c-c++-common/declare-mapper-14.c: Likewise.

Diff:
---
 gcc/c/c-decl.cc| 169 +
 gcc/c/c-objc-common.h  |  12 +
 gcc/c/c-parser.cc  | 279 +++--
 gcc/c/c-tree.h |   8 +
 gcc/c/c-typeck.cc  |  15 ++
 .../c-c++-common/gomp/declare-mapper-12.c  |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-3.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-4.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-5.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-6.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-7.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-8.c |   2 +-
 gcc/testsuite/c-c++-common/gomp/declare-mapper-9.c |   2 +-
 gcc/testsuite/gcc.dg/gomp/declare-mapper-10.c  |  61 +
 gcc/testsuite/gcc.dg/gomp/declare-mapper-11.c  |  33 +++
 .../libgomp.c-c++-common/declare-mapper-10.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-11.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-12.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-13.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-14.c   |   2 +-
 .../libgomp.c-c++-common/declare-mapper-9.c|   2 +-
 21 files changed, 574 insertions(+), 31 deletions(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 8c420f229762..b8af1282eab7 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -13857,6 +13857,175 @@ c_check_omp_declare_reduction_r (tree *tp, int *, 
void *data)
   return NULL_TREE;
 }
 
+/* Return identifier to look up for omp declare reduction.  */
+
+tree
+c_omp_mapper_id (tree mapper_id)
+{
+  const char *p = NULL;
+
+  const char prefix[] = "omp declare mapper ";
+
+  if (mapper_id == NULL_TREE)
+p = "";
+  else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
+p = IDENTIFIER_POINTER (mapper_id);
+  else
+return error_mark_node;
+
+  size_t lenp = sizeof (prefix);
+  size_t len = strlen (p);
+  char *name = XALLOCAV

[gcc/devel/omp/gcc-15] OpenMP, Fortran: Handle errors in 'declare mapper' instantiation

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:7affa61f67813b86206db027b981b165bccb84b7

commit 7affa61f67813b86206db027b981b165bccb84b7
Author: Sandra Loosemore 
Date:   Mon May 12 16:41:45 2025 +

OpenMP, Fortran: Handle errors in 'declare mapper' instantiation

The patch "OpenMP: Reprocess expanded clauses after 'declare mapper'
instantiation" added further error-checking to
gfc_omp_instantiate_mappers, which is called during the translation
phase of processing, but these errors were effectively ignored for
further processing of the code.  This patch makes the translation
phase insert an error_mark_node in these situations instead of
generating normal tree code.

This patch fixes an ICE in gfortran.dg/gomp/declare-mapper-29.f90
where it was attempting to gimplify code that had already been
diagnosed as invalid in the front end.

gcc/fortran/ChangeLog
* gfortran.h (gfc_omp_instantiate_mappers): Adjust declaration
to return an error status instead of void.
* openmp.cc (gfc_gomp_instantiate_mappers): Likewise for the
the definition.
* trans-openmp.cc (gfc_trans_omp_target): Check return status of
call to gfc_omp_instantiate_mappers and insert an error_mark_node
on failure instead of continuing normal processing of the construct.
(gfc_trans_omp_target_data): Likewise.
(gfc_trans_omp_target_enter_data): Likewise.
(gfc_trans_omp_target_exit_data): Likewise.

Diff:
---
 gcc/fortran/gfortran.h  |  2 +-
 gcc/fortran/openmp.cc   | 10 -
 gcc/fortran/trans-openmp.cc | 52 ++---
 3 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 848555e60706..3be828c960a7 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3918,7 +3918,7 @@ void gfc_resolve_omp_do_blocks (gfc_code *, gfc_namespace 
*);
 void gfc_resolve_omp_declare (gfc_namespace *);
 void gfc_resolve_omp_udrs (gfc_symtree *);
 void gfc_resolve_omp_udms (gfc_symtree *);
-void gfc_omp_instantiate_mappers (gfc_code *, gfc_omp_clauses *,
+bool gfc_omp_instantiate_mappers (gfc_code *, gfc_omp_clauses *,
  toc_directive = TOC_OPENMP,
  int = OMP_LIST_MAP);
 void gfc_omp_save_and_clear_state (struct gfc_omp_saved_state *);
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 356fc5936dc5..bcb54512943f 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -13976,13 +13976,18 @@ gfc_omp_instantiate_mapper (gfc_omp_namelist 
**outlistp,
   return outlistp;
 }
 
-void
+/* Instantiate mappers for CLAUSES for LIST.  Returns true on success and
+   false if errors were diagnosed.  This function is invoked from the
+   translation phase so callers need to handle passing up the error.  */
+bool
 gfc_omp_instantiate_mappers (gfc_code *code ATTRIBUTE_UNUSED, gfc_omp_clauses 
*clauses,
 toc_directive cd, int list)
 {
   gfc_omp_namelist *clause = clauses->lists[list];
   gfc_omp_namelist **clausep = &clauses->lists[list];
   bool invoked_mappers = false;
+  int orig_errors, new_errors;
+  gfc_get_errors (NULL, &orig_errors);
 
   for (; clause; clause = *clausep)
 {
@@ -14023,6 +14028,9 @@ gfc_omp_instantiate_mappers (gfc_code *code 
ATTRIBUTE_UNUSED, gfc_omp_clauses *c
   resolve_omp_mapper_clauses (code, clauses, gfc_current_ns);
   gfc_current_ns = old_ns;
 }
+
+  gfc_get_errors (NULL, &new_errors);
+  return new_errors == orig_errors;
 }
 
 /* Resolve !$omp declare mapper constructs.  */
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 13194be355b6..66709dd0be95 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -9246,7 +9246,11 @@ gfc_trans_omp_target (gfc_code *code)
   if (flag_openmp)
 {
   gfc_omp_clauses *target_clauses = &clausesa[GFC_OMP_SPLIT_TARGET];
-  gfc_omp_instantiate_mappers (code, target_clauses);
+  if (!gfc_omp_instantiate_mappers (code, target_clauses))
+   {
+ stmt = error_mark_node;
+ goto done;
+   }
   omp_clauses = gfc_trans_omp_clauses (&block, target_clauses,
   code->loc);
 }
@@ -9348,6 +9352,7 @@ gfc_trans_omp_target (gfc_code *code)
OMP_TARGET_COMBINED (stmt) = 1;
   cfun->has_omp_target = true;
 }
+ done:
   gfc_add_expr_to_block (&block, stmt);
   gfc_free_split_omp_clauses (code, clausesa);
   return gfc_finish_block (&block);
@@ -9527,11 +9532,16 @@ gfc_trans_omp_target_data (gfc_code *code)
 
   gfc_start_block (&block);
   gfc_omp_clauses *target_data_clauses = code->ext.omp_clauses;
-  gfc_omp_instantiate_mappers (code, target_data_clauses);
-  omp_clauses = gfc_trans_omp_clauses (&block, target_data_clauses, code->loc);
-  stmt = gfc_trans_omp_code (code->block->

[gcc/devel/omp/gcc-15] OpenMP: Look up 'declare mapper' definitions at resolution time not parse time

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:3ea1f835c3775431634ffe1ad44b0c742664a3dd

commit 3ea1f835c3775431634ffe1ad44b0c742664a3dd
Author: Julian Brown 
Date:   Wed Apr 23 00:01:43 2025 +

OpenMP: Look up 'declare mapper' definitions at resolution time not parse 
time

This patch moves 'declare mapper' lookup for OpenMP clauses from parse
time to resolution time for Fortran, and adds diagnostics for missing
named mappers.  This changes clause lookup in a particular case -- where
several 'declare mapper's are defined in a context, mappers declared
earlier may now instantiate mappers declared later, whereas previously
they would not.  I think the new behaviour makes more sense -- at an
invocation site, all mappers are visible no matter the declaration order
in some particular block.  I've adjusted tests to account for this.

I think the new arrangement better matches the Fortran FE's usual way of
doing things -- mapper lookup is a semantic concept, not a syntactical
one, so shouldn't be handled in the syntax-handling code.

The patch also fixes a case where the user explicitly writes 'default'
as the name on the mapper modifier for a clause.

2023-08-10  Julian Brown  

gcc/fortran/
* gfortran.h (gfc_omp_namelist_udm): Add MAPPER_ID field to store 
the
mapper name to use for lookup during resolution.
* match.cc (gfc_free_omp_namelist): Handle OMP_LIST_TO and
OMP_LIST_FROM when freeing mapper references.
* module.cc (load_omp_udms, write_omp_udm): Handle MAPPER_ID field.
* openmp.cc (gfc_match_omp_clauses): Handle explicitly-specified
'default' name.  Don't do mapper lookup here, but record mapper 
name if
the user specifies one.
(resolve_omp_clauses): Do mapper lookup here instead.  Report error 
for
missing named mapper.

gcc/testsuite/
* gfortran.dg/gomp/declare-mapper-31.f90: New test.

libgomp/
* testsuite/libgomp.fortran/declare-mapper-30.f90: New test.
* testsuite/libgomp.fortran/declare-mapper-4.f90: Adjust test for 
new
lookup behaviour.

Diff:
---
 gcc/fortran/gfortran.h |  3 ++
 gcc/fortran/match.cc   |  4 +-
 gcc/fortran/module.cc  |  6 +++
 gcc/fortran/openmp.cc  | 46 --
 .../gfortran.dg/gomp/declare-mapper-31.f90 | 34 
 .../libgomp.fortran/declare-mapper-30.f90  | 24 +++
 .../testsuite/libgomp.fortran/declare-mapper-4.f90 | 18 +
 7 files changed, 116 insertions(+), 19 deletions(-)

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 3be828c960a7..67cf255fbd93 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1844,6 +1844,9 @@ gfc_omp_udm;
 
 typedef struct gfc_omp_namelist_udm
 {
+  /* Used to store mapper_id before resolution.  */
+  const char *mapper_id;
+
   bool multiple_elems_p;
   struct gfc_omp_udm *udm;
 }
diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc
index aa902f935e08..d1648fdf913c 100644
--- a/gcc/fortran/match.cc
+++ b/gcc/fortran/match.cc
@@ -5882,7 +5882,9 @@ void
 gfc_free_omp_namelist (gfc_omp_namelist *name, int list)
 {
   bool free_ns = (list == OMP_LIST_AFFINITY || list == OMP_LIST_DEPEND);
-  bool free_mapper = (list == OMP_LIST_MAP);
+  bool free_mapper = (list == OMP_LIST_MAP
+ || list == OMP_LIST_TO
+ || list == OMP_LIST_FROM);
   bool free_align_allocator = (list == OMP_LIST_ALLOCATE);
   bool free_mem_traits_space = (list == OMP_LIST_USES_ALLOCATORS);
   bool free_init = (list == OMP_LIST_INIT);
diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc
index bad9b6948a2d..bf43ed59eb47 100644
--- a/gcc/fortran/module.cc
+++ b/gcc/fortran/module.cc
@@ -5562,6 +5562,11 @@ load_omp_udms (void)
  if (peek_atom () != ATOM_RPAREN)
{
  n->u2.udm = gfc_get_omp_namelist_udm ();
+ mio_pool_string (&n->u2.udm->mapper_id);
+
+ if (n->u2.udm->mapper_id == NULL)
+   n->u2.udm->mapper_id = gfc_get_string ("%s", "");
+
  n->u2.udm->multiple_elems_p = mio_name (0, omp_map_cardinality);
  mio_pointer_ref (&n->u2.udm->udm);
}
@@ -6638,6 +6643,7 @@ write_omp_udm (gfc_omp_udm *udm)
 
   if (n->u2.udm)
{
+ mio_pool_string (&n->u2.udm->mapper_id);
  mio_name (n->u2.udm->multiple_elems_p, omp_map_cardinality);
  mio_pointer_ref (&n->u2.udm->udm);
}
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index bcb54512943f..ea4e75edd700 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -3645,6 +3645,8 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const 
omp_mask mask,
  m = gfc_match (" %n ) ", mappe

[gcc/devel/omp/gcc-15] OpenMP: Noncontiguous "target update" for Fortran

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:b5994c6a48001a32644c1bb575d40dbef05947a3

commit b5994c6a48001a32644c1bb575d40dbef05947a3
Author: Julian Brown 
Date:   Thu Apr 24 19:05:56 2025 +

OpenMP: Noncontiguous "target update" for Fortran

(Note: On OG14 branch, this was tacked on to "OpenMP: Array shaping
operator and strided "target update" for C", losing its original
commit message from OG13; I've restored it as a separate patch for
OG15, and merged with "Strided/rectangular 'target update'
out-of-bounds array lookup fix" and the Fortran part of "Dimension
ordering for array-shaping operator for C and C++".)

This patch implements noncontiguous "target update" for Fortran.
The existing middle end/runtime bits relating to C++ support are reused,
with some small adjustments, e.g.:

  1. The node used to map the OMP "array descriptor" (from omp-low.cc
 onwards) now uses the OMP_CLAUSE_SIZE field as a bias (the difference
 between the "virtual origin" element with zero indices in each
 dimension and the first element actually stored in memory).

  2. The OMP_CLAUSE_SIZE field of a GOMP_MAP_DIM_STRIDE node may now be
 used to store a "span", which is the distance in bytes between
 two adjacent elements in an array (with unit stride) when that is
 different from the element size, as it can be in Fortran.

The implementation goes to some effort to massage Fortran array metadata
(array descriptors) into a form that can ultimately be consumed by
omp_target_memcpy_rect_worker. The method for doing this is described
in comments in the patch body.

2023-07-03  Julian Brown  

gcc/ChangeLog
* gimplify.cc (gimplify_adjust_omp_clauses): Don't gimplify
VIEW_CONVERT_EXPR away in GOMP_MAP_TO_GRID/GOMP_MAP_FROM_GRID 
clauses.
* omp-low.cc (omp_noncontig_descriptor_type): Add SPAN field.
(scan_sharing_clauses): Don't store descriptor size in its
OMP_CLAUSE_SIZE field.
(lower_omp_target): Add missing OMP_CLAUSE_MAP check.  Add 
special-case
string handling.  Handle span and bias.  Use low bound instead of 
zero
as index for trailing full dimensions.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_omp_deep_map_kind_p): Handle
GOMP_MAP_{TO,FROM}_GRID, GOMP_MAP_GRID_{DIM,STRIDE}.
(gfc_trans_omp_arrayshape_type, gfc_omp_calculate_gcd,
gfc_desc_to_omp_noncontig_array, gfc_omp_contiguous_update_p): New
functions.
(gfc_trans_omp_clauses): Handle noncontiguous to/from clauses for 
OMP
"target update" directives.

gcc/testsuite/ChangeLog
* gfortran.dg/gomp/noncontig-updates-1.f90: New test.
* gfortran.dg/gomp/noncontig-updates-2.f90: New test.
* gfortran.dg/gomp/noncontig-updates-3.f90: New test.
* gfortran.dg/gomp/noncontig-updates-4.f90: New test.

libgomp/ChangeLog
* libgomp.h (omp_noncontig_array_desc): Add span field.
* target.c (omp_target_memcpy_rect_worker): Add span parameter. 
Update
forward declaration. Handle span != element_size.
(gomp_update): Handle bias in descriptor's size slot.  Update calls 
to
omp_target_memcpy_rect_worker.
* testsuite/libgomp.fortran/noncontig-updates-1.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-2.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-3.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-4.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-5.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-6.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-7.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-8.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-9.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-10.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-11.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-12.f90: New test.
* testsuite/libgomp.fortran/noncontig-updates-13.f90: New test.

Co-Authored-By: Sandra Loosemore 

Diff:
---
 gcc/fortran/trans-openmp.cc| 500 +
 gcc/gimplify.cc|  10 +
 gcc/omp-low.cc |  94 +++-
 .../gfortran.dg/gomp/noncontig-updates-1.f90   |  19 +
 .../gfortran.dg/gomp/noncontig-updates-2.f90   |  16 +
 .../gfortran.dg/gomp/noncontig-updates-3.f90   |  16 +
 .../gfortran.dg/gomp/noncontig-updates-4.f90   |  15 +
 libgomp/libgomp.h  |   1 +
 libgomp/target.c

[gcc/devel/omp/gcc-15] OpenMP: Array shaping operator and strided "target update" for C

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:7fc852666c51536b6d504505ab84b2c050c46d17

commit 7fc852666c51536b6d504505ab84b2c050c46d17
Author: Julian Brown 
Date:   Thu Apr 24 19:03:16 2025 +

OpenMP: Array shaping operator and strided "target update" for C

Following the similar support for C++, here is the C implementation for
the OpenMP 5.0 array-shaping operator, and for strided and rectangular
updates for "target update".

Much of the implementation is shared with the C++ support added by the
previous patch.  Some details of parsing necessarily differ for C,
but the general ideas are the same.

This version of the patch has been rebased and contains a couple of
minor fixes relative to versions posted previously.

2023-09-05  Julian Brown  

gcc/c/
* c-parser.cc (c_parser_braced_init): Disallow array-shaping 
operator
in braced init.
(c_parser_conditional_expression): Disallow array-shaping operator 
in
conditional expression.
(c_parser_cast_expression): Add array-shaping operator support.
(c_parser_postfix_expression): Disallow array-shaping operator in
statement expressions.
(c_parser_postfix_expression_after_primary): Add OpenMP array 
section
stride support.
(c_parser_expr_list): Disallow array-shaping operator in expression
lists.
(c_array_type_nelts_total): New function.
(c_parser_omp_variable_list): Support array-shaping operator.
(c_parser_omp_target_update): Recognize GOMP_MAP_TO_GRID and
GOMP_MAP_FROM_GRID map kinds as well as 
OMP_CLAUSE_TO/OMP_CLAUSE_FROM.
* c-tree.h (c_omp_array_shaping_op_p, c_omp_has_array_shape_p): New
extern declarations.
(create_omp_arrayshape_type): Add prototype.
* c-typeck.cc (c_omp_array_shaping_op_p, c_omp_has_array_shape_p): 
New
globals.
(build_omp_array_section): Permit integral types, not just integer
constants, when creating array types for array sections.
(create_omp_arrayshape_type): New function.
(handle_omp_array_sections_1): Add DISCONTIGUOUS parameter.  Add
strided/rectangular array section support.
(omp_array_section_low_bound): New function.
(handle_omp_array_sections): Add DISCONTIGUOUS parameter.  Add
strided/rectangular array section support.
(c_finish_omp_clauses): Update calls to handle_omp_array_sections.
Handle discontiguous updates.

gcc/testsuite/
* gcc.dg/gomp/bad-array-shaping-c-1.c: New test.
* gcc.dg/gomp/bad-array-shaping-c-2.c: New test.
* gcc.dg/gomp/bad-array-shaping-c-3.c: New test.
* gcc.dg/gomp/bad-array-shaping-c-4.c: New test.
* gcc.dg/gomp/bad-array-shaping-c-5.c: New test.
* gcc.dg/gomp/bad-array-shaping-c-6.c: New test.
* gcc.dg/gomp/bad-array-shaping-c-7.c: New test.

libgomp/
* testsuite/libgomp.c-c++-common/array-shaping-14.c: New test.
* testsuite/libgomp.c/array-shaping-1.c: New test.
* testsuite/libgomp.c/array-shaping-2.c: New test.
* testsuite/libgomp.c/array-shaping-3.c: New test.
* testsuite/libgomp.c/array-shaping-4.c: New test.
* testsuite/libgomp.c/array-shaping-5.c: New test.
* testsuite/libgomp.c/array-shaping-6.c: New test.

Diff:
---
 gcc/c/c-parser.cc  | 294 -
 gcc/c/c-tree.h |   4 +
 gcc/c/c-typeck.cc  | 232 +---
 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-1.c  |  26 ++
 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-2.c  |  24 ++
 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-3.c  |  30 +++
 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-4.c  |  27 ++
 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-5.c  |  17 ++
 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-6.c  |  26 ++
 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-7.c  |  15 ++
 .../libgomp.c-c++-common/array-shaping-14.c|  34 +++
 libgomp/testsuite/libgomp.c/array-shaping-1.c  | 236 +
 libgomp/testsuite/libgomp.c/array-shaping-2.c  |  39 +++
 libgomp/testsuite/libgomp.c/array-shaping-3.c  |  42 +++
 libgomp/testsuite/libgomp.c/array-shaping-4.c  |  36 +++
 libgomp/testsuite/libgomp.c/array-shaping-5.c  |  38 +++
 libgomp/testsuite/libgomp.c/array-shaping-6.c  |  45 
 17 files changed, 1121 insertions(+), 44 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index d72cd10fbb8b..708f7d8f1391 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -6438,7 +6438,9 @@ c_parser_braced_init (c_parser *parser, tree type, bool 
nested_p,
   gcc_obstack_init (&braced_init_obstack);
   gc

[gcc/devel/omp/gcc-15] OpenMP: testsuite fixups for C++ allocators

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:b2fe3f7606e8faa5f0f68470f86a34e64d999408

commit b2fe3f7606e8faa5f0f68470f86a34e64d999408
Author: Sandra Loosemore 
Date:   Sat May 10 21:45:56 2025 +

OpenMP: testsuite fixups for C++ allocators

The patch "OpenMP: Add C++ support for 'omp allocate'" is a backport
of a mainline patch.  These additional testsuite fixes are necessary to
shut up bogus failures on OG15 but maybe are not required or suitable for
upstream.

gcc/testsuite/
* c-c++-common/gomp/uses_allocators-1.c: Adjust for this testcase
no longer failing with "sorry" in C++.
* g++.dg/gomp/allocate-15.C: Disable scan-assembler tests since
compilation fails with "sorry" before getting that far.
* g++.dg/gomp/allocate-16.C: Likewise.

Diff:
---
 gcc/testsuite/c-c++-common/gomp/uses_allocators-1.c |  4 ++--
 gcc/testsuite/g++.dg/gomp/allocate-15.C | 18 --
 gcc/testsuite/g++.dg/gomp/allocate-16.C | 18 --
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/gomp/uses_allocators-1.c 
b/gcc/testsuite/c-c++-common/gomp/uses_allocators-1.c
index 5a2e4a90e54c..acfd5b72a01f 100644
--- a/gcc/testsuite/c-c++-common/gomp/uses_allocators-1.c
+++ b/gcc/testsuite/c-c++-common/gomp/uses_allocators-1.c
@@ -22,7 +22,7 @@ f (omp_allocator_handle_t my_alloc)
   #pragma omp target
   {
 int a; /* { dg-error "'my_alloc' in 'allocator' clause inside a target 
region must be specified in an 'uses_allocators' clause on the 'target' 
directive" "" { target c } } */
-#pragma omp allocate(a) allocator(my_alloc) /* { dg-message "sorry, 
unimplemented: '#pragma omp allocate' not yet supported" "" { target c++ } }  */
+#pragma omp allocate(a) allocator(my_alloc) /* { dg-error "'my_alloc' in 
'allocator' clause inside a target region must be specified in an 
'uses_allocators' clause on the 'target' directive" "" { target c++ } } */
 a  = 5;
 void *prt = omp_alloc(32, my_alloc);
 #pragma omp parallel allocate(allocator(my_alloc) : a) firstprivate(a) /* 
{ dg-error "allocator 'my_alloc' in 'allocate' clause inside a target region 
must be specified in an 'uses_allocators' clause on the 'target' directive" } */
@@ -37,7 +37,7 @@ g (omp_allocator_handle_t my_alloc)
   #pragma omp target uses_allocators(my_alloc)
   {
 int a;
-#pragma omp allocate(a) allocator(my_alloc)  /* { dg-message "sorry, 
unimplemented: '#pragma omp allocate' not yet supported" "" { target c++ } }  */
+#pragma omp allocate(a) allocator(my_alloc)
 a  = 5;
 void *prt = omp_alloc(32, my_alloc);
 #pragma omp parallel allocate(allocator(my_alloc) : a) firstprivate(a)
diff --git a/gcc/testsuite/g++.dg/gomp/allocate-15.C 
b/gcc/testsuite/g++.dg/gomp/allocate-15.C
index 1f86bc42cc8a..88b4c57a742a 100644
--- a/gcc/testsuite/g++.dg/gomp/allocate-15.C
+++ b/gcc/testsuite/g++.dg/gomp/allocate-15.C
@@ -67,7 +67,8 @@
 /* Making a regex for demangled identifiers is actually way harder than making
a regex for mangled ones, too many escapes are needed.  */
 
-/* { dg-final { scan-assembler "\.align 
256\\s*\.type\\s*_ZZZ6f0_256vENKUlvE_clEvE1a" } } */
+/* scan-assembler test fails due to "sorry"; disabled by removing outer {}.  */
+/* dg-final { scan-assembler "\.align 
256\\s*\.type\\s*_ZZZ6f0_256vENKUlvE_clEvE1a" } */
 int* f0_256()
 {
   auto cl = [](){
@@ -77,7 +78,8 @@ int* f0_256()
   };
   return cl();
 }
-/* { dg-final { scan-assembler "\.align 
512\\s*\.type\\s*_ZZZ6f0_512vENKUlvE_clEvE1a" } } */
+/* scan-assembler test fails due to "sorry"; disabled by removing outer {}.  */
+/* dg-final { scan-assembler "\.align 
512\\s*\.type\\s*_ZZZ6f0_512vENKUlvE_clEvE1a" } */
 int* f0_512()
 {
   auto cl = [](){
@@ -87,7 +89,8 @@ int* f0_512()
   };
   return cl();
 }
-/* { dg-final { scan-assembler "\.align 
1024\\s*\.type\\s*_ZZZ7f0_1024vENKUlvE_clEvE1a" } } */
+/* scan-assembler test fails due to "sorry"; disabled by removing outer {}.  */
+/* dg-final { scan-assembler "\.align 
1024\\s*\.type\\s*_ZZZ7f0_1024vENKUlvE_clEvE1a" } */
 int* f0_1024()
 {
   auto cl = [](){
@@ -98,7 +101,8 @@ int* f0_1024()
   return cl();
 }
 
-/* { dg-final { scan-assembler "\.align 
256\\s*\.type\\s*_ZZZ6f1_256IvEPivENKUlvE_clEvE1a" } } */
+/* scan-assembler test fails due to "sorry"; disabled by removing outer {}.  */
+/* dg-final { scan-assembler "\.align 
256\\s*\.type\\s*_ZZZ6f1_256IvEPivENKUlvE_clEvE1a" } */
 template
 int* f1_256()
 {
@@ -111,7 +115,8 @@ int* f1_256()
 }
 template int* f1_256();
 
-/* { dg-final { scan-assembler "\.align 
512\\s*\.type\\s*_ZZZ6f1_512IvEPivENKUlvE_clEvE1a" } } */
+/* scan-assembler test fails due to "sorry"; disabled by removing outer {}.  */
+/* dg-final { scan-assembler "\.align 
512\\s*\.type\\s*_ZZZ6f1_512IvEPivENKUlvE_clEvE1a" } */
 template
 int* f1_512()
 {
@@ -124,7 +129,8 @@ int* f1_512()
 }
 template int* f1_512();
 
-/* { dg-final { sc

[gcc r16-669] Fortran: default-initialization and functions returning derived type [PR85750]

2025-05-15 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:d31ab498b12ebbe4f50acb2aa240ff92c73f310c

commit r16-669-gd31ab498b12ebbe4f50acb2aa240ff92c73f310c
Author: Harald Anlauf 
Date:   Thu May 15 21:07:07 2025 +0200

Fortran: default-initialization and functions returning derived type 
[PR85750]

Functions with non-pointer, non-allocatable result and of derived type did
not always get initialized although the type had default-initialization,
and a derived type component had the allocatable or pointer attribute.
Rearrange the logic when to apply default-initialization.

PR fortran/85750

gcc/fortran/ChangeLog:

* resolve.cc (resolve_symbol): Reorder conditions when to apply
default-initializers.

gcc/testsuite/ChangeLog:

* gfortran.dg/alloc_comp_auto_array_3.f90: Adjust scan counts.
* gfortran.dg/alloc_comp_class_3.f03: Remove bogus warnings.
* gfortran.dg/alloc_comp_class_4.f03: Likewise.
* gfortran.dg/allocate_with_source_14.f03: Adjust scan count.
* gfortran.dg/derived_constructor_comps_6.f90: Likewise.
* gfortran.dg/derived_result_5.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc |   8 +-
 .../gfortran.dg/alloc_comp_auto_array_3.f90|   4 +-
 gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03   |   3 +-
 gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03   |   5 +-
 .../gfortran.dg/allocate_with_source_14.f03|   2 +-
 .../gfortran.dg/derived_constructor_comps_6.f90|   2 +-
 gcc/testsuite/gfortran.dg/derived_result_5.f90 | 123 +
 7 files changed, 134 insertions(+), 13 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index bf1aa704888f..d09aef0a899c 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -18059,16 +18059,16 @@ skip_interfaces:
  || (a->dummy && !a->pointer && a->intent == INTENT_OUT
  && sym->ns->proc_name->attr.if_source != IFSRC_IFBODY))
apply_default_init (sym);
+  else if (a->function && !a->pointer && !a->allocatable && !a->use_assoc
+  && sym->result)
+   /* Default initialization for function results.  */
+   apply_default_init (sym->result);
   else if (a->function && sym->result && a->access != ACCESS_PRIVATE
   && (sym->ts.u.derived->attr.alloc_comp
   || sym->ts.u.derived->attr.pointer_comp))
/* Mark the result symbol to be referenced, when it has allocatable
   components.  */
sym->result->attr.referenced = 1;
-  else if (a->function && !a->pointer && !a->allocatable && !a->use_assoc
-  && sym->result)
-   /* Default initialization for function results.  */
-   apply_default_init (sym->result);
 }
 
   if (sym->ts.type == BT_CLASS && sym->ns == gfc_current_ns
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90 
b/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
index 2af089e84e8d..d0751f3d3eba 100644
--- a/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
@@ -25,6 +25,6 @@ contains
 allocate (array(1)%bigarr)
   end function
 end
-! { dg-final { scan-tree-dump-times "builtin_malloc" 3 "original" } }
+! { dg-final { scan-tree-dump-times "builtin_malloc" 4 "original" } }
 ! { dg-final { scan-tree-dump-times "builtin_free" 3 "original" } }
-! { dg-final { scan-tree-dump-times "while \\(1\\)" 4 "original" } }
+! { dg-final { scan-tree-dump-times "while \\(1\\)" 5 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03 
b/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03
index 0753e33d535d..8202d783621c 100644
--- a/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03
@@ -45,11 +45,10 @@ contains
 type(c), value :: d
   end subroutine
 
-  type(c) function c_init()  ! { dg-warning "not set" }
+  type(c) function c_init()
   end function
 
   subroutine sub(d)
 type(u), value :: d
   end subroutine
 end program test_pr58586
-
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03 
b/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
index 4a55d73b245e..9ff38e3fb7c5 100644
--- a/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
@@ -51,14 +51,14 @@ contains
 type(t), value :: d
   end subroutine
 
-  type(c) function c_init() ! { dg-warning "not set" }
+  type(c) function c_init()
   end function
 
   class(c) function c_init2() ! { dg-warning "not set" }
 allocatable :: c_init2
   end function
 
-  type(c) function d_init(this) ! { dg-warning "not set" }
+  type(c) function d_init(this)
 class(d) :: this
   end function
 
@@ -102,4 +102,3 @@ program test_pr58586
   call add_c(oe%init())
   deallocate(oe)
 end program
-
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_14.f03 

[gcc/devel/omp/gcc-15] Fix strided `target update`

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:2ab0f672c29b875f4c5cb73b3770598981d9dba5

commit 2ab0f672c29b875f4c5cb73b3770598981d9dba5
Author: Paul-Antoine Arras 
Date:   Fri Jun 7 20:29:40 2024 +0200

Fix strided `target update`

OG14 fixup for mainline commit 25072a477a5
"OpenMP: Call cuMemcpy2D/cuMemcpy3D for nvptx for omp_target_memcpy_rect"

libgomp/ChangeLog
* target.c (omp_target_memcpy_rect_worker): Require unit strides
and matching element size.

Diff:
---
 libgomp/target.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libgomp/target.c b/libgomp/target.c
index 66bc5c1b7a20..ae1a31d7505e 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -5266,6 +5266,9 @@ omp_target_memcpy_rect_worker (void *dst, const void 
*src, size_t element_size,
 
   /* host->device, device->host and intra device.  */
   if (num_dims == 2
+  && (!strides || (strides[0] == 1
+  && strides[1] == 1
+  && element_size == span))
   && ((src_devicep
   && src_devicep == dst_devicep
   && src_devicep->memcpy2d_func)
@@ -5292,6 +5295,10 @@ omp_target_memcpy_rect_worker (void *dst, const void 
*src, size_t element_size,
return ret ? 0 : EINVAL;
 }
   else if (num_dims == 3
+  && (!strides || (strides[0] == 1
+   && strides[1] == 1
+   && strides[2] == 1
+   && element_size == span))
   && ((src_devicep
&& src_devicep == dst_devicep
&& src_devicep->memcpy3d_func)


[gcc/devel/omp/gcc-15] libgomp: parallel reverse offload

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:fc4bf7b190ee2db44839c09518ca074c5cef8a3b

commit fc4bf7b190ee2db44839c09518ca074c5cef8a3b
Author: Andrew Stubbs 
Date:   Fri Sep 1 16:49:58 2023 +0100

libgomp: parallel reverse offload

Extend OpenMP reverse offload support to allow running the host kernels
on multiple threads.  The device plugin API for reverse offload is now made
non-blocking, meaning that running the host kernel in the wrong device
context is no longer a problem.  The NVPTX message passing interface now
uses a ring buffer aproximately matching GCN.

libgomp/ChangeLog:

* config/gcn/target.c (GOMP_target_ext): Add "signal" field.
Fix atomics race condition.
* config/nvptx/libgomp-nvptx.h (REV_OFFLOAD_QUEUE_SIZE): New define.
(struct rev_offload): Implement ring buffer.
* config/nvptx/target.c (GOMP_target_ext): Likewise.
* env.c (initialize_env): Read GOMP_REVERSE_OFFLOAD_THREADS.
* libgomp-plugin.c (GOMP_PLUGIN_target_rev): Replace "aq" parameter
with "signal" and "use_aq".
* libgomp-plugin.h (GOMP_PLUGIN_target_rev): Likewise.
* libgomp.h (gomp_target_rev): Likewise.
* plugin/plugin-gcn.c (process_reverse_offload): Add "signal".
(console_output): Pass signal value through.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_openacc_async_construct):
Attach new threads to the numbered device.
Change the flag to CU_STREAM_NON_BLOCKING.
(GOMP_OFFLOAD_run): Implement ring-buffer and remove signalling.
* target.c (gomp_target_rev): Rename to ...
(gomp_target_rev_internal): ... this, and change "dev_num" to
"devicep".
(gomp_target_rev_worker_thread): New function.
(gomp_target_rev): New function (old name).
* libgomp.texi: Document GOMP_REVERSE_OFFLOAD_THREADS.
* testsuite/libgomp.c/reverse-offload-threads-1.c: New test.
* testsuite/libgomp.c/reverse-offload-threads-2.c: New test.

Diff:
---
 libgomp/config/gcn/target.c|  39 --
 libgomp/config/nvptx/libgomp-nvptx.h   |  35 -
 libgomp/config/nvptx/target.c  |  53 +---
 libgomp/env.c  |   6 +
 libgomp/libgomp-plugin.c   |   4 +-
 libgomp/libgomp-plugin.h   |   2 +-
 libgomp/libgomp.h  |   3 +-
 libgomp/libgomp.texi   |  17 +++
 libgomp/plugin/plugin-gcn.c|   8 +-
 libgomp/plugin/plugin-nvptx.c  |  68 --
 libgomp/target.c   | 143 -
 .../libgomp.c/reverse-offload-threads-1.c  |  26 
 .../libgomp.c/reverse-offload-threads-2.c  |  31 +
 13 files changed, 376 insertions(+), 59 deletions(-)

diff --git a/libgomp/config/gcn/target.c b/libgomp/config/gcn/target.c
index 1e98f1d91a17..5327ad3389f4 100644
--- a/libgomp/config/gcn/target.c
+++ b/libgomp/config/gcn/target.c
@@ -122,19 +122,38 @@ GOMP_target_ext (int device, void (*fn) (void *), size_t 
mapnum,
   <= (index - 1024))
   asm ("s_sleep 64");
 
+  /* In theory, it should be enough to write "written" with __ATOMIC_RELEASE,
+ and have the rest of the data flushed to memory automatically, but some
+ devices (gfx908) seem to have a race condition where the flushed data
+ arrives after the atomic data, and the host does the wrong thing.
+ If we just write everything atomically in the correct order then we're
+ safe.  */
+
   unsigned int slot = index % 1024;
-  data->queue[slot].value_u64[0] = (uint64_t) fn;
-  data->queue[slot].value_u64[1] = (uint64_t) mapnum;
-  data->queue[slot].value_u64[2] = (uint64_t) hostaddrs;
-  data->queue[slot].value_u64[3] = (uint64_t) sizes;
-  data->queue[slot].value_u64[4] = (uint64_t) kinds;
-  data->queue[slot].value_u64[5] = (uint64_t) GOMP_ADDITIONAL_ICVS.device_num;
-
-  data->queue[slot].type = 4; /* Reverse offload.  */
+  __atomic_store_n (&data->queue[slot].value_u64[0], (uint64_t) fn,
+   __ATOMIC_RELAXED);
+  __atomic_store_n (&data->queue[slot].value_u64[1], (uint64_t) mapnum,
+   __ATOMIC_RELAXED);
+  __atomic_store_n (&data->queue[slot].value_u64[2], (uint64_t) hostaddrs,
+   __ATOMIC_RELAXED);
+  __atomic_store_n (&data->queue[slot].value_u64[3], (uint64_t) sizes,
+   __ATOMIC_RELAXED);
+  __atomic_store_n (&data->queue[slot].value_u64[4], (uint64_t) kinds,
+   __ATOMIC_RELAXED);
+  __atomic_store_n (&data->queue[slot].value_u64[5],
+   (uint64_t) GOMP_ADDITIONAL_ICVS.device_num,
+   __ATOMIC_RELAXED);
+
+  volatile int signal = 0;
+  __atomic_store_n (&data->queue[slot].value_u64[6], (uint64_t) &

[gcc/devel/omp/gcc-15] OpenMP: Enable 'declare mapper' mappers for 'target update' directives

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:6ffe14f3198140918d10958702281afba863b41b

commit 6ffe14f3198140918d10958702281afba863b41b
Author: Julian Brown 
Date:   Sat Apr 26 18:28:36 2025 +

OpenMP: Enable 'declare mapper' mappers for 'target update' directives

This patch enables use of 'declare mapper' for 'target update' directives,
for each of C, C++ and Fortran.

There are some implementation choices here and some
"read-between-the-lines" consequences regarding this functionality,
as follows:

 * It is possible to invoke a mapper which contains clauses that
   don't make sense for a given 'target update' operation.  E.g. if a
   mapper definition specifies a "from:" mapping and the user does "target
   update to(...)" which triggers that mapper, the resulting map kind
   (OpenMP 5.2, "Table 5.3: Map-Type Decay of Map Type Combinations")
   is "alloc" (and for the inverse case "release").  For such cases,
   an unconditional warning is issued and the map clause in question is
   dropped from the mapper expansion.  (Other choices might be to make
   this an error, or to do the same thing but silently, or warn only
   given some special option.)

 * The array-shaping operator is *permitted* for map clauses within
   'declare mapper' definitions.  That is because such mappers may be used
   for 'target update' directives, where the array-shaping operator is
   permitted.  I think that makes sense, depending on the semantic model
   of how and when substitution is supposed to take place, but I couldn't
   find such behaviour explicitly mentioned in the spec (as of 5.2).
   If the mapper is triggered by a different directive ("omp target",
   "omp target data", etc.), an error will be raised.

Support is also added for the "mapper" modifier on to/from clauses for
all three base languages.

2023-08-10  Julian Brown  

gcc/c-family/
* c-common.h (c_omp_region_type): Add C_ORT_UPDATE and 
C_ORT_OMP_UPDATE
codes.
* c-omp.cc (omp_basic_map_kind_name): New function.
(omp_instantiate_mapper): Add LOC parameter.  Add 'target update'
support.
(c_omp_instantiate_mappers): Add 'target update' support.

gcc/c/
* c-parser.cc (c_parser_omp_variable_list): Support array-shaping
operator in 'declare mapper' definitions.
(c_parser_omp_clause_map): Pass C_ORT_OMP_DECLARE_MAPPER to
c_parser_omp_variable_list in mapper definitions.
(c_parser_omp_clause_from_to): Add parsing for mapper modifier.
(c_parser_omp_target_update): Instantiate mappers.

gcc/cp/
* parser.cc (cp_parser_omp_var_list_no_open): Support array-shaping
operator in 'declare mapper' definitions.
(cp_parser_omp_clause_from_to): Add parsing for mapper modifier.
(cp_parser_omp_clause_map): Pass C_ORT_OMP_DECLARE_MAPPER to
cp_parser_omp_var_list_no_open in mapper definitions.
(cp_parser_omp_target_update): Instantiate mappers.

gcc/fortran/
* openmp.cc (gfc_match_motion_var_list): Add parsing for mapper
modifier.
(gfc_match_omp_clauses): Adjust error handling for changes to
gfc_match_motion_var_list.
(gfc_omp_instantiate_mapper): Add code argument to get proper
location for diagnostic.
(gfc_omp_instantiate_mappers): Adjust for above change.
* trans-openmp.cc (gfc_trans_omp_clauses): Use correct ref for 
update
operations.
(gfc_trans_omp_target_update): Instantiate mappers.

gcc/testsuite/
* c-c++-common/gomp/declare-mapper-17.c: New test.
* c-c++-common/gomp/declare-mapper-19.c: New test.
* gfortran.dg/gomp/declare-mapper-24.f90: New test.
* gfortran.dg/gomp/declare-mapper-26.f90: Uncomment 'target update'
part of test.
* gfortran.dg/gomp/declare-mapper-27.f90: New test.

libgomp/
* testsuite/libgomp.c-c++-common/declare-mapper-18.c: New test.
* testsuite/libgomp.fortran/declare-mapper-25.f90: New test.
* testsuite/libgomp.fortran/declare-mapper-28.f90: New test.

Co-Authored-By: Andrew Stubbs  
Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 

Diff:
---
 gcc/c-family/c-common.h|   4 +-
 gcc/c-family/c-omp.cc  | 117 +--
 gcc/c/c-parser.cc  | 152 ++--
 gcc/cp/parser.cc   | 160 +++--
 gcc/fortran/openmp.cc  | 101 ++---
 gcc/fortran/trans-openmp.cc|  30 ++--
 .../c-c++-common/gomp/declare-mapper-17.c  |  38 ++

[gcc/devel/omp/gcc-15] OpenMP: Allow complete replacement of clause during map/to/from expansion

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:7431820c24b68001c614b26208be9c9f53c712b8

commit 7431820c24b68001c614b26208be9c9f53c712b8
Author: Julian Brown 
Date:   Tue Apr 30 19:21:22 2024 +0200

OpenMP: Allow complete replacement of clause during map/to/from expansion

At present, map/to/from clauses on OpenMP "target" directives may be
expanded into several mapping nodes if they describe array sections with
pointer or reference bases, or similar.  This patch allows the original
clause to be replaced during that expansion, mostly by passing the list
pointer to the node to various functions rather than the node itself.

This is needed by the following patch. There shouldn't be any functional
changes introduced by this patch itself.

2023-09-05  Julian Brown  

gcc/c-family/
* c-common.h (expand_array_base, expand_component_selector,
expand_map_clause): Adjust member declarations.
* c-omp.cc (omp_expand_access_chain): Pass and return pointer to
clause.
(c_omp_address_inspector::expand_array_base): Likewise.
(c_omp_address_inspector::expand_component_selector): Likewise.
(c_omp_address_inspector::expand_map_clause): Likewise.

gcc/c/
* c-typeck.cc (handle_omp_array_sections): Pass pointer to clause to
process instead of clause.
(c_finish_omp_clauses): Update calls to handle_omp_array_sections.
Handle cases where initial clause might be replaced.

gcc/cp/
* semantics.cc (handle_omp_array_sections): Pass pointer to clause
instead of clause.  Add PNEXT return parameter for next clause in 
list
to process.
(finish_omp_clauses): Update calls to handle_omp_array_sections.
Handle cases where initial clause might be replaced.

Diff:
---
 gcc/c-family/c-common.h | 12 
 gcc/c-family/c-omp.cc   | 75 +
 gcc/c/c-typeck.cc   | 45 ++---
 gcc/cp/semantics.cc | 37 +++-
 4 files changed, 98 insertions(+), 71 deletions(-)

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index ac4d794d1858..5713622b10bc 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1407,12 +1407,12 @@ public:
 
   bool maybe_zero_length_array_section (tree);
 
-  tree expand_array_base (tree, vec &, tree, unsigned *,
- c_omp_region_type);
-  tree expand_component_selector (tree, vec &, tree,
- unsigned *, c_omp_region_type);
-  tree expand_map_clause (tree, tree, vec &,
- c_omp_region_type);
+  tree * expand_array_base (tree *, vec &, tree, unsigned *,
+   c_omp_region_type);
+  tree * expand_component_selector (tree *, vec &, tree,
+   unsigned *, c_omp_region_type);
+  tree * expand_map_clause (tree *, tree, vec &,
+   c_omp_region_type);
 };
 
 enum c_omp_directive_kind {
diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 1c70d2c5a527..8ca5954b6290 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -3642,11 +3642,12 @@ 
c_omp_address_inspector::maybe_zero_length_array_section (tree clause)
expression types here, because e.g. you can't have an array of
references.  */
 
-static tree
-omp_expand_access_chain (tree c, tree expr, vec &addr_tokens,
-unsigned *idx, c_omp_region_type ort)
+static tree *
+omp_expand_access_chain (tree *pc, tree expr,
+vec &addr_tokens, unsigned *idx, 
c_omp_region_type ort)
 {
   using namespace omp_addr_tokenizer;
+  tree c = *pc;
   location_t loc = OMP_CLAUSE_LOCATION (c);
   unsigned i = *idx;
   tree c2 = NULL_TREE;
@@ -3689,34 +3690,35 @@ omp_expand_access_chain (tree c, tree expr, 
vec &addr_tokens,
   break;
 
 default:
-  return error_mark_node;
+  return NULL;
 }
 
   if (c2)
 {
   OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
   OMP_CLAUSE_CHAIN (c) = c2;
-  c = c2;
+  pc = &OMP_CLAUSE_CHAIN (c);
 }
 
   *idx = ++i;
 
   if (i < addr_tokens.length ()
   && addr_tokens[i]->type == ACCESS_METHOD)
-return omp_expand_access_chain (c, expr, addr_tokens, idx, ort);
+return omp_expand_access_chain (pc, expr, addr_tokens, idx, ort);
 
-  return c;
+  return pc;
 }
 
 /* Translate "array_base_decl access_method" to OMP mapping clauses.  */
 
-tree
-c_omp_address_inspector::expand_array_base (tree c,
+tree *
+c_omp_address_inspector::expand_array_base (tree *pc,
vec &addr_tokens,
tree expr, unsigned *idx,
c_omp_region_type ort)
 {
   using namespace omp_addr_tokenizer;
+  tree c = *pc;
   location_t loc = OMP_CLAUSE_LOCATION

[gcc/devel/omp/gcc-15] OpenACC 2.7: Connect readonly modifier to points-to analysis

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:ef9bac1dbc7c600372100206995f4a4598475005

commit ef9bac1dbc7c600372100206995f4a4598475005
Author: Chung-Lin Tang 
Date:   Mon Nov 11 17:16:26 2024 +

OpenACC 2.7: Connect readonly modifier to points-to analysis

This patch links the readonly modifier to points-to analysis.

In front-ends, firstprivate pointer clauses are marked with
OMP_CLAUSE_MAP_POINTS_TO_READONLY set true, and later during lowering the
receiver side read of pointer has VAR_POINTS_TO_READONLY set true, which 
later
directs SSA_NAME_POINTS_TO_READONLY_MEMORY set to true during SSA 
conversion.

SSA_NAME_POINTS_TO_READONLY_MEMORY is an already existing flag connected 
with
alias oracle routines in tree-ssa-alias.cc, thus making the 
readonly-modifier
effective in hinting points-to analysis.

Currently have one testcase c-c++-common/goacc/readonly-2.c where we can
demonstrate 'readonly' can avoid a clobber by function call.

This patch is ported from upstream submission:
https://gcc.gnu.org/pipermail/gcc-patches/2024-April/648728.html

gcc/c-family/ChangeLog:

* c-omp.cc (c_omp_address_inspector::expand_array_base):
Set OMP_CLAUSE_MAP_POINTS_TO_READONLY on pointer clause.
(c_omp_address_inspector::expand_component_selector): Likewise.

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_trans_omp_array_section):
Set OMP_CLAUSE_MAP_POINTS_TO_READONLY on pointer clause.

gcc/ChangeLog:

* gimple-expr.cc (copy_var_decl): Copy VAR_POINTS_TO_READONLY
for VAR_DECLs.
* omp-low.cc (lower_omp_target): Set VAR_POINTS_TO_READONLY for
variables of receiver refs.
* tree-pretty-print.cc (dump_omp_clause):
Print OMP_CLAUSE_MAP_POINTS_TO_READONLY.
(dump_generic_node): Print SSA_NAME_POINTS_TO_READONLY_MEMORY.
* tree-ssanames.cc (make_ssa_name_fn): Set
SSA_NAME_POINTS_TO_READONLY_MEMORY if DECL_POINTS_TO_READONLY is 
set.
* tree.h (OMP_CLAUSE_MAP_POINTS_TO_READONLY): New macro.
(VAR_POINTS_TO_READONLY): New macro.

gcc/testsuite/ChangeLog:

* c-c++-common/goacc/readonly-1.c: Adjust testcase.
* c-c++-common/goacc/readonly-2.c: New testcase.
* gfortran.dg/goacc/readonly-1.f90: Adjust testcase.
* gfortran.dg/pr67170.f90: Likewise.

Diff:
---
 gcc/c-family/c-omp.cc  |  4 
 gcc/fortran/trans-openmp.cc|  2 ++
 gcc/gimple-expr.cc |  2 ++
 gcc/omp-low.cc |  2 ++
 gcc/testsuite/c-c++-common/goacc/readonly-1.c  | 20 ++--
 gcc/testsuite/c-c++-common/goacc/readonly-2.c  | 16 
 gcc/testsuite/gfortran.dg/goacc/readonly-1.f90 | 20 ++--
 gcc/testsuite/gfortran.dg/pr67170.f90  |  2 +-
 gcc/tree-pretty-print.cc   |  4 
 gcc/tree-ssanames.cc   |  3 +++
 gcc/tree.h | 11 +++
 11 files changed, 65 insertions(+), 21 deletions(-)

diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 588218d3e1f1..662b79164262 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -4157,6 +4157,8 @@ c_omp_address_inspector::expand_array_base (tree *pc,
 }
   else if (c2)
 {
+  if (OMP_CLAUSE_MAP_READONLY (c))
+   OMP_CLAUSE_MAP_POINTS_TO_READONLY (c2) = 1;
   OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
   OMP_CLAUSE_CHAIN (c) = c2;
   if (implicit_p)
@@ -4346,6 +4348,8 @@ c_omp_address_inspector::expand_component_selector (tree 
*pc,
 }
   else if (c2)
 {
+  if (OMP_CLAUSE_MAP_READONLY (c))
+   OMP_CLAUSE_MAP_POINTS_TO_READONLY (c2) = 1;
   OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
   OMP_CLAUSE_CHAIN (c) = c2;
   pc = &OMP_CLAUSE_CHAIN (c);
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index afe18ecb28bc..521f7ccfff62 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -3408,6 +3408,8 @@ gfc_trans_omp_array_section (stmtblock_t *block, 
toc_directive cd,
   ptr2 = fold_convert (ptrdiff_type_node, ptr2);
   OMP_CLAUSE_SIZE (node3) = fold_build2 (MINUS_EXPR, ptrdiff_type_node,
 ptr, ptr2);
+  if (n->u.map.readonly)
+OMP_CLAUSE_MAP_POINTS_TO_READONLY (node3) = 1;
 }
 
 /* CLAUSES is a list of clauses resulting from an "omp declare mapper"
diff --git a/gcc/gimple-expr.cc b/gcc/gimple-expr.cc
index c0367f490d69..69a5b7e300f0 100644
--- a/gcc/gimple-expr.cc
+++ b/gcc/gimple-expr.cc
@@ -385,6 +385,8 @@ copy_var_decl (tree var, tree name, tree type)
   DECL_CONTEXT (copy) = DECL_CONTEXT (var);
   TREE_USED (copy) = 1;
   DECL_SEEN_IN_BIND_EXPR_P (copy) = 1;
+  if (VAR_P (var))
+VAR_POINTS_TO_READONLY

[gcc/devel/omp/gcc-15] OpenMP: Add flag for code elision to omp_context_selector_matches.

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:203eb6e9c949ebfe3d08a845d641a68955a82b49

commit 203eb6e9c949ebfe3d08a845d641a68955a82b49
Author: Sandra Loosemore 
Date:   Sun Feb 9 21:34:35 2025 +

OpenMP: Add flag for code elision to omp_context_selector_matches.

The "begin declare variant" has different rules for determining
whether a context selector cannot match for purposes of code elision
than we normally use; it excludes the case of a constant false
"condition" selector for the "user" set.

gcc/ChangeLog
* omp-general.cc (omp_context_selector_matches): Add an optional
bool argument for the code elision case.
* omp-general.h (omp_context_selector_matches): Likewise.

Diff:
---
 gcc/omp-general.cc | 28 
 gcc/omp-general.h  |  2 +-
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index cd97f0fdcec4..0eaa43156a5f 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1755,13 +1755,19 @@ omp_construct_traits_match (tree selector_traits, tree 
context_traits,
CONSTRUCT_CONTEXT is known to be complete and not missing constructs
filled in later during compilation.
 
+   If DECLARE_VARIANT_ELISION_P is true, the function implements the test
+   for elision of preprocessed code in "begin declare variant" constructs,
+   and returns 0 only for failure to match traits in the device and
+   implementation sets.
+
Dynamic properties (which are evaluated at run-time) should always
return 1.  */
 
 int
 omp_context_selector_matches (tree ctx,
  tree construct_context,
- bool complete_p)
+ bool complete_p,
+ bool declare_variant_elision_p)
 {
   int ret = 1;
   bool maybe_offloaded = omp_maybe_offloaded (construct_context);
@@ -1773,9 +1779,12 @@ omp_context_selector_matches (tree ctx,
 
   /* Immediately reject the match if there are any ignored
 selectors present.  */
-  for (tree ts = selectors; ts; ts = TREE_CHAIN (ts))
-   if (OMP_TS_CODE (ts) == OMP_TRAIT_INVALID)
- return 0;
+  if (!declare_variant_elision_p
+ || set == OMP_TRAIT_SET_DEVICE
+ || set == OMP_TRAIT_SET_IMPLEMENTATION)
+   for (tree ts = selectors; ts; ts = TREE_CHAIN (ts))
+ if (OMP_TS_CODE (ts) == OMP_TRAIT_INVALID)
+   return 0;
 
   if (set == OMP_TRAIT_SET_CONSTRUCT)
{
@@ -2129,6 +2138,13 @@ omp_context_selector_matches (tree ctx,
  break;
case OMP_TRAIT_USER_CONDITION:
  gcc_assert (set == OMP_TRAIT_SET_USER);
+ /* The spec does not include the "user" set in the things that
+can trigger code elision in "begin declare variant".  */
+ if (declare_variant_elision_p)
+   {
+ ret = -1;
+ break;
+   }
  for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p))
if (OMP_TP_NAME (p) == NULL_TREE)
  {
@@ -2144,6 +2160,10 @@ omp_context_selector_matches (tree ctx,
ret = -1;
  }
  break;
+   case OMP_TRAIT_INVALID:
+ /* This is only for the declare_variant_elision_p case.  */
+ ret = -1;
+ break;
default:
  break;
}
diff --git a/gcc/omp-general.h b/gcc/omp-general.h
index 19a10231b520..1468cdd7e138 100644
--- a/gcc/omp-general.h
+++ b/gcc/omp-general.h
@@ -205,7 +205,7 @@ extern bool omp_check_for_duplicate_variant (location_t loc,
 tree base_decl, tree ctx);
 extern void omp_mark_declare_variant (location_t loc, tree variant,
  tree construct);
-extern int omp_context_selector_matches (tree, tree, bool);
+extern int omp_context_selector_matches (tree, tree, bool, bool = false);
 extern tree omp_merge_context_selectors (location_t, tree, tree,
 enum omp_ctx_directive);
 extern tree resolve_omp_target_device_matches (tree node);


[gcc/devel/omp/gcc-15] OpenMP: Restore lost Fortran testcase for 'omp allocate'

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:67b186d7377b6a0b7ad6a469b3ae9feba192f149

commit 67b186d7377b6a0b7ad6a469b3ae9feba192f149
Author: Tobias Burnus 
Date:   Thu May 1 15:39:42 2025 +

OpenMP: Restore lost Fortran testcase for 'omp allocate'

This testcase, which is present on the OG13 and OG14 branches, was
overlooked when the Fortran support for 'omp allocate' was added to
mainline (commit d4b6d147920b93297e621124a99ed01e7e310d92 from
December 2023).

libgomp/ChangeLog

* testsuite/libgomp.fortran/allocate-8a.f90: New test.

(cherry picked from commit 08ce1b9f6707e00089c4d77d2bb82963d531bb1d)

Diff:
---
 libgomp/testsuite/libgomp.fortran/allocate-8a.f90 | 45 +++
 1 file changed, 45 insertions(+)

diff --git a/libgomp/testsuite/libgomp.fortran/allocate-8a.f90 
b/libgomp/testsuite/libgomp.fortran/allocate-8a.f90
new file mode 100644
index ..5f6c8c1e2717
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/allocate-8a.f90
@@ -0,0 +1,45 @@
+! { dg-additional-options "-fopenmp-allocators" }
+! { dg-additional-options "-fdump-tree-omplower" }
+program main
+  use iso_c_binding
+  use omp_lib
+  implicit none (type, external)
+  integer(omp_allocator_handle_kind):: alloc_h
+  integer :: i, N
+  integer(c_intptr_t) :: intptr
+  integer, allocatable :: A(:)
+  type(omp_alloctrait):: traits(1) = [omp_alloctrait(omp_atk_alignment, 128)]
+
+  N = 10
+  alloc_h = omp_init_allocator(omp_default_mem_space, 1, traits)
+
+  !$omp allocate(A) allocator(alloc_h)
+  allocate(A(N))
+  a(:) = [(i, i=1,N)]
+  if (mod (transfer (loc(a), intptr),128) /= 0) &
+stop 1
+  if (any (a /= [(i, i=1,N)])) &
+stop 2
+  deallocate(A)
+  !$omp allocate(A) allocator(alloc_h) align(512)
+  allocate(A(N))
+  block
+integer, allocatable :: B(:)
+!$omp allocators allocate(allocator(alloc_h), align(256) : B)
+allocate(B(N))
+B(:) = [(2*i, i=1,N)]
+A(:) = B
+if (mod (transfer (loc(B), intptr), 256) /= 0) &
+  stop 1
+! end of scope deallocation
+  end block
+  if (mod (transfer (loc(a), intptr),512) /= 0) &
+stop 1
+  if (any (a /= [(2*i, i=1,N)])) &
+stop 2
+  deallocate(A) ! Must deallocate here - before deallocator is destroyed
+  call omp_destroy_allocator(alloc_h)
+  ! No auto dealloc of A because it is SAVE
+end
+! { dg-final { scan-tree-dump-times "__builtin_GOMP_alloc \\(" 3 "omplower" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(" 3 "omplower" } }


[gcc/devel/omp/gcc-15] OpenMP: C++ front end support for "begin declare variant"

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:295dd6f754aaccacfe1708d962373ed8be3717dc

commit 295dd6f754aaccacfe1708d962373ed8be3717dc
Author: Sandra Loosemore 
Date:   Sun Feb 9 21:34:35 2025 +

OpenMP: C++ front end support for "begin declare variant"

This patch implements C++ support for the "begin declare variant"
construct.  The OpenMP specification is hazy on interaction of this
feature with C++ language features.  Variant functions in classes are
supported but must be defined as members in the class definition,
using an unqualified name for the base function which also must be
present in that class.  Similarly variant functions in a namespace can
only be defined in that namespace using an unqualified name for a base
function already declared in that namespace.  Variants for template
functions or inside template classes seem to (mostly) work.

gcc/cp/ChangeLog
* cp-tree.h (struct cp_omp_declare_variant_attr): New.
(struct saved_scope): Add omp_declare_variant_attribute field.
* decl.cc (omp_declare_variant_finalize_one): Add logic to inject
"this" parameter for method calls.
* parser.cc (cp_parser_skip_to_pragma_omp_end_declare_variant): New.
(omp_start_variant_function): New.
(omp_finish_variant_function): New.
(cp_parser_init_declarator): Handle variant functions.
(cp_parser_class_specifier): Handle deferred lookup of base 
functions
when the entire class has been seen.
(cp_parser_member_declaration): Handle variant functions.
(cp_finish_omp_declare_variant): Merge context selectors if in
a "begin declare variant" block.
(cp_parser_omp_begin): Match "omp begin declare variant".  Adjust
error messages.
(cp_parser_omp_end): Match "omp end declare variant".
* parser.h (struct cp_parser): Add omp_unregistered_variants field.
* semantics.cc (finish_translation_unit): Detect unmatched
"omp begin declare variant".

gcc/testsuite/ChangeLog
* g++.dg/gomp/delim-declare-variant-1.C: New.
* g++.dg/gomp/delim-declare-variant-2.C: New.
* g++.dg/gomp/delim-declare-variant-3.C: New.
* g++.dg/gomp/delim-declare-variant-4.C: New.
* g++.dg/gomp/delim-declare-variant-5.C: New.
* g++.dg/gomp/delim-declare-variant-6.C: New.
* g++.dg/gomp/delim-declare-variant-7.C: New.
* g++.dg/gomp/delim-declare-variant-40.C: New.
* g++.dg/gomp/delim-declare-variant-41.C: New.
* g++.dg/gomp/delim-declare-variant-50.C: New.
* g++.dg/gomp/delim-declare-variant-51.C: New.
* g++.dg/gomp/delim-declare-variant-52.C: New.
* g++.dg/gomp/delim-declare-variant-70.C: New.
* g++.dg/gomp/delim-declare-variant-71.C: New.

libgomp/
* testsuite/libgomp.c++/delim-declare-variant-1.C: New.
* testsuite/libgomp.c++/delim-declare-variant-2.C: New.
* testsuite/libgomp.c++/delim-declare-variant-7.C: New.

Co-Authored-By: Julian Brown 
Co-Authored-By: waffl3x 

Diff:
---
 gcc/cp/cp-tree.h   |   6 +
 gcc/cp/decl.cc |  15 +
 gcc/cp/parser.cc   | 544 +++--
 gcc/cp/parser.h|   5 +
 gcc/cp/semantics.cc|   7 +
 .../g++.dg/gomp/delim-declare-variant-1.C  |  39 ++
 .../g++.dg/gomp/delim-declare-variant-2.C  |  53 ++
 .../g++.dg/gomp/delim-declare-variant-3.C  |  37 ++
 .../g++.dg/gomp/delim-declare-variant-4.C  |  57 +++
 .../g++.dg/gomp/delim-declare-variant-40.C |  51 ++
 .../g++.dg/gomp/delim-declare-variant-41.C |  31 ++
 .../g++.dg/gomp/delim-declare-variant-5.C  |  53 ++
 .../g++.dg/gomp/delim-declare-variant-50.C |  99 
 .../g++.dg/gomp/delim-declare-variant-51.C | 181 +++
 .../g++.dg/gomp/delim-declare-variant-52.C |  24 +
 .../g++.dg/gomp/delim-declare-variant-6.C  |  72 +++
 .../g++.dg/gomp/delim-declare-variant-7.C  |  57 +++
 .../g++.dg/gomp/delim-declare-variant-70.C | 206 
 .../g++.dg/gomp/delim-declare-variant-71.C | 157 ++
 .../libgomp.c++/delim-declare-variant-1.C  |  29 ++
 .../libgomp.c++/delim-declare-variant-2.C  |  37 ++
 .../libgomp.c++/delim-declare-variant-7.C  |  39 ++
 22 files changed, 1766 insertions(+), 33 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index d1e2a28b6ac3..b40f7917aedc 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1924,6 +1924,11 @@ struct GTY(()) cp_omp_begin_assumes_data {
   bool attr_syntax;
 };
 
+struct GTY(()) cp_omp_declare_variant_attr {
+  bool attr_syntax;
+  tree se

[gcc/devel/omp/gcc-15] OpenMP: C front end support for "begin declare variant"

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:d5a1822a5ccaa2ce7c35f04fcdcedfe92e209d84

commit d5a1822a5ccaa2ce7c35f04fcdcedfe92e209d84
Author: Sandra Loosemore 
Date:   Sun Feb 9 21:34:36 2025 +

OpenMP: C front end support for "begin declare variant"

gcc/c/ChangeLog
* c-decl.cc (current_omp_declare_variant_attribute): Define.
* c-lang.h (struct c_omp_declare_variant_attr): Declare.
(current_omp_declare_variant_attribute): Declare.
* c-parser.cc (c_parser_skip_to_pragma_omp_end_declare_variant): 
New.
(c_parser_translation_unit): Check for "omp begin declare variant"
with no matching "end".
(c_parser_declaration_or_fndef): Handle functions in "omp begin
declare variant" block.
(c_finish_omp_declare_variant): Merge context selectors with
surrounding "omp begin declare variant".
(JOIN_STR): Define.
(omp_start_variant_function): New.
(omp_finish_variant_function): New.
(c_parser_omp_begin): Handle "omp begin declare variant".
(c_parser_omp_end): Likewise.

Co-Authored-By: Julian Brown 

Diff:
---
 gcc/c/c-decl.cc   |   3 +
 gcc/c/c-lang.h|   8 ++
 gcc/c/c-parser.cc | 343 --
 3 files changed, 318 insertions(+), 36 deletions(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index b8af1282eab7..00cf95561f15 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -163,6 +163,9 @@ vec 
*current_omp_declare_target_attribute;
we are in.  */
 vec *current_omp_begin_assumes;
 
+/* Vector of "omp begin/end declare variant" blocks we are in.  */
+vec *current_omp_declare_variant_attribute;
+
 /* Vector of loop names with C_DECL_LOOP_NAME or C_DECL_SWITCH_NAME marked
LABEL_DECL as the last and canonical for each loop or switch.  */
 static vec loop_names;
diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
index 4b93d184dbca..cd68fc00e457 100644
--- a/gcc/c/c-lang.h
+++ b/gcc/c/c-lang.h
@@ -72,6 +72,11 @@ struct GTY(()) c_omp_begin_assumes_data {
   bool attr_syntax;
 };
 
+struct GTY(()) c_omp_declare_variant_attr {
+  bool attr_syntax;
+  tree selector;
+};
+
 /* If non-empty, implicit "omp declare target" attribute is added into the
attribute lists.  */
 extern GTY(()) vec
@@ -80,5 +85,8 @@ extern GTY(()) vec
#pragma omp end assumes (and how many times when nested).  */
 extern GTY(()) vec
   *current_omp_begin_assumes;
+/* And similarly for #pragma omp begin/end declare variant.  */
+extern GTY(()) vec
+  *current_omp_declare_variant_attribute;
 
 #endif /* ! GCC_C_LANG_H */
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 00ad86124594..6d607e99a49c 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -1456,6 +1456,55 @@ c_parser_skip_to_pragma_eol (c_parser *parser, bool 
error_if_not_eol = true)
   parser->error = false;
 }
 
+/* Skip tokens up to and including "#pragma omp end declare variant".
+   Properly handle nested "#pragma omp begin declare variant" pragmas.  */
+static void
+c_parser_skip_to_pragma_omp_end_declare_variant (c_parser *parser)
+{
+  for (int depth = 0; depth >= 0; )
+{
+  c_token *token = c_parser_peek_token (parser);
+
+  switch (token->type)
+   {
+   case CPP_PRAGMA_EOL:
+ if (!parser->in_pragma)
+   break;
+ /* FALLTHRU */
+   case CPP_EOF:
+ /* If we've run out of tokens, stop.  */
+ return;
+
+   case CPP_PRAGMA:
+ if ((token->pragma_kind == PRAGMA_OMP_BEGIN
+  || token->pragma_kind == PRAGMA_OMP_END)
+ && c_parser_peek_nth_token (parser, 2)->type == CPP_NAME
+ && c_parser_peek_nth_token (parser, 3)->type == CPP_NAME)
+   {
+ tree id1 = c_parser_peek_nth_token (parser, 2)->value;
+ tree id2 = c_parser_peek_nth_token (parser, 3)->value;
+ if (strcmp (IDENTIFIER_POINTER (id1), "declare") == 0
+ && strcmp (IDENTIFIER_POINTER (id2), "variant") == 0)
+   {
+ if (token->pragma_kind == PRAGMA_OMP_BEGIN)
+   depth++;
+ else
+   depth--;
+   }
+   }
+ c_parser_consume_pragma (parser);
+ c_parser_skip_to_pragma_eol (parser, false);
+ continue;
+
+   default:
+ break;
+   }
+
+  /* Consume the token.  */
+  c_parser_consume_token (parser);
+}
+}
+
 /* Skip tokens until we have consumed an entire block, or until we
have consumed a non-nested ';'.  */
 
@@ -1979,6 +2028,13 @@ c_parser_translation_unit (c_parser *parser)
   "#pragma omp end declare target");
   vec_safe_truncate (current_omp_declare_target_attribute, 0);
 }
+  if (vec_safe_length (current_omp_declare_variant_attribute))
+{
+  if (!errorcount)
+   error ("% without corresponding "
+  "%");
+  vec_safe_truncate (curr

[gcc/devel/omp/gcc-15] openmp: Add support for iterators in 'target update' clauses (C/C++)

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:176d660537b2edc8007a4bed1eb936d881a46277

commit 176d660537b2edc8007a4bed1eb936d881a46277
Author: Kwok Cheung Yeung 
Date:   Wed Nov 27 21:51:34 2024 +

openmp: Add support for iterators in 'target update' clauses (C/C++)

This adds support for iterators in 'to' and 'from' clauses in the
'target update' OpenMP directive.

gcc/c/

* c-parser.cc (c_parser_omp_clause_from_to): Parse 'iterator' 
modifier.
* c-typeck.cc (c_finish_omp_clauses): Finish iterators for to/from
clauses.

gcc/cp/

* parser.cc (cp_parser_omp_clause_from_to): Parse 'iterator' 
modifier.
* semantics.cc (finish_omp_clauses): Finish iterators for to/from
clauses.

gcc/

* gimplify.cc (gimplify_scan_omp_clauses): Add argument for iterator
loop sequence.   Gimplify the clause decl and size into the iterator
loop if iterators are used.
(gimplify_omp_workshare): Add argument for iterator loops sequence
in call to gimplify_scan_omp_clauses.
(gimplify_omp_target_update): Call remove_unused_omp_iterator_vars 
and
build_omp_iterators_loops.  Add loop sequence as argument when 
calling
gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses and building
the Gimple statement.
* tree-pretty-print.cc (dump_omp_clause): Call dump_omp_iterators
for to/from clauses with iterators.
* tree.cc (omp_clause_num_ops): Add extra operand for 
OMP_CLAUSE_FROM
and OMP_CLAUSE_TO.
* tree.h (OMP_CLAUSE_HAS_ITERATORS): Add check for OMP_CLAUSE_TO and
OMP_CLAUSE_FROM.
(OMP_CLAUSE_ITERATORS): Likewise.

gcc/testsuite/

* c-c++-common/gomp/target-update-iterators-1.c: New.
* c-c++-common/gomp/target-update-iterators-2.c: New.
* c-c++-common/gomp/target-update-iterators-3.c: New.

libgomp/

* target.c (gomp_update): Call gomp_merge_iterator_maps.  Free
allocated variables.
* testsuite/libgomp.c-c++-common/target-update-iterators-1.c: New.
* testsuite/libgomp.c-c++-common/target-update-iterators-2.c: New.
* testsuite/libgomp.c-c++-common/target-update-iterators-3.c: New.

Diff:
---
 gcc/c/c-parser.cc  | 55 ++
 gcc/c/c-typeck.cc  |  5 +-
 gcc/cp/parser.cc   | 56 --
 gcc/cp/semantics.cc|  5 +-
 gcc/gimplify.cc| 37 +++-
 .../c-c++-common/gomp/target-update-iterators-1.c  | 20 +++
 .../c-c++-common/gomp/target-update-iterators-2.c  | 23 
 .../c-c++-common/gomp/target-update-iterators-3.c  | 17 ++
 gcc/tree-pretty-print.cc   | 10 
 gcc/tree.cc|  4 +-
 gcc/tree.h |  6 +-
 libgomp/target.c   | 14 +
 .../target-update-iterators-1.c| 65 +
 .../target-update-iterators-2.c| 58 +++
 .../target-update-iterators-3.c| 67 ++
 15 files changed, 404 insertions(+), 38 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 8c85ccee2bd2..f1c7efc4ba32 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20988,8 +20988,11 @@ c_parser_omp_clause_device_type (c_parser *parser, 
tree list)
to ( variable-list )
 
OpenMP 5.1:
-   from ( [present :] variable-list )
-   to ( [present :] variable-list ) */
+   from ( [motion-modifier[,] [motion-modifier[,]...]:] variable-list )
+   to ( [motion-modifier[,] [motion-modifier[,]...]:] variable-list )
+
+   motion-modifier:
+ present | iterator (iterators-definition)  */
 
 static tree
 c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind,
@@ -21001,20 +21004,27 @@ c_parser_omp_clause_from_to (c_parser *parser, enum 
omp_clause_code kind,
 return list;
 
   int pos = 1, colon_pos = 0;
+  int iterator_length = 0;
 
   while (c_parser_peek_nth_token_raw (parser, pos)->type == CPP_NAME)
 {
-  if (c_parser_peek_nth_token_raw (parser, pos + 1)->type == CPP_COMMA)
-   pos += 2;
-  else if (c_parser_peek_nth_token_raw (parser, pos + 1)->type
-  == CPP_OPEN_PAREN)
+  const char *identifier =
+   IDENTIFIER_POINTER (c_parser_peek_nth_token_raw (parser, pos)->value);
+  if (c_parser_peek_nth_token_raw (parser, pos + 1)->type
+ == CPP_OPEN_PAREN)
{
  unsigned int npos = pos + 2;
  if (c_parser_check_balanced_raw_token_sequence (parser, &npos)
-&& (c_parser_peek_nth_token_raw (parser, npos)->type
- 

[gcc/devel/omp/gcc-15] openmp: Refactor handling of iterators

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:4e12ac8efad19d339a2c02efc7595c6f974f2328

commit 4e12ac8efad19d339a2c02efc7595c6f974f2328
Author: Kwok Cheung Yeung 
Date:   Wed Nov 27 21:49:12 2024 +

openmp: Refactor handling of iterators

Move code to calculate the iteration size and to generate the iterator
expansion loop into separate functions.

Use OMP_ITERATOR_DECL_P to check for iterators in clause declarations.

gcc/c-family/

* c-omp.cc (c_finish_omp_depobj): Use OMP_ITERATOR_DECL_P.

gcc/c/

* c-typeck.cc (handle_omp_array_sections): Use OMP_ITERATOR_DECL_P.
(c_finish_omp_clauses): Likewise.

gcc/cp/

* pt.cc (tsubst_omp_clause_decl): Use OMP_ITERATOR_DECL_P.
* semantics.cc (handle_omp_array_sections): Likewise.
(finish_omp_clauses): Likewise.

gcc/

* gimplify.cc (gimplify_omp_affinity): Use OMP_ITERATOR_DECL_P.
(compute_omp_iterator_count): New.
(build_omp_iterator_loop): New.
(gimplify_omp_depend): Use OMP_ITERATOR_DECL_P,
compute_omp_iterator_count and build_omp_iterator_loop.
* tree-inline.cc (copy_tree_body_r): Use OMP_ITERATOR_DECL_P.
* tree-pretty-print.cc (dump_omp_clause): Likewise.
* tree.h (OMP_ITERATOR_DECL_P): New macro.

Diff:
---
 gcc/c-family/c-omp.cc|   4 +-
 gcc/c/c-typeck.cc|  13 +-
 gcc/cp/pt.cc |   4 +-
 gcc/cp/semantics.cc  |   8 +-
 gcc/gimplify.cc  | 321 +++
 gcc/tree-inline.cc   |   5 +-
 gcc/tree-pretty-print.cc |   8 +-
 gcc/tree.h   |   6 +
 8 files changed, 173 insertions(+), 196 deletions(-)

diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 662b79164262..7d333185fdd5 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -764,9 +764,7 @@ c_finish_omp_depobj (location_t loc, tree depobj,
  kind = OMP_CLAUSE_DEPEND_KIND (clause);
  t = OMP_CLAUSE_DECL (clause);
  gcc_assert (t);
- if (TREE_CODE (t) == TREE_LIST
- && TREE_PURPOSE (t)
- && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
+ if (OMP_ITERATOR_DECL_P (t))
{
  error_at (OMP_CLAUSE_LOCATION (clause),
"% modifier may not be specified on "
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 68640ffc26b9..16a26c40c4e5 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -15685,9 +15685,7 @@ handle_omp_array_sections (tree *pc, tree **pnext, enum 
c_omp_region_type ort,
   tree *tp = &OMP_CLAUSE_DECL (c);
   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
|| OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
-  && TREE_CODE (*tp) == TREE_LIST
-  && TREE_PURPOSE (*tp)
-  && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC)
+  && OMP_ITERATOR_DECL_P (*tp))
 tp = &TREE_VALUE (*tp);
   tree first = handle_omp_array_sections_1 (c, *tp, types,
maybe_zero_len, first_non_one,
@@ -17144,9 +17142,7 @@ c_finish_omp_clauses (tree clauses, enum 
c_omp_region_type ort)
  /* FALLTHRU */
case OMP_CLAUSE_AFFINITY:
  t = OMP_CLAUSE_DECL (c);
- if (TREE_CODE (t) == TREE_LIST
- && TREE_PURPOSE (t)
- && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
+ if (OMP_ITERATOR_DECL_P (t))
{
  if (TREE_PURPOSE (t) != last_iterators)
last_iterators_remove
@@ -17248,10 +17244,7 @@ c_finish_omp_clauses (tree clauses, enum 
c_omp_region_type ort)
  break;
}
}
- if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
- && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
- && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
- == TREE_VEC))
+ if (OMP_ITERATOR_DECL_P (OMP_CLAUSE_DECL (c)))
TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
  else
OMP_CLAUSE_DECL (c) = t;
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index e2041b8ce6e8..54f1b3f2942c 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -17861,9 +17861,7 @@ tsubst_omp_clause_decl (tree decl, tree args, 
tsubst_flags_t complain,
 return decl;
 
   /* Handle OpenMP iterators.  */
-  if (TREE_CODE (decl) == TREE_LIST
-  && TREE_PURPOSE (decl)
-  && TREE_CODE (TREE_PURPOSE (decl)) == TREE_VEC)
+  if (OMP_ITERATOR_DECL_P (decl))
 {
   tree ret;
   if (iterator_cache[0] == TREE_PURPOSE (decl))
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 196eb9fd8c07..2e70e59588a0 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -6389,9 +6389,7 @@ handle_omp_array_sections (tree *pc, tree **pnext, enum 
c_omp_region_type ort,
   tree *tp = &OMP_CLAUSE_DECL (c);
   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
|| OMP_CLAU

[gcc/devel/omp/gcc-15] OpenACC: array reductions bug fixes

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:a6682e7af891700ae67e7d0f5d3fcc462eb44609

commit a6682e7af891700ae67e7d0f5d3fcc462eb44609
Author: Chung-Lin Tang 
Date:   Fri May 2 00:33:07 2025 +

OpenACC: array reductions bug fixes

This is a merge of the v4 to v5 diff patch from:
https://gcc.gnu.org/pipermail/gcc-patches/2025-March/679682.html

This patch fixes issues found for NVPTX sm_70 testing, and another issue
related to copying to reduction buffer for worker/vector mode.

gcc/ChangeLog:

* config/gcn/gcn-tree.cc (gcn_goacc_reduction_setup): Fix array case
copy source into reduction buffer.
* config/nvptx/nvptx.cc (nvptx_expand_shared_addr): Move default 
size
init setting place.
(enum nvptx_builtins): Add NVPTX_BUILTIN_BAR_WARPSYNC.
(nvptx_init_builtins): Add DEF() of nvptx_builtin_bar_warpsync.
(nvptx_expand_builtin): Expand NVPTX_BUILTIN_BAR_WARPSYNC.
(nvptx_goacc_reduction_setup): Fix array case copy source into 
reduction
buffer.
(nvptx_goacc_reduction_fini): Add bar.warpsync for at end of 
vector-mode
reductions for sm_70 and above.

libgomp/ChangeLog:

* testsuite/libgomp.oacc-c-c++-common/reduction-arrays-2.c: Adjust 
test.
* testsuite/libgomp.oacc-c-c++-common/reduction-arrays-3.c: 
Likewise.
* testsuite/libgomp.oacc-c-c++-common/reduction-arrays-4.c: 
Likewise.
* testsuite/libgomp.oacc-c-c++-common/reduction-arrays-5.c: 
Likewise.

Diff:
---
 gcc/config/gcn/gcn-tree.cc |  3 +-
 gcc/config/nvptx/nvptx.cc  | 32 --
 .../libgomp.oacc-c-c++-common/reduction-arrays-2.c | 24 
 .../libgomp.oacc-c-c++-common/reduction-arrays-3.c | 24 
 .../libgomp.oacc-c-c++-common/reduction-arrays-4.c | 24 
 .../libgomp.oacc-c-c++-common/reduction-arrays-5.c | 24 
 6 files changed, 122 insertions(+), 9 deletions(-)

diff --git a/gcc/config/gcn/gcn-tree.cc b/gcc/config/gcn/gcn-tree.cc
index 87c42671a687..c3349d6fd6f4 100644
--- a/gcc/config/gcn/gcn-tree.cc
+++ b/gcc/config/gcn/gcn-tree.cc
@@ -750,13 +750,14 @@ gcn_goacc_reduction_setup (gcall *call)
   tree offset = gimple_call_arg (call, 5);
   if (array_p)
{
+ tree copy_src = !integer_zerop (ref_to_res) ? ref_to_res : array_addr;
  tree decl = gcn_goacc_get_worker_array_reduction_buffer
(array_type, array_max_idx, &seq);
  tree ptr = make_ssa_name (TREE_TYPE (array_addr));
  gimplify_assign (ptr, build_fold_addr_expr (decl), &seq);
 
  /* Store incoming value to worker reduction buffer.  */
- oacc_build_array_copy (ptr, array_addr, array_max_idx, &seq);
+ oacc_build_array_copy (ptr, copy_src, array_max_idx, &seq);
}
   else
{
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index ba40a8472281..115d34f6dfb3 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -6516,16 +6516,16 @@ nvptx_expand_shared_addr (tree exp, rtx target,
   if (TREE_CONSTANT (size_expr))
 size = TREE_INT_CST_LOW (size_expr);
 
+  /* Default size for unknown size expression.  */
+  if (size == 0)
+size = 256;
+
   if (vector)
 {
   offload_attrs oa;
 
   populate_offload_attrs (&oa);
 
-  /* Default size for unknown size expression.  */
-  if (size == 0)
-   size = 256;
-
   unsigned int psize = ROUND_UP (size + offset, align);
   unsigned int pnum = nvptx_mach_max_workers ();
   vector_red_partition = MAX (vector_red_partition, psize);
@@ -6621,6 +6621,7 @@ enum nvptx_builtins
   NVPTX_BUILTIN_BAR_RED_AND,
   NVPTX_BUILTIN_BAR_RED_OR,
   NVPTX_BUILTIN_BAR_RED_POPC,
+  NVPTX_BUILTIN_BAR_WARPSYNC,
   NVPTX_BUILTIN_BREV,
   NVPTX_BUILTIN_BREVLL,
   NVPTX_BUILTIN_COND_UNI,
@@ -6753,6 +6754,8 @@ nvptx_init_builtins (void)
   DEF (BAR_RED_POPC, "bar_red_popc",
(UINT, UINT, UINT, UINT, UINT, NULL_TREE));
 
+  DEF (BAR_WARPSYNC, "bar_warpsync", (VOID, VOID, NULL_TREE));
+
   DEF (BREV, "brev", (UINT, UINT, NULL_TREE));
   DEF (BREVLL, "brevll", (LLUINT, LLUINT, NULL_TREE));
 
@@ -6803,6 +6806,10 @@ nvptx_expand_builtin (tree exp, rtx target, rtx 
ARG_UNUSED (subtarget),
 case NVPTX_BUILTIN_BAR_RED_POPC:
   return nvptx_expand_bar_red (exp, target, mode, ignore);
 
+case NVPTX_BUILTIN_BAR_WARPSYNC:
+  emit_insn (gen_nvptx_warpsync ());
+  return NULL_RTX;
+
 case NVPTX_BUILTIN_BREV:
 case NVPTX_BUILTIN_BREVLL:
   return nvptx_expand_brev (exp, target, mode, ignore);
@@ -7774,11 +7781,11 @@ nvptx_goacc_reduction_setup (gcall *call, offload_attrs 
*oa)
 
   push_gimplify_context (true);
 
+  /* Copy the receiver object.  */
+  tree ref_to_res = gimple_call_arg (call, 1);
+
   if (level != GOMP_DIM_GANG)
 {
-  /* Copy the receiver objec

[gcc/devel/omp/gcc-15] OpenMP: Support functions for nested "begin declare variant"

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:e0a386fae63d349e347ac7394bd15e54cc5e8e11

commit e0a386fae63d349e347ac7394bd15e54cc5e8e11
Author: Sandra Loosemore 
Date:   Sun Feb 9 21:34:35 2025 +

OpenMP: Support functions for nested "begin declare variant"

This patch adds functions for variant name mangling and context selector
merging that are shared by the C and C++ front ends.

The OpenMP specification says that name mangling is supposed to encode
the context selector for the variant, but also provides for no way to
reference these functions directly by name or from a different
compilation unit.  It also gives no guidance on how dynamic selectors
might be encoded across compilation units.

The GCC implementation of this feature instead treats variant
functions as if they have no linkage and uses a simple counter to
generate names.

gcc/ChangeLog
* omp-general.cc (omp_mangle_variant_name): New.
(omp_check_for_duplicate_variant): New.
(omp_copy_trait_set): New.
(omp_trait_selectors_equivalent): New.
(omp_combine_trait_sets): New.
(omp_merge_context_selectors): New.
* omp-general.h (omp_mangle_variant_name): Declare.
(omp_check_for_duplicate_variant): Declare.
(omp_merge_context_selectors): Declare.

Diff:
---
 gcc/omp-general.cc | 194 +
 gcc/omp-general.h  |   5 ++
 2 files changed, 199 insertions(+)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 5818ac618e9c..cd97f0fdcec4 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1521,6 +1521,66 @@ omp_check_context_selector (location_t loc, tree ctx,
   return ctx;
 }
 
+/* Produce a mangled version of BASE_ID for the name of the variant
+   function with context selector CTX.  SEP is a separator string.
+   The return value is an IDENTIFIER_NODE.
+
+   Per the OpenMP spec, "the symbol names of two definitions of a function are
+   considered to be equal if and only if their effective context selectors are
+   equivalent".  However, if we did have two such definitions, we'd get an ODR
+   violation.  We already take steps in the front ends to make variant
+   functions internal to the compilation unit, since there is no (portable) way
+   to reference them directly by name or declare them as extern in another
+   compilation unit.  So, we can diagnose the would-be ODR violations by
+   checking that there is not already a variant for the same function with an
+   equivalent context selector, and otherwise just use a simple counter to name
+   the variant functions instead of any complicated scheme to encode the
+   context selector in the name.  */
+
+tree
+omp_mangle_variant_name (tree base_id, tree ctx ATTRIBUTE_UNUSED,
+const char *sep)
+{
+  const char *base_name = IDENTIFIER_POINTER (base_id);
+
+  /* Now do the actual mangling.  */
+  static int variant_counter;
+  /* The numeric suffix and terminating byte ought to need way less than
+ 32 bytes extra, that's just a magic number.  */
+  size_t buflen = (strlen (base_name) + strlen (sep) + strlen ("ompvariant")
+  + 32);
+  char *buffer = (char *) alloca (buflen);
+  snprintf (buffer, buflen, "%s%sompvariant%d", base_name, sep,
+   ++variant_counter);
+  return get_identifier (buffer);
+}
+
+/* Forward declaration.  */
+static int omp_context_selector_compare (tree ctx1, tree ctx2);
+
+/* Diagnose an error if there is already a variant with CTX registered
+   for BASE_DECL.  Returns true if OK, false otherwise.  */
+bool
+omp_check_for_duplicate_variant (location_t loc, tree base_decl, tree ctx)
+{
+  for (tree attr = DECL_ATTRIBUTES (base_decl); attr; attr = TREE_CHAIN (attr))
+{
+  attr = lookup_attribute ("omp declare variant base", attr);
+  if (attr == NULL_TREE)
+   break;
+
+  tree selector = TREE_VALUE (TREE_VALUE (attr));
+  if (omp_context_selector_compare (ctx, selector) == 0)
+   {
+ error_at (loc,
+   "Multiple definitions of variants with the same "
+   "context selector violate the one-definition rule");
+ return false;
+   }
+}
+  return true;
+}
+
 /* Forward declarations.  */
 static int omp_context_selector_set_compare (enum omp_tss_code, tree, tree);
 static int omp_construct_simd_compare (tree, tree, bool);
@@ -4989,3 +5049,137 @@ omp_maybe_apply_loop_xforms (tree *expr_p, tree 
for_clauses)
 }
 }
 
+/* The next group of functions support merging of context selectors for
+   nested "begin declare variant" directives.  The spec says:
+
+ ...the effective context selectors of the outer directive are
+ appended to the context selector of the inner directive to form the
+ effective context selector of the inner directive.  If a
+ trait-set-selector is present on both directives, the trait-selector
+ list of 

[gcc/devel/omp/gcc-15] OpenMP: C/C++ common testcases for "omp begin declare variant"

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:3dfe9733eabd74f21999dde36166bdedc5d06b1c

commit 3dfe9733eabd74f21999dde36166bdedc5d06b1c
Author: Sandra Loosemore 
Date:   Sun Feb 9 21:34:36 2025 +

OpenMP: C/C++ common testcases for "omp begin declare variant"

gcc/testsuite/ChangeLog
* c-c++-common/gomp/delim-declare-variant-1.c: New.
* c-c++-common/gomp/delim-declare-variant-2.c: New.
* c-c++-common/gomp/delim-declare-variant-3.c: New.
* c-c++-common/gomp/delim-declare-variant-4.c: New.
* c-c++-common/gomp/delim-declare-variant-5.c: New.
* c-c++-common/gomp/delim-declare-variant-6.c: New.
* c-c++-common/gomp/delim-declare-variant-7.c: New.

libgomp/ChangeLog
* testsuite/libgomp.c-c++-common/delim-declare-variant-1.c: New.

Diff:
---
 .../c-c++-common/gomp/delim-declare-variant-1.c| 55 +
 .../c-c++-common/gomp/delim-declare-variant-2.c| 66 
 .../c-c++-common/gomp/delim-declare-variant-3.c| 50 +++
 .../c-c++-common/gomp/delim-declare-variant-4.c| 31 ++
 .../c-c++-common/gomp/delim-declare-variant-5.c| 26 
 .../c-c++-common/gomp/delim-declare-variant-6.c| 71 ++
 .../c-c++-common/gomp/delim-declare-variant-7.c| 27 
 .../libgomp.c-c++-common/delim-declare-variant-1.c | 45 ++
 8 files changed, 371 insertions(+)

diff --git a/gcc/testsuite/c-c++-common/gomp/delim-declare-variant-1.c 
b/gcc/testsuite/c-c++-common/gomp/delim-declare-variant-1.c
new file mode 100644
index ..28cac0d65503
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/delim-declare-variant-1.c
@@ -0,0 +1,55 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-gimple" } */
+
+/* Check basic functionality for the delimited form of "declare variant"
+   - no error re duplicate definitions
+   - variants are registered and correctly resolved at call site.  */
+
+int foo (int a)
+{
+  return a;
+}
+
+int bar (int x)
+{
+  return x;
+}
+
+#pragma omp begin declare variant match (construct={target})
+int foo (int a)
+{
+  return a + 1;
+}
+
+int bar (int x)
+{
+  return x * 2;
+}
+#pragma omp end declare variant
+
+/* Because of the high score value, this variant for "bar" should always be
+   selected even when the one above also matches.  */
+#pragma omp begin declare variant match 
(implementation={vendor(score(1):"gnu")})
+int bar (int x)
+{
+  return x * 4;
+}
+#pragma omp end declare variant
+
+int main (void)
+{
+  if (foo (42) != 42) __builtin_abort ();
+  if (bar (3) != 12) __builtin_abort ();
+#pragma omp target
+  {
+if (foo (42) != 43) __builtin_abort ();
+if (bar (3) != 12) __builtin_abort ();
+  }
+}
+
+/* { dg-final { scan-tree-dump-times "omp declare variant base 
\\(foo.ompvariant." 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "omp declare variant base 
\\(bar.ompvariant." 2 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "foo \\(42\\)" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "foo\\.ompvariant. \\(42\\)" 1 "gimple" } 
} */
+/* { dg-final { scan-tree-dump-times "bar \\(3\\)" 0 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "bar\\.ompvariant. \\(3\\)" 2 "gimple" } 
} */
diff --git a/gcc/testsuite/c-c++-common/gomp/delim-declare-variant-2.c 
b/gcc/testsuite/c-c++-common/gomp/delim-declare-variant-2.c
new file mode 100644
index ..03bfe2746268
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/delim-declare-variant-2.c
@@ -0,0 +1,66 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-foffload=disable -fdump-tree-original" } */
+
+/* Check for elision of preprocessed code in a begin/end declare variant
+   construct when it can be determined at parse time that the selector
+   can never match.  */
+
+int foobar (int x, int y)
+{
+  return x * y;
+}
+
+int baz (int x)
+{
+  return x;
+}
+
+#pragma omp begin declare variant match (implementation={vendor("acme")}) /* { 
dg-warning "unknown property" } */
+int foobar (int x, int y)
+{
+  random junk that would ordinarily cause a parse error;
+  return x + y;
+}
+#pragma omp end declare variant
+
+#pragma omp begin declare variant match (device={kind(fpga)})
+int foobar (int x, int y)
+{
+  random junk that would ordinarily cause a parse error;
+  return x + y;
+}
+#pragma omp end declare variant
+
+/* Per the OpenMP specification, elision only happens when the implementation
+   or device selectors cannot match; the user/condition selector doesn't
+   matter for this.  */
+#pragma omp begin declare variant match (user={condition (0)})
+int foobar (int x, int y)
+{
+  return x + y;
+}
+#pragma omp end declare variant
+
+/* Check that we're finding the right "omp end declare variant" when
+   constructs are nested.  */
+#pragma omp begin declare variant match (implementation={vendor("acme")})  /* 
{ dg-warning "unknown property" } */
+  #pragma omp begin declare variant match 

[gcc/devel/omp/gcc-15] OpenACC: Improve implicit mapping for non-lexically nested offload regions: Adjust cherry-picked tes

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:f6c5e4c0c695cc7a41376a920350827d54755d1c

commit f6c5e4c0c695cc7a41376a920350827d54755d1c
Author: Thomas Schwinge 
Date:   Wed Apr 16 21:52:53 2025 +0200

OpenACC: Improve implicit mapping for non-lexically nested offload regions: 
Adjust cherry-picked test cases

Adjust cherry-picked test cases per
OG14 commit b918a7e4b4bdf070bfa9ede48ef9d22f89ff7795
"OpenACC: Improve implicit mapping for non-lexically nested offload regions"
(in combination with
OG14 commit 5fb2987d33c7296543fa7b8dbeab597fc552b110
"Clarify 'OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P' in 
'gcc/tree-pretty-print.cc:dump_omp_clause'"
(cherry picked from trunk commit d6e66e7b3a40315ad303344e19bccb4006c51cac)).

libgomp/
* testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C: Adjust.
* testsuite/libgomp.oacc-c++/exceptions-throw-3.C: Likewise.
* testsuite/libgomp.oacc-c++/pr119692-1-1.C: Likewise.
* testsuite/libgomp.oacc-c++/pr119692-1-2.C: Likewise.
* testsuite/libgomp.oacc-c++/pr119692-1-3.C: Likewise.

Diff:
---
 libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C | 2 +-
 libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C| 2 +-
 libgomp/testsuite/libgomp.oacc-c++/pr119692-1-1.C  | 2 +-
 libgomp/testsuite/libgomp.oacc-c++/pr119692-1-2.C  | 2 +-
 libgomp/testsuite/libgomp.oacc-c++/pr119692-1-3.C  | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C 
b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C
index 4fa419f245fc..e9372fa95273 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C
+++ b/libgomp/testsuite/libgomp.oacc-c++/exceptions-bad_cast-3.C
@@ -44,6 +44,6 @@ int main()
   }
 }
 
-/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
map\(tofrom:_ZTI2C2 \[len: [0-9]+\]\) map\(tofrom:_ZTI2C1 \[len: [0-9]+\]\) 
map\(tofrom:_ZTV2C1 \[len: [0-9]+\]\)$} gimple { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
map\(tofrom:_ZTI2C2 \[len: [0-9]+\] \[runtime_implicit\]\) map\(tofrom:_ZTI2C1 
\[len: [0-9]+\] \[runtime_implicit\]\) map\(tofrom:_ZTV2C1 \[len: [0-9]+\] 
\[runtime_implicit\]\)$} gimple { xfail *-*-* } } } */
 
 /* { dg-final { scan-tree-dump-times {gimple_call <__cxa_bad_cast, } 1 
optimized } } */
diff --git a/libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C 
b/libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C
index 74a62b3abfac..6664f800e697 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C
+++ b/libgomp/testsuite/libgomp.oacc-c++/exceptions-throw-3.C
@@ -37,7 +37,7 @@ int main()
   }
 }
 
-/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
map\(tofrom:_ZTI11MyException \[len: [0-9]+\]\)$} gimple { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
map\(tofrom:_ZTI11MyException \[len: [0-9]+\] \[runtime_implicit\]\)$} gimple { 
xfail *-*-* } } } */
 
 /* { dg-final { scan-tree-dump-times {gimple_call <__cxa_allocate_exception, } 
1 optimized } }
{ dg-final { scan-tree-dump-times {gimple_call <__cxa_throw, } 1 optimized 
} } */
diff --git a/libgomp/testsuite/libgomp.oacc-c++/pr119692-1-1.C 
b/libgomp/testsuite/libgomp.oacc-c++/pr119692-1-1.C
index 5c3e037f5911..4a876f74f1fa 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/pr119692-1-1.C
+++ b/libgomp/testsuite/libgomp.oacc-c++/pr119692-1-1.C
@@ -39,4 +39,4 @@ int main()
   }
 }
 
-/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
map\(tofrom:_ZTI2C2 \[len: [0-9]+\]\) map\(tofrom:_ZTI2C1 \[len: [0-9]+\]\) 
map\(tofrom:_ZTV2C1 \[len: [0-9]+\]\)$} gimple { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
map\(tofrom:_ZTI2C2 \[len: [0-9]+\] \[runtime_implicit\]\) map\(tofrom:_ZTI2C1 
\[len: [0-9]+\] \[runtime_implicit\]\) map\(tofrom:_ZTV2C1 \[len: [0-9]+\] 
\[runtime_implicit\]\)$} gimple { xfail *-*-* } } } */
diff --git a/libgomp/testsuite/libgomp.oacc-c++/pr119692-1-2.C 
b/libgomp/testsuite/libgomp.oacc-c++/pr119692-1-2.C
index 207b183163ff..052e423ca08e 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/pr119692-1-2.C
+++ b/libgomp/testsuite/libgomp.oacc-c++/pr119692-1-2.C
@@ -9,4 +9,4 @@
 
 /* { dg-bogus {using 'vector_length \(32\)', ignoring 1} {} { target 
openacc_nvidia_accel_selected xfail *-*-* } 0 } */
 
-/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
default\(none\) map\(tofrom:_ZTI2C2 \[len: [0-9]+\]\) map\(tofrom:_ZTI2C1 
\[len: [0-9]+\]\) map\(tofrom:_ZTV2C1 \[len: [0-9]+\]\)$} gimple { xfail *-*-* 
} } } */
+/* { dg-final { scan-tree-dump-not {(?n)#pragma omp target oacc_serial 
default\(none\) map\(tofrom:_ZTI2C2 \[len: [0-9]+\] \[runtime_implicit\]\) 
map\(tofrom:_ZTI2C1 \[len: [0-9]+\] \[runtime_implicit\]\) map\(tofrom:_ZTV2C1 
\[len: [0-9]+\] \[runtim

[gcc/devel/omp/gcc-15] Use OpenACC code to process OpenMP target regions

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:8258d04ad7aaed6b6017da313ca14fcfdc512e7d

commit 8258d04ad7aaed6b6017da313ca14fcfdc512e7d
Author: Chung-Lin Tang 
Date:   Sat Apr 19 21:11:34 2025 +

Use OpenACC code to process OpenMP target regions

(forward ported from devel/omp/gcc-12)

This is a backport of:
https://gcc.gnu.org/pipermail/gcc-patches/2023-May/619003.html

This patch implements '-fopenmp-target=acc', which enables internally 
handling
a subset of OpenMP target regions as OpenACC parallel regions. This 
basically
includes target, teams, parallel, distribute, for/do constructs, and 
atomics.

Essentially, we adjust the internal kinds to OpenACC type, and let OpenACC 
code
paths handle them, with various needed adjustments throughout middle-end and
nvptx backend. When using this "OMPACC" mode, if there are cases the patch
doesn't handle, it issues a warning, and reverts to normal processing for 
that
target region.

gcc/ChangeLog:

* builtins.cc (expand_builtin_omp_builtins): New function.
(expand_builtin): Add expand cases for BUILT_IN_GOMP_BARRIER,
BUILT_IN_OMP_GET_THREAD_NUM, BUILT_IN_OMP_GET_NUM_THREADS,
BUILT_IN_OMP_GET_TEAM_NUM, and BUILT_IN_OMP_GET_NUM_TEAMS using
expand_builtin_omp_builtins, enabled under -fopenmp-target=acc.
* cgraphunit.cc (analyze_functions): Add call to
omp_ompacc_attribute_tagging, enabled under -fopenmp-target=acc.
* common.opt (fopenmp-target=): Add new option and enums.
* config/nvptx/mkoffload.cc (main): Handle -fopenmp-target=.
* config/nvptx/nvptx-protos.h (nvptx_expand_omp_get_num_threads): 
New
prototype.
(nvptx_mem_shared_p): Likewise.
* config/nvptx/nvptx.cc (omp_num_threads_sym): New global static RTX
symbol for number of threads in team.
(omp_num_threads_align): New var for alignment of 
omp_num_threads_sym.
(need_omp_num_threads): New bool for if any function references
omp_num_threads_sym.
(nvptx_option_override): Initialize omp_num_threads_sym/align.
(write_as_kernel): Disable normal OpenMP kernel entry under OMPACC 
mode.
(nvptx_declare_function_name): Disable shim function under OMPACC 
mode.
Disable soft-stack under OMPACC mode. Add generation of neutering 
init
code under OMPACC mode.
(nvptx_output_set_softstack): Return "" under OMPACC mode.
(nvptx_expand_call): Set parallelism to vector for function calls 
with
"ompacc for" attached.
(nvptx_expand_oacc_fork): Set mode to GOMP_DIM_VECTOR under OMPACC 
mode.
(nvptx_expand_oacc_join): Likewise.
(nvptx_expand_omp_get_num_threads): New function.
(nvptx_mem_shared_p): New function.
(nvptx_mach_max_workers): Return 1 under OMPACC mode.
(nvptx_mach_vector_length): Return 32 under OMPACC mode.
(nvptx_single): Add adjustments for OMPACC mode, which have
parallel-construct fork/joins, and regions of code where neutering 
is
dynamically determined.
(nvptx_reorg): Enable neutering under OMPACC mode when "ompacc for"
attribute is attached to function. Disable uniform-simt when under
OMPACC mode.
(nvptx_file_end): Write __nvptx_omp_num_threads out when needed.
(nvptx_goacc_fork_join): Return true under OMPACC mode.
* config/nvptx/nvptx.h (struct GTY(()) machine_function): Add
omp_parallel_predicate and omp_fn_entry_num_threads_reg fields.
* config/nvptx/nvptx.md (unspecv): Add UNSPECV_GET_TID,
UNSPECV_GET_NTID, UNSPECV_GET_CTAID, UNSPECV_GET_NCTAID,
UNSPECV_OMP_PARALLEL_FORK, UNSPECV_OMP_PARALLEL_JOIN entries.
(nvptx_shared_mem_operand): New predicate.
(gomp_barrier): New expand pattern.
(omp_get_num_threads): New expand pattern.
(omp_get_num_teams): New insn pattern.
(omp_get_thread_num): Likewise.
(omp_get_team_num): Likewise.
(get_ntid): Likewise.
(nvptx_omp_parallel_fork): Likewise.
(nvptx_omp_parallel_join): Likewise.

* expr.cc (expand_expr_real_1): Call expand_var_decl target hook.
* flag-types.h (omp_target_mode_kind): New flag value enum.
* gimplify.cc (struct gimplify_omp_ctx): Add 'bool ompacc' field.
(gimplify_scan_omp_clauses): Handle OMP_CLAUSE__OMPACC_.
(gimplify_adjust_omp_clauses): Likewise.
(gimplify_omp_ctx_ompacc_p): New function.
(gimplify_omp_for): Handle combined loops under OMPACC.

* lto-wrapper.cc (append_compiler_options): Add OPT_fopenmp_target_.
* omp-builtins.def (BUILT_IN_OMP_GET_THREAD

[gcc/devel/omp/gcc-15] OpenMP: Expand "declare mapper" mappers for target {enter, exit, } data directives

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:214479eb07f025b7721172420b2c18fd5c797edf

commit 214479eb07f025b7721172420b2c18fd5c797edf
Author: Julian Brown 
Date:   Tue Apr 22 02:50:59 2025 +

OpenMP: Expand "declare mapper" mappers for target {enter,exit,} data 
directives

This patch allows 'declare mapper' mappers to be used on 'omp target
data', 'omp target enter data' and 'omp target exit data' directives.
For each of these, only explicit mappings are supported, unlike for
'omp target' directives where implicit uses of variables inside an
offload region might trigger mappers also.

Each of C, C++ and Fortran are supported.

The patch also adjusts 'map kind decay' to match OpenMP 5.2 semantics,
which is particularly important with regard to 'exit data' operations.

2023-07-06  Julian Brown  

gcc/c-family/
* c-common.h (c_omp_region_type): Add C_ORT_EXIT_DATA,
C_ORT_OMP_EXIT_DATA.
(c_omp_instantiate_mappers): Add region type parameter.
* c-omp.cc (omp_split_map_kind, omp_join_map_kind,
omp_map_decayed_kind): New functions.
(omp_instantiate_mapper): Add ORT parameter.  Implement map kind 
decay
for instantiated mapper clauses.
(c_omp_instantiate_mappers): Add ORT parameter, pass to
omp_instantiate_mapper.

gcc/c/
* c-parser.cc (c_parser_omp_target_data): Instantiate mappers for
'omp target data'.
(c_parser_omp_target_enter_data): Instantiate mappers for 'omp 
target
enter data'.
(c_parser_omp_target_exit_data): Instantiate mappers for 'omp target
exit data'.
(c_parser_omp_target): Add c_omp_region_type argument to
c_omp_instantiate_mappers call.
* c-tree.h (c_omp_instantiate_mappers): Remove spurious prototype.

gcc/cp/
* parser.cc (cp_parser_omp_target_data): Instantiate mappers for 
'omp
target data'.
(cp_parser_omp_target_enter_data): Instantiate mappers for 'omp 
target
enter data'.
(cp_parser_omp_target_exit_data): Instantiate mappers for 'omp 
target
exit data'.
(cp_parser_omp_target): Add c_omp_region_type argument to
c_omp_instantiate_mappers call.
* pt.cc (tsubst_omp_clauses): Instantiate mappers for OMP regions 
other
than just C_ORT_OMP_TARGET.
(tsubst_expr): Update call to tsubst_omp_clauses for 
OMP_TARGET_UPDATE,
OMP_TARGET_ENTER_DATA, OMP_TARGET_EXIT_DATA stanza.
* semantics.cc (cxx_omp_map_array_section): Avoid calling
build_array_ref for non-array/non-pointer bases (error reported
already).

gcc/fortran/
* trans-openmp.cc (omp_split_map_op, omp_join_map_op,
omp_map_decayed_kind): New functions.
(gfc_trans_omp_instantiate_mapper): Add CD parameter.  Implement map
kind decay.
(gfc_trans_omp_instantiate_mappers): Add CD parameter.  Pass to 
above
function.
(gfc_trans_omp_target_data): Instantiate mappers for 'omp target 
data'.
(gfc_trans_omp_target_enter_data): Instantiate mappers for 'omp 
target
enter data'.
(gfc_trans_omp_target_exit_data): Instantiate mappers for 'omp 
target
exit data'.

gcc/testsuite/
* c-c++-common/gomp/declare-mapper-15.c: New test.
* c-c++-common/gomp/declare-mapper-16.c: New test.
* g++.dg/gomp/declare-mapper-1.C: Adjust expected scan output.
* gfortran.dg/gomp/declare-mapper-22.f90: New test.
* gfortran.dg/gomp/declare-mapper-23.f90: New test.

Diff:
---
 gcc/c-family/c-common.h|   2 +-
 gcc/c-family/c-omp.cc  | 193 ++-
 gcc/c/c-parser.cc  |  11 +-
 gcc/c/c-tree.h |   1 -
 gcc/cp/parser.cc   |  15 +-
 gcc/cp/pt.cc   |   8 +-
 gcc/cp/semantics.cc|   5 +-
 gcc/fortran/trans-openmp.cc| 209 +++--
 .../c-c++-common/gomp/declare-mapper-15.c  |  59 ++
 .../c-c++-common/gomp/declare-mapper-16.c  |  39 
 gcc/testsuite/g++.dg/gomp/declare-mapper-1.C   |   2 +-
 .../gfortran.dg/gomp/declare-mapper-22.f90 |  60 ++
 .../gfortran.dg/gomp/declare-mapper-23.f90 |  25 +++
 13 files changed, 593 insertions(+), 36 deletions(-)

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index d784ba38d9e6..ac4d794d1858 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1347,7 +1347,7 @@ extern void c_omp_mark_declare_variant (location_t, tree, 
tree);
 extern void c_omp_adjust_map_cl

[gcc/devel/omp/gcc-15] openmp: Add support for iterators in map clauses (C/C++)

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:4756123b29d183da7f57533d4ef67c6361fb2a79

commit 4756123b29d183da7f57533d4ef67c6361fb2a79
Author: Kwok Cheung Yeung 
Date:   Sat May 3 20:24:26 2025 +

openmp: Add support for iterators in map clauses (C/C++)

This adds preliminary support for iterators in map clauses within OpenMP
'target' constructs (which includes constructs such as 'target enter data').

Iterators with non-constant loop bounds are not currently supported.

gcc/c/

* c-parser.cc (c_parser_omp_clause_map): Parse 'iterator' modifier.
* c-typeck.cc (c_finish_omp_clauses): Finish iterators.  Apply
iterators to generated clauses.

gcc/cp/

* parser.cc (cp_parser_omp_clause_map): Parse 'iterator' modifier.
* semantics.cc (finish_omp_clauses): Finish iterators.  Apply
iterators to generated clauses.

gcc/

* gimple-pretty-print.cc (dump_gimple_omp_target): Print expanded
iterator loops.
* gimple.cc (gimple_build_omp_target): Add argument for iterator
loops sequence.  Initialize iterator loops field.
* gimple.def (GIMPLE_OMP_TARGET): Set GSS symbol to GSS_OMP_TARGET.
* gimple.h (gomp_target): Set GSS symbol to GSS_OMP_TARGET.  Add 
extra
field for iterator loops.
(gimple_build_omp_target): Add argument for iterator loops sequence.
(gimple_omp_target_iterator_loops): New.
(gimple_omp_target_iterator_loops_ptr): New.
(gimple_omp_target_set_iterator_loops): New.
* gimplify.cc (find_var_decl): New.
(copy_omp_iterator): New.
(remap_omp_iterator_var_1): New.
(remap_omp_iterator_var): New.
(remove_unused_omp_iterator_vars): New.
(struct iterator_loop_info_t): New type.
(iterator_loop_info_map_t): New type.
(build_omp_iterators_loops): New.
(enter_omp_iterator_loop_context_1): New.
(enter_omp_iterator_loop_context): New.
(enter_omp_iterator_loop_context): New.
(exit_omp_iterator_loop_context): New.
(gimplify_adjust_omp_clauses): Add argument for iterator loop
sequence.  Gimplify the clause decl and size into the iterator
loop if iterators are used.
(gimplify_omp_workshare): Call remove_unused_omp_iterator_vars and
build_omp_iterators_loops for OpenMP target expressions.  Add
loop sequence as argument when calling gimplify_adjust_omp_clauses
and building the Gimple statement.
* gimplify.h (enter_omp_iterator_loop_context): New prototype.
(exit_omp_iterator_loop_context): New prototype.
* gsstruct.def (GSS_OMP_TARGET): New.
* omp-low.cc (lower_omp_map_iterator_expr): New.
(lower_omp_map_iterator_size): New.
(finish_omp_map_iterators): New.
(lower_omp_target): Add sorry if iterators used with deep mapping.
Call lower_omp_map_iterator_expr before assigning to sender ref.
Call lower_omp_map_iterator_size before setting the size.  Insert
iterator loop sequence before the statements for the target clause.
* tree-nested.cc (convert_nonlocal_reference_stmt): Walk the 
iterator
loop sequence of OpenMP target statements.
(convert_local_reference_stmt): Likewise.
(convert_tramp_reference_stmt): Likewise.
* tree-pretty-print.cc (dump_omp_iterators): Dump extra iterator
information if present.
(dump_omp_clause): Call dump_omp_iterators for iterators in map
clauses.
* tree.cc (omp_clause_num_ops): Add operand for OMP_CLAUSE_MAP.
(walk_tree_1): Do not walk last operand of OMP_CLAUSE_MAP.
* tree.h (OMP_CLAUSE_HAS_ITERATORS): New.
(OMP_CLAUSE_ITERATORS): New.

gcc/testsuite/

* c-c++-common/gomp/map-6.c (foo): Amend expected error message.
* c-c++-common/gomp/target-map-iterators-1.c: New.
* c-c++-common/gomp/target-map-iterators-2.c: New.
* c-c++-common/gomp/target-map-iterators-3.c: New.
* c-c++-common/gomp/target-map-iterators-4.c: New.

libgomp/

* target.c (kind_to_name): New.
(gomp_merge_iterator_maps): New.
(gomp_map_vars_internal): Call gomp_merge_iterator_maps.  Copy
address of only the first iteration to target vars.  Free allocated
variables.
* testsuite/libgomp.c-c++-common/target-map-iterators-1.c: New.
* testsuite/libgomp.c-c++-common/target-map-iterators-2.c: New.
* testsuite/libgomp.c-c++-common/target-map-iterators-3.c: New.

Co-authored-by: Andrew Stubbs 

Diff:
---
 gcc/c/c-parser.cc 

[gcc/devel/omp/gcc-15] OpenMP: Support accelerated 2D/3D memory copies for AMD GCN [OG14-only part]

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:5f7678f015bb31a5aef0ea4f801a3fcff2e85050

commit 5f7678f015bb31a5aef0ea4f801a3fcff2e85050
Author: Julian Brown 
Date:   Wed Sep 13 13:31:48 2023 +

OpenMP: Support accelerated 2D/3D memory copies for AMD GCN [OG14-only part]

This patch only adds the bits missing from mainline:

Support is also added for 1-dimensional strided accesses: these are
treated as a special case of 2-dimensional transfers, where the innermost
dimension is formed from the stride length (in bytes).

2023-09-19  Julian Brown  

libgomp/
* target.c (omp_target_memcpy_rect_worker): Add 1D strided transfer
support.

Diff:
---
 libgomp/target.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/libgomp/target.c b/libgomp/target.c
index 8e811bfcce96..66bc5c1b7a20 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -5215,6 +5215,37 @@ omp_target_memcpy_rect_worker (void *dst, const void 
*src, size_t element_size,
   if (__builtin_mul_overflow (span, strides[0], &stride))
return EINVAL;
 
+  if (((src_devicep && src_devicep->memcpy2d_func)
+  || (dst_devicep && dst_devicep->memcpy2d_func))
+ && (stride % element_size) == 0)
+   {
+ /* Try using memcpy2d for a 1-dimensional strided access.  Here we
+treat the transfer as a 2-dimensional array, where the inner
+dimension is calculated to be (stride in bytes) / element_size.
+Indices/offsets are adjusted so the source/destination pointers
+point to the first element to be transferred, to make the sums
+easier.  (There are some configurations of 2D strided accesses
+that memcpy3d could handle similarly, but those are probably rare
+and are unimplemented for now.)   */
+
+ /* If stride is element size, this is a contiguous transfer and
+should have been handled above.  */
+ assert (stride > element_size);
+
+ int dst_id = dst_devicep ? dst_devicep->target_id : -1;
+ int src_id = src_devicep ? src_devicep->target_id : -1;
+ void *subarray_src = (char *) src + src_off;
+ void *subarray_dst = (char *) dst + dst_off;
+
+ struct gomp_device_descr *devp = dst_devicep ? dst_devicep
+  : src_devicep;
+ ret = devp->memcpy2d_func (dst_id, src_id, element_size, volume[0],
+subarray_dst, 0, 0, stride, subarray_src,
+0, 0, stride);
+ if (ret != -1)
+   return ret ? 0 : EINVAL;
+   }
+
   for (i = 0, ret = 1; i < volume[0] && ret; i++)
{
  if (src_devicep == NULL)


[gcc/devel/omp/gcc-15] openmp: Add macros for iterator element access

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:c97eaee945deaddfc5c14a2ef6102ff5599a91f3

commit c97eaee945deaddfc5c14a2ef6102ff5599a91f3
Author: Kwok Cheung Yeung 
Date:   Sat May 3 20:38:10 2025 +

openmp: Add macros for iterator element access

gcc/c/

* c-parser.cc (c_parser_omp_iterators): Use macros for accessing
iterator elements.
(c_parser_omp_clause_affinity): Likewise.
(c_parser_omp_clause_depend): Likewise.
(c_parser_omp_clause_map): Likewise.
(c_parser_omp_clause_from_to): Likewise.
* c-typeck.cc (c_omp_finish_iterators): Likewise.

gcc/cp/

* parser.cc (cp_parser_omp_iterators): Use macros for accessing
iterator elements.
(cp_parser_omp_clause_affinity): Likewise.
(cp_parser_omp_clause_depend): Likewise.
(cp_parser_omp_clause_from_to): Likewise.
(cp_parser_omp_clause_map): Likewise.
* semantics.cc (cp_omp_finish_iterators): Likewise.

gcc/fortran/

* trans-openmp.cc (gfc_trans_omp_array_section): Use macros for
accessing iterator elements.
(handle_iterator): Likewise.
(gfc_trans_omp_clauses): Likewise.

gcc/

* gimplify.cc (gimplify_omp_affinity): Use macros for accessing
iterator elements.
(compute_omp_iterator_count): Likewise.
(build_omp_iterator_loop): Likewise.
(remove_unused_omp_iterator_vars): Likewise.
(build_omp_iterators_loops): Likewise.
(enter_omp_iterator_loop_context_1): Likewise.
(extract_base_bit_offset): Likewise.
* omp-low.cc (lower_omp_map_iterator_expr): Likewise.
(lower_omp_map_iterator_size): Likewise.
(allocate_omp_iterator_elems): Likewise.
(free_omp_iterator_elems): Likewise.
* tree-inline.cc (copy_tree_body_r): Likewise.
* tree-pretty-print.cc (dump_omp_iterators): Likewise.
* tree.h (OMP_ITERATORS_VAR, OMP_ITERATORS_BEGIN, OMP_ITERATORS_END,
OMP_ITERATORS_STEP, OMP_ITERATORS_ORIG_STEP, OMP_ITERATORS_BLOCK,
OMP_ITERATORS_LABEL, OMP_ITERATORS_INDEX, OMP_ITERATORS_ELEMS,
OMP_ITERATORS_COUNT, OMP_ITERATORS_EXPANDED_P): New macros.

Diff:
---
 gcc/c/c-parser.cc   | 16 +-
 gcc/c/c-typeck.cc   | 24 +++---
 gcc/cp/parser.cc| 16 +-
 gcc/cp/semantics.cc | 26 +++
 gcc/fortran/trans-openmp.cc | 38 +++---
 gcc/gimplify.cc | 78 ++---
 gcc/omp-low.cc  | 17 +-
 gcc/tree-inline.cc  |  4 +--
 gcc/tree-pretty-print.cc| 20 ++--
 gcc/tree.h  | 13 
 10 files changed, 133 insertions(+), 119 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index f1c7efc4ba32..8a5b4932dbcb 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20202,10 +20202,10 @@ c_parser_omp_iterators (c_parser *parser)
   pushdecl (iter_var);
 
   *last = make_tree_vec (6);
-  TREE_VEC_ELT (*last, 0) = iter_var;
-  TREE_VEC_ELT (*last, 1) = begin;
-  TREE_VEC_ELT (*last, 2) = end;
-  TREE_VEC_ELT (*last, 3) = step;
+  OMP_ITERATORS_VAR (*last) = iter_var;
+  OMP_ITERATORS_BEGIN (*last) = begin;
+  OMP_ITERATORS_END (*last) = end;
+  OMP_ITERATORS_STEP (*last) = step;
   last = &TREE_CHAIN (*last);
 
   if (c_parser_next_token_is (parser, CPP_COMMA))
@@ -20270,7 +20270,7 @@ c_parser_omp_clause_affinity (c_parser *parser, tree 
list)
   tree block = pop_scope ();
   if (iterators != error_mark_node)
{
- TREE_VEC_ELT (iterators, 5) = block;
+ OMP_ITERATORS_BLOCK (iterators) = block;
  for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
OMP_CLAUSE_DECL (c) = build_tree_list (iterators,
   OMP_CLAUSE_DECL (c));
@@ -20387,7 +20387,7 @@ c_parser_omp_clause_depend (c_parser *parser, tree list)
  if (iterators == error_mark_node)
iterators = NULL_TREE;
  else
-   TREE_VEC_ELT (iterators, 5) = block;
+   OMP_ITERATORS_BLOCK (iterators) = block;
}
 
   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
@@ -20723,7 +20723,7 @@ c_parser_omp_clause_map (c_parser *parser, tree list, 
enum gomp_map_kind kind)
   if (iterators == error_mark_node)
iterators = NULL_TREE;
   else
-   TREE_VEC_ELT (iterators, 5) = block;
+   OMP_ITERATORS_BLOCK (iterators) = block;
 }
 
   for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
@@ -21169,7 +21169,7 @@ c_parser_omp_clause_from_to (c_parser *parser, enum 
omp_clause_code kind,
   if (iterators == error_mark_node)
iterators = NULL_TREE;
   else
-   TREE_VEC_ELT (iterators, 5) = 

[gcc/devel/omp/gcc-15] OpenACC 2.7: update references to supported version to 2.7/201811.

2025-05-15 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:cd09bc9e3c240154095200ef38eea2bdf7de4ebf

commit cd09bc9e3c240154095200ef38eea2bdf7de4ebf
Author: Chung-Lin Tang 
Date:   Fri Apr 11 08:46:12 2025 +

OpenACC 2.7: update references to supported version to 2.7/201811.

2025-04-11  Chung-Lin Tang  

gcc/c-family/ChangeLog:

* c-cppbuiltin.cc (c_cpp_builtins): Updated _OPENACC to "201811"
for OpenACC 2.7.

gcc/ChangeLog
* doc/extend.texi:  Adjust version references to 2.7 from 2.6.

gcc/fortran/ChangeLog:

* cpp.cc (cpp_define_builtins): Updated _OPENACC to "201811"
for OpenACC 2.7.
* intrinsic.texi (OpenACC Module OPENACC): Adjust version
references to 2.7 from 2.6.

gcc/testsuite/ChangeLog:

* c-c++-common/cpp/openacc-define-3.c: Adjust test.
* gfortran.dg/openacc-define-3.f90: Adjust test.

libgomp/ChangeLog:

* acc_prof.h (_ACC_PROF_INFO_VERSION): Adjust to 201811.
* libgomp.texi (Enabling OpenACC): Adjust version
references to 2.7 from 2.6.
* openacc.f90 (module openacc): Adjust openacc_version to 201811.
* openacc_lib.h (openacc_version): Adjust openacc_version to 201811.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-version-1.c:
Adjust test value to 201811.
* testsuite/libgomp.oacc-fortran/openacc_version-1.f: Adjust
test value to 201811.
* testsuite/libgomp.oacc-fortran/openacc_version-2.f90: Likewise.

Co-Authored-By: Sandra Loosemore 

Diff:
---
 gcc/c-family/c-cppbuiltin.cc | 2 +-
 gcc/doc/extend.texi  | 2 +-
 gcc/fortran/cpp.cc   | 2 +-
 gcc/fortran/intrinsic.texi   | 6 +++---
 gcc/testsuite/c-c++-common/cpp/openacc-define-3.c| 2 +-
 gcc/testsuite/gfortran.dg/openacc-define-3.f90   | 2 +-
 libgomp/acc_prof.h   | 6 --
 libgomp/libgomp.texi | 8 
 libgomp/openacc.f90  | 2 +-
 libgomp/openacc_lib.h| 2 +-
 libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-version-1.c | 2 +-
 libgomp/testsuite/libgomp.oacc-fortran/openacc_version-1.f   | 2 +-
 libgomp/testsuite/libgomp.oacc-fortran/openacc_version-2.f90 | 2 +-
 13 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index 4589ee4a3a62..15596dbfa545 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1631,7 +1631,7 @@ c_cpp_builtins (cpp_reader *pfile)
 cpp_define (pfile, "__SSP__=1");
 
   if (flag_openacc)
-cpp_define (pfile, "_OPENACC=201711");
+cpp_define (pfile, "_OPENACC=201811");
 
   if (flag_openmp)
 cpp_define (pfile, "_OPENMP=201511");
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 0978c4c41b25..ec68c85e2b7b 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -10695,7 +10695,7 @@ influence run-time behavior.
 
 GCC strives to be compatible with the
 @uref{https://www.openacc.org/, OpenACC Application Programming
-Interface v2.6}.
+Interface v2.7}.
 
 To enable the processing of OpenACC directives @samp{#pragma acc}
 in C and C++, GCC needs to be invoked with the @option{-fopenacc} option.
diff --git a/gcc/fortran/cpp.cc b/gcc/fortran/cpp.cc
index 1b7042056460..ffddee43a37f 100644
--- a/gcc/fortran/cpp.cc
+++ b/gcc/fortran/cpp.cc
@@ -172,7 +172,7 @@ cpp_define_builtins (cpp_reader *pfile)
   cpp_define (pfile, "_LANGUAGE_FORTRAN=1");
 
   if (flag_openacc)
-cpp_define (pfile, "_OPENACC=201711");
+cpp_define (pfile, "_OPENACC=201811");
 
   if (flag_openmp)
 cpp_define (pfile, "_OPENMP=201511");
diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi
index 8c160e58b00a..a7171bf31957 100644
--- a/gcc/fortran/intrinsic.texi
+++ b/gcc/fortran/intrinsic.texi
@@ -15787,7 +15787,7 @@ The following scalar integer named constants are of the 
kind
 @section OpenACC Module @code{OPENACC}
 @table @asis
 @item @emph{Standard}:
-OpenACC Application Programming Interface v2.6
+OpenACC Application Programming Interface v2.7
 @end table
 
 
@@ -15801,9 +15801,9 @@ are listed below.
 
 For details refer to the actual
 @uref{https://www.openacc.org/,
-OpenACC Application Programming Interface v2.6}.
+OpenACC Application Programming Interface v2.7}.
 
 @code{OPENACC} provides the scalar default-integer
 named constant @code{openacc_version} with a value of the form
 @var{mm}, where @code{} is the year and @var{mm} the month
-of the OpenACC version; for OpenACC v2.6 the value is @code{201711}.
+of the OpenACC version; for OpenACC v2.7 the

[gcc r16-647] libstdc++: Fix preprocessor check for __float128 formatter [PR119246]

2025-05-15 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:d010a39b9e788a1b3c58e0954c1b2c6afad8210a

commit r16-647-gd010a39b9e788a1b3c58e0954c1b2c6afad8210a
Author: Tomasz Kamiński 
Date:   Thu May 15 08:58:09 2025 +0200

libstdc++: Fix preprocessor check for __float128 formatter [PR119246]

The previous check `_GLIBCXX_FORMAT_F128 != 1` was passing if
_GLIBCXX_FORMAT_F128 was not defined, i.e. evaluted to zero.

This broke sparc-sun-solaris2.11 and x86_64-darwin.

PR libstdc++/119246

libstdc++-v3/ChangeLog:

* include/std/format: Updated check for _GLIBCXX_FORMAT_F128.

Diff:
---
 libstdc++-v3/include/std/format | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index f0b0252255d3..bfda5895e0c0 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -2973,7 +2973,7 @@ namespace __format
 };
 #endif
 
-#if defined(__SIZEOF_FLOAT128__) && _GLIBCXX_FORMAT_F128 != 1
+#if defined(__SIZEOF_FLOAT128__) && _GLIBCXX_FORMAT_F128 > 1
   // Reuse __formatter_fp::format<__format::__flt128_t, Out> for __float128.
   // This formatter is not declared if _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT is 
true,
   // as __float128 when present is same type as __ieee128, which may be same as


[gcc r16-648] OpenMP/Fortran: Fix allocatable-component mapping of derived-type array comps

2025-05-15 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:f99017c3125f4400cf6a098cf5b33d32fe3e6645

commit r16-648-gf99017c3125f4400cf6a098cf5b33d32fe3e6645
Author: Tobias Burnus 
Date:   Thu May 15 09:15:21 2025 +0200

OpenMP/Fortran: Fix allocatable-component mapping of derived-type array 
comps

The check whether the location expression in map clause has allocatable
components was failing for some derived-type array expressions such as
  map(var%tiles(1))
as the compiler produced
  _4 = var.tiles;
  MEMREF(_4, _5);
This commit now also handles this case.

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_omp_deep_mapping_do): Handle SSA_NAME if
a def_stmt is available.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/alloc-comp-4.f90: New test.

Diff:
---
 gcc/fortran/trans-openmp.cc| 20 ++
 libgomp/testsuite/libgomp.fortran/alloc-comp-4.f90 | 75 ++
 2 files changed, 95 insertions(+)

diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 0b8150fb9777..2a48d4af5276 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -2478,6 +2478,26 @@ gfc_omp_deep_mapping_do (bool is_cnt, const gimple *ctx, 
tree clause,
   else
 while (TREE_CODE (tmp) == COMPONENT_REF || TREE_CODE (tmp) == ARRAY_REF)
   tmp = TREE_OPERAND (tmp, TREE_CODE (tmp) == COMPONENT_REF ? 1 : 0);
+  if (TREE_CODE (tmp) == MEM_REF)
+tmp = TREE_OPERAND (tmp, 0);
+  if (TREE_CODE (tmp) == SSA_NAME)
+{
+  gimple *def_stmt = SSA_NAME_DEF_STMT (tmp);
+  if (gimple_code (def_stmt) == GIMPLE_ASSIGN)
+   {
+ tmp = gimple_assign_rhs1 (def_stmt);
+ if (poly)
+   {
+ tmp = TYPE_FIELDS (type);
+ type = TREE_TYPE (tmp);
+   }
+ else
+   while (TREE_CODE (tmp) == COMPONENT_REF
+  || TREE_CODE (tmp) == ARRAY_REF)
+ tmp = TREE_OPERAND (tmp,
+ TREE_CODE (tmp) == COMPONENT_REF ? 1 : 0);
+   }
+}
   /* If the clause argument is nonallocatable, skip is-allocate check. */
   if (GFC_DECL_GET_SCALAR_ALLOCATABLE (tmp)
   || GFC_DECL_GET_SCALAR_POINTER (tmp)
diff --git a/libgomp/testsuite/libgomp.fortran/alloc-comp-4.f90 
b/libgomp/testsuite/libgomp.fortran/alloc-comp-4.f90
new file mode 100644
index ..d5e982ba1a81
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/alloc-comp-4.f90
@@ -0,0 +1,75 @@
+!
+! Check that mapping with map(var%tiles(1)) works.
+!
+! This uses deep mapping to handle the allocatable
+! derived-type components
+!
+! The tricky part is that GCC generates intermittently
+! an SSA_NAME that needs to be resolved.
+!
+module m
+type t
+ integer, allocatable :: den1(:,:), den2(:,:)
+end type t
+
+type t2
+ type(t), allocatable :: tiles(:)
+end type t2
+end
+
+use m
+use iso_c_binding
+implicit none (type, external)
+type(t2), target :: var
+logical :: is_self_map
+type(C_ptr) :: pden1, pden2, ptiles, ptiles1
+
+allocate(var%tiles(1))
+var%tiles(1)%den1 = reshape([1,2,3,4],[2,2])
+var%tiles(1)%den2 = reshape([11,22,33,44],[2,2])
+
+ptiles = c_loc(var%tiles)
+ptiles1 = c_loc(var%tiles(1))
+pden1 = c_loc(var%tiles(1)%den1)
+pden2 = c_loc(var%tiles(1)%den2)
+
+
+is_self_map = .false.
+!$omp target map(to: is_self_map)
+  is_self_map = .true.
+!$omp end target
+
+!$omp target enter data map(var%tiles(1))
+
+!$omp target firstprivate(ptiles, ptiles1, pden1, pden2)
+ if (any (var%tiles(1)%den1 /= reshape([1,2,3,4],[2,2]))) stop 1
+ if (any (var%tiles(1)%den2 /= reshape([11,22,33,44],[2,2]))) stop 2
+ var%tiles(1)%den1 = var%tiles(1)%den1 + 5
+ var%tiles(1)%den2 = var%tiles(1)%den2 + 7
+
+ if (is_self_map) then
+   if (.not. c_associated (ptiles, c_loc(var%tiles))) stop 3
+   if (.not. c_associated (ptiles1, c_loc(var%tiles(1 stop 4
+   if (.not. c_associated (pden1, c_loc(var%tiles(1)%den1))) stop 5
+   if (.not. c_associated (pden2, c_loc(var%tiles(1)%den2))) stop 6
+ else
+   if (c_associated (ptiles, c_loc(var%tiles))) stop 3
+   if (c_associated (ptiles1, c_loc(var%tiles(1 stop 4
+   if (c_associated (pden1, c_loc(var%tiles(1)%den1))) stop 5
+   if (c_associated (pden2, c_loc(var%tiles(1)%den2))) stop 6
+ endif
+!$omp end target
+
+if (is_self_map) then
+  if (any (var%tiles(1)%den1 /= 5 + reshape([1,2,3,4],[2,2]))) stop 7
+  if (any (var%tiles(1)%den2 /= 7 + reshape([11,22,33,44],[2,2]))) stop 8
+else
+  if (any (var%tiles(1)%den1 /= reshape([1,2,3,4],[2,2]))) stop 7
+  if (any (var%tiles(1)%den2 /= reshape([11,22,33,44],[2,2]))) stop 8
+endif
+
+!$omp target exit data map(var%tiles(1))
+
+if (any (var%tiles(1)%den1 /= 5 + reshape([1,2,3,4],[2,2]))) stop 7
+if (any (var%tiles(1)%den2 /= 7 + reshape([11,22,33,44],[2,2]))) stop 8
+end


[gcc r16-660] cobol: Don't display 0xFF HIGH-VALUE characters in testcases. [PR120251]

2025-05-15 Thread Robert Dubner via Gcc-cvs
https://gcc.gnu.org/g:022d8e25e49021b378a4e6c24c2f0c380a066690

commit r16-660-g022d8e25e49021b378a4e6c24c2f0c380a066690
Author: Robert Dubner 
Date:   Thu May 15 12:01:12 2025 -0400

cobol: Don't display 0xFF HIGH-VALUE characters in testcases. [PR120251]

The tests were displaying 0xFF characters, and the resulting generated
output changed with the system locale.  The check_88 test was modified
so that the regex comparisons ignore those character positions. Two
of the other tests were changed to output hexadecimal rather than
character strings.

There is one new test, and the other inspect testcases were edited to
remove an unimportant back-apostrophe that had found its way into the
source code sequence number area.

gcc/testsuite/ChangeLog:

PR cobol/120251
* cobol.dg/group1/check_88.cob: Ignore characters above 0x80.
* 
cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.cob:
Output HIGH-VALUE as hex, rather than as characters.
* 
cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.out:
Likewise.
* cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.cob: 
Typo.
* cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.out: 
Likewise.
* cobol.dg/group2/INSPECT_ISO_Example_1.cob: Likewise.
* cobol.dg/group2/INSPECT_ISO_Example_2.cob: Likewise.
* cobol.dg/group2/INSPECT_ISO_Example_3.cob: Likewise.
* cobol.dg/group2/INSPECT_ISO_Example_4.cob: Likewise.
* cobol.dg/group2/INSPECT_ISO_Example_5-f.cob: Likewise.
* cobol.dg/group2/INSPECT_ISO_Example_6.cob: Likewise.
* cobol.dg/group2/INSPECT_ISO_Example_7.cob: Likewise.
* 
cobol.dg/group2/Multiple_INDEXED_BY_variables_with_the_same_name.cob: New test.
* 
cobol.dg/group2/Multiple_INDEXED_BY_variables_with_the_same_name.out: New test.

Diff:
---
 gcc/testsuite/cobol.dg/group1/check_88.cob | 12 +--
 ...CATE_Rule_8_OPTION_INITIALIZE_with_figconst.cob |  3 ++-
 ...CATE_Rule_8_OPTION_INITIALIZE_with_figconst.out |  3 +--
 .../INSPECT_CONVERTING_TO_figurative_constants.cob | 12 +--
 .../INSPECT_CONVERTING_TO_figurative_constants.out | 10 -
 .../cobol.dg/group2/INSPECT_ISO_Example_1.cob  |  2 +-
 .../cobol.dg/group2/INSPECT_ISO_Example_2.cob  |  2 +-
 .../cobol.dg/group2/INSPECT_ISO_Example_3.cob  |  2 +-
 .../cobol.dg/group2/INSPECT_ISO_Example_4.cob  |  2 +-
 .../cobol.dg/group2/INSPECT_ISO_Example_5-f.cob|  2 +-
 .../cobol.dg/group2/INSPECT_ISO_Example_6.cob  |  2 +-
 .../cobol.dg/group2/INSPECT_ISO_Example_7.cob  |  2 +-
 ...ple_INDEXED_BY_variables_with_the_same_name.cob | 24 ++
 ...ple_INDEXED_BY_variables_with_the_same_name.out |  3 +++
 14 files changed, 54 insertions(+), 27 deletions(-)

diff --git a/gcc/testsuite/cobol.dg/group1/check_88.cob 
b/gcc/testsuite/cobol.dg/group1/check_88.cob
index 4a7723eb92a3..18a299fc282b 100644
--- a/gcc/testsuite/cobol.dg/group1/check_88.cob
+++ b/gcc/testsuite/cobol.dg/group1/check_88.cob
@@ -3,25 +3,25 @@
 *> { dg-output {\->   <\-(\n|\r\n|\r)} }
 *> { dg-output {\->"""<\-(\n|\r\n|\r)} }
 *> { dg-output {\->000<\-(\n|\r\n|\r)} }
-*> { dg-output {\->ÿÿÿ<\-(\n|\r\n|\r)} }
+*> { dg-output {\->.*<\-(\n|\r\n|\r)} }
 *> { dg-output { (\n|\r\n|\r)} }
 *> { dg-output {\-><\-(\n|\r\n|\r)} }
 *> { dg-output {\-><\-(\n|\r\n|\r)} }
 *> { dg-output {\-><\-(\n|\r\n|\r)} }
 *> { dg-output {\-><\-(\n|\r\n|\r)} }
-*> { dg-output {\-><\-(\n|\r\n|\r)} }
+*> { dg-output {\->.*<\-(\n|\r\n|\r)} }
 *> { dg-output { (\n|\r\n|\r)} }
 *> { dg-output {There should be no garbage after character 32(\n|\r\n|\r)} }
 *> { dg-output 
{\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\*\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-(\n|\r\n|\r)}
 }
-*> { dg-output {üüü Bundesstraße   
 (\n|\r\n|\r)} }
-*> { dg-output {üüü Bundesstraße   
 (\n|\r\n|\r)} }
+*> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} }
+*> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} }
 *> { dg-output { (\n|\r\n|\r)} }
 *> { dg-output {There should be no spaces before the final quote(\n|\r\n|\r)} }
-*> { dg-output {"üüü Bundesstraße"(\n|\r\n|\r)} }
+*> { dg-output {".* Bundesstraße"(\n|\r\n|\r)} }
 *> { dg-output { (\n|\r\n|\r)} }
 *> { dg-output {   IsLow   ""(\n|\r\n|\r)} }
 *> { dg-output {   IsZero  "000"(\n|\r\n|\r)} }
-*> { dg-output {   IsHi"ÿÿÿ"(\n|\r\n|\r)} }
+*> { dg-output {   IsHi".*"(\n|\r\n|\r)} }
 *> { dg-output {   IsBob   "bob"(\n|\r\n|\r)} }
 *> { dg-output {   IsQuote "(\n|\r\n|\r)} }
 *> { dg-output {   IsSpace "   "(\n|\r\n|\r)} }
diff --git 
a/gcc/testsuite/cobol.dg/group2/ALLOCATE_R

  1   2   >