diff options
| author | Douglas Gregor <dgregor@apple.com> | 2015-10-09 20:36:17 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2015-10-09 20:36:17 +0000 |
| commit | d4f2afa23c8b4a26d553c5e5126351f1d7157f93 (patch) | |
| tree | e18aea9cb828c00fc0d29d09f46213183e679138 /clang/lib/Sema | |
| parent | 6ccc8ca6d9715c76eb89f0d338b2a782f1edd0c4 (diff) | |
| download | bcm5719-llvm-d4f2afa23c8b4a26d553c5e5126351f1d7157f93.tar.gz bcm5719-llvm-d4f2afa23c8b4a26d553c5e5126351f1d7157f93.zip | |
Fix inference of _Nullable for weak Objective-C properties.
The inference of _Nullable for weak Objective-C properties was broken
in several ways:
* It was back-patching the type information very late in the process
of checking the attributes for an Objective-C property, which is
just wrong.
* It was using ad hoc checks to try to suppress the warning about
missing nullability specifiers (-Wnullability-completeness), which
didn't actual work in all cases (rdar://problem/22985457)
* It was inferring _Nullable even outside of assumes-nonnull regions,
which is wrong.
Putting the inference of _Nullable for weak Objective-C properties in
the same place as all of the other inference logic fixes all of these
ills.
llvm-svn: 249896
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaObjCProperty.cpp | 9 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 11 |
2 files changed, 9 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 15843fde39d..374e5ccd918 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/lib/Sema/SemaObjCProperty.cpp @@ -181,7 +181,7 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, } // Validate the attributes on the @property. - CheckObjCPropertyAttributes(Res, AtLoc, Attributes, + CheckObjCPropertyAttributes(Res, AtLoc, Attributes, (isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCProtocolDecl>(ClassDecl))); @@ -2301,13 +2301,6 @@ void Sema::CheckObjCPropertyAttributes(Decl *PDecl, if (*nullability == NullabilityKind::NonNull) Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) << "nonnull" << "weak"; - } else { - PropertyTy = - Context.getAttributedType( - AttributedType::getNullabilityAttrKind(NullabilityKind::Nullable), - PropertyTy, PropertyTy); - TypeSourceInfo *TSInfo = PropertyDecl->getTypeSourceInfo(); - PropertyDecl->setType(PropertyTy, TSInfo); } } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 049698d3820..d1bf6cc6bb2 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -3311,9 +3311,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, // Are we in an assume-nonnull region? bool inAssumeNonNullRegion = false; - if (S.PP.getPragmaAssumeNonNullLoc().isValid() && - !state.getDeclarator().isObjCWeakProperty() && - !S.deduceWeakPropertyFromType(T)) { + if (S.PP.getPragmaAssumeNonNullLoc().isValid()) { inAssumeNonNullRegion = true; // Determine which file we saw the assume-nonnull region in. FileID file = getNullabilityCompletenessCheckFileID( @@ -3392,6 +3390,13 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, complainAboutMissingNullability = CAMN_No; break; } + + // Weak properties are inferred to be nullable. + if (state.getDeclarator().isObjCWeakProperty() && inAssumeNonNullRegion) { + inferNullability = NullabilityKind::Nullable; + break; + } + // fallthrough case Declarator::FileContext: |

