Skip to content

Commit

Permalink
fix: don't crash on empty function/enum bodies (#3281)
Browse files Browse the repository at this point in the history
In some cases, `FunctionDecl::hasBody` (and presumably `EnumDecl::hasBody`,
though I don't have a crasher for that) will report `true` when
`FunctionDecl::getBody` would return null. Prefer using `getBody`
to check whether a decl has a body.
  • Loading branch information
zrlk committed Nov 26, 2018
1 parent f749ea9 commit f06d335
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@ bool IndexerASTVisitor::VisitEnumDecl(const clang::EnumDecl* Decl) {
GraphObserver::NodeId DeclNode(BuildNodeIdForDecl(Decl));
SourceLocation DeclLoc = Decl->getLocation();
SourceRange NameRange = RangeForNameOfDeclaration(Decl);
if (Decl->isThisDeclarationADefinition() && Decl->hasBody()) {
if (Decl->isThisDeclarationADefinition() && Decl->getBody() != nullptr) {
Marks.set_marked_source_end(Decl->getBody()->getSourceRange().getBegin());
} else {
Marks.set_marked_source_end(GetLocForEndOfToken(
Expand Down Expand Up @@ -2893,7 +2893,7 @@ bool IndexerASTVisitor::VisitFunctionDecl(clang::FunctionDecl* Decl) {
SourceLocation DeclLoc = Decl->getLocation();
SourceRange NameRange = RangeForNameOfDeclaration(Decl);
if (!DeclLoc.isMacroID() && Decl->isThisDeclarationADefinition() &&
Decl->hasBody()) {
Decl->getBody() != nullptr) {
Marks.set_marked_source_end(Decl->getBody()->getSourceRange().getBegin());
} else {
Marks.set_marked_source_end(GetLocForEndOfToken(
Expand Down

0 comments on commit f06d335

Please sign in to comment.