r214507 - Improving diagnostic source ranges for the nonnull attribute. Now it highlights the attribute and the faulty nonpointer type when possible.

Aaron Ballman aaron at aaronballman.com
Fri Aug 1 10:11:55 PDT 2014


On Fri, Aug 1, 2014 at 1:01 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Fri, Aug 1, 2014 at 5:58 AM, Aaron Ballman <aaron at aaronballman.com> wrote:
>> Author: aaronballman
>> Date: Fri Aug  1 07:58:11 2014
>> New Revision: 214507
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=214507&view=rev
>> Log:
>> Improving diagnostic source ranges for the nonnull attribute. Now it highlights the attribute and the faulty nonpointer type when possible.
>>
>> Modified:
>>     cfe/trunk/include/clang/AST/DeclObjC.h
>>     cfe/trunk/lib/AST/DeclObjC.cpp
>>     cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/DeclObjC.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=214507&r1=214506&r2=214507&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/DeclObjC.h (original)
>> +++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Aug  1 07:58:11 2014
>> @@ -329,6 +329,7 @@ public:
>>
>>    QualType getReturnType() const { return MethodDeclType; }
>>    void setReturnType(QualType T) { MethodDeclType = T; }
>> +  SourceRange getReturnTypeSourceRange() const;
>>
>>    /// \brief Determine the type of an expression that sends a message to this
>>    /// function.
>>
>> Modified: cfe/trunk/lib/AST/DeclObjC.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=214507&r1=214506&r2=214507&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/AST/DeclObjC.cpp (original)
>> +++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Aug  1 07:58:11 2014
>> @@ -952,6 +952,13 @@ ObjCInterfaceDecl *ObjCMethodDecl::getCl
>>    llvm_unreachable("unknown method context");
>>  }
>>
>> +SourceRange ObjCMethodDecl::getReturnTypeSourceRange() const {
>> +  const auto *TSI = getReturnTypeSourceInfo();
>> +  if (TSI)
>> +    return TSI->getTypeLoc().getSourceRange();
>> +  return SourceRange();
>> +}
>> +
>>  static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container,
>>                                              const ObjCMethodDecl *Method,
>>                                 SmallVectorImpl<const ObjCMethodDecl *> &Methods,
>>
>> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=214507&r1=214506&r2=214507&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Aug  1 07:58:11 2014
>> @@ -88,12 +88,30 @@ static QualType getFunctionOrMethodParam
>>    return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
>>  }
>>
>> +static SourceRange getFunctionOrMethodParamRange(const Decl *D, unsigned Idx) {
>> +  if (const auto *FD = dyn_cast<FunctionDecl>(D))
>> +    return FD->getParamDecl(Idx)->getSourceRange();
>> +  else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
>
> Drop the else(s) after return.

Good catch. Rectified (with a few others on drive-by) in r214526.

~Aaron



More information about the cfe-commits mailing list