Author: sammccall Date: Wed Oct 10 03:51:48 2018 New Revision: 344133 URL: http://llvm.org/viewvc/llvm-project?rev=344133&view=rev Log: [CodeComplete] Fix crash when completing params function declarations.
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 Added: cfe/trunk/test/CodeCompletion/crash-func-decl.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=344133&r1=344132&r2=344133&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Oct 10 03:51:48 2018 @@ -1881,7 +1881,8 @@ static void AddOrdinaryNameResults(Sema: } // 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); Added: cfe/trunk/test/CodeCompletion/crash-func-decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/crash-func-decl.cpp?rev=344133&view=auto ============================================================================== --- cfe/trunk/test/CodeCompletion/crash-func-decl.cpp (added) +++ cfe/trunk/test/CodeCompletion/crash-func-decl.cpp Wed Oct 10 03:51:48 2018 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits