[libclang] Fix a crash with invalid code, while skip function bodies is enabled.

llvm-svn: 175860
This commit is contained in:
Argyrios Kyrtzidis 2013-02-22 04:11:06 +00:00
parent 62eae089ca
commit 4431918f40
3 changed files with 7 additions and 3 deletions

View File

@ -1974,7 +1974,7 @@ Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
assert(Tok.is(tok::l_brace));
SourceLocation LBraceLoc = Tok.getLocation();
if (SkipFunctionBodies && Actions.canSkipFunctionBody(Decl) &&
if (SkipFunctionBodies && (!Decl || Actions.canSkipFunctionBody(Decl)) &&
trySkippingFunctionBody()) {
BodyScope.Exit();
return Actions.ActOnSkippedFunctionBody(Decl);

View File

@ -8449,9 +8449,9 @@ bool Sema::canSkipFunctionBody(Decl *D) {
}
Decl *Sema::ActOnSkippedFunctionBody(Decl *Decl) {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl))
if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(Decl))
FD->setHasSkippedBody();
else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(Decl))
else if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(Decl))
MD->setHasSkippedBody();
return ActOnFinishFunctionBody(Decl, 0);
}

View File

@ -1,5 +1,9 @@
using MyTypeAlias = int;
extern "C" {
template < typename T > *Allocate() { }
}
// RUN: c-index-test -index-file %s > %t
// RUN: FileCheck %s -input-file=%t