r345029 - [clang] Fix a null pointer dereference.
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 23 06:49:37 PDT 2018
Author: kadircet
Date: Tue Oct 23 06:49:37 2018
New Revision: 345029
URL: http://llvm.org/viewvc/llvm-project?rev=345029&view=rev
Log:
[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
Added:
cfe/trunk/test/Index/complete-switch.c
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=345029&r1=345028&r2=345029&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Oct 23 06:49:37 2018
@@ -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);
Added: cfe/trunk/test/Index/complete-switch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-switch.c?rev=345029&view=auto
==============================================================================
--- cfe/trunk/test/Index/complete-switch.c (added)
+++ cfe/trunk/test/Index/complete-switch.c Tue Oct 23 06:49:37 2018
@@ -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
More information about the cfe-commits
mailing list