Re: [PATCH] testsuite: fix pr115929-1.c with -Wformat-security

2024-07-20 Thread Xi Ruoyao
On Sat, 2024-07-20 at 07:16 +0100, Sam James wrote:
> Xi Ruoyao  writes:
> 
> > On Sat, 2024-07-20 at 06:52 +0100, Sam James wrote:
> > > Some distributions like Gentoo make -Wformat and -Wformat-security
> > > enabled by default. Pass -Wno-format to the test to avoid a spurious
> > > fail in such environments.
> > > 
> > > gcc/testsuite/
> > >   PR rtl-optimization/115929
> > >   * gcc.dg/torture/pr115929-1.c: Pass -Wno-format.
> > > ---
> > 
> > IMO if you are patching GCC downstream to enable some options, you can
> > patch the test case in the same .patch file anyway instead of pushing it
> > upstream.
> 
> It's a fair argument.
> 
> That said, you did say the same thing reflexively about -fhardened, even
> if this is a different situation ;)
> 
> One might argue that especially for torture/, supporting "not
> unreasonable" random flags is not a bad thing.
> 
> > 
> > If we take the responsibility to make the test suite anticipate random
> > downstream changes, the test suite will ended up filled with different
> > workarounds for 42 distros.
> > 
> 
> My counterpoint would be that there are certain warnings we know various
> distros enable by default, and various warnings where it's not
> inconceivable we might do them upstream at some point.

Then I'll prefer the change log not to say "Gentoo makes GCC enable -
Wformat by default", but something like "-Wformat is a commonly used
flag and people may run test suite with it enabled" and maybe also "we
may turn it on by default in the future."  I.e. not to mention a
specific distro (so distro maintainers cannot use the changelog as a
reason to push random messes), but consider the situation someone
running the test suite with some not so strange CFLAGS.

Just my 2 cents.  I'm just a "write after approval" guy anyway and I've
no permission to Ack or Nack a patch.  And I'm somewhat frustrated after
my test suite fixes for default PIE (well we have --enable-default-pie
and AFAIK every distro is using it, so IMO it should have a higher
priority than -Wformat) gets no response after Ping^5.

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


[r13-8926 Regression] FAIL: gfortran.dg/pr113363.f90 -Os (test for excess errors) on Linux/x86_64

2024-07-20 Thread haochen.jiang
On Linux/x86_64,

7c81ff02a943cda82cc1a82b36ae8ab14470b00a is the first bad commit
commit 7c81ff02a943cda82cc1a82b36ae8ab14470b00a
Author: Paul Thomas 
Date:   Mon May 13 07:27:20 2024 +0100

Fortran: Fix wrong code in unlimited polymorphic assignment [PR113363]

caused

FAIL: gfortran.dg/pr113363.f90   -O0  (internal compiler error: Segmentation 
fault)
FAIL: gfortran.dg/pr113363.f90   -O0  (test for excess errors)
FAIL: gfortran.dg/pr113363.f90   -O1  (internal compiler error: Segmentation 
fault)
FAIL: gfortran.dg/pr113363.f90   -O1  (test for excess errors)
FAIL: gfortran.dg/pr113363.f90   -O2  (internal compiler error: Segmentation 
fault)
FAIL: gfortran.dg/pr113363.f90   -O2  (test for excess errors)
FAIL: gfortran.dg/pr113363.f90   -O3 -fomit-frame-pointer -funroll-loops 
-fpeel-loops -ftracer -finline-functions  (internal compiler error: 
Segmentation fault)
FAIL: gfortran.dg/pr113363.f90   -O3 -fomit-frame-pointer -funroll-loops 
-fpeel-loops -ftracer -finline-functions  (test for excess errors)
FAIL: gfortran.dg/pr113363.f90   -O3 -g  (internal compiler error: Segmentation 
fault)
FAIL: gfortran.dg/pr113363.f90   -O3 -g  (test for excess errors)
FAIL: gfortran.dg/pr113363.f90   -Os  (internal compiler error: Segmentation 
fault)
FAIL: gfortran.dg/pr113363.f90   -Os  (test for excess errors)

with GCC configured with

../../gcc/configure 
--prefix=/export/users/haochenj/src/gcc-bisect/gcc-13/releases/gcc-13/r13-8926/usr
 --enable-clocale=gnu --with-system-zlib --with-demangler-in-ld 
--with-fpmath=sse --enable-languages=c,c++,fortran --enable-cet --without-isl 
--enable-libmpx x86_64-linux --disable-bootstrap

To reproduce:

$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="dg.exp=gfortran.dg/pr113363.f90 --target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="dg.exp=gfortran.dg/pr113363.f90 --target_board='unix{-m32\ 
-march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="dg.exp=gfortran.dg/pr113363.f90 --target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="dg.exp=gfortran.dg/pr113363.f90 --target_board='unix{-m64\ 
-march=cascadelake}'"

(Please do not reply to this email, for question about this report, contact me 
at haochen dot jiang at intel.com.)
(If you met problems with cascadelake related, disabling AVX512F in command 
line might save that.)
(However, please make sure that there is no potential problems with AVX512.)


Re: [PATCH] s390: Fix unresolved iterators bhfgq and xdee

2024-07-20 Thread Andreas Krebbel



On 7/20/24 08:39, Stefan Schulze Frielinghaus wrote:

I'm pinging this early since I would like to make sure that it gets into
14.2 RC which is about to be done on Tuesday 23rd July.

On Tue, Jul 16, 2024 at 04:50:29PM +0200, Stefan Schulze Frielinghaus wrote:

Code attribute bhfgq is missing a mapping for TF.  This results in
unresolved iterators in assembler templates for *bswaptf.

With the TF mapping added the base mnemonics vlbr and vstbr are not
"used" anymore but only the extended mnemonics (vlbr was
interpreted as vlbr; likewise for vstbr).  Therefore, remove the base
mnemonics from the scheduling description, otherwise, genattrtab would
error about unknown mnemonics.

Likewise, for movtf_vr only the extended mnemonics for vrepi are used,
now, which means the base mnemonic is "unused" and has to be removed
from the scheduling description.

Similarly, we end up with unresolved iterators in assembler templates
for mulfprx23 since code attribute xdee is missing a mapping for FPRX2.

Note, this is basically a cherry pick of commit r15-2060-ga4abda934aa426
with the addition that vrepi is removed from the scheduling description,
too.

Bootstrapped on s390.  Ok for release branches 12, 13, and 14?


Ok, Thanks!

Andreas




gcc/ChangeLog:

* config/s390/3931.md (vlbr, vstbr, vrepi): Remove.
* config/s390/s390.md (xdee): Add FPRX2 mapping.
* config/s390/vector.md (bhfgq): Add TF mapping.





---
  gcc/config/s390/3931.md   | 7 ---
  gcc/config/s390/s390.md   | 2 +-
  gcc/config/s390/vector.md | 2 +-
  3 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/gcc/config/s390/3931.md b/gcc/config/s390/3931.md
index bed1f6c21f1..9cb11b72bba 100644
--- a/gcc/config/s390/3931.md
+++ b/gcc/config/s390/3931.md
@@ -404,7 +404,6 @@ vlvgg,
  vlvgh,
  vlvgp,
  vst,
-vstbr,
  vstbrf,
  vstbrg,
  vstbrh,
@@ -627,7 +626,6 @@ tm,
  tmy,
  vl,
  vlbb,
-vlbr,
  vlbrf,
  vlbrg,
  vlbrh,
@@ -661,7 +659,6 @@ vlreph,
  vlrl,
  vlrlr,
  vst,
-vstbr,
  vstbrf,
  vstbrg,
  vstbrh,
@@ -1077,7 +1074,6 @@ vrepb,
  vrepf,
  vrepg,
  vreph,
-vrepi,
  vrepib,
  vrepif,
  vrepig,
@@ -1930,7 +1926,6 @@ vrepb,
  vrepf,
  vrepg,
  vreph,
-vrepi,
  vrepib,
  vrepif,
  vrepig,
@@ -2156,7 +2151,6 @@ vistrfs,
  vistrhs,
  vl,
  vlbb,
-vlbr,
  vlbrf,
  vlbrg,
  vlbrh,
@@ -2248,7 +2242,6 @@ tbegin,
  tbeginc,
  tend,
  vst,
-vstbr,
  vstbrf,
  vstbrg,
  vstbrh,
diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md
index 50a828f2bbb..8edc1261c38 100644
--- a/gcc/config/s390/s390.md
+++ b/gcc/config/s390/s390.md
@@ -744,7 +744,7 @@
  ;; In FP templates, a  in "mr" will expand to "mxr" in
  ;; TF/TDmode, "mdr" in DF/DDmode, "meer" in SFmode and "mer in
  ;; SDmode.
-(define_mode_attr xdee [(TF "x") (DF "d") (SF "ee") (TD "x") (DD "d") (SD 
"e")])
+(define_mode_attr xdee [(TF "x") (FPRX2 "x") (DF "d") (SF "ee") (TD "x") (DD "d") (SD 
"e")])
  
  ;; The decimal floating point variants of add, sub, div and mul support 3

  ;; fp register operands.  The following attributes allow to merge the bfp and
diff --git a/gcc/config/s390/vector.md b/gcc/config/s390/vector.md
index 1bae1056951..f88e8b655fa 100644
--- a/gcc/config/s390/vector.md
+++ b/gcc/config/s390/vector.md
@@ -134,7 +134,7 @@
(V1TI "q") (TI "q")
(V1SF "f") (V2SF "f") (V4SF "f")
(V1DF "g") (V2DF "g")
-   (V1TF "q")])
+   (V1TF "q") (TF "q")])
  
  ; This is for vmalhw. It gets an 'w' attached to avoid confusion with

  ; multiply and add logical high vmalh.
--
2.45.0



Re: [PATCH] Spec Files: remove documentation about obsolete spec strings

2024-07-20 Thread Gerald Pfeifer
On Tue, 16 Jan 2024, André Maroneze wrote:
> Remove from documentation spec strings that no longer exist in the code:
> - predefines: removed in 2003 (From-SVN: r66917)
> - signed_char: removed in 2002 (From-SVN: r49444)
> 
> gcc/
>     * doc/invoke.texi (Spec Files): Remove obsolete spec strings

Thank you for your patch, and sorry we did not get to it earlier.

I pushed it with a slightly adjusted ChangeLog (and under your name);
sadly I missed the details you provided which were really useful, thank 
you for providing those.

Gerald

[COMMITTED] Tweak pr116003.c to target bitint.

2024-07-20 Thread Andrew MacLeod

On 7/20/24 01:58, Sam James wrote:

FAIL: gcc.dg/pr116003.c (test for excess errors)
Excess errors:
/home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:4:1:
 sorry, unimplemented: '_BitInt(5)' is not supported on this target
/home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:8:1:
 sorry, unimplemented: '_BitInt(129)' is not supported on this target
/home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:11:5:
 sorry, unimplemented: '_BitInt(128)' is not supported on this target

I think it needs dg-do compile { target bitint }.


Indeed, thanks.  Pushed.

Andrew
commit 320c0d49dd5d7d96443b8ee2fde3cce533eaa761
Author: Andrew MacLeod 
Date:   Sat Jul 20 11:45:16 2024 -0400

Add bitint to options for testcase

Testcase should only be for bitint targets

gcc/testsuite/
* gcc.dg/pr116003.c : Add target bitint.

diff --git a/gcc/testsuite/gcc.dg/pr116003.c b/gcc/testsuite/gcc.dg/pr116003.c
index 6021058a14e..970b1539c48 100644
--- a/gcc/testsuite/gcc.dg/pr116003.c
+++ b/gcc/testsuite/gcc.dg/pr116003.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target bitint } } */
 /* { dg-options "-O2 -fnon-call-exceptions -fprofile-arcs 
-finstrument-functions -fno-tree-copy-prop" } */
 
 _BitInt(5) b5;


Re: [COMMITTED] Tweak pr116003.c to target bitint.

2024-07-20 Thread Jakub Jelinek
On Sat, Jul 20, 2024 at 11:48:36AM -0400, Andrew MacLeod wrote:
> On 7/20/24 01:58, Sam James wrote:
> > FAIL: gcc.dg/pr116003.c (test for excess errors)
> > Excess errors:
> > /home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:4:1:
> >  sorry, unimplemented: '_BitInt(5)' is not supported on this target
> > /home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:8:1:
> >  sorry, unimplemented: '_BitInt(129)' is not supported on this target
> > /home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:11:5:
> >  sorry, unimplemented: '_BitInt(128)' is not supported on this target
> > 
> > I think it needs dg-do compile { target bitint }.
> > 
> Indeed, thanks.  Pushed.

