[gcc r15-1605] MIPS: Implement vcond_mask optabs for MSA

2024-06-25 Thread YunQiang Su via Gcc-cvs
https://gcc.gnu.org/g:17b368b4b4524ce9d11bf79ce7f58d6825156ce0

commit r15-1605-g17b368b4b4524ce9d11bf79ce7f58d6825156ce0
Author: YunQiang Su 
Date:   Thu Jun 20 01:20:36 2024 +0800

MIPS: Implement vcond_mask optabs for MSA

Currently, we have `mips_expand_vec_cond_expr`, which calculate
cmp_res first.  We can just add a new extra argument to ask it
to use operands[3] as cmp_res instead of calculating from operands[4]
and operands[5].

gcc
* config/mips/mips.cc(mips_expand_vec_cond_expr): Add extra
argument to info that opernads[3] is cmp_res already.
* config/mips/mips-protos.h(mips_expand_vec_cond_expr): Ditto.
* config/mips/mips-msa.md(vcond_mask): Define new expand.
(vcondu): Use mips_expand_vec_cond_expr with 4th argument.
(vcond): Ditto.

Diff:
---
 gcc/config/mips/mips-msa.md   | 17 +++--
 gcc/config/mips/mips-protos.h |  2 +-
 gcc/config/mips/mips.cc   | 18 --
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/gcc/config/mips/mips-msa.md b/gcc/config/mips/mips-msa.md
index 779157f2a0c..0081b688ce9 100644
--- a/gcc/config/mips/mips-msa.md
+++ b/gcc/config/mips/mips-msa.md
@@ -411,6 +411,19 @@
   DONE;
 })
 
+(define_expand "vcond_mask_"
+  [(match_operand:MSA 0 "register_operand")
+   (match_operand:MSA 1 "reg_or_m1_operand")
+   (match_operand:MSA 2 "reg_or_0_operand")
+   (match_operand:IMSA 3 "register_operand")]
+  "ISA_HAS_MSA
+   && (GET_MODE_NUNITS (mode) == GET_MODE_NUNITS (mode))"
+{
+  mips_expand_vec_cond_expr (mode, mode, operands, true);
+  DONE;
+})
+
+
 (define_expand "vcondu"
   [(match_operand:MSA 0 "register_operand")
(match_operand:MSA 1 "reg_or_m1_operand")
@@ -421,7 +434,7 @@
   "ISA_HAS_MSA
&& (GET_MODE_NUNITS (mode) == GET_MODE_NUNITS (mode))"
 {
-  mips_expand_vec_cond_expr (mode, mode, operands);
+  mips_expand_vec_cond_expr (mode, mode, operands, 
false);
   DONE;
 })
 
@@ -435,7 +448,7 @@
   "ISA_HAS_MSA
&& (GET_MODE_NUNITS (mode) == GET_MODE_NUNITS (mode))"
 {
-  mips_expand_vec_cond_expr (mode, mode, operands);
+  mips_expand_vec_cond_expr (mode, mode, operands, 
false);
   DONE;
 })
 
diff --git a/gcc/config/mips/mips-protos.h b/gcc/config/mips/mips-protos.h
index fcc0a0ae663..75f80984c03 100644
--- a/gcc/config/mips/mips-protos.h
+++ b/gcc/config/mips/mips-protos.h
@@ -385,7 +385,7 @@ extern mulsidi3_gen_fn mips_mulsidi3_gen_fn (enum rtx_code);
 #endif
 
 extern void mips_register_frame_header_opt (void);
-extern void mips_expand_vec_cond_expr (machine_mode, machine_mode, rtx *);
+extern void mips_expand_vec_cond_expr (machine_mode, machine_mode, rtx *, 
bool);
 extern void mips_expand_vec_cmp_expr (rtx *);
 
 extern void mips_emit_speculation_barrier_function (void);
diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index 24addfa89aa..7d4791157d1 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -22801,14 +22801,20 @@ mips_expand_vec_cmp_expr (rtx *operands)
 
 void
 mips_expand_vec_cond_expr (machine_mode mode, machine_mode vimode,
-  rtx *operands)
+  rtx *operands, bool mask)
 {
-  rtx cond = operands[3];
-  rtx cmp_op0 = operands[4];
-  rtx cmp_op1 = operands[5];
-  rtx cmp_res = gen_reg_rtx (vimode);
+  rtx cmp_res;
+  if (mask)
+cmp_res = operands[3];
+  else
+{
+  rtx cond = operands[3];
+  rtx cmp_op0 = operands[4];
+  rtx cmp_op1 = operands[5];
+  cmp_res = gen_reg_rtx (vimode);
 
-  mips_expand_msa_cmp (cmp_res, GET_CODE (cond), cmp_op0, cmp_op1);
+  mips_expand_msa_cmp (cmp_res, GET_CODE (cond), cmp_op0, cmp_op1);
+}
 
   /* We handle the following cases:
  1) r = a CMP b ? -1 : 0


[gcc r15-1604] MIPS: Output $0 for conditional trap if !ISA_HAS_COND_TRAPI

2024-06-25 Thread YunQiang Su via Gcc-cvs
https://gcc.gnu.org/g:0b456434fe0f1d64291b7c6b3596c836c9519f85

commit r15-1604-g0b456434fe0f1d64291b7c6b3596c836c9519f85
Author: YunQiang Su 
Date:   Wed Jun 19 23:48:26 2024 +0800

MIPS: Output $0 for conditional trap if !ISA_HAS_COND_TRAPI

MIPSr6 removes condition trap instructions with imm, so the instruction
like `teq $2,imm` will be converted to
  li $at, imm
  teq $2, $at

The current version of Gas cannot detect if imm is zero, and output
  teq $2, $0
Let's do it in GCC.

gcc
* config/mips/mips.md(conditional_trap_reg): Output $0 instead
of 0 if !ISA_HAS_COND_TRAPI.

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

diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md
index f9da06663bb..737d2566ec8 100644
--- a/gcc/config/mips/mips.md
+++ b/gcc/config/mips/mips.md
@@ -1245,7 +1245,7 @@
 (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
(const_int 0))]
   "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
-  "t%C0\t%z1,%2"
+  "t%C0\t%z1,%z2"
   [(set_attr "type" "trap")])
 
 (define_insn "*conditional_trap"


[gcc r15-1606] Revert one of the force_subreg changes

2024-06-25 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:b694bf417cdd7d0a4d78e9927bab6bc202b7df6c

commit r15-1606-gb694bf417cdd7d0a4d78e9927bab6bc202b7df6c
Author: Richard Sandiford 
Date:   Tue Jun 25 09:41:21 2024 +0100

Revert one of the force_subreg changes

One of the changes in g:d4047da6a070175aae7121c739d1cad6b08ff4b2
caused a regression in ft32-elf; see:

https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655418.html

for details.  This change was different from the others in that the
original call was to simplify_subreg rather than simplify_lowpart_subreg.
The old code would therefore go on to do the force_reg for more cases
than the new code would.

gcc/
* expmed.cc (store_bit_field_using_insv): Revert earlier change
to use force_subreg instead of simplify_gen_subreg.

Diff:
---
 gcc/expmed.cc | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/expmed.cc b/gcc/expmed.cc
index 3b9475f5aa0..8bbbc94a98c 100644
--- a/gcc/expmed.cc
+++ b/gcc/expmed.cc
@@ -695,7 +695,13 @@ store_bit_field_using_insv (const extraction_insn *insv, 
rtx op0,
 if we must narrow it, be sure we do it correctly.  */
 
  if (GET_MODE_SIZE (value_mode) < GET_MODE_SIZE (op_mode))
-   tmp = force_subreg (op_mode, value1, value_mode, 0);
+   {
+ tmp = simplify_subreg (op_mode, value1, value_mode, 0);
+ if (! tmp)
+   tmp = simplify_gen_subreg (op_mode,
+  force_reg (value_mode, value1),
+  value_mode, 0);
+   }
  else
{
  if (targetm.mode_rep_extended (op_mode, value_mode) != UNKNOWN)


[gcc r15-1607] rs6000: Properly default-disable late-combine passes [PR106594, PR115622, PR115633]

2024-06-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:70480055636c2ca79761cb4440e930daa16bb7aa

commit r15-1607-g70480055636c2ca79761cb4440e930daa16bb7aa
Author: Thomas Schwinge 
Date:   Tue Jun 25 10:55:41 2024 +0200

rs6000: Properly default-disable late-combine passes [PR106594, PR115622, 
PR115633]

..., so that it also works for '__attribute__ ((optimize("[...]")))' etc.

PR target/106594
PR target/115622
PR target/115633
gcc/
* config/rs6000/rs6000.cc (rs6000_option_override_internal): Move
default-disable of late-combine passes from here...
(rs6000_override_options_after_change): ... to here.

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

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index cd14e5a34ed..71fe31297cf 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -3434,6 +3434,14 @@ rs6000_override_options_after_change (void)
   /* If we are inserting ROP-protect instructions, disable shrink wrap.  */
   if (rs6000_rop_protect)
 flag_shrink_wrap = 0;
+
+  /* One of the late-combine passes runs after register allocation
+ and can match define_insn_and_splits that were previously used
+ only before register allocation.  Some of those define_insn_and_splits
+ use gen_reg_rtx unconditionally.  Disable late-combine by default
+ until the define_insn_and_splits are fixed.  */
+  if (!OPTION_SET_P (flag_late_combine_instructions))
+flag_late_combine_instructions = 0;
 }
 
 #ifdef TARGET_USES_LINUX64_OPT
@@ -4771,14 +4779,6 @@ rs6000_option_override_internal (bool global_init_p)
targetm.expand_builtin_va_start = NULL;
 }
 
-  /* One of the late-combine passes runs after register allocation
- and can match define_insn_and_splits that were previously used
- only before register allocation.  Some of those define_insn_and_splits
- use gen_reg_rtx unconditionally.  Disable late-combine by default
- until the define_insn_and_splits are fixed.  */
-  if (!OPTION_SET_P (flag_late_combine_instructions))
-flag_late_combine_instructions = 0;
-
   rs6000_override_options_after_change ();
 
   /* If not explicitly specified via option, decide whether to generate indexed


[gcc r15-1608] SPARC: fix internal error with -mv8plus on 64-bit Linux

2024-06-25 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:d4db77ce37a65207baea88859fd9c191469187f8

commit r15-1608-gd4db77ce37a65207baea88859fd9c191469187f8
Author: Eric Botcazou 
Date:   Tue Jun 25 11:47:48 2024 +0200

SPARC: fix internal error with -mv8plus on 64-bit Linux

This passes -m32 when -mv8plus is specified on Linux (like on Solaris).

gcc/
PR target/115608
* config/sparc/linux64.h (CC1_SPEC): Pass -m32 for -mv8plus.

Diff:
---
 gcc/config/sparc/linux64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h
index 66426d8f5fe..63543f961ad 100644
--- a/gcc/config/sparc/linux64.h
+++ b/gcc/config/sparc/linux64.h
@@ -162,7 +162,7 @@ extern const char *host_detect_local_cpu (int argc, const 
char **argv);
 "%{m32:%{m64:%emay not use both -m32 and -m64}} \
 %{m32:-mptr32 -mno-stack-bias %{!mlong-double-128:-mlong-double-64} \
   %{!mcpu*:-mcpu=cypress}} \
-%{mv8plus:-mptr32 -mno-stack-bias %{!mlong-double-128:-mlong-double-64} \
+%{mv8plus:-m32 -mptr32 -mno-stack-bias %{!mlong-double-128:-mlong-double-64} \
   %{!mcpu*:-mcpu=v9}} \
 %{!m32:%{!mcpu*:-mcpu=ultrasparc}} \
 %{!mno-vis:%{!m32:%{!mcpu=v9:-mvis}}}"


[gcc r14-10345] SPARC: fix internal error with -mv8plus on 64-bit Linux

2024-06-25 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:4bf93fc3d360dbeb5c07303c1b5028989c575ac1

commit r14-10345-g4bf93fc3d360dbeb5c07303c1b5028989c575ac1
Author: Eric Botcazou 
Date:   Tue Jun 25 11:47:48 2024 +0200

SPARC: fix internal error with -mv8plus on 64-bit Linux

This passes -m32 when -mv8plus is specified on Linux (like on Solaris).

gcc/
PR target/115608
* config/sparc/linux64.h (CC1_SPEC): Pass -m32 for -mv8plus.

Diff:
---
 gcc/config/sparc/linux64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h
index 1e2e4aef2ad..83e0d6874d9 100644
--- a/gcc/config/sparc/linux64.h
+++ b/gcc/config/sparc/linux64.h
@@ -162,7 +162,7 @@ extern const char *host_detect_local_cpu (int argc, const 
char **argv);
 "%{m32:%{m64:%emay not use both -m32 and -m64}} \
 %{m32:-mptr32 -mno-stack-bias %{!mlong-double-128:-mlong-double-64} \
   %{!mcpu*:-mcpu=cypress}} \
-%{mv8plus:-mptr32 -mno-stack-bias %{!mlong-double-128:-mlong-double-64} \
+%{mv8plus:-m32 -mptr32 -mno-stack-bias %{!mlong-double-128:-mlong-double-64} \
   %{!mcpu*:-mcpu=v9}} \
 %{!m32:%{!mcpu*:-mcpu=ultrasparc}} \
 %{!mno-vis:%{!m32:%{!mcpu=v9:-mvis}}}"


[gcc r15-1609] libatomic: Add rcpc3 128-bit atomic operations for AArch64

2024-06-25 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:7107574958e2bed11d916a1480ef1319f15e5ffe

commit r15-1609-g7107574958e2bed11d916a1480ef1319f15e5ffe
Author: Victor Do Nascimento 
Date:   Mon Jun 10 11:10:36 2024 +0100

libatomic: Add rcpc3 128-bit atomic operations for AArch64

The introduction of the optional RCPC3 architectural extension for
Armv8.2-A upwards provides additional support for the release
consistency model, introducing the Load-Acquire RCpc Pair Ordered, and
Store-Release Pair Ordered operations in the form of LDIAPP and STILP.

These operations are single-copy atomic on cores which also implement
LSE2 and, as such, support for these operations is added to Libatomic
and employed accordingly when the LSE2 and RCPC3 features are detected
in a given core at runtime.

libatomic/ChangeLog:

* config/linux/aarch64/atomic_16.S (libat_load_16): Add LRCPC3
variant.
(libat_store_16): Likewise.
* config/linux/aarch64/host-config.h (HWCAP2_LRCPC3): New.
(LSE2_LRCPC3_ATOP): Previously LSE2_ATOP.  New ifuncs guarded
under it.
(has_rcpc3): New.

Diff:
---
 libatomic/config/linux/aarch64/atomic_16.S   | 46 ++--
 libatomic/config/linux/aarch64/host-config.h | 34 +---
 2 files changed, 74 insertions(+), 6 deletions(-)

diff --git a/libatomic/config/linux/aarch64/atomic_16.S 
b/libatomic/config/linux/aarch64/atomic_16.S
index c44c31c6418..5767fba5c03 100644
--- a/libatomic/config/linux/aarch64/atomic_16.S
+++ b/libatomic/config/linux/aarch64/atomic_16.S
@@ -35,16 +35,21 @@
writes, this will be true when using atomics in actual code.
 
The libat__16 entry points are ARMv8.0.
-   The libat__16_i1 entry points are used when LSE128 is available.
+   The libat__16_i1 entry points are used when LSE128 or LRCPC3 is 
available.
The libat__16_i2 entry points are used when LSE2 is available.  */
 
 #include "auto-config.h"
 
.arch   armv8-a+lse
 
+/* There is overlap in atomic instructions implemented in RCPC3 and LSE2.
+   Consequently, both _i1 and _i2 suffixes are needed for functions using 
these.
+   Elsewhere, all extension-specific implementations are mapped to _i1.  */
+
+#define LRCPC3(NAME)   libat_##NAME##_i1
 #define LSE128(NAME)   libat_##NAME##_i1
 #define LSE(NAME)  libat_##NAME##_i1
-#define LSE2(NAME) libat_##NAME##_i1
+#define LSE2(NAME) libat_##NAME##_i2
 #define CORE(NAME) libat_##NAME
 #define ATOMIC(NAME)   __atomic_##NAME
 
@@ -513,6 +518,43 @@ END (test_and_set_16)
 /* ifunc implementations: Carries run-time dependence on the presence of 
further
architectural extensions.  */
 
+ENTRY_FEAT (load_16, LRCPC3)
+   cbnzw1, 1f
+
+   /* RELAXED.  */
+   ldp res0, res1, [x0]
+   ret
+1:
+   cmp w1, SEQ_CST
+   b.eq2f
+
+   /* ACQUIRE/CONSUME (Load-AcquirePC semantics).  */
+   /* ldiapp res0, res1, [x0]  */
+   .inst   0xd9411800
+   ret
+
+   /* SEQ_CST.  */
+2: ldartmp0, [x0]  /* Block reordering with Store-Release instr.  
*/
+   /* ldiapp res0, res1, [x0]  */
+   .inst   0xd9411800
+   ret
+END_FEAT (load_16, LRCPC3)
+
+
+ENTRY_FEAT (store_16, LRCPC3)
+   cbnzw4, 1f
+
+   /* RELAXED.  */
+   stp in0, in1, [x0]
+   ret
+
+   /* RELEASE/SEQ_CST.  */
+1: /* stilp in0, in1, [x0]  */
+   .inst   0xd9031802
+   ret
+END_FEAT (store_16, LRCPC3)
+
+
 ENTRY_FEAT (exchange_16, LSE128)
mov tmp0, x0
mov res0, in0
diff --git a/libatomic/config/linux/aarch64/host-config.h 
b/libatomic/config/linux/aarch64/host-config.h
index d05e9eb628f..93f367d5878 100644
--- a/libatomic/config/linux/aarch64/host-config.h
+++ b/libatomic/config/linux/aarch64/host-config.h
@@ -33,6 +33,9 @@
 #ifndef HWCAP_USCAT
 # define HWCAP_USCAT   (1 << 25)
 #endif
+#ifndef HWCAP2_LRCPC3
+# define HWCAP2_LRCPC3 (1UL << 46)
+#endif
 #ifndef HWCAP2_LSE128
 # define HWCAP2_LSE128 (1UL << 47)
 #endif
