On 9/6/21 08:10, 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 thay all have this issue.
2021-08-06 wangpc <pc.w...@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))
It seems that the reason this was missed before was because we checked
for this in start_decl, which isn't called for template instantiation.
Would it work to move the verify_type_context code from start_decl to
cp_finish_decl, near the other call to verify_type_context, instead of
doing anything here?
+ {
+ 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} } */