[gcc r12-10503] tree-optimization/111070 - fix ICE with recent ifcombine fix

2024-06-11 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:d73137ab352d654f50b703925bd92e021dce1cab

commit r12-10503-gd73137ab352d654f50b703925bd92e021dce1cab
Author: Richard Biener 
Date:   Mon Aug 21 09:01:00 2023 +0200

tree-optimization/111070 - fix ICE with recent ifcombine fix

We now got test coverage for non-SSA name bits so the following amends
the SSA_NAME_OCCURS_IN_ABNORMAL_PHI checks.

PR tree-optimization/111070
* tree-ssa-ifcombine.cc (ifcombine_ifandif): Check we have
an SSA name before checking SSA_NAME_OCCURS_IN_ABNORMAL_PHI.

* gcc.dg/pr111070.c: New testcase.

(cherry picked from commit 966b0a96523fb7adbf498ac71df5e033c70dc546)

Diff:
---
 gcc/testsuite/gcc.dg/pr111070.c | 20 
 gcc/tree-ssa-ifcombine.cc   |  9 ++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr111070.c b/gcc/testsuite/gcc.dg/pr111070.c
new file mode 100644
index 000..1ebc7adf782
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr111070.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+/* common */
+char c;
+/* arrays must be 8 byte aligned, regardless of size */
+char c_ary[1];
+
+/* data */
+char d = 1;
+char d_ary[1] = {1};
+
+int main ()
+{
+  if (((unsigned long)&c_ary[0] & 7) != 0)
+return 1;
+  if (((unsigned long)&d_ary[0] & 7) != 0)
+return 1;
+  return 0;
+}
diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index b139328af22..dcfa92c0c82 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -415,7 +415,8 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
 {
   tree t, t2;
 
-  if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1))
+  if (TREE_CODE (name1) == SSA_NAME
+ && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1))
return false;
 
   /* Do it.  */
@@ -468,8 +469,10 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
   gimple_stmt_iterator gsi;
   tree t;
 
-  if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1)
- || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name2))
+  if ((TREE_CODE (name1) == SSA_NAME
+  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1))
+ || (TREE_CODE (name2) == SSA_NAME
+ && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name2)))
return false;
 
   /* Find the common name which is bit-tested.  */


[gcc r15-1174] RISC-V: Implement .SAT_SUB for unsigned vector int

2024-06-11 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:8087204a4260a552c7cee37d1fb46cec7edfe9ee

commit r15-1174-g8087204a4260a552c7cee37d1fb46cec7edfe9ee
Author: Pan Li 
Date:   Tue Jun 11 11:04:22 2024 +0800

RISC-V: Implement .SAT_SUB for unsigned vector int

As the middle support of .SAT_SUB committed,  implement the unsigned
vector int of .SAT_SUB for the riscv backend.  Consider below example
code:

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

Before this patch:
  ...
  vsetvli a5,a3,e64,m1,ta,mu
  sllia4,a5,3
  vle64.v v2,0(a1)
  vle64.v v1,0(a2)
  vmsgeu.vv   v0,v2,v1
  vmv1r.v v3,v4
  vsub.vv v3,v2,v1,v0.t
  vse64.v v3,0(a0)
  ...

After this patch:
  ...
  vsetvli a5,a3,e64,m1,ta,ma
  sllia4,a5,3
  vle64.v v1,0(a1)
  vle64.v v2,0(a2)
  vssubu.vv   v1,v1,v2
  vse64.v v1,0(a0)
  ...

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/autovec.md (ussub3): Add new pattern impl
for the unsigned vector modes.
* config/riscv/riscv-protos.h (expand_vec_ussub): Add new func
decl to expand .SAT_SUB for vector mode.
* config/riscv/riscv-v.cc (emit_vec_saddu): Add new func impl
to expand .SAT_SUB for vector mode.
(emit_vec_binary_alu): Add new helper func to emit binary alu.
(expand_vec_ussub): Leverage above helper func.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add helper macros for test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-1.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-2.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-3.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-4.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-1.c: New 
test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-2.c: New 
test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-3.c: New 
test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-4.c: New 
test.

Signed-off-by: Pan Li 

Diff:
---
 gcc/config/riscv/autovec.md| 12 
 gcc/config/riscv/riscv-protos.h|  1 +
 gcc/config/riscv/riscv-v.cc| 19 --
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-1.c  | 19 ++
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-2.c  | 20 ++
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-3.c  | 20 ++
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-4.c  | 20 ++
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-run-1.c  | 75 ++
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-run-2.c  | 75 ++
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-run-3.c  | 75 ++
 .../riscv/rvv/autovec/binop/vec_sat_u_sub-run-4.c  | 75 ++
 gcc/testsuite/gcc.target/riscv/sat_arith.h | 31 +
 12 files changed, 437 insertions(+), 5 deletions(-)

diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md
index 15db26d52c6..0b1e50dd0e9 100644
--- a/gcc/config/riscv/autovec.md
+++ b/gcc/config/riscv/autovec.md
@@ -2644,6 +2644,7 @@
 ;; =
 ;; Includes:
 ;; - add
+;; - sub
 ;; =
 (define_expand "usadd3"
   [(match_operand:V_VLSI 0 "register_operand")
@@ -2656,6 +2657,17 @@
   }
 )
 
+(define_expand "ussub3"
+  [(match_operand:V_VLSI 0 "register_operand")
+   (match_operand:V_VLSI 1 "register_operand")
+   (match_operand:V_VLSI 2 "register_operand")]
+  "TARGET_VECTOR"
+  {
+riscv_vector::expand_vec_ussub (operands[0], operands[1], operands[2], 
mode);
+DONE;
+  }
+)
+
 ;; =
 ;; == Early break auto-vectorization patterns
 ;; =
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 09e

[gcc r15-1175] i386: PR target/115397: AVX512 ternlog vs. -m32 -fPIC constant pool.

2024-06-11 Thread Roger Sayle via Gcc-cvs
https://gcc.gnu.org/g:a797398cfbc75899fdb7d97436c0c89c02b133c0

commit r15-1175-ga797398cfbc75899fdb7d97436c0c89c02b133c0
Author: Roger Sayle 
Date:   Tue Jun 11 09:31:34 2024 +0100

i386: PR target/115397: AVX512 ternlog vs. -m32 -fPIC constant pool.

This patch fixes PR target/115397, a recent regression caused by my
ternlog patch that results in an ICE (building numpy) with -m32 -fPIC.
The problem is that ix86_broadcast_from_constant, which calls
get_pool_constant, doesn't handle the UNSPEC_GOTOFF that's created by
calling validize_mem when using -fPIC on i686.  The logic here is a bit
convoluted (and my future patches will clean some of this up), but the
simplest fix is to call ix86_broadcast_from_constant between the calls
to force_const_mem and the call to validize_mem.

Perhaps a better solution might be to call targetm.delegitimize_address
from the middle-end's get_pool_constant, but ultimately the best approach
would be to not place things in the constant pool if we don't need to.
My plans to move (broadcast) constant handling from expand to split1
should simplify this.

2024-06-11  Roger Sayle  

gcc/ChangeLog
PR target/115397
* config/i386/i386-expand.cc (ix86_expand_ternlog): Move call to
ix86_broadcast_from_constant before call to validize_mem, but after
call to force_const_mem.

gcc/testsuite/ChangeLog
PR target/115397
* gcc.target/i386/pr115397.c: New test case.

Diff:
---
 gcc/config/i386/i386-expand.cc   |  3 ++-
 gcc/testsuite/gcc.target/i386/pr115397.c | 17 +
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 9b60264dce2..312329e550b 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -26041,8 +26041,9 @@ ix86_expand_ternlog (machine_mode mode, rtx op0, rtx 
op1, rtx op2, int idx,
   tmp2 = ix86_gen_bcst_mem (mode, op2);
   if (!tmp2)
{
- tmp2 = validize_mem (force_const_mem (mode, op2));
+ tmp2 = force_const_mem (mode, op2);
  rtx bcast = ix86_broadcast_from_constant (mode, tmp2);
+ tmp2 = validize_mem (tmp2);
  if (bcast)
{
  rtx reg2 = gen_reg_rtx (mode);
diff --git a/gcc/testsuite/gcc.target/i386/pr115397.c 
b/gcc/testsuite/gcc.target/i386/pr115397.c
new file mode 100644
index 000..27835782b78
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115397.c
@@ -0,0 +1,17 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-fPIC -mavx512f -O3" } */
+
+int LONG_divide_AVX512F_dimensions_0;
+void npy_set_floatstatus_overflow();
+void LONG_divide_AVX512F() {
+  long *src;
+  int raise_err = 0;
+  for (; LONG_divide_AVX512F_dimensions_0;
+   --LONG_divide_AVX512F_dimensions_0, ++src) {
+long a = *src;
+if (a)
+  raise_err = 1;
+  }
+  if (raise_err)
+npy_set_floatstatus_overflow();
+}


[gcc r14-10303] ira: Fix go_through_subreg offset calculation [PR115281]

2024-06-11 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:7d64bc0990381221c480ba15cb9cc950e51e2cef

commit r14-10303-g7d64bc0990381221c480ba15cb9cc950e51e2cef
Author: Richard Sandiford 
Date:   Tue Jun 11 09:58:48 2024 +0100

ira: Fix go_through_subreg offset calculation [PR115281]

go_through_subreg used:

  else if (!can_div_trunc_p (SUBREG_BYTE (x),
 REGMODE_NATURAL_SIZE (GET_MODE (x)), offset))

to calculate the register offset for a pseudo subreg x.  In the blessed
days before poly-int, this was:

*offset = (SUBREG_BYTE (x) / REGMODE_NATURAL_SIZE (GET_MODE (x)));

But I think this is testing the wrong natural size.  If we exclude
paradoxical subregs (which will get an offset of zero regardless),
it's the inner register that is being split, so it should be the
inner register's natural size that we use.

This matters in the testcase because we have an SFmode lowpart
subreg into the last of three variable-sized vectors.  The
SUBREG_BYTE is therefore equal to the size of two variable-sized
vectors.  Dividing by the vector size gives a register offset of 2,
as expected, but dividing by the size of a scalar FPR would give
a variable offset.

I think something similar could happen for fixed-size targets if
REGMODE_NATURAL_SIZE is different for vectors and integers (say),
although that case would trade an ICE for an incorrect offset.

gcc/
PR rtl-optimization/115281
* ira-conflicts.cc (go_through_subreg): Use the natural size of
the inner mode rather than the outer mode.

gcc/testsuite/
PR rtl-optimization/115281
* gfortran.dg/pr115281.f90: New test.

(cherry picked from commit 46d931b3dd31cbba7c3355ada63f155aa24a4e2b)

Diff:
---
 gcc/ira-conflicts.cc   |  3 ++-
 gcc/testsuite/gfortran.dg/pr115281.f90 | 39 ++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/gcc/ira-conflicts.cc b/gcc/ira-conflicts.cc
index 83274c53330..15ac42d8848 100644
--- a/gcc/ira-conflicts.cc
+++ b/gcc/ira-conflicts.cc
@@ -227,8 +227,9 @@ go_through_subreg (rtx x, int *offset)
   if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
 *offset = subreg_regno_offset (REGNO (reg), GET_MODE (reg),
   SUBREG_BYTE (x), GET_MODE (x));
+  /* The offset is always 0 for paradoxical subregs.  */
   else if (!can_div_trunc_p (SUBREG_BYTE (x),
-REGMODE_NATURAL_SIZE (GET_MODE (x)), offset))
+REGMODE_NATURAL_SIZE (GET_MODE (reg)), offset))
 /* Checked by validate_subreg.  We must know at compile time which
inner hard registers are being accessed.  */
 gcc_unreachable ();
diff --git a/gcc/testsuite/gfortran.dg/pr115281.f90 
b/gcc/testsuite/gfortran.dg/pr115281.f90
new file mode 100644
index 000..80aa822e745
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr115281.f90
@@ -0,0 +1,39 @@
+! { dg-options "-O3" }
+! { dg-additional-options "-mcpu=neoverse-v1" { target aarch64*-*-* } }
+
+SUBROUTINE fn0(ma, mb, nt)
+  CHARACTER ca
+  REAL r0(ma)
+  INTEGER i0(mb)
+  REAL r1(3,mb)
+  REAL r2(3,mb)
+  REAL r3(3,3)
+  zero=0.0
+  do na = 1, nt
+ nt = i0(na)
+ do l = 1, 3
+r1 (l, na) =   r0 (nt)
+r2(l, na) = zero
+ enddo
+  enddo
+  if (ca  .ne.'z') then
+ do j = 1, 3
+do i = 1, 3
+   r4  = zero
+enddo
+ enddo
+ do na = 1, nt
+do k =  1, 3
+   do l = 1, 3
+  do m = 1, 3
+ r3 = r4 * v
+  enddo
+   enddo
+enddo
+ do i = 1, 3
+   do k = 1, ifn (r3)
+   enddo
+enddo
+ enddo
+ endif
+END


[gcc(refs/vendors/redhat/heads/gcc-13-branch)] Merge commit 'r13-8838-g7813d94393f60ac641265cb3fc3a446f9f3aea7e' into redhat/gcc-13-branch

2024-06-11 Thread Jakub Jelinek via Libstdc++-cvs
https://gcc.gnu.org/g:03b1a31f9807251f378fcecb29c4669eed357eb2

commit 03b1a31f9807251f378fcecb29c4669eed357eb2
Merge: 5632a1dc05e 7813d94393f
Author: Jakub Jelinek 
Date:   Tue Jun 11 11:10:28 2024 +0200

Merge commit 'r13-8838-g7813d94393f60ac641265cb3fc3a446f9f3aea7e' into 
redhat/gcc-13-branch

Diff:

 gcc/ChangeLog  |  95 +++
 gcc/DATESTAMP  |   2 +-
 gcc/ada/ChangeLog  |  13 ++
 gcc/ada/exp_ch6.adb|  11 +-
 gcc/ada/exp_util.adb   |   6 +
 gcc/ada/sem_ch6.adb|  12 +-
 gcc/builtins.cc|  16 ++-
 gcc/c/c-decl.cc|  15 +++
 gcc/combine.cc |   6 +-
 gcc/config/alpha/alpha.md  |  21 ++--
 gcc/config/alpha/constraints.md|   2 +-
 gcc/config/avr/avr.md  |  16 +++
 gcc/config/i386/i386-options.cc|  10 +-
 gcc/config/i386/x86-tune.def   |   2 +-
 gcc/config/mips/mips.cc|  11 +-
 gcc/config/rs6000/rs6000-builtin.cc|   2 +-
 gcc/config/rs6000/rs6000-c.cc  |  62 +-
 gcc/config/rs6000/rs6000-gen-builtins.cc   |  72 +--
 gcc/cp/ChangeLog   |  19 +++
 gcc/cp/init.cc |   4 +-
 gcc/cp/parser.cc   |   7 +-
 gcc/cp/pt.cc   |  14 +--
 gcc/doc/invoke.texi|   6 +-
 gcc/fold-const.cc  |  18 ++-
 gcc/fortran/ChangeLog  |  38 ++
 gcc/fortran/trans-array.cc |  16 +++
 gcc/fortran/trans-expr.cc  |  52 +---
 gcc/fortran/trans-intrinsic.cc |   4 +-
 gcc/testsuite/ChangeLog| 121 ++
 gcc/testsuite/g++.dg/cpp0x/initlist-pmf2.C |  12 ++
 gcc/testsuite/g++.dg/ext/unroll-4.C|  16 +++
 gcc/testsuite/gcc.c-torture/execute/pr108789.c |  39 ++
 gcc/testsuite/gcc.dg/pr114493-1.c  |  19 +++
 gcc/testsuite/gcc.dg/pr114493-2.c  |  26 
 gcc/testsuite/gcc.dg/pr114902.c|  23 
 gcc/testsuite/gcc.dg/pr115092.c|  16 +++
 gcc/testsuite/gcc.dg/vect/pr113281-1.c |  17 +++
 gcc/testsuite/gcc.dg/vect/pr113281-2.c |  50 
 gcc/testsuite/gcc.dg/vect/pr113281-3.c |  39 ++
 gcc/testsuite/gcc.dg/vect/pr113281-4.c |  55 +
 gcc/testsuite/gcc.dg/vect/pr113281-5.c |  66 ++
 gcc/testsuite/gcc.dg/vect/pr115192.c   |  28 +
 gcc/testsuite/gcc.target/alpha/pr115297.c  |  13 ++
 gcc/testsuite/gcc.target/arm/cmse/extend-param.c   |  21 +++-
 gcc/testsuite/gcc.target/arm/cmse/extend-return.c  |   4 +-
 .../gcc.target/avr/torture/pr115307-isinf.c|  21 
 .../gcc.target/avr/torture/pr115317-isinf.c|  55 +
 gcc/testsuite/gfortran.dg/asan/pr110415-2.f90  |  45 +++
 gcc/testsuite/gfortran.dg/asan/pr110415-3.f90  |  49 
 .../gfortran.dg/asan/unlimited_polymorphic_34.f90  | 135 +
 gcc/testsuite/gfortran.dg/pr110415.f90 |  20 +++
 gcc/testsuite/gfortran.dg/shape_12.f90 |  51 
 gcc/testsuite/gnat.dg/access11.adb |  80 
 gcc/testsuite/gnat.dg/incomplete8.adb  |  22 
 gcc/tree-data-ref.cc   |   5 +-
 gcc/tree-vect-patterns.cc  | 107 +++-
 libgcc/config/avr/libf7/ChangeLog  |   8 ++
 libgcc/config/avr/libf7/libf7-asm.sx   |  19 +--
 libstdc++-v3/ChangeLog |  24 
 libstdc++-v3/doc/html/manual/using.html|  10 +-
 libstdc++-v3/doc/xml/manual/using.xml  |  33 +
 libstdc++-v3/include/std/stacktrace|  13 +-
 .../testsuite/19_diagnostics/stacktrace/hash.cc|   2 +-
 63 files changed, 1614 insertions(+), 202 deletions(-)


[gcc/redhat/heads/gcc-13-branch] (47 commits) Merge commit 'r13-8838-g7813d94393f60ac641265cb3fc3a446f9f3

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
The branch 'redhat/heads/gcc-13-branch' was updated to point to:

 03b1a31f980... Merge commit 'r13-8838-g7813d94393f60ac641265cb3fc3a446f9f3

It previously pointed to:

 5632a1dc05e... Merge commit 'r13-8792-g53bc98f5355ada17d1629a2d0e96aebd397

Diff:

Summary of changes (added commits):
---

  03b1a31... Merge commit 'r13-8838-g7813d94393f60ac641265cb3fc3a446f9f3
  7813d94... c: Fix up pointer types to may_alias structures [PR114493] (*)
  865d60a... fold-const: Fix up CLZ handling in tree_call_nonnegative_wa (*)
  f9db8b0... builtins: Force SAVE_EXPR for __builtin_{add,sub,mul}_overf (*)
  308ca60... invoke.texi: Clarify -march=lujiazui (*)
  50b5019... rs6000: Fix up PCH in --enable-host-pie builds [PR115324] (*)
  8deaab6... combine: Fix up simplify_compare_const [PR115092] (*)
  f2ef3ac... Daily bump. (*)
  ef494b1... Fix crash on access-to-incomplete type (*)
  02025fb... Add testcase for PR ada/114398 (*)
  e54d909... ada: Storage_Error in indirect call to function returning l (*)
  7067b7e... Daily bump. (*)
  cd8dc16... Daily bump. (*)
  e11fb72... Daily bump. (*)
  e4f85ea... Disable FMADD in chains for Zen4 and generic (*)
  3cf6c1f... Daily bump. (*)
  c0f2293... Daily bump. (*)
  16fe81c... Daily bump. (*)
  38360ba... Daily bump. (*)
  ed06ca8... alpha: Fix invalid RTX in divmodsi insn patterns [PR115297] (*)
  218246b... Daily bump. (*)
  6634ff0... Daily bump. (*)
  c57d73f... AVR: tree-optimization/115307 - Work around isinf bloat fro (*)
  b45d728... AVR: target/115317 - Make isinf(-Inf) return -1. (*)
  3687dcf... libstdc++: Replace link to gcc-4.3.2 docs in manual [PR1152 (*)
  acdf0f7... Daily bump. (*)
  2602b71... vect: Tighten vect_determine_precisions_from_range [PR11328 (*)
  0836216... vect: Fix access size alignment assumption [PR115192] (*)
  173f876... i386: Fix ix86_option override after change [PR 113719] (*)
  d0fb9d2... Daily bump. (*)
  3be8fa7... MIPS16: Mark $2/$3 as clobbered if GP is used (*)
  2618cda... Daily bump. (*)
  ebca600... Daily bump. (*)
  fd91953... libstdc++: Fix up 19_diagnostics/stacktrace/hash.cc on 13 b (*)
  3185cfe... Fortran: Fix SHAPE for zero-size arrays (*)
  67434fe... libstdc++: Guard use of sized deallocation [PR114940] (*)
  d7f9f23... Daily bump. (*)
  b954f15... Daily bump. (*)
  513d050... Daily bump. (*)
  91c7ec5... Daily bump. (*)
  53cdaa7... c++: unroll pragma in templates [PR111529] (*)
  5f14578... c++: array of PMF [PR113598] (*)
  cf76815... Daily bump. (*)
  6f8933c... Daily bump. (*)
  75d394c... testsuite: Verify r0-r3 are extended with CMSE (*)
  f0b88ec... Fortran: fix issues with class(*) assignment [PR114827] (*)
  2ebf3af... Fortran: fix reallocation on assignment of polymorphic vari (*)

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


[gcc r15-1177] rust: Do not link with libdl and libpthread unconditionally

2024-06-11 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:75299e4fe50aa8d9b3ff529e48db4ed246083e64

commit r15-1177-g75299e4fe50aa8d9b3ff529e48db4ed246083e64
Author: Arthur Cohen 
Date:   Fri Apr 12 13:52:18 2024 +0200

rust: Do not link with libdl and libpthread unconditionally

ChangeLog:

* Makefile.tpl: Add CRAB1_LIBS variable.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check if -ldl and -lpthread are needed, and if so, 
add
them to CRAB1_LIBS.

gcc/rust/ChangeLog:

* Make-lang.in: Remove overazealous LIBS = -ldl -lpthread line, link
crab1 against CRAB1_LIBS.

Diff:
---
 Makefile.in   |   3 +
 Makefile.tpl  |   3 +
 configure | 154 ++
 configure.ac  |  41 ++
 gcc/rust/Make-lang.in |   5 +-
 5 files changed, 205 insertions(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in
index db4fa6c6260..34c5550beca 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -197,6 +197,7 @@ HOST_EXPORTS = \
$(BASE_EXPORTS) \
CC="$(CC)"; export CC; \
ADA_CFLAGS="$(ADA_CFLAGS)"; export ADA_CFLAGS; \
+   CRAB1_LIBS="$(CRAB1_LIBS)"; export CRAB1_LIBS; \
CFLAGS="$(CFLAGS)"; export CFLAGS; \
CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \
CXX="$(CXX)"; export CXX; \
@@ -450,6 +451,8 @@ GOCFLAGS = $(CFLAGS)
 GDCFLAGS = @GDCFLAGS@
 GM2FLAGS = $(CFLAGS)
 
+CRAB1_LIBS = @CRAB1_LIBS@
+
 PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
 
 GUILE = guile
diff --git a/Makefile.tpl b/Makefile.tpl
index 1d5813cd569..8f4bf297918 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -200,6 +200,7 @@ HOST_EXPORTS = \
$(BASE_EXPORTS) \
CC="$(CC)"; export CC; \
ADA_CFLAGS="$(ADA_CFLAGS)"; export ADA_CFLAGS; \
+   CRAB1_LIBS="$(CRAB1_LIBS)"; export CRAB1_LIBS; \
CFLAGS="$(CFLAGS)"; export CFLAGS; \
CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \
CXX="$(CXX)"; export CXX; \
@@ -453,6 +454,8 @@ GOCFLAGS = $(CFLAGS)
 GDCFLAGS = @GDCFLAGS@
 GM2FLAGS = $(CFLAGS)
 
+CRAB1_LIBS = @CRAB1_LIBS@
+
 PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
 
 GUILE = guile
diff --git a/configure b/configure
index 3b0abeb8b2e..51576a41f30 100755
--- a/configure
+++ b/configure
@@ -690,6 +690,7 @@ extra_host_zlib_configure_flags
 extra_host_libiberty_configure_flags
 stage1_languages
 host_libs_picflag
+CRAB1_LIBS
 PICFLAG
 host_shared
 gcc_host_pie
@@ -8875,6 +8876,139 @@ fi
 
 
 
+# Rust requires -ldl and -lpthread if you are using an old glibc that does not 
include them by
+# default, so we check for them here
+
+missing_rust_dynlibs=none
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing 
dlopen" >&5
+$as_echo_n "checking for library containing dlopen... " >&6; }
+if ${ac_cv_search_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' dl; do
+  if test -z "$ac_lib"; then
+ac_res="none required"
+  else
+ac_res=-l$ac_lib
+LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_dlopen=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+conftest$ac_exeext
+  if ${ac_cv_search_dlopen+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_dlopen+:} false; then :
+
+else
+  ac_cv_search_dlopen=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5
+$as_echo "$ac_cv_search_dlopen" >&6; }
+ac_res=$ac_cv_search_dlopen
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing 
pthread_create" >&5
+$as_echo_n "checking for library containing pthread_create... " >&6; }
+if ${ac_cv_search_pthread_create+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pthread_create ();
+int
+main ()
+{
+return pthread_create ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' pthread; do
+  if test -z "$ac_lib"; then
+ac_res="none required"
+  else
+ac_res=-l$ac_lib
+LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; th

[gcc r13-8839] libstdc++: Use __builtin_shufflevector for simd split and concat

2024-06-11 Thread Matthias Kretz via Libstdc++-cvs
https://gcc.gnu.org/g:26113c278069e7e58f5e4149ef86a30c043b262f

commit r13-8839-g26113c278069e7e58f5e4149ef86a30c043b262f
Author: Matthias Kretz 
Date:   Mon May 6 12:13:55 2024 +0200

libstdc++: Use __builtin_shufflevector for simd split and concat

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/114958
* include/experimental/bits/simd.h (__as_vector): Return scalar
simd as one-element vector. Return vector from single-vector
fixed_size simd.
(__vec_shuffle): New.
(__extract_part): Adjust return type signature.
(split): Use __extract_part for any split into non-fixed_size
simds.
(concat): If the return type stores a single vector, use
__vec_shuffle (which calls __builtin_shufflevector) to produce
the return value.
* include/experimental/bits/simd_builtin.h
(__shift_elements_right): Removed.
(__extract_part): Return single elements directly. Use
__vec_shuffle (which calls __builtin_shufflevector) to for all
non-trivial cases.
* include/experimental/bits/simd_fixed_size.h (__extract_part):
Return single elements directly.
* testsuite/experimental/simd/pr114958.cc: New test.

(cherry picked from commit fb1649f8b4ad5043dd0e65e4e3a643a0ced018a9)

Diff:
---
 libstdc++-v3/include/experimental/bits/simd.h  | 161 +++--
 .../include/experimental/bits/simd_builtin.h   | 152 +--
 .../include/experimental/bits/simd_fixed_size.h|   4 +-
 .../testsuite/experimental/simd/pr114958.cc|  20 +++
 4 files changed, 145 insertions(+), 192 deletions(-)

diff --git a/libstdc++-v3/include/experimental/bits/simd.h 
b/libstdc++-v3/include/experimental/bits/simd.h
index 63cc7bef610..6d3209b1a0e 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -1616,7 +1616,24 @@ template 
 if constexpr (__is_vector_type_v<_V>)
   return __x;
 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
-  return __data(__x)._M_data;
+  {
+   if constexpr (__is_fixed_size_abi_v)
+ {
+   static_assert(is_simd<_V>::value);
+   static_assert(_V::abi_type::template __traits<
+   typename 
_V::value_type>::_SimdMember::_S_tuple_size == 1);
+   return __as_vector(__data(__x).first);
+ }
+   else if constexpr (_V::size() > 1)
+ return __data(__x)._M_data;
+   else
+ {
+   static_assert(is_simd<_V>::value);
+   using _Tp = typename _V::value_type;
+   using _RV [[__gnu__::__vector_size__(sizeof(_Tp))]] = _Tp;
+   return _RV{__data(__x)};
+ }
+  }
 else if constexpr (__is_vectorizable_v<_V>)
   return __vector_type_t<_V, 2>{__x};
 else
@@ -2026,6 +2043,60 @@ template >
   return ~__a;
   }
 
+// }}}
+// __vec_shuffle{{{
+template 
+  _GLIBCXX_SIMD_INTRINSIC constexpr auto
+  __vec_shuffle(_T0 __x, _T1 __y, index_sequence<_Is...> __seq, _Fun 
__idx_perm)
+  {
+constexpr int _N0 = sizeof(__x) / sizeof(__x[0]);
+constexpr int _N1 = sizeof(__y) / sizeof(__y[0]);
+#if __has_builtin(__builtin_shufflevector)
+#ifdef __clang__
+// Clang requires _T0 == _T1
+if constexpr (sizeof(__x) > sizeof(__y) and _N1 == 1)
+  return __vec_shuffle(__x, _T0{__y[0]}, __seq, __idx_perm);
+else if constexpr (sizeof(__x) > sizeof(__y))
+  return __vec_shuffle(__x, __intrin_bitcast<_T0>(__y), __seq, __idx_perm);
+else if constexpr (sizeof(__x) < sizeof(__y) and _N0 == 1)
+  return __vec_shuffle(_T1{__x[0]}, __y, __seq, [=](int __i) {
+  __i = __idx_perm(__i);
+  return __i < _N0 ? __i : __i - _N0 + _N1;
+});
+else if constexpr (sizeof(__x) < sizeof(__y))
+  return __vec_shuffle(__intrin_bitcast<_T1>(__x), __y, __seq, [=](int 
__i) {
+  __i = __idx_perm(__i);
+  return __i < _N0 ? __i : __i - _N0 + _N1;
+});
+else
+#endif
+  return __builtin_shufflevector(__x, __y, [=] {
+  constexpr int __j = __idx_perm(_Is);
+  static_assert(__j < _N0 + _N1);
+  return __j;
+}()...);
+#else
+using _Tp = __remove_cvref_t;
+return __vector_type_t<_Tp, sizeof...(_Is)> {
+  [=]() -> _Tp {
+   constexpr int __j = __idx_perm(_Is);
+   static_assert(__j < _N0 + _N1);
+   if constexpr (__j < 0)
+ return 0;
+   else if constexpr (__j < _N0)
+ return __x[__j];
+   else
+ return __y[__j - _N0];
+  }()...
+};
+#endif
+  }
+
+template 
+  _GLIBCXX_SIMD_INTRINSIC constexpr auto
+  __vec_shuffle(_T0 __x, _Seq __seq, _Fun __idx_perm)
+  { return __vec_shuffle(__x, _T0(), __seq, __idx_perm); }
+
 // }}}
 // __concat{{{
 tem

[gcc r13-8840] libstdc++: Avoid MMX return types from __builtin_shufflevector

2024-06-11 Thread Matthias Kretz via Gcc-cvs
https://gcc.gnu.org/g:0efc27068e59cac6bd80ff962e92618a037bbfe8

commit r13-8840-g0efc27068e59cac6bd80ff962e92618a037bbfe8
Author: Matthias Kretz 
Date:   Wed May 15 11:02:22 2024 +0200

libstdc++: Avoid MMX return types from __builtin_shufflevector

This resolves a regression on i686 that was introduced with
r15-429-gfb1649f8b4ad50.

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115247
* include/experimental/bits/simd.h (__as_vector): Don't use
vector_size(8) on __i386__.
(__vec_shuffle): Never return MMX vectors, widen to 16 bytes
instead.
(concat): Fix padding calculation to pick up widening logic from
__as_vector.

(cherry picked from commit 241a6cc88d866fb36bd35ddb3edb659453d6322e)

Diff:
---
 libstdc++-v3/include/experimental/bits/simd.h | 39 +++
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/libstdc++-v3/include/experimental/bits/simd.h 
b/libstdc++-v3/include/experimental/bits/simd.h
index 6d3209b1a0e..ce7805e43e5 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -1630,7 +1630,12 @@ template 
  {
static_assert(is_simd<_V>::value);
using _Tp = typename _V::value_type;
+#ifdef __i386__
+   constexpr auto __bytes = sizeof(_Tp) == 8 ? 16 : sizeof(_Tp);
+   using _RV [[__gnu__::__vector_size__(__bytes)]] = _Tp;
+#else
using _RV [[__gnu__::__vector_size__(sizeof(_Tp))]] = _Tp;
+#endif
return _RV{__data(__x)};
  }
   }
@@ -2046,11 +2051,14 @@ template >
 // }}}
 // __vec_shuffle{{{
 template 
-  _GLIBCXX_SIMD_INTRINSIC constexpr auto
+  _GLIBCXX_SIMD_INTRINSIC constexpr
+  __vector_type_t()[0])>, 
sizeof...(_Is)>
   __vec_shuffle(_T0 __x, _T1 __y, index_sequence<_Is...> __seq, _Fun 
__idx_perm)
   {
 constexpr int _N0 = sizeof(__x) / sizeof(__x[0]);
 constexpr int _N1 = sizeof(__y) / sizeof(__y[0]);
+using _Tp = remove_reference_t()[0])>;
+using _RV [[maybe_unused]] = __vector_type_t<_Tp, sizeof...(_Is)>;
 #if __has_builtin(__builtin_shufflevector)
 #ifdef __clang__
 // Clang requires _T0 == _T1
@@ -2070,14 +2078,23 @@ template 
 });
 else
 #endif
-  return __builtin_shufflevector(__x, __y, [=] {
-  constexpr int __j = __idx_perm(_Is);
-  static_assert(__j < _N0 + _N1);
-  return __j;
-}()...);
+  {
+   const auto __r = __builtin_shufflevector(__x, __y, [=] {
+  constexpr int __j = __idx_perm(_Is);
+  static_assert(__j < _N0 + _N1);
+  return __j;
+}()...);
+#ifdef __i386__
+   if constexpr (sizeof(__r) == sizeof(_RV))
+ return __r;
+   else
+ return _RV {__r[_Is]...};
+#else
+   return __r;
+#endif
+  }
 #else