@@ -54,7 +57,7 @@ typedef struct __ifunc_arg_t {
 #if defined (LAT_CAS_N)
 # define LSE_ATOP
 #elif defined (LAT_LOAD_N) || defined (LAT_STORE_N)
-# define LSE2_ATOP
+# define LSE2_LRCPC3_ATOP
 #elif defined (LAT_EXCH_N) || defined (LAT_FIOR_N) || defined (LAT_FAND_N)
 # define LSE128_ATOP
 #endif
@@ -63,9 +66,10 @@ typedef struct __ifunc_arg_t {
 #  if defined (LSE_ATOP)
 #   define IFUNC_NCOND(N)  1
 #   define IFUNC_COND_1(hwcap & HWCAP_ATOMICS)
-#  elif defined (LSE2_ATOP)
-#   define IFUNC_NCOND(N)  1
-#   define IFUNC_COND_1(has_lse2 (hwcap, features))
+#  elif defined (LSE2_LRCPC3_ATOP)
+#   define IFUNC_NCOND(N)  2
+#   define IFUNC_COND_1(has_rcpc3 (hwcap, features))
+#   define IFUNC_COND_2(has_lse2 (hwcap, features))
 #  elif defined (LSE128_ATOP)
 #   define IFUNC_NCOND(N)  1
 #   define IFUNC_COND_1(has_lse128 (hwcap, features))
@@ -131,6 +135,28 

[gcc r15-1610] Add a debug counter for late-combine

2024-06-25 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:b6215065a5b14317a342176d5304ecaea3163639

commit r15-1610-gb6215065a5b14317a342176d5304ecaea3163639
Author: Richard Sandiford 
Date:   Tue Jun 25 12:58:12 2024 +0100

Add a debug counter for late-combine

This should help to diagnose problems like PR115631.

gcc/
* dbgcnt.def (late_combine): New debug counter.
* late-combine.cc (insn_combination::run): Use it.

Diff:
---
 gcc/dbgcnt.def  | 1 +
 gcc/late-combine.cc | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/gcc/dbgcnt.def b/gcc/dbgcnt.def
index ed9f062eac2..e0b9b1b2a76 100644
--- a/gcc/dbgcnt.def
+++ b/gcc/dbgcnt.def
@@ -186,6 +186,7 @@ DEBUG_COUNTER (ipa_sra_params)
 DEBUG_COUNTER (ipa_sra_retvalues)
 DEBUG_COUNTER (ira_move)
 DEBUG_COUNTER (ivopts_loop)
+DEBUG_COUNTER (late_combine)
 DEBUG_COUNTER (lim)
 DEBUG_COUNTER (local_alloc_for_sched)
 DEBUG_COUNTER (loop_unswitch)
diff --git a/gcc/late-combine.cc b/gcc/late-combine.cc
index 22a1d81d38e..fc75d1c56d7 100644
--- a/gcc/late-combine.cc
+++ b/gcc/late-combine.cc
@@ -41,6 +41,7 @@
 #include "tree-pass.h"
 #include "cfgcleanup.h"
 #include "target.h"
+#include "dbgcnt.h"
 
 using namespace rtl_ssa;
 
@@ -428,6 +429,11 @@ insn_combination::run ()
   || !crtl->ssa->verify_insn_changes (m_nondebug_changes))
 return false;
 
+  // We've now decided that the optimization is valid and profitable.
+  // Allow it to be suppressed for bisection purposes.
+  if (!dbg_cnt (::late_combine))
+return false;
+
   substitute_optional_uses (m_def);
 
   confirm_change_group ();


[gcc r15-1611] doc: gccint: Fix typos in jump_table_data description

2024-06-25 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:d27049a38a4c07fa1e662ffd66df3f15d330503f

commit r15-1611-gd27049a38a4c07fa1e662ffd66df3f15d330503f
Author: Xi Ruoyao 
Date:   Tue Jun 25 21:42:38 2024 +0800

doc: gccint: Fix typos in jump_table_data description

gcc/ChangeLog:

* doc/rtl.texi (jump_table_data): Fix typos.

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

diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
index c1717ab5f6b..a1ede418c21 100644
--- a/gcc/doc/rtl.texi
+++ b/gcc/doc/rtl.texi
@@ -3872,8 +3872,8 @@ To set the kind of a label, use the @code{SET_LABEL_KIND} 
macro.
 @item jump_table_data
 A @code{jump_table_data} insn is a placeholder for the jump-table data
 of a @code{casesi} or @code{tablejump} insn.  They are placed after
-a @code{tablejump_p} insn.  A @code{jump_table_data} insn is not part o
-a basic blockm but it is associated with the basic block that ends with
+a @code{tablejump_p} insn.  A @code{jump_table_data} insn is not part of
+a basic block but it is associated with the basic block that ends with
 the @code{tablejump_p} insn.  The @code{PATTERN} of a @code{jump_table_data}
 is always either an @code{addr_vec} or an @code{addr_diff_vec}, and a
 @code{jump_table_data} insn is always preceded by a @code{code_label}.


[gcc r15-1612] GORI cleanups

2024-06-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:3587bfae391616d155de0c9cbe98206634f3ed6b

commit r15-1612-g3587bfae391616d155de0c9cbe98206634f3ed6b
Author: Richard Biener 
Date:   Tue Jun 25 15:41:57 2024 +0200

GORI cleanups

The following replaces conditional is_export_p calls as is_export_p
handles a NULL bb itself.

* gimple-range-gori.cc (gori_compute::may_recompute_p):
Call is_export_p with NULL bb.

Diff:
---
 gcc/gimple-range-gori.cc | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index 275283a424f..a31e3be65f7 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -1332,18 +1332,14 @@ gori_compute::may_recompute_p (tree name, basic_block 
bb, int depth)
  gcc_checking_assert (depth >= 1);
}
 
-  bool res = (bb ? m_map.is_export_p (dep1, bb)
-: m_map.is_export_p (dep1));
+  bool res = m_map.is_export_p (dep1, bb);
   if (res || depth <= 1)
return res;
   // Check another level of recomputation.
   return may_recompute_p (dep1, bb, --depth);
 }
   // Two dependencies terminate the depth of the search.
-  if (bb)
-return m_map.is_export_p (dep1, bb) || m_map.is_export_p (dep2, bb);
-  else
-return m_map.is_export_p (dep1) || m_map.is_export_p (dep2);
+  return m_map.is_export_p (dep1, bb) || m_map.is_export_p (dep2, bb);
 }
 
 // Return TRUE if NAME can be recomputed on edge E.  If any direct dependent


[gcc r15-1613] Fix PR c/115587, uninitialized variable in c_parser_omp_loop_nest

2024-06-25 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:21f1073d388af8af207183b0ed592e1cc47d20ab

commit r15-1613-g21f1073d388af8af207183b0ed592e1cc47d20ab
Author: Sandra Loosemore 
Date:   Tue Jun 25 13:54:43 2024 +

Fix PR c/115587, uninitialized variable in c_parser_omp_loop_nest

This function had a reference to an uninitialized variable on the
error path.  The problem was diagnosed by clang but not gcc.  It seems
the cleanest solution is to initialize all the loop-clause variables
at the point of declaration rather than at different places in the
code.

The C++ front end didn't have this problem, but I've made similar
changes there to keep the code in sync.

gcc/c/ChangeLog:

PR c/115587
* c-parser.cc (c_parser_omp_loop_nest): Move initializations to
point of declaration.

gcc/cp/ChangeLog:

PR c/115587
* parser.cc (cp_parser_omp_loop_nest): Move initializations to
point of declaration.

Diff:
---
 gcc/c/c-parser.cc | 4 +---
 gcc/cp/parser.cc  | 8 ++--
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index e83e9c683f7..33643ec910a 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -22430,7 +22430,7 @@ static tree c_parser_omp_unroll (location_t, c_parser 
*, bool *);
 static tree
 c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
 {
-  tree decl, cond, incr, init;
+  tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE;
   tree body = NULL_TREE;
   matching_parens parens;
   bool moreloops;
@@ -22619,7 +22619,6 @@ c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
 }
 
   /* Parse the loop condition.  */
-  cond = NULL_TREE;
   if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
 {
   location_t cond_loc = c_parser_peek_token (parser)->location;
@@ -22652,7 +22651,6 @@ c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
 
   /* Parse the increment expression.  */
-  incr = NULL_TREE;
   if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
 {
   location_t incr_loc = c_parser_peek_token (parser)->location;
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index e7409b856f1..e5f16fe963d 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -45153,8 +45153,8 @@ static tree cp_parser_omp_tile (cp_parser *, cp_token 
*, bool *);
 static tree
 cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p)
 {
-  tree decl, cond, incr, init;
-  tree orig_init, real_decl, orig_decl;
+  tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE;
+  tree orig_init = NULL_TREE, real_decl = NULL_TREE, orig_decl = NULL_TREE;
   tree init_block, body_block;
   tree init_placeholder, body_placeholder;
   tree init_scope;
@@ -45324,8 +45324,6 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p)
   if (!parens.require_open (parser))
 return NULL;
 
-  init = orig_init = decl = real_decl = orig_decl = NULL_TREE;
-
   init_placeholder = build_stmt (input_location, EXPR_STMT,
 integer_zero_node);
   vec_safe_push (omp_for_parse_state->init_placeholderv, init_placeholder);
@@ -45501,12 +45499,10 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool 
*if_p)
}
 }
 
-  cond = NULL;
   if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
 cond = cp_parser_omp_for_cond (parser, decl, omp_for_parse_state->code);
   cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
 
-  incr = NULL;
   if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
 {
   /* If decl is an iterator, preserve the operator on decl


[gcc r15-1614] c++: using non-dep array var of unknown bound [PR115358]

2024-06-25 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:e3915c1ad56591cbd68229a64c941c38330abd69

commit r15-1614-ge3915c1ad56591cbd68229a64c941c38330abd69
Author: Patrick Palka 
Date:   Tue Jun 25 10:42:21 2024 -0400

c++: using non-dep array var of unknown bound [PR115358]

For a non-dependent array variable of unknown bound, it seems we need to
try instantiating its definition upon use in a template context for sake
of proper checking and typing of the overall expression, like we do for
function specializations with deduced return type.

PR c++/115358

gcc/cp/ChangeLog:

* decl2.cc (mark_used): Call maybe_instantiate_decl for an array
variable with unknown bound.
* semantics.cc (finish_decltype_type): Remove now redundant
handling of array variables with unknown bound.
* typeck.cc (cxx_sizeof_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/template/array37.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/decl2.cc |  2 ++
 gcc/cp/semantics.cc |  7 ---
 gcc/cp/typeck.cc|  7 ---
 gcc/testsuite/g++.dg/template/array37.C | 14 ++
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 6c3ef60d51f..cdd2b8aada2 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -6001,6 +6001,8 @@ mark_used (tree decl, tsubst_flags_t complain /* = 
tf_warning_or_error */)
  find out its type.  For OpenMP user defined reductions, we need them
  instantiated for reduction clauses which inline them by hand directly.  */
   if (undeduced_auto_decl (decl)
+  || (VAR_P (decl)
+ && VAR_HAD_UNKNOWN_BOUND (decl))
   || (TREE_CODE (decl) == FUNCTION_DECL
  && DECL_OMP_DECLARE_REDUCTION_P (decl)))
 maybe_instantiate_decl (decl);
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 08f5f245e7d..6c1813d37c6 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12002,13 +12002,6 @@ finish_decltype_type (tree expr, bool 
id_expression_or_member_access_p,
   return error_mark_node;
 }
 
-  /* To get the size of a static data member declared as an array of
- unknown bound, we need to instantiate it.  */
-  if (VAR_P (expr)
-  && VAR_HAD_UNKNOWN_BOUND (expr)
-  && DECL_TEMPLATE_INSTANTIATION (expr))
-instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false);
-
   if (id_expression_or_member_access_p)
 {
   /* If e is an id-expression or a class member access (5.2.5
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 717eb63eb98..50f48768a95 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -2130,13 +2130,6 @@ cxx_sizeof_expr (location_t loc, tree e, tsubst_flags_t 
complain)
   location_t e_loc = cp_expr_loc_or_loc (e, loc);
   STRIP_ANY_LOCATION_WRAPPER (e);
 
-  /* To get the size of a static data member declared as an array of
- unknown bound, we need to instantiate it.  */
-  if (VAR_P (e)
-  && VAR_HAD_UNKNOWN_BOUND (e)
-  && DECL_TEMPLATE_INSTANTIATION (e))
-instantiate_decl (e, /*defer_ok*/true, /*expl_inst_mem*/false);
-
   if (TREE_CODE (e) == PARM_DECL
   && DECL_ARRAY_PARAMETER_P (e)
   && (complain & tf_warning))
diff --git a/gcc/testsuite/g++.dg/template/array37.C 
b/gcc/testsuite/g++.dg/template/array37.C
new file mode 100644
index 000..c5c11663a4d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/array37.C
@@ -0,0 +1,14 @@
+// PR c++/115358
+
+template
+struct A { static int STR[]; };
+
+template
+int A::STR[] = {1,2,3};
+
+void f(int(&)[3]);
+
+template
+void g() {
+  f(A::STR); // { dg-bogus "int []" }
+}


[gcc r15-1615] c++: alias CTAD and copy deduction guide [PR115198]

2024-06-25 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:06ebb7c6f31fe42ffdea6f51ac1ba1f6b058c090

commit r15-1615-g06ebb7c6f31fe42ffdea6f51ac1ba1f6b058c090
Author: Patrick Palka 
Date:   Tue Jun 25 12:59:24 2024 -0400

c++: alias CTAD and copy deduction guide [PR115198]

Here we're neglecting to update DECL_NAME during the alias CTAD guide
transformation, which causes copy_guide_p to return false for the
transformed copy deduction guide since DECL_NAME is still __dguide_C
with TREE_TYPE C but it should be __dguide_A with TREE_TYPE A
(i.e. C).  This ultimately results in ambiguity during
overload resolution between the copy deduction guide vs copy ctor guide.

This patch makes us update DECL_NAME of a transformed guide accordingly
during alias/inherited CTAD.

PR c++/115198

gcc/cp/ChangeLog:

* pt.cc (alias_ctad_tweaks): Update DECL_NAME of the transformed
guides.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/class-deduction-alias22.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/pt.cc |  6 +-
 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias22.C | 14 ++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 607753ae6b7..daa8ac386dc 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -30342,13 +30342,14 @@ alias_ctad_tweaks (tree tmpl, tree uguides)
  any).  */
 
   enum { alias, inherited } ctad_kind;
-  tree atype, fullatparms, utype;
+  tree atype, fullatparms, utype, name;
   if (TREE_CODE (tmpl) == TEMPLATE_DECL)
 {
   ctad_kind = alias;
   atype = TREE_TYPE (tmpl);
   fullatparms = DECL_TEMPLATE_PARMS (tmpl);
   utype = DECL_ORIGINAL_TYPE (DECL_TEMPLATE_RESULT (tmpl));
+  name = dguide_name (tmpl);
 }
   else
 {
@@ -30356,6 +30357,8 @@ alias_ctad_tweaks (tree tmpl, tree uguides)
   atype = NULL_TREE;
   fullatparms = TREE_PURPOSE (tmpl);
   utype = TREE_VALUE (tmpl);
+  name = dguide_name (TPARMS_PRIMARY_TEMPLATE
+ (INNERMOST_TEMPLATE_PARMS (fullatparms)));
 }
 
   tsubst_flags_t complain = tf_warning_or_error;
@@ -30451,6 +30454,7 @@ alias_ctad_tweaks (tree tmpl, tree uguides)
}
  if (g == error_mark_node)
