This revision was automatically updated to reflect the committed changes.
rsandifo-arm marked an inline comment as done.
Closed by commit rGb50d80c1ee1f: [Sema][SVE] Don't allow fields to have
sizeless type (authored by rsandifo-arm).
Changed prior to commit:
https://reviews.llvm.org/D75737?vs=249990&id=250277#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75737/new/
https://reviews.llvm.org/D75737
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaLambda.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
@@ -249,6 +249,20 @@
return count;
}
+struct sized_struct {
+ int f1;
+ svint8_t f2; // expected-error {{field has sizeless type 'svint8_t'}}
+ svint8_t f3 : 2; // expected-error {{field has sizeless type 'svint8_t'}}
+ svint8_t : 3; // expected-error {{field has sizeless type 'svint8_t'}}
+};
+
+union sized_union {
+ int f1;
+ svint8_t f2; // expected-error {{field has sizeless type 'svint8_t'}}
+ svint8_t f3 : 2; // expected-error {{field has sizeless type 'svint8_t'}}
+ svint8_t : 3; // expected-error {{field has sizeless type 'svint8_t'}}
+};
+
void pass_int8_ref(svint8_t &); // expected-note {{not viable}}
svint8_t &return_int8_ref();
@@ -257,6 +271,11 @@
#endif
template <typename T>
+struct s_template {
+ T y; // expected-error {{field has sizeless type '__SVInt8_t'}}
+};
+
+template <typename T>
struct s_ptr_template {
s_ptr_template();
s_ptr_template(T, svint8_t = svint8_t());
@@ -344,6 +363,9 @@
local_int8 = svint8_t();
local_int8 = svint16_t(); // expected-error {{assigning to 'svint8_t' (aka '__SVInt8_t') from incompatible type 'svint16_t'}}
+ s_template<int> st_int;
+ s_template<svint8_t> st_svint8; // expected-note {{in instantiation}}
+
s_ptr_template<int> st_ptr_int;
s_ptr_template<svint8_t> st_ptr_svint8;
@@ -474,6 +496,9 @@
local_int8 = ([]() -> svint8_t { return svint8_t(); })();
auto fn1 = [&local_int8](svint8_t x) { local_int8 = x; };
auto fn2 = [&local_int8](svint8_t *ptr) { *ptr = local_int8; };
+#if __cplusplus >= 201703L
+ auto fn3 = [a(return_int8())] {}; // expected-error {{field has sizeless type '__SVInt8_t'}}
+#endif
for (auto x : local_int8) { // expected-error {{no viable 'begin' function available}}
}
Index: clang/test/Sema/sizeless-1.c
===================================================================
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -230,6 +230,20 @@
return count;
}
+struct sized_struct {
+ int f1;
+ svint8_t f2; // expected-error {{field has sizeless type 'svint8_t'}}
+ svint8_t f3 : 2; // expected-error {{field has sizeless type 'svint8_t'}}
+ svint8_t : 3; // expected-error {{field has sizeless type 'svint8_t'}}
+};
+
+union sized_union {
+ int f1;
+ svint8_t f2; // expected-error {{field has sizeless type 'svint8_t'}}
+ svint8_t f3 : 2; // expected-error {{field has sizeless type 'svint8_t'}}
+ svint8_t : 3; // expected-error {{field has sizeless type 'svint8_t'}}
+};
+
#if __STDC_VERSION__ >= 201112L
void test_generic(void) {
svint8_t local_int8;
Index: clang/lib/Sema/SemaLambda.cpp
===================================================================
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1629,7 +1629,8 @@
// If the variable being captured has an invalid type, mark the class as
// invalid as well.
if (!FieldType->isDependentType()) {
- if (RequireCompleteType(Loc, FieldType, diag::err_field_incomplete)) {
+ if (RequireCompleteSizedType(Loc, FieldType,
+ diag::err_field_incomplete_or_sizeless)) {
RD->setInvalidDecl();
Field->setInvalidDecl();
} else {
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5247,8 +5247,8 @@
Chain.push_back(Anon);
RecordDecl *RecordDef = Record->getDefinition();
- if (RequireCompleteType(Anon->getLocation(), RecTy,
- diag::err_field_incomplete) ||
+ if (RequireCompleteSizedType(Anon->getLocation(), RecTy,
+ diag::err_field_incomplete_or_sizeless) ||
InjectAnonymousStructOrUnionMembers(*this, S, CurContext, RecordDef,
AS_none, Chain)) {
Anon->setInvalidDecl();
@@ -16103,8 +16103,9 @@
// C99 6.7.2.1p4 - verify the field type.
// C++ 9.6p3: A bit-field shall have integral or enumeration type.
if (!FieldTy->isDependentType() && !FieldTy->isIntegralOrEnumerationType()) {
- // Handle incomplete types with specific error.
- if (RequireCompleteType(FieldLoc, FieldTy, diag::err_field_incomplete))
+ // Handle incomplete and sizeless types with a specific error.
+ if (RequireCompleteSizedType(FieldLoc, FieldTy,
+ diag::err_field_incomplete_or_sizeless))
return ExprError();
if (FieldName)
return Diag(FieldLoc, diag::err_not_integral_type_bitfield)
@@ -16321,7 +16322,8 @@
QualType EltTy = Context.getBaseElementType(T);
if (!EltTy->isDependentType()) {
- if (RequireCompleteType(Loc, EltTy, diag::err_field_incomplete)) {
+ if (RequireCompleteSizedType(Loc, EltTy,
+ diag::err_field_incomplete_or_sizeless)) {
// Fields of incomplete type force their record to be invalid.
Record->setInvalidDecl();
InvalidDecl = true;
@@ -16865,8 +16867,9 @@
// elsewhere, after synthesized ivars are known.
}
} else if (!FDTy->isDependentType() &&
- RequireCompleteType(FD->getLocation(), FD->getType(),
- diag::err_field_incomplete)) {
+ RequireCompleteSizedType(
+ FD->getLocation(), FD->getType(),
+ diag::err_field_incomplete_or_sizeless)) {
// Incomplete type
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
@@ -16924,8 +16927,8 @@
Context, "", UnavailableAttr::IR_ARCFieldWithOwnership,
FD->getLocation()));
} else if (getLangOpts().ObjC &&
- getLangOpts().getGC() != LangOptions::NonGC &&
- Record && !Record->hasObjectMember()) {
+ getLangOpts().getGC() != LangOptions::NonGC && Record &&
+ !Record->hasObjectMember()) {
if (FD->getType()->isObjCObjectPointerType() ||
FD->getType().isObjCGCStrong())
Record->setHasObjectMember(true);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5602,7 +5602,8 @@
def err_func_returning_array_function : Error<
"function cannot return %select{array|function}0 type %1">;
def err_field_declared_as_function : Error<"field %0 declared as a function">;
-def err_field_incomplete : Error<"field has incomplete type %0">;
+def err_field_incomplete_or_sizeless : Error<
+ "field has %select{incomplete|sizeless}0 type %1">;
def ext_variable_sized_type_in_struct : ExtWarn<
"field %0 with variable sized type %1 not at the end of a struct or class is"
" a GNU extension">, InGroup<GNUVariableSizedTypeNotAtEnd>;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits