[PATCH] D75736: [Sema][SVE] Don't allow static or thread-local variables to have sizeless type
Richard Sandiford via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 6 04:57:43 PST 2020
rsandifo-arm created this revision.
rsandifo-arm added reviewers: sdesmalen, efriedma, rovka, rjmccall.
Herald added subscribers: cfe-commits, psnobl, rkruppe, tschuett.
Herald added a project: clang.
rsandifo-arm added a parent revision: D75734: [Sema][SVE] Reject atomic sizeless types.
rsandifo-arm added a child revision: D75737: [Sema][SVE] Don't allow fields to have sizeless type.
clang accepts a TU containing just:
__SVInt8_t x;
However, sizeless types are not allowed to have static or thread-local
storage duration and trying to code-generate the TU triggers an LLVM
fatal error:
Globals cannot contain scalable vectors
<vscale x 16 x i8>* @x
fatal error: error in backend: Broken module found, compilation aborted!
This patch adds an associated clang diagnostic.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75736
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/sizeless-1.c
clang/test/SemaCXX/sizeless-1.cpp
Index: clang/test/SemaCXX/sizeless-1.cpp
===================================================================
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -10,6 +10,10 @@
typedef __SVInt8_t svint8_t;
typedef __SVInt16_t svint16_t;
+svint8_t global_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
+extern svint8_t extern_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
+static svint8_t static_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
+__thread svint8_t thread_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
svint8_t *global_int8_ptr;
extern svint8_t *extern_int8_ptr;
static svint8_t *static_int8_ptr;
@@ -58,6 +62,8 @@
struct incomplete_struct *incomplete_ptr;
void func(int sel) {
+ static svint8_t static_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
+
svint8_t local_int8;
svint16_t local_int16;
Index: clang/test/Sema/sizeless-1.c
===================================================================
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -5,6 +5,10 @@
typedef __SVInt8_t svint8_t;
typedef __SVInt16_t svint16_t;
+svint8_t global_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
+extern svint8_t extern_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
+static svint8_t static_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
+__thread svint8_t thread_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
svint8_t *global_int8_ptr;
extern svint8_t *extern_int8_ptr;
static svint8_t *static_int8_ptr;
@@ -48,6 +52,8 @@
struct incomplete_struct *incomplete_ptr;
void func(int sel) {
+ static svint8_t static_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
+
svint8_t local_int8;
svint16_t local_int16;
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -7939,6 +7939,12 @@
return;
}
+ if (!NewVD->hasLocalStorage() && T->isSizelessType()) {
+ Diag(NewVD->getLocation(), diag::err_sizeless_nonlocal) << T;
+ NewVD->setInvalidDecl();
+ return;
+ }
+
if (isVM && NewVD->hasAttr<BlocksAttr>()) {
Diag(NewVD->getLocation(), diag::err_block_on_vm);
NewVD->setInvalidDecl();
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9132,6 +9132,8 @@
"__block attribute not allowed, only allowed on local variables">;
def err_block_on_vm : Error<
"__block attribute not allowed on declaration with a variably modified type">;
+def err_sizeless_nonlocal : Error<
+ "non-local variable with sizeless type %0">;
def err_vec_builtin_non_vector : Error<
"first two arguments to %0 must be vectors">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75736.248698.patch
Type: text/x-patch
Size: 3151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200306/f5b43767/attachment-0001.bin>
More information about the cfe-commits
mailing list