continue;
+ DECL_NAME (g) = name;
  if (nfparms == 0)
{
  /* The targs are all non-dependent, so g isn't a template.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias22.C 
b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias22.C
new file mode 100644
index 000..9c6c841166a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias22.C
@@ -0,0 +1,14 @@
+// PR c++/115198
+// { dg-do compile { target c++20 } }
+
+template
+struct C {
+  C() = default;
+  C(const C&) = default;
+};
+
+template
+using A = C;
+
+C c;
+A a = c; // { dg-bogus "ambiguous" }


[gcc r15-1616] late-combine: Honor targetm.cannot_copy_insn_p

2024-06-25 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:b87e19afa349691fdc91173bcf7a9afc7b3b0cb1

commit r15-1616-gb87e19afa349691fdc91173bcf7a9afc7b3b0cb1
Author: Richard Sandiford 
Date:   Tue Jun 25 18:02:35 2024 +0100

late-combine: Honor targetm.cannot_copy_insn_p

late-combine was failing to take targetm.cannot_copy_insn_p into
account, which led to multiple definitions of PIC symbols on
arm*-*-* targets.

gcc/
* late-combine.cc (insn_combination::substitute_nondebug_use):
Reject second and subsequent uses if targetm.cannot_copy_insn_p
disallows copying.

Diff:
---
 gcc/late-combine.cc | 12 
 1 file changed, 12 insertions(+)

diff --git a/gcc/late-combine.cc b/gcc/late-combine.cc
index fc75d1c56d7..b7c0bc07a8b 100644
--- a/gcc/late-combine.cc
+++ b/gcc/late-combine.cc
@@ -179,6 +179,18 @@ insn_combination::substitute_nondebug_use (use_info *use)
   if (dump_file && (dump_flags & TDF_DETAILS))
 dump_insn_slim (dump_file, use->insn ()->rtl ());
 
+  // Reject second and subsequent uses if the target does not allow
+  // the defining instruction to be copied.
+  if (targetm.cannot_copy_insn_p
+  && m_nondebug_changes.length () >= 2
+  && targetm.cannot_copy_insn_p (m_def_insn->rtl ()))
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "-- The target does not allow multiple"
+" copies of insn %d\n", m_def_insn->uid ());
+  return false;
+}
+
   // Check that we can change the instruction pattern.  Leave recognition
   // of the result till later.
   insn_propagation prop (use_rtl, m_dest, m_src);


[gcc r15-1617] [committed] Fix fr30-elf newlib build failure with late-combine

2024-06-25 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:7c28228cda274484b78611ea4c5cbe4ce08f512e

commit r15-1617-g7c28228cda274484b78611ea4c5cbe4ce08f512e
Author: Jeff Law 
Date:   Tue Jun 25 11:22:01 2024 -0600

[committed] Fix fr30-elf newlib build failure with late-combine

So the late combine work has exposed a latent bug in the fr30 port.

The fr30 "call" instruction is pc-relative with a *very* limited range, 12 
bits
to be precise.

With such a limited range its hard to see how we could ever consistently 
use it
in the compiler, with the possible exception of self-recursion.  Even for a
call to a locally binding function -ffunction-sections and linker placement 
of
functions may separate the caller/callee.  Code generation seemed to be 
using
indirect forms pretty consistently, though the RTL would allow direct calls.

With late-combine some of those indirects would be optimized into direct 
calls.
This naturally led to out of range scenarios.

With the fr30 port slated for removal unless it gets updated to use LRA and 
the
fundamental problems using direct calls, I took the shortest path to keep
things working -- namely forcing all calls to be indirect.

Tested in my tester with no regressions (and fixes the newlib build failure
with late-combine enabled).Pushed to the trunk.

gcc/
* config/fr30/constraints.md (Q): Remove unused constraint.
* config/fr30/predicates.md (call_operand): Remove unused predicate.
* config/fr30/fr30.md (call, vall_value): Turn into expanders and
force the call address into a register.
(*call, *call_value): Adjust to only allow indirect calls.  Adjust
output template accordingly.

Diff:
---
 gcc/config/fr30/constraints.md |  6 --
 gcc/config/fr30/fr30.md| 26 --
 gcc/config/fr30/predicates.md  | 10 --
 3 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/gcc/config/fr30/constraints.md b/gcc/config/fr30/constraints.md
index e4e2be1bfd9..1beee7cc3a2 100644
--- a/gcc/config/fr30/constraints.md
+++ b/gcc/config/fr30/constraints.md
@@ -63,9 +63,3 @@
   "An integer in the range -256 to 255."
   (and (match_code "const_int")
(match_test "IN_RANGE (ival, -256, 255)")))
-
-;; Extra constraints.
-(define_constraint "Q"
-  "@internal"
-  (and (match_code "mem")
-   (match_code "symbol_ref" "0")))
diff --git a/gcc/config/fr30/fr30.md b/gcc/config/fr30/fr30.md
index ecde60b455d..04f6d909054 100644
--- a/gcc/config/fr30/fr30.md
+++ b/gcc/config/fr30/fr30.md
@@ -1079,12 +1079,19 @@
 ;; `SImode', except it is normally a `const_int'); operand 2 is the number of
 ;; registers used as operands.
 
-(define_insn "call"
-  [(call (match_operand 0 "call_operand" "Qm")
+(define_expand "call"
+  [(parallel [(call (mem:QI (match_operand:SI  0 "register_operand" "r"))
+(match_operand 1 "" "g"))
+  (clobber (reg:SI 17))])]
+  ""
+  " { operands[0] = force_reg (SImode, XEXP (operands[0], 0)); } ")
+
+(define_insn "*call"
+  [(call (mem:QI (match_operand:SI 0 "register_operand" "r"))
 (match_operand 1 "" "g"))
(clobber (reg:SI 17))]
   ""
-  "call%#\\t%0"
+  "call%#\\t@%0"
   [(set_attr "delay_type" "delayed")]
 )
 
@@ -1094,14 +1101,21 @@
 ;; increased by one).
 
 ;; Subroutines that return `BLKmode' objects use the `call' insn.
+(define_expand "call_value"
+  [(parallel [(set (match_operand 0 "register_operand"  "=r")
+   (call (mem:QI (match_operand:SI 1 "register_operand" "r"))
+ (match_operand 2 "" "g")))
+  (clobber (reg:SI 17))])]
+  ""
+  " { operands[1] = force_reg (SImode, XEXP (operands[1], 0)); } ")
 
-(define_insn "call_value"
+(define_insn "*call_value"
   [(set (match_operand 0 "register_operand"  "=r")
-   (call (match_operand 1 "call_operand" "Qm")
+   (call (mem:QI (match_operand:SI 1 "register_operand" "r"))
  (match_operand 2 "" "g")))
(clobber (reg:SI 17))]
   ""
-  "call%#\\t%1"
+  "call%#\\t@%1"
   [(set_attr "delay_type" "delayed")]
 )
 
diff --git a/gcc/config/fr30/predicates.md b/gcc/config/fr30/predicates.md
index f67c6097430..2f87a4c81b2 100644
--- a/gcc/config/fr30/predicates.md
+++ b/gcc/config/fr30/predicates.md
@@ -51,16 +51,6 @@
  && REGNO (op) <= 7);
 })
 
-;; Returns true if OP is suitable for use in a CALL insn.
-
-(define_predicate "call_operand"
-  (match_code "mem")
-{
-  return (GET_CODE (op) == MEM
- && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
- || GET_CODE (XEXP (op, 0)) == REG));
-})
-
 ;; Returns TRUE if OP is a valid operand of a DImode operation.
 
 (define_predicate "di_operand"


[gcc r15-1618] PR modula2/115536 Expression is evaluated incorrectly when encountering relops and indirection

2024-06-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:9f168b412f44781013401492acfedf22afe7741b

commit r15-1618-g9f168b412f44781013401492acfedf22afe7741b
Author: Gaius Mulley 
Date:   Tue Jun 25 18:35:22 2024 +0100

PR modula2/115536 Expression is evaluated incorrectly when encountering 
relops and indirection

This fix ensures that we only call BuildRelOpFromBoolean if we are
inside a constant expression (where no indirection can be used).
The fix creates a temporary variable when a boolean is created from
a relop in other cases.
The previous pattern implementation would not work if the operands required
dereferencing during non const expressions.  Comparison of relop results
in a constant expression are resolved by constant propagation, basic
block analysis and dead code removal.  After the quadruples have been
optimized only one assignment to the boolean variable will remain for
const expressions.  All quadruple pattern checking for boolean
expressions is removed by the patch.  Thus the implementation becomes
more generic.

gcc/m2/ChangeLog:

PR modula2/115536
* gm2-compiler/M2BasicBlock.def (GetBasicBlockScope): New procedure.
(GetBasicBlockStart): Ditto.
(GetBasicBlockEnd): Ditto.
(IsBasicBlockFirst): New procedure function.
* gm2-compiler/M2BasicBlock.mod (ConvertQuads2BasicBlock): Allow
conditional boolean quads to be removed.
(GetBasicBlockScope): Implement new procedure.
(GetBasicBlockStart): Ditto.
(GetBasicBlockEnd): Ditto.
(IsBasicBlockFirst): Implement new procedure function.
* gm2-compiler/M2GCCDeclare.def (FoldConstants): New parameter
declaration.
* gm2-compiler/M2GCCDeclare.mod (FoldConstants): New parameter
declaration.
(DeclareTypesConstantsProceduresInRange): Recreate basic blocks
after resolving constant expressions.
(CodeBecomes): Guard IsVariableSSA with IsVar.
* gm2-compiler/M2GenGCC.def (ResolveConstantExpressions): New
parameter declaration.
* gm2-compiler/M2GenGCC.mod (FoldIfLess): Remove relop pattern
detection.
(FoldIfGre): Ditto.
(FoldIfLessEqu): Ditto.
(FoldIfGreEqu): Ditto.
(FoldIfIn): Ditto.
(FoldIfNotIn): Ditto.
(FoldIfEqu): Ditto.
(FoldIfNotEqu): Ditto.
(FoldBecomes): Add BasicBlock parameter and allow conditional
boolean becomes to be folded in the first basic block.
(ResolveConstantExpressions): Reimplement.
* gm2-compiler/M2Quads.def (IsConstQuad): New procedure function.
(IsConditionalBooleanQuad): Ditto.
* gm2-compiler/M2Quads.mod (IsConstQuad): Implement new procedure 
function.
(IsConditionalBooleanQuad): Ditto.
(MoveWithMode): Use GenQuadOTypetok.
(IsInitialisingConst): Rewrite using OpUsesOp1.
(OpUsesOp1): New procedure function.
(doBuildAssignment): Mark des as a VarConditional.
(ConvertBooleanToVariable): Call PutVarConditional.
(DumpQuadSummary): New procedure.
(BuildRelOpFromBoolean): Updated debugging and improved comments.
(BuildRelOp): Only call BuildRelOpFromBoolean if we are in a const
expression and both operands are boolean relops.
(GenQuadOTypeUniquetok): New procedure.
(BackPatch): Correct comment.
* gm2-compiler/SymbolTable.def (PutVarConditional): New procedure.
(IsVarConditional): New procedure function.
* gm2-compiler/SymbolTable.mod (PutVarConditional): Implement new
procedure.
(IsVarConditional): Implement new procedure function.
(SymConstVar): New field IsConditional.
(SymVar): New field IsConditional.
(MakeVar): Initialize IsConditional field.
(MakeConstVar): Initialize IsConditional field.
* gm2-compiler/M2Swig.mod (DoBasicBlock): Change parameters to
use BasicBlock.
* gm2-compiler/M2Code.mod (SecondDeclareAndOptimize): Use iterator
to FoldConstants over basic block list.
* gm2-compiler/M2SymInit.mod (AppendEntry): Replace parameters
with BasicBlock.
* gm2-compiler/P3Build.bnf (Relation): Call RecordOp for #, <> and 
=.

gcc/testsuite/ChangeLog:

PR modula2/115536
* gm2/iso/const/pass/constbool4.mod: New test.
* gm2/iso/const/pass/constbool5.mod: New test.
* gm2/iso/run/pass/condtest2.mod: New test.
* gm2/iso/run/pass/condtest3.mod: New test.
* gm2/iso/run/pass/condtest4.mod: New test.
* gm2/iso/run/pass/condtest5.mod: New test.
* gm2/iso/run/pass/constbool4.

[gcc r15-1619] ira: Scale save/restore costs of callee save registers with block frequency

2024-06-25 Thread Surya Kumari Jangala via Gcc-cvs
https://gcc.gnu.org/g:3b9b8d6cfdf59337f4b7ce10ce92a98044b2657b

commit r15-1619-g3b9b8d6cfdf59337f4b7ce10ce92a98044b2657b
Author: Surya Kumari Jangala 
Date:   Tue Jun 25 08:37:49 2024 -0500

ira: Scale save/restore costs of callee save registers with block frequency

In assign_hard_reg(), when computing the costs of the hard registers, the
cost of saving/restoring a callee-save hard register in prolog/epilog is
taken into consideration. However, this cost is not scaled with the entry
block frequency. Without scaling, the cost of saving/restoring is quite
small and this can result in a callee-save register being chosen by
assign_hard_reg() even though there are free caller-save registers
available. Assigning a callee save register to a pseudo that is live
in the entire function and across a call will cause shrink wrap to fail.

2024-06-25  Surya Kumari Jangala  

gcc/
PR rtl-optimization/111673
* ira-color.cc (assign_hard_reg): Scale save/restore costs of
callee save registers with block frequency.

gcc/testsuite/
PR rtl-optimization/111673
* gcc.target/powerpc/pr111673.c: New test.

Diff:
---
 gcc/ira-color.cc|  4 +++-
 gcc/testsuite/gcc.target/powerpc/pr111673.c | 17 +
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/ira-color.cc b/gcc/ira-color.cc
index b9ae32d1b4d..ca32a23a0c9 100644
--- a/gcc/ira-color.cc
+++ b/gcc/ira-color.cc
@@ -2178,7 +2178,9 @@ assign_hard_reg (ira_allocno_t a, bool retry_p)
add_cost = ((ira_memory_move_cost[mode][rclass][0]
 + ira_memory_move_cost[mode][rclass][1])
* saved_nregs / hard_regno_nregs (hard_regno,
- mode) - 1);
+ mode) - 1)
+  * (optimize_size ? 1 :
+ REG_FREQ_FROM_BB (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
cost += add_cost;
full_cost += add_cost;
  }
diff --git a/gcc/testsuite/gcc.target/powerpc/pr111673.c 
b/gcc/testsuite/gcc.target/powerpc/pr111673.c
new file mode 100644
index 000..e0c0f85460a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr111673.c
@@ -0,0 +1,17 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-O2 -fdump-rtl-pro_and_epilogue" } */
+
+/* Verify there is an early return without the prolog and shrink-wrap
+   the function. */
+
+int f (int);
+int
+advance (int dz)
+{
+  if (dz > 0)
+return (dz + dz) * dz;
+  else
+return dz * f (dz);
+}
+
+/* { dg-final { scan-rtl-dump-times "Performing shrink-wrapping" 1 
"pro_and_epilogue" } } */


[gcc r15-1620] c++: ICE with __dynamic_cast redecl [PR115501]

2024-06-25 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:71f484d02b2b3e8616cd7af27a0d4c72e4c7e977

commit r15-1620-g71f484d02b2b3e8616cd7af27a0d4c72e4c7e977
Author: Marek Polacek 
Date:   Tue Jun 18 10:50:49 2024 -0400

c++: ICE with __dynamic_cast redecl [PR115501]

Since r13-3299, build_dynamic_cast_1 calls pushdecl which calls
duplicate_decls and that in this testcase emits the "conflicting
declaration" error and returns error_mark_node, so the subsequent
build_cxx_call crashes on the error_mark_node.

PR c++/115501

gcc/cp/ChangeLog:

* rtti.cc (build_dynamic_cast_1): Return if dcast_fn is erroneous.

gcc/testsuite/ChangeLog:

* g++.dg/rtti/dyncast8.C: New test.

Diff:
---
 gcc/cp/rtti.cc   |  2 ++
 gcc/testsuite/g++.dg/rtti/dyncast8.C | 15 +++
 2 files changed, 17 insertions(+)

diff --git a/gcc/cp/rtti.cc b/gcc/cp/rtti.cc
index ed69606f4dd..cc006ea927f 100644
--- a/gcc/cp/rtti.cc
+++ b/gcc/cp/rtti.cc
@@ -794,6 +794,8 @@ build_dynamic_cast_1 (location_t loc, tree type, tree expr,
  pop_abi_namespace (flags);
  dynamic_cast_node = dcast_fn;
}
+ if (dcast_fn == error_mark_node)
+   return error_mark_node;
  result = build_cxx_call (dcast_fn, 4, elems, complain);
  SET_EXPR_LOCATION (result, loc);
 
diff --git a/gcc/testsuite/g++.dg/rtti/dyncast8.C 
b/gcc/testsuite/g++.dg/rtti/dyncast8.C
new file mode 100644
index 000..de23433dd9b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/dyncast8.C
@@ -0,0 +1,15 @@
+// PR c++/115501
+// { dg-do compile }
+
+struct s{virtual void f();};
+struct s1 : s{};
+namespace __cxxabiv1
+{
+  extern "C" void __dynamic_cast(); // { dg-message "previous declaration" }
+}
+void diagnostic_information_impl(s const *se)
+{
+  dynamic_cast(se);
+}
+
+// { dg-error "conflicting declaration" "" { target *-*-* } 0 }


[gcc r15-1621] c++: ICE with generic lambda and pack expansion [PR115425]

2024-06-25 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:ed6ffc4e62f716d1b31d599d22594dd969da137f

commit r15-1621-ged6ffc4e62f716d1b31d599d22594dd969da137f
Author: Marek Polacek 
Date:   Fri Jun 14 17:50:29 2024 -0400

c++: ICE with generic lambda and pack expansion [PR115425]

In r13-272 we hardened the *_PACK_EXPANSION and *_ARGUMENT_PACK macros.
That trips up here because make_pack_expansion returns error_mark_node
and we access that with PACK_EXPANSION_LOCAL_P.

PR c++/115425

gcc/cp/ChangeLog:

* pt.cc (tsubst_pack_expansion): Return error_mark_node if
make_pack_expansion doesn't work out.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-generic12.C: New test.

Diff:
---
 gcc/cp/pt.cc  |  2 ++
 gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C | 25 +
 2 files changed, 27 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index daa8ac386dc..017cc7fd0ab 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -13775,6 +13775,8 @@ tsubst_pack_expansion (tree t, tree args, 
tsubst_flags_t complain,
   else
result = tsubst (pattern, args, complain, in_decl);
   result = make_pack_expansion (result, complain);
+  if (result == error_mark_node)
+   return error_mark_node;
   PACK_EXPANSION_LOCAL_P (result) = PACK_EXPANSION_LOCAL_P (t);
   PACK_EXPANSION_SIZEOF_P (result) = PACK_EXPANSION_SIZEOF_P (t);
   if (PACK_EXPANSION_AUTO_P (t))
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C
new file mode 100644
index 000..219529c7c32
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C
@@ -0,0 +1,25 @@
+// PR c++/115425
+// { dg-do compile { target c++20 } }
+
+using size_t = decltype(sizeof(0));
+
+template 
+struct X {};
+
+template
+void foo(X);
+
+template
+struct S;
+
+template
+auto test() {
+  constexpr static auto x = foo>(); // { dg-error "no 
matching function" }
+  return [](X) {
+(typename S::type{}, ...);
+  }(X<__integer_pack (0)...>{});
+}
+
+int main() {
+  test();
+}


[gcc r15-1622] Add param for bb limit to invoke fast_vrp.

2024-06-25 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:1ea95cc5e099d554764b82df8e972129e9d20885

commit r15-1622-g1ea95cc5e099d554764b82df8e972129e9d20885
Author: Andrew MacLeod 
Date:   Mon Jun 17 11:38:46 2024 -0400

Add param for bb limit to invoke fast_vrp.

If the basic block count is too high, simply use fast_vrp for all
VRP passes.

* doc/invoke.texi (vrp-block-limit): Document.
* params.opt (param=vrp-block-limit): New.
* tree-vrp.cc (fvrp_folder::execute): Invoke fast_vrp if block
count exceeds limit.

Diff:
---
 gcc/doc/invoke.texi |  3 +++
 gcc/params.opt  |  4 
 gcc/tree-vrp.cc | 14 --
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 23d90db2925..729dbc1691e 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -16849,6 +16849,9 @@ this parameter.  The default value of this parameter is 
50.
 @item vect-induction-float
 Enable loop vectorization of floating point inductions.
 
+@item vrp-block-limit
+Maximum number of basic blocks before VRP switches to a lower memory algorithm.
+
 @item vrp-sparse-threshold
 Maximum number of basic blocks before VRP uses a sparse bitmap cache.
 
diff --git a/gcc/params.opt b/gcc/params.opt
index d34ef545bf0..c17ba17b91b 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -1198,6 +1198,10 @@ The maximum factor which the loop vectorizer applies to 
the cost of statements i
 Common Joined UInteger Var(param_vect_induction_float) Init(1) IntegerRange(0, 
1) Param Optimization
 Enable loop vectorization of floating point inductions.
 
+-param=vrp-block-limit=
+Common Joined UInteger Var(param_vrp_block_limit) Init(15) Optimization 
Param
+Maximum number of basic blocks before VRP switches to a fast model with less 
memory requirements.
+
 -param=vrp-sparse-threshold=
 Common Joined UInteger Var(param_vrp_sparse_threshold) Init(3000) Optimization 
Param
 Maximum number of basic blocks before VRP uses a sparse bitmap cache.
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 26979b706e5..e184e9af51e 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -60,6 +60,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-cp.h"
 #include "ipa-prop.h"
 #include "attribs.h"
+#include "diagnostic-core.h"
 
 // This class is utilized by VRP and ranger to remove __builtin_unreachable
 // calls, and reflect any resulting global ranges.
@@ -1331,9 +1332,18 @@ public:
   unsigned int execute (function *fun) final override
 {
   // Check for fast vrp.
-  if (&data == &pass_data_fast_vrp)
+  bool use_fvrp = (&data == &pass_data_fast_vrp);
+  if (!use_fvrp && last_basic_block_for_fn (fun) > param_vrp_block_limit)
+   {
+ use_fvrp = true;
+ warning (OPT_Wdisabled_optimization,
+  "Using fast VRP algorithm. %d basic blocks"
+  " exceeds %<--param=vrp-block-limit=%d%> limit",
+  n_basic_blocks_for_fn (fun),
+  param_vrp_block_limit);
+   }
+  if (use_fvrp)
return execute_fast_vrp (fun, final_p);
-
   return execute_ranger_vrp (fun, final_p);
 }


[gcc r15-1623] PR modula2/115540 gcc/m2/mc-boot-ch/Gtermios.cc error return-statement with a value

2024-06-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d16355c72c7f7b54ecf06371d14d7ad309ea4c34

commit r15-1623-gd16355c72c7f7b54ecf06371d14d7ad309ea4c34
Author: Gaius Mulley 
Date:   Tue Jun 25 21:37:44 2024 +0100

PR modula2/115540 gcc/m2/mc-boot-ch/Gtermios.cc error return-statement with 
a value

This patch fixes three occurrences of cfmakeraw use in the hand built
m2 support libraries which incorrectly attempt to return a void
result.

gcc/m2/ChangeLog:

PR modula2/115540
* gm2-libs-ch/termios.c (cfmakeraw): Remove return.
* mc-boot-ch/Gtermios.cc (cfmakeraw): Remove return.
* pge-boot/Gtermios.cc (cfmakeraw): Remove return.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-libs-ch/termios.c  | 2 +-
 gcc/m2/mc-boot-ch/Gtermios.cc | 2 +-
 gcc/m2/pge-boot/Gtermios.cc   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/m2/gm2-libs-ch/termios.c b/gcc/m2/gm2-libs-ch/termios.c
index 472a4c022e8..fe7403b3dee 100644
--- a/gcc/m2/gm2-libs-ch/termios.c
+++ b/gcc/m2/gm2-libs-ch/termios.c
@@ -281,7 +281,7 @@ int EXPORT (tcsetattr) (int fd, int option, struct termios 
*t)
 void EXPORT (cfmakeraw) (struct termios *t)
 {
 #if defined(HAVE_CFMAKERAW)
-  return cfmakeraw (t);
+  cfmakeraw (t);
 #endif
 }
 
diff --git a/gcc/m2/mc-boot-ch/Gtermios.cc b/gcc/m2/mc-boot-ch/Gtermios.cc
index a11065a6725..0ef5c8ba803 100644
--- a/gcc/m2/mc-boot-ch/Gtermios.cc
+++ b/gcc/m2/mc-boot-ch/Gtermios.cc
@@ -289,7 +289,7 @@ void
 EXPORT (cfmakeraw) (struct termios *t)
 {
 #if defined(HAVE_CFMAKERAW)
-  return cfmakeraw (t);
+  cfmakeraw (t);
 #endif
 }
 
diff --git a/gcc/m2/pge-boot/Gtermios.cc b/gcc/m2/pge-boot/Gtermios.cc
index 4f3557619db..5f966403b19 100644
--- a/gcc/m2/pge-boot/Gtermios.cc
+++ b/gcc/m2/pge-boot/Gtermios.cc
@@ -289,7 +289,7 @@ void
 EXPORT (cfmakeraw) (struct termios *t)
 {
 #if defined(HAVE_CFMAKERAW)
-  return cfmakeraw (t);
+  cfmakeraw (t);
 #endif
 }


[gcc r15-1624] [PATCH v2 3/3] RISC-V: cmpmem for RISCV with V extension

2024-06-25 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:b1e828dd9694294de1ec71e319d32a6b30b087d8

commit r15-1624-gb1e828dd9694294de1ec71e319d32a6b30b087d8
Author: Sergei Lewis 
Date:   Tue Jun 25 15:26:14 2024 -0600

[PATCH v2 3/3] RISC-V: cmpmem for RISCV with V extension

So this is the cmpmem patch from Sergei, updated for the trunk.

Updates included adjusting the existing cmpmemsi expander to
conditionally try expansion via vector.  And a minor testsuite
adjustment to turn off vector expansion in one test that is primarily
focused on vset optimization and ensuring we don't have extras.

I've spun this in my tester successfully and just want to see a clean
run through precommit CI before moving forward.

Jeff
gcc/ChangeLog:

* config/riscv/riscv-protos.h (riscv_vector::expand_vec_cmpmem): New
function declaration.
* config/riscv/riscv-string.cc (riscv_vector::expand_vec_cmpmem): 
New
function.
* config/riscv/riscv.md (cmpmemsi): Try 
riscv_vector::expand_vec_cmpmem
for constant lengths.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/cmpmem-1.c: New codegen tests
* gcc.target/riscv/rvv/base/cmpmem-2.c: New execution tests
* gcc.target/riscv/rvv/base/cmpmem-3.c: New codegen tests
* gcc.target/riscv/rvv/base/cmpmem-4.c: New codegen tests
* gcc.target/riscv/rvv/autovec/vls/misalign-1.c: Turn off vector 
mem* and
str* handling.

Diff:
---
 gcc/config/riscv/riscv-protos.h|   1 +
 gcc/config/riscv/riscv-string.cc   | 100 +
 gcc/config/riscv/riscv.md  |   7 +-
 .../gcc.target/riscv/rvv/autovec/vls/misalign-1.c  |   2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/cmpmem-1.c |  88 ++
 gcc/testsuite/gcc.target/riscv/rvv/base/cmpmem-2.c |  74 +++
 gcc/testsuite/gcc.target/riscv/rvv/base/cmpmem-3.c |  45 ++
 gcc/testsuite/gcc.target/riscv/rvv/base/cmpmem-4.c |  62 +
 8 files changed, 377 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index a3380d4250d..a8b76173fa0 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -679,6 +679,7 @@ void expand_rawmemchr (machine_mode, rtx, rtx, rtx, bool = 
false);
 bool expand_strcmp (rtx, rtx, rtx, rtx, unsigned HOST_WIDE_INT, bool);
 void emit_vec_extract (rtx, rtx, rtx);
 bool expand_vec_setmem (rtx, rtx, rtx);
+bool expand_vec_cmpmem (rtx, rtx, rtx, rtx);
 
 /* Rounding mode bitfield for fixed point VXRM.  */
 enum fixed_point_rounding_mode
diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc
index 1ddebdcee3f..257a514d290 100644
--- a/gcc/config/riscv/riscv-string.cc
+++ b/gcc/config/riscv/riscv-string.cc
@@ -1605,4 +1605,104 @@ expand_vec_setmem (rtx dst_in, rtx length_in, rtx 
fill_value_in)
   return true;
 }
 
+/* Used by cmpmemsi in riscv.md.  */
+
+bool
+expand_vec_cmpmem (rtx result_out, rtx blk_a_in, rtx blk_b_in, rtx length_in)
+{
+  HOST_WIDE_INT lmul;
+  /* Check we are able and allowed to vectorise this operation;
+ bail if not.  */
+  if (!check_vectorise_memory_operation (length_in, lmul))
+return false;
+
+  /* Strategy:
+ load entire blocks at a and b into vector regs
+ generate mask of bytes that differ
+ find first set bit in mask
+ find offset of first set bit in mask, use 0 if none set
+ result is ((char*)a[offset] - (char*)b[offset])
+   */
+
+  machine_mode vmode
+  = riscv_vector::get_vector_mode (QImode, BYTES_PER_RISCV_VECTOR * lmul)
+ .require ();
+  rtx blk_a_addr = copy_addr_to_reg (XEXP (blk_a_in, 0));
+  rtx blk_a = change_address (blk_a_in, vmode, blk_a_addr);
+  rtx blk_b_addr = copy_addr_to_reg (XEXP (blk_b_in, 0));
+  rtx blk_b = change_address (blk_b_in, vmode, blk_b_addr);
+
+  rtx vec_a = gen_reg_rtx (vmode);
+  rtx vec_b = gen_reg_rtx (vmode);
+
+  machine_mode mask_mode = get_mask_mode (vmode);
+  rtx mask = gen_reg_rtx (mask_mode);
+  rtx mismatch_ofs = gen_reg_rtx (Pmode);
+
+  rtx ne = gen_rtx_NE (mask_mode, vec_a, vec_b);
+  rtx vmsops[] = { mask, ne, vec_a, vec_b };
+  rtx vfops[] = { mismatch_ofs, mask };
+
+  /* If the length is exactly vlmax for the selected mode, do that.
+ Otherwise, use a predicated store.  */
+
+  if (known_eq (GET_MODE_SIZE (vmode), INTVAL (length_in)))
+{
+  emit_move_insn (vec_a, blk_a);
+  emit_move_insn (vec_b, blk_b);
+  emit_vlmax_insn (code_for_pred_cmp (vmode), riscv_vector::COMPARE_OP,
+  vmsops);
+
+  emit_vlmax_insn (code_for_pred_ffs (mask_mode, Pmode),
+  riscv_vector::CPOP_OP, vfops);
+}
+  else
+{
+  if (!satisfies_constraint_K (length_in))
+ length_in = force_reg (Pmode, length_in);
+
+  rtx memmask = CONSTM1_RTX (mask_mode);

[gcc r15-1625] c++: ICE with __has_unique_object_representations [PR115476]

2024-06-25 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:fc382a373e6824bb998007d1dcb0805b0cf4b8e8

commit r15-1625-gfc382a373e6824bb998007d1dcb0805b0cf4b8e8
Author: Marek Polacek 
Date:   Mon Jun 17 17:53:12 2024 -0400

c++: ICE with __has_unique_object_representations [PR115476]

Here we started to ICE with r13-25: in check_trait_type, for "X[]" we
return true here:

  if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
return true; // Array of unknown bound. Don't care about completeness.

and then end up crashing in record_has_unique_obj_representations:

4836  if (cur != wi::to_offset (sz))

because sz is null.


https://eel.is/c++draft/type.traits#tab:meta.unary.prop-row-47-column-3-sentence-1
says that the preconditions for __has_unique_object_representations are:
"T shall be a complete type, cv void, or an array of unknown bound" and
that "For an array type T, the same result as
has_unique_object_representations_v>" so T[]
should be treated as T.  So we should use kind==2 for the trait.

PR c++/115476

gcc/cp/ChangeLog:

* semantics.cc (finish_trait_expr)
: Move below to call
check_trait_type with kind==2.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/has-unique-obj-representations4.C: New test.

Diff:
---
 gcc/cp/semantics.cc  |  2 +-
 .../g++.dg/cpp1z/has-unique-obj-representations4.C   | 16 
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 6c1813d37c6..8e3e4e23b72 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12959,7 +12959,6 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_HAS_NOTHROW_COPY:
 case CPTK_HAS_TRIVIAL_COPY:
 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
-case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   if (!check_trait_type (type1))
return error_mark_node;
   break;
@@ -12969,6 +12968,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_STD_LAYOUT:
 case CPTK_IS_TRIVIAL:
 case CPTK_IS_TRIVIALLY_COPYABLE:
+case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   if (!check_trait_type (type1, /* kind = */ 2))
return error_mark_node;
   break;
diff --git a/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations4.C 
b/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations4.C
new file mode 100644
index 000..d6949dc7005
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations4.C
@@ -0,0 +1,16 @@
+// PR c++/115476
+// { dg-do compile { target c++11 } }
+
+struct X;
+static_assert(__has_unique_object_representations(X), "");   // { dg-error 
"invalid use of incomplete type" }
+static_assert(__has_unique_object_representations(X[]), "");  // { dg-error 
"invalid use of incomplete type" }
+static_assert(__has_unique_object_representations(X[1]), "");  // { dg-error 
"invalid use of incomplete type" }
+static_assert(__has_unique_object_representations(X[][1]), "");  // { dg-error 
"invalid use of incomplete type" }
+
+struct X {
+  int x;
+};
+static_assert(__has_unique_object_representations(X), "");
+static_assert(__has_unique_object_representations(X[]), "");
+static_assert(__has_unique_object_representations(X[1]), "");
+static_assert(__has_unique_object_representations(X[][1]), "");