This isn't enough.
The bitint effective target just means that the target supports
at least some _BitInt precisions (the standard in that case mandates
support for at least bits in long long, so 64), but this testcase
uses _BitInt(129), for that one needs to check for
#if __BITINT_MAXWIDTH__ >= 129
or use e.g. bitint575 effective target which guarantees _BitInt(575)
support.

Jakub



Re: [COMMITTED] Tweak pr116003.c to target bitint.

2024-07-20 Thread Andrew MacLeod



On 7/20/24 12:00, Jakub Jelinek wrote:

On Sat, Jul 20, 2024 at 11:48:36AM -0400, Andrew MacLeod wrote:

On 7/20/24 01:58, Sam James wrote:

FAIL: gcc.dg/pr116003.c (test for excess errors)
Excess errors:
/home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:4:1:
 sorry, unimplemented: '_BitInt(5)' is not supported on this target
/home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:8:1:
 sorry, unimplemented: '_BitInt(129)' is not supported on this target
/home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:11:5:
 sorry, unimplemented: '_BitInt(128)' is not supported on this target

I think it needs dg-do compile { target bitint }.


Indeed, thanks.  Pushed.

This isn't enough.
The bitint effective target just means that the target supports
at least some _BitInt precisions (the standard in that case mandates
support for at least bits in long long, so 64), but this testcase
uses _BitInt(129), for that one needs to check for
#if __BITINT_MAXWIDTH__ >= 129
or use e.g. bitint575 effective target which guarantees _BitInt(575)
support.

Jakub


ugg.  Maybe wrap the entire body like so?

diff --git a/gcc/testsuite/gcc.dg/pr116003.c 
b/gcc/testsuite/gcc.dg/pr116003.c

index 970b1539c48..741baff52a7 100644
--- a/gcc/testsuite/gcc.dg/pr116003.c
+++ b/gcc/testsuite/gcc.dg/pr116003.c
@@ -1,6 +1,7 @@
 /* { dg-do compile { target bitint } } */
 /* { dg-options "-O2 -fnon-call-exceptions -fprofile-arcs 
-finstrument-functions -fno-tree-copy-prop" } */


+#if __BITINT_MAXWIDTH__ >= 129
 _BitInt(5) b5;

 char c;
@@ -19,3 +20,4 @@ l64:
   if (__builtin_sub_overflow(c, 0, &b5))
 goto l64;
 }
+#endif





Re: [COMMITTED] Tweak pr116003.c to target bitint.

2024-07-20 Thread Jakub Jelinek
On Sat, Jul 20, 2024 at 12:31:34PM -0400, Andrew MacLeod wrote:
> 
> On 7/20/24 12:00, Jakub Jelinek wrote:
> > On Sat, Jul 20, 2024 at 11:48:36AM -0400, Andrew MacLeod wrote:
> > > On 7/20/24 01:58, Sam James wrote:
> > > > FAIL: gcc.dg/pr116003.c (test for excess errors)
> > > > Excess errors:
> > > > /home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:4:1:
> > > >  sorry, unimplemented: '_BitInt(5)' is not supported on this target
> > > > /home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:8:1:
> > > >  sorry, unimplemented: '_BitInt(129)' is not supported on this target
> > > > /home/tcwg-buildslave/workspace/tcwg_gnu_5/abe/snapshots/gcc.git~master/gcc/testsuite/gcc.dg/pr116003.c:11:5:
> > > >  sorry, unimplemented: '_BitInt(128)' is not supported on this target
> > > > 
> > > > I think it needs dg-do compile { target bitint }.
> > > > 
> > > Indeed, thanks.  Pushed.
> > This isn't enough.
> > The bitint effective target just means that the target supports
> > at least some _BitInt precisions (the standard in that case mandates
> > support for at least bits in long long, so 64), but this testcase
> > uses _BitInt(129), for that one needs to check for
> > #if __BITINT_MAXWIDTH__ >= 129
> > or use e.g. bitint575 effective target which guarantees _BitInt(575)
> > support.
> > 
> > Jakub
> > 
> ugg.  Maybe wrap the entire body like so?

Yes.  Though, perantically empty translation unit is invalid, so you could
do something like
#else
int
main ()
{
}
before the
#endif

Jakub



Re: [COMMITTED] Tweak pr116003.c to target bitint.

2024-07-20 Thread Andrew MacLeod



On 7/20/24 12:54, Jakub Jelinek wrote:


This isn't enough.
The bitint effective target just means that the target supports
at least some _BitInt precisions (the standard in that case mandates
support for at least bits in long long, so 64), but this testcase
uses _BitInt(129), for that one needs to check for
#if __BITINT_MAXWIDTH__ >= 129
or use e.g. bitint575 effective target which guarantees _BitInt(575)
support.

Jakub


ugg.  Maybe wrap the entire body like so?

Yes.  Though, perantically empty translation unit is invalid, so you could
do something like
#else
int
main ()
{
}
before the
#endif

Jakub


perhaps easier to just do

diff --git a/gcc/testsuite/gcc.dg/pr116003.c 
b/gcc/testsuite/gcc.dg/pr116003.c

index 970b1539c48..44e625015b0 100644
--- a/gcc/testsuite/gcc.dg/pr116003.c
+++ b/gcc/testsuite/gcc.dg/pr116003.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target bitint } } */
+/* { dg-do compile { target bitint575 } } */
 /* { dg-options "-O2 -fnon-call-exceptions -fprofile-arcs 
-finstrument-functions -fno-tree-copy-prop" } */


 _BitInt(5) b5;



Re: [patch,avr] Support new built-in for faster mask computation

2024-07-20 Thread Georg-Johann Lay

Am 19.07.24 um 16:56 schrieb Jeff Law:

On 7/18/24 3:12 PM, Georg-Johann Lay wrote:

This new builtin provides a faster way to compute
expressions like  1 << x  or ~(1 << x) that are sometimes
used as masks for setting bits in the I/O region, and when
x is not known at compile-time.

The open coded C expression takes 5 + 4 * x cycles to compute an
8-bit result, whereas the builtin takes only 7 cycles independent
of x.

The implementation is straight forward and uses 3 new insns.

Ok for trunk?

Johann

--

AVR: Support new built-in function __builtin_avr_mask1.

gcc/
 * config/avr/builtins.def (MASK1): New DEF_BUILTIN.
 * config/avr/avr.cc (avr_rtx_costs_1): Handle rtx costs for
 expressions like __builtin_avr_mask1.
 (avr_init_builtins) : New tree type.
 (avr_expand_builtin) [AVR_BUILTIN_MASK1]: Diagnose unexpected forms.
 (avr_fold_builtin) [AVR_BUILTIN_MASK1]: Handle case.
 * config/avr/avr.md (gen_mask1): New expand helper.
 (mask1_0x01_split, mask1_0x80_split, mask1_0xfe_split): New
 insn-and-split.
 (*mask1_0x01, *mask1_0x80, *mask1_0xfe): New insns.
 * doc/extend.texi (AVR Built-in Functions) <__builtin_avr_mask1>:
 Document new built-in function.
gcc/testsuite/
 * gcc.target/avr/torture/builtin-mask1.c: New test.

OK from a technical standpoint.  Just a few nits.
[...]

I'm not sure the builtin is strictly needed since this could likely be 
handled in the shift expanders and/or combiner patterns.  But I've got 
no objection to adding the builtin.


jeff


Hi Jeff,

at least combiner patterns won't work.  For something like

var |= 1 << (off & 7)

insn combine is just getting lost; it tries expressions with
MEM, IOR, even PARALLELs, but nothing that's close to a rotation.
Also it doesn't break out memory regerences (presumably because it
has no scratch reg available).  It is getting even worse for

var &= ~ (1 << (off & 7))

avr.md has rotlqi3 but no tries are ever made to emit
something like rotl (1, off) or rotr (0x80, off).

Johann


[PATCH] c++: fix wrong ambiguity resolution [PR29834]

2024-07-20 Thread Marek Polacek
[ Entering the contest to fix the oldest PR in this cycle. ]

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
This 18-year-old PR reports that we parse certain comma expressions
as a declaration rather than statement when the statement begins with
a functional-style cast expression.  Consider

  int(x), 0;

which does not declare x--it only casts x to int--, whereas

  int(x), (y);

declares x and y.  We need some kind of look-ahead to decide how we
should disambiguate the construct, because cp_parser_init_declarator
commits eagerly once it has seen "int(x)", and then it's too late to
recover.

This patch makes us try to parse the code as a sequence of declarators;
if that fails, we are likely looking at a statement.  That's a simple
idea, but it's complicated by code like

  void (*p)(void *)(fun);

which initializes a pointer-to-function, or

  int(x), (x) + 1;

which is an expression statement, but the second (x) is parsed as
a valid declarator, only the + after reveals that the whole thing
is an expression.  You can have things like

  int(**p)

which by itself doesn't tell you much.  You can have

  int(*q)(void*)

which looks like it starts with a functional-style cast, but it is not
a cast.  The simple

  int(x) = 42;

has an initializer so it declares x; it is not an assignment.  But then,

int(d) __attribute__(());

does not have an initializer, but the attribute makes it a declaration.

PR c++/29834
PR c++/54905

gcc/cp/ChangeLog:

* parser.cc (cp_parser_lambda_introducer): Use
cp_parser_next_token_starts_initializer_p.
(cp_parser_simple_declaration): Add look-ahead to decide if we're
looking at a declaration or statement.
(cp_parser_next_token_starts_initializer_p): New.

gcc/testsuite/ChangeLog:

* g++.dg/parse/ambig15.C: New test.
* g++.dg/parse/ambig16.C: New test.
---
 gcc/cp/parser.cc | 73 ++--
 gcc/testsuite/g++.dg/parse/ambig15.C | 83 
 gcc/testsuite/g++.dg/parse/ambig16.C | 18 ++
 3 files changed, 168 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/ambig15.C
 create mode 100644 gcc/testsuite/g++.dg/parse/ambig16.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 1fa0780944b..797cfc3204e 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -2947,6 +2947,8 @@ static bool cp_parser_next_token_ends_template_argument_p
   (cp_parser *);
 static bool cp_parser_nth_token_starts_template_argument_list_p
   (cp_parser *, size_t);
+static bool cp_parser_next_token_starts_initializer_p
+  (cp_parser *);
 static enum tag_types cp_parser_token_is_class_key
   (cp_token *);
 static enum tag_types cp_parser_token_is_type_parameter_key
@@ -11663,9 +11665,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree 
lambda_expr)
}
 
   /* Find the initializer for this capture.  */
-  if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)
- || cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)
- || cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
+  if (cp_parser_next_token_starts_initializer_p (parser))
{
  /* An explicit initializer exists.  */
  if (cxx_dialect < cxx14)
@@ -11747,9 +11747,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree 
lambda_expr)
  /* If what follows is an initializer, the second '...' is
 invalid.  But for cases like [...xs...], the first one
 is invalid.  */
- if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)
- || cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)
- || cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
+ if (cp_parser_next_token_starts_initializer_p (parser))
ellipsis_loc = loc;
  error_at (ellipsis_loc, "too many %<...%> in lambda capture");
  continue;
