This revision was automatically updated to reflect the committed changes.
Closed by commit rL345029: [clang] Fix a null pointer dereference. (authored by 
kadircet, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53561

Files:
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/test/Index/complete-switch.c


Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -4419,6 +4419,9 @@
     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);
Index: cfe/trunk/test/Index/complete-switch.c
===================================================================
--- cfe/trunk/test/Index/complete-switch.c
+++ cfe/trunk/test/Index/complete-switch.c
@@ -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


Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -4419,6 +4419,9 @@
     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);
Index: cfe/trunk/test/Index/complete-switch.c
===================================================================
--- cfe/trunk/test/Index/complete-switch.c
+++ cfe/trunk/test/Index/complete-switch.c
@@ -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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to