[gcc r14-10346] Fix PR c/115587, uninitialized variable in c_parser_omp_loop_nest

2024-06-25 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:b383719aebe45bbe8cc3944e515ed7caa30e8744

commit r14-10346-gb383719aebe45bbe8cc3944e515ed7caa30e8744
Author: Sandra Loosemore 
Date:   Tue Jun 25 13:54:43 2024 +

Fix PR c/115587, uninitialized variable in c_parser_omp_loop_nest

This function had a reference to an uninitialized variable on the
error path.  The problem was diagnosed by clang but not gcc.  It seems
the cleanest solution is to initialize all the loop-clause variables
at the point of declaration rather than at different places in the
code.

The C++ front end didn't have this problem, but I've made similar
changes there to keep the code in sync.

gcc/c/ChangeLog:

PR c/115587
* c-parser.cc (c_parser_omp_loop_nest): Move initializations to
point of declaration.

gcc/cp/ChangeLog:

PR c/115587
* parser.cc (cp_parser_omp_loop_nest): Move initializations to
point of declaration.

(cherry picked from commit 21f1073d388af8af207183b0ed592e1cc47d20ab)

Diff:
---
 gcc/c/c-parser.cc | 4 +---
 gcc/cp/parser.cc  | 8 ++--
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 00f8bf4376e..5fcfff7134a 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -22240,7 +22240,7 @@ c_parser_omp_scan_loop_body (c_parser *parser, bool 
open_brace_parsed)
 static tree
 c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
 {
-  tree decl, cond, incr, init;
+  tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE;
   tree body = NULL_TREE;
   matching_parens parens;
   bool moreloops;
@@ -22330,7 +22330,6 @@ c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
 }
 
   /* Parse the loop condition.  */
-  cond = NULL_TREE;
   if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
 {
   location_t cond_loc = c_parser_peek_token (parser)->location;
@@ -22363,7 +22362,6 @@ c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
 
   /* Parse the increment expression.  */
-  incr = NULL_TREE;
   if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
 {
   location_t incr_loc = c_parser_peek_token (parser)->location;
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 6b786ed8266..7e81c1010c4 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -44756,8 +44756,8 @@ cp_parser_omp_scan_loop_body (cp_parser *parser)
 static tree
 cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p)
 {
-  tree decl, cond, incr, init;
-  tree orig_init, real_decl, orig_decl;
+  tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE;
+  tree orig_init = NULL_TREE, real_decl = NULL_TREE, orig_decl = NULL_TREE;
   tree init_block, body_block;
   tree init_placeholder, body_placeholder;
   tree init_scope;
@@ -44793,8 +44793,6 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p)
   if (!parens.require_open (parser))
 return NULL;
 
-  init = orig_init = decl = real_decl = orig_decl = NULL_TREE;
-
   init_placeholder = build_stmt (input_location, EXPR_STMT,
 integer_zero_node);
   vec_safe_push (omp_for_parse_state->init_placeholderv, init_placeholder);
@@ -44970,12 +44968,10 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool 
*if_p)
}
 }
 
-  cond = NULL;
   if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
 cond = cp_parser_omp_for_cond (parser, decl, omp_for_parse_state->code);
   cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
 
