[gcc r11-11419] c++/c-common: Fix convert_vector_to_array_for_subscript for qualified vector types [PR89224]

2024-05-07 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:046aeffba336295fbdaf0e1ecf64b582d08f0aa6

commit r11-11419-g046aeffba336295fbdaf0e1ecf64b582d08f0aa6
Author: Andrew Pinski 
Date:   Tue Feb 20 13:38:28 2024 -0800

c++/c-common: Fix convert_vector_to_array_for_subscript for qualified 
vector types [PR89224]

After r7-987-gf17a223de829cb, the access for the elements of a vector type 
would lose the qualifiers.
So if we had `constvector[0]`, the type of the element of the array would 
not have const on it.
This was due to a missing build_qualified_type for the inner type of the 
vector when building the array type.
We need to add back the call to build_qualified_type and now the access has 
the correct qualifiers. So the
overloads and even if it is a lvalue or rvalue is correctly done.

Note we correctly now reject the testcase gcc.dg/pr83415.c which was 
incorrectly accepted after r7-987-gf17a223de829cb.

Built and tested for aarch64-linux-gnu.

PR c++/89224

gcc/c-family/ChangeLog:

* c-common.c (convert_vector_to_array_for_subscript): Call 
build_qualified_type
for the inner type.

gcc/cp/ChangeLog:

* constexpr.c (cxx_eval_array_reference): Compare main variants
for the vector/array types instead of the types directly.

gcc/testsuite/ChangeLog:

* g++.dg/torture/vector-subaccess-1.C: New test.
* gcc.dg/pr83415.c: Change warning to error.

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

Diff:
---
 gcc/c-family/c-common.c   |  7 ++-
 gcc/cp/constexpr.c|  3 ++-
 gcc/testsuite/g++.dg/torture/vector-subaccess-1.C | 23 +++
 gcc/testsuite/gcc.dg/pr83415.c|  2 +-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 9417b7fb4d1f..ae3ef89b05cb 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -8274,6 +8274,7 @@ convert_vector_to_array_for_subscript (location_t loc,
   if (gnu_vector_type_p (TREE_TYPE (*vecp)))
 {
   tree type = TREE_TYPE (*vecp);
+  tree newitype;
 
   ret = !lvalue_p (*vecp);
 
@@ -8288,8 +8289,12 @@ convert_vector_to_array_for_subscript (location_t loc,
 for function parameters.  */
   c_common_mark_addressable_vec (*vecp);
 
+  /* Make sure qualifiers are copied from the vector type to the new 
element
+of the array type.  */
+  newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
+
   *vecp = build1 (VIEW_CONVERT_EXPR,
- build_array_type_nelts (TREE_TYPE (type),
+ build_array_type_nelts (newitype,
  TYPE_VECTOR_SUBPARTS (type)),
  *vecp);
 }
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 38f684144f0c..eb18b5b35378 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3767,7 +3767,8 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree 
t,
   if (!lval
   && TREE_CODE (ary) == VIEW_CONVERT_EXPR
   && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (ary, 0)))
-  && TREE_TYPE (t) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0
+  && (TYPE_MAIN_VARIANT (TREE_TYPE (t))
+ == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0))
 ary = TREE_OPERAND (ary, 0);
 
   tree oldidx = TREE_OPERAND (t, 1);
diff --git a/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C 
b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
new file mode 100644
index ..0c8958a4e034
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
@@ -0,0 +1,23 @@
+/* PR c++/89224 */
+
+/* The access of `vector[i]` has the same qualifiers as the original
+   vector which was missing. */
+
+typedef __attribute__((vector_size(16))) unsigned char  Int8x8_t;
+
+template 
+void g(T ) {
+__builtin_abort();
+}
+template 
+void g(const T ) {
+  __builtin_exit(0);
+}
+void f(const Int8x8_t x) {
+  g(x[0]);
+}
+int main(void)
+{
+Int8x8_t x ={};
+f(x);
+}
diff --git a/gcc/testsuite/gcc.dg/pr83415.c b/gcc/testsuite/gcc.dg/pr83415.c
index 5934c16d97cb..2fc85031505d 100644
--- a/gcc/testsuite/gcc.dg/pr83415.c
+++ b/gcc/testsuite/gcc.dg/pr83415.c
@@ -7,6 +7,6 @@ int
 main (int argc, short *argv[])
 {
   int i = argc;
-  y[i] = 7 - i; /* { dg-warning "read-only" } */
+  y[i] = 7 - i; /* { dg-error "read-only" } */
   return 0;
 }


[gcc r12-10420] c++/c-common: Fix convert_vector_to_array_for_subscript for qualified vector types [PR89224]

2024-05-07 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:315f8a474eb1a9b2d213aa650bdb132c78546264

commit r12-10420-g315f8a474eb1a9b2d213aa650bdb132c78546264
Author: Andrew Pinski 
Date:   Tue Feb 20 13:38:28 2024 -0800

c++/c-common: Fix convert_vector_to_array_for_subscript for qualified 
vector types [PR89224]

After r7-987-gf17a223de829cb, the access for the elements of a vector type 
would lose the qualifiers.
So if we had `constvector[0]`, the type of the element of the array would 
not have const on it.
This was due to a missing build_qualified_type for the inner type of the 
vector when building the array type.
We need to add back the call to build_qualified_type and now the access has 
the correct qualifiers. So the
overloads and even if it is a lvalue or rvalue is correctly done.

Note we correctly now reject the testcase gcc.dg/pr83415.c which was 
incorrectly accepted after r7-987-gf17a223de829cb.

Built and tested for aarch64-linux-gnu.

PR c++/89224

gcc/c-family/ChangeLog:

* c-common.cc (convert_vector_to_array_for_subscript): Call 
build_qualified_type
for the inner type.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_array_reference): Compare main variants
for the vector/array types instead of the types directly.

gcc/testsuite/ChangeLog:

* g++.dg/torture/vector-subaccess-1.C: New test.
* gcc.dg/pr83415.c: Change warning to error.

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

Diff:
---
 gcc/c-family/c-common.cc  |  7 ++-
 gcc/cp/constexpr.cc   |  3 ++-
 gcc/testsuite/g++.dg/torture/vector-subaccess-1.C | 23 +++
 gcc/testsuite/gcc.dg/pr83415.c|  2 +-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 9d1faf8ae167..94bef24220b4 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -8511,6 +8511,7 @@ convert_vector_to_array_for_subscript (location_t loc,
   if (gnu_vector_type_p (TREE_TYPE (*vecp)))
 {
   tree type = TREE_TYPE (*vecp);
+  tree newitype;
 
   ret = !lvalue_p (*vecp);
 
@@ -8525,8 +8526,12 @@ convert_vector_to_array_for_subscript (location_t loc,
 for function parameters.  */
   c_common_mark_addressable_vec (*vecp);
 
+  /* Make sure qualifiers are copied from the vector type to the new 
element
+of the array type.  */
+  newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
+
   *vecp = build1 (VIEW_CONVERT_EXPR,
- build_array_type_nelts (TREE_TYPE (type),
+ build_array_type_nelts (newitype,
  TYPE_VECTOR_SUBPARTS (type)),
  *vecp);
 }
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index d2d02c282cd3..41f862e7056e 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -3932,7 +3932,8 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree 
t,
   if (!lval
   && TREE_CODE (ary) == VIEW_CONVERT_EXPR
   && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (ary, 0)))
-  && TREE_TYPE (t) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0
+  && (TYPE_MAIN_VARIANT (TREE_TYPE (t))
+ == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0))
 ary = TREE_OPERAND (ary, 0);
 
   tree oldidx = TREE_OPERAND (t, 1);
diff --git a/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C 
b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
new file mode 100644
index ..0c8958a4e034
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
@@ -0,0 +1,23 @@
+/* PR c++/89224 */
+
+/* The access of `vector[i]` has the same qualifiers as the original
+   vector which was missing. */
+
+typedef __attribute__((vector_size(16))) unsigned char  Int8x8_t;
+
+template 
+void g(T ) {
+__builtin_abort();
+}
+template 
+void g(const T ) {
+  __builtin_exit(0);
+}
+void f(const Int8x8_t x) {
+  g(x[0]);
+}
+int main(void)
+{
+Int8x8_t x ={};
+f(x);
+}
diff --git a/gcc/testsuite/gcc.dg/pr83415.c b/gcc/testsuite/gcc.dg/pr83415.c
index 5934c16d97cb..2fc85031505d 100644
--- a/gcc/testsuite/gcc.dg/pr83415.c
+++ b/gcc/testsuite/gcc.dg/pr83415.c
@@ -7,6 +7,6 @@ int
 main (int argc, short *argv[])
 {
   int i = argc;
-  y[i] = 7 - i; /* { dg-warning "read-only" } */
+  y[i] = 7 - i; /* { dg-error "read-only" } */
   return 0;
 }


[gcc r15-311] Revert "Revert "testsuite/gcc.target/cris/pr93372-2.c: Handle xpass from combine improvement""

2024-05-07 Thread Hans-Peter Nilsson via Gcc-cvs
https://gcc.gnu.org/g:f6ce85502eb2e4e7bbd9b3c6c1c065a004f8f531

commit r15-311-gf6ce85502eb2e4e7bbd9b3c6c1c065a004f8f531
Author: Hans-Peter Nilsson 
Date:   Wed May 8 04:11:20 2024 +0200

Revert "Revert "testsuite/gcc.target/cris/pr93372-2.c: Handle xpass from 
combine improvement""

This reverts commit 39f81924d88e3cc197fc3df74204c9b5e01e12f7.

Diff:
---
 gcc/testsuite/gcc.target/cris/pr93372-2.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.target/cris/pr93372-2.c 
b/gcc/testsuite/gcc.target/cris/pr93372-2.c
index 912069c018d5..2ef6471a990b 100644
--- a/gcc/testsuite/gcc.target/cris/pr93372-2.c
+++ b/gcc/testsuite/gcc.target/cris/pr93372-2.c
@@ -1,19 +1,20 @@
 /* Check that eliminable compare-instructions are eliminated. */
 /* { dg-do compile } */
 /* { dg-options "-O2" } */
-/* { dg-final { scan-assembler-not "\tcmp|\ttest" { xfail *-*-* } } } */
-/* { dg-final { scan-assembler-not "\tnot" { xfail cc0 } } } */
-/* { dg-final { scan-assembler-not "\tlsr" { xfail cc0 } } } */
+/* { dg-final { scan-assembler-not "\tcmp|\ttest" } } */
+/* { dg-final { scan-assembler-not "\tnot" } } */
+/* { dg-final { scan-assembler-not "\tlsr" } } */
+/* We should get just one move, storing the result into *d.  */
+/* { dg-final { scan-assembler-times "\tmove" 1 } } */
 
 int f(int a, int b, int *d)
 {
   int c = a - b;
 
-  /* Whoops!  We get a cmp.d with the original operands here. */
+  /* We used to get a cmp.d with the original operands here. */
   *d = (c == 0);
 
-  /* Whoops!  While we don't get a test.d for the result here for cc0,
- we get a sequence of insns: a move, a "not" and a shift of the
- subtraction-result, where a simple "spl" would have done. */
+  /* We used to get a suboptimal sequence, but now we get the optimal "sge"
+ (a.k.a "spl") re-using flags from the subtraction. */
   return c >= 0;
 }


[gcc r13-8713] c++/c-common: Fix convert_vector_to_array_for_subscript for qualified vector types [PR89224]

2024-05-07 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:f5d9eef6507f36692066c0934d9f8c9d462e698f

commit r13-8713-gf5d9eef6507f36692066c0934d9f8c9d462e698f
Author: Andrew Pinski 
Date:   Tue Feb 20 13:38:28 2024 -0800

c++/c-common: Fix convert_vector_to_array_for_subscript for qualified 
vector types [PR89224]

After r7-987-gf17a223de829cb, the access for the elements of a vector type 
would lose the qualifiers.
So if we had `constvector[0]`, the type of the element of the array would 
not have const on it.
This was due to a missing build_qualified_type for the inner type of the 
vector when building the array type.
We need to add back the call to build_qualified_type and now the access has 
the correct qualifiers. So the
overloads and even if it is a lvalue or rvalue is correctly done.

Note we correctly now reject the testcase gcc.dg/pr83415.c which was 
incorrectly accepted after r7-987-gf17a223de829cb.

Built and tested for aarch64-linux-gnu.

PR c++/89224

gcc/c-family/ChangeLog:

* c-common.cc (convert_vector_to_array_for_subscript): Call 
build_qualified_type
for the inner type.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_array_reference): Compare main variants
for the vector/array types instead of the types directly.

gcc/testsuite/ChangeLog:

* g++.dg/torture/vector-subaccess-1.C: New test.
* gcc.dg/pr83415.c: Change warning to error.

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

Diff:
---
 gcc/c-family/c-common.cc  |  7 ++-
 gcc/cp/constexpr.cc   |  3 ++-
 gcc/testsuite/g++.dg/torture/vector-subaccess-1.C | 23 +++
 gcc/testsuite/gcc.dg/pr83415.c|  2 +-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index d423cbbacaee..303d7f1ef5de 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -8545,6 +8545,7 @@ convert_vector_to_array_for_subscript (location_t loc,
   if (gnu_vector_type_p (TREE_TYPE (*vecp)))
 {
   tree type = TREE_TYPE (*vecp);
+  tree newitype;
 
   ret = !lvalue_p (*vecp);
 
@@ -8559,8 +8560,12 @@ convert_vector_to_array_for_subscript (location_t loc,
 for function parameters.  */
   c_common_mark_addressable_vec (*vecp);
 
+  /* Make sure qualifiers are copied from the vector type to the new 
element
+of the array type.  */
+  newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
+
   *vecp = build1 (VIEW_CONVERT_EXPR,
- build_array_type_nelts (TREE_TYPE (type),
+ build_array_type_nelts (newitype,
  TYPE_VECTOR_SUBPARTS (type)),
  *vecp);
 }
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index a3c21e88e7ba..216b98122007 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -4187,7 +4187,8 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree 
t,
   if (!lval
   && TREE_CODE (ary) == VIEW_CONVERT_EXPR
   && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (ary, 0)))
-  && TREE_TYPE (t) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0
+  && (TYPE_MAIN_VARIANT (TREE_TYPE (t))
+ == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0))
 ary = TREE_OPERAND (ary, 0);
 
   tree oldidx = TREE_OPERAND (t, 1);
diff --git a/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C 
b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
new file mode 100644
index ..0c8958a4e034
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
@@ -0,0 +1,23 @@
+/* PR c++/89224 */
+
+/* The access of `vector[i]` has the same qualifiers as the original
+   vector which was missing. */
+
+typedef __attribute__((vector_size(16))) unsigned char  Int8x8_t;
+
+template 
+void g(T ) {
+__builtin_abort();
+}
+template 
+void g(const T ) {
+  __builtin_exit(0);
+}
+void f(const Int8x8_t x) {
+  g(x[0]);
+}
+int main(void)
+{
+Int8x8_t x ={};
+f(x);
+}
diff --git a/gcc/testsuite/gcc.dg/pr83415.c b/gcc/testsuite/gcc.dg/pr83415.c
index 5934c16d97cb..2fc85031505d 100644
--- a/gcc/testsuite/gcc.dg/pr83415.c
+++ b/gcc/testsuite/gcc.dg/pr83415.c
@@ -7,6 +7,6 @@ int
 main (int argc, short *argv[])
 {
   int i = argc;
-  y[i] = 7 - i; /* { dg-warning "read-only" } */
+  y[i] = 7 - i; /* { dg-error "read-only" } */
   return 0;
 }


[gcc r14-10183] c++/c-common: Fix convert_vector_to_array_for_subscript for qualified vector types [PR89224]

2024-05-07 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:cacc48014c7fdb888b4449830b567e5375dfb4e3

commit r14-10183-gcacc48014c7fdb888b4449830b567e5375dfb4e3
Author: Andrew Pinski 
Date:   Tue Feb 20 13:38:28 2024 -0800

c++/c-common: Fix convert_vector_to_array_for_subscript for qualified 
vector types [PR89224]

After r7-987-gf17a223de829cb, the access for the elements of a vector type 
would lose the qualifiers.
So if we had `constvector[0]`, the type of the element of the array would 
not have const on it.
This was due to a missing build_qualified_type for the inner type of the 
vector when building the array type.
We need to add back the call to build_qualified_type and now the access has 
the correct qualifiers. So the
overloads and even if it is a lvalue or rvalue is correctly done.

Note we correctly now reject the testcase gcc.dg/pr83415.c which was 
incorrectly accepted after r7-987-gf17a223de829cb.

Built and tested for aarch64-linux-gnu.

PR c++/89224

gcc/c-family/ChangeLog:

* c-common.cc (convert_vector_to_array_for_subscript): Call 
build_qualified_type
for the inner type.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_array_reference): Compare main variants
for the vector/array types instead of the types directly.

gcc/testsuite/ChangeLog:

* g++.dg/torture/vector-subaccess-1.C: New test.
* gcc.dg/pr83415.c: Change warning to error.

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

Diff:
---
 gcc/c-family/c-common.cc  |  7 ++-
 gcc/cp/constexpr.cc   |  3 ++-
 gcc/testsuite/g++.dg/torture/vector-subaccess-1.C | 23 +++
 gcc/testsuite/gcc.dg/pr83415.c|  2 +-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 01e3d247fc28..d14591c7bd3b 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -8959,6 +8959,7 @@ convert_vector_to_array_for_subscript (location_t loc,
   if (gnu_vector_type_p (TREE_TYPE (*vecp)))
 {
   tree type = TREE_TYPE (*vecp);
+  tree newitype;
 
   ret = !lvalue_p (*vecp);
 
@@ -8973,8 +8974,12 @@ convert_vector_to_array_for_subscript (location_t loc,
 for function parameters.  */
   c_common_mark_addressable_vec (*vecp);
 
+  /* Make sure qualifiers are copied from the vector type to the new 
element
+of the array type.  */
+  newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
+
   *vecp = build1 (VIEW_CONVERT_EXPR,
- build_array_type_nelts (TREE_TYPE (type),
+ build_array_type_nelts (newitype,
  TYPE_VECTOR_SUBPARTS (type)),
  *vecp);
 }
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 8078b31544d1..4a5444e0258a 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -4430,7 +4430,8 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree 
t,
   if (!lval
   && TREE_CODE (ary) == VIEW_CONVERT_EXPR
   && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (ary, 0)))
-  && TREE_TYPE (t) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0
+  && (TYPE_MAIN_VARIANT (TREE_TYPE (t))
+ == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0))
 ary = TREE_OPERAND (ary, 0);
 
   tree oldidx = TREE_OPERAND (t, 1);
diff --git a/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C 
b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
new file mode 100644
index ..0c8958a4e034
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
@@ -0,0 +1,23 @@
+/* PR c++/89224 */
+
+/* The access of `vector[i]` has the same qualifiers as the original
+   vector which was missing. */
+
+typedef __attribute__((vector_size(16))) unsigned char  Int8x8_t;
+
+template 
+void g(T ) {
+__builtin_abort();
+}
+template 
+void g(const T ) {
+  __builtin_exit(0);
+}
+void f(const Int8x8_t x) {
+  g(x[0]);
+}
+int main(void)
+{
+Int8x8_t x ={};
+f(x);
+}
diff --git a/gcc/testsuite/gcc.dg/pr83415.c b/gcc/testsuite/gcc.dg/pr83415.c
index 5934c16d97cb..2fc85031505d 100644
--- a/gcc/testsuite/gcc.dg/pr83415.c
+++ b/gcc/testsuite/gcc.dg/pr83415.c
@@ -7,6 +7,6 @@ int
 main (int argc, short *argv[])
 {
   int i = argc;
-  y[i] = 7 - i; /* { dg-warning "read-only" } */
+  y[i] = 7 - i; /* { dg-error "read-only" } */
   return 0;
 }


[gcc r14-10182] c++/modules: Stream unmergeable temporaries by value again [PR114856]

2024-05-07 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:61a095b05c244a6e0b1aec36ee1607def00654ab

commit r14-10182-g61a095b05c244a6e0b1aec36ee1607def00654ab
Author: Nathaniel Shead 
Date:   Tue Apr 30 22:29:57 2024 +1000

c++/modules: Stream unmergeable temporaries by value again [PR114856]

In r14-9266-g2823b4d96d9ec4 I gave all temporary vars a DECL_CONTEXT,
including those at namespace or global scope, so that they could be
properly merged across importers.  However, not all of these temporary
vars are actually supposed to be mergeable.

For instance, in the attached testcase we have an unnamed temporary var
used in the NSDMI of a class member, which cannot properly merged -- but
it also doesn't need to be, as it'll be thrown away when the class type
itself is merged anyway.

This patch reverts the change made above and instead makes a weaker
adjustment that only causes temporary vars with linkage have a
DECL_CONTEXT to merge from.  This way these unnamed, "unmergeable"
temporaries are properly streamed by value again.

PR c++/114856

gcc/cp/ChangeLog:

* call.cc (make_temporary_var_for_ref_to_temp): Set context for
temporaries with linkage.
* init.cc (create_temporary_var): Revert to only set context
when in a function decl.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr114856.h: New test.
* g++.dg/modules/pr114856_a.H: New test.
* g++.dg/modules/pr114856_b.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 
Reviewed-by: Patrick Palka 
(cherry picked from commit e60032b382364897a58e67994baac896bcd03327)

Diff:
---
 gcc/cp/call.cc|  3 +++
 gcc/cp/init.cc|  2 +-
 gcc/testsuite/g++.dg/modules/pr114856.h   | 12 
 gcc/testsuite/g++.dg/modules/pr114856_a.H |  5 +
 gcc/testsuite/g++.dg/modules/pr114856_b.C |  5 +
 5 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index dbdd7c29fe88..38b9c4f08601 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -13800,6 +13800,9 @@ make_temporary_var_for_ref_to_temp (tree decl, tree 
type)
   tree name = mangle_ref_init_variable (decl);
   DECL_NAME (var) = name;
   SET_DECL_ASSEMBLER_NAME (var, name);
+
+  /* Set the context to make the variable mergeable in modules.  */
+  DECL_CONTEXT (var) = current_scope ();
 }
   else
 /* Create a new cleanup level if necessary.  */
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index a93ce00800c4..e758a8c8568b 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -4287,7 +4287,7 @@ create_temporary_var (tree type)
   TREE_USED (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
-  DECL_CONTEXT (decl) = current_scope ();
+  DECL_CONTEXT (decl) = current_function_decl;
 
   return decl;
 }
diff --git a/gcc/testsuite/g++.dg/modules/pr114856.h 
b/gcc/testsuite/g++.dg/modules/pr114856.h
new file mode 100644
index ..b1a3c2cd8341
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114856.h
@@ -0,0 +1,12 @@
+// PR c++/114856
+
+#include 
+struct A {
+  ~A();
+};
+struct V {
+  V(std::initializer_list);
+};
+struct data {
+  V v{{}};
+};
diff --git a/gcc/testsuite/g++.dg/modules/pr114856_a.H 
b/gcc/testsuite/g++.dg/modules/pr114856_a.H
new file mode 100644
index ..6195277dbde1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114856_a.H
@@ -0,0 +1,5 @@
+// PR c++/114856
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+#include "pr114856.h"
diff --git a/gcc/testsuite/g++.dg/modules/pr114856_b.C 
b/gcc/testsuite/g++.dg/modules/pr114856_b.C
new file mode 100644
index ..f81dc8b81d5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114856_b.C
@@ -0,0 +1,5 @@
+// PR c++/114856
+// { dg-additional-options "-fmodules-ts" }
+
+#include "pr114856.h"
+import "pr114856_a.H";


[gcc r15-310] c++/modules: Stream unmergeable temporaries by value again [PR114856]

2024-05-07 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:e60032b382364897a58e67994baac896bcd03327

commit r15-310-ge60032b382364897a58e67994baac896bcd03327
Author: Nathaniel Shead 
Date:   Tue Apr 30 22:29:57 2024 +1000

c++/modules: Stream unmergeable temporaries by value again [PR114856]

In r14-9266-g2823b4d96d9ec4 I gave all temporary vars a DECL_CONTEXT,
including those at namespace or global scope, so that they could be
properly merged across importers.  However, not all of these temporary
vars are actually supposed to be mergeable.

For instance, in the attached testcase we have an unnamed temporary var
used in the NSDMI of a class member, which cannot properly merged -- but
it also doesn't need to be, as it'll be thrown away when the class type
itself is merged anyway.

This patch reverts the change made above and instead makes a weaker
adjustment that only causes temporary vars with linkage have a
DECL_CONTEXT to merge from.  This way these unnamed, "unmergeable"
temporaries are properly streamed by value again.

PR c++/114856

gcc/cp/ChangeLog:

* call.cc (make_temporary_var_for_ref_to_temp): Set context for
temporaries with linkage.
* init.cc (create_temporary_var): Revert to only set context
when in a function decl.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr114856.h: New test.
* g++.dg/modules/pr114856_a.H: New test.
* g++.dg/modules/pr114856_b.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 
Reviewed-by: Patrick Palka 

Diff:
---
 gcc/cp/call.cc|  3 +++
 gcc/cp/init.cc|  2 +-
 gcc/testsuite/g++.dg/modules/pr114856.h   | 12 
 gcc/testsuite/g++.dg/modules/pr114856_a.H |  5 +
 gcc/testsuite/g++.dg/modules/pr114856_b.C |  5 +
 5 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 7c4ecf08c4bd..e058da7735fa 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -13802,6 +13802,9 @@ make_temporary_var_for_ref_to_temp (tree decl, tree 
type)
   tree name = mangle_ref_init_variable (decl);
   DECL_NAME (var) = name;
   SET_DECL_ASSEMBLER_NAME (var, name);
+
+  /* Set the context to make the variable mergeable in modules.  */
+  DECL_CONTEXT (var) = current_scope ();
 }
   else
 /* Create a new cleanup level if necessary.  */
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index c1b5b7425c9b..7bb98f445c37 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -4287,7 +4287,7 @@ create_temporary_var (tree type)
   TREE_USED (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
-  DECL_CONTEXT (decl) = current_scope ();
+  DECL_CONTEXT (decl) = current_function_decl;
 
   return decl;
 }
diff --git a/gcc/testsuite/g++.dg/modules/pr114856.h 
b/gcc/testsuite/g++.dg/modules/pr114856.h
new file mode 100644
index ..b1a3c2cd8341
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114856.h
@@ -0,0 +1,12 @@
+// PR c++/114856
+
+#include 
+struct A {
+  ~A();
+};
+struct V {
+  V(std::initializer_list);
+};
+struct data {
+  V v{{}};
+};
diff --git a/gcc/testsuite/g++.dg/modules/pr114856_a.H 
b/gcc/testsuite/g++.dg/modules/pr114856_a.H
new file mode 100644
index ..6195277dbde1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114856_a.H
@@ -0,0 +1,5 @@
+// PR c++/114856
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+#include "pr114856.h"
diff --git a/gcc/testsuite/g++.dg/modules/pr114856_b.C 
b/gcc/testsuite/g++.dg/modules/pr114856_b.C
new file mode 100644
index ..f81dc8b81d5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114856_b.C
@@ -0,0 +1,5 @@
+// PR c++/114856
+// { dg-additional-options "-fmodules-ts" }
+
+#include "pr114856.h"
+import "pr114856_a.H";


[gcc r15-309] c++/c-common: Fix convert_vector_to_array_for_subscript for qualified vector types [PR89224]

2024-05-07 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:4421d35167b3083e0f2e4c84c91fded09a30cf22

commit r15-309-g4421d35167b3083e0f2e4c84c91fded09a30cf22
Author: Andrew Pinski 
Date:   Tue Feb 20 13:38:28 2024 -0800

c++/c-common: Fix convert_vector_to_array_for_subscript for qualified 
vector types [PR89224]

After r7-987-gf17a223de829cb, the access for the elements of a vector type 
would lose the qualifiers.
So if we had `constvector[0]`, the type of the element of the array would 
not have const on it.
This was due to a missing build_qualified_type for the inner type of the 
vector when building the array type.
We need to add back the call to build_qualified_type and now the access has 
the correct qualifiers. So the
overloads and even if it is a lvalue or rvalue is correctly done.

Note we correctly now reject the testcase gcc.dg/pr83415.c which was 
incorrectly accepted after r7-987-gf17a223de829cb.

Built and tested for aarch64-linux-gnu.

PR c++/89224

gcc/c-family/ChangeLog:

* c-common.cc (convert_vector_to_array_for_subscript): Call 
build_qualified_type
for the inner type.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_array_reference): Compare main variants
for the vector/array types instead of the types directly.

gcc/testsuite/ChangeLog:

* g++.dg/torture/vector-subaccess-1.C: New test.
* gcc.dg/pr83415.c: Change warning to error.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/c-family/c-common.cc  |  7 ++-
 gcc/cp/constexpr.cc   |  3 ++-
 gcc/testsuite/g++.dg/torture/vector-subaccess-1.C | 23 +++
 gcc/testsuite/gcc.dg/pr83415.c|  2 +-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 032dcb4b41d5..aae998d0f738 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -8964,6 +8964,7 @@ convert_vector_to_array_for_subscript (location_t loc,
   if (gnu_vector_type_p (TREE_TYPE (*vecp)))
 {
   tree type = TREE_TYPE (*vecp);
+  tree newitype;
 
   ret = !lvalue_p (*vecp);
 
@@ -8978,8 +8979,12 @@ convert_vector_to_array_for_subscript (location_t loc,
 for function parameters.  */
   c_common_mark_addressable_vec (*vecp);
 
+  /* Make sure qualifiers are copied from the vector type to the new 
element
+of the array type.  */
+  newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
+
   *vecp = build1 (VIEW_CONVERT_EXPR,
- build_array_type_nelts (TREE_TYPE (type),
+ build_array_type_nelts (newitype,
  TYPE_VECTOR_SUBPARTS (type)),
  *vecp);
 }
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 50f799d7ff7c..bd72533491e5 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -4424,7 +4424,8 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree 
t,
   if (!lval
   && TREE_CODE (ary) == VIEW_CONVERT_EXPR
   && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (ary, 0)))
-  && TREE_TYPE (t) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0
+  && (TYPE_MAIN_VARIANT (TREE_TYPE (t))
+ == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0))
 ary = TREE_OPERAND (ary, 0);
 
   tree oldidx = TREE_OPERAND (t, 1);
diff --git a/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C 
b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
new file mode 100644
index ..0c8958a4e034
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/vector-subaccess-1.C
@@ -0,0 +1,23 @@
+/* PR c++/89224 */
+
+/* The access of `vector[i]` has the same qualifiers as the original
+   vector which was missing. */
+
+typedef __attribute__((vector_size(16))) unsigned char  Int8x8_t;
+
+template 
+void g(T ) {
+__builtin_abort();
+}
+template 
+void g(const T ) {
+  __builtin_exit(0);
+}
+void f(const Int8x8_t x) {
+  g(x[0]);
+}
+int main(void)
+{
+Int8x8_t x ={};
+f(x);
+}
diff --git a/gcc/testsuite/gcc.dg/pr83415.c b/gcc/testsuite/gcc.dg/pr83415.c
index 5934c16d97cb..2fc85031505d 100644
--- a/gcc/testsuite/gcc.dg/pr83415.c
+++ b/gcc/testsuite/gcc.dg/pr83415.c
@@ -7,6 +7,6 @@ int
 main (int argc, short *argv[])
 {
   int i = argc;
-  y[i] = 7 - i; /* { dg-warning "read-only" } */
+  y[i] = 7 - i; /* { dg-error "read-only" } */
   return 0;
 }


[gcc r15-308] DCE __cxa_atexit calls where the function is pure/const [PR19661]

2024-05-07 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:c9dd853680b12d9c9def5de61abde5d057c526ba

commit r15-308-gc9dd853680b12d9c9def5de61abde5d057c526ba
Author: Andrew Pinski 
Date:   Fri Mar 15 16:34:22 2024 -0700

DCE __cxa_atexit calls where the function is pure/const [PR19661]

In C++ sometimes you have a deconstructor function which is "empty", like 
for an
example with unions or with arrays.  The front-end might not know it is 
empty either
so this should be done on during optimization.o
To implement it I added it to DCE where we mark if a statement is necessary 
or not.

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

Changes since v1:
  * v2: Add support for __aeabi_atexit for arm-*eabi. Add extra comments.
Add cxa_atexit-5.C testcase for -fPIC case.
  * v3: Fix testcases for the __aeabi_atexit (forgot to do in the v2).

PR tree-optimization/19661

gcc/ChangeLog:

* tree-ssa-dce.cc (is_cxa_atexit): New function.
(is_removable_cxa_atexit_call): New function.
(mark_stmt_if_obviously_necessary): Don't mark removable
cxa_at_exit calls.
(mark_all_reaching_defs_necessary_1): Likewise.
(propagate_necessity): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/cxa_atexit-1.C: New test.
* g++.dg/tree-ssa/cxa_atexit-2.C: New test.
* g++.dg/tree-ssa/cxa_atexit-3.C: New test.
* g++.dg/tree-ssa/cxa_atexit-4.C: New test.
* g++.dg/tree-ssa/cxa_atexit-5.C: New test.
* g++.dg/tree-ssa/cxa_atexit-6.C: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-1.C | 20 ++
 gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-2.C | 21 ++
 gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-3.C | 19 +
 gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-4.C | 20 ++
 gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-5.C | 39 +++
 gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-6.C | 24 
 gcc/tree-ssa-dce.cc  | 58 
 7 files changed, 201 insertions(+)

diff --git a/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-1.C 
b/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-1.C
new file mode 100644
index ..82ff3d2b7783
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-1.C
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cddce1-details -fdump-tree-optimized" } */
+// { dg-require-effective-target cxa_atexit }
+/* PR tree-optimization/19661 */
+
+/* The call to axexit should be removed as A::~A() is a pure/const function 
call
+   and there is no visible effect if A::~A() call does not happen.  */
+
+struct A { 
+A(); 
+~A() {} 
+}; 
+ 
+void foo () { 
+  static A a; 
+} 
+
+/* { dg-final { scan-tree-dump-times "Deleting : 
(?:__cxxabiv1::__cxa_atexit|__aeabiv1::__aeabi_atexit)" 1 "cddce1" } } */
+/* { dg-final { scan-tree-dump-not "__cxa_atexit|__aeabi_atexit" "optimized" } 
} */
+
diff --git a/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-2.C 
b/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-2.C
new file mode 100644
index ..726b6d7f1561
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-2.C
@@ -0,0 +1,21 @@
+/* { dg-do compile { target c++11 } } */
+/* { dg-options "-O2 -fdump-tree-cddce1-details -fdump-tree-optimized" } */
+// { dg-require-effective-target cxa_atexit }
+/* PR tree-optimization/19661 */
+
+/* The call to axexit should be not removed as A::~A() as it marked with 
noipa.  */
+
+struct A { 
+A(); 
+~A();
+}; 
+
+[[gnu::noipa]] A::~A() {}
+ 
+void foo () { 
+  static A a; 
+} 
+
+/* { dg-final { scan-tree-dump-not "Deleting : 
(?:__cxxabiv1::__cxa_atexit|__aeabiv1::__aeabi_atexit)" "cddce1" } } */
+/* { dg-final { scan-tree-dump-times "(?:__cxa_atexit|__aeabi_atexit)" 1 
"optimized" } } */
+
diff --git a/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-3.C 
b/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-3.C
new file mode 100644
index ..42cc7ccb11ba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-3.C
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cddce1-details -fdump-tree-optimized" } */
+// { dg-require-effective-target cxa_atexit }
+/* PR tree-optimization/19661 */
+
+/* We should not remove the call to atexit as A::~A is unknown.  */
+
+struct A { 
+A(); 
+~A();
+}; 
+
+void foo () { 
+  static A a; 
+} 
+
+/* { dg-final { scan-tree-dump-not "Deleting : 
(?:__cxxabiv1::__cxa_atexit|__aeabiv1::__aeabi_atexit)" "cddce1" } } */
+/* { dg-final { scan-tree-dump-times "(?:__cxa_atexit|__aeabi_atexit)" 1 
"optimized" } } */
+
diff --git a/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-4.C 
b/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-4.C
new file mode 100644
index ..591c1c0552a1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-4.C
@@ -0,0 +1,20 @@
+/* { dg-do 

[gcc r15-307] MATCH: Add some more value_replacement simplifications (a != 0 ? expr : 0) to match

2024-05-07 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:e472527c7b45d23e8dfd0fb767a6e663b4bc136e

commit r15-307-ge472527c7b45d23e8dfd0fb767a6e663b4bc136e
Author: Andrew Pinski 
Date:   Tue Apr 30 14:45:26 2024 -0700

MATCH: Add some more value_replacement simplifications (a != 0 ? expr : 0) 
to match

This adds a few more of what is currently done in phiopt's value_replacement
to match. I noticed this when I was hooking up phiopt's value_replacement
code to use match and disabling the old code. But this can be done
independently from the hooking up phiopt's value_replacement as phiopt
is already hooked up for simplified versions already.

/* a != 0 ? a / b : 0  -> a / b iff b is nonzero. */
/* a != 0 ? a * b : 0 -> a * b */
/* a != 0 ? a & b : 0 -> a & b */

We prefer the `cond ? a : 0` forms to allow optimization of `a * cond` which
uses that form.

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

PR tree-optimization/114894

gcc/ChangeLog:

* match.pd (`a != 0 ? a / b : 0`): New pattern.
(`a != 0 ? a * b : 0`): New pattern.
(`a != 0 ? a & b : 0`): New pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/phi-opt-value-5.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/match.pd| 18 
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-5.c | 39 +
 2 files changed, 57 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index d401e7503e62..03a03c31233c 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4290,6 +4290,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cond (eq @0 integer_all_onesp) @1 (op:c@2 @1 @0))
