Re: [PATCH, rs6000] Add a combine pattern for CA minus one [PR95737]

2022-01-18 Thread Andrew Pinski via Gcc-patches
On Tue, Jan 18, 2022 at 11:13 PM HAO CHEN GUI via Gcc-patches
 wrote:
>
> Hi,
>This patch adds a combine pattern for "CA minus one". As CA only has two
> values (0 or 1), we could convert following pattern
>   (sign_extend:DI (plus:SI (reg:SI 98 ca)
> (const_int -1 [0x]
> to
>(plus:DI (reg:DI 98 ca)
> (const_int -1 [0x])))
> With this patch, it eliminates one unnecessary sign extend. Also in 
> rs6000,
> regclass of CA register is set to NO_REGS. So CA is not in hard register set
> and it can't match register_operand. The patch changes it to any_operand.
>
> Bootstrapped and tested on powerpc64-linux BE and LE with no regressions.
> Is this okay for trunk? Any recommendations? Thanks a lot.
>
> ChangeLog
> 2022-01-19 Haochen Gui 
>
> gcc/
> * config/rs6000/predicates.md (ca_operand): Match any_operand as CA
> register is not in hard register set.
> * config/rs6000/rs6000.md (extenddi_ca_minus_one): Define.
>
> gcc/testsuite/
> * gcc.target/powerpc/pr95737.c: New.
>
>
> patch.diff
> diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
> index c65dfb91f3d..cd2ae1dc8e0 100644
> --- a/gcc/config/rs6000/predicates.md
> +++ b/gcc/config/rs6000/predicates.md
> @@ -188,7 +188,7 @@ (define_predicate "vlogical_operand"
>
>  ;; Return 1 if op is the carry register.
>  (define_predicate "ca_operand"
> -  (match_operand 0 "register_operand")
> +  (match_operand 0 "any_operand")
>  {
>if (SUBREG_P (op))
>  op = SUBREG_REG (op);
> diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
> index 6ecb0bd6142..f1b09aad3b5 100644
> --- a/gcc/config/rs6000/rs6000.md
> +++ b/gcc/config/rs6000/rs6000.md
> @@ -2358,6 +2358,21 @@ (define_insn "subf3_carry_in_xx"
>"subfe %0,%0,%0"
>[(set_attr "type" "add")])
>
> +(define_insn_and_split "*extenddi_ca_minus_one"
> +  [(set (match_operand:DI 0 "gpc_reg_operand")
> +   (sign_extend:DI (plus:SI (match_operand:SI 1 "ca_operand")
> +(const_int -1]
> +  ""
> +  "#"
> +  ""
> +  [(parallel [(set (match_dup 0)
> +  (plus:DI (match_dup 2)
> +   (const_int -1)))
> + (clobber (match_dup 2))])]
> +{
> +  operands[2] = copy_rtx (operands[1]);
> +  PUT_MODE (operands[2], DImode);
> +})

There are a few things missing I think for this to be correct.
I think it should be:
(define_insn_and_split "*extenddi_ca_minus_one"
  [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
   (sign_extend:DI (plus:SI (reg:SI CA_REGNO)
 (const_int -1]
  ""
  "#"
  "&& reload_completed"
  [(parallel [(set (match_dup 0)
  (plus:DI (reg:DI CA_REGNO)
   (const_int -1)))
 (clobber (reg:DI CA_REGNO))])]
{})

There is no reason to change ca_operand either since
subf3_carry_in_xx already hard codes the CA_REGNO too; you can
just use it directly like above.

Sorry for the incorrect whitespace formatting though.

Thanks,
Andrew Pinski

>
>  (define_insn "@neg2"
>[(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c 
> b/gcc/testsuite/gcc.target/powerpc/pr95737.c
> new file mode 100644
> index 000..94320f23423
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c
> @@ -0,0 +1,10 @@
> +/* PR target/95737 */
> +/* { dg-do compile { target lp64 } } */
> +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */
> +/* { dg-final { scan-assembler-not {\mextsw\M} } } */
> +
> +
> +unsigned long long negativeLessThan (unsigned long long a, unsigned long 
> long b)
> +{
> +   return -(a < b);
> +}


nvptx: update fix for -Wformat-diag (was: [PATCH] nvptx: fix -Wformat-diag warnings)

2022-01-18 Thread Thomas Schwinge
Hi!

On 2022-01-18T17:51:31+0100, Martin Liška  wrote:
> Can you please test for me the following patch candidate?

Thanks.  I additionally fixed up 'num_workers' in test cases, and then
pushed to master branch commit 2aea19bdb12308aac1519ffc5ecc9d1ec24f9cc5
"nvptx: update fix for -Wformat-diag", see attached.


Grüße
 Thomas


-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
>From 2aea19bdb12308aac1519ffc5ecc9d1ec24f9cc5 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Tue, 18 Jan 2022 17:50:02 +0100
Subject: [PATCH] nvptx: update fix for -Wformat-diag

gcc/ChangeLog:

	* config/nvptx/nvptx.cc (nvptx_goacc_validate_dims_1): Update
	warning messages.

libgomp/ChangeLog:

	* testsuite/libgomp.oacc-c++/privatized-ref-2.C: Update scanning
	patterns.
	* testsuite/libgomp.oacc-c++/privatized-ref-3.C: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c:
	Likewise.
	* testsuite/libgomp.oacc-c-c++-common/kernels-loop-2.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/pr85486.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/pr95270-1.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/routine-nohost-2.c:
	Likewise.
	* testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c:
	Likewise.
	* testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c:
	Likewise.
	* testsuite/libgomp.oacc-c-c++-common/vector-length-64-1.c:
	Likewise.
	* testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90:
	Likewise.
	* testsuite/libgomp.oacc-fortran/derivedtypes-arrays-1.f90:
	Likewise.
	* testsuite/libgomp.oacc-fortran/kernels-loop-2.f95: Likewise.
	* testsuite/libgomp.oacc-fortran/parallel-dims.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/privatized-ref-1.f95: Likewise.

Co-authored-by: Thomas Schwinge 
---
 gcc/config/nvptx/nvptx.cc  |  8 
 .../testsuite/libgomp.oacc-c++/privatized-ref-2.C  |  6 +++---
 .../testsuite/libgomp.oacc-c++/privatized-ref-3.C  |  6 +++---
 .../libgomp.oacc-c-c++-common/acc_prof-kernels-1.c |  4 ++--
 .../libgomp.oacc-c-c++-common/kernels-loop-2.c |  4 ++--
 .../libgomp.oacc-c-c++-common/parallel-dims.c  | 14 +++---
 .../testsuite/libgomp.oacc-c-c++-common/pr85486.c  |  2 +-
 .../libgomp.oacc-c-c++-common/pr95270-1.c  |  4 ++--
 .../libgomp.oacc-c-c++-common/routine-nohost-2.c   |  2 +-
 .../libgomp.oacc-c-c++-common/struct-copyout-1.c   |  2 +-
 .../libgomp.oacc-c-c++-common/struct-copyout-2.c   |  2 +-
 .../libgomp.oacc-c-c++-common/vector-length-64-1.c |  2 +-
 .../libgomp.oacc-fortran/attach-descriptor-1.f90   |  2 +-
 .../libgomp.oacc-fortran/derivedtypes-arrays-1.f90 |  2 +-
 .../libgomp.oacc-fortran/kernels-loop-2.f95|  4 ++--
 .../libgomp.oacc-fortran/parallel-dims.f90 |  4 ++--
 .../libgomp.oacc-fortran/privatized-ref-1.f95  |  6 +++---
 17 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index a829bd3fe7a..db6a405d623 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -5894,7 +5894,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level, unsigned used)
 
   if (dims[GOMP_DIM_VECTOR] > PTX_WARP_SIZE)
 	{
-	  vector_reason = G_("using % (%d) due to call to"
+	  vector_reason = G_("using % due to call to"
 			 " vector-partitionable routine, ignoring %d");
 	  dims[GOMP_DIM_VECTOR] = PTX_WARP_SIZE;
 	}
@@ -5902,7 +5902,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level, unsigned used)
 
   if (dims[GOMP_DIM_VECTOR] == 0)
 {
-  vector_reason = G_("using % (%d), ignoring runtime setting");
+  vector_reason = G_("using %, ignoring runtime setting");
   dims[GOMP_DIM_VECTOR] = default_vector_length;
 }
 
@@ -5916,12 +5916,12 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level, unsigned used)
 warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
 		vector_reason != NULL
 		? vector_reason
-		: G_("using % (%d), ignoring %d"),
+		: G_("using %, ignoring %d"),
 		dims[GOMP_DIM_VECTOR], old_dims[GOMP_DIM_VECTOR]);
 
   if (dims[GOMP_DIM_WORKER] != old_dims[GOMP_DIM_WORKER])
 warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
-		G_("using % (%d), ignoring %d"),
+		G_("using %, ignoring %d"),
 		dims[GOMP_DIM_WORKER], old_dims[GOMP_DIM_WORKER]);
 
   if (oacc_default_dims_p)
diff --git a/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-2.C b/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-2.C
index f531bae5f2d..18552206c6b 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-2.C
+++ b/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-2.C
@@ -69,7 +69,7 @@ void workers (void)
 #pragma acc parallel copyout(res) 

Re: [PATCH] middle-end/101292 - invalid memory access with warning control

2022-01-18 Thread Richard Biener via Gcc-patches
On Tue, 18 Jan 2022, Martin Sebor wrote:

> On 1/18/22 01:36, Richard Biener wrote:
> > On Mon, 17 Jan 2022, Martin Sebor wrote:
> > 
> >> On 1/17/22 07:32, Richard Biener via Gcc-patches wrote:
> >>> The warning control falls into the C++ trap of using a reference
> >>> to old hashtable contents for a put operation which can end up
> >>> re-allocating that before reading from the old freed referenced to
> >>> source.  Fixed by introducing a temporary.
> >>
> >> I think a better place to fix this and avoid the gotcha once and
> >> for all is in the GCC hash_map: C++ containers are expected to
> >> handle the insertion of own elements gracefully.
> > 
> > I don't think that's reasonably possible if you consider
> > 
> >T *a = map.get (X);
> >T *b = map.get (Y);
> >map.put (Z, *a);
> >map.put (W, *b);
> 
> This case is up to the caller to handle, the same as anything else
> involving pointers or references into reallocated storage (it's no
> different in C than it is in C++).
> 
> The specific case I'm referring to is passing a pointer or reference
> to a single element in a container to the first modifying call on
> the container.

Huh, that's a quite special case I'm not sure "fixing" will avoid
the mistake.

> > 
> > the only way to "fix" it would be to change the API to not
> > return by reference for get, remove get_or_insert (or change
> > its API to also require passing the new value).
> 
> No, the fix is to have the modifying function create a copy of
> the element being inserted before reallocating the container.

Sure, that's possible I guess.

Richard.


[PATCH] testsuite/102833 - fix gcc.dg/vect/bb-slp-17.c dump scanning

2022-01-18 Thread Richard Biener via Gcc-patches
The desired transform requires V2SI vector add support, the closest
we have is vect64 so check that which at least fixes the i?86 fail.

Tested on x86_64-unknown-linux-gnu, pushed.

2022-01-19  Richard Biener  

PR testsuite/102833
* gcc.dg/vect/bb-slp-17.c: Require vect64.
---
 gcc/testsuite/gcc.dg/vect/bb-slp-17.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-17.c 
b/gcc/testsuite/gcc.dg/vect/bb-slp-17.c
index f8bfb4b8b1a..fc3ef42f51a 100644
--- a/gcc/testsuite/gcc.dg/vect/bb-slp-17.c
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-17.c
@@ -57,5 +57,6 @@ int main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "optimized: basic block" 1 "slp2" { 
target vect_int_mult } } } */
-  
+/* We need V2SI vector add support for the b[] vectorization, if we don't
+   have that we might only see the store vectorized and thus 2 subgraphs.  */
+/* { dg-final { scan-tree-dump-times "optimized: basic block" 1 "slp2" { 
target { vect_int_mult && vect64 } } } } */
-- 
2.31.1


[PATCH, rs6000] Add a combine pattern for CA minus one [PR95737]

2022-01-18 Thread HAO CHEN GUI via Gcc-patches
Hi,
   This patch adds a combine pattern for "CA minus one". As CA only has two
values (0 or 1), we could convert following pattern
  (sign_extend:DI (plus:SI (reg:SI 98 ca)
(const_int -1 [0x]
to
   (plus:DI (reg:DI 98 ca)
(const_int -1 [0x])))
With this patch, it eliminates one unnecessary sign extend. Also in rs6000,
regclass of CA register is set to NO_REGS. So CA is not in hard register set
and it can't match register_operand. The patch changes it to any_operand.

Bootstrapped and tested on powerpc64-linux BE and LE with no regressions.
Is this okay for trunk? Any recommendations? Thanks a lot.

ChangeLog
2022-01-19 Haochen Gui 

gcc/
* config/rs6000/predicates.md (ca_operand): Match any_operand as CA
register is not in hard register set.
* config/rs6000/rs6000.md (extenddi_ca_minus_one): Define.

gcc/testsuite/
* gcc.target/powerpc/pr95737.c: New.


patch.diff
diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index c65dfb91f3d..cd2ae1dc8e0 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -188,7 +188,7 @@ (define_predicate "vlogical_operand"

 ;; Return 1 if op is the carry register.
 (define_predicate "ca_operand"
-  (match_operand 0 "register_operand")
+  (match_operand 0 "any_operand")
 {
   if (SUBREG_P (op))
 op = SUBREG_REG (op);
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 6ecb0bd6142..f1b09aad3b5 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -2358,6 +2358,21 @@ (define_insn "subf3_carry_in_xx"
   "subfe %0,%0,%0"
   [(set_attr "type" "add")])

+(define_insn_and_split "*extenddi_ca_minus_one"
+  [(set (match_operand:DI 0 "gpc_reg_operand")
+   (sign_extend:DI (plus:SI (match_operand:SI 1 "ca_operand")
+(const_int -1]
+  ""
+  "#"
+  ""
+  [(parallel [(set (match_dup 0)
+  (plus:DI (match_dup 2)
+   (const_int -1)))
+ (clobber (match_dup 2))])]
+{
+  operands[2] = copy_rtx (operands[1]);
+  PUT_MODE (operands[2], DImode);
+})

 (define_insn "@neg2"
   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c 
b/gcc/testsuite/gcc.target/powerpc/pr95737.c
new file mode 100644
index 000..94320f23423
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c
@@ -0,0 +1,10 @@
+/* PR target/95737 */
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-O2 -mdejagnu-cpu=power8" } */
+/* { dg-final { scan-assembler-not {\mextsw\M} } } */
+
+
+unsigned long long negativeLessThan (unsigned long long a, unsigned long long 
b)
+{
+   return -(a < b);
+}


Re: [PATCH] powerc: Fix asm machine directive for some CPUs

2022-01-18 Thread Sebastian Huber

On 18/01/2022 22:42, Segher Boessenkool wrote:

+default:
+  break;

Please don't do that.  You can do

   default:
 break;
 break;
 /* And just to make sure:  */
 break;
 break;

and it will do exactly the same as not having a default at all.  Not
having such useless code is by far the most readable, so please don't
include a default case at all.


I removed the default case. I hope this is what you wanted.



Okay with those changes.  Thanks!


Thanks for having a look at this. I would like to back port this patch 
also to the GCC 10 and 11 branches.


--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


[PATCH][pushed] testsuite: fix pytest detection unsupported message.

2022-01-18 Thread Martin Liška

PR testsuite/104109

gcc/testsuite/ChangeLog:

* lib/gcov.exp: Fix pytest detection unsupported message.
---
 gcc/testsuite/lib/gcov.exp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/lib/gcov.exp b/gcc/testsuite/lib/gcov.exp
index 6c57515e229..9d5b2cdb86b 100644
--- a/gcc/testsuite/lib/gcov.exp
+++ b/gcc/testsuite/lib/gcov.exp
@@ -276,14 +276,13 @@ proc run-gcov-pytest { args } {
 set testcase [remote_download host $testcase]
 set result [remote_exec host $GCOV "$testcase -i"]
 
+set pytest_script [lindex $args 1]

 if { ![check_effective_target_pytest3] } {
-  unsupported "$script pytest python3 is missing"
+  unsupported "$pytest_script pytest python3 is missing"
   return
 }
 
-set pytest_script [lindex $args 1]

 setenv GCOV_PATH $testcase
-verbose "pytest_script: $srcdir $subdir $pytest_script" 2
 spawn -noecho python3 -m pytest --color=no -rap -s --tb=no 
$srcdir/$subdir/$pytest_script
 
 set prefix "\[^\r\n\]*"

--
2.34.1



PING^1 [PATCH v3] rs6000: Fix some issues in rs6000_can_inline_p [PR102059]

2022-01-18 Thread Kewen.Lin via Gcc-patches
Gentle ping this:

https://gcc.gnu.org/pipermail/gcc-patches/2022-January/587635.html

BR,
Kewen

on 2022/1/5 下午3:34, Kewen.Lin via Gcc-patches wrote:
> Hi,
> 
> This patch is to fix the inconsistent behaviors for non-LTO mode
> and LTO mode.  As Martin pointed out, currently the function
> rs6000_can_inline_p simply makes it inlinable if callee_tree is
> NULL, but it's unexpected, we should use the command line options
> from target_option_default_node as default.
> 
> It replaces rs6000_isa_flags with target_option_default_node when
> caller_tree is NULL since it's more straightforward and doesn't
> suffer from some bug not to keep rs6000_isa_flags as default.
> 
> It also extends the scope of the check for the case that callee
> has explicit set options, inlining in test case pr102059-5.c can
> happen unexpectedly before, it's fixed accordingly.
> 
> As Richi/Mike pointed out, some tuning flags like MASK_P8_FUSION
> can be neglected for always inlining, this patch also takes some
> flags when the callee is attributed by always_inline.
> 
> v1: https://gcc.gnu.org/pipermail/gcc-patches/2021-September/578552.html
> v2: https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586112.html
> 
> This patch is one re-post of this updated version[1] and also
> rebased and adjusted on top of the related commit r12-6219.
> 
> Bootstrapped and regtested on powerpc64-linux-gnu P8 and
> powerpc64le-linux-gnu P9 and P10.
> 
> Is it ok for trunk?
> 
> [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586296.html
> 
> BR,
> Kewen
> -
> gcc/ChangeLog:
> 
>   PR target/102059
>   * config/rs6000/rs6000.c (rs6000_can_inline_p): Adjust with
>   target_option_default_node and consider always_inline_safe flags.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR target/102059
>   * gcc.target/powerpc/pr102059-4.c: New test.
>   * gcc.target/powerpc/pr102059-5.c: New test.
>   * gcc.target/powerpc/pr102059-6.c: New test.
>   * gcc.target/powerpc/pr102059-7.c: New test.
>   * gcc.target/powerpc/pr102059-8.c: New test.
>   * gcc.dg/lto/pr102059-1_0.c: Remove unneeded option.
> 
> 



[PATCH] Enhance vec_pack_trunc for integral mode mask.

2022-01-18 Thread liuhongt via Gcc-patches
> your description above hints at that the actual modes involved in the
> vec_pack_sbool_trunc are the same so the TYPE_MODE (narrow_vectype)
> and TYPE_MODE (vectype) are not the actual modes participating.  I think
> it would be way better to fix that.
>
> I suppose that since we know TYPE_VECTOR_SUBPARTS is a power of two
> it's always going to be only QImode that is of interest here so maybe a better
> check would be TYPE_MODE (narrow_vectype) == QImode rather than
> the equality check or elide the mode check completely and only retain
> the TYPE_VECTOR_SUBPARTS check you add?
>
> > optab1 = vec_pack_sbool_trunc_optab;
> >else
> > optab1 = optab_for_tree_code (c1, vectype, optab_default);
> > @@ -12213,7 +12216,9 @@ supportable_narrowing_operation (enum tree_code 
> > code,
> >if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
> >   && VECTOR_BOOLEAN_TYPE_P (prev_type)
> >   && intermediate_mode == prev_mode
>
> Likewise here.
>
> So I think the change is OK if you remove the mode equality checks.

Thanks for the review, here is updated patch, it survived bootstrap and regtest.
I'm going to check in the patch if there's no surprise for SPEC2017 on ICX.

For testcase in PR, the patch supports QI:4 -> HI:16 pack with
multi steps(first pack QI:4 -> QI:8 through vec_pack_sbool_trunc_qi,
then pack QI:8 -> HI:16 through vec_pack_trunc_hi).
Similar for QI:2 -> HI:16 which is test4 in mask-pack-prefer-128.c.

gcc/ChangeLog:

PR target/103771
* tree-vect-stmts.c (supportable_narrowing_operation): Enhance
integral mode mask pack by multi steps which takes
vec_pack_sbool_trunc_optab as start when elements number is
less than BITS_PER_UNITS.

gcc/testsuite/ChangeLog:

* gcc.target/i386/mask-pack-prefer128.c: New test.
* gcc.target/i386/mask-pack-prefer128.c: New test.
* gcc.target/i386/pr103771.c: New test.
---
 .../gcc.target/i386/mask-pack-prefer128.c  |  8 
 .../gcc.target/i386/mask-pack-prefer256.c  |  8 
 gcc/testsuite/gcc.target/i386/pr103771.c   | 18 ++
 gcc/tree-vect-stmts.cc | 11 +++
 4 files changed, 41 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/mask-pack-prefer128.c
 create mode 100644 gcc/testsuite/gcc.target/i386/mask-pack-prefer256.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr103771.c

diff --git a/gcc/testsuite/gcc.target/i386/mask-pack-prefer128.c 
b/gcc/testsuite/gcc.target/i386/mask-pack-prefer128.c
new file mode 100644
index 000..c9ea37c7ed3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mask-pack-prefer128.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-march=skylake-avx512 -O3 -fopenmp-simd 
-fdump-tree-vect-details -mprefer-vector-width=128" } */
+/* Disabling epilogues until we find a better way to deal with scans.  */
+/* { dg-additional-options "--param vect-epilogues-nomask=0" } */
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 10 "vect" } } */
+/* { dg-final { scan-assembler-not "maskmov" } } */
+
+#include "mask-pack.c"
diff --git a/gcc/testsuite/gcc.target/i386/mask-pack-prefer256.c 
b/gcc/testsuite/gcc.target/i386/mask-pack-prefer256.c
new file mode 100644
index 000..841f51b4041
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mask-pack-prefer256.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-march=skylake-avx512 -O3 -fopenmp-simd 
-fdump-tree-vect-details -mprefer-vector-width=256" } */
+/* Disabling epilogues until we find a better way to deal with scans.  */
+/* { dg-additional-options "--param vect-epilogues-nomask=0" } */
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 10 "vect" } } */
+/* { dg-final { scan-assembler-not "maskmov" } } */
+
+#include "mask-pack.c"
diff --git a/gcc/testsuite/gcc.target/i386/pr103771.c 
b/gcc/testsuite/gcc.target/i386/pr103771.c
new file mode 100644
index 000..a1a9952b6a8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr103771.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-march=cascadelake -O3 -fdump-tree-vect-details 
-mprefer-vector-width=128" } */
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */
+
+typedef unsigned char uint8_t;
+
+static uint8_t x264_clip_uint8 (int x)
+{
+  return x & (~255) ? (-x) >> 31 : x;
+}
+
+void
+mc_weight (uint8_t* __restrict dst, uint8_t* __restrict src,
+  int i_width,int i_scale)
+{
+  for(int x = 0; x < i_width; x++)
+dst[x] = x264_clip_uint8 (src[x] * i_scale);
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 95be4f38eea..824ebb6354b 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -12124,6 +12124,7 @@ supportable_narrowing_operation (enum tree_code code,
   tree intermediate_type, prev_type;
   machine_mode intermediate_mode, prev_mode;
   int i;
+  unsigned HOST_WIDE_INT n_elts;
   bool uns;
 
   *multi_step_cvt 

Re: [PATCH] gimple-ssa-warn-access: Fix up asan_test.C -Wdangling-pointer regression [PR104103]

2022-01-18 Thread Richard Biener via Gcc-patches



> Am 19.01.2022 um 01:04 schrieb Martin Sebor via Gcc-patches 
> :
> 
> On 1/18/22 16:56, Jakub Jelinek wrote:
>> Hi!
>> As reported in the PR or as I've seen since the weekend, asan_test.C fails
>> because of many warnings like:
>> /home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1157:10: error: 
>> using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
>> /home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1157:10: error: 
>> using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
>> /home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1162:27: error: 
>> using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
>> ...
>> (lots of them).
>> There are no dangling pointers though, the warning pass sees:
>>   some_automatic_var ={v} {CLOBBER};
>>   .ASAN_MARK (POISON, _automatic_var, 8);
>> and warns on that (both on user vars and on e.g. TARGET_EXPR temporaries).
>> There is nothing wrong on that, .ASAN_MARK is compiler instrumentation,
>> which doesn't even touch the variable in any way nor make it escaped.
>> What it instead does is change bytes in the shadow memory corresponding
>> to the variable to reflect that the variable is out of scope and make
>> sure that access to it would be diagnosed at runtime.
>> So, for all purposes of the -Wdangling-pointer and -Wuse-after-free
>> warnings, we should ignore this internal call.
>> Bootstrapped/regtested on x86_64-linux and i686-linux, fixes asan_test.C
>> FAIL (so no new test has been added), ok for trunk?

Ok.

Richard 

> This is in line with what's done for -Wmaybe-uninitialized so it makes
> sense to do it here as well.  -Wmaybe-uninitialized also exempts calls
> to sanitizer built-ins from checking.  I don't know if they might come
> up here but if it can't be ruled out, moving the code from
> tree-ssa-uninit.cc into a utility helper and calling it from both
> places might be a good idea.
> 
> Martin
> 
>> 2022-01-18  Jakub Jelinek  
>>PR middle-end/104103
>>* gimple-ssa-warn-access.cc (pass_waccess::check_call): Don't check
>>.ASAN_MARK calls.
>> --- gcc/gimple-ssa-warn-access.cc.jj2022-01-16 20:55:46.783932110 +0100
>> +++ gcc/gimple-ssa-warn-access.cc2022-01-18 20:56:13.697780325 +0100
>> @@ -4232,6 +4232,11 @@ pass_waccess::check_call (gcall *stmt)
>>if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
>>  check_builtin (stmt);
>>  +  /* .ASAN_MARK doesn't access any vars, only modifies shadow memory.  */
>> +  if (gimple_call_internal_p (stmt)
>> +  && gimple_call_internal_fn (stmt) == IFN_ASAN_MARK)
>> +return;
>> +
>>if (!m_early_checks_p)
>>  if (tree callee = gimple_call_fndecl (stmt))
>>{
>>Jakub
> 


Re: [PATCH] fold-const: Optimize &"foo"[0] == "foo" [PR89074]

2022-01-18 Thread Richard Biener via Gcc-patches



> Am 19.01.2022 um 00:50 schrieb Jakub Jelinek via Gcc-patches 
> :
> 
> Hi!
> 
> This is a non-C++ related part from the PR89074 address_compare changes.
> For "foo" == "foo" we already optimize this from the (cmp @0 @0)
> simplification, because we use operand_equal_p in that case
> and operand_equal_p also compares the STRING_CSTs bytes rather than
> just addresses.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard 


> 2022-01-18  Jakub Jelinek  
> 
>PR c++/89074
>* fold-const.cc (address_compare): Consider different STRING_CSTs
>with the same lengths that memcmp the same as equal, not different.
> 
>* gcc.dg/tree-ssa/pr89074.c: New test.
> 
> --- gcc/fold-const.cc.jj2022-01-18 13:25:08.057491249 +0100
> +++ gcc/fold-const.cc2022-01-18 13:53:26.106261913 +0100
> @@ -16587,6 +16587,15 @@ address_compare (tree_code code, tree ty
>   || TREE_CODE (base1) == SSA_NAME
>   || TREE_CODE (base1) == STRING_CST))
> equal = (base0 == base1);
> +  /* Assume different STRING_CSTs with the same content will be
> + merged.  */
> +  if (equal == 0
> +  && TREE_CODE (base0) == STRING_CST
> +  && TREE_CODE (base1) == STRING_CST
> +  && TREE_STRING_LENGTH (base0) == TREE_STRING_LENGTH (base1)
> +  && memcmp (TREE_STRING_POINTER (base0), TREE_STRING_POINTER (base1),
> + TREE_STRING_LENGTH (base0)) == 0)
> +equal = 1;
>   if (equal == 1)
> {
>   if (code == EQ_EXPR
> --- gcc/testsuite/gcc.dg/tree-ssa/pr89074.c.jj2022-01-18 
> 18:42:05.125004996 +0100
> +++ gcc/testsuite/gcc.dg/tree-ssa/pr89074.c2022-01-18 18:43:39.249694890 
> +0100
> @@ -0,0 +1,12 @@
> +/* PR c++/89074 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +/* { dg-final { scan-tree-dump "return 1;" "optimized" } } */
> +
> +int
> +foo (void)
> +{
> +  const char *a = &"foo"[0];
> +  const char *b = "foo";
> +  return a == b;
> +}
> 
>Jakub
> 


Re: [PATCH] testsuite: Adjust possibly fragile slp-perm-9.c [PR104015]

2022-01-18 Thread Kewen.Lin via Gcc-patches
on 2022/1/19 上午5:34, Segher Boessenkool wrote:
> On Tue, Jan 18, 2022 at 11:57:32AM +, Richard Sandiford wrote:
>> "Kewen.Lin"  writes:
PR tree-optimization/104015
* gcc.dg/vect/slp-perm-9.c: Adjust.
* gcc.target/powerpc/pr104015-1.c: New test.
* gcc.target/powerpc/pr104015-2.c: New test.
> 
>> OK for the target-independent part, thanks.  IMO it's OK independently
>> of the rs6000 tests.
> 
> The rs6000 parts are fine as well.  Thanks!
> 
> I see you got rid of the ilp32 tests, I was going to holler about that,
> there is no reason this should only work (or only be tested) on 64-bit
> systems :-)
> 

Thanks Richard and Segher, committed as r12-6717.

BR,
Kewen


RE: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows

2022-01-18 Thread Sundeep KOKKONDA via Gcc-patches
Hello Andrew,

I updated the patch. Please see attached patch files and let me know your 
feedback.



Thanks,
Sundeep K.

-Original Message-
From: Andrew Pinski  
Sent: Tuesday, January 18, 2022 9:22 AM
To: sundeep.kokko...@gmail.com
Cc: GCC Patches 
Subject: Re: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in 
Windows

On Mon, Jan 17, 2022 at 8:35 AM Sundeep KOKKONDA via Gcc-patches 
 wrote:
>
> Hello,
>
>
>
> The '-MF' option cannot deal with path size >256 characters in 
> Windows. This patch is to fix this long path issue with -MF option.
>
> Let me know is it ok to commit?

I don't think this is the right place to put this.
Maybe a better way to implement this is to have a wrapper around fopen for 
windows and do it that way.
Does open have the same issue?

Thanks,
Andrew Pinski

>
>
>
>
>
> --
>
> Thanks,
>
> Sundeep K.
>


lrealpath.patch
Description: Binary data


c-opts.patch
Description: Binary data


[r12-6704 Regression] FAIL: g++.target/i386/pr98218-1.C -std=gnu++20 scan-assembler-times pcmpgtd 2 on Linux/x86_64

2022-01-18 Thread sunil.k.pandey via Gcc-patches
On Linux/x86_64,

fdd6d85bd75df9a97659220373b5c1e8b3019e26 is the first bad commit
commit fdd6d85bd75df9a97659220373b5c1e8b3019e26
Author: Jason Merrill 
Date:   Tue Jan 18 17:43:03 2022 -0500

c++: Use -std=c++20 in testsuite default std list

caused

FAIL: g++.dg/cpp0x/constexpr-compare2.C  -std=c++14 (test for excess errors)
FAIL: g++.dg/cpp0x/constexpr-compare2.C  -std=c++17 (test for excess errors)
FAIL: g++.dg/cpp0x/constexpr-compare2.C  -std=c++20 (test for excess errors)
FAIL: g++.dg/opt/pr91838.C  -std=c++14  scan-assembler pxor\\s+%xmm0,\\s+%xmm0
FAIL: g++.dg/opt/pr91838.C  -std=c++17  scan-assembler pxor\\s+%xmm0,\\s+%xmm0
FAIL: g++.dg/opt/pr91838.C  -std=c++20  scan-assembler pxor\\s+%xmm0,\\s+%xmm0
FAIL: g++.dg/vect/simd-bool-comparison-1.cc  -std=c++14  scan-tree-dump-times 
vect "vectorized 1 loops" 1
FAIL: g++.dg/vect/simd-bool-comparison-1.cc  -std=c++17  scan-tree-dump-times 
vect "vectorized 1 loops" 1
FAIL: g++.dg/vect/simd-bool-comparison-1.cc  -std=c++20  scan-tree-dump-times 
vect "vectorized 1 loops" 1
FAIL: g++.dg/vect/simd-bool-comparison-1.cc  -std=c++98  scan-tree-dump-times 
vect "vectorized 1 loops" 1
FAIL: g++.dg/vect/slp-pr87105.cc  -std=c++14  scan-tree-dump-times slp2 "basic 
block part vectorized" 1
FAIL: g++.dg/vect/slp-pr87105.cc  -std=c++17  scan-tree-dump-times slp2 "basic 
block part vectorized" 1
FAIL: g++.dg/vect/slp-pr87105.cc  -std=c++20  scan-tree-dump-times slp2 "basic 
block part vectorized" 1
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 10)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 11)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 12)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 13)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 14)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 15)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 16)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 17)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 18)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 19)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 4)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 5)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 6)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 7)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 8)
FAIL: g++.target/i386/mv28.C  -std=c++14  (test for errors, line 9)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 10)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 11)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 12)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 13)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 14)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 15)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 16)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 17)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 18)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 19)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 4)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 5)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 6)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 7)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 8)
FAIL: g++.target/i386/mv28.C  -std=c++17  (test for errors, line 9)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 10)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 11)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 12)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 13)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 14)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 15)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 16)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 17)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 18)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 19)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 4)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 5)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 6)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 7)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 8)
FAIL: g++.target/i386/mv28.C  -std=c++20  (test for errors, line 9)
FAIL: g++.target/i386/mv28.C  -std=c++98  (test for errors, line 10)
FAIL: g++.target/i386/mv28.C  -std=c++98  (test for errors, line 11)
FAIL: g++.target/i386/mv28.C  -std=c++98  (test for errors, line 12)
FAIL: g++.target/i386/mv28.C  