-  incr = NULL;
   if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
 {
   /* If decl is an iterator, preserve the operator on decl


[gcc r15-1626] libstdc++: Replace viewcvs links in docs with cgit links

2024-06-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:9d8021d1875677286c3dde90dfed2aca864edad0

commit r15-1626-g9d8021d1875677286c3dde90dfed2aca864edad0
Author: Jonathan Wakely 
Date:   Tue Jun 25 13:35:17 2024 +0100

libstdc++: Replace viewcvs links in docs with cgit links

libstdc++-v3/ChangeLog:

* doc/xml/faq.xml: Replace viewcvs links with cgit links.
* doc/xml/manual/allocator.xml: Likewise.
* doc/xml/manual/mt_allocator.xml: Likewise.
* doc/html/*: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/api.html  |  2 +-
 libstdc++-v3/doc/html/faq.html  |  2 +-
 libstdc++-v3/doc/html/manual/memory.html| 10 +-
 libstdc++-v3/doc/html/manual/mt_allocator_impl.html |  6 +++---
 libstdc++-v3/doc/xml/faq.xml|  2 +-
 libstdc++-v3/doc/xml/manual/allocator.xml   | 10 +-
 libstdc++-v3/doc/xml/manual/mt_allocator.xml|  6 +++---
 7 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/libstdc++-v3/doc/html/api.html b/libstdc++-v3/doc/html/api.html
index b494d91f9af..d2cff093d8f 100644
--- a/libstdc++-v3/doc/html/api.html
+++ b/libstdc++-v3/doc/html/api.html
@@ -38,4 +38,4 @@
 
   In addition, a rendered set of man pages are available in the same
   location specified above. Start with C++Intro(3).
-Prev Up Next Home 

+Prev Up Next Home 

\ No newline at end of file
diff --git a/libstdc++-v3/doc/html/faq.html b/libstdc++-v3/doc/html/faq.html
index dcb94ba67dc..507555839f2 100644
--- a/libstdc++-v3/doc/html/faq.html
+++ b/libstdc++-v3/doc/html/faq.html
@@ -147,7 +147,7 @@
  The libstdc++ project is contributed to by several developers
  all over the world, in the same way as GCC or the Linux kernel.
  The current maintainers are listed in the
- https://gcc.gnu.org/viewcvs/gcc/trunk/MAINTAINERS?view=co"; 
target="_top">MAINTAINERS
+ https://gcc.gnu.org/cgit/gcc/tree/MAINTAINERS"; 
target="_top">MAINTAINERS
  file (look for "c++ runtime libs").
 
 Development and discussion is held on the libstdc++ mailing
diff --git a/libstdc++-v3/doc/html/manual/memory.html 
b/libstdc++-v3/doc/html/manual/memory.html
index 08ad2fd4dd8..6b707105969 100644
--- a/libstdc++-v3/doc/html/manual/memory.html
+++ b/libstdc++-v3/doc/html/manual/memory.html
@@ -120,8 +120,8 @@
Over multiple iterations, various STL container
  objects have elements inserted to some maximum amount. A variety
  of allocators are tested.
- Test source for http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/testsuite/performance/23_containers/insert/sequence.cc?view=markup";
 target="_top">sequence
- and http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/testsuite/performance/23_containers/insert/associative.cc?view=markup";
 target="_top">associative
+ Test source for https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc";
 target="_top">sequence
+ and https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc";
 target="_top">associative
  containers.

Insertion and erasure in a multi-threaded environment.
@@ -130,14 +130,14 @@
  on a per-thread basis, as well as measuring thread contention
  for memory resources.
  Test source
-http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/testsuite/performance/23_containers/insert_erase/associative.cc?view=markup";
 target="_top">here.
+https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc";
 target="_top">here.

 A threaded producer/consumer model.

Test source for
- http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc?view=markup";
 target="_top">sequence
+ https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc";
 target="_top">sequence
  and
- http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc?view=markup";
 target="_top">associative
+ https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc";
 target="_top">associative
  containers.
  
  Since GCC 12 the default choice for
diff --git a/libstdc++-v3/doc/html/manual/mt_allocator_impl.html 
b/libstdc++-v3/doc/html/manual/mt_allocator_impl.html
index 2e5926add00..c69b9c5b55a 100644
--- a/libstdc++-v3/doc/html/manual/mt_allocator_impl.html
+++ b/libstdc++-v3/doc/html/manual/mt_allocator_impl.html
@@ -155,7 +155,7 @@ that uses it is fully constructed. For most (but not all) 
STL
 containers, this works, as an instance of the allocator is constructed
 as part of a container's constructor. However, this assumption is
 implementation-specific, and subject to change. For an

[gcc r15-1627] modula2: tidyup remove unused procedures and unused parameters

2024-06-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:038144534a683d4248c9b98a7110a59b305f124a

commit r15-1627-g038144534a683d4248c9b98a7110a59b305f124a
Author: Gaius Mulley 
Date:   Tue Jun 25 23:11:29 2024 +0100

modula2: tidyup remove unused procedures and unused parameters

This patch removes M2GenGCC.mod:QuadCondition and
M2Quads.mod:GenQuadOTypeUniquetok.  It also removes unused parameter
WalkAction for all FoldIf procedures.

gcc/m2/ChangeLog:

* gm2-compiler/M2GenGCC.mod (QuadCondition): Remove.
(FoldIfEqu): Remove WalkAction parameter.
(FoldIfNotEqu): Ditto.
(FoldIfGreEqu): Ditto.
(FoldIfLessEqu): Ditto.
(FoldIfGre): Ditto.
(FoldIfLess): Ditto.
(FoldIfIn): Ditto.
(FoldIfNotIn): Ditto.
* gm2-compiler/M2Quads.mod (GenQuadOTypeUniquetok): Remove.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2GenGCC.mod | 77 +---
 gcc/m2/gm2-compiler/M2Quads.mod  | 52 ---
 2 files changed, 16 insertions(+), 113 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index c59695a3779..fc3fa204ac0 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -637,14 +637,14 @@ BEGIN
  CastOp : FoldCast (tokenno, p, quad, op1, op2, op3) |
  InclOp : FoldIncl (tokenno, p, quad, op1, op3) |
  ExclOp : FoldExcl (tokenno, p, quad, op1, op3) |
- IfEquOp: FoldIfEqu (tokenno, p, quad, op1, op2, op3) |
- IfNotEquOp : FoldIfNotEqu (tokenno, p, quad, op1, op2, op3) |
- IfLessOp   : FoldIfLess (tokenno, p, quad, op1, op2, op3) |
- IfLessEquOp: FoldIfLessEqu (tokenno, p, quad, op1, op2, op3) |
- IfGreOp: FoldIfGre (tokenno, p, quad, op1, op2, op3) |
- IfGreEquOp : FoldIfGreEqu (tokenno, p, quad, op1, op2, op3) |
- IfInOp : FoldIfIn (tokenno, p, quad, op1, op2, op3) |
- IfNotInOp  : FoldIfNotIn (tokenno, p, quad, op1, op2, op3) |
+ IfEquOp: FoldIfEqu (tokenno, quad, op1, op2, op3) |
+ IfNotEquOp : FoldIfNotEqu (tokenno, quad, op1, op2, op3) |
+ IfLessOp   : FoldIfLess (tokenno, quad, op1, op2, op3) |
+ IfLessEquOp: FoldIfLessEqu (tokenno, quad, op1, op2, op3) |
+ IfGreOp: FoldIfGre (tokenno, quad, op1, op2, op3) |
+ IfGreEquOp : FoldIfGreEqu (tokenno, quad, op1, op2, op3) |
+ IfInOp : FoldIfIn (tokenno, quad, op1, op2, op3) |
+ IfNotInOp  : FoldIfNotIn (tokenno, quad, op1, op2, op3) |
  LogicalShiftOp : FoldSetShift(tokenno, p, quad, op1, op2, op3) |
  LogicalRotateOp: FoldSetRotate (tokenno, p, quad, op1, op2, op3) |
  ParamOp: FoldBuiltinFunction (tokenno, p, quad, op1, op2, 
op3) |
@@ -5332,7 +5332,7 @@ END FoldIncl ;
 if op1 < op2 then goto op3.
 *)
 
-PROCEDURE FoldIfLess (tokenno: CARDINAL; p: WalkAction;
+PROCEDURE FoldIfLess (tokenno: CARDINAL;
   quad: CARDINAL; left, right, destQuad: CARDINAL) ;
 BEGIN
(* Firstly ensure that constant literals are declared.  *)
@@ -5357,57 +5357,12 @@ BEGIN
 END FoldIfLess ;
 
 
-(*
-   QuadCondition - Pre-condition:  left, right operands are constants
-   which have been resolved.
-   Post-condition: return TRUE if the condition at
-   quad is TRUE.
-*)
-
-PROCEDURE QuadCondition (quad: CARDINAL) : BOOLEAN ;
-VAR
-   left, right, dest, combined,
-   leftpos, rightpos, destpos : CARDINAL ;
-   constExpr, overflow: BOOLEAN ;
-   op : QuadOperator ;
-BEGIN
-   GetQuadOtok (quad, combined, op,
-left, right, dest, overflow,
-constExpr,
-leftpos, rightpos, destpos) ;
-   CASE op OF
-
-   IfInOp :  PushValue (right) ;
- RETURN SetIn (left, combined) |
-   IfNotInOp  :  PushValue (right) ;
- RETURN NOT SetIn (left, combined)
-
-   ELSE
-   END ;
-   PushValue (left) ;
-   PushValue (right) ;
-   CASE op OF
-
-   IfGreOp:  RETURN Gre (combined) |
-   IfLessOp   :  RETURN Less (combined) |
-   IfLessEquOp:  RETURN LessEqu (combined) |
-   IfGreEquOp :  RETURN GreEqu (combined) |
-   IfEquOp:  RETURN GreEqu (combined) |
-   IfNotEquOp :  RETURN NotEqu (combined)
-
-   ELSE
-  InternalError ('unrecognized comparison operator')
-   END ;
-   RETURN FALSE
-END QuadCondition ;
-
-
 (*
FoldIfGre - check to see if it is possible to evaluate
if op1 > op2 then goto op3.
 *)
 
-PROCEDURE FoldIfGre (tokenno: CARDINAL; p: WalkAction;
+PROCEDURE FoldIfGre (tokenno: CARDINAL;
  quad: CARDINAL;
  lef

[gcc r11-11537] libstdc++: Replace reference to mainline in release branch docs

2024-06-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:7d60b932ccd658078173abc13251e0a120dafd9d

commit r11-11537-g7d60b932ccd658078173abc13251e0a120dafd9d
Author: Jonathan Wakely 
Date:   Tue Jun 25 23:20:49 2024 +0100

libstdc++: Replace reference to mainline in release branch docs

libstdc++-v3/ChangeLog:

* doc/xml/manual/status_cxx2023.xml: Change reference from
mainline GCC to the release branch.
* doc/html/manual/status.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/status.html   | 3 +--
 libstdc++-v3/doc/xml/manual/status_cxx2023.xml | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/status.html 
b/libstdc++-v3/doc/html/manual/status.html
index 3805e9e24f0..838cba72f47 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -1702,8 +1702,7 @@ options. The pre-defined symbol
 __cplusplus is used to check for the
 presence of the required flag.
 
-This section describes the C++23 and library TS support in mainline GCC,
-not in any particular release.
+This section describes the C++23 and library TS support in the GCC 11 release 
series.
 
 The following table lists new library features that have been accepted into
 the C++23 working draft. The "Proposal" column provides a link to the
diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2023.xml 
b/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
index 75f31f55aa9..381f989d482 100644
--- a/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
+++ b/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
@@ -20,8 +20,7 @@ presence of the required flag.
 
 
 
-This section describes the C++23 and library TS support in mainline GCC,
-not in any particular release.
+This section describes the C++23 and library TS support in the GCC 11 release 
series.
 
 
 


[gcc r12-10581] libstdc++: Remove confusing text from status tables for release branch

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

commit r12-10581-g4b69afd72ea8aaa8921c8049049f412614e1327d
Author: Jonathan Wakely 
Date:   Tue Jun 25 23:25:54 2024 +0100

libstdc++: Remove confusing text from status tables for release branch

When I tried to make the release branch versions of these docs refer to
the release branch instead of "mainline GCC", for some reason I left the
text "not any particular release" there. That's just confusing, because
the docs are for a particular release, the latest on that branch. Remove
that confusing text in several places.

libstdc++-v3/ChangeLog:

* doc/xml/manual/status_cxx2023.xml: Change reference from
mainline GCC to the release branch.
* doc/xml/manual/status_cxx1998.xml: Remove confusing "not in
any particular release" text.
* doc/xml/manual/status_cxx2011.xml: Likewise.
* doc/xml/manual/status_cxx2014.xml: Likewise.
* doc/xml/manual/status_cxx2017.xml: Likewise.
* doc/xml/manual/status_cxx2020.xml: Likewise.
* doc/xml/manual/status_cxxtr1.xml: Likewise.
* doc/xml/manual/status_cxxtr24733.xml: Likewise.
* doc/html/manual/status.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/status.html  | 24 ---
 libstdc++-v3/doc/xml/manual/status_cxx1998.xml|  3 +--
 libstdc++-v3/doc/xml/manual/status_cxx2011.xml|  3 +--
 libstdc++-v3/doc/xml/manual/status_cxx2014.xml|  3 +--
 libstdc++-v3/doc/xml/manual/status_cxx2017.xml|  3 +--
 libstdc++-v3/doc/xml/manual/status_cxx2020.xml|  3 +--
 libstdc++-v3/doc/xml/manual/status_cxx2023.xml|  3 +--
 libstdc++-v3/doc/xml/manual/status_cxxtr1.xml |  3 +--
 libstdc++-v3/doc/xml/manual/status_cxxtr24733.xml |  3 +--
 9 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/status.html 
b/libstdc++-v3/doc/html/manual/status.html
index a6494912c07..c212ea64fe6 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -5,8 +5,7 @@
  NextChapter 1. StatusTable of ContentsImplementation 
StatusC++ 
1998/2003Implementation 
StatusImplementation Specific 
BehaviorC++ 2011Implementation Specific 
BehaviorC++ 
2014Implementation Specific 
BehaviorFilesystem 
TSC++ 2017Implementation Specific 
BehaviorParallelism 2 
TSC++ 2020C++ 
2023C++ TR1Implementation Specific BehaviorC++ TR 
24733C++ IS 
29124Implementation Specific 
BehaviorLicenseThe Code: 
GPLThe Documentation: GPL, 
FDLBugsImplementation 
BugsStandard Bugs
 Implementation 
StatusC++ 
1998/2003Implementation Status
 This status table is based on the table of contents of ISO/IEC 14882:2003.
 
-This section describes the C++ support in the GCC 12 release series,
-not in any particular release.
+This section describes the C++ support in the GCC 12 release series.
 Table 1.1. C++ 1998/2003 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -160,8 +159,7 @@ since that release.
 
 This status table is based on the table of contents of ISO/IEC 14882:2011.
 
-This section describes the C++11 support in the GCC 12 release series,
-not in any particular release.
+This section describes the C++11 support in the GCC 12 release series.
 Table 1.2. C++ 2011 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -433,8 +431,7 @@ This status table is based on the table of contents of 
ISO/IEC 14882:2014.
 Some subclauses are not shown in the table where the content is unchanged
 since C++11 and the implementation is complete.
 
-This section describes the C++14 and library TS support in the GCC 12 release 
series,
-not in any particular release.
+This section describes the C++14 and library TS support in the GCC 12 release 
series.
 Table 1.3. C++ 2014 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -578,8 +575,7 @@ GCC 9.1 was the first release with non-experimental C++17 
support,
 so the API and ABI of features added in C++17 is only stable
 since that release.
 
-This section describes the C++17 and library TS support in the GCC 12 release 
series,
-not in any particular release.
+This section describes the C++17 and library TS support in the GCC 12 release 
series.
 
 The following table lists new library features that are included in
 the C++17 standard. The "Proposal" column provides a link to the
@@ -1254,8 +1250,7 @@ options. The pre-defined symbol
 __cplusplus is used to check for the
 presence of the required flag.
 
-This section describes the C++20 and library TS support in the GCC 12 release 
series,
-not in any particular release.
+This section describes the C++20 and library TS support in the GCC 12 release 
series.
 
 The following table lists new library features that are included in
 the C++20 standard. The "Proposal" column provides a link to the
@@ -1720,8 +1715,7 @@ opti

[gcc r13-8868] libstdc++: Remove confusing text from status tables for release branch

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

commit r13-8868-gbc6e4bd567867280dae832ec8edeec480c937e47
Author: Jonathan Wakely 
Date:   Tue Jun 25 23:25:54 2024 +0100

libstdc++: Remove confusing text from status tables for release branch

When I tried to make the release branch versions of these docs refer to
the release branch instead of "mainline GCC", for some reason I left the
text "not any particular release" there. That's just confusing, because
the docs are for a particular release, the latest on that branch. Remove
that confusing text in several places.

libstdc++-v3/ChangeLog:

* doc/xml/manual/status_cxx1998.xml: Remove confusing "not in
any particular release" text.
* doc/xml/manual/status_cxx2011.xml: Likewise.
* doc/xml/manual/status_cxx2014.xml: Likewise.
* doc/xml/manual/status_cxx2017.xml: Likewise.
* doc/xml/manual/status_cxx2020.xml: Likewise.
* doc/xml/manual/status_cxx2023.xml: Likewise.
* doc/xml/manual/status_cxxtr1.xml: Likewise.
* doc/xml/manual/status_cxxtr24733.xml: Likewise.
* doc/html/manual/status.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/status.html  | 16 
 libstdc++-v3/doc/xml/manual/status_cxx1998.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2011.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2014.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2017.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2020.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2023.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxxtr1.xml |  2 +-
 libstdc++-v3/doc/xml/manual/status_cxxtr24733.xml |  2 +-
 9 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/status.html 
b/libstdc++-v3/doc/html/manual/status.html
index 53957bd2e0d..a2c89002289 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -6,7 +6,7 @@
 This status table is based on the table of contents of ISO/IEC 14882:2003.
 
 This section describes the C++ support in
-the GCC 13 release series, not in any particular release.
+the GCC 13 release series.
 Table 1.1. C++ 1998/2003 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -161,7 +161,7 @@ since that release.
 This status table is based on the table of contents of ISO/IEC 14882:2011.
 
 This section describes the C++11 support in
-the GCC 13 release series, not in any particular release.
+the GCC 13 release series.
 Table 1.2. C++ 2011 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -434,7 +434,7 @@ Some subclauses are not shown in the table where the 
content is unchanged
 since C++11 and the implementation is complete.
 
 This section describes the C++14 and library TS support in
-the GCC 13 release series, not in any particular release.
+the GCC 13 release series.
 Table 1.3. C++ 2014 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -579,7 +579,7 @@ so the API and ABI of features added in C++17 is only stable
 since that release.
 
 This section describes the C++17 and library TS support in
-the GCC 13 release series, not in any particular release.
+the GCC 13 release series.
 
 The following table lists new library features that are included in
 the C++17 standard. The "Proposal" column provides a link to the
@@ -1255,7 +1255,7 @@ options. The pre-defined symbol
 presence of the required flag.
 
 This section describes the C++20 and library TS support in
-the GCC 13 release series, not in any particular release.
+the GCC 13 release series.
 
 The following table lists new library features that are included in
 the C++20 standard. The "Proposal" column provides a link to the
@@ -1725,7 +1725,7 @@ options. The pre-defined symbol
 presence of the required flag.
 
 This section describes the C++23 and library TS support in
-the GCC 13 release series, not in any particular release.
+the GCC 13 release series.
 
 The following table lists new library features that have been accepted into
 the C++23 working draft. The "Proposal" column provides a link to the
@@ -2123,7 +2123,7 @@ In this implementation the header names are prefixed by
 , and so on.
 
 This page describes the TR1 support in
-the GCC 13 release series, not in any particular release.
+the GCC 13 release series.
 Table 1.11. C++ TR1 Implementation 
StatusSectionDescriptionStatusComments2General Utilities2.1Reference wrappers 
 2.1.1Additions to header  
synopsisY 2.1.2Class template reference_wrapper  2.1.2.1reference_wrapper construct/copy/destroyY 2.1.2.2reference_wrapper assignmentY 2.1.2.3reference_wrapper accessY 2.1.2.4reference_wrapper invocationY 2.1.2.5reference_wrapper helper functionsY 
 2.2Smart pointers  2.2.1Additions to header  
synopsisY 2.2.2Class bad_

[gcc r14-10347] libstdc++: Remove confusing text from status tables for release branch

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

commit r14-10347-gf91d9b3e91e6077c3cab6d703375f186f1d8d43b
Author: Jonathan Wakely 
Date:   Tue Jun 25 23:25:54 2024 +0100

libstdc++: Remove confusing text from status tables for release branch

When I tried to make the release branch versions of these docs refer to
the release branch instead of "mainline GCC", for some reason I left the
text "not any particular release" there. That's just confusing, because
the docs are for a particular release, the latest on that branch. Remove
that confusing text in several places.

libstdc++-v3/ChangeLog:

* doc/xml/manual/status_cxx1998.xml: Remove confusing "not in
any particular release" text.
* doc/xml/manual/status_cxx2011.xml: Likewise.
* doc/xml/manual/status_cxx2014.xml: Likewise.
* doc/xml/manual/status_cxx2017.xml: Likewise.
* doc/xml/manual/status_cxx2020.xml: Likewise.
* doc/xml/manual/status_cxx2023.xml: Likewise.
* doc/xml/manual/status_cxxtr1.xml: Likewise.
* doc/xml/manual/status_cxxtr24733.xml: Likewise.
* doc/html/manual/status.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/status.html  | 16 
 libstdc++-v3/doc/xml/manual/status_cxx1998.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2011.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2014.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2017.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2020.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2023.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxxtr1.xml |  2 +-
 libstdc++-v3/doc/xml/manual/status_cxxtr24733.xml |  2 +-
 9 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/status.html 
b/libstdc++-v3/doc/html/manual/status.html
index c13ec20feaa..6dc4535aff6 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -6,7 +6,7 @@
 This status table is based on the table of contents of ISO/IEC 14882:2003.
 
 This section describes the C++ support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 Table 1.1. C++ 1998/2003 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -161,7 +161,7 @@ since that release.
 This status table is based on the table of contents of ISO/IEC 14882:2011.
 
 This section describes the C++11 support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 Table 1.2. C++ 2011 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -434,7 +434,7 @@ Some subclauses are not shown in the table where the 
content is unchanged
 since C++11 and the implementation is complete.
 
 This section describes the C++14 and library TS support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 Table 1.3. C++ 2014 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -579,7 +579,7 @@ so the API and ABI of features added in C++17 is only stable
 since that release.
 
 This section describes the C++17 and library TS support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 
 The following table lists new library features that are included in
 the C++17 standard. The "Proposal" column provides a link to the
@@ -1255,7 +1255,7 @@ options. The pre-defined symbol
 presence of the required flag.
 
 This section describes the C++20 and library TS support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 
 The following table lists new library features that are included in
 the C++20 standard. The "Proposal" column provides a link to the
@@ -1725,7 +1725,7 @@ options. The pre-defined symbol
 presence of the required flag.
 
 This section describes the C++23 and library TS support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 
 The following table lists new library features that have been accepted into
 the C++23 working draft. The "Proposal" column provides a link to the
@@ -2213,7 +2213,7 @@ In this implementation the header names are prefixed by
 , and so on.
 
 This page describes the TR1 support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 Table 1.11. C++ TR1 Implementation 
StatusSectionDescriptionStatusComments2General Utilities2.1Reference wrappers 
 2.1.1Additions to header  
synopsisY 2.1.2Class template reference_wrapper  2.1.2.1reference_wrapper construct/copy/destroyY 2.1.2.2reference_wrapper assignmentY 2.1.2.3reference_wrapper accessY 2.1.2.4reference_wrapper invocationY 2.1.2.5reference_wrapper helper functionsY 
 2.2Smart pointers  2.2.1Additions to header  
synopsisY 2.2.2Class bad

[gcc r15-1628] libstdc++: Simplify std::valarray initialization helpers

2024-06-25 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:7d413a87f15562b9ec21f462d565522b45e57c3c

commit r15-1628-g7d413a87f15562b9ec21f462d565522b45e57c3c
Author: Jonathan Wakely 
Date:   Wed Jun 19 13:38:58 2024 +0100

libstdc++: Simplify std::valarray initialization helpers

Dispatching to partial specializations doesn't really seem to offer much
benefit here. The __is_trivial(T) condition is a compile-time constant
so the untaken branches are dead code and don't cost us anything.

libstdc++-v3/ChangeLog:

* include/bits/valarray_array.h (_Array_default_ctor): Remove.
(__valarray_default_construct): Inline it into here.
(_Array_init_ctor): Remove.
(__valarray_fill_construct): Inline it into here.
(_Array_copy_ctor): Remove.
(__valarray_copy_construct(const T*, const T*, T*)): Inline it
into here.
(__valarray_copy_construct(const T*, size_t, size_t, T*)):
Use _GLIBCXX17_CONSTEXPR for constant condition.

Diff:
---
 libstdc++-v3/include/bits/valarray_array.h | 97 ++
 1 file changed, 18 insertions(+), 79 deletions(-)

diff --git a/libstdc++-v3/include/bits/valarray_array.h 
b/libstdc++-v3/include/bits/valarray_array.h
index 07c49ce1057..0dc28333f33 100644
--- a/libstdc++-v3/include/bits/valarray_array.h
+++ b/libstdc++-v3/include/bits/valarray_array.h
@@ -62,105 +62,44 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __valarray_release_memory(void* __p)
   { operator delete(__p); }
 
-  // Turn a raw-memory into an array of _Tp filled with _Tp()
-  // This is required in 'valarray v(n);'
-  template
-struct _Array_default_ctor
-{
-  // Please note that this isn't exception safe.  But
-  // valarrays aren't required to be exception safe.
-  inline static void
-  _S_do_it(_Tp* __b, _Tp* __e)
-  {
-   while (__b != __e)
- new(__b++) _Tp();
-  }
-};
-
-  template
-struct _Array_default_ctor<_Tp, true>
-{
-  // For trivial types, it suffices to say 'memset()'
-  inline static void
-  _S_do_it(_Tp* __b, _Tp* __e)
-  { __builtin_memset(__b, 0, (__e - __b) * sizeof(_Tp)); }
-};
-
+  // Turn raw-memory into an array of _Tp filled with _Tp().
+  // This is used in `valarray v(n);` and in `valarray::shift(n)`.
   template
 inline void
 __valarray_default_construct(_Tp* __b, _Tp* __e)
 {
-  _Array_default_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e);
+  if _GLIBCXX17_CONSTEXPR (__is_trivial(_Tp))
+   __builtin_memset(__b, 0, (__e - __b) * sizeof(_Tp));
+  else
+   while (__b != __e)
+ ::new(static_cast(__b++)) _Tp();
 }
 
   // Turn a raw-memory into an array of _Tp filled with __t
   // This is the required in valarray v(n, t).  Also
   // used in valarray<>::resize().
-  template
-struct _Array_init_ctor
-{
-  // Please note that this isn't exception safe.  But
-  // valarrays aren't required to be exception safe.
-  inline static void
-  _S_do_it(_Tp* __b, _Tp* __e, const _Tp __t)
-  {
-   while (__b != __e)
- new(__b++) _Tp(__t);
-  }
-};
-
-  template
-struct _Array_init_ctor<_Tp, true>
-{
-  inline static void
-  _S_do_it(_Tp* __b, _Tp* __e, const _Tp __t)
-  {
-   while (__b != __e)
- *__b++ = __t;
-  }
-};
-
   template
 inline void
 __valarray_fill_construct(_Tp* __b, _Tp* __e, const _Tp __t)
 {
-  _Array_init_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e, __t);
+  while (__b != __e)
+   ::new(static_cast(__b++)) _Tp(__t);
 }
 
-  //
   // copy-construct raw array [__o, *) from plain array [__b, __e)
-  // We can't just say 'memcpy()'
-  //
-  template
-struct _Array_copy_ctor
-{
-  // Please note that this isn't exception safe.  But
-  // valarrays aren't required to be exception safe.
-  inline static void
-  _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o)
-  {
-   while (__b != __e)
- new(__o++) _Tp(*__b++);
-  }
-};
-
-  template
-struct _Array_copy_ctor<_Tp, true>
-{
-  inline static void
-  _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o)
-  {
-   if (__b)
- __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp));
-  }
-};
-
   template
 inline void
 __valarray_copy_construct(const _Tp* __b, const _Tp* __e,
  _Tp* __restrict__ __o)
 {
-  _Array_copy_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e, __o);
+  if _GLIBCXX17_CONSTEXPR (__is_trivial(_Tp))
+   {
+ if (__b)
+   __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp));
+   }
+  else
+   while (__b != __e)
+ ::new(static_cast(__o++)) _Tp(*__b++);
 }
 
   // copy-construct raw array [__o, *) from strided array __a[<__n : __s>]
@@ -169,7 +108,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 __

[gcc r15-1629] [PATCH 08/11] Handle unions for CodeView.

2024-06-25 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:0a5f559fb369ac9568ff57835928ac3ce3517be7

commit r15-1629-g0a5f559fb369ac9568ff57835928ac3ce3517be7
Author: Mark Harmstone 
Date:   Tue Jun 25 17:28:49 2024 -0600

[PATCH 08/11] Handle unions for CodeView.

Translates DW_TAG_union_type DIEs into LF_UNION symbols.

gcc/
* dwarf2codeview.cc (write_lf_union): New function.
(write_custom_types): Call write_lf_union.
(add_struct_forward_def): Handle DW_TAG_union_type DIEs.
(get_type_num_struct): Handle unions.
(get_type_num): Handle DW_TAG_union_type DIEs.
* dwarf2codeview.h (LF_UNION): Define.

Diff:
---
 gcc/dwarf2codeview.cc | 91 +++
 gcc/dwarf2codeview.h  |  1 +
 2 files changed, 86 insertions(+), 6 deletions(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 9c6614f6297..9e3b64522b2 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -1454,6 +1454,72 @@ write_lf_structure (codeview_custom_type *t)
   asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
 }
 
+/* Write an LF_UNION type.  */
+
+static void
+write_lf_union (codeview_custom_type *t)
+{
+  size_t name_len, leaf_len;
+
+  /* This is lf_union in binutils and lfUnion in Microsoft's cvinfo.h:
+
+struct lf_union
+{
+  uint16_t size;
+  uint16_t kind;
+  uint16_t num_members;
+  uint16_t properties;
+  uint32_t field_list;
+  uint16_t length;
+  char name[];
+} ATTRIBUTE_PACKED;
+  */
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end - %LLcv_type%x_start\n",
+  t->num, t->num);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_start:\n", t->num);
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  fprint_whex (asm_out_file, t->kind);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_structure.num_members);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_structure.properties);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (4, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_structure.field_list);
+  putc ('\n', asm_out_file);
+
+  leaf_len = 12 + write_cv_integer (&t->lf_structure.length);
+
+  if (t->lf_structure.name)
+{
+  name_len = strlen (t->lf_structure.name) + 1;
+  ASM_OUTPUT_ASCII (asm_out_file, t->lf_structure.name, name_len);
+}
+  else
+{
+  static const char unnamed_struct[] = "";
+
+  name_len = sizeof (unnamed_struct);
+  ASM_OUTPUT_ASCII (asm_out_file, unnamed_struct, name_len);
+}
+
+  leaf_len += name_len;
+  write_cv_padding (4 - (leaf_len % 4));
+
+  free (t->lf_structure.name);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
+}
+
 /* Write the .debug$T section, which contains all of our custom type
definitions.  */
 
