]> granicus.if.org Git - clang/commitdiff
Fix crash in -Wuninitialized when using switch statments whose condition is a logical...
authorTed Kremenek <kremenek@apple.com>
Tue, 10 May 2011 22:10:35 +0000 (22:10 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 10 May 2011 22:10:35 +0000 (22:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131158 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/UninitializedValues.cpp
test/Sema/uninit-variables.c

index 88a2db751a43e4a51e64325300c82c5ddea0c0c8..fc0b904c83cd3b57b037341df869b9eb8155f87b 100644 (file)
@@ -214,11 +214,15 @@ static BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) {
   if (!b || !b->isLogicalOp())
     return 0;
   
-  if (block->pred_size() == 2 &&
-      ((block->succ_size() == 2 && block->getTerminatorCondition() == b) ||
-       block->size() == 1))
-    return b;
-  
+  if (block->pred_size() == 2) {
+    if (block->getTerminatorCondition() == b) {
+      if (block->succ_size() == 2)
+      return b;
+    }
+    else if (block->size() == 1)
+      return b;
+  }
+
   return 0;
 }
 
index 60cae802ae73a8f70dcb712791d4957a5e33af38..b70a29519c411083542a2700c26db4eb58a7e0ca 100644 (file)
@@ -339,3 +339,16 @@ int test51(void)
     return a; // no-warning
 }
 
+// FIXME: This is a false positive, but it tests logical operations in switch statements.
+int test52(int a, int b) {
+  int x;  // expected-note {{variable 'x' is declared here}} expected-note {{add initialization to silence this warning}}
+  switch (a || b) { // expected-warning {{switch condition has boolean value}}
+    case 0:
+      x = 1;
+      break;
+    case 1:
+      x = 2;
+      break;
+  }
+  return x; // expected-warning {{variable 'x' may be uninitialized when used here}}
+}