@@ -16047,6 +16045,58 @@ cp_parser_simple_declaration (cp_parser* parser,
 else
   break;
 
+  /* If we are still uncommitted, we're probably looking at something like
+ T(x), which can be a declaration but does not have to be, depending
+ on what comes after.  Consider
+   int(x), 0;
+ which is _not_ a declaration of x, it's a functional cast, and
+   int(x), (y);
+ which declares x and y.  We need some kind of look-ahead to decide,
+ cp_parser_init_declarator below will commit eagerly once it has seen
+ "int(x)".  So we try to parse this as a sequence of declarators; if
+ that fails, we are likely looking at a statement.  (We could avoid
+ all of this if there is no non-nested comma.)  */
+  if (cp_parser_uncommitted_to_tentative_parse_p (parser)
+  && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
+{
+  bool all_ok = true;
+  cp_lexer_save_tokens (parser->lexer);
+  /* A

Re: [COMMITTED] Tweak pr116003.c to target bitint.

2024-07-20 Thread Jakub Jelinek
On Sat, Jul 20, 2024 at 12:57:39PM -0400, Andrew MacLeod wrote:
> perhaps easier to just do

That works as well, sure.

> diff --git a/gcc/testsuite/gcc.dg/pr116003.c
> b/gcc/testsuite/gcc.dg/pr116003.c
> index 970b1539c48..44e625015b0 100644
> --- a/gcc/testsuite/gcc.dg/pr116003.c
> +++ b/gcc/testsuite/gcc.dg/pr116003.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile { target bitint } } */
> +/* { dg-do compile { target bitint575 } } */
>  /* { dg-options "-O2 -fnon-call-exceptions -fprofile-arcs
> -finstrument-functions -fno-tree-copy-prop" } */
> 
>  _BitInt(5) b5;

Jakub



[PATCH] i386: Add _MM_FROUND_TIES_TO_EVEN to smmintrin.h

2024-07-20 Thread Paul Caprioli
Intrinsics such as `_mm512_add_round_ps` take a rounding mode argument to 
specify the floating point rounding mode. This and similar instructions do NOT 
round their result to an integer. Thus it is inappropriate for user code to 
specify the existing `_MM_FROUND_TO_NEAREST_INT` when desiring to round to the 
nearest floating point number. This patch adds a suitable macro definition.

Note that some few instructions, e.g., `ROUNDPS`, do round to an integer, so 
the existing macro definition ought not be deprecated.

Note that IEEE Std 754-2019 for floating-point arithmetic specifies two 
rounding direction attributes to nearest: `roundTiesToEven` and 
`roundTiesToAway`. Also, it specifies three directed rounding attributes: 
`roundTowardPositive`, `roundTowardNegative`, and `roundTowardZero`.

This patch follows that IEEE naming precedent.  As hardware correctly 
implements that IEEE rounding attribute, it seems best not to innovate in 
naming the macro

Please note that I do not have write access to the git repo and that I am not a 
member of this email alias.  Your adding p...@hpkfft.com to any discussions 
would be appreciated.

Regards,
Paul



From 0e2ceddffed88dab9cc459f7efcab2e36e1cb7e3 Mon Sep 17 00:00:00 2001
From: Paul Caprioli 
Date: Sat, 20 Jul 2024 11:31:06 -0700
Subject: [PATCH] Add _MM_FROUND_TIES_TO_EVEN to smmintrin.h

---
 gcc/config/i386/smmintrin.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/config/i386/smmintrin.h b/gcc/config/i386/smmintrin.h
index 4c315feec36..b194659ae06 100644
--- a/gcc/config/i386/smmintrin.h
+++ b/gcc/config/i386/smmintrin.h
@@ -39,6 +39,7 @@
 
 /* Rounding mode macros. */
 #define _MM_FROUND_TO_NEAREST_INT	0x00
+#define _MM_FROUND_TIES_TO_EVEN		0x00
 #define _MM_FROUND_TO_NEG_INF		0x01
 #define _MM_FROUND_TO_POS_INF		0x02
 #define _MM_FROUND_TO_ZERO		0x03
-- 
2.39.2



[PATCH 2/2] Output CodeView type information for rvalue references

2024-07-20 Thread Mark Harmstone
Translates DW_TAG_rvalue_reference_type DIEs into LF_POINTER types.

gcc/
* dwarf2codeview.cc (get_type_num_reference_type): Handle rvalue refs.
(get_type_num_array_type): Add DW_TAG_rvalue_reference_type to switch.
(get_type_num): Handle DW_TAG_rvalue_reference_type DIEs.
* dwarf2codeview.h (CV_PTR_MODE_RVREF): Define.
---
 gcc/dwarf2codeview.cc | 15 ++-
 gcc/dwarf2codeview.h  |  1 +
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 23175204acd..9f446cb9cbb 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -2293,11 +2293,11 @@ get_type_num_pointer_type (dw_die_ref type, bool 
in_struct)
   return ct->num;
 }
 
-/* Process a DW_TAG_reference_type DIE, add a new LF_POINTER type, and return
-   its number.  */
+/* Process a DW_TAG_reference_type or DW_TAG_rvalue_reference_type DIE, add a
+   new LF_POINTER type, and return its number.  */
 
 static uint32_t
-get_type_num_reference_type (dw_die_ref type, bool in_struct)
+get_type_num_reference_type (dw_die_ref type, bool in_struct, bool rvref)
 {
   uint32_t base_type_num, byte_size;
   dw_die_ref base_type;
@@ -2318,7 +2318,7 @@ get_type_num_reference_type (dw_die_ref type, bool 
in_struct)
   ct->next = NULL;
   ct->kind = LF_POINTER;
   ct->lf_pointer.base_type = base_type_num;
-  ct->lf_pointer.attributes = CV_PTR_MODE_LVREF;
+  ct->lf_pointer.attributes = rvref? CV_PTR_MODE_RVREF : CV_PTR_MODE_LVREF;
 
   if (byte_size == 4)
 ct->lf_pointer.attributes |= CV_PTR_NEAR32;
@@ -3064,6 +3064,7 @@ get_type_num_array_type (dw_die_ref type, bool in_struct)
case DW_TAG_union_type:
case DW_TAG_pointer_type:
case DW_TAG_reference_type:
+   case DW_TAG_rvalue_reference_type:
  size = get_AT_unsigned (t, DW_AT_byte_size);
  break;
 
@@ -3192,7 +3193,11 @@ get_type_num (dw_die_ref type, bool in_struct, bool 
no_fwd_ref)
   break;
 
 case DW_TAG_reference_type:
-  num = get_type_num_reference_type (type, in_struct);
+  num = get_type_num_reference_type (type, in_struct, false);
+  break;
+
+case DW_TAG_rvalue_reference_type:
+  num = get_type_num_reference_type (type, in_struct, true);
   break;
 
 case DW_TAG_const_type:
diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h
index 7d4e3ab1db4..8ede1b29529 100644
--- a/gcc/dwarf2codeview.h
+++ b/gcc/dwarf2codeview.h
@@ -56,6 +56,7 @@ along with GCC; see the file COPYING3.  If not see
 #define CV_PTR_NEAR32  0x0a
 #define CV_PTR_64  0x0c
 #define CV_PTR_MODE_LVREF  0x20
+#define CV_PTR_MODE_RVREF  0x80
 
 /* LF_MODIFIER values.  */
 #define MOD_const  0x1
-- 
2.44.2



[PATCH 1/2] Output CodeView type information for references

2024-07-20 Thread Mark Harmstone
Translates DW_TAG_reference_type DIEs into LF_POINTER types.

gcc/
* dwarf2codeview.cc (get_type_num_reference_type): New function.
(get_type_num_array_type): Add DW_TAG_reference_type to switch.
(get_type_num): Handle DW_TAG_reference_type DIEs.
* dwarf2codeview.h (CV_PTR_MODE_LVREF): Define.
---
 gcc/dwarf2codeview.cc | 44 +++
 gcc/dwarf2codeview.h  |  1 +
 2 files changed, 45 insertions(+)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index c174f320480..23175204acd 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -2293,6 +2293,45 @@ get_type_num_pointer_type (dw_die_ref type, bool 
in_struct)
   return ct->num;
 }
 
+/* Process a DW_TAG_reference_type DIE, add a new LF_POINTER type, and return
+   its number.  */
+
+static uint32_t
+get_type_num_reference_type (dw_die_ref type, bool in_struct)
+{
+  uint32_t base_type_num, byte_size;
+  dw_die_ref base_type;
+  codeview_custom_type *ct;
+
+  byte_size = get_AT_unsigned (type, DW_AT_byte_size);
+  if (byte_size != 4 && byte_size != 8)
+return 0;
+
+  base_type = get_AT_ref (type, DW_AT_type);
+
+  base_type_num = get_type_num (base_type, in_struct, false);
+  if (base_type_num == 0)
+return 0;
+
+  ct = (codeview_custom_type *) xmalloc (sizeof (codeview_custom_type));
+
+  ct->next = NULL;
+  ct->kind = LF_POINTER;
+  ct->lf_pointer.base_type = base_type_num;
+  ct->lf_pointer.attributes = CV_PTR_MODE_LVREF;
+
+  if (byte_size == 4)
+ct->lf_pointer.attributes |= CV_PTR_NEAR32;
+  else
+ct->lf_pointer.attributes |= CV_PTR_64;
+
+  ct->lf_pointer.attributes |= byte_size << 13;
+
+  add_custom_type (ct);
+
+  return ct->num;
+}
+
 /* Process a DW_TAG_const_type DIE, adding an LF_MODIFIER type and returning
its number.  */
 
@@ -3024,6 +3063,7 @@ get_type_num_array_type (dw_die_ref type, bool in_struct)
case DW_TAG_class_type:
case DW_TAG_union_type:
case DW_TAG_pointer_type:
+   case DW_TAG_reference_type:
  size = get_AT_unsigned (t, DW_AT_byte_size);
  break;
 
@@ -3151,6 +3191,10 @@ get_type_num (dw_die_ref type, bool in_struct, bool 
no_fwd_ref)
   num = get_type_num_pointer_type (type, in_struct);
   break;
 
+case DW_TAG_reference_type:
+  num = get_type_num_reference_type (type, in_struct);
+  break;
+
 case DW_TAG_const_type:
   num = get_type_num_const_type (type, in_struct);
   break;
diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h
index 8fd3632e524..7d4e3ab1db4 100644
--- a/gcc/dwarf2codeview.h
+++ b/gcc/dwarf2codeview.h
@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3.  If not see
 /* LF_POINTER attributes.  */
 #define CV_PTR_NEAR32  0x0a
 #define CV_PTR_64  0x0c
+#define CV_PTR_MODE_LVREF  0x20
 
 /* LF_MODIFIER values.  */
 #define MOD_const  0x1
-- 
2.44.2



[PATCH v3 00/12] Metadirective support + "declare variant" improvements

2024-07-20 Thread Sandra Loosemore
This is a revised version of the patch set I last posted in late May:

https://gcc.gnu.org/pipermail/gcc-patches/2024-May/653066.html

Aside from rebasing the patch set so it applies cleanly to mainline
head again, I incorporated a few small code cleanups and testsuite
fixes I'd collected, plus a few more substantive improvements:

- I changed the metadirective pretty-printers to use "otherwise"
  instead of the now-deprecated "default" clause, as Tobias suggested
  in his review of the previous version of part 1, and made
  corresponding tweaks to the test cases that were examining the dump
  output.

- I also re-did the device_num support for the target_device selector
  along the lines suggested by Tobias (simplifying the libgomp support
  and adding a conditional to the generated code), and added a new
  testcase for that.

- When I was working on something else I observed that the C front end
  now has support for attribute-syntax directives; when I originally
  implemented that for metadirectives on the OG13 branch about a year
  ago, only C++ had general support for attribute syntax.  My C++
  testcases failed to "just work" in C because the lookahead
  save/restore mechanism for attribute directives collided with the
  token caching used by metadirective for parsing the body.  So I
  fixed that, now the testcases work in both languages.

Also note the lists of improvements and bug fixes for previous
versions of the patch set, which I won't duplicate here.

I realize this is a large and complicated patch set with many
dependencies between the pieces (and I have another layer on top of
this in the works to support "begin declare variant").  If the
maintainers would find it easier to review if I refactored the pieces
in some other way, please let me know what would help to expedite the
process.  I'd really like to get these patches in somehow or another,
so I don't have to continue to spend so much time maintaining them out
of tree.  :-S

-Sandra

Sandra Loosemore (12):
  OpenMP: metadirective tree data structures and front-end interfaces
  OpenMP: middle-end support for metadirectives
  libgomp: runtime support for target_device selector
  OpenMP: C front end support for metadirectives
  OpenMP: C++ front-end support for metadirectives
  OpenMP: common c/c++ testcases for metadirectives
  OpenMP: Fortran front-end support for metadirectives.
  OpenMP: Reject other properties with kind(any)
  OpenMP: Extend dynamic selector support to declare variant
  OpenMP: Remove dead code from declare variant reimplementation
  OpenMP: Update "declare target"/OpenMP context interaction
  OpenMP: Update documentation of metadirective implementation status.

 gcc/Makefile.in   |2 +-
 gcc/builtin-types.def |2 +
 gcc/c-family/c-attribs.cc |2 -
 gcc/c-family/c-common.h   |4 +-
 gcc/c-family/c-gimplify.cc|   27 +
 gcc/c-family/c-omp.cc |   60 +-
 gcc/c-family/c-pragma.cc  |1 +
 gcc/c-family/c-pragma.h   |1 +
 gcc/c/c-decl.cc   |8 +-
 gcc/c/c-parser.cc |  508 +++-
 gcc/cgraph.cc |2 -
 gcc/cgraph.h  |   12 +-
 gcc/cgraphclones.cc   |2 +-
 gcc/cp/cp-tree.h  |2 +
 gcc/cp/decl.cc|2 +-
 gcc/cp/decl2.cc   |9 +-
 gcc/cp/parser.cc  |  526 -
 gcc/cp/parser.h   |7 +
 gcc/cp/pt.cc  |  120 +
 gcc/cp/semantics.cc   |3 +-
 gcc/doc/generic.texi  |   32 +
 gcc/doc/gimple.texi   |6 +
 gcc/fortran/decl.cc   |   29 +
 gcc/fortran/dump-parse-tree.cc|   21 +
 gcc/fortran/gfortran.h|   21 +-
 gcc/fortran/io.cc |2 +-
 gcc/fortran/match.h   |2 +
 gcc/fortran/openmp.cc |  294 ++-
 gcc/fortran/parse.cc  |  578 +++--
 gcc/fortran/parse.h   |8 +-
 gcc/fortran/resolve.cc|6 +
 gcc/fortran/st.cc |4 +
 gcc/fortran/symbol.cc |   25 +-
 gcc/fortran/trans-decl.cc |5 +-
 gcc/fortran/trans-openmp.cc   |  238 +-
 gcc/fortran/trans-stmt.h  |1 +
 gcc/fortran/trans.cc  |1 +
 gcc/fortran/types.def |2 +
 gcc/gimple-low.cc |   36 +
 gcc/gimple-pretty-print.cc|   78 +
 gcc/gimple-streamer-in.cc   

[PATCH v3 01/12] OpenMP: metadirective tree data structures and front-end interfaces

2024-07-20 Thread Sandra Loosemore
This patch adds the OMP_METADIRECTIVE tree node and shared tree-level
support for manipulating metadirectives.  It defines/exposes
interfaces that will be used in subsequent patches that add front-end
and middle-end support, but nothing generates these nodes yet.

This patch also adds compile-time support for dynamic context
selectors (the target_device selector set and the condition selector
of the user selector set) for metadirectives only.  The "declare
variant" directive still supports only static selectors.

gcc/ChangeLog
* Makefile.in (GTFILES): Move omp-general.h earlier in the list.
* builtin-types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR):
New.
* doc/generic.texi (OpenMP): Document OMP_METADIRECTIVE and
context selector interfaces.
* omp-builtins.def (BUILT_IN_GOMP_EVALUATE_TARGET_DEVICE): New.
* omp-general.cc (omp_check_context_selector): Add metadirective_p
parameter, use it to conditionalize target_device support.
(make_omp_metadirective_variant): New.
(omp_context_selector_matches): Add metadirective_p and delay_p
parameters, use them to control things that can only be matched
late.  Handle OMP_TRAIT_SET_TARGET_DEVICE.
(score_wide_int): Move definition to omp-general.h.
(omp_encode_kind_arch_isa_props): New.
(omp_dynamic_cond): New.
(omp_context_compute_score): Handle OMP_TRAIT_SET_TARGET_DEVICE.
(omp_resolve_late_declare_variant, omp_resolve_declare_variant):
Adjust calls to omp_context_selector_matches.
(sort_variant): New.
(omp_get_dynamic_candidates): New.
(omp_early_resolve_metadirective): New.
* omp-general.h (score_wide_int): Moved here from omp-general.cc.
(struct omp_variant): New.
(OMP_METADIRECTIVE_VARIANT_SELECTOR): New.
(OMP_METADIRECTIVE_VARIANT_DIRECTIVE): New.
(OMP_METADIRECTIVE_VARIANT_BODY): New.
(make_omp_metadirective_variant): Declare.
(omp_check_context_selector): Adjust to match definition.
(omp_context_selector_matches): Likewise.
(omp_early_resolve_metadirective): New.
* tree-pretty-print.cc (dump_omp_context_selector): Remove
static qualifier.
(dump_generic_node): Handle OMP_METADIRECTIVE.
* tree-pretty-print.h (dump_omp_context_selector): Declare.
* tree.def (OMP_METADIRECTIVE): New.
* tree.h (OMP_METADIRECTIVE_VARIANTS): New.

gcc/c/ChangeLog
* c-parser.cc (c_finish_omp_declare_variant): Update calls to
omp_check_context_selector and omp_context_selector_matches.

gcc/cp/ChangeLog
* decl.cc (omp_declare_variant_finalize_one):  Update call to
omp_context_selector_matches to pass additional arguments.
* parser.cc (cp_finish_omp_declare_variant): Likewise for
omp_check_context_selector.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant):  Update calls to
omp_check_context_selector and omp_context_selector_matches.
* types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 gcc/Makefile.in |   2 +-
 gcc/builtin-types.def   |   2 +
 gcc/c/c-parser.cc   |   4 +-
 gcc/cp/decl.cc  |   2 +-
 gcc/cp/parser.cc|   2 +-
 gcc/doc/generic.texi|  32 
 gcc/fortran/trans-openmp.cc |   4 +-
 gcc/fortran/types.def   |   2 +
 gcc/omp-builtins.def|   3 +
 gcc/omp-general.cc  | 364 ++--
 gcc/omp-general.h   |  31 ++-
 gcc/tree-pretty-print.cc|  36 +++-
 gcc/tree-pretty-print.h |   2 +
 gcc/tree.def|   6 +
 gcc/tree.h  |   3 +
 15 files changed, 468 insertions(+), 27 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index f4bb4a88cf3..55641fffcaa 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2880,6 +2880,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h 