[r12-6703 Regression] FAIL: g++.dg/warn/pr104025.C -std=gnu++98 (test for excess errors) on Linux/x86_64

2022-01-18 Thread sunil.k.pandey via Gcc-patches
On Linux/x86_64,

2aa184458a11a7ec8c1b451b8eeff458a24632bb is the first bad commit
commit 2aa184458a11a7ec8c1b451b8eeff458a24632bb
Author: Jason Merrill 
Date:   Mon Jan 17 17:16:38 2022 -0500

c++: input_location and lookahead [PR104025]

caused

FAIL: g++.dg/warn/pr104025.C  -std=gnu++14 (test for excess errors)
FAIL: g++.dg/warn/pr104025.C  -std=gnu++17 (test for excess errors)
FAIL: g++.dg/warn/pr104025.C  -std=gnu++2a (test for excess errors)
FAIL: g++.dg/warn/pr104025.C  -std=gnu++98 (test for excess errors)

with GCC configured with

../../gcc/configure 
--prefix=/local/skpandey/gccwork/toolwork/gcc-bisect-master/master/r12-6703/usr 
--enable-clocale=gnu --with-system-zlib --with-demangler-in-ld 
--with-fpmath=sse --enable-languages=c,c++,fortran --enable-cet --without-isl 
--enable-libmpx x86_64-linux --disable-bootstrap

To reproduce:

$ cd {build_dir}/gcc && make check RUNTESTFLAGS="dg.exp=g++.dg/warn/pr104025.C 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check RUNTESTFLAGS="dg.exp=g++.dg/warn/pr104025.C 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check RUNTESTFLAGS="dg.exp=g++.dg/warn/pr104025.C 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check RUNTESTFLAGS="dg.exp=g++.dg/warn/pr104025.C 
--target_board='unix{-m64\ -march=cascadelake}'"

(Please do not reply to this email, for question about this report, contact me 
at skpgkp2 at gmail dot com)


Re: [pushed] c++: input_location and lookahead [PR104025]

2022-01-18 Thread Jason Merrill via Gcc-patches

On 1/18/22 18:20, Jakub Jelinek wrote:

On Tue, Jan 18, 2022 at 05:56:47PM -0500, Jason Merrill wrote:

Debug information was getting confused because input_location was different
depending on whether we had looked ahead to see if the next tokens look like
a template argument list.

I tried resetting input_location in cp_lexer_rollback_tokens itself, but
that caused regressions, so let's just do it here for now.

Tested x86_64-pc-linux-gnu, applying to trunk.

PR c++/104025

gcc/cp/ChangeLog:

* parser.cc (saved_token_sentinel::rollback): Call
cp_lexer_set_source_position.
(~saved_token_sentinel): Call rollback.

gcc/testsuite/ChangeLog:

* g++.dg/warn/pr104025.C: New test.


The testcase fails for me with this change.


Oops, thanks.  Fixed thus:

From bd0ef3534816a1b8ffad544d9ed720690a97d7cc Mon Sep 17 00:00:00 2001
From: Jason Merrill 
Date: Tue, 18 Jan 2022 22:11:56 -0500
Subject: [PATCH] c++: fix PR104025 change
To: gcc-patches@gcc.gnu.org

Somehow I pushed my earlier patch without it actually fixing the test; we
need input_location to be for the last consumed token, not the next one.

gcc/cp/ChangeLog:

	* parser.cc (saved_token_sentinel::rollback): Use
	cp_lexer_previous_token.
---
 gcc/cp/parser.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 60d9f7bb723..00279c43404 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -1308,7 +1308,8 @@ struct saved_token_sentinel
   void rollback ()
   {
 cp_lexer_rollback_tokens (lexer);
-cp_lexer_set_source_position (lexer);
+cp_lexer_set_source_position_from_token
+  (cp_lexer_previous_token (lexer));
 mode = STS_DONOTHING;
   }
   ~saved_token_sentinel ()
-- 
2.27.0



Re: [PATCH] RISC-V: Document the degree of position independence that medany affords

2022-01-18 Thread Kito Cheng via Gcc-patches
LGTM, thanks for adding those comments :)

On Wed, Jan 19, 2022 at 1:21 AM Palmer Dabbelt  wrote:
>
> The code generated by -mcmodel=medany is defined to be
> position-independent, but is not guaranteed to function correctly when
> linked into position-independent executables or libraries.  See the
> recent discussion at the psABI specification [1] for more details.
>
> It would be better to reject these invalid sequences when linking, but
> as pointed out in a recent LD bug [2] there may be some compatibility
> issues related to the PCREL_HI20 relocations used to initialize GP.
> Given the complexity here it's unlikely we'll be able to reject these
> sequences any time soon, so instead just document that these may not
> work.
>
> [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/245
> [2]: https://sourceware.org/bugzilla/show_bug.cgi?id=28789
>
> gcc/ChangeLog:
>
> * doc/invoke.texi: Document the degree of position independence
> that -mcmodel=medany affords.
>
> Signed-off-by: Palmer Dabbelt 
>
> ---
>
> Changes since v1:
>
> * Fix spelling of "guaranteed", twice.
> * Reference the binutils bug on rejecting these sequences, for more
>   context.
> ---
>  gcc/doc/invoke.texi | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 5504971ea81..7bca621535f 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -27568,6 +27568,10 @@ Generate code for the medium-any code model. The 
> program and its statically
>  defined symbols must be within any single 2 GiB address range. Programs can 
> be
>  statically or dynamically linked.
>
> +The code generated by the medium-any code model is position-independent, but 
> is
> +not guaranteed to function correctly when linked into position-independent
> +executables or libraries.
> +
>  @item -mexplicit-relocs
>  @itemx -mno-exlicit-relocs
>  Use or do not use assembler relocation operators when dealing with symbolic
> --
> 2.32.0
>


[PING^3][PATCH,v2,1/1,AARCH64][PR102768] aarch64: Add compiler support for Shadow Call Stack

2022-01-18 Thread Dan Li via Gcc-patches

Gentile ping for this again.
Could someone please give me a quick reply first? :), thanks.

Link: https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586204.html


Shadow Call Stack can be used to protect the return address of a
function at runtime, and clang already supports this feature[1].

To enable SCS in user mode, in addition to compiler, other support
is also required (as discussed in [2]). This patch only adds basic
support for SCS from the compiler side, and provides convenience
for users to enable SCS.

For linux kernel, only the support of the compiler is required.

[1] https://clang.llvm.org/docs/ShadowCallStack.html
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102768


Signed-off-by: Dan Li 

gcc/c-family/ChangeLog:

* c-attribs.c (handle_no_sanitize_shadow_call_stack_attribute):
New.

gcc/ChangeLog:

* config/aarch64/aarch64-protos.h (aarch64_shadow_call_stack_enabled):
New decl.
* config/aarch64/aarch64.c (aarch64_shadow_call_stack_enabled):
New.
(aarch64_expand_prologue):  Push x30 onto SCS before it's
pushed onto stack.
(aarch64_expand_epilogue):  Pop x30 frome SCS.
* config/aarch64/aarch64.h (TARGET_SUPPORT_SHADOW_CALL_STACK):
New macro.
(TARGET_CHECK_SCS_RESERVED_REGISTER):   Likewise.
* config/aarch64/aarch64.md (scs_push): New template.
(scs_pop):  Likewise.
* defaults.h (TARGET_SUPPORT_SHADOW_CALL_STACK):New macro.
* doc/extend.texi:  Document -fsanitize=shadow-call-stack.
* doc/invoke.texi:  Document attribute.
* flag-types.h (enum sanitize_code):Add
SANITIZE_SHADOW_CALL_STACK.
* opts-global.c (handle_common_deferred_options):   Add SCS
compile option check.
* opts.c (finish_options):  Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/shadow_call_stack_1.c: New test.
* gcc.target/aarch64/shadow_call_stack_2.c: New test.
* gcc.target/aarch64/shadow_call_stack_3.c: New test.
* gcc.target/aarch64/shadow_call_stack_4.c: New test.
---
 gcc/c-family/c-attribs.c  | 21 +
 gcc/config/aarch64/aarch64-protos.h   |  1 +
 gcc/config/aarch64/aarch64.c  | 27 +++
 gcc/config/aarch64/aarch64.h  | 11 +
 gcc/config/aarch64/aarch64.md | 18 
 gcc/defaults.h|  4 ++
 gcc/doc/extend.texi   |  7 +++
 gcc/doc/invoke.texi   | 29 
 gcc/flag-types.h  |  2 +
 gcc/opts-global.c |  6 +++
 gcc/opts.c| 12 +
 .../gcc.target/aarch64/shadow_call_stack_1.c  |  6 +++
 .../gcc.target/aarch64/shadow_call_stack_2.c  |  6 +++
 .../gcc.target/aarch64/shadow_call_stack_3.c  | 45 +++
 .../gcc.target/aarch64/shadow_call_stack_4.c  | 18 
 15 files changed, 213 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/shadow_call_stack_1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/shadow_call_stack_2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/shadow_call_stack_3.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/shadow_call_stack_4.c

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 007b928c54b..9b3a35c06bf 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -56,6 +56,8 @@ static tree handle_cold_attribute (tree *, tree, tree, int, 
bool *);
 static tree handle_no_sanitize_attribute (tree *, tree, tree, int, bool *);
 static tree handle_no_sanitize_address_attribute (tree *, tree, tree,
  int, bool *);
+static tree handle_no_sanitize_shadow_call_stack_attribute (tree *, tree,
+ tree, int, bool *);
 static tree handle_no_sanitize_thread_attribute (tree *, tree, tree,
 int, bool *);
 static tree handle_no_address_safety_analysis_attribute (tree *, tree, tree,
@@ -454,6 +456,10 @@ const struct attribute_spec c_common_attribute_table[] =
  handle_no_sanitize_attribute, NULL },
   { "no_sanitize_address",0, 0, true, false, false, false,
  handle_no_sanitize_address_attribute, NULL },
+  { "no_sanitize_shadow_call_stack",
+ 0, 0, true, false, false, false,
+ handle_no_sanitize_shadow_call_stack_attribute,
+ NULL },
   { "no_sanitize_thread", 0, 0, true, false, false, false,
  handle_no_sanitize_thread_attribute, NULL },
   { "no_sanitize_undefined",  0, 0, true, false, false, false,
@@ -1175,6 +1181,21 @@ handle_no_sanitize_address_attribute (tree *node, tree 
name, tree, 

[PATCH 2/2] [Ada] Set target_cpu to x32 for x86_64-linux-gnux32

2022-01-18 Thread H.J. Lu via Gcc-patches
Since the x86_64-linux-gnux32 compiler is actually an x32 compiler, set
target_cpu to x32 for x86_64-linux-gnux32.

PR ada/103538
* gcc-interface/Makefile.in (target_cpu): Set to x32 for
x86_64-linux-gnux32.
---
 gcc/ada/gcc-interface/Makefile.in | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/ada/gcc-interface/Makefile.in 
b/gcc/ada/gcc-interface/Makefile.in
index 53d0739470a..b8a24708280 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -350,6 +350,13 @@ ifeq ($(strip $(filter-out x86_64, $(target_cpu))),)
   endif
 endif
 
+# The x86_64-linux-gnux32 compiler is actually an x32 compiler
+ifeq ($(strip $(filter-out x86_64 linux-gnux32%, $(target_cpu) $(target_os))),)
+  ifneq ($(strip $(MULTISUBDIR)),/64)
+target_cpu:=x32
+  endif
+endif
+
 # The SuSE PowerPC64/Linux compiler is actually a 32-bit PowerPC compiler
 ifeq ($(strip $(filter-out powerpc64 suse linux%, $(target_cpu) 
$(target_vendor) $(target_os))),)
   target_cpu:=powerpc
-- 
2.34.1



[PATCH 1/2] [Ada] Compile s-mmap and 128bit on x86_64-linux-gnux32

2022-01-18 Thread H.J. Lu via Gcc-patches
PR ada/103538
* Makefile.rtl (LIBGNAT_TARGET_PAIRS): Add
$(TRASYM_DWARF_UNIX_PAIRS),
s-tsmona.adb

Re: [PATCH] i386: Fix *aesu8

2022-01-18 Thread Hongtao Liu via Gcc-patches
On Wed, Jan 19, 2022 at 9:40 AM Jakub Jelinek  wrote:
>
> Hi!
>
> On Wed, Jan 19, 2022 at 09:09:41AM +0800, Hongtao Liu wrote:
> > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> > Yes, thanks.
>
> Thanks.  Committed.
> grep '{[^|}]*}"' *.md
>
> found another spot, though dunno if we have sufficient effective targets
> etc. to add an -masm=intel test for it (and my installed binutils doesn't
> support it anyway).
> Binutils trunk testsuite shows the argument isn't omitted even in the Intel
> syntax:
> grep aesencwide *.s
> keylocker.s:aesencwide128kl 126(%edx)
> keylocker.s:aesencwide256kl 126(%edx)
> keylocker.s:aesencwide128kl [edx+126]
> keylocker.s:aesencwide256kl [edx+126]
> property-10.s:   aesencwide128kl (%eax)
> x86-64-keylocker.s: aesencwide128kl 126(%rdx)
> x86-64-keylocker.s: aesencwide256kl 126(%rdx)
> x86-64-keylocker.s: aesencwide128kl [rdx+126]
> x86-64-keylocker.s: aesencwide256kl [rdx+126]
> and doesn't use any WHATEVER PTR.
>
> Ok for trunk?
Yes, thanks again.
>
> 2022-01-19  Jakub Jelinek  
>
> * config/i386/sse.md (*aesu*): Use %0 instead of
> {%0}.
>
> --- gcc/config/i386/sse.md.jj   2022-01-19 02:23:59.762022574 +0100
> +++ gcc/config/i386/sse.md  2022-01-19 02:32:07.953324150 +0100
> @@ -28437,7 +28437,7 @@ (define_insn "*aesu8"
> [(match_operand:BLK 0 "memory_operand" "m")]
> AESDECENCWIDEKL))])]
>"TARGET_WIDEKL"
> -  "aes\t{%0}"
> +  "aes\t%0"
>[(set_attr "type" "other")])
>
>  ;; Modes handled by broadcast patterns.  NB: Allow V64QI and V32HI with
>
>
> Jakub
>


-- 
BR,
Hongtao


[PATCH] i386: Fix *aesu8

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

On Wed, Jan 19, 2022 at 09:09:41AM +0800, Hongtao Liu wrote:
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> Yes, thanks.

Thanks.  Committed.
grep '{[^|}]*}"' *.md

found another spot, though dunno if we have sufficient effective targets
etc. to add an -masm=intel test for it (and my installed binutils doesn't
support it anyway).
Binutils trunk testsuite shows the argument isn't omitted even in the Intel
syntax:
grep aesencwide *.s
keylocker.s:aesencwide128kl 126(%edx)
keylocker.s:aesencwide256kl 126(%edx)
keylocker.s:aesencwide128kl [edx+126]
keylocker.s:aesencwide256kl [edx+126]
property-10.s:   aesencwide128kl (%eax)
x86-64-keylocker.s: aesencwide128kl 126(%rdx)
x86-64-keylocker.s: aesencwide256kl 126(%rdx)
x86-64-keylocker.s: aesencwide128kl [rdx+126]
x86-64-keylocker.s: aesencwide256kl [rdx+126]
and doesn't use any WHATEVER PTR.

Ok for trunk?

2022-01-19  Jakub Jelinek  

* config/i386/sse.md (*aesu*): Use %0 instead of
{%0}.

--- gcc/config/i386/sse.md.jj   2022-01-19 02:23:59.762022574 +0100
+++ gcc/config/i386/sse.md  2022-01-19 02:32:07.953324150 +0100
@@ -28437,7 +28437,7 @@ (define_insn "*aesu8"
[(match_operand:BLK 0 "memory_operand" "m")]
AESDECENCWIDEKL))])]
   "TARGET_WIDEKL"
-  "aes\t{%0}"
+  "aes\t%0"
   [(set_attr "type" "other")])
 
 ;; Modes handled by broadcast patterns.  NB: Allow V64QI and V32HI with


Jakub



[PATCH] tree-optimization/103721 - Only add equivalencies that are still valid.

2022-01-18 Thread Andrew MacLeod via Gcc-patches
This patch happens to fix the PR, but I believe it only papers over a 
deeper issue that is uncovered in PR104067.


That said, examination of the issue uncovered an oversight in the way 
equivalence sets are merged by the equivalence oracle.  I have not seen 
an instance via the ranger, but I suspect its just a matter of time.


Equivalences sets are added to the basic block in which they occur.   By 
default, the definition of an SSA_NAME create an equivalence in the DEF 
block containing just the name itself. Other equivalences are added as 
they are encountered in their respective basic blocks, and are created 
by combining whatever equivalence is active (via query) in that block 
with the new equivalence.  An equivalence introduced by an edge is 
currently only added the edge destination is a block with a single 
predecessor.  It is then added to that block.


When a query is made for the equivalence set for b_2 at BBx, a walk up 
the dominance tree is made looking for the first block which has an 
equivalence containing b_2.  This then becomes the equivalence set for 
B2 at BBx.


If this set contains f_8, before we know that f_8 and b_2 actually 
equivalent, we query the equivalence set of f_8 at BBx. If it comes back 
with the same set, then the 2 names are equivalent.  if the set is 
different, then they are not.


This allows us to register equivalences as we see them without worrying 
about invalidating other equivalences.  Rather, we defer validation 
until we actually care, and pay the cost at the query point.


This PR has exposed a flaw in how we register equivalence sets around 
back edges which could potentially show up somewhere.


searchvolume_5 was use in previous blocks along the back edge and has an 
equivalence set of {_5, world_7} in BB8


  # searchVolume_11 = PHI <1(4), 0(3)>  { _11 }
  # currentVolume_8 = searchVolume_5    { _5, _8 , world_7 }

  
  # searchVolume_5 = PHI     { _5, _11 }
  # currentVolume_6 = PHI 

When an equivalence is added for currentVolume_6, a query is made for 
the equivalence set for currentVolume_8, which returns the set  {_5, _8, 
world_7 }.   Currently, this is simply combined with {_6} via a bitwise 
OR to produce {_5, _6, _8, world_7 }.  This is incorrect as _5's 
equivalence set is now {_5, _11}.


_6 and _8 dont appear to be directly related to _5, so we were missing 
it.   What should be happening is when we merge the equivalence set for 
currentVolume_6 and  currentVolume_8, each member of the set should be 
verified by the same criteria the query uses... ie, ask for the equiv 
set for _5, _8, and world_7 at BB9, and if it is different than this 
set, it isn't added.


This would then create the correct equivalence set  { _6, _8, world_7 }, 
as the query for _5 would come back with {_5, _11} and not evaluate as 
equivalent.


And yes, PHIS all happen in parallel... We don't need to worry about 
ordering because even if the PHI hadn't been processed in this order, 
the definition would have provided a default of { _5 }, and thus still 
not been equivalent and still won't be added to the set.


Anyway, even tho I think there is an additional problem in this PR, I 
wanted to get approval and check this code in under this PR since it 
does need to be fixed, and was uncovered here.  We wont close the PR 
until we are sure the underlying issue is resolved.


I will also see if I can come up with some kind of test case in the 
meantime as well.


Bootstraps on x86_64-pc-linux-gnu with no regressions.   Overall compile 
time is very nominal.. less than a 0.1% impact on the EVRP/VRP passes, 
so the cost is miniscule.


OK for trunk?

Andrew
commit 100d007b7fdd00dfdf272a4b944832eb1df193bb
Author: Andrew MacLeod 
Date:   Tue Jan 18 12:42:02 2022 -0500

Only add equivalencies that are still valid.

When equivalencies sets are merged, each member of the set should be queried
to ensure its still valid rather than a bulk union.

* value-relation.cc (relation_oracle::valid_equivs): Query and add
if valid members of a set.
(equiv_oracle::register_equiv): Call valid_equivs rather than
bitmap direct operations.
(path_oracle::register_equiv): Ditto.
* value-relation.h (relation_oracle::valid_equivs): New prototype.

diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index 32ca693c464..0134e0328ba 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -188,6 +188,23 @@ relation_transitive (relation_kind r1, relation_kind r2)
   return rr_transitive_table[r1 - VREL_FIRST][r2 - VREL_FIRST];
 }
 
+// Given an equivalence set EQUIV, set all the bits in B that are still valid
+// members of EQUIV in basic block BB.
+
+void
+relation_oracle::valid_equivs (bitmap b, const_bitmap equivs, basic_block bb)
+{
+  unsigned i;
+  bitmap_iterator bi;
+  EXECUTE_IF_SET_IN_BITMAP (equivs, 0, i, bi)
+{
+  tree ssa = ssa_name (i);
+  const_bitmap ssa_equiv 

Re: [committed] libstdc++: Fix std::atomic> for AIX [PR104101]

2022-01-18 Thread Hans-Peter Nilsson via Gcc-patches
> From: Jonathan Wakely via Gcc-patches 
> Date: Wed, 19 Jan 2022 02:03:58 +0100

> Tested powerpc64le-linux, powerpc-aix, pushed to trunk.
> 
> 
> This fixes a testsuite failure

I'm guessing the actual number is in the tens.

> on AIX.

...and by the looks of it, some 60 regressions (as counted
by contrib/regression/btest-gcc.sh) on newlib targets too
for the same reason.

brgds, H-P


[committed] add test for PR104076

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

A -Wdangling-pointer false positive reported just the other day
on this list has disappeared after an unrelated change to
the gimplifier (r12-6694).  In r12-6714 I've committed the regression
test for it, though I'm not sure I see what the warning code could
have done to avoid the false positive.  Ideas are welcome.

Thanks
Martin


[committed] prune out expected warning [PR104103]

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

The regression test gcc.dg/torture/pr57147-2.c triggers a valid
warning by passing a variable with zero size to a function that
expects an array of size 1.  The recent change to run the access
pass also earlier in the optimization pipeline has triggered
this warning.  In r12-6713 I have committed a change to prune
the warning out.

https://gcc.gnu.org/g:282110ae8b54250c8dcb73afc6f30761a41e38e6

I saw the test failure in my build before committing the original
change but then couldn't reproduce it so I chalked it up to cosmic
rays without deeper investigation.  My bad.

Martin


Re: [PATCH] i386: Fix GLC tuning with -masm=intel [PR104104]

2022-01-18 Thread Hongtao Liu via Gcc-patches
On Wed, Jan 19, 2022 at 8:00 AM Jakub Jelinek  wrote:
>
> On Sun, Jan 16, 2022 at 12:22:18PM +0800, Hongtao Liu via Gcc-patches wrote:
> > On Sun, Jan 16, 2022 at 12:44 AM Uros Bizjak via Gcc-patches
> >  wrote:
> > >
> > > On Sat, Jan 15, 2022 at 5:39 PM Hongyu Wang  
> > > wrote:
> > > >
> > > > Thanks for the suggestion, here is the updated patch that survived
> > > > bootstrap/regtest.
> > >
> > > LGTM for me, but please get the final approval from Hongtao.
> > >
> > Ok, thanks.
>
> Unfortunately the patch results in assembler failures with -masm=intel.
>
> > > > > +  if (TARGET_DEST_FALSE_DEPENDENCY
> > > > > +  && get_attr_dest_false_dep (insn) ==
> > > > > +DEST_FALSE_DEP_TRUE)
> > > > > +output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
>
> All the vxorps insns were emitted like the above, which means for -masm=sysv
> it looks like
> vxorps  %xmm3, %xmm3, %xmm3
> but for -masm=intel like:
> vxorps
> We want obviously
> vxorps  xmm3, xmm3, xmm3
> so the following patch just drops the errorneous {}s.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Yes, thanks.
>
> 2022-01-19  Jakub Jelinek  
>
> PR target/104104
> * config/i386/sse.md
> (__,
> 
> avx512fp16_sh_v8hf,
> avx512dq_mul3, 
> _permvar,
> avx2_perm_1, avx512f_perm_1,
> avx512dq_rangep,
> avx512dq_ranges,
> _getmant,
> avx512f_vgetmant):
> Use vxorps\t%x0, %x0, %x0 instead of vxorps\t{%x0, %x0, %x0}.
>
> * gcc.target/i386/pr104104.c: New test.
>
> --- gcc/config/i386/sse.md.jj   2022-01-18 11:58:59.156988142 +0100
> +++ gcc/config/i386/sse.md  2022-01-18 21:20:40.02248 +0100
> @@ -6539,7 +6539,7 @@ (define_insn "__<
>  {
>if (TARGET_DEST_FALSE_DEP_FOR_GLC
>&& )
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "v\t{%2, %1, 
> %0|%0, %1, %2}";
>  }
>[(set_attr "type" "ssemul")
> @@ -6750,7 +6750,7 @@ (define_insn "avx512fp16_
>  {
>if (TARGET_DEST_FALSE_DEP_FOR_GLC
>&& )
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "vsh\t{%2, %1, 
> %0|%0, %1, 
> %2}";
>  }
>[(set_attr "type" "ssemul")
> @@ -15222,7 +15222,7 @@ (define_insn "avx512dq_mul3&& 
>&& !reg_mentioned_p (operands[0], operands[1])
>&& !reg_mentioned_p (operands[0], operands[2]))
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "vpmullq\t{%2, %1, %0|%0, %1, %2}";
>  }
>[(set_attr "type" "sseimul")
> @@ -24658,7 +24658,7 @@ (define_insn "_permvar&& 
>&& !reg_mentioned_p (operands[0], operands[1])
>&& !reg_mentioned_p (operands[0], operands[2]))
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "vperm\t{%1, %2, 
> %0|%0, %2, %1}";
>  }
>[(set_attr "type" "sselog")
> @@ -24900,7 +24900,7 @@ (define_insn "avx2_perm_1if (TARGET_DEST_FALSE_DEP_FOR_GLC
>&& 
>&& !reg_mentioned_p (operands[0], operands[1]))
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "vperm\t{%2, %1, 
> %0|%0, %1, %2}";
>  }
>[(set_attr "type" "sselog")
> @@ -24975,7 +24975,7 @@ (define_insn "avx512f_perm_1if (TARGET_DEST_FALSE_DEP_FOR_GLC
>&& 
>&& !reg_mentioned_p (operands[0], operands[1]))
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "vperm\t{%2, %1, 
> %0|%0, %1, %2}";
>  }
>[(set_attr "type" "sselog")
> @@ -26880,7 +26880,7 @@ (define_insn "avx512dq_rangep&& 
>&& !reg_mentioned_p (operands[0], operands[1])
>&& !reg_mentioned_p (operands[0], operands[2]))
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "vrange\t{%3, %2, %1, 
> %0|%0, %1, %2, %3}";
>  }
>[(set_attr "type" "sse")
> @@ -26903,7 +26903,7 @@ (define_insn "avx512dq_ranges&& 
>&& !reg_mentioned_p (operands[0], operands[1])
>&& !reg_mentioned_p (operands[0], operands[2]))
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "vrange\t{%3, 
> %2, %1, 
> %0|%0, %1, 
> %2, %3}";
>  }
>[(set_attr "type" "sse")
> @@ -26949,7 +26949,7 @@ (define_insn "_getmantif (TARGET_DEST_FALSE_DEP_FOR_GLC
>&& 
>&& MEM_P (operands[1]))
> -output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
> +output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
>return "vgetmant\t{%2, %1, 
> %0|%0, %1, %2}";
>  }
>[(set_attr 

[committed] fix a typo in pointer_related_p [PR104069]

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

The new pointer_related_p() utility function added for -Wuse-after-free
is documented to conservatively return false when it cannot determine
relatedness but actually returns true.  That has caused the false
positive reported in PR 104069.  In r12-6712 I've committed as obvious
a fix for this mistake along with a test case.

https://gcc.gnu.org/g:2f714642e574c64e1c0e093cad3de6f8accb6ec7

Martin


[committed] libstdc++: Update documentation for C++17 deprecations

2022-01-18 Thread Jonathan Wakely via Gcc-patches
Pushed to trunk.


libstdc++-v3/ChangeLog:

* doc/xml/manual/evolution.xml: Document deprecations.
* doc/xml/manual/status_cxx2017.xml: Update status.
* doc/html/*: Regenerate.
---
 libstdc++-v3/doc/html/manual/api.html  | 10 ++
 libstdc++-v3/doc/html/manual/status.html   |  4 ++--
 libstdc++-v3/doc/xml/manual/evolution.xml  | 14 ++
 libstdc++-v3/doc/xml/manual/status_cxx2017.xml |  3 +--
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/doc/xml/manual/evolution.xml 
b/libstdc++-v3/doc/xml/manual/evolution.xml
index 34e44ee93e4..f5bc6471465 100644
--- a/libstdc++-v3/doc/xml/manual/evolution.xml
+++ b/libstdc++-v3/doc/xml/manual/evolution.xml
@@ -1033,6 +1033,20 @@ accessors for the unexpected handler are deprecated for 
C++11 and later.
 Dynamic exception specifications should be replaced with noexcept.
 
 
+
+C++98 adaptable function utilities
+(std::bind1st, std::unary_function,
+std::ptr_fun, std::mem_fun_ref etc.)
+were deprecated for C++11.
+std::iterator, std::raw_storage_iterator,
+get_temporary_buffer, and std::not_fun
+were deprecated for C++17.
+
+
+
+Non-standard std::pair constructors were deprecated.
+
+
 
 The bitmap, mt, and 
pool
 options for --enable-libstdcxx-allocator were removed.
diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml 
b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
index 459bb13a629..3e11861c7bd 100644
--- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
+++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
@@ -265,14 +265,13 @@ Feature-testing recommendations for C++.
 
 
 
-  
Deprecating Vestigial Library Parts in C++17 
   
http://www.w3.org/1999/xlink; 
xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0174r2.html;>
P0174R2

   
-   No  (kept for backwards compatibility)
+   12.1 
   
 
 
-- 
2.31.1



[committed] libstdc++: Fix deprecated attribute for std::get_temporary_buffer

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


This was deprecated in C++17, not C++14.

libstdc++-v3/ChangeLog:

* include/bits/stl_tempbuf.h (get_temporary_buffer): Change
_GLIBCXX14_DEPRECATED to _GLIBCXX17_DEPRECATED.
---
 libstdc++-v3/include/bits/stl_tempbuf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_tempbuf.h 
b/libstdc++-v3/include/bits/stl_tempbuf.h
index 654c6a80747..db7cdb14ca9 100644
--- a/libstdc++-v3/include/bits/stl_tempbuf.h
+++ b/libstdc++-v3/include/bits/stl_tempbuf.h
@@ -96,7 +96,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Provides the nothrow exception guarantee.
*/
   template
-_GLIBCXX14_DEPRECATED
+_GLIBCXX17_DEPRECATED
 pair<_Tp*, ptrdiff_t>
 get_temporary_buffer(ptrdiff_t __len) _GLIBCXX_NOEXCEPT
 {
-- 
2.31.1



[committed] libstdc++: Remove unused std::pair helper function

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


This function is no longer used since r12-6691 and can be removed.

libstdc++-v3/ChangeLog:

* include/bits/stl_pair.h (_PCC::_DeprConsPair): Remove unused
function.
---
 libstdc++-v3/include/bits/stl_pair.h | 14 --
 1 file changed, 14 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_pair.h 
b/libstdc++-v3/include/bits/stl_pair.h
index 8564fd1ae9e..0eb78345ca4 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -128,20 +128,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __and_,
  is_convertible<_U2&&, _T2>>::value;
   }
-
-  template 
-  static constexpr bool _DeprConsPair()
-  {
-   using __do_converts = __and_,
-is_convertible<_U2&&, _T2>>;
-   using __converts = __conditional_t<__implicit,
-  __do_converts,
-  __not_<__do_converts>>;
-   return __and_,
- is_constructible<_T2, _U2&&>,
- __converts
->::value;
-  }
 };
 
   template 
-- 
2.31.1



[committed] libstdc++: Fix std::atomic> for AIX [PR104101]

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


This fixes a testsuite failure on AIX.

The lock function currently just spins, which should be changed to use
back-off, and maybe then _M_val.wait(__current) when supported.

libstdc++-v3/ChangeLog:

PR libstdc++/104101
* include/bits/shared_ptr_atomic.h (_Sp_atomic::_Atomic_count::lock):
Only use __thread_relax if __cpp_lib_atomic_wait is defined.
---
 libstdc++-v3/include/bits/shared_ptr_atomic.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h 
b/libstdc++-v3/include/bits/shared_ptr_atomic.h
index 50aa46370ca..35f781dc9a0 100644
--- a/libstdc++-v3/include/bits/shared_ptr_atomic.h
+++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h
@@ -392,7 +392,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  auto __current = _M_val.load(memory_order_relaxed);
  while (__current & _S_lock_bit)
{
+#if __cpp_lib_atomic_wait
  __detail::__thread_relax();
+#endif
  __current = _M_val.load(memory_order_relaxed);
}
 
@@ -401,7 +403,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 __o,
 memory_order_relaxed))
{
+#if __cpp_lib_atomic_wait
  __detail::__thread_relax();
+#endif
  __current = __current & ~_S_lock_bit;
}
  return reinterpret_cast(__current);
-- 
2.31.1



Re: [PATCH] i386: Fix GLC tuning with -masm=intel [PR104104]

2022-01-18 Thread Wang, Hongyu via Gcc-patches
Sorry for introducing such failure and thanks for the patch, I suppose it could 
be treated as obvious fix?

发件人: Jakub Jelinek 
发送时间: 星期三, 一月 19, 2022 8:01 上午
收件人: Hongtao Liu; Uros Bizjak
抄送: gcc-patches@gcc.gnu.org; Wang, Hongyu
主题: [PATCH] i386: Fix GLC tuning with -masm=intel [PR104104]

