[PATCH] C++: add type checking for static local vector variable in template

2021-09-01 Thread wangpc via Gcc-patches
From: wangpc 

---
 gcc/cp/pt.c|  8 +++-
 .../aarch64/sve/static-var-in-template.C   | 18 ++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 
gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f0aa626ab723..988f4cb1e73f 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14731,7 +14731,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t 
complain)
 even if its underlying type is not.  */
  TYPE_DEPENDENT_P_VALID (TREE_TYPE (r)) = false;
  }
-
+/* We should verify static local variable's type
+since vector type does not have a fixed size.  */
+if (TREE_STATIC (t)
+  &&!verify_type_context (input_location, TCTX_STATIC_STORAGE, type))
+{
+  RETURN (error_mark_node);
+}
layout_decl (r, 0);
   }
   break;
diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
new file mode 100644
index ..26d397ca565d
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+int i = 0;
+static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+f<2>();
+return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */
-- 
2.33.0.windows.1



[PATCH] C++: add type checking for static local vector variable in template

2021-09-06 Thread wangpc via Gcc-patches
This patch adds type checking for static local vector variable in
C++ template, both AArch64 SVE and RISCV RVV are of sizeless type
and thay all have this issue.

2021-08-06  wangpc  

gcc/cp/ChangeLog

* pt.c (tsubst_decl): Add type checking.

gcc/testsuite/ChangeLog

* g++.target/aarch64/sve/static-var-in-template.C: New test.
---
 gcc/cp/pt.c|  8 +++-
 .../aarch64/sve/static-var-in-template.C   | 18 ++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 
gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f0aa626ab723..988f4cb1e73f 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14731,7 +14731,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t 
complain)
 even if its underlying type is not.  */
  TYPE_DEPENDENT_P_VALID (TREE_TYPE (r)) = false;
  }
-
+/* We should verify static local variable's type
+since vector type does not have a fixed size.  */
+if (TREE_STATIC (t)
+  &&!verify_type_context (input_location, TCTX_STATIC_STORAGE, type))
+{
+  RETURN (error_mark_node);
+}
layout_decl (r, 0);
   }
   break;
diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
new file mode 100644
index ..26d397ca565d
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+int i = 0;
+static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+f<2>();
+return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */
-- 
2.33.0.windows.1



[PATCH] C++: add type checking for static local vector variable in template

2021-09-16 Thread wangpc via Gcc-patches
This patch adds type checking for static local vector variable in
C++ template, both AArch64 SVE and RISCV RVV are of sizeless type
and they all have this issue.

2021-08-06  wangpc  

gcc/cp/ChangeLog

* pt.c (tsubst_decl): Add type checking.

gcc/testsuite/ChangeLog

* g++.target/aarch64/sve/static-var-in-template.C: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 90111e4c786..e3a06ea0858 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7520,6 +7520,12 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
   && DECL_INITIALIZED_IN_CLASS_P (decl))
 check_static_variable_definition (decl, type);
 
+  if (VAR_P (decl)
+  && DECL_FUNCTION_SCOPE_P (decl)
+  && TREE_STATIC (decl))
+verify_type_context (DECL_SOURCE_LOCATION (decl),
+ TCTX_STATIC_STORAGE, type);
+
   if (init && TREE_CODE (decl) == FUNCTION_DECL)
 {
   tree clone;
diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
new file mode 100644
index 000..c2395d18d50
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+f<2>();
+return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */
-- 
2.33.0.windows.1



[PATCH] C++: add type checking for static local vector variable in template

2021-09-16 Thread wangpc via Gcc-patches
This patch adds type checking for static local vector variable in
C++ template, both AArch64 SVE and RISCV RVV are of sizeless type
and they all have this issue.

2021-08-06  wangpc  

gcc/cp/ChangeLog

* decl.c (cp_finish_decl): Add type checking.

gcc/testsuite/ChangeLog

* g++.target/aarch64/sve/static-var-in-template.C: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 90111e4c786..e3a06ea0858 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7520,6 +7520,12 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
   && DECL_INITIALIZED_IN_CLASS_P (decl))
 check_static_variable_definition (decl, type);
 