$(srcdir)/coretypes.h \
   $(srcdir)/tree-ssa-operands.h \
   $(srcdir)/tree-profile.cc $(srcdir)/tree-nested.cc \
   $(srcdir)/omp-offload.h \
+  $(srcdir)/omp-general.h \
   $(srcdir)/omp-general.cc \
   $(srcdir)/omp-low.cc \
   $(srcdir)/targhooks.cc $(out_file) $(srcdir)/passes.cc \
@@ -2906,7 +2907,6 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h 
$(srcdir)/coretypes.h \
   $(srcdir)/ipa-strub.cc \
   $(srcdir)/internal-fn.h \
   $(srcdir)/calls.cc \
-  $(srcdir)/omp-general.h \
   $(srcdir)/analyzer/analyzer-language.cc \
   @all_gtfiles@
 
diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
index c97d6bad1de..605a38ab84d 100644
--- a/gcc/builtin-types.def
+++ b/gcc/builtin-types.def
@@ -878,6 +878,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_VOID_UINT_PTR_INT_PTR, BT_VOID, 
BT_INT, BT_PTR,
 BT_INT, BT_PTR)
 DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_UINT_UINT_BOOL,
 BT_BOOL

[PATCH v3 03/12] libgomp: runtime support for target_device selector

2024-07-20 Thread Sandra Loosemore
This patch implements the libgomp runtime support for the dynamic
target_device selector via the GOMP_evaluate_target_device function.

include/ChangeLog
* cuda/cuda.h (CUdevice_attribute): Add definitions for
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR.

libgomp/ChangeLog
* Makefile.am (libgomp_la_SOURCES): Add selector.c.
* Makefile.in: Regenerate.
* config/gcn/selector.c: New.
* config/linux/selector.c: New.
* config/linux/x86/selector.c: New.
* config/nvptx/selector.c: New.
* libgomp-plugin.h (GOMP_OFFLOAD_evaluate_device): New.
* libgomp.h (struct gomp_device_descr): Add evaluate_device_func field.
* libgomp.map (GOMP_5.1.3): New, add GOMP_evaluate_target_device.
* libgomp.texi (OpenMP Context Selectors): Document dynamic selector
matching of kind/arch/isa.
* libgomp_g.h (GOMP_evaluate_current_device): New.
(GOMP_evaluate_target_device): New.
* oacc-host.c (host_evaluate_device): New.
(host_openacc_exec): Initialize evaluate_device_func field to
host_evaluate_device.
* plugin/plugin-gcn.c (gomp_match_selectors): New.
(gomp_match_isa): New.
(GOMP_OFFLOAD_evaluate_device): New.
* plugin/plugin-nvptx.c (struct ptx_device): Add compute_major and
compute_minor fields.
(nvptx_open_device): Read compute capability information from device.
(gomp_match_selectors): New.
(gomp_match_selector): New.
(CHECK_ISA): New macro.
(GOMP_OFFLOAD_evaluate_device): New.
* selector.c: New.
* target.c (GOMP_evaluate_target_device): New.
(gomp_load_plugin_for_device): Load evaluate_device plugin function.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 include/cuda/cuda.h |   2 +
 libgomp/Makefile.am |   2 +-
 libgomp/Makefile.in |   5 +-
 libgomp/config/gcn/selector.c   | 102 +++
 libgomp/config/linux/selector.c |  65 +
 libgomp/config/linux/x86/selector.c | 406 
 libgomp/config/nvptx/selector.c |  77 ++
 libgomp/libgomp-plugin.h|   2 +
 libgomp/libgomp.h   |   1 +
 libgomp/libgomp.map |   5 +
 libgomp/libgomp.texi|  18 +-
 libgomp/libgomp_g.h |   8 +
 libgomp/oacc-host.c |  11 +
 libgomp/plugin/plugin-gcn.c |  52 
 libgomp/plugin/plugin-nvptx.c   |  82 ++
 libgomp/selector.c  |  64 +
 libgomp/target.c|  22 ++
 17 files changed, 918 insertions(+), 6 deletions(-)
 create mode 100644 libgomp/config/gcn/selector.c
 create mode 100644 libgomp/config/linux/selector.c
 create mode 100644 libgomp/config/linux/x86/selector.c
 create mode 100644 libgomp/config/nvptx/selector.c
 create mode 100644 libgomp/selector.c

diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h
index 804d08ca57e..81545c2ebef 100644
--- a/include/cuda/cuda.h
+++ b/include/cuda/cuda.h
@@ -83,6 +83,8 @@ typedef enum {
   CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39,
   CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40,
   CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41,
+  CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75,
+  CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76,
   CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82,
   CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS = 88
 } CUdevice_attribute;
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 855f0affddf..ba2dd0bb3c2 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 selector.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index da902f3daca..b5d704992fc 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -219,7 +219,7 @@ 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 target-indirect.lo selector.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 +552,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-parallel.c oacc-host.c

[PATCH v3 02/12] OpenMP: middle-end support for metadirectives

2024-07-20 Thread Sandra Loosemore
This patch adds middle-end support for OpenMP metadirectives.  Some
context selectors can be resolved during gimplification, but others need to
be deferred until the omp_device_lower pass, which requires that cgraph,
LTO streaming, inlining, etc all know about this construct as well.

gcc/ChangeLog
* cgraph.h (struct cgraph_node): Add has_metadirectives flag.
* cgraphclones.cc (cgraph_node::create_clone): Copy has_metadirectives
flag.
* doc/gimple.texi (Class hierarchy of GIMPLE statements): Document
gomp_metadirective and gomp_variant.
* gimple-low.cc (lower_omp_metadirective): New.
(lower_stmt): Call it.
* gimple-pretty-print.cc (dump_gimple_omp_metadirective): New.
(pp_gimple_stmt_1): Call it.
* gimple-streamer-in.cc (input_gimple_stmt): Handle
GIMPLE_OMP_METADIRECTIVE.
* gimple-streamer-out.cc (output_gimple_stmt): Likewise.
* gimple-walk.cc (walk_gimple_op): Likewise.
(walk_gimple_stmt): Likewise.
* gimple.cc (gimple_alloc_omp_metadirective): New.
(gimple_build_omp_metadirective): New.
(gimple_build_omp_variant): New.
* gimple.def (GIMPLE_OMP_METADIRECTIVE): New.
(GIMPLE_OMP_METADIRECTIVE_VARIANT): New.
* gimple.h (gomp_variant, gomp_metadirective): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(gimple_alloc_omp_metadirective): New.
(gimple_build_omp_metadirective): New.
(gimple_build_omp_variant): New.
(gimple_has_substatements): Handle GIMPLE_OMP_METADIRECTIVE.
(gimple_has_ops): Likewise.
(gimple_omp_metadirective_label): New.
(gimple_omp_metadirective_set_label): New.
(gimple_omp_variants): New.
(gimple_omp_metadirective_set_variants): New.
(gimple_return_set_retval): Handle GIMPLE_OMP_METADIRECTIVE.
* gimplify.cc (is_gimple_stmt): HANDLE OMP_METADIRECTIVE.
(expand_omp_metadirective): New.
(gimplify_omp_metadirective): New.
(gimplify_expr): Call it.
* gsstruct.def (GSS_OMP_METADIRECTIVE): New.
(GSS_OMP_METADIRECTIVE_VARIANT): New.
* lto-cgraph.cc (lto_output_node): Handle has_metadirectives flag.
(input_overwrite_node): Likewise.
* omp-expand.cc (expand_omp_target): Propagate has_metadirectives
flag.
(build_omp_regions_1): Handle GIMPLE_OMP_METADIRECTIVE.
(omp_make_gimple_edges): Likewise.
* omp-general.cc (omp_late_resolve_metadirective): New.
* omp-general.h (omp_late_resolve_metadirective): Declare.
* omp-low.cc (struct omp_context): Add next_clone field.
(new_omp_context): Handle next_clone field.
(clone_omp_context): New.
(delete_omp_context): Delete clones.
(create_omp_child_function): Propagate has_metadirectives bit.
(scan_omp_metadirective): New.
(scan_omp_1_stmt): Handle GIMPLE_OMP_METADIRECTIVE.
(lower_omp_metadirective): New.
(lower_omp_1): Handle GIMPLE_OMP_METADIRECTIVE.  Warn about
direct calls to offloadable functions containing metadirectives.
* omp-offload.cc: Include cfganal.h and cfghooks.h.
(omp_expand_metadirective): New.
(execute_omp_device_lower): Handle metadirectives.
(pass_omp_device_lower::gate):  Check has_metadirectives bit.
* omp-simd-clone.cc (simd_clone_create): Propagate has_metadirectives
flag.
* tree-cfg.cc (cleanup_dead_labels): Handle GIMPLE_OMP_METADIRECTIVE.
(gimple_redirect_edge_and_branch): Likewise.
* tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE.
(estimate_num_instructions): Likewise.
(expand_call_inline): Propagate has_metadirectives flag.
(tree_function_versioning): Likewise.
* tree-nested.cc (convert_nonlocal_reference_stmt): Handle
GIMPLE_OMP_METADIRECTIVE specially.
(convert_local_reference_stmt): Likewise.
(convert_tramp_reference_stmt): Likewise.
(convert_gimple_call): Likewise.
* tree-ssa-operands.cc: Include omp-general.h.
(operands_scanner::parse_ssa_operands): Handle
GIMPLE_OMP_METADIRECTIVE.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
Co-Authored-By: Marcel Vollweiler 
---
 gcc/cgraph.h   |   3 +
 gcc/cgraphclones.cc|   1 +
 gcc/doc/gimple.texi|   6 ++
 gcc/gimple-low.cc  |  36 
 gcc/gimple-pretty-print.cc |  78 
 gcc/gimple-streamer-in.cc  |  10 ++
 gcc/gimple-streamer-out.cc |   6 ++
 gcc/gimple-walk.cc |  28 ++
 gcc/gimple.cc  |  35 +++
 gcc/gimple.def |   7 ++
 gcc/gimple.h   | 100 +++-
 gcc/gimplify.cc| 184 +
 gcc/gsstruct.def   |   