@@ -1492,6 +1558,10 @@ write_custom_types (void)
case LF_CLASS:
  write_lf_structure (custom_types);
  break;
+
+   case LF_UNION:
+ write_lf_union (custom_types);
+ break;
}
 
   free (custom_types);
@@ -2026,7 +2096,7 @@ flush_deferred_types (void)
   last_deferred_type = NULL;
 }
 
-/* Add a forward definition for a struct or class.  */
+/* Add a forward definition for a struct, class, or union.  */
 
 static uint32_t
 add_struct_forward_def (dw_die_ref type)
@@ -2047,6 +2117,10 @@ add_struct_forward_def (dw_die_ref type)
   ct->kind = LF_STRUCTURE;
   break;
 
+case DW_TAG_union_type:
+  ct->kind = LF_UNION;
+  break;
+
 default:
   break;
 }
@@ -2068,9 +2142,9 @@ add_struct_forward_def (dw_die_ref type)
   return ct->num;
 }
 
-/* Process a DW_TAG_structure_type or DW_TAG_class_type DIE, add an
-   LF_FIELDLIST and an LF_STRUCTURE / LF_CLASS type, and return the number of
-   the latter.  */
+/* Process a DW_TAG_structure_type, DW_TAG_class_type, or DW_TAG_union_type
+   DIE, add an LF_FIELDLIST and an LF_STRUCTURE / LF_CLASS / LF_UNION type,
+   and return the number of the latter.  */
 
 static uint32_t
 get_type_num_struct (dw_die_ref type, bool in_struct, bool *is_fwd_ref)
@@ -2227,8 +2301,8 @@ get_type_num_struct (dw_die_ref type, bool in_struct, 
bool *is_fwd_ref)
   ct = ct2;
 }
 
-  /* Now add an LF_STRUCTURE / LF_CLASS, pointing to the LF_FIELDLIST we just
- added.  */
+  /* Now add an LF_STRUCTURE / LF_CLASS / LF_UNION, pointing to the
+ LF_FIELDLIST we just added.  */
 
   ct = (codeview_custom_type *) xmalloc (sizeof (codeview_custom_type));
 
@@ -2244,6 +2318,10 @@ get_type_num_struct (dw_die_ref type, bool in_struct, 
bool *is_fwd_ref)
   ct->kind = LF_STRUCTURE;
   break;
 
+case DW_TAG_union_type:
+  ct->kind = LF_UNION;
+  break;
+
 default:
   break;
 }
@@ -2325,6 +2403,7 @@ get_type_num (dw_die_re

[gcc r15-1630] [PATCH 09/11] Handle arrays for CodeView

2024-06-25 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:3e64a687a303dd550df072676c853d79076de37f

commit r15-1630-g3e64a687a303dd550df072676c853d79076de37f
Author: Mark Harmstone 
Date:   Tue Jun 25 17:31:24 2024 -0600

[PATCH 09/11] Handle arrays for CodeView

Translates DW_TAG_array_type DIEs into LF_ARRAY symbols.

gcc/
* dwarf2codeview.cc (struct codeview_custom_type): Add lf_array to
union.
(write_lf_array): New function.
(write_custom_types): Call write_lf_array.
(get_type_num_array_type): New function.
(get_type_num): Handle DW_TAG_array_type DIEs.
* dwarf2codeview.h (LF_ARRAY): Define.

Diff:
---
 gcc/dwarf2codeview.cc | 179 ++
 gcc/dwarf2codeview.h  |   1 +
 2 files changed, 180 insertions(+)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 9e3b64522b2..3f1ce5577fc 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -250,6 +250,12 @@ struct codeview_custom_type
   codeview_integer length;
   char *name;
 } lf_structure;
+struct
+{
+  uint32_t element_type;
+  uint32_t index_type;
+  codeview_integer length_in_bytes;
+} lf_array;
   };
 };
 
@@ -1520,6 +1526,53 @@ write_lf_union (codeview_custom_type *t)
   asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
 }
 
+/* Write an LF_ARRAY type.  */
+
+static void
+write_lf_array (codeview_custom_type *t)
+{
+  size_t leaf_len;
+
+  /* This is lf_array in binutils and lfArray in Microsoft's cvinfo.h:
+
+struct lf_array
+{
+  uint16_t size;
+  uint16_t kind;
+  uint32_t element_type;
+  uint32_t index_type;
+  uint16_t length_in_bytes;
+  char name[];
+} ATTRIBUTE_PACKED;
+  */
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end - %LLcv_type%x_start\n",
+  t->num, t->num);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_start:\n", t->num);
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  fprint_whex (asm_out_file, t->kind);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (4, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_array.element_type);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (4, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_array.index_type);
+  putc ('\n', asm_out_file);
+
+  leaf_len = 13 + write_cv_integer (&t->lf_array.length_in_bytes);
+
+  ASM_OUTPUT_ASCII (asm_out_file, "", 1);
+
+  write_cv_padding (4 - (leaf_len % 4));
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
+}
+
 /* Write the .debug$T section, which contains all of our custom type
definitions.  */
 
@@ -1562,6 +1615,10 @@ write_custom_types (void)
case LF_UNION:
  write_lf_union (custom_types);
  break;
+
+   case LF_ARRAY:
+ write_lf_array (custom_types);
+ break;
}
 
   free (custom_types);
@@ -2346,6 +2403,124 @@ get_type_num_struct (dw_die_ref type, bool in_struct, 
bool *is_fwd_ref)
   return ct->num;
 }
 
