[PATCH] D53070: [CodeComplete] Fix crash when completing params function declarations.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 10 03:09:15 PDT 2018
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a subscriber: cfe-commits.
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.
Repository:
rC Clang
https://reviews.llvm.org/D53070
Files:
lib/Sema/SemaCodeComplete.cpp
test/CodeCompletion/crash-func-decl.cpp
Index: test/CodeCompletion/crash-func-decl.cpp
===================================================================
--- /dev/null
+++ test/CodeCompletion/crash-func-decl.cpp
@@ -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
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -1881,7 +1881,8 @@
}
// 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53070.168967.patch
Type: text/x-patch
Size: 964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181010/191c7dca/attachment.bin>
More information about the cfe-commits
mailing list