[PATCH v3 08/12] OpenMP: Reject other properties with kind(any)

2024-07-20 Thread Sandra Loosemore
The OpenMP spec says:

"If trait-property any is specified in the kind trait-selector of the
device selector set or the target_device selector sets, no other
trait-property may be specified in the same selector set."

GCC was not previously enforcing this restriction and several testcases
included such valid constructs.  This patch fixes it.

gcc/ChangeLog
* omp-general.cc (omp_check_context_selector): Reject other
properties in the same selector set with kind(any).

gcc/testsuite/ChangeLog
* c-c++-common/gomp/declare-variant-10.c: Fix broken tests.
* c-c++-common/gomp/declare-variant-3.c: Likewise.
* c-c++-common/gomp/declare-variant-9.c: Likewise.
* c-c++-common/gomp/declare-variant-any.c: New.
* gfortran.dg/gomp/declare-variant-10.f90: Fix broken tests.
* gfortran.dg/gomp/declare-variant-3.f90: Likewise.
* gfortran.dg/gomp/declare-variant-9.f90: Likewise.
* gfortran.dg/gomp/declare-variant-any.f90: Likewise.
---
 gcc/omp-general.cc| 31 +++
 .../c-c++-common/gomp/declare-variant-10.c|  4 +--
 .../c-c++-common/gomp/declare-variant-3.c | 10 ++
 .../c-c++-common/gomp/declare-variant-9.c |  4 +--
 .../c-c++-common/gomp/declare-variant-any.c   | 10 ++
 .../gfortran.dg/gomp/declare-variant-10.f90   |  4 +--
 .../gfortran.dg/gomp/declare-variant-3.f90| 12 ++-
 .../gfortran.dg/gomp/declare-variant-9.f90|  2 +-
 .../gfortran.dg/gomp/declare-variant-any.f90  | 28 +
 9 files changed, 82 insertions(+), 23 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-any.c
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 87a245ec8b3..12f178c5a2d 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1288,6 +1288,8 @@ omp_check_context_selector (location_t loc, tree ctx, 
bool metadirective_p)
   for (tree tss = ctx; tss; tss = TREE_CHAIN (tss))
 {
   enum omp_tss_code tss_code = OMP_TSS_CODE (tss);
+  bool saw_any_prop = false;
+  bool saw_other_prop = false;
 
   /* FIXME: not implemented yet.  */
   if (!metadirective_p && tss_code == OMP_TRAIT_SET_TARGET_DEVICE)
@@ -1325,6 +1327,27 @@ omp_check_context_selector (location_t loc, tree ctx, 
bool metadirective_p)
  else
ts_seen[ts_code] = true;
 
+
+ /* If trait-property "any" is specified in the "kind"
+trait-selector of the "device" selector set or the
+"target_device" selector sets, no other trait-property
+may be specified in the same selector set.  */
+ if (ts_code == OMP_TRAIT_DEVICE_KIND)
+   for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p))
+ {
+   const char *prop = omp_context_name_list_prop (p);
+   if (!prop)
+ continue;
+   else if (strcmp (prop, "any") == 0)
+ saw_any_prop = true;
+   else
+ saw_other_prop = true;
+ }
+   else if (ts_code == OMP_TRAIT_DEVICE_ARCH
+  || ts_code == OMP_TRAIT_DEVICE_ISA
+  || ts_code == OMP_TRAIT_DEVICE_NUM)
+   saw_other_prop = true;
+
  if (omp_ts_map[ts_code].valid_properties == NULL)
continue;
 
@@ -1377,6 +1400,14 @@ omp_check_context_selector (location_t loc, tree ctx, 
bool metadirective_p)
  break;
  }
}
+
+  if (saw_any_prop && saw_other_prop)
+   {
+ error_at (loc,
+   "no other trait-property may be specified "
+   "in the same selector set with %");
+ return error_mark_node;
+   }
 }
   return ctx;
 }
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c 
b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c
index 2b8a39425b1..e77693430d1 100644
--- a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c
+++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c
@@ -7,7 +7,7 @@ void f01 (void);
 #pragma omp declare variant (f01) match (device={isa(avx512f,avx512bw)})
 void f02 (void);
 void f03 (void);
-#pragma omp declare variant (f03) match 
(device={kind("any"),arch(x86_64),isa(avx512f,avx512bw)})
+#pragma omp declare variant (f03) match 
(device={arch(x86_64),isa(avx512f,avx512bw)})
 void f04 (void);
 void f05 (void);
 #pragma omp declare variant (f05) match (device={kind(gpu)})
@@ -28,7 +28,7 @@ void f15 (void);
 #pragma omp declare variant (f15) match (device={isa(sse4,ssse3),arch(i386)})
 void f16 (void);
 void f17 (void);
-#pragma omp declare variant (f17) match (device={kind(any,fpga)})
+#pragma omp declare variant (f17) match (device={kind(fpga)})
 void f18 (void);
 
 #pragma omp declare target
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c 
b/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c
index f5

[PATCH v3 04/12] OpenMP: C front end support for metadirectives

2024-07-20 Thread Sandra Loosemore
This patch adds support to the C front end to parse OpenMP metadirective
constructs.  It includes support for early parse-time resolution
of metadirectives (when possible) that will also be used by the C++ front
end.

Additional common C/C++ testcases are in a later patch in the series.

gcc/c-family/ChangeLog
* c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META.
(c_omp_expand_metadirective): Declare.
* c-gimplify.cc: Include omp-general.h.
(genericize_omp_metadirective_stmt): New.
(c_genericize_control_stmt): Call it.
* c-omp.cc (c_omp_directives): Add "metadirective" and fix
commented-out stubs for the begin/end form.
(c_omp_expand_metadirective_r): New.
(c_omp_expand_metadirective): New.
* c-pragma.cc (omp_pragmas): Add "metadirective".
* c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE.

gcc/c/ChangeLog
* c-parser.cc (struct c_parser): Add save_tokens and
save_tokens_avail fields for saving lookahead state and fields
for metadirective parsing.
(c_parser_skip_until_found): Restore state using new fields.
(c_parser_skip_to_pragma_eol): Likewise.
(c_parser_skip_to_end_of_block_or_statement):  Add metadirective_p
parameter; use it to control brace and parentheses behavior.
(c_parser_handle_statement_omp_attributes): Save state using
new c_parser fields.
(mangle_metadirective_region_label): New.
(c_parser_label, c_parser_statement_after_labels): Use it.
(c_parser_pragma): Handle metadirective.
(c_parser_omp_context_selector): Add metadirective_p flag, use it
to gate support for non-constant user condition.
(c_parser_omp_context_selector_specification): Add metadirective_p
argument.
(c_parser_finish_omp_declare_variant): Adjust call to above.
(c_maybe_parse_omp_decl): Save state using new c_parser fields.
(analyze_metadirective_body): New.
(c_parser_omp_metadirective): New.

