Re: [PATCH] Simplify "1 - bool_val" to "bool_val ^ 1"

2023-01-31 Thread Richard Biener via Gcc-patches
On Wed, Feb 1, 2023 at 2:30 AM Andrew Pinski via Gcc-patches
 wrote:
>
> For bool values, it is easier to deal with
> xor 1 rather than having 1 - a. This is because
> we are more likely to simplify the xor further in many
> cases.
>
> This is a special case for (MASK - b) where MASK
> is a powerof2 - 1 and b <= MASK but only for bool
> ranges ([0,1]) as that is the main case where the
> difference comes into play.
>
> Note this is enabled for gimple folding only
> as the ranges are only know while doing gimple
> folding and cfun is not always set when fold is called.

Can we robustify ssa_name_has_boolean_range_p instead?
I see it's called even from GENERIC folding in match.pd already.

Otherwise OK.

Thanks,
Richard.

>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no
> regressions.
>
> gcc/ChangeLog:
>
> PR tree-optimization/108355

I think this should be 108354?

> PR tree-optimization/96921
> * match.pd: Add pattern for "1 - bool_val".
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/108355
> PR tree-optimization/96921
> * gcc.dg/tree-ssa/bool-minus-1.c: New test.
> * gcc.dg/tree-ssa/bool-minus-2.c: New test.
> * gcc.dg/tree-ssa/pr108354-1.c: New test.
> ---
>  gcc/match.pd | 13 
>  gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c | 11 +++
>  gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c | 33 
>  gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c   | 26 +++
>  4 files changed, 83 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index f605b798c44..c9e8bebede2 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1732,6 +1732,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   (if (!FIXED_POINT_TYPE_P (type))
>   (plus @0 (negate @1
>
> +#if GIMPLE
> +/* 1 - a is a ^ 1 if a had a bool range. */
> +/* This is only enabled for gimple as sometimes
> +   cfun is not set for the function which contains
> +   the SSA_NAME (e.g. while IPA passes are happening,
> +   fold might be called).  */
> +(simplify
> + (minus integer_onep@0 SSA_NAME@1)
> +  (if (INTEGRAL_TYPE_P (type)
> +   && ssa_name_has_boolean_range (@1))
> +   (bit_xor @1 @0)))
> +#endif
> +
>  /* Other simplifications of negation (c.f. fold_negate_expr_1).  */
>  (simplify
>   (negate (mult:c@0 @1 negate_expr_p@2))
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
> new file mode 100644
> index 000..e434ff9507a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
> @@ -0,0 +1,11 @@
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +_Bool
> +foo (_Bool a)
> +{
> +  int c = 1 - a;
> +  return c;
> +}
> +
> +/* { dg-final { scan-tree-dump-times "1 - " 0 "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "~a" 1 "optimized" } } */
> +
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
> new file mode 100644
> index 000..b77d36c1d3c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
> @@ -0,0 +1,33 @@
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +_Bool
> +foo (_Bool a, _Bool b)
> +{
> +  int c = 1 - a;
> +  int d = 1 - b;
> +  int e = c & d;
> +  return 1 - e;
> +}
> +
> +_Bool
> +bar (_Bool a, _Bool b)
> +{
> +  int c = 1 - a;
> +  int d = 1 - b;
> +  _Bool e = c & d;
> +  return 1 - e;
> +}
> +
> +_Bool
> +baz (_Bool a, _Bool b)
> +{
> +  _Bool c = 1 - a;
> +  _Bool d = 1 - b;
> +  _Bool e = c & d;
> +  return 1 - e;
> +}
> +
> +/* { dg-final { scan-tree-dump-times "1 - " 0 "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "~a" 0 "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "~b" 0 "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "a_\[0-9\]+.D. \\\| b_\[0-9\]+.D." 3 
> "optimized" } } */
> +
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c
> new file mode 100644
> index 000..60d1dbc281e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c
> @@ -0,0 +1,26 @@
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +int b;
> +int *c;
> +int e;
> +static int *f = 
> +int g;
> +void foo();
> +short(a)(short h, short i) { return h - i; }
> +int(d)(int h) { return h == 83647 ? 0 : -h; }
> +int main() {
> +  short j;
> +  int *k = , *l = 
> +  *f = 0 == c;
> +  j = a(0 != 2, *k);
> +  if (d(j ^ (0 == l || *k)) != *k)
> +;
> +  else
> +foo();
> +  c = 
> +}
> +
> +/* { dg-final { scan-tree-dump-times " 1 - " 0 "optimized" } } */
> +/* There should be no calls to foo. */
> +/* { dg-final { scan-tree-dump-times "foo " 0 "optimized" } } */
> +
> --
> 2.17.1
>


Re: [PATCH] PR tree-optimization/108356 - Ranger cache - always use range_from_dom when updating.

2023-01-31 Thread Richard Biener via Gcc-patches
On Tue, Jan 31, 2023 at 9:11 PM Andrew MacLeod via Gcc-patches
 wrote:
>
> This turned out to be a more interesting problem than I wanted.
>
> the situation boils down to:
>
> 
> # g_5 = PHI <0(2), 2(8)>
>if (g_5 <= 1)
>  goto ; [INV]
>
>  :
>if (g_5 != 0)
>  goto ; [INV]
>else
>  goto ; [INV]
>
> :
>c = 0;
>
> :
>  goto ; [INV]
>
>   We globally know that g_5 is [0,0][2,2]
> we also know that 10->4 , g_5 will be [0,0]
> Which means we also know that that the branch in bb_4 will never be
> taken, and will always go to bb 8.
> THis is all processed in EVRP, the branch is changed, and the next time
> VRP is called, we blow the block with c = 0 like we want...
>
> Unfortunately it doesnt happen within EVRP because when this updated
> range for g_5 is propagated in the cache, it was tripping over a shotcut
> which tried to avoid using lookups when it thinks it didnt matter, and
> would occasionally drop back to the global range.
>
> In particular, the cache had originally propagated [0,0][2,2] as the on
> entry range to bb8. when we rewrite the branch, we mark 4->7 and 7->8
> as unexecutable edges, then propagate the new range for g_5..  This
> requires recalculating the existing range on entry to bb8.
>
> It properly picked up [0,0] from 4->8, but when the cache query checked
> the range from 7->8, it discovered that no value was yet set, so instead
> of looking it up, it fell back to the global range of [0,0][2,2].  If it
> properly calculates that edge instead, it comes up with UNDEFINED (as it
> is unexecutable) and results in [0,0]... and EVRP then also removes the
> block is c = 0 in.
>
> By picking up the global value, it still thought 2 was a possibility
> later on, and a single VRP pass couldn't eliminate the branch ultimately
> leading to the store... it required a second one with the adjusted CFG
> to catch it.
>
> This patch tells the cache to always do a read-only scan of the
> dominator tree to find the nearest actual value and use that instead.
> This may solve other lingering weird propagation issues.
>
> I also ran a performance run on this change. It does slow VRP by down
> about 1%, but the overall change is nominal at around 0.05%.
>
> Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK?

OK.

Thanks,
Richard.

> Andrew
>


[PATCH] x86: Use DW_EH_PE_indirect|DW_EH_PE_pcrel encodings for -fno-pic code

2023-01-31 Thread Fangrui Song via Gcc-patches
Follow aarch64 and riscv ports by using (global ? DW_EH_PE_indirect : 0)
| DW_EH_PE_pcrel for -fno-pic code.  This avoids a canonical PLT entry
for a personality reference in .eh_frame and a copy relocation for a
typeinfo reference in .gcc_except_table, when the definition is in
libstdc++.so.6.

gcc/

PR target/108622
* config/i386/i386.cc (asm_preferred_eh_data_format): Always use the
PIC encoding. Use DW_EH_PE_indirect if global.
---
 gcc/config/i386/i386.cc | 23 +++
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 3cacf738c4a..b572dd46a62 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -22851,22 +22851,13 @@ ix86_stack_protect_fail (void)
 int
 asm_preferred_eh_data_format (int code, int global)
 {
-  /* PE-COFF is effectively always -fPIC because of the .reloc section.  */
-  if (flag_pic || TARGET_PECOFF || !ix86_direct_extern_access)
-{
-  int type = DW_EH_PE_sdata8;
-  if (ptr_mode == SImode
- || ix86_cmodel == CM_SMALL_PIC
- || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
-   type = DW_EH_PE_sdata4;
-  return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
-}
-
-  if (ix86_cmodel == CM_SMALL
-  || (ix86_cmodel == CM_MEDIUM && code))
-return DW_EH_PE_udata4;
-
-  return DW_EH_PE_absptr;
+  int type = DW_EH_PE_sdata8;
+  if (ptr_mode == SImode || ix86_cmodel == CM_SMALL ||
+  ix86_cmodel == CM_SMALL_PIC ||
+  (ix86_cmodel == CM_MEDIUM && code) ||
+  (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
+type = DW_EH_PE_sdata4;
+  return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
 }
 
 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
-- 
2.39.1.456.gfc5497dd1b-goog



Re: [PATCH 0/6] PowerPC Dense Math prelimary support (-mcpu=future)

2023-01-31 Thread Michael Meissner via Gcc-patches
On Sun, Jan 29, 2023 at 09:52:38PM -0500, Michael Meissner wrote:
> On Sat, Jan 28, 2023 at 02:29:04AM -0500, Michael Meissner wrote:
> > On Fri, Jan 27, 2023 at 01:59:00PM -0600, Segher Boessenkool wrote:
> > > > There is one bug that I noticed.  When you use the full DMR instruction 
> > > > the
> > > > constant copy propagation patch issues internal errors.  I believe this 
> > > > is due
> > > > to the CCP pass not handling opaque types cleanly enough, and it only 
> > > > shows up
> > > > in larger types.  I would like to get these patches committed, and then 
> > > > work
> > > > the maintainers of the CCP to fix the problem.
> > > 
> > > Erm.  If the compiler ICEs, we can not include this code.  But hopefully
> > > you mean something else?
> > 
> > I realize we can't include the code for final release.  But as a temporary
> > measure I was hoping we would put in the code, we could allow somebody more
> > familar with ccp to debug it.  Then if there were changes needed in the 
> > PowerPC
> > back end, we could make them, once ccp was fixed.
> > 
> > But that is a moot point, ccp no longer dies with the code, so I have 
> > removed
> > the comment and the no tree ccp option in the next set of patches.
> 
> Unfortunately, while it worked on my x86 as a cross compiler, when I did the
> builds for real, it is a problem, so I will need to look into it.

Ok, I tracked down the source of the bug.  The CCP pass is depending on the
precision field.  Unfortunately in tree-core.h, the precision is a 10 integer
bit field, so 1,024 will become 0.

Having a 0 precision meant that the hwint function for sign extending a value
would generate:

(HOST_WIDE_INT)(((unsigned HOST_WIDE_INT)value << 64) >> 64)

which is undefined behavior in C and C++.  On the x86_64 doing the shift left
and then right gives you the initial value (which was -1), while on the PowerPC
it always gives you 0.  The CCP code was assuming if it wasn't -1, that it was
an integer, but the TDO type is opaque, not integer.

The solution was to grow precision by 1 bit and decrease the extra bits in the
placeholder entry by 1 bit.  I'm testing it now.

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


[pushed] analyzer: fix uses of alloca in testsuite

2023-01-31 Thread David Malcolm via Gcc-patches
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-5615-gd03ae4be2c6d48.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/call-summaries-2.c: Add
dg-require-effective-target alloca.
* gcc.dg/analyzer/imprecise-floating-point-1.c: Likewise.
* gcc.dg/analyzer/infinite-recursion-alloca.c: Likewise.
* gcc.dg/analyzer/malloc-callbacks.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-5.c: Likewise.  Remove includes
of  and .  Use "__builtin_free" rather than
"free", to match uses of "__builtin_malloc".
* gcc.dg/analyzer/putenv-1.c: Add dg-require-effective-target
alloca.
* gcc.dg/analyzer/write-to-string-literal-5.c: Likewise.

Signed-off-by: David Malcolm 
---
 gcc/testsuite/gcc.dg/analyzer/call-summaries-2.c | 1 +
 .../gcc.dg/analyzer/imprecise-floating-point-1.c | 2 ++
 .../gcc.dg/analyzer/infinite-recursion-alloca.c  | 2 ++
 gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c | 2 ++
 gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c  | 9 -
 gcc/testsuite/gcc.dg/analyzer/putenv-1.c | 1 +
 .../gcc.dg/analyzer/write-to-string-literal-5.c  | 1 +
 7 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/analyzer/call-summaries-2.c 
b/gcc/testsuite/gcc.dg/analyzer/call-summaries-2.c
index 22ca475b2ed..2d82d02e4e2 100644
--- a/gcc/testsuite/gcc.dg/analyzer/call-summaries-2.c
+++ b/gcc/testsuite/gcc.dg/analyzer/call-summaries-2.c
@@ -1,4 +1,5 @@
 /* { dg-additional-options "-fanalyzer-call-summaries --param 
analyzer-min-snodes-for-call-summary=0" } */
+/* { dg-require-effective-target alloca } */
 
 /* There need to be at least two calls to a function for the
call-summarization code to be used.
diff --git a/gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c 
b/gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c
index d8a3f4884d6..7fe09fb826b 100644
--- a/gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target alloca } */
+
 #include 
 
 /* Tests warn on use of floating-point operands inside the calculation
diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-alloca.c 
b/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-alloca.c
index 8c50631d8ce..87727e8ca25 100644
--- a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-alloca.c
+++ b/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-alloca.c
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target alloca } */
+
 typedef __SIZE_TYPE__ size_t;
 
 int test_alloca_1 (void)
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c 
b/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c
index c79f80d376d..cf3927fcaea 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c
@@ -1,3 +1,5 @@
+/* { dg-require-effective-target alloca } */
+
 #include 
 
 typedef void *(*allocator_t) (size_t);
diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c 
b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c
index eb6aae0f8cb..2a61d8ca236 100644
--- a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c
+++ b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c
@@ -1,9 +1,8 @@
 /* { dg-additional-options "-Wno-unused-but-set-variable" } */
+/* { dg-require-effective-target alloca } */
 
 #include 
-#include 
 #include 
-#include 
 #include 
 
 /* Tests with symbolic values.  */
@@ -14,7 +13,7 @@ void test1 (size_t size)
   if (!buf) return;
 
   buf[size] = '\0'; /* { dg-warning "heap-based buffer overflow" } */
-  free (buf);
+  __builtin_free (buf);
 }
 
 void test2 (size_t size)
@@ -23,7 +22,7 @@ void test2 (size_t size)
   if (!buf) return;
 
   buf[size + 1] = '\0'; /* { dg-warning "heap-based buffer overflow" } */
-  free (buf);
+  __builtin_free (buf);
 }
 
 void test3 (size_t size, size_t op)
@@ -32,7 +31,7 @@ void test3 (size_t size, size_t op)
   if (!buf) return;
 
   buf[size + op] = '\0'; /* { dg-warning "heap-based buffer overflow" } */
-  free (buf);
+  __builtin_free (buf);
 }
 
 void test4 (size_t size, unsigned short s)
diff --git a/gcc/testsuite/gcc.dg/analyzer/putenv-1.c 
b/gcc/testsuite/gcc.dg/analyzer/putenv-1.c
index 4c3f0ae2e74..543121258c8 100644
--- a/gcc/testsuite/gcc.dg/analyzer/putenv-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/putenv-1.c
@@ -1,4 +1,5 @@
 /* { dg-additional-options "-Wno-analyzer-null-argument" } */
+/* { dg-require-effective-target alloca } */
 
 #include 
 #include 
diff --git a/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-5.c 
b/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-5.c
index b7ac4659012..42efc49fb22 100644
--- a/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-5.c
+++ b/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-5.c
@@ -2,6 +2,7 @@
notes) works.  */
 
 /* { dg-additional-options 

[pushed] analyzer: fix -Wanalyzer-allocation-size false -ve on alloca [PR108616]

2023-01-31 Thread David Malcolm via Gcc-patches
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-5614-g70d34f2a30a5f1.

gcc/analyzer/ChangeLog:
PR analyzer/108616
* pending-diagnostic.cc (fixup_location_in_macro_p): Add "alloca"
to macros that we shouldn't unwind inside.

gcc/testsuite/ChangeLog:
PR analyzer/108616
* gcc.dg/analyzer/allocation-size-multiline-3.c: New test.
* gcc.dg/analyzer/test-alloca.h: New test.

Signed-off-by: David Malcolm 
---
 gcc/analyzer/pending-diagnostic.cc|  6 +++
 .../analyzer/allocation-size-multiline-3.c| 44 +++
 gcc/testsuite/gcc.dg/analyzer/test-alloca.h   |  3 ++
 3 files changed, 53 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-3.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/test-alloca.h

diff --git a/gcc/analyzer/pending-diagnostic.cc 
b/gcc/analyzer/pending-diagnostic.cc
index 79e6c5528eb..e36ed4fd9c1 100644
--- a/gcc/analyzer/pending-diagnostic.cc
+++ b/gcc/analyzer/pending-diagnostic.cc
@@ -139,6 +139,12 @@ static bool
 fixup_location_in_macro_p (cpp_hashnode *macro)
 {
   ht_identifier ident = macro->ident;
+
+  /* Don't unwind inside "alloca" macro, so that we don't suppress warnings
+ from it (due to being in system headers).  */
+  if (ht_ident_eq (ident, "alloca"))
+return true;
+
   /* Don't unwind inside  macros, so that we don't suppress warnings
  from them (due to being in system headers).  */
   if (ht_ident_eq (ident, "va_start")
diff --git a/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-3.c 
b/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-3.c
new file mode 100644
index 000..e27364a8e83
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-3.c
@@ -0,0 +1,44 @@
+/* Verify that we warn for incorrect uses of "alloca" (which may be in a 
+   macro in a system header), and that the output looks correct.  */
+
+/* { dg-additional-options "-fdiagnostics-path-format=inline-events 
-fdiagnostics-show-caret -fanalyzer-fine-grained" } */
+/* { dg-require-effective-target alloca } */
+
+#include 
+#include "test-alloca.h"
+
+void test_constant_99 (void)
+{
+  int32_t *ptr = alloca (99); /* { dg-warning "allocated buffer size is not a 
multiple of the pointee's size" } */
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = alloca (99);
+  ^~
+  'test_constant_99': events 1-2
+|
+|   int32_t *ptr = alloca (99);
+|  ^~
+|  |
+|  (1) allocated 99 bytes here
+|  (2) assigned to 'int32_t *' {aka 'int *'} here; 'sizeof 
(int32_t {aka int})' is '4'
+|
+   { dg-end-multiline-output "" } */
+
+void test_symbolic (int n)
+{
+  int32_t *ptr = alloca (n * 2); /* { dg-warning "allocated buffer size is not 
a multiple of the pointee's size" } */
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = alloca (n * 2);
+  ^~
+  'test_symbolic': events 1-2
+|
+|   int32_t *ptr = alloca (n * 2);
+|  ^~
+|  |
+|  (1) allocated 'n * 2' bytes here
+|  (2) assigned to 'int32_t *' {aka 'int *'} here; 'sizeof 
(int32_t {aka int})' is '4'
+|
+   { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/test-alloca.h 
b/gcc/testsuite/gcc.dg/analyzer/test-alloca.h
new file mode 100644
index 000..f4045f92adc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/test-alloca.h
@@ -0,0 +1,3 @@
+#pragma GCC system_header
+
+#define alloca(X) __builtin_alloca(X)
-- 
2.26.3



[pushed] c++: Add -Wno-changes-meaning

2023-01-31 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

This isn't exactly a regression fix, but it is in response to new build
failures and safe.

-- 8< --

In recent years this error has been coming up more because other compilers
don't diagnose it as consistently.  So let's add a flag for it, and be more
lenient about cases that aren't likely to cause bugs.

gcc/ChangeLog:

* doc/invoke.texi: Document -Wno-changes-meaning.

gcc/c-family/ChangeLog:

* c.opt: Add -Wno-changes-meaning.

gcc/cp/ChangeLog:

* class.cc (note_name_declared_in_class): Change from permerror to
-Wchanges-meaning pedwarn, forcing -pedantic-errors for most cases.

gcc/testsuite/ChangeLog:

* g++.dg/warn/changes-meaning2.C: New test.
* g++.dg/warn/changes-meaning3.C: New test.
---
 gcc/doc/invoke.texi  | 17 +
 gcc/c-family/c.opt   |  4 
 gcc/cp/class.cc  | 18 ++
 gcc/testsuite/g++.dg/warn/changes-meaning2.C | 16 
 gcc/testsuite/g++.dg/warn/changes-meaning3.C | 13 +
 5 files changed, 64 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/changes-meaning2.C
 create mode 100644 gcc/testsuite/g++.dg/warn/changes-meaning3.C

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d12f318adfd..14d4e8a224c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6287,6 +6287,23 @@ union U @{
 
 @end itemize
 
+@item -Wno-changes-meaning @r{(C++ and Objective-C++ only)}
+C++ requires that unqualified uses of a name within a class have the
+same meaning in the complete scope of the class, so declaring the name
+after using it is ill-formed:
+@smallexample
+struct A;
+struct B1 @{ A a; typedef A A; @}; // warning, 'A' changes meaning
+struct B2 @{ A a; struct A @{ @}; @}; // error, 'A' changes meaning
+@end smallexample
+By default, the B1 case is only a warning because the two declarations
+have the same type, while the B2 case is an error.  Both diagnostics
+can be disabled with @option{-Wno-changes-meaning}.  Alternately, the
+error case can be reduced to a warning with
+@option{-Wno-error=changes-meaning} or @option{-fpermissive}.
+
+Both diagnostics are also suppressed by @option{-fms-extensions}.
+
 @item -Wchar-subscripts
 @opindex Wchar-subscripts
 @opindex Wno-char-subscripts
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index ef371ca8c26..c0fea56a8f5 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -494,6 +494,10 @@ Wcatch-value=
 C++ ObjC++ Var(warn_catch_value) Warning Joined RejectNegative UInteger 
LangEnabledBy(C++ ObjC++,Wall, 1, 0) IntegerRange(0, 3)
 Warn about catch handlers of non-reference type.
 
+Wchanges-meaning
+C++ ObjC++ Var(warn_changes_meaning) Warning Init(1)
+Complain about a name being declared as a class member after a previous use of 
the same name.
+
 Wchar-subscripts
 C ObjC C++ ObjC++ Var(warn_char_subscripts) Warning LangEnabledBy(C ObjC C++ 
ObjC++,Wall)
 Warn about subscripts whose type is \"char\".
diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 351de6c5419..a2aa6674590 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -9016,7 +9016,7 @@ note_name_declared_in_class (tree name, tree decl)
 return;
   /* The C language allows members to be declared with a type of the same
  name, and the C++ standard says this diagnostic is not required.  So
- allow it in extern "C" blocks unless predantic is specified.
+ allow it in extern "C" blocks unless pedantic is specified.
  Allow it in all cases if -ms-extensions is specified.  */
   if ((!pedantic && current_lang_name == lang_name_c)
   || flag_ms_extensions)
@@ -9032,9 +9032,19 @@ note_name_declared_in_class (tree name, tree decl)
 A name N used in a class S shall refer to the same declaration
 in its context and when re-evaluated in the completed scope of
 S.  */
-  if (permerror (location_of (decl),
-"declaration of %q#D changes meaning of %qD",
-decl, OVL_NAME (decl)))
+  auto ov = make_temp_override (global_dc->pedantic_errors);
+  if (TREE_CODE (decl) == TYPE_DECL
+ && TREE_CODE (olddecl) == TYPE_DECL
+ && same_type_p (TREE_TYPE (decl), TREE_TYPE (olddecl)))
+   /* Different declaration, but same meaning; just warn.  */;
+  else if (flag_permissive)
+   /* Let -fpermissive make it a warning like past versions.  */;
+  else
+   /* Make it an error.  */
+   global_dc->pedantic_errors = 1;
+  if (pedwarn (location_of (decl), OPT_Wchanges_meaning,
+  "declaration of %q#D changes meaning of %qD",
+  decl, OVL_NAME (decl)))
{
  inform (loc, "used here to mean %q#D", olddecl);
  inform (location_of (olddecl), "declared here" );
diff --git a/gcc/testsuite/g++.dg/warn/changes-meaning2.C 

[pushed] doc: add notes about limitations of -fanalyzer

2023-01-31 Thread David Malcolm via Gcc-patches
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-5613-ga90316c6ceddfb.

gcc/ChangeLog:
* doc/invoke.texi (Static Analyzer Options): Add notes about
limitations of -fanalyzer.

Signed-off-by: David Malcolm 
---
 gcc/doc/invoke.texi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 06d77983e30..ddeeea5ccb4 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10064,6 +10064,13 @@ code, and issues warnings for problems found on them.
 
 This analysis is much more expensive than other GCC warnings.
 
+In technical terms, it performs coverage-guided symbolic execution of
+the code being compiled.  It is neither sound nor complete: it can
+have false positives and false negatives.  It is a bug-finding tool,
+rather than a tool for proving program correctness.
+
+The analyzer is only suitable for use on C code in this release.
+
 Enabling this option effectively enables the following warnings:
 
 @gccoptlist{ @gol
-- 
2.26.3



[PATCH] RISC-V: Fix constraint bug for binary operation

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

Current constraint configuration will generate:
vadd.vv v0,v24,v25,v0.t
vsll.vx v0,v24,a5,v0.t

They are incorrect according to RVV ISA.
This patch fix this obvious issue.

gcc/ChangeLog:

* config/riscv/vector-iterators.md (sll.vi): Fix constraint bug.
(sll.vv): Ditto.
(%3,%4): Ditto.
(%3,%v4): Ditto.
* config/riscv/vector.md: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/binop_vv_constraint-1.c:
* gcc.target/riscv/rvv/base/shift_vx_constraint-1.c:

---
 gcc/config/riscv/vector-iterators.md  | 86 +--
 gcc/config/riscv/vector.md| 41 +
 .../riscv/rvv/base/binop_vv_constraint-1.c|  8 +-
 .../riscv/rvv/base/shift_vx_constraint-1.c|  9 +-
 4 files changed, 75 insertions(+), 69 deletions(-)

diff --git a/gcc/config/riscv/vector-iterators.md 
b/gcc/config/riscv/vector-iterators.md
index a2f192d6ba0..4f9799ade05 100644
--- a/gcc/config/riscv/vector-iterators.md
+++ b/gcc/config/riscv/vector-iterators.md
@@ -229,42 +229,42 @@
(umod "register_operand")])
 
 (define_code_attr binop_rhs1_constraint [
-   (plus "vr,vr,vr")
-   (minus "vr,vr,vi")
-   (ior "vr,vr,vr")
-   (xor "vr,vr,vr")
-   (and "vr,vr,vr")
-   (ashift "vr,vr,vr")
-   (ashiftrt "vr,vr,vr")
-   (lshiftrt "vr,vr,vr")
-   (smin "vr,vr,vr")
-   (smax "vr,vr,vr")
-   (umin "vr,vr,vr")
-   (umax "vr,vr,vr")
-   (mult "vr,vr,vr")
-   (div "vr,vr,vr")
-   (mod "vr,vr,vr")
-   (udiv "vr,vr,vr")
-   (umod "vr,vr,vr")])
+   (plus "vr,vr,vr,vr,vr,vr")
+   (minus "vr,vr,vr,vr,vi,vi")
+   (ior "vr,vr,vr,vr,vr,vr")
+   (xor "vr,vr,vr,vr,vr,vr")
+   (and "vr,vr,vr,vr,vr,vr")
+   (ashift "vr,vr,vr,vr,vr,vr")
+   (ashiftrt "vr,vr,vr,vr,vr,vr")
+   (lshiftrt "vr,vr,vr,vr,vr,vr")
+   (smin "vr,vr,vr,vr,vr,vr")
+   (smax "vr,vr,vr,vr,vr,vr")
+   (umin "vr,vr,vr,vr,vr,vr")
+   (umax "vr,vr,vr,vr,vr,vr")
+   (mult "vr,vr,vr,vr,vr,vr")
+   (div "vr,vr,vr,vr,vr,vr")
+   (mod "vr,vr,vr,vr,vr,vr")
+   (udiv "vr,vr,vr,vr,vr,vr")
+   (umod "vr,vr,vr,vr,vr,vr")])
 
 (define_code_attr binop_rhs2_constraint [
-   (plus "vr,vi,vr")
-   (minus "vr,vj,vr")
-   (ior "vr,vi,vr")
-   (xor "vr,vi,vr")
-   (and "vr,vi,vr")
-   (ashift "vr,vk,vr")
-   (ashiftrt "vr,vk,vr")
-   (lshiftrt "vr,vk,vr")
-   (smin "vr,vr,vr")
-   (smax "vr,vr,vr")
-   (umin "vr,vr,vr")
-   (umax "vr,vr,vr")
-   (mult "vr,vr,vr")
-   (div "vr,vr,vr")
-   (mod "vr,vr,vr")
-   (udiv "vr,vr,vr")
-   (umod "vr,vr,vr")])
+   (plus "vr,vr,vi,vi,vr,vr")
+   (minus "vr,vr,vj,vj,vr,vr")
+   (ior "vr,vr,vi,vi,vr,vr")
+   (xor "vr,vr,vi,vi,vr,vr")
+   (and "vr,vr,vi,vi,vr,vr")
+   (ashift "vr,vr,vk,vk,vr,vr")
+   (ashiftrt "vr,vr,vk,vk,vr,vr")
+   (lshiftrt "vr,vr,vk,vk,vr,vr")
+   (smin "vr,vr,vr,vr,vr,vr")
+   (smax "vr,vr,vr,vr,vr,vr")
+   (umin "vr,vr,vr,vr,vr,vr")
+   (umax "vr,vr,vr,vr,vr,vr")
+   (mult "vr,vr,vr,vr,vr,vr")
+   (div "vr,vr,vr,vr,vr,vr")
+   (mod "vr,vr,vr,vr,vr,vr")
+   (udiv "vr,vr,vr,vr,vr,vr")
+   (umod "vr,vr,vr,vr,vr,vr")])
 
 (define_code_attr int_binop_insn_type [
(plus "vialu")
@@ -285,9 +285,9 @@
(udiv "vidiv")
(umod "vidiv")])
 
-;;  expands to the insn name of binop matching constraint 
alternative = 1.
+;;  expands to the insn name of binop matching constraint 
rhs1 is immediate.
 ;; minus is negated as vadd and ss_minus is negated as vsadd, others remain 
.
-(define_code_attr binop_alt1_insn [(ashift "sll.vi")
+(define_code_attr binop_imm_rhs1_insn [(ashift "sll.vi")
   (ashiftrt 

[PATCH] Simplify "1 - bool_val" to "bool_val ^ 1"

2023-01-31 Thread Andrew Pinski via Gcc-patches
For bool values, it is easier to deal with
xor 1 rather than having 1 - a. This is because
we are more likely to simplify the xor further in many
cases.

This is a special case for (MASK - b) where MASK
is a powerof2 - 1 and b <= MASK but only for bool
ranges ([0,1]) as that is the main case where the
difference comes into play.

Note this is enabled for gimple folding only
as the ranges are only know while doing gimple
folding and cfun is not always set when fold is called.

OK? Bootstrapped and tested on x86_64-linux-gnu with no
regressions.

gcc/ChangeLog:

PR tree-optimization/108355
PR tree-optimization/96921
* match.pd: Add pattern for "1 - bool_val".

gcc/testsuite/ChangeLog:

PR tree-optimization/108355
PR tree-optimization/96921
* gcc.dg/tree-ssa/bool-minus-1.c: New test.
* gcc.dg/tree-ssa/bool-minus-2.c: New test.
* gcc.dg/tree-ssa/pr108354-1.c: New test.
---
 gcc/match.pd | 13 
 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c | 11 +++
 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c | 33 
 gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c   | 26 +++
 4 files changed, 83 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c

diff --git a/gcc/match.pd b/gcc/match.pd
index f605b798c44..c9e8bebede2 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1732,6 +1732,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (if (!FIXED_POINT_TYPE_P (type))
  (plus @0 (negate @1
 
+#if GIMPLE
+/* 1 - a is a ^ 1 if a had a bool range. */
+/* This is only enabled for gimple as sometimes
+   cfun is not set for the function which contains
+   the SSA_NAME (e.g. while IPA passes are happening,
+   fold might be called).  */
+(simplify
+ (minus integer_onep@0 SSA_NAME@1)
+  (if (INTEGRAL_TYPE_P (type)
+   && ssa_name_has_boolean_range (@1))
+   (bit_xor @1 @0)))
+#endif
+
 /* Other simplifications of negation (c.f. fold_negate_expr_1).  */
 (simplify
  (negate (mult:c@0 @1 negate_expr_p@2))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
new file mode 100644
index 000..e434ff9507a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
@@ -0,0 +1,11 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+_Bool
+foo (_Bool a)
+{
+  int c = 1 - a;
+  return c;
+}
+
+/* { dg-final { scan-tree-dump-times "1 - " 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "~a" 1 "optimized" } } */
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
new file mode 100644
index 000..b77d36c1d3c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
@@ -0,0 +1,33 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+_Bool
+foo (_Bool a, _Bool b)
+{
+  int c = 1 - a;
+  int d = 1 - b;
+  int e = c & d;
+  return 1 - e;
+}
+
+_Bool
+bar (_Bool a, _Bool b)
+{
+  int c = 1 - a;
+  int d = 1 - b;
+  _Bool e = c & d;
+  return 1 - e;
+}
+
+_Bool
+baz (_Bool a, _Bool b)
+{
+  _Bool c = 1 - a;
+  _Bool d = 1 - b;
+  _Bool e = c & d;
+  return 1 - e;
+}
+
+/* { dg-final { scan-tree-dump-times "1 - " 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "~a" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "~b" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "a_\[0-9\]+.D. \\\| b_\[0-9\]+.D." 3 
"optimized" } } */
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c
new file mode 100644
index 000..60d1dbc281e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c
@@ -0,0 +1,26 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int b;
+int *c;
+int e;
+static int *f = 
+int g;
+void foo();
+short(a)(short h, short i) { return h - i; }
+int(d)(int h) { return h == 83647 ? 0 : -h; }
+int main() {
+  short j;
+  int *k = , *l = 
+  *f = 0 == c;
+  j = a(0 != 2, *k);
+  if (d(j ^ (0 == l || *k)) != *k)
+;
+  else
+foo();
+  c = 
+}
+
+/* { dg-final { scan-tree-dump-times " 1 - " 0 "optimized" } } */
+/* There should be no calls to foo. */
+/* { dg-final { scan-tree-dump-times "foo " 0 "optimized" } } */
+
-- 
2.17.1



[PATCH] Simplify "1 - bool_val" to "bool_val ^ 1"

2023-01-31 Thread Andrew Pinski via Gcc-patches
For bool values, it is easier to deal with
xor 1 rather than having 1 - a. This is because
we are more likely to simplify the xor further in many
cases.

This is a special case for (MASK - b) where MASK
is a powerof2 - 1 and b <= MASK but only for bool
ranges ([0,1]) as that is the main case where the
difference comes into play.

Note this is enabled for gimple folding only
as the ranges are only know while doing gimple
folding and cfun is not always set when fold is called.

OK? Bootstrapped and tested on x86_64-linux-gnu with no
regressions.

gcc/ChangeLog:

PR tree-optimization/108355
PR tree-optimization/96921
* match.pd: Add pattern for "1 - bool_val".

gcc/testsuite/ChangeLog:

PR tree-optimization/108355
PR tree-optimization/96921
* gcc.dg/tree-ssa/bool-minus-1.c: New test.
* gcc.dg/tree-ssa/bool-minus-2.c: New test.
* gcc.dg/tree-ssa/pr108354-1.c: New test.
---
 gcc/match.pd | 13 
 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c | 11 +++
 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c | 33 
 gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c   | 26 +++
 4 files changed, 83 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c

diff --git a/gcc/match.pd b/gcc/match.pd
index f605b798c44..c9e8bebede2 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1732,6 +1732,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (if (!FIXED_POINT_TYPE_P (type))
  (plus @0 (negate @1
 
+#if GIMPLE
+/* 1 - a is a ^ 1 if a had a bool range. */
+/* This is only enabled for gimple as sometimes
+   cfun is not set for the function which contains
+   the SSA_NAME (e.g. while IPA passes are happening,
+   fold might be called).  */
+(simplify
+ (minus integer_onep@0 SSA_NAME@1)
+  (if (INTEGRAL_TYPE_P (type)
+   && ssa_name_has_boolean_range (@1))
+   (bit_xor @1 @0)))
+#endif
+
 /* Other simplifications of negation (c.f. fold_negate_expr_1).  */
 (simplify
  (negate (mult:c@0 @1 negate_expr_p@2))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
new file mode 100644
index 000..e434ff9507a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c
@@ -0,0 +1,11 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+_Bool
+foo (_Bool a)
+{
+  int c = 1 - a;
+  return c;
+}
+
+/* { dg-final { scan-tree-dump-times "1 - " 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "~a" 1 "optimized" } } */
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
new file mode 100644
index 000..b77d36c1d3c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c
@@ -0,0 +1,33 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+_Bool
+foo (_Bool a, _Bool b)
+{
+  int c = 1 - a;
+  int d = 1 - b;
+  int e = c & d;
+  return 1 - e;
+}
+
+_Bool
+bar (_Bool a, _Bool b)
+{
+  int c = 1 - a;
+  int d = 1 - b;
+  _Bool e = c & d;
+  return 1 - e;
+}
+
+_Bool
+baz (_Bool a, _Bool b)
+{
+  _Bool c = 1 - a;
+  _Bool d = 1 - b;
+  _Bool e = c & d;
+  return 1 - e;
+}
+
+/* { dg-final { scan-tree-dump-times "1 - " 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "~a" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "~b" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "a_\[0-9\]+.D. \\\| b_\[0-9\]+.D." 3 
"optimized" } } */
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c
new file mode 100644
index 000..60d1dbc281e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c
@@ -0,0 +1,26 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int b;
+int *c;
+int e;
+static int *f = 
+int g;
+void foo();
+short(a)(short h, short i) { return h - i; }
+int(d)(int h) { return h == 83647 ? 0 : -h; }
+int main() {
+  short j;
+  int *k = , *l = 
+  *f = 0 == c;
+  j = a(0 != 2, *k);
+  if (d(j ^ (0 == l || *k)) != *k)
+;
+  else
+foo();
+  c = 
+}
+
+/* { dg-final { scan-tree-dump-times " 1 - " 0 "optimized" } } */
+/* There should be no calls to foo. */
+/* { dg-final { scan-tree-dump-times "foo " 0 "optimized" } } */
+
-- 
2.17.1



[pushed] c++: aggregate base and TARGET_EXPR_ELIDING_P [PR108559]

2023-01-31 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

We also need to split up a CONSTRUCTOR in cp_genericize_init if we need to
add extra copy constructor calls to deal with CWG2403.

PR c++/108559

gcc/cp/ChangeLog:

* cp-gimplify.cc (any_non_eliding_target_exprs): New.
(cp_genericize_init): Check it.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/aggr-base13.C: New test.
---
 gcc/cp/cp-gimplify.cc| 22 +++---
 gcc/testsuite/g++.dg/cpp1z/aggr-base13.C | 19 +++
 2 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/aggr-base13.C

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index a35cedd05cc..9929d29981a 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -893,6 +893,21 @@ omp_cxx_notice_variable (struct cp_genericize_omp_taskreg 
*omp_ctx, tree decl)
 }
 }
 
+/* True if any of the element initializers in CTOR are TARGET_EXPRs that are
+   not expected to elide, e.g. because unsafe_copy_elision_p is true.  */
+
+static bool
+any_non_eliding_target_exprs (tree ctor)
+{
+  for (const constructor_elt  : *CONSTRUCTOR_ELTS (ctor))
+{
+  if (TREE_CODE (e.value) == TARGET_EXPR
+ && !TARGET_EXPR_ELIDING_P (e.value))
+   return true;
+}
+  return false;
+}
+
 /* If we might need to clean up a partially constructed object, break down the
CONSTRUCTOR with split_nonconstant_init.  Also expand VEC_INIT_EXPR at this
point.  If initializing TO with FROM is non-trivial, overwrite *REPLACE with
@@ -904,10 +919,11 @@ cp_genericize_init (tree *replace, tree from, tree to)
   tree init = NULL_TREE;
   if (TREE_CODE (from) == VEC_INIT_EXPR)
 init = expand_vec_init_expr (to, from, tf_warning_or_error);
-  else if (flag_exceptions
-  && TREE_CODE (from) == CONSTRUCTOR
+  else if (TREE_CODE (from) == CONSTRUCTOR
   && TREE_SIDE_EFFECTS (from)
-  && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (from)))
+  && ((flag_exceptions
+   && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (from)))
+  || any_non_eliding_target_exprs (from)))
 {
   to = cp_stabilize_reference (to);
   replace_placeholders (from, to);
diff --git a/gcc/testsuite/g++.dg/cpp1z/aggr-base13.C 
b/gcc/testsuite/g++.dg/cpp1z/aggr-base13.C
new file mode 100644
index 000..c4c7ee0e8f0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/aggr-base13.C
@@ -0,0 +1,19 @@
+// PR c++/108559
+// { dg-do compile { target c++17 } }
+
+struct A {
+  int g = 0;
+
+  A() {}
+  A(const A&) {}
+};
+
+struct B : A {};
+
+A u() { return A{}; }
+
+int bug() { return B{u()}.g; }
+
+int main() {
+  return 0;
+}

base-commit: a9fbc6687faa09bf045c0fcee7960b7fef796fcc
-- 
2.31.1



Re: [PATCH] libsanitizer: cherry-pick commit 742bcbf685bc from upstream

2023-01-31 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 31, 2023 at 02:39:54PM -0800, H.J. Lu wrote:
> cherry-pick:
> 
> 742bcbf685bc compiler-rt/lib: Add .Linterceptor_sigsetjmp
> 
>   PR sanitizer/108106
>   * hwasan/hwasan_setjmp_x86_64.S (__interceptor_setjmp): Jump
>   to .Linterceptor_sigsetjmp instead of __interceptor_sigsetjmp.
>   (__interceptor_sigsetjmp): Add a local alias,
>   .Linterceptor_sigsetjmp.

LGTM, thanks.

Jakub



[pushed] wwwdocs: gcc-5: Fix deep link into GDB manual

2023-01-31 Thread Gerald Pfeifer
A slightly tricky one, and I figured using the single-page version of that 
document is going to be more resilient in the future.

Pushed.

Gerald
---
 htdocs/gcc-5/changes.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/gcc-5/changes.html b/htdocs/gcc-5/changes.html
index 893e35de..201a039f 100644
--- a/htdocs/gcc-5/changes.html
+++ b/htdocs/gcc-5/changes.html
@@ -504,7 +504,7 @@ version 2 and the current setting.
 
 New random number distributions logistic_distribution and
   uniform_on_sphere_distribution as extensions.
-https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethods-In-Python.html;>GDB
+https://sourceware.org/gdb/current/onlinedocs/gdb#Xmethods-In-Python;>GDB
   Xmethods for containers and std::unique_ptr.
   
 
-- 
2.39.1


Re: [PATCH] c++: ICE with -Wlogical-op [PR107755]

2023-01-31 Thread Jason Merrill via Gcc-patches

On 1/31/23 15:41, Marek Polacek wrote:

Here we crash in the middle end because warn_logical_operator calls
build_range_check which calls various fold_* functions and those
don't work too well when we're still processing template trees.  For
instance here we crash because we're converting a RECORD_TYPE to bool.
At this point VIEW_CONVERT_EXPR(b) hasn't yet been converted
to Foo::operator bool ().

I was excited to fix this with instantiation_dependent_expression_p
which can now be called from c-family/ as well, but the problem isn't
that the expression is dependent.  So, p_t_d it is.

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


OK.


PR c++/107755

gcc/cp/ChangeLog:

* call.cc (build_new_op): Don't call warn_logical_operator when
processing a template.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wlogical-op-4.C: New test.
---
  gcc/cp/call.cc|  2 +-
  gcc/testsuite/g++.dg/warn/Wlogical-op-4.C | 23 +++
  2 files changed, 24 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/warn/Wlogical-op-4.C

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 5715a7cd1de..f7c5d9da94b 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -7335,7 +7335,7 @@ build_new_op (const op_location_t , enum tree_code 
code, int flags,
  case TRUTH_ORIF_EXPR:
  case TRUTH_AND_EXPR:
  case TRUTH_OR_EXPR:
-  if (complain & tf_warning)
+  if ((complain & tf_warning) && !processing_template_decl)
warn_logical_operator (loc, code, boolean_type_node,
   code_orig_arg1, arg1,
   code_orig_arg2, arg2);
diff --git a/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C 
b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
new file mode 100644
index 000..745c9117a3d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
@@ -0,0 +1,23 @@
+// PR c++/107755
+// { dg-do compile }
+// { dg-options "-Wlogical-op" }
+
+struct Foo
+{
+  operator bool() const { return false; }
+};
+
+bool a;
+Foo b;
+
+template 
+static bool Bar()
+{
+  return (true && (false ? a : b));
+  return (false || (false ? a : b));
+}
+
+bool Baz()
+{
+  return Bar();
+}

base-commit: b2ec2504af77b35e748067eeb846821d12a6b6b4




[PATCH] libsanitizer: cherry-pick commit 742bcbf685bc from upstream

2023-01-31 Thread H.J. Lu via Gcc-patches
cherry-pick:

742bcbf685bc compiler-rt/lib: Add .Linterceptor_sigsetjmp

PR sanitizer/108106
* hwasan/hwasan_setjmp_x86_64.S (__interceptor_setjmp): Jump
to .Linterceptor_sigsetjmp instead of __interceptor_sigsetjmp.
(__interceptor_sigsetjmp): Add a local alias,
.Linterceptor_sigsetjmp.
---
 libsanitizer/hwasan/hwasan_setjmp_x86_64.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libsanitizer/hwasan/hwasan_setjmp_x86_64.S 
b/libsanitizer/hwasan/hwasan_setjmp_x86_64.S
index 7566c1ea0a5..a5a3858d94d 100644
--- a/libsanitizer/hwasan/hwasan_setjmp_x86_64.S
+++ b/libsanitizer/hwasan/hwasan_setjmp_x86_64.S
@@ -37,13 +37,14 @@ __interceptor_setjmp:
   CFI_STARTPROC
   _CET_ENDBR
   xorl %esi, %esi
-  jmp  __interceptor_sigsetjmp
+  jmp  .Linterceptor_sigsetjmp
   CFI_ENDPROC
 ASM_SIZE(__interceptor_setjmp)
 
 .global __interceptor_sigsetjmp
 ASM_TYPE_FUNCTION(__interceptor_sigsetjmp)
 __interceptor_sigsetjmp:
+.Linterceptor_sigsetjmp:
   CFI_STARTPROC
   _CET_ENDBR
 
-- 
2.39.1



[PATCH] RISC-V: Add vsra.vx C++ API tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* g++.target/riscv/rvv/base/vsra_vx-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vx-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vx-3.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_mu-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_mu-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_mu-3.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tu-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tu-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tu-3.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tum-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tum-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tum-3.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tumu-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tumu-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vx_tumu-3.C: New test.

---
 .../g++.target/riscv/rvv/base/vsra_vx-1.C | 314 ++
 .../g++.target/riscv/rvv/base/vsra_vx-2.C | 314 ++
 .../g++.target/riscv/rvv/base/vsra_vx-3.C | 314 ++
 .../g++.target/riscv/rvv/base/vsra_vx_mu-1.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vx_mu-2.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vx_mu-3.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vx_tu-1.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vx_tu-2.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vx_tu-3.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vx_tum-1.C | 160 +
 .../g++.target/riscv/rvv/base/vsra_vx_tum-2.C | 160 +
 .../g++.target/riscv/rvv/base/vsra_vx_tum-3.C | 160 +
 .../riscv/rvv/base/vsra_vx_tumu-1.C   | 160 +
 .../riscv/rvv/base/vsra_vx_tumu-2.C   | 160 +
 .../riscv/rvv/base/vsra_vx_tumu-3.C   | 160 +
 15 files changed, 2862 insertions(+)
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_mu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_mu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_mu-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tu-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tum-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tum-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tum-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tumu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tumu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx_tumu-3.C

diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx-1.C 
b/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx-1.C
new file mode 100644
index 000..e3c152f7f4e
--- /dev/null
+++ b/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vx-1.C
@@ -0,0 +1,314 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+vint8mf8_t test___riscv_vsra(vint8mf8_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8mf4_t test___riscv_vsra(vint8mf4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8mf2_t test___riscv_vsra(vint8mf2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8m1_t test___riscv_vsra(vint8m1_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8m2_t test___riscv_vsra(vint8m2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8m4_t test___riscv_vsra(vint8m4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8m8_t test___riscv_vsra(vint8m8_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16mf4_t test___riscv_vsra(vint16mf4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16mf2_t test___riscv_vsra(vint16mf2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16m1_t test___riscv_vsra(vint16m1_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16m2_t test___riscv_vsra(vint16m2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16m4_t test___riscv_vsra(vint16m4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16m8_t test___riscv_vsra(vint16m8_t 

[PATCH] RISC-V: Add vsrl.vx C++ API tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* g++.target/riscv/rvv/base/vsrl_vx-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx-3.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_mu-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_mu-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_mu-3.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tu-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tu-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tu-3.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tum-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tum-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tum-3.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tumu-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tumu-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vx_tumu-3.C: New test.

---
 .../g++.target/riscv/rvv/base/vsrl_vx-1.C | 314 ++
 .../g++.target/riscv/rvv/base/vsrl_vx-2.C | 314 ++
 .../g++.target/riscv/rvv/base/vsrl_vx-3.C | 314 ++
 .../g++.target/riscv/rvv/base/vsrl_vx_mu-1.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vx_mu-2.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vx_mu-3.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vx_tu-1.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vx_tu-2.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vx_tu-3.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vx_tum-1.C | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vx_tum-2.C | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vx_tum-3.C | 160 +
 .../riscv/rvv/base/vsrl_vx_tumu-1.C   | 160 +
 .../riscv/rvv/base/vsrl_vx_tumu-2.C   | 160 +
 .../riscv/rvv/base/vsrl_vx_tumu-3.C   | 160 +
 15 files changed, 2862 insertions(+)
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_mu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_mu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_mu-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tu-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tum-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tum-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tum-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tumu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tumu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx_tumu-3.C

diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx-1.C 
b/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx-1.C
new file mode 100644
index 000..2c4a990fa28
--- /dev/null
+++ b/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vx-1.C
@@ -0,0 +1,314 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+vuint8mf8_t test___riscv_vsrl(vuint8mf8_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8mf4_t test___riscv_vsrl(vuint8mf4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8mf2_t test___riscv_vsrl(vuint8mf2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8m1_t test___riscv_vsrl(vuint8m1_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8m2_t test___riscv_vsrl(vuint8m2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8m4_t test___riscv_vsrl(vuint8m4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8m8_t test___riscv_vsrl(vuint8m8_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16mf4_t test___riscv_vsrl(vuint16mf4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16mf2_t test___riscv_vsrl(vuint16mf2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16m1_t test___riscv_vsrl(vuint16m1_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16m2_t test___riscv_vsrl(vuint16m2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16m4_t test___riscv_vsrl(vuint16m4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16m8_t 

[PATCH] RISC-V: Add shift constraint tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/shift_vx_constraint-1.c: New test.

---
 .../riscv/rvv/base/shift_vx_constraint-1.c| 133 ++
 1 file changed, 133 insertions(+)
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/base/shift_vx_constraint-1.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/shift_vx_constraint-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/shift_vx_constraint-1.c
new file mode 100644
index 000..ae3883c5af9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/shift_vx_constraint-1.c
@@ -0,0 +1,133 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+#include "riscv_vector.h"
+
+/*
+** f1:
+** vsetivli\tzero,4,e32,m1,tu,ma
+** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsll\.vi\tv[0-9]+,\s*v[0-9]+,31
+** vsll\.vi\tv[0-9]+,\s*v[0-9]+,31
+** vse32\.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f1 (void * in, void *out)
+{
+vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
+vint32m1_t v2 = __riscv_vle32_v_i32m1_tu (v, in, 4);
+vint32m1_t v3 = __riscv_vsll_vx_i32m1 (v2, 31, 4);
+vint32m1_t v4 = __riscv_vsll_vx_i32m1_tu (v3, v2, 31, 4);
+__riscv_vse32_v_i32m1 (out, v4, 4);
+}
+
+/*
+** f2:
+** vsetvli\t[a-x0-9]+,zero,e8,mf4,ta,ma
+** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
+** ...
+** vsetivli\tzero,4,e32,m1,ta,ma
+** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
+** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+
+** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+,\s*v0.t
+** vse32.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f2 (void * in, void *out)
+{
+vbool32_t mask = *(vbool32_t*)in;
+asm volatile ("":::"memory");
+vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
+vint32m1_t v2 = __riscv_vle32_v_i32m1_m (mask, in, 4);
+vint32m1_t v3 = __riscv_vsll_vx_i32m1 (v2, 32, 4);
+vint32m1_t v4 = __riscv_vsll_vx_i32m1_m (mask, v3, 32, 4);
+__riscv_vse32_v_i32m1 (out, v4, 4);
+}
+
+/*
+** f3:
+** vsetvli\t[a-x0-9]+,zero,e8,mf4,ta,ma
+** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsetivli\tzero,4,e32,m1,tu,mu
+** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
+** vsll\.vi\tv[0-9]+,\s*v[0-9]+,\s*17
+** vsll\.vi\tv[0-9]+,\s*v[0-9]+,\s*17,\s*v0.t
+** vse32.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f3 (void * in, void *out)
+{
+vbool32_t mask = *(vbool32_t*)in;
+asm volatile ("":::"memory");
+vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
+vint32m1_t v2 = __riscv_vle32_v_i32m1_tumu (mask, v, in, 4);
+vint32m1_t v3 = __riscv_vsll_vx_i32m1 (v2, 17, 4);
+vint32m1_t v4 = __riscv_vsll_vx_i32m1_tumu (mask, v3, v2, 17, 4);
+__riscv_vse32_v_i32m1 (out, v4, 4);
+}
+
+/*
+** f4:
+** vsetivli\tzero,4,e8,mf8,tu,ma
+** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+
+** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+
+** vse8\.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f4 (void * in, void *out, size_t x)
+{
+vint8mf8_t v = __riscv_vle8_v_i8mf8 (in, 4);
+vint8mf8_t v2 = __riscv_vle8_v_i8mf8_tu (v, in, 4);
+vint8mf8_t v3 = __riscv_vsll_vx_i8mf8 (v2, x, 4);
+vint8mf8_t v4 = __riscv_vsll_vx_i8mf8_tu (v3, v2, x, 4);
+__riscv_vse8_v_i8mf8 (out, v4, 4);
+}
+
+/*
+** f5:
+** vsetvli\t[a-x0-9]+,zero,e8,mf8,ta,ma
+** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsetivli\tzero,4,e8,mf8,ta,ma
+** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
+** vsll\.vi\tv[0-9]+,\s*v[0-9]+,\s*5
+** vsll\.vi\tv[0-9]+,\s*v[0-9]+,\s*5,\s*v0.t
+** vse8.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f5 (void * in, void *out)
+{
+vbool64_t mask = *(vbool64_t*)in;
+asm volatile ("":::"memory");
+vint8mf8_t v = __riscv_vle8_v_i8mf8 (in, 4);
+vint8mf8_t v2 = __riscv_vle8_v_i8mf8_m (mask, in, 4);
+vint8mf8_t v3 = __riscv_vsll_vx_i8mf8 (v2, 5, 4);
+vint8mf8_t v4 = __riscv_vsll_vx_i8mf8_m (mask, v3, 5, 4);
+__riscv_vse8_v_i8mf8 (out, v4, 4);
+}
+
+/*
+** f6:
+** vsetvli\t[a-x0-9]+,zero,e8,mf8,ta,ma
+** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsetivli\tzero,4,e8,mf8,tu,mu
+** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
+** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+
+** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+,\s*v0.t
+** vse8.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f6 (void * in, void *out, size_t x)
+{
+vbool64_t mask = *(vbool64_t*)in;
+asm volatile ("":::"memory");
+vint8mf8_t v = __riscv_vle8_v_i8mf8 (in, 4);
+vint8mf8_t v2 = __riscv_vle8_v_i8mf8_tumu (mask, v, in, 4);
+vint8mf8_t v3 = __riscv_vsll_vx_i8mf8 (v2, x, 4);
+vint8mf8_t v4 = __riscv_vsll_vx_i8mf8_tumu (mask, v3, v2, x, 4);
+__riscv_vse8_v_i8mf8 (out, v4, 4);
+}
-- 
2.36.3



[PATCH] RISC-V: Add vsra.vx C API tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/vsra_vx-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_m-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_m-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_m-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_mu-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_mu-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_mu-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tu-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tu-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tu-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tum-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tum-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tum-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tumu-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tumu-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vx_tumu-3.c: New test.

---
 .../gcc.target/riscv/rvv/base/vsra_vx-1.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx-2.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx-3.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_m-1.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_m-2.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_m-3.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_mu-1.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_mu-2.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_mu-3.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_tu-1.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_tu-2.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_tu-3.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_tum-1.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_tum-2.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vx_tum-3.c | 160 ++
 .../riscv/rvv/base/vsra_vx_tumu-1.c   | 160 ++
 .../riscv/rvv/base/vsra_vx_tumu-2.c   | 160 ++
 .../riscv/rvv/base/vsra_vx_tumu-3.c   | 160 ++
 18 files changed, 2880 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_m-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_m-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_m-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_mu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_mu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_mu-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tu-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tum-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tum-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tum-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tumu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tumu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx_tumu-3.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx-1.c
new file mode 100644
index 000..7a7a5a1a933
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vx-1.c
@@ -0,0 +1,160 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+vint8mf8_t test___riscv_vsra_vx_i8mf8(vint8mf8_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra_vx_i8mf8(op1,shift,vl);
+}
+
+
+vint8mf4_t test___riscv_vsra_vx_i8mf4(vint8mf4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra_vx_i8mf4(op1,shift,vl);
+}
+
+
+vint8mf2_t test___riscv_vsra_vx_i8mf2(vint8mf2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra_vx_i8mf2(op1,shift,vl);
+}
+
+
+vint8m1_t test___riscv_vsra_vx_i8m1(vint8m1_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra_vx_i8m1(op1,shift,vl);
+}
+
+
+vint8m2_t test___riscv_vsra_vx_i8m2(vint8m2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsra_vx_i8m2(op1,shift,vl);
+}
+
+
+vint8m4_t test___riscv_vsra_vx_i8m4(vint8m4_t op1,size_t 

[PATCH] RISC-V: Add vsrl.vx C API tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/vsrl_vx-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_m-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_m-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_m-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_mu-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_mu-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_mu-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tu-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tu-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tu-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tum-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tum-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tum-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tumu-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tumu-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vx_tumu-3.c: New test.

---
 .../gcc.target/riscv/rvv/base/vsrl_vx-1.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx-2.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx-3.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_m-1.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_m-2.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_m-3.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_mu-1.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_mu-2.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_mu-3.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_tu-1.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_tu-2.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_tu-3.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_tum-1.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_tum-2.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vx_tum-3.c | 160 ++
 .../riscv/rvv/base/vsrl_vx_tumu-1.c   | 160 ++
 .../riscv/rvv/base/vsrl_vx_tumu-2.c   | 160 ++
 .../riscv/rvv/base/vsrl_vx_tumu-3.c   | 160 ++
 18 files changed, 2880 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_m-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_m-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_m-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_mu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_mu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_mu-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tu-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tum-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tum-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tum-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tumu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tumu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx_tumu-3.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx-1.c
new file mode 100644
index 000..284289a59f4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vx-1.c
@@ -0,0 +1,160 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+vuint8mf8_t test___riscv_vsrl_vx_u8mf8(vuint8mf8_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl_vx_u8mf8(op1,shift,vl);
+}
+
+
+vuint8mf4_t test___riscv_vsrl_vx_u8mf4(vuint8mf4_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl_vx_u8mf4(op1,shift,vl);
+}
+
+
+vuint8mf2_t test___riscv_vsrl_vx_u8mf2(vuint8mf2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl_vx_u8mf2(op1,shift,vl);
+}
+
+
+vuint8m1_t test___riscv_vsrl_vx_u8m1(vuint8m1_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl_vx_u8m1(op1,shift,vl);
+}
+
+
+vuint8m2_t test___riscv_vsrl_vx_u8m2(vuint8m2_t op1,size_t shift,size_t vl)
+{
+return __riscv_vsrl_vx_u8m2(op1,shift,vl);
+}
+
+
+vuint8m4_t test___riscv_vsrl_vx_u8m4(vuint8m4_t 

[PATCH] RISC-V: Add RVV shift.vx C/C++ API support

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/ChangeLog:

* config/riscv/predicates.md (pmode_reg_or_uimm5_operand): New 
predicate.
* config/riscv/riscv-vector-builtins-bases.cc: New class.
* config/riscv/riscv-vector-builtins-functions.def (vsll): Ditto.
(vsra): Ditto.
(vsrl): Ditto.
* config/riscv/riscv-vector-builtins.cc: Ditto.
* config/riscv/vector.md (@pred__scalar): New pattern.

---
 gcc/config/riscv/predicates.md|  8 ++
 .../riscv/riscv-vector-builtins-bases.cc  | 10 ++-
 .../riscv/riscv-vector-builtins-functions.def |  3 +++
 gcc/config/riscv/riscv-vector-builtins.cc | 13 ++
 gcc/config/riscv/vector.md| 26 +++
 5 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md
index 57f7ddfbd7d..895831443e1 100644
--- a/gcc/config/riscv/predicates.md
+++ b/gcc/config/riscv/predicates.md
@@ -301,6 +301,14 @@
(and (match_code "const_vector")
 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 
31)"
 
+;; pmode_reg_or_uimm5_operand can be used by vsll.vx/vsrl.vx/vsra.vx 
instructions.
+;; Since it has the same predicate with vector_length_operand which allows 
register
+;; or immediate (0 ~ 31), we define this predicate same as 
vector_length_operand here.
+;; We don't use vector_length_operand directly to predicate 
vsll.vx/vsrl.vx/vsra.vx
+;; since it may be confusing.
+(define_special_predicate "pmode_reg_or_uimm5_operand"
+  (match_operand 0 "vector_length_operand"))
+
 (define_special_predicate "pmode_reg_or_0_operand"
   (ior (match_operand 0 "const_0_operand")
(match_operand 0 "pmode_register_operand")))
diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc 
b/gcc/config/riscv/riscv-vector-builtins-bases.cc
index f4256fedc5b..00d357a0d36 100644
--- a/gcc/config/riscv/riscv-vector-builtins-bases.cc
+++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc
@@ -163,7 +163,15 @@ class binop : public function_base
 public:
   rtx expand (function_expander ) const override
   {
-return e.use_exact_insn (code_for_pred (CODE, e.vector_mode ()));
+switch (e.op_info->op)
+  {
+  case OP_TYPE_vx:
+   return e.use_exact_insn (code_for_pred_scalar (CODE, e.vector_mode ()));
+  case OP_TYPE_vv:
+   return e.use_exact_insn (code_for_pred (CODE, e.vector_mode ()));
+  default:
+   gcc_unreachable ();
+  }
   }
 };
 
diff --git a/gcc/config/riscv/riscv-vector-builtins-functions.def 
b/gcc/config/riscv/riscv-vector-builtins-functions.def
index 9f9678ab6dd..b543946c72e 100644
--- a/gcc/config/riscv/riscv-vector-builtins-functions.def
+++ b/gcc/config/riscv/riscv-vector-builtins-functions.def
@@ -80,5 +80,8 @@ DEF_RVV_FUNCTION (vdiv, binop, full_preds, iu_vvv_ops)
 DEF_RVV_FUNCTION (vrem, binop, full_preds, iu_vvv_ops)
 DEF_RVV_FUNCTION (vdivu, binop, full_preds, iu_vvv_ops)
 DEF_RVV_FUNCTION (vremu, binop, full_preds, iu_vvv_ops)
+DEF_RVV_FUNCTION (vsll, binop, full_preds, iu_shift_vvx_ops)
+DEF_RVV_FUNCTION (vsra, binop, full_preds, iu_shift_vvx_ops)
+DEF_RVV_FUNCTION (vsrl, binop, full_preds, iu_shift_vvx_ops)
 
 #undef DEF_RVV_FUNCTION
diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 3a6c2c7c6f2..12fea2b3594 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -249,6 +249,11 @@ static CONSTEXPR const rvv_arg_type_info shift_vv_args[]
   = {rvv_arg_type_info (RVV_BASE_vector),
  rvv_arg_type_info (RVV_BASE_shift_vector), rvv_arg_type_info_end};
 
+/* A list of args for vector_type func (vector_type, size) function.  */
+static CONSTEXPR const rvv_arg_type_info vector_size_args[]
+  = {rvv_arg_type_info (RVV_BASE_vector), rvv_arg_type_info (RVV_BASE_size),
+ rvv_arg_type_info_end};
+
 /* A list of none preds that will be registered for intrinsic functions.  */
 static CONSTEXPR const predication_type_index none_preds[]
   = {PRED_TYPE_none, NUM_PRED_TYPES};
@@ -405,6 +410,14 @@ static CONSTEXPR const rvv_op_info iu_shift_vvv_ops
  rvv_arg_type_info (RVV_BASE_vector), /* Return type */
  shift_vv_args /* Args */};
 
+/* A static operand information for vector_type func (vector_type, size_t)
+ * function registration. */
+static CONSTEXPR const rvv_op_info iu_shift_vvx_ops
+  = {iu_ops, /* Types */
+ OP_TYPE_vx, /* Suffix */
+ rvv_arg_type_info (RVV_BASE_vector), /* Return type */
+ vector_size_args /* Args */};
+
 /* A list of all RVV intrinsic functions.  */
 static function_group_info function_groups[] = {
 #define DEF_RVV_FUNCTION(NAME, SHAPE, PREDS, OPS_INFO) 
\
diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md
index e8d75f164e3..36b0e07728c 100644
--- a/gcc/config/riscv/vector.md
+++ b/gcc/config/riscv/vector.md
@@ 

[PATCH] c++: ICE with -Wlogical-op [PR107755]

2023-01-31 Thread Marek Polacek via Gcc-patches
Here we crash in the middle end because warn_logical_operator calls
build_range_check which calls various fold_* functions and those
don't work too well when we're still processing template trees.  For
instance here we crash because we're converting a RECORD_TYPE to bool.
At this point VIEW_CONVERT_EXPR(b) hasn't yet been converted
to Foo::operator bool ().

I was excited to fix this with instantiation_dependent_expression_p
which can now be called from c-family/ as well, but the problem isn't
that the expression is dependent.  So, p_t_d it is.

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

PR c++/107755

gcc/cp/ChangeLog:

* call.cc (build_new_op): Don't call warn_logical_operator when
processing a template.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wlogical-op-4.C: New test.
---
 gcc/cp/call.cc|  2 +-
 gcc/testsuite/g++.dg/warn/Wlogical-op-4.C | 23 +++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wlogical-op-4.C

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 5715a7cd1de..f7c5d9da94b 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -7335,7 +7335,7 @@ build_new_op (const op_location_t , enum tree_code 
code, int flags,
 case TRUTH_ORIF_EXPR:
 case TRUTH_AND_EXPR:
 case TRUTH_OR_EXPR:
-  if (complain & tf_warning)
+  if ((complain & tf_warning) && !processing_template_decl)
warn_logical_operator (loc, code, boolean_type_node,
   code_orig_arg1, arg1,
   code_orig_arg2, arg2);
diff --git a/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C 
b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
new file mode 100644
index 000..745c9117a3d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
@@ -0,0 +1,23 @@
+// PR c++/107755
+// { dg-do compile }
+// { dg-options "-Wlogical-op" }
+
+struct Foo
+{
+  operator bool() const { return false; }
+};
+
+bool a;
+Foo b;
+
+template 
+static bool Bar()
+{
+  return (true && (false ? a : b));
+  return (false || (false ? a : b));
+}
+
+bool Baz()
+{
+  return Bar();
+}

base-commit: b2ec2504af77b35e748067eeb846821d12a6b6b4
-- 
2.39.1



[PATCH] PR tree-optimization/108356 - Ranger cache - always use range_from_dom when updating.

2023-01-31 Thread Andrew MacLeod via Gcc-patches

This turned out to be a more interesting problem than I wanted.

the situation boils down to:


# g_5 = PHI <0(2), 2(8)>
  if (g_5 <= 1)
    goto ; [INV]

 :
  if (g_5 != 0)
    goto ; [INV]
  else
    goto ; [INV]

   :
  c = 0;

   :
    goto ; [INV]

 We globally know that g_5 is [0,0][2,2]
we also know that 10->4 , g_5 will be [0,0]
Which means we also know that that the branch in bb_4 will never be 
taken, and will always go to bb 8.
THis is all processed in EVRP, the branch is changed, and the next time 
VRP is called, we blow the block with c = 0 like we want...


Unfortunately it doesnt happen within EVRP because when this updated 
range for g_5 is propagated in the cache, it was tripping over a shotcut 
which tried to avoid using lookups when it thinks it didnt matter, and 
would occasionally drop back to the global range.


In particular, the cache had originally propagated [0,0][2,2] as the on 
entry range to bb8. when we rewrite the branch, we mark 4->7 and 7->8  
as unexecutable edges, then propagate the new range for g_5..  This 
requires recalculating the existing range on entry to bb8.


It properly picked up [0,0] from 4->8, but when the cache query checked 
the range from 7->8, it discovered that no value was yet set, so instead 
of looking it up, it fell back to the global range of [0,0][2,2].  If it 
properly calculates that edge instead, it comes up with UNDEFINED (as it 
is unexecutable) and results in [0,0]... and EVRP then also removes the 
block is c = 0 in.


By picking up the global value, it still thought 2 was a possibility 
later on, and a single VRP pass couldn't eliminate the branch ultimately 
leading to the store... it required a second one with the adjusted CFG 
to catch it.


This patch tells the cache to always do a read-only scan of the 
dominator tree to find the nearest actual value and use that instead.  
This may solve other lingering weird propagation issues.


I also ran a performance run on this change. It does slow VRP by down 
about 1%, but the overall change is nominal at around 0.05%.


Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK?

Andrew

From ddb9df254ed2bc5f11bdde213e1485d7971a25d9 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod 
Date: Tue, 10 Jan 2023 13:40:56 -0500
Subject: [PATCH] Ranger cache - always use range_from_dom when updating.

When updating an existing range, if we dont query the dom tree, we can
get the global range instead of a proper range on some incoming edges
which cause the range to not be refined properly.

	PR tree-optimization/108356
	gcc/
	* gimple-range-cache.cc (ranger_cache::range_on_edge): Always
	do a search of the DOM tree for a range.

	gcc/testsuite/
	* gcc.dg/pr108356.c: New.
---
 gcc/gimple-range-cache.cc   |  2 +-
 gcc/testsuite/gcc.dg/pr108356.c | 23 +++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr108356.c

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index a8202f0e895..20c444bc4f4 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -998,7 +998,7 @@ bool
 ranger_cache::range_on_edge (vrange , edge e, tree expr)
 {
   if (gimple_range_ssa_p (expr))
-return edge_range (r, e, expr, RFD_NONE);
+return edge_range (r, e, expr, RFD_READ_ONLY);
   return get_tree_range (r, expr, NULL);
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr108356.c b/gcc/testsuite/gcc.dg/pr108356.c
new file mode 100644
index 000..1df6b278e45
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr108356.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+char a;
+static char c = 3;
+char d;
+void foo();
+short(b)(short e, short f) { return e + f; }
+int main() {
+  unsigned g = 0;
+  if (c)
+;
+  else
+foo();
+  for (; g < 2; g = b(g, 2)) {
+d = g ? 0 : a;
+if (g)
+  c = 0;
+  }
+}
+
+
+/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */
-- 
2.39.0



[pushed] c++: Add fixed test [PR102870]

2023-01-31 Thread Marek Polacek via Gcc-patches
This was fixed by r12-7857: now we properly reject instead of
crashing.

PR c++/102870

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/variadic184.C: New test.
---
 gcc/testsuite/g++.dg/cpp0x/variadic184.C | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/variadic184.C

diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic184.C 
b/gcc/testsuite/g++.dg/cpp0x/variadic184.C
new file mode 100644
index 000..458357ac5a9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic184.C
@@ -0,0 +1,12 @@
+// PR c++/102870
+// { dg-do compile { target c++11 } }
+
+template  struct integer_sequence;
+template 
+using make_integer_sequence = integer_sequence<_Tp, __integer_pack(_Num)...>;
+template 
+using make_index_sequence = make_integer_sequence;
+template  struct Tuple;
+template  using type = Tuple...>;
+template  void f() { Tuple>{}; } // { dg-error "parameter 
packs not expanded" }
+int main() { f(); }

base-commit: 77906341efc5cb69aada0645c22850bc83c1d42c
-- 
2.39.1



Re: [PATCH] middle-end/108500 - replace recursive domtree DFS traversal

2023-01-31 Thread Richard Biener via Gcc-patches



> Am 31.01.2023 um 16:59 schrieb Jakub Jelinek via Gcc-patches 
> :
> 
> On Tue, Jan 31, 2023 at 03:45:43PM +0100, Richard Biener wrote:
>> The following replaces the recursive DFS traversal of the dominator
>> tree in assign_dfs_numbers with a tree traversal using the fact
>> that we have recorded parents.
>> 
>> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>> 
>> This makes r13-5325 somewhat obsolete, though not computing the
>> DFS numbers at all is beneficial in the cases where we perform
>> immediate CFG manipulations.
>> 
>> OK for trunk and later branch(es)?
>> 
>> Thanks,
>> Richard.
>> 
>>PR middle-end/108500
>>* dominance.cc (assign_dfs_numbers): Replace recursive DFS
>>with tree traversal algorithm.
> 
> LGTM.
> 
>> diff --git a/gcc/dominance.cc b/gcc/dominance.cc
>> index 099b8fd3f24..34fabe40c18 100644
>> --- a/gcc/dominance.cc
>> +++ b/gcc/dominance.cc
>> @@ -639,18 +639,25 @@ dom_info::calc_idoms ()
>> static void
>> assign_dfs_numbers (struct et_node *node, int *num)
>> {
>> -  struct et_node *son;
>> -
>> -  node->dfs_num_in = (*num)++;
>> -
>> -  if (node->son)
>> +  et_node *n = node;
>> +  while (1)
>> {
>> -  assign_dfs_numbers (node->son, num);
>> -  for (son = node->son->right; son != node->son; son = son->right)
>> -assign_dfs_numbers (son, num);
>> +  n->dfs_num_in = (*num)++;
>> +  if (n->son)
>> +n = n->son;
>> +  else
>> +{
>> +  while (!n->right || n->right == n->father->son)
> 
> Am I right that we could replace !n->right with n == node here too
> (i.e. only node can have NULL father and in that case also NULL
> left/right?  

Yes.

> Though !n->right might result in better code because
> we need to load it anyway for the second comparison.
> 
>> +{
>> +  n->dfs_num_out = (*num)++;
>> +  if (n == node)
>> +return;
>> +  n = n->father;
>> +}
>> +  n->dfs_num_out = (*num)++;
>> +  n = n->right;
>> +}
>> }
>> -
>> -  node->dfs_num_out = (*num)++;
>> }
>> 
> 
>Jakub
> 


Re: [PATCH] RISC-V: Add vsra.vv C++ API tests

2023-01-31 Thread Kito Cheng via Gcc-patches
committed, thanks!

On Tue, Jan 31, 2023 at 9:00 PM  wrote:
>
> From: Ju-Zhe Zhong 
>
> gcc/testsuite/ChangeLog:
>
> * g++.target/riscv/rvv/base/vsra_vv-1.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv-2.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv-3.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_mu-1.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_mu-2.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_mu-3.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tu-1.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tu-2.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tu-3.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tum-1.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tum-2.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tum-3.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tumu-1.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tumu-2.C: New test.
> * g++.target/riscv/rvv/base/vsra_vv_tumu-3.C: New test.
>
> ---
>  .../g++.target/riscv/rvv/base/vsra_vv-1.C | 314 ++
>  .../g++.target/riscv/rvv/base/vsra_vv-2.C | 314 ++
>  .../g++.target/riscv/rvv/base/vsra_vv-3.C | 314 ++
>  .../g++.target/riscv/rvv/base/vsra_vv_mu-1.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsra_vv_mu-2.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsra_vv_mu-3.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsra_vv_tu-1.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsra_vv_tu-2.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsra_vv_tu-3.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsra_vv_tum-1.C | 160 +
>  .../g++.target/riscv/rvv/base/vsra_vv_tum-2.C | 160 +
>  .../g++.target/riscv/rvv/base/vsra_vv_tum-3.C | 160 +
>  .../riscv/rvv/base/vsra_vv_tumu-1.C   | 160 +
>  .../riscv/rvv/base/vsra_vv_tumu-2.C   | 160 +
>  .../riscv/rvv/base/vsra_vv_tumu-3.C   | 160 +
>  15 files changed, 2862 insertions(+)
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-3.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_mu-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_mu-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_mu-3.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tu-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tu-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tu-3.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tum-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tum-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tum-3.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tumu-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tumu-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tumu-3.C
>
> diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-1.C 
> b/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-1.C
> new file mode 100644
> index 000..f7f849c91ff
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-1.C
> @@ -0,0 +1,314 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
> -fno-schedule-insns2" } */
> +
> +#include "riscv_vector.h"
> +
> +vint8mf8_t test___riscv_vsra(vint8mf8_t op1,vuint8mf8_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint8mf4_t test___riscv_vsra(vint8mf4_t op1,vuint8mf4_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint8mf2_t test___riscv_vsra(vint8mf2_t op1,vuint8mf2_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint8m1_t test___riscv_vsra(vint8m1_t op1,vuint8m1_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint8m2_t test___riscv_vsra(vint8m2_t op1,vuint8m2_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint8m4_t test___riscv_vsra(vint8m4_t op1,vuint8m4_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint8m8_t test___riscv_vsra(vint8m8_t op1,vuint8m8_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint16mf4_t test___riscv_vsra(vint16mf4_t op1,vuint16mf4_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint16mf2_t test___riscv_vsra(vint16mf2_t op1,vuint16mf2_t shift,size_t vl)
> +{
> +return __riscv_vsra(op1,shift,vl);
> +}
> +
> +
> +vint16m1_t test___riscv_vsra(vint16m1_t 

Re: [PATCH] RISC-V: Add binop constraint tests

2023-01-31 Thread Kito Cheng via Gcc-patches
committed, thanks!

On Tue, Jan 31, 2023 at 8:39 PM  wrote:
>
> From: Ju-Zhe Zhong 
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/base/binop_vv_constraint-1.c: New test.
>
> ---
>  .../riscv/rvv/base/binop_vv_constraint-1.c| 132 ++
>  1 file changed, 132 insertions(+)
>  create mode 100644 
> gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c 
> b/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c
> new file mode 100644
> index 000..3ab1ccee035
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c
> @@ -0,0 +1,132 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3" } */
> +/* { dg-final { check-function-bodies "**" "" } } */
> +#include "riscv_vector.h"
> +
> +/*
> +** f1:
> +** vsetivli\tzero,4,e32,m1,tu,ma
> +** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
> +** vse32\.v\tv[0-9]+,0\([a-x0-9]+\)
> +** ret
> +*/
> +void f1 (void * in, void *out)
> +{
> +vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
> +vint32m1_t v2 = __riscv_vle32_v_i32m1_tu (v, in, 4);
> +vint32m1_t v3 = __riscv_vadd_vv_i32m1 (v2, v2, 4);
> +vint32m1_t v4 = __riscv_vadd_vv_i32m1_tu (v3, v2, v2, 4);
> +__riscv_vse32_v_i32m1 (out, v4, 4);
> +}
> +
> +/*
> +** f2:
> +** vsetvli\t[a-x0-9]+,zero,e8,mf4,ta,ma
> +** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vsetivli\tzero,4,e32,m1,ta,ma
> +** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t
> +** vse32.v\tv[0-9]+,0\([a-x0-9]+\)
> +** ret
> +*/
> +void f2 (void * in, void *out)
> +{
> +vbool32_t mask = *(vbool32_t*)in;
> +asm volatile ("":::"memory");
> +vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
> +vint32m1_t v2 = __riscv_vle32_v_i32m1_m (mask, in, 4);
> +vint32m1_t v3 = __riscv_vadd_vv_i32m1 (v2, v2, 4);
> +vint32m1_t v4 = __riscv_vadd_vv_i32m1_m (mask, v3, v3, 4);
> +__riscv_vse32_v_i32m1 (out, v4, 4);
> +}
> +
> +/*
> +** f3:
> +** vsetvli\t[a-x0-9]+,zero,e8,mf4,ta,ma
> +** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vsetivli\tzero,4,e32,m1,tu,mu
> +** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t
> +** vse32.v\tv[0-9]+,0\([a-x0-9]+\)
> +** ret
> +*/
> +void f3 (void * in, void *out)
> +{
> +vbool32_t mask = *(vbool32_t*)in;
> +asm volatile ("":::"memory");
> +vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
> +vint32m1_t v2 = __riscv_vle32_v_i32m1_tumu (mask, v, in, 4);
> +vint32m1_t v3 = __riscv_vadd_vv_i32m1 (v2, v2, 4);
> +vint32m1_t v4 = __riscv_vadd_vv_i32m1_tumu (mask, v3, v2, v2, 4);
> +__riscv_vse32_v_i32m1 (out, v4, 4);
> +}
> +
> +/*
> +** f4:
> +** vsetivli\tzero,4,e8,mf8,tu,ma
> +** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
> +** vse8\.v\tv[0-9]+,0\([a-x0-9]+\)
> +** ret
> +*/
> +void f4 (void * in, void *out)
> +{
> +vint8mf8_t v = __riscv_vle8_v_i8mf8 (in, 4);
> +vint8mf8_t v2 = __riscv_vle8_v_i8mf8_tu (v, in, 4);
> +vint8mf8_t v3 = __riscv_vadd_vv_i8mf8 (v2, v2, 4);
> +vint8mf8_t v4 = __riscv_vadd_vv_i8mf8_tu (v3, v2, v2, 4);
> +__riscv_vse8_v_i8mf8 (out, v4, 4);
> +}
> +
> +/*
> +** f5:
> +** vsetvli\t[a-x0-9]+,zero,e8,mf8,ta,ma
> +** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vsetivli\tzero,4,e8,mf8,ta,ma
> +** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t
> +** vse8.v\tv[0-9]+,0\([a-x0-9]+\)
> +** ret
> +*/
> +void f5 (void * in, void *out)
> +{
> +vbool64_t mask = *(vbool64_t*)in;
> +asm volatile ("":::"memory");
> +vint8mf8_t v = __riscv_vle8_v_i8mf8 (in, 4);
> +vint8mf8_t v2 = __riscv_vle8_v_i8mf8_m (mask, in, 4);
> +vint8mf8_t v3 = __riscv_vadd_vv_i8mf8 (v2, v2, 4);
> +vint8mf8_t v4 = __riscv_vadd_vv_i8mf8_m (mask, v3, v3, 4);
> +__riscv_vse8_v_i8mf8 (out, v4, 4);
> +}
> +
> +/*
> +** f6:
> +** vsetvli\t[a-x0-9]+,zero,e8,mf8,ta,ma
> +** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vsetivli\tzero,4,e8,mf8,tu,mu
> +** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
> +** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
> +** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t
> +** vse8.v\tv[0-9]+,0\([a-x0-9]+\)
> +** ret
> +*/
> +void f6 (void * in, void *out)
> +{
> +vbool64_t mask = *(vbool64_t*)in;
> +asm volatile 

Re: [PATCH] RISC-V: Add vsrl.vv C++ API tests

2023-01-31 Thread Kito Cheng via Gcc-patches
committed, thanks!

On Tue, Jan 31, 2023 at 8:58 PM  wrote:
>
> From: Ju-Zhe Zhong 
>
> gcc/testsuite/ChangeLog:
>
> * g++.target/riscv/rvv/base/vsrl_vv-1.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv-2.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv-3.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_mu-1.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_mu-2.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_mu-3.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tu-1.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tu-2.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tu-3.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tum-1.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tum-2.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tum-3.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tumu-1.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tumu-2.C: New test.
> * g++.target/riscv/rvv/base/vsrl_vv_tumu-3.C: New test.
>
> ---
>  .../g++.target/riscv/rvv/base/vsrl_vv-1.C | 314 ++
>  .../g++.target/riscv/rvv/base/vsrl_vv-2.C | 314 ++
>  .../g++.target/riscv/rvv/base/vsrl_vv-3.C | 314 ++
>  .../g++.target/riscv/rvv/base/vsrl_vv_mu-1.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsrl_vv_mu-2.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsrl_vv_mu-3.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsrl_vv_tu-1.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsrl_vv_tu-2.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsrl_vv_tu-3.C  | 160 +
>  .../g++.target/riscv/rvv/base/vsrl_vv_tum-1.C | 160 +
>  .../g++.target/riscv/rvv/base/vsrl_vv_tum-2.C | 160 +
>  .../g++.target/riscv/rvv/base/vsrl_vv_tum-3.C | 160 +
>  .../riscv/rvv/base/vsrl_vv_tumu-1.C   | 160 +
>  .../riscv/rvv/base/vsrl_vv_tumu-2.C   | 160 +
>  .../riscv/rvv/base/vsrl_vv_tumu-3.C   | 160 +
>  15 files changed, 2862 insertions(+)
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-3.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_mu-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_mu-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_mu-3.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tu-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tu-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tu-3.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tum-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tum-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tum-3.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tumu-1.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tumu-2.C
>  create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tumu-3.C
>
> diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-1.C 
> b/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-1.C
> new file mode 100644
> index 000..21b6f49eb75
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-1.C
> @@ -0,0 +1,314 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
> -fno-schedule-insns2" } */
> +
> +#include "riscv_vector.h"
> +
> +vuint8mf8_t test___riscv_vsrl(vuint8mf8_t op1,vuint8mf8_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint8mf4_t test___riscv_vsrl(vuint8mf4_t op1,vuint8mf4_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint8mf2_t test___riscv_vsrl(vuint8mf2_t op1,vuint8mf2_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint8m1_t test___riscv_vsrl(vuint8m1_t op1,vuint8m1_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint8m2_t test___riscv_vsrl(vuint8m2_t op1,vuint8m2_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint8m4_t test___riscv_vsrl(vuint8m4_t op1,vuint8m4_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint8m8_t test___riscv_vsrl(vuint8m8_t op1,vuint8m8_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint16mf4_t test___riscv_vsrl(vuint16mf4_t op1,vuint16mf4_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint16mf2_t test___riscv_vsrl(vuint16mf2_t op1,vuint16mf2_t shift,size_t vl)
> +{
> +return __riscv_vsrl(op1,shift,vl);
> +}
> +
> +
> +vuint16m1_t 

Re: [PATCH] RISC-V: Add vsra.vv C API tests

2023-01-31 Thread Kito Cheng via Gcc-patches
committed, thanks!

On Tue, Jan 31, 2023 at 8:19 PM  wrote:
>
> From: Ju-Zhe Zhong 
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/base/vsra_vv-1.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv-2.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv-3.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_m-1.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_m-2.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_m-3.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_mu-1.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_mu-2.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_mu-3.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tu-1.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tu-2.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tu-3.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tum-1.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tum-2.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tum-3.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tumu-1.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tumu-2.c: New test.
> * gcc.target/riscv/rvv/base/vsra_vv_tumu-3.c: New test.
>
>
> ---
>  .../gcc.target/riscv/rvv/base/vsra_vv-1.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv-2.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv-3.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_m-1.c   | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_m-2.c   | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_m-3.c   | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_mu-1.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_mu-2.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_mu-3.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_tu-1.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_tu-2.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_tu-3.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_tum-1.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_tum-2.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsra_vv_tum-3.c | 160 ++
>  .../riscv/rvv/base/vsra_vv_tumu-1.c   | 160 ++
>  .../riscv/rvv/base/vsra_vv_tumu-2.c   | 160 ++
>  .../riscv/rvv/base/vsra_vv_tumu-3.c   | 160 ++
>  18 files changed, 2880 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_m-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_m-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_m-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_mu-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_mu-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_mu-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tu-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tu-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tu-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tum-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tum-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tum-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tumu-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tumu-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tumu-3.c
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-1.c 
> b/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-1.c
> new file mode 100644
> index 000..01dee8d57fd
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-1.c
> @@ -0,0 +1,160 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
> -fno-schedule-insns2" } */
> +
> +#include "riscv_vector.h"
> +
> +vint8mf8_t test___riscv_vsra_vv_i8mf8(vint8mf8_t op1,vuint8mf8_t 
> shift,size_t vl)
> +{
> +return __riscv_vsra_vv_i8mf8(op1,shift,vl);
> +}
> +
> +
> +vint8mf4_t test___riscv_vsra_vv_i8mf4(vint8mf4_t op1,vuint8mf4_t 
> shift,size_t vl)
> +{
> +return __riscv_vsra_vv_i8mf4(op1,shift,vl);
> +}
> +
> +
> +vint8mf2_t test___riscv_vsra_vv_i8mf2(vint8mf2_t op1,vuint8mf2_t 
> shift,size_t vl)
> +{
> +return __riscv_vsra_vv_i8mf2(op1,shift,vl);
> +}
> +
> +
> +vint8m1_t test___riscv_vsra_vv_i8m1(vint8m1_t 

Re: [PATCH] RISC-V: Add srl.vv C API tests

2023-01-31 Thread Kito Cheng via Gcc-patches
committed, thanks!

On Tue, Jan 31, 2023 at 8:17 PM  wrote:
>
> From: Ju-Zhe Zhong 
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/base/vsrl_vv-1.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv-2.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv-3.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_m-1.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_m-2.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_m-3.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_mu-1.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_mu-2.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_mu-3.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tu-1.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tu-2.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tu-3.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tum-1.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tum-2.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tum-3.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tumu-1.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tumu-2.c: New test.
> * gcc.target/riscv/rvv/base/vsrl_vv_tumu-3.c: New test.
>
> ---
>  .../gcc.target/riscv/rvv/base/vsrl_vv-1.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv-2.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv-3.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_m-1.c   | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_m-2.c   | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_m-3.c   | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_mu-1.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_mu-2.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_mu-3.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_tu-1.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_tu-2.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_tu-3.c  | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_tum-1.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_tum-2.c | 160 ++
>  .../gcc.target/riscv/rvv/base/vsrl_vv_tum-3.c | 160 ++
>  .../riscv/rvv/base/vsrl_vv_tumu-1.c   | 160 ++
>  .../riscv/rvv/base/vsrl_vv_tumu-2.c   | 160 ++
>  .../riscv/rvv/base/vsrl_vv_tumu-3.c   | 160 ++
>  18 files changed, 2880 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_m-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_m-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_m-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_mu-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_mu-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_mu-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tu-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tu-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tu-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tum-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tum-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tum-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tumu-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tumu-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tumu-3.c
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-1.c 
> b/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-1.c
> new file mode 100644
> index 000..a4c556adda0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-1.c
> @@ -0,0 +1,160 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
> -fno-schedule-insns2" } */
> +
> +#include "riscv_vector.h"
> +
> +vuint8mf8_t test___riscv_vsrl_vv_u8mf8(vuint8mf8_t op1,vuint8mf8_t 
> shift,size_t vl)
> +{
> +return __riscv_vsrl_vv_u8mf8(op1,shift,vl);
> +}
> +
> +
> +vuint8mf4_t test___riscv_vsrl_vv_u8mf4(vuint8mf4_t op1,vuint8mf4_t 
> shift,size_t vl)
> +{
> +return __riscv_vsrl_vv_u8mf4(op1,shift,vl);
> +}
> +
> +
> +vuint8mf2_t test___riscv_vsrl_vv_u8mf2(vuint8mf2_t op1,vuint8mf2_t 
> shift,size_t vl)
> +{
> +return __riscv_vsrl_vv_u8mf2(op1,shift,vl);
> +}
> +
> +
> +vuint8m1_t test___riscv_vsrl_vv_u8m1(vuint8m1_t 

Re: [PATCH] RISC-V: Add integer binary vv C/C++ API support

2023-01-31 Thread Kito Cheng via Gcc-patches
committed with comment log tweak, thanks!

On Tue, Jan 31, 2023 at 8:07 PM  wrote:
>
> From: Ju-Zhe Zhong 
>
> ---
>  gcc/config/riscv/constraints.md   |  10 +
>  gcc/config/riscv/iterators.md |  14 +-
>  gcc/config/riscv/predicates.md|  15 ++
>  .../riscv/riscv-vector-builtins-bases.cc  |  48 +
>  .../riscv/riscv-vector-builtins-bases.h   |  17 ++
>  .../riscv/riscv-vector-builtins-functions.def |  18 ++
>  .../riscv/riscv-vector-builtins-shapes.cc |  25 +++
>  .../riscv/riscv-vector-builtins-shapes.h  |   1 +
>  gcc/config/riscv/riscv-vector-builtins.cc |  38 
>  gcc/config/riscv/riscv-vector-builtins.h  |   1 +
>  gcc/config/riscv/riscv.cc |  10 +
>  gcc/config/riscv/vector-iterators.md  | 183 ++
>  gcc/config/riscv/vector.md|  49 -
>  13 files changed, 421 insertions(+), 8 deletions(-)
>
> diff --git a/gcc/config/riscv/constraints.md b/gcc/config/riscv/constraints.md
> index 7061201ba37..3637380ee47 100644
> --- a/gcc/config/riscv/constraints.md
> +++ b/gcc/config/riscv/constraints.md
> @@ -140,6 +140,16 @@
>(and (match_code "const_vector")
> (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -16, 
> 15)")))
>
> +(define_constraint "vj"
> +  "A vector negated 5-bit signed immediate."
> +  (and (match_code "const_vector")
> +   (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -15, 
> 16)")))
> +
> +(define_constraint "vk"
> +  "A vector 5-bit unsigned immediate."
> +  (and (match_code "const_vector")
> +   (match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 
> 31)")))
> +
>  (define_constraint "Wc0"
>"@internal
>   A constraint that matches a vector of immediate all zeros."
> diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md
> index 0e8dbcc9e7e..9561403419b 100644
> --- a/gcc/config/riscv/iterators.md
> +++ b/gcc/config/riscv/iterators.md
> @@ -196,7 +196,12 @@
>  (xor "xor")
>  (and "and")
>  (plus "add")
> -(minus "sub")])
> +(minus "sub")
> +(smin "smin")
> +(smax "smax")
> +(umin "umin")
> +(umax "umax")
> +(mult "mul")])
>
>  ;;  code attributes
>  (define_code_attr or_optab [(ior "ior")
> @@ -214,7 +219,12 @@
> (xor "xor")
> (and "and")
> (plus "add")
> -   (minus "sub")])
> +   (minus "sub")
> +   (smin "min")
> +   (smax "max")
> +   (umin "minu")
> +   (umax "maxu")
> +   (mult "mul")])
>
>  ; atomics code attribute
>  (define_code_attr atomic_optab
> diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md
> index f9013bbf8bb..57f7ddfbd7d 100644
> --- a/gcc/config/riscv/predicates.md
> +++ b/gcc/config/riscv/predicates.md
> @@ -286,6 +286,21 @@
> (match_test "GET_CODE (op) == UNSPEC
>  && (XINT (op, 1) == UNSPEC_VUNDEF)"
>
> +(define_predicate "vector_arith_operand"
> +  (ior (match_operand 0 "register_operand")
> +   (and (match_code "const_vector")
> +(match_test "riscv_vector::const_vec_all_same_in_range_p (op, 
> -16, 15)"
> +
> +(define_predicate "vector_neg_arith_operand"
> +  (ior (match_operand 0 "register_operand")
> +   (and (match_code "const_vector")
> +(match_test "riscv_vector::const_vec_all_same_in_range_p (op, 
> -15, 16)"
> +
> +(define_predicate "vector_shift_operand"
> +  (ior (match_operand 0 "register_operand")
> +   (and (match_code "const_vector")
> +(match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 
> 31)"
> +
>  (define_special_predicate "pmode_reg_or_0_operand"
>(ior (match_operand 0 "const_0_operand")
> (match_operand 0 "pmode_register_operand")))
> diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc 
> b/gcc/config/riscv/riscv-vector-builtins-bases.cc
> index 129e89f443e..f4256fedc5b 100644
> --- a/gcc/config/riscv/riscv-vector-builtins-bases.cc
> +++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc
> @@ -154,6 +154,19 @@ public:
>}
>  };
>
> +/* Implements
> + * 
> vadd/vsub/vrsub/vand/vor/vxor/vsll/vsra/vsrl/vmin/vmax/vminu/vmaxu/vdiv/vrem/vdivu/vremu/vsadd/vsaddu/vssub/vssubu.
> + */
> +template
> +class binop : public function_base
> +{
> +public:
> +  rtx expand (function_expander ) const override
> +  {
> +return e.use_exact_insn (code_for_pred (CODE, e.vector_mode ()));
> +  }
> +};
> +
>  static CONSTEXPR const vsetvl vsetvl_obj;
>  static CONSTEXPR const vsetvl vsetvlmax_obj;
>  static CONSTEXPR const loadstore vle_obj;
> @@ 

RE: [PATCH 3/3] arm: Fix MVE predicates synthesis [PR 108443]

2023-01-31 Thread Kyrylo Tkachov via Gcc-patches


> -Original Message-
> From: Andre Vieira (lists) 
> Sent: Wednesday, January 25, 2023 5:41 PM
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov ; Richard Earnshaw
> 
> Subject: Re: [PATCH 3/3] arm: Fix MVE predicates synthesis [PR 108443]
> 
> Looks like the first patch was missing a change I had made to prevent
> mve_bool_vec_to_const ICEing if called with a non-vector immediate. Now
> included.
> 
> On 24/01/2023 13:56, Andre Vieira (lists) via Gcc-patches wrote:
> > Hi,
> >
> > This patch fixes the way we synthesize MVE predicate immediates and
> > fixes some other inconsistencies around predicates. For instance this
> > patch fixes the modes used in the vctp intrinsics, to couple them with
> > predicate modes with the appropriate lane numbers. For this V2QI is
> > added to represent a predicate created by vctp64q. The reason we use
> > V2QI and not for instance a V2BI with 8-bit boolean modes is because we
> > are trying to avoid having two 'INT' modes of the same size. We make
> > sure we use the V2QI mode instead of HI for any instruction working on
> > two lanes of 64-bits consuming a predicate.
> >
> > Bootstrapped on aarch64-none-linux-gnu and regression tested on
> > arm-none-eabi and armeb-none-eabi for armv8.1-m.main+mve.fp.
> >
> > OK for trunk?
> >
> > gcc/ChangeLog:
> >
> >      PR target/108443
> >      * config/arm/arm.h (VALID_MVE_PRED_MODE): Add V2QI.
> > * config/arm/arm.cc (thumb2_legitimate_address_p): Use HImode for
> >  addressing MVE predicate modes.
> >  (mve_bool_vec_to_const): Change to represent correct MVE predicate
> >  format.
> >  (arm_hard_regno_mode_ok): Use VALID_MVE_PRED_MODE instead of
> > checking modes.
> >  (arm_vector_mode_supported_p): Likewise.
> >  (arm_mode_to_pred_mode): Add V2QI.
> >  * config/arm/arm-builtins.cc (UNOP_PRED_UNONE_QUALIFIERS): New
> > qualifier.
> >  (UNOP_PRED_PRED_QUALIFIERS): New qualifier
> >  (BINOP_PRED_UNONE_PRED_QUALIFIERS): New qualifier.
> >  (v2qi_UP): New macro.
> >  (v4bi_UP): New macro.
> >  (v8bi_UP): New macro.
> >  (v16bi_UP): New macro.
> >  (arm_expand_builtin_args): Make it able to expand the new predicate
> >  modes.
> >  * config/arm/arm-modes.def (V2QI): New mode.
> >  * config/arm/arm-simd-builtin-types.def (Pred1x16_t, Pred2x8_t
> >  Pred4x4_t): Remove unused predicate builtin types.
> >  * config/arm/arm_mve.h (__arm_vctp16q, __arm_vctp32q,
> __arm_vctp64q,
> >  __arm_vctp8q, __arm_vpnot, __arm_vctp8q_m, __arm_vctp64q_m,
> >  __arm_vctp32q_m, __arm_vctp16q_m): Use predicate modes.
> >  * config/arm/arm_mve_builtins.def (vctp16q, vctp32q, vctp64q, vctp8q,
> >  vpnot, vctp8q_m, vctp16q_m, vctp32q_m, vctp64q_m): Likewise.
> >  * config/arm/constraints.md (DB): Check for VALID_MVE_PRED_MODE
> > instead
> >  of MODE_VECTOR_BOOL.
> >  * config/arm/iterators.md (MVE_7, MVE_7_HI): Add V2QI
> >  (MVE_VPRED): Likewise.
> >      (MVE_vpred): Add V2QI and map upper case predicate modes to
> > lower case.
> >  (MVE_vctp): New mode attribute.
> >  (mode1): Remove.
> >  (VCTPQ): Remove.
> >  (VCTPQ_M): Remove.
> >  * config/arm/mve.md (mve_vctpqhi): Rename this...
> >  (mve_vctpq): ... to this. And use new mode
> >  attributes.
> >  (mve_vpnothi): Rename this...
> >  (mve_vpnotv16bi): ... to this.
> >  (mve_vctpq_mhi): Rename this...
> >  (mve_vctpq_m):... to this.
> >  (mve_vldrdq_gather_base_z_v2di,
> >  mve_vldrdq_gather_offset_z_v2di,
> >  mve_vldrdq_gather_shifted_offset_z_v2di,
> >  mve_vstrdq_scatter_base_p_v2di,
> >  mve_vstrdq_scatter_offset_p_v2di,
> >  mve_vstrdq_scatter_offset_p_v2di_insn,
> >  mve_vstrdq_scatter_shifted_offset_p_v2di,
> >  mve_vstrdq_scatter_shifted_offset_p_v2di_insn,
> >  mve_vstrdq_scatter_base_wb_p_v2di,
> >  mve_vldrdq_gather_base_wb_z_v2di,
> >  mve_vldrdq_gather_base_nowb_z_v2di,
> >  mve_vldrdq_gather_base_wb_z_v2di_insn):  Use V2QI insead of
> > HI for predicates.
> >  * config/arm/unspecs.md (VCTP8Q, VCTP16Q, VCTP32Q, VCTP64Q):
> Replace
> >  these...
> >  (VCTP): ... with this.
> >  (VCTP8Q_M, VCTP16Q_M, VCTP32Q_M, VCTP64Q_M): Replace these...
> >  (VCTP_M): ... with this.
> >  * config/arm/vfp.md (*thumb2_movhi_vfp, *thumb2_movhi_fp16): Use
> > VALID_MVE_PRED_MODE
> >      instead of checking for MODE_VECTOR_BOOL class.
> >
> >
> > gcc/testsuite/ChangeLog:
> >
> >      * gcc.dg/rtl/arm/mve-vxbi.c: Use new predicate modes.
> >      * gcc.target/arm/mve/pr108443-run.c: New test.
> >      * gcc.target/arm/mve/pr108443.c: New test.

diff --git a/gcc/testsuite/gcc.target/arm/mve/pr108443.c 
b/gcc/testsuite/gcc.target/arm/mve/pr108443.c
new file mode 100644
index 
..227d4b11f477a43b95ee981c190c289b84f1a486
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/pr108443.c
@@ -0,0 +1,14 @@
+/* { dg-do 

Re: [PATCH v3] c++: fix ICE with -Wduplicated-cond [PR107593]

2023-01-31 Thread Jason Merrill via Gcc-patches

On 1/30/23 21:34, Marek Polacek wrote:

On Mon, Jan 30, 2023 at 01:12:00PM -0500, Jason Merrill wrote:

On 1/30/23 11:00, Marek Polacek wrote:

On Fri, Jan 27, 2023 at 06:17:00PM -0500, Patrick Palka wrote:

On Fri, 27 Jan 2023, Marek Polacek wrote:


On Fri, Jan 27, 2023 at 05:15:00PM -0500, Patrick Palka wrote:

On Thu, 26 Jan 2023, Marek Polacek via Gcc-patches wrote:


Here we crash because a CAST_EXPR, representing T(), doesn't have
its operand, and operand_equal_p's STRIP_ANY_LOCATION_WRAPPER doesn't
expect that.  (o_e_p is called from warn_duplicated_cond_add_or_warn.)

In the past we've adjusted o_e_p to better cope with template codes,
but in this case I think we just want to avoid attempting to warn
about inst-dependent expressions; I don't think I've ever envisioned
-Wduplicated-cond to warn about them.

The ICE started with r12-6022, two-stage name lookup for overloaded
operators, which gave dependent operators a TREE_TYPE (in particular,
DEPENDENT_OPERATOR_TYPE), so we no longer bail out here in o_e_p:

/* Similar, if either does not have a type (like a template id),
   they aren't equal.  */
if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
  return false;

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

PR c++/107593

gcc/cp/ChangeLog:

* parser.cc (cp_parser_selection_statement): Don't do
-Wduplicated-cond when the condition is dependent.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wduplicated-cond3.C: New test.
---
   gcc/cp/parser.cc  |  3 +-
   gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C | 38 +++
   2 files changed, 40 insertions(+), 1 deletion(-)
   create mode 100644 gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 4cdc1cd472f..3df85d49e16 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -13209,7 +13209,8 @@ cp_parser_selection_statement (cp_parser* parser, bool 
*if_p,
/* Add the condition.  */
condition = finish_if_stmt_cond (condition, statement);
-   if (warn_duplicated_cond)
+   if (warn_duplicated_cond
+   && !instantiation_dependent_expression_p (condition))
  warn_duplicated_cond_add_or_warn (token->location, condition,
);


I noticed warn_duplicated_cond_add_or_warn already has logic to handle
TREE_SIDE_EFFECTS conditions by invaliding the entire chain.  I wonder
if we'd want to do the same for instantiation-dep conditions?


warn_duplicated_cond_add_or_warn lives in c-family/c-warn.cc so I can't
use instantiation_dependent_expression_p there.  Sure, I could write a
C++ wrapper but with my patch we just won't add CONDITION to the chain
which I thought would work just as well.


Or maybe define instantiation_dependent_expression_p in the C front-end to
just return false?


Like this?

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


OK, thanks.


-- >8 --
Here we crash because a CAST_EXPR, representing T(), doesn't have
its operand, and operand_equal_p's STRIP_ANY_LOCATION_WRAPPER doesn't
expect that.  (o_e_p is called from warn_duplicated_cond_add_or_warn.)

In the past we've adjusted o_e_p to better cope with template codes,
but in this case I think we just want to avoid attempting to warn
about inst-dependent expressions; I don't think I've ever envisioned
-Wduplicated-cond to warn about them.  Also destroy the chain when
an inst-dependent expression is encountered to not warn in
Wduplicated-cond4.C.

The ICE started with r12-6022, two-stage name lookup for overloaded
operators, which gave dependent operators a TREE_TYPE (in particular,
DEPENDENT_OPERATOR_TYPE), so we no longer bail out here in o_e_p:

   /* Similar, if either does not have a type (like a template id),
  they aren't equal.  */
   if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
 return false;

PR c++/107593
PR c++/108597

gcc/c-family/ChangeLog:

* c-common.h (instantiation_dependent_expression_p): Declare.
* c-warn.cc (warn_duplicated_cond_add_or_warn): If the condition
is dependent, invalidate the chain.

gcc/c/ChangeLog:

* c-objc-common.cc (instantiation_dependent_expression_p): New.

gcc/cp/ChangeLog:

* cp-tree.h (instantiation_dependent_expression_p): Don't
declare here.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wduplicated-cond3.C: New test.
* g++.dg/warn/Wduplicated-cond4.C: New test.
* g++.dg/warn/Wduplicated-cond5.C: New test.
---
  gcc/c-family/c-common.h   |  1 +
  gcc/c-family/c-warn.cc|  2 +-
  gcc/c/c-objc-common.cc|  8 
  gcc/cp/cp-tree.h  |  1 -
  gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C | 38 +++
  gcc/testsuite/g++.dg/warn/Wduplicated-cond4.C | 17 +
  

Re: [PATCH] middle-end/108500 - replace recursive domtree DFS traversal

2023-01-31 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 31, 2023 at 03:45:43PM +0100, Richard Biener wrote:
> The following replaces the recursive DFS traversal of the dominator
> tree in assign_dfs_numbers with a tree traversal using the fact
> that we have recorded parents.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
> 
> This makes r13-5325 somewhat obsolete, though not computing the
> DFS numbers at all is beneficial in the cases where we perform
> immediate CFG manipulations.
> 
> OK for trunk and later branch(es)?
> 
> Thanks,
> Richard.
> 
>   PR middle-end/108500
>   * dominance.cc (assign_dfs_numbers): Replace recursive DFS
>   with tree traversal algorithm.

LGTM.

> diff --git a/gcc/dominance.cc b/gcc/dominance.cc
> index 099b8fd3f24..34fabe40c18 100644
> --- a/gcc/dominance.cc
> +++ b/gcc/dominance.cc
> @@ -639,18 +639,25 @@ dom_info::calc_idoms ()
>  static void
>  assign_dfs_numbers (struct et_node *node, int *num)
>  {
> -  struct et_node *son;
> -
> -  node->dfs_num_in = (*num)++;
> -
> -  if (node->son)
> +  et_node *n = node;
> +  while (1)
>  {
> -  assign_dfs_numbers (node->son, num);
> -  for (son = node->son->right; son != node->son; son = son->right)
> - assign_dfs_numbers (son, num);
> +  n->dfs_num_in = (*num)++;
> +  if (n->son)
> + n = n->son;
> +  else
> + {
> +   while (!n->right || n->right == n->father->son)

Am I right that we could replace !n->right with n == node here too
(i.e. only node can have NULL father and in that case also NULL
left/right?  Though !n->right might result in better code because
we need to load it anyway for the second comparison.

> + {
> +   n->dfs_num_out = (*num)++;
> +   if (n == node)
> + return;
> +   n = n->father;
> + }
> +   n->dfs_num_out = (*num)++;
> +   n = n->right;
> + }
>  }
> -
> -  node->dfs_num_out = (*num)++;
>  }
>  

Jakub



[PATCH, COMMITTED] PR target/108589 - Check REG_P for AARCH64_FUSE_ADDSUB_2REG_CONST1

2023-01-31 Thread Philipp Tomsich
This adds a check for REG_P on SET_DEST for the new idiom recognizer
for AARCH64_FUSE_ADDSUB_2REG_CONST1.  The reported ICE is only
observable with checking=rtl.

Bootstrapped/regtested aarch64-linux, committed.

PR target/108589

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch_macro_fusion_pair_p): Check
REG_P on SET_DEST.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/pr108589.c: New test.

Signed-off-by: Philipp Tomsich 
---

 gcc/config/aarch64/aarch64.cc   |  1 +
 gcc/testsuite/gcc.target/aarch64/pr108589.c | 15 +++
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr108589.c

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 17c1e23e5b5..acc0cfe5f94 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -25704,6 +25704,7 @@ aarch_macro_fusion_pair_p (rtx_insn *prev, rtx_insn 
*curr)
  && CONST_INT_P (XEXP (curr_src, 1))
  && INTVAL (XEXP (curr_src, 1)) == polarity
  && REG_P (XEXP (curr_src, 0))
+ && REG_P (SET_DEST (prev_set))
  && REGNO (SET_DEST (prev_set)) == REGNO (XEXP (curr_src, 0)))
return true;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/pr108589.c 
b/gcc/testsuite/gcc.target/aarch64/pr108589.c
new file mode 100644
index 000..e9c5bc608af
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr108589.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target lp64 } */
+/* { dg-options "-O2 -mtune=ampere1a -fno-split-wide-types" } */
+
+int i;
+__int128 j;
+short s;
+
+void
+foo (void)
+{
+  j -= i;
+  int l = i - __builtin_sub_overflow_p (0, 61680, s);
+  j -= __builtin_mul_overflow_p (i, l, 0);
+}
-- 
2.34.1



Re: [PATCH] vect: Fix single def-use cycle for ifn reductions [PR108608]

2023-01-31 Thread Richard Biener via Gcc-patches
On Tue, Jan 31, 2023 at 2:08 PM Richard Sandiford via Gcc-patches
 wrote:
>
> The patch that added support for fmin/fmax reductions didn't
> handle single def-use cycles.  In some ways, this seems like
> going out of our way to make things slower, but that's a
> discussion for another day.
>
> Tested on aarch64-linux-gnu & x86_64-linux-gnu.  OK for trunk
> and the GCC 12 branch?

OK.

Richard.

> Richard
>
>
> gcc/
> PR tree-optimization/108608
> * tree-vect-loop.cc (vect_transform_reduction): Handle single
> def-use cycles that involve function calls rather than tree codes.
>
> gcc/testsuite/
> PR tree-optimization/108608
> * gcc.dg/vect/pr108608.c: New test.
> * gcc.target/aarch64/sve/pr108608-1.c: Likewise.
> ---
>  gcc/testsuite/gcc.dg/vect/pr108608.c  | 24 +++
>  .../gcc.target/aarch64/sve/pr108608-1.c   |  9 +++
>  gcc/tree-vect-loop.cc | 22 ++---
>  3 files changed, 46 insertions(+), 9 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/vect/pr108608.c
>  create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr108608-1.c
>
> diff --git a/gcc/testsuite/gcc.dg/vect/pr108608.c 
> b/gcc/testsuite/gcc.dg/vect/pr108608.c
> new file mode 100644
> index 000..e968141ba03
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/pr108608.c
> @@ -0,0 +1,24 @@
> +#include "tree-vect.h"
> +
> +double __attribute__((noipa))
> +foo (double m, float *ptr)
> +{
> +  for (int i = 0; i < 256; i++)
> +m = __builtin_fmax (m, ptr[i]);
> +  return m;
> +}
> +
> +int
> +main (void)
> +{
> +  check_vect ();
> +  float ptr[256];
> +  for (int j = 0; j < 16; ++j)
> +{
> +  for (int i = 0; i < 256; ++i)
> +   ptr[i] = i == 128 + j ? 2 + j : i == 161 ? 1 : 0;
> +  if (foo (0, ptr) != 2 + j)
> +   __builtin_abort ();
> +}
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr108608-1.c 
> b/gcc/testsuite/gcc.target/aarch64/sve/pr108608-1.c
> new file mode 100644
> index 000..0a7d485e047
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr108608-1.c
> @@ -0,0 +1,9 @@
> +/* { dg-options "-O3" } */
> +
> +double __attribute__((noipa))
> +foo (double m, float *ptr)
> +{
> +  for (int i = 0; i < 256; i++)
> +m = __builtin_fmax (m, ptr[i]);
> +  return m;
> +}
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index f0801c23671..f03af1efd0f 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -7755,8 +7755,6 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
>gimple_match_op op;
>if (!gimple_extract_op (stmt_info->stmt, ))
>  gcc_unreachable ();
> -  gcc_assert (op.code.is_tree_code ());
> -  auto code = tree_code (op.code);
>
>/* All uses but the last are expected to be defined in the loop.
>   The last use is the reduction variable.  In case of nested cycle this
> @@ -7778,7 +7776,8 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
>vec_num = 1;
>  }
>
> -  internal_fn cond_fn = get_conditional_internal_fn (code);
> +  code_helper code = canonicalize_code (op.code, op.type);
> +  internal_fn cond_fn = get_conditional_internal_fn (code, op.type);
>vec_loop_masks *masks = _VINFO_MASKS (loop_vinfo);
>bool mask_by_cond_expr = use_mask_by_cond_expr_p (code, cond_fn, 
> vectype_in);
>
> @@ -7802,9 +7801,10 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
>if (reduction_type == FOLD_LEFT_REDUCTION)
>  {
>internal_fn reduc_fn = STMT_VINFO_REDUC_FN (reduc_info);
> +  gcc_assert (code.is_tree_code ());
>return vectorize_fold_left_reduction
> - (loop_vinfo, stmt_info, gsi, vec_stmt, slp_node, reduc_def_phi, 
> code,
> -  reduc_fn, op.ops, vectype_in, reduc_index, masks);
> + (loop_vinfo, stmt_info, gsi, vec_stmt, slp_node, reduc_def_phi,
> +  tree_code (code), reduc_fn, op.ops, vectype_in, reduc_index, 
> masks);
>  }
>
>bool single_defuse_cycle = STMT_VINFO_FORCE_SINGLE_CYCLE (reduc_info);
> @@ -7814,7 +7814,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
>   || code == SAD_EXPR);
>
>/* Create the destination vector  */
> -  tree scalar_dest = gimple_assign_lhs (stmt_info->stmt);
> +  tree scalar_dest = gimple_get_lhs (stmt_info->stmt);
>tree vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
>
>vect_get_vec_defs (loop_vinfo, stmt_info, slp_node, ncopies,
> @@ -7849,7 +7849,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
>   /* Make sure that the reduction accumulator is vop[0].  */
>   if (reduc_index == 1)
> {
> - gcc_assert (commutative_tree_code (code));
> + gcc_assert (commutative_binary_op_p (code, op.type));
>   std::swap (vop[0], vop[1]);
> }
>   tree mask = vect_get_loop_mask (gsi, masks, vec_num * ncopies,
> @@ -7877,11 +7877,15 @@ 

[PATCH] middle-end/108500 - replace recursive domtree DFS traversal

2023-01-31 Thread Richard Biener via Gcc-patches
The following replaces the recursive DFS traversal of the dominator
tree in assign_dfs_numbers with a tree traversal using the fact
that we have recorded parents.

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

This makes r13-5325 somewhat obsolete, though not computing the
DFS numbers at all is beneficial in the cases where we perform
immediate CFG manipulations.

OK for trunk and later branch(es)?

Thanks,
Richard.

PR middle-end/108500
* dominance.cc (assign_dfs_numbers): Replace recursive DFS
with tree traversal algorithm.
---
 gcc/dominance.cc | 27 +--
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/gcc/dominance.cc b/gcc/dominance.cc
index 099b8fd3f24..34fabe40c18 100644
--- a/gcc/dominance.cc
+++ b/gcc/dominance.cc
@@ -639,18 +639,25 @@ dom_info::calc_idoms ()
 static void
 assign_dfs_numbers (struct et_node *node, int *num)
 {
-  struct et_node *son;
-
-  node->dfs_num_in = (*num)++;
-
-  if (node->son)
+  et_node *n = node;
+  while (1)
 {
-  assign_dfs_numbers (node->son, num);
-  for (son = node->son->right; son != node->son; son = son->right)
-   assign_dfs_numbers (son, num);
+  n->dfs_num_in = (*num)++;
+  if (n->son)
+   n = n->son;
+  else
+   {
+ while (!n->right || n->right == n->father->son)
+   {
+ n->dfs_num_out = (*num)++;
+ if (n == node)
+   return;
+ n = n->father;
+   }
+ n->dfs_num_out = (*num)++;
+ n = n->right;
+   }
 }
-
-  node->dfs_num_out = (*num)++;
 }
 
 /* Compute the data necessary for fast resolving of dominator queries in a
-- 
2.35.3


Re: For Modula-2 build-tree testing, also set up paths to compiler libraries

2023-01-31 Thread Gaius Mulley via Gcc-patches
Thomas Schwinge  writes:

> Hi!
>
> On 2022-10-10T16:31:26+0100, Gaius Mulley via Gcc-patches 
>  wrote:
>> Here are the dejagnu expect library scripts for the gm2
>> testsuite.
>
> This (or some variant thereof; haven't checked), became part of
> commit r13-4704-g1eee94d351774cdc2efc8ee508b82d065184c6ee
> "Merge modula-2 front end onto gcc".
>
>
> For build-tree testing ('$gccpath != ""'; such as standard 'make check'),
> 'gm2_link_flags' takes care to set up paths to a number of libraries that
> may be necessary:
>
>> --- /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
>
>> +set gm2_link_libraries "m2pim m2iso";
>
>> +#  gm2_link_flags - detects the whereabouts of libraries (-lstdc++).
>> +#
>> +
>> +proc gm2_link_flags { paths } {
>> +global srcdir;
>> +global ld_library_path;
>> +global gccpath;
>> +global gm2_link_libraries;
>> +
>> +set gccpath ${paths}
>> +set libio_dir ""
>> +set flags ""
>> +set ld_library_path "."
>> +
>> +set shlib_ext [get_shlib_extension]
>> +verbose "shared lib extension: $shlib_ext"
>> +
>> +if { $gccpath == "" } {
>> +  global tool_root_dir
>> +
>> +  set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
>> +  if { $libstdcpp != "" } {
>> +  append flags "-L${libstdcpp} "
>> +  append ld_library_path ":${libstdcpp}"
>> +  }
>> +} else {
>> + if [file exists "${gccpath}/lib/libstdc++.a"] {
>> + append ld_library_path ":${gccpath}/lib"
>> + }
>> + if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
>> + append flags "-L${gccpath}/libstdc++ "
>> + append ld_library_path ":${gccpath}/libstdc++"
>> + }
>> + if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
>> + append flags " -L${gccpath}/libstdc++-v3/src/.libs "
>> + append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
>> + }
>> + # Look for libstdc++.${shlib_ext}.
>> + if [file exists 
>> "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
>> + append flags " -L${gccpath}/libstdc++-v3/src/.libs "
>> + append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
>> + }
>> +
>> + # puts stderr "${gm2_link_libraries}  before foreach"
>> + foreach d [list {*}${gm2_link_libraries}] {
>> + # puts stderr "${d}  "
>> + send_log "ld_library_path was ${ld_library_path}\n"
>> + send_log "looking for ${gccpath}/lib${d}/.libs/lib${d}.a\n"
>> + if [file exists "${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"] {
>> + send_log "good found 
>> ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a\n"
>> + # append flags " -L${gccpath}/libgm2/lib${d}/.libs -l${d}"
>> + append flags " ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"
>> + append ld_library_path ":${gccpath}/libgm2/lib${d}/.libs"
>> + }
>> + send_log "ld_library_path is ${ld_library_path}\n"
>> + }
>> +}
>> +
>> +set_ld_library_path_env_vars
>> +return "$flags"
>> +}
>
> However, this misses compiler libraries (such as libgcc, which libstdc++
> may depend on).  For example, I see my x86_64-pc-linux-gnu '-m32' testing
> not pick up the build-tree libgcc, but instead some random system one,
> which (expectedly) doesn't satisfy requirements of other build-tree
> libraries:
>
> [...]/build-gcc/gcc/testsuite/gm225/m.x0: 
> /lib/i386-linux-gnu/libgcc_s.so.1: version `GCC_7.0.0' not found (required by 
> [...]/build-gcc/x86_64-pc-linux-gnu/32/libstdc++-v3/src/.libs/libstdc++.so.6)
>
> ..., and thus a lot of execution FAILs.
>
> To cure that, OK to push the attached
> "For Modula-2 build-tree testing, also set up paths to compiler libraries"?
>
>
> Grüße
>  Thomas
>
>
> -
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
> München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
> Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
> München, HRB 106955
>
>>From 5d9c8bf1a5352317fc7fd3fffe66ba690d412a4f Mon Sep 17 00:00:00 2001
> From: Thomas Schwinge 
> Date: Tue, 31 Jan 2023 11:38:15 +0100
> Subject: [PATCH] For Modula-2 build-tree testing, also set up paths to
>  compiler libraries
>
> Currently, 'gcc/testsuite/lib/gm2.exp:gm2_link_flags' doesn't set up
> paths to compiler libraries (such as libgcc, which libstdc++
> may depend on).  For example, I see my x86_64-pc-linux-gnu '-m32' testing
> not pick up the build-tree libgcc, but instead some random system one,
> which (expectedly) doesn't satisfy requirements of other build-tree
> libraries:
>
> [...]/build-gcc/gcc/testsuite/gm225/m.x0: 
> /lib/i386-linux-gnu/libgcc_s.so.1: version `GCC_7.0.0' not found (required by 
> [...]/build-gcc/x86_64-pc-linux-gnu/32/libstdc++-v3/src/.libs/libstdc++.so.6)
>
> ..., and thus a lot of execution FAILs.
>
> As 

[PATCH 2/2] Documentation Update.

2023-01-31 Thread Qing Zhao via Gcc-patches
Update documentation to clarify a GCC extension on structure with
flexible array member being nested in another structure.

gcc/ChangeLog:

* doc/extend.texi: Document GCC extension on a structure containing
a flexible array member to be a member of another structure.
---
 gcc/doc/extend.texi | 35 ++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 4a89a3eae7c..54e4baf49a9 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -1748,7 +1748,40 @@ Flexible array members may only appear as the last 
member of a
 A structure containing a flexible array member, or a union containing
 such a structure (possibly recursively), may not be a member of a
 structure or an element of an array.  (However, these uses are
-permitted by GCC as extensions.)
+permitted by GCC as extensions, see details below.)
+@end itemize
+
+GCC extension accepts a structure containing a flexible array member, or
+a union containing such a structure (possibly recursively) to be a member
+of a structure.
+
+There are two situations:
+
+@itemize @bullet
+@item
+The structure with a flexible array member is the last field of another
+structure, for example:
+
+@smallexample
+struct flex  @{ int length; char data[]; @};
+
+struct out_flex @{ int m; struct flex flex_data; @};
+@end smallexample
+
+In the above, @code{flex_data.data[]} is considered as a flexible array too.
+
+@item
+The structure with a flexible array member is the middle field of another
+structure, for example:
+
+@smallexample
+struct flex  @{ int length; char data[]; @};
+
+struct mid_flex @{ int m; struct flex flex_data; int n; @};
+@end smallexample
+
+In the above, @code{flex_data.data[]} is allowed to be extended flexibly to
+the padding. E.g, up to 4 elements.
 @end itemize
 
 Non-empty initialization of zero-length
-- 
2.31.1



[PATCH 0/2]PR101832: Handle component_ref to a structure/union field including flexible array member for builtin_object_size

2023-01-31 Thread Qing Zhao via Gcc-patches
This is the patch for PR101832, to fix builtin_object_size to
correctly handle component_ref to a structure/union field that
includes a flexible array member.

also includes a documentation update for the GCC extension on embedding
a structure/union with flexible array member into another structure.

bootstrapped and regression tested on aarch64 and x86.

Okay for commit?

thanks.

Qing



[PATCH 1/2] Handle component_ref to a structre/union field including flexible array member [PR101832]

2023-01-31 Thread Qing Zhao via Gcc-patches
GCC extension accepts the case when a struct with a flexible array member
is embedded into another struct (possibly recursively).
__builtin_object_size should treat such struct as flexible size per
-fstrict-flex-arrays.

PR tree-optimization/101832

gcc/ChangeLog:

PR tree-optimization/101832
* tree-object-size.cc (flexible_size_type_p): New function.
(addr_object_size): Handle structure/union type when it has
flexible size.

gcc/testsuite/ChangeLog:

PR tree-optimization/101832
* gcc.dg/builtin-object-size-pr101832-2.c: New test.
* gcc.dg/builtin-object-size-pr101832-3.c: New test.
* gcc.dg/builtin-object-size-pr101832-4.c: New test.
* gcc.dg/builtin-object-size-pr101832.c: New test.
---
 .../gcc.dg/builtin-object-size-pr101832-2.c   | 135 ++
 .../gcc.dg/builtin-object-size-pr101832-3.c   | 135 ++
 .../gcc.dg/builtin-object-size-pr101832-4.c   | 135 ++
 .../gcc.dg/builtin-object-size-pr101832.c | 119 +++
 gcc/tree-object-size.cc   | 115 +++
 5 files changed, 611 insertions(+), 28 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832-2.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832-3.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832-4.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832.c

diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-2.c 
b/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-2.c
new file mode 100644
index 000..f38babc5415
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-2.c
@@ -0,0 +1,135 @@
+/* PR 101832: 
+   GCC extension accepts the case when a struct with a flexible array member
+   is embedded into another struct (possibly recursively).
+   __builtin_object_size will treat such struct as flexible size per
+   -fstrict-flex-arrays.  */ 
+/* { dg-do run } */
+/* { dg-options "-O2 -fstrict-flex-arrays=1" } */
+
+#include 
+
+unsigned n_fails = 0;
+
+#define expect(p, _v) do { \
+  size_t v = _v; \
+  if (p == v) \
+printf("ok:  %s == %zd\n", #p, p); \
+  else {\
+printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
+n_fails++; \
+  } \
+} while (0);
+
+struct A {
+  int n;
+  char data[];/* Content following header */
+};
+
+struct B {
+  int m;
+  struct A a;
+};
+
+struct C {
+  int q;
+  struct B b;
+};
+
+struct A0 {
+  int n;
+  char data[0];/* Content following header */
+};
+
+struct B0 {
+  int m;
+  struct A0 a;
+};
+
+struct C0 {
+  int q;
+  struct B0 b;
+};
+
+struct A1 {
+  int n;
+  char data[1];/* Content following header */
+};
+
+struct B1 {
+  int m;
+  struct A1 a;
+};
+
+struct C1 {
+  int q;
+  struct B1 b;
+};
+
+struct An {
+  int n;
+  char data[8];/* Content following header */
+};
+
+struct Bn {
+  int m;
+  struct An a;
+};
+
+struct Cn {
+  int q;
+  struct Bn b;
+};
+
+volatile void *magic1, *magic2;
+
+int main(int argc, char *argv[])
+{
+struct B *outer;
+struct C *outest;
+
+/* Make sure optimization can't find some other object size. */
+outer = (void *)magic1;
+outest = (void *)magic2;
+
+expect(__builtin_object_size(>a, 1), -1);
+expect(__builtin_object_size(>b, 1), -1);
+expect(__builtin_object_size(>b.a, 1), -1);
+
+struct B0 *outer0;
+struct C0 *outest0;
+
+/* Make sure optimization can't find some other object size. */
+outer0 = (void *)magic1;
+outest0 = (void *)magic2;
+
+expect(__builtin_object_size(>a, 1), -1);
+expect(__builtin_object_size(>b, 1), -1);
+expect(__builtin_object_size(>b.a, 1), -1);
+
+struct B1 *outer1;
+struct C1 *outest1;
+
+/* Make sure optimization can't find some other object size. */
+outer1 = (void *)magic1;
+outest1 = (void *)magic2;
+
+expect(__builtin_object_size(>a, 1), -1);
+expect(__builtin_object_size(>b, 1), -1);
+expect(__builtin_object_size(>b.a, 1), -1);
+
+struct Bn *outern;
+struct Cn *outestn;
+
+/* Make sure optimization can't find some other object size. */
+outern = (void *)magic1;
+outestn = (void *)magic2;
+
+expect(__builtin_object_size(>a, 1), sizeof(outern->a));
+expect(__builtin_object_size(>b, 1), sizeof(outestn->b));
+expect(__builtin_object_size(>b.a, 1), sizeof(outestn->b.a));
+
+if (n_fails > 0)
+  __builtin_abort ();
+
+return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-3.c 
b/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-3.c
new file mode 100644
index 000..aaae99b8d67
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-3.c
@@ -0,0 +1,135 @@
+/* PR 101832: 
+   GCC extension accepts the case when a struct with a flexible array member
+   is embedded into another struct (possibly recursively).
+   __builtin_object_size will treat such struct as flexible size per
+   

[COMMITTED] gccrs: rustc_attrs: Allow `rustc_inherit_overflow_checks` as a builtin..

2023-01-31 Thread Arthur Cohen
..attribute. We cannot yet handle this attribute, but we should not reject it 
either

gcc/rust/ChangeLog:

* util/rust-attributes.cc: Add `rustc_inherit_overflow_checks` to list
of builtin attributes.

gcc/testsuite/ChangeLog:

* rust/compile/rustc_attr1.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/util/rust-attributes.cc  | 32 ---
 gcc/testsuite/rust/compile/rustc_attr1.rs | 13 +
 2 files changed, 30 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/rustc_attr1.rs

diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 2cefdb247d1..9db77b40dfb 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -26,21 +26,23 @@ namespace Rust {
 namespace Analysis {
 
 // 
https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#248
-static const BuiltinAttrDefinition __definitions[] = {
-  {"inline", CODE_GENERATION},
-  {"cold", CODE_GENERATION},
-  {"cfg", EXPANSION},
-  {"cfg_attr", EXPANSION},
-  {"deprecated", STATIC_ANALYSIS},
-  {"allow", STATIC_ANALYSIS},
-  {"doc", HIR_LOWERING},
-  {"must_use", STATIC_ANALYSIS},
-  {"lang", HIR_LOWERING},
-  {"link_section", CODE_GENERATION},
-  {"no_mangle", CODE_GENERATION},
-  {"repr", CODE_GENERATION},
-  {"path", EXPANSION},
-};
+static const BuiltinAttrDefinition __definitions[]
+  = {{"inline", CODE_GENERATION},
+ {"cold", CODE_GENERATION},
+ {"cfg", EXPANSION},
+ {"cfg_attr", EXPANSION},
+ {"deprecated", STATIC_ANALYSIS},
+ {"allow", STATIC_ANALYSIS},
+ {"doc", HIR_LOWERING},
+ {"must_use", STATIC_ANALYSIS},
+ {"lang", HIR_LOWERING},
+ {"link_section", CODE_GENERATION},
+ {"no_mangle", CODE_GENERATION},
+ {"repr", CODE_GENERATION},
+ {"path", EXPANSION},
+ // From now on, these are reserved by the compiler and gated through
+ // #![feature(rustc_attrs)]
+ {"rustc_inherit_overflow_checks", CODE_GENERATION}};
 
 BuiltinAttributeMappings *
 BuiltinAttributeMappings::get ()
diff --git a/gcc/testsuite/rust/compile/rustc_attr1.rs 
b/gcc/testsuite/rust/compile/rustc_attr1.rs
new file mode 100644
index 000..4bc7d5e3553
--- /dev/null
+++ b/gcc/testsuite/rust/compile/rustc_attr1.rs
@@ -0,0 +1,13 @@
+// { dg-additional-options "-w" }
+
+#![feature(rustc_attrs)]
+
+pub struct NotI8(i8);
+
+impl NotI8 {
+#[inline]
+#[rustc_inherit_overflow_checks]
+pub fn add(self, other: NotI8) -> NotI8 {
+NotI8(self.0 + other.0)
+}
+}
-- 
2.39.1



[COMMITTED] gccrs: bugfix: initialize slice from array in const context

2023-01-31 Thread Arthur Cohen
From: Faisal Abbas <90.abbasfai...@gmail.com>

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Turn
constant item typechecking into a coercion site instead of a unify
site.

gcc/testsuite/ChangeLog:

* rust/compile/const6.rs: New test.

Signed-off-by: Faisal Abbas <90.abbasfai...@gmail.com>

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/typecheck/rust-hir-type-check-stmt.cc | 2 +-
 gcc/testsuite/rust/compile/const6.rs   | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/rust/compile/const6.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc 
b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
index e82dd8e5300..a55cf22ba23 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
@@ -68,7 +68,7 @@ TypeCheckStmt::visit (HIR::ConstantItem )
   TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ());
   TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (constant.get_expr ());
 
-  infered = unify_site (
+  infered = coercion_site (
 constant.get_mappings ().get_hirid (),
 TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()),
 TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()),
diff --git a/gcc/testsuite/rust/compile/const6.rs 
b/gcc/testsuite/rust/compile/const6.rs
new file mode 100644
index 000..8f0dc320129
--- /dev/null
+++ b/gcc/testsuite/rust/compile/const6.rs
@@ -0,0 +1,4 @@
+fn main() {
+const array:[i32; 1] = [1];
+const slice:&[i32] = 
+}
-- 
2.39.1



[COMMITTED] gccrs: Add testcase to show forward declared items work via TypeAlias

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

Fixes #1073

gcc/testsuite/ChangeLog:

* rust/compile/issue-1073.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/testsuite/rust/compile/issue-1073.rs | 4 
 1 file changed, 4 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-1073.rs

diff --git a/gcc/testsuite/rust/compile/issue-1073.rs 
b/gcc/testsuite/rust/compile/issue-1073.rs
new file mode 100644
index 000..ac887c02b4d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1073.rs
@@ -0,0 +1,4 @@
+// { dg-options "-w" }
+type A = B;
+
+struct B;
-- 
2.39.1



[COMMITTED] gccrs: Add guards against getting data from an empty vector

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-tyctx.cc (TypeCheckContext::pop_return_type): Add
guards around `std::vector.pop_back()`.
(TypeCheckContext::peek_context): Likewise for `std::vector.back()`.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/typecheck/rust-tyctx.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/rust/typecheck/rust-tyctx.cc b/gcc/rust/typecheck/rust-tyctx.cc
index ad5f67cc1dd..af86b064c6c 100644
--- a/gcc/rust/typecheck/rust-tyctx.cc
+++ b/gcc/rust/typecheck/rust-tyctx.cc
@@ -142,12 +142,14 @@ TypeCheckContext::push_return_type (TypeCheckContextItem 
item,
 void
 TypeCheckContext::pop_return_type ()
 {
+  rust_assert (!return_type_stack.empty ());
   return_type_stack.pop_back ();
 }
 
 TypeCheckContextItem &
 TypeCheckContext::peek_context ()
 {
+  rust_assert (!return_type_stack.empty ());
   return return_type_stack.back ().first;
 }
 
-- 
2.39.1



[COMMITTED] gccrs: Refactor TypeResolution to be a simple query based system

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

This patch refactors the type resolution system to introduce a new
interface

  bool query_type (HirId, TyTy::BaseType** result)

This is needed in order to properly support forward declared items. Our
name resolution system has two parts:

  1. Toplevel scan
  2. Item resolution

The toplevel scan gathers all the nesseacry 'names' into their respective
namespace by doing a full toplevel scan and generate canonical paths for
each item. The second pass is responsible for drilling down into each
structure or function to resolve each field or variable etc. This means
our name resolution system supports forward decalred items but our type
resolution system did not.

This patch removes the toplevel scan from our type resolution pass which
is not able to handle all cases such as a function with return type and
the type is decalred after the fact or a type alias to a type declared
after the fact. The name resolution mappings are resolved so when errors
occured here we got errors such as unable to lookup HirId 1234, which meant
yes we have 'resolved' this reference to this HirId but we are unable to
find any type information for it. This means we needed a new way to figure
out the type in a query based way.

This is where the new query_type inferface comes in so when we have an
HirId we want to resolve the mappings class allows us to figure out what
item this is such as:

  1. HIR::Item (normal HIR::Function, Struct, TypeAlias, ...)
  2. HIR::ImplItem (function, constant, ... within an impl-block)
  3. HIR::ImplBlock (Self type on an impl-block)
  4. HIR::ExternalItem (extern-block item)

The mappings class allows us to simply lookup these HIR nodes and then
call the relevant resolver class to compute the type. This patch does not
add support for self-referencial types but is the starting point to be able
to support such types.

Fixes #1455

gcc/rust/ChangeLog:

* Make-lang.in: Remove `rust-hir-typecheck-toplevel` object and add
`rust-hir-path-probe` one.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::MethodResolver):
Remove no longer used `context` and `mapping` fields, and use new
`query_type` API.
(MethodResolver::MethodResolver): Likewise.
(MethodResolver::select): Use new `query_type` API.
* typecheck/rust-hir-path-probe.h: New header.
* typecheck/rust-hir-path-probe.cc: New file.
* typecheck/rust-hir-dot-operator.h (class MethodResolver): Remove no
longer used `context` and `mapping` fields, and use new `query_type` 
API.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): 
New function.
* typecheck/rust-hir-type-check-base.h: Declare `query_type` function.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add 
debug print.
* typecheck/rust-hir-type-check-implitem.cc 
(TypeCheckTopLevelExternItem::Resolve):
Refactor and make use of new query system.
(TypeCheckTopLevelExternItem::Resolve): Likewise.
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckTopLevelImplItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
(TypeCheckImplItem::TypeCheckImplItem): Likewise.
(TypeCheckImplItem::Resolve): Likewise.
(TypeCheckImplItemWithTrait::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.h (class 
TypeCheckTopLevelImplItem): Likewise.
(class TypeCheckImplItemWithTrait): Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::TypeCheckItem): 
Likewise.
(TypeCheckItem::Resolve): Likewise.
(TypeCheckItem::ResolveImplItem): Likewise.
(TypeCheckItem::ResolveImplBlockSelf): Likewise.
(TypeCheckItem::visit): Likewise.
(TypeCheckItem::resolve_impl_item): Likewise.
(TypeCheckItem::resolve_impl_block_substitutions): Likewise.
(TypeCheckItem::resolve_impl_block_self): Likewise.
* typecheck/rust-hir-type-check-item.h: Likewise.
* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_root_path): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): 
Likewise.
* typecheck/rust-hir-type-check-stmt.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::Resolve): 
Likewise.
(TypeCheckType::visit): Likewise.
(TypeCheckType::resolve_root_path): Likewise.
* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve): Likewise.
* typecheck/rust-hir-type-check.h: Likewise.
* typecheck/rust-substitution-mapper.h: Likewise.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise.
(TypeCheckBase::get_predicate_from_bound): Likewise.
(TypeBoundsMappings::add_bound): Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty.h: Likewise.
* 

[COMMITTED] gccrs: Make constexpr constructors type-checking more permissive

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (eval_store_expression): Remove invalid
assertion on constexpr constructors.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-constexpr.cc | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/backend/rust-constexpr.cc 
b/gcc/rust/backend/rust-constexpr.cc
index 8efb4301d09..8623816236c 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -2953,14 +2953,14 @@ eval_store_expression (const constexpr_ctx *ctx, tree 
t, bool lval,
   TREE_SIDE_EFFECTS (*valp) = TREE_SIDE_EFFECTS (init);
   CONSTRUCTOR_NO_CLEARING (*valp) = CONSTRUCTOR_NO_CLEARING (init);
 }
-  else if (TREE_CODE (init) == CONSTRUCTOR
-  && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init),
- type))
-{
-  /* See above on initialization of empty bases.  */
-  gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval);
-  return init;
-}
+  // else if (TREE_CODE (init) == CONSTRUCTOR
+  //  && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init),
+  // type))
+  //   {
+  // /* See above on initialization of empty bases.  */
+  // // gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval);
+  // return init;
+  //   }
   else
 *valp = init;
 
-- 
2.39.1



[COMMITTED] gccrs: Desugar double borrows into two HIR:BorrowExpr's

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

We simply hit a gcc_unreachable() on double borrows but it seems reasonable
to just desugar the AST into a borrow of a borrow to foo. Instead of a
borrow expression with a flag to be respected.

Fixes #1506

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.h: Lower double borrow expressions to two
`HIR::BorrowExpr`s.
* hir/tree/rust-hir-expr.h: Remove `is_double_borrow` field from
`HIR::BorrowExpr`.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Remove
call to `gcc_unreachable` on double borrow expressions.

gcc/testsuite/ChangeLog:

* rust/compile/torture/issue-1506.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/hir/rust-ast-lower-expr.h| 27 ---
 gcc/rust/hir/tree/rust-hir-expr.h |  5 ++--
 .../typecheck/rust-hir-type-check-expr.cc |  6 -
 .../rust/compile/torture/issue-1506.rs|  3 +++
 4 files changed, 28 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/torture/issue-1506.rs

diff --git a/gcc/rust/hir/rust-ast-lower-expr.h 
b/gcc/rust/hir/rust-ast-lower-expr.h
index 92773b6f3a1..b0ab409646d 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.h
+++ b/gcc/rust/hir/rust-ast-lower-expr.h
@@ -643,10 +643,29 @@ public:
   mappings->get_next_hir_id (crate_num),
   UNKNOWN_LOCAL_DEFID);
 
-translated = new HIR::BorrowExpr (
-  mapping, std::unique_ptr (borrow_lvalue),
-  expr.get_is_mut () ? Mutability::Mut : Mutability::Imm,
-  expr.get_is_double_borrow (), expr.get_outer_attrs (), expr.get_locus 
());
+HIR::BorrowExpr *borrow_expr
+  = new HIR::BorrowExpr (mapping,
+std::unique_ptr (borrow_lvalue),
+expr.get_is_mut () ? Mutability::Mut
+   : Mutability::Imm,
+expr.get_outer_attrs (), expr.get_locus ());
+
+if (expr.get_is_double_borrow ())
+  {
+   NodeId artifical_bouble_borrow_id = mappings->get_next_node_id ();
+   Analysis::NodeMapping mapping (crate_num, artifical_bouble_borrow_id,
+  mappings->get_next_hir_id (crate_num),
+  UNKNOWN_LOCAL_DEFID);
+
+   borrow_expr
+ = new HIR::BorrowExpr (mapping,
+std::unique_ptr (borrow_expr),
+expr.get_is_mut () ? Mutability::Mut
+   : Mutability::Imm,
+expr.get_outer_attrs (), expr.get_locus ());
+  }
+
+translated = borrow_expr;
   }
 
   void visit (AST::DereferenceExpr ) override
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h 
b/gcc/rust/hir/tree/rust-hir-expr.h
index 5a1e9768526..564d5215724 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -192,10 +192,10 @@ public:
 
   BorrowExpr (Analysis::NodeMapping mappings,
  std::unique_ptr borrow_lvalue, Mutability mut,
- bool is_double_borrow, AST::AttrVec outer_attribs, Location locus)
+ AST::AttrVec outer_attribs, Location locus)
 : OperatorExpr (std::move (mappings), std::move (borrow_lvalue),
std::move (outer_attribs), locus),
-  mut (mut), double_borrow (is_double_borrow)
+  mut (mut)
   {}
 
   void accept_vis (HIRFullVisitor ) override;
@@ -203,7 +203,6 @@ public:
 
   Mutability get_mut () const { return mut; }
   bool is_mut () const { return mut == Mutability::Mut; }
-  bool get_is_double_borrow () const { return double_borrow; }
 
 protected:
   /* Use covariance to implement clone function as returning this object rather
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 41c8cd1f19b..c415ae98a7a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1209,12 +1209,6 @@ TypeCheckExpr::visit (HIR::BorrowExpr )
}
 }
 
-  if (expr.get_is_double_borrow ())
-{
-  // FIXME double_reference
-  gcc_unreachable ();
-}
-
   infered = new TyTy::ReferenceType (expr.get_mappings ().get_hirid (),
 TyTy::TyVar (resolved_base->get_ref ()),
 expr.get_mut ());
diff --git a/gcc/testsuite/rust/compile/torture/issue-1506.rs 
b/gcc/testsuite/rust/compile/torture/issue-1506.rs
new file mode 100644
index 000..a38f23144ed
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/issue-1506.rs
@@ -0,0 +1,3 @@
+pub fn main() {
+let _:  = 1;
+}
-- 
2.39.1



[COMMITTED] gccrs: testsuite/rust: add a testcase for testing ...

2023-01-31 Thread Arthur Cohen
From: liushuyu 

... builtin macro and decl macro mixed expansion

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_recurse.rs: New test.

Signed-off-by: Zixing Liu 

Tested on x86_64-pc-linux-gnu, committed on master.

---
 .../rust/compile/builtin_macro_recurse.rs | 21 +++
 1 file changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/builtin_macro_recurse.rs

diff --git a/gcc/testsuite/rust/compile/builtin_macro_recurse.rs 
b/gcc/testsuite/rust/compile/builtin_macro_recurse.rs
new file mode 100644
index 000..0b516fd93a9
--- /dev/null
+++ b/gcc/testsuite/rust/compile/builtin_macro_recurse.rs
@@ -0,0 +1,21 @@
+// { dg-additional-options "-fdump-tree-gimple" }
+
+#[rustc_builtin_macro]
+macro_rules! concat {
+() => {{}};
+}
+
+macro_rules! a {
+() => { "test" };
+}
+
+macro_rules! b {
+() => { "canary" };
+}
+
+fn main() {
+// { dg-final { scan-tree-dump-times {"test1canary"} 1 gimple } }
+let _ = concat!(a!(), 1, b!());
+// should not error
+concat!(a!(), true, b!(),);
+}
-- 
2.39.1



[COMMITTED] gccrs: backend: Expose Bvariable class through rust-gcc header

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* rust-gcc.cc (class Bvariable): Move class to `rust-gcc.h` header.
* rust-gcc.h: New file.

Tested on x86_64-pc-linux-gnu, committed on master.


Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/rust-gcc.cc | 30 +--
 gcc/rust/rust-gcc.h  | 58 
 2 files changed, 59 insertions(+), 29 deletions(-)
 create mode 100644 gcc/rust/rust-gcc.h

diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index e3331d60e32..82b2d33977d 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -50,38 +50,10 @@
 #include "rust-linemap.h"
 #include "rust-backend.h"
 #include "rust-object-export.h"
+#include "rust-gcc.h"
 
 #include "backend/rust-tree.h"
 
-// TODO: this will have to be significantly modified to work with Rust
-
-// Bvariable is a bit more complicated, because of zero-sized types.
-// The GNU linker does not permit dynamic variables with zero size.
-// When we see such a variable, we generate a version of the type with
-// non-zero size.  However, when referring to the global variable, we
-// want an expression of zero size; otherwise, if, say, the global
-// variable is passed to a function, we will be passing a
-// non-zero-sized value to a zero-sized value, which can lead to a
-// miscompilation.
-
-class Bvariable
-{
-public:
-  Bvariable (tree t) : t_ (t), orig_type_ (NULL) {}
-
-  Bvariable (tree t, tree orig_type) : t_ (t), orig_type_ (orig_type) {}
-
-  // Get the tree for use as an expression.
-  tree get_tree (Location) const;
-
-  // Get the actual decl;
-  tree get_decl () const { return this->t_; }
-
-private:
-  tree t_;
-  tree orig_type_;
-};
-
 // Get the tree of a variable for use as an expression.  If this is a
 // zero-sized global, create an expression that refers to the decl but
 // has zero size.
diff --git a/gcc/rust/rust-gcc.h b/gcc/rust/rust-gcc.h
new file mode 100644
index 000..085c16d0f3b
--- /dev/null
+++ b/gcc/rust/rust-gcc.h
@@ -0,0 +1,58 @@
+// rust-gcc.cc -- Rust frontend to gcc IR.
+// Copyright (C) 2011-2022 Free Software Foundation, Inc.
+// Contributed by Ian Lance Taylor, Google.
+// forked from gccgo
+
+// 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
+// .
+
+#include "rust-system.h"
+
+// This has to be included outside of extern "C", so we have to
+// include it here before tree.h includes it later.
+#include 
+
+#include "tree.h"
+#include "rust-location.h"
+
+// TODO: this will have to be significantly modified to work with Rust
+
+// Bvariable is a bit more complicated, because of zero-sized types.
+// The GNU linker does not permit dynamic variables with zero size.
+// When we see such a variable, we generate a version of the type with
+// non-zero size.  However, when referring to the global variable, we
+// want an expression of zero size; otherwise, if, say, the global
+// variable is passed to a function, we will be passing a
+// non-zero-sized value to a zero-sized value, which can lead to a
+// miscompilation.
+
+class Bvariable
+{
+public:
+  Bvariable (tree t) : t_ (t), orig_type_ (NULL) {}
+
+  Bvariable (tree t, tree orig_type) : t_ (t), orig_type_ (orig_type) {}
+
+  // Get the tree for use as an expression.
+  tree get_tree (Location) const;
+
+  // Get the actual decl;
+  tree get_decl () const { return this->t_; }
+
+private:
+  tree t_;
+  tree orig_type_;
+};
-- 
2.39.1



[COMMITTED] gccrs: Add testcase to show forward declared items work

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

Fixes #1006

gcc/testsuite/ChangeLog:

* rust/compile/issue-1006.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/testsuite/rust/compile/issue-1006.rs | 10 ++
 1 file changed, 10 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-1006.rs

diff --git a/gcc/testsuite/rust/compile/issue-1006.rs 
b/gcc/testsuite/rust/compile/issue-1006.rs
new file mode 100644
index 000..7f565deaef3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1006.rs
@@ -0,0 +1,10 @@
+// { dg-options "-w" }
+union B {
+a: A,
+b: f32,
+}
+
+struct A {
+data: i32,
+len: usize,
+}
-- 
2.39.1



[COMMITTED] gccrs: Add testcase for const-eval issue from rust-blog

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

see:
https://blog.rust-lang.org/2022/09/15/const-eval-safety-rule-revision.html

gcc/testsuite/ChangeLog:

* rust/compile/rust-const-blog-issue.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/testsuite/rust/compile/rust-const-blog-issue.rs | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/rust-const-blog-issue.rs

diff --git a/gcc/testsuite/rust/compile/rust-const-blog-issue.rs 
b/gcc/testsuite/rust/compile/rust-const-blog-issue.rs
new file mode 100644
index 000..a5ea2ebacb9
--- /dev/null
+++ b/gcc/testsuite/rust/compile/rust-const-blog-issue.rs
@@ -0,0 +1,12 @@
+// { dg-excess-errors "accessing value of"  }
+mod mem {
+extern "rust-intrinsic" {
+#[rustc_const_stable(feature = "const_transmute", since = "1.46.0")]
+fn transmute(_: T) -> U;
+}
+}
+
+pub static FOO: () = unsafe {
+let illegal_ptr2int: usize = mem::transmute(&());
+let _copy = illegal_ptr2int;
+};
-- 
2.39.1



[COMMITTED] gccrs: Cleanup formatting of backend expression visitor

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

gcc/rust/ChangeLog:

* backend/rust-compile-expr.h: Formatting.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-compile-expr.h | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.h 
b/gcc/rust/backend/rust-compile-expr.h
index 83293a40b44..845511f9f43 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -68,24 +68,31 @@ public:
   void visit (HIR::RangeFullExpr ) override;
   void visit (HIR::RangeFromToInclExpr ) override;
 
-  // Empty visit for unused Expression HIR nodes.
+  // TODO
   void visit (HIR::ClosureExprInner &) override {}
   void visit (HIR::ClosureExprInnerTyped &) override {}
-  void visit (HIR::StructExprFieldIdentifier &) override {}
-  void visit (HIR::StructExprFieldIdentifierValue &) override {}
-  void visit (HIR::StructExprFieldIndexValue &) override {}
   void visit (HIR::ErrorPropagationExpr &) override {}
   void visit (HIR::RangeToInclExpr &) override {}
-  void visit (HIR::WhileLetLoopExpr &) override {}
   void visit (HIR::ForLoopExpr &) override {}
+
+  // TODO
+  // these need to be sugared in the HIR to if statements and a match
+  void visit (HIR::WhileLetLoopExpr &) override {}
   void visit (HIR::IfExprConseqIfLet &) override {}
   void visit (HIR::IfLetExpr &) override {}
   void visit (HIR::IfLetExprConseqElse &) override {}
   void visit (HIR::IfLetExprConseqIf &) override {}
   void visit (HIR::IfLetExprConseqIfLet &) override {}
+
+  // lets not worry about async yet
   void visit (HIR::AwaitExpr &) override {}
   void visit (HIR::AsyncBlockExpr &) override {}
 
+  // nothing to do for these
+  void visit (HIR::StructExprFieldIdentifier &) override {}
+  void visit (HIR::StructExprFieldIdentifierValue &) override {}
+  void visit (HIR::StructExprFieldIndexValue &) override {}
+
 protected:
   tree get_fn_addr_from_dyn (const TyTy::DynamicObjectType *dyn,
 TyTy::BaseType *receiver, TyTy::FnType *fntype,
-- 
2.39.1



[COMMITTED] gccrs: Static Items must be const evaluated

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

Statics like constants need to have a singular value they are not functions
to be lazy evaluated. So to evaluate a block expr we can just reuse our
const code to resolve this to a singular value.

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): Const evaluate
static item expressions.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-compile-item.cc | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-item.cc 
b/gcc/rust/backend/rust-compile-item.cc
index 634b983a771..d1cdc3b6698 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -43,13 +43,18 @@ CompileItem::visit (HIR::StaticItem )
   rust_assert (ok);
 
   tree type = TyTyResolveCompile::compile (ctx, resolved_type);
-  tree value = CompileExpr::Compile (var.get_expr (), ctx);
 
   const Resolver::CanonicalPath *canonical_path = nullptr;
   ok = ctx->get_mappings ()->lookup_canonical_path (
 var.get_mappings ().get_nodeid (), _path);
   rust_assert (ok);
 
+  HIR::Expr *const_value_expr = var.get_expr ();
+  ctx->push_const_context ();
+  tree value = compile_constant_item (ctx, resolved_type, canonical_path,
+ const_value_expr, var.get_locus ());
+  ctx->pop_const_context ();
+
   std::string name = canonical_path->get ();
   std::string asm_name = ctx->mangle_item (resolved_type, *canonical_path);
 
-- 
2.39.1



[COMMITTED] gccrs: expand: eager evaluate macros inside builtin macros

2023-01-31 Thread Arthur Cohen
From: liushuyu 

gcc/rust/ChangeLog:

* ast/rust-ast.h (class MacroInvocData): Store expander as
member of the class.
(class Expr): Add `is_literal` virtual method
* ast/rust-expr.h: Override `is_literal` for `LiteralExpr`s.
* expand/rust-macro-builtins.cc (try_expand_macro_expression): New 
function.
(try_extract_string_literal_from_fragment): Likewise.
(try_expand_single_string_literal): Likewise.
(try_expand_many_expr): Likewise.
(parse_single_string_literal): Add macro expander as argument.
(MacroBuiltin::include_bytes): Pass expander as argument to
`parse_single_string_literal`.
(MacroBuiltin::include_str): Likewise.
(MacroBuiltin::compile_error): Likewise.
(MacroBuiltin::include): Likewise.
(MacroBuiltin::concat): Likewise and add better error handling.
(MacroBuiltin::env): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Expand
invocations recursively.

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_concat.rs: Fix test error messages.
* rust/compile/builtin_macro_env.rs: Likewise.

Signed-off-by: Zixing Liu 

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/ast/rust-ast.h   |  12 +
 gcc/rust/ast/rust-expr.h  |   2 +
 gcc/rust/expand/rust-macro-builtins.cc| 206 ++
 gcc/rust/expand/rust-macro-expand.cc  |   1 +
 .../rust/compile/builtin_macro_concat.rs  |   8 +-
 .../rust/compile/builtin_macro_env.rs |   4 +-
 6 files changed, 182 insertions(+), 51 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 9e1b8b11373..ccabccd6aff 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -31,6 +31,7 @@ namespace Rust {
 typedef std::string Identifier;
 typedef int TupleIndex;
 struct Session;
+struct MacroExpander;
 
 namespace AST {
 // foward decl: ast visitor
@@ -951,6 +952,8 @@ public:
 
   virtual Location get_locus () const = 0;
 
+  virtual bool is_literal () const { return false; }
+
   // HACK: strictly not needed, but faster than full downcast clone
   virtual bool is_expr_without_block () const = 0;
 
@@ -1471,6 +1474,7 @@ private:
   // One way of parsing the macro. Probably not applicable for all macros.
   std::vector > parsed_items;
   bool parsed_to_meta_item = false;
+  MacroExpander *expander = nullptr;
 
 public:
   std::string as_string () const;
@@ -1495,6 +1499,7 @@ public:
 path = other.path;
 token_tree = other.token_tree;
 parsed_to_meta_item = other.parsed_to_meta_item;
+expander = other.expander;
 
 parsed_items.reserve (other.parsed_items.size ());
 for (const auto  : other.parsed_items)
@@ -1523,6 +1528,13 @@ public:
   SimplePath _path () { return path; }
   const SimplePath _path () const { return path; }
 
+  void set_expander (MacroExpander *new_expander) { expander = new_expander; }
+  MacroExpander *get_expander ()
+  {
+rust_assert (expander);
+return expander;
+  }
+
   void
   set_meta_item_output (std::vector > new_items)
   {
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 1966a590c94..c764f9c4c66 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -67,6 +67,8 @@ public:
 
   Location get_locus () const override final { return locus; }
 
+  bool is_literal () const override final { return true; }
+
   Literal get_literal () const { return literal; }
 
   void accept_vis (ASTVisitor ) override;
diff --git a/gcc/rust/expand/rust-macro-builtins.cc 
b/gcc/rust/expand/rust-macro-builtins.cc
index f5e3e188423..606f33c65bc 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -17,12 +17,14 @@
 // .
 
 #include "rust-macro-builtins.h"
+#include "rust-ast.h"
 #include "rust-diagnostics.h"
 #include "rust-expr.h"
 #include "rust-session-manager.h"
 #include "rust-macro-invoc-lexer.h"
 #include "rust-lex.h"
 #include "rust-parse.h"
+#include "rust-attribute-visitor.h"
 
 namespace Rust {
 namespace {
@@ -61,13 +63,119 @@ macro_end_token (AST::DelimTokenTree _token_tree,
   return last_token_id;
 }
 
+/* Expand and extract an expression from the macro */
+
+static inline AST::ASTFragment
+try_expand_macro_expression (AST::Expr *expr, MacroExpander *expander)
+{
+  rust_assert (expander);
+
+  auto vis = Rust::AttrVisitor (*expander);
+  expr->accept_vis (vis);
+  return expander->take_expanded_fragment (vis);
+}
+
+/* Expand and then extract a string literal from the macro */
+
+static std::unique_ptr
+try_extract_string_literal_from_fragment (const Location _locus,
+ std::unique_ptr )
+{
+  auto maybe_lit = static_cast (node.get ());
+  if (!node || !node->is_literal ()
+  || maybe_lit->get_lit_type () != AST::Literal::STRING)
+{
+  rust_error_at 

[COMMITTED] gccrs: module lowering: Do not append null pointers as items

2023-01-31 Thread Arthur Cohen
Some module items do not need to get lowered to HIR such as `macro_rules!` 
definitions. Hence, module lowering should act the same as crate lowering: Only 
emplace back the lowered item if it is a valid pointer

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Do not lower
null items within modules.

gcc/testsuite/ChangeLog:

* rust/compile/macro44.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/hir/rust-ast-lower-item.cc   |  5 +++-
 gcc/testsuite/rust/compile/macro44.rs | 34 +++
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/rust/compile/macro44.rs

diff --git a/gcc/rust/hir/rust-ast-lower-item.cc 
b/gcc/rust/hir/rust-ast-lower-item.cc
index 8aec68d9458..411cc4be855 100644
--- a/gcc/rust/hir/rust-ast-lower-item.cc
+++ b/gcc/rust/hir/rust-ast-lower-item.cc
@@ -59,7 +59,10 @@ ASTLoweringItem::visit (AST::Module )
   for (auto  : module.get_items ())
 {
   auto transitem = translate (item.get ());
-  items.push_back (std::unique_ptr (transitem));
+  // The item may be null if it doesn't need to live in the HIR - for
+  // example, macro rules definitions
+  if (transitem)
+   items.push_back (std::unique_ptr (transitem));
 }
 
   // should be lowered/copied from module.get_in/outer_attrs()
diff --git a/gcc/testsuite/rust/compile/macro44.rs 
b/gcc/testsuite/rust/compile/macro44.rs
new file mode 100644
index 000..84b2cdbb506
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro44.rs
@@ -0,0 +1,34 @@
+mod foo {
+mod bar {
+mod baz {
+macro_rules! baz {
+() => {{}};
+}
+}
+}
+
+macro_rules! foo {
+() => {{}};
+}
+
+fn foo_f() { // { dg-warning "function is never used" }
+foo!();
+}
+
+fn bar_f() { // { dg-warning "function is never used" }
+baz!();
+}
+}
+
+mod foo2 {
+#[macro_export]
+macro_rules! bar1 {
+() => {};
+}
+
+macro_rules! bar2 {
+() => {};
+}
+}
+
+fn main() {}
-- 
2.39.1



[COMMITTED] gccrs: rust: Add -frust-compile-until option

2023-01-31 Thread Arthur Cohen
This option helps ensure that we do not introduce regressions on various
parts of the compilation pipeline. For example, a testcase (or testsuite
from the `testing` project) might pass attribute checking, expansion and
lowering, but fail during typechecking. Should a change suddenly make
that testcase fail expansion, we would not be able to notice it. By
generating tests that run up until expansion, typechecking, compilation
and so forth we ensure that no regressions are added accidentally to
already failing tests/testsuites.

gcc/rust/ChangeLog:

* lang.opt: Add new ``-frust-compile-until` option.
* rust-session-manager.cc (Session::compile_crate): Add stops around
various compilation steps in the pipeline.
* rust-session-manager.h (struct CompileOptions): Add `CompileStep` enum
and field.

gcc/testsuite/ChangeLog:

* rust/compile/frust-compile-until.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/lang.opt | 42 +++
 gcc/rust/rust-session-manager.cc  | 36 +++-
 gcc/rust/rust-session-manager.h   | 25 ++-
 .../rust/compile/frust-compile-until.rs   |  7 
 4 files changed, 107 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/frust-compile-until.rs

diff --git a/gcc/rust/lang.opt b/gcc/rust/lang.opt
index 3e6826954da..40aafaf34d2 100644
--- a/gcc/rust/lang.opt
+++ b/gcc/rust/lang.opt
@@ -117,6 +117,48 @@ Rust Joined RejectNegative
 
 o
 Rust Joined Separate
+
+frust-compile-until=
+Rust Joined RejectNegative Enum(frust_compile_until) 
Var(flag_rust_compile_until)
+-frust-compile-until=[ast|attributecheck|expansion|nameresolution|lowering|typecheck|privacy|unsafety|const|copimlation|end]
 When to stop in the pipeline when compiling Rust code
+
+Enum
+Name(frust_compile_until) Type(int) UnknownError(unknown rust compile-until 
%qs)
+
+EnumValue
+Enum(frust_compile_until) String(ast) Value(0)
+
+EnumValue
+Enum(frust_compile_until) String(attributecheck) Value(1)
+
+EnumValue
+Enum(frust_compile_until) String(expansion) Value(2)
+
+EnumValue
+Enum(frust_compile_until) String(nameresolution) Value(3)
+
+EnumValue
+Enum(frust_compile_until) String(lowering) Value(4)
+
+EnumValue
+Enum(frust_compile_until) String(typecheck) Value(5)
+
+EnumValue
+Enum(frust_compile_until) String(privacy) Value(6)
+
+EnumValue
+Enum(frust_compile_until) String(unsafety) Value(7)
+
+EnumValue
+Enum(frust_compile_until) String(const) Value(8)
+
+EnumValue
+Enum(frust_compile_until) String(compilation) Value(9)
+
+EnumValue
+Enum(frust_compile_until) String(end) Value(10)
+
+
 ; Documented in common.opt
 
 ; This comment is to ensure we retain the blank line above.
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 157f5099155..4ee7175b48b 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -223,7 +223,9 @@ Session::handle_option (
 case OPT_frust_edition_:
   options.set_edition (flag_rust_edition);
   break;
-
+case OPT_frust_compile_until_:
+  options.set_compile_step (flag_rust_compile_until);
+  break;
 case OPT_frust_metadata_output_:
   options.set_metadata_output (arg);
   break;
@@ -447,6 +449,8 @@ Session::compile_crate (const char *filename)
   return;
 }
 
+  auto last_step = options.get_compile_until ();
+
   // parse file here
   /* create lexer and parser - these are file-specific and so aren't instance
* variables */
@@ -503,7 +507,7 @@ Session::compile_crate (const char *filename)
 
   // If -fsyntax-only was passed, we can just skip the remaining passes.
   // Parsing errors are already emitted in `parse_crate()`
-  if (flag_syntax_only)
+  if (flag_syntax_only || last_step == CompileOptions::CompileStep::Ast)
 return;
 
   // register plugins pipeline stage
@@ -522,8 +526,14 @@ Session::compile_crate (const char *filename)
   // TODO: what do I dump here? injected crate names?
 }
 
+  if (last_step == CompileOptions::CompileStep::AttributeCheck)
+return;
+
   Analysis::AttributeChecker ().go (parsed_crate);
 
+  if (last_step == CompileOptions::CompileStep::Expansion)
+return;
+
   // expansion pipeline stage
   expansion (parsed_crate);
   rust_debug ("\033[0;31mSUCCESSFULLY FINISHED EXPANSION \033[0m");
@@ -536,6 +546,9 @@ Session::compile_crate (const char *filename)
   rust_debug ("END POST-EXPANSION AST DUMP");
 }
 
+  if (last_step == CompileOptions::CompileStep::NameResolution)
+return;
+
   // resolution pipeline stage
   Resolver::NameResolution::Resolve (parsed_crate);
   if (options.dump_option_enabled (CompileOptions::RESOLUTION_DUMP))
@@ -546,6 +559,9 @@ Session::compile_crate (const char *filename)
   if (saw_errors ())
 return;
 
+  if (last_step == CompileOptions::CompileStep::Lowering)
+return;
+
   // lower AST to HIR
   

[COMMITTED] gccrs: const generics: Forbid default values in Functions, Traits and Impls

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc (ConstChecker::ctx_to_str): Allow
getting an error string from a specific constant context.
(ConstChecker::ctx_allows_default): New function, check if a context
allows default values for Const generics.
(ConstChecker::visit): Call into `ctx_allows_default`.
* checks/errors/rust-const-checker.h: Declare `ctx_allows_default`.

gcc/testsuite/ChangeLog:

* rust/compile/const_generics_8.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/checks/errors/rust-const-checker.cc  | 97 +--
 gcc/rust/checks/errors/rust-const-checker.h   | 25 +
 .../rust/compile/const_generics_8.rs  | 12 +++
 3 files changed, 128 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/const_generics_8.rs

diff --git a/gcc/rust/checks/errors/rust-const-checker.cc 
b/gcc/rust/checks/errors/rust-const-checker.cc
index 0c1b743cfaf..2fa9614abf1 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -52,6 +52,67 @@ ConstChecker::is_const_extern_fn (HIR::ExternalFunctionItem 
)
 });
 }
 
+const char *
+ConstChecker::ctx_to_str (ConstGenericCtx ctx)
+{
+  switch (ctx)
+{
+case ConstGenericCtx::Function:
+  return "function";
+case ConstGenericCtx::TypeAlias:
+  return "type alias";
+case ConstGenericCtx::Struct:
+  return "struct";
+case ConstGenericCtx::Enum:
+  return "enum";
+case ConstGenericCtx::Union:
+  return "union";
+case ConstGenericCtx::Trait:
+  return "trait";
+case ConstGenericCtx::Impl:
+  return "impl";
+default:
+  gcc_unreachable ();
+}
+}
+
+bool
+ConstChecker::ctx_allows_default (ConstGenericCtx ctx)
+{
+  switch (ctx)
+{
+case ConstGenericCtx::TypeAlias:
+case ConstGenericCtx::Struct:
+case ConstGenericCtx::Enum:
+case ConstGenericCtx::Trait:
+  return true;
+default:
+  return false;
+}
+}
+
+void
+ConstChecker::check_default_const_generics (
+  std::vector> , ConstGenericCtx context)
+{
+  if (ctx_allows_default (context))
+return;
+
+  for (auto  : params)
+{
+  if (param->get_kind () == GenericParam::GenericKind::CONST)
+   {
+ auto const_param = static_cast (param.get ());
+ if (const_param->has_default_expression ())
+   rust_error_at (
+ param->get_locus (),
+ "default values for const generic parameters are not "
+ "allowed in %qs items",
+ ctx_to_str (context));
+   }
+}
+}
+
 void
 ConstChecker::visit (Lifetime )
 {}
@@ -560,6 +621,9 @@ ConstChecker::visit (Function )
   if (const_fn)
 const_context.enter (function.get_mappings ().get_hirid ());
 
+  check_default_const_generics (function.get_generic_params (),
+   ConstGenericCtx::Function);
+
   for (auto  : function.get_function_params ())
 param.get_type ()->accept_vis (*this);
 
@@ -571,18 +635,27 @@ ConstChecker::visit (Function )
 
 void
 ConstChecker::visit (TypeAlias _alias)
-{}
+{
+  check_default_const_generics (type_alias.get_generic_params (),
+   ConstGenericCtx::TypeAlias);
+}
 
 void
 ConstChecker::visit (StructStruct _item)
-{}
+{
+  check_default_const_generics (struct_item.get_generic_params (),
+   ConstGenericCtx::Struct);
+}
 
 void
 ConstChecker::visit (TupleStruct _struct)
-{}
+{
+  check_default_const_generics (tuple_struct.get_generic_params (),
+   ConstGenericCtx::Struct);
+}
 
 void
-ConstChecker::visit (EnumItem )
+ConstChecker::visit (EnumItem _item)
 {}
 
 void
@@ -605,11 +678,17 @@ ConstChecker::visit (EnumItemDiscriminant )
 
 void
 ConstChecker::visit (Enum _item)
-{}
+{
+  check_default_const_generics (enum_item.get_generic_params (),
+   ConstGenericCtx::Enum);
+}
 
 void
 ConstChecker::visit (Union _item)
-{}
+{
+  check_default_const_generics (union_item.get_generic_params (),
+   ConstGenericCtx::Union);
+}
 
 void
 ConstChecker::visit (ConstantItem _item)
@@ -652,6 +731,9 @@ ConstChecker::visit (TraitItemType )
 void
 ConstChecker::visit (Trait )
 {
+  check_default_const_generics (trait.get_generic_params (),
+   ConstGenericCtx::Trait);
+
   for (auto  : trait.get_trait_items ())
 item->accept_vis (*this);
 }
@@ -659,6 +741,9 @@ ConstChecker::visit (Trait )
 void
 ConstChecker::visit (ImplBlock )
 {
+  check_default_const_generics (impl.get_generic_params (),
+   ConstGenericCtx::Impl);
+
   for (auto  : impl.get_impl_items ())
 item->accept_vis (*this);
 }
diff --git a/gcc/rust/checks/errors/rust-const-checker.h 
b/gcc/rust/checks/errors/rust-const-checker.h
index ca86b490130..13cf44b1273 100644
--- 

[COMMITTED] gccrs: attributes: Add #[macro_use] as builtin

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* util/rust-attributes.cc: Add `macro_use` to list of builtin
attributes.

gcc/testsuite/ChangeLog:

* rust/compile/macro_export_1.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/util/rust-attributes.cc | 1 +
 gcc/testsuite/rust/compile/macro_export_1.rs | 2 ++
 2 files changed, 3 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/macro_export_1.rs

diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 9db77b40dfb..1c85273e541 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -40,6 +40,7 @@ static const BuiltinAttrDefinition __definitions[]
  {"no_mangle", CODE_GENERATION},
  {"repr", CODE_GENERATION},
  {"path", EXPANSION},
+ {"macro_use", NAME_RESOLUTION},
  // From now on, these are reserved by the compiler and gated through
  // #![feature(rustc_attrs)]
  {"rustc_inherit_overflow_checks", CODE_GENERATION}};
diff --git a/gcc/testsuite/rust/compile/macro_export_1.rs 
b/gcc/testsuite/rust/compile/macro_export_1.rs
new file mode 100644
index 000..f87df083624
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro_export_1.rs
@@ -0,0 +1,2 @@
+#[macro_use]
+mod foo {}
-- 
2.39.1



[COMMITTED] gccrs: Statics are a coercion site

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

Statics can be assigned to a block expression meaning they need to behave
similarly to constant items.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-toplevel.cc (TypeCheckTopLevel::visit):
Make static items behave more similarly to const items.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/typecheck/rust-hir-type-check-toplevel.cc | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-toplevel.cc 
b/gcc/rust/typecheck/rust-hir-type-check-toplevel.cc
index b0ee292df10..594e527fdcf 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-toplevel.cc
@@ -261,11 +261,11 @@ TypeCheckTopLevel::visit (HIR::StaticItem )
   TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (var.get_expr ());
 
   TyTy::BaseType *unified
-= unify_site (var.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (type, var.get_type ()->get_locus ()),
- TyTy::TyWithLocation (expr_type,
-   var.get_expr ()->get_locus ()),
- var.get_locus ());
+= coercion_site (var.get_mappings ().get_hirid (),
+TyTy::TyWithLocation (type, var.get_type ()->get_locus ()),
+TyTy::TyWithLocation (expr_type,
+  var.get_expr ()->get_locus ()),
+var.get_locus ());
   context->insert_type (var.get_mappings (), unified);
 }
 
-- 
2.39.1



[COMMITTED] gccrs: testsuite: add loop condition execution test

2023-01-31 Thread Arthur Cohen
From: liushuyu 

gcc/testsuite/ChangeLog:

* rust/execute/torture/loop-condition-eval.rs: New test.

Signed-off-by: Zixing Liu 

Tested on x86_64-pc-linux-gnu, committed on master.

---
 .../execute/torture/loop-condition-eval.rs| 21 +++
 1 file changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/rust/execute/torture/loop-condition-eval.rs

diff --git a/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs 
b/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs
new file mode 100644
index 000..008965917ab
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs
@@ -0,0 +1,21 @@
+// { dg-output "1\n" }
+pub fn test() -> u64 {
+let mut n = 113383; // #20 in https://oeis.org/A006884
+while n != 1 {
+n = if n % 2 == 0 { n / 2 } else { 3 * n + 1 };
+}
+n
+}
+
+pub fn test_1() -> u64 {
+test()
+}
+
+extern "C" {
+fn printf(fmt: *const i8, ...);
+}
+
+fn main() -> i32 {
+unsafe { printf("%lu\n" as *const str as *const i8, test_1()) }
+0
+}
-- 
2.39.1



[COMMITTED] gccrs: add testcase with struct to test component_ref and constructor codes..

2023-01-31 Thread Arthur Cohen
From: Faisal Abbas <90.abbasfai...@gmail.com>

..in eval_constant_expression()

gcc/testsuite/ChangeLog:

* rust/compile/const8.rs: New test.

Signed-off-by: Faisal Abbas <90.abbasfai...@gmail.com>

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/testsuite/rust/compile/const8.rs | 40 
 1 file changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/const8.rs

diff --git a/gcc/testsuite/rust/compile/const8.rs 
b/gcc/testsuite/rust/compile/const8.rs
new file mode 100644
index 000..94c4268ec8c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/const8.rs
@@ -0,0 +1,40 @@
+// { dg-options "-w -O0 -fdump-tree-gimple" }
+struct Foo {
+First: i32,
+Second: f32
+}
+
+struct Bar {
+First: i32,
+Second: f32
+}
+
+struct Baz {
+First: i32,
+Second: f32
+}
+const A:Foo = Foo { First: 1, Second: 1.0 };
+const B:Bar = Bar { First: 2, Second: 2.0 };
+const C:Baz = Baz { First: 3, Second: 2.0 };
+
+const fn test() -> f32 {
+if (A.First == 2) {
+return A.Second;
+}
+else if (B.First == 2) {
+return B.Second;
+}
+else if (C.First == 2) {
+return C.Second;
+}
+
+return 0.0;
+}
+
+const D:f32 = test();
+
+fn main() {
+// { dg-final { scan-tree-dump-times {d = 2.0} 1 gimple } }
+let d = D;
+}
+
-- 
2.39.1



[COMMITTED] gccrs: const generics: Make sure const generic types are visited properly

2023-01-31 Thread Arthur Cohen
...in all contexts.

gcc/testsuite/ChangeLog:

* rust/compile/const_generics_7.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/testsuite/rust/compile/const_generics_7.rs | 17 +
 1 file changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/const_generics_7.rs

diff --git a/gcc/testsuite/rust/compile/const_generics_7.rs 
b/gcc/testsuite/rust/compile/const_generics_7.rs
new file mode 100644
index 000..2c128db92ea
--- /dev/null
+++ b/gcc/testsuite/rust/compile/const_generics_7.rs
@@ -0,0 +1,17 @@
+struct S;
+
+pub fn foo() {} // { dg-error "failed to resolve" }
+type Foo = S; // { dg-error "failed to resolve" }
+struct Foo2; // { dg-error "failed to resolve" }
+enum Foo3 { // { dg-error "failed to resolve" }
+Foo,
+Bar,
+}
+union Foo4 { // { dg-error "failed to resolve" }
+a: usize,
+b: i32,
+}
+trait Fooable {} // { dg-error "failed to resolve" }
+
+trait Traitable {}
+impl Traitable for Foo2 {} // { dg-error "failed to 
resolve" }
-- 
2.39.1



[COMMITTED] gccrs: Fix duplicated function generation on higher ranked trait bounds

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

Deuplicate function elimination can fail when we compile helpers during
higher ranked trait bound monomorphization. This because the
TyTy::BaseType info can be lost/reset during the compilation process. This
adds a second mechanism to match based on the manged names which is a bit
more reliable. This patch is required since the query based refactor of
the type system so this issue was likely hidden to to using duplicated type
info for higher ranked trait bounds.

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: Add new optional `asm_name` string
argument to `lookup_function_decl`.
* backend/rust-compile-item.cc (CompileItem::visit): Compute assembly
name and pass it to `lookup_function_decl` when calling it.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-compile-context.h | 21 -
 gcc/rust/backend/rust-compile-item.cc   | 14 --
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-context.h 
b/gcc/rust/backend/rust-compile-context.h
index 2d379c2a5fa..49f78e19b20 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -148,7 +148,8 @@ public:
   }
 
   bool lookup_function_decl (HirId id, tree *fn, DefId dId = UNKNOWN_DEFID,
-const TyTy::BaseType *ref = nullptr)
+const TyTy::BaseType *ref = nullptr,
+const std::string _name = std::string ())
   {
 // for for any monomorphized fns
 if (ref != nullptr)
@@ -163,11 +164,29 @@ public:
  {
const TyTy::BaseType *r = e.first;
tree f = e.second;
+
if (ref->is_equal (*r))
  {
*fn = f;
return true;
  }
+
+   if (DECL_ASSEMBLER_NAME_SET_P (f) && !asm_name.empty ())
+ {
+   tree raw = DECL_ASSEMBLER_NAME_RAW (f);
+   const char *rptr = IDENTIFIER_POINTER (raw);
+
+   bool lengths_match_p
+ = IDENTIFIER_LENGTH (raw) == asm_name.size ();
+   if (lengths_match_p
+   && strncmp (rptr, asm_name.c_str (),
+   IDENTIFIER_LENGTH (raw))
+== 0)
+ {
+   *fn = f;
+   return true;
+ }
+ }
  }
return false;
   }
diff --git a/gcc/rust/backend/rust-compile-item.cc 
b/gcc/rust/backend/rust-compile-item.cc
index d1cdc3b6698..b2e9b3fbf6d 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -134,11 +134,18 @@ CompileItem::visit (HIR::Function )
}
 }
 
+  const Resolver::CanonicalPath *canonical_path = nullptr;
+  bool ok = ctx->get_mappings ()->lookup_canonical_path (
+function.get_mappings ().get_nodeid (), _path);
+  rust_assert (ok);
+
+  const std::string asm_name = ctx->mangle_item (fntype, *canonical_path);
+
   // items can be forward compiled which means we may not need to invoke this
   // code. We might also have already compiled this generic function as well.
   tree lookup = NULL_TREE;
   if (ctx->lookup_function_decl (fntype->get_ty_ref (), ,
-fntype->get_id (), fntype))
+fntype->get_id (), fntype, asm_name))
 {
   // has this been added to the list then it must be finished
   if (ctx->function_completed (lookup))
@@ -160,11 +167,6 @@ CompileItem::visit (HIR::Function )
   fntype->override_context ();
 }
 
-  const Resolver::CanonicalPath *canonical_path = nullptr;
-  bool ok = ctx->get_mappings ()->lookup_canonical_path (
-function.get_mappings ().get_nodeid (), _path);
-  rust_assert (ok);
-
   if (function.get_qualifiers ().is_const ())
 ctx->push_const_context ();
 
-- 
2.39.1



[COMMITTED] gccrs: add testcase to test component_ref and constructor codes in eval_constant_expression()

2023-01-31 Thread Arthur Cohen
From: Faisal Abbas <90.abbasfai...@gmail.com>

gcc/testsuite/ChangeLog:

* rust/compile/const7.rs: New test.

Signed-off-by: Faisal Abbas <90.abbasfai...@gmail.com>

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/testsuite/rust/compile/const7.rs | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/const7.rs

diff --git a/gcc/testsuite/rust/compile/const7.rs 
b/gcc/testsuite/rust/compile/const7.rs
new file mode 100644
index 000..a7431c0c4d2
--- /dev/null
+++ b/gcc/testsuite/rust/compile/const7.rs
@@ -0,0 +1,12 @@
+// { dg-options "-w -O0 -fdump-tree-gimple" }
+struct Foo(usize, usize);
+
+const A:Foo = Foo(123, 4546);
+
+const B:usize = A.0;
+
+fn main() {
+// { dg-final { scan-tree-dump-times {b = 123} 1 gimple } }
+let b = B;
+}
+
-- 
2.39.1



[COMMITTED] gccrs: backend: correctly formulate the exit condition ...

2023-01-31 Thread Arthur Cohen
From: liushuyu 

... previously the exit condition was treated the same as the loop
condition (which is the inverse condition of the exit condition). Now
this is corrected.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Properly formulate
exit condition when compiling while loops.

Signed-off-by: Zixing Liu 

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-compile-expr.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index ea146731cbe..d58e2258947 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -727,8 +727,11 @@ CompileExpr::visit (HIR::WhileLoopExpr )
 
   tree condition
 = CompileExpr::Compile (expr.get_predicate_expr ().get (), ctx);
+  tree exit_condition
+= fold_build1_loc (expr.get_locus ().gcc_location (), TRUTH_NOT_EXPR,
+  boolean_type_node, condition);
   tree exit_expr
-= ctx->get_backend ()->exit_expression (condition, expr.get_locus ());
+= ctx->get_backend ()->exit_expression (exit_condition, expr.get_locus ());
   ctx->add_statement (exit_expr);
 
   tree code_block_stmt
-- 
2.39.1



[COMMITTED] gccrs: Unit structs are not concrete when they need substitutions

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

Fixes #1518

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Fix `is_concrete` for unit types with
substitutions.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/typecheck/rust-tyty.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 24efc7aa54c..43460d2dd2f 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -1362,6 +1362,11 @@ public:
 
   bool is_concrete () const override final
   {
+if (is_unit ())
+  {
+   return !needs_substitution ();
+  }
+
 for (auto  : variants)
   {
for (auto  : variant->get_fields ())
-- 
2.39.1



[COMMITTED] gccrs: Add new check for contains_associated_types

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

We don't need to setup associated types when a trait does not contain any
associated types.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc 
(TypeBoundPredicate::contains_associated_types):
Check if a type bound predicate contains assocated types.
* typecheck/rust-tyty.h: Declare the above mentioned function.
* typecheck/rust-hir-trait-resolve.cc: Use `contains_associated_types`
function.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/typecheck/rust-hir-trait-resolve.cc |  3 +++
 gcc/rust/typecheck/rust-tyty-bounds.cc   | 15 +++
 gcc/rust/typecheck/rust-tyty.h   |  2 ++
 3 files changed, 20 insertions(+)

diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index c14a6c3a9be..22398b1fa8a 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -368,6 +368,9 @@ void
 AssociatedImplTrait::setup_associated_types (
   const TyTy::BaseType *self, const TyTy::TypeBoundPredicate )
 {
+  if (!bound.contains_associated_types ())
+return;
+
   // compute the constrained impl block generic arguments based on self and the
   // higher ranked trait bound
   TyTy::BaseType *receiver = self->clone ();
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc 
b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 8dfd692f345..69376aaa373 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -374,6 +374,21 @@ TypeBoundPredicate::requires_generic_args () const
   return substitutions.size () > 1;
 }
 
+bool
+TypeBoundPredicate::contains_associated_types () const
+{
+  auto trait_ref = get ();
+  for (const auto _item : trait_ref->get_trait_items ())
+{
+  bool is_associated_type
+   = trait_item.get_trait_item_type ()
+ == Resolver::TraitItemReference::TraitItemType::TYPE;
+  if (is_associated_type)
+   return true;
+}
+  return false;
+}
+
 // trait item reference
 
 const Resolver::TraitItemReference *
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 14868f2bb81..24efc7aa54c 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -1057,6 +1057,8 @@ public:
 
   bool requires_generic_args () const;
 
+  bool contains_associated_types () const;
+
 private:
   DefId reference;
   Location locus;
-- 
2.39.1



[COMMITTED] gccrs: remove bad assertion

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

gcc/rust/ChangeLog:

* backend/rust-tree.cc (rs_type_quals): Comment out bad assertion

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-tree.cc | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc
index d2ddcfd2957..47506d6792a 100644
--- a/gcc/rust/backend/rust-tree.cc
+++ b/gcc/rust/backend/rust-tree.cc
@@ -974,9 +974,10 @@ rs_type_quals (const_tree type)
 return TYPE_UNQUALIFIED;
   quals = TYPE_QUALS (type);
   /* METHOD and REFERENCE_TYPEs should never have quals.  */
-  gcc_assert (
-(TREE_CODE (type) != METHOD_TYPE && !TYPE_REF_P (type))
-|| ((quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) == TYPE_UNQUALIFIED));
+  // gcc_assert (
+  //   (TREE_CODE (type) != METHOD_TYPE && !TYPE_REF_P (type))
+  //   || ((quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) ==
+  //   TYPE_UNQUALIFIED));
   return quals;
 }
 
-- 
2.39.1



[COMMITTED] gccrs: Remove param_use_canonical_types checks ported from c++ front-end

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

We are not fully setting TYPE_CANONICAL yet but we don't need to be as
strict as the C++ front-end yet. param_use_canonical_types is a command
line option we are not using either.

gcc/rust/ChangeLog:

* backend/rust-tree.cc (comptypes): Remove some C++ specific checks in
Rust const folder for now.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-tree.cc | 22 +-
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc
index d79cd96f011..d2ddcfd2957 100644
--- a/gcc/rust/backend/rust-tree.cc
+++ b/gcc/rust/backend/rust-tree.cc
@@ -2916,27 +2916,7 @@ comptypes (tree t1, tree t2, int strict)
   perform a deep check. */
return structural_comptypes (t1, t2, strict);
 
-  if (flag_checking && param_use_canonical_types)
-   {
- bool result = structural_comptypes (t1, t2, strict);
-
- if (result && TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
-   /* The two types are structurally equivalent, but their
-  canonical types were different. This is a failure of the
-  canonical type propagation code.*/
-   internal_error (
- "canonical types differ for identical types %qT and %qT", t1, t2);
- else if (!result && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
-   /* Two types are structurally different, but the canonical
-  types are the same. This means we were over-eager in
-  assigning canonical types. */
-   internal_error (
- "same canonical type node for different types %qT and %qT", t1,
- t2);
-
- return result;
-   }
-  if (!flag_checking && param_use_canonical_types)
+  if (!flag_checking)
return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
   else
return structural_comptypes (t1, t2, strict);
-- 
2.39.1



[COMMITTED] gccrs: Refactor unify to hit a unify_site

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

This allows us to enforce better error handling on unify sites

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site): Add
better unification function with debug calls.
* typecheck/rust-autoderef.cc (AutoderefCycle::cycle): Add more debug
calls and use new unify API.
* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Likewise.
(TypeCoercionRules::coerce_borrowed_pointer): Likewise.
(TypeCoercionRules::select): Likewise.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): Likewise.
* typecheck/rust-hir-trait-resolve.cc 
(TraitItemReference::resolve_item): Likewise.
(TypeCheckBase::coercion_site): Likewise.
(TypeCheckBase::cast_site): Likewise.
* typecheck/rust-hir-type-check-base.h: Likewise.
* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): 
Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 
Likewise.
* typecheck/rust-hir-type-check-implitem.cc 
(TypeCheckTopLevelImplItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): 
Likewise.
* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): 
Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): 
Likewise.
* typecheck/rust-hir-type-check-struct.cc 
(TypeCheckStructExpr::resolve): Likewise.
* typecheck/rust-hir-type-check-toplevel.cc (TypeCheckTopLevel::visit): 
Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): 
Likewise.
* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve): Likewise.
* typecheck/rust-tyctx.cc (TypeCheckContext::peek_return_type): 
Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::visit): 
Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty-rules.h: Likewise.
* typecheck/rust-tyty.cc (BaseType::mappings_str): Likewise.
(BaseType::debug): Print type name more clearly.
(BaseType::debug_str): Add new function to print type pointer and name.
(TupleType::get_name): Improve type name fetching function.
(ReferenceType::get_name): Likewise.
(PointerType::get_name): Likewise.
* typecheck/rust-tyty.h: Refactor definitions outside of the header.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1152.rs: Fix dejagnu assertion.
* rust/compile/tuple1.rs: Likewise.
* rust/compile/type-alias1.rs: Likewise.
* rust/execute/torture/operator_overload_9.rs: Likewise.
* rust/execute/torture/slice1.rs: Rework test to use new parsing
capability and stick to the original implementation.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/typecheck/rust-autoderef.cc  |  15 +-
 gcc/rust/typecheck/rust-coercion.cc   |  62 +++-
 gcc/rust/typecheck/rust-hir-dot-operator.cc   |  15 +
 gcc/rust/typecheck/rust-hir-trait-resolve.cc  |  24 +-
 .../typecheck/rust-hir-type-check-base.cc |  42 ++-
 gcc/rust/typecheck/rust-hir-type-check-base.h |   4 +
 .../typecheck/rust-hir-type-check-enumitem.cc |   6 +-
 .../typecheck/rust-hir-type-check-expr.cc | 170 ---
 .../typecheck/rust-hir-type-check-implitem.cc |  17 +-
 .../typecheck/rust-hir-type-check-item.cc |  11 +-
 .../typecheck/rust-hir-type-check-path.cc |   5 +-
 .../typecheck/rust-hir-type-check-pattern.cc  |   4 +-
 .../typecheck/rust-hir-type-check-stmt.cc |  15 +-
 .../typecheck/rust-hir-type-check-struct.cc   |  12 +-
 .../typecheck/rust-hir-type-check-toplevel.cc |  15 +-
 .../typecheck/rust-hir-type-check-type.cc |   8 +-
 gcc/rust/typecheck/rust-hir-type-check.cc |  12 +-
 gcc/rust/typecheck/rust-tyctx.cc  |   1 +
 gcc/rust/typecheck/rust-tyty-call.cc  |   5 +-
 gcc/rust/typecheck/rust-tyty-cmp.h|   4 +-
 gcc/rust/typecheck/rust-tyty-rules.h  | 264 ++
 gcc/rust/typecheck/rust-tyty.cc   |  61 +++-
 gcc/rust/typecheck/rust-tyty.h|  36 +--
 gcc/testsuite/rust/compile/issue-1152.rs  |   2 -
 gcc/testsuite/rust/compile/tuple1.rs  |   2 +-
 gcc/testsuite/rust/compile/type-alias1.rs |   2 +-
 .../execute/torture/operator_overload_9.rs|   2 +-
 gcc/testsuite/rust/execute/torture/slice1.rs  |   7 +-
 28 files changed, 460 insertions(+), 363 deletions(-)

diff --git a/gcc/rust/typecheck/rust-autoderef.cc 
b/gcc/rust/typecheck/rust-autoderef.cc
index 71d39cff3de..ca43f847e98 100644
--- a/gcc/rust/typecheck/rust-autoderef.cc
+++ b/gcc/rust/typecheck/rust-autoderef.cc
@@ -255,7 +255,12 @@ resolve_operator_overload_fn (
  lookup = fn->infer_substitions (Location 

[COMMITTED] gccrs: Add extra debugging for method call expressions

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add
more calls to `rust_debug` for development.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 12 
 1 file changed, 12 insertions(+)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index a0eb1a596f7..bea5eb8cb0b 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1024,6 +1024,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr )
   return;
 }
 
+  rust_debug_loc (expr.get_method_name ().get_locus (),
+ "resolved method to: {%u} {%s}",
+ candidate.candidate.ty->get_ref (),
+ candidate.candidate.ty->debug_str ().c_str ());
+
   // Get the adjusted self
   Adjuster adj (receiver_tyty);
   TyTy::BaseType *adjusted_self = adj.adjust_type (candidate.adjustments);
@@ -1120,6 +1125,9 @@ TypeCheckExpr::visit (HIR::MethodCallExpr )
   // apply any remaining generic arguments
   if (expr.get_method_name ().has_generic_args ())
 {
+  rust_debug_loc (expr.get_method_name ().get_generic_args ().get_locus (),
+ "applying generic arguments to method_call: {%s}",
+ lookup->debug_str ().c_str ());
   HIR::GenericArgs  = expr.get_method_name ().get_generic_args ();
   lookup
= SubstMapper::Resolve (lookup, expr.get_method_name ().get_locus (),
@@ -1129,10 +1137,14 @@ TypeCheckExpr::visit (HIR::MethodCallExpr )
 }
   else if (lookup->needs_generic_substitutions ())
 {
+  rust_debug ("method needs inference: {%s}",
+ lookup->debug_str ().c_str ());
   lookup = SubstMapper::InferSubst (lookup,
expr.get_method_name ().get_locus ());
 }
 
+  rust_debug ("type-checking method_call: {%s}", lookup->debug_str ().c_str 
());
+
   TyTy::BaseType *function_ret_tyty
 = TyTy::TypeCheckMethodCallExpr::go (lookup, expr, adjusted_self, context);
   if (function_ret_tyty == nullptr
-- 
2.39.1



[COMMITTED] gccrs: ast: Add better assertion on AST fragments

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* ast/rust-ast.h: Improve assertions within ASTFragment API.

Co-authored-by: philberty 

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/ast/rust-ast.h | 47 ++---
 1 file changed, 39 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 58fe2674479..9e1b8b11373 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -1819,7 +1819,7 @@ public:
 return true;
   }
 
-  std::string as_string ()
+  std::string as_string () const
   {
 switch (kind)
   {
@@ -1869,14 +1869,45 @@ private:
*/
 
   bool is_single_fragment () const { return nodes.size () == 1; }
-  bool is_single_fragment (SingleASTNode::NodeType expected) const
+
+  bool is_single_fragment_of_kind (SingleASTNode::NodeType expected) const
   {
 return is_single_fragment () && nodes[0].get_kind () == expected;
   }
 
-  bool is_single_fragment_kind (SingleASTNode::NodeType kind) const
+  void assert_single_fragment (SingleASTNode::NodeType expected) const
   {
-return is_single_fragment () && nodes[0].get_kind () == kind;
+static const std::map str_map = {
+  {SingleASTNode::NodeType::IMPL, "impl"},
+  {SingleASTNode::NodeType::ITEM, "item"},
+  {SingleASTNode::NodeType::TYPE, "type"},
+  {SingleASTNode::NodeType::EXPRESSION, "expr"},
+  {SingleASTNode::NodeType::STMT, "stmt"},
+  {SingleASTNode::NodeType::EXTERN, "extern"},
+  {SingleASTNode::NodeType::TRAIT, "trait"},
+  {SingleASTNode::NodeType::TRAIT_IMPL, "trait impl"},
+};
+
+auto actual = nodes[0].get_kind ();
+auto fail = false;
+
+if (!is_single_fragment ())
+  {
+   rust_error_at (Location (), "fragment is not single");
+   fail = true;
+  }
+
+if (actual != expected)
+  {
+   rust_error_at (
+ Location (),
+ "invalid fragment operation: expected %qs node, got %qs node",
+ str_map.find (expected)->second,
+ str_map.find (nodes[0].get_kind ())->second);
+   fail = true;
+  }
+
+rust_assert (!fail);
   }
 
 public:
@@ -1920,23 +1951,23 @@ public:
 
   bool is_expression_fragment () const
   {
-return is_single_fragment (SingleASTNode::NodeType::EXPRESSION);
+return is_single_fragment_of_kind (SingleASTNode::NodeType::EXPRESSION);
   }
 
   bool is_type_fragment () const
   {
-return is_single_fragment (SingleASTNode::NodeType::TYPE);
+return is_single_fragment_of_kind (SingleASTNode::NodeType::TYPE);
   }
 
   std::unique_ptr take_expression_fragment ()
   {
-rust_assert (is_single_fragment_kind 
(SingleASTNode::NodeType::EXPRESSION));
+assert_single_fragment (SingleASTNode::NodeType::EXPRESSION);
 return nodes[0].take_expr ();
   }
 
   std::unique_ptr take_type_fragment ()
   {
-rust_assert (is_single_fragment_kind (SingleASTNode::NodeType::TYPE));
+assert_single_fragment (SingleASTNode::NodeType::TYPE);
 return nodes[0].take_type ();
   }
 
-- 
2.39.1



[COMMITTED] gccrs: transcriber: Do not infinite loop if the current parsed node is an error

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (parse_many): Return early from parsing
loop if we encounter an error, and emit that error in the meantime.

Co-authored-by: philberty 

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/expand/rust-macro-expand.cc | 8 
 1 file changed, 8 insertions(+)

diff --git a/gcc/rust/expand/rust-macro-expand.cc 
b/gcc/rust/expand/rust-macro-expand.cc
index df258bd96ec..ed1b838c987 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -731,6 +731,14 @@ parse_many (Parser , TokenId 
,
break;
 
   auto node = parse_fn ();
+  if (node.is_error ())
+   {
+ for (auto err : parser.get_errors ())
+   err.emit_error ();
+
+ return AST::ASTFragment::create_error ();
+   }
+
   nodes.emplace_back (std::move (node));
 }
 
-- 
2.39.1



[COMMITTED] gccrs: ast: Only expand expressions and types if the kind is right

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* ast/rust-ast.h: Add assertions and accessors for fragment nodes.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Fix expansion
context typo when visiting `InherentImpl` items.
(AttrVisitor::maybe_expand_expr): Use new Fragment accessor to fetch
properly typed node.
(AttrVisitor::maybe_expand_type): Likewise.
* expand/rust-macro-expand.cc (transcribe_type): Emit parse errors
when trying to parse a type.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/ast/rust-ast.h   | 15 +++
 gcc/rust/expand/rust-attribute-visitor.cc | 11 +++
 gcc/rust/expand/rust-macro-expand.cc  |  4 +++-
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 213208efb56..58fe2674479 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -24,6 +24,7 @@
 #include "rust-hir-map.h"
 #include "rust-token.h"
 #include "rust-location.h"
+#include "rust-diagnostics.h"
 
 namespace Rust {
 // TODO: remove typedefs and make actual types for these
@@ -1868,6 +1869,10 @@ private:
*/
 
   bool is_single_fragment () const { return nodes.size () == 1; }
+  bool is_single_fragment (SingleASTNode::NodeType expected) const
+  {
+return is_single_fragment () && nodes[0].get_kind () == expected;
+  }
 
   bool is_single_fragment_kind (SingleASTNode::NodeType kind) const
   {
@@ -1913,6 +1918,16 @@ public:
 
   bool should_expand () const { return !is_error (); }
 
+  bool is_expression_fragment () const
+  {
+return is_single_fragment (SingleASTNode::NodeType::EXPRESSION);
+  }
+
+  bool is_type_fragment () const
+  {
+return is_single_fragment (SingleASTNode::NodeType::TYPE);
+  }
+
   std::unique_ptr take_expression_fragment ()
   {
 rust_assert (is_single_fragment_kind 
(SingleASTNode::NodeType::EXPRESSION));
diff --git a/gcc/rust/expand/rust-attribute-visitor.cc 
b/gcc/rust/expand/rust-attribute-visitor.cc
index 15aedbfa668..673f0432a30 100644
--- a/gcc/rust/expand/rust-attribute-visitor.cc
+++ b/gcc/rust/expand/rust-attribute-visitor.cc
@@ -2662,7 +2662,7 @@ AttrVisitor::visit (AST::InherentImpl )
   for (auto  : impl.get_generic_params ())
 param->accept_vis (*this);
 
-  expander.push_context (MacroExpander::ContextType::TYPE);
+  expander.push_context (MacroExpander::ContextType::ITEM);
 
   auto  = impl.get_type ();
   type->accept_vis (*this);
@@ -2706,7 +2706,7 @@ AttrVisitor::visit (AST::TraitImpl )
   for (auto  : impl.get_generic_params ())
 param->accept_vis (*this);
 
-  expander.push_context (MacroExpander::ContextType::TYPE);
+  expander.push_context (MacroExpander::ContextType::ITEM);
 
   auto  = impl.get_type ();
   type->accept_vis (*this);
@@ -3427,11 +3427,13 @@ AttrVisitor::visit (AST::BareFunctionType )
 
   // no where clause, apparently
 }
+
 void
 AttrVisitor::maybe_expand_expr (std::unique_ptr )
 {
   auto final_fragment = expand_macro_fragment_recursive ();
-  if (final_fragment.should_expand ())
+  if (final_fragment.should_expand ()
+  && final_fragment.is_expression_fragment ())
 expr = final_fragment.take_expression_fragment ();
 }
 
@@ -3439,7 +3441,8 @@ void
 AttrVisitor::maybe_expand_type (std::unique_ptr )
 {
   auto final_fragment = expand_macro_fragment_recursive ();
-  if (final_fragment.should_expand ())
+  if (final_fragment.should_expand () && final_fragment.is_type_fragment ())
 type = final_fragment.take_type_fragment ();
 }
+
 } // namespace Rust
diff --git a/gcc/rust/expand/rust-macro-expand.cc 
b/gcc/rust/expand/rust-macro-expand.cc
index ed1b838c987..c68faba86ad 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -864,7 +864,9 @@ transcribe_expression (Parser )
 static AST::ASTFragment
 transcribe_type (Parser )
 {
-  auto type = parser.parse_type ();
+  auto type = parser.parse_type (true);
+  for (auto err : parser.get_errors ())
+err.emit_error ();
 
   return AST::ASTFragment ({std::move (type)});
 }
-- 
2.39.1



[COMMITTED] gccrs: Create canonical process of compiling constant items

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

In order to compile a block expression constant, the simplest way for us
was to reuse what code we have and to generate an artifical function which
does not get added to the translation unit. The constant then becomes
a CALL_EXPR to this artifical function which we can pass to the constexpr
evaluator to resolve the result of this artifical 'CALL_EXPR'.

Before this patch we seperated the difference between block expressions
and non block expressions in constants. So for non block expressions we
simply compiled them as if it was a simple constant but this is not
guaranteed to be the case in rust, for example coercion sites can generate
temporaries during autoderef which we let the constant evaluator resolve
for us. This makes all constants handled in the same way to simplify the
logic here.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Improve compilation pipeline and 
simplify
function.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-compile-base.cc | 103 ++
 1 file changed, 55 insertions(+), 48 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index e1506b377ce..568abf9ca2c 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -652,65 +652,72 @@ HIRCompileBase::compile_constant_item (
   bool is_block_expr
 = const_value_expr->get_expression_type () == HIR::Expr::ExprType::Block;
 
-  // compile the expression
-  tree folded_expr = error_mark_node;
-  if (!is_block_expr)
-{
-  tree value = CompileExpr::Compile (const_value_expr, ctx);
-  folded_expr = fold_expr (value);
-}
-  else
-{
-  // in order to compile a block expr we want to reuse as much existing
-  // machineary that we already have. This means the best approach is to
-  // make a _fake_ function with a block so it can hold onto temps then
-  // use our constexpr code to fold it completely or error_mark_node
-  Backend::typed_identifier receiver;
-  tree compiled_fn_type = ctx->get_backend ()->function_type (
-   receiver, {}, {Backend::typed_identifier ("_", const_type, locus)},
-   NULL, locus);
-
-  tree fndecl
-   = ctx->get_backend ()->function (compiled_fn_type, ident, "", 0, locus);
-  TREE_READONLY (fndecl) = 1;
+  // in order to compile a block expr we want to reuse as much existing
+  // machineary that we already have. This means the best approach is to
+  // make a _fake_ function with a block so it can hold onto temps then
+  // use our constexpr code to fold it completely or error_mark_node
+  Backend::typed_identifier receiver;
+  tree compiled_fn_type = ctx->get_backend ()->function_type (
+receiver, {}, {Backend::typed_identifier ("_", const_type, locus)}, NULL,
+locus);
+
+  tree fndecl
+= ctx->get_backend ()->function (compiled_fn_type, ident, "", 0, locus);
+  TREE_READONLY (fndecl) = 1;
+
+  tree enclosing_scope = NULL_TREE;
 
-  tree enclosing_scope = NULL_TREE;
+  Location start_location = const_value_expr->get_locus ();
+  Location end_location = const_value_expr->get_locus ();
+  if (is_block_expr)
+{
   HIR::BlockExpr *function_body
= static_cast (const_value_expr);
-  Location start_location = function_body->get_locus ();
-  Location end_location = function_body->get_end_locus ();
+  start_location = function_body->get_locus ();
+  end_location = function_body->get_end_locus ();
+}
 
-  tree code_block
-   = ctx->get_backend ()->block (fndecl, enclosing_scope, {},
- start_location, end_location);
-  ctx->push_block (code_block);
+  tree code_block = ctx->get_backend ()->block (fndecl, enclosing_scope, {},
+   start_location, end_location);
+  ctx->push_block (code_block);
 
-  bool address_is_taken = false;
-  tree ret_var_stmt = NULL_TREE;
-  Bvariable *return_address
-   = ctx->get_backend ()->temporary_variable (fndecl, code_block,
-  const_type, NULL,
-  address_is_taken, locus,
-  _var_stmt);
+  bool address_is_taken = false;
+  tree ret_var_stmt = NULL_TREE;
+  Bvariable *return_address
+= ctx->get_backend ()->temporary_variable (fndecl, code_block, const_type,
+  NULL, address_is_taken, locus,
+  _var_stmt);
 
-  ctx->add_statement (ret_var_stmt);
-  ctx->push_fn (fndecl, return_address);
+  ctx->add_statement (ret_var_stmt);
+  ctx->push_fn (fndecl, return_address);
 
+  if (is_block_expr)
+{
+  HIR::BlockExpr *function_body
+   = static_cast (const_value_expr);
   compile_function_body (ctx, fndecl, *function_body, true);
-  

[COMMITTED] gccrs: Add missing location info to coercions

2023-01-31 Thread Arthur Cohen
From: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::TypeCheckBase):
Remove constructor.
(TypeCheckBase::coercion_site): Add `Location` argument to function.
* typecheck/rust-hir-type-check-base.h: Use 
`TypeCheckBase::coercion_site`
function with location argument.
* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): 
Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 
Likewise.
* typecheck/rust-hir-type-check-expr.h (class TypeCheckExpr): Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): 
Likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): 
Likewise.
* typecheck/rust-hir-type-check-toplevel.cc (TypeCheckTopLevel::visit): 
Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise.
(TypeCheckMethodCallExpr::visit): Likewise.
* typecheck/rust-tyty.h: Add missing locus field.
* typecheck/rust-tyty.cc (StructFieldType::clone): Use locus field.
(StructFieldType::monomorphized_clone): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 .../typecheck/rust-hir-type-check-base.cc | 12 +-
 gcc/rust/typecheck/rust-hir-type-check-base.h | 10 ++---
 .../typecheck/rust-hir-type-check-enumitem.cc |  6 ++-
 .../typecheck/rust-hir-type-check-expr.cc |  4 +-
 gcc/rust/typecheck/rust-hir-type-check-expr.h |  2 +-
 .../typecheck/rust-hir-type-check-stmt.cc | 24 +++
 .../typecheck/rust-hir-type-check-struct.cc   | 29 ++---
 .../typecheck/rust-hir-type-check-toplevel.cc |  9 ++--
 gcc/rust/typecheck/rust-tyty-call.cc  | 41 +++
 gcc/rust/typecheck/rust-tyty.cc   |  5 ++-
 gcc/rust/typecheck/rust-tyty.h| 11 +++--
 11 files changed, 109 insertions(+), 44 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index f75266b2160..b809ac33108 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -25,6 +25,11 @@
 namespace Rust {
 namespace Resolver {
 
+TypeCheckBase::TypeCheckBase ()
+  : mappings (Analysis::Mappings::get ()), resolver (Resolver::get ()),
+context (TypeCheckContext::get ())
+{}
+
 bool
 TypeCheckBase::check_for_unconstrained (
   const std::vector _to_constrain,
@@ -332,9 +337,12 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec 
, Location locus)
 }
 
 TyTy::BaseType *
-TypeCheckBase::coercion_site (HirId id, TyTy::BaseType *expected,
- TyTy::BaseType *expr, Location locus)
+TypeCheckBase::coercion_site (HirId id, TyTy::TyWithLocation lhs,
+ TyTy::TyWithLocation rhs, Location locus)
 {
+  TyTy::BaseType *expected = lhs.get_ty ();
+  TyTy::BaseType *expr = rhs.get_ty ();
+
   rust_debug ("coercion_site id={%u} expected={%s} expr={%s}", id,
  expected->debug_str ().c_str (), expr->debug_str ().c_str ());
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h 
b/gcc/rust/typecheck/rust-hir-type-check-base.h
index d5b12705f63..acdf55713d5 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.h
@@ -24,7 +24,6 @@
 #include "rust-name-resolver.h"
 #include "rust-hir-visitor.h"
 #include "rust-hir-map.h"
-#include "rust-backend.h"
 
 namespace Rust {
 namespace Resolver {
@@ -35,8 +34,8 @@ class TypeCheckBase
 public:
   virtual ~TypeCheckBase () {}
 
-  static TyTy::BaseType *coercion_site (HirId id, TyTy::BaseType *lhs,
-   TyTy::BaseType *rhs,
+  static TyTy::BaseType *coercion_site (HirId id, TyTy::TyWithLocation lhs,
+   TyTy::TyWithLocation rhs,
Location coercion_locus);
 
   static TyTy::BaseType *cast_site (HirId id, TyTy::TyWithLocation from,
@@ -44,10 +43,7 @@ public:
Location cast_locus);
 
 protected:
-  TypeCheckBase ()
-: mappings (Analysis::Mappings::get ()), resolver (Resolver::get ()),
-  context (TypeCheckContext::get ())
-  {}
+  TypeCheckBase ();
 
   TraitReference *resolve_trait_path (HIR::TypePath &);
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc 
b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
index e7a7f08853b..0a99d444060 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
@@ -129,7 +129,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple )
= TypeCheckType::Resolve (field.get_field_type ().get ());
   TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
-std::to_string (idx), field_type);
+  

[COMMITTED] gccrs: lint: Do not emit unused warnings for public items

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* checks/lints/rust-lint-scan-deadcode.h: Do not report public items
as dead code.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1031.rs: Remove extraneous dead code warnings.
* rust/compile/issue-1289.rs: Likewise.
* rust/compile/test_mod.rs: Likewise.
* rust/compile/torture/raw_identifiers.rs: Likewise.
* rust/compile/torture/raw_identifiers_keywords.rs: Likewise.
* rust/compile/privacy7.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/checks/lints/rust-lint-scan-deadcode.h  | 9 +
 gcc/testsuite/rust/compile/issue-1031.rs | 2 --
 gcc/testsuite/rust/compile/issue-1289.rs | 2 --
 gcc/testsuite/rust/compile/privacy7.rs   | 9 +
 gcc/testsuite/rust/compile/test_mod.rs   | 1 -
 gcc/testsuite/rust/compile/torture/raw_identifiers.rs| 4 ++--
 .../rust/compile/torture/raw_identifiers_keywords.rs | 4 ++--
 7 files changed, 18 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/privacy7.rs

diff --git a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h 
b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
index 3289b7d759b..63a308949c3 100644
--- a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
+++ b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
@@ -53,7 +53,7 @@ public:
   void visit (HIR::Function ) override
   {
 HirId hirId = function.get_mappings ().get_hirid ();
-if (should_warn (hirId))
+if (should_warn (hirId) && !function.get_visibility ().is_public ())
   {
if (mappings->is_impl_item (hirId))
  {
@@ -78,7 +78,7 @@ public:
   void visit (HIR::StructStruct ) override
   {
 HirId hirId = stct.get_mappings ().get_hirid ();
-if (should_warn (hirId))
+if (should_warn (hirId) && !stct.get_visibility ().is_public ())
   {
bool name_starts_underscore = stct.get_identifier ().at (0) == '_';
if (!name_starts_underscore)
@@ -92,7 +92,8 @@ public:
for (auto  : stct.get_fields ())
  {
HirId field_hir_id = field.get_mappings ().get_hirid ();
-   if (should_warn (field_hir_id))
+   if (should_warn (field_hir_id)
+   && !field.get_visibility ().is_public ())
  {
rust_warning_at (field.get_locus (), 0,
 "field is never read: %<%s%>",
@@ -106,7 +107,7 @@ public:
   {
 // only warn tuple struct unconstructed, and ignoring unused field
 HirId hirId = stct.get_mappings ().get_hirid ();
-if (should_warn (hirId))
+if (should_warn (hirId) && !stct.get_visibility ().is_public ())
   {
rust_warning_at (stct.get_locus (), 0,
 "struct is never constructed: %<%s%>",
diff --git a/gcc/testsuite/rust/compile/issue-1031.rs 
b/gcc/testsuite/rust/compile/issue-1031.rs
index 939f0f981e0..5ba8f7a267b 100644
--- a/gcc/testsuite/rust/compile/issue-1031.rs
+++ b/gcc/testsuite/rust/compile/issue-1031.rs
@@ -6,12 +6,10 @@ extern "rust-intrinsic" {
 #[lang = "const_ptr"]
 impl *const T {
 pub const unsafe fn offset(self, count: isize) -> *const T {
-// { dg-warning "associated function is never used" "" { target *-*-* 
} .-1 }
 unsafe { offset(self, count) }
 }
 
 pub const unsafe fn add(self, count: usize) -> Self {
-// { dg-warning "associated function is never used" "" { target *-*-* 
} .-1 }
 unsafe { self.offset(count as isize) }
 }
 }
diff --git a/gcc/testsuite/rust/compile/issue-1289.rs 
b/gcc/testsuite/rust/compile/issue-1289.rs
index 343aaab078b..eb41af0a75b 100644
--- a/gcc/testsuite/rust/compile/issue-1289.rs
+++ b/gcc/testsuite/rust/compile/issue-1289.rs
@@ -23,12 +23,10 @@ impl *mut T {
 #[lang = "const_ptr"]
 impl *const T {
 pub const unsafe fn offset(self, count: isize) -> *mut T {
-// { dg-warning "associated function is never used" "" { target *-*-* 
} .-1 }
 unsafe { intrinsics::offset(self, count) as *mut T }
 }
 
 pub const unsafe fn add(self, count: usize) -> Self {
-// { dg-warning "associated function is never used" "" { target *-*-* 
} .-1 }
 unsafe { self.offset(count as isize) }
 }
 }
diff --git a/gcc/testsuite/rust/compile/privacy7.rs 
b/gcc/testsuite/rust/compile/privacy7.rs
new file mode 100644
index 000..00fa0ef8f11
--- /dev/null
+++ b/gcc/testsuite/rust/compile/privacy7.rs
@@ -0,0 +1,9 @@
+pub struct Foo(i8);
+struct Bar(pub i8); // { dg-warning "struct is never constructed: .Bar." }
+pub struct Baz {
+a: i32, // { dg-warning "field is never read: .a." }
+pub b: i32,
+}
+
+pub fn foo() {}
+fn bar() {} // { dg-warning "function is never used: .bar." }
diff --git a/gcc/testsuite/rust/compile/test_mod.rs 
b/gcc/testsuite/rust/compile/test_mod.rs
index 4b3c000236b..6e9c19b3fa4 100644
--- a/gcc/testsuite/rust/compile/test_mod.rs
+++ 

[COMMITTED] gccrs: dump: Add AST debugging using the AST::Dump class

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* ast/rust-ast-dump.h: Add shorthand `AST::Dump::debug` function to
dump an AST node on `stderr`.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/ast/rust-ast-dump.h | 16 
 1 file changed, 16 insertions(+)

diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index 4fa4db9265f..955dbc0bebc 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -52,6 +52,22 @@ public:
   void go (AST::Crate );
   void go (AST::Item );
 
+  /**
+   * Use the AST Dump as a debugging tool
+   */
+  template  static void debug (T )
+  {
+auto dump = Dump (std::cerr);
+
+std::cerr << '\n';
+instance.accept_vis (dump);
+std::cerr << '\n';
+  }
+  template  static void debug (std::unique_ptr )
+  {
+debug (*instance);
+  }
+
 private:
   std::ostream 
   Indent indentation;
-- 
2.39.1



[COMMITTED] gccrs: macros: Handle matchers properly in repetitions

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (MacroExpander::match_matcher): Handle
fragments differently based on whether or not we are currently trying
to match a matcher in a repetition context.
(MacroExpander::match_n_matches): Use new `in_repetition` argument
properly when calling `match_matcher`.
* expand/rust-macro-expand.h (MacroExpander::match_matcher): Allow
passing extra `in_repetition` bool argument

gcc/testsuite/ChangeLog:

* rust/compile/macro43.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/expand/rust-macro-expand.cc  | 14 +++---
 gcc/rust/expand/rust-macro-expand.h   |  2 +-
 gcc/testsuite/rust/compile/macro43.rs | 64 +++
 3 files changed, 74 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/macro43.rs

diff --git a/gcc/rust/expand/rust-macro-expand.cc 
b/gcc/rust/expand/rust-macro-expand.cc
index a214ca906bf..df258bd96ec 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -435,7 +435,7 @@ MacroExpander::match_fragment (Parser 
,
 
 bool
 MacroExpander::match_matcher (Parser ,
- AST::MacroMatcher )
+ AST::MacroMatcher , bool in_repetition)
 {
   if (depth_exceeds_recursion_limit ())
 {
@@ -485,8 +485,12 @@ MacroExpander::match_matcher (Parser 
,
 
// matched fragment get the offset in the token stream
size_t offs_end = source.get_offs ();
-   sub_stack.insert_metavar (
- MatchedFragment (fragment->get_ident (), offs_begin, offs_end));
+   if (in_repetition)
+ sub_stack.append_fragment (
+   MatchedFragment (fragment->get_ident (), offs_begin, offs_end));
+   else
+ sub_stack.insert_metavar (
+   MatchedFragment (fragment->get_ident (), offs_begin, offs_end));
  }
  break;
 
@@ -509,7 +513,7 @@ MacroExpander::match_matcher (Parser 
,
AST::MacroMatcher *m
  = static_cast (match.get ());
expansion_depth++;
-   if (!match_matcher (parser, *m))
+   if (!match_matcher (parser, *m, in_repetition))
  {
expansion_depth--;
return false;
@@ -619,7 +623,7 @@ MacroExpander::match_n_matches (Parser 
,
  case AST::MacroMatch::MacroMatchType::Matcher: {
AST::MacroMatcher *m
  = static_cast (match.get ());
-   valid_current_match = match_matcher (parser, *m);
+   valid_current_match = match_matcher (parser, *m, true);
  }
  break;
}
diff --git a/gcc/rust/expand/rust-macro-expand.h 
b/gcc/rust/expand/rust-macro-expand.h
index 97a02692d1f..bef140236b3 100644
--- a/gcc/rust/expand/rust-macro-expand.h
+++ b/gcc/rust/expand/rust-macro-expand.h
@@ -273,7 +273,7 @@ struct MacroExpander
 AST::MacroMatchRepetition );
 
   bool match_matcher (Parser ,
- AST::MacroMatcher );
+ AST::MacroMatcher , bool in_repetition = false);
 
   /**
* Match any amount of matches
diff --git a/gcc/testsuite/rust/compile/macro43.rs 
b/gcc/testsuite/rust/compile/macro43.rs
new file mode 100644
index 000..c7bf50a030e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro43.rs
@@ -0,0 +1,64 @@
+macro_rules! nonzero_integers {
+( $( $Ty: ident($Int: ty); )+ ) => {
+$(
+/// An integer that is known not to equal zero.
+///
+/// This enables some memory layout optimization.
+/// For example, `Option` is the same size as `u32`:
+///
+/// ```rust
+/// use std::mem::size_of;
+/// assert_eq!(size_of::>(), 
size_of::());
+/// ```
+#[stable(feature = "nonzero", since = "1.28.0")]
+#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
+#[repr(transparent)]
+pub struct $Ty(NonZero<$Int>);
+
+impl $Ty {
+/// Create a non-zero without checking the value.
+///
+/// # Safety
+///
+/// The value must not be zero.
+#[stable(feature = "nonzero", since = "1.28.0")]
+#[inline]
+pub const unsafe fn new_unchecked(n: $Int) -> Self {
+$Ty(NonZero(n))
+}
+
+/// Create a non-zero if the given value is not zero.
+#[stable(feature = "nonzero", since = "1.28.0")]
+#[inline]
+pub fn new(n: $Int) -> Option {
+if n != 0 {
+Some($Ty(NonZero(n)))
+} else {
+None
+}
+}
+
+/// 

[COMMITTED] gccrs: backend: Add overflow checks to every arithmetic operation

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Insert overflow
checks logic.
(CompileExpr::array_copied_expr): Insert overflow checks logic.
* backend/rust-compile-item.cc (CompileItem::visit): Insert overflow
checks logic.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Insert
overflow checks logic.
* rust-gcc.cc (Gcc_backend::arithmetic_or_logical_expression): 
Differentiate
existing function from `arithmetic_or_logical_expression_checked`.
This function does insert perform overflow checks.
(Gcc_backend::arithmetic_or_logical_expression_checked): New
function.
(is_overflowing_expr): New function. Check if an expression is an
overflowing one (ADD, SUB, MUL).
(fetch_overflow_builtins): New function.
* rust-backend.h: Declare `arithmetic_or_logical_expression_checked` in
abstract `Backend` class.

gcc/testsuite/ChangeLog:

* rust/debug/win64-abi.rs: Fix assertion to take into account
overflow builtins
* rust/compile/torture/macro-issue1426.rs: Moved to...
* rust/execute/torture/macro-issue1426.rs: ...here.
* rust/execute/torture/overflow1.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-compile-expr.cc |  55 +--
 gcc/rust/backend/rust-compile-item.cc |   6 +
 gcc/rust/backend/rust-compile-type.cc |   4 +
 gcc/rust/rust-backend.h   |  19 ++-
 gcc/rust/rust-gcc.cc  | 140 --
 gcc/testsuite/rust/debug/win64-abi.rs |   8 +-
 .../torture/macro-issue1426.rs|   9 +-
 .../rust/execute/torture/overflow1.rs |  20 +++
 8 files changed, 223 insertions(+), 38 deletions(-)
 rename gcc/testsuite/rust/{compile => execute}/torture/macro-issue1426.rs (68%)
 create mode 100644 gcc/testsuite/rust/execute/torture/overflow1.rs

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 9db14a238a7..ea146731cbe 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -26,6 +26,7 @@
 #include "rust-compile-block.h"
 #include "rust-compile-implitem.h"
 #include "rust-constexpr.h"
+#include "rust-gcc.h"
 
 #include "fold-const.h"
 #include "realmpfr.h"
@@ -146,9 +147,26 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr )
   return;
 }
 
-  translated
-= ctx->get_backend ()->arithmetic_or_logical_expression (op, lhs, rhs,
-expr.get_locus ());
+  if (ctx->in_fn () && !ctx->const_context_p ())
+{
+  auto receiver_tmp = NULL_TREE;
+  auto receiver
+   = ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl,
+  NULL_TREE, TREE_TYPE (lhs),
+  lhs, true, expr.get_locus (),
+  _tmp);
+  auto check
+   = ctx->get_backend ()->arithmetic_or_logical_expression_checked (
+ op, lhs, rhs, expr.get_locus (), receiver);
+
+  ctx->add_statement (check);
+  translated = receiver->get_tree (expr.get_locus ());
+}
+  else
+{
+  translated = ctx->get_backend ()->arithmetic_or_logical_expression (
+   op, lhs, rhs, expr.get_locus ());
+}
 }
 
 void
@@ -176,13 +194,27 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr )
   return;
 }
 
-  auto operator_expr
-= ctx->get_backend ()->arithmetic_or_logical_expression (op, lhs, rhs,
-expr.get_locus ());
-  tree assignment
-= ctx->get_backend ()->assignment_statement (lhs, operator_expr,
-expr.get_locus ());
-  ctx->add_statement (assignment);
+  if (ctx->in_fn () && !ctx->const_context_p ())
+{
+  auto tmp = NULL_TREE;
+  auto receiver
+   = ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl,
+  NULL_TREE, TREE_TYPE (lhs),
+  lhs, true, expr.get_locus (),
+  );
+  auto check
+   = ctx->get_backend ()->arithmetic_or_logical_expression_checked (
+ op, lhs, rhs, expr.get_locus (), receiver);
+  ctx->add_statement (check);
+
+  translated = ctx->get_backend ()->assignment_statement (
+   lhs, receiver->get_tree (expr.get_locus ()), expr.get_locus ());
+}
+  else
+{
+  translated = ctx->get_backend ()->arithmetic_or_logical_expression (
+   op, lhs, rhs, expr.get_locus ());
+}
 }
 
 void
@@ -2383,7 +2415,10 @@ CompileExpr::array_copied_expr (Location expr_locus,
   return error_mark_node;
 }
 
+  ctx->push_const_context ();
   tree 

[COMMITTED] gccrs: parser: Parse RangeFullExpr without erroring out

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* parse/rust-parse-impl.h: Allow parsing full range expressions without
erroring out.

gcc/testsuite/ChangeLog:

* rust/compile/parse_range.rs: New test.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/parse/rust-parse-impl.h  | 6 +-
 gcc/testsuite/rust/compile/parse_range.rs | 9 +
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/rust/compile/parse_range.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index fe628647653..72207a1bc22 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -14112,9 +14112,13 @@ std::unique_ptr
 Parser::parse_nud_range_exclusive_expr (
   const_TokenPtr tok, AST::AttrVec outer_attrs ATTRIBUTE_UNUSED)
 {
+  auto restrictions = ParseRestrictions ();
+  restrictions.expr_can_be_null = true;
+
   // FIXME: this probably parses expressions accidently or whatever
   // try parsing RHS (as tok has already been consumed in parse_expression)
-  std::unique_ptr right = parse_expr (LBP_DOT_DOT, AST::AttrVec ());
+  std::unique_ptr right
+= parse_expr (LBP_DOT_DOT, AST::AttrVec (), restrictions);
 
   Location locus = tok->get_locus ();
 
diff --git a/gcc/testsuite/rust/compile/parse_range.rs 
b/gcc/testsuite/rust/compile/parse_range.rs
new file mode 100644
index 000..03469b1f8d5
--- /dev/null
+++ b/gcc/testsuite/rust/compile/parse_range.rs
@@ -0,0 +1,9 @@
+// { dg-additional-options "-fsyntax-only" }
+
+fn main() {
+let a = [1, 2, 3, 4];
+let _ = a[0..];
+let _ = a[..3];
+let _ = a[0..3];
+let _ = a[..];
+}
-- 
2.39.1



[COMMITTED] gccrs: builtins: Add add_overflow builtin and refactor class

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* backend/rust-builtins.h: Refactor builtin context class and add
overflow builtins.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/backend/rust-builtins.h | 51 ++--
 1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/gcc/rust/backend/rust-builtins.h b/gcc/rust/backend/rust-builtins.h
index 2bfa6c6cdf7..5cd84010723 100644
--- a/gcc/rust/backend/rust-builtins.h
+++ b/gcc/rust/backend/rust-builtins.h
@@ -18,8 +18,9 @@
 #define RUST_BUILTINS_H
 
 #include "rust-system.h"
-#include "tree.h"
+#include "rust-tree.h"
 #include "langhooks.h"
+#include "tree.h"
 
 namespace Rust {
 namespace Compile {
@@ -99,16 +100,34 @@ private:
 
   BuiltinsContext () { setup (); }
 
-  void setup ()
+  void setup_overflow_fns ()
+  {
+tree overflow_type
+  = build_varargs_function_type_list (boolean_type_node, NULL_TREE);
+
+define_builtin ("add_overflow", BUILT_IN_ADD_OVERFLOW,
+   "__builtin_add_overflow", "add_overflow", overflow_type, 0);
+define_builtin ("sub_overflow", BUILT_IN_SUB_OVERFLOW,
+   "__builtin_sub_overflow", "sub_overflow", overflow_type, 0);
+define_builtin ("mul_overflow", BUILT_IN_MUL_OVERFLOW,
+   "__builtin_mul_overflow", "mul_overflow", overflow_type, 0);
+  }
+
+  void setup_math_fns ()
   {
 tree math_function_type_f32
   = build_function_type_list (float_type_node, float_type_node, NULL_TREE);
 
 define_builtin ("sinf32", BUILT_IN_SINF, "__builtin_sinf", "sinf",
math_function_type_f32, builtin_const);
-
 define_builtin ("sqrtf32", BUILT_IN_SQRTF, "__builtin_sqrtf", "sqrtf",
math_function_type_f32, builtin_const);
+  }
+
+  void setup ()
+  {
+setup_math_fns ();
+setup_overflow_fns ();
 
 define_builtin ("unreachable", BUILT_IN_UNREACHABLE,
"__builtin_unreachable", NULL,
@@ -132,6 +151,16 @@ private:
   0);
   }
 
+  static void handle_flags (tree decl, int flags)
+  {
+if (flags & builtin_const)
+  TREE_READONLY (decl) = 1;
+if (flags & builtin_noreturn)
+  TREE_READONLY (decl) = 1;
+if (flags & builtin_novops)
+  DECL_IS_NOVOPS (decl) = 1;
+  }
+
   // Define a builtin function.  BCODE is the builtin function code
   // defined by builtins.def.  NAME is the name of the builtin function.
   // LIBNAME is the name of the corresponding library function, and is
@@ -144,24 +173,16 @@ private:
   {
 tree decl = add_builtin_function (name, fntype, bcode, BUILT_IN_NORMAL,
  libname, NULL_TREE);
-if ((flags & builtin_const) != 0)
-  TREE_READONLY (decl) = 1;
-if ((flags & builtin_noreturn) != 0)
-  TREE_THIS_VOLATILE (decl) = 1;
-if ((flags & builtin_novops) != 0)
-  DECL_IS_NOVOPS (decl) = 1;
+handle_flags (decl, flags);
 set_builtin_decl (bcode, decl, true);
+
 this->builtin_functions_[name] = decl;
 if (libname != NULL)
   {
decl = add_builtin_function (libname, fntype, bcode, BUILT_IN_NORMAL,
 NULL, NULL_TREE);
-   if ((flags & builtin_const) != 0)
- TREE_READONLY (decl) = 1;
-   if ((flags & builtin_noreturn) != 0)
- TREE_THIS_VOLATILE (decl) = 1;
-   if ((flags & builtin_novops) != 0)
- DECL_IS_NOVOPS (decl) = 1;
+   handle_flags (decl, flags);
+
this->builtin_functions_[libname] = decl;
   }
 
-- 
2.39.1



[COMMITTED] gccrs: session-manager: Add ast-pretty-expanded dump

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Allow the dump of 
prettified AST
(Session::dump_ast_pretty): New
* rust-session-manager.h: Add new output file for pretty AST dump

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/rust/rust-session-manager.cc | 10 --
 gcc/rust/rust-session-manager.h  |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 2b33ddfa601..157f5099155 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -58,6 +58,7 @@ namespace Rust {
 const char *kLexDumpFile = "gccrs.lex.dump";
 const char *kASTDumpFile = "gccrs.ast.dump";
 const char *kASTPrettyDumpFile = "gccrs.ast-pretty.dump";
+const char *kASTPrettyDumpFileExpanded = "gccrs.ast-pretty-expanded.dump";
 const char *kASTExpandedDumpFile = "gccrs.ast-expanded.dump";
 const char *kHIRDumpFile = "gccrs.hir.dump";
 const char *kHIRPrettyDumpFile = "gccrs.hir-pretty.dump";
@@ -531,6 +532,7 @@ Session::compile_crate (const char *filename)
   // dump AST with expanded stuff
   rust_debug ("BEGIN POST-EXPANSION AST DUMP");
   dump_ast_expanded (parser, parsed_crate);
+  dump_ast_pretty (parsed_crate, true);
   rust_debug ("END POST-EXPANSION AST DUMP");
 }
 
@@ -832,10 +834,14 @@ Session::dump_ast (Parser , AST::Crate 
) const
 }
 
 void
-Session::dump_ast_pretty (AST::Crate ) const
+Session::dump_ast_pretty (AST::Crate , bool expanded) const
 {
   std::ofstream out;
-  out.open (kASTPrettyDumpFile);
+  if (expanded)
+out.open (kASTPrettyDumpFileExpanded);
+  else
+out.open (kASTPrettyDumpFile);
+
   if (out.fail ())
 {
   rust_error_at (Linemap::unknown_location (), "cannot open %s:%m; 
ignored",
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 055aea6b7e6..db915991809 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -319,7 +319,7 @@ private:
 
   void dump_lex (Parser ) const;
   void dump_ast (Parser , AST::Crate ) const;
-  void dump_ast_pretty (AST::Crate ) const;
+  void dump_ast_pretty (AST::Crate , bool expanded = false) const;
   void dump_ast_expanded (Parser , AST::Crate ) const;
   void dump_hir (HIR::Crate ) const;
   void dump_hir_pretty (HIR::Crate ) const;
-- 
2.39.1



Re: [PATCH] modula2/108462 - duplicate install of static modula2 target libs

2023-01-31 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Mon, 23 Jan 2023, Richard Biener wrote:
>
>> The following addresses the fact that libgm2 installs static libraries
>> into two places, one performed by
>> 
>> toolexeclib_LTLIBRARIES = libm2cor.la
>> 
>> and one performed as part of the install-data-local rule to a
>> m2/m2cor subdirectory alongside Modula-2 .def and .mod files.
>> 
>> This patch opts to keep the copy installed by libtool and removes
>> the extra installs in the install-data-local rules.
>> 
>> I've built and installed both with and without
>> --enable-version-specific-runtime-libs and compiled and linked
>> a Modula-2 testcase with the installed compiler with the two
>> multilibs and with and without static successfully.
>> 
>> OK for trunk?
>
> Ping.

yes sure, LGTM

A heads up that I've just renamed the gcc/m2/gm2-libs-pim directory to
gcc/m2/gm2-libs-log for consistency.  I've just tried the patch (post
rename changes) and the patch builds and installs fine (non bootstrap
test build though),

regards,
Gaius


[PATCH] vect: Fix single def-use cycle for ifn reductions [PR108608]

2023-01-31 Thread Richard Sandiford via Gcc-patches
The patch that added support for fmin/fmax reductions didn't
handle single def-use cycles.  In some ways, this seems like
going out of our way to make things slower, but that's a
discussion for another day.

Tested on aarch64-linux-gnu & x86_64-linux-gnu.  OK for trunk
and the GCC 12 branch?

Richard


gcc/
PR tree-optimization/108608
* tree-vect-loop.cc (vect_transform_reduction): Handle single
def-use cycles that involve function calls rather than tree codes.

gcc/testsuite/
PR tree-optimization/108608
* gcc.dg/vect/pr108608.c: New test.
* gcc.target/aarch64/sve/pr108608-1.c: Likewise.
---
 gcc/testsuite/gcc.dg/vect/pr108608.c  | 24 +++
 .../gcc.target/aarch64/sve/pr108608-1.c   |  9 +++
 gcc/tree-vect-loop.cc | 22 ++---
 3 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr108608.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr108608-1.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr108608.c 
b/gcc/testsuite/gcc.dg/vect/pr108608.c
new file mode 100644
index 000..e968141ba03
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr108608.c
@@ -0,0 +1,24 @@
+#include "tree-vect.h"
+
+double __attribute__((noipa))
+foo (double m, float *ptr)
+{
+  for (int i = 0; i < 256; i++)
+m = __builtin_fmax (m, ptr[i]);
+  return m;
+}
+
+int
+main (void)
+{
+  check_vect ();
+  float ptr[256];
+  for (int j = 0; j < 16; ++j)
+{
+  for (int i = 0; i < 256; ++i)
+   ptr[i] = i == 128 + j ? 2 + j : i == 161 ? 1 : 0;
+  if (foo (0, ptr) != 2 + j)
+   __builtin_abort ();
+}
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr108608-1.c 
b/gcc/testsuite/gcc.target/aarch64/sve/pr108608-1.c
new file mode 100644
index 000..0a7d485e047
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/pr108608-1.c
@@ -0,0 +1,9 @@
+/* { dg-options "-O3" } */
+
+double __attribute__((noipa))
+foo (double m, float *ptr)
+{
+  for (int i = 0; i < 256; i++)
+m = __builtin_fmax (m, ptr[i]);
+  return m;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index f0801c23671..f03af1efd0f 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7755,8 +7755,6 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
   gimple_match_op op;
   if (!gimple_extract_op (stmt_info->stmt, ))
 gcc_unreachable ();
-  gcc_assert (op.code.is_tree_code ());
-  auto code = tree_code (op.code);
 
   /* All uses but the last are expected to be defined in the loop.
  The last use is the reduction variable.  In case of nested cycle this
@@ -7778,7 +7776,8 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
   vec_num = 1;
 }
 
-  internal_fn cond_fn = get_conditional_internal_fn (code);
+  code_helper code = canonicalize_code (op.code, op.type);
+  internal_fn cond_fn = get_conditional_internal_fn (code, op.type);
   vec_loop_masks *masks = _VINFO_MASKS (loop_vinfo);
   bool mask_by_cond_expr = use_mask_by_cond_expr_p (code, cond_fn, vectype_in);
 
@@ -7802,9 +7801,10 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
   if (reduction_type == FOLD_LEFT_REDUCTION)
 {
   internal_fn reduc_fn = STMT_VINFO_REDUC_FN (reduc_info);
+  gcc_assert (code.is_tree_code ());
   return vectorize_fold_left_reduction
- (loop_vinfo, stmt_info, gsi, vec_stmt, slp_node, reduc_def_phi, code,
-  reduc_fn, op.ops, vectype_in, reduc_index, masks);
+ (loop_vinfo, stmt_info, gsi, vec_stmt, slp_node, reduc_def_phi,
+  tree_code (code), reduc_fn, op.ops, vectype_in, reduc_index, masks);
 }
 
   bool single_defuse_cycle = STMT_VINFO_FORCE_SINGLE_CYCLE (reduc_info);
@@ -7814,7 +7814,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
  || code == SAD_EXPR);
 
   /* Create the destination vector  */
-  tree scalar_dest = gimple_assign_lhs (stmt_info->stmt);
+  tree scalar_dest = gimple_get_lhs (stmt_info->stmt);
   tree vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
 
   vect_get_vec_defs (loop_vinfo, stmt_info, slp_node, ncopies,
@@ -7849,7 +7849,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
  /* Make sure that the reduction accumulator is vop[0].  */
  if (reduc_index == 1)
{
- gcc_assert (commutative_tree_code (code));
+ gcc_assert (commutative_binary_op_p (code, op.type));
  std::swap (vop[0], vop[1]);
}
  tree mask = vect_get_loop_mask (gsi, masks, vec_num * ncopies,
@@ -7877,11 +7877,15 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
  if (emulated_mixed_dot_prod)
new_stmt = vect_emulate_mixed_dot_prod (loop_vinfo, stmt_info, gsi,
vec_dest, vop);
+ else if (code.is_internal_fn ())
+   new_stmt = gimple_build_call_internal (internal_fn (code),
+

Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays

2023-01-31 Thread Siddhesh Poyarekar

On 2023-01-31 07:46, Jakub Jelinek wrote:

On Wed, Dec 21, 2022 at 05:25:54PM -0500, Siddhesh Poyarekar wrote:

The tree object size pass tries to fail when it detects a flex array in
the struct, but it ends up doing the right thing only when the flex
array is in the outermost struct.  For nested cases (such as arrays
nested in a union or an inner struct), it ends up taking whatever value
the flex array is declared with, using zero for the standard flex array,
i.e. [].

Rework subobject size computation to make it more consistent across the
board, honoring -fstrict-flex-arrays.  With this change, any array at
the end of the struct will end up causing __bos to use the allocated
value of the outer object, bailing out in the maximum case when it can't
find it.  In the minimum case, it will return the subscript value or the
allocated value of the outer object, whichever is larger.


I think it is way too late in the GCC 13 cycle to change behavior here
except for when -fstrict-flex-arrays is used.


I agree.


Plus, am not really convinced it is a good idea to change the behavior
here except for the new options, programs in the wild took 2+ years
to acommodate for what we GCC requiring and am not sure they'd be willing
to be adjusted again.


The behaviour change basically does two things: better minimum object 
size estimates and more conservative object size estimates for trailing 
arrays.  ISTM that this should in fact reduce breakages due to flex 
arrays, although one could argue that protection gets reduced for 
trailing arrays without -fstrict-flex-arrays.  It wouldn't cause 
non-mitigation behaviour changes though, would it?


We don't need to rush this of course, we could consider this for gcc 14 
given that we're well into stage 4.


Thanks,
Sid


[PATCH] RISC-V: Add vsra.vv C++ API tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* g++.target/riscv/rvv/base/vsra_vv-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vv-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vv-3.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_mu-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_mu-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_mu-3.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tu-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tu-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tu-3.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tum-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tum-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tum-3.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tumu-1.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tumu-2.C: New test.
* g++.target/riscv/rvv/base/vsra_vv_tumu-3.C: New test.

---
 .../g++.target/riscv/rvv/base/vsra_vv-1.C | 314 ++
 .../g++.target/riscv/rvv/base/vsra_vv-2.C | 314 ++
 .../g++.target/riscv/rvv/base/vsra_vv-3.C | 314 ++
 .../g++.target/riscv/rvv/base/vsra_vv_mu-1.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vv_mu-2.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vv_mu-3.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vv_tu-1.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vv_tu-2.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vv_tu-3.C  | 160 +
 .../g++.target/riscv/rvv/base/vsra_vv_tum-1.C | 160 +
 .../g++.target/riscv/rvv/base/vsra_vv_tum-2.C | 160 +
 .../g++.target/riscv/rvv/base/vsra_vv_tum-3.C | 160 +
 .../riscv/rvv/base/vsra_vv_tumu-1.C   | 160 +
 .../riscv/rvv/base/vsra_vv_tumu-2.C   | 160 +
 .../riscv/rvv/base/vsra_vv_tumu-3.C   | 160 +
 15 files changed, 2862 insertions(+)
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_mu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_mu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_mu-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tu-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tum-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tum-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tum-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tumu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tumu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv_tumu-3.C

diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-1.C 
b/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-1.C
new file mode 100644
index 000..f7f849c91ff
--- /dev/null
+++ b/gcc/testsuite/g++.target/riscv/rvv/base/vsra_vv-1.C
@@ -0,0 +1,314 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+vint8mf8_t test___riscv_vsra(vint8mf8_t op1,vuint8mf8_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8mf4_t test___riscv_vsra(vint8mf4_t op1,vuint8mf4_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8mf2_t test___riscv_vsra(vint8mf2_t op1,vuint8mf2_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8m1_t test___riscv_vsra(vint8m1_t op1,vuint8m1_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8m2_t test___riscv_vsra(vint8m2_t op1,vuint8m2_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8m4_t test___riscv_vsra(vint8m4_t op1,vuint8m4_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint8m8_t test___riscv_vsra(vint8m8_t op1,vuint8m8_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16mf4_t test___riscv_vsra(vint16mf4_t op1,vuint16mf4_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16mf2_t test___riscv_vsra(vint16mf2_t op1,vuint16mf2_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16m1_t test___riscv_vsra(vint16m1_t op1,vuint16m1_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16m2_t test___riscv_vsra(vint16m2_t op1,vuint16m2_t shift,size_t vl)
+{
+return __riscv_vsra(op1,shift,vl);
+}
+
+
+vint16m4_t test___riscv_vsra(vint16m4_t op1,vuint16m4_t shift,size_t vl)
+{
+return 

[PATCH] RISC-V: Add vsrl.vv C++ API tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* g++.target/riscv/rvv/base/vsrl_vv-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv-3.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_mu-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_mu-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_mu-3.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tu-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tu-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tu-3.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tum-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tum-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tum-3.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tumu-1.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tumu-2.C: New test.
* g++.target/riscv/rvv/base/vsrl_vv_tumu-3.C: New test.

---
 .../g++.target/riscv/rvv/base/vsrl_vv-1.C | 314 ++
 .../g++.target/riscv/rvv/base/vsrl_vv-2.C | 314 ++
 .../g++.target/riscv/rvv/base/vsrl_vv-3.C | 314 ++
 .../g++.target/riscv/rvv/base/vsrl_vv_mu-1.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vv_mu-2.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vv_mu-3.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vv_tu-1.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vv_tu-2.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vv_tu-3.C  | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vv_tum-1.C | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vv_tum-2.C | 160 +
 .../g++.target/riscv/rvv/base/vsrl_vv_tum-3.C | 160 +
 .../riscv/rvv/base/vsrl_vv_tumu-1.C   | 160 +
 .../riscv/rvv/base/vsrl_vv_tumu-2.C   | 160 +
 .../riscv/rvv/base/vsrl_vv_tumu-3.C   | 160 +
 15 files changed, 2862 insertions(+)
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_mu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_mu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_mu-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tu-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tum-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tum-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tum-3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tumu-1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tumu-2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv_tumu-3.C

diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-1.C 
b/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-1.C
new file mode 100644
index 000..21b6f49eb75
--- /dev/null
+++ b/gcc/testsuite/g++.target/riscv/rvv/base/vsrl_vv-1.C
@@ -0,0 +1,314 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+vuint8mf8_t test___riscv_vsrl(vuint8mf8_t op1,vuint8mf8_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8mf4_t test___riscv_vsrl(vuint8mf4_t op1,vuint8mf4_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8mf2_t test___riscv_vsrl(vuint8mf2_t op1,vuint8mf2_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8m1_t test___riscv_vsrl(vuint8m1_t op1,vuint8m1_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8m2_t test___riscv_vsrl(vuint8m2_t op1,vuint8m2_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8m4_t test___riscv_vsrl(vuint8m4_t op1,vuint8m4_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint8m8_t test___riscv_vsrl(vuint8m8_t op1,vuint8m8_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16mf4_t test___riscv_vsrl(vuint16mf4_t op1,vuint16mf4_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16mf2_t test___riscv_vsrl(vuint16mf2_t op1,vuint16mf2_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16m1_t test___riscv_vsrl(vuint16m1_t op1,vuint16m1_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16m2_t test___riscv_vsrl(vuint16m2_t op1,vuint16m2_t shift,size_t vl)
+{
+return __riscv_vsrl(op1,shift,vl);
+}
+
+
+vuint16m4_t test___riscv_vsrl(vuint16m4_t op1,vuint16m4_t shift,size_t vl)
+{
+

Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays

2023-01-31 Thread Jakub Jelinek via Gcc-patches
On Wed, Dec 21, 2022 at 05:25:54PM -0500, Siddhesh Poyarekar wrote:
> The tree object size pass tries to fail when it detects a flex array in
> the struct, but it ends up doing the right thing only when the flex
> array is in the outermost struct.  For nested cases (such as arrays
> nested in a union or an inner struct), it ends up taking whatever value
> the flex array is declared with, using zero for the standard flex array,
> i.e. [].
> 
> Rework subobject size computation to make it more consistent across the
> board, honoring -fstrict-flex-arrays.  With this change, any array at
> the end of the struct will end up causing __bos to use the allocated
> value of the outer object, bailing out in the maximum case when it can't
> find it.  In the minimum case, it will return the subscript value or the
> allocated value of the outer object, whichever is larger.

I think it is way too late in the GCC 13 cycle to change behavior here
except for when -fstrict-flex-arrays is used.
Plus, am not really convinced it is a good idea to change the behavior
here except for the new options, programs in the wild took 2+ years
to acommodate for what we GCC requiring and am not sure they'd be willing
to be adjusted again.

> gcc/ChangeLog:
> 
>   PR tree-optimization/107952
>   * tree-object-size.cc (size_from_objects): New function.
>   (addr_object_size): Call it.  Fully rely on
>   array_ref_flexible_size_p call to determine flex array.

Jakub



[PATCH] RISC-V: Add binop constraint tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/binop_vv_constraint-1.c: New test.

---
 .../riscv/rvv/base/binop_vv_constraint-1.c| 132 ++
 1 file changed, 132 insertions(+)
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c
new file mode 100644
index 000..3ab1ccee035
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c
@@ -0,0 +1,132 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+#include "riscv_vector.h"
+
+/*
+** f1:
+** vsetivli\tzero,4,e32,m1,tu,ma
+** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** vse32\.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f1 (void * in, void *out)
+{
+vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
+vint32m1_t v2 = __riscv_vle32_v_i32m1_tu (v, in, 4);
+vint32m1_t v3 = __riscv_vadd_vv_i32m1 (v2, v2, 4);
+vint32m1_t v4 = __riscv_vadd_vv_i32m1_tu (v3, v2, v2, 4);
+__riscv_vse32_v_i32m1 (out, v4, 4);
+}
+
+/*
+** f2:
+** vsetvli\t[a-x0-9]+,zero,e8,mf4,ta,ma
+** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsetivli\tzero,4,e32,m1,ta,ma
+** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t
+** vse32.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f2 (void * in, void *out)
+{
+vbool32_t mask = *(vbool32_t*)in;
+asm volatile ("":::"memory");
+vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
+vint32m1_t v2 = __riscv_vle32_v_i32m1_m (mask, in, 4);
+vint32m1_t v3 = __riscv_vadd_vv_i32m1 (v2, v2, 4);
+vint32m1_t v4 = __riscv_vadd_vv_i32m1_m (mask, v3, v3, 4);
+__riscv_vse32_v_i32m1 (out, v4, 4);
+}
+
+/*
+** f3:
+** vsetvli\t[a-x0-9]+,zero,e8,mf4,ta,ma
+** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsetivli\tzero,4,e32,m1,tu,mu
+** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t
+** vse32.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f3 (void * in, void *out)
+{
+vbool32_t mask = *(vbool32_t*)in;
+asm volatile ("":::"memory");
+vint32m1_t v = __riscv_vle32_v_i32m1 (in, 4);
+vint32m1_t v2 = __riscv_vle32_v_i32m1_tumu (mask, v, in, 4);
+vint32m1_t v3 = __riscv_vadd_vv_i32m1 (v2, v2, 4);
+vint32m1_t v4 = __riscv_vadd_vv_i32m1_tumu (mask, v3, v2, v2, 4);
+__riscv_vse32_v_i32m1 (out, v4, 4);
+}
+
+/*
+** f4:
+** vsetivli\tzero,4,e8,mf8,tu,ma
+** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** vse8\.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f4 (void * in, void *out)
+{
+vint8mf8_t v = __riscv_vle8_v_i8mf8 (in, 4);
+vint8mf8_t v2 = __riscv_vle8_v_i8mf8_tu (v, in, 4);
+vint8mf8_t v3 = __riscv_vadd_vv_i8mf8 (v2, v2, 4);
+vint8mf8_t v4 = __riscv_vadd_vv_i8mf8_tu (v3, v2, v2, 4);
+__riscv_vse8_v_i8mf8 (out, v4, 4);
+}
+
+/*
+** f5:
+** vsetvli\t[a-x0-9]+,zero,e8,mf8,ta,ma
+** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsetivli\tzero,4,e8,mf8,ta,ma
+** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t
+** vse8.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f5 (void * in, void *out)
+{
+vbool64_t mask = *(vbool64_t*)in;
+asm volatile ("":::"memory");
+vint8mf8_t v = __riscv_vle8_v_i8mf8 (in, 4);
+vint8mf8_t v2 = __riscv_vle8_v_i8mf8_m (mask, in, 4);
+vint8mf8_t v3 = __riscv_vadd_vv_i8mf8 (v2, v2, 4);
+vint8mf8_t v4 = __riscv_vadd_vv_i8mf8_m (mask, v3, v3, 4);
+__riscv_vse8_v_i8mf8 (out, v4, 4);
+}
+
+/*
+** f6:
+** vsetvli\t[a-x0-9]+,zero,e8,mf8,ta,ma
+** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
+** vsetivli\tzero,4,e8,mf8,tu,mu
+** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
+** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t
+** vse8.v\tv[0-9]+,0\([a-x0-9]+\)
+** ret
+*/
+void f6 (void * in, void *out)
+{
+vbool64_t mask = *(vbool64_t*)in;
+asm volatile ("":::"memory");
+vint8mf8_t v = __riscv_vle8_v_i8mf8 (in, 4);
+vint8mf8_t v2 = __riscv_vle8_v_i8mf8_tumu (mask, v, in, 4);
+vint8mf8_t v3 = __riscv_vadd_vv_i8mf8 (v2, v2, 4);
+vint8mf8_t v4 = __riscv_vadd_vv_i8mf8_tumu (mask, v3, v2, v2, 4);
+__riscv_vse8_v_i8mf8 (out, v4, 4);
+}
-- 
2.36.3



Re: [PATCH 1/2] testsuite: Run __bos tests to completion

2023-01-31 Thread Jakub Jelinek via Gcc-patches
On Wed, Dec 21, 2022 at 05:25:53PM -0500, Siddhesh Poyarekar wrote:
> gcc/testsuite/ChangeLog:
> 
>   * gcc.dg/builtin-dynamic-object-size-0.c: Move FAIL and nfail
>   into...
>   * gcc.dg/builtin-object-size-common.h: ... new file.
>   * g++.dg/ext/builtin-object-size1.C: Include
>   builtin-object-size-common.h.  Replace all abort with FAIL.
>   (main): Call DONE.
>   * g++.dg/ext/builtin-object-size2.C: Likewise.
>   * gcc.dg/builtin-object-size-1.c: Likewise.
>   * gcc.dg/builtin-object-size-12.c: Likewise.
>   * gcc.dg/builtin-object-size-13.c: Likewise.
>   * gcc.dg/builtin-object-size-15.c: Likewise.
>   * gcc.dg/builtin-object-size-2.c: Likewise.
>   * gcc.dg/builtin-object-size-3.c: Likewise.
>   * gcc.dg/builtin-object-size-4.c: Likewise.
>   * gcc.dg/builtin-object-size-6.c: Likewise.
>   * gcc.dg/builtin-object-size-7.c: Likewise.
>   * gcc.dg/builtin-object-size-8.c: Likewise.
>   * gcc.dg/pr101836.c: Likewise.
>   * gcc.dg/strict-flex-array-3.c: Likewise.
> --- a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
> +++ b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
> @@ -1,8 +1,9 @@
>  // { dg-do run }
>  // { dg-options "-O2" }
>  
> +#include "../../gcc.dg/builtin-object-size-common.h"
> +
>  typedef __SIZE_TYPE__ size_t;
> -extern "C" void abort ();
>  extern "C" void exit (int);
>  extern "C" void *malloc (size_t);
>  extern "C" void free (void *);

I'd then wonder if size_t shouldn't be typedefed and perhaps
even exit/malloc/free etc. shouldn't be prototyped in
builtin-object-size-common.h too (of course, with extern "C"
conditionalized on __cplusplus).

>if (__builtin_object_size (r + 6, 0) != res - 6)
> -abort ();
> +FAIL ();

There should be a tab, not 8 spaces.

> @@ -335,13 +336,13 @@ test2 (void)
>if (res >= 12)
>  {
>if (__builtin_object_size (r + 12, 0) != res - 12)
> -abort ();
> +FAIL ();

Ditto.
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-common.h
> @@ -0,0 +1,12 @@
> +unsigned nfails = 0;
> +
> +#define FAIL() ({ \
> +  __builtin_printf ("Failure at line: %d\n", __LINE__);  
>   \
> +  nfails++;\
> +})
> +
> +#define DONE() ({ \
> +  if (nfails > 0)  \
> +__builtin_abort ();  
>   \
> +  return 0;\
> +})

Why the statement expressions?  do { and } while (0) would work too...
> -  printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
> -   __builtin_abort (); \
> +  __builtin_printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
> +   FAIL (); \

The above has rightly indented FAIL, but the line before that uses
10 spaces rather than tab + 2 spaces.

Otherwise LGTM.

Jakub



Re: [Patch] libgomp.texi: Reverse-offload updates (was: [Patch] libgomp: Handle OpenMP's reverse offloads)

2023-01-31 Thread Jakub Jelinek via Gcc-patches
On Sat, Dec 10, 2022 at 09:18:26AM +0100, Tobias Burnus wrote:
> libgomp.texi: Reverse-offload updates
> 
> libgomp/
>   * libgomp.texi (5.0 Impl. Status): Update 'requires' and 'ancestor'.
>   (GCN): Add item about 'omp requires'.
>   (nvptx): Likewise; add item about reverse offload.
> 
> --- a/libgomp/libgomp.texi
> +++ b/libgomp/libgomp.texi
> @@ -192,8 +192,8 @@ The OpenMP 4.5 specification is fully supported.
>env variable @tab Y @tab
>  @item Nested-parallel changes to @emph{max-active-levels-var} ICV @tab Y @tab
>  @item @code{requires} directive @tab P
> -  @tab complete but no non-host devices provides @code{unified_address},
> -  @code{unified_shared_memory} or @code{reverse_offload}
> +  @tab complete but no non-host devices provides @code{unified_address} 
> or
> +  @code{unified_shared_memory}
>  @item @code{teams} construct outside an enclosing target region @tab Y @tab
>  @item Non-rectangular loop nests @tab Y @tab
>  @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
> @@ -228,7 +228,7 @@ The OpenMP 4.5 specification is fully supported.
>  @item @code{allocate} clause @tab P @tab Initial support
>  @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
>  @item @code{ancestor} modifier on @code{device} clause
> -  @tab Y @tab See comment for @code{requires}
> +  @tab Y @tab Host fallback with GCN devices
>  @item Implicit declare target directive @tab Y @tab
>  @item Discontiguous array section with @code{target update} construct
>@tab N @tab
> @@ -288,7 +288,7 @@ The OpenMP 4.5 specification is fully supported.
>@code{append_args} @tab N @tab
>  @item @code{dispatch} construct @tab N @tab
>  @item device-specific ICV settings with environment variables @tab Y @tab
> -@item @code{assume} directive @tab Y @tab
> +@item @code{assume} and @code{assumes} directives @tab Y @tab
>  @item @code{nothing} directive @tab Y @tab
>  @item @code{error} directive @tab Y @tab
>  @item @code{masked} construct @tab Y @tab
> @@ -4456,6 +4456,9 @@ The implementation remark:
>  @item I/O within OpenMP target regions and OpenACC parallel/kernels is 
> supported
>using the C library @code{printf} functions and the Fortran
>@code{print}/@code{write} statements.
> +@item OpenMP code that has a requires directive with @code{unified_address},
> +  @code{unified_shared_memory} or @code{reverse_offload} will remove
> +  any GCN device from the list of available devices (``host fallback'').
>  @end itemize
>  
>  
> @@ -4507,6 +4510,15 @@ The implementation remark:
>  @item Compilation OpenMP code that contains @code{requires reverse_offload}
>requires at least @code{-march=sm_35}, compiling for 
> @code{-march=sm_30}
>is not supported.
> +@item For code containing reverse offload (i.e. @code{target} regions with
> +  @code{device(ancestor:1)}), there is a slight performance penality
> +  for @emph{all} target regions, consisting mostly of shutdown delay
> +  Per device, reverse offload regions are processed serial such that

s/serial/serially/ ?

> +  the next reverse offload region is only executed after the previous
> +  one returns.
> +@item OpenMP code that has a requires directive with @code{unified_address}
> +  or @code{unified_shared_memory} will remove any nvptx device from the
> +  list of available devices (``host fallback'').
>  @end itemize

Otherwise LGTM

Jakub



[PATCH] RISC-V: Add vsra.vv C API tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/vsra_vv-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_m-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_m-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_m-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_mu-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_mu-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_mu-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tu-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tu-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tu-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tum-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tum-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tum-3.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tumu-1.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tumu-2.c: New test.
* gcc.target/riscv/rvv/base/vsra_vv_tumu-3.c: New test.


---
 .../gcc.target/riscv/rvv/base/vsra_vv-1.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv-2.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv-3.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_m-1.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_m-2.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_m-3.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_mu-1.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_mu-2.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_mu-3.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_tu-1.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_tu-2.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_tu-3.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_tum-1.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_tum-2.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsra_vv_tum-3.c | 160 ++
 .../riscv/rvv/base/vsra_vv_tumu-1.c   | 160 ++
 .../riscv/rvv/base/vsra_vv_tumu-2.c   | 160 ++
 .../riscv/rvv/base/vsra_vv_tumu-3.c   | 160 ++
 18 files changed, 2880 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_m-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_m-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_m-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_mu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_mu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_mu-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tu-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tum-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tum-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tum-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tumu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tumu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv_tumu-3.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-1.c
new file mode 100644
index 000..01dee8d57fd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vsra_vv-1.c
@@ -0,0 +1,160 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+vint8mf8_t test___riscv_vsra_vv_i8mf8(vint8mf8_t op1,vuint8mf8_t shift,size_t 
vl)
+{
+return __riscv_vsra_vv_i8mf8(op1,shift,vl);
+}
+
+
+vint8mf4_t test___riscv_vsra_vv_i8mf4(vint8mf4_t op1,vuint8mf4_t shift,size_t 
vl)
+{
+return __riscv_vsra_vv_i8mf4(op1,shift,vl);
+}
+
+
+vint8mf2_t test___riscv_vsra_vv_i8mf2(vint8mf2_t op1,vuint8mf2_t shift,size_t 
vl)
+{
+return __riscv_vsra_vv_i8mf2(op1,shift,vl);
+}
+
+
+vint8m1_t test___riscv_vsra_vv_i8m1(vint8m1_t op1,vuint8m1_t shift,size_t vl)
+{
+return __riscv_vsra_vv_i8m1(op1,shift,vl);
+}
+
+
+vint8m2_t test___riscv_vsra_vv_i8m2(vint8m2_t op1,vuint8m2_t shift,size_t vl)
+{
+return __riscv_vsra_vv_i8m2(op1,shift,vl);
+}
+
+
+vint8m4_t 

[PATCH] RISC-V: Add srl.vv C API tests

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/vsrl_vv-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_m-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_m-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_m-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_mu-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_mu-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_mu-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tu-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tu-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tu-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tum-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tum-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tum-3.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tumu-1.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tumu-2.c: New test.
* gcc.target/riscv/rvv/base/vsrl_vv_tumu-3.c: New test.

---
 .../gcc.target/riscv/rvv/base/vsrl_vv-1.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv-2.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv-3.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_m-1.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_m-2.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_m-3.c   | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_mu-1.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_mu-2.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_mu-3.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_tu-1.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_tu-2.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_tu-3.c  | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_tum-1.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_tum-2.c | 160 ++
 .../gcc.target/riscv/rvv/base/vsrl_vv_tum-3.c | 160 ++
 .../riscv/rvv/base/vsrl_vv_tumu-1.c   | 160 ++
 .../riscv/rvv/base/vsrl_vv_tumu-2.c   | 160 ++
 .../riscv/rvv/base/vsrl_vv_tumu-3.c   | 160 ++
 18 files changed, 2880 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_m-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_m-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_m-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_mu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_mu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_mu-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tu-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tum-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tum-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tum-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tumu-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tumu-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv_tumu-3.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-1.c
new file mode 100644
index 000..a4c556adda0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vsrl_vv-1.c
@@ -0,0 +1,160 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+vuint8mf8_t test___riscv_vsrl_vv_u8mf8(vuint8mf8_t op1,vuint8mf8_t 
shift,size_t vl)
+{
+return __riscv_vsrl_vv_u8mf8(op1,shift,vl);
+}
+
+
+vuint8mf4_t test___riscv_vsrl_vv_u8mf4(vuint8mf4_t op1,vuint8mf4_t 
shift,size_t vl)
+{
+return __riscv_vsrl_vv_u8mf4(op1,shift,vl);
+}
+
+
+vuint8mf2_t test___riscv_vsrl_vv_u8mf2(vuint8mf2_t op1,vuint8mf2_t 
shift,size_t vl)
+{
+return __riscv_vsrl_vv_u8mf2(op1,shift,vl);
+}
+
+
+vuint8m1_t test___riscv_vsrl_vv_u8m1(vuint8m1_t op1,vuint8m1_t shift,size_t vl)
+{
+return __riscv_vsrl_vv_u8m1(op1,shift,vl);
+}
+
+
+vuint8m2_t test___riscv_vsrl_vv_u8m2(vuint8m2_t op1,vuint8m2_t shift,size_t vl)
+{
+return __riscv_vsrl_vv_u8m2(op1,shift,vl);
+}
+
+
+vuint8m4_t 

Re: [Patch] OpenMP: Parse align clause in allocate directive in C/C++

2023-01-31 Thread Jakub Jelinek via Gcc-patches
On Tue, Dec 13, 2022 at 06:44:27PM +0100, Tobias Burnus wrote:
> OpenMP: Parse align clause in allocate directive in C/C++
> 
> gcc/c/ChangeLog:
> 
>   * c-parser.cc (c_parser_omp_allocate): Parse align
>   clause and check for restrictions.
> 
> gcc/cp/ChangeLog:
> 
>   * parser.cc (cp_parser_omp_allocate): Parse align
>   clause.
> 
> gcc/testsuite/ChangeLog:
> 
>   * c-c++-common/gomp/allocate-5.c: Extend for align clause.
> 
>  gcc/c/c-parser.cc| 88 
> 
>  gcc/cp/parser.cc | 58 +-
>  gcc/testsuite/c-c++-common/gomp/allocate-5.c | 36 
>  3 files changed, 144 insertions(+), 38 deletions(-)
> 
> diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
> index 1bbb39f9b08..62c302748dd 100644
> --- a/gcc/c/c-parser.cc
> +++ b/gcc/c/c-parser.cc
> @@ -18819,32 +18819,71 @@ c_parser_oacc_wait (location_t loc, c_parser 
> *parser, char *p_name)
>return stmt;
>  }
>  
> -/* OpenMP 5.0:
> -   # pragma omp allocate (list)  [allocator(allocator)]  */
> +/* OpenMP 5.x:
> +   # pragma omp allocate (list)  clauses
> +
> +   OpenMP 5.0 clause:
> +   allocator (omp_allocator_handle_t expression)
> +
> +   OpenMP 5.1 additional clause:
> +   align (int expression)] */

integer-expression or constant-expression or just expression.
Also, 2 spaces before */ rather than just one.

> +  else if (p[2] == 'i')
> + {
> +   alignment = c_fully_fold (expr.value, false, NULL);
> +   if (TREE_CODE (alignment) != INTEGER_CST
> +   || !INTEGRAL_TYPE_P (TREE_TYPE (alignment))
> +   || tree_int_cst_sgn (alignment) != 1
> +   || !integer_pow2p (alignment))

Note, the reason why we diagnose this in c-parser.cc and for C++
in semantics.cc rather than in parser.cc are templates, it would be
wasteful to handle it in two spots (parser.cc and during instantiation).

> -  if (allocator)
> +  if (allocator || alignment)
>  for (tree c = nl; c != NULL_TREE; c = OMP_CLAUSE_CHAIN (c))
> -  OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
> +  {
> + OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
> + OMP_CLAUSE_ALLOCATE_ALIGN (c) = alignment;
> +  }

So, if you want for now until we actually support the directive
properly diagnose it here in the parser (otherwise there is nothing
to stick it on for later), then it would need either what semantics.cc
currently uses:
  if (!type_dependent_expression_p (align)
  && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
{
  error_at (OMP_CLAUSE_LOCATION (c),
"% clause % modifier "
"argument needs to be positive constant "
"power of two integer expression");
  remove = true;
}
  else
{
  align = mark_rvalue_use (align);
  if (!processing_template_decl)
{
  align = maybe_constant_value (align);
  if (TREE_CODE (align) != INTEGER_CST
  || !tree_fits_uhwi_p (align)
  || !integer_pow2p (align))
{
  error_at (OMP_CLAUSE_LOCATION (c),
"% clause % modifier "
"argument needs to be positive constant "
"power of two integer expression");
  remove = true;
}
}
}
with adjusted diagnostics, or perhaps instead of the
!processing_template_decl guarding do
fold_non_dependent_expr (align, !tf_none)
instead of maybe_constant_value and just for
processing_template_decl && TREE_CODE (align) != INTEGER_CST
do nothing instead of the other tests and diagnostics.
With the !processing_template_decl guarding it wouldn't diagnose
ever non-power of two or non-constant operand in templates,
with fold_non_dependent_expr etc. it would as long as they are
not dependent.

Otherwise LGTM, with or without the above changes.

Jakub



[PATCH] RISC-V: Add integer binary vv C/C++ API support

2023-01-31 Thread juzhe . zhong
From: Ju-Zhe Zhong 

---
 gcc/config/riscv/constraints.md   |  10 +
 gcc/config/riscv/iterators.md |  14 +-
 gcc/config/riscv/predicates.md|  15 ++
 .../riscv/riscv-vector-builtins-bases.cc  |  48 +
 .../riscv/riscv-vector-builtins-bases.h   |  17 ++
 .../riscv/riscv-vector-builtins-functions.def |  18 ++
 .../riscv/riscv-vector-builtins-shapes.cc |  25 +++
 .../riscv/riscv-vector-builtins-shapes.h  |   1 +
 gcc/config/riscv/riscv-vector-builtins.cc |  38 
 gcc/config/riscv/riscv-vector-builtins.h  |   1 +
 gcc/config/riscv/riscv.cc |  10 +
 gcc/config/riscv/vector-iterators.md  | 183 ++
 gcc/config/riscv/vector.md|  49 -
 13 files changed, 421 insertions(+), 8 deletions(-)

diff --git a/gcc/config/riscv/constraints.md b/gcc/config/riscv/constraints.md
index 7061201ba37..3637380ee47 100644
--- a/gcc/config/riscv/constraints.md
+++ b/gcc/config/riscv/constraints.md
@@ -140,6 +140,16 @@
   (and (match_code "const_vector")
(match_test "riscv_vector::const_vec_all_same_in_range_p (op, -16, 
15)")))
 
+(define_constraint "vj"
+  "A vector negated 5-bit signed immediate."
+  (and (match_code "const_vector")
+   (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -15, 
16)")))
+
+(define_constraint "vk"
+  "A vector 5-bit unsigned immediate."
+  (and (match_code "const_vector")
+   (match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 31)")))
+
 (define_constraint "Wc0"
   "@internal
  A constraint that matches a vector of immediate all zeros."
diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md
index 0e8dbcc9e7e..9561403419b 100644
--- a/gcc/config/riscv/iterators.md
+++ b/gcc/config/riscv/iterators.md
@@ -196,7 +196,12 @@
 (xor "xor")
 (and "and")
 (plus "add")
-(minus "sub")])
+(minus "sub")
+(smin "smin")
+(smax "smax")
+(umin "umin")
+(umax "umax")
+(mult "mul")])
 
 ;;  code attributes
 (define_code_attr or_optab [(ior "ior")
@@ -214,7 +219,12 @@
(xor "xor")
(and "and")
(plus "add")
-   (minus "sub")])
+   (minus "sub")
+   (smin "min")
+   (smax "max")
+   (umin "minu")
+   (umax "maxu")
+   (mult "mul")])
 
 ; atomics code attribute
 (define_code_attr atomic_optab
diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md
index f9013bbf8bb..57f7ddfbd7d 100644
--- a/gcc/config/riscv/predicates.md
+++ b/gcc/config/riscv/predicates.md
@@ -286,6 +286,21 @@
(match_test "GET_CODE (op) == UNSPEC
 && (XINT (op, 1) == UNSPEC_VUNDEF)"
 
+(define_predicate "vector_arith_operand"
+  (ior (match_operand 0 "register_operand")
+   (and (match_code "const_vector")
+(match_test "riscv_vector::const_vec_all_same_in_range_p (op, -16, 
15)"
+
+(define_predicate "vector_neg_arith_operand"
+  (ior (match_operand 0 "register_operand")
+   (and (match_code "const_vector")
+(match_test "riscv_vector::const_vec_all_same_in_range_p (op, -15, 
16)"
+
+(define_predicate "vector_shift_operand"
+  (ior (match_operand 0 "register_operand")
+   (and (match_code "const_vector")
+(match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 
31)"
+
 (define_special_predicate "pmode_reg_or_0_operand"
   (ior (match_operand 0 "const_0_operand")
(match_operand 0 "pmode_register_operand")))
diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc 
b/gcc/config/riscv/riscv-vector-builtins-bases.cc
index 129e89f443e..f4256fedc5b 100644
--- a/gcc/config/riscv/riscv-vector-builtins-bases.cc
+++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc
@@ -154,6 +154,19 @@ public:
   }
 };
 
+/* Implements
+ * 
vadd/vsub/vrsub/vand/vor/vxor/vsll/vsra/vsrl/vmin/vmax/vminu/vmaxu/vdiv/vrem/vdivu/vremu/vsadd/vsaddu/vssub/vssubu.
+ */
+template
+class binop : public function_base
+{
+public:
+  rtx expand (function_expander ) const override
+  {
+return e.use_exact_insn (code_for_pred (CODE, e.vector_mode ()));
+  }
+};
+
 static CONSTEXPR const vsetvl vsetvl_obj;
 static CONSTEXPR const vsetvl vsetvlmax_obj;
 static CONSTEXPR const loadstore vle_obj;
@@ -178,6 +191,24 @@ static CONSTEXPR const loadstore 
vsoxei8_obj;
 static CONSTEXPR const loadstore vsoxei16_obj;
 static CONSTEXPR const loadstore vsoxei32_obj;
 static CONSTEXPR const loadstore vsoxei64_obj;
+static CONSTEXPR const binop vadd_obj;
+static CONSTEXPR const binop vsub_obj;
+static CONSTEXPR const binop vrsub_obj;

Re: [Patch] Fortran: Extend align-clause checks of OpenMP's allocate clause

2023-01-31 Thread Jakub Jelinek via Gcc-patches
On Tue, Dec 13, 2022 at 05:38:22PM +0100, Tobias Burnus wrote:
> I missed that 'align' needs to be a power of 2 - contrary to 'aligned',
> which does not have this restriction for some odd reason.

Yeah, odd.  The C and C++ FEs indeed diagnose non-pow2p constants
for align (and not for aligned clause).
> 
> OK for mainline?

Yes, thanks.  Sorry for the delay.

> Fortran: Extend align-clause checks of OpenMP's allocate directive
> 
> gcc/fortran/ChangeLog:
> 
>   * openmp.cc (resolve_omp_clauses): Check also for
>   power of two.
> 
> libgomp/ChangeLog:
> 
>   * testsuite/libgomp.fortran/allocate-3.f90: Fix ALIGN
>   usage, remove unused -fdump-tree-original.
>   * testsuite/libgomp.fortran/allocate-4.f90: New.

Jakub



Re: [PATCH 3/3] arm: Fix MVE predicates synthesis [PR 108443]

2023-01-31 Thread Andre Vieira (lists) via Gcc-patches



Yeah that shouldn't be there, it's from an earlier version of the patch 
I wrote where I was experimenting changing the existing modes, I'll 
remove it from the ChangeLog.


On 31/01/2023 09:53, Kyrylo Tkachov wrote:


gcc/testsuite/ChangeLog:

      * gcc.dg/rtl/arm/mve-vxbi.c: Use new predicate modes.


... I don't see this in the patch. Is this the correct patch? Or does the 
CHangeLog need updating?


      * gcc.target/arm/mve/pr108443-run.c: New test.
      * gcc.target/arm/mve/pr108443.c: New test.


  1   2   >