+  if (VAR_P (decl)
+  && DECL_FUNCTION_SCOPE_P (decl)
+  && TREE_STATIC (decl))
+verify_type_context (DECL_SOURCE_LOCATION (decl),
+ TCTX_STATIC_STORAGE, type);
+
   if (init && TREE_CODE (decl) == FUNCTION_DECL)
 {
   tree clone;
diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
new file mode 100644
index 000..c2395d18d50
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+f<2>();
+return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */
-- 
2.33.0.windows.1



[PATCH v2] C++: add type checking for static local vector variable in template

2021-09-16 Thread wangpc via Gcc-patches
This patch adds type checking for static local vector variable in
C++ template, both AArch64 SVE and RISCV RVV are of sizeless type
and they all have this issue.

2021-08-06  wangpc  

gcc/cp/ChangeLog

* decl.c (cp_finish_decl): Add type checking.

gcc/testsuite/ChangeLog

* g++.target/aarch64/sve/static-var-in-template.C: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 90111e4c786..21a6be12719 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7520,6 +7520,13 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
   && DECL_INITIALIZED_IN_CLASS_P (decl))
 check_static_variable_definition (decl, type);
 
+  if (!processing_template_decl
+  && VAR_P (decl)
+  && DECL_FUNCTION_SCOPE_P (decl)
+  && TREE_STATIC (decl))
+verify_type_context (DECL_SOURCE_LOCATION (decl),
+ TCTX_STATIC_STORAGE, type);
+
   if (init && TREE_CODE (decl) == FUNCTION_DECL)
 {
   tree clone;
diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
new file mode 100644
index 000..c2395d18d50
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+f<2>();
+return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */
-- 
2.33.0.windows.1



[PATCH v2] C++: add type checking for static local vector variable in template

2021-09-17 Thread wangpc via Gcc-patches
This patch moves verify_type_context from start_decl_1 to cp_finish_decl
and adds type checking for static local vector variable in C++ template.

2021-08-06  wangpc  

gcc/cp/ChangeLog

* decl.c (start_decl_1): Remove verify_type_context.
(cp_finish_decl): Add more type checking.

gcc/testsuite/ChangeLog

* g++.target/aarch64/sve/static-var-in-template.C: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 90111e4c786..d411963896a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5491,13 +5491,6 @@ start_decl_1 (tree decl, bool initialized)
   cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
 }
 
-  if (is_global_var (decl))
-{
-  type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
-  ? TCTX_THREAD_STORAGE
-  : TCTX_STATIC_STORAGE);
-  verify_type_context (input_location, context, TREE_TYPE (decl));
-}
   if (initialized)
 /* Is it valid for this decl to have an initializer at all?  */
 {
@@ -7520,6 +7513,22 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
   && DECL_INITIALIZED_IN_CLASS_P (decl))
 check_static_variable_definition (decl, type);
 
+  if (!processing_template_decl && VAR_P (decl))
+{
+  if (is_global_var (decl))
+   {
+ type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
+ ? TCTX_THREAD_STORAGE
+ : TCTX_STATIC_STORAGE);
+ verify_type_context (input_location, context, TREE_TYPE (decl));
+   }
+
+  if (DECL_FUNCTION_SCOPE_P (decl)
+ && TREE_STATIC (decl))
+   verify_type_context (DECL_SOURCE_LOCATION (decl),
+TCTX_STATIC_STORAGE, type);
+}
+
   if (init && TREE_CODE (decl) == FUNCTION_DECL)
 {
   tree clone;
diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
new file mode 100644
index 000..c2395d18d50
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+f<2>();
+return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */
-- 
2.33.0.windows.1



[PATCH] C++: add type checking for static local vector variable in template

2021-09-17 Thread wangpc via Gcc-patches

Thanks for your advice, I have misunderstood what you meant.

I have sent a second version patch, please review whether it is OK.

On 2021/9/16 23:19, Jason Merrill wrote:

On 9/16/21 05:11, wangpc via Gcc-patches wrote:

This patch adds type checking for static local vector variable in
C++ template, both AArch64 SVE and RISCV RVV are of sizeless type
and they all have this issue.

2021-08-06  wangpc  

gcc/cp/ChangeLog

 * decl.c (cp_finish_decl): Add type checking.

gcc/testsuite/ChangeLog

 * g++.target/aarch64/sve/static-var-in-template.C: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 90111e4c786..e3a06ea0858 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7520,6 +7520,12 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,

    && DECL_INITIALIZED_IN_CLASS_P (decl))
  check_static_variable_definition (decl, type);
  +  if (VAR_P (decl)
+  && DECL_FUNCTION_SCOPE_P (decl)
+  && TREE_STATIC (decl))
+    verify_type_context (DECL_SOURCE_LOCATION (decl),
+  TCTX_STATIC_STORAGE, type);