gcc/testsuite/ChangeLog
* gcc.dg/gomp/metadirective-1.c: New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 gcc/c-family/c-common.h |   4 +-
 gcc/c-family/c-gimplify.cc  |  27 +
 gcc/c-family/c-omp.cc   |  60 ++-
 gcc/c-family/c-pragma.cc|   1 +
 gcc/c-family/c-pragma.h |   1 +
 gcc/c/c-parser.cc   | 524 +++-
 gcc/testsuite/gcc.dg/gomp/metadirective-1.c |  15 +
 7 files changed, 605 insertions(+), 27 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/gomp/metadirective-1.c

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index ccaea27c2b9..588a298a9a2 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1399,7 +1399,8 @@ enum c_omp_directive_kind {
   C_OMP_DIR_CONSTRUCT,
   C_OMP_DIR_DECLARATIVE,
   C_OMP_DIR_UTILITY,
-  C_OMP_DIR_INFORMATIONAL
+  C_OMP_DIR_INFORMATIONAL,
+  C_OMP_DIR_META
 };
 
 struct c_omp_directive {
@@ -1413,6 +1414,7 @@ extern const struct c_omp_directive c_omp_directives[];
 extern const struct c_omp_directive *c_omp_categorize_directive (const char *,
 const char *,
 const char *);
+extern tree c_omp_expand_metadirective (vec &);
 
 /* Return next tree in the chain for chain_next walking of tree nodes.  */
 inline tree
diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc
index 3e29766e092..897c3328f8e 100644
--- a/gcc/c-family/c-gimplify.cc
+++ b/gcc/c-family/c-gimplify.cc
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "context.h"
 #include "tree-pass.h"
 #include "internal-fn.h"
+#include "omp-general.h"
 
 /*  The gimplification pass converts the language-dependent trees
 (ld-trees) emitted by the parser into language-independent trees
@@ -485,6 +486,27 @@ genericize_omp_for_stmt (tree *stmt_p, int *walk_subtrees, 
void *data,
   finish_bc_block (&OMP_FOR_BODY (stmt), bc_continue, clab);
 }
 
+/* Genericize a OMP_METADIRECTIVE node *STMT_P.  */
+
+static void
+genericize_omp_metadirective_stmt (tree *stmt_p, int *walk_subtrees,
+  void *data, walk_tree_fn func,
+  walk_tree_lh lh)
+{
+  tree stmt = *stmt_p;
+
+  for (tree variant = OMP_METADIRECTIVE_VARIANTS (stmt);
+   variant != NULL_TREE;
+   variant = TREE_CHAIN (variant))
+{
+  walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_DIRECTIVE (variant),
+  func, data, NULL, lh);
+  walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_BODY (variant),
+  func, data, NULL, lh);
+}
+
+  *walk_subtrees = 0;
+}
 
 /* Lower structured control flow tree nodes, such as loops.  The
STMT_P, WALK_SUBTREES, and DATA arguments are a

[PATCH v3 12/12] OpenMP: Update documentation of metadirective implementation status.

2024-07-20 Thread Sandra Loosemore
libgomp/ChangeLog
* libgomp.texi (OpenMP 5.0): Mark metadirective and declare variant
as implemented.
(OpenMP 5.1): Mark target_device as supported.
Add changed interaction between declare target and OpenMP context
and dynamic selector support.
(OpenMP 5.2): Mark otherwise clause as supported, note that
default is also still accepted.
---
 libgomp/libgomp.texi | 21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 4b9459048d1..829e2c87387 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -192,9 +192,8 @@ The OpenMP 4.5 specification is fully supported.
 @item Array shaping @tab N @tab
 @item Array sections with non-unit strides in C and C++ @tab N @tab
 @item Iterators @tab Y @tab
-@item @code{metadirective} directive @tab N @tab
-@item @code{declare variant} directive
-  @tab P @tab @emph{simd} traits not handled correctly
+@item @code{metadirective} directive @tab Y @tab
+@item @code{declare variant} directive @tab Y @tab
 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
   env variable @tab Y @tab
 @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
@@ -289,8 +288,8 @@ The OpenMP 4.5 specification is fully supported.
 @headitem Description @tab Status @tab Comments
 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
 @item @code{omp_all_memory} reserved locator @tab Y @tab
-@item @emph{target_device trait} in OpenMP Context @tab N @tab
-@item @code{target_device} selector set in context selectors @tab N @tab
+@item @emph{target_device trait} in OpenMP Context @tab Y
+@item @code{target_device} selector set in context selectors @tab Y @tab
 @item C/C++'s @code{declare variant} directive: elision support of
   preprocessed code @tab N @tab
 @item @code{declare variant}: new clauses @code{adjust_args} and
@@ -366,6 +365,12 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N 
@tab
 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
   clauses @tab Y @tab
+@item Changed interaction between @code{declare target} and OpenMP context
+  @tab Y @tab
+@item Dynamic selector support in @code{metadirective} @tab Y @tab
+@item Dynamic selector support in @code{declare variant} @tab P
+  @tab Fortran rejects non-constant expressions in dynamic selectors;
+  C/C++ reject expressions using argument variables.
 @end multitable
 
 
@@ -413,8 +418,10 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @item Deprecation of traits array following the allocator_handle expression in
   @code{uses_allocators} @tab N @tab
 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
-  @tab N @tab
-@item Deprecation of @code{default} clause on metadirectives @tab N @tab
+  @tab Y @tab
+@item Deprecation of @code{default} clause on metadirectives @tab N
+  @tab Both @code{otherwise} and @code{default} are accepted
+  without diagnostics.
 @item Deprecation of delimited form of @code{declare target} @tab N @tab
 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
-- 
2.25.1



[PATCH v3 05/12] OpenMP: C++ front-end support for metadirectives

2024-07-20 Thread Sandra Loosemore
This patch adds C++ support for metadirectives.  It uses the
c-family support committed with the corresponding C front end patch
to do early parse-time metadirective resolution when possible.

Additional C/C++ common testcases are provided in a subsequent
patch in the series.

gcc/cp/ChangeLog
* parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add
metadirective_p parameter, use it to control brace/parentheses
behavior for metadirectives.
(mangle_metadirective_region_label): New.
(cp_parser_label_for_labeled_statement): Use it.
(cp_parser_jump_statement): Likewise.
(cp_parser_omp_context_selector): Add metadirective_p
parameter, use it to control error behavior for non-constant exprs
properties.
(cp_parser_omp_context_selector_specification): Add metadirective_p
parameter, use it for cp_parser_omp_context_selector call.
(cp_finish_omp_declare_variant): Adjust call to
cp_parser_omp_context_selector_specification.
(analyze_metadirective_body): New.
(cp_parser_omp_metadirective): New.
(cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE.
* parser.h (struct cp_parser): Add fields for metadirective parsing
state.
* pt.cc (tsubst_omp_context_selector): New.
(tsubst_stmt): Handle OMP_METADIRECTIVE.

libgomp/ChangeLog
* testsuite/libgomp.c++/metadirective-template-1.C: New.
* testsuite/libgomp.c++/metadirective-template-2.C: New.
* testsuite/libgomp.c++/metadirective-template-3.C: New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 gcc/cp/parser.cc  | 524 +-
 gcc/cp/parser.h   |   7 +
 gcc/cp/pt.cc  | 119 
 .../libgomp.c++/metadirective-template-1.C|  37 ++
 .../libgomp.c++/metadirective-template-2.C|  41 ++
 .../libgomp.c++/metadirective-template-3.C|  41 ++
 6 files changed, 756 insertions(+), 13 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-1.C
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-2.C
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-3.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 045b3fe7a5b..d4358ab35a1 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -3003,7 +3003,7 @@ static void cp_parser_skip_to_end_of_statement
 static void cp_parser_consume_semicolon_at_end_of_statement
   (cp_parser *);
 static void cp_parser_skip_to_end_of_block_or_statement
-  (cp_parser *);
+  (cp_parser *, bool = false);
 static bool cp_parser_skip_to_closing_brace
   (cp_parser *);
 static bool cp_parser_skip_entire_template_parameter_list
@@ -4196,9 +4196,11 @@ cp_parser_consume_semicolon_at_end_of_statement 
(cp_parser *parser)
have consumed a non-nested `;'.  */
 
 static void
-cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser)
+cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser,
+bool metadirective_p)
 {
   int nesting_depth = 0;
+  int bracket_depth = 0;
 
   /* Unwind generic function template scope if necessary.  */
   if (parser->fully_implicit_function_template_p)
@@ -4220,7 +4222,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* 
parser)
 
case CPP_SEMICOLON:
  /* Stop if this is an unnested ';'. */
- if (!nesting_depth)
+ if (!nesting_depth && (!metadirective_p || bracket_depth <= 0))
nesting_depth = -1;
  break;
 
@@ -4239,6 +4241,19 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* 
parser)
  nesting_depth++;
  break;
 
+   case CPP_OPEN_PAREN:
+ /* Track parentheses in case the statement is a standalone 'for'
+statement - we want to skip over the semicolons separating the
+operands.  */
+ if (metadirective_p && nesting_depth == 0)
+   bracket_depth++;
+ break;
+
+   case CPP_CLOSE_PAREN:
+ if (metadirective_p && nesting_depth == 0)
+   bracket_depth--;
+ break;
+
case CPP_KEYWORD:
  if (!cp_token_is_module_directive (token))
break;
@@ -13021,6 +13036,18 @@ attr_chainon (tree attrs, tree attr)
   return chainon (attrs, attr);
 }
 
