Browse Source

Fixed a crash when trying to get a source location for an implicit declaration.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/987/head
Dimitar Dobrev 8 years ago
parent
commit
c3048ae8d8
  1. 28
      src/CppParser/Parser.cpp

28
src/CppParser/Parser.cpp

@ -481,6 +481,17 @@ static clang::Decl* GetPreviousDeclInContext(const clang::Decl* D) @@ -481,6 +481,17 @@ static clang::Decl* GetPreviousDeclInContext(const clang::Decl* D)
return nullptr;
}
bool IsExplicit(const clang::Decl* D)
{
using namespace clang;
auto CTS = llvm::dyn_cast<ClassTemplateSpecializationDecl>(D);
return !CTS ||
CTS->getSpecializationKind() == TSK_ExplicitSpecialization ||
CTS->getSpecializationKind() == TSK_ExplicitInstantiationDeclaration ||
CTS->getSpecializationKind() == TSK_ExplicitInstantiationDefinition;
}
static clang::SourceLocation GetDeclStartLocation(clang::CompilerInstance* C,
const clang::Decl* D)
{
@ -500,7 +511,7 @@ static clang::SourceLocation GetDeclStartLocation(clang::CompilerInstance* C, @@ -500,7 +511,7 @@ static clang::SourceLocation GetDeclStartLocation(clang::CompilerInstance* C,
return lineBeginLoc;
auto prevDecl = GetPreviousDeclInContext(D);
if(!prevDecl)
if(!prevDecl || !IsExplicit(prevDecl))
return lineBeginLoc;
auto prevDeclEndLoc = SM.getExpansionLoc(prevDecl->getLocEnd());
@ -816,6 +827,8 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC) @@ -816,6 +827,8 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC)
if (Record->isImplicit())
return;
if (IsExplicit(Record))
{
auto headStartLoc = GetDeclStartLocation(c.get(), Record);
auto headEndLoc = Record->getLocation(); // identifier location
auto bodyEndLoc = Record->getLocEnd();
@ -825,6 +838,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC) @@ -825,6 +838,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC)
HandlePreprocessedEntities(RC, headRange, MacroLocation::ClassHead);
HandlePreprocessedEntities(RC, bodyRange, MacroLocation::ClassBody);
}
auto& Sema = c->getSema();
@ -3429,8 +3443,17 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl) @@ -3429,8 +3443,17 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl)
Decl->USR = GetDeclUSR(D);
Decl->isImplicit = D->isImplicit();
Decl->location = SourceLocation(D->getLocation().getRawEncoding());
auto IsDeclExplicit = IsExplicit(D);
if (IsDeclExplicit)
{
Decl->lineNumberStart = c->getSourceManager().getExpansionLineNumber(D->getLocStart());
Decl->lineNumberEnd = c->getSourceManager().getExpansionLineNumber(D->getLocEnd());
}
else
{
Decl->lineNumberStart = -1;
Decl->lineNumberEnd = -1;
}
if (Decl->PreprocessedEntities.empty() && !D->isImplicit())
{
@ -3442,7 +3465,7 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl) @@ -3442,7 +3465,7 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl)
{
// Ignore function parameters as we already walk their preprocessed entities.
}
else
else if (IsDeclExplicit)
{
auto startLoc = GetDeclStartLocation(c.get(), D);
auto endLoc = D->getLocEnd();
@ -3452,6 +3475,7 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl) @@ -3452,6 +3475,7 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl)
}
}
if (IsDeclExplicit)
HandleOriginalText(D, Decl);
HandleComments(D, Decl);

Loading…
Cancel
Save