Re: [PATCH] riscv: Allocate enough space to strcpy() string

2024-06-15 Thread Christoph Müllner
On Sat, Jun 15, 2024, 08:25 Kito Cheng  wrote:

> Oooops, thanks for catching that! It's LGTM:)
>

Also OK for the GCC 14 branch?


> Christoph Müllner  於 2024年6月15日 週六 04:58 寫道:
>
>> I triggered an ICE on Ubuntu 24.04 when compiling code that uses
>> function attributes. Looking into the sources shows that we have
>> a systematic issue in the attribute handling code:
>> * we determine the length with strlen() (excluding the terminating null)
>> * we allocate a buffer with this length
>> * we copy the original string using strcpy() (incl. the terminating null)
>>
>> To quote the man page of strcpy():
>> "The programmer is responsible for allocating a  destination  buffer
>> large  enough,  that  is, strlen(src)  + 1."
>>
>> The ICE looks like this:
>>
>> *** buffer overflow detected ***: terminated
>> xtheadmempair_bench.c:14:1: internal compiler error: Aborted
>>14 | {
>>   | ^
>> 0xaf3b99 crash_signal
>> /home/ubuntu/src/gcc/scaleff/gcc/toplev.cc:319
>> 0xe5b957 strcpy
>> /usr/include/riscv64-linux-gnu/bits/string_fortified.h:79
>> 0xe5b957 riscv_process_target_attr
>>
>> /home/ubuntu/src/gcc/scaleff/gcc/config/riscv/riscv-target-attr.cc:339
>> 0xe5baaf riscv_process_target_attr
>>
>> /home/ubuntu/src/gcc/scaleff/gcc/config/riscv/riscv-target-attr.cc:314
>> 0xe5bc5f riscv_option_valid_attribute_p(tree_node*, tree_node*,
>> tree_node*, int)
>>
>> /home/ubuntu/src/gcc/scaleff/gcc/config/riscv/riscv-target-attr.cc:389
>> 0x6a31e5 handle_target_attribute
>> /home/ubuntu/src/gcc/scaleff/gcc/c-family/c-attribs.cc:5915
>> 0x5d3a07 decl_attributes(tree_node**, tree_node*, int, tree_node*)
>> /home/ubuntu/src/gcc/scaleff/gcc/attribs.cc:900
>> 0x5db403 c_decl_attributes
>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-decl.cc:5501
>> 0x5e8965 start_function(c_declspecs*, c_declarator*, tree_node*)
>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-decl.cc:10562
>> 0x6318ed c_parser_declaration_or_fndef
>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-parser.cc:2914
>> 0x63a8ad c_parser_external_declaration
>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-parser.cc:2048
>> 0x63b219 c_parser_translation_unit
>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-parser.cc:1902
>> 0x63b219 c_parse_file()
>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-parser.cc:27277
>> 0x68fec5 c_common_parse_file()
>> /home/ubuntu/src/gcc/scaleff/gcc/c-family/c-opts.cc:1311
>> Please submit a full bug report, with preprocessed source (by using
>> -freport-bug).
>> Please include the complete backtrace with any bug report.
>> See  for instructions.
>>
>> gcc/ChangeLog:
>>
>> * config/riscv/riscv-target-attr.cc
>> (riscv_target_attr_parser::parse_arch):
>> Fix allocation size of buffer.
>> (riscv_process_one_target_attr): Likewise.
>> (riscv_process_target_attr): Likewise.
>>
>> Signed-off-by: Christoph Müllner 
>> ---
>>  gcc/config/riscv/riscv-target-attr.cc | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/gcc/config/riscv/riscv-target-attr.cc
>> b/gcc/config/riscv/riscv-target-attr.cc
>> index 1a73d69bf50..19eb7b06d54 100644
>> --- a/gcc/config/riscv/riscv-target-attr.cc
>> +++ b/gcc/config/riscv/riscv-target-attr.cc
>> @@ -109,7 +109,7 @@ riscv_target_attr_parser::parse_arch (const char *str)
>>  {
>>/* Parsing the extension list like "+[,+]*".  */
>>size_t len = strlen (str);
>> -  std::unique_ptr buf (new char[len]);
>> +  std::unique_ptr buf (new char[len+1]);
>>char *str_to_check = buf.get ();
>>strcpy (str_to_check, str);
>>const char *token = strtok_r (str_to_check, ",", &str_to_check);
>> @@ -247,7 +247,7 @@ riscv_process_one_target_attr (char *arg_str,
>>return false;
>>  }
>>
>> -  std::unique_ptr buf (new char[len]);
>> +  std::unique_ptr buf (new char[len+1]);
>>char *str_to_check = buf.get();
>>strcpy (str_to_check, arg_str);
>>
>> @@ -334,7 +334,7 @@ riscv_process_target_attr (tree fndecl, tree args,
>> location_t loc,
>>return false;
>>  }
>>
>> -  std::unique_ptr buf (new char[len]);
>> +  std::unique_ptr buf (new char[len+1]);
>>char *str_to_check = buf.get ();
>>strcpy (str_to_check, TREE_STRING_POINTER (args));
>>
>> --
>> 2.45.1
>>
>>


[pushed] doc: Remove pointer to old versions of binutils

2024-06-15 Thread Gerald Pfeifer
The oldest release in the advertised location dates back to August 2002,
which is way older than we remotely want to cover here.

gcc:
PR target/69374
* doc/install.texi (Specific): Remove pointer to old versions
of binutils.
---
 gcc/doc/install.texi | 4 
 1 file changed, 4 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 38c93f067b5..298031dc2de 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -5251,10 +5251,6 @@ version before they were removed), patches
 likely to be accepted, since they should not affect the support for more
 modern targets.
 
-For some systems, old versions of GNU binutils may also be useful,
-and are available from @file{pub/binutils/old-releases} on
-@uref{https://sourceware.org/mirrors.html,,sourceware.org mirror sites}.
-
 Some of the information on specific systems above relates to
 such older systems, but much of the information
 about GCC on such systems (which may no longer be applicable to
-- 
2.45.2


Re: [RFC v2] RISC-V: Promote Zaamo/Zalrsc to a when using an old binutils

2024-06-15 Thread Andreas Schwab
../../gcc/common/config/riscv/riscv-common.cc: In member function 'std::string 
riscv_subset_list::to_string(bool, bool) const':
../../gcc/common/config/riscv/riscv-common.cc:997:37: error: 'a_subset' may be 
used uninitialized [-Werror=maybe-uninitialized]
  997 |   if (subset_cmp (a_subset->name, subset->name) > 0)
  |   ~~^~~~
../../gcc/common/config/riscv/riscv-common.cc:923:19: note: 'a_subset' was 
declared here
  923 |   riscv_subset_t *a_subset;
  |   ^~~~
cc1plus: all warnings being treated as errors

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


[pushed] wwwdocs: news: Drop links to old OpenMP standard PDFs

2024-06-15 Thread Gerald Pfeifer
We still have newer ones and general links to the specifications.

Pushed.

Gerald
---
 htdocs/news.html | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/htdocs/news.html b/htdocs/news.html
index 4a24a4ad..7d793add 100644
--- a/htdocs/news.html
+++ b/htdocs/news.html
@@ -239,8 +239,7 @@
 
 OpenMP 4.0 offloading support in GCC
  [2015-01-14] wwwdocs:
- http://www.openmp.org/wp-content/uploads/OpenMP4.0.0.pdf";>
- OpenMP 4.0 https://gcc.gnu.org/gcc-5/changes.html#offload";>
+ OpenMP 4.0 https://gcc.gnu.org/gcc-5/changes.html#offload";>
  offloading support was added to GCC.
  Contributed by Jakub Jelinek (Red Hat), Bernd Schmidt and
  Thomas Schwinge (CodeSourcery), Andrey Turetskiy,
@@ -534,8 +533,7 @@ by Embecosm.
 
 OpenMP v3.1
 [2011-08-02] wwwdocs:
-An implementation of the http://www.openmp.org/mp-documents/OpenMP3.1.pdf";>OpenMP v3.1
+An implementation of the OpenMP 3.1
 parallel programming interface for C, C++ and Fortran has been added.
 Code was contributed by Jakub Jelinek of Red Hat, Inc. and
 Tobias Burnus.
@@ -702,8 +700,7 @@ target has been contributed by Picochip Designs 
Limited.
 GCC 4.3.1 has been released.
 
 June 6, 2008
-An implementation of the http://openmp.org/mp-documents/spec30.pdf";>OpenMP v3.0
+An implementation of the OpenMP 3.0
 parallel programming interface for C, C++ and Fortran has been added.
 Code was contributed by Jakub Jelinek, Richard Henderson and
 Ulrich Drepper of Red Hat, Inc.
-- 
2.45.2


Re: [PATCH] libstdc++: Fix build for AVR [PR115481, PR111639]

2024-06-15 Thread Georg-Johann Lay

Am 14.06.24 um 21:11 schrieb Detlef Vollmann:

I actually plan anyway to run a test with the built libstdc++ on simulavr.

   Detlef


As an aside, simulavr tries to simulate an exact match of the hardware
including internal I/O like timers, IRQs, etc.

For GCC regression testing, no internal I/O is needed; all what's
required for testing algorithms is a core simulator like avrtest:

https://github.com/sprintersb/atest

https://github.com/sprintersb/atest?tab=readme-ov-file#running-the-avr-gcc-testsuite-using-the-avrtest-simulator

avrtest runs orders of magnitude faster than simulavr, however it
doesn't implement a GDB server, EEPROM or timers (none of which
is required for the GCC testsuite).

Apart from that, only being a core simulator, you can test for more
cores than covered by simulavr.  simulavr supports devices that cover
the following 8 multilib variants:

avr2
tiny-stack
avr25
avr25/tiny-stack
avr4
avr5
avr51
avr6

out of the 19 variants available in avr-gcc, like avr3, avr31,
avrtiny, and all the avrxmega[2-7] variants that can be used with
avrtest.

avrtest comes with board descriptions that cover a variety
of all the different cores.

avrtest board descriptions usually supply more RAM than the
actual device has, which allows more PASSes due to less
out-of-memory FAILs.


Johann


Re: [PATCH V4] Add warning options -W[no-]compare-distinct-pointer-types

2024-06-15 Thread Gerald Pfeifer
On Thu, 17 Aug 2023, Jose E. Marchesi via Gcc-patches wrote:
> [Changes from V3:
:
> LLVM supports an option -W[no-]compare-distinct-pointer-types that can
> be used in order to enable or disable the emission of such warnings.

It looks this went in, alas is not covered in gcc-14/changes.html?

Was that intentional? If not, would you mind considering adding something?

Gerald


Re: [PATCH] riscv: Allocate enough space to strcpy() string

2024-06-15 Thread Kito Cheng
Ok for gcc 14 too :)

Christoph Müllner  於 2024年6月15日 週六 15:14 寫道:

>
>
> On Sat, Jun 15, 2024, 08:25 Kito Cheng  wrote:
>
>> Oooops, thanks for catching that! It's LGTM:)
>>
>
> Also OK for the GCC 14 branch?
>
>
>> Christoph Müllner  於 2024年6月15日 週六 04:58 寫道:
>>
>>> I triggered an ICE on Ubuntu 24.04 when compiling code that uses
>>> function attributes. Looking into the sources shows that we have
>>> a systematic issue in the attribute handling code:
>>> * we determine the length with strlen() (excluding the terminating null)
>>> * we allocate a buffer with this length
>>> * we copy the original string using strcpy() (incl. the terminating null)
>>>
>>> To quote the man page of strcpy():
>>> "The programmer is responsible for allocating a  destination  buffer
>>> large  enough,  that  is, strlen(src)  + 1."
>>>
>>> The ICE looks like this:
>>>
>>> *** buffer overflow detected ***: terminated
>>> xtheadmempair_bench.c:14:1: internal compiler error: Aborted
>>>14 | {
>>>   | ^
>>> 0xaf3b99 crash_signal
>>> /home/ubuntu/src/gcc/scaleff/gcc/toplev.cc:319
>>> 0xe5b957 strcpy
>>> /usr/include/riscv64-linux-gnu/bits/string_fortified.h:79
>>> 0xe5b957 riscv_process_target_attr
>>>
>>> /home/ubuntu/src/gcc/scaleff/gcc/config/riscv/riscv-target-attr.cc:339
>>> 0xe5baaf riscv_process_target_attr
>>>
>>> /home/ubuntu/src/gcc/scaleff/gcc/config/riscv/riscv-target-attr.cc:314
>>> 0xe5bc5f riscv_option_valid_attribute_p(tree_node*, tree_node*,
>>> tree_node*, int)
>>>
>>> /home/ubuntu/src/gcc/scaleff/gcc/config/riscv/riscv-target-attr.cc:389
>>> 0x6a31e5 handle_target_attribute
>>> /home/ubuntu/src/gcc/scaleff/gcc/c-family/c-attribs.cc:5915
>>> 0x5d3a07 decl_attributes(tree_node**, tree_node*, int, tree_node*)
>>> /home/ubuntu/src/gcc/scaleff/gcc/attribs.cc:900
>>> 0x5db403 c_decl_attributes
>>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-decl.cc:5501
>>> 0x5e8965 start_function(c_declspecs*, c_declarator*, tree_node*)
>>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-decl.cc:10562
>>> 0x6318ed c_parser_declaration_or_fndef
>>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-parser.cc:2914
>>> 0x63a8ad c_parser_external_declaration
>>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-parser.cc:2048
>>> 0x63b219 c_parser_translation_unit
>>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-parser.cc:1902
>>> 0x63b219 c_parse_file()
>>> /home/ubuntu/src/gcc/scaleff/gcc/c/c-parser.cc:27277
>>> 0x68fec5 c_common_parse_file()
>>> /home/ubuntu/src/gcc/scaleff/gcc/c-family/c-opts.cc:1311
>>> Please submit a full bug report, with preprocessed source (by using
>>> -freport-bug).
>>> Please include the complete backtrace with any bug report.
>>> See  for instructions.
>>>
>>> gcc/ChangeLog:
>>>
>>> * config/riscv/riscv-target-attr.cc
>>> (riscv_target_attr_parser::parse_arch):
>>> Fix allocation size of buffer.
>>> (riscv_process_one_target_attr): Likewise.
>>> (riscv_process_target_attr): Likewise.
>>>
>>> Signed-off-by: Christoph Müllner 
>>> ---
>>>  gcc/config/riscv/riscv-target-attr.cc | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/gcc/config/riscv/riscv-target-attr.cc
>>> b/gcc/config/riscv/riscv-target-attr.cc
>>> index 1a73d69bf50..19eb7b06d54 100644
>>> --- a/gcc/config/riscv/riscv-target-attr.cc
>>> +++ b/gcc/config/riscv/riscv-target-attr.cc
>>> @@ -109,7 +109,7 @@ riscv_target_attr_parser::parse_arch (const char
>>> *str)
>>>  {
>>>/* Parsing the extension list like "+[,+]*".  */
>>>size_t len = strlen (str);
>>> -  std::unique_ptr buf (new char[len]);
>>> +  std::unique_ptr buf (new char[len+1]);
>>>char *str_to_check = buf.get ();
>>>strcpy (str_to_check, str);
>>>const char *token = strtok_r (str_to_check, ",", &str_to_check);
>>> @@ -247,7 +247,7 @@ riscv_process_one_target_attr (char *arg_str,
>>>return false;
>>>  }
>>>
>>> -  std::unique_ptr buf (new char[len]);
>>> +  std::unique_ptr buf (new char[len+1]);
>>>char *str_to_check = buf.get();
>>>strcpy (str_to_check, arg_str);
>>>
>>> @@ -334,7 +334,7 @@ riscv_process_target_attr (tree fndecl, tree args,
>>> location_t loc,
>>>return false;
>>>  }
>>>
>>> -  std::unique_ptr buf (new char[len]);
>>> +  std::unique_ptr buf (new char[len+1]);
>>>char *str_to_check = buf.get ();
>>>strcpy (str_to_check, TREE_STRING_POINTER (args));
>>>
>>> --
>>> 2.45.1
>>>
>>>


[wwwdocs,pushed] backends.html - Update weblinks to AVR simulators

2024-06-15 Thread Georg-Johann Lay

Applied this one:

backends.html - Update weblinks to AVR simulators.

diff --git a/htdocs/backends.html b/htdocs/backends.html
index bdaf29ad..1f7c85d7 100644
--- a/htdocs/backends.html
+++ b/htdocs/backends.html
@@ -120,9 +120,19 @@ visium |  B g  t s
 xtensa | C
 

-For AVR simulator, see https://gcc.gnu.org/ml/gcc/2003-10/msg00027.html";>
-https://gcc.gnu.org/ml/gcc/2003-10/msg00027.html.
+For AVR simulator, see
+  
+avrtest at
+  https://github.com/sprintersb/atest";
+>https://github.com/sprintersb/atest and
+  href="https://github.com/sprintersb/atest?tab=readme-ov-file#running-the-avr-gcc-testsuite-using-the-avrtest-simulator";
+>README: Running the avr-gcc Testsuite using the avrtest 
Simulator

+
+SimulAVR at https://www.nongnu.org/simulavr";
+  >https://www.nongnu.org/simulavr
+
+
+

 For ARC simulator, see https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb";>


Ping^2: [PATCH 0/3] Recover in-tree libiconv build support

2024-06-15 Thread Arsen Arsenović
Hi!

Another gentle ping on this patch series.  Could it be merged into
trunk?

TIA, have a lovely day!
-- 
Arsen Arsenović


signature.asc
Description: PGP signature


[PATCH v1] RISC-V: Add testcases for vector unsigned SAT_SUB form 2

2024-06-15 Thread pan2 . li
From: Pan Li 

The previous RISC-V backend .SAT_SUB enabling patch missed the form 2
testcases of vector modes.  Aka:

Form 2:
  #define DEF_VEC_SAT_U_SUB_FMT_2(T)   \
  void __attribute__((noinline))   \
  vec_sat_u_sub_##T##_fmt_2 (T *out, T *op_1, T *op_2, unsigned limit) \
  {\
unsigned i;\
for (i = 0; i < limit; i++)\
  {\
T x = op_1[i]; \
T y = op_2[i]; \
out[i] = (x - y) & (-(T)(x > y));  \
  }\
  }

This patch would like to make it up to ensure form 2 of .SAT_SUB vector
is covered.

Passed the rv64gcv rvv.exp tests.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-5.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-6.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-7.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-8.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-5.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-6.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-7.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-8.c: New test.

Signed-off-by: Pan Li 
---
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-5.c | 19 +
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-6.c | 20 +
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-7.c | 20 +
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-8.c | 20 +
 .../rvv/autovec/binop/vec_sat_u_sub-run-5.c   | 75 +++
 .../rvv/autovec/binop/vec_sat_u_sub-run-6.c   | 75 +++
 .../rvv/autovec/binop/vec_sat_u_sub-run-7.c   | 75 +++
 .../rvv/autovec/binop/vec_sat_u_sub-run-8.c   | 75 +++
 8 files changed, 379 insertions(+)
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-5.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-6.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-7.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-8.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-5.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-6.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-7.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-8.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-5.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-5.c
new file mode 100644
index 000..b05f3ad14ee
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-5.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize 
-fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "vec_sat_arith.h"
+
+/*
+** vec_sat_u_sub_uint8_t_fmt_2:
+** ...
+** vsetvli\s+[atx][0-9]+,\s*[atx][0-9]+,\s*e8,\s*m1,\s*ta,\s*ma
+** vle8\.v\s+v[0-9]+,\s*0\([atx][0-9]+\)
+** vle8\.v\s+v[0-9]+,\s*0\([atx][0-9]+\)
+** vssubu\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** ...
+*/
+DEF_VEC_SAT_U_SUB_FMT_2(uint8_t)
+
+/* { dg-final { scan-rtl-dump-times ".SAT_SUB " 4 "expand" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-6.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-6.c
new file mode 100644
index 000..251a5332350
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-6.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize 
-fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "vec_sat_arith.h"
+
+/*
+** vec_sat_u_sub_uint16_t_fmt_2:
+** ...
+** vsetvli\s+[atx][0-9]+,\s*[atx][0-9]+,\s*e16,\s*m1,\s*ta,\s*ma
+** ...
+** vle16\.v\s+v[0-9]+,\s*0\([atx][0-9]+\)
+** vle16\.v\s+v[0-9]+,\s*0\([atx][0-9]+\)
+** vssubu\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** ...
+*/
+DEF_VEC_SAT_U_SUB_FMT_2(uint16_t)
+
+/* { dg-final { scan-rtl-dump-times ".SAT_SUB " 4 "expand" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vec_sat_u_

Re: [PATCH v1] RISC-V: Add testcases for vector unsigned SAT_SUB form 2

2024-06-15 Thread ??????
lgtm








 --Reply to Message--
 On Sat, Jun 15, 2024 20:56 PM Li, Pan2

Re: [PATCH] libstdc++: Do not use memset _Hashtable buckets allocation

2024-06-15 Thread François Dumont

Here is the simplified patch then.

    libstdc++: Do not use memset in _Hashtable buckets allocation

    Using memset is incorrect if the __bucket_ptr type is non-trivial, or
    does not use an all-zero bit pattern for its null value.

    Replace the use of memset with std::__uinitialized_default_n to set the
    pointers to nullptr. Doing so and corresponding std::_Destroy_n 
when deallocating

    buckets.

    libstdc++-v3/ChangeLog:

    * include/bits/hashtable_policy.h
    (_Hashtable_alloc::_M_allocate_buckets): Do not use memset 
to zero

    out bucket pointers.
    (_Hashtable_alloc::_M_deallocate_buckets): Add destroy of 
buckets.


Tested under Linux x64, ok to commit ?

François

On 13/06/2024 20:58, Jonathan Wakely wrote:

On Thu, 13 Jun 2024 at 19:57, Jonathan Wakely  wrote:

On Thu, 13 Jun 2024 at 18:40, François Dumont  wrote:

Hi

Following your recent change here:

https://gcc.gnu.org/pipermail/libstdc++/2024-June/058998.html

I think we also need to fix the memset at bucket allocation level.

I did it trying also to be more fancy pointer friendly by running
__uninitialized_default_n_a on the allocator returned pointer rather
than on the __to_address result. I wonder if an __uninitialized_fill_n_a
would have been better ? Doing so I also had to call std::_Destroy on
deallocation. Let me know if it is too early.

You don't need the RAII guard. Initializing Alloc::pointer isn't
allowed to throw exceptions:

"An allocator type X shall meet the Cpp17CopyConstructible
requirements (Table 32). The XX::pointer,
XX::const_pointer, XX::void_pointer, and XX::const_void_pointer types
shall meet the Cpp17Nullable-
Pointer requirements (Table 36). No constructor, comparison operator
function, copy operation, move
operation, or swap operation on these pointer types shall exit via an
exception."

And you should not pass the allocator to the __uninitialized_xxx call,
nor the _Destroy call. We don't want to use the allocator's
construct/destroy members for those pointers. They are not container
elements.

I think either uninitialized_fill_n with nullptr or
__uninitialized_default_n is fine. Not the _a forms taking an
allocator though.

And I'd use _Destroy_n(_M_buckets, _M_bucket_count)



I also wonder if the compiler will be able to optimize it to a memset
call ? I'm interested to work on it if you confirm that it won't.

It will do whatever is fastest, which might be memset or might be
vectorized code to zero it out (which is probably what libc memset
does too).


libstdc++: Do not use memset in _Hashtable buckets allocation

Using memset is incorrect if the __bucket_ptr type is non-trivial, or
does not use an all-zero bit pattern for its null value.

Replace the use of memset with std::__uinitialized_default_n_a to set the
pointers to nullptr. Doing so and corresponding std::_Destroy when
deallocating
buckets.

libstdc++-v3/ChangeLog:

  * include/bits/hashtable_policy.h
  (_Hashtable_alloc::_M_allocate_buckets): Do not use memset to zero
  out bucket pointers.
  (_Hashtable_alloc::_M_deallocate_buckets): Add destroy of buckets.


I hope you won't ask for copy rights on the changelog entry :-)

Tested under Linux x64, ok to commit ?

Françoisdiff --git a/libstdc++-v3/include/bits/hashtable_policy.h 
b/libstdc++-v3/include/bits/hashtable_policy.h
index 26def24f24e..510108a1a6f 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -33,8 +33,9 @@
 
 #include// for std::tuple, std::forward_as_tuple
 #include  // for __is_fast_hash
-#include  // for std::min, std::is_permutation.
+#include  // for std::min, std::is_permutation
 #include  // for std::pair
+#include  // for __uninitialized_default_n
 #include // for __gnu_cxx::__aligned_buffer
 #include   // for std::__alloc_rebind
 #include // for __gnu_cxx::__int_traits
@@ -2069,11 +2070,9 @@ namespace __detail
 -> __buckets_ptr
 {
   __buckets_alloc_type __alloc(_M_node_allocator());
-
   auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
-  __buckets_ptr __p = std::__to_address(__ptr);
-  __builtin_memset(__p, 0, __bkt_count * sizeof(__node_base_ptr));
-  return __p;
+  std::__uninitialized_default_n(__ptr, __bkt_count);
+  return std::__to_address(__ptr);
 }
 
   template
@@ -2085,6 +2084,7 @@ namespace __detail
   typedef typename __buckets_alloc_traits::pointer _Ptr;
   auto __ptr = std::pointer_traits<_Ptr>::pointer_to(*__bkts);
   __buckets_alloc_type __alloc(_M_node_allocator());
+  std::_Destroy_n(__ptr, __bkt_count);
   __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
 }
 


[PATCH] LoongArch: Tweak IOR rtx_cost for bstrins

2024-06-15 Thread Xi Ruoyao
Consider

c &= 0xfff;
a &= ~0xfff;
b &= ~0xfff;
a |= c;
b |= c;

This can be done with 2 bstrins instructions.  But we need to recognize
it in loongarch_rtx_costs or the compiler will not propagate "c & 0xfff"
forward.

gcc/ChangeLog:

* config/loongarch/loongarch.cc:
(loongarch_use_bstrins_for_ior_with_mask): Split the main logic
into ...
(loongarch_use_bstrins_for_ior_with_mask_1): ... here.
(loongarch_rtx_costs): Special case for IOR those can be
implemented with bstrins.

gcc/testsuite/ChangeLog;

* gcc.target/loongarch/bstrins-3.c: New test.
---

Bootstrapped and regtested on loongarch64-linux-gnu.  Ok for trunk?

 gcc/config/loongarch/loongarch.cc | 73 ++-
 .../gcc.target/loongarch/bstrins-3.c  | 16 
 2 files changed, 72 insertions(+), 17 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/bstrins-3.c

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index 6ec3ee62502..23cd943d848 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -3681,6 +3681,27 @@ loongarch_set_reg_reg_piece_cost (machine_mode mode, 
unsigned int units)
   return COSTS_N_INSNS ((GET_MODE_SIZE (mode) + units - 1) / units);
 }
 
+static int
+loongarch_use_bstrins_for_ior_with_mask_1 (machine_mode mode,
+  unsigned HOST_WIDE_INT mask1,
+  unsigned HOST_WIDE_INT mask2)
+{
+  if (mask1 != ~mask2 || !mask1 || !mask2)
+return 0;
+
+  /* Try to avoid a right-shift.  */
+  if (low_bitmask_len (mode, mask1) != -1)
+return -1;
+
+  if (low_bitmask_len (mode, mask2 >> (ffs_hwi (mask2) - 1)) != -1)
+return 1;
+
+  if (low_bitmask_len (mode, mask1 >> (ffs_hwi (mask1) - 1)) != -1)
+return -1;
+
+  return 0;
+}
+
 /* Return the cost of moving between two registers of mode MODE.  */
 
 static int
@@ -3812,6 +3833,38 @@ loongarch_rtx_costs (rtx x, machine_mode mode, int 
outer_code,
   /* Fall through.  */
 
 case IOR:
+  {
+   rtx op0 = XEXP (x, 0), op1 = XEXP (x, 1);
+   if (GET_CODE (op0) == AND && GET_CODE (op1) == AND
+   && (mode == SImode || (TARGET_64BIT && mode == DImode)))
+ {
+   rtx rtx_mask0 = XEXP (op0, 1), rtx_mask1 = XEXP (op1, 1);
+   if (CONST_INT_P (rtx_mask0) && CONST_INT_P (rtx_mask1))
+ {
+   unsigned HOST_WIDE_INT mask0 = UINTVAL (rtx_mask0);
+   unsigned HOST_WIDE_INT mask1 = UINTVAL (rtx_mask1);
+   if (loongarch_use_bstrins_for_ior_with_mask_1 (mode,
+  mask0,
+  mask1))
+ {
+   /* A bstrins instruction */
+   *total = COSTS_N_INSNS (1);
+
+   /* A srai instruction */
+   if (low_bitmask_len (mode, mask0) == -1
+   && low_bitmask_len (mode, mask1) == -1)
+ *total += COSTS_N_INSNS (1);
+
+   for (int i = 0; i < 2; i++)
+ *total += set_src_cost (XEXP (op0, i), mode, speed);
+
+   return true;
+ }
+ }
+ }
+  }
+
+  /* Fall through.  */
 case XOR:
   /* Double-word operations use two single-word operations.  */
   *total = loongarch_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (2),
@@ -5796,23 +5849,9 @@ bool loongarch_pre_reload_split (void)
 int
 loongarch_use_bstrins_for_ior_with_mask (machine_mode mode, rtx *op)
 {
-  unsigned HOST_WIDE_INT mask1 = UINTVAL (op[2]);
-  unsigned HOST_WIDE_INT mask2 = UINTVAL (op[4]);
-
-  if (mask1 != ~mask2 || !mask1 || !mask2)
-return 0;
-
-  /* Try to avoid a right-shift.  */
-  if (low_bitmask_len (mode, mask1) != -1)
-return -1;
-
-  if (low_bitmask_len (mode, mask2 >> (ffs_hwi (mask2) - 1)) != -1)
-return 1;
-
-  if (low_bitmask_len (mode, mask1 >> (ffs_hwi (mask1) - 1)) != -1)
-return -1;
-
-  return 0;
+  return loongarch_use_bstrins_for_ior_with_mask_1 (mode,
+   UINTVAL (op[2]),
+   UINTVAL (op[4]));
 }
 
 /* Rewrite a MEM for simple load/store under -mexplicit-relocs=auto
diff --git a/gcc/testsuite/gcc.target/loongarch/bstrins-3.c 
b/gcc/testsuite/gcc.target/loongarch/bstrins-3.c
new file mode 100644
index 000..13762bdef42
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/bstrins-3.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-final" } */
+/* { dg-final { scan-rtl-dump-times "insv\[sd\]i" 2 "final" } } */
+
+struct X {
+  long a, b;
+};
+
+struct X
+test (long a, long b, long c)
+{
+  c &= 0xfff;
+  a &= ~0xfff;
+  b &= ~0xfff;
+  return (struct X){.a = a | c, .b = b | c}; 
+}
-- 
2.45.2

[PATCH] LoongArch: Only transform move/move/bstrins to srai/bstrins when -Os

2024-06-15 Thread Xi Ruoyao
The first form has a lower latency (due to the special handling of
"move" in LA464 and LA664) despite it's longer.

gcc/ChangeLog:

* config/loongarch/loongarch.md (define_peephole2): Require
optimize_insn_for_size_p () for move/move/bstrins =>
srai/bstrins transform.
---

Bootstrapped and regtested on loongarch64-linux-gnu.  Ok for trunk?

 gcc/config/loongarch/loongarch.md | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.md 
b/gcc/config/loongarch/loongarch.md
index 25c1d323ba0..e4434c3bd4e 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -1617,20 +1617,23 @@ (define_insn_and_split "*bstrins__for_ior_mask"
   })
 
 ;; We always avoid the shift operation in bstrins__for_ior_mask
-;; if possible, but the result may be sub-optimal when one of the masks
+;; if possible, but the result may be larger when one of the masks
 ;; is (1 << N) - 1 and one of the src register is the dest register.
 ;; For example:
 ;; movet0, a0
 ;; movea0, a1
 ;; bstrins.d   a0, t0, 42, 0
 ;; ret
-;; using a shift operation would be better:
+;; using a shift operation would be smaller:
 ;; srai.d  t0, a1, 43
 ;; bstrins.d   a0, t0, 63, 43
 ;; ret
 ;; unfortunately we cannot figure it out in split1: before reload we cannot
 ;; know if the dest register is one of the src register.  Fix it up in
 ;; peephole2.
+;;
+;; Note that the first form has a lower latency so this should only be
+;; done when optimizing for size.
 (define_peephole2
   [(set (match_operand:GPR 0 "register_operand")
(match_operand:GPR 1 "register_operand"))
@@ -1639,7 +1642,7 @@ (define_peephole2
  (match_operand:SI 3 "const_int_operand")
  (const_int 0))
(match_dup 0))]
-  "peep2_reg_dead_p (3, operands[0])"
+  "peep2_reg_dead_p (3, operands[0]) && optimize_insn_for_size_p ()"
   [(const_int 0)]
   {
 int len = GET_MODE_BITSIZE (mode) - INTVAL (operands[3]);
-- 
2.45.2



Re: [PATCH] LoongArch: Tweak IOR rtx_cost for bstrins

2024-06-15 Thread Xi Ruoyao
On Sat, 2024-06-15 at 21:44 +0800, Xi Ruoyao wrote:
> +     for (int i = 0; i < 2; i++)
> +   *total += set_src_cost (XEXP (op0, i), mode,
> speed);

Oops this is wrong.  I need to fix this and regtest again.

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


Re: [C PATCH, v3] Fix for redeclared enumerator initialized with different type [PR115109]

2024-06-15 Thread Martin Uecker


The patch fails on arm because the tests make assumptions
about enums that are not true everywhere. Should we just 
limit the tests to x86?

Martin

Am Montag, dem 03.06.2024 um 17:37 + schrieb Joseph Myers:
> On Sat, 1 Jun 2024, Martin Uecker wrote:
> 
> > This is a new version of the patch.  I changed the overflow warning to
> > an error and added your other example to the test case.
> > 
> > Bootstrapped and regression tested on x86_64.
> > 
> > 
> > c23: Fix for redeclared enumerator initialized with different type 
> > [PR115109]
> > 
> > c23 specifies that the type of a redeclared enumerator is the one of the
> > previous declaration.  Convert initializers with different type 
> > accordingly
> > and emit an error when the value does not fit.
> > 
> > 2024-06-01 Martin Uecker  
> > 
> > PR c/115109
> > 
> > gcc/c/
> > * c-decl.cc (build_enumerator): When redeclaring an
> > enumerator convert value to previous type.  For redeclared
> > enumerators use underlying type for computing the next value.
> > 
> > gcc/testsuite/
> > * gcc.dg/pr115109.c: New test.
> > * gcc.dg/c23-tag-enum-6.c: New test.
> > * gcc.dg/c23-tag-enum-7.c: New test.
> 
> OK.
> 



[PATCH v2] LoongArch: Tweak IOR rtx_cost for bstrins

2024-06-15 Thread Xi Ruoyao
Consider

c &= 0xfff;
a &= ~0xfff;
b &= ~0xfff;
a |= c;
b |= c;

This can be done with 2 bstrins instructions.  But we need to recognize
it in loongarch_rtx_costs or the compiler will not propagate "c & 0xfff"
forward.

gcc/ChangeLog:

* config/loongarch/loongarch.cc:
(loongarch_use_bstrins_for_ior_with_mask): Split the main logic
into ...
(loongarch_use_bstrins_for_ior_with_mask_1): ... here.
(loongarch_rtx_costs): Special case for IOR those can be
implemented with bstrins.

gcc/testsuite/ChangeLog;

* gcc.target/loongarch/bstrins-3.c: New test.
---

Bootstrapped and regtested on loongarch64-linux-gnu.  Ok for trunk?

 gcc/config/loongarch/loongarch.cc | 73 ++-
 .../gcc.target/loongarch/bstrins-3.c  | 16 
 2 files changed, 72 insertions(+), 17 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/bstrins-3.c

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index 6ec3ee62502..256b76d044b 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -3681,6 +3681,27 @@ loongarch_set_reg_reg_piece_cost (machine_mode mode, 
unsigned int units)
   return COSTS_N_INSNS ((GET_MODE_SIZE (mode) + units - 1) / units);
 }
 
+static int
+loongarch_use_bstrins_for_ior_with_mask_1 (machine_mode mode,
+  unsigned HOST_WIDE_INT mask1,
+  unsigned HOST_WIDE_INT mask2)
+{
+  if (mask1 != ~mask2 || !mask1 || !mask2)
+return 0;
+
+  /* Try to avoid a right-shift.  */
+  if (low_bitmask_len (mode, mask1) != -1)
+return -1;
+
+  if (low_bitmask_len (mode, mask2 >> (ffs_hwi (mask2) - 1)) != -1)
+return 1;
+
+  if (low_bitmask_len (mode, mask1 >> (ffs_hwi (mask1) - 1)) != -1)
+return -1;
+
+  return 0;
+}
+
 /* Return the cost of moving between two registers of mode MODE.  */
 
 static int
@@ -3812,6 +3833,38 @@ loongarch_rtx_costs (rtx x, machine_mode mode, int 
outer_code,
   /* Fall through.  */
 
 case IOR:
+  {
+   rtx op[2] = {XEXP (x, 0), XEXP (x, 1)};
+   if (GET_CODE (op[0]) == AND && GET_CODE (op[1]) == AND
+   && (mode == SImode || (TARGET_64BIT && mode == DImode)))
+ {
+   rtx rtx_mask0 = XEXP (op[0], 1), rtx_mask1 = XEXP (op[1], 1);
+   if (CONST_INT_P (rtx_mask0) && CONST_INT_P (rtx_mask1))
+ {
+   unsigned HOST_WIDE_INT mask0 = UINTVAL (rtx_mask0);
+   unsigned HOST_WIDE_INT mask1 = UINTVAL (rtx_mask1);
+   if (loongarch_use_bstrins_for_ior_with_mask_1 (mode,
+  mask0,
+  mask1))
+ {
+   /* A bstrins instruction */
+   *total = COSTS_N_INSNS (1);
+
+   /* A srai instruction */
+   if (low_bitmask_len (mode, mask0) == -1
+   && low_bitmask_len (mode, mask1) == -1)
+ *total += COSTS_N_INSNS (1);
+
+   for (int i = 0; i < 2; i++)
+ *total += set_src_cost (XEXP (op[i], 0), mode, speed);
+
+   return true;
+ }
+ }
+ }
+  }
+
+  /* Fall through.  */
 case XOR:
   /* Double-word operations use two single-word operations.  */
   *total = loongarch_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (2),
@@ -5796,23 +5849,9 @@ bool loongarch_pre_reload_split (void)
 int
 loongarch_use_bstrins_for_ior_with_mask (machine_mode mode, rtx *op)
 {
-  unsigned HOST_WIDE_INT mask1 = UINTVAL (op[2]);
-  unsigned HOST_WIDE_INT mask2 = UINTVAL (op[4]);
-
-  if (mask1 != ~mask2 || !mask1 || !mask2)
-return 0;
-
-  /* Try to avoid a right-shift.  */
-  if (low_bitmask_len (mode, mask1) != -1)
-return -1;
-
-  if (low_bitmask_len (mode, mask2 >> (ffs_hwi (mask2) - 1)) != -1)
-return 1;
-
-  if (low_bitmask_len (mode, mask1 >> (ffs_hwi (mask1) - 1)) != -1)
-return -1;
-
-  return 0;
+  return loongarch_use_bstrins_for_ior_with_mask_1 (mode,
+   UINTVAL (op[2]),
+   UINTVAL (op[4]));
 }
 
 /* Rewrite a MEM for simple load/store under -mexplicit-relocs=auto
diff --git a/gcc/testsuite/gcc.target/loongarch/bstrins-3.c 
b/gcc/testsuite/gcc.target/loongarch/bstrins-3.c
new file mode 100644
index 000..13762bdef42
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/bstrins-3.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-final" } */
+/* { dg-final { scan-rtl-dump-times "insv\[sd\]i" 2 "final" } } */
+
+struct X {
+  long a, b;
+};
+
+struct X
+test (long a, long b, long c)
+{
+  c &= 0xfff;
+  a &= ~0xfff;
+  b &= ~0xfff;
+  return (struct X){.a = a | c, .b = b | c}; 
+}
-- 

Re: [PATCH v1] RISC-V: Add testcases for vector unsigned SAT_SUB form 2

2024-06-15 Thread Jeff Law




On 6/15/24 6:56 AM, pan2...@intel.com wrote:

From: Pan Li 

The previous RISC-V backend .SAT_SUB enabling patch missed the form 2
testcases of vector modes.  Aka:

Form 2:
   #define DEF_VEC_SAT_U_SUB_FMT_2(T)   \
   void __attribute__((noinline))   \
   vec_sat_u_sub_##T##_fmt_2 (T *out, T *op_1, T *op_2, unsigned limit) \
   {\
 unsigned i;\
 for (i = 0; i < limit; i++)\
   {\
 T x = op_1[i]; \
 T y = op_2[i]; \
 out[i] = (x - y) & (-(T)(x > y));  \
   }\
   }

This patch would like to make it up to ensure form 2 of .SAT_SUB vector
is covered.

Passed the rv64gcv rvv.exp tests.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-5.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-6.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-7.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-8.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-5.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-6.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-7.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-8.c: New test.

OK
jeff



Re: [PATCH] DOCUMENTATION_ROOT_URL vs. release branches [PR114738]

2024-06-15 Thread Gerald Pfeifer
On Tue, 23 Apr 2024, David Malcolm wrote:
> My hope is that the URL suffixes don't change: we shouldn't be adding
> new command-line options on the release branches, and I'd hope that
> texinfo doesn't change the generated anchors from run to run.

Already before this thread, but definitely now, I started to wonder 
whether we shouldn't fundamentally change our approach on online 
documentation for release branches.

My proposal is to have only one version per release branch online,
that is, not https://gcc.gnu.org/onlinedocs/gcc-14.1.0 and
https://gcc.gnu.org/onlinedocs/gcc-14.2.0 and so forth, rather just

  https://gcc.gnu.org/onlinedocs/gcc-14

There should be *very* few user visible changes such as new options or 
substantially different behaviors on release branches - pretty much by 
definition.

So why not have one version of the documentation per release branch where 
users of 14.1 get documentation fixes/improvements made for later in the
branch?

And it would vastly simplify things in terms of creating docs - simply 
build them once a day, no changes for point releases... (and much, much
less duplication).

What do you think?

Gerald


Re: [PATCH] DOCUMENTATION_ROOT_URL vs. release branches [PR114738]

2024-06-15 Thread Jakub Jelinek
On Sat, Jun 15, 2024 at 09:47:04PM +0200, Gerald Pfeifer wrote:
> There should be *very* few user visible changes such as new options or 
> substantially different behaviors on release branches - pretty much by 
> definition.

In reality there are tons of changes, people add new options even on release
branches all the time.

So I think it is very useful to have separate documentation for the separate
releases.

Jakub



Re: [PATCH] libstdc++: Fix build for AVR [PR115481, PR111639]

2024-06-15 Thread Detlef Vollmann

On 6/15/24 10:30, Georg-Johann Lay wrote:

Am 14.06.24 um 21:11 schrieb Detlef Vollmann:
I actually plan anyway to run a test with the built libstdc++ on 
simulavr.



As an aside, simulavr tries to simulate an exact match of the hardware
including internal I/O like timers, IRQs, etc.

For GCC regression testing, no internal I/O is needed; all what's
required for testing algorithms is a core simulator like avrtest:

https://github.com/sprintersb/atest

https://github.com/sprintersb/atest?tab=readme-ov-file#running-the-avr-gcc-testsuite-using-the-avrtest-simulator

avrtest runs orders of magnitude faster than simulavr, however it
doesn't implement a GDB server, EEPROM or timers (none of which
is required for the GCC testsuite).


Thanks for the pointer.


Apart from that, only being a core simulator, you can test for more
cores than covered by simulavr.  simulavr supports devices that cover
the following 8 multilib variants:

avr2
tiny-stack
avr25
avr25/tiny-stack
avr4
avr5
avr51
avr6

out of the 19 variants available in avr-gcc, like avr3, avr31,
avrtiny, and all the avrxmega[2-7] variants that can be used with
avrtest.


avr-gcc 15 actually has 57 multilib variants (long-double32,
double64 and short-calls versions).

avr-libc 2.2.0 uses -print-multi-lib to build them all,
avr-libc 2.0.0 has only 17 variants hardcoded.

But right now I'm fighting against an ICE in cmath, i.e. so far
any tests of cmath fail...

I'll investigate this tomorrow and decide then what I'll do...

  Detlef



Re: [PATCH v3] gcc, libcpp: Add warning switch for "#pragma once in main file" [PR89808]

2024-06-15 Thread Ken Matsui
On Thu, Jun 13, 2024 at 7:44 AM Jason Merrill  wrote:
>
> On 6/13/24 10:31, Ken Matsui wrote:
> > This patch adds a warning switch for "#pragma once in main file".  The
> > warning option name is Wpragma-once-outside-header, which is the same
> > as Clang.
> >
> >   PR preprocessor/89808
> >
> > gcc/c-family/ChangeLog:
> >
> >   * c.opt (Wpragma_once_outside_header): Define new option.
> >
> > gcc/ChangeLog:
> >
> >   * doc/invoke.texi (Warning Options): Document
> >   -Wno-pragma-once-outside-header.
> >
> > libcpp/ChangeLog:
> >
> >   * include/cpplib.h (struct cpp_options): Define
> >   cpp_warn_pragma_once_outside_header.
>
> This bit-field should be unneeded now, along with the uses of it.

Thank you!  I'll update the patch shortly.

>
> >   (cpp_warning_reason): Define CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER.
> >   * directives.cc (do_pragma_once): Use
> >   cpp_warn_pragma_once_outside_header and
> >   CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER.
> >   * init.cc (cpp_create_reader): Handle
> >   cpp_warn_pragma_once_outside_header.
> >
> > gcc/testsuite/ChangeLog:
> >
> >   * g++.dg/warn/Wno-pragma-once-outside-header.C: New test.
> >   * g++.dg/warn/Wpragma-once-outside-header.C: New test.
> >
> > Signed-off-by: Ken Matsui 
> > ---
> >   gcc/c-family/c.opt |  4 
> >   gcc/doc/invoke.texi| 10 --
> >   .../g++.dg/warn/Wno-pragma-once-outside-header.C   |  5 +
> >   .../g++.dg/warn/Wpragma-once-outside-header.C  |  6 ++
> >   libcpp/directives.cc   |  9 ++---
> >   libcpp/include/cpplib.h|  7 ++-
> >   libcpp/init.cc |  1 +
> >   7 files changed, 36 insertions(+), 6 deletions(-)
> >   create mode 100644 
> > gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
> >   create mode 100644 gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
> >
> > diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> > index 403abc1f26e..3439f36fe45 100644
> > --- a/gcc/c-family/c.opt
> > +++ b/gcc/c-family/c.opt
> > @@ -1188,6 +1188,10 @@ Wpragmas
> >   C ObjC C++ ObjC++ Var(warn_pragmas) Init(1) Warning
> >   Warn about misuses of pragmas.
> >
> > +Wpragma-once-outside-header
> > +C ObjC C++ ObjC++ Var(warn_pragma_once_outside_header) 
> > CppReason(CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER) Init(1) Warning
> > +Warn about #pragma once outside of a header.
> > +
> >   Wprio-ctor-dtor
> >   C ObjC C++ ObjC++ Var(warn_prio_ctor_dtor) Init(1) Warning
> >   Warn if constructor or destructors with priorities from 0 to 100 are used.
> > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> > index 9456ced468a..c7f17ca9eb7 100644
> > --- a/gcc/doc/invoke.texi
> > +++ b/gcc/doc/invoke.texi
> > @@ -391,8 +391,8 @@ Objective-C and Objective-C++ Dialects}.
> >   -Wpacked  -Wno-packed-bitfield-compat  -Wpacked-not-aligned  -Wpadded
> >   -Wparentheses  -Wno-pedantic-ms-format
> >   -Wpointer-arith  -Wno-pointer-compare  -Wno-pointer-to-int-cast
> > --Wno-pragmas  -Wno-prio-ctor-dtor  -Wredundant-decls
> > --Wrestrict  -Wno-return-local-addr  -Wreturn-type
> > +-Wno-pragmas  -Wno-pragma-once-outside-header  -Wno-prio-ctor-dtor
> > +-Wredundant-decls  -Wrestrict  -Wno-return-local-addr  -Wreturn-type
> >   -Wno-scalar-storage-order  -Wsequence-point
> >   -Wshadow  -Wshadow=global  -Wshadow=local  -Wshadow=compatible-local
> >   -Wno-shadow-ivar
> > @@ -7983,6 +7983,12 @@ Do not warn about misuses of pragmas, such as 
> > incorrect parameters,
> >   invalid syntax, or conflicts between pragmas.  See also
> >   @option{-Wunknown-pragmas}.
> >
> > +@opindex Wno-pragma-once-outside-header
> > +@opindex Wpragma-once-outside-header
> > +@item -Wno-pragma-once-outside-header
> > +Do not warn when @code{#pragma once} is used in a file that is not a header
> > +file, such as a main file.
> > +
> >   @opindex Wno-prio-ctor-dtor
> >   @opindex Wprio-ctor-dtor
> >   @item -Wno-prio-ctor-dtor
> > diff --git a/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C 
> > b/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
> > new file mode 100644
> > index 000..b5be4d25a9d
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
> > @@ -0,0 +1,5 @@
> > +// { dg-do assemble  }
> > +// { dg-options "-Wno-pragma-once-outside-header" }
> > +
> > +#pragma once
> > +int main() {}
> > diff --git a/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C 
> > b/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
> > new file mode 100644
> > index 000..324b0638c3f
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
> > @@ -0,0 +1,6 @@
> > +// { dg-do assemble  }
> > +// { dg-options "-Werror=pragma-once-outside-header" }
> > +// { dg-message "some warnings being treated as errors" "" {target 
> > "*-*-*"} 0 }
>

[PATCH v4] gcc, libcpp: Add warning switch for "#pragma once in main file" [PR89808]

2024-06-15 Thread Ken Matsui
This patch adds a warning switch for "#pragma once in main file".  The
warning option name is Wpragma-once-outside-header, which is the same
as Clang provides.

PR preprocessor/89808

gcc/c-family/ChangeLog:

* c.opt (Wpragma_once_outside_header): Define new option.
* c.opt.urls: Regenerate.

gcc/ChangeLog:

* doc/invoke.texi (Warning Options): Document
-Wno-pragma-once-outside-header.

libcpp/ChangeLog:

* include/cpplib.h (cpp_warning_reason): Define
CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER.
* directives.cc (do_pragma_once): Use
CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wno-pragma-once-outside-header.C: New test.
* g++.dg/warn/Wpragma-once-outside-header.C: New test.

Signed-off-by: Ken Matsui 
---
 gcc/c-family/c.opt |  4 
 gcc/c-family/c.opt.urls|  3 +++
 gcc/doc/invoke.texi| 10 --
 .../g++.dg/warn/Wno-pragma-once-outside-header.C   |  5 +
 .../g++.dg/warn/Wpragma-once-outside-header.C  |  6 ++
 libcpp/directives.cc   |  3 ++-
 libcpp/include/cpplib.h|  3 ++-
 7 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
 create mode 100644 gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 403abc1f26e..3439f36fe45 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1188,6 +1188,10 @@ Wpragmas
 C ObjC C++ ObjC++ Var(warn_pragmas) Init(1) Warning
 Warn about misuses of pragmas.
 
+Wpragma-once-outside-header
+C ObjC C++ ObjC++ Var(warn_pragma_once_outside_header) 
CppReason(CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER) Init(1) Warning
+Warn about #pragma once outside of a header.
+
 Wprio-ctor-dtor
 C ObjC C++ ObjC++ Var(warn_prio_ctor_dtor) Init(1) Warning
 Warn if constructor or destructors with priorities from 0 to 100 are used.
diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls
index dd455d7c0dc..778ca08be2e 100644
--- a/gcc/c-family/c.opt.urls
+++ b/gcc/c-family/c.opt.urls
@@ -672,6 +672,9 @@ 
UrlSuffix(gcc/Warning-Options.html#index-Wno-pointer-to-int-cast)
 Wpragmas
 UrlSuffix(gcc/Warning-Options.html#index-Wno-pragmas)
 
+Wpragma-once-outside-header
+UrlSuffix(gcc/Warning-Options.html#index-Wno-pragma-once-outside-header)
+
 Wprio-ctor-dtor
 UrlSuffix(gcc/Warning-Options.html#index-Wno-prio-ctor-dtor)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 9456ced468a..c7f17ca9eb7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -391,8 +391,8 @@ Objective-C and Objective-C++ Dialects}.
 -Wpacked  -Wno-packed-bitfield-compat  -Wpacked-not-aligned  -Wpadded
 -Wparentheses  -Wno-pedantic-ms-format
 -Wpointer-arith  -Wno-pointer-compare  -Wno-pointer-to-int-cast
--Wno-pragmas  -Wno-prio-ctor-dtor  -Wredundant-decls
--Wrestrict  -Wno-return-local-addr  -Wreturn-type
+-Wno-pragmas  -Wno-pragma-once-outside-header  -Wno-prio-ctor-dtor
+-Wredundant-decls  -Wrestrict  -Wno-return-local-addr  -Wreturn-type
 -Wno-scalar-storage-order  -Wsequence-point
 -Wshadow  -Wshadow=global  -Wshadow=local  -Wshadow=compatible-local
 -Wno-shadow-ivar
@@ -7983,6 +7983,12 @@ Do not warn about misuses of pragmas, such as incorrect 
parameters,
 invalid syntax, or conflicts between pragmas.  See also
 @option{-Wunknown-pragmas}.
 
+@opindex Wno-pragma-once-outside-header
+@opindex Wpragma-once-outside-header
+@item -Wno-pragma-once-outside-header
+Do not warn when @code{#pragma once} is used in a file that is not a header
+file, such as a main file.
+
 @opindex Wno-prio-ctor-dtor
 @opindex Wprio-ctor-dtor
 @item -Wno-prio-ctor-dtor
diff --git a/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C 
b/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
new file mode 100644
index 000..b5be4d25a9d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
@@ -0,0 +1,5 @@
+// { dg-do assemble  }
+// { dg-options "-Wno-pragma-once-outside-header" }
+
+#pragma once
+int main() {}
diff --git a/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C 
b/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
new file mode 100644
index 000..324b0638c3f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
@@ -0,0 +1,6 @@
+// { dg-do assemble  }
+// { dg-options "-Werror=pragma-once-outside-header" }
+// { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 }
+
+#pragma once  // { dg-error "#pragma once in main file" }
+int main() {}
diff --git a/libcpp/directives.cc b/libcpp/directives.cc
index 479f8c716e8..467efdf637d 100644
--- a/libcpp/directives.cc
+++ b/libcpp/directives.cc
@@ -1589,7 +1589,8 @@ static void
 do_pragma_once (cpp_reader *pfile)
 {
   if (_cpp_in_main_source_f

Re: [PATCH v3 1/3] diagnostics: Enable escape sequence processing on windows consoles

2024-06-15 Thread Jonathan Yong

On 6/3/24 17:07, Peter Damianov wrote:

Since windows 10 release v1511, the windows console has had support for VT100
escape sequences. We should try to enable this, and utilize it where possible.


Thank you. Patches look good to me, pushed to master branch.



[PATCH] c++: Simplify uses of LAMBDA_EXPR_EXTRA_SCOPE

2024-06-15 Thread Nathaniel Shead
No functional change intended; OK for trunk?

-- >8 --

I noticed there already exists a getter to get the scope of a lambda
from its type directly rather than needing to go via
CLASSTYPE_LAMBDA_EXPR, we may as well use it.

gcc/cp/ChangeLog:

* module.cc (trees_out::get_merge_kind): Use
LAMBDA_TYPE_EXTRA_SCOPE instead of LAMBDA_EXPR_EXTRA_SCOPE.
(trees_out::key_mergeable): Likewise.

Signed-off-by: Nathaniel Shead 
---
 gcc/cp/module.cc | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index ea7ad0c1f29..6d6044af199 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -10686,9 +10686,7 @@ trees_out::get_merge_kind (tree decl, depset *dep)
   g++.dg/modules/lambda-6_a.C.  */
if (DECL_IMPLICIT_TYPEDEF_P (STRIP_TEMPLATE (decl))
&& LAMBDA_TYPE_P (TREE_TYPE (decl)))
- if (tree scope
- = LAMBDA_EXPR_EXTRA_SCOPE (CLASSTYPE_LAMBDA_EXPR
-(TREE_TYPE (decl
+ if (tree scope = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl)))
{
  /* Lambdas attached to fields are keyed to its class.  */
  if (TREE_CODE (scope) == FIELD_DECL)
@@ -10993,8 +10991,7 @@ trees_out::key_mergeable (int tag, merge_kind mk, tree 
decl, tree inner,
case MK_keyed:
  {
gcc_checking_assert (LAMBDA_TYPE_P (TREE_TYPE (inner)));
-   tree scope = LAMBDA_EXPR_EXTRA_SCOPE (CLASSTYPE_LAMBDA_EXPR
- (TREE_TYPE (inner)));
+   tree scope = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (inner));
gcc_checking_assert (TREE_CODE (scope) == VAR_DECL
 || TREE_CODE (scope) == FIELD_DECL
 || TREE_CODE (scope) == PARM_DECL
-- 
2.43.2



[PATCH] c++/modules: Ensure deduction guides are always reachable [PR115231]

2024-06-15 Thread Nathaniel Shead
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

This probably isn't the most efficient approach, since we need to do
name lookup to find deduction guides for a type which will also
potentially do a bunch of pointless lazy loading from imported modules,
but I wasn't able to work out a better approach without completely
reworking how deduction guides are stored and represented.  This way at
least is correct (I believe), and we can maybe revisit this in the
future.

-- >8 --

Deduction guides are represented as 'normal' functions currently, and
have no special handling in modules.  However, this causes some issues;
by [temp.deduct.guide] a deduction guide is not found by normal name
lookup and instead all reachable deduction guides for a class template
should be considered, but this does not happen currently.

To solve this, this patch ensures that all deduction guides are
considered exported to ensure that they are always visible to importers
if they are reachable.  Another alternative here would be to add a new
kind of "all reachable" flag to name lookup, but that is complicated by
some difficulties in handling GM entities; this may be a better way to
go if more kinds of entities end up needing this handling, however.

Another issue here is that because deduction guides are "unrelated"
functions, they will usually get discarded from the GMF, so this patch
ensures that when finding dependencies, GMF deduction guides will also
have bindings created.  We do this in find_dependencies so that we don't
unnecessarily create bindings for GMF deduction guides that are never
reached; for consistency we do this for *all* deduction guides, not just
GM ones.

Finally, when merging deduction guides from multiple modules, the name
lookup code may now return two-dimensional overload sets, so update
callers to match.

As a small drive-by improvement this patch also updates the error pretty
printing code to add a space before the '->' when printing a deduction
guide, so we get 'S(int) -> S' instead of 'S(int)-> S'.

PR c++/115231

gcc/cp/ChangeLog:

* error.cc (dump_function_decl): Add a space before '->' when
printing deduction guides.
* module.cc (depset::hash::add_binding_entity): Skip deduction
guides here.
(depset::hash::add_deduction_guides): New.
(depset::hash::find_dependencies): Add deduction guide
dependencies for a class template.
(module_state::write_cluster): Always consider deduction guides
as exported.
* pt.cc (deduction_guides_for): Use 'lkp_iterator' instead of
'ovl_iterator'.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dguide-1_a.C: New test.
* g++.dg/modules/dguide-1_b.C: New test.
* g++.dg/modules/dguide-2_a.C: New test.
* g++.dg/modules/dguide-2_b.C: New test.
* g++.dg/modules/dguide-3_a.C: New test.
* g++.dg/modules/dguide-3_b.C: New test.
* g++.dg/modules/dguide-3_c.C: New test.

Signed-off-by: Nathaniel Shead 
---
 gcc/cp/error.cc   |  1 +
 gcc/cp/module.cc  | 60 +++
 gcc/cp/pt.cc  |  2 +-
 gcc/testsuite/g++.dg/modules/dguide-1_a.C | 44 +
 gcc/testsuite/g++.dg/modules/dguide-1_b.C | 20 
 gcc/testsuite/g++.dg/modules/dguide-2_a.C | 24 +
 gcc/testsuite/g++.dg/modules/dguide-2_b.C | 19 +++
 gcc/testsuite/g++.dg/modules/dguide-3_a.C | 10 
 gcc/testsuite/g++.dg/modules/dguide-3_b.C | 10 
 gcc/testsuite/g++.dg/modules/dguide-3_c.C | 22 +
 10 files changed, 211 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/dguide-1_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/dguide-1_b.C
 create mode 100644 gcc/testsuite/g++.dg/modules/dguide-2_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/dguide-2_b.C
 create mode 100644 gcc/testsuite/g++.dg/modules/dguide-3_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/dguide-3_b.C
 create mode 100644 gcc/testsuite/g++.dg/modules/dguide-3_c.C

diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 171a352c85f..2fb5084320e 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -1866,6 +1866,7 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int 
flags)
dump_type_suffix (pp, ret, flags);
   else if (deduction_guide_p (t))
{
+ pp->set_padding (pp_before);
  pp_cxx_ws_string (pp, "->");
  dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags);
}
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 6d6044af199..a2c9e151fd5 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -2589,6 +2589,9 @@ public:
 void add_partial_entities (vec *);
 void add_class_entities (vec *);
 
+  private:
+void add_deduction_guides (tree decl);
+
   public:
 void find_dependencies (module_state *);
 bool finalize_dependencies ();
@@ -13127,6 +13130,11 @@ depset::hash::add_b

[committed] Fix minor SH scan-asm failure after recent IOR->ADD changes

2024-06-15 Thread Jeff Law
This fixes minor fallout from the IOR->ADD change for rotates that I 
installed a little while ago.


Basically the SH backend has a special pattern for setting the T 
register that has elements similar to a rotate.  With the IOR->ADD 
change that pattern no longer matches and we get scan-asm failures.


Fixing isn't a trivial case of just replacing IOR with ADD as the 
IOR->ADD change changes some of the simplifications/canonicalizations 
along the way.


The net is we need a pattern with a slightly different structure.   I've 
regression tested this on sh3[eb]-linux-gnu and bootstrapped 
sh4-linux-gnu (without a regression test).


Pushing to the trunk,
Jeff

gcc/
* config/sh/sh.md (neg_zero_extract_4b): New pattern.


diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 19481c07db6..92a1efeb811 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -10093,6 +10093,25 @@ (define_insn_and_split "*neg_zero_extract_4"
   [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
(const_int 1) (match_dup 2)))])
 
+;; Same thing, but when we use a PLUS rather than IOR/XOR for the rotation
+;; which causes things to simplify somewhat differently.
+(define_insn_and_split "*neg_zero_extract_4b"
+  [(set (reg:SI T_REG)
+   (and:SI (not:SI (plus:SI
+ (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
+  (match_operand 1 "const_int_operand"))
+ (ashift:SI (match_operand:SI 2 "arith_reg_operand")
+(match_operand 3 "const_int_operand"
+   (const_int 1)))]
+  "TARGET_SH1 && can_create_pseudo_p ()
+   && INTVAL (operands[3]) > 0
+   && INTVAL (operands[1]) + INTVAL (operands[3]) == 32"
+  "#"
+  "&& 1"
+  [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (match_dup 4))
+   (const_int 1) (match_dup 1)))]
+  { operands[4] = GEN_INT (1 << INTVAL (operands[1])); })
+
 (define_insn_and_split "*neg_zero_extract_5"
   [(set (reg:SI T_REG)
(and:SI (not:SI (subreg:SI


[PATCH v5] gcc, libcpp: Add warning switch for "#pragma once in main file" [PR89808]

2024-06-15 Thread Ken Matsui
This patch adds a warning switch for "#pragma once in main file".  The
warning option name is Wpragma-once-outside-header, which is the same
as Clang provides.

PR preprocessor/89808

gcc/c-family/ChangeLog:

* c.opt (Wpragma_once_outside_header): Define new option.
* c.opt.urls: Regenerate.

gcc/ChangeLog:

* doc/invoke.texi (Warning Options): Document
-Wno-pragma-once-outside-header.

libcpp/ChangeLog:

* include/cpplib.h (cpp_warning_reason): Define
CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER.
* directives.cc (do_pragma_once): Use
CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wno-pragma-once-outside-header.C: New test.
* g++.dg/warn/Wpragma-once-outside-header.C: New test.

Signed-off-by: Ken Matsui 
---
 gcc/c-family/c.opt |  4 
 gcc/c-family/c.opt.urls|  3 +++
 gcc/doc/invoke.texi| 10 --
 .../g++.dg/warn/Wno-pragma-once-outside-header.C   |  5 +
 .../g++.dg/warn/Wpragma-once-outside-header.C  |  6 ++
 libcpp/directives.cc   |  3 ++-
 libcpp/include/cpplib.h|  3 ++-
 7 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
 create mode 100644 gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 403abc1f26e..3439f36fe45 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1188,6 +1188,10 @@ Wpragmas
 C ObjC C++ ObjC++ Var(warn_pragmas) Init(1) Warning
 Warn about misuses of pragmas.
 
+Wpragma-once-outside-header
+C ObjC C++ ObjC++ Var(warn_pragma_once_outside_header) 
CppReason(CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER) Init(1) Warning
+Warn about #pragma once outside of a header.
+
 Wprio-ctor-dtor
 C ObjC C++ ObjC++ Var(warn_prio_ctor_dtor) Init(1) Warning
 Warn if constructor or destructors with priorities from 0 to 100 are used.
diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls
index dd455d7c0dc..778ca08be2e 100644
--- a/gcc/c-family/c.opt.urls
+++ b/gcc/c-family/c.opt.urls
@@ -672,6 +672,9 @@ 
UrlSuffix(gcc/Warning-Options.html#index-Wno-pointer-to-int-cast)
 Wpragmas
 UrlSuffix(gcc/Warning-Options.html#index-Wno-pragmas)
 
+Wpragma-once-outside-header
+UrlSuffix(gcc/Warning-Options.html#index-Wno-pragma-once-outside-header)
+
 Wprio-ctor-dtor
 UrlSuffix(gcc/Warning-Options.html#index-Wno-prio-ctor-dtor)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 9456ced468a..c7f17ca9eb7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -391,8 +391,8 @@ Objective-C and Objective-C++ Dialects}.
 -Wpacked  -Wno-packed-bitfield-compat  -Wpacked-not-aligned  -Wpadded
 -Wparentheses  -Wno-pedantic-ms-format
 -Wpointer-arith  -Wno-pointer-compare  -Wno-pointer-to-int-cast
--Wno-pragmas  -Wno-prio-ctor-dtor  -Wredundant-decls
--Wrestrict  -Wno-return-local-addr  -Wreturn-type
+-Wno-pragmas  -Wno-pragma-once-outside-header  -Wno-prio-ctor-dtor
+-Wredundant-decls  -Wrestrict  -Wno-return-local-addr  -Wreturn-type
 -Wno-scalar-storage-order  -Wsequence-point
 -Wshadow  -Wshadow=global  -Wshadow=local  -Wshadow=compatible-local
 -Wno-shadow-ivar
@@ -7983,6 +7983,12 @@ Do not warn about misuses of pragmas, such as incorrect 
parameters,
 invalid syntax, or conflicts between pragmas.  See also
 @option{-Wunknown-pragmas}.
 
+@opindex Wno-pragma-once-outside-header
+@opindex Wpragma-once-outside-header
+@item -Wno-pragma-once-outside-header
+Do not warn when @code{#pragma once} is used in a file that is not a header
+file, such as a main file.
+
 @opindex Wno-prio-ctor-dtor
 @opindex Wprio-ctor-dtor
 @item -Wno-prio-ctor-dtor
diff --git a/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C 
b/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
new file mode 100644
index 000..b5be4d25a9d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
@@ -0,0 +1,5 @@
+// { dg-do assemble  }
+// { dg-options "-Wno-pragma-once-outside-header" }
+
+#pragma once
+int main() {}
diff --git a/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C 
b/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
new file mode 100644
index 000..29f09b69f71
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
@@ -0,0 +1,6 @@
+// { dg-do assemble  }
+// { dg-options "-Werror=pragma-once-outside-header" }
+// { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 }
+
+#pragma once  // { dg-error "'pragma once' in main file" }
+int main() {}
diff --git a/libcpp/directives.cc b/libcpp/directives.cc
index 479f8c716e8..467efdf637d 100644
--- a/libcpp/directives.cc
+++ b/libcpp/directives.cc
@@ -1589,7 +1589,8 @@ static void
 do_pragma_once (cpp_reader *pfile)
 {
   if (_cpp_in_main_source_

Re: [PATCH] c++/modules: Ensure deduction guides are always reachable [PR115231]

2024-06-15 Thread Nathaniel Shead
On Sun, Jun 16, 2024 at 12:29:23PM +1000, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
> 
> This probably isn't the most efficient approach, since we need to do
> name lookup to find deduction guides for a type which will also
> potentially do a bunch of pointless lazy loading from imported modules,
> but I wasn't able to work out a better approach without completely
> reworking how deduction guides are stored and represented.  This way at
> least is correct (I believe), and we can maybe revisit this in the
> future.
> 
> -- >8 --
> 
> Deduction guides are represented as 'normal' functions currently, and
> have no special handling in modules.  However, this causes some issues;
> by [temp.deduct.guide] a deduction guide is not found by normal name
> lookup and instead all reachable deduction guides for a class template
> should be considered, but this does not happen currently.
> 
> To solve this, this patch ensures that all deduction guides are
> considered exported to ensure that they are always visible to importers
> if they are reachable.  Another alternative here would be to add a new
> kind of "all reachable" flag to name lookup, but that is complicated by
> some difficulties in handling GM entities; this may be a better way to
> go if more kinds of entities end up needing this handling, however.
> 
> Another issue here is that because deduction guides are "unrelated"
> functions, they will usually get discarded from the GMF, so this patch
> ensures that when finding dependencies, GMF deduction guides will also
> have bindings created.  We do this in find_dependencies so that we don't
> unnecessarily create bindings for GMF deduction guides that are never
> reached; for consistency we do this for *all* deduction guides, not just
> GM ones.
> 
> Finally, when merging deduction guides from multiple modules, the name
> lookup code may now return two-dimensional overload sets, so update
> callers to match.
> 
> As a small drive-by improvement this patch also updates the error pretty
> printing code to add a space before the '->' when printing a deduction
> guide, so we get 'S(int) -> S' instead of 'S(int)-> S'.
> 
>   PR c++/115231
> 
> gcc/cp/ChangeLog:
> 
>   * error.cc (dump_function_decl): Add a space before '->' when
>   printing deduction guides.
>   * module.cc (depset::hash::add_binding_entity): Skip deduction
>   guides here.
>   (depset::hash::add_deduction_guides): New.
>   (depset::hash::find_dependencies): Add deduction guide
>   dependencies for a class template.
>   (module_state::write_cluster): Always consider deduction guides
>   as exported.
>   * pt.cc (deduction_guides_for): Use 'lkp_iterator' instead of
>   'ovl_iterator'.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.dg/modules/dguide-1_a.C: New test.
>   * g++.dg/modules/dguide-1_b.C: New test.
>   * g++.dg/modules/dguide-2_a.C: New test.
>   * g++.dg/modules/dguide-2_b.C: New test.
>   * g++.dg/modules/dguide-3_a.C: New test.
>   * g++.dg/modules/dguide-3_b.C: New test.
>   * g++.dg/modules/dguide-3_c.C: New test.
> 
> Signed-off-by: Nathaniel Shead 
> ---
>  gcc/cp/error.cc   |  1 +
>  gcc/cp/module.cc  | 60 +++
>  gcc/cp/pt.cc  |  2 +-
>  gcc/testsuite/g++.dg/modules/dguide-1_a.C | 44 +
>  gcc/testsuite/g++.dg/modules/dguide-1_b.C | 20 
>  gcc/testsuite/g++.dg/modules/dguide-2_a.C | 24 +
>  gcc/testsuite/g++.dg/modules/dguide-2_b.C | 19 +++
>  gcc/testsuite/g++.dg/modules/dguide-3_a.C | 10 
>  gcc/testsuite/g++.dg/modules/dguide-3_b.C | 10 
>  gcc/testsuite/g++.dg/modules/dguide-3_c.C | 22 +
>  10 files changed, 211 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/modules/dguide-1_a.C
>  create mode 100644 gcc/testsuite/g++.dg/modules/dguide-1_b.C
>  create mode 100644 gcc/testsuite/g++.dg/modules/dguide-2_a.C
>  create mode 100644 gcc/testsuite/g++.dg/modules/dguide-2_b.C
>  create mode 100644 gcc/testsuite/g++.dg/modules/dguide-3_a.C
>  create mode 100644 gcc/testsuite/g++.dg/modules/dguide-3_b.C
>  create mode 100644 gcc/testsuite/g++.dg/modules/dguide-3_c.C
> 
> diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
> index 171a352c85f..2fb5084320e 100644
> --- a/gcc/cp/error.cc
> +++ b/gcc/cp/error.cc
> @@ -1866,6 +1866,7 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int 
> flags)
>   dump_type_suffix (pp, ret, flags);
>else if (deduction_guide_p (t))
>   {
> +   pp->set_padding (pp_before);
> pp_cxx_ws_string (pp, "->");
> dump_type (pp, TREE_TYPE (TREE_TYPE (t)), flags);
>   }
> diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
> index 6d6044af199..a2c9e151fd5 100644
> --- a/gcc/cp/module.cc
> +++ b/gcc/cp/module.cc
> @@ -2589,6 +2589,9 @@ public:
>  void add_partial_entities (vec *);
>  voi