+/* Process a DW_TAG_array_type DIE, adding an LF_ARRAY type and returning its
+   number.  */
+
+static uint32_t
+get_type_num_array_type (dw_die_ref type, bool in_struct)
+{
+  dw_die_ref base_type, t, first_child, c, *dimension_arr;
+  uint64_t size = 0;
+  unsigned int dimensions, i;
+  uint32_t element_type;
+
+  base_type = get_AT_ref (type, DW_AT_type);
+  if (!base_type)
+return 0;
+
+  /* We need to know the size of our base type.  Loop through until we find
+ it.  */
+  t = base_type;
+  while (t && size == 0)
+{
+  switch (dw_get_die_tag (t))
+   {
+   case DW_TAG_const_type:
+   case DW_TAG_volatile_type:
+   case DW_TAG_typedef:
+   case DW_TAG_enumeration_type:
+ t = get_AT_ref (t, DW_AT_type);
+ break;
+
+   case DW_TAG_base_type:
+   case DW_TAG_structure_type:
+   case DW_TAG_class_type:
+   case DW_TAG_union_type:
+   case DW_TAG_pointer_type:
+ size = get_AT_unsigned (t, DW_AT_byte_size);
+ break;
+
+   default:
+ return 0;
+   }
+}
+
+  if (size == 0)
+return 0;
+
+  first_child = dw_get_die_child (type);
+  if (!first_child)
+return 0;
+
+  element_type = get_type_num (base_type, in_struct, false);
+  if (element_type == 0)
+return 0;
+
+  /* Create an array of our DW_TAG_subrange_type children, in reverse order.
+ We have to do this because unlike DWARF CodeView doesn't have
+ multidimensional arrays, so instead we do arrays of arrays.  */
+
+  dimensions = 0;
+  c = first_child;
+  do
+{
+  c = dw_get_die_sib (c);
+  if (dw_get_die_tag (c) != DW_TAG_subrange_type)
+   continue;
+
+  dimensions++;
+}
+  while (c != first_child);
+
+  if (dimensions == 0)
+return 0;
+
+  dimension_arr = (dw_die_ref *) xmalloc (sizeof (dw_die_ref) * dimensions);
+
+  c = first_child;
+  i = 0;
+  do
+  

[gcc r15-1631] c++: decltype of capture proxy of ref [PR115504]

2024-06-25 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:737449e5f233feb682b5dd2cc153892ad90a79bd

commit r15-1631-g737449e5f233feb682b5dd2cc153892ad90a79bd
Author: Patrick Palka 
Date:   Tue Jun 25 20:07:15 2024 -0400

c++: decltype of capture proxy of ref [PR115504]

The finish_decltype_type capture proxy handling added in r14-5330 was
incorrectly stripping references in the type of the captured variable.

PR c++/115504

gcc/cp/ChangeLog:

* semantics.cc (finish_decltype_type): Don't strip the reference
type (if any) of a capture proxy's captured variable.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/decltype-auto8.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/semantics.cc |  1 -
 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 22 ++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 8e3e4e23b72..44de4c9a529 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12071,7 +12071,6 @@ finish_decltype_type (tree expr, bool 
id_expression_or_member_access_p,
{
  expr = DECL_CAPTURED_VARIABLE (expr);
  type = TREE_TYPE (expr);
- type = non_reference (type);
}
  else
{
diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C 
b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C
new file mode 100644
index 000..55135cecf72
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C
@@ -0,0 +1,22 @@
+// PR c++/115504
+// { dg-do compile { target c++14 } }
+
+void f(int& x, const int& y) {
+  [&x]() {
+decltype(auto) a = x;
+using type = decltype(x);
+using type = decltype(a);
+using type = int&; // not 'int'
+  };
+
+  [x]() {
+decltype(auto) a = x; // { dg-error "discards qualifiers" }
+  };
+
+  [x]() mutable {
+decltype(auto) a = x;
+using type = decltype(x);
+using type = decltype(a);
+using type = int&;
+  };
+}


[gcc r15-1633] testsuite: use check-jsonschema for validating .sarif files [PR109360]

2024-06-25 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:17967907102099806dc80c71ee7665ffb22ffa23

commit r15-1633-g17967907102099806dc80c71ee7665ffb22ffa23
Author: David Malcolm 
Date:   Tue Jun 25 20:26:21 2024 -0400

testsuite: use check-jsonschema for validating .sarif files [PR109360]

As reported here:
  https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655434.html
the schema validation I added for generated .sarif files in
r15-1541-ga84fe222029ff2 used the "jsonschema" command line tool, which
has been deprecated by more recent versions of the Python 3 "jsonschema"
module.

This patch updates the validation to use the more recent
"check-jsonschema" command line tool, from the Python 3 "check-jsonschema"
module, fixing the testsuite FAILs due to the deprecation message.

As an added bonus, the output on validation failures is *much* nicer, e.g.
if I undo r15-1540-g9f4fdc3acebcf6, the error messages begin like this:
verify-sarif-file: res: Schema validation errors were encountered.
  
diagnostic-format-sarif-file-bad-utf8-pr109098-1.c.sarif::$.runs[0].results[0].locations[0].physicalLocation.region.startColumn:
 0 is less than the minimum of 1
  
diagnostic-format-sarif-file-bad-utf8-pr109098-1.c.sarif::$.runs[0].results[0].relatedLocations[0].physicalLocation.region.startColumn:
 0 is less than the minimum of 1
  
diagnostic-format-sarif-file-bad-utf8-pr109098-1.c.sarif::$.runs[0].results[0].relatedLocations[1].physicalLocation.region.startColumn:
 0 is less than the minimum of 1
  
diagnostic-format-sarif-file-bad-utf8-pr109098-1.c.sarif::$.runs[0].results[0].relatedLocations[2].physicalLocation.region.startColumn:
 0 is less than the minimum of 1
child process exited abnormally
FAIL: c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c  
-Wc++-compat   (test .sarif output against SARIF schema)

Tested with Python 3.8 with check_jsonschema 0.28.6

gcc/ChangeLog:
PR testsuite/109360
* doc/install.texi (Python3 modules): Update SARIF validation
requirement to use check-jsonschema rather than jsonschema.

gcc/testsuite/ChangeLog:
PR testsuite/109360
* lib/scansarif.exp (verify-sarif-file): Use check-jsonschema
rather than jsonschema, updating the invocation accordingly.
* lib/target-supports.exp (check_effective_target_jsonschema): 
Convert
to...
(check_effective_target_check_jsonschema): ...this.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/doc/install.texi  | 7 ---
 gcc/testsuite/lib/scansarif.exp   | 8 
 gcc/testsuite/lib/target-supports.exp | 6 +++---
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 0c769165146..b5456992583 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -461,9 +461,10 @@ is shown below:
 @code{gcov}, @code{gzip}, @code{json}, @code{os} and @code{pytest}.
 
 @item SARIF testsuite
-Tests of SARIF output will use the @code{jsonschema} program from the
-@code{jsonschema} module (if available) to validate generated .sarif files.
-If this tool is not found, the validation parts of those tests are skipped.
+Tests of SARIF output will use the @code{check-jsonschema} program from
+the @code{check-jsonschema} module (if available) to validate generated
+.sarif files.  If this tool is not found, the validation parts of those
+tests are skipped.
 
 @item c++ cxx api generation
 @code{csv}, @code{os}, @code{sys} and @code{time}.
diff --git a/gcc/testsuite/lib/scansarif.exp b/gcc/testsuite/lib/scansarif.exp
index 3eb38b8102e..cc0890ef5d8 100644
--- a/gcc/testsuite/lib/scansarif.exp
+++ b/gcc/testsuite/lib/scansarif.exp
@@ -57,7 +57,7 @@ proc scan-sarif-file-not { args } {
 # Assuming python3 is available, use verify-sarif-file.py to check
 # that the .sarif file is UTF-8 encoded and is parseable as JSON.
 #
-# Assuming "jsonschema" is available, use it to verify that the .sarif
+# Assuming "check-jsonschema" is available, use it to verify that the .sarif
 # file complies with the SARIF schema.
 
 proc verify-sarif-file { args } {
@@ -86,8 +86,8 @@ proc verify-sarif-file { args } {
 # Verify that the file complies with the SARIF schema.
 
 # Check that jsonschema is installed.
-if { ![check_effective_target_jsonschema] } {
-   unsupported "$testcase verify-sarif-file: jsonschema is missing"
+if { ![check_effective_target_check_jsonschema] } {
+   unsupported "$testcase verify-sarif-file: check-jsonschema is missing"
return  
 }
 
@@ -95,7 +95,7 @@ proc verify-sarif-file { args } {
 verbose "schema_file: $schema_file" 2
 
 set what "$testcase (test .sarif output against SARIF schema)"
-if [catch {exec jsonschema --instance $output_file $schema_file} res ] {
+if [catch {exec check-jsonschema --schemafile $schema_file $output_file

[gcc r15-1634] diagnostics: eliminate various implicit uses of global_dc

2024-06-25 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:d681c5211e613c64d149e734b15cdcf7d542342e

commit r15-1634-gd681c5211e613c64d149e734b15cdcf7d542342e
Author: David Malcolm 
Date:   Tue Jun 25 20:26:30 2024 -0400

diagnostics: eliminate various implicit uses of global_dc

This patch eliminates all implicit uses of "global_dc" from
the path-printing logic and from
gcc_rich_location::add_location_if_nearby.

No functional change intended.

gcc/c/ChangeLog:
* c-parser.cc (c_parser_require): Pass *global_dc to
gcc_rich_location::add_location_if_nearby.

gcc/cp/ChangeLog:
* parser.cc (cp_parser_error_1): Pass *global_dc to
gcc_rich_location::add_location_if_nearby.
(cp_parser_decl_specifier_seq): Likewise.
(cp_parser_set_storage_class): Likewise.
(cp_parser_set_storage_class): Likewise.

gcc/ChangeLog:
* diagnostic-path.cc (class path_label): Add m_path field,
and use it to replace all uses of global_dc.
(event_range::event_range): Add "ctxt" param and use it to
construct m_path_label.
(event_range::maybe_add_event): Add "ctxt" param and pass it to
gcc_rich_location::add_location_if_nearby.
(path_summary::path_summary): Add "ctxt" param and pass it to
event_range::maybe_add_event.
(diagnostic_context::print_path): Pass *this to path_summary ctor.
(selftest::test_empty_path): Use "dc" when constructing
path_summary rather than implicitly using global_dc.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
(selftest::diagnostic_path_cc_tests): Eliminate use of global_dc.
* diagnostic-show-locus.cc
(gcc_rich_location::add_location_if_nearby): Add "ctxt" param and
use it instead of implicitly using global_dc.
(selftest::test_add_location_if_nearby): Use
test_diagnostic_context rather than implicitly using global_dc.
* diagnostic.cc (pedantic_warning_kind): Delete macro.
(permissive_error_kind): Delete macro.
(permissive_error_option): Delete macro.
(diagnostic_context::diagnostic_enabled): Remove use of
permissive_error_option.
(diagnostic_context::report_diagnostic): Remove use of
pedantic_warning_kind.
(diagnostic_impl): Convert to...
(diagnostic_context::diagnostic_impl): ...this.
(diagnostic_n_impl): Convert to...
(diagnostic_context::diagnostic_n_impl): ...this.
(emit_diagnostic): Explicitly use global_dc for method call.
(emit_diagnostic_valist): Likewise.
(emit_diagnostic_valist_meta): Likewise.
(inform): Likewise.
(inform_n): Likewise.
(warning): Likewise.
(warning_at): Likewise.
(warning_meta): Likewise.
(warning_n): Likewise.
(pedwarn): Likewise.
(permerror): Likewise.
(permerror_opt): Likewise.
(error): Likewise.
(error_n): Likewise.
(error_at): Likewise.
(error_meta): Likewise.
(sorry): Likewise.
(sorry_at): Likewise.
(fatal_error): Likewise.
(internal_error): Likewise.
(internal_error_no_backtrace): Likewise.
* diagnostic.h (diagnostic_context::diagnostic_impl): New decl.
(diagnostic_context::diagnostic_n_impl): New decl.
* gcc-rich-location.h (gcc_rich_location::add_location_if_nearby):
Add "ctxt" param.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/c/c-parser.cc|   2 +-
 gcc/cp/parser.cc |  11 ++--
 gcc/diagnostic-path.cc   | 125 ---
 gcc/diagnostic-show-locus.cc |  25 
 gcc/diagnostic.cc| 136 +--
 gcc/diagnostic.h |   8 +++
 gcc/gcc-rich-location.h  |   6 +-
 7 files changed, 166 insertions(+), 147 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 33643ec910a..6a3f96d5b61 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -1248,7 +1248,7 @@ c_parser_require (c_parser *parser,
   bool added_matching_location = false;
   if (matching_location != UNKNOWN_LOCATION)
added_ma

[gcc r15-1635] diagnostics: introduce diagnostic-global-context.cc

2024-06-25 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:3800a78a767f463bed6948c640eee4250781e62e

commit r15-1635-g3800a78a767f463bed6948c640eee4250781e62e
Author: David Malcolm 
Date:   Tue Jun 25 20:26:35 2024 -0400

diagnostics: introduce diagnostic-global-context.cc

This moves all of the uses of global_dc within diagnostic.cc (including
the definition) to a new diagnostic-global-context.cc.  My intent is to
make clearer those parts of our internal API that implicitly use
global_dc, and to perhaps avoid linking global_dc into a future
libdiagnostics.so.

No functional change intended.

gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add diagnostic-global-context.o.
* diagnostic-global-context.cc: New file, taken from material in
diagnostic.cc.
* diagnostic.cc (global_diagnostic_context): Move to
diagnostic-global-context.cc.
(global_dc): Likewise.
(verbatim): Likewise.
(emit_diagnostic): Likewise.
(emit_diagnostic_valist): Likewise.
(emit_diagnostic_valist_meta): Likewise.
(inform): Likewise.
(inform_n): Likewise.
(warning): Likewise.
(warning_at): Likewise.
(warning_meta): Likewise.
(warning_n): Likewise.
(pedwarn): Likewise.
(permerror): Likewise.
(permerror_opt): Likewise.
(error): Likewise.
(error_n): Likewise.
(error_at): Likewise.
(error_meta): Likewise.
(sorry): Likewise.
(sorry_at): Likewise.
(seen_error): Likewise.
(fatal_error): Likewise.
(internal_error): Likewise.
(internal_error_no_backtrace): Likewise.
(fnotice): Likewise.
(auto_diagnostic_group::auto_diagnostic_group): Likewise.
(auto_diagnostic_group::~auto_diagnostic_group): Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/Makefile.in  |   1 +
 gcc/diagnostic-global-context.cc | 553 +++
 gcc/diagnostic.cc| 521 
 3 files changed, 554 insertions(+), 521 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 9eacb21bf54..7d3ea27a6ab 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1824,6 +1824,7 @@ OBJS = \
 OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \
diagnostic-format-json.o \
diagnostic-format-sarif.o \
+   diagnostic-global-context.o \
diagnostic-macro-unwinding.o \
diagnostic-path.o \
diagnostic-show-locus.o \
diff --git a/gcc/diagnostic-global-context.cc b/gcc/diagnostic-global-context.cc
new file mode 100644
index 000..497eb9e727c
--- /dev/null
+++ b/gcc/diagnostic-global-context.cc
@@ -0,0 +1,553 @@
+/* Language-independent diagnostic subroutines that implicitly use global_dc.
+   Copyright (C) 1999-2024 Free Software Foundation, Inc.
+   Contributed by Gabriel Dos Reis 
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+
+/* This file implements the parts of the language independent aspect
+   of diagnostic messages that implicitly use global_dc.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "intl.h"
+#include "diagnostic.h"
+
+/* A diagnostic_context surrogate for stderr.  */
+static diagnostic_context global_diagnostic_context;
+diagnostic_context *global_dc = &global_diagnostic_context;
+
+/* Standard error reporting routines in increasing order of severity.  */
+
+/* Text to be emitted verbatim to the error message stream; this
+   produces no prefix and disables line-wrapping.  Use rarely.  */
+void
+verbatim (const char *gmsgid, ...)
+{
+  va_list ap;
+
+  va_start (ap, gmsgid);
+  text_info text (_(gmsgid), &ap, errno);
+  pp_format_verbatim (global_dc->printer, &text);
+  pp_newline_and_flush (global_dc->printer);
+  va_end (ap);
+}
+
+/* Wrapper around diagnostic_context::diagnostic_impl
+   implying global_dc and taking a variable argument list.  */
+
+bool
+emit_diagnostic (diagnostic_t kind, location_t location, int opt,
+const char *gmsgid, ...)
+{
+  auto_diagnostic_group d;
+  va_list ap;
+  va_start (ap, gmsgid);
+  rich_location richloc (line_table, location);
+  bool ret = global_dc->d

[gcc r15-1636] [PATCH 10/11] Handle bitfields for CodeView

2024-06-25 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:009b3290f2b2a41409530cbc8119343d6344b50e

commit r15-1636-g009b3290f2b2a41409530cbc8119343d6344b50e
Author: Mark Harmstone 
Date:   Tue Jun 25 20:20:26 2024 -0600

[PATCH 10/11] Handle bitfields for CodeView

Translates structure members with DW_AT_data_bit_offset set in DWARF
into LF_BITFIELD symbols.

gcc/
* dwarf2codeview.cc (struct codeview_custom_type): Add lf_bitfield 
to
union.
(write_lf_bitfield): New function.
(write_custom_types): Call write_lf_bitfield.
(create_bitfield): New function.
(get_type_num_struct): Handle bitfields.
* dwarf2codeview.h (LF_BITFIELD): Define.

Diff:
---
 gcc/dwarf2codeview.cc | 89 +--
 gcc/dwarf2codeview.h  |  1 +
 2 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 3f1ce5577fc..06267639169 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -256,6 +256,12 @@ struct codeview_custom_type
   uint32_t index_type;
   codeview_integer length_in_bytes;
 } lf_array;
+struct
+{
+  uint32_t base_type;
+  uint8_t length;
+  uint8_t position;
+} lf_bitfield;
   };
 };
 
@@ -1573,6 +1579,50 @@ write_lf_array (codeview_custom_type *t)
   asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
 }
 
+/* Write an LF_BITFIELD type.  */
+
+static void
+write_lf_bitfield (codeview_custom_type *t)
+{
+  /* This is lf_bitfield in binutils and lfBitfield in Microsoft's cvinfo.h:
+
+struct lf_bitfield
+{
+  uint16_t size;
+  uint16_t kind;
+  uint32_t base_type;
+  uint8_t length;
+  uint8_t position;
+} ATTRIBUTE_PACKED;
+  */
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end - %LLcv_type%x_start\n",
+  t->num, t->num);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_start:\n", t->num);
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  fprint_whex (asm_out_file, t->kind);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (4, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_bitfield.base_type);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (1, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_bitfield.length);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (1, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_bitfield.position);
+  putc ('\n', asm_out_file);
+
+  write_cv_padding (2);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
+}
+
 /* Write the .debug$T section, which contains all of our custom type
definitions.  */
 
@@ -1619,6 +1669,10 @@ write_custom_types (void)
case LF_ARRAY:
  write_lf_array (custom_types);
  break;
+
+   case LF_BITFIELD:
+ write_lf_bitfield (custom_types);
+ break;
}
 
   free (custom_types);
@@ -2199,6 +2253,33 @@ add_struct_forward_def (dw_die_ref type)
   return ct->num;
 }
 
+/* Add an LF_BITFIELD type, returning its number.  DWARF represents bitfields
+   as members in a struct with a DW_AT_data_bit_offset attribute, whereas in
+   CodeView they're a distinct type.  */
+
+static uint32_t
+create_bitfield (dw_die_ref c)
+{
+  codeview_custom_type *ct;
+  uint32_t base_type;
+
+  base_type = get_type_num (get_AT_ref (c, DW_AT_type), true, false);
+  if (base_type == 0)
+return 0;
+
+  ct = (codeview_custom_type *) xmalloc (sizeof (codeview_custom_type));
+
+  ct->next = NULL;
+  ct->kind = LF_BITFIELD;
+  ct->lf_bitfield.base_type = base_type;
+  ct->lf_bitfield.length = get_AT_unsigned (c, DW_AT_bit_size);
+  ct->lf_bitfield.position = get_AT_unsigned (c, DW_AT_data_bit_offset);
+
+  add_custom_type (ct);
+
+  return ct->num;
+}
+
 /* Process a DW_TAG_structure_type, DW_TAG_class_type, or DW_TAG_union_type
DIE, add an LF_FIELDLIST and an LF_STRUCTURE / LF_CLASS / LF_UNION type,
and return the number of the latter.  */
@@ -2279,8 +2360,12 @@ get_type_num_struct (dw_die_ref type, bool in_struct, 
bool *is_fwd_ref)
  break;
}
 
- el->lf_member.type = get_type_num (get_AT_ref (c, DW_AT_type), true,
-   false);
+ if (get_AT (c, DW_AT_data_bit_offset))
+   el->lf_member.type = create_bitfield (c);
+ else
+   el->lf_member.type = get_type_num (get_AT_ref (c, DW_AT_type),
+  true, false);
+
  el->lf_member.offset.neg = false;
  el->lf_member.offset.num = get_AT_unsigned (c,
  
DW_AT_data_member_location);
diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h
index 70eed6bf2aa..70eae554b80 100644
--- a/gcc/dwarf2codeview.h
+++ b/gcc/dwarf2codeview.h
@@ -64,6 +64,7 @@ along with GCC; see the file COPYING3.  If not see
 #defi

[gcc r15-1637] [PATCH 11/11] Handle subroutine types in CodeView

2024-06-25 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:01f8b1002147c08f206a058a6d1f7bfb006aa324

commit r15-1637-g01f8b1002147c08f206a058a6d1f7bfb006aa324
Author: Mark Harmstone 
Date:   Tue Jun 25 20:24:22 2024 -0600

[PATCH 11/11] Handle subroutine types in CodeView

gcc/
* dwarf2codeview.cc (struct codeview_custom_type): Add lf_procedure
and lf_arglist to union.
(write_lf_procedure, write_lf_arglist): New functions.
(write_custom_types): Call write_lf_procedure and write_lf_arglist.
(get_type_num_subroutine_type): New function.
(get_type_num): Handle DW_TAG_subroutine_type DIEs.
* dwarf2codeview.h (LF_PROCEDURE, LF_ARGLIST): Define.

Diff:
---
 gcc/dwarf2codeview.cc | 238 ++
 gcc/dwarf2codeview.h  |   2 +
 2 files changed, 240 insertions(+)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 06267639169..e8ed3713480 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -262,6 +262,19 @@ struct codeview_custom_type
   uint8_t length;
   uint8_t position;
 } lf_bitfield;
+struct
+{
+  uint32_t return_type;
+  uint8_t calling_convention;
+  uint8_t attributes;
+  uint16_t num_parameters;
+  uint32_t arglist;
+} lf_procedure;
+struct
+{
+  uint32_t num_entries;
+  uint32_t *args;
+} lf_arglist;
   };
 };
 
@@ -1623,6 +1636,102 @@ write_lf_bitfield (codeview_custom_type *t)
   asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
 }
 
+/* Write an LF_PROCEDURE type.  Function pointers are implemented as pointers
+   to one of these.  */
+
+static void
+write_lf_procedure (codeview_custom_type *t)
+{
+  /* This is lf_procedure in binutils and lfProc in Microsoft's cvinfo.h:
+
+struct lf_procedure
+{
+  uint16_t size;
+  uint16_t kind;
+  uint32_t return_type;
+  uint8_t calling_convention;
+  uint8_t attributes;
+  uint16_t num_parameters;
+  uint32_t arglist;
+} ATTRIBUTE_PACKED;
+  */
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end - %LLcv_type%x_start\n",
+  t->num, t->num);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_start:\n", t->num);
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  fprint_whex (asm_out_file, t->kind);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (4, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_procedure.return_type);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (1, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_procedure.calling_convention);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (1, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_procedure.attributes);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_procedure.num_parameters);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (4, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_procedure.arglist);
+  putc ('\n', asm_out_file);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
+}
+
+/* Write an LF_ARGLIST type.  This is just a list of other types.  LF_PROCEDURE
+   entries point to one of these.  */
+
+static void
+write_lf_arglist (codeview_custom_type *t)
+{
+  /* This is lf_arglist in binutils and lfArgList in Microsoft's cvinfo.h:
+
+struct lf_arglist
+{
+  uint16_t size;
+  uint16_t kind;
+  uint32_t num_entries;
+  uint32_t args[];
+} ATTRIBUTE_PACKED;
+  */
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end - %LLcv_type%x_start\n",
+  t->num, t->num);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_start:\n", t->num);
+
+  fputs (integer_asm_op (2, false), asm_out_file);
+  fprint_whex (asm_out_file, t->kind);
+  putc ('\n', asm_out_file);
+
+  fputs (integer_asm_op (4, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_arglist.num_entries);
+  putc ('\n', asm_out_file);
+
+  for (uint32_t i = 0; i < t->lf_arglist.num_entries; i++)
+{
+  fputs (integer_asm_op (4, false), asm_out_file);
+  fprint_whex (asm_out_file, t->lf_arglist.args[i]);
+  putc ('\n', asm_out_file);
+}
+
+  free (t->lf_arglist.args);
+
+  asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num);
+}
+
 /* Write the .debug$T section, which contains all of our custom type
definitions.  */
 