@2))
 
+/* a != 0 ? a / b : 0  -> a / b iff b is nonzero. */
+(for op (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+  (cond (ne @0 integer_zerop) (op@2 @3 @1) integer_zerop )
+   (if (bitwise_equal_p (@0, @3)
+&& tree_expr_nonzero_p (@1))
+@2)))
+
+/* Note we prefer the != case here
+   as (a != 0) * (a * b) will generate that version. */
+/* a != 0 ? a * b : 0 -> a * b */
+/* a != 0 ? a & b : 0 -> a & b */
+(for op (mult bit_and)
+ (simplify
+  (cond (ne @0 integer_zerop) (op:c@2 @1 @3) integer_zerop)
+  (if (bitwise_equal_p (@0, @3))
+   @2)))
+
 /* Simplifications of shift and rotates.  */
 
 (for rotate (lrotate rrotate)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-5.c 
b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-5.c
new file mode 100644
index ..8062eb19b113
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-5.c
@@ -0,0 +1,39 @@
+/* { dg-do compile } */
+/* PR treee-optimization/114894 */
+/* Phi-OPT should be able to optimize these without sinking being invoked. */
+/* { dg-options "-O -fdump-tree-phiopt2 -fdump-tree-phiopt3 
-fdump-tree-optimized -fno-tree-sink" } */
+
+int fmul1(int a, int b)
+{
+  int c = a * b;
+  if (a != 0)
+return c;
+  return 0;
+}
+
+
+int fand1(int a, int b)
+{
+  int c = a & b;
+  if (a != 0)
+return c;
+  return 0;
+}
+
+
+void g(int);
+
+int fdiv1(int a, int b)
+{
+  int d = b|1;
+  g(d);
+  int c = a / d;
+  return a != 0 ? c : 0;
+}
+
+/* fdiv1 requires until later than phiopt2 to be able to detect that
+   d is non-zero. to be able to remove the conditional.  */
+/* { dg-final { scan-tree-dump-times "goto" 2 "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not "goto" "phiopt3" } } */
+/* { dg-final { scan-tree-dump-not "goto" "optimized" } } */
+


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [committed][RISC-V] Turn on overlap_op_by_pieces for generic-ooo tuning

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:39c05d26b53dcfaede63414a21cc9f769bae98f1

commit 39c05d26b53dcfaede63414a21cc9f769bae98f1
Author: Jeff Law 
Date:   Tue May 7 15:34:16 2024 -0600

[committed][RISC-V] Turn on overlap_op_by_pieces for generic-ooo tuning

Per quick email exchange with Palmer.  Given the triviality, I'm just 
pushing
it.

gcc/
* config/riscv/riscv.cc (generic_ooo_tune_info): Turn on
overlap_op_by_pieces.

(cherry picked from commit 9f14f1978260148d4d6208dfd73df1858e623758)

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

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index a9b57d411841..62207b6b2273 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -536,7 +536,7 @@ static const struct riscv_tune_param generic_ooo_tune_info 
= {
   4,   /* fmv_cost */
   false,   /* slow_unaligned_access */
   false,   /* use_divmod_expansion */
-  false,   /* overlap_op_by_pieces */
+  true,/* overlap_op_by_pieces 
*/
   RISCV_FUSE_NOTHING,   /* fusible_ops */
   _vector_cost,/* vector cost */
 };


[gcc r15-306] [committed][RISC-V] Turn on overlap_op_by_pieces for generic-ooo tuning

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:9f14f1978260148d4d6208dfd73df1858e623758

commit r15-306-g9f14f1978260148d4d6208dfd73df1858e623758
Author: Jeff Law 
Date:   Tue May 7 15:34:16 2024 -0600

[committed][RISC-V] Turn on overlap_op_by_pieces for generic-ooo tuning

Per quick email exchange with Palmer.  Given the triviality, I'm just 
pushing
it.

gcc/
* config/riscv/riscv.cc (generic_ooo_tune_info): Turn on
overlap_op_by_pieces.

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

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index a9b57d411841..62207b6b2273 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -536,7 +536,7 @@ static const struct riscv_tune_param generic_ooo_tune_info 
= {
   4,   /* fmv_cost */
   false,   /* slow_unaligned_access */
   false,   /* use_divmod_expansion */
-  false,   /* overlap_op_by_pieces */
+  true,/* overlap_op_by_pieces 
*/
   RISCV_FUSE_NOTHING,   /* fusible_ops */
   _vector_cost,/* vector cost */
 };


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [committed] [RISC-V] Allow uarchs to set TARGET_OVERLAP_OP_BY_PIECES_P

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:07f793b32359e37191b2bda2a4e8cac8428648e8

commit 07f793b32359e37191b2bda2a4e8cac8428648e8
Author: Christoph Müllner 
Date:   Tue May 7 15:16:21 2024 -0600

[committed] [RISC-V] Allow uarchs to set TARGET_OVERLAP_OP_BY_PIECES_P

This is almost exclusively work from the VRULL team.

As we've discussed in the Tuesday meeting in the past, we'd like to have a 
knob
in the tuning structure to indicate that overlapped stores during
move_by_pieces expansion of memcpy & friends are acceptable.

This patch adds the that capability in our tuning structure.  It's off for 
all
the uarchs upstream, but we have been using it inside Ventana for our uarch
with success.  So technically it's NFC upstream, but puts in the 
infrastructure
multiple organizations likely need.

gcc/

* config/riscv/riscv.cc (struct riscv_tune_param): Add new
"overlap_op_by_pieces" field.
(rocket_tune_info, sifive_7_tune_info): Set it.
(sifive_p400_tune_info, sifive_p600_tune_info): Likewise.
(thead_c906_tune_info, xiangshan_nanhu_tune_info): Likewise.
(generic_ooo_tune_info, optimize_size_tune_info): Likewise.
(riscv_overlap_op_by_pieces): New function.
(TARGET_OVERLAP_OP_BY_PIECES_P): define.

gcc/testsuite/

* gcc.target/riscv/memcpy-nonoverlapping.c: New test.
* gcc.target/riscv/memset-nonoverlapping.c: New test.

(cherry picked from commit 300393484dbfa9fd3891174ea47aa3fb41915abc)

Diff:
---
 gcc/config/riscv/riscv.cc  | 18 
 .../gcc.target/riscv/memcpy-nonoverlapping.c   | 54 ++
 .../gcc.target/riscv/memset-nonoverlapping.c   | 45 ++
 3 files changed, 117 insertions(+)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 545e68566dc7..a9b57d411841 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -288,6 +288,7 @@ struct riscv_tune_param
   unsigned short fmv_cost;
   bool slow_unaligned_access;
   bool use_divmod_expansion;
+  bool overlap_op_by_pieces;
   unsigned int fusible_ops;
   const struct cpu_vector_cost *vec_costs;
 };
@@ -427,6 +428,7 @@ static const struct riscv_tune_param rocket_tune_info = {
   8,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_NOTHING,   /* fusible_ops */
   NULL,/* vector cost */
 };
@@ -444,6 +446,7 @@ static const struct riscv_tune_param sifive_7_tune_info = {
   8,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_NOTHING,   /* fusible_ops */
   NULL,/* vector cost */
 };
@@ -461,6 +464,7 @@ static const struct riscv_tune_param sifive_p400_tune_info 
= {
   4,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_LUI_ADDI | RISCV_FUSE_AUIPC_ADDI,  /* fusible_ops */
   _vector_cost,/* vector cost */
 };
@@ -478,6 +482,7 @@ static const struct riscv_tune_param sifive_p600_tune_info 
= {
   4,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_LUI_ADDI | RISCV_FUSE_AUIPC_ADDI,  /* fusible_ops */
   _vector_cost,/* vector cost */
 };
@@ -495,6 +500,7 @@ static const struct riscv_tune_param thead_c906_tune_info = 
{
   8,   /* fmv_cost */
   false,/* slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_NOTHING,   /* fusible_ops */
   NULL,/* vector cost */
 };
@@ -512,6 +518,7 @@ static const struct riscv_tune_param 
xiangshan_nanhu_tune_info = {
   3,   /* fmv_cost */
   true,/* 

[gcc r15-305] [committed] [RISC-V] Allow uarchs to set TARGET_OVERLAP_OP_BY_PIECES_P

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:300393484dbfa9fd3891174ea47aa3fb41915abc

commit r15-305-g300393484dbfa9fd3891174ea47aa3fb41915abc
Author: Christoph Müllner 
Date:   Tue May 7 15:16:21 2024 -0600

[committed] [RISC-V] Allow uarchs to set TARGET_OVERLAP_OP_BY_PIECES_P

This is almost exclusively work from the VRULL team.

As we've discussed in the Tuesday meeting in the past, we'd like to have a 
knob
in the tuning structure to indicate that overlapped stores during
move_by_pieces expansion of memcpy & friends are acceptable.

This patch adds the that capability in our tuning structure.  It's off for 
all
the uarchs upstream, but we have been using it inside Ventana for our uarch
with success.  So technically it's NFC upstream, but puts in the 
infrastructure
multiple organizations likely need.

gcc/

* config/riscv/riscv.cc (struct riscv_tune_param): Add new
"overlap_op_by_pieces" field.
(rocket_tune_info, sifive_7_tune_info): Set it.
(sifive_p400_tune_info, sifive_p600_tune_info): Likewise.
(thead_c906_tune_info, xiangshan_nanhu_tune_info): Likewise.
(generic_ooo_tune_info, optimize_size_tune_info): Likewise.
(riscv_overlap_op_by_pieces): New function.
(TARGET_OVERLAP_OP_BY_PIECES_P): define.

gcc/testsuite/

* gcc.target/riscv/memcpy-nonoverlapping.c: New test.
* gcc.target/riscv/memset-nonoverlapping.c: New test.

Diff:
---
 gcc/config/riscv/riscv.cc  | 18 
 .../gcc.target/riscv/memcpy-nonoverlapping.c   | 54 ++
 .../gcc.target/riscv/memset-nonoverlapping.c   | 45 ++
 3 files changed, 117 insertions(+)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 545e68566dc7..a9b57d411841 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -288,6 +288,7 @@ struct riscv_tune_param
   unsigned short fmv_cost;
   bool slow_unaligned_access;
   bool use_divmod_expansion;
+  bool overlap_op_by_pieces;
   unsigned int fusible_ops;
   const struct cpu_vector_cost *vec_costs;
 };
@@ -427,6 +428,7 @@ static const struct riscv_tune_param rocket_tune_info = {
   8,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_NOTHING,   /* fusible_ops */
   NULL,/* vector cost */
 };
@@ -444,6 +446,7 @@ static const struct riscv_tune_param sifive_7_tune_info = {
   8,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_NOTHING,   /* fusible_ops */
   NULL,/* vector cost */
 };
@@ -461,6 +464,7 @@ static const struct riscv_tune_param sifive_p400_tune_info 
= {
   4,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_LUI_ADDI | RISCV_FUSE_AUIPC_ADDI,  /* fusible_ops */
   _vector_cost,/* vector cost */
 };
@@ -478,6 +482,7 @@ static const struct riscv_tune_param sifive_p600_tune_info 
= {
   4,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_LUI_ADDI | RISCV_FUSE_AUIPC_ADDI,  /* fusible_ops */
   _vector_cost,/* vector cost */
 };
@@ -495,6 +500,7 @@ static const struct riscv_tune_param thead_c906_tune_info = 
{
   8,   /* fmv_cost */
   false,/* slow_unaligned_access */
   false,   /* use_divmod_expansion */
+  false,   /* overlap_op_by_pieces */
   RISCV_FUSE_NOTHING,   /* fusible_ops */
   NULL,/* vector cost */
 };
@@ -512,6 +518,7 @@ static const struct riscv_tune_param 
xiangshan_nanhu_tune_info = {
   3,   /* fmv_cost */
   true,/* 
slow_unaligned_access */
   false,   /* 

gcc-wwwdocs branch master updated. 506a866eae7f722c532bdcd513da6b8134be4091

2024-05-07 Thread Jakub Jelinek via Gcc-cvs-wwwdocs
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gcc-wwwdocs".

The branch, master has been updated
   via  506a866eae7f722c532bdcd513da6b8134be4091 (commit)
  from  0053d65e4071ba2e25073fdc2e1b7e8bf12a96a7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -
commit 506a866eae7f722c532bdcd513da6b8134be4091
Author: Jakub Jelinek 
Date:   Tue May 7 22:39:57 2024 +0200

Adjust implementation status of C++26 P2893R3 - Variadic friends.

diff --git a/htdocs/projects/cxx-status.html b/htdocs/projects/cxx-status.html
index 726b8153..4401c87e 100644
--- a/htdocs/projects/cxx-status.html
+++ b/htdocs/projects/cxx-status.html
@@ -163,7 +163,7 @@
 
Variadic friends 
https://wg21.link/P2893R3;>P2893R3
-   https://gcc.gnu.org/PR114459;>No
+   15
__cpp_variadic_friend >= 202403L 
 
 

---

Summary of changes:
 htdocs/projects/cxx-status.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


hooks/post-receive
-- 
gcc-wwwdocs


[gcc r15-304] c++: Implement C++26 P2893R3 - Variadic friends [PR114459]

2024-05-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:17458d2bc74b904968e6bdc12527eb040c8d2370

commit r15-304-g17458d2bc74b904968e6bdc12527eb040c8d2370
Author: Jakub Jelinek 
Date:   Tue May 7 22:38:01 2024 +0200

c++: Implement C++26 P2893R3 - Variadic friends [PR114459]

The following patch imeplements the C++26 P2893R3 - Variadic friends
paper.  The paper allows for the friend type declarations to specify
more than one friend type specifier and allows to specify ... at
the end of each.  The patch doesn't introduce tentative parsing of
friend-type-declaration non-terminal, but rather just extends existing
parsing where it is a friend declaration which ends with ; after the
declaration specifiers to the cases where it ends with ...; or , or ...,
In that case it pedwarns for cxx_dialect < cxx26, handles the ... and
if there is , continues in a loop to parse the further friend type
specifiers.

2024-05-07  Jakub Jelinek  

PR c++/114459
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Predefine
__cpp_variadic_friend=202403L for C++26.
gcc/cp/
* parser.cc (cp_parser_member_declaration): Implement C++26
P2893R3 - Variadic friends.  Parse friend type declarations
with ... or with more than one friend type specifier.
* friend.cc (make_friend_class): Allow TYPE_PACK_EXPANSION.
* pt.cc (instantiate_class_template): Handle PACK_EXPANSION_P
in friend classes.
gcc/testsuite/
* g++.dg/cpp26/feat-cxx26.C (__cpp_variadic_friend): Add test.
* g++.dg/cpp26/variadic-friend1.C: New test.

Diff:
---
 gcc/c-family/c-cppbuiltin.cc  |   1 +
 gcc/cp/friend.cc  |   3 +-
 gcc/cp/parser.cc  | 126 ++
 gcc/cp/pt.cc  |  16 
 gcc/testsuite/g++.dg/cpp26/feat-cxx26.C   |   6 ++
 gcc/testsuite/g++.dg/cpp26/variadic-friend1.C |  58 
 6 files changed, 169 insertions(+), 41 deletions(-)

diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index b6f25e4db3c0..d9b84a0f1b97 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1093,6 +1093,7 @@ c_cpp_builtins (cpp_reader *pfile)
  cpp_define (pfile, "__cpp_placeholder_variables=202306L");
  cpp_define (pfile, "__cpp_structured_bindings=202403L");
  cpp_define (pfile, "__cpp_deleted_function=202403L");
+ cpp_define (pfile, "__cpp_variadic_friend=202403L");
}
   if (flag_concepts)
 {
diff --git a/gcc/cp/friend.cc b/gcc/cp/friend.cc
index 758ea87b1721..2e70d0160c46 100644
--- a/gcc/cp/friend.cc
+++ b/gcc/cp/friend.cc
@@ -279,7 +279,8 @@ make_friend_class (tree type, tree friend_type, bool 
complain)
 }
 
   if (! MAYBE_CLASS_TYPE_P (friend_type)
-  && TREE_CODE (friend_type) != TEMPLATE_TEMPLATE_PARM)
+  && TREE_CODE (friend_type) != TEMPLATE_TEMPLATE_PARM
+  && TREE_CODE (friend_type) != TYPE_PACK_EXPANSION)
 {
   /* N1791: If the type specifier in a friend declaration designates a
 (possibly cv-qualified) class type, that class is declared as a
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 775067ed4bc5..c4191200291d 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -28100,8 +28100,17 @@ cp_parser_member_declaration (cp_parser* parser)
   && cp_parser_parse_and_diagnose_invalid_type_name (parser))
 goto out;
   /* If there is no declarator, then the decl-specifier-seq should
- specify a type.  */
-  if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
+ specify a type.  For C++26 Variadic friends don't just check for
+ a semicolon, but also for a comma and in both cases optionally
+ preceded by ellipsis.  */
+  if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)
+  || (cp_parser_friend_p (_specifiers)
+ && cxx_dialect >= cxx11
+ && (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)
+ || (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)
+ && (cp_lexer_nth_token_is (parser->lexer, 2, CPP_SEMICOLON)
+ || cp_lexer_nth_token_is (parser->lexer, 2,
+   CPP_COMMA))
 {
   /* If there was no decl-specifier-seq, and the next token is a
 `;', then we have something like:
@@ -28136,44 +28145,81 @@ cp_parser_member_declaration (cp_parser* parser)
{
  /* If the `friend' keyword was present, the friend must
 be introduced with a class-key.  */
-  if (!declares_class_or_enum && cxx_dialect < cxx11)
-pedwarn (decl_spec_token_start->location, OPT_Wpedantic,
- "in C++03 a class-key must be used "
- "when declaring a friend");
-  /* In this case:
-
-

[gcc r14-10181] expansion: Use __trunchfbf2 calls rather than __extendhfbf2 [PR114907]

2024-05-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:f43f346f19889a15a171a10c6ae1b1fe0a5bc038

commit r14-10181-gf43f346f19889a15a171a10c6ae1b1fe0a5bc038
Author: Jakub Jelinek 
Date:   Tue May 7 21:30:21 2024 +0200

expansion: Use __trunchfbf2 calls rather than __extendhfbf2 [PR114907]

The HF and BF modes have the same size/precision and neither is
a subset nor superset of the other.
So, using either __extendhfbf2 or __trunchfbf2 is weird.
The expansion apparently emits __extendhfbf2, but on the libgcc side
we apparently have __trunchfbf2 implemented.

I think it is easier to switch to using what is available rather than
adding new entrypoints to libgcc, even alias, because this is backportable.

2024-05-07  Jakub Jelinek  

PR middle-end/114907
* expr.cc (convert_mode_scalar): Use trunc_optab rather than
sext_optab for HF->BF conversions.
* optabs-libfuncs.cc (gen_trunc_conv_libfunc): Likewise.

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

(cherry picked from commit 28ee13db2e9d995bd3728c4ff3a3545e24b39cd2)

Diff:
---
 gcc/expr.cc | 12 ++--
 gcc/optabs-libfuncs.cc  |  4 +++-
 gcc/testsuite/gcc.dg/pr114907.c | 27 +++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index d4414e242cb9..9f66d4794459 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -355,8 +355,16 @@ convert_mode_scalar (rtx to, rtx from, int unsignedp)
  && REAL_MODE_FORMAT (from_mode) == _half_format));
 
   if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
-   /* Conversion between decimal float and binary float, same size.  */
-   tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
+   {
+ if (REAL_MODE_FORMAT (to_mode) == _bfloat_half_format
+ && REAL_MODE_FORMAT (from_mode) == _half_format)
+   /* libgcc implements just __trunchfbf2, not __extendhfbf2.  */
+   tab = trunc_optab;
+ else
+   /* Conversion between decimal float and binary float, same
+  size.  */
+   tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
+   }
   else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
tab = sext_optab;
   else
diff --git a/gcc/optabs-libfuncs.cc b/gcc/optabs-libfuncs.cc
index 02e9bf6ea5aa..26729910d92b 100644
--- a/gcc/optabs-libfuncs.cc
+++ b/gcc/optabs-libfuncs.cc
@@ -589,7 +589,9 @@ gen_trunc_conv_libfunc (convert_optab tab,
   if (GET_MODE_CLASS (float_tmode) != GET_MODE_CLASS (float_fmode))
 gen_interclass_conv_libfunc (tab, opname, float_tmode, float_fmode);
 
-  if (GET_MODE_PRECISION (float_fmode) <= GET_MODE_PRECISION (float_tmode))
+  if (GET_MODE_PRECISION (float_fmode) <= GET_MODE_PRECISION (float_tmode)
+  && (REAL_MODE_FORMAT (float_tmode) != _bfloat_half_format
+ || REAL_MODE_FORMAT (float_fmode) != _half_format))
 return;
 
   if (GET_MODE_CLASS (float_tmode) == GET_MODE_CLASS (float_fmode))
diff --git a/gcc/testsuite/gcc.dg/pr114907.c b/gcc/testsuite/gcc.dg/pr114907.c
new file mode 100644
index ..628746e1f8c1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114907.c
@@ -0,0 +1,27 @@
+/* PR middle-end/114907 */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16_runtime } */
+/* { dg-add-options bfloat16 } */
+/* { dg-require-effective-target bfloat16_runtime } */
+
+__attribute__((noipa)) _Float16
+foo (__bf16 x)
+{
+  return (_Float16) x;
+}
+
+__attribute__((noipa)) __bf16
+bar (_Float16 x)
+{
+  return (__bf16) x;
+}
+
+int
+main ()
+{
+  if (foo (11.125bf16) != 11.125f16
+  || bar (11.125f16) != 11.125bf16)
+__builtin_abort ();
+}


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

2024-05-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:aca573ea64ccfd54d4447e9a3200acd7a9157082

commit r14-10180-gaca573ea64ccfd54d4447e9a3200acd7a9157082
Author: Jakub Jelinek 
Date:   Tue May 7 21:29:14 2024 +0200

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

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

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

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

2024-05-07  Jakub Jelinek  

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

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

(cherry picked from commit d4e25cf4f7c1f51a8824cc62bbb85a81a41b829a)

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

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


[gcc r15-303] expansion: Use __trunchfbf2 calls rather than __extendhfbf2 [PR114907]

2024-05-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:28ee13db2e9d995bd3728c4ff3a3545e24b39cd2

commit r15-303-g28ee13db2e9d995bd3728c4ff3a3545e24b39cd2
Author: Jakub Jelinek 
Date:   Tue May 7 21:30:21 2024 +0200

expansion: Use __trunchfbf2 calls rather than __extendhfbf2 [PR114907]

The HF and BF modes have the same size/precision and neither is
a subset nor superset of the other.
So, using either __extendhfbf2 or __trunchfbf2 is weird.
The expansion apparently emits __extendhfbf2, but on the libgcc side
we apparently have __trunchfbf2 implemented.

I think it is easier to switch to using what is available rather than
adding new entrypoints to libgcc, even alias, because this is backportable.

2024-05-07  Jakub Jelinek  

PR middle-end/114907
* expr.cc (convert_mode_scalar): Use trunc_optab rather than
sext_optab for HF->BF conversions.
* optabs-libfuncs.cc (gen_trunc_conv_libfunc): Likewise.

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

Diff:
---
 gcc/expr.cc | 12 ++--
 gcc/optabs-libfuncs.cc  |  4 +++-
 gcc/testsuite/gcc.dg/pr114907.c | 27 +++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index d4414e242cb9..9f66d4794459 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -355,8 +355,16 @@ convert_mode_scalar (rtx to, rtx from, int unsignedp)
  && REAL_MODE_FORMAT (from_mode) == _half_format));
 
   if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
-   /* Conversion between decimal float and binary float, same size.  */
-   tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
+   {
+ if (REAL_MODE_FORMAT (to_mode) == _bfloat_half_format
+ && REAL_MODE_FORMAT (from_mode) == _half_format)
+   /* libgcc implements just __trunchfbf2, not __extendhfbf2.  */
+   tab = trunc_optab;
+ else
+   /* Conversion between decimal float and binary float, same
+  size.  */
+   tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
+   }
   else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
tab = sext_optab;
   else
diff --git a/gcc/optabs-libfuncs.cc b/gcc/optabs-libfuncs.cc
index 02e9bf6ea5aa..26729910d92b 100644
--- a/gcc/optabs-libfuncs.cc
+++ b/gcc/optabs-libfuncs.cc
@@ -589,7 +589,9 @@ gen_trunc_conv_libfunc (convert_optab tab,
   if (GET_MODE_CLASS (float_tmode) != GET_MODE_CLASS (float_fmode))
 gen_interclass_conv_libfunc (tab, opname, float_tmode, float_fmode);
 
-  if (GET_MODE_PRECISION (float_fmode) <= GET_MODE_PRECISION (float_tmode))
+  if (GET_MODE_PRECISION (float_fmode) <= GET_MODE_PRECISION (float_tmode)
+  && (REAL_MODE_FORMAT (float_tmode) != _bfloat_half_format
+ || REAL_MODE_FORMAT (float_fmode) != _half_format))
 return;
 
   if (GET_MODE_CLASS (float_tmode) == GET_MODE_CLASS (float_fmode))
diff --git a/gcc/testsuite/gcc.dg/pr114907.c b/gcc/testsuite/gcc.dg/pr114907.c
new file mode 100644
index ..628746e1f8c1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114907.c
@@ -0,0 +1,27 @@
+/* PR middle-end/114907 */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16_runtime } */
+/* { dg-add-options bfloat16 } */
+/* { dg-require-effective-target bfloat16_runtime } */
+
+__attribute__((noipa)) _Float16
+foo (__bf16 x)
+{
+  return (_Float16) x;
+}
+
+__attribute__((noipa)) __bf16
+bar (_Float16 x)
+{
+  return (__bf16) x;
+}
+
+int
+main ()
+{
+  if (foo (11.125bf16) != 11.125f16
+  || bar (11.125f16) != 11.125bf16)
+__builtin_abort ();
+}


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

2024-05-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d4e25cf4f7c1f51a8824cc62bbb85a81a41b829a

commit r15-302-gd4e25cf4f7c1f51a8824cc62bbb85a81a41b829a
Author: Jakub Jelinek 
Date:   Tue May 7 21:29:14 2024 +0200

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

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

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

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

2024-05-07  Jakub Jelinek  

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

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

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

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


[gcc r15-301] c++: DECL_DECOMPOSITION_P cleanup

2024-05-07 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:7887d808876c00e682e11c19caae1a0dbc9fa3a8

commit r15-301-g7887d808876c00e682e11c19caae1a0dbc9fa3a8
Author: Marek Polacek 
Date:   Fri Mar 1 13:36:51 2024 -0500

c++: DECL_DECOMPOSITION_P cleanup

DECL_DECOMPOSITION_P already checks VAR_P but we repeat the check
in a lot of places.

gcc/cp/ChangeLog:

* decl.cc (duplicate_decls): Don't check VAR_P before
DECL_DECOMPOSITION_P.
* init.cc (build_aggr_init): Likewise.
* parser.cc (cp_parser_range_for): Likewise.
(do_range_for_auto_deduction): Likewise.
(cp_convert_range_for): Likewise.
(cp_convert_omp_range_for): Likewise.
(cp_finish_omp_range_for): Likewise.
* pt.cc (extract_locals_r): Likewise.
(tsubst_omp_for_iterator): Likewise.
(tsubst_decomp_names): Likewise.
(tsubst_stmt): Likewise.
* typeck.cc (maybe_warn_about_returning_address_of_local): Likewise.

Diff:
---
 gcc/cp/decl.cc   |  3 +--
 gcc/cp/init.cc   |  2 +-
 gcc/cp/parser.cc | 11 ---
 gcc/cp/pt.cc | 11 +++
 gcc/cp/typeck.cc |  3 +--
 5 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index b112b70659f8..e02562466a74 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -1938,8 +1938,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, 
bool was_hidden)
  inform (olddecl_loc, "previous declaration %q#D", olddecl);
  return error_mark_node;
}
-  else if ((VAR_P (olddecl) && DECL_DECOMPOSITION_P (olddecl))
-  || (VAR_P (newdecl) && DECL_DECOMPOSITION_P (newdecl)))
+  else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P 
(newdecl))
/* A structured binding must be unique in its declarative region.  */;
   else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
   || DECL_IMPLICIT_TYPEDEF_P (newdecl))
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index a93ce00800c4..c1b5b7425c9b 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -2008,7 +2008,7 @@ build_aggr_init (tree exp, tree init, int flags, 
tsubst_flags_t complain)
   tree itype = init ? TREE_TYPE (init) : NULL_TREE;
   int from_array = 0;
 
-  if (VAR_P (exp) && DECL_DECOMPOSITION_P (exp))
+  if (DECL_DECOMPOSITION_P (exp))
{
  from_array = 1;
  init = mark_rvalue_use (init);
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 66ce161252c7..775067ed4bc5 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -14122,7 +14122,6 @@ cp_parser_range_for (cp_parser *parser, tree scope, 
tree init, tree range_decl,
  /* For decomposition declaration get all of the corresponding
 declarations out of the way.  */
  if (TREE_CODE (v) == ARRAY_REF
- && VAR_P (TREE_OPERAND (v, 0))
  && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0)))
{
  tree d = range_decl;
@@ -14243,7 +14242,7 @@ do_range_for_auto_deduction (tree decl, tree 
range_expr, cp_decomp *decomp)
iter_decl, auto_node,
tf_warning_or_error,
adc_variable_type);
- if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl))
+ if (DECL_DECOMPOSITION_P (decl))
cp_finish_decomp (decl, decomp);
}
 }