On Sun, Jan 16, 2022 at 12:22:18PM +0800, Hongtao Liu via Gcc-patches wrote:
> On Sun, Jan 16, 2022 at 12:44 AM Uros Bizjak via Gcc-patches
>  wrote:
> >
> > On Sat, Jan 15, 2022 at 5:39 PM Hongyu Wang  wrote:
> > >
> > > Thanks for the suggestion, here is the updated patch that survived
> > > bootstrap/regtest.
> >
> > LGTM for me, but please get the final approval from Hongtao.
> >
> Ok, thanks.

Unfortunately the patch results in assembler failures with -masm=intel.

> > > > +  if (TARGET_DEST_FALSE_DEPENDENCY
> > > > +  && get_attr_dest_false_dep (insn) ==
> > > > +DEST_FALSE_DEP_TRUE)
> > > > +output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);

All the vxorps insns were emitted like the above, which means for -masm=sysv
it looks like
vxorps  %xmm3, %xmm3, %xmm3
but for -masm=intel like:
vxorps
We want obviously
vxorps  xmm3, xmm3, xmm3
so the following patch just drops the errorneous {}s.

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

2022-01-19  Jakub Jelinek  

PR target/104104
* config/i386/sse.md
(__,

avx512fp16_sh_v8hf,
avx512dq_mul3, _permvar,
avx2_perm_1, avx512f_perm_1,
avx512dq_rangep,
avx512dq_ranges,
_getmant,
avx512f_vgetmant):
Use vxorps\t%x0, %x0, %x0 instead of vxorps\t{%x0, %x0, %x0}.

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

