forked from OSchip/llvm-project
[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:
parent
d3d2a0b591
commit
6d57266a8c
|
@ -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);
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue