[gcc r15-2243] RISC-V: Disable Zba optimization pattern if XTheadMemIdx is enabled

2024-07-24 Thread Christoph Mテシllner via Gcc-cvs
https://gcc.gnu.org/g:9817d29cd66762893782a52b2c304c5083bc0023

commit r15-2243-g9817d29cd66762893782a52b2c304c5083bc0023
Author: Christoph Müllner 
Date:   Tue Jul 23 14:48:02 2024 +0200

RISC-V: Disable Zba optimization pattern if XTheadMemIdx is enabled

It is possible that the Zba optimization pattern zero_extendsidi2_bitmanip
matches for a XTheadMemIdx INSN with the effect of emitting an invalid
instruction as reported in PR116035.

The pattern above is used to emit a zext.w instruction to zero-extend
SI mode registers to DI mode.  A similar functionality can be achieved
by XTheadBb's th.extu instruction.  And indeed, we have the equivalent
pattern in thead.md (zero_extendsidi2_th_extu).  However, that pattern
depends on !TARGET_XTHEADMEMIDX.  To compensate for that, there are
specific patterns that ensure that zero-extension instruction can still
be emitted (th_memidx_bb_zero_extendsidi2 and friends).

While we could implement something similar (th_memidx_zba_zero_extendsidi2)
it would only make sense, if there existed real HW that does implement Zba
and XTheadMemIdx, but not XTheadBb.  Unless such a machine exists, let's
simply disable zero_extendsidi2_bitmanip if XTheadMemIdx is available.

PR target/116035

gcc/ChangeLog:

* config/riscv/bitmanip.md: Disable zero_extendsidi2_bitmanip
for XTheadMemIdx.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr116035-1.c: New test.
* gcc.target/riscv/pr116035-2.c: New test.

Reported-by: Patrick O'Neill 
Signed-off-by: Christoph Müllner 

Diff:
---
 gcc/config/riscv/bitmanip.md|  2 +-
 gcc/testsuite/gcc.target/riscv/pr116035-1.c | 29 +
 gcc/testsuite/gcc.target/riscv/pr116035-2.c | 26 ++
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index d262430485e7..9fc5215d6e35 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -22,7 +22,7 @@
 (define_insn "*zero_extendsidi2_bitmanip"
   [(set (match_operand:DI 0 "register_operand" "=r,r")
(zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "r,m")))]
-  "TARGET_64BIT && TARGET_ZBA"
+  "TARGET_64BIT && TARGET_ZBA && !TARGET_XTHEADMEMIDX"
   "@
zext.w\t%0,%1
lwu\t%0,%1"
diff --git a/gcc/testsuite/gcc.target/riscv/pr116035-1.c 
b/gcc/testsuite/gcc.target/riscv/pr116035-1.c
new file mode 100644
index ..bc45941ff8f0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr116035-1.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Og" "-Os" "-Oz" } } */
+/* { dg-options "-march=rv64g_zba_xtheadmemidx" { target { rv64 } } } */
+/* { dg-options "-march=rv32g_zba_xtheadmemidx" { target { rv32 } } } */
+
+void a(long);
+unsigned b[11];
+void c()
+{
+  for (int d = 0; d < 11; ++d)
+a(b[d]);
+}
+
+#if __riscv_xlen == 64
+unsigned long zext64_32(unsigned int u32)
+{
+  /* Missed optimization for Zba+XTheadMemIdx.  */
+  return u32; //zext.w a0, a0
+}
+#endif
+
+/* { dg-final { scan-assembler "th.lwuia\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" { 
target rv64 } } } */
+/* { dg-final { scan-assembler "th.lwia\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" { 
target rv32 } } } */
+
+/* { dg-final { scan-assembler-not "lwu\t\[a-x0-9\]+,\(\[a-x0-9\]+\),4,0" } } 
*/
+
+/* Missed optimizations for Zba+XTheadMemIdx.  */
+/* { dg-final { scan-assembler "zext.w\t" { target rv64 xfail rv64 } } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/pr116035-2.c 
b/gcc/testsuite/gcc.target/riscv/pr116035-2.c
new file mode 100644
index ..2c1a96948605
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr116035-2.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Og" "-Os" "-Oz" } } */
+/* { dg-options "-march=rv64g_xtheadbb_xtheadmemidx" { target { rv64 } } } */
+/* { dg-options "-march=rv32g_xtheadbb_xtheadmemidx" { target { rv32 } } } */
+
+void a(long);
+unsigned b[11];
+void c()
+{
+  for (int d = 0; d < 11; ++d)
+a(b[d]);
+}
+
+#if __riscv_xlen == 64
+unsigned long zext64_32(unsigned int u32)
+{
+return u32; //th.extu a0, a0, 31, 0
+}
+#endif
+
+/* { dg-final { scan-assembler "th.lwuia\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" { 
target { rv64 } } } } */
+/* { dg-final { scan-assembler "th.lwia\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" { 
target { rv32 } } } } */
+
+/* { dg-final { scan-assembler-not "lwu\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" } 
} */
+
+/* { dg-final { scan-assembler "th.extu\t" { target rv64 } } } */


[gcc r15-2244] [MAINTAINERS] Update email and move to DCO

2024-07-24 Thread Matthew Malcomson via Gcc-cvs
https://gcc.gnu.org/g:93ced50d1cf6ac0855934cbbc5eb08e870d7949c

commit r15-2244-g93ced50d1cf6ac0855934cbbc5eb08e870d7949c
Author: Matthew Malcomson 
Date:   Tue Jul 23 14:56:41 2024 +0100

[MAINTAINERS] Update email and move to DCO

* MAINTAINERS: Update my email address.

Signed-off-by: Matthew Malcomson 

Diff:
---
 MAINTAINERS | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 200a223b431f..542d058d727c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -636,7 +636,7 @@ Luis Machadoluisgpm 

 Ziga Mahkovec   ziga
 Vladimir Makarovvmakarov
 David Malcolm   dmalcolm
-Matthew Malcomson   matmal01
+Matthew Malcomson   matmal01
 Mikhail Maltsev miyuki  
 Jose E. Marchesijemarch 
 Stamatis Markianos-Wright   stammark
@@ -922,6 +922,7 @@ Jeff Law

 Jeff Law
 Jeff Law
 H.J. Lu 
+Matthew Malcomson   
 Immad Mir   
 Gaius Mulley
 Andrew Pinski   


[gcc r15-2245] libstdc++: Clean up @diff@ markup in some I/O tests

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:3216b131656f3056dae587584ad2104cc659aecd

commit r15-2245-g3216b131656f3056dae587584ad2104cc659aecd
Author: Jonathan Wakely 
Date:   Mon Jul 22 13:00:26 2024 +0100

libstdc++: Clean up @diff@ markup in some I/O tests

We have a number of 27_io/* tests with comments like this:

// @require@ %-*.tst
// @diff@ %-*.tst %-*.txt

It seems that these declare required data files used by the test and a
post-test action to compare the test output with the expected result.
We do have tests that depend on some *.tst and/or *.txt files that are
copied from testsuite/data into each test's working directory before it
runs, so the comments are related to those dependencies.  However,
nothing in the current test framework actually makes use of these
comments. Currently, every test gets a fresh copy of every *.tst and
*.txt file in the testsuite/data directory, whether the test actually
requires them or not.

This change is the first in a series to clean up this unused markup in
the tests. This first step is to just remove all @require@ and @diff@
comments where they seem to serve no purpose at all. These tests do not
open any of the *.tst or *.txt files that are copied into the test's
working directory from the testsuite/data directory, so they don't
"require" any of those files, and there's no need to "diff" them after
the test runs.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/4879.cc: Remove
@require@ and @diff@ comments.
* testsuite/27_io/basic_filebuf/close/char/9964.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/3.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/9507.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-io.cc: Likewise.
Remove unused variable.
* testsuite/27_io/basic_filebuf/sputn/char/2-io.cc: Likewise.
* testsuite/27_io/basic_ofstream/cons/char/1.cc: Remove
@require@ and @diff@ comments. Remove unused variables.
* testsuite/27_io/basic_ofstream/rdbuf/char/2832.cc: Remove
* testsuite/27_io/ios_base/sync_with_stdio/2.cc: Likewise.

Diff:
---
 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc  |  4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc  |  4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc  |  4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc   |  4 +---
 .../testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc |  5 +
 .../testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc |  5 +
 .../testsuite/27_io/basic_filebuf/snextc/char/2-out.cc |  5 +
 .../testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc   |  5 +
 .../testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc   |  5 +
 .../testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc  |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc  |  6 +-
 libs

[gcc r15-2246] libstdc++: Replace @require@ markup in some I/O tests

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:dfd07532693c7df9e15920b7607672382122b38c

commit r15-2246-gdfd07532693c7df9e15920b7607672382122b38c
Author: Jonathan Wakely 
Date:   Wed Jul 17 13:27:19 2024 +0100

libstdc++: Replace @require@ markup in some I/O tests

We can replace the @require@ markup with { dg-additional-files ... }
directives, so that the required files are explicitly named and are
explicitly copied into place for tests that require it. This will allow
a later change to remove the "Copy all required data files" step in the
proc libstdc++_init in testsuite/lib/libstdc++.exp that is marked TODO.
This commit uses dg-additional-files for a subset of the files that
contain @require@.

Also remove the @diff@ markup where appears to be copy & pasted from
other test files, and so serves no purpose. For example, there is no
output file created by 27_io/basic_ifstream/cons/char/1.cc so there is
nothing for @diff@ to compare. Maybe the purpose was to check that
reading the .tst file with an ifstream doesn't change it, but we've
survived without doing those comparisons for many years so I think we
can remove those cases of @diff@ markup.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/2.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files. Remove
unused variable.
* testsuite/27_io/basic_filebuf/close/char/3.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files.
* testsuite/27_io/basic_filebuf/close/char/4.cc: Likewise.
* testsuite/27_io/basic_filebuf/close/char/5.cc: Likewise.
* testsuite/27_io/basic_filebuf/in_avail/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/is_open/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/2.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-io.cc: Likewise.
Remove unused variable.
* testsuite/27_io/basic_filebuf/sputn/char/2-in.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files.
* testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/char/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/char/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/rdbuf/char/2832.cc: Likewise.
* testsuite/27_io/basic_istream/readso

[gcc r15-2247] libstdc++: Use dg-additional-files in some I/O tests

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:687dc787d7523c46a9b5e1e9ac1062e44693dd3a

commit r15-2247-g687dc787d7523c46a9b5e1e9ac1062e44693dd3a
Author: Jonathan Wakely 
Date:   Mon Jul 22 14:01:43 2024 +0100

libstdc++: Use dg-additional-files in some I/O tests

Use the dg-additional-files directive to declare files that need to be
copied into the test's working directory. This is currently redundant
(as all .tst and .txt files are copied for all tests) but is a step
towards not copying all files.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/imbue/char/2.cc: Use
dg-additional-files.
* testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/path.cc: Likewise.
* testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc:
Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/setbuf/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/3.cc: Likewise.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: Likewise.
* testsuite/27_io/basic_fstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_fstream/open/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/assign/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/move.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/wchar_t/1.cc: Likewise.
* testsuite/27_io/objects/char/10.cc: Likewise.
* testsuite/27_io/objects/char/12048-1.cc: Likewise.
* testsuite/27_io/objects/char/12048-2.cc: Likewise.
* testsuite/27_io/objects/char/12048-3.cc: Likewise.
* testsuite/27_io/objects/char/12048-4.cc: Likewise.
* testsuite/27_io/objects/char/12048-5.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-1.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-2.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-3.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-4.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-5.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-1.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-2.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-3.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-4.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc: Likewise.

Diff:
---
 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc| 4 +++-
 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc  | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc   | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc   | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc   | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc   | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc   | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc| 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc  | 1 +
 libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc  | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc   | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc  | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/open/wchar_t/1.cc | 3 ++-
 libstdc++-v3/testsuite/27_io/objects/char/10.cc   | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc  

[gcc r15-2248] libstdc++: Add file-io-diff to replace @diff@ markup in I/O tests

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:515da03a838db05443ebcc4c543a405bed764188

commit r15-2248-g515da03a838db05443ebcc4c543a405bed764188
Author: Jonathan Wakely 
Date:   Mon Jul 22 14:39:57 2024 +0100

libstdc++: Add file-io-diff to replace @diff@ markup in I/O tests

This adds a new dg-final action to compare two files after a test has
run, so that we can verify that fstream operations produce the expected
results. With this change, all uses of @diff@ that seem potentially
useful have been converted to actually compare the files and FAIL if
they differ.

The file-io-diff action can take two arguments naming the files to be
compared, or for convenience it can take a single string and will
compare STR.tst and STR.txt, as that's how it's commonly used.

Additionally, all remaining uses of @require@ are converted to
dg-additional-files directives, so that the TODO in libstdc++.exp can
be resolved.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/1.cc: Remove
@require@ and @diff@. Use dg-final file-io-diff action.
* testsuite/27_io/basic_istream/extractors_other/char/2.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc:
Likewise.
* testsuite/27_io/basic_istream/get/char/2.cc: Likewise.
* testsuite/27_io/basic_istream/get/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istream/ignore/char/3.cc: Likewise.
* testsuite/27_io/basic_istream/ignore/wchar_t/3.cc: Likewise.
* testsuite/27_io/basic_istream/peek/char/6414.cc: Likewise.
* testsuite/27_io/basic_istream/peek/wchar_t/6414.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/char/fstream.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc:
Likewise.
* testsuite/27_io/basic_istream/tellg/char/fstream.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc:
Likewise.
* testsuite/27_io/basic_ofstream/open/char/1.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/1.cc:
Likewise.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc:
Likewise.
* testsuite/27_io/ios_base/sync_with_stdio/1.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/2.cc:
Likewise. Check file positions.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc:
Likewise.
* testsuite/lib/libstdc++.exp (file-io-diff): New proc.

Diff:
---
 .../testsuite/27_io/basic_filebuf/close/char/1.cc  |  6 ++--
 .../27_io/basic_istream/extractors_other/char/2.cc |  9 --
 .../basic_istream/extractors_other/wchar_t/2.cc|  9 --
 .../testsuite/27_io/basic_istream/get/char/2.cc|  8 --
 .../testsuite/27_io/basic_istream/get/wchar_t/2.cc |  8 --
 .../testsuite/27_io/basic_istream/ignore/char/3.cc |  8 --
 .../27_io/basic_istream/ignore/wchar_t/3.cc|  8 --
 .../27_io/basic_istream/peek/char/6414.cc  |  9 --
 .../27_io/basic_istream/peek/wchar_t/6414.cc   |  9 --
 .../27_io/basic_istream/seekg/char/fstream.cc  | 10 +--
 .../27_io/basic_istream/seekg/wchar_t/fstream.cc   | 12 +---
 .../27_io/basic_istream/tellg/char/fstream.cc  | 10 +--
 .../27_io/basic_istream/tellg/wchar_t/fstream.cc   | 10 +--
 .../testsuite/27_io/basic_ofstream/open/char/1.cc  |  5 ++--
 .../27_io/basic_ostream/inserters_other/char/1.cc  |  8 --
 .../27_io/basic_ostream/inserters_other/char/2.cc  |  7 +++--
 .../basic_ostream/inserters_other/wchar_t/1.cc |  8 --
 .../basic_ostream/inserters_other/wchar_t/2.cc |  7 +++--
 .../testsuite/27_io/ios_base/sync_with_stdio/1.cc  |  5 ++--
 libstdc++-v3/testsuite/lib/libstdc++.exp   | 32 ++
 20 files changed, 131 insertions(+), 57 deletions(-)

diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc 
b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
index e2b336a711d6..d9e9c53e3e6e 100644
--- a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
@@ -15,14 +15,14 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 27.8.1.3 filebuf member functions
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.8.1.3 filebuf member functions
 
 // various tests for filebuf::open() and filebuf::close() including
 // the non-portable functionality in the libstdc++-v3 IO library
 
 // { dg-require-fileio "" }
+// { dg-additional-files "filebuf_members-1.tst filebuf_members-1.txt" }
+// { dg-final { file-io-diff "filebuf_members-1" } }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/27_io/basic_istream/e

[gcc r15-2249] libstdc++: Use dg-additional-files in some algorithm tests

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:681417f7a0044b5603fa7d4db57c5aecc914fc8e

commit r15-2249-g681417f7a0044b5603fa7d4db57c5aecc914fc8e
Author: Jonathan Wakely 
Date:   Mon Jul 22 14:01:43 2024 +0100

libstdc++: Use dg-additional-files in some algorithm tests

Use the dg-additional-files directive to declare files that need to be
copied into the test's working directory. This is currently redundant
(as all .tst and .txt files are copied for all tests) but is a step
towards not copying all files.

libstdc++-v3/ChangeLog:

* testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc:
Use dg-additional-files.
* testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc:
Likewise.
* testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc:
Likewise.
* testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc:
Likewise.
* testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc:
Likewise.
* testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc:
Likewise.
* testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc:
Likewise.
* testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc:
Likewise.

Diff:
---
 .../testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc   | 1 +
 .../testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc| 1 +
 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc  | 1 +
 .../testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc| 1 +
 libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc | 1 +
 libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc | 1 +
 libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc | 1 +
 .../testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc   | 1 +
 8 files changed, 8 insertions(+)

diff --git 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
index 1a0635c0ccaa..c5414d4975dc 100644
--- 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
+++ 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
index 823e275da19f..c2fd748cbf09 100644
--- 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
+++ 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
index 67888797047b..3d1c7c7595d8 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
@@ -27,6 +27,7 @@
 #include 
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 // In the occasion of libstdc++/25482
 void test01()
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
index e1adccfdd216..8d380052313d 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
@@ -18,6 +18,7 @@
 // .
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
index 5179d78b455d..a437bedb420b 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
@@ -1,5 +1,6 @@
 // { dg-do run { target c++11 } }
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
 //
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc
index 14f58998fefa..1353282f6a04 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambu

[gcc r15-2250] libstdc++: Use dg-additional-files in some non-I/O tests

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:171af3580de54d482c6a32fb249e96000a9e10b8

commit r15-2250-g171af3580de54d482c6a32fb249e96000a9e10b8
Author: Jonathan Wakely 
Date:   Mon Jul 22 15:15:16 2024 +0100

libstdc++: Use dg-additional-files in some non-I/O tests

libstdc++-v3/ChangeLog:

* testsuite/20_util/hash/chi2_q_document_words.cc: Use
dg-additional-files for input text.
* testsuite/performance/ext/pb_ds/all_text_find.cc: Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_find.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_insert.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_join.cc:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_modify.hpp: 
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_pop_mem.cc: 
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_push.cc:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_push_pop.cc: 
Likewise.
* testsuite/performance/ext/pb_ds/tree_text_insert.cc: Likewise.
* testsuite/performance/ext/pb_ds/tree_text_lor_find.cc:
Likewise.

Diff:
---
 libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc| 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc   | 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp | 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp   | 2 ++
 .../testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp| 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_join.cc | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_modify.hpp  | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_pop_mem.cc  | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_push.cc | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_push_pop.cc | 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_insert.cc| 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_lor_find.cc  | 2 ++
 12 files changed, 24 insertions(+)

diff --git a/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc 
b/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
index a6ebc0011eba..3c77527c27ce 100644
--- a/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
+++ b/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
@@ -19,6 +19,8 @@
 // along with this library; see the file COPYING3.  If not see
 // .
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 #include "chi2_quality.h"
 
 // Tests chi^2 for a set of words taken from a document written in English.
diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
index 13c73a76647d..df822c3d5f78 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file text_find_timing_test.cpp
  * Contains test for finding text.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
index 18e383ea17c6..dbaaf04a1b64 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file multimap_text_find_timing_test.cpp
  * Contains test for inserting text words.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
index 737be39a154b..2c86b52f30a2 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file multimap_text_insert_timing_test.cpp
  * Contains test for inserting text words.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp
index 9ce235381bd8..ab755312c69a 100644
--- a/l

[gcc r15-2251] libstdc++: Stop copying all data files into test directory

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:cee008380b85bd1cac9c8a5b64266388471ec026

commit r15-2251-gcee008380b85bd1cac9c8a5b64266388471ec026
Author: Jonathan Wakely 
Date:   Mon Jul 22 14:07:32 2024 +0100

libstdc++: Stop copying all data files into test directory

This removes the TODO in libstdc++_init, so that we don't copy all *.tst
and *.txt files from testsuite/data into every test's working directory.
Instead, only the necessary files declared with dg-additional-files are
copied.

libstdc++-v3/ChangeLog:

* testsuite/lib/libstdc++.exp (libstdc++_init): Do not copy all
data files into test directory.

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

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
b/libstdc++-v3/testsuite/lib/libstdc++.exp
index ef511949c7bc..4bf88e72d051 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -158,11 +158,6 @@ proc libstdc++_init { testfile } {
 global dg-do-what-default
 set dg-do-what-default run
 
-# Copy all required data files.
-# TODO: Use dg-additional-files in individual tests instead of doing this.
-v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
-v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
-
 set ld_library_path_tmp ""
 
 # Locate libgcc.a so we don't need to account for different values of


[gcc r15-2252] libstdc++: Rename tests [PR12048]

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:4efe43a61334e231bcd3cf9150cd844dbdf9ed20

commit r15-2252-g4efe43a61334e231bcd3cf9150cd844dbdf9ed20
Author: Jonathan Wakely 
Date:   Mon Jul 22 15:50:19 2024 +0100

libstdc++: Rename tests [PR12048]

These have the wrong PR number in the filenames.

libstdc++-v3/ChangeLog:

PR libstdc++/12048
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc: ...here.

Diff:
---
 .../testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-1.cc => 12048-1.cc}   | 0
 .../testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-2.cc => 12048-2.cc}   | 0
 .../testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-3.cc => 12048-3.cc}   | 0
 .../testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-4.cc => 12048-4.cc}   | 0
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc


[gcc r15-2253] aarch64: Fuse CMP+CSEL and CMP+CSET for -mcpu=neoverse-v2

2024-07-24 Thread Kyrylo Tkachov via Gcc-cvs
https://gcc.gnu.org/g:4c5eb66e701bc9f3bf1298269f52559b10d63a09

commit r15-2253-g4c5eb66e701bc9f3bf1298269f52559b10d63a09
Author: Jennifer Schmitz 
Date:   Mon Jul 22 23:24:45 2024 -0700

aarch64: Fuse CMP+CSEL and CMP+CSET for -mcpu=neoverse-v2

According to the Neoverse V2 Software Optimization Guide (section 4.14), the
instruction pairs CMP+CSEL and CMP+CSET can be fused, which had not been
implemented so far. This patch implements and tests the two fusion pairs.

The patch was bootstrapped and regtested on aarch64-linux-gnu, no 
regression.
There was also no non-noise impact on SPEC CPU2017 benchmark.
OK for mainline?

Signed-off-by: Jennifer Schmitz 

gcc/

* config/aarch64/aarch64.cc (aarch_macro_fusion_pair_p): Implement
fusion logic.
* config/aarch64/aarch64-fusion-pairs.def (cmp+csel): New entry.
(cmp+cset): Likewise.
* config/aarch64/tuning_models/neoversev2.h: Enable logic in
field fusible_ops.

gcc/testsuite/

* gcc.target/aarch64/cmp_csel_fuse.c: New test.
* gcc.target/aarch64/cmp_cset_fuse.c: Likewise.

Diff:
---
 gcc/config/aarch64/aarch64-fusion-pairs.def  |  2 ++
 gcc/config/aarch64/aarch64.cc| 19 +
 gcc/config/aarch64/tuning_models/neoversev2.h|  5 +++-
 gcc/testsuite/gcc.target/aarch64/cmp_csel_fuse.c | 34 
 gcc/testsuite/gcc.target/aarch64/cmp_cset_fuse.c | 31 +
 5 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/aarch64-fusion-pairs.def 
b/gcc/config/aarch64/aarch64-fusion-pairs.def
index 9a43b0c80657..bf5e85ba8fe1 100644
--- a/gcc/config/aarch64/aarch64-fusion-pairs.def
+++ b/gcc/config/aarch64/aarch64-fusion-pairs.def
@@ -37,5 +37,7 @@ AARCH64_FUSION_PAIR ("aes+aesmc", AES_AESMC)
 AARCH64_FUSION_PAIR ("alu+branch", ALU_BRANCH)
 AARCH64_FUSION_PAIR ("alu+cbz", ALU_CBZ)
 AARCH64_FUSION_PAIR ("addsub_2reg_const1", ADDSUB_2REG_CONST1)
+AARCH64_FUSION_PAIR ("cmp+csel", CMP_CSEL)
+AARCH64_FUSION_PAIR ("cmp+cset", CMP_CSET)
 
 #undef AARCH64_FUSION_PAIR
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 9e51236ce9fa..db598ebf2c79 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -27348,6 +27348,25 @@ aarch_macro_fusion_pair_p (rtx_insn *prev, rtx_insn 
*curr)
   && reg_referenced_p (SET_DEST (prev_set), PATTERN (curr)))
 return true;
 
+  /* FUSE CMP and CSEL.  */
+  if (aarch64_fusion_enabled_p (AARCH64_FUSE_CMP_CSEL)
+  && prev_set && curr_set
+  && GET_CODE (SET_SRC (prev_set)) == COMPARE
+  && GET_CODE (SET_SRC (curr_set)) == IF_THEN_ELSE
+  && REG_P (XEXP (SET_SRC (curr_set), 1))
+  && REG_P (XEXP (SET_SRC (curr_set), 2))
+  && reg_referenced_p (SET_DEST (prev_set), PATTERN (curr)))
+return true;
+
+  /* Fuse CMP and CSET.  */
+  if (aarch64_fusion_enabled_p (AARCH64_FUSE_CMP_CSET)
+  && prev_set && curr_set
+  && GET_CODE (SET_SRC (prev_set)) == COMPARE
+  && GET_RTX_CLASS (GET_CODE (SET_SRC (curr_set))) == RTX_COMPARE
+  && REG_P (SET_DEST (curr_set))
+  && reg_referenced_p (SET_DEST (prev_set), PATTERN (curr)))
+return true;
+
   /* Fuse flag-setting ALU instructions and conditional branch.  */
   if (aarch64_fusion_enabled_p (AARCH64_FUSE_ALU_BRANCH)
   && any_condjump_p (curr))
diff --git a/gcc/config/aarch64/tuning_models/neoversev2.h 
b/gcc/config/aarch64/tuning_models/neoversev2.h
index f76e4ef358f7..ae99fab22d80 100644
--- a/gcc/config/aarch64/tuning_models/neoversev2.h
+++ b/gcc/config/aarch64/tuning_models/neoversev2.h
@@ -221,7 +221,10 @@ static const struct tune_params neoversev2_tunings =
 2 /* store_pred.  */
   }, /* memmov_cost.  */
   5, /* issue_rate  */
-  (AARCH64_FUSE_AES_AESMC | AARCH64_FUSE_CMP_BRANCH), /* fusible_ops  */
+  (AARCH64_FUSE_AES_AESMC
+   | AARCH64_FUSE_CMP_BRANCH
+   | AARCH64_FUSE_CMP_CSEL
+   | AARCH64_FUSE_CMP_CSET), /* fusible_ops  */
   "32:16", /* function_align.  */
   "4", /* jump_align.  */
   "32:16", /* loop_align.  */
diff --git a/gcc/testsuite/gcc.target/aarch64/cmp_csel_fuse.c 
b/gcc/testsuite/gcc.target/aarch64/cmp_csel_fuse.c
new file mode 100644
index ..f5e511e46737
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/cmp_csel_fuse.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcpu=neoverse-v2" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+/*
+** f1:
+** ...
+** cmp w[0-9]+, w[0-9]+
+** cselw[0-9]+, w[0-9]+, w[0-9]+, le
+** ret
+*/
+int f1 (int a, int b, int c)
+{
+  int cmp = a > b;
+  int add1 = c + 3;
+  int add2 = c + 8;
+  return cmp ? add1 : add2;
+}
+
+/*
+** f2:
+** ...
+** cmp x[0-9]+, x[0-9]+
+** cselx[0-9]+, x[0-9]+, x[0-9]+, le
+** ret
+*/
+long long f2 (long long a, long long b, long long c)
+{
+  long lon

[gcc r15-2254] Revert "aarch64: Fuse CMP+CSEL and CMP+CSET for -mcpu=neoverse-v2"

2024-07-24 Thread Kyrylo Tkachov via Gcc-cvs
https://gcc.gnu.org/g:39562dd1e745c7aacc23b51b2849a7d346cbef14

commit r15-2254-g39562dd1e745c7aacc23b51b2849a7d346cbef14
Author: Kyrylo Tkachov 
Date:   Wed Jul 24 17:25:43 2024 +0530

Revert "aarch64: Fuse CMP+CSEL and CMP+CSET for -mcpu=neoverse-v2"

This reverts commit 4c5eb66e701bc9f3bf1298269f52559b10d63a09.

Diff:
---
 gcc/config/aarch64/aarch64-fusion-pairs.def  |  2 --
 gcc/config/aarch64/aarch64.cc| 19 -
 gcc/config/aarch64/tuning_models/neoversev2.h|  5 +---
 gcc/testsuite/gcc.target/aarch64/cmp_csel_fuse.c | 34 
 gcc/testsuite/gcc.target/aarch64/cmp_cset_fuse.c | 31 -
 5 files changed, 1 insertion(+), 90 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-fusion-pairs.def 
b/gcc/config/aarch64/aarch64-fusion-pairs.def
index bf5e85ba8fe1..9a43b0c80657 100644
--- a/gcc/config/aarch64/aarch64-fusion-pairs.def
+++ b/gcc/config/aarch64/aarch64-fusion-pairs.def
@@ -37,7 +37,5 @@ AARCH64_FUSION_PAIR ("aes+aesmc", AES_AESMC)
 AARCH64_FUSION_PAIR ("alu+branch", ALU_BRANCH)
 AARCH64_FUSION_PAIR ("alu+cbz", ALU_CBZ)
 AARCH64_FUSION_PAIR ("addsub_2reg_const1", ADDSUB_2REG_CONST1)
-AARCH64_FUSION_PAIR ("cmp+csel", CMP_CSEL)
-AARCH64_FUSION_PAIR ("cmp+cset", CMP_CSET)
 
 #undef AARCH64_FUSION_PAIR
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index db598ebf2c79..9e51236ce9fa 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -27348,25 +27348,6 @@ aarch_macro_fusion_pair_p (rtx_insn *prev, rtx_insn 
*curr)
   && reg_referenced_p (SET_DEST (prev_set), PATTERN (curr)))
 return true;
 
-  /* FUSE CMP and CSEL.  */
-  if (aarch64_fusion_enabled_p (AARCH64_FUSE_CMP_CSEL)
-  && prev_set && curr_set
-  && GET_CODE (SET_SRC (prev_set)) == COMPARE
-  && GET_CODE (SET_SRC (curr_set)) == IF_THEN_ELSE
-  && REG_P (XEXP (SET_SRC (curr_set), 1))
-  && REG_P (XEXP (SET_SRC (curr_set), 2))
-  && reg_referenced_p (SET_DEST (prev_set), PATTERN (curr)))
-return true;
-
-  /* Fuse CMP and CSET.  */
-  if (aarch64_fusion_enabled_p (AARCH64_FUSE_CMP_CSET)
-  && prev_set && curr_set
-  && GET_CODE (SET_SRC (prev_set)) == COMPARE
-  && GET_RTX_CLASS (GET_CODE (SET_SRC (curr_set))) == RTX_COMPARE
-  && REG_P (SET_DEST (curr_set))
-  && reg_referenced_p (SET_DEST (prev_set), PATTERN (curr)))
-return true;
-
   /* Fuse flag-setting ALU instructions and conditional branch.  */
   if (aarch64_fusion_enabled_p (AARCH64_FUSE_ALU_BRANCH)
   && any_condjump_p (curr))
diff --git a/gcc/config/aarch64/tuning_models/neoversev2.h 
b/gcc/config/aarch64/tuning_models/neoversev2.h
index ae99fab22d80..f76e4ef358f7 100644
--- a/gcc/config/aarch64/tuning_models/neoversev2.h
+++ b/gcc/config/aarch64/tuning_models/neoversev2.h
@@ -221,10 +221,7 @@ static const struct tune_params neoversev2_tunings =
 2 /* store_pred.  */
   }, /* memmov_cost.  */
   5, /* issue_rate  */
-  (AARCH64_FUSE_AES_AESMC
-   | AARCH64_FUSE_CMP_BRANCH
-   | AARCH64_FUSE_CMP_CSEL
-   | AARCH64_FUSE_CMP_CSET), /* fusible_ops  */
+  (AARCH64_FUSE_AES_AESMC | AARCH64_FUSE_CMP_BRANCH), /* fusible_ops  */
   "32:16", /* function_align.  */
   "4", /* jump_align.  */
   "32:16", /* loop_align.  */
diff --git a/gcc/testsuite/gcc.target/aarch64/cmp_csel_fuse.c 
b/gcc/testsuite/gcc.target/aarch64/cmp_csel_fuse.c
deleted file mode 100644
index f5e511e46737..
--- a/gcc/testsuite/gcc.target/aarch64/cmp_csel_fuse.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-O2 -mcpu=neoverse-v2" } */
-/* { dg-final { check-function-bodies "**" "" } } */
-
-/*
-** f1:
-** ...
-** cmp w[0-9]+, w[0-9]+
-** cselw[0-9]+, w[0-9]+, w[0-9]+, le
-** ret
-*/
-int f1 (int a, int b, int c)
-{
-  int cmp = a > b;
-  int add1 = c + 3;
-  int add2 = c + 8;
-  return cmp ? add1 : add2;
-}
-
-/*
-** f2:
-** ...
-** cmp x[0-9]+, x[0-9]+
-** cselx[0-9]+, x[0-9]+, x[0-9]+, le
-** ret
-*/
-long long f2 (long long a, long long b, long long c)
-{
-  long long cmp = a > b;
-  long long add1 = c + 3;
-  long long add2 = c + 8;
-  return cmp ? add1 : add2;
-}
-
diff --git a/gcc/testsuite/gcc.target/aarch64/cmp_cset_fuse.c 
b/gcc/testsuite/gcc.target/aarch64/cmp_cset_fuse.c
deleted file mode 100644
index 04f1ce2773ba..
--- a/gcc/testsuite/gcc.target/aarch64/cmp_cset_fuse.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-O2 -mcpu=neoverse-v2" } */
-/* { dg-final { check-function-bodies "**" "" } } */
-
-/*
-** f1:
-** cmp w[0-9]+, w[0-9]+
-** csetw[0-9]+, gt
-** ...
-*/
-int g;
-int f1 (int a, int b)
-{
-  int cmp = a > b;
-  g = cmp + 1;
-  return cmp;
-}
-
-/*
-** f2:
-** cmp x[0-9]+, x[0-9]+
-** csetx[0-9]+, gt
-** ...
-*/
-long long h;
-long long f2 (long long a, long long b)
-{
-  long long cmp = a > b;
-  h = cmp + 1;
-  retur

[gcc r15-2255] tree-optimization/116057 - wrong code with CCP and vector CTORs

2024-07-24 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:1ea551514b9c285d801ac5ab8d78b22483ff65af

commit r15-2255-g1ea551514b9c285d801ac5ab8d78b22483ff65af
Author: Richard Biener 
Date:   Wed Jul 24 13:16:35 2024 +0200

tree-optimization/116057 - wrong code with CCP and vector CTORs

The following fixes an issue with CCPs likely_value when faced with
a vector CTOR containing undef SSA names and constants.  This should
be classified as CONSTANT and not UNDEFINED.

PR tree-optimization/116057
* tree-ssa-ccp.cc (likely_value): Also walk CTORs in stmt
operands to look for constants.

* gcc.dg/torture/pr116057.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr116057.c | 20 
 gcc/tree-ssa-ccp.cc | 11 +++
 2 files changed, 31 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr116057.c 
b/gcc/testsuite/gcc.dg/torture/pr116057.c
new file mode 100644
index ..a7021c8e746e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr116057.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-additional-options "-Wno-psabi" } */
+
+#define vect8 __attribute__((vector_size(8)))
+
+vect8 int __attribute__((noipa))
+f(int a)
+{
+  int b;
+  vect8 int t={1,1};
+  if(a) return t;
+  return (vect8 int){0, b};
+}
+
+int main ()
+{
+  if (f(0)[0] != 0)
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
index de83d26d311a..44711018e0ef 100644
--- a/gcc/tree-ssa-ccp.cc
+++ b/gcc/tree-ssa-ccp.cc
@@ -762,6 +762,17 @@ likely_value (gimple *stmt)
continue;
   if (is_gimple_min_invariant (op))
has_constant_operand = true;
+  else if (TREE_CODE (op) == CONSTRUCTOR)
+   {
+ unsigned j;
+ tree val;
+ FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (op), j, val)
+   if (CONSTANT_CLASS_P (val))
+ {
+   has_constant_operand = true;
+   break;
+ }
+   }
 }
 
   if (has_constant_operand)


[gcc r12-10638] rs6000: Update ELFv2 stack frame comment showing the correct ROP save location

2024-07-24 Thread Peter Bergner via Gcc-cvs
https://gcc.gnu.org/g:2647b9e052eafbbec1094558167be9a24e2d8221

commit r12-10638-g2647b9e052eafbbec1094558167be9a24e2d8221
Author: Peter Bergner 
Date:   Fri Jun 7 16:03:08 2024 -0500

rs6000: Update ELFv2 stack frame comment showing the correct ROP save 
location

The ELFv2 stack frame layout comment in rs6000-logue.cc shows the ROP
hash save slot in the wrong location.  Update the comment to show the
correct ROP hash save location in the frame.

2024-06-07  Peter Bergner  

gcc/
* config/rs6000/rs6000-logue.cc (rs6000_stack_info): Update comment.

(cherry picked from commit e91cf26a954a5c1bf431e36f3a1e69f94e9fa4fe)

Diff:
---
 gcc/config/rs6000/rs6000-logue.cc | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-logue.cc 
b/gcc/config/rs6000/rs6000-logue.cc
index 33077b72611c..270f41573757 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -595,21 +595,21 @@ rs6000_savres_strategy (rs6000_stack_t *info,
+---+
| Parameter save area (+padding*) (P)   |  32
+---+
-   | Optional ROP hash slot (R)|  32+P
+   | Alloca space (A)  |  32+P
+---+
-   | Alloca space (A)  |  32+P+R
+   | Local variable space (L)  |  32+P+A
+---+
-   | Local variable space (L)  |  32+P+R+A
+   | Optional ROP hash slot (R)|  32+P+A+L
+---+
-   | Save area for AltiVec registers (W)   |  32+P+R+A+L
+   | Save area for AltiVec registers (W)   |  32+P+A+L+R
+---+
-   | AltiVec alignment padding (Y) |  32+P+R+A+L+W
+   | AltiVec alignment padding (Y) |  32+P+A+L+R+W
+---+
-   | Save area for GP registers (G)|  32+P+R+A+L+W+Y
+   | Save area for GP registers (G)|  32+P+A+L+R+W+Y
+---+
-   | Save area for FP registers (F)|  32+P+R+A+L+W+Y+G
+   | Save area for FP registers (F)|  32+P+A+L+R+W+Y+G
+---+
-   old SP->| back chain to caller's caller |  32+P+R+A+L+W+Y+G+F
+   old SP->| back chain to caller's caller |  32+P+A+L+R+W+Y+G+F
+---+
 
  * If the alloca area is present, the parameter save area is


[gcc r12-10639] rs6000: Compute rop_hash_save_offset for non-Altivec compiles [PR115389]

2024-07-24 Thread Peter Bergner via Gcc-cvs
https://gcc.gnu.org/g:60e513cd47aadd8f139079f8388b14930e6e0913

commit r12-10639-g60e513cd47aadd8f139079f8388b14930e6e0913
Author: Peter Bergner 
Date:   Fri Jun 14 14:36:20 2024 -0500

rs6000: Compute rop_hash_save_offset for non-Altivec compiles [PR115389]

We currently only compute the offset for the ROP hash save location in
the stack frame for Altivec compiles.  For non-Altivec compiles when we
emit ROP mitigation instructions, we use a default offset of zero which
corresponds to the backchain save location which will get clobbered on
any call.  The fix is to compute the ROP hash save location for all
compiles.

2024-06-14  Peter Bergner  

gcc/
PR target/115389
* config/rs6000/rs6000-logue.cc (rs6000_stack_info): Compute
rop_hash_save_offset for non-Altivec compiles.

gcc/testsuite
PR target/115389
* gcc.target/powerpc/pr115389.c: New test.

(cherry picked from commit c70eea0dba5f223d49c80cfb3e80e87b74330aac)

Diff:
---
 gcc/config/rs6000/rs6000-logue.cc   |  9 -
 gcc/testsuite/gcc.target/powerpc/pr115389.c | 17 +
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-logue.cc 
b/gcc/config/rs6000/rs6000-logue.cc
index 270f41573757..3894bd23d179 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -821,17 +821,16 @@ rs6000_stack_info (void)
  gcc_assert (info->altivec_size == 0
  || info->altivec_save_offset % 16 == 0);
 
- /* Adjust for AltiVec case.  */
- info->ehrd_offset = info->altivec_save_offset - ehrd_size;
-
  /* Adjust for ROP protection.  */
  info->rop_hash_save_offset
= info->altivec_save_offset - info->rop_hash_size;
- info->ehrd_offset -= info->rop_hash_size;
}
   else
-   info->ehrd_offset = info->gp_save_offset - ehrd_size;
+ /* Adjust for ROP protection.  */
+ info->rop_hash_save_offset
+   = info->gp_save_offset - info->rop_hash_size;
 
+  info->ehrd_offset = info->rop_hash_save_offset - ehrd_size;
   info->ehcr_offset = info->ehrd_offset - ehcr_size;
   info->cr_save_offset = reg_size; /* first word when 64-bit.  */
   info->lr_save_offset = 2*reg_size;
diff --git a/gcc/testsuite/gcc.target/powerpc/pr115389.c 
b/gcc/testsuite/gcc.target/powerpc/pr115389.c
new file mode 100644
index ..a091ee8a1be0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr115389.c
@@ -0,0 +1,17 @@
+/* PR target/115389 */
+/* { dg-do assemble } */
+/* { dg-options "-O2 -mdejagnu-cpu=power10 -mrop-protect -mno-vsx -mno-altivec 
-mabi=no-altivec -save-temps" } */
+/* { dg-require-effective-target rop_ok } */
+
+/* Verify we do not emit invalid offsets for our ROP insns.  */
+
+extern void foo (void);
+long
+bar (void)
+{
+  foo ();
+  return 0;
+}
+
+/* { dg-final { scan-assembler-times {\mhashst\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mhashchk\M} 1 } } */


[gcc r12-10641] rs6000: Error on CPUs and ABIs that don't support the ROP protection insns [PR114759]

2024-07-24 Thread Peter Bergner via Gcc-cvs
https://gcc.gnu.org/g:25cf4d2a2200903fe868f8cbd9d24f35768041c1

commit r12-10641-g25cf4d2a2200903fe868f8cbd9d24f35768041c1
Author: Peter Bergner 
Date:   Mon Jul 15 16:57:32 2024 -0500

rs6000: Error on CPUs and ABIs that don't support the ROP protection insns 
[PR114759]

We currently silently ignore the -mrop-protect option for old CPUs we don't
support with the ROP hash insns, but we throw an error for unsupported ABIs.
This patch treats unsupported CPUs and ABIs similarly by throwing an error
both both.  This matches clang behavior and allows us to simplify our tests
in the code that generates our prologue and epilogue code.

2024-06-26  Peter Bergner  

gcc/
PR target/114759
* config/rs6000/rs6000.cc (rs6000_option_override_internal): 
Disallow
CPUs and ABIs that do no support the ROP protection insns.
* config/rs6000/rs6000-logue.cc (rs6000_stack_info): Remove now
unneeded tests.
(rs6000_emit_prologue): Likewise.
Remove unneeded gcc_assert.
(rs6000_emit_epilogue): Likewise.
* config/rs6000/rs6000.md: Likewise.

gcc/testsuite/
PR target/114759
* gcc.target/powerpc/pr114759-3.c: New test.

(cherry picked from commit 6f2bab9b5d1ce1914c748b7dcd8638dafaa98df7)

Diff:
---
 gcc/config/rs6000/rs6000-logue.cc | 22 ++
 gcc/config/rs6000/rs6000.cc   | 12 
 gcc/config/rs6000/rs6000.md   |  4 ++--
 gcc/testsuite/gcc.target/powerpc/pr114759-3.c | 19 +++
 4 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-logue.cc 
b/gcc/config/rs6000/rs6000-logue.cc
index 9817ce78639a..d891d43c074e 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -720,17 +720,11 @@ rs6000_stack_info (void)
   info->calls_p = (!crtl->is_leaf || cfun->machine->ra_needs_full_frame);
   info->rop_hash_size = 0;
 
-  if (TARGET_POWER8
-  && info->calls_p
-  && DEFAULT_ABI == ABI_ELFv2
-  && rs6000_rop_protect)
+  /* If we want ROP protection and this function makes a call, indicate
+ we need to create a stack slot to save the hashed return address in.  */
+  if (rs6000_rop_protect
+  && info->calls_p)
 info->rop_hash_size = 8;
-  else if (rs6000_rop_protect && DEFAULT_ABI != ABI_ELFv2)
-{
-  /* We can't check this in rs6000_option_override_internal since
-DEFAULT_ABI isn't established yet.  */
-  error ("%qs requires the ELFv2 ABI", "-mrop-protect");
-}
 
   /* Determine if we need to save the condition code registers.  */
   if (save_reg_p (CR2_REGNO)
@@ -3279,9 +3273,8 @@ rs6000_emit_prologue (void)
   /* NOTE: The hashst isn't needed if we're going to do a sibcall,
  but there's no way to know that here.  Harmless except for
  performance, of course.  */
-  if (TARGET_POWER8 && rs6000_rop_protect && info->rop_hash_size != 0)
+  if (info->rop_hash_size)
 {
-  gcc_assert (DEFAULT_ABI == ABI_ELFv2);
   rtx stack_ptr = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
   rtx addr = gen_rtx_PLUS (Pmode, stack_ptr,
   GEN_INT (info->rop_hash_save_offset));
@@ -5026,12 +5019,9 @@ rs6000_emit_epilogue (enum epilogue_type epilogue_type)
 
   /* The ROP hash check must occur after the stack pointer is restored
  (since the hash involves r1), and is not performed for a sibcall.  */
-  if (TARGET_POWER8
-  && rs6000_rop_protect
-  && info->rop_hash_size != 0
+  if (info->rop_hash_size
   && epilogue_type != EPILOGUE_TYPE_SIBCALL)
 {
-  gcc_assert (DEFAULT_ABI == ABI_ELFv2);
   rtx stack_ptr = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
   rtx addr = gen_rtx_PLUS (Pmode, stack_ptr,
   GEN_INT (info->rop_hash_save_offset));
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 03893b2cf8bd..cf0d089d06ba 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -4888,6 +4888,18 @@ rs6000_option_override_internal (bool global_init_p)
 rs6000_print_builtin_options (stderr, 0, "builtin mask",
  rs6000_builtin_mask);
 
+  /* We only support ROP protection on certain targets.  */
+  if (rs6000_rop_protect)
+{
+  /* Disallow CPU targets we don't support.  */
+  if (!TARGET_POWER8)
+   error ("%<-mrop-protect%> requires %<-mcpu=power8%> or later");
+
+  /* Disallow ABI targets we don't support.  */
+  if (DEFAULT_ABI != ABI_ELFv2)
+   error ("%<-mrop-protect%> requires the ELFv2 ABI");
+}
+
   /* Initialize all of the registers.  */
   rs6000_init_hard_regno_mode_ok (global_init_p);
 
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index d1ae5be96d44..b0614868f942 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs600

[gcc r12-10640] rs6000: ROP - Emit hashst and hashchk insns on Power8 and later [PR114759]

2024-07-24 Thread Peter Bergner via Gcc-cvs
https://gcc.gnu.org/g:aa293f40770bae5e94f33d4700f2f0ce9eff712b

commit r12-10640-gaa293f40770bae5e94f33d4700f2f0ce9eff712b
Author: Peter Bergner 
Date:   Wed Jun 19 16:07:29 2024 -0500

rs6000: ROP - Emit hashst and hashchk insns on Power8 and later [PR114759]

We currently only emit the ROP-protect hash* insns for Power10, where the
insns were added to the architecture.  We want to emit them for earlier
cpus (where they operate as NOPs), so that if those older binaries are
ever executed on a Power10, then they'll be protected from ROP attacks.
Binutils accepts hashst and hashchk back to Power8, so change GCC to emit
them for Power8 and later.  This matches clang's behavior.

2024-06-19  Peter Bergner  

gcc/
PR target/114759
* config/rs6000/rs6000-logue.cc (rs6000_stack_info): Use 
TARGET_POWER8.
(rs6000_emit_prologue): Likewise.
* config/rs6000/rs6000.md (hashchk): Likewise.
(hashst): Likewise.
Fix whitespace.

gcc/testsuite/
PR target/114759
* gcc.target/powerpc/pr114759-2.c: New test.
* lib/target-supports.exp (rop_ok): Use
check_effective_target_has_arch_pwr8.

(cherry picked from commit a05c3d23d1e1c8d2971b123804fc7a61a3561adb)

Diff:
---
 gcc/config/rs6000/rs6000-logue.cc |  6 +++---
 gcc/config/rs6000/rs6000.md   |  6 +++---
 gcc/testsuite/gcc.target/powerpc/pr114759-2.c | 17 +
 gcc/testsuite/lib/target-supports.exp |  2 +-
 4 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-logue.cc 
b/gcc/config/rs6000/rs6000-logue.cc
index 3894bd23d179..9817ce78639a 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -720,7 +720,7 @@ rs6000_stack_info (void)
   info->calls_p = (!crtl->is_leaf || cfun->machine->ra_needs_full_frame);
   info->rop_hash_size = 0;
 
-  if (TARGET_POWER10
+  if (TARGET_POWER8
   && info->calls_p
   && DEFAULT_ABI == ABI_ELFv2
   && rs6000_rop_protect)
@@ -3279,7 +3279,7 @@ rs6000_emit_prologue (void)
   /* NOTE: The hashst isn't needed if we're going to do a sibcall,
  but there's no way to know that here.  Harmless except for
  performance, of course.  */
-  if (TARGET_POWER10 && rs6000_rop_protect && info->rop_hash_size != 0)
+  if (TARGET_POWER8 && rs6000_rop_protect && info->rop_hash_size != 0)
 {
   gcc_assert (DEFAULT_ABI == ABI_ELFv2);
   rtx stack_ptr = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
@@ -5026,7 +5026,7 @@ rs6000_emit_epilogue (enum epilogue_type epilogue_type)
 
   /* The ROP hash check must occur after the stack pointer is restored
  (since the hash involves r1), and is not performed for a sibcall.  */
-  if (TARGET_POWER10
+  if (TARGET_POWER8
   && rs6000_rop_protect
   && info->rop_hash_size != 0
   && epilogue_type != EPILOGUE_TYPE_SIBCALL)
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index c38bebde185b..d1ae5be96d44 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -15557,9 +15557,9 @@
 
 (define_insn "hashst"
   [(set (match_operand:DI 0 "simple_offsettable_mem_operand" "=m")
-(unspec_volatile:DI [(match_operand:DI 1 "int_reg_operand" "r")]
+   (unspec_volatile:DI [(match_operand:DI 1 "int_reg_operand" "r")]
UNSPEC_HASHST))]
-  "TARGET_POWER10 && rs6000_rop_protect"
+  "TARGET_POWER8 && rs6000_rop_protect"
 {
   static char templ[32];
   const char *p = rs6000_privileged ? "p" : "";
@@ -15572,7 +15572,7 @@
   [(unspec_volatile [(match_operand:DI 0 "int_reg_operand" "r")
 (match_operand:DI 1 "simple_offsettable_mem_operand" "m")]
UNSPEC_HASHCHK)]
-  "TARGET_POWER10 && rs6000_rop_protect"
+  "TARGET_POWER8 && rs6000_rop_protect"
 {
   static char templ[32];
   const char *p = rs6000_privileged ? "p" : "";
diff --git a/gcc/testsuite/gcc.target/powerpc/pr114759-2.c 
b/gcc/testsuite/gcc.target/powerpc/pr114759-2.c
new file mode 100644
index ..3881ebd416e6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr114759-2.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mdejagnu-cpu=power8 -mrop-protect" } */
+/* { dg-require-effective-target rop_ok } Only enable on supported ABIs.  */
+
+/* Verify we generate ROP-protect hash insns when compiling for Power8.  */
+
+extern void foo (void);
+
+int
+bar (void)
+{
+  foo ();
+  return 5;
+}
+
+/* { dg-final { scan-assembler-times {\mhashst\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mhashchk\M} 1 } } */
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 64216dfbdb26..ee2fa5ed8a61 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -6752,7 +6752,7 @@ proc check_effective_target_powerpc_elfv2 { } {
 # Return 

[gcc r12-10642] rs6000: Catch unsupported ABI errors when using -mrop-protect [PR114759, PR115988]

2024-07-24 Thread Peter Bergner via Gcc-cvs
https://gcc.gnu.org/g:f7bebf4c07dffaa75c77152e8004aa0ccbf6eeac

commit r12-10642-gf7bebf4c07dffaa75c77152e8004aa0ccbf6eeac
Author: Peter Bergner 
Date:   Thu Jul 18 18:01:46 2024 -0500

rs6000: Catch unsupported ABI errors when using -mrop-protect 
[PR114759,PR115988]

2024-07-18  Peter Bergner  

gcc/testsuite/
PR target/114759
PR target/115988
* gcc.target/powerpc/pr114759-3.c: Catch unsupported ABI errors.

(cherry picked from commit b2f47a5c1d5204131660ea0372a08e692df8844e)

Diff:
---
 gcc/testsuite/gcc.target/powerpc/pr114759-3.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/pr114759-3.c 
b/gcc/testsuite/gcc.target/powerpc/pr114759-3.c
index 6770a9aec3b5..e2f1d42e111f 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr114759-3.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr114759-3.c
@@ -2,7 +2,8 @@
 /* { dg-do compile } */
 /* { dg-options "-O2 -mdejagnu-cpu=power7 -mrop-protect" } */
 
-/* Verify we emit an error if we use -mrop-protect with an unsupported cpu.  */
+/* Verify we emit an error if we use -mrop-protect with an unsupported cpu
+   or ABI.  */
 
 extern void foo (void);
 
@@ -17,3 +18,4 @@ bar (void)
in the final line (which is all that dg-error inspects). Hence, we have
to tell dg-error to ignore the line number.  */
 /* { dg-error "'-mrop-protect' requires '-mcpu=power8'" "PR114759" { target 
*-*-* } 0 } */
+/* { dg-error "'-mrop-protect' requires the ELFv2 ABI" "PR114759" { target { ! 
rop_ok } } 0 } */


[gcc r15-2256] modula2: Add GNU flex as a build and install prerequisite.

2024-07-24 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:52f3473e375b1bb57d08c97291a82c04070036c3

commit r15-2256-g52f3473e375b1bb57d08c97291a82c04070036c3
Author: Gaius Mulley 
Date:   Wed Jul 24 14:25:45 2024 +0100

modula2: Add GNU flex as a build and install prerequisite.

gcc/ChangeLog:

* doc/install.texi (GM2-prerequisite): Add GNU flex.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/doc/install.texi | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index dda623f4410a..4973f195daf9 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -334,6 +334,10 @@ environment to your ``good'' shell prior to running
 @command{zsh} is not a fully compliant POSIX shell and will not
 work when configuring GCC@.
 
+@item GNU flex
+
+Necessary to build the lexical analysis module.
+
 @item A POSIX or SVR4 awk
 
 Necessary for creating some of the generated source files for GCC@.


[gcc r15-2257] modula2: Improve error message to include symbol name.

2024-07-24 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:6a99f3ae962542165fdfc077f1040ea4d936691b

commit r15-2257-g6a99f3ae962542165fdfc077f1040ea4d936691b
Author: Gaius Mulley 
Date:   Wed Jul 24 14:26:39 2024 +0100

modula2: Improve error message to include symbol name.

gcc/m2/ChangeLog:

* gm2-compiler/M2StateCheck.mod (GenerateError): Add
symbol name to the error message.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2StateCheck.mod | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/m2/gm2-compiler/M2StateCheck.mod 
b/gcc/m2/gm2-compiler/M2StateCheck.mod
index e53cb174474c..940c433bcc14 100644
--- a/gcc/m2/gm2-compiler/M2StateCheck.mod
+++ b/gcc/m2/gm2-compiler/M2StateCheck.mod
@@ -306,7 +306,7 @@ PROCEDURE GenerateError (tok: CARDINAL; s: StateCheck; sym: 
CARDINAL) ;
 VAR
str: String ;
 BEGIN
-   str := InitString ('not expecting a {%1Ad} {%1a: }in a ') ;
+   str := InitString ('not expecting the {%1Ad} {%1a} in a ') ;
IF const IN s^.state
THEN
   str := ConCat (str, Mark (InitString ('{%kCONST} block')))


[gcc r15-2258] optabs/rs6000: Rename iorc and andc to iorn and andn

2024-07-24 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:23f195b06ad759939805a36646c724bccc3f3984

commit r15-2258-g23f195b06ad759939805a36646c724bccc3f3984
Author: Andrew Pinski 
Date:   Mon Jul 22 21:23:38 2024 -0700

optabs/rs6000: Rename iorc and andc to iorn and andn

When I was trying to add an scalar version of iorc and andc, the optab that
got matched was for and/ior with the mode of csi and cdi instead of iorc and
andc optabs for si and di modes. Since csi/cdi are the complex integer 
modes,
we need to rename the optabs to be without c there. This changes c to n 
which
is a neutral and known not to be first letter of a mode.

Bootstrapped and tested on x86_64 and powerpc64le.

gcc/ChangeLog:

* config/rs6000/rs6000-builtins.def: s/iorc/iorn/. s/andc/andn/
for the code.
* config/rs6000/rs6000-string.cc (expand_cmp_vec_sequence): Update
to iorn.
* config/rs6000/rs6000.md (andc3): Rename to ...
(andn3): This.
(iorc3): Rename to ...
(iorn3): This.
* doc/md.texi: Update documentation for the rename.
* internal-fn.def (BIT_ANDC): Rename to ...
(BIT_ANDN): This.
(BIT_IORC): Rename to ...
(BIT_IORN): This.
* optabs.def (andc_optab): Rename to ...
(andn_optab): This.
(iorc_optab): Rename to ...
(iorn_optab): This.
* gimple-isel.cc (gimple_expand_vec_cond_expr): Update for the
renamed internal functions, ANDC/IORC to ANDN/IORN.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def | 44 +--
 gcc/config/rs6000/rs6000-string.cc|  2 +-
 gcc/config/rs6000/rs6000.md   |  4 ++--
 gcc/doc/md.texi   |  8 +++
 gcc/gimple-isel.cc| 12 +-
 gcc/internal-fn.def   |  4 ++--
 gcc/optabs.def| 10 +---
 7 files changed, 44 insertions(+), 40 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index 77eb0f7e4069..ffbeff64d6d6 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -518,25 +518,25 @@
 VAND_V8HI_UNS andv8hi3 {}
 
   const vsc __builtin_altivec_vandc_v16qi (vsc, vsc);
-VANDC_V16QI andcv16qi3 {}
+VANDC_V16QI andnv16qi3 {}
 
   const vuc __builtin_altivec_vandc_v16qi_uns (vuc, vuc);
-VANDC_V16QI_UNS andcv16qi3 {}
+VANDC_V16QI_UNS andnv16qi3 {}
 
   const vf __builtin_altivec_vandc_v4sf (vf, vf);
-VANDC_V4SF andcv4sf3 {}
+VANDC_V4SF andnv4sf3 {}
 
   const vsi __builtin_altivec_vandc_v4si (vsi, vsi);
-VANDC_V4SI andcv4si3 {}
+VANDC_V4SI andnv4si3 {}
 
   const vui __builtin_altivec_vandc_v4si_uns (vui, vui);
-VANDC_V4SI_UNS andcv4si3 {}
+VANDC_V4SI_UNS andnv4si3 {}
 
   const vss __builtin_altivec_vandc_v8hi (vss, vss);
-VANDC_V8HI andcv8hi3 {}
+VANDC_V8HI andnv8hi3 {}
 
   const vus __builtin_altivec_vandc_v8hi_uns (vus, vus);
-VANDC_V8HI_UNS andcv8hi3 {}
+VANDC_V8HI_UNS andnv8hi3 {}
 
   const vsc __builtin_altivec_vavgsb (vsc, vsc);
 VAVGSB avgv16qi3_ceil {}
@@ -1189,13 +1189,13 @@
 VAND_V2DI_UNS andv2di3 {}
 
   const vd __builtin_altivec_vandc_v2df (vd, vd);
-VANDC_V2DF andcv2df3 {}
+VANDC_V2DF andnv2df3 {}
 
   const vsll __builtin_altivec_vandc_v2di (vsll, vsll);
-VANDC_V2DI andcv2di3 {}
+VANDC_V2DI andnv2di3 {}
 
   const vull __builtin_altivec_vandc_v2di_uns (vull, vull);
-VANDC_V2DI_UNS andcv2di3 {}
+VANDC_V2DI_UNS andnv2di3 {}
 
   const vd __builtin_altivec_vnor_v2df (vd, vd);
 VNOR_V2DF norv2df3 {}
@@ -1975,40 +1975,40 @@
 NEG_V2DI negv2di2 {}
 
   const vsc __builtin_altivec_orc_v16qi (vsc, vsc);
-ORC_V16QI iorcv16qi3 {}
+ORC_V16QI iornv16qi3 {}
 
   const vuc __builtin_altivec_orc_v16qi_uns (vuc, vuc);
-ORC_V16QI_UNS iorcv16qi3 {}
+ORC_V16QI_UNS iornv16qi3 {}
 
   const vsq __builtin_altivec_orc_v1ti (vsq, vsq);
-ORC_V1TI iorcv1ti3 {}
+ORC_V1TI iornv1ti3 {}
 
   const vuq __builtin_altivec_orc_v1ti_uns (vuq, vuq);
-ORC_V1TI_UNS iorcv1ti3 {}
+ORC_V1TI_UNS iornv1ti3 {}
 
   const vd __builtin_altivec_orc_v2df (vd, vd);
-ORC_V2DF iorcv2df3 {}
+ORC_V2DF iornv2df3 {}
 
   const vsll __builtin_altivec_orc_v2di (vsll, vsll);
-ORC_V2DI iorcv2di3 {}
+ORC_V2DI iornv2di3 {}
 
   const vull __builtin_altivec_orc_v2di_uns (vull, vull);
-ORC_V2DI_UNS iorcv2di3 {}
+ORC_V2DI_UNS iornv2di3 {}
 
   const vf __builtin_altivec_orc_v4sf (vf, vf);
-ORC_V4SF iorcv4sf3 {}
+ORC_V4SF iornv4sf3 {}
 
   const vsi __builtin_altivec_orc_v4si (vsi, vsi);
-ORC_V4SI iorcv4si3 {}
+ORC_V4SI iornv4si3 {}
 
   const vui __builtin_altivec_orc_v4si_uns (vui, vui);
-ORC_V4SI_UNS iorcv4si3 {}
+ORC_V4SI_UNS iornv4si3 {}
 
   const vss __builtin_altivec_orc_v8hi (vss

[gcc r15-2259] c++: add fixed testcase [PR109997]

2024-07-24 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:eebe830013c0d66816dfcae7b7aa77de5646bcad

commit r15-2259-geebe830013c0d66816dfcae7b7aa77de5646bcad
Author: Jason Merrill 
Date:   Wed Jul 24 11:07:42 2024 -0400

c++: add fixed testcase [PR109997]

Fixed by r14-9713 for PR100667.

PR c++/109997

gcc/testsuite/ChangeLog:

* g++.dg/ext/is_assignable1.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/ext/is_assignable1.C | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/testsuite/g++.dg/ext/is_assignable1.C 
b/gcc/testsuite/g++.dg/ext/is_assignable1.C
new file mode 100644
index ..31e64509b452
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_assignable1.C
@@ -0,0 +1,4 @@
+// PR c++/109997
+
+struct S;
+bool b = __is_assignable(int, S); // { dg-error "incomplete" }


[gcc r14-10506] RISC-V: Disable Zba optimization pattern if XTheadMemIdx is enabled

2024-07-24 Thread Christoph Mテシllner via Gcc-cvs
https://gcc.gnu.org/g:ab0386679fef35c544d139270436c63026e00ff2

commit r14-10506-gab0386679fef35c544d139270436c63026e00ff2
Author: Christoph Müllner 
Date:   Tue Jul 23 14:48:02 2024 +0200

RISC-V: Disable Zba optimization pattern if XTheadMemIdx is enabled

It is possible that the Zba optimization pattern zero_extendsidi2_bitmanip
matches for a XTheadMemIdx INSN with the effect of emitting an invalid
instruction as reported in PR116035.

The pattern above is used to emit a zext.w instruction to zero-extend
SI mode registers to DI mode.  A similar functionality can be achieved
by XTheadBb's th.extu instruction.  And indeed, we have the equivalent
pattern in thead.md (zero_extendsidi2_th_extu).  However, that pattern
depends on !TARGET_XTHEADMEMIDX.  To compensate for that, there are
specific patterns that ensure that zero-extension instruction can still
be emitted (th_memidx_bb_zero_extendsidi2 and friends).

While we could implement something similar (th_memidx_zba_zero_extendsidi2)
it would only make sense, if there existed real HW that does implement Zba
and XTheadMemIdx, but not XTheadBb.  Unless such a machine exists, let's
simply disable zero_extendsidi2_bitmanip if XTheadMemIdx is available.

PR target/116035

gcc/ChangeLog:

* config/riscv/bitmanip.md: Disable zero_extendsidi2_bitmanip
for XTheadMemIdx.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr116035-1.c: New test.
* gcc.target/riscv/pr116035-2.c: New test.

(cherry picked from commit 9817d29cd66762893782a52b2c304c5083bc0023)
Reported-by: Patrick O'Neill 
Signed-off-by: Christoph Müllner 

Diff:
---
 gcc/config/riscv/bitmanip.md|  2 +-
 gcc/testsuite/gcc.target/riscv/pr116035-1.c | 29 +
 gcc/testsuite/gcc.target/riscv/pr116035-2.c | 26 ++
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index ccda25c01c1b..0612e69fcb3b 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -22,7 +22,7 @@
 (define_insn "*zero_extendsidi2_bitmanip"
   [(set (match_operand:DI 0 "register_operand" "=r,r")
(zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "r,m")))]
-  "TARGET_64BIT && TARGET_ZBA"
+  "TARGET_64BIT && TARGET_ZBA && !TARGET_XTHEADMEMIDX"
   "@
zext.w\t%0,%1
lwu\t%0,%1"
diff --git a/gcc/testsuite/gcc.target/riscv/pr116035-1.c 
b/gcc/testsuite/gcc.target/riscv/pr116035-1.c
new file mode 100644
index ..bc45941ff8f0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr116035-1.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Og" "-Os" "-Oz" } } */
+/* { dg-options "-march=rv64g_zba_xtheadmemidx" { target { rv64 } } } */
+/* { dg-options "-march=rv32g_zba_xtheadmemidx" { target { rv32 } } } */
+
+void a(long);
+unsigned b[11];
+void c()
+{
+  for (int d = 0; d < 11; ++d)
+a(b[d]);
+}
+
+#if __riscv_xlen == 64
+unsigned long zext64_32(unsigned int u32)
+{
+  /* Missed optimization for Zba+XTheadMemIdx.  */
+  return u32; //zext.w a0, a0
+}
+#endif
+
+/* { dg-final { scan-assembler "th.lwuia\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" { 
target rv64 } } } */
+/* { dg-final { scan-assembler "th.lwia\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" { 
target rv32 } } } */
+
+/* { dg-final { scan-assembler-not "lwu\t\[a-x0-9\]+,\(\[a-x0-9\]+\),4,0" } } 
*/
+
+/* Missed optimizations for Zba+XTheadMemIdx.  */
+/* { dg-final { scan-assembler "zext.w\t" { target rv64 xfail rv64 } } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/pr116035-2.c 
b/gcc/testsuite/gcc.target/riscv/pr116035-2.c
new file mode 100644
index ..2c1a96948605
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr116035-2.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Og" "-Os" "-Oz" } } */
+/* { dg-options "-march=rv64g_xtheadbb_xtheadmemidx" { target { rv64 } } } */
+/* { dg-options "-march=rv32g_xtheadbb_xtheadmemidx" { target { rv32 } } } */
+
+void a(long);
+unsigned b[11];
+void c()
+{
+  for (int d = 0; d < 11; ++d)
+a(b[d]);
+}
+
+#if __riscv_xlen == 64
+unsigned long zext64_32(unsigned int u32)
+{
+return u32; //th.extu a0, a0, 31, 0
+}
+#endif
+
+/* { dg-final { scan-assembler "th.lwuia\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" { 
target { rv64 } } } } */
+/* { dg-final { scan-assembler "th.lwia\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" { 
target { rv32 } } } } */
+
+/* { dg-final { scan-assembler-not "lwu\t\[a-x0-9\]+,\\(\[a-x0-9\]+\\),4,0" } 
} */
+
+/* { dg-final { scan-assembler "th.extu\t" { target rv64 } } } */


[gcc r15-2260] aarch64: Remove unused global aarch64_tune_flags

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:4cb933f8f9ff223695b4929a32aa736c6b218e37

commit r15-2260-g4cb933f8f9ff223695b4929a32aa736c6b218e37
Author: Andrew Carlotti 
Date:   Wed Apr 17 19:28:20 2024 +0100

aarch64: Remove unused global aarch64_tune_flags

gcc/ChangeLog:

* config/aarch64/aarch64.cc
(aarch64_tune_flags): Remove unused global variable.
(aarch64_override_options_internal): Remove dead assignment.

Diff:
---
 gcc/config/aarch64/aarch64.cc | 4 
 1 file changed, 4 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 9e51236ce9fa..d8fbd7102e7b 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -349,9 +349,6 @@ static bool aarch64_print_address_internal (FILE*, 
machine_mode, rtx,
 /* The processor for which instructions should be scheduled.  */
 enum aarch64_processor aarch64_tune = cortexa53;
 
-/* Mask to specify which instruction scheduling options should be used.  */
-uint64_t aarch64_tune_flags = 0;
-
 /* Global flag for PC relative loads.  */
 bool aarch64_pcrelative_literal_loads;
 
@@ -18273,7 +18270,6 @@ void
 aarch64_override_options_internal (struct gcc_options *opts)
 {
   const struct processor *tune = aarch64_get_tune_cpu (opts->x_selected_tune);
-  aarch64_tune_flags = tune->flags;
   aarch64_tune = tune->sched_core;
   /* Make a copy of the tuning parameters attached to the core, which
  we may later overwrite.  */


[gcc r15-2261] aarch64: Move AARCH64_NUM_ISA_MODES definition

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:f11692fbfd85e6d62ecdb07e5affb611b29a6715

commit r15-2261-gf11692fbfd85e6d62ecdb07e5affb611b29a6715
Author: Andrew Carlotti 
Date:   Fri May 3 16:09:27 2024 +0100

aarch64: Move AARCH64_NUM_ISA_MODES definition

AARCH64_NUM_ISA_MODES will be used within aarch64-opts.h in a later
commit.

gcc/ChangeLog:

* config/aarch64/aarch64.h (DEF_AARCH64_ISA_MODE): Move to...
* config/aarch64/aarch64-opts.h (DEF_AARCH64_ISA_MODE): ...here.

Diff:
---
 gcc/config/aarch64/aarch64-opts.h | 5 +
 gcc/config/aarch64/aarch64.h  | 5 -
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-opts.h 
b/gcc/config/aarch64/aarch64-opts.h
index a05c0d3ded1c..06a4fed38334 100644
--- a/gcc/config/aarch64/aarch64-opts.h
+++ b/gcc/config/aarch64/aarch64-opts.h
@@ -24,6 +24,11 @@
 
 #ifndef USED_FOR_TARGET
 typedef uint64_t aarch64_feature_flags;
+
+constexpr unsigned int AARCH64_NUM_ISA_MODES = (0
+#define DEF_AARCH64_ISA_MODE(IDENT) + 1
+#include "aarch64-isa-modes.def"
+);
 #endif
 
 /* The various cores that implement AArch64.  */
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index fac1882bcb38..2be6dc4089b8 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -183,11 +183,6 @@ enum class aarch64_feature : unsigned char {
 
 constexpr auto AARCH64_FL_SM_STATE = AARCH64_FL_SM_ON | AARCH64_FL_SM_OFF;
 
-constexpr unsigned int AARCH64_NUM_ISA_MODES = (0
-#define DEF_AARCH64_ISA_MODE(IDENT) + 1
-#include "aarch64-isa-modes.def"
-);
-
 /* The mask of all ISA modes.  */
 constexpr auto AARCH64_FL_ISA_MODES
   = (aarch64_feature_flags (1) << AARCH64_NUM_ISA_MODES) - 1;


[gcc r15-2262] aarch64: Eliminate a temporary variable.

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:b5fa14e886f0f5f3e10970c705042bc3157be714

commit r15-2262-gb5fa14e886f0f5f3e10970c705042bc3157be714
Author: Andrew Carlotti 
Date:   Fri May 10 12:56:44 2024 +0100

aarch64: Eliminate a temporary variable.

The name would become misleading in a later commit anyway, and I think
this is marginally more readable.

gcc/ChangeLog:

* config/aarch64/aarch64.cc
(aarch64_override_options): Remove temporary variable.

Diff:
---
 gcc/config/aarch64/aarch64.cc | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index d8fbd7102e7b..4e3a4047ea80 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -18856,7 +18856,6 @@ aarch64_override_options (void)
   SUBTARGET_OVERRIDE_OPTIONS;
 #endif
 
-  auto isa_mode = AARCH64_FL_DEFAULT_ISA_MODE;
   if (cpu && arch)
 {
   /* If both -mcpu and -march are specified, warn if they are not
@@ -18879,25 +18878,25 @@ aarch64_override_options (void)
}
 
   selected_arch = arch->arch;
-  aarch64_set_asm_isa_flags (arch_isa | isa_mode);
+  aarch64_set_asm_isa_flags (arch_isa | AARCH64_FL_DEFAULT_ISA_MODE);
 }
   else if (cpu)
 {
   selected_arch = cpu->arch;
-  aarch64_set_asm_isa_flags (cpu_isa | isa_mode);
+  aarch64_set_asm_isa_flags (cpu_isa | AARCH64_FL_DEFAULT_ISA_MODE);
 }
   else if (arch)
 {
   cpu = &all_cores[arch->ident];
   selected_arch = arch->arch;
-  aarch64_set_asm_isa_flags (arch_isa | isa_mode);
+  aarch64_set_asm_isa_flags (arch_isa | AARCH64_FL_DEFAULT_ISA_MODE);
 }
   else
 {
   /* No -mcpu or -march specified, so use the default CPU.  */
   cpu = &all_cores[TARGET_CPU_DEFAULT];
   selected_arch = cpu->arch;
-  aarch64_set_asm_isa_flags (cpu->flags | isa_mode);
+  aarch64_set_asm_isa_flags (cpu->flags | AARCH64_FL_DEFAULT_ISA_MODE);
 }
 
   selected_tune = tune ? tune->ident : cpu->ident;


[gcc r15-2264] aarch64: Define aarch64_get_{asm_|}isa_flags

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:c0ed0823a6fa35dc074d3323163473a663721441

commit r15-2264-gc0ed0823a6fa35dc074d3323163473a663721441
Author: Andrew Carlotti 
Date:   Fri May 10 11:46:17 2024 +0100

aarch64: Define aarch64_get_{asm_|}isa_flags

Building an aarch64_feature_flags value from data within a gcc_options
or cl_target_option struct will get more complicated in a later commit.
Use a macro to avoid doing this manually in more than one location.

gcc/ChangeLog:

* common/config/aarch64/aarch64-common.cc
(aarch64_handle_option): Use new macro.
* config/aarch64/aarch64.cc
(aarch64_override_options_internal): Ditto.
(aarch64_option_print): Ditto.
(aarch64_set_current_function): Ditto.
(aarch64_can_inline_p): Ditto.
(aarch64_declare_function_name): Ditto.
(aarch64_start_file): Ditto.
* config/aarch64/aarch64.h (aarch64_get_asm_isa_flags): New
(aarch64_get_isa_flags): New.
(aarch64_asm_isa_flags): Use new macro.
(aarch64_isa_flags): Ditto.

Diff:
---
 gcc/common/config/aarch64/aarch64-common.cc |  2 +-
 gcc/config/aarch64/aarch64.cc   | 36 ++---
 gcc/config/aarch64/aarch64.h| 11 +
 3 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/gcc/common/config/aarch64/aarch64-common.cc 
b/gcc/common/config/aarch64/aarch64-common.cc
index 951d041d3109..63c50189a09d 100644
--- a/gcc/common/config/aarch64/aarch64-common.cc
+++ b/gcc/common/config/aarch64/aarch64-common.cc
@@ -111,7 +111,7 @@ aarch64_handle_option (struct gcc_options *opts,
 
 case OPT_mgeneral_regs_only:
   opts->x_target_flags |= MASK_GENERAL_REGS_ONLY;
-  aarch64_set_asm_isa_flags (opts, opts->x_aarch64_asm_isa_flags);
+  aarch64_set_asm_isa_flags (opts, aarch64_get_asm_isa_flags (opts));
   return true;
 
 case OPT_mfix_cortex_a53_835769:
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 1b343c9ae1c7..66ce04d77e17 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -18329,10 +18329,11 @@ aarch64_override_options_internal (struct gcc_options 
*opts)
   && !fixed_regs[R18_REGNUM])
 error ("%<-fsanitize=shadow-call-stack%> requires %<-ffixed-x18%>");
 
-  if ((opts->x_aarch64_isa_flags & (AARCH64_FL_SM_ON | AARCH64_FL_ZA_ON))
-  && !(opts->x_aarch64_isa_flags & AARCH64_FL_SME))
+  aarch64_feature_flags isa_flags = aarch64_get_isa_flags (opts);
+  if ((isa_flags & (AARCH64_FL_SM_ON | AARCH64_FL_ZA_ON))
+  && !(isa_flags & AARCH64_FL_SME))
 {
-  if (opts->x_aarch64_isa_flags & AARCH64_FL_SM_ON)
+  if (isa_flags & AARCH64_FL_SM_ON)
error ("streaming functions require the ISA extension %qs", "sme");
   else
error ("functions with SME state require the ISA extension %qs",
@@ -18341,8 +18342,7 @@ aarch64_override_options_internal (struct gcc_options 
*opts)
  " option %<-march%>, or by using the %"
  " attribute or pragma", "sme");
   opts->x_target_flags &= ~MASK_GENERAL_REGS_ONLY;
-  auto new_flags = (opts->x_aarch64_asm_isa_flags
-   | feature_deps::SME ().enable);
+  auto new_flags = isa_flags | feature_deps::SME ().enable;
   aarch64_set_asm_isa_flags (opts, new_flags);
 }
 
@@ -19036,9 +19036,9 @@ aarch64_option_print (FILE *file, int indent, struct 
cl_target_option *ptr)
   const struct processor *cpu
 = aarch64_get_tune_cpu (ptr->x_selected_tune);
   const struct processor *arch = aarch64_get_arch (ptr->x_selected_arch);
+  aarch64_feature_flags isa_flags = aarch64_get_asm_isa_flags(ptr);
   std::string extension
-= aarch64_get_extension_string_for_isa_flags (ptr->x_aarch64_asm_isa_flags,
- arch->flags);
+= aarch64_get_extension_string_for_isa_flags (isa_flags, arch->flags);
 
   fprintf (file, "%*sselected tune = %s\n", indent, "", cpu->name);
   fprintf (file, "%*sselected arch = %s%s\n", indent, "",
@@ -19098,7 +19098,7 @@ aarch64_set_current_function (tree fndecl)
   auto new_isa_mode = (fndecl
   ? aarch64_fndecl_isa_mode (fndecl)
   : AARCH64_DEFAULT_ISA_MODE);
-  auto isa_flags = TREE_TARGET_OPTION (new_tree)->x_aarch64_isa_flags;
+  auto isa_flags = aarch64_get_isa_flags (TREE_TARGET_OPTION (new_tree));
 
   static bool reported_zt0_p;
   if (!reported_zt0_p
@@ -20703,16 +20703,16 @@ aarch64_can_inline_p (tree caller, tree callee)
   : target_option_default_node);
 
   /* Callee's ISA flags should be a subset of the caller's.  */
-  auto caller_asm_isa = (caller_opts->x_aarch64_asm_isa_flags
+  auto caller_asm_isa = (aarch64_get_asm_isa_flags (caller_opts)
 & ~AARCH64_FL_ISA_MODES);
-  auto callee_asm_isa = (callee_opts->x_aarch64_asm_isa_fla

[gcc r15-2265] aarch64: Decouple feature flag option storage type

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:033d9053dae3c1aafae63d22641adb49210301d8

commit r15-2265-g033d9053dae3c1aafae63d22641adb49210301d8
Author: Andrew Carlotti 
Date:   Fri May 10 11:56:57 2024 +0100

aarch64: Decouple feature flag option storage type

The awk scripts that process the .opt files are relatively fragile and
only handle a limited set of data types correctly.  The unrecognised
aarch64_feature_flags type is handled as a uint64_t, which happens to be
correct for now.  However, that assumption will change when we extend
the mask to 128 bits.

This patch changes the option members to use uint64_t types, and adds a
"_0" suffix to the names (both for future extensibility, and to allow
the original name to be used for the full aarch64_feature_flags mask
within generator files).

gcc/ChangeLog:

* common/config/aarch64/aarch64-common.cc
(aarch64_set_asm_isa_flags): Reorder, and add suffix to names.
* config/aarch64/aarch64.h
(aarch64_get_asm_isa_flags): Add "_0" suffix.
(aarch64_get_isa_flags): Ditto.
(aarch64_asm_isa_flags): Redefine using renamed uint64_t value.
(aarch64_isa_flags): Ditto.
* config/aarch64/aarch64.opt:
(aarch64_asm_isa_flags): Rename to...
(aarch64_asm_isa_flags_0): ...this, and change to uint64_t.
(aarch64_isa_flags): Rename to...
(aarch64_isa_flags_0): ...this, and change to uint64_t.

Diff:
---
 gcc/common/config/aarch64/aarch64-common.cc | 11 ++-
 gcc/config/aarch64/aarch64.h| 11 ---
 gcc/config/aarch64/aarch64.opt  |  4 ++--
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/gcc/common/config/aarch64/aarch64-common.cc 
b/gcc/common/config/aarch64/aarch64-common.cc
index 63c50189a09d..bd0770dd0d84 100644
--- a/gcc/common/config/aarch64/aarch64-common.cc
+++ b/gcc/common/config/aarch64/aarch64-common.cc
@@ -66,15 +66,16 @@ static const struct default_options 
aarch_option_optimization_table[] =
 { OPT_LEVELS_NONE, 0, NULL, 0 }
   };
 
-/* Set OPTS->x_aarch64_asm_isa_flags to FLAGS and update
-   OPTS->x_aarch64_isa_flags accordingly.  */
+
+/* Set OPTS->x_aarch64_asm_isa_flags_0 to FLAGS and update
+   OPTS->x_aarch64_isa_flags_0 accordingly.  */
 void
 aarch64_set_asm_isa_flags (gcc_options *opts, aarch64_feature_flags flags)
 {
-  opts->x_aarch64_asm_isa_flags = flags;
-  opts->x_aarch64_isa_flags = flags;
+  opts->x_aarch64_asm_isa_flags_0 = flags;
   if (opts->x_target_flags & MASK_GENERAL_REGS_ONLY)
-opts->x_aarch64_isa_flags &= ~feature_deps::get_flags_off (AARCH64_FL_FP);
+flags &= ~feature_deps::get_flags_off (AARCH64_FL_FP);
+  opts->x_aarch64_isa_flags_0 = flags;
 }
 
 /* Implement TARGET_HANDLE_OPTION.
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 193f2486176b..903e708565dc 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -23,13 +23,18 @@
 #define GCC_AARCH64_H
 
 #define aarch64_get_asm_isa_flags(opts) \
-  (aarch64_feature_flags ((opts)->x_aarch64_asm_isa_flags))
+  (aarch64_feature_flags ((opts)->x_aarch64_asm_isa_flags_0))
 #define aarch64_get_isa_flags(opts) \
-  (aarch64_feature_flags ((opts)->x_aarch64_isa_flags))
+  (aarch64_feature_flags ((opts)->x_aarch64_isa_flags_0))
 
 /* Make these flags read-only so that all uses go via
aarch64_set_asm_isa_flags.  */
-#ifndef GENERATOR_FILE
+#ifdef GENERATOR_FILE
+#undef aarch64_asm_isa_flags
+#define aarch64_asm_isa_flags (aarch64_feature_flags (aarch64_asm_isa_flags_0))
+#undef aarch64_isa_flags
+#define aarch64_isa_flags (aarch64_feature_flags (aarch64_isa_flags_0))
+#else
 #undef aarch64_asm_isa_flags
 #define aarch64_asm_isa_flags (aarch64_get_asm_isa_flags (&global_options))
 #undef aarch64_isa_flags
diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt
index 6356c419399b..45aab49de27b 100644
--- a/gcc/config/aarch64/aarch64.opt
+++ b/gcc/config/aarch64/aarch64.opt
@@ -31,10 +31,10 @@ TargetVariable
 enum aarch64_arch selected_arch = aarch64_no_arch
 
 TargetVariable
-aarch64_feature_flags aarch64_asm_isa_flags = 0
+uint64_t aarch64_asm_isa_flags_0 = 0
 
 TargetVariable
-aarch64_feature_flags aarch64_isa_flags = 0
+uint64_t aarch64_isa_flags_0 = 0
 
 TargetVariable
 unsigned aarch_enable_bti = 2


[gcc r15-2266] aarch64: Add explicit bool cast to return value

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:7700fe40b5281057640b61c9b04fc608f9cdc3c2

commit r15-2266-g7700fe40b5281057640b61c9b04fc608f9cdc3c2
Author: Andrew Carlotti 
Date:   Wed Jul 10 15:00:16 2024 +0100

aarch64: Add explicit bool cast to return value

gcc/ChangeLog:

* config/aarch64/aarch64.cc
(aarch64_valid_sysreg_name_p): Add bool cast.

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

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 66ce04d77e17..7c2af1316b67 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -30296,7 +30296,7 @@ aarch64_valid_sysreg_name_p (const char *regname)
   if (sysreg == NULL)
 return aarch64_is_implem_def_reg (regname);
   if (sysreg->arch_reqs)
-return (aarch64_isa_flags & sysreg->arch_reqs);
+return bool (aarch64_isa_flags & sysreg->arch_reqs);
   return true;
 }


[gcc r15-2267] aarch64: Add bool conversion to TARGET_* macros

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:8797a869c011f99ada3aced877b187f5430ec2f3

commit r15-2267-g8797a869c011f99ada3aced877b187f5430ec2f3
Author: Andrew Carlotti 
Date:   Wed Jul 10 14:42:37 2024 +0100

aarch64: Add bool conversion to TARGET_* macros

Use a new AARCH64_HAVE_ISA macro in TARGET_* definitions, and eliminate
all the AARCH64_ISA_* feature macros.

gcc/ChangeLog:

* config/aarch64/aarch64-c.cc
(aarch64_define_unconditional_macros): Use TARGET_V8R macro.
(aarch64_update_cpp_builtins): Use TARGET_* macros.
* config/aarch64/aarch64.h (AARCH64_HAVE_ISA): New macro.
(AARCH64_ISA_SM_OFF, AARCH64_ISA_SM_ON, AARCH64_ISA_ZA_ON)
(AARCH64_ISA_V8A, AARCH64_ISA_V8_1A, AARCH64_ISA_CRC)
(AARCH64_ISA_FP, AARCH64_ISA_SIMD, AARCH64_ISA_LSE)
(AARCH64_ISA_RDMA, AARCH64_ISA_V8_2A, AARCH64_ISA_F16)
(AARCH64_ISA_SVE, AARCH64_ISA_SVE2, AARCH64_ISA_SVE2_AES)
(AARCH64_ISA_SVE2_BITPERM, AARCH64_ISA_SVE2_SHA3)
(AARCH64_ISA_SVE2_SM4, AARCH64_ISA_SME, AARCH64_ISA_SME_I16I64)
(AARCH64_ISA_SME_F64F64, AARCH64_ISA_SME2, AARCH64_ISA_V8_3A)
(AARCH64_ISA_DOTPROD, AARCH64_ISA_AES, AARCH64_ISA_SHA2)
(AARCH64_ISA_V8_4A, AARCH64_ISA_SM4, AARCH64_ISA_SHA3)
(AARCH64_ISA_F16FML, AARCH64_ISA_RCPC, AARCH64_ISA_RCPC8_4)
(AARCH64_ISA_RNG, AARCH64_ISA_V8_5A, AARCH64_ISA_TME)
(AARCH64_ISA_MEMTAG, AARCH64_ISA_V8_6A, AARCH64_ISA_I8MM)
(AARCH64_ISA_F32MM, AARCH64_ISA_F64MM, AARCH64_ISA_BF16)
(AARCH64_ISA_SB, AARCH64_ISA_RCPC3, AARCH64_ISA_V8R)
(AARCH64_ISA_PAUTH, AARCH64_ISA_V8_7A, AARCH64_ISA_V8_8A)
(AARCH64_ISA_V8_9A, AARCH64_ISA_V9A, AARCH64_ISA_V9_1A)
(AARCH64_ISA_V9_2A, AARCH64_ISA_V9_3A, AARCH64_ISA_V9_4A)
(AARCH64_ISA_MOPS, AARCH64_ISA_LS64, AARCH64_ISA_CSSC)
(AARCH64_ISA_D128, AARCH64_ISA_THE, AARCH64_ISA_GCS): Remove.
(TARGET_BASE_SIMD, TARGET_SIMD, TARGET_FLOAT)
(TARGET_NON_STREAMING, TARGET_STREAMING, TARGET_ZA, TARGET_SHA2)
(TARGET_SHA3, TARGET_AES, TARGET_SM4, TARGET_F16FML)
(TARGET_CRC32, TARGET_LSE, TARGET_FP_F16INST)
(TARGET_SIMD_F16INST, TARGET_DOTPROD, TARGET_SVE, TARGET_SVE2)
(TARGET_SVE2_AES, TARGET_SVE2_BITPERM, TARGET_SVE2_SHA3)
(TARGET_SVE2_SM4, TARGET_SME, TARGET_SME_I16I64)
(TARGET_SME_F64F64, TARGET_SME2, TARGET_ARMV8_3, TARGET_JSCVT)
(TARGET_FRINT, TARGET_TME, TARGET_RNG, TARGET_MEMTAG)
(TARGET_I8MM, TARGET_SVE_I8MM, TARGET_SVE_F32MM)
(TARGET_SVE_F64MM, TARGET_BF16_FP, TARGET_BF16_SIMD)
(TARGET_SVE_BF16, TARGET_PAUTH, TARGET_BTI, TARGET_MOPS)
(TARGET_LS64, TARGET_CSSC, TARGET_SB, TARGET_RCPC, TARGET_RCPC2)
(TARGET_RCPC3, TARGET_SIMD_RDMA, TARGET_ARMV9_4, TARGET_D128)
(TARGET_THE, TARGET_GCS): Redefine using AARCH64_HAVE_ISA.
(TARGET_V8R, TARGET_V9A): New.
* config/aarch64/aarch64.md (arch_enabled): Use TARGET_RCPC2.
* config/aarch64/iterators.md (GPI_I16): Use TARGET_FP_F16INST.
(GPF_F16): Ditto.
* config/aarch64/predicates.md
(aarch64_rcpc_memory_operand): Use TARGET_RCPC2.

Diff:
---
 gcc/config/aarch64/aarch64-c.cc  |   6 +-
 gcc/config/aarch64/aarch64.h | 196 ++-
 gcc/config/aarch64/aarch64.md|   2 +-
 gcc/config/aarch64/iterators.md  |   4 +-
 gcc/config/aarch64/predicates.md |   2 +-
 5 files changed, 79 insertions(+), 131 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc
index 2aff097dd33c..f9b9e3793755 100644
--- a/gcc/config/aarch64/aarch64-c.cc
+++ b/gcc/config/aarch64/aarch64-c.cc
@@ -64,7 +64,7 @@ aarch64_define_unconditional_macros (cpp_reader *pfile)
   builtin_define ("__ARM_ARCH_8A");
 
   builtin_define_with_int_value ("__ARM_ARCH_PROFILE",
-  AARCH64_ISA_V8R ? 'R' : 'A');
+  TARGET_V8R ? 'R' : 'A');
   builtin_define ("__ARM_FEATURE_CLZ");
   builtin_define ("__ARM_FEATURE_IDIV");
   builtin_define ("__ARM_FEATURE_UNALIGNED");
@@ -132,7 +132,7 @@ aarch64_update_cpp_builtins (cpp_reader *pfile)
   aarch64_def_or_undef (flag_unsafe_math_optimizations, "__ARM_FP_FAST", 
pfile);
 
   cpp_undef (pfile, "__ARM_ARCH");
-  builtin_define_with_int_value ("__ARM_ARCH", AARCH64_ISA_V9A ? 9 : 8);
+  builtin_define_with_int_value ("__ARM_ARCH", TARGET_V9A ? 9 : 8);
 
   builtin_define_with_int_value ("__ARM_SIZEOF_MINIMAL_ENUM",
 flag_short_enums ? 1 : 4);
@@ -259,7 +259,7 @@ aarch64_update_cpp_builtins (cpp_reader *pfile)
 
   aarch64_def_or_undef (TARGET_LS64,
"__ARM_FEATURE_LS64", pfile);
-  aarch64_def_or_undef (AARCH64_ISA_RCPC, "__ARM_FEATURE_RCPC", pfile);
+  aarch64_def_or_undef (TARGET_RCPC, "__ARM_FEATURE_RCPC", pf

[gcc r15-2269] Add new bbitmap class

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:181fdad106c353529850b3af7687a1b9b7509b0b

commit r15-2269-g181fdad106c353529850b3af7687a1b9b7509b0b
Author: Andrew Carlotti 
Date:   Fri Jun 21 18:59:25 2024 +0100

Add new bbitmap class

This class provides a constant-size bitmap that can be used as almost a
drop-in replacement for bitmaps stored in integer types.  The
implementation is entirely within the header file and uses recursive
templated operations to support effective optimisation and usage in
constexpr expressions.

This initial implementation hardcodes the choice of uint64_t elements
for storage and initialisation, but this could instead be specified via
a second template parameter.

gcc/ChangeLog:

* bbitmap.h: New file.

Diff:
---
 gcc/bbitmap.h | 236 ++
 1 file changed, 236 insertions(+)

diff --git a/gcc/bbitmap.h b/gcc/bbitmap.h
new file mode 100644
index ..716c013b1035
--- /dev/null
+++ b/gcc/bbitmap.h
@@ -0,0 +1,236 @@
+/* Functions to support fixed-length bitmaps.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#ifndef GCC_BBITMAP_H
+#define GCC_BBITMAP_H
+
+/* Implementation of bounded (fixed length) bitmaps.
+
+   This provides a drop-in replacement for bitmaps that have outgrown the
+   storage capacity of a single integer.
+
+   Sets are stored as a fixed length array of uint64_t elements.  The length of
+   this array is given as a template parameter.  */
+
+/* Use recusive templated functions to define constexpr operations.  */
+template
+struct bbitmap_operators
+{
+  /* Return a result that maps binary operator OP to elements [0, M) of
+ X and Y, and takes the remaining elements from REST.  */
+  template
+  static constexpr Result binary(Operator op, const Arg &x, const Arg &y,
+Rest ...rest)
+  {
+return bbitmap_operators::template binary
+  (op, x, y, op (x.val[M - 1], y.val[M - 1]), rest...);
+  }
+
+  /* Return a result that contains the bitwise inverse of elements [0, M) of X,
+ and takes the remaining elements from REST.  */
+  template
+  static constexpr Result bit_not(const Arg &x, Rest ...rest)
+  {
+return bbitmap_operators::template bit_not
+  (x, ~(x.val[M - 1]), rest...);
+  }
+
+  /* Return true if any element [0, M) of X is nonzero.  */
+  template
+  static constexpr bool non_zero(const Arg &x)
+  {
+return (bool) x.val[M - 1]
+  || bbitmap_operators::template non_zero (x);
+  }
+
+  /* Return true if elements [0, M) of X are all equal to the corresponding
+ elements of Y.  */
+  template
+  static constexpr bool equal(const Arg &x, const Arg &y)
+  {
+return x.val[M - 1] == y.val[M - 1]
+  && bbitmap_operators::template equal (x, y);
+  }
+
+  /* If bit index INDEX selects a bit in the first M elements, return a
+ Result with that bit set and the other bits of the leading M elements
+ clear.  Clear the leading M elements otherwise.  Take the remaining
+ elements of the Result from REST.  */
+  template
+  static constexpr Result from_index(int index, Rest ...rest)
+  {
+return bbitmap_operators::template from_index
+  (index,
+   uint64_t ((index - (M - 1) * 64) == (index & 63)) << (index & 63),
+   rest...);
+  }
+};
+
+/* These functions form the base for the recursive functions above.  They
+   return either bitmap containing the elements passed in REST, or a default
+   bool result.  */
+template<>
+struct bbitmap_operators<0>
+{
+  template
+  static constexpr Result binary(Operator, const Arg, const Arg,
+Rest ...rest)
+  {
+return Result { rest... };
+  }
+
+  template
+  static constexpr Result bit_not(const Arg, Rest ...rest)
+  {
+return Result { rest... };
+  }
+
+  template
+  static constexpr bool non_zero(const Arg)
+  {
+return false;
+  }
+
+  template
+  static constexpr bool equal(const Arg, const Arg)
+  {
+return true;
+  }
+
+  template
+  static constexpr Result from_index(int, Rest ...rest)
+  {
+return Result { rest... };
+  }
+};
+
+template
+constexpr T bbitmap_element_or(T x, T y) { return x | y;}
+
+template
+constexpr T bbitmap_element_and(T x, T y) { return x & y;}
+
+template
+constexpr T bbitmap_element_xor(T x, T y) { return x ^ y;}

[gcc r15-2270] aarch64: Extend aarch64_feature_flags to 128 bits

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:129b40529e906f423f008b484206ef6edeb21f42

commit r15-2270-g129b40529e906f423f008b484206ef6edeb21f42
Author: Andrew Carlotti 
Date:   Fri May 10 13:34:34 2024 +0100

aarch64: Extend aarch64_feature_flags to 128 bits

Replace the existing uint64_t typedef with a bbitmap<2> typedef.  Most
of the preparatory work was carried out in previous commits, so this
patch itself is fairly small.

gcc/ChangeLog:

* common/config/aarch64/aarch64-common.cc
(aarch64_set_asm_isa_flags): Store a second uint64_t value.
* config/aarch64/aarch64-opts.h
(aarch64_feature_flags): Switch typedef to bbitmap<2>.
* config/aarch64/aarch64.cc
(aarch64_set_current_function): Extract isa mode from val[0].
* config/aarch64/aarch64.h
(aarch64_get_asm_isa_flags): Load a second uint64_t value.
(aarch64_get_isa_flags): Ditto.
(aarch64_asm_isa_flags): Ditto.
(aarch64_isa_flags): Ditto.
(HANDLE): Use bbitmap<2>::from_index to initialise flags.
(AARCH64_FL_ISA_MODES): Do arithmetic on integer type.
(AARCH64_ISA_MODE): Extract value from bbitmap<2> array.
* config/aarch64/aarch64.opt
(aarch64_asm_isa_flags_1): New variable.
(aarch64_isa_flags_1): Ditto.

Diff:
---
 gcc/common/config/aarch64/aarch64-common.cc | 12 
 gcc/config/aarch64/aarch64-opts.h   |  6 --
 gcc/config/aarch64/aarch64.cc   |  6 +++---
 gcc/config/aarch64/aarch64.h| 20 
 gcc/config/aarch64/aarch64.opt  |  6 ++
 5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/gcc/common/config/aarch64/aarch64-common.cc 
b/gcc/common/config/aarch64/aarch64-common.cc
index bd0770dd0d84..64b65b7ff9e4 100644
--- a/gcc/common/config/aarch64/aarch64-common.cc
+++ b/gcc/common/config/aarch64/aarch64-common.cc
@@ -67,15 +67,19 @@ static const struct default_options 
aarch_option_optimization_table[] =
   };
 
 
-/* Set OPTS->x_aarch64_asm_isa_flags_0 to FLAGS and update
-   OPTS->x_aarch64_isa_flags_0 accordingly.  */
+/* Set OPTS->x_aarch64_asm_isa_flags_<0..n> to FLAGS and update
+   OPTS->x_aarch64_isa_flags_<0..n> accordingly.  */
 void
 aarch64_set_asm_isa_flags (gcc_options *opts, aarch64_feature_flags flags)
 {
-  opts->x_aarch64_asm_isa_flags_0 = flags;
+  opts->x_aarch64_asm_isa_flags_0 = flags.val[0];
+  opts->x_aarch64_asm_isa_flags_1 = flags.val[1];
+
   if (opts->x_target_flags & MASK_GENERAL_REGS_ONLY)
 flags &= ~feature_deps::get_flags_off (AARCH64_FL_FP);
-  opts->x_aarch64_isa_flags_0 = flags;
+
+  opts->x_aarch64_isa_flags_0 = flags.val[0];
+  opts->x_aarch64_isa_flags_1 = flags.val[1];
 }
 
 /* Implement TARGET_HANDLE_OPTION.
diff --git a/gcc/config/aarch64/aarch64-opts.h 
b/gcc/config/aarch64/aarch64-opts.h
index 2c36bfaad19b..80ec1a05253d 100644
--- a/gcc/config/aarch64/aarch64-opts.h
+++ b/gcc/config/aarch64/aarch64-opts.h
@@ -23,14 +23,16 @@
 #define GCC_AARCH64_OPTS_H
 
 #ifndef USED_FOR_TARGET
-typedef uint64_t aarch64_isa_mode;
+#include "bbitmap.h"
 
-typedef uint64_t aarch64_feature_flags;
+typedef uint64_t aarch64_isa_mode;
 
 constexpr unsigned int AARCH64_NUM_ISA_MODES = (0
 #define DEF_AARCH64_ISA_MODE(IDENT) + 1
 #include "aarch64-isa-modes.def"
 );
+
+typedef bbitmap<2> aarch64_feature_flags;
 #endif
 
 /* The various cores that implement AArch64.  */
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 7c2af1316b67..e0cf382998c7 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -19119,7 +19119,7 @@ aarch64_set_current_function (tree fndecl)
  aarch64_pragma_target_parse.  */
   if (old_tree == new_tree
   && (!fndecl || aarch64_previous_fndecl)
-  && (aarch64_isa_mode) (isa_flags & AARCH64_FL_ISA_MODES) == new_isa_mode)
+  && (isa_flags & AARCH64_FL_ISA_MODES).val[0] == new_isa_mode)
 {
   gcc_assert (AARCH64_ISA_MODE == new_isa_mode);
   return;
@@ -19134,11 +19134,11 @@ aarch64_set_current_function (tree fndecl)
   /* The ISA mode can vary based on function type attributes and
  function declaration attributes.  Make sure that the target
  options correctly reflect these attributes.  */
-  if ((aarch64_isa_mode) (isa_flags & AARCH64_FL_ISA_MODES) != new_isa_mode)
+  if ((isa_flags & AARCH64_FL_ISA_MODES).val[0] != new_isa_mode)
 {
   auto base_flags = (aarch64_asm_isa_flags & ~AARCH64_FL_ISA_MODES);
   aarch64_set_asm_isa_flags (base_flags
-| (aarch64_feature_flags) new_isa_mode);
+| aarch64_feature_flags (new_isa_mode));
 
   aarch64_override_options_internal (&global_options);
   new_tree = build_target_option_node (&global_options,
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 6310ebd72ff2..b7e3304

[gcc r15-2263] aarch64: Introduce aarch64_isa_mode type

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:2abf063aee3ed75ab8e7839dad8a701740828f6c

commit r15-2263-g2abf063aee3ed75ab8e7839dad8a701740828f6c
Author: Andrew Carlotti 
Date:   Fri May 3 16:51:05 2024 +0100

aarch64: Introduce aarch64_isa_mode type

Currently there are many places where an aarch64_feature_flags variable
is used, but only the bottom three isa mode bits are set and read.
Using a separate data type for these value makes it more clear that
they're not expected or required to have any of their upper feature bits
set.  It will also make things simpler and more efficient when we extend
aarch64_feature_flags to 128 bits.

This patch uses explicit casts whenever converting from an
aarch64_feature_flags value to an aarch64_isa_mode value.  This isn't
strictly necessary, but serves to highlight the locations where an
explicit conversion will become necessary later.

gcc/ChangeLog:

* config/aarch64/aarch64-opts.h: Add aarch64_isa_mode typedef.
* config/aarch64/aarch64-protos.h
(aarch64_gen_callee_cookie): Use aarch64_isa_mode parameter.
(aarch64_sme_vq_immediate): Ditto.
* config/aarch64/aarch64.cc
(aarch64_fntype_pstate_sm): Use aarch64_isa_mode values.
(aarch64_fntype_pstate_za): Ditto.
(aarch64_fndecl_pstate_sm): Ditto.
(aarch64_fndecl_pstate_za): Ditto.
(aarch64_fndecl_isa_mode): Ditto.
(aarch64_cfun_incoming_pstate_sm): Ditto.
(aarch64_cfun_enables_pstate_sm): Ditto.
(aarch64_call_switches_pstate_sm): Ditto.
(aarch64_gen_callee_cookie): Ditto.
(aarch64_callee_isa_mode): Ditto.
(aarch64_insn_callee_abi): Ditto.
(aarch64_sme_vq_immediate): Ditto.
(aarch64_add_offset_temporaries): Ditto.
(aarch64_add_offset): Ditto.
(aarch64_add_sp): Ditto.
(aarch64_sub_sp): Ditto.
(aarch64_guard_switch_pstate_sm): Ditto.
(aarch64_switch_pstate_sm): Ditto.
(aarch64_init_cumulative_args): Ditto.
(aarch64_allocate_and_probe_stack_space): Ditto.
(aarch64_expand_prologue): Ditto.
(aarch64_expand_epilogue): Ditto.
(aarch64_start_call_args): Ditto.
(aarch64_expand_call): Ditto.
(aarch64_end_call_args): Ditto.
(aarch64_set_current_function): Ditto, with added conversions.
(aarch64_handle_attr_arch): Avoid macro with changed type.
(aarch64_handle_attr_cpu): Ditto.
(aarch64_handle_attr_isa_flags): Ditto.
(aarch64_switch_pstate_sm_for_landing_pad):
Use arch64_isa_mode values.
(aarch64_switch_pstate_sm_for_jump): Ditto.
(pass_switch_pstate_sm::gate): Ditto.
* config/aarch64/aarch64.h
(AARCH64_ISA_MODE_{SM_ON|SM_OFF|ZA_ON}): New macros.
(AARCH64_FL_SM_STATE): Mark as possibly unused.
(AARCH64_ISA_MODE_SM_STATE): New aarch64_isa_mode mask.
(AARCH64_DEFAULT_ISA_MODE): New aarch64_isa_mode value.
(AARCH64_FL_DEFAULT_ISA_MODE): Define using above value.
(AARCH64_ISA_MODE): Change type to aarch64_isa_mode.
(arm_pcs): Use aarch64_isa_mode value.

Diff:
---
 gcc/config/aarch64/aarch64-opts.h   |   2 +
 gcc/config/aarch64/aarch64-protos.h |   4 +-
 gcc/config/aarch64/aarch64.cc   | 144 ++--
 gcc/config/aarch64/aarch64.h|  21 +-
 4 files changed, 94 insertions(+), 77 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-opts.h 
b/gcc/config/aarch64/aarch64-opts.h
index 06a4fed38334..2c36bfaad19b 100644
--- a/gcc/config/aarch64/aarch64-opts.h
+++ b/gcc/config/aarch64/aarch64-opts.h
@@ -23,6 +23,8 @@
 #define GCC_AARCH64_OPTS_H
 
 #ifndef USED_FOR_TARGET
+typedef uint64_t aarch64_isa_mode;
+
 typedef uint64_t aarch64_feature_flags;
 
 constexpr unsigned int AARCH64_NUM_ISA_MODES = (0
diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 42639e9efcf1..f64afe288901 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -767,7 +767,7 @@ bool aarch64_constant_address_p (rtx);
 bool aarch64_emit_approx_div (rtx, rtx, rtx);
 bool aarch64_emit_approx_sqrt (rtx, rtx, bool);
 tree aarch64_vector_load_decl (tree);
-rtx aarch64_gen_callee_cookie (aarch64_feature_flags, arm_pcs);
+rtx aarch64_gen_callee_cookie (aarch64_isa_mode, arm_pcs);
 void aarch64_expand_call (rtx, rtx, rtx, bool);
 bool aarch64_expand_cpymem_mops (rtx *, bool);
 bool aarch64_expand_cpymem (rtx *, bool);
@@ -808,7 +808,7 @@ int aarch64_add_offset_temporaries (rtx);
 void aarch64_split_add_offset (scalar_int_mode, rtx, rtx, rtx, rtx, rtx);
 bool aarch64_rdsvl_immediate_p (const_rtx);
 rtx aarch64_sme_vq_immediate (machine_mode mode, HOST_WIDE_INT,
-   

[gcc r15-2268] aarch64: Use constructor explicitly in get_flags_off

2024-07-24 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:8977a1270b9c17e6682d25eb4b4030d7f2204df9

commit r15-2268-g8977a1270b9c17e6682d25eb4b4030d7f2204df9
Author: Andrew Carlotti 
Date:   Thu Jul 11 01:25:05 2024 +0100

aarch64: Use constructor explicitly in get_flags_off

gcc/ChangeLog:

* config/aarch64/aarch64-feature-deps.h
(get_flags_off): Construct aarch64_feature_flags (0) explicitly.

Diff:
---
 gcc/config/aarch64/aarch64-feature-deps.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-feature-deps.h 
b/gcc/config/aarch64/aarch64-feature-deps.h
index 79126db88254..a14ae22b7298 100644
--- a/gcc/config/aarch64/aarch64-feature-deps.h
+++ b/gcc/config/aarch64/aarch64-feature-deps.h
@@ -97,9 +97,10 @@ template struct info;
 constexpr aarch64_feature_flags
 get_flags_off (aarch64_feature_flags mask)
 {
-  return (0
+  return (aarch64_feature_flags (0)
 #define AARCH64_OPT_EXTENSION(A, IDENT, C, D, E, F) \
- | (feature_deps::IDENT ().enable & mask ? AARCH64_FL_##IDENT : 0)
+ | (feature_deps::IDENT ().enable & mask ? AARCH64_FL_##IDENT \
+ : aarch64_feature_flags (0))
 #include "config/aarch64/aarch64-option-extensions.def"
  );
 }


[gcc r15-2271] libstdc++: Remove duplicate include header from ranges_algobase.h

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:c9d61cff97b92c64e7f0717b3fb64fff4c870321

commit r15-2271-gc9d61cff97b92c64e7f0717b3fb64fff4c870321
Author: Michael Levine 
Date:   Tue Jul 23 12:50:31 2024 +0100

libstdc++: Remove duplicate include header from ranges_algobase.h

The bits/stl_algobase.h header was added to bits/ranges_algobase.h
separately through two related commits:
r15-1106-g674d213ab91871
r15-1117-g0bb1db32ccf54a

The comment for the first time it is included in the file is also
incorrect (my error from that 2nd one) since it is really being included
for __memcmp, not __memcpy

This patch removes the duplicate header include.

libstdc++-v3/ChangeLog:

* include/bits/ranges_algobase.h: Remove duplicate include of
.

Signed-off-by: Michael Levine 

Diff:
---
 libstdc++-v3/include/bits/ranges_algobase.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/ranges_algobase.h 
b/libstdc++-v3/include/bits/ranges_algobase.h
index 7ce5ac314f25..fd35b8ba14cb 100644
--- a/libstdc++-v3/include/bits/ranges_algobase.h
+++ b/libstdc++-v3/include/bits/ranges_algobase.h
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include  // __memcpy
 #include  // ranges::begin, ranges::range etc.
 #include   // __invoke
 #include  // __is_byte


[gcc r15-2272] libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:5fc9c40fea2481e56bf7bcc994cb40c71e28abb8

commit r15-2272-g5fc9c40fea2481e56bf7bcc994cb40c71e28abb8
Author: Jonathan Wakely 
Date:   Wed Jul 24 11:32:22 2024 +0100

libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

This questionable combination of flags causes a number of errors. This
one in std::vector needs to be fixed in the gcc-13 branch so I'm
committing it separately to simplify backporting.

libstdc++-v3/ChangeLog:

PR libstdc++/116070
* include/bits/stl_bvector.h: Check feature test macro before
using is_default_constructible_v.

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index 245e1c3b3a77..c45b7ff3320d 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -593,7 +593,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX20_CONSTEXPR
_Bvector_impl() _GLIBCXX_NOEXCEPT_IF(
  is_nothrow_default_constructible<_Bit_alloc_type>::value)
-#if __cpp_concepts
+#if __cpp_concepts && __glibcxx_type_trait_variable_templates
requires is_default_constructible_v<_Bit_alloc_type>
 #endif
: _Bit_alloc_type()


[gcc r15-2273] libstdc++: Fix and for -std=gnu++14 -fconcepts [PR116070]

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6c22fe418cff57dad712c4b950638e6e2d09bd9c

commit r15-2273-g6c22fe418cff57dad712c4b950638e6e2d09bd9c
Author: Jonathan Wakely 
Date:   Wed Jul 24 11:32:22 2024 +0100

libstdc++: Fix  and  for -std=gnu++14 -fconcepts 
[PR116070]

This questionable combination of flags causes a number of errors. The
ones in the rvalue stream overloads need to be fixed in the gcc-14
branch so I'm committing it separately to simplify backporting.

libstdc++-v3/ChangeLog:

PR libstdc++/116070
* include/std/istream: Check feature test macro before using
is_class_v and is_same_v.
* include/std/ostream: Likewise.

Diff:
---
 libstdc++-v3/include/std/istream | 2 +-
 libstdc++-v3/include/std/ostream | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream
index 11d51d3e666c..a2b207dae78c 100644
--- a/libstdc++-v3/include/std/istream
+++ b/libstdc++-v3/include/std/istream
@@ -1069,7 +1069,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // 2328. Rvalue stream extraction should use perfect forwarding
   // 1203. More useful rvalue stream insertion
 
-#if __cpp_concepts >= 201907L
+#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
   template
 requires __derived_from_ios_base<_Is>
   && requires (_Is& __is, _Tp&& __t) { __is >> std::forward<_Tp>(__t); }
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index 8a21758d0a33..12be6c4fd178 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -768,7 +768,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 1203. More useful rvalue stream insertion
 
-#if __cpp_concepts >= 201907L
+#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
   // Use concepts if possible because they're cheaper to evaluate.
   template
 concept __derived_from_ios_base = is_class_v<_Tp>


[gcc r15-2274] testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

2024-07-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:69e69847e21a8d951ab5f09fd3421449564dba31

commit r15-2274-g69e69847e21a8d951ab5f09fd3421449564dba31
Author: Jakub Jelinek 
Date:   Wed Jul 24 18:00:05 2024 +0200

testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

Didn't notice the memmove is into an int variable, so the test
was still failing on big endian.

2024-07-24  Jakub Jelinek  

PR tree-optimization/116034
PR testsuite/116061
* gcc.dg/pr116034.c (g): Change type from int to unsigned short.
(foo): Guard memmove call on __SIZEOF_SHORT__ == 2.

Diff:
---
 gcc/testsuite/gcc.dg/pr116034.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
index 9a31de034246..955b4c9e86b8 100644
--- a/gcc/testsuite/gcc.dg/pr116034.c
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -2,12 +2,13 @@
 /* { dg-do run } */
 /* { dg-options "-O1 -fno-strict-aliasing" } */
 
-int g;
+unsigned short int g;
 
 static inline int
 foo (_Complex unsigned short c)
 {
-  __builtin_memmove (&g, 1 + (char *) &c, 2);
+  if (__SIZEOF_SHORT__ == 2)
+__builtin_memmove (&g, 1 + (char *) &c, 2);
   return g;
 }


[gcc r14-10507] testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

2024-07-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:181f40f5cf8510a16191e4768dadbe2cb7a5c095

commit r14-10507-g181f40f5cf8510a16191e4768dadbe2cb7a5c095
Author: Jakub Jelinek 
Date:   Wed Jul 24 18:00:05 2024 +0200

testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

Didn't notice the memmove is into an int variable, so the test
was still failing on big endian.

2024-07-24  Jakub Jelinek  

PR tree-optimization/116034
PR testsuite/116061
* gcc.dg/pr116034.c (g): Change type from int to unsigned short.
(foo): Guard memmove call on __SIZEOF_SHORT__ == 2.

(cherry picked from commit 69e69847e21a8d951ab5f09fd3421449564dba31)

Diff:
---
 gcc/testsuite/gcc.dg/pr116034.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
index 9a31de034246..955b4c9e86b8 100644
--- a/gcc/testsuite/gcc.dg/pr116034.c
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -2,12 +2,13 @@
 /* { dg-do run } */
 /* { dg-options "-O1 -fno-strict-aliasing" } */
 
-int g;
+unsigned short int g;
 
 static inline int
 foo (_Complex unsigned short c)
 {
-  __builtin_memmove (&g, 1 + (char *) &c, 2);
+  if (__SIZEOF_SHORT__ == 2)
+__builtin_memmove (&g, 1 + (char *) &c, 2);
   return g;
 }


[gcc(refs/users/meissner/heads/work173)] Modify how arch flags are set.

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:f3a1dcd7eae79994ad592ba3245deec657e60588

commit f3a1dcd7eae79994ad592ba3245deec657e60588
Author: Michael Meissner 
Date:   Wed Jul 24 12:55:44 2024 -0400

Modify how arch flags are set.

2024-07-24  Michael Meissner  

gcc/

* config/rs6000/rs6000.cc (get_arch_flags): Modify how arch flags 
are
set.
* config/rs6000/rs6000.h (ARCH_FLAGS_*): Delete.

Diff:
---
 gcc/config/rs6000/rs6000.cc | 55 +++--
 gcc/config/rs6000/rs6000.h  | 10 -
 2 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 4550fd44036e..17f98607905f 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1824,27 +1824,48 @@ rs6000_cpu_name_lookup (const char *name)
 static HOST_WIDE_INT
 get_arch_flags (int cpu_index)
 {
-  if (cpu_index < 0)
-return 0;
+  HOST_WIDE_INT ret = 0;
 
-  enum processor_type processor = processor_target_table[cpu_index].processor;
+  if (cpu_index >= 0)
+switch (processor_target_table[cpu_index].processor)
+  {
+  case PROCESSOR_POWER11:
+   ret |= ARCH_MASK_POWER11;
+   /* fall through.  */
 
-  switch (processor)
-{
-case PROCESSOR_POWER4:  return ARCH_FLAGS_POWER4;
-case PROCESSOR_POWER5:  return ARCH_FLAGS_POWER5;
-case PROCESSOR_POWER6:  return ARCH_FLAGS_POWER6;
-case PROCESSOR_POWER7:  return ARCH_FLAGS_POWER7;
-case PROCESSOR_POWER8:  return ARCH_FLAGS_POWER8;
-case PROCESSOR_POWER9:  return ARCH_FLAGS_POWER9;
-case PROCESSOR_POWER10: return ARCH_FLAGS_POWER10;
-case PROCESSOR_POWER11: return ARCH_FLAGS_POWER11;
+  case PROCESSOR_POWER10:
+   ret |= ARCH_MASK_POWER10;
+   /* fall through.  */
 
-default:
-  break;
-}
+  case PROCESSOR_POWER9:
+   ret |= ARCH_MASK_POWER9;
+   /* fall through.  */
 
-  return 0;
+  case PROCESSOR_POWER8:
+   ret |= ARCH_MASK_POWER8;
+   /* fall through.  */
+
+  case PROCESSOR_POWER7:
+   ret |= ARCH_MASK_POWER7;
+   /* fall through.  */
+
+  case PROCESSOR_POWER6:
+   ret |= ARCH_MASK_POWER6;
+   /* fall through.  */
+
+  case PROCESSOR_POWER5:
+   ret |= ARCH_MASK_POWER5;
+   /* fall through.  */
+
+  case PROCESSOR_POWER4:
+   ret |= ARCH_MASK_POWER4;
+   break;
+
+  default:
+   break;
+  }
+
+  return ret;
 }
 
 
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 548ef9c0fa50..dbc844a7da10 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -2508,16 +2508,6 @@ enum arch_bits {
 #define ARCH_MASK_POWER10  (HOST_WIDE_INT_1 << ARCH_ENUM_POWER10)
 #define ARCH_MASK_POWER11  (HOST_WIDE_INT_1 << ARCH_ENUM_POWER11)
 
-/* Flags to set the architecture bits for a given cpu.  */
-#define ARCH_FLAGS_POWER4  ARCH_MASK_POWER4
-#define ARCH_FLAGS_POWER5  (ARCH_FLAGS_POWER4  | ARCH_MASK_POWER5)
-#define ARCH_FLAGS_POWER6  (ARCH_FLAGS_POWER5  | ARCH_MASK_POWER6)
-#define ARCH_FLAGS_POWER7  (ARCH_FLAGS_POWER6  | ARCH_MASK_POWER7)
-#define ARCH_FLAGS_POWER8  (ARCH_FLAGS_POWER7  | ARCH_MASK_POWER8)
-#define ARCH_FLAGS_POWER9  (ARCH_FLAGS_POWER8  | ARCH_MASK_POWER9)
-#define ARCH_FLAGS_POWER10 (ARCH_FLAGS_POWER9  | ARCH_MASK_POWER10)
-#define ARCH_FLAGS_POWER11 (ARCH_FLAGS_POWER10 | ARCH_MASK_POWER11)
-
 /* We used to use -mpower8-internal and -mpower10 as an ISA bit, switch to use
an architecture bit.  */
 #define TARGET_POWER8  ((rs6000_arch_flags & ARCH_MASK_POWER8)  != 0)


[gcc(refs/users/meissner/heads/work173)] Update ChangeLog.*

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:b78f446a7e962266a3dd4be002bf54f2dec4fe64

commit b78f446a7e962266a3dd4be002bf54f2dec4fe64
Author: Michael Meissner 
Date:   Wed Jul 24 12:56:54 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.meissner | 12 
 1 file changed, 12 insertions(+)

diff --git a/gcc/ChangeLog.meissner b/gcc/ChangeLog.meissner
index d50a89e9c876..692e2bca61ed 100644
--- a/gcc/ChangeLog.meissner
+++ b/gcc/ChangeLog.meissner
@@ -1,5 +1,17 @@
  Branch work173, patch #2 
 
+Modify how arch flags are set.
+
+2024-07-24  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000.cc (get_arch_flags): Modify how arch flags are
+   set.
+   * config/rs6000/rs6000.h (ARCH_FLAGS_*): Delete.
+
+ Branch work173, patch #2 
+
 Remove -mpower10 and -mpower8-internal
 
 2024-07-23  Michael Meissner  


[gcc r13-8943] libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:46d68bc90688745fc9f25795c371ecaf21e18b56

commit r13-8943-g46d68bc90688745fc9f25795c371ecaf21e18b56
Author: Jonathan Wakely 
Date:   Wed Jul 24 11:32:22 2024 +0100

libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

This questionable combination of flags causes a number of errors. This
one in std::vector needs to be fixed in the gcc-13 branch so I'm
committing it separately to simplify backporting.

libstdc++-v3/ChangeLog:

PR libstdc++/116070
* include/bits/stl_bvector.h: Check feature test macro before
using is_default_constructible_v.

(cherry picked from commit 5fc9c40fea2481e56bf7bcc994cb40c71e28abb8)

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index e18de7c62aa2..63e416053e0f 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -593,7 +593,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX20_CONSTEXPR
_Bvector_impl() _GLIBCXX_NOEXCEPT_IF(
  is_nothrow_default_constructible<_Bit_alloc_type>::value)
-#if __cpp_concepts
+#if __cpp_concepts && __cpp_lib_type_trait_variable_templates
requires is_default_constructible_v<_Bit_alloc_type>
 #endif
: _Bit_alloc_type()


[gcc r15-2275] [rtl-optimization/116037] Explicitly track if a destination was skipped in ext-dce

2024-07-24 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:679086172b84be18c55fdbb9cda7e97806e7c083

commit r15-2275-g679086172b84be18c55fdbb9cda7e97806e7c083
Author: Jeff Law 
Date:   Wed Jul 24 11:16:26 2024 -0600

[rtl-optimization/116037] Explicitly track if a destination was skipped in 
ext-dce

So this has been in the hopper since the first bugs were reported against
ext-dce.  It'd been holding off committing as I was finding other issues in
terms of correctness of live computations.  There's still problems in that
space, but I think it's time to push this chunk forward.  I'm marking it as
116037, but it may impact other bugs.

This patch starts explicitly tracking if set processing skipped a 
destination,
which can happen for wide modes (TI+), vectors, certain subregs, etc.  This 
is
computed during ext_dce_set_processing.

During use processing we use that flag to determine reliably if we need to 
make
the inputs fully live and to avoid even trying to eliminate an extension if 
we
skipped output processing.

While testing this I found that a recent change to fix cases where we had 
two
subreg input operands mucked up the code to make things like a shift/rotate
count fully live.  So that goof has been fixed.

Bootstrapped and regression tested on x86.  Most, but not all, of these 
changes
have also been tested on the crosses.  Pushing to the trunk.

I'm not including it in this patch but I'm poking at converting this code to
use note_uses/note_stores to make it more maintainable.  The SUBREG and
STRICT_LOW_PART handling of note_stores is problematical, but I think it's
solvable.  I haven't tried a conversion to note_uses yet.

PR rtl-optimization/116037
gcc/
* ext-dce.cc (ext_dce_process_sets): Note if we ever skip a dest
and return that info explicitly.
(ext_dce_process_uses): If a set was skipped, then consider all bits
in every input as live.  Do not try to optimize away an extension if
we skipped processing a destination in the same insn.  Restore code
to make shift/rotate count fully live.
(ext_dce_process_bb): Handle API changes for ext_dce_process_sets.

gcc/testsuite/
* gcc.dg/torture/pr116037.c: New test

Diff:
---
 gcc/ext-dce.cc  | 42 ++---
 gcc/testsuite/gcc.dg/torture/pr116037.c | 36 
 2 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/gcc/ext-dce.cc b/gcc/ext-dce.cc
index c56dfb505b88..c94d1fc34145 100644
--- a/gcc/ext-dce.cc
+++ b/gcc/ext-dce.cc
@@ -181,9 +181,11 @@ safe_for_live_propagation (rtx_code code)
within an object) are set by INSN, the more aggressive the
optimization phase during use handling will be.  */
 
-static void
+static bool
 ext_dce_process_sets (rtx_insn *insn, rtx obj, bitmap live_tmp)
 {
+  bool skipped_dest = false;
+
   subrtx_iterator::array_type array;
   FOR_EACH_SUBRTX (iter, array, obj, NONCONST)
 {
@@ -210,6 +212,7 @@ ext_dce_process_sets (rtx_insn *insn, rtx obj, bitmap 
live_tmp)
  /* Skip the subrtxs of this destination.  There is
 little value in iterating into the subobjects, so
 just skip them for a bit of efficiency.  */
+ skipped_dest = true;
  iter.skip_subrtxes ();
  continue;
}
@@ -241,6 +244,7 @@ ext_dce_process_sets (rtx_insn *insn, rtx obj, bitmap 
live_tmp)
  /* Skip the subrtxs of the STRICT_LOW_PART.  We can't
 process them because it'll set objects as no longer
 live when they are in fact still live.  */
+ skipped_dest = true;
  iter.skip_subrtxes ();
  continue;
}
@@ -291,6 +295,7 @@ ext_dce_process_sets (rtx_insn *insn, rtx obj, bitmap 
live_tmp)
  if (!is_a  (GET_MODE (SUBREG_REG (x)), 
&outer_mode)
  || GET_MODE_BITSIZE (outer_mode) > 64)
{
+ skipped_dest = true;
  iter.skip_subrtxes ();
  continue;
}
@@ -318,6 +323,7 @@ ext_dce_process_sets (rtx_insn *insn, rtx obj, bitmap 
live_tmp)
 remain the same.  Thus we can not continue here, we must
 either figure out what part of the destination is modified
 or skip the sub-rtxs.  */
+ skipped_dest = true;
  iter.skip_subrtxes ();
  continue;
}
@@ -370,9 +376,11 @@ ext_dce_process_sets (rtx_insn *insn, rtx obj, bitmap 
live_tmp)
   else if (GET_CODE (x) == COND_EXEC)
{
  /* This isn't ideal, but may not be so bad in practice.  */
+ skipped_dest = true;
  iter.skip_subrtxes ();
}
 }
+  return skipped_dest;
 }
 
 /* INSN has a sign/zero exten

[gcc r15-2276] c++: Mostly concepts related formatting fixes

2024-07-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d2fc64c85788c135419cc3dcf5b4fa64558af547

commit r15-2276-gd2fc64c85788c135419cc3dcf5b4fa64558af547
Author: Jakub Jelinek 
Date:   Wed Jul 24 19:46:58 2024 +0200

c++: Mostly concepts related formatting fixes

When playing with P2963R3, while reading and/or modifying code I've fixed
various comment or code formatting issues (and in 3 spots also comment
wording), but including that in the WIP P2963R3 patch made that patch
totally unreadable because these changes were 4 times the size of the
actual code changes.

So, here it is separated to a pure formatting + comment wording patch.

2024-07-24  Jakub Jelinek  

* constraint.cc (subst_info::quiet, subst_info::noisy): Formatting
fixes.
(known_non_bool_p): Comment formatting fixes.
(unpack_concept_check): Likewise.
(resolve_function_concept_overload): Likewise.
(resolve_function_concept_check): Likewise.
(resolve_concept_check): Likewise.
(deduce_constrained_parameter): Likewise.
(finish_type_constraints): Likewise.
(get_returned_expression): Likewise.
(get_variable_initializer): Likewise.
(norm_info::update_context, norm_info::ctx_params): Formatting
fixes.
(norm_info::context): Comment formatting fixes.
(normalize_logical_operation): Likewise.  Formatting fix.
(normalize_concept_check): Comment formatting fixes.
(normalize_atom): Likewise.
(normalize_expression): Likewise.
(get_normalized_constraints_from_info): Likewise.
(get_normalized_constraints_from_decl): Likewise.  Formatting
fixes.
(atomic_constraints_identical_p): Comment formatting fixes.
(constraints_equivalent_p): Formatting fixes.
(inchash::add_constraint): Likewise.
(associate_classtype_constraints): Comment formatting fixes.
(get_constraints): Likewise.
(set_constraints): Likewise.
(build_concept_check_arguments): Likewise.
(build_function_check): Likewise.
(build_concept_check): Likewise.
(finish_shorthand_constraint): Likewise.
(get_shorthand_constraints): Likewise.
(check_constraint_variables): Likewise.
(tsubst_constraint_variables): Likewise.
(tsubst_requires_expr): Likewise.
(get_mapped_args): Likewise.  Formatting fixes.
(satisfy_atom): Comment formatting fixes.
(satisfy_constraint_r): Comment wording and formatting fixes.
(satisfy_normalized_constraints): Comment formatting fixes.
(satisfy_declaration_constraints): Likewise.
(evaluate_concept_check): Likewise.
(finish_requires_expr): Likewise.
(finish_compound_requirement): Likewise.
(check_function_concept): Likewise.
(equivalently_constrained): Likewise.
(more_constrained): Likewise.
(diagnose_atomic_constraint): Likewise.
* cp-tree.h (TREE_LANG_FLAG_0): Fix a comment error,
FOLD_EXPR_MODIFY_P instead of FOLD_EXPR_MODOP_P.
(DECL_MAIN_FREESTANDING_P, DECL_MAIN_P): Comment formatting fixes.
(enum cpp0x_warn_str): Likewise.
(enum composite_pointer_operation): Likewise.
(enum expr_list_kind): Likewise.
(enum impl_conv_rhs): Likewise.
(enum impl_conv_void): Likewise.
(struct deferred_access_check): Likewise.
(ATOMIC_CONSTR_EXPR): Likewise.
(FUNCTION_REF_QUALIFIED): Likewise.
(DECL_DEPENDENT_P): Likewise.
(FOLD_EXPR_MODIFY_P): Likewise.
(FOLD_EXPR_OP_RAW): Likewise.
(FOLD_EXPR_PACK): Likewise.
(FOLD_EXPR_INIT): Likewise.
(TYPE_WAS_UNNAMED): Likewise.
(class cp_unevaluated): Likewise.
(struct ovl_op_info_t assertion): Likewise.
(cp_declarator::function::requires_clause): Likewise.
(variable_template_p): Likewise.
(concept_definition_p): Likewise.
* logic.cc (clause::clause): Likewise.
(clause::replace): Likewise.
(clause::insert): Likewise.  Formatting fixes.
(struct formula): Comment formatting fixes.
(formula::branch): Likewise.
(debug): Formatting fixes.
(dnf_size_r): Comment formatting fixes.
(cnf_size_r): Likewise.
(dnf_size): Likewise.
(cnf_size): Likewise.
(branch_clause): Likewise.
(decompose_term): Likewise.  Formatting fixes.
(struct subsumption_entry): Comment formatting fixes.
(subsumption_cache): Likewise.
(save_subsumption): Likewise.  Formatting fixes.
(sub

[gcc] Created branch 'devel/fortran_unsigned'

2024-07-24 Thread Thomas Kテカnig via Gcc-cvs
The branch 'devel/fortran_unsigned' was created pointing to:

 f70cf64690ab... Got some basic arithmetic working, test case now run-time.


[gcc/devel/fortran_unsigned] Initial version - add do-nothing -funsigned option and BT_UNSIGNED.

2024-07-24 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:623d8e6272d915e76f1d607a95db9d1624cec572

commit 623d8e6272d915e76f1d607a95db9d1624cec572
Author: Thomas Koenig 
Date:   Sun Jul 21 14:58:54 2024 +0200

Initial version - add do-nothing -funsigned option and BT_UNSIGNED.

Diff:
---
 gcc/fortran/expr.cc   | 3 +++
 gcc/fortran/lang.opt  | 4 
 gcc/fortran/trans-decl.cc | 4 
 gcc/fortran/trans-expr.cc | 4 
 4 files changed, 15 insertions(+)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index be138d196a23..8de694e31da7 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -350,6 +350,9 @@ gfc_copy_expr (gfc_expr *p)
  strncpy (q->boz.str, p->boz.str, p->boz.len);
  break;
 
+   case BT_UNSIGNED:
+ gfc_internal_error ("Unsigned not yet implemented");
+
case BT_PROCEDURE:
 case BT_VOID:
/* Should never be reached.  */
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 5efd4a0129a6..320c31771f81 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -784,6 +784,10 @@ frepack-arrays
 Fortran Var(flag_repack_arrays)
 Copy array sections into a contiguous block on procedure entry.
 
+funsigned
+Fortran Var(flag_unsigned)
+Experimental unsigned numbers.
+
 fcoarray=
 Fortran RejectNegative Joined Enum(gfc_fcoarray) Var(flag_coarray) 
Init(GFC_FCOARRAY_NONE)
 -fcoarray=Specify which coarray parallelization should be 
used.
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index e6ac7f25b3b0..436a4051c057 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -7060,6 +7060,10 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
  type = (sym->ts.u.derived->intmod_sym_id == ISOCBINDING_FUNPTR
? CFI_type_cfunptr : CFI_type_cptr);
  break;
+
+ case BT_UNSIGNED:
+   gfc_internal_error ("Unsigned not yet implemented");
+
case BT_ASSUMED:
case BT_CLASS:
case BT_PROCEDURE:
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index d9eb333abcb1..d431ed5bdea7 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -5822,6 +5822,10 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr 
*e, gfc_symbol *fsym)
}
  else
gcc_unreachable ();
+
+   case BT_UNSIGNED:
+ gfc_internal_error ("Unsigned not yet implemented");
+
case BT_PROCEDURE:
case BT_HOLLERITH:
case BT_UNION:


[gcc/devel/fortran_unsigned] Very first program compiles.

2024-07-24 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:cb2e6d872e374ee0df02414e1c1f31ed4cb28be8

commit cb2e6d872e374ee0df02414e1c1f31ed4cb28be8
Author: Thomas Koenig 
Date:   Mon Jul 22 22:53:27 2024 +0200

Very first program compiles.

Diff:
---
 gcc/fortran/decl.cc  | 11 +
 gcc/fortran/dump-parse-tree.cc   |  8 
 gcc/fortran/expr.cc  |  1 +
 gcc/fortran/gfortran.h   | 20 
 gcc/fortran/libgfortran.h|  2 +-
 gcc/fortran/match.cc |  7 +++
 gcc/fortran/misc.cc  |  6 +++
 gcc/fortran/primary.cc   | 80 
 gcc/fortran/trans-const.cc   | 11 +
 gcc/fortran/trans-types.cc   | 69 +++
 gcc/fortran/trans-types.h|  1 +
 gcc/testsuite/gfortran.dg/unsigned_1.f90 |  8 
 12 files changed, 223 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index b8308aeee550..cc358f09b838 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -4342,6 +4342,17 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int 
implicit_flag)
   goto get_kind;
 }
 
+  if (flag_unsigned)
+{
+  if ((matched_type && strcmp ("unsigned", name) == 0)
+ || (!matched_type && gfc_match (" unsigned") == MATCH_YES))
+   {
+ ts->type = BT_UNSIGNED;
+ ts->kind = gfc_default_integer_kind;
+ goto get_kind;
+   }
+}
+
   if ((matched_type && strcmp ("character", name) == 0)
   || (!matched_type && gfc_match (" character") == MATCH_YES))
 {
diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index 80aa8ef84e71..e94dc495708a 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -563,6 +563,14 @@ show_expr (gfc_expr *p)
fprintf (dumpfile, "_%d", p->ts.kind);
  break;
 
+   case BT_UNSIGNED:
+ mpz_out_str (dumpfile, 10, p->value.integer);
+ fputc('u', dumpfile);
+
+ if (p->ts.kind != gfc_default_integer_kind)
+   fprintf (dumpfile, "_%d", p->ts.kind);
+ break;
+
case BT_LOGICAL:
  if (p->value.logical)
fputs (".true.", dumpfile);
diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 8de694e31da7..2c1f965c73a2 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -159,6 +159,7 @@ gfc_get_constant_expr (bt type, int kind, locus *where)
   switch (type)
 {
 case BT_INTEGER:
+case BT_UNSIGNED:
   mpz_init (e->value.integer);
   break;
 
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 3bdf18d6f9bc..d51960ff0d31 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -2732,6 +2732,25 @@ gfc_integer_info;
 
 extern gfc_integer_info gfc_integer_kinds[];
 
+/* Unsigned numbers, experimental.  */
+
+typedef struct
+{
+  mpz_t huge;
+
+  int kind, radix, digits, bit_size, range;
+
+  /* True if the C type of the given name maps to this precision.  Note that
+ more than one bit can be set.  We will use this later on.  */
+  unsigned int c_unsigned_char : 1;
+  unsigned int c_unsigned_short : 1;
+  unsigned int c_unsigned_int : 1;
+  unsigned int c_unsigned_long : 1;
+  unsigned int c_unsigned_long_long : 1;
+}
+gfc_unsigned_info;
+
+extern gfc_unsigned_info gfc_unsigned_kinds[];
 
 typedef struct
 {
@@ -3455,6 +3474,7 @@ tree gfc_get_union_type (gfc_symbol *);
 tree gfc_get_derived_type (gfc_symbol * derived, int codimen = 0);
 extern int gfc_index_integer_kind;
 extern int gfc_default_integer_kind;
+extern int gfc_default_unsigned_kind;
 extern int gfc_max_integer_kind;
 extern int gfc_default_real_kind;
 extern int gfc_default_double_kind;
diff --git a/gcc/fortran/libgfortran.h b/gcc/fortran/libgfortran.h
index 2cb4a5a08ffd..895629d6f801 100644
--- a/gcc/fortran/libgfortran.h
+++ b/gcc/fortran/libgfortran.h
@@ -190,7 +190,7 @@ typedef enum
 typedef enum
 { BT_UNKNOWN = 0, BT_INTEGER, BT_LOGICAL, BT_REAL, BT_COMPLEX,
   BT_DERIVED, BT_CHARACTER, BT_CLASS, BT_PROCEDURE, BT_HOLLERITH, BT_VOID,
-  BT_ASSUMED, BT_UNION, BT_BOZ
+  BT_ASSUMED, BT_UNION, BT_BOZ, BT_UNSIGNED
 }
 bt;
 
diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc
index 1851a8f94a54..e206da95bde1 100644
--- a/gcc/fortran/match.cc
+++ b/gcc/fortran/match.cc
@@ -2131,6 +2131,13 @@ gfc_match_type_spec (gfc_typespec *ts)
   goto kind_selector;
 }
 
+  if (flag_unsigned && gfc_match ("unsigned") == MATCH_YES)
+{
+  ts->type = BT_UNSIGNED;
+  ts->kind = gfc_default_integer_kind;
+  goto kind_selector;
+}
+
   if (gfc_match ("double precision") == MATCH_YES)
 {
   ts->type = BT_REAL;
diff --git a/gcc/fortran/misc.cc b/gcc/fortran/misc.cc
index a365cec9b492..991829516efe 100644
--- a/gcc/fortran/misc.cc
+++ b/gcc/fortran/misc.cc
@@ -70,6 +70,9 @@ gfc_basic_typename (bt type)
 case BT_INTEGER:
   p = "INTEGER";
   break;
+case BT_

[gcc/devel/fortran_unsigned] Got some basic arithmetic working, test case now run-time.

2024-07-24 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:f70cf64690ab718b40763be506ec47e135e666f3

commit f70cf64690ab718b40763be506ec47e135e666f3
Author: Thomas Koenig 
Date:   Wed Jul 24 22:35:49 2024 +0200

Got some basic arithmetic working, test case now run-time.

Diff:
---
 gcc/fortran/arith.cc | 13 +-
 gcc/fortran/check.cc |  9 +++
 gcc/fortran/expr.cc  |  3 ++-
 gcc/fortran/gfortran.h   |  2 ++
 gcc/fortran/primary.cc   | 42 ++--
 gcc/fortran/resolve.cc   | 27 +++-
 gcc/fortran/simplify.cc  | 18 +++---
 gcc/testsuite/gfortran.dg/unsigned_1.f90 | 13 ++
 8 files changed, 97 insertions(+), 30 deletions(-)

diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
index b373c25e5e12..a7b8af7779d1 100644
--- a/gcc/fortran/arith.cc
+++ b/gcc/fortran/arith.cc
@@ -1719,14 +1719,25 @@ eval_intrinsic (gfc_intrinsic_op op,
 
 gcc_fallthrough ();
 /* Numeric binary  */
+case INTRINSIC_POWER:
+  if (flag_unsigned)
+   {
+ if (op1->ts.type == BT_UNSIGNED || op2->ts.type == BT_UNSIGNED)
+   goto runtime;
+   }
+
+  gcc_fallthrough();
+
 case INTRINSIC_PLUS:
 case INTRINSIC_MINUS:
 case INTRINSIC_TIMES:
 case INTRINSIC_DIVIDE:
-case INTRINSIC_POWER:
   if (!gfc_numeric_ts (&op1->ts) || !gfc_numeric_ts (&op2->ts))
goto runtime;
 
+  if (flag_unsigned && gfc_invalid_unsigned_ops (op1, op2))
+   goto runtime;
+
   /* Do not perform conversions if operands are not conformable as
 required for the binary intrinsic operators (F2018:10.1.5).
 Defer to a possibly overloading user-defined operator.  */
diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index 2f50d84b876f..e90a99df1e2b 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -7637,3 +7637,12 @@ gfc_check_storage_size (gfc_expr *a, gfc_expr *kind)
 
   return true;
 }
+
+/* Check two operands that either both or none of them can
+   be UNSIGNED.  */
+
+bool
+gfc_invalid_unsigned_ops (gfc_expr * op1, gfc_expr * op2)
+{
+  return (op1->ts.type == BT_UNSIGNED) + (op2->ts.type == BT_UNSIGNED) == 1;
+}
diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 2c1f965c73a2..545a64dba239 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -903,7 +903,8 @@ gfc_kind_max (gfc_expr *e1, gfc_expr *e2)
 static bool
 numeric_type (bt type)
 {
-  return type == BT_COMPLEX || type == BT_REAL || type == BT_INTEGER;
+  return type == BT_COMPLEX || type == BT_REAL || type == BT_INTEGER
+|| type == BT_UNSIGNED;
 }
 
 
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index d51960ff0d31..3e20821cceae 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -4021,6 +4021,7 @@ bool gfc_boz2real (gfc_expr *, int);
 bool gfc_invalid_boz (const char *, locus *);
 bool gfc_invalid_null_arg (gfc_expr *);
 
+bool gfc_invalid_unsigned_ops (gfc_expr *, gfc_expr *);
 
 /* class.cc */
 void gfc_fix_class_refs (gfc_expr *e);
@@ -4103,6 +4104,7 @@ void gfc_convert_mpz_to_signed (mpz_t, int);
 gfc_expr *gfc_simplify_ieee_functions (gfc_expr *);
 bool gfc_is_constant_array_expr (gfc_expr *);
 bool gfc_is_size_zero_array (gfc_expr *);
+void gfc_convert_mpz_to_unsigned (mpz_t, int);
 
 /* trans-array.cc  */
 
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index d2a6e69fa428..c1aa0bc77c91 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -210,20 +210,27 @@ convert_integer (const char *buffer, int kind, int radix, 
locus *where)
 
 
 /* Convert an unsigned string to an expression node.  XXX:
-   This needs a calculation modulo 2^n.  */
+   This needs a calculation modulo 2^n.  TODO: Implement restriction
+   that no unary minus is permitted.  */
 static gfc_expr *
 convert_unsigned (const char *buffer, int kind, int radix, locus *where)
 {
   gfc_expr *e;
-  mpz_t tmp;
-  mpz_init_set_ui (tmp, 1);
-  /* XXX  Change this later.  */
-  mpz_mul_2exp (tmp, tmp, kind * 8);
-  mpz_sub_ui (tmp, tmp, 1);
+  const char *t;
+  int k;
+
   e = gfc_get_constant_expr (BT_UNSIGNED, kind, where);
-  mpz_set_str (e->value.integer, buffer, radix);
-  mpz_and (e->value.integer, e->value.integer, tmp);
-  mpz_clear (tmp);
+  /* A leading plus is allowed, but not by mpz_set_str.  */
+  if (buffer[0] == '+')
+t = buffer + 1;
+  else
+t = buffer;
+
+  mpz_set_str (e->value.integer, t, radix);
+
+  k = gfc_validate_kind (BT_UNSIGNED, kind, false);
+  gfc_convert_mpz_to_unsigned (e->value.integer, 
gfc_unsigned_kinds[k].bit_size);
+
   return e;
 }
 
@@ -333,9 +340,15 @@ match_unsigned_constant (gfc_expr **result)
   gfc_gobble_whitespace ();
 
   length = match_digits (/* signflag = */ false, 10, NULL);
-  gfc_current_locus = old_loc;
+
   if (length == -1)
-return MATCH_NO;
+goto fail;
+
+  m = gfc_match_char ('u');
+  if (m == MATCH_NO)
+goto fail;
+
+  

[gcc r15-2277] c++: parse error with -std=c++14 -fconcepts [PR116071]

2024-07-24 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:8c71830b51e6fd10087ce3f6791de80eb1f10b96

commit r15-2277-g8c71830b51e6fd10087ce3f6791de80eb1f10b96
Author: Jason Merrill 
Date:   Wed Jul 24 16:20:33 2024 -0400

c++: parse error with -std=c++14 -fconcepts [PR116071]

cp_parser_simple_type_specifier tries a variety of different things that
might qualify as a user-defined type: an actual type-name, a constrained
auto, a CTAD placeholder.  In a context where a type-specifier is optional,
this is all tentative.  With -std=c++14 -fconcepts, we try type-name and
constrained auto in sub-tentative parses, and when we run out of things to
try we haven't found anything but also haven't failed the outer tentative
parse, so parse_definitely succeeds, discarding the nested-name-specifier.

Fixed by failing if we didn't find anything.

I said in r14-3203 that we should disable this combination of flags if
further problems arise, but this seems like a more general problem that only
happened to occur with just this combination of flags.  So it lives on.

PR c++/116071

gcc/cp/ChangeLog:

* parser.cc (cp_parser_simple_type_specifier): Call
cp_parser_simulate_error if nothing worked.

gcc/testsuite/ChangeLog:

* g++.dg/parse/pr116071.C: New test.

Diff:
---
 gcc/cp/parser.cc  | 10 +++---
 gcc/testsuite/g++.dg/parse/pr116071.C | 18 ++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 1fa0780944b6..f79736c17ac6 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -20786,9 +20786,13 @@ cp_parser_simple_type_specifier (cp_parser* parser,
}
 
   /* If it didn't work out, we don't have a TYPE.  */
-  if ((flags & CP_PARSER_FLAGS_OPTIONAL)
- && !cp_parser_parse_definitely (parser))
-   type = NULL_TREE;
+  if (flags & CP_PARSER_FLAGS_OPTIONAL)
+   {
+ if (!type)
+   cp_parser_simulate_error (parser);
+ if (!cp_parser_parse_definitely (parser))
+   type = NULL_TREE;
+   }
 
   /* Keep track of all name-lookups performed in class scopes.  */
   if (type
diff --git a/gcc/testsuite/g++.dg/parse/pr116071.C 
b/gcc/testsuite/g++.dg/parse/pr116071.C
new file mode 100644
index ..7590782d5ee8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/pr116071.C
@@ -0,0 +1,18 @@
+// PR c++/116071
+// { dg-options "-std=c++14 -fconcepts" }
+
+template struct S { ~S(); };
+template S::~S() { }
+
+template
+struct result_of;
+
+template
+struct result_of
+{
+  using type = void;
+};
+
+struct thread {
+  void join() { };
+};


[gcc r15-2279] json: add array::append_string

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:3f14878fbfcd69b316e2be195c3377a750ad6031

commit r15-2279-g3f14878fbfcd69b316e2be195c3377a750ad6031
Author: David Malcolm 
Date:   Wed Jul 24 18:07:51 2024 -0400

json: add array::append_string

No functional change intended.

gcc/analyzer/ChangeLog:
* supergraph.cc (supernode::to_json): Avoid naked "new" by using
json::array::append_string.
(supernode::to_json): Likewise.

gcc/ChangeLog:
* diagnostic-format-sarif.cc (sarif_artifact::populate_roles):
Avoid naked "new" by using json::array::append_string.
(sarif_builder::maybe_make_kinds_array): Likewise.
* json.cc (json::array::append_string): New.
(selftest::test_writing_arrays): Use it.
* json.h (json::array::append_string): New decl.
* optinfo-emit-json.cc (optrecord_json_writer::pass_to_json):
Avoid naked "new" by using json::array::append_string.
(optrecord_json_writer::optinfo_to_json): Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/analyzer/supergraph.cc | 4 ++--
 gcc/diagnostic-format-sarif.cc | 8 
 gcc/json.cc| 9 -
 gcc/json.h | 1 +
 gcc/optinfo-emit-json.cc   | 4 ++--
 5 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/gcc/analyzer/supergraph.cc b/gcc/analyzer/supergraph.cc
index 4dc7942b26aa..20c62856d4b6 100644
--- a/gcc/analyzer/supergraph.cc
+++ b/gcc/analyzer/supergraph.cc
@@ -747,7 +747,7 @@ supernode::to_json () const
pretty_printer pp;
pp_format_decoder (&pp) = default_tree_printer;
pp_gimple_stmt_1 (&pp, stmt, 0, (dump_flags_t)0);
-   phi_arr->append (new json::string (pp_formatted_text (&pp)));
+   phi_arr->append_string (pp_formatted_text (&pp));
   }
 snode_obj->set ("phis", phi_arr);
   }
@@ -762,7 +762,7 @@ supernode::to_json () const
pretty_printer pp;
pp_format_decoder (&pp) = default_tree_printer;
pp_gimple_stmt_1 (&pp, stmt, 0, (dump_flags_t)0);
-   stmt_arr->append (new json::string (pp_formatted_text (&pp)));
+   stmt_arr->append_string (pp_formatted_text (&pp));
   }
 snode_obj->set ("stmts", stmt_arr);
   }
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 225476995d13..7105f7853318 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -435,7 +435,7 @@ sarif_artifact::populate_roles ()
 if (bitmap_bit_p (m_roles, i))
   {
enum diagnostic_artifact_role role = (enum diagnostic_artifact_role)i;
-   roles_arr->append (new json::string (get_artifact_role_string (role)));
+   roles_arr->append_string (get_artifact_role_string (role));
   }
   set ("roles", roles_arr);
 }
@@ -1394,13 +1394,13 @@ sarif_builder::maybe_make_kinds_array 
(diagnostic_event::meaning m) const
   json::array *kinds_arr = new json::array ();
   if (const char *verb_str
= diagnostic_event::meaning::maybe_get_verb_str (m.m_verb))
-kinds_arr->append (new json::string (verb_str));
+kinds_arr->append_string (verb_str);
   if (const char *noun_str
= diagnostic_event::meaning::maybe_get_noun_str (m.m_noun))
-kinds_arr->append (new json::string (noun_str));
+kinds_arr->append_string (noun_str);
   if (const char *property_str
= diagnostic_event::meaning::maybe_get_property_str (m.m_property))
-kinds_arr->append (new json::string (property_str));
+kinds_arr->append_string (property_str);
   return kinds_arr;
 }
 
diff --git a/gcc/json.cc b/gcc/json.cc
index 53edca520556..86490259dabf 100644
--- a/gcc/json.cc
+++ b/gcc/json.cc
@@ -286,6 +286,13 @@ array::append (value *v)
   m_elements.safe_push (v);
 }
 
+void
+array::append_string (const char *utf8_value)
+{
+  gcc_assert (utf8_value);
+  append (new json::string (utf8_value));
+}
+
 /* class json::float_number, a subclass of json::value, wrapping a double.  */
 
 /* Implementation of json::value::print for json::float_number.  */
@@ -432,7 +439,7 @@ test_writing_arrays ()
   arr.append (new json::string ("foo"));
   ASSERT_PRINT_EQ (arr, true, "[\"foo\"]");
 
-  arr.append (new json::string ("bar"));
+  arr.append_string ("bar");
   ASSERT_PRINT_EQ (arr, true,
   "[\"foo\",\n"
   " \"bar\"]");
diff --git a/gcc/json.h b/gcc/json.h
index ad4f8c448f8c..d3493a72d525 100644
--- a/gcc/json.h
+++ b/gcc/json.h
@@ -130,6 +130,7 @@ class array : public value
   void print (pretty_printer *pp, bool formatted) const final override;
 
   void append (value *v);
+  void append_string (const char *utf8_value);
 
  private:
   auto_vec m_elements;
diff --git a/gcc/optinfo-emit-json.cc b/gcc/optinfo-emit-json.cc
index 1fa82d438db9..faae95fc232a 100644
--- a/gcc/optinfo-emit-json.cc
+++ b/gcc/optinfo-emit-json.cc
@@ -259,7 +259,7 @@ optrecord_json_writer::pass_to_json (opt_pass *pass)
 optgroup

[gcc r15-2278] json: add dump overload for easier debugging

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:6baa26c3d6ceec1aba5f143dbfef00e24aa795bb

commit r15-2278-g6baa26c3d6ceec1aba5f143dbfef00e24aa795bb
Author: David Malcolm 
Date:   Wed Jul 24 18:07:51 2024 -0400

json: add dump overload for easier debugging

This has saved me a lot of typing in the debugger.

gcc/ChangeLog:
* json.cc (value::dump): New overload, taking no params.
* json.h (value::dump): New decl.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/json.cc | 10 ++
 gcc/json.h  |  1 +
 2 files changed, 11 insertions(+)

diff --git a/gcc/json.cc b/gcc/json.cc
index b3106f39cedf..53edca520556 100644
--- a/gcc/json.cc
+++ b/gcc/json.cc
@@ -90,6 +90,16 @@ value::dump (FILE *outf, bool formatted) const
   pp_flush (&pp);
 }
 
+/* A convenience function for debugging.
+   Dump to stderr with formatting, and a trailing newline. */
+
+void
+value::dump () const
+{
+  dump (stderr, true);
+  fprintf (stderr, "\n");
+}
+
 /* class json::object, a subclass of json::value, representing
an ordered collection of key/value pairs.  */
 
diff --git a/gcc/json.h b/gcc/json.h
index 97c68116b329..ad4f8c448f8c 100644
--- a/gcc/json.h
+++ b/gcc/json.h
@@ -83,6 +83,7 @@ class value
   virtual void print (pretty_printer *pp, bool formatted) const = 0;
 
   void dump (FILE *, bool formatted) const;
+  void DEBUG_FUNCTION dump () const;
 };
 
 /* Subclass of value for objects: a collection of key/value pairs


[gcc r15-2280] analyzer: reduce use of naked "new" for json dumps

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:78d1906c982ad49a0742a7bc1624762159ca165c

commit r15-2280-g78d1906c982ad49a0742a7bc1624762159ca165c
Author: David Malcolm 
Date:   Wed Jul 24 18:07:52 2024 -0400

analyzer: reduce use of naked "new" for json dumps

No functional change intended.

gcc/analyzer/ChangeLog:
* call-string.cc (call_string::to_json): Avoid naked "new".
* constraint-manager.cc (bounded_range::set_json_attr): Likewise.
(equiv_class::to_json): Likewise.
(constraint::to_json): Likewise.
(bounded_ranges_constraint::to_json): Likewise.
* diagnostic-manager.cc (saved_diagnostic::to_json): Likewise.
(saved_diagnostic::maybe_add_sarif_properties): Likewise.
* engine.cc (exploded_node::to_json): Likewise.
(exploded_edge::to_json): Likewise.
* program-point.cc (program_point::to_json): Likewise.
* program-state.cc (program_state::to_json): Likewise.
* sm.cc (state_machine::to_json): Likewise.
* store.cc (binding_cluster::to_json): Likewise.
(store::to_json): Likewise.
* supergraph.cc (supernode::to_json): Likewise.
(superedge::to_json): Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/analyzer/call-string.cc|  9 +++--
 gcc/analyzer/constraint-manager.cc | 12 ++--
 gcc/analyzer/diagnostic-manager.cc | 14 +++---
 gcc/analyzer/engine.cc | 13 ++---
 gcc/analyzer/program-point.cc  | 11 ---
 gcc/analyzer/program-state.cc  |  2 +-
 gcc/analyzer/sm.cc |  2 +-
 gcc/analyzer/store.cc  |  6 +++---
 gcc/analyzer/supergraph.cc | 17 -
 9 files changed, 39 insertions(+), 47 deletions(-)

diff --git a/gcc/analyzer/call-string.cc b/gcc/analyzer/call-string.cc
index 23880e3f5419..c404c09ca0df 100644
--- a/gcc/analyzer/call-string.cc
+++ b/gcc/analyzer/call-string.cc
@@ -111,12 +111,9 @@ call_string::to_json () const
   for (const call_string::element_t &e : m_elements)
 {
   json::object *e_obj = new json::object ();
-  e_obj->set ("src_snode_idx",
- new json::integer_number (e.m_callee->m_index));
-  e_obj->set ("dst_snode_idx",
- new json::integer_number (e.m_caller->m_index));
-  e_obj->set ("funcname",
- new json::string (function_name (e.m_caller->m_fun)));
+  e_obj->set_integer ("src_snode_idx", e.m_callee->m_index);
+  e_obj->set_integer ("dst_snode_idx", e.m_caller->m_index);
+  e_obj->set_string ("funcname", function_name (e.m_caller->m_fun));
   arr->append (e_obj);
 }
 
diff --git a/gcc/analyzer/constraint-manager.cc 
b/gcc/analyzer/constraint-manager.cc
index 29539060ebdd..62d3b84bb745 100644
--- a/gcc/analyzer/constraint-manager.cc
+++ b/gcc/analyzer/constraint-manager.cc
@@ -479,7 +479,7 @@ bounded_range::set_json_attr (json::object *obj, const char 
*name, tree value)
   pretty_printer pp;
   pp_format_decoder (&pp) = default_tree_printer;
   pp_printf (&pp, "%E", value);
-  obj->set (name, new json::string (pp_formatted_text (&pp)));
+  obj->set_string (name, pp_formatted_text (&pp));
 }
 
 
@@ -1140,7 +1140,7 @@ equiv_class::to_json () const
   pretty_printer pp;
   pp_format_decoder (&pp) = default_tree_printer;
   pp_printf (&pp, "%qE", m_constant);
-  ec_obj->set ("constant", new json::string (pp_formatted_text (&pp)));
+  ec_obj->set_string ("constant", pp_formatted_text (&pp));
 }
 
   return ec_obj;
@@ -1397,9 +1397,9 @@ constraint::to_json () const
 {
   json::object *con_obj = new json::object ();
 
-  con_obj->set ("lhs", new json::integer_number (m_lhs.as_int ()));
-  con_obj->set ("op", new json::string (constraint_op_code (m_op)));
-  con_obj->set ("rhs", new json::integer_number (m_rhs.as_int ()));
+  con_obj->set_integer ("lhs", m_lhs.as_int ());
+  con_obj->set_string ("op", constraint_op_code (m_op));
+  con_obj->set_integer ("rhs", m_rhs.as_int ());
 
   return con_obj;
 }
@@ -1485,7 +1485,7 @@ bounded_ranges_constraint::to_json () const
 {
   json::object *con_obj = new json::object ();
 
-  con_obj->set ("ec", new json::integer_number (m_ec_id.as_int ()));
+  con_obj->set_integer ("ec", m_ec_id.as_int ());
   con_obj->set ("ranges", m_ranges->to_json ());
 
   return con_obj;
diff --git a/gcc/analyzer/diagnostic-manager.cc 
b/gcc/analyzer/diagnostic-manager.cc
index 51304b0795b6..92e30bd049bd 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -746,17 +746,17 @@ saved_diagnostic::to_json () const
   json::object *sd_obj = new json::object ();
 
   if (m_sm)
-sd_obj->set ("sm", new json::string (m_sm->get_name ()));
-  sd_obj->set ("enode", new json::integer_number (m_enode->m_index));
-  sd_obj->set ("snode", new json::integer_number (m_snode->m_index));
+sd_obj->set_string ("sm", m_sm->get_name ());
+  sd_

[gcc r15-2281] gcov: reduce use of naked "new" for json output

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:da0def223e82a4a9400915b2957e96f9f060f5af

commit r15-2281-gda0def223e82a4a9400915b2957e96f9f060f5af
Author: David Malcolm 
Date:   Wed Jul 24 18:07:52 2024 -0400

gcov: reduce use of naked "new" for json output

No functional change intended.

gcc/ChangeLog:
* gcov.cc (output_intermediate_json_line): Use
json::object::set_integer to avoid naked "new".

Signed-off-by: David Malcolm 

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

diff --git a/gcc/gcov.cc b/gcc/gcov.cc
index e76a314041cd..85fdac4368e8 100644
--- a/gcc/gcov.cc
+++ b/gcc/gcov.cc
@@ -1285,8 +1285,8 @@ output_intermediate_json_line (json::array *object,
const int covered = info.popcount ();
 
json::object *cond = new json::object ();
-   cond->set ("count", new json::integer_number (count));
-   cond->set ("covered", new json::integer_number (covered));
+   cond->set_integer ("count", count);
+   cond->set_integer ("covered", covered);
 
json::array *mtrue = new json::array ();
json::array *mfalse = new json::array ();


[gcc r15-2282] diagnostics: SARIF output: add sarif_object subclasses throughout

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:5342c63f4fb49c110c6252538cb954779c6ff156

commit r15-2282-g5342c63f4fb49c110c6252538cb954779c6ff156
Author: David Malcolm 
Date:   Wed Jul 24 18:07:52 2024 -0400

diagnostics: SARIF output: add sarif_object subclasses throughout

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-sarif.cc: Introduce subclasses of sarif_object
for all aspects of the spec that we're using.  Replace almost all
usage of json::object with uses of these subclasses, the only
remaining use of json::object being for originalUriBaseIds, as per
SARIF 2.1.0 §3.14.14.  This stronger typing makes it considerably
easier to maintain validity against the schema.
* diagnostic-format-sarif.h (class sarif_logical_location): New.
(make_sarif_logical_location_object): Convert return type from
json::object * to sarif_logical_location *.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc | 605 ++---
 gcc/diagnostic-format-sarif.h  |   9 +-
 2 files changed, 399 insertions(+), 215 deletions(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 7105f7853318..c35d8788d6de 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -36,18 +36,87 @@ along with GCC; see the file COPYING3.  If not see
 #include "ordered-hash-map.h"
 #include "sbitmap.h"
 
+/* Forward decls.  */
 class sarif_builder;
 
-/* Subclass of json::object for SARIF invocation objects
+/* Subclasses of sarif_object.
+   Keep these in order of their descriptions in the specification.  */
+class sarif_artifact_content; // 3.3
+class sarif_artifact_location; // 3.4
+class sarif_message; // 3.11
+class sarif_multiformat_message_string; // 3.12
+class sarif_log; // 3.13
+class sarif_run; // 3.14
+class sarif_tool; // 3.18
+class sarif_tool_component; // 3.19
+class sarif_invocation; // 3.20
+class sarif_artifact; // 3.24
+class sarif_result; // 3.27
+class sarif_location; // 3.28
+class sarif_physical_location; // 3.29
+class sarif_region; // 3.30
+class sarif_logical_location; // 3.33
+class sarif_code_flow; // 3.36
+class sarif_thread_flow; // 3.37
+class sarif_thread_flow_location; // 3.38
+class sarif_reporting_descriptor; // 3.49
+class sarif_reporting_descriptor_reference; // 3.53
+class sarif_tool_component_reference; // 3.54
+class sarif_fix; // 3.55
+class sarif_artifact_change; // 3.56
+class sarif_replacement; // 3.57
+class sarif_ice_notification; // 3.58
+
+/* Declarations of subclasses of sarif_object.
+   Keep these in order of their descriptions in the specification.  */
+
+/* Subclass of sarif_object for SARIF "artifactContent" objects
+   (SARIF v2.1.0 section 3.3).  */
+
+class sarif_artifact_content : public sarif_object {};
+
+/* Subclass of sarif_object for SARIF "artifactLocation" objects
+   (SARIF v2.1.0 section 3.4).  */
+
+class sarif_artifact_location : public sarif_object {};
+
+/* Subclass of sarif_object for SARIF "message" objects
+   (SARIF v2.1.0 section 3.11).  */
+
+class sarif_message : public sarif_object {};
+
+/* Subclass of sarif_object for SARIF "multiformatMessageString" objects
+   (SARIF v2.1.0 section 3.12).  */
+
+class sarif_multiformat_message_string : public sarif_object {};
+
+/* Subclass of sarif_object for SARIF "log" objects
+   (SARIF v2.1.0 section 3.13).  */
+
+class sarif_log : public sarif_object {};
+
+/* Subclass of sarif_object for SARIF "run" objects
+   (SARIF v2.1.0 section 3.14).  */
+
+class sarif_run : public sarif_object {};
+
+/* Subclass of sarif_object for SARIF "tool" objects
+   (SARIF v2.1.0 section 3.18).  */
+
+class sarif_tool : public sarif_object {};
+
+/* Subclass of sarif_object for SARIF "toolComponent" objects
+   (SARIF v2.1.0 section 3.19).  */
+
+class sarif_tool_component : public sarif_object {};
+
+/* Subclass of sarif_object for SARIF "invocation" objects
(SARIF v2.1.0 section 3.20).  */
 
 class sarif_invocation : public sarif_object
 {
 public:
-  sarif_invocation ()
-  : m_notifications_arr (new json::array ()),
-m_success (true)
-  {}
+  sarif_invocation ();
 
   void add_notification_for_ice (diagnostic_context *context,
 const diagnostic_info &diagnostic,
@@ -104,7 +173,7 @@ private:
   bool m_embed_contents;
 };
 
-/* Subclass of sarif_object for SARIF result objects
+/* Subclass of sarif_object for SARIF "result" objects
(SARIF v2.1.0 section 3.27).  */
 
 class sarif_result : public sarif_object
@@ -122,42 +191,95 @@ public:
   sarif_builder *builder);
 
 private:
-  void add_related_location (json::object *location_obj);
+  void
+  add_related_location (sarif_location *location_obj);
 
   json::array *m_related_locations_arr;
 };
 
-/* Subclass of sarif_object for SARIF notification objects
-   (SARIF v2.1.0 section 3.58).
+/* Subclass of sar

[gcc r15-2283] diagnostics: output formats: use references for non-null pointers

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:29522bff8f4940a6b4307da0021e257c98eeecea

commit r15-2283-g29522bff8f4940a6b4307da0021e257c98eeecea
Author: David Malcolm 
Date:   Wed Jul 24 18:07:53 2024 -0400

diagnostics: output formats: use references for non-null pointers

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-json.cc (json_from_expanded_location): Make
"static". Pass param "context" by reference, as it cannot be null.
(json_from_location_range): Likewise for param "context".
(json_from_fixit_hint): Likewise.
(make_json_for_path): Likewise.
(json_output_format::on_end_diagnostic): Update for above changes.

(diagnostic_output_format_init_json::diagnostic_output_format_init_json):
Pass param "context" by reference, as it cannot be null.
(diagnostic_output_format_init_json_stderr): Likewise.
(diagnostic_output_format_init_json_file): Likewise.
(selftest::test_unknown_location): Update for above changes.
(selftest::test_bad_endpoints): Likewise.
* diagnostic-format-sarif.cc (sarif_builder::m_context): Convert
from pointer to reference.
(sarif_invocation::add_notification_for_ice): Convert both params
from pointers to references.
(sarif_invocation::prepare_to_flush): Likewise for "context".
(sarif_result::on_nested_diagnostic): Likewise for "context" and
"builder".
(sarif_result::on_diagram): Likewise.
(sarif_ice_notification::sarif_ice_notification): Likewise.
(sarif_builder::sarif_builder): Likewise for "context".
(sarif_builder::end_diagnostic): Likewise.
(sarif_builder::emit_diagram): Likewise.
(sarif_builder::make_result_object): Likewise.
(make_reporting_descriptor_object_for_warning): Likewise.
(sarif_builder::make_locations_arr): Update for change to m_context.
(sarif_builder::get_sarif_column): Likewise.
(sarif_builder::make_message_object_for_diagram): Convert "context"
from pointer to reference.
(sarif_builder::make_tool_object): Likewise for "m_context".
(sarif_builder::make_driver_tool_component_object): Likewise.
(sarif_builder::get_or_create_artifact): Likewise.
(sarif_builder::maybe_make_artifact_content_object): Likewise.
(sarif_builder::get_source_lines): Likewise.
(sarif_output_format::on_end_diagnostic): Update for above changes.
(sarif_output_format::on_diagram): Likewise.
(sarif_output_format::sarif_output_format): Likewise.
(diagnostic_output_format_init_sarif): Convert param "context"
from pointer to reference.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* diagnostic.cc (diagnostic_output_format_init): Likewise.
* diagnostic.h (diagnostic_output_format_init): Likewise.
(diagnostic_output_format_init_json_stderr): Likewise.
(diagnostic_output_format_init_json_file): Likewise.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
(json_from_expanded_location): Delete decl.
* gcc.cc (driver_handle_option): Update for change to
diagnostic_output_format_init.
* opts.cc (common_handle_option): Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-json.cc  |  56 +++---
 gcc/diagnostic-format-sarif.cc | 166 -
 gcc/diagnostic.cc  |   2 +-
 gcc/diagnostic.h   |  15 ++--
 gcc/gcc.cc |   3 +-
 gcc/opts.cc|   3 +-
 6 files changed, 122 insertions(+), 123 deletions(-)

diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 4dc0f264fc70..1bf8da663cc2 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -94,8 +94,8 @@ private:
 
 /* Generate a JSON object for LOC.  */
 
-json::value *
-json_from_expanded_location (diagnostic_context *context, location_t loc)
+static json::value *
+json_from_expanded_location (diagnostic_context &context, location_t loc)
 {
   expanded_location exploc = expand_location (loc);
   json::object *result = new json::object ();
@@ -103,7 +103,7 @@ json_from_expanded_location (diagnostic_context *context, 
location_t loc)
 result->set_string ("file", exploc.file);
   result->set_integer ("line", exploc.line);
 
-  const enum diagnostics_column_unit orig_unit = context->m_column_unit;
+  co

[gcc r15-2284] json: support std::unique_ptr in array::append and object::set

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:2486234b5ae0d71ca7bbdc6e216b4707cd5bef15

commit r15-2284-g2486234b5ae0d71ca7bbdc6e216b4707cd5bef15
Author: David Malcolm 
Date:   Wed Jul 24 18:07:53 2024 -0400

json: support std::unique_ptr in array::append and object::set

This patch uses templates to add overloads of json::array::append and
json::object::set taking std::unique_ptr where T is a subclass of
json::value.

Doing so makes it much easier to track memory ownership and enforce
schema validity when constructing non-trivial JSON; using the wrong
kind of JSON value leads to compile-time errors like the following:

error: cannot convert ‘unique_ptr’ to ‘unique_ptr’
  629 |   location_obj->set ("message", std::move (message_obj));
  |~~^
  |  |
  |  
unique_ptr

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-json.cc: Define INCLUDE_MEMORY.
* diagnostic-format-sarif.cc: Likewise.
* dumpfile.cc: Likewise.
* gcov.cc: Likewise.
* json.cc: Likewise.  Include "make-unique.h".
(selftest::test_formatting): Exercise overloads of
array::append and object::set that use unique_ptr.
* json.h: Require INCLUDE_MEMORY to have been defined.
(json::object::set): Add a template to add a family of overloads
taking a std::unique_ptr
(json::array::append): Likewise.
* optinfo-emit-json.cc: Define INCLUDE_MEMORY.
* optinfo.cc: Likewise.
* timevar.cc: Likewise.
* toplev.cc: Likewise.
* tree-diagnostic-client-data-hooks.cc: Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-json.cc|  1 +
 gcc/diagnostic-format-sarif.cc   |  1 +
 gcc/dumpfile.cc  |  1 +
 gcc/gcov.cc  |  1 +
 gcc/json.cc  | 17 +-
 gcc/json.h   | 38 
 gcc/optinfo-emit-json.cc |  1 +
 gcc/optinfo.cc   |  1 +
 gcc/timevar.cc   |  1 +
 gcc/toplev.cc|  1 +
 gcc/tree-diagnostic-client-data-hooks.cc |  1 +
 11 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 1bf8da663cc2..55ba39e0c532 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "diagnostic.h"
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index d6de5806f5ac..6aba81c6ac9b 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #define INCLUDE_VECTOR
 #include "system.h"
 #include "coretypes.h"
diff --git a/gcc/dumpfile.cc b/gcc/dumpfile.cc
index 82bd8b06bebf..6353c0857449 100644
--- a/gcc/dumpfile.cc
+++ b/gcc/dumpfile.cc
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 .  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "options.h"
diff --git a/gcc/gcov.cc b/gcc/gcov.cc
index 85fdac4368e8..aa016c658ce0 100644
--- a/gcc/gcov.cc
+++ b/gcc/gcov.cc
@@ -32,6 +32,7 @@ along with Gcov; see the file COPYING3.  If not see
 
 #include "config.h"
 #define INCLUDE_ALGORITHM
+#define INCLUDE_MEMORY
 #define INCLUDE_VECTOR
 #define INCLUDE_STRING
 #define INCLUDE_MAP
diff --git a/gcc/json.cc b/gcc/json.cc
index 86490259dabf..275ef486faf1 100644
--- a/gcc/json.cc
+++ b/gcc/json.cc
@@ -19,11 +19,13 @@ along with GCC; see the file COPYING3.  If not see
 .  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "json.h"
 #include "pretty-print.h"
 #include "math.h"
+#include "make-unique.h"
 #include "selftest.h"
 
 using namespace json;
@@ -499,28 +501,31 @@ test_writing_literals ()
   ASSERT_PRINT_EQ (literal (false), true, "false");
 }
 
-/* Verify that nested values are formatted correctly when written.  */
+/* Verify that nested values are formatted correctly when written.
+
+   Also, make use of array::append(std::unique_ptr) and
+   object::set (const char *key, std::unique_ptr v).*/
 
 static void
 test_formatting ()
 {
   object obj;
   object *child = new object;
-  object *grandchild = new object;
+  std::unique_ptr grandchild = ::make_unique ();
 
   obj.set_str

[gcc r15-2285] diagnostics: SARIF output: use std::unique_ptr throughout

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:ee2dad94acc88c2ea78a91b7eb8914e7c1bae829

commit r15-2285-gee2dad94acc88c2ea78a91b7eb8914e7c1bae829
Author: David Malcolm 
Date:   Wed Jul 24 18:07:53 2024 -0400

diagnostics: SARIF output: use std::unique_ptr throughout

No functional change intended.

gcc/analyzer/ChangeLog:
* checker-event.cc (maybe_add_sarif_properties): Update setting
of "original_fndecl" to use typesafe unique_ptr variant of
json::object::set.

gcc/ChangeLog:
* diagnostic-format-sarif.cc: Include "make-unique.h".  Convert
raw pointers to std::unique_ptr throughout to indicate ownership,
adding comments in the few places where pointers are borrowed.
Use typesafe unique_ptr variants of json::object::set and
json::array::append throughout to make types of properties more
explicit, whilst using "auto" to reduce typing.
Use "nullptr" rather than "NULL" throughout.
* diagnostic-format-sarif.h (make_sarif_logical_location_object):
Use std::unique_ptr for return type.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/analyzer/checker-event.cc  |   5 +-
 gcc/diagnostic-format-sarif.cc | 667 -
 gcc/diagnostic-format-sarif.h  |   2 +-
 3 files changed, 337 insertions(+), 337 deletions(-)

diff --git a/gcc/analyzer/checker-event.cc b/gcc/analyzer/checker-event.cc
index 593f364e1d66..2f1438c983a5 100644
--- a/gcc/analyzer/checker-event.cc
+++ b/gcc/analyzer/checker-event.cc
@@ -161,8 +161,9 @@ maybe_add_sarif_properties (sarif_object 
&thread_flow_loc_obj) const
   if (m_original_fndecl != m_effective_fndecl)
 {
   tree_logical_location logical_loc (m_original_fndecl);
-  props.set (PROPERTY_PREFIX "original_fndecl",
-make_sarif_logical_location_object (logical_loc));
+  props.set
+   (PROPERTY_PREFIX "original_fndecl",
+make_sarif_logical_location_object (logical_loc));
 }
   if (m_original_depth != m_effective_depth)
 props.set_integer (PROPERTY_PREFIX "original_depth", m_original_depth);
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 6aba81c6ac9b..6f61d89363f2 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic-format-sarif.h"
 #include "ordered-hash-map.h"
 #include "sbitmap.h"
+#include "make-unique.h"
 
 /* Forward decls.  */
 class sarif_builder;
@@ -125,7 +126,7 @@ public:
   void prepare_to_flush (diagnostic_context &context);
 
 private:
-  json::array *m_notifications_arr;
+  std::unique_ptr m_notifications_arr;
   bool m_success;
 };
 
@@ -180,7 +181,7 @@ private:
 class sarif_result : public sarif_object
 {
 public:
-  sarif_result () : m_related_locations_arr (NULL) {}
+  sarif_result () : m_related_locations_arr (nullptr) {}
 
   void
   on_nested_diagnostic (diagnostic_context &context,
@@ -193,9 +194,9 @@ public:
 
 private:
   void
-  add_related_location (sarif_location *location_obj);
+  add_related_location (std::unique_ptr location_obj);
 
-  json::array *m_related_locations_arr;
+  json::array *m_related_locations_arr; // borrowed
 };
 
 /* Subclass of sarif_object for SARIF "location" objects
@@ -226,10 +227,12 @@ class sarif_thread_flow : public sarif_object
 public:
   sarif_thread_flow (const diagnostic_thread &thread);
 
-  void add_location (sarif_thread_flow_location *thread_flow_loc_obj);
+  void
+  add_location
+(std::unique_ptr thread_flow_loc_obj);
 
 private:
-  json::array *m_locations_arr;
+  json::array *m_locations_arr; // borrowed
 };
 
 /* Subclass of sarif_object for SARIF "threadFlowLocation" objects
@@ -340,80 +343,81 @@ public:
 
   void flush_to_file (FILE *outf);
 
-  json::array *make_locations_arr (const diagnostic_info &diagnostic,
-  enum diagnostic_artifact_role role);
-  sarif_location *
+  std::unique_ptr
+  make_locations_arr (const diagnostic_info &diagnostic,
+ enum diagnostic_artifact_role role);
+  std::unique_ptr
   make_location_object (const rich_location &rich_loc,
const logical_location *logical_loc,
enum diagnostic_artifact_role role);
-  sarif_message *
+  std::unique_ptr
   make_message_object (const char *msg) const;
-  sarif_message *
+  std::unique_ptr
   make_message_object_for_diagram (diagnostic_context &context,
   const diagnostic_diagram &diagram);
-  sarif_artifact_content *
+  std::unique_ptr
   maybe_make_artifact_content_object (const char *filename) const;
 
 private:
-  sarif_result *
+  std::unique_ptr
   make_result_object (diagnostic_context &context,
  const diagnostic_info &diagnostic,
  diagnostic_t orig_diag_kind);
   void
-  set_any_logical_locs_a

[gcc r15-2286] diagnostics: JSON output: use std::unique_ptr throughout

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:ae4f4f767efc156aac4b2e7a874648fdc60307f3

commit r15-2286-gae4f4f767efc156aac4b2e7a874648fdc60307f3
Author: David Malcolm 
Date:   Wed Jul 24 18:07:54 2024 -0400

diagnostics: JSON output: use std::unique_ptr throughout

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-json.cc: Include "make-unique.h".
(json_output_format::m_toplevel_array): Convert to
std::unique_ptr.
(json_output_format::json_output_format): Update accordingly.
(json_output_format::~json_output_format): Remove manual
"delete" of field.
(json_from_expanded_location): Convert return type to
std::unique_ptr.
(json_from_location_range): Likewise.  Use nullptr rather than
NULL.
(json_from_fixit_hint): Convert return type to std::unique_ptr.
(json_from_metadata): Likewise.
(make_json_for_path): Likewise.
(json_output_format::on_end_diagnostic): Use std::unique_ptr
throughout.
(json_file_output_format::~json_file_output_format): Use nullptr.
(selftest::test_unknown_location): Update to use std::unique_ptr.
(selftest::test_bad_endpoints): Likewise.  Replace NULL with
nullptr.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-json.cc | 122 +-
 1 file changed, 62 insertions(+), 60 deletions(-)

diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 55ba39e0c532..b78cb92cfd7a 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "json.h"
 #include "selftest.h"
 #include "logical-location.h"
+#include "make-unique.h"
 
 /* Subclass of diagnostic_output_format for JSON output.  */
 
@@ -62,7 +63,7 @@ protected:
   json_output_format (diagnostic_context &context,
  bool formatted)
   : diagnostic_output_format (context),
-m_toplevel_array (new json::array ()),
+m_toplevel_array (::make_unique ()),
 m_cur_group (nullptr),
 m_cur_children_array (nullptr),
 m_formatted (formatted)
@@ -75,31 +76,30 @@ protected:
   {
 m_toplevel_array->dump (outf, m_formatted);
 fprintf (outf, "\n");
-delete m_toplevel_array;
 m_toplevel_array = nullptr;
   }
 
 private:
   /* The top-level JSON array of pending diagnostics.  */
-  json::array *m_toplevel_array;
+  std::unique_ptr m_toplevel_array;
 
   /* The JSON object for the current diagnostic group.  */
-  json::object *m_cur_group;
+  json::object *m_cur_group; // borrowed
 
   /* The JSON array for the "children" array within the current diagnostic
  group.  */
-  json::array *m_cur_children_array;
+  json::array *m_cur_children_array; // borrowed
 
   bool m_formatted;
 };
 
 /* Generate a JSON object for LOC.  */
 
-static json::value *
+static std::unique_ptr
 json_from_expanded_location (diagnostic_context &context, location_t loc)
 {
   expanded_location exploc = expand_location (loc);
-  json::object *result = new json::object ();
+  std::unique_ptr result = ::make_unique  ();
   if (exploc.file)
 result->set_string ("file", exploc.file);
   result->set_integer ("line", exploc.line);
@@ -130,26 +130,29 @@ json_from_expanded_location (diagnostic_context &context, 
location_t loc)
 
 /* Generate a JSON object for LOC_RANGE.  */
 
-static json::object *
+static std::unique_ptr
 json_from_location_range (diagnostic_context &context,
  const location_range *loc_range, unsigned range_idx)
 {
   location_t caret_loc = get_pure_location (loc_range->m_loc);
 
   if (caret_loc == UNKNOWN_LOCATION)
-return NULL;
+return nullptr;
 
   location_t start_loc = get_start (loc_range->m_loc);
   location_t finish_loc = get_finish (loc_range->m_loc);
 
-  json::object *result = new json::object ();
-  result->set ("caret", json_from_expanded_location (context, caret_loc));
+  std::unique_ptr result = ::make_unique  ();
+  result->set ("caret",
+  json_from_expanded_location (context, caret_loc));
   if (start_loc != caret_loc
   && start_loc != UNKNOWN_LOCATION)
-result->set ("start", json_from_expanded_location (context, start_loc));
+result->set ("start",
+json_from_expanded_location (context, start_loc));
   if (finish_loc != caret_loc
   && finish_loc != UNKNOWN_LOCATION)
-result->set ("finish", json_from_expanded_location (context, finish_loc));
+result->set ("finish",
+json_from_expanded_location (context, finish_loc));
 
   if (loc_range->m_label)
 {
@@ -163,15 +166,17 @@ json_from_location_range (diagnostic_context &context,
 
 /* Generate a JSON object for HINT.  */
 
-static json::object *
+static std::unique_ptr
 json_from_fixit_hint (diagnostic_context &context, const fixit_hint

[gcc r15-2287] diagnostics: SARIF output: potentially add escaped renderings of source (§3.3.4)

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:148066bd0560b5136692991dacba15c9f21caf96

commit r15-2287-g148066bd0560b5136692991dacba15c9f21caf96
Author: David Malcolm 
Date:   Wed Jul 24 18:07:54 2024 -0400

diagnostics: SARIF output: potentially add escaped renderings of source 
(§3.3.4)

This patch adds support to our SARIF output for cases where
rich_loc.escape_on_output_p () is true, such as for -Wbidi-chars.

In such cases, the pertinent SARIF "location" object gains a property
bag with property "gcc/escapeNonAscii": true, and the "artifactContent"
within the location's physical location's snippet" gains a "rendered"
property (§3.3.4) that escapes non-ASCII text in the snippet, such as:

"rendered": {"text":

where "text" has a string value such as (for a "trojan source" attack):

  "9 | /* } if (isAdmin)  begin admins 
only */\n"
  "  |      
 ^\n"
  "  |   |   |  
 |\n"
  "  |   |   |  
 end of bidirectional context\n"
  "  |   U+202E (RIGHT-TO-LEFT OVERRIDE) U+2066 (LEFT-TO-RIGHT 
ISOLATE)\n"

where the escaping is affected by -fdiagnostics-escape-format=; with
-fdiagnostics-escape-format=bytes, the rendered text of the above is:

  "9 | /*<80> } <81>if (isAdmin)<81> 
<81> begin admins only */\n"
  "  |   
^\n"
  "  |   |   |  
 |\n"
  "  |   U+202E (RIGHT-TO-LEFT OVERRIDE) U+2066 
(LEFT-TO-RIGHT ISOLATE)  end of bidirectional context\n"

The patch also refactors/adds enough selftest machinery to be able to
test the snippet generation from within the selftest framework, rather
than just within DejaGnu (where the regex-based testing isn't
sophisticated enough to verify such properties as the above).

gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add selftest-json.o.
* diagnostic-format-sarif.cc: Include "selftest.h",
"selftest-diagnostic.h", "selftest-diagnostic-show-locus.h",
"selftest-json.h", and "text-range-label.h".
(class content_renderer): New.
(sarif_builder::m_rules_arr): Convert to std::unique_ptr.
(sarif_builder::make_location_object): Add class
escape_nonascii_renderer.  If rich_loc.escape_on_output_p (),
pass a nonnull escape_nonascii_renderer to
maybe_make_physical_location_object as its snippet_renderer, and
add a property bag property "gcc/escapeNonAscii" to the SARIF
location object.  For other overloads of make_location_object,
pass nullptr for the snippet_renderer.
(sarif_builder::maybe_make_region_object_for_context): Add
"snippet_renderer" param and pass it to
maybe_make_artifact_content_object.
(sarif_builder::make_tool_object): Drop "const".
(sarif_builder::make_driver_tool_component_object): Likewise.
Use typesafe unique_ptr variant of object::set for setting "rules"
property on driver_obj.
(sarif_builder::maybe_make_artifact_content_object): Add param "r"
and use it to potentially set the "rendered" property (§3.3.4).
(selftest::test_make_location_object): New.
(selftest::diagnostic_format_sarif_cc_tests): New.
* diagnostic-show-locus.cc: Include "text-range-label.h" and
"selftest-diagnostic-show-locus.h".

(selftests::diagnostic_show_locus_fixture::diagnostic_show_locus_fixture):
New.
(selftests::test_layout_x_offset_display_utf8): Use
diagnostic_show_locus_fixture to simplify and consolidate setup
code.
(selftests::test_diagnostic_show_locus_one_liner): Likewise.
(selftests::test_one_liner_colorized_utf8): Likewise.
(selftests::test_diagnostic_show_locus_one_liner_utf8): Likewise.
* gcc-rich-location.h (class text_range_label): Move to new file
text-range-label.h.
* selftest-diagnostic-show-locus.h: New file, based on material in
diagnostic-show-locus.cc.
* selftest-json.cc: New file.
* selftest-json.h: New file.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::diagnostic_format_sarif_cc_tests.
* selftest.h (selftest::diagnostic_format_sarif_cc_tests): New decl.

gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-sarif-file-Wbidi-chars.c: Verify
that we have a property bag with property "gcc/escapeNonAsc

[gcc r15-2288] diagnostics: SARIF output: add "workingDirectory" property (§3.20.19)

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:8c07814f46ca617ccc5f9fbf2b220dc41ae228c2

commit r15-2288-g8c07814f46ca617ccc5f9fbf2b220dc41ae228c2
Author: David Malcolm 
Date:   Wed Jul 24 18:07:55 2024 -0400

diagnostics: SARIF output: add "workingDirectory" property (§3.20.19)

gcc/ChangeLog:
* diagnostic-format-sarif.cc
(sarif_builder::make_artifact_location_object): Make public.
(sarif_invocation::sarif_invocation): Add param "builder".
Use it to potentially populate the "workingDirectory" property
with the result of pwd (§3.20.19).
(sarif_builder::sarif_builder): Pass *this to m_invocation_obj's
ctor.

gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-sarif-file-1.c: Verify that we have
a "workingDirectory" property.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc| 15 ++-
 .../c-c++-common/diagnostic-format-sarif-file-1.c |  1 +
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 847e1eb9bdfc..9be84fb268a5 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -125,7 +125,7 @@ class sarif_tool_component : public sarif_object {};
 class sarif_invocation : public sarif_object
 {
 public:
-  sarif_invocation ();
+  sarif_invocation (sarif_builder &builder);
 
   void add_notification_for_ice (diagnostic_context &context,
 const diagnostic_info &diagnostic,
@@ -378,6 +378,9 @@ public:
   std::unique_ptr
   maybe_make_artifact_content_object (const char *filename) const;
 
+  std::unique_ptr
+  make_artifact_location_object (const char *filename);
+
 private:
   std::unique_ptr
   make_result_object (diagnostic_context &context,
@@ -404,8 +407,6 @@ private:
   std::unique_ptr
   make_artifact_location_object (location_t loc);
   std::unique_ptr
-  make_artifact_location_object (const char *filename);
-  std::unique_ptr
   make_artifact_location_object_for_pwd () const;
   std::unique_ptr
   maybe_make_region_object (location_t loc,
@@ -512,10 +513,14 @@ sarif_object::get_or_create_properties ()
 
 /* class sarif_invocation : public sarif_object.  */
 
-sarif_invocation::sarif_invocation ()
+sarif_invocation::sarif_invocation (sarif_builder &builder)
 : m_notifications_arr (::make_unique ()),
   m_success (true)
 {
+  // "workingDirectory" property (SARIF v2.1.0 section 3.20.19)
+  if (const char *pwd = getpwd ())
+set ("workingDirectory",
+ builder.make_artifact_location_object (pwd));
 }
 
 /* Handle an internal compiler error DIAGNOSTIC occurring on CONTEXT.
@@ -747,7 +752,7 @@ sarif_builder::sarif_builder (diagnostic_context &context,
  const char *main_input_filename_,
  bool formatted)
 : m_context (context),
-  m_invocation_obj (::make_unique ()),
+  m_invocation_obj (::make_unique (*this)),
   m_results_array (new json::array ()),
   m_cur_group_result (nullptr),
   m_seen_any_relative_paths (false),
diff --git a/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c 
b/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c
index 50375465483d..0a3778323792 100644
--- a/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c
+++ b/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c
@@ -32,6 +32,7 @@
  { dg-final { scan-sarif-file "\"informationUri\": \"" } }
 
  { dg-final { scan-sarif-file "\"invocations\": \\\[" } }
+   { dg-final { scan-sarif-file {"workingDirectory": } } }
{ dg-final { scan-sarif-file "\"toolExecutionNotifications\": \\\[\\\]" 
} }
{ dg-final { scan-sarif-file "\"executionSuccessful\": true" } }


[gcc r15-2289] diagnostics: SARIF output: add "arguments" property (§3.20.2)

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:29ee588129bf07d3adb62b6c2c189ba932c00ff4

commit r15-2289-g29ee588129bf07d3adb62b6c2c189ba932c00ff4
Author: David Malcolm 
Date:   Wed Jul 24 18:07:55 2024 -0400

diagnostics: SARIF output: add "arguments" property (§3.20.2)

gcc/ChangeLog:
* diagnostic-format-sarif.cc (sarif_invocation::sarif_invocation):
Add "original_argv" param and use it to populate "arguments"
property (§3.20.2).
(sarif_builder::sarif_builder): Pass argv to m_invocation_obj's
ctor.
* diagnostic.cc (diagnostic_context::initialize): Initialize
m_original_argv.
(diagnostic_context::finish): Clean up m_original_argv.
(diagnostic_context::set_original_argv): New.
* diagnostic.h: Include "unique-argv.h".
(diagnostic_context::set_original_argv): New decl.
(diagnostic_context::get_original_argv): New decl.
(diagnostic_context::m_original_argv): New field.
* toplev.cc: Include "unique-argv.h".
(general_init): Add "original_argv" param and move it to global_dc.
(toplev::main): Stash a copy of the original argv before expansion,
and pass it to general_init for use by SARIF output.
* unique-argv.h: New file.

gcc/jit/ChangeLog:
* jit-playback.cc (jit::playback_context::compile) Add a trailing
null to argvec.

gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-sarif-file-1.c: Verify that we
have an "arguments" property (§3.20.2).

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc | 25 +---
 gcc/diagnostic.cc  | 17 ++
 gcc/diagnostic.h   | 10 
 gcc/jit/jit-playback.cc|  6 +-
 .../c-c++-common/diagnostic-format-sarif-file-1.c  |  5 ++
 gcc/toplev.cc  | 13 -
 gcc/unique-argv.h  | 67 ++
 7 files changed, 132 insertions(+), 11 deletions(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 9be84fb268a5..6c7216651627 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -125,7 +125,8 @@ class sarif_tool_component : public sarif_object {};
 class sarif_invocation : public sarif_object
 {
 public:
-  sarif_invocation (sarif_builder &builder);
+  sarif_invocation (sarif_builder &builder,
+   const char * const *original_argv);
 
   void add_notification_for_ice (diagnostic_context &context,
 const diagnostic_info &diagnostic,
@@ -329,10 +330,8 @@ public:
- GCC supports one-deep nesting of diagnostics (via auto_diagnostic_group),
  but we only capture location and message information from such nested
  diagnostics (e.g. we ignore fix-it hints on them)
-   - doesn't yet capture command-line arguments: would be run.invocations
- property (SARIF v2.1.0 section 3.14.11), as invocation objects
- (SARIF v2.1.0 section 3.20), but we'd want to capture the arguments to
- toplev::main, and the response files.
+   - although we capture command-line arguments (section 3.20.2), we don't
+ yet capture response files.
- doesn't capture secondary locations within a rich_location
  (perhaps we should use the "relatedLocations" property: SARIF v2.1.0
  section 3.27.22)
@@ -513,10 +512,20 @@ sarif_object::get_or_create_properties ()
 
 /* class sarif_invocation : public sarif_object.  */
 
-sarif_invocation::sarif_invocation (sarif_builder &builder)
+sarif_invocation::sarif_invocation (sarif_builder &builder,
+   const char * const *original_argv)
 : m_notifications_arr (::make_unique ()),
   m_success (true)
 {
+  // "arguments" property (SARIF v2.1.0 section 3.20.2)
+  if (original_argv)
+{
+  auto arguments_arr = ::make_unique ();
+  for (size_t i = 0; original_argv[i]; ++i)
+   arguments_arr->append_string (original_argv[i]);
+  set ("arguments", std::move (arguments_arr));
+}
+
   // "workingDirectory" property (SARIF v2.1.0 section 3.20.19)
   if (const char *pwd = getpwd ())
 set ("workingDirectory",
@@ -752,7 +761,9 @@ sarif_builder::sarif_builder (diagnostic_context &context,
  const char *main_input_filename_,
  bool formatted)
 : m_context (context),
-  m_invocation_obj (::make_unique (*this)),
+  m_invocation_obj
+(::make_unique (*this,
+ context.get_original_argv ())),
   m_results_array (new json::array ()),
   m_cur_group_result (nullptr),
   m_seen_any_relative_paths (false),
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index aa8afd521fa2..c70c394f7ccd 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/di

[gcc r15-2290] diagnostics: SARIF output: add "{start,end}TimeUtc" properties (§§3.20.7-8)

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:b4693ce3a0565bb75d0d5698f2ce2ffc53d1ff84

commit r15-2290-gb4693ce3a0565bb75d0d5698f2ce2ffc53d1ff84
Author: David Malcolm 
Date:   Wed Jul 24 18:07:55 2024 -0400

diagnostics: SARIF output: add "{start,end}TimeUtc" properties (§§3.20.7-8)

gcc/ChangeLog:
* diagnostic-format-sarif.cc
(make_date_time_string_for_current_time): New.
(sarif_invocation::sarif_invocation): Set "startTimeUtc"
property (§3.20.7).
(sarif_invocation::prepare_to_flush): Set "endTimeUtc"
property (§3.20.8).

gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-sarif-file-1.c: Verify that we have
"startTimeUtc" and "endTimeUtc" properties of the correct form.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc | 28 ++
 .../c-c++-common/diagnostic-format-sarif-file-1.c  |  5 
 2 files changed, 33 insertions(+)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 6c7216651627..775d01f75744 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -119,6 +119,26 @@ class sarif_tool : public sarif_object {};
 
 class sarif_tool_component : public sarif_object {};
 
+/* Make a JSON string for the current date and time.
+   See SARIF v2.1.0 section 3.9 "Date/time properties".
+   Given that we don't run at the very beginning/end of the
+   process, it doesn't make sense to be more accurate than
+   the current second.  */
+
+static std::unique_ptr
+make_date_time_string_for_current_time ()
+{
+  time_t t = time (nullptr);
+  struct tm *tm = gmtime (&t);
+  char buf[256];
+  snprintf (buf, sizeof (buf) - 1,
+   ("%04i-%02i-%02iT"
+"%02i:%02i:%02iZ"),
+   tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+   tm->tm_hour, tm->tm_min, tm->tm_sec);
+  return ::make_unique (buf);
+}
+
 /* Subclass of sarif_object for SARIF "invocation" objects
(SARIF v2.1.0 section 3.20).  */
 
@@ -530,6 +550,10 @@ sarif_invocation::sarif_invocation (sarif_builder &builder,
   if (const char *pwd = getpwd ())
 set ("workingDirectory",
  builder.make_artifact_location_object (pwd));
+
+  // "startTimeUtc" property (SARIF v2.1.0 section 3.20.7)
+  set ("startTimeUtc",
+make_date_time_string_for_current_time ());
 }
 
 /* Handle an internal compiler error DIAGNOSTIC occurring on CONTEXT.
@@ -559,6 +583,10 @@ sarif_invocation::prepare_to_flush (diagnostic_context 
&context)
  this object (SARIF v2.1.0 section 3.8) e.g. for recording time vars.  */
   if (auto client_data_hooks = context.get_client_data_hooks ())
 client_data_hooks->add_sarif_invocation_properties (*this);
+
+  // "endTimeUtc" property (SARIF v2.1.0 section 3.20.8);
+  set ("endTimeUtc",
+make_date_time_string_for_current_time ());
 }
 
 /* class sarif_artifact : public sarif_object.  */
diff --git a/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c 
b/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c
index c9ad0d238195..fdf602eaae7b 100644
--- a/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c
+++ b/gcc/testsuite/c-c++-common/diagnostic-format-sarif-file-1.c
@@ -37,6 +37,11 @@
3.20.2 invocation "arguments" property:
{ dg-final { scan-sarif-file {"arguments": \[} } }
 
+   Expect "startTimeUtc" and "endTimeUtc" properties of the form
+   "-nn-nnTnn:nn:nnZ" (3.20.7 and 3.20.8):
+   { dg-final { scan-sarif-file {"startTimeUtc": 
"[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z"} 
} }
+   { dg-final { scan-sarif-file {"endTimeUtc": 
"[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z"} 
} }
+
{ dg-final { scan-sarif-file {"workingDirectory": } } }
{ dg-final { scan-sarif-file "\"toolExecutionNotifications\": \\\[\\\]" 
} }
{ dg-final { scan-sarif-file "\"executionSuccessful\": true" } }


[gcc r15-2291] diagnostics: SARIF output: add "annotations" property (§3.28.6)

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:d7a688fc960f78c62aacdc5acb8432873fed300e

commit r15-2291-gd7a688fc960f78c62aacdc5acb8432873fed300e
Author: David Malcolm 
Date:   Wed Jul 24 18:07:56 2024 -0400

diagnostics: SARIF output: add "annotations" property (§3.28.6)

This patch extends our SARIF output so that if a diagnostic has any
labelled source ranges, the "location" object gains an "annotations"
property capturing them (§3.28.6).

For example, given this textual output:

../../src/gcc/testsuite/gcc.dg/bad-binary-ops.c: In function ‘test_2’:
../../src/gcc/testsuite/gcc.dg/bad-binary-ops.c:31:11: error: invalid 
operands to binary + (have ‘struct s’ and ‘struct t’)
   30 |   return (some_function ()
  |   
  |   |
  |   struct s
   31 |   + some_other_function ());
  |   ^ ~~
  | |
  | struct t

the SARIF output gains this within the result's location[0]:

   "annotations": [{"startLine": 30,
"startColumn": 11,
"endColumn": 27,
"message": {"text": "struct s"}},
   {"startLine": 31,
"startColumn": 13,
"endColumn": 35,
"message": {"text": "struct t"}}]}]},

gcc/ChangeLog:
* diagnostic-format-sarif.cc
(sarif_builder::make_location_object): Add "annotations" property if
there are any labelled ranges (§3.28.6).
(selftest::test_make_location_object): Verify annotations are added
to location_obj.
* json.h (json::array::size): New.
(json::array::operator[]): New.
* selftest-json.cc
(selftest::expect_json_object_with_array_property): New.
* selftest-json.h
(selftest::expect_json_object_with_array_property): New decl.
(EXPECT_JSON_OBJECT_WITH_ARRAY_PROPERTY): New macro.

gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-sarif-file-Wbidi-chars.c: Verify
that we have an "annotations" property for the labelled
ranges (§3.28.6).

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc | 70 +-
 gcc/json.h |  3 +
 gcc/selftest-json.cc   | 16 +
 gcc/selftest-json.h| 14 +
 .../diagnostic-format-sarif-file-Wbidi-chars.c |  8 +++
 5 files changed, 110 insertions(+), 1 deletion(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 775d01f75744..afb29eab5839 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -345,6 +345,7 @@ public:
- CWE metadata
- diagnostic groups (see limitations below)
- logical locations (e.g. cfun)
+   - labelled ranges (as annotations)
 
Known limitations:
- GCC supports one-deep nesting of diagnostics (via auto_diagnostic_group),
@@ -361,7 +362,6 @@ public:
  ("artifact.hashes" property (SARIF v2.1.0 section 3.24.11).
- doesn't capture the "analysisTarget" property
  (SARIF v2.1.0 section 3.27.13).
-   - doesn't capture labelled ranges
- doesn't capture -Werror cleanly
- doesn't capture inlining information (can SARIF handle this?)
- doesn't capture macro expansion information (can SARIF handle this?).  */
@@ -1210,6 +1210,38 @@ sarif_builder::make_location_object (const rich_location 
&rich_loc,
   /* "logicalLocations" property (SARIF v2.1.0 section 3.28.4).  */
   set_any_logical_locs_arr (*location_obj, logical_loc);
 
+  /* "annotations" property (SARIF v2.1.0 section 3.28.6).  */
+  {
+/* Create annotations for any labelled ranges.  */
+std::unique_ptr annotations_arr = nullptr;
+for (unsigned int i = 0; i < rich_loc.get_num_locations (); i++)
+  {
+   const location_range *range = rich_loc.get_range (i);
+   if (const range_label *label = range->m_label)
+ {
+   label_text text = label->get_text (i);
+   if (text.get ())
+ {
+   location_t range_loc = rich_loc.get_loc (i);
+   auto region
+ = maybe_make_region_object (range_loc,
+ rich_loc.get_column_override ());
+   if (region)
+ {
+   if (!annotations_arr)
+ annotations_arr = ::make_unique ();
+   region->set
+ ("message", make_message_object (text.get ()));
+   annotations_arr->append (std::move (region));
+ }
+ }
+ }
+  }
+if (annotations_arr)
+  location_obj->set ("annotations",
+ 

[gcc r15-2292] diagnostics: add selftests for SARIF output

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:68c7747dd29016d51e6f04e7fe1d8543423f093f

commit r15-2292-g68c7747dd29016d51e6f04e7fe1d8543423f093f
Author: David Malcolm 
Date:   Wed Jul 24 18:07:56 2024 -0400

diagnostics: add selftests for SARIF output

The existing DejaGnu-based tests for our SARIF output used regexes
to verify the JSON at the string level, which lets us test for
the presence of properties, but doesn't check the overall structure.

This patch uses the selftest framework to verify the structure of
the tree of JSON values for a log containing one diagnostic.

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-sarif.cc (sarif_builder::flush_to_object):
New, using code moved from...
(sarif_builder::end_group): ...here.
(class selftest::test_sarif_diagnostic_context): New.
(selftest::test_simple_log): New.
(selftest::diagnostic_format_sarif_cc_tests): Call it.
* json.h (json::object::is_empty): New.
* selftest-diagnostic.cc (test_diagnostic_context::report): New.
* selftest-diagnostic.h (test_diagnostic_context::report): New
decl.
* selftest-json.cc (selftest::assert_json_string_eq): New.
(selftest::expect_json_object_with_string_property): New.
(selftest::assert_json_string_property_eq): New.
* selftest-json.h (selftest::assert_json_string_eq): New decl.
(ASSERT_JSON_STRING_EQ): New macro.
(selftest::expect_json_object_with_string_property): New decl.
(EXPECT_JSON_OBJECT_WITH_STRING_PROPERTY): New macro.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc | 185 +++--
 gcc/json.h |   2 +
 gcc/selftest-diagnostic.cc |  14 
 gcc/selftest-diagnostic.h  |  10 +++
 gcc/selftest-json.cc   |  34 +++-
 gcc/selftest-json.h|  27 ++
 6 files changed, 264 insertions(+), 8 deletions(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index afb29eab5839..816f3210036e 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -380,6 +380,7 @@ public:
 const diagnostic_diagram &diagram);
   void end_group ();
 
+  std::unique_ptr flush_to_object ();
   void flush_to_file (FILE *outf);
 
   std::unique_ptr
@@ -860,6 +861,20 @@ sarif_builder::end_group ()
   m_cur_group_result = nullptr;
 }
 
+/* Create a top-level object, and add it to all the results
+   (and other entities) we've seen so far, moving ownership
+   to the object.  */
+
+std::unique_ptr
+sarif_builder::flush_to_object ()
+{
+  m_invocation_obj->prepare_to_flush (m_context);
+  std::unique_ptr top
+= make_top_level_object (std::move (m_invocation_obj),
+std::move (m_results_array));
+  return top;
+}
+
 /* Create a top-level object, and add it to all the results
(and other entities) we've seen so far.
 
@@ -868,12 +883,8 @@ sarif_builder::end_group ()
 void
 sarif_builder::flush_to_file (FILE *outf)
 {
-  m_invocation_obj->prepare_to_flush (m_context);
-  std::unique_ptr top
-= make_top_level_object (std::move (m_invocation_obj),
-std::move (m_results_array));
+  std::unique_ptr top = flush_to_object ();
   top->dump (outf, m_formatted);
-  m_invocation_obj = nullptr;
   fprintf (outf, "\n");
 }
 
@@ -2434,6 +2445,54 @@ diagnostic_output_format_init_sarif_stream 
(diagnostic_context &context,
 
 namespace selftest {
 
+/* A subclass of sarif_output_format for writing selftests.
+   The JSON output is cached internally, rather than written
+   out to a file.  */
+
+class test_sarif_diagnostic_context : public test_diagnostic_context
+{
+public:
+  test_sarif_diagnostic_context ()
+  {
+diagnostic_output_format_init_sarif (*this);
+
+m_format = new buffered_output_format (*this,
+  "MAIN_INPUT_FILENAME",
+  true);
+set_output_format (m_format); // give ownership;
+  }
+
+  std::unique_ptr flush_to_object ()
+  {
+return m_format->flush_to_object ();
+  }
+
+private:
+  class buffered_output_format : public sarif_output_format
+  {
+  public:
+buffered_output_format (diagnostic_context &context,
+   const char *main_input_filename_,
+   bool formatted)
+  : sarif_output_format (context, main_input_filename_, formatted)
+{
+}
+bool machine_readable_stderr_p () const final override
+{
+  return false;
+}
+std::unique_ptr flush_to_object ()
+{
+  return m_builder.flush_to_object ();
+}
+  };
+
+  buffered_output_format *m_format; // borrowed
+};
+
+/* Test making a sarif_location for a complex rich_location
+   with labels and escape-on-output.  */
+
 static vo

[gcc r15-2293] diagnostics: SARIF output: tweak output for UNKNOWN_LOCATION

2024-07-24 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:142003df61b45ba8fcd17a68909a8ea0782a6679

commit r15-2293-g142003df61b45ba8fcd17a68909a8ea0782a6679
Author: David Malcolm 
Date:   Wed Jul 24 18:07:57 2024 -0400

diagnostics: SARIF output: tweak output for UNKNOWN_LOCATION

gcc/ChangeLog:
* diagnostic-format-sarif.cc (sarif_builder::make_locations_arr):
Don't add entirely empty location objects, such as for
UNKNOWN_LOCATION.
(test_sarif_diagnostic_context::test_sarif_diagnostic_context):
Add param "main_input_filename".
(selftest::test_simple_log): Provide above param.  Verify that
"locations" is empty.
(selftest::test_simple_log_2): New.
(selftest::diagnostic_format_sarif_cc_tests): Call it.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc | 123 ++---
 1 file changed, 115 insertions(+), 8 deletions(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 816f3210036e..1fc45c9b4b39 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -1134,8 +1134,12 @@ sarif_builder::make_locations_arr (const diagnostic_info 
&diagnostic,
   if (auto client_data_hooks = m_context.get_client_data_hooks ())
 logical_loc = client_data_hooks->get_current_logical_location ();
 
-  locations_arr->append
-(make_location_object (*diagnostic.richloc, logical_loc, role));
+  auto location_obj
+= make_location_object (*diagnostic.richloc, logical_loc, role);
+  /* Don't add entirely empty location objects to the array.  */
+  if (!location_obj->is_empty ())
+locations_arr->append (std::move (location_obj));
+
   return locations_arr;
 }
 
@@ -2452,12 +2456,12 @@ namespace selftest {
 class test_sarif_diagnostic_context : public test_diagnostic_context
 {
 public:
-  test_sarif_diagnostic_context ()
+  test_sarif_diagnostic_context (const char *main_input_filename)
   {
 diagnostic_output_format_init_sarif (*this);
 
 m_format = new buffered_output_format (*this,
-  "MAIN_INPUT_FILENAME",
+  main_input_filename,
   true);
 set_output_format (m_format); // give ownership;
   }
@@ -2609,14 +2613,14 @@ test_make_location_object (const line_table_case &case_)
   }
 }
 
-/* Test of reporting a diagnostic to a diagnostic_context and
-   examining the generated sarif_log.
+/* Test of reporting a diagnostic at UNKNOWN_LOCATION to a
+   diagnostic_context and examining the generated sarif_log.
Verify various basic properties. */
 
 static void
 test_simple_log ()
 {
-  test_sarif_diagnostic_context dc;
+  test_sarif_diagnostic_context dc ("MAIN_INPUT_FILENAME");
 
   rich_location richloc (line_table, UNKNOWN_LOCATION);
   dc.report (DK_ERROR, richloc, nullptr, 0, "this is a test: %i", 42);
@@ -2719,7 +2723,109 @@ test_simple_log ()
   }
 
   // 3.27.12:
-  EXPECT_JSON_OBJECT_WITH_ARRAY_PROPERTY (result, "locations");
+  auto locations
+   = EXPECT_JSON_OBJECT_WITH_ARRAY_PROPERTY (result, "locations");
+  ASSERT_EQ (locations->size (), 0);
+}
+  }
+}
+
+/* As above, but with a "real" location_t.  */
+
+static void
+test_simple_log_2 (const line_table_case &case_)
+{
+  auto_fix_quotes fix_quotes;
+
+  const char *const content
+/* 011
+   123456789012345.  */
+= "unsinged int i;\n";
+  diagnostic_show_locus_fixture f (case_, content);
+  location_t line_end = linemap_position_for_column (line_table, 31);
+
+  /* Don't attempt to run the tests if column data might be unavailable.  */
+  if (line_end > LINE_MAP_MAX_LOCATION_WITH_COLS)
+return;
+
+  test_sarif_diagnostic_context dc (f.get_filename ());
+
+  const location_t typo_loc
+= make_location (linemap_position_for_column (line_table, 1),
+linemap_position_for_column (line_table, 1),
+linemap_position_for_column (line_table, 8));
+
+  rich_location richloc (line_table, typo_loc);
+  dc.report (DK_ERROR, richloc, nullptr, 0,
+"did you misspell %qs again?",
+"unsigned");
+
+  auto log_ptr = dc.flush_to_object ();
+
+  // 3.13 sarifLog:
+  auto log = log_ptr.get ();
+
+  auto runs = EXPECT_JSON_OBJECT_WITH_ARRAY_PROPERTY (log, "runs"); // 3.13.4
+  ASSERT_EQ (runs->size (), 1);
+
+  // 3.14 "run" object:
+  auto run = (*runs)[0];
+
+  {
+// 3.14.23:
+auto results = EXPECT_JSON_OBJECT_WITH_ARRAY_PROPERTY (run, "results");
+ASSERT_EQ (results->size (), 1);
+
+{
+  // 3.27 "result" object:
+  auto result = (*results)[0];
+  ASSERT_JSON_STRING_PROPERTY_EQ (result, "ruleId", "error");
+  ASSERT_JSON_STRING_PROPERTY_EQ (result, "level", "error"); // 3.27.10
+
+  {
+   // 3.27.11:
+   auto message
+ = EXPECT_JSON_OBJECT_WITH_OBJECT_PROPERTY (result, "message")

[gcc(refs/users/meissner/heads/work173)] Revert changes

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:11ca5a8c33f06bf3c1b663870a979638b6cde2c3

commit 11ca5a8c33f06bf3c1b663870a979638b6cde2c3
Author: Michael Meissner 
Date:   Wed Jul 24 18:46:33 2024 -0400

Revert changes

Diff:
---
 gcc/config/rs6000/rs6000-c.cc |  23 ++---
 gcc/config/rs6000/rs6000-cpus.def |   8 +-
 gcc/config/rs6000/rs6000-protos.h |   5 +-
 gcc/config/rs6000/rs6000.cc   | 211 --
 gcc/config/rs6000/rs6000.h|  31 --
 gcc/config/rs6000/rs6000.opt  |  19 ++--
 6 files changed, 73 insertions(+), 224 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 2ffaee165885..68519e1397f1 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -338,8 +338,7 @@ rs6000_define_or_undefine_macro (bool define_p, const char 
*name)
#pragma GCC target, we need to adjust the macros dynamically.  */
 
 void
-rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags,
-HOST_WIDE_INT arch_flags)
+rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags)
 {
   if (TARGET_DEBUG_BUILTIN || TARGET_DEBUG_TARGET)
 fprintf (stderr,
@@ -412,7 +411,7 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags,
summary of the flags associated with particular cpu
definitions.  */
 
-  /* rs6000_isa_flags and rs6000_arch_flags based options.  */
+  /* rs6000_isa_flags based options.  */
   rs6000_define_or_undefine_macro (define_p, "_ARCH_PPC");
   if ((flags & OPTION_MASK_PPC_GPOPT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PPCSQ");
@@ -422,21 +421,21 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags,
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PPC64");
   if ((flags & OPTION_MASK_MFCRF) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR4");
-  if ((arch_flags & ARCH_MASK_POWER4) != 0)
+  if ((flags & OPTION_MASK_POPCNTB) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR5");
-  if ((arch_flags & ARCH_MASK_POWER5) != 0)
+  if ((flags & OPTION_MASK_FPRND) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR5X");
-  if ((arch_flags & ARCH_MASK_POWER6) != 0)
+  if ((flags & OPTION_MASK_CMPB) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR6");
-  if ((arch_flags & ARCH_MASK_POWER7) != 0)
+  if ((flags & OPTION_MASK_POPCNTD) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR7");
-  if ((arch_flags & ARCH_MASK_POWER8) != 0)
+  if ((flags & OPTION_MASK_POWER8) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR8");
-  if ((arch_flags & ARCH_MASK_POWER9) != 0)
+  if ((flags & OPTION_MASK_MODULO) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR9");
-  if ((arch_flags & ARCH_MASK_POWER10) != 0)
+  if ((flags & OPTION_MASK_POWER10) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR10");
-  if ((arch_flags & ARCH_MASK_POWER11) != 0)
+  if ((flags & OPTION_MASK_POWER11) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR11");
   if ((flags & OPTION_MASK_SOFT_FLOAT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_SOFT_FLOAT");
@@ -606,7 +605,7 @@ void
 rs6000_cpu_cpp_builtins (cpp_reader *pfile)
 {
   /* Define all of the common macros.  */
-  rs6000_target_modify_macros (true, rs6000_isa_flags, rs6000_arch_flags);
+  rs6000_target_modify_macros (true, rs6000_isa_flags);
 
   if (TARGET_FRE)
 builtin_define ("__RECIP__");
diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index a3568898b0b6..84fac8bdac1d 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -47,6 +47,7 @@
fusion here, instead set it in rs6000.cc if we are tuning for a power8
system.  */
 #define ISA_2_7_MASKS_SERVER   (ISA_2_6_MASKS_SERVER   \
+| OPTION_MASK_POWER8   \
 | OPTION_MASK_P8_VECTOR\
 | OPTION_MASK_CRYPTO   \
 | OPTION_MASK_EFFICIENT_UNALIGNED_VSX  \
@@ -82,9 +83,11 @@
 | OPTION_MASK_PREFIXED)
 
 #define ISA_3_1_MASKS_SERVER   (ISA_3_0_MASKS_SERVER   \
+| OPTION_MASK_POWER10  \
 | OTHER_POWER10_MASKS)
 
-#define POWER11_MASKS_SERVER   ISA_3_1_MASKS_SERVER
+#define POWER11_MASKS_SERVER (ISA_3_1_MASKS_SERVER \
+ | OPTION_MASK_POWER11)
 
 /* Flags that need to be turned off if -mno-vsx.  */
 #define OTHER_VSX_VECTOR_MASKS (OPTION_MASK_EFFICIENT_UNALIGNED_VSX\
@@ -122,6 +125,8 @@
 | OPTION_MASK_FLOAT128_HW  \
 | OPTION_MASK_FLOAT128_KEYWORD \
 | OPTION_

[gcc(refs/users/meissner/heads/work173)] Separate architecture flags from ISA flags

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:db3b4de65c0e0f05fa78723d978de35519efb482

commit db3b4de65c0e0f05fa78723d978de35519efb482
Author: Michael Meissner 
Date:   Wed Jul 24 19:16:06 2024 -0400

Separate architecture flags from ISA flags

2024-07-24  Michael Meissner  

gcc/

* config/rs6000/rs6000-cpus.def (ARCH_MASK_POWER*): New macros.
* config/rs6000/rs6000.cc (rs6000_print_isa_options): Print out the
architure bits.
(get_arch_flags): New function.
(rs6000_debug_reg_global): Add support for separating architecture 
flags
the ISA flags.
(rs6000_option_override_internal): Likewise.
(struct rs6000_arch_mask): Likewise.
(rs6000_arch_masks): Likewise.
(rs6000_function_specific_save): Likewise.
(rs6000_function_specific_restore): Likewise.
(rs6000_function_specific_print): Likewise.
(rs6000_print_options_internal): Likewise.
(rs6000_can_inline_p): Likewise.
* config/rs6000/rs6000.opt (rs6000_arch_flags): New target variable.
(x_rs6000_arch_flags): New save area for rs6000_arch_flags.

Diff:
---
 gcc/config/rs6000/rs6000-cpus.def |  15 
 gcc/config/rs6000/rs6000.cc   | 153 +-
 gcc/config/rs6000/rs6000.h|   1 -
 gcc/config/rs6000/rs6000.opt  |   8 ++
 4 files changed, 159 insertions(+), 18 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index 84fac8bdac1d..9c982df89dae 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -158,6 +158,21 @@
 
 #endif
 
+/* List of architecture masks (to set the _ARCH_PWR flag that don't have a
+   separate -m option.  It the past, we would have -mpower11, -mpower10,
+   -mpower9, etc. but bad things would happen if the user did -mpower10 instead
+   of -mcpu=power10.  Over time, older options will be removed as -m
+   and moved into this list.  */
+
+#define ARCH_MASK_POWER4   (HOST_WIDE_INT_1 << 1)
+#define ARCH_MASK_POWER5   (HOST_WIDE_INT_1 << 2)
+#define ARCH_MASK_POWER6   (HOST_WIDE_INT_1 << 3)
+#define ARCH_MASK_POWER7   (HOST_WIDE_INT_1 << 4)
+#define ARCH_MASK_POWER8   (HOST_WIDE_INT_1 << 5)
+#define ARCH_MASK_POWER9   (HOST_WIDE_INT_1 << 6)
+#define ARCH_MASK_POWER10  (HOST_WIDE_INT_1 << 7)
+#define ARCH_MASK_POWER11  (HOST_WIDE_INT_1 << 8)
+
 /* This table occasionally claims that a processor does not support a
particular feature even though it does, but the feature is slower than the
alternative.  Thus, it shouldn't be relied on as a complete description of
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index eddd2adbab59..6ceea856c0e4 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1170,7 +1170,7 @@ enum reg_class (*rs6000_preferred_reload_class_ptr) (rtx, 
enum reg_class)
 const int INSN_NOT_AVAILABLE = -1;
 
 static void rs6000_print_isa_options (FILE *, int, const char *,
- HOST_WIDE_INT);
+ HOST_WIDE_INT, HOST_WIDE_INT);
 static HOST_WIDE_INT rs6000_disable_incompatible_switches (void);
 
 static enum rs6000_reg_type register_to_reg_type (rtx, bool *);
@@ -1817,6 +1817,57 @@ rs6000_cpu_name_lookup (const char *name)
   return -1;
 }
 
+
+/* Map the processor into the arch bits that are set off of -mcpu= instead
+   of having an internal -m option.  */
+
+static HOST_WIDE_INT
+get_arch_flags (int cpu_index)
+{
+  HOST_WIDE_INT ret = 0;
+
+  if (cpu_index >= 0)
+switch (processor_target_table[cpu_index].processor)
+  {
+  case PROCESSOR_POWER11:
+   ret |= ARCH_MASK_POWER11;
+   /* fall through.  */
+
+  case PROCESSOR_POWER10:
+   ret |= ARCH_MASK_POWER10;
+   /* fall through.  */
+
+  case PROCESSOR_POWER9:
+   ret |= ARCH_MASK_POWER9;
+   /* fall through.  */
+
+  case PROCESSOR_POWER8:
+   ret |= ARCH_MASK_POWER8;
+   /* fall through.  */
+
+  case PROCESSOR_POWER7:
+   ret |= ARCH_MASK_POWER7;
+   /* fall through.  */
+
+  case PROCESSOR_POWER6:
+   ret |= ARCH_MASK_POWER6;
+   /* fall through.  */
+
+  case PROCESSOR_POWER5:
+   ret |= ARCH_MASK_POWER5;
+   /* fall through.  */
+
+  case PROCESSOR_POWER4:
+   ret |= ARCH_MASK_POWER4;
+   break;
+
+  default:
+   break;
+  }
+
+  return ret;
+}
+
 
 /* Return number of consecutive hard regs needed starting at reg REGNO
to hold something of mode MODE.
@@ -2398,9 +2449,10 @@ rs6000_debug_reg_global (void)
   const char *name = processor_target_table[rs6000_cpu_index].name;
   HOST_WIDE_INT flags
= processor_target_table[rs6000_cpu_index].target_enable;
+  HOST_WIDE_INT arch_flags = get_arch_flags (rs6000_cpu_index);
 
   sprintf (flags_buffer, "-mcpu=%s flags", name);
-

[gcc(refs/users/meissner/heads/work173)] Use architecture flags for defining _ARCH_PWR macros.

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:dc0cb0ad7c3f9388eadccdd9bc1cd0f1d11b2fae

commit dc0cb0ad7c3f9388eadccdd9bc1cd0f1d11b2fae
Author: Michael Meissner 
Date:   Wed Jul 24 19:51:02 2024 -0400

Use architecture flags for defining _ARCH_PWR macros.

2024-07-24  Michael Meissner  

gcc/

* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros) Add 
support to
use architecture flags instead of ISA flags for setting most of the
_ARCH_PWR* macros.
(rs6000_cpu_cpp_builtins): Likewise.
* config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Remove
OPTION_MASK_POWER8.
(ISA_3_1_MASKS_SERVER): Remove OPTION_MASK_POWER10.
(POWER11_MASKS_SERVER): Remove OPTION_MASK_POWER11.
(POWERPC_MASKS): Remove OPTION_MASK_POWER8, OPTION_MASK_POWER10, and
OPTION_MASK_POWER11.
* config/rs6000/rs6000-protos.h (rs6000_target_modify_macros): 
Update
declaration.
(rs6000_target_modify_macros_ptr): Likewise.
* config/rs6000/rs6000.cc (rs6000_target_modify_macros_ptr): 
Likewise.
(rs6000_option_override_internal): Use architecture flags instead 
of ISA
flags.
(rs6000_opt_masks): Remove -mpower10 and -mpower11 support.
(rs6000_pragma_target_parse): Use architecture flags as well as ISA
flags.
* config/rs6000/rs6000.h (TARGET_POWER8): New macro.
(TARGET_POWER10): Likewise.
* config/rs6000/rs6000.opt (-mpower8-internal): No longer make this 
an
ISA flag.
(-mpower10): Likewise.
(-mpower11): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-c.cc | 23 ---
 gcc/config/rs6000/rs6000-cpus.def |  8 +---
 gcc/config/rs6000/rs6000-protos.h |  5 +++--
 gcc/config/rs6000/rs6000.cc   | 19 +++
 gcc/config/rs6000/rs6000.h|  6 ++
 gcc/config/rs6000/rs6000.opt  | 11 ++-
 6 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 68519e1397f1..2ffaee165885 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -338,7 +338,8 @@ rs6000_define_or_undefine_macro (bool define_p, const char 
*name)
#pragma GCC target, we need to adjust the macros dynamically.  */
 
 void
-rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags)
+rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags,
+HOST_WIDE_INT arch_flags)
 {
   if (TARGET_DEBUG_BUILTIN || TARGET_DEBUG_TARGET)
 fprintf (stderr,
@@ -411,7 +412,7 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags)
summary of the flags associated with particular cpu
definitions.  */
 
-  /* rs6000_isa_flags based options.  */
+  /* rs6000_isa_flags and rs6000_arch_flags based options.  */
   rs6000_define_or_undefine_macro (define_p, "_ARCH_PPC");
   if ((flags & OPTION_MASK_PPC_GPOPT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PPCSQ");
@@ -421,21 +422,21 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PPC64");
   if ((flags & OPTION_MASK_MFCRF) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR4");
-  if ((flags & OPTION_MASK_POPCNTB) != 0)
+  if ((arch_flags & ARCH_MASK_POWER4) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR5");
-  if ((flags & OPTION_MASK_FPRND) != 0)
+  if ((arch_flags & ARCH_MASK_POWER5) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR5X");
-  if ((flags & OPTION_MASK_CMPB) != 0)
+  if ((arch_flags & ARCH_MASK_POWER6) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR6");
-  if ((flags & OPTION_MASK_POPCNTD) != 0)
+  if ((arch_flags & ARCH_MASK_POWER7) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR7");
-  if ((flags & OPTION_MASK_POWER8) != 0)
+  if ((arch_flags & ARCH_MASK_POWER8) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR8");
-  if ((flags & OPTION_MASK_MODULO) != 0)
+  if ((arch_flags & ARCH_MASK_POWER9) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR9");
-  if ((flags & OPTION_MASK_POWER10) != 0)
+  if ((arch_flags & ARCH_MASK_POWER10) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR10");
-  if ((flags & OPTION_MASK_POWER11) != 0)
+  if ((arch_flags & ARCH_MASK_POWER11) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR11");
   if ((flags & OPTION_MASK_SOFT_FLOAT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_SOFT_FLOAT");
@@ -605,7 +606,7 @@ void
 rs6000_cpu_cpp_builtins (cpp_reader *pfile)
 {
   /* Define all of the common macros.  */
-  rs6000_target_modify_macros (true, rs6000_isa_flags);
+  rs6000_target_modify_macros (true, rs6000_isa_flags, rs6000_arch_flags);
 
   if (TARGET_FRE)
 builtin_de

[gcc(refs/users/meissner/heads/work173)] Make clone_targets use architecture flags.

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:ecaac2a990989cde515d3ad0159a7db134ff4893

commit ecaac2a990989cde515d3ad0159a7db134ff4893
Author: Michael Meissner 
Date:   Wed Jul 24 19:21:47 2024 -0400

Make clone_targets use architecture flags.

2024-07-24  Michael Meissner  

gcc/

* config/rs6000/rs6000.cc (struct clone_map): Switch to use 
architecture
flags instead of ISA flags for target_clone support.
(rs6000_clone_map): Likewise.
(rs6000_clone_priority): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000.cc | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 6ceea856c0e4..7ebf70339324 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -251,17 +251,17 @@ enum {
 
 /* Map compiler ISA bits into HWCAP names.  */
 struct clone_map {
-  HOST_WIDE_INT isa_mask;  /* rs6000_isa mask */
+  HOST_WIDE_INT arch_mask; /* rs6000_arch_mask.  */
   const char *name;/* name to use in __builtin_cpu_supports.  */
 };
 
 static const struct clone_map rs6000_clone_map[CLONE_MAX] = {
-  { 0, "" },   /* Default options.  */
-  { OPTION_MASK_CMPB,  "arch_2_05" },  /* ISA 2.05 (power6).  */
-  { OPTION_MASK_POPCNTD,   "arch_2_06" },  /* ISA 2.06 (power7).  */
-  { OPTION_MASK_P8_VECTOR, "arch_2_07" },  /* ISA 2.07 (power8).  */
-  { OPTION_MASK_P9_VECTOR, "arch_3_00" },  /* ISA 3.0 (power9).  */
-  { OPTION_MASK_POWER10,   "arch_3_1" },   /* ISA 3.1 (power10).  */
+  { 0, "" },   /* Default options.  */
+  { ARCH_MASK_POWER6,  "arch_2_05" },  /* ISA 2.05 (power6).  */
+  { ARCH_MASK_POWER7,  "arch_2_06" },  /* ISA 2.06 (power7).  */
+  { ARCH_MASK_POWER8,  "arch_2_07" },  /* ISA 2.07 (power8).  */
+  { ARCH_MASK_POWER9,  "arch_3_00" },  /* ISA 3.0 (power9).  */
+  { ARCH_MASK_POWER10, "arch_3_1" },   /* ISA 3.1 (power10).  */
 };
 
 
@@ -25396,7 +25396,7 @@ static int
 rs6000_clone_priority (tree fndecl)
 {
   tree fn_opts = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
-  HOST_WIDE_INT isa_masks;
+  HOST_WIDE_INT arch_masks;
   int ret = CLONE_DEFAULT;
   tree attrs = lookup_attribute ("target", DECL_ATTRIBUTES (fndecl));
   const char *attrs_str = NULL;
@@ -25412,12 +25412,12 @@ rs6000_clone_priority (tree fndecl)
fn_opts = target_option_default_node;
 
   if (!fn_opts || !TREE_TARGET_OPTION (fn_opts))
-   isa_masks = rs6000_isa_flags;
+   arch_masks = rs6000_arch_flags;
   else
-   isa_masks = TREE_TARGET_OPTION (fn_opts)->x_rs6000_isa_flags;
+   arch_masks = TREE_TARGET_OPTION (fn_opts)->x_rs6000_arch_flags;
 
   for (ret = CLONE_MAX - 1; ret != 0; ret--)
-   if ((rs6000_clone_map[ret].isa_mask & isa_masks) != 0)
+   if ((rs6000_clone_map[ret].arch_mask & arch_masks) != 0)
  break;
 }


[gcc(refs/users/meissner/heads/work173)] Set .machine from the architecture flags

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:377cc95fa1ec8b8f5000c205f740cc996534613d

commit 377cc95fa1ec8b8f5000c205f740cc996534613d
Author: Michael Meissner 
Date:   Wed Jul 24 19:25:30 2024 -0400

Set .machine from the architecture flags

2024-07-24  Michael Meissner  

gcc/

* config/rs6000/rs6000 (rs6000_machine_from_flags): Set .machine 
from
the architecture flags.

Diff:
---
 gcc/config/rs6000/rs6000.cc | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 7ebf70339324..f736a87db4a9 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -5960,27 +5960,28 @@ rs6000_machine_from_flags (void)
 return "ppc64";
 #endif
 
+  HOST_WIDE_INT arch_flags = rs6000_arch_flags;
   HOST_WIDE_INT flags = rs6000_isa_flags;
 
   /* Disable the flags that should never influence the .machine selection.  */
   flags &= ~(OPTION_MASK_PPC_GFXOPT | OPTION_MASK_PPC_GPOPT | OPTION_MASK_ISEL
 | OPTION_MASK_ALTIVEC);
 
-  if ((flags & (POWER11_MASKS_SERVER & ~ISA_3_1_MASKS_SERVER)) != 0)
+  if ((arch_flags & ARCH_MASK_POWER11) != 0)
 return "power11";
-  if ((flags & (ISA_3_1_MASKS_SERVER & ~ISA_3_0_MASKS_SERVER)) != 0)
+  if ((arch_flags & ARCH_MASK_POWER10) != 0)
 return "power10";
-  if ((flags & (ISA_3_0_MASKS_SERVER & ~ISA_2_7_MASKS_SERVER)) != 0)
+  if ((arch_flags & ARCH_MASK_POWER9) != 0)
 return "power9";
-  if ((flags & (ISA_2_7_MASKS_SERVER & ~ISA_2_6_MASKS_SERVER)) != 0)
+  if ((arch_flags & ARCH_MASK_POWER8) != 0)
 return "power8";
-  if ((flags & (ISA_2_6_MASKS_SERVER & ~ISA_2_5_MASKS_SERVER)) != 0)
+  if ((arch_flags & ARCH_MASK_POWER7) != 0)
 return "power7";
-  if ((flags & (ISA_2_5_MASKS_SERVER & ~ISA_2_4_MASKS)) != 0)
+  if ((arch_flags & ARCH_MASK_POWER6) != 0)
 return "power6";
-  if ((flags & (ISA_2_4_MASKS & ~ISA_2_1_MASKS)) != 0)
+  if ((arch_flags & ARCH_MASK_POWER5) != 0)
 return "power5";
-  if ((flags & ISA_2_1_MASKS) != 0)
+  if ((arch_flags & ARCH_MASK_POWER4) != 0)
 return "power4";
   if ((flags & OPTION_MASK_POWERPC64) != 0)
 return "ppc64";


[gcc r15-2295] i386: Adjust rtx cost for imulq and imulw [PR115749]

2024-07-24 Thread Kong Lingling via Gcc-cvs
https://gcc.gnu.org/g:bc00de070f0b9a25f68ffddbefe516543a44bd23

commit r15-2295-gbc00de070f0b9a25f68ffddbefe516543a44bd23
Author: Lingling Kong 
Date:   Thu Jul 25 09:42:06 2024 +0800

i386: Adjust rtx cost for imulq and imulw [PR115749]

gcc/ChangeLog:

PR target/115749
* config/i386/x86-tune-costs.h (struct processor_costs):
Adjust rtx_cost of imulq and imulw for COST_N_INSNS (4)
to COST_N_INSNS (3).

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr115749.c: New test.

Diff:
---
 gcc/config/i386/x86-tune-costs.h | 16 
 gcc/testsuite/gcc.target/i386/pr115749.c | 16 
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/gcc/config/i386/x86-tune-costs.h b/gcc/config/i386/x86-tune-costs.h
index 769f334e5318..2bfaee554d53 100644
--- a/gcc/config/i386/x86-tune-costs.h
+++ b/gcc/config/i386/x86-tune-costs.h
@@ -2182,7 +2182,7 @@ struct processor_costs skylake_cost = {
   COSTS_N_INSNS (1),   /* variable shift costs */
   COSTS_N_INSNS (1),   /* constant shift costs */
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
-   COSTS_N_INSNS (4),  /*   HI */
+   COSTS_N_INSNS (3),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
COSTS_N_INSNS (3),  /*   DI */
COSTS_N_INSNS (3)}, /*other */
@@ -2310,7 +2310,7 @@ struct processor_costs icelake_cost = {
   COSTS_N_INSNS (1),   /* variable shift costs */
   COSTS_N_INSNS (1),   /* constant shift costs */
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
-   COSTS_N_INSNS (4),  /*   HI */
+   COSTS_N_INSNS (3),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
COSTS_N_INSNS (3),  /*   DI */
COSTS_N_INSNS (3)}, /*other */
@@ -2434,9 +2434,9 @@ struct processor_costs alderlake_cost = {
   COSTS_N_INSNS (1),   /* variable shift costs */
   COSTS_N_INSNS (1),   /* constant shift costs */
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
-   COSTS_N_INSNS (4),  /*   HI */
+   COSTS_N_INSNS (3),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
-   COSTS_N_INSNS (4),  /*   DI */
+   COSTS_N_INSNS (3),  /*   DI */
COSTS_N_INSNS (4)}, /*other */
   0,   /* cost of multiply per each bit set */
   {COSTS_N_INSNS (16), /* cost of a divide/mod for QI */
@@ -3234,9 +3234,9 @@ struct processor_costs tremont_cost = {
   COSTS_N_INSNS (1),   /* variable shift costs */
   COSTS_N_INSNS (1),   /* constant shift costs */
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
-   COSTS_N_INSNS (4),  /*   HI */
+   COSTS_N_INSNS (3),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
-   COSTS_N_INSNS (4),  /*   DI */
+   COSTS_N_INSNS (3),  /*   DI */
COSTS_N_INSNS (4)}, /*other */
   0,   /* cost of multiply per each bit set */
   {COSTS_N_INSNS (16), /* cost of a divide/mod for QI */
@@ -3816,9 +3816,9 @@ struct processor_costs generic_cost = {
   COSTS_N_INSNS (1),   /* variable shift costs */
   COSTS_N_INSNS (1),   /* constant shift costs */
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
-   COSTS_N_INSNS (4),  /*   HI */
+   COSTS_N_INSNS (3),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
-   COSTS_N_INSNS (4),  /*   DI */
+   COSTS_N_INSNS (3),  /*   DI */
COSTS_N_INSNS (4)}, /*other */
   0,   /* cost of multiply per each bit set */
   {COSTS_N_INSNS (16), /* cost of a divide/mod for QI 

[gcc/meissner/heads/work173-bugs] (16 commits) Merge commit 'refs/users/meissner/heads/work173-bugs' of gi

2024-07-24 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work173-bugs' was updated to point to:

 b241f306435a... Merge commit 'refs/users/meissner/heads/work173-bugs' of gi

It previously pointed to:

 34348576103d... Add ChangeLog.bugs and update REVISION.

Diff:

Summary of changes (added commits):
---

  b241f30... Merge commit 'refs/users/meissner/heads/work173-bugs' of gi
  623a257... Add ChangeLog.bugs and update REVISION.
  dc0cb0a... Use architecture flags for defining _ARCH_PWR macros. (*)
  377cc95... Set .machine from the architecture flags (*)
  ecaac2a... Make clone_targets use architecture flags. (*)
  db3b4de... Separate architecture flags from ISA flags (*)
  11ca5a8... Revert changes (*)
  b78f446... Update ChangeLog.* (*)
  f3a1dcd... Modify how arch flags are set. (*)
  93b27dd... Update ChangeLog.* (*)
  d64c5ff... Remove -mpower10 and -mpower8-internal (*)
  191fcce... Update ChangeLog.* (*)
  5021a6c... Move architecture flags from isa flags (*)
  f5939df... Revert changes (*)
  a423861... Update ChangeLog.* (*)
  f4fdb95... Move architecture flags from isa flags (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work173-bugs' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work173-bugs)] Merge commit 'refs/users/meissner/heads/work173-bugs' of git+ssh://gcc.gnu.org/git/gcc into me/work1

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:b241f306435a010151d59b3468286303ea2322e8

commit b241f306435a010151d59b3468286303ea2322e8
Merge: 623a257c9517 34348576103d
Author: Michael Meissner 
Date:   Thu Jul 25 00:54:55 2024 -0400

Merge commit 'refs/users/meissner/heads/work173-bugs' of 
git+ssh://gcc.gnu.org/git/gcc into me/work173-bugs

Diff:


[gcc(refs/users/meissner/heads/work173-bugs)] Add ChangeLog.bugs and update REVISION.

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:623a257c9517c3353ea7a3d86aa179f865d2293c

commit 623a257c9517c3353ea7a3d86aa179f865d2293c
Author: Michael Meissner 
Date:   Mon Jul 22 15:06:29 2024 -0400

Add ChangeLog.bugs and update REVISION.

2024-07-22  Michael Meissner  

gcc/

* ChangeLog.bugs: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.bugs | 6 ++
 gcc/REVISION   | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.bugs b/gcc/ChangeLog.bugs
new file mode 100644
index ..902aaca7a1a5
--- /dev/null
+++ b/gcc/ChangeLog.bugs
@@ -0,0 +1,6 @@
+ Branch work173-bugs, baseline 
+
+2024-07-22   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 125a55f99c87..678ec160dcf8 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work173 branch
+work173-bugs branch


[gcc/meissner/heads/work173-dmf] (16 commits) Merge commit 'refs/users/meissner/heads/work173-dmf' of git

2024-07-24 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work173-dmf' was updated to point to:

 d8c9901389ec... Merge commit 'refs/users/meissner/heads/work173-dmf' of git

It previously pointed to:

 47fc63ebcee7... Add ChangeLog.dmf and update REVISION.

Diff:

Summary of changes (added commits):
---

  d8c9901... Merge commit 'refs/users/meissner/heads/work173-dmf' of git
  fe24662... Add ChangeLog.dmf and update REVISION.
  dc0cb0a... Use architecture flags for defining _ARCH_PWR macros. (*)
  377cc95... Set .machine from the architecture flags (*)
  ecaac2a... Make clone_targets use architecture flags. (*)
  db3b4de... Separate architecture flags from ISA flags (*)
  11ca5a8... Revert changes (*)
  b78f446... Update ChangeLog.* (*)
  f3a1dcd... Modify how arch flags are set. (*)
  93b27dd... Update ChangeLog.* (*)
  d64c5ff... Remove -mpower10 and -mpower8-internal (*)
  191fcce... Update ChangeLog.* (*)
  5021a6c... Move architecture flags from isa flags (*)
  f5939df... Revert changes (*)
  a423861... Update ChangeLog.* (*)
  f4fdb95... Move architecture flags from isa flags (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work173-dmf' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work173-dmf)] Add ChangeLog.dmf and update REVISION.

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:fe246621c60bd63f6007bacc6b5092ea56583ef0

commit fe246621c60bd63f6007bacc6b5092ea56583ef0
Author: Michael Meissner 
Date:   Mon Jul 22 15:03:47 2024 -0400

Add ChangeLog.dmf and update REVISION.

2024-07-22  Michael Meissner  

gcc/

* ChangeLog.dmf: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.dmf | 6 ++
 gcc/REVISION  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.dmf b/gcc/ChangeLog.dmf
new file mode 100644
index ..a638f2fb1faa
--- /dev/null
+++ b/gcc/ChangeLog.dmf
@@ -0,0 +1,6 @@
+ Branch work173-dmf, baseline 
+
+2024-07-22   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 125a55f99c87..ba813185b130 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work173 branch
+work173-dmf branch


[gcc(refs/users/meissner/heads/work173-dmf)] Merge commit 'refs/users/meissner/heads/work173-dmf' of git+ssh://gcc.gnu.org/git/gcc into me/work17

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:d8c9901389ecc40f743f432cc433c860924bbfc9

commit d8c9901389ecc40f743f432cc433c860924bbfc9
Merge: fe246621c60b 47fc63ebcee7
Author: Michael Meissner 
Date:   Thu Jul 25 00:56:05 2024 -0400

Merge commit 'refs/users/meissner/heads/work173-dmf' of 
git+ssh://gcc.gnu.org/git/gcc into me/work173-dmf

Diff:


[gcc/meissner/heads/work173-tar] (16 commits) Merge commit 'refs/users/meissner/heads/work173-tar' of git

2024-07-24 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work173-tar' was updated to point to:

 1064a2f6906a... Merge commit 'refs/users/meissner/heads/work173-tar' of git

It previously pointed to:

 c8b6ce9637ad... Add ChangeLog.tar and update REVISION.

Diff:

Summary of changes (added commits):
---

  1064a2f... Merge commit 'refs/users/meissner/heads/work173-tar' of git
  2271a8f... Add ChangeLog.tar and update REVISION.
  dc0cb0a... Use architecture flags for defining _ARCH_PWR macros. (*)
  377cc95... Set .machine from the architecture flags (*)
  ecaac2a... Make clone_targets use architecture flags. (*)
  db3b4de... Separate architecture flags from ISA flags (*)
  11ca5a8... Revert changes (*)
  b78f446... Update ChangeLog.* (*)
  f3a1dcd... Modify how arch flags are set. (*)
  93b27dd... Update ChangeLog.* (*)
  d64c5ff... Remove -mpower10 and -mpower8-internal (*)
  191fcce... Update ChangeLog.* (*)
  5021a6c... Move architecture flags from isa flags (*)
  f5939df... Revert changes (*)
  a423861... Update ChangeLog.* (*)
  f4fdb95... Move architecture flags from isa flags (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work173-tar' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work173-tar)] Add ChangeLog.tar and update REVISION.

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:2271a8f962993dbd457a1932f0c4084b5373ce94

commit 2271a8f962993dbd457a1932f0c4084b5373ce94
Author: Michael Meissner 
Date:   Mon Jul 22 15:05:41 2024 -0400

Add ChangeLog.tar and update REVISION.

2024-07-22  Michael Meissner  

gcc/

* ChangeLog.tar: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.tar | 6 ++
 gcc/REVISION  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
new file mode 100644
index ..49bf0b56d50e
--- /dev/null
+++ b/gcc/ChangeLog.tar
@@ -0,0 +1,6 @@
+ Branch work173-tar, baseline 
+
+2024-07-22   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 125a55f99c87..326918224436 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work173 branch
+work173-tar branch


[gcc(refs/users/meissner/heads/work173-tar)] Merge commit 'refs/users/meissner/heads/work173-tar' of git+ssh://gcc.gnu.org/git/gcc into me/work17

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:1064a2f6906a3570e576594f45d8f1632979eb8d

commit 1064a2f6906a3570e576594f45d8f1632979eb8d
Merge: 2271a8f96299 c8b6ce9637ad
Author: Michael Meissner 
Date:   Thu Jul 25 00:57:11 2024 -0400

Merge commit 'refs/users/meissner/heads/work173-tar' of 
git+ssh://gcc.gnu.org/git/gcc into me/work173-tar

Diff:


[gcc/meissner/heads/work173-test] (16 commits) Merge commit 'refs/users/meissner/heads/work173-test' of gi

2024-07-24 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work173-test' was updated to point to:

 903574fd9243... Merge commit 'refs/users/meissner/heads/work173-test' of gi

It previously pointed to:

 7a7b57e177e0... Add ChangeLog.test and update REVISION.

Diff:

Summary of changes (added commits):
---

  903574f... Merge commit 'refs/users/meissner/heads/work173-test' of gi
  07826cb... Add ChangeLog.test and update REVISION.
  dc0cb0a... Use architecture flags for defining _ARCH_PWR macros. (*)
  377cc95... Set .machine from the architecture flags (*)
  ecaac2a... Make clone_targets use architecture flags. (*)
  db3b4de... Separate architecture flags from ISA flags (*)
  11ca5a8... Revert changes (*)
  b78f446... Update ChangeLog.* (*)
  f3a1dcd... Modify how arch flags are set. (*)
  93b27dd... Update ChangeLog.* (*)
  d64c5ff... Remove -mpower10 and -mpower8-internal (*)
  191fcce... Update ChangeLog.* (*)
  5021a6c... Move architecture flags from isa flags (*)
  f5939df... Revert changes (*)
  a423861... Update ChangeLog.* (*)
  f4fdb95... Move architecture flags from isa flags (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work173-test' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work173-test)] Merge commit 'refs/users/meissner/heads/work173-test' of git+ssh://gcc.gnu.org/git/gcc into me/work1

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:903574fd9243e255f47543de8aaf07e4aede42da

commit 903574fd9243e255f47543de8aaf07e4aede42da
Merge: 07826cbe9d56 7a7b57e177e0
Author: Michael Meissner 
Date:   Thu Jul 25 00:58:25 2024 -0400

Merge commit 'refs/users/meissner/heads/work173-test' of 
git+ssh://gcc.gnu.org/git/gcc into me/work173-test

Diff:


[gcc(refs/users/meissner/heads/work173-test)] Add ChangeLog.test and update REVISION.

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:07826cbe9d5665a0e3cc763cce10864dc54e1fb7

commit 07826cbe9d5665a0e3cc763cce10864dc54e1fb7
Author: Michael Meissner 
Date:   Mon Jul 22 15:07:51 2024 -0400

Add ChangeLog.test and update REVISION.

2024-07-22  Michael Meissner  

gcc/

* ChangeLog.test: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.test | 6 ++
 gcc/REVISION   | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.test b/gcc/ChangeLog.test
new file mode 100644
index ..03e20764eb03
--- /dev/null
+++ b/gcc/ChangeLog.test
@@ -0,0 +1,6 @@
+ Branch work173-test, baseline 
+
+2024-07-22   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 125a55f99c87..858e261ae8fb 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work173 branch
+work173-test branch


[gcc/meissner/heads/work173-vpair] (16 commits) Merge commit 'refs/users/meissner/heads/work173-vpair' of g

2024-07-24 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work173-vpair' was updated to point to:

 ba573e905753... Merge commit 'refs/users/meissner/heads/work173-vpair' of g

It previously pointed to:

 8515318b78ea... Add ChangeLog.vpair and update REVISION.

Diff:

Summary of changes (added commits):
---

  ba573e9... Merge commit 'refs/users/meissner/heads/work173-vpair' of g
  2d29496... Add ChangeLog.vpair and update REVISION.
  dc0cb0a... Use architecture flags for defining _ARCH_PWR macros. (*)
  377cc95... Set .machine from the architecture flags (*)
  ecaac2a... Make clone_targets use architecture flags. (*)
  db3b4de... Separate architecture flags from ISA flags (*)
  11ca5a8... Revert changes (*)
  b78f446... Update ChangeLog.* (*)
  f3a1dcd... Modify how arch flags are set. (*)
  93b27dd... Update ChangeLog.* (*)
  d64c5ff... Remove -mpower10 and -mpower8-internal (*)
  191fcce... Update ChangeLog.* (*)
  5021a6c... Move architecture flags from isa flags (*)
  f5939df... Revert changes (*)
  a423861... Update ChangeLog.* (*)
  f4fdb95... Move architecture flags from isa flags (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work173-vpair' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work173-vpair)] Merge commit 'refs/users/meissner/heads/work173-vpair' of git+ssh://gcc.gnu.org/git/gcc into me/work

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:ba573e90575301a6e35bd0b9d628b22992e8be8c

commit ba573e90575301a6e35bd0b9d628b22992e8be8c
Merge: 2d294966cc54 8515318b78ea
Author: Michael Meissner 
Date:   Thu Jul 25 00:59:51 2024 -0400

Merge commit 'refs/users/meissner/heads/work173-vpair' of 
git+ssh://gcc.gnu.org/git/gcc into me/work173-vpair

Diff:


[gcc(refs/users/meissner/heads/work173-vpair)] Add ChangeLog.vpair and update REVISION.

2024-07-24 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:2d294966cc549e9ae661ab6875526049486b4d72

commit 2d294966cc549e9ae661ab6875526049486b4d72
Author: Michael Meissner 
Date:   Mon Jul 22 15:04:47 2024 -0400

Add ChangeLog.vpair and update REVISION.

2024-07-22  Michael Meissner  

gcc/

* ChangeLog.vpair: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.vpair | 6 ++
 gcc/REVISION| 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
new file mode 100644
index ..6b79a1e6c689
--- /dev/null
+++ b/gcc/ChangeLog.vpair
@@ -0,0 +1,6 @@
+ Branch work173-vpair, baseline 
+
+2024-07-22   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 125a55f99c87..f7e937ee745e 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work173 branch
+work173-vpair branch


[gcc r15-2296] Maintain complex constraint vector order during PTA solving

2024-07-24 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:09de976f9bcab1d3018d5461ea2abb8a47f20528

commit r15-2296-g09de976f9bcab1d3018d5461ea2abb8a47f20528
Author: Richard Biener 
Date:   Tue Jul 23 14:05:47 2024 +0200

Maintain complex constraint vector order during PTA solving

There's a FIXME comment in the PTA constraint solver that the vector
of complex constraints can get unsorted which can lead to duplicate
entries piling up during node unification.  The following fixes this
with the assumption that delayed updates to constraints are uncommon
(otherwise re-sorting the whole vector would be more efficient).

* tree-ssa-structalias.cc (constraint_equal): Take const
reference to constraints.
(constraint_vec_find): Similar.
(solve_graph): Keep constraint vector sorted and verify
sorting with checking.

Diff:
---
 gcc/tree-ssa-structalias.cc | 73 +
 1 file changed, 61 insertions(+), 12 deletions(-)

diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 65f9132a94fd..a32ef1d5cc0c 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -902,7 +902,7 @@ constraint_less (const constraint_t &a, const constraint_t 
&b)
 /* Return true if two constraints A and B are equal.  */
 
 static bool
-constraint_equal (struct constraint a, struct constraint b)
+constraint_equal (const constraint &a, const constraint &b)
 {
   return constraint_expr_equal (a.lhs, b.lhs)
 && constraint_expr_equal (a.rhs, b.rhs);
@@ -913,7 +913,7 @@ constraint_equal (struct constraint a, struct constraint b)
 
 static constraint_t
 constraint_vec_find (vec vec,
-struct constraint lookfor)
+constraint &lookfor)
 {
   unsigned int place;
   constraint_t found;
@@ -2806,10 +2806,8 @@ solve_graph (constraint_graph_t graph)
 better visitation order in the next iteration.  */
  while (bitmap_clear_bit (changed, i))
{
- unsigned int j;
- constraint_t c;
  bitmap solution;
- vec complex = graph->complex[i];
+ vec &complex = graph->complex[i];
  varinfo_t vi = get_varinfo (i);
  bool solution_empty;
 
@@ -2845,23 +2843,73 @@ solve_graph (constraint_graph_t graph)
  solution_empty = bitmap_empty_p (solution);
 
  /* Process the complex constraints */
+ hash_set *cvisited = nullptr;
+ if (flag_checking)
+   cvisited = new hash_set;
  bitmap expanded_pts = NULL;
- FOR_EACH_VEC_ELT (complex, j, c)
+ for (unsigned j = 0; j < complex.length (); ++j)
{
- /* XXX: This is going to unsort the constraints in
-some cases, which will occasionally add duplicate
-constraints during unification.  This does not
-affect correctness.  */
- c->lhs.var = find (c->lhs.var);
- c->rhs.var = find (c->rhs.var);
+ constraint_t c = complex[j];
+ /* At unification time only the directly involved nodes
+will get their complex constraints updated.  Update
+our complex constraints now but keep the constraint
+vector sorted and clear of duplicates.  Also make
+sure to evaluate each prevailing constraint only once.  */
+ unsigned int new_lhs = find (c->lhs.var);
+ unsigned int new_rhs = find (c->rhs.var);
+ if (c->lhs.var != new_lhs || c->rhs.var != new_rhs)
+   {
+ constraint tem = *c;
+ tem.lhs.var = new_lhs;
+ tem.rhs.var = new_rhs;
+ unsigned int place
+   = complex.lower_bound (&tem, constraint_less);
+ c->lhs.var = new_lhs;
+ c->rhs.var = new_rhs;
+ if (place != j)
+   {
+ complex.ordered_remove (j);
+ if (j < place)
+   --place;
+ if (place < complex.length ())
+   {
+ if (constraint_equal (*complex[place], *c))
+   {
+ j--;
+ continue;
+   }
+ else
+   complex.safe_insert (place, c);
+   }
+ else
+   complex.quick_push (c);
+ if (place > j)
+   {
+ j--;
+ continue;
+   }
+  

[gcc r15-2297] SVE Intrinsics: Change return type of redirect_call to gcall.

2024-07-24 Thread Kyrylo Tkachov via Gcc-cvs
https://gcc.gnu.org/g:3adfcc5802237e1299d67e6d716481cd3db2234a

commit r15-2297-g3adfcc5802237e1299d67e6d716481cd3db2234a
Author: Jennifer Schmitz 
Date:   Tue Jul 23 03:54:50 2024 -0700

SVE Intrinsics: Change return type of redirect_call to gcall.

As suggested in the review of
https://gcc.gnu.org/pipermail/gcc-patches/2024-July/657474.html,
this patch changes the return type of gimple_folder::redirect_call from
gimple * to gcall *. The motivation for this is that so far, most callers of
the function had been casting the result of the function to gcall. These
call sites were updated.

The patch was bootstrapped and regtested on aarch64-linux-gnu, no 
regression.
OK for mainline?

Signed-off-by: Jennifer Schmitz 

gcc/

* config/aarch64/aarch64-sve-builtins.cc
(gimple_folder::redirect_call): Update return type.
* config/aarch64/aarch64-sve-builtins.h: Likewise.
* config/aarch64/aarch64-sve-builtins-sve2.cc (svqshl_impl::fold):
Remove cast to gcall.
(svrshl_impl::fold): Likewise.

Diff:
---
 gcc/config/aarch64/aarch64-sve-builtins-sve2.cc | 6 +++---
 gcc/config/aarch64/aarch64-sve-builtins.cc  | 2 +-
 gcc/config/aarch64/aarch64-sve-builtins.h   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc 
b/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc
index 4f25cc680282..dc5915516825 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc
@@ -349,7 +349,7 @@ public:
instance.base_name = "svlsr";
instance.base = functions::svlsr;
  }
-   gcall *call = as_a  (f.redirect_call (instance));
+   gcall *call = f.redirect_call (instance);
gimple_call_set_arg (call, 2, amount);
return call;
  }
@@ -379,7 +379,7 @@ public:
function_instance instance ("svlsl", functions::svlsl,
shapes::binary_uint_opt_n, MODE_n,
f.type_suffix_ids, GROUP_none, f.pred);
-   gcall *call = as_a  (f.redirect_call (instance));
+   gcall *call = f.redirect_call (instance);
gimple_call_set_arg (call, 2, amount);
return call;
  }
@@ -392,7 +392,7 @@ public:
function_instance instance ("svrshr", functions::svrshr,
shapes::shift_right_imm, MODE_n,
f.type_suffix_ids, GROUP_none, f.pred);
-   gcall *call = as_a  (f.redirect_call (instance));
+   gcall *call = f.redirect_call (instance);
gimple_call_set_arg (call, 2, amount);
return call;
  }
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.cc 
b/gcc/config/aarch64/aarch64-sve-builtins.cc
index f3983a123e35..0a560eaedca1 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins.cc
@@ -3592,7 +3592,7 @@ gimple_folder::load_store_cookie (tree type)
 }
 
 /* Fold the call to a call to INSTANCE, with the same arguments.  */
-gimple *
+gcall *
 gimple_folder::redirect_call (const function_instance &instance)
 {
   registered_function *rfn
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.h 
b/gcc/config/aarch64/aarch64-sve-builtins.h
index 9cc07d5fa3de..9ab6f202c306 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.h
+++ b/gcc/config/aarch64/aarch64-sve-builtins.h
@@ -629,7 +629,7 @@ public:
   tree fold_contiguous_base (gimple_seq &, tree);
   tree load_store_cookie (tree);
 
-  gimple *redirect_call (const function_instance &);
+  gcall *redirect_call (const function_instance &);
   gimple *redirect_pred_x ();
 
   gimple *fold_to_cstu (poly_uint64);