+
+/* Helper function for cp_parser_label: mangle a metadirective region
+   label NAME.  */
+static tree
+mangle_metadirective_region_label (cp_parser *parser, tree name)
+{
+  const char *old_name = IDENTIFIER_POINTER (name);
+  char *new_name = (char *) alloca (strlen (old_name) + 32);
+  sprintf (new_name, "%s_MDR%u", old_name, parser->metadirective_region_num);
+  return get_identifier (new_name);
+}
+
 /* Parse the label for a labeled-statement, i.e.
 
label:
@@ -13123,7 +13150,12 @@ cp_parser_label_for_labeled_statement (cp_parser* 
parser, tree attributes)
 
  

[PATCH v3 06/12] OpenMP: common c/c++ testcases for metadirectives

2024-07-20 Thread Sandra Loosemore
gcc/testsuite/ChangeLog
* c-c++-common/gomp/attrs-metadirective-1.c: New.
* c-c++-common/gomp/attrs-metadirective-2.c: New.
* c-c++-common/gomp/attrs-metadirective-3.c: New.
* c-c++-common/gomp/attrs-metadirective-4.c: New.
* c-c++-common/gomp/attrs-metadirective-5.c: New.
* c-c++-common/gomp/attrs-metadirective-6.c: New.
* c-c++-common/gomp/attrs-metadirective-7.c: New.
* c-c++-common/gomp/attrs-metadirective-8.c: New.
* c-c++-common/gomp/metadirective-1.c: New.
* c-c++-common/gomp/metadirective-2.c: New.
* c-c++-common/gomp/metadirective-3.c: New.
* c-c++-common/gomp/metadirective-4.c: New.
* c-c++-common/gomp/metadirective-5.c: New.
* c-c++-common/gomp/metadirective-6.c: New.
* c-c++-common/gomp/metadirective-7.c: New.
* c-c++-common/gomp/metadirective-8.c: New.
* c-c++-common/gomp/metadirective-construct.c: New.
* c-c++-common/gomp/metadirective-device.c: New.
* c-c++-common/gomp/metadirective-no-score.c: New.
* c-c++-common/gomp/metadirective-target-device.c: New.

libgomp/ChangeLog
* testsuite/libgomp.c-c++-common/metadirective-1.c: New.
* testsuite/libgomp.c-c++-common/metadirective-2.c: New.
* testsuite/libgomp.c-c++-common/metadirective-3.c: New.
* testsuite/libgomp.c-c++-common/metadirective-4.c: New.
* testsuite/libgomp.c-c++-common/metadirective-5.c: New.
* testsuite/libgomp.c-c++-common/metadirective-target-device.c: New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 .../c-c++-common/gomp/attrs-metadirective-1.c |  41 
 .../c-c++-common/gomp/attrs-metadirective-2.c |  75 
 .../c-c++-common/gomp/attrs-metadirective-3.c |  32 
 .../c-c++-common/gomp/attrs-metadirective-4.c |  41 
 .../c-c++-common/gomp/attrs-metadirective-5.c |  25 +++
 .../c-c++-common/gomp/attrs-metadirective-6.c |  32 
 .../c-c++-common/gomp/attrs-metadirective-7.c |  32 
 .../c-c++-common/gomp/attrs-metadirective-8.c |  17 ++
 .../c-c++-common/gomp/metadirective-1.c   |  52 +
 .../c-c++-common/gomp/metadirective-2.c   |  74 
 .../c-c++-common/gomp/metadirective-3.c   |  31 +++
 .../c-c++-common/gomp/metadirective-4.c   |  40 
 .../c-c++-common/gomp/metadirective-5.c   |  24 +++
 .../c-c++-common/gomp/metadirective-6.c   |  31 +++
 .../c-c++-common/gomp/metadirective-7.c   |  31 +++
 .../c-c++-common/gomp/metadirective-8.c   |  16 ++
 .../gomp/metadirective-construct.c| 177 ++
 .../c-c++-common/gomp/metadirective-device.c  | 147 +++
 .../gomp/metadirective-no-score.c |  95 ++
 .../gomp/metadirective-target-device.c| 147 +++
 .../libgomp.c-c++-common/metadirective-1.c|  35 
 .../libgomp.c-c++-common/metadirective-2.c|  41 
 .../libgomp.c-c++-common/metadirective-3.c|  34 
 .../libgomp.c-c++-common/metadirective-4.c|  52 +
 .../libgomp.c-c++-common/metadirective-5.c|  46 +
 .../metadirective-target-device.c |  63 +++
 26 files changed, 1431 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-1.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-2.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-3.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-4.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-5.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-6.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-7.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-8.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-1.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-2.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-3.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-4.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-5.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-6.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-7.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-8.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-construct.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-device.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-no-score.c
 create mode 100644 
gcc/testsuite/c-c++-common/gomp/metadirective-target-device.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-1.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-2.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-3.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-com

[PATCH v3 10/12] OpenMP: Remove dead code from declare variant reimplementation

2024-07-20 Thread Sandra Loosemore
After reimplementing late resolution of "declare variant" to use the
same mechanisms as metadirective, the declare_variant_alt and
calls_declare_variant_alt flags on struct cgraph_node are no longer
used by anything.  For the purposes of marking functions that need
late resolution, the has_metadirectives flag has replaced
calls_declare_variant_alt.

Likewise struct omp_declare_variant_entry, struct
omp_declare_variant_base_entry, and the hash tables used to store
these structures are no longer needed, since the information needed for
late resolution is now stored in the gomp_metadirective nodes.

There are no functional changes in this patch, just removing dead code.

gcc/ChangeLog
* cgraph.cc (symbol_table::create_edge): Don't set
calls_declare_variant_alt in the caller.
* cgraph.h (struct cgraph_node): Remove declare_variant_alt
and calls_declare_variant_alt flags.
* cgraphclones.cc (cgraph_node::create_clone): Don't copy
calls_declare_variant_alt bit.
* ipa-free-lang-data.cc (free_lang_data_in_decl): Adjust code
referencing declare_variant_alt bit.
* ipa.cc (symbol_table::remove_unreachable_nodes): Likewise.
* lto-cgraph.cc (lto_output_node): Remove references to deleted
bits.
(output_refs): Adjust code referencing declare_variant_alt bit.
(input_overwrite_node): Remove references to deleted bits.
(input_refs): Adjust code referencing declare_variant_alt bit.
* lto-streamer-out.cc (lto_output): Likewise.
* lto-streamer.h (omp_lto_output_declare_variant_alt): Delete.
(omp_lto_input_declare_variant_alt): Delete.
* lto/lto-partition.cc (lto_balanced_map): Adjust code referencing
deleted declare_variant_alt bit.
* omp-expand.cc (expand_omp_target): Use has_metadirectives bit to
trigger pass_omp_device_lower instead of calls_declare_variant_alt.
* omp-general.cc (struct omp_declare_variant_entry): Delete.
(struct omp_declare_variant_base_entry): Delete.
(struct omp_declare_variant_hasher): Delete.
(omp_declare_variant_hasher::hash): Delete.
(omp_declare_variant_hasher::equal): Delete.
(omp_declare_variants): Delete.
(omp_declare_variant_alt_hasher): Delete.
(omp_declare_variant_alt_hasher::hash): Delete.
(omp_declare_variant_alt_hasher::equal): Delete.
(omp_declare_variant_alt): Delete.
(omp_lto_output_declare_variant_alt): Delete.
(omp_lto_input_declare_variant_alt): Delete.
(includes): Delete unnecessary include of gt-omp-general.h.
* omp-offload.cc (execute_omp_device_lower): Remove references
to deleted bit.
(pass_omp_device_lower::gate): Likewise.
* omp-simd-clone.cc (simd_clone_create): Likewise.
* passes.cc (ipa_write_summaries): Likeise.
* symtab.cc (symtab_node::get_partitioning_class): Likewise.
* tree-inline.cc (expand_call_inline): Likewise.
(tree_function_versioning): Likewise.
---
 gcc/cgraph.cc |   2 -
 gcc/cgraph.h  |  11 +-
 gcc/cgraphclones.cc   |   1 -
 gcc/ipa-free-lang-data.cc |   2 +-
 gcc/ipa.cc|   3 -
 gcc/lto-cgraph.cc |  10 --
 gcc/lto-streamer-out.cc   |   3 +-
 gcc/lto-streamer.h|   6 --
 gcc/lto/lto-partition.cc  |   5 +-
 gcc/omp-expand.cc |   2 +-
 gcc/omp-general.cc| 217 --
 gcc/omp-offload.cc|   8 +-
 gcc/omp-simd-clone.cc |   2 -
 gcc/passes.cc |   3 +-
 gcc/symtab.cc |   2 +-
 gcc/tree-inline.cc|   4 -
 16 files changed, 10 insertions(+), 271 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 473d8410bc9..103bc2c0332 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -931,8 +931,6 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node 
*callee,
  caller->decl);
   else
 edge->in_polymorphic_cdtor = caller->thunk;
-  if (callee)
-caller->calls_declare_variant_alt |= callee->declare_variant_alt;
 
   if (callee && symtab->state != LTO_STREAMING
   && edge->callee->comdat_local_p ())
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 6653ce19c3e..dd210842df7 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -897,10 +897,8 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public 
symtab_node
   split_part (false), indirect_call_target (false), local (false),
   versionable (false), can_change_signature (false),
   redefined_extern_inline (false), tm_may_enter_irr (false),
-  ipcp_clone (false), declare_variant_alt (false),
-  calls_declare_variant_alt (false), gc_candidate (false),
-  called_by_ifunc_resolver (false),
-  has_metadirectives (false),
+  ipcp_clone (false), gc_candidate (false),
+  called_by_ifunc_resolver (false), has_metadirectives (false),
   m_uid (uid), m_summary_id (-1)
 

[PATCH v3 09/12] OpenMP: Extend dynamic selector support to declare variant

2024-07-20 Thread Sandra Loosemore
This patch extends the mechanisms previously added to support dynamic
selectors in metavariant constructs to also apply to "declare
variant".  The front-end mechanisms used to handle "declare variant"
via attributes attached to the function decls remain the same, but the
gimplifier now uses the same internal data structures and helper
functions as metadirective to score and sort "declare variant"
alternatives, and constructs a gomp_metadirective node for variant
calls that cannot be resolved at gimplification time.  During late
resolution, this gomp_metadirective is processed in exactly the same
way as for real metadirectives.

During implementation of this functionality, a number of bugs were
discovered in the previous selector scoring and matching code:

* Metadirective resolution was failing to account for scoring in
  "declare simd" clones, and was also relying on calling a function to
  match construct constructors that's only useful during
  gimplification during late resolution long after that pass.

* The construct constructor scoring was previously implemented backwards
  from the specification (PR114596); a number of testcases were also broken
  in the same way as the implementation.

* The special rules for matching simdlen and aligned properties on simd
  selectors were not implemented (nor were these properties on metadirectives
  being rejected per the OpenMP spec).

This patch includes a new implementation of this functionality that
has cleaner interfaces and is hopefully(!) easier to correlate to
requirements of the OpenMP specification.  Instead of relying on the
gimplifier to score construct selectors, the scoring code has been
consolidated in omp-general.cc with the gimplifier only providing
the OpenMP construct context surrounding the metadirective or variant
call.  This is cached on the gomp_metadirective if necessary for late
resolution.

An additional improvement added in this patch is that for both
metadirective and "declare variant", if late resolution is required the
gimplifier now discards all alternatives that are known not to match.

Note that this patch leaves a substantial amount of dead code that
was used to support the former late "declare variant" resolution strategy,
notably the declare_variant_alt and calls_declare_variant_alt flags on
cgraph_node and all the code that touches those fields.  The next
patch in this series removes that unused code.

Another issue not addressed in this patch is the special scoping rules
for expressions in "declare variant" dynamic selectors, which is still
under discussion in PR113904.  We expect this to be fixed separately.

gcc/c/ChangeLog
* c-parser.c (c_parser_omp_context_selector): Remove metadirective_p
parameter and conditionalization.
(c_parser_omp_context_selector_specification): Remove metadirective_p
parameter and adjust call not to pass it on.
(c_finish_omp_declare_variant): Adjust arguments on calls to
c_parser_omp_context_selector_specification and
omp_context_selector_matches.
(c_parser_omp_metadirective): Likewise.

gcc/cp/ChangeLog
* cp-tree.h (struct saved_scope): Add new field
x_processing_omp_trait_property_expr.
(processing_omp_trait_property_expr): Define
* decl.cc (omp_declare_variant_finalize_one): Adjust arguments
to omp_context_selector_matches.
* parser.cc (cp_parser_omp_context_selector): Remove metadirective_p
argument and conditionalization.
(cp_parser_omp_context_selector_specification): Remove metadirective_p
argument and adjust call not to pass it on.
(cp_finish_omp_declare_variant): Adjust arguments on call to above.
(cp_parser_omp_metadirective): Likewise.
* pt.cc (tsubst_omp_context_selector): Adjust error behavior.
(tsubst_stmt): Adjust call to omp_context_selector_matches.
* semantics.cc (finish_id_expression_1): Do not diagnose error
for use of parameter in declare variant selector here.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust arguments
to omp_context_selector_matches.
(gfc_trans_omp_metadirective): Likewise.

gcc/Changelog
* gimple-streamer-in.cc (input_gimple_stmt): Restore
gomp_metadirective context.
* gimple-streamer-out.cc (output_gimple_stmt): Save
gomp_metadirective context.
* gimple.cc (gimple_build_omp_metadirective): Initialize
gomp_metadirective context.
* gimple.def (GIMPLE_OMP_METADIRECTIVE): Update comments.
* gimple.h (gomp_metadirective): Add context field and update comments.
(gimple_omp_metadirective_context): New.
(gimple_omp_metadirective_set_context): New.
* gimplify.cc (omp_resolved_variant_calls): New.
(gimplify_variant_call_expr): New.
(gimplify_call_expr): Adjust parameters.  Call
gimplify_variant_call_expr to handle declar

[PATCH v3 11/12] OpenMP: Update "declare target"/OpenMP context interaction

2024-07-20 Thread Sandra Loosemore
The code and test case previously implemented the OpenMP 5.0 spec,
which said in section 2.3.1:

"For functions within a declare target block, the target trait is added
to the beginning of the set..."

In OpenMP 5.1, this was changed to
"For device routines, the target trait is added to the beginning of
the set..."

In OpenMP 5.2 and TR12, it says:
"For procedures that are determined to be target function variants
by a declare target directive..."

The definition of "device routine" in OpenMP 5.1 is confusing, but
certainly the intent of the later versions of the spec is clear that
it doesn't just apply to functions within a begin declare target/end
declare target block.

The only use of the "omp declare target block" function attribute was
to support the 5.0 language, so it can be removed.  This patch changes
the context augmentation to use the "omp declare target" attribute
instead.

gcc/c-family/ChangeLog
* c-attribs.cc (c_common_gnu_attributes): Delete "omp declare
target block".

gcc/c/ChangeLog
* c-decl.cc (c_decl_attributes): Don't add "omp declare target
block".

gcc/cp/decl2.cc
* decl2.cc (cplus_decl_attributes): Don't add "omp declare target
block".

gcc/ChangeLog
* omp-general.cc (omp_complete_construct_context): Check
"omp declare target" attribute, not "omp declare target block".

gcc/testsuite/ChangeLog
* c-c++-common/gomp/declare-target-indirect-2.c : Adjust
expected output for removal of "omp declare target block".
* c-c++-common/gomp/declare-variant-8.c: Likewise, the variant
call to f20 is now resolved differently.
* c-c++-common/gomp/reverse-offload-1.c: Adjust expected output.
* gfortran.dg/gomp/declare-variant-8.f90: Likewise, both f18
and f20 now resolve to the variant.  Delete obsolete comments.
---
 gcc/c-family/c-attribs.cc|  2 --
 gcc/c/c-decl.cc  |  8 ++--
 gcc/cp/decl2.cc  |  9 ++---
 gcc/omp-general.cc   |  2 +-
 .../c-c++-common/gomp/declare-target-indirect-2.c| 10 +-
 gcc/testsuite/c-c++-common/gomp/declare-variant-8.c  |  4 ++--
 gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c  |  2 +-
 gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 | 12 ++--
 8 files changed, 15 insertions(+), 34 deletions(-)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index f9b229aba7f..7f74c25d3d7 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -574,8 +574,6 @@ const struct attribute_spec c_common_gnu_attributes[] =
  handle_omp_declare_target_attribute, NULL },
   { "omp declare target nohost", 0, 0, true, false, false, false,
  handle_omp_declare_target_attribute, NULL },
-  { "omp declare target block", 0, 0, true, false, false, false,
- handle_omp_declare_target_attribute, NULL },
   { "non overlapping",   0, 0, true, false, false, false,
  handle_non_overlapping_attribute, NULL },
   { "alloc_align",   1, 1, false, true, true, false,
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 97f1d346835..e2a62bf2d56 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -5418,12 +5418,8 @@ c_decl_attributes (tree *node, tree attributes, int 
flags)
attributes = tree_cons (get_identifier ("omp declare target implicit"),
NULL_TREE, attributes);
   else
-   {
- attributes = tree_cons (get_identifier ("omp declare target"),
- NULL_TREE, attributes);
- attributes = tree_cons (get_identifier ("omp declare target block"),
- NULL_TREE, attributes);
-   }
+   attributes = tree_cons (get_identifier ("omp declare target"),
+   NULL_TREE, attributes);
   if (TREE_CODE (*node) == FUNCTION_DECL)
{
  int device_type
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 6d674684931..da881e9e797 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1781,13 +1781,8 @@ cplus_decl_attributes (tree *decl, tree attributes, int 
flags)
  = tree_cons (get_identifier ("omp declare target implicit"),
   NULL_TREE, attributes);
  else
-   {
- attributes = tree_cons (get_identifier ("omp declare target"),
- NULL_TREE, attributes);
- attributes
-   = tree_cons (get_identifier ("omp declare target block"),
-NULL_TREE, attributes);
-   }
+   attributes = tree_cons (get_identifier ("omp declare target"),
+   NULL_TREE, attributes);
  if (TREE_CODE (*decl) == FUNCTION_DECL)
{

[PATCH v3 07/12] OpenMP: Fortran front-end support for metadirectives.

2024-07-20 Thread Sandra Loosemore
This patch adds support for metadirectives to the Fortran front end.

gcc/fortran/ChangeLog
* decl.cc (gfc_match_end): Handle metadirectives.
* dump-parse-tree.cc (show_omp_node): Likewise.
(show_code_node): Likewise.
* gfortran.h (enum gfc_statement): Add ST_OMP_METADIRECTIVE.
(struct gfc_omp_clauses): Rename target_first_st_is_teams field to
target_first_st_is_teams_or_meta.
(struct gfc_omp_variant): New.
(struct gfc_st_label): Add omp_region field.
(gfc_exec_op): Add EXEC_OMP_METADIRECTIVE.
(struct gfc_code): Add omp_variants field.
(gfc_free_omp_variants): Declare.
(match_omp_directive): Declare.
(is_omp_declarative_stmt): Declare.
* io.cc (format_asterisk): Add initializer for new omp_region field.
* match.h (gfc_match_omp_begin_metadirective): Declare.
(gfc_match_omp_metadirective): Declare.
* openmp.cc (gfc_match_omp_eos): Special case for matching an
OpenMP context selector.
(gfc_free_omp_variants): New.
(gfc_match_omp_clauses): Remove context_selector parameter.
(match_omp): Adjust call to gfc_match_omp_clauses.
(gfc_match_omp_context_selector): Add metadirective_p parameter.
Adjust error-checking logic and calls to gfc_match_omp_clauses.
Set gfc_matching_omp_context_selector.
(gfc_match_omp_context_selector_specification): Generalize to take
a set selector list pointer as parameter, instead of a
declare variant pointer.
(gfc_match_omp_declare_variant): Adjust call to match above change.
(match_omp_metadirective): New.
(gfc_match_omp_begin_metadirective): New.
(gfc_match_omp_metadirective): New.
(resolve_omp_metadirective): New.
(resolve_omp_target): Handle metadirectives.
(gfc_resolve_omp_directive): Handle metadirectives.
* parse.cc (gfc_matching_omp_context_selector): New.
(gfc_in_metadirective_body): New.
(gfc_omp_region_count): New.
(decode_omp_directive): Handle "begin metadirective", "end
metadirective", and "metadirective".
(match_omp_directive): New.
(case_omp_structured_block): New define.
(case_omp_do): New define.
(gfc_ascii_statement): Handle ST_OMP_BEGIN_METADIRECTIVE,
ST_OMP_END_METADIRECTIVE, and ST_OMP_METADIRECTIVE.
(accept_statement): Handle ST_OMP_BEGIN_METADIRECTIVE and
ST_OMP_METADIRECTIVE.
(gfc_omp_end_stmt): New.
(parse_omp_do): Use gfc_omp_end_stmt.  Special-case
"omp end metadirective" to end the current construct.
(parse_omp_structured_block): Likewise.  Adjust setting of
target_first_st_is_teams_or_meta flag.
(parse_omp_metadirective_body): New.
(parse_executable): Handle metadirectives.  Use
case_omp_structured_block and case_omp_do here.
(gfc_parse_file): Initialize gfc_omp_region_count,
gfc_in_metadirective_body, and gfc_matching_omp_context_selector.
(is_omp_declarative_stmt): New.
* parse.h (enum gfc_compile_state): Add metadirective constructs.
(gfc_omp_end_stmt): Declare.
(gfc_matching_omp_context_selector): Declare.
(gfc_in_metadirective_body): Declare.
(gfc_omp_region_count): Declare.
* resolve.cc (gfc_resolve_code): Handle EXEC_OMP_METADIRECTIVE.
* st.cc (gfc_free_statement): Handle EXEC_OMP_METADIRECTIVE.
* symbol.cc (compare_st_labels): Compare omp_region, not just the
value.
(gfc_get_st_label): Likewise.  Initialize the omp_region field when
creating a new label.
* trans-decl.cc (gfc_get_label_decl): Encode the omp_region in the
label name.
* trans-openmp.cc (gfc_trans_omp_directive): Handle
EXEC_OMP_METADIRECTIVE.
(gfc_trans_omp_set_selector): New, split from...
(gfc_trans_omp_declare_variant): ...here.
(gfc_trans_omp_metadirective): New.
* trans-stmt.h (gfc_trans_omp_metadirective): Declare.
* trans.cc (trans_code): Handle EXEC_OMP_METADIRECTIVE.

gcc/testsuite/ChangeLog

* gfortran.dg/gomp/metadirective-1.f90: New.
* gfortran.dg/gomp/metadirective-10.f90: New.
* gfortran.dg/gomp/metadirective-11.f90: New.
* gfortran.dg/gomp/metadirective-2.f90: New.
* gfortran.dg/gomp/metadirective-3.f90: New.
* gfortran.dg/gomp/metadirective-4.f90: New.
* gfortran.dg/gomp/metadirective-5.f90: New.
* gfortran.dg/gomp/metadirective-6.f90: New.
* gfortran.dg/gomp/metadirective-7.f90: New.
* gfortran.dg/gomp/metadirective-8.f90: New.
* gfortran.dg/gomp/metadirective-9.f90: New.
* gfortran.dg/gomp/metadirective-construct.f90: New.
* gfortran.dg/gomp/metadirective-no-score.f90: New.
* gfortran.dg/gomp/pure-1.f90: Add metadirective test.
* gfortran.dg/gom

Re: [patch,avr] Support new built-in for faster mask computation

2024-07-20 Thread Jeff Law




On 7/20/24 11:27 AM, Georg-Johann Lay wrote:



Hi Jeff,

at least combiner patterns won't work.  For something like

var |= 1 << (off & 7)

insn combine is just getting lost; it tries expressions with
MEM, IOR, even PARALLELs, but nothing that's close to a rotation.
Also it doesn't break out memory regerences (presumably because it
has no scratch reg available).  It is getting even worse for
I just added these to the RISC-V backend a few weeks back using combiner 
patterns.




var &= ~ (1 << (off & 7))

avr.md has rotlqi3 but no tries are ever made to emit
something like rotl (1, off) or rotr (0x80, off).
It may be a case that generating them in QImode isn't happening for one 
reason or another.  C semantics will often force things to an integer 
type which is exceedingly painful on the riscv64 port.


jeff


Re: [COMMITTED] Tweak pr116003.c to target bitint.

2024-07-20 Thread Andrew MacLeod


On 7/20/24 14:54, Jakub Jelinek wrote:

On Sat, Jul 20, 2024 at 12:57:39PM -0400, Andrew MacLeod wrote:

perhaps easier to just do

That works as well, sure.



Committed.

Andrew
commit 15571d2d54c705f22aced5e972cb463d0593aa3c
Author: Andrew MacLeod 
Date:   Sat Jul 20 12:49:39 2024 -0400

Require bitint575 for pr116003.c

Require a bitint target large enough.

gcc/testsuite/
* gcc.dg/pr116003.c: Require bitint575 target.

diff --git a/gcc/testsuite/gcc.dg/pr116003.c b/gcc/testsuite/gcc.dg/pr116003.c
index 970b1539c48..44e625015b0 100644
--- a/gcc/testsuite/gcc.dg/pr116003.c
+++ b/gcc/testsuite/gcc.dg/pr116003.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target bitint } } */
+/* { dg-do compile { target bitint575 } } */
 /* { dg-options "-O2 -fnon-call-exceptions -fprofile-arcs 
-finstrument-functions -fno-tree-copy-prop" } */
 
 _BitInt(5) b5;


