[clang] Fix a null pointer dereference.

Summary:
Sometimes expression inside switch statement can be invalid, for
example type might be incomplete. In those cases code were causing a null
pointer dereference. This patch fixes that.

Reviewers: sammccall, ioeric, hokein

Reviewed By: sammccall

Subscribers: arphaman, cfe-commits

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

llvm-svn: 345029
This commit is contained in:
Kadir Cetinkaya 2018-10-23 13:49:37 +00:00
parent d3d2a0b591
commit 6d57266a8c
2 changed files with 13 additions and 0 deletions

View File

@ -4419,6 +4419,9 @@ void Sema::CodeCompleteCase(Scope *S) {
return;
SwitchStmt *Switch = getCurFunction()->SwitchStack.back().getPointer();
// Condition expression might be invalid, do not continue in this case.
if (!Switch->getCond())
return;
QualType type = Switch->getCond()->IgnoreImplicit()->getType();
if (!type->isEnumeralType()) {
CodeCompleteExpressionData Data(type);

View File

@ -0,0 +1,10 @@
void f() {
auto foo = bar;
switch(foo) {
case x:
break;
}
}
// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:4:10 %s | FileCheck %s -allow-empty
// CHECK-NOT: COMPLETION: foo