Fixed a crash in code completion.

Summary: The crash occured when FunctionDecl was parsed with an initializer.

Reviewers: bkramer, klimek, francisco.lopes

Reviewed By: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D37382

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312788 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ilya Biryukov 2017-09-08 13:36:38 +00:00
parent 0abc73f06c
commit 78a32be113
2 changed files with 21 additions and 5 deletions

View File

@ -2264,11 +2264,23 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
}
if (ParseExpressionList(Exprs, CommaLocs, [&] {
Actions.CodeCompleteConstructor(getCurScope(),
cast<VarDecl>(ThisDecl)->getType()->getCanonicalTypeInternal(),
ThisDecl->getLocation(), Exprs);
})) {
llvm::function_ref<void()> ExprListCompleter;
auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
auto ConstructorCompleter = [&, ThisVarDecl] {
Actions.CodeCompleteConstructor(
getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
ThisDecl->getLocation(), Exprs);
};
if (ThisVarDecl) {
// ParseExpressionList can sometimes succeed even when ThisDecl is not
// VarDecl. This is an error and it is reported in a call to
// Actions.ActOnInitializerError(). However, we call
// CodeCompleteConstructor only on VarDecls, falling back to default
// completer in other cases.
ExprListCompleter = ConstructorCompleter;
}
if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
Actions.ActOnInitializerError(ThisDecl);
SkipUntil(tok::r_paren, StopAtSemi);

View File

@ -0,0 +1,4 @@
int (*foo(int a))(flo
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
// RUN: | FileCheck %s
// CHECK: COMPLETION: float