-using _Tp = __remove_cvref_t;
-return __vector_type_t<_Tp, sizeof...(_Is)> {
+return _RV {
   [=]() -> _Tp {
constexpr int __j = __idx_perm(_Is);
static_assert(__j < _N0 + _N1);
@@ -4312,9 +4329,9 @@ template 
__vec_shuffle(__as_vector(__xs)..., 
std::make_index_sequence<_RW::_S_full_size>(),
  [](int __i) {
constexpr int __sizes[2] = 
{int(simd_size_v<_Tp, _As>)...};
-   constexpr int __padding0
- = sizeof(__vector_type_t<_Tp, __sizes[0]>) / 
sizeof(_Tp)
- - __sizes[0];
+   constexpr int __vsizes[2]
+ = {int(sizeof(__as_vector(__xs)) / 
sizeof(_Tp))...};
+   constexpr int __padding0 = __vsizes[0] - 
__sizes[0];
return __i >= _Np ? -1 : __i < __sizes[0] ? __i 
: __i + __padding0;
  })};
   }


[gcc r13-8841] libstdc++: Fix simd conversion for -fno-signed-char for Clang

2024-06-11 Thread Matthias Kretz via Libstdc++-cvs
https://gcc.gnu.org/g:ef2169090d0868e4718c2ebf25365aaa52c22139

commit r13-8841-gef2169090d0868e4718c2ebf25365aaa52c22139
Author: Matthias Kretz 
Date:   Mon Jun 3 12:02:07 2024 +0200

libstdc++: Fix simd conversion for -fno-signed-char for Clang

The special case for Clang in the trait producing a signed integer type
lead to the trait returning 'char' where it should have been 'signed
char'. This workaround was introduced because on Clang the return type
of vector compares was not convertible to '_SimdWrapper<
__int_for_sizeof_t<...' unless '__int_for_sizeof_t' was an alias
for 'char'. In order to not rewrite the complete mask type code (there
is code scattered around the implementation assuming signed integers),
this needs to be 'signed char'; so the special case for Clang needs to
be removed.
The conversion issue is now solved in _SimdWrapper, which now
additionally allows conversion from vector types with compatible
integral type.

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115308
* include/experimental/bits/simd.h (__int_for_sizeof): Remove
special cases for __clang__.
(_SimdWrapper): Change constructor overload set to allow
conversion from vector types with integral conversions via bit
reinterpretation.

(cherry picked from commit 8e36cf4c5c9140915d001db132a900b48037)

Diff:
---
 libstdc++-v3/include/experimental/bits/simd.h | 45 ---
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/libstdc++-v3/include/experimental/bits/simd.h 
b/libstdc++-v3/include/experimental/bits/simd.h
index ce7805e43e5..e6c407d86fa 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -584,19 +584,12 @@ template 
 static_assert(_Bytes > 0);
 if constexpr (_Bytes == sizeof(int))
   return int();
-  #ifdef __clang__
-else if constexpr (_Bytes == sizeof(char))
-  return char();
-  #else
 else if constexpr (_Bytes == sizeof(_SChar))
   return _SChar();
-  #endif
 else if constexpr (_Bytes == sizeof(short))
   return short();
-  #ifndef __clang__
 else if constexpr (_Bytes == sizeof(long))
   return long();
-  #endif
 else if constexpr (_Bytes == sizeof(_LLong))
   return _LLong();
   #ifdef __SIZEOF_INT128__
@@ -2712,6 +2705,8 @@ template 
 
 // }}}
 // _SimdWrapper{{{
+struct _DisabledSimdWrapper;
+
 template 
   struct _SimdWrapper<
 _Tp, _Width,
@@ -2721,16 +2716,17 @@ template 
  == sizeof(__vector_type_t<_Tp, _Width>),
   __vector_type_t<_Tp, _Width>>
   {
-using _Base
-  = _SimdWrapperBase<__has_iec559_behavior<__signaling_NaN, _Tp>::value
-  && sizeof(_Tp) * _Width
-   == sizeof(__vector_type_t<_Tp, _Width>),
-__vector_type_t<_Tp, _Width>>;
+static constexpr bool _S_need_default_init
+  = __has_iec559_behavior<__signaling_NaN, _Tp>::value
+ and sizeof(_Tp) * _Width == sizeof(__vector_type_t<_Tp, _Width>);
+
+using _BuiltinType = __vector_type_t<_Tp, _Width>;
+
+using _Base = _SimdWrapperBase<_S_need_default_init, _BuiltinType>;
 
 static_assert(__is_vectorizable_v<_Tp>);
 static_assert(_Width >= 2); // 1 doesn't make sense, use _Tp directly then
 
-using _BuiltinType = __vector_type_t<_Tp, _Width>;
 using value_type = _Tp;
 
 static inline constexpr size_t _S_full_size
@@ -2766,13 +2762,26 @@ template 
 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper&
 operator=(_SimdWrapper&&) = default;
 
-template >,
-is_same<_V, __intrinsic_type_t<_Tp, _Width>
+// Convert from exactly matching __vector_type_t
+using _SimdWrapperBase<_S_need_default_init, 
_BuiltinType>::_SimdWrapperBase;
+
+// Convert from __intrinsic_type_t if __intrinsic_type_t and 
__vector_type_t differ, otherwise
+// this ctor should not exist. Making the argument type unusable is our 
next best solution.
+_GLIBCXX_SIMD_INTRINSIC constexpr
+_SimdWrapper(conditional_t>,
+  _DisabledSimdWrapper, __intrinsic_type_t<_Tp, 
_Width>> __x)
+: _Base(__vector_bitcast<_Tp, _Width>(__x)) {}
+
+// Convert from different __vector_type_t, but only if bit 
reinterpretation is a correct
+// conversion of the value_type
+template ,
+ typename = enable_if_t
+  and is_integral_v>>
   _GLIBCXX_SIMD_INTRINSIC constexpr
   _SimdWrapper(_V __x)
-  // __vector_bitcast can convert e.g. __m128 to __vector(2) float
-  : _Base(__vector_bitcast<_Tp, _Width>(__x)) {}
+  : _Base(reinterpret_cast<_BuiltinType>(__x)) {}
 
 template  && ...)


[gcc r12-10504] c-family: copy attribute diagnostic fixes [PR113262]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ca8ad807cf33ca9d74a2aecdd78b59af9834b882

commit r12-10504-gca8ad807cf33ca9d74a2aecdd78b59af9834b882
Author: Jakub Jelinek 
Date:   Tue Jan 9 15:37:04 2024 +0100

c-family: copy attribute diagnostic fixes [PR113262]

The copy attributes is allowed on decls as well as types and even has
checks whether decl (set to *node) is DECL_P or TYPE_P, but for diagnostics
unconditionally uses DECL_SOURCE_LOCATION (decl), which obviously only works
if it applies to a decl.

2024-01-09  Jakub Jelinek  

PR c/113262
* c-attribs.cc (handle_copy_attribute): Don't use
DECL_SOURCE_LOCATION (decl) if decl is not DECL_P, use 
input_location
instead.  Formatting fixes.

* gcc.dg/pr113262.c: New test.

(cherry picked from commit c9fc7f398e8b330ff12ec8a29bfa058b6daf6624)

Diff:
---
 gcc/c-family/c-attribs.cc   | 32 ++--
 gcc/testsuite/gcc.dg/pr113262.c |  6 ++
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 8221733613e..88f026336c9 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -2820,13 +2820,14 @@ handle_copy_attribute (tree *node, tree name, tree args,
   if (ref == error_mark_node)
 return NULL_TREE;
 
+  location_t loc = input_location;
+  if (DECL_P (decl))
+loc = DECL_SOURCE_LOCATION (decl);
   if (TREE_CODE (ref) == STRING_CST)
 {
   /* Explicitly handle this case since using a string literal
 as an argument is a likely mistake.  */
-  error_at (DECL_SOURCE_LOCATION (decl),
-   "%qE attribute argument cannot be a string",
-   name);
+  error_at (loc, "%qE attribute argument cannot be a string", name);
   return NULL_TREE;
 }
 
@@ -2837,10 +2838,8 @@ handle_copy_attribute (tree *node, tree name, tree args,
   /* Similar to the string case, since some function attributes
 accept literal numbers as arguments (e.g., alloc_size or
 nonnull) using one here is a likely mistake.  */
-  error_at (DECL_SOURCE_LOCATION (decl),
-   "%qE attribute argument cannot be a constant arithmetic "
-   "expression",
-   name);
+  error_at (loc, "%qE attribute argument cannot be a constant arithmetic "
+   "expression", name);
   return NULL_TREE;
 }
 
@@ -2848,12 +2847,11 @@ handle_copy_attribute (tree *node, tree name, tree args,
 {
   /* Another possible mistake (but indirect self-references aren't
 and diagnosed and shouldn't be).  */
-  if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
+  if (warning_at (loc, OPT_Wattributes,
  "%qE attribute ignored on a redeclaration "
- "of the referenced symbol",
- name))
-   inform (DECL_SOURCE_LOCATION (node[1]),
-   "previous declaration here");
+ "of the referenced symbol", name)
+ && DECL_P (node[1]))
+   inform (DECL_SOURCE_LOCATION (node[1]), "previous declaration here");
   return NULL_TREE;
 }
 
@@ -2873,7 +2871,8 @@ handle_copy_attribute (tree *node, tree name, tree args,
ref = TREE_OPERAND (ref, 1);
   else
break;
-} while (!DECL_P (ref));
+}
+  while (!DECL_P (ref));
 
   /* For object pointer expressions, consider those to be requests
  to copy from their type, such as in:
@@ -2905,8 +2904,7 @@ handle_copy_attribute (tree *node, tree name, tree args,
 to a variable, or variable attributes to a function.  */
  if (warning (OPT_Wattributes,
   "%qE attribute ignored on a declaration of "
-  "a different kind than referenced symbol",
-  name)
+  "a different kind than referenced symbol", name)
  && DECL_P (ref))
inform (DECL_SOURCE_LOCATION (ref),
"symbol %qD referenced by %qD declared here", ref, decl);
@@ -2956,9 +2954,7 @@ handle_copy_attribute (tree *node, tree name, tree args,
 }
   else if (!TYPE_P (decl))
 {
-  error_at (DECL_SOURCE_LOCATION (decl),
-   "%qE attribute must apply to a declaration",
-   name);
+  error_at (loc, "%qE attribute must apply to a declaration", name);
   return NULL_TREE;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr113262.c b/gcc/testsuite/gcc.dg/pr113262.c
new file mode 100644
index 000..ee55183b587
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113262.c
@@ -0,0 +1,6 @@
+/* PR c/113262 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int [[gnu::copy ("")]] a;  /* { dg-error "'copy' attribute argument cannot 
be a string" } */
+


[gcc r12-10508] docs: Fix 2 typos

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ba385435a9c6f2ae211c2595ffb96ee176aec12c

commit r12-10508-gba385435a9c6f2ae211c2595ffb96ee176aec12c
Author: Jakub Jelinek 
Date:   Thu Jan 25 09:10:08 2024 +0100

docs: Fix 2 typos

When looking into PR113572, I've noticed a typo in VECTOR_CST documentation
and grep found pasto of it elsewhere.

2024-01-25  Jakub Jelinek  

* doc/generic.texi (VECTOR_CST): Fix typo - petterns -> patterns.
* doc/rtl.texi (CONST_VECTOR): Likewise.

(cherry picked from commit 36c1384038f3b9f01124f0fc38bb3c930b1cbe8a)

Diff:
---
 gcc/doc/generic.texi | 2 +-
 gcc/doc/rtl.texi | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/generic.texi b/gcc/doc/generic.texi
index e5f9d1be8ea..1f7b00a2403 100644
--- a/gcc/doc/generic.texi
+++ b/gcc/doc/generic.texi
@@ -1144,7 +1144,7 @@ vector.  For example @{ 0, 1 @} could be seen as two 
patterns with
 one element each or one pattern with two elements (@var{base0} and
 @var{base1}).  The canonical encoding is always the one with the
 fewest patterns or (if both encodings have the same number of
-petterns) the one with the fewest encoded elements.
+patterns) the one with the fewest encoded elements.
 
 @samp{vector_cst_encoding_nelts (@var{v})} gives the total number of
 encoded elements in @var{v}, which is 6 in the example above.
diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
index 43c9ee8bffe..2aed9a0454e 100644
--- a/gcc/doc/rtl.texi
+++ b/gcc/doc/rtl.texi
@@ -1843,7 +1843,7 @@ vector.  For example @{ 0, 1 @} could be seen as two 
patterns with
 one element each or one pattern with two elements (@var{base0} and
 @var{base1}).  The canonical encoding is always the one with the
 fewest patterns or (if both encodings have the same number of
-petterns) the one with the fewest encoded elements.
+patterns) the one with the fewest encoded elements.
 
 @samp{const_vector_encoding_nelts (@var{v})} gives the total number of
 encoded elements in @var{v}, which is 6 in the example above.


[gcc r12-10505] libgomp: Fix up FLOCK fallback handling [PR113192]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:3f0d1e53892348d4df79d822a9910583378674d7

commit r12-10505-g3f0d1e53892348d4df79d822a9910583378674d7
Author: Jakub Jelinek 
Date:   Wed Jan 10 13:29:47 2024 +0100

libgomp: Fix up FLOCK fallback handling [PR113192]

My earlier change broke Solaris testing, because @FLOCK@ isn't substituted
just into libgomp/Makefile where it worked, but also the
testsuite/libgomp-site-extra.exp file where Make variables aren't present
and can't be substituted.

The following patch instead computes the absolute srcdir path and uses it
for FLOCK.

2024-01-10  Jakub Jelinek  

PR libgomp/113192
* configure.ac (FLOCK): Use $libgomp_abs_srcdir/testsuite/flock
instead of \$(abs_top_srcdir)/testsuite/flock.
* configure: Regenerated.

(cherry picked from commit 2fb3ee3ee82874e160309344bc3e52afeed8f26a)

Diff:
---
 libgomp/configure|  9 -
 libgomp/configure.ac | 11 ++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/libgomp/configure b/libgomp/configure
index be2c5a63d69..67f6b1435a5 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -16710,6 +16710,13 @@ done
 
 # Fallback if 'perl' is available.
 if test -z "$FLOCK"; then
+  # These need to be absolute paths, yet at the same time need to
+  # canonicalize only relative paths, because then amd will not unmount
+  # drives. Thus the use of PWDCMD: set it to 'pawd' or 'amq -w' if using amd.
+  case $srcdir in
+[\\/$]* | ?:[\\/]*) libgomp_abs_srcdir=${srcdir} ;;
+*) libgomp_abs_srcdir=`cd "$srcdir" && ${PWDCMD-pwd} || echo "$srcdir"` ;;
+  esac
   # Extract the first word of "perl", so it can be a program name with args.
 set dummy perl; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -16727,7 +16734,7 @@ do
   test -z "$as_dir" && as_dir=.
 for ac_exec_ext in '' $ac_executable_extensions; do
   if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-ac_cv_prog_FLOCK="$srcdir/testsuite/flock"
+ac_cv_prog_FLOCK="$libgomp_abs_srcdir/testsuite/flock"
 $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" 
>&5
 break 2
   fi
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index cc96e5b753b..dd88f20103a 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -343,7 +343,16 @@ AC_MSG_NOTICE([checking for flock implementation])
 AC_CHECK_PROGS(FLOCK, flock)
 # Fallback if 'perl' is available.
 if test -z "$FLOCK"; then
-  AC_CHECK_PROG(FLOCK, perl, $srcdir/testsuite/flock)
+  # These need to be absolute paths, yet at the same time need to
+  # canonicalize only relative paths, because then amd will not unmount
+  # drives. Thus the use of PWDCMD: set it to 'pawd' or 'amq -w' if using amd.
+  case $srcdir in
+changequote(,)dnl
+[\\/$]* | ?:[\\/]*) libgomp_abs_srcdir=${srcdir} ;;
+changequote([,])dnl
+*) libgomp_abs_srcdir=`cd "$srcdir" && ${PWDCMD-pwd} || echo "$srcdir"` ;;
+  esac
+  AC_CHECK_PROG(FLOCK, perl, $libgomp_abs_srcdir/testsuite/flock)
 fi
 
 # Get target configury.


[gcc r12-10506] cfgexpand: Workaround CSE of ADDR_EXPRs in VAR_DECL partitioning [PR113372]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:170c2bba7cb85b3ac9380a7d5a1c6d82b3c6aa63

commit r12-10506-g170c2bba7cb85b3ac9380a7d5a1c6d82b3c6aa63
Author: Jakub Jelinek 
Date:   Tue Jan 16 11:49:34 2024 +0100

cfgexpand: Workaround CSE of ADDR_EXPRs in VAR_DECL partitioning [PR113372]

The following patch adds a quick workaround to bugs in VAR_DECL
partitioning.
The problem is that there is no dependency between ADDR_EXPRs of local
decls and CLOBBERs of those vars, so VN can CSE uses of ADDR_EXPRs
(including ivopts integral variants thereof), which can break
add_scope_conflicts discovery of what variables are actually used
in certain region.
E.g. we can have
  ivtmp.40_3 = (unsigned long) &MEM  [(void *)&bitint.6 
+ 8B];
...
  uses of ivtmp.40_3
...
  bitint.6 ={v} {CLOBBER(eos)};
...
  ivtmp.28_43 = (unsigned long) &MEM  [(void 
*)&bitint.6 + 8B];
...
  uses of ivtmp.28_43
before VN (such as dom3), which the add_scope_conflicts code identifies as 2
independent uses of bitint.6 variable (which is correct), but then VN
determines ivtmp.28_43 is the same as ivtmp.40_3 and just uses ivtmp.40_3
even in the second region; at that point add_scope_conflict thinks the
bitint.6 variable is not used in that region anymore.

The following patch does a simple single def-stmt check for such ADDR_EXPRs
(rather than say trying to do a full propagation of what SSA_NAMEs can
contain ADDR_EXPRs of local variables), which seems to workaround all 4 PRs.

In addition to this patch I've used the attached one to gather statistics
on the total size of all variable partitions in a function and seems besides
the new testcases nothing is really affected compared to no patch (I've
actually just modified the patch to == OMP_SCAN instead of == ADDR_EXPR, so
it looks the same except that it never triggers).  The comparison wasn't
perfect because I've only gathered BITS_PER_WORD, main_input_filename (did
some replacement of build directories and /tmp/ccXX names of LTO to make
it more similar between the two bootstraps/regtests), current_function_name
and the total size of all variable partitions if any, because I didn't
record e.g. the optimization options and so e.g. torture tests which iterate
over options could have different partition sizes even in one compiler when
BITS_PER_WORD, main_input_filename and current_function_name are all equal.
So had to write an awk script to check if the first triple in the second
build appeared in the first one and the quadruple in the second build
appeared in the first one too, otherwise print result and that only
triggered in the new tests.
Also, the cc1plus binary according to objdump -dr is identical between the
two builds except for the ADDR_EXPR vs. OMP_SCAN constant in the two spots.

2024-01-16  Jakub Jelinek  

PR tree-optimization/113372
PR middle-end/90348
PR middle-end/110115
PR middle-end/111422
* cfgexpand.cc (add_scope_conflicts_2): New function.
(add_scope_conflicts_1): Use it.

* gcc.c-torture/execute/pr90348.c: New test.
* gcc.c-torture/execute/pr110115.c: New test.
* gcc.c-torture/execute/pr111422.c: New test.

(cherry picked from commit 1251d3957de04dc9b023a23c09400217e13deadb)

Diff:
---
 gcc/cfgexpand.cc   | 30 +++--
 gcc/testsuite/gcc.c-torture/execute/pr110115.c | 45 ++
 gcc/testsuite/gcc.c-torture/execute/pr111422.c | 39 ++
 gcc/testsuite/gcc.c-torture/execute/pr90348.c  | 38 ++
 4 files changed, 150 insertions(+), 2 deletions(-)

diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc
index 9c4d67ba7b6..eadec9a2bfd 100644
--- a/gcc/cfgexpand.cc
+++ b/gcc/cfgexpand.cc
@@ -571,6 +571,26 @@ visit_conflict (gimple *, tree op, tree, void *data)
   return false;
 }
 