@@ -14442,7 +14441,7 @@ cp_convert_range_for (tree statement, tree range_decl, 
tree range_expr,
   cp_finish_decl (range_decl, deref_begin,
  /*is_constant_init*/false, NULL_TREE,
  LOOKUP_ONLYCONVERTING, decomp);
-  if (VAR_P (range_decl) && DECL_DECOMPOSITION_P (range_decl))
+  if (DECL_DECOMPOSITION_P (range_decl))
 cp_finish_decomp (range_decl, decomp);
 
   warn_for_range_copy (range_decl, deref_begin);
@@ -0,7 +44439,6 @@ cp_convert_omp_range_for (tree _pre_body, tree ,
{
  tree v = DECL_VALUE_EXPR (decl);
  if (TREE_CODE (v) == ARRAY_REF
- && VAR_P (TREE_OPERAND (v, 0))
  && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0)))
{
  d = TREE_OPERAND (v, 0);
@@ -44545,7 +44543,6 @@ cp_convert_omp_range_for (tree _pre_body, tree ,
 {
   tree v = DECL_VALUE_EXPR (orig_decl);
   if (TREE_CODE (v) == ARRAY_REF
- && VAR_P (TREE_OPERAND (v, 0))
  && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0)))
{
  tree d = orig_decl;
@@ -44623,7 +44620,7 @@ cp_finish_omp_range_for (tree orig, tree begin)
   tree decl = TREE_VEC_ELT (TREE_CHAIN (orig), 2);
   cp_decomp decomp_d, *decomp = NULL;
 
-  if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl))
+  if (DECL_DECOMPOSITION_P (decl))
 {
   decomp = _d;
   decomp_d.decl = TREE_VEC_ELT (TREE_CHAIN (orig), 3);
@@ -44649,7 +44646,7 @@ cp_finish_omp_range_for (tree orig, tree begin)

[gcc r14-10179] [PR modula2/113768][PR modula2/114133] bugfix constants must be cast prior to vararg call

2024-05-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:07dab3f6b56c711dcd737d856cf01a597a2e1626

commit r14-10179-g07dab3f6b56c711dcd737d856cf01a597a2e1626
Author: Gaius Mulley 
Date:   Tue May 7 19:51:08 2024 +0100

[PR modula2/113768][PR modula2/114133] bugfix constants must be cast prior 
to vararg call

This bug fix corrects the test codes below by converting the constant
literals to the type required by C.  In the testcases below the values, 1
etc were converted into the INTEGER type before being passed to a C
vararg function.  By default in modula2 constant literal ordinals are
represented as the ZTYPE (the largest GCC integer type node).

gcc/testsuite/ChangeLog:

PR modula2/113768
PR modula2/114133
* gm2/extensions/run/pass/callingc10.mod: Convert constant literal
numbers into INTEGER.
* gm2/extensions/run/pass/callingc11.mod: Ditto.
* gm2/extensions/run/pass/vararg2.mod: Ditto.
* gm2/iso/run/pass/packed.mod: Emit a printf as a runtime
diagnostic.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/testsuite/gm2/extensions/run/pass/callingc10.mod | 6 +++---
 gcc/testsuite/gm2/extensions/run/pass/callingc11.mod | 6 +++---
 gcc/testsuite/gm2/extensions/run/pass/vararg2.mod| 6 +++---
 gcc/testsuite/gm2/iso/run/pass/packed.mod| 2 ++
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod 
b/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
index 3a2d3e210dcc..0c26fedf8453 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
@@ -4,13 +4,13 @@ FROM cvararg IMPORT funcptr ;
 FROM SYSTEM IMPORT ADR ;
 
 BEGIN
-   IF funcptr (1, "hello", 5) = 1
+   IF funcptr (INTEGER (1), "hello", INTEGER (5)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " ", 6) = 1
+   IF funcptr (INTEGER (1), "hello" + " ", INTEGER (6)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " " + "world", 11) = 1
+   IF funcptr (INTEGER (1), "hello" + " " + "world", INTEGER (11)) = INTEGER 
(1)
THEN
END
 END callingc10.
diff --git a/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod 
b/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
index 9b8cb82d645f..d71026ee35df 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
@@ -5,13 +5,13 @@ FROM SYSTEM IMPORT ADR ;
 FROM strconst IMPORT WORLD ;
 
 BEGIN
-   IF funcptr (1, "hello", 5) = 1
+   IF funcptr (INTEGER (1), "hello", INTEGER (5)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " ", 6) = 1
+   IF funcptr (INTEGER (1), "hello" + " ", INTEGER (6)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " " + WORLD, 11) = 1
+   IF funcptr (INTEGER (1), "hello" + " " + WORLD, INTEGER (11)) = INTEGER (1)
THEN
END
 END callingc11.
diff --git a/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod 
b/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
index e26ed096fb84..05f7074a459d 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
@@ -21,13 +21,13 @@ FROM cvararg IMPORT funcptr ;
 FROM SYSTEM IMPORT ADR ;
 
 BEGIN
-   IF funcptr(1, ADR("hello world"), 11)=1
+   IF funcptr(INTEGER (1), ADR("hello world"), INTEGER (11))=INTEGER (1)
THEN
END ;
-   IF funcptr(1, ADR("hello"), 5)=1
+   IF funcptr(INTEGER (1), ADR("hello"), INTEGER (5))=INTEGER (1)
THEN
END ;
-   IF funcptr(1, ADR("/etc/passwd"), 11)=1
+   IF funcptr(INTEGER (1), ADR("/etc/passwd"), INTEGER (11))=INTEGER (1)
THEN
END
 END vararg2.
diff --git a/gcc/testsuite/gm2/iso/run/pass/packed.mod 
b/gcc/testsuite/gm2/iso/run/pass/packed.mod
index 401a6998f71a..3dad71e60a13 100644
--- a/gcc/testsuite/gm2/iso/run/pass/packed.mod
+++ b/gcc/testsuite/gm2/iso/run/pass/packed.mod
@@ -38,7 +38,9 @@ PROCEDURE test ;
 VAR
v: CARDINAL ;
 BEGIN
+   printf ("testing to see BITSET{0} = CARDINAL (1)...");
Assert(CAST(CARDINAL, BITSET{0}) = VAL(CARDINAL, 1), __FILE__, __LINE__) ;
+   printf ("yes\n");
v := MAX(CARDINAL)-1 ;
WHILE v>0 DO
   Assert(CAST(CARDINAL, SHIFT(CAST(BITSET, v), -1)) = v DIV 2, __FILE__, 
__LINE__) ;


[gcc r15-300] PR modula2/114133 bugfix constants must be cast prior to vararg call

2024-05-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:76e591200f54226290ddb49b8ac6231a694bf882

commit r15-300-g76e591200f54226290ddb49b8ac6231a694bf882
Author: Gaius Mulley 
Date:   Tue May 7 19:24:08 2024 +0100

PR modula2/114133 bugfix constants must be cast prior to vararg call

This bug fix corrects the test codes below by converting the constant
literals to the type required by C.  In the testcases below the values, 1
etc were converted into the INTEGER type before being passed to a C
vararg function.  By default in modula2 constant literal ordinals are
represented as the ZTYPE (the largest GCC integer type node).

gcc/testsuite/ChangeLog:

PR modula2/114133
* gm2/extensions/run/pass/callingc10.mod: Convert constant
literal numbers into INTEGER.
* gm2/extensions/run/pass/callingc11.mod: Ditto.
* gm2/extensions/run/pass/vararg2.mod: Ditto.
* gm2/iso/run/pass/packed.mod: Emit a printf as a runtime
diagnostic.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/testsuite/gm2/extensions/run/pass/callingc10.mod | 6 +++---
 gcc/testsuite/gm2/extensions/run/pass/callingc11.mod | 6 +++---
 gcc/testsuite/gm2/extensions/run/pass/vararg2.mod| 6 +++---
 gcc/testsuite/gm2/iso/run/pass/packed.mod| 2 ++
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod 
b/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
index 3a2d3e210dcc..0c26fedf8453 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
@@ -4,13 +4,13 @@ FROM cvararg IMPORT funcptr ;
 FROM SYSTEM IMPORT ADR ;
 
 BEGIN
-   IF funcptr (1, "hello", 5) = 1
+   IF funcptr (INTEGER (1), "hello", INTEGER (5)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " ", 6) = 1
+   IF funcptr (INTEGER (1), "hello" + " ", INTEGER (6)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " " + "world", 11) = 1
+   IF funcptr (INTEGER (1), "hello" + " " + "world", INTEGER (11)) = INTEGER 
(1)
THEN
END
 END callingc10.
diff --git a/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod 
b/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
index 9b8cb82d645f..d71026ee35df 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
@@ -5,13 +5,13 @@ FROM SYSTEM IMPORT ADR ;
 FROM strconst IMPORT WORLD ;
 
 BEGIN
-   IF funcptr (1, "hello", 5) = 1
+   IF funcptr (INTEGER (1), "hello", INTEGER (5)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " ", 6) = 1
+   IF funcptr (INTEGER (1), "hello" + " ", INTEGER (6)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " " + WORLD, 11) = 1
+   IF funcptr (INTEGER (1), "hello" + " " + WORLD, INTEGER (11)) = INTEGER (1)
THEN
END
 END callingc11.
diff --git a/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod 
b/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
index e26ed096fb84..05f7074a459d 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
@@ -21,13 +21,13 @@ FROM cvararg IMPORT funcptr ;
 FROM SYSTEM IMPORT ADR ;
 
 BEGIN
-   IF funcptr(1, ADR("hello world"), 11)=1
+   IF funcptr(INTEGER (1), ADR("hello world"), INTEGER (11))=INTEGER (1)
THEN
END ;
-   IF funcptr(1, ADR("hello"), 5)=1
+   IF funcptr(INTEGER (1), ADR("hello"), INTEGER (5))=INTEGER (1)
THEN
END ;
-   IF funcptr(1, ADR("/etc/passwd"), 11)=1
+   IF funcptr(INTEGER (1), ADR("/etc/passwd"), INTEGER (11))=INTEGER (1)
THEN
END
 END vararg2.
diff --git a/gcc/testsuite/gm2/iso/run/pass/packed.mod 
b/gcc/testsuite/gm2/iso/run/pass/packed.mod
index 401a6998f71a..3dad71e60a13 100644
--- a/gcc/testsuite/gm2/iso/run/pass/packed.mod
+++ b/gcc/testsuite/gm2/iso/run/pass/packed.mod
@@ -38,7 +38,9 @@ PROCEDURE test ;
 VAR
v: CARDINAL ;
 BEGIN
+   printf ("testing to see BITSET{0} = CARDINAL (1)...");
Assert(CAST(CARDINAL, BITSET{0}) = VAL(CARDINAL, 1), __FILE__, __LINE__) ;
+   printf ("yes\n");
v := MAX(CARDINAL)-1 ;
WHILE v>0 DO
   Assert(CAST(CARDINAL, SHIFT(CAST(BITSET, v), -1)) = v DIV 2, __FILE__, 
__LINE__) ;


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [RISC-V] [PATCH v2] Enable inlining str* by default

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:8b5321bc863bfc9920676c33295644cbebfd0a05

commit 8b5321bc863bfc9920676c33295644cbebfd0a05
Author: Jeff Law 
Date:   Tue May 7 11:43:09 2024 -0600

[RISC-V] [PATCH v2] Enable inlining str* by default

So with Chrstoph's patches from late 2022 we've had the ability to inline
strlen, and str[n]cmp (scalar).  However, we never actually turned this
capability on by default!

This patch flips the those default to allow inlinining by default.  It also
fixes one bug exposed by our internal testing when NBYTES is zero for 
strncmp.
I don't think that case happens enough to try and optimize it, we just 
disable
inline expansion for that instance.

This has been bootstrapped and regression tested on rv64gc at various times 
as
well as cross tested on rv64gc more times than I can probably count (we've 
have
this patch internally for a while).  More importantly, I just successfully
tested it on rv64gc and rv32gcv elf configurations with the trunk

gcc/

* config/riscv/riscv-string.cc (riscv_expand_strcmp): Do not inline
strncmp with zero size.
(emit_strcmp_scalar_compare_subword): Adjust rotation for rv32 vs 
rv64.
* config/riscv/riscv.opt (var_inline_strcmp): Enable by default.
(vriscv_inline_strncmp, riscv_inline_strlen): Likewise.

gcc/testsuite

* gcc.target/riscv/zbb-strlen-disabled-2.c: Turn off inlining.

(cherry picked from commit 1139f38e798181572121657e5b267a9698edb62f)

Diff:
---
 gcc/config/riscv/riscv-string.cc   | 9 -
 gcc/config/riscv/riscv.opt | 6 +++---
 gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c | 4 ++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc
index b09b51d7526b..41cb061c746d 100644
--- a/gcc/config/riscv/riscv-string.cc
+++ b/gcc/config/riscv/riscv-string.cc
@@ -153,7 +153,7 @@ emit_strcmp_scalar_compare_subword (rtx data1, rtx data2, 
rtx orc1,
   rtx imask = gen_rtx_CONST_INT (Xmode, im);
   rtx m_reg = gen_reg_rtx (Xmode);
   emit_insn (gen_rtx_SET (m_reg, imask));
-  do_rotr3 (m_reg, m_reg, GEN_INT (64 - cmp_bytes * BITS_PER_UNIT));
+  do_rotr3 (m_reg, m_reg, GEN_INT (BITS_PER_WORD - cmp_bytes * BITS_PER_UNIT));
   do_and3 (data1, m_reg, data1);
   do_and3 (data2, m_reg, data2);
   if (TARGET_ZBB)
@@ -497,6 +497,13 @@ riscv_expand_strcmp (rtx result, rtx src1, rtx src2,
return false;
   nbytes = UINTVAL (bytes_rtx);
 
+  /* If NBYTES is zero the result of strncmp will always be zero,
+but that would require special casing in the caller.  So for
+now just don't do an inline expansion.  This probably rarely
+happens in practice, but it is tested by the testsuite.  */
+  if (nbytes == 0)
+   return false;
+
   /* We don't emit parts of a strncmp() call.  */
   if (nbytes > compare_max)
return false;
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 7cca1c4aab20..1252834aec5b 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -517,15 +517,15 @@ Target Var(TARGET_INLINE_SUBWORD_ATOMIC) Init(1)
 Always inline subword atomic operations.
 
 minline-strcmp
-Target Var(riscv_inline_strcmp) Init(0)
+Target Var(riscv_inline_strcmp) Init(1)
 Inline strcmp calls if possible.
 
 minline-strncmp
-Target Var(riscv_inline_strncmp) Init(0)
+Target Var(riscv_inline_strncmp) Init(1)
 Inline strncmp calls if possible.
 
 minline-strlen
-Target Var(riscv_inline_strlen) Init(0)
+Target Var(riscv_inline_strlen) Init(1)
 Inline strlen calls if possible.
 
 -param=riscv-strcmp-inline-limit=
diff --git a/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c 
b/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c
index a481068aa0c7..1295aeb0086e 100644
--- a/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c
+++ b/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c
@@ -1,6 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv32gc_zbb" { target { rv32 } } } */
-/* { dg-options "-march=rv64gc_zbb" { target { rv64 } } } */
+/* { dg-options "-mno-inline-strlen -march=rv32gc_zbb" { target { rv32 } } } */
+/* { dg-options "-mno-inline-strlen -march=rv64gc_zbb" { target { rv64 } } } */
 /* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
 
 typedef long unsigned int size_t;


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [PATCH 1/1] RISC-V: Add Zfbfmin extension to the -march= option

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:c396fa61e71313cdfcb384bd0fb74f7d3b972d30

commit c396fa61e71313cdfcb384bd0fb74f7d3b972d30
Author: Xiao Zeng 
Date:   Mon May 6 15:57:37 2024 -0600

[PATCH 1/1] RISC-V: Add Zfbfmin extension to the -march= option

This patch would like to add new sub extension (aka Zfbfmin) to the
-march= option. It introduces a new data type BF16.

1 The Zfbfmin extension depend on 'F', and the FLH, FSH, FMV.X.H, and
FMV.H.X instructions as defined in the Zfh extension.

2 The Zfhmin extension includes the following instructions from the
Zfh extension: FLH, FSH, FMV.X.H, FMV.H.X, FCVT.S.H, and FCVT.H.S.

3 Zfhmin extension depend on 'F'.

4 Simply put, just make Zfbfmin dependent on Zfhmin.

Perhaps in the future, we could propose making the FLH, FSH, FMV.X.H, and
FMV.H.X instructions an independent extension to achieve precise dependency
relationships for the Zfbfmin.

You can locate more information about Zfbfmin from below spec doc.




gcc/
* common/config/riscv/riscv-common.cc (riscv_implied_info): zfbfmin
implies zfhmin.
(riscv_ext_version_table, riscv_ext_flag_table): Add zfbfmin.
* config/riscv/riscv.opt (ZFBFMIN): Add optoion.

gcc/testsuite/
* gcc.target/riscv/arch-35.c: New test.
* gcc.target/riscv/arch-36.c: New test.
* gcc.target/riscv/predef-34.c: New test.
* gcc.target/riscv/predef-35.c: New test.

(cherry picked from commit 35224ead63732a3550ba4b1332c06e9dc7999c31)

Diff:
---
 gcc/common/config/riscv/riscv-common.cc|  3 ++
 gcc/config/riscv/riscv.opt |  2 ++
 gcc/testsuite/gcc.target/riscv/arch-35.c   |  5 
 gcc/testsuite/gcc.target/riscv/arch-36.c   |  5 
 gcc/testsuite/gcc.target/riscv/predef-34.c | 47 ++
 gcc/testsuite/gcc.target/riscv/predef-35.c | 47 ++
 6 files changed, 109 insertions(+)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 8cc0e727737e..fb76017ffbc0 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -155,6 +155,7 @@ static const riscv_implied_info_t riscv_implied_info[] =
   {"zvksed", "zve32x"},
   {"zvksh",  "zve32x"},
 
+  {"zfbfmin", "zfhmin"},
   {"zfh", "zfhmin"},
   {"zfhmin", "f"},
 
@@ -331,6 +332,7 @@ static const struct riscv_ext_version 
riscv_ext_version_table[] =
   {"zvl32768b", ISA_SPEC_CLASS_NONE, 1, 0},
   {"zvl65536b", ISA_SPEC_CLASS_NONE, 1, 0},
 
+  {"zfbfmin",   ISA_SPEC_CLASS_NONE, 1, 0},
   {"zfh",   ISA_SPEC_CLASS_NONE, 1, 0},
   {"zfhmin",ISA_SPEC_CLASS_NONE, 1, 0},
   {"zvfbfmin",  ISA_SPEC_CLASS_NONE, 1, 0},
@@ -1698,6 +1700,7 @@ static const riscv_ext_flag_table_t 
riscv_ext_flag_table[] =
   {"zvl32768b", _options::x_riscv_zvl_flags, MASK_ZVL32768B},
   {"zvl65536b", _options::x_riscv_zvl_flags, MASK_ZVL65536B},
 
+  {"zfbfmin",   _options::x_riscv_zf_subext, MASK_ZFBFMIN},
   {"zfhmin",_options::x_riscv_zf_subext, MASK_ZFHMIN},
   {"zfh",   _options::x_riscv_zf_subext, MASK_ZFH},
   {"zvfbfmin",  _options::x_riscv_zf_subext, MASK_ZVFBFMIN},
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index ee824756381b..7cca1c4aab20 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -393,6 +393,8 @@ Mask(ZIC64B) Var(riscv_zicmo_subext)
 TargetVariable
 int riscv_zf_subext
 
+Mask(ZFBFMIN)  Var(riscv_zf_subext)
+
 Mask(ZFHMIN)  Var(riscv_zf_subext)
 
 Mask(ZFH) Var(riscv_zf_subext)
diff --git a/gcc/testsuite/gcc.target/riscv/arch-35.c 
b/gcc/testsuite/gcc.target/riscv/arch-35.c
new file mode 100644
index ..6c7837696669
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-35.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32i_zfbfmin -mabi=ilp32f" } */
+int foo()
+{
+}
diff --git a/gcc/testsuite/gcc.target/riscv/arch-36.c 
b/gcc/testsuite/gcc.target/riscv/arch-36.c
new file mode 100644
index ..cbdccf128079
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-36.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64i_zfbfmin -mabi=lp64f" } */
+int foo()
+{
+}
diff --git a/gcc/testsuite/gcc.target/riscv/predef-34.c 
b/gcc/testsuite/gcc.target/riscv/predef-34.c
new file mode 100644
index ..0a993271f7f2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/predef-34.c
@@ -0,0 +1,47 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32i_zfbfmin -mabi=ilp32f -mcmodel=medlow 
-misa-spec=20191213" } */
+
+int main () {
+
+#ifndef __riscv_arch_test
+#error "__riscv_arch_test"
+#endif
+
+#if __riscv_xlen != 32
+#error "__riscv_xlen"
+#endif
+
+#if !defined(__riscv_i)
+#error "__riscv_i"
+#endif
+
+#if 

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Add testcase for PR114749.

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:cd0e329128a349ff58b75de14e1c877cce9abffc

commit cd0e329128a349ff58b75de14e1c877cce9abffc
Author: Robin Dapp 
Date:   Mon May 6 15:51:37 2024 -0600

RISC-V: Add testcase for PR114749.

this adds a test case for PR114749.
Going to commit as obvious unless somebody complains.

Regards
 Robin

gcc/testsuite/ChangeLog:

PR tree-optimization/114749

* gcc.target/riscv/rvv/autovec/pr114749.c: New test.

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114749.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114749.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114749.c
new file mode 100644
index ..6733b0481a6a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114749.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv_zvl128b -mabi=lp64d -fwhole-program -O3 
-mrvv-vector-bits=zvl" } */
+
+extern int a[];
+extern char b[];
+int c = 24;
+_Bool d[24][24][24];
+_Bool (*e)[24][24] = d;
+int main() {
+  for (short f = 0; f < 24; f += 3)
+for (unsigned g = 0; g < (char)c; g += 2) {
+  a[f] = 0;
+  b[g] |= ({ e[f][f][f]; });
+}
+}


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [RISC-V] Add support for _Bfloat16

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:af9ec7bb55674b09434ff821ee496558ca8dc4c3

commit af9ec7bb55674b09434ff821ee496558ca8dc4c3
Author: Xiao Zeng 
Date:   Mon May 6 15:39:12 2024 -0600

[RISC-V] Add support for _Bfloat16

1 At point ,
  BF16 has already been completed "post public review".

2 LLVM has also added support for RISCV BF16 in
   and
  .

3 According to the discussion 
,
  this use __bf16 and use DF16b in riscv_mangle_type like x86.

Below test are passed for this patch
* The riscv fully regression test.

gcc/ChangeLog:

* config/riscv/iterators.md: New mode iterator HFBF.
* config/riscv/riscv-builtins.cc (riscv_init_builtin_types):
Initialize data type _Bfloat16.
* config/riscv/riscv-modes.def (FLOAT_MODE): New.
(ADJUST_FLOAT_FORMAT): New.
* config/riscv/riscv.cc (riscv_mangle_type): Support for BFmode.
(riscv_scalar_mode_supported_p): Ditto.
(riscv_libgcc_floating_mode_supported_p): Ditto.
(riscv_init_libfuncs): Set the conversion method for BFmode and
HFmode.
(riscv_block_arith_comp_libfuncs_for_mode): Set the arithmetic
and comparison libfuncs for the mode.
* config/riscv/riscv.md (mode" ): Add BF.
(movhf): Support for BFmode.
(mov): Ditto.
(*movhf_softfloat): Ditto.
(*mov_softfloat): Ditto.

libgcc/ChangeLog:

* config/riscv/sfp-machine.h (_FP_NANFRAC_B): New.
(_FP_NANSIGN_B): Ditto.
* config/riscv/t-softfp32: Add support for BF16 libfuncs.
* config/riscv/t-softfp64: Ditto.
* soft-fp/floatsibf.c: For si -> bf16.
* soft-fp/floatunsibf.c: For unsi -> bf16.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/bf16_arithmetic.c: New test.
* gcc.target/riscv/bf16_call.c: New test.
* gcc.target/riscv/bf16_comparison.c: New test.
* gcc.target/riscv/bf16_float_libcall_convert.c: New test.
* gcc.target/riscv/bf16_integer_libcall_convert.c: New test.

Co-authored-by: Jin Ma 
(cherry picked from commit 8c7cee80eb50792e57d514be1418c453ddd1073e)

Diff:
---
 gcc/config/riscv/iterators.md  |  2 +
 gcc/config/riscv/riscv-builtins.cc | 16 +
 gcc/config/riscv/riscv-modes.def   |  3 +
 gcc/config/riscv/riscv.cc  | 64 +++--
 gcc/config/riscv/riscv.md  | 24 +++
 gcc/testsuite/gcc.target/riscv/bf16_arithmetic.c   | 42 +++
 gcc/testsuite/gcc.target/riscv/bf16_call.c | 12 
 gcc/testsuite/gcc.target/riscv/bf16_comparison.c   | 36 ++
 .../gcc.target/riscv/bf16_float_libcall_convert.c  | 57 +++
 .../riscv/bf16_integer_libcall_convert.c   | 81 ++
 libgcc/config/riscv/sfp-machine.h  |  3 +
 libgcc/config/riscv/t-softfp32 | 10 ++-
 libgcc/config/riscv/t-softfp64 |  3 +-
 libgcc/soft-fp/floatsibf.c | 45 
 libgcc/soft-fp/floatunsibf.c   | 45 
 15 files changed, 407 insertions(+), 36 deletions(-)

diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md
index 75e119e407a3..32e1b1403051 100644
--- a/gcc/config/riscv/iterators.md
+++ b/gcc/config/riscv/iterators.md
@@ -75,6 +75,8 @@
 ;; Iterator for floating-point modes that can be loaded into X registers.
 (define_mode_iterator SOFTF [SF (DF "TARGET_64BIT") (HF "TARGET_ZFHMIN")])
 
+;; Iterator for floating-point modes of BF16
+(define_mode_iterator HFBF [HF BF])
 
 ;; ---
 ;; Mode attributes
diff --git a/gcc/config/riscv/riscv-builtins.cc 
b/gcc/config/riscv/riscv-builtins.cc
index d457e306dd18..4c08834288ac 100644
--- a/gcc/config/riscv/riscv-builtins.cc
+++ b/gcc/config/riscv/riscv-builtins.cc
@@ -230,6 +230,7 @@ static GTY(()) int riscv_builtin_decl_index[NUM_INSN_CODES];
   riscv_builtin_decls[riscv_builtin_decl_index[(CODE)]]
 
 tree riscv_float16_type_node = NULL_TREE;
+tree riscv_bfloat16_type_node = NULL_TREE;
 
 /* Return the function type associated with function prototype TYPE.  */
 
@@ -273,6 +274,21 @@ riscv_init_builtin_types (void)
   if (!maybe_get_identifier ("_Float16"))
 lang_hooks.types.register_builtin_type (riscv_float16_type_node,
"_Float16");
+
+  /* Provide the _Bfloat16 type and bfloat16_type_node if needed.  */
+  if (!bfloat16_type_node)
+{
+  riscv_bfloat16_type_node = make_node (REAL_TYPE);
+  TYPE_PRECISION 

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Document -mcmodel=large

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:6b0b0128c4f3fed4dff92c489017b7504c7f970b

commit 6b0b0128c4f3fed4dff92c489017b7504c7f970b
Author: Palmer Dabbelt 
Date:   Mon May 6 15:34:26 2024 -0600

RISC-V: Document -mcmodel=large

  This slipped through the cracks.  Probably also NEWS-worthy.

gcc/ChangeLog:

* doc/invoke.texi (RISC-V): Add -mcmodel=large.

(cherry picked from commit 6ffea3e37380860507cce08af42a997fbdb5d754)

Diff:
---
 gcc/doc/invoke.texi | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 9456ced468af..dc4c5a3189d7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1252,7 +1252,7 @@ See RS/6000 and PowerPC Options.
 -msave-restore  -mno-save-restore
 -mshorten-memrefs  -mno-shorten-memrefs
 -mstrict-align  -mno-strict-align
--mcmodel=medlow  -mcmodel=medany
+-mcmodel=medlow  -mcmodel=medany -mcmodel=large
 -mexplicit-relocs  -mno-explicit-relocs
 -mrelax  -mno-relax
 -mriscv-attribute  -mno-riscv-attribute
@@ -31049,6 +31049,11 @@ The code generated by the medium-any code model is 
position-independent, but is
 not guaranteed to function correctly when linked into position-independent
 executables or libraries.
 
+@opindex -mcmodel=large
+@item -mcmodel=large
+Generate code for a large code model, which has no restrictions on size or
+placement of symbols.
+
 @item -mexplicit-relocs
 @itemx -mno-exlicit-relocs
 Use or do not use assembler relocation operators when dealing with symbolic


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] So another constant synthesis improvement.

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:3ccf8a5463d9a606515e141a7f582683115d985b

commit 3ccf8a5463d9a606515e141a7f582683115d985b
Author: Jeff Law 
Date:   Mon May 6 15:27:43 2024 -0600

So another constant synthesis improvement.

In this patch we're looking at cases where we'd like to be able to use
lui+slli, but can't because of the sign extending nature of lui on
TARGET_64BIT.  For example: 0x800110020UL.  The trunk currently 
generates 4
instructions for that constant, when it can be done with 3 
(lui+slli.uw+addi).

When Zba is enabled, we can use lui+slli.uw as the slli.uw masks off the 
bits
32..63 before shifting, giving us the precise semantics we want.

I strongly suspect we'll want to do the same for a set of constants with
lui+add.uw, lui+shNadd.uw, so you'll see the beginnings of generalizing 
support
for lui followed by a "uw" instruction.

The new test just tests the set of cases that showed up while exploring a
particular space of the constant synthesis problem.  It's not meant to be
exhaustive (failure to use shadd when profitable).

gcc/

* config/riscv/riscv.cc (riscv_integer_op): Add field tracking if we
want to use a "uw" instruction variant.
(riscv_build_integer_1): Initialize the new field in various places.
Use lui+slli.uw for some constants.
(riscv_move_integer): Handle slli.uw.

gcc/testsuite/

* gcc.target/riscv/synthesis-2.c: New test.

(cherry picked from commit 975bb17e2f6bc90d366237ab1c5dc9b8df2dee69)

Diff:
---
 gcc/config/riscv/riscv.cc|   60 +-
 gcc/testsuite/gcc.target/riscv/synthesis-2.c | 1481 ++
 2 files changed, 1539 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 44945d47fd64..6f1c67bf3f7a 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -249,6 +249,7 @@ struct riscv_arg_info {
where A is an accumulator, each CODE[i] is a binary rtl operation
and each VALUE[i] is a constant integer.  CODE[0] is undefined.  */
 struct riscv_integer_op {
+  bool use_uw;
   enum rtx_code code;
   unsigned HOST_WIDE_INT value;
 };
@@ -734,6 +735,7 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
   /* Simply ADDI or LUI.  */
   codes[0].code = UNKNOWN;
   codes[0].value = value;
+  codes[0].use_uw = false;
   return 1;
 }
   if (TARGET_ZBS && SINGLE_BIT_MASK_OPERAND (value))
@@ -741,6 +743,7 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
   /* Simply BSETI.  */
   codes[0].code = UNKNOWN;
   codes[0].value = value;
+  codes[0].use_uw = false;
 
   /* RISC-V sign-extends all 32bit values that live in a 32bit
 register.  To avoid paradoxes, we thus need to use the
@@ -769,6 +772,7 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
{
  alt_codes[alt_cost-1].code = PLUS;
  alt_codes[alt_cost-1].value = low_part;
+ alt_codes[alt_cost-1].use_uw = false;
  memcpy (codes, alt_codes, sizeof (alt_codes));
  cost = alt_cost;
}
@@ -782,6 +786,7 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
{
  alt_codes[alt_cost-1].code = XOR;
  alt_codes[alt_cost-1].value = low_part;
+ alt_codes[alt_cost-1].use_uw = false;
  memcpy (codes, alt_codes, sizeof (alt_codes));
  cost = alt_cost;
}
@@ -792,17 +797,37 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
 {
   int shift = ctz_hwi (value);
   unsigned HOST_WIDE_INT x = value;
+  bool use_uw = false;
   x = sext_hwi (x >> shift, HOST_BITS_PER_WIDE_INT - shift);
 
   /* Don't eliminate the lower 12 bits if LUI might apply.  */
-  if (shift > IMM_BITS && !SMALL_OPERAND (x) && LUI_OPERAND (x << 
IMM_BITS))
+  if (shift > IMM_BITS
+ && !SMALL_OPERAND (x)
+ && (LUI_OPERAND (x << IMM_BITS)
+ || (TARGET_64BIT
+ && TARGET_ZBA
+ && LUI_OPERAND ((x << IMM_BITS)
+ & ~HOST_WIDE_INT_C (0x8000)
shift -= IMM_BITS, x <<= IMM_BITS;
 
+  /* Adjust X if it isn't a LUI operand in isolation, but we can use
+a subsequent "uw" instruction form to mask off the undesirable
+bits.  */
+  if (!LUI_OPERAND (x)
+ && TARGET_64BIT
+ && TARGET_ZBA
+ && LUI_OPERAND (x & ~HOST_WIDE_INT_C (0x8000UL)))
+   {
+ x = sext_hwi (x, 32);
+ use_uw = true;
+   }
+
   alt_cost = 1 + riscv_build_integer_1 (alt_codes, x, mode);
   if (alt_cost < cost)
{
  alt_codes[alt_cost-1].code = ASHIFT;
  alt_codes[alt_cost-1].value = shift;
+ 

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: miscll comment fixes [NFC]

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:3d0f38b394e6c5f4bb93ce2047dd985ea7e081af

commit 3d0f38b394e6c5f4bb93ce2047dd985ea7e081af
Author: Vineet Gupta 
Date:   Tue Mar 1 03:45:19 2022 -0800

RISC-V: miscll comment fixes [NFC]

gcc/ChangeLog:
* config/riscv/riscv.cc: Comment updates.
* config/riscv/riscv.h: Ditto.

Signed-off-by: Vineet Gupta 
(cherry picked from commit 467ca4a195e26dba77e7f62cc1a3d45a4e541c72)

Diff:
---
 gcc/config/riscv/riscv.cc | 6 --
 gcc/config/riscv/riscv.h  | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 8ed9df8126a6..44945d47fd64 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -1258,7 +1258,9 @@ riscv_legitimate_constant_p (machine_mode mode 
ATTRIBUTE_UNUSED, rtx x)
   return riscv_const_insns (x) > 0;
 }
 
-/* Implement TARGET_CANNOT_FORCE_CONST_MEM.  */
+/* Implement TARGET_CANNOT_FORCE_CONST_MEM.
+   Return true if X cannot (or should not) be spilled to the
+   constant pool.  */
 
 static bool
 riscv_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
@@ -8624,7 +8626,7 @@ riscv_modes_tieable_p (machine_mode mode1, machine_mode 
mode2)
   && GET_MODE_CLASS (mode2) == MODE_FLOAT));
 }
 
-/* Implement CLASS_MAX_NREGS.  */
+/* Implement TARGET_CLASS_MAX_NREGS.  */
 
 static unsigned char
 riscv_class_max_nregs (reg_class_t rclass, machine_mode mode)
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 7797e67317a6..58d0b09bf7d9 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -315,7 +315,7 @@ ASM_MISA_SPEC
- FRAME_POINTER_REGNUM
- 1 vl register
- 1 vtype register
-   - 30 unused registers for future expansion
+   - 28 unused registers for future expansion
- 32 vector registers  */
 
 #define FIRST_PSEUDO_REGISTER 128


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [committed][RISC-V] Fix nearbyint failure on rv32 and formatting nits

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:9ba5c71aeab72bf5a773eaeaaf96a03520c3da9f

commit 9ba5c71aeab72bf5a773eaeaaf96a03520c3da9f
Author: Jeff Law 
Date:   Thu May 2 17:13:12 2024 -0600

[committed][RISC-V] Fix nearbyint failure on rv32 and formatting nits

The CI system tripped an execution failure for rv32 with the ceil/round 
patch.

The fundamental problem is the FP->INT step in these sequences requires the
input size to match the output size.  The output size was based on 
rv32/rv64.
Meaning that we'd try to do DF->SI->DF.

That doesn't preserve the semantics we want in at least two ways.

The net is we can't use this trick for DF values on rv32.  While inside the
code I realized we had a similar problem for HF modes.  HF modes we can 
support
only for Zfa.  So I fixed that proactively.

The CI system also pointed out various formatting nits.  I think this fixes 
all
but one overly long line.

Note I could have factored the TARGET_ZFA test.  But I think as-written it's
clearer what the desired cases to transform are.

gcc/
* config/riscv/riscv.md (2): Adjust
condition to match what can be properly implemented.  Fix various
formatting issues.
(lsi2_sext): Fix formatting

(cherry picked from commit 8367c996e55b2c54aeee25e446357a1015a1d11d)

Diff:
---
 gcc/config/riscv/riscv.md | 65 +--
 1 file changed, 34 insertions(+), 31 deletions(-)

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index b9b0acf92c73..d4676507b452 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -2077,8 +2077,8 @@
 (define_insn "lsi2_sext"
   [(set (match_operand:DI   0 "register_operand" "=r")
 (sign_extend:DI (unspec:SI
-[(match_operand:ANYF 1 "register_operand" " f")]
-  ROUND)))]
+[(match_operand:ANYF 1 "register_operand" " f")]
+ ROUND)))]
   "TARGET_64BIT && (TARGET_HARD_FLOAT || TARGET_ZFINX)"
   "fcvt.w. %0,%1,"
   [(set_attr "type" "fcvt_f2i")
@@ -2094,13 +2094,25 @@
   [(set_attr "type" "fcvt_f2i")
(set_attr "mode" "")])
 
+;; There are a couple non-obvious restrictions to be aware of.
+;;
+;; We'll do a FP-INT conversion in the sequence.  But we don't
+;; have a .l (64bit) variant of those instructions for rv32.
+;; To preserve proper semantics we must reject DFmode inputs
+;; for rv32 unless Zfa is enabled.
+;;
+;; The ANYF iterator allows HFmode.  We don't have all the
+;; necessary patterns defined for HFmode.  So restrict HFmode
+;; to TARGET_ZFA.
 (define_expand "2"
   [(set (match_operand:ANYF 0 "register_operand" "=f")
-(unspec:ANYF
-[(match_operand:ANYF 1 "register_operand" " f")]
-ROUND))]
-  "TARGET_HARD_FLOAT && (TARGET_ZFA
- || flag_fp_int_builtin_inexact || 
!flag_trapping_math)"
+   (unspec:ANYF
+   [(match_operand:ANYF 1 "register_operand" " f")]
+   ROUND))]
+  "(TARGET_HARD_FLOAT
+&& (TARGET_ZFA || flag_fp_int_builtin_inexact || !flag_trapping_math)
+&& (TARGET_ZFA || TARGET_64BIT || mode != DFmode)
+&& (TARGET_ZFA || mode != HFmode))"
 {
   if (TARGET_ZFA)
 emit_insn (gen__zfa2 (operands[0],
@@ -2116,7 +2128,7 @@
 
   riscv_emit_move (tmp_reg, operands[1]);
   riscv_emit_move (coeff_reg,
-   riscv_vector::get_fp_rounding_coefficient 
(mode));
+  riscv_vector::get_fp_rounding_coefficient 
(mode));
   emit_insn (gen_abs2 (abs_reg, operands[1]));
 
   riscv_expand_conditional_branch (label, LT, abs_reg, coeff_reg);
@@ -2126,29 +2138,20 @@
 
   emit_label (label);
   switch (mode)
-{
-case SFmode:
-  reg = gen_reg_rtx (SImode);
-  emit_insn (gen_lsfsi2 (reg, operands[1]));
-  emit_insn (gen_floatsisf2 (abs_reg, reg));
-  break;
-case DFmode:
-  if (TARGET_64BIT)
-{
-  reg = gen_reg_rtx (DImode);
-  emit_insn (gen_ldfdi2 (reg, operands[1]));
-  emit_insn (gen_floatdidf2 (abs_reg, reg));
-}
-  else
-{
-  reg = gen_reg_rtx (SImode);
-  emit_insn (gen_ldfsi2 (reg, operands[1]));
-  emit_insn (gen_floatsidf2 (abs_reg, reg));
-}
-  break;
-default:
-  gcc_unreachable ();
-}
+   {
+   case SFmode:
+ reg = gen_reg_rtx (SImode);
+ emit_insn (gen_lsfsi2 (reg, operands[1]));
+ emit_insn (gen_floatsisf2 (abs_reg, reg));
+ break;
+   case DFmode:
+ reg = gen_reg_rtx (DImode);
+ emit_insn (gen_ldfdi2 (reg, operands[1]));
+ emit_insn (gen_floatdidf2 (abs_reg, reg));
+ break;
+   default:
+ gcc_unreachable ();
+   }
 
   emit_insn (gen_copysign3 

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [RFA][RISC-V] Improve constant synthesis for constants with 2 bits set

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:0099c20adb23b71718d4c6f3937fd126f1a931e4

commit 0099c20adb23b71718d4c6f3937fd126f1a931e4
Author: Jeff Law 
Date:   Thu May 2 14:06:22 2024 -0600

[RFA][RISC-V] Improve constant synthesis for constants with 2 bits set

In doing some preparation work for using zbkb's pack instructions for 
constant
synthesis I figured it would be wise to get a sense of how well our constant
synthesis is actually working and address any clear issues.

So the first glaring inefficiency is in our handling of constants with a 
small
number of bits set.  Let's start with just two bits set.   There are 2016
distinct constants in that space (rv64).  With Zbs enabled the absolute 
worst
we should ever do is two instructions (bseti+bseti).  Yet we have 503 cases
where we're generating 3+ instructions when there's just two bits set in the
constant.  A constant like 0x80001000 generates 4 instructions!

This patch adds bseti (and indirectly binvi if we needed it) as a first 
class
citizen for constant synthesis.  There's two components to this change.

First, we can't generate an IOR with a constant like (1 << 45) as an 
operand.
The IOR/XOR define_insn is in riscv.md.  The constant argument for those
patterns must match an arith_operand which means its not really usable for
generating bseti directly in the cases we care about (at least one of the 
bits
will be in the 32..63 range and thus won't match arith_operand).

We have a few things we could do.  One would be to extend the existing 
pattern
to incorporate bseti cases.  But I suspect folks like the separation of the
base architecture (riscv.md) from the Zb* extensions (bitmanip.md).  We 
could
also try to generate the RTL for bseti
directly, bypassing gen_fmt_ee (which forces undesirable constants into 
registers based on the predicate of the appropriate define_insn). Neither of 
these seemed particularly appealing to me.

So what I've done instead is to make ior/xor a define_expand and have the
expander allow a wider set of constant operands when Zbs is enabled.  That
allows us to keep the bulk of Zb* support inside bitmanip.md and continue to
use gen_fmt_ee in the constant synthesis paths.

Note the code generation in this case is designed to first set as many bits 
as
we can with lui, then with addi since those can both set multiple bits at a
time.  If there are any residual bits left to set we can emit bseti
instructions up to the current cost ceiling.

This results in fixing all of the 503 2-bit set cases where we emitted too 
many
instructions.  It also significantly helps other scenarios with more bits 
set.

The testcase I'm including verifies the number of instructions we generate 
for
the full set of 2016 possible cases.  Obviously this won't be possible as we
increase the number of bits (there are something like 48k cases with just 3
bits set).

gcc/

* config/riscv/predicates.md (arith_or_zbs_operand): New predicate.
* config/riscv/riscv.cc (riscv_build_integer_one): Use bseti to set
single bits when profitable.
* config/riscv/riscv.md (*3): Renamed with '*' prefix.
(3): New expander for IOR/XOR.

gcc/testsuite
* gcc.target/riscv/synthesis-1.c: New test.

Diff:
---
 gcc/config/riscv/predicates.md   |8 +
 gcc/config/riscv/riscv.cc|   65 +-
 gcc/config/riscv/riscv.md|   17 +-
 gcc/testsuite/gcc.target/riscv/synthesis-1.c | 2034 ++
 4 files changed, 2110 insertions(+), 14 deletions(-)

diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md
index 539e0f7379b7..e7d797d4dbf0 100644
--- a/gcc/config/riscv/predicates.md
+++ b/gcc/config/riscv/predicates.md
@@ -386,6 +386,14 @@
   (and (match_code "const_int")
(match_test "SINGLE_BIT_MASK_OPERAND (UINTVAL (op))")))
 
+;; Register, small constant or single bit constant for use in
+;; bseti/binvi.
+(define_predicate "arith_or_zbs_operand"
+  (ior (match_operand 0 "const_arith_operand")
+   (match_operand 0 "register_operand")
+   (and (match_test "TARGET_ZBS")
+   (match_operand 0 "single_bit_mask_operand"
+
 (define_predicate "not_single_bit_mask_operand"
   (and (match_code "const_int")
(match_test "SINGLE_BIT_MASK_OPERAND (~UINTVAL (op))")))
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 24d1ead3902c..8ed9df8126a6 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -725,6 +725,9 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
   HOST_WIDE_INT low_part = CONST_LOW_PART (value);
   int cost = RISCV_MAX_INTEGER_OPS + 1, alt_cost;
   struct riscv_integer_op alt_codes[RISCV_MAX_INTEGER_OPS];
+  int upper_trailing_ones 

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [committed] [RISC-V] Trivial pattern cleanup

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:1985c80b0470848d6362e8f769744ed6b7ed743d

commit 1985c80b0470848d6362e8f769744ed6b7ed743d
Author: Jeff Law 
Date:   Wed May 1 12:43:37 2024 -0600

[committed] [RISC-V] Trivial pattern cleanup

As I was reviewing and cleaning up some internal work, I noticed a 
particular
idiom being used elsewhere in the RISC-V backend.

Specifically the use of explicit subregs when an adjustment to the
match_operand would be sufficient.

Let's take this example from the and-not splitter:

>  (define_split
>[(set (match_operand:X 0 "register_operand")
> (and:X (not:X (lshiftrt:X (match_operand:X 1 "register_operand")
>   (subreg:QI (match_operand:X 2 
"register_operand") 0)))
>(const_int 1)))]

Note the explicit subreg.  We can instead use a match_operand with QImode.
This ever-so-slightly simplifies the machine description.

It also means that if we have a QImode object lying around (say we loaded it
from memory in QImode), we can use it directly rather than first extending 
it
to X, then truncing to QI.  So we end up with simpler RTL and in rare cases
improve the code we generate.

When used in a define_split or define_insn_and_split we need to make 
suitable
adjustments to the split RTL.

Bootstrapped a while back.  Just re-tested with a cross.

gcc/
* config/riscv/bitmanip.md (splitter to use w-form division): Remove
explicit subregs.
(zero extended bitfield extraction): Similarly.
* config/riscv/thead.md (*th_memidx_operand): Similarly.

(cherry picked from commit 76ca6e1f8b1524b82a871ce29cf58c79e5e77e2b)

Diff:
---
 gcc/config/riscv/bitmanip.md | 9 +
 gcc/config/riscv/thead.md| 4 ++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index ccda25c01c1b..ad3ad758959e 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -50,11 +50,11 @@
(sign_extend:DI (div:SI (plus:SI (ashift:SI (subreg:SI 
(match_operand:DI 1 "register_operand") 0)
(match_operand:QI 2 
"imm123_operand"))
 (subreg:SI (match_operand:DI 3 
"register_operand") 0))
-   (subreg:SI (match_operand:DI 4 
"register_operand") 0
+   (match_operand:SI 4 "register_operand"
(clobber (match_operand:DI 5 "register_operand"))]
   "TARGET_64BIT && TARGET_ZBA"
[(set (match_dup 5) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) 
(match_dup 3)))
-(set (match_dup 0) (sign_extend:DI (div:SI (subreg:SI (match_dup 5) 0) 
(subreg:SI (match_dup 4) 0])
+(set (match_dup 0) (sign_extend:DI (div:SI (subreg:SI (match_dup 5) 0) 
(match_dup 4])
 
 ; Zba does not provide W-forms of sh[123]add(.uw)?, which leads to an
 ; interesting irregularity: we can generate a signed 32-bit result
@@ -722,13 +722,14 @@
 (define_split
   [(set (match_operand:X 0 "register_operand")
(and:X (not:X (lshiftrt:X (match_operand:X 1 "register_operand")
- (subreg:QI (match_operand:X 2 
"register_operand") 0)))
+ (match_operand:QI 2 "register_operand")))
   (const_int 1)))]
   "TARGET_ZBS"
   [(set (match_dup 0) (zero_extract:X (match_dup 1)
  (const_int 1)
  (match_dup 2)))
-   (set (match_dup 0) (xor:X (match_dup 0) (const_int 1)))])
+   (set (match_dup 0) (xor:X (match_dup 0) (const_int 1)))]
+  "operands[2] = gen_lowpart (mode, operands[2]);")
 
 ;; We can create a polarity-reversed mask (i.e. bit N -> { set = 0, clear = -1 
})
 ;; using a bext(i) followed by an addi instruction.
diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
index 5c7d4beb1b66..a47fe6f28b8c 100644
--- a/gcc/config/riscv/thead.md
+++ b/gcc/config/riscv/thead.md
@@ -466,12 +466,12 @@
 (define_insn_and_split "*th_memidx_operand"
   [(set (match_operand:DI 0 "register_operand" "=r")
  (ashift:DI
-   (zero_extend:DI (subreg:SI (match_operand:DI 1 "register_operand" "r") 
0))
+   (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
(match_operand 2 "const_int_operand" "n")))]
   "TARGET_64BIT && TARGET_XTHEADMEMIDX && lra_in_progress"
   "#"
   ""
-  [(set (match_dup 0) (zero_extend:DI (subreg:SI (match_dup 1) 0)))
+  [(set (match_dup 0) (zero_extend:DI (match_dup 1)))
(set (match_dup 0) (ashift:DI (match_dup 0) (match_dup 2)))]
   ""
   [(set_attr "type" "bitmanip")])


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [committed] [RISC-V] Don't run new rounding tests on newlib risc-v targets

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:63c91bfa7fae1716b23b67cc4e614e379b06f8f6

commit 63c91bfa7fae1716b23b67cc4e614e379b06f8f6
Author: Jeff Law 
Date:   Thu May 2 08:42:32 2024 -0600

[committed] [RISC-V] Don't run new rounding tests on newlib risc-v targets

The new round_32.c and round_64.c tests depend on the optimizers to 
recognize
the conversions feeding the floor/ceil calls and convert them into ceilf,
floorf and the like.

Those transformations only occur when the target indicates the C library has
the appropriate routines (fnclass == function_c99_misc).  While newlib has
these routines, they are not exposed as available to the compiler and thus 
the
transformation the tests depend on do not happen. Naturally the scan-tests 
then
fail.

gcc/testsuite
* gcc.target/riscv/round_32.c: Add require-effective-target glibc.
* gcc.target/riscv/round_64.c: Likewise.

(cherry picked from commit 1e29da0b6508b23a7a6b14a7fb643b917a195003)

Diff:
---
 gcc/testsuite/gcc.target/riscv/round_32.c | 1 +
 gcc/testsuite/gcc.target/riscv/round_64.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/round_32.c 
b/gcc/testsuite/gcc.target/riscv/round_32.c
index f9fea70ad552..88ff77aff2e0 100644
--- a/gcc/testsuite/gcc.target/riscv/round_32.c
+++ b/gcc/testsuite/gcc.target/riscv/round_32.c
@@ -1,4 +1,5 @@
 /* { dg-do compile { target { riscv32*-*-* } } } */
+/* { dg-require-effective-target glibc } */
 /* { dg-options "-march=rv32gc -mabi=ilp32d -fno-math-errno 
-funsafe-math-optimizations -fno-inline" } */
 /* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
 
diff --git a/gcc/testsuite/gcc.target/riscv/round_64.c 
b/gcc/testsuite/gcc.target/riscv/round_64.c
index e79690979a50..5e13bccdcd2a 100644
--- a/gcc/testsuite/gcc.target/riscv/round_64.c
+++ b/gcc/testsuite/gcc.target/riscv/round_64.c
@@ -1,4 +1,5 @@
 /* { dg-do compile { target { riscv64*-*-* } } } */
+/* { dg-require-effective-target glibc } */
 /* { dg-options "-march=rv64gc -mabi=lp64d -fno-math-errno 
-funsafe-math-optimizations -fno-inline" } */
 /* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [committed] [RISC-V] Fix detection of store pair fusion cases

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:305a5d2d9a9394579d132364c0fd1ca9e95c9f4c

commit 305a5d2d9a9394579d132364c0fd1ca9e95c9f4c
Author: Jeff Law 
Date:   Wed May 1 11:28:41 2024 -0600

[committed] [RISC-V] Fix detection of store pair fusion cases

We've got the ability to count the number of store pair fusions happening in
the front-end of the pipeline.  When comparing some code from last year vs 
the
current trunk we saw a fairly dramatic drop.

The problem is the store pair fusion detection code was actively harmful 
due to
a minor bug in checking offsets.   So instead of pairing up 8 byte stores 
such
as sp+0 with sp+8, it tried to pair up sp+8 and sp+16.

Given uarch sensitivity I didn't try to pull together a testcase.  But we 
could
certainly see the undesirable behavior in benchmarks as simplistic as 
dhrystone
up through spec2017.

Anyway, bootstrapped a while back.  Also verified through our performance
counters that store pair fusion rates are back up.  Regression tested with
crosses a few minutes ago.

gcc/
* config/riscv/riscv.cc (riscv_macro_fusion_pair_p): Break out
tests for easier debugging in store pair fusion case.  Fix offset
check in same.

(cherry picked from commit fad93e7617ce1aafb006983a71b6edc9ae1eb2d1)

Diff:
---
 gcc/config/riscv/riscv.cc | 57 ++-
 1 file changed, 37 insertions(+), 20 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 0f62b295b969..24d1ead3902c 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -8874,26 +8874,43 @@ riscv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn 
*curr)
  extract_base_offset_in_addr (SET_DEST (prev_set), _prev, 
_prev);
  extract_base_offset_in_addr (SET_DEST (curr_set), _curr, 
_curr);
 
- /* The two stores must be contained within opposite halves of the same
-16 byte aligned block of memory.  We know that the stack pointer 
and
-the frame pointer have suitable alignment.  So we just need to 
check
-the offsets of the two stores for suitable alignment.
-
-Originally the thought was to check MEM_ALIGN, but that was 
reporting
-incorrect alignments, even for SP/FP accesses, so we gave up on 
that
-approach.  */
- if (base_prev != NULL_RTX
- && base_curr != NULL_RTX
- && REG_P (base_prev)
- && REG_P (base_curr)
- && REGNO (base_prev) == REGNO (base_curr)
- && (REGNO (base_prev) == STACK_POINTER_REGNUM
- || REGNO (base_prev) == HARD_FRAME_POINTER_REGNUM)
- && ((INTVAL (offset_prev) == INTVAL (offset_curr) + 8
-  && (INTVAL (offset_prev) % 16) == 0)
- || ((INTVAL (offset_curr) == INTVAL (offset_prev) + 8)
- && (INTVAL (offset_curr) % 16) == 0)))
-   return true;
+ /* Fail if we did not find both bases.  */
+ if (base_prev == NULL_RTX || base_curr == NULL_RTX)
+   return false;
+
+ /* Fail if either base is not a register.  */
+ if (!REG_P (base_prev) || !REG_P (base_curr))
+   return false;
+
+ /* Fail if the bases are not the same register.  */
+ if (REGNO (base_prev) != REGNO (base_curr))
+   return false;
+
+ /* Originally the thought was to check MEM_ALIGN, but that was
+reporting incorrect alignments, even for SP/FP accesses, so we
+gave up on that approach.  Instead just check for stack/hfp
+which we know are aligned.  */
+ if (REGNO (base_prev) != STACK_POINTER_REGNUM
+ && REGNO (base_prev) != HARD_FRAME_POINTER_REGNUM)
+   return false;
+
+ /* The two stores must be contained within opposite halves of the
+same 16 byte aligned block of memory.  We know that the stack
+pointer and the frame pointer have suitable alignment.  So we
+just need to check the offsets of the two stores for suitable
+alignment.  */
+ /* Get the smaller offset into OFFSET_PREV.  */
+ if (INTVAL (offset_prev) > INTVAL (offset_curr))
+   std::swap (offset_prev, offset_curr);
+
+ /* If the smaller offset (OFFSET_PREV) is not 16 byte aligned,
+then fail.  */
+ if ((INTVAL (offset_prev) % 16) != 0)
+   return false;
+
+ /* The higher offset must be 8 bytes more than the lower
+offset.  */
+ return (INTVAL (offset_prev) + 8 == INTVAL (offset_curr));
}
 }


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] This is almost exclusively Jivan's work. His original post:

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:7fd192a0af22aa524685692c086ea1ffe5b0d789

commit 7fd192a0af22aa524685692c086ea1ffe5b0d789
Author: Jivan Hakobyan 
Date:   Tue Apr 30 09:44:02 2024 -0600

This is almost exclusively Jivan's work.  His original post:

> https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg336483.html

This patch is primarily meant to improve the code we generate for FP 
rounding
such as ceil/floor.  It also addresses some unnecessary sign extensions in 
the
same areas.

RISC-V's FP conversions have a bit of undesirable behavior that make them
non-suitable as-is for ceil/floor and other related functions. These
deficiencies are addressed in the Zfa extension, but there's no reason not 
to
pick up a nice improvement when we can.

Basically we can still use the basic FP conversions for floor/ceil and 
friends
when we don't care about inexact exceptions by checking for the special 
cases
first, then emitting the conversion when the special cases don't apply.  
That's
still much faster than calling into glibc.

The redundant sign extensions are eliminated using the same trick Jivan 
added
last year, just in a few more places ;-)

This eliminates roughly 10% of the dynamic instruction count for imagick.  
But
more importantly it's about a 17% performance improvement for that workload
within spec.

This has been bootstrapped as well as regression tested in a cross 
environment.
It's also successfully built & run specint/specfp correctly.

Pushing to the trunk and the coordination branch momentarily.

gcc/
* config/riscv/iterators.md (fix_ops, fix_uns): New iterators.
(RINT, rint_pattern, rint_rm): Remove unused iterators.
* config/riscv/riscv-protos.h (get_fp_rounding_coefficient): 
Prototype.
* config/riscv/riscv-v.cc (get_fp_rounding_coefficient): 
Externalize.
external linkage.
* config/riscv/riscv.md (UNSPEC_LROUND): Remove.
(fix_trunc2): Replace with ...
(_truncsi2): New expander & associated insn.
(_truncsi2_ext): New insn.
(_truncdi2): Likewise.
(l2): Replace with ...
(lrintsi2): New expander and associated insn.
(lrintsi2_ext, lrintdi2): New insns.
(2): Replace with
(lsi2): New expander and associated insn.
(lsi2_sext): New insn.
(ldi2): Likewise.
(2): New expander.

gcc/testsuite/
* gcc.target/riscv/fix.c: New test.
* gcc.target/riscv/round.c: New test.
* gcc.target/riscv/round_32.c: New test.
* gcc.target/riscv/round_64.c: New test.

(cherry picked from commit f652a35877e32d470d649d1aee5d94fa0169a478)

Diff:
---
 gcc/config/riscv/iterators.md |  12 +-
 gcc/config/riscv/riscv-protos.h   |   1 +
 gcc/config/riscv/riscv-v.cc   |   2 +-
 gcc/config/riscv/riscv.md | 211 +++---
 gcc/testsuite/gcc.target/riscv/fix.c  |  34 +
 gcc/testsuite/gcc.target/riscv/round.c| 144 
 gcc/testsuite/gcc.target/riscv/round_32.c |  22 
 gcc/testsuite/gcc.target/riscv/round_64.c |  23 
 8 files changed, 427 insertions(+), 22 deletions(-)

diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md
index a7694137685a..75e119e407a3 100644
--- a/gcc/config/riscv/iterators.md
+++ b/gcc/config/riscv/iterators.md
@@ -196,6 +196,13 @@
 
 (define_code_iterator bitmanip_rotate [rotate rotatert])
 
+;; These code iterators allow the signed and unsigned fix operations to use
+;; the same template.
+(define_code_iterator fix_ops [fix unsigned_fix])
+
+(define_code_attr fix_uns [(fix "fix") (unsigned_fix "fixuns")])
+
+
 ;; ---
 ;; Code Attributes
 ;; ---
@@ -312,11 +319,6 @@
 ;; Int Iterators.
 ;; ---
 
-;; Iterator and attributes for floating-point rounding instructions.
-(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND])
-(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND "round")])
-(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")])
-
 ;; Iterator and attributes for quiet comparisons.
 (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET UNSPEC_FLE_QUIET])
 (define_int_attr quiet_pattern [(UNSPEC_FLT_QUIET "lt") (UNSPEC_FLE_QUIET 
"le")])
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 5d46a29d8b70..e5aebf3fc3d5 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -711,6 +711,7 @@ bool gather_scatter_valid_offset_p (machine_mode);
 HOST_WIDE_INT estimated_poly_value (poly_int64, unsigned int);
 bool 

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Refine the condition for add additional vars in RVV cost model

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:48b653eb14f8bde7772cf1f2d674bdd9c75302bd

commit 48b653eb14f8bde7772cf1f2d674bdd9c75302bd
Author: demin.han 
Date:   Tue Mar 26 16:52:12 2024 +0800

RISC-V: Refine the condition for add additional vars in RVV cost model

The adjacent_dr_p is sufficient and unnecessary condition for contiguous 
access.
So unnecessary live-ranges are added and result in smaller LMUL.

This patch uses MEMORY_ACCESS_TYPE as condition and constrains segment
load/store.

Tested on RV64 and no regression.

PR target/114506

gcc/ChangeLog:

* config/riscv/riscv-vector-costs.cc 
(non_contiguous_memory_access_p): Rename
(need_additional_vector_vars_p): Rename and refine condition

gcc/testsuite/ChangeLog:

* gcc.dg/vect/costmodel/riscv/rvv/pr114506.c: New test.

Signed-off-by: demin.han 
(cherry picked from commit ca2f531cc5db4f1020d4329976610356033e0246)

Diff:
---
 gcc/config/riscv/riscv-vector-costs.cc | 23 ++
 .../gcc.dg/vect/costmodel/riscv/rvv/pr114506.c | 23 ++
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-costs.cc 
b/gcc/config/riscv/riscv-vector-costs.cc
index d27bb68a7b92..4582b0db4250 100644
--- a/gcc/config/riscv/riscv-vector-costs.cc
+++ b/gcc/config/riscv/riscv-vector-costs.cc
@@ -563,14 +563,24 @@ get_store_value (gimple *stmt)
 return gimple_assign_rhs1 (stmt);
 }
 
-/* Return true if it is non-contiguous load/store.  */
+/* Return true if addtional vector vars needed.  */
 static bool
-non_contiguous_memory_access_p (stmt_vec_info stmt_info)
+need_additional_vector_vars_p (stmt_vec_info stmt_info)
 {
   enum stmt_vec_info_type type
 = STMT_VINFO_TYPE (vect_stmt_to_vectorize (stmt_info));
-  return ((type == load_vec_info_type || type == store_vec_info_type)
- && !adjacent_dr_p (STMT_VINFO_DATA_REF (stmt_info)));
+  if (type == load_vec_info_type || type == store_vec_info_type)
+{
+  if (STMT_VINFO_GATHER_SCATTER_P (stmt_info)
+ && STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) == VMAT_GATHER_SCATTER)
+   return true;
+
+  machine_mode mode = TYPE_MODE (STMT_VINFO_VECTYPE (stmt_info));
+  int lmul = riscv_get_v_regno_alignment (mode);
+  if (DR_GROUP_SIZE (stmt_info) * lmul > RVV_M8)
+   return true;
+}
+  return false;
 }
 
 /* Return the LMUL of the current analysis.  */
@@ -739,10 +749,7 @@ update_local_live_ranges (
  stmt_vec_info stmt_info = vinfo->lookup_stmt (gsi_stmt (si));
  enum stmt_vec_info_type type
= STMT_VINFO_TYPE (vect_stmt_to_vectorize (stmt_info));
- if (non_contiguous_memory_access_p (stmt_info)
- /* LOAD_LANES/STORE_LANES doesn't need a perm indice.  */
- && STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info)
-  != VMAT_LOAD_STORE_LANES)
+ if (need_additional_vector_vars_p (stmt_info))
{
  /* For non-adjacent load/store STMT, we will potentially
 convert it into:
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114506.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114506.c
new file mode 100644
index ..a88d24b2d2d4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114506.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize 
-mrvv-max-lmul=dynamic -fdump-tree-vect-details" } */
+
+float a[32000], b[32000], c[32000], d[32000];
+float aa[256][256], bb[256][256], cc[256][256];
+
+void
+s2275 ()
+{
+  for (int i = 0; i < 256; i++)
+{
+  for (int j = 0; j < 256; j++)
+   {
+ aa[j][i] = aa[j][i] + bb[j][i] * cc[j][i];
+   }
+  a[i] = b[i] + c[i] * d[i];
+}
+}
+
+/* { dg-final { scan-assembler-times {e32,m8} 1 } } */
+/* { dg-final { scan-assembler-not {e32,m4} } } */
+/* { dg-final { scan-assembler-not {csrr} } } */
+/* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Fix parsing of Zic* extensions

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:cd78056ad4b3b8a27b3e17dd29dc81d3e28c7719

commit cd78056ad4b3b8a27b3e17dd29dc81d3e28c7719
Author: Christoph Müllner 
Date:   Mon Apr 29 00:46:06 2024 +0200

RISC-V: Fix parsing of Zic* extensions

The extension parsing table entries for a range of Zic* extensions
does not match the mask definition in riscv.opt.
This results in broken TARGET_ZIC* macros, because the values of
riscv_zi_subext and riscv_zicmo_subext are set wrong.

This patch fixes this by moving Zic64b into riscv_zicmo_subext
and all other affected Zic* extensions to riscv_zi_subext.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: Move ziccamoa, ziccif,
zicclsm, and ziccrse into riscv_zi_subext.
* config/riscv/riscv.opt: Define MASK_ZIC64B for
riscv_ziccmo_subext.

Signed-off-by: Christoph Müllner 
(cherry picked from commit 285300eb928b171236e895f28c960ad02dcb0d67)

Diff:
---
 gcc/common/config/riscv/riscv-common.cc | 8 
 gcc/config/riscv/riscv.opt  | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 43b7549e3ec5..8cc0e727737e 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -1638,15 +1638,15 @@ static const riscv_ext_flag_table_t 
riscv_ext_flag_table[] =
 
   {"zihintntl", _options::x_riscv_zi_subext, MASK_ZIHINTNTL},
   {"zihintpause", _options::x_riscv_zi_subext, MASK_ZIHINTPAUSE},
+  {"ziccamoa", _options::x_riscv_zi_subext, MASK_ZICCAMOA},
+  {"ziccif", _options::x_riscv_zi_subext, MASK_ZICCIF},
+  {"zicclsm", _options::x_riscv_zi_subext, MASK_ZICCLSM},
+  {"ziccrse", _options::x_riscv_zi_subext, MASK_ZICCRSE},
 
   {"zicboz", _options::x_riscv_zicmo_subext, MASK_ZICBOZ},
   {"zicbom", _options::x_riscv_zicmo_subext, MASK_ZICBOM},
   {"zicbop", _options::x_riscv_zicmo_subext, MASK_ZICBOP},
   {"zic64b", _options::x_riscv_zicmo_subext, MASK_ZIC64B},
-  {"ziccamoa", _options::x_riscv_zicmo_subext, MASK_ZICCAMOA},
-  {"ziccif", _options::x_riscv_zicmo_subext, MASK_ZICCIF},
-  {"zicclsm", _options::x_riscv_zicmo_subext, MASK_ZICCLSM},
-  {"ziccrse", _options::x_riscv_zicmo_subext, MASK_ZICCRSE},
 
   {"zve32x",   _options::x_target_flags, MASK_VECTOR},
   {"zve32f",   _options::x_target_flags, MASK_VECTOR},
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index b14888e9816c..ee824756381b 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -237,8 +237,6 @@ Mask(ZIHINTPAUSE) Var(riscv_zi_subext)
 
 Mask(ZICOND)  Var(riscv_zi_subext)
 
-Mask(ZIC64B)  Var(riscv_zi_subext)
-
 Mask(ZICCAMOA)Var(riscv_zi_subext)
 
 Mask(ZICCIF)  Var(riscv_zi_subext)
@@ -390,6 +388,8 @@ Mask(ZICBOM) Var(riscv_zicmo_subext)
 
 Mask(ZICBOP) Var(riscv_zicmo_subext)
 
+Mask(ZIC64B) Var(riscv_zicmo_subext)
+
 TargetVariable
 int riscv_zf_subext


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Add -X to link spec

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:96a6647f966a7ec24d07f2960956c71c1ca320c3

commit 96a6647f966a7ec24d07f2960956c71c1ca320c3
Author: Fangrui Song 
Date:   Fri Apr 26 18:14:33 2024 -0700

RISC-V: Add -X to link spec

--discard-locals (-X) instructs the linker to remove local .L* symbols,
which occur a lot due to label differences for linker relaxation. The
arm port has a similar need and passes -X to ld.

In contrast, the RISC-V port does not pass -X to ld and rely on the
default --discard-locals in GNU ld's riscv port. The arm way is more
conventional (compiler driver instead of the linker customizes the
default linker behavior) and works with lld.

gcc/ChangeLog:

* config/riscv/elf.h (LINK_SPEC): Add -X.
* config/riscv/freebsd.h (LINK_SPEC): Add -X.
* config/riscv/linux.h (LINK_SPEC): Add -X.

Diff:
---
 gcc/config/riscv/elf.h | 1 +
 gcc/config/riscv/freebsd.h | 1 +
 gcc/config/riscv/linux.h   | 1 +
 3 files changed, 3 insertions(+)

diff --git a/gcc/config/riscv/elf.h b/gcc/config/riscv/elf.h
index f533764d9f86..c97f13c0ccad 100644
--- a/gcc/config/riscv/elf.h
+++ b/gcc/config/riscv/elf.h
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #define LINK_SPEC "\
 -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv \
 %{mno-relax:--no-relax} \
+-X \
 %{mbig-endian:-EB} \
 %{mlittle-endian:-EL} \
 %{shared}"
diff --git a/gcc/config/riscv/freebsd.h b/gcc/config/riscv/freebsd.h
index bd08a9852850..5dd4d51c42bc 100644
--- a/gcc/config/riscv/freebsd.h
+++ b/gcc/config/riscv/freebsd.h
@@ -44,6 +44,7 @@ along with GCC; see the file COPYING3.  If not see
   %{p:%nconsider using `-pg' instead of `-p' with gprof (1)}   \
   %{v:-V}  \
   %{assert*} %{R*} %{rpath*} %{defsym*}\
+  -X   \
   %{mbig-endian:-EB}   \
   %{mlittle-endian:-EL}\
   %{shared:-Bshareable %{h*} %{soname*}}   \
diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
index 15851f653bc6..3c356227134d 100644
--- a/gcc/config/riscv/linux.h
+++ b/gcc/config/riscv/linux.h
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 #define LINK_SPEC "\
 -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv" LD_EMUL_SUFFIX " \
 %{mno-relax:--no-relax} \
+-X \
 %{mbig-endian:-EB} \
 %{mlittle-endian:-EL} \
 %{shared} \


[gcc/riscv/heads/gcc-14-with-riscv-opts] (40 commits) [RISC-V] [PATCH v2] Enable inlining str* by default

2024-05-07 Thread Jeff Law via Gcc-cvs
The branch 'riscv/heads/gcc-14-with-riscv-opts' was updated to point to:

 8b5321bc863b... [RISC-V] [PATCH v2] Enable inlining str* by default

It previously pointed to:

 af8ad1d874dc... [committed][RISC-V] Fix nearbyint failure on rv32 and forma

Diff:

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

  af8ad1d... [committed][RISC-V] Fix nearbyint failure on rv32 and forma
  8ff2586... [RFA][RISC-V] Improve constant synthesis for constants with
  951478a... [committed] [RISC-V] Don't run new rounding tests on newlib
  990fa14... [committed] [RISC-V] Trivial pattern cleanup
  b00f722... [committed] [RISC-V] Fix detection of store pair fusion cas
  ece3a75... This is almost exclusively Jivan's work.  His original post
  5009e02... RISC-V: Refine the condition for add additional vars in RVV
  7cae858... RISC-V: Fix parsing of Zic* extensions
  355f858... RISC-V: Add -X to link spec


Summary of changes (added commits):
---

  8b5321b... [RISC-V] [PATCH v2] Enable inlining str* by default
  c396fa6... [PATCH 1/1] RISC-V: Add Zfbfmin extension to the -march= op
  cd0e329... RISC-V: Add testcase for PR114749.
  af9ec7b... [RISC-V] Add support for _Bfloat16
  6b0b012... RISC-V: Document -mcmodel=large
  3ccf8a5... So another constant synthesis improvement.
  3d0f38b... RISC-V: miscll comment fixes [NFC]
  9ba5c71... [committed][RISC-V] Fix nearbyint failure on rv32 and forma
  0099c20... [RFA][RISC-V] Improve constant synthesis for constants with
  63c91bf... [committed] [RISC-V] Don't run new rounding tests on newlib
  1985c80... [committed] [RISC-V] Trivial pattern cleanup
  305a5d2... [committed] [RISC-V] Fix detection of store pair fusion cas
  7fd192a... This is almost exclusively Jivan's work.  His original post
  48b653e... RISC-V: Refine the condition for add additional vars in RVV
  cd78056... RISC-V: Fix parsing of Zic* extensions
  96a6647... RISC-V: Add -X to link spec
  23cf010... libgomp: Add gfx90c, 1036 and 1103 declare variant tests (*)
  a1c8ae1... gimple-ssa-sprintf: Use [0, 1] range for %lc with (wint_t)  (*)
  390bd23... c++/modules: imported spec befriending class tmpl [PR114889 (*)
  c6141ad... AVR: ipa/92606 - Don't optimize PROGMEM data against non-PR (*)
  43b730b... Bump BASE-VER (*)
  cd0059a... Update ChangeLog and version files for release (*)
  4f12e06... Update gennews for GCC 14. (*)
  308a39c... Daily bump. (*)
  c7b4305... testsuite: c++: Skip g++.dg/analyzer on Solaris [PR111475] (*)
  765ddff... Daily bump. (*)
  43b7e2f... Daily bump. (*)
  532d775... Daily bump. (*)
  d811080... [PATCH] PR modula2/114929 for loop fails to iterate down to (*)
  3b4d6b6... c++: initializer_list and EH [PR114935] (*)
  db447ec... Revert "tree-optimization/114921 - _Float16 -> __bf16 isn't (*)
  d7c06a8... libstdc++: Update powerpc-linux-gnu baseline_symbols (*)
  7963194... RISC-V: Add testcase for pr114734 (*)
  5c42872... middle-end/114734 - wrong code with expand_call_mem_ref (*)
  242fbc0... cfgrtl: Fix MEM_EXPR update in duplicate_insn_chain [PR1149 (*)
  fa7e05d... tree-optimization/114921 - _Float16 -> __bf16 isn't noop (*)
  f86f197... Daily bump. (*)
  8e39d4f... Regenerate gcc.pot (*)
  590a065... Daily bump. (*)
  9ccb16d... Daily bump. (*)

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


[gcc r15-299] [RISC-V] [PATCH v2] Enable inlining str* by default

2024-05-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:1139f38e798181572121657e5b267a9698edb62f

commit r15-299-g1139f38e798181572121657e5b267a9698edb62f
Author: Jeff Law 
Date:   Tue May 7 11:43:09 2024 -0600

[RISC-V] [PATCH v2] Enable inlining str* by default

So with Chrstoph's patches from late 2022 we've had the ability to inline
strlen, and str[n]cmp (scalar).  However, we never actually turned this
capability on by default!

This patch flips the those default to allow inlinining by default.  It also
fixes one bug exposed by our internal testing when NBYTES is zero for 
strncmp.
I don't think that case happens enough to try and optimize it, we just 
disable
inline expansion for that instance.

This has been bootstrapped and regression tested on rv64gc at various times 
as
well as cross tested on rv64gc more times than I can probably count (we've 
have
this patch internally for a while).  More importantly, I just successfully
tested it on rv64gc and rv32gcv elf configurations with the trunk

gcc/

* config/riscv/riscv-string.cc (riscv_expand_strcmp): Do not inline
strncmp with zero size.
(emit_strcmp_scalar_compare_subword): Adjust rotation for rv32 vs 
rv64.
* config/riscv/riscv.opt (var_inline_strcmp): Enable by default.
(vriscv_inline_strncmp, riscv_inline_strlen): Likewise.

gcc/testsuite

* gcc.target/riscv/zbb-strlen-disabled-2.c: Turn off inlining.

Diff:
---
 gcc/config/riscv/riscv-string.cc   | 9 -
 gcc/config/riscv/riscv.opt | 6 +++---
 gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c | 4 ++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc
index b09b51d7526b..41cb061c746d 100644
--- a/gcc/config/riscv/riscv-string.cc
+++ b/gcc/config/riscv/riscv-string.cc
@@ -153,7 +153,7 @@ emit_strcmp_scalar_compare_subword (rtx data1, rtx data2, 
rtx orc1,
   rtx imask = gen_rtx_CONST_INT (Xmode, im);
   rtx m_reg = gen_reg_rtx (Xmode);
   emit_insn (gen_rtx_SET (m_reg, imask));
-  do_rotr3 (m_reg, m_reg, GEN_INT (64 - cmp_bytes * BITS_PER_UNIT));
+  do_rotr3 (m_reg, m_reg, GEN_INT (BITS_PER_WORD - cmp_bytes * BITS_PER_UNIT));
   do_and3 (data1, m_reg, data1);
   do_and3 (data2, m_reg, data2);
   if (TARGET_ZBB)
@@ -497,6 +497,13 @@ riscv_expand_strcmp (rtx result, rtx src1, rtx src2,
return false;
   nbytes = UINTVAL (bytes_rtx);
 
+  /* If NBYTES is zero the result of strncmp will always be zero,
+but that would require special casing in the caller.  So for
+now just don't do an inline expansion.  This probably rarely
+happens in practice, but it is tested by the testsuite.  */
+  if (nbytes == 0)
+   return false;
+
   /* We don't emit parts of a strncmp() call.  */
   if (nbytes > compare_max)
return false;
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 7cca1c4aab20..1252834aec5b 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -517,15 +517,15 @@ Target Var(TARGET_INLINE_SUBWORD_ATOMIC) Init(1)
 Always inline subword atomic operations.
 
 minline-strcmp
-Target Var(riscv_inline_strcmp) Init(0)
+Target Var(riscv_inline_strcmp) Init(1)
 Inline strcmp calls if possible.
 
 minline-strncmp
-Target Var(riscv_inline_strncmp) Init(0)
+Target Var(riscv_inline_strncmp) Init(1)
 Inline strncmp calls if possible.
 
 minline-strlen
-Target Var(riscv_inline_strlen) Init(0)
+Target Var(riscv_inline_strlen) Init(1)
 Inline strlen calls if possible.
 
 -param=riscv-strcmp-inline-limit=
diff --git a/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c 
b/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c
index a481068aa0c7..1295aeb0086e 100644
--- a/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c
+++ b/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c
@@ -1,6 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv32gc_zbb" { target { rv32 } } } */
-/* { dg-options "-march=rv64gc_zbb" { target { rv64 } } } */
+/* { dg-options "-mno-inline-strlen -march=rv32gc_zbb" { target { rv32 } } } */
+/* { dg-options "-mno-inline-strlen -march=rv64gc_zbb" { target { rv64 } } } */
 /* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
 
 typedef long unsigned int size_t;


[gcc/devel/rust/master] borrowck: Build Polonius automatically

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ab8b4cc38806e1a7190a7426ce073951752d1a60

commit ab8b4cc38806e1a7190a7426ce073951752d1a60
Author: Jakub Dupak 
Date:   Wed Feb 28 00:08:01 2024 +0100

borrowck: Build Polonius automatically

This is minimalistic version to build Polonius with Cargo.

gcc/rust/ChangeLog:

* Make-lang.in: Build Polonius.

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/Make-lang.in | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 74663379487d..3275015b0466 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -266,6 +266,7 @@ rust.srcman:
 # Clean hooks.
 
 rust.mostlyclean:
+   rm -rf rust/ffi-polonius/release libffi_polonius.a
 #  cd $(srcdir)/rust; rm -f *.o y.tab.h y.tab.c lex.yy.c
 
 rust.clean: rust.mostlyclean
@@ -487,3 +488,9 @@ rust/%.o: rust/checks/errors/borrowck/%.cc
 rust/%.o: rust/metadata/%.cc
$(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
$(POSTCOMPILE)
+
+rust/libffi_polonius.a: \
+   rust/checks/errors/borrowck/ffi-polonius/Cargo.toml \
+   $(wildcard $(srcdir)/rust/checks/errors/borrowck/ffi-polonius/src/*)
+   cargo build --manifest-path 
$(srcdir)/rust/checks/errors/borrowck/ffi-polonius/Cargo.toml --release 
--target-dir rust/ffi-polonius
+   cp rust/ffi-polonius/release/libffi_polonius.a rust/libffi_polonius.a
\ No newline at end of file


[gcc/devel/rust/master] Pin macos CI to version 13

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ba8ce7e66ca145004810f50246872902baf95ba0

commit ba8ce7e66ca145004810f50246872902baf95ba0
Author: Pierre-Emmanuel Patry 
Date:   Tue Apr 30 13:16:36 2024 +0200

Pin macos CI to version 13

Latest macos environment runs on arm and is thus
incompatible with gcc.

ChangeLog:

* .github/workflows/ccpp.yml: Pin macos runner
version.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 .github/workflows/ccpp.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml
index 1955a03ab094..3381ec80d689 100644
--- a/.github/workflows/ccpp.yml
+++ b/.github/workflows/ccpp.yml
@@ -253,7 +253,7 @@ jobs:
   CC: clang
   CXX: clang++
 
-runs-on: macos-latest
+runs-on: macos-13
 
 steps:
 - uses: actions/checkout@v3


[gcc/devel/rust/master] borrowck: Polonius error reporting

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a926ad27cda683dd32fb3a6d2c809af13d418cce

commit a926ad27cda683dd32fb3a6d2c809af13d418cce
Author: Jakub Dupak 
Date:   Wed Feb 28 00:01:28 2024 +0100

borrowck: Polonius error reporting

gcc/rust/ChangeLog:

* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi_generated.rs: 
Error reporting.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Error reporting.
* checks/errors/borrowck/polonius/rust-polonius-ffi.h (struct 
FactsView):
Error reporting.
(struct Output): Error reporting.
* checks/errors/borrowck/polonius/rust-polonius.h (struct Facts): 
Error reporting.
* checks/errors/borrowck/rust-borrow-checker.cc: Error reporting.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../ffi-polonius/src/gccrs_ffi_generated.rs|   8 ++
 .../checks/errors/borrowck/ffi-polonius/src/lib.rs | 115 +++--
 .../errors/borrowck/polonius/rust-polonius-ffi.h   |   7 ++
 .../errors/borrowck/polonius/rust-polonius.h   |   3 +-
 .../checks/errors/borrowck/rust-borrow-checker.cc  |  21 +++-
 5 files changed, 117 insertions(+), 37 deletions(-)

diff --git 
a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi_generated.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi_generated.rs
index 209081795289..db75a1d1509d 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi_generated.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi_generated.rs
@@ -48,3 +48,11 @@ pub struct FactsView {
 pub known_placeholder_subset: Slice>,
 pub placeholder: Slice>,
 }
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct Output {
+pub loan_errors: bool,
+pub subset_errors: bool,
+pub move_errors: bool,
+}
diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
index 819c34a93749..085b6a0b5188 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
@@ -86,48 +86,95 @@ fn print_point(point: GccrsAtom) {
 let val: usize = point.into();
 let mid = val % 2 == 1;
 let bb = val >> 16;
-let stmt = (val >> 1) & 0x;
-print!("{}(bb{}[{}])", if mid { "Mid" } else { "Start" }, bb, stmt);
+let stmt = (val >> 1) & ((1 << 15) - 1);
+eprint!("{}(bb{}[{}])", if mid { "Mid" } else { "Start" }, bb, stmt);
 }
 
 /// Run the polonius analysis on the given facts (for a single function).
 /// Right now, results are only printed and not propagated back to the gccrs.
 #[no_mangle]
-pub unsafe extern "C" fn polonius_run(input: gccrs_ffi::FactsView, 
dump_enabled: bool) {
+pub unsafe extern "C" fn polonius_run(
+input: gccrs_ffi::FactsView,
+dump_enabled: bool,
+) -> gccrs_ffi::Output {
 let facts = AllFactsfrom(input);
-let output = Output::compute(, polonius_engine::Algorithm::Naive, 
dump_enabled);
-
-// FIXME: Temporary output
-println!("Polonius analysis completed. Results:");
-println!("Errors: {:#?}", output.errors);
-println!("Subset error: {:#?}", output.subset_errors);
-println!("Move error: {:#?}", output.move_errors);
-
-println!("Subsets:");
-let mut subset_vec: Vec<_> = output.subset.iter().collect();
-subset_vec.sort_by_key(|&(point, _)| point);
-for (point, subsets) in subset_vec {
-print_point(*point);
-println!(": {{");
-for (, rhss) in subsets {
-for  in rhss {
-println!("{} <= {}", usize::from(lhs), usize::from(rhs));
+let output = Output::compute(
+,
+polonius_engine::Algorithm::DatafrogOpt,
+dump_enabled,
+);
+
+if dump_enabled {
+eprintln!("Subsets:");
+let mut subset_vec: Vec<_> = output.subset.iter().collect();
+subset_vec.sort_by_key(|&(point, _)| point);
+for (point, subsets) in subset_vec {
+print_point(*point);
+eprintln!(": {{");
+for (, rhss) in subsets {
+for  in rhss {
+eprintln!("{} <= {}", usize::from(lhs), 
usize::from(rhs));
+}
 }
+eprintln!("}}");
 }
-println!("}}");
-}
-println!("Subset anywhere: {:#?}", output.subset_anywhere);
-
-// Print origin live on entry
-println!("Origin live on entry:");
-let mut origin_vec: Vec<_> = output.origin_live_on_entry.iter().collect();
-origin_vec.sort_by_key(|&(point, _)| point);
-for (point, origins) in origin_vec {
-print_point(*point);
-println!(": {{");
-for  in origins {
-println!("{}", usize::from(origin));
+
+// Print origin live on entry
+eprintln!("Origin live on entry:");
+let mut origin_vec: Vec<_> = 
output.origin_live_on_entry.iter().collect();
+origin_vec.sort_by_key(|&(point, _)| 

[gcc/devel/rust/master] Remove redundant macro definition

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:fa86c37a57696b9dba2d1553dbe9e913865f4209

commit fa86c37a57696b9dba2d1553dbe9e913865f4209
Author: zhanghe9702 
Date:   Sun Mar 24 16:48:56 2024 +0800

Remove redundant macro definition

gcc/rust/ChangeLog:
* backend/rust-tree.h: removing the CLASSTYPE_VBASECLASSES macro
which is duplicated three times.

Signed-off-by: Zhang He 

Diff:
---
 gcc/rust/backend/rust-tree.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/gcc/rust/backend/rust-tree.h b/gcc/rust/backend/rust-tree.h
index 26c8b653ac64..2e231cad5e14 100644
--- a/gcc/rust/backend/rust-tree.h
+++ b/gcc/rust/backend/rust-tree.h
@@ -139,12 +139,6 @@
should be initialized.)  */
 #define CLASSTYPE_VBASECLASSES(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->vbases)
 
-/* A vector of BINFOs for the direct and indirect virtual base classes
-   that this type uses in a post-order depth-first left-to-right
-   order.  (In other words, these bases appear in the order that they
-   should be initialized.)  */
-#define CLASSTYPE_VBASECLASSES(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->vbases)
-
 /* We used to have a variant type for lang_type.  Keep the name of the
checking accessor for the sole survivor.  */
 #define LANG_TYPE_CLASS_CHECK(NODE) (TYPE_LANG_SPECIFIC (NODE))
@@ -783,12 +777,6 @@ extern GTY (()) tree cp_global_trees[CPTI_MAX];
 #define CLASSTYPE_PRIMARY_BINFO(NODE)  
\
   (LANG_TYPE_CLASS_CHECK (NODE)->primary_base)
 
-/* A vector of BINFOs for the direct and indirect virtual base classes
-   that this type uses in a post-order depth-first left-to-right
-   order.  (In other words, these bases appear in the order that they
-   should be initialized.)  */
-#define CLASSTYPE_VBASECLASSES(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->vbases)
-
 /* The type corresponding to NODE when NODE is used as a base class,
i.e., NODE without virtual base classes or tail padding.  */
 #define CLASSTYPE_AS_BASE(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->as_base)


[gcc/devel/rust/master] chore: Fix Remark CI

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a24871e1bdea1b1f9fff2a737820214db6528a14

commit a24871e1bdea1b1f9fff2a737820214db6528a14
Author: Arthur Cohen 
Date:   Fri Apr 12 17:10:40 2024 +0200

chore: Fix Remark CI

ChangeLog:

* CONTRIBUTING.md: Fix invalid line length.
* README.md: Likewise.

Diff:
---
 CONTRIBUTING.md | 6 --
 README.md   | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 75812a657a30..98cd8894ad68 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -4,7 +4,8 @@
 
 * **Ensure the bug was not already reported** by searching on GitHub under 
[Issues](https://github.com/Rust-GCC/gccrs/issues).
 
-* If you're unable to find an open issue addressing the problem, [open a new 
one](https://github.com/Rust-GCC/gccrs/issues/new).
+* If you're unable to find an open issue addressing the problem,
+  [open a new one](https://github.com/Rust-GCC/gccrs/issues/new).
   Be sure to include a **title and clear description**, as much relevant 
information as possible, and a **code sample**
   or an **executable test case** demonstrating the expected behavior that is 
not occurring.
 
@@ -15,7 +16,8 @@
 * Ensure the PR description clearly describes the problem and solution. 
Include the relevant issue number if applicable.
 
 * Before submitting, GCC development requires copyright assignment or the 
Developer's Certificate of Origin sign-off.
-   Please see the [Contributing to GCC](https://gcc.gnu.org/contribute.html) 
guide or [Developer's Certificate of Origin (DCO) 
Sign-off](https://gcc.gnu.org/dco.html) guide.
+   Please see the [Contributing to GCC](https://gcc.gnu.org/contribute.html) 
guide or
+  [Developer's Certificate of Origin (DCO) 
Sign-off](https://gcc.gnu.org/dco.html) guide.
 
 * Patches sent to the [`gcc-rust` mailing 
list](https://gcc.gnu.org/mailman/listinfo/gcc-rust) are likewise welcome.
 These will be imported into a GitHub PR to follow the normal review process,
diff --git a/README.md b/README.md
index 2ba59d3a6b24..bd79c4a713c1 100644
--- a/README.md
+++ b/README.md
@@ -217,7 +217,8 @@ If you want to contribute to GCC Rust, you can find more 
information in [CONTRIB
 
 Please be aware this project is designed to be pushed upstream to GCC when we 
reach some milestones,
 and this means we require copyright assignment or the Developer's Certificate 
of Origin sign-off.
-Please see the [Contributing to GCC](https://gcc.gnu.org/contribute.html) 
guide or [Developer's Certificate of Origin (DCO) 
Sign-off](https://gcc.gnu.org/dco.html) guide.
+Please see the [Contributing to GCC](https://gcc.gnu.org/contribute.html) 
guide or
+[Developer's Certificate of Origin (DCO) 
Sign-off](https://gcc.gnu.org/dco.html) guide.
 
 Not all contributions must be code; we would love to see new test cases or 
bugs and issues to be reported.
 Feel free to add any comments on open PRs


[gcc/devel/rust/master] borrowck: Use std::ignore

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:45d5c01fdba6e4c09a3ec4497b9be355bb2db106

commit 45d5c01fdba6e4c09a3ec4497b9be355bb2db106
Author: Jakub Dupak 
Date:   Wed Apr 24 14:32:48 2024 +0200

borrowck: Use std::ignore

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Use std::ignore.

Diff:
---
 .../checks/errors/borrowck/rust-bir-builder-expr-stmt.cc   | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index d64641177d0e..81fa2ea7b043 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -237,7 +237,7 @@ ExprStmtBuilder::visit (HIR::ArrayIndexExpr )
   auto lhs = visit_expr (*expr.get_array_expr ());
   auto rhs = visit_expr (*expr.get_index_expr ());
   // The index is not tracked in BIR.
-  (void) rhs;
+  std::ignore = rhs;
   return_place (
 ctx.place_db.lookup_or_add_path (Place::INDEX, lookup_type (expr), lhs));
 }
@@ -454,7 +454,7 @@ ExprStmtBuilder::visit (HIR::LoopExpr )
 {
   auto loop = setup_loop (expr);
 
-  (void) visit_expr (*expr.get_loop_block ());
+  std::ignore = visit_expr (*expr.get_loop_block ());
   if (!ctx.get_current_bb ().is_terminated ())
 push_goto (loop.continue_bb);
 
@@ -471,7 +471,7 @@ ExprStmtBuilder::visit (HIR::WhileLoopExpr )
   push_switch (cond_val, {body_bb, loop.break_bb});
 
   ctx.current_bb = body_bb;
-  (void) visit_expr (*expr.get_loop_block ());
+  std::ignore = visit_expr (*expr.get_loop_block ());
   push_goto (loop.continue_bb);
 
   ctx.current_bb = loop.break_bb;
@@ -497,7 +497,7 @@ ExprStmtBuilder::visit (HIR::IfExpr )
 
   ctx.current_bb = new_bb ();
   BasicBlockId then_start_block = ctx.current_bb;
-  (void) visit_expr (*expr.get_if_block ());
+  std::ignore = visit_expr (*expr.get_if_block ());
   if (!ctx.get_current_bb ().is_terminated ())
 push_goto (INVALID_BB); // Resolved later.
   BasicBlockId then_end_block = ctx.current_bb;
@@ -525,14 +525,14 @@ ExprStmtBuilder::visit (HIR::IfExprConseqElse )
 
   ctx.current_bb = new_bb ();
   BasicBlockId then_start_bb = ctx.current_bb;
-  (void) visit_expr (*expr.get_if_block (), result);
+  std::ignore = visit_expr (*expr.get_if_block (), result);
   if (!ctx.get_current_bb ().is_terminated ())
 push_goto (INVALID_BB); // Resolved later.
   BasicBlockId then_end_bb = ctx.current_bb;
 
   ctx.current_bb = new_bb ();
   BasicBlockId else_start_bb = ctx.current_bb;
-  (void) visit_expr (*expr.get_else_block (), result);
+  std::ignore = visit_expr (*expr.get_else_block (), result);
   if (!ctx.get_current_bb ().is_terminated ())
 push_goto (INVALID_BB); // Resolved later.
   BasicBlockId else_end_bb = ctx.current_bb;
@@ -658,7 +658,7 @@ ExprStmtBuilder::visit (HIR::LetStmt )
push_user_type_ascription (var, lookup_type (*stmt.get_type ()));
 
   if (stmt.has_init_expr ())
-   (void) visit_expr (*stmt.get_init_expr (), var);
+   std::ignore = visit_expr (*stmt.get_init_expr (), var);
 }
   else
 {


[gcc/devel/rust/master] borrowck: Polonius dump

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:509c286cb0665720550cb88a2628a98d35f1b37e

commit 509c286cb0665720550cb88a2628a98d35f1b37e
Author: Jakub Dupak 
Date:   Tue Feb 27 23:52:53 2024 +0100

borrowck: Polonius dump

gcc/rust/ChangeLog:

* checks/errors/borrowck/polonius/rust-polonius.h (struct 
FullPoint):
Polonius facts dump.
(struct Facts): Polonius facts dump.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go):
Polonius facts dump.
(Dump::visit): Polonius facts dump.
(Dump::visit_place): Polonius facts dump.
(Dump::visit_move_place): Polonius facts dump.
(Dump::visit_scope): Polonius facts dump.
* checks/errors/borrowck/rust-borrow-checker.cc 
(BorrowChecker::go): Polonius facts dump.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/polonius/rust-polonius.h   |  2 +-
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 25 ++--
 .../checks/errors/borrowck/rust-borrow-checker.cc  | 69 +-
 3 files changed, 88 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h 
b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
index 239cc3440117..1534260552b0 100644
--- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
+++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
@@ -148,7 +148,7 @@ struct Facts
   void dump_var_used_at (std::ostream ) const
   {
 for (auto  : var_used_at)
-  os << e.first - 1 << " " << FullPoint (e.second) << "\n";
+  os << e.first << " " << FullPoint (e.second) << "\n";
   }
 
   void dump_var_defined_at (std::ostream ) const
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index d3398b6f405a..03e2b8ea404c 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -115,7 +115,7 @@ Dump::go (bool enable_simplify_cfg)
   if (enable_simplify_cfg)
 simplify_cfg (func, bb_fold_map);
 
-  renumber_places (func, place_map);
+  // renumber_places (func, place_map);
 
   stream << "fn " << name << "(";
   print_comma_separated (stream, func.arguments, [this] (PlaceId place_id) {
@@ -214,6 +214,8 @@ Dump::visit (const Statement )
   visit_place (stmt.get_place ());
   stream << ")";
   break;
+default:
+  rust_internal_error_at (UNKNOWN_LOCATION, "Unknown statement kind.");
 }
   statement_place = INVALID_PLACE;
 }
@@ -251,7 +253,8 @@ Dump::visit_place (PlaceId place_id)
   stream << "const " << get_tyty_name (place.tyty);
   break;
 case Place::INVALID:
-  stream << "_INVALID";
+  if (place_id == INVALID_PLACE)
+   stream << "_INVALID";
 }
 }
 
@@ -259,7 +262,7 @@ void
 Dump::visit_move_place (PlaceId place_id)
 {
   const Place  = func.place_db[place_id];
-  if (!place.is_constant ())
+  if (place.should_be_moved ())
 stream << "move ";
   visit_place (place_id);
 }
@@ -267,7 +270,11 @@ Dump::visit_move_place (PlaceId place_id)
 void
 Dump::visit (const BorrowExpr )
 {
-  stream << "&";
+  stream << "&"
+<< "'?" << expr.get_origin () << " ";
+  if (func.place_db.get_loans ()[expr.get_loan ()].mutability
+  == Mutability::Mut)
+stream << "mut ";
   visit_place (expr.get_place ());
 }
 
@@ -360,7 +367,15 @@ Dump::visit_scope (ScopeId id, size_t depth)
   indent (depth + 1) << "let _";
   stream << place_map[local] << ": "
 << get_tyty_name (func.place_db[local].tyty);
-  stream << ";\n";
+  stream << ";\t";
+
+  stream << "[";
+  print_comma_separated (stream,
+func.place_db[local].regions.get_regions (),
+[this] (FreeRegion region_id) {
+  stream << "'?" << region_id;
+});
+  stream << "]\n";
 }
   for (auto  : scope.children)
 visit_scope (child, (id >= 1) ? depth + 1 : depth);
diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc 
b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
index ae06aadaa5b1..a2351c57eb42 100644
--- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
@@ -18,9 +18,10 @@
 
 #include "rust-borrow-checker.h"
 #include "rust-function-collector.h"
+#include "rust-bir-fact-collector.h"
 #include "rust-bir-builder.h"
 #include "rust-bir-dump.h"
-#include "rust-bir-fact-collector.h"
+#include "polonius/rust-polonius.h"
 
 namespace Rust {
 namespace HIR {
@@ -36,7 +37,7 @@ mkdir_wrapped (const std::string )
 #elif __APPLE__
   ret = mkdir (dirname.c_str (), 0775);
 #endif
-  (void) ret;
+  rust_assert (ret == 0 || errno == EEXIST);
 }
 
 void
@@ -68,6 +69,8 @@ BorrowChecker::go (HIR::Crate )
= mappings->get_crate_name (crate.get_mappings ().get_crate_num (),
 

[gcc/devel/rust/master] Inline 'gcc/rust/Make-lang.in:RUST_LIBDEPS'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e1c80b39a6421e7f68c7ffbed7b1f67a9c60cf93

commit e1c80b39a6421e7f68c7ffbed7b1f67a9c60cf93
Author: Thomas Schwinge 
Date:   Wed Feb 28 23:06:25 2024 +0100

Inline 'gcc/rust/Make-lang.in:RUST_LIBDEPS'

gcc/rust/
* Make-lang.in (RUST_LIBDEPS): Inline into all users.

Diff:
---
 gcc/rust/Make-lang.in | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index d2ab626d3939..862dbf6a8791 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -228,10 +228,8 @@ rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 LIBPROC_MACRO_INTERNAL = 
../libgrust/libproc_macro_internal/libproc_macro_internal.a
 LIBFORMAT_PARSER = rust/libformat_parser.a
 
-RUST_LIBDEPS = $(LIBDEPS) $(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER)
-
 # The compiler itself is called crab1
-crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(RUST_LIBDEPS) 
$(rust.prev)
+crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(rust.prev)
@$(call LINK_PROGRESS,$(INDEX.rust),start)
+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
  $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(BACKENDLIBS)


[gcc/devel/rust/master] Remove unnecessary SIDE_EFFECTS/READONLY macros

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:3a31617b48a4840b0aa90726333e4e7dedf1493b

commit 3a31617b48a4840b0aa90726333e4e7dedf1493b
Author: Mael Cravero 
Date:   Tue Apr 30 12:04:50 2024 +0200

Remove unnecessary SIDE_EFFECTS/READONLY macros

Closes #2357

gcc/rust/ChangeLog:

* rust-gcc.cc: remove unnecessary TREE_SIDE_EFFECTS and 
TREE_READONLY
macros used in arithmetic overflow checks.

Signed-off-by: Mael Cravero 

Diff:
---
 gcc/rust/rust-gcc.cc | 17 -
 1 file changed, 17 deletions(-)

diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index f17e19a2dfcf..6f547ee7b9de 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -1149,15 +1149,6 @@ fetch_overflow_builtins (ArithmeticOrLogicalOperator op)
   rust_assert (abort);
   rust_assert (builtin);
 
-  // FIXME: ARTHUR: This is really ugly. The builtin context should take care 
of
-  // that
-  TREE_SIDE_EFFECTS (abort) = 1;
-  TREE_READONLY (abort) = 0;
-
-  // FIXME: ARTHUR: Same here. Remove these!
-  TREE_SIDE_EFFECTS (builtin) = 1;
-  TREE_READONLY (builtin) = 0;
-
   return {abort, builtin};
 }
 
@@ -1192,10 +1183,6 @@ arithmetic_or_logical_expression_checked 
(ArithmeticOrLogicalOperator op,
 
   auto abort_call = build_call_expr_loc (location, abort, 0);
 
-  // FIXME: ARTHUR: Is that needed?
-  TREE_SIDE_EFFECTS (abort_call) = 1;
-  TREE_READONLY (abort_call) = 0;
-
   auto builtin_call
 = build_call_expr_loc (location, builtin, 3, left, right, result_ref);
   auto overflow_check
@@ -1205,10 +1192,6 @@ arithmetic_or_logical_expression_checked 
(ArithmeticOrLogicalOperator op,
   auto if_block = build3_loc (location, COND_EXPR, void_type_node,
  overflow_check, abort_call, NULL_TREE);
 
-  // FIXME: ARTHUR: Needed?
-  TREE_SIDE_EFFECTS (if_block) = 1;
-  TREE_READONLY (if_block) = 0;
-
   return if_block;
 }


[gcc/devel/rust/master] Add 'gcc/rust/Make-lang.in:LIBFORMAT_PARSER'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:fb9ff2f1550c3317628e4d8c9602f8b65c527865

commit fb9ff2f1550c3317628e4d8c9602f8b65c527865
Author: Thomas Schwinge 
Date:   Wed Feb 28 22:51:24 2024 +0100

Add 'gcc/rust/Make-lang.in:LIBFORMAT_PARSER'

... to avoid verbatim repetition.

gcc/rust/
* Make-lang.in (LIBPROC_MACRO_INTERNAL): New.
(RUST_LIBDEPS, crab1$(exeext), rust/libformat_parser.a): Use it.

Diff:
---
 gcc/rust/Make-lang.in | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 6c34c7cb9070..d2ab626d3939 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -226,14 +226,15 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
 LIBPROC_MACRO_INTERNAL = 
../libgrust/libproc_macro_internal/libproc_macro_internal.a
+LIBFORMAT_PARSER = rust/libformat_parser.a
 
-RUST_LIBDEPS = $(LIBDEPS) $(LIBPROC_MACRO_INTERNAL) rust/libformat_parser.a
+RUST_LIBDEPS = $(LIBDEPS) $(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER)
 
 # The compiler itself is called crab1
 crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(RUST_LIBDEPS) 
$(rust.prev)
@$(call LINK_PROGRESS,$(INDEX.rust),start)
+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
- $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) 
$(LIBPROC_MACRO_INTERNAL) rust/libformat_parser.a $(BACKENDLIBS)
+ $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(BACKENDLIBS)
@$(call LINK_PROGRESS,$(INDEX.rust),end)
 
 # Build hooks.
@@ -423,7 +424,7 @@ rust/%.o: rust/lex/%.cc
echo $@
 
 # TODO: Improve `cargo` invocation with host specific flags, possibly creating 
a $(CARGO) variable?
-rust/libformat_parser.a: $(srcdir)/../libgrust/libformat_parser/Cargo.toml 
$(wildcard $(srcdir)/../libgrust/libformat_parser/src/*.rs)
+$(LIBFORMAT_PARSER): $(srcdir)/../libgrust/libformat_parser/Cargo.toml 
$(wildcard $(srcdir)/../libgrust/libformat_parser/src/*.rs)
cd $(srcdir)/../libgrust/libformat_parser && cargo build --offline  # 
FIXME: Not always release, right?
cp 
$(srcdir)/../libgrust/libformat_parser/target/debug/liblibformat_parser.a $@


[gcc/devel/rust/master] borrowck: Testsuite

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:35e028f58c18876a8286745ac628bdc882818ead

commit 35e028f58c18876a8286745ac628bdc882818ead
Author: Jakub Dupak 
Date:   Wed Apr 24 13:47:20 2024 +0200

borrowck: Testsuite

gcc/testsuite/ChangeLog:

* rust/borrowck/borrowck.exp: New test.
* rust/borrowck/position_dependant_outlives.rs: New test.
* rust/borrowck/reference.rs: New test.
* rust/borrowck/return_ref_to_local.rs: New test.
* rust/borrowck/subset.rs: New test.
* rust/borrowck/test_move.rs: New test.
* rust/borrowck/test_move_behind_reference.rs: New test.
* rust/borrowck/test_move_conditional.rs: New test.
* rust/borrowck/tmp.rs: New test.
* rust/borrowck/use_while_mut.rs: New test.
* rust/borrowck/use_while_mut_fr.rs: New test.
* rust/borrowck/well_formed_function_inputs.rs: New test.

Diff:
---
 gcc/testsuite/rust/borrowck/borrowck.exp   | 35 
 .../rust/borrowck/position_dependant_outlives.rs   | 11 +++
 gcc/testsuite/rust/borrowck/reference.rs   | 99 ++
 gcc/testsuite/rust/borrowck/return_ref_to_local.rs |  6 ++
 gcc/testsuite/rust/borrowck/subset.rs  | 27 ++
 gcc/testsuite/rust/borrowck/test_move.rs   | 16 
 .../rust/borrowck/test_move_behind_reference.rs| 27 ++
 .../rust/borrowck/test_move_conditional.rs | 28 ++
 gcc/testsuite/rust/borrowck/tmp.rs | 79 +
 gcc/testsuite/rust/borrowck/use_while_mut.rs   |  7 ++
 gcc/testsuite/rust/borrowck/use_while_mut_fr.rs|  8 ++
 .../rust/borrowck/well_formed_function_inputs.rs   | 16 
 12 files changed, 359 insertions(+)

diff --git a/gcc/testsuite/rust/borrowck/borrowck.exp 
b/gcc/testsuite/rust/borrowck/borrowck.exp
new file mode 100644
index ..6e96a7d11d87
--- /dev/null
+++ b/gcc/testsuite/rust/borrowck/borrowck.exp
@@ -0,0 +1,35 @@
+# Copyright (C) 2021-2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Compile tests, no torture testing.
+#
+# These tests raise errors in the front end; torture testing doesn't apply.
+
+# Load support procs.
+load_lib rust-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+set saved-dg-do-what-default ${dg-do-what-default}
+
+set dg-do-what-default "compile"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.rs]] "" ""
+set dg-do-what-default ${saved-dg-do-what-default}
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/rust/borrowck/position_dependant_outlives.rs 
b/gcc/testsuite/rust/borrowck/position_dependant_outlives.rs
new file mode 100644
index ..7856934a6b36
--- /dev/null
+++ b/gcc/testsuite/rust/borrowck/position_dependant_outlives.rs
@@ -0,0 +1,11 @@
+// { dg-additional-options "-frust-compile-until=compilation 
-frust-borrowcheck" }
+
+pub fn position_dependent_outlives<'a>(x: &'a mut i32, cond: bool) -> &'a mut 
i32 {
+let y =  *x;
+if cond {
+return y;
+} else {
+*x = 0;
+return x;
+}
+}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/borrowck/reference.rs 
b/gcc/testsuite/rust/borrowck/reference.rs
new file mode 100644
index ..b825a9686b75
--- /dev/null
+++ b/gcc/testsuite/rust/borrowck/reference.rs
@@ -0,0 +1,99 @@
+// { dg-additional-options "-frust-compile-until=compilation 
-frust-borrowcheck" }
+
+
+#[lang = "sized"]
+pub trait Sized {}
+
+struct Reference<'a> {
+value: &'a i32,
+}
+
+impl<'a> Reference<'a> {
+fn new<'a>(value: &'a i32) -> Reference<'a> {
+Reference { value: value }
+}
+}
+
+struct ReferenceMut<'a> {
+value: &'a mut i32,
+}
+
+impl<'a> ReferenceMut<'a> {
+fn new<'a>(value: &'a mut i32) -> ReferenceMut<'a> {
+ReferenceMut { value: value }
+}
+}
+
+fn immutable_borrow_while_immutable_borrowed_struct() {
+let x = 0;
+let y = Reference::new();
+let z = 
+let w = y;
+}
+
+fn immutable_borrow_while_mutable_borrowed_struct() {
+// { dg-error "Found loan errors in function 
immutable_borrow_while_mutable_borrowed_struct" "" { target *-*-* } .-1 }
+let mut x = 0;
+let y = ReferenceMut::new( x);
+let z =  //~ ERROR
+let w = y;
+}
+
+fn mutable_borrow_while_immutable_borrowed_struct() {
+// { dg-error "Found loan 

[gcc/devel/rust/master] Remove 'libgrust/libproc_macro_internal' from 'gcc/rust/Make-lang.in:RUST_LDFLAGS'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:97759a56aa09fcef19c2202d0d91dd9fedf94547

commit 97759a56aa09fcef19c2202d0d91dd9fedf94547
Author: Thomas Schwinge 
Date:   Wed Feb 28 22:41:42 2024 +0100

Remove 'libgrust/libproc_macro_internal' from 
'gcc/rust/Make-lang.in:RUST_LDFLAGS'

This isn't necessary, as the full path to 'libproc_macro_internal.a' is
specified.

gcc/rust/
* Make-lang.in (RUST_LDFLAGS): Remove
'libgrust/libproc_macro_internal'.

Diff:
---
 gcc/rust/Make-lang.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index a68ae1e93f68..13e035da218b 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -225,7 +225,7 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
 
 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
-RUST_LDFLAGS = $(LDFLAGS) -L./../libgrust/libproc_macro_internal
+RUST_LDFLAGS = $(LDFLAGS)
 RUST_LIBDEPS = $(LIBDEPS) 
../libgrust/libproc_macro_internal/libproc_macro_internal.a 
rust/libformat_parser.a
 
 # The compiler itself is called crab1


[gcc/devel/rust/master] borrowck: Link Polonius and run it

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5f0db57567e147846cd0b7aa4cb2fc8bba9208a0

commit 5f0db57567e147846cd0b7aa4cb2fc8bba9208a0
Author: Jakub Dupak 
Date:   Tue Feb 27 23:59:36 2024 +0100

borrowck: Link Polonius and run it

gcc/rust/ChangeLog:

* Make-lang.in: Link Polonius.
* checks/errors/borrowck/rust-borrow-checker.cc: Run Polonius.

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/Make-lang.in  | 7 +--
 gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 3275015b0466..dd94c9b5eab5 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -227,12 +227,15 @@ rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
 LIBPROC_MACRO_INTERNAL = 
../libgrust/libproc_macro_internal/libproc_macro_internal.a
 LIBFORMAT_PARSER = ../libgrust/libformat_parser/debug/liblibformat_parser.a
+LIBFFI_POLONIUS = rust/libffi_polonius.a
 
 # The compiler itself is called crab1
-crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(rust.prev)
+crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(LIBFFI_POLONIUS) $(rust.prev)
@$(call LINK_PROGRESS,$(INDEX.rust),start)
+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
- $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(BACKENDLIBS)
+ $(RUST_ALL_OBJS) attribs.o $(BACKEND) \
+ $(LIBS) $(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) 
$(LIBFFI_POLONIUS) \
+ $(BACKENDLIBS)
@$(call LINK_PROGRESS,$(INDEX.rust),end)
 
 # Build hooks.
diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc 
b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
index a2351c57eb42..168b7054608d 100644
--- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
@@ -154,6 +154,8 @@ BorrowChecker::go (HIR::Crate )
  dump_facts_to_file ("placeholder",
  ::Facts::dump_placeholder);
}
+
+  Polonius::polonius_run (facts.freeze (), rust_be_debug_p ());
 }
 
   for (auto closure ATTRIBUTE_UNUSED : collector.get_closures ())


[gcc/devel/rust/master] Removed obsolete objects

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:3b9a0405f494774ce3054c87baea20aa3164eb4d

commit 3b9a0405f494774ce3054c87baea20aa3164eb4d
Author: Kushal Pal 
Date:   Wed Apr 24 06:04:53 2024 +

Removed obsolete objects

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Lines
removed as the objects are unused.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 6a9bb73ffe0f..b5b88b410e58 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1304,23 +1304,14 @@ CompileExpr::visit (HIR::MethodCallExpr )
 {
   const TyTy::DynamicObjectType *dyn
= static_cast (receiver->get_root ());
-
-  std::vector arguments;
-  for (auto  : expr.get_arguments ())
-   arguments.push_back (arg.get ());
-
   fn_expr
= get_fn_addr_from_dyn (dyn, receiver, fntype, self, expr.get_locus ());
   self = get_receiver_from_dyn (dyn, receiver, fntype, self,
expr.get_locus ());
 }
   else
-{
-  // lookup compiled functions since it may have already been compiled
-  HIR::PathExprSegment method_name = expr.get_method_name ();
-  HIR::PathIdentSegment segment_name = method_name.get_segment ();
-  fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ());
-}
+// lookup compiled functions since it may have already been compiled
+fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ());
 
   // lookup the autoderef mappings
   HirId autoderef_mappings_id


[gcc/devel/rust/master] Add a test for inherent impl type name resolve

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5b6c98285583130072cfa9ce84cbfd357a58c267

commit 5b6c98285583130072cfa9ce84cbfd357a58c267
Author: Pierre-Emmanuel Patry 
Date:   Thu Apr 18 22:39:47 2024 +0200

Add a test for inherent impl type name resolve

A previous bug with name resolution 2.0 was caused by an incorrectly
resolved inherent impl name. This test shall highlight the behavior
and prevent regression.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/name_resolution25.rs | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/testsuite/rust/compile/name_resolution25.rs 
b/gcc/testsuite/rust/compile/name_resolution25.rs
new file mode 100644
index ..3cacac7f64bd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution25.rs
@@ -0,0 +1,5 @@
+// { dg-options "-frust-name-resolution-2.0" }
+
+struct Test; // { dg-warning "struct is never constructed: .Test." }
+
+impl Test {}


[gcc/devel/rust/master] Visit type during resolution of inherent impl

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:973e60a2be6936d4909a9ccda1c9dce1e6eb1f4a

commit 973e60a2be6936d4909a9ccda1c9dce1e6eb1f4a
Author: Pierre-Emmanuel Patry 
Date:   Thu Apr 18 22:30:56 2024 +0200

Visit type during resolution of inherent impl

Inherent impl has a type it applies to. This type
was not visited and thus not resolved.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit
inherent impl type.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index 393994808ee0..c54cabad2e5d 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -115,6 +115,7 @@ void
 DefaultResolver::visit (AST::InherentImpl )
 {
   auto inner_fn = [this, ] () {
+visit (impl.get_type ());
 for (auto  : impl.get_impl_items ())
   item->accept_vis (*this);
   };


[gcc/devel/rust/master] Merge commit '2a9881565c7b48d04cf891666a66a1a2e560bce8' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:17ee9c68cbc9ba7a13b77ea458fbbc6275c38d02

commit 17ee9c68cbc9ba7a13b77ea458fbbc6275c38d02
Merge: e02c6e686bd3 2a9881565c7b
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:55:46 2024 +0200

Merge commit '2a9881565c7b48d04cf891666a66a1a2e560bce8' into HEAD

Diff:


[gcc/devel/rust/master] Rust: Move 'libformat_parser' build into libgrust

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:611d0bdc55a858736bd5cfabfc1ed4fef800d81a

commit 611d0bdc55a858736bd5cfabfc1ed4fef800d81a
Author: Thomas Schwinge 
Date:   Thu Feb 29 08:44:49 2024 +0100

Rust: Move 'libformat_parser' build into libgrust

Addresses #2883.

contrib/
* gcc_update (files_and_dependencies): Update for
'libformat_parser' in libgrust.
gcc/rust/
* Make-lang.in (LIBFORMAT_PARSER): Point to 'libformat_parser'
build in libgrust.
(%.toml:, $(LIBFORMAT_PARSER):): Remove.
libgrust/
* libformat_parser/Makefile.am: New.
* Makefile.am [!TARGET_LIBRARY] (SUBDIRS): Add 'libformat_parser'.
* configure.ac: Handle it.
(TARGET_LIBRARY): New 'AM_CONDITIONAL'.
* libformat_parser/Makefile.in: Generate.
* Makefile.in: Regenerate.
* configure: Likewise.

Diff:
---
 contrib/gcc_update|   1 +
 gcc/rust/Make-lang.in |  16 +-
 libgrust/Makefile.am  |   6 +-
 libgrust/Makefile.in  |   5 +-
 libgrust/configure|  22 +-
 libgrust/configure.ac |   3 +
 libgrust/libformat_parser/Makefile.am |  13 +
 libgrust/libformat_parser/Makefile.in | 441 ++
 8 files changed, 487 insertions(+), 20 deletions(-)

diff --git a/contrib/gcc_update b/contrib/gcc_update
index 774c926e723d..2c50592eb359 100755
--- a/contrib/gcc_update
+++ b/contrib/gcc_update
@@ -156,6 +156,7 @@ libgomp/config.h.in: libgomp/configure.ac libgomp/aclocal.m4
 libgrust/Makefile.in: libgrust/Makefile.am libgrust/aclocal.m4
 libgrust/aclocal.m4: libgrust/configure.ac
 libgrust/configure: libgrust/configure.ac libgrust/aclocal.m4
+libgrust/libformat_parser/Makefile.in: libgrust/libformat_parser/Makefile.am 
libgrust/aclocal.m4
 libgrust/libproc_macro_internal/Makefile.in: 
libgrust/libproc_macro_internal/Makefile.am libgrust/aclocal.m4
 libitm/aclocal.m4: libitm/configure.ac libitm/acinclude.m4
 libitm/Makefile.in: libitm/Makefile.am libitm/aclocal.m4
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 0c664b523d11..74663379487d 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -226,8 +226,7 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
 LIBPROC_MACRO_INTERNAL = 
../libgrust/libproc_macro_internal/libproc_macro_internal.a
-LIBFORMAT_PARSER_D = rust/libformat_parser
-LIBFORMAT_PARSER = $(LIBFORMAT_PARSER_D)/debug/liblibformat_parser.a
+LIBFORMAT_PARSER = ../libgrust/libformat_parser/debug/liblibformat_parser.a
 
 # The compiler itself is called crab1
 crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(rust.prev)
@@ -419,19 +418,6 @@ rust/%.o: rust/lex/%.cc
$(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
$(POSTCOMPILE)
 
-%.toml:
-   echo $@
-
-# TODO: Improve `cargo` invocation with host specific flags, possibly creating 
a $(CARGO) variable?
-$(LIBFORMAT_PARSER): $(srcdir)/../libgrust/libformat_parser/Cargo.toml 
$(wildcard $(srcdir)/../libgrust/libformat_parser/src/*.rs)
-   cargo \
- --config $(srcdir)/../libgrust/libformat_parser/.cargo/config \
- build \
-   --offline \
-   --target-dir $(LIBFORMAT_PARSER_D) \
-   --manifest-path $(srcdir)/../libgrust/libformat_parser/Cargo.toml \
-   # FIXME: Not always '--release', right?
-
 # build all rust/parse files in rust folder, add cross-folder includes
 rust/%.o: rust/parse/%.cc
$(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
diff --git a/libgrust/Makefile.am b/libgrust/Makefile.am
index 5b38c8842cb4..7a4512cae96b 100644
--- a/libgrust/Makefile.am
+++ b/libgrust/Makefile.am
@@ -11,7 +11,11 @@ TOP_GCCDIR := $(shell cd $(top_srcdir) && cd .. && pwd)
 GCC_DIR = $(TOP_GCCDIR)/gcc
 RUST_SRC = $(GCC_DIR)/rust
 
-SUBDIRS = libproc_macro_internal
+SUBDIRS =
+if !TARGET_LIBRARY
+SUBDIRS += libformat_parser
+endif
+SUBDIRS += libproc_macro_internal
 
 RUST_BUILDDIR := $(shell pwd)
 
diff --git a/libgrust/Makefile.in b/libgrust/Makefile.in
index d065584d196f..6665f8da738f 100644
--- a/libgrust/Makefile.in
+++ b/libgrust/Makefile.in
@@ -88,6 +88,7 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
+@TARGET_LIBRARY_FALSE@am__append_1 = libformat_parser
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
@@ -165,7 +166,7 @@ am__define_uniq_tagged_files = \
 ETAGS = etags
 CTAGS = ctags
 CSCOPE = cscope
-DIST_SUBDIRS = $(SUBDIRS)
+DIST_SUBDIRS = libformat_parser libproc_macro_internal
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
 AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
@@ -308,7 +309,7 @@ AM_CFLAGS = -I $(srcdir)/../libgcc -I 
$(MULTIBUILDTOP)../../gcc/include
 TOP_GCCDIR := $(shell cd $(top_srcdir) && 

[gcc/devel/rust/master] Rust: Move 'libformat_parser' build into the GCC build directory

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8dde956e18426b2204e660d3e7ff68bb8589a635

commit 8dde956e18426b2204e660d3e7ff68bb8589a635
Author: Thomas Schwinge 
Date:   Wed Feb 28 23:26:39 2024 +0100

Rust: Move 'libformat_parser' build into the GCC build directory

Fixes #2883.

* .gitignore: Remove 'libgrust/*/target/'.
gcc/rust/
* Make-lang.in (LIBFORMAT_PARSER): Point to the GCC build
directory.
* ($(LIBFORMAT_PARSER)): Build in the GCC build directory.

Diff:
---
 .gitignore|  1 -
 gcc/rust/Make-lang.in | 11 +--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index 1b2ecabbfe7e..d0e0fd1837f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -77,4 +77,3 @@ test.code-workspace
 
 gcc/rust/test3-tiny/*
 .clang-format.swap
-libgrust/*/target/
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index fbd43c96b1a0..0c664b523d11 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -226,7 +226,8 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
 LIBPROC_MACRO_INTERNAL = 
../libgrust/libproc_macro_internal/libproc_macro_internal.a
-LIBFORMAT_PARSER = 
$(srcdir)/../libgrust/libformat_parser/target/debug/liblibformat_parser.a
+LIBFORMAT_PARSER_D = rust/libformat_parser
+LIBFORMAT_PARSER = $(LIBFORMAT_PARSER_D)/debug/liblibformat_parser.a
 
 # The compiler itself is called crab1
 crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(rust.prev)
@@ -423,7 +424,13 @@ rust/%.o: rust/lex/%.cc
 
 # TODO: Improve `cargo` invocation with host specific flags, possibly creating 
a $(CARGO) variable?
 $(LIBFORMAT_PARSER): $(srcdir)/../libgrust/libformat_parser/Cargo.toml 
$(wildcard $(srcdir)/../libgrust/libformat_parser/src/*.rs)
-   cd $(srcdir)/../libgrust/libformat_parser && cargo build --offline  # 
FIXME: Not always release, right?
+   cargo \
+ --config $(srcdir)/../libgrust/libformat_parser/.cargo/config \
+ build \
+   --offline \
+   --target-dir $(LIBFORMAT_PARSER_D) \
+   --manifest-path $(srcdir)/../libgrust/libformat_parser/Cargo.toml \
+   # FIXME: Not always '--release', right?
 
 # build all rust/parse files in rust folder, add cross-folder includes
 rust/%.o: rust/parse/%.cc


[gcc/devel/rust/master] Rust: Don't cache 'libformat_parser.a'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:34a70f48756cb294da342245f5d2b0d622fa298c

commit 34a70f48756cb294da342245f5d2b0d622fa298c
Author: Thomas Schwinge 
Date:   Wed Feb 28 23:02:19 2024 +0100

Rust: Don't cache 'libformat_parser.a'

gcc/rust/
* Make-lang.in (LIBFORMAT_PARSER): Point to the actual build 
artifact.
($(LIBFORMAT_PARSER)): Don't cache it.

Diff:
---
 gcc/rust/Make-lang.in | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 862dbf6a8791..fbd43c96b1a0 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -226,7 +226,7 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
 LIBPROC_MACRO_INTERNAL = 
../libgrust/libproc_macro_internal/libproc_macro_internal.a
-LIBFORMAT_PARSER = rust/libformat_parser.a
+LIBFORMAT_PARSER = 
$(srcdir)/../libgrust/libformat_parser/target/debug/liblibformat_parser.a
 
 # The compiler itself is called crab1
 crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS) 
$(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(rust.prev)
@@ -424,7 +424,6 @@ rust/%.o: rust/lex/%.cc
 # TODO: Improve `cargo` invocation with host specific flags, possibly creating 
a $(CARGO) variable?
 $(LIBFORMAT_PARSER): $(srcdir)/../libgrust/libformat_parser/Cargo.toml 
$(wildcard $(srcdir)/../libgrust/libformat_parser/src/*.rs)
cd $(srcdir)/../libgrust/libformat_parser && cargo build --offline  # 
FIXME: Not always release, right?
-   cp 
$(srcdir)/../libgrust/libformat_parser/target/debug/liblibformat_parser.a $@
 
 # build all rust/parse files in rust folder, add cross-folder includes
 rust/%.o: rust/parse/%.cc


[gcc/devel/rust/master] Merge commit 'e621b174d7c622aa4b677a4c812e5061e311cc5c' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c9e59de17dd46032f7c63463b8738b287ae34f8c

commit c9e59de17dd46032f7c63463b8738b287ae34f8c
Merge: d2bcecd7fd91 e621b174d7c6
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:48:27 2024 +0200

Merge commit 'e621b174d7c622aa4b677a4c812e5061e311cc5c' into HEAD

Diff:


[gcc/devel/rust/master] borrowck: BIR: scope handling

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:de18440f92465be93f0248a7071834baa1ec748d

commit de18440f92465be93f0248a7071834baa1ec748d
Author: Jakub Dupak 
Date:   Fri Feb 2 14:38:59 2024 +0100

borrowck: BIR: scope handling

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
(ExprStmtBuilder::setup_loop):
Loop handling.
(ExprStmtBuilder::visit): Handle scopes.
* checks/errors/borrowck/rust-bir-builder-internal.h (struct 
BuilderContext):
Handle scopes.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Dump scopes.
(Dump::visit): Add scopes dump.
(Dump::indent): Add indentation logic.
(Dump::visit_scope): Dump scope.
* checks/errors/borrowck/rust-bir-dump.h: Dump methods.
* checks/errors/borrowck/rust-bir-place.h 
(std::numeric_limits::max): Scope constants.
(struct Scope): Scope representation.
(class PlaceDB): Scope tracking.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/rust-bir-builder-expr-stmt.cc  | 32 ++---
 .../errors/borrowck/rust-bir-builder-internal.h| 82 +++---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 52 ++
 gcc/rust/checks/errors/borrowck/rust-bir-dump.h|  3 +
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 56 ++-
 5 files changed, 188 insertions(+), 37 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index ea8107b1fb76..89352d84f6b8 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -37,9 +37,17 @@ ExprStmtBuilder::setup_loop (HIR::BaseLoopExpr )
   PlaceId label_var = take_or_create_return_place (lookup_type (expr));
 
   BasicBlockId continue_bb = new_bb ();
+  push_goto (continue_bb);
+  ctx.current_bb = continue_bb;
+  // falseUnwind
+  start_new_consecutive_bb ();
+
   BasicBlockId break_bb = new_bb ();
-  ctx.loop_and_label_stack.push_back (
-{true, label, label_var, break_bb, continue_bb});
+  // We are still outside the loop block;
+  ScopeId continue_scope = ctx.place_db.get_current_scope_id () + 1;
+  ctx.loop_and_label_stack.emplace_back (true, label, label_var, break_bb,
+continue_bb, continue_scope);
+
   return ctx.loop_and_label_stack.back ();
 }
 
@@ -289,13 +297,16 @@ ExprStmtBuilder::visit (HIR::FieldAccessExpr )
 void
 ExprStmtBuilder::visit (HIR::BlockExpr )
 {
+  push_new_scope ();
+
   if (block.has_label ())
 {
   NodeId label
= block.get_label ().get_lifetime ().get_mappings ().get_nodeid ();
   PlaceId label_var = take_or_create_return_place (lookup_type (block));
-  ctx.loop_and_label_stack.push_back (
-   {false, label, label_var, new_bb (), INVALID_BB});
+  ctx.loop_and_label_stack.emplace_back (
+   false, label, label_var, new_bb (), INVALID_BB,
+   ctx.place_db.get_current_scope_id ());
 }
 
   // Eliminates dead code after break, continue, return.
@@ -333,6 +344,8 @@ ExprStmtBuilder::visit (HIR::BlockExpr )
take_or_create_return_place (
  lookup_type (*block.get_final_expr ();
 }
+
+  pop_scope ();
 }
 
 void
@@ -340,6 +353,8 @@ ExprStmtBuilder::visit (HIR::ContinueExpr )
 {
   LoopAndLabelCtx info = cont.has_label () ? get_label_ctx (cont.get_label ())
   : get_unnamed_loop_ctx ();
+  start_new_consecutive_bb ();
+  unwind_until (info.continue_bb);
   push_goto (info.continue_bb);
   // No code allowed after continue. Handled in BlockExpr.
 }
@@ -352,6 +367,8 @@ ExprStmtBuilder::visit (HIR::BreakExpr )
   if (brk.has_break_expr ())
 push_assignment (info.label_var, visit_expr (*brk.get_expr ()));
 
+  start_new_consecutive_bb ();
+  unwind_until (ctx.place_db.get_scope (info.continue_scope).parent);
   push_goto (info.break_bb);
   // No code allowed after continue. Handled in BlockExpr.
 }
@@ -406,6 +423,7 @@ ExprStmtBuilder::visit (HIR::ReturnExpr )
 {
   push_assignment (RETURN_VALUE_PLACE, visit_expr (*ret.get_expr ()));
 }
+  unwind_until (ROOT_SCOPE);
   ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
 }
 
@@ -420,9 +438,6 @@ ExprStmtBuilder::visit (HIR::LoopExpr )
 {
   auto loop = setup_loop (expr);
 
-  push_goto (loop.continue_bb);
-
-  ctx.current_bb = loop.continue_bb;
   (void) visit_expr (*expr.get_loop_block ());
   if (!ctx.get_current_bb ().is_terminated ())
 push_goto (loop.continue_bb);
@@ -435,9 +450,6 @@ ExprStmtBuilder::visit (HIR::WhileLoopExpr )
 {
   auto loop = setup_loop (expr);
 
-  push_goto (loop.continue_bb);
-
-  ctx.current_bb = loop.continue_bb;
   auto cond_val = visit_expr (*expr.get_predicate_expr ());
   auto body_bb 

[gcc/devel/rust/master] Add 'gcc/rust/Make-lang.in:LIBPROC_MACRO_INTERNAL'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:00d5896b317ea0c43b01e3a8649b497a5d731f29

commit 00d5896b317ea0c43b01e3a8649b497a5d731f29
Author: Thomas Schwinge 
Date:   Wed Feb 28 22:51:24 2024 +0100

Add 'gcc/rust/Make-lang.in:LIBPROC_MACRO_INTERNAL'

... to avoid verbatim repetition.

gcc/rust/
* Make-lang.in (LIBPROC_MACRO_INTERNAL): New.
(RUST_LIBDEPS, crab1$(exeext)): Use it.

Diff:
---
 gcc/rust/Make-lang.in | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index c39fd9453823..6c34c7cb9070 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -225,13 +225,15 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
 
 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
-RUST_LIBDEPS = $(LIBDEPS) 
../libgrust/libproc_macro_internal/libproc_macro_internal.a 
rust/libformat_parser.a
+LIBPROC_MACRO_INTERNAL = 
../libgrust/libproc_macro_internal/libproc_macro_internal.a
+
+RUST_LIBDEPS = $(LIBDEPS) $(LIBPROC_MACRO_INTERNAL) rust/libformat_parser.a
 
 # The compiler itself is called crab1
 crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(RUST_LIBDEPS) 
$(rust.prev)
@$(call LINK_PROGRESS,$(INDEX.rust),start)
+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
- $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) 
../libgrust/libproc_macro_internal/libproc_macro_internal.a 
rust/libformat_parser.a $(BACKENDLIBS)
+ $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) 
$(LIBPROC_MACRO_INTERNAL) rust/libformat_parser.a $(BACKENDLIBS)
@$(call LINK_PROGRESS,$(INDEX.rust),end)
 
 # Build hooks.


[gcc/devel/rust/master] Inline 'gcc/rust/Make-lang.in:RUST_LDFLAGS'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1e97d748f45e4ae4e56ef2f2cd30c90bf000d410

commit 1e97d748f45e4ae4e56ef2f2cd30c90bf000d410
Author: Thomas Schwinge 
Date:   Wed Feb 28 22:45:18 2024 +0100

Inline 'gcc/rust/Make-lang.in:RUST_LDFLAGS'

Unused.

gcc/rust/
* Make-lang.in (RUST_LDFLAGS): Inline into all users.

Diff:
---
 gcc/rust/Make-lang.in | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 13e035da218b..c39fd9453823 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -225,13 +225,12 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
 
 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
-RUST_LDFLAGS = $(LDFLAGS)
 RUST_LIBDEPS = $(LIBDEPS) 
../libgrust/libproc_macro_internal/libproc_macro_internal.a 
rust/libformat_parser.a
 
 # The compiler itself is called crab1
 crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(RUST_LIBDEPS) 
$(rust.prev)
@$(call LINK_PROGRESS,$(INDEX.rust),start)
-   +$(LLINKER) $(ALL_LINKERFLAGS) $(RUST_LDFLAGS) -o $@ \
+   +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
  $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) 
../libgrust/libproc_macro_internal/libproc_macro_internal.a 
rust/libformat_parser.a $(BACKENDLIBS)
@$(call LINK_PROGRESS,$(INDEX.rust),end)


[gcc/devel/rust/master] Improve parsing of raw byte string literals

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:67928be5b05ab927baf0a366689c246ec61ed745

commit 67928be5b05ab927baf0a366689c246ec61ed745
Author: Owen Avery 
Date:   Tue Mar 26 20:16:08 2024 -0400

Improve parsing of raw byte string literals

gcc/rust/ChangeLog:

* lex/rust-lex.cc
(Lexer::parse_raw_byte_string):
Bring handling of edge cases to par with parse_byte_string.

gcc/testsuite/ChangeLog:

* rust/compile/raw-byte-string-loc.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/lex/rust-lex.cc  | 23 +++
 gcc/testsuite/rust/compile/raw-byte-string-loc.rs |  6 ++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 9c2203160cd4..7c37e83d6cb7 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -1840,14 +1840,18 @@ Lexer::parse_raw_byte_string (location_t loc)
   int length = 1;
   int hash_count = 0;
 
+  const location_t string_begin_locus = get_current_location ();
+
   // get hash count at beginnning
   skip_input ();
   current_char = peek_input ();
   length++;
+  current_column++;
   while (current_char == '#')
 {
   hash_count++;
   length++;
+  current_column++;
 
   skip_input ();
   current_char = peek_input ();
@@ -1862,6 +1866,7 @@ Lexer::parse_raw_byte_string (location_t loc)
   skip_input ();
   current_char = peek_input ();
   length++;
+  current_column++;
 
   while (true)
 {
@@ -1884,27 +1889,37 @@ Lexer::parse_raw_byte_string (location_t loc)
  skip_input (hash_count);
  current_char = peek_input ();
  length += hash_count + 1;
+ current_column += hash_count + 1;
  break;
}
}
-
-  if (current_char.value > 127)
+  else if (current_char.value > 127)
{
  rust_error_at (get_current_location (),
 "character %<%s%> in raw byte string out of range",
 current_char.as_string ().c_str ());
  current_char = 0;
}
+  else if (current_char.is_eof ())
+   {
+ rust_error_at (string_begin_locus, "unended raw byte string literal");
+ return Token::make (END_OF_FILE, get_current_location ());
+   }
 
   length++;
+  current_column++;
+  if (current_char == '\n')
+   {
+ current_line++;
+ current_column = 1;
+ start_line (current_line, max_column_hint);
+   }
 
   str += current_char;
   skip_input ();
   current_char = peek_input ();
 }
 
-  current_column += length;
-
   loc += length - 1;
 
   str.shrink_to_fit ();
diff --git a/gcc/testsuite/rust/compile/raw-byte-string-loc.rs 
b/gcc/testsuite/rust/compile/raw-byte-string-loc.rs
new file mode 100644
index ..f37d3f9694d3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/raw-byte-string-loc.rs
@@ -0,0 +1,6 @@
+const X: &'static u8 = br#"12
+12"#;
+
+BREAK
+// { dg-error "unrecognised token" "" { target *-*-* } .-1 }
+// { dg-excess-errors "error 'failed to parse item' does not have location" }


[gcc/devel/rust/master] Fix use rebind name resolution.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a8d1604cb38ba6a170afee40dbfbbc630b2c7c6e

commit a8d1604cb38ba6a170afee40dbfbbc630b2c7c6e
Author: Pierre-Emmanuel Patry 
Date:   Thu Mar 21 19:25:52 2024 +0100

Fix use rebind name resolution.

Name resolution for rebind were missing.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(TopLevel::handle_use_glob):
Change function prototype to use a reference instead.
(TopLevel::handle_use_dec): Likewise.
(TopLevel::handle_rebind): Add name resolution on rebind use
declarations.
(flatten_rebind): Change prototype to accept a pair of path/alias.
(flatten_list): Adapt call to flatten_rebind.
(flatten): Adapt call to flatten_rebind.
(flatten_glob): Remove unused part.
(TopLevel::visit): Add rebind resolution.
* resolve/rust-toplevel-name-resolver-2.0.h: Adapt function 
prototypes.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 194 -
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |   5 +-
 2 files changed, 151 insertions(+), 48 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index e6da8db850c3..4593c67c5d3e 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-toplevel-name-resolver-2.0.h"
+#include "input.h"
 #include "optional.h"
 #include "rust-ast-full.h"
 #include "rust-hir-map.h"
@@ -434,7 +435,7 @@ TopLevel::visit (AST::ConstantItem _item)
 }
 
 bool
-TopLevel::handle_use_glob (AST::SimplePath glob)
+TopLevel::handle_use_glob (AST::SimplePath )
 {
   auto resolved = ctx.types.resolve_path (glob.get_segments ());
   if (!resolved.has_value ())
@@ -453,7 +454,7 @@ TopLevel::handle_use_glob (AST::SimplePath glob)
 }
 
 bool
-TopLevel::handle_use_dec (AST::SimplePath path)
+TopLevel::handle_use_dec (AST::SimplePath )
 {
   auto locus = path.get_final_segment ().get_locus ();
   auto declared_name = path.get_final_segment ().as_string ();
@@ -508,6 +509,97 @@ TopLevel::handle_use_dec (AST::SimplePath path)
});
   };
 
+  resolve_and_insert (Namespace::Values, path);
+  resolve_and_insert (Namespace::Types, path);
+  resolve_and_insert (Namespace::Macros, path);
+
+  return found;
+}
+
+bool
+TopLevel::handle_rebind (std::pair 
)
+{
+  auto  = rebind.first;
+
+  location_t locus = UNKNOWN_LOCATION;
+  std::string declared_name;
+
+  switch (rebind.second.get_new_bind_type ())
+{
+case AST::UseTreeRebind::NewBindType::IDENTIFIER:
+  declared_name = rebind.second.get_identifier ().as_string ();
+  locus = rebind.second.get_identifier ().get_locus ();
+  break;
+case AST::UseTreeRebind::NewBindType::NONE:
+  declared_name = path.get_final_segment ().as_string ();
+  locus = path.get_final_segment ().get_locus ();
+  break;
+case AST::UseTreeRebind::NewBindType::WILDCARD:
+  rust_unreachable ();
+  break;
+}
+
+  // in what namespace do we perform path resolution? All
+  // of them? see which one matches? Error out on
+  // ambiguities? so, apparently, for each one that
+  // matches, add it to the proper namespace
+  // :(
+  auto found = false;
+
+  auto resolve_and_insert = [this, , _name,
+locus] (Namespace ns,
+const AST::SimplePath ) {
+tl::optional resolved = tl::nullopt;
+tl::optional resolved_bind = tl::nullopt;
+
+std::vector declaration_v
+  = {AST::SimplePathSegment (declared_name, locus)};
+// FIXME: resolve_path needs to return an `expected` so
+// that we can improve it with hints or location or w/ever. and maybe
+// only emit it the first time.
+switch (ns)
+  {
+  case Namespace::Values:
+   resolved = ctx.values.resolve_path (path.get_segments ());
+   resolved_bind = ctx.values.resolve_path (declaration_v);
+   break;
+  case Namespace::Types:
+   resolved = ctx.types.resolve_path (path.get_segments ());
+   resolved_bind = ctx.types.resolve_path (declaration_v);
+   break;
+  case Namespace::Macros:
+   resolved = ctx.macros.resolve_path (path.get_segments ());
+   resolved_bind = ctx.macros.resolve_path (declaration_v);
+   break;
+  case Namespace::Labels:
+   // TODO: Is that okay?
+   rust_unreachable ();
+  }
+
+resolved.map ([this, , _name, locus, ns, path,
+  _bind] (Rib::Definition def) {
+  found = true;
+
+  insert_or_error_out (declared_name, locus, def.get_node_id (), ns);
+  if (resolved_bind.has_value ())
+   {
+ auto bind_def = resolved_bind.value ();
+ // what do we do with the id?
+ auto 

[gcc/devel/rust/master] Remove 'libgrust/librustc_format_parser' from 'gcc/rust/Make-lang.in:RUST_LDFLAGS'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:9dda7062e0bddcfe08e08f6a4efd8dd544f89463

commit 9dda7062e0bddcfe08e08f6a4efd8dd544f89463
Author: Thomas Schwinge 
Date:   Wed Feb 28 22:39:52 2024 +0100

Remove 'libgrust/librustc_format_parser' from 
'gcc/rust/Make-lang.in:RUST_LDFLAGS'

That directory doesn't even exist.

gcc/rust/
* Make-lang.in (RUST_LDFLAGS): Remove
'libgrust/librustc_format_parser'.

Diff:
---
 gcc/rust/Make-lang.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index bec02f79731a..a68ae1e93f68 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -225,7 +225,7 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
 
 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
 
-RUST_LDFLAGS = $(LDFLAGS) -L./../libgrust/libproc_macro_internal 
-L./../libgrust/librustc_format_parser/
+RUST_LDFLAGS = $(LDFLAGS) -L./../libgrust/libproc_macro_internal
 RUST_LIBDEPS = $(LIBDEPS) 
../libgrust/libproc_macro_internal/libproc_macro_internal.a 
rust/libformat_parser.a
 
 # The compiler itself is called crab1


[gcc/devel/rust/master] Add mappings for struct base and struct fields

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:15a37afd98abaa865c7945357b2ca07da4d063d2

commit 15a37afd98abaa865c7945357b2ca07da4d063d2
Author: Pierre-Emmanuel Patry 
Date:   Thu Mar 21 19:16:02 2024 +0100

Add mappings for struct base and struct fields

Definition/usage mapping during name resolution was missing.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add mapping
implementation.
* resolve/rust-late-name-resolver-2.0.h: Add function visitor 
prototype
override.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 21 +
 gcc/rust/resolve/rust-late-name-resolver-2.0.h  |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index dc7cde1b3233..f580c23377b0 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -228,5 +228,26 @@ Late::visit (AST::TypePath )
 Definition (resolved->get_node_id ()));
 }
 
+void
+Late::visit (AST::StructExprStructBase )
+{
+  auto resolved = ctx.types.get (s.get_struct_name ().as_string ());
+
+  ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
+Definition (resolved->get_node_id ()));
+  DefaultResolver::visit (s);
+}
+
+void
+Late::visit (AST::StructExprStructFields )
+{
+  auto resolved = ctx.types.get (s.get_struct_name ().as_string ());
+
+  ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
+Definition (resolved->get_node_id ()));
+
+  DefaultResolver::visit (s);
+}
+
 } // namespace Resolver2_0
 } // namespace Rust
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 3a8a0060f5a2..ee712b305d4f 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -46,6 +46,8 @@ public:
   void visit (AST::IdentifierExpr &) override;
   void visit (AST::PathInExpression &) override;
   void visit (AST::TypePath &) override;
+  void visit (AST::StructExprStructBase &) override;
+  void visit (AST::StructExprStructFields &) override;
 
 private:
   /* Setup Rust's builtin types (u8, i32, !...) in the resolver */


[gcc/devel/rust/master] rust: Add --offline flag to cargo when building Rust components.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2dff71f6fcbd84570e282b6c884ae246715c621e

commit 2dff71f6fcbd84570e282b6c884ae246715c621e
Author: Arthur Cohen 
Date:   Tue Apr 9 13:43:01 2024 +0200

rust: Add --offline flag to cargo when building Rust components.

gcc/rust/ChangeLog:

* Make-lang.in: Add --offline flag to cargo invocation.

Diff:
---
 gcc/rust/Make-lang.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 1efab4987db5..bec02f79731a 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -421,8 +421,9 @@ rust/%.o: rust/lex/%.cc
 %.toml:
echo $@
 
+# TODO: Improve `cargo` invocation with host specific flags, possibly creating 
a $(CARGO) variable?
 rust/libformat_parser.a: $(srcdir)/../libgrust/libformat_parser/Cargo.toml 
$(wildcard $(srcdir)/../libgrust/libformat_parser/src/*.rs)
-   cargo build --manifest-path 
$(srcdir)/../libgrust/libformat_parser/Cargo.toml # FIXME: Not always release, 
right?
+   cd $(srcdir)/../libgrust/libformat_parser && cargo build --offline  # 
FIXME: Not always release, right?
cp 
$(srcdir)/../libgrust/libformat_parser/target/debug/liblibformat_parser.a $@
 
 # build all rust/parse files in rust folder, add cross-folder includes


[gcc/devel/rust/master] Fix quoted string format

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:7697c1e9f55ffd6dbcad818ba8c0d7e756080608

commit 7697c1e9f55ffd6dbcad818ba8c0d7e756080608
Author: Pierre-Emmanuel Patry 
Date:   Wed Mar 13 17:18:58 2024 +0100

Fix quoted string format

This format dialog triggered a warning.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(TopLevel::handle_use_dec):
Replace the string format %<%s%> with the proper %qs format.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 80b142678b95..e6da8db850c3 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -499,7 +499,7 @@ TopLevel::handle_use_dec (AST::SimplePath path)
  auto result = node_forwarding.find (def.get_node_id ());
  if (result != node_forwarding.cend ()
  && result->second != path.get_node_id ())
-   rust_error_at (path.get_locus (), "%<%s%> defined multiple times",
+   rust_error_at (path.get_locus (), "%qs defined multiple times",
   declared_name.c_str ());
  else // No previous thing has inserted this into our scope
node_forwarding.insert ({def.get_node_id (), path.get_node_id ()});


[gcc/devel/rust/master] Prevent getting immutable context with classic nr

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a63f0ac77e448551b7320dac3acfb0a6331d6fe9

commit a63f0ac77e448551b7320dac3acfb0a6331d6fe9
Author: Pierre-Emmanuel Patry 
Date:   Wed Mar 13 16:44:00 2024 +0100

Prevent getting immutable context with classic nr

Immutable name resolution context is not initialized when the classic
name resolution is in use. It can therefore not be used, the getter would
error out.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_root_path):
Only get immutable name resolution context when name resolution 2.0 
is
used.
* typecheck/rust-hir-type-check-type.cc 
(TypeCheckType::resolve_root_path):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-path.cc | 14 --
 gcc/rust/typecheck/rust-hir-type-check-type.cc | 17 +
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index b0e52c454e9d..dd6ab03a3627 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -199,16 +199,18 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
, size_t *offset,
   bool is_root = *offset == 0;
   NodeId ast_node_id = seg.get_mappings ().get_nodeid ();
 
-  auto nr_ctx
-   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
   // then lookup the reference_node_id
   NodeId ref_node_id = UNKNOWN_NODEID;
 
   if (flag_name_resolution_2_0)
-   // assign the ref_node_id if we've found something
-   nr_ctx.lookup (expr.get_mappings ().get_nodeid ())
- .map ([_node_id] (NodeId resolved) { ref_node_id = resolved; });
+   {
+ auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ // assign the ref_node_id if we've found something
+ nr_ctx.lookup (expr.get_mappings ().get_nodeid ())
+   .map ([_node_id] (NodeId resolved) { ref_node_id = resolved; });
+   }
   else if (!resolver->lookup_resolved_name (ast_node_id, _node_id))
resolver->lookup_resolved_type (ast_node_id, _node_id);
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 588e5bce88e1..44ebc159b23a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -341,19 +341,20 @@ TypeCheckType::resolve_root_path (HIR::TypePath , 
size_t *offset,
   bool is_root = *offset == 0;
   NodeId ast_node_id = seg->get_mappings ().get_nodeid ();
 
-  auto nr_ctx
-   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
   // then lookup the reference_node_id
   NodeId ref_node_id = UNKNOWN_NODEID;
 
   // FIXME: HACK: ARTHUR: Remove this
   if (flag_name_resolution_2_0)
-   // assign the ref_node_id if we've found something
-   nr_ctx.lookup (path.get_mappings ().get_nodeid ())
- .map ([_node_id, ] (NodeId resolved) {
-   ref_node_id = resolved;
- });
+   {
+ auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+ // assign the ref_node_id if we've found something
+ nr_ctx.lookup (path.get_mappings ().get_nodeid ())
+   .map ([_node_id, ] (NodeId resolved) {
+ ref_node_id = resolved;
+   });
+   }
   else if (!resolver->lookup_resolved_name (ast_node_id, _node_id))
resolver->lookup_resolved_type (ast_node_id, _node_id);


[gcc/devel/rust/master] Merge commit '767698ff6c8f07047ad90bef89f3dc4c4515f0df' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:30a67f581fef03ef28a8d93ed7608c35021e21d1

commit 30a67f581fef03ef28a8d93ed7608c35021e21d1
Merge: 17d389c4a3f9 767698ff6c8f
Author: Thomas Schwinge 
Date:   Wed Apr 10 11:05:52 2024 +0200

Merge commit '767698ff6c8f07047ad90bef89f3dc4c4515f0df' into HEAD

Diff:


[gcc/devel/rust/master] Adjust '.github/bors_log_expected_warnings'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:013b520529d5f1bddec27dd921eab5e917663693

commit 013b520529d5f1bddec27dd921eab5e917663693
Author: Thomas Schwinge 
Date:   Wed Apr 10 14:34:26 2024 +0200

Adjust '.github/bors_log_expected_warnings'

Diff:
---
 .github/bors_log_expected_warnings | 141 ++---
 1 file changed, 100 insertions(+), 41 deletions(-)

diff --git a/.github/bors_log_expected_warnings 
b/.github/bors_log_expected_warnings
index 173310bb2257..989829d685f4 100644
--- a/.github/bors_log_expected_warnings
+++ b/.github/bors_log_expected_warnings
@@ -1,4 +1,68 @@
 ../../../../libgcc/generic-morestack.c:397:16: warning: comparison of integer 
expressions of different signedness: ‘unsigned int’ and ‘long int’ 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixdfbitint.c:51:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixdfbitint.c:51:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixdfbitint.c:57:22: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixdfbitint.c:57:22: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixdfbitint.c:61:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixdfbitint.c:61:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixsfbitint.c:51:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixsfbitint.c:51:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixsfbitint.c:57:22: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixsfbitint.c:57:22: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixsfbitint.c:61:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixsfbitint.c:61:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixtfbitint.c:61:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixtfbitint.c:61:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixtfbitint.c:67:22: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixtfbitint.c:67:22: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixtfbitint.c:71:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixtfbitint.c:71:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixxfbitint.c:62:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixxfbitint.c:62:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixxfbitint.c:68:22: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixxfbitint.c:68:22: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixxfbitint.c:72:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 
[-Wsign-compare]
+../../../../libgcc/soft-fp/fixxfbitint.c:72:20: warning: comparison of integer 
expressions of different signedness: ‘int’ and ‘USItype’ {aka ‘unsigned int’} 

[gcc/devel/rust/master] Struct are types, not values

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:01f3f7b846504858c43a5d94b9d60109369648e1

commit 01f3f7b846504858c43a5d94b9d60109369648e1
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 17:10:42 2024 +0100

Struct are types, not values

We shall search in the right namespace. The correct namespace for struct
is type namespace.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): 
Change
search location for struct types.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-item.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 4ab946e1c2a1..3e504e5df322 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -279,9 +279,11 @@ TypeCheckItem::visit (HIR::StructStruct _decl)
 {
   auto nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-  auto canonical_path = nr_ctx.values.to_canonical_path (
+  auto canonical_path = nr_ctx.types.to_canonical_path (
struct_decl.get_mappings ().get_nodeid ());
 
+  if (!canonical_path.has_value ())
+   rust_unreachable ();
   path = canonical_path.value ();
 }
   else


[gcc/devel/rust/master] Merge commit '8534cc772def8142379c0e72ab6392d40f3f60f6^' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:17d389c4a3f9fd540cb9cce670b9165ea59ff2ab

commit 17d389c4a3f9fd540cb9cce670b9165ea59ff2ab
Merge: 31fed215c247 d0f8cb17bbd3
Author: Thomas Schwinge 
Date:   Wed Apr 10 11:05:29 2024 +0200

Merge commit '8534cc772def8142379c0e72ab6392d40f3f60f6^' into HEAD

Diff:

 gcc/ChangeLog  |   265 +
 gcc/DATESTAMP  | 2 +-
 gcc/analyzer/ChangeLog |29 +
 gcc/analyzer/analyzer.h| 3 +
 gcc/analyzer/ranges.cc |18 +
 gcc/analyzer/region-model-manager.cc   |38 +-
 gcc/analyzer/region-model.cc   |17 +-
 gcc/analyzer/region.cc |48 -
 gcc/analyzer/region.h  |20 +-
 gcc/analyzer/varargs.cc|38 +-
 gcc/cfgexpand.cc   | 2 +-
 gcc/cfgrtl.cc  |51 +-
 gcc/cfgrtl.h   | 1 +
 gcc/common/config/riscv/riscv-common.cc|46 +
 gcc/config/aarch64/aarch64-arches.def  | 2 +-
 gcc/config/aarch64/aarch64-builtins.cc | 3 +-
 gcc/config/aarch64/aarch64-passes.def  | 1 +
 gcc/config/aarch64/aarch64-protos.h| 1 +
 gcc/config/aarch64/aarch64-sme.md  |48 +-
 gcc/config/aarch64/aarch64-speculation.cc  |64 +-
 gcc/config/aarch64/aarch64.cc  |64 +-
 gcc/config/aarch64/aarch64.md  | 8 +-
 gcc/config/arm/arm.cc  |11 +-
 gcc/config/avr/avr-c.cc| 1 +
 gcc/config/avr/avr-protos.h| 1 +
 gcc/config/avr/avr.cc  |70 +-
 gcc/config/avr/avr.h   | 1 +
 gcc/config/avr/avr.md  |47 +-
 gcc/config/avr/builtins.def|16 +-
 gcc/config/bpf/bpf.md  | 2 +-
 gcc/config/bpf/bpf.opt | 2 +
 gcc/config/gcn/gcn-valu.md | 5 +-
 gcc/config/gcn/gcn.cc  |23 +-
 gcc/config/gcn/gcn.h   | 6 +
 gcc/config/i386/i386.cc|24 +-
 gcc/config/loongarch/larchintrin.h |71 +-
 gcc/config/nvptx/gen-omp-device-properties.sh  | 2 +-
 gcc/config/nvptx/nvptx.cc  | 3 +-
 gcc/config/riscv/riscv-c.cc| 2 +-
 gcc/config/riscv/riscv-protos.h| 7 +
 gcc/config/riscv/riscv-vsetvl.cc   |25 +
 gcc/config/riscv/riscv.h   | 7 +-
 gcc/config/riscv/riscv.md  | 2 +-
 gcc/config/riscv/riscv.opt |12 +
 gcc/cp/ChangeLog   |39 +
 gcc/cp/constraint.cc   | 5 +-
 gcc/cp/module.cc   | 4 +
 gcc/cp/parser.cc   | 9 +-
 gcc/cp/search.cc   |22 +-
 gcc/cp/typeck.cc   |24 +-
 gcc/d/ChangeLog|38 +
 gcc/d/Make-lang.in | 1 +
 gcc/d/d-attribs.cc | 6 +-
 gcc/d/d-builtins.cc|39 +-
 gcc/d/d-codegen.cc |16 +-
 gcc/d/d-convert.cc | 6 +-
 gcc/d/d-lang.cc|26 +-
 gcc/d/d-target.cc  |12 +-
 gcc/d/decl.cc  |39 +-
 gcc/d/dmd/MERGE| 2 +-
 gcc/d/dmd/VERSION  | 2 +-
 gcc/d/dmd/aggregate.h  | 7 +-
 gcc/d/dmd/cparse.d |17 +
 gcc/d/dmd/cppmangle.d  | 6 +-
 gcc/d/dmd/cxxfrontend.d|   623 +
 gcc/d/dmd/declaration.h| 7 +-
 gcc/d/dmd/dinterpret.d | 4 +-
 gcc/d/dmd/dmangle.d|10 +-
 gcc/d/dmd/dmodule.d| 4 +-
 gcc/d/dmd/doc.d| 2 +-
 gcc/d/dmd/doc.h| 7 +-
 gcc/d/dmd/dscope.d | 1 +
 gcc/d/dmd/dstruct.d| 2 +-
 gcc/d/dmd/dsymbol.d|   273 +-
 gcc/d/dmd/dsymbol.h|35 +-
 

[gcc/devel/rust/master] Merge commit 'f0b1cf01782ba975cfda32800c91076df78058d6' into HEAD [#2857]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:31fed215c24705ff8a471d9d3662b3afd1faa932

commit 31fed215c24705ff8a471d9d3662b3afd1faa932
Merge: 9575360bad47 f0b1cf01782b
Author: Thomas Schwinge 
Date:   Wed Apr 10 11:02:28 2024 +0200

Merge commit 'f0b1cf01782ba975cfda32800c91076df78058d6' into HEAD [#2857]

Diff:


[gcc/devel/rust/master] Change enum namespace from value to type

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:08a6f1a1183572b35e5151f2b73b1aec41d42db2

commit 08a6f1a1183572b35e5151f2b73b1aec41d42db2
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 17:08:05 2024 +0100

Change enum namespace from value to type

The enum type shall be in type namespace, not value namespace.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(GlobbingVisitor::visit):
Change enum type namespace.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 820ba271ae0c..b672d448151a 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -95,7 +95,7 @@ GlobbingVisitor::visit (AST::Enum _item)
 {
   if (enum_item.get_visibility ().is_public ())
 ctx.insert_shadowable (enum_item.get_identifier (),
-  enum_item.get_node_id (), Namespace::Values);
+  enum_item.get_node_id (), Namespace::Types);
 }
 
 void


[gcc/devel/rust/master] Unit struct constructor shall be resolved

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e19483da430ccd1da3a08dd1cebb87b425898720

commit e19483da430ccd1da3a08dd1cebb87b425898720
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 17:04:51 2024 +0100

Unit struct constructor shall be resolved

Unit struct have a special constructor that should be added to the struct
namespace in order to be resolved later when called. As it is a function
it should be added in the value namespace.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(GlobbingVisitor::visit):
Add the struct constructor when the struct is a unit.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 4134b9a46202..75d9bb82131f 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -68,8 +68,13 @@ void
 GlobbingVisitor::visit (AST::StructStruct _item)
 {
   if (struct_item.get_visibility ().is_public ())
-ctx.insert_shadowable (struct_item.get_identifier (),
-  struct_item.get_node_id (), Namespace::Values);
+{
+  ctx.insert_shadowable (struct_item.get_identifier (),
+struct_item.get_node_id (), Namespace::Types);
+  if (struct_item.is_unit_struct ())
+   ctx.insert_shadowable (struct_item.get_identifier (),
+  struct_item.get_node_id (), Namespace::Values);
+}
 }
 
 void


[gcc/devel/rust/master] Merge commit 'f0b1cf01782ba975cfda32800c91076df78058d6^' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:9575360bad470025b131fa74fdc11ac28409cb9c

commit 9575360bad470025b131fa74fdc11ac28409cb9c
Merge: 1cae91f78a00 5329b9418820
Author: Thomas Schwinge 
Date:   Wed Apr 10 11:01:28 2024 +0200

Merge commit 'f0b1cf01782ba975cfda32800c91076df78058d6^' into HEAD

Diff:

 ChangeLog  |4 +
 MAINTAINERS|2 +
 gcc/ChangeLog  |  451 +++
 gcc/DATESTAMP  |2 +-
 gcc/Makefile.in|7 +
 gcc/analyzer/ChangeLog |7 +
 gcc/analyzer/pending-diagnostic.cc |   16 +-
 gcc/attribs.cc |   10 -
 gcc/bitmap.cc  |2 +-
 gcc/c-family/ChangeLog |   20 +
 gcc/c-family/c-ada-spec.cc |3 +-
 gcc/c-family/c-format.cc   |   12 +-
 gcc/c-family/c-opts.cc |5 +
 gcc/c-family/c.opt |4 +
 gcc/c/ChangeLog|   18 +
 gcc/c/c-decl.cc|4 +-
 gcc/c/c-parser.cc  |3 +-
 gcc/c/c-typeck.cc  |   12 +-
 gcc/cfgexpand.cc   |   24 +-
 gcc/config/aarch64/aarch64-sys-regs.def|   85 +
 gcc/config/aarch64/aarch64.h   |   20 +
 gcc/config/avr/avr-mcus.def|4 +-
 gcc/config/avr/gen-avr-mmcu-specs.cc   |  158 +-
 gcc/config/avr/specs.h |7 +-
 gcc/config/i386/constraints.md |   36 +-
 gcc/config/i386/darwin.h   |3 +-
 gcc/config/i386/darwin32-biarch.h  |3 -
 gcc/config/i386/darwin64-biarch.h  |3 -
 gcc/config/i386/i386-features.cc   |   42 +-
 gcc/config/i386/i386-protos.h  |1 -
 gcc/config/i386/i386.cc|   31 +-
 gcc/config/i386/i386.md|  129 +-
 gcc/config/i386/mmx.md |   69 +
 gcc/config/i386/predicates.md  |   65 +
 gcc/config/i386/sse.md |   34 +-
 gcc/config/riscv/riscv-vector-builtins-shapes.cc   |   17 +-
 gcc/config/riscv/riscv-vector-builtins.cc  |3 +-
 gcc/config/riscv/riscv.cc  |2 +-
 gcc/configure  |2 +-
 gcc/configure.ac   |2 +-
 gcc/cp/ChangeLog   |  143 +
 gcc/cp/Make-lang.in|2 +-
 gcc/cp/class.cc|   14 +-
 gcc/cp/constexpr.cc|   10 +
 gcc/cp/coroutines.cc   |4 +-
 gcc/cp/cp-objcp-common.cc  |1 -
 gcc/cp/cp-tree.h   |3 +-
 gcc/cp/decl.cc |   39 +-
 gcc/cp/decl2.cc|7 +-
 gcc/cp/except.cc   |   99 +-
 gcc/cp/lambda.cc   |4 +-
 gcc/cp/method.cc   |2 +
 gcc/cp/module.cc   |   25 +-
 gcc/cp/name-lookup.cc  |   17 +
 gcc/cp/parser.cc   |   43 +-
 gcc/cp/pt.cc   |   53 +-
 gcc/cp/semantics.cc|7 +-
 gcc/cp/tree.cc |5 +-
 gcc/d/ChangeLog|   23 +
 gcc/d/d-builtins.cc|   31 +-
 gcc/d/d-codegen.cc |   15 +-
 gcc/d/decl.cc  |   22 +-
 gcc/d/dmd/MERGE|2 +-
 gcc/d/dmd/aggregate.d  |2 +-
 gcc/d/dmd/aggregate.h  |1 +
 gcc/d/dmd/astcodegen.d |1 +
 gcc/d/dmd/astenums.d   |2 +-
 gcc/d/dmd/clone.d  |   17 +-
 gcc/d/dmd/constfold.d  |2 +-
 gcc/d/dmd/dcast.d  |   87 +-
 gcc/d/dmd/declaration.d|4 +-
 gcc/d/dmd/declaration.h|2 -
 gcc/d/dmd/dinterpret.d |2 +-
 gcc/d/dmd/dsymbol.h|2 -
 gcc/d/dmd/dsymbolsem.d |2 +-
 gcc/d/dmd/errors.h |2 -
 gcc/d/dmd/expression.h 

[gcc/devel/rust/master] Merge commit 'af3f0482367232d2d655e51bee382e98ddbfb117' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1cae91f78a006bcd494e4846142fc170099af71e

commit 1cae91f78a006bcd494e4846142fc170099af71e
Merge: 1af2c40d7595 af3f04823672
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:56:34 2024 +0200

Merge commit 'af3f0482367232d2d655e51bee382e98ddbfb117' into HEAD

Diff:


[gcc/devel/rust/master] Visit function return type in default resolver

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e84d67febe5805675d3f86e0e535702dfe67b78d

commit e84d67febe5805675d3f86e0e535702dfe67b78d
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 16:47:50 2024 +0100

Visit function return type in default resolver

Function return type was not properly visited in the default resolver
visitor pattern.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit
function return type.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index e2609d13c9a6..d805bc9a511d 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -79,6 +79,9 @@ DefaultResolver::visit (AST::Function )
  }
   }
 
+if (function.has_return_type ())
+  visit (function.get_return_type ());
+
 if (function.has_body ())
   function.get_definition ().value ()->accept_vis (*this);
   };


[gcc/devel/rust/master] Merge commit 'f89186f962421f6d972035fc4b4c20490e7b1c5b^' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1af2c40d7595c91f8c8f3573c1bec30556e35bb6

commit 1af2c40d7595c91f8c8f3573c1bec30556e35bb6
Merge: 17ee9c68cbc9 830d4659604e
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:55:56 2024 +0200

Merge commit 'f89186f962421f6d972035fc4b4c20490e7b1c5b^' into HEAD

Diff:

 ChangeLog  |8 +
 MAINTAINERS|6 +-
 contrib/ChangeLog  |   10 +
 contrib/test_installed |4 +
 contrib/unicode/gen_libstdcxx_unicode_data.py  |   30 +-
 gcc/ChangeLog  |  762 ++
 gcc/DATESTAMP  |2 +-
 gcc/analyzer/ChangeLog |   36 +
 gcc/analyzer/checker-event.cc  |   59 +-
 gcc/analyzer/region-model.cc   |  111 +-
 gcc/analyzer/state-purge.cc|9 +
 gcc/analyzer/supergraph.cc |4 +
 gcc/asan.h |7 +-
 gcc/builtins.cc|8 +-
 gcc/c-family/ChangeLog |   12 +
 gcc/c-family/c-opts.cc |5 +
 gcc/c-family/c-pch.cc  |   23 +-
 gcc/c/ChangeLog|   32 +
 gcc/c/c-convert.cc |3 +-
 gcc/c/c-decl.cc|9 +-
 gcc/c/c-tree.h |3 +-
 gcc/c/c-typeck.cc  |   36 +-
 gcc/common/config/riscv/riscv-common.cc|   14 +
 gcc/config/aarch64/aarch64-simd.md |   11 +-
 gcc/config/aarch64/aarch64.cc  |  129 +-
 gcc/config/arm/arm.cc  |2 +
 gcc/config/avr/avr-mcus.def|8 +-
 gcc/config/avr/avr.cc  | 7434 +++
 gcc/config/gcn/gcn.cc  |6 +-
 gcc/config/gcn/gcn.h   |   16 +-
 gcc/config/gcn/gcn.md  |   17 +-
 gcc/config/i386/constraints.md |4 +
 gcc/config/i386/i386-expand.cc |2 +-
 gcc/config/i386/i386-features.cc   |   26 +
 gcc/config/i386/i386.cc|   91 +-
 gcc/config/i386/i386.md|4 -
 gcc/config/loongarch/larchintrin.h |   16 +-
 gcc/config/loongarch/lasx.md   |   16 -
 gcc/config/loongarch/loongarch-def.h   |3 +
 gcc/config/loongarch/loongarch-opts.cc |2 -
 gcc/config/loongarch/loongarch-protos.h|1 +
 gcc/config/loongarch/loongarch.cc  |  577 +-
 gcc/config/loongarch/loongarch.md  |  125 +-
 gcc/config/loongarch/lsx.md|   11 -
 gcc/config/loongarch/predicates.md |   12 +
 gcc/config/loongarch/simd.md   |   18 +
 gcc/config/mips/mips-msa.md|   18 +-
 gcc/config/pa/pa.cc|  215 +-
 gcc/config/pa/pa.md|   90 +-
 gcc/config/riscv/generic-ooo.md|2 +-
 gcc/config/riscv/generic.md|2 +-
 gcc/config/riscv/riscv-c.cc|3 +-
 gcc/config/riscv/riscv-cores.def   |   11 +
 gcc/config/riscv/riscv-opts.h  |2 +
 gcc/config/riscv/riscv-protos.h|2 +-
 gcc/config/riscv/riscv-v.cc|   12 +-
 gcc/config/riscv/riscv-vector-builtins.cc  |   23 +-
 gcc/config/riscv/riscv-vsetvl.cc   |  255 +-
 gcc/config/riscv/riscv.cc  |  151 +-
 gcc/config/riscv/riscv.h   |5 +-
 gcc/config/riscv/riscv.md  |   20 +-
 gcc/config/riscv/riscv.opt |   14 +
 gcc/config/riscv/sifive-7.md   |2 +-
 gcc/config/riscv/sifive-p400.md|  174 +
 gcc/config/riscv/sifive-p600.md|  178 +
 gcc/config/riscv/thead.cc  |3 +-
 gcc/config/sol2.h  |2 +-
 gcc/config/sparc/sparc.h   |7 +
 gcc/config/xtensa/constraints.md   |   26 +-
 gcc/config/xtensa/predicates.md|7 +-
 gcc/config/xtensa/xtensa.cc|   46 +-
 gcc/config/xtensa/xtensa.md|   41 +-
 gcc/config/xtensa/xtensa.opt   |4 +-
 gcc/cp/ChangeLog   |  111 +
 gcc/cp/call.cc |   18 +-
 gcc/cp/constexpr.cc|1 +
 

[gcc/devel/rust/master] Change error message to match test

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:124d56a328163a8de49e01e9d88aaf6f6c5aa3e9

commit 124d56a328163a8de49e01e9d88aaf6f6c5aa3e9
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 17 13:53:21 2024 +0100

Change error message to match test

Error message did not match the test from the previous name resolver when
a given path cannot be resolved.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_root_path):
Change error message to match old resolver and test case.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-path.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index cdb506dacbe5..b0e52c454e9d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -266,8 +266,10 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
, size_t *offset,
{
  if (is_root)
{
- rust_error_at (seg.get_locus (),
-"failed to resolve root segment");
+ rust_error_at (expr.get_locus (), ErrorCode::E0425,
+"cannot find value %qs in this scope",
+expr.as_simple_path ().as_string ().c_str ());
+
  return new TyTy::ErrorType (expr.get_mappings ().get_hirid ());
}
  return root_tyty;


[gcc/devel/rust/master] Add support for ambiguous use declarations

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:6b1d14b72e1b38ce55389683436781b229ed51f8

commit 6b1d14b72e1b38ce55389683436781b229ed51f8
Author: Pierre-Emmanuel Patry 
Date:   Tue Jan 16 13:55:02 2024 +0100

Add support for ambiguous use declarations

Glob use declarations may lead to ambiguous situation where two
definitions with the same name are imported in a given scope. The
compiler now handles shadowable items inserted after non shadowable
items. An error is now thrown when multiple shadowable items are imported
and used in the same rib.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit): Adapt
resolved type to the new API.
(Early::visit_attributes): Retrieve the node id from the definition.
* resolve/rust-forever-stack.h: Change the return type of getter
functions. Those functions now return a definition type instead of a
node id.
* resolve/rust-forever-stack.hxx: Change member function 
implementation
in the forever stack to accomodate it's API changes.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use internal
node id. Emit an error when resolving multiple ambiguous values.
* resolve/rust-rib.cc (Rib::Definition::Definition): Add a default
constructor.
(Rib::Definition::is_ambiguous): Add a new function to determine
whether a function definition is ambiguous or not.
(Rib::Definition::to_string): Add a member function to convert a 
given
definition to a string.
(Rib::insert): Add new rules for value insertion in a rib. Insertion
order does not impact the result anymore: inserting a shadowable 
value
after a non shadowable one does not trigger an error anymore. All
shadowable values inserted in a rib are kepts until being replaced 
by a
non shadowable one.
(Rib::get): Return a definition instead of a node id.
* resolve/rust-rib.h: Update function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc 
(TopLevel::handle_use_glob):
Update return value container to match the new function's prototype.
(TopLevel::handle_use_dec): Likewise.
(flatten_glob): Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc   | 18 +++---
 gcc/rust/resolve/rust-forever-stack.h  | 10 ++--
 gcc/rust/resolve/rust-forever-stack.hxx| 39 ++--
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc| 17 --
 gcc/rust/resolve/rust-rib.cc   | 69 +-
 gcc/rust/resolve/rust-rib.h| 19 +-
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 41 +++--
 7 files changed, 142 insertions(+), 71 deletions(-)

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 982c696d2af1..af148b0c1c0d 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -152,9 +152,11 @@ Early::visit (AST::MacroInvocation )
 
   // 
https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
 
-  tl::optional definition = tl::nullopt;
+  tl::optional definition = tl::nullopt;
   if (path.get_segments ().size () == 1)
-definition = textual_scope.get (path.get_final_segment ().as_string ());
+definition
+  = textual_scope.get (path.get_final_segment ().as_string ())
+ .map ([] (NodeId id) { return Rib::Definition::NonShadowable (id); });
 
   // we won't have changed `definition` from `nullopt` if there are more
   // than one segments in our path
@@ -169,13 +171,13 @@ Early::visit (AST::MacroInvocation )
   return;
 }
 
-  insert_once (invoc, *definition);
+  insert_once (invoc, definition->get_node_id ());
 
   // now do we need to keep mappings or something? or insert "uses" into our
   // ForeverStack? can we do that? are mappings simpler?
   auto mappings = Analysis::Mappings::get ();
   AST::MacroRulesDefinition *rules_def = nullptr;
-  if (!mappings->lookup_macro_def (definition.value (), _def))
+  if (!mappings->lookup_macro_def (definition->get_node_id (), _def))
 {
   // Macro definition not found, maybe it is not expanded yet.
   return;
@@ -212,8 +214,8 @@ Early::visit_attributes (std::vector )
  continue;
}
 
- auto pm_def
-   = mappings->lookup_derive_proc_macro_def (definition.value ());
+ auto pm_def = mappings->lookup_derive_proc_macro_def (
+   definition->get_node_id ());
 
  rust_assert (pm_def.has_value ());
 
@@ -234,8 +236,8 @@ Early::visit_attributes (std::vector )
 "could not resolve attribute macro 

[gcc/devel/rust/master] Merge commit '2341df1cb9b3681bfefe29207887b2b3dc271a95' into HEAD [#2801]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0de2032ecf451e9fed2ad16c3ce771663fbc37a5

commit 0de2032ecf451e9fed2ad16c3ce771663fbc37a5
Merge: d1a0609b7e62 2341df1cb9b3
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:52:58 2024 +0200

Merge commit '2341df1cb9b3681bfefe29207887b2b3dc271a95' into HEAD [#2801]

Diff:


[gcc/devel/rust/master] Merge commit '4bd09ce06f50d266c992c984cc993384d5e6655e' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ca224bde2989de54fc33fae46df560b7f5af835e

commit ca224bde2989de54fc33fae46df560b7f5af835e
Merge: 4966574bdc77 4bd09ce06f50
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:45:29 2024 +0200

Merge commit '4bd09ce06f50d266c992c984cc993384d5e6655e' into HEAD

Diff:


[gcc/devel/rust/master] Merge commit '2341df1cb9b3681bfefe29207887b2b3dc271a95^' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:d1a0609b7e62b21d747dfaa0c0f84e51099bd952

commit d1a0609b7e62b21d747dfaa0c0f84e51099bd952
Merge: c9e59de17dd4 484f48f03cf9
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:51:48 2024 +0200

Merge commit '2341df1cb9b3681bfefe29207887b2b3dc271a95^' into HEAD

Diff:

 ChangeLog  |   10 +
 gcc/ChangeLog  |  214 +
 gcc/DATESTAMP  |2 +-
 gcc/attribs.h  |2 +-
 gcc/c-family/ChangeLog |6 +
 gcc/common.opt |2 +-
 gcc/config/aarch64/aarch64-cores.def   |1 +
 gcc/config/aarch64/aarch64-tune.md |2 +-
 gcc/config/aarch64/predicates.md   |6 +-
 gcc/config/i386/i386-options.cc|2 +-
 gcc/config/loongarch/loongarch.cc  |5 +
 gcc/config/mips/mips.cc|2 +
 gcc/config/riscv/riscv-opts.h  |9 +
 gcc/config/riscv/riscv-vsetvl.cc   |   63 +-
 gcc/config/riscv/riscv.opt |   14 +
 gcc/cp/ChangeLog   |   50 +
 gcc/cp/decl.cc |7 +-
 gcc/cp/decl2.cc|   10 +-
 gcc/cp/module.cc   |   24 +-
 gcc/cp/name-lookup.cc  |   15 +-
 gcc/cp/name-lookup.h   |3 +-
 gcc/cp/parser.cc   |   21 +-
 gcc/cp/pt.cc   |4 +-
 gcc/doc/extend.texi|  821 +-
 gcc/doc/invoke.texi|  233 +-
 gcc/gengtype.cc|4 +-
 gcc/gimple-lower-bitint.cc |   18 +-
 gcc/gimple-ssa-warn-access.cc  |9 +
 gcc/ipa-polymorphic-call.cc|1 -
 gcc/ipa-strub.cc   |   19 +-
 gcc/omp-expand.cc  |6 +-
 gcc/omp-general.cc |   21 +-
 gcc/predict.cc |  131 +-
 gcc/predict.def|   10 +
 gcc/rust/ChangeLog | 8325 
 gcc/sched-deps.cc  |   48 +-
 gcc/testsuite/ChangeLog| 1781 +
 .../g++.dg/cpp23/explicit-obj-diagnostics3.C   |  106 +-
 .../g++.dg/cpp23/explicit-obj-diagnostics9.C   |6 +
 gcc/testsuite/g++.dg/cpp2a/nontype-class61.C   |   25 +
 gcc/testsuite/g++.dg/cpp2a/nontype-class62.C   |8 +
 gcc/testsuite/g++.dg/modules/merge-16.h|   10 +
 gcc/testsuite/g++.dg/modules/merge-16_a.C  |7 +
 gcc/testsuite/g++.dg/modules/merge-16_b.C  |5 +
 gcc/testsuite/g++.dg/modules/pr113292_a.H  |   34 +
 gcc/testsuite/g++.dg/modules/pr113292_b.C  |   13 +
 gcc/testsuite/g++.dg/modules/pr113292_c.C  |   11 +
 gcc/testsuite/g++.dg/pr99966.C |2 +-
 gcc/testsuite/g++.target/loongarch/got-load.C  |   19 +
 gcc/testsuite/gcc.c-torture/compile/pr110251.c |   27 +
 gcc/testsuite/gcc.c-torture/compile/pr113221-1.c   |   12 +
 gcc/testsuite/gcc.dg/array-quals-1.c   |   20 +-
 gcc/testsuite/gcc.dg/atomic/stdatomic-flag-2.c |2 +-
 gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c   |2 +-
 gcc/testsuite/gcc.dg/bitint-70.c   |   14 +
 gcc/testsuite/gcc.dg/bitint-71.c   |   18 +
 gcc/testsuite/gcc.dg/bitint-72.c   |   16 +
 gcc/testsuite/gcc.dg/c23-tag-alias-2.c |2 +-
 gcc/testsuite/gcc.dg/c23-tag-alias-3.c |2 +-
 gcc/testsuite/gcc.dg/cmp-mem-const-3.c |2 +-
 gcc/testsuite/gcc.dg/cmp-mem-const-4.c |2 +-
 gcc/testsuite/gcc.dg/cmp-mem-const-5.c |2 +-
 gcc/testsuite/gcc.dg/cmp-mem-const-6.c |2 +-
 gcc/testsuite/gcc.dg/gnu23-tag-alias-3.c   |2 +-
 gcc/testsuite/gcc.dg/memcmp-1.c|   35 +
 gcc/testsuite/gcc.dg/pr111409.c|2 +-
 gcc/testsuite/gcc.dg/predict-18.c  |6 +-
 gcc/testsuite/gcc.dg/predict-23.c  |   11 +
 gcc/testsuite/gcc.dg/scantest-lto.c|1 +
 gcc/testsuite/gcc.dg/torture/bitint-50.c   |   31 +
 gcc/testsuite/gcc.dg/torture/inline-mem-cpy-1.c|1 +
 gcc/testsuite/gcc.dg/tree-ssa/gen-vect-2.c |2 +
 gcc/testsuite/gcc.dg/tree-ssa/gen-vect-25.c|2 +
 gcc/testsuite/gcc.dg/tree-ssa/predict-1.c  |   10 +
 gcc/testsuite/gcc.dg/tree-ssa/predict-2.c  |   11 +
 gcc/testsuite/gcc.dg/tree-ssa/predict-3.c  |   15 +
 

[gcc/devel/rust/master] borrowck: Remove block braces to satisfy GNU style

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c90a9ada247d96025562be15780dba3f3d1f9ec0

commit c90a9ada247d96025562be15780dba3f3d1f9ec0
Author: Jakub Dupak 
Date:   Mon Apr 1 14:06:33 2024 +0200

borrowck: Remove block braces to satisfy GNU style

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (renumber_places):
Remove unecessary braces.
(Dump::go): Remove unecessary braces.
(Dump::visit): Remove unecessary braces.
(Dump::visit_scope): Remove unecessary braces.
* checks/errors/borrowck/rust-bir-fact-collector.h (class 
FactCollector):
Remove unecessary braces.
(points): Remove unecessary braces.
* checks/errors/borrowck/rust-bir-free-region.h: Remove unecessary 
braces.
* checks/errors/borrowck/rust-bir-place.h: Remove unecessary braces.
* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go):
Remove unecessary braces.
* checks/errors/borrowck/rust-function-collector.h: Remove 
unecessary braces.

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 47 +---
 .../errors/borrowck/rust-bir-fact-collector.h  | 87 +++---
 .../checks/errors/borrowck/rust-bir-free-region.h  | 16 +---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 17 ++---
 .../checks/errors/borrowck/rust-borrow-checker.cc  |  6 +-
 .../errors/borrowck/rust-function-collector.h  |  4 +-
 6 files changed, 56 insertions(+), 121 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 51dd14363506..a39f145f8f95 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -42,13 +42,9 @@ renumber_places (const Function , std::vector 
_map)
 {
   const Place  = func.place_db[in_id];
   if (place.kind == Place::VARIABLE || place.kind == Place::TEMPORARY)
-   {
- place_map[in_id] = next_out_id++;
-   }
+   place_map[in_id] = next_out_id++;
   else
-   {
- place_map[in_id] = INVALID_PLACE;
-   }
+   place_map[in_id] = INVALID_PLACE;
 }
 }
 
@@ -138,10 +134,9 @@ Dump::go (bool enable_simplify_cfg)
  stream << ";\n";
}
   if (!bb_terminated)
-   {
- stream << indentation << indentation << "goto -> bb"
-<< bb_fold_map[bb.successors.at (0)] << ";\t\t" << i++ << "\n";
-   }
+   stream << indentation << indentation << "goto -> bb"
+  << bb_fold_map[bb.successors.at (0)] << ";\t\t" << i++ << "\n";
+
   stream << indentation << "}\n";
 }
 
@@ -276,15 +271,13 @@ void
 Dump::visit (const CallExpr )
 {
   stream << "Call(";
-  if (auto fn_type
-  = func.place_db[expr.get_callable ()].tyty->try_as ())
-{
-  stream << fn_type->get_identifier ();
-}
+  auto maybe_fn_type
+= func.place_db[expr.get_callable ()].tyty->try_as ();
+  if (maybe_fn_type)
+stream << maybe_fn_type->get_identifier ();
   else
-{
-  visit_move_place (expr.get_callable ());
-}
+visit_move_place (expr.get_callable ());
+
   stream << ")(";
   print_comma_separated (stream, expr.get_arguments (),
 [this] (PlaceId place_id) {
@@ -321,13 +314,9 @@ void
 Dump::visit (const Assignment )
 {
   if (func.place_db[expr.get_rhs ()].is_rvalue ())
-{
-  visit_move_place (expr.get_rhs ());
-}
+visit_move_place (expr.get_rhs ());
   else
-{
-  visit_place (expr.get_rhs ());
-}
+visit_place (expr.get_rhs ());
 }
 
 std::ostream &
@@ -346,9 +335,8 @@ Dump::visit_scope (ScopeId id, size_t depth)
 return;
 
   if (id > 1)
-{
-  indent (depth) << "scope " << id - 1 << " {\n";
-}
+indent (depth) << "scope " << id - 1 << " {\n";
+
   for (auto  : scope.locals)
 {
   indent (depth + 1) << "let _";
@@ -357,9 +345,8 @@ Dump::visit_scope (ScopeId id, size_t depth)
   stream << ";\n";
 }
   for (auto  : scope.children)
-{
-  visit_scope (child, (id >= 1) ? depth + 1 : depth);
-}
+visit_scope (child, (id >= 1) ? depth + 1 : depth);
+
   if (id > 1)
 indent (depth) << "}\n";
 }
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
index 17c198e0fa7f..527ae65606cc 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -67,9 +67,8 @@ class FactCollector : public Visitor
   {
 std::vector free_regions;
 for (size_t i = 0; i < size; i++)
-  {
-   free_regions.push_back (region_binder.get_next_free_region ());
-  }
+  free_regions.push_back (region_binder.get_next_free_region ());
+
 return FreeRegions (std::move (free_regions));
   }
 
@@ -129,9 +128,8 @@ protected: // 

[gcc/devel/rust/master] Merge commit 'a5258f3a11ab577835ef5e93be5cb65ec9e44132^' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d2bcecd7fd914adf55daac7d36745b03b3279c49

commit d2bcecd7fd914adf55daac7d36745b03b3279c49
Merge: ca224bde2989 db4e496aadf1
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:45:56 2024 +0200

Merge commit 'a5258f3a11ab577835ef5e93be5cb65ec9e44132^' into HEAD

Diff:

 gcc/config/aarch64/aarch64.cc   | 11 +++
 gcc/testsuite/gcc.target/aarch64/pr112573.c | 15 +++
 2 files changed, 26 insertions(+)


[gcc/devel/rust/master] borrowck: BIR: make BIR visitor const

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:42ec29cacf4a16586bd30611b116cfff5a549c5e

commit 42ec29cacf4a16586bd30611b116cfff5a549c5e
Author: Jakub Dupak 
Date:   Tue Feb 27 20:22:17 2024 +0100

borrowck: BIR: make BIR visitor const

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): const
visitor
* checks/errors/borrowck/rust-bir-dump.h: const visitor
* checks/errors/borrowck/rust-bir-visitor.h: const visitor
* checks/errors/borrowck/rust-bir.h: const getter

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 14 +++---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.h| 14 +++---
 gcc/rust/checks/errors/borrowck/rust-bir-visitor.h | 14 +++---
 gcc/rust/checks/errors/borrowck/rust-bir.h |  6 +-
 4 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 320b653f830a..6f1579df1d9e 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -155,7 +155,7 @@ Dump::go (bool enable_simplify_cfg)
   stream << "}\n";
 }
 void
-Dump::visit (Statement )
+Dump::visit (const Statement )
 {
   statement_place = stmt.get_place ();
   switch (stmt.get_kind ())
@@ -247,7 +247,7 @@ Dump::visit_move_place (PlaceId place_id)
 }
 
 void
-Dump::visit (BorrowExpr )
+Dump::visit (const BorrowExpr )
 {
   stream << "&";
   visit_lifetime (statement_place);
@@ -268,7 +268,7 @@ Dump::visit_lifetime (PlaceId place_id)
 }
 
 void
-Dump::visit (InitializerExpr )
+Dump::visit (const InitializerExpr )
 {
   stream << "{";
   print_comma_separated (stream, expr.get_values (), [this] (PlaceId place_id) 
{
@@ -278,7 +278,7 @@ Dump::visit (InitializerExpr )
 }
 
 void
-Dump::visit (CallExpr )
+Dump::visit (const CallExpr )
 {
   stream << "Call(";
   if (auto fn_type
@@ -305,7 +305,7 @@ Dump::visit (CallExpr )
 }
 
 void
-Dump::visit (Operator<1> )
+Dump::visit (const Operator<1> )
 {
   stream << "Operator(";
   visit_move_place (expr.get_operand<0> ());
@@ -313,7 +313,7 @@ Dump::visit (Operator<1> )
 }
 
 void
-Dump::visit (Operator<2> )
+Dump::visit (const Operator<2> )
 {
   stream << "Operator(";
   visit_move_place (expr.get_operand<0> ());
@@ -323,7 +323,7 @@ Dump::visit (Operator<2> )
 }
 
 void
-Dump::visit (Assignment )
+Dump::visit (const Assignment )
 {
   if (func.place_db[expr.get_rhs ()].is_rvalue ())
 {
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
index cc3f9cdc7386..9d6babd00535 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
@@ -49,16 +49,16 @@ public:
   void go (bool enable_simplify_cfg = false);
 
 protected:
-  void visit (Statement ) override;
+  void visit (const Statement ) override;
   void visit_place (PlaceId place_id);
   void visit_move_place (PlaceId place_id);
-  void visit (BorrowExpr ) override;
+  void visit (const BorrowExpr ) override;
   void visit_lifetime (PlaceId place_id);
-  void visit (InitializerExpr ) override;
-  void visit (CallExpr ) override;
-  void visit (Operator<1> ) override;
-  void visit (Operator<2> ) override;
-  void visit (Assignment ) override;
+  void visit (const InitializerExpr ) override;
+  void visit (const CallExpr ) override;
+  void visit (const Operator<1> ) override;
+  void visit (const Operator<2> ) override;
+  void visit (const Assignment ) override;
   void visit_scope (ScopeId id, size_t depth = 1);
 
   std::ostream  (size_t depth);
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
index 7ad62f700dbc..2371b8bb5cec 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
@@ -32,13 +32,13 @@ class CallExpr;
 class Visitor
 {
 public:
-  virtual void visit (Statement ) = 0;
-  virtual void visit (InitializerExpr ) = 0;
-  virtual void visit (Operator<1> ) = 0;
-  virtual void visit (Operator<2> ) = 0;
-  virtual void visit (BorrowExpr ) = 0;
-  virtual void visit (Assignment ) = 0;
-  virtual void visit (CallExpr ) = 0;
+  virtual void visit (const Statement ) = 0;
+  virtual void visit (const InitializerExpr ) = 0;
+  virtual void visit (const Operator<1> ) = 0;
+  virtual void visit (const Operator<2> ) = 0;
+  virtual void visit (const BorrowExpr ) = 0;
+  virtual void visit (const Assignment ) = 0;
+  virtual void visit (const CallExpr ) = 0;
 };
 
 class Visitable
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h 
b/gcc/rust/checks/errors/borrowck/rust-bir.h
index f8a2151aaf8c..d21cb90abf52 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir.h
@@ -137,6 +137,10 @@ public:
 
 public:
   std::vector 

[gcc/devel/rust/master] Merge commit '7a6906c8d80e437a97c780370a8fec4e00561c7b' into HEAD [#2288]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4966574bdc77ab3a0e6ff8bdebb8b85ffb44c851

commit 4966574bdc77ab3a0e6ff8bdebb8b85ffb44c851
Merge: 041fef1b5810 7a6906c8d80e
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:43:34 2024 +0200

Merge commit '7a6906c8d80e437a97c780370a8fec4e00561c7b' into HEAD [#2288]

Diff:


[gcc/devel/rust/master] borrowck: BIR: use callable API

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ba7e9a78f6c0f875d94db51c9fc64fec64477874

commit ba7e9a78f6c0f875d94db51c9fc64fec64477874
Author: Jakub Dupak 
Date:   Fri Feb 2 14:33:56 2024 +0100

borrowck: BIR: use callable API

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
(ExprStmtBuilder::visit):
Use callable API

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/rust-bir-builder-expr-stmt.cc  | 23 +-
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index 2c916294ca7a..ea8107b1fb76 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -248,25 +248,12 @@ ExprStmtBuilder::visit (HIR::CallExpr )
   PlaceId fn = visit_expr (*expr.get_fnexpr ());
   std::vector arguments = visit_list (expr.get_arguments ());
 
-  auto *call_type = ctx.place_db[fn].tyty;
-  if (auto fn_type = call_type->try_as ())
-{
-  for (size_t i = 0; i < fn_type->get_params ().size (); ++i)
-   {
- coercion_site (arguments[i], fn_type->get_params ()[i].second);
-   }
-}
-  else if (auto fn_ptr_type = call_type->try_as ())
-{
-  for (size_t i = 0; i < fn_ptr_type->get_params ().size (); ++i)
-   {
- coercion_site (arguments[i],
-fn_ptr_type->get_params ()[i].get_tyty ());
-   }
-}
-  else
+  const auto fn_type
+= ctx.place_db[fn].tyty->as ();
+
+  for (size_t i = 0; i < fn_type->get_num_params (); ++i)
 {
-  rust_unreachable ();
+  coercion_site (arguments[i], fn_type->get_param_type_at (i));
 }
 
   return_expr (new CallExpr (fn, std::move (arguments)), lookup_type (expr),


[gcc/devel/rust/master] Fix grammar as pointed out by Marc

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:edd018d8c7b7a0229e10430ee61ac50f390670c2

commit edd018d8c7b7a0229e10430ee61ac50f390670c2
Author: Jasmine Tang 
Date:   Fri Apr 5 02:25:48 2024 -0700

Fix grammar as pointed out by Marc

ChangeLog:

* README.md (gccrs-workspace]): like-wise.

Diff:
---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 502b61f0ab1e..2ba59d3a6b24 100644
--- a/README.md
+++ b/README.md
@@ -75,11 +75,11 @@ $ make
 
 ```
 
-Alternatively, a docker environment is avaiable for ARM-based Mac contributors.
+Alternatively, a docker environment is available for ARM-based Mac 
contributors.
 
 Please visit 
[gccrs-workspace](https://github.com/badumbatish/gccrs-workspace). 
  
-The image is based on Ubuntu ARM and came with dependencies all fetched.
+The image is based on Ubuntu ARM and comes with dependencies all fetched.
 
  Running GCC Rust


[gcc/devel/rust/master] Merge commit 'fc59a3995cb46c190c0efb0431ad204e399975c4' into HEAD [#2183]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:041fef1b58109237f972d28f8225f72c0fc1a75a

commit 041fef1b58109237f972d28f8225f72c0fc1a75a
Merge: 0ba53bfa815a fc59a3995cb4
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:34:02 2024 +0200

Merge commit 'fc59a3995cb46c190c0efb0431ad204e399975c4' into HEAD [#2183]

Diff:


[gcc/devel/rust/master] borrowck: Bump copyright notice

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ff196e451c6b4eb9736b2331c6a108b85f9d260b

commit ff196e451c6b4eb9736b2331c6a108b85f9d260b
Author: Jakub Dupak 
Date:   Wed Apr 3 10:30:15 2024 +0200

borrowck: Bump copyright notice

gcc/rust/ChangeLog:

* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs: Bump 
copyright.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Bump copyright.
* checks/errors/borrowck/polonius/rust-polonius-ffi.h: Bump 
copyright.
* checks/errors/borrowck/polonius/rust-polonius.h: Bump copyright.
* checks/errors/borrowck/rust-bir-dump.cc: Bump copyright.
* checks/errors/borrowck/rust-bir-fact-collector.h: Bump copyright.
* checks/errors/borrowck/rust-bir-free-region.h: Bump copyright.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/ffi-polonius/src/gccrs_ffi.rs  |  2 +-
 .../checks/errors/borrowck/ffi-polonius/src/lib.rs |  2 +-
 .../errors/borrowck/polonius/rust-polonius-ffi.h   |  2 +-
 .../checks/errors/borrowck/polonius/rust-polonius.h|  2 +-
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 18 ++
 .../checks/errors/borrowck/rust-bir-fact-collector.h   |  2 +-
 gcc/rust/checks/errors/borrowck/rust-bir-free-region.h | 18 ++
 7 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
index 3a849444bbc3..5b4e6d39d21c 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
index a9aa8106b69a..819c34a93749 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius-ffi.h 
b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius-ffi.h
index 500d25a3222e..ebfddab76170 100644
--- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius-ffi.h
+++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius-ffi.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h 
b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
index df746dd0c767..239cc3440117 100644
--- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
+++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index a39f145f8f95..d3398b6f405a 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -1,3 +1,21 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// 
+
 #include "rust-system.h"
 #include "rust-bir-dump.h"
 #include "rust-diagnostics.h"
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
index 527ae65606cc..bb8fedaf3db7 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h
index e5d6ef3c98be..b8d73c9c070d 100644

[gcc/devel/rust/master] Improve parsing of raw string literals

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e36c3ece68cecba3170ab2d35de6e0a0c8bac40e

commit e36c3ece68cecba3170ab2d35de6e0a0c8bac40e
Author: Owen Avery 
Date:   Tue Mar 26 21:10:05 2024 -0400

Improve parsing of raw string literals

gcc/rust/ChangeLog:

* lex/rust-lex.cc
(Lexer::parse_raw_string):
Bring handling of edge cases to par with parse_raw_byte_string.

gcc/testsuite/ChangeLog:

* rust/compile/raw-string-loc.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/lex/rust-lex.cc | 21 ++---
 gcc/testsuite/rust/compile/raw-string-loc.rs |  6 ++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 7c37e83d6cb7..e5c9148976c1 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -2152,6 +2152,9 @@ Lexer::parse_raw_string (location_t loc, int 
initial_hash_count)
   str.reserve (16); // some sensible default
 
   int length = 1 + initial_hash_count;
+  current_column += length;
+
+  const location_t string_begin_locus = get_current_location ();
 
   if (initial_hash_count > 0)
 skip_input (initial_hash_count - 1);
@@ -2162,10 +2165,11 @@ Lexer::parse_raw_string (location_t loc, int 
initial_hash_count)
 rust_error_at (get_current_location (), "raw string has no opening 
%<\"%>");
 
   length++;
+  current_column++;
   skip_input ();
   current_char = peek_input ();
 
-  while (!current_char.is_eof ())
+  while (true)
 {
   if (current_char.value == '"')
{
@@ -2186,19 +2190,30 @@ Lexer::parse_raw_string (location_t loc, int 
initial_hash_count)
  skip_input (initial_hash_count);
  current_char = peek_input ();
  length += initial_hash_count + 1;
+ current_column += initial_hash_count + 1;
  break;
}
}
+  else if (current_char.is_eof ())
+   {
+ rust_error_at (string_begin_locus, "unended raw string literal");
+ return Token::make (END_OF_FILE, get_current_location ());
+   }
 
   length++;
+  current_column++;
+  if (current_char == '\n')
+   {
+ current_line++;
+ current_column = 1;
+ start_line (current_line, max_column_hint);
+   }
 
   str += current_char.as_string ();
   skip_input ();
   current_char = peek_input ();
 }
 
-  current_column += length;
-
   loc += length - 1;
 
   str.shrink_to_fit ();
diff --git a/gcc/testsuite/rust/compile/raw-string-loc.rs 
b/gcc/testsuite/rust/compile/raw-string-loc.rs
new file mode 100644
index ..70977510ba38
--- /dev/null
+++ b/gcc/testsuite/rust/compile/raw-string-loc.rs
@@ -0,0 +1,6 @@
+const X: &'static str = r#"12
+12"#;
+
+BREAK
+// { dg-error "unrecognised token" "" { target *-*-* } .-1 }
+// { dg-excess-errors "error 'failed to parse item' does not have location" }


[gcc/devel/rust/master] Merge commit 'fc59a3995cb46c190c0efb0431ad204e399975c4^' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:0ba53bfa815ad64c834ad726a8cf81d7acf1c49f

commit 0ba53bfa815ad64c834ad726a8cf81d7acf1c49f
Merge: edd018d8c7b7 ee0717da1eb5
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:20:22 2024 +0200

Merge commit 'fc59a3995cb46c190c0efb0431ad204e399975c4^' into HEAD

Diff:

 ChangeLog  |   15 +
 MAINTAINERS|1 +
 config/ChangeLog   |4 +
 config/acinclude.m4|   22 -
 contrib/ChangeLog  |   10 +
 contrib/dg-extract-results.py  |3 +-
 contrib/unicode/gen_libstdcxx_unicode_data.py  |5 +-
 gcc/BASE-VER   |2 +-
 gcc/ChangeLog  | 1125 +++
 gcc/DATESTAMP  |2 +-
 gcc/ada/ChangeLog  |  201 ++
 gcc/analyzer/ChangeLog |   20 +
 gcc/analyzer/analyzer.h|3 +
 gcc/analyzer/constraint-manager.cc |2 +-
 gcc/analyzer/region-model-manager.cc   |6 +
 gcc/analyzer/sm-taint.cc   |  114 +-
 gcc/builtins.cc|5 +-
 gcc/c-family/ChangeLog |   30 +
 gcc/c-family/c-ada-spec.cc |2 +
 gcc/c-family/c-cppbuiltin.cc   |1 +
 gcc/c-family/c-pretty-print.cc |   12 +
 gcc/c/ChangeLog|   43 +
 gcc/c/c-parser.cc  |  155 +-
 gcc/c/c-tree.h |2 +
 gcc/c/c-typeck.cc  |  113 +-
 gcc/cfgexpand.cc   |   30 +-
 gcc/config.gcc |2 +-
 gcc/config.in  |   12 +
 gcc/config/aarch64/aarch64-ldp-fusion.cc   |   76 +-
 gcc/config/aarch64/aarch64-protos.h|1 +
 gcc/config/aarch64/aarch64-simd.md |  134 +-
 gcc/config/aarch64/aarch64-sve-builtins-sme.def|   53 +-
 gcc/config/aarch64/aarch64-sve-builtins-sve2.def   |1 +
 gcc/config/aarch64/aarch64-sve-builtins.cc |   48 +-
 gcc/config/aarch64/aarch64-sve-builtins.def|   13 -
 gcc/config/aarch64/aarch64-sve-builtins.h  |4 -
 gcc/config/aarch64/aarch64.cc  |  124 +-
 gcc/config/aarch64/aarch64.h   |6 +
 gcc/config/aarch64/aarch64.opt |4 +-
 gcc/config/aarch64/iterators.md|2 +
 gcc/config/arm/arm_neon.h  | 2032 +---
 gcc/config/arm/arm_neon_builtins.def   |   12 +
 gcc/config/arm/iterators.md|6 +
 gcc/config/arm/neon.md |  249 +++
 gcc/config/arm/unspecs.md  |8 +
 gcc/config/avr/avr-arch.h  |   40 +-
 gcc/config/avr/avr-devices.cc  |   20 +-
 gcc/config/avr/avr-mcus.def|   56 +-
 gcc/config/avr/avr.cc  |   75 +-
 gcc/config/avr/avr.h   |2 +
 gcc/config/avr/avr.opt |   16 +-
 gcc/config/avr/driver-avr.cc   |   27 +-
 gcc/config/avr/gen-avr-mmcu-specs.cc   |  115 +-
 gcc/config/avr/gen-avr-mmcu-texi.cc|3 +-
 gcc/config/avr/specs.h |   10 +-
 gcc/config/i386/i386-c.cc  |7 +
 gcc/config/i386/i386.opt   |3 +-
 gcc/config/i386/sse.md |4 -
 gcc/config/loongarch/genopts/genstr.sh |2 +-
 gcc/config/loongarch/genopts/loongarch-strings |8 +-
 gcc/config/loongarch/genopts/loongarch.opt.in  |   54 +-
 gcc/config/loongarch/lasx.md   |4 +-
 gcc/config/loongarch/loongarch-builtins.cc |6 +-
 gcc/config/loongarch/loongarch-c.cc|2 +-
 gcc/config/loongarch/loongarch-cpu.cc  |2 +-
 gcc/config/loongarch/loongarch-def.cc  |   14 +-
 gcc/config/loongarch/loongarch-def.h   |  120 +-
 gcc/config/loongarch/loongarch-driver.cc   |5 +-
 gcc/config/loongarch/loongarch-opts.cc |   34 +-
 gcc/config/loongarch/loongarch-opts.h  |   26 +-
 gcc/config/loongarch/loongarch-str.h   |7 +-
 gcc/config/loongarch/loongarch.cc  |  122 +-
 gcc/config/loongarch/loongarch.h   |2 +-
 gcc/config/loongarch/loongarch.md  |  198 +-
 gcc/config/loongarch/loongarch.opt |   58 +-
 gcc/config/loongarch/lsx.md|4 

[gcc/devel/rust/master] borrowck: Free region representation

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b783c3ce70167c218213fad90a61dba7eec733db

commit b783c3ce70167c218213fad90a61dba7eec733db
Author: Jakub Dupak 
Date:   Tue Feb 27 21:07:03 2024 +0100

borrowck: Free region representation

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-free-region.h: New file.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../checks/errors/borrowck/rust-bir-free-region.h  | 107 +
 1 file changed, 107 insertions(+)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h
new file mode 100644
index ..0560a894ab06
--- /dev/null
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h
@@ -0,0 +1,107 @@
+#ifndef RUST_BIR_FREE_REGION_H
+#define RUST_BIR_FREE_REGION_H
+
+#include "rust-diagnostics.h"
+#include "polonius/rust-polonius-ffi.h"
+
+namespace Rust {
+
+using FreeRegion = size_t;
+
+class FreeRegions
+{
+  std::vector regions;
+
+public:
+  WARN_UNUSED_RESULT bool has_regions () const { return !regions.empty (); }
+  decltype (regions)::const_iterator begin () const { return regions.begin (); 
}
+  decltype (regions)::const_iterator end () const { return regions.end (); }
+  size_t size () const { return regions.size (); }
+  FreeRegion [] (size_t i) { return regions.at (i); }
+  const FreeRegion [] (size_t i) const { return regions.at (i); }
+  const std::vector _regions () const { return regions; }
+  void set_from (std::vector &)
+  {
+this->regions.clear ();
+for (auto  : regions)
+  {
+   this->regions.push_back ({region});
+  }
+  }
+
+  WARN_UNUSED_RESULT FreeRegions prepend (FreeRegion region) const
+  {
+std::vector new_regions = {region};
+new_regions.insert (new_regions.end (), regions.begin (), regions.end ());
+return FreeRegions (std::move (new_regions));
+  }
+
+  FreeRegions (std::vector &) : regions (regions) {}
+
+  WARN_UNUSED_RESULT std::string to_string () const
+  {
+std::stringstream result;
+for (auto  : regions)
+  {
+   result << region;
+   result << ", ";
+  }
+// Remove the last ", " from the string.
+if (result.tellg () > 2)
+  result.seekp (-2, std::ios_base::cur);
+
+return result.str ();
+  }
+};
+
+class RegionBinder
+{
+  FreeRegion _free_region;
+
+public:
+  explicit RegionBinder (FreeRegion _free_region)
+: next_free_region (next_free_region)
+  {}
+
+  WARN_UNUSED_RESULT FreeRegion get_next_free_region () const
+  {
+return next_free_region++;
+  }
+
+  FreeRegions bind_regions (std::vector regions,
+   FreeRegions parent_free_regions)
+  {
+std::vector free_regions;
+for (auto  : regions)
+  {
+   if (region.is_early_bound ())
+ {
+   free_regions.push_back (parent_free_regions[region.get_index ()]);
+ }
+   else if (region.is_static ())
+ {
+   free_regions.push_back (0);
+ }
+   else if (region.is_anonymous ())
+ {
+   free_regions.push_back (get_next_free_region ());
+ }
+   else if (region.is_named ())
+ {
+   rust_unreachable (); // FIXME
+ }
+   else
+ {
+   rust_sorry_at (UNKNOWN_LOCATION, "Unimplemented");
+   rust_unreachable ();
+ }
+  }
+// This is necesarry because of clash of current gcc and gcc4.8.
+FreeRegions free_regions_final{std::move (free_regions)};
+return free_regions_final;
+  }
+};
+
+} // namespace Rust
+
+#endif // RUST_BIR_FREE_REGION_H


[gcc/devel/rust/master] Add an alternative solution on MacOS

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:19719f4f2d230b39937b6977f81164a59acabcd7

commit 19719f4f2d230b39937b6977f81164a59acabcd7
Author: Jasmine Tang 
Date:   Thu Apr 4 20:02:26 2024 -0700

Add an alternative solution on MacOS

For #2937.
ChangeLog:

* README.md (gccrs-workspace]): like-wise.

Diff:
---
 README.md | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/README.md b/README.md
index 31df8df5138a..502b61f0ab1e 100644
--- a/README.md
+++ b/README.md
@@ -75,6 +75,12 @@ $ make
 
 ```
 
+Alternatively, a docker environment is avaiable for ARM-based Mac contributors.
+
+Please visit 
[gccrs-workspace](https://github.com/badumbatish/gccrs-workspace). 
+ 
+The image is based on Ubuntu ARM and came with dependencies all fetched.
+
  Running GCC Rust
 
 Running the compiler itself without make install we can simply invoke the 
compiler proper:


  1   2   3   4   5   6   >