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 =================================================================== --- test/CodeCompletion/crash-func-decl.cpp +++ 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