[PATCH] [RTL/fwprop] Allow propagations from inner loop to outer loop.

2022-01-05 Thread liuhongt via Gcc-patches
> that's flow_loop_nested_p (loop *outer, loop *inner) which
> is implemented in O(1).  Note behavior for outer == inner
> might be different (didn't check your implementation too hard)
>
Thanks, it seems flow_loop_nested_p assume outer and inner not to be
NULL. So I add some conditions to check NULL which is considered as an outer
 loop of any other loop.



gcc/ChangeLog:

PR rtl/103750
* fwprop.c (forward_propagate_into): Allow propagations from
inner loop to outer loop.

gcc/testsuite/ChangeLog:

* g++.target/i386/pr103750-fwprop-1.C: New test.
---
 gcc/fwprop.c  |  7 +++--
 .../g++.target/i386/pr103750-fwprop-1.C   | 26 +++
 2 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/pr103750-fwprop-1.C

diff --git a/gcc/fwprop.c b/gcc/fwprop.c
index 2eab4fd4614..af2e9d1c189 100644
--- a/gcc/fwprop.c
+++ b/gcc/fwprop.c
@@ -866,10 +866,13 @@ forward_propagate_into (use_info *use, bool reg_prop_only 
= false)
   rtx src = SET_SRC (def_set);
 
   /* Allow propagations into a loop only for reg-to-reg copies, since
- replacing one register by another shouldn't increase the cost.  */
+ replacing one register by another shouldn't increase the cost.
+ Propagations from inner loop to outer loop should be also ok.  */
   struct loop *def_loop = def_insn->bb ()->cfg_bb ()->loop_father;
   struct loop *use_loop = use->bb ()->cfg_bb ()->loop_father;
-  if ((reg_prop_only || def_loop != use_loop)
+  if ((reg_prop_only
+   || (use_loop && def_loop != use_loop
+  &&(!def_loop || !flow_loop_nested_p (use_loop, def_loop
   && (!reg_single_def_p (dest) || !reg_single_def_p (src)))
 return false;
 
diff --git a/gcc/testsuite/g++.target/i386/pr103750-fwprop-1.C 
b/gcc/testsuite/g++.target/i386/pr103750-fwprop-1.C
new file mode 100644
index 000..26987d307aa
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr103750-fwprop-1.C
@@ -0,0 +1,26 @@
+/* PR target/103750.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -std=c++1y -march=cannonlake -fdump-rtl-fwprop1" } */
+/* { dg-final { scan-rtl-dump-not "subreg:HI\[ 
\\\(\]*reg:SI\[^\n]*\n\[^\n]*UNSPEC_TZCNT" "fwprop1" } } */
+
+#include
+const char16_t *qustrchr(char16_t *n, char16_t *e, char16_t c) noexcept
+{
+  __m256i mch256 = _mm256_set1_epi16(c);
+  for ( ; n < e; n += 32) {
+__m256i data1 = _mm256_loadu_si256(reinterpret_cast(n));
+__m256i data2 = _mm256_loadu_si256(reinterpret_cast(n) + 
1);
+__mmask16 mask1 = _mm256_cmpeq_epu16_mask(data1, mch256);
+__mmask16 mask2 = _mm256_cmpeq_epu16_mask(data2, mch256);
+if (_kortestz_mask16_u8(mask1, mask2))
+  continue;
+
+unsigned idx = _tzcnt_u32(mask1);
+if (mask1 == 0) {
+  idx = __tzcnt_u16(mask2);
+  n += 16;
+}
+return n + idx;
+  }
+  return e;
+}
-- 
2.18.1



Re: [power-ieee128] RFH: LTO broken

2022-01-05 Thread Michael Meissner via Gcc-patches
On Tue, Jan 04, 2022 at 12:07:49PM +0100, Jakub Jelinek wrote:
> On Mon, Jan 03, 2022 at 11:43:57PM +0100, Thomas Koenig wrote:
> > > clearly there is still work to fix (but seems e.g. most of the lto tests
> > > are related to the gnu attributes stuff:(  ).
> > 
> > This is looking better than what I expected.  Apart from LTO, I expect
> 
> I've just verified that LTO is broken even in C/C++, it isn't just gfortran.
> Just do
> make check-gcc RUNTESTFLAGS='--target_board=unix\{-mabi=ieeelongdouble\} 
> lto.exp'
> on a system where gcc is configured to default to -mabi=ibmlongdouble
> with glibc 2.32 or later and watch all the FAILs.
> All the failures look like:
> /home/jakub/gcc/obj/gcc/xgcc -B/home/jakub/gcc/obj/gcc/ c_lto_20081024_0.o 
> -mabi=ieeelongdouble -fdiagnostics-plain-output -O0 -flto 
> -flto-partition=none -o gcc-
> dg-lto-20081024-01.exe
> lto1: warning: Using IEEE extended precision 'long double' [-Wpsabi]
> FAIL: gcc.dg/lto/20081024 c_lto_20081024_0.o-c_lto_20081024_0.o link, -O0 
> -flto -flto-partition=none 
> 
> Michael, do you think you could have a look?  Either it is the ELF object
> created for debug info or the one created by lto1.

I pushed the patch to the branch.

-- 
Michael Meissner, IBM
PO Box 98, Ayer, Massachusetts, USA, 01432
email: meiss...@linux.ibm.com


Re: [power-ieee128] RFH: LTO broken

2022-01-05 Thread Michael Meissner via Gcc-patches
On Tue, Jan 04, 2022 at 12:07:49PM +0100, Jakub Jelinek wrote:
> On Mon, Jan 03, 2022 at 11:43:57PM +0100, Thomas Koenig wrote:
> > > clearly there is still work to fix (but seems e.g. most of the lto tests
> > > are related to the gnu attributes stuff:(  ).
> > 
> > This is looking better than what I expected.  Apart from LTO, I expect
> 
> I've just verified that LTO is broken even in C/C++, it isn't just gfortran.
> Just do
> make check-gcc RUNTESTFLAGS='--target_board=unix\{-mabi=ieeelongdouble\} 
> lto.exp'
> on a system where gcc is configured to default to -mabi=ibmlongdouble
> with glibc 2.32 or later and watch all the FAILs.
> All the failures look like:
> /home/jakub/gcc/obj/gcc/xgcc -B/home/jakub/gcc/obj/gcc/ c_lto_20081024_0.o 
> -mabi=ieeelongdouble -fdiagnostics-plain-output -O0 -flto 
> -flto-partition=none -o gcc-
> dg-lto-20081024-01.exe
> lto1: warning: Using IEEE extended precision 'long double' [-Wpsabi]
> FAIL: gcc.dg/lto/20081024 c_lto_20081024_0.o-c_lto_20081024_0.o link, -O0 
> -flto -flto-partition=none 
> 
> Michael, do you think you could have a look?  Either it is the ELF object
> created for debug info or the one created by lto1.

Here is the patch:

| From 22b778e6ea951774df921a2a49c0cf75a2b512a3 Mon Sep 17 00:00:00 2001
| From: Michael Meissner 
| Date: Wed, 5 Jan 2022 22:23:19 -0500
| Subject: [PATCH] Allow other languages to change long double format.

With Fortran adding support for changing the long double format, this
patch removes the code that only allowed C/C++ to change the long double
format for GLIBC 2.32 and later without a warning.

gcc/
2022-01-05  Michael Meissner  

* config/rs6000/rs6000.c (rs6000_option_override_internal): Remove
checks for only C/C++ front ends before allowing the long double
format to change without a warning.
---
 gcc/config/rs6000/rs6000.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 319182e94d9..0e3481c8327 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -4221,13 +4221,11 @@ rs6000_option_override_internal (bool global_init_p)
   if (rs6000_ieeequad != TARGET_IEEEQUAD_DEFAULT && TARGET_LONG_DOUBLE_128)
{
  /* Determine if the user can change the default long double type at
-compilation time.  Only C and C++ support this, and you need GLIBC
-2.32 or newer.  Only issue one warning.  */
+compilation time.  You need GLIBC 2.32 or newer to be able to
+change the long double type.  Only issue one warning.  */
  static bool warned_change_long_double;
 
- if (!warned_change_long_double
- && (!glibc_supports_ieee_128bit ()
- || (!lang_GNU_C () && !lang_GNU_CXX (
+ if (!warned_change_long_double && !glibc_supports_ieee_128bit ())
{
  warned_change_long_double = true;
  if (TARGET_IEEEQUAD)
-- 
2.33.1


-- 
Michael Meissner, IBM
PO Box 98, Ayer, Massachusetts, USA, 01432
email: meiss...@linux.ibm.com


Re: [PATCH] target: [PR102941] Fix inline-asm flags with non-REG_P output

2022-01-05 Thread Andrew Pinski via Gcc-patches
On Thu, Dec 2, 2021 at 2:16 PM Andrew Pinski  wrote:
>
> On Tue, Oct 26, 2021 at 2:45 AM apinski--- via Gcc-patches
>  wrote:
> >
> > From: Andrew Pinski 
> >
> > So the problem here is that arm_md_asm_adjust would
> > just create a set directly to the output memory which is wrong.
> > It needs to output to a temp register first and then do a
> > move.
> >
> > OK? Bootstrapped and tested on aarch64-linux-gnu with no regressions.
> > I have no way to test on arm even though this touches common code.
>
> Ping?

Ping?

Thanks,
Andrew Pinski

>
> >
> > PR target/102941
> >
> > gcc/ChangeLog:
> >
> > * config/arm/aarch-common.c (arm_md_asm_adjust):
> > Use a temp if !REG_P.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.target/aarch64/asm-flag-7.c: New test.
> > * gcc.target/arm/asm-flag-7.c: New test.
> > ---
> >  gcc/config/arm/aarch-common.c |  2 +-
> >  gcc/testsuite/gcc.target/aarch64/asm-flag-7.c | 22 ++
> >  gcc/testsuite/gcc.target/arm/asm-flag-7.c | 23 +++
> >  3 files changed, 46 insertions(+), 1 deletion(-)
> >  create mode 100644 gcc/testsuite/gcc.target/aarch64/asm-flag-7.c
> >  create mode 100644 gcc/testsuite/gcc.target/arm/asm-flag-7.c
> >
> > diff --git a/gcc/config/arm/aarch-common.c b/gcc/config/arm/aarch-common.c
> > index 67343fe4025..60b3516c1df 100644
> > --- a/gcc/config/arm/aarch-common.c
> > +++ b/gcc/config/arm/aarch-common.c
> > @@ -641,7 +641,7 @@ arm_md_asm_adjust (vec , vec & 
> > /*inputs*/,
> >rtx x = gen_rtx_REG (mode, CC_REGNUM);
> >x = gen_rtx_fmt_ee (code, word_mode, x, const0_rtx);
> >
> > -  if (dest_mode == word_mode)
> > +  if (dest_mode == word_mode && REG_P (dest))
> > emit_insn (gen_rtx_SET (dest, x));
> >else
> > {
> > diff --git a/gcc/testsuite/gcc.target/aarch64/asm-flag-7.c 
> > b/gcc/testsuite/gcc.target/aarch64/asm-flag-7.c
> > new file mode 100644
> > index 000..6c31b854b0b
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/aarch64/asm-flag-7.c
> > @@ -0,0 +1,22 @@
> > +/* Test that "=@cc*" works with MEM_P RTX  */
> > +/* PR target/102941 */
> > +/* { dg-do compile } */
> > +/* { dg-options "-O" } */
> > +
> > +#ifndef __GCC_ASM_FLAG_OUTPUTS__
> > +#error "missing preprocessor define"
> > +#endif
> > +int test_cmpu_x;
> > +
> > +void f(long *);
> > +long
> > +test_cmpu_y() {
> > +  long le;
> > +  f();
> > +  __asm__("cmp %"
> > +  "[x], %"
> > +  "[y]"
> > +  : "=@ccls"(le)
> > +  : [x] ""(test_cmpu_x), [y] ""(test_cmpu_y));
> > +return le;
> > +}
> > diff --git a/gcc/testsuite/gcc.target/arm/asm-flag-7.c 
> > b/gcc/testsuite/gcc.target/arm/asm-flag-7.c
> > new file mode 100644
> > index 000..ac11da0a3a8
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/arm/asm-flag-7.c
> > @@ -0,0 +1,23 @@
> > +/* Test that "=@cc*" works with MEM_P RTX  */
> > +/* PR target/102941 */
> > +/* { dg-do compile } */
> > +/* { dg-options "-O" } */
> > +/* { dg-skip-if "" { arm_thumb1 } } */
> > +
> > +#ifndef __GCC_ASM_FLAG_OUTPUTS__
> > +#error "missing preprocessor define"
> > +#endif
> > +int test_cmpu_x;
> > +
> > +void f(long *);
> > +long
> > +test_cmpu_y() {
> > +  long le;
> > +  f();
> > +  __asm__("cmp %"
> > +  "[x], %"
> > +  "[y]"
> > +  : "=@ccls"(le)
> > +  : [x] ""(test_cmpu_x), [y] ""(test_cmpu_y));
> > +return le;
> > +}
> > --
> > 2.17.1
> >


Re: [power-ieee128] RFH: LTO broken

2022-01-05 Thread Michael Meissner via Gcc-patches
On Tue, Jan 04, 2022 at 12:07:49PM +0100, Jakub Jelinek wrote:
> On Mon, Jan 03, 2022 at 11:43:57PM +0100, Thomas Koenig wrote:
> > > clearly there is still work to fix (but seems e.g. most of the lto tests
> > > are related to the gnu attributes stuff:(  ).
> > 
> > This is looking better than what I expected.  Apart from LTO, I expect
> 
> I've just verified that LTO is broken even in C/C++, it isn't just gfortran.
> Just do
> make check-gcc RUNTESTFLAGS='--target_board=unix\{-mabi=ieeelongdouble\} 
> lto.exp'
> on a system where gcc is configured to default to -mabi=ibmlongdouble
> with glibc 2.32 or later and watch all the FAILs.
> All the failures look like:
> /home/jakub/gcc/obj/gcc/xgcc -B/home/jakub/gcc/obj/gcc/ c_lto_20081024_0.o 
> -mabi=ieeelongdouble -fdiagnostics-plain-output -O0 -flto 
> -flto-partition=none -o gcc-
> dg-lto-20081024-01.exe
> lto1: warning: Using IEEE extended precision 'long double' [-Wpsabi]
> FAIL: gcc.dg/lto/20081024 c_lto_20081024_0.o-c_lto_20081024_0.o link, -O0 
> -flto -flto-partition=none 
> 
> Michael, do you think you could have a look?  Either it is the ELF object
> created for debug info or the one created by lto1.
> 
>   Jakub
> 

The problem is in rs6000_option_override_internal.  I allowed C and C++ to
change the long double format, but not other languages.  I forgot that LTO is
another front end.  I have a patch to remove the checks for C/C++.

I hope to validate it and send it out before the end of the night for me.
Note, I have a day surgery tomorrow, and I will be offline for at least part of
the day.

-- 
Michael Meissner, IBM
PO Box 98, Ayer, Massachusetts, USA, 01432
email: meiss...@linux.ibm.com


Re: [PATCH] Avoid more -Wformat-diag warnings [PR103758]

2022-01-05 Thread Joseph Myers
On Wed, 5 Jan 2022, Marek Polacek via Gcc-patches wrote:

> Let's use "%, %, or %" rather than "[x|y|z]" as in the rest of
> our codebase.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11?

OK.

-- 
Joseph S. Myers
jos...@codesourcery.com


[PATCH] Avoid more -Wformat-diag warnings [PR103758]

2022-01-05 Thread Marek Polacek via Gcc-patches
Let's use "%, %, or %" rather than "[x|y|z]" as in the rest of
our codebase.

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

PR c++/103758

gcc/c-family/ChangeLog:

* c-pragma.c (handle_pragma_scalar_storage_order): Use %< %> in
diagnostic messages.
(handle_pragma_diagnostic): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/sso-6.c: Update dg-warning.
---
 gcc/c-family/c-pragma.c  | 16 ++--
 gcc/testsuite/gcc.dg/sso-6.c |  4 ++--
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index ecf4457aacd..8dde5b841b2 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -441,7 +441,8 @@ handle_pragma_scalar_storage_order (cpp_reader 
*ARG_UNUSED(dummy))
 
   token = pragma_lex ();
   if (token != CPP_NAME)
-GCC_BAD ("missing [big-endian|little-endian|default] after %<#pragma 
scalar_storage_order%>");
+GCC_BAD ("missing %, %, or % after "
+"%<#pragma scalar_storage_order%>");
   kind_string = IDENTIFIER_POINTER (x);
   if (strcmp (kind_string, "default") == 0)
 global_sso = default_sso;
@@ -450,7 +451,8 @@ handle_pragma_scalar_storage_order (cpp_reader 
*ARG_UNUSED(dummy))
   else if (strcmp (kind_string, "little") == 0)
 global_sso = SSO_LITTLE_ENDIAN;
   else
-GCC_BAD ("expected [big-endian|little-endian|default] after %<#pragma 
scalar_storage_order%>");
+GCC_BAD ("expected %, %, or % after 
"
+"%<#pragma scalar_storage_order%>");
 }
 
 /* GCC supports two #pragma directives for renaming the external
@@ -771,8 +773,9 @@ handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
   if (token != CPP_NAME)
 {
   warning_at (loc, OPT_Wpragmas,
- "missing [error|warning|ignored|push|pop|ignored_attributes]"
- " after %<#pragma GCC diagnostic%>");
+ "missing %, %, %, %, "
+ "%, or % after "
+ "%<#pragma GCC diagnostic%>");
   return;
 }
 
@@ -830,8 +833,9 @@ handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
   else
 {
   warning_at (loc, OPT_Wpragmas,
- "expected [error|warning|ignored|push|pop|ignored_attributes]"
- " after %<#pragma GCC diagnostic%>");
+ "expected %, %, %, %, "
+ "%, % after "
+ "%<#pragma GCC diagnostic%>");
   return;
 }
 
diff --git a/gcc/testsuite/gcc.dg/sso-6.c b/gcc/testsuite/gcc.dg/sso-6.c
index e955fa93686..559253293b5 100644
--- a/gcc/testsuite/gcc.dg/sso-6.c
+++ b/gcc/testsuite/gcc.dg/sso-6.c
@@ -3,7 +3,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target int32plus } */
 
-#pragma scalar_storage_order /* { dg-warning "missing 
.big-endian.little-endian.default." } */
+#pragma scalar_storage_order /* { dg-warning "missing .big-endian., 
.little-endian., or .default." } */
 
 #pragma scalar_storage_order big-endian
 
@@ -36,7 +36,7 @@ struct S5
   int i;
 };
 
-#pragma scalar_storage_order other /* { dg-warning "expected 
.big-endian.little-endian.default." } */
+#pragma scalar_storage_order other /* { dg-warning "expected .big-endian., 
.little-endian., or .default." } */
 
 struct S1 my_s1 = { 0x12345678 };
 struct S2 my_s2 = { 0x12345678 };

base-commit: 4ec62dbafe0cb3b79cc635dfb964ef6a7ccc2d40
-- 
2.33.1



[PATCH] Fix target/103910: missing GTY on x86_mfence causing PCH usage to ICE

2022-01-05 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

With -O3 -march=opteron, a mfence builtin is added after the loop
to say the nontemporal stores are no longer needed. This all good
without precompiled headers as the function decl that is referneced
by x86_mfence is referenced in another variable but with precompiled
headers, x86_mfence is all messed up and the decl was GC'ed away.
This fixes the problem by marking x86_mfence as GTY to save/restore
during precompiled headers just like most other variables in
the header file.

Committed as obvious after a bootstrap/test on x86_64-linux-gnu.

gcc/ChangeLog:

PR target/103910
* config/i386/i386.h (x86_mfence): Mark with GTY.
---
 gcc/config/i386/i386.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index f027608eefa..3ac0f698ae2 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -486,7 +486,7 @@ extern unsigned char ix86_prefetch_sse;
 
 /* Fence to use after loop using storent.  */
 
-extern tree x86_mfence;
+extern GTY(()) tree x86_mfence;
 #define FENCE_FOLLOWING_MOVNT x86_mfence
 
 /* Once GDB has been enhanced to deal with functions without frame
-- 
2.17.1



Re: [power-ieee128] libquadmath: Use -mno-gnu-attribute in libquadmath

2022-01-05 Thread Michael Meissner via Gcc-patches
On Mon, Jan 03, 2022 at 04:24:50PM +0100, Jakub Jelinek wrote:
> Hi!
> 
> Testing found that we also need libquadmath to be built with
> -mno-gnu-attribute, otherwise -mabi=ieeelongdouble programs don't link.
> 
> Ok for power-ieee128?
> 
> 2022-01-03  Jakub Jelinek  
> 
>   * configure.ac: Set XCFLAGS to -mno-gnu-attribute on
>   powerpc64le*-linux*.
>   * configure: Regenerated.

I'm wondering whether we want to change things so that Fortran never uses long
double on PowerPC, but instead it explicitly uses __float128 and __ibm128.  But
this breaks down in using printf/scanf, which don't have format options for
those types.

Unfortunately this won't work with the current code, since passing any of the
128-bit floating point types causes the flag 'rs6000_passes_long_double' to be
set (and then the gnu attribute #4 is set).  In theory, that should be set only
if an explicit long double type is used.  But the problem is when those things
are set, you tend to only have modes and not types.

To do it 'right', you probably need a GIMPLE pass that looks at the actual
types used, not the modes.

-- 
Michael Meissner, IBM
PO Box 98, Ayer, Massachusetts, USA, 01432
email: meiss...@linux.ibm.com


[PATCH] i386: Introduce V2QImode minmax, abs and uavgv2hi3_ceil [PR103861]

2022-01-05 Thread Uros Bizjak via Gcc-patches
Add V2QImode minmax, abs and uavxv2qi3_ceil operations with SSE registers.

2022-01-05  Uroš Bizjak  

gcc/ChangeLog:

PR target/103861
* config/i386/mmx.md (VI_16_32): New mode iterator.
(VI1_16_32): Ditto.
(mmxvecsize): Handle V2QI mode.
(3): Rename from v4qi3.
Use VI1_16_32 mode iterator.
(3): Rename from v4qi3.
Use VI1_16_32 mode iterator.
(abs2): Use VI_16_32 mode iterator.
(uavgv2qi3_ceil): New insn pattern.

gcc/testsuite/ChangeLog:

PR target/103861
* gcc.target/i386/pr103861-3.c: New test.
* g++.dg/vect/slp-pr98855.cc (dg-final): Check that
no vectorization using SLP was performed.

I have changed scan-tree-dump patterns in g++.dg/vect/slp-pr98855.cc
to check that no SLP vectorization was performed. The existing
scan-tree-dump-times was too fragile, since the message was output for
every vectorization mode.

Another issue is missing vectorization for uavgv2qi3_ceil. I will open
a PR for that.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Pushed to master.

Uros.
diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md
index 96d85a54e10..a409bb7c6c6 100644
--- a/gcc/config/i386/mmx.md
+++ b/gcc/config/i386/mmx.md
@@ -63,6 +63,12 @@
 ;; 4-byte integer vector modes
 (define_mode_iterator VI_32 [V4QI V2HI])
 
+;; 4-byte and 2-byte integer vector modes
+(define_mode_iterator VI_16_32 [V4QI V2QI V2HI])
+
+;; 4-byte and 2-byte QImode vector modes
+(define_mode_iterator VI1_16_32 [V4QI V2QI])
+
 ;; V2S* modes
 (define_mode_iterator V2FI [V2SF V2SI])
 
@@ -71,7 +77,8 @@
 
 ;; Mapping from integer vector mode to mnemonic suffix
 (define_mode_attr mmxvecsize
-  [(V8QI "b") (V4QI "b") (V4HI "w") (V2HI "w") (V2SI "d") (V1DI "q")])
+  [(V8QI "b") (V4QI "b") (V2QI "b")
+   (V4HI "w") (V2HI "w") (V2SI "d") (V1DI "q")])
 
 (define_mode_attr mmxdoublemode
   [(V8QI "V8HI") (V4HI "V4SI")])
@@ -2140,11 +2147,11 @@
  (match_operand:V4HI 2 "register_operand")))]
   "TARGET_MMX_WITH_SSE")
 
-(define_insn "v4qi3"
-  [(set (match_operand:V4QI 0 "register_operand" "=Yr,*x,Yv")
-   (smaxmin:V4QI
- (match_operand:V4QI 1 "register_operand" "%0,0,Yv")
- (match_operand:V4QI 2 "register_operand" "Yr,*x,Yv")))]
+(define_insn "3"
+  [(set (match_operand:VI1_16_32 0 "register_operand" "=Yr,*x,Yv")
+   (smaxmin:VI1_16_32
+ (match_operand:VI1_16_32 1 "register_operand" "%0,0,Yv")
+ (match_operand:VI1_16_32 2 "register_operand" "Yr,*x,Yv")))]
   "TARGET_SSE4_1"
   "@
pb\t{%2, %0|%0, %2}
@@ -2218,11 +2225,11 @@
  (match_operand:V8QI 2 "register_operand")))]
   "TARGET_MMX_WITH_SSE")
 
-(define_insn "v4qi3"
-  [(set (match_operand:V4QI 0 "register_operand" "=x,Yw")
-(umaxmin:V4QI
- (match_operand:V4QI 1 "register_operand" "%0,Yw")
- (match_operand:V4QI 2 "register_operand" "x,Yw")))]
+(define_insn "3"
+  [(set (match_operand:VI1_16_32 0 "register_operand" "=x,Yw")
+(umaxmin:VI1_16_32
+ (match_operand:VI1_16_32 1 "register_operand" "%0,Yw")
+ (match_operand:VI1_16_32 2 "register_operand" "x,Yw")))]
   "TARGET_SSE2"
   "@
pb\t{%2, %0|%0, %2}
@@ -2269,9 +2276,9 @@
   "TARGET_SSSE3 && TARGET_MMX_WITH_SSE")
 
 (define_insn "abs2"
-  [(set (match_operand:VI_32 0 "register_operand" "=Yv")
-   (abs:VI_32
- (match_operand:VI_32 1 "register_operand" "Yv")))]
+  [(set (match_operand:VI_16_32 0 "register_operand" "=Yv")
+   (abs:VI_16_32
+ (match_operand:VI_16_32 1 "register_operand" "Yv")))]
   "TARGET_SSSE3"
   "%vpabs\t{%1, %0|%0, %1}"
   [(set_attr "type" "sselog1")
@@ -4351,6 +4358,26 @@
(set_attr "type" "sseiadd")
(set_attr "mode" "TI")])
 
+(define_insn "uavgv2qi3_ceil"
+  [(set (match_operand:V2QI 0 "register_operand" "=x,Yw")
+   (truncate:V2QI
+ (lshiftrt:V2HI
+   (plus:V2HI
+ (plus:V2HI
+   (zero_extend:V2HI
+ (match_operand:V2QI 1 "register_operand" "%0,Yw"))
+   (zero_extend:V2HI
+ (match_operand:V2QI 2 "register_operand" "x,Yw")))
+ (const_vector:V2HI [(const_int 1) (const_int 1)]))
+   (const_int 1]
+  "TARGET_SSE2"
+  "@
+   pavgb\t{%2, %0|%0, %2}
+   vpavgb\t{%2, %1, %0|%0, %1, %2}"
+  [(set_attr "isa" "noavx,avx")
+   (set_attr "type" "sseiadd")
+   (set_attr "mode" "TI")])
+
 (define_insn "uavgv2hi3_ceil"
   [(set (match_operand:V2HI 0 "register_operand" "=x,Yw")
(truncate:V2HI
diff --git a/gcc/testsuite/g++.dg/vect/slp-pr98855.cc 
b/gcc/testsuite/g++.dg/vect/slp-pr98855.cc
index b1010326698..ff59eb95aca 100644
--- a/gcc/testsuite/g++.dg/vect/slp-pr98855.cc
+++ b/gcc/testsuite/g++.dg/vect/slp-pr98855.cc
@@ -81,6 +81,5 @@ void encrypt_n(const uint8_t in[], uint8_t out[], size_t 
blocks, uint32_t *EK)
 }
 }
 
-// This used to work on { target x86_64-*-* i?86-*-* } but a fix in SLP
-// discovery makes us trip over the threshold again.
-// { dg-final { scan-tree-dump-times "not vectorized: 

[PATCH] Fortran: Fix ICE in argument_rank_mismatch [PR103287]

2022-01-05 Thread Sandra Loosemore
One of my previous TS29113-related patches from last fall introduced an 
ICE due to a bogus assertion.  This is the fix Steve suggested in the 
issue, bundled with the test cases, regression-tested, etc.  OK to check in?


-Sandra
commit beaae3933ef62e4d52ec22c14a308295c0794683
Author: Sandra Loosemore 
Date:   Wed Jan 5 13:18:10 2022 -0800

Fortran: Fix ICE in argument_rank_mismatch [PR103287]

This patch removes an incorrect assertion.  A user-friendly error for this
case is already given elsewhere.

2022-01-05  Steve Kargl  
	Sandra Loosemore  

	PR fortran/103287

	gcc/fortran/
	* interface.c (argument_rank_mismatch): Replace incorrect assertion
	with return.

	gcc/testsuite/
	* gfortran.dg/c-interop/pr103287-1.f90: new.
	* gfortran.dg/c-interop/pr103287-2.f90: new.

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 4be9583..0fd881d 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -2237,7 +2237,11 @@ argument_rank_mismatch (const char *name, locus *where,
 }
   else
 {
-  gcc_assert (rank2 != -1);
+  if (rank2 == -1)
+	/* This is an assumed rank-actual passed to a function without
+	   an explicit interface, which is already diagnosed in
+	   gfc_procedure_use.  */
+	return;
   if (rank1 == 0)
 	gfc_error_opt (0, "Rank mismatch between actual argument at %L "
 		   "and actual argument at %L (scalar and rank-%d)",
diff --git a/gcc/testsuite/gfortran.dg/c-interop/pr103287-1.f90 b/gcc/testsuite/gfortran.dg/c-interop/pr103287-1.f90
new file mode 100644
index 000..aeca52f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/c-interop/pr103287-1.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+
+subroutine g
+   call s([1])
+end
+subroutine h(x)
+   integer, pointer :: x(..)
+   call s(x) ! { dg-error "Assumed-rank argument requires an explicit interface" } 
+end
diff --git a/gcc/testsuite/gfortran.dg/c-interop/pr103287-2.f90 b/gcc/testsuite/gfortran.dg/c-interop/pr103287-2.f90
new file mode 100644
index 000..0e724b8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/c-interop/pr103287-2.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+
+subroutine g
+   call s(1)
+end
+subroutine h(x)
+   integer, pointer :: x(..)
+   call s(x) ! { dg-error "Assumed-rank argument requires an explicit interface" } 
+end


Re: [PATCH][hooks-bin] Port email_to.py to Python3.

2022-01-05 Thread Joseph Myers
On Wed, 5 Jan 2022, Martin Liška wrote:

> Please install it, apparently I can't push commits there:

Done.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [PATCH] rs6000: Skip overload instances with uninitialized fntype (PR103622)

2022-01-05 Thread Segher Boessenkool
Happy new year Bill!

On Mon, Dec 13, 2021 at 10:15:46AM -0600, Bill Schmidt wrote:
> For some data types like IEEE-128, we determine whether the type is available
> at built-in function initialization time.  If it's not, then we don't provide
> the function type for function instances that require the data type.  PR103622
> observes that this can cause us to ICE when running the list of instances when
> the target doesn't support the data type.
> 
> Ideally, we wouldn't even put such an instance in the list of instances that
> an overload can map to, but to do that is much more complicated.  Instead,
> this patch just ensures we don't dereference a NULL pointer when the situation
> arises.

Okay for trunk.  Thanks!


Segher


>   PR target/103622
>   * config/rs6000/rs6000-c.c (altivec_resolve_new_overloaded_builtin):
>   Skip over instances with undefined function types.


Re: [PATCH] enable -Winvalid-memory-order for C++ [PR99612]

2022-01-05 Thread Martin Sebor via Gcc-patches

On 1/5/22 1:45 AM, Martin Liška wrote:

On 12/8/21 17:49, Martin Sebor via Gcc-patches wrote:

Even with -Wno-system-headers enabled, the -Winvalid-memory-order
code tries to make sure calls to atomic functions with invalid
memory orders are diagnosed even though the C atomic functions
are defined as macros in the  system header.
The warning triggers at all optimization levels, including -O0.

Independently, the core diagnostic enhancements implemented earlier
this year (the warning group control) enable warnings for functions
defined in system headers that are inlined into user code.  This
was done for similar reason as above: because it's desirable to
diagnose invalid calls made from user code to system functions
(e.g., buffer overflows, invalid or mismatched deallocations,
etc.)

However, the C macro solution interferes with the code diagnostic
changes and prevents the invalid memory model warnings from being
issued for the same problems in C++.  In addition, because C++
atomics are ordinary (inline) functions that call the underlying
__atomic_xxx built-ins, the invalid memory orders can only be
detected with both inlining and constant propagation enabled.

The attached patch removes these limitations and enables
-Winvalid-memory-order to trigger even for C++ std::atomic,
(almost) just like it does in C, at all optimization levels
including -O0.

To make that possible I had to move -Winvalid-memory-order from
builtins.c to a GIMPLE pass where it can use context-sensitive
range info at -O0, instead of relying on constant propagation
(only available at -O1 and above).  Although the same approach
could be used to emit better object code for C++ atomics at -O0
(i.e., use the right memory order instead of dropping to seq_cst),
this patch doesn't do that.)

In addition to enabling the warning I've also enhanced it to
include the memory models involved in the diagnosed call (both
the problem ones and the viable alternatives).

Tested on x86_64-linux.

Jonathan, I CC you for two reasons: a) because this solution
is based on your (as well as my own) preference for handling
C++ system headers, and because of our last week's discussion
of the false positives in std::string resulting from the same
choice there.

I don't anticipate this change to lead to the same fallout
because it's unlikely for GCC to synthesize invalid memory
orders out of thin air; and b) because the current solution
can only detect the problems in calls to atomic functions at
-O0 that are declared with attribute always_inline.  This
includes member functions defined in the enclosing atomic
class but not namespace-scope functions.  To make
the detection possible those would also have to be
always_inline.  If that's a change you'd like to see I can
look into making it happen.

Martin


Hello.

I think the patch caused:

gcc/gimple-ssa-warn-access.cc:2844:30: warning: quoted ‘%s’ directive in 
format; use ‘%qs’ instead [-Wformat-diag]


Can you please take a look?


I've fixed it in r12-6271.

Thanks
Martin


[PATCH] tree-optimization/103514 Missing XOR-EQ-AND Optimization

2022-01-05 Thread Navid Rahimi via Gcc-patches
Hi GCC community,

This patch will add the missed pattern described in bug 103514 [1] to the 
match.pd. [1] includes proof of correctness for the patch too. 

PR tree-optimization/103514
* match.pd (a & b) ^ (a == b) -> !(a | b): New optimization.
* match.pd (a & b) == (a ^ b) -> !(a | b): New optimization.
* gcc.dg/tree-ssa/pr103514.c: Testcase for this optimization.

1) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103514

Best wishes,
Navid.From 7bc34478cc3a494bb634625281b5f03e43f210a9 Mon Sep 17 00:00:00 2001
From: Navid Rahimi 
Date: Wed, 1 Dec 2021 00:00:54 -0800
Subject: [PATCH] tree-optimization/103514 Missing XOR-EQ-AND Optimization

	* match.pd (a & b) ^ (a == b) -> !(a | b): New optimization.
	* match.pd (a & b) == (a ^ b) -> !(a | b): New optimization.
	* gcc.dg/tree-ssa/pr103514.c: Testcase for this optimization.
---
 gcc/match.pd |  8 ++
 gcc/testsuite/gcc.dg/tree-ssa/pr103514.c | 33 
 2 files changed, 41 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr103514.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 0d7b8dd1334..df55206d2ec 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1768,6 +1768,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (negate (nop_convert? (bit_not @0)))
  (plus (view_convert @0) { build_each_one_cst (type); }))
 
+/* (a & b) ^ (a == b) -> !(a | b) */
+/* (a & b) == (a ^ b) -> !(a | b) */
+(for first_op (bit_xor eq)
+ second_op (eq bit_xor)
+ (simplify
+  (first_op:c (bit_and:c truth_valued_p@0 truth_valued_p@1) (second_op:c @0 @1))
+(bit_not (bit_ior @0 @1
+
 /* Convert ~ (A - 1) or ~ (A + -1) to -A.  */
 (simplify
  (bit_not (convert? (minus @0 integer_each_onep)))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103514.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103514.c
new file mode 100644
index 000..5942ad37bf0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103514.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+#include 
+
+bool
+i (bool a, bool b)
+{
+ return (a & b) ^ (a == b);
+}
+
+bool
+j (bool a, bool b)
+{
+ return (a & b) == (a ^ b);
+}
+
+bool
+g (bool a, bool b)
+{
+return (a && b) == (a ^ b); 
+}
+
+bool
+h (bool a, bool b)
+{
+ return (a && b) ^ (a == b);
+}
+
+
+/* Make sure we have removed "==" and "^" and "&". */
+/* { dg-final { scan-tree-dump-not "&" "optimized"} } */
+/* { dg-final { scan-tree-dump-not "\\^"  "optimized"} } */
+/* { dg-final { scan-tree-dump-not "==" "optimized"} } */
\ No newline at end of file
-- 
2.25.1



Re: [PATCH] rs6000: Skip overload instances with uninitialized fntype (PR103622)

2022-01-05 Thread Bill Schmidt via Gcc-patches
Hi!  I'd like to ping this patch, now that I'm back from break.

Thanks!
Bill

On 12/13/21 10:15 AM, Bill Schmidt wrote:
> Hi!
>
> For some data types like IEEE-128, we determine whether the type is available
> at built-in function initialization time.  If it's not, then we don't provide
> the function type for function instances that require the data type.  PR103622
> observes that this can cause us to ICE when running the list of instances when
> the target doesn't support the data type.
>
> Ideally, we wouldn't even put such an instance in the list of instances that
> an overload can map to, but to do that is much more complicated.  Instead,
> this patch just ensures we don't dereference a NULL pointer when the situation
> arises.
>
> Tested the fix on a powerpc-e300c3-linux-gnu cross.  Bootstrapped and tested 
> on
> powerpc64le-linux-gnu with no regressions.  Is this okay for trunk?
>
> Thanks!
> Bill
>
>
> 2021-12-13  Bill Schmidt  
>
> gcc/
>   PR target/103622
>   * config/rs6000/rs6000-c.c (altivec_resolve_new_overloaded_builtin):
>   Skip over instances with undefined function types.
> ---
>  gcc/config/rs6000/rs6000-c.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c
> index 8e83d97e72f..fc4cc929884 100644
> --- a/gcc/config/rs6000/rs6000-c.c
> +++ b/gcc/config/rs6000/rs6000-c.c
> @@ -2943,6 +2943,12 @@ altivec_resolve_new_overloaded_builtin (location_t 
> loc, tree fndecl,
>  
>   for (; instance != NULL; instance = instance->next)
> {
> + /* It is possible for an instance to require a data type that isn't
> +defined on this target, in which case instance->fntype will be
> +NULL.  */
> + if (!instance->fntype)
> +   continue;
> +
>   bool mismatch = false;
>   tree nextparm = TYPE_ARG_TYPES (instance->fntype);
>  


[PATCH] i386: Fix type of one_cmplv2qi2 alternatives 1,2 [PR103915]

2022-01-05 Thread Uros Bizjak via Gcc-patches
2022-01-05  Uroš Bizjak  

gcc/ChangeLog:

PR target/103915
* config/i386/mmx.md (one_cmplv2qi2): Change
alternatives 1,2 type from sselog to sselog1.

gcc/testsuite/ChangeLog:

PR target/103915
* gcc.target/i386/pr103915.c: New test.


Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Pushed to master.

Uros.
diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md
index fc8ec5e4d49..96d85a54e10 100644
--- a/gcc/config/i386/mmx.md
+++ b/gcc/config/i386/mmx.md
@@ -2752,7 +2752,7 @@
   ""
   "#"
   [(set_attr "isa" "*,sse2,avx512vl")
-   (set_attr "type" "negnot,sselog,sselog")
+   (set_attr "type" "negnot,sselog1,sselog1")
(set_attr "mode" "SI,TI,TI")])
 
 (define_split
diff --git a/gcc/testsuite/gcc.target/i386/pr103915.c 
b/gcc/testsuite/gcc.target/i386/pr103915.c
new file mode 100644
index 000..34f1d635510
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr103915.c
@@ -0,0 +1,11 @@
+/* PR target/103915 */
+/* { dg-do compile } */
+/* { dg-options "-flive-range-shrinkage" } */
+
+char __attribute__((__vector_size__ (2))) data;
+
+void
+foo (void)
+{
+  data = ~data;
+}


[PATCH] i386: Fix expand_vec_perm_pshufb for narrow modes [PR103905]

2022-01-05 Thread Uros Bizjak via Gcc-patches
2022-01-05  Uroš Bizjak  

gcc/ChangeLog:

PR target/103905
* config/i386/i386-expand.c (expand_vec_perm_pshufb): Fix number of
narrow mode remapped elements for !one_operand_p case.

gcc/testsuite/ChangeLog:

PR target/103905
* gcc.target/i386/pr103905.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
The testcase is also tested by Martin on a real XOP target.

Pushed to master.

Uros.
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index e93ef1cafa6..9bd8e539d08 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -18730,7 +18730,7 @@ expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
 {
   unsigned i, nelt, eltsz, mask;
   unsigned char perm[64];
-  machine_mode vmode = V16QImode;
+  machine_mode vmode;
   struct expand_vec_perm_d nd;
   rtx rperm[64], vperm, target, op0, op1;
 
@@ -18754,6 +18754,7 @@ expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
   case 16:
if (!TARGET_XOP)
  return false;
+   vmode = V16QImode;
break;
 
   case 32:
@@ -18803,6 +18804,7 @@ expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
   case 16:
if (!TARGET_SSSE3)
  return false;
+   vmode = V16QImode;
break;
 
   case 32:
@@ -18894,6 +18896,7 @@ expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
/* Or if vpermps can be used.  */
else if (d->vmode == V16SFmode)
  vmode = V16SImode;
+
if (vmode == V64QImode)
  {
/* vpshufb only works intra lanes, it is not
@@ -18946,8 +18949,10 @@ expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
 
   machine_mode vpmode = vmode;
 
-  if (vmode == V4QImode
-  || vmode == V8QImode)
+  nelt = GET_MODE_SIZE (vmode);
+
+  /* Emulate narrow modes with V16QI instructions.  */
+  if (nelt < 16)
 {
   rtx m128 = GEN_INT (-128);
 
@@ -18955,19 +18960,15 @@ expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
 account for inactive top elements from the first operand.  */
   if (!d->one_operand_p)
{
- int sz = GET_MODE_SIZE (vmode);
-
  for (i = 0; i < nelt; ++i)
{
- int ival = INTVAL (rperm[i]);
- if (ival >= sz)
-   ival += 16-sz;
- rperm[i] = GEN_INT (ival);
+ unsigned ival = UINTVAL (rperm[i]);
+ if (ival >= nelt)
+   rperm[i] = GEN_INT (ival + 16 - nelt);
}
}
 
-  /* V4QI/V8QI is emulated with V16QI instruction, fill inactive
-elements in the top positions with zeros.  */
+  /* Fill inactive elements in the top positions with zeros.  */
   for (i = nelt; i < 16; ++i)
rperm[i] = m128;
 
diff --git a/gcc/testsuite/gcc.target/i386/pr103905.c 
b/gcc/testsuite/gcc.target/i386/pr103905.c
new file mode 100644
index 000..aef9c4d3a0a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr103905.c
@@ -0,0 +1,25 @@
+/* PR target/103905 */
+/* { dg-do run } */
+/* { dg-require-effective-target xop } */
+/* { dg-options "-O3 -mxop" } */
+
+#include "xop-check.h"
+
+char perm[64];
+
+void
+__attribute__((noipa))
+foo (int n)
+{
+  for (int i = 0; i < n; ++i)
+perm[i] = i;
+}
+
+static void
+xop_test (void)
+{
+  foo (8);
+
+  if (perm[7] != 7)
+__builtin_abort ();
+}


Re: [PATCH] Register --sysroot in the driver switches table

2022-01-05 Thread Olivier Hainque via Gcc-patches


> On 5 Jan 2022, at 10:26, Olivier Hainque  wrote:
> 
> The change should also set "validated" true 
> when requesting to save --sysroot.

The attached adjustment fixes the failure I could reproduce,
bootstraps and regtests fine on x86_64-linux, and passes a build
+ a couple of in-house testsuites for one of our vxworks ports.

Ok to commit?

Thanks in advance,

Olivier

2022-01-05  Olivier Hainque  

* gcc.c (driver_handle_option): State --sysroot as
validated.



0001-State-sysroot-option-as-validated-once-processed.patch
Description: Binary data


Re: [PATCH] middle-end/101530 - fix shufflevector lowering

2022-01-05 Thread Jeff Law via Gcc-patches




On 1/5/2022 7:17 AM, Richard Biener via Gcc-patches wrote:

This makes __builtin_shufflevector lowering force the result
of the BIT_FIELD_REF lowpart operation to a temporary as to
fulfil the IL verifier constraint that BIT_FIELD_REFs should
be always in outermost handled component position.  Trying to
enforce this during gimplification isn't as straight-forward
as here where we know we're dealing with an rvalue.

Bootstrap & regtest running on x86_64-unknown-linux-gnu - OK for trunk?

Thanks,
Richard.

2022-01-05  Richard Biener  

PR middle-end/101530
gcc/c-family/
* c-common.c (c_build_shufflevector): Wrap the BIT_FIELD_REF
in a TARGET_EXPR to force a temporary.

gcc/testsuite/
* c-c++-common/builtin-shufflevector-3.c: New testcase.

Seems quite reasonable to me.

jeff



Re: [PATCH] LTO plugin: modernize a bit.

2022-01-05 Thread Jeff Law via Gcc-patches




On 1/5/2022 4:06 AM, Martin Liška wrote:

The patch is about small refactoring of the plugin.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

include/ChangeLog:

* plugin-api.h (enum ld_plugin_tag): Do not set implicit enum
values.

lto-plugin/ChangeLog:

* lto-plugin.c (struct plugin_objfile): Use bool for offset
field.
(exec_lto_wrapper): Assign true/false to bool variables.
(process_offload_section): Likewise.
(claim_file_handler): Likewise.
(onload): Likewise.
I don't see anything controversial in here.  But the timing isn't 
great.  We're in stage3 and presumably moving into stage4 shortly. 
Shouldn't this wait until stage1 re-opens?


jeff



Re: [PATCH][Hashtable 6/6] PR 68303 small size optimization

2022-01-05 Thread Jonathan Wakely via Gcc-patches
On Sat, 25 Dec 2021 at 21:39, François Dumont  wrote:

> On 23/12/21 2:03 pm, Jonathan Wakely wrote:
> > On 21/12/21 07:07 +0100, François Dumont wrote:
> >> Hi
> >>
> >> ??? Is there a chance for this patch to be integrated for next gcc
> >> release ?
> >
> > Yes, I think this can still make it for GCC 12 (the patch was first
> > posted long ago in stage 1 and it's just me being slow to review it).
> >
> > But I have some questions and comments ...
> >
> >
> >> diff --git a/libstdc++-v3/include/bits/hashtable.h
> >> b/libstdc++-v3/include/bits/hashtable.h
> >> index 6e2d4c10cfe..6b2c6b99fef 100644
> >> --- a/libstdc++-v3/include/bits/hashtable.h
> >> +++ b/libstdc++-v3/include/bits/hashtable.h
> >> @@ -419,6 +419,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >>   _M_uses_single_bucket() const
> >>   { return _M_uses_single_bucket(_M_buckets); }
> >>
> >> +  static constexpr size_t
> >> +  __small_size_threshold()
> >> +  {
> >> +return
> >> + __detail::_Hashtable_hash_traits<_Hash>::__small_size_threshold();
> >> +  }
> >> +
> I've added the noexcept qualification as you asked.
> >>   __hashtable_alloc&
> >>   _M_base_alloc() { return *this; }
> >>
> >> @@ -788,6 +795,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >>   _M_bucket_index(__hash_code __c) const
> >>   { return __hash_code_base::_M_bucket_index(__c,
> >> _M_bucket_count); }
> >>
> >> +  __node_base_ptr
> >> +  _M_find_before_node(const key_type&);
> >> +
> >>   // Find and insert helper functions and types
> >>   // Find the node before the one matching the criteria.
> >>   __node_base_ptr
> >> @@ -831,6 +841,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >>   __node_base_ptr
> >>   _M_get_previous_node(size_type __bkt, __node_ptr __n);
> >>
> >> +  pair
> >> +  _M_compute_hash_code(const_iterator __hint, const key_type&
> >> __k) const;
> >> +
> >>   // Insert node __n with hash code __code, in bucket __bkt if no
> >>   // rehash (assumes no element with same key already present).
> >>   // Takes ownership of __n if insertion succeeds, throws otherwise.
> >> @@ -1126,7 +1139,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >>   void _M_rehash(size_type __bkt_count, const __rehash_state&
> >> __state);
> >> };
> >>
> >> -
> >>   // Definitions of class template _Hashtable's out-of-line member
> >> functions.
> >>   template >>typename _ExtractKey, typename _Equal,
> >> @@ -1628,6 +1640,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >> find(const key_type& __k)
> >> -> iterator
> >> {
> >> +  if (size() <= __small_size_threshold())
> >> +{
> >> +  for (auto __it = begin(); __it != end(); ++__it)
> >> +if (this->_M_key_equals(__k, *__it._M_cur))
> >> +  return __it;
> >> +  return end();
> >> +}
> >
> > This loop is repeated a few times, would it be better factored out
> > into its own function? _M_find_loop or something? The return type is
> > different in some cases, so maybe it's OK like this.
> Yes, I also thought about that but there is often small changes from one
> loop to another as you noticed.
> >
> >
> >
> >> +
> >>   __hash_code __code = this->_M_hash_code(__k);
> >>   std::size_t __bkt = _M_bucket_index(__code);
> >>   return iterator(_M_find_node(__bkt, __k, __code));
> >> @@ -1643,6 +1663,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >> find(const key_type& __k) const
> >> -> const_iterator
> >> {
> >> +  if (size() <= __small_size_threshold())
> >> +{
> >> +  for (auto __it = begin(); __it != end(); ++__it)
> >> +if (this->_M_key_equals(__k, *__it._M_cur))
> >> +  return __it;
> >> +  return end();
> >> +}
> >> +
> >>   __hash_code __code = this->_M_hash_code(__k);
> >>   std::size_t __bkt = _M_bucket_index(__code);
> >>   return const_iterator(_M_find_node(__bkt, __k, __code));
> >> @@ -1855,6 +1883,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >>   }
> >> #endif
> >>
> >> +  // Find the node before the one whose key compares equal to k.
> >> +  // Return nullptr if no node is found.
> >> +  template >> +   typename _ExtractKey, typename _Equal,
> >> +   typename _Hash, typename _RangeHash, typename _Unused,
> >> +   typename _RehashPolicy, typename _Traits>
> >> +auto
> >> +_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
> >> +   _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::
> >> +_M_find_before_node(const key_type& __k)
> >> +-> __node_base_ptr
> >> +{
> >> +  __node_base_ptr __prev_p = &_M_before_begin;
> >
> > This is OK now, but would need to be std::__addressof(_M_before_begin)
> > if/when the _Hash_code_base type becomes dependent on the allocator's
> > pointer.
> Yes, maybe after gcc release we will talk about those fancy pointer
> types again.
> >
> >  __n_last = __n_last->_M_next();
> >> diff --git a/libstdc++-v3/include/bits/hashtable_policy.h
> >> 

Re: [PATCH] libgomp, openmp: pinned memory

2022-01-05 Thread Andrew Stubbs

On 04/01/2022 18:47, Jakub Jelinek wrote:

On Tue, Jan 04, 2022 at 07:28:29PM +0100, Jakub Jelinek via Gcc-patches wrote:

Other issues in the patch are that it doesn't munlock on deallocation and
that because of that deallocation we need to figure out what to do on page
boundaries.  As documented, mlock can be passed address and/or address +
size that aren't at page boundaries and pinning happens even just for
partially touched pages.  But munlock unpins also even the partially
overlapping pages and we don't know at that point whether some other pinned
allocations don't appear in those pages.


Right, it doesn't munlock because of these issues. I don't know of any way
to solve this that wouldn't involve building tables of locked ranges (and
knowing what the page size is).

I considered using mmap with the lock flag instead, but the failure mode
looked unhelpful. I guess we could mmap with the regular flags, then mlock
after. That should bypass the regular heap and ensure each allocation has
it's own page. I'm not sure what the unintended side-effects of that might
be.


But the munlock is even more important because of the low ulimit -l, because
if munlock isn't done on deallocation, the by default I think 64KB limit
will be reached even much earlier.  If most users have just 64KB limit on
pinned memory per process, then that most likely asks for grabbing such memory
in whole pages and doing memory management on that resource.
Because vasting that precious memory on the partial pages which will most
likely get non-pinned allocations when we just have 16 such pages is a big
waste.


E.g. if we start using (dynamically, using dlopen/dlsym etc.) the memkind
library for some of the allocators, for the pinned memory we could use
e.g. the memkind_create_fixed API - on the first pinned allocation, check
what is the ulimit -l and if it is fairly small, mmap PROT_NONE the whole
pinned size (but don't pin it whole at start, just whatever we need as we
go).


I don't believe 64KB will be anything like enough for any real HPC 
application. Is it really worth optimizing for this case?


Anyway, I'm working on an implementation using mmap instead of malloc 
for pinned allocations. I figure that will simplify the unpin algorithm 
(because it'll be munmap) and optimize for large allocations such as I 
imagine HPC applications will use. It won't fix the ulimit issue.


Andrew


Re: [Patch][V2]Enable -Wuninitialized + -ftrivial-auto-var-init for address taken variables

2022-01-05 Thread Qing Zhao via Gcc-patches
Hi, Richard,

Thanks a lot for the review and questions.
See my reply embedded below:


> On Jan 5, 2022, at 4:33 AM, Richard Biener  wrote:
> 
> On Thu, Dec 16, 2021 at 5:00 PM Qing Zhao  wrote:
>> 
>> Hi,
>> 
>> This is the 2nd version of the patch.
>> The original patch is at:
>> 
>> https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586341.html
>> 
>> In addition to resolve the two issues mentioned in the original patch,
>> This patch also can be used as a very good workaround for the issue in 
>> PR103720
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103720
>> 
>> And as I checked, the patch can fix all the bogus uninitialized warnings when
>> building kernel with -O2 + -ftrivial-auto-var-init=zero + -Wuninitialized.
>> 
>> So, this is a very important patch that need to be included into gcc12.
>> 
>> Compared to the 1st patch, the major changes are to resolve Martin’s 
>> comments on
>> tree-ssa-uninit.c
>> 
>> 1.  Add some meaningful temporaries to break the long expression to make it
>> Readable. And also add comments to explain the purpose of the statement;
>> 
>> 2.  Resolve the memory leakage of the dynamically created string.
>> 
>> The patch has been bootstrapped and regressing tested on both x86 and 
>> aarch64, no issues.
>> Okay for commit?
> 
>  tree decl_name
> += build_string_literal (IDENTIFIER_LENGTH (DECL_NAME (decl)) + 1,
> +   IDENTIFIER_POINTER (DECL_NAME (decl)));
> 
> you need to deal with DECL_NAME being NULL.

Okay. 
Usually under what situation, the decl_name will be NULL?

>  It's also a bit awkward
> to build another
> copy of all decl names :/  

Yes, this is awkward. But it might be unavoidable for address taken variables 
since the original variable might be completely deleted by optimizations.
See the details at:
https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577431.html

We had a previous discussion on this issue, and the idea of adding this 3rd 
argument with the name of the variable was proposed by you at that time. -:)
And I think that’s a good solution to this problem.


> The changes in the uninit warning are also
> quite ugly, refactoring
> things to always pass down a name / location pair might improve that
> (but I'd like to
> understand the case to fix first).

I will try this idea to see whether it will work. 

> 
> + /* The LHS of the call is a temporary variable, we use it as a
> +placeholder to record the information on whether the warning
> +has been issued or not.  */
> + repl_var = gimple_call_lhs (def_stmt);
> 
> this seems to be a change that can be done independently?

The major purpose of this “repl_var” is used to record the info whether the 
warning has been issued for the variable or not, then avoid emitting it again 
later.
Since the original variable has been completely deleted by optimization, we 
have to use this “repl_var” for a placeholder to record such info.
> 
> + /* Ignore the call to .DEFERRED_INIT that define the original
> +var itself.  */
> + if (is_gimple_assign (context))
> +   {
> + if (TREE_CODE (gimple_assign_lhs (context)) == VAR_DECL)
> +   lhs_var = gimple_assign_lhs (context);
> + else if (TREE_CODE (gimple_assign_lhs (context)) == SSA_NAME)
> +   lhs_var = SSA_NAME_VAR (gimple_assign_lhs (context));
> +   }
> + if (lhs_var
> + && (lhs_var_name = DECL_NAME (lhs_var))
> + && (lhs_var_name_str = IDENTIFIER_POINTER (lhs_var_name))
> + && (strcmp (lhs_var_name_str, var_name_str) == 0))
> +   return;
> 
> likewise but I don't really understand what you are doing here.

The above is to exclude the following case:

   temp = .DEFERRED_INIT (4, 2, “alt_reloc");
   alt_reloc = temp;

i.e, a call to .DEFERRED_INIT that define the original variable itself.

>  I'm
> also not sure
> I understand the case we try to fix with passing the name - is that
> for VLA decls
> that get replaced by allocation?

This whole patch is mainly to resolve the issue that has been discussed last 
Aug as:

https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577431.html

We have agreed at that time to resolve this issue later.

And this patch is to resolve this issue.
Hope this is clear.

Thanks.

Qimg


> 
> The patch adjusts testcases but doesn't add new ones but each of the
> above changes
> would warrant one and make it easier to understand the motivation of
> the changes.
> 
> Richard.
> 
>> thanks.
>> 
>> Qing
>> 
>> =
>> 
>> **Compared to the 1st version, the code change is:
>> 
>> --- a/gcc/tree-ssa-uninit.c
>> +++ b/gcc/tree-ssa-uninit.c
>> @@ -182,9 +182,22 @@ warn_uninit (opt_code opt, tree t, tree var, const char 
>> *gmsgid,
>> @@ -798,26 +798,35 @@
>>if (!var && !SSA_NAME_VAR (t))
>>  {
>>gimple *def_stmt = SSA_NAME_DEF_STMT (t);
>> -@@ 

[committed] libstdc++: Fix overconstrained std::string constructor [PR103919]

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


The C++17 basic_string(const T&, size_t, size_t) constructor is
overconstrained, so it can't be used for a NTBS and a temporary string
gets constructed (potentially allocating memory). There is no
corresponding constructor taking an NTBS, so no need to disambiguate
from it. Accepting an NTBS avoids the temporary (and potential
allocation) and is what the standard requires.

libstdc++-v3/ChangeLog:

PR libstdc++/103919
* include/bits/basic_string.h (basic_string(const T&, size_t, size_t)):
Relax constraints on string_view parameter.
* include/bits/cow_string.h (basic_string(const T&, size_t, size_t)):
Likewise.
* testsuite/21_strings/basic_string/cons/char/103919.cc: New test.
---
 libstdc++-v3/include/bits/basic_string.h  |  3 +-
 libstdc++-v3/include/bits/cow_string.h|  3 +-
 .../basic_string/cons/char/103919.cc  | 43 +++
 3 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 
libstdc++-v3/testsuite/21_strings/basic_string/cons/char/103919.cc

diff --git a/libstdc++-v3/include/bits/basic_string.h 
b/libstdc++-v3/include/bits/basic_string.h
index 463cef25b6e..a91ba5114b1 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -766,7 +766,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*  @param  __n   The number of characters to copy from __t.
*  @param  __a   Allocator to use.
*/
-  template>
+  template>>
_GLIBCXX20_CONSTEXPR
basic_string(const _Tp& __t, size_type __pos, size_type __n,
 const _Alloc& __a = _Alloc())
diff --git a/libstdc++-v3/include/bits/cow_string.h 
b/libstdc++-v3/include/bits/cow_string.h
index 8d0b7727be4..84aab2f33c6 100644
--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -690,7 +690,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*  @param  __n   The number of characters to copy from __t.
*  @param  __a   Allocator to use.
*/
-  template>
+  template>>
basic_string(const _Tp& __t, size_type __pos, size_type __n,
 const _Alloc& __a = _Alloc())
: basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { }
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/103919.cc 
b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/103919.cc
new file mode 100644
index 000..94400e319ff
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/103919.cc
@@ -0,0 +1,43 @@
+// { dg-do run { target c++17 } }
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+std::size_t counter = 0;
+
+void* operator new(std::size_t n)
+{
+  counter += n;
+  return std::malloc(n);
+}
+
+void operator delete(void* p)
+{
+  std::free(p);
+}
+
+void operator delete(void* p, std::size_t)
+{
+  std::free(p);
+}
+
+int main()
+{
+  const char* str = "A string that is considerably longer than the SSO buffer";
+
+  // PR libstdc++/103919
+  // basic_string(const T&, size_t, size_t) constructor is overconstrained
+  counter = 0;
+  std::string s(str, 2, 6);
+  VERIFY( s == "string" );
+#if _GLIBCXX_USE_CXX11_ABI
+  // The string fits in the SSO buffer, so nothing is allocated.
+  VERIFY( counter == 0 );
+#else
+  // The COW string allocates a string rep and 7 chars.
+  VERIFY( counter < std::strlen(str) );
+#endif
+}
-- 
2.31.1



[committed] libstdc++: Implement P1328 "Making std::type_info::operator== constexpr"

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


This feature is present in the C++23 draft.

With Jakub's recent front-end changes we can implement constexpr
equality by comparing the addresses of std::type_info objects. We do not
need string comparisons, because for constant evaluation cases we know
we aren't dealing with std::type_info objects defined in other
translation units.

The ARM EABI requires that the type_info::operator== function can be
defined out-of-line (and suggests that should be the default), but to be
a constexpr function it must be defined inline (at least for C++23
mode). To meet these conflicting requirements we make the inline version
of operator== call a new __equal function when called at runtime. That
is an alias for the non-inline definition of operator== defined in
libsupc++.

libstdc++-v3/ChangeLog:

* config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Export new symbol for
ARM EABI.
* include/bits/c++config (_GLIBCXX23_CONSTEXPR): Define.
* include/std/version (__cpp_lib_constexpr_typeinfo): Define.
* libsupc++/tinfo.cc: Add #error to ensure non-inline definition
is emitted.
(type_info::__equal): Define alias symbol.
* libsupc++/typeinfo (type_info::before): Combine different
implementations into one.
(type_info::operator==): Likewise. Use address equality for
constant evaluation. Call __equal for targets that require the
definition to be non-inline.
* testsuite/18_support/type_info/constexpr.cc: New test.
---
 libstdc++-v3/config/abi/pre/gnu.ver   |  3 +
 libstdc++-v3/include/bits/c++config   | 10 +-
 libstdc++-v3/include/std/version  |  1 +
 libstdc++-v3/libsupc++/tinfo.cc   |  7 ++
 libstdc++-v3/libsupc++/typeinfo   | 96 ---
 .../18_support/type_info/constexpr.cc | 48 ++
 6 files changed, 131 insertions(+), 34 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/18_support/type_info/constexpr.cc

diff --git a/libstdc++-v3/config/abi/pre/gnu.ver 
b/libstdc++-v3/config/abi/pre/gnu.ver
index c2f09a9290a..afd242b32aa 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -2424,6 +2424,9 @@ GLIBCXX_3.4.30 {
 # std::__timepunct::_M_am_pm_format(const char**)
 _ZNKSt11__timepunctI[cw]E15_M_am_pm_formatEPPK[cw];
 
+# Only defined #if ! __GXX_TYPEINFO_EQUALITY_INLINE
+_ZNKSt9type_info7__equalERKS_;
+
 } GLIBCXX_3.4.29;
 
 # Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 3609793c0e6..c64b61b3c90 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -175,13 +175,21 @@
 #endif
 
 #ifndef _GLIBCXX20_CONSTEXPR
-# if __cplusplus > 201703L
+# if __cplusplus >= 202002L
 #  define _GLIBCXX20_CONSTEXPR constexpr
 # else
 #  define _GLIBCXX20_CONSTEXPR
 # endif
 #endif
 
+#ifndef _GLIBCXX23_CONSTEXPR
+# if __cplusplus >= 202100L
+#  define _GLIBCXX23_CONSTEXPR constexpr
+# else
+#  define _GLIBCXX23_CONSTEXPR
+# endif
+#endif
+
 #ifndef _GLIBCXX17_INLINE
 # if __cplusplus >= 201703L
 #  define _GLIBCXX17_INLINE inline
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index 58760e69be8..f421056964e 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -295,6 +295,7 @@
 // c++2b
 #define __cpp_lib_adaptor_iterator_pair_constructor 202106L
 #define __cpp_lib_byteswap 202110L
+#define __cpp_lib_constexpr_typeinfo 202106L
 #define __cpp_lib_invoke_r 202106L
 #define __cpp_lib_ios_noreplace 202200L
 #define __cpp_lib_is_scoped_enum 202011L
diff --git a/libstdc++-v3/libsupc++/tinfo.cc b/libstdc++-v3/libsupc++/tinfo.cc
index f38472020d2..ef13dd33064 100644
--- a/libstdc++-v3/libsupc++/tinfo.cc
+++ b/libstdc++-v3/libsupc++/tinfo.cc
@@ -32,6 +32,10 @@ std::type_info::
 
 #if !__GXX_TYPEINFO_EQUALITY_INLINE
 
+#if __cplusplus > 202002L
+# error "this file must be compiled with C++20 or older to define operator=="
+#endif
+
 // We can't rely on common symbols being shared between shared objects.
 bool std::type_info::
 operator== (const std::type_info& arg) const _GLIBCXX_NOEXCEPT
@@ -47,6 +51,9 @@ operator== (const std::type_info& arg) const _GLIBCXX_NOEXCEPT
 #endif
 }
 
+bool
+std::type_info::__equal (const std::type_info& arg) const _GLIBCXX_NOEXCEPT
+__attribute__((alias("_ZNKSt9type_infoeqERKS_")));
 #endif
 
 namespace std {
diff --git a/libstdc++-v3/libsupc++/typeinfo b/libstdc++-v3/libsupc++/typeinfo
index 91c30997403..3018a510fd5 100644
--- a/libstdc++-v3/libsupc++/typeinfo
+++ b/libstdc++-v3/libsupc++/typeinfo
@@ -38,6 +38,10 @@
 
 #pragma GCC visibility push(default)
 
+#if __cplusplus >= 202100L
+# define __cpp_lib_constexpr_typeinfo 202106L
+#endif
+
 extern "C++" {
 
 namespace __cxxabiv1
@@ -99,40 +103,12 @@ namespace std
 const char* name() 

[committed] libstdc++: Improvements to standard error category objects (part deux)

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


In r12-3860 the error categories in  were made final and
immortal, but I missed the categories for  and . This makes
the same changes to those.

libstdc++-v3/ChangeLog:

* src/c++11/cxx11-ios_failure.cc (io_error_category): Define
class and virtual functions as 'final'.
(io_category_instance): Use constinit union to make the object
immortal.
* src/c++11/future.cc (future_error_category): Define class and
virtual functions as 'final'.
(future_category_instance): Use constinit union.
---
 libstdc++-v3/src/c++11/cxx11-ios_failure.cc | 25 
 libstdc++-v3/src/c++11/future.cc| 26 +
 2 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/libstdc++-v3/src/c++11/cxx11-ios_failure.cc 
b/libstdc++-v3/src/c++11/cxx11-ios_failure.cc
index 5a151b6ec5c..ba4b1413bf9 100644
--- a/libstdc++-v3/src/c++11/cxx11-ios_failure.cc
+++ b/libstdc++-v3/src/c++11/cxx11-ios_failure.cc
@@ -44,14 +44,15 @@
 
 namespace
 {
-  struct io_error_category : std::error_category
+  struct io_error_category final : std::error_category
   {
-virtual const char*
-name() const noexcept
+const char*
+name() const noexcept final
 { return "iostream"; }
 
 _GLIBCXX_DEFAULT_ABI_TAG
-virtual std::string message(int __ec) const
+std::string
+message(int __ec) const final
 {
   std::string __msg;
   switch (std::io_errc(__ec))
@@ -67,13 +68,17 @@ namespace
 }
   };
 
-  const io_error_category&
-  __io_category_instance() noexcept
+  struct constant_init
   {
-static const io_error_category __ec{};
-return __ec;
-  }
+union {
+  unsigned char unused;
+  io_error_category cat;
+};
+constexpr constant_init() : cat() { }
+~constant_init() { /* do nothing, union member is not destroyed */ }
+  };
 
+  __constinit constant_init io_category_instance{};
 } // namespace
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -82,7 +87,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   const error_category&
   iostream_category() noexcept
-  { return __io_category_instance(); }
+  { return io_category_instance.cat; }
 
   ios_base::failure::failure(const string& __str)
   : system_error(io_errc::stream, __str) { }
diff --git a/libstdc++-v3/src/c++11/future.cc b/libstdc++-v3/src/c++11/future.cc
index c5423931eb3..488ff17a1e6 100644
--- a/libstdc++-v3/src/c++11/future.cc
+++ b/libstdc++-v3/src/c++11/future.cc
@@ -27,14 +27,15 @@
 
 namespace
 {
-  struct future_error_category : public std::error_category
+  struct future_error_category final : public std::error_category
   {
-virtual const char*
-name() const noexcept
+const char*
+name() const noexcept final
 { return "future"; }
 
 _GLIBCXX_DEFAULT_ABI_TAG
-virtual std::string message(int __ec) const
+std::string
+message(int __ec) const final
 {
   std::string __msg;
   switch (std::future_errc(__ec))
@@ -59,12 +60,17 @@ namespace
 }
   };
 
-  const future_error_category&
-  __future_category_instance() noexcept
+  struct constant_init
   {
-static const future_error_category __fec{};
-return __fec;
-  }
+union {
+  unsigned char unused;
+  future_error_category cat;
+};
+constexpr constant_init() : cat() { }
+~constant_init() { /* do nothing, union member is not destroyed */ }
+  };
+
+  __constinit constant_init future_category_instance{};
 }
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -76,7 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { _GLIBCXX_THROW_OR_ABORT(future_error(make_error_code(future_errc(__i; }
 
   const error_category& future_category() noexcept
-  { return __future_category_instance(); }
+  { return future_category_instance.cat; }
 
   future_error::~future_error() noexcept { }
 
-- 
2.31.1



[committed] libstdc++: Fix std::error_code pretty printer for versioned namespace

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdErrorCodePrinter): Strip
versioned namespace from the type name that is printed.
---
 libstdc++-v3/python/libstdcxx/v6/printers.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py 
b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 44f1148d5ab..b3f4956381b 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1522,7 +1522,7 @@ class StdErrorCodePrinter:
 
 def __init__ (self, typename, val):
 self.val = val
-self.typename = typename
+self.typename = strip_versioned_namespace(typename)
 # Do this only once ...
 if StdErrorCodePrinter._errno_categories is None:
 StdErrorCodePrinter._errno_categories = ['generic']
-- 
2.31.1



Re: [PATCH] libgomp, OpenMP, nvptx: Low-latency memory allocator

2022-01-05 Thread Andrew Stubbs

On 05/01/2022 13:04, Tom de Vries wrote:

On 1/5/22 12:08, Tom de Vries wrote:

The allocators-1.c test-case doesn't compile because:
...
FAIL: libgomp.c/allocators-1.c (test for excess errors)
Excess errors:
/home/vries/oacc/trunk/source-gcc/libgomp/testsuite/libgomp.c/allocators-1.c:7:22: 
sorry, unimplemented: '    ' clause on 'requires' directive not 
supported yet


UNRESOLVED: libgomp.c/allocators-1.c compilation failed to produce 
executable

...

So, I suppose I need "[PATCH] OpenMP front-end: allow requires 
dynamic_allocators" as well, I'll try again with that applied.


After applying that, I get:
...
WARNING: program timed out.
FAIL: libgomp.c/allocators-2.c execution test
WARNING: program timed out.
FAIL: libgomp.c/allocators-3.c execution test
...


It works for me.

Those tests are doing some large number of allocations repeatedly and in 
parallel to stress the atomics. They're also slightly longer running 
than the other tests.
  - allocators-2 calls omp_alloc 8080 times, over 16 kernel launches, 
some of which will fall back to PTX malloc.
  - allocators-3 calls omp_alloc and omp_free 8 million times each, 
over 8 kernel launches, and takes about a minute to run on my device 
(whether that falls back depends entirely on how the free calls interleave).


Either there is a flaw in the concurrency causing some kind of deadlock, 
or else your timeout is set too short for your device. I hope it's the 
latter. We may need to tweak this.


Andrew


Re: [PATCH] libgomp, OpenMP, nvptx: Low-latency memory allocator

2022-01-05 Thread Andrew Stubbs

On 05/01/2022 11:08, Tom de Vries wrote:
The alloc-7.c execution test failure is a regression, AFAICT.  It fails 
here:

...
38    if uintptr_t) p) % __alignof (int)) != 0 || p[0] || p[1] 
|| p[2])

39  abort ();
...
because:
...
(gdb) p p[0]
$2 = 772014104
(gdb) p p[1]
$3 = 0
(gdb) p p[2]
$4 = 9
...

In other words, the pointer returned by omp_calloc does not point to 
zeroed out memory.


The version that was applied to OG11 had this bug fixed, but I didn't 
get around to posting the update because Christmas got in the way and 
it's gone out of my mind, sorry.


The attached patch has the fix and also removes the hunk related to the 
PTX update.


Andrew
libgomp, nvptx: low-latency memory allocator

This patch adds support for allocating low-latency ".shared" memory on
NVPTX GPU device, via the omp_low_lat_mem_space and omp_alloc.  The memory
can be allocated, reallocated, and freed using a basic but fast algorithm,
is thread safe and the size of the low-latency heap can be configured using
the GOMP_NVPTX_LOWLAT_POOL environment variable.

The use of the PTX dynamic_smem_size feature means that the minimum version
requirement is now bumped to 4.1 (still old at this point).

libgomp/ChangeLog:

* allocator.c (MEMSPACE_ALLOC): New macro.
(MEMSPACE_CALLOC): New macro.
(MEMSPACE_REALLOC): New macro.
(MEMSPACE_FREE): New macro.
(dynamic_smem_size): New constants.
(omp_alloc): Use MEMSPACE_ALLOC.
Implement fall-backs for predefined allocators.
(omp_free): Use MEMSPACE_FREE.
(omp_calloc): Use MEMSPACE_CALLOC.
Implement fall-backs for predefined allocators.
(omp_realloc): Use MEMSPACE_REALLOC.
Implement fall-backs for predefined allocators.
* config/nvptx/team.c (__nvptx_lowlat_heap_root): New variable.
(__nvptx_lowlat_pool): New asm varaible.
(gomp_nvptx_main): Initialize the low-latency heap.
* plugin/plugin-nvptx.c (lowlat_pool_size): New variable.
(GOMP_OFFLOAD_init_device): Read the GOMP_NVPTX_LOWLAT_POOL envvar.
(GOMP_OFFLOAD_run): Apply lowlat_pool_size.
* config/nvptx/allocator.c: New file.
* testsuite/libgomp.c/allocators-1.c: New test.
* testsuite/libgomp.c/allocators-2.c: New test.
* testsuite/libgomp.c/allocators-3.c: New test.
* testsuite/libgomp.c/allocators-4.c: New test.
* testsuite/libgomp.c/allocators-5.c: New test.
* testsuite/libgomp.c/allocators-6.c: New test.

diff --git a/libgomp/allocator.c b/libgomp/allocator.c
index 07a5645f4cc..b1f5fe0a5e2 100644
--- a/libgomp/allocator.c
+++ b/libgomp/allocator.c
@@ -34,6 +34,38 @@
 
 #define omp_max_predefined_alloc omp_thread_mem_alloc
 
+/* These macros may be overridden in config//allocator.c.  */
+#ifndef MEMSPACE_ALLOC
+#define MEMSPACE_ALLOC(MEMSPACE, SIZE) \
+  ((void)MEMSPACE, malloc (SIZE))
+#endif
+#ifndef MEMSPACE_CALLOC
+#define MEMSPACE_CALLOC(MEMSPACE, SIZE) \
+  ((void)MEMSPACE, calloc (1, SIZE))
+#endif
+#ifndef MEMSPACE_REALLOC
+#define MEMSPACE_REALLOC(MEMSPACE, ADDR, OLDSIZE, SIZE) \
+  ((void)MEMSPACE, (void)OLDSIZE, realloc (ADDR, SIZE))
+#endif
+#ifndef MEMSPACE_FREE
+#define MEMSPACE_FREE(MEMSPACE, ADDR, SIZE) \
+  ((void)MEMSPACE, (void)SIZE, free (ADDR))
+#endif
+
+/* Map the predefined allocators to the correct memory space.
+   The index to this table is the omp_allocator_handle_t enum value.  */
+static const omp_memspace_handle_t predefined_alloc_mapping[] = {
+  omp_default_mem_space,   /* omp_null_allocator. */
+  omp_default_mem_space,   /* omp_default_mem_alloc. */
+  omp_large_cap_mem_space, /* omp_large_cap_mem_alloc. */
+  omp_default_mem_space,   /* omp_const_mem_alloc. */
+  omp_high_bw_mem_space,   /* omp_high_bw_mem_alloc. */
+  omp_low_lat_mem_space,   /* omp_low_lat_mem_alloc. */
+  omp_low_lat_mem_space,   /* omp_cgroup_mem_alloc. */
+  omp_low_lat_mem_space,   /* omp_pteam_mem_alloc. */
+  omp_low_lat_mem_space,   /* omp_thread_mem_alloc. */
+};
+
 struct omp_allocator_data
 {
   omp_memspace_handle_t memspace;
@@ -281,7 +313,7 @@ retry:
   allocator_data->used_pool_size = used_pool_size;
   gomp_mutex_unlock (_data->lock);
 #endif
-  ptr = malloc (new_size);
+  ptr = MEMSPACE_ALLOC (allocator_data->memspace, new_size);
   if (ptr == NULL)
{
 #ifdef HAVE_SYNC_BUILTINS
@@ -297,7 +329,10 @@ retry:
 }
   else
 {
-  ptr = malloc (new_size);
+  omp_memspace_handle_t memspace = (allocator_data
+   ? allocator_data->memspace
+   : predefined_alloc_mapping[allocator]);
+  ptr = MEMSPACE_ALLOC (memspace, new_size);
   if (ptr == NULL)
goto fail;
 }
@@ -315,32 +350,35 @@ retry:
   return ret;
 
 fail:
-  if (allocator_data)
+  int fallback = (allocator_data
+ ? allocator_data->fallback
+ : allocator == omp_default_mem_alloc
+  

[PATCH] middle-end/101530 - fix shufflevector lowering

2022-01-05 Thread Richard Biener via Gcc-patches
This makes __builtin_shufflevector lowering force the result
of the BIT_FIELD_REF lowpart operation to a temporary as to
fulfil the IL verifier constraint that BIT_FIELD_REFs should
be always in outermost handled component position.  Trying to
enforce this during gimplification isn't as straight-forward
as here where we know we're dealing with an rvalue.

Bootstrap & regtest running on x86_64-unknown-linux-gnu - OK for trunk?

Thanks,
Richard.

2022-01-05  Richard Biener  

PR middle-end/101530
gcc/c-family/
* c-common.c (c_build_shufflevector): Wrap the BIT_FIELD_REF
in a TARGET_EXPR to force a temporary.

gcc/testsuite/
* c-c++-common/builtin-shufflevector-3.c: New testcase.
---
 gcc/c-family/c-common.c   |  5 +
 .../c-c++-common/builtin-shufflevector-3.c| 15 +++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/builtin-shufflevector-3.c

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 13341fa315e..64209303d54 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -1243,6 +1243,11 @@ c_build_shufflevector (location_t loc, tree v0, tree v1,
   tree lpartt = build_vector_type (TREE_TYPE (ret_type), mask.length ());
   ret = build3_loc (loc, BIT_FIELD_REF,
lpartt, ret, TYPE_SIZE (lpartt), bitsize_zero_node);
+  /* Wrap the lowpart operation in a TARGET_EXPR so it gets a separate
+temporary during gimplification.  See PR101530 for cases where
+we'd otherwise end up with non-toplevel BIT_FIELD_REFs.  */
+  tree tem = create_tmp_var_raw (lpartt);
+  ret = build4 (TARGET_EXPR, lpartt, tem, ret, NULL_TREE, NULL_TREE);
 }
 
   if (!c_dialect_cxx () && !wrap)
diff --git a/gcc/testsuite/c-c++-common/builtin-shufflevector-3.c 
b/gcc/testsuite/c-c++-common/builtin-shufflevector-3.c
new file mode 100644
index 000..0c9bda689ef
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/builtin-shufflevector-3.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+typedef int __attribute__((__vector_size__ (sizeof(int)*4))) V;
+
+int
+foo(V v, int i)
+{
+  return __builtin_shufflevector (v, v, 2, 3)[i];
+}
+
+int
+bar(V v, int i)
+{
+  return __builtin_shufflevector(v, v, 4)[0] & i;
+}
-- 
2.31.1


Re: [PATCH v4 00/12] Add LoongArch support.

2022-01-05 Thread Paul Hua via Gcc-patches
Hi all,

Ping?

By the way, the LoongArch machine is already connected to the Cfarm
and will be announced soon.
You can login through ssh.
ssh -l your-cfarm-user-name -p 25469 114.242.206.180


On Fri, Dec 24, 2021 at 5:28 PM chenglulu  wrote:
>
> The LoongArch architecture (LoongArch) is an Instruction Set
> Architecture (ISA) that has a Reduced Instruction Set Computer (RISC)
> style.
> The documents are on
> https://loongson.github.io/LoongArch-Documentation/README-EN.html
>
> The ELF ABI Documents are on:
> https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
>
> The binutils has been merged into trunk:
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=560b3fe208255ae909b4b1c88ba9c28b09043307
>
> Note: We split -mabi= into -mabi=lp64d/f/s, the new options not support by 
> upstream binutils yet,
> this GCC port requires the following patch applied to binutils to build.
> https://github.com/loongson/binutils-gdb/commit/aacb0bf860f02aa5a7dcb76dd0e392bf871c7586
> (will be submitted to upstream after gcc side comfirmed)
>
>
> changelog:
>
> v1 -> v2
> 1. Split patch set.
> 2. Change some code style.
> 3. Add -mabi=lp64d/f/s options.
> 4. Change GLIBC_DYNAMIC_LINKER_LP64 name.
>
> v2 -> v3
> 1. Change some code style.
> 2. Bug fix.
>
> v3 -> v4
> 1. Change some code style.
> 2. Bug fix.
> 3. Delete some builtin macros.
>
> Add LoongArch support.
>
> chenglulu (12):
>   LoongArch Port: Regenerate configure
>   LoongArch Port: gcc build
>   LoongArch Port: Regenerate gcc/configure.
>   LoongArch Port: Machine Decsription files.
>   LoongArch Port: Machine description C files and .h files.
>   LoongArch Port: Builtin functions.
>   LoongArch Port: Builtin macros.
>   LoongArch Port: libgcc
>   LoongArch Port: Regenerate libgcc/configure.
>   LoongArch Port: libgomp
>   LoongArch Port: gcc/testsuite
>   LoongArch Port: Add doc.
>
>  config/picflag.m4 |3 +
>  configure |   10 +-
>  configure.ac  |   10 +-
>  contrib/config-list.mk|5 +-
>  .../config/loongarch/loongarch-common.c   |   63 +
>  gcc/config.gcc|  400 +-
>  gcc/config/host-linux.c   |2 +
>  gcc/config/loongarch/constraints.md   |  212 +
>  gcc/config/loongarch/generic.md   |  132 +
>  gcc/config/loongarch/genopts/genstr.sh|   91 +
>  .../loongarch/genopts/loongarch-strings   |   58 +
>  gcc/config/loongarch/genopts/loongarch.opt.in |  189 +
>  gcc/config/loongarch/gnu-user.h   |   78 +
>  gcc/config/loongarch/la464.md |  132 +
>  gcc/config/loongarch/larchintrin.h|  413 ++
>  gcc/config/loongarch/linux.h  |   50 +
>  gcc/config/loongarch/loongarch-builtins.c |  511 ++
>  gcc/config/loongarch/loongarch-c.c|  111 +
>  gcc/config/loongarch/loongarch-cpu.c  |  206 +
>  gcc/config/loongarch/loongarch-cpu.h  |   30 +
>  gcc/config/loongarch/loongarch-def.c  |  164 +
>  gcc/config/loongarch/loongarch-def.h  |  151 +
>  gcc/config/loongarch/loongarch-driver.c   |  187 +
>  gcc/config/loongarch/loongarch-driver.h   |   69 +
>  gcc/config/loongarch/loongarch-ftypes.def |  106 +
>  gcc/config/loongarch/loongarch-modes.def  |   29 +
>  gcc/config/loongarch/loongarch-opts.c |  582 ++
>  gcc/config/loongarch/loongarch-opts.h |   86 +
>  gcc/config/loongarch/loongarch-protos.h   |  242 +
>  gcc/config/loongarch/loongarch-str.h  |   57 +
>  gcc/config/loongarch/loongarch-tune.h |   72 +
>  gcc/config/loongarch/loongarch.c  | 6461 +
>  gcc/config/loongarch/loongarch.h  | 1291 
>  gcc/config/loongarch/loongarch.md | 3829 ++
>  gcc/config/loongarch/loongarch.opt|  189 +
>  gcc/config/loongarch/predicates.md|  553 ++
>  gcc/config/loongarch/sync.md  |  574 ++
>  gcc/config/loongarch/t-linux  |   53 +
>  gcc/config/loongarch/t-loongarch  |   59 +
>  gcc/configure |   85 +-
>  gcc/configure.ac  |   33 +-
>  gcc/doc/install.texi  |   47 +-
>  gcc/doc/invoke.texi   |  201 +
>  gcc/doc/md.texi   |   55 +
>  gcc/testsuite/g++.dg/cpp0x/constexpr-rom.C|2 +-
>  gcc/testsuite/g++.old-deja/g++.abi/ptrmem.C   |2 +-
>  gcc/testsuite/g++.old-deja/g++.pt/ptrmem6.C   |2 +-
>  gcc/testsuite/gcc.dg/20020312-2.c |2 +
>  gcc/testsuite/gcc.dg/loop-8.c |2 +-
>  .../torture/stackalign/builtin-apply-2.c  |2 +-
>  gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-3.c |2 +-
>  .../gcc.target/loongarch/loongarch.exp|   40 +
>  .../gcc.target/loongarch/tst-asm-const.c   

[committed] libstdc++: Add pretty printer for std::regex internals

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


This helps visualize the NFA states in a std::regex.  It probably isn't
very useful for users, but helps when working on the implementation.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdRegexStatePrinter): New
printer for std::regex NFA states.
---
 libstdc++-v3/python/libstdcxx/v6/printers.py | 32 
 1 file changed, 32 insertions(+)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py 
b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 84a54698c17..44f1148d5ab 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1554,6 +1554,34 @@ class StdErrorCodePrinter:
 pass
 return '%s = {"%s": %s}' % (self.typename, category, strval)
 
+class StdRegexStatePrinter:
+"Print a state node in the NFA for a std::regex"
+
+def __init__ (self, typename, val):
+self.val = val
+self.typename = typename
+
+def to_string (self):
+opcode = str(self.val['_M_opcode'])
+if opcode:
+opcode = opcode[25:]
+next_id = self.val['_M_next']
+
+variants = {'repeat':'alt', 'alternative':'alt',
+'subexpr_begin':'subexpr', 'subexpr_end':'subexpr',
+'line_begin_assertion':None, 'line_end_assertion':None,
+'word_boundary':'neg', 'subexpr_lookahead':'neg',
+'backref':'backref_index',
+'match':None, 'accept':None,
+'dummy':None, 'unknown':None
+   }
+v = variants[opcode]
+
+s = "opcode={}, next={}".format(opcode, next_id)
+if v is not None and self.val['_M_' + v] is not None:
+s = "{}, {}={}".format(s, v, self.val['_M_' + v])
+return "{%s}" % (s)
+
 # A "regular expression" printer which conforms to the
 # "SubPrettyPrinter" protocol from gdb.printing.
 class RxPrinter(object):
@@ -2015,6 +2043,10 @@ def build_libstdcxx_dictionary ():
 libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset',
   Tr1UnorderedSetPrinter)
 
+# std::regex components
+libstdcxx_printer.add_version('std::__detail::', '_State',
+  StdRegexStatePrinter)
+
 # These are the C++11 printer registrations for -D_GLIBCXX_DEBUG cases.
 # The tr1 namespace containers do not have any debug equivalents,
 # so do not register printers for them.
-- 
2.31.1



[committed] libstdc++: Fix comments in std::forward_list tests

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


libstdc++-v3/ChangeLog:

* testsuite/23_containers/forward_list/operations/1.cc: Fill in
placeholders in comments.
* testsuite/23_containers/forward_list/operations/2.cc:
Likewise.
* testsuite/23_containers/forward_list/operations/3.cc:
Likewise.
* testsuite/23_containers/forward_list/operations/4.cc:
Likewise.
* testsuite/23_containers/forward_list/operations/5.cc:
Likewise.
* testsuite/23_containers/forward_list/operations/6.cc:
Likewise.
* testsuite/23_containers/forward_list/operations/7.cc:
Likewise.
---
 .../testsuite/23_containers/forward_list/operations/1.cc  | 8 
 .../testsuite/23_containers/forward_list/operations/2.cc  | 2 +-
 .../testsuite/23_containers/forward_list/operations/3.cc  | 2 +-
 .../testsuite/23_containers/forward_list/operations/4.cc  | 2 +-
 .../testsuite/23_containers/forward_list/operations/5.cc  | 4 ++--
 .../testsuite/23_containers/forward_list/operations/6.cc  | 4 ++--
 .../testsuite/23_containers/forward_list/operations/7.cc  | 4 ++--
 7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/1.cc 
b/libstdc++-v3/testsuite/23_containers/forward_list/operations/1.cc
index 776e672513d..32b10fc3975 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/operations/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/1.cc
@@ -17,13 +17,13 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
+// C++11 23.3.4.6 Operations [forwardlist.ops]
 
 #include 
 #include 
 
 // This test verifies the following:
-//   
+//   splice_after for entire list
 void
 test01()
 {
@@ -41,7 +41,7 @@ test01()
 }
 
 // This test verifies the following:
-//   
+//   splice_after for iterator range
 void
 test02()
 {
@@ -70,7 +70,7 @@ test02()
 }
 
 // This test verifies the following:
-//   
+//   splice_after for single element
 void
 test03()
 {
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/2.cc 
b/libstdc++-v3/testsuite/23_containers/forward_list/operations/2.cc
index ed6d12ad2bc..9885392df32 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/operations/2.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/2.cc
@@ -17,7 +17,7 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
+// C++11 23.3.4.6 Operations [forwardlist.ops]
 
 #include 
 #include 
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/3.cc 
b/libstdc++-v3/testsuite/23_containers/forward_list/operations/3.cc
index f0d7cd1878e..f67ecd13dff 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/operations/3.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/3.cc
@@ -17,7 +17,7 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
+// C++11 23.3.4.6 Operations [forwardlist.ops]
 
 #include 
 #include 
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/4.cc 
b/libstdc++-v3/testsuite/23_containers/forward_list/operations/4.cc
index 06fa0742f32..92fd0a006d8 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/operations/4.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/4.cc
@@ -17,7 +17,7 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
+// C++11 23.3.4.6 Operations [forwardlist.ops]
 
 #include 
 #include 
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/5.cc 
b/libstdc++-v3/testsuite/23_containers/forward_list/operations/5.cc
index 9b94f7e9c72..a772c36793c 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/operations/5.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/5.cc
@@ -17,13 +17,13 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
+// C++11 23.3.4.6 Operations [forwardlist.ops]
 
 #include 
 #include 
 
 // This test verifies the following:
-//   
+//   merge
 void
 test01()
 {
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/6.cc 
b/libstdc++-v3/testsuite/23_containers/forward_list/operations/6.cc
index ed6d7d36b8d..cd3c74bd08d 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/operations/6.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/6.cc
@@ -17,7 +17,7 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
+// 

[committed] libstdc++: Avoid -Wzero-as-null-pointer-constant warning [PR103848]

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


libstdc++-v3/ChangeLog:

PR libstdc++/103848
* include/bits/stl_deque.h (operator-): Do not use 0 as null
pointer constant.
---
 libstdc++-v3/include/bits/stl_deque.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_deque.h 
b/libstdc++-v3/include/bits/stl_deque.h
index e4c53d56068..7fa9b0b3c09 100644
--- a/libstdc++-v3/include/bits/stl_deque.h
+++ b/libstdc++-v3/include/bits/stl_deque.h
@@ -370,7 +370,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   operator-(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT
   {
return difference_type(_S_buffer_size())
- * (__x._M_node - __y._M_node - int(__x._M_node != 0))
+ * (__x._M_node - __y._M_node - bool(__x._M_node))
  + (__x._M_cur - __x._M_first)
  + (__y._M_last - __y._M_cur);
   }
@@ -383,10 +383,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX_NODISCARD
friend difference_type
operator-(const _Self& __x,
- const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) 
_GLIBCXX_NOEXCEPT
+ const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
+   _GLIBCXX_NOEXCEPT
{
  return difference_type(_S_buffer_size())
-   * (__x._M_node - __y._M_node - int(__x._M_node != 0))
+   * (__x._M_node - __y._M_node - bool(__x._M_node))
+ (__x._M_cur - __x._M_first)
+ (__y._M_last - __y._M_cur);
}
-- 
2.31.1



[committed] libstdc++: Simplify std::allocator_traits>::construct

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


We don't need a preprocessor condition to decide whether to use
placement new or std::construct_at, because std::_Construct already does
that.

libstdc++-v3/ChangeLog:

* include/bits/alloc_traits.h (allocator_traits>):
Use std::_Construct for construct.
---
 libstdc++-v3/include/bits/alloc_traits.h | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/libstdc++-v3/include/bits/alloc_traits.h 
b/libstdc++-v3/include/bits/alloc_traits.h
index f51049f4a51..fa93feb7198 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -632,13 +632,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static _GLIBCXX20_CONSTEXPR void
construct(allocator_type&, _Up* __p, _Args&&... __args)
noexcept(std::is_nothrow_constructible<_Up, _Args...>::value)
-   {
-#if __cplusplus <= 201703L
- ::new((void *)__p) _Up(std::forward<_Args>(__args)...);
-#else
- std::construct_at(__p, std::forward<_Args>(__args)...);
-#endif
-   }
+   { std::_Construct(__p, std::forward<_Args>(__args)...); }
 
   /**
*  @brief  Destroy an object of type `_Up`
-- 
2.31.1



[committed] libstdc++: Fix example preprocessor command in FAQ [PR103877]

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


libstdc++-v3/ChangeLog:

PR libstdc++/103877
* doc/xml/faq.xml: Add '-x c++' to preprocessor command.
* doc/html/faq.html: Regenerate.
---
 libstdc++-v3/doc/html/faq.html | 2 +-
 libstdc++-v3/doc/xml/faq.xml   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/doc/html/faq.html b/libstdc++-v3/doc/html/faq.html
index 967e5f5f348..f49b84c4c33 100644
--- a/libstdc++-v3/doc/html/faq.html
+++ b/libstdc++-v3/doc/html/faq.html
@@ -456,7 +456,7 @@
  CPLUSPLUS_CPP_SPEC in
  the gcc config headers for your target (and try changing them to
  see what happens when building complicated code).  You can also run
- g++ -E -dM -  
/dev/null" to display
+ g++ -E -dM -x c++ 
/dev/null to display
  a list of predefined macros for any particular installation.
   This has been discussed on the mailing lists
  http://gcc.gnu.org/cgi-bin/htsearch?method=andformat=builtin-longsort=scorewords=_XOPEN_SOURCE+Solaris;
 target="_top">quite a bit.
diff --git a/libstdc++-v3/doc/xml/faq.xml b/libstdc++-v3/doc/xml/faq.xml
index e419d3c22a0..9ae4966ecea 100644
--- a/libstdc++-v3/doc/xml/faq.xml
+++ b/libstdc++-v3/doc/xml/faq.xml
@@ -580,7 +580,7 @@
  CPLUSPLUS_CPP_SPEC in
  the gcc config headers for your target (and try changing them to
  see what happens when building complicated code).  You can also run
- g++ -E -dM -  /dev/null" to display
+ g++ -E -dM -x c++ /dev/null to display
  a list of predefined macros for any particular installation.
   
   This has been discussed on the mailing lists
-- 
2.31.1



[committed] libstdc++: Reduce template instantiations in

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


This moves the last two template parameters of __regex_algo_impl to be
runtime function parameters instead, so that we don't need four
different instantiations for the possible ways to call it. Most of the
function (and what it instantiates) is the same in all cases, so making
them compile-time choices doesn't really have much benefit.

Use  'if constexpr' for conditions that check template parameters, so
that when we do depend on a compile-time condition we only instantiate
what we need to.

libstdc++-v3/ChangeLog:

* include/bits/regex.h (__regex_algo_impl): Change __policy and
__match_mode template parameters to be function parameters.
(regex_match, regex_search): Pass policy and match mode as
function arguments.
* include/bits/regex.tcc (__regex_algo_impl): Change template
parameters to function parameters.
* include/bits/regex_compiler.h (_RegexTranslatorBase): Use
'if constexpr' for conditions using template parameters.
(_RegexTranslator): Likewise.
* include/bits/regex_executor.tcc (_Executor::_M_handle_accept):
Likewise.
* testsuite/util/testsuite_regex.h (regex_match_debug)
(regex_search_debug): Move template arguments to function
arguments.
---
 libstdc++-v3/include/bits/regex.h | 33 +--
 libstdc++-v3/include/bits/regex.tcc   |  8 ++---
 libstdc++-v3/include/bits/regex_compiler.h|  9 ++---
 libstdc++-v3/include/bits/regex_executor.tcc  |  2 +-
 libstdc++-v3/testsuite/util/testsuite_regex.h | 24 +++---
 5 files changed, 37 insertions(+), 39 deletions(-)

diff --git a/libstdc++-v3/include/bits/regex.h 
b/libstdc++-v3/include/bits/regex.h
index ff09f49f9e8..7480b0a5f97 100644
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -45,15 +45,14 @@ namespace __detail
   enum class _RegexExecutorPolicy : int { _S_auto, _S_alternate };
 
   template
+  typename _CharT, typename _TraitsT>
 bool
-__regex_algo_impl(_BiIter__s,
- _BiIter __e,
+__regex_algo_impl(_BiIter __s, _BiIter __e,
  match_results<_BiIter, _Alloc>&  __m,
  const basic_regex<_CharT, _TraitsT>& __re,
- regex_constants::match_flag_type __flags);
+ regex_constants::match_flag_type __flags,
+ _RegexExecutorPolicy __policy,
+ bool __match_mode);
 
   template
 class _Executor;
@@ -792,12 +791,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_M_flags = __f;
   }
 
-  template
+  template
friend bool
__detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
const basic_regex<_Cp, _Rp>&,
-   regex_constants::match_flag_type);
+   regex_constants::match_flag_type,
+   _RegexExecutorPolicy, bool);
 
   template
friend class __detail::_Executor;
@@ -2063,12 +2062,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   template
friend class __detail::_Executor;
 
-  template
+  template
friend bool
__detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
const basic_regex<_Cp, _Rp>&,
-   regex_constants::match_flag_type);
+   regex_constants::match_flag_type,
+   _RegexExecutorPolicy, bool);
 
   // Reset contents to __size unmatched sub_match objects
   // (plus additional objects for prefix, suffix and unmatched sub).
@@ -2206,9 +2205,8 @@ _GLIBCXX_END_NAMESPACE_CXX11
regex_constants::match_flag_type __flags
   = regex_constants::match_default)
 {
-  return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, 
_Rx_traits,
-   __detail::_RegexExecutorPolicy::_S_auto, true>
- (__s, __e, __m, __re, __flags);
+  return __detail::__regex_algo_impl(__s, __e, __m, __re, __flags,
+   __detail::_RegexExecutorPolicy::_S_auto, true);
 }
 
   /**
@@ -2363,9 +2361,8 @@ _GLIBCXX_END_NAMESPACE_CXX11
 regex_constants::match_flag_type __flags
 = regex_constants::match_default)
 {
-  return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, 
_Rx_traits,
-   __detail::_RegexExecutorPolicy::_S_auto, false>
- (__s, __e, __m, __re, __flags);
+  return __detail::__regex_algo_impl(__s, __e, __m, __re, __flags,
+   __detail::_RegexExecutorPolicy::_S_auto, false);
 }
 
   /**
diff --git a/libstdc++-v3/include/bits/regex.tcc 
b/libstdc++-v3/include/bits/regex.tcc
index 

[committed] libstdc++: Compare match_results for failed regex_match

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


The regex_match_debug testsuite helper doesn't compare the
std::match_results objects after a failed match, but it should do. The
standard says that the effects of a failed match on the match-results
are unspecified, except that [conditions testable by operator==]. So we
can check that the two sets of results compare equal even if the match
failed.

libstdc++-v3/ChangeLog:

* testsuite/util/testsuite_regex.h (regex_match_debug): Compare
results even if the match failed.
---
 libstdc++-v3/testsuite/util/testsuite_regex.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/util/testsuite_regex.h 
b/libstdc++-v3/testsuite/util/testsuite_regex.h
index 6af3d8d836f..f2bb068024d 100644
--- a/libstdc++-v3/testsuite/util/testsuite_regex.h
+++ b/libstdc++-v3/testsuite/util/testsuite_regex.h
@@ -150,8 +150,7 @@ namespace __gnu_test
   auto __res2 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
   _RegexExecutorPolicy::_S_alternate, true>
(__s, __e, __mm, __re, __flags);
-  // __m is unspecified if return value is false.
-  if (__res1 == __res2 && (!__res1 || __m == __mm))
+  if (__res1 == __res2 && __m == __mm)
return __res1;
   throw std::exception();
 }
-- 
2.31.1



[committed] libstdc++: Improve std::regex_error::what() strings

2022-01-05 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux, pushed to trunk.


This replaces the vague "regex_error" for std::regex_error::what() with
a string that corresponds to the error_type enum passed to the
constructor. This allows us to remove many of the strings passed to
__throw_regex_error, because the default string is at least as good.
When a string argument to __throw_regex_error is kept it should add some
context-specific detail absent from the default string.

Also remove full stops (periods) from the end of those strings, to make
it easier to include them in logs and other output. I've left them
starting with an upper-case letter, which is consistent with strerror
output for (at least) Glibc, Solaris and BSD. I'm ambivalent whether
that's the right choice.

This also adds the missing noreturn attribute to __throw_regex_error.

libstdc++-v3/ChangeLog:

* include/bits/regex_compiler.tcc: Adjust all calls to
__throw_regex_error.
* include/bits/regex_error.h (__throw_regex_error): Add noreturn
attribute.
* include/bits/regex_scanner.tcc: Likewise.
* src/c++11/regex.cc (desc): New helper function.
(regex_error::regex_error(error_type)): Use desc to get a string
corresponding to the error code.
---
 libstdc++-v3/include/bits/regex_compiler.tcc | 37 +-
 libstdc++-v3/include/bits/regex_error.h  | 27 ---
 libstdc++-v3/include/bits/regex_scanner.tcc  | 76 
 libstdc++-v3/src/c++11/regex.cc  | 47 +++-
 4 files changed, 111 insertions(+), 76 deletions(-)

diff --git a/libstdc++-v3/include/bits/regex_compiler.tcc 
b/libstdc++-v3/include/bits/regex_compiler.tcc
index ce834b12255..c12f7502538 100644
--- a/libstdc++-v3/include/bits/regex_compiler.tcc
+++ b/libstdc++-v3/include/bits/regex_compiler.tcc
@@ -157,8 +157,7 @@ namespace __detail
  auto __neg = _M_value[0] == 'n';
  this->_M_disjunction();
  if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
-   __throw_regex_error(regex_constants::error_paren,
-   "Parenthesis is not closed.");
+   __throw_regex_error(regex_constants::error_paren);
  auto __tmp = _M_pop();
  __tmp._M_append(_M_nfa->_M_insert_accept());
  _M_stack.push(
@@ -180,8 +179,7 @@ namespace __detail
   auto __init = [this, &__neg]()
{
  if (_M_stack.empty())
-   __throw_regex_error(regex_constants::error_badrepeat,
-   "Nothing to repeat before a quantifier.");
+   __throw_regex_error(regex_constants::error_badrepeat);
  __neg = __neg && _M_match_token(_ScannerT::_S_token_opt);
};
   if (_M_match_token(_ScannerT::_S_token_closure0))
@@ -217,11 +215,9 @@ namespace __detail
   else if (_M_match_token(_ScannerT::_S_token_interval_begin))
{
  if (_M_stack.empty())
-   __throw_regex_error(regex_constants::error_badrepeat,
-   "Nothing to repeat before a quantifier.");
+   __throw_regex_error(regex_constants::error_badrepeat);
  if (!_M_match_token(_ScannerT::_S_token_dup_count))
-   __throw_regex_error(regex_constants::error_badbrace,
-   "Unexpected token in brace expression.");
+   __throw_regex_error(regex_constants::error_badbrace);
  _StateSeqT __r(_M_pop());
  _StateSeqT __e(*_M_nfa, _M_nfa->_M_insert_dummy());
  long __min_rep = _M_cur_int_value(10);
@@ -237,8 +233,7 @@ namespace __detail
__infi = true;
}
  if (!_M_match_token(_ScannerT::_S_token_interval_end))
-   __throw_regex_error(regex_constants::error_brace,
-   "Unexpected end of brace expression.");
+   __throw_regex_error(regex_constants::error_brace);
 
  __neg = __neg && _M_match_token(_ScannerT::_S_token_opt);
 
@@ -257,8 +252,7 @@ namespace __detail
  else
{
  if (__n < 0)
-   __throw_regex_error(regex_constants::error_badbrace,
-   "Invalid range in brace expression.");
+   __throw_regex_error(regex_constants::error_badbrace);
  auto __end = _M_nfa->_M_insert_dummy();
  // _M_alt is the "match more" branch, and _M_next is the
  // "match less" one. Switch _M_alt and _M_next of all created
@@ -325,8 +319,7 @@ namespace __detail
  _StateSeqT __r(*_M_nfa, _M_nfa->_M_insert_dummy());
  this->_M_disjunction();
  if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
-   __throw_regex_error(regex_constants::error_paren,
-   "Parenthesis is not closed.");
+   __throw_regex_error(regex_constants::error_paren);
  __r._M_append(_M_pop());
  _M_stack.push(__r);
}
@@ -335,8 +328,7 @@ namespace __detail
  _StateSeqT __r(*_M_nfa, 

[PATCH 2/N] Enable migration to C++.

2022-01-05 Thread Martin Liška

Hi.

The second patch brings us closer to C++. I used some libiberty macros
and changed signed/unsigned integer types.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
MartinFrom 17de4d675005368d7e69615da22cd405542c4fe1 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Wed, 5 Jan 2022 14:00:15 +0100
Subject: [PATCH] Enable migration to C++.

lto-plugin/ChangeLog:

	* lto-plugin.c (translate): Use XRESIZEVEC and correct
	signed/unsigned integer types.
	(free_1): Likewise.
	(dump_symtab): Likewise.
	(finish_conflict_resolution): Likewise.
	(add_output_files): Likewise.
	(resolve_conflicts): Likewise.
	(process_symtab): Likewise.
	(process_symtab_extension): Likewise.
	(claim_file_handler): Likewise.
	(process_option): Likewise.
	(onload): Likewise.
---
 lto-plugin/lto-plugin.c | 55 ++---
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 0147b1b9667..51e0b4ded43 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -185,7 +185,7 @@ static char **output_files = NULL;
 static unsigned int num_output_files = 0;
 
 static char **lto_wrapper_argv;
-static int lto_wrapper_num_args;
+static unsigned lto_wrapper_num_args;
 
 static char **pass_through_items = NULL;
 static unsigned int num_pass_through_items;
@@ -363,9 +363,9 @@ translate (char *data, char *end, struct plugin_symtab *out)
  the algorithm is O(1) now. */
 
   len = (end - data)/8 + out->nsyms + 1;
-  syms = xrealloc (out->syms, len * sizeof (struct ld_plugin_symbol));
-  aux = xrealloc (out->aux, len * sizeof (struct sym_aux));
-  
+  syms = XRESIZEVEC (struct ld_plugin_symbol, out->syms, len);
+  aux = XRESIZEVEC (struct sym_aux, out->aux, len);
+
   for (n = out->nsyms; data < end; n++) 
 { 
   aux[n].id = out->id; 
@@ -414,13 +414,11 @@ parse_symtab_extension (char *data, char *end, struct plugin_symtab *out)
 static void
 free_1 (struct plugin_file_info *files, unsigned num_files)
 {
-  unsigned int i;
-  for (i = 0; i < num_files; i++)
+  for (unsigned i = 0; i < num_files; i++)
 {
   struct plugin_file_info *info = [i];
   struct plugin_symtab *symtab = >symtab;
-  unsigned int j;
-  for (j = 0; j < symtab->nsyms; j++)
+  for (int j = 0; j < symtab->nsyms; j++)
 	{
 	  struct ld_plugin_symbol *s = >syms[j];
 	  free (s->name);
@@ -470,9 +468,7 @@ free_2 (void)
 static void
 dump_symtab (FILE *f, struct plugin_symtab *symtab)
 {
-  unsigned j;
-
-  for (j = 0; j < symtab->nsyms; j++)
+  for (int j = 0; j < symtab->nsyms; j++)
 {
   uint32_t slot = symtab->aux[j].slot;
   unsigned int resolution = symtab->syms[j].resolution;
@@ -502,7 +498,7 @@ finish_conflict_resolution (struct plugin_symtab *symtab,
 { 
   char resolution = LDPR_UNKNOWN;
 
-  if (symtab->aux[i].next_conflict == -1)
+  if (symtab->aux[i].next_conflict == -1U)
 	continue;
 
   switch (symtab->syms[i].def) 
@@ -591,7 +587,7 @@ add_output_files (FILE *f)
   for (;;)
 {
   const unsigned piece = 32;
-  char *buf, *s = xmalloc (piece);
+  char *buf, *s = XNEWVEC (char, piece);
   size_t len;
 
   buf = s;
@@ -604,15 +600,14 @@ cont:
   len = strlen (s);
   if (s[len - 1] != '\n')
 	{
-	  s = xrealloc (s, len + piece);
+	  s = XRESIZEVEC (char, s, len + piece);
 	  buf = s + len;
 	  goto cont;
 	}
   s[len - 1] = '\0';
 
   num_output_files++;
-  output_files
-	= xrealloc (output_files, num_output_files * sizeof (char *));
+  output_files = XRESIZEVEC (char *, output_files, num_output_files);
   output_files[num_output_files - 1] = s;
   add_input_file (output_files[num_output_files - 1]);
 }
@@ -962,8 +957,8 @@ resolve_conflicts (struct plugin_symtab *t, struct plugin_symtab *conflicts)
   int outlen;
 
   outlen = t->nsyms;
-  conflicts->syms = xmalloc (sizeof (struct ld_plugin_symbol) * outlen);
-  conflicts->aux = xmalloc (sizeof (struct sym_aux) * outlen);
+  conflicts->syms = XNEWVEC (struct ld_plugin_symbol, outlen);
+  conflicts->aux = XNEWVEC (struct sym_aux, outlen);
 
   /* Move all duplicate symbols into the auxiliary conflicts table. */
   out = 0;
@@ -1027,7 +1022,7 @@ static int
 process_symtab (void *data, const char *name, off_t offset, off_t length)
 {
   struct plugin_objfile *obj = (struct plugin_objfile *)data;
-  char *s;
+  const char *s;
   char *secdatastart, *secdata;
 
   if (!startswith (name, ".gnu.lto_.symtab"))
@@ -1036,7 +1031,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
   s = strrchr (name, '.');
   if (s)
 sscanf (s, ".%" PRI_LL "x", >out->id);
-  secdata = secdatastart = xmalloc (length);
+  secdata = secdatastart = XNEWVEC (char, length);
   offset += obj->file->offset;
   if (offset != lseek (obj->file->fd, offset, SEEK_SET))
 goto err;
@@ -1079,7 +1074,7 @@ process_symtab_extension (void *data, const 

[PATCH] middle-end/77608: object size estimate with variable offsets

2022-01-05 Thread Siddhesh Poyarekar
This partially fixes middle-end/77608 by making __builtin_object_size
return the whole object size instead of bailing out in case the offset
in the object is variable and the maximum estimate is requested.

gcc/ChangeLog:

PR middle-end/77608
* tree-object-size.c (size_for_offset): New object_size_type
parameter.  Return known whole size if offset is not constant.
(addr_object_size, compute_builtin_object_size): Adjust.
(plus_stmt_object_size): Defer constness check of offset to
size_for_offset.

gcc/testsuite/ChangeLog:

PR middle-end/77608
* gcc.dg/builtin-object-size-1.c (test1): Add tests.
* gcc.dg/builtin-object-size-2.c (test1): Likewise.

Signed-off-by: Siddhesh Poyarekar 
---

This applies on top of the __builtin_dynamic_object_size patchset.  It
should be possible to process trees with side effects and fully fix
77608, but I'll do that later since it would be a bit more involved.

Tested with a full bootstrap on x86_64 and ubsan bootstrap.

 gcc/testsuite/gcc.dg/builtin-object-size-1.c | 16 
 gcc/testsuite/gcc.dg/builtin-object-size-2.c | 37 ++
 gcc/tree-object-size.c   | 77 +++-
 3 files changed, 97 insertions(+), 33 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-1.c 
b/gcc/testsuite/gcc.dg/builtin-object-size-1.c
index 161f426ec0b..0f92713b141 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-1.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-1.c
@@ -22,6 +22,8 @@ struct A
 extern char exta[];
 extern char extb[30];
 extern struct A zerol[0];
+int off = 2;
+int off2 = -3;
 
 void
 __attribute__ ((noinline))
@@ -162,6 +164,13 @@ test1 (void *q, int x)
   if (__builtin_object_size ([5], 0) != sizeof (extb) - 5)
 abort ();
 #ifdef __builtin_object_size
+  if (__builtin_object_size ([off], 0) != sizeof (extb) - off)
+abort ();
+  r = [5];
+  if (__builtin_object_size (r + off, 0) != sizeof (extb) - 5 - off)
+abort ();
+  if (__builtin_object_size (r + off2, 0) != sizeof (extb) - 5 - off2)
+abort ();
   if (__builtin_object_size (var, 0) != x + 10)
 abort ();
   if (__builtin_object_size (var + 10, 0) != x)
@@ -169,6 +178,13 @@ test1 (void *q, int x)
   if (__builtin_object_size ([5], 0) != x + 5)
 abort ();
 #else
+  if (__builtin_object_size ([off], 0) != sizeof (extb))
+abort ();
+  r = [5];
+  if (__builtin_object_size (r + off, 0) != sizeof (extb))
+abort ();
+  if (__builtin_object_size (r + off2, 0) != sizeof (extb))
+abort ();
   if (__builtin_object_size (var, 0) != (size_t) -1)
 abort ();
   if (__builtin_object_size (var + 10, 0) != (size_t) -1)
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-2.c 
b/gcc/testsuite/gcc.dg/builtin-object-size-2.c
index 2729538da17..62a5af1384a 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-2.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-2.c
@@ -24,6 +24,9 @@ extern char extb[30];
 extern struct A extc[];
 struct A zerol[0];
 
+int off = 3;
+int off2 = -3;
+
 void
 __attribute__ ((noinline))
 test1 (void *q, int x)
@@ -151,6 +154,23 @@ test1 (void *q, int x)
 abort ();
   if (__builtin_object_size ([5], 1) != sizeof (extb) - 5)
 abort ();
+#ifdef __builtin_object_size
+  if (__builtin_object_size ([off], 1) != sizeof (extb) - off)
+abort ();
+  r = [5];
+  if (__builtin_object_size (r + off, 1) != sizeof (extb) - 5 - off)
+abort ();
+  if (__builtin_object_size (r + off2, 0) != sizeof (extb) - 5 - off2)
+abort ();
+#else
+  if (__builtin_object_size ([off], 1) != sizeof (extb))
+abort ();
+  r = [5];
+  if (__builtin_object_size (r + off, 1) != sizeof (extb))
+abort ();
+  if (__builtin_object_size (r + off2, 0) != sizeof (extb))
+abort ();
+#endif
   if (__builtin_object_size (extc, 1) != (size_t) -1)
 abort ();
   if (__builtin_object_size (extc + 10, 1) != (size_t) -1)
@@ -200,6 +220,23 @@ test1 (void *q, int x)
 abort ();
   if (__builtin_object_size ([7].c[7], 1) != sizeof (vara[0].c) - 7)
 abort ();
+#ifdef __builtin_object_size
+  if (__builtin_object_size ([5].c[off], 1) != sizeof (vara[0].c) - off)
+abort ();
+  r = [1].c[5];
+  if (__builtin_object_size (r + off, 1) != sizeof (vara[0].c) - 5 - off)
+abort ();
+  if (__builtin_object_size (r + off2, 1) != sizeof (vara[0].c) - 5 - off2)
+abort ();
+#else
+  if (__builtin_object_size ([5].c[off], 1) != sizeof (vara[0].c))
+abort ();
+  r = [1].c[5];
+  if (__builtin_object_size (r + off, 1) != sizeof (vara[0].c))
+abort ();
+  if (__builtin_object_size (r + off2, 1) != sizeof (vara[0].c))
+abort ();
+#endif
   if (__builtin_object_size (zerol, 1) != 0)
 abort ();
   if (__builtin_object_size (, 1) != 0)
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index bf45adc7307..b5cb637f207 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -347,10 +347,21 @@ init_offset_limit (void)
be positive and hence, be 

Re: DCO entry

2022-01-05 Thread Martin Liška

On 1/5/22 13:07, Nathan Sidwell wrote:

I have some patches that I cannot in good conscience keep secret.


Welcome back Nathan!

About the sorting, it seems all other names lists in the file
are sorted by surname. Your patch changes that to sort by first name,
do we really want the change?

Thanks,
Martin



nathan




Re: [PATCH] libgomp, OpenMP, nvptx: Low-latency memory allocator

2022-01-05 Thread Tom de Vries via Gcc-patches

On 1/5/22 12:08, Tom de Vries wrote:

The allocators-1.c test-case doesn't compile because:
...
FAIL: libgomp.c/allocators-1.c (test for excess errors)
Excess errors:
/home/vries/oacc/trunk/source-gcc/libgomp/testsuite/libgomp.c/allocators-1.c:7:22: 
sorry, unimplemented: '    ' clause on 'requires' directive not 
supported yet


UNRESOLVED: libgomp.c/allocators-1.c compilation failed to produce 
executable

...

So, I suppose I need "[PATCH] OpenMP front-end: allow requires 
dynamic_allocators" as well, I'll try again with that applied.


After applying that, I get:
...
WARNING: program timed out.
FAIL: libgomp.c/allocators-2.c execution test
WARNING: program timed out.
FAIL: libgomp.c/allocators-3.c execution test
...

Thanks,
- Tom


Re: [PATCH] nvptx: bump default to PTX 4.1

2022-01-05 Thread Tom de Vries via Gcc-patches

On 1/5/22 11:33, Andrew Stubbs wrote:

On 05/01/2022 10:24, Tom de Vries wrote:

On 12/21/21 12:33, Andrew Stubbs wrote:

On 20/12/2021 15:58, Andrew Stubbs wrote:
In order to support the %dynamic_smem_size PTX feature is is 
necessary to bump the minimum supported PTX version from 3.1 (~2013) 
to 4.1 (~2014).


Tobias has pointed out, privately, that the default version is both 
documented and encoded in the -mptx option, so I need to fix that too.


This patch adds -mptx=4.1, sets it as the default, and updates the 
documentation accordingly.


The -mptx=3.1 option is kept for backwards compatibility as an alias 
for 4.1. There's no point in actually allowing 3.1 as any program 
linked against libgomp will fail (and that's all offloading programs).


OK for stage 1?


Just keep -mptx=3.1 as is, and add -mptx=4.1.

AFAIU, there's actually only one file required to have -mptx=4.1, the 
one using %dynamic_smem_size.  Since it's somewhat cumbersome to add 
flags for a single file, how about:

...
diff --git a/libgomp/configure.tgt b/libgomp/configure.tgt
index d4f1e741b5a..92242697f24 100644
--- a/libgomp/configure.tgt
+++ b/libgomp/configure.tgt
@@ -162,6 +162,7 @@ case "${target}" in

    nvptx*-*-*)
 config_path="nvptx accel"
+   XCFLAGS="$XCFLAGS -mptx=4.1"
 ;;

    *-*-rtems*)
...
?


There shouldn't be any need for that as long as the default is correct.


There is no need to change the default, as long as we use this.

In any case, I'm no expert but doesn't the deferred assembly thing mean 
that the whole project needs to have the correct minimum setting?




If your question is whether ptx modules with .version 3.1 and 4.1 can be 
linked together, then the answer seems to be yes.


If the NVPTX maintainer prefers I can leave the 3.1 meaning actually 
3.1, but that will break any makefiles or build scripts that exist in 
the wild and happen to specify 3.1 explicitly (not that I know any 
reason why they would).


I think you're trying to support a scenario we shouldn't support, by 
making things unclear.


Thanks,
- Tom


Re: [PATCH] Fortran: Fix ICE caused by missing error for untyped symbol [PR103258]

2022-01-05 Thread Paul Richard Thomas via Gcc-patches
Hi Sandra,

That's a good shout to query suppress_errors. The patch is OK by me.

Thanks

Paul


On Wed, 5 Jan 2022 at 03:21, Sandra Loosemore 
wrote:

> This patch fixes an ICE that appeared after I checked in my patch for
> PR101337 back in November, which made the resolve phase try harder to
> check all operands/arguments for errors instead of giving up after the
> first one, but it's actually a bug that existed before that and was only
> revealed by that earlier patch.
>
> The problem is that the parse phase is doing early resolution to try to
> constant-fold a character length expression.  It's throwing away the
> error(s) if it fails, but in the test case for this issue it was leaving
> behind some state indicating that the error had already been diagnosed
> so it wasn't getting caught again during the "real" resolution phase
> either.
>
> Every bit of code touched by this seems kind of hacky to me -- the
> different mechanisms for suppressing/ignoring errors, the magic bit in
> the symbol attributes, the part that tries to constant-fold an
> expression that might not actually be a constant, etc.  But, this is the
> least hacky fix I could come up with.  :-P  It fixes the test case from
> the issue and does not cause any regressions elsewhere in the gfortran
> testsuite.
>
> OK to check in?
>
> -Sandra
>


-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein


Re: [PATCH] Loop unswitching: support gswitch statements.

2022-01-05 Thread Richard Biener via Gcc-patches
On Thu, Dec 9, 2021 at 2:02 PM Martin Liška  wrote:
>
> On 11/30/21 12:17, Richard Biener wrote:
> > I'd like to see the gswitch support - that's what was posted before stage3
> > close, this patch on its own doesn't seem worth pushing for.  That said,
> > I have some comments below (and the already raised ones about how
> > things might need to change with gswitch support).  Is it so difficult to
> > develop gswitch support as a separate change ontop of this?
>
> Hello.
>
> Took me some time, but I have a working version of the patch that makes both
> refactoring of the costing model and adds support for gswitch. For quite some
> time, I maintained 2 patches, but as commonly happens, I was forced doing 
> quite
> some rework. If we really want a separation for bisection purpose, I suggest 
> simple
> disabling of gswitch support?

It was really meant to ease review.  I'm now looking at the combined
patch, comments will
follow.

+static void
+clean_up_after_unswitching (const auto_edge_flag _edge_flag)
+{
+  basic_block bb;
+
...
+  /* Clean up the ignored_edge_flag from edges.  */
+  FOR_EACH_BB_FN (bb, cfun)
+{
+  edge e;

you can probably clean up outgoing edge flags in the loop above?

(I'm randomly jumping)

+ /* Build compound expression for all cases leading
+to this edge.  */
+ tree expr = NULL_TREE;
+ for (unsigned i = 1; i < gimple_switch_num_labels (stmt); ++i)
+   {
+ tree lab = gimple_switch_label (stmt, i);
+ basic_block dest = label_to_block (cfun, CASE_LABEL (lab));
+ edge e2 = find_edge (gimple_bb (stmt), dest);
+ if (e == e2)

just as a style note I prefer if (e != e2) continue; so the following code
needs less indentation

+ tree cmp1 = build2 (GE_EXPR, boolean_type_node, idx,
+ CASE_LOW (lab));

is there a reason you are not using fold_build2?  Do we want to somehow account
for the built expression size or maybe have a separate limit for the number of
cases we want to combine this way?

+ unswitch_predicate *predicate
+   = new unswitch_predicate (expr, idx, edge_index);
+ ranger->gori ().outgoing_edge_range_p
(predicate->true_range, e,
+idx,
*get_global_range_query ());
+ /* Huge switches are not supported by Ranger.  */
+ if (predicate->true_range.undefined_p ())

I hope ranger will set the range to varying_p () in that case, not
undefined?  But even
then, is that a reason for punting?  I guess we fail to prune cases in
that case but
the cost modeling should then account for those and thus we are at
least consistent?

+   {
+ delete predicate;
+ return;

In this context, when we do

+  if (operand_equal_p (predicate->lhs, last_predicate->lhs, 0))
+   {
+ irange  = (true_edge ? predicate->merged_true_range
+  : predicate->merged_false_range);
+ last_predicate->merged_true_range.intersect (other);
+ last_predicate->merged_false_range.intersect (other);
+ return;

ranger may be conservative when intersecting (and hopefully not end up
with undefined_p - heh).  I also am confused about intersecting both
merged_true_range and merged_false_range with 'other'?  I would
have expected to merge true edge info with true edge info and thus
only "swap" things somehow?  OTOH "path" suggests we're dealing
with more than one edge and associated ranges?  Maybe expanding
the comment on the predicate_vector would be useful.  AFAIR we
there store the sequence of unswitchings done with pairs of
the predicate unswitched on and a bool indicating whether we're
dealing with the copy that had the predicate true or the one that
had it false.

+  unswitch_predicate *predicate = NULL;
+  basic_block bb = NULL;
+  if (num > param_max_unswitch_level)
+{
+  if (dump_enabled_p ())
+   dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
+"Not unswitching anymore, hit max level\n");
+  goto exit;
+}

I'll notice that given we have the overall size budget limiting the number
of unswitchings itself is probably unnecessary (as noted above we might
need to account for the size of the unswitch condition).

+  for (unsigned i = 0; i != loop->num_nodes; i++)
+{
+  vec  = get_predicates_for_bb (bbs[i]);
+  if (!predicates.is_empty ())
+   {

same comment about indenting

I wonder whether evaluate_control_stmt_using_entry_checks could set
ignored_edge_flag itself instead of communicating via a hash_set?

It's not exactly clear what we use pred->handled for, do we re-discover
and re-try predicates when unswitching another level otherwise?  But
we _do_ want to unswitch the same switch stmt again, no?  And since
the BB 

Fix PR97966 regression

2022-01-05 Thread Nathan Sidwell

Marek's fix for PR97966 caused a regression with (non-template) member
functions of template classes.  We need to mark them used in the
instantiated class's scope, rather than the scope we were in before
instantiating, as the latter may itself be in template and change the
behaviour of marking a function as used.

pushed to trunk

nathan

--
Nathan SidwellFrom 10195da73618ab818b66d4d2fade1be46ea39962 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Tue, 4 Jan 2022 13:36:44 -0800
Subject: [PATCH 3/3] Adjust mark used member in instantiated class scope

The fix for PR97966 caused a regression with (non-template) member
functions of template classes.  We need to mark them used in the
instantiated class's scope, rather than the scope we were in before
instantiating, as the latter may itself be in template and change the
behaviour of marking a function as used.

	gcc/cp/
	* pt.c (instantiate_class_template_1): Process attribute((used)) set
	in class's context.
	gcc/testsuite/
	* g++.dg/template/attr-used.C: New.
---
 gcc/cp/pt.c   | 13 -
 gcc/testsuite/g++.dg/template/attr-used.C | 16 
 2 files changed, 24 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/attr-used.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c587966adbe..0fa4a162354 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -12277,6 +12277,14 @@ instantiate_class_template_1 (tree type)
 
   perform_instantiation_time_access_checks (pattern, args);
   perform_deferred_access_checks (tf_warning_or_error);
+
+  /* Now that we've gone through all the members, instantiate those
+ marked with attribute used.  We must do this in the context of
+ the class -- not the context we pushed from, as that might be
+ inside a template and change the behaviour of mark_used.  */
+  for (tree x : used)
+mark_used (x);
+
   pop_nested_class ();
   maximum_field_alignment = saved_maximum_field_alignment;
   if (!fn_context)
@@ -12290,11 +12298,6 @@ instantiate_class_template_1 (tree type)
   if (TYPE_CONTAINS_VPTR_P (type) && CLASSTYPE_KEY_METHOD (type))
 vec_safe_push (keyed_classes, type);
 
-  /* Now that we've gone through all the members, instantiate those
- marked with attribute used.  */
-  for (tree x : used)
-mark_used (x);
-
   return type;
 }
 
diff --git a/gcc/testsuite/g++.dg/template/attr-used.C b/gcc/testsuite/g++.dg/template/attr-used.C
new file mode 100644
index 000..e12bf4caa3f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/attr-used.C
@@ -0,0 +1,16 @@
+// { dg-do compile }
+
+template struct X {
+  void g () {}
+  void f () __attribute__((__used__)) {}
+};
+
+extern X x; // X incomplete here
+
+template 
+void Frob (T t) {
+  x.g(); // X completed here, X::f's body marked for instantiation
+}
+
+// Make sure X::f is emitted
+// { dg-final { scan-assembler "_ZN1XIiE1fEv:" } }
-- 
2.30.2



Fix diagnostic recursion ICE

2022-01-05 Thread Nathan Sidwell
The diagnostic machinery uses template instantiation when generating the 
[with T = ...] text.  In this case that caused an alignment warning to 
be emitted with a subsequent recursion ICE.


pushed to trunk

nathan

--
Nathan SidwellFrom f2da9e26f5c0f04d48872938eff130e2028e75d3 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Tue, 4 Jan 2022 12:45:36 -0800
Subject: [PATCH 2/3] Fix diagnostic recursion ICE

The [with T = $TYPE] diagnostic machinery must not cause recursion. So let's
not unilaterally warn about new alignment.  (template extracted from Open3D.)

	gcc/cp/
	* init.c (build_new_1): Check complain before alignment warning.
	gcc/testsuite/
	* g++.dg/diagnostic/recur-align.C: New.
---
 gcc/cp/init.c |  3 ++-
 gcc/testsuite/g++.dg/diagnostic/recur-align.C | 19 +++
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/recur-align.C

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 3f56ca4bf5e..9d616f3f5e9 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -3408,7 +3408,8 @@ build_new_1 (vec **placement, tree type, tree nelts,
 = (type_num_arguments (TREE_TYPE (alloc_fn)) > 1
|| varargs_function_p (alloc_fn));
 
-  if (warn_aligned_new
+  if (complain & tf_warning_or_error
+  && warn_aligned_new
   && !placement_allocation_fn_p
   && TYPE_ALIGN (elt_type) > malloc_alignment ()
   && (warn_aligned_new > 1
diff --git a/gcc/testsuite/g++.dg/diagnostic/recur-align.C b/gcc/testsuite/g++.dg/diagnostic/recur-align.C
new file mode 100644
index 000..e7d4b9a17cc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/recur-align.C
@@ -0,0 +1,19 @@
+// ICE with diagnostic recursion
+// { dg-do compile { target { c++11_only || c++14_only } } }
+// { dg-options -Waligned-new }
+
+struct __attribute__ ((aligned(256))) Aligned
+{
+  int b;
+};
+
+template
+auto Foo (const T* x) -> decltype (new T (*x))
+{
+  return new T (*x); // { dg-warning "with extended alignment" }
+}
+
+void Bar () {
+  Aligned y;
+  Foo ();
+}
-- 
2.30.2



DCO entry

2022-01-05 Thread Nathan Sidwell

I have some patches that I cannot in good conscience keep secret.

nathan
--
Nathan SidwellFrom 77e71619532c7cd27e907bb22af157b8e56dca58 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Tue, 4 Jan 2022 12:41:25 -0800
Subject: [PATCH 1/3] DCO Entry

	* MAINTAINERS: Add DCO entry.  Sort that list.
---
 MAINTAINERS | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index fb1bd3c57f9..0fd3a1f99f2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -711,13 +711,14 @@ Certificate of Origin Version 1.1.  See https://gcc.gnu.org/dco.html for more
 information.
 
 
- Matthias Kretz	
+ Gaius Mulley	
  Jeff Law	
  Jeff Law	
  Jonathan Wakely
- Gaius Mulley	
- Siddhesh Poyarekar
+ Martin Uecker	
+ Matthias Kretz	
+ Nathan Sidwell	
  Navid Rahimi	
- Trevor Saunders
  Petter Tomner	
- Martin Uecker	
+ Siddhesh Poyarekar
+ Trevor Saunders
-- 
2.30.2



Re: [PATCH] Support ld.mold linker.

2022-01-05 Thread Martin Liška

On 1/4/22 08:23, Richard Biener wrote:

Since we have a fixed set of supported linkers and we know their implementation
status with respect to linker plugin support we can maybe auto-add
-fno-use-linker-plugin
(via specs?) when -fuse-ld=lld or -fuse-ld=mold is used?


Well, if I'm correct, we do so when GCC is configured with --with-ld=...
That can perform version detection and so on. I still hope that ld.mold will
support LTO plug-in quite soon. It's even possible that it will be there
once GCC 12.1 is released.


But yes,
adding a note to
the documentation that for lld and mold LTO support is severely
restricted compared to
GNU ld or gold on platforms that support the linker plugin and thus
their use is discouraged
there might be a good idea.


I'm going to do that if ld.mold LTO support won't be available
when 12.1 gets released.

Martin


[Ada] Improve support for casing on types with controlled parts

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
INOX allows casing on composite values. In some cases of bindings for
subcomponents, the compiler introduced copying which led to compiler
failures associated with finalizing those copies. In such cases a bound
object now provides a constant view of the appropriate subcomponent of
the selector object, not a copy thereof.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch5.adb (Finish_Binding_Object_Declaration): Fix a bug
that was introduced in the previous commit.  The previous
version initialized a Boolean constant Declare_Copy before the
variable Decl had been initialized properly.diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -3392,12 +3392,12 @@ package body Exp_Ch5 is
Decl : Node_Id := First (Declarations (Block_Stmt));
Def_Id   : Node_Id := Empty;
 
+   function Declare_Copy (Decl : Node_Id) return Boolean is
+ (Nkind (Decl) = N_Object_Declaration);
--  Declare_Copy indicates which of the two approaches
--  was chosen during analysis: declare (and initialize)
--  a new variable, or use access values to declare a renaming
--  of the appropriate subcomponent of the selector value.
-   Declare_Copy : constant Boolean :=
- Nkind (Decl) = N_Object_Declaration;
 
function Make_Conditional (Stmt : Node_Id) return Node_Id;
--  If there is only one choice for this alternative, then
@@ -3443,7 +3443,7 @@ package body Exp_Ch5 is
end loop;
 
--  For a binding object, we sometimes make a copy and
-   --  sometimes introduce  a renaming. That decision is made
+   --  sometimes introduce a renaming. That decision is made
--  elsewhere. The renaming case involves dereferencing an
--  access value because of the possibility of multiple
--  choices (with multiple binding definitions) for a single
@@ -3452,7 +3452,7 @@ package body Exp_Ch5 is
--  renaming case, we initialize (again, maybe conditionally)
--  the access value.
 
-   if Declare_Copy then
+   if Declare_Copy (Decl) then
   declare
  Assign_Value : constant Node_Id  :=
Make_Assignment_Statement (Loc,




[Ada] Simplify detection of alphabetic characters with membership test

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Cleanup originating from enabling expansion of dispatching wrappers for
GNATprove; semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_prag.adb (Adjust_External_Name_Case): Use membership test.diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -398,14 +398,12 @@ package body Sem_Prag is
 CC := Get_String_Char (Strval (N), J);
 
 if Opt.External_Name_Exp_Casing = Uppercase
-  and then CC >= Get_Char_Code ('a')
-  and then CC <= Get_Char_Code ('z')
+  and then CC in Get_Char_Code ('a') .. Get_Char_Code ('z')
 then
Store_String_Char (CC - 32);
 
 elsif Opt.External_Name_Exp_Casing = Lowercase
-  and then CC >= Get_Char_Code ('A')
-  and then CC <= Get_Char_Code ('Z')
+  and then CC in Get_Char_Code ('A') .. Get_Char_Code ('Z')
 then
Store_String_Char (CC + 32);
 




[Ada] Expand controlling function wrapper into expression function

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
GNATprove prefers various internally generated functions to be
expression functions, because then it will use the expression itself as
an implicit postcondition. The same applies to wrappers for dispatching
functions with controlling results.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch3.adb (Make_Controlling_Function_Wrappers): For
GNATprove build the wrapper as an expression function.diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -9607,11 +9607,11 @@ package body Exp_Ch3 is
   Actual_List : List_Id;
   Formal  : Entity_Id;
   Par_Formal  : Entity_Id;
+  Ext_Aggr: Node_Id;
   Formal_Node : Node_Id;
   Func_Body   : Node_Id;
   Func_Decl   : Node_Id;
   Func_Id : Entity_Id;
-  Return_Stmt : Node_Id;
 
--  Start of processing for Make_Controlling_Function_Wrappers
 
@@ -9731,25 +9731,38 @@ package body Exp_Ch3 is
Actual_List := No_List;
 end if;
 
-Return_Stmt :=
-  Make_Simple_Return_Statement (Loc,
-Expression =>
-  Make_Extension_Aggregate (Loc,
-Ancestor_Part   =>
-  Make_Function_Call (Loc,
-Name   =>
-  New_Occurrence_Of (Alias (Subp), Loc),
-Parameter_Associations => Actual_List),
-Null_Record_Present => True));
-
-Func_Body :=
-  Make_Subprogram_Body (Loc,
-Specification  =>
-  Make_Wrapper_Specification (Subp),
-Declarations   => Empty_List,
-Handled_Statement_Sequence =>
-  Make_Handled_Sequence_Of_Statements (Loc,
-Statements => New_List (Return_Stmt)));
+Ext_Aggr :=
+  Make_Extension_Aggregate (Loc,
+Ancestor_Part   =>
+  Make_Function_Call (Loc,
+Name   =>
+  New_Occurrence_Of (Alias (Subp), Loc),
+Parameter_Associations => Actual_List),
+Null_Record_Present => True);
+
+--  GNATprove will use expression of an expression function as an
+--  implicit postcondition. GNAT will not benefit from expression
+--  function (and would struggle if we add an expression function
+--  to freezing actions).
+
+if GNATprove_Mode then
+   Func_Body :=
+ Make_Expression_Function (Loc,
+   Specification =>
+ Make_Wrapper_Specification (Subp),
+   Expression => Ext_Aggr);
+else
+   Func_Body :=
+ Make_Subprogram_Body (Loc,
+   Specification  =>
+ Make_Wrapper_Specification (Subp),
+   Declarations   => Empty_List,
+   Handled_Statement_Sequence =>
+ Make_Handled_Sequence_Of_Statements (Loc,
+   Statements => New_List (
+ Make_Simple_Return_Statement (Loc,
+   Expression => Ext_Aggr;
+end if;
 
 Append_To (Body_List, Func_Body);
 




[Ada] Expand controlling functions wrappers in GNATprove mode

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Enable expansion of wrappers for dispatching functions with controlling
results in GNATprove mode. Without those wrappers the AST for calls to
dispatching functions on parent and child objects is exactly the same
and the GNATprove backend can't determine what function is actually
called.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch3.ads (Make_Controlling_Function_Wrappers): Move
declaration from body to spec, so it can be called by
SPARK-specific expansion.
* exp_ch3.adb (Make_Controlling_Function_Wrappers): Likewise.
* exp_spark.adb (SPARK_Freeze_Type): Enable expansion of
wrappers for function with controlling result types.diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -294,17 +294,6 @@ package body Exp_Ch3 is
--  inherited. If the result is false, the init_proc and the discriminant
--  checking functions of the parent can be reused by a derived type.
 
-   procedure Make_Controlling_Function_Wrappers
- (Tag_Typ   : Entity_Id;
-  Decl_List : out List_Id;
-  Body_List : out List_Id);
-   --  Ada 2005 (AI-391): Makes specs and bodies for the wrapper functions
-   --  associated with inherited functions with controlling results which
-   --  are not overridden. The body of each wrapper function consists solely
-   --  of a return statement whose expression is an extension aggregate
-   --  invoking the inherited subprogram's parent subprogram and extended
-   --  with a null association list.
-
function Make_Null_Procedure_Specs (Tag_Typ : Entity_Id) return List_Id;
--  Ada 2005 (AI-251): Makes specs for null procedures associated with any
--  null procedures inherited from an interface type that have not been


diff --git a/gcc/ada/exp_ch3.ads b/gcc/ada/exp_ch3.ads
--- a/gcc/ada/exp_ch3.ads
+++ b/gcc/ada/exp_ch3.ads
@@ -158,6 +158,17 @@ package Exp_Ch3 is
--  initialized; if Variable_Comps is True then tags components located at
--  variable positions of Target are initialized.
 
+   procedure Make_Controlling_Function_Wrappers
+ (Tag_Typ   : Entity_Id;
+  Decl_List : out List_Id;
+  Body_List : out List_Id);
+   --  Ada 2005 (AI-391): Makes specs and bodies for the wrapper functions
+   --  associated with inherited functions with controlling results which
+   --  are not overridden. The body of each wrapper function consists solely
+   --  of a return statement whose expression is an extension aggregate
+   --  invoking the inherited subprogram's parent subprogram and extended
+   --  with a null association list.
+
procedure Make_Predefined_Primitive_Eq_Spec
  (Tag_Typ : Entity_Id;
   Predef_List : List_Id;


diff --git a/gcc/ada/exp_spark.adb b/gcc/ada/exp_spark.adb
--- a/gcc/ada/exp_spark.adb
+++ b/gcc/ada/exp_spark.adb
@@ -903,6 +903,9 @@ package body Exp_SPARK is
   Eq_Spec : Node_Id := Empty;
   Predef_List : List_Id;
 
+  Wrapper_Decl_List : List_Id;
+  Wrapper_Body_List : List_Id := No_List;
+
   Saved_GM  : constant Ghost_Mode_Type := Ghost_Mode;
   Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
   --  Save the Ghost-related attributes to restore on exit
@@ -961,6 +964,35 @@ package body Exp_SPARK is
  end if;
   end if;
 
+  if Ekind (Typ) = E_Record_Type
+and then Is_Tagged_Type (Typ)
+and then not Is_CPP_Class (Typ)
+  then
+ --  Ada 2005 (AI-391): For a nonabstract null extension, create
+ --  wrapper functions for each nonoverridden inherited function
+ --  with a controlling result of the type. The wrapper for such
+ --  a function returns an extension aggregate that invokes the
+ --  parent function.
+
+ if Ada_Version >= Ada_2005
+   and then not Is_Abstract_Type (Typ)
+   and then Is_Null_Extension (Typ)
+ then
+Exp_Ch3.Make_Controlling_Function_Wrappers
+  (Typ, Wrapper_Decl_List, Wrapper_Body_List);
+Insert_List_Before_And_Analyze (N, Wrapper_Decl_List);
+ end if;
+
+ --  Ada 2005 (AI-391): If any wrappers were created for nonoverridden
+ --  inherited functions, then add their bodies to the AST, so they
+ --  will be processed like ordinary subprogram bodies (even though the
+ --  compiler adds them into the freezing action).
+
+ if not Is_Interface (Typ) then
+Insert_List_Before_And_Analyze (N, Wrapper_Body_List);
+ end if;
+  end if;
+
   Restore_Ghost_Region (Saved_GM, Saved_IGR);
end SPARK_Freeze_Type;
 




[Ada] Use Add_Char_To_Name_Buffer for 1-character strings

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Adding a single character to name buffer should be (marginally) more
efficient with Add_Char_To_Name_Buffer and not Add_Str_To_Name_Buffer.
Even if not more efficient, it should be still more readable.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_dbug.adb, sem_dim.adb: Replace Add_Str_To_Name_Buffer with
Add_Char_To_Name_Buffer.diff --git a/gcc/ada/exp_dbug.adb b/gcc/ada/exp_dbug.adb
--- a/gcc/ada/exp_dbug.adb
+++ b/gcc/ada/exp_dbug.adb
@@ -172,7 +172,7 @@ package body Exp_Dbug is
procedure Add_Real_To_Buffer (U : Ureal) is
begin
   Add_Uint_To_Buffer (Norm_Num (U));
-  Add_Str_To_Name_Buffer ("_");
+  Add_Char_To_Name_Buffer ('_');
   Add_Uint_To_Buffer (Norm_Den (U));
end Add_Real_To_Buffer;
 
@@ -671,7 +671,7 @@ package body Exp_Dbug is
  Add_Real_To_Buffer (Delta_Value (E));
 
  if Small_Value (E) /= Delta_Value (E) then
-Add_Str_To_Name_Buffer ("_");
+Add_Char_To_Name_Buffer ('_');
 Add_Real_To_Buffer (Small_Value (E));
  end if;
 
@@ -710,7 +710,7 @@ package body Exp_Dbug is
 
 if Lo_Encode or Hi_Encode then
if Biased then
-  Add_Str_To_Name_Buffer ("_");
+  Add_Char_To_Name_Buffer ('_');
else
   if Lo_Encode then
  if Hi_Encode then
@@ -1535,7 +1535,7 @@ package body Exp_Dbug is
 
begin
   Set_Entity_Name (Var);
-  Add_Str_To_Name_Buffer ("L");
+  Add_Char_To_Name_Buffer ('L');
   Set_Chars (Var, Name_Enter);
end;
 
@@ -1544,7 +1544,7 @@ package body Exp_Dbug is
   and then Ekind (Scope (Homonym (Ent))) = E_Block
 then
Set_Entity_Name (Ent);
-   Add_Str_To_Name_Buffer ("B");
+   Add_Char_To_Name_Buffer ('B');
Set_Chars (Ent, Name_Enter);
 end if;
  end if;


diff --git a/gcc/ada/sem_dim.adb b/gcc/ada/sem_dim.adb
--- a/gcc/ada/sem_dim.adb
+++ b/gcc/ada/sem_dim.adb
@@ -2759,7 +2759,7 @@ package body Sem_Dim is
 
   --  Insert a blank between the literal and the symbol
 
-  Add_Str_To_Name_Buffer (" ");
+  Add_Char_To_Name_Buffer (' ');
   Append (Global_Name_Buffer, Symbol_Of (Typ));
 
   Error_Msg_Name_1 := Name_Find;




[Ada] Simplify calls to Name_Find with known string parameter

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Code cleanup; semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* gnatls.adb (Gnatls): Use Name_Find function.
* targparm.adb (Get_Target_Parameters): Likewise.diff --git a/gcc/ada/gnatls.adb b/gcc/ada/gnatls.adb
--- a/gcc/ada/gnatls.adb
+++ b/gcc/ada/gnatls.adb
@@ -2092,10 +2092,7 @@ begin
  Hi   : Source_Ptr;
 
   begin
- Name_Buffer (1 .. 10) := "system.ads";
- Name_Len := 10;
-
- Read_Source_File (Name_Find, 0, Hi, Text, FD);
+ Read_Source_File (Name_Find ("system.ads"), 0, Hi, Text, FD);
 
  if Null_Source_Buffer_Ptr (Text) then
 No_Runtime := True;


diff --git a/gcc/ada/targparm.adb b/gcc/ada/targparm.adb
--- a/gcc/ada/targparm.adb
+++ b/gcc/ada/targparm.adb
@@ -157,10 +157,7 @@ package body Targparm is
  return;
   end if;
 
-  Name_Buffer (1 .. 10) := "system.ads";
-  Name_Len := 10;
-
-  Read_Source_File (Name_Find, 0, Hi, Text, FD);
+  Read_Source_File (Name_Find ("system.ads"), 0, Hi, Text, FD);
 
   if Null_Source_Buffer_Ptr (Text) then
  Write_Line ("fatal error, run-time library not installed correctly");




[Ada] Compiler crash with -gnatR2 and with of child

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
This patch fixes a bug where if a parent library package contains a with
clause that mentions a child of that same parent package, then gnat can
crash if the parent package is compiled with the -gnatR2 switch.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* repinfo.adb (List_Entities): The code was assuming that if we
encounter a package in the current scope, then it must be
a (physically) nested package.  That was wrong, because it could
be a child package.  Avoid recursing into child packages; they
have not been annotated with representation information, and
-gnatR2 queries that information.diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb
--- a/gcc/ada/repinfo.adb
+++ b/gcc/ada/repinfo.adb
@@ -568,12 +568,14 @@ package body Repinfo is
   end if;
end if;
 
-   --  Recurse into nested package, but not if they are package
-   --  renamings (in particular renamings of the enclosing package,
-   --  as for some Java bindings and for generic instances).
+   --  Recurse into nested package, but not child packages, and not
+   --  nested package renamings (in particular renamings of the
+   --  enclosing package, as for some Java bindings and for generic
+   --  instances).
 
if Ekind (E) = E_Package then
-  if No (Renamed_Entity (E)) then
+  if No (Renamed_Entity (E)) and then not Is_Child_Unit (E)
+  then
  List_Entities (E, Bytes_Big_Endian);
   end if;
 




[Ada] Remove obsolete s-sopco* and s-strops units

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
These units are not required anymore as oldest compiler version allowed
for bootstrap does not need them.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-sopco3.ads, libgnat/s-sopco3.adb: Remove.
* libgnat/s-sopco4.ads, libgnat/s-sopco4.adb: Remove.
* libgnat/s-sopco5.ads, libgnat/s-sopco5.adb: Remove.
* libgnat/s-strops.ads, libgnat/s-strops.adb: Remove.
* Makefile.rtl (ADA_EXCLUDE_SRCS): Remove occurences of removed
units.
* gcc-interface/Make-lang.in (ada/sdefault.o): Remove
dependencies on removed units.
(GNATBIND_OBJS): Remove occurences of removed units.

patch.diff.gz
Description: application/gzip


[Ada] Remove extra whitespace in declarations and parameters lists

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Remove extra whitespace spotted while doing other cleanups related to
expansion of dispatching routines for GNATprove.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch3.adb (Build_Dcheck_Function): Remove extra whitespace.
* libgnarl/s-taskin.adb (Initialize_ATCB): Likewise.diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -1045,10 +1045,10 @@ package body Exp_Ch3 is
 (Case_Id : Entity_Id;
  Variant : Node_Id) return Entity_Id
   is
- Body_Node   : Node_Id;
- Func_Id : Entity_Id;
- Parameter_List  : List_Id;
- Spec_Node   : Node_Id;
+ Body_Node  : Node_Id;
+ Func_Id: Entity_Id;
+ Parameter_List : List_Id;
+ Spec_Node  : Node_Id;
 
   begin
  Body_Node := New_Node (N_Subprogram_Body, Loc);


diff --git a/gcc/ada/libgnarl/s-taskin.adb b/gcc/ada/libgnarl/s-taskin.adb
--- a/gcc/ada/libgnarl/s-taskin.adb
+++ b/gcc/ada/libgnarl/s-taskin.adb
@@ -82,18 +82,18 @@ package body System.Tasking is
-
 
procedure Initialize_ATCB
- (Self_ID  : Task_Id;
-  Task_Entry_Point : Task_Procedure_Access;
-  Task_Arg : System.Address;
-  Parent   : Task_Id;
-  Elaborated   : Access_Boolean;
-  Base_Priority: System.Any_Priority;
-  Base_CPU : System.Multiprocessors.CPU_Range;
-  Domain   : Dispatching_Domain_Access;
-  Task_Info: System.Task_Info.Task_Info_Type;
-  Stack_Size   : System.Parameters.Size_Type;
-  T: Task_Id;
-  Success  : out Boolean)
+ (Self_ID  : Task_Id;
+  Task_Entry_Point : Task_Procedure_Access;
+  Task_Arg : System.Address;
+  Parent   : Task_Id;
+  Elaborated   : Access_Boolean;
+  Base_Priority: System.Any_Priority;
+  Base_CPU : System.Multiprocessors.CPU_Range;
+  Domain   : Dispatching_Domain_Access;
+  Task_Info: System.Task_Info.Task_Info_Type;
+  Stack_Size   : System.Parameters.Size_Type;
+  T: Task_Id;
+  Success  : out Boolean)
is
begin
   T.Common.State := Unactivated;
@@ -228,18 +228,18 @@ package body System.Tasking is
 
   T := STPO.New_ATCB (0);
   Initialize_ATCB
-(Self_ID  => null,
- Task_Entry_Point => null,
- Task_Arg => Null_Address,
- Parent   => Null_Task,
- Elaborated   => null,
- Base_Priority=> Base_Priority,
- Base_CPU => Base_CPU,
- Domain   => System_Domain,
- Task_Info=> Task_Info.Unspecified_Task_Info,
- Stack_Size   => 0,
- T=> T,
- Success  => Success);
+(Self_ID  => null,
+ Task_Entry_Point => null,
+ Task_Arg => Null_Address,
+ Parent   => Null_Task,
+ Elaborated   => null,
+ Base_Priority=> Base_Priority,
+ Base_CPU => Base_CPU,
+ Domain   => System_Domain,
+ Task_Info=> Task_Info.Unspecified_Task_Info,
+ Stack_Size   => 0,
+ T=> T,
+ Success  => Success);
   pragma Assert (Success);
 
   STPO.Initialize (T);




[Ada] Remove explicit "in" in internal parameter association

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Code cleanup related to expansion of dispatching routines for GNATprove.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_attr.adb (Build_Array_VS_Func): Remove explicit "IN" in
spec of the generated array validation function; it was
redundant, just like it would be in a user-written code.diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -404,8 +404,6 @@ package body Exp_Attr is
   Parameter_Specifications => New_List (
 Make_Parameter_Specification (Loc,
   Defining_Identifier => Obj_Id,
-  In_Present  => True,
-  Out_Present => False,
   Parameter_Type  => New_Occurrence_Of (Formal_Typ, Loc))),
   Result_Definition=>
 New_Occurrence_Of (Standard_Boolean, Loc)),




[Ada] Align arrows in parameter associations

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Whitespace cleanup; wrong layout found with grep.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch4.adb (Expand_N_Op_Ne): Fix whitespace.
* sem_dim.adb (Expand_Put_Call_With_Symbol): Likewise.
(Reduce): Likewise.diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -10067,7 +10067,7 @@ package body Exp_Ch4 is
   Make_Op_Not (Loc,
 Right_Opnd =>
   Make_Op_Eq (Loc,
-Left_Opnd =>  Left_Opnd (N),
+Left_Opnd  => Left_Opnd (N),
 Right_Opnd => Right_Opnd (N)));
 
 --  The level of parentheses is useless in GNATprove mode, and


diff --git a/gcc/ada/sem_dim.adb b/gcc/ada/sem_dim.adb
--- a/gcc/ada/sem_dim.adb
+++ b/gcc/ada/sem_dim.adb
@@ -3322,13 +3322,13 @@ package body Sem_Dim is
 if Chars (Name_Call) = Name_Image then
Rewrite (N,
  Make_Function_Call (Loc,
-   Name =>   New_Copy (Name_Call),
+   Name   => New_Copy (Name_Call),
Parameter_Associations => New_Actuals));
Analyze_And_Resolve (N);
 else
Rewrite (N,
  Make_Procedure_Call_Statement (Loc,
-   Name =>   New_Copy (Name_Call),
+   Name   => New_Copy (Name_Call),
Parameter_Associations => New_Actuals));
Analyze (N);
 end if;
@@ -3665,7 +3665,7 @@ package body Sem_Dim is
   declare
  G : constant Int := GCD (X.Numerator, X.Denominator);
   begin
- return Rational'(Numerator =>   Whole (Int (X.Numerator)   / G),
+ return Rational'(Numerator   => Whole (Int (X.Numerator)   / G),
   Denominator => Whole (Int (X.Denominator) / G));
   end;
end Reduce;




[Ada] Remove extra space in parameter associations

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Whitespace cleanup related to cleanup of creating copies of subprogram
specifications, which was needed for expanding dispatching wrappers for
GNATprove.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_aggr.adb (Two_Pass_Aggregate_Expansion): Fix whitespace.
* libgnat/a-cofuve.ads (Add): Likewise.
* sem_ch3.adb (Build_Access_Subprogram_Wrapper): Likewise.diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6408,7 +6408,7 @@ package body Exp_Aggr is
 One_Loop := Make_Loop_Statement (Loc,
   Iteration_Scheme =>
 Make_Iteration_Scheme (Loc,
-  Iterator_Specification =>  New_Copy_Tree (Iter)),
+  Iterator_Specification => New_Copy_Tree (Iter)),
 Statements => New_List (Incr));
 
 Append (One_Loop, Size_Expr_Code);
@@ -6540,7 +6540,7 @@ package body Exp_Aggr is
 One_Loop := Make_Loop_Statement (Loc,
   Iteration_Scheme =>
 Make_Iteration_Scheme (Loc,
-  Iterator_Specification =>  Copy_Separate_Tree (Iter)),
+  Iterator_Specification => Copy_Separate_Tree (Iter)),
 Statements => New_List (New_Comp, Incr));
 
 Append (One_Loop, Insertion_Code);


diff --git a/gcc/ada/libgnat/a-cofuve.ads b/gcc/ada/libgnat/a-cofuve.ads
--- a/gcc/ada/libgnat/a-cofuve.ads
+++ b/gcc/ada/libgnat/a-cofuve.ads
@@ -303,7 +303,7 @@ package Ada.Containers.Functional_Vectors with SPARK_Mode is
  and then Get (Add'Result, Position) = New_Item
  and then Range_Equal
 (Left  => Container,
- Right =>  Add'Result,
+ Right => Add'Result,
  Fst   => Index_Type'First,
  Lst   => Index_Type'Pred (Position))
  and then Range_Shifted


diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -6780,7 +6780,7 @@ package body Sem_Ch3 is
   Append (
  Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Temporary (Loc, 'P'),
-   Parameter_Type  =>  New_Occurrence_Of (Id, Loc)),
+   Parameter_Type  => New_Occurrence_Of (Id, Loc)),
  Profile);
 
   if Nkind (Type_Def) = N_Access_Procedure_Definition then




[Ada] Fix layout of parameters in calls to Predef_Spec_Or_Body

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Code cleanup related to expansion of dispatching routines for GNATprove.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch3.adb (Make_Eq_Body, Make_Neq_Body,
Make_Predefined_Primitive_Eq_Spec,
Make_Predefined_Primitive_Specs): Fix whitespace.diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -9800,9 +9800,9 @@ package body Exp_Ch3 is
begin
   Decl :=
 Predef_Spec_Or_Body (Loc,
-  Tag_Typ => Typ,
-  Name=> Eq_Name,
-  Profile => New_List (
+  Tag_Typ  => Typ,
+  Name => Eq_Name,
+  Profile  => New_List (
 Make_Parameter_Specification (Loc,
   Defining_Identifier =>
 Make_Defining_Identifier (Loc, Name_X),
@@ -10193,9 +10193,9 @@ package body Exp_Ch3 is
 
   Decl :=
 Predef_Spec_Or_Body (Loc,
-  Tag_Typ => Tag_Typ,
-  Name=> Chars (Renaming_Prim),
-  Profile => New_List (
+  Tag_Typ  => Tag_Typ,
+  Name => Chars (Renaming_Prim),
+  Profile  => New_List (
 Make_Parameter_Specification (Loc,
   Defining_Identifier =>
 Make_Defining_Identifier (Loc, Chars (Left_Op)),
@@ -10450,9 +10450,9 @@ package body Exp_Ch3 is
 
   if Eq_Needed then
  Eq_Spec := Predef_Spec_Or_Body (Loc,
-   Tag_Typ => Tag_Typ,
-   Name=> Eq_Name,
-   Profile => New_List (
+   Tag_Typ  => Tag_Typ,
+   Name => Eq_Name,
+   Profile  => New_List (
  Make_Parameter_Specification (Loc,
Defining_Identifier =>
  Make_Defining_Identifier (Loc, Name_X),
@@ -10462,7 +10462,7 @@ package body Exp_Ch3 is
Defining_Identifier =>
  Make_Defining_Identifier (Loc, Name_Y),
Parameter_Type  => New_Occurrence_Of (Tag_Typ, Loc))),
- Ret_Type => Standard_Boolean);
+   Ret_Type => Standard_Boolean);
  Append_To (Predef_List, Eq_Spec);
 
  if Has_Predef_Eq_Renaming then
@@ -10514,9 +10514,9 @@ package body Exp_Ch3 is
   --  Spec of _Size
 
   Append_To (Res, Predef_Spec_Or_Body (Loc,
-Tag_Typ => Tag_Typ,
-Name=> Name_uSize,
-Profile => New_List (
+Tag_Typ  => Tag_Typ,
+Name => Name_uSize,
+Profile  => New_List (
   Make_Parameter_Specification (Loc,
 Defining_Identifier => Make_Defining_Identifier (Loc, Name_X),
 Parameter_Type  => New_Occurrence_Of (Tag_Typ, Loc))),




[Ada] Fix condition to build subtype for discriminated types

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
We should build subtype for discriminated types in several situations
where we know a priori that we never need to allocate the max possible
size.

To factorize these conditions between `Analyze_Component_Declaration`
and `Analyze_Object_Declaration`, the function `Should_Build_Subtypes`
is introduced.

This new function fixes the condition for the following case:

   type Foo (Size : Natural) is record
  Bar : aliased Synchronized_Bounded_Queue_Package.Queue;
  Name : String (1..Size);
   end record;

For that case, the condition relied on the fact that `Current_Scope` is
discriminated to not build the subtype. A priori, it was thought that
the Foo discriminant would be used for Bar.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Analyze_Component_Declaration): Rework condition
to build subtypes.
(Analyze_Object_Declaration): Likewise.
(Should_Build_Subtype): New.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -723,6 +723,16 @@ package body Sem_Ch3 is
--  sets the flags SSO_Set_Low_By_Default/SSO_Set_High_By_Default according
--  to the setting of Opt.Default_SSO.
 
+   function Should_Build_Subtype (T : Entity_Id) return Boolean;
+   --  When analyzing components or object declarations, it is possible, in
+   --  some cases, to build subtypes for discriminated types. This is
+   --  worthwhile to avoid the backend allocating the maximum possible size for
+   --  objects of the type.
+   --  In particular, when T is limited, the discriminants and therefore the
+   --  size of an object of type T cannot change. Furthermore, if T is definite
+   --  with statically initialized defaulted discriminants, we are able and
+   --  want to build a constrained subtype of the right size.
+
procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id);
--  Create a new signed integer entity, and apply the constraint to obtain
--  the required first named subtype of this type.
@@ -2203,17 +2213,9 @@ package body Sem_Ch3 is
  end if;
   end if;
 
-  --  If the component is an unconstrained task or protected type with
-  --  discriminants, the component and the enclosing record are limited
-  --  and the component is constrained by its default values. Compute
-  --  its actual subtype, else it may be allocated the maximum size by
-  --  the backend, and possibly overflow.
+  --  When possible, build the default subtype
 
-  if Is_Concurrent_Type (T)
-and then not Is_Constrained (T)
-and then Has_Discriminants (T)
-and then not Has_Discriminants (Current_Scope)
-  then
+  if Should_Build_Subtype (T) then
  declare
 Act_T : constant Entity_Id := Build_Default_Subtype (T, N);
 
@@ -4799,14 +4801,9 @@ package body Sem_Ch3 is
 Apply_Length_Check (E, T);
  end if;
 
-  --  If the type is limited unconstrained with defaulted discriminants and
-  --  there is no expression, then the object is constrained by the
-  --  defaults, so it is worthwhile building the corresponding subtype.
+  --  When possible, build the default subtype
 
-  elsif (Is_Limited_Record (T) or else Is_Concurrent_Type (T))
-and then not Is_Constrained (T)
-and then Has_Discriminants (T)
-  then
+  elsif Should_Build_Subtype (T) then
  if No (E) then
 Act_T := Build_Default_Subtype (T, N);
  else
@@ -22879,6 +22876,80 @@ package body Sem_Ch3 is
   end if;
end Set_Stored_Constraint_From_Discriminant_Constraint;
 
+   --
+   -- Should_Build_Subtype --
+   --
+
+   function Should_Build_Subtype (T : Entity_Id) return Boolean is
+
+  function Default_Discriminant_Values_Known_At_Compile_Time
+ (T : Entity_Id) return Boolean;
+ --  For an unconstrained type T, return False if the given type has a
+ --  discriminant with default value not known at compile time. Return
+ --  True otherwise.
+
+  -
+  -- Default_Discriminant_Values_Known_At_Compile_Time --
+  -
+
+  function Default_Discriminant_Values_Known_At_Compile_Time
+ (T : Entity_Id) return Boolean
+  is
+ Discr : Entity_Id;
+ DDV : Node_Id;
+
+  begin
+
+ --  If the type has no discriminant, we know them all at compile time
+
+ if not Has_Discriminants (T) then
+return True;
+ end if;
+
+ --  The type has discriminants, check that none of them has a default
+ --  value not known at compile time.
+
+ Discr := First_Discriminant (T);
+
+ while Present (Discr) loop
+DDV := Discriminant_Default_Value (Discr);
+
+if Present (DDV) 

[Ada] Add contracts for the proof of System.Arith_128

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Similar to the contracts added for the 32bits and 64bits versions, add
corresponding contracts for the 128bits version. Proof is currently too
difficult for this instance of generic System.Arith_Double, as even with
a huge prover timeout of 15 minutes, 2 checks remain unproved.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-arit128.adb: Mark in SPARK.
* libgnat/s-arit128.ads: Add functional contracts.diff --git a/gcc/ada/libgnat/s-arit128.adb b/gcc/ada/libgnat/s-arit128.adb
--- a/gcc/ada/libgnat/s-arit128.adb
+++ b/gcc/ada/libgnat/s-arit128.adb
@@ -31,7 +31,9 @@
 
 with System.Arith_Double;
 
-package body System.Arith_128 is
+package body System.Arith_128
+  with SPARK_Mode
+is
 
subtype Uns128 is Interfaces.Unsigned_128;
subtype Uns64  is Interfaces.Unsigned_64;


diff --git a/gcc/ada/libgnat/s-arit128.ads b/gcc/ada/libgnat/s-arit128.ads
--- a/gcc/ada/libgnat/s-arit128.ads
+++ b/gcc/ada/libgnat/s-arit128.ads
@@ -36,31 +36,102 @@
 pragma Restrictions (No_Elaboration_Code);
 --  Allow direct call from gigi generated code
 
+--  Preconditions in this unit are meant for analysis only, not for run-time
+--  checking, so that the expected exceptions are raised. This is enforced
+--  by setting the corresponding assertion policy to Ignore. Postconditions
+--  and contract cases should not be executed at runtime as well, in order
+--  not to slow down the execution of these functions.
+
+pragma Assertion_Policy (Pre=> Ignore,
+ Post   => Ignore,
+ Contract_Cases => Ignore,
+ Ghost  => Ignore);
+
+with Ada.Numerics.Big_Numbers.Big_Integers_Ghost;
 with Interfaces;
 
-package System.Arith_128 is
-   pragma Pure;
+package System.Arith_128
+  with Pure, SPARK_Mode
+is
+   use type Ada.Numerics.Big_Numbers.Big_Integers_Ghost.Big_Integer;
+   use type Interfaces.Integer_128;
 
subtype Int128 is Interfaces.Integer_128;
 
-   function Add_With_Ovflo_Check128 (X, Y : Int128) return Int128;
+   subtype Big_Integer is
+ Ada.Numerics.Big_Numbers.Big_Integers_Ghost.Big_Integer
+   with Ghost;
+
+   package Signed_Conversion is new
+ Ada.Numerics.Big_Numbers.Big_Integers_Ghost.Signed_Conversions
+ (Int => Int128);
+
+   function Big (Arg : Int128) return Big_Integer is
+ (Signed_Conversion.To_Big_Integer (Arg))
+   with Ghost;
+
+   function In_Int128_Range (Arg : Big_Integer) return Boolean is
+ (Ada.Numerics.Big_Numbers.Big_Integers_Ghost.In_Range
+   (Arg, Big (Int128'First), Big (Int128'Last)))
+   with Ghost;
+
+   function Add_With_Ovflo_Check128 (X, Y : Int128) return Int128
+   with
+ Pre  => In_Int128_Range (Big (X) + Big (Y)),
+ Post => Add_With_Ovflo_Check128'Result = X + Y;
--  Raises Constraint_Error if sum of operands overflows 128 bits,
--  otherwise returns the 128-bit signed integer sum.
 
-   function Subtract_With_Ovflo_Check128 (X, Y : Int128) return Int128;
+   function Subtract_With_Ovflo_Check128 (X, Y : Int128) return Int128
+   with
+ Pre  => In_Int128_Range (Big (X) - Big (Y)),
+ Post => Subtract_With_Ovflo_Check128'Result = X - Y;
--  Raises Constraint_Error if difference of operands overflows 128
--  bits, otherwise returns the 128-bit signed integer difference.
 
-   function Multiply_With_Ovflo_Check128 (X, Y : Int128) return Int128;
+   function Multiply_With_Ovflo_Check128 (X, Y : Int128) return Int128
+   with
+ Pre  => In_Int128_Range (Big (X) * Big (Y)),
+ Post => Multiply_With_Ovflo_Check128'Result = X * Y;
pragma Export (C, Multiply_With_Ovflo_Check128, "__gnat_mulv128");
--  Raises Constraint_Error if product of operands overflows 128
--  bits, otherwise returns the 128-bit signed integer product.
--  Gigi may also call this routine directly.
 
+   function Same_Sign (X, Y : Big_Integer) return Boolean is
+ (X = Big (Int128'(0))
+or else Y = Big (Int128'(0))
+or else (X < Big (Int128'(0))) = (Y < Big (Int128'(0
+   with Ghost;
+
+   function Round_Quotient (X, Y, Q, R : Big_Integer) return Big_Integer is
+ (if abs R > (abs Y - Big (Int128'(1))) / Big (Int128'(2)) then
+   (if Same_Sign (X, Y) then Q + Big (Int128'(1))
+else Q - Big (Int128'(1)))
+  else
+Q)
+   with
+ Ghost,
+ Pre => Y /= 0 and then Q = X / Y and then R = X rem Y;
+
procedure Scaled_Divide128
  (X, Y, Z : Int128;
   Q, R: out Int128;
-  Round   : Boolean);
+  Round   : Boolean)
+   with
+ Pre  => Z /= 0
+   and then In_Int128_Range
+ (if Round then Round_Quotient (Big (X) * Big (Y), Big (Z),
+Big (X) * Big (Y) / Big (Z),
+Big (X) * Big (Y) rem Big (Z))
+  else Big (X) * Big (Y) / Big (Z)),
+ Post => Big (R) = Big (X) * Big (Y) rem Big (Z)
+   and then
+ (if Round then
+Big (Q) = 

[Ada] Simplify handling of user-defined numeric literals

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Code cleanup; semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_util.adb (String_From_Numeric_Literal): Simplify using
membership tests and ranges; fix whitespace.diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -28978,7 +28978,7 @@ package body Sem_Util is
   Source_Text (Get_Source_File_Index (Loc));
   Src_Ptr : Source_Ptr := Loc;
 
-  C : Character  := Sbuffer (Src_Ptr);
+  C : Character := Sbuffer (Src_Ptr);
   --  Current source program character
 
   function Belongs_To_Numeric_Literal (C : Character) return Boolean;
@@ -28991,9 +28991,7 @@ package body Sem_Util is
   function Belongs_To_Numeric_Literal (C : Character) return Boolean is
   begin
  case C is
-when '0' .. '9'
-   | '_' | '.' | 'e' | '#' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
-=>
+when '0' .. '9' | '_' | '.' | 'e' | '#' | 'A' .. 'F' =>
return True;
 
 --  Make sure '+' or '-' is part of an exponent
@@ -29002,7 +29000,7 @@ package body Sem_Util is
declare
   Prev_C : constant Character := Sbuffer (Src_Ptr - 1);
begin
-  return Prev_C = 'e' or else Prev_C = 'E';
+  return Prev_C in 'e' | 'E';
end;
 
 --  Other characters cannot belong to a numeric literal




[Ada] Proof of runtime units for integer exponentiation (checks on)

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
This proves the generic unit System.Expont instantiated for Integer,
Long_Long_Integer and Long_Long_Long_Integer. The proof is similar to
the one done for the same units with checks off. In this case too, the
generic function is changed into a generic package.

GNATprove is called with switch --level=2.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-expint.ads: Mark in SPARK. Adapt to change to
package.
* libgnat/s-explli.ads: Likewise.
* libgnat/s-expllli.ads: Likewise.
* libgnat/s-expont.adb: Add lemmas and ghost code.
* libgnat/s-expont.ads: Add functional contract.diff --git a/gcc/ada/libgnat/s-expint.ads b/gcc/ada/libgnat/s-expint.ads
--- a/gcc/ada/libgnat/s-expint.ads
+++ b/gcc/ada/libgnat/s-expint.ads
@@ -31,11 +31,26 @@
 
 --  Integer exponentiation (checks on)
 
+--  Preconditions, postconditions, ghost code, loop invariants and assertions
+--  in this unit are meant for analysis only, not for run-time checking, as it
+--  would be too costly otherwise. This is enforced by setting the assertion
+--  policy to Ignore.
+
+pragma Assertion_Policy (Pre=> Ignore,
+ Post   => Ignore,
+ Ghost  => Ignore,
+ Loop_Invariant => Ignore,
+ Assert => Ignore);
+
 with System.Expont;
 
-package System.Exp_Int is
+package System.Exp_Int
+  with SPARK_Mode
+is
+
+   package Expont_Integer is new Expont (Integer);
 
-   function Exp_Integer is new Expont (Integer);
-   pragma Pure_Function (Exp_Integer);
+   function Exp_Integer (Left : Integer; Right : Natural) return Integer
+ renames Expont_Integer.Expon;
 
 end System.Exp_Int;


diff --git a/gcc/ada/libgnat/s-explli.ads b/gcc/ada/libgnat/s-explli.ads
--- a/gcc/ada/libgnat/s-explli.ads
+++ b/gcc/ada/libgnat/s-explli.ads
@@ -31,11 +31,27 @@
 
 --  Long_Long_Integer exponentiation (checks on)
 
+--  Preconditions, postconditions, ghost code, loop invariants and assertions
+--  in this unit are meant for analysis only, not for run-time checking, as it
+--  would be too costly otherwise. This is enforced by setting the assertion
+--  policy to Ignore.
+
+pragma Assertion_Policy (Pre=> Ignore,
+ Post   => Ignore,
+ Ghost  => Ignore,
+ Loop_Invariant => Ignore,
+ Assert => Ignore);
+
 with System.Expont;
 
-package System.Exp_LLI is
+package System.Exp_LLI
+  with SPARK_Mode
+is
+
+   package Expont_Integer is new Expont (Long_Long_Integer);
 
-   function Exp_Long_Long_Integer is new Expont (Long_Long_Integer);
-   pragma Pure_Function (Exp_Long_Long_Integer);
+   function Exp_Long_Long_Integer
+ (Left : Long_Long_Integer; Right : Natural) return Long_Long_Integer
+ renames Expont_Integer.Expon;
 
 end System.Exp_LLI;


diff --git a/gcc/ada/libgnat/s-expllli.ads b/gcc/ada/libgnat/s-expllli.ads
--- a/gcc/ada/libgnat/s-expllli.ads
+++ b/gcc/ada/libgnat/s-expllli.ads
@@ -31,11 +31,28 @@
 
 --  Long_Long_Long_Integer exponentiation (checks on)
 
+--  Preconditions, postconditions, ghost code, loop invariants and assertions
+--  in this unit are meant for analysis only, not for run-time checking, as it
+--  would be too costly otherwise. This is enforced by setting the assertion
+--  policy to Ignore.
+
+pragma Assertion_Policy (Pre=> Ignore,
+ Post   => Ignore,
+ Ghost  => Ignore,
+ Loop_Invariant => Ignore,
+ Assert => Ignore);
+
 with System.Expont;
 
-package System.Exp_LLLI is
+package System.Exp_LLLI
+  with SPARK_Mode
+is
+
+   package Expont_Integer is new Expont (Long_Long_Long_Integer);
 
-   function Exp_Long_Long_Long_Integer is new Expont (Long_Long_Long_Integer);
-   pragma Pure_Function (Exp_Long_Long_Long_Integer);
+   function Exp_Long_Long_Long_Integer
+ (Left : Long_Long_Long_Integer; Right : Natural)
+  return Long_Long_Long_Integer
+ renames Expont_Integer.Expon;
 
 end System.Exp_LLLI;


diff --git a/gcc/ada/libgnat/s-expont.adb b/gcc/ada/libgnat/s-expont.adb
--- a/gcc/ada/libgnat/s-expont.adb
+++ b/gcc/ada/libgnat/s-expont.adb
@@ -29,44 +29,198 @@
 --  --
 --
 
-function System.Expont (Left : Int; Right : Natural) return Int is
+package body System.Expont
+  with SPARK_Mode
+is
 
-   --  Note that negative exponents get a constraint error because the
-   --  subtype of the Right argument (the exponent) is Natural.
+   --  Preconditions, postconditions, ghost code, loop invariants and
+   --  assertions in this unit are meant for analysis only, not for run-time
+   --  checking, as it would be too costly otherwise. 

[Ada] Remove unnecessary check for missing parameter specifications

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
List iteration with First/Present/Next is safe even for No_List. This
safety is intentional and we rely on it in many places.

Code cleanup; semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_disp.adb (Gen_Parameters_Profile): Remove redundant guard.diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -8065,19 +8065,17 @@ package body Exp_Disp is
Out_Present => True,
Parameter_Type  => New_Occurrence_Of (Typ, Loc)));
 
- if Present (Parameter_Specifications (Parent (E))) then
-P := First (Parameter_Specifications (Parent (E)));
-while Present (P) loop
-   Append_To (Parms,
- Make_Parameter_Specification (Loc,
-   Defining_Identifier =>
- Make_Defining_Identifier (Loc,
-   Chars => Chars (Defining_Identifier (P))),
-   Parameter_Type  => New_Copy_Tree (Parameter_Type (P)),
-   Expression  => New_Copy_Tree (Expression (P;
-   Next (P);
-end loop;
- end if;
+ P := First (Parameter_Specifications (Parent (E)));
+ while Present (P) loop
+Append_To (Parms,
+  Make_Parameter_Specification (Loc,
+Defining_Identifier =>
+  Make_Defining_Identifier (Loc,
+Chars => Chars (Defining_Identifier (P))),
+Parameter_Type  => New_Copy_Tree (Parameter_Type (P)),
+Expression  => New_Copy_Tree (Expression (P;
+Next (P);
+ end loop;
 
  return Parms;
   end Gen_Parameters_Profile;




[Ada] Introduce expression functions for contract of Scan_Exponent

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Introduce expression functions to make the contract of Scan_Exponent
more readable. They can be reused in the contracts of scan functions for
scalar types.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-valuti.ads (Starts_As_Exponent_Format_Ghost): Ghost
function to determine if a string is recognized as something
which might be an exponent.
(Is_Opt_Exponent_Format_Ghost): Ghost function to determine if a
string has the correct format for an optional exponent.
(Scan_Exponent): Use ghost functions to factorize contracts.diff --git a/gcc/ada/libgnat/s-valuti.ads b/gcc/ada/libgnat/s-valuti.ads
--- a/gcc/ada/libgnat/s-valuti.ads
+++ b/gcc/ada/libgnat/s-valuti.ads
@@ -213,6 +213,50 @@ is
--  natural number, consisting in a sequence of figures possibly separated
--  by single underscores. It may be followed by other characters.
 
+   function Starts_As_Exponent_Format_Ghost
+ (Str  : String;
+  Real : Boolean) return Boolean
+   is
+ (Str'Length > 1
+  and then Str (Str'First) in 'E' | 'e'
+  and then
+(declare
+Plus_Sign  : constant Boolean := Str (Str'First + 1) = '+';
+Minus_Sign : constant Boolean := Str (Str'First + 1) = '-';
+Sign   : constant Boolean := Plus_Sign or Minus_Sign;
+ begin
+   (if Minus_Sign then Real)
+and then (if Sign then Str'Length > 2)
+and then
+  (declare
+ Start : constant Natural :=
+  (if Sign then Str'First + 2 else Str'First + 1);
+   begin
+ Str (Start) in '0' .. '9')))
+   with
+ Ghost;
+   --  Ghost function that determines if Str is recognized as something which
+   --  might be an exponent, ie. it starts with an 'e', capitalized or not,
+   --  followed by an optional sign which can only be '-' if we are working on
+   --  real numbers (Real is True), and then a digit in decimal notation.
+
+   function Is_Opt_Exponent_Format_Ghost
+ (Str  : String;
+  Real : Boolean) return Boolean
+   is
+ (not Starts_As_Exponent_Format_Ghost (Str, Real)
+  or else
+(declare
+   Start : constant Natural :=
+ (if Str (Str'First + 1) in '+' | '-' then Str'First + 2
+  else Str'First + 1);
+ begin Is_Natural_Format_Ghost (Str (Start .. Str'Last
+   with
+ Ghost;
+   --  Ghost function that determines if Str has the correct format for an
+   --  optional exponent, that is, either it does not start as an exponent, or
+   --  it is in a correct format for a natural number.
+
function Scan_Natural_Ghost
  (Str : String;
   P   : Natural;
@@ -238,50 +282,22 @@ is
  Pre =>
--  Ptr.all .. Max is either an empty range, or a valid range in Str
(Ptr.all > Max or else (Ptr.all >= Str'First and then Max <= Str'Last))
- and then
-   Max < Natural'Last
- and then
-   (if Ptr.all < Max and then Str (Ptr.all) in 'E' | 'e' then
-  (declare
- Plus_Sign  : constant Boolean := Str (Ptr.all + 1) = '+';
- Minus_Sign : constant Boolean := Str (Ptr.all + 1) = '-';
- Sign   : constant Boolean := Plus_Sign or Minus_Sign;
-   begin
- (if Minus_Sign and not Real then True
-  elsif Sign
-and then (Ptr.all > Max - 2
-or else Str (Ptr.all + 2) not in '0' .. '9')
-  then True
-  else
-(declare
-   Start : constant Natural :=
- (if Sign then Ptr.all + 2 else Ptr.all + 1);
- begin
-   Is_Natural_Format_Ghost (Str (Start .. Max)),
+ and then Max < Natural'Last
+ and then Is_Opt_Exponent_Format_Ghost (Str (Ptr.all .. Max), Real),
  Post =>
-   (if Ptr.all'Old < Max and then Str (Ptr.all'Old) in 'E' | 'e' then
+   (if Starts_As_Exponent_Format_Ghost (Str (Ptr.all'Old .. Max), Real)
+then
   (declare
  Plus_Sign  : constant Boolean := Str (Ptr.all'Old + 1) = '+';
  Minus_Sign : constant Boolean := Str (Ptr.all'Old + 1) = '-';
  Sign   : constant Boolean := Plus_Sign or Minus_Sign;
- Unchanged  : constant Boolean :=
-   Exp = 0 and Ptr.all = Ptr.all'Old;
+ Start  : constant Natural :=
+   (if Sign then Ptr.all'Old + 2 else Ptr.all'Old + 1);
+ Value  : constant Natural :=
+   Scan_Natural_Ghost (Str (Start .. Max), Start, 0);
begin
- (if Minus_Sign and not Real then Unchanged
-  elsif Sign
-and then (Ptr.all'Old > Max - 2
-or else Str (Ptr.all'Old + 2) not in '0' .. '9')
-  then Unchanged
-  else
-(declare
-   Start : 

[Ada] Prevent Get_Current_Value_Condition from returning the same node

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Get_Current_Value_Condition should never return Val = Var, because that
could cause infinite recursion in Known_Null.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_util.ads (Get_Current_Value_Condition): Belt: Add a
postcondition that Val /= Var.
* sem_util.adb (Known_Null): Suspenders: Raise Program_Error if
Get_Current_Value_Condition returned the same value. This will
be enabled even without assertions, because infinite recursion
is a nuisance -- better to crash if this bug ever occurs.diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads
--- a/gcc/ada/exp_util.ads
+++ b/gcc/ada/exp_util.ads
@@ -703,7 +703,7 @@ package Exp_Util is
procedure Get_Current_Value_Condition
  (Var : Node_Id;
   Op  : out Node_Kind;
-  Val : out Node_Id);
+  Val : out Node_Id) with Post => Val /= Var;
--  This routine processes the Current_Value field of the variable Var. If
--  the Current_Value field is null or if it represents a known value, then
--  on return Cond is set to N_Empty, and Val is set to Empty.


diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -22062,6 +22062,13 @@ package body Sem_Util is
 
  Get_Current_Value_Condition (N, Op, Val);
 
+ --  If Get_Current_Value_Condition were to return Val = N, then the
+ --  recursion below could be infinite.
+
+ if Val = N then
+raise Program_Error;
+ end if;
+
  if Known_Null (Val) then
 if Op = N_Op_Eq then
return True;




[Ada] Simplify making of null procedure wrappers

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Yet another cleanup related to expansion of dispatching primitives for
GNATprove. To keep this change semantically neutral, one parameter is
added to the Copy_Subprogram_Spec utility routine.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch3.adb (Make_Null_Procedure_Specs): Simplify by reusing
Copy_Subprogram_Spec.
* sem_util.ads (Copy_Subprogram_Spec): Add New_Sloc parameter.
* sem_util.adb (Copy_Subprogram_Spec): Pass New_Sloc to
New_Copy_Tree.diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -10265,8 +10265,8 @@ package body Exp_Ch3 is
   Decl_List  : constant List_Id:= New_List;
   Loc: constant Source_Ptr := Sloc (Tag_Typ);
   Formal : Entity_Id;
-  Formal_List: List_Id;
   New_Param_Spec : Node_Id;
+  New_Spec   : Node_Id;
   Parent_Subp: Entity_Id;
   Prim_Elmt  : Elmt_Id;
   Subp   : Entity_Id;
@@ -10285,59 +10285,47 @@ package body Exp_Ch3 is
  if Present (Parent_Subp)
and then Is_Null_Interface_Primitive (Parent_Subp)
  then
-Formal := First_Formal (Subp);
-
-if Present (Formal) then
-   Formal_List := New_List;
-
-   while Present (Formal) loop
+--  The null procedure spec is copied from the inherited procedure,
+--  except for the IS NULL (which must be added) and the overriding
+--  indicators (which must be removed, if present).
 
-  --  Copy the parameter spec including default expressions
+New_Spec :=
+  Copy_Subprogram_Spec (Subprogram_Specification (Subp), Loc);
 
-  New_Param_Spec :=
-New_Copy_Tree (Parent (Formal), New_Sloc => Loc);
+Set_Null_Present  (New_Spec, True);
+Set_Must_Override (New_Spec, False);
+Set_Must_Not_Override (New_Spec, False);
 
-  --  Generate a new defining identifier for the new formal.
-  --  Required because New_Copy_Tree does not duplicate
-  --  semantic fields (except itypes).
+Formal := First_Formal (Subp);
+New_Param_Spec := First (Parameter_Specifications (New_Spec));
 
-  Set_Defining_Identifier (New_Param_Spec,
-Make_Defining_Identifier (Sloc (Formal),
-  Chars => Chars (Formal)));
+while Present (Formal) loop
 
-  --  For controlling arguments we must change their parameter
-  --  type to reference the tagged type (instead of the
-  --  interface type).
+   --  For controlling arguments we must change their parameter
+   --  type to reference the tagged type (instead of the interface
+   --  type).
 
-  if Is_Controlling_Formal (Formal) then
- if Nkind (Parameter_Type (Parent (Formal))) = N_Identifier
- then
-Set_Parameter_Type (New_Param_Spec,
-  New_Occurrence_Of (Tag_Typ, Loc));
-
- else pragma Assert
-(Nkind (Parameter_Type (Parent (Formal))) =
-N_Access_Definition);
-Set_Subtype_Mark (Parameter_Type (New_Param_Spec),
-  New_Occurrence_Of (Tag_Typ, Loc));
- end if;
+   if Is_Controlling_Formal (Formal) then
+  if Nkind (Parameter_Type (Parent (Formal))) = N_Identifier
+  then
+ Set_Parameter_Type (New_Param_Spec,
+   New_Occurrence_Of (Tag_Typ, Loc));
+
+  else pragma Assert
+ (Nkind (Parameter_Type (Parent (Formal))) =
+ N_Access_Definition);
+ Set_Subtype_Mark (Parameter_Type (New_Param_Spec),
+   New_Occurrence_Of (Tag_Typ, Loc));
   end if;
+   end if;
 
-  Append (New_Param_Spec, Formal_List);
-
-  Next_Formal (Formal);
-   end loop;
-else
-   Formal_List := No_List;
-end if;
+   Next_Formal (Formal);
+   Next (New_Param_Spec);
+end loop;
 
 Append_To (Decl_List,
   Make_Subprogram_Declaration (Loc,
-Make_Procedure_Specification (Loc,
-  Defining_Unit_Name   =>
-Make_Defining_Identifier (Loc, Chars (Subp)),
-  Parameter_Specifications => Formal_List,
-  Null_Present => True)));
+Specification => New_Spec));
  end if;
 
  

[Ada] Proof of runtime units for integer exponentiation (checks off)

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
This proves the generic unit System.Exponn instanciated for Integer,
Long_Long_Integer and Long_Long_Long_Integer. In order to be able to add
a suitable contract to the generic function, it is changed into a
generic package which contains the function. Instantiations are adapted.

GNATprove is called with switch --level=2.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-exnint.ads: Mark in SPARK. Adapt to change to
package.
* libgnat/s-exnlli.ads: Likewise.
* libgnat/s-exnllli.ads: Likewise.
* libgnat/s-exponn.adb: Add lemmas and ghost code. Secial case
value zero as Left or Right to simplify proof.
* libgnat/s-exponn.ads: Transform the generic function into a
generic package with a function inside. Add a functional
contract.diff --git a/gcc/ada/libgnat/s-exnint.ads b/gcc/ada/libgnat/s-exnint.ads
--- a/gcc/ada/libgnat/s-exnint.ads
+++ b/gcc/ada/libgnat/s-exnint.ads
@@ -31,11 +31,26 @@
 
 --  Integer exponentiation (checks off)
 
+--  Preconditions, postconditions, ghost code, loop invariants and assertions
+--  in this unit are meant for analysis only, not for run-time checking, as it
+--  would be too costly otherwise. This is enforced by setting the assertion
+--  policy to Ignore.
+
+pragma Assertion_Policy (Pre=> Ignore,
+ Post   => Ignore,
+ Ghost  => Ignore,
+ Loop_Invariant => Ignore,
+ Assert => Ignore);
+
 with System.Exponn;
 
-package System.Exn_Int is
+package System.Exn_Int
+  with SPARK_Mode
+is
+
+   package Exponn_Integer is new Exponn (Integer);
 
-   function Exn_Integer is new Exponn (Integer);
-   pragma Pure_Function (Exn_Integer);
+   function Exn_Integer (Left : Integer; Right : Natural) return Integer
+ renames Exponn_Integer.Expon;
 
 end System.Exn_Int;


diff --git a/gcc/ada/libgnat/s-exnlli.ads b/gcc/ada/libgnat/s-exnlli.ads
--- a/gcc/ada/libgnat/s-exnlli.ads
+++ b/gcc/ada/libgnat/s-exnlli.ads
@@ -31,11 +31,27 @@
 
 --  Long_Long_Integer exponentiation (checks off)
 
+--  Preconditions, postconditions, ghost code, loop invariants and assertions
+--  in this unit are meant for analysis only, not for run-time checking, as it
+--  would be too costly otherwise. This is enforced by setting the assertion
+--  policy to Ignore.
+
+pragma Assertion_Policy (Pre=> Ignore,
+ Post   => Ignore,
+ Ghost  => Ignore,
+ Loop_Invariant => Ignore,
+ Assert => Ignore);
+
 with System.Exponn;
 
-package System.Exn_LLI is
+package System.Exn_LLI
+  with SPARK_Mode
+is
+
+   package Exponn_Integer is new Exponn (Long_Long_Integer);
 
-   function Exn_Long_Long_Integer is new Exponn (Long_Long_Integer);
-   pragma Pure_Function (Exn_Long_Long_Integer);
+   function Exn_Long_Long_Integer
+ (Left : Long_Long_Integer; Right : Natural) return Long_Long_Integer
+ renames Exponn_Integer.Expon;
 
 end System.Exn_LLI;


diff --git a/gcc/ada/libgnat/s-exnllli.ads b/gcc/ada/libgnat/s-exnllli.ads
--- a/gcc/ada/libgnat/s-exnllli.ads
+++ b/gcc/ada/libgnat/s-exnllli.ads
@@ -31,11 +31,28 @@
 
 --  Long_Long_Long_Integer exponentiation (checks off)
 
+--  Preconditions, postconditions, ghost code, loop invariants and assertions
+--  in this unit are meant for analysis only, not for run-time checking, as it
+--  would be too costly otherwise. This is enforced by setting the assertion
+--  policy to Ignore.
+
+pragma Assertion_Policy (Pre=> Ignore,
+ Post   => Ignore,
+ Ghost  => Ignore,
+ Loop_Invariant => Ignore,
+ Assert => Ignore);
+
 with System.Exponn;
 
-package System.Exn_LLLI is
+package System.Exn_LLLI
+  with SPARK_Mode
+is
+
+   package Exponn_Integer is new Exponn (Long_Long_Long_Integer);
 
-   function Exn_Long_Long_Long_Integer is new Exponn (Long_Long_Long_Integer);
-   pragma Pure_Function (Exn_Long_Long_Long_Integer);
+   function Exn_Long_Long_Long_Integer
+ (Left : Long_Long_Long_Integer; Right : Natural)
+  return Long_Long_Long_Integer
+ renames Exponn_Integer.Expon;
 
 end System.Exn_LLLI;


diff --git a/gcc/ada/libgnat/s-exponn.adb b/gcc/ada/libgnat/s-exponn.adb
--- a/gcc/ada/libgnat/s-exponn.adb
+++ b/gcc/ada/libgnat/s-exponn.adb
@@ -29,44 +29,198 @@
 --  --
 --
 
-function System.Exponn (Left : Int; Right : Natural) return Int is
+package body System.Exponn
+  with SPARK_Mode
+is
 
-   --  Note that negative exponents get a constraint error because the
-   --  subtype of the Right argument (the exponent) is Natural.
+   --  Preconditions, 

[Ada] Remove redundant code related to instances with formal subprograms

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Cleanup related to expansion of dispatching wrappers for GNATprove,
which just like instantiation involves copying of a specification from
an existing subprogram.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch12.adb (Instantiate_Formal_Subprogram): Remove redundant
call to Set_Defining_Unit_Name; a similar call is done few lines
below.diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -10866,7 +10866,6 @@ package body Sem_Ch12 is
 and then Expander_Active
   then
  New_Subp := Make_Temporary (Sloc (Actual), 'S');
- Set_Defining_Unit_Name (New_Spec, New_Subp);
   else
  New_Subp := Make_Defining_Identifier (Loc, Chars (Formal_Sub));
   end if;




[Ada] Fix sharing of formal parameters between wrapper spec and body

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
When creating wrappers for dispatching functions with controlling
results, we first created the wrapper spec. Then we created a shallow
copy of its specification for the wrapper body using New_Copy_Tree.

However, formal parameters in spec and body must have distinct entities
and New_Copy_Tree doesn't create such distinct copies. For GNAT this
doesn't seem to be a problem; for GNATprove it causes crashes.

A similar routine Make_Null_Procedure_Specs solves this problem by
explicitly injecting new entities into the shallow copy created by
New_Copy_Tree. In Make_Controlling_Function_Wrappers a more elegant
solution is to reuse Copy_Parameter_List.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch3.adb (Make_Controlling_Function_Wrappers): Create
distinct copies of parameter lists for spec and body with
Copy_Parameter_List; cleanup.
(Make_Null_Procedure_Specs): Fix style in comments; remove a
potentially unnecessary initialization of a local variable.diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -9591,19 +9591,41 @@ package body Exp_Ch3 is
   Decl_List : out List_Id;
   Body_List : out List_Id)
is
-  Loc : constant Source_Ptr := Sloc (Tag_Typ);
+  Loc : constant Source_Ptr := Sloc (Tag_Typ);
+
+  function Make_Wrapper_Specification (Subp : Entity_Id) return Node_Id;
+  --  Returns a function specification with the same profile as Subp
+
+  
+  -- Make_Wrapper_Specification --
+  
+
+  function Make_Wrapper_Specification (Subp : Entity_Id) return Node_Id is
+  begin
+ return
+   Make_Function_Specification (Loc,
+ Defining_Unit_Name   =>
+   Make_Defining_Identifier (Loc,
+ Chars => Chars (Subp)),
+ Parameter_Specifications =>
+   Copy_Parameter_List (Subp),
+ Result_Definition=>
+   New_Occurrence_Of (Etype (Subp), Loc));
+  end Make_Wrapper_Specification;
+
   Prim_Elmt   : Elmt_Id;
   Subp: Entity_Id;
   Actual_List : List_Id;
-  Formal_List : List_Id;
   Formal  : Entity_Id;
   Par_Formal  : Entity_Id;
   Formal_Node : Node_Id;
   Func_Body   : Node_Id;
   Func_Decl   : Node_Id;
-  Func_Spec   : Node_Id;
+  Func_Id : Entity_Id;
   Return_Stmt : Node_Id;
 
+   --  Start of processing for Make_Controlling_Function_Wrappers
+
begin
   Decl_List := New_List;
   Body_List := New_List;
@@ -9674,43 +9696,10 @@ package body Exp_Ch3 is
end;
 end if;
 
-Formal_List := No_List;
-Formal := First_Formal (Subp);
-
-if Present (Formal) then
-   Formal_List := New_List;
-
-   while Present (Formal) loop
-  Append
-(Make_Parameter_Specification
-   (Loc,
-Defining_Identifier =>
-  Make_Defining_Identifier (Sloc (Formal),
-Chars => Chars (Formal)),
-In_Present  => In_Present (Parent (Formal)),
-Out_Present => Out_Present (Parent (Formal)),
-Null_Exclusion_Present =>
-  Null_Exclusion_Present (Parent (Formal)),
-Parameter_Type =>
-  New_Occurrence_Of (Etype (Formal), Loc),
-Expression =>
-  New_Copy_Tree (Expression (Parent (Formal,
- Formal_List);
-
-  Next_Formal (Formal);
-   end loop;
-end if;
-
-Func_Spec :=
-  Make_Function_Specification (Loc,
-Defining_Unit_Name   =>
-  Make_Defining_Identifier (Loc,
-Chars => Chars (Subp)),
-Parameter_Specifications => Formal_List,
-Result_Definition=>
-  New_Occurrence_Of (Etype (Subp), Loc));
+Func_Decl :=
+  Make_Subprogram_Declaration (Loc,
+Specification => Make_Wrapper_Specification (Subp));
 
-Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
 Append_To (Decl_List, Func_Decl);
 
 --  Build a wrapper body that calls the parent function. The body
@@ -9723,34 +9712,35 @@ package body Exp_Ch3 is
 
 Formal  := First_Formal (Subp);
 Par_Formal  := First_Formal (Alias (Subp));
-Formal_Node := First (Formal_List);
+Formal_Node :=
+  First (Parameter_Specifications (Specification (Func_Decl)));
 
 if Present (Formal) then
Actual_List := New_List;
-else
-  

[Ada] Renamed_Entity should return Entity_Id

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
This patch is minor cleanup. The Renamed_Entity and Alias synthesized
attributes are of type Entity_Id.  No change in behavior.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* einfo-utils.ads, einfo-utils.adb (Renamed_Entity Alias):
Change Node_Id to Entity_Id.diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -47,16 +47,16 @@ package body Einfo.Utils is
-- Aliases/Renamings of Renamed_Or_Alias --
---
 
-   function Alias (N : Entity_Id) return Node_Id is
+   function Alias (N : Entity_Id) return Entity_Id is
begin
-  return Val : constant Node_Id := Renamed_Or_Alias (N) do
+  return Val : constant Entity_Id := Renamed_Or_Alias (N) do
  pragma Assert
(Is_Overloadable (N) or else Ekind (N) = E_Subprogram_Type);
  pragma Assert (Val in N_Entity_Id | N_Empty_Id);
   end return;
end Alias;
 
-   procedure Set_Alias (N : Entity_Id; Val : Node_Id) is
+   procedure Set_Alias (N : Entity_Id; Val : Entity_Id) is
begin
   pragma Assert
 (Is_Overloadable (N) or else Ekind (N) = E_Subprogram_Type);
@@ -65,15 +65,15 @@ package body Einfo.Utils is
   Set_Renamed_Or_Alias (N, Val);
end Set_Alias;
 
-   function Renamed_Entity (N : Entity_Id) return Node_Id is
+   function Renamed_Entity (N : Entity_Id) return Entity_Id is
begin
-  return Val : constant Node_Id := Renamed_Or_Alias (N) do
+  return Val : constant Entity_Id := Renamed_Or_Alias (N) do
  pragma Assert (not Is_Object (N) or else Etype (N) = Any_Type);
  pragma Assert (Val in N_Entity_Id | N_Empty_Id);
   end return;
end Renamed_Entity;
 
-   procedure Set_Renamed_Entity (N : Entity_Id; Val : Node_Id) is
+   procedure Set_Renamed_Entity (N : Entity_Id; Val : Entity_Id) is
begin
   pragma Assert (not Is_Object (N));
   pragma Assert (Val in N_Entity_Id);


diff --git a/gcc/ada/einfo-utils.ads b/gcc/ada/einfo-utils.ads
--- a/gcc/ada/einfo-utils.ads
+++ b/gcc/ada/einfo-utils.ads
@@ -42,10 +42,10 @@ package Einfo.Utils is
--  expressions, but those use different mechanisms; the fields here are not
--  used.
 
-   function Alias (N : Entity_Id) return Node_Id;
-   procedure Set_Alias (N : Entity_Id; Val : Node_Id);
-   function Renamed_Entity (N : Entity_Id) return Node_Id;
-   procedure Set_Renamed_Entity (N : Entity_Id; Val : Node_Id);
+   function Alias (N : Entity_Id) return Entity_Id;
+   procedure Set_Alias (N : Entity_Id; Val : Entity_Id);
+   function Renamed_Entity (N : Entity_Id) return Entity_Id;
+   procedure Set_Renamed_Entity (N : Entity_Id; Val : Entity_Id);
function Renamed_Object (N : Entity_Id) return Node_Id;
procedure Set_Renamed_Object (N : Entity_Id; Val : Node_Id);
 




[Ada] Deconstruct dead wrappers added for external axiomatization

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Support for external axiomatization in GNATprove has been deconstructed
few years ago, so the related frontend code can be deconstructed too.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch12.ads (Build_Function_Wrapper, Build_Operator_Wrapper):
Remove unreferenced spec.
* sem_ch12.adb (Build_Function_Wrapper, Build_Operator_Wrapper):
Remove dead bodies.diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -6080,211 +6080,6 @@ package body Sem_Ch12 is
   end if;
end Get_Associated_Node;
 
-   
-   -- Build_Function_Wrapper --
-   
-
-   function Build_Function_Wrapper
- (Formal_Subp : Entity_Id;
-  Actual_Subp : Entity_Id) return Node_Id
-   is
-  Loc   : constant Source_Ptr := Sloc (Current_Scope);
-  Ret_Type  : constant Entity_Id  := Get_Instance_Of (Etype (Formal_Subp));
-  Actuals   : List_Id;
-  Decl  : Node_Id;
-  Func_Name : Node_Id;
-  Func  : Entity_Id;
-  Parm_Type : Node_Id;
-  Profile   : List_Id := New_List;
-  Spec  : Node_Id;
-  Act_F : Entity_Id;
-  Form_F: Entity_Id;
-  New_F : Entity_Id;
-
-   begin
-  Func_Name := New_Occurrence_Of (Actual_Subp, Loc);
-
-  Func := Make_Defining_Identifier (Loc, Chars (Formal_Subp));
-  Mutate_Ekind (Func, E_Function);
-  Set_Is_Generic_Actual_Subprogram (Func);
-
-  Actuals := New_List;
-  Profile := New_List;
-
-  Act_F  := First_Formal (Actual_Subp);
-  Form_F := First_Formal (Formal_Subp);
-  while Present (Form_F) loop
-
- --  Create new formal for profile of wrapper, and add a reference
- --  to it in the list of actuals for the enclosing call. The name
- --  must be that of the formal in the formal subprogram, because
- --  calls to it in the generic body may use named associations.
-
- New_F := Make_Defining_Identifier (Loc, Chars (Form_F));
-
- Parm_Type :=
-   New_Occurrence_Of (Get_Instance_Of (Etype (Form_F)), Loc);
-
- Append_To (Profile,
-   Make_Parameter_Specification (Loc,
- Defining_Identifier => New_F,
- Parameter_Type  => Parm_Type));
-
- Append_To (Actuals, New_Occurrence_Of (New_F, Loc));
- Next_Formal (Form_F);
-
- if Present (Act_F) then
-Next_Formal (Act_F);
- end if;
-  end loop;
-
-  Spec :=
-Make_Function_Specification (Loc,
-  Defining_Unit_Name   => Func,
-  Parameter_Specifications => Profile,
-  Result_Definition=> New_Occurrence_Of (Ret_Type, Loc));
-
-  Decl :=
-Make_Expression_Function (Loc,
-  Specification => Spec,
-  Expression=>
-Make_Function_Call (Loc,
-  Name   => Func_Name,
-  Parameter_Associations => Actuals));
-
-  return Decl;
-   end Build_Function_Wrapper;
-
-   
-   -- Build_Operator_Wrapper --
-   
-
-   function Build_Operator_Wrapper
- (Formal_Subp : Entity_Id;
-  Actual_Subp : Entity_Id) return Node_Id
-   is
-  Loc   : constant Source_Ptr := Sloc (Current_Scope);
-  Ret_Type  : constant Entity_Id  :=
-Get_Instance_Of (Etype (Formal_Subp));
-  Op_Type   : constant Entity_Id  :=
-Get_Instance_Of (Etype (First_Formal (Formal_Subp)));
-  Is_Binary : constant Boolean:=
-Present (Next_Formal (First_Formal (Formal_Subp)));
-
-  Decl: Node_Id;
-  Expr: Node_Id := Empty;
-  F1, F2  : Entity_Id;
-  Func: Entity_Id;
-  Op_Name : Name_Id;
-  Spec: Node_Id;
-  L, R: Node_Id;
-
-   begin
-  Op_Name := Chars (Actual_Subp);
-
-  --  Create entities for wrapper function and its formals
-
-  F1 := Make_Temporary (Loc, 'A');
-  F2 := Make_Temporary (Loc, 'B');
-  L  := New_Occurrence_Of (F1, Loc);
-  R  := New_Occurrence_Of (F2, Loc);
-
-  Func := Make_Defining_Identifier (Loc, Chars (Formal_Subp));
-  Mutate_Ekind (Func, E_Function);
-  Set_Is_Generic_Actual_Subprogram (Func);
-
-  Spec :=
-Make_Function_Specification (Loc,
-  Defining_Unit_Name   => Func,
-  Parameter_Specifications => New_List (
-Make_Parameter_Specification (Loc,
-   Defining_Identifier => F1,
-   Parameter_Type  => New_Occurrence_Of (Op_Type, Loc))),
-  Result_Definition=> New_Occurrence_Of (Ret_Type, Loc));
-
-  if Is_Binary then
- Append_To (Parameter_Specifications (Spec),
-Make_Parameter_Specification (Loc,
-  Defining_Identifier => F2,
-  Parameter_Type  => New_Occurrence_Of (Op_Type, Loc)));
-  end 

[Ada] Rename parameter-dependent constants in generic unit

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Constant names of Big2xx32, Big2xx63 and Big2xx64 were misleading, as
SIngle_Size and Double_Size need not be 32 and 64. Replace by names that
don't refer to an explicit size.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-aridou.adb: Apply replacement.

patch.diff.gz
Description: application/gzip


[Ada] Remove Compiler_Unit[_Warning] pragmas

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
Updated base requirement on GNAT version and the fact that stage1 of the
bootstrap now uses the base compiler's libgnat allows for more Ada
features in the runtime and makes these pragma obsolete.

Added comments in files that are still built during stage1 and that need
to be modified with care now that there is no pragma to prevent
incorrect modification.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst (Compiler_Unit)
(Compiler_Unit_Warning): Remove.
* gnat-style.texi, gnat_rm.texi, gnat_ugn.texi: Regenerate.
* libgnat/g-dynhta.ads: Add comment indicating this unit is
built during stage1.
* libgnat/g-dyntab.ads: Likewise.
* libgnat/g-graphs.ads: Likewise.
* libgnat/g-lists.ads: Likewise.
* libgnat/g-sets.ads: Likewise.
* libgnat/gnat.ads: Likewise.
* libgnat/s-pehage.ads: Likewise.
* libgnat/s-resfil.ads: Likewise.
* libgnat/s-rident.ads: Likewise.
* libgnat/s-utf_32.ads: Likewise.
* errout.ads: Update comment.
* opt.ads (Opt): Remove Compiler_Unit.
* par-ch5.adb (All_Pragmas): Remove call to Check_Compiler_Unit.
* sem_prag.adb (Analyze_Pragma): Likewise.
* sem_ch4.adb (Non_Static_Choice_Error, Analyze_If_Expression)
(Analyze_Set_Membership, Record_Interp): Likewise.
* sem_ch11.adb (Analyze_Raise_Expression): Likewise.
* sem_ch6.adb: Remove Restric package reference.
(Analyze_Extended_Return_Statement): Remove call to
Check_Compiler_Unit.
* par-prag.adb (Process_Restrictions_Or_Restriction_Warnings):
Remove handling of Pragma_Compiler_Unit[_Warning}.
* restrict.adb (Check_Compiler_Unit): Remove both.
* restrict.ads: Likewise.
* snames.ads-tmpl (Pragma_Id): Remove
Pragma_Compiler_Unit[_Warning].
* libgnat/a-assert.ads: Remove pragma Compiler_Unit_Warning.
* libgnat/a-chlat1.ads: Likewise.
* libgnat/a-elchha.adb: Likewise.
* libgnat/a-elchha.ads: Likewise.
* libgnat/a-ioexce.ads: Likewise.
* libgnat/a-strhas.ads: Likewise.
* libgnat/g-byorma.adb: Likewise.
* libgnat/g-byorma.ads: Likewise.
* libgnat/g-dyntab.adb: Likewise.
* libgnat/g-heasor.ads: Likewise.
* libgnat/g-hesora.adb: Likewise.
* libgnat/g-hesora.ads: Likewise.
* libgnat/g-htable.adb: Likewise.
* libgnat/g-htable.ads: Likewise.
* libgnat/g-spchge.adb: Likewise.
* libgnat/g-spchge.ads: Likewise.
* libgnat/g-speche.adb: Likewise.
* libgnat/g-speche.ads: Likewise.
* libgnat/g-table.ads: Likewise.
* libgnat/g-u3spch.adb: Likewise.
* libgnat/g-u3spch.ads: Likewise.
* libgnat/interfac.ads: Likewise.
* libgnat/s-addope.adb: Likewise.
* libgnat/s-addope.ads: Likewise.
* libgnat/s-assert.adb: Likewise.
* libgnat/s-assert.ads: Likewise.
* libgnat/s-bitops.adb: Likewise.
* libgnat/s-bitops.ads: Likewise.
* libgnat/s-carun8.adb: Likewise.
* libgnat/s-carun8.ads: Likewise.
* libgnat/s-casuti.adb: Likewise.
* libgnat/s-casuti.ads: Likewise.
* libgnat/s-conca2.adb: Likewise.
* libgnat/s-conca2.ads: Likewise.
* libgnat/s-conca3.adb: Likewise.
* libgnat/s-conca3.ads: Likewise.
* libgnat/s-conca4.adb: Likewise.
* libgnat/s-conca4.ads: Likewise.
* libgnat/s-conca5.adb: Likewise.
* libgnat/s-conca5.ads: Likewise.
* libgnat/s-conca6.adb: Likewise.
* libgnat/s-conca6.ads: Likewise.
* libgnat/s-conca7.adb: Likewise.
* libgnat/s-conca7.ads: Likewise.
* libgnat/s-conca8.adb: Likewise.
* libgnat/s-conca8.ads: Likewise.
* libgnat/s-conca9.adb: Likewise.
* libgnat/s-conca9.ads: Likewise.
* libgnat/s-crc32.adb: Likewise.
* libgnat/s-crc32.ads: Likewise.
* libgnat/s-crtl.ads: Likewise.
* libgnat/s-excdeb.adb: Likewise.
* libgnat/s-excdeb.ads: Likewise.
* libgnat/s-except.ads: Likewise.
* libgnat/s-exctab.adb: Likewise.
* libgnat/s-exctab.ads: Likewise.
* libgnat/s-finmas.ads: Likewise.
* libgnat/s-htable.adb: Likewise.
* libgnat/s-htable.ads: Likewise.
* libgnat/s-mastop.adb: Likewise.
* libgnat/s-mastop.ads: Likewise.
* libgnat/s-memory.adb: Likewise.
* libgnat/s-memory.ads: Likewise.
* libgnat/s-os_lib.ads: Likewise.
* libgnat/s-parame.adb: Likewise.
* libgnat/s-parame.ads: Likewise.
* libgnat/s-parame__posix2008.ads: Likewise.
* libgnat/s-purexc.ads: Likewise.
* libgnat/s-resfil.adb: Likewise.
* libgnat/s-restri.adb: Likewise.
* libgnat/s-restri.ads: Likewise.
* libgnat/s-secsta.adb: Likewise.
* 

[Ada] Fix lemma in generic unit System.Arith_Double

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
This system unit is instanciated with values of Single_Size either 32
or 64 currently. A lemma was only valid for value of 32, which became
visible when proving the instance with value of 64.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-aridou.adb (Lemma_Word_Commutation): Fix for
instances with other values of Single_Size.diff --git a/gcc/ada/libgnat/s-aridou.adb b/gcc/ada/libgnat/s-aridou.adb
--- a/gcc/ada/libgnat/s-aridou.adb
+++ b/gcc/ada/libgnat/s-aridou.adb
@@ -541,7 +541,8 @@ is
procedure Lemma_Word_Commutation (X : Single_Uns)
with
  Ghost,
- Post => Big_2xx32 * Big (Double_Uns (X)) = Big (2**32 * Double_Uns (X));
+ Post => Big_2xx32 * Big (Double_Uns (X))
+   = Big (2**Single_Size * Double_Uns (X));
 
-
-- Local lemma null bodies --




[Ada] Reduce runtime dependencies on stage1

2022-01-05 Thread Pierre-Marie de Rodat via Gcc-patches
To simplify the bootstrap constraints, duplicate a few definitions in
order to remove dependencies on a recent version of System.Case_Util,
System.Crtl, System.OS_Lib.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* osint.adb (File_Names_Equal): Declare To_Lower locally.
* osint.ads (Null_FD): New.
* fmap.adb, sinput-l.adb, targparm.adb: Adapt to changes above.
* switch-b.adb (Scan_Debug_Switches): Use Is_Regular_File to
simplify the bootstrap dependencies.diff --git a/gcc/ada/fmap.adb b/gcc/ada/fmap.adb
--- a/gcc/ada/fmap.adb
+++ b/gcc/ada/fmap.adb
@@ -301,7 +301,7 @@ package body Fmap is
   Read_Source_File (Name_Enter (File_Name), 1, Hi, Src, FD, Config);
 
   if Null_Source_Buffer_Ptr (Src) then
- if FD = Null_FD then
+ if FD = Osint.Null_FD then
 Write_Str ("warning: could not locate mapping file """);
  else
 Write_Str ("warning: no read access for mapping file """);


diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb
--- a/gcc/ada/osint.adb
+++ b/gcc/ada/osint.adb
@@ -1059,6 +1059,21 @@ package body Osint is
--
 
function File_Names_Equal (File1, File2 : String) return Boolean is
+
+  function To_Lower (A : String) return String;
+  --  For bootstrap reasons, we cannot use To_Lower from System.Case_Util
+
+  --
+  -- To_Lower --
+  --
+
+  function To_Lower (A : String) return String is
+ Result : String := A;
+  begin
+ To_Lower (Result);
+ return Result;
+  end To_Lower;
+
begin
   if File_Names_Case_Sensitive then
  return File1 = File2;


diff --git a/gcc/ada/osint.ads b/gcc/ada/osint.ads
--- a/gcc/ada/osint.ads
+++ b/gcc/ada/osint.ads
@@ -52,6 +52,10 @@ package Osint is
Project_Include_Path_File : constant String := "ADA_PRJ_INCLUDE_FILE";
Project_Objects_Path_File : constant String := "ADA_PRJ_OBJECTS_FILE";
 
+   Null_FD : constant File_Descriptor := -2;
+   --  Uninitialized file descriptor. Copied from System.OS_Lib for bootstrap
+   --  reasons.
+
Output_FD : File_Descriptor;
--  File descriptor for current library info, list, tree, C, H, or binder
--  output. Only one of these is open at a time, so we need only one FD.


diff --git a/gcc/ada/sinput-l.adb b/gcc/ada/sinput-l.adb
--- a/gcc/ada/sinput-l.adb
+++ b/gcc/ada/sinput-l.adb
@@ -420,7 +420,7 @@ package body Sinput.L is
   if Null_Source_Buffer_Ptr (Src) then
  Source_File.Decrement_Last;
 
- if FD = Null_FD then
+ if FD = Osint.Null_FD then
 return No_Source_File;
  else
 return No_Access_To_Source_File;


diff --git a/gcc/ada/switch-b.adb b/gcc/ada/switch-b.adb
--- a/gcc/ada/switch-b.adb
+++ b/gcc/ada/switch-b.adb
@@ -312,7 +312,7 @@ package body Switch.B is
 
 Ptr := Max + 1;
 
-if not Is_Read_Accessible_File (Force_Elab_Order_File.all) then
+if not Is_Regular_File (Force_Elab_Order_File.all) then
Osint.Fail (Force_Elab_Order_File.all & ": file not found");
 end if;
 


diff --git a/gcc/ada/targparm.adb b/gcc/ada/targparm.adb
--- a/gcc/ada/targparm.adb
+++ b/gcc/ada/targparm.adb
@@ -165,7 +165,7 @@ package body Targparm is
   if Null_Source_Buffer_Ptr (Text) then
  Write_Line ("fatal error, run-time library not installed correctly");
 
- if FD = Null_FD then
+ if FD = Osint.Null_FD then
 Write_Line ("cannot locate file system.ads");
  else
 Write_Line ("no read access for file system.ads");




Re: [PATCH] libgomp, OpenMP, nvptx: Low-latency memory allocator

2022-01-05 Thread Tom de Vries via Gcc-patches

On 12/20/21 16:58, Andrew Stubbs wrote:
This patch is submitted now for review and so I can commit a backport it 
to the OG11 branch, but isn't suitable for mainline until stage 1.


The patch implements support for omp_low_lat_mem_space and 
omp_low_lat_mem_alloc on NVPTX offload devices. The omp_pteam_mem_alloc, 
omp_cgroup_mem_alloc and omp_thread_mem_alloc allocators are also 
configured to use this space (this to match the current or intended 
behaviour in other toolchains).


The memory is drawn from the ".shared" space that is accessible only 
from within the team in which it is allocated, and which effectively 
ceases to exist when the kernel exits.  By default, 8 KiB of space is 
reserved for each team at launch time. This can be adjusted, at runtime, 
via a new environment variable "GOMP_NVPTX_LOWLAT_POOL". Reserving a 
larger amount may limit the number of teams that can be run in parallel 
(due to hardware limitations). Conversely, reducing the allocation may 
increase the number of teams that can be run in parallel. (I have not 
yet attempted to tune the default too precisely.) The actual maximum 
size will vary according to the available hardware and the number of 
variables that the compiler has placed in .shared space.


The allocator implementation is designed to add no extra space-overhead 
than omp_alloc already does (aside from rounding allocations up to a 
multiple of 8 bytes), thus the internal free and realloc must be told 
how big the original allocation was. The free algorithm maintains an 
in-order linked-list of free memory chunks. Memory is allocated on a 
first-fit basis.


If the allocation fails the NVPTX allocator returns NULL and omp_alloc 
handles the fall-back. Now that this is a thing that is likely to happen 
(low-latency memory is small) this patch also implements appropriate 
fall-back modes for the predefined allocators (fall-back for custom 
allocators already worked).


In order to support the %dynamic_smem_size PTX feature is is necessary 
to bump the minimum supported PTX version from 3.1 (~2013) to 4.1 (~2014).


I applied the patch (but used the libgomp/configure.tgt patch to force 
-mptx=4.1, rather than changing the default).


I ran into the following (using export GOMP_NVPTX_JIT=-O0 to work around 
known driver problems), and observed these extra FAILs:

...
FAIL: libgomp.c/../libgomp.c-c++-common/alloc-7.c execution test
FAIL: libgomp.c/../libgomp.c-c++-common/alloc-8.c execution test
FAIL: libgomp.c/allocators-1.c (test for excess errors)
FAIL: libgomp.c/allocators-2.c (test for excess errors)
FAIL: libgomp.c/allocators-3.c (test for excess errors)
FAIL: libgomp.c/allocators-4.c (test for excess errors)
FAIL: libgomp.c/allocators-5.c (test for excess errors)
FAIL: libgomp.c/allocators-6.c (test for excess errors)
FAIL: libgomp.c++/../libgomp.c-c++-common/alloc-7.c execution test
FAIL: libgomp.c++/../libgomp.c-c++-common/alloc-8.c execution test
FAIL: libgomp.fortran/alloc-10.f90   -O  execution test
FAIL: libgomp.fortran/alloc-9.f90   -O  execution test
...

The allocators-1.c test-case doesn't compile because:
...
FAIL: libgomp.c/allocators-1.c (test for excess errors)
Excess errors:
/home/vries/oacc/trunk/source-gcc/libgomp/testsuite/libgomp.c/allocators-1.c:7:22: 
sorry, unimplemented: '	' clause on 'requires' directive not supported yet


UNRESOLVED: libgomp.c/allocators-1.c compilation failed to produce 
executable

...

So, I suppose I need "[PATCH] OpenMP front-end: allow requires 
dynamic_allocators" as well, I'll try again with that applied.


The alloc-7.c execution test failure is a regression, AFAICT.  It fails 
here:

...
38if uintptr_t) p) % __alignof (int)) != 0 || p[0] || p[1] 
|| p[2])

39  abort ();
...
because:
...
(gdb) p p[0]
$2 = 772014104
(gdb) p p[1]
$3 = 0
(gdb) p p[2]
$4 = 9
...

In other words, the pointer returned by omp_calloc does not point to 
zeroed out memory.


Thanks,
- Tom


[PATCH] LTO plugin: modernize a bit.

2022-01-05 Thread Martin Liška

The patch is about small refactoring of the plugin.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

include/ChangeLog:

* plugin-api.h (enum ld_plugin_tag): Do not set implicit enum
values.

lto-plugin/ChangeLog:

* lto-plugin.c (struct plugin_objfile): Use bool for offset
field.
(exec_lto_wrapper): Assign true/false to bool variables.
(process_offload_section): Likewise.
(claim_file_handler): Likewise.
(onload): Likewise.
---
 include/plugin-api.h| 68 -
 lto-plugin/lto-plugin.c | 19 ++--
 2 files changed, 44 insertions(+), 43 deletions(-)

diff --git a/include/plugin-api.h b/include/plugin-api.h
index 4e12c0320d6..8aebe2ff267 100644
--- a/include/plugin-api.h
+++ b/include/plugin-api.h
@@ -487,40 +487,40 @@ enum ld_plugin_level
 
 enum ld_plugin_tag

 {
-  LDPT_NULL = 0,
-  LDPT_API_VERSION = 1,
-  LDPT_GOLD_VERSION = 2,
-  LDPT_LINKER_OUTPUT = 3,
-  LDPT_OPTION = 4,
-  LDPT_REGISTER_CLAIM_FILE_HOOK = 5,
-  LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK = 6,
-  LDPT_REGISTER_CLEANUP_HOOK = 7,
-  LDPT_ADD_SYMBOLS = 8,
-  LDPT_GET_SYMBOLS = 9,
-  LDPT_ADD_INPUT_FILE = 10,
-  LDPT_MESSAGE = 11,
-  LDPT_GET_INPUT_FILE = 12,
-  LDPT_RELEASE_INPUT_FILE = 13,
-  LDPT_ADD_INPUT_LIBRARY = 14,
-  LDPT_OUTPUT_NAME = 15,
-  LDPT_SET_EXTRA_LIBRARY_PATH = 16,
-  LDPT_GNU_LD_VERSION = 17,
-  LDPT_GET_VIEW = 18,
-  LDPT_GET_INPUT_SECTION_COUNT = 19,
-  LDPT_GET_INPUT_SECTION_TYPE = 20,
-  LDPT_GET_INPUT_SECTION_NAME = 21,
-  LDPT_GET_INPUT_SECTION_CONTENTS = 22,
-  LDPT_UPDATE_SECTION_ORDER = 23,
-  LDPT_ALLOW_SECTION_ORDERING = 24,
-  LDPT_GET_SYMBOLS_V2 = 25,
-  LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS = 26,
-  LDPT_UNIQUE_SEGMENT_FOR_SECTIONS = 27,
-  LDPT_GET_SYMBOLS_V3 = 28,
-  LDPT_GET_INPUT_SECTION_ALIGNMENT = 29,
-  LDPT_GET_INPUT_SECTION_SIZE = 30,
-  LDPT_REGISTER_NEW_INPUT_HOOK = 31,
-  LDPT_GET_WRAP_SYMBOLS = 32,
-  LDPT_ADD_SYMBOLS_V2 = 33
+  LDPT_NULL,
+  LDPT_API_VERSION,
+  LDPT_GOLD_VERSION,
+  LDPT_LINKER_OUTPUT,
+  LDPT_OPTION,
+  LDPT_REGISTER_CLAIM_FILE_HOOK,
+  LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK,
+  LDPT_REGISTER_CLEANUP_HOOK,
+  LDPT_ADD_SYMBOLS,
+  LDPT_GET_SYMBOLS,
+  LDPT_ADD_INPUT_FILE,
+  LDPT_MESSAGE,
+  LDPT_GET_INPUT_FILE,
+  LDPT_RELEASE_INPUT_FILE,
+  LDPT_ADD_INPUT_LIBRARY,
+  LDPT_OUTPUT_NAME,
+  LDPT_SET_EXTRA_LIBRARY_PATH,
+  LDPT_GNU_LD_VERSION,
+  LDPT_GET_VIEW,
+  LDPT_GET_INPUT_SECTION_COUNT,
+  LDPT_GET_INPUT_SECTION_TYPE,
+  LDPT_GET_INPUT_SECTION_NAME,
+  LDPT_GET_INPUT_SECTION_CONTENTS,
+  LDPT_UPDATE_SECTION_ORDER,
+  LDPT_ALLOW_SECTION_ORDERING,
+  LDPT_GET_SYMBOLS_V2,
+  LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS,
+  LDPT_UNIQUE_SEGMENT_FOR_SECTIONS,
+  LDPT_GET_SYMBOLS_V3,
+  LDPT_GET_INPUT_SECTION_ALIGNMENT,
+  LDPT_GET_INPUT_SECTION_SIZE,
+  LDPT_REGISTER_NEW_INPUT_HOOK,
+  LDPT_GET_WRAP_SYMBOLS,
+  LDPT_ADD_SYMBOLS_V2,
 };
 
 /* The plugin transfer vector.  */

diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index c9c048d3631..0147b1b9667 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -122,7 +122,7 @@ struct plugin_symtab
 struct plugin_objfile
 {
   int found;
-  int offload;
+  bool offload;
   simple_object_read *objfile;
   struct plugin_symtab *out;
   const struct ld_plugin_input_file *file;
@@ -205,7 +205,7 @@ static const char *link_output_name = NULL;
 
 /* This indicates link_output_name already contains the dot of the

suffix, so we can skip it in extensions.  */
-static int skip_in_suffix = 0;
+static bool skip_in_suffix = false;
 
 /* The version of gold being used, or -1 if not gold.  The number is

MAJOR * 100 + MINOR.  */
@@ -636,7 +636,8 @@ exec_lto_wrapper (char *argv[])
   /* Write argv to a file to avoid a command line that is too long
  Save the file locally on save-temps.  */
   const char *suffix = ".lto_wrapper_args";
-  suffix += skip_in_suffix;
+  if (skip_in_suffix)
+suffix++;
   if (save_temps && link_output_name)
 arguments_file_name = concat (link_output_name, suffix, NULL);
   else
@@ -1132,7 +1133,7 @@ process_offload_section (void *data, const char *name, 
off_t offset, off_t len)
   if (startswith (name, ".gnu.offload_lto_.opts"))
 {
   struct plugin_objfile *obj = (struct plugin_objfile *) data;
-  obj->offload = 1;
+  obj->offload = true;
   return 0;
 }
 
@@ -1175,7 +1176,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)

   *claimed = 0;
   obj.file = file;
   obj.found = 0;
-  obj.offload = 0;
+  obj.offload = false;
   obj.out = _file.symtab;
   errmsg = NULL;
   obj.objfile = simple_object_start_read (file->fd, file->offset, 
LTO_SEGMENT_NAME,
@@ -1213,7 +1214,7 @@ claim_file_handler (const struct ld_plugin_input_file 
*file, int *claimed)
 simple_object_find_sections (obj.objfile, process_offload_section,
 , );
 
-  if 

[PATCH] tree-optimization/103816 - detect offset overflow in SLP group analysis

2022-01-05 Thread Richard Biener via Gcc-patches
This makes sure to detect overflow when computing DR_GROUP_GAP
and DR_GROUP_SIZE more thoroughly so artificial testcases like the
added one are not fooling the existing check.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2022-01-05  Richard Biener  

PR tree-optimization/103816
* tree-vect-data-refs.c (vect_analyze_group_access_1): Also
check DR_GROUP_GAP compute for overflow and representability.

* gcc.dg/torture/pr103816.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr103816.c | 10 ++
 gcc/tree-vect-data-refs.c   | 15 ++-
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr103816.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr103816.c 
b/gcc/testsuite/gcc.dg/torture/pr103816.c
new file mode 100644
index 000..769036a1af8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr103816.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-w" } */
+
+extern struct {
+  unsigned char a;
+  unsigned char b;
+  unsigned char c;
+  unsigned char d;
+} g[];
+void main() { g[0].b = (g[0].b & g[4].b) * g[2305843009213693952ULL].c; }
diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index 2b3ec6289de..dd20ed974af 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -2721,7 +2721,20 @@ vect_analyze_group_access_1 (vec_info *vinfo, 
dr_vec_info *dr_info)
   /* Check that the distance between two accesses is equal to the type
  size. Otherwise, we have gaps.  */
   diff = (TREE_INT_CST_LOW (DR_INIT (data_ref))
-  - TREE_INT_CST_LOW (prev_init)) / type_size;
+ - TREE_INT_CST_LOW (prev_init)) / type_size;
+ if (diff < 1 || diff > UINT_MAX)
+   {
+ /* For artificial testcases with array accesses with large
+constant indices we can run into overflow issues which
+can end up fooling the groupsize constraint below so
+check the individual gaps (which are represented as
+unsigned int) as well.  */
+ if (dump_enabled_p ())
+   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+"interleaved access with gap larger "
+"than representable\n");
+ return false;
+   }
  if (diff != 1)
{
  /* FORNOW: SLP of accesses with gaps is not supported.  */
-- 
2.31.1


Re: [Patch][V2]Enable -Wuninitialized + -ftrivial-auto-var-init for address taken variables

2022-01-05 Thread Richard Biener via Gcc-patches
On Thu, Dec 16, 2021 at 5:00 PM Qing Zhao  wrote:
>
> Hi,
>
> This is the 2nd version of the patch.
> The original patch is at:
>
> https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586341.html
>
> In addition to resolve the two issues mentioned in the original patch,
> This patch also can be used as a very good workaround for the issue in 
> PR103720
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103720
>
> And as I checked, the patch can fix all the bogus uninitialized warnings when
> building kernel with -O2 + -ftrivial-auto-var-init=zero + -Wuninitialized.
>
> So, this is a very important patch that need to be included into gcc12.
>
> Compared to the 1st patch, the major changes are to resolve Martin’s comments 
> on
> tree-ssa-uninit.c
>
> 1.  Add some meaningful temporaries to break the long expression to make it
>  Readable. And also add comments to explain the purpose of the statement;
>
> 2.  Resolve the memory leakage of the dynamically created string.
>
> The patch has been bootstrapped and regressing tested on both x86 and 
> aarch64, no issues.
> Okay for commit?

  tree decl_name
+= build_string_literal (IDENTIFIER_LENGTH (DECL_NAME (decl)) + 1,
+   IDENTIFIER_POINTER (DECL_NAME (decl)));

you need to deal with DECL_NAME being NULL.  It's also a bit awkward
to build another
copy of all decl names :/  The changes in the uninit warning are also
quite ugly, refactoring
things to always pass down a name / location pair might improve that
(but I'd like to
understand the case to fix first).

+ /* The LHS of the call is a temporary variable, we use it as a
+placeholder to record the information on whether the warning
+has been issued or not.  */
+ repl_var = gimple_call_lhs (def_stmt);

this seems to be a change that can be done independently?

+ /* Ignore the call to .DEFERRED_INIT that define the original
+var itself.  */
+ if (is_gimple_assign (context))
+   {
+ if (TREE_CODE (gimple_assign_lhs (context)) == VAR_DECL)
+   lhs_var = gimple_assign_lhs (context);
+ else if (TREE_CODE (gimple_assign_lhs (context)) == SSA_NAME)
+   lhs_var = SSA_NAME_VAR (gimple_assign_lhs (context));
+   }
+ if (lhs_var
+ && (lhs_var_name = DECL_NAME (lhs_var))
+ && (lhs_var_name_str = IDENTIFIER_POINTER (lhs_var_name))
+ && (strcmp (lhs_var_name_str, var_name_str) == 0))
+   return;

likewise but I don't really understand what you are doing here.  I'm
also not sure
I understand the case we try to fix with passing the name - is that
for VLA decls
that get replaced by allocation?

The patch adjusts testcases but doesn't add new ones but each of the
above changes
would warrant one and make it easier to understand the motivation of
the changes.

Richard.

> thanks.
>
> Qing
>
> =
>
> **Compared to the 1st version, the code change is:
>
>  --- a/gcc/tree-ssa-uninit.c
>  +++ b/gcc/tree-ssa-uninit.c
>  @@ -182,9 +182,22 @@ warn_uninit (opt_code opt, tree t, tree var, const char 
> *gmsgid,
> @@ -798,26 +798,35 @@
> if (!var && !SSA_NAME_VAR (t))
>   {
> gimple *def_stmt = SSA_NAME_DEF_STMT (t);
> -@@ -197,9 +210,34 @@ warn_uninit (opt_code opt, tree t, tree var, const char 
> *gmsgid,
> +@@ -197,9 +210,43 @@ warn_uninit (opt_code opt, tree t, tree var, const char 
> *gmsgid,
>&& zerop (gimple_assign_rhs2 (def_stmt)))
>  var = SSA_NAME_VAR (v);
>  }
>  +
>  +  if (gimple_call_internal_p (def_stmt, IFN_DEFERRED_INIT))
>  +   {
> ++tree lhs_var = NULL_TREE;
> ++tree lhs_var_name = NULL_TREE;
> ++const char *lhs_var_name_str = NULL;
>  + /* Get the variable name from the 3rd argument of call.  */
>  + var_name = gimple_call_arg (def_stmt, 2);
>  + var_name = TREE_OPERAND (TREE_OPERAND (var_name, 0), 0);
>  + var_name_str = TREE_STRING_POINTER (var_name);
>  +
> -+if (is_gimple_assign (context)
> -+&& TREE_CODE (gimple_assign_lhs (context)) == VAR_DECL
> -+&& DECL_NAME (gimple_assign_lhs (context))
> -+&& IDENTIFIER_POINTER (DECL_NAME (gimple_assign_lhs (context
> -+  if (strcmp
> -+(IDENTIFIER_POINTER (DECL_NAME (gimple_assign_lhs 
> (context))),
> -+ var_name_str) == 0)
> -+return;
> ++/* Ignore the call to .DEFERRED_INIT that define the original
> ++   var itself.  */
> ++if (is_gimple_assign (context))
> ++  {
> ++if (TREE_CODE (gimple_assign_lhs (context)) == VAR_DECL)
> ++  lhs_var = gimple_assign_lhs (context);
> ++else if (TREE_CODE (gimple_assign_lhs (context)) == SSA_NAME)
> ++  lhs_var = SSA_NAME_VAR (gimple_assign_lhs (context));
> ++  }
> ++   

Re: [PATCH] nvptx: bump default to PTX 4.1

2022-01-05 Thread Andrew Stubbs

On 05/01/2022 10:24, Tom de Vries wrote:

On 12/21/21 12:33, Andrew Stubbs wrote:

On 20/12/2021 15:58, Andrew Stubbs wrote:
In order to support the %dynamic_smem_size PTX feature is is 
necessary to bump the minimum supported PTX version from 3.1 (~2013) 
to 4.1 (~2014).


Tobias has pointed out, privately, that the default version is both 
documented and encoded in the -mptx option, so I need to fix that too.


This patch adds -mptx=4.1, sets it as the default, and updates the 
documentation accordingly.


The -mptx=3.1 option is kept for backwards compatibility as an alias 
for 4.1. There's no point in actually allowing 3.1 as any program 
linked against libgomp will fail (and that's all offloading programs).


OK for stage 1?


Just keep -mptx=3.1 as is, and add -mptx=4.1.

AFAIU, there's actually only one file required to have -mptx=4.1, the 
one using %dynamic_smem_size.  Since it's somewhat cumbersome to add 
flags for a single file, how about:

...
diff --git a/libgomp/configure.tgt b/libgomp/configure.tgt
index d4f1e741b5a..92242697f24 100644
--- a/libgomp/configure.tgt
+++ b/libgomp/configure.tgt
@@ -162,6 +162,7 @@ case "${target}" in

    nvptx*-*-*)
     config_path="nvptx accel"
+   XCFLAGS="$XCFLAGS -mptx=4.1"
     ;;

    *-*-rtems*)
...
?


There shouldn't be any need for that as long as the default is correct. 
In any case, I'm no expert but doesn't the deferred assembly thing mean 
that the whole project needs to have the correct minimum setting?


If the NVPTX maintainer prefers I can leave the 3.1 meaning actually 
3.1, but that will break any makefiles or build scripts that exist in 
the wild and happen to specify 3.1 explicitly (not that I know any 
reason why they would).


Andrew


Re: [PATCH] nvptx: bump default to PTX 4.1

2022-01-05 Thread Tom de Vries via Gcc-patches

On 12/21/21 12:33, Andrew Stubbs wrote:

On 20/12/2021 15:58, Andrew Stubbs wrote:
In order to support the %dynamic_smem_size PTX feature is is necessary 
to bump the minimum supported PTX version from 3.1 (~2013) to 4.1 
(~2014).


Tobias has pointed out, privately, that the default version is both 
documented and encoded in the -mptx option, so I need to fix that too.


This patch adds -mptx=4.1, sets it as the default, and updates the 
documentation accordingly.


The -mptx=3.1 option is kept for backwards compatibility as an alias for 
4.1. There's no point in actually allowing 3.1 as any program linked 
against libgomp will fail (and that's all offloading programs).


OK for stage 1?


Just keep -mptx=3.1 as is, and add -mptx=4.1.

AFAIU, there's actually only one file required to have -mptx=4.1, the 
one using %dynamic_smem_size.  Since it's somewhat cumbersome to add 
flags for a single file, how about:

...
diff --git a/libgomp/configure.tgt b/libgomp/configure.tgt
index d4f1e741b5a..92242697f24 100644
--- a/libgomp/configure.tgt
+++ b/libgomp/configure.tgt
@@ -162,6 +162,7 @@ case "${target}" in

   nvptx*-*-*)
config_path="nvptx accel"
+   XCFLAGS="$XCFLAGS -mptx=4.1"
;;

   *-*-rtems*)
...
?

Thanks,
- Tom


Re: [PATCH] match.pd: Simplify 1 / X for integer X [PR95424]

2022-01-05 Thread Richard Biener via Gcc-patches
On Wed, Jan 5, 2022 at 10:42 AM Jakub Jelinek  wrote:
>
> On Wed, Jan 05, 2022 at 10:38:53AM +0100, Richard Biener via Gcc-patches 
> wrote:
> > On Wed, Jan 5, 2022 at 10:18 AM Zhao Wei Liew  wrote:
> > >
> > > > X >= -1 && X <= 1 is (hopefully?) going to be simplified
> > > > as  (unsigned)X + 1 <= 2, it might be good to simplify it this way
> > > > here as well?
> > >
> > > Yup, GCC does simplify it that way in the end, so I didn't really bother 
> > > to simplify it here. That said, I'm open to simplifying it here as well, 
> > > but I'm not sure how to do the unsigned cast.
> >
> > You'd do sth like
> >   (with
> > {  tree utype = unsigned_type_for (type); }
> > (cond (le (plus (convert:utype @0) { build_one_cst (utype); }) {
> > build_int_cst (utype, 2); }) ...)
> >
> > extra tricky will be 1 bit integer types, I guess it might be easiest
> > to exclude them
> > and special case them separately - X / Y is always X for them I think,
>
> Note, we already have:
>  /* X / bool_range_Y is X.  */
>  (simplify
>   (div @0 SSA_NAME@1)
>   (if (INTEGRAL_TYPE_P (type) && ssa_name_has_boolean_range (@1))
>@0))
> for those.

Ah, it might not handle the signed : 1 case though since -1 is not in the
bool range.  We could generalize the above though.

Richard.

>
> Jakub
>


Re: [PATCH] ifcvt: Check for asm goto at the end of then_bb/else_bb in ifcvt [PR103908]

2022-01-05 Thread Richard Biener via Gcc-patches
On Wed, 5 Jan 2022, Jakub Jelinek wrote:

> Hi!
> 
> On the following testcase, RTL ifcvt sees then_bb
> (note 7 6 8 3 [bb 3] NOTE_INSN_BASIC_BLOCK)
> (insn 8 7 9 3 (set (mem/c:SI (symbol_ref:DI ("b") [flags 0x2]   0x7fdccf5b0cf0 b>) [1 b+0 S4 A32])
> (const_int 1 [0x1])) "pr103908.c":6:7 81 {*movsi_internal}
>  (nil))
> (jump_insn 9 8 13 3 (parallel [
> (asm_operands/v ("# insn 1") ("") 0 []
>  []
>  [
> (label_ref:DI 21)
> ] pr103908.c:7)
> (clobber (reg:CC 17 flags))
> ]) "pr103908.c":7:5 -1
>  (expr_list:REG_UNUSED (reg:CC 17 flags)
> (nil))
>  -> 21)
> and similarly else_bb (just with a different asm_operands template).
> It checks that those basic blocks have a single successor and
> uses last_active_insn which intentionally skips over JUMP_INSNs, sees
> both basic blocks contain the same set and merges them (or if the
> sets are different, attempts some other noce optimization).
> But we can't assume that the jump, even when it has only a single successor,
> has no side-effects.
> 
> The following patch fixes it by checking specially for asm goto, but
> I wonder if it wouldn't be better to
>   if (JUMP_P (BB_END (test_bb)) && !onlyjump_p (BB_END (test_bb)))
> return false;
> and give up on any other hypothetical single successor jumps.
> 
> The patch below has been bootstrapped/regtested on x86_64-linux and
> i686-linux, I could bootstrap the !onlyjump_p version too...

I'd prefer checking with onlyjump_p.  OK with that change.

Thanks,
Richard.

> 2022-01-05  Jakub Jelinek  
> 
>   PR rtl-optimization/103908
>   * ifcvt.c (bb_valid_for_noce_process_p): Punt on bbs ending with
>   asm goto.
> 
>   * gcc.target/i386/pr103908.c: New test.
> 
> --- gcc/ifcvt.c.jj2022-01-03 10:40:42.919140216 +0100
> +++ gcc/ifcvt.c   2022-01-04 23:50:40.962529052 +0100
> @@ -3064,6 +3064,13 @@ bb_valid_for_noce_process_p (basic_block
>  
>if (!insn_valid_noce_process_p (last_insn, cc))
>  return false;
> +
> +  /* Punt for blocks ending with asm goto, last_active_insn
> + ignores JUMP_INSNs.  */
> +  if (JUMP_P (BB_END (test_bb))
> +  && asm_noperands (PATTERN (BB_END (test_bb))) >= 0)
> +return false;
> +
>last_set = single_set (last_insn);
>  
>rtx x = SET_DEST (last_set);
> --- gcc/testsuite/gcc.target/i386/pr103908.c.jj   2022-01-04 
> 23:58:02.992341275 +0100
> +++ gcc/testsuite/gcc.target/i386/pr103908.c  2022-01-04 23:57:39.399671539 
> +0100
> @@ -0,0 +1,24 @@
> +/* PR rtl-optimization/103908 */
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -fdisable-tree-cselim -fno-tree-sink" } */
> +/* { dg-final { scan-assembler "# insn 1" } } */
> +/* { dg-final { scan-assembler "# insn 2" } } */
> +
> +int a, b;
> +
> +void
> +foo (void)
> +{
> +  if (a)
> +{
> +  b = 1;
> +  asm goto ("# insn 1" : : : : lab1);
> +lab1:;
> +}
> +  else
> +{
> +  b = 1;
> +  asm goto ("# insn 2" : : : : lab2);
> +lab2:;
> +}
> +}
> 
>   Jakub
> 
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)


Re: [PATCH] match.pd: Simplify 1 / X for integer X [PR95424]

2022-01-05 Thread Jakub Jelinek via Gcc-patches
On Wed, Jan 05, 2022 at 10:38:53AM +0100, Richard Biener via Gcc-patches wrote:
> On Wed, Jan 5, 2022 at 10:18 AM Zhao Wei Liew  wrote:
> >
> > > X >= -1 && X <= 1 is (hopefully?) going to be simplified
> > > as  (unsigned)X + 1 <= 2, it might be good to simplify it this way
> > > here as well?
> >
> > Yup, GCC does simplify it that way in the end, so I didn't really bother to 
> > simplify it here. That said, I'm open to simplifying it here as well, but 
> > I'm not sure how to do the unsigned cast.
> 
> You'd do sth like
>   (with
> {  tree utype = unsigned_type_for (type); }
> (cond (le (plus (convert:utype @0) { build_one_cst (utype); }) {
> build_int_cst (utype, 2); }) ...)
> 
> extra tricky will be 1 bit integer types, I guess it might be easiest
> to exclude them
> and special case them separately - X / Y is always X for them I think,

Note, we already have:
 /* X / bool_range_Y is X.  */
 (simplify
  (div @0 SSA_NAME@1)
  (if (INTEGRAL_TYPE_P (type) && ssa_name_has_boolean_range (@1))
   @0))
for those.

Jakub



Re: [PATCH] gimple-fold: Remove incorrect folding of debug stmts [PR103691]

2022-01-05 Thread Richard Biener via Gcc-patches
On Wed, 5 Jan 2022, Jakub Jelinek wrote:

> Hi!
> 
> For ADDR_EXPR gimple_debug_bind_get_value fold_stmt_1 uses
> maybe_canonicalize_mem_ref_addr earlier and I think that should
> resolve the concerns raised in PR52329.  But folding ADDR_EXPR
> operand using maybe_fold_reference and then taking address of that
> looks like an invalid transformation, it can transform
>   # DEBUG D.4293 => [0]
> into
>   # DEBUG D.4293 => &2.0e+0
> etc., all we want to allow are the lhs folding of the operand which
> maybe_fold_reference no longer does since r12-21-g0bf8cd9d5e8ac.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2022-01-05  Jakub Jelinek  
> 
>   PR fortran/103691
>   * gimple-fold.c (fold_stmt_1): Don't call maybe_fold_reference
>   for DEBUG stmts with ADDR_EXPR gimple_debug_bind_get_value,
>   it can do unwanted rhs folding like [0] into &2.0 etc.
> 
>   * gfortran.dg/pr103691.f90: New test.
> 
> --- gcc/gimple-fold.c.jj  2022-01-03 10:40:42.872140874 +0100
> +++ gcc/gimple-fold.c 2022-01-04 13:29:17.571321684 +0100
> @@ -6283,8 +6283,7 @@ fold_stmt_1 (gimple_stmt_iterator *gsi,
>if (gimple_debug_bind_p (stmt))
>   {
> tree val = gimple_debug_bind_get_value (stmt);
> -   if (val
> -   && REFERENCE_CLASS_P (val))
> +   if (val && REFERENCE_CLASS_P (val))
>   {
> tree tem = maybe_fold_reference (val);
> if (tem)
> @@ -6292,18 +6291,6 @@ fold_stmt_1 (gimple_stmt_iterator *gsi,
> gimple_debug_bind_set_value (stmt, tem);
> changed = true;
>   }
> - }
> -   else if (val
> -&& TREE_CODE (val) == ADDR_EXPR)
> - {
> -   tree ref = TREE_OPERAND (val, 0);
> -   tree tem = maybe_fold_reference (ref);
> -   if (tem)
> - {
> -   tem = build_fold_addr_expr_with_type (tem, TREE_TYPE (val));
> -   gimple_debug_bind_set_value (stmt, tem);
> -   changed = true;
> - }
>   }
>   }
>break;
> --- gcc/testsuite/gfortran.dg/pr103691.f90.jj 2022-01-04 13:31:23.564557726 
> +0100
> +++ gcc/testsuite/gfortran.dg/pr103691.f902022-01-04 13:31:08.053774883 
> +0100
> @@ -0,0 +1,9 @@
> +! PR fortran/103691
> +! { dg-do compile }
> +! { dg-options "-O2 -g" }
> +
> +program pr103691
> +  real, parameter :: a(0) = 2.0
> +  real, allocatable :: b(:)
> +  allocate (b, mold=a)
> +end
> 
>   Jakub
> 
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)


[PATCH] ifcvt: Check for asm goto at the end of then_bb/else_bb in ifcvt [PR103908]

2022-01-05 Thread Jakub Jelinek via Gcc-patches
Hi!

On the following testcase, RTL ifcvt sees then_bb
(note 7 6 8 3 [bb 3] NOTE_INSN_BASIC_BLOCK)
(insn 8 7 9 3 (set (mem/c:SI (symbol_ref:DI ("b") [flags 0x2]  ) [1 b+0 S4 A32])
(const_int 1 [0x1])) "pr103908.c":6:7 81 {*movsi_internal}
 (nil))
(jump_insn 9 8 13 3 (parallel [
(asm_operands/v ("# insn 1") ("") 0 []
 []
 [
(label_ref:DI 21)
] pr103908.c:7)
(clobber (reg:CC 17 flags))
]) "pr103908.c":7:5 -1
 (expr_list:REG_UNUSED (reg:CC 17 flags)
(nil))
 -> 21)
and similarly else_bb (just with a different asm_operands template).
It checks that those basic blocks have a single successor and
uses last_active_insn which intentionally skips over JUMP_INSNs, sees
both basic blocks contain the same set and merges them (or if the
sets are different, attempts some other noce optimization).
But we can't assume that the jump, even when it has only a single successor,
has no side-effects.

The following patch fixes it by checking specially for asm goto, but
I wonder if it wouldn't be better to
  if (JUMP_P (BB_END (test_bb)) && !onlyjump_p (BB_END (test_bb)))
return false;
and give up on any other hypothetical single successor jumps.

The patch below has been bootstrapped/regtested on x86_64-linux and
i686-linux, I could bootstrap the !onlyjump_p version too...

2022-01-05  Jakub Jelinek  

PR rtl-optimization/103908
* ifcvt.c (bb_valid_for_noce_process_p): Punt on bbs ending with
asm goto.

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

--- gcc/ifcvt.c.jj  2022-01-03 10:40:42.919140216 +0100
+++ gcc/ifcvt.c 2022-01-04 23:50:40.962529052 +0100
@@ -3064,6 +3064,13 @@ bb_valid_for_noce_process_p (basic_block
 
   if (!insn_valid_noce_process_p (last_insn, cc))
 return false;
+
+  /* Punt for blocks ending with asm goto, last_active_insn
+ ignores JUMP_INSNs.  */
+  if (JUMP_P (BB_END (test_bb))
+  && asm_noperands (PATTERN (BB_END (test_bb))) >= 0)
+return false;
+
   last_set = single_set (last_insn);
 
   rtx x = SET_DEST (last_set);
--- gcc/testsuite/gcc.target/i386/pr103908.c.jj 2022-01-04 23:58:02.992341275 
+0100
+++ gcc/testsuite/gcc.target/i386/pr103908.c2022-01-04 23:57:39.399671539 
+0100
@@ -0,0 +1,24 @@
+/* PR rtl-optimization/103908 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdisable-tree-cselim -fno-tree-sink" } */
+/* { dg-final { scan-assembler "# insn 1" } } */
+/* { dg-final { scan-assembler "# insn 2" } } */
+
+int a, b;
+
+void
+foo (void)
+{
+  if (a)
+{
+  b = 1;
+  asm goto ("# insn 1" : : : : lab1);
+lab1:;
+}
+  else
+{
+  b = 1;
+  asm goto ("# insn 2" : : : : lab2);
+lab2:;
+}
+}

Jakub



Re: [PATCH] match.pd: Simplify 1 / X for integer X [PR95424]

2022-01-05 Thread Richard Biener via Gcc-patches
On Wed, Jan 5, 2022 at 10:18 AM Zhao Wei Liew  wrote:
>
> > X >= -1 && X <= 1 is (hopefully?) going to be simplified
> > as  (unsigned)X + 1 <= 2, it might be good to simplify it this way
> > here as well?
>
> Yup, GCC does simplify it that way in the end, so I didn't really bother to 
> simplify it here. That said, I'm open to simplifying it here as well, but I'm 
> not sure how to do the unsigned cast.

You'd do sth like
  (with
{  tree utype = unsigned_type_for (type); }
(cond (le (plus (convert:utype @0) { build_one_cst (utype); }) {
build_int_cst (utype, 2); }) ...)

extra tricky will be 1 bit integer types, I guess it might be easiest
to exclude them
and special case them separately - X / Y is always X for them I think,
for signed
1 bit types X / Y is always undefined when X is not 0 (the division
overflows or is by zero).
Not sure if worth though ;)  (might appear when bools end up divided
by bools ...)

> Besides that, thanks for the rest of your suggestions! I'm testing the 
> changes and will post a v2 soon.
>
> On Wed, 5 Jan 2022 at 16:18, Richard Biener  
> wrote:
> >
> > On Wed, Jan 5, 2022 at 7:15 AM Zhao Wei Liew via Gcc-patches
> >  wrote:
> > >
> > > match.pd/95424: Simplify 1 / X for integer X
> > >
> > > This patch implements an optimization for the following C++ code:
> > >
> > > int f(int x) {
> > > return 1 / x;
> > > }
> > >
> > > int f(unsigned int x) {
> > > return 1 / x;
> > > }
> > >
> > > Before this patch, x86-64 gcc -std=c++20 -O3 produces the following
> > > assembly:
> > >
> > > f(int):
> > > xor edx, edx
> > > mov eax, 1
> > > idiv edi
> > > ret
> > > f(unsigned int):
> > > xor edx, edx
> > > mov eax, 1
> > > div edi
> > > ret
> > >
> > > In comparison, clang++ -std=c++20 -O3 produces the following assembly:
> > >
> > > f(int):
> > > lea ecx, [rdi + 1]
> > > xor eax, eax
> > > cmp ecx, 3
> > > cmovb eax, edi
> > > ret
> > > f(unsigned int):
> > > xor eax, eax
> > > cmp edi, 1
> > > sete al
> > > ret
> > >
> > > Clang's output is more efficient as it avoids expensive div operations.
> > >
> > > With this patch, GCC now produces the following assembly:
> > > f(int):
> > > lea eax, [rdi + 1]
> > > cmp eax, 2
> > > mov eax, 0
> > > cmovbe eax, edi
> > > ret
> > > f(unsigned int):
> > > xor eax, eax
> > > cmp edi, 1
> > > sete al
> > > ret
> > >
> > > which is virtualy identical to Clang's assembly output. Any slight
> > > differences
> > > in the output for f(int) is related to another possible missed 
> > > optimization.
> > >
> > > gcc/ChangeLog:
> > >
> > > * match.pd: Simplify 1 / X where X is an integer.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > * gcc.dg/tree-ssa/divide-6.c: New test.
> > > * gcc.dg/tree-ssa/divide-7.c: New test.
> > >
> > > diff --git a/gcc/match.pd b/gcc/match.pd
> > > index 84c9b918041..5edae1818bb 100644
> > > --- a/gcc/match.pd
> > > +++ b/gcc/match.pd
> > > @@ -422,7 +422,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > > (div:C @0 (negate @0))
> > > (if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
> > >   && TYPE_OVERFLOW_UNDEFINED (type))
> > > -{ build_minus_one_cst (type); })))
> > > +{ build_minus_one_cst (type); }))
> > > +
> > > + /* 1 / X -> X == 1 for unsigned integer X
> > > +1 / X -> X >= -1 && X <= 1 ? X : 0 for signed integer X
> > > +But not for 1 / 0 so that we can get proper warnings and errors. */
> > > + (simplify
> > > +   (div integer_onep@0 @1)
> > > +   (switch
> > > + (if (!integer_zerop (@1)
> > > +  && INTEGRAL_TYPE_P (TREE_TYPE (@1))
> >
> > you can use INTEGRAL_TYPE_P (type), the type of @0, @1 and the
> > result ('type') are the same.
> >
> > > +  && TYPE_UNSIGNED (TREE_TYPE (@1)))
> > > +  (eq @0 @1))
> > > + (if (!integer_zerop (@1)
> > > +  && INTEGRAL_TYPE_P (TREE_TYPE (@1))
> > > +  && !TYPE_UNSIGNED (TREE_TYPE (@1)))
> >
> > Please refactor as
> >
> > (if (INTEGRAL_TYPE_P (type)
> >  && !integer_zerop (@1))
> >  (if (TYPE_UNSIGNED ())
> >   (eq @0 @1)
> >   (cond (...
> >
> > > +  (cond (bit_and (ge @1 { build_minus_one_cst (integer_type_node); })
> > > + (le @1 { build_one_cst (integer_type_node); }))
> >
> > You should use build_[minus_]one_cst (type) to get -1/1 of the correct
> > type here.
> >
> > X >= -1 && X <= 1 is (hopefully?) going to be simplified
> > as  (unsigned)X + 1 <= 2, it might be good to simplify it this way
> > here as well?
> >
> > Finally I'm not sure whether 1 /[ceil] 2 isn't 1, similar -1 /[floor]
> > 2 should be -1
> > so the transform looks to be correct only for TRUNC_DIV_EXPR, not all 'div'?
> >
> > Thanks,
> > Richard.
> >
> > > +@1 { build_zero_cst (type); })
> > >
> > >  /* For unsigned integral types, FLOOR_DIV_EXPR is the same as
> > > TRUNC_DIV_EXPR.  Rewrite into the latter in this case.  

Re: [PATCH] Register --sysroot in the driver switches table

2022-01-05 Thread Olivier Hainque via Gcc-patches
Hi Martin,

> On 5 Jan 2022, at 08:45, Martin Liška  wrote:
> 
> On 12/20/21 22:28, Olivier Hainque via Gcc-patches wrote:

> I think the patch broke my cross-rx-gcc12 package, failing now with:

> configure: error: in 
> `/home/abuild/rpmbuild/BUILD/gcc-12.0.0+git190624/obj-x86_64-suse-linux/rx-elf/libgcc':

> xgcc: error: unrecognized command-line option '--sysroot=/usr/rx-elf/sys-root'
> 
> The compiler is configured with:
> 
> [   21s] + ../configure --prefix=/usr --infodir=/usr/share/info 
> --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 
> --enable-languages=c,c++ --enable-checking=release --disable-werror 
> --with-gxx-include-dir=/usr/include/c++/12 --enable-ssp --disable-libssp 
> --disable-libvtv --enable-cet=auto --disable-libcc1 --disable-plugin 
> --with-bugurl=https://bugs.opensuse.org/ '--with-pkgversion=SUSE Linux' 
> --with-slibdir=/usr/rx-elf/sys-root/lib64 --with-system-zlib 
> --enable-libstdcxx-allocator=new --disable-libstdcxx-pch 
> --enable-version-specific-runtime-libs --with-gcc-major-version-only 
> --enable-linux-futex --enable-gnu-indirect-function --program-suffix=-12 
> --program-prefix=rx-elf- --target=rx-elf --disable-nls 
> --with-sysroot=/usr/rx-elf/sys-root --with-build-sysroot=/usr/rx-elf/sys-root 
> --with-build-time-tools=/usr/rx-elf/bin --with-newlib --disable-libsanitizer 
> --build=x86_64-suse-linux --host=x86_64-suse-linux
> 
> Can you please take a look?

Sure. Thanks for reporting the failure. Sorry for the breakage.

The change should also set "validated" true 
when requesting to save --sysroot.

I'm not sure why we don't see the problem with our vxworks
setup - double checked again this morning, we do have successful
builds passing --sysroot to the driver when configuring various
libraries.

Testing the patch further ...





[PATCH] gimple-fold: Remove incorrect folding of debug stmts [PR103691]

2022-01-05 Thread Jakub Jelinek via Gcc-patches
Hi!

For ADDR_EXPR gimple_debug_bind_get_value fold_stmt_1 uses
maybe_canonicalize_mem_ref_addr earlier and I think that should
resolve the concerns raised in PR52329.  But folding ADDR_EXPR
operand using maybe_fold_reference and then taking address of that
looks like an invalid transformation, it can transform
  # DEBUG D.4293 => [0]
into
  # DEBUG D.4293 => &2.0e+0
etc., all we want to allow are the lhs folding of the operand which
maybe_fold_reference no longer does since r12-21-g0bf8cd9d5e8ac.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2022-01-05  Jakub Jelinek  

PR fortran/103691
* gimple-fold.c (fold_stmt_1): Don't call maybe_fold_reference
for DEBUG stmts with ADDR_EXPR gimple_debug_bind_get_value,
it can do unwanted rhs folding like [0] into &2.0 etc.

* gfortran.dg/pr103691.f90: New test.

--- gcc/gimple-fold.c.jj2022-01-03 10:40:42.872140874 +0100
+++ gcc/gimple-fold.c   2022-01-04 13:29:17.571321684 +0100
@@ -6283,8 +6283,7 @@ fold_stmt_1 (gimple_stmt_iterator *gsi,
   if (gimple_debug_bind_p (stmt))
{
  tree val = gimple_debug_bind_get_value (stmt);
- if (val
- && REFERENCE_CLASS_P (val))
+ if (val && REFERENCE_CLASS_P (val))
{
  tree tem = maybe_fold_reference (val);
  if (tem)
@@ -6292,18 +6291,6 @@ fold_stmt_1 (gimple_stmt_iterator *gsi,
  gimple_debug_bind_set_value (stmt, tem);
  changed = true;
}
-   }
- else if (val
-  && TREE_CODE (val) == ADDR_EXPR)
-   {
- tree ref = TREE_OPERAND (val, 0);
- tree tem = maybe_fold_reference (ref);
- if (tem)
-   {
- tem = build_fold_addr_expr_with_type (tem, TREE_TYPE (val));
- gimple_debug_bind_set_value (stmt, tem);
- changed = true;
-   }
}
}
   break;
--- gcc/testsuite/gfortran.dg/pr103691.f90.jj   2022-01-04 13:31:23.564557726 
+0100
+++ gcc/testsuite/gfortran.dg/pr103691.f90  2022-01-04 13:31:08.053774883 
+0100
@@ -0,0 +1,9 @@
+! PR fortran/103691
+! { dg-do compile }
+! { dg-options "-O2 -g" }
+
+program pr103691
+  real, parameter :: a(0) = 2.0
+  real, allocatable :: b(:)
+  allocate (b, mold=a)
+end

Jakub



Re: [committed] testsuite: Fix gcc.target/i386/pr103895.c testcase [PR103895]

2022-01-05 Thread Jakub Jelinek via Gcc-patches
On Wed, Jan 05, 2022 at 10:16:30AM +0100, Andreas Schwab wrote:
> On Jan 05 2022, Jakub Jelinek via Gcc-patches wrote:
> 
> > The testcase uses SSE and SSE2 intrinsics, so fails on i686-linux
> > if -msse2 isn't enabled by default.  Fixed by adding -msse2 to
> > dg-options.
> 
> Shouldn't that use { dg-require-effective-target sse2 }?

Not necessarily, it is a dg-do compile test, so it doesn't care
if assembler can assemble sse2 instructions or not.

Jakub



Re: [PATCH] match.pd: Simplify 1 / X for integer X [PR95424]

2022-01-05 Thread Zhao Wei Liew via Gcc-patches
> X >= -1 && X <= 1 is (hopefully?) going to be simplified
> as  (unsigned)X + 1 <= 2, it might be good to simplify it this way
> here as well?

Yup, GCC does simplify it that way in the end, so I didn't really bother to
simplify it here. That said, I'm open to simplifying it here as well, but
I'm not sure how to do the unsigned cast.
Besides that, thanks for the rest of your suggestions! I'm testing the
changes and will post a v2 soon.

On Wed, 5 Jan 2022 at 16:18, Richard Biener 
wrote:
>
> On Wed, Jan 5, 2022 at 7:15 AM Zhao Wei Liew via Gcc-patches
>  wrote:
> >
> > match.pd/95424: Simplify 1 / X for integer X
> >
> > This patch implements an optimization for the following C++ code:
> >
> > int f(int x) {
> > return 1 / x;
> > }
> >
> > int f(unsigned int x) {
> > return 1 / x;
> > }
> >
> > Before this patch, x86-64 gcc -std=c++20 -O3 produces the following
> > assembly:
> >
> > f(int):
> > xor edx, edx
> > mov eax, 1
> > idiv edi
> > ret
> > f(unsigned int):
> > xor edx, edx
> > mov eax, 1
> > div edi
> > ret
> >
> > In comparison, clang++ -std=c++20 -O3 produces the following assembly:
> >
> > f(int):
> > lea ecx, [rdi + 1]
> > xor eax, eax
> > cmp ecx, 3
> > cmovb eax, edi
> > ret
> > f(unsigned int):
> > xor eax, eax
> > cmp edi, 1
> > sete al
> > ret
> >
> > Clang's output is more efficient as it avoids expensive div operations.
> >
> > With this patch, GCC now produces the following assembly:
> > f(int):
> > lea eax, [rdi + 1]
> > cmp eax, 2
> > mov eax, 0
> > cmovbe eax, edi
> > ret
> > f(unsigned int):
> > xor eax, eax
> > cmp edi, 1
> > sete al
> > ret
> >
> > which is virtualy identical to Clang's assembly output. Any slight
> > differences
> > in the output for f(int) is related to another possible missed
optimization.
> >
> > gcc/ChangeLog:
> >
> > * match.pd: Simplify 1 / X where X is an integer.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.dg/tree-ssa/divide-6.c: New test.
> > * gcc.dg/tree-ssa/divide-7.c: New test.
> >
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index 84c9b918041..5edae1818bb 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -422,7 +422,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > (div:C @0 (negate @0))
> > (if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
> >   && TYPE_OVERFLOW_UNDEFINED (type))
> > -{ build_minus_one_cst (type); })))
> > +{ build_minus_one_cst (type); }))
> > +
> > + /* 1 / X -> X == 1 for unsigned integer X
> > +1 / X -> X >= -1 && X <= 1 ? X : 0 for signed integer X
> > +But not for 1 / 0 so that we can get proper warnings and errors. */
> > + (simplify
> > +   (div integer_onep@0 @1)
> > +   (switch
> > + (if (!integer_zerop (@1)
> > +  && INTEGRAL_TYPE_P (TREE_TYPE (@1))
>
> you can use INTEGRAL_TYPE_P (type), the type of @0, @1 and the
> result ('type') are the same.
>
> > +  && TYPE_UNSIGNED (TREE_TYPE (@1)))
> > +  (eq @0 @1))
> > + (if (!integer_zerop (@1)
> > +  && INTEGRAL_TYPE_P (TREE_TYPE (@1))
> > +  && !TYPE_UNSIGNED (TREE_TYPE (@1)))
>
> Please refactor as
>
> (if (INTEGRAL_TYPE_P (type)
>  && !integer_zerop (@1))
>  (if (TYPE_UNSIGNED ())
>   (eq @0 @1)
>   (cond (...
>
> > +  (cond (bit_and (ge @1 { build_minus_one_cst (integer_type_node);
})
> > + (le @1 { build_one_cst (integer_type_node); }))
>
> You should use build_[minus_]one_cst (type) to get -1/1 of the correct
> type here.
>
> X >= -1 && X <= 1 is (hopefully?) going to be simplified
> as  (unsigned)X + 1 <= 2, it might be good to simplify it this way
> here as well?
>
> Finally I'm not sure whether 1 /[ceil] 2 isn't 1, similar -1 /[floor]
> 2 should be -1
> so the transform looks to be correct only for TRUNC_DIV_EXPR, not all
'div'?
>
> Thanks,
> Richard.
>
> > +@1 { build_zero_cst (type); })
> >
> >  /* For unsigned integral types, FLOOR_DIV_EXPR is the same as
> > TRUNC_DIV_EXPR.  Rewrite into the latter in this case.  */
> > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/divide-6.c
> > b/gcc/testsuite/gcc.dg/tree-ssa/divide-6.c
> > new file mode 100644
> > index 000..a9fc4c04058
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/divide-6.c
> > @@ -0,0 +1,9 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O -fdump-tree-optimized" } */
> > +
> > +unsigned int f(unsigned int x) {
> > +  return 1 / x;
> > +}
> > +
> > +/* { dg-final { scan-tree-dump-not "1 / x_..D.;" "optimized" } } */
> > +/* { dg-final { scan-tree-dump "x_..D. == 1;" "optimized" } } */
> > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/divide-7.c
> > b/gcc/testsuite/gcc.dg/tree-ssa/divide-7.c
> > new file mode 100644
> > index 000..285279af7c2
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/divide-7.c
> > @@ -0,0 +1,9 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O 

Re: [committed] testsuite: Fix gcc.target/i386/pr103895.c testcase [PR103895]

2022-01-05 Thread Andreas Schwab
On Jan 05 2022, Jakub Jelinek via Gcc-patches wrote:

> The testcase uses SSE and SSE2 intrinsics, so fails on i686-linux
> if -msse2 isn't enabled by default.  Fixed by adding -msse2 to
> dg-options.

Shouldn't that use { dg-require-effective-target sse2 }?

-- 
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."


[committed] testsuite: Fix gcc.target/i386/pr103895.c testcase [PR103895]

2022-01-05 Thread Jakub Jelinek via Gcc-patches
Hi!

The testcase uses SSE and SSE2 intrinsics, so fails on i686-linux
if -msse2 isn't enabled by default.  Fixed by adding -msse2 to
dg-options.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to
trunk as obvious.

2022-01-05  Jakub Jelinek  

PR target/103895
* gcc.target/i386/pr103895.c: Add -msse2 to dg-options.

--- gcc/testsuite/gcc.target/i386/pr103895.c.jj 2022-01-04 23:11:22.788586688 
+0100
+++ gcc/testsuite/gcc.target/i386/pr103895.c2022-01-05 01:30:33.926589366 
+0100
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Og -ffloat-store" } */
+/* { dg-options "-Og -ffloat-store -msse2" } */
 
 #include 
 typedef float vFloat __attribute__((__vector_size__(16)));

Jakub



Re: [PATCH] enable -Winvalid-memory-order for C++ [PR99612]

2022-01-05 Thread Martin Liška

On 12/8/21 17:49, Martin Sebor via Gcc-patches wrote:

Even with -Wno-system-headers enabled, the -Winvalid-memory-order
code tries to make sure calls to atomic functions with invalid
memory orders are diagnosed even though the C atomic functions
are defined as macros in the  system header.
The warning triggers at all optimization levels, including -O0.

Independently, the core diagnostic enhancements implemented earlier
this year (the warning group control) enable warnings for functions
defined in system headers that are inlined into user code.  This
was done for similar reason as above: because it's desirable to
diagnose invalid calls made from user code to system functions
(e.g., buffer overflows, invalid or mismatched deallocations,
etc.)

However, the C macro solution interferes with the code diagnostic
changes and prevents the invalid memory model warnings from being
issued for the same problems in C++.  In addition, because C++
atomics are ordinary (inline) functions that call the underlying
__atomic_xxx built-ins, the invalid memory orders can only be
detected with both inlining and constant propagation enabled.

The attached patch removes these limitations and enables
-Winvalid-memory-order to trigger even for C++ std::atomic,
(almost) just like it does in C, at all optimization levels
including -O0.

To make that possible I had to move -Winvalid-memory-order from
builtins.c to a GIMPLE pass where it can use context-sensitive
range info at -O0, instead of relying on constant propagation
(only available at -O1 and above).  Although the same approach
could be used to emit better object code for C++ atomics at -O0
(i.e., use the right memory order instead of dropping to seq_cst),
this patch doesn't do that.)

In addition to enabling the warning I've also enhanced it to
include the memory models involved in the diagnosed call (both
the problem ones and the viable alternatives).

Tested on x86_64-linux.

Jonathan, I CC you for two reasons: a) because this solution
is based on your (as well as my own) preference for handling
C++ system headers, and because of our last week's discussion
of the false positives in std::string resulting from the same
choice there.

I don't anticipate this change to lead to the same fallout
because it's unlikely for GCC to synthesize invalid memory
orders out of thin air; and b) because the current solution
can only detect the problems in calls to atomic functions at
-O0 that are declared with attribute always_inline.  This
includes member functions defined in the enclosing atomic
class but not namespace-scope functions.  To make
the detection possible those would also have to be
always_inline.  If that's a change you'd like to see I can
look into making it happen.

Martin


Hello.

I think the patch caused:

gcc/gimple-ssa-warn-access.cc:2844:30: warning: quoted ‘%s’ directive in 
format; use ‘%qs’ instead [-Wformat-diag]

Can you please take a look?

Thanks,
Martin


  1   2   >