--- gcc/config/i386/sse.md.jj   2022-01-18 11:58:59.156988142 +0100
+++ gcc/config/i386/sse.md  2022-01-18 21:20:40.02248 +0100
@@ -6539,7 +6539,7 @@ (define_insn "__<
 {
   if (TARGET_DEST_FALSE_DEP_FOR_GLC
   && )
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "v\t{%2, %1, 
%0|%0, %1, %2}";
 }
   [(set_attr "type" "ssemul")
@@ -6750,7 +6750,7 @@ (define_insn "avx512fp16_
 {
   if (TARGET_DEST_FALSE_DEP_FOR_GLC
   && )
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vsh\t{%2, %1, 
%0|%0, %1, 
%2}";
 }
   [(set_attr "type" "ssemul")
@@ -15222,7 +15222,7 @@ (define_insn "avx512dq_mul3
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vpmullq\t{%2, %1, %0|%0, %1, %2}";
 }
   [(set_attr "type" "sseimul")
@@ -24658,7 +24658,7 @@ (define_insn "_permvar
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vperm\t{%1, %2, %0|%0, 
%2, %1}";
 }
   [(set_attr "type" "sselog")
@@ -24900,7 +24900,7 @@ (define_insn "avx2_perm_1
   && !reg_mentioned_p (operands[0], operands[1]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vperm\t{%2, %1, %0|%0, 
%1, %2}";
 }
   [(set_attr "type" "sselog")
@@ -24975,7 +24975,7 @@ (define_insn "avx512f_perm_1
   && !reg_mentioned_p (operands[0], operands[1]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vperm\t{%2, %1, 
%0|%0, %1, %2}";
 }
   [(set_attr "type" "sselog")
@@ -26880,7 +26880,7 @@ (define_insn "avx512dq_rangep
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vrange\t{%3, %2, %1, 
%0|%0, %1, %2, %3}";
 }
   [(set_attr "type" "sse")
@@ -26903,7 +26903,7 @@ (define_insn "avx512dq_ranges
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vrange\t{%3, %2, 
%1, %0|%0, %1, 
%2, %3}";
 }
   [(set_attr "type" "sse")
@@ -26949,7 +26949,7 @@ (define_insn "_getmant
   && MEM_P (operands[1]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vgetmant\t{%2, %1, 
%0|%0, %1, %2}";
 }
   [(set_attr "prefix" "evex")
@@ -26971,7 +26971,7 @@ (define_insn "avx512f_vgetmant
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn 

Re: [PATCH][pushed] Add check_effective_target_pytest3.

2022-01-18 Thread H.J. Lu via Gcc-patches
On Mon, Jan 17, 2022 at 2:29 AM Martin Liška  wrote:
>
> Hi.
>
> The patch is about factoring out a function similar to 
> check_effective_target_python3.
>
> Cheers,
> Martin
>
> gcc/testsuite/ChangeLog:
>
> * lib/gcov.exp: Use check_effective_target_pytest3.
> * lib/target-supports.exp: Add check_effective_target_pytest3.
> ---
>   gcc/testsuite/lib/gcov.exp|  9 -
>   gcc/testsuite/lib/target-supports.exp | 12 
>   2 files changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/testsuite/lib/gcov.exp b/gcc/testsuite/lib/gcov.exp
> index dfa1b3686ab..6c57515e229 100644
> --- a/gcc/testsuite/lib/gcov.exp
> +++ b/gcc/testsuite/lib/gcov.exp
> @@ -17,6 +17,8 @@
>   # Verify various kinds of gcov output: line counts, branch percentages,
>   # and call return percentages.  None of this is language-specific.
>
> +load_lib "target-supports.exp"
> +
>   global GCOV
>
>   #
> @@ -274,11 +276,8 @@ proc run-gcov-pytest { args } {
>   set testcase [remote_download host $testcase]
>   set result [remote_exec host $GCOV "$testcase -i"]
>
> -set pytest_cmd "python3 -m pytest --color=no -rap -s --tb=no"
> -set result [remote_exec host "$pytest_cmd --version"]
> -set status [lindex $result 0]
> -if { $status != 0 } then {
> -  unsupported "$subdir/$testcase run-gcov-pytest python3 pytest missing"
> +if { ![check_effective_target_pytest3] } {
> +  unsupported "$script pytest python3 is missing"
^

This caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104109

> return
>   }
>
> diff --git a/gcc/testsuite/lib/target-supports.exp 
> b/gcc/testsuite/lib/target-supports.exp
> index 12c5ca5da33..fd48475a57c 100644
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -11734,3 +11734,15 @@ proc check_effective_target_python3 { } {
>   return 0;
>   }
>   }
> +
> +# Return 1 if pytest module is available for python3.
> +
> +proc check_effective_target_pytest3 { } {
> +set result [remote_exec host "python3 -m pytest --color=no -rap -s 
> --tb=no --version"]
> +set status [lindex $result 0]
> +if { $status == 0 } then {
> +return 1;
> +} else {
> +return 0;
> +}
> +}
> --
> 2.34.1
>


-- 
H.J.


Re: [PATCH] gimple-ssa-warn-access: Fix up asan_test.C -Wdangling-pointer regression [PR104103]

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

On 1/18/22 16:56, Jakub Jelinek wrote:

Hi!

As reported in the PR or as I've seen since the weekend, asan_test.C fails
because of many warnings like:
/home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1157:10: error: 
using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
/home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1157:10: error: 
using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
/home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1162:27: error: 
using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
...
(lots of them).
There are no dangling pointers though, the warning pass sees:
   some_automatic_var ={v} {CLOBBER};
   .ASAN_MARK (POISON, _automatic_var, 8);
and warns on that (both on user vars and on e.g. TARGET_EXPR temporaries).
There is nothing wrong on that, .ASAN_MARK is compiler instrumentation,
which doesn't even touch the variable in any way nor make it escaped.
What it instead does is change bytes in the shadow memory corresponding
to the variable to reflect that the variable is out of scope and make
sure that access to it would be diagnosed at runtime.
So, for all purposes of the -Wdangling-pointer and -Wuse-after-free
warnings, we should ignore this internal call.

Bootstrapped/regtested on x86_64-linux and i686-linux, fixes asan_test.C
FAIL (so no new test has been added), ok for trunk?


This is in line with what's done for -Wmaybe-uninitialized so it makes
sense to do it here as well.  -Wmaybe-uninitialized also exempts calls
to sanitizer built-ins from checking.  I don't know if they might come
up here but if it can't be ruled out, moving the code from
tree-ssa-uninit.cc into a utility helper and calling it from both
places might be a good idea.

Martin



2022-01-18  Jakub Jelinek  

PR middle-end/104103
* gimple-ssa-warn-access.cc (pass_waccess::check_call): Don't check
.ASAN_MARK calls.

--- gcc/gimple-ssa-warn-access.cc.jj2022-01-16 20:55:46.783932110 +0100
+++ gcc/gimple-ssa-warn-access.cc   2022-01-18 20:56:13.697780325 +0100
@@ -4232,6 +4232,11 @@ pass_waccess::check_call (gcall *stmt)
if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
  check_builtin (stmt);
  
+  /* .ASAN_MARK doesn't access any vars, only modifies shadow memory.  */

+  if (gimple_call_internal_p (stmt)
+  && gimple_call_internal_fn (stmt) == IFN_ASAN_MARK)
+return;
+
if (!m_early_checks_p)
  if (tree callee = gimple_call_fndecl (stmt))
{

Jakub





[PATCH] i386: Fix GLC tuning with -masm=intel [PR104104]

2022-01-18 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 16, 2022 at 12:22:18PM +0800, Hongtao Liu via Gcc-patches wrote:
> On Sun, Jan 16, 2022 at 12:44 AM Uros Bizjak via Gcc-patches
>  wrote:
> >
> > On Sat, Jan 15, 2022 at 5:39 PM Hongyu Wang  wrote:
> > >
> > > Thanks for the suggestion, here is the updated patch that survived
> > > bootstrap/regtest.
> >
> > LGTM for me, but please get the final approval from Hongtao.
> >
> Ok, thanks.

Unfortunately the patch results in assembler failures with -masm=intel.

> > > > +  if (TARGET_DEST_FALSE_DEPENDENCY
> > > > +  && get_attr_dest_false_dep (insn) ==
> > > > +DEST_FALSE_DEP_TRUE)
> > > > +output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);

All the vxorps insns were emitted like the above, which means for -masm=sysv
it looks like
vxorps  %xmm3, %xmm3, %xmm3
but for -masm=intel like:
vxorps  
We want obviously
vxorps  xmm3, xmm3, xmm3
so the following patch just drops the errorneous {}s.

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

2022-01-19  Jakub Jelinek  

PR target/104104
* config/i386/sse.md
(__,

avx512fp16_sh_v8hf,
avx512dq_mul3, _permvar,
avx2_perm_1, avx512f_perm_1,
avx512dq_rangep,
avx512dq_ranges,
_getmant,
avx512f_vgetmant):
Use vxorps\t%x0, %x0, %x0 instead of vxorps\t{%x0, %x0, %x0}.

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

--- gcc/config/i386/sse.md.jj   2022-01-18 11:58:59.156988142 +0100
+++ gcc/config/i386/sse.md  2022-01-18 21:20:40.02248 +0100
@@ -6539,7 +6539,7 @@ (define_insn "__<
 {
   if (TARGET_DEST_FALSE_DEP_FOR_GLC
   && )
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "v\t{%2, %1, 
%0|%0, %1, %2}";
 }
   [(set_attr "type" "ssemul")
@@ -6750,7 +6750,7 @@ (define_insn "avx512fp16_
 {
   if (TARGET_DEST_FALSE_DEP_FOR_GLC
   && )
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vsh\t{%2, %1, 
%0|%0, %1, 
%2}";
 }
   [(set_attr "type" "ssemul")
@@ -15222,7 +15222,7 @@ (define_insn "avx512dq_mul3
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vpmullq\t{%2, %1, %0|%0, %1, %2}";
 }
   [(set_attr "type" "sseimul")
@@ -24658,7 +24658,7 @@ (define_insn "_permvar
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vperm\t{%1, %2, %0|%0, 
%2, %1}";
 }
   [(set_attr "type" "sselog")
@@ -24900,7 +24900,7 @@ (define_insn "avx2_perm_1
   && !reg_mentioned_p (operands[0], operands[1]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vperm\t{%2, %1, %0|%0, 
%1, %2}";
 }
   [(set_attr "type" "sselog")
@@ -24975,7 +24975,7 @@ (define_insn "avx512f_perm_1
   && !reg_mentioned_p (operands[0], operands[1]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vperm\t{%2, %1, 
%0|%0, %1, %2}";
 }
   [(set_attr "type" "sselog")
@@ -26880,7 +26880,7 @@ (define_insn "avx512dq_rangep
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vrange\t{%3, %2, %1, 
%0|%0, %1, %2, %3}";
 }
   [(set_attr "type" "sse")
@@ -26903,7 +26903,7 @@ (define_insn "avx512dq_ranges
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vrange\t{%3, %2, 
%1, %0|%0, %1, 
%2, %3}";
 }
   [(set_attr "type" "sse")
@@ -26949,7 +26949,7 @@ (define_insn "_getmant
   && MEM_P (operands[1]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vgetmant\t{%2, %1, 
%0|%0, %1, %2}";
 }
   [(set_attr "prefix" "evex")
@@ -26971,7 +26971,7 @@ (define_insn "avx512f_vgetmant
   && !reg_mentioned_p (operands[0], operands[1])
   && !reg_mentioned_p (operands[0], operands[2]))
-output_asm_insn ("vxorps\t{%x0, %x0, %x0}", operands);
+output_asm_insn ("vxorps\t%x0, %x0, %x0", operands);
   return "vgetmant\t{%3, 
%2, %1, 
%0|%0, %1, 
%2, %3}";
 }
[(set_attr "prefix" "evex")
--- gcc/testsuite/gcc.target/i386/pr104104.c.jj 2022-01-18 21:38:17.007906673 
+0100
+++ gcc/testsuite/gcc.target/i386/pr104104.c

[PATCH] gimple-ssa-warn-access: Fix up asan_test.C -Wdangling-pointer regression [PR104103]

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

As reported in the PR or as I've seen since the weekend, asan_test.C fails
because of many warnings like:
/home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1157:10: error: 
using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
/home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1157:10: error: 
using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
/home/jakub/src/gcc/gcc/testsuite/g++.dg/asan/asan_test.cc:1162:27: error: 
using a dangling pointer to an unnamed temporary [-Werror=dangling-pointer=]
...
(lots of them).
There are no dangling pointers though, the warning pass sees:
  some_automatic_var ={v} {CLOBBER};
  .ASAN_MARK (POISON, _automatic_var, 8);
and warns on that (both on user vars and on e.g. TARGET_EXPR temporaries).
There is nothing wrong on that, .ASAN_MARK is compiler instrumentation,
which doesn't even touch the variable in any way nor make it escaped.
What it instead does is change bytes in the shadow memory corresponding
to the variable to reflect that the variable is out of scope and make
sure that access to it would be diagnosed at runtime.
So, for all purposes of the -Wdangling-pointer and -Wuse-after-free
warnings, we should ignore this internal call.

Bootstrapped/regtested on x86_64-linux and i686-linux, fixes asan_test.C
FAIL (so no new test has been added), ok for trunk?

2022-01-18  Jakub Jelinek  

PR middle-end/104103
* gimple-ssa-warn-access.cc (pass_waccess::check_call): Don't check
.ASAN_MARK calls.

--- gcc/gimple-ssa-warn-access.cc.jj2022-01-16 20:55:46.783932110 +0100
+++ gcc/gimple-ssa-warn-access.cc   2022-01-18 20:56:13.697780325 +0100
@@ -4232,6 +4232,11 @@ pass_waccess::check_call (gcall *stmt)
   if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 check_builtin (stmt);
 
+  /* .ASAN_MARK doesn't access any vars, only modifies shadow memory.  */
+  if (gimple_call_internal_p (stmt)
+  && gimple_call_internal_fn (stmt) == IFN_ASAN_MARK)
+return;
+
   if (!m_early_checks_p)
 if (tree callee = gimple_call_fndecl (stmt))
   {

Jakub



Re: [PATCH] libgccjit: Add support for register variables [PR104072]

2022-01-18 Thread David Malcolm via Gcc-patches
On Mon, 2022-01-17 at 19:46 -0500, Antoni Boucher via Gcc-patches
wrote:
> I missed the comment about the new define, so here's the updated
> patch.

Thanks for the patch.
> 
> Le lundi 17 janvier 2022 à 19:24 -0500, Antoni Boucher via Jit a
> écrit :
> > Hi.
> > This patch add supports for register variables in libgccjit.
> > 
> > It passes the JIT tests, but since I added a function in reginfo.c,
> > I
> > wonder if I should run the whole testsuite.

We're in stage 4 for gcc 12, so we should be especially careful about
changes right now, and we're not meant to be adding new GCC 12
features.

How close is gcc 12's libgccjit to being usable with your rustc
backend?  If we're almost there, I'm willing to make our case for late-
breaking libgccjit changes to the release managers, but if you think
rustc users are going to need to build a patched libgccjit, then let's
queue this up for gcc 13.

> 2022-01-17  Antoni Boucher 
> 
> gcc/jit/
>   PR target/104072

This should be "jit", rather than "target".

This will need updaing for the various .c to .cc renamings on trunk
yesterday.

[...snip...]

> diff --git a/gcc/jit/dummy-frontend.c b/gcc/jit/dummy-frontend.c
> index 84ff359bfe3..04d8fc6ab48 100644
> --- a/gcc/jit/dummy-frontend.c
> +++ b/gcc/jit/dummy-frontend.c
> @@ -599,6 +599,8 @@ jit_langhook_init (void)
>  
>build_common_builtin_nodes ();
>  
> +  clear_global_regs_cache ();
> +

Similarly to my comments on the bitcasts patch, call this from a
reginfo_cc_finalize function called from toplev::finalize instead.

> diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
> index 03704ef10b8..1757ad583fe 100644
> --- a/gcc/jit/libgccjit.c
> +++ b/gcc/jit/libgccjit.c
> @@ -2649,6 +2649,18 @@ gcc_jit_lvalue_set_link_section (gcc_jit_lvalue 
> *lvalue,
>lvalue->set_link_section (section_name);
>  }
>  
> +/* Public entrypoint.  See description in libgccjit.h.
> +
> +   After error-checking, the real work is done by the
> +   gcc::jit::recording::lvalue::set_register_name method in jit-recording.c. 
>  */
> +
> +void
> +gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue,
> +   const char *reg_name)
> +{

Need error checking here, to gracefully reject NULL value, and NULL
reg_name.

> +  lvalue->set_register_name (reg_name);
> +}
> +

> diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
> index c93d7055d43..af4427c4503 100644
> --- a/gcc/jit/jit-playback.h
> +++ b/gcc/jit/jit-playback.h
> @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include  // for std::pair
>  
>  #include "timevar.h"
> +#include "varasm.h"
>  
>  #include "jit-recording.h"
>  
> @@ -701,6 +702,14 @@ public:
>  set_decl_section_name (as_tree (), name);
>}
>  
> +  void
> +  set_register_name (const char* reg_name)
> +  {
> +set_user_assembler_name (as_tree (), reg_name);
> +DECL_REGISTER (as_tree ()) = 1;
> +DECL_HARD_REGISTER (as_tree ()) = 1;
> +  }

I'm not familiar enough with the backend to know if this is correct,
sorry.

Is there an analogous thing in the C frontend that this corresponds to?

[...snip...]

> diff --git a/gcc/reginfo.c b/gcc/reginfo.c
> index 234f72eceeb..4fe375c4463 100644
> --- a/gcc/reginfo.c
> +++ b/gcc/reginfo.c
> @@ -91,6 +91,14 @@ static const char initial_call_used_regs[] = 
> CALL_USED_REGISTERS;
> and are also considered fixed.  */
>  char global_regs[FIRST_PSEUDO_REGISTER];
>  
> +void clear_global_regs_cache (void)
> +{

This should be made static and called from a reginfo_cc_finalize,
called from toplev::finalize.

> +  for (size_t i = 0 ; i < FIRST_PSEUDO_REGISTER ; i++)
> +  {
> +global_regs[i] = 0;

Probably should also clear global_regs_decl[i].

> +  }

and unset all of global_reg_set, I believe.  I'm not particularly
familiar with this code, so a backend expert should look at this.

> +}
> +


> diff --git a/gcc/system.h b/gcc/system.h
> index c25cd64366f..950969367b3 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -1316,4 +1316,6 @@ endswith (const char *str, const char *suffix)
>return memcmp (str + str_len - suffix_len, suffix, suffix_len) == 0;
>  }
>  
> +extern void clear_global_regs_cache (void);

Declare reginfo_cc_finalize as "extern", and do it from rtl.h, rather
than system.h


>  #endif /* ! GCC_SYSTEM_H */

[...snip...]

> diff --git a/gcc/testsuite/jit.dg/test-register-variable.c 
> b/gcc/testsuite/jit.dg/test-register-variable.c
> new file mode 100644
> index 000..3cea3f1668f
> --- /dev/null
> +++ b/gcc/testsuite/jit.dg/test-register-variable.c
> @@ -0,0 +1,54 @@
> +#include 
> +#include 
> +
> +#include "libgccjit.h"
> +
> +/* We don't want set_options() in harness.h to set -O3 so our little local
> +   is optimized away. */
> +#define TEST_ESCHEWS_SET_OPTIONS
> +static void set_options (gcc_jit_context *ctxt, const char *argv0)
> +{
> +}
> +
> +#define TEST_COMPILING_TO_FILE
> +#define OUTPUT_KIND  GCC_JIT_OUTPUT_KIND_ASSEMBLER
> +#define OUTPUT_FILENAME  

[PATCH] fold-const: Optimize &"foo"[0] == "foo" [PR89074]

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

This is a non-C++ related part from the PR89074 address_compare changes.
For "foo" == "foo" we already optimize this from the (cmp @0 @0)
simplification, because we use operand_equal_p in that case
and operand_equal_p also compares the STRING_CSTs bytes rather than
just addresses.

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

2022-01-18  Jakub Jelinek  

PR c++/89074
* fold-const.cc (address_compare): Consider different STRING_CSTs
with the same lengths that memcmp the same as equal, not different.

* gcc.dg/tree-ssa/pr89074.c: New test.

--- gcc/fold-const.cc.jj2022-01-18 13:25:08.057491249 +0100
+++ gcc/fold-const.cc   2022-01-18 13:53:26.106261913 +0100
@@ -16587,6 +16587,15 @@ address_compare (tree_code code, tree ty
   || TREE_CODE (base1) == SSA_NAME
   || TREE_CODE (base1) == STRING_CST))
 equal = (base0 == base1);
+  /* Assume different STRING_CSTs with the same content will be
+ merged.  */
+  if (equal == 0
+  && TREE_CODE (base0) == STRING_CST
+  && TREE_CODE (base1) == STRING_CST
+  && TREE_STRING_LENGTH (base0) == TREE_STRING_LENGTH (base1)
+  && memcmp (TREE_STRING_POINTER (base0), TREE_STRING_POINTER (base1),
+TREE_STRING_LENGTH (base0)) == 0)
+equal = 1;
   if (equal == 1)
 {
   if (code == EQ_EXPR
--- gcc/testsuite/gcc.dg/tree-ssa/pr89074.c.jj  2022-01-18 18:42:05.125004996 
+0100
+++ gcc/testsuite/gcc.dg/tree-ssa/pr89074.c 2022-01-18 18:43:39.249694890 
+0100
@@ -0,0 +1,12 @@
+/* PR c++/89074 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump "return 1;" "optimized" } } */
+
+int
+foo (void)
+{
+  const char *a = &"foo"[0];
+  const char *b = "foo";
+  return a == b;
+}

Jakub



[PATCH] [COMMITTED] Improve coment for the newly added code in ipa-split.

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

It was pointed out to me by Jakub, that the comment in front of
the new code which handles warning/error attribute was not really
understandable. This fixes the comment to be understandable; I
don't know why I wrote the original comment that way even.

Committed as obvious after a quick build.

gcc/ChangeLog:

* ipa-split.cc (visit_bb): Fix comment before the
warning/error attribute checking code.
---
 gcc/ipa-split.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ipa-split.cc b/gcc/ipa-split.cc
index 6ca45f3b745..ff11cf34b23 100644
--- a/gcc/ipa-split.cc
+++ b/gcc/ipa-split.cc
@@ -931,8 +931,8 @@ visit_bb (basic_block bb, basic_block return_bb,
break;
  }
 
- /* Calls that function has either the warning or error
-attribute on it should not be split off into another
+ /* Calls to functions (which have the warning or error
+attribute on them) should not be split off into another
 function.  */
  if (lookup_attribute ("warning", DECL_ATTRIBUTES (decl))
   || lookup_attribute ("error", DECL_ATTRIBUTES (decl)))
-- 
2.27.0



Re: [PATCH] c++, v2: Fix handling of temporaries with consteval ctors and non-trivial dtors [PR104055]

2022-01-18 Thread Jason Merrill via Gcc-patches

On 1/18/22 18:07, Jakub Jelinek wrote:

On Tue, Jan 18, 2022 at 11:51:31AM -0500, Jason Merrill wrote:

On 1/18/22 09:26, Jakub Jelinek wrote:

On Tue, Jan 18, 2022 at 09:08:03AM -0500, Jason Merrill wrote:

which makes call a TARGET_EXPR with the dtor in TARGET_EXPR_CLEANUP,
but then call cxx_constant_value on it.  In cxx_eval_outermost_constant_expr
it triggers the:
 else if (TREE_CODE (t) != CONSTRUCTOR)
   {
 r = get_target_expr_sfinae (r, tf_warning_or_error | 
tf_no_cleanup);
 TREE_CONSTANT (r) = true;
   }
which wraps the CONSTRUCTOR r into a new TARGET_EXPR, but one without
dtors (I think we need e.g. the TREE_CONSTANT for the callers),
and finally build_over_call uses that.


Looks like you added the tf_no_cleanup in r10-3661 (constexpr new). Maybe
that should only be added if TARGET_EXPR_CLEANUP (t) is null?


I thought about that, but I'm worried that if the cleanup action
is non-empty, then the TREE_CONSTANT (r) = true; after it isn't appropriate,
because the TARGET_EXPR has side-effects.


Hmm.  If we e.g. pull out a subobject value from the TARGET_EXPR temporary,
we still need to run the cleanup, so we don't want to optimize the temporary
away, so not setting TREE_CONSTANT sounds right.


And the callers like cxx_constant_value_sfinae just return error_mark_node
if it isn't set:
if (sfinae && !TREE_CONSTANT (r))
  r = error_mark_node;


Yes.  Is that wrong?  I guess we need to be more careful about adjusting the
arguments to cxx_constant_value_sfinae if we still want a constant value.

Perhaps we also still want to set tf_no_cleanup if object is nonnull, since
in that case we know the prvalue is going to be an initializer rather than a
temporary.


This passed bootstrap/regtest on i686-linux and bootstrap on
x86_64-linux (regtest still pending):


OK if it passes.


2022-01-18  Jakub Jelinek  

PR c++/104055
* constexpr.cc (cxx_eval_outermost_constant_expr): If t is a
TARGET_EXPR with TARGET_EXPR_CLEANUP, use get_target_expr rather
than get_target_expr_sfinae with tf_no_cleanup, and don't set
TREE_CONSTANT.

* g++.dg/cpp2a/consteval27.C: New test.

--- gcc/cp/constexpr.cc.jj  2022-01-18 11:58:59.296986142 +0100
+++ gcc/cp/constexpr.cc 2022-01-18 20:07:28.362485336 +0100
@@ -7821,7 +7821,11 @@ cxx_eval_outermost_constant_expr (tree t
if (TREE_CODE (t) == TARGET_EXPR
  && TARGET_EXPR_INITIAL (t) == r)
return t;
-  else if (TREE_CODE (t) != CONSTRUCTOR)
+  else if (TREE_CODE (t) == CONSTRUCTOR)
+   ;
+  else if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_CLEANUP (t))
+   r = get_target_expr (r);
+  else
{
  r = get_target_expr_sfinae (r, tf_warning_or_error | tf_no_cleanup);
  TREE_CONSTANT (r) = true;
--- gcc/testsuite/g++.dg/cpp2a/consteval27.C.jj 2022-01-18 20:12:55.326006216 
+0100
+++ gcc/testsuite/g++.dg/cpp2a/consteval27.C2022-01-18 20:13:01.442921759 
+0100
@@ -0,0 +1,18 @@
+// PR c++/104055
+// { dg-do run { target c++20 } }
+
+int g;
+
+struct A {
+  ~A () { if (a != 17 || b != 26) __builtin_abort (); g = 42; }
+  consteval A () : a (17), b (26) {}
+  int a, b;
+};
+
+int
+main ()
+{
+  A{};
+  if (g != 42)
+__builtin_abort ();
+}


Jakub





Re: [PATCH] libgccjit: Add option to hide stderr logs [PR104073]

2022-01-18 Thread David Malcolm via Gcc-patches
On Mon, 2022-01-17 at 21:02 -0500, Antoni Boucher via Gcc-patches
wrote:
> Hi.
> This option will be useful for rustc_codegen_gcc to hide the error
> about unsupported 128-bit integer types.
> 
> David, if you know of a better way to check if these types are
> supported than creating such a type and checking if it causes an error,
> I will not need this patch.

Off the top of my head I don't know of such a way.

That said, this seems to be vaguely analogous to a test in a
"configure" script, attempting a compile and seeing if it succeeds.

This seems like a useful pattern for libgccjit to support, so that
client code can query the capabilities of the host, so I think the idea
of this patch is sound.

As for the details of the patch, I don't like adding new members to the
enums in libgccjit.h; I prefer adding new entrypoints, as the latter
gives a way to tell if client code uses the new entrypoint as part of
the ELF metadata, so that we can tell directly that client code is
incompatible with an older libgccjit.so from the symbol metadata in the
built binary.

So I'd prefer something like:

  extern void
  gcc_jit_context_set_bool_print_errors_to_stderr (gcc_jit_context *ctxt,
   int enabled);

where gcc_jit_context_set_bool_print_errors_to_stderr defaults to true,
but client code can use:

  gcc_jit_context_set_bool_print_errors_to_stderr (ctxt, false);

Or maybe have a way to specify the FILE * for errors to be printed to,
defaulting to stderr, but settable to NULL if you want to suppress the
printing?  That might be more flexible.

Thoughts?
Dave



Re: [pushed] c++: input_location and lookahead [PR104025]

2022-01-18 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 18, 2022 at 05:56:47PM -0500, Jason Merrill wrote:
> Debug information was getting confused because input_location was different
> depending on whether we had looked ahead to see if the next tokens look like
> a template argument list.
> 
> I tried resetting input_location in cp_lexer_rollback_tokens itself, but
> that caused regressions, so let's just do it here for now.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.
> 
>   PR c++/104025
> 
> gcc/cp/ChangeLog:
> 
>   * parser.cc (saved_token_sentinel::rollback): Call
>   cp_lexer_set_source_position.
>   (~saved_token_sentinel): Call rollback.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.dg/warn/pr104025.C: New test.

The testcase fails for me with this change.
I see:
Breakpoint 5, cp_parser_id_expression (parser=0x7fffea26e7b8, 
template_keyword_p=false, check_dependency_p=true, template_p=0x7fffaf5f, 
declarator_p=false, optional_p=false)
at ../../gcc/cp/parser.cc:6257
6257  saved_token_sentinel toks (parser->lexer, STS_ROLLBACK);
(gdb) p expand_location (input_location)
$6 = {file = 0x4162bb0 "pr104025.C", line = 16, column = 12, data = 0x0, sysp = 
false}
- input_location is when entering this code conditional on the warning
set to the last committed token, i.e. i in
bar (c.i < m);
Next it commits the < and m tokens (so up to column 16) and then fails
and invokes rollback and cp_lexer_set_source_position.  But that sets
input_location from the peeked token, i.e. the < one with column 14.
So, with -w, we get 16:12, without -w we get 16:14.

> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -1308,6 +1308,7 @@ struct saved_token_sentinel
>void rollback ()
>{
>  cp_lexer_rollback_tokens (lexer);
> +cp_lexer_set_source_position (lexer);
>  mode = STS_DONOTHING;
>}
>~saved_token_sentinel ()
> @@ -1315,7 +1316,7 @@ struct saved_token_sentinel
>  if (mode == STS_COMMIT)
>cp_lexer_commit_tokens (lexer);
>  else if (mode == STS_ROLLBACK)
> -  cp_lexer_rollback_tokens (lexer);
> +  rollback ();
>  
>  gcc_assert (lexer->saved_tokens.length () == len);
>}
> diff --git a/gcc/testsuite/g++.dg/warn/pr104025.C 
> b/gcc/testsuite/g++.dg/warn/pr104025.C
> new file mode 100644
> index 000..9457c8ef52c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/pr104025.C
> @@ -0,0 +1,20 @@
> +// PR c++/104025
> +// { dg-do compile }
> +// { dg-options "-Wmissing-template-keyword -fcompare-debug" }
> +
> +void bar (int);
> +
> +struct S { int i; };
> +
> +template 
> +struct T
> +{
> +  int m;
> +  C c;
> +  void foo ()
> +  {
> +bar (c.i < m);
> +  }
> +};
> +
> +template void T::foo ();
> 
> base-commit: 7ca21601704c4a637f3cefa7c8814920782354d8

Jakub



[PATCH] c++, v2: Fix handling of temporaries with consteval ctors and non-trivial dtors [PR104055]

2022-01-18 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 18, 2022 at 11:51:31AM -0500, Jason Merrill wrote:
> On 1/18/22 09:26, Jakub Jelinek wrote:
> > On Tue, Jan 18, 2022 at 09:08:03AM -0500, Jason Merrill wrote:
> > > > which makes call a TARGET_EXPR with the dtor in TARGET_EXPR_CLEANUP,
> > > > but then call cxx_constant_value on it.  In 
> > > > cxx_eval_outermost_constant_expr
> > > > it triggers the:
> > > > else if (TREE_CODE (t) != CONSTRUCTOR)
> > > >   {
> > > > r = get_target_expr_sfinae (r, tf_warning_or_error | 
> > > > tf_no_cleanup);
> > > > TREE_CONSTANT (r) = true;
> > > >   }
> > > > which wraps the CONSTRUCTOR r into a new TARGET_EXPR, but one without
> > > > dtors (I think we need e.g. the TREE_CONSTANT for the callers),
> > > > and finally build_over_call uses that.
> > > 
> > > Looks like you added the tf_no_cleanup in r10-3661 (constexpr new). Maybe
> > > that should only be added if TARGET_EXPR_CLEANUP (t) is null?
> > 
> > I thought about that, but I'm worried that if the cleanup action
> > is non-empty, then the TREE_CONSTANT (r) = true; after it isn't appropriate,
> > because the TARGET_EXPR has side-effects.
> 
> Hmm.  If we e.g. pull out a subobject value from the TARGET_EXPR temporary,
> we still need to run the cleanup, so we don't want to optimize the temporary
> away, so not setting TREE_CONSTANT sounds right.
> 
> > And the callers like cxx_constant_value_sfinae just return error_mark_node
> > if it isn't set:
> >if (sfinae && !TREE_CONSTANT (r))
> >  r = error_mark_node;
> 
> Yes.  Is that wrong?  I guess we need to be more careful about adjusting the
> arguments to cxx_constant_value_sfinae if we still want a constant value.
> 
> Perhaps we also still want to set tf_no_cleanup if object is nonnull, since
> in that case we know the prvalue is going to be an initializer rather than a
> temporary.

This passed bootstrap/regtest on i686-linux and bootstrap on
x86_64-linux (regtest still pending):

2022-01-18  Jakub Jelinek  

PR c++/104055
* constexpr.cc (cxx_eval_outermost_constant_expr): If t is a
TARGET_EXPR with TARGET_EXPR_CLEANUP, use get_target_expr rather
than get_target_expr_sfinae with tf_no_cleanup, and don't set
TREE_CONSTANT.

* g++.dg/cpp2a/consteval27.C: New test.

--- gcc/cp/constexpr.cc.jj  2022-01-18 11:58:59.296986142 +0100
+++ gcc/cp/constexpr.cc 2022-01-18 20:07:28.362485336 +0100
@@ -7821,7 +7821,11 @@ cxx_eval_outermost_constant_expr (tree t
   if (TREE_CODE (t) == TARGET_EXPR
  && TARGET_EXPR_INITIAL (t) == r)
return t;
-  else if (TREE_CODE (t) != CONSTRUCTOR)
+  else if (TREE_CODE (t) == CONSTRUCTOR)
+   ;
+  else if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_CLEANUP (t))
+   r = get_target_expr (r);
+  else
{
  r = get_target_expr_sfinae (r, tf_warning_or_error | tf_no_cleanup);
  TREE_CONSTANT (r) = true;
--- gcc/testsuite/g++.dg/cpp2a/consteval27.C.jj 2022-01-18 20:12:55.326006216 
+0100
+++ gcc/testsuite/g++.dg/cpp2a/consteval27.C2022-01-18 20:13:01.442921759 
+0100
@@ -0,0 +1,18 @@
+// PR c++/104055
+// { dg-do run { target c++20 } }
+
+int g;
+
+struct A { 
+  ~A () { if (a != 17 || b != 26) __builtin_abort (); g = 42; }
+  consteval A () : a (17), b (26) {}
+  int a, b;
+};
+
+int
+main ()
+{
+  A{};
+  if (g != 42)
+__builtin_abort ();
+}


Jakub



Re: [PATCH] libgccjit: Add support for bitcasts [PR104071]

2022-01-18 Thread David Malcolm via Gcc-patches
On Mon, 2022-01-17 at 19:30 -0500, Antoni Boucher via Gcc-patches
wrote:
> I was missing the define, so I added it.
> Here's the new patch with it.

Thanks for the patch.

> Le lundi 17 janvier 2022 à 17:18 -0500, Antoni Boucher via Jit a
> écrit :
> > Hi.
> > This patch add support for bitcasts in libgccjit.
> > 
> > It passes the JIT tests, but since I added a function in tree.c, I
> > wonder if I should run the whole testsuite.

We're in stage 4 for GCC 12 now, so we need to be especially careful
and conservative about every change.  A strict reading on the rules is
that we shouldn't be adding new features - but if they're confined to
libgccjit we may be able to get release manager approval.

> > 
> > David, you can now disregard my question in my email about 128-bit
> > integers regarding my issue with initialize_sizetypes being called
> > multiple times because this patch fix this issue.
> > I turns out there was a cache of types that needed to be cleared
> > when
> > you initialize the JIT.
> > 
> > The check for sizes is pending, because it requires the updates to
> > get_size I made in my patch for 128-bit integers.

Sorry, I seem to have mislaid that patch; do you have the "Subject"
line handy?

Do you have a list of the patches I need to review?

As for this patch, overall I like it, but there are various nits...

> > 
> > Thanks for the review!

> 2022-01-17  Antoni Boucher 
> 
> gcc/jit/
>   PR target/104071

Should be "jit" rather than "target".

Various source files are now .cc rather than .c after yesterday's big
renaming.

>   * docs/topics/compatibility.rst (LIBGCCJIT_ABI_20): New ABI tag.
>   * docs/topics/expressions.rst: Add documentation for the
>   function gcc_jit_context_new_bitcast.
>   * dummy-frontend.c: clear the cache of non-standard integer
>   types to avoid having issues with some optimizations of
>   bitcast where the SSA_NAME will have a size of a cached
>   integer type that should have been invalidated, causing a
>   comparison of integer constant to fail.
>   * jit-playback.c: New function (new_bitcast).
>   * jit-playback.h: New function (new_bitcast).
>   * jit-recording.c: New functions (new_bitcast,
>   bitcast::replay_into, bitcast::visit_children,
>   bitcast::make_debug_string, bitcast::write_reproducer).
>   * jit-recording.h: New calss (bitcast) and new function
>   (new_bitcast, bitcast::replay_into, bitcast::visit_children,
>   bitcast::make_debug_string, bitcast::write_reproducer,
>   bitcast::get_precedence).
>   * libgccjit.c: New function (gcc_jit_context_new_bitcast)
>   * libgccjit.h: New function (gcc_jit_context_new_bitcast)
>   * libgccjit.map (LIBGCCJIT_ABI_20): New ABI tag.
> 
> gcc/testsuite/
>   PR target/104071
>   * jit.dg/all-non-failing-tests.h: Add new test-bitcast.
>   * jit.dg/test-bitcast.c: New test.
> 
> gcc/
>   PR target/104071
>   * tree.c: New function (clear_nonstandard_integer_type_cache).
>   * tree.h: New function (clear_nonstandard_integer_type_cache).
> ---
>  gcc/jit/docs/topics/compatibility.rst|  9 +++
>  gcc/jit/docs/topics/expressions.rst  | 17 +
>  gcc/jit/dummy-frontend.c |  2 +
>  gcc/jit/jit-playback.c   | 13 
>  gcc/jit/jit-playback.h   |  5 ++
>  gcc/jit/jit-recording.c  | 66 
>  gcc/jit/jit-recording.h  | 32 ++
>  gcc/jit/libgccjit.c  | 28 +
>  gcc/jit/libgccjit.h  | 15 +
>  gcc/jit/libgccjit.map|  6 ++
>  gcc/testsuite/jit.dg/all-non-failing-tests.h | 10 +++
>  gcc/testsuite/jit.dg/test-bitcast.c  | 60 ++
>  gcc/tree.c   |  8 +++
>  gcc/tree.h   |  1 +
>  14 files changed, 272 insertions(+)
>  create mode 100644 gcc/testsuite/jit.dg/test-bitcast.c
> 
> diff --git a/gcc/jit/docs/topics/compatibility.rst 
> b/gcc/jit/docs/topics/compatibility.rst
> index 16cebe31a10..b5a6b704dda 100644
> --- a/gcc/jit/docs/topics/compatibility.rst
> +++ b/gcc/jit/docs/topics/compatibility.rst
> @@ -302,3 +302,12 @@ thread-local storage model of a variable:
>  section of a variable:
>  
>* :func:`gcc_jit_lvalue_set_link_section`
> +
> +.. _LIBGCCJIT_ABI_20:
> +
> +``LIBGCCJIT_ABI_20``
> +---
> +``LIBGCCJIT_ABI_20`` covers the addition of an API entrypoint to bitcast a
> +value from one type to another:
> +
> +  * :func:`gcc_jit_context_new_bitcast`
> diff --git a/gcc/jit/docs/topics/expressions.rst 
> b/gcc/jit/docs/topics/expressions.rst
> index 791a20398ca..1328a53f70f 100644
> --- a/gcc/jit/docs/topics/expressions.rst
> +++ b/gcc/jit/docs/topics/expressions.rst
> @@ -649,6 +649,23 @@ Type-coercion
>   * int <-> bool
>   * P*  <-> Q*, for pointer types P and Q
>  
> +.. 

[pushed] c++: input_location and lookahead [PR104025]

2022-01-18 Thread Jason Merrill via Gcc-patches
Debug information was getting confused because input_location was different
depending on whether we had looked ahead to see if the next tokens look like
a template argument list.

I tried resetting input_location in cp_lexer_rollback_tokens itself, but
that caused regressions, so let's just do it here for now.

Tested x86_64-pc-linux-gnu, applying to trunk.

PR c++/104025

gcc/cp/ChangeLog:

* parser.cc (saved_token_sentinel::rollback): Call
cp_lexer_set_source_position.
(~saved_token_sentinel): Call rollback.

gcc/testsuite/ChangeLog:

* g++.dg/warn/pr104025.C: New test.

Co-authored-by: Jakub Jelinek  
---
 gcc/cp/parser.cc |  3 ++-
 gcc/testsuite/g++.dg/warn/pr104025.C | 20 
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/pr104025.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b262b765a9a..60d9f7bb723 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -1308,6 +1308,7 @@ struct saved_token_sentinel
   void rollback ()
   {
 cp_lexer_rollback_tokens (lexer);
+cp_lexer_set_source_position (lexer);
 mode = STS_DONOTHING;
   }
   ~saved_token_sentinel ()
@@ -1315,7 +1316,7 @@ struct saved_token_sentinel
 if (mode == STS_COMMIT)
   cp_lexer_commit_tokens (lexer);
 else if (mode == STS_ROLLBACK)
-  cp_lexer_rollback_tokens (lexer);
+  rollback ();
 
 gcc_assert (lexer->saved_tokens.length () == len);
   }
diff --git a/gcc/testsuite/g++.dg/warn/pr104025.C 
b/gcc/testsuite/g++.dg/warn/pr104025.C
new file mode 100644
index 000..9457c8ef52c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/pr104025.C
@@ -0,0 +1,20 @@
+// PR c++/104025
+// { dg-do compile }
+// { dg-options "-Wmissing-template-keyword -fcompare-debug" }
+
+void bar (int);
+
+struct S { int i; };
+
+template 
+struct T
+{
+  int m;
+  C c;
+  void foo ()
+  {
+bar (c.i < m);
+  }
+};
+
+template void T::foo ();

base-commit: 7ca21601704c4a637f3cefa7c8814920782354d8
-- 
2.27.0



Re: [PATCH] riscv: fix -Wformat-diag errors.

2022-01-18 Thread Joseph Myers
On Tue, 18 Jan 2022, Martin Liška wrote:

> @@ -3309,8 +3309,8 @@ riscv_handle_type_attribute (tree *node
> ATTRIBUTE_UNUSED, tree name, tree args,
> && strcmp (string, "machine"))
>   {
> warning (OPT_Wattributes,
> -"argument to %qE attribute is not \"user\",
> \"supervisor\", or \"machine\"",
> -name);
> +"argument to %qE attribute is not %,
> %, "
> +"or %", name);
> *no_add_attrs = true;

My reading is that the attribute arguments here are string constants, not 
identifiers - that is, the ASCII double quotes are correct in the 
diagnostic output, because those double quotes are part of the literal 
text that's supposed to appear in the program.  (Maybe %<\"user\"%> is the 
right way of marking it up to indicate that the double quotes are part of 
the literal program text, not English-level quoting.)

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


Re: [PATCH] libstdc++: Clear padding bits in atomic compare_exchange

2022-01-18 Thread Jonathan Wakely via Gcc-patches
On Tue, 2 Nov 2021 at 01:26, Thomas Rodgers  wrote:

> This should address Jonathan's feedback and adds support for atomic_ref
>


>This change implements P0528 which requires that padding bits not
>participate in atomic compare exchange operations. All arguments to the
>generic template are 'sanitized' by the __builtin_clearpadding intrisic

The name of the intrinsic and the word "instrinsic" have typos.

>before they are used in comparisons. This alrequires that any stores
>also sanitize the incoming value.
>
>Signed-off-by: Thomas Rodgers 
>
>libstdc++=v3/ChangeLog:

Typo

>
> * include/std/atomic (atomic::atomic(_Tp): clear padding for

Unclosed paren.




>+#if __has_builtin(__builtin_clear_padding)

Instead of checking this built-in at every call site, can't we just make
__maybe_has_padding return false if the built-in isn't supported?
__clear_padding already handles the case where the built-in isn't supported.

>+template
>+  constexpr bool
>+  __maybe_has_padding()
>+  {
>+#if __has_builtin(__has_unique_object_representations)
>+return !__has_unique_object_representations(_Tp)
>+&& !is_floating_point<_Tp>::value;
>+#else
>+return true;
>+#endif
>+  }

So make that:

template
  constexpr bool
  __maybe_has_padding()
  {
#if ! __has_builtin(__builtin_clear_padding)
return false;
#elif __has_builtin(__has_unique_object_representations)
return !__has_unique_object_representations(_Tp)
&& !is_floating_point<_Tp>::value;
#else
return true;
#endif
 }


>+ if _GLIBCXX14_CONSTEXPR (__atomic_impl::__maybe_has_padding<_Tp>())
>+  {

This needs to be _GLIBCXX17_CONSTEXPR (everywhere that `if constexpr` is
used).

>+  {
>+alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
>+__builtin_memcpy(__buf, std::__addressof(__e), sizeof(_Tp));

alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
_Tp* __exp = ::new((void*)__buf) _Tp(__e);

>+auto* __exp =
__atomic_impl::__clear_padding(*reinterpret_cast<_Tp*>(__buf));

And then you don't need the reinterpret_cast:

__exp = __atomic_impl::__clear_padding(__exp);

>+auto* __des = __atomic_impl::__clear_padding(__i);
>+if (__atomic_compare_exchange(std::__addressof(__val), __exp, __des,
__weak,
>+  int(__s), int(__f)))
>+  return true;


> template
>   _GLIBCXX_ALWAYS_INLINE void
>   store(_Tp* __ptr, _Val<_Tp> __t, memory_order __m) noexcept
>-  { __atomic_store(__ptr, std::__addressof(__t), int(__m)); }
>+  {
>+#if __has_builtin(__builtin_clear_padding)
>+ if _GLIBCXX14_CONSTEXPR (__maybe_has_padding<_Tp>())
>+  __clear_padding(__t);
>+#endif
>+ __atomic_store(__ptr, std::__addressof(__t), int(__m));
>+  }
>

All calls to __clear_padding need to be qualified.

>+ return __compare_exchange(*__ptr, __expected, __desired, true,
>+  __success, __failure);

So do calls to __compare_exchange.


>
>   explicit
>   __atomic_ref(_Tp& __t) : _M_ptr(std::__addressof(__t))
>-  { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
>+  {
>+ __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0);
>+#if __cplusplus > 201402L && __has_builtin(__builtin_clear_padding)
>+ __builtin_clear_padding(_M_ptr);
>+#endif
>+  }

Is this safe to do?

What if multiple threads all create a std::atomic_ref round the same object
at once, they'll all try to clear padding, and so race, won't they?
I don't think we can clear padding on atomic_ref construction, only on
store and RMW operations.


>--- a/libstdc++-v3/include/std/atomic
>+++ b/libstdc++-v3/include/std/atomic
>@@ -228,13 +228,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>   atomic& operator=(const atomic&) = delete;
>   atomic& operator=(const atomic&) volatile = delete;
>
>-#if __cplusplus > 201703L && __has_builtin(__builtin_clear_padding)
>   constexpr atomic(_Tp __i) noexcept : _M_i(__i)
>-  { __builtin_clear_padding(std::__addressof(_M_i)); }
>-#else
>-  constexpr atomic(_Tp __i) noexcept : _M_i(__i)
>-  { }
>+  {
>+#if __cplusplus > 201402L && __has_builtin(__builtin_clear_padding)
>+ __builtin_clear_padding(std::__addressof(_M_i));
> #endif
>+  }
>

Is this an incremental patch relative to the first one?
The changes to this file look correct.

>--- /dev/null
>+++
b/libstdc++-v3/testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc
>@@ -0,0 +1,43 @@
>+// { dg-options "-std=gnu++2a" }
>+// { dg-do run { target c++2a } }

This new test is using "2a" not "20".


Re: [PATCH v2] bpf: ensure correct string offsets in BTF.ext

2022-01-18 Thread David Faust via Gcc-patches




On 1/18/22 13:18, Jose E. Marchesi wrote:


Hi David.


[Changed from v1: Adjust to account for file renaming so patch applies.]

BPF CO-RE relocations contain offsets to strings buffered in the BTF
string table. These BTF-specific strings are stored in memory in the
CTF auxilliary strtab, which at output time is concatenated onto the end
of the standard strtab.

Previously, these string offsets were computed at the time the
relocations were created. But strings could be added to the standard
strtab after this point, causing the offsets to no longer be correct.

Compute the offsets just before output instead, when they are sure to no
longer change.

Tested for bpf-unknown-none. OK to install?
Thanks.


OK.
Thanks.


Pushed, thanks





gcc/ChangeLog:

* config/bpf/coreout.cc (bpf_core_reloc_add): Do not account
for base strtab offset yet as it may change.
(output_asm_btfext_core_reloc): Do so here instead.
(output_btfext_core_sections): Likewise.
---
  gcc/config/bpf/coreout.cc | 14 +-
  1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
index 4ec12ecd305..cceaaa969cc 100644
--- a/gcc/config/bpf/coreout.cc
+++ b/gcc/config/bpf/coreout.cc
@@ -168,11 +168,8 @@ bpf_core_reloc_add (const tree type, const char * 
section_name,
bpf_core_reloc_ref bpfcr = ggc_cleared_alloc ();
ctf_container_ref ctfc = ctf_get_tu_ctfc ();
  
-  /* Buffer the access string in the auxiliary strtab. Since the two string

- tables are concatenated, add the length of the first to the offset.  */
-  size_t strtab_len = ctfc_get_strtab_len (ctfc, CTF_STRTAB);
+  /* Buffer the access string in the auxiliary strtab.  */
ctf_add_string (ctfc, buf, &(bpfcr->bpfcr_astr_off), CTF_AUX_STRTAB);
-  bpfcr->bpfcr_astr_off += strtab_len;
  
bpfcr->bpfcr_type = get_btf_id (ctf_lookup_tree_type (ctfc, type));

bpfcr->bpfcr_insn_label = label;
@@ -191,7 +188,6 @@ bpf_core_reloc_add (const tree type, const char * 
section_name,
sec = ggc_cleared_alloc ();
  
ctf_add_string (ctfc, section_name, >name_offset, CTF_AUX_STRTAB);

-  sec->name_offset += strtab_len;
if (strcmp (section_name, ""))
  ctfc->ctfc_aux_strlen += strlen (section_name) + 1;
  
@@ -287,6 +283,9 @@ output_btfext_header (void)

  static void
  output_asm_btfext_core_reloc (bpf_core_reloc_ref bpfcr)
  {
+  bpfcr->bpfcr_astr_off += ctfc_get_strtab_len (ctf_get_tu_ctfc (),
+   CTF_STRTAB);
+
dw2_assemble_integer (4, gen_rtx_LABEL_REF (Pmode, 
bpfcr->bpfcr_insn_label));
fprintf (asm_out_file, "\t%s bpfcr_insn\n", ASM_COMMENT_START);
  
@@ -323,6 +322,11 @@ output_btfext_core_sections (void)

/* Section name offset, refers to the offset of a string with the name 
of
 the section to which these CORE relocations refer, e.g. '.text'.
 The string is buffered in the BTF strings table.  */
+
+  /* BTF specific strings are in CTF_AUX_STRTAB, which is concatenated
+after CTF_STRTAB. Add the length of STRTAB to the final offset.  */
+  sec->name_offset += ctfc_get_strtab_len (ctf_get_tu_ctfc (), CTF_STRTAB);
+
dw2_asm_output_data (4, sec->name_offset,  
"btfext_secinfo_sec_name_off");
dw2_asm_output_data (4, vec_safe_length (sec->relocs),
   "btfext_secinfo_num_recs");


Re: [PATCH v2] bpf: write CO-RE relocation record size only once

2022-01-18 Thread David Faust via Gcc-patches




On 1/18/22 13:17, Jose E. Marchesi wrote:


Hi David.


[Changed from v1: Adjust to account for file renaming so patch applies.]

The CO-RE relocation record size should be written only once in the
.BTF.ext section, not once for each section with relocations.

Tested for bpf-unknown-none. OK to install?


This is OK.
Thanks for the patch.


Pushed, thanks




Thanks.

gcc/ChangeLog:

* config/bpf/coreout.cc (output_btfext_header): Account for
4-byte record size in core_relo_len.
(output_btfext_core_sections): Only write record size once.
* config/bpf/coreout.h (btf_ext_section_header): Delete unused
member.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/core-section-1.c: Adjust expected record size
occurrences.
---
  gcc/config/bpf/coreout.cc | 14 +-
  gcc/config/bpf/coreout.h  |  1 -
  gcc/testsuite/gcc.target/bpf/core-section-1.c |  2 +-
  3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
index f8ca2804207..4ec12ecd305 100644
--- a/gcc/config/bpf/coreout.cc
+++ b/gcc/config/bpf/coreout.cc
@@ -259,7 +259,7 @@ output_btfext_header (void)
uint32_t core_relo_off = 0, core_relo_len = 0;
  
/* Header core_relo_len is the sum total length in bytes of all CO-RE

- relocation sections.  */
+ relocation sections, plus the 4 byte record size.  */
size_t i;
bpf_core_section_ref sec;
core_relo_len += vec_safe_length (bpf_core_sections)
@@ -269,6 +269,9 @@ output_btfext_header (void)
  core_relo_len +=
vec_safe_length (sec->relocs) * sizeof (struct btf_ext_reloc);
  
+  if (core_relo_len)

+core_relo_len += sizeof (uint32_t);
+
dw2_asm_output_data (4, func_info_off, "func_info_offset");
dw2_asm_output_data (4, func_info_len, "func_info_len");
  
@@ -310,12 +313,13 @@ output_btfext_core_sections (void)

  {
size_t i;
bpf_core_section_ref sec;
+
+  /* BTF Ext section info. */
+  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
+  "btfext_core_info_rec_size");
+
FOR_EACH_VEC_ELT (*bpf_core_sections, i, sec)
  {
-  /* BTF Ext section info. */
-  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
-  "btfext_secinfo_rec_size");
-
/* Section name offset, refers to the offset of a string with the name 
of
 the section to which these CORE relocations refer, e.g. '.text'.
 The string is buffered in the BTF strings table.  */
diff --git a/gcc/config/bpf/coreout.h b/gcc/config/bpf/coreout.h
index a9d7e364ba3..3c7bdfd8c2f 100644
--- a/gcc/config/bpf/coreout.h
+++ b/gcc/config/bpf/coreout.h
@@ -33,7 +33,6 @@ extern "C"
  
  struct btf_ext_section_header

  {
-  uint32_t kind;
uint32_t sec_name_off;
uint32_t num_records;
  };
diff --git a/gcc/testsuite/gcc.target/bpf/core-section-1.c 
b/gcc/testsuite/gcc.target/bpf/core-section-1.c
index 031acd5292e..4f16b087c1a 100644
--- a/gcc/testsuite/gcc.target/bpf/core-section-1.c
+++ b/gcc/testsuite/gcc.target/bpf/core-section-1.c
@@ -35,4 +35,4 @@ int bar_func (struct T *t)
  /* { dg-final { scan-assembler-times "ascii \"foo_sec.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
  /* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
  /* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
-/* { dg-final { scan-assembler-times "btfext_secinfo_rec_size" 2 } } */
+/* { dg-final { scan-assembler-times "btfext_core_info_rec_size" 1 } } */


Re: [PATCH] powerc: Fix asm machine directive for some CPUs

2022-01-18 Thread Segher Boessenkool
Hi!

On Tue, Jan 18, 2022 at 12:51:39PM +0100, Sebastian Huber wrote:
> For some CPUs, the assembler machine directive cannot be determined by ISA
> flags.

That may be the best we can do here, with the current setup, yes.

>   PR 104090/target
>   * config/rs6000/rs6000.cc (rs6000_machine_from_flags): Use also
>   rtems_cpu.

rs6000_cpu you mean :-)

> +  /* For some CPUs, the machine cannot be determined by ISA flags.  We have 
> to
> + check them first.  */
> +  switch (rs6000_cpu)
> +{
> +case PROCESSOR_PPC8540:
> +case PROCESSOR_PPC8548:
> +  return "e500";

Ah I could not figure out what core those two are.  But you know it :-)

> +default:
> +  break;

Please don't do that.  You can do

  default:
break;
break;
/* And just to make sure:  */
break;
break;

and it will do exactly the same as not having a default at all.  Not
having such useless code is by far the most readable, so please don't
include a default case at all.

Okay with those changes.  Thanks!


Segher


Re: [PATCH] testsuite: Adjust possibly fragile slp-perm-9.c [PR104015]

2022-01-18 Thread Segher Boessenkool
On Tue, Jan 18, 2022 at 11:57:32AM +, Richard Sandiford wrote:
> "Kewen.Lin"  writes:
> >>PR tree-optimization/104015
> >>* gcc.dg/vect/slp-perm-9.c: Adjust.
> >>* gcc.target/powerpc/pr104015-1.c: New test.
> >>* gcc.target/powerpc/pr104015-2.c: New test.

> OK for the target-independent part, thanks.  IMO it's OK independently
> of the rs6000 tests.

The rs6000 parts are fine as well.  Thanks!

I see you got rid of the ilp32 tests, I was going to holler about that,
there is no reason this should only work (or only be tested) on 64-bit
systems :-)


Segher


Re: [PATCH v2] bpf: ensure correct string offsets in BTF.ext

2022-01-18 Thread Jose E. Marchesi via Gcc-patches


Hi David.

> [Changed from v1: Adjust to account for file renaming so patch applies.]
>
> BPF CO-RE relocations contain offsets to strings buffered in the BTF
> string table. These BTF-specific strings are stored in memory in the
> CTF auxilliary strtab, which at output time is concatenated onto the end
> of the standard strtab.
>
> Previously, these string offsets were computed at the time the
> relocations were created. But strings could be added to the standard
> strtab after this point, causing the offsets to no longer be correct.
>
> Compute the offsets just before output instead, when they are sure to no
> longer change.
>
> Tested for bpf-unknown-none. OK to install?
> Thanks.

OK.
Thanks.

>
> gcc/ChangeLog:
>
>   * config/bpf/coreout.cc (bpf_core_reloc_add): Do not account
>   for base strtab offset yet as it may change.
>   (output_asm_btfext_core_reloc): Do so here instead.
>   (output_btfext_core_sections): Likewise.
> ---
>  gcc/config/bpf/coreout.cc | 14 +-
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
> index 4ec12ecd305..cceaaa969cc 100644
> --- a/gcc/config/bpf/coreout.cc
> +++ b/gcc/config/bpf/coreout.cc
> @@ -168,11 +168,8 @@ bpf_core_reloc_add (const tree type, const char * 
> section_name,
>bpf_core_reloc_ref bpfcr = ggc_cleared_alloc ();
>ctf_container_ref ctfc = ctf_get_tu_ctfc ();
>  
> -  /* Buffer the access string in the auxiliary strtab. Since the two string
> - tables are concatenated, add the length of the first to the offset.  */
> -  size_t strtab_len = ctfc_get_strtab_len (ctfc, CTF_STRTAB);
> +  /* Buffer the access string in the auxiliary strtab.  */
>ctf_add_string (ctfc, buf, &(bpfcr->bpfcr_astr_off), CTF_AUX_STRTAB);
> -  bpfcr->bpfcr_astr_off += strtab_len;
>  
>bpfcr->bpfcr_type = get_btf_id (ctf_lookup_tree_type (ctfc, type));
>bpfcr->bpfcr_insn_label = label;
> @@ -191,7 +188,6 @@ bpf_core_reloc_add (const tree type, const char * 
> section_name,
>sec = ggc_cleared_alloc ();
>  
>ctf_add_string (ctfc, section_name, >name_offset, CTF_AUX_STRTAB);
> -  sec->name_offset += strtab_len;
>if (strcmp (section_name, ""))
>  ctfc->ctfc_aux_strlen += strlen (section_name) + 1;
>  
> @@ -287,6 +283,9 @@ output_btfext_header (void)
>  static void
>  output_asm_btfext_core_reloc (bpf_core_reloc_ref bpfcr)
>  {
> +  bpfcr->bpfcr_astr_off += ctfc_get_strtab_len (ctf_get_tu_ctfc (),
> + CTF_STRTAB);
> +
>dw2_assemble_integer (4, gen_rtx_LABEL_REF (Pmode, 
> bpfcr->bpfcr_insn_label));
>fprintf (asm_out_file, "\t%s bpfcr_insn\n", ASM_COMMENT_START);
>  
> @@ -323,6 +322,11 @@ output_btfext_core_sections (void)
>/* Section name offset, refers to the offset of a string with the name 
> of
>the section to which these CORE relocations refer, e.g. '.text'.
>The string is buffered in the BTF strings table.  */
> +
> +  /* BTF specific strings are in CTF_AUX_STRTAB, which is concatenated
> +  after CTF_STRTAB. Add the length of STRTAB to the final offset.  */
> +  sec->name_offset += ctfc_get_strtab_len (ctf_get_tu_ctfc (), 
> CTF_STRTAB);
> +
>dw2_asm_output_data (4, sec->name_offset,  
> "btfext_secinfo_sec_name_off");
>dw2_asm_output_data (4, vec_safe_length (sec->relocs),
>  "btfext_secinfo_num_recs");


Re: [PATCH v2] bpf: write CO-RE relocation record size only once

2022-01-18 Thread Jose E. Marchesi via Gcc-patches


Hi David.

> [Changed from v1: Adjust to account for file renaming so patch applies.]
>
> The CO-RE relocation record size should be written only once in the
> .BTF.ext section, not once for each section with relocations.
>
> Tested for bpf-unknown-none. OK to install?

This is OK.
Thanks for the patch.

> Thanks.
>
> gcc/ChangeLog:
>
>   * config/bpf/coreout.cc (output_btfext_header): Account for
>   4-byte record size in core_relo_len.
>   (output_btfext_core_sections): Only write record size once.
>   * config/bpf/coreout.h (btf_ext_section_header): Delete unused
>   member.
>
> gcc/testsuite/ChangeLog:
>
>   * gcc.target/bpf/core-section-1.c: Adjust expected record size
>   occurrences.
> ---
>  gcc/config/bpf/coreout.cc | 14 +-
>  gcc/config/bpf/coreout.h  |  1 -
>  gcc/testsuite/gcc.target/bpf/core-section-1.c |  2 +-
>  3 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
> index f8ca2804207..4ec12ecd305 100644
> --- a/gcc/config/bpf/coreout.cc
> +++ b/gcc/config/bpf/coreout.cc
> @@ -259,7 +259,7 @@ output_btfext_header (void)
>uint32_t core_relo_off = 0, core_relo_len = 0;
>  
>/* Header core_relo_len is the sum total length in bytes of all CO-RE
> - relocation sections.  */
> + relocation sections, plus the 4 byte record size.  */
>size_t i;
>bpf_core_section_ref sec;
>core_relo_len += vec_safe_length (bpf_core_sections)
> @@ -269,6 +269,9 @@ output_btfext_header (void)
>  core_relo_len +=
>vec_safe_length (sec->relocs) * sizeof (struct btf_ext_reloc);
>  
> +  if (core_relo_len)
> +core_relo_len += sizeof (uint32_t);
> +
>dw2_asm_output_data (4, func_info_off, "func_info_offset");
>dw2_asm_output_data (4, func_info_len, "func_info_len");
>  
> @@ -310,12 +313,13 @@ output_btfext_core_sections (void)
>  {
>size_t i;
>bpf_core_section_ref sec;
> +
> +  /* BTF Ext section info. */
> +  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
> +"btfext_core_info_rec_size");
> +
>FOR_EACH_VEC_ELT (*bpf_core_sections, i, sec)
>  {
> -  /* BTF Ext section info. */
> -  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
> -"btfext_secinfo_rec_size");
> -
>/* Section name offset, refers to the offset of a string with the name 
> of
>the section to which these CORE relocations refer, e.g. '.text'.
>The string is buffered in the BTF strings table.  */
> diff --git a/gcc/config/bpf/coreout.h b/gcc/config/bpf/coreout.h
> index a9d7e364ba3..3c7bdfd8c2f 100644
> --- a/gcc/config/bpf/coreout.h
> +++ b/gcc/config/bpf/coreout.h
> @@ -33,7 +33,6 @@ extern "C"
>  
>  struct btf_ext_section_header
>  {
> -  uint32_t kind;
>uint32_t sec_name_off;
>uint32_t num_records;
>  };
> diff --git a/gcc/testsuite/gcc.target/bpf/core-section-1.c 
> b/gcc/testsuite/gcc.target/bpf/core-section-1.c
> index 031acd5292e..4f16b087c1a 100644
> --- a/gcc/testsuite/gcc.target/bpf/core-section-1.c
> +++ b/gcc/testsuite/gcc.target/bpf/core-section-1.c
> @@ -35,4 +35,4 @@ int bar_func (struct T *t)
>  /* { dg-final { scan-assembler-times "ascii \"foo_sec.0\"\[\t 
> \]+\[^\n\]*btf_aux_string" 1 } } */
>  /* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t 
> \]+\[^\n\]*btf_aux_string" 1 } } */
>  /* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
> -/* { dg-final { scan-assembler-times "btfext_secinfo_rec_size" 2 } } */
> +/* { dg-final { scan-assembler-times "btfext_core_info_rec_size" 1 } } */


[PATCH v2] bpf: ensure correct string offsets in BTF.ext

2022-01-18 Thread David Faust via Gcc-patches
[Changed from v1: Adjust to account for file renaming so patch applies.]

BPF CO-RE relocations contain offsets to strings buffered in the BTF
string table. These BTF-specific strings are stored in memory in the
CTF auxilliary strtab, which at output time is concatenated onto the end
of the standard strtab.

Previously, these string offsets were computed at the time the
relocations were created. But strings could be added to the standard
strtab after this point, causing the offsets to no longer be correct.

Compute the offsets just before output instead, when they are sure to no
longer change.

Tested for bpf-unknown-none. OK to install?
Thanks.

gcc/ChangeLog:

* config/bpf/coreout.cc (bpf_core_reloc_add): Do not account
for base strtab offset yet as it may change.
(output_asm_btfext_core_reloc): Do so here instead.
(output_btfext_core_sections): Likewise.
---
 gcc/config/bpf/coreout.cc | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
index 4ec12ecd305..cceaaa969cc 100644
--- a/gcc/config/bpf/coreout.cc
+++ b/gcc/config/bpf/coreout.cc
@@ -168,11 +168,8 @@ bpf_core_reloc_add (const tree type, const char * 
section_name,
   bpf_core_reloc_ref bpfcr = ggc_cleared_alloc ();
   ctf_container_ref ctfc = ctf_get_tu_ctfc ();
 
-  /* Buffer the access string in the auxiliary strtab. Since the two string
- tables are concatenated, add the length of the first to the offset.  */
-  size_t strtab_len = ctfc_get_strtab_len (ctfc, CTF_STRTAB);
+  /* Buffer the access string in the auxiliary strtab.  */
   ctf_add_string (ctfc, buf, &(bpfcr->bpfcr_astr_off), CTF_AUX_STRTAB);
-  bpfcr->bpfcr_astr_off += strtab_len;
 
   bpfcr->bpfcr_type = get_btf_id (ctf_lookup_tree_type (ctfc, type));
   bpfcr->bpfcr_insn_label = label;
@@ -191,7 +188,6 @@ bpf_core_reloc_add (const tree type, const char * 
section_name,
   sec = ggc_cleared_alloc ();
 
   ctf_add_string (ctfc, section_name, >name_offset, CTF_AUX_STRTAB);
-  sec->name_offset += strtab_len;
   if (strcmp (section_name, ""))
 ctfc->ctfc_aux_strlen += strlen (section_name) + 1;
 
@@ -287,6 +283,9 @@ output_btfext_header (void)
 static void
 output_asm_btfext_core_reloc (bpf_core_reloc_ref bpfcr)
 {
+  bpfcr->bpfcr_astr_off += ctfc_get_strtab_len (ctf_get_tu_ctfc (),
+   CTF_STRTAB);
+
   dw2_assemble_integer (4, gen_rtx_LABEL_REF (Pmode, bpfcr->bpfcr_insn_label));
   fprintf (asm_out_file, "\t%s bpfcr_insn\n", ASM_COMMENT_START);
 
@@ -323,6 +322,11 @@ output_btfext_core_sections (void)
   /* Section name offset, refers to the offset of a string with the name of
 the section to which these CORE relocations refer, e.g. '.text'.
 The string is buffered in the BTF strings table.  */
+
+  /* BTF specific strings are in CTF_AUX_STRTAB, which is concatenated
+after CTF_STRTAB. Add the length of STRTAB to the final offset.  */
+  sec->name_offset += ctfc_get_strtab_len (ctf_get_tu_ctfc (), CTF_STRTAB);
+
   dw2_asm_output_data (4, sec->name_offset,  
"btfext_secinfo_sec_name_off");
   dw2_asm_output_data (4, vec_safe_length (sec->relocs),
   "btfext_secinfo_num_recs");
-- 
2.34.1



[PATCH v2] bpf: write CO-RE relocation record size only once

2022-01-18 Thread David Faust via Gcc-patches
[Changed from v1: Adjust to account for file renaming so patch applies.]

The CO-RE relocation record size should be written only once in the
.BTF.ext section, not once for each section with relocations.

Tested for bpf-unknown-none. OK to install?
Thanks.

gcc/ChangeLog:

* config/bpf/coreout.cc (output_btfext_header): Account for
4-byte record size in core_relo_len.
(output_btfext_core_sections): Only write record size once.
* config/bpf/coreout.h (btf_ext_section_header): Delete unused
member.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/core-section-1.c: Adjust expected record size
occurrences.
---
 gcc/config/bpf/coreout.cc | 14 +-
 gcc/config/bpf/coreout.h  |  1 -
 gcc/testsuite/gcc.target/bpf/core-section-1.c |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
index f8ca2804207..4ec12ecd305 100644
--- a/gcc/config/bpf/coreout.cc
+++ b/gcc/config/bpf/coreout.cc
@@ -259,7 +259,7 @@ output_btfext_header (void)
   uint32_t core_relo_off = 0, core_relo_len = 0;
 
   /* Header core_relo_len is the sum total length in bytes of all CO-RE
- relocation sections.  */
+ relocation sections, plus the 4 byte record size.  */
   size_t i;
   bpf_core_section_ref sec;
   core_relo_len += vec_safe_length (bpf_core_sections)
@@ -269,6 +269,9 @@ output_btfext_header (void)
 core_relo_len +=
   vec_safe_length (sec->relocs) * sizeof (struct btf_ext_reloc);
 
+  if (core_relo_len)
+core_relo_len += sizeof (uint32_t);
+
   dw2_asm_output_data (4, func_info_off, "func_info_offset");
   dw2_asm_output_data (4, func_info_len, "func_info_len");
 
@@ -310,12 +313,13 @@ output_btfext_core_sections (void)
 {
   size_t i;
   bpf_core_section_ref sec;
+
+  /* BTF Ext section info. */
+  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
+  "btfext_core_info_rec_size");
+
   FOR_EACH_VEC_ELT (*bpf_core_sections, i, sec)
 {
-  /* BTF Ext section info. */
-  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
-  "btfext_secinfo_rec_size");
-
   /* Section name offset, refers to the offset of a string with the name of
 the section to which these CORE relocations refer, e.g. '.text'.
 The string is buffered in the BTF strings table.  */
diff --git a/gcc/config/bpf/coreout.h b/gcc/config/bpf/coreout.h
index a9d7e364ba3..3c7bdfd8c2f 100644
--- a/gcc/config/bpf/coreout.h
+++ b/gcc/config/bpf/coreout.h
@@ -33,7 +33,6 @@ extern "C"
 
 struct btf_ext_section_header
 {
-  uint32_t kind;
   uint32_t sec_name_off;
   uint32_t num_records;
 };
diff --git a/gcc/testsuite/gcc.target/bpf/core-section-1.c 
b/gcc/testsuite/gcc.target/bpf/core-section-1.c
index 031acd5292e..4f16b087c1a 100644
--- a/gcc/testsuite/gcc.target/bpf/core-section-1.c
+++ b/gcc/testsuite/gcc.target/bpf/core-section-1.c
@@ -35,4 +35,4 @@ int bar_func (struct T *t)
 /* { dg-final { scan-assembler-times "ascii \"foo_sec.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
-/* { dg-final { scan-assembler-times "btfext_secinfo_rec_size" 2 } } */
+/* { dg-final { scan-assembler-times "btfext_core_info_rec_size" 1 } } */
-- 
2.34.1



[committed] analyzer: fix ICE on unary ops folding to casts of constants [PR104089]

2022-01-18 Thread David Malcolm via Gcc-patches
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r12-6700-g2aefe248aa4160205c44808166393a42031d2dea.

gcc/analyzer/ChangeLog:
PR analyzer/104089
* region-model-manager.cc
(region_model_manager::get_or_create_constant_svalue): Assert that
we have a CONSTANT_CLASS_P.
(region_model_manager::maybe_fold_unaryop): Only fold a constant
when fold_unary's result is a constant or a cast of a constant.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/pr104089.c: New test.
PR analyzer/104089

Signed-off-by: David Malcolm 
---
 gcc/analyzer/region-model-manager.cc | 19 ++-
 gcc/testsuite/gcc.dg/analyzer/pr104089.c |  9 +
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr104089.c

diff --git a/gcc/analyzer/region-model-manager.cc 
b/gcc/analyzer/region-model-manager.cc
index 9d4f5952ef3..bb93526807f 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -209,6 +209,7 @@ const svalue *
 region_model_manager::get_or_create_constant_svalue (tree cst_expr)
 {
   gcc_assert (cst_expr);
+  gcc_assert (CONSTANT_CLASS_P (cst_expr));
 
   constant_svalue **slot = m_constants_map.get (cst_expr);
   if (slot)
@@ -426,7 +427,23 @@ region_model_manager::maybe_fold_unaryop (tree type, enum 
tree_code op,
   /* Constants.  */
   if (tree cst = arg->maybe_get_constant ())
 if (tree result = fold_unary (op, type, cst))
-  return get_or_create_constant_svalue (result);
+  {
+   if (CONSTANT_CLASS_P (result))
+ return get_or_create_constant_svalue (result);
+
+   /* fold_unary can return casts of constants; try to handle them.  */
+   if (op != NOP_EXPR
+&& type
+&& TREE_CODE (result) == NOP_EXPR
+&& CONSTANT_CLASS_P (TREE_OPERAND (result, 0)))
+ {
+   const svalue *inner_cst
+ = get_or_create_constant_svalue (TREE_OPERAND (result, 0));
+   return get_or_create_cast (type,
+  get_or_create_cast (TREE_TYPE (result),
+  inner_cst));
+ }
+  }
 
   return NULL;
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104089.c 
b/gcc/testsuite/gcc.dg/analyzer/pr104089.c
new file mode 100644
index 000..c51770411f1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr104089.c
@@ -0,0 +1,9 @@
+/* { dg-additional-options "-frounding-math" } */
+
+volatile _Float16 true_min = 5.9604644775390625000e-8F16;
+
+int
+main (void)
+{
+  return __builtin_fpclassify (0, 1, 4, 3, 2, true_min);
+}
-- 
2.26.3



[committed] analyzer: fix ICE on realloc of zeroed memory [PR104062]

2022-01-18 Thread David Malcolm via Gcc-patches
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r12-6699-g79e746bb05e432dcd1c18161469272d67c33d79d.

gcc/analyzer/ChangeLog:
PR analyzer/104062
* region-model-manager.cc
(region_model_manager::maybe_fold_sub_svalue): Avoid casting to
NULL type when folding access to repeated svalue.

gcc/testsuite/ChangeLog:
PR analyzer/104062
* gcc.dg/analyzer/pr104062.c: New test.

Signed-off-by: David Malcolm 
---
 gcc/analyzer/region-model-manager.cc |  3 ++-
 gcc/testsuite/gcc.dg/analyzer/pr104062.c | 13 +
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr104062.c

diff --git a/gcc/analyzer/region-model-manager.cc 
b/gcc/analyzer/region-model-manager.cc
index 903cdfde91d..9d4f5952ef3 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -794,7 +794,8 @@ region_model_manager::maybe_fold_sub_svalue (tree type,
 
   if (const repeated_svalue *repeated_sval
= parent_svalue->dyn_cast_repeated_svalue ())
-return get_or_create_cast (type, repeated_sval->get_inner_svalue ());
+if (type)
+  return get_or_create_cast (type, repeated_sval->get_inner_svalue ());
 
   return NULL;
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104062.c 
b/gcc/testsuite/gcc.dg/analyzer/pr104062.c
new file mode 100644
index 000..7129c27f60b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr104062.c
@@ -0,0 +1,13 @@
+void *
+calloc (__SIZE_TYPE__, __SIZE_TYPE__);
+
+void *
+realloc (void *, __SIZE_TYPE__);
+
+void
+foo (void)
+{
+  int *ap5 = calloc (4, sizeof *ap5);
+  int *ap7 = realloc (ap5, sizeof *ap5);
+} /* { dg-warning "leak of 'ap5'" "leak of ap5" } */
+/* { dg-warning "leak of 'ap7'" "leak of ap7" { target *-*-* } .-1 } */
-- 
2.26.3



Re: [committed 2/2] libstdc++: Use GCC's predefined macro for endianness [PR104080]

2022-01-18 Thread Jonathan Wakely via Gcc-patches
On Tue, 18 Jan 2022 at 20:01, Patrick Palka  wrote:

> On Tue, 18 Jan 2022, Patrick Palka wrote:
>
> > On Tue, Jan 18, 2022 at 5:12 AM Jonathan Wakely 
> wrote:
> > >
> > > Tested x86_64-linux, pushed to trunk.
> > >
> > >
> > > Instead of hardcoded preprocessor conditionals with explicit target
> > > checks, just rely on the fact that __BYTE_ORDER__ is always defined by
> > > GCC.
> >
> > Thanks a lot for fixing these!  I apparently missed removing this
> > batch of #includes from the amalgamation in r12-6647.  For
> > completeness I suppose we should remove these #includes too.   I
> > wonder if we can rely on __BYTE_ORDER__ being defined by other
> > compilers?
>
>
We already use it unconditionally in , for std::endian.

I actually considered replacing all the FAST_FLOAT_USES_BIG_ENDIAN
preprocessor checks with:

if constexpr (std::endian::native == std::endian::big)

But it would make the diffs from upstream bigger for no benefit.

I did wonder whether some of those functions could avoid doing memcpy then
byteswap, if we just swapped the bytes without the memcpy. But GCC probably
optimizes that code well anyway, so I didn't even bother checking it.
Upstream probably tested that already as well.



> (N.B. not just for completeness but potentially also for correctness,
> since floating_from_chars.cc #includes "fast_float/fast_float.h" into an
> anonymous namespace, and we probably shouldn't be #including system
> headers into an anonymous namespace..)
>

Good point.


[PATCH] bpf: ensure correct string offsets in BTF.ext

2022-01-18 Thread David Faust via Gcc-patches
BPF CO-RE relocations contain offsets to strings buffered in the BTF
string table. These BTF-specific strings are stored in memory in the
CTF auxilliary strtab, which at output time is concatenated onto the end
of the standard strtab.

Previously, these string offsets were computed at the time the
relocations were created. But strings could be added to the standard
strtab after this point, causing the offsets to no longer be correct.

Compute the offsets just before output instead, when they are sure to no
longer change.

Tested for bpf-unknown-none. OK to install?
Thanks

gcc/ChangeLog:

* config/bpf/coreout.c (bpf_core_reloc_add): Do not account
for base strtab offset yet as it may change.
(output_asm_btfext_core_reloc): Do so here instead.
(output_btfext_core_sections): Likewise.
---
 gcc/config/bpf/coreout.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/config/bpf/coreout.c b/gcc/config/bpf/coreout.c
index 4ec12ecd305..cceaaa969cc 100644
--- a/gcc/config/bpf/coreout.c
+++ b/gcc/config/bpf/coreout.c
@@ -168,11 +168,8 @@ bpf_core_reloc_add (const tree type, const char * 
section_name,
   bpf_core_reloc_ref bpfcr = ggc_cleared_alloc ();
   ctf_container_ref ctfc = ctf_get_tu_ctfc ();
 
-  /* Buffer the access string in the auxiliary strtab. Since the two string
- tables are concatenated, add the length of the first to the offset.  */
-  size_t strtab_len = ctfc_get_strtab_len (ctfc, CTF_STRTAB);
+  /* Buffer the access string in the auxiliary strtab.  */
   ctf_add_string (ctfc, buf, &(bpfcr->bpfcr_astr_off), CTF_AUX_STRTAB);
-  bpfcr->bpfcr_astr_off += strtab_len;
 
   bpfcr->bpfcr_type = get_btf_id (ctf_lookup_tree_type (ctfc, type));
   bpfcr->bpfcr_insn_label = label;
@@ -191,7 +188,6 @@ bpf_core_reloc_add (const tree type, const char * 
section_name,
   sec = ggc_cleared_alloc ();
 
   ctf_add_string (ctfc, section_name, >name_offset, CTF_AUX_STRTAB);
-  sec->name_offset += strtab_len;
   if (strcmp (section_name, ""))
 ctfc->ctfc_aux_strlen += strlen (section_name) + 1;
 
@@ -287,6 +283,9 @@ output_btfext_header (void)
 static void
 output_asm_btfext_core_reloc (bpf_core_reloc_ref bpfcr)
 {
+  bpfcr->bpfcr_astr_off += ctfc_get_strtab_len (ctf_get_tu_ctfc (),
+   CTF_STRTAB);
+
   dw2_assemble_integer (4, gen_rtx_LABEL_REF (Pmode, bpfcr->bpfcr_insn_label));
   fprintf (asm_out_file, "\t%s bpfcr_insn\n", ASM_COMMENT_START);
 
@@ -323,6 +322,11 @@ output_btfext_core_sections (void)
   /* Section name offset, refers to the offset of a string with the name of
 the section to which these CORE relocations refer, e.g. '.text'.
 The string is buffered in the BTF strings table.  */
+
+  /* BTF specific strings are in CTF_AUX_STRTAB, which is concatenated
+after CTF_STRTAB. Add the length of STRTAB to the final offset.  */
+  sec->name_offset += ctfc_get_strtab_len (ctf_get_tu_ctfc (), CTF_STRTAB);
+
   dw2_asm_output_data (4, sec->name_offset,  
"btfext_secinfo_sec_name_off");
   dw2_asm_output_data (4, vec_safe_length (sec->relocs),
   "btfext_secinfo_num_recs");
-- 
2.34.1



[PATCH] bpf: write CO-RE relocation record size only once

2022-01-18 Thread David Faust via Gcc-patches
The CO-RE relocation record size should be written only once in the
.BTF.ext section, not once for each section with relocations.

Tested for bpf-unknown-none, OK to install?
Thanks

gcc/ChangeLog:

* config/bpf/coreout.c (output_btfext_header): Account for
4-byte record size in core_relo_len.
(output_btfext_core_sections): Only write record size once.
* config/bpf/coreout.h (btf_ext_section_header): Delete unused
member.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/core-section-1.c: Adjust expected record size
occurrences.
---
 gcc/config/bpf/coreout.c  | 14 +-
 gcc/config/bpf/coreout.h  |  1 -
 gcc/testsuite/gcc.target/bpf/core-section-1.c |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/gcc/config/bpf/coreout.c b/gcc/config/bpf/coreout.c
index f8ca2804207..4ec12ecd305 100644
--- a/gcc/config/bpf/coreout.c
+++ b/gcc/config/bpf/coreout.c
@@ -259,7 +259,7 @@ output_btfext_header (void)
   uint32_t core_relo_off = 0, core_relo_len = 0;
 
   /* Header core_relo_len is the sum total length in bytes of all CO-RE
- relocation sections.  */
+ relocation sections, plus the 4 byte record size.  */
   size_t i;
   bpf_core_section_ref sec;
   core_relo_len += vec_safe_length (bpf_core_sections)
@@ -269,6 +269,9 @@ output_btfext_header (void)
 core_relo_len +=
   vec_safe_length (sec->relocs) * sizeof (struct btf_ext_reloc);
 
+  if (core_relo_len)
+core_relo_len += sizeof (uint32_t);
+
   dw2_asm_output_data (4, func_info_off, "func_info_offset");
   dw2_asm_output_data (4, func_info_len, "func_info_len");
 
@@ -310,12 +313,13 @@ output_btfext_core_sections (void)
 {
   size_t i;
   bpf_core_section_ref sec;
+
+  /* BTF Ext section info. */
+  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
+  "btfext_core_info_rec_size");
+
   FOR_EACH_VEC_ELT (*bpf_core_sections, i, sec)
 {
-  /* BTF Ext section info. */
-  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
-  "btfext_secinfo_rec_size");
-
   /* Section name offset, refers to the offset of a string with the name of
 the section to which these CORE relocations refer, e.g. '.text'.
 The string is buffered in the BTF strings table.  */
diff --git a/gcc/config/bpf/coreout.h b/gcc/config/bpf/coreout.h
index a9d7e364ba3..3c7bdfd8c2f 100644
--- a/gcc/config/bpf/coreout.h
+++ b/gcc/config/bpf/coreout.h
@@ -33,7 +33,6 @@ extern "C"
 
 struct btf_ext_section_header
 {
-  uint32_t kind;
   uint32_t sec_name_off;
   uint32_t num_records;
 };
diff --git a/gcc/testsuite/gcc.target/bpf/core-section-1.c 
b/gcc/testsuite/gcc.target/bpf/core-section-1.c
index 031acd5292e..4f16b087c1a 100644
--- a/gcc/testsuite/gcc.target/bpf/core-section-1.c
+++ b/gcc/testsuite/gcc.target/bpf/core-section-1.c
@@ -35,4 +35,4 @@ int bar_func (struct T *t)
 /* { dg-final { scan-assembler-times "ascii \"foo_sec.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
-/* { dg-final { scan-assembler-times "btfext_secinfo_rec_size" 2 } } */
+/* { dg-final { scan-assembler-times "btfext_core_info_rec_size" 1 } } */
-- 
2.34.1



[committed] libstdc++: Limit new basic_string(nullptr_t) constructor to C++23 [PR104099]

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


The new deleted constructors added by P2166R1 are a breaking change,
making previously valid code ill-formed in C++23. As a result, they
should only be defined for C++23 and not for C++11 and up.

libstdc++-v3/ChangeLog:

PR libstdc++/104099
* include/bits/basic_string.h (basic_string(nullptr_t)): Only
define for C++23.
(operator=(nullptr_t)): Likewise.
* include/bits/cow_string.h: Likewise.
* include/std/string_view (basic_string_view(nullptr_t)):
Likewise.
* testsuite/21_strings/basic_string/cons/char/nullptr.cc: Adjust
expected error. Add examples that become ill-formed in C++23.
* testsuite/21_strings/basic_string_view/cons/char/nonnull.cc:
Adjust expected errors.
* testsuite/21_strings/basic_string_view/cons/wchar_t/nonnull.cc:
Likewise.
---
 libstdc++-v3/include/bits/basic_string.h  |  4 ++-
 libstdc++-v3/include/bits/cow_string.h|  4 ++-
 libstdc++-v3/include/std/string_view  |  3 ++-
 .../basic_string/cons/char/nullptr.cc | 26 ++-
 .../basic_string_view/cons/char/nonnull.cc|  3 ++-
 .../basic_string_view/cons/wchar_t/nonnull.cc |  3 ++-
 6 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/bits/basic_string.h 
b/libstdc++-v3/include/bits/basic_string.h
index a91ba5114b1..fc6a303a957 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -728,10 +728,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
else
  _M_construct(__str.begin(), __str.end(), std::forward_iterator_tag());
   }
+#endif // C++11
 
+#if __cplusplus >= 202100L
   basic_string(nullptr_t) = delete;
   basic_string& operator=(nullptr_t) = delete;
-#endif // C++11
+#endif // C++23
 
   /**
*  @brief  Construct string as copy of a range.
diff --git a/libstdc++-v3/include/bits/cow_string.h 
b/libstdc++-v3/include/bits/cow_string.h
index 84aab2f33c6..a49a5b04f2f 100644
--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -665,10 +665,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
else
  _M_dataplus._M_p = _S_construct(__str.begin(), __str.end(), __a);
   }
+#endif // C++11
 
+#if __cplusplus >= 202100L
   basic_string(nullptr_t) = delete;
   basic_string& operator=(nullptr_t) = delete;
-#endif // C++11
+#endif // C++23
 
   /**
*  @brief  Construct string as copy of a range.
diff --git a/libstdc++-v3/include/std/string_view 
b/libstdc++-v3/include/std/string_view
index 99080e9eccd..bccf4d1847f 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -167,10 +167,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
noexcept(noexcept(ranges::size(__r)) && noexcept(ranges::data(__r)))
: _M_len(ranges::size(__r)), _M_str(ranges::data(__r))
{ }
+
+  basic_string_view(nullptr_t) = delete;
 #endif // C++23
 #endif // C++20
 
-  basic_string_view(nullptr_t) = delete;
 
   constexpr basic_string_view&
   operator=(const basic_string_view&) noexcept = default;
diff --git 
a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nullptr.cc 
b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nullptr.cc
index fdb24aeeb89..a69fa614ba3 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nullptr.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nullptr.cc
@@ -1,4 +1,28 @@
 // { dg-do compile { target c++11 } }
 #include 
 
-std::string s = nullptr; // { dg-error "deleted" "P2166R1" }
+std::string s = nullptr; // { dg-error "deleted" "P2166R1" { target c++23 } }
+
+struct S
+{
+  operator const char*() const { return ""; }
+  operator std::nullptr_t() const { return {}; }
+};
+
+std::string s2{ S{} }; // { dg-error "deleted" "PR 104099" { target c++23 } }
+
+#if __cpp_concepts
+struct J
+{
+  // In C++20 this selects basic_string(const char*),
+  // in C++23 it's ambiguous due to basic_string(nullptr_t).
+  template
+requires (!std::is_same_v, T>)
+&& (!std::is_same_v)
+&& (!std::is_same_v)
+&& (!std::is_same_v)
+operator T() const { return {}; }
+};
+
+std::string s3{ J{} }; // { dg-error "ambiguous" "PR 104099" { target c++23 } }
+#endif
diff --git 
a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/nonnull.cc 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/nonnull.cc
index 00bb8e414b8..2e43788e4f5 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/nonnull.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/nonnull.cc
@@ -25,5 +25,6 @@ test01()
 {
   std::string_view s((const char*)nullptr); // { dg-warning "\\\[-Wnonnull" }
   std::string_view t((char*)nullptr);  // { dg-warning "\\\[-Wnonnull" }
-  std::string_view u(nullptr); // { dg-error "deleted" }
+  

Re: [PATCH] waccess: Look at calls when tracking clobbers [PR104092]

2022-01-18 Thread Jason Merrill via Gcc-patches

On 1/18/22 13:06, Martin Sebor wrote:

On 1/18/22 06:37, Richard Sandiford wrote:

In this PR the waccess pass was fed:

   D.10779 ={v} {CLOBBER};
   VIEW_CONVERT_EXPR(D.10779) = .MASK_LOAD_LANES 
(addr_5(D), 64B, _2);

   _7 = D.10779.__val[0];

However, the tracking of m_clobbers only looked at gassigns,
so it missed that the clobber on the first line was overwritten
by the call on the second line.

This patch splits the updating of m_clobbers out into its own
function, called after the check_*() routines, and extends it
to handle both gassigns and gcalls.  I think that makes sense
as an instance of the "read, operate, write" model, with the
new function being part of "write".

Previously only the gimple_clobber_p handling was conditional
on m_check_dangling_p, but I think the whole of the new function
can be.  We only enter stmts into m_clobbers if m_check_dangling_p,
so we only need to remove them under the same condition.


Thanks for the patch.  If you or someone can think of a test case
that's independent of a target, adding one would be very helpful.

Other than that, since I can't approve any changes I CC Jason who
was kind enough to approve the implementation of the warning for
his OK.


OK if Martin is happy with it.


Tested on aarch64-linux-gnu.  OK to install?

Richard


gcc/
PR middle-end/104092
* gimple-ssa-warn-access.cc (pass_waccess::update_clobbers_from_lhs):
New function, split out from...
(pass_waccess::check_stmt): ...here and generalized to calls.
(pass_waccess::check_block): Call it.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/general/pr104092.c: New test.
---
  gcc/gimple-ssa-warn-access.cc | 68 +++
  .../aarch64/sve/acle/general/pr104092.c   |  7 ++
  2 files changed, 48 insertions(+), 27 deletions(-)
  create mode 100644 
gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr104092.c


diff --git a/gcc/gimple-ssa-warn-access.cc 
b/gcc/gimple-ssa-warn-access.cc

index f639807a78a..25066fa6b89 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2094,6 +2094,9 @@ private:
    /* Check a non-call statement.  */
    void check_stmt (gimple *);
+  /* Update the clobber map based on the lhs of a statement.  */
+  void update_clobbers_from_lhs (gimple *);
+
    /* Check statements in a basic block.  */
    void check_block (basic_block);
@@ -4270,33 +4273,6 @@ is_auto_decl (tree x)
  void
  pass_waccess::check_stmt (gimple *stmt)
  {
-  if (m_check_dangling_p && gimple_clobber_p (stmt))
-    {
-  /* Ignore clobber statemts in blocks with exceptional edges.  */
-  basic_block bb = gimple_bb (stmt);
-  edge e = EDGE_PRED (bb, 0);
-  if (e->flags & EDGE_EH)
-    return;
-
-  tree var = gimple_assign_lhs (stmt);
-  m_clobbers.put (var, stmt);
-  return;
-    }
-
-  if (is_gimple_assign (stmt))
-    {
-  /* Clobbered unnamed temporaries such as compound literals can be
- revived.  Check for an assignment to one and remove it from
- M_CLOBBERS.  */
-  tree lhs = gimple_assign_lhs (stmt);
-  while (handled_component_p (lhs))
-    lhs = TREE_OPERAND (lhs, 0);
-
-  if (is_auto_decl (lhs))
-    m_clobbers.remove (lhs);
-  return;
-    }
-
    if (greturn *ret = dyn_cast  (stmt))
  {
    if (optimize && flag_isolate_erroneous_paths_dereference)
@@ -4326,6 +4302,42 @@ pass_waccess::check_stmt (gimple *stmt)
  }
  }
+/* Update the clobber map based on the lhs of STMT.  */
+
+void
+pass_waccess::update_clobbers_from_lhs (gimple *stmt)
+{
+  if (gimple_clobber_p (stmt))
+    {
+  /* Ignore clobber statements in blocks with exceptional edges.  */
+  basic_block bb = gimple_bb (stmt);
+  edge e = EDGE_PRED (bb, 0);
+  if (e->flags & EDGE_EH)
+    return;
+
+  tree var = gimple_assign_lhs (stmt);
+  m_clobbers.put (var, stmt);
+  return;
+    }
+
+  if (is_gimple_assign (stmt) || is_gimple_call (stmt))
+    {
+  /* Clobbered unnamed temporaries such as compound literals can be
+ revived.  Check for an assignment to one and remove it from
+ M_CLOBBERS.  */
+  tree lhs = gimple_get_lhs (stmt);
+  if (!lhs)
+    return;
+
+  while (handled_component_p (lhs))
+    lhs = TREE_OPERAND (lhs, 0);
+
+  if (is_auto_decl (lhs))
+    m_clobbers.remove (lhs);
+  return;
+    }
+}
+
  /* Check basic block BB for invalid accesses.  */
  void
@@ -4340,6 +4352,8 @@ pass_waccess::check_block (basic_block bb)
  check_call (call);
    else
  check_stmt (stmt);
+  if (m_check_dangling_p)
+    update_clobbers_from_lhs (stmt);
  }
  }
diff --git 
a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr104092.c 
b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr104092.c

new file mode 100644
index 000..c17ece7d82f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr104092.c
@@ -0,0 +1,7 @@
+/* { dg-options "-O2 -Wall" } */
+
+#include 
+
+svuint64_t 

Re: [committed 2/2] libstdc++: Use GCC's predefined macro for endianness [PR104080]

2022-01-18 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 18, 2022 at 02:44:34PM -0500, Patrick Palka via Gcc-patches wrote:
> On Tue, Jan 18, 2022 at 5:12 AM Jonathan Wakely  wrote:
> >
> > Tested x86_64-linux, pushed to trunk.
> >
> >
> > Instead of hardcoded preprocessor conditionals with explicit target
> > checks, just rely on the fact that __BYTE_ORDER__ is always defined by
> > GCC.
> 
> Thanks a lot for fixing these!  I apparently missed removing this
> batch of #includes from the amalgamation in r12-6647.  For
> completeness I suppose we should remove these #includes too.   I
> wonder if we can rely on __BYTE_ORDER__ being defined by other
> compilers?

clang++ 8 and later defines, them, ICC 16+ too.

Jakub



Re: [committed 2/2] libstdc++: Use GCC's predefined macro for endianness [PR104080]

2022-01-18 Thread Patrick Palka via Gcc-patches
On Tue, 18 Jan 2022, Patrick Palka wrote:

> On Tue, Jan 18, 2022 at 5:12 AM Jonathan Wakely  wrote:
> >
> > Tested x86_64-linux, pushed to trunk.
> >
> >
> > Instead of hardcoded preprocessor conditionals with explicit target
> > checks, just rely on the fact that __BYTE_ORDER__ is always defined by
> > GCC.
> 
> Thanks a lot for fixing these!  I apparently missed removing this
> batch of #includes from the amalgamation in r12-6647.  For
> completeness I suppose we should remove these #includes too.   I
> wonder if we can rely on __BYTE_ORDER__ being defined by other
> compilers?

(N.B. not just for completeness but potentially also for correctness,
since floating_from_chars.cc #includes "fast_float/fast_float.h" into an
anonymous namespace, and we probably shouldn't be #including system
headers into an anonymous namespace..)

> 
> >
> > libstdc++-v3/ChangeLog:
> >
> > PR libstdc++/104080
> > * src/c++17/fast_float/LOCAL_PATCHES: Update.
> > * src/c++17/fast_float/fast_float.h (FASTFLOAT_IS_BIG_ENDIAN):
> > Define in terms of __BYTE_ORDER__.
> > ---
> >  libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES | 1 +
> >  libstdc++-v3/src/c++17/fast_float/fast_float.h  | 4 +++-
> >  2 files changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES 
> > b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES
> > index 447c7ed2cdb..5bb42933398 100644
> > --- a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES
> > +++ b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES
> > @@ -1,3 +1,4 @@
> >  r12-6647
> >  r12-6648
> >  r12-6664
> > +r12-6665
> > diff --git a/libstdc++-v3/src/c++17/fast_float/fast_float.h 
> > b/libstdc++-v3/src/c++17/fast_float/fast_float.h
> > index ee129309ba3..31fb88b8aba 100644
> > --- a/libstdc++-v3/src/c++17/fast_float/fast_float.h
> > +++ b/libstdc++-v3/src/c++17/fast_float/fast_float.h
> > @@ -128,7 +128,9 @@ from_chars_result from_chars_advanced(const char 
> > *first, const char *last,
> >  #define FASTFLOAT_VISUAL_STUDIO 1
> >  #endif
> >
> > -#ifdef _WIN32
> > +#ifdef __BYTE_ORDER__
> > +#define FASTFLOAT_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
> > +#elif defined _WIN32
> >  #define FASTFLOAT_IS_BIG_ENDIAN 0
> >  #else
> >  #if defined(__APPLE__) || defined(__FreeBSD__)
> > --
> > 2.31.1
> >
> 



Re: [committed 2/2] libstdc++: Use GCC's predefined macro for endianness [PR104080]

2022-01-18 Thread Patrick Palka via Gcc-patches
On Tue, Jan 18, 2022 at 5:12 AM Jonathan Wakely  wrote:
>
> Tested x86_64-linux, pushed to trunk.
>
>
> Instead of hardcoded preprocessor conditionals with explicit target
> checks, just rely on the fact that __BYTE_ORDER__ is always defined by
> GCC.

Thanks a lot for fixing these!  I apparently missed removing this
batch of #includes from the amalgamation in r12-6647.  For
completeness I suppose we should remove these #includes too.   I
wonder if we can rely on __BYTE_ORDER__ being defined by other
compilers?

>
> libstdc++-v3/ChangeLog:
>
> PR libstdc++/104080
> * src/c++17/fast_float/LOCAL_PATCHES: Update.
> * src/c++17/fast_float/fast_float.h (FASTFLOAT_IS_BIG_ENDIAN):
> Define in terms of __BYTE_ORDER__.
> ---
>  libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES | 1 +
>  libstdc++-v3/src/c++17/fast_float/fast_float.h  | 4 +++-
>  2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES 
> b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES
> index 447c7ed2cdb..5bb42933398 100644
> --- a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES
> +++ b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES
> @@ -1,3 +1,4 @@
>  r12-6647
>  r12-6648
>  r12-6664
> +r12-6665
> diff --git a/libstdc++-v3/src/c++17/fast_float/fast_float.h 
> b/libstdc++-v3/src/c++17/fast_float/fast_float.h
> index ee129309ba3..31fb88b8aba 100644
> --- a/libstdc++-v3/src/c++17/fast_float/fast_float.h
> +++ b/libstdc++-v3/src/c++17/fast_float/fast_float.h
> @@ -128,7 +128,9 @@ from_chars_result from_chars_advanced(const char *first, 
> const char *last,
>  #define FASTFLOAT_VISUAL_STUDIO 1
>  #endif
>
> -#ifdef _WIN32
> +#ifdef __BYTE_ORDER__
> +#define FASTFLOAT_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
> +#elif defined _WIN32
>  #define FASTFLOAT_IS_BIG_ENDIAN 0
>  #else
>  #if defined(__APPLE__) || defined(__FreeBSD__)
> --
> 2.31.1
>



Re: [PATCH] RISC-V: Fix use-after-free error in `parse_multiletter_ext'

2022-01-18 Thread Maciej W. Rozycki
On Wed, 19 Jan 2022, Kito Cheng wrote:

> LGTM, thanks :)
> 
> > Avoid undefined arithmetic involving a pointer to a heap allocation that
> > has been freed and move a problematic calculation ahead of the following
> > call to `free' in `riscv_subset_list::parse_multiletter_ext', removing a
> > compilation error:

 Committed, thanks!

  Maciej


Re: [PATCH] git-backport: support renamed .cc files in commit message.

2022-01-18 Thread Harald Anlauf via Gcc-patches

Am 17.01.22 um 22:26 schrieb Martin Liška:

On 1/12/22 16:54, Martin Liška wrote:


There's a patch that enhances git-backport so that it updates commit
messages for files which name ends now with .cc and is still .c on a branch.



The patch has been installed as I've made the renaming now.

Cheers,
Martin



I just made a "git rebase" and had to manually fix the filenames
in the commit message.  Otherwise gcc-verify would complain.

Would it make sense to have something that is clever enough for
rebase to do similar things as git-backport?

Thanks,
Harald


Re: [PATCH] c++: DEPENDENT_OPERATOR_TYPE as type of NTTP [PR104074]

2022-01-18 Thread Jason Merrill via Gcc-patches

On 1/18/22 11:08, Patrick Palka wrote:

We're incorrectly rejecting the below testcase during template argument
coercion because invalid_nontype_parm_type_p returns true for
DEPENDENT_OPERATOR_TYPE.

This patch fixes this by partially rewriting invalid_nontype_parm_type_p
in terms of WILDCARD_TYPE_P, of which DEPENDENT_OPERATOR_TYPE is one.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?


OK


PR c++/104074

gcc/cp/ChangeLog:

* pt.c (invalid_nontype_parm_type_p): Use WILDCARD_TYPE_P so
that we return false for DEPENDENT_OPERATOR_TYPE too.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/nontype-auto20.C: New test.
---
  gcc/cp/pt.c | 14 ++
  gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C |  5 +
  2 files changed, 11 insertions(+), 8 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 0fa4a162354..e57613488d4 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -26931,16 +26931,14 @@ invalid_nontype_parm_type_p (tree type, 
tsubst_flags_t complain)
}
return false;
  }
-  else if (TREE_CODE (type) == TYPENAME_TYPE)
-return false;
-  else if (TREE_CODE (type) == DECLTYPE_TYPE)
-return false;
else if (TREE_CODE (type) == NULLPTR_TYPE)
  return false;
-  /* A bound template template parm could later be instantiated to have a valid
- nontype parm type via an alias template.  */
-  else if (cxx_dialect >= cxx11
-  && TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
+  else if (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
+  && cxx_dialect < cxx11)
+/* Fall through; before C++11 alias templates, a bound ttp
+   always instantiates to a class type.  */;
+  else if (WILDCARD_TYPE_P (type))
+/* Any other wildcard type not already handled above is allowed.  */
  return false;
else if (TREE_CODE (type) == COMPLEX_TYPE)
  /* Fall through.  */;
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C 
b/gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C
new file mode 100644
index 000..03eea91ce09
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C
@@ -0,0 +1,5 @@
+// PR c++/104074
+// { dg-do compile { target c++17 } }
+
+template class gr_sp;
+template using gr_rp = gr_sp<+T::recycle>;




Re: [vect] PR103997: Fix epilogue mode skipping

2022-01-18 Thread Andre Vieira (lists) via Gcc-patches


On 14/01/2022 09:57, Richard Biener wrote:


The 'used_vector_modes' is also a heuristic by itself since it registers
every vector type we query, not only those that are used in the end ...

So it's really all heuristics that can eventually go bad.

IMHO remembering the VF that we ended up with (maybe w/o unrolling)
for each analyzed vector_mode[] might be really the easiest thing to do,
that should make it easy to skip those modes where the VF is larger
or equal as the VF of the main loop for the purpose of epilogue
vectorization.  Likewise those vector_mode[] that failed analysis can
be remembered (with -1U VF for example).

Richard.


I liked the caching suggestion, so here it is. Sorry for the delay, 
wanted to post this after pushing the vect unroll which was waiting on 
some retesting for the rebase.


gcc/ChangeLog:

    PR 103997
    * tree-vect-loop.c (vect_analyze_loop): Fix mode skipping for 
epilogue

    vectorization.
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 
0fe3529b2d1cf36617c04c1d0f1c4c7bb363607c..6d3dbb2187b4096a7db947b6343257a47cd9fb3d
 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -3004,6 +3004,12 @@ vect_analyze_loop (class loop *loop, vec_info_shared 
*shared)
   unsigned int mode_i = 0;
   unsigned HOST_WIDE_INT simdlen = loop->simdlen;
 
+  /* Keep track of the VF for each mode.  Initialize all to 0 which indicates
+ a mode has not been analyzed.  */
+  auto_vec cached_vf_per_mode;
+  for (unsigned i = 0; i < vector_modes.length (); ++i)
+cached_vf_per_mode.safe_push (0);
+
   /* First determine the main loop vectorization mode, either the first
  one that works, starting with auto-detecting the vector mode and then
  following the targets order of preference, or the one with the
@@ -3011,6 +3017,10 @@ vect_analyze_loop (class loop *loop, vec_info_shared 
*shared)
   while (1)
 {
   bool fatal;
+  unsigned int last_mode_i = mode_i;
+  /* Set cached VF to -1 prior to analysis, which indicates a mode has
+failed.  */
+  cached_vf_per_mode[last_mode_i] = -1;
   opt_loop_vec_info loop_vinfo
= vect_analyze_loop_1 (loop, shared, _form_info,
   NULL, vector_modes, mode_i,
@@ -3020,6 +3030,12 @@ vect_analyze_loop (class loop *loop, vec_info_shared 
*shared)
 
   if (loop_vinfo)
{
+ /*  Analyzis has been successful so update the VF value.  The
+ VF should always be a multiple of unroll_factor and we want to
+ capture the original VF here.  */
+ cached_vf_per_mode[last_mode_i]
+   = exact_div (LOOP_VINFO_VECT_FACTOR (loop_vinfo),
+loop_vinfo->suggested_unroll_factor);
  /* Once we hit the desired simdlen for the first time,
 discard any previous attempts.  */
  if (simdlen
@@ -3105,7 +3121,7 @@ vect_analyze_loop (class loop *loop, vec_info_shared 
*shared)
 would be at least as high as the main loop's and we would be
 vectorizing for more scalar iterations than there would be left.  */
   if (!supports_partial_vectors
- && maybe_ge (GET_MODE_NUNITS (vector_modes[mode_i]), first_vinfo_vf))
+ && maybe_ge (cached_vf_per_mode[mode_i], first_vinfo_vf))
{
  mode_i++;
  if (mode_i == vector_modes.length ())


Re: [PATCH] waccess: Look at calls when tracking clobbers [PR104092]

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

On 1/18/22 06:37, Richard Sandiford wrote:

In this PR the waccess pass was fed:

   D.10779 ={v} {CLOBBER};
   VIEW_CONVERT_EXPR(D.10779) = .MASK_LOAD_LANES (addr_5(D), 
64B, _2);
   _7 = D.10779.__val[0];

However, the tracking of m_clobbers only looked at gassigns,
so it missed that the clobber on the first line was overwritten
by the call on the second line.

This patch splits the updating of m_clobbers out into its own
function, called after the check_*() routines, and extends it
to handle both gassigns and gcalls.  I think that makes sense
as an instance of the "read, operate, write" model, with the
new function being part of "write".

Previously only the gimple_clobber_p handling was conditional
on m_check_dangling_p, but I think the whole of the new function
can be.  We only enter stmts into m_clobbers if m_check_dangling_p,
so we only need to remove them under the same condition.


Thanks for the patch.  If you or someone can think of a test case
that's independent of a target, adding one would be very helpful.

Other than that, since I can't approve any changes I CC Jason who
was kind enough to approve the implementation of the warning for
his OK.

Martin



Tested on aarch64-linux-gnu.  OK to install?

Richard


gcc/
PR middle-end/104092
* gimple-ssa-warn-access.cc (pass_waccess::update_clobbers_from_lhs):
New function, split out from...
(pass_waccess::check_stmt): ...here and generalized to calls.
(pass_waccess::check_block): Call it.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/general/pr104092.c: New test.
---
  gcc/gimple-ssa-warn-access.cc | 68 +++
  .../aarch64/sve/acle/general/pr104092.c   |  7 ++
  2 files changed, 48 insertions(+), 27 deletions(-)
  create mode 100644 
gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr104092.c

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index f639807a78a..25066fa6b89 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2094,6 +2094,9 @@ private:
/* Check a non-call statement.  */
void check_stmt (gimple *);
  
+  /* Update the clobber map based on the lhs of a statement.  */

+  void update_clobbers_from_lhs (gimple *);
+
/* Check statements in a basic block.  */
void check_block (basic_block);
  
@@ -4270,33 +4273,6 @@ is_auto_decl (tree x)

  void
  pass_waccess::check_stmt (gimple *stmt)
  {
-  if (m_check_dangling_p && gimple_clobber_p (stmt))
-{
-  /* Ignore clobber statemts in blocks with exceptional edges.  */
-  basic_block bb = gimple_bb (stmt);
-  edge e = EDGE_PRED (bb, 0);
-  if (e->flags & EDGE_EH)
-   return;
-
-  tree var = gimple_assign_lhs (stmt);
-  m_clobbers.put (var, stmt);
-  return;
-}
-
-  if (is_gimple_assign (stmt))
-{
-  /* Clobbered unnamed temporaries such as compound literals can be
-revived.  Check for an assignment to one and remove it from
-M_CLOBBERS.  */
-  tree lhs = gimple_assign_lhs (stmt);
-  while (handled_component_p (lhs))
-   lhs = TREE_OPERAND (lhs, 0);
-
-  if (is_auto_decl (lhs))
-   m_clobbers.remove (lhs);
-  return;
-}
-
if (greturn *ret = dyn_cast  (stmt))
  {
if (optimize && flag_isolate_erroneous_paths_dereference)
@@ -4326,6 +4302,42 @@ pass_waccess::check_stmt (gimple *stmt)
  }
  }
  
+/* Update the clobber map based on the lhs of STMT.  */

+
+void
+pass_waccess::update_clobbers_from_lhs (gimple *stmt)
+{
+  if (gimple_clobber_p (stmt))
+{
+  /* Ignore clobber statements in blocks with exceptional edges.  */
+  basic_block bb = gimple_bb (stmt);
+  edge e = EDGE_PRED (bb, 0);
+  if (e->flags & EDGE_EH)
+   return;
+
+  tree var = gimple_assign_lhs (stmt);
+  m_clobbers.put (var, stmt);
+  return;
+}
+
+  if (is_gimple_assign (stmt) || is_gimple_call (stmt))
+{
+  /* Clobbered unnamed temporaries such as compound literals can be
+revived.  Check for an assignment to one and remove it from
+M_CLOBBERS.  */
+  tree lhs = gimple_get_lhs (stmt);
+  if (!lhs)
+   return;
+
+  while (handled_component_p (lhs))
+   lhs = TREE_OPERAND (lhs, 0);
+
+  if (is_auto_decl (lhs))
+   m_clobbers.remove (lhs);
+  return;
+}
+}
+
  /* Check basic block BB for invalid accesses.  */
  
  void

@@ -4340,6 +4352,8 @@ pass_waccess::check_block (basic_block bb)
check_call (call);
else
check_stmt (stmt);
+  if (m_check_dangling_p)
+   update_clobbers_from_lhs (stmt);
  }
  }
  
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr104092.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr104092.c

new file mode 100644
index 000..c17ece7d82f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr104092.c
@@ -0,0 +1,7 @@
+/* { dg-options "-O2 -Wall" } */
+
+#include 
+

Re: [PATCH] libstdc++: Implement C++20 atomic and atomic

2022-01-18 Thread David Edelsohn via Gcc-patches
This patch introduced new AIX testsuite failures.

PR libstdc++/104101

Thanks, David


[pushed] c++: new (nothrow) array cleanup [PR104007]

2022-01-18 Thread Jason Merrill via Gcc-patches
For this testcase, the cleanup that is supposed to happen if initialization
throws was wrongly being run on the normal control path as well.  This turns
out to be because the EH-only handling in gimple_push_cleanup didn't apply
to conditional cleanups such as we have for nothrow new, since we check
whether the result is non-null before proceeding with the initialization.

Tested x86_64-pc-linux-gnu, applying to trunk as obvious.

PR c++/104007

gcc/ChangeLog:

* gimplify.c (gimple_push_cleanup): Handle eh_only in conditional
context.

gcc/testsuite/ChangeLog:

* g++.dg/eh/new2.C: New test.
---
 gcc/gimplify.cc|  1 +
 gcc/testsuite/g++.dg/eh/new2.C | 10 ++
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/eh/new2.C

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index ab9874a2438..bf2f60cce9a 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -6885,6 +6885,7 @@ gimple_push_cleanup (tree var, tree cleanup, bool 
eh_only, gimple_seq *pre_p,
  cleanup = build3 (COND_EXPR, void_type_node, flag, cleanup, NULL);
  gimplify_stmt (, _stmts);
  wce = gimple_build_wce (cleanup_stmts);
+ gimple_wce_set_cleanup_eh_only (wce, eh_only);
 
  gimplify_seq_add_stmt (_ctxp->conditional_cleanups, ffalse);
  gimplify_seq_add_stmt (_ctxp->conditional_cleanups, wce);
diff --git a/gcc/testsuite/g++.dg/eh/new2.C b/gcc/testsuite/g++.dg/eh/new2.C
new file mode 100644
index 000..d4a1abfbf85
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/new2.C
@@ -0,0 +1,10 @@
+// PR c++/104007
+// { dg-do run }
+
+extern "C" void abort();
+#include 
+
+struct S { ~S() { abort(); } };
+int main() {
+  new (std::nothrow) S[1];
+}

base-commit: 76fe494230477a69f8fa8c8ca2d493acaf343eb1
-- 
2.27.0



Re: [PATCH] rs6000: fix last -Wformat-diag

2022-01-18 Thread Segher Boessenkool
On Tue, Jan 18, 2022 at 05:21:30PM +0100, Martin Liška wrote:
> I'm going to install the following -Wformat-diag that is based on Segher's 
> wording.

Thanks!

(But please fix the format=flawed:
> Content-Type: text/plain; charset=UTF-8; format=flowed
)


Segher


[PATCH] RISC-V: Document the degree of position independence that medany affords

2022-01-18 Thread Palmer Dabbelt
The code generated by -mcmodel=medany is defined to be
position-independent, but is not guaranteed to function correctly when
linked into position-independent executables or libraries.  See the
recent discussion at the psABI specification [1] for more details.

It would be better to reject these invalid sequences when linking, but
as pointed out in a recent LD bug [2] there may be some compatibility
issues related to the PCREL_HI20 relocations used to initialize GP.
Given the complexity here it's unlikely we'll be able to reject these
sequences any time soon, so instead just document that these may not
work.

[1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/245
[2]: https://sourceware.org/bugzilla/show_bug.cgi?id=28789

gcc/ChangeLog:

* doc/invoke.texi: Document the degree of position independence
that -mcmodel=medany affords.

Signed-off-by: Palmer Dabbelt 

---

Changes since v1:

* Fix spelling of "guaranteed", twice.
* Reference the binutils bug on rejecting these sequences, for more
  context.
---
 gcc/doc/invoke.texi | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 5504971ea81..7bca621535f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27568,6 +27568,10 @@ Generate code for the medium-any code model. The 
program and its statically
 defined symbols must be within any single 2 GiB address range. Programs can be
 statically or dynamically linked.
 
+The code generated by the medium-any code model is position-independent, but is
+not guaranteed to function correctly when linked into position-independent
+executables or libraries.
+
 @item -mexplicit-relocs
 @itemx -mno-exlicit-relocs
 Use or do not use assembler relocation operators when dealing with symbolic
-- 
2.32.0



[PATCH] libgcc: Align __EH_FRAME_BEGIN__ to pointer size

2022-01-18 Thread H.J. Lu via Gcc-patches
Aligne __EH_FRAME_BEGIN__ to pointer size since gcc/unwind-dw2-fde.h has

/* The first few fields of a CIE.  The CIE_id field is 0 for a CIE,
   to distinguish it from a valid FDE.  FDEs are aligned to an addressing
   unit boundary, but the fields within are unaligned.  */
struct dwarf_cie
{
  uword length;
  sword CIE_id;
  ubyte version;
  unsigned char augmentation[];
} __attribute__ ((packed, aligned (__alignof__ (void *;

/* The first few fields of an FDE.  */
struct dwarf_fde
{
  uword length;
  sword CIE_delta;
  unsigned char pc_begin[];
} __attribute__ ((packed, aligned (__alignof__ (void *;

which indicates that CIE/FDE should be aligned at the pointer size.

PR libgcc/27576
* crtstuff.c (__EH_FRAME_BEGIN__): Aligned to pointer size.
---
 libgcc/crtstuff.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
index b98b86a5a88..b0d0062ad5b 100644
--- a/libgcc/crtstuff.c
+++ b/libgcc/crtstuff.c
@@ -261,7 +261,8 @@ STATIC func_ptr __DTOR_LIST__[1]
 /* Stick a label at the beginning of the frame unwind info so we can register
and deregister it with the exception handling library code.  */
 STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
- __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
+ __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__),
+   aligned(__alignof__ (void *
  = { };
 #endif /* USE_EH_FRAME_REGISTRY */
 
-- 
2.34.1



Re: [PATCH] RISC-V: Fix use-after-free error in `parse_multiletter_ext'

2022-01-18 Thread Kito Cheng via Gcc-patches
LGTM, thanks :)

On Wed, Jan 19, 2022 at 12:59 AM Maciej W. Rozycki  wrote:
>
> Avoid undefined arithmetic involving a pointer to a heap allocation that
> has been freed and move a problematic calculation ahead of the following
> call to `free' in `riscv_subset_list::parse_multiletter_ext', removing a
> compilation error:
>
> .../gcc/common/config/riscv/riscv-common.cc: In member function 'const char* 
> riscv_subset_list::parse_multiletter_ext(const char*, const char*, const 
> char*)':
> .../gcc/common/config/riscv/riscv-common.cc:905:27: error: pointer 'subset' 
> used after 'void free(void*)' [-Werror=use-after-free]
>   905 |   p += end_of_version - subset;
>   |~~~^~~~
> .../gcc/common/config/riscv/riscv-common.cc:904:12: note: call to 'void 
> free(void*)' here
>   904 |   free (subset);
>   |   ~^~~~
> cc1plus: all warnings being treated as errors
> make[2]: *** [Makefile:2428: riscv-common.o] Error 1
>
> and a build regression from commit 671a283636de ("Add -Wuse-after-free
> [PR80532].").
>
> gcc/
> * common/config/riscv/riscv-common.cc
> (riscv_subset_list::parse_multiletter_ext): Move pointer
> arithmetic ahead of `free'.
> ---
>  gcc/common/config/riscv/riscv-common.cc |2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> gcc-riscv-parse-multiletter-ext-free.diff
> Index: gcc/gcc/common/config/riscv/riscv-common.cc
> ===
> --- gcc.orig/gcc/common/config/riscv/riscv-common.cc
> +++ gcc/gcc/common/config/riscv/riscv-common.cc
> @@ -901,8 +901,8 @@ riscv_subset_list::parse_multiletter_ext
> }
>
>add (subset, major_version, minor_version, explicit_version_p, false);
> -  free (subset);
>p += end_of_version - subset;
> +  free (subset);
>
>if (*p != '\0' && *p != '_')
> {


[PATCH] RISC-V: Fix use-after-free error in `parse_multiletter_ext'

2022-01-18 Thread Maciej W. Rozycki
Avoid undefined arithmetic involving a pointer to a heap allocation that 
has been freed and move a problematic calculation ahead of the following 
call to `free' in `riscv_subset_list::parse_multiletter_ext', removing a 
compilation error:

.../gcc/common/config/riscv/riscv-common.cc: In member function 'const char* 
riscv_subset_list::parse_multiletter_ext(const char*, const char*, const 
char*)':
.../gcc/common/config/riscv/riscv-common.cc:905:27: error: pointer 'subset' 
used after 'void free(void*)' [-Werror=use-after-free]
  905 |   p += end_of_version - subset;
  |~~~^~~~
.../gcc/common/config/riscv/riscv-common.cc:904:12: note: call to 'void 
free(void*)' here
  904 |   free (subset);
  |   ~^~~~
cc1plus: all warnings being treated as errors
make[2]: *** [Makefile:2428: riscv-common.o] Error 1

and a build regression from commit 671a283636de ("Add -Wuse-after-free 
[PR80532].").

gcc/
* common/config/riscv/riscv-common.cc 
(riscv_subset_list::parse_multiletter_ext): Move pointer 
arithmetic ahead of `free'.
---
 gcc/common/config/riscv/riscv-common.cc |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

gcc-riscv-parse-multiletter-ext-free.diff
Index: gcc/gcc/common/config/riscv/riscv-common.cc
===
--- gcc.orig/gcc/common/config/riscv/riscv-common.cc
+++ gcc/gcc/common/config/riscv/riscv-common.cc
@@ -901,8 +901,8 @@ riscv_subset_list::parse_multiletter_ext
}
 
   add (subset, major_version, minor_version, explicit_version_p, false);
-  free (subset);
   p += end_of_version - subset;
+  free (subset);
 
   if (*p != '\0' && *p != '_')
{


Re: [PATCH] c++: Further address_compare fixes [PR89074]

2022-01-18 Thread Jason Merrill via Gcc-patches

On 1/18/22 11:40, Jakub Jelinek wrote:

On Tue, Jan 18, 2022 at 11:25:38AM -0500, Jason Merrill wrote:

Can you please comment on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86369#c1
then?


Done.


Thanks.


About the rest of the patch, I thought I had seen richi comment on IRC (but
can't find the comment now) that these cases where we could give a constant
answer but decide not to because of C++ rules should be handled in the front
end rather than generic code, which makes sense to me; that is, use
folding_initializer only for giving more constant results, not for giving
fewer constant results.  Maybe add another flag for limiting constant
results if we think it's significantly easier to recognize these cases in
fold?


I'm afraid avoiding the match.pd & fold-const code here would be a lot of
work.
The match.pd code looks like:
(for cmp (simple_comparison)
  (simplify
   (cmp (convert1?@2 addr@0) (convert2? addr@1))
   (with
{
  poly_int64 off0, off1;
  tree base0, base1;
  int equal = address_compare (cmp, TREE_TYPE (@2), @0, @1, base0, base1,
   off0, off1, GENERIC);
}
(if (equal == 1)
 (switch
  (if (cmp == EQ_EXPR && (known_eq (off0, off1) || known_ne (off0, off1)))
   { constant_boolean_node (known_eq (off0, off1), type); })
  (if (cmp == NE_EXPR && (known_eq (off0, off1) || known_ne (off0, off1)))
   { constant_boolean_node (known_ne (off0, off1), type); })
  (if (cmp == LT_EXPR && (known_lt (off0, off1) || known_ge (off0, off1)))
   { constant_boolean_node (known_lt (off0, off1), type); })
  (if (cmp == LE_EXPR && (known_le (off0, off1) || known_gt (off0, off1)))
   { constant_boolean_node (known_le (off0, off1), type); })
  (if (cmp == GE_EXPR && (known_ge (off0, off1) || known_lt (off0, off1)))
   { constant_boolean_node (known_ge (off0, off1), type); })
  (if (cmp == GT_EXPR && (known_gt (off0, off1) || known_le (off0, off1)))
   { constant_boolean_node (known_gt (off0, off1), type); }))
 (if (equal == 0)
  (switch
   (if (cmp == EQ_EXPR)
{ constant_boolean_node (false, type); })
   (if (cmp == NE_EXPR)
{ constant_boolean_node (true, type); })))
and
(for minmax (min max)
  cmp (lt gt)
  (simplify
   (minmax (convert1?@2 addr@0) (convert2?@3 addr@1))
   (with
{
  poly_int64 off0, off1;
  tree base0, base1;
  int equal = address_compare (cmp, TREE_TYPE (@2), @0, @1, base0, base1,
   off0, off1, GENERIC);
}
(if (equal == 1)
 (if (minmax == MIN_EXPR)
  (if (known_le (off0, off1))
   @2
   (if (known_gt (off0, off1))
@3))
  (if (known_ge (off0, off1))
   @2
   (if (known_lt (off0, off1))
@3)))
and address_compare is a fairly large routine and uses equal_address_to
which is another quite large routine and we'd need to redo big chunks
of that code in constexpr.c.
Not using match.pd and fold-const.cc at all during constexpr evaluation
(except perhaps for folding of builtins) seems like a nice ultimate goal
(we would only optimize what we are required to and nothing else, at least
in the strict modes), but I'm afraid it would take several years to implement.

Having another flag next to folding_initialize that would be used in
fold-const.c in the meantime looks fine to me, any suggestion on how to call
it?


flag_unspecified_compare?

Jason



Re: [PATCH] c++: Fix handling of temporaries with consteval ctors and non-trivial dtors [PR104055]

2022-01-18 Thread Jason Merrill via Gcc-patches

On 1/18/22 09:26, Jakub Jelinek wrote:

On Tue, Jan 18, 2022 at 09:08:03AM -0500, Jason Merrill wrote:

which makes call a TARGET_EXPR with the dtor in TARGET_EXPR_CLEANUP,
but then call cxx_constant_value on it.  In cxx_eval_outermost_constant_expr
it triggers the:
else if (TREE_CODE (t) != CONSTRUCTOR)
  {
r = get_target_expr_sfinae (r, tf_warning_or_error | tf_no_cleanup);
TREE_CONSTANT (r) = true;
  }
which wraps the CONSTRUCTOR r into a new TARGET_EXPR, but one without
dtors (I think we need e.g. the TREE_CONSTANT for the callers),
and finally build_over_call uses that.


Looks like you added the tf_no_cleanup in r10-3661 (constexpr new). Maybe
that should only be added if TARGET_EXPR_CLEANUP (t) is null?


I thought about that, but I'm worried that if the cleanup action
is non-empty, then the TREE_CONSTANT (r) = true; after it isn't appropriate,
because the TARGET_EXPR has side-effects.


Hmm.  If we e.g. pull out a subobject value from the TARGET_EXPR 
temporary, we still need to run the cleanup, so we don't want to 
optimize the temporary away, so not setting TREE_CONSTANT sounds right.



And the callers like cxx_constant_value_sfinae just return error_mark_node
if it isn't set:
   if (sfinae && !TREE_CONSTANT (r))
 r = error_mark_node;


Yes.  Is that wrong?  I guess we need to be more careful about adjusting 
the arguments to cxx_constant_value_sfinae if we still want a constant 
value.


Perhaps we also still want to set tf_no_cleanup if object is nonnull, 
since in that case we know the prvalue is going to be an initializer 
rather than a temporary.


Jason



Re: [PATCH] nvptx: fix -Wformat-diag warnings

2022-01-18 Thread Martin Liška

On 1/18/22 17:36, Thomas Schwinge wrote:

Similar here: '%'.


Grüße
  Thomas


I see, thank you for the review.

Can you please test for me the following patch candidate?

Thanks,
MartinFrom de5cafe27131c002e6634dd7417577452eb1aac8 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Tue, 18 Jan 2022 17:50:02 +0100
Subject: [PATCH] nvptx: update fix for -Wformat-diag

gcc/ChangeLog:

	* config/nvptx/nvptx.cc (nvptx_goacc_validate_dims_1): Update
	warning messages.

libgomp/ChangeLog:

	* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c:
	Update scanning patterns.
	* testsuite/libgomp.oacc-c-c++-common/kernels-loop-2.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/pr85486.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/pr95270-1.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/routine-nohost-2.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c: Likewise.
	* testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/derivedtypes-arrays-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/kernels-loop-2.f95: Likewise.
	* testsuite/libgomp.oacc-fortran/parallel-dims.f90: Likewise.
---
 gcc/config/nvptx/nvptx.cc|  8 
 .../libgomp.oacc-c-c++-common/acc_prof-kernels-1.c   |  4 ++--
 .../libgomp.oacc-c-c++-common/kernels-loop-2.c   |  4 ++--
 .../libgomp.oacc-c-c++-common/parallel-dims.c| 12 ++--
 .../testsuite/libgomp.oacc-c-c++-common/pr85486.c|  2 +-
 .../testsuite/libgomp.oacc-c-c++-common/pr95270-1.c  |  4 ++--
 .../libgomp.oacc-c-c++-common/routine-nohost-2.c |  2 +-
 .../libgomp.oacc-c-c++-common/struct-copyout-1.c |  2 +-
 .../libgomp.oacc-c-c++-common/struct-copyout-2.c |  2 +-
 .../libgomp.oacc-fortran/attach-descriptor-1.f90 |  2 +-
 .../libgomp.oacc-fortran/derivedtypes-arrays-1.f90   |  2 +-
 .../libgomp.oacc-fortran/kernels-loop-2.f95  |  4 ++--
 .../testsuite/libgomp.oacc-fortran/parallel-dims.f90 |  4 ++--
 13 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index a829bd3fe7a..db6a405d623 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -5894,7 +5894,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level, unsigned used)
 
   if (dims[GOMP_DIM_VECTOR] > PTX_WARP_SIZE)
 	{
-	  vector_reason = G_("using % (%d) due to call to"
+	  vector_reason = G_("using % due to call to"
 			 " vector-partitionable routine, ignoring %d");
 	  dims[GOMP_DIM_VECTOR] = PTX_WARP_SIZE;
 	}
@@ -5902,7 +5902,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level, unsigned used)
 
   if (dims[GOMP_DIM_VECTOR] == 0)
 {
-  vector_reason = G_("using % (%d), ignoring runtime setting");
+  vector_reason = G_("using %, ignoring runtime setting");
   dims[GOMP_DIM_VECTOR] = default_vector_length;
 }
 
@@ -5916,12 +5916,12 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level, unsigned used)
 warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
 		vector_reason != NULL
 		? vector_reason
-		: G_("using % (%d), ignoring %d"),
+		: G_("using %, ignoring %d"),
 		dims[GOMP_DIM_VECTOR], old_dims[GOMP_DIM_VECTOR]);
 
   if (dims[GOMP_DIM_WORKER] != old_dims[GOMP_DIM_WORKER])
 warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
-		G_("using % (%d), ignoring %d"),
+		G_("using %, ignoring %d"),
 		dims[GOMP_DIM_WORKER], old_dims[GOMP_DIM_WORKER]);
 
   if (oacc_default_dims_p)
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c
index cb9b6cf8856..d7f47627438 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c
@@ -189,7 +189,7 @@ int main()
 int x[N];
 #pragma acc kernels \
   num_gangs (30) num_workers (3) vector_length (5)
-/* { dg-prune-output "using .vector_length. \\(32\\), ignoring 5" } */
+/* { dg-prune-output "using .vector_length \\(32\\)., ignoring 5" } */
 {
   for (int i = 0; i < N; ++i)
 	x[i] = i * i;
@@ -214,7 +214,7 @@ int main()
 int x[N];
 #pragma acc kernels \
   num_gangs (num_gangs) num_workers (num_workers) vector_length (vector_length)
-/* { dg-prune-output "using .vector_length. \\(32\\), ignoring runtime setting" } */
+/* { dg-prune-output "using .vector_length \\(32\\)., ignoring runtime setting" } */
 {
   for (int i = 0; i < N; ++i)
 	x[i] = i * i;
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/kernels-loop-2.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/kernels-loop-2.c
index 640951b4f85..591c0f322ef 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/kernels-loop-2.c
+++ 

Re: [PATCH] c++: Further address_compare fixes [PR89074]

2022-01-18 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 18, 2022 at 11:25:38AM -0500, Jason Merrill wrote:
> > Can you please comment on 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86369#c1
> > then?
> 
> Done.

Thanks.

> About the rest of the patch, I thought I had seen richi comment on IRC (but
> can't find the comment now) that these cases where we could give a constant
> answer but decide not to because of C++ rules should be handled in the front
> end rather than generic code, which makes sense to me; that is, use
> folding_initializer only for giving more constant results, not for giving
> fewer constant results.  Maybe add another flag for limiting constant
> results if we think it's significantly easier to recognize these cases in
> fold?

I'm afraid avoiding the match.pd & fold-const code here would be a lot of
work.
The match.pd code looks like:
(for cmp (simple_comparison)
 (simplify
  (cmp (convert1?@2 addr@0) (convert2? addr@1))
  (with
   {
 poly_int64 off0, off1;
 tree base0, base1;
 int equal = address_compare (cmp, TREE_TYPE (@2), @0, @1, base0, base1,
  off0, off1, GENERIC);
   }
   (if (equal == 1)
(switch
 (if (cmp == EQ_EXPR && (known_eq (off0, off1) || known_ne (off0, off1)))
  { constant_boolean_node (known_eq (off0, off1), type); })
 (if (cmp == NE_EXPR && (known_eq (off0, off1) || known_ne (off0, off1)))
  { constant_boolean_node (known_ne (off0, off1), type); })
 (if (cmp == LT_EXPR && (known_lt (off0, off1) || known_ge (off0, off1)))
  { constant_boolean_node (known_lt (off0, off1), type); })
 (if (cmp == LE_EXPR && (known_le (off0, off1) || known_gt (off0, off1)))
  { constant_boolean_node (known_le (off0, off1), type); })
 (if (cmp == GE_EXPR && (known_ge (off0, off1) || known_lt (off0, off1)))
  { constant_boolean_node (known_ge (off0, off1), type); })
 (if (cmp == GT_EXPR && (known_gt (off0, off1) || known_le (off0, off1)))
  { constant_boolean_node (known_gt (off0, off1), type); }))
(if (equal == 0)
 (switch
  (if (cmp == EQ_EXPR)
   { constant_boolean_node (false, type); })
  (if (cmp == NE_EXPR)
   { constant_boolean_node (true, type); })))
and
(for minmax (min max)
 cmp (lt gt)
 (simplify
  (minmax (convert1?@2 addr@0) (convert2?@3 addr@1))
  (with
   {
 poly_int64 off0, off1;
 tree base0, base1;
 int equal = address_compare (cmp, TREE_TYPE (@2), @0, @1, base0, base1,
  off0, off1, GENERIC);
   }
   (if (equal == 1)
(if (minmax == MIN_EXPR)
 (if (known_le (off0, off1))
  @2
  (if (known_gt (off0, off1))
   @3))
 (if (known_ge (off0, off1))
  @2
  (if (known_lt (off0, off1))
   @3)))
and address_compare is a fairly large routine and uses equal_address_to
which is another quite large routine and we'd need to redo big chunks
of that code in constexpr.c.
Not using match.pd and fold-const.cc at all during constexpr evaluation
(except perhaps for folding of builtins) seems like a nice ultimate goal
(we would only optimize what we are required to and nothing else, at least
in the strict modes), but I'm afraid it would take several years to implement.

Having another flag next to folding_initialize that would be used in
fold-const.c in the meantime looks fine to me, any suggestion on how to call
it?

Jakub



[committed] libstdc++: Fix suggested alternative to std::ptr_fun

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


libstdc++-v3/ChangeLog:

* include/bits/stl_function.h (ptr_fun): Fix suggestion for
non-deprecated alternative.
---
 libstdc++-v3/include/bits/stl_function.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_function.h 
b/libstdc++-v3/include/bits/stl_function.h
index a1a770dc2de..25badd5988a 100644
--- a/libstdc++-v3/include/bits/stl_function.h
+++ b/libstdc++-v3/include/bits/stl_function.h
@@ -1121,7 +1121,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
   template
-_GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
+_GLIBCXX11_DEPRECATED_SUGGEST("std::function")
 inline pointer_to_unary_function<_Arg, _Result>
 ptr_fun(_Result (*__x)(_Arg))
 { return pointer_to_unary_function<_Arg, _Result>(__x); }
@@ -1148,7 +1148,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
   template
-_GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
+_GLIBCXX11_DEPRECATED_SUGGEST("std::function")
 inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
 ptr_fun(_Result (*__x)(_Arg1, _Arg2))
 { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
-- 
2.31.1



[committed] libstdc++: Define for C++23

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


This adds the C++23  header, as proposed by P0943R6, for
compatibility with C code.

There are still some ABI differences between atomic_xxx in C and C++
std::atomic_xxx in C++, so this only provides source compatibility, not
binary compatibility.

libstdc++-v3/ChangeLog:

* include/Makefile.am: Install new header.
* include/Makefile.in: Regenerate.
* include/c_compatibility/stdatomic.h: New file.
* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc: New test.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 .../include/c_compatibility/stdatomic.h   | 124 +
 .../headers/stdatomic.h/c_compat.cc   | 130 ++
 4 files changed, 256 insertions(+)
 create mode 100644 libstdc++-v3/include/c_compatibility/stdatomic.h
 create mode 100644 
libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index d1431926cdd..43f7f9f240d 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -850,6 +850,7 @@ c_compatibility_headers = \
${c_compatibility_srcdir}/fenv.h \
${c_compatibility_srcdir}/tgmath.h \
${c_compatibility_srcdir}/math.h \
+   ${c_compatibility_srcdir}/stdatomic.h \
${c_compatibility_srcdir}/stdlib.h
 endif
 
diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h 
b/libstdc++-v3/include/c_compatibility/stdatomic.h
new file mode 100644
index 000..852574bd87c
--- /dev/null
+++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
@@ -0,0 +1,124 @@
+// C compatibility header  -*- C++ -*-
+
+// Copyright (C) 2022 The GCC developers
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// .
+
+/** @file include/stdatomic.h
+ *  This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_STDATOMIC_H
+#define _GLIBCXX_STDATOMIC_H
+
+#if __cplusplus > 202002L
+#include 
+
+#define _Atomic(_Tp) std::atomic<_Tp>
+
+using std::memory_order;
+using std::memory_order_relaxed;
+using std::memory_order_consume;
+using std::memory_order_acquire;
+using std::memory_order_release;
+using std::memory_order_acq_rel;
+using std::memory_order_seq_cst;
+using std::atomic_flag;
+using std::atomic_bool;
+using std::atomic_char;
+using std::atomic_schar;
+using std::atomic_uchar;
+using std::atomic_short;
+using std::atomic_ushort;
+using std::atomic_int;
+using std::atomic_uint;
+using std::atomic_long;
+using std::atomic_ulong;
+using std::atomic_llong;
+using std::atomic_ullong;
+#ifdef _GLIBCXX_USE_CHAR8_T
+using std::atomic_char8_t;
+#endif
+using std::atomic_char16_t;
+using std::atomic_char32_t;
+using std::atomic_wchar_t;
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+using std::atomic_int8_t;
+using std::atomic_uint8_t;
+using std::atomic_int16_t;
+using std::atomic_uint16_t;
+using std::atomic_int32_t;
+using std::atomic_uint32_t;
+using std::atomic_int64_t;
+using std::atomic_uint64_t;
+using std::atomic_int_least8_t;
+using std::atomic_uint_least8_t;
+using std::atomic_int_least16_t;
+using std::atomic_uint_least16_t;
+using std::atomic_int_least32_t;
+using std::atomic_uint_least32_t;
+using std::atomic_int_least64_t;
+using std::atomic_uint_least64_t;
+using std::atomic_int_fast8_t;
+using std::atomic_uint_fast8_t;
+using std::atomic_int_fast16_t;
+using std::atomic_uint_fast16_t;
+using std::atomic_int_fast32_t;
+using std::atomic_uint_fast32_t;
+using std::atomic_int_fast64_t;
+using std::atomic_uint_fast64_t;
+#endif
+using std::atomic_intptr_t;
+using std::atomic_uintptr_t;
+using std::atomic_size_t;
+using std::atomic_ptrdiff_t;
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+using std::atomic_intmax_t;
+using std::atomic_uintmax_t;
+#endif
+using std::atomic_is_lock_free;
+using std::atomic_load;
+using std::atomic_load_explicit;
+using std::atomic_store;
+using std::atomic_store_explicit;
+using std::atomic_exchange;
+using std::atomic_exchange_explicit;

[committed] libstdc++: Declare std::c8rtomb and std::mbrtoc8 if provided by the C library

2022-01-18 Thread Jonathan Wakely via Gcc-patches
From: Tom Honermann 

Tested powerpc64le-linux, pushed to trunk.


This patch completes implementation of the C++20 proposal P0482R6 [1] by
adding declarations of std::c8rtomb() and std::mbrtoc8() in  if
provided by the C library in .

This patch addresses feedback provided in response to a previous patch
submission [2].

Autoconf changes determine if the C library declares c8rtomb and mbrtoc8
at global scope when uchar.h is included and compiled with either
-fchar8_t or -std=c++20. New _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T
and _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 configuration macros
reflect the probe results. The  header declares these functions
in the std namespace only if available and the _GLIBCXX_USE_CHAR8_T
configuration macro is defined (by default it is defined if the C++20
__cpp_char8_t feature test macro is defined)

Patches to glibc to implement c8rtomb and mbrtoc8 have been submitted [3].

New tests validate the presence of these declarations. The tests pass
trivially if the C library does not provide these functions. Otherwise
they ensure that the functions are declared when  is included
and either -fchar8_t or -std=c++20 is enabled.

1]: WG21 P0482R6
  "char8_t: A type for UTF-8 characters and strings (Revision 6)"
  https://wg21.link/p0482r6

[2]: [PATCH] C++ P0482R6 char8_t: declare std::c8rtomb and std::mbrtoc8
if provided by the C library
  https://gcc.gnu.org/pipermail/libstdc++/2021-June/052685.html

[3]: "C++20 P0482R6 and C2X N2653"
  [Patch 0/3]:
https://sourceware.org/pipermail/libc-alpha/2022-January/135061.html
  [Patch 1/3]:
https://sourceware.org/pipermail/libc-alpha/2022-January/135062.html
  [Patch 2/3]:
https://sourceware.org/pipermail/libc-alpha/2022-January/135063.html
  [Patch 3/3]:
https://sourceware.org/pipermail/libc-alpha/2022-January/135064.html

libstdc++-v3/ChangeLog:

* acinclude.m4: Define config macros if uchar.h provides
c8rtomb() and mbrtoc8().
* config.h.in: Regenerate.
* configure: Regenerate.
* include/c_compatibility/uchar.h (c8rtomb, mbrtoc8): Define.
* include/c_global/cuchar (c8rtomb, mbrtoc8): Likewise.
* include/c_std/cuchar (c8rtomb, mbrtoc8): Likewise.
* testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc:
New test.
* testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc:
New test.
---
 libstdc++-v3/acinclude.m4 | 44 +++
 libstdc++-v3/config.h.in  |  8 ++
 libstdc++-v3/configure| 76 +++
 libstdc++-v3/include/c_compatibility/uchar.h  |  8 ++
 libstdc++-v3/include/c_global/cuchar  | 33 +++-
 libstdc++-v3/include/c_std/cuchar | 35 +
 .../headers/cuchar/functions_std_cxx20.cc | 12 +++
 .../headers/cuchar/functions_std_fchar8_t.cc  | 12 +++
 8 files changed, 227 insertions(+), 1 deletion(-)
 create mode 100644 
libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc
 create mode 100644 
libstdc++-v3/testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 930861e6a94..d996477254c 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -2044,6 +2044,50 @@ AC_DEFUN([GLIBCXX_CHECK_UCHAR_H], [
  namespace std in .])
   fi
 
+  CXXFLAGS="$CXXFLAGS -fchar8_t"
+  if test x"$ac_has_uchar_h" = x"yes"; then
+AC_MSG_CHECKING([for c8rtomb and mbrtoc8 in  with -fchar8_t])
+AC_TRY_COMPILE([#include 
+   namespace test
+   {
+ using ::c8rtomb;
+ using ::mbrtoc8;
+   }
+  ],
+  [], [ac_uchar_c8rtomb_mbrtoc8_fchar8_t=yes],
+  [ac_uchar_c8rtomb_mbrtoc8_fchar8_t=no])
+  else
+ac_uchar_c8rtomb_mbrtoc8_fchar8_t=no
+  fi
+  AC_MSG_RESULT($ac_uchar_c8rtomb_mbrtoc8_fchar8_t)
+  if test x"$ac_uchar_c8rtomb_mbrtoc8_fchar8_t" = x"yes"; then
+AC_DEFINE(_GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T, 1,
+ [Define if c8rtomb and mbrtoc8 functions in  should be
+ imported into namespace std in  for -fchar8_t.])
+  fi
+
+  CXXFLAGS="$CXXFLAGS -std=c++20"
+  if test x"$ac_has_uchar_h" = x"yes"; then
+AC_MSG_CHECKING([for c8rtomb and mbrtoc8 in  with -std=c++20])
+AC_TRY_COMPILE([#include 
+   namespace test
+   {
+ using ::c8rtomb;
+ using ::mbrtoc8;
+   }
+  ],
+  [], [ac_uchar_c8rtomb_mbrtoc8_cxx20=yes],
+  [ac_uchar_c8rtomb_mbrtoc8_cxx20=no])
+  else
+ac_uchar_c8rtomb_mbrtoc8_cxx20=no
+  fi
+  AC_MSG_RESULT($ac_uchar_c8rtomb_mbrtoc8_cxx20)
+  if test x"$ac_uchar_c8rtomb_mbrtoc8_cxx20" = x"yes"; then
+AC_DEFINE(_GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20, 1,
+ 

[committed] libstdc++: Use __cpp_lib_concepts in std::reverse_iterator [PR104098]

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


We should not assume that std::iter_value_t etc. are defined
unconditionally for C++20 mode.

libstdc++-v3/ChangeLog:

PR libstdc++/104098
* include/bits/stl_iterator.h (reverse_iterator): Check
__cpp_lib_concepts instead of __cplusplus.
---
 libstdc++-v3/include/bits/stl_iterator.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h 
b/libstdc++-v3/include/bits/stl_iterator.h
index 549a391d04d..266ddd02a78 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -94,7 +94,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{
*/
 
-#if __cplusplus > 201703L && __cpp_lib_concepts
+#if __cpp_lib_concepts
   namespace __detail
   {
 // Weaken iterator_category _Cat to _Limit if it is derived from that,
@@ -155,7 +155,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 public:
   typedef _Iteratoriterator_type;
   typedef typename __traits_type::pointer  pointer;
-#if __cplusplus <= 201703L
+#if ! __cpp_lib_concepts
   typedef typename __traits_type::difference_type  difference_type;
   typedef typename __traits_type::referencereference;
 #else
-- 
2.31.1



[committed] libstdc++: Fix ambiguous std::pair constructors [PR101124]

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


The deprecated non-standard std::pair constructors that allow
constructing std::pair from an rvalue and
a literal zero where not sufficiently constrained. They were viable when
constructing std::pair, and that case
should work fine using the standard constructors.

Replace the constraints on the non-standard constructors so they are
only viable in cases that should actually be ill-formed according to the
standard.

Also rename __null_ptr_constant to __zero_as_null_pointer_constant so it
matches the name of the -Wzero-as-null-pointer-constant warning. Also
make the text of the deprecated warning describe the problem in more
detail.

libstdc++-v3/ChangeLog:

PR libstdc++/101124
* include/bits/stl_pair.h (pair): Adjust constraints on
deprecated constructors accepting literal zero as null pointer
constant. Improve wording of deprecated attribute.
* testsuite/20_util/pair/cons/99957.cc: Check that deprecated
constructors do not cause ambiguities for copyable types.
---
 libstdc++-v3/include/bits/stl_pair.h  | 85 ---
 .../testsuite/20_util/pair/cons/99957.cc  | 12 ++-
 2 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_pair.h 
b/libstdc++-v3/include/bits/stl_pair.h
index abf2120b590..8564fd1ae9e 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -462,62 +462,81 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: first(__p.first), second(__p.second) { }
 
 #if _GLIBCXX_USE_DEPRECATED
+#if defined(__DEPRECATED)
+# define _GLIBCXX_DEPRECATED_PAIR_CTOR \
+  __attribute__ ((__deprecated__ ("use 'nullptr' instead of '0' to " \
+ "initialize std::pair of move-only " \
+ "type and pointer")))
+#else
+# define _GLIBCXX_DEPRECATED_PAIR_CTOR
+#endif
+
 private:
   /// @cond undocumented
 
   // A type which can be constructed from literal zero, but not nullptr
-  struct __null_ptr_constant
+  struct __zero_as_null_pointer_constant
   {
-   __null_ptr_constant(int __null_ptr_constant::*) { }
+   __zero_as_null_pointer_constant(int __zero_as_null_pointer_constant::*)
+   { }
template::value>>
-   __null_ptr_constant(_Tp) = delete;
+   __zero_as_null_pointer_constant(_Tp) = delete;
   };
-
-  // True if type _Up is one of _Tp& or const _Tp&
-  template
-   using __is_lvalue_of
- = __or_, is_same<_Up, _Tp&>>;
-
   /// @endcond
 public:
 
   // Deprecated extensions to DR 811.
+  // These allow construction from an rvalue and a literal zero,
+  // in cases where the standard says the zero should be deduced as int
   template::value
-&& _PCCP::template
-  _DeprConsPair(),
+  __enable_if_t<__and_<__not_>,
+   is_pointer<_T2>,
+   is_constructible<_T1, _U1>,
+   __not_>,
+   is_convertible<_U1, _T1>>::value,
 bool> = true>
-   _GLIBCXX_DEPRECATED_SUGGEST("nullptr")
-   constexpr pair(_U1&& __x, __null_ptr_constant)
-   : first(std::forward<_U1>(__x)), second(nullptr) { }
+   _GLIBCXX_DEPRECATED_PAIR_CTOR
+   constexpr
+   pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
+   : first(std::forward<_U1>(__x)), second(nullptr) { }
 
   template::value
-&& _PCCP::template
-  _DeprConsPair(),
+  __enable_if_t<__and_<__not_>,
+   is_pointer<_T2>,
+   is_constructible<_T1, _U1>,
+   __not_>,
+   __not_>>::value,
 bool> = false>
-   _GLIBCXX_DEPRECATED_SUGGEST("nullptr")
-   explicit constexpr pair(_U1&& __x, __null_ptr_constant)
-   : first(std::forward<_U1>(__x)), second(nullptr) { }
+   _GLIBCXX_DEPRECATED_PAIR_CTOR
+   explicit constexpr
+   pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
+   : first(std::forward<_U1>(__x)), second(nullptr) { }
 
   template::value
-&& _PCCP::template
-  _DeprConsPair(),
+  __enable_if_t<__and_,
+   __not_>,
+   is_constructible<_T2, _U2>,
+   __not_>,
+   is_convertible<_U2, _T2>>::value,
 bool> = true>
-   _GLIBCXX_DEPRECATED_SUGGEST("nullptr")
-   constexpr pair(__null_ptr_constant, _U2&& __y)
-   : first(nullptr), second(std::forward<_U2>(__y)) { }
+   

Re: [PATCH] riscv: fix -Wformat-diag errors.

2022-01-18 Thread Palmer Dabbelt

On Tue, 18 Jan 2022 08:31:12 PST (-0800), gcc-patches@gcc.gnu.org wrote:

Thanks Martin!


Yep.  Seeing this go by, though, I think there's some English issues 
with the original messages.  I'd write it more like this, but I'm never 
100% sure on these things:


   diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
   index 004822bfe6c..2f83303ca51 100644
   --- a/gcc/common/config/riscv/riscv-common.cc
   +++ b/gcc/common/config/riscv/riscv-common.cc
   @@ -375,7 +375,7 @@ riscv_subset_list::add (const char *subset, int 
major_version,
  else
error_at (
  m_loc,
   -  "%<-march=%s%>: extension %qs appear more than one time",
   +  "%<-march=%s%>: extension %qs appears more than one time",
  m_arch,
  subset);
   
   @@ -620,7 +620,7 @@ riscv_subset_list::parsing_subset_version (const char *ext,

if (!major_p)
  {
error_at (m_loc, "%<-march=%s%>: for %<%s%dp%dp?%>, version "
   -  "number with more than 2 level is not supported",
   +  "numbers with more than 2 levels are not supported",
  m_arch, ext, major, version);
return NULL;
  }
   @@ -701,8 +701,9 @@ riscv_subset_list::parse_std_ext (const char *p)
  /* std_ext_p= */ true, _version_p);
  if (major_version != 0 || minor_version != 0)
{
   -  warning_at (m_loc, 0, "version of % will be omitted, please "
   -"specify version for individual extension");
   +  warning_at (m_loc, 0, "version of % will be ignored, please "
   +"specify versions for each individual "
   +"extension");
}
   
  /* We have special rule for G, we disallow rv32gm2p but allow rv32g_zicsr





On Wed, Jan 19, 2022 at 12:23 AM Martin Liška  wrote:


Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.

Martin

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (riscv_subset_list::add):
Wrap keywords with quotes and remove trailing dots.
(riscv_subset_list::parsing_subset_version): Likewise.
(riscv_subset_list::parse_std_ext): Likewise.
(riscv_subset_list::parse_multiletter_ext): Likewise.
* config/riscv/riscv.cc (riscv_handle_type_attribute): Likewise.
---
  gcc/common/config/riscv/riscv-common.cc | 16 
  gcc/config/riscv/riscv.cc   |  4 ++--
  2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index c1d8431c1fa..004822bfe6c 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -375,7 +375,7 @@ riscv_subset_list::add (const char *subset, int 
major_version,
else
error_at (
  m_loc,
- "%<-march=%s%>: Extension `%s' appear more than one time.",
+ "%<-march=%s%>: extension %qs appear more than one time",
  m_arch,
  subset);

@@ -613,14 +613,14 @@ riscv_subset_list::parsing_subset_version (const char 
*ext,
  {
if (!ISDIGIT (*(p+1)))
  {
-   error_at (m_loc, "%<-march=%s%>: Expect number "
- "after %<%dp%>.", m_arch, version);
+   error_at (m_loc, "%<-march=%s%>: expect number "
+ "after %<%dp%>", m_arch, version);
return NULL;
  }
if (!major_p)
  {
-   error_at (m_loc, "%<-march=%s%>: For %<%s%dp%dp?%>, version "
- "number with more than 2 level is not supported.",
+   error_at (m_loc, "%<-march=%s%>: for %<%s%dp%dp?%>, version "
+ "number with more than 2 level is not supported",
  m_arch, ext, major, version);
return NULL;
  }
@@ -701,8 +701,8 @@ riscv_subset_list::parse_std_ext (const char *p)
  /* std_ext_p= */ true, _version_p);
if (major_version != 0 || minor_version != 0)
{
- warning_at (m_loc, 0, "version of `g` will be omitted, please "
-   "specify version for individual extension.");
+ warning_at (m_loc, 0, "version of % will be omitted, please "
+   "specify version for individual extension");
}

/* We have special rule for G, we disallow rv32gm2p but allow 
rv32g_zicsr
@@ -906,7 +906,7 @@ riscv_subset_list::parse_multiletter_ext (const char *p,

if (*p != '\0' && *p != '_')
{
- error_at (m_loc, "%<-march=%s%>: %s must separate with _",
+ error_at (m_loc, "%<-march=%s%>: %s must separate with %<_%>",
m_arch, ext_type_str);
  return 

Re: [PATCH] nvptx: fix -Wformat-diag warnings

2022-01-18 Thread Thomas Schwinge
Hi Martin!

On 2022-01-18T17:22:53+0100, Martin Liška  wrote:
> Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.

> --- a/gcc/config/nvptx/nvptx.cc
> +++ b/gcc/config/nvptx/nvptx.cc
> @@ -5894,7 +5894,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int 
> fn_level, unsigned used)
>
> if (dims[GOMP_DIM_VECTOR] > PTX_WARP_SIZE)
>   {
> -   vector_reason = G_("using vector_length (%d) due to call to"
> +   vector_reason = G_("using % (%d) due to call to"
>" vector-partitionable routine, ignoring %d");
> dims[GOMP_DIM_VECTOR] = PTX_WARP_SIZE;
>   }

Instead of '% (%d)' that should be
'%'.  The '%d' is an argument (in braces) to the
OpenACC 'vector_length' clause.

> @@ -5902,7 +5902,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int 
> fn_level, unsigned used)
>
> if (dims[GOMP_DIM_VECTOR] == 0)
>   {
> -  vector_reason = G_("using vector_length (%d), ignoring runtime 
> setting");
> +  vector_reason = G_("using % (%d), ignoring runtime 
> setting");
> dims[GOMP_DIM_VECTOR] = default_vector_length;
>   }

Same here.

> @@ -5916,12 +5916,12 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], 
> int fn_level, unsigned used)
>   warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
>   vector_reason != NULL
>   ? vector_reason
> - : G_("using vector_length (%d), ignoring %d"),
> + : G_("using % (%d), ignoring %d"),
>   dims[GOMP_DIM_VECTOR], old_dims[GOMP_DIM_VECTOR]);

Same here.

> if (dims[GOMP_DIM_WORKER] != old_dims[GOMP_DIM_WORKER])
>   warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
> - G_("using num_workers (%d), ignoring %d"),
> + G_("using % (%d), ignoring %d"),
>   dims[GOMP_DIM_WORKER], old_dims[GOMP_DIM_WORKER]);

Similar here: '%'.


Grüße
 Thomas


> diff --git a/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-2.C 
> b/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-2.C
> index 520016ab59d..f531bae5f2d 100644
> --- a/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-2.C
> +++ b/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-2.C
> @@ -69,7 +69,7 @@ void workers (void)
>   #pragma acc parallel copyout(res) num_gangs(64) num_workers(64) /* { 
> dg-line l_compute[incr c_compute] } */
> /* { dg-note {variable 'i' declared in block isn't candidate for 
> adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
> l_compute$c_compute } */
> /* { dg-note {variable 'j' declared in block isn't candidate for 
> adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
> l_compute$c_compute } */
> -  /* { dg-warning "using num_workers \\(32\\), ignoring 64" "" { target 
> openacc_nvidia_accel_selected } l_compute$c_compute } */
> +  /* { dg-warning "using .num_workers. \\(32\\), ignoring 64" "" { target 
> openacc_nvidia_accel_selected } l_compute$c_compute } */
> {
>   int i, j;
>   #pragma acc loop gang /* { dg-line l_loop[incr c_loop] } */
> @@ -105,7 +105,7 @@ void vectors (void)
>   #pragma acc parallel copyout(res) num_gangs(64) num_workers(64) /* { 
> dg-line l_compute[incr c_compute] } */
> /* { dg-note {variable 'i' declared in block isn't candidate for 
> adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
> l_compute$c_compute } */
> /* { dg-note {variable 'j' declared in block isn't candidate for 
> adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
> l_compute$c_compute } */
> -  /* { dg-warning "using num_workers \\(32\\), ignoring 64" "" { target 
> openacc_nvidia_accel_selected } l_compute$c_compute } */
> +  /* { dg-warning "using .num_workers. \\(32\\), ignoring 64" "" { target 
> openacc_nvidia_accel_selected } l_compute$c_compute } */
> {
>   int i, j;
>   #pragma acc loop gang worker /* { dg-line l_loop[incr c_loop] } */
> @@ -141,7 +141,7 @@ void gangs_workers_vectors (void)
>   #pragma acc parallel copyout(res) num_gangs(64) num_workers(64) /* { 
> dg-line l_compute[incr c_compute] } */
> /* { dg-note {variable 'i' declared in block isn't candidate for 
> adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
> l_compute$c_compute } */
> /* { dg-note {variable 'j' declared in block isn't candidate for 
> adjusting OpenACC privatization level: not addressable} "" { target *-*-* } 
> l_compute$c_compute } */
> -  /* { dg-warning "using num_workers \\(32\\), ignoring 64" "" { target 
> openacc_nvidia_accel_selected } l_compute$c_compute } */
> +  /* { dg-warning "using .num_workers. \\(32\\), ignoring 64" "" { target 
> openacc_nvidia_accel_selected } l_compute$c_compute } */
> {
>   int i, j;
>   #pragma acc loop collapse(2) gang worker vector /* { dg-line l_loop[incr 
> c_loop] } */
> diff --git a/libgomp/testsuite/libgomp.oacc-c++/privatized-ref-3.C 

Re: [PATCH] riscv: fix -Wformat-diag errors.

2022-01-18 Thread Kito Cheng via Gcc-patches
Thanks Martin!

On Wed, Jan 19, 2022 at 12:23 AM Martin Liška  wrote:
>
> Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.
>
> Martin
>
> gcc/ChangeLog:
>
> * common/config/riscv/riscv-common.cc (riscv_subset_list::add):
> Wrap keywords with quotes and remove trailing dots.
> (riscv_subset_list::parsing_subset_version): Likewise.
> (riscv_subset_list::parse_std_ext): Likewise.
> (riscv_subset_list::parse_multiletter_ext): Likewise.
> * config/riscv/riscv.cc (riscv_handle_type_attribute): Likewise.
> ---
>   gcc/common/config/riscv/riscv-common.cc | 16 
>   gcc/config/riscv/riscv.cc   |  4 ++--
>   2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/gcc/common/config/riscv/riscv-common.cc 
> b/gcc/common/config/riscv/riscv-common.cc
> index c1d8431c1fa..004822bfe6c 100644
> --- a/gcc/common/config/riscv/riscv-common.cc
> +++ b/gcc/common/config/riscv/riscv-common.cc
> @@ -375,7 +375,7 @@ riscv_subset_list::add (const char *subset, int 
> major_version,
> else
> error_at (
>   m_loc,
> - "%<-march=%s%>: Extension `%s' appear more than one time.",
> + "%<-march=%s%>: extension %qs appear more than one time",
>   m_arch,
>   subset);
>
> @@ -613,14 +613,14 @@ riscv_subset_list::parsing_subset_version (const char 
> *ext,
>   {
> if (!ISDIGIT (*(p+1)))
>   {
> -   error_at (m_loc, "%<-march=%s%>: Expect number "
> - "after %<%dp%>.", m_arch, version);
> +   error_at (m_loc, "%<-march=%s%>: expect number "
> + "after %<%dp%>", m_arch, version);
> return NULL;
>   }
> if (!major_p)
>   {
> -   error_at (m_loc, "%<-march=%s%>: For %<%s%dp%dp?%>, version "
> - "number with more than 2 level is not supported.",
> +   error_at (m_loc, "%<-march=%s%>: for %<%s%dp%dp?%>, version "
> + "number with more than 2 level is not supported",
>   m_arch, ext, major, version);
> return NULL;
>   }
> @@ -701,8 +701,8 @@ riscv_subset_list::parse_std_ext (const char *p)
>   /* std_ext_p= */ true, _version_p);
> if (major_version != 0 || minor_version != 0)
> {
> - warning_at (m_loc, 0, "version of `g` will be omitted, please "
> -   "specify version for individual extension.");
> + warning_at (m_loc, 0, "version of % will be omitted, please "
> +   "specify version for individual extension");
> }
>
> /* We have special rule for G, we disallow rv32gm2p but allow 
> rv32g_zicsr
> @@ -906,7 +906,7 @@ riscv_subset_list::parse_multiletter_ext (const char *p,
>
> if (*p != '\0' && *p != '_')
> {
> - error_at (m_loc, "%<-march=%s%>: %s must separate with _",
> + error_at (m_loc, "%<-march=%s%>: %s must separate with %<_%>",
> m_arch, ext_type_str);
>   return NULL;
> }
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 7c806780883..8314864d5e7 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -3309,8 +3309,8 @@ riscv_handle_type_attribute (tree *node 
> ATTRIBUTE_UNUSED, tree name, tree args,
>   && strcmp (string, "machine"))
> {
>   warning (OPT_Wattributes,
> -  "argument to %qE attribute is not \"user\", 
> \"supervisor\", or \"machine\"",
> -  name);
> +  "argument to %qE attribute is not %, 
> %, "
> +  "or %", name);
>   *no_add_attrs = true;
> }
> }
> --
> 2.34.1
>
>


Enable -Werror=format-diag for bootstrap

2022-01-18 Thread Martin Liška

On 1/16/22 01:31, Martin Sebor wrote:

Hello.

(I think your message in unrelated to this email thread).


Martin, I've looked into removing the -Wno-error for this warning
for just a subset of targets.  It seems doable with some hardcoding
in configure.ac but if you're planning to do the cleanup for all of
them I'm wondering if we should even bother.  What do you think?


Yes, I've just installed patches that should address all -Wformat-diag errors
for all targets we have.

Please enable the corresponding -Werror for bootstrap.

Thanks,
Martin



Martin




Re: [PATCH] c++: Further address_compare fixes [PR89074]

2022-01-18 Thread Jason Merrill via Gcc-patches

On 1/18/22 05:17, Jakub Jelinek wrote:

On Thu, Jan 13, 2022 at 04:18:33PM -0500, Jason Merrill wrote:

Note, address_compare has some special cases, e.g. it assumes that
static vars are never adjacent to automatic vars, which is the case
for the usual layout where automatic vars are on the stack and after
.rodata/.data sections there is heap:
/* Assume that automatic variables can't be adjacent to global
   variables.  */
else if (is_global_var (base0) != is_global_var (base1))
  ;
Is it ok that during constant evaluation we don't treat those as undefined
behavior, or shall that be with !folding_initializer && too?


I guess that's undefined as well.


Ok, following patch seems to guard that too


Another special case is:
if ((DECL_P (base0) && TREE_CODE (base1) == STRING_CST)
 || (TREE_CODE (base0) == STRING_CST && DECL_P (base1))
 || (TREE_CODE (base0) == STRING_CST
 && TREE_CODE (base1) == STRING_CST
 && ioff0 >= 0 && ioff1 >= 0
 && ioff0 < TREE_STRING_LENGTH (base0)
 && ioff1 < TREE_STRING_LENGTH (base1)
/* This is a too conservative test that the STRING_CSTs
   will not end up being string-merged.  */
 && strncmp (TREE_STRING_POINTER (base0) + ioff0,
 TREE_STRING_POINTER (base1) + ioff1,
 MIN (TREE_STRING_LENGTH (base0) - ioff0,
  TREE_STRING_LENGTH (base1) - ioff1)) != 0))
  ;
else if (!DECL_P (base0) || !DECL_P (base1))
  return 2;
Here we similarly assume that vars aren't adjacent to string literals
or vice versa.  Do we need to stick !folding_initializer && to those
DECL_P vs. STRING_CST cases?


Seems so.


and this too


Though, because of the return 2; for
non-DECL_P that would mean rejecting comparisons like  == &"foobar"[3]
etc. which ought to be fine, no?  So perhaps we need to watch for
decls. vs. STRING_CSTs like for DECLs whether the address is at the start
or at the end of the string literal or somewhere in between (at least
for folding_initializer)?


Agreed.


and this as well.
Furthermore I've fixed constexpr-compare2.C by assuming if
folding_initializer that addresses of non-aliased (visibly to the compiler)
FUNCTION_DECLs are different and that functions are non-zero sized for the
purpose of var vs. function comparisons.


And yet another chapter but probably unsolvable is comparison of
string literal addresses.  I think pedantically in C++
&"foo"[0] == &"foo"[0] is undefined behavior, different occurences of
the same string literals might still not be merged in some implementations.


I disagree; it's unspecified whether string literals are merged, but I think
the comparison result is well specified depending on that implementation
behavior.


Can you please comment on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86369#c1
then?


Done.

About the rest of the patch, I thought I had seen richi comment on IRC 
(but can't find the comment now) that these cases where we could give a 
constant answer but decide not to because of C++ rules should be handled 
in the front end rather than generic code, which makes sense to me; that 
is, use folding_initializer only for giving more constant results, not 
for giving fewer constant results.  Maybe add another flag for limiting 
constant results if we think it's significantly easier to recognize 
these cases in fold?



Anyway, the following has been successfully bootstrapped/regtested on
x86_64-linux and i686-linux, ok for trunk?

2022-01-18  Jakub Jelinek  

PR c++/89074
PR c++/104033
* fold-const.c (address_compare): Restrict the decl vs. STRING_CST
or vice versa or STRING_CST vs. STRING_CST or
is_global_var != is_global_var optimizations to !folding_initializer.
Punt for FUNCTION_DECLs with non-zero offsets.  If folding_initializer,
assume non-aliased functions have non-zero size and have different
addresses.  For folding_initializer, punt on comparisons of start
of some object and end of another one, regardless whether it is a decl
or string literal.  Also punt for folding_initializer of
STRING_CST vs. STRING_CST comparisons if the two literals could be
overlapping.

* g++.dg/cpp1y/constexpr-89074-3.C: New test.

--- gcc/fold-const.c.jj 2022-01-17 14:19:08.817376382 +0100
+++ gcc/fold-const.c2022-01-17 15:50:16.687211071 +0100
@@ -16608,21 +16608,27 @@ address_compare (tree_code code, tree ty
HOST_WIDE_INT ioff0 = -1, ioff1 = -1;
off0.is_constant ();
off1.is_constant ();
-  if ((DECL_P (base0) && TREE_CODE (base1) == STRING_CST)
-   || (TREE_CODE (base0) == STRING_CST && DECL_P (base1))
-   || (TREE_CODE (base0) == STRING_CST
-  && TREE_CODE (base1) == STRING_CST
-  && ioff0 >= 0 && ioff1 >= 0
-  && ioff0 < TREE_STRING_LENGTH (base0)
-  && ioff1 < TREE_STRING_LENGTH (base1)
- 

[PATCH] vms: fix -Wformat-diag warnings.

2022-01-18 Thread Martin Liška

Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.

Martin

gcc/ChangeLog:

* config/vms/vms-c.cc (vms_pragma_nostandard): Fix -Wformat-diag
warning.
(vms_pragma_standard): Likewise.
(vms_pragma_extern_prefix): Likewise.
---
 gcc/config/vms/vms-c.cc | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/config/vms/vms-c.cc b/gcc/config/vms/vms-c.cc
index aae67d259ab..2f74fb574cd 100644
--- a/gcc/config/vms/vms-c.cc
+++ b/gcc/config/vms/vms-c.cc
@@ -41,7 +41,7 @@ vms_pragma_nostandard (cpp_reader *pfile ATTRIBUTE_UNUSED)
   tree x;
 
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma __nostandard");
+warning (OPT_Wpragmas, "junk at end of %<#pragma __nostandard%>");
 }
 
 /* '#pragma __standard' is simply ignored.  */

@@ -52,7 +52,7 @@ vms_pragma_standard (cpp_reader *pfile ATTRIBUTE_UNUSED)
   tree x;
 
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma __standard");
+warning (OPT_Wpragmas, "junk at end of %<#pragma __standard%>");
 }
 
 /* Saved member alignment.  */

@@ -271,13 +271,13 @@ vms_pragma_extern_prefix (cpp_reader * ARG_UNUSED (dummy))
 pragma_extern_prefix = saved_extern_prefix;
   else
 warning (OPT_Wpragmas,
- "malformed '#pragma __extern_prefix', ignoring");
+ "malformed %<#pragma __extern_prefix%>, ignoring");
   return;
 }
   else if (tok != CPP_STRING)
 {
   warning (OPT_Wpragmas,
-   "malformed '#pragma __extern_prefix', ignoring");
+   "malformed %<#pragma __extern_prefix%>, ignoring");
 }
   else
 {
--
2.34.1




[PATCH] xtensa: fix -Wformat-diag warnings.

2022-01-18 Thread Martin Liška

Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.

Martin

gcc/ChangeLog:

* config/xtensa/xtensa.cc (print_operand): Fix warnings.
(print_operand_address): Likewise.
(xtensa_multibss_section_type_flags): Likewise.
---
 gcc/config/xtensa/xtensa.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 198bd3c08a0..7023badf0e2 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -2392,7 +2392,7 @@ void
 print_operand (FILE *file, rtx x, int letter)
 {
   if (!x)
-error ("PRINT_OPERAND null pointer");
+error ("% null pointer");
 
   switch (letter)

 {
@@ -2549,7 +2549,7 @@ void
 print_operand_address (FILE *file, rtx addr)
 {
   if (!addr)
-error ("PRINT_OPERAND_ADDRESS, null pointer");
+error ("%, null pointer");
 
   switch (GET_CODE (addr))

 {
@@ -3662,7 +3662,7 @@ xtensa_multibss_section_type_flags (tree decl, const char 
*name, int reloc)
flags |= SECTION_BSS;  /* @nobits */
   else
warning (0, "only uninitialized variables can be placed in a "
-".bss section");
+"%<.bss%> section");
 }
 
   return flags;

--
2.34.1




[PATCH] v850: fix -Wformat-diag warnings.

2022-01-18 Thread Martin Liška

Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.

Martin

gcc/ChangeLog:

* config/v850/v850-c.cc (pop_data_area): Fix -Wformat-diag
warning.
(ghs_pragma_section): Likewise.
(ghs_pragma_interrupt): Likewise.
(ghs_pragma_starttda): Likewise.
(ghs_pragma_startsda): Likewise.
(ghs_pragma_startzda): Likewise.
(ghs_pragma_endtda): Likewise.
(ghs_pragma_endsda): Likewise.
(ghs_pragma_endzda): Likewise.
---
 gcc/config/v850/v850-c.cc | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/config/v850/v850-c.cc b/gcc/config/v850/v850-c.cc
index 0ff0e8c6430..45a3a0d811f 100644
--- a/gcc/config/v850/v850-c.cc
+++ b/gcc/config/v850/v850-c.cc
@@ -64,10 +64,10 @@ static int
 pop_data_area (v850_data_area data_area)
 {
   if (data_area_stack == NULL)
-warning (OPT_Wpragmas, "#pragma GHS end found without "
+warning (OPT_Wpragmas, "%<#pragma%> GHS end found without "
 "previous startXXX");
   else if (data_area != data_area_stack->data_area)
-warning (OPT_Wpragmas, "#pragma GHS endXXX does not match "
+warning (OPT_Wpragmas, "%<#pragma%> GHS endXXX does not match "
 "previous startXXX");
   else
 {
@@ -150,7 +150,7 @@ ghs_pragma_section (cpp_reader * pfile ATTRIBUTE_UNUSED)
   if (type == CPP_COMMA)
repeat = 1;
   else if (type != CPP_EOF)
-   warning (OPT_Wpragmas, "junk at end of #pragma ghs section");
+   warning (OPT_Wpragmas, "junk at end of %<#pragma%> ghs section");
   
   if  (streq (sect, "data"))kind = GHS_SECTION_KIND_DATA;

   else if (streq (sect, "text"))kind = GHS_SECTION_KIND_TEXT;
@@ -181,7 +181,7 @@ ghs_pragma_section (cpp_reader * pfile ATTRIBUTE_UNUSED)
   return;
 
  bad:

-  warning (OPT_Wpragmas, "malformed #pragma ghs section");
+  warning (OPT_Wpragmas, "malformed %<#pragma%> ghs section");
   return;
 
  reset:

@@ -200,7 +200,7 @@ ghs_pragma_interrupt (cpp_reader * pfile ATTRIBUTE_UNUSED)
   tree x;
   
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma ghs interrupt");
+warning (OPT_Wpragmas, "junk at end of %<#pragma%> ghs interrupt");
   
   mark_current_function_as_interrupt ();

 }
@@ -211,7 +211,7 @@ ghs_pragma_starttda (cpp_reader * pfile ATTRIBUTE_UNUSED)
   tree x;
   
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma ghs starttda");
+warning (OPT_Wpragmas, "junk at end of %<#pragma%> ghs starttda");
   
   push_data_area (DATA_AREA_TDA);

 }
@@ -222,7 +222,7 @@ ghs_pragma_startsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
   tree x;
   
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma ghs startsda");
+warning (OPT_Wpragmas, "junk at end of %<#pragma%> ghs startsda");
   
   push_data_area (DATA_AREA_SDA);

 }
@@ -233,7 +233,7 @@ ghs_pragma_startzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
   tree x;
   
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma ghs startzda");
+warning (OPT_Wpragmas, "junk at end of %<#pragma%> ghs startzda");
   
   push_data_area (DATA_AREA_ZDA);

 }
@@ -244,7 +244,7 @@ ghs_pragma_endtda (cpp_reader * pfile ATTRIBUTE_UNUSED)
   tree x;
   
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma ghs endtda");
+warning (OPT_Wpragmas, "junk at end of %<#pragma%> ghs endtda");
   
   pop_data_area (DATA_AREA_TDA);

 }
@@ -255,7 +255,7 @@ ghs_pragma_endsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
   tree x;
   
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma ghs endsda");
+warning (OPT_Wpragmas, "junk at end of %<#pragma%> ghs endsda");
   
   pop_data_area (DATA_AREA_SDA);

 }
@@ -266,7 +266,7 @@ ghs_pragma_endzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
   tree x;
   
   if (pragma_lex () != CPP_EOF)

-warning (OPT_Wpragmas, "junk at end of #pragma ghs endzda");
+warning (OPT_Wpragmas, "junk at end of %<#pragma%> ghs endzda");
   
   pop_data_area (DATA_AREA_ZDA);

 }
--
2.34.1




[PATCH] nds32: fix -Wformat-diag warning.

2022-01-18 Thread Martin Liška

Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.

Martin

gcc/ChangeLog:

* config/nds32/nds32-intrinsic.cc (nds32_expand_builtin_impl):
Fix warnings.
* config/nds32/nds32-intrinsic.md: Likewise.
* config/nds32/nds32-isr.cc (nds32_check_isr_attrs_conflict): Likewise.
* config/nds32/nds32.cc (nds32_print_operand): Likewise.
(nds32_insert_attributes): Likewise.
---
 gcc/config/nds32/nds32-intrinsic.cc |  6 +++---
 gcc/config/nds32/nds32-intrinsic.md | 28 ++--
 gcc/config/nds32/nds32-isr.cc   |  2 +-
 gcc/config/nds32/nds32.cc   | 14 +++---
 4 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/gcc/config/nds32/nds32-intrinsic.cc 
b/gcc/config/nds32/nds32-intrinsic.cc
index 3c297cfeece..2f2cd7c791e 100644
--- a/gcc/config/nds32/nds32-intrinsic.cc
+++ b/gcc/config/nds32/nds32-intrinsic.cc
@@ -1013,7 +1013,7 @@ nds32_expand_builtin_impl (tree exp,
   /* Both v3s and v3f toolchains define TARGET_FPU_SINGLE.  */
   if (!TARGET_FPU_SINGLE)
{
- error ("this builtin function is only available "
+ error ("this built-in function is only available "
 "on the v3s or v3f toolchain");
  return NULL_RTX;
}
@@ -1025,7 +1025,7 @@ nds32_expand_builtin_impl (tree exp,
   /* Only v3f toolchain defines TARGET_FPU_DOUBLE.  */
   if (!TARGET_FPU_DOUBLE)
{
- error ("this builtin function is only available "
+ error ("this built-in function is only available "
 "on the v3f toolchain");
  return NULL_RTX;
}
@@ -1040,7 +1040,7 @@ nds32_expand_builtin_impl (tree exp,
 case NDS32_BUILTIN_SBUP:
   if (TARGET_ISA_V3M)
{
- error ("this builtin function not support "
+ error ("this built-in function not support "
 "on the v3m toolchain");
  return NULL_RTX;
}
diff --git a/gcc/config/nds32/nds32-intrinsic.md 
b/gcc/config/nds32/nds32-intrinsic.md
index 45b10f0665d..d7229cdbaa9 100644
--- a/gcc/config/nds32/nds32-intrinsic.md
+++ b/gcc/config/nds32/nds32-intrinsic.md
@@ -301,8 +301,8 @@ (define_expand "unspec_clr_pending_hwint"
   offset = 32;
 }
   else
-error ("__nds32__clr_pending_hwint not support NDS32_INT_SWI,"
-  " NDS32_INT_ALZ, NDS32_INT_IDIVZE, NDS32_INT_DSSIM");
+error ("%<__nds32__clr_pending_hwint%> not support %,"
+  " %, %, %");
 
   /* $INT_PEND type is write one clear.  */

   clr_hwint = GEN_INT (1 << (INTVAL (operands[0]) - offset));
@@ -359,8 +359,8 @@ (define_expand "unspec_get_pending_int"
   operands[2] = GEN_INT (31 - (INTVAL (operands[1]) - 32));
 }
   else
-error ("get_pending_int not support NDS32_INT_ALZ,"
-  " NDS32_INT_IDIVZE, NDS32_INT_DSSIM");
+error ("% not support %,"
+  " %, %");
 
   /* mfsr op0, sytem_reg  */

   if (system_reg != NULL_RTX)
@@ -417,8 +417,8 @@ (define_expand "unspec_set_int_priority"
   offset = 48;
 }
   else
-error ("set_int_priority not support NDS32_INT_SWI,"
-  " NDS32_INT_ALZ, NDS32_INT_IDIVZE, NDS32_INT_DSSIM");
+error ("i% not support %,"
+  " %, %, %");
 
   mask = GEN_INT (~(3 << 2 * (INTVAL (operands[0]) - offset)));

   priority = GEN_INT ((int) (INTVAL (operands[1])
@@ -477,8 +477,8 @@ (define_expand "unspec_get_int_priority"
   offset = 48;
 }
   else
-error ("set_int_priority not support NDS32_INT_SWI,"
-  " NDS32_INT_ALZ, NDS32_INT_IDIVZE, NDS32_INT_DSSIM");
+error ("% not support %,"
+  " %, %, %");
 
   priority = GEN_INT (31 - 2 * (INTVAL (operands[1]) - offset));
 
@@ -514,8 +514,8 @@ (define_expand "unspec_set_trig_level"

   offset = 32;
 }
   else
-error ("__nds32__set_trig_type_level not support NDS32_INT_SWI,"
-  " NDS32_INT_ALZ, NDS32_INT_IDIVZE, NDS32_INT_DSSIM");
+error ("%<__nds32__set_trig_type_level%> not support %,"
+  " %, %, %");
 
   if (system_reg != NULL_RTX)

 {
@@ -551,8 +551,8 @@ (define_expand "unspec_set_trig_edge"
   offset = 32;
 }
   else
-error ("__nds32__set_trig_type_edge not support NDS32_INT_SWI,"
-  " NDS32_INT_ALZ, NDS32_INT_IDIVZE, NDS32_INT_DSSIM");
+error ("%<__nds32__set_trig_type_edge%> not support %,"
+  " %, %, %");
 
   if (system_reg != NULL_RTX)

 {
@@ -588,8 +588,8 @@ (define_expand "unspec_get_trig_type"
   offset = 32;
 }
   else
-error ("__nds32__get_trig_type not support NDS32_INT_SWI,"
-  " NDS32_INT_ALZ, NDS32_INT_IDIVZE, NDS32_INT_DSSIM");
+error ("%<__nds32__get_trig_type%> not support %,"
+  " %, %, %");
 
   if (system_reg != NULL_RTX)

 {
diff --git a/gcc/config/nds32/nds32-isr.cc b/gcc/config/nds32/nds32-isr.cc
index 344fb7057d1..eef2d862bd0 100644
--- a/gcc/config/nds32/nds32-isr.cc
+++ b/gcc/config/nds32/nds32-isr.cc
@@ -614,7 +614,7 @@ nds32_check_isr_attrs_conflict 

[PATCH] nvptx: fix -Wformat-diag warnings

2022-01-18 Thread Martin Liška

Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.

Martin

gcc/ChangeLog:

* config/nvptx/nvptx.cc (nvptx_goacc_validate_dims_1): Wrap
keyword.
* config/nvptx/nvptx.md: Remove trailing dot.

libgomp/ChangeLog:

* testsuite/libgomp.oacc-c++/privatized-ref-2.C: Update keyword
in dg-warning.
* testsuite/libgomp.oacc-c++/privatized-ref-3.C: Likewise.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/kernels-loop-2.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/pr85486.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/pr95270-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/routine-nohost-2.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c: Likewise.
* testsuite/libgomp.oacc-c-c++-common/vector-length-64-1.c: Likewise.
* testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90: Likewise.
* testsuite/libgomp.oacc-fortran/derivedtypes-arrays-1.f90: Likewise.
* testsuite/libgomp.oacc-fortran/kernels-loop-2.f95: Likewise.
* testsuite/libgomp.oacc-fortran/parallel-dims.f90: Likewise.
* testsuite/libgomp.oacc-fortran/privatized-ref-1.f95: Likewise.
---
 gcc/config/nvptx/nvptx.cc  |  8 
 gcc/config/nvptx/nvptx.md  |  6 +++---
 .../testsuite/libgomp.oacc-c++/privatized-ref-2.C  |  6 +++---
 .../testsuite/libgomp.oacc-c++/privatized-ref-3.C  |  6 +++---
 .../libgomp.oacc-c-c++-common/acc_prof-kernels-1.c |  4 ++--
 .../libgomp.oacc-c-c++-common/kernels-loop-2.c |  4 ++--
 .../libgomp.oacc-c-c++-common/parallel-dims.c  | 14 +++---
 .../testsuite/libgomp.oacc-c-c++-common/pr85486.c  |  2 +-
 .../libgomp.oacc-c-c++-common/pr95270-1.c  |  4 ++--
 .../libgomp.oacc-c-c++-common/routine-nohost-2.c   |  2 +-
 .../libgomp.oacc-c-c++-common/struct-copyout-1.c   |  2 +-
 .../libgomp.oacc-c-c++-common/struct-copyout-2.c   |  2 +-
 .../libgomp.oacc-c-c++-common/vector-length-64-1.c |  2 +-
 .../libgomp.oacc-fortran/attach-descriptor-1.f90   |  2 +-
 .../libgomp.oacc-fortran/derivedtypes-arrays-1.f90 |  2 +-
 .../libgomp.oacc-fortran/kernels-loop-2.f95|  4 ++--
 .../libgomp.oacc-fortran/parallel-dims.f90 |  4 ++--
 .../libgomp.oacc-fortran/privatized-ref-1.f95  |  6 +++---
 18 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 20fd8938f2d..a829bd3fe7a 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -5894,7 +5894,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int 
fn_level, unsigned used)
 
   if (dims[GOMP_DIM_VECTOR] > PTX_WARP_SIZE)

{
- vector_reason = G_("using vector_length (%d) due to call to"
+ vector_reason = G_("using % (%d) due to call to"
 " vector-partitionable routine, ignoring %d");
  dims[GOMP_DIM_VECTOR] = PTX_WARP_SIZE;
}
@@ -5902,7 +5902,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int 
fn_level, unsigned used)
 
   if (dims[GOMP_DIM_VECTOR] == 0)

 {
-  vector_reason = G_("using vector_length (%d), ignoring runtime setting");
+  vector_reason = G_("using % (%d), ignoring runtime 
setting");
   dims[GOMP_DIM_VECTOR] = default_vector_length;
 }
 
@@ -5916,12 +5916,12 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level, unsigned used)

 warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
vector_reason != NULL
? vector_reason
-   : G_("using vector_length (%d), ignoring %d"),
+   : G_("using % (%d), ignoring %d"),
dims[GOMP_DIM_VECTOR], old_dims[GOMP_DIM_VECTOR]);
 
   if (dims[GOMP_DIM_WORKER] != old_dims[GOMP_DIM_WORKER])

 warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
-   G_("using num_workers (%d), ignoring %d"),
+   G_("using % (%d), ignoring %d"),
dims[GOMP_DIM_WORKER], old_dims[GOMP_DIM_WORKER]);
 
   if (oacc_default_dims_p)

diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md
index ce74672e5ae..5cf190ab73e 100644
--- a/gcc/config/nvptx/nvptx.md
+++ b/gcc/config/nvptx/nvptx.md
@@ -1410,7 +1410,7 @@ (define_expand "nonlocal_goto"
(match_operand 3 "" "")]
   ""
 {
-  sorry ("target cannot support nonlocal goto.");
+  sorry ("target cannot support nonlocal goto");
   emit_insn (gen_nop ());
   DONE;
 })
@@ -1419,7 +1419,7 @@ (define_expand "nonlocal_goto_receiver"
   [(const_int 0)]
   ""
 {
-  sorry ("target cannot support nonlocal goto.");
+  sorry ("target cannot support nonlocal goto");
 })
 
 (define_expand 

Re: [PATCH] middle-end/101292 - invalid memory access with warning control

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

On 1/18/22 01:36, Richard Biener wrote:

On Mon, 17 Jan 2022, Martin Sebor wrote:


On 1/17/22 07:32, Richard Biener via Gcc-patches wrote:

The warning control falls into the C++ trap of using a reference
to old hashtable contents for a put operation which can end up
re-allocating that before reading from the old freed referenced to
source.  Fixed by introducing a temporary.


I think a better place to fix this and avoid the gotcha once and
for all is in the GCC hash_map: C++ containers are expected to
handle the insertion of own elements gracefully.


I don't think that's reasonably possible if you consider

   T *a = map.get (X);
   T *b = map.get (Y);
   map.put (Z, *a);
   map.put (W, *b);


This case is up to the caller to handle, the same as anything else
involving pointers or references into reallocated storage (it's no
different in C than it is in C++).

The specific case I'm referring to is passing a pointer or reference
to a single element in a container to the first modifying call on
the container.



the only way to "fix" it would be to change the API to not
return by reference for get, remove get_or_insert (or change
its API to also require passing the new value).


No, the fix is to have the modifying function create a copy of
the element being inserted before reallocating the container.



Note the above shows that making 'put' take the value by
value instead of by reference doesn't work either.

IMHO the issue is that C++ doesn't make it obvious that 'put'
gets a pointer to the old element (stupid references).


The problem isn't specific to references, it can come up with
pointers just as easily.  Pointers might just make it more obvious.

Martin



Richard.


Martin



Bootstrap & regtest running on x86_64-unknown-linux-gnu.

2022-01-17  Richard Biener  

  PR middle-end/101292
  * diagnostic-spec.c (copy_warning): Make sure to not
  reference old hashtable content on possible resize.
  * warning-control.cc (copy_warning): Likewise.
---
   gcc/diagnostic-spec.c  | 5 -
   gcc/warning-control.cc | 3 ++-
   2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/diagnostic-spec.c b/gcc/diagnostic-spec.c
index a8af229d677..4341ccfaae9 100644
--- a/gcc/diagnostic-spec.c
+++ b/gcc/diagnostic-spec.c
@@ -195,7 +195,10 @@ copy_warning (location_t to, location_t from)
 else
   {
 if (from_spec)
-   nowarn_map->put (to, *from_spec);
+   {
+ nowarn_spec_t tem = *from_spec;
+ nowarn_map->put (to, tem);
+   }
  else
nowarn_map->remove (to);
   }
diff --git a/gcc/warning-control.cc b/gcc/warning-control.cc
index f9808bf4392..fa39ecab421 100644
--- a/gcc/warning-control.cc
+++ b/gcc/warning-control.cc
@@ -206,7 +206,8 @@ void copy_warning (ToType to, FromType from)
  gcc_assert (supp);
   
   	  gcc_checking_assert (nowarn_map);

- nowarn_map->put (to_loc, *from_spec);
+ nowarn_spec_t tem = *from_spec;
+ nowarn_map->put (to_loc, tem);
}
  else
{









[PATCH] riscv: fix -Wformat-diag errors.

2022-01-18 Thread Martin Liška

Pushed as pre-approved by Jeff. The patch fixes -Wformat-diag warnings.

Martin

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (riscv_subset_list::add):
Wrap keywords with quotes and remove trailing dots.
(riscv_subset_list::parsing_subset_version): Likewise.
(riscv_subset_list::parse_std_ext): Likewise.
(riscv_subset_list::parse_multiletter_ext): Likewise.
* config/riscv/riscv.cc (riscv_handle_type_attribute): Likewise.
---
 gcc/common/config/riscv/riscv-common.cc | 16 
 gcc/config/riscv/riscv.cc   |  4 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index c1d8431c1fa..004822bfe6c 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -375,7 +375,7 @@ riscv_subset_list::add (const char *subset, int 
major_version,
   else
error_at (
  m_loc,
- "%<-march=%s%>: Extension `%s' appear more than one time.",
+ "%<-march=%s%>: extension %qs appear more than one time",
  m_arch,
  subset);
 
@@ -613,14 +613,14 @@ riscv_subset_list::parsing_subset_version (const char *ext,

  {
if (!ISDIGIT (*(p+1)))
  {
-   error_at (m_loc, "%<-march=%s%>: Expect number "
- "after %<%dp%>.", m_arch, version);
+   error_at (m_loc, "%<-march=%s%>: expect number "
+ "after %<%dp%>", m_arch, version);
return NULL;
  }
if (!major_p)
  {
-   error_at (m_loc, "%<-march=%s%>: For %<%s%dp%dp?%>, version "
- "number with more than 2 level is not supported.",
+   error_at (m_loc, "%<-march=%s%>: for %<%s%dp%dp?%>, version "
+ "number with more than 2 level is not supported",
  m_arch, ext, major, version);
return NULL;
  }
@@ -701,8 +701,8 @@ riscv_subset_list::parse_std_ext (const char *p)
  /* std_ext_p= */ true, _version_p);
   if (major_version != 0 || minor_version != 0)
{
- warning_at (m_loc, 0, "version of `g` will be omitted, please "
-   "specify version for individual extension.");
+ warning_at (m_loc, 0, "version of % will be omitted, please "
+   "specify version for individual extension");
}
 
   /* We have special rule for G, we disallow rv32gm2p but allow rv32g_zicsr

@@ -906,7 +906,7 @@ riscv_subset_list::parse_multiletter_ext (const char *p,
 
   if (*p != '\0' && *p != '_')

{
- error_at (m_loc, "%<-march=%s%>: %s must separate with _",
+ error_at (m_loc, "%<-march=%s%>: %s must separate with %<_%>",
m_arch, ext_type_str);
  return NULL;
}
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 7c806780883..8314864d5e7 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -3309,8 +3309,8 @@ riscv_handle_type_attribute (tree *node ATTRIBUTE_UNUSED, 
tree name, tree args,
  && strcmp (string, "machine"))
{
  warning (OPT_Wattributes,
-  "argument to %qE attribute is not \"user\", \"supervisor\", or 
\"machine\"",
-  name);
+  "argument to %qE attribute is not %, %, 
"
+  "or %", name);
  *no_add_attrs = true;
}
}
--
2.34.1




[PATCH] Fix -Wformat-diag in various targets.

2022-01-18 Thread Martin Liška

Hello.

The patch fixes -Wformat-diag in various targets.
I'm going to install the patch based on Jeff's pre-approval of similar patches.

Martin

gcc/ChangeLog:

* collect2.cc (scan_libraries): Fix -Wformat-diag issues.
* config/aarch64/aarch64-builtins.cc (aarch64_simd_expand_builtin): 
Likewise.
* config/arc/arc.md: Likewise.
* config/avr/avr.cc (avr_section_type_flags): Likewise.
* config/bfin/bfin.cc (bfin_option_override): Likewise.
(bfin_handle_longcall_attribute): Likewise.
* config/cris/cris.h (FUNCTION_PROFILER): Likewise.
* config/frv/frv.cc (frv_expand_builtin): Likewise.
* config/ia64/ia64-c.cc (ia64_hpux_handle_builtin_pragma): Likewise.
* config/iq2000/iq2000.cc (save_restore_insns): Likewise.
(iq2000_print_operand_address): Likewise.
(iq2000_print_operand): Likewise.
* config/m32c/m32c-pragma.cc (m32c_pragma_memregs): Likewise.
(m32c_pragma_address): Likewise.
* config/m68k/m68k.cc (m68k_handle_fndecl_attribute): Likewise.
* config/mips/mips.cc (mips_handle_interrupt_attr): Likewise.
(mips_set_compression_mode): Likewise.
* config/mmix/mmix.cc (mmix_function_profiler): Likewise.
(mmix_print_operand): Likewise.
(mmix_output_shiftvalue_op_from_str): Likewise.
(mmix_output_shifted_value): Likewise.
* config/msp430/driver-msp430.cc (msp430_select_hwmult_lib): Likewise.
* config/msp430/msp430.cc (msp430_option_override): Likewise.
(msp430_attr): Likewise.
(msp430_expand_delay_cycles): Likewise.
(msp430_expand_builtin): Likewise.
* config/rs6000/aix73.h: Likewise.
* config/rs6000/rtems.h (INVALID_64BIT): Likewise.
* config/rx/rx.cc (rx_expand_builtin_mvtc): Likewise.
(valid_psw_flag): Likewise.
* config/sh/sh.cc (parse_validate_atomic_model_option): Likewise.
* config/stormy16/stormy16.cc (xstormy16_function_profiler): Likewise.
(xstormy16_expand_builtin_va_start): Likewise.
(xstormy16_handle_below100_attribute): Likewise.
---
 gcc/collect2.cc|  2 +-
 gcc/config/aarch64/aarch64-builtins.cc |  2 +-
 gcc/config/arc/arc.md  |  2 +-
 gcc/config/avr/avr.cc  |  2 +-
 gcc/config/bfin/bfin.cc|  8 +++
 gcc/config/cris/cris.h |  2 +-
 gcc/config/frv/frv.cc  |  6 +++---
 gcc/config/ia64/ia64-c.cc  |  2 +-
 gcc/config/iq2000/iq2000.cc|  8 +++
 gcc/config/m32c/m32c-pragma.cc | 12 +--
 gcc/config/m68k/m68k.cc|  2 +-
 gcc/config/mips/mips.cc|  6 +++---
 gcc/config/mmix/mmix.cc|  8 +++
 gcc/config/msp430/driver-msp430.cc |  6 +++---
 gcc/config/msp430/msp430.cc| 30 +-
 gcc/config/rs6000/aix73.h  |  2 +-
 gcc/config/rs6000/rtems.h  |  2 +-
 gcc/config/rx/rx.cc|  4 ++--
 gcc/config/sh/sh.cc|  6 +++---
 gcc/config/stormy16/stormy16.cc|  6 +++---
 20 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/gcc/collect2.cc b/gcc/collect2.cc
index 0185b9d9e82..d81c7f28f16 100644
--- a/gcc/collect2.cc
+++ b/gcc/collect2.cc
@@ -2552,7 +2552,7 @@ scan_libraries (const char *prog_name)
 
   pex = pex_init (PEX_USE_PIPES, "collect2", NULL);

   if (pex == NULL)
-fatal_error (input_location, "pex_init failed: %m");
+fatal_error (input_location, "% failed: %m");
 
   errmsg = pex_run (pex, 0, ldd_file_name, real_ldd_argv, NULL, NULL, );

   if (errmsg != NULL)
diff --git a/gcc/config/aarch64/aarch64-builtins.cc 
b/gcc/config/aarch64/aarch64-builtins.cc
index 215de1c09c8..b7f338d6229 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -1943,7 +1943,7 @@ aarch64_simd_expand_builtin (int fcode, tree exp, rtx 
target)
}
   else
error_at (EXPR_LOCATION (exp),
- "total size and element size must be a non-zero "
+ "total size and element size must be a nonzero "
  "constant immediate");
   /* Don't generate any RTL.  */
   return const0_rtx;
diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index d4e22a4b2d9..ace3cb70424 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -4666,7 +4666,7 @@ (define_insn "trap_s"
   /* Keep this message in sync with the one in arc.cc:arc_expand_builtin,
  because *.md files do not get scanned by exgettext.  */
   fatal_error (input_location,
-  \"operand to trap_s should be an unsigned 6-bit value\");
+  \"operand to % should be an unsigned 6-bit value\");
 }
   [(set_attr "length" "2")
   (set_attr "type" "misc")])
diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 9eec991e10a..4ed390e4cf9 100644
--- 

  1   2   >