Skip to content

Commit

Permalink
[CodeComplete] Fix crash when completing params function declarations.
Browse files Browse the repository at this point in the history
Summary:
In a decl like `int AA(BB cc)` where BB isn't defined, we end up trying to
parse `BB cc` as an expression (vexing parse) and end up triggering the
parser's "recovery-in-function" completion with no actual function
scope.

This patch avoids the assumption that such a scope exists in this context.

Reviewers: kadircet

Subscribers: cfe-commits

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

llvm-svn: 344133
  • Loading branch information
sam-mccall committed Oct 10, 2018
1 parent 5cb3a82 commit aeb4b3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,8 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC,
}

// Switch-specific statements.
if (!SemaRef.getCurFunction()->SwitchStack.empty()) {
if (SemaRef.getCurFunction() &&
!SemaRef.getCurFunction()->SwitchStack.empty()) {
// case expression:
Builder.AddTypedTextChunk("case");
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Expand Down
5 changes: 5 additions & 0 deletions clang/test/CodeCompletion/crash-func-decl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Important that BB is unknown.
// This triggers completion in PCC_RecoveryInFunction context, with no function.
int AA(BB cc);
// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:3:12 %s | FileCheck %s
// CHECK: COMPLETION: char

0 comments on commit aeb4b3e

Please sign in to comment.