diff options
author | Volodymyr Sapsai <vsapsai@apple.com> | 2017-09-28 23:18:49 +0000 |
---|---|---|
committer | Volodymyr Sapsai <vsapsai@apple.com> | 2017-09-28 23:18:49 +0000 |
commit | 3adb8ef46e4e2af980bc418c569694ef74d252d3 (patch) | |
tree | 4d0fbb6aefcdc5fb51e00d52649d8f0b060f325f /lib/Sema | |
parent | d5fedf97720711126ed57d6a0b5ec687f40edb69 (diff) | |
download | clang-3adb8ef46e4e2af980bc418c569694ef74d252d3.tar.gz |
[Sema] Put nullability fix-it after the end of the pointer.
Fixes nullability fix-it for `id<SomeProtocol>`. With this change
nullability specifier is inserted after ">" instead of between
"id" and "<".
rdar://problem/34260995
Reviewers: jordan_rose, doug.gregor, ahatanak, arphaman
Reviewed By: jordan_rose
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D38327
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314473 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaType.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index d5ec98c8cb..3c455043af 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -3500,7 +3500,8 @@ static void fixItNullability(Sema &S, DiagnosticBuilder &Diag, static void emitNullabilityConsistencyWarning(Sema &S, SimplePointerKind PointerKind, - SourceLocation PointerLoc) { + SourceLocation PointerLoc, + SourceLocation PointerEndLoc) { assert(PointerLoc.isValid()); if (PointerKind == SimplePointerKind::Array) { @@ -3510,14 +3511,15 @@ static void emitNullabilityConsistencyWarning(Sema &S, << static_cast<unsigned>(PointerKind); } - if (PointerLoc.isMacroID()) + auto FixItLoc = PointerEndLoc.isValid() ? PointerEndLoc : PointerLoc; + if (FixItLoc.isMacroID()) return; auto addFixIt = [&](NullabilityKind Nullability) { - auto Diag = S.Diag(PointerLoc, diag::note_nullability_fix_it); + auto Diag = S.Diag(FixItLoc, diag::note_nullability_fix_it); Diag << static_cast<unsigned>(Nullability); Diag << static_cast<unsigned>(PointerKind); - fixItNullability(S, Diag, PointerLoc, Nullability); + fixItNullability(S, Diag, FixItLoc, Nullability); }; addFixIt(NullabilityKind::Nullable); addFixIt(NullabilityKind::NonNull); @@ -3529,9 +3531,10 @@ static void emitNullabilityConsistencyWarning(Sema &S, /// /// If the file has \e not seen other uses of nullability, this particular /// pointer is saved for possible later diagnosis. See recordNullabilitySeen(). -static void checkNullabilityConsistency(Sema &S, - SimplePointerKind pointerKind, - SourceLocation pointerLoc) { +static void +checkNullabilityConsistency(Sema &S, SimplePointerKind pointerKind, + SourceLocation pointerLoc, + SourceLocation pointerEndLoc = SourceLocation()) { // Determine which file we're performing consistency checking for. FileID file = getNullabilityCompletenessCheckFileID(S, pointerLoc); if (file.isInvalid()) @@ -3552,6 +3555,7 @@ static void checkNullabilityConsistency(Sema &S, if (fileNullability.PointerLoc.isInvalid() && !S.Context.getDiagnostics().isIgnored(diagKind, pointerLoc)) { fileNullability.PointerLoc = pointerLoc; + fileNullability.PointerEndLoc = pointerEndLoc; fileNullability.PointerKind = static_cast<unsigned>(pointerKind); } @@ -3559,7 +3563,7 @@ static void checkNullabilityConsistency(Sema &S, } // Complain about missing nullability. - emitNullabilityConsistencyWarning(S, pointerKind, pointerLoc); + emitNullabilityConsistencyWarning(S, pointerKind, pointerLoc, pointerEndLoc); } /// Marks that a nullability feature has been used in the file containing @@ -3585,7 +3589,8 @@ static void recordNullabilitySeen(Sema &S, SourceLocation loc) { return; auto kind = static_cast<SimplePointerKind>(fileNullability.PointerKind); - emitNullabilityConsistencyWarning(S, kind, fileNullability.PointerLoc); + emitNullabilityConsistencyWarning(S, kind, fileNullability.PointerLoc, + fileNullability.PointerEndLoc); } /// Returns true if any of the declarator chunks before \p endIndex include a @@ -3895,6 +3900,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, // Returns true if _Nonnull was inferred. auto inferPointerNullability = [&](SimplePointerKind pointerKind, SourceLocation pointerLoc, + SourceLocation pointerEndLoc, AttributeList *&attrs) -> AttributeList * { // We've seen a pointer. if (NumPointersRemaining > 0) @@ -3950,7 +3956,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, // Fallthrough. case CAMN_Yes: - checkNullabilityConsistency(S, pointerKind, pointerLoc); + checkNullabilityConsistency(S, pointerKind, pointerLoc, pointerEndLoc); } return nullptr; }; @@ -3973,6 +3979,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, if (auto *attr = inferPointerNullability( pointerKind, D.getDeclSpec().getTypeSpecTypeLoc(), + D.getDeclSpec().getLocEnd(), D.getMutableDeclSpec().getAttributes().getListRef())) { T = Context.getAttributedType( AttributedType::getNullabilityAttrKind(*inferNullability),T,T); @@ -4008,8 +4015,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, S.Diag(DeclType.Loc, diag::err_blocks_disable) << LangOpts.OpenCL; // Handle pointer nullability. - inferPointerNullability(SimplePointerKind::BlockPointer, - DeclType.Loc, DeclType.getAttrListRef()); + inferPointerNullability(SimplePointerKind::BlockPointer, DeclType.Loc, + DeclType.EndLoc, DeclType.getAttrListRef()); T = S.BuildBlockPointerType(T, D.getIdentifierLoc(), Name); if (DeclType.Cls.TypeQuals || LangOpts.OpenCL) { @@ -4031,7 +4038,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, // Handle pointer nullability inferPointerNullability(SimplePointerKind::Pointer, DeclType.Loc, - DeclType.getAttrListRef()); + DeclType.EndLoc, DeclType.getAttrListRef()); if (LangOpts.ObjC1 && T->getAs<ObjCObjectType>()) { T = Context.getObjCObjectPointerType(T); @@ -4530,8 +4537,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, QualType ClsType; // Handle pointer nullability. - inferPointerNullability(SimplePointerKind::MemberPointer, - DeclType.Loc, DeclType.getAttrListRef()); + inferPointerNullability(SimplePointerKind::MemberPointer, DeclType.Loc, + DeclType.EndLoc, DeclType.getAttrListRef()); if (SS.isInvalid()) { // Avoid emitting extra errors if we already errored on the scope. |