public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] C++: add type checking for static local vector variable in template
@ 2021-09-16  9:11 wangpc
  2021-09-16 15:19 ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: wangpc @ 2021-09-16  9:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: wangpc

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  <pc.wang@linux.alibaba.com>

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 00000000000..c2395d18d50
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include <arm_sve.h>
+
+template <int N>
+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


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH] C++: add type checking for static local vector variable in template
@ 2021-09-16  8:59 wangpc
  0 siblings, 0 replies; 8+ messages in thread
From: wangpc @ 2021-09-16  8:59 UTC (permalink / raw)
  To: gcc-patches; +Cc: wangpc

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  <pc.wang@linux.alibaba.com>

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 00000000000..c2395d18d50
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#include <arm_sve.h>
+
+template <int N>
+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


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH] C++: add type checking for static local vector variable in template
@ 2021-09-06 12:10 wangpc
  2021-09-15 21:02 ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: wangpc @ 2021-09-06 12:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: wangpc

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  <pc.wang@linux.alibaba.com>

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 000000000000..26d397ca565d
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+#include <arm_sve.h>
+
+template <int N>
+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


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH] C++: add type checking for static local vector variable in template
@ 2021-09-01  8:11 wangpc
  0 siblings, 0 replies; 8+ messages in thread
From: wangpc @ 2021-09-01  8:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: wangpc

From: wangpc <wpc337719@alibaba-inc.com>

---
 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 000000000000..26d397ca565d
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+#include <arm_sve.h>
+
+template <int N>
+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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-17  8:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16  9:11 [PATCH] C++: add type checking for static local vector variable in template wangpc
2021-09-16 15:19 ` Jason Merrill
2021-09-17  8:05   ` wangpc
  -- strict thread matches above, loose matches on Subject: below --
2021-09-16  8:59 wangpc
2021-09-06 12:10 wangpc
2021-09-15 21:02 ` Jason Merrill
2021-09-16  9:06   ` pc.wang
2021-09-01  8:11 wangpc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).