[SH, committed]: Fix outage caused by secondary combine pass (was: Re: [RFC/PATCH] libgcc: sh: Use soft-fp for non-hosted SH3/SH4)

2024-07-20 Thread Oleg Endo
Hi,

I've committed the attached patch to fix the full gcc + libstdc++ build on
sh-elf.

Best regards,
Oleg Endo



On Sat, 2024-07-06 at 07:35 -0600, Jeff Law wrote:
> 
> On 7/5/24 1:28 AM, Sébastien Michelland wrote:
> > Hi Oleg!
> > 
> > > I don't understand why this is being limited to SH3 and SH4 only?
> > > Almost all SH4 systems out there have an FPU (unless special 
> > > configurations
> > > are used).  So I'd say if switching to soft-fp, then for SH-anything, not
> > > just SH3/SH4.
> > > 
> > > If it yields some improvements for some users, I'm all for it.
> > 
> > Yeah I just defaulted to SH3/SH4 conservatively because that's the only 
> > hardware I have. (My main platform also happens to be one of these SH4 
> > without an FPU, the SH4AL-DSP.)
> > 
> > Once this is tested/validated on simulator, I'll happily simplify the 
> > patch to apply to all SH.
> > 
> > > I think it would make sense to test it using sh-sim on SH2 big-endian and
> > > little endian at least, as that doesn't have an FPU and hence would run
> > > tests utilizing soft-fp.
> > > 
> > > After building the toolchain for --target=sh-elf, you can use this to run
> > > the testsuite in the simulator:
> > > 
> > > make -k check RUNTESTFLAGS="--target_board=sh-sim\{-m2/-ml,-m2/-mb}"
> > > 
> > > (add make -j parameter according to you needs -- it will be slow)
> > 
> > Alright, it might take a little bit.
> > 
> > Building the combined tree of gcc/binutils/newlib masters (again 
> > following [1]) gives me an ICE in libstdc++v3/src/libbacktrace, 
> > irrespective of my libgcc change:
> This is almost certainly a poorly written pattern.  I just fixed a bunch 
> of these, but not this one.  Essentially a recent change in the generic 
> parts of the compiler is exposing some bugs in the SH backend. 
> Specifically:
> 
> > ;; Store (negated) T bit as all zeros or ones in a reg.  
> > ;;  subcRn,Rn   ! Rn = Rn - Rn - T; T = T
> > ;;  not Rn,Rn   ! Rn = 0 - Rn
> > ;; 
> > ;; Note the call to sh_split_treg_set_expr may clobber
> > ;; the T reg.  We must express this, even though it's
> > ;; not immediately obvious this pattern changes the
> > ;; T register.
> > (define_insn_and_split "mov_neg_si_t"
> >   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
> > (neg:SI (match_operand 1 "treg_set_expr")))
> >(clobber (reg:SI T_REG))] 
> >   "TARGET_SH1" 
> > {
> >   gcc_assert (t_reg_operand (operands[1], VOIDmode));
> >   return "subc  %0,%0";
> > }
> >   "&& can_create_pseudo_p () && !t_reg_operand (operands[1], VOIDmode)"
> >   [(const_int 0)]
> > {
> >   sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
> >   emit_insn (gen_mov_neg_si_t (operands[0], get_t_reg_rtx ()));
> > 
> >   if (ti.remove_trailing_nott ())
> > emit_insn (gen_one_cmplsi2 (operands[0], operands[0]));
> > 
> >   DONE; 
> > }
> >   [(set_attr "type" "arith")])
> 
> 
> As written this pattern could match after register allocation is 
> complete and thus we can't create new pseudos (the condition TARGET_SH1 
> controls that behavior).  operands[1] won't necessarily be the T 
> register in that case.
> 
> The split condition fails because we can't create new pseudos, so it's 
> left as-is.  At final assembly time the assertion triggers.
> 
> the "&& can_create_pseudo ()" part of the split condition should be 
> moved into the main condition.  I think that's all that's necessary to 
> fix this problem.  It'd probably be best of Oleg went through the 
> various define_insn_and_split patterns that utilize can_create_pseudo in 
> their split condition and evaluated them.
> 
> I only fixed the most obvious cases in my change from this morning.  I 
> don't typically work on the SH port and for changes which aren't 
> obviously correct, Oleg is in a better position to evaluate the proper fix.
> 
> jeff
From 9e740e7d71d02369774e1380902bddd9681c463f Mon Sep 17 00:00:00 2001
From: Oleg Endo 
Date: Sun, 21 Jul 2024 14:11:21 +0900
Subject: [PATCH] SH: Fix outage caused by recently added 2nd combine pass after reg alloc

I've also confirmed on the CSiBE set that the secondary combine pass is
actually beneficial on SH.  It does result in some code size reductions.

gcc/CHangeLog:
	* config/sh/sh.md (mov_neg_si_t): Allow insn and split after
	register allocation.
	(*treg_noop_move): New insn.
---
 gcc/config/sh/sh.md | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 3e97825..7eee12c 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -8407,21 +8407,29 @@
 {
   gcc_assert (t_reg_operand (operands[1], VOIDmode));
   return "subc	%0,%0";
 }
-  "&& can_create_pseudo_p () && !t_reg_operand (operands[1], VOIDmode)"
+  "&& !t_reg_operand (operands[1], VOIDmode)"
   [(const_int 0)]
 {
   sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
   emit_insn (gen_mov_neg_si_t (operands[0], get_t_reg_rtx ()));
 
   if (ti.remove_trailing_nott ())
 emi

Re: [PATCH] c-family: Introduce the -Winvalid-noreturn flag from clang with extra tuneability

2024-07-20 Thread Julian Waters
HI Jason,

I was hoping to have -Wno-invalid-noreturn=explicit directly disable
explicit noreturn warnings for instance, following the style of the
-Wno-attributes=vendor:: option, while the pattern in
-fstrong-eval-order seems to be that of using RejectNegative and
handling each specified positive case rather than disabling the
unwanted case, which would mean one would have to write
-Winvalid-noreturn=explicit to avoid implicit noreturns, which at
least I found to be less clear. If there was a way to only allow the
-Wno form of a warning option, I feel it would be simpler to implement
this (A positive form like -Winvalid-noreturn=explicit wouldn't make
much sense since gcc already warns for it even without the option, in
my opinion), but I don't think there's a RejectPositive variant of
RejectNegative, unfortunately. I can change it to be more like
-fstrong-eval-order if needed, but I feel that is less clear than just
allowing the user to disable the warning variant directly

I'm a little unsure about the noreturn warnings being a Common warning
now actually, any warnings implemented under the gcc directory and not
under c/c-family/cp is a Common warning right? Just need some
confirmation to be sure

I'll revert the semicolon fix for mingw and propose that separately,
but I'll leave further discussion about the other review comments
raised for this patch for a later time, since it seems to me that I'll
be rewriting the patch again and possibly removing some code that was
reviewed, so I'll save it for when the patch is more stable

best regards,
Julian