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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits