[clang] 69d2fa9 - [SemaObjC] Fix a crash on invalid when 'auto' is used in a @property
Erik Pilkington via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 24 09:13:01 PDT 2020
Author: Erik Pilkington
Date: 2020-06-24T12:11:39-04:00
New Revision: 69d2fa9ed1c1aba6f473feb03cad257e69a0cf52
URL: https://github.com/llvm/llvm-project/commit/69d2fa9ed1c1aba6f473feb03cad257e69a0cf52
DIFF: https://github.com/llvm/llvm-project/commit/69d2fa9ed1c1aba6f473feb03cad257e69a0cf52.diff
LOG: [SemaObjC] Fix a crash on invalid when 'auto' is used in a @property
rdar://48506879
Added:
Modified:
clang/lib/Sema/SemaType.cpp
clang/test/SemaObjCXX/property-invalid-type.mm
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 46fa8bc0608b..81a0c4a2a9c2 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3301,12 +3301,16 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
D.isFunctionDeclarator())
break;
bool Cxx = SemaRef.getLangOpts().CPlusPlus;
- switch (cast<TagDecl>(SemaRef.CurContext)->getTagKind()) {
- case TTK_Enum: llvm_unreachable("unhandled tag kind");
- case TTK_Struct: Error = Cxx ? 1 : 2; /* Struct member */ break;
- case TTK_Union: Error = Cxx ? 3 : 4; /* Union member */ break;
- case TTK_Class: Error = 5; /* Class member */ break;
- case TTK_Interface: Error = 6; /* Interface member */ break;
+ if (isa<ObjCContainerDecl>(SemaRef.CurContext)) {
+ Error = 6; // Interface member.
+ } else {
+ switch (cast<TagDecl>(SemaRef.CurContext)->getTagKind()) {
+ case TTK_Enum: llvm_unreachable("unhandled tag kind");
+ case TTK_Struct: Error = Cxx ? 1 : 2; /* Struct member */ break;
+ case TTK_Union: Error = Cxx ? 3 : 4; /* Union member */ break;
+ case TTK_Class: Error = 5; /* Class member */ break;
+ case TTK_Interface: Error = 6; /* Interface member */ break;
+ }
}
if (D.getDeclSpec().isFriendSpecified())
Error = 20; // Friend type
@@ -7031,15 +7035,15 @@ static bool checkNullabilityTypeSpecifier(TypeProcessingState &state,
// attributes, require that the type be a single-level pointer.
if (isContextSensitive) {
// Make sure that the pointee isn't itself a pointer type.
- const Type *pointeeType;
+ const Type *pointeeType = nullptr;
if (desugared->isArrayType())
pointeeType = desugared->getArrayElementTypeNoTypeQual();
- else
+ else if (desugared->isAnyPointerType())
pointeeType = desugared->getPointeeType().getTypePtr();
- if (pointeeType->isAnyPointerType() ||
- pointeeType->isObjCObjectPointerType() ||
- pointeeType->isMemberPointerType()) {
+ if (pointeeType && (pointeeType->isAnyPointerType() ||
+ pointeeType->isObjCObjectPointerType() ||
+ pointeeType->isMemberPointerType())) {
S.Diag(nullabilityLoc, diag::err_nullability_cs_multilevel)
<< DiagNullabilityKind(nullability, true)
<< type;
diff --git a/clang/test/SemaObjCXX/property-invalid-type.mm b/clang/test/SemaObjCXX/property-invalid-type.mm
index 9122426f4c30..35a5f3a5a525 100644
--- a/clang/test/SemaObjCXX/property-invalid-type.mm
+++ b/clang/test/SemaObjCXX/property-invalid-type.mm
@@ -21,3 +21,13 @@ void foo(I *i)
{
i.helper; // expected-warning{{property access result unused - getters should not be used for side effects}}
}
+
+ at interface J
+ at property (nonnull) auto a; // expected-error {{'auto' not allowed in interface member}}
+ at property auto b; // expected-error {{'auto' not allowed in interface member}}
+ at property (nullable) auto c; // expected-error {{'auto' not allowed in interface member}}
+ at end
+
+ at interface J (Cat)
+ at property (nonnull) auto catprop; // expected-error {{'auto' not allowed in interface member}}
+ at end
More information about the cfe-commits
mailing list