I was thinking to move the verify_type_context code from start_decl, 
which handles more cases:



  if (is_global_var (decl))
    {
  type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
   ? TCTX_THREAD_STORAGE
   : TCTX_STATIC_STORAGE);
  verify_type_context (input_location, context, TREE_TYPE (decl));
    }


Jason


Re: [PATCH v2] C++: add type checking for static local vector variable in template

2021-09-17 Thread wangpc via Gcc-patches
I have tested this patch on AArch64 and RISCV by running testsuites, the 
diagnostic message seems to be right.


While one thing that should be noted is that error message will be 
reported twice as below:


static-template.cpp: In instantiation of 'void f1() [with int a = 2]':
static-template.cpp:29:11:   required from here
static-template.cpp:11:24: error: RVV type 'vuint16m1_t' does not have a fixed 
size
   11 | static vuint16m1_t v = vmv_v_x_u16m1(a, gvl);
  |^
static-template.cpp:11:24: error: RVV type 'vuint16m1_t' does not have a fixed 
size

I haven't figured it out, or is it a normal behavior?

On 2021/9/17 21:34, Jason Merrill wrote:

On 9/17/21 03:58, wangpc wrote:

This patch moves verify_type_context from start_decl_1 to cp_finish_decl
and adds type checking for static local vector variable in C++ template.


How have you tested this patch?
https://gcc.gnu.org/contribute.html#testing


2021-08-06  wangpc 

gcc/cp/ChangeLog

 * decl.c (start_decl_1): Remove verify_type_context.
    (cp_finish_decl): Add more type checking.

gcc/testsuite/ChangeLog

 * g++.target/aarch64/sve/static-var-in-template.C: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 90111e4c786..d411963896a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5491,13 +5491,6 @@ start_decl_1 (tree decl, bool initialized)
    cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
  }
  -  if (is_global_var (decl))
-    {
-  type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
-   ? TCTX_THREAD_STORAGE
-   : TCTX_STATIC_STORAGE);
-  verify_type_context (input_location, context, TREE_TYPE (decl));
-    }
    if (initialized)
  /* Is it valid for this decl to have an initializer at all?  */
  {
@@ -7520,6 +7513,22 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,

    && DECL_INITIALIZED_IN_CLASS_P (decl))
  check_static_variable_definition (decl, type);
  +  if (!processing_template_decl && VAR_P (decl))
+    {
+  if (is_global_var (decl))
+    {
+  type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
+  ? TCTX_THREAD_STORAGE
+  : TCTX_STATIC_STORAGE);
+  verify_type_context (input_location, context, TREE_TYPE (decl));
+    }
+
+  if (DECL_FUNCTION_SCOPE_P (decl)
+  && TREE_STATIC (decl))
+    verify_type_context (DECL_SOURCE_LOCATION (decl),
+ TCTX_STATIC_STORAGE, type);


This is redundant; is_global_var is true for a local static. Which 
makes the name confusing, but that's the intended behavior.



+    }
+
    if (init && TREE_CODE (decl) == FUNCTION_DECL)
  {
    tree clone;
diff --git 
a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C

new file mode 100644
index 000..c2395d18d50
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+    static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+    f<2>();
+    return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */



Re: [PATCH v2] C++: add type checking for static local vector variable in template

2021-09-17 Thread wangpc via Gcc-patches

OK I know, it's because the redundant code will check a declaration twice.

On 2021/9/17 22:30, wangpc wrote:


I have tested this patch on AArch64 and RISCV by running testsuites, 
the diagnostic message seems to be right.


While one thing that should be noted is that error message will be 
reported twice as below:


static-template.cpp: In instantiation of 'void f1() [with int a = 2]':
static-template.cpp:29:11:   required from here
static-template.cpp:11:24: error: RVV type 'vuint16m1_t' does not have a fixed 
size
11 | static vuint16m1_t v = vmv_v_x_u16m1(a, gvl);
   |^
static-template.cpp:11:24: error: RVV type 'vuint16m1_t' does not have a fixed 
size

I haven't figured it out, or is it a normal behavior?

On 2021/9/17 21:34, Jason Merrill wrote:

On 9/17/21 03:58, wangpc wrote:
This patch moves verify_type_context from start_decl_1 to 
cp_finish_decl
and adds type checking for static local vector variable in C++ 
template.


How have you tested this patch?
https://gcc.gnu.org/contribute.html#testing


2021-08-06  wangpc 

gcc/cp/ChangeLog

 * decl.c (start_decl_1): Remove verify_type_context.
    (cp_finish_decl): Add more type checking.

gcc/testsuite/ChangeLog

 * g++.target/aarch64/sve/static-var-in-template.C: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 90111e4c786..d411963896a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5491,13 +5491,6 @@ start_decl_1 (tree decl, bool initialized)
    cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
  }
  -  if (is_global_var (decl))
