[PATCH] D53561: [clang] Fix a null pointer dereference.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 23 04:56:45 PDT 2018


kadircet updated this revision to Diff 170608.
kadircet added a comment.
Herald added a subscriber: arphaman.

- Add tests.


Repository:
  rC Clang

https://reviews.llvm.org/D53561

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


Index: test/Index/complete-switch.c
===================================================================
--- /dev/null
+++ 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: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53561.170608.patch
Type: text/x-patch
Size: 926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181023/07c938f6/attachment.bin>


More information about the cfe-commits mailing list