+/* Helper function for add_scope_conflicts_1.  For USE on
+   a stmt, if it is a SSA_NAME and in its SSA_NAME_DEF_STMT is known to be
+   based on some ADDR_EXPR, invoke VISIT on that ADDR_EXPR.  */
+
+static inline void
+add_scope_conflicts_2 (tree use, bitmap work,
+  walk_stmt_load_store_addr_fn visit)
+{
+  if (TREE_CODE (use) == SSA_NAME
+  && (POINTER_TYPE_P (TREE_TYPE (use))
+ || INTEGRAL_TYPE_P (TREE_TYPE (use
+{
+  gimple *g = SSA_NAME_DEF_STMT (use);
+  if (is_gimple_assign (g))
+   if (tree op = gimple_assign_rhs1 (g))
+ if (TREE_CODE (op) == ADDR_EXPR)
+   visit (g, TREE_OPERAND (op, 0), op, work);
+}
+}
+
 /* Helper routine for add_scope_conflicts, calculating the active partitions
at the end of BB, leaving the result in WORK.  We're called to generate
conflicts when FOR_CONFLICT is true, otherwise we're just tracking
@@ -583,6 +603,8 @@

[gcc r12-10507] i386: Add -masm=intel profiling support [PR113122]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:bc51280bea76a382875da36e45ebb265b8c0

commit r12-10507-gbc51280bea76a382875da36e45ebb265b8c0
Author: Jakub Jelinek 
Date:   Thu Jan 18 10:21:12 2024 +0100

i386: Add -masm=intel profiling support [PR113122]

x86_function_profiler emits assembly directly into file and only emits
AT&T syntax.  The following patch adjusts it to emit MASM syntax
if -masm=intel.
As it doesn't use asm_fprintf, I can't use {|} syntax for the dialects.

I've tested using
for i in -mcmodel=large "-mcmodel=large -fpic" "" -fpic "-m32 -fpic" 
"-m32"; do
./xgcc -B ./ -c -O2 -fprofile $i -masm=att pr113122.c -o pr113122.o1;
./xgcc -B ./ -c -O2 -fprofile $i -masm=intel pr113122.c -o pr113122.o2;
objdump -dr pr113122.o1 > /tmp/1; objdump -dr pr113122.o2 > /tmp/2;
diff -up /tmp/1 /tmp/2; done
that the emitted sequences are identical after assembly.

2024-01-18  Jakub Jelinek  

PR target/113122
* config/i386/i386.cc (x86_function_profiler): Add -masm=intel
support.  Add missing space after , in emitted assembly in some
cases.  Formatting fixes.

* gcc.target/i386/pr113122-1.c: New test.
* gcc.target/i386/pr113122-2.c: New test.
* gcc.target/i386/pr113122-3.c: New test.
* gcc.target/i386/pr113122-4.c: New test.

(cherry picked from commit d4a2d91b46b2cf758b249a4545e34287e90da23b)

Diff:
---
 gcc/config/i386/i386.cc| 62 --
 gcc/testsuite/gcc.target/i386/pr113122-1.c | 10 +
 gcc/testsuite/gcc.target/i386/pr113122-2.c | 11 ++
 gcc/testsuite/gcc.target/i386/pr113122-3.c |  9 +
 gcc/testsuite/gcc.target/i386/pr113122-4.c | 10 +
 5 files changed, 90 insertions(+), 12 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 6b6142f4aa0..af42e4b9739 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -21532,7 +21532,10 @@ x86_function_profiler (FILE *file, int labelno 
ATTRIBUTE_UNUSED)
   if (TARGET_64BIT)
 {
 #ifndef NO_PROFILE_COUNTERS
-  fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);
+  if (ASSEMBLER_DIALECT == ASM_INTEL)
+   fprintf (file, "\tlea\tr11, %sP%d[rip]\n", LPREFIX, labelno);
+  else
+   fprintf (file, "\tleaq\t%sP%d(%%rip), %%r11\n", LPREFIX, labelno);
 #endif
 
   if (!TARGET_PECOFF)
@@ -21543,12 +21546,29 @@ x86_function_profiler (FILE *file, int labelno 
ATTRIBUTE_UNUSED)
  /* NB: R10 is caller-saved.  Although it can be used as a
 static chain register, it is preserved when calling
 mcount for nested functions.  */
- fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n",
-  mcount_name);
+ if (ASSEMBLER_DIALECT == ASM_INTEL)
+   fprintf (file, "1:\tmovabs\tr10, OFFSET FLAT:%s\n"
+  "\tcall\tr10\n", mcount_name);
+ else
+   fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n",
+mcount_name);
  break;
case CM_LARGE_PIC:
 #ifdef NO_PROFILE_COUNTERS
- fprintf (file, "1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n");
+ if (ASSEMBLER_DIALECT == ASM_INTEL)
+   {
+ fprintf (file, "1:movabs\tr11, "
+"OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-1b\n");
+ fprintf (file, "\tlea\tr10, 1b[rip]\n");
+ fprintf (file, "\tadd\tr10, r11\n");
+ fprintf (file, "\tmovabs\tr11, OFFSET FLAT:%s@PLTOFF\n",
+  mcount_name);
+ fprintf (file, "\tadd\tr10, r11\n");
+ fprintf (file, "\tcall\tr10\n");
+ break;
+   }
+ fprintf (file,
+  "1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n");
  fprintf (file, "\tleaq\t1b(%%rip), %%r10\n");
  fprintf (file, "\taddq\t%%r11, %%r10\n");
  fprintf (file, "\tmovabsq\t$%s@PLTOFF, %%r11\n", mcount_name);
@@ -21560,7 +21580,11 @@ x86_function_profiler (FILE *file, int labelno 
ATTRIBUTE_UNUSED)
  break;
case CM_SMALL_PIC:
case CM_MEDIUM_PIC:
- fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
+ if (ASSEMBLER_DIALECT == ASM_INTEL)
+   fprintf (file, "1:\tcall\t[QWORD PTR %s@GOTPCREL[rip]]\n",
+mcount_name);
+ else
+   fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
  break;
default:
  x86_print_call_or_nop (file, mcount_name);
@@ -21573,23 +21597,37 @@ x86_function_profiler (FILE *file, int labelno 
ATTRIBUTE_UNUSED)
   else if (flag_pic)
 {
 #ifndef NO_PROFILE_COUNTERS
-  fprintf (file, "\tleal\t%sP%d@G

[gcc r12-10517] libquadmath: Don't assume the storage for __float128 arguments is aligned [PR114533]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:9987fe67cf6211515d8ebf6528cc83c77dfb5bf3

commit r12-10517-g9987fe67cf6211515d8ebf6528cc83c77dfb5bf3
Author: Jakub Jelinek 
Date:   Wed Apr 3 10:02:35 2024 +0200

libquadmath: Don't assume the storage for __float128 arguments is aligned 
[PR114533]

With the 
register_printf_type/register_printf_modifier/register_printf_specifier
APIs the C library is just told the size of the argument and is provided 
with
a callback to fetch the argument from va_list using va_arg into C library 
provided
memory.  The C library isn't told what alignment requirement it has, but we 
were
using direct load of a __float128 value from that memory which assumes
__alignof (__float128) alignment.

The following patch fixes that by using memcpy instead.

I haven't been able to reproduce an actual crash, tried
 #include 
 #include 
 #include 

int main ()
{
  __float128 r;
  int prec = 20;
  int width = 46;
  char buf[128];

  r = 2.0q;
  r = sqrtq (r);
  int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
  if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: +1.41421356237309504880e+00 */
  quadmath_snprintf (buf, sizeof buf, "%Qa", r);
  if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
  n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
  if (n > -1)
{
  char *str = malloc (n + 1);
  if (str)
{
  quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
  printf ("%s\n", str);
  /* Prints: +1.41421356237309504880e+00 */
}
  free (str);
}
  printf ("%+-#*.20Qe\n", width, r);
  printf ("%Qa\n", r);
  printf ("%+-#46.*Qe\n", prec, r);
  printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r);
  return 0;
}
In any case, I think memcpy for loading from it is right.

2024-04-03  Simon Chopin  
Jakub Jelinek  

PR libquadmath/114533
* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy
__float128 out of args.
* printf/printf_fphex.c (__quadmath_printf_fphex): Likewise.

Signed-off-by: Simon Chopin 
(cherry picked from commit 8455d6f6cd43b7b143ab9ee19437452fceba9cc9)

Diff:
---
 libquadmath/printf/printf_fp.c| 2 +-
 libquadmath/printf/printf_fphex.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libquadmath/printf/printf_fp.c b/libquadmath/printf/printf_fp.c
index 8effcee88fa..9968aa5307c 100644
--- a/libquadmath/printf/printf_fp.c
+++ b/libquadmath/printf/printf_fp.c
@@ -363,7 +363,7 @@ __quadmath_printf_fp (struct __quadmath_printf_file *fp,
 
   /* Fetch the argument value. */
 {
-  fpnum = **(const __float128 **) args[0];
+  memcpy (&fpnum, *(const void *const *) args[0], sizeof (fpnum));
 
   /* Check for special values: not a number or infinity.  */
   if (isnanq (fpnum))
diff --git a/libquadmath/printf/printf_fphex.c 
b/libquadmath/printf/printf_fphex.c
index a40a6b00945..ddb413563c6 100644
--- a/libquadmath/printf/printf_fphex.c
+++ b/libquadmath/printf/printf_fphex.c
@@ -163,7 +163,8 @@ __quadmath_printf_fphex (struct __quadmath_printf_file *fp,
 
   /* Fetch the argument value. */
 {
-  fpnum.value = **(const __float128 **) args[0];
+  memcpy (&fpnum.value, *(const void *const *) args[0],
+ sizeof (fpnum.value));
 
   /* Check for special values: not a number or infinity.  */
   if (isnanq (fpnum.value))


[gcc r12-10509] tree-ssa-strlen: Fix up handle_store [PR113603]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:f5758e8142d8926f9a3e3500ba3c9956054dfaf8

commit r12-10509-gf5758e8142d8926f9a3e3500ba3c9956054dfaf8
Author: Jakub Jelinek 
Date:   Tue Jan 30 09:58:05 2024 +0100

tree-ssa-strlen: Fix up handle_store [PR113603]

Since r10-2101-gb631bdb3c16e85f35d3 handle_store uses
count_nonzero_bytes{,_addr} which (more recently limited to statements
with the same vuse) can walk earlier statements feeding the rhs
of the store and call get_stridx on it.
Unlike most of the other functions where get_stridx is called first on
rhs and only later on lhs, handle_store calls get_stridx on the lhs before
the count_nonzero_bytes* call and does some si->nonzero_bytes comparison
on it.
Now, strinfo structures are refcounted and it is important not to screw
it up.
What happens on the following testcase is that we call get_strinfo on the
destination idx's base (g), which returns a strinfo at that moment
with refcount of 2, one copy referenced in bb 2 final strinfos, one in bb 3
(the vector of strinfos was unshared from the dominator there because some
other strinfo was added) and finally we process a store in bb 6.
Now, count_nonzero_bytes is called and that sees &g[1] in a PHI and
calls get_stridx on it, which in turn calls get_stridx_plus_constant
because &g + 1 address doesn't have stridx yet.  This creates a new
strinfo for it:
  si = new_strinfo (ptr, idx, build_int_cst (size_type_node, nonzero_chars),
basesi->full_string_p);
  set_strinfo (idx, si);
and the latter call, because it is the first one in bb 6 that needs it,
unshares the stridx_to_strinfo vector (so refcount of the g strinfo becomes
3).
Now, get_stridx_plus_constant needs to chain the new strinfo of &g[1] in
between the related strinfos, so after the g record.  Because the strinfo
is now shared between the current bb and 2 other bbs, it needs to
unshare_strinfo it (creating a new strinfo which can be modified as a copy
of the old one, decrementing refcount of the old shared one and setting
refcount of the new one to 1):
  if (strinfo *nextsi = get_strinfo (chainsi->next))
{
  nextsi = unshare_strinfo (nextsi);
  si->next = nextsi->idx;
  nextsi->prev = idx;
}
  chainsi = unshare_strinfo (chainsi);
  if (chainsi->first == 0)
chainsi->first = chainsi->idx;
  chainsi->next = idx;
Now, the bug is that the caller of this a couple of frames above,
handle_store, holds on a pointer to this g strinfo (but doesn't know
about the unsharing, so the pointer is to the old strinfo with refcount
of 2), and later needs to update it, so it
  si = unshare_strinfo (si);
and modifies some fields in it.
This creates a new strinfo (with refcount of 1 which is stored into
the vector of the current bb) based on the old strinfo for g and
decrements refcount of the old one to 1.  So, now we are in inconsistent
state, because the old strinfo for g is referenced in bb 2 and bb 3
vectors, but has just refcount of 1, and then have one strinfo (the one
created by unshare_strinfo (chainsi) in get_stridx_plus_constant) which
has refcount of 1 but isn't referenced from anywhere anymore.
Later on when we free one of the bb 2 or bb 3 vectors (forgot which)
that decrements refcount from 1 to 0 and poisons the strinfo/returns it to
the pool, but then maybe_invalidate when looking at the other bb's pointer
to it ICEs.

The following patch fixes it by calling get_strinfo again, it is guaranteed
to return non-NULL, but could be an unshared copy instead of the originally
fetched shared one.

I believe we only need to do this refetching for the case where get_strinfo
is called on the lhs before get_stridx is called on other operands, because
we should be always modifying (apart from the chaining changes) the strinfo
for the destination of the statements, not other strinfos just consumed in
there.

2024-01-30  Jakub Jelinek  

PR tree-optimization/113603
* tree-ssa-strlen.cc (strlen_pass::handle_store): After
count_nonzero_bytes call refetch si using get_strinfo in case it
has been unshared in the meantime.

* gcc.c-torture/compile/pr113603.c: New test.

(cherry picked from commit d7250c1e02478586a0cd6d5cb67bf4d17249a7e7)

Diff:
---
 gcc/testsuite/gcc.c-torture/compile/pr113603.c | 40 ++
 gcc/tree-ssa-strlen.cc |  3 ++
 2 files changed, 43 insertions(+)

diff --git a/gcc/testsuite/gcc.c-torture/compile/pr113603.c 
b/gcc/testsuite/gcc.c-torture/compile/pr113603.c
new file mode 100644
index 000..0d4e817fbef
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr113603.c
@@ -0,0 +1,40 @@
+/* PR tree-optimization/113603 */
+
+i

[gcc r12-10510] ggc-common: Fix save PCH assertion

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e6976013c0910a1043b82a820180f01f356ffd3d

commit r12-10510-ge6976013c0910a1043b82a820180f01f356ffd3d
Author: Jakub Jelinek 
Date:   Sat Feb 3 14:37:19 2024 +0100

ggc-common: Fix save PCH assertion

We are getting a gnuradio PCH ICE
/usr/include/pybind11/stl.h:447:1: internal compiler error: in gt_pch_save, 
at ggc-common.cc:693
0x1304e7d gt_pch_save(_IO_FILE*)
../../gcc/ggc-common.cc:693
0x12a45fb c_common_write_pch()
../../gcc/c-family/c-pch.cc:175
0x18ad711 c_parse_final_cleanups()
../../gcc/cp/decl2.cc:5062
0x213988b c_common_parse_file()
../../gcc/c-family/c-opts.cc:1319
(unfortunately it isn't reproduceable always, but often needs
up to 100 attempts, isn't reproduceable in a cross etc.).
The bug is in the assertion I've added in gt_pch_save when adding
relocation support for the PCH files in case they happen not to be
mmapped at the selected address.
addr is a relocated address which points to a location in the PCH
blob (starting at mmi.preferred_base, with mmi.size bytes) which contains
a pointer that needs to be relocated.  So the assertion is meant to
verify the address is within the PCH blob, obviously it needs to be
equal or above mmi.preferred_base, but I got the other comparison wrong
and when one is very unlucky and the last sizeof (void *) bytes of the
blob happen to be a pointer which needs to be relocated, such as on the
s390x host addr 0x8008a04ff8, mmi.preferred_base 0x80 and
mmi.size 0x8a05000, addr + sizeof (void *) is equal to mmi.preferred_base +
mmi.size and that is still fine, both addresses are end of something.

2024-02-03  Jakub Jelinek  

* ggc-common.cc (gt_pch_save): Allow addr to be equal to
mmi.preferred_base + mmi.size - sizeof (void *).

(cherry picked from commit a4e240643cfa387579d4fa2bf9210a7d20433847)

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

diff --git a/gcc/ggc-common.cc b/gcc/ggc-common.cc
index 755d166417a..002212f8203 100644
--- a/gcc/ggc-common.cc
+++ b/gcc/ggc-common.cc
@@ -670,7 +670,7 @@ gt_pch_save (FILE *f)
 {
   gcc_assert ((uintptr_t) addr >= (uintptr_t) mmi.preferred_base
  && ((uintptr_t) addr + sizeof (void *)
- < (uintptr_t) mmi.preferred_base + mmi.size));
+ <= (uintptr_t) mmi.preferred_base + mmi.size));
   if (addr == last_addr)
continue;
   if (last_addr == NULL)


[gcc r12-10511] attribs: Don't canonicalize lookup_scoped_attribute_spec argument [PR113674]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:fda7a897d037ff1c59630f0a741eb20e68f45848

commit r12-10511-gfda7a897d037ff1c59630f0a741eb20e68f45848
Author: Jakub Jelinek 
Date:   Mon Feb 12 20:45:01 2024 +0100

attribs: Don't canonicalize lookup_scoped_attribute_spec argument [PR113674]

The C and C++ FEs when parsing attributes already canonicalize them
(i.e. if they start with __ and end with __ substrings, we remove those).
lookup_attribute already verifies in gcc_assert that the first character
of name is not an underscore, and even lookup_scoped_attribute_spec doesn't
attempt to canonicalize the namespace it is passed.  But for some historic
reason it was canonicalizing the name argument, which misbehaves when
an attribute starts with  and ends with .
I believe it is just wrong to try to canonicalize
lookup_scope_attribute_spec name attribute, it should have been
canonicalized already, in other spots where it is called it is already
canonicalized before.

2024-02-12  Jakub Jelinek  

PR c++/113674
* attribs.cc (extract_attribute_substring): Remove.
(lookup_scoped_attribute_spec): Don't call it.

* c-c++-common/Wattributes-3.c: New test.

(cherry picked from commit b42e978f29b33071addff6d7bb8bcdb11d176606)

Diff:
---
 gcc/attribs.cc | 10 --
 gcc/testsuite/c-c++-common/Wattributes-3.c | 13 +
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index 876277dd5b3..f73e00b6201 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -109,15 +109,6 @@ static const struct attribute_spec empty_attribute_table[] 
=
   { NULL, 0, 0, false, false, false, false, NULL, NULL }
 };
 
-/* Return base name of the attribute.  Ie '__attr__' is turned into 'attr'.
-   To avoid need for copying, we simply return length of the string.  */
-
-static void
-extract_attribute_substring (struct substring *str)
-{
-  canonicalize_attr_name (str->str, str->length);
-}
-
 /* Insert an array of attributes ATTRIBUTES into a namespace.  This
array must be NULL terminated.  NS is the name of attribute
namespace.  IGNORED_P is true iff all unknown attributes in this
@@ -409,7 +400,6 @@ lookup_scoped_attribute_spec (const_tree ns, const_tree 
name)
 
   attr.str = IDENTIFIER_POINTER (name);
   attr.length = IDENTIFIER_LENGTH (name);
-  extract_attribute_substring (&attr);
   return attrs->attribute_hash->find_with_hash (&attr,
substring_hash (attr.str,
attr.length));
diff --git a/gcc/testsuite/c-c++-common/Wattributes-3.c 
b/gcc/testsuite/c-c++-common/Wattributes-3.c
new file mode 100644
index 000..a1a6d9a5895
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wattributes-3.c
@@ -0,0 +1,13 @@
+/* PR c++/113674 */
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-options "" } */
+
+[[noreturn]] int foo (int i)   /* { dg-warning "'__noreturn__' 
attribute (directive )?ignored" } */
+{
+  return i;
+}
+
+[[maybe_unused]] int bar (int i)   /* { dg-warning 
"'__maybe_unused__' attribute (directive )?ignored" } */
+{
+  return i;
+}


[gcc r12-10512] c: Handle scoped attributes in __has*attribute and scoped attribute parsing changes in -std=c11 etc.

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:c2cd5eefccf54074ea9f8dc677a9a05b8a880ae4

commit r12-10512-gc2cd5eefccf54074ea9f8dc677a9a05b8a880ae4
Author: Jakub Jelinek 
Date:   Thu Feb 22 19:32:02 2024 +0100

c: Handle scoped attributes in __has*attribute and scoped attribute parsing 
changes in -std=c11 etc. modes [PR114007]

We aren't able to parse __has_attribute (vendor::attr) (and 
__has_c_attribute
and __has_cpp_attribute) in strict C < C23 modes.  While in -std=gnu* modes
or in -std=c23 there is CPP_SCOPE token, in -std=c* (except for -std=c23)
there are is just a pair of CPP_COLON tokens.
The c-lex.cc hunk adds support for that, but always returns 0 in that case
unlike the GCC 14+ version.

2024-02-22  Jakub Jelinek  

PR c/114007
gcc/c-family/
* c-lex.cc (c_common_has_attribute): Parse 2 CPP_COLONs with
the first one with COLON_SCOPE flag the same as CPP_SCOPE but
ensure 0 is returned then.
gcc/testsuite/
* gcc.dg/c23-attr-syntax-8.c: New test.
libcpp/
* include/cpplib.h (COLON_SCOPE): Define to PURE_ZERO.
* lex.cc (_cpp_lex_direct): When lexing CPP_COLON with another
colon after it, if !CPP_OPTION (pfile, scope) set COLON_SCOPE
flag on the first CPP_COLON token.

(cherry picked from commit 37127ed975e09813eaa2d1cf1062055fce45dd16)

Diff:
---
 gcc/c-family/c-lex.cc| 32 ++--
 gcc/testsuite/gcc.dg/c23-attr-syntax-8.c | 12 
 libcpp/include/cpplib.h  |  1 +
 libcpp/lex.cc|  9 +++--
 4 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc
index 8bfa4f4024f..bd48bfc88e0 100644
--- a/gcc/c-family/c-lex.cc
+++ b/gcc/c-family/c-lex.cc
@@ -327,9 +327,28 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax)
   do
nxt_token = cpp_peek_token (pfile, idx++);
   while (nxt_token->type == CPP_PADDING);
-  if (nxt_token->type == CPP_SCOPE)
+  if (!c_dialect_cxx ()
+ && nxt_token->type == CPP_COLON
+ && (nxt_token->flags & COLON_SCOPE) != 0)
+   {
+ const cpp_token *prev_token = nxt_token;
+ do
+   nxt_token = cpp_peek_token (pfile, idx++);
+ while (nxt_token->type == CPP_PADDING);
+ if (nxt_token->type == CPP_COLON)
+   {
+ /* __has_attribute (vendor::attr) in -std=c17 etc. modes.
+:: isn't CPP_SCOPE but 2 CPP_COLON tokens, where the
+first one should have COLON_SCOPE flag to distinguish
+it from : :.  */
+ have_scope = true;
+ get_token_no_padding (pfile); // Eat first colon.
+   }
+ else
+   nxt_token = prev_token;
+   }
+  if (nxt_token->type == CPP_SCOPE || have_scope)
{
- have_scope = true;
  get_token_no_padding (pfile); // Eat scope.
  nxt_token = get_token_no_padding (pfile);
  if (nxt_token->type == CPP_NAME)
@@ -359,6 +378,15 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax)
 "attribute identifier required after scope");
  attr_name = NULL_TREE;
}
+ if (have_scope)
+   {
+ /* The parser in this case won't be able to parse
+[[vendor::attr]], so ensure 0 is returned.  */
+ result = 0;
+ attr_name = NULL_TREE;
+   }
+ else
+   have_scope = true;
}
   else
{
diff --git a/gcc/testsuite/gcc.dg/c23-attr-syntax-8.c 
b/gcc/testsuite/gcc.dg/c23-attr-syntax-8.c
new file mode 100644
index 000..6fff160dff0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-attr-syntax-8.c
@@ -0,0 +1,12 @@
+/* PR c/114007 */
+/* { dg-do compile } */
+/* { dg-options "-std=c11" } */
+
+#if __has_c_attribute (gnu::unused)
+[[gnu::unused]]
+#endif
+int i;
+#if __has_cpp_attribute (gnu::unused)
+[[gnu::unused]]
+#endif
+int j;
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 3eba6f74b57..abdc207d1a1 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -193,6 +193,7 @@ struct GTY(()) cpp_string {
 #define BOL(1 << 6) /* Token at beginning of line.  */
 #define PURE_ZERO  (1 << 7) /* Single 0 digit, used by the C++ frontend,
set in c-lex.cc.  */
+#define COLON_SCOPEPURE_ZERO /* Adjacent colons in C < 23.  */
 #define SP_DIGRAPH (1 << 8) /* # or ## token was a digraph.  */
 #define SP_PREV_WHITE  (1 << 9) /* If whitespace before a ##
operator, or before this token
diff --git a/libcpp/lex.cc b/libcpp/lex.cc
index fb1dfabb7af..04acaa72331 100644
--- a/libcpp/lex.cc
+++ b/libcpp/lex.cc
@@ -3945,8 +3945,13 @@ _cpp_lex_direct (cpp_reader *pfile)
 
 case ':':
   result->type = CPP

[gcc r12-10513] i386: Fix ICEs with SUBREGs from vector etc. constants to XFmode [PR114184]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:929972273e858a9a913b0d74e69ac2f8d7255c28

commit r12-10513-g929972273e858a9a913b0d74e69ac2f8d7255c28
Author: Jakub Jelinek 
Date:   Mon Mar 4 10:04:19 2024 +0100

i386: Fix ICEs with SUBREGs from vector etc. constants to XFmode [PR114184]

The Intel extended format has the various weird number categories,
pseudo denormals, pseudo infinities, pseudo NaNs and unnormals.
Those are not representable in the GCC real_value and so neither
GIMPLE nor RTX VIEW_CONVERT_EXPR/SUBREG folding folds those into
constants.

As can be seen on the following testcase, because it isn't folded
(since GCC 12, before that we were folding it) we can end up with
a SUBREG of a CONST_VECTOR or similar constant, which isn't valid
general_operand, so we ICE during vregs pass trying to recognize
the move instruction.
Initially I thought it is a middle-end bug, the movxf instruction
has general_operand predicate, but the middle-end certainly never
tests that predicate, seems moves are special optabs.
And looking at other mov optabs, e.g. for vector modes the i386
patterns use nonimmediate_operand predicate on the input, yet
ix86_expand_vector_move deals with CONSTANT_P and SUBREG of CONSTANT_P
arguments which if the predicate was checked couldn't ever make it through.

The following patch handles this case similarly to the
ix86_expand_vector_move's SUBREG of CONSTANT_P case, does it just for XFmode
because I believe that is the only mode that needs it from the scalar ones,
others should just be folded.

2024-03-04  Jakub Jelinek  

PR target/114184
* config/i386/i386-expand.cc (ix86_expand_move): If XFmode op1
is SUBREG of CONSTANT_P, force the SUBREG_REG into memory or
register.

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

(cherry picked from commit ea1c16f95b8fbaba4a7f3663ff9933ebedfb92a5)

Diff:
---
 gcc/config/i386/i386-expand.cc   | 17 +
 gcc/testsuite/gcc.target/i386/pr114184.c | 22 ++
 2 files changed, 39 insertions(+)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 304d5e7cbbc..c57a8f56dac 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -350,6 +350,23 @@ ix86_expand_move (machine_mode mode, rtx operands[])
 
 default:
   break;
+
+case SUBREG:
+  /* As not all values in XFmode are representable in real_value,
+we might be called with unfoldable SUBREGs of constants.  */
+  if (mode == XFmode
+ && CONSTANT_P (SUBREG_REG (op1))
+ && can_create_pseudo_p ())
+   {
+ machine_mode imode = GET_MODE (SUBREG_REG (op1));
+ rtx r = force_const_mem (imode, SUBREG_REG (op1));
+ if (r)
+   r = validize_mem (r);
+ else
+   r = force_reg (imode, SUBREG_REG (op1));
+ op1 = simplify_gen_subreg (mode, r, imode, SUBREG_BYTE (op1));
+   }
+  break;
 }
 
   if ((flag_pic || MACHOPIC_INDIRECT)
diff --git a/gcc/testsuite/gcc.target/i386/pr114184.c 
b/gcc/testsuite/gcc.target/i386/pr114184.c
new file mode 100644
index 000..360b3b95026
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr114184.c
@@ -0,0 +1,22 @@
+/* PR target/114184 */
+/* { dg-do compile } */
+/* { dg-options "-Og -mavx2" } */
+
+typedef unsigned char V __attribute__((vector_size (32)));
+typedef unsigned char W __attribute__((vector_size (16)));
+
+_Complex long double
+foo (void)
+{
+  _Complex long double d;
+  *(V *)&d = (V) { 149, 136, 89, 42, 38, 240, 196, 194 };
+  return d;
+}
+
+long double
+bar (void)
+{
+  long double d;
+  *(W *)&d = (W) { 149, 136, 89, 42, 38, 240, 196, 194 };
+  return d;
+}


[gcc r12-10518] fold-const: Handle NON_LVALUE_EXPR in native_encode_initializer [PR114537]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:42afabb838d511f5feb150bfa4e68b5880aae1fa

commit r12-10518-g42afabb838d511f5feb150bfa4e68b5880aae1fa
Author: Jakub Jelinek 
Date:   Thu Apr 4 10:47:52 2024 +0200

fold-const: Handle NON_LVALUE_EXPR in native_encode_initializer [PR114537]

The following testcase is incorrectly rejected.  The problem is that
for bit-fields native_encode_initializer expects the corresponding
CONSTRUCTOR elt value must be INTEGER_CST, but that isn't the case
here, it is wrapped into NON_LVALUE_EXPR by maybe_wrap_with_location.
We could STRIP_ANY_LOCATION_WRAPPER as well, but as all we are looking for
is INTEGER_CST inside, just looking through NON_LVALUE_EXPR seems easier.

2024-04-04  Jakub Jelinek  

PR c++/114537
* fold-const.cc (native_encode_initializer): Look through
NON_LVALUE_EXPR if val is INTEGER_CST.

* g++.dg/cpp2a/bit-cast16.C: New test.

(cherry picked from commit 1baec8deb014b8a7da58879a407a4c00cdeb5a09)

Diff:
---
 gcc/fold-const.cc   |  2 ++
 gcc/testsuite/g++.dg/cpp2a/bit-cast16.C | 16 
 2 files changed, 18 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index da96ed34a4c..70302943cea 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -8423,6 +8423,8 @@ native_encode_initializer (tree init, unsigned char *ptr, 
int len,
  if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
return 0;
 
+ if (TREE_CODE (val) == NON_LVALUE_EXPR)
+   val = TREE_OPERAND (val, 0);
  if (TREE_CODE (val) != INTEGER_CST)
return 0;
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/bit-cast16.C 
b/gcc/testsuite/g++.dg/cpp2a/bit-cast16.C
new file mode 100644
index 000..d298af67ef2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/bit-cast16.C
@@ -0,0 +1,16 @@
+// PR c++/114537
+// { dg-do compile { target c++20 } }
+
+namespace std {
+template
+constexpr T
+bit_cast (const F& f) noexcept
+{
+  return __builtin_bit_cast (T, f);
+}
+}
+
+struct A { signed char b : 1 = 0; signed char c : 7 = 0; };
+struct D { unsigned char e; };
+constexpr unsigned char f = std::bit_cast (A{}).e;
+static_assert (f == 0);


[gcc r12-10514] bb-reorder: Fix -freorder-blocks-and-partition ICEs on aarch64 with asm goto [PR110079]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b294d461e2efd6894ba6570ca003701c20fc3cd8

commit r12-10514-gb294d461e2efd6894ba6570ca003701c20fc3cd8
Author: Jakub Jelinek 
Date:   Thu Mar 7 10:02:49 2024 +0100

bb-reorder: Fix -freorder-blocks-and-partition ICEs on aarch64 with asm 
goto [PR110079]

The following testcase ICEs, because fix_crossing_unconditional_branches
thinks that asm goto is an unconditional jump and removes it, replacing it
with unconditional jump to one of the labels.
This doesn't happen on x86 because the function in question isn't invoked
there at all:
  /* If the architecture does not have unconditional branches that
 can span all of memory, convert crossing unconditional branches
 into indirect jumps.  Since adding an indirect jump also adds
 a new register usage, update the register usage information as
 well.  */
  if (!HAS_LONG_UNCOND_BRANCH)
fix_crossing_unconditional_branches ();
I think for the asm goto case, for the non-fallthru edge if any we should
handle it like any other fallthru (and fix_crossing_unconditional_branches
doesn't really deal with those, it only looks at explicit branches at the
end of bbs and we are in cfglayout mode at that point) and for the labels
we just pass the labels as immediates to the assembly and it is up to the
user to figure out how to store them/branch to them or whatever they want to
do.
So, the following patch fixes this by not treating asm goto as a simple
unconditional jump.

I really think that on the !HAS_LONG_UNCOND_BRANCH targets we have a bug
somewhere else, where outofcfglayout or whatever should actually create
those indirect jumps on the crossing edges instead of adding normal
unconditional jumps, I see e.g. in
__attribute__((cold)) int bar (char *);
__attribute__((hot)) int baz (char *);
void qux (int x) { if (__builtin_expect (!x, 1)) goto l1; bar (""); goto 
l1; l1: baz (""); }
void corge (int x) { if (__builtin_expect (!x, 0)) goto l1; baz (""); l2: 
return; l1: bar (""); goto l2; }
with -O2 -freorder-blocks-and-partition on aarch64 before/after this patch
just b .L? jumps which I believe are +-32MB, so if .text is larger than
32MB, it could fail to link, but this patch doesn't address that.

2024-03-07  Jakub Jelinek  

PR rtl-optimization/110079
* bb-reorder.cc (fix_crossing_unconditional_branches): Don't adjust
asm goto.

* gcc.dg/pr110079.c: New test.

(cherry picked from commit b209d905f5ce1fa9d76ce634fd54245ff340960b)

Diff:
---
 gcc/bb-reorder.cc   |  3 ++-
 gcc/testsuite/gcc.dg/pr110079.c | 43 +
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/gcc/bb-reorder.cc b/gcc/bb-reorder.cc
index 2c194aa9055..ef2a1923511 100644
--- a/gcc/bb-reorder.cc
+++ b/gcc/bb-reorder.cc
@@ -2266,7 +2266,8 @@ fix_crossing_unconditional_branches (void)
  /* Make sure the jump is not already an indirect or table jump.  */
 
  if (!computed_jump_p (last_insn)
- && !tablejump_p (last_insn, NULL, NULL))
+ && !tablejump_p (last_insn, NULL, NULL)
+ && asm_noperands (PATTERN (last_insn)) < 0)
{
  /* We have found a "crossing" unconditional branch.  Now
 we must convert it to an indirect jump.  First create
diff --git a/gcc/testsuite/gcc.dg/pr110079.c b/gcc/testsuite/gcc.dg/pr110079.c
new file mode 100644
index 000..1682f9c2344
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr110079.c
@@ -0,0 +1,43 @@
+/* PR rtl-optimization/110079 */
+/* { dg-do compile { target lra } } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-freorder-blocks-and-partition" { target freorder 
} } */
+
+int a;
+__attribute__((cold)) int bar (char *);
+__attribute__((hot)) int baz (char *);
+
+void
+foo (void)
+{
+l1:
+  while (a)
+;
+  bar ("");
+  asm goto ("" : : : : l2);
+  asm ("");
+l2:
+  goto l1;
+}
+
+void
+qux (void)
+{
+  asm goto ("" : : : : l1);
+  bar ("");
+  goto l1;
+l1:
+  baz ("");
+}
+
+void
+corge (void)
+{
+  asm goto ("" : : : : l1);
+  baz ("");
+l2:
+  return;
+l1:
+  bar ("");
+  goto l2;
+}


[gcc r12-10515] aarch64: Fix TImode __sync_*_compare_and_exchange expansion with LSE [PR114310]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:9f484597028f2b2862bf22003dbae25c24ce5930

commit r12-10515-g9f484597028f2b2862bf22003dbae25c24ce5930
Author: Jakub Jelinek 
Date:   Thu Mar 14 14:09:20 2024 +0100

aarch64: Fix TImode __sync_*_compare_and_exchange expansion with LSE 
[PR114310]

The following testcase ICEs with LSE atomics.
The problem is that the @atomic_compare_and_swap expander uses
aarch64_reg_or_zero predicate for the desired operand, which is fine,
given that for most of the modes and even for TImode in some cases
it can handle zero immediate just fine, but the TImode
@aarch64_compare_and_swap_lse just uses register_operand for
that operand instead, again intentionally so, because the casp,
caspa, caspl and caspal instructions need to use a pair of consecutive
registers for the operand and xzr is just one register and we can't
just store zero into the link register to emulate pair of zeros.

So, the following patch fixes that by forcing the newval operand into
a register for the TImode LSE case.

2024-03-14  Jakub Jelinek  

PR target/114310
* config/aarch64/aarch64.cc (aarch64_expand_compare_and_swap): For
TImode force newval into a register.

* gcc.dg/pr114310.c: New test.

(cherry picked from commit 9349aefa1df7ae36714b7b9f426ad46e314892d1)

Diff:
---
 gcc/config/aarch64/aarch64.cc   |  2 ++
 gcc/testsuite/gcc.dg/pr114310.c | 20 
 2 files changed, 22 insertions(+)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 96976abdbf4..f8082c4035e 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -23010,6 +23010,8 @@ aarch64_expand_compare_and_swap (rtx operands[])
 rval = copy_to_mode_reg (r_mode, oldval);
   else
emit_move_insn (rval, gen_lowpart (r_mode, oldval));
+  if (mode == TImode)
+   newval = force_reg (mode, newval);
 
   emit_insn (gen_aarch64_compare_and_swap_lse (mode, rval, mem,
   newval, mod_s));
diff --git a/gcc/testsuite/gcc.dg/pr114310.c b/gcc/testsuite/gcc.dg/pr114310.c
new file mode 100644
index 000..55edd800e42
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114310.c
@@ -0,0 +1,20 @@
+/* PR target/114310 */
+/* { dg-do run { target int128 } } */
+
+volatile __attribute__((aligned (sizeof (__int128_t __int128_t v = 10;
+
+int
+main ()
+{
+#if __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+  if (__sync_val_compare_and_swap (&v, (__int128_t) 10, (__int128_t) 0) != 10)
+__builtin_abort ();
+  if (__sync_val_compare_and_swap (&v, (__int128_t) 10, (__int128_t) 15) != 0)
+__builtin_abort ();
+  if (__sync_val_compare_and_swap (&v, (__int128_t) 0, (__int128_t) 42) != 0)
+__builtin_abort ();
+  if (__sync_val_compare_and_swap (&v, (__int128_t) 31, (__int128_t) 35) != 42)
+__builtin_abort ();
+#endif
+  return 0;
+}


[gcc r12-10516] icf: Reset SSA_NAME_{PTR, RANGE}_INFO in successfully merged functions [PR113907]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:81c300bf6836505ef1df1c4430972863c732fc14

commit r12-10516-g81c300bf6836505ef1df1c4430972863c732fc14
Author: Jakub Jelinek 
Date:   Thu Mar 14 17:48:30 2024 +0100

icf: Reset SSA_NAME_{PTR,RANGE}_INFO in successfully merged functions 
[PR113907]

AFAIK we have no code in LTO streaming to stream out or in
SSA_NAME_{RANGE,PTR}_INFO, so LTO effectively throws it all away
and let vrp1 and alias analysis after IPA recompute that.  There is
just one spot, for IPA VRP and IPA bit CCP we save/restore ranges
and set SSA_NAME_{PTR,RANGE}_INFO e.g. on parameters depending on what
we saved and propagated, but that is after streaming in bodies for the
post IPA optimizations.

Now, without LTO SSA_NAME_{RANGE,PTR}_INFO is already computed from
earlier in many cases (er.g. evrp and early alias analysis but other spots
too), but IPA ICF is ignoring the ranges and points-to details when
comparing the bodies.  I think ignoring that is just fine, that is
effectively what we do for LTO where we throw that information away
before the analysis, and not ignoring it could lead to fewer ICF merging
possibilities.

So, the following patch instead verifies that for LTO 
SSA_NAME_{PTR,RANGE}_INFO
just isn't there on SSA_NAMEs in functions into which other functions have
been ICFed, and for non-LTO throws that information away (which matches the
LTO behavior).

Another possibility would be to remember the SSA_NAME <-> SSA_NAME mapping
vector (just one of the 2) on successful sem_function::equals on the
sem_function which is not the chosen leader (e.g. how SSA_NAMEs in the
leader map to SSA_NAMEs in the other function) and use that vector
to union the ranges in sem_function::merge.  I can implement that for
comparison, but wanted to post this first if there is an agreement on
doing that or if Honza thinks we should take SSA_NAME_{RANGE,PTR}_INFO
into account.  I think we can compare SSA_NAME_RANGE_INFO, but have
no idea how to try to compare points to info.  And I think it will result
in less effective ICF for non-LTO vs. LTO unnecessarily.

2024-03-12  Jakub Jelinek  

PR middle-end/113907
* ipa-icf.cc (sem_item_optimizer::merge_classes): Reset
SSA_NAME_RANGE_INFO and SSA_NAME_PTR_INFO on successfully ICF merged
functions.

* gcc.dg/pr113907-1.c: New test.

(cherry picked from commit 7580e39452b65ab5fb5a06f3f1ad7d59720269b5)

Diff:
---
 gcc/ipa-icf.cc| 32 -
 gcc/testsuite/gcc.dg/pr113907-1.c | 49 +++
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index 6528a7a10b2..bf06ad522d9 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -3389,6 +3389,7 @@ sem_item_optimizer::merge_classes (unsigned int 
prev_class_count,
  continue;
 
sem_item *source = c->members[0];
+   bool this_merged_p = false;
 
if (DECL_NAME (source->decl)
&& MAIN_NAME_P (DECL_NAME (source->decl)))
@@ -3435,7 +3436,7 @@ sem_item_optimizer::merge_classes (unsigned int 
prev_class_count,
if (dbg_cnt (merged_ipa_icf))
  {
bool merged = source->merge (alias);
-   merged_p |= merged;
+   this_merged_p |= merged;
 
if (merged && alias->type == VAR)
  {
@@ -3444,6 +3445,35 @@ sem_item_optimizer::merge_classes (unsigned int 
prev_class_count,
  }
  }
  }
+
+   merged_p |= this_merged_p;
+   if (this_merged_p
+   && source->type == FUNC
+   && (!flag_wpa || flag_checking))
+ {
+   unsigned i;
+   tree name;
+   FOR_EACH_SSA_NAME (i, name, DECL_STRUCT_FUNCTION (source->decl))
+ {
+   /* We need to either merge or reset SSA_NAME_*_INFO.
+  For merging we don't preserve the mapping between
+  original and alias SSA_NAMEs from successful equals
+  calls.  */
+   if (POINTER_TYPE_P (TREE_TYPE (name)))
+ {
+   if (SSA_NAME_PTR_INFO (name))
+ {
+   gcc_checking_assert (!flag_wpa);
+   SSA_NAME_PTR_INFO (name) = NULL;
+ }
+ }
+   else if (SSA_NAME_RANGE_INFO (name))
+ {
+   gcc_checking_assert (!flag_wpa);
+   SSA_NAME_RANGE_INFO (name) = NULL;
+ }
+ }
+ }
   }
 
   if (!m_merged_variables.is_empty ())
diff --git a/gcc/testsuite/gcc.dg/pr113907-1.c 
b/gcc/testsuite/gcc.dg/pr113907-1.c
new file mode 100644
index 000..04c4fb8c128
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113907-1.c
@@ -0,0 

[gcc r12-10519] c++: Fix ICE with weird copy assignment operator [PR114572]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:f33e8ee4cb44e7a6326a894a9c153557238bde03

commit r12-10519-gf33e8ee4cb44e7a6326a894a9c153557238bde03
Author: Jakub Jelinek 
Date:   Fri Apr 5 09:31:28 2024 +0200

c++: Fix ICE with weird copy assignment operator [PR114572]

While ctors/dtors don't return anything (undeclared void or this pointer
on arm) and copy assignment operators normally return a reference to *this,
it isn't invalid to return uselessly some class object which might need
destructing, but the OpenMP clause handling code wasn't expecting that.

The following patch fixes that.

2024-04-05  Jakub Jelinek  

PR c++/114572
* cp-gimplify.cc (cxx_omp_clause_apply_fn): Call build_cplus_new
on build_call_a result if it has class type.

* testsuite/libgomp.c++/pr114572.C: New test.

(cherry picked from commit 592536eb3c0a97a55b1019ff0216ef77e6ca847e)

Diff:
---
 gcc/cp/cp-gimplify.cc|  4 
 libgomp/testsuite/libgomp.c++/pr114572.C | 24 
 2 files changed, 28 insertions(+)

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 7ae5327f693..4b7e5729ef1 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -2038,6 +2038,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
   TREE_PURPOSE (parm), fn,
   i - is_method, tf_warning_or_error);
   t = build_call_a (fn, i, argarray);
+  if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t)))
+   t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error);
   t = fold_convert (void_type_node, t);
   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   append_to_statement_list (t, &ret);
@@ -2071,6 +2073,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
   TREE_PURPOSE (parm), fn,
   i - is_method, tf_warning_or_error);
   t = build_call_a (fn, i, argarray);
+  if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t)))
+   t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error);
   t = fold_convert (void_type_node, t);
   return fold_build_cleanup_point_expr (TREE_TYPE (t), t);
 }
diff --git a/libgomp/testsuite/libgomp.c++/pr114572.C 
b/libgomp/testsuite/libgomp.c++/pr114572.C
new file mode 100644
index 000..21d5c847f8d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/pr114572.C
@@ -0,0 +1,24 @@
+// PR c++/114572
+// { dg-do run }
+// { dg-options "-fopenmp -O0" }
+
+#include 
+
+struct S
+{
+  S () : s (0) {}
+  ~S () {}
+  S operator= (const S &x) { s = x.s; return *this; }
+  int s;
+};
+
+int
+main ()
+{
+  S s;
+  #pragma omp parallel for lastprivate(s)
+  for (int i = 0; i < 10; ++i)
+s.s = i;
+  if (s.s != 9)
+abort ();
+}


[gcc r12-10520] vect: Don't clear base_misaligned in update_epilogue_loop_vinfo [PR114566]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:f8a327930b82e89ae1466cfacb9e8ac9f5c44e77

commit r12-10520-gf8a327930b82e89ae1466cfacb9e8ac9f5c44e77
Author: Jakub Jelinek 
Date:   Fri Apr 5 14:56:14 2024 +0200

vect: Don't clear base_misaligned in update_epilogue_loop_vinfo [PR114566]

The following testcase is miscompiled, because in the vectorized
epilogue the vectorizer assumes it can use aligned loads/stores
(if the base decl gets alignment increased), but it actually doesn't
increase that.
This is because r10-4203-g97c1460367 added the hunk following
patch removes.  The explanation feels reasonable, but actually it
is not true as the testcase proves.
The thing is, we vectorize the main loop with 64-byte vectors
and the corresponding data refs have base_alignment 16 (the
a array has DECL_ALIGN 128) and offset_alignment 32.  Now, because
of the offset_alignment 32 rather than 64, we need to use unaligned
loads/stores in the main loop (and ditto in the first load/store
in vectorized epilogue).  But the second load/store in the vectorized
epilogue uses only 32-byte vectors and because it is a multiple
of offset_alignment, it checks if we could increase alignment of the
a VAR_DECL, the function returns true, sets base_misaligned = true
and says the access is then aligned.
But when update_epilogue_loop_vinfo clears base_misaligned with the
assumption that the var had to have the alignment increased already,
the update of DECL_ALIGN doesn't happen anymore.

Now, I'd think this base_alignment = false was needed before
r10-4030-gd2db7f7901 change was committed where it incorrectly
overwrote DECL_ALIGN even if it was already larger, rather than
just always increasing it.  But with that change in, it doesn't
make sense to me anymore.

Note, the testcase is latent on the trunk, but reproduces on the 13
branch.

2024-04-05  Jakub Jelinek  

PR tree-optimization/114566
* tree-vect-loop.cc (update_epilogue_loop_vinfo): Don't clear
base_misaligned.

* gcc.target/i386/avx512f-pr114566.c: New test.

(cherry picked from commit a844095e17c1a5aada1364c6f6eaade87ead463c)

Diff:
---
 gcc/testsuite/gcc.target/i386/avx512f-pr114566.c | 34 
 gcc/tree-vect-loop.cc|  8 +-
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/avx512f-pr114566.c 
b/gcc/testsuite/gcc.target/i386/avx512f-pr114566.c
new file mode 100644
index 000..abfab1bfcd5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512f-pr114566.c
@@ -0,0 +1,34 @@
+/* PR tree-optimization/114566 */
+/* { dg-do run } */
+/* { dg-options "-O3 -mavx512f" } */
+/* { dg-additional-options "-fstack-protector-strong" { target 
fstack_protector } } */
+/* { dg-require-effective-target avx512f } */
+
+#define AVX512F
+#include "avx512f-helper.h"
+
+__attribute__((noipa)) int
+foo (float x, float y)
+{
+  float a[8][56];
+  __builtin_memset (a, 0, sizeof (a));
+
+  for (int j = 0; j < 8; j++)
+for (int k = 0; k < 56; k++)
+  {
+   float b = k * y;
+   if (b < 0.)
+ b = 0.;
+   if (b > 0.)
+ b = 0.;
+   a[j][k] += b;
+  }
+
+  return __builtin_log (x);
+}
+
+void
+TEST (void)
+{
+  foo (86.25f, 0.625f);
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index fd0e5a70a96..1abc43f396e 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -9499,9 +9499,7 @@ find_in_mapping (tree t, void *context)
corresponding dr_vec_info need to be reconnected to the EPILOGUE's
stmt_vec_infos, their statements need to point to their corresponding copy,
if they are gather loads or scatter stores then their reference needs to be
-   updated to point to its corresponding copy and finally we set
-   'base_misaligned' to false as we have already peeled for alignment in the
-   prologue of the main loop.  */
+   updated to point to its corresponding copy.  */
 
 static void
 update_epilogue_loop_vinfo (class loop *epilogue, tree advance)
@@ -9642,10 +9640,6 @@ update_epilogue_loop_vinfo (class loop *epilogue, tree 
advance)
}
   DR_STMT (dr) = STMT_VINFO_STMT (stmt_vinfo);
   stmt_vinfo->dr_aux.stmt = stmt_vinfo;
-  /* The vector size of the epilogue is smaller than that of the main loop
-so the alignment is either the same or lower. This means the dr will
-thus by definition be aligned.  */
-  STMT_VINFO_DR_INFO (stmt_vinfo)->base_misaligned = false;
 }
 
   epilogue_vinfo->shared->datarefs_copy.release ();


[gcc r12-10522] asan, v3: Fix up handling of > 32 byte aligned variables with -fsanitize=address -fstack-protector*

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:082fe43efd241caf8f757c056b98e1ae8b55c300

commit r12-10522-g082fe43efd241caf8f757c056b98e1ae8b55c300
Author: Jakub Jelinek 
Date:   Thu Apr 11 11:12:11 2024 +0200

asan, v3: Fix up handling of > 32 byte aligned variables with 
-fsanitize=address -fstack-protector* [PR110027]

