r312788 - Fixed a crash in code completion.
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 8 06:36:38 PDT 2017
Author: ibiryukov
Date: Fri Sep 8 06:36:38 2017
New Revision: 312788
URL: http://llvm.org/viewvc/llvm-project?rev=312788&view=rev
Log:
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
Added:
cfe/trunk/test/CodeCompletion/crash-func-init.cpp
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=312788&r1=312787&r2=312788&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Sep 8 06:36:38 2017
@@ -2264,11 +2264,23 @@ Decl *Parser::ParseDeclarationAfterDecla
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);
Added: cfe/trunk/test/CodeCompletion/crash-func-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/crash-func-init.cpp?rev=312788&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/crash-func-init.cpp (added)
+++ cfe/trunk/test/CodeCompletion/crash-func-init.cpp Fri Sep 8 06:36:38 2017
@@ -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
More information about the cfe-commits
mailing list