-    {
-  type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
-   ? TCTX_THREAD_STORAGE
-   : TCTX_STATIC_STORAGE);
-  verify_type_context (input_location, context, TREE_TYPE (decl));
-    }
    if (initialized)
  /* Is it valid for this decl to have an initializer at all?  */
  {
@@ -7520,6 +7513,22 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,

    && DECL_INITIALIZED_IN_CLASS_P (decl))
  check_static_variable_definition (decl, type);
  +  if (!processing_template_decl && VAR_P (decl))
+    {
+  if (is_global_var (decl))
+    {
+  type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
+  ? TCTX_THREAD_STORAGE
+  : TCTX_STATIC_STORAGE);
+  verify_type_context (input_location, context, TREE_TYPE (decl));
+    }
+
+  if (DECL_FUNCTION_SCOPE_P (decl)
+  && TREE_STATIC (decl))
+    verify_type_context (DECL_SOURCE_LOCATION (decl),
+ TCTX_STATIC_STORAGE, type);


This is redundant; is_global_var is true for a local static. Which 
makes the name confusing, but that's the intended behavior.



+    }
+
    if (init && TREE_CODE (decl) == FUNCTION_DECL)
  {
    tree clone;
diff --git 
a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C

new file mode 100644
index 000..c2395d18d50
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+    static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+    f<2>();
+    return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */



[PATCH v2] C++: add type checking for static local vector variable in template

2021-09-17 Thread wangpc via Gcc-patches
This patch moves verify_type_context from start_decl_1 to cp_finish_decl to
do more type checking such as static local vector variable in C++ template.

2021-08-06  wangpc  

gcc/cp/ChangeLog

* decl.c (start_decl_1): Move verify_type_context to ...
(cp_finish_decl): ... to here.

gcc/testsuite/ChangeLog

* g++.target/aarch64/sve/static-var-in-template.C: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 90111e4c786..deaa6c56a8f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5491,13 +5491,6 @@ start_decl_1 (tree decl, bool initialized)
   cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
 }
 
-  if (is_global_var (decl))
-{
-  type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
-  ? TCTX_THREAD_STORAGE
-  : TCTX_STATIC_STORAGE);
-  verify_type_context (input_location, context, TREE_TYPE (decl));
-}
   if (initialized)
 /* Is it valid for this decl to have an initializer at all?  */
 {
@@ -7520,6 +7513,14 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
   && DECL_INITIALIZED_IN_CLASS_P (decl))
 check_static_variable_definition (decl, type);
 