On Tue, Mar 26, 2024 at 02:08:02PM +0800, liuhongt wrote:
> > > So, try to add some other variable with larger size and smaller 
alignment
> > > to the frame (and make sure it isn't optimized away).
> > >
> > > alignb above is the alignment of the first partition's var, if
> > > align_frame_offset really needs to depend on the var alignment, it 
probably
> > > should be the maximum alignment of all the vars with alignment
> > > alignb * BITS_PER_UNIT <=3D MAX_SUPPORTED_STACK_ALIGNMENT
> > >
>
> In asan_emit_stack_protection, when it allocated fake stack, it assume
> bottom of stack is also aligned to alignb. And the place violated this
> is the first var partition. which is 32 bytes offsets,  it should be
> BIGGEST_ALIGNMENT / BITS_PER_UNIT.
> So I think we need to use MAX (BIGGEST_ALIGNMENT /
> BITS_PER_UNIT, ASAN_RED_ZONE_SIZE) for the first var partition.

Your first patch aligned offsets[0] to maximum of alignb and
ASAN_RED_ZONE_SIZE.  But as I wrote in the reply to that mail, alignb there
is the alignment of just a single variable which is the first one to appear
in the sorted list and is placed in the highest spot in the stack frame.
That is not necessarily the largest alignment, the sorting ensures that it
is a variable with the largest size in the frame (and only if several of
them have equal size, largest alignment from the same sized ones).  Your
second patch used maximum of BIGGEST_ALIGNMENT / BITS_PER_UNIT and
ASAN_RED_ZONE_SIZE.  That doesn't change anything at all when using
-mno-avx512f - offsets[0] is still just 32-byte aligned in that case
relative to top of frame, just changes the -mavx512f case to be 64-byte
aligned offsets[0] (aka offsets[0] is then either 0 or -64 instead of either
0 or -32).  That will not help if any variable in the frame needs 128-byte,
256-byte, 512-byte ...  4096-byte alignment.  If you want to fix the bug in
the spot you've touched, you'd need to walk all the
stack_vars[stack_vars_sorted[si2]] for si2 [si + 1, n - 1] and for those
where the loop would do anything (i.e.
stack_vars[i2].representative == i2
&& TREE_CODE (decl2) == SSA_NAME
   ? SA.partition_to_pseudo[var_to_partition (SA.map, decl2)] == NULL_RTX
   : DECL_RTL (decl2) == pc_rtx
and the pred applies (but that means also walking the earlier ones!
because with -fstack-protector* the vars can be processed in several calls) 
and
alignb2 * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT
and compute maximum of those alignments.
That maximum is already computed,
data->asan_alignb = MAX (data->asan_alignb, alignb);
computes that, but you get the final result only after you do all the
expand_stack_vars calls.  You'd need to compute it before.

Though, that change would be still in the wrong place.
The thing is, it would be a waste of the precious stack space when it isn't
needed at all (e.g.  when asan will not at compile time do the use after
return checking, or if it won't do it at runtime, or even if it will do at
runtime it will waste the space on the stack).

The following patch fixes it solely for the __asan_stack_malloc_N
allocations, doesn't enlarge unnecessarily further the actual stack frame.
Because asan is only supported on FRAME_GROWS_DOWNWARD architectures
(mips, rs6000 and xtensa are conditional FRAME_GROWS_DOWNWARD arches, which
for -fsanitize=address or -fstack-protector* use FRAME_GROWS_DOWNWARD 1,
otherwise 0, others supporting asan always just use 1), the assumption for
the dynamic stack realignment is that the top of the stack frame (aka offset
0) is aligned to alignb passed to the function (which is the maximum of 
alignb
of all the vars in the frame).  As checked by the assertion in the patch,
offsets[0] is 0 most of the time and so that assumption is correct, the only
case when it is not 0 is if -fstack-protector* is on together with
-fsanitize=address and cfgexpand.cc (create_stack_guard) created a stack
guard.  That is the only variable which is allocated in the stack frame
right away, for all others with -fsanitize=address defer_stack_allocation
(or -fstack-protector*) returns true and so they aren't allocated
immediately but handled during the frame layout phases.  So, the original
frame_offset of 0 is changed because of the stack guard to
-pointer_size_in_bytes and later at the
  if (data->asan_vec.is_empty ())
{
  align_frame_offset (ASAN_RED_ZONE

[gcc r12-10525] internal-fn: Temporarily disable flag_trapv during .{ADD, SUB, MUL}_OVERFLOW etc. expansion [PR114753]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b3ef00f8b8d577d7b62cea36c13cf087a3b13d0c

commit r12-10525-gb3ef00f8b8d577d7b62cea36c13cf087a3b13d0c
Author: Jakub Jelinek 
Date:   Thu Apr 18 09:45:14 2024 +0200

internal-fn: Temporarily disable flag_trapv during .{ADD,SUB,MUL}_OVERFLOW 
etc. expansion [PR114753]

__builtin_{add,sub,mul}_overflow{,_p} builtins are well defined
for all inputs even for -ftrapv, and the -fsanitize=signed-integer-overflow
ifns shouldn't abort in libgcc but emit the desired ubsan diagnostics
or abort depending on -fsanitize* setting regardless of -ftrapv.
The expansion of these internal functions uses expand_expr* in various
places (e.g. MULT_EXPR at least in 2 spots), so temporarily disabling
flag_trapv in all those spots would be hard.
The following patch disables it around the bodies of 3 functions
which can do the expand_expr calls.
If it was in the C++ FE, I'd use some RAII sentinel, but I don't think
we have one in the middle-end.

2024-04-18  Jakub Jelinek  

PR middle-end/114753
* internal-fn.cc (expand_mul_overflow): Save flag_trapv and
temporarily clear it for the duration of the function, then
restore previous value.
(expand_vector_ubsan_overflow): Likewise.
(expand_arith_overflow): Likewise.

* gcc.dg/pr114753.c: New test.

(cherry picked from commit 6c152c9db3b5b9d43e12846fb7a44977c0b65fc2)

Diff:
---
 gcc/internal-fn.cc  | 19 +++
 gcc/testsuite/gcc.dg/pr114753.c | 14 ++
 2 files changed, 33 insertions(+)

diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index db23f66b021..ca9cf30b6b5 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -1395,7 +1395,11 @@ expand_mul_overflow (location_t loc, tree lhs, tree 
arg0, tree arg1,
   rtx target = NULL_RTX;
   signop sign;
   enum insn_code icode;
+  int save_flag_trapv = flag_trapv;
 
+  /* We don't want any __mulv?i3 etc. calls from the expansion of
+ these internal functions, so disable -ftrapv temporarily.  */
+  flag_trapv = 0;
   done_label = gen_label_rtx ();
   do_error = gen_label_rtx ();
 
@@ -2237,6 +2241,7 @@ expand_mul_overflow (location_t loc, tree lhs, tree arg0, 
tree arg1,
   else
expand_arith_overflow_result_store (lhs, target, mode, res);
 }
+  flag_trapv = save_flag_trapv;
 }
 
 /* Expand UBSAN_CHECK_* internal function if it has vector operands.  */
@@ -2257,7 +2262,11 @@ expand_vector_ubsan_overflow (location_t loc, enum 
tree_code code, tree lhs,
   rtx resvr = NULL_RTX;
   unsigned HOST_WIDE_INT const_cnt = 0;
   bool use_loop_p = (!cnt.is_constant (&const_cnt) || const_cnt > 4);
+  int save_flag_trapv = flag_trapv;
 
+  /* We don't want any __mulv?i3 etc. calls from the expansion of
+ these internal functions, so disable -ftrapv temporarily.  */
+  flag_trapv = 0;
   if (lhs)
 {
   optab op;
@@ -2387,6 +2396,7 @@ expand_vector_ubsan_overflow (location_t loc, enum 
tree_code code, tree lhs,
 }
   else if (resvr)
 emit_move_insn (lhsr, resvr);
+  flag_trapv = save_flag_trapv;
 }
 
 /* Expand UBSAN_CHECK_ADD call STMT.  */
@@ -2465,7 +2475,11 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
   prec0 = MIN (prec0, pr);
   pr = get_min_precision (arg1, uns1_p ? UNSIGNED : SIGNED);
   prec1 = MIN (prec1, pr);
+  int save_flag_trapv = flag_trapv;
 
+  /* We don't want any __mulv?i3 etc. calls from the expansion of
+ these internal functions, so disable -ftrapv temporarily.  */
+  flag_trapv = 0;
   /* If uns0_p && uns1_p, precop is minimum needed precision
  of unsigned type to hold the exact result, otherwise
  precop is minimum needed precision of signed type to
@@ -2506,6 +2520,7 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
  ops.location = loc;
  rtx tem = expand_expr_real_2 (&ops, NULL_RTX, mode, EXPAND_NORMAL);
  expand_arith_overflow_result_store (lhs, target, mode, tem);
+ flag_trapv = save_flag_trapv;
  return;
}
 
@@ -2529,16 +2544,19 @@ expand_arith_overflow (enum tree_code code, gimple 
*stmt)
  if (integer_zerop (arg0) && !unsr_p)
{
  expand_neg_overflow (loc, lhs, arg1, false, NULL);
+ flag_trapv = save_flag_trapv;
  return;
}
  /* FALLTHRU */
case PLUS_EXPR:
  expand_addsub_overflow (loc, code, lhs, arg0, arg1, unsr_p,
  unsr_p, unsr_p, false, NULL);
+ flag_trapv = save_flag_trapv;
  return;
case MULT_EXPR:
  expand_mul_overflow (loc, lhs, arg0, arg1, unsr_p,
   unsr_p, unsr_p, false, NULL);
+ flag_trapv = save_flag_trapv;
  return;
default:
  gcc_unreachable ();
@@ -2584,6 +2602,7 @@ expand_arith

[gcc r12-10523] c++: Fix bogus warnings about ignored annotations [PR114691]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e9b960edb01449786a29a8d196c476bfefc4f243

commit r12-10523-ge9b960edb01449786a29a8d196c476bfefc4f243
Author: Jakub Jelinek 
Date:   Fri Apr 12 20:53:10 2024 +0200

c++: Fix bogus warnings about ignored annotations [PR114691]

The middle-end warns about the ANNOTATE_EXPR added for while/for loops
if they declare a var inside of the loop condition.
This is because the assumption is that ANNOTATE_EXPR argument is used
immediately in a COND_EXPR (later GIMPLE_COND), but simplify_loop_decl_cond
wraps the ANNOTATE_EXPR inside of a TRUTH_NOT_EXPR, so it no longer
holds.

The following patch fixes that by adding the TRUTH_NOT_EXPR inside of the
ANNOTATE_EXPR argument if any.

2024-04-12  Jakub Jelinek  

PR c++/114691
* semantics.cc (simplify_loop_decl_cond): Use cp_build_unary_op with
TRUTH_NOT_EXPR on ANNOTATE_EXPR argument (if any) rather than
ANNOTATE_EXPR itself.

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

(cherry picked from commit 91146346f57cc54dfeb2669347edd0eb3d13af7f)

Diff:
---
 gcc/cp/semantics.cc |  6 +-
 gcc/testsuite/g++.dg/ext/pr114691.C | 22 ++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index d4d1b01b91e..2d29b0ae1b5 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -800,7 +800,11 @@ simplify_loop_decl_cond (tree *cond_p, tree body)
   *cond_p = boolean_true_node;
 
   if_stmt = begin_if_stmt ();
-  cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, false, tf_warning_or_error);
+  cond_p = &cond;
+  while (TREE_CODE (*cond_p) == ANNOTATE_EXPR)
+cond_p = &TREE_OPERAND (*cond_p, 0);
+  *cond_p = cp_build_unary_op (TRUTH_NOT_EXPR, *cond_p, false,
+  tf_warning_or_error);
   finish_if_stmt_cond (cond, if_stmt);
   finish_break_stmt ();
   finish_then_clause (if_stmt);
diff --git a/gcc/testsuite/g++.dg/ext/pr114691.C 
b/gcc/testsuite/g++.dg/ext/pr114691.C
new file mode 100644
index 000..bda8ff9b39f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/pr114691.C
@@ -0,0 +1,22 @@
+// PR c++/114691
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+void qux (int);
+int foo (int);
+
+void
+bar (int x)
+{
+  #pragma GCC ivdep
+  while (int y = foo (x))  // { dg-bogus "ignoring loop annotation" }
+qux (y);
+}
+
+void
+baz (int x)
+{
+  #pragma GCC ivdep
+  for (; int y = foo (x); )// { dg-bogus "ignoring loop annotation" }
+qux (y);
+}


[gcc r12-10521] c++: Fix up maybe_warn_for_constant_evaluated calls [PR114580]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b3b7176d5857f116a4a42d885df70f8847e4cd2a

commit r12-10521-gb3b7176d5857f116a4a42d885df70f8847e4cd2a
Author: Jakub Jelinek 
Date:   Tue Apr 9 09:31:42 2024 +0200

c++: Fix up maybe_warn_for_constant_evaluated calls [PR114580]

When looking at maybe_warn_for_constant_evaluated for the trivial
infinite loops patch, I've noticed that it can emit weird diagnostics
for if constexpr in templates, first warn that std::is_constant_evaluted()
always evaluates to false (because the function template is not constexpr)
and then during instantiation warn that std::is_constant_evaluted()
always evaluates to true (because it is used in if constexpr condition).
Now, only the latter is actually true, even when the if constexpr
is in a non-constexpr function, it will still always evaluate to true.

So, the following patch fixes it to call maybe_warn_for_constant_evaluated
always with IF_STMT_CONSTEXPR_P (if_stmt) as the second argument rather than
true if it is if constexpr with non-dependent condition etc.

2024-04-09  Jakub Jelinek  

PR c++/114580
* semantics.cc (finish_if_stmt_cond): Call
maybe_warn_for_constant_evaluated with IF_STMT_CONSTEXPR_P (if_stmt)
as the second argument, rather than true/false depending on if
it is if constexpr with non-dependent constant expression with
bool type.

* g++.dg/cpp2a/is-constant-evaluated15.C: New test.

(cherry picked from commit cfed80b9e4f562c99679739548df9369117dd791)

Diff:
---
 gcc/cp/semantics.cc|  4 +---
 .../g++.dg/cpp2a/is-constant-evaluated15.C | 28 ++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 0672d6c5b68..d4d1b01b91e 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -1026,6 +1026,7 @@ tree
 finish_if_stmt_cond (tree cond, tree if_stmt)
 {
   cond = maybe_convert_cond (cond);
+  maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt));
   if (IF_STMT_CONSTEXPR_P (if_stmt)
   && !type_dependent_expression_p (cond)
   && require_constant_expression (cond)
@@ -1034,12 +1035,9 @@ finish_if_stmt_cond (tree cond, tree if_stmt)
 converted to bool.  */
   && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
 {
-  maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/true);
   cond = instantiate_non_dependent_expr (cond);
   cond = cxx_constant_value (cond, NULL_TREE);
 }
-  else
-maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false);
   finish_cond (&IF_COND (if_stmt), cond);
   add_stmt (if_stmt);
   THEN_CLAUSE (if_stmt) = push_stmt_list ();
diff --git a/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated15.C 
b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated15.C
new file mode 100644
index 000..50a3cac6e07
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated15.C
@@ -0,0 +1,28 @@
+// PR c++/114580
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wtautological-compare" }
+
+namespace std {
+  constexpr inline bool
+  is_constant_evaluated () noexcept
+  {
+#if __cpp_if_consteval >= 202106L
+if consteval { return true; } else { return false; }
+#else
+return __builtin_is_constant_evaluated ();
+#endif
+  }
+}
+
+template 
+void foo ()
+{
+  if constexpr ((T) std::is_constant_evaluated ()) // { dg-warning 
"'std::is_constant_evaluated' always evaluates to true in 'if constexpr'" }
+;  // { dg-bogus 
"'std::is_constant_evaluated' always evaluates to false in a non-'constexpr' 
function" }
+}
+
+void
+bar ()
+{
+  foo  ();
+}


[gcc r12-10533] fold-const: Fix up CLZ handling in tree_call_nonnegative_warnv_p [PR115337]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b065824e30e9168d33b56039e436c4b09078e260

commit r12-10533-gb065824e30e9168d33b56039e436c4b09078e260
Author: Jakub Jelinek 
Date:   Tue Jun 4 15:49:41 2024 +0200

fold-const: Fix up CLZ handling in tree_call_nonnegative_warnv_p [PR115337]

The function currently incorrectly assumes all the __builtin_clz* and .CLZ
calls have non-negative result.  That is the case of the former which is UB
on zero and has [0, prec-1] return value otherwise, and is the case of the
single argument .CLZ as well (again, UB on zero), but for two argument
.CLZ is the case only if the second argument is also nonnegative (or if we
know the argument can't be zero, but let's do that just in the ranger IMHO).

The following patch does that.

2024-06-04  Jakub Jelinek  

PR tree-optimization/115337
* fold-const.cc (tree_call_nonnegative_warnv_p) :
If fn is CFN_CLZ, use CLZ_DEFINED_VALUE_AT.

(cherry picked from commit b82a816000791e7a286c7836b3a473ec0e2a577b)

Diff:
---
 gcc/fold-const.cc | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 70302943cea..d81a71c41a1 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -84,6 +84,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "vec-perm-indices.h"
 #include "asan.h"
 #include "gimple-range.h"
+#include "internal-fn.h"
 
 /* Nonzero if we are folding constants inside an initializer or a C++
manifestly-constant-evaluated context; zero otherwise.
@@ -14861,7 +14862,6 @@ tree_call_nonnegative_warnv_p (tree type, combined_fn 
fn, tree arg0, tree arg1,
 CASE_CFN_FFS:
 CASE_CFN_PARITY:
 CASE_CFN_POPCOUNT:
-CASE_CFN_CLZ:
 CASE_CFN_CLRSB:
 case CFN_BUILT_IN_BSWAP16:
 case CFN_BUILT_IN_BSWAP32:
@@ -14870,6 +14870,22 @@ tree_call_nonnegative_warnv_p (tree type, combined_fn 
fn, tree arg0, tree arg1,
   /* Always true.  */
   return true;
 
+CASE_CFN_CLZ:
+  if (fn != CFN_CLZ)
+   return true;
+  else if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
+   {
+ tree atype = TREE_TYPE (arg0);
+ int val = 0;
+ if (direct_internal_fn_supported_p (IFN_CLZ, atype,
+ OPTIMIZE_FOR_BOTH)
+ && CLZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (atype),
+   val) == 2
+ && val >= 0)
+   return true;
+   }
+  break;
+
 CASE_CFN_SQRT:
 CASE_CFN_SQRT_FN:
   /* sqrt(-0.0) is -0.0.  */


[gcc r12-10524] attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusions [PR114634]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:bb21a7de31183108bdb2489f987deaf94e4985b6

commit r12-10524-gbb21a7de31183108bdb2489f987deaf94e4985b6
Author: Jakub Jelinek 
Date:   Mon Apr 15 10:25:22 2024 +0200

attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusions [PR114634]

The enumerator still doesn't have TREE_TYPE set but diag_attr_exclusions
assumes that all decls must have types.
I think it is better in something as unimportant as diag_attr_exclusions
to be more robust, if there is no type, it can just diagnose exclusions
on the DECL_ATTRIBUTES, like for types it only diagnoses it on
TYPE_ATTRIBUTES.

2024-04-15  Jakub Jelinek  

PR c++/114634
* attribs.cc (diag_attr_exclusions): Set attrs[1] to NULL_TREE for
decls with NULL TREE_TYPE.

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

(cherry picked from commit 7ec54f5fdfec298812a749699874db4d6a7246bb)

Diff:
---
 gcc/attribs.cc  | 7 ++-
 gcc/testsuite/g++.dg/ext/attrib68.C | 8 
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index f73e00b6201..3bf4253ebc4 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -479,7 +479,12 @@ diag_attr_exclusions (tree last_decl, tree node, tree 
attrname,
   if (DECL_P (node))
 {
   attrs[0] = DECL_ATTRIBUTES (node);
-  attrs[1] = TYPE_ATTRIBUTES (TREE_TYPE (node));
+  if (TREE_TYPE (node))
+   attrs[1] = TYPE_ATTRIBUTES (TREE_TYPE (node));
+  else
+   /* TREE_TYPE can be NULL e.g. while processing attributes on
+  enumerators.  */
+   attrs[1] = NULL_TREE;
 }
   else
 {
diff --git a/gcc/testsuite/g++.dg/ext/attrib68.C 
b/gcc/testsuite/g++.dg/ext/attrib68.C
new file mode 100644
index 000..be3b1108491
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attrib68.C
@@ -0,0 +1,8 @@
+// PR c++/114634
+// { dg-do compile }
+
+template 
+struct A
+{
+  enum { e __attribute__ ((aligned (16))) };   // { dg-error "alignment may 
not be specified for 'e'" }
+};


[gcc r12-10528] gimple-ssa-sprintf: Use [0, 1] range for %lc with (wint_t) 0 argument [PR114876]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:bf134407b494bf79f66fc5048ff0ca409275089c

commit r12-10528-gbf134407b494bf79f66fc5048ff0ca409275089c
Author: Jakub Jelinek 
Date:   Tue Apr 30 11:22:32 2024 +0200

gimple-ssa-sprintf: Use [0, 1] range for %lc with (wint_t) 0 argument 
[PR114876]

Seems when Martin S. implemented this, he coded there strict reading
of the standard, which said that %lc with (wint_t) 0 argument is handled
as wchar_t[2] temp = { arg, 0 }; %ls with temp arg and so shouldn't print
any values.  But, most of the libc implementations actually handled that
case like %c with '\0' argument, adding a single NUL character, the only
known exception is musl.
Recently, C23 changed this in response to GB-141 and POSIX in
https://austingroupbugs.net/view.php?id=1647
so that it should have the same behavior as %c with '\0'.

Because there is implementation divergence, the following patch uses
a range rather than hardcoding it to all 1s (i.e. the %c behavior),
though the likely case is still 1 (forward looking plus most of
implementations).
The res.knownrange = true; assignment removed is redundant due to
the same assignment done unconditionally before the if statement,
rest is formatting fixes.

I don't think the min >= 0 && min < 128 case is right either, I'd think
it should be min >= 0 && max < 128, otherwise it is just some possible
inputs are (maybe) ASCII and there can be others, but this code is a total
mess anyway, with the min, max, likely (somewhere in [min, max]?) and then
unlikely possibly larger than max, dunno, perhaps for at least some chars
in the ASCII range the likely case could be for the ascii case; so perhaps
just the one_2_one_ascii shouldn't set max to 1 and mayfail should be true
for max >= 128.  Anyway, didn't feel I should touch that right now.

2024-04-30  Jakub Jelinek  

PR tree-optimization/114876
* gimple-ssa-sprintf.cc (format_character): For min == 0 && max == 
0,
set max, likely and unlikely members to 1 rather than 0.  Remove
useless res.knownrange = true;.  Formatting fixes.

* gcc.dg/pr114876.c: New test.
* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust expected
diagnostics.

(cherry picked from commit 6c6b70f07208ca14ba783933988c04c6fc2fff42)

Diff:
---
 gcc/gimple-ssa-sprintf.cc  | 20 +++--
 gcc/testsuite/gcc.dg/pr114876.c| 34 ++
 .../gcc.dg/tree-ssa/builtin-sprintf-warn-1.c   | 12 
 3 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/gcc/gimple-ssa-sprintf.cc b/gcc/gimple-ssa-sprintf.cc
index c0405ab32db..301078ac95f 100644
--- a/gcc/gimple-ssa-sprintf.cc
+++ b/gcc/gimple-ssa-sprintf.cc
@@ -2166,8 +2166,7 @@ format_character (const directive &dir, tree arg, 
pointer_query &ptr_qry)
 
   res.knownrange = true;
 
-  if (dir.specifier == 'C'
-  || dir.modifier == FMT_LEN_l)
+  if (dir.specifier == 'C' || dir.modifier == FMT_LEN_l)
 {
   /* A wide character can result in as few as zero bytes.  */
   res.range.min = 0;
@@ -2178,10 +2177,13 @@ format_character (const directive &dir, tree arg, 
pointer_query &ptr_qry)
{
  if (min == 0 && max == 0)
{
- /* The NUL wide character results in no bytes.  */
- res.range.max = 0;
- res.range.likely = 0;
- res.range.unlikely = 0;
+ /* In strict reading of older ISO C or POSIX, this required
+no characters to be emitted.  ISO C23 changes that, so
+does POSIX, to match what has been implemented in most of the
+implementations, namely emitting a single NUL character.
+Let's use 0 for minimum and 1 for all the other values.  */
+ res.range.max = 1;
+ res.range.likely = res.range.unlikely = 1;
}
  else if (min >= 0 && min < 128)
{
@@ -2189,11 +2191,12 @@ format_character (const directive &dir, tree arg, 
pointer_query &ptr_qry)
 is not a 1-to-1 mapping to the source character set or
 if the source set is not ASCII.  */
  bool one_2_one_ascii
-   = (target_to_host_charmap[0] == 1 && target_to_host ('a') == 
97);
+   = (target_to_host_charmap[0] == 1
+  && target_to_host ('a') == 97);
 
  /* A wide character in the ASCII range most likely results
 in a single byte, and only unlikely in up to MB_LEN_MAX.  */
- res.range.max = one_2_one_ascii ? 1 : target_mb_len_max ();;
+ res.range.max = one_2_one_ascii ? 1 : target_mb_len_max ();
  res.range.likely = 1;
  res.range.unlikely = target_mb_len_max ();
  res.mayfail = !one_2_one_ascii;
@@ -2224,7 +2227,6 @@ f

[gcc r12-10526] rtlanal: Fix set_noop_p for volatile loads or stores [PR114768]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:7d0673575aba5dfb41022897a882b9c386c332f4

commit r12-10526-g7d0673575aba5dfb41022897a882b9c386c332f4
Author: Jakub Jelinek 
Date:   Fri Apr 19 08:47:53 2024 +0200

rtlanal: Fix set_noop_p for volatile loads or stores [PR114768]

On the following testcase, combine propagates the mem/v load into mem store
with the same address and then removes it, because noop_move_p says it is a
no-op move.  If it was the other way around, i.e. mem/v store and mem load,
or both would be mem/v, it would be kept.
The problem is that rtx_equal_p never checks any kind of flags on the rtxes
(and I think it would be quite dangerous to change it at this point), and
set_noop_p checks side_effects_p on just one of the operands, not both.
In the MEM <- MEM set, it only checks it on the destination, in
store to ZERO_EXTRACT only checks it on the source.

The following patch adds the missing side_effects_p checks.

2024-04-19  Jakub Jelinek  

PR rtl-optimization/114768
* rtlanal.cc (set_noop_p): Don't return true for MEM <- MEM
sets if src has side-effects or for stores into ZERO_EXTRACT
if ZERO_EXTRACT operand has side-effects.

* gcc.dg/pr114768.c: New test.

(cherry picked from commit 9f295847a9c32081bdd0fe908ffba58e830a24fb)

Diff:
---
 gcc/rtlanal.cc  | 11 +++
 gcc/testsuite/gcc.dg/pr114768.c | 10 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index 78a740cb54b..5ba5e4aaaf9 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -1639,12 +1639,15 @@ set_noop_p (const_rtx set)
 return 1;
 
   if (MEM_P (dst) && MEM_P (src))
-return rtx_equal_p (dst, src) && !side_effects_p (dst);
+return (rtx_equal_p (dst, src)
+   && !side_effects_p (dst)
+   && !side_effects_p (src));
 
   if (GET_CODE (dst) == ZERO_EXTRACT)
-return rtx_equal_p (XEXP (dst, 0), src)
-  && !BITS_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx
-  && !side_effects_p (src);
+return (rtx_equal_p (XEXP (dst, 0), src)
+   && !BITS_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx
+   && !side_effects_p (src)
+   && !side_effects_p (XEXP (dst, 0)));
 
   if (GET_CODE (dst) == STRICT_LOW_PART)
 dst = XEXP (dst, 0);
diff --git a/gcc/testsuite/gcc.dg/pr114768.c b/gcc/testsuite/gcc.dg/pr114768.c
new file mode 100644
index 000..ffe3b368638
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114768.c
@@ -0,0 +1,10 @@
+/* PR rtl-optimization/114768 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-final" } */
+/* { dg-final { scan-rtl-dump "\\\(mem/v:" "final" } } */
+
+void
+foo (int *p)
+{
+  *p = *(volatile int *) p;
+}


[gcc r12-10527] openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tree-nested decl copy [PR114825]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cc96dc569f74b7410a97b4beee16435fc2abcfdd

commit r12-10527-gcc96dc569f74b7410a97b4beee16435fc2abcfdd
Author: Jakub Jelinek 
Date:   Thu Apr 25 20:09:35 2024 +0200

openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tree-nested decl 
copy [PR114825]

tree-nested.cc creates in 2 spots artificial VAR_DECLs, one of them is used
both for debug info and OpenMP/OpenACC lowering purposes, the other solely 
for
OpenMP/OpenACC lowering purposes.
When the decls are used in OpenMP/OpenACC lowering, the OMP langhooks 
(mostly
Fortran, C just a little and C++ doesn't have nested functions) then inspect
the flags on the vars and based on that decide how to lower the 
corresponding
clauses.

Unfortunately we weren't copying DECL_LANG_SPECIFIC and DECL_LANG_FLAG_?, so
the langhooks made decisions on the default flags on those instead.
As the original decl isn't necessarily a VAR_DECL, could be e.g. PARM_DECL,
using copy_node wouldn't work properly, so this patch just copies those
flags in addition to other flags it was copying already.  And I've removed
code duplication by introducing a helper function which does copying common
to both uses.

2024-04-25  Jakub Jelinek  

PR fortran/114825
* tree-nested.cc (get_debug_decl): New function.
(get_nonlocal_debug_decl): Use it.
(get_local_debug_decl): Likewise.

* gfortran.dg/gomp/pr114825.f90: New test.

(cherry picked from commit 14d48516e588ad2b35e2007b3970bdcb1b3f145c)

Diff:
---
 gcc/testsuite/gfortran.dg/gomp/pr114825.f90 | 16 
 gcc/tree-nested.cc  | 61 -
 2 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/gomp/pr114825.f90 
b/gcc/testsuite/gfortran.dg/gomp/pr114825.f90
new file mode 100644
index 000..b635476af61
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/pr114825.f90
@@ -0,0 +1,16 @@
+! PR fortran/114825
+
+subroutine pr114825(b)
+  type t
+real, allocatable :: m(:)
+  end type t
+  type(t), allocatable, target :: b(:)
+  type(t), pointer :: d
+  !$omp parallel private(d)
+  d => b(1)
+  !$omp end parallel
+contains
+  subroutine sub
+d => b(1)
+  end subroutine sub
+end subroutine pr114825
diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc
index 3956e495f92..3c2cf46e3f4 100644
--- a/gcc/tree-nested.cc
+++ b/gcc/tree-nested.cc
@@ -1039,6 +1039,37 @@ get_frame_field (struct nesting_info *info, tree 
target_context,
 
 static void note_nonlocal_vla_type (struct nesting_info *info, tree type);
 
+/* Helper for get_nonlocal_debug_decl and get_local_debug_decl.  */
+
+static tree
+get_debug_decl (tree decl)
+{
+  tree new_decl
+= build_decl (DECL_SOURCE_LOCATION (decl),
+ VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
+  DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl);
+  DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl);
+  TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl);
+  TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl);
+  TREE_READONLY (new_decl) = TREE_READONLY (decl);
+  TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl);
+  DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1;
+  if ((TREE_CODE (decl) == PARM_DECL
+   || TREE_CODE (decl) == RESULT_DECL
+   || VAR_P (decl))
+  && DECL_BY_REFERENCE (decl))
+DECL_BY_REFERENCE (new_decl) = 1;
+  /* Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_* for OpenMP langhook
+ purposes.  */
+  DECL_LANG_SPECIFIC (new_decl) = DECL_LANG_SPECIFIC (decl);
+#define COPY_DLF(n) DECL_LANG_FLAG_##n (new_decl) = DECL_LANG_FLAG_##n (decl)
+  COPY_DLF (0); COPY_DLF (1); COPY_DLF (2); COPY_DLF (3);
+  COPY_DLF (4); COPY_DLF (5); COPY_DLF (6); COPY_DLF (7);
+  COPY_DLF (8);
+#undef COPY_DLF
+  return new_decl;
+}
+
 /* A subroutine of convert_nonlocal_reference_op.  Create a local variable
in the nested function with DECL_VALUE_EXPR set to reference the true
variable in the parent function.  This is used both for debug info
@@ -1086,21 +1117,8 @@ get_nonlocal_debug_decl (struct nesting_info *info, tree 
decl)
 x = build_simple_mem_ref_notrap (x);
 
   /* ??? We should be remapping types as well, surely.  */
-  new_decl = build_decl (DECL_SOURCE_LOCATION (decl),
-VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
+  new_decl = get_debug_decl (decl);
   DECL_CONTEXT (new_decl) = info->context;
-  DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl);
-  DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl);
-  TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl);
-  TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl);
-  TREE_READONLY (new_decl) = TREE_READONLY (decl);
-  TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl);
-  DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1;
-  if ((TREE_CODE (decl) == PARM_DECL
-   || TREE_CODE (decl) == RESULT_DECL
-   || VAR_P (

[gcc r12-10529] tree-inline: Remove .ASAN_MARK calls when inlining functions into no_sanitize callers [PR114956]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:25bd98dfd99e92c57ff393d393f54d028d7f86f4

commit r12-10529-g25bd98dfd99e92c57ff393d393f54d028d7f86f4
Author: Jakub Jelinek 
Date:   Tue May 7 21:29:14 2024 +0200

tree-inline: Remove .ASAN_MARK calls when inlining functions into 
no_sanitize callers [PR114956]

In r9-5742 we've started allowing to inline always_inline functions into
functions which have disabled e.g. address sanitization even when the
always_inline function is implicitly from command line options sanitized.

This mostly works fine because most of the asan instrumentation is done only
late after ipa, but as the following testcase the .ASAN_MARK ifn calls
gimplifier adds can result in ICEs.

Fixed by dropping those during inlining, similarly to how we drop
.TSAN_FUNC_EXIT calls.

2024-05-07  Jakub Jelinek  

PR sanitizer/114956
* tree-inline.cc: Include asan.h.
(copy_bb): Remove also .ASAN_MARK calls if id->dst_fn has 
asan/hwasan
sanitization disabled.

* gcc.dg/asan/pr114956.c: New test.

(cherry picked from commit d4e25cf4f7c1f51a8824cc62bbb85a81a41b829a)

Diff:
---
 gcc/testsuite/gcc.dg/asan/pr114956.c | 26 ++
 gcc/tree-inline.cc   | 28 +---
 2 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/asan/pr114956.c 
b/gcc/testsuite/gcc.dg/asan/pr114956.c
new file mode 100644
index 000..fb87d514f25
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/pr114956.c
@@ -0,0 +1,26 @@
+/* PR sanitizer/114956 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsanitize=address,null" } */
+
+int **a;
+void qux (int *);
+
+__attribute__((always_inline)) static inline int *
+foo (void)
+{
+  int b[1];
+  qux (b);
+  return a[1];
+}
+
+__attribute__((no_sanitize_address)) void
+bar (void)
+{
+  *a = foo ();
+}
+
+void
+baz (void)
+{
+  bar ();
+}
diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index 8f5a44ee6f5..a49724f3ff2 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -65,6 +65,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "symbol-summary.h"
 #include "symtab-thunks.h"
 #include "symtab-clones.h"
+#include "asan.h"
 
 /* I'm not real happy about this, but we need to handle gimple and
non-gimple trees.  */
@@ -2210,13 +2211,26 @@ copy_bb (copy_body_data *id, basic_block bb,
}
  else if (call_stmt
   && id->call_stmt
-  && gimple_call_internal_p (stmt)
-  && gimple_call_internal_fn (stmt) == IFN_TSAN_FUNC_EXIT)
-   {
- /* Drop TSAN_FUNC_EXIT () internal calls during inlining.  */
- gsi_remove (©_gsi, false);
- continue;
-   }
+  && gimple_call_internal_p (stmt))
+   switch (gimple_call_internal_fn (stmt))
+ {
+ case IFN_TSAN_FUNC_EXIT:
+   /* Drop .TSAN_FUNC_EXIT () internal calls during inlining.  */
+   gsi_remove (©_gsi, false);
+   continue;
+ case IFN_ASAN_MARK:
+   /* Drop .ASAN_MARK internal calls during inlining into
+  no_sanitize functions.  */
+   if (!sanitize_flags_p (SANITIZE_ADDRESS, id->dst_fn)
+   && !sanitize_flags_p (SANITIZE_HWADDRESS, id->dst_fn))
+ {
+   gsi_remove (©_gsi, false);
+   continue;
+ }
+   break;
+ default:
+   break;
+ }
 
  /* Statements produced by inlining can be unfolded, especially
 when we constant propagated some operands.  We can't fold


[gcc r12-10532] builtins: Force SAVE_EXPR for __builtin_{add, sub, mul}_overflow [PR108789]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:91a371254494934e191e3060ae2a86905eb4b2b2

commit r12-10532-g91a371254494934e191e3060ae2a86905eb4b2b2
Author: Jakub Jelinek 
Date:   Tue Jun 4 12:28:01 2024 +0200

builtins: Force SAVE_EXPR for __builtin_{add,sub,mul}_overflow [PR108789]

The following testcase is miscompiled, because we use save_expr
on the .{ADD,SUB,MUL}_OVERFLOW call we are creating, but if the first
two operands are not INTEGER_CSTs (in that case we just fold it right away)
but are TREE_READONLY/!TREE_SIDE_EFFECTS, save_expr doesn't actually
create a SAVE_EXPR at all and so we lower it to
*arg2 = REALPART_EXPR (.ADD_OVERFLOW (arg0, arg1)), \
IMAGPART_EXPR (.ADD_OVERFLOW (arg0, arg1))
which evaluates the ifn twice and just hope it will be CSEd back.
As *arg2 aliases *arg0, that is not the case.
The builtins are really never const/pure as they store into what
the third arguments points to, so after handling the INTEGER_CST+INTEGER_CST
case, I think we should just always use SAVE_EXPR.  Just building SAVE_EXPR
by hand and setting TREE_SIDE_EFFECTS on it doesn't work, because
c_fully_fold optimizes it away again, so the following patch marks the
ifn calls as TREE_SIDE_EFFECTS (but doesn't do it for the
__builtin_{add,sub,mul}_overflow_p case which were designed for use
especially in constant expressions and don't really evaluate the
realpart side, so we don't really need a SAVE_EXPR in that case).

2024-06-04  Jakub Jelinek  

PR middle-end/108789
* builtins.cc (fold_builtin_arith_overflow): For ovf_only,
don't call save_expr and don't build REALPART_EXPR, otherwise
set TREE_SIDE_EFFECTS on call before calling save_expr.

* gcc.c-torture/execute/pr108789.c: New test.

(cherry picked from commit b8e28381cb5c0cddfe5201faf799d8b27f5d7d6c)

Diff:
---
 gcc/builtins.cc| 16 ++-
 gcc/testsuite/gcc.c-torture/execute/pr108789.c | 39 ++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 57929a42bc4..f91947020b6 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -9180,7 +9180,21 @@ fold_builtin_arith_overflow (location_t loc, enum 
built_in_function fcode,
   tree ctype = build_complex_type (type);
   tree call = build_call_expr_internal_loc (loc, ifn, ctype, 2,
arg0, arg1);
-  tree tgt = save_expr (call);
+  tree tgt;
+  if (ovf_only)
+   {
+ tgt = call;
+ intres = NULL_TREE;
+   }
+  else
+   {
+ /* Force SAVE_EXPR even for calls which satisfy tree_invariant_p_1,
+as while the call itself is const, the REALPART_EXPR store is
+certainly not.  And in any case, we want just one call,
+not multiple and trying to CSE them later.  */
+ TREE_SIDE_EFFECTS (call) = 1;
+ tgt = save_expr (call);
+   }
   intres = build1_loc (loc, REALPART_EXPR, type, tgt);
   ovfres = build1_loc (loc, IMAGPART_EXPR, type, tgt);
   ovfres = fold_convert_loc (loc, boolean_type_node, ovfres);
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr108789.c 
b/gcc/testsuite/gcc.c-torture/execute/pr108789.c
new file mode 100644
index 000..32ee19be1c4
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr108789.c
@@ -0,0 +1,39 @@
+/* PR middle-end/108789 */
+
+int
+add (unsigned *r, const unsigned *a, const unsigned *b)
+{
+  return __builtin_add_overflow (*a, *b, r);
+}
+
+int
+mul (unsigned *r, const unsigned *a, const unsigned *b)
+{
+  return __builtin_mul_overflow (*a, *b, r);
+}
+
+int
+main ()
+{
+  unsigned x;
+
+  /* 1073741824U + 1073741824U should not overflow.  */
+  x = (__INT_MAX__ + 1U) / 2;
+  if (add (&x, &x, &x))
+__builtin_abort ();
+
+  /* 256U * 256U should not overflow */
+  x = 1U << (sizeof (int) * __CHAR_BIT__ / 4);
+  if (mul (&x, &x, &x))
+__builtin_abort ();
+
+  /* 2147483648U + 2147483648U should overflow */
+  x = __INT_MAX__ + 1U;
+  if (!add (&x, &x, &x))
+__builtin_abort ();
+
+  /* 65536U * 65536U should overflow */
+  x = 1U << (sizeof (int) * __CHAR_BIT__ / 2);
+  if (!mul (&x, &x, &x))
+__builtin_abort ();
+}


[gcc r12-10530] combine: Fix up simplify_compare_const [PR115092]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:840bc6741680a9c4b58fa1005f19a5d2e7d4be1f

commit r12-10530-g840bc6741680a9c4b58fa1005f19a5d2e7d4be1f
Author: Jakub Jelinek 
Date:   Wed May 15 18:37:17 2024 +0200

combine: Fix up simplify_compare_const [PR115092]

The following testcases are miscompiled (with tons of GIMPLE
optimization disabled) because combine sees GE comparison of
1-bit sign_extract (i.e. something with [-1, 0] value range)
with (const_int -1) (which is always true) and optimizes it into
NE comparison of 1-bit zero_extract ([0, 1] value range) against
(const_int 0).
The reason is that simplify_compare_const first (correctly)
simplifies the comparison to
GE (ashift:SI something (const_int 31)) (const_int -2147483648)
and then an optimization for when the second operand is power of 2
triggers.  That optimization is fine for power of 2s which aren't
the signed minimum of the mode, or if it is NE, EQ, GEU or LTU
against the signed minimum of the mode, but for GE or LT optimizing
it into NE (or EQ) against const0_rtx is wrong, those cases
are always true or always false (but the function doesn't have
a standardized way to tell callers the comparison is now unconditional).

The following patch just disables the optimization in that case.

2024-05-15  Jakub Jelinek  

PR rtl-optimization/114902
PR rtl-optimization/115092
* combine.cc (simplify_compare_const): Don't optimize
GE op0 SIGNED_MIN or LT op0 SIGNED_MIN into NE op0 const0_rtx or
EQ op0 const0_rtx.

* gcc.dg/pr114902.c: New test.
* gcc.dg/pr115092.c: New test.

(cherry picked from commit 0b93a0ae153ef70a82ff63e67926a01fdab9956b)

Diff:
---
 gcc/combine.cc  |  6 --
 gcc/testsuite/gcc.dg/pr114902.c | 23 +++
 gcc/testsuite/gcc.dg/pr115092.c | 16 
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 9a34ef847aa..e79500d40c9 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -11789,8 +11789,10 @@ simplify_compare_const (enum rtx_code code, 
machine_mode mode,
  `and'ed with that bit), we can replace this with a comparison
  with zero.  */
   if (const_op
-  && (code == EQ || code == NE || code == GE || code == GEU
- || code == LT || code == LTU)
+  && (code == EQ || code == NE || code == GEU || code == LTU
+ /* This optimization is incorrect for signed >= INT_MIN or
+< INT_MIN, those are always true or always false.  */
+ || ((code == GE || code == LT) && const_op > 0))
   && is_a  (mode, &int_mode)
   && GET_MODE_PRECISION (int_mode) - 1 < HOST_BITS_PER_WIDE_INT
   && pow2p_hwi (const_op & GET_MODE_MASK (int_mode))
diff --git a/gcc/testsuite/gcc.dg/pr114902.c b/gcc/testsuite/gcc.dg/pr114902.c
new file mode 100644
index 000..60684faa25d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114902.c
@@ -0,0 +1,23 @@
+/* PR rtl-optimization/114902 */
+/* { dg-do run } */
+/* { dg-options "-O1 -fno-tree-fre -fno-tree-forwprop -fno-tree-ccp 
-fno-tree-dominator-opts" } */
+
+__attribute__((noipa))
+int foo (int x)
+{
+  int a = ~x;
+  int t = a & 1;
+  int e = -t;
+  int b = e >= -1;
+  if (b)
+return 0;
+  __builtin_trap ();
+}
+
+int
+main ()
+{
+  foo (-1);
+  foo (0);
+  foo (1);
+}
diff --git a/gcc/testsuite/gcc.dg/pr115092.c b/gcc/testsuite/gcc.dg/pr115092.c
new file mode 100644
index 000..c9047f4d321
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr115092.c
@@ -0,0 +1,16 @@
+/* PR rtl-optimization/115092 */
+/* { dg-do run } */
+/* { dg-options "-O1 -fgcse -ftree-pre -fno-tree-dominator-opts -fno-tree-fre 
-fno-guess-branch-probability" } */
+
+int a, b, c = 1, d, e;
+
+int
+main ()
+{
+  int f, g = a;
+  b = -2;
+  f = -(1 >> ((c && b) & ~a));
+  if (f <= b)
+d = g / e;
+  return 0;
+}


[gcc r12-10531] rs6000: Fix up PCH in --enable-host-pie builds [PR115324]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:bda8c28e6fcdbe0b486b54616877eec32c86d322

commit r12-10531-gbda8c28e6fcdbe0b486b54616877eec32c86d322
Author: Jakub Jelinek 
Date:   Mon Jun 3 23:11:06 2024 +0200

rs6000: Fix up PCH in --enable-host-pie builds [PR115324]

PCH doesn't work properly in --enable-host-pie configurations on
powerpc*-linux*.
The problem is that the rs6000_builtin_info and rs6000_instance_info
arrays mix pointers to .rodata/.data (bifname and attr_string point
to string literals in .rodata section, and the next member is either NULL
or &rs6000_instance_info[XXX]) and GC member (tree fntype).
Now, for normal GC this works just fine, we emit
  {
&rs6000_instance_info[0].fntype,
1 * (RS6000_INST_MAX),
sizeof (rs6000_instance_info[0]),
>_ggc_mx_tree_node,
>_pch_nx_tree_node
  },
  {
&rs6000_builtin_info[0].fntype,
1 * (RS6000_BIF_MAX),
sizeof (rs6000_builtin_info[0]),
>_ggc_mx_tree_node,
>_pch_nx_tree_node
  },
GC roots which are strided and thus cover only the fntype members of all
the elements of the two arrays.
For PCH though it actually results in saving those huge arrays (one is
130832 bytes, another 81568 bytes) into the .gch files and loading them back
in full.  While the bifname and attr_string and next pointers are marked as
GTY((skip)), they are actually saved to point to the .rodata and .data
sections of the process which writes the PCH, but because cc1/cc1plus etc.
are position independent executables with --enable-host-pie, when it is
loaded from the PCH file, it can point in a completely different addresses
where nothing is mapped at all or some random different thing appears at.
While gengtype supports the callback option, that one is meant for
relocatable function pointers and doesn't work in the case of GTY arrays
inside of .data section anyway.

So, either we'd need to add some further GTY extensions, or the following
patch instead reworks it such that the fntype members which were the only
reason for PCH in those arrays are moved to separate arrays.

Size-wise in .data sections it is (in bytes):

 vanillapatched
rs6000_builtin_info  130832 110704
rs6000_instance_info  81568  40784
rs6000_overload_info   7392   7392
rs6000_builtin_info_fntype0  10064
rs6000_instance_info_fntype   0  20392
sum  219792 189336

where previously we saved/restored for PCH those 130832+81568 bytes, now we
save/restore just 10064+20392 bytes, so this change is beneficial for the
data section size.

Unfortunately, it grows the size of the rs6000_init_generated_builtins
function, vanilla had 218328 bytes, patched has 228668.

When I applied
 void
 rs6000_init_generated_builtins ()
 {
+  bifdata *rs6000_builtin_info_p;
+  tree *rs6000_builtin_info_fntype_p;
+  ovlddata *rs6000_instance_info_p;
+  tree *rs6000_instance_info_fntype_p;
+  ovldrecord *rs6000_overload_info_p;
+  __asm ("" : "=r" (rs6000_builtin_info_p) : "0" (rs6000_builtin_info));
+  __asm ("" : "=r" (rs6000_builtin_info_fntype_p) : "0" 
(rs6000_builtin_info_fntype));
+  __asm ("" : "=r" (rs6000_instance_info_p) : "0" (rs6000_instance_info));
+  __asm ("" : "=r" (rs6000_instance_info_fntype_p) : "0" 
(rs6000_instance_info_fntype));
+  __asm ("" : "=r" (rs6000_overload_info_p) : "0" (rs6000_overload_info));
+  #define rs6000_builtin_info rs6000_builtin_info_p
+  #define rs6000_builtin_info_fntype rs6000_builtin_info_fntype_p
+  #define rs6000_instance_info rs6000_instance_info_p
+  #define rs6000_instance_info_fntype rs6000_instance_info_fntype_p
+  #define rs6000_overload_info rs6000_overload_info_p
+
hack by hand, the size of the function is 209700 though, so if really
wanted, we could add __attribute__((__noipa__)) to the function when
building with recent enough GCC and pass pointers to the first elements
of the 5 arrays to the function as arguments.  If you want such a change,
could that be done incrementally?

2024-06-03  Jakub Jelinek  

PR target/115324
* config/rs6000/rs6000-gen-builtins.cc (write_decls): Remove
GTY markup from struct bifdata and struct ovlddata and remove their
fntype members.  Change next member in struct ovlddata and
first_instance member of struct ovldrecord to have int type rather
than struct ovlddata *.  Remove GTY markup from rs6000_builtin_info
and rs6000_instance_info arrays, declare new
rs6000_builtin_info_fntype and rs6000_instance_info_fntype arrays,
which have GTY markup.
(write_bif_static_init): Adjust for the a

[gcc r12-10534] c: Fix up pointer types to may_alias structures [PR114493]

2024-06-11 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d4126b329b2ae4f2b60efa1c7ad51b576de168bd

commit r12-10534-gd4126b329b2ae4f2b60efa1c7ad51b576de168bd
Author: Jakub Jelinek 
Date:   Thu Jun 6 22:12:11 2024 +0200

c: Fix up pointer types to may_alias structures [PR114493]

The following testcase ICEs in ipa-free-lang, because the
fld_incomplete_type_of
  gcc_assert (TYPE_CANONICAL (t2) != t2
  && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE 
(t)));
assertion doesn't hold.
This is because t is a struct S * type which was created while struct S
was still incomplete and without the may_alias attribute (and TYPE_CANONICAL
of a pointer type is a type created with can_alias_all = false argument),
while later on on the struct definition may_alias attribute was used.
fld_incomplete_type_of then creates an incomplete distinct copy of the
structure (but with the original attributes) but pointers created for it
are because of the "may_alias" attribute TYPE_REF_CAN_ALIAS_ALL, including
their TYPE_CANONICAL, because while that is created with !can_alias_all
argument, we later set it because of the "may_alias" attribute on the
to_type.

This doesn't ICE with C++ since PR70512 fix because the C++ FE sets
TYPE_REF_CAN_ALIAS_ALL on all pointer types to the class type (and its
variants) when the may_alias is added.

The following patch does that in the C FE as well.

2024-06-06  Jakub Jelinek  

PR c/114493
* c-decl.cc (c_fixup_may_alias): New function.
(finish_struct): Call it if "may_alias" attribute is
specified.

* gcc.dg/pr114493-1.c: New test.
* gcc.dg/pr114493-2.c: New test.

(cherry picked from commit d5a3c6d43acb8b2211d9fb59d59482d74c010f01)

Diff:
---
 gcc/c/c-decl.cc   | 15 +++
 gcc/testsuite/gcc.dg/pr114493-1.c | 19 +++
 gcc/testsuite/gcc.dg/pr114493-2.c | 26 ++
 3 files changed, 60 insertions(+)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 619a2090937..668e234f019 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -8699,6 +8699,17 @@ finish_incomplete_vars (tree incomplete_vars, bool 
toplevel)
 }
 }
 
+/* TYPE is a struct or union that we're applying may_alias to after the body is
+   parsed.  Fixup any POINTER_TO types.  */
+
+static void
+c_fixup_may_alias (tree type)
+{
+  for (tree t = TYPE_POINTER_TO (type); t; t = TYPE_NEXT_PTR_TO (t))
+for (tree v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
+  TYPE_REF_CAN_ALIAS_ALL (v) = true;
+}
+
 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
FIELDLIST is a chain of FIELD_DECL nodes for the fields.
@@ -8973,6 +8984,10 @@ finish_struct (location_t loc, tree t, tree fieldlist, 
tree attributes,
   warning_at (loc, 0, "union cannot be made transparent");
 }
 
+  if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
+for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
+  c_fixup_may_alias (x);
+
   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
 {
diff --git a/gcc/testsuite/gcc.dg/pr114493-1.c 
b/gcc/testsuite/gcc.dg/pr114493-1.c
new file mode 100644
index 000..446f33eac3b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114493-1.c
@@ -0,0 +1,19 @@
+/* PR c/114493 */
+/* { dg-do compile { target lto } } */
+/* { dg-options "-O2 -flto" } */
+
+void foo (void);
+struct S;
+struct S bar (struct S **);
+struct S qux (const struct S **);
+
+struct __attribute__((__may_alias__)) S {
+  int s;
+};
+
+struct S
+baz (void)
+{
+  foo ();
+  return (struct S) {};
+}
diff --git a/gcc/testsuite/gcc.dg/pr114493-2.c 
b/gcc/testsuite/gcc.dg/pr114493-2.c
new file mode 100644
index 000..93e3d6e5bc4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114493-2.c
@@ -0,0 +1,26 @@
+/* PR c/114493 */
+/* { dg-do compile { target lto } } */
+/* { dg-options "-O2 -flto -std=c2x" } */
+
+void foo (void);
+struct S;
+struct S bar (struct S **);
+struct S qux (const struct S **);
+
+void
+corge (void)
+{
+  struct S { int s; } s;
+  s.s = 0;
+}
+
+struct __attribute__((__may_alias__)) S {
+  int s;
+};
+
+struct S
+baz (void)
+{
+  foo ();
+  return (struct S) {};
+}


[gcc r15-1178] libstdc++: Add test for chrono::leap_seconds ostream insertion

2024-06-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:84c87d1f43091c2e537182d029db9739de518096

commit r15-1178-g84c87d1f43091c2e537182d029db9739de518096
Author: Jonathan Wakely 
Date:   Mon Jun 10 21:10:29 2024 +0100

libstdc++: Add test for chrono::leap_seconds ostream insertion

Also add a comment to the three-way comparison oeprator for
chrono::leap_seconds, noting the deviation from the spec (which is
functionally equivalent). What we implement is the originally proposed
resolution to LWG 3383, which should compile slightly more efficiently
than the final accepted resolution.

libstdc++-v3/ChangeLog:

* include/std/chrono (leap_seconds): Add comment.
* testsuite/std/time/leap_seconds/io.cc: New test.

Diff:
---
 libstdc++-v3/include/std/chrono|  2 +
 libstdc++-v3/testsuite/std/time/leap_seconds/io.cc | 56 ++
 2 files changed, 58 insertions(+)

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index b0aadf83b03..7ffa5360728 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -2925,6 +2925,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   const leap_second& __y) noexcept
{ return !(__x < __y.date()); }
 
+  // This is a simplified form of the constraint specified in the standard,
+  // three_way_comparable_with>.
   template _Duration>
[[nodiscard]] friend constexpr auto
operator<=>(const leap_second& __x,
diff --git a/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc 
b/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc
new file mode 100644
index 000..511fafdd1a0
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc
@@ -0,0 +1,56 @@
+// { dg-do run { target c++20 } }
+// { dg-require-effective-target tzdb }
+// { dg-require-effective-target cxx11_abi }
+
+#include 
+#include 
+#include 
+#include 
+
+void
+test_output()
+{
+  using namespace std::chrono;
+
+  std::ostringstream out;
+  out << '\n';
+
+  for (auto& l : get_tzdb().leap_seconds)
+  if (l <= sys_days{2018y/March/17d})
+out << l.date() << ": " << l.value() << '\n';
+
+  VERIFY( out.str() == R"(
+1972-07-01 00:00:00: 1s
+1973-01-01 00:00:00: 1s
+1974-01-01 00:00:00: 1s
+1975-01-01 00:00:00: 1s
+1976-01-01 00:00:00: 1s
+1977-01-01 00:00:00: 1s
+1978-01-01 00:00:00: 1s
+1979-01-01 00:00:00: 1s
+1980-01-01 00:00:00: 1s
+1981-07-01 00:00:00: 1s
+1982-07-01 00:00:00: 1s
+1983-07-01 00:00:00: 1s
+1985-07-01 00:00:00: 1s
+1988-01-01 00:00:00: 1s
+1990-01-01 00:00:00: 1s
+1991-01-01 00:00:00: 1s
+1992-07-01 00:00:00: 1s
+1993-07-01 00:00:00: 1s
+1994-07-01 00:00:00: 1s
+1996-01-01 00:00:00: 1s
+1997-07-01 00:00:00: 1s
+1999-01-01 00:00:00: 1s
+2006-01-01 00:00:00: 1s
+2009-01-01 00:00:00: 1s
+2012-07-01 00:00:00: 1s
+2015-07-01 00:00:00: 1s
+2017-01-01 00:00:00: 1s
+)" );
+}
+
+int main()
+{
+  test_output();
+}


[gcc r15-1179] scev query mismatch message

2024-06-11 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:2f0c09c00b8ccf41c27d4b7ba0cafdeb99242a29

commit r15-1179-g2f0c09c00b8ccf41c27d4b7ba0cafdeb99242a29
Author: Andrew MacLeod 
Date:   Thu May 30 09:40:46 2024 -0400

scev query mismatch message

Add a message to the listing if SCEV is not invoked because of a
range_query mismatch

* gimple-range-fold.cc (range_of_ssa_name_with_loop_info): Issue a
message if SCEV is not invoked due to a mismatch.

Diff:
---
 gcc/gimple-range-fold.cc | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 98a4877ba18..6037c29ce11 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -1267,9 +1267,18 @@ fold_using_range::range_of_ssa_name_with_loop_info 
(vrange &r, tree name,
   // SCEV currently invokes get_range_query () for values.  If the query
   // being passed in is not the same SCEV will use, do not invoke SCEV.
   // This can be remove if/when SCEV uses a passed in range-query.
-  if (src.query () != get_range_query (cfun)
-  || !range_of_var_in_loop (r, name, l, phi, src.query ()))
-r.set_varying (TREE_TYPE (name));
+  if (src.query () != get_range_query (cfun))
+{
+  r.set_varying (TREE_TYPE (name));
+  // Report the msmatch if SRC is not the global query.  The cache
+  // uses a global query and would provide numerous false positives.
+  if (dump_file && (dump_flags & TDF_DETAILS)
+ && src.query () != get_global_range_query ())
+   fprintf (dump_file,
+ "fold_using-range:: SCEV not invoked due to mismatched queries\n");
+}
+  else if (!range_of_var_in_loop (r, name, l, phi, src.query ()))
+  r.set_varying (TREE_TYPE (name));
 }
 
 // ---


[gcc r15-1180] Factor out static_assert constexpr string extraction for reuse

2024-06-11 Thread Andi Kleen via Gcc-cvs
https://gcc.gnu.org/g:6ef8c905e0064c4dfb7ca302355fc20cb96b147b

commit r15-1180-g6ef8c905e0064c4dfb7ca302355fc20cb96b147b
Author: Andi Kleen 
Date:   Sun May 5 22:40:20 2024 -0700

Factor out static_assert constexpr string extraction for reuse

The only semantics changes are slightly more vague error messages
to generalize.

gcc/cp/ChangeLog:

* cp-tree.h (class cexpr_str): Add.
* semantics.cc (finish_static_assert): Convert to use cexpr_str.
(cexpr_str::type_check): Extract constexpr string code to here.
(cexpr_str::extract): ... and here.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/static_assert1.C: Update to new error message.
* g++.dg/cpp0x/udlit-error1.C: Dito.

Diff:
---
 gcc/cp/cp-tree.h|  18 ++
 gcc/cp/semantics.cc | 256 +++-
 gcc/testsuite/g++.dg/cpp0x/udlit-error1.C   |   2 +-
 gcc/testsuite/g++.dg/cpp26/static_assert1.C |  32 ++--
 4 files changed, 176 insertions(+), 132 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 1ac31d073d18..62718ff126a2 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -9015,6 +9015,24 @@ struct push_access_scope_guard
   }
 };
 
+/* Extracting strings from constexpr.  */
+
+class cexpr_str
+{
+public:
+  cexpr_str (tree message) : message (message) {}
+  cexpr_str (const cexpr_str &) = delete;
+  ~cexpr_str () { XDELETEVEC (buf); }
+
+  bool type_check (location_t location);
+  bool extract (location_t location, const char * & msg, int &len);
+  tree message;
+private:
+  tree message_data = NULL_TREE;
+  tree message_sz = NULL_TREE;
+  char *buf = nullptr;
+};
+
 /* True if TYPE is an extended floating-point type.  */
 
 inline bool
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 44cc4289f39c..20f4675833e2 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11667,28 +11667,18 @@ init_cp_semantics (void)
 }
 
 
-/* Build a STATIC_ASSERT for a static assertion with the condition
-   CONDITION and the message text MESSAGE.  LOCATION is the location
-   of the static assertion in the source code.  When MEMBER_P, this
-   static assertion is a member of a class.  If SHOW_EXPR_P is true,
-   print the condition (because it was instantiation-dependent).  */
+/* Get constant string at LOCATION. Returns true if successful,
+   otherwise false.  */
 
-void
-finish_static_assert (tree condition, tree message, location_t location,
- bool member_p, bool show_expr_p)
+bool
+cexpr_str::type_check (location_t location)
 {
   tsubst_flags_t complain = tf_warning_or_error;
-  tree message_sz = NULL_TREE, message_data = NULL_TREE;
 
   if (message == NULL_TREE
   || message == error_mark_node
-  || condition == NULL_TREE
-  || condition == error_mark_node)
-return;
-
-  if (check_for_bare_parameter_packs (condition)
   || check_for_bare_parameter_packs (message))
-return;
+return false;
 
   if (TREE_CODE (message) != STRING_CST
   && !type_dependent_expression_p (message))
@@ -11704,10 +11694,10 @@ finish_static_assert (tree condition, tree message, 
location_t location,
 false, complain);
   if (message_sz == error_mark_node || message_data == error_mark_node)
{
- error_at (location, "% message must be a string "
- "literal or object with % and "
- "% members");
- return;
+ error_at (location, "constexpr string must be a string "
+   "literal or object with % and "
+   "% members");
+ return false;
}
   releasing_vec size_args, data_args;
   message_sz = finish_call_expr (message_sz, &size_args, false, false,
@@ -11715,26 +11705,144 @@ finish_static_assert (tree condition, tree message, 
location_t location,
   message_data = finish_call_expr (message_data, &data_args, false, false,
   complain);
   if (message_sz == error_mark_node || message_data == error_mark_node)
-   return;
+   return false;
   message_sz = build_converted_constant_expr (size_type_node, message_sz,
- complain);
+  complain);
   if (message_sz == error_mark_node)
{
- error_at (location, "% message % "
- "must be implicitly convertible to "
- "%");
- return;
+ error_at (location, "constexpr string % "
+   "must be implicitly convertible to "
+   "%");
+ return false;
}
   message_data = build_converted_constant_expr (const_string_type_node,
-   message_data, complain);
+   

[gcc r15-1181] C++: Support constexpr strings for asm statements

2024-06-11 Thread Andi Kleen via Gcc-cvs
https://gcc.gnu.org/g:53ac88cedf9348b0139fa92c3257b877694f6194

commit r15-1181-g53ac88cedf9348b0139fa92c3257b877694f6194
Author: Andi Kleen 
Date:   Wed Jan 24 04:27:13 2024 -0800

C++: Support constexpr strings for asm statements

Some programing styles use a lot of inline assembler, and it is common
to use very complex preprocessor macros to generate the assembler
strings for the asm statements. In C++ there would be a typesafe alternative
using templates and constexpr to generate the assembler strings, but
unfortunately the asm statement requires plain string literals, so this
doesn't work.

This patch modifies the C++ parser to accept strings generated by
constexpr instead of just plain strings. This requires new syntax
because e.g. asm("..." : "r" (expr)) would be ambigious with a function
call. I chose () to make it unique. For example now you can write

constexpr const char *genasm() { return "insn"; }
constexpr const char *genconstraint() { return "r"; }

asm(genasm() :: (genconstraint()) (input));

The constexpr strings are allowed for the asm template, the
constraints and the clobbers (every time current asm accepts a string)

This version allows the same constexprs as C++26 static_assert,
following Jakub's suggestion.

The drawback of this scheme is that the constexpr doesn't have
full control over the input/output/clobber lists, but that can be
usually handled with a switch statement.  One could imagine
more flexible ways to handle that, for example supporting constexpr
vectors for the clobber list, or similar. But even without
that it is already useful.

Bootstrapped and full test on x86_64-linux.

gcc/c-family/ChangeLog:

* c-cppbuiltin.cc (c_cpp_builtins): Define __GXX_CONSTEXPR_ASM__

gcc/cp/ChangeLog:

* parser.cc (cp_parser_asm_string_expression): New function
to handle constexpr strings for asm.
(cp_parser_asm_definition): Use cp_parser_asm_string_expression.
(cp_parser_yield_expression): Dito.
(cp_parser_asm_specification_opt): Dito.
(cp_parser_asm_operand_list): Dito.
(cp_parser_asm_clobber_list): Dito.

gcc/ChangeLog:

* doc/extend.texi: Document constexpr asm.

gcc/testsuite/ChangeLog:

* g++.dg/ext/asm11.C: Adjust to new error message.
* g++.dg/ext/asm9.C: Dito.
* g++.dg/parse/asm1.C: Dito.
* g++.dg/parse/asm2.C: Dito.
* g++.dg/parse/asm3.C: Dito.
* g++.dg/cpp1z/constexpr-asm-1.C: New test.
* g++.dg/cpp1z/constexpr-asm-2.C: New test.
* g++.dg/cpp1z/constexpr-asm-3.C: New test.

Diff:
---
 gcc/c-family/c-cppbuiltin.cc |  5 +-
 gcc/cp/parser.cc | 85 
 gcc/doc/extend.texi  | 35 ++--
 gcc/testsuite/g++.dg/cpp1z/constexpr-asm-1.C | 30 ++
 gcc/testsuite/g++.dg/cpp1z/constexpr-asm-2.C | 21 +++
 gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C | 31 ++
 gcc/testsuite/g++.dg/ext/asm11.C | 22 +++
 gcc/testsuite/g++.dg/ext/asm9.C  |  3 +-
 gcc/testsuite/g++.dg/parse/asm1.C|  1 +
 gcc/testsuite/g++.dg/parse/asm2.C|  1 +
 gcc/testsuite/g++.dg/parse/asm3.C|  1 +
 11 files changed, 193 insertions(+), 42 deletions(-)

diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index d9b84a0f1b97..dfd8f6f0c485 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -954,7 +954,10 @@ c_cpp_builtins (cpp_reader *pfile)
}
 
   if (cxx_dialect >= cxx11)
-cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
+   {
+ cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
+ cpp_define (pfile, "__GXX_CONSTEXPR_ASM__");
+   }
 
   /* Binary literals have been allowed in g++ before C++11
 and were standardized for C++14.  */
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 9f43a7768891..6cd7274046da 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -22833,6 +22833,52 @@ cp_parser_using_directive (cp_parser* parser)
   cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
 }
 
+/* Parse a string literal or constant expression yielding a string.
+   The constant expression uses extra parens to avoid ambiguity with "x" 
(expr).
+
+   asm-string-expr:
+ string-literal
+ ( constant-expr ) */
+
+static tree
+cp_parser_asm_string_expression (cp_parser *parser)
+{
+  cp_token *tok = cp_lexer_peek_token (parser->lexer);
+
+  if (tok->type == CPP_OPEN_PAREN)
+{
+  matching_parens parens;
+  parens.consume_open (parser);
+  tree string = cp_parser_constant_expression (parser);
+  if (string != error_mark_node)
+   string = cxx

[gcc r15-1182] aarch64: Add vector floating point trunc pattern

2024-06-11 Thread Pengxuan Zheng via Gcc-cvs
https://gcc.gnu.org/g:e7cd8ea1fa3e48404954bb7c06e9bcd603f132dd

commit r15-1182-ge7cd8ea1fa3e48404954bb7c06e9bcd603f132dd
Author: Pengxuan Zheng 
Date:   Fri Jun 7 19:52:00 2024 -0700

aarch64: Add vector floating point trunc pattern

This patch is a follow-up of r15-1079-g230d62a2cdd16c to add vector floating
point trunc pattern for V2DF->V2SF and V4SF->V4HF conversions by renaming 
the
existing aarch64_float_truncate_lo_ pattern to the 
standard
optab one, i.e., trunc2. This allows the 
vectorizer
to vectorize certain floating point narrowing operations for the aarch64 
target.

gcc/ChangeLog:

* config/aarch64/aarch64-builtins.cc (VAR1): Remap 
float_truncate_lo_
builtin codes to standard optab ones.
* config/aarch64/aarch64-simd.md 
(aarch64_float_truncate_lo_):
Rename to...
(trunc2): ... This.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/trunc-vec.c: New test.

Signed-off-by: Pengxuan Zheng 

Diff:
---
 gcc/config/aarch64/aarch64-builtins.cc   |  7 +++
 gcc/config/aarch64/aarch64-simd.md   |  6 +++---
 gcc/testsuite/gcc.target/aarch64/trunc-vec.c | 21 +
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-builtins.cc 
b/gcc/config/aarch64/aarch64-builtins.cc
index 25189888d17d..d589e59defc2 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -543,6 +543,13 @@ BUILTIN_VDQ_BHSI (uhadd, uavg, _floor, 0)
 VAR1 (float_extend_lo_, extend, v2sf, v2df)
 VAR1 (float_extend_lo_, extend, v4hf, v4sf)
 
+/* __builtin_aarch64_float_truncate_lo_ should be expanded through the
+   standard optabs CODE_FOR_trunc2. */
+constexpr insn_code CODE_FOR_aarch64_float_truncate_lo_v4hf
+= CODE_FOR_truncv4sfv4hf2;
+constexpr insn_code CODE_FOR_aarch64_float_truncate_lo_v2sf
+= CODE_FOR_truncv2dfv2sf2;
+
 #undef VAR1
 #define VAR1(T, N, MAP, FLAG, A) \
   {#N #A, UP (A), CF##MAP (N, A), 0, TYPES_##T, FLAG_##FLAG},
diff --git a/gcc/config/aarch64/aarch64-simd.md 
b/gcc/config/aarch64/aarch64-simd.md
index c5e2c9f00d02..f644bd1731e5 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -3197,7 +3197,7 @@
 }
 )
 
-(define_insn "aarch64_float_truncate_lo_"
+(define_insn "trunc2"
   [(set (match_operand:VDF 0 "register_operand" "=w")
   (float_truncate:VDF
(match_operand: 1 "register_operand" "w")))]
@@ -3256,7 +3256,7 @@
 int lo = BYTES_BIG_ENDIAN ? 2 : 1;
 int hi = BYTES_BIG_ENDIAN ? 1 : 2;
 
-emit_insn (gen_aarch64_float_truncate_lo_v2sf (tmp, operands[lo]));
+emit_insn (gen_truncv2dfv2sf2 (tmp, operands[lo]));
 emit_insn (gen_aarch64_float_truncate_hi_v4sf (operands[0],
   tmp, operands[hi]));
 DONE;
@@ -3272,7 +3272,7 @@
   {
 rtx tmp = gen_reg_rtx (V2SFmode);
 emit_insn (gen_aarch64_vec_concatdf (tmp, operands[1], operands[2]));
-emit_insn (gen_aarch64_float_truncate_lo_v2sf (operands[0], tmp));
+emit_insn (gen_truncv2dfv2sf2 (operands[0], tmp));
 DONE;
   }
 )
diff --git a/gcc/testsuite/gcc.target/aarch64/trunc-vec.c 
b/gcc/testsuite/gcc.target/aarch64/trunc-vec.c
new file mode 100644
index ..05e8af7912de
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/trunc-vec.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* { dg-final { scan-assembler-times {fcvtn\tv[0-9]+.2s, v[0-9]+.2d} 1 } } */
+void
+f (double *__restrict a, float *__restrict b)
+{
+  b[0] = a[0];
+  b[1] = a[1];
+}
+
+/* { dg-final { scan-assembler-times {fcvtn\tv[0-9]+.4h, v[0-9]+.4s} 1 } } */
+void
+f1 (float *__restrict a, _Float16 *__restrict b)
+{
+
+  b[0] = a[0];
+  b[1] = a[1];
+  b[2] = a[2];
+  b[3] = a[3];
+}


[gcc r15-1183] i386: Use CMOV in .SAT_{ADD|SUB} expansion for TARGET_CMOV [PR112600]

2024-06-11 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:05b95238be648c9cf8af2516930af6a7b637a2b8

commit r15-1183-g05b95238be648c9cf8af2516930af6a7b637a2b8
Author: Uros Bizjak 
Date:   Tue Jun 11 16:00:31 2024 +0200

i386: Use CMOV in .SAT_{ADD|SUB} expansion for TARGET_CMOV [PR112600]

For TARGET_CMOV targets emit insn sequence involving conditonal move.

.SAT_ADD:

addl%esi, %edi
movl$-1, %eax
cmovnc  %edi, %eax
ret

.SAT_SUB:

subl%esi, %edi
movl$0, %eax
cmovnc  %edi, %eax
ret

PR target/112600

gcc/ChangeLog:

* config/i386/i386.md (usadd3): Emit insn sequence
involving conditional move for TARGET_CMOVE targets.
(ussub3): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr112600-a.c: Also scan for cmov.
* gcc.target/i386/pr112600-b.c: Ditto.

Diff:
---
 gcc/config/i386/i386.md| 62 +-
 gcc/testsuite/gcc.target/i386/pr112600-a.c |  2 +-
 gcc/testsuite/gcc.target/i386/pr112600-b.c |  2 +-
 3 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index d69bc8d6e482..a64f2ad4f5f0 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -9885,13 +9885,35 @@
   ""
 {
   rtx res = gen_reg_rtx (mode);
-  rtx msk = gen_reg_rtx (mode);
   rtx dst;
 
   emit_insn (gen_add3_cc_overflow_1 (res, operands[1], operands[2]));
-  emit_insn (gen_x86_movcc_0_m1_neg (msk));
-  dst = expand_simple_binop (mode, IOR, res, msk,
-operands[0], 1, OPTAB_WIDEN);
+
+  if (TARGET_CMOVE)
+{
+  rtx cmp = gen_rtx_GEU (VOIDmode, gen_rtx_REG (CCCmode, FLAGS_REG),
+const0_rtx);
+
+  if ( < GET_MODE_SIZE (SImode))
+   {
+ dst = force_reg (mode, operands[0]);
+ emit_insn (gen_movsicc (gen_lowpart (SImode, dst), cmp,
+ gen_lowpart (SImode, res), constm1_rtx));
+   }
+   else
+   {
+ dst = operands[0];
+ emit_insn (gen_movcc (dst, cmp, res, constm1_rtx));
+   }
+}
+  else
+{
+  rtx msk = gen_reg_rtx (mode);
+
+  emit_insn (gen_x86_movcc_0_m1_neg (msk));
+  dst = expand_simple_binop (mode, IOR, res, msk,
+operands[0], 1, OPTAB_WIDEN);
+}
 
   if (!rtx_equal_p (dst, operands[0]))
 emit_move_insn (operands[0], dst);
@@ -9905,14 +9927,36 @@
   ""
 {
   rtx res = gen_reg_rtx (mode);
-  rtx msk = gen_reg_rtx (mode);
   rtx dst;
 
   emit_insn (gen_sub_3 (res, operands[1], operands[2]));
-  emit_insn (gen_x86_movcc_0_m1_neg (msk));
-  msk = expand_simple_unop (mode, NOT, msk, NULL, 1);
-  dst = expand_simple_binop (mode, AND, res, msk,
-operands[0], 1, OPTAB_WIDEN);
+
+  if (TARGET_CMOVE)
+{
+  rtx cmp = gen_rtx_GEU (VOIDmode, gen_rtx_REG (CCCmode, FLAGS_REG),
+const0_rtx);
+
+  if ( < GET_MODE_SIZE (SImode))
+   {
+ dst = force_reg (mode, operands[0]);
+ emit_insn (gen_movsicc (gen_lowpart (SImode, dst), cmp,
+ gen_lowpart (SImode, res), const0_rtx));
+   }
+   else
+   {
+ dst = operands[0];
+ emit_insn (gen_movcc (dst, cmp, res, const0_rtx));
+   }
+}
+  else
+{
+  rtx msk = gen_reg_rtx (mode);
+
+  emit_insn (gen_x86_movcc_0_m1_neg (msk));
+  msk = expand_simple_unop (mode, NOT, msk, NULL, 1);
+  dst = expand_simple_binop (mode, AND, res, msk,
+operands[0], 1, OPTAB_WIDEN);
+}
 
   if (!rtx_equal_p (dst, operands[0]))
 emit_move_insn (operands[0], dst);
diff --git a/gcc/testsuite/gcc.target/i386/pr112600-a.c 
b/gcc/testsuite/gcc.target/i386/pr112600-a.c
index fa122bc7a3fd..2b0848604512 100644
--- a/gcc/testsuite/gcc.target/i386/pr112600-a.c
+++ b/gcc/testsuite/gcc.target/i386/pr112600-a.c
@@ -1,7 +1,7 @@
 /* PR target/112600 */
 /* { dg-do compile } */
 /* { dg-options "-O2" } */
-/* { dg-final { scan-assembler-times "sbb" 4 } } */
+/* { dg-final { scan-assembler-times "sbb|cmov" 4 } } */
 
 unsigned char
 add_sat_char (unsigned char x, unsigned char y)
diff --git a/gcc/testsuite/gcc.target/i386/pr112600-b.c 
b/gcc/testsuite/gcc.target/i386/pr112600-b.c
index ea14bb9738b7..ac4e26423b6f 100644
--- a/gcc/testsuite/gcc.target/i386/pr112600-b.c
+++ b/gcc/testsuite/gcc.target/i386/pr112600-b.c
@@ -1,7 +1,7 @@
 /* PR target/112600 */
 /* { dg-do compile } */
 /* { dg-options "-O2" } */
-/* { dg-final { scan-assembler-times "sbb" 4 } } */
+/* { dg-final { scan-assembler-times "sbb|cmov" 4 } } */
 
 unsigned char
 sub_sat_char (unsigned char x, unsigned char y)


[gcc r15-1184] RISC-V: Add basic Zaamo and Zalrsc support

2024-06-11 Thread Patrick O'Neill via Gcc-cvs
https://gcc.gnu.org/g:af139b3fc19fbdd7caa649bcb2cb75cc5a254143

commit r15-1184-gaf139b3fc19fbdd7caa649bcb2cb75cc5a254143
Author: Edwin Lu 
Date:   Wed Feb 7 16:30:28 2024 -0800

RISC-V: Add basic Zaamo and Zalrsc support

There is a proposal to split the A extension into two parts: Zaamo and 
Zalrsc.
This patch adds basic support by making the A extension imply Zaamo and
Zalrsc.

Proposal: https://github.com/riscv/riscv-zaamo-zalrsc/tags

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: Add Zaamo and Zalrsc.
* config/riscv/arch-canonicalize: Make A imply Zaamo and Zalrsc.
* config/riscv/riscv.opt: Add Zaamo and Zalrsc
* config/riscv/sync.md: Convert TARGET_ATOMIC to TARGET_ZAAMO and
TARGET_ZALRSC.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/attribute-15.c: Adjust expected arch string.
* gcc.target/riscv/attribute-16.c: Ditto.
* gcc.target/riscv/attribute-17.c: Ditto.
* gcc.target/riscv/attribute-18.c: Ditto.
* gcc.target/riscv/pr110696.c: Ditto.
* gcc.target/riscv/rvv/base/pr114352-1.c: Ditto.
* gcc.target/riscv/rvv/base/pr114352-3.c: Ditto.

Signed-off-by: Edwin Lu 
Co-authored-by: Patrick O'Neill 

Diff:
---
 gcc/common/config/riscv/riscv-common.cc| 11 ++--
 gcc/config/riscv/arch-canonicalize |  1 +
 gcc/config/riscv/riscv.opt |  6 -
 gcc/config/riscv/sync.md   | 30 +++---
 gcc/testsuite/gcc.target/riscv/attribute-15.c  |  2 +-
 gcc/testsuite/gcc.target/riscv/attribute-16.c  |  2 +-
 gcc/testsuite/gcc.target/riscv/attribute-17.c  |  2 +-
 gcc/testsuite/gcc.target/riscv/attribute-18.c  |  2 +-
 gcc/testsuite/gcc.target/riscv/pr110696.c  |  2 +-
 .../gcc.target/riscv/rvv/base/pr114352-1.c |  4 +--
 .../gcc.target/riscv/rvv/base/pr114352-3.c |  8 +++---
 11 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 88204393fde0..78dfd6b1470d 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -79,6 +79,9 @@ static const riscv_implied_info_t riscv_implied_info[] =
   {"f", "zicsr"},
   {"d", "zicsr"},
 
+  {"a", "zaamo"},
+  {"a", "zalrsc"},
+
   {"zdinx", "zfinx"},
   {"zfinx", "zicsr"},
   {"zdinx", "zicsr"},
@@ -255,6 +258,8 @@ static const struct riscv_ext_version 
riscv_ext_version_table[] =
   {"za64rs",  ISA_SPEC_CLASS_NONE, 1, 0},
   {"za128rs", ISA_SPEC_CLASS_NONE, 1, 0},
   {"zawrs", ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zaamo", ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zalrsc", ISA_SPEC_CLASS_NONE, 1, 0},
 
   {"zba", ISA_SPEC_CLASS_NONE, 1, 0},
   {"zbb", ISA_SPEC_CLASS_NONE, 1, 0},
@@ -1616,9 +1621,11 @@ static const riscv_ext_flag_table_t 
riscv_ext_flag_table[] =
   {"zifencei", &gcc_options::x_riscv_zi_subext, MASK_ZIFENCEI},
   {"zicond",   &gcc_options::x_riscv_zi_subext, MASK_ZICOND},
 
-  {"za64rs", &gcc_options::x_riscv_za_subext, MASK_ZA64RS},
+  {"za64rs",  &gcc_options::x_riscv_za_subext, MASK_ZA64RS},
   {"za128rs", &gcc_options::x_riscv_za_subext, MASK_ZA128RS},
-  {"zawrs", &gcc_options::x_riscv_za_subext, MASK_ZAWRS},
+  {"zawrs",   &gcc_options::x_riscv_za_subext, MASK_ZAWRS},
+  {"zaamo",   &gcc_options::x_riscv_za_subext, MASK_ZAAMO},
+  {"zalrsc",  &gcc_options::x_riscv_za_subext, MASK_ZALRSC},
 
   {"zba",&gcc_options::x_riscv_zb_subext, MASK_ZBA},
   {"zbb",&gcc_options::x_riscv_zb_subext, MASK_ZBB},
diff --git a/gcc/config/riscv/arch-canonicalize 
b/gcc/config/riscv/arch-canonicalize
index 8f7d040cdeb9..6c10d1aa81b5 100755
--- a/gcc/config/riscv/arch-canonicalize
+++ b/gcc/config/riscv/arch-canonicalize
@@ -40,6 +40,7 @@ LONG_EXT_PREFIXES = ['z', 's', 'h', 'x']
 #
 IMPLIED_EXT = {
   "d" : ["f", "zicsr"],
+  "a" : ["zaamo", "zalrsc"],
   "f" : ["zicsr"],
   "zdinx" : ["zfinx", "zicsr"],
   "zfinx" : ["zicsr"],
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 78cb1c37e69f..b13e993c47a2 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -256,7 +256,11 @@ Mask(ZICCRSE) Var(riscv_zi_subext)
 TargetVariable
 int riscv_za_subext
 
-Mask(ZAWRS) Var(riscv_za_subext)
+Mask(ZAWRS)  Var(riscv_za_subext)
+
+Mask(ZAAMO)  Var(riscv_za_subext)
+
+Mask(ZALRSC) Var(riscv_za_subext)
 
 Mask(ZA64RS)  Var(riscv_za_subext)
 
diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md
index 6f0b5aae08dc..c9544176ead5 100644
--- a/gcc/config/riscv/sync.md
+++ b/gcc/config/riscv/sync.md
@@ -93,7 +93,7 @@
 (match_operand:GPR 1 "reg_or_0_operand" "rJ"))
   (match_operand:SI 2 "const_int_operand")] ;; model
 UNSPEC_SYNC_OLD_OP))]
-  "TARGET_ATOMIC"
+  "TARGET_ZAAMO"
   "amo.%A2\tzero,%z1,%0"
   [(set_attr "type" "atomic")

[gcc r15-1185] RISC-V: Add Zalrsc and Zaamo testsuite support

2024-06-11 Thread Patrick O'Neill via Gcc-cvs
https://gcc.gnu.org/g:0fea902b1b5311c8b34ae8e789f1733bd8429904

commit r15-1185-g0fea902b1b5311c8b34ae8e789f1733bd8429904
Author: Patrick O'Neill 
Date:   Mon Jun 10 14:12:40 2024 -0700

RISC-V: Add Zalrsc and Zaamo testsuite support

Convert testsuite infrastructure to use Zalrsc and Zaamo rather than A.

gcc/ChangeLog:

* doc/sourcebuild.texi: Add docs for atomic extension testsuite 
infra.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/amo-table-a-6-amo-add-1.c: Use Zaamo rather than 
A.
* gcc.target/riscv/amo-table-a-6-amo-add-2.c: Ditto.
* gcc.target/riscv/amo-table-a-6-amo-add-3.c: Ditto.
* gcc.target/riscv/amo-table-a-6-amo-add-4.c: Ditto.
* gcc.target/riscv/amo-table-a-6-amo-add-5.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-1.c: Use Zalrsc 
rather
than A.
* gcc.target/riscv/amo-table-a-6-compare-exchange-2.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-3.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-4.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-5.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-6.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-7.c: Ditto.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-1.c: Use Zaamo 
rather
than A.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-2.c: Ditto.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-3.c: Ditto.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-4.c: Ditto.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-5.c: Ditto.
* gcc.target/riscv/amo-table-ztso-amo-add-1.c: Add Zaamo option.
* gcc.target/riscv/amo-table-ztso-amo-add-2.c: Ditto.
* gcc.target/riscv/amo-table-ztso-amo-add-3.c: Ditto.
* gcc.target/riscv/amo-table-ztso-amo-add-4.c: Ditto.
* gcc.target/riscv/amo-table-ztso-amo-add-5.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-1.c: Use Zalrsc 
rather
than A.
* gcc.target/riscv/amo-table-ztso-compare-exchange-2.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-3.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-4.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-5.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-6.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-7.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-1.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-2.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-3.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-4.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-5.c: Ditto.
* lib/target-supports.exp: Add testsuite infrastructure support for
Zaamo and Zalrsc.

Signed-off-by: Patrick O'Neill 

Diff:
---
 gcc/doc/sourcebuild.texi   | 16 +++-
 .../gcc.target/riscv/amo-table-a-6-amo-add-1.c |  2 +-
 .../gcc.target/riscv/amo-table-a-6-amo-add-2.c |  2 +-
 .../gcc.target/riscv/amo-table-a-6-amo-add-3.c |  2 +-
 .../gcc.target/riscv/amo-table-a-6-amo-add-4.c |  2 +-
 .../gcc.target/riscv/amo-table-a-6-amo-add-5.c |  2 +-
 .../riscv/amo-table-a-6-compare-exchange-1.c   |  2 +-
 .../riscv/amo-table-a-6-compare-exchange-2.c   |  2 +-
 .../riscv/amo-table-a-6-compare-exchange-3.c   |  2 +-
 .../riscv/amo-table-a-6-compare-exchange-4.c   |  2 +-
 .../riscv/amo-table-a-6-compare-exchange-5.c   |  2 +-
 .../riscv/amo-table-a-6-compare-exchange-6.c   |  2 +-
 .../riscv/amo-table-a-6-compare-exchange-7.c   |  2 +-
 .../riscv/amo-table-a-6-subword-amo-add-1.c|  2 +-
 .../riscv/amo-table-a-6-subword-amo-add-2.c|  2 +-
 .../riscv/amo-table-a-6-subword-amo-add-3.c|  2 +-
 .../riscv/amo-table-a-6-subword-amo-add-4.c|  2 +-
 .../riscv/amo-table-a-6-subword-amo-add-5.c|  2 +-
 .../gcc.target/riscv/amo-table-ztso-amo-add-1.c|  2 +-
 .../gcc.target/riscv/amo-table-ztso-amo-add-2.c|  2 +-
 .../gcc.target/riscv/amo-table-ztso-amo-add-3.c|  2 +-
 .../gcc.target/riscv/amo-table-ztso-amo-add-4.c|  2 +-
 .../gcc.target/riscv/amo-table-ztso-amo-add-5.c|  2 +-
 .../riscv/amo-table-ztso-compare-exchange-1.c  |  2 +-
 .../riscv/amo-table-ztso-compare-exchange-2.c  |  2 +-
 .../riscv/amo-table-ztso-compare-exchange-3.c  |  2 +-
 .../riscv/amo-table-ztso-compare-exchange-4.c  |  2 +-
 .../riscv/amo-table-ztso-compare-exchange-5.c  |  2 +-
 .../riscv/amo-table-ztso-compare-exchange-6.c  |  2 +-
 .../riscv/amo-table-ztso-compare-exchange-7.c  |  2 +-
 .

[gcc r15-1186] RISC-V: Add Zalrsc amo-op patterns

2024-06-11 Thread Patrick O'Neill via Gcc-cvs
https://gcc.gnu.org/g:1588983be6112561c805a50eb7a3c585865beffa

commit r15-1186-g1588983be6112561c805a50eb7a3c585865beffa
Author: Patrick O'Neill 
Date:   Wed Feb 7 16:30:30 2024 -0800

RISC-V: Add Zalrsc amo-op patterns

All amo patterns can be represented with lrsc sequences.
Add these patterns as a fallback when Zaamo is not enabled.

gcc/ChangeLog:

* config/riscv/sync.md (atomic_): New expand 
pattern.
(amo_atomic_): Rename amo pattern.
(atomic_fetch_): New lrsc sequence pattern.
(lrsc_atomic_): New expand pattern.
(amo_atomic_fetch_): Rename amo pattern.
(lrsc_atomic_fetch_): New lrsc sequence pattern.
(atomic_exchange): New expand pattern.
(amo_atomic_exchange): Rename amo pattern.
(lrsc_atomic_exchange): New lrsc sequence pattern.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/amo-zaamo-preferred-over-zalrsc.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-1.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-2.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-3.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-4.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-5.c: New test.

Signed-off-by: Patrick O'Neill 

Diff:
---
 gcc/config/riscv/sync.md   | 124 -
 .../riscv/amo-zaamo-preferred-over-zalrsc.c|  17 +++
 .../gcc.target/riscv/amo-zalrsc-amo-add-1.c|  19 
 .../gcc.target/riscv/amo-zalrsc-amo-add-2.c|  19 
 .../gcc.target/riscv/amo-zalrsc-amo-add-3.c|  19 
 .../gcc.target/riscv/amo-zalrsc-amo-add-4.c|  19 
 .../gcc.target/riscv/amo-zalrsc-amo-add-5.c|  19 
 7 files changed, 231 insertions(+), 5 deletions(-)

diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md
index c9544176ead5..4df9d0b5a5ff 100644
--- a/gcc/config/riscv/sync.md
+++ b/gcc/config/riscv/sync.md
@@ -86,7 +86,24 @@
 DONE;
   })
 
-(define_insn "atomic_"
+;; AMO ops
+
+(define_expand "atomic_"
+  [(any_atomic:GPR (match_operand:GPR 0 "memory_operand");; mem location
+  (match_operand:GPR 1 "reg_or_0_operand")) ;; value for op
+   (match_operand:SI 2 "const_int_operand")];; model
+  "TARGET_ZAAMO || TARGET_ZALRSC"
+{
+  if (TARGET_ZAAMO)
+emit_insn (gen_amo_atomic_ (operands[0], operands[1],
+   operands[2]));
+  else
+emit_insn (gen_lrsc_atomic_ (operands[0], operands[1],
+operands[2]));
+  DONE;
+})
+
+(define_insn "amo_atomic_"
   [(set (match_operand:GPR 0 "memory_operand" "+A")
(unspec_volatile:GPR
  [(any_atomic:GPR (match_dup 0)
@@ -98,7 +115,44 @@
   [(set_attr "type" "atomic")
(set (attr "length") (const_int 4))])
 
-(define_insn "atomic_fetch_"
+(define_insn "lrsc_atomic_"
+  [(set (match_operand:GPR 0 "memory_operand" "+A")
+   (unspec_volatile:GPR
+ [(any_atomic:GPR (match_dup 0)
+(match_operand:GPR 1 "reg_or_0_operand" "rJ"))
+  (match_operand:SI 2 "const_int_operand")] ;; model
+UNSPEC_SYNC_OLD_OP))
+   (clobber (match_scratch:GPR 3 "=&r"))]   ;; tmp_1
+  "!TARGET_ZAAMO && TARGET_ZALRSC"
+  {
+return "1:\;"
+  "lr.%I2\t%3, %0\;"
+  "\t%3, %3, %1\;"
+  "sc.%J2\t%3, %3, %0\;"
+  "bnez\t%3, 1b";
+  }
+  [(set_attr "type" "atomic")
+   (set (attr "length") (const_int 16))])
+
+;; AMO fetch ops
+
+(define_expand "atomic_fetch_"
+  [(match_operand:GPR 0 "register_operand") ;; old value at mem
+   (any_atomic:GPR (match_operand:GPR 1 "memory_operand");; mem location
+  (match_operand:GPR 2 "reg_or_0_operand")) ;; value for op
+   (match_operand:SI 3 "const_int_operand")];; model
+  "TARGET_ZAAMO || TARGET_ZALRSC"
+  {
+if (TARGET_ZAAMO)
+  emit_insn (gen_amo_atomic_fetch_ (operands[0], 
operands[1],
+   operands[2], 
operands[3]));
+else
+  emit_insn (gen_lrsc_atomic_fetch_ (operands[0], 
operands[1],
+operands[2], 
operands[3]));
+DONE;
+  })
+
+(define_insn "amo_atomic_fetch_"
   [(set (match_operand:GPR 0 "register_operand" "=&r")
(match_operand:GPR 1 "memory_operand" "+A"))
(set (match_dup 1)
@@ -112,6 +166,27 @@
   [(set_attr "type" "atomic")
(set (attr "length") (const_int 4))])
 
+(define_insn "lrsc_atomic_fetch_"
+  [(set (match_operand:GPR 0 "register_operand" "=&r")
+   (match_operand:GPR 1 "memory_operand" "+A"))
+   (set (match_dup 1)
+   (unspec_volatile:GPR
+ [(any_atomic:GPR (match_dup 1)
+(match_operand:GPR 2 "reg_or_0_operand" "rJ"))
+  (match_operand:SI 3 "const_i

[gcc r12-10535] libstdc++: Destroy allocators in re-inserted container nodes [PR114401]

2024-06-11 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c394e299491ce6dc7e1a51b89165078e11cf75be

commit r12-10535-gc394e299491ce6dc7e1a51b89165078e11cf75be
Author: Jonathan Wakely 
Date:   Thu Mar 21 13:25:15 2024 +

libstdc++: Destroy allocators in re-inserted container nodes [PR114401]

The allocator objects in container node handles were not being destroyed
after the node was re-inserted into a container. They are stored in a
union and so need to be explicitly destroyed when the node becomes
empty. The containers were zeroing the node handle's pointer, which
makes it empty, causing the handle's destructor to think there's nothing
to clean up.

Add a new member function to the node handle which destroys the
allocator and zeros the pointer. Change the containers to call that
instead of just changing the pointer manually.

We can also remove the _M_empty member of the union which is not
necessary.

libstdc++-v3/ChangeLog:

PR libstdc++/114401
* include/bits/hashtable.h (_Hashtable::_M_reinsert_node): Call
release() on node handle instead of just zeroing its pointer.
(_Hashtable::_M_reinsert_node_multi): Likewise.
(_Hashtable::_M_merge_unique): Likewise.
(_Hashtable::_M_merge_multi): Likewise.
* include/bits/node_handle.h (_Node_handle_common::release()):
New member function.
(_Node_handle_common::_Optional_alloc::_M_empty): Remove
unnecessary union member.
(_Node_handle_common): Declare _Hashtable as a friend.
* include/bits/stl_tree.h (_Rb_tree::_M_reinsert_node_unique):
Call release() on node handle instead of just zeroing its
pointer.
(_Rb_tree::_M_reinsert_node_equal): Likewise.
(_Rb_tree::_M_reinsert_node_hint_unique): Likewise.
(_Rb_tree::_M_reinsert_node_hint_equal): Likewise.
* testsuite/23_containers/multiset/modifiers/114401.cc: New test.
* testsuite/23_containers/set/modifiers/114401.cc: New test.
* testsuite/23_containers/unordered_multiset/modifiers/114401.cc: 
New test.
* testsuite/23_containers/unordered_set/modifiers/114401.cc: New 
test.

(cherry picked from commit c2e28df90a1640cebadef6c6c8ab5ea964071bb1)

Diff:
---
 libstdc++-v3/include/bits/hashtable.h  |  10 +-
 libstdc++-v3/include/bits/node_handle.h|  19 +++-
 libstdc++-v3/include/bits/stl_tree.h   |  10 +-
 .../23_containers/multiset/modifiers/114401.cc | 125 
 .../23_containers/set/modifiers/114401.cc  | 125 
 .../unordered_multiset/modifiers/114401.cc | 126 +
 .../unordered_set/modifiers/114401.cc  | 126 +
 7 files changed, 528 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/include/bits/hashtable.h 
b/libstdc++-v3/include/bits/hashtable.h
index 1a505fff089b..3823c7e7471d 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -985,7 +985,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // DR 1189.
   // reserve, if present, comes from _Rehash_base.
 
-#if __cplusplus > 201402L
+#if __cplusplus > 201404L
   /// Re-insert an extracted node into a container with unique keys.
   insert_return_type
   _M_reinsert_node(node_type&& __nh)
@@ -1010,7 +1010,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  {
__ret.position
  = _M_insert_unique_node(__bkt, __code, __nh._M_ptr);
-   __nh._M_ptr = nullptr;
+   __nh.release();
__ret.inserted = true;
  }
  }
@@ -1030,7 +1030,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
auto __code = this->_M_hash_code(__k);
auto __ret
  = _M_insert_multi_node(__hint._M_cur, __code, __nh._M_ptr);
-   __nh._M_ptr = nullptr;
+   __nh.release();
return __ret;
   }
 
@@ -1112,7 +1112,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
  auto __nh = __src.extract(__pos);
  _M_insert_unique_node(__bkt, __code, __nh._M_ptr, __n_elt);
- __nh._M_ptr = nullptr;
+ __nh.release();
  __n_elt = 1;
}
  else if (__n_elt != 1)
@@ -1139,7 +1139,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
= _M_src_hash_code(__src.hash_function(), __k, *__pos._M_cur);
  auto __nh = __src.extract(__pos);
  __hint = _M_insert_multi_node(__hint, __code, __nh._M_ptr)._M_cur;
- __nh._M_ptr = nullptr;
+ __nh.release();
}
}
 #endif // C++17
diff --git a/libstdc++-v3/include/bits/node_handle.h 
b/libstdc++-v3/include/bits/node_handle.h
index d7a7a30c8390..92ed27c10083 100644
--- a/libstdc++-v3/include/bits/node_handle.h
+++ b/libstdc++-

[gcc r12-10537] libstdc++: Begin lifetime of storage in std::vector [PR114367]

2024-06-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:5c2c5805304da2436f4a749d357eee34eae9d792

commit r12-10537-g5c2c5805304da2436f4a749d357eee34eae9d792
Author: Jonathan Wakely 
Date:   Mon Mar 18 13:00:17 2024 +

libstdc++: Begin lifetime of storage in std::vector [PR114367]

This doesn't cause a problem with GCC, but Clang correctly diagnoses a
bug in the code. The objects in the allocated storage need to begin
their lifetime before we start using them.

This change uses the allocator's construct function instead of using
std::construct_at directly, in order to support fancy pointers.

libstdc++-v3/ChangeLog:

PR libstdc++/114367
* include/bits/stl_bvector.h (_M_allocate): Use allocator's
construct function to begin lifetime of words.

(cherry picked from commit 16afbd9c9c4282d56062cef95e6eccfdcf3efe03)

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index f90d3c47f3d3..e1559c253d81 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -629,13 +629,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   _M_allocate(size_t __n)
   {
_Bit_pointer __p = _Bit_alloc_traits::allocate(_M_impl, _S_nword(__n));
-#if __cpp_lib_is_constant_evaluated
+#if __cpp_lib_is_constant_evaluated && __cpp_constexpr_dynamic_alloc
if (std::is_constant_evaluated())
-   {
- __n = _S_nword(__n);
- for (size_t __i = 0; __i < __n; ++__i)
-   __p[__i] = 0ul;
-   }
+ {
+   __n = _S_nword(__n);
+   for (size_t __i = 0; __i < __n; ++__i)
+ std::construct_at(std::to_address(__p) + __i);
+ }
 #endif
return __p;
   }


[gcc r12-10541] libstdc++: Add preprocessor checks to [PR100285]

2024-06-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:3494bc7b03997f96e84e84f6904917854466d5ea

commit r12-10541-g3494bc7b03997f96e84e84f6904917854466d5ea
Author: Jonathan Wakely 
Date:   Fri Jun 9 12:15:21 2023 +0100

libstdc++: Add preprocessor checks to  [PR100285]

We can't define endpoints and resolvers without the relevant OS support.
If IPPROTO_TCP and IPPROTO_UDP are both undefined then we won't need
basic_endpoint and basic_resolver anyway, so make them depend on those
macros.

libstdc++-v3/ChangeLog:

PR libstdc++/100285
* include/experimental/internet [IPPROTO_TCP || IPPROTO_UDP]
(basic_endpoint, basic_resolver_entry, resolver_base)
(basic_resolver_results, basic_resolver): Only define if the tcp
or udp protocols will be defined.

(cherry picked from commit 793ed718b522b15e2d758eca953feeec1979fe2c)

Diff:
---
 libstdc++-v3/include/experimental/internet | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libstdc++-v3/include/experimental/internet 
b/libstdc++-v3/include/experimental/internet
index 4be4bfb731e5..5b05b0f37af7 100644
--- a/libstdc++-v3/include/experimental/internet
+++ b/libstdc++-v3/include/experimental/internet
@@ -1457,6 +1457,7 @@ namespace ip
 operator<<(basic_ostream<_CharT, _Traits>& __os, const network_v6& __net)
 { return __os << __net.to_string(); }
 
+#if defined IPPROTO_TCP || defined  IPPROTO_UDP
   /// An IP endpoint.
   template
 class basic_endpoint
@@ -2091,6 +2092,7 @@ namespace ip
   __ec = std::make_error_code(errc::operation_not_supported);
 #endif
 }
+#endif // IPPROTO_TCP || IPPROTO_UDP
 
   /** The name of the local host.
* @{


[gcc r12-10536] libstdc++: Reverse arguments in constraint for std::optional's <=> [PR104606]

2024-06-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:80d0f82e6961ff8991897454e2bac126488ea6b9

commit r12-10536-g80d0f82e6961ff8991897454e2bac126488ea6b9
Author: Jonathan Wakely 
Date:   Wed Mar 27 21:51:13 2024 +

libstdc++: Reverse arguments in constraint for std::optional's <=> 
[PR104606]

This is a workaround for a possible compiler bug that causes constraint
recursion in the operator<=>(const optional&, const U&) overload.

libstdc++-v3/ChangeLog:

PR libstdc++/104606
* include/std/optional (operator<=>(const optional&, const U&)):
Reverse order of three_way_comparable_with template arguments.
* testsuite/20_util/optional/relops/104606.cc: New test.

(cherry picked from commit 7f65d8267fbfd19cf21a3dc71d27e989e75044a3)

Diff:
---
 libstdc++-v3/include/std/optional  |  2 +-
 .../testsuite/20_util/optional/relops/104606.cc| 18 ++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index 122ff7e58630..5729554dc8da 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -1420,7 +1420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #ifdef __cpp_lib_three_way_comparison
   template
 requires (!__is_optional_v<_Up>)
-  && three_way_comparable_with<_Tp, _Up>
+  && three_way_comparable_with<_Up, _Tp>
 constexpr compare_three_way_result_t<_Tp, _Up>
 operator<=>(const optional<_Tp>& __x, const _Up& __v)
 { return bool(__x) ? *__x <=> __v : strong_ordering::less; }
diff --git a/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc 
b/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc
new file mode 100644
index ..2b8df2452199
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++17 } }
+
+// Bug 104606 comparison operator resolution with std::optional and -std=c++20
+
+#include 
+#include 
+#include 
+
+struct Value : std::variant> { };
+
+struct Comparator {
+  template  bool operator<=(const T &) { return true; }
+};
+
+std::optional o;
+Comparator c;
+
+auto x = c <= o;


[gcc r12-10542] libstdc++: Implement some missing functions for net::ip::network_v6

2024-06-11 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:5f885bd5f435ea05ad18d28860b3f22c7705d967

commit r12-10542-g5f885bd5f435ea05ad18d28860b3f22c7705d967
Author: Jonathan Wakely 
Date:   Thu Feb 1 10:08:05 2024 +

libstdc++: Implement some missing functions for net::ip::network_v6

libstdc++-v3/ChangeLog:

* include/experimental/internet (network_v6::network): Define.
(network_v6::hosts): Finish implementing.
(network_v6::to_string): Do not concatenate std::string to
arbitrary std::basic_string specialization.
* testsuite/experimental/net/internet/network/v6/cons.cc: New
test.

(cherry picked from commit 5b069117e261ae0b438aee0cdff8707827810adf)

Diff:
---
 libstdc++-v3/include/experimental/internet | 26 ++--
 .../experimental/net/internet/network/v6/cons.cc   | 74 ++
 2 files changed, 96 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/experimental/internet 
b/libstdc++-v3/include/experimental/internet
index 5b05b0f37af7..c57b48bcaa32 100644
--- a/libstdc++-v3/include/experimental/internet
+++ b/libstdc++-v3/include/experimental/internet
@@ -1310,17 +1310,35 @@ namespace ip
 constexpr address_v6 address() const noexcept { return _M_addr; }
 constexpr int prefix_length() const noexcept { return _M_prefix_len; }
 
-constexpr address_v6 network() const noexcept; // TODO
+_GLIBCXX17_CONSTEXPR address_v6
+network() const noexcept
+{
+  address_v6::bytes_type __bytes = _M_addr.to_bytes();
+  int __nbytes = (_M_prefix_len + 7) / 8;
+  for (int __n = __nbytes; __n < 16; ++__n)
+   __bytes[__n] = 0;
+  if (int __zbits = (__nbytes * 8) - _M_prefix_len)
+   __bytes[__nbytes - 1] &= 0xFF << __zbits;
+  return address_v6(__bytes, _M_addr.scope_id());
+}
 
 address_v6_range
 hosts() const noexcept
 {
   if (is_host())
return { address(), *++address_v6_iterator(address()) };
-  return {}; // { network(), XXX broadcast() XXX }; // TODO
+
+  address_v6::bytes_type __bytes = _M_addr.to_bytes();
+  int __nbytes = (_M_prefix_len + 7) / 8;
+  for (int __n = __nbytes; __n < 16; ++__n)
+   __bytes[__n] = 0xFF;
+  if (int __bits = (__nbytes * 8) - _M_prefix_len)
+   __bytes[__nbytes - 1] |= (1 << __bits) - 1;
+  address_v6 __last(__bytes, _M_addr.scope_id());
+  return { network(), *++address_v6_iterator(__last) };
 }
 
-constexpr network_v6
+_GLIBCXX17_CONSTEXPR network_v6
 canonical() const noexcept
 { return network_v6{network(), prefix_length()}; }
 
@@ -1342,7 +1360,7 @@ namespace ip
   to_string(const _Allocator& __a = _Allocator()) const
   {
return address().to_string(__a) + '/'
- + std::to_string(prefix_length());
++ std::to_string(prefix_length()).c_str();
   }
 
   private:
diff --git 
a/libstdc++-v3/testsuite/experimental/net/internet/network/v6/cons.cc 
b/libstdc++-v3/testsuite/experimental/net/internet/network/v6/cons.cc
new file mode 100644
index ..9b4b791bd023
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/net/internet/network/v6/cons.cc
@@ -0,0 +1,74 @@
+// { dg-do run { target c++14 } }
+// { dg-require-effective-target net_ts_ip }
+// { dg-add-options net_ts }
+
+#include 
+#include 
+#include 
+
+using std::experimental::net::ip::network_v6;
+using std::experimental::net::ip::address_v6;
+
+constexpr void
+test01()
+{
+  network_v6 n0;
+  VERIFY( n0.address().is_unspecified() );
+  VERIFY( n0.prefix_length() == 0 );
+}
+
+constexpr void
+test02()
+{
+  address_v6 a0;
+  network_v6 n0{ a0, 0 };
+  VERIFY( n0.address() == a0 );
+  VERIFY( n0.prefix_length() == 0 );
+
+  address_v6 a1{ address_v6::bytes_type{ 1, 2, 4, 8, 16, 32, 64, 128,
+3, 7, 47, 71, 83, 165, 199, 255 } };
+  network_v6 n1{ a1, 99};
+  VERIFY( n1.address() == a1 );
+  VERIFY( n1.prefix_length() == 99 );
+}
+
+void
+test02_errors()
+{
+  address_v6 a0;
+  try
+  {
+network_v6{a0, -1};
+VERIFY(false);
+  }
+  catch(const std::out_of_range&)
+  {
+  }
+
+  try
+  {
+network_v6{a0, 129};
+VERIFY(false);
+  }
+  catch(const std::out_of_range&)
+  {
+  }
+}
+
+constexpr bool
+test_constexpr()
+{
+  test01();
+  test02();
+  return true;
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test02_errors();
+
+  static_assert( test_constexpr(), "valid in constant expressions" );
+}


[gcc r12-10538] libstdc++: Fix infinite loop in std::binomial_distribution [PR114359]

2024-06-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:bd31ecc1c7aef5b4ae7ddb04926a2f4105957df4

commit r12-10538-gbd31ecc1c7aef5b4ae7ddb04926a2f4105957df4
Author: Jonathan Wakely 
Date:   Mon Mar 18 13:22:17 2024 +

libstdc++: Fix infinite loop in std::binomial_distribution [PR114359]

The multiplication (4 * _M_t * __1p) can wraparound to zero if _M_t is
unsigned and 4 * _M_t wraps to zero. The third operand has type double,
so do the second multiplication first, so that we aren't multiplying
integers.

libstdc++-v3/ChangeLog:

PR libstdc++/114359
* include/bits/random.tcc (binomial_distribution::param_type):
Ensure arithmetic is done as type double.
* testsuite/26_numerics/random/binomial_distribution/114359.cc: New 
test.

(cherry picked from commit 07e03761a7fc1626a6a74ed957e117f56981558c)

Diff:
---
 libstdc++-v3/include/bits/random.tcc |  2 +-
 .../26_numerics/random/binomial_distribution/114359.cc   | 12 
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/random.tcc 
b/libstdc++-v3/include/bits/random.tcc
index 41644205425e..5d9f679d6645 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -1503,7 +1503,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  // sqrt(pi / 2)
  const double __spi_2 = 1.2533141373155002512078826424055226L;
  _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
- _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
+ _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * (_M_t * __1p)));
  _M_c = 2 * _M_d1 / __np;
  _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2;
  const double __a12 = _M_a1 + _M_s2 * __spi_2;
diff --git 
a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc 
b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc
new file mode 100644
index ..c1e4c380bf91
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc
@@ -0,0 +1,12 @@
+// { dg-do run { target c++11 } }
+
+// Bug 114359 - std::binomial_distribution hangs in infinite loop
+
+#include 
+
+int main()
+{
+  std::default_random_engine g{};
+  std::binomial_distribution b(1U << 30);
+  b(g);  // hangs forever
+}


[gcc r12-10543] libstdc++: Fix uses of non-reserved names in headers

2024-06-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:4d257dac0adecc7ce6b1b871cd5e99ae75f0688f

commit r12-10543-g4d257dac0adecc7ce6b1b871cd5e99ae75f0688f
Author: Jonathan Wakely 
Date:   Fri Feb 10 23:16:15 2023 +

libstdc++: Fix uses of non-reserved names in headers

The non-reserved names 'val' and 'dest' were being used in our headers
but haven't been added to the 17_intro/names.cc test. That's because
they are used by  and 
respecitvely on glibc-based systems.

libstdc++-v3/ChangeLog:

* include/bits/fs_ops.h (create_directory): Use reserved name
for parameter.
* include/bits/regex_automaton.h (_State_base::_M_print):
Likewise.
* include/bits/regex_automaton.tcc(_State_base::_M_print):
Likewise.
* include/bits/regex_scanner.tcc(_Scanner::_M_print): Likewise.
* include/experimental/bits/fs_ops.h (create_directory):
Likewise.
* include/std/mutex (timed_mutex::_M_clocklock): Likewise.
(recursive_timed_mutex:_M_clocklock): Likewise.
* libsupc++/cxxabi_init_exception.h
(__cxa_init_primary_exception): Likewise.
* testsuite/17_intro/names.cc: Add checks.

(cherry picked from commit dc79eba72b4d16180e500eba336f511a485a8496)

Diff:
---
 libstdc++-v3/include/bits/fs_ops.h  |  4 +-
 libstdc++-v3/include/bits/regex_automaton.h |  2 +-
 libstdc++-v3/include/bits/regex_automaton.tcc   | 18 
 libstdc++-v3/include/bits/regex_scanner.tcc | 60 -
 libstdc++-v3/include/experimental/bits/fs_ops.h |  4 +-
 libstdc++-v3/include/std/mutex  |  8 ++--
 libstdc++-v3/libsupc++/cxxabi_init_exception.h  |  5 ++-
 libstdc++-v3/testsuite/17_intro/names.cc| 21 -
 8 files changed, 70 insertions(+), 52 deletions(-)

diff --git a/libstdc++-v3/include/bits/fs_ops.h 
b/libstdc++-v3/include/bits/fs_ops.h
index 1ae8fe12374d..e85eb980f585 100644
--- a/libstdc++-v3/include/bits/fs_ops.h
+++ b/libstdc++-v3/include/bits/fs_ops.h
@@ -90,8 +90,8 @@ namespace filesystem
   bool create_directory(const path& __p);
   bool create_directory(const path& __p, error_code& __ec) noexcept;
 
-  bool create_directory(const path& __p, const path& attributes);
-  bool create_directory(const path& __p, const path& attributes,
+  bool create_directory(const path& __p, const path& __attributes);
+  bool create_directory(const path& __p, const path& __attributes,
error_code& __ec) noexcept;
 
   void create_directory_symlink(const path& __to, const path& __new_symlink);
diff --git a/libstdc++-v3/include/bits/regex_automaton.h 
b/libstdc++-v3/include/bits/regex_automaton.h
index 44bde42e2126..1bafaff79b39 100644
--- a/libstdc++-v3/include/bits/regex_automaton.h
+++ b/libstdc++-v3/include/bits/regex_automaton.h
@@ -110,7 +110,7 @@ namespace __detail
 
 #ifdef _GLIBCXX_DEBUG
 std::ostream&
-_M_print(std::ostream& ostr) const;
+_M_print(std::ostream& __ostr) const;
 
 // Prints graphviz dot commands for state.
 std::ostream&
diff --git a/libstdc++-v3/include/bits/regex_automaton.tcc 
b/libstdc++-v3/include/bits/regex_automaton.tcc
index caaf3c407745..bce378f0f70c 100644
--- a/libstdc++-v3/include/bits/regex_automaton.tcc
+++ b/libstdc++-v3/include/bits/regex_automaton.tcc
@@ -36,34 +36,34 @@ namespace __detail
 {
 #ifdef _GLIBCXX_DEBUG
   inline std::ostream&
-  _State_base::_M_print(std::ostream& ostr) const
+  _State_base::_M_print(std::ostream& __ostr) const
   {
 switch (_M_opcode)
 {
   case _S_opcode_alternative:
   case _S_opcode_repeat:
-   ostr << "alt next=" << _M_next << " alt=" << _M_alt;
+   __ostr << "alt next=" << _M_next << " alt=" << _M_alt;
break;
   case _S_opcode_subexpr_begin:
-   ostr << "subexpr begin next=" << _M_next << " index=" << _M_subexpr;
+   __ostr << "subexpr begin next=" << _M_next << " index=" << _M_subexpr;
break;
   case _S_opcode_subexpr_end:
-   ostr << "subexpr end next=" << _M_next << " index=" << _M_subexpr;
+   __ostr << "subexpr end next=" << _M_next << " index=" << _M_subexpr;
break;
   case _S_opcode_backref:
-   ostr << "backref next=" << _M_next << " index=" << _M_backref_index;
+   __ostr << "backref next=" << _M_next << " index=" << _M_backref_index;
break;
   case _S_opcode_match:
-   ostr << "match next=" << _M_next;
+   __ostr << "match next=" << _M_next;
break;
   case _S_opcode_accept:
-   ostr << "accept next=" << _M_next;
+   __ostr << "accept next=" << _M_next;
break;
   default:
-   ostr << "unknown next=" << _M_next;
+   __ostr << "unknown next=" << _M_next;
break;
 }
-return ostr;
+return __ostr;
   }
 
   // Prints graphviz dot commands for state.
diff --git a/libstdc++-v3/include/bits/regex_scanner.tcc 
b/libstdc++-v3/include/bits/regex_s

[gcc r12-10540] libstdc++: Fix std::__uninitialized_default_n for constant evaluation [PR110542]

2024-06-11 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:874896659df65b4bdf85b3dbca0ab527bb4c920e

commit r12-10540-g874896659df65b4bdf85b3dbca0ab527bb4c920e
Author: Jonathan Wakely 
Date:   Tue Jul 4 16:03:45 2023 +0100

libstdc++: Fix std::__uninitialized_default_n for constant evaluation 
[PR110542]

libstdc++-v3/ChangeLog:

PR libstdc++/110542
* include/bits/stl_uninitialized.h (__uninitialized_default_n):
Do not use std::fill_n during constant evaluation.

(cherry picked from commit 83cae6c4b788544635a71748e1881c150f42efef)

Diff:
---
 libstdc++-v3/include/bits/stl_uninitialized.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h 
b/libstdc++-v3/include/bits/stl_uninitialized.h
index 7ed69f53f7d8..88e003a30335 100644
--- a/libstdc++-v3/include/bits/stl_uninitialized.h
+++ b/libstdc++-v3/include/bits/stl_uninitialized.h
@@ -690,6 +690,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 inline _ForwardIterator
 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
 {
+#ifdef __cpp_lib_is_constant_evaluated
+  if (std::is_constant_evaluated())
+   return __uninitialized_default_n_1::
+__uninit_default_n(__first, __n);
+#endif
+
   typedef typename iterator_traits<_ForwardIterator>::value_type
_ValueType;
   // See uninitialized_fill_n for the conditions for using std::fill_n.


[gcc r12-10539] libstdc++: Adjust expected locale-dependent date formats in tests

2024-06-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:6f0bd7cfb3288b667ab8e8ec18984a67c4238a86

commit r12-10539-g6f0bd7cfb3288b667ab8e8ec18984a67c4238a86
Author: Jonathan Wakely 
Date:   Wed Apr 10 13:24:51 2024 +0100

libstdc++: Adjust expected locale-dependent date formats in tests

The test 27_io/manipulators/extended/get_time/char/2.cc expects that
%a in the de_DE locale is "Di" but on FreeBSD it's "Di." with a trailing
period. Adjust the input string to be "1971 Di." instead of "Di 1971"
and that way if %a doesn't expect the trailing '.' it simply won't
extract it from the stream.

This fixes:
FAIL: 27_io/manipulators/extended/get_time/char/2.cc  -std=gnu++17 
execution test

libstdc++-v3/ChangeLog:

* testsuite/27_io/manipulators/extended/get_time/char/2.cc:
Adjust input string so that it matches %a with or without a
trailing period.

(cherry picked from commit 4decc1062f0f6eb44209d9d5a26a744ffa474648)

Diff:
---
 .../testsuite/27_io/manipulators/extended/get_time/char/2.cc| 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc 
b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc
index d4cd0dc30402..6681b049936b 100644
--- a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc
+++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc
@@ -35,9 +35,9 @@ void test01()
   VERIFY( loc_de != loc_c );
   istringstream iss;
   iss.imbue(loc_de);
-  iss.str("Di 1971");
-  tm time1;
-  iss >> get_time(&time1, "%a %Y");
+  iss.str("1971 Di."); // %a is "Di" on some targets, "Di." on others.
+  tm time1{};
+  iss >> get_time(&time1, "%Y %a");
   VERIFY(time1.tm_wday == 2);
   VERIFY(time1.tm_year == 71);
 }


[gcc r12-10544] libstdc++: Define __cpp_lib_constexpr_algorithms in (LWG 3792)

2024-06-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:3837f956515eb8aff4f933eac83f4c6d1a0f1f48

commit r12-10544-g3837f956515eb8aff4f933eac83f4c6d1a0f1f48
Author: Jonathan Wakely 
Date:   Wed Mar 22 12:55:29 2023 +

libstdc++: Define __cpp_lib_constexpr_algorithms in  (LWG 3792)

We actually defined this macro in  at one point, but I removed
it in r10-7901-g2025db692e9ed1.

libstdc++-v3/ChangeLog:

* include/std/utility (__cpp_lib_constexpr_algorithms): Define,
as per LWG 3792.
* testsuite/20_util/exchange/constexpr.cc: Check for it.

(cherry picked from commit 924d990425d29ef39f3faac49d4a3772e4302c96)

Diff:
---
 libstdc++-v3/include/std/utility | 4 
 libstdc++-v3/testsuite/20_util/exchange/constexpr.cc | 6 ++
 2 files changed, 10 insertions(+)

diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility
index fb618356c414..acc47d649768 100644
--- a/libstdc++-v3/include/std/utility
+++ b/libstdc++-v3/include/std/utility
@@ -86,6 +86,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if __cplusplus >= 201402L
 #define __cpp_lib_exchange_function 201304L
 
+#if __cplusplus > 201703L
+# define __cpp_lib_constexpr_algorithms 201806L
+#endif
+
   /// Assign @p __new_val to @p __obj and return its previous value.
   template 
 _GLIBCXX20_CONSTEXPR
diff --git a/libstdc++-v3/testsuite/20_util/exchange/constexpr.cc 
b/libstdc++-v3/testsuite/20_util/exchange/constexpr.cc
index 7a7ecd35db73..e7dc31ed9866 100644
--- a/libstdc++-v3/testsuite/20_util/exchange/constexpr.cc
+++ b/libstdc++-v3/testsuite/20_util/exchange/constexpr.cc
@@ -20,6 +20,12 @@
 
 #include 
 
+#ifndef __cpp_lib_constexpr_algorithms
+# error "Feature test macro for constexpr std::exchange is missing in 
"
+#elif __cpp_lib_constexpr_algorithms < 201806L
+# error "Feature test macro for constexpr std::exchange has wrong value in 
"
+#endif
+
 constexpr bool
 test()
 {


[gcc r12-10545] libstdc++: Fix fwrite error parameter

2024-06-11 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:870e389a050b2b194614fc961a95c774c18473b7

commit r12-10545-g870e389a050b2b194614fc961a95c774c18473b7
Author: Tianqiang Shuai <1101282...@qq.com>
Date:   Wed Jul 5 17:07:51 2023 +0100

libstdc++: Fix fwrite error parameter

The first parameter of fwrite should be the const char* __s which want
write to FILE *__file, rather than the FILE *__file write to the FILE
*__file.

libstdc++-v3/ChangeLog:

* config/io/basic_file_stdio.cc (xwrite) [USE_STDIO_PURE]: Fix
first argument.

(cherry picked from commit bb4f8f14ed15310b5e01f1c6013585550debdab9)

Diff:
---
 libstdc++-v3/config/io/basic_file_stdio.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc 
b/libstdc++-v3/config/io/basic_file_stdio.cc
index 09fdd750b807..f5aec04750fa 100644
--- a/libstdc++-v3/config/io/basic_file_stdio.cc
+++ b/libstdc++-v3/config/io/basic_file_stdio.cc
@@ -128,7 +128,7 @@ namespace
 for (;;)
   {
 #ifdef _GLIBCXX_USE_STDIO_PURE
-   const std::streamsize __ret = fwrite(__file, 1, __nleft, __file);
+   const std::streamsize __ret = fwrite(__s, 1, __nleft, __file);
 #else
const std::streamsize __ret = write(__fd, __s, __nleft);
 #endif


[gcc r12-10546] PHIOPT: Don't transform minmax if middle bb contains a phi [PR115143]

2024-06-11 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:d30afaae6764379a63c22459b40aaecfa82b0fc4

commit r12-10546-gd30afaae6764379a63c22459b40aaecfa82b0fc4
Author: Andrew Pinski 
Date:   Sat May 18 11:55:58 2024 -0700

PHIOPT: Don't transform minmax if middle bb contains a phi [PR115143]

The problem here is even if last_and_only_stmt returns a statement,
the bb might still contain a phi node which defines a ssa name
which is used in that statement so we need to add a check to make sure
that the phi nodes are empty for the middle bbs in both the
`CMP?MINMAX:MINMAX` case and the `CMP?MINMAX:B` cases.

Bootstrapped and tested on x86_64_linux-gnu with no regressions.

PR tree-optimization/115143

gcc/ChangeLog:

* tree-ssa-phiopt.cc (minmax_replacement): Check for empty
phi nodes for middle bbs for the case where middle bb is not empty.

gcc/testsuite/ChangeLog:

* gcc.c-torture/compile/pr115143-1.c: New test.
* gcc.c-torture/compile/pr115143-2.c: New test.
* gcc.c-torture/compile/pr115143-3.c: New test.

Signed-off-by: Andrew Pinski 
(cherry picked from commit 9ff8f041331ef8b56007fb3c4d41d76f9850010d)

Diff:
---
 gcc/testsuite/gcc.c-torture/compile/pr115143-1.c | 21 +
 gcc/testsuite/gcc.c-torture/compile/pr115143-2.c | 30 
 gcc/testsuite/gcc.c-torture/compile/pr115143-3.c | 29 +++
 gcc/tree-ssa-phiopt.cc   |  4 
 4 files changed, 84 insertions(+)

diff --git a/gcc/testsuite/gcc.c-torture/compile/pr115143-1.c 
b/gcc/testsuite/gcc.c-torture/compile/pr115143-1.c
new file mode 100644
index ..5cb119ea4325
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr115143-1.c
@@ -0,0 +1,21 @@
+/* PR tree-optimization/115143 */
+/* This used to ICE.
+   minmax part of phiopt would transform,
+   would transform `a!=0?min(a, b) : 0` into `min(a,b)`
+   which was correct except b was defined by a phi in the inner
+   bb which was not handled. */
+short a, d;
+char b;
+long c;
+unsigned long e, f;
+void g(unsigned long h) {
+  if (c ? e : b)
+if (e)
+  if (d) {
+a = f ? ({
+  unsigned long i = d ? f : 0, j = e ? h : 0;
+  i < j ? i : j;
+}) : 0;
+  }
+}
+
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr115143-2.c 
b/gcc/testsuite/gcc.c-torture/compile/pr115143-2.c
new file mode 100644
index ..05c3bbe9738e
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr115143-2.c
@@ -0,0 +1,30 @@
+/* { dg-options "-fgimple" } */
+/* PR tree-optimization/115143 */
+/* This used to ICE.
+   minmax part of phiopt would transform,
+   would transform `a!=0?min(a, b) : 0` into `min(a,b)`
+   which was correct except b was defined by a phi in the inner
+   bb which was not handled. */
+unsigned __GIMPLE (ssa,startwith("phiopt"))
+foo (unsigned a, unsigned b)
+{
+  unsigned j;
+  unsigned _23;
+  unsigned _12;
+
+  __BB(2):
+  if (a_6(D) != 0u)
+goto __BB3;
+  else
+goto __BB4;
+
+  __BB(3):
+  j_10 = __PHI (__BB2: b_11(D));
+  _23 = __MIN (a_6(D), j_10);
+  goto __BB4;
+
+  __BB(4):
+  _12 = __PHI (__BB3: _23, __BB2: 0u);
+  return _12;
+
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr115143-3.c 
b/gcc/testsuite/gcc.c-torture/compile/pr115143-3.c
new file mode 100644
index ..53c5fb5588e9
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr115143-3.c
@@ -0,0 +1,29 @@
+/* { dg-options "-fgimple" } */
+/* PR tree-optimization/115143 */
+/* This used to ICE.
+   minmax part of phiopt would transform,
+   would transform `a!=0?min(a, b) : 0` into `min(a,b)`
+   which was correct except b was defined by a phi in the inner
+   bb which was not handled. */
+unsigned __GIMPLE (ssa,startwith("phiopt"))
+foo (unsigned a, unsigned b)
+{
+  unsigned j;
+  unsigned _23;
+  unsigned _12;
+
+  __BB(2):
+  if (a_6(D) > 0u)
+goto __BB3;
+  else
+goto __BB4;
+
+  __BB(3):
+  j_10 = __PHI (__BB2: b_7(D));
+  _23 = __MIN (a_6(D), j_10);
+  goto __BB4;
+
+  __BB(4):
+  _12 = __PHI (__BB3: _23, __BB2: 0u);
+  return _12;
+}
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index e2dba56383b4..558d5b4b57db 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -1973,6 +1973,10 @@ minmax_replacement (basic_block cond_bb, basic_block 
middle_bb,
  || gimple_code (assign) != GIMPLE_ASSIGN)
return false;
 
+  /* There cannot be any phi nodes in the middle bb. */
+  if (!gimple_seq_empty_p (phi_nodes (middle_bb)))
+   return false;
+
   lhs = gimple_assign_lhs (assign);
   ass_code = gimple_assign_rhs_code (assign);
   if (ass_code != MAX_EXPR && ass_code != MIN_EXPR)


[gcc r12-10547] libcc1: fix include

2024-06-11 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:8f11ed1c58e14421ba4be1652764fc47fdce8dc7

commit r12-10547-g8f11ed1c58e14421ba4be1652764fc47fdce8dc7
Author: Francois-Xavier Coudert 
Date:   Sat Mar 16 09:50:00 2024 +0100

libcc1: fix  include

Use INCLUDE_VECTOR before including system.h, instead of directly
including , to avoid running into poisoned identifiers.

Signed-off-by: Dimitry Andric 

PR middle-end/111632

libcc1/ChangeLog:

* libcc1plugin.cc: Fix include.
* libcp1plugin.cc: Fix include.

(cherry picked from commit 5213047b1d50af63dfabb5e5649821a6cb157e33)

Diff:
---
 libcc1/libcc1plugin.cc | 3 +--
 libcc1/libcp1plugin.cc | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc
index bdd0bdabe77f..8d96667e33bd 100644
--- a/libcc1/libcc1plugin.cc
+++ b/libcc1/libcc1plugin.cc
@@ -32,6 +32,7 @@
 #undef PACKAGE_VERSION
 
 #define INCLUDE_MEMORY
+#define INCLUDE_VECTOR
 #include "gcc-plugin.h"
 #include "system.h"
 #include "coretypes.h"
@@ -69,8 +70,6 @@
 #include "gcc-c-interface.h"
 #include "context.hh"
 
-#include 
-
 using namespace cc1_plugin;
 
 
diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index e2d5039a0a1f..6c93e9121343 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -33,6 +33,7 @@
 #undef PACKAGE_VERSION
 
 #define INCLUDE_MEMORY
+#define INCLUDE_VECTOR
 #include "gcc-plugin.h"
 #include "system.h"
 #include "coretypes.h"
@@ -71,8 +72,6 @@
 #include "rpc.hh"
 #include "context.hh"
 
-#include 
-
 using namespace cc1_plugin;


[gcc r12-10548] Include safe-ctype.h after C++ standard headers, to avoid over-poisoning

2024-06-11 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:a995fded34fe488153b06bb41e026277f01efded

commit r12-10548-ga995fded34fe488153b06bb41e026277f01efded
Author: Francois-Xavier Coudert 
Date:   Thu Mar 7 14:36:03 2024 +0100

Include safe-ctype.h after C++ standard headers, to avoid over-poisoning

When building gcc's C++ sources against recent libc++, the poisoning of
the ctype macros due to including safe-ctype.h before including C++
standard headers such as , , etc, causes many compilation
errors, similar to:

  In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23:
  In file included from /home/dim/src/gcc/master/gcc/system.h:233:
  In file included from /usr/include/c++/v1/vector:321:
  In file included from
  /usr/include/c++/v1/__format/formatter_bool.h:20:
  In file included from
  /usr/include/c++/v1/__format/formatter_integral.h:32:
  In file included from /usr/include/c++/v1/locale:202:
  /usr/include/c++/v1/__locale:546:5: error: '__abi_tag__' attribute
  only applies to structs, variables, functions, and namespaces
546 | _LIBCPP_INLINE_VISIBILITY
| ^
  /usr/include/c++/v1/__config:813:37: note: expanded from macro
  '_LIBCPP_INLINE_VISIBILITY'
813 | #  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
| ^
  /usr/include/c++/v1/__config:792:26: note: expanded from macro
  '_LIBCPP_HIDE_FROM_ABI'
792 |
__attribute__((__abi_tag__(_LIBCPP_TOSTRING(
  _LIBCPP_VERSIONED_IDENTIFIER
|  ^
  In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23:
  In file included from /home/dim/src/gcc/master/gcc/system.h:233:
  In file included from /usr/include/c++/v1/vector:321:
  In file included from
  /usr/include/c++/v1/__format/formatter_bool.h:20:
  In file included from
  /usr/include/c++/v1/__format/formatter_integral.h:32:
  In file included from /usr/include/c++/v1/locale:202:
  /usr/include/c++/v1/__locale:547:37: error: expected ';' at end of
  declaration list
547 | char_type toupper(char_type __c) const
| ^
  /usr/include/c++/v1/__locale:553:48: error: too many arguments
  provided to function-like macro invocation
553 | const char_type* toupper(char_type* __low, const
char_type* __high) const
|^
  /home/dim/src/gcc/master/gcc/../include/safe-ctype.h:146:9: note:
  macro 'toupper' defined here
146 | #define toupper(c) do_not_use_toupper_with_safe_ctype
| ^

This is because libc++ uses different transitive includes than
libstdc++, and some of those transitive includes pull in various ctype
declarations (typically via ).

There was already a special case for including  before
safe-ctype.h, so move the rest of the C++ standard header includes to
the same location, to fix the problem.

PR middle-end/111632

gcc/ChangeLog:

* system.h: Include safe-ctype.h after C++ standard headers.

Signed-off-by: Dimitry Andric 
(cherry picked from commit 9970b576b7e4ae337af1268395ff221348c4b34a)

Diff:
---
 gcc/system.h | 39 ++-
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/gcc/system.h b/gcc/system.h
index e10c34f70eca..38733dd81a6e 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -194,27 +194,8 @@ extern int fprintf_unlocked (FILE *, const char *, ...);
 #undef fread_unlocked
 #undef fwrite_unlocked
 
-/* Include  before "safe-ctype.h" to avoid GCC poisoning
-   the ctype macros through safe-ctype.h */
-
-#ifdef __cplusplus
-#ifdef INCLUDE_STRING
-# include 
-#endif
-#endif
-
-/* There are an extraordinary number of issues with .
-   The last straw is that it varies with the locale.  Use libiberty's
-   replacement instead.  */
-#include "safe-ctype.h"
-
-#include 
-
-#include 
-
-#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
-extern int errno;
-#endif
+/* Include C++ standard headers before "safe-ctype.h" to avoid GCC
+   poisoning the ctype macros through safe-ctype.h */
 
 #ifdef __cplusplus
 #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY)
@@ -229,6 +210,9 @@ extern int errno;
 #ifdef INCLUDE_SET
 # include 
 #endif
+#ifdef INCLUDE_STRING
+# include 
+#endif
 #ifdef INCLUDE_VECTOR
 # include 
 #endif
@@ -245,6 +229,19 @@ extern int errno;
 # include 
 #endif
 
+/* There are an extraordinary number of issues with .
+   The last straw is that it varies with the locale.  Use libiberty's
+   replacement instead.  */
+#include "safe-ctype.h"
+
+#include 
+
+#include 
+
+#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
+extern int errno;
+#endif
+
 /* Some of glibc's string inl

[gcc r15-1187] vect: Merge loop mask and cond_op mask in fold-left reduction [PR115382].

2024-06-11 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:2b438a0d2aa80f051a09b245a58f643540d4004b

commit r15-1187-g2b438a0d2aa80f051a09b245a58f643540d4004b
Author: Robin Dapp 
Date:   Fri Jun 7 14:36:41 2024 +0200

vect: Merge loop mask and cond_op mask in fold-left reduction [PR115382].

Currently we discard the cond-op mask when the loop is fully masked
which causes wrong code in
gcc.dg/vect/vect-cond-reduc-in-order-2-signed-zero.c
when compiled with
-O3 -march=cascadelake --param vect-partial-vector-usage=2.

This patch ANDs both masks.

gcc/ChangeLog:

PR tree-optimization/115382

* tree-vect-loop.cc (vectorize_fold_left_reduction): Use
prepare_vec_mask.
* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
Remove static of prepare_vec_mask.
* tree-vectorizer.h (prepare_vec_mask): Export.

Diff:
---
 gcc/tree-vect-loop.cc  | 10 +-
 gcc/tree-vect-stmts.cc |  2 +-
 gcc/tree-vectorizer.h  |  3 +++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index c471f1564a72..5b1ad06eca66 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7204,7 +7204,15 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo,
   tree len = NULL_TREE;
   tree bias = NULL_TREE;
   if (LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
-   mask = vect_get_loop_mask (loop_vinfo, gsi, masks, vec_num, vectype_in, 
i);
+   {
+ tree loop_mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
+  vec_num, vectype_in, i);
+ if (is_cond_op)
+   mask = prepare_vec_mask (loop_vinfo, TREE_TYPE (loop_mask),
+loop_mask, vec_opmask[i], gsi);
+ else
+   mask = loop_mask;
+   }
   else if (is_cond_op)
mask = vec_opmask[i];
   if (LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo))
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 05a169ecb2dd..831f18253765 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -1643,7 +1643,7 @@ check_load_store_for_partial_vectors (loop_vec_info 
loop_vinfo, tree vectype,
MASK_TYPE is the type of both masks.  If new statements are needed,
insert them before GSI.  */
 
-static tree
+tree
 prepare_vec_mask (loop_vec_info loop_vinfo, tree mask_type, tree loop_mask,
  tree vec_mask, gimple_stmt_iterator *gsi)
 {
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 97ec9c341e7d..6bb0f5c3a56f 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -2508,6 +2508,9 @@ extern void vect_free_slp_tree (slp_tree);
 extern bool compatible_calls_p (gcall *, gcall *);
 extern int vect_slp_child_index_for_operand (const gimple *, int op, bool);
 
+extern tree prepare_vec_mask (loop_vec_info, tree, tree, tree,
+ gimple_stmt_iterator *);
+
 /* In tree-vect-patterns.cc.  */
 extern void
 vect_mark_pattern_stmts (vec_info *, stmt_vec_info, gimple *, tree);


[gcc r15-1188] Fix building JIT with musl libc [PR115442]

2024-06-11 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:e4244b88d75124f6957bfa080c8ad34017364e53

commit r15-1188-ge4244b88d75124f6957bfa080c8ad34017364e53
Author: Andrew Pinski 
Date:   Tue Jun 11 12:30:01 2024 -0700

Fix building JIT with musl libc [PR115442]

Just like r13-6662-g0e6f87835ccabf but this time for jit/jit-recording.cc.

Pushed as obvious after a quick build to make sure jit still builds.

gcc/jit/ChangeLog:

PR jit/115442
* jit-recording.cc: Define INCLUDE_SSTREAM before including
system.h and don't directly incldue sstream.

Signed-off-by: Andrew Pinski 

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

diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 68a2e860c1fb..70830e349653 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 .  */
 
 #include "config.h"
+#define INCLUDE_SSTREAM
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
@@ -29,7 +30,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "jit-builtins.h"
 #include "jit-recording.h"
 #include "jit-playback.h"
-#include 
 
 namespace gcc {
 namespace jit {


[gcc r14-10304] Fix building JIT with musl libc [PR115442]

2024-06-11 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:e6b1c0820590a1f330099ed7560982b5c6da4e91

commit r14-10304-ge6b1c0820590a1f330099ed7560982b5c6da4e91
Author: Andrew Pinski 
Date:   Tue Jun 11 12:30:01 2024 -0700

Fix building JIT with musl libc [PR115442]

Just like r13-6662-g0e6f87835ccabf but this time for jit/jit-recording.cc.

Pushed as obvious after a quick build to make sure jit still builds.

gcc/jit/ChangeLog:

PR jit/115442
* jit-recording.cc: Define INCLUDE_SSTREAM before including
system.h and don't directly incldue sstream.

Signed-off-by: Andrew Pinski 
(cherry picked from commit e4244b88d75124f6957bfa080c8ad34017364e53)

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

diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 68a2e860c1fb..70830e349653 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 .  */
 
 #include "config.h"
+#define INCLUDE_SSTREAM
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
@@ -29,7 +30,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "jit-builtins.h"
 #include "jit-recording.h"
 #include "jit-playback.h"
-#include 
 
 namespace gcc {
 namespace jit {


[gcc r13-8842] Fix building JIT with musl libc [PR115442]

2024-06-11 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:6eb0e931097a8fec01591051c9ef582d52fe7f0c

commit r13-8842-g6eb0e931097a8fec01591051c9ef582d52fe7f0c
Author: Andrew Pinski 
Date:   Tue Jun 11 12:30:01 2024 -0700

Fix building JIT with musl libc [PR115442]

Just like r13-6662-g0e6f87835ccabf but this time for jit/jit-recording.cc.

Pushed as obvious after a quick build to make sure jit still builds.

gcc/jit/ChangeLog:

PR jit/115442
* jit-recording.cc: Define INCLUDE_SSTREAM before including
system.h and don't directly incldue sstream.

Signed-off-by: Andrew Pinski 
(cherry picked from commit e4244b88d75124f6957bfa080c8ad34017364e53)

Diff:
---
 gcc/jit/jit-recording.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index cf734cf7ef5f..914082ae861e 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 .  */
 
 #include "config.h"
+#define INCLUDE_SSTREAM
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"


[gcc r15-1189] doc: Remove redundant introduction of x86-64

2024-06-11 Thread Gerald Pfeifer via Gcc-cvs
https://gcc.gnu.org/g:6bc26cceb243c6f359f65a1afa5515f911f3327d

commit r15-1189-g6bc26cceb243c6f359f65a1afa5515f911f3327d
Author: Gerald Pfeifer 
Date:   Wed Jun 12 00:04:09 2024 +0200

doc: Remove redundant introduction of x86-64

The same sentence as in the x86_64-*-solaris2* section is in the
x86_64-*-* section directly above.

gcc:
PR target/69374
* doc/install.texi (Specific) : Remove
redundant introduction of x86-64.

Diff:
---
 gcc/doc/install.texi | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 2addafd24657..bc70318c0878 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -5104,8 +5104,6 @@ both 64-bit x86-64 and 32-bit x86 code (via the 
@option{-m32} switch).
 @end html
 @anchor{x86-64-x-solaris2}
 @heading x86_64-*-solaris2*
-GCC also supports the x86-64 architecture implemented by the AMD64
-processor (@samp{amd64-*-*} is an alias for @samp{x86_64-*-*}).
 Unlike other systems, without special options a
 bi-arch compiler is built which generates 32-bit code by default, but
 can generate 64-bit x86-64 code with the @option{-m64} switch.  Since


[gcc(refs/users/meissner/heads/work168-tar)] Add -mlrspr.

2024-06-11 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:1232a584429302448e9ff8dee30e92901b37870a

commit 1232a584429302448e9ff8dee30e92901b37870a
Author: Michael Meissner 
Date:   Tue Jun 11 18:23:32 2024 -0400

Add -mlrspr.

2024-06-11  Michael Meissner  

gcc/

* config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
support for -mlrspr.
* config/rs6000/rs6000.opt (-mlrspr): New debug option.

Diff:
---
 gcc/config/rs6000/rs6000.cc  | 4 +++-
 gcc/config/rs6000/rs6000.opt | 4 
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 70214e4b28c5..3e118c866081 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1949,7 +1949,9 @@ rs6000_hard_regno_mode_ok_uncached (int regno, 
machine_mode mode)
   return (!orig_complex_p && mode == SImode);
 
 case LR_REGNO:
-  return (!orig_complex_p && mode == Pmode);
+  if (!TARGET_LRSPR)
+   return (!orig_complex_p && mode == Pmode);
+  /* fall through.  */
 
 case CTR_REGNO:
 case TAR_REGNO:
diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt
index 27f873972b57..137290b8364f 100644
--- a/gcc/config/rs6000/rs6000.opt
+++ b/gcc/config/rs6000/rs6000.opt
@@ -658,6 +658,10 @@ mdfspr
 Target Undocumented Var(TARGET_DFSPR) Init(0)
 Allow (do not allow) 64-bit floating point to be in the CTR or TAR registers.
 
+mlrspr
+Target Undocumented Var(TARGET_LRSPR) Init(0)
+Treat (do not treat) the LR register like CTR/TAR in terms of what modes it 
can hold.
+
 ; Documented parameters
 
 -param=rs6000-vect-unroll-limit=


[gcc(refs/users/meissner/heads/work168-tar)] Update ChangeLog.*

2024-06-11 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:aca81acacb06caf3031674541bd83bd6a70776ac

commit aca81acacb06caf3031674541bd83bd6a70776ac
Author: Michael Meissner 
Date:   Tue Jun 11 18:24:20 2024 -0400

Update ChangeLog.*

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

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
index ec645be708f2..e1609221b2c7 100644
--- a/gcc/ChangeLog.tar
+++ b/gcc/ChangeLog.tar
@@ -1,3 +1,15 @@
+ Branch work168-tar, patch #203 
+
+Add -mlrspr.
+
+2024-06-11  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
+   support for -mlrspr.
+   * config/rs6000/rs6000.opt (-mlrspr): New debug option.
+
  Branch work168-tar, patch #202 
 
 Add options for modes in SPR registers.


[gcc r15-1190] c: Add -std=c2y, -std=gnu2y, -Wc23-c2y-compat, C2Y _Generic with type operand

2024-06-11 Thread Joseph Myers via Gcc-cvs
https://gcc.gnu.org/g:0cf68222d2df3af7fefad28a82fcd51d8b40a192

commit r15-1190-g0cf68222d2df3af7fefad28a82fcd51d8b40a192
Author: Joseph Myers 
Date:   Tue Jun 11 23:00:04 2024 +

c: Add -std=c2y, -std=gnu2y, -Wc23-c2y-compat, C2Y _Generic with type 
operand

The first new C2Y feature, _Generic where the controlling operand is a
type name rather than an expression (as defined in N3260), was voted
into C2Y today.  (In particular, this form of _Generic allows
distinguishing qualified and unqualified versions of a type.)  This
feature also includes allowing the generic associations to specify
incomplete and function types.

Add this feature to GCC, along with the -std=c2y, -std=gnu2y and
-Wc23-c2y-compat options to control when and how it is diagnosed.  As
usual, the feature is allowed by default in older standards modes,
subject to diagnosis with -pedantic, -pedantic-errors or
-Wc23-c2y-compat.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.

gcc/
* doc/cpp.texi (__STDC_VERSION__): Document C2Y handling.
* doc/invoke.texi (-Wc23-c2y-compat, -std=c2y, -std=gnu2y):
Document options.
(-std=gnu23): Update documentation.
* doc/standards.texi (C Language): Document C2Y.  Update C23
description.
* config/rl78/rl78.cc (rl78_option_override): Handle "GNU C2Y"
language name.
* dwarf2out.cc (highest_c_language, gen_compile_unit_die):
Likewise.

gcc/c-family/
* c-common.cc (flag_isoc2y): New.
(flag_isoc99, flag_isoc11, flag_isoc23): Update comments.
* c-common.h (flag_isoc2y): New.
(clk_c, flag_isoc23): Update comments.
* c-opts.cc (set_std_c2y): New.
(c_common_handle_option): Handle OPT_std_c2y and OPT_std_gnu2y.
(set_std_c89, set_std_c99, set_std_c11, set_std_c17, set_std_c23):
Set flag_isoc2y.
(set_std_c23): Update comment.
* c.opt (Wc23-c2y-compat, std=c2y, std=gnu2y): New.
* c.opt.urls: Regenerate.

gcc/c/
* c-errors.cc (pedwarn_c23): New.
* c-parser.cc (disable_extension_diagnostics)
(restore_extension_diagnostics): Save and restore
warn_c23_c2y_compat.
(c_parser_generic_selection): Handle type name as controlling
operand.  Allow incomplete and function types subject to
pedwarn_c23 calls.
* c-tree.h (pedwarn_c23): New.

gcc/testsuite/
* gcc.dg/c23-generic-1.c, gcc.dg/c23-generic-2.c,
gcc.dg/c23-generic-3.c, gcc.dg/c23-generic-4.c,
gcc.dg/c2y-generic-1.c, gcc.dg/c2y-generic-2.c,
gcc.dg/c2y-generic-3.c, gcc.dg/gnu2y-generic-1.c: New tests.
* gcc.dg/c23-tag-6.c: Use -pedantic-errors.

libcpp/
* include/cpplib.h (CLK_GNUC2Y, CLK_STDC2Y): New.
* init.cc (lang_defaults): Add GNUC2Y and STDC2Y entries.
(cpp_init_builtins): Define __STDC_VERSION__ to 202500L for GNUC2Y
and STDC2Y.

Diff:
---
 gcc/c-family/c-common.cc   | 10 +++--
 gcc/c-family/c-common.h|  8 +++-
 gcc/c-family/c-opts.cc | 34 +-
 gcc/c-family/c.opt | 12 +
 gcc/c-family/c.opt.urls|  3 ++
 gcc/c/c-errors.cc  | 39 
 gcc/c/c-parser.cc  | 82 ++
 gcc/c/c-tree.h |  2 +
 gcc/config/rl78/rl78.cc|  1 +
 gcc/doc/cpp.texi   |  4 +-
 gcc/doc/invoke.texi| 23 +-
 gcc/doc/standards.texi |  8 +++-
 gcc/dwarf2out.cc   |  5 ++-
 gcc/testsuite/gcc.dg/c23-generic-1.c   | 17 +++
 gcc/testsuite/gcc.dg/c23-generic-2.c   | 17 +++
 gcc/testsuite/gcc.dg/c23-generic-3.c   | 16 +++
 gcc/testsuite/gcc.dg/c23-generic-4.c   | 16 +++
 gcc/testsuite/gcc.dg/c23-tag-6.c   |  2 +-
 gcc/testsuite/gcc.dg/c2y-generic-1.c   | 15 +++
 gcc/testsuite/gcc.dg/c2y-generic-2.c   | 17 +++
 gcc/testsuite/gcc.dg/c2y-generic-3.c   |  9 
 gcc/testsuite/gcc.dg/gnu2y-generic-1.c | 15 +++
 libcpp/include/cpplib.h|  3 +-
 libcpp/init.cc |  5 +++
 24 files changed, 323 insertions(+), 40 deletions(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 0341c44a2cd9..24335deeb582 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -216,18 +216,22 @@ int flag_cond_mismatch;
 
 int flag_isoc94;
 
-/* Nonzero means use the ISO C99 (or C11) dialect of C.  */
+/* Nonzero means use the ISO C99 (or later) dialect of C.  */
 
 int flag_isoc99;
 
-/* Nonzero means use the ISO C11 dialect of C.  */
+/* Nonzero means use the ISO C11 (or later) dial

[gcc/aoliva/heads/testbase] (9 commits) Fix fold-left reduction vectorization with multiple stmt co

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testbase' was updated to point to:

 dd6f942c2665... Fix fold-left reduction vectorization with multiple stmt co

It previously pointed to:

 b24f2954dbc1... Add additional option --param max-completely-peeled-insns=2

Diff:

Summary of changes (added commits):
---

  dd6f942... Fix fold-left reduction vectorization with multiple stmt co (*)
  9499756... libstdc++: Optimize std::to_address (*)
  e4f1c1b... fixincludes: bypass some fixes for recent darwin headers (*)
  c319075... Add finalizer creation to array constructor for functions o (*)
  a47b1aa... bitint: Fix up lower_addsub_overflow [PR115352] (*)
  9fff0be... go: Fix gccgo -v on Solaris with ld (*)
  9ab90fc... testsuite: go: Require split-stack support for go.test/test (*)
  51046e4... Fix returned type to be allocatable for user-functions. (*)
  3472b57... enable adjustment of return_pc debug attrs (*)

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


[gcc/aoliva/heads/testme] (13 commits) map packed field type to unpacked for debug info

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 e8eff7b6ed77... map packed field type to unpacked for debug info

It previously pointed to:

 c3e23e85d8a3... [libstdc++] drop workaround for clang<=7

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  c3e23e8... [libstdc++] drop workaround for clang<=7
  81cb861... [testsuite] [arm] test board cflags in multilib.exp


Summary of changes (added commits):
---

  e8eff7b... map packed field type to unpacked for debug info
  bed2675... [libstdc++] [testsuite] require cmath for c++23 cmath tests
  1c784e7... [libstdc++] [testsuite] xfail double-prec from_chars for fl
  b6a9deb... [libstdc++] drop workaround for clang<=7 (*)
  dd6f942... Fix fold-left reduction vectorization with multiple stmt co (*)
  9499756... libstdc++: Optimize std::to_address (*)
  e4f1c1b... fixincludes: bypass some fixes for recent darwin headers (*)
  c319075... Add finalizer creation to array constructor for functions o (*)
  a47b1aa... bitint: Fix up lower_addsub_overflow [PR115352] (*)
  9fff0be... go: Fix gccgo -v on Solaris with ld (*)
  9ab90fc... testsuite: go: Require split-stack support for go.test/test (*)
  51046e4... Fix returned type to be allocatable for user-functions. (*)
  3472b57... enable adjustment of return_pc debug attrs (*)

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


[gcc(refs/users/aoliva/heads/testme)] [libstdc++] [testsuite] xfail double-prec from_chars for float128_t

2024-06-11 Thread Alexandre Oliva via Libstdc++-cvs
https://gcc.gnu.org/g:1c784e7ac556b71f5771c6112b319dad2bcb8c4c

commit 1c784e7ac556b71f5771c6112b319dad2bcb8c4c
Author: Alexandre Oliva 
Date:   Sat Jun 8 09:42:55 2024 -0300

[libstdc++] [testsuite] xfail double-prec from_chars for float128_t

Tests involving float128_t were xfailed or otherwise worked around for
vxworks on aarch64.  The same issue came up on rtems.  This patch
adjusts them similarly.


for  libstdc++-v3/ChangeLog

* testsuite/20_util/from_chars/8.cc: Skip float128_t testing
on aarch64-rtems*.
* testsuite/20_util/to_chars/float128_c++23.cc: Xfail run on
aarch64-rtems*.

Diff:
---
 libstdc++-v3/testsuite/20_util/from_chars/8.cc| 2 +-
 libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/20_util/from_chars/8.cc 
b/libstdc++-v3/testsuite/20_util/from_chars/8.cc
index a6343422c5a9..bacad89943b5 100644
--- a/libstdc++-v3/testsuite/20_util/from_chars/8.cc
+++ b/libstdc++-v3/testsuite/20_util/from_chars/8.cc
@@ -17,7 +17,7 @@
 
 // { dg-do run { target c++23 } }
 // { dg-add-options ieee }
-// { dg-additional-options "-DSKIP_LONG_DOUBLE" { target aarch64-*-vxworks* } }
+// { dg-additional-options "-DSKIP_LONG_DOUBLE" { target aarch64-*-vxworks* 
aarch64-*-rtems* } }
 
 #include 
 #include 
diff --git a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc 
b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
index ca00761ee7c9..6cb9cadcd204 100644
--- a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
+++ b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
@@ -19,7 +19,7 @@
 // { dg-require-effective-target ieee_floats }
 // { dg-require-effective-target size32plus }
 // { dg-add-options ieee }
-// { dg-xfail-run-if "from_chars limited to double-precision" { 
aarch64-*-vxworks* } }
+// { dg-xfail-run-if "from_chars limited to double-precision" { 
aarch64-*-vxworks* aarch64-*-rtems* } }
 
 #include 
 #include 


[gcc(refs/users/aoliva/heads/testme)] [libstdc++] [testsuite] require cmath for c++23 cmath tests

2024-06-11 Thread Alexandre Oliva via Libstdc++-cvs
https://gcc.gnu.org/g:bed26758b722c27f22be833546b0ef9a9793dfe2

commit bed26758b722c27f22be833546b0ef9a9793dfe2
Author: Alexandre Oliva 
Date:   Tue Jun 11 20:25:33 2024 -0300

[libstdc++] [testsuite] require cmath for c++23 cmath tests

Some c++23 tests fail on targets that don't satisfy dg-require-cmath,
because referenced math functions don't get declared in std.  Add the
missing requirement.


for  libstdc++-v3/ChangeLog

* testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc:
Require cmath.
* testsuite/26_numerics/headers/cmath/functions_std_c++23.cc:
Likewise.
* testsuite/26_numerics/headers/cmath/nextafter_std_c++23.cc:
Likewise.

Diff:
---
 libstdc++-v3/testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc | 1 +
 libstdc++-v3/testsuite/26_numerics/headers/cmath/functions_std_c++23.cc | 1 +
 libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc | 1 +
 3 files changed, 3 insertions(+)

diff --git 
a/libstdc++-v3/testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc 
b/libstdc++-v3/testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc
index 0e3d112fe2e8..3c2377fd6987 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-do link { target c++23 } }
+// { dg-require-cmath "" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/26_numerics/headers/cmath/functions_std_c++23.cc 
b/libstdc++-v3/testsuite/26_numerics/headers/cmath/functions_std_c++23.cc
index 000cebf364aa..ea68ac5da755 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/cmath/functions_std_c++23.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/functions_std_c++23.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-do link { target c++23 } }
+// { dg-require-cmath "" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc 
b/libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc
index 7d7e10bd8aea..91767d22cc3f 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-do run { target c++23 } }
+// { dg-require-cmath "" }
 
 #include 
 #include 


[gcc(refs/users/aoliva/heads/testme)] map packed field type to unpacked for debug info

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:e8eff7b6ed77dc74bfb4c042d7acdb3963848409

commit e8eff7b6ed77dc74bfb4c042d7acdb3963848409
Author: Alexandre Oliva 
Date:   Tue Jun 11 20:30:30 2024 -0300

map packed field type to unpacked for debug info

We create a distinct type for each field in a packed record with a
gnu_size, but there is no distinct debug information for them.  Use
the same unpacked type for debug information.


for  gcc/ada/ChangeLog

* gcc-interfacedecl.cc (gnat_to_gnu_field): Use unpacked type
as the debug type for packed fields.

for  gcc/testsuite

* gnat.dg/bias1.adb: Count occurrences of -7.*DW_AT_GNU_bias.

Diff:
---
 gcc/ada/gcc-interface/decl.cc   | 4 
 gcc/testsuite/gnat.dg/bias1.adb | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 8b72c96c4396..e97ff64a4805 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -7786,6 +7786,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree 
gnu_record_type, int packed,
   /* If a size is specified, adjust the field's type to it.  */
   if (gnu_size)
 {
+  tree debug_field_type = gnu_field_type;
   tree orig_field_type;
 
   /* If the field's type is justified modular, we would need to remove
@@ -7844,6 +7845,9 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree 
gnu_record_type, int packed,
  && !DECL_P (TYPE_NAME (gnu_field_type)))
create_type_decl (TYPE_NAME (gnu_field_type), gnu_field_type, true,
  debug_info_p, gnat_field);
+
+  if (debug_info_p && gnu_field_type != debug_field_type)
+   SET_TYPE_DEBUG_TYPE (gnu_field_type, debug_field_type);
 }
 
   /* Otherwise (or if there was an error), don't specify a position.  */
diff --git a/gcc/testsuite/gnat.dg/bias1.adb b/gcc/testsuite/gnat.dg/bias1.adb
index 016a159b692d..d9a00a1aa458 100644
--- a/gcc/testsuite/gnat.dg/bias1.adb
+++ b/gcc/testsuite/gnat.dg/bias1.adb
@@ -1,6 +1,7 @@
 --  { dg-do compile }
 --  { dg-options "-cargs -g -dA -gnatws -fgnat-encodings=gdb -margs" }
 --  { dg-final { scan-assembler "DW_AT_GNU_bias" } }
+--  { dg-final { scan-assembler-times "-7.*DW_AT_GNU_bias" 1 } }
 
 procedure Bias1 is
type Small is range -7 .. -4;
@@ -31,4 +32,4 @@ procedure Bias1 is
 
 begin
null;
-end Bias1;
\ No newline at end of file
+end Bias1;


[gcc r15-1191] Fix ICE in rtl check due to CONST_WIDE_INT in CONST_VECTOR_DUPLICATE_P

2024-06-11 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:1d496d2cd1d5d8751a1637abca89339d6f9ddd3b

commit r15-1191-g1d496d2cd1d5d8751a1637abca89339d6f9ddd3b
Author: liuhongt 
Date:   Tue Jun 11 10:23:27 2024 +0800

Fix ICE in rtl check due to CONST_WIDE_INT in CONST_VECTOR_DUPLICATE_P

The patch add extra check to make sure the component of CONST_VECTOR
is CONST_INT_P.

gcc/ChangeLog:

PR target/115384
* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
Only do the simplification of (AND (ASHIFTRT A imm) mask)
to (LSHIFTRT A imm) when the component of const_vector is
CONST_INT_P.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/simplify-rtx.cc  |  6 --
 gcc/testsuite/gcc.target/i386/pr115384.c | 12 
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 9bc3ef9ad9fd..3ee95f74d3db 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -4072,9 +4072,11 @@ simplify_context::simplify_binary_operation_1 (rtx_code 
code,
   if (VECTOR_MODE_P (mode) && GET_CODE (op0) == ASHIFTRT
  && (CONST_INT_P (XEXP (op0, 1))
  || (GET_CODE (XEXP (op0, 1)) == CONST_VECTOR
- && CONST_VECTOR_DUPLICATE_P (XEXP (op0, 1
+ && CONST_VECTOR_DUPLICATE_P (XEXP (op0, 1))
+ && CONST_INT_P (XVECEXP (XEXP (op0, 1), 0, 0
  && GET_CODE (op1) == CONST_VECTOR
- && CONST_VECTOR_DUPLICATE_P (op1))
+ && CONST_VECTOR_DUPLICATE_P (op1)
+ && CONST_INT_P (XVECEXP (op1, 0, 0)))
{
  unsigned HOST_WIDE_INT shift_count
= (CONST_INT_P (XEXP (op0, 1))
diff --git a/gcc/testsuite/gcc.target/i386/pr115384.c 
b/gcc/testsuite/gcc.target/i386/pr115384.c
new file mode 100644
index ..31dd6f4eb18a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115384.c
@@ -0,0 +1,12 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O" } */
+
+typedef __attribute__((__vector_size__(sizeof(__int128 __int128 W;
+
+W w;
+
+void
+foo()
+{
+  w = w >> 4 & 18446744073709551600llu;
+}


[gcc(refs/users/aoliva/heads/testme)] [testsuite] add linkonly to dg-additional-sources [PR115295]

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:d0e0c26b2a3211ca0e1d945b4745c580d8f65f33

commit d0e0c26b2a3211ca0e1d945b4745c580d8f65f33
Author: Alexandre Oliva 
Date:   Tue Jun 11 21:44:55 2024 -0300

[testsuite] add linkonly to dg-additional-sources [PR115295]

Diff:
---
 gcc/doc/sourcebuild.texi |  9 +
 gcc/testsuite/g++.dg/vect/pr95401.cc |  2 +-
 gcc/testsuite/lib/gcc-defs.exp   | 36 
 3 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index e997dbec3334..08c178db674c 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1320,15 +1320,16 @@ to @var{var_value} before execution of the program 
created by the test.
 Specify additional files, other than source files, that must be copied
 to the system where the compiler runs.
 
-@item @{ dg-additional-sources "@var{filelist}" [@{ target @var{selector} @}] 
@}
+@item @{ dg-additional-sources "@var{filelist}" [@{ \[linkonly\] \[target 
@var{selector}\] @}] @}
 Specify additional source files to appear in the compile line
 following the main test file.
 If the directive includes the optional @samp{@{ @var{selector} @}}
 then the additional sources are only added if the target system
 matches the @var{selector}.
-Additional sources are generally used only in @samp{link} and @samp{run}
-tests; they are reported as unsupported and discarded in other kinds of
-tests that direct the compiler to output to a single file.
+If @samp{linkonly} is specified, additional sources are used only in
+@samp{link} and @samp{run} tests; they are reported as unsupported and
+discarded in other kinds of tests that direct the compiler to output to
+a single file.
 @end table
 
 @subsubsection Add checks at the end of a test
diff --git a/gcc/testsuite/g++.dg/vect/pr95401.cc 
b/gcc/testsuite/g++.dg/vect/pr95401.cc
index 6a56dab09572..8b1be4f24252 100644
--- a/gcc/testsuite/g++.dg/vect/pr95401.cc
+++ b/gcc/testsuite/g++.dg/vect/pr95401.cc
@@ -1,5 +1,5 @@
 // { dg-additional-options "-mavx2 -O3" { target avx2_runtime } }
-// { dg-additional-sources pr95401a.cc }
+// { dg-additional-sources pr95401a.cc linkonly }
 
 extern int var_9;
 extern unsigned var_14;
diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.exp
index cdca4c254d6e..324a90981e43 100644
--- a/gcc/testsuite/lib/gcc-defs.exp
+++ b/gcc/testsuite/lib/gcc-defs.exp
@@ -303,6 +303,7 @@ proc dg-additional-options { args } {
 # main source file.
 
 set additional_sources ""
+set additional_sources_omit_on_compile ""
 set additional_sources_used ""
 
 proc dg-additional-sources { args } {
@@ -313,8 +314,14 @@ proc dg-additional-sources { args } {
return
 }
 
-if { [llength $args] >= 3 } {
-   switch [dg-process-target [lindex $args 2]] {
+set target [lindex $args 2]
+if { [llength $args] >= 3 && [lindex $target 0] == "linkonly" } {
+   append additional_sources_omit_on_compile " [lindex $args 1]"
+   set target [lreplace $target 0 1]
+}
+
+if { [llength $args] >= 3 && $target != ""} {
+   switch [dg-process-target $target] {
"S" { append additional_sources " [lindex $args 1]" }
"N" { }
"F" { error "[lindex $args 0]: `xfail' not allowed here" }
@@ -407,17 +414,30 @@ proc dg-additional-files-options { options source dest 
type } {
 gcc_adjust_linker_flags
 
 global additional_sources
+global additional_sources_omit_on_compile
 global additional_sources_used
 global additional_files
 set to_download [list]
 if { $additional_sources == "" } then {
-} elseif { $type != "executable" && $dest != "" } then {
-   foreach s $additional_sources {
-   unsupported "$s: additional-source will not be used to build $dest"
-   }
-   set additional_sources_used ""
-   set additional_sources ""
 } else {
+   
+   if { $type != "executable" && $dest != "" && \
+$additional_sources_omit_on_compile != "" } then {
+   set linkonly ""
+   foreach s $additional_sources {
+   foreach s2 $additional_sources_omit_on_compile {
+   if { $s == $s2 } {
+   unsupported "$s: additional-source will not be used to 
build $dest"
+   set s ""
+   break
+   }
+   }
+   if { $s != "" } {
+   append linkonly " $s"
+   }
+   }
+   set additional_sources "$linkonly"
+   }
if [is_remote host] {
lappend options "additional_flags=$additional_sources"
}


[gcc/aoliva/heads/testme] (2 commits) [testsuite] add linkonly to dg-additional-sources [PR115295

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 606e815b8427... [testsuite] add linkonly to dg-additional-sources [PR115295

It previously pointed to:

 d0e0c26b2a32... [testsuite] add linkonly to dg-additional-sources [PR115295

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  d0e0c26... [testsuite] add linkonly to dg-additional-sources [PR115295
  e8eff7b... map packed field type to unpacked for debug info


Summary of changes (added commits):
---

  606e815... [testsuite] add linkonly to dg-additional-sources [PR115295
  4f96af2... map packed field type to unpacked for debug info


[gcc(refs/users/aoliva/heads/testme)] map packed field type to unpacked for debug info

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:4f96af24fbfa3b7d6d43149c01e7d9a0a5b3e248

commit 4f96af24fbfa3b7d6d43149c01e7d9a0a5b3e248
Author: Alexandre Oliva 
Date:   Tue Jun 11 20:30:30 2024 -0300

map packed field type to unpacked for debug info

We create a distinct type for each field in a packed record with a
gnu_size, but there is no distinct debug information for them.  Use
the same unpacked type for debug information.


for  gcc/ada/ChangeLog

* gcc-interface/decl.cc (gnat_to_gnu_field): Use unpacked type
as the debug type for packed fields.

for  gcc/testsuite/ChangeLog

* gnat.dg/bias1.adb: Count occurrences of -7.*DW_AT_GNU_bias.

Diff:
---
 gcc/ada/gcc-interface/decl.cc   | 4 
 gcc/testsuite/gnat.dg/bias1.adb | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 8b72c96c4396..e97ff64a4805 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -7786,6 +7786,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree 
gnu_record_type, int packed,
   /* If a size is specified, adjust the field's type to it.  */
   if (gnu_size)
 {
+  tree debug_field_type = gnu_field_type;
   tree orig_field_type;
 
   /* If the field's type is justified modular, we would need to remove
@@ -7844,6 +7845,9 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree 
gnu_record_type, int packed,
  && !DECL_P (TYPE_NAME (gnu_field_type)))
create_type_decl (TYPE_NAME (gnu_field_type), gnu_field_type, true,
  debug_info_p, gnat_field);
+
+  if (debug_info_p && gnu_field_type != debug_field_type)
+   SET_TYPE_DEBUG_TYPE (gnu_field_type, debug_field_type);
 }
 
   /* Otherwise (or if there was an error), don't specify a position.  */
diff --git a/gcc/testsuite/gnat.dg/bias1.adb b/gcc/testsuite/gnat.dg/bias1.adb
index 016a159b692d..d9a00a1aa458 100644
--- a/gcc/testsuite/gnat.dg/bias1.adb
+++ b/gcc/testsuite/gnat.dg/bias1.adb
@@ -1,6 +1,7 @@
 --  { dg-do compile }
 --  { dg-options "-cargs -g -dA -gnatws -fgnat-encodings=gdb -margs" }
 --  { dg-final { scan-assembler "DW_AT_GNU_bias" } }
+--  { dg-final { scan-assembler-times "-7.*DW_AT_GNU_bias" 1 } }
 
 procedure Bias1 is
type Small is range -7 .. -4;
@@ -31,4 +32,4 @@ procedure Bias1 is
 
 begin
null;
-end Bias1;
\ No newline at end of file
+end Bias1;


[gcc(refs/users/aoliva/heads/testme)] [testsuite] add linkonly to dg-additional-sources [PR115295]

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:606e815b8427976d801e572b8c571bf030a51ff8

commit 606e815b8427976d801e572b8c571bf030a51ff8
Author: Alexandre Oliva 
Date:   Tue Jun 11 21:44:55 2024 -0300

[testsuite] add linkonly to dg-additional-sources [PR115295]

The D testsuite shows it was a mistake to assume that
dg-additional-sources are never to be used for compilation tests.
Even if an output file is specified for compilation, extra module
files can be named and used in the compilation without being flagged
as errors.

Introduce a 'linkonly' flag for dg-additional-sources, and use it in
pr95401.cc, so that its additional sources get discarded when vector
tests downgrade to compile-only.


for  gcc/ChangeLog

* doc/sourcebuild.texi (dg-additional-sources): Add linkonly.

for  gcc/testsuite/ChangeLog

* g++.dg/vect/pr95401.cc: Add linkonly to dg-additional-sources.
* lib/gcc-defs (additional_sources_omit_on_compile): New.
(dg-additional-sources): Add to it on linkonly.
(dg-additional-files-options): Omit select sources on compile.

Diff:
---
 gcc/doc/sourcebuild.texi |  9 +
 gcc/testsuite/g++.dg/vect/pr95401.cc |  2 +-
 gcc/testsuite/lib/gcc-defs.exp   | 35 ---
 3 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index e997dbec3334..08c178db674c 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1320,15 +1320,16 @@ to @var{var_value} before execution of the program 
created by the test.
 Specify additional files, other than source files, that must be copied
 to the system where the compiler runs.
 
-@item @{ dg-additional-sources "@var{filelist}" [@{ target @var{selector} @}] 
@}
+@item @{ dg-additional-sources "@var{filelist}" [@{ \[linkonly\] \[target 
@var{selector}\] @}] @}
 Specify additional source files to appear in the compile line
 following the main test file.
 If the directive includes the optional @samp{@{ @var{selector} @}}
 then the additional sources are only added if the target system
 matches the @var{selector}.
-Additional sources are generally used only in @samp{link} and @samp{run}
-tests; they are reported as unsupported and discarded in other kinds of
-tests that direct the compiler to output to a single file.
+If @samp{linkonly} is specified, additional sources are used only in
+@samp{link} and @samp{run} tests; they are reported as unsupported and
+discarded in other kinds of tests that direct the compiler to output to
+a single file.
 @end table
 
 @subsubsection Add checks at the end of a test
diff --git a/gcc/testsuite/g++.dg/vect/pr95401.cc 
b/gcc/testsuite/g++.dg/vect/pr95401.cc
index 6a56dab09572..8b1be4f24252 100644
--- a/gcc/testsuite/g++.dg/vect/pr95401.cc
+++ b/gcc/testsuite/g++.dg/vect/pr95401.cc
@@ -1,5 +1,5 @@
 // { dg-additional-options "-mavx2 -O3" { target avx2_runtime } }
-// { dg-additional-sources pr95401a.cc }
+// { dg-additional-sources pr95401a.cc linkonly }
 
 extern int var_9;
 extern unsigned var_14;
diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.exp
index cdca4c254d6e..c6ec490f0092 100644
--- a/gcc/testsuite/lib/gcc-defs.exp
+++ b/gcc/testsuite/lib/gcc-defs.exp
@@ -303,18 +303,26 @@ proc dg-additional-options { args } {
 # main source file.
 
 set additional_sources ""
+set additional_sources_omit_on_compile ""
 set additional_sources_used ""
 
 proc dg-additional-sources { args } {
 global additional_sources
+global additional_sources_omit_on_compile
 
 if { [llength $args] > 3 } {
error "[lindex $args 0]: too many arguments"
return
 }
 
-if { [llength $args] >= 3 } {
-   switch [dg-process-target [lindex $args 2]] {
+set target [lindex $args 2]
+if { [llength $args] >= 3 && [lindex $target 0] == "linkonly" } {
+   append additional_sources_omit_on_compile " [lindex $args 1]"
+   set target [lreplace $target 0 1]
+}
+
+if { [llength $args] >= 3 && $target != ""} {
+   switch [dg-process-target $target] {
"S" { append additional_sources " [lindex $args 1]" }
"N" { }
"F" { error "[lindex $args 0]: `xfail' not allowed here" }
@@ -407,16 +415,29 @@ proc dg-additional-files-options { options source dest 
type } {
 gcc_adjust_linker_flags
 
 global additional_sources
+global additional_sources_omit_on_compile
 global additional_sources_used
 global additional_files
 set to_download [list]
-if { $additional_sources == "" } then {
-} elseif { $type != "executable" && $dest != "" } then {
+if { $additional_sources_omit_on_compile != "" \
+&& $additional_sources != "" \
+&& $type != "executable" && $dest != "" } then {
+   set linkonly ""
foreach s $additional_sources {
-   unsupported "$s: additional-source wi

[gcc r15-1193] [libstdc++] drop workaround for clang<=7

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:da57b4562c5ada8971b6684b6aad1c996e1ef9cc

commit r15-1193-gda57b4562c5ada8971b6684b6aad1c996e1ef9cc
Author: Alexandre Oliva 
Date:   Wed Jun 12 00:16:20 2024 -0300

[libstdc++] drop workaround for clang<=7

In response to a request in the review of the patch that introduced
_GLIBCXX_CLANG, this patch removes from std/variant an obsolete
workaround for clang 7-.


for  libstdc++-v3/ChangeLog

* include/std/variant: Drop obsolete workaround.

Diff:


[gcc r15-1194] map packed field type to unpacked for debug info

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:ea5c9f25241ae0658180afbcad7f4e298352f561

commit r15-1194-gea5c9f25241ae0658180afbcad7f4e298352f561
Author: Alexandre Oliva 
Date:   Wed Jun 12 00:16:22 2024 -0300

map packed field type to unpacked for debug info

We create a distinct type for each field in a packed record with a
gnu_size, but there is no distinct debug information for them.  Use
the same unpacked type for debug information.


for  gcc/ada/ChangeLog

* gcc-interface/decl.cc (gnat_to_gnu_field): Use unpacked type
as the debug type for packed fields.

for  gcc/testsuite/ChangeLog

* gnat.dg/bias1.adb: Count occurrences of -7.*DW_AT_GNU_bias.

Diff:
---
 gcc/ada/gcc-interface/decl.cc   | 4 
 gcc/testsuite/gnat.dg/bias1.adb | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 8b72c96c4396..e97ff64a4805 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -7786,6 +7786,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree 
gnu_record_type, int packed,
   /* If a size is specified, adjust the field's type to it.  */
   if (gnu_size)
 {
+  tree debug_field_type = gnu_field_type;
   tree orig_field_type;
 
   /* If the field's type is justified modular, we would need to remove
@@ -7844,6 +7845,9 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree 
gnu_record_type, int packed,
  && !DECL_P (TYPE_NAME (gnu_field_type)))
create_type_decl (TYPE_NAME (gnu_field_type), gnu_field_type, true,
  debug_info_p, gnat_field);
+
+  if (debug_info_p && gnu_field_type != debug_field_type)
+   SET_TYPE_DEBUG_TYPE (gnu_field_type, debug_field_type);
 }
 
   /* Otherwise (or if there was an error), don't specify a position.  */
diff --git a/gcc/testsuite/gnat.dg/bias1.adb b/gcc/testsuite/gnat.dg/bias1.adb
index 016a159b692d..d9a00a1aa458 100644
--- a/gcc/testsuite/gnat.dg/bias1.adb
+++ b/gcc/testsuite/gnat.dg/bias1.adb
@@ -1,6 +1,7 @@
 --  { dg-do compile }
 --  { dg-options "-cargs -g -dA -gnatws -fgnat-encodings=gdb -margs" }
 --  { dg-final { scan-assembler "DW_AT_GNU_bias" } }
+--  { dg-final { scan-assembler-times "-7.*DW_AT_GNU_bias" 1 } }
 
 procedure Bias1 is
type Small is range -7 .. -4;
@@ -31,4 +32,4 @@ procedure Bias1 is
 
 begin
null;
-end Bias1;
\ No newline at end of file
+end Bias1;


[gcc r15-1195] [testsuite] [arm] test board cflags in multilib.exp

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:89a746f2a326ae83c51868271615fe5d7e249c50

commit r15-1195-g89a746f2a326ae83c51868271615fe5d7e249c50
Author: Alexandre Oliva 
Date:   Wed Jun 12 00:16:24 2024 -0300

[testsuite] [arm] test board cflags in multilib.exp

multilib.exp tests for multilib-altering flags in a board's
multilib_flags and skips the test, but if such flags appear in the
board's cflags, with the same distorting effects on tested multilibs,
we fail to skip the test.

Extend the skipping logic to board's cflags as well.


for  gcc/testsuite/ChangeLog

* gcc.target/arm/multilib.exp: Skip based on board cflags too.

Diff:
---
 gcc/testsuite/gcc.target/arm/multilib.exp | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/multilib.exp 
b/gcc/testsuite/gcc.target/arm/multilib.exp
index 4442d5d754bd..12c93bc89d22 100644
--- a/gcc/testsuite/gcc.target/arm/multilib.exp
+++ b/gcc/testsuite/gcc.target/arm/multilib.exp
@@ -18,13 +18,15 @@ load_lib gcc-dg.exp
 
 dg-init
 
-if { [board_info [target_info name] exists multilib_flags] 
- && [regexp {(-marm|-mthumb|-march=.*|-mcpu=.*|-mfpu=.*|-mfloat=abi=.*)\y} 
[board_info [target_info name] multilib_flags]] } {
+foreach flagsvar {multilib_flags cflags} {
+  if { [board_info [target_info name] exists $flagsvar] 
+ && [regexp {(-marm|-mthumb|-march=.*|-mcpu=.*|-mfpu=.*|-mfloat=abi=.*)\y} 
[board_info [target_info name] $flagsvar]] } {

 # Multilib flags override anything we can apply to a test, so
 # skip if any of the above options are set there.
-verbose "skipping multilib tests due to multilib_flags setting" 1
+verbose "skipping multilib tests due to $flagsvar setting" 1
 return
+  }
 }
 
 # We don't want to run this test multiple times in a parallel make check.


[gcc r15-1196] [tree-prof] skip if errors were seen [PR113681]

2024-06-11 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:66f48557e11a530646e5562c50a75b4b9839f171

commit r15-1196-g66f48557e11a530646e5562c50a75b4b9839f171
Author: Alexandre Oliva 
Date:   Wed Jun 12 00:16:27 2024 -0300

[tree-prof] skip if errors were seen [PR113681]

ipa_tree_profile asserts that the symtab is in IPA_SSA state, but we
don't reach that state and ICE if e.g. ipa-strub passes report errors.
Skip this pass if errors were seen.


for  gcc/ChangeLog

PR tree-optimization/113681
* tree-profile.cc (pass_ipa_tree_profile::gate): Skip if
seen_errors.

for  gcc/testsuite/ChangeLog

PR tree-optimization/113681
* c-c++-common/strub-pr113681.c: New.

Diff:
---
 gcc/testsuite/c-c++-common/strub-pr113681.c | 22 ++
 gcc/tree-profile.cc |  3 ++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/strub-pr113681.c 
b/gcc/testsuite/c-c++-common/strub-pr113681.c
new file mode 100644
index ..3ef9017b2eb7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/strub-pr113681.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-fstrub=relaxed -fbranch-probabilities" } */
+/* { dg-require-effective-target strub } */
+
+/* Same as torture/strub-inlineable1.c, but with -fbranch-probabilities, to
+   check that IPA tree-profiling won't ICE.  It would when we refrained from
+   running passes that would take it to IPA_SSA, but ran the pass that asserted
+   for IPA_SSA.  */
+
+inline void __attribute__ ((strub ("internal"), always_inline))
+inl_int_ali (void)
+{
+  /* No internal wrapper, so this body ALWAYS gets inlined,
+ but it cannot be called from non-strub contexts.  */
+}
+
+void
+bat (void)
+{
+  /* Not allowed, not a strub context.  */
+  inl_int_ali (); /* { dg-error "context" } */
+}
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index b87c121790c9..e4bb689cef58 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -2070,7 +2070,8 @@ pass_ipa_tree_profile::gate (function *)
  disabled.  */
   return (!in_lto_p && !flag_auto_profile
  && (flag_branch_probabilities || flag_test_coverage
- || profile_arc_flag || condition_coverage_flag));
+ || profile_arc_flag || condition_coverage_flag)
+ && !seen_error ());
 }
 
 } // anon namespace


[gcc r15-1197] doc: Simplify *-*-linux-gnu dependencies

2024-06-11 Thread Gerald Pfeifer via Gcc-cvs
https://gcc.gnu.org/g:919e88f7915b57ae3a2152a1947dbfac3fccfe88

commit r15-1197-g919e88f7915b57ae3a2152a1947dbfac3fccfe88
Author: Gerald Pfeifer 
Date:   Wed Jun 12 08:46:20 2024 +0200

doc: Simplify *-*-linux-gnu dependencies

Glibc 2.1 was released in 1999, binutils 2.12 in 2002; no need to
explicitly list them as dependencies any longer.

gcc:
PR target/69374
* doc/install.texi (Specific) <*-*-linux-gnu>: Do not list
glibc 2.1 and binutils 2.12 as minimum dependencies.

Diff:
---
 gcc/doc/install.texi | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index bc70318c0878..621c874d268d 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4266,9 +4266,6 @@ supported, so @option{--enable-threads=dce} does not work.
 @end html
 @anchor{x-x-linux-gnu}
 @heading *-*-linux-gnu
-The @code{.init_array} and @code{.fini_array} sections are enabled
-unconditionally which requires at least glibc 2.1 and binutils 2.12.
-
 Versions of libstdc++-v3 starting with 3.2.1 require bug fixes present
 in glibc 2.2.5 and later.  More information is available in the
 libstdc++-v3 documentation.


[gcc r15-1198] Widening-Mul: Take gsi after_labels instead of start_bb for gcall insertion

2024-06-11 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:acd2ca1e28128d9d0d41683d6039f437c02d793f

commit r15-1198-gacd2ca1e28128d9d0d41683d6039f437c02d793f
Author: Pan Li 
Date:   Tue Jun 11 21:39:43 2024 +0800

Widening-Mul: Take gsi after_labels instead of start_bb for gcall insertion

We inserted the gcall of .SAT_ADD before the gsi_start_bb for avoiding
the ssa def after use ICE issue.  Unfortunately,  there will be the
potential ICE when the first stmt is label.  We cannot insert the gcall
before the label.  Thus,  we take gsi_after_labels to locate the
'really' stmt that the gcall will insert before.

The existing test cases pr115387-1.c and pr115387-2.c cover this change.

The below test suites are passed for this patch.
* The rv64gcv fully regression test with newlib.
* The x86 regression test.
* The x86 bootstrap test.

gcc/ChangeLog:

* tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children):
Leverage gsi_after_labels instead of gsi_start_bb to skip the
leading labels of bb.

Signed-off-by: Pan Li 

Diff:
---
 gcc/tree-ssa-math-opts.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index fbb8e0ea3067..c09e90064439 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -6102,7 +6102,7 @@ math_opts_dom_walker::after_dom_children (basic_block bb)
   for (gphi_iterator psi = gsi_start_phis (bb); !gsi_end_p (psi);
 gsi_next (&psi))
 {
-  gimple_stmt_iterator gsi = gsi_start_bb (bb);
+  gimple_stmt_iterator gsi = gsi_after_labels (bb);
   match_unsigned_saturation_add (&gsi, psi.phi ());
 }