@@ -1673,6 +1782,14 @@ write_custom_types (void)
case LF_BITFIELD:
  write_lf_bitfield (custom_types);
  break;
+
+   case LF_PROCEDURE:
+ write_lf_procedure (custom_types);
+ break;
+
+   case LF_ARGLIST:
+ write_lf_arglist (custom_types);
+ break;
}
 
   free (custom_types);
@@ -2488,6 +2605,123 @@ get_type_num_struct (dw_die_ref type, bool in_struct, 
bool *is_fwd_ref)
   return ct->num

[gcc r15-1638] Optimize a < 0 ? -1 : 0 to (signed)a >> 31.

2024-06-25 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:aac00d09859cc5934bd0f7493d537b8430337773

commit r15-1638-gaac00d09859cc5934bd0f7493d537b8430337773
Author: liuhongt 
Date:   Thu Jun 20 12:41:13 2024 +0800

Optimize a < 0 ? -1 : 0 to (signed)a >> 31.

Try to optimize x < 0 ? -1 : 0 into (signed) x >> 31
and x < 0 ? 1 : 0 into (unsigned) x >> 31.

Move the optimization did in ix86_expand_int_vcond to match.pd

gcc/ChangeLog:

PR target/114189
* match.pd: Simplify a < 0 ? -1 : 0 to (signed) >> 31 and a <
0 ? 1 : 0 to (unsigned) a >> 31 for vector integer type.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx2-pr115517.c: New test.
* gcc.target/i386/avx512-pr115517.c: New test.
* g++.target/i386/avx2-pr115517.C: New test.
* g++.target/i386/avx512-pr115517.C: New test.
* g++.dg/tree-ssa/pr88152-1.C: Adjust testcase.

Diff:
---
 gcc/match.pd| 30 +++
 gcc/testsuite/g++.dg/tree-ssa/pr88152-1.C   |  2 +-
 gcc/testsuite/g++.target/i386/avx2-pr115517.C   | 60 +
 gcc/testsuite/g++.target/i386/avx512-pr115517.C | 70 +
 gcc/testsuite/gcc.target/i386/avx2-pr115517.c   | 33 
 gcc/testsuite/gcc.target/i386/avx512-pr115517.c | 70 +
 6 files changed, 264 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 3d0689c9312..cf8a399a744 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5927,6 +5927,36 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (VECTOR_INTEGER_TYPE_P (type)
&& target_supports_op_p (type, MINMAX, optab_vector))
 (minmax @0 @1
+
+/* Try to optimize x < 0 ? -1 : 0 into (signed) x >> 31
+   and x < 0 ? 1 : 0 into (unsigned) x >> 31.  */
+(simplify
+  (vec_cond (lt @0 integer_zerop) integer_all_onesp integer_zerop)
+   (if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0))
+   && !TYPE_UNSIGNED (TREE_TYPE (@0))
+   && tree_nop_conversion_p (type, TREE_TYPE (@0))
+   && target_supports_op_p (TREE_TYPE (@0), RSHIFT_EXPR, optab_scalar))
+(with
+  {
+   unsigned int prec = element_precision (TREE_TYPE (@0));
+  }
+(view_convert
+  (rshift @0 { build_int_cst (integer_type_node, prec - 1);})
+
+(simplify
+  (vec_cond (lt @0 integer_zerop) integer_onep integer_zerop)
+   (if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0))
+   && !TYPE_UNSIGNED (TREE_TYPE (@0))
+   && tree_nop_conversion_p (type, TREE_TYPE (@0)))
+(with
+ {
+   unsigned int prec = element_precision (TREE_TYPE (@0));
+   tree utype = unsigned_type_for (TREE_TYPE (@0));
+ }
+ (if (target_supports_op_p (utype, RSHIFT_EXPR, optab_scalar))
+  (view_convert
+   (rshift (view_convert:utype @0)
+   { build_int_cst (integer_type_node, prec - 1);}))
 #endif
 
 (for cnd (cond vec_cond)
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr88152-1.C 
b/gcc/testsuite/g++.dg/tree-ssa/pr88152-1.C
index 423ec897c1d..21299b886f0 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/pr88152-1.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr88152-1.C
@@ -1,7 +1,7 @@
 // PR target/88152
 // { dg-do compile }
 // { dg-options "-O2 -std=c++14 -fdump-tree-forwprop1" }
-// { dg-final { scan-tree-dump-times " (?:<|>=) \{ 0\[, ]" 120 "forwprop1" } }
+// { dg-final { scan-tree-dump-times " (?:(?:<|>=) \{ 0\[, \]|>> 
(?:7|15|31|63))" 120 "forwprop1" } }
 
 template 
 using V [[gnu::vector_size (sizeof (T) * N)]] = T;
diff --git a/gcc/testsuite/g++.target/i386/avx2-pr115517.C 
b/gcc/testsuite/g++.target/i386/avx2-pr115517.C
new file mode 100644
index 000..ec000c57542
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/avx2-pr115517.C
@@ -0,0 +1,60 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx2 -O2" } */
+/* { dg-final { scan-assembler-times "vpsrlq" 2 } } */
+/* { dg-final { scan-assembler-times "vpsrld" 2 } } */
+/* { dg-final { scan-assembler-times "vpsrlw" 2 } } */
+
+typedef short v8hi __attribute__((vector_size(16)));
+typedef short v16hi __attribute__((vector_size(32)));
+typedef int v4si __attribute__((vector_size(16)));
+typedef int v8si __attribute__((vector_size(32)));
+typedef long long v2di __attribute__((vector_size(16)));
+typedef long long v4di __attribute__((vector_size(32)));
+
+v8hi
+foo (v8hi a)
+{
+  v8hi const1_op = __extension__(v8hi){1,1,1,1,1,1,1,1};
+  v8hi const0_op = __extension__(v8hi){0,0,0,0,0,0,0,0};
+  return a < const0_op ? const1_op : const0_op;
+}
+
+v16hi
+foo2 (v16hi a)
+{
+  v16hi const1_op = __extension__(v16hi){1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
+  v16hi const0_op = __extension__(v16hi){0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+  return a < const0_op ? const1_op : const0_op;
+}
+
+v4si
+foo3 (v4si a)
+{
+  v4si const1_op = __extension__(v4si){1,1,1,1};
+  v4si const0_op = __extension__(v4si){0,0,0,0};
+  return a < const0_op ? const1_op : const0_op;
+}
+
+v8si
+foo4 (v8si a)
+{
+  v8si const1_op = __extension__(v8

[gcc r15-1639] [testsuite] [arm] [vect] adjust mve-vshr test [PR113281]

2024-06-25 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:54d2339c9f87f702e02e571a5460e11c19e1c02f

commit r15-1639-g54d2339c9f87f702e02e571a5460e11c19e1c02f
Author: Alexandre Oliva 
Date:   Wed Jun 26 02:08:18 2024 -0300

[testsuite] [arm] [vect] adjust mve-vshr test [PR113281]

The test was too optimistic, alas.  We used to vectorize shifts by
clamping the shift counts below the bit width of the types (e.g. at 15
for 16-bit vector elements), but (uint16_t)32768 >> (uint16_t)16 is
well defined (because of promotion to 32-bit int) and must yield 0,
not 1 (as before the fix).

Unfortunately, in the gimple model of vector units, such large shift
counts wouldn't be well-defined, so we won't vectorize such shifts any
more, unless we can tell they're in range or undefined.

So the test that expected the vectorization we no longer performed
needs to be adjusted.  Instead of nobbling the test, Richard Earnshaw
suggested annotating the test with the expected ranges so as to enable
the optimization, and Christophe Lyon suggested a further
simplification.


Co-Authored-By: Richard Earnshaw 

for  gcc/testsuite/ChangeLog

PR tree-optimization/113281
* gcc.target/arm/simd/mve-vshr.c: Add expected ranges.

Diff:
---
 gcc/testsuite/gcc.target/arm/simd/mve-vshr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.target/arm/simd/mve-vshr.c 
b/gcc/testsuite/gcc.target/arm/simd/mve-vshr.c
index 8c7adef9ed8..03078de49c6 100644
--- a/gcc/testsuite/gcc.target/arm/simd/mve-vshr.c
+++ b/gcc/testsuite/gcc.target/arm/simd/mve-vshr.c
@@ -9,6 +9,8 @@
   void test_ ## NAME ##_ ## SIGN ## BITS ## x ## NB (TYPE##BITS##_t * 
__restrict__ dest, TYPE##BITS##_t *a, TYPE##BITS##_t *b) { \
 int i; \
 for (i=0; i= (unsigned)(BITS))  \
+   __builtin_unreachable();\
   dest[i] = a[i] OP b[i];  \
 }  \
 }


[gcc r15-1640] [libstdc++] [testsuite] no libatomic for vxworks

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

commit r15-1640-geed2027843409bf3afd03053d95760bdacb8fbf6
Author: Alexandre Oliva 
Date:   Wed Jun 26 02:08:27 2024 -0300

[libstdc++] [testsuite] no libatomic for vxworks

libatomic hasn't been ported to vxworks.  Most of the stdatomic.h and
 underlying requirements are provided by builtins and libgcc,
and the vxworks libc already provides remaining __atomic symbols, so
porting libatomic doesn't seem to make sense.

However, some of the target arch-only tests in
add_options_for_libatomic cover vxworks targets, so we end up
attempting to link libatomic in, even though it's not there.
Preempt those too-broad tests.


Co-Authored-By: Marc Poulhiès 

for  libstdc++-v3/ChangeLog

* testsuite/lib/dg-options.exp (add_options_for_libatomic):
None for *-*-vxworks*.

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

diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp 
b/libstdc++-v3/testsuite/lib/dg-options.exp
index 84f9e3ebc73..0d77fb029b0 100644
--- a/libstdc++-v3/testsuite/lib/dg-options.exp
+++ b/libstdc++-v3/testsuite/lib/dg-options.exp
@@ -338,6 +338,11 @@ proc atomic_link_flags { paths } {
 }
 
 proc add_options_for_libatomic { flags } {
+# We don't (need to) build libatomic for vxworks.  Don't try to
+# link it in, even on arches that support libatomic.
+if { [istarget *-*-vxworks*] } {
+   return $flags
+}
 if { [istarget hppa*-*-hpux*]
 || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
 || [istarget riscv*-*-*]


[gcc r15-1641] optab: Add isfinite_optab for isfinite builtin

2024-06-25 Thread HaoChen Gui via Gcc-cvs
https://gcc.gnu.org/g:680eda8c74100eb957dffbcc5554230e71f25990

commit r15-1641-g680eda8c74100eb957dffbcc5554230e71f25990
Author: Haochen Gui 
Date:   Wed Jun 26 13:35:10 2024 +0800

optab: Add isfinite_optab for isfinite builtin

gcc/
* builtins.cc (interclass_mathfn_icode): Set optab to isfinite_optab
for isfinite builtin.
* optabs.def (isfinite_optab): New.
* doc/md.texi (isfinite): Document.

Diff:
---
 gcc/builtins.cc | 4 +++-
 gcc/doc/md.texi | 6 ++
 gcc/optabs.def  | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index d467d1697b4..03634cdaba1 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -2459,8 +2459,10 @@ interclass_mathfn_icode (tree arg, tree fndecl)
   errno_set = true; builtin_optab = ilogb_optab; break;
 CASE_FLT_FN (BUILT_IN_ISINF):
   builtin_optab = isinf_optab; break;
-case BUILT_IN_ISNORMAL:
 case BUILT_IN_ISFINITE:
+  builtin_optab = isfinite_optab;
+  break;
+case BUILT_IN_ISNORMAL:
 CASE_FLT_FN (BUILT_IN_FINITE):
 case BUILT_IN_FINITED32:
 case BUILT_IN_FINITED64:
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 5730bda80dc..3eb4216141e 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -8557,6 +8557,12 @@ operand 2, greater than operand 2 or is unordered with 
operand 2.
 
 This pattern is not allowed to @code{FAIL}.
 
+@cindex @code{isfinite@var{m}2} instruction pattern
+@item @samp{isfinite@var{m}2}
+Return 1 if operand 1 is a finite floating point number and 0
+otherwise.  @var{m} is a scalar floating point mode.  Operand 0
+has mode @code{SImode}, and operand 1 has mode @var{m}.
+
 @end table
 
 @end ifset
diff --git a/gcc/optabs.def b/gcc/optabs.def
index bc2611abdc2..9514a317259 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -352,6 +352,7 @@ OPTAB_D (fmod_optab, "fmod$a3")
 OPTAB_D (hypot_optab, "hypot$a3")
 OPTAB_D (ilogb_optab, "ilogb$a2")
 OPTAB_D (isinf_optab, "isinf$a2")
+OPTAB_D (isfinite_optab, "isfinite$a2")
 OPTAB_D (issignaling_optab, "issignaling$a2")
 OPTAB_D (ldexp_optab, "ldexp$a3")
 OPTAB_D (log10_optab, "log10$a2")


[gcc r15-1642] optab: Add isnormal_optab for isnormal builtin

2024-06-25 Thread HaoChen Gui via Gcc-cvs
https://gcc.gnu.org/g:5a10ac0e5921d5aeac58429457423b611ee325d2

commit r15-1642-g5a10ac0e5921d5aeac58429457423b611ee325d2
Author: Haochen Gui 
Date:   Wed Jun 26 13:35:58 2024 +0800

optab: Add isnormal_optab for isnormal builtin

gcc/
* builtins.cc (interclass_mathfn_icode): Set optab to isnormal_optab
for isnormal builtin.
* optabs.def (isnormal_optab): New.
* doc/md.texi (isnormal): Document.

Diff:
---
 gcc/builtins.cc | 2 ++
 gcc/doc/md.texi | 6 ++
 gcc/optabs.def  | 1 +
 3 files changed, 9 insertions(+)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 03634cdaba1..0b902896ddd 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -2463,6 +2463,8 @@ interclass_mathfn_icode (tree arg, tree fndecl)
   builtin_optab = isfinite_optab;
   break;
 case BUILT_IN_ISNORMAL:
+  builtin_optab = isnormal_optab;
+  break;
 CASE_FLT_FN (BUILT_IN_FINITE):
 case BUILT_IN_FINITED32:
 case BUILT_IN_FINITED64:
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 3eb4216141e..4fd7da095fe 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -8563,6 +8563,12 @@ Return 1 if operand 1 is a finite floating point number 
and 0
 otherwise.  @var{m} is a scalar floating point mode.  Operand 0
 has mode @code{SImode}, and operand 1 has mode @var{m}.
 
+@cindex @code{isnormal@var{m}2} instruction pattern
+@item @samp{isnormal@var{m}2}
+Return 1 if operand 1 is a normal floating point number and 0
+otherwise.  @var{m} is a scalar floating point mode.  Operand 0
+has mode @code{SImode}, and operand 1 has mode @var{m}.
+
 @end table
 
 @end ifset
diff --git a/gcc/optabs.def b/gcc/optabs.def
index 9514a317259..2f36ed4cb42 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -353,6 +353,7 @@ OPTAB_D (hypot_optab, "hypot$a3")
 OPTAB_D (ilogb_optab, "ilogb$a2")
 OPTAB_D (isinf_optab, "isinf$a2")
 OPTAB_D (isfinite_optab, "isfinite$a2")
+OPTAB_D (isnormal_optab, "isnormal$a2")
 OPTAB_D (issignaling_optab, "issignaling$a2")
 OPTAB_D (ldexp_optab, "ldexp$a3")
 OPTAB_D (log10_optab, "log10$a2")


[gcc r15-1643] tree-optimization/115646 - ICE with pow shrink-wrapping from bitfield

2024-06-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:453b1d291d1a0f89087ad91cf6b1bed1ec68eff3

commit r15-1643-g453b1d291d1a0f89087ad91cf6b1bed1ec68eff3
Author: Richard Biener 
Date:   Tue Jun 25 16:13:02 2024 +0200

tree-optimization/115646 - ICE with pow shrink-wrapping from bitfield

The following makes analysis and transform agree on constraints.

PR tree-optimization/115646
* tree-call-cdce.cc (check_pow): Check for bit_sz values
as allowed by transform.

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

Diff:
---
 gcc/testsuite/gcc.dg/pr115646.c | 13 +
 gcc/tree-call-cdce.cc   |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/pr115646.c b/gcc/testsuite/gcc.dg/pr115646.c
new file mode 100644
index 000..24bc1e4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr115646.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern double pow(double x, double y);
+
+struct S {
+unsigned int a : 3, b : 8, c : 21;
+};
+
+void foo (struct S *p)
+{
+  pow (p->c, 42);
+}
diff --git a/gcc/tree-call-cdce.cc b/gcc/tree-call-cdce.cc
index 7f67a0b2dc6..befe6acf178 100644
--- a/gcc/tree-call-cdce.cc
+++ b/gcc/tree-call-cdce.cc
@@ -260,7 +260,7 @@ check_pow (gcall *pow_call)
   /* If the type of the base is too wide,
  the resulting shrink wrapping condition
 will be too conservative.  */
-  if (bit_sz > MAX_BASE_INT_BIT_SIZE)
+  if (bit_sz != 8 && bit_sz != 16 && bit_sz != MAX_BASE_INT_BIT_SIZE)
 return false;
 
   return true;