diff options
| author | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-07-28 00:42:01 +0000 |
|---|---|---|
| committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-07-28 00:42:01 +0000 |
| commit | c67dd95697b35654614b04d00c8fd7c720ff49b0 (patch) | |
| tree | 0ad8246377737a8be5c5cd529455a4bed8ae923b /clang-tools-extra/clang-rename/USRFinder.cpp | |
| parent | 2e46f720fadddbc4ea8ef80ede715e9da1037d3f (diff) | |
| download | bcm5719-llvm-c67dd95697b35654614b04d00c8fd7c720ff49b0.tar.gz bcm5719-llvm-c67dd95697b35654614b04d00c8fd7c720ff49b0.zip | |
clang-rename: adjust NamedDeclFindingASTVisitor for RecordDecls
Ensure that Context is always properly initialised in the constructor. It is
used for querying the LangOpts in VisitTypeLoc. Prevent a null pointer
dereference in setResult by ensuring that a RecordDecl is being handled.
Patch by Alexander Shaposhnikov!
llvm-svn: 276948
Diffstat (limited to 'clang-tools-extra/clang-rename/USRFinder.cpp')
| -rw-r--r-- | clang-tools-extra/clang-rename/USRFinder.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-rename/USRFinder.cpp b/clang-tools-extra/clang-rename/USRFinder.cpp index b64b20d54bf..0c8eefaa37c 100644 --- a/clang-tools-extra/clang-rename/USRFinder.cpp +++ b/clang-tools-extra/clang-rename/USRFinder.cpp @@ -42,8 +42,9 @@ public: // \brief Finds the NamedDecl for a name in the source. // \param Name the fully qualified name. explicit NamedDeclFindingASTVisitor(const SourceManager &SourceMgr, - const std::string &Name) - : Result(nullptr), SourceMgr(SourceMgr), Name(Name) {} + const std::string &Name, + const ASTContext *Context) + : Result(nullptr), SourceMgr(SourceMgr), Name(Name), Context(Context) {} // Declaration visitors: @@ -75,9 +76,10 @@ public: bool VisitTypeLoc(const TypeLoc Loc) { const auto TypeBeginLoc = Loc.getBeginLoc(); const auto TypeEndLoc = Lexer::getLocForEndOfToken( - TypeBeginLoc, 0, SourceMgr, Context->getLangOpts()); - return setResult(Loc.getType()->getAsCXXRecordDecl(), TypeBeginLoc, - TypeEndLoc); + TypeBeginLoc, 0, SourceMgr, Context->getLangOpts()); + if (auto *RD = Loc.getType()->getAsCXXRecordDecl()) + return setResult(RD, TypeBeginLoc, TypeEndLoc); + return true; } // Other: @@ -170,7 +172,7 @@ const NamedDecl *getNamedDeclAt(const ASTContext &Context, const NamedDecl *getNamedDeclFor(const ASTContext &Context, const std::string &Name) { const auto &SourceMgr = Context.getSourceManager(); - NamedDeclFindingASTVisitor Visitor(SourceMgr, Name); + NamedDeclFindingASTVisitor Visitor(SourceMgr, Name, &Context); Visitor.TraverseDecl(Context.getTranslationUnitDecl()); return Visitor.getNamedDecl(); |