+  if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
+{
+  type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
+  ? TCTX_THREAD_STORAGE
+  : TCTX_STATIC_STORAGE);
+  verify_type_context (input_location, context, TREE_TYPE (decl));
+}
+
   if (init && TREE_CODE (decl) == FUNCTION_DECL)
 {
   tree clone;
diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C 
b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
new file mode 100644
index 000..74237ff7c57
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include 
+
+template 
+void f()
+{
+static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+f<2>();
+return 0;
+}
+
+/* { dg-error "SVE type 'svbool_t' does not have a fixed size" "" { target 
*-*-* } 0 } */
-- 
2.33.0.windows.1



[PATCH] RISC-V: Compute default ABI from -mcpu or -march

2022-06-06 Thread wangpc via Gcc-patches
If -mcpu or -march is specified and there is no -mabi, we will calculate
default ABI from arch string provided by -march or defined in CPU info.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (compute_default_abi): 
Implementation
to calculate -mabi from arch string.
(riscv_expand_abi_from_arch): New spec function to calcalute -mabi from 
arch
string provided by -march option.
(riscv_expand_abi_from_cpu): New spec function to find CPU info and 
calculate
-mabi from arch string defined in CPU info.
* config/riscv/riscv.h (EXTRA_SPEC_FUNCTIONS): Add above spec functions.
(OPTION_DEFAULT_SPECS): Use new spec functions to calculate -mabi and 
-march
has higher priority than -mcpu.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/mabi-1.c: ilp32e test.
* gcc.target/riscv/mabi-2.c: ilp32 test.
* gcc.target/riscv/mabi-3.c: ilp32f test.
* gcc.target/riscv/mabi-4.c: ilp32d test.
* gcc.target/riscv/mabi-5.c: lp64 test.
* gcc.target/riscv/mabi-6.c: lp64f test.
* gcc.target/riscv/mabi-7.c: lp64d test.
* gcc.target/riscv/mabi-8.c: -march override -mcpu.
---
 gcc/common/config/riscv/riscv-common.cc | 66 +
 gcc/config/riscv/riscv.h| 15 --
 gcc/testsuite/gcc.target/riscv/mabi-1.c |  7 +++
 gcc/testsuite/gcc.target/riscv/mabi-2.c |  7 +++
 gcc/testsuite/gcc.target/riscv/mabi-3.c |  7 +++
 gcc/testsuite/gcc.target/riscv/mabi-4.c |  7 +++
 gcc/testsuite/gcc.target/riscv/mabi-5.c |  7 +++
 gcc/testsuite/gcc.target/riscv/mabi-6.c |  7 +++
 gcc/testsuite/gcc.target/riscv/mabi-7.c |  7 +++
 gcc/testsuite/gcc.target/riscv/mabi-8.c |  7 +++
 10 files changed, 134 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-4.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-5.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-6.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-7.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/mabi-8.c

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 0e5be2ce105..f8e40549d18 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -1266,6 +1266,72 @@ riscv_default_mtune (int argc, const char **argv)
 return default_mtune;
 }
 
+/* Compute default -mabi option from arch string.  */
+
+static const char *
+compute_default_abi (const char* arch_str)
+{
+  location_t loc = UNKNOWN_LOCATION;
+
+  riscv_parse_arch_string (arch_str, NULL, loc);
+
+  if (current_subset_list->xlen () == 64)
+{
+  if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION,
+RISCV_DONT_CARE_VERSION))
+   return "lp64d";
+  if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION,
+RISCV_DONT_CARE_VERSION))
+   return "lp64f";
+  return "lp64";
+}
+  else
+{
+  if (current_subset_list->lookup ("e", RISCV_DONT_CARE_VERSION,
+RISCV_DONT_CARE_VERSION))
+   return "ilp32e";
+  if (current_subset_list->lookup ("d", RISCV_DONT_CARE_VERSION,
+RISCV_DONT_CARE_VERSION))
+   return "ilp32d";
+  if (current_subset_list->lookup ("f", RISCV_DONT_CARE_VERSION,
+RISCV_DONT_CARE_VERSION))
+   return "ilp32f";
+  return "ilp32";
+}
+}
+
+/* Expand default -mabi option from -march option.  */
+
+const char *
+riscv_expand_abi_from_arch (int argc, const char **argv)
+{
+  gcc_assert (argc == 1);
+  return xasprintf ("-mabi=%s", compute_default_abi (argv[0]));
+}
+
+/* Expand default -mabi option from -mcpu option.  */
+
+const char *
+riscv_expand_abi_from_cpu (int argc, const char **argv)
+{
+  gcc_assert (argc > 0 && argc <= 2);
+  const char *default_abi_str = NULL;
+  if (argc >= 2)
+default_abi_str = argv[1];
+
+  const riscv_cpu_info *cpu = riscv_find_cpu (argv[0]);
+
+  if (cpu == NULL)
+{
+  if (default_abi_str == NULL)
+   return "";
+  else
+   return xasprintf ("-mabi=%s", default_abi_str);
+}
+  else
+return xasprintf ("-mabi=%s", compute_default_abi (cpu->arch));
+}
+
 /* Expand arch string with implied extensions from -mcpu option.  */
 
 const char *
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 6f7f4d3fbdc..14cd695f37f 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -50,15 +50,20 @@ along with GCC; see the file COPYING3.  If not see
 extern const char *riscv_expand_arch (int argc, const char **argv);
 extern const char *riscv_expand_arch_from_cpu (int argc, const char **ar