Re: [PATCH] [x86] Fix unrecognizable insn of cvtss2si.

2022-10-10 Thread Uros Bizjak via Gcc-patches
On Mon, Oct 10, 2022 at 3:26 AM liuhongt via Gcc-patches
 wrote:
>
> Adjust lrintmn2 operand preidcates according to real instructions.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok as an obvious fix?
>
> gcc/ChangeLog:
>
> PR target/107185
> * config/i386/i386.md (lrint2): Swap
> predicate of operands[0] and operands[1].
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr107185.c: New test.

OK.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386.md  | 4 ++--
>  gcc/testsuite/gcc.target/i386/pr107185.c | 8 
>  2 files changed, 10 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr107185.c
>
> diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
> index 1be9b669909..947513701b9 100644
> --- a/gcc/config/i386/i386.md
> +++ b/gcc/config/i386/i386.md
> @@ -20145,8 +20145,8 @@ (define_insn "lrintxf2"
> (set_attr "mode" "")])
>
>  (define_expand "lrint2"
> -  [(set (match_operand:SWI48 0 "nonimmediate_operand")
> - (unspec:SWI48 [(match_operand:MODEF 1 "register_operand")]
> +  [(set (match_operand:SWI48 0 "register_operand")
> + (unspec:SWI48 [(match_operand:MODEF 1 "nonimmediate_operand")]
>UNSPEC_FIX_NOTRUNC))]
>"SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH")
>
> diff --git a/gcc/testsuite/gcc.target/i386/pr107185.c 
> b/gcc/testsuite/gcc.target/i386/pr107185.c
> new file mode 100644
> index 000..333191a9a89
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr107185.c
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +/* { dg-options "-ffast-math" } */
> +
> +void
> +foo (float f)
> +{
> +  long p =  __builtin_lrintf (f);
> +}
> --
> 2.27.0
>


[committed 1/5] arc: Fix enter pattern instruction's offsets

2022-10-10 Thread Claudiu Zissulescu via Gcc-patches
The enter pattern instruction contains the necessary information for
the dwarf machinery to generate the appropriate dwarf code.  This
patch is fixing the register offsets related to CFA, and adds a test.

gcc/
* config/arc/arc.cc (arc_save_callee_enter): Use negative offsets.

gcc/testsuite
* gcc.target/arc/enter-dw2-1.c: New file.

Signed-off-by: Claudiu Zissulescu 
---
 gcc/config/arc/arc.cc  |  6 ++---
 gcc/testsuite/gcc.target/arc/enter-dw2-1.c | 28 ++
 2 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/enter-dw2-1.c

diff --git a/gcc/config/arc/arc.cc b/gcc/config/arc/arc.cc
index db4b56b23ff..7be27e01035 100644
--- a/gcc/config/arc/arc.cc
+++ b/gcc/config/arc/arc.cc
@@ -3356,7 +3356,7 @@ arc_save_callee_enter (uint64_t gmask,
   reg = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
   mem = gen_frame_mem (Pmode, plus_constant (Pmode,
 stack_pointer_rtx,
-off));
+-off));
   XVECEXP (insn, 0, indx) = gen_rtx_SET (mem, reg);
   RTX_FRAME_RELATED_P (XVECEXP (insn, 0, indx++)) = 1;
   off -= UNITS_PER_WORD;
@@ -3370,7 +3370,7 @@ arc_save_callee_enter (uint64_t gmask,
   reg = gen_rtx_REG (SImode, regno);
   mem = gen_frame_mem (SImode, plus_constant (Pmode,
  stack_pointer_rtx,
- off));
+ -off));
   XVECEXP (insn, 0, indx) = gen_rtx_SET (mem, reg);
   RTX_FRAME_RELATED_P (XVECEXP (insn, 0, indx)) = 1;
   gmask = gmask & ~(1ULL << regno);
@@ -3380,7 +3380,7 @@ arc_save_callee_enter (uint64_t gmask,
 {
   mem = gen_frame_mem (Pmode, plus_constant (Pmode,
 stack_pointer_rtx,
-off));
+-off));
   XVECEXP (insn, 0, indx) = gen_rtx_SET (mem, hard_frame_pointer_rtx);
   RTX_FRAME_RELATED_P (XVECEXP (insn, 0, indx++)) = 1;
   off -= UNITS_PER_WORD;
diff --git a/gcc/testsuite/gcc.target/arc/enter-dw2-1.c 
b/gcc/testsuite/gcc.target/arc/enter-dw2-1.c
new file mode 100644
index 000..25d03562198
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arc/enter-dw2-1.c
@@ -0,0 +1,28 @@
+/* Verify that we generate appropriate CFI offsets in the case of enter
+   instruction.  */
+/* { dg-skip-if "Not having enter_s insn." { arc700 || arc6xx } } */
+/* { dg-do compile } */
+/* { dg-options "-g -Os" } */
+
+extern void bar (void);
+
+void foo (void)
+{
+  asm volatile (";my clobber list"
+   : : : "r13", "r14", "r15", "r16", "r17", "r18", "r19");
+  bar ();
+  asm volatile (";my clobber list"
+   : : : "r13", "r14", "r15", "r16", "r17", "r18", "r19");
+}
+
+
+/* { dg-final { scan-assembler-times "enter_s" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_def_cfa_offset 32" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_offset 31, -32" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_offset 13, -28" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_offset 14, -24" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_offset 15, -20" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_offset 16, -16" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_offset 17, -12" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_offset 18, -8" 1 } } */
+/* { dg-final { scan-assembler-times "\.cfi_offset 19, -4" 1 } } */
-- 
2.30.2



[committed 2/5] arc: Remove Rcr constraint

2022-10-10 Thread Claudiu Zissulescu via Gcc-patches
gcc/ChangeLog:

* config/arc/arc.md(mulsi3_700): Remove Rcr.
(mulsi3_highpart): Likewise.
(umulsi3_highpart_i): Likewise.
(umulsi3_highpart_int): Likewise.
(macd): Likewise.
(macdu): Likewise.
* config/arc/constraints.md (Rcr): Remove it.

gcc/testsuite/ChangeLog:
* gcc.target/arc/tmac-2.c: Update test.

Signed-off-by: Claudiu Zissulescu 

fix
---
 gcc/config/arc/arc.md | 36 +--
 gcc/config/arc/constraints.md | 10 
 gcc/testsuite/gcc.target/arc/tmac-2.c |  2 +-
 3 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 7170445309f..90ce66d45ba 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -2336,11 +2336,11 @@ (define_insn "mulu64"
 ; registers, since it cannot be the destination of a multi-cycle insn
 ; like MPY or MPYU.
 (define_insn "mulsi3_700"
- [(set (match_operand:SI 0 "mpy_dest_reg_operand""=Rcr,r,r,Rcr,r")
-   (mult:SI (match_operand:SI 1 "register_operand"  "%0,c,0,0,c")
-(match_operand:SI 2 "nonmemory_operand" "cL,cL,I,Cal,Cal")))]
+ [(set (match_operand:SI 0 "mpy_dest_reg_operand""=r, r,r,  r,r")
+   (mult:SI (match_operand:SI 1 "register_operand"  "%0, r,0,  0,r")
+(match_operand:SI 2 "nonmemory_operand" "rL,rL,I,Cal,Cal")))]
  "TARGET_ARC700_MPY"
-  "mpyu%? %0,%1,%2"
+  "mpyu%?\\t%0,%1,%2"
   [(set_attr "length" "4,4,4,8,8")
(set_attr "type" "umulti")
(set_attr "predicable" "yes,no,no,yes,no")
@@ -2501,15 +2501,15 @@ (define_insn_and_split "mulsidi3_700"
(set_attr "length" "8")])
 
 (define_insn "mulsi3_highpart"
-  [(set (match_operand:SI 0 "register_operand"  "=Rcr,r,Rcr,r")
+  [(set (match_operand:SI 0 "register_operand""=r,r,r,r")
(truncate:SI
 (lshiftrt:DI
  (mult:DI
-  (sign_extend:DI (match_operand:SI 1 "register_operand" "%0,c,  0,c"))
-  (sign_extend:DI (match_operand:SI 2 "extend_operand""c,c,  
i,i")))
+  (sign_extend:DI (match_operand:SI 1 "register_operand" "%0,r,0,r"))
+  (sign_extend:DI (match_operand:SI 2 "extend_operand""r,r,i,i")))
  (const_int 32]
   "TARGET_MPY"
-  "mpy%+%? %0,%1,%2"
+  "mpy%+%?\\t%0,%1,%2"
   [(set_attr "length" "4,4,8,8")
(set_attr "type" "multi")
(set_attr "predicable" "yes,no,yes,no")
@@ -2518,15 +2518,15 @@ (define_insn "mulsi3_highpart"
 ; Note that mpyhu has the same latency as mpy / mpyh,
 ; thus we use the type multi.
 (define_insn "*umulsi3_highpart_i"
-  [(set (match_operand:SI 0 "register_operand"  "=Rcr,r,Rcr,r")
+  [(set (match_operand:SI 0 "register_operand""=r,r,r,r")
(truncate:SI
 (lshiftrt:DI
  (mult:DI
-  (zero_extend:DI (match_operand:SI 1 "register_operand" "%0,c,  0,c"))
-  (zero_extend:DI (match_operand:SI 2 "extend_operand""c,c,  
i,i")))
+  (zero_extend:DI (match_operand:SI 1 "register_operand" "%0,r,0,r"))
+  (zero_extend:DI (match_operand:SI 2 "extend_operand""r,r,i,i")))
  (const_int 32]
   "TARGET_MPY"
-  "mpy%+u%? %0,%1,%2"
+  "mpy%+u%?\\t%0,%1,%2"
   [(set_attr "length" "4,4,8,8")
(set_attr "type" "multi")
(set_attr "predicable" "yes,no,yes,no")
@@ -2536,15 +2536,15 @@ (define_insn "*umulsi3_highpart_i"
 ;; need a separate pattern for immediates
 ;; ??? This is fine for combine, but not for reload.
 (define_insn "umulsi3_highpart_int"
-  [(set (match_operand:SI 0 "register_operand""=Rcr, r, r,Rcr,  r")
+  [(set (match_operand:SI 0 "register_operand""=r, r, r,r,  r")
(truncate:SI
 (lshiftrt:DI
  (mult:DI
-  (zero_extend:DI (match_operand:SI 1 "register_operand"  " 0, c, 0,  
0,  c"))
-  (match_operand:DI 2 "immediate_usidi_operand" "L, L, I, Cal, Cal"))
+  (zero_extend:DI (match_operand:SI 1 "register_operand"  " 0, r, 0,  
0,  r"))
+  (match_operand:DI 2 "immediate_usidi_operand" "L, L, I,Cal,Cal"))
  (const_int 32]
   "TARGET_MPY"
-  "mpy%+u%? %0,%1,%2"
+  "mpy%+u%?\\t%0,%1,%2"
   [(set_attr "length" "4,4,4,8,8")
(set_attr "type" "multi")
(set_attr "predicable" "yes,no,no,yes,no")
@@ -6141,7 +6141,7 @@ (define_insn_and_split "maddsidi4_split"
(set_attr "length" "36")])
 
 (define_insn "macd"
-  [(set (match_operand:DI 0 "even_register_operand"   "=Rcr,r,r")
+  [(set (match_operand:DI 0 "even_register_operand""=r,r,r")
(plus:DI
 (mult:DI
  (sign_extend:DI (match_operand:SI 1 "register_operand" "%0,r,r"))
@@ -6243,7 +6243,7 @@ (define_insn_and_split "umaddsidi4_split"
(set_attr "length" "36")])
 
 (define_insn "macdu"
-  [(set (match_operand:DI 0 "even_register_operand"   "=Rcr,r,r")
+  [(set (match_operand:DI 0 "even_register_operand""=r,r,r")
(plus:DI
 (mult:D

[committed 5/5] arc: Remove obsolete mRcq and mRcw options.

2022-10-10 Thread Claudiu Zissulescu via Gcc-patches
gcc/

* common/config/arc/arc-common.cc (arc_option_optimization_table):
Remove Rcq and Rcw options.
* config/arc/arc.opt (mRcq): Ignore option, preserve it for
backwards compatibility.
(mRcw): Likewise.
* doc/invoke.texi (mRcw, mRcq): Update document.

Signed-off-by: Claudiu Zissulescu 
---
 gcc/common/config/arc/arc-common.cc |  2 --
 gcc/config/arc/arc.opt  | 10 ++
 gcc/doc/invoke.texi |  8 ++--
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/gcc/common/config/arc/arc-common.cc 
b/gcc/common/config/arc/arc-common.cc
index e69c4a4fac7..62fe54234e0 100644
--- a/gcc/common/config/arc/arc-common.cc
+++ b/gcc/common/config/arc/arc-common.cc
@@ -44,8 +44,6 @@ arc_option_init_struct (struct gcc_options *opts 
ATTRIBUTE_UNUSED)
 #define OPT_LEVELS_3_PLUS_SPEED_ONLY OPT_LEVELS_3_PLUS
 static const struct default_options arc_option_optimization_table[] =
   {
-{ OPT_LEVELS_ALL, OPT_mRcq, NULL, 1 },
-{ OPT_LEVELS_ALL, OPT_mRcw, NULL, 1 },
 { OPT_LEVELS_ALL, OPT_msize_level_, NULL, 1 },
 { OPT_LEVELS_ALL, OPT_mearly_cbranchsi, NULL, 1 },
 { OPT_LEVELS_ALL, OPT_mbbit_peephole, NULL, 1 },
diff --git a/gcc/config/arc/arc.opt b/gcc/config/arc/arc.opt
index 0add5a2a21f..b58273255f7 100644
--- a/gcc/config/arc/arc.opt
+++ b/gcc/config/arc/arc.opt
@@ -308,12 +308,14 @@ Target Ignore
 Does nothing.  Preserved for backward compatibility.
 
 mRcq
-Target Var(TARGET_Rcq)
-Enable Rcq constraint handling - most short code generation depends on this.
+Target Ignore
+Does nothing.  Preserved for backward compatibility.
+
 
 mRcw
-Target Var(TARGET_Rcw)
-Enable Rcw constraint handling - ccfsm condexec mostly depends on this.
+Target Ignore
+Does nothing.  Preserved for backward compatibility.
+
 
 mearly-cbranchsi
 Target Var(TARGET_EARLY_CBRANCHSI)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1eeaec18810..278c55d5a19 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -20896,15 +20896,11 @@ This is the default for @option{-Os}.
 
 @item -mRcq
 @opindex mRcq
-Enable @samp{Rcq} constraint handling.  
-Most short code generation depends on this.
-This is the default.
+Does nothing.  Preserved for backward compatibility.
 
 @item -mRcw
 @opindex mRcw
-Enable @samp{Rcw} constraint handling.  
-Most ccfsm condexec mostly depends on this.
-This is the default.
+Does nothing.  Preserved for backward compatibility.
 
 @item -msize-level=@var{level}
 @opindex msize-level
-- 
2.30.2



[committed 3/5] arc: Remove Rcw constraint

2022-10-10 Thread Claudiu Zissulescu via Gcc-patches
gcc/Changelog:

* config/arc/arc.md (smaxsi3): Remove Rcw.
(sminsi3): Likewise.
(addsi3_mixed): Likewise.
(add_f_2): Likewise.
(subsi3_insn): Likewise.
(sub_f): Likewise.
(sub_n): Likewise.
(bset): Likewise.
(bxor): Likewise.
(bclr): Likewise.
(bset_insn): Likewise.
(bxor_insn): Likewise.
(bclr_insn): Likewise.
(bmsk_insn): Likewise.
(bicsi3_insn): Likewise.
(xorsi3): Likewise.
(negsi2): Likewise.
(lshrsi3_insn): Likewise.
(abssf2): Likewise.
(negsf2): Likewise.
* config/arc/constraints.md(Rcw): Remove it.

Signed-off-by: Claudiu Zissulescu 
---
 gcc/config/arc/arc.md | 220 +-
 gcc/config/arc/constraints.md |  14 ---
 2 files changed, 110 insertions(+), 124 deletions(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 90ce66d45ba..e6fa2a1fbf6 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -1991,22 +1991,22 @@ (define_insn "abssi2"
 ;; Maximum and minimum insns
 
 (define_insn "smaxsi3"
-   [(set (match_operand:SI 0 "dest_reg_operand" "=Rcw, w,  w")
-(smax:SI (match_operand:SI 1 "register_operand"  "%0, c,  c")
- (match_operand:SI 2 "nonmemory_operand" "cL,cL,Cal")))]
+   [(set (match_operand:SI 0 "dest_reg_operand"   "=r, r,  r")
+(smax:SI (match_operand:SI 1 "register_operand"  "%0, r,  r")
+ (match_operand:SI 2 "nonmemory_operand" "rL,rL,Cal")))]
   ""
-  "max%? %0,%1,%2"
+  "max%?\\t%0,%1,%2"
   [(set_attr "type" "two_cycle_core")
(set_attr "length" "4,4,8")
(set_attr "predicable" "yes,no,no")]
 )
 
 (define_insn "sminsi3"
-   [(set (match_operand:SI 0 "dest_reg_operand" "=Rcw, w,  w")
-(smin:SI (match_operand:SI 1 "register_operand"  "%0, c,  c")
- (match_operand:SI 2 "nonmemory_operand" "cL,cL,Cal")))]
+   [(set (match_operand:SI 0 "dest_reg_operand"   "=r, r,  r")
+(smin:SI (match_operand:SI 1 "register_operand"  "%0, r,  r")
+ (match_operand:SI 2 "nonmemory_operand" "rL,rL,Cal")))]
   ""
-  "min%? %0,%1,%2"
+  "min%?\\t%0,%1,%2"
   [(set_attr "type" "two_cycle_core")
(set_attr "length" "4,4,8")
(set_attr "predicable" "yes,no,no")]
@@ -2028,10 +2028,10 @@ (define_insn "sminsi3"
 ; We avoid letting this pattern use LP_COUNT as a register by specifying
 ;  register class 'W' instead of 'w'.
 (define_insn_and_split "*addsi3_mixed"
-  ;;  0   123  
 4   5   6 78   9   ab c   d e   f  10  11  12
-  [(set (match_operand:SI 0 "dest_reg_operand"  "=Rcq#q,Rcq,   
h,!*Rsd,Rcq,Rcb,Rcq, Rcqq,Rcqq,Rcw,Rcw, Rcw,W,  W,W,  W,Rcqq,Rcw,  W")
-   (plus:SI (match_operand:SI 1 "register_operand" "%0,  c,   0, Rcqq, 
 0,  0,Rcb, Rcqq,   0,  0,  c,   0,c,  c,0,  0,   0,  0,  c")
-(match_operand:SI 2 "nonmemory_operand" "cL, 0, Cm1,
L,CL2,Csp,CM4,RcqqK,  cO, cL,  0,cCca,cLCmL,Cca,I,C2a, Cal,Cal,Cal")))]
+  ;;  0   12 3 
  4   5   6 78  9 ab c   d e   f   10  11  12
+  [(set (match_operand:SI 0 "dest_reg_operand"  "=Rcq#q,Rcq,   
h,!*Rsd,Rcq,Rcb,Rcq, Rcqq,Rcqq, r,r,   r,W,  W,W,  W,Rcqq,  r,  W")
+   (plus:SI (match_operand:SI 1 "register_operand" "%0,  c,   0, Rcqq, 
 0,  0,Rcb, Rcqq,   0, 0,r,   0,c,  c,0,  0,   0,  0,  c")
+(match_operand:SI 2 "nonmemory_operand" "cL, 0, Cm1,
L,CL2,Csp,CM4,RcqqK,  cO,rL,0,rCca,cLCmL,Cca,I,C2a, Cal,Cal,Cal")))]
   ""
 {
   arc_output_addsi (operands, arc_ccfsm_cond_exec_p (), true);
@@ -2792,13 +2792,13 @@ (define_insn "add_f"
 (define_insn "*add_f_2"
   [(set (reg:CC_C CC_REG)
(compare:CC_C
- (plus:SI (match_operand:SI 1 "register_operand" "c,0,c")
-  (match_operand:SI 2 "nonmemory_operand" "cL,I,cCal"))
+ (plus:SI (match_operand:SI 1 "register_operand"  "r ,0,r")
+  (match_operand:SI 2 "nonmemory_operand" "rL,I,rCal"))
  (match_dup 2)))
-   (set (match_operand:SI 0 "dest_reg_operand" "=w,Rcw,w")
+   (set (match_operand:SI 0 "dest_reg_operand" "=r,r,r")
(plus:SI (match_dup 1) (match_dup 2)))]
   ""
-  "add.f %0,%1,%2"
+  "add.f\\t%0,%1,%2"
   [(set_attr "cond" "set")
(set_attr "type" "compare")
(set_attr "length" "4,4,8")])
@@ -2895,22 +2895,22 @@ (define_expand "subsi3"
 ; the casesi expander might generate a sub of zero, so we have to recognize it.
 ; combine should make such an insn go away.
 (define_insn_and_split "subsi3_insn"
-  [(set (match_operand:SI 0 "dest_reg_operand"   
"=Rcqq,Rcqq,Rcw,Rcw,w,w,w,  w,  w,  w")
-   (minus:SI (match_operand:SI 1 "nonmemory_operand""0,Rcqq,  0, 
cL,c,L,I,Cal,Cal,  c")
- (match_operand:SI 2 "nonmemory_opera

[committed 4/5] arc: Remove Rcq constraint.

2022-10-10 Thread Claudiu Zissulescu via Gcc-patches
gcc/
* config/arc/arc.cc (arc_check_short_reg_p): New function.
(arc_address_cost): Replace satisfies_constraint_Rcq with the
above new function.
(arc_output_addsi): Likewise.
(split_addsi): Likewise.
(split_subsi): Likewise.
* config/arc/arc.md (movqi_insn): Remove Rcq constraint.
(movhi_insn): Likewise.
(movsi_insn): Likewise.
(tst_movb): Likewise.
(tst): Likewise.
(tst_bitfield): Likewise.
(abssi2): Likewise.
(addsi3_mixed): Likewise.
(mulhisi3_reg): Likewise.
(umulhisi3_reg): Likewise.
(mulsi_600): Likewise.
(mul64): Likewise.
(subsi3_insn): Likewise.
(bicsi3_insn): Likewise.
(xorsi3): Likewise.
(negsi2): Likewise.
(one_cmplsi2): Likewise.
(lshrsi3_insn): Likewise.
(cmpsi_cc_insn_mixed): Likewise.
(cmpsi_cc_zn_insn): Likewise.
(btst): Likewise.
(cmpsi_cc_z_insn): Likewise.
(cmpsi_cc_c_insn): Likewise.
(indirect_jump): Likewise.
(casesi_jump): Likewise.
(call_i): Likewise.
(call_value_i): Likewise.
(bbit): Likewise.
(abssf2): Likewise.
(ashlsi2_cnt1): Likewise.
(lshrsi3_cnt1): Likewise.
(ashrsi3_cnt1): Likewise.
* config/arc/constraints.md (Rcq): Remove.

Signed-off-by: Claudiu Zissulescu 
---
 gcc/config/arc/arc.cc |  48 +++
 gcc/config/arc/arc.md | 152 --
 gcc/config/arc/constraints.md |  20 -
 3 files changed, 104 insertions(+), 116 deletions(-)

diff --git a/gcc/config/arc/arc.cc b/gcc/config/arc/arc.cc
index 7be27e01035..e6f52d87714 100644
--- a/gcc/config/arc/arc.cc
+++ b/gcc/config/arc/arc.cc
@@ -2474,6 +2474,20 @@ arc_setup_incoming_varargs (cumulative_args_t 
args_so_far,
 }
 }
 
+/* Return TRUE if reg is ok for short instrcutions.  */
+
+static bool
+arc_check_short_reg_p (rtx op)
+{
+  if (!REG_P (op))
+return false;
+
+  if (IN_RANGE (REGNO (op) ^ 4, 4, 11))
+return true;
+
+  return false;
+}
+
 /* Cost functions.  */
 
 /* Provide the costs of an addressing mode that contains ADDR.
@@ -2485,7 +2499,7 @@ arc_address_cost (rtx addr, machine_mode, addr_space_t, 
bool speed)
   switch (GET_CODE (addr))
 {
 case REG :
-  return speed || satisfies_constraint_Rcq (addr) ? 0 : 1;
+  return speed || arc_check_short_reg_p (addr) ? 0 : 1;
 case PRE_INC: case PRE_DEC: case POST_INC: case POST_DEC:
 case PRE_MODIFY: case POST_MODIFY:
   return !speed;
@@ -2517,14 +2531,14 @@ arc_address_cost (rtx addr, machine_mode, addr_space_t, 
bool speed)
? COSTS_N_INSNS (1)
: speed
? 0
-   : (satisfies_constraint_Rcq (plus0)
+   : (arc_check_short_reg_p (plus0)
   && satisfies_constraint_O (plus1))
? 0
: 1);
  case REG:
return (speed < 1 ? 0
-   : (satisfies_constraint_Rcq (plus0)
-  && satisfies_constraint_Rcq (plus1))
+   : (arc_check_short_reg_p (plus0)
+  && arc_check_short_reg_p (plus1))
? 0 : 1);
  case CONST :
  case SYMBOL_REF :
@@ -9003,8 +9017,8 @@ arc_output_addsi (rtx *operands, bool cond_p, bool 
output_p)
   int intval = (REG_P (operands[2]) ? 1
: CONST_INT_P (operands[2]) ? INTVAL (operands[2]) : 0xbadc057);
   int neg_intval = -intval;
-  int short_0 = satisfies_constraint_Rcq (operands[0]);
-  int short_p = (!cond_p && short_0 && satisfies_constraint_Rcq (operands[1]));
+  int short_0 = arc_check_short_reg_p (operands[0]);
+  int short_p = (!cond_p && short_0 && arc_check_short_reg_p (operands[1]));
   int ret = 0;
 
 #define REG_H_P(OP) (REG_P (OP) && ((TARGET_V2 && REGNO (OP) <= 31 \
@@ -9037,7 +9051,7 @@ arc_output_addsi (rtx *operands, bool cond_p, bool 
output_p)
 patterns.  */
   if (short_p
  && ((REG_H_P (operands[2])
-  && (match || satisfies_constraint_Rcq (operands[2])))
+  && (match || arc_check_short_reg_p (operands[2])))
  || (CONST_INT_P (operands[2])
  && ((unsigned) intval <= (match ? 127 : 7)
ADDSI_OUTPUT1 ("add%? %0,%1,%2 ;1");
@@ -9064,7 +9078,7 @@ arc_output_addsi (rtx *operands, bool cond_p, bool 
output_p)
   /* Generate add_s r0,b,u6; add_s r1,b,u6 patterns.  */
   if (TARGET_CODE_DENSITY && REG_P (operands[0]) && REG_P (operands[1])
  && ((REGNO (operands[0]) == 0) || (REGNO (operands[0]) == 1))
- && satisfies_constraint_Rcq (operands[1])
+ && arc_check_short_reg_p (operands[1])
  && satisfies_constraint_L (operands[2]))
ADDSI_OUTPUT1 ("add%? %0,%1,%2 ;6");
 }
@@ -10033,7 +10047,7 @@ split_addsi (rtx *operands)
   /* Try for two short insns 

[committed] openmp, fortran: Fix up IFN_ASSUME call

2022-10-10 Thread Jakub Jelinek via Gcc-patches
On Thu, Oct 06, 2022 at 06:15:52PM +0200, Tobias Burnus wrote:
> Like as attached? – It did survive regtesting.

Like in other spots in trans-openmp.cc that create a TARGET_EXPR, the
slot has to be created with create_tmp_var_raw, because gfc_create_var
adds the var to BLOCK_VARS and that ICEs during expansion because
gimple_add_tmp_var_fn has:
  gcc_assert (!DECL_CHAIN (tmp) && !DECL_SEEN_IN_BIND_EXPR_P (tmp));
assertion.  Also, both C/C++ ensure the argument to IFN_ASSUME has
boolean_type_node, it is easier if Fortran does that too.

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

2022-10-10  Jakub Jelinek  

* trans-openmp.cc (gfc_trans_omp_assume): Use create_tmp_var_raw
instead of gfc_create_var for TARGET_EXPR slot creation.  Create it
with boolean_type_node and convert.

--- gcc/fortran/trans-openmp.cc.jj  2022-10-07 00:13:12.508191601 +0200
+++ gcc/fortran/trans-openmp.cc 2022-10-09 14:17:55.430364168 +0200
@@ -4588,11 +4588,14 @@ gfc_trans_omp_assume (gfc_code *code)
  t = se.expr;
else
  {
-   tree var = gfc_create_var (TREE_TYPE (se.expr), NULL);
+   tree var = create_tmp_var_raw (boolean_type_node);
+   DECL_CONTEXT (var) = current_function_decl;
stmtblock_t block2;
gfc_init_block (&block2);
gfc_add_block_to_block (&block2, &se.pre);
-   gfc_add_modify_loc (loc, &block2, var, se.expr);
+   gfc_add_modify_loc (loc, &block2, var,
+   fold_convert_loc (loc, boolean_type_node,
+ se.expr));
gfc_add_block_to_block (&block2, &se.post);
t = gfc_finish_block (&block2);
t = build4 (TARGET_EXPR, boolean_type_node, var, t, NULL, NULL);

Jakub



[GCC][PATCH] arm: Add cde feature support for Cortex-M55 CPU.

2022-10-10 Thread Srinath Parvathaneni via Gcc-patches
Hi,

This patch adds cde feature (optional) support for Cortex-M55 CPU, please refer
[1] for more details. To use this feature we need to specify +cdecpN 
(e.g. -mcpu=cortex-m55+cdecp), where N is the coprocessor number 0 to 7.

Bootstrapped for arm-none-linux-gnueabihf target, regression tested
on arm-none-eabi target and found no regressions.

[1] https://developer.arm.com/documentation/101051/0101/?lang=en (version: 
r1p1).

Ok for master?

Regards,
Srinath.

gcc/ChangeLog:

2022-10-07  Srinath Parvathaneni  

* common/config/arm/arm-common.cc (arm_canon_arch_option_1): Ignore cde
options for mlibarch.
* config/arm/arm-cpus.in (begin cpu cortex-m55): Add cde options.
* doc/invoke.texi (CDE): Document options for Cortex-M55 CPU.

gcc/testsuite/ChangeLog:

2022-10-07  Srinath Parvathaneni  

* gcc.target/arm/multilib.exp: Add multilib tests for Cortex-M55 CPU.


### Attachment also inlined for ease of reply###


diff --git a/gcc/common/config/arm/arm-common.cc 
b/gcc/common/config/arm/arm-common.cc
index 
c38812f1ea6a690cd19b0dc74d963c4f5ae155ca..b6f955b3c012475f398382e72c9a3966412991ec
 100644
--- a/gcc/common/config/arm/arm-common.cc
+++ b/gcc/common/config/arm/arm-common.cc
@@ -753,6 +753,15 @@ arm_canon_arch_option_1 (int argc, const char **argv, bool 
arch_for_multilib)
   arm_initialize_isa (target_isa, selected_cpu->common.isa_bits);
   arm_parse_option_features (target_isa, &selected_cpu->common,
 strchr (cpu, '+'));
+  if (arch_for_multilib)
+   {
+ const enum isa_feature removable_bits[] = {ISA_IGNORE_FOR_MULTILIB,
+isa_nobit};
+ sbitmap isa_bits = sbitmap_alloc (isa_num_bits);
+ arm_initialize_isa (isa_bits, removable_bits);
+ bitmap_and_compl (target_isa, target_isa, isa_bits);
+   }
+
   if (fpu && strcmp (fpu, "auto") != 0)
{
  /* The easiest and safest way to remove the default fpu
diff --git a/gcc/config/arm/arm-cpus.in b/gcc/config/arm/arm-cpus.in
index 
5a63bc548e54dbfdce5d1df425bd615d81895d80..aa02c04c4924662f3ddd58e6967392ba3f4b4a87
 100644
--- a/gcc/config/arm/arm-cpus.in
+++ b/gcc/config/arm/arm-cpus.in
@@ -1633,6 +1633,14 @@ begin cpu cortex-m55
  option nomve remove mve mve_float
  option nofp remove ALL_FP mve_float
  option nodsp remove MVE mve_float
+ option cdecp0 add cdecp0
+ option cdecp1 add cdecp1
+ option cdecp2 add cdecp2
+ option cdecp3 add cdecp3
+ option cdecp4 add cdecp4
+ option cdecp5 add cdecp5
+ option cdecp6 add cdecp6
+ option cdecp7 add cdecp7
  isa quirk_no_asmcpu quirk_vlldm
  costs v7m
  vendor 41
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 
aa5655764a0360959f9c1061749d2cc9ebd23489..26857f7a90e42d925bc6908686ac78138a53c4ad
 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -21698,6 +21698,10 @@ floating-point instructions on @samp{cortex-m55}.
 Disable the M-Profile Vector Extension (MVE) single precision floating-point
 instructions on @samp{cortex-m55}.
 
+@item +cdecp0, +cdecp1, ... , +cdecp7
+Enable the Custom Datapath Extension (CDE) on selected coprocessors according
+to the numbers given in the options in the range 0 to 7 on @samp{cortex-m55}.
+
 @item  +nofp
 Disables the floating-point instructions on @samp{arm9e},
 @samp{arm946e-s}, @samp{arm966e-s}, @samp{arm968e-s}, @samp{arm10e},
diff --git a/gcc/testsuite/gcc.target/arm/multilib.exp 
b/gcc/testsuite/gcc.target/arm/multilib.exp
index 
2fa648c61dafebb663969198bf7849400a7547f6..7a977bff58b7b68bfe9e49d7602989a39caa6534
 100644
--- a/gcc/testsuite/gcc.target/arm/multilib.exp
+++ b/gcc/testsuite/gcc.target/arm/multilib.exp
@@ -851,6 +851,18 @@ if {[multilib_config "rmprofile"] } {
{-mcpu=cortex-m55+nomve+nofp -mfpu=auto -mfloat-abi=softfp} 
"thumb/v8-m.main/nofp"
{-mcpu=cortex-m55+nodsp+nofp -mfpu=auto -mfloat-abi=soft} 
"thumb/v8-m.main/nofp"
{-mcpu=cortex-m55+nodsp+nofp -mfpu=auto -mfloat-abi=softfp} 
"thumb/v8-m.main/nofp"
+   {-mcpu=cortex-m55 -mfloat-abi=hard -mfpu=auto} "thumb/v8-m.main+dp/hard"
+   {-mcpu=cortex-m55+cdecp0 -mfloat-abi=hard -mfpu=auto} 
"thumb/v8-m.main+dp/hard"
+   {-mcpu=cortex-m55+nomve+cdecp0 -mfloat-abi=hard -mfpu=auto} 
"thumb/v8-m.main+dp/hard"
+   
{-mcpu=cortex-m55+cdecp0+cdecp1+cdecp2+cdecp3+cdecp4+cdecp5+cdecp6+cdecp7 
-mfloat-abi=hard -mfpu=auto} "thumb/v8-m.main+dp/hard"
+   {-mcpu=cortex-m55 -mfloat-abi=softfp -mfpu=auto} 
"thumb/v8-m.main+dp/softfp"
+   {-mcpu=cortex-m55+cdecp0 -mfloat-abi=softfp -mfpu=auto} 
"thumb/v8-m.main+dp/softfp"
+   {-mcpu=cortex-m55+nomve+cdecp0 -mfloat-abi=softfp -mfpu=auto} 
"thumb/v8-m.main+dp/softfp"
+   
{-mcpu=cortex-m55+cdecp0+cdecp1+cdecp2+cdecp3+cdecp4+cdecp5+cdecp6+cdecp7 
-mfloat-abi=softfp -mfpu=auto} "thumb/v8-m.main+dp/softfp"
+   {-mcpu=cortex-m55 -mfloat-abi=soft -mfpu=auto} "thumb/v8-m.main/nofp"
+   {-mcp

[patch] Tighten VXWORKS_LIBGCC_SPEC wrt libgcc_eh

2022-10-10 Thread Olivier Hainque via Gcc-patches
Hello,

VxWorks has a custom definition of LIBGCC_SPEC to accommodate
the variety of "modules" a user can build (dkm, sharedlib (-shared),
static rtp, or rtp depending on shared libs (-non-static))

This change reworks that spec to better support configurations with
shared libraries enabled (patch coming) and document the variations.

The change also prepares for a possible dual-eh (dwarf+sjlj) setup,
which we (AdaCore) work on proposing. The impact on this patch is really
minimal and there's no functional impact at all in the interim.

The bulk of the change consists in the introduction of a couple of local
macros that instantiate the link options needed to include libgcc_eh in
the closure, with values depending on the configuration characteristics.

A few comments are added to explain the general idea and each of the
variations. Part of the changes consist in adding -lgcc after -lgcc_eh
to accommodate configurations where libgcc_eh legitimately resort to
libgcc functions on some targets, for example cas synchronisation routines
on aarch64.


We have been using this for a while in house for gcc-11 based toolchains
targetting a range of vxworks7r2 configurations (arm, aarch64, ppc, ppc64,
x86, x86_64, with shared libraries enabled for all the 64bit variants),
as well as for vxworks6.9 on powerpc.

I have verified that gcc-12 based toolchain for arm, ppc and ppc64 behave
as expected and performed a sanity check build for powerpc64-vxworks7r2 on
mainline.

Will commit shortly.

Cheers,

Olivier

2022-10-09  Olivier Hainque  

* config/vxworks (VX_LGCC_EH_SO0, VX_LGCC_EH_SO1): New internal macros.
(VXWORKS_LIBGCC_SPEC): Use them and document.



0001-Tigthen-the-addition-of-lgcc_eh-to-vxworks_libgcc_sp.patch
Description: Binary data




Re: [PATCH v2 00/10] Introduce strub: machine-independent stack scrubbing

2022-10-10 Thread Richard Biener via Gcc-patches
On Fri, Jul 29, 2022 at 8:36 AM Alexandre Oliva  wrote:
>
> On Jul 29, 2022, Alexandre Oliva  wrote:
>
> > This patch adds the strub attribute for function and variable types,
> > command-line options, passes and adjustments to implement it,
> > documentation, and tests.
>
> The entire patch, and the patchlets used for testing, are available from
> the GCC git repo, branch refs/users/aoliva/heads/strub:

As noted in the Cauldron Discussion I think you should do all instrumentation
post-IPA only to simplify your life not needing to handle inlining of
instrumentation
and to get the full benefit of WPA analysis when used with LTO.  That might
even mean doing it as a regular IPA pass where clones are used for strubbing
and original bodies are used for inlining.

Richard.

> e9d1e252e0bcd silence warnings
> 4a93638ee91b1 enable strub for all viable functions by default, for testing
> 29e98f10c5faa Introduce strub: machine-independent stack scrubbing
>
> --
> Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
>Free Software Activist   GNU Toolchain Engineer
> Disinformation flourishes because many people care deeply about injustice
> but very few check the facts.  Ask me about 


[PATCH] middle-end IFN_ASSUME support [PR106654]

2022-10-10 Thread Jakub Jelinek via Gcc-patches
Hi!

My earlier patches gimplify the simplest non-side-effects assumptions
into if (cond) ; else __builtin_unreachable (); and throw the rest
on the floor.
The following patch attempts to do something with the rest too.
For -O0, it actually throws even the simplest assumptions on the floor,
we don't expect optimizations and the assumptions are there to allow
optimizations.  Otherwise, it keeps the handling of the simplest
assumptions as is, and otherwise arranges for the assumptions to be
visible in the IL as
  .ASSUME (_Z2f4i._assume.0, i_1(D));
call where there is an artificial function like:
bool _Z2f4i._assume.0 (int i)
{
  bool _2;

   [local count: 1073741824]:
  _2 = i_1(D) == 43;
  return _2;

}
with the semantics that there is UB unless the assumption function
would return true.

Aldy, could ranger handle this?  If it sees .ASSUME call,
walk the body of such function from the edge(s) to exit with the
assumption that the function returns true, so above set _2 [true, true]
and from there derive that i_1(D) [43, 43] and then map the argument
in the assumption function to argument passed to IFN_ASSUME (note,
args there are shifted by 1)?

During gimplification it actually gimplifies it into
  D.2591 = .ASSUME ();
  if (D.2591 != 0) goto ; else goto ;
  :
  {
i = i + 1;
D.2591 = i == 44;
  }
  :
  .ASSUME (D.2591);
with the condition wrapped into a GIMPLE_BIND (I admit the above isn't
extra clean but it is just something to hold it from gimplifier until
gimple low pass; it reassembles if (condition_never_true) { cond; };
an alternative would be introduce GOMP_ASSUME statement that would have
the guard var as operand and the GIMPLE_BIND as body, but for the
few passes (tree-nested and omp lowering) in between that looked like
an overkill to me) which is then pattern matched during gimple lowering
and outlined into a separate function.  Variables declared inside of the
condition (both static and automatic) just change context, automatic
variables from the caller are turned into parameters (note, as the code
is never executed, I handle this way even non-POD types, we don't need to
bother pretending there would be user copy constructors etc. involved).

The assume_function artificial functions are then optimized until RTL
expansion, which isn't done for them nor any later pass, on the other
side bodies are not freed when done.

Earlier version of the patch has been successfully bootstrapped/regtested
on x86_64-linux and i686-linux and all assume tests have passed even with
this version.  Ok for trunk if it succeeds on another bootstrap/regtest?

There are a few further changes I'd like to do, like ignoring the
.ASSUME calls in inlining size estimations (but haven't figured out where
it is done), or for LTO arrange for the assume functions to be emitted
in all partitions that reference those (usually there will be just one,
unless code with the assumption got inlined, versioned etc.).

2022-10-10  Jakub Jelinek  

PR c++/106654
gcc/
* function.h (struct function): Add assume_function bitfield.
* gimplify.cc (gimplify_call_expr): For -O0, always throw
away assumptions on the floor immediately.  Otherwise if the
assumption isn't simple enough, expand it into IFN_ASSUME
guarded block.
* gimple-low.cc (create_assumption_fn): New function.
(struct lower_assumption_data): New type.
(find_assumption_locals_r, assumption_copy_decl,
adjust_assumption_stmt_r, adjust_assumption_stmt_op,
lower_assumption): New functions.
(lower_stmt): Handle IFN_ASSUME guarded block.
* tree-ssa-ccp.cc (pass_fold_builtins::execute): Remove
IFN_ASSUME calls.
* lto-streamer-out.cc (output_struct_function_base): Pack
assume_function bit.
* lto-streamer-in.cc (input_struct_function_base): And unpack it.
* cgraphunit.cc (cgraph_node::expand): Don't verify assume_function
has TREE_ASM_WRITTEN set and don't release its body.
* cfgexpand.cc (pass_expand::execute): Don't expand assume_function
into RTL, just destroy loops and exit.
* internal-fn.cc (expand_ASSUME): Remove gcc_unreachable.
* passes.cc (pass_rest_of_compilation::gate): Return false also for
fun->assume_function.
* tree-vectorizer.cc (pass_vectorize::gate,
pass_slp_vectorize::gate): Likewise.
* ipa-icf.cc (sem_function::parse): Punt for func->assume_function.
gcc/cp/
* parser.cc (cp_parser_omp_assumption_clauses): Wrap IFN_ASSUME
argument with fold_build_cleanup_point_expr.
* cp-gimplify.cc (process_stmt_assume_attribute): Likewise.
* pt.cc (tsubst_copy_and_build): Likewise.
gcc/testsuite/
* g++.dg/cpp23/attr-assume5.C: New test.
* g++.dg/cpp23/attr-assume6.C: New test.
* g++.dg/cpp23/attr-assume7.C: New test.

--- gcc/function.h.jj   2022-10-10 09:31:22.051478926 +0200
+++ gcc/function.h  2022-10-10 09

Re: [RFC] Add op1_range for __builtin_signbit.

2022-10-10 Thread Aldy Hernandez via Gcc-patches
I have committed this patch, as the __builtin_signbit range-op entry
is correct.  I'd still like clarification on the folding).

Aldy

On Thu, Oct 6, 2022 at 12:51 PM Aldy Hernandez  wrote:
>
> This is the op1_range range-op entry for __builtin_signbit.  It allows
> us to wind back through a call to signbit.
>
> For example, on the true side of if (__builtin_signbit(x_5) != 0) we
> can crop down the range of x_5 to:
>
> [frange] float [-Inf, -0.0 (-0x0.0p+0)] -NAN
>
> Similarly on the false side, we can crop to:
>
> [frange] float [0.0 (0x0.0p+0), +Inf] +NAN
>
> This brings about an interesting question, can we fold the second
> conditional here as always false?
>
> void foo(float x)
> {
>   if (__builtin_signbit (x))
> {
>   if (x > 0.0)
> link_error();
> }
> }
>
> The only values for x at the second conditional are negative values,
> or -NAN, so it will always evaluate to false.  ISTM that we
> *shouldn't* fold this conditional as there is user observable behavior
> if there is a signaling NAN.  For that matter, that is exactly what we
> do in ranger-ops.  We leave the conditional in place, but ranger
> is able to determine that "x" is UNDEFINED on the path leading up to
> link_error:
>
> === BB 3 
> Imports: x_3(D)
> Exports: x_3(D)
> x_3(D)  [frange] float [-Inf, -0.0 (-0x0.0p+0)] -NAN
>  :
> if (x_3(D) > 0.0)
>   goto ; [INV]
> else
>   goto ; [INV]
>
> 3->4  (T) x_3(D) :  [frange] UNDEFINED
> 3->5  (F) x_3(D) :  [frange] float [-Inf, -0.0 (-0x0.0p+0)] -NAN
>
> This would allow users of ranger to query x_3 on the 3->4 and notice
> it's unreachable, without VRP removing the conditional.
>
> I believe this is correct, but would like confirmation from the experts.
>
> gcc/ChangeLog:
>
> * gimple-range-op.cc: Add op1_range entry for __builtin_signbit.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/tree-ssa/vrp-float-signbit-3.c: New test.
> ---
>  gcc/gimple-range-op.cc| 20 +++
>  .../gcc.dg/tree-ssa/vrp-float-signbit-3.c | 14 +
>  2 files changed, 34 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c
>
> diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc
> index 42ebc7d6ce5..abc33e7af0c 100644
> --- a/gcc/gimple-range-op.cc
> +++ b/gcc/gimple-range-op.cc
> @@ -306,6 +306,7 @@ class cfn_signbit : public range_operator_float
>  {
>  public:
>using range_operator_float::fold_range;
> +  using range_operator_float::op1_range;
>virtual bool fold_range (irange &r, tree type, const frange &lh,
>const irange &, relation_kind) const
>{
> @@ -320,6 +321,25 @@ public:
>}
> return false;
>}
> +  virtual bool op1_range (frange &r, tree type, const irange &lhs,
> + const frange &, relation_kind) const override
> +  {
> +if (lhs.zero_p ())
> +  {
> +   r.set (type, dconst0, frange_val_max (type));
> +   r.update_nan (false);
> +   return true;
> +  }
> +if (!lhs.contains_p (build_zero_cst (lhs.type (
> +  {
> +   REAL_VALUE_TYPE dconstm0 = dconst0;
> +   dconstm0.sign = 1;
> +   r.set (type, frange_val_min (type), dconstm0);
> +   r.update_nan (true);
> +   return true;
> +  }
> +return false;
> +  }
>  } op_cfn_signbit;
>
>  // Implement range operator for CFN_BUILT_IN_TOUPPER and 
> CFN_BUILT_IN_TOLOWER.
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c
> new file mode 100644
> index 000..dd3090aeb10
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c
> @@ -0,0 +1,14 @@
> +// { dg-do compile }
> +// { dg-options "-O2 -ffast-math -fdump-tree-evrp" }
> +
> +void link_error();
> +
> +void foo(float x)
> +{
> +  if (__builtin_signbit (x))
> +{
> +  if (x > 0.0)
> +   link_error();
> +}
> +}
> +// { dg-final { scan-tree-dump-not "link_error" "evrp" } }
> --
> 2.37.1
>



Require fgraphite effective target for pr107153.c test [PR107153]

2022-10-10 Thread Jakub Jelinek via Gcc-patches
Hi!

On Fri, Oct 07, 2022 at 02:26:56PM +0200, Richard Biener via Gcc-patches wrote:
>   * gcc.dg/autopar/pr107153.c: New testcase.

The test uses -floop-parallelize-all which emits a sorry when graphite
isn't configured in.

Tested on x86_64-linux and i686-linux, committed to trunk as obvious.

2022-10-10  Jakub Jelinek  

PR tree-optimization/107153
* gcc.dg/autopar/pr107153.c: Require fgraphite effective target.

--- gcc/testsuite/gcc.dg/autopar/pr107153.c.jj  2022-10-10 09:31:57.664981573 
+0200
+++ gcc/testsuite/gcc.dg/autopar/pr107153.c 2022-10-10 11:59:00.365605619 
+0200
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target fgraphite } } */
 /* { dg-options "-O1 -floop-parallelize-all -ftree-parallelize-loops=2 
-fno-tree-dominator-opts" } */
 
 void


Jakub



Re: [PATCH v4 4/4] OpenMP/OpenACC: Unordered/non-constant component offset struct mapping

2022-10-10 Thread Jakub Jelinek via Gcc-patches
On Sun, Oct 09, 2022 at 02:51:37PM -0700, Julian Brown wrote:
> This patch adds support for non-constant component offsets in "map"
> clauses for OpenMP (and the equivalants for OpenACC), which are not able
> to be sorted into order at compile time.  Normally struct accesses in
> such clauses are gathered together and sorted into increasing address
> order after a "GOMP_MAP_STRUCT" node: if we have variable indices,
> that is no longer possible.
> 
> This patch adds support for such mappings by adding a new variant of
> GOMP_MAP_STRUCT that does not require the list of nodes following to
> be in sorted order.  This passes right down to the runtime: the list is
> sorted in libgomp according to the dynamic values of the offsets after
> the newly-introduced GOMP_MAP_STRUCT_UNORD node.
> 
> This mostly affects arrays of structs indexed by variables in C and C++,
> but can also affect derived-type arrays with constant indexes when they
> have an array descriptor.

I don't understand why this is needed.
We have a restriction that ought to make all such cases invalid:
"If multiple list items are explicitly mapped on the same construct and have 
the same containing
array or have base pointers that share original storage, and if any of the list 
items do not have
corresponding list items that are present in the device data environment prior 
to a task
encountering the construct, then the list items must refer to the same array 
elements of either the
containing array or the implicit array of the base pointers."

So, all those
#pragma omp target map(t->a[i].p, t->a[j].p) etc. cases are invalid unless
i == j, so IMNSHO one doesn't need to worry about unordered cases.

> +#if defined(_GNU_SOURCE) || defined(__GNUC__)
> +static int
> +compare_addr_r (const void *a, const void *b, void *data)
> +{
> +  void **hostaddrs = (void **) data;
> +  int ai = *(int *) a, bi = *(int *) b;
> +  if (hostaddrs[ai] < hostaddrs[bi])
> +return -1;
> +  else if (hostaddrs[ai] > hostaddrs[bi])
> +return 1;
> +  return 0;
> +}
> +#endif

Note, not all glibcs have qsort_r and _GNU_SOURCE macro being defined
doesn't imply glibc.  You'd need something like _GLIBC_PREREQ macro
and require 2.8 or later.

> +
>  static inline __attribute__((always_inline)) struct target_mem_desc *
>  gomp_map_vars_internal (struct gomp_device_descr *devicep,
>   struct goacc_asyncqueue *aq, size_t mapnum,
> @@ -968,6 +982,17 @@ gomp_map_vars_internal (struct gomp_device_descr 
> *devicep,
>tgt->device_descr = devicep;
>tgt->prev = NULL;
>struct gomp_coalesce_buf cbuf, *cbufp = NULL;
> +  size_t hostaddr_idx;
> +
> +#if !defined(_GNU_SOURCE) && defined(__GNUC__)
> +  /* If we don't have _GNU_SOURCE (thus no qsort_r), but we are compiling 
> with
> + GCC (and why wouldn't we be?), we can use this nested function for
> + regular qsort.  */
> +  int compare_addr (const void *a, const void *b)
> +{
> +  return compare_addr_r (a, b, (void *) &hostaddrs[hostaddr_idx]);
> +}
> +#endif

Please don't use nested functions in libgomp.

> +   int *order = NULL;
> +   if ((kind & typemask) == GOMP_MAP_STRUCT_UNORD)
> + {
> +   order = (int *) gomp_alloca (sizeof (int) * sizes[i]);
> +   for (int j = 0; j < sizes[i]; j++)
> + order[j] = j;
> +#ifdef _GNU_SOURCE
> +   qsort_r (order, sizes[i], sizeof (int), &compare_addr_r,
> +&hostaddrs[i + 1]);
> +#elif defined(__GNUC__)
> +   hostaddr_idx = i + 1;
> +   qsort (order, sizes[i], sizeof (int), &compare_addr);
> +#else
> +#error no threadsafe qsort
> +#endif

This is too ugly.  If this is really needed (see above) and
you need fallback for missing qsort_t, better sort array of tuples
containing the order number and some data pointer needed for the comparison
routine.

Jakub



Re: Extend fold_vec_perm to fold VEC_PERM_EXPR in VLA manner

2022-10-10 Thread Prathamesh Kulkarni via Gcc-patches
On Fri, 30 Sept 2022 at 21:38, Richard Sandiford
 wrote:
>
> Richard Sandiford via Gcc-patches  writes:
> > Prathamesh Kulkarni  writes:
> >> Sorry to ask a silly question but in which case shall we select 2nd vector 
> >> ?
> >> For num_poly_int_coeffs == 2,
> >> a1 /trunc n1 == (a1 + 0x) / (n1.coeffs[0] + n1.coeffs[1]*x)
> >> If a1/trunc n1 succeeds,
> >> 0 / n1.coeffs[1] == a1/n1.coeffs[0] == 0.
> >> So, a1 has to be < n1.coeffs[0] ?
> >
> > Remember that a1 is itself a poly_int.  It's not necessarily a constant.
> >
> > E.g. the TRN1 .D instruction maps to a VEC_PERM_EXPR with the selector:
> >
> >   { 0, 2 + 2x, 1, 4 + 2x, 2, 6 + 2x, ... }
>
> Sorry, should have been:
>
>   { 0, 2 + 2x, 2, 4 + 2x, 4, 6 + 2x, ... }
Hi Richard,
Thanks for the clarifications, and sorry for late reply.
I have attached POC patch that tries to implement the above approach.
Passes bootstrap+test on x86_64-linux-gnu and aarch64-linux-gnu for VLS vectors.

For VLA vectors, I have only done limited testing so far.
It seems to pass couple of tests written in the patch for
nelts_per_pattern == 3,
and folds the following svld1rq test:
int32x4_t v = {1, 2, 3, 4};
return svld1rq_s32 (svptrue_b8 (), &v[0])
into:
return {1, 2, 3, 4, ...};
I will try to bootstrap+test it on SVE machine to test further for VLA folding.

I have a couple of questions:
1] When mask selects elements from same vector but from different patterns:
For eg:
arg0 = {1, 11, 2, 12, 3, 13, ...},
arg1 = {21, 31, 22, 32, 23, 33, ...},
mask = {0, 0, 0, 1, 0, 2, ... },
All have npatterns = 2, nelts_per_pattern = 3.

With above mask,
Pattern {0, ...} selects arg0[0], ie {1, ...}
Pattern {0, 1, 2, ...} selects arg0[0], arg0[1], arg0[2], ie {1, 11, 2, ...}
While arg0[0] and arg0[2] belong to same pattern, arg0[1] belongs to different
pattern in arg0.
The result is:
res = {1, 1, 1, 11, 1, 2, ...}
In this case, res's 2nd pattern {1, 11, 2, ...} is encoded with:
with a0 = 1, a1 = 11, S = -9.
Is that expected tho ? It seems to create a new encoding which
wasn't present in the input vector. For instance, the next elem in
sequence would be -7,
which is not present originally in arg0.
I suppose it's fine since if the user defines mask to have pattern {0,
1, 2, ...}
they intended result to have pattern with above encoding.
Just wanted to confirm if this is correct ?

2] Could you please suggest a test-case for S < 0 ?
I am not able to come up with one :/

Thanks,
Prathamesh
>
> > which is an interleaving of the two patterns:
> >
> >   { 0, 2, 4, ... }  a0 = 0, a1 = 2, S = 2
> >   { 2 + 2x, 4 + 2x, 6 + 2x }a0 = 2 + 2x, a1 = 4 + 2x, S = 2
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 9f7beae14e5..a150a75faf5 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -85,6 +85,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "vec-perm-indices.h"
 #include "asan.h"
 #include "gimple-range.h"
+#include 
+#include "tree-pretty-print.h"
+#include "print-tree.h"
 
 /* Nonzero if we are folding constants inside an initializer or a C++
manifestly-constant-evaluated context; zero otherwise.
@@ -10494,38 +10497,53 @@ fold_mult_zconjz (location_t loc, tree type, tree 
expr)
  build_zero_cst (itype));
 }
 
+/* Check if PATTERN in SEL selects either ARG0 or ARG1,
+   and return the selected arg, otherwise return NULL_TREE.  */
 
-/* Helper function for fold_vec_perm.  Store elements of VECTOR_CST or
-   CONSTRUCTOR ARG into array ELTS, which has NELTS elements, and return
-   true if successful.  */
-
-static bool
-vec_cst_ctor_to_array (tree arg, unsigned int nelts, tree *elts)
+static tree
+get_vector_for_pattern (tree arg0, tree arg1,
+   const vec_perm_indices &sel, unsigned pattern)
 {
-  unsigned HOST_WIDE_INT i, nunits;
+  unsigned sel_npatterns = sel.encoding ().npatterns ();
+  unsigned sel_nelts_per_pattern = sel.encoding ().nelts_per_pattern ();
 
-  if (TREE_CODE (arg) == VECTOR_CST
-  && VECTOR_CST_NELTS (arg).is_constant (&nunits))
+  poly_uint64 n1 = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
+  poly_uint64 nsel = sel.length ();
+  poly_uint64 esel;
+
+  if (!multiple_p (nsel, sel_npatterns, &esel))
+return NULL_TREE;
+
+  poly_uint64 a1 = sel[pattern + sel_npatterns];
+  int S = 0;
+  if (sel_nelts_per_pattern == 3)
 {
-  for (i = 0; i < nunits; ++i)
-   elts[i] = VECTOR_CST_ELT (arg, i);
+  poly_uint64 a2 = sel[pattern + 2 * sel_npatterns];
+  S = (a2 - a1).to_constant ();
 }
-  else if (TREE_CODE (arg) == CONSTRUCTOR)
+  
+  poly_uint64 ae = a1 + (esel - 2) * S;
+  uint64_t q1, qe;
+  poly_uint64 r1, re;
+
+  if (!can_div_trunc_p (a1, n1, &q1, &r1)
+  || !can_div_trunc_p (ae, n1, &qe, &re)
+  || (q1 != qe))
+return NULL_TREE;
+
+  tree arg = ((q1 & 1) == 0) ? arg0 : arg1;
+
+  if (S < 0)
 {
-  constructor_elt *elt;
+  poly_uint64 a0 = sel[pattern];
+  if (!known_eq (S, a1 - a0))
+return NULL_TREE;
 
-  FOR_EACH_

[PATCH][RFT] Vectorization of first-order recurrences

2022-10-10 Thread Richard Biener via Gcc-patches
The following picks up the prototype by Ju-Zhe Zhong for vectorizing
first order recurrences.  That solves two TSVC missed optimization PRs.

There's a new scalar cycle def kind, vect_first_order_recurrence
and it's handling of the backedge value vectorization is complicated
by the fact that the vectorized value isn't the PHI but instead
a (series of) permute(s) shifting in the recurring value from the
previous iteration.  I've implemented this by creating both the
single vectorized PHI and the series of permutes when vectorizing
the scalar PHI but leave the backedge values in both unassigned.
The backedge values are (for the testcases) computed by a load
which is also the place after which the permutes are inserted.
That placement also restricts the cases we can handle (without
resorting to code motion).

I added both costing and SLP handling though SLP handling is
restricted to the case where a single vectorized PHI is enough.

Missing is epilogue handling - while prologue peeling would
be handled transparently by adjusting iv_phi_p the epilogue
case doesn't work with just inserting a scalar LC PHI since
that a) keeps the scalar load live and b) that loads is the
wrong one, it has to be the last, much like when we'd vectorize
the LC PHI as live operation.  Unfortunately LIVE
compute/analysis happens too early before we decide on
peeling.  When using fully masked loop vectorization the
vect-recurr-6.c works as expected though.

I have tested this on x86_64 for now, but since epilogue
handling is missing there's probably no practical cases.
My prototype WHILE_ULT AVX512 patch can handle vect-recurr-6.c
just fine but I didn't feel like running SPEC within SDE nor
is the WHILE_ULT patch complete enough.  Builds of SPEC 2k7
with fully masked loops succeed (minus three cases of
PR107096, caused by my WHILE_ULT prototype).

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

Testing with SVE, GCN or RVV appreciated, ideas how to cleanly
handle epilogues welcome.

Thanks,
Richard.

PR tree-optimization/99409
PR tree-optimization/99394
* tree-vectorizer.h (vect_def_type::vect_first_order_recurrence): Add.
(stmt_vec_info_type::recurr_info_type): Likewise.
(vectorizable_recurr): New function.
* tree-vect-loop.cc (vect_phi_first_order_recurrence_p): New
function.
(vect_analyze_scalar_cycles_1): Look for first order
recurrences.
(vect_analyze_loop_operations): Handle them.
(vect_transform_loop): Likewise.
(vectorizable_recurr): New function.
(maybe_set_vectorized_backedge_value): Handle the backedge value
setting in the first order recurrence PHI and the permutes.
* tree-vect-stmts.cc (vect_analyze_stmt): Handle first order
recurrences.
(vect_transform_stmt): Likewise.
(vect_is_simple_use): Likewise.
(vect_is_simple_use): Likewise.
* tree-vect-slp.cc (vect_get_and_check_slp_defs): Likewise.
(vect_build_slp_tree_2): Likewise.
(vect_schedule_scc): Handle the backedge value setting in the
first order recurrence PHI and the permutes.

* gcc.dg/vect/vect-recurr-1.c: New testcase.
* gcc.dg/vect/vect-recurr-2.c: Likewise.
* gcc.dg/vect/vect-recurr-3.c: Likewise.
* gcc.dg/vect/vect-recurr-4.c: Likewise.
* gcc.dg/vect/vect-recurr-5.c: Likewise.
* gcc.dg/vect/vect-recurr-6.c: Likewise.
* gcc.dg/vect/tsvc/vect-tsvc-s252.c: Un-XFAIL.
* gcc.dg/vect/tsvc/vect-tsvc-s254.c: Likewise.
* gcc.dg/vect/tsvc/vect-tsvc-s291.c: Likewise.

Co-authored-by: Ju-Zhe Zhong 
---
 .../gcc.dg/vect/tsvc/vect-tsvc-s252.c |   2 +-
 .../gcc.dg/vect/tsvc/vect-tsvc-s254.c |   2 +-
 .../gcc.dg/vect/tsvc/vect-tsvc-s291.c |   2 +-
 gcc/testsuite/gcc.dg/vect/vect-recurr-1.c |  38 +++
 gcc/testsuite/gcc.dg/vect/vect-recurr-2.c |  39 +++
 gcc/testsuite/gcc.dg/vect/vect-recurr-3.c |  39 +++
 gcc/testsuite/gcc.dg/vect/vect-recurr-4.c |  42 +++
 gcc/testsuite/gcc.dg/vect/vect-recurr-5.c |  43 +++
 gcc/testsuite/gcc.dg/vect/vect-recurr-6.c |  39 +++
 gcc/tree-vect-loop.cc | 286 --
 gcc/tree-vect-slp.cc  |  38 ++-
 gcc/tree-vect-stmts.cc|  17 +-
 gcc/tree-vectorizer.h |   4 +
 13 files changed, 563 insertions(+), 28 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-1.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-2.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-3.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-4.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-5.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-6.c

diff --git a/gcc/testsuite/gcc.dg/vect/tsvc/vect-tsvc-s252.c 
b/gcc/testsuite/gcc.dg/vect/tsvc/vect-tsvc-s252.c
index f1302b60ae5..83eaa7a8ff5 100644
--- a/gcc/test

Re: [PATCH][RFT] Vectorization of first-order recurrences

2022-10-10 Thread juzhe.zh...@rivai.ai
Thank you so much. I will apply this patch and test it in downstream RVV GCC 
(12.2.0)


juzhe.zh...@rivai.ai
 
From: Richard Biener
Date: 2022-10-10 19:03
To: gcc-patches
CC: richard.sandiford; ams; juzhe.zhong
Subject: [PATCH][RFT] Vectorization of first-order recurrences
The following picks up the prototype by Ju-Zhe Zhong for vectorizing
first order recurrences.  That solves two TSVC missed optimization PRs.
 
There's a new scalar cycle def kind, vect_first_order_recurrence
and it's handling of the backedge value vectorization is complicated
by the fact that the vectorized value isn't the PHI but instead
a (series of) permute(s) shifting in the recurring value from the
previous iteration.  I've implemented this by creating both the
single vectorized PHI and the series of permutes when vectorizing
the scalar PHI but leave the backedge values in both unassigned.
The backedge values are (for the testcases) computed by a load
which is also the place after which the permutes are inserted.
That placement also restricts the cases we can handle (without
resorting to code motion).
 
I added both costing and SLP handling though SLP handling is
restricted to the case where a single vectorized PHI is enough.
 
Missing is epilogue handling - while prologue peeling would
be handled transparently by adjusting iv_phi_p the epilogue
case doesn't work with just inserting a scalar LC PHI since
that a) keeps the scalar load live and b) that loads is the
wrong one, it has to be the last, much like when we'd vectorize
the LC PHI as live operation.  Unfortunately LIVE
compute/analysis happens too early before we decide on
peeling.  When using fully masked loop vectorization the
vect-recurr-6.c works as expected though.
 
I have tested this on x86_64 for now, but since epilogue
handling is missing there's probably no practical cases.
My prototype WHILE_ULT AVX512 patch can handle vect-recurr-6.c
just fine but I didn't feel like running SPEC within SDE nor
is the WHILE_ULT patch complete enough.  Builds of SPEC 2k7
with fully masked loops succeed (minus three cases of
PR107096, caused by my WHILE_ULT prototype).
 
Bootstrapped and tested on x86_64-unknown-linux-gnu.
 
Testing with SVE, GCN or RVV appreciated, ideas how to cleanly
handle epilogues welcome.
 
Thanks,
Richard.
 
PR tree-optimization/99409
PR tree-optimization/99394
* tree-vectorizer.h (vect_def_type::vect_first_order_recurrence): Add.
(stmt_vec_info_type::recurr_info_type): Likewise.
(vectorizable_recurr): New function.
* tree-vect-loop.cc (vect_phi_first_order_recurrence_p): New
function.
(vect_analyze_scalar_cycles_1): Look for first order
recurrences.
(vect_analyze_loop_operations): Handle them.
(vect_transform_loop): Likewise.
(vectorizable_recurr): New function.
(maybe_set_vectorized_backedge_value): Handle the backedge value
setting in the first order recurrence PHI and the permutes.
* tree-vect-stmts.cc (vect_analyze_stmt): Handle first order
recurrences.
(vect_transform_stmt): Likewise.
(vect_is_simple_use): Likewise.
(vect_is_simple_use): Likewise.
* tree-vect-slp.cc (vect_get_and_check_slp_defs): Likewise.
(vect_build_slp_tree_2): Likewise.
(vect_schedule_scc): Handle the backedge value setting in the
first order recurrence PHI and the permutes.
 
* gcc.dg/vect/vect-recurr-1.c: New testcase.
* gcc.dg/vect/vect-recurr-2.c: Likewise.
* gcc.dg/vect/vect-recurr-3.c: Likewise.
* gcc.dg/vect/vect-recurr-4.c: Likewise.
* gcc.dg/vect/vect-recurr-5.c: Likewise.
* gcc.dg/vect/vect-recurr-6.c: Likewise.
* gcc.dg/vect/tsvc/vect-tsvc-s252.c: Un-XFAIL.
* gcc.dg/vect/tsvc/vect-tsvc-s254.c: Likewise.
* gcc.dg/vect/tsvc/vect-tsvc-s291.c: Likewise.
 
Co-authored-by: Ju-Zhe Zhong 
---
.../gcc.dg/vect/tsvc/vect-tsvc-s252.c |   2 +-
.../gcc.dg/vect/tsvc/vect-tsvc-s254.c |   2 +-
.../gcc.dg/vect/tsvc/vect-tsvc-s291.c |   2 +-
gcc/testsuite/gcc.dg/vect/vect-recurr-1.c |  38 +++
gcc/testsuite/gcc.dg/vect/vect-recurr-2.c |  39 +++
gcc/testsuite/gcc.dg/vect/vect-recurr-3.c |  39 +++
gcc/testsuite/gcc.dg/vect/vect-recurr-4.c |  42 +++
gcc/testsuite/gcc.dg/vect/vect-recurr-5.c |  43 +++
gcc/testsuite/gcc.dg/vect/vect-recurr-6.c |  39 +++
gcc/tree-vect-loop.cc | 286 --
gcc/tree-vect-slp.cc  |  38 ++-
gcc/tree-vect-stmts.cc|  17 +-
gcc/tree-vectorizer.h |   4 +
13 files changed, 563 insertions(+), 28 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-1.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-2.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-3.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-4.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-5.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-recurr-6.c
 
diff --git a/gcc/testsuite/gcc.dg/vect/tsvc/vect-tsvc-s252.c 
b/gcc/testsuite/gcc.dg/vect/tsvc/vect-tsvc-s252.c
index f1302b60ae5..83eaa7a8ff5 100644
--- 

Re: [PATCH] libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606]

2022-10-10 Thread Jonathan Wakely via Gcc-patches
On Mon, 10 Oct 2022 at 07:18, Richard Biener  wrote:
>
> On Fri, Oct 7, 2022 at 5:55 PM Jonathan Wakely via Gcc-patches
>  wrote:
> >
> > This needs a little more documentation (see the TODO in the manual),
> > rather than just the comments in the source. This isn't final, but I
> > think it's the direction I want to take.
> >
> > -- >8 --
> >
> > Implement a long-standing request to support tuning the size of the
> > emergency buffer for allocating exceptions after malloc fails, or to
> > disable that buffer entirely.
> >
> > It's now possible to disable the dynamic allocation of the buffer and
> > use a fixed-size static buffer, via --enable-libstdcxx-static-eh-pool.
> > This is a built-time choice that is baked into libstdc++ and so affects
> > all code linked against that build of libstdc++.
> >
> > The size of the pool can be set by --with-libstdcxx-eh-pool-obj-count=N
> > which is measured in units of sizeof(void*) not bytes. A given exception
> > type such as std::system_error depends on the target, so giving a size
> > in bytes wouldn't be portable across 16/32/64-bit targets.
> >
> > When libstdc++ is configured to use a dynamic buffer, the size of that
> > buffer can now be tuned at runtime by setting the GLIBCXX_TUNABLES
> > environment variable (c.f. PR libstdc++/88264). The number of exceptions
> > to reserve space for is controlled by the "glibcxx.eh_pool.obj_count"
> > and "glibcxx.eh_pool.obj_size" tunables. The pool will be sized to be
> > able to allocate obj_count exceptions of size obj_size*sizeof(void*) and
> > obj_count "dependent" exceptions rethrown by std::rethrow_exception.
> >
> > With the ability to tune the buffer size, we can reduce the default pool
> > size. Most users never need to throw 1kB exceptions in parallel from
> > hundreds of threads after malloc is OOM.
>
> But does it hurt?  Back in time when I reworked the allocator to be less
> wasteful the whole point was to allow more exceptions to be in-flight
> during OOM shutdown of a process with many threads.

It certainly hurts for small systems, but maybe we can keep the large
allocation for 64-bit targets (currently 73kB) and only reduce it for
32-bit (19kB) and 16-bit (3kB IIRC) targets.

And obviously if the new code to check an env var is backported, the
defaults shouldn't be changed in the release branch. Just enable the
new feature, but leave defaults the same.

N.B. the C++ ABI actually requires that the emergency pool should
block if too many threads try to access it at once. That would mean
the program slows down drastically, but doesn't empty the pool and
terminate if there are many threads all trying to throw on OOM. I'm
not convinced blocking is the right default, but making it an option
seems reasonable (I created PR107180 to track that).


> So if we reduce the default buffer size that should be documented
> in changes.html, maybe with a hint how to restore the old buffer size
> (configury flags required or runtime ENV setting)?

The git commit message gives the env setting to do that, and
acinclude.m4 gives the configure option to do that. I can certainly
add the info to changes.html where it's more likely to be noticed.


>
> Otherwise looks OK to me.

Great, thanks for taking a look.



[committed] libstdc++: std::make_signed_t should be ill-formed

2022-10-10 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux. Pushed to trunk.

-- >8 --

Currently we only reject std::make_signed_t but not cv bool.
Similarly for std::make_unsigned_t.

As well as making those ill-formed, this adds a requires-clause to the
make_signed and make_unsigned primary templates. This makes
non-integral, non-enum cases fail immediately with a clear error, rather
than giving an error about __make_signed_selector being
incomplete.

libstdc++-v3/ChangeLog:

* include/std/type_traits (make_signed, make_unsigned): Add
specializations for cv bool. Add requires-clause for C++20 to
improve diagnostics for non-integral, non-enum cases.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Check cv bool.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
Adjust expected errors for C++20 and later.
* testsuite/lib/prune.exp: Prune "in requirements  [with ...]"
lines from diagnostics.
---
 libstdc++-v3/include/std/type_traits  | 18 ++---
 .../make_signed/requirements/typedefs_neg.cc  | 27 +--
 .../requirements/typedefs_neg.cc  | 25 -
 .../range_access/range_access_cpp20_neg.cc|  3 ++-
 libstdc++-v3/testsuite/lib/prune.exp  |  1 +
 5 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index b74565eb521..6108b98aa6a 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1802,12 +1802,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Primary template.
   /// make_unsigned
   template
+#if __cpp_concepts
+requires is_integral<_Tp>::value || __is_enum(_Tp)
+#endif
 struct make_unsigned
 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
 
   // Integral, but don't define.
-  template<>
-struct make_unsigned;
+  template<> struct make_unsigned;
+  template<> struct make_unsigned;
+  template<> struct make_unsigned;
+  template<> struct make_unsigned;
 
   /// @cond undocumented
 
@@ -1932,12 +1937,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Primary template.
   /// make_signed
   template
+#if __cpp_concepts
+requires is_integral<_Tp>::value || __is_enum(_Tp)
+#endif
 struct make_signed
 { typedef typename __make_signed_selector<_Tp>::__type type; };
 
   // Integral, but don't define.
-  template<>
-struct make_signed;
+  template<> struct make_signed;
+  template<> struct make_signed;
+  template<> struct make_signed;
+  template<> struct make_signed;
 
 #if __cplusplus > 201103L
   /// Alias template for make_signed
diff --git 
a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc 
b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
index 051bb64c710..88b8ae887ef 100644
--- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
@@ -20,31 +20,28 @@
 // .
 
 #include 
-#include 
 
-enum test_enum { first_selection };
+struct pod_class { };
 
 void test01()
 {
   using std::make_signed;
 
   // Negative tests.
-  typedef make_signed::type  test1_type;
+  using T1 = make_signed::type; // { dg-error "incomplete" }
+  using T2 = make_signed::type; // { dg-error "incomplete" }
+  using T3 = make_signed::type; // { dg-error "incomplete" }
+  using T4 = make_signed::type; // { dg-error 
"incomplete" }
 
-  typedef make_signed<__gnu_test::pod_uint>::type  test2_type;
+  using T5 = make_signed::type; // { dg-error "here" }
 
-  typedef make_signed::type test3_type;
+  using T6 = make_signed::type; // { dg-error "here" }
 
-  typedef void (fn_type) ();
-  typedef make_signed::type   test4_type;
+  using fn_type = void ();
+  using T7 = make_signed::type; // { dg-error "here" }
 
-  typedef make_signed::type test5_type;
+  using T8 = make_signed::type; // { dg-error "here" }
 }
 
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 32 }
-// { dg-error "required from here" "" { target *-*-* } 34 }
-// { dg-error "required from here" "" { target *-*-* } 36 }
-// { dg-error "required from here" "" { target *-*-* } 39 }
-// { dg-error "required from here" "" { target *-*-* } 41 }
-
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
+// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 }
+// { dg-error "constraint failure" "" { target c++20 } 0 }
diff --git 
a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc 
b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
index ff98cc42ef7..50f15e7037c 100644
--- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/ty

[COMMITTED] The true side of x != x should set NAN.

2022-10-10 Thread Aldy Hernandez via Gcc-patches
gcc/ChangeLog:

* range-op-float.cc (foperator_not_equal::op1_range): Set NAN on
TRUE side for x != x.
---
 gcc/range-op-float.cc | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 91833d3f855..5ffe38da53a 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -497,14 +497,17 @@ bool
 foperator_not_equal::op1_range (frange &r, tree type,
const irange &lhs,
const frange &op2,
-   relation_kind) const
+   relation_kind rel) const
 {
   switch (get_bool_state (r, lhs, type))
 {
 case BRS_TRUE:
+  // The TRUE side of op1 != op1 implies op1 is NAN.
+  if (rel == VREL_EQ)
+   r.set_nan (type);
   // If the result is true, the only time we know anything is if
   // OP2 is a constant.
-  if (op2.singleton_p ())
+  else if (op2.singleton_p ())
{
  // This is correct even if op1 is NAN, because the following
  // range would be ~[tmp, tmp] with the NAN property set to
-- 
2.37.3



[COMMITTED] Make range-op-float entries public.

2022-10-10 Thread Aldy Hernandez via Gcc-patches
gcc/ChangeLog:

* range-op-float.cc (class foperator_identity): Make members public.
(class foperator_equal): Same.
(class foperator_not_equal): Same.
(class foperator_lt): Same.
(class foperator_le): Same.
(class foperator_gt): Same.
(class foperator_ge): Same.
(class foperator_unordered): Same.
(class foperator_ordered): Same.
---
 gcc/range-op-float.cc | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 5ffe38da53a..3cf117d8931 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -315,7 +315,7 @@ class foperator_identity : public range_operator_float
 {
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
-
+public:
   bool fold_range (frange &r, tree type ATTRIBUTE_UNUSED,
   const frange &op1, const frange &op2 ATTRIBUTE_UNUSED,
   relation_kind) const final override
@@ -338,7 +338,7 @@ class foperator_equal : public range_operator_float
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
-
+public:
   bool fold_range (irange &r, tree type,
   const frange &op1, const frange &op2,
   relation_kind rel) const final override;
@@ -444,7 +444,7 @@ class foperator_not_equal : public range_operator_float
 {
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
-
+public:
   bool fold_range (irange &r, tree type,
   const frange &op1, const frange &op2,
   relation_kind rel) const final override;
@@ -545,7 +545,7 @@ class foperator_lt : public range_operator_float
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
-
+public:
   bool fold_range (irange &r, tree type,
   const frange &op1, const frange &op2,
   relation_kind rel) const final override;
@@ -660,7 +660,7 @@ class foperator_le : public range_operator_float
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
-
+public:
   bool fold_range (irange &r, tree type,
   const frange &op1, const frange &op2,
   relation_kind rel) const final override;
@@ -767,7 +767,7 @@ class foperator_gt : public range_operator_float
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
-
+public:
   bool fold_range (irange &r, tree type,
   const frange &op1, const frange &op2,
   relation_kind rel) const final override;
@@ -882,7 +882,7 @@ class foperator_ge : public range_operator_float
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
-
+public:
   bool fold_range (irange &r, tree type,
   const frange &op1, const frange &op2,
   relation_kind rel) const final override;
@@ -993,7 +993,6 @@ class foperator_unordered : public range_operator_float
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
-
 public:
   bool fold_range (irange &r, tree type,
   const frange &op1, const frange &op2,
@@ -1071,7 +1070,6 @@ class foperator_ordered : public range_operator_float
   using range_operator_float::fold_range;
   using range_operator_float::op1_range;
   using range_operator_float::op2_range;
-
 public:
   bool fold_range (irange &r, tree type,
   const frange &op1, const frange &op2,
-- 
2.37.3



[COMMITTED] x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side).

2022-10-10 Thread Aldy Hernandez via Gcc-patches
gcc/ChangeLog:

* range-op-float.cc (foperator_unordered::op1_range): Set NAN when
operands are equal and result is TRUE.
---
 gcc/range-op-float.cc | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 68578aa6fe7..91833d3f855 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -1026,23 +1026,27 @@ bool
 foperator_unordered::op1_range (frange &r, tree type,
const irange &lhs,
const frange &op2,
-   relation_kind) const
+   relation_kind rel) const
 {
   switch (get_bool_state (r, lhs, type))
 {
 case BRS_TRUE:
+  if (rel == VREL_EQ)
+   r.set_nan (type);
   // Since at least one operand must be NAN, if one of them is
   // not, the other must be.
-  if (!op2.maybe_isnan ())
+  else if (!op2.maybe_isnan ())
r.set_nan (type);
   else
r.set_varying (type);
   break;
 
 case BRS_FALSE:
+  if (rel == VREL_EQ)
+   r.clear_nan ();
   // A false UNORDERED means both operands are !NAN, so it's
   // impossible for op2 to be a NAN.
-  if (op2.known_isnan ())
+  else if (op2.known_isnan ())
r.set_undefined ();
   else
{
-- 
2.37.3



[COMMITTED] Add frange::maybe_isnan (bool sign).

2022-10-10 Thread Aldy Hernandez via Gcc-patches
It is useful to know if there's the possiblity of a NAN with a given
sign.  This is to complement maybe_isnan(void) which returns TRUE for a
NAN of any sign.

A follow-up patch implementing ABS will make use of this.

gcc/ChangeLog:

* value-range.h (frange::maybe_isnan): New.
---
 gcc/value-range.h | 13 +
 1 file changed, 13 insertions(+)

diff --git a/gcc/value-range.h b/gcc/value-range.h
index 484f911bd90..07a2067898c 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -323,6 +323,7 @@ public:
   bool known_isnan () const;
   bool known_isinf () const;
   bool maybe_isnan () const;
+  bool maybe_isnan (bool sign) const;
   bool maybe_isinf () const;
   bool signbit_p (bool &signbit) const;
 private:
@@ -1295,6 +1296,18 @@ frange::maybe_isnan () const
   return m_pos_nan || m_neg_nan;
 }
 
+// Return TRUE if range is possibly a NAN with SIGN.
+
+inline bool
+frange::maybe_isnan (bool sign) const
+{
+  if (undefined_p ())
+return false;
+  if (sign)
+return m_neg_nan;
+  return m_pos_nan;
+}
+
 // Return TRUE if range is a +NAN or -NAN.
 
 inline bool
-- 
2.37.3



[COMMITTED] Return non-legacy ranges in range.h.

2022-10-10 Thread Aldy Hernandez via Gcc-patches
int_range<1> is a legacy range (think anti ranges, legacy VRP, etc).
There is a penalty for converting anything built with <1> to
non-legacy.  Since most of the uses of these functions are now ranger,
we can save a miniscule amount of time by converting them to
non-legacy.

gcc/ChangeLog:

* range.h (range_true): Return int_range<2>.
(range_false): Same.
(range_true_and_false): Same.
---
 gcc/range.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/range.h b/gcc/range.h
index 5c70c66566c..8138d6f5515 100644
--- a/gcc/range.h
+++ b/gcc/range.h
@@ -32,7 +32,7 @@ static inline int_range<1>
 range_true (tree type)
 {
   unsigned prec = TYPE_PRECISION (type);
-  return int_range<1> (type, wi::one (prec), wi::one (prec));
+  return int_range<2> (type, wi::one (prec), wi::one (prec));
 }
 
 // Return an irange instance that is a boolean FALSE.
@@ -41,7 +41,7 @@ static inline int_range<1>
 range_false (tree type)
 {
   unsigned prec = TYPE_PRECISION (type);
-  return int_range<1> (type, wi::zero (prec), wi::zero (prec));
+  return int_range<2> (type, wi::zero (prec), wi::zero (prec));
 }
 
 // Return an irange that covers both true and false.
@@ -50,7 +50,7 @@ static inline int_range<1>
 range_true_and_false (tree type)
 {
   unsigned prec = TYPE_PRECISION (type);
-  return int_range<1> (type, wi::zero (prec), wi::one (prec));
+  return int_range<2> (type, wi::zero (prec), wi::one (prec));
 }
 
 #endif // GCC_RANGE_H
-- 
2.37.3



Re: [committed] libstdc++: std::make_signed_t should be ill-formed

2022-10-10 Thread Patrick Palka via Gcc-patches
On Mon, 10 Oct 2022, Jonathan Wakely via Libstdc++ wrote:

> Tested powerpc64le-linux. Pushed to trunk.
> 
> -- >8 --
> 
> Currently we only reject std::make_signed_t but not cv bool.
> Similarly for std::make_unsigned_t.
> 
> As well as making those ill-formed, this adds a requires-clause to the
> make_signed and make_unsigned primary templates. This makes
> non-integral, non-enum cases fail immediately with a clear error, rather
> than giving an error about __make_signed_selector being
> incomplete.

IIUC the requires-clause turns what was once a hard error into a SFINAE
error, so e.g. for

  template typename make_signed::type f(int);
  template void f(...);
  int main() { f(0); }

the call to f would previously be rejected due to an error outside the
immediate context about incomplete __make_signed_selector, and now with
the requires-clause resolves to the second overload.  I wonder if this
new behavior is conforming -- the examples in [structure.specifications]
of how to implement 'Mandates' suggest that a failed 'Mandates' should
yield a hard error?

> 
> libstdc++-v3/ChangeLog:
> 
>   * include/std/type_traits (make_signed, make_unsigned): Add
>   specializations for cv bool. Add requires-clause for C++20 to
>   improve diagnostics for non-integral, non-enum cases.
>   * testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
>   Check cv bool.
>   * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
>   Likewise.
>   * testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
>   Adjust expected errors for C++20 and later.
>   * testsuite/lib/prune.exp: Prune "in requirements  [with ...]"
>   lines from diagnostics.
> ---
>  libstdc++-v3/include/std/type_traits  | 18 ++---
>  .../make_signed/requirements/typedefs_neg.cc  | 27 +--
>  .../requirements/typedefs_neg.cc  | 25 -
>  .../range_access/range_access_cpp20_neg.cc|  3 ++-
>  libstdc++-v3/testsuite/lib/prune.exp  |  1 +
>  5 files changed, 40 insertions(+), 34 deletions(-)
> 
> diff --git a/libstdc++-v3/include/std/type_traits 
> b/libstdc++-v3/include/std/type_traits
> index b74565eb521..6108b98aa6a 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -1802,12 +1802,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>// Primary template.
>/// make_unsigned
>template
> +#if __cpp_concepts
> +requires is_integral<_Tp>::value || __is_enum(_Tp)
> +#endif
>  struct make_unsigned
>  { typedef typename __make_unsigned_selector<_Tp>::__type type; };
>  
>// Integral, but don't define.
> -  template<>
> -struct make_unsigned;
> +  template<> struct make_unsigned;
> +  template<> struct make_unsigned;
> +  template<> struct make_unsigned;
> +  template<> struct make_unsigned;
>  
>/// @cond undocumented
>  
> @@ -1932,12 +1937,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>// Primary template.
>/// make_signed
>template
> +#if __cpp_concepts
> +requires is_integral<_Tp>::value || __is_enum(_Tp)
> +#endif
>  struct make_signed
>  { typedef typename __make_signed_selector<_Tp>::__type type; };
>  
>// Integral, but don't define.
> -  template<>
> -struct make_signed;
> +  template<> struct make_signed;
> +  template<> struct make_signed;
> +  template<> struct make_signed;
> +  template<> struct make_signed;
>  
>  #if __cplusplus > 201103L
>/// Alias template for make_signed
> diff --git 
> a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc 
> b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
> index 051bb64c710..88b8ae887ef 100644
> --- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
> +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
> @@ -20,31 +20,28 @@
>  // .
>  
>  #include 
> -#include 
>  
> -enum test_enum { first_selection };
> +struct pod_class { };
>  
>  void test01()
>  {
>using std::make_signed;
>  
>// Negative tests.
> -  typedef make_signed::typetest1_type;
> +  using T1 = make_signed::type; // { dg-error "incomplete" }
> +  using T2 = make_signed::type; // { dg-error "incomplete" }
> +  using T3 = make_signed::type; // { dg-error "incomplete" }
> +  using T4 = make_signed::type; // { dg-error 
> "incomplete" }
>  
> -  typedef make_signed<__gnu_test::pod_uint>::typetest2_type;
> +  using T5 = make_signed::type; // { dg-error "here" }
>  
> -  typedef make_signed::type test3_type;
> +  using T6 = make_signed::type; // { dg-error "here" }
>  
> -  typedef void (fn_type) ();
> -  typedef make_signed::type test4_type;
> +  using fn_type = void ();
> +  using T7 = make_signed::type; // { dg-error "here" }
>  
> -  typedef make_signed::type   test5_type;
> +  using T8 = make_signed::type; // { dg-error "here" }
>  }
>  
> -// { dg-error

[committed] RISC-V: Add newline to the end of file [NFC]

2022-10-10 Thread Kito Cheng
gcc/ChangeLog:

* config/riscv/riscv-c.cc: Add newline to the end of file.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pragma-1.c: Add newline to the end of file.
* gcc.target/riscv/rvv/base/pragma-2.c: Ditto.
* gcc.target/riscv/rvv/base/pragma-3.c: Ditto.
* gcc.target/riscv/rvv/base/user-1.c: Ditto.
* gcc.target/riscv/rvv/base/user-2.c: Ditto.
* gcc.target/riscv/rvv/base/user-3.c: Ditto.
* gcc.target/riscv/rvv/base/user-4.c: Ditto.
* gcc.target/riscv/rvv/base/user-5.c: Ditto.
* gcc.target/riscv/rvv/base/user-6.c: Ditto.
* gcc.target/riscv/rvv/base/vread_csr.c: Ditto.
* gcc.target/riscv/rvv/base/vwrite_csr.c: Ditto.
---
 gcc/config/riscv/riscv-c.cc  | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/pragma-1.c   | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/pragma-2.c   | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/pragma-3.c   | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/user-2.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/user-3.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/user-4.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/user-5.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/user-6.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/vread_csr.c  | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/vwrite_csr.c | 2 +-
 12 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/config/riscv/riscv-c.cc b/gcc/config/riscv/riscv-c.cc
index cac0043d680..78f6eacb068 100644
--- a/gcc/config/riscv/riscv-c.cc
+++ b/gcc/config/riscv/riscv-c.cc
@@ -190,4 +190,4 @@ void
 riscv_register_pragmas (void)
 {
   c_register_pragma ("riscv", "intrinsic", riscv_pragma_intrinsic);
-}
\ No newline at end of file
+}
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-1.c
index 79b1159d9e7..3d81b179235 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-1.c
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-options "-O3 -march=rv32gc -mabi=ilp32d" } */
 
-#pragma riscv intrinsic "vector" /* { dg-error {#pragma riscv intrinsic' 
option 'vector' needs 'V' extension enabled} } */
\ No newline at end of file
+#pragma riscv intrinsic "vector" /* { dg-error {#pragma riscv intrinsic' 
option 'vector' needs 'V' extension enabled} } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-2.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-2.c
index fa790b1f4e6..fd2aa3066cd 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-2.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-2.c
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-skip-if "test rvv intrinsic" { *-*-* } { "*" } { "-march=rv*v*" } } */
 
-#pragma riscv intrinsic "vector"
\ No newline at end of file
+#pragma riscv intrinsic "vector"
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-3.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-3.c
index 86da678adfa..96a0e051a29 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-3.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pragma-3.c
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-skip-if "test rvv intrinsic" { *-*-* } { "*" } { "-march=rv*v*" } } */
 
-#pragma riscv intrinsic "report-error" /* { dg-error {unknown '#pragma riscv 
intrinsic' option 'report-error'} } */
\ No newline at end of file
+#pragma riscv intrinsic "report-error" /* { dg-error {unknown '#pragma riscv 
intrinsic' option 'report-error'} } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
index 299e3934a57..fa1f0f3d4d2 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
@@ -62,4 +62,4 @@ void foo61 () {vfloat32m8_t t;}
 void foo62 () {vfloat64m1_t t;}
 void foo63 () {vfloat64m2_t t;}
 void foo64 () {vfloat64m4_t t;}
-void foo65 () {vfloat64m8_t t;}
\ No newline at end of file
+void foo65 () {vfloat64m8_t t;}
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/user-2.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/user-2.c
index 2a88467d218..92f4ee02d20 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/user-2.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/user-2.c
@@ -62,4 +62,4 @@ void foo61 () {vfloat32m8_t t;} /* { dg-error {unknown type 
name 'vfloat32m8_t'}
 void foo62 () {vfloat64m1_t t;} /* { dg-error {unknown type name 
'vfloat64m1_t'} } */
 void foo63 () {vfloat64m2_t t;} /* { dg-error {unknown type name 
'vfloat64m2_t'} } */
 void foo64 () {vfloat64m4_t t;} /* { dg-error {unknown type name 
'vfloat64m4_t'} } */
-void foo65 () {vfloat64m8_t t;} /* { dg-error {unknown type name 
'vfloat64m8_t'} } */
\ No newline at end of file
+void foo65 () {vfloat64m8_t t;} /* { dg-error {unknown type name 
'vfloat64m8_t'} } */
diff --git a

[committed] RISC-V: Adjust testcase for rvv/base/user-1.c

2022-10-10 Thread Kito Cheng
The -march option check isn't precise enough, -march=rv*v* also mach any
zve extensions.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/user-1.c: Add dg-options and drop
dg-skip-if.

Reported-by: Christoph Müllner 
Tested-by: Christoph Müllner 
Reviewed-by: Ju-Zhe Zhong 
---
 gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
index fa1f0f3d4d2..00fb73f220f 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-skip-if "test rvv intrinsic" { *-*-* } { "*" } { "-march=rv*v*" } } */
+/* { dg-options "-O3 -march=rv32gcv -mabi=ilp32d" } */
 
 #include "riscv_vector.h"
 
-- 
2.37.2



[committed] RISC-V: Add riscv_vector.h wrapper in testsuite to prevent pull in stdint.h from C library

2022-10-10 Thread Kito Cheng
For RISC-V linux/glibc toolchain will got header file not found when including
stdint.h if multilib is not enabled, it because some header file will
try to include gnu/stubs-.h from the system, however it only
generated when multilib enabled.

In order to prevent that, we introduce a wrapper for riscv_vector.h,
include stdint-gcc.h rather than the default stdint.h.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/riscv_vector.h: New.

Reported-by: Christoph Müllner 
Tested-by: Christoph Müllner 
Reviewed-by: Ju-Zhe Zhong 
---
 .../gcc.target/riscv/rvv/base/riscv_vector.h  | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/riscv_vector.h

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/riscv_vector.h 
b/gcc/testsuite/gcc.target/riscv/rvv/base/riscv_vector.h
new file mode 100644
index 000..fbb4858fc86
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/riscv_vector.h
@@ -0,0 +1,11 @@
+/* Wrapper of riscv_vector.h, prevent riscv_vector.h including stdint.h from
+   C library, that might cause problem on testing RV32 related testcase when
+   we disable multilib.  */
+#ifndef _RISCV_VECTOR_WRAP_H
+
+#define _GCC_WRAP_STDINT_H
+#include "stdint-gcc.h"
+#include_next 
+#define _RISCV_VECTOR_WRAP_H
+
+#endif
-- 
2.37.2



Re: [PATCH] Don't ICE running selftests if errors were raised [PR99723]

2022-10-10 Thread Andrea Corallo via Gcc-patches
Jeff Law via Gcc-patches  writes:

> On 9/27/22 09:12, Andrea Corallo via Gcc-patches wrote:
>> Hi all
>>
>> this is to address PR 99723.
>>
>> In the PR GCC crashes as the initialization of common trees is not
>> performed as no compilation is happening, this is because we raise an
>> error earlier while processing the arch flags.
>>
>> This patch changes the code to execute selftests only if no errors
>> where raised before.
>>
>> Bootstrapped on aarch64, okay for trunk?
>>
>> Best Regards
>>
>>Andrea
>>
>> 2022-09-27  Andrea Corallo  
>>
>>  * toplev.cc (toplev::main): Don't run self tests in case of
>>  previous error.
>
> OK

Into trunk as 248c8aeebc4.

Thanks

  Andrea


Re: [committed] RISC-V: Adjust testcase for rvv/base/user-1.c

2022-10-10 Thread 钟居哲
LGTM.



juzhe.zh...@rivai.ai
 
From: Kito Cheng
Date: 2022-10-10 21:14
To: gcc-patches; kito.cheng; christoph.muellner; juzhe.zhong
CC: Kito Cheng
Subject: [committed] RISC-V: Adjust testcase for rvv/base/user-1.c
The -march option check isn't precise enough, -march=rv*v* also mach any
zve extensions.
 
gcc/testsuite/ChangeLog:
 
* gcc.target/riscv/rvv/base/user-1.c: Add dg-options and drop
dg-skip-if.
 
Reported-by: Christoph Müllner 
Tested-by: Christoph Müllner 
Reviewed-by: Ju-Zhe Zhong 
---
gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
 
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
index fa1f0f3d4d2..00fb73f220f 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/user-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-skip-if "test rvv intrinsic" { *-*-* } { "*" } { "-march=rv*v*" } } */
+/* { dg-options "-O3 -march=rv32gcv -mabi=ilp32d" } */
#include "riscv_vector.h"
-- 
2.37.2
 
 


Re: [committed] RISC-V: Add riscv_vector.h wrapper in testsuite to prevent pull in stdint.h from C library

2022-10-10 Thread 钟居哲
LGTM.



juzhe.zh...@rivai.ai
 
From: Kito Cheng
Date: 2022-10-10 21:14
To: gcc-patches; kito.cheng; christoph.muellner; juzhe.zhong
CC: Kito Cheng
Subject: [committed] RISC-V: Add riscv_vector.h wrapper in testsuite to prevent 
pull in stdint.h from C library
For RISC-V linux/glibc toolchain will got header file not found when including
stdint.h if multilib is not enabled, it because some header file will
try to include gnu/stubs-.h from the system, however it only
generated when multilib enabled.
 
In order to prevent that, we introduce a wrapper for riscv_vector.h,
include stdint-gcc.h rather than the default stdint.h.
 
gcc/testsuite/ChangeLog:
 
* gcc.target/riscv/rvv/base/riscv_vector.h: New.
 
Reported-by: Christoph Müllner 
Tested-by: Christoph Müllner 
Reviewed-by: Ju-Zhe Zhong 
---
.../gcc.target/riscv/rvv/base/riscv_vector.h  | 11 +++
1 file changed, 11 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/riscv_vector.h
 
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/riscv_vector.h 
b/gcc/testsuite/gcc.target/riscv/rvv/base/riscv_vector.h
new file mode 100644
index 000..fbb4858fc86
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/riscv_vector.h
@@ -0,0 +1,11 @@
+/* Wrapper of riscv_vector.h, prevent riscv_vector.h including stdint.h from
+   C library, that might cause problem on testing RV32 related testcase when
+   we disable multilib.  */
+#ifndef _RISCV_VECTOR_WRAP_H
+
+#define _GCC_WRAP_STDINT_H
+#include "stdint-gcc.h"
+#include_next 
+#define _RISCV_VECTOR_WRAP_H
+
+#endif
-- 
2.37.2
 
 


[PATCH] RISC-V: Add missing vsetvl instruction type.

2022-10-10 Thread juzhe . zhong
From: Ju-Zhe Zhong 

When implementing built-in framework, I notice I missed
vsetvl instruction type, so add it in a single patch
preparing for the following patches.

gcc/ChangeLog:

* config/riscv/riscv.md: Add vsetvl instruction type.

---
 gcc/config/riscv/riscv.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 014206fb8bd..2d1cda2b98f 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -229,6 +229,7 @@
 ;; Classification of RVV instructions which will be added to each RVV .md 
pattern and used by scheduler.
 ;; rdvlenb vector byte length vlenb csrr read
 ;; rdvlvector length vl csrr read
+;; vsetvl  vector configuration-setting instrucions
 ;; 7. Vector Loads and Stores
 ;; vldevector unit-stride load instructions
 ;; vstevector unit-stride store instructions
@@ -316,7 +317,7 @@
   "unknown,branch,jump,call,load,fpload,store,fpstore,
mtc,mfc,const,arith,logical,shift,slt,imul,idiv,move,fmove,fadd,fmul,
fmadd,fdiv,fcmp,fcvt,fsqrt,multi,auipc,sfb_alu,nop,ghost,bitmanip,rotate,
-   rdvlenb,rdvl,vlde,vste,vldm,vstm,vlds,vsts,
+   rdvlenb,rdvl,vsetvl,vlde,vste,vldm,vstm,vlds,vsts,
vldux,vldox,vstux,vstox,vldff,vldr,vstr,
vialu,viwalu,vext,vicalu,vshift,vnshift,vicmp,
vimul,vidiv,viwmul,vimuladd,viwmuladd,vimerge,vimov,
-- 
2.36.1



[PATCH] RISC-V: move struct vector_type_info from *.h to *.cc.

2022-10-10 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (struct vector_type_info): Move 
from riscv-vector-builtins.h.
* config/riscv/riscv-vector-builtins.h (struct vector_type_info): Move 
to riscv-vector-builtins.cc.

---
 gcc/config/riscv/riscv-vector-builtins.cc | 16 
 gcc/config/riscv/riscv-vector-builtins.h  | 16 
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 0096e32f5e4..d7b567a7ba1 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -50,6 +50,22 @@ using namespace riscv_vector;
 
 namespace riscv_vector {
 
+/* Static information about each vector type.  */
+struct vector_type_info
+{
+  /* The name of the type as declared by riscv_vector.h
+ which is recommend to use. For example: 'vint32m1_t'.  */
+  const char *name;
+
+  /* ABI name of vector type. The type is always available
+ under this name, even when riscv_vector.h isn't included.
+ For example:  '__rvv_int32m1_t'.  */
+  const char *abi_name;
+
+  /* The C++ mangling of ABI_NAME.  */
+  const char *mangled_name;
+};
+
 /* Information about each RVV type.  */
 static CONSTEXPR const vector_type_info vector_types[] = {
 #define DEF_RVV_TYPE(USER_NAME, NCHARS, ABI_NAME, ARGS...)\
diff --git a/gcc/config/riscv/riscv-vector-builtins.h 
b/gcc/config/riscv/riscv-vector-builtins.h
index 6ca0b073964..524fb0b02c2 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -26,22 +26,6 @@ namespace riscv_vector {
 /* This is for segment instructions.  */
 const unsigned int MAX_TUPLE_SIZE = 8;
 
-/* Static information about each vector type.  */
-struct vector_type_info
-{
-  /* The name of the type as declared by riscv_vector.h
- which is recommend to use. For example: 'vint32m1_t'.  */
-  const char *user_name;
-
-  /* ABI name of vector type. The type is always available
- under this name, even when riscv_vector.h isn't included.
- For example:  '__rvv_int32m1_t'.  */
-  const char *abi_name;
-
-  /* The C++ mangling of ABI_NAME.  */
-  const char *mangled_name;
-};
-
 /* Enumerates the RVV types, together called
"vector types" for brevity.  */
 enum vector_type_index
-- 
2.36.1



Re: [committed] libstdc++: std::make_signed_t should be ill-formed

2022-10-10 Thread Tim Song via Gcc-patches
On Mon, Oct 10, 2022 at 8:09 AM Patrick Palka via Libstdc++
 wrote:
>
> On Mon, 10 Oct 2022, Jonathan Wakely via Libstdc++ wrote:
>
> > Tested powerpc64le-linux. Pushed to trunk.
> >
> > -- >8 --
> >
> > Currently we only reject std::make_signed_t but not cv bool.
> > Similarly for std::make_unsigned_t.
> >
> > As well as making those ill-formed, this adds a requires-clause to the
> > make_signed and make_unsigned primary templates. This makes
> > non-integral, non-enum cases fail immediately with a clear error, rather
> > than giving an error about __make_signed_selector being
> > incomplete.
>
> IIUC the requires-clause turns what was once a hard error into a SFINAE
> error, so e.g. for
>
>   template typename make_signed::type f(int);
>   template void f(...);
>   int main() { f(0); }
>
> the call to f would previously be rejected due to an error outside the
> immediate context about incomplete __make_signed_selector, and now with
> the requires-clause resolves to the second overload.  I wonder if this
> new behavior is conforming -- the examples in [structure.specifications]
> of how to implement 'Mandates' suggest that a failed 'Mandates' should
> yield a hard error?

I'm also concerned about the inability to name make_signed in a
context that doesn't require its instantiation (e.g.,
conditional_t, make_signed,
type_identity>::type). That seems a plausible use case, and
breaking it doesn't seem great to me (conformance aside).


Re: [PATCH][RFT] Vectorization of first-order recurrences

2022-10-10 Thread Andrew Stubbs

On 10/10/2022 12:03, Richard Biener wrote:

The following picks up the prototype by Ju-Zhe Zhong for vectorizing
first order recurrences.  That solves two TSVC missed optimization PRs.

There's a new scalar cycle def kind, vect_first_order_recurrence
and it's handling of the backedge value vectorization is complicated
by the fact that the vectorized value isn't the PHI but instead
a (series of) permute(s) shifting in the recurring value from the
previous iteration.  I've implemented this by creating both the
single vectorized PHI and the series of permutes when vectorizing
the scalar PHI but leave the backedge values in both unassigned.
The backedge values are (for the testcases) computed by a load
which is also the place after which the permutes are inserted.
That placement also restricts the cases we can handle (without
resorting to code motion).

I added both costing and SLP handling though SLP handling is
restricted to the case where a single vectorized PHI is enough.

Missing is epilogue handling - while prologue peeling would
be handled transparently by adjusting iv_phi_p the epilogue
case doesn't work with just inserting a scalar LC PHI since
that a) keeps the scalar load live and b) that loads is the
wrong one, it has to be the last, much like when we'd vectorize
the LC PHI as live operation.  Unfortunately LIVE
compute/analysis happens too early before we decide on
peeling.  When using fully masked loop vectorization the
vect-recurr-6.c works as expected though.

I have tested this on x86_64 for now, but since epilogue
handling is missing there's probably no practical cases.
My prototype WHILE_ULT AVX512 patch can handle vect-recurr-6.c
just fine but I didn't feel like running SPEC within SDE nor
is the WHILE_ULT patch complete enough.  Builds of SPEC 2k7
with fully masked loops succeed (minus three cases of
PR107096, caused by my WHILE_ULT prototype).

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

Testing with SVE, GCN or RVV appreciated, ideas how to cleanly
handle epilogues welcome.


The testcases all produce correct code on GCN and pass the execution tests.

The code isn't terribly optimal because we don't have a two-input 
permutation instruction, so we permute each half separately and 
vec_merge the results. In this case the first vector is always a no-op 
permutation so that's wasted cycles. We'd really want a vector rotate 
and write-lane (or the other way around). I think the special-case 
permutations can be recognised and coded into the backend, but I don't 
know if we can easily tell that the first vector is just a bunch of 
duplicates, when it's not constant.


Andrew


[PATCH] RISC-V: move struct vector_type_info from *.h to *.cc and change "user_name" into "name".

2022-10-10 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (struct vector_type_info): Move 
from config/riscv/riscv-vector-builtins.h.
(DEF_RVV_TYPE): Change USER_NAME to NAME.
(register_vector_type): Change user_name to name.
* config/riscv/riscv-vector-builtins.def (DEF_RVV_TYPE): Change 
USER_NAME to NAME.
* config/riscv/riscv-vector-builtins.h (struct vector_type_info): Move 
to riscv-vector-builtins.cc.
(DEF_RVV_TYPE): Change USER_NAME to NAME.

---
 gcc/config/riscv/riscv-vector-builtins.cc  | 28 +-
 gcc/config/riscv/riscv-vector-builtins.def |  2 +-
 gcc/config/riscv/riscv-vector-builtins.h   | 20 ++--
 3 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 0096e32f5e4..7033b1fc176 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -50,10 +50,26 @@ using namespace riscv_vector;
 
 namespace riscv_vector {
 
+/* Static information about each vector type.  */
+struct vector_type_info
+{
+  /* The name of the type as declared by riscv_vector.h
+ which is recommend to use. For example: 'vint32m1_t'.  */
+  const char *name;
+
+  /* ABI name of vector type. The type is always available
+ under this name, even when riscv_vector.h isn't included.
+ For example:  '__rvv_int32m1_t'.  */
+  const char *abi_name;
+
+  /* The C++ mangling of ABI_NAME.  */
+  const char *mangled_name;
+};
+
 /* Information about each RVV type.  */
 static CONSTEXPR const vector_type_info vector_types[] = {
-#define DEF_RVV_TYPE(USER_NAME, NCHARS, ABI_NAME, ARGS...)\
-  {#USER_NAME, #ABI_NAME, "u" #NCHARS #ABI_NAME},
+#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, ARGS...)\
+  {#NAME, #ABI_NAME, "u" #NCHARS #ABI_NAME},
 #include "riscv-vector-builtins.def"
 };
 
@@ -151,14 +167,14 @@ register_builtin_types ()
 = TARGET_64BIT ? unsigned_intSI_type_node : long_unsigned_type_node;
 
   machine_mode mode;
-#define DEF_RVV_TYPE(USER_NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,
\
+#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,\
 VECTOR_MODE_MIN_VLEN_32)  \
   mode = TARGET_MIN_VLEN > 32 ? VECTOR_MODE##mode  
\
  : VECTOR_MODE_MIN_VLEN_32##mode; \
-  scalar_types[VECTOR_TYPE_##USER_NAME]
\
+  scalar_types[VECTOR_TYPE_##NAME]\
 = riscv_v_ext_enabled_vector_mode_p (mode) ? SCALAR_TYPE##_type_node   
\
   : NULL_TREE;\
-  vector_modes[VECTOR_TYPE_##USER_NAME]
\
+  vector_modes[VECTOR_TYPE_##NAME]\
 = riscv_v_ext_enabled_vector_mode_p (mode) ? mode : VOIDmode;
 #include "riscv-vector-builtins.def"
 
@@ -198,7 +214,7 @@ register_vector_type (vector_type_index type)
  is disabled according to '-march'.  */
   if (!vectype)
 return;
-  tree id = get_identifier (vector_types[type].user_name);
+  tree id = get_identifier (vector_types[type].name);
   tree decl = build_decl (input_location, TYPE_DECL, id, vectype);
   decl = lang_hooks.decls.pushdecl (decl);
 
diff --git a/gcc/config/riscv/riscv-vector-builtins.def 
b/gcc/config/riscv/riscv-vector-builtins.def
index a9001b3b496..664734b881b 100644
--- a/gcc/config/riscv/riscv-vector-builtins.def
+++ b/gcc/config/riscv/riscv-vector-builtins.def
@@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.  If not see
  TARGET_MIN_VLEN > 32. Otherwise the machine mode is VNx1SImode.  */
 
 #ifndef DEF_RVV_TYPE
-#define DEF_RVV_TYPE(USER_NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,
\
+#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,\
 VECTOR_MODE_MIN_VLEN_32)
 #endif
 
diff --git a/gcc/config/riscv/riscv-vector-builtins.h 
b/gcc/config/riscv/riscv-vector-builtins.h
index 6ca0b073964..ec85e0b1320 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -26,28 +26,12 @@ namespace riscv_vector {
 /* This is for segment instructions.  */
 const unsigned int MAX_TUPLE_SIZE = 8;
 
-/* Static information about each vector type.  */
-struct vector_type_info
-{
-  /* The name of the type as declared by riscv_vector.h
- which is recommend to use. For example: 'vint32m1_t'.  */
-  const char *user_name;
-
-  /* ABI name of vector type. The type is always available
- under this name, even when riscv_vector.h isn't included.
- For example:  '__rvv_int32m1_t'.  */
-  const char *abi_name;
-
-  /* The C++ mangling of ABI_NAME.  */
-  const char *mangled_name;
-};
-
 /* Enumerates the RVV types, together called
"vector types" for 

Re: [PATCH] rs6000: Rework option -mpowerpc64 handling [PR106680]

2022-10-10 Thread Segher Boessenkool
On Mon, Oct 10, 2022 at 10:15:58AM +0800, Kewen.Lin wrote:
> on 2022/10/4 05:15, Segher Boessenkool wrote:
> > Right.  If If mpowerpc64 is enabled while OS_MISSING_POWERPC64, warn for
> > that; 
> 
> Currently if option powerpc64 is enabled explicitly while 
> OS_MISSING_POWERPC64,
> there is no warning.  One typical case is -m32 compilation on ppc64.  I made
> a patch to warn for this case as you suggested (btw, this change can be taken
> separately from this rework), it caused some test cases to fail as below:

"Explicitly" means the user says "-m32 -mpowerpc64".

I wonder what "on powerpc64" means in what you say, and why that would
matter?

> gcc.dg/vect/vect-82_64.c
> gcc.dg/vect/vect-83_64.c
> gcc.target/powerpc/bswap64-4.c
> gcc.target/powerpc/ppc64-double-1.c
> gcc.target/powerpc/pr106680-4.c 
> gcc.target/powerpc/rs6000-fpint-2.c
> 
> It's fine to fix them with one additional option "-w" to disable the warning.
> But IIUC one concern is that if we want to test with 
> "--target_board=unix'{-m32,
> -m32/-mpowerpc64}'", the latter combination will always have this warning,
> with one extra "-w" (that is -m32/-mpowerpc64/-w) can make some cases which
> aim to check warning msg ineffective.  So maybe we want to re-consider it
> (like just leaving it as before)?

There will always be false positives (and negatives!) if you put any
warning options in RUNTESTFLAGS.  -w is merely louder than most :-)

But leave this as further improvement.  Maybe put in a comment.

> > and if mpowerpc64 was only implicit, disable it as well (and say
> > we did!)
> 
> But on ppc64 linux, for -m32 compilation mpowerpc64 is implicitly enabled
> since it's with bi-arch supported, I made a patch to disable it as well as
> warn it, it can't be bootstrapped since it warned for -m32 build (-Werror)
> and failed.  So I refined it to something like:
> 
> +  /* With RS6000_BI_ARCH defined (bi-architecture (32/64) supported),
> + TARGET_DEFAULT has bit MASK_POWERPC64 on by default, to keep the
> + behavior consistent (like: no warnings for -m32 on ppc64), we
> + just sliently disable it.  Otherwise, disable it and warn.  */
> +  rs6000_isa_flags &= ~OPTION_MASK_POWERPC64;
> +#ifndef RS6000_BI_ARCH
> +  warning (0, "powerpc64 is unexpected to be enabled on the "
> +  "current OS");
> +#endif

It has nothing to do with biarch.  Let's just not warn if it is so much
work to do it correctly.  We never did before, and no one complained,
how bad can it be :-)


Segher


Re: [PATCH] RISC-V: move struct vector_type_info from *.h to *.cc.

2022-10-10 Thread 钟居哲
Ignore this patch plz. It's not finished.
The correct && full patch is this:
https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603148.html 
Thanks.



juzhe.zh...@rivai.ai
 
From: juzhe.zhong
Date: 2022-10-10 21:49
To: gcc-patches
CC: kito.cheng; Ju-Zhe Zhong
Subject: [PATCH] RISC-V: move struct vector_type_info from *.h to *.cc.
From: Ju-Zhe Zhong 
 
gcc/ChangeLog:
 
* config/riscv/riscv-vector-builtins.cc (struct vector_type_info): Move 
from riscv-vector-builtins.h.
* config/riscv/riscv-vector-builtins.h (struct vector_type_info): Move 
to riscv-vector-builtins.cc.
 
---
gcc/config/riscv/riscv-vector-builtins.cc | 16 
gcc/config/riscv/riscv-vector-builtins.h  | 16 
2 files changed, 16 insertions(+), 16 deletions(-)
 
diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 0096e32f5e4..d7b567a7ba1 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -50,6 +50,22 @@ using namespace riscv_vector;
namespace riscv_vector {
+/* Static information about each vector type.  */
+struct vector_type_info
+{
+  /* The name of the type as declared by riscv_vector.h
+ which is recommend to use. For example: 'vint32m1_t'.  */
+  const char *name;
+
+  /* ABI name of vector type. The type is always available
+ under this name, even when riscv_vector.h isn't included.
+ For example:  '__rvv_int32m1_t'.  */
+  const char *abi_name;
+
+  /* The C++ mangling of ABI_NAME.  */
+  const char *mangled_name;
+};
+
/* Information about each RVV type.  */
static CONSTEXPR const vector_type_info vector_types[] = {
#define DEF_RVV_TYPE(USER_NAME, NCHARS, ABI_NAME, ARGS...)\
diff --git a/gcc/config/riscv/riscv-vector-builtins.h 
b/gcc/config/riscv/riscv-vector-builtins.h
index 6ca0b073964..524fb0b02c2 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -26,22 +26,6 @@ namespace riscv_vector {
/* This is for segment instructions.  */
const unsigned int MAX_TUPLE_SIZE = 8;
-/* Static information about each vector type.  */
-struct vector_type_info
-{
-  /* The name of the type as declared by riscv_vector.h
- which is recommend to use. For example: 'vint32m1_t'.  */
-  const char *user_name;
-
-  /* ABI name of vector type. The type is always available
- under this name, even when riscv_vector.h isn't included.
- For example:  '__rvv_int32m1_t'.  */
-  const char *abi_name;
-
-  /* The C++ mangling of ABI_NAME.  */
-  const char *mangled_name;
-};
-
/* Enumerates the RVV types, together called
"vector types" for brevity.  */
enum vector_type_index
-- 
2.36.1
 


Re: [committed] libstdc++: std::make_signed_t should be ill-formed

2022-10-10 Thread Jonathan Wakely via Gcc-patches
On Mon, 10 Oct 2022 at 14:50, Tim Song via Libstdc++
 wrote:
>
> On Mon, Oct 10, 2022 at 8:09 AM Patrick Palka via Libstdc++
>  wrote:
> >
> > On Mon, 10 Oct 2022, Jonathan Wakely via Libstdc++ wrote:
> >
> > > Tested powerpc64le-linux. Pushed to trunk.
> > >
> > > -- >8 --
> > >
> > > Currently we only reject std::make_signed_t but not cv bool.
> > > Similarly for std::make_unsigned_t.
> > >
> > > As well as making those ill-formed, this adds a requires-clause to the
> > > make_signed and make_unsigned primary templates. This makes
> > > non-integral, non-enum cases fail immediately with a clear error, rather
> > > than giving an error about __make_signed_selector being
> > > incomplete.
> >
> > IIUC the requires-clause turns what was once a hard error into a SFINAE
> > error, so e.g. for
> >
> >   template typename make_signed::type f(int);
> >   template void f(...);
> >   int main() { f(0); }
> >
> > the call to f would previously be rejected due to an error outside the
> > immediate context about incomplete __make_signed_selector, and now with
> > the requires-clause resolves to the second overload.  I wonder if this
> > new behavior is conforming -- the examples in [structure.specifications]
> > of how to implement 'Mandates' suggest that a failed 'Mandates' should
> > yield a hard error?
>
> I'm also concerned about the inability to name make_signed in a
> context that doesn't require its instantiation (e.g.,
> conditional_t, make_signed,
> type_identity>::type). That seems a plausible use case, and
> breaking it doesn't seem great to me (conformance aside).

Ah yes, that's a problem.

We could fix it like this:

  template
struct make_unsigned;

  template
#if __cpp_concepts
requires is_integral<_Tp>::value || __is_enum(_Tp)
struct make_unsigned<_Tp>
#else
struct make_unsigned
#endif
{ typedef typename __make_unsigned_selector<_Tp>::__type type; };

  But that doesn't really improve the diagnostic much. It's simpler
just to revert the addition of the constraints.



Re: Re: [PATCH][RFT] Vectorization of first-order recurrences

2022-10-10 Thread 钟居哲
RVV also doesn't have a two-input permutation instructions (unlike ARM SVE has 
tbl instructions) and 
RVV needs about 4 instructions to handle this permutation, it still improve 
performance a lot.
I think backend should handle this. Because this first-order recurrence loop 
vectorizer always generates the
special permuation index = [vl-1, vl, vl+1,. ..]  (This index sequence 
pattern is just following LLVM). 
If the backend doesn't want this permuation happens, just recognize this index 
pattern and disable it.


juzhe.zh...@rivai.ai
 
From: Andrew Stubbs
Date: 2022-10-10 21:57
To: Richard Biener; gcc-patches@gcc.gnu.org
CC: richard.sandif...@arm.com; juzhe.zh...@rivai.ai
Subject: Re: [PATCH][RFT] Vectorization of first-order recurrences
On 10/10/2022 12:03, Richard Biener wrote:
> The following picks up the prototype by Ju-Zhe Zhong for vectorizing
> first order recurrences.  That solves two TSVC missed optimization PRs.
> 
> There's a new scalar cycle def kind, vect_first_order_recurrence
> and it's handling of the backedge value vectorization is complicated
> by the fact that the vectorized value isn't the PHI but instead
> a (series of) permute(s) shifting in the recurring value from the
> previous iteration.  I've implemented this by creating both the
> single vectorized PHI and the series of permutes when vectorizing
> the scalar PHI but leave the backedge values in both unassigned.
> The backedge values are (for the testcases) computed by a load
> which is also the place after which the permutes are inserted.
> That placement also restricts the cases we can handle (without
> resorting to code motion).
> 
> I added both costing and SLP handling though SLP handling is
> restricted to the case where a single vectorized PHI is enough.
> 
> Missing is epilogue handling - while prologue peeling would
> be handled transparently by adjusting iv_phi_p the epilogue
> case doesn't work with just inserting a scalar LC PHI since
> that a) keeps the scalar load live and b) that loads is the
> wrong one, it has to be the last, much like when we'd vectorize
> the LC PHI as live operation.  Unfortunately LIVE
> compute/analysis happens too early before we decide on
> peeling.  When using fully masked loop vectorization the
> vect-recurr-6.c works as expected though.
> 
> I have tested this on x86_64 for now, but since epilogue
> handling is missing there's probably no practical cases.
> My prototype WHILE_ULT AVX512 patch can handle vect-recurr-6.c
> just fine but I didn't feel like running SPEC within SDE nor
> is the WHILE_ULT patch complete enough.  Builds of SPEC 2k7
> with fully masked loops succeed (minus three cases of
> PR107096, caused by my WHILE_ULT prototype).
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
> 
> Testing with SVE, GCN or RVV appreciated, ideas how to cleanly
> handle epilogues welcome.
 
The testcases all produce correct code on GCN and pass the execution tests.
 
The code isn't terribly optimal because we don't have a two-input 
permutation instruction, so we permute each half separately and 
vec_merge the results. In this case the first vector is always a no-op 
permutation so that's wasted cycles. We'd really want a vector rotate 
and write-lane (or the other way around). I think the special-case 
permutations can be recognised and coded into the backend, but I don't 
know if we can easily tell that the first vector is just a bunch of 
duplicates, when it's not constant.
 
Andrew
 


[RFC] Add support for vectors in comparisons (like the C++ frontend does)

2022-10-10 Thread Paul Iannetta via Gcc-patches
Hi,

I am trying to bridge the gap between the extensions supported by the C
and C++ front-ends.  When it comes to vector extensions, C++ supports
vectors in comparisons and within conditional expressions whereas the C
front-end does not.

I have a patch to bring this feature to the C front-end as well, and
would like to hear your opinion on it, especially since it may affect
the feature-set of the objc front-end as well.

I have tried to mirror as much as possible what the C++ front-end does
and checked that both front-end produce the same GIMPLE for all the
simple expressions as well as some more complex combinations of the
operators (?:, !, ^, || and &&).

Currently, this is only a tentative patch and I did not add any tests
to the testsuite.  Moreover, the aarch64's target-specific testsuite
explicitly tests the non-presence of this feature, which will have to
be removed.

I've run the testsuite on x86 and I've not seen any regressions.

Cheers,
Paul

#  >8 
Support for vector types in simple comparisons

gcc/

* doc/extend.texi: Remove the C++ mention, since both C and C++
  support the all the mentioned features.

gcc/c/

* c-typeck.cc (build_unary_op): Add support for vector for the
  unary exclamation mark.
(build_conditional_expr): Add support for vector in conditional
expressions.
(build_binary_op): Add support for vector for &&, || and ^.
(c_objc_common_truthvalue_conversion): Remove the special gards
preventing vector types.

#  >8 
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 17185fd3da4..03ade14cae9 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -4536,12 +4536,15 @@ build_unary_op (location_t location, enum tree_code 
code, tree xarg,
 case TRUTH_NOT_EXPR:
   if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
  && typecode != REAL_TYPE && typecode != POINTER_TYPE
- && typecode != COMPLEX_TYPE)
+ && typecode != COMPLEX_TYPE && typecode != VECTOR_TYPE)
{
  error_at (location,
"wrong type argument to unary exclamation mark");
  return error_mark_node;
}
+  if (gnu_vector_type_p (TREE_TYPE (arg)))
+   return build_binary_op (location, EQ_EXPR, arg,
+   build_zero_cst (TREE_TYPE (arg)), false);
   if (int_operands)
{
  arg = c_objc_common_truthvalue_conversion (location, xarg);
@@ -5477,6 +5480,129 @@ build_conditional_expr (location_t colon_loc, tree 
ifexp, bool ifexp_bcp,
   result_type = type2;
 }
 
+  if (gnu_vector_type_p (TREE_TYPE (ifexp))
+  && VECTOR_INTEGER_TYPE_P (TREE_TYPE (ifexp)))
+{
+  tree ifexp_type = TREE_TYPE (ifexp);
+
+  /* If ifexp is another cond_expr choosing between -1 and 0,
+then we can use its comparison.  It may help to avoid
+additional comparison, produce more accurate diagnostics
+and enables folding.  */
+  if (TREE_CODE (ifexp) == VEC_COND_EXPR
+ && integer_minus_onep (TREE_OPERAND (ifexp, 1))
+ && integer_zerop (TREE_OPERAND (ifexp, 2)))
+   ifexp = TREE_OPERAND (ifexp, 0);
+
+  tree op1_type = TREE_TYPE (op1);
+  tree op2_type = TREE_TYPE (op2);
+
+  if (!VECTOR_TYPE_P (op1_type) && !VECTOR_TYPE_P (op2_type))
+   {
+ /* Rely on the error messages of the scalar version.  */
+ tree scal =
+   build_conditional_expr (colon_loc, integer_one_node, ifexp_bcp,
+   op1, op1_original_type, op1_loc,
+   op2, op2_original_type, op2_loc);
+ if (scal == error_mark_node)
+   return error_mark_node;
+ tree stype = TREE_TYPE (scal);
+ tree ctype = TREE_TYPE (ifexp_type);
+ if (TYPE_SIZE (stype) != TYPE_SIZE (ctype)
+ || (!INTEGRAL_TYPE_P (stype) && !SCALAR_FLOAT_TYPE_P (stype)))
+   {
+ error_at (colon_loc,
+   "inferred scalar type %qT is not an integer or "
+   "floating-point type of the same size as %qT", stype,
+   COMPARISON_CLASS_P (ifexp)
+   ? TREE_TYPE (TREE_TYPE (TREE_OPERAND (ifexp, 0)))
+   : ctype);
+ return error_mark_node;
+   }
+
+ tree vtype = build_opaque_vector_type (stype,
+TYPE_VECTOR_SUBPARTS
+(ifexp_type));
+ /* The warnings (like Wsign-conversion) have already been
+given by the scalar build_conditional_expr. We still check
+unsafe_conversion_p to forbid truncating long long -> float.  */
+ if (unsafe_conversion_p (stype, op1, NULL_TREE, false))
+   {
+ error_at (colon_loc, "conversion of scalar 

Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' (was: [PATCH 1/3] STABS: remove -gstabs and -gxcoff functionality)

2022-10-10 Thread Thomas Schwinge
Hi!

On 2022-09-01T12:05:23+0200, Martin Liška  wrote:
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> I've also built all cross compilers.

First: thanks for that: clean up plus "built all cross compilers"!

But yet, I've now tracked down an issue related to these changes,
apparently only visible via the nvptx back end -- and quite
non-obvious...  ;-)

> --- a/gcc/config/nvptx/nvptx.cc
> +++ b/gcc/config/nvptx/nvptx.cc
> @@ -52,7 +52,6 @@
>  #include "tm-preds.h"
>  #include "tm-constrs.h"
>  #include "langhooks.h"
> -#include "dbxout.h"
>  #include "cfgrtl.h"
>  #include "gimple.h"
>  #include "stor-layout.h"

> --- a/gcc/dbxout.cc
> +++ /dev/null
> @@ -1,3936 +0,0 @@
> -/* Output dbx-format symbol table information from GNU compiler.

The "dbx-format symbol table information" stuff indeed is not relevant
anymore, but:

> -/* Record an element in the table of global destructors.  SYMBOL is
> -   a SYMBOL_REF of the function to be called; PRIORITY is a number
> -   between 0 and MAX_INIT_PRIORITY.  */
> -
> -void
> -default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
> -   int priority ATTRIBUTE_UNUSED)
> -{
> -#if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
> -  /* Tell GNU LD that this is part of the static destructor set.
> - This will work for any system that uses stabs, most usefully
> - aout systems.  */
> -  dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
> -  dbxout_stab_value_label (XSTR (symbol, 0));
> -#else
> -  sorry ("global destructors not supported on this target");
> -#endif
> -}
> -
> -/* Likewise for global constructors.  */
> -
> -void
> -default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
> -int priority ATTRIBUTE_UNUSED)
> -{
> -#if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
> -  /* Tell GNU LD that this is part of the static destructor set.
> - This will work for any system that uses stabs, most usefully
> - aout systems.  */
> -  dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
> -  dbxout_stab_value_label (XSTR (symbol, 0));
> -#else
> -  sorry ("global constructors not supported on this target");
> -#endif
> -}

> --- a/gcc/dbxout.h
> +++ /dev/null
> @@ -1,60 +0,0 @@
> -/* dbxout.h - Various declarations for functions found in dbxout.cc

> -extern void default_stabs_asm_out_destructor (rtx, int);
> -extern void default_stabs_asm_out_constructor (rtx, int);

... these two functions, 'default_stabs_asm_out_constructor',
'default_stabs_asm_out_destructor' (specifically, now their 'sorry'
branches only) used to serve as default 'TARGET_ASM_CONSTRUCTOR',
'TARGET_ASM_DESTRUCTOR' via...

> --- a/gcc/target-def.h
> +++ b/gcc/target-def.h

|  #if !defined(TARGET_ASM_CONSTRUCTOR) && !defined(USE_COLLECT2)
|  # ifdef CTORS_SECTION_ASM_OP
|  #  define TARGET_ASM_CONSTRUCTOR default_ctor_section_asm_out_constructor
>  # else
>  #  ifdef TARGET_ASM_NAMED_SECTION
>  #   define TARGET_ASM_CONSTRUCTOR default_named_section_asm_out_constructor
> -#  else
> -#   define TARGET_ASM_CONSTRUCTOR default_stabs_asm_out_constructor
>  #  endif
>  # endif
>  #endif
> @@ -74,8 +72,6 @@
|  #if !defined(TARGET_ASM_DESTRUCTOR) && !defined(USE_COLLECT2)
|  # ifdef DTORS_SECTION_ASM_OP
|  #  define TARGET_ASM_DESTRUCTOR default_dtor_section_asm_out_destructor
>  # else
>  #  ifdef TARGET_ASM_NAMED_SECTION
>  #   define TARGET_ASM_DESTRUCTOR default_named_section_asm_out_destructor
> -#  else
> -#   define TARGET_ASM_DESTRUCTOR default_stabs_asm_out_destructor
>  #  endif
>  # endif
>  #endif

... this setup here (manually added some more context to the 'diff').

That is, if a back end was not 'USE_COLLECT2', nor manually defined
'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR', or got pointed to the
respective 'default_[...]'  functions due to 'CTORS_SECTION_ASM_OP',
'DTORS_SECTION_ASM_OP', or 'TARGET_ASM_NAMED_SECTION', it got pointed to
'default_stabs_asm_out_constructor', 'default_stabs_asm_out_destructor'.
These would emit 'sorry' for any global constructor/destructor they're
run into.

This is now gone, and thus in such a back end configuration case
'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' don't get defined
anymore, and thus the subsequently following:

#if !defined(TARGET_HAVE_CTORS_DTORS)
# if defined(TARGET_ASM_CONSTRUCTOR) && defined(TARGET_ASM_DESTRUCTOR)
# define TARGET_HAVE_CTORS_DTORS true
# endif
#endif

... doesn't define 'TARGET_HAVE_CTORS_DTORS' anymore, and thus per my
understanding, 'gcc/final.cc:rest_of_handle_final':

if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
&& targetm.have_ctors_dtors)
  targetm.asm_out.constructor (XEXP (DECL_RTL (current_function_decl), 0),
   decl_init_priority_lookup
 (current_function_decl));
if (DECL_STATIC_DESTRUCTOR (current_function_decl)
&& targ

Re: Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' (was: [PATCH 1/3] STABS: remove -gstabs and -gxcoff functionality)

2022-10-10 Thread Tom de Vries via Gcc-patches

On 10/10/22 16:19, Thomas Schwinge wrote:

With that, OK to push?


FWIW, nvptx change looks in the obvious category to me.

Thanks,
- Tom


Re: [RFC] Add support for vectors in comparisons (like the C++ frontend does)

2022-10-10 Thread Iain Sandoe
Hi Paul,

Not a review of the patch - but a couple of observations.

> On 10 Oct 2022, at 15:11, Paul Iannetta via Gcc-patches 
>  wrote:

> I am trying to bridge the gap between the extensions supported by the C
> and C++ front-ends.  When it comes to vector extensions, C++ supports
> vectors in comparisons and within conditional expressions whereas the C
> front-end does not.

Equivalence seems, on the face of it, a reasonable objective - but I am
curious as whether there is some more concrete motivation for the patch,
e.g. some codebase that currently does not work but would with this change?

> I have a patch to bring this feature to the C front-end as well, and
> would like to hear your opinion on it, especially since it may affect
> the feature-set of the objc front-end as well.

Likewise, I am interested in the motivation for the ObjC change.  The usual
initial filter for consideration of functional changes (at least for the NeXT
runtime on Darwin) is “What does current clang do?” or, even better, “what
does current Xcode do?”.   There are several (possibly many) cases where
C in clang has extensions to C++ behaviour - and vice-versa (because there
is a single  front-end codebase, that happens easily, whether by design o
 accident).

The reason for the ‘clang litmus test’ is that the effective language standard
for ObjectiveC is determined by that compiler.

cheers
Iain

> I have tried to mirror as much as possible what the C++ front-end does
> and checked that both front-end produce the same GIMPLE for all the
> simple expressions as well as some more complex combinations of the
> operators (?:, !, ^, || and &&).
> 
> Currently, this is only a tentative patch and I did not add any tests
> to the testsuite.  Moreover, the aarch64's target-specific testsuite
> explicitly tests the non-presence of this feature, which will have to
> be removed.
> 
> I've run the testsuite on x86 and I've not seen any regressions.
> 
> Cheers,
> Paul
> 
> #  >8 
> Support for vector types in simple comparisons
> 
> gcc/
> 
>   * doc/extend.texi: Remove the C++ mention, since both C and C++
> support the all the mentioned features.
> 
> gcc/c/
> 
>   * c-typeck.cc (build_unary_op): Add support for vector for the
> unary exclamation mark.
>   (build_conditional_expr): Add support for vector in conditional
>   expressions.
>   (build_binary_op): Add support for vector for &&, || and ^.
>   (c_objc_common_truthvalue_conversion): Remove the special gards
>   preventing vector types.
> 
> #  >8 
> diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> index 17185fd3da4..03ade14cae9 100644
> --- a/gcc/c/c-typeck.cc
> +++ b/gcc/c/c-typeck.cc
> @@ -4536,12 +4536,15 @@ build_unary_op (location_t location, enum tree_code 
> code, tree xarg,
> case TRUTH_NOT_EXPR:
>   if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
> && typecode != REAL_TYPE && typecode != POINTER_TYPE
> -   && typecode != COMPLEX_TYPE)
> +   && typecode != COMPLEX_TYPE && typecode != VECTOR_TYPE)
>   {
> error_at (location,
>   "wrong type argument to unary exclamation mark");
> return error_mark_node;
>   }
> +  if (gnu_vector_type_p (TREE_TYPE (arg)))
> + return build_binary_op (location, EQ_EXPR, arg,
> + build_zero_cst (TREE_TYPE (arg)), false);
>   if (int_operands)
>   {
> arg = c_objc_common_truthvalue_conversion (location, xarg);
> @@ -5477,6 +5480,129 @@ build_conditional_expr (location_t colon_loc, tree 
> ifexp, bool ifexp_bcp,
>   result_type = type2;
> }
> 
> +  if (gnu_vector_type_p (TREE_TYPE (ifexp))
> +  && VECTOR_INTEGER_TYPE_P (TREE_TYPE (ifexp)))
> +{
> +  tree ifexp_type = TREE_TYPE (ifexp);
> +
> +  /* If ifexp is another cond_expr choosing between -1 and 0,
> +  then we can use its comparison.  It may help to avoid
> +  additional comparison, produce more accurate diagnostics
> +  and enables folding.  */
> +  if (TREE_CODE (ifexp) == VEC_COND_EXPR
> +   && integer_minus_onep (TREE_OPERAND (ifexp, 1))
> +   && integer_zerop (TREE_OPERAND (ifexp, 2)))
> + ifexp = TREE_OPERAND (ifexp, 0);
> +
> +  tree op1_type = TREE_TYPE (op1);
> +  tree op2_type = TREE_TYPE (op2);
> +
> +  if (!VECTOR_TYPE_P (op1_type) && !VECTOR_TYPE_P (op2_type))
> + {
> +   /* Rely on the error messages of the scalar version.  */
> +   tree scal =
> + build_conditional_expr (colon_loc, integer_one_node, ifexp_bcp,
> + op1, op1_original_type, op1_loc,
> + op2, op2_original_type, op2_loc);
> +   if (scal == error_mark_node)
> + return error_mark_node;
> +   tree stype = TREE_TYPE (scal);
> +   tree ctype = TREE_TYPE (ifexp_type);
> +   if (TY

Re: [PATCH v4] c-family: ICE with [[gnu::nocf_check]] [PR106937]

2022-10-10 Thread Jason Merrill via Gcc-patches

On 10/7/22 18:16, Marek Polacek wrote:

On Fri, Oct 07, 2022 at 05:56:18PM -0400, Jason Merrill wrote:

On 10/7/22 17:08, Marek Polacek wrote:

On Fri, Oct 07, 2022 at 12:17:34PM -0400, Jason Merrill wrote:

On 10/6/22 22:12, Marek Polacek wrote:

On Thu, Oct 06, 2022 at 05:42:41PM -0400, Jason Merrill wrote:

On 10/4/22 19:06, Marek Polacek wrote:

On Fri, Sep 30, 2022 at 09:12:24AM -0400, Jason Merrill wrote:

On 9/29/22 18:49, Marek Polacek wrote:

When getting the name of an attribute, we ought to use
get_attribute_name, which handles both [[ ]] and __attribute__(())
forms.  Failure to do so may result in an ICE, like here.

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


How do we print the attributes with this patch?  Don't we also want to print
the namespace, and use [[]] in the output?


Good point, however: while the testcase indeed has an attribute
in the [[]] form in the typedef, here we're printing its "aka":

warning: initialization of 'FuncPointerWithNoCfCheck' {aka 'void 
(__attribute__((nocf_check)) *)(void)'} from incompatible pointer type 
'FuncPointer' {aka 'void (*)(void)'}

c-pretty-print.cc doesn't seem to know how to print an [[]] attribute.
I could do that, but then we'd print

  aka 'void ([[nocf_check]] *)(void)'

in the above, but that's invalid syntax!


Indeed, it should be

void (* [[gnu::nocf_check]])(void)


Ok, let me fix that too, then.  I've updated the description to show
what we print with the patch, and what was printed before.


Oops, apparently I was wrongly assuming that the attribute appertained to
the pointer.


So was I :/.


Since it actually appertains to the function type, it should
be

   void (*)(void) [[gnu::nocf_check]].

But for GCC attribute syntax, I think we want to leave the __attribute__
where it was before, as in the manual's example

   void (__attribute__((noreturn)) f) (void);


Thanks, done here:

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

-- >8 --
When getting the name of an attribute, we ought to use
get_attribute_name, which handles both [[]] and __attribute__(())
forms.  Failure to do so may result in an ICE, like here.

pp_c_attributes_display wasn't able to print the [[]] form of
attributes, so this patch teaches it to.

When printing a pointer to function with a standard attribute, the attribute
should be printed after the parameter-list.  With this patch we print:

aka 'void (*)(int) [[gnu::nocf_check]]'

pp_c_attributes has been unused since its introduction in r56273 so
this patch removes it.

PR c++/106937

gcc/c-family/ChangeLog:

* c-pretty-print.cc (pp_c_specifier_qualifier_list): Only print
GNU attributes here.
(c_pretty_printer::abstract_declarator): For a pointer to function,
print the standard [[]] attributes here.
(pp_c_attributes): Remove.
(pp_c_attributes_display): Print the [[]] form if appropriate.  Use
get_attribute_name.  Don't print a trailing space when printing the
[[]] form.
* c-pretty-print.h (pp_c_attributes): Remove.

gcc/cp/ChangeLog:

* error.cc: Include "attribs.h".
(dump_type_prefix): Only print GNU attributes here.
(dump_type_suffix): Print standard attributes here.

gcc/testsuite/ChangeLog:

* c-c++-common/pointer-to-fn1.c: New test.
---
   gcc/c-family/c-pretty-print.cc  | 102 +++-
   gcc/c-family/c-pretty-print.h   |   1 -
   gcc/cp/error.cc |  17 +++-
   gcc/testsuite/c-c++-common/pointer-to-fn1.c |  18 
   4 files changed, 92 insertions(+), 46 deletions(-)
   create mode 100644 gcc/testsuite/c-c++-common/pointer-to-fn1.c

diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc
index efa1768f4d6..349f0a07d3e 100644
--- a/gcc/c-family/c-pretty-print.cc
+++ b/gcc/c-family/c-pretty-print.cc
@@ -466,7 +466,12 @@ pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree 
t)
  {
pp_c_whitespace (pp);
pp_c_left_paren (pp);
-   pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
+   /* If we're dealing with the GNU form of attributes, print this:
+void (__attribute__((noreturn)) *f) ();
+  If it is the standard [[]] attribute, we'll print the attribute
+  in c_pretty_printer::abstract_declarator.  */
+   if (!cxx11_attribute_p (TYPE_ATTRIBUTES (pointee)))
+ pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
  }
else if (!c_dialect_cxx ())
  pp_c_whitespace (pp);
@@ -564,15 +569,26 @@ pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
   void
   c_pretty_printer::abstract_declarator (tree t)
   {
+  bool fn_ptr_p = false;
 if (TREE_CODE (t) == POINTER_TYPE)
   {
 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
  || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
-   pp_c_right_paren (this);
+  

Re: [PATCH] libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606]

2022-10-10 Thread Jonathan Wakely via Gcc-patches
On Mon, 10 Oct 2022 at 12:17, Jonathan Wakely  wrote:
>
> On Mon, 10 Oct 2022 at 07:18, Richard Biener  
> wrote:
> >
> > On Fri, Oct 7, 2022 at 5:55 PM Jonathan Wakely via Gcc-patches
> >  wrote:
> > >
> > > This needs a little more documentation (see the TODO in the manual),
> > > rather than just the comments in the source. This isn't final, but I
> > > think it's the direction I want to take.
> > >
> > > -- >8 --
> > >
> > > Implement a long-standing request to support tuning the size of the
> > > emergency buffer for allocating exceptions after malloc fails, or to
> > > disable that buffer entirely.
> > >
> > > It's now possible to disable the dynamic allocation of the buffer and
> > > use a fixed-size static buffer, via --enable-libstdcxx-static-eh-pool.
> > > This is a built-time choice that is baked into libstdc++ and so affects
> > > all code linked against that build of libstdc++.
> > >
> > > The size of the pool can be set by --with-libstdcxx-eh-pool-obj-count=N
> > > which is measured in units of sizeof(void*) not bytes. A given exception
> > > type such as std::system_error depends on the target, so giving a size
> > > in bytes wouldn't be portable across 16/32/64-bit targets.
> > >
> > > When libstdc++ is configured to use a dynamic buffer, the size of that
> > > buffer can now be tuned at runtime by setting the GLIBCXX_TUNABLES
> > > environment variable (c.f. PR libstdc++/88264). The number of exceptions
> > > to reserve space for is controlled by the "glibcxx.eh_pool.obj_count"
> > > and "glibcxx.eh_pool.obj_size" tunables. The pool will be sized to be
> > > able to allocate obj_count exceptions of size obj_size*sizeof(void*) and
> > > obj_count "dependent" exceptions rethrown by std::rethrow_exception.
> > >
> > > With the ability to tune the buffer size, we can reduce the default pool
> > > size. Most users never need to throw 1kB exceptions in parallel from
> > > hundreds of threads after malloc is OOM.
> >
> > But does it hurt?  Back in time when I reworked the allocator to be less
> > wasteful the whole point was to allow more exceptions to be in-flight
> > during OOM shutdown of a process with many threads.
>
> It certainly hurts for small systems, but maybe we can keep the large
> allocation for 64-bit targets (currently 73kB) and only reduce it for
> 32-bit (19kB) and 16-bit (3kB IIRC) targets.

Maybe this incremental diff would be an improvement:

@@ -90,7 +90,7 @@ using namespace __cxxabiv1;
// Assume that the number of concurrent exception objects scales with the
// processor word size, i.e., 16-bit systems are not likely to have hundreds
// of threads all simultaneously throwing on OOM conditions.
-# define EMERGENCY_OBJ_COUNT   (8 * __SIZEOF_POINTER__)
+# define EMERGENCY_OBJ_COUNT   (4 * __SIZEOF_POINTER__ * __SIZEOF_POINTER__)
# define MAX_OBJ_COUNT  (16 << __SIZEOF_POINTER__)
#else
# define EMERGENCY_OBJ_COUNT   4

This makes it quadratic in the word size, so on 64-bit targets we'd
have space for 256 "reasonable size" exceptions (and twice as many
single word exceptions like std::bad_alloc), but only 64 on 32-bit
targets, and only 16 on 16-bit ones.

This slightly increases the initial allocation on x86_64 from 72,704
bytes to 73,728 bytes, but reduces 32-bit from 18,944 bytes to 12,800.
If more is needed, it can be chosen via configure or the environment.



Re: [RFC] Add support for vectors in comparisons (like the C++ frontend does)

2022-10-10 Thread Paul Iannetta via Gcc-patches
Hi Ian,

Observations are also very welcomed, thank you!

On Mon, Oct 10, 2022 at 03:37:24PM +0100, Iain Sandoe wrote:
> Hi Paul,
> 
> Not a review of the patch - but a couple of observations.
> 
> > On 10 Oct 2022, at 15:11, Paul Iannetta via Gcc-patches 
> >  wrote:
> 
> > I am trying to bridge the gap between the extensions supported by the C
> > and C++ front-ends.  When it comes to vector extensions, C++ supports
> > vectors in comparisons and within conditional expressions whereas the C
> > front-end does not.
> 
> Equivalence seems, on the face of it, a reasonable objective - but I am
> curious as whether there is some more concrete motivation for the patch,
> e.g. some codebase that currently does not work but would with this change?
> 

The main motivation behind the equivalence is that, we have C and C++
codebases, and it is not very convenient to have to remember which
extension is allowed in C and not in C++ and vice-versa.  And, in this
case, it makes it harder for GCC to generate conditional moves for
code using vectors, especially since `a ? b : c` is not recognized,
and thus, we cannot rely on the `VEC_COND_EXPR` construction.

> > I have a patch to bring this feature to the C front-end as well, and
> > would like to hear your opinion on it, especially since it may affect
> > the feature-set of the objc front-end as well.
> 
> Likewise, I am interested in the motivation for the ObjC change.  The usual
> initial filter for consideration of functional changes (at least for the NeXT
> runtime on Darwin) is “What does current clang do?” or, even better, “what
> does current Xcode do?”.   There are several (possibly many) cases where
> C in clang has extensions to C++ behaviour - and vice-versa (because there
> is a single  front-end codebase, that happens easily, whether by design o
>  accident).

Well, the only motivation was that it was easier to make the change
for both front-ends at the same time and avoided some checks.  I'll
add them so that it won't introduce a divergence on what is accepted
by the objc front-end.

Thanks,
Paul

> 
> The reason for the ‘clang litmus test’ is that the effective language standard
> for ObjectiveC is determined by that compiler.
> 
> cheers
> Iain
> 
> > I have tried to mirror as much as possible what the C++ front-end does
> > and checked that both front-end produce the same GIMPLE for all the
> > simple expressions as well as some more complex combinations of the
> > operators (?:, !, ^, || and &&).
> > 
> > Currently, this is only a tentative patch and I did not add any tests
> > to the testsuite.  Moreover, the aarch64's target-specific testsuite
> > explicitly tests the non-presence of this feature, which will have to
> > be removed.
> > 
> > I've run the testsuite on x86 and I've not seen any regressions.
> > 
> > Cheers,
> > Paul
> > 
> > #  >8 
> > Support for vector types in simple comparisons
> > 
> > gcc/
> > 
> > * doc/extend.texi: Remove the C++ mention, since both C and C++
> >   support the all the mentioned features.
> > 
> > gcc/c/
> > 
> > * c-typeck.cc (build_unary_op): Add support for vector for the
> >   unary exclamation mark.
> > (build_conditional_expr): Add support for vector in conditional
> > expressions.
> > (build_binary_op): Add support for vector for &&, || and ^.
> > (c_objc_common_truthvalue_conversion): Remove the special gards
> > preventing vector types.
> > 
> > #  >8 
> > diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> > index 17185fd3da4..03ade14cae9 100644
> > --- a/gcc/c/c-typeck.cc
> > +++ b/gcc/c/c-typeck.cc
> > @@ -4536,12 +4536,15 @@ build_unary_op (location_t location, enum tree_code 
> > code, tree xarg,
> > case TRUTH_NOT_EXPR:
> >   if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
> >   && typecode != REAL_TYPE && typecode != POINTER_TYPE
> > - && typecode != COMPLEX_TYPE)
> > + && typecode != COMPLEX_TYPE && typecode != VECTOR_TYPE)
> > {
> >   error_at (location,
> > "wrong type argument to unary exclamation mark");
> >   return error_mark_node;
> > }
> > +  if (gnu_vector_type_p (TREE_TYPE (arg)))
> > +   return build_binary_op (location, EQ_EXPR, arg,
> > +   build_zero_cst (TREE_TYPE (arg)), false);
> >   if (int_operands)
> > {
> >   arg = c_objc_common_truthvalue_conversion (location, xarg);
> > @@ -5477,6 +5480,129 @@ build_conditional_expr (location_t colon_loc, tree 
> > ifexp, bool ifexp_bcp,
> >   result_type = type2;
> > }
> > 
> > +  if (gnu_vector_type_p (TREE_TYPE (ifexp))
> > +  && VECTOR_INTEGER_TYPE_P (TREE_TYPE (ifexp)))
> > +{
> > +  tree ifexp_type = TREE_TYPE (ifexp);
> > +
> > +  /* If ifexp is another cond_expr choosing between -1 and 0,
> > +then we can use its comparison.  It may help to avoid
> > +additional compa

Re: [PATCH][GCC 12] arm: Fix constant immediates predicates and constraints for some MVE builtins

2022-10-10 Thread Christophe Lyon via Gcc-patches

ping^2 ?


On 10/5/22 16:55, Christophe Lyon via Gcc-patches wrote:

ping?


On 9/12/22 10:13, Christophe Lyon via Gcc-patches wrote:

Hi!

On 9/9/22 11:33, Christophe Lyon wrote:

This is a backport from trunk to gcc-12.

Several MVE builtins incorrectly use the same predicate/constraint
pair for several modes, which does not match the specification.
This patch uses the appropriate iterator instead.

2022-09-06  Christophe Lyon  

gcc/
* config/arm/mve.md (mve_vqshluq_n_s): Use
MVE_pred/MVE_constraint instead of mve_imm_7/Ra.
(mve_vqshluq_m_n_s): Likewise.
(mve_vqrshrnbq_n_): Use MVE_pred3/MVE_constraint3
instead of mve_imm_8/Rb.
(mve_vqrshrunbq_n_s): Likewise.
(mve_vqrshrntq_n_): Likewise.
(mve_vqrshruntq_n_s): Likewise.
(mve_vrshrnbq_n_): Likewise.
(mve_vrshrntq_n_): Likewise.
(mve_vqrshrnbq_m_n_): Likewise.
(mve_vqrshrntq_m_n_): Likewise.
(mve_vrshrnbq_m_n_): Likewise.
(mve_vrshrntq_m_n_): Likewise.
(mve_vqrshrunbq_m_n_s): Likewise.
(mve_vsriq_n_): Likewise.

(cheerry-picked from c3fb6658c7670e446f2fd00984404d971e416b3c)



Is this backport OK for gcc-12? (with the "cheerry" typo above fixed)

Thanks,

Christophe



---
  gcc/config/arm/mve.md | 30 +++---
  1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/gcc/config/arm/mve.md b/gcc/config/arm/mve.md
index f16991c0a34..469e7e7f8dc 100644
--- a/gcc/config/arm/mve.md
+++ b/gcc/config/arm/mve.md
@@ -1617,7 +1617,7 @@ (define_insn "mve_vqshluq_n_s"
    [
 (set (match_operand:MVE_2 0 "s_register_operand" "=w")
  (unspec:MVE_2 [(match_operand:MVE_2 1 "s_register_operand" "w")
-   (match_operand:SI 2 "mve_imm_7" "Ra")]
+   (match_operand:SI 2 "" "")]
   VQSHLUQ_N_S))
    ]
    "TARGET_HAVE_MVE"
@@ -2608,7 +2608,7 @@ (define_insn "mve_vqrshrnbq_n_"
 (set (match_operand: 0 "s_register_operand" "=w")
  (unspec: [(match_operand: 1 
"s_register_operand" "0")

   (match_operand:MVE_5 2 "s_register_operand" "w")
- (match_operand:SI 3 "mve_imm_8" "Rb")]
+ (match_operand:SI 3 "" 
"")]

   VQRSHRNBQ_N))
    ]
    "TARGET_HAVE_MVE"
@@ -2623,7 +2623,7 @@ (define_insn "mve_vqrshrunbq_n_s"
 (set (match_operand: 0 "s_register_operand" "=w")
  (unspec: [(match_operand: 1 
"s_register_operand" "0")

   (match_operand:MVE_5 2 "s_register_operand" "w")
- (match_operand:SI 3 "mve_imm_8" "Rb")]
+ (match_operand:SI 3 "" 
"")]

   VQRSHRUNBQ_N_S))
    ]
    "TARGET_HAVE_MVE"
@@ -3563,7 +3563,7 @@ (define_insn "mve_vsriq_n_"
 (set (match_operand:MVE_2 0 "s_register_operand" "=w")
  (unspec:MVE_2 [(match_operand:MVE_2 1 "s_register_operand" "0")
 (match_operand:MVE_2 2 "s_register_operand" "w")
-   (match_operand:SI 3 "mve_imm_selective_upto_8" "Rg")]
+   (match_operand:SI 3 "" "")]
   VSRIQ_N))
    ]
    "TARGET_HAVE_MVE"
@@ -4466,7 +4466,7 @@ (define_insn "mve_vqrshrntq_n_"
 (set (match_operand: 0 "s_register_operand" "=w")
  (unspec: [(match_operand: 1 
"s_register_operand" "0")

 (match_operand:MVE_5 2 "s_register_operand" "w")
-   (match_operand:SI 3 "mve_imm_8" "Rb")]
+   (match_operand:SI 3 "" "")]
   VQRSHRNTQ_N))
    ]
    "TARGET_HAVE_MVE"
@@ -4482,7 +4482,7 @@ (define_insn "mve_vqrshruntq_n_s"
 (set (match_operand: 0 "s_register_operand" "=w")
  (unspec: [(match_operand: 1 
"s_register_operand" "0")

 (match_operand:MVE_5 2 "s_register_operand" "w")
-   (match_operand:SI 3 "mve_imm_8" "Rb")]
+   (match_operand:SI 3 "" "")]
   VQRSHRUNTQ_N_S))
    ]
    "TARGET_HAVE_MVE"
@@ -4770,7 +4770,7 @@ (define_insn "mve_vrshrnbq_n_"
 (set (match_operand: 0 "s_register_operand" "=w")
  (unspec: [(match_operand: 1 
"s_register_operand" "0")

 (match_operand:MVE_5 2 "s_register_operand" "w")
-   (match_operand:SI 3 "mve_imm_8" "Rb")]
+   (match_operand:SI 3 "" "")]
   VRSHRNBQ_N))
    ]
    "TARGET_HAVE_MVE"
@@ -4786,7 +4786,7 @@ (define_insn "mve_vrshrntq_n_"
 (set (match_operand: 0 "s_register_operand" "=w")
  (unspec: [(match_operand: 1 
"s_register_operand" "0")

 (match_operand:MVE_5 2 "s_register_operand" "w")
-   (match_operand:SI 3 "mve_imm_8" "Rb")]
+   (match_operand:SI 3 "" "")]
   VRSHRNTQ_N))
    ]
    "TARGET_HAVE_MVE"
@@ -4980,7 +4980,7 @@ (define_insn "mve_vqshluq_m_n_s"
 (set (match_operand:MVE_2 0 "s_register_operand" "=w")
  (unspec:MVE_2 [(match_operand:MVE_2 1 "s_register_operand" "0")
 (match_operand:MVE_2 2 "s_register_operand" "w")
-   (match_operand:SI 3 "mve_imm_7" "Ra")
+   (match_operand:SI 3 "" "")
 (match_operand: 4 "vpr_register_operand" 
"Up")]

   VQSHLUQ_M_N_S))
    ]
@@ -

[PATCH] 0/19 modula-2 front end patches overview

2022-10-10 Thread Gaius Mulley via Gcc-patches


Here are the latest modula-2 front end patches for review.
The status of the patches and their contents are also contained at:

   https://splendidisolation.ddns.net/public/modula2/patchsummary.html

where they are also broken down into topic groups.

In summary the high level changes from the last posting are:

   * the driver code has been completely rewritten and it is now based
 on the fortran driver and the c++ driver.  The gm2 driver adds
 paths/libraries depending upon dialect chosen.
   * the linking mechanism has been completely redesigned
 (As per
 https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595725.html).
 Objects can be linked via g++.  New linking options
 are available to allow linking with/without a scaffold.
   * gcc/m2/Make-lang.in (rewritten).
   * gm2tools/ removed and any required functionality with the
 new linking mechanism has been moved into cc1gm2.

The gm2 testsuite has been extended to test project linking
options.

Testing
===

1. bootstrap on gcc-13 master --enable-languages=c,c++,fortran,d,lto

2. bootstrap on gcc-13 devel/modula-2 --enable-languages=c,c++,fortran,d,lto
   no extra failures seen between contrib/compare_diffs 1 2

3. bootstrap on gcc-13 devel/modula-2 --enable-languages=c,c++,fortran,d,lto,m2
   no extra no m2 failures seen between contrib/compare_diffs 2 3

Steps 1, 2, 3 were performed on amd64 and aarch64 systems.

The devel/modula-2 branch has been bootstrapped on:

   amd64 (debian bullseye/suse leap, suse tumbleweed),
   aarch64 (debian bullseye),
   armv7l (raspian),
   ppc64 (GNU/Linux),
   ppc64le (GNU/Linux),
   i586 (debian bullseye),
   sparc64 solaris
   sparc32 solaris

and built on

   NetBSD 9.2 sparc64
   OpenBSD amd64

Sources
===

The patch set files follow in subsequent emails for review and copies
can be found in the tarball below.  For ease of testing the full front
end is also available via:

  git clone git://gcc.gnu.org/git/gcc.git gcc-git-devel-modula2
  cd gcc-git-devel-modula2
  git checkout devel/modula-2

The complete patch set is also available from:

  https://splendidisolation.ddns.net/public/modula2/gm2patchset.tar.gz

which can be applied to the gcc-13 master branch via:

  git clone git://gcc.gnu.org/git/gcc.git gcc-git
  wget --no-check-certificate \
  https://splendidisolation.ddns.net/public/modula2/gm2patchset.tar.gz
  tar zxf gm2patchset.tar.gz
  bash gm2patchset/apply-patch.bash gcc-git
  bash gm2patchset/pre-configure.bash gcc-git # regenerates configure and 
friends

when the script has completed the master branch should be identical
to git branch devel/modula-2 above modulo recent git master commits.

Review Patch Set


Here are all the source infrastructure files and all the c++/c sources
(minus the bootstrap tools as these are autogenerated from the
modula-2 sources).  I've not included the modula-2 sources (patch sets
18 and 19) in these emails as an attempt to reduce the email volume.
They are available in
https://splendidisolation.ddns.net/public/modula2/gm2patchset.tar.gz
and of course the git repro.

I'm happy to convert the documentation into sphynx and at a convenient
point would like to post the analyser patches for modula2.

Thank you for reviewing the patches and thank you to all the testers

regards,
Gaius


[PATCH] 7/19 modula2 front end: libgm2/libm2log contents

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the makefiles, autoconf sources necessary
to build the various libgm2 libraries.  The c/c++/h files are included
in the patch set.  The modula-2 sources are found in gcc/m2.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2log/Break.c
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2log/Break.c   2022-10-07 
20:21:18.738098020 +0100
@@ -0,0 +1,134 @@
+/* Break.c implements an interrupt handler for SIGINT.
+
+Copyright (C) 2004-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include 
+
+#if defined(HAVE_STDIO_H)
+#include 
+#endif
+
+#if defined(HAVE_STDARG_H)
+#include 
+#endif
+
+#if defined(HAVE_STDLIB_H)
+#include 
+#endif
+
+#if defined(HAVE_MALLOC_H)
+#include 
+#endif
+
+typedef void (*PROC) (void);
+
+#if defined(HAVE_SIGNAL_H)
+#include 
+
+struct plist
+{
+  PROC proc;
+  struct plist *next;
+};
+
+static struct plist *head = NULL;
+
+/* localHandler - dismisses the parameter, p, and invokes the GNU
+   Modula-2 handler.  */
+
+static void
+localHandler (int p)
+{
+  if (head != NULL)
+head->proc ();
+}
+
+/* EnableBreak - enable the current break handler.  */
+
+void
+Break_EnableBreak (void)
+{
+  signal (SIGINT, localHandler);
+}
+
+/* DisableBreak - disable the current break handler (and all
+   installed handlers).  */
+
+void
+Break_DisableBreak (void)
+{
+  signal (SIGINT, SIG_IGN);
+}
+
+/* InstallBreak - installs a procedure, p, to be invoked when a
+   ctrl-c is caught.  Any number of these procedures may be stacked.
+   Only the top procedure is run when ctrl-c is caught.  */
+
+void
+Break_InstallBreak (PROC p)
+{
+  struct plist *q = (struct plist *)malloc (sizeof (struct plist));
+
+  if (q == NULL)
+{
+  perror ("out of memory error in module Break");
+  exit (1);
+}
+  q->next = head;
+  head = q;
+  head->proc = p;
+}
+
+/* UnInstallBreak - pops the break handler stack.  */
+
+void
+Break_UnInstallBreak (void)
+{
+  struct plist *q = head;
+
+  if (head != NULL)
+{
+  head = head->next;
+  free (q);
+}
+}
+#else
+void
+Break_EnableBreak (void)
+{
+}
+void
+Break_DisableBreak (void)
+{
+}
+void
+Break_InstallBreak (PROC *p)
+{
+}
+void
+Break_UnInstallBreak (void)
+{
+}
+#endif
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2log/Makefile.am
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2log/Makefile.am   2022-10-07 
20:21:18.738098020 +0100
@@ -0,0 +1,166 @@
+# Makefile for libm2log.
+#   Copyright 2013-2022  Free Software Foundation, Inc.
+#
+# This file 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; see the file COPYING3.  If not see
+# .
+
+SUFFIXES = .c .mod .def .o .obj .lo .a .la
+
+ACLOCAL_AMFLAGS = -I . -I .. -I ../config
+
+VPATH = . @srcdir@ @srcdir@/../../gcc/m2/gm2-libs-pim
+
+# Multilib support.
+MAKEOVERRIDES=
+
+version := $(shell $(CC) -dumpversion)
+
+# Directory in which the compiler finds libraries etc.
+libsubdir = $(libdir)/gcc/$(target_alias)/$(version)
+# Used to install the shared libgcc.
+slibdir = @slibdir@
+
+toolexeclibdir=@toolexeclibdir@
+toolexecdir=@toolexecdir@
+GM2_FOR_TARGET=@GM2_FOR_TARGET@
+
+MULTIDIR := $(shell $(CC) $(CFLAGS) -print-multi-directory)
+MULTIOSDIR := $(shell $(CC) $(CFLAGS) -print-multi-os-directory)
+
+MULTIOSSUBDIR := $(shell if test x$(MULTIOSDIR) != x.; then echo 
/$(MULTIOSDIR); fi

[PATCH] 3/19 modula2 front end: gm2 driver files.

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the c++, h and option related files necessary
to build the driver program gm2.  The patch also consists of the
autoconf/configure related build infastructure sources found in
gcc/m2.  The reviewer might need to look at the 01-02-make patchset.
The gm2 driver is heavily based on the fortran driver, it also adds
the c++ libraries and modula-2 search paths and libraries depending
upon dialect for user convenience.  Users could link modula-2 objects
using g++ if they supply the include and link paths.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2spec.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2spec.cc 2022-10-07 20:21:18.662097087 
+0100
@@ -0,0 +1,937 @@
+/* gm2spec.cc specific flags and argument handling within GNU Modula-2.
+
+Copyright (C) 2007-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "xregex.h"
+#include "obstack.h"
+#include "intl.h"
+#include "prefix.h"
+#include "opt-suggestions.h"
+#include "gcc.h"
+#include "opts.h"
+#include "vec.h"
+
+#include "m2/gm2config.h"
+
+#ifdef HAVE_DIRENT_H
+#include 
+#else
+#ifdef HAVE_SYS_NDIR_H
+#include 
+#endif
+#ifdef HAVE_SYS_DIR_H
+#include 
+#endif
+#ifdef HAVE_NDIR_H
+#include 
+#endif
+#endif
+
+/* This bit is set if we saw a `-xfoo' language specification.  */
+#define LANGSPEC   (1<<1)
+/* This bit is set if they did `-lm' or `-lmath'.  */
+#define MATHLIB(1<<2)
+/* This bit is set if they did `-lc'.  */
+#define WITHLIBC   (1<<3)
+/* Skip this option.  */
+#define SKIPOPT(1<<4)
+
+#ifndef MATH_LIBRARY
+#define MATH_LIBRARY "m"
+#endif
+#ifndef MATH_LIBRARY_PROFILE
+#define MATH_LIBRARY_PROFILE MATH_LIBRARY
+#endif
+
+#ifndef LIBSTDCXX
+#define LIBSTDCXX "stdc++"
+#endif
+#ifndef LIBSTDCXX_PROFILE
+#define LIBSTDCXX_PROFILE LIBSTDCXX
+#endif
+#ifndef LIBSTDCXX_STATIC
+#define LIBSTDCXX_STATIC NULL
+#endif
+
+#ifndef LIBCXX
+#define LIBCXX "c++"
+#endif
+#ifndef LIBCXX_PROFILE
+#define LIBCXX_PROFILE LIBCXX
+#endif
+#ifndef LIBCXX_STATIC
+#define LIBCXX_STATIC NULL
+#endif
+
+#ifndef LIBCXXABI
+#define LIBCXXABI "c++abi"
+#endif
+#ifndef LIBCXXABI_PROFILE
+#define LIBCXXABI_PROFILE LIBCXXABI
+#endif
+#ifndef LIBCXXABI_STATIC
+#define LIBCXXABI_STATIC NULL
+#endif
+
+/* The values used here must match those of the stdlib_kind enumeration
+   in c.opt.  */
+enum stdcxxlib_kind
+{
+  USE_LIBSTDCXX = 1,
+  USE_LIBCXX = 2
+};
+
+#define DEFAULT_DIALECT "pim"
+#undef DEBUG_ARG
+
+typedef enum { iso, pim, min, logitech, pimcoroutine, maxlib } libs;
+
+/* These are the library names which are installed as part of gm2 and reflect
+   -flibs=name.  The -flibs= option provides the user with a short cut to add
+   libraries without having to know the include and link path.  */
+
+static const char *library_name[maxlib]
+= { "m2iso", "m2pim", "m2min", "m2log", "m2cor" };
+
+/* They match the installed archive name for example libm2iso.a,
+   libm2pim.a, libm2min.a, libm2log.a and libm2cor.a.  They also match a
+   subdirectory name where the definition modules are kept.  The driver
+   checks the argument to -flibs= for an entry in library_name or
+   alternatively the existance of the subdirectory (to allow for third
+   party libraries to coexist).  */
+
+static const char *library_abbrev[maxlib]
+= { "iso", "pim", "min", "log", "cor" };
+
+/* Users may specifiy -flibs=pim,iso etc which are mapped onto
+   -flibs=m2pim,m2iso respectively.  This provides a match between
+   the dialect of Modula-2 and the library set.  */
+
+static const char *add_include (const char *libpath, const char *library);
+
+static bool seen_scaffold_static = false;
+static bool seen_scaffold_dynamic = false;
+static bool scaffold_static = false;
+static bool scaffold_dynamic = true;  // Default uses -fscaffold-dynamic.
+static bool seen_gen_module_list = false;
+static bool seen_uselist = false;
+static bool uselist = false;
+static bool gen_module_list = true;  // Default uses -fgen-module-list=-.
+static const char *gen_module_filename = "-";
+static const char *multilib_dir = NULL;
+/* The original argum

[PATCH] 6/19 modula2 front end: libgm2/libm2min contents

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the makefiles, autoconf and a few C sources
to build the libgm2/libm2min libraries.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2min/Makefile.am
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2min/Makefile.am   2022-10-07 
20:21:18.738098020 +0100
@@ -0,0 +1,147 @@
+# Makefile for libm2min.
+#   Copyright 2013-2022  Free Software Foundation, Inc.
+#
+# This file 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; see the file COPYING3.  If not see
+# .
+
+SUFFIXES = .c .mod .def .o .obj .lo .a .la
+
+ACLOCAL_AMFLAGS = -I . -I .. -I ../config
+
+VPATH = . @srcdir@/../../gcc/m2/gm2-libs-min
+
+# Multilib support.
+MAKEOVERRIDES=
+
+version := $(shell $(CC) -dumpversion)
+
+# Directory in which the compiler finds libraries etc.
+libsubdir = $(libdir)/gcc/$(target_alias)/$(version)
+# Used to install the shared libgcc.
+slibdir = @slibdir@
+
+toolexeclibdir=@toolexeclibdir@
+toolexecdir=@toolexecdir@
+GM2_FOR_TARGET=@GM2_FOR_TARGET@
+
+MULTIDIR := $(shell $(CC) $(CFLAGS) -print-multi-directory)
+MULTIOSDIR := $(shell $(CC) $(CFLAGS) -print-multi-os-directory)
+
+MULTIOSSUBDIR := $(shell if test x$(MULTIOSDIR) != x.; then echo 
/$(MULTIOSDIR); fi)
+inst_libdir = $(libsubdir)$(MULTISUBDIR)
+inst_slibdir = $(slibdir)$(MULTIOSSUBDIR)
+
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+"GCC_DIR=$(GCC_DIR)" \
+"GM2_SRC=$(GM2_SRC)" \
+   "AR_FLAGS=$(AR_FLAGS)" \
+   "CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+   "CC_FOR_TARGET=$(CC_FOR_TARGET)" \
+   "GM2_FOR_TARGET=$(GM2_FOR_TARGET)" \
+   "CFLAGS=$(CFLAGS)" \
+   "CXXFLAGS=$(CXXFLAGS)" \
+   "CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+   "CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+   "INSTALL=$(INSTALL)" \
+   "INSTALL_DATA=$(INSTALL_DATA)" \
+   "INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+   "INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+   "LDFLAGS=$(LDFLAGS)" \
+   "LIBCFLAGS=$(LIBCFLAGS)" \
+   "LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+   "MAKE=$(MAKE)" \
+   "MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+"MULTISUBDIR=$(MULTISUBDIR)" \
+"MULTIOSDIR=$(MULTIOSDIR)" \
+"MULTIBUILDTOP=$(MULTIBUILDTOP)" \
+"MULTIFLAGS=$(MULTIFLAGS)" \
+   "PICFLAG=$(PICFLAG)" \
+   "PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+   "SHELL=$(SHELL)" \
+   "RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+   "exec_prefix=$(exec_prefix)" \
+   "infodir=$(infodir)" \
+   "libdir=$(libdir)" \
+   "includedir=$(includedir)" \
+   "prefix=$(prefix)" \
+   "tooldir=$(tooldir)" \
+   "AR=$(AR)" \
+   "AS=$(AS)" \
+   "LD=$(LD)" \
+   "RANLIB=$(RANLIB)" \
+   "NM=$(NM)" \
+   "NM_FOR_BUILD=$(NM_FOR_BUILD)" \
+   "NM_FOR_TARGET=$(NM_FOR_TARGET)" \
+   "DESTDIR=$(DESTDIR)" \
+   "WERROR=$(WERROR)" \
+"TARGET_LIB_PATH_libgm2=$(TARGET_LIB_PATH_libgm2)"
+
+# Subdir rules rely on $(FLAGS_TO_PASS)
+FLAGS_TO_PASS = $(AM_MAKEFLAGS)
+
+M2DEFS = libc.def  M2RTS.def \
+ SYSTEM.def
+
+M2MODS = M2RTS.mod  SYSTEM.mod
+
+libm2mindir = libm2min
+toolexeclib_LTLIBRARIES = libm2min.la
+libm2min_la_SOURCES = $(M2MODS) libc.c
+libm2min_la_DEPENDENCIES = SYSTEM.def $(addsuffix .lo, $(basename 
$(libm2min_la_SOURCES)))
+libm2min_la_CFLAGS = -I. -I$(GM2_SRC)/gm2-libs-min -I$(GM2_SRC)/gm2-libs
+libm2min_la_M2FLAGS = -I. -I$(GM2_SRC)/gm2-libs-min -I$(GM2_SRC)/gm2-libs 
-fno-exceptions \
+   -fno-m2-plugin -fno-scaffold-dynamic -fno-scaffold-main
+libm2min_la_LINK = $(LINK) -version-info $(libtool_VERSION)
+BUILT_SOURCES = SYSTEM.def
+CLEANFILES = SYSTEM.def
+
+M2LIBDIR = /m2/m2min/
+
+.mod.lo:
+   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile 
$(GM2_FOR_TARGET) -c $(CFLAGS_FOR_TARGET) $(LIBCFLAGS) $(libm2min_la_M2FLAGS) 
$< -o $@
+
+libc.o: $(GM2_SRC)/gm2-libs-min/libc.c
+
+
+SYSTEM.def: Makefile
+   echo "CC = $(CC_FOR_BUILD)  CC_FOR_TARGET = $(CC_FOR_TARGET)  GM2 = 
$(GM2)  GM2_FOR_TARGET = $(GM2_FOR_TARGET) GM2_FOR_BUILD = $(GM2_FOR_BUILD)"
+   bash $(GM2_SRC)/tools-src/makeSystem -fpim \
+ $(GM2_SRC)/gm2-libs-min/SYSTEM.def \
+

[PATCH] 2/19 modula2 front end: Make-lang.in

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

The makefile fragment for modula2 which builds the gm2 driver and cc1gm2.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/Make-lang.in
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/Make-lang.in   2022-10-07 20:21:18.634096743 
+0100
@@ -0,0 +1,1556 @@
+# Top level -*- makefile -*- fragment for GNU M2.
+
+# Copyright (C) 2000-2022 Free Software Foundation, Inc.
+
+#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
+#.
+
+GM2_MAKE_DEBUG=
+
+# Actual names to use when installing a native compiler.
+GM2_INSTALL_NAME = $(shell echo gm2|sed '$(program_transform_name)')
+GM2_TARGET_INSTALL_NAME = $(target_noncanonical)-$(shell echo gm2|sed 
'$(program_transform_name)')
+
+# Actual names to use when installing a cross-compiler.
+GM2_CROSS_NAME = `echo gm2|sed '$(program_transform_cross_name)'`
+
+M2_MAINTAINER = no
+
+CPP_GM2=-fpermissive -DIN_GCC -g
+GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
+
+GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ 
-L$(objdir)/../ld $(TFLAGS)
+
+TEXISRC = $(objdir)/m2/images/gnu.eps \
+  $(srcdir)/doc/gm2.texi \
+  m2/gm2-libs.texi \
+  m2/gm2-ebnf.texi \
+  m2/SYSTEM-pim.texi \
+  m2/SYSTEM-iso.texi \
+  m2/Builtins.texi
+
+# Define the names for selecting modula-2 in LANGUAGES.
+m2 modula-2 modula2: gm2$(exeext) xgcc$(exeext) cc1gm2$(exeext) \
+ $(GCC_PASSES) $(GCC_PARTS)
+m2.serial = cc1gm2$(exeext)
+
+# Tell GNU make to ignore these if they exist.
+.PHONY: m2 modula-2 modula2
+
+GM2_PROG_DEP=gm2$(exeext) xgcc$(exeext) cc1gm2$(exeext)
+
+include m2/config-make
+LIBSTDCXX=../$(TARGET_SUBDIR)/libstdc++-v3/src/.libs/libstdc++.a
+
+PGE=m2/pge$(exeext)
+
+SRC_PREFIX=G
+
+m2/gm2spec.o: $(srcdir)/m2/gm2spec.cc $(SYSTEM_H) $(GCC_H) $(CONFIG_H) \
+   m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS) \
+   $(generated_files) $(C_TREE_H) insn-attr-common.h
+   (SHLIB_LINK='$(SHLIB_LINK)' \
+   SHLIB_MULTILIB='$(SHLIB_MULTILIB)'; \
+   $(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+ $(DRIVER_DEFINES) \
+   -DLIBSUBDIR=\"$(libsubdir)\" \
+-DPREFIX=\"$(prefix)\" \
+-c $(srcdir)/m2/gm2spec.cc $(OUTPUT_OPTION))
+
+# Create the compiler driver for M2.
+CFLAGS-m2/m2/gm2spec.o += $(DRIVER_DEFINES)
+
+GM2_OBJS = $(GCC_OBJS) prefix.o intl.o m2/gm2spec.o
+
+# Create the compiler driver for gm2.
+gm2$(exeext): $(GM2_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS) \
+m2/gm2config.h
+   +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+ $(GM2_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
+ $(EXTRA_GCC_LIBS) $(LIBS)
+
+# Create a version of the gm2 driver which calls the cross-compiler.
+gm2-cross$(exeext): gm2$(exeext)
+   -rm -f gm2-cross$(exeext)
+   cp gm2$(exeext) gm2-cross$(exeext)
+
+po-generated:
+
+# Build hooks:
+
+m2.all.cross: gm2-cross$(exeext) plugin/m2rte$(exeext).so
+
+m2.start.encap: gm2$(exeext) plugin/m2rte$(exeext).so
+m2.rest.encap:
+
+m2.info: doc/m2.info
+
+m2.man: doc/m2.1
+
+m2.install-man: $(DESTDIR)$(man1dir)/$(GM2_INSTALL_NAME)$(man1ext)
+
+$(DESTDIR)$(man1dir)/$(GM2_INSTALL_NAME)$(man1ext): doc/m2.1 installdirs
+   -rm -f $@
+   -$(INSTALL_DATA) $< $@
+   -chmod a-x $@
+
+m2.dvi: $(TEXISRC)
+   $(TEXI2DVI) -I $(objdir)/m2 -I $(srcdir)/doc/include 
$(srcdir)/doc/gm2.texi -o $@
+
+m2.ps: m2.dvi
+   dvips -o $@ $<
+
+m2.pdf: m2.ps
+   gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=$@ $<
+
+.INTERMEDIATE: gm2.pod
+
+m2.pod: doc/gm2.texi $(TEXISRC)
+   -$(TEXI2POD) -I $(objdir)/m2 -D m2 < $< > $@
+
+doc/m2.info: $(TEXISRC)
+   if test "x$(BUILD_INFO)" = xinfo; then \
+ rm -f doc/m2.info*; \
+  $(MAKEINFO) --no-headers -I$(objdir)/m2 -I$(srcdir)/doc/include \
+  -o $@ $(srcdir)/doc/gm2.texi ; \
+   else true; fi
+
+$(objdir)/m2/images/gnu.eps: $(srcdir)/m2/images/gnupng
+   test -d m2/images || mkdir -p m2/images
+   if [ -f $(srcdir)/m2/images/gnu.eps ] ; then \
+   cp $(srcdir)/m2/images/gnu.eps $@ ; \
+else \
+   pngtopnm $< | pnmtops -noturn > $@ ; \
+fi
+
+m2/gm2-libs.texi: gm2-libs.texi-check; @true
+
+gm2-libs.texi-check:  m2/SYSTEM-pim.texi m2/SYS

[PATCH] 8/19 modula2 front end: libgm2 contents

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the libgm2 makefile, autoconf sources
necessary to build the libm2pim, libm2iso, libm2min, libm2cor
and libm2log.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/ChangeLog
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/ChangeLog  2022-10-07 20:21:18.730097923 
+0100
@@ -0,0 +1,506 @@
+2022-05-18  Gaius Mulley  
+
+   * Corrected dates on all source files.
+   * libm2pim/Selective.c: Reformatted comments.
+   * libm2pim/SysExceptions.c: Reformatted comments.
+   * libm2pim/dtoa.c: Reformatted comments.
+   * libm2pim/ldtoa.c: Reformatted comments.
+   * libm2pim/sckt.c: Reformatted comments.
+   * libm2pim/termios.c: Reformatted comments.
+   * libm2pim/wrapc.c: Reformatted comments.
+   * libm2pim/termios.c: Reformatted comments within enum.
+   * libm2pim/Selective.c: Correct spelling.
+   * libm2pim/termios.c: Use GNU comment formatting.
+
+2022-05-17  Gaius Mulley  
+
+   * Corrected dates on all source files.
+
+2022-03-02  Gaius Mulley  
+
+   * libm2pim/sckt.c (tcpServerEstablishPort): Corrected spelling.
+   (tcpServerEstablish) Corrected spelling.
+
+2021-06-27  Gaius Mulley  
+
+   * Makefile.am: renamed getopt.c to cgetopt.c.
+
+2021-05-29  Gaius Mulley  
+
+   * Makefile.in: (rebuilt).
+   * aclocal.m4: (rebuilt).
+   * configure: (rebuilt).
+   * configure.ac: tidied up messages.  Removed android
+   from the list of supported hosts.  Corrected a comment
+   * libm2pim/Makefile.am: Conditionally build.
+   * libm2cor/Makefile.am: Conditionally build.
+   * libm2log/Makefile.am: Conditionally build.
+   * libm2iso/Makefile.am: Conditionally build.
+   * libm2cor/Makefile.in: (Rebuilt).
+   * libm2iso/Makefile.in: (Rebuilt).
+   * libm2log/Makefile.in: (Rebuilt).
+   * libm2min/Makefile.in: (Rebuilt).
+   * libm2pim/Makefile.in: (Rebuilt).
+
+2021-05-28  Gaius Mulley  
+
+   * Makefile.in: (Rebuilt).
+   * aclocal.m4: (Rebuilt).
+   * configure: (Rebuilt).
+   * configure.ac: Introduce checks for supported host
+   operating system and also known detect target architectures
+   which are currently restricted to minimal runtime libraries.
+   * libm2cor/Makefile.in: (Rebuilt).
+   * libm2iso/Makefile.in: (Rebuilt).
+   * libm2log/Makefile.in: (Rebuilt).
+   * libm2min/Makefile.in: (Rebuilt).
+   * libm2pim/Makefile.in: (Rebuilt).
+
+2021-02-12  Gaius Mulley  
+
+   * libm2iso/RTco.c: (threadSem) new declaration
+and implmentation of thread semaphores used internally by
+the m2 runtime system.
+
+2021-01-13  Gaius Mulley  
+
+   * Makefile.am: Updated dates.
+   * aclocal.m4: (Rebuilt).
+   * autogen.sh: Updated dates.
+   * configure: (Rebuilt).
+   * configure.ac: Updated dates.
+   * libm2cor/KeyBoardLEDs.c: Updated dates.
+   * libm2cor/Makefile.am: Updated dates.
+   * libm2iso/ChanConsts.h: Updated dates.
+   * libm2iso/ErrnoCategory.c: Updated dates.
+   * libm2iso/Makefile.am: Updated dates.
+   * libm2iso/RTco.c: Updated dates.
+   * libm2iso/wrapsock.c: Updated dates.
+   * libm2iso/wraptime.c: Updated dates.
+   * libm2log/Break.c: Updated dates.
+   * libm2log/Makefile.am: Updated dates.
+   * libm2min/Makefile.am: Updated dates.
+   * libm2min/libc.c: Updated dates.
+   * libm2pim/Makefile.am: Updated dates.
+   * libm2pim/Selective.c: Updated dates.
+   * libm2pim/SysExceptions.c: Updated dates.
+   * libm2pim/UnixArgs.c: Updated dates.
+   * libm2pim/dtoa.c: Updated dates.
+   * libm2pim/errno.c: Updated dates.
+   * libm2pim/getopt.c: Updated dates.
+   * libm2pim/ldtoa.c: Updated dates.
+   * libm2pim/sckt.c: Updated dates.
+   * libm2pim/target.c: Updated dates.
+   * libm2pim/termios.c: Updated dates.
+   * libm2pim/wrapc.c: Updated dates.
+
+2020-11-20  Gaius Mulley  
+
+   * Makefile.in: (Rebuilt).
+   * aclocal.m4: (Rebuilt).
+   * configure: (Rebuilt).
+   * configure.ac: (libtool_VERSION=17.0.0)
+
+2020-06-18  Gaius Mulley  
+
+   * Makefile.in: (Rebuilt).
+   * aclocal.m4: (Rebuilt).
+   * autogen.sh: Execute automake including dependencies.
+   * configure: (Rebuilt).
+   * libm2cor/Makefile.in: (Rebuilt).
+   * libm2iso/Makefile.in: (Rebuilt).
+   * libm2log/Makefile.am: SYSTEM.def is a dependency using
+ BUILT_SOURCES.
+   * libm2log/Makefile.in: (Rebuilt).
+   * libm2min/Makefile.in: (Rebuilt).
+   * libm2pim/Makefile.in: (Rebuilt).
+
+2020-06-15  Gaius Mulley  
+
+   * libm2pim/Makefile.am: Added SYSTEM.def as a dependency.
+   * libm2log/Makefile.am: Added SYSTEM.def as a dependency.
+
+2020-06-11  Matthias Klose  
+
+   * Makefile.am: Reordered libraries.

[PATCH] 1/19 modula2 front end: changes outside gcc/m2, libgm2 and gcc/testsuite.

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set contains the non machine generated changes found in /
for example the language die and documentation changes.  It also
contains the changes to the top level build Makefile infastructure
and the install.texi sourcebuild.texi documentation.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw gcc-git-master/configure.ac gcc-git-devel-modula2/configure.ac
--- gcc-git-master/configure.ac 2022-10-07 20:21:09.001978462 +0100
+++ gcc-git-devel-modula2/configure.ac  2022-10-07 20:21:18.522095368 +0100
@@ -140,7 +140,7 @@
 # binutils, gas and ld appear in that order because it makes sense to run
 # "make check" in that particular order.
 # If --enable-gold is used, "gold" may replace "ld".
-host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim 
gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 
gotools c++tools"
+host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim 
gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 
gm2tools gotools c++tools"
 
 # these libraries are built for the target environment, and are built after
 # the host libraries and the host tools (which may be a cross compiler)
@@ -162,6 +162,7 @@
target-libffi \
target-libobjc \
target-libada \
+   target-libgm2 \
target-libgo \
target-libphobos \
target-zlib"
@@ -459,6 +460,14 @@
   noconfigdirs="$noconfigdirs gnattools"
 fi
 
+AC_ARG_ENABLE(libgm2,
+[AS_HELP_STRING([--enable-libgm2], [build libgm2 directory])],
+ENABLE_LIBGM2=$enableval,
+ENABLE_LIBGM2=no)
+if test "${ENABLE_LIBGM2}" != "yes" ; then
+  noconfigdirs="$noconfigdirs gm2tools"
+fi
+
 AC_ARG_ENABLE(libssp,
 [AS_HELP_STRING([--enable-libssp], [build libssp directory])],
 ENABLE_LIBSSP=$enableval,
@@ -3616,6 +3625,7 @@
 NCN_STRICT_CHECK_TARGET_TOOLS(GFORTRAN_FOR_TARGET, gfortran)
 NCN_STRICT_CHECK_TARGET_TOOLS(GOC_FOR_TARGET, gccgo)
 NCN_STRICT_CHECK_TARGET_TOOLS(GDC_FOR_TARGET, gdc)
+NCN_STRICT_CHECK_TARGET_TOOLS(GM2_FOR_TARGET, gm2)
 
 ACX_CHECK_INSTALLED_TARGET_TOOL(AR_FOR_TARGET, ar)
 ACX_CHECK_INSTALLED_TARGET_TOOL(AS_FOR_TARGET, as)
@@ -3654,6 +3664,8 @@
[gcc/gccgo -B$$r/$(HOST_SUBDIR)/gcc/], go)
 GCC_TARGET_TOOL(gdc, GDC_FOR_TARGET, GDC,
[gcc/gdc -B$$r/$(HOST_SUBDIR)/gcc/], d)
+GCC_TARGET_TOOL(gm2, GM2_FOR_TARGET, GM2,
+   [gcc/gm2 -B$$r/$(HOST_SUBDIR)/gcc/], m2)
 GCC_TARGET_TOOL(ld, LD_FOR_TARGET, LD, [ld/ld-new])
 GCC_TARGET_TOOL(lipo, LIPO_FOR_TARGET, LIPO)
 GCC_TARGET_TOOL(nm, NM_FOR_TARGET, NM, [binutils/nm-new])
@@ -3780,6 +3792,9 @@
 # Specify what files to not compare during bootstrap.
 
 compare_exclusions="gcc/cc*-checksum\$(objext) | gcc/ada/*tools/*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2-compiler-boot/M2Version*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2-compiler-boot/SYSTEM*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2version*"
 case "$target" in
   hppa*64*-*-hpux*) ;;
   powerpc*-ibm-aix*) compare_exclusions="$compare_exclusions | 
*libgomp*\$(objext)" ;;
diff -ruw gcc-git-master/gcc/doc/sourcebuild.texi 
gcc-git-devel-modula2/gcc/doc/sourcebuild.texi
--- gcc-git-master/gcc/doc/sourcebuild.texi 2022-10-07 20:21:09.761987791 
+0100
+++ gcc-git-devel-modula2/gcc/doc/sourcebuild.texi  2022-10-07 
20:21:18.606096399 +0100
@@ -97,6 +97,9 @@
 @item libgfortran
 The Fortran runtime library.
 
+@item libgm2
+The Modula-2 runtime library.
+
 @item libgo
 The Go runtime library.  The bulk of this library is mirrored from the
 @uref{https://github.com/@/golang/go, master Go repository}.
@@ -187,13 +190,12 @@
 @item @var{language}
 Subdirectories for various languages.  Directories containing a file
 @file{config-lang.in} are language subdirectories.  The contents of
-the subdirectories @file{c} (for C), @file{cp} (for C++),
-@file{objc} (for Objective-C), @file{objcp} (for Objective-C++),
-and @file{lto} (for LTO) are documented in this
-manual (@pxref{Passes, , Passes and Files of the Compiler});
-those for other languages are not.  @xref{Front End, ,
-Anatomy of a Language Front End}, for details of the files in these
-directories.
+the subdirectories @file{c} (for C), @file{cp} (for C++), @file{m2}
+(for Modula-2), @file{objc} (for Objective-C), @file{objcp} (for
+Objective-C++), and @file{lto} (for LTO) are documented in this manual
+(@pxref{Passes, , Passes and Files of the Compiler}); those for other
+languages are not.  @xref{Front End, , Anatomy of a Language Front
+End}, for details of the files in these directories.
 
 @item common
 Source files shared between the compiler drivers (such as
diff -ruw gcc-git-master/gcc/doc/install.texi 
gcc-git-devel-modula2/gcc/doc/install.texi
--- gcc-git-master/gcc/doc/install.texi 2022-10-07 20:21:09.749987645 +0100
+++ gcc-git-devel-modula2/gcc/doc/install.texi  2022-10-07 20:21:18.60

[PATCH] 14/19 modula2 front end: gimple interface remainder

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the gimple interface.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/init.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/init.cc2022-10-07 
20:21:18.650096940 +0100
@@ -0,0 +1,199 @@
+/* init.cc initializes the modules of the GNU Modula-2 front end.
+
+Copyright (C) 2012-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "init.h"
+#include "config.h"
+#include "system.h"
+
+#if defined(__GNUG__)
+#define EXTERN extern "C"
+#else /* !__GNUG__  */
+#define EXTERN extern
+#endif /* !__GNUG__  */
+
+EXTERN void _M2_M2Bitset_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Debug_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Defaults_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Environment_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_RTExceptions_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2EXCEPTION_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2RTS_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Dependent_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SysExceptions_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_DynamicStrings_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Assertion_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_FormatStrings_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_FIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SFIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SArgs_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Lists_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_UnixArgs_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Args_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_wrapc_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_TimeString_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_IO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_StdIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_CmdArgs_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Preprocess_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Error_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Search_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Indexing_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_NameKey_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_NumberIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_FpuIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SysStorage_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Storage_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_StrIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Debug_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Batch_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_StrLib_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2ALU_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Options_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Comp_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2LexBuf_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SymbolTable_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Base_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Quads_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SymbolKey_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_FifoQueue_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Reserved_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Const_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_P1SymBuild_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_P2SymBuild_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_P3SymBuild_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2System_init (int argc, char *argv[], char *envp[]);
+EXTERN vo

[PATCH] 9/19 modula2 front end: plugin source files

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the modula2 plugin which detects some runtime
errors at compiletime.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/plugin/m2rte.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/plugin/m2rte.cc2022-10-07 
20:21:18.682097332 +0100
@@ -0,0 +1,335 @@
+/* m2rte.cc a plugin to detect runtime exceptions at compiletime.
+
+Copyright (C) 2017-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+
+#include "gcc-plugin.h"
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "options.h"
+#include "tree-pass.h"
+#include "diagnostic-core.h"
+#include "flags.h"
+#include "intl.h"
+#include "plugin.h"
+#include "tree.h"
+#include "gimple.h"
+#include "gimplify.h"
+#include "gimple-iterator.h"
+#include "gimplify-me.h"
+#include "gimple-pretty-print.h"
+#include "plugin-version.h"
+#include "diagnostic.h"
+#include "context.h"
+
+#include "rtegraph.h"
+extern bool ggc_force_collect;
+extern void ggc_collect (void);
+
+#undef DEBUG_BASICBLOCK
+
+int plugin_is_GPL_compatible;
+
+void debug_tree (tree);
+
+/* All dialects of Modula-2 issue some or all of these runtime error calls.
+   This plugin detects whether a runtime error will be called in the first
+   basic block of a reachable function.  */
+
+static const char *m2_runtime_error_calls[] = {
+  "M2RTS_AssignmentException",
+  "M2RTS_ReturnException",
+  "M2RTS_IncException",
+  "M2RTS_DecException",
+  "M2RTS_InclException",
+  "M2RTS_ExclException",
+  "M2RTS_ShiftException",
+  "M2RTS_RotateException",
+  "M2RTS_StaticArraySubscriptException",
+  "M2RTS_DynamicArraySubscriptException",
+  "M2RTS_ForLoopBeginException",
+  "M2RTS_ForLoopToException",
+  "M2RTS_ForLoopEndException",
+  "M2RTS_PointerNilException",
+  "M2RTS_NoReturnException",
+  "M2RTS_CaseException",
+  "M2RTS_WholeNonPosDivException",
+  "M2RTS_WholeNonPosModException",
+  "M2RTS_WholeZeroDivException",
+  "M2RTS_WholeZeroRemException",
+  "M2RTS_WholeValueException",
+  "M2RTS_RealValueException",
+  "M2RTS_ParameterException",
+  "M2RTS_NoException",
+  NULL,
+};
+
+
+#if defined(DEBUG_BASICBLOCK)
+/* pretty_function display the name of the function.  */
+
+static void
+pretty_function (tree fndecl)
+{
+  if (fndecl != NULL && (DECL_NAME (fndecl) != NULL))
+{
+  const char *n = IDENTIFIER_POINTER (DECL_NAME (fndecl));
+  fprintf (stderr, "PROCEDURE %s ;\n", n);
+}
+}
+#endif
+
+void
+print_rtl (FILE *outf, const_rtx rtx_first);
+
+/* strend returns true if string name has ending.  */
+
+static bool
+strend (const char *name, const char *ending)
+{
+  unsigned int len = strlen (name);
+  return (len > strlen (ending)
+ && (strcmp (&name[len-strlen (ending)], ending) == 0));
+}
+
+/* is_constructor returns true if the function name is that of a module
+   constructor or deconstructor.  */
+
+static bool
+is_constructor (tree fndecl)
+{
+  const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
+  unsigned int len = strlen (name);
+
+  return ((len > strlen ("_M2_"))
+ && (strncmp (name, "_M2_", strlen ("_M2_")) == 0)
+ && (strend (name, "_init") || strend (name, "_finish")));
+}
+
+/* is_external returns true if the function is extern.  */
+
+static bool
+is_external (tree function)
+{
+  return (! DECL_EXTERNAL (function))
+&& TREE_PUBLIC (function)
+&& TREE_STATIC (function);
+}
+
+/* is_external returns true if the function is a call to a Modula-2
+   runtime exception handler.  */
+
+static bool
+is_rte (tree fndecl)
+{
+  const char *n = IDENTIFIER_POINTER (DECL_NAME (fndecl));
+
+  for (int i = 0; m2_runtime_error_calls[i] != NULL; i++)
+if (strcmp (m2_runtime_error_calls[i], n) == 0)
+  return true;
+  return false;
+}
+
+/* examine_call extract the function tree from the gimple call
+   statement and check whether it is a call to a runtime exception.  */
+
+static void
+examine_call (gimple *stmt)
+{
+  tree fndecl = gimple_call_fndecl (stmt);
+  rtenode *func = rtegraph_lookup (stmt, fndecl, true);
+  // rtegraph_dump ();
+  if (fndecl != NULL && (DECL_NAME (fndecl) != NULL))
+{
+  /* Firstly check if the function is a runtime exception.  */
+  if (is_rte (fndecl))

[PATCH] 13/19 modula2 front end: gimple interface *[g-m]*.cc

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the gimple interface.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2linemap.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2linemap.cc   2022-10-07 
20:21:18.650096940 +0100
@@ -0,0 +1,254 @@
+/* m2linemap.cc provides an interface to GCC linemaps.
+
+Copyright (C) 2012-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "gcc-consolidation.h"
+
+/* Utilize some of the C build routines */
+
+#include "../gm2-lang.h"
+#include "../m2-tree.h"
+
+#include "m2assert.h"
+#include "m2block.h"
+#include "m2decl.h"
+#include "m2expr.h"
+#include "m2options.h"
+#include "m2tree.h"
+#include "m2type.h"
+#define m2linemap_c
+#include "m2linemap.h"
+
+static int inFile = FALSE;
+
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
+
+/* Start getting locations from a new file.  */
+
+EXTERN
+void
+m2linemap_StartFile (void *filename, unsigned int linebegin)
+{
+  if (inFile)
+m2linemap_EndFile ();
+  linemap_add (line_table, LC_ENTER, false,
+   xstrdup (reinterpret_cast (filename)), linebegin);
+  inFile = TRUE;
+}
+
+/* Tell the line table the file has ended.  */
+
+EXTERN
+void
+m2linemap_EndFile (void)
+{
+  linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
+  inFile = FALSE;
+}
+
+/* Indicate that there is a new source file line number with a
+   maximum width.  */
+
+EXTERN
+void
+m2linemap_StartLine (unsigned int linenumber, unsigned int linesize)
+{
+  linemap_line_start (line_table, linenumber, linesize);
+}
+
+/* GetLocationColumn, returns a location_t based on the current line
+   number and column.  */
+
+EXTERN
+location_t
+m2linemap_GetLocationColumn (unsigned int column)
+{
+  return linemap_position_for_column (line_table, column);
+}
+
+/* GetLocationRange, returns a location based on the start column
+   and end column.  */
+
+EXTERN
+location_t
+m2linemap_GetLocationRange (unsigned int start, unsigned int end)
+{
+  location_t caret = m2linemap_GetLocationColumn (start);
+
+  source_range where;
+  where.m_start = linemap_position_for_column (line_table, start);
+  where.m_finish = linemap_position_for_column (line_table, end);
+  return make_location (caret, where);
+}
+
+
+static
+int
+isSrcLocation (location_t location)
+{
+  return (location != BUILTINS_LOCATION) && (location != UNKNOWN_LOCATION);
+}
+
+
+/* GetLocationBinary, returns a location based on the expression
+   start caret finish locations.  */
+
+EXTERN
+location_t
+m2linemap_GetLocationBinary (location_t caret, location_t start, location_t 
finish)
+{
+  if (isSrcLocation (start) && isSrcLocation (finish) && isSrcLocation (caret)
+&& (m2linemap_GetFilenameFromLocation (start) != NULL))
+{
+  linemap_add (line_table, LC_ENTER, false, xstrdup 
(m2linemap_GetFilenameFromLocation (start)), 1);
+  gcc_assert (inFile);
+  location_t location = make_location (caret, start, finish);
+  return location;
+}
+  return caret;
+}
+
+/* GetLineNoFromLocation - returns the lineno given a location.  */
+
+EXTERN
+int
+m2linemap_GetLineNoFromLocation (location_t location)
+{
+  if (isSrcLocation (location) && (!M2Options_GetCpp ()))
+{
+  expanded_location xl = expand_location (location);
+  return xl.line;
+}
+  return 0;
+}
+
+/* GetColumnNoFromLocation - returns the columnno given a location.  */
+
+EXTERN
+int
+m2linemap_GetColumnNoFromLocation (location_t location)
+{
+  if (isSrcLocation (location) && (!M2Options_GetCpp ()))
+{
+  expanded_location xl = expand_location (location);
+  return xl.column;
+}
+  return 0;
+}
+
+/* GetFilenameFromLocation - returns the filename given a location.  */
+
+EXTERN
+const char *
+m2linemap_GetFilenameFromLocation (location_t location)
+{
+  if (isSrcLocation (location) && (!M2Options_GetCpp ()))
+{
+  expanded_location xl = expand_location (location);
+  return xl.file;
+}
+  return NULL;
+}
+
+/* ErrorAt - issue an error message.  */
+
+EXTERN
+void
+m2linemap_ErrorAt (location_t location, char *message)
+{
+  error_at (location, message);
+}
+
+/* m2linemap_ErrorAtf - wraps up an error message.  */
+
+void
+m2linemap_ErrorAtf (locat

[PATCH] 17/19 modula2 front end: dejagnu expect library scripts

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

Here are the dejagnu expect library scripts for the gm2
testsuite.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/testsuite/lib/gm2.exp
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/testsuite/lib/gm2.exp 2022-10-07 
20:21:18.718097775 +0100
@@ -0,0 +1,498 @@
+# Copyright (C) 2003-2020 Free Software Foundation, Inc.
+
+# This program 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 was written by Gaius Mulley (gaius.mul...@southwales.ac.uk)
+# for GNU Modula-2.
+
+# we want to use libgloss so we can get find_gcc.
+load_lib libgloss.exp
+load_lib prune.exp
+load_lib gcc-defs.exp
+load_lib target-libpath.exp
+
+
+#
+# GCC_UNDER_TEST is the compiler under test.
+#
+
+#
+# default_gcc_version -- extract and print the version number of the compiler
+#
+
+proc default_gcc_version { } {
+global GCC_UNDER_TEST
+
+gm2_init;
+
+# ignore any arguments after the command
+set compiler [lindex $GCC_UNDER_TEST 0]
+
+if ![is_remote host] {
+   set compiler_name [which $compiler];
+} else {
+   set compiler_name $compiler;
+}
+
+# verify that the compiler exists
+if { $compiler_name != 0 } then {
+   set tmp [remote_exec host "$compiler --version"]
+   set status [lindex $tmp 0];
+   set output [lindex $tmp 1];
+   regexp "version.*$" $output version
+   if { $status == 0 && [info exists version] } then {
+   clone_output "$compiler_name $version\n"
+   } else {
+   clone_output "Couldn't determine version of $compiler_name: 
$output\n"
+   }
+} else {
+   # compiler does not exist (this should have already been detected)
+   warning "$compiler does not exist"
+}
+}
+
+#
+# gcc_version -- Call default_gcc_version, so we can override it if needed.
+#
+
+proc gcc_version { } {
+default_gcc_version;
+}
+
+#
+# gm2_init -- called at the start of each .exp script.
+#
+# There currently isn't much to do, but always using it allows us to
+# make some enhancements without having to go back and rewrite the scripts.
+#
+
+set gm2_initialized 0;
+set gm2_compile_method "default";
+set gm2_link_path "";
+set gm2_link_libraries "m2pim m2iso";
+set gm2_link_objects "";
+
+proc gm2_set_compile_method { arg } {
+global gm2_compile_method;
+
+send_log "\n"
+send_log " setting gm2_compile_method to $arg \n"
+send_log "\n"
+set gm2_compile_method $arg;
+}
+
+
+proc gm2_init { args } {
+global tmpdir;
+global objdir;
+global rootme;
+global base_dir;
+global tool_root_dir;
+global gluefile wrap_flags;
+global gm2_initialized;
+global GCC_UNDER_TEST;
+global TOOL_EXECUTABLE;
+global gm2_link_libraries;
+global gm2_link_objects;
+global gm2_link_path;
+global HAVE_LIBSTDCXX_V3;
+
+if { $gm2_initialized == 1 } { return; }
+
+set gm2_link_objects "";
+set GCC_UNDER_TEST [lookfor_file $rootme gm2];
+append GCC_UNDER_TEST " " -B[file dirname $rootme]/gcc " " ${args};
+append GCC_UNDER_TEST " " -fno-diagnostics-show-caret
+append GCC_UNDER_TEST " " -fno-diagnostics-show-line-numbers
+append GCC_UNDER_TEST " " -fdiagnostics-color=never
+send_log "GCC_UNDER_TEST is ${GCC_UNDER_TEST}\n"
+
+if ![info exists tmpdir] then {
+   set tmpdir /tmp;
+}
+if {[target_info needs_status_wrapper] != "" && \
+   [target_info needs_status_wrapper] != "0" && \
+   ![info exists gluefile]} {
+   set gluefile ${tmpdir}/gcc-testglue.o;
+   set result [build_wrapper $gluefile];
+   if { $result != "" } {
+   set gluefile [lindex $result 0];
+   set wrap_flags [lindex $result 1];
+   } else {
+   unset gluefile
+   }
+}
+
+set gm2_link_path "[gm2_link_flags [get_multilibs]]";
+verbose $gm2_link_path 1
+}
+
+#
+# gm2_target_compile_default -- compile a source file
+#
+
+proc gm2_target_compile_default { source dest type options } {
+global gluefile wrap_flags
+global GCC_UNDER_TEST
+global TOOL_OPTIONS
+global TEST_ALWAYS_FLAGS
+global gm2_link_objects
+global gm2_link_libraries
+global gm2_link_path
+
+if {[target_info needs_status_wrapp

[PATCH] 5/19 modula2 front end: libgm2/libm2iso contents

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the makefiles, autoconf sources necessary
to build the various libgm2/libm2iso libraries.  The c/c++/h files
are also included in the patch set.  The modula-2 sources are found
in gcc/m2.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2iso/wrapsock.c
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2iso/wrapsock.c2022-10-07 
20:21:18.738098020 +0100
@@ -0,0 +1,250 @@
+/* wrapsock.c provides access to socket related system calls.
+
+Copyright (C) 2008-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include "config.h"
+
+#if defined(HAVE_SYS_TYPES_H)
+#include "sys/types.h"
+#endif
+
+#if defined(HAVE_SYS_SOCKET_H)
+#include "sys/socket.h"
+#endif
+
+#if defined(HAVE_NETINET_IN_H)
+#include "netinet/in.h"
+#endif
+
+#if defined(HAVE_NETDB_H)
+#include "netdb.h"
+#endif
+
+#if defined(HAVE_UNISTD_H)
+#include "unistd.h"
+#endif
+
+#if defined(HAVE_SIGNAL_H)
+#include "signal.h"
+#endif
+
+#if defined(HAVE_SYS_ERRNO_H)
+#include "sys/errno.h"
+#endif
+
+#if defined(HAVE_ERRNO_H)
+#include "errno.h"
+#endif
+
+#if defined(HAVE_MALLOC_H)
+#include "malloc.h"
+#endif
+
+#if defined(HAVE_MALLOC_H)
+#include "signal.h"
+#endif
+
+#if defined(HAVE_STRING_H)
+#include "string.h"
+#endif
+
+#if defined(HAVE_STDLIB_H)
+#include "stdlib.h"
+#endif
+
+#if !defined(TRUE)
+#define TRUE (1 == 1)
+#endif
+#if !defined(FALSE)
+#define FALSE (1 == 0)
+#endif
+
+#include "ChanConsts.h"
+
+#define MAXHOSTNAME 1024
+#define MAXPBBUF 1024
+
+#if defined(HAVE_NETINET_IN_H)
+
+typedef struct
+{
+  char hostname[MAXHOSTNAME];
+  struct hostent *hp;
+  struct sockaddr_in sa;
+  int sockFd;
+  int portNo;
+  int hasChar;
+  char pbChar[MAXPBBUF];
+} clientInfo;
+
+static openResults clientConnect (clientInfo *c);
+
+/* clientOpen - returns an ISO Modula-2 OpenResult.  It attempts to
+   connect to: hostname:portNo.  If successful then the data
+   structure, c, will have its fields initialized.  */
+
+openResults
+wrapsock_clientOpen (clientInfo *c, char *hostname, unsigned int length,
+ int portNo)
+{
+  /* remove SIGPIPE which is raised on the server if the client is killed.  */
+  signal (SIGPIPE, SIG_IGN);
+
+  c->hp = gethostbyname (hostname);
+  if (c->hp == NULL)
+return noSuchFile;
+
+  memset ((void *)&c->sa, 0, sizeof (c->sa));
+  c->sa.sin_family = AF_INET;
+  memcpy ((void *)&c->sa.sin_addr, (void *)c->hp->h_addr, c->hp->h_length);
+  c->portNo = portNo;
+  c->sa.sin_port = htons (portNo);
+  c->hasChar = 0;
+  /* Open a TCP socket (an Internet stream socket) */
+
+  c->sockFd = socket (c->hp->h_addrtype, SOCK_STREAM, 0);
+  return clientConnect (c);
+}
+
+/* clientOpenIP - returns an ISO Modula-2 OpenResult.  It attempts to
+   connect to: ipaddress:portNo.  If successful then the data
+   structure, c, will have its fields initialized.  */
+
+openResults
+wrapsock_clientOpenIP (clientInfo *c, unsigned int ip, int portNo)
+{
+  /* remove SIGPIPE which is raised on the server if the client is killed.  */
+  signal (SIGPIPE, SIG_IGN);
+
+  memset ((void *)&c->sa, 0, sizeof (c->sa));
+  c->sa.sin_family = AF_INET;
+  memcpy ((void *)&c->sa.sin_addr, (void *)&ip, sizeof (ip));
+  c->portNo = portNo;
+  c->sa.sin_port = htons (portNo);
+
+  /* Open a TCP socket (an Internet stream socket) */
+
+  c->sockFd = socket (PF_INET, SOCK_STREAM, 0);
+  return clientConnect (c);
+}
+
+/* clientConnect - returns an ISO Modula-2 OpenResult once a connect
+   has been performed.  If successful the clientInfo will include the
+   file descriptor ready for read/write operations.  */
+
+static openResults
+clientConnect (clientInfo *c)
+{
+  if (connect (c->sockFd, (struct sockaddr *)&c->sa, sizeof (c->sa)) < 0)
+return noSuchFile;
+
+  return opened;
+}
+
+/* getClientPortNo - returns the portNo from structure, c.  */
+
+int
+wrapsock_getClientPortNo (clientInfo *c)
+{
+  return c->portNo;
+}
+
+/* getClientHos

[PATCH] 4/19 modula2 front end: libgm2/libm2pim contents

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the makefiles, autoconf sources necessary
to build the various libgm2/libm2pim libraries.  The c/c++/h files
are included in the patch set.  The modula-2 sources are found in
gcc/m2/ as they are used by the compiler.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2pim/target.c
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2pim/target.c  2022-10-07 
20:21:18.738098020 +0100
@@ -0,0 +1,61 @@
+/* target.c provide access to miscellaneous math functions.
+
+Copyright (C) 2005-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include 
+
+#if defined(HAVE_MATH_H)
+#include 
+#endif
+
+#if !defined(HAVE_EXP10)
+#if defined(M_LN10)
+double
+exp10 (double x)
+{
+  return exp (x * M_LN10);
+}
+#endif
+#endif
+
+#if !defined(HAVE_EXP10F)
+#if defined(M_LN10)
+float
+exp10f (float x)
+{
+  return expf (x * M_LN10);
+}
+#endif
+#endif
+
+#if !defined(HAVE_EXP10L)
+#if defined(M_LN10)
+long double
+exp10l (long double x)
+{
+  return expl (x * M_LN10);
+}
+#endif
+#endif
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2pim/Selective.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2pim/Selective.cc  2022-10-07 
20:21:18.738098020 +0100
@@ -0,0 +1,319 @@
+/* Selective.c provide access to timeval and select.
+
+Copyright (C) 2009-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include 
+#include 
+
+#if defined(HAVE_STDDEF_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_STDIO_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_SYS_TIME_H)
+#include 
+#endif
+
+#if defined(HAVE_TIME_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_STRING_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_WCHAR_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_STDLIB_H)
+/* Obtain a prototype for free and malloc.  */
+#include 
+#endif
+
+#if defined(HAVE_SYS_TYPES_H)
+#include 
+#endif
+
+#if defined(HAVE_UNISTD_H)
+#include 
+#endif
+
+#if !defined(NULL)
+#define NULL (void *)0
+#endif
+
+#if defined(HAVE_SELECT)
+#define FDSET_T fd_set
+#else
+#define FDSET_T void
+#endif
+
+/* Select wrap a call to the C select.  */
+
+#if defined(HAVE_STRUCT_TIMEVAL)
+extern "C" int
+Selective_Select (int nooffds, fd_set *readfds, fd_set *writefds,
+  fd_set *exceptfds, struct timeval *timeout)
+{
+  return select (nooffds, readfds, writefds, exceptfds, timeout);
+}
+#else
+extern "C" int
+Selective_Select (int nooffds, void *readfds, void *writefds, void *exceptfds,
+  void *timeout)
+{
+  return 0;
+}
+#endif
+
+/* InitTime initializes a timeval structure and returns a pointer to it.  */
+
+#if defined(HAVE_STRUCT_TIMEVAL)
+extern "C" struct timeval *
+Selective_InitTime (unsigned int sec, unsigned int usec)
+{
+  struct timeval *t = (struct timeval *)malloc (sizeof (struc

[PATCH] 11/19 modula2 front end: gimple interface *[a-d]*.cc

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the gimple interface.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2assert.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2assert.cc2022-10-07 
20:21:18.650096940 +0100
@@ -0,0 +1,41 @@
+/* m2assert.cc provides a simple assertion for location.
+
+Copyright (C) 2012-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "gcc-consolidation.h"
+
+#include "../gm2-lang.h"
+#include "../m2-tree.h"
+
+#define m2assert_c
+#include "m2assert.h"
+#include "m2options.h"
+
+void
+m2assert_AssertLocation (location_t location)
+{
+  /* Internally the compiler will use unknown location and
+ builtins_location so we ignore these values.  */
+  if (location == BUILTINS_LOCATION || location == UNKNOWN_LOCATION)
+return;
+
+  if (M2Options_OverrideLocation (location) != location)
+internal_error ("the location value is corrupt");
+}
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2block.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2block.cc 2022-10-07 
20:21:18.650096940 +0100
@@ -0,0 +1,770 @@
+/* m2block.cc provides an interface to maintaining block structures.
+
+Copyright (C) 2012-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "gcc-consolidation.h"
+
+#define m2block_c
+#include "m2assert.h"
+#include "m2block.h"
+#include "m2decl.h"
+#include "m2options.h"
+#include "m2tree.h"
+#include "m2treelib.h"
+
+/* For each binding contour we allocate a binding_level structure
+   which records the entities defined or declared in that contour.
+   Contours include:
+
+   the global one one for each subprogram definition
+
+   Binding contours are used to create GCC tree BLOCK nodes.  */
+
+struct GTY (()) binding_level
+{
+  /* The function associated with the scope.  This is NULL_TREE for the
+ global scope.  */
+  tree fndecl;
+
+  /* A chain of _DECL nodes for all variables, constants, functions,
+ and typedef types.  These are in the reverse of the order supplied.  */
+  tree names;
+
+  /* A boolean to indicate whether this is binding level is a global ie
+ outer module scope.  In which case fndecl will be NULL_TREE.  */
+  int is_global;
+
+  /* The context of the binding level, for a function binding level
+ this will be the same as fndecl, however for a global binding level
+ this is a translation_unit.  */
+  tree context;
+
+  /* The binding level below this one.  This field is only used when
+ the binding level has been pushed by pushFunctionScope.  */
+  struct binding_level *next;
+
+  /* All binding levels are placed onto this list.  */
+  struct binding_level *list;
+
+  /* A varray of trees, which represent the list of statement
+ sequences.  */
+  vec *m2_statements;
+
+  /* A list of constants (only kept in the global binding level).
+ Constants need to be kept through the life of the compilation, as the
+ same constants can be used in any scope.  */
+  tree constants;
+
+  /* A list of inner module initialization functions.  */
+  tree init_functions;
+
+  /* A list of types created by M2GCCDeclare prior to code generation
+ and those which may not be specifically declared and saved via a
+ push_decl.  */
+  tree types;
+
+  /* A list of all DECL_EXPR created within this binding level.  This
+ will be prepended to the statement list once the binding level (scope
+ is finished).  */
+  tree decl;
+
+  /* A list of labels which have bee

[PATCH] 16/19 modula2 front end: bootstrap and documentation tools

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set contains the bootstrap linking tool as well as python3
scripts to automatically generate texi libraries section of the gm2
documentation.  In the fullness of time this will be changed to emit
sphinx.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py 2022-10-07 
20:21:18.682097332 +0100
@@ -0,0 +1,184 @@
+#!/usr/bin/env python3
+
+# utility to tidy dates and detect lack of copyright.
+
+# Copyright (C) 2016-2022 Free Software Foundation, Inc.
+#
+# This file is part of GNU Modula-2.
+#
+# GNU Modula-2 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.
+#
+# GNU Modula-2 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 GNU Modula-2; see the file COPYING.  If not, write to the
+# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+import os, sys
+
+maxLineLength = 60
+
+
+#
+#  visitDir - call func for each file below, dir, matching extension, ext.
+#
+
+def visitDir (dir, ext, func):
+listOfFiles = os.listdir(dir)
+listOfFiles.sort()
+for file in listOfFiles:
+if os.path.isfile(os.path.join(dir, file)):
+l = len(ext)
+if (len(file)>l) and (file[-l:] == ext):
+func(os.path.join(dir, file))
+elif os.path.isdir(os.path.join(dir, file)):
+visitDir(os.path.join(dir, file), ext, func)
+
+#
+#  isYear - returns True if, year, is legal.
+#
+
+def isYear (year):
+if len(year)==5:
+year = year[:-1]
+for c in year:
+if not c.isdigit():
+return False
+return True
+
+
+#
+#  handleCopyright -
+#
+
+def handleCopyright (outfile, lines, n, leader1, leader2):
+global maxLineLength
+i = lines[n]
+c = i.find('Copyright (C) ')+len('Copyright (C)')
+outfile.write(i[:c])
+d = i[c:].split()
+start = c
+seenDate = True
+years = []
+while seenDate:
+if d == []:
+n += 1
+i = lines[n]
+d = i[2:].split()
+else:
+e = d[0]
+punctuation = ""
+if len(d)==1:
+d = []
+else:
+d = d[1:]
+
+if c>maxLineLength:
+outfile.write('\n')
+outfile.write(leader1)
+outfile.write(leader2)
+outfile.write(' '*(start-2))
+c = start
+
+if isYear(e):
+if (e[-1]=='.') or (e[-1]==','):
+punctuation = e[-1]
+e = e[:-1]
+else:
+punctuation = ""
+else:
+seenDate = False
+if seenDate:
+if not (e in years):
+c += len(e) + len(punctuation)
+outfile.write(' ')
+outfile.write(e)
+outfile.write(punctuation)
+years += [e]
+else:
+if start < c:
+outfile.write('\n')
+outfile.write(leader1)
+outfile.write(leader2)
+outfile.write(' '*(start-2))
+
+outfile.write(' ')
+outfile.write(e)
+outfile.write(punctuation)
+for w in d:
+outfile.write(' ')
+outfile.write(w)
+
+outfile.write('\n')
+return outfile, n+1
+
+#
+#  handleHeader - reads in the header of a file and inserts
+# a line break around the Copyright dates.
+#
+
+def handleHeader (file, leader1, leader2):
+print("--")
+l = open(file, 'r').readlines()
+if len(l)>20:
+outfile = open('tmptidy', 'w')
+n = 0
+for i in l:
+if i.find('Copyright (C)')>=0:
+outfile, n = handleCopyright(outfile, l, n, leader1, leader2)
+outfile.writelines(l[n:])
+outfile.close()
+print("-> mv tmptidy", file)
+command = "mv tmptidy %s" % file
+os.system(command)
+return
+else:
+outfile.write(l[n])
+n += 1
+outfile.close()
+sys.stdout.write("%s:1:1 needs a Copyright notice..\n" % file)
+
+
+#
+#  bashTidy - tidy up dates using '#' comment
+#
+
+def bashTidy

[PATCH] 15/19 modula2 front end: cc1gm2 additional non modula2 source files

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set contains the .h, .cc and .flex files found in
gcc/m2.  The files are tightly coupled with the gimple interface
(see 04-gimple-interface) and built using the rules found in
(01-03-make).

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-lang.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-lang.cc2022-10-07 20:21:18.650096940 
+0100
@@ -0,0 +1,938 @@
+/* gm2-lang.cc language-dependent hooks for GNU Modula-2.
+
+Copyright (C) 2002-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING.  If not, write to the
+Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
+
+#include "gm2-gcc/gcc-consolidation.h"
+
+#include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name.  */
+#include "tree-pass.h" /* FIXME: only for PROP_gimple_any.  */
+#include "toplev.h"
+#include "debug.h"
+
+#include "opts.h"
+
+#define GM2_LANG_C
+#include "gm2-lang.h"
+#include "m2block.h"
+#include "dynamicstrings.h"
+#include "m2options.h"
+#include "m2convert.h"
+#include "m2linemap.h"
+#include "init.h"
+#include "m2-tree.h"
+#include "convert.h"
+#include "rtegraph.h"
+
+static void write_globals (void);
+
+static int insideCppArgs = FALSE;
+
+#define EXPR_STMT_EXPR(NODE) TREE_OPERAND (EXPR_STMT_CHECK (NODE), 0)
+
+/* start of new stuff.  */
+
+/* Language-dependent contents of a type.  */
+
+struct GTY (()) lang_type
+{
+  char dummy;
+};
+
+/* Language-dependent contents of a decl.  */
+
+struct GTY (()) lang_decl
+{
+  char dummy;
+};
+
+/* Language-dependent contents of an identifier.  This must include a
+   tree_identifier.  */
+
+struct GTY (()) lang_identifier
+{
+  struct tree_identifier common;
+};
+
+/* The resulting tree type.  */
+
+union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
+chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), "
+"TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN "
+"(&%h.generic)) : NULL"))) lang_tree_node
+{
+  union tree_node GTY ((tag ("0"),
+desc ("tree_node_structure (&%h)"))) generic;
+  struct lang_identifier GTY ((tag ("1"))) identifier;
+};
+
+/* We don't use language_function.  */
+
+struct GTY (()) language_function
+{
+
+  /* While we are parsing the function, this contains information about
+  the statement-tree that we are building.  */
+  /* struct stmt_tree_s stmt_tree;  */
+  tree stmt_tree;
+};
+
+/* end of new stuff.  */
+
+/* Language hooks.  */
+
+bool
+gm2_langhook_init (void)
+{
+  build_common_tree_nodes (false);
+
+  /* I don't know why this has to be done explicitly.  */
+  void_list_node = build_tree_list (NULL_TREE, void_type_node);
+
+  build_common_builtin_nodes ();
+
+  /* The default precision for floating point numbers.  This is used
+ for floating point constants with abstract type.  This may eventually
+ be controllable by a command line option.  */
+  mpfr_set_default_prec (256);
+
+  /* GNU Modula-2 uses exceptions.  */
+  using_eh_for_cleanups ();
+
+  return true;
+}
+
+/* The option mask.  */
+
+static unsigned int
+gm2_langhook_option_lang_mask (void)
+{
+  return CL_ModulaX2;
+}
+
+/* Initialize the options structure.  */
+
+static void
+gm2_langhook_init_options_struct (struct gcc_options *opts)
+{
+  /* Default to avoiding range issues for complex multiply and divide.  */
+  opts->x_flag_complex_method = 2;
+
+  /* The builtin math functions should not set errno.  */
+  opts->x_flag_errno_math = 0;
+  opts->frontend_set_flag_errno_math = true;
+
+  /* Exceptions are used to handle recovering from panics.  */
+  opts->x_flag_exceptions = 1;
+  opts->x_flag_non_call_exceptions = 1;
+
+  init_FrontEndInit ();
+}
+
+/* Infrastructure for a VEC of bool values.  */
+
+/* This array determines whether the filename is associated with the
+   C preprocessor.  */
+
+static vec filename_cpp;
+
+void
+gm2_langhook_init_options (unsigned int decoded_options_count,
+   struct cl_decoded_option *decoded_options)
+{
+  unsigned int i;
+  bool in_cpp_args = false;
+
+  // filename_cpp = ggc_vec_alloc (decoded_options_count);
+
+  for (i = 1; i < decoded_options_count; i++)
+{
+  switch (decoded_options[i].opt_

Re: [RFC] Add support for vectors in comparisons (like the C++ frontend does)

2022-10-10 Thread Iain Sandoe
Hi Paul,

> On 10 Oct 2022, at 16:20, Paul Iannetta  wrote:

> On Mon, Oct 10, 2022 at 03:37:24PM +0100, Iain Sandoe wrote:
>> Hi Paul,
>> 
>> Not a review of the patch - but a couple of observations.
>> 
>>> On 10 Oct 2022, at 15:11, Paul Iannetta via Gcc-patches 
>>>  wrote:
>> 
>>> I am trying to bridge the gap between the extensions supported by the C
>>> and C++ front-ends.  When it comes to vector extensions, C++ supports
>>> vectors in comparisons and within conditional expressions whereas the C
>>> front-end does not.
>> 
>> Equivalence seems, on the face of it, a reasonable objective - but I am
>> curious as whether there is some more concrete motivation for the patch,
>> e.g. some codebase that currently does not work but would with this change?
>> 
> 
> The main motivation behind the equivalence is that, we have C and C++
> codebases, and it is not very convenient to have to remember which
> extension is allowed in C and not in C++ and vice-versa.  And, in this
> case, it makes it harder for GCC to generate conditional moves for
> code using vectors, especially since `a ? b : c` is not recognized,
> and thus, we cannot rely on the `VEC_COND_EXPR` construction.
> 
>>> I have a patch to bring this feature to the C front-end as well, and
>>> would like to hear your opinion on it, especially since it may affect
>>> the feature-set of the objc front-end as well.
>> 
>> Likewise, I am interested in the motivation for the ObjC change.  The usual
>> initial filter for consideration of functional changes (at least for the NeXT
>> runtime on Darwin) is “What does current clang do?” or, even better, “what
>> does current Xcode do?”.   There are several (possibly many) cases where
>> C in clang has extensions to C++ behaviour - and vice-versa (because there
>> is a single  front-end codebase, that happens easily, whether by design o
>> accident).
> 
> Well, the only motivation was that it was easier to make the change
> for both front-ends at the same time and avoided some checks.  I'll
> add them so that it won't introduce a divergence on what is accepted
> by the objc front-end.

I have no objection to GCC growing extensions to Objective-C (even ones that
clang does not have) provided that we check what clang does and (say under the
-pedantic flag) reject extensions that are not present there.  So there is no 
need
to back out of this - but some example codes that we can check would be useful. 

In general, extensions to the “standard” language would be behind some flag that
disables them when the “standard” version is selected - and gives 
warnings/errors
as appropriate for ‘-pedantic’.  So that, for example, -std=gnuCXX could enable 
the
extensions, but -std=CXX would complain.

thanks
Iain

> 
> Thanks,
> Paul
> 
>> 
>> The reason for the ‘clang litmus test’ is that the effective language 
>> standard
>> for ObjectiveC is determined by that compiler.
>> 
>> cheers
>> Iain
>> 
>>> I have tried to mirror as much as possible what the C++ front-end does
>>> and checked that both front-end produce the same GIMPLE for all the
>>> simple expressions as well as some more complex combinations of the
>>> operators (?:, !, ^, || and &&).
>>> 
>>> Currently, this is only a tentative patch and I did not add any tests
>>> to the testsuite.  Moreover, the aarch64's target-specific testsuite
>>> explicitly tests the non-presence of this feature, which will have to
>>> be removed.
>>> 
>>> I've run the testsuite on x86 and I've not seen any regressions.
>>> 
>>> Cheers,
>>> Paul
>>> 
>>> #  >8 
>>> Support for vector types in simple comparisons
>>> 
>>> gcc/
>>> 
>>> * doc/extend.texi: Remove the C++ mention, since both C and C++
>>>   support the all the mentioned features.
>>> 
>>> gcc/c/
>>> 
>>> * c-typeck.cc (build_unary_op): Add support for vector for the
>>>   unary exclamation mark.
>>> (build_conditional_expr): Add support for vector in conditional
>>> expressions.
>>> (build_binary_op): Add support for vector for &&, || and ^.
>>> (c_objc_common_truthvalue_conversion): Remove the special gards
>>> preventing vector types.
>>> 
>>> #  >8 
>>> diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
>>> index 17185fd3da4..03ade14cae9 100644
>>> --- a/gcc/c/c-typeck.cc
>>> +++ b/gcc/c/c-typeck.cc
>>> @@ -4536,12 +4536,15 @@ build_unary_op (location_t location, enum tree_code 
>>> code, tree xarg,
>>>case TRUTH_NOT_EXPR:
>>>  if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
>>>   && typecode != REAL_TYPE && typecode != POINTER_TYPE
>>> - && typecode != COMPLEX_TYPE)
>>> + && typecode != COMPLEX_TYPE && typecode != VECTOR_TYPE)
>>> {
>>>   error_at (location,
>>> "wrong type argument to unary exclamation mark");
>>>   return error_mark_node;
>>> }
>>> +  if (gnu_vector_type_p (TREE_TYPE (arg)))
>>> +   return build_binary_o

Re: [PATCH] Add new target hook: simplify_modecc_const.

2022-10-10 Thread H.J. Lu via Gcc-patches
On Thu, Jul 28, 2022 at 5:40 AM Richard Sandiford via Gcc-patches
 wrote:
>
> Seems this thread has become a bit heated, so I'll try to proceed
> with caution :-)
>
> In the below, I'll use "X-mode const_int" to mean "a const_int that
> is known from context to represent an X-mode value".  Of course,
> the const_int itself always stores VOIDmode.
>
> "Roger Sayle"  writes:
> > Hi Segher,
> > It's very important to distinguish the invariants that exist for the RTL
> > data structures as held in memory (rtx), vs. the use of "enum rtx_code"s,
> > "machine_mode"s and operands in the various processing functions
> > of the middle-end.
>
> FWIW, I agree this distinction is important, with the proviso (which
> I think you were also adding) that the code never loses track of what
> mode an rtx operand (stored in a variable) actually has/is being
> interpreted to have.
>
> In other words, the reason (zero_extend (const_int N)) is invalid is
> not that constant integers can't be extended in principle (of course
> they can).  It's invalid because we've lost track of how many bits
> that N actually has.  That problem doesn't apply in contexts where
> the operation is described using individual variables (rather than
> a single rtx) *provided that* one of those variables says what mode
> any potential const_ints actually represent.
>
> > Yes, it's very true that RTL integer constants don't specify a mode
> > (are VOIDmode), so therefore operations like ZERO_EXTEND or EQ
> > don't make sense with all constant operands.  This is (one reason)
> > why constant-only operands are disallowed from RTL (data structures),
> > and why in APIs that perform/simplify these operations, the original
> > operand mode (of the const_int(s)) must be/is always passed as a
> > parameter.
> >
> > Hence, for say simplify_const_binary_operation, op0 and op1 can
> > both be const_int, as the mode argument specifies the mode of the
> > "code" operation. Likewise, in simplify_relational_operation, both
> > op0 and op1 may be CONST_INT as "cmp_mode" explicitly specifies
> > the mode that the operation is performed in and "mode" specifies
> > the mode of the result.
>
> And the mode argument to simplify_const_relational_operation specifies
> the mode of the operands, not the mode of the result.  I.e. it specifies
> the modes of op0 and op1 rather than the mode that would be attached to
> the code in "(code:mode ...)" if an rtx were created with these parameters.
>
> That confused me when I saw the patch initially.  Elsewhere in the
> file "mode" tends to be the mode of the result, in cases where the
> mode of the result can be different from the modes of the operands,
> so using it for the mode of the operands seems a bit confusing
> (not your fault of course).
>
> I still struggle with the idea of having CC-mode const_ints though
> (using the meaning of "CC-mode const_ints" above).  I realise
> (compare (...) (const_int 0)) has been the norm "for ever", but here
> it feels like we're also blessing non-zero CC-mode const_ints.
> That raises the question of how many significant bits a CC-mode
> const_int actually has.  Currently:
>
>  ...  For historical reasons,
>  the size of a CC mode is four units.
>
> But treating CC-mode const_ints as having 32 significant bits is surely
> the wrong thing to do.
>
> So if we want to add more interpretation around CC modes, I think we
> should first clean up the representation to make the set of valid values
> more explicit.  (Preferably without reusing const_int for constant values,
> but that's probably a losing battle :-))
>
> Thanks,
> Richard

Here is a testcase to show that combine generates

(set (reg:CCC 17 flags)
   (ltu:SI (const_int 1 [1])
 (const_int 0 [0])))

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

This new target hook handles it properly.

-- 
H.J.


Re: Adding a new thread model to GCC

2022-10-10 Thread LIU Hao via Gcc-patches

在 2022-10-04 20:44, LIU Hao 写道:

Attached are revised patches. These are exported from trunk.



Revised further. The patch for libgfortran has been committed to trunk today, so I include only the 
other two.


  * In the second patch, a space character has been inserted after
`(int)` for clearness.

  * The macro controlling how to build GCC itself has been renamed to
`TARGET_USING_MCFGTHREAD` for consistency.

  * Checks against `TARGET_USING_MCFGTHREAD` have been updated in a
more friendly way.

  * When not using mcfgthread, NTDLL is no longer a default library.
Although all recent Windows versions are based on the NT kernel,
there could still be people who want to target 9x or CE; thus
NTDLL is only added when it is potentially necessary, for example
when linking against the static libgcc.



--
Best regards,
LIU Hao

From b371849927adba290d1e17e2a43866cc3465eb4c Mon Sep 17 00:00:00 2001
From: LIU Hao 
Date: Sun, 2 Oct 2022 00:57:08 +0800
Subject: [PATCH 1/2] libstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows

This makes `std::thread::hardware_concurrency()` return the number of
logical processors, instead of zero.

libstdc++-v3/ChangeLog:
* src/c++11/thread.cc (get_nprocs): Add new implementation
for native Windows targets
---
 libstdc++-v3/src/c++11/thread.cc | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
index 707a4ad415b9..a54bc3e939a0 100644
--- a/libstdc++-v3/src/c++11/thread.cc
+++ b/libstdc++-v3/src/c++11/thread.cc
@@ -68,6 +68,15 @@ static inline int get_nprocs()
 #elif defined(_GLIBCXX_USE_SC_NPROC_ONLN)
 # include 
 # define _GLIBCXX_NPROCS sysconf(_SC_NPROC_ONLN)
+#elif defined(_WIN32)
+# include 
+static inline int get_nprocs()
+{
+  SYSTEM_INFO sysinfo;
+  GetSystemInfo(&sysinfo);
+  return (int) sysinfo.dwNumberOfProcessors;
+}
+# define _GLIBCXX_NPROCS get_nprocs()
 #else
 # define _GLIBCXX_NPROCS 0
 #endif
-- 
2.37.3

From 5df9fa2b8d6ea3c357e7a9fcd42721811ea376ce Mon Sep 17 00:00:00 2001
From: LIU Hao 
Date: Sat, 16 Apr 2022 00:46:23 +0800
Subject: [PATCH 2/2] gcc: Add 'mcf' thread model support from mcfgthread

This patch adds the new thread model `mcf`, which implements mutexes
and condition variables with the mcfgthread library.

Source code for mcfgthread is available at 
.

config/ChangeLog:
* gthr.m4 (GCC_AC_THREAD_HEADER): Add new case for `mcf` thread
model

gcc/config/ChangeLog:
* i386/mingw-mcfgthread.h: New file
* i386/mingw32.h: Add builtin macro and default libraries for
mcfgthread when thread model is `mcf`

gcc/ChangeLog:
* config.gcc: Include 'i386/mingw-mcfgthread.h' when thread model
is `mcf`
* configure.ac: Recognize `mcf` as a valid thread model

libatomic/ChangeLog:
* configure.tgt: Add new case for `mcf` thread model

libgcc/ChangeLog:
* config.host: Add new cases for `mcf` thread model
* config/i386/gthr-mcf.h: New file
* config/i386/t-mingw-mcfgthread: New file
* config/i386/t-slibgcc-cygming: Add mcfgthread for libgcc DLL

libstdc++-v3/ChangeLog:
* libsupc++/atexit_thread.cc (__cxa_thread_atexit): Use
implementation from mcfgthread if available
* libsupc++/guard.cc (__cxa_guard_acquire, __cxa_guard_release,
__cxa_guard_abort): Use implementations from mcfgthread if
available
---
 config/gthr.m4  |  1 +
 gcc/config.gcc  |  3 +++
 gcc/config/i386/mingw-mcfgthread.h  |  1 +
 gcc/config/i386/mingw32.h   | 13 ++-
 gcc/configure.ac|  2 +-
 libatomic/configure.tgt |  2 +-
 libgcc/config.host  |  6 +
 libgcc/config/i386/gthr-mcf.h   |  1 +
 libgcc/config/i386/t-mingw-mcfgthread   |  1 +
 libgcc/config/i386/t-slibgcc-cygming|  6 -
 libstdc++-v3/libsupc++/atexit_thread.cc | 20 
 libstdc++-v3/libsupc++/guard.cc | 31 +
 12 files changed, 83 insertions(+), 4 deletions(-)
 create mode 100644 gcc/config/i386/mingw-mcfgthread.h
 create mode 100644 libgcc/config/i386/gthr-mcf.h
 create mode 100644 libgcc/config/i386/t-mingw-mcfgthread

diff --git a/config/gthr.m4 b/config/gthr.m4
index 4b937306ad08..11996247f150 100644
--- a/config/gthr.m4
+++ b/config/gthr.m4
@@ -22,6 +22,7 @@ case $1 in
 tpf)   thread_header=config/s390/gthr-tpf.h ;;
 vxworks)   thread_header=config/gthr-vxworks.h ;;
 win32) thread_header=config/i386/gthr-win32.h ;;
+mcf)   thread_header=config/i386/gthr-mcf.h ;;
 esac
 AC_SUBST(thread_header)
 ])
diff --git a/gcc/config.gcc b/gcc/config.gcc
index eec544ff1bac..1f6adea1ab9b 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2091,6 +2091,9 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
if test x$enable_threads = xposix 

[patch] configury support for VxWorks shared libraries

2022-10-10 Thread Olivier Hainque via Gcc-patches
Hello,

This change introduces configury infrastructure allowing the
production of shared libraries for VxWorks, amenable to use with
non-static rtps (linked with "-non-static").

The ability to produce PIC code is not a given on all VxWorks
configurations, so activating this has to be explicitly requested
by configuring with  --enable-shared
(https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602523.html).

This requirement is then leveraged to factorize the configuration
processing in a mostly cpu independant manner, which makes maintenance
a lot easier.

When activated, shared libs are built for the rtp mode only
(the only kind of entity for which they are supported by the
VxWorks environment), for code model != large at this stage as
large and PIC still don't play well together.

We have been using this for about a year with gcc-11 based toolchains,
with support activated for aarch64, x86_64 and ppc64-vxworks7r2, and
not activated for the corresponding 32bit variants (arm, i686, ppc).
Aarch64 proved an interesting challenge with the gcc/gcc_eh split
for lse features.

I obtained good test results with a gcc-12 based compiler for ppc64
and could get a successful sanity check build with mainline for that
cpu as well.

Will commit to mainline shortly.

Cheers,

Olivier

2022-10-09  Olivier Hainque  

gcc/
* config.gcc (*vxworks*): Add t-slibgcc fragment
if enable_shared.

libgcc/
* config.host (*vxworks*): When enable_shared, add
libgcc and crtstuff "shared" fragments for rtp except
large code model.
(aarch64*-wrs-vxworks7*): Remove t-slibgcc-libgcc from
the list of fragments.

toplevel/
* libtool.m4 (*vxworks*): When enable_shared, set dynamic_linker
and friends for rtp !large. Assume the linker has the required
abilities and set lt_cv_deplibs_check_method.


Then, regenerating configure scripts to reflect the libtool.m4 update.

2022-10-09  Olivier Hainque  

gcc/
* configure: Regenerate.

libatomic/
* configure: Regenerate.
 
libbacktrace/
* configure: Regenerate.

libcc1/
* configure: Regenerate.

libffi/
* configure: Regenerate.
  
libgfortran/
* configure: Regenerate.

libgomp/
* configure: Regenerate.
 
libitm/
* configure: Regenerate.

libobjc/
* configure: Regenerate.
   
liboffloadmic/
* configure: Regenerate.
   
liboffloadmic/
* plugin/configure: Regenerate.
   
libphobos/
* configure: Regenerate.

libquadmath/
* configure: Regenerate.

libsanitizer/
* configure: Regenerate.

libssp/
* configure: Regenerate.

libstdc++-v3/
* configure: Regenerate.

libvtv/
* configure: Regenerate.

lto-plugin/
* configure: Regenerate.

zlib/
* configure: Regenerate.



0002-Generic-configury-support-for-shared-libs-on-VxWorks.patch
Description: Binary data





Re: [PATCH v2] LoongArch: Libvtv add loongarch support.

2022-10-10 Thread Caroline Tice via Gcc-patches
On Tue, Sep 27, 2022 at 3:04 AM Lulu Cheng  wrote:

>
> v1 - > v2:
>
> 1. When the macro __loongarch_lp64 is defined, the VTV_PAGE_SIZE is set to
> 64K.
> 2. In the vtv_malloc.cc file __vtv_malloc_init function, it does not check
>whether VTV_PAGE_SIZE is equal to the system page size, if the macro
>__loongarch_lp64 is defined.
>
> All regression tests of libvtv passed.
>
> === libvtv Summary ===
>
> # of expected passes176
>
> But I haven't tested the performance yet.
>
> ---
> Co-Authored-By: qijingwen 
>
> include/ChangeLog:
>
> * vtv-change-permission.h (defined):
> (VTV_PAGE_SIZE): Under the loongarch64 architecture,
> set VTV_PAGE_SIZE to 64K.
>
> libvtv/ChangeLog:
>
> * configure.tgt: Add loongarch support.
> * vtv_malloc.cc (defined): If macro __loongarch_lp64 is
> defined, then don't check whether VTV_PAGE_SIZE is the
> same as the system page size.
> ---
>  include/vtv-change-permission.h | 4 
>  libvtv/configure.tgt| 3 +++
>  libvtv/vtv_malloc.cc| 5 +
>  3 files changed, 12 insertions(+)
>
> diff --git a/include/vtv-change-permission.h
> b/include/vtv-change-permission.h
> index 70bdad92bca..64e419c29d5 100644
> --- a/include/vtv-change-permission.h
> +++ b/include/vtv-change-permission.h
> @@ -48,6 +48,10 @@ extern void __VLTChangePermission (int);
>  #else
>  #if defined(__sun__) && defined(__svr4__) && defined(__sparc__)
>  #define VTV_PAGE_SIZE 8192
> +/* LoongArch architecture 64-bit system supports 4k,16k and 64k
> +   page size, which is set to the maximum value here.  */
> +#elif defined(__loongarch_lp64)
> +#define VTV_PAGE_SIZE 65536
>  #else
>  #define VTV_PAGE_SIZE 4096
>  #endif
> diff --git a/libvtv/configure.tgt b/libvtv/configure.tgt
> index aa2a3f675b8..6cdd1e97ab1 100644
> --- a/libvtv/configure.tgt
> +++ b/libvtv/configure.tgt
> @@ -50,6 +50,9 @@ case "${target}" in
> ;;
>x86_64-*-darwin[1]* | i?86-*-darwin[1]*)
> ;;
> +  loongarch*-*-linux*)
> +   VTV_SUPPORTED=yes
> +   ;;
>*)
> ;;
>  esac
> diff --git a/libvtv/vtv_malloc.cc b/libvtv/vtv_malloc.cc
> index 67c5de6d4e9..45804b8d7f8 100644
> --- a/libvtv/vtv_malloc.cc
> +++ b/libvtv/vtv_malloc.cc
> @@ -212,6 +212,11 @@ __vtv_malloc_init (void)
>
>  #if defined (__CYGWIN__) || defined (__MINGW32__)
>if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE())
> +#elif defined (__loongarch_lp64)
> +  /* I think that under the LoongArch 64-bit system, VTV_PAGE_SIZE is set
> + to the maximum value of 64K supported by the system, so there is no
> + need to judge here.  */
> +  if (false)
>  #else
>if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE))
>

Is "if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE))" going to fail for
loongarch?  If not, why do you need to insert anything here at all?  If so,
perhaps you could write something similar to sysconf_SC_PAGE_SIZE for
loongarch (as was done for __CYGWIN__ & __MINGW32__)?

-- Caroline
cmt...@google.com



>  #endif
> --
> 2.31.1
>
>


Re: [patch] configury support for VxWorks shared libraries

2022-10-10 Thread Olivier Hainque via Gcc-patches
Sorry, I forgot to cc libstdc++ on 

  https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603182.html

which includes a regen of libstdc++-v3/configure after an update
libtool.m4.

Not committed yet.

With Kind Regards,

Olivier


> On 10 Oct 2022, at 19:05, Olivier Hainque  wrote:
> 
> Hello,
> 
> This change introduces configury infrastructure allowing the
> production of shared libraries for VxWorks, amenable to use with
> non-static rtps (linked with "-non-static").
> 
> The ability to produce PIC code is not a given on all VxWorks
> configurations, so activating this has to be explicitly requested
> by configuring with  --enable-shared
> (https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602523.html).
> 
> This requirement is then leveraged to factorize the configuration
> processing in a mostly cpu independant manner, which makes maintenance
> a lot easier.
> 
> When activated, shared libs are built for the rtp mode only
> (the only kind of entity for which they are supported by the
> VxWorks environment), for code model != large at this stage as
> large and PIC still don't play well together.
> 
> We have been using this for about a year with gcc-11 based toolchains,
> with support activated for aarch64, x86_64 and ppc64-vxworks7r2, and
> not activated for the corresponding 32bit variants (arm, i686, ppc).
> Aarch64 proved an interesting challenge with the gcc/gcc_eh split
> for lse features.
> 
> I obtained good test results with a gcc-12 based compiler for ppc64
> and could get a successful sanity check build with mainline for that
> cpu as well.
> 
> Will commit to mainline shortly.
> 
> Cheers,
> 
> Olivier
> 
> 2022-10-09  Olivier Hainque  
> 
> gcc/
>* config.gcc (*vxworks*): Add t-slibgcc fragment
>if enable_shared.
> 
> libgcc/
>* config.host (*vxworks*): When enable_shared, add
>libgcc and crtstuff "shared" fragments for rtp except
>large code model.
>(aarch64*-wrs-vxworks7*): Remove t-slibgcc-libgcc from
>the list of fragments.
> 
> toplevel/
>* libtool.m4 (*vxworks*): When enable_shared, set dynamic_linker
>and friends for rtp !large. Assume the linker has the required
>abilities and set lt_cv_deplibs_check_method.
> 
> 
> Then, regenerating configure scripts to reflect the libtool.m4 update.
> 
> 2022-10-09  Olivier Hainque  
> 
> gcc/
>* configure: Regenerate.
> 
> libatomic/
>* configure: Regenerate.
> 
> libbacktrace/
>* configure: Regenerate.
> 
> libcc1/
>* configure: Regenerate.
> 
> libffi/
>* configure: Regenerate.
> 
> libgfortran/
>* configure: Regenerate.
> 
> libgomp/
>* configure: Regenerate.
> 
> libitm/
>* configure: Regenerate.
> 
> libobjc/
>* configure: Regenerate.
> 
> liboffloadmic/
>* configure: Regenerate.
> 
> liboffloadmic/
>* plugin/configure: Regenerate.
> 
> libphobos/
>* configure: Regenerate.
> 
> libquadmath/
>* configure: Regenerate.
> 
> libsanitizer/
>* configure: Regenerate.
> 
> libssp/
>* configure: Regenerate.
> 
> libstdc++-v3/
>* configure: Regenerate.
> 
> libvtv/
>* configure: Regenerate.
> 
> lto-plugin/
>* configure: Regenerate.
> 
> zlib/
>* configure: Regenerate.
> 
> <0002-Generic-configury-support-for-shared-libs-on-VxWorks.patch>
> 
> 



Ping: [PATCH] elf: ELF toolchain --without-{headers, newlib} should provide stdint.h

2022-10-10 Thread Arsen Arsenović via Gcc-patches
Evening,

Ping on this patch, it should fix some configuration issues we get on 
ELF targets (especially in libstdc++).

https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602751.html

Thanks,
-- 
Arsen Arsenović


signature.asc
Description: This is a digitally signed message part.


[PATCH] Avoid calling tracer.trailer() twice.

2022-10-10 Thread Aldy Hernandez via Gcc-patches
[Andrew, you OK with this?  I can't tell whether the trailer() call was
actually needed.]

logical_combine is calling tracer.trailer() one too many times causing
the second trailer() call to subtract a 0 indent by 2, yielding an
indent of SOMETHING_REALLY_BIG :).  You'd be surprised how many tools
can't handle incredibly long lines.

gcc/ChangeLog:

* gimple-range-gori.cc (gori_compute::logical_combine): Avoid
calling tracer.trailer().
---
 gcc/gimple-range-gori.cc | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index b37d03cddda..469382aa477 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -798,20 +798,12 @@ gori_compute::logical_combine (vrange &r, enum tree_code 
code,
   // would be lost.
   if (!range_is_either_true_or_false (lhs))
 {
-  bool res;
   Value_Range r1 (r);
   if (logical_combine (r1, code, m_bool_zero, op1_true, op1_false,
   op2_true, op2_false)
  && logical_combine (r, code, m_bool_one, op1_true, op1_false,
  op2_true, op2_false))
-   {
- r.union_ (r1);
- res = true;
-   }
-  else
-   res = false;
-  if (idx)
-   tracer.trailer (idx, "logical_combine", res, NULL_TREE, r);
+   r.union_ (r1);
 }
 
   switch (code)
-- 
2.37.3



Re: [PATCH v2 0/9] fortran: clobber fixes [PR41453]

2022-10-10 Thread Mikael Morin

Le 23/09/2022 à 09:54, Mikael Morin a écrit :

Le 22/09/2022 à 22:42, Harald Anlauf via Fortran a écrit :

This LGTM.  It also fixes a regression introduced with r9-3030 :-)
If you think that this set (1-3) is backportable, feel free to do so.


Yes, 2 and 3 are worth backporting, I will see how dependent they are on 1.


I'm going to backport 1-3 as you suggested, it's so much easier.


[PATCH v5] c-family: ICE with [[gnu::nocf_check]] [PR106937]

2022-10-10 Thread Marek Polacek via Gcc-patches
On Mon, Oct 10, 2022 at 10:49:34AM -0400, Jason Merrill wrote:
> On 10/7/22 18:16, Marek Polacek wrote:
> > On Fri, Oct 07, 2022 at 05:56:18PM -0400, Jason Merrill wrote:
> > > On 10/7/22 17:08, Marek Polacek wrote:
> > > > On Fri, Oct 07, 2022 at 12:17:34PM -0400, Jason Merrill wrote:
> > > > > On 10/6/22 22:12, Marek Polacek wrote:
> > > > > > On Thu, Oct 06, 2022 at 05:42:41PM -0400, Jason Merrill wrote:
> > > > > > > On 10/4/22 19:06, Marek Polacek wrote:
> > > > > > > > On Fri, Sep 30, 2022 at 09:12:24AM -0400, Jason Merrill wrote:
> > > > > > > > > On 9/29/22 18:49, Marek Polacek wrote:
> > > > > > > > > > When getting the name of an attribute, we ought to use
> > > > > > > > > > get_attribute_name, which handles both [[ ]] and 
> > > > > > > > > > __attribute__(())
> > > > > > > > > > forms.  Failure to do so may result in an ICE, like here.
> > > > > > > > > > 
> > > > > > > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > > > > > > > > 
> > > > > > > > > How do we print the attributes with this patch?  Don't we 
> > > > > > > > > also want to print
> > > > > > > > > the namespace, and use [[]] in the output?
> > > > > > > > 
> > > > > > > > Good point, however: while the testcase indeed has an attribute
> > > > > > > > in the [[]] form in the typedef, here we're printing its "aka":
> > > > > > > > 
> > > > > > > > warning: initialization of 'FuncPointerWithNoCfCheck' {aka 
> > > > > > > > 'void (__attribute__((nocf_check)) *)(void)'} from incompatible 
> > > > > > > > pointer type 'FuncPointer' {aka 'void (*)(void)'}
> > > > > > > > 
> > > > > > > > c-pretty-print.cc doesn't seem to know how to print an [[]] 
> > > > > > > > attribute.
> > > > > > > > I could do that, but then we'd print
> > > > > > > > 
> > > > > > > >   aka 'void ([[nocf_check]] *)(void)'
> > > > > > > > 
> > > > > > > > in the above, but that's invalid syntax!
> > > > > > > 
> > > > > > > Indeed, it should be
> > > > > > > 
> > > > > > > void (* [[gnu::nocf_check]])(void)
> > > > > > 
> > > > > > Ok, let me fix that too, then.  I've updated the description to show
> > > > > > what we print with the patch, and what was printed before.
> > > > > 
> > > > > Oops, apparently I was wrongly assuming that the attribute 
> > > > > appertained to
> > > > > the pointer.
> > > > 
> > > > So was I :/.
> > > > 
> > > > > Since it actually appertains to the function type, it should
> > > > > be
> > > > > 
> > > > >void (*)(void) [[gnu::nocf_check]].
> > > > > 
> > > > > But for GCC attribute syntax, I think we want to leave the 
> > > > > __attribute__
> > > > > where it was before, as in the manual's example
> > > > > 
> > > > >void (__attribute__((noreturn)) f) (void);
> > > > 
> > > > Thanks, done here:
> > > > 
> > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > > > 
> > > > -- >8 --
> > > > When getting the name of an attribute, we ought to use
> > > > get_attribute_name, which handles both [[]] and __attribute__(())
> > > > forms.  Failure to do so may result in an ICE, like here.
> > > > 
> > > > pp_c_attributes_display wasn't able to print the [[]] form of
> > > > attributes, so this patch teaches it to.
> > > > 
> > > > When printing a pointer to function with a standard attribute, the 
> > > > attribute
> > > > should be printed after the parameter-list.  With this patch we print:
> > > > 
> > > > aka 'void (*)(int) [[gnu::nocf_check]]'
> > > > 
> > > > pp_c_attributes has been unused since its introduction in r56273 so
> > > > this patch removes it.
> > > > 
> > > > PR c++/106937
> > > > 
> > > > gcc/c-family/ChangeLog:
> > > > 
> > > > * c-pretty-print.cc (pp_c_specifier_qualifier_list): Only print
> > > > GNU attributes here.
> > > > (c_pretty_printer::abstract_declarator): For a pointer to 
> > > > function,
> > > > print the standard [[]] attributes here.
> > > > (pp_c_attributes): Remove.
> > > > (pp_c_attributes_display): Print the [[]] form if appropriate.  
> > > > Use
> > > > get_attribute_name.  Don't print a trailing space when printing 
> > > > the
> > > > [[]] form.
> > > > * c-pretty-print.h (pp_c_attributes): Remove.
> > > > 
> > > > gcc/cp/ChangeLog:
> > > > 
> > > > * error.cc: Include "attribs.h".
> > > > (dump_type_prefix): Only print GNU attributes here.
> > > > (dump_type_suffix): Print standard attributes here.
> > > > 
> > > > gcc/testsuite/ChangeLog:
> > > > 
> > > > * c-c++-common/pointer-to-fn1.c: New test.
> > > > ---
> > > >gcc/c-family/c-pretty-print.cc  | 102 
> > > > +++-
> > > >gcc/c-family/c-pretty-print.h   |   1 -
> > > >gcc/cp/error.cc |  17 +++-
> > > >gcc/testsuite/c-c++-common/pointer-to-fn1.c |  18 
> > > >4 files changed, 92 insertions(+), 46 deletions(-)
> > > >create mode 100644 gcc/testsuite/c-c++-common/pointer-t

Re: [PATCH] c++: Remove maybe-rvalue OR in implicit move

2022-10-10 Thread Marek Polacek via Gcc-patches
Ping.

On Wed, Sep 28, 2022 at 05:26:34PM -0400, Marek Polacek via Gcc-patches wrote:
> This patch removes the two-stage overload resolution when performing
> implicit move, whereby the compiler does two separate overload resolutions:
> one treating the operand as an rvalue, and then (if that resolution fails)
> another one treating the operand as an lvalue.  In the standard this was
> introduced via CWG 1579 and implemented in gcc in r251035.  In r11-2412,
> we disabled the fallback OR in C++20 (but not in C++17).  Then C++23 P2266
> removed the fallback overload resolution, and changed the implicit move rules
> once again.  So we wound up with three different behaviors.
> 
> The two overload resolutions approach was complicated and quirky, so
> users should transition to the newer model.  Removing the maybe-rvalue
> OR also allows us to simplify our code, for instance, now we can get
> rid of LOOKUP_PREFER_RVALUE altogether.
> 
> This change means that code that previously didn't compile in C++17 will
> now compile, for example:
> 
>   struct S1 { S1(S1 &&); };
>   struct S2 : S1 {};
> 
>   S1
>   f (S2 s)
>   {
> return s; // OK, derived-to-base, use S1::S1(S1&&)
>   }
> 
> And conversely, code that used to work in C++17 may not compile anymore:
> 
>   struct W {
> W();
>   };
> 
>   struct F {
> F(W&);
> F(W&&) = delete;
>   };
> 
>   F fn ()
>   {
> W w;
> return w; // use w as rvalue -> use of deleted function F::F(W&&)
>   }
> 
> I plan to add a note to porting_to.html.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> gcc/cp/ChangeLog:
> 
>   * call.cc (standard_conversion): Remove LOOKUP_PREFER_RVALUE code.
>   (reference_binding): Honor clk_implicit_rval even pre-C++20.
>   (implicit_conversion_1): Remove LOOKUP_PREFER_RVALUE code.
>   (build_user_type_conversion_1): Likewise.
>   (convert_like_internal): Likewise.
>   (build_over_call): Likewise.
>   * cp-tree.h (LOOKUP_PREFER_RVALUE): Remove.
>   (LOOKUP_NO_NARROWING): Adjust definition.
>   * except.cc (build_throw): Don't perform two overload resolutions.
>   * typeck.cc (maybe_warn_pessimizing_move): Don't use
>   LOOKUP_PREFER_RVALUE.
>   (check_return_expr): Don't perform two overload resolutions.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.dg/cpp0x/Wredundant-move10.C: Adjust dg-warning.
>   * g++.dg/cpp0x/Wredundant-move7.C: Likewise.
>   * g++.dg/cpp0x/move-return2.C: Remove dg-error.
>   * g++.dg/cpp0x/move-return4.C: Likewise.
>   * g++.dg/cpp0x/ref-qual20.C: Adjust expected return value.
>   * g++.dg/cpp0x/move-return5.C: New test.
> ---
>  gcc/cp/call.cc| 41 ++-
>  gcc/cp/cp-tree.h  |  6 +--
>  gcc/cp/except.cc  | 23 ++-
>  gcc/cp/typeck.cc  | 34 +++
>  .../g++.dg/cpp0x/Wredundant-move10.C  |  2 +-
>  gcc/testsuite/g++.dg/cpp0x/Wredundant-move7.C |  6 +--
>  gcc/testsuite/g++.dg/cpp0x/move-return2.C |  2 +-
>  gcc/testsuite/g++.dg/cpp0x/move-return4.C |  2 +-
>  gcc/testsuite/g++.dg/cpp0x/move-return5.C | 20 +
>  gcc/testsuite/g++.dg/cpp0x/ref-qual20.C   |  2 +-
>  10 files changed, 41 insertions(+), 97 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/cpp0x/move-return5.C
> 
> diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
> index 3506b0fcfbb..e100913ea29 100644
> --- a/gcc/cp/call.cc
> +++ b/gcc/cp/call.cc
> @@ -1272,9 +1272,6 @@ standard_conversion (tree to, tree from, tree expr, 
> bool c_cast_p,
>   }
>   }
>conv = build_conv (ck_rvalue, from, conv);
> -  if (flags & LOOKUP_PREFER_RVALUE)
> - /* Tell convert_like to set LOOKUP_PREFER_RVALUE.  */
> - conv->rvaluedness_matches_p = true;
>/* If we're performing copy-initialization, remember to skip
>explicit constructors.  */
>if (flags & LOOKUP_ONLYCONVERTING)
> @@ -1572,9 +1569,6 @@ standard_conversion (tree to, tree from, tree expr, 
> bool c_cast_p,
>type.  A temporary object is created to hold the result of
>the conversion unless we're binding directly to a reference.  */
>conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
> -  if (flags & LOOKUP_PREFER_RVALUE)
> - /* Tell convert_like to set LOOKUP_PREFER_RVALUE.  */
> - conv->rvaluedness_matches_p = true;
>/* If we're performing copy-initialization, remember to skip
>explicit constructors.  */
>if (flags & LOOKUP_ONLYCONVERTING)
> @@ -1883,7 +1877,7 @@ reference_binding (tree rto, tree rfrom, tree expr, 
> bool c_cast_p, int flags,
> /* Unless it's really a C++20 lvalue being treated as an xvalue.
>But in C++23, such an expression is just an xvalue, not a special
>lvalue, so the binding is once again ill-formed.  */
> -   && !(cxx_dialect == cxx20
> +   && !(cxx_dial

Re: [PATCH] c++: parser - Support for target address spaces in C++

2022-10-10 Thread Jason Merrill via Gcc-patches

On 10/9/22 12:12, Paul Iannetta wrote:

Hi,

On Thu, Oct 06, 2022 at 01:34:40PM -0400, Jason Merrill wrote:
[snip]


Hmm?  We mangle __restrict:

void f(int *__restrict *p) { } // _Z1fPrPi



Indeed, I have overlooked that point.  Thank you for pointing it out.


but cv-qualifiers (including restrict) are dropped on the top-level type of
a parameter.

If address spaces should be mangled, it probably makes sense to use the same
 mangling that we already use for attributes in
write_CV_qualifiers_for_type.



That's a nice feature! LLVM is using AS to mangle the
address-name qualified types but that would have required an update of
libiberty's demangler in the binutils as well.


And they haven't proposed this mangling to

  https://github.com/itanium-cxx-abi/cxx-abi/

yet, either.


Following your advice,
I implemented the mangling of address_names as U__address_name
(eg., U8__seg_fs), underscores may appear but that does not seem to be
a problem.

I don't think that there should be anything to do on the template
side, but I am no expert of what is expected of templates when it
comes to strip or forward qualifiers. So, please tell me if I
overlooked something on that side.


You certainly want some template tests, say

template 
int f (T *p) { return *p; }
__seg_fs int *a;
int main() { f(a); }
// test for mangling of f<__seg_fs int>

-

template 
int f (T __seg_gs *p) { return *p; }
__seg_fs int *a;
int main() { f(a); } // error, conflicting address spaces


Now concerning the meat of the patch itself.

The C part of the support of address spaces does not appear to have
dedicated tests, especially since it is mostly a target specific
feature.  I, however, added a few tests, one for the mangling,
and others which test the different error messages that might
appear when using address spaces in an unsafe way.

Most of the patch tries to mirror the commit
309434d678721acedb299f20cdc2b4778062b180
which introduces address spaces to the C front-end.  The C and C++
parsers share a lot but are subtly different so there might be some
discrepancies.  In particular, I ensure that address spaces do not
conflict, that only one address space can be specified at a time, and
that the type conversion mechanism pick the superset of the address
spaces if available. I also forbid address spaces in compound literals.

I have only tested the patch on x86 and on our not-yet-upstream
architecture, without seeing any regressions.

NB: I do not add a DSO for the moment because I have started the process of
assigning copyright to the FSF.

#  >8 
Add support for custom address spaces in C++

gcc/
 * tree.h (ENCODE_QUAL_ADDR_SPACE): Missing parentheses.

gcc/c/
 * c-decl.cc: Remove c_register_addr_space.

gcc/c-family/
 * c-common.cc (c_register_addr_space): Imported from c-decl.cc
 (addr_space_superset): Imported from gcc/c/c-typecheck.cc
 * c-common.h: Remove the FIXME.
 (addr_space_superset): Add prototype.

gcc/cp/
 * cp-tree.h (enum cp_decl_spec): Add addr_space support.
 (struct cp_decl_specifier_seq): Likewise.
 * decl.cc (get_type_quals): Likewise.
 (check_tag_decl): Likewise.
 * parser.cc (cp_parser_type_specifier): Likewise.
 (cp_parser_cv_qualifier_seq_opt): Likewise.
 (cp_parser_postfix_expression): Likewise.
 (cp_parser_type_specifier): Likewise.
 (set_and_check_decl_spec_loc): Likewise.
 * typeck.cc (composite_pointer_type): Likewise
 (comp_ptr_ttypes_real): Likewise.
 * tree.cc: Remove c_register_addr_space stub.
 * mangle.cc (write_CV_qualifiers_for_type): Mangle address spaces
   using the extended qualifier notation.

gcc/doc
 * extend.texi (Named Address Spaces): add a mention about C++
   support.

gcc/testsuite/
 * g++.dg/abi/mangle-addr-space1.C: New test.
 * g++.dg/parse/addr-space.C: New test.
 * g++.dg/parse/addr-space1.C: New test.
 * g++.dg/parse/addr-space2.C: New test.

#  >8 
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index bb0544eeaea..ff1146ecc25 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -615,6 +615,33 @@ c_addr_space_name (addr_space_t as)
return IDENTIFIER_POINTER (ridpointers [rid]);
  }
  
+/* Return true if between two named address spaces, whether there is a superset

+   named address space that encompasses both address spaces.  If there is a
+   superset, return which address space is the superset.  */
+
+bool
+addr_space_superset (addr_space_t as1, addr_space_t as2,
+addr_space_t * common)
+{
+  if (as1 == as2)
+{
+  *common = as1;
+  return true;
+}
+  else if (targetm.addr_space.subset_p (as1, as2))
+{
+  *common = as2;
+  return true;
+}
+  else if (targetm.addr_space.

Re: [PATCH v5] c-family: ICE with [[gnu::nocf_check]] [PR106937]

2022-10-10 Thread Jason Merrill via Gcc-patches

On 10/10/22 15:18, Marek Polacek wrote:

On Mon, Oct 10, 2022 at 10:49:34AM -0400, Jason Merrill wrote:

On 10/7/22 18:16, Marek Polacek wrote:

On Fri, Oct 07, 2022 at 05:56:18PM -0400, Jason Merrill wrote:

On 10/7/22 17:08, Marek Polacek wrote:

On Fri, Oct 07, 2022 at 12:17:34PM -0400, Jason Merrill wrote:

On 10/6/22 22:12, Marek Polacek wrote:

On Thu, Oct 06, 2022 at 05:42:41PM -0400, Jason Merrill wrote:

On 10/4/22 19:06, Marek Polacek wrote:

On Fri, Sep 30, 2022 at 09:12:24AM -0400, Jason Merrill wrote:

On 9/29/22 18:49, Marek Polacek wrote:

When getting the name of an attribute, we ought to use
get_attribute_name, which handles both [[ ]] and __attribute__(())
forms.  Failure to do so may result in an ICE, like here.

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


How do we print the attributes with this patch?  Don't we also want to print
the namespace, and use [[]] in the output?


Good point, however: while the testcase indeed has an attribute
in the [[]] form in the typedef, here we're printing its "aka":

warning: initialization of 'FuncPointerWithNoCfCheck' {aka 'void 
(__attribute__((nocf_check)) *)(void)'} from incompatible pointer type 
'FuncPointer' {aka 'void (*)(void)'}

c-pretty-print.cc doesn't seem to know how to print an [[]] attribute.
I could do that, but then we'd print

   aka 'void ([[nocf_check]] *)(void)'

in the above, but that's invalid syntax!


Indeed, it should be

void (* [[gnu::nocf_check]])(void)


Ok, let me fix that too, then.  I've updated the description to show
what we print with the patch, and what was printed before.


Oops, apparently I was wrongly assuming that the attribute appertained to
the pointer.


So was I :/.


Since it actually appertains to the function type, it should
be

void (*)(void) [[gnu::nocf_check]].

But for GCC attribute syntax, I think we want to leave the __attribute__
where it was before, as in the manual's example

void (__attribute__((noreturn)) f) (void);


Thanks, done here:

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

-- >8 --
When getting the name of an attribute, we ought to use
get_attribute_name, which handles both [[]] and __attribute__(())
forms.  Failure to do so may result in an ICE, like here.

pp_c_attributes_display wasn't able to print the [[]] form of
attributes, so this patch teaches it to.

When printing a pointer to function with a standard attribute, the attribute
should be printed after the parameter-list.  With this patch we print:

 aka 'void (*)(int) [[gnu::nocf_check]]'

pp_c_attributes has been unused since its introduction in r56273 so
this patch removes it.

PR c++/106937

gcc/c-family/ChangeLog:

* c-pretty-print.cc (pp_c_specifier_qualifier_list): Only print
GNU attributes here.
(c_pretty_printer::abstract_declarator): For a pointer to function,
print the standard [[]] attributes here.
(pp_c_attributes): Remove.
(pp_c_attributes_display): Print the [[]] form if appropriate.  Use
get_attribute_name.  Don't print a trailing space when printing the
[[]] form.
* c-pretty-print.h (pp_c_attributes): Remove.

gcc/cp/ChangeLog:

* error.cc: Include "attribs.h".
(dump_type_prefix): Only print GNU attributes here.
(dump_type_suffix): Print standard attributes here.

gcc/testsuite/ChangeLog:

* c-c++-common/pointer-to-fn1.c: New test.
---
gcc/c-family/c-pretty-print.cc  | 102 +++-
gcc/c-family/c-pretty-print.h   |   1 -
gcc/cp/error.cc |  17 +++-
gcc/testsuite/c-c++-common/pointer-to-fn1.c |  18 
4 files changed, 92 insertions(+), 46 deletions(-)
create mode 100644 gcc/testsuite/c-c++-common/pointer-to-fn1.c

diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc
index efa1768f4d6..349f0a07d3e 100644
--- a/gcc/c-family/c-pretty-print.cc
+++ b/gcc/c-family/c-pretty-print.cc
@@ -466,7 +466,12 @@ pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree 
t)
  {
pp_c_whitespace (pp);
pp_c_left_paren (pp);
-   pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
+   /* If we're dealing with the GNU form of attributes, print this:
+void (__attribute__((noreturn)) *f) ();
+  If it is the standard [[]] attribute, we'll print the attribute
+  in c_pretty_printer::abstract_declarator.  */
+   if (!cxx11_attribute_p (TYPE_ATTRIBUTES (pointee)))
+ pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
  }
else if (!c_dialect_cxx ())
  pp_c_whitespace (pp);
@@ -564,15 +569,26 @@ pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
void
c_pretty_printer::abstract_declarator (tree t)
{
+  bool fn_ptr_p = false;
  if (TREE_CODE (t) == POINTER_TYPE)
{
  if (TREE_CODE (T

Re: [patch] configury support for VxWorks shared libraries

2022-10-10 Thread Jonathan Wakely via Gcc-patches
On Mon, 10 Oct 2022 at 19:06, Olivier Hainque via Libstdc++
 wrote:
>
> Sorry, I forgot to cc libstdc++ on
>
>   https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603182.html
>
> which includes a regen of libstdc++-v3/configure after an update
> libtool.m4.

OK, thanks for the heads up.



Re: [PATCH] c++: Remove maybe-rvalue OR in implicit move

2022-10-10 Thread Jason Merrill via Gcc-patches

On 9/28/22 17:26, Marek Polacek wrote:

This patch removes the two-stage overload resolution when performing
implicit move, whereby the compiler does two separate overload resolutions:
one treating the operand as an rvalue, and then (if that resolution fails)
another one treating the operand as an lvalue.  In the standard this was
introduced via CWG 1579 and implemented in gcc in r251035.  In r11-2412,
we disabled the fallback OR in C++20 (but not in C++17).  Then C++23 P2266
removed the fallback overload resolution, and changed the implicit move rules
once again.  So we wound up with three different behaviors.

The two overload resolutions approach was complicated and quirky, so
users should transition to the newer model.  Removing the maybe-rvalue
OR also allows us to simplify our code, for instance, now we can get
rid of LOOKUP_PREFER_RVALUE altogether.

This change means that code that previously didn't compile in C++17 will
now compile, for example:

   struct S1 { S1(S1 &&); };
   struct S2 : S1 {};

   S1
   f (S2 s)
   {
 return s; // OK, derived-to-base, use S1::S1(S1&&)
   }

And conversely, code that used to work in C++17 may not compile anymore:

   struct W {
 W();
   };

   struct F {
 F(W&);
 F(W&&) = delete;
   };

   F fn ()
   {
 W w;
 return w; // use w as rvalue -> use of deleted function F::F(W&&)
   }

I plan to add a note to porting_to.html.


It surprises me that this was a change: I guess it depends on how you 
interpret the old wording's "if the overload resolution fails".  I 
vaguely remember there being a bug report about this, before the new 
approach made it moot.



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


OK with the comment tweaks below:


gcc/cp/ChangeLog:

* call.cc (standard_conversion): Remove LOOKUP_PREFER_RVALUE code.
(reference_binding): Honor clk_implicit_rval even pre-C++20.
(implicit_conversion_1): Remove LOOKUP_PREFER_RVALUE code.
(build_user_type_conversion_1): Likewise.
(convert_like_internal): Likewise.
(build_over_call): Likewise.
* cp-tree.h (LOOKUP_PREFER_RVALUE): Remove.
(LOOKUP_NO_NARROWING): Adjust definition.
* except.cc (build_throw): Don't perform two overload resolutions.
* typeck.cc (maybe_warn_pessimizing_move): Don't use
LOOKUP_PREFER_RVALUE.
(check_return_expr): Don't perform two overload resolutions.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/Wredundant-move10.C: Adjust dg-warning.
* g++.dg/cpp0x/Wredundant-move7.C: Likewise.
* g++.dg/cpp0x/move-return2.C: Remove dg-error.
* g++.dg/cpp0x/move-return4.C: Likewise.
* g++.dg/cpp0x/ref-qual20.C: Adjust expected return value.
* g++.dg/cpp0x/move-return5.C: New test.
---
  gcc/cp/call.cc| 41 ++-
  gcc/cp/cp-tree.h  |  6 +--
  gcc/cp/except.cc  | 23 ++-
  gcc/cp/typeck.cc  | 34 +++
  .../g++.dg/cpp0x/Wredundant-move10.C  |  2 +-
  gcc/testsuite/g++.dg/cpp0x/Wredundant-move7.C |  6 +--
  gcc/testsuite/g++.dg/cpp0x/move-return2.C |  2 +-
  gcc/testsuite/g++.dg/cpp0x/move-return4.C |  2 +-
  gcc/testsuite/g++.dg/cpp0x/move-return5.C | 20 +
  gcc/testsuite/g++.dg/cpp0x/ref-qual20.C   |  2 +-
  10 files changed, 41 insertions(+), 97 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp0x/move-return5.C

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 3506b0fcfbb..e100913ea29 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -1272,9 +1272,6 @@ standard_conversion (tree to, tree from, tree expr, bool 
c_cast_p,
}
}
conv = build_conv (ck_rvalue, from, conv);
-  if (flags & LOOKUP_PREFER_RVALUE)
-   /* Tell convert_like to set LOOKUP_PREFER_RVALUE.  */
-   conv->rvaluedness_matches_p = true;
/* If we're performing copy-initialization, remember to skip
 explicit constructors.  */
if (flags & LOOKUP_ONLYCONVERTING)
@@ -1572,9 +1569,6 @@ standard_conversion (tree to, tree from, tree expr, bool 
c_cast_p,
 type.  A temporary object is created to hold the result of
 the conversion unless we're binding directly to a reference.  */
conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
-  if (flags & LOOKUP_PREFER_RVALUE)
-   /* Tell convert_like to set LOOKUP_PREFER_RVALUE.  */
-   conv->rvaluedness_matches_p = true;
/* If we're performing copy-initialization, remember to skip
 explicit constructors.  */
if (flags & LOOKUP_ONLYCONVERTING)
@@ -1883,7 +1877,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool 
c_cast_p, int flags,
  /* Unless it's really a C++20 lvalue being treated as an xvalue.
 But in C++23, such an expression is just an xvalue, not a special
 lvalue, so the 

Re: [PATCH RESEND 0/1] RFC: P1689R5 support

2022-10-10 Thread Jason Merrill via Gcc-patches

On 10/4/22 11:11, Ben Boeckel wrote:

This patch adds initial support for ISO C++'s [P1689R5][], a format for
describing C++ module requirements and provisions based on the source
code. This is required because compiling C++ with modules is not
embarrassingly parallel and need to be ordered to ensure that `import
some_module;` can be satisfied in time by making sure that the TU with
`export import some_module;` is compiled first.

[P1689R5]: https://isocpp.org/files/papers/P1689R5.html

I'd like feedback on the approach taken here with respect to the
user-visible flags. I'll also note that header units are not supported
at this time because the current `-E` behavior with respect to `import
;` is to search for an appropriate `.gcm` file which is not
something such a "scan" can support. A new mode will likely need to be
created (e.g., replacing `-E` with `-fc++-module-scanning` or something)
where headers are looked up "normally" and processed only as much as
scanning requires.

Testing is currently happening in CMake's CI using a prior revision of
this patch (the differences are basically the changelog, some style, and
`trtbd` instead of `p1689r5` as the format name).

For testing within GCC, I'll work on the following:

- scanning non-module source
- scanning module-importing source (`import X;`)
- scanning module-exporting source (`export module X;`)
- scanning module implementation unit (`module X;`)
- flag combinations?

Are there existing tools for handling JSON output for testing purposes?


David Malcolm would probably know best about JSON wrangling.


Basically, something that I can add to the test suite that doesn't care
about whitespace, but checks the structure (with sensible replacements
for absolute paths where relevant)?


Various tests in g++.dg/debug/dwarf2 handle that sort of thing with regexps.


For the record, Clang has patches with similar flags and behavior by
Chuanqi Xu here:

 https://reviews.llvm.org/D134269

with the same flags (though using my old `trtbd` spelling for the
format name).

Thanks,

--Ben

Ben Boeckel (1):
   p1689r5: initial support

  gcc/ChangeLog   |   9 ++
  gcc/c-family/ChangeLog  |   6 +
  gcc/c-family/c-opts.cc  |  40 ++-
  gcc/c-family/c.opt  |  12 ++
  gcc/cp/ChangeLog|   5 +
  gcc/cp/module.cc|   3 +-
  gcc/doc/invoke.texi |  15 +++
  gcc/fortran/ChangeLog   |   5 +
  gcc/fortran/cpp.cc  |   4 +-
  gcc/genmatch.cc |   2 +-
  gcc/input.cc|   4 +-
  libcpp/ChangeLog|  11 ++
  libcpp/include/cpplib.h |  12 +-
  libcpp/include/mkdeps.h |  17 ++-
  libcpp/init.cc  |  14 ++-
  libcpp/mkdeps.cc| 235 ++--
  16 files changed, 368 insertions(+), 26 deletions(-)


base-commit: d812e8cb2a920fd75768e16ca8ded59ad93c172f




Re: [committed] libstdc++: std::make_signed_t should be ill-formed

2022-10-10 Thread Jonathan Wakely via Gcc-patches
On Mon, 10 Oct 2022 at 15:05, Jonathan Wakely wrote:
>
> On Mon, 10 Oct 2022 at 14:50, Tim Song via Libstdc++
>  wrote:
> >
> > On Mon, Oct 10, 2022 at 8:09 AM Patrick Palka via Libstdc++
> >  wrote:
> > >
> > > On Mon, 10 Oct 2022, Jonathan Wakely via Libstdc++ wrote:
> > >
> > > > Tested powerpc64le-linux. Pushed to trunk.
> > > >
> > > > -- >8 --
> > > >
> > > > Currently we only reject std::make_signed_t but not cv bool.
> > > > Similarly for std::make_unsigned_t.
> > > >
> > > > As well as making those ill-formed, this adds a requires-clause to the
> > > > make_signed and make_unsigned primary templates. This makes
> > > > non-integral, non-enum cases fail immediately with a clear error, rather
> > > > than giving an error about __make_signed_selector being
> > > > incomplete.
> > >
> > > IIUC the requires-clause turns what was once a hard error into a SFINAE
> > > error, so e.g. for
> > >
> > >   template typename make_signed::type f(int);
> > >   template void f(...);
> > >   int main() { f(0); }
> > >
> > > the call to f would previously be rejected due to an error outside the
> > > immediate context about incomplete __make_signed_selector, and now with
> > > the requires-clause resolves to the second overload.  I wonder if this
> > > new behavior is conforming -- the examples in [structure.specifications]
> > > of how to implement 'Mandates' suggest that a failed 'Mandates' should
> > > yield a hard error?
> >
> > I'm also concerned about the inability to name make_signed in a
> > context that doesn't require its instantiation (e.g.,
> > conditional_t, make_signed,
> > type_identity>::type). That seems a plausible use case, and
> > breaking it doesn't seem great to me (conformance aside).
>
> Ah yes, that's a problem.
>
> We could fix it like this:
>
>   template
> struct make_unsigned;
>
>   template
> #if __cpp_concepts
> requires is_integral<_Tp>::value || __is_enum(_Tp)
> struct make_unsigned<_Tp>
> #else
> struct make_unsigned
> #endif
> { typedef typename __make_unsigned_selector<_Tp>::__type type; };
>
>   But that doesn't really improve the diagnostic much. It's simpler
> just to revert the addition of the constraints.

Reverted like so. Tested powerpc64le-linux, pushed to trunk.
commit 1d2f07ed4ce028a7c1f9b18f5d959f30213545ca
Author: Jonathan Wakely 
Date:   Mon Oct 10 15:06:53 2022

libstdc++: Revert addition of constraints to make_signed/make_unsigned

Constraining the primary template makes it unusable in uninstantiated
contexts.

libstdc++-v3/ChangeLog:

* include/std/type_traits (make_signed, make_unsigned): Remove
constraints on primary template.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Undo changes to expected error in C++20 mode.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
Likewise.
* testsuite/20_util/make_signed/requirements/uninstantiated.cc:
New test.
* testsuite/20_util/make_unsigned/requirements/uninstantiated.cc:
New test.

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 6108b98aa6a..1d7c3b04a0e 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1802,9 +1802,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Primary template.
   /// make_unsigned
   template
-#if __cpp_concepts
-requires is_integral<_Tp>::value || __is_enum(_Tp)
-#endif
 struct make_unsigned
 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
 
@@ -1937,9 +1934,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Primary template.
   /// make_signed
   template
-#if __cpp_concepts
-requires is_integral<_Tp>::value || __is_enum(_Tp)
-#endif
 struct make_signed
 { typedef typename __make_signed_selector<_Tp>::__type type; };
 
diff --git 
a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc 
b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
index 88b8ae887ef..451eeb8c92d 100644
--- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
@@ -43,5 +43,4 @@ void test01()
   using T8 = make_signed::type; // { dg-error "here" }
 }
 
-// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 }
-// { dg-error "constraint failure" "" { target c++20 } 0 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
diff --git 
a/libstdc++-v3/testsuite/20_util/make_signed/requirements/uninstantiated.cc 
b/libstdc++-v3/testsuite/20_util/make_signed/requirements/uninstantiated.cc
new file mode 100644
index 000..3facf0c595a
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/uninstantiated.cc
@@ -0,0 +1,8 @@

Re: [PATCH] c++ modules: lazy loading from within template [PR99377]

2022-10-10 Thread Nathan Sidwell via Gcc-patches

On 10/4/22 13:36, Patrick Palka wrote:

Here when lazily loading the binding for f at parse time from the
template g, processing_template_decl is set and thus the call to
note_vague_linkage_fn from module_state::read_cluster has no effect,
and we never push f onto deferred_fns and end up never emitting its
definition.

ISTM the behavior of the lazy loading machinery shouldn't be sensitive
to whether we're inside a template, and therefore we should probably be
clearing processing_template_decl somewhere e.g in lazy_load_binding.
This is sufficient to fix the testcase.


yeah, I remember hitting issues with this, but thought I'd got rid of the need 
to override processing_template_decl.  Do you also need to override it in 
lazy_load_pendings though? that's a lazy loader and my suspicion is it might be 
susceptible to the same issues.




But it also seems the processing_template_decl test in
note_vague_linkage_fn, added by r8-7539-g977bc3ee11383e for PR84973, is
perhaps too strong: if the intent is to avoid deferring output for
uninstantiated templates, we should make sure that DECL in question is
an uninstantiated template by checking e.g. value_dependent_expression_p.
This too is sufficient to fix the testcase (since f isn't a template)
and survives bootstrap and regtest.


I think this is an orthogonal issue -- can we remove it from this patch?




Does one or the other approach look like the correct fix for this PR?

PR c++/99377

gcc/cp/ChangeLog:

* decl2.cc (note_vague_linkage_fn): Relax processing_template_decl
test to value_dependent_expression_p.
* module.cc (lazy_load_binding): Clear processing_template_decl.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr99377-2_a.C: New test.
* g++.dg/modules/pr99377-2_b.C: New test.
---
  gcc/cp/decl2.cc| 2 +-
  gcc/cp/module.cc   | 2 ++
  gcc/testsuite/g++.dg/modules/pr99377-2_a.C | 5 +
  gcc/testsuite/g++.dg/modules/pr99377-2_b.C | 6 ++
  4 files changed, 14 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_a.C
  create mode 100644 gcc/testsuite/g++.dg/modules/pr99377-2_b.C

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 9f18466192f..5af4d17ee3b 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -876,7 +876,7 @@ check_classfn (tree ctype, tree function, tree 
template_parms)
  void
  note_vague_linkage_fn (tree decl)
  {
-  if (processing_template_decl)
+  if (value_dependent_expression_p (decl))
  return;
  
DECL_DEFER_OUTPUT (decl) = 1;

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 500ac06563a..79cbb346ffa 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -19074,6 +19074,8 @@ lazy_load_binding (unsigned mod, tree ns, tree id, 
binding_slot *mslot)
  
timevar_start (TV_MODULE_IMPORT);
  
+  processing_template_decl_sentinel ptds;

+
/* Stop GC happening, even in outermost loads (because our caller
   could well be building up a lookup set).  */
function_depth++;
diff --git a/gcc/testsuite/g++.dg/modules/pr99377-2_a.C 
b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C
new file mode 100644
index 000..26e2bccbbbe
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99377-2_a.C
@@ -0,0 +1,5 @@
+// PR c++/99377
+// { dg-additional-options -fmodules-ts }
+// { dg-module-cmi pr99377 }
+export module pr99377;
+export inline void f() { }
diff --git a/gcc/testsuite/g++.dg/modules/pr99377-2_b.C 
b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C
new file mode 100644
index 000..69571952c8a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99377-2_b.C
@@ -0,0 +1,6 @@
+// PR c++/99377
+// { dg-additional-options -fmodules-ts }
+// { dg-do link }
+import pr99377;
+template void g() { f(); }
+int main() { g(); }


--
Nathan Sidwell



Re: [PATCH RESEND 1/1] p1689r5: initial support

2022-10-10 Thread Jason Merrill via Gcc-patches

On 10/4/22 11:12, Ben Boeckel wrote:

This patch implements support for [P1689R5][] to communicate to a build
system the C++20 module dependencies to build systems so that they may
build `.gcm` files in the proper order.


Thanks!


Support is communicated through the following three new flags:

- `-fdeps-format=` specifies the format for the output. Currently named
   `p1689r5`.

- `-fdeps-file=` specifies the path to the file to write the format to.


Do you expect users to want to emit Makefile (-MM) and P1689 
dependencies from the same compilation?



- `-fdep-output=` specifies the `.o` that will be written for the TU
   that is scanned. This is required so that the build system can
   correlate the dependency output with the actual compilation that will
   occur.


The dependency machinery already needs to be able to figure out the name 
of the output file, can't we reuse that instead of specifying it on the 
command line?



CMake supports this format as of 17 Jun 2022 (to be part of 3.25.0)
using an experimental feature selection (to allow for future usage
evolution without committing to how it works today). While it remains
experimental, docs may be found in CMake's documentation for
experimental features.

Future work may include using this format for Fortran module
dependencies as well, however this is still pending work.

[P1689R5]: https://isocpp.org/files/papers/P1689R5.html
[cmake-experimental]: 
https://gitlab.kitware.com/cmake/cmake/-/blob/master/Help/dev/experimental.rst

TODO:

- header-unit information fields

Header units (including the standard library headers) are 100%
unsupported right now because the `-E` mechanism wants to import their
BMIs. A new mode (i.e., something more workable than existing `-E`
behavior) that mocks up header units as if they were imported purely
from their path and content would be required.

- non-utf8 paths

The current standard says that paths that are not unambiguously
represented using UTF-8 are not supported (because these cases are rare
and the extra complication is not worth it at this time). Future
versions of the format might have ways of encoding non-UTF-8 paths. For
now, this patch just doesn't support non-UTF-8 paths (ignoring the
"unambiguously represetable in UTF-8" case).

- figure out why junk gets placed at the end of the file

Sometimes it seems like the file gets a lot of `NUL` bytes appended to
it. It happens rarely and seems to be the result of some
`ftruncate`-style call which results in extra padding in the contents.
Noting it here as an observation at least.

Signed-off-by: Ben Boeckel 
---
  gcc/ChangeLog   |   9 ++
  gcc/c-family/ChangeLog  |   6 +
  gcc/c-family/c-opts.cc  |  40 ++-
  gcc/c-family/c.opt  |  12 ++
  gcc/cp/ChangeLog|   5 +
  gcc/cp/module.cc|   3 +-
  gcc/doc/invoke.texi |  15 +++
  gcc/fortran/ChangeLog   |   5 +
  gcc/fortran/cpp.cc  |   4 +-
  gcc/genmatch.cc |   2 +-
  gcc/input.cc|   4 +-
  libcpp/ChangeLog|  11 ++
  libcpp/include/cpplib.h |  12 +-
  libcpp/include/mkdeps.h |  17 ++-
  libcpp/init.cc  |  14 ++-
  libcpp/mkdeps.cc| 235 ++--
  16 files changed, 368 insertions(+), 26 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6dded16c0e3..2d61de6adde 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2022-09-20  Ben Boeckel  
+
+   * doc/invoke.texi: Document -fdeps-format=, -fdep-file=, and
+   -fdep-output= flags.
+   * genmatch.cc (main): Add new preprocessor parameter used for C++
+   module tracking.
+   * input.cc (test_lexer): Add new preprocessor parameter used for C++
+   module tracking.
+
  2022-09-19  Torbjörn SVENSSON  
  
  	* targhooks.cc (default_zero_call_used_regs): Improve sorry

diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index ba3d76dd6cb..569dcd96e8c 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2022-09-20  Ben Boeckel  
+
+   * c-opts.cc (c_common_handle_option): Add fdeps_file variable and
+   -fdeps-format=, -fdep-file=, and -fdep-output= parsing.
+   * c.opt: Add -fdeps-format=, -fdep-file=, and -fdep-output= flags.
+
  2022-09-15  Richard Biener  
  
  	* c-common.h (build_void_list_node): Remove.

diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index babaa2fc157..617d0e93696 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -77,6 +77,9 @@ static bool verbose;
  /* Dependency output file.  */
  static const char *deps_file;
  
+/* Enhanced dependency output file.  */

+static const char *fdeps_file;
+
  /* The prefix given by -iprefix, if any.  */
  static const char *iprefix;
  
@@ -360,6 +363,23 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,

deps_file = arg;
break;
  
+case OPT_fdep_format_:

+  if (!strcmp (arg, "p1689r5"))
+   cpp_opts->deps.format =

Re: [PATCH] middle-end IFN_ASSUME support [PR106654]

2022-10-10 Thread Jason Merrill via Gcc-patches

On 10/10/22 04:54, Jakub Jelinek via Gcc-patches wrote:

Hi!

My earlier patches gimplify the simplest non-side-effects assumptions
into if (cond) ; else __builtin_unreachable (); and throw the rest
on the floor.
The following patch attempts to do something with the rest too.
For -O0, it actually throws even the simplest assumptions on the floor,
we don't expect optimizations and the assumptions are there to allow
optimizations.


I'd think we should trap on failed assume at -O0 (i.e. with 
-funreachable-traps).


Jason



Re: [PATCH] middle-end IFN_ASSUME support [PR106654]

2022-10-10 Thread Jakub Jelinek via Gcc-patches
On Mon, Oct 10, 2022 at 05:09:29PM -0400, Jason Merrill wrote:
> On 10/10/22 04:54, Jakub Jelinek via Gcc-patches wrote:
> > My earlier patches gimplify the simplest non-side-effects assumptions
> > into if (cond) ; else __builtin_unreachable (); and throw the rest
> > on the floor.
> > The following patch attempts to do something with the rest too.
> > For -O0, it actually throws even the simplest assumptions on the floor,
> > we don't expect optimizations and the assumptions are there to allow
> > optimizations.
> 
> I'd think we should trap on failed assume at -O0 (i.e. with
> -funreachable-traps).

For the simple conditions?  Perhaps.  But for the side-effects cases
that doesn't seem to be easily possible.

Jakub



Go patch committed: Only build thunk struct type when needed

2022-10-10 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend delays building the struct type for a
go/defer thunk until it is needed.  We were building it in the
determine_types pass.  Now, we delay until the
simplify_thunk_statements pass.  That ensures that we are consistent
in determining whether an argument is constant.

With this change we no longer need to add a field for a call to
recover, as the simplify_thunk_statements pass runs after the
build_recover_thunks pass, so the additional argument will already
have been added to the call.

The test case for this is https://go.dev/cl/440297.

This fixes https://go.dev/issue/56109.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
10c26259a8ea34a63a14e85b18e6066766ad6a7a
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 10ed3fee67c..1c2466090f1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-50707b4b51266166ce9bcf9de187e35760ec50f9
+164f2aeb1deec4c11e55b8bfb152ff7ff4c1dd4c
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc
index b442830b0b7..af8c7d15998 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -2349,7 +2349,7 @@ Thunk_statement::Thunk_statement(Statement_classification 
classification,
 Call_expression* call,
 Location location)
 : Statement(classification, location),
-  call_(call), struct_type_(NULL)
+  call_(call)
 {
 }
 
@@ -2430,15 +2430,6 @@ void
 Thunk_statement::do_determine_types()
 {
   this->call_->determine_type_no_context();
-
-  // Now that we know the types of the call, build the struct used to
-  // pass parameters.
-  Call_expression* ce = this->call_->call_expression();
-  if (ce == NULL)
-return;
-  Function_type* fntype = ce->get_function_type();
-  if (fntype != NULL && !this->is_simple(fntype))
-this->struct_type_ = this->build_struct(fntype);
 }
 
 // Check types in a thunk statement.
@@ -2581,6 +2572,8 @@ Thunk_statement::simplify_statement(Gogo* gogo, 
Named_object* function,
   if (this->is_simple(fntype))
 return false;
 
+  Struct_type* struct_type = this->build_struct(fntype);
+
   Expression* fn = ce->fn();
   Interface_field_reference_expression* interface_method =
 fn->interface_field_reference_expression();
@@ -2600,7 +2593,7 @@ Thunk_statement::simplify_statement(Gogo* gogo, 
Named_object* function,
   std::string thunk_name = gogo->thunk_name();
 
   // Build the thunk.
-  this->build_thunk(gogo, thunk_name);
+  this->build_thunk(gogo, thunk_name, struct_type);
 
   // Generate code to call the thunk.
 
@@ -2630,8 +2623,7 @@ Thunk_statement::simplify_statement(Gogo* gogo, 
Named_object* function,
 
   // Build the struct.
   Expression* constructor =
-Expression::make_struct_composite_literal(this->struct_type_, vals,
- location);
+Expression::make_struct_composite_literal(struct_type, vals, location);
 
   // Allocate the initialized struct on the heap.
   constructor = Expression::make_heap_expression(constructor, location);
@@ -2745,15 +2737,6 @@ Thunk_statement::build_struct(Function_type* fntype)
   fields->push_back(Struct_field(tid));
 }
 
-  // The predeclared recover function has no argument.  However, we
-  // add an argument when building recover thunks.  Handle that here.
-  if (ce->is_recover_call())
-{
-  fields->push_back(Struct_field(Typed_identifier("can_recover",
- Type::lookup_bool_type(),
- location)));
-}
-
   const Expression_list* args = ce->args();
   if (args != NULL)
 {
@@ -2781,7 +2764,8 @@ Thunk_statement::build_struct(Function_type* fntype)
 // artificial, function.
 
 void
-Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name)
+Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name,
+Struct_type* struct_type)
 {
   Location location = this->location();
 
@@ -2807,7 +2791,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const 
std::string& thunk_name)
   // which is a pointer to the special structure we build.
   const char* const parameter_name = "__go_thunk_parameter";
   Typed_identifier_list* thunk_parameters = new Typed_identifier_list();
-  Type* pointer_to_struct_type = Type::make_pointer_type(this->struct_type_);
+  Type* pointer_to_struct_type = Type::make_pointer_type(struct_type);
   thunk_parameters->push_back(Typed_identifier(parameter_name,
   pointer_to_struct_type,
   location));
@@ -2914,7 +2898,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const 
std::string& thunk_name)
 }
 
   Expression_list* call_params = ne

Go patch committed: Treat S("") as a string constant

2022-10-10 Thread Ian Lance Taylor via Gcc-patches
This Go frontend patch treats S("") as a string constant.  The
compiler neglected to notice that a conversion from a string constant
to a string type was a valid string constant.

I didn't add a test case because this only caused a compiler failure
when compiling without optimization, which is not the normal case, and
is not a case that we test.

This fixes https://go.dev/issue/56113.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
29b0fe393859729215b0db5d28f2faea30c6ec32
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 1c2466090f1..5b95b38a541 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-164f2aeb1deec4c11e55b8bfb152ff7ff4c1dd4c
+6c188108858e3ae8c8ea8e4cc55427d8cf01bbc8
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 247ae1bba34..71838b14629 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -4092,6 +4092,9 @@ Type_conversion_expression::do_numeric_constant_value(
 bool
 Type_conversion_expression::do_string_constant_value(std::string* val) const
 {
+  if (this->type_->is_string_type() && this->expr_->type()->is_string_type())
+return this->expr_->string_constant_value(val);
+
   if (this->type_->is_string_type()
   && this->expr_->type()->integer_type() != NULL)
 {


Re: [RFC] Add support for vectors in comparisons (like the C++ frontend does)

2022-10-10 Thread Joseph Myers
On Mon, 10 Oct 2022, Paul Iannetta via Gcc-patches wrote:

> I have a patch to bring this feature to the C front-end as well, and
> would like to hear your opinion on it, especially since it may affect
> the feature-set of the objc front-end as well.

> Currently, this is only a tentative patch and I did not add any tests
> to the testsuite.

I think tests (possibly existing C++ tests moved to c-c++-common?) are 
necessary to judge such a feature; it could better be judged based on 
tests without implementation than based on implementation without tests.

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


[PATCH][ICE] Fix for PR107193.

2022-10-10 Thread Eugene Rozenfeld via Gcc-patches
The bug was introduced in f30e9fd33e56a5a721346ea6140722e1b193db42.
A variable (cur_locus_e) was incorrectly declared inside a loop.
I also moved two other declarations (last and locus) down to make
the code more clear.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
PR debug/107193
* tree-cfg.cc (assign_discriminators): Move declaration of cur_locus_e
out of the loop.
---
 gcc/tree-cfg.cc | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 41f2925665f..ae781871a19 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -1204,9 +1204,8 @@ assign_discriminators (void)
   edge e;
   edge_iterator ei;
   gimple_stmt_iterator gsi;
-  gimple *last = last_stmt (bb);
-  location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
   location_t curr_locus = UNKNOWN_LOCATION;
+  expanded_location curr_locus_e = {};
   int curr_discr = 0;
 
   /* Traverse the basic block, if two function calls within a basic block
@@ -1215,7 +1214,7 @@ assign_discriminators (void)
   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
{
  gimple *stmt = gsi_stmt (gsi);
- expanded_location curr_locus_e;
+
  if (curr_locus == UNKNOWN_LOCATION)
{
  curr_locus = gimple_location (stmt);
@@ -1238,6 +1237,8 @@ assign_discriminators (void)
curr_discr = next_discriminator_for_locus (curr_locus);
}
 
+  gimple *last = last_stmt (bb);
+  location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
   if (locus == UNKNOWN_LOCATION)
continue;
 
-- 
2.25.1



Re: [PATCH] Set discriminators for call stmts on the same line within the same basic block

2022-10-10 Thread David Edelsohn via Gcc-patches
This patch causes a bootstrap comparison failure on AIX.  It apparently
does not cause a failure on PPC64BE Linux with the same ABI, so I suspect
that the failure may be related to the way that function aliases are
implemented on AIX, which doesn't have ELF symbol alias semantics.

"This change will also simplify call site lookups since now location with
discriminator will uniquely identify the call site (no callee function name
is needed)."

I will open a PR with more information about the comparison difference now
that I have a work-around to bring AIX back to a bootstrappable state.  Any
thoughts about what could be going wrong?

Thanks, David


Re: [EXTERNAL] Re: [PATCH] Set discriminators for call stmts on the same line within the same basic block

2022-10-10 Thread Eugene Rozenfeld via Gcc-patches
I sent a patch that fixes a bug introduced by this patch: 
https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603203.html

What you are seeing could have been caused by the same bug since it involves an 
uninitialized variable.

Eugene


On Oct 10, 2022, at 5:54 PM, David Edelsohn  wrote:


This patch causes a bootstrap comparison failure on AIX.  It apparently does 
not cause a failure on PPC64BE Linux with the same ABI, so I suspect that the 
failure may be related to the way that function aliases are implemented on AIX, 
which doesn't have ELF symbol alias semantics.

"This change will also simplify call site lookups since now location with 
discriminator will uniquely identify the call site (no callee function name is 
needed)."

I will open a PR with more information about the comparison difference now that 
I have a work-around to bring AIX back to a bootstrappable state.  Any thoughts 
about what could be going wrong?

Thanks, David




Re: [PATCH][ICE] Fix for PR107193.

2022-10-10 Thread H.J. Lu via Gcc-patches
On Mon, Oct 10, 2022 at 5:37 PM Eugene Rozenfeld
 wrote:
>
> The bug was introduced in f30e9fd33e56a5a721346ea6140722e1b193db42.
> A variable (cur_locus_e) was incorrectly declared inside a loop.
> I also moved two other declarations (last and locus) down to make
> the code more clear.
>
> Tested on x86_64-pc-linux-gnu.
>
> gcc/ChangeLog:
> PR debug/107193
> * tree-cfg.cc (assign_discriminators): Move declaration of cur_locus_e
> out of the loop.
> ---
>  gcc/tree-cfg.cc | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
> index 41f2925665f..ae781871a19 100644
> --- a/gcc/tree-cfg.cc
> +++ b/gcc/tree-cfg.cc
> @@ -1204,9 +1204,8 @@ assign_discriminators (void)
>edge e;
>edge_iterator ei;
>gimple_stmt_iterator gsi;
> -  gimple *last = last_stmt (bb);
> -  location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
>location_t curr_locus = UNKNOWN_LOCATION;
> +  expanded_location curr_locus_e = {};
>int curr_discr = 0;
>
>/* Traverse the basic block, if two function calls within a basic block
> @@ -1215,7 +1214,7 @@ assign_discriminators (void)
>for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
> {
>   gimple *stmt = gsi_stmt (gsi);
> - expanded_location curr_locus_e;
> +
>   if (curr_locus == UNKNOWN_LOCATION)
> {
>   curr_locus = gimple_location (stmt);
> @@ -1238,6 +1237,8 @@ assign_discriminators (void)
> curr_discr = next_discriminator_for_locus (curr_locus);
> }
>
> +  gimple *last = last_stmt (bb);
> +  location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
>if (locus == UNKNOWN_LOCATION)
> continue;
>
> --
> 2.25.1
>

It restored bootstrap for me.

Thanks.

-- 
H.J.


Re: [PATCH] RISC-V: Add missing vsetvl instruction type.

2022-10-10 Thread Kito Cheng via Gcc-patches
Committed, thanks :)

On Mon, Oct 10, 2022 at 9:44 PM  wrote:
>
> From: Ju-Zhe Zhong 
>
> When implementing built-in framework, I notice I missed
> vsetvl instruction type, so add it in a single patch
> preparing for the following patches.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv.md: Add vsetvl instruction type.
>
> ---
>  gcc/config/riscv/riscv.md | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
> index 014206fb8bd..2d1cda2b98f 100644
> --- a/gcc/config/riscv/riscv.md
> +++ b/gcc/config/riscv/riscv.md
> @@ -229,6 +229,7 @@
>  ;; Classification of RVV instructions which will be added to each RVV .md 
> pattern and used by scheduler.
>  ;; rdvlenb vector byte length vlenb csrr read
>  ;; rdvlvector length vl csrr read
> +;; vsetvl  vector configuration-setting instrucions
>  ;; 7. Vector Loads and Stores
>  ;; vldevector unit-stride load instructions
>  ;; vstevector unit-stride store instructions
> @@ -316,7 +317,7 @@
>"unknown,branch,jump,call,load,fpload,store,fpstore,
> mtc,mfc,const,arith,logical,shift,slt,imul,idiv,move,fmove,fadd,fmul,
> fmadd,fdiv,fcmp,fcvt,fsqrt,multi,auipc,sfb_alu,nop,ghost,bitmanip,rotate,
> -   rdvlenb,rdvl,vlde,vste,vldm,vstm,vlds,vsts,
> +   rdvlenb,rdvl,vsetvl,vlde,vste,vldm,vstm,vlds,vsts,
> vldux,vldox,vstux,vstox,vldff,vldr,vstr,
> vialu,viwalu,vext,vicalu,vshift,vnshift,vicmp,
> vimul,vidiv,viwmul,vimuladd,viwmuladd,vimerge,vimov,
> --
> 2.36.1
>


Re: [PATCH] RISC-V: move struct vector_type_info from *.h to *.cc and change "user_name" into "name".

2022-10-10 Thread Kito Cheng via Gcc-patches
Committed, thanks :)

On Mon, Oct 10, 2022 at 9:58 PM  wrote:
>
> From: Ju-Zhe Zhong 
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vector-builtins.cc (struct vector_type_info): 
> Move from config/riscv/riscv-vector-builtins.h.
> (DEF_RVV_TYPE): Change USER_NAME to NAME.
> (register_vector_type): Change user_name to name.
> * config/riscv/riscv-vector-builtins.def (DEF_RVV_TYPE): Change 
> USER_NAME to NAME.
> * config/riscv/riscv-vector-builtins.h (struct vector_type_info): 
> Move to riscv-vector-builtins.cc.
> (DEF_RVV_TYPE): Change USER_NAME to NAME.
>
> ---
>  gcc/config/riscv/riscv-vector-builtins.cc  | 28 +-
>  gcc/config/riscv/riscv-vector-builtins.def |  2 +-
>  gcc/config/riscv/riscv-vector-builtins.h   | 20 ++--
>  3 files changed, 25 insertions(+), 25 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
> b/gcc/config/riscv/riscv-vector-builtins.cc
> index 0096e32f5e4..7033b1fc176 100644
> --- a/gcc/config/riscv/riscv-vector-builtins.cc
> +++ b/gcc/config/riscv/riscv-vector-builtins.cc
> @@ -50,10 +50,26 @@ using namespace riscv_vector;
>
>  namespace riscv_vector {
>
> +/* Static information about each vector type.  */
> +struct vector_type_info
> +{
> +  /* The name of the type as declared by riscv_vector.h
> + which is recommend to use. For example: 'vint32m1_t'.  */
> +  const char *name;
> +
> +  /* ABI name of vector type. The type is always available
> + under this name, even when riscv_vector.h isn't included.
> + For example:  '__rvv_int32m1_t'.  */
> +  const char *abi_name;
> +
> +  /* The C++ mangling of ABI_NAME.  */
> +  const char *mangled_name;
> +};
> +
>  /* Information about each RVV type.  */
>  static CONSTEXPR const vector_type_info vector_types[] = {
> -#define DEF_RVV_TYPE(USER_NAME, NCHARS, ABI_NAME, ARGS...)\
> -  {#USER_NAME, #ABI_NAME, "u" #NCHARS #ABI_NAME},
> +#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, ARGS...)\
> +  {#NAME, #ABI_NAME, "u" #NCHARS #ABI_NAME},
>  #include "riscv-vector-builtins.def"
>  };
>
> @@ -151,14 +167,14 @@ register_builtin_types ()
>  = TARGET_64BIT ? unsigned_intSI_type_node : long_unsigned_type_node;
>
>machine_mode mode;
> -#define DEF_RVV_TYPE(USER_NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,  
>   \
> +#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,\
>  VECTOR_MODE_MIN_VLEN_32) 
>  \
>mode = TARGET_MIN_VLEN > 32 ? VECTOR_MODE##mode
>   \
>   : VECTOR_MODE_MIN_VLEN_32##mode;
>  \
> -  scalar_types[VECTOR_TYPE_##USER_NAME]  
>   \
> +  scalar_types[VECTOR_TYPE_##NAME]\
>  = riscv_v_ext_enabled_vector_mode_p (mode) ? SCALAR_TYPE##_type_node 
>   \
>: NULL_TREE;   
>  \
> -  vector_modes[VECTOR_TYPE_##USER_NAME]  
>   \
> +  vector_modes[VECTOR_TYPE_##NAME]\
>  = riscv_v_ext_enabled_vector_mode_p (mode) ? mode : VOIDmode;
>  #include "riscv-vector-builtins.def"
>
> @@ -198,7 +214,7 @@ register_vector_type (vector_type_index type)
>   is disabled according to '-march'.  */
>if (!vectype)
>  return;
> -  tree id = get_identifier (vector_types[type].user_name);
> +  tree id = get_identifier (vector_types[type].name);
>tree decl = build_decl (input_location, TYPE_DECL, id, vectype);
>decl = lang_hooks.decls.pushdecl (decl);
>
> diff --git a/gcc/config/riscv/riscv-vector-builtins.def 
> b/gcc/config/riscv/riscv-vector-builtins.def
> index a9001b3b496..664734b881b 100644
> --- a/gcc/config/riscv/riscv-vector-builtins.def
> +++ b/gcc/config/riscv/riscv-vector-builtins.def
> @@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.  If not see
>   TARGET_MIN_VLEN > 32. Otherwise the machine mode is VNx1SImode.  */
>
>  #ifndef DEF_RVV_TYPE
> -#define DEF_RVV_TYPE(USER_NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,  
>   \
> +#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,\
>  VECTOR_MODE_MIN_VLEN_32)
>  #endif
>
> diff --git a/gcc/config/riscv/riscv-vector-builtins.h 
> b/gcc/config/riscv/riscv-vector-builtins.h
> index 6ca0b073964..ec85e0b1320 100644
> --- a/gcc/config/riscv/riscv-vector-builtins.h
> +++ b/gcc/config/riscv/riscv-vector-builtins.h
> @@ -26,28 +26,12 @@ namespace riscv_vector {
>  /* This is for segment instructions.  */
>  const unsigned int MAX_TUPLE_SIZE = 8;
>
> -/* Static information about each vector type.  */
> -struct vector_type_info
> -{
> -  /* The name of the type as declared by riscv_vector.h
> - which is recommend to use. For example: 'vint32m1_t'.  */
> -  const char *user_name;
> -
> -  /* ABI name of vector type. The type is always a

[PATCH] libstdc++: Implement ranges::repeat_view from P2474R2

2022-10-10 Thread Patrick Palka via Gcc-patches
Tested on x86_64-pc-linux-gnu, does this look OK for trunk? (The paper
also makes changes to views::take and views::drop, which will be
implemented separately.)

libstdc++-v3/ChangeLog:

* include/std/ranges (repeat_view): Define.
(repeat_view::_Iterator): Define.
(views::__detail::__can_repeat_view): Define.
(views::__detail::__can_bounded_repeat_view): Define.
(views::_Repeat, views::repeat): Define.
* testsuite/std/ranges/repeat/1.cc: New test.
---
 libstdc++-v3/include/std/ranges   | 210 ++
 libstdc++-v3/testsuite/std/ranges/repeat/1.cc |  93 
 2 files changed, 303 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/std/ranges/repeat/1.cc

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 1f821128d2d..5857d426a66 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -7356,6 +7356,216 @@ namespace views::__adaptor
 
 inline constexpr _JoinWith join_with;
   } // namespace views
+
+  template
+requires (is_object_v<_Tp> && same_as<_Tp, remove_cv_t<_Tp>>
+  && (__detail::__is_integer_like<_Bound> || same_as<_Bound, 
unreachable_sentinel_t>))
+  class repeat_view : public view_interface>
+  {
+__detail::__box<_Tp> _M_value = _Tp();
+[[no_unique_address]] _Bound _M_bound = _Bound();
+
+struct _Iterator;
+
+  public:
+repeat_view() requires default_initializable<_Tp> = default;
+
+constexpr explicit
+repeat_view(const _Tp& __value, _Bound __bound = _Bound())
+: _M_value(__value), _M_bound(__bound)
+{
+  if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
+   __glibcxx_assert(__bound >= 0);
+}
+
+constexpr explicit
+repeat_view(_Tp&& __value, _Bound __bound = _Bound())
+: _M_value(std::move(__value)), _M_bound(__bound)
+{ }
+
+template
+  requires constructible_from<_Tp, _Args...>
+&& constructible_from<_Bound, _BoundArgs...>
+constexpr explicit
+repeat_view(piecewise_construct_t,
+   tuple<_Args...> __args,
+   tuple<_BoundArgs...> __bound_args = tuple<>{})
+: _M_value(std::make_from_tuple<_Tp>(std::move(__args))),
+  _M_bound(std::make_from_tuple<_Bound>(std::move(__bound_args)))
+{ }
+
+constexpr _Iterator
+begin() const
+{ return _Iterator(std::__addressof(*_M_value)); }
+
+constexpr _Iterator
+end() const requires (!same_as<_Bound, unreachable_sentinel_t>)
+{ return _Iterator(std::__addressof(*_M_value), _M_bound); }
+
+constexpr unreachable_sentinel_t
+end() const noexcept
+{ return unreachable_sentinel; }
+
+constexpr auto
+size() const requires (!same_as<_Bound, unreachable_sentinel_t>)
+{ return __detail::__to_unsigned_like(_M_bound); }
+  };
+
+  template
+repeat_view(_Tp, _Bound) -> repeat_view<_Tp, _Bound>;
+
+  template
+requires __detail::__is_integer_like<_Bound> || same_as<_Bound, 
unreachable_sentinel_t>
+  class repeat_view<_Tp, _Bound>::_Iterator
+  {
+using __index_type
+  = __conditional_t, ptrdiff_t, 
_Bound>;
+
+const _Tp* _M_value = nullptr;
+__index_type _M_current = __index_type();
+
+constexpr explicit
+_Iterator(const _Tp* __value, __index_type __bound = __index_type())
+: _M_value(__value), _M_current(__bound)
+{
+  if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
+   __glibcxx_assert(__bound >= 0);
+}
+
+friend repeat_view;
+
+  public:
+using iterator_concept = random_access_iterator_tag;
+using iterator_category = random_access_iterator_tag;
+using value_type = _Tp;
+using difference_type = 
__conditional_t<__detail::__is_signed_integer_like<__index_type>,
+   __index_type,
+   
__detail::__iota_diff_t<__index_type>>;
+
+_Iterator() = default;
+
+constexpr const _Tp&
+operator*() const noexcept
+{ return *_M_value; }
+
+constexpr _Iterator&
+operator++()
+{
+  ++_M_current;
+  return *this;
+}
+
+constexpr _Iterator
+operator++(int)
+{
+  auto __tmp = *this;
+  ++*this;
+  return __tmp;
+}
+
+constexpr _Iterator&
+operator--()
+{
+  if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
+   __glibcxx_assert(_M_current > 0);
+  --_M_current;
+  return *this;
+}
+
+constexpr _Iterator
+operator--(int)
+{
+  auto __tmp = *this;
+  --*this;
+  return __tmp;
+}
+
+constexpr _Iterator&
+operator+=(difference_type __n)
+{
+  if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
+   __glibcxx_assert(_M_current + __n >= 0);
+  _M_current += __n;
+  return *this;
+}
+
+constexpr _Iterator&
+operator-=(difference_type __n)
+{
+  if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
+   __glibcxx_assert(_M_current - __

Re: [PATCH][ICE] Fix for PR107193.

2022-10-10 Thread Jason Merrill via Gcc-patches

On 10/10/22 20:36, Eugene Rozenfeld wrote:

The bug was introduced in f30e9fd33e56a5a721346ea6140722e1b193db42.
A variable (cur_locus_e) was incorrectly declared inside a loop.
I also moved two other declarations (last and locus) down to make
the code more clear.

Tested on x86_64-pc-linux-gnu.


OK.


gcc/ChangeLog:
PR debug/107193
* tree-cfg.cc (assign_discriminators): Move declaration of cur_locus_e
out of the loop.
---
  gcc/tree-cfg.cc | 7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 41f2925665f..ae781871a19 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -1204,9 +1204,8 @@ assign_discriminators (void)
edge e;
edge_iterator ei;
gimple_stmt_iterator gsi;
-  gimple *last = last_stmt (bb);
-  location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
location_t curr_locus = UNKNOWN_LOCATION;
+  expanded_location curr_locus_e = {};
int curr_discr = 0;
  
/* Traverse the basic block, if two function calls within a basic block

@@ -1215,7 +1214,7 @@ assign_discriminators (void)
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
{
  gimple *stmt = gsi_stmt (gsi);
- expanded_location curr_locus_e;
+
  if (curr_locus == UNKNOWN_LOCATION)
{
  curr_locus = gimple_location (stmt);
@@ -1238,6 +1237,8 @@ assign_discriminators (void)
curr_discr = next_discriminator_for_locus (curr_locus);
}
  
+  gimple *last = last_stmt (bb);

+  location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
if (locus == UNKNOWN_LOCATION)
continue;
  




Re: [PATCH][ICE] Fix for PR107193.

2022-10-10 Thread Jeff Law via Gcc-patches



On 10/10/22 18:36, Eugene Rozenfeld via Gcc-patches wrote:

The bug was introduced in f30e9fd33e56a5a721346ea6140722e1b193db42.
A variable (cur_locus_e) was incorrectly declared inside a loop.
I also moved two other declarations (last and locus) down to make
the code more clear.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
PR debug/107193
* tree-cfg.cc (assign_discriminators): Move declaration of cur_locus_e
out of the loop.


Thanks.  I suspect this caused the hppa bootstrap failure due to 
comparison mismatch as well.  Given it's an 8hr build, I'm inclined to 
just restart it once this patch goes in and hope rather than bisect :-)



jeff




[committed] [PR rtl-optimization/107182] Clear EDGE_CROSSING for jump->ret optimization

2022-10-10 Thread Jeff Law via Gcc-patches


When turning a jump to a return into a return, we need to clear 
EDGE_CROSSING of the fallthru edge to prevent a checking failure.


I considered not applying the transformation when the edge has 
EDGE_CROSSING set, but it still seems like we ought to eliminate the 
unnecessary jump in that case.



Bootstrapped and regression tested on x86_64.  Also did a profiled 
bootstrap and regression test on x86_64.



Installing on the trunk.


Jeff

commit db24bdc743cf23ea12d2dcf8254d86ab366bb46d
Author: Jeff Law 
Date:   Tue Oct 11 00:44:26 2022 -0400

[PR rtl-optimization/107182] Clear EDGE_CROSSING for jump->ret optimization

When turning a jump to a return into a return, we need to clear 
EDGE_CROSSING
of the fallthru edge to prevent a checking failure.

I considered not applying the transformation when the edge has EDGE_CROSSING
set, but it still seems like we ought to eliminate the unnecessary jump in
that case.

gcc/
PR rtl-optimization/107182
* cfgrtl.cc (fixup_reorder_chain): When optimizing a jump to a
return, clear EDGE_CROSSING on the appropriate edge.

diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc
index 281a432f6a6..f31941a61f9 100644
--- a/gcc/cfgrtl.cc
+++ b/gcc/cfgrtl.cc
@@ -4055,6 +4055,7 @@ fixup_reorder_chain (void)
  ret_label = PATTERN (ret);
  dest = EXIT_BLOCK_PTR_FOR_FN (cfun);
 
+ e_fall->flags &= ~EDGE_CROSSING;
  /* E_FALL->dest might become unreachable as a result of
 replacing the jump with a return.  So arrange to remove
 unreachable blocks.  */


[PATCH] RISC-V: Move function place to make it looks better.

2022-10-10 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (rvv_switcher::rvv_switcher): 
Move down like ARM SVE.
(rvv_switcher::~rvv_switcher): Move down like ARM SVE.
(mangle_builtin_type): Move down to make it together with other global 
function.
(class rvv_switcher): Move from riscv-vector-builtins.h.
* config/riscv/riscv-vector-builtins.h (class rvv_switcher): Move to 
riscv-vector-builtins.cc.

---
 gcc/config/riscv/riscv-vector-builtins.cc | 79 ++-
 gcc/config/riscv/riscv-vector-builtins.h  | 19 --
 2 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 7033b1fc176..6fd1bb0fcb2 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -86,23 +86,6 @@ static GTY(()) tree abi_vector_types[NUM_VECTOR_TYPES + 1];
 extern GTY(()) tree builtin_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1];
 tree builtin_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1];
 
-rvv_switcher::rvv_switcher ()
-{
-  /* Set have_regs_of_mode before targetm.init_builtins ().  */
-  memcpy (m_old_have_regs_of_mode, have_regs_of_mode,
- sizeof (have_regs_of_mode));
-  for (int i = 0; i < NUM_MACHINE_MODES; ++i)
-if (riscv_v_ext_enabled_vector_mode_p ((machine_mode) i))
-  have_regs_of_mode[i] = true;
-}
-
-rvv_switcher::~rvv_switcher ()
-{
-  /* Recover back have_regs_of_mode.  */
-  memcpy (have_regs_of_mode, m_old_have_regs_of_mode,
- sizeof (have_regs_of_mode));
-}
-
 /* Add type attributes to builtin type tree, currently only the mangled name. 
*/
 static void
 add_vector_type_attribute (tree type, const char *mangled_name)
@@ -140,19 +123,6 @@ lookup_vector_type_attribute (const_tree type)
   return lookup_attribute ("RVV type", TYPE_ATTRIBUTES (type));
 }
 
-/* If TYPE is a built-in type defined by the RVV ABI, return the mangled name,
-   otherwise return NULL.  */
-const char *
-mangle_builtin_type (const_tree type)
-{
-  if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
-type = TREE_TYPE (TYPE_NAME (type));
-  if (tree attr = lookup_vector_type_attribute (type))
-if (tree id = TREE_VALUE (chain_index (0, TREE_VALUE (attr
-  return IDENTIFIER_POINTER (id);
-  return NULL;
-}
-
 /* Register the built-in RVV ABI types, such as __rvv_int32m1_t.  */
 static void
 register_builtin_types ()
@@ -231,6 +201,55 @@ register_vector_type (vector_type_index type)
   builtin_vector_types[0][type] = vectype;
 }
 
+/* RAII class for enabling enough RVV features to define the built-in
+   types and implement the riscv_vector.h pragma.
+
+   Note: According to 'TYPE_MODE' macro implementation, we need set
+   have_regs_of_mode[mode] to be true if we want to get the exact mode
+   from 'TYPE_MODE'. However, have_regs_of_mode has not been set yet in
+   targetm.init_builtins (). We need rvv_switcher to set have_regs_of_mode
+   before targetm.init_builtins () and recover back have_regs_of_mode
+   after targetm.init_builtins ().  */
+class rvv_switcher
+{
+public:
+  rvv_switcher ();
+  ~rvv_switcher ();
+
+private:
+  bool m_old_have_regs_of_mode[MAX_MACHINE_MODE];
+};
+
+rvv_switcher::rvv_switcher ()
+{
+  /* Set have_regs_of_mode before targetm.init_builtins ().  */
+  memcpy (m_old_have_regs_of_mode, have_regs_of_mode,
+ sizeof (have_regs_of_mode));
+  for (int i = 0; i < NUM_MACHINE_MODES; ++i)
+if (riscv_v_ext_enabled_vector_mode_p ((machine_mode) i))
+  have_regs_of_mode[i] = true;
+}
+
+rvv_switcher::~rvv_switcher ()
+{
+  /* Recover back have_regs_of_mode.  */
+  memcpy (have_regs_of_mode, m_old_have_regs_of_mode,
+ sizeof (have_regs_of_mode));
+}
+
+/* If TYPE is a built-in type defined by the RVV ABI, return the mangled name,
+   otherwise return NULL.  */
+const char *
+mangle_builtin_type (const_tree type)
+{
+  if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
+type = TREE_TYPE (TYPE_NAME (type));
+  if (tree attr = lookup_vector_type_attribute (type))
+if (tree id = TREE_VALUE (chain_index (0, TREE_VALUE (attr
+  return IDENTIFIER_POINTER (id);
+  return NULL;
+}
+
 /* Initialize all compiler built-ins related to RVV that should be
defined at start-up.  */
 void
diff --git a/gcc/config/riscv/riscv-vector-builtins.h 
b/gcc/config/riscv/riscv-vector-builtins.h
index ec85e0b1320..5c01a760657 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -36,25 +36,6 @@ enum vector_type_index
   NUM_VECTOR_TYPES
 };
 
-/* RAII class for enabling enough RVV features to define the built-in
-   types and implement the riscv_vector.h pragma.
-
-   Note: According to 'TYPE_MODE' macro implementation, we need set
-   have_regs_of_mode[mode] to be true if we want to get the exact mode
-   from 'TYPE_MODE'. However, have_regs_of_mode has not been set 

[PATCH] RISC-V: Refine register_builtin_types function.

2022-10-10 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (GTY): Redefine vector types.
(build_const_pointer): New function.
(register_builtin_type): Ditto.
(DEF_RVV_TYPE): Simplify macro.
(register_vector_type): Refine implementation.
* config/riscv/riscv-vector-builtins.h (struct GTY): New struct.

---
 gcc/config/riscv/riscv-vector-builtins.cc | 81 ---
 gcc/config/riscv/riscv-vector-builtins.h  | 10 +++
 2 files changed, 51 insertions(+), 40 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 6fd1bb0fcb2..daf180801cc 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -73,18 +73,14 @@ static CONSTEXPR const vector_type_info vector_types[] = {
 #include "riscv-vector-builtins.def"
 };
 
-/* The scalar type associated with each vector type.  */
-static GTY (()) tree scalar_types[NUM_VECTOR_TYPES];
-/* The machine mode associated with each vector type.  */
-static GTY (()) machine_mode vector_modes[NUM_VECTOR_TYPES];
 /* The RVV types, with their built-in
"__rvv..._t" name.  Allow an index of NUM_VECTOR_TYPES, which always
yields a null tree.  */
 static GTY(()) tree abi_vector_types[NUM_VECTOR_TYPES + 1];
 
 /* Same, but with the riscv_vector.h "v..._t" name.  */
-extern GTY(()) tree builtin_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1];
-tree builtin_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1];
+extern GTY (()) rvv_builtin_types_t builtin_types[NUM_VECTOR_TYPES + 1];
+rvv_builtin_types_t builtin_types[NUM_VECTOR_TYPES + 1];
 
 /* Add type attributes to builtin type tree, currently only the mangled name. 
*/
 static void
@@ -123,6 +119,39 @@ lookup_vector_type_attribute (const_tree type)
   return lookup_attribute ("RVV type", TYPE_ATTRIBUTES (type));
 }
 
+/* Return a representation of "const T *".  */
+static tree
+build_const_pointer (tree t)
+{
+  return build_pointer_type (build_qualified_type (t, TYPE_QUAL_CONST));
+}
+
+/* Helper function for register a single built-in RVV ABI type.  */
+static void
+register_builtin_type (vector_type_index type, tree eltype, machine_mode mode)
+{
+  builtin_types[type].scalar = eltype;
+  builtin_types[type].scalar_ptr = build_pointer_type (eltype);
+  builtin_types[type].scalar_const_ptr = build_const_pointer (eltype);
+  if (!riscv_v_ext_enabled_vector_mode_p (mode))
+return;
+
+  tree vectype = build_vector_type_for_mode (eltype, mode);
+  gcc_assert (VECTOR_MODE_P (TYPE_MODE (vectype)) && TYPE_MODE (vectype) == 
mode
+ && TYPE_MODE_RAW (vectype) == mode && TYPE_ALIGN (vectype) <= 128
+ && known_eq (tree_to_poly_uint64 (TYPE_SIZE (vectype)),
+  GET_MODE_BITSIZE (mode)));
+  vectype = build_distinct_type_copy (vectype);
+  gcc_assert (vectype == TYPE_MAIN_VARIANT (vectype));
+  SET_TYPE_STRUCTURAL_EQUALITY (vectype);
+  TYPE_ARTIFICIAL (vectype) = 1;
+  TYPE_INDIVISIBLE_P (vectype) = 1;
+  add_vector_type_attribute (vectype, vector_types[type].mangled_name);
+  make_type_sizeless (vectype);
+  abi_vector_types[type] = vectype;
+  lang_hooks.types.register_builtin_type (vectype, 
vector_types[type].abi_name);
+}
+
 /* Register the built-in RVV ABI types, such as __rvv_int32m1_t.  */
 static void
 register_builtin_types ()
@@ -137,42 +166,12 @@ register_builtin_types ()
 = TARGET_64BIT ? unsigned_intSI_type_node : long_unsigned_type_node;
 
   machine_mode mode;
-#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE,\
-VECTOR_MODE_MIN_VLEN_32)  \
+#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE, 
\
+VECTOR_MODE_MIN_VLEN_32, ARGS...) \
   mode = TARGET_MIN_VLEN > 32 ? VECTOR_MODE##mode  
\
  : VECTOR_MODE_MIN_VLEN_32##mode; \
-  scalar_types[VECTOR_TYPE_##NAME]\
-= riscv_v_ext_enabled_vector_mode_p (mode) ? SCALAR_TYPE##_type_node   
\
-  : NULL_TREE;\
-  vector_modes[VECTOR_TYPE_##NAME]\
-= riscv_v_ext_enabled_vector_mode_p (mode) ? mode : VOIDmode;
+  register_builtin_type (VECTOR_TYPE_##NAME, SCALAR_TYPE##_type_node, mode);
 #include "riscv-vector-builtins.def"
-
-  for (unsigned int i = 0; i < NUM_VECTOR_TYPES; ++i)
-{
-  tree eltype = scalar_types[i];
-  mode = vector_modes[i];
-  /* We disabled the datatypes according '-march'.  */
-  if (!eltype)
-   continue;
-
-  tree vectype = build_vector_type_for_mode (eltype, mode);
-  gcc_assert (
-   VECTOR_MODE_P (TYPE_MODE (vectype)) && TYPE_MODE (vectype) == mode
-   && TYPE_MODE_RAW (vectype) == mode && TYPE_ALIGN (vectype) <= 

  1   2   >