]> granicus.if.org Git - clang/commitdiff
[analyzer] Ignore parentheses around block-level expressions when computing liveness...
authorJordy Rose <jediknil@belkadan.com>
Thu, 9 Jun 2011 05:44:04 +0000 (05:44 +0000)
committerJordy Rose <jediknil@belkadan.com>
Thu, 9 Jun 2011 05:44:04 +0000 (05:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132769 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LiveVariables.cpp
test/Analysis/misc-ps.c

index 303dc0f604d7662a3a6b56e9149cfcf204f178a7..0fe87e8719bd6314fd0975a529be9c3911978c1a 100644 (file)
@@ -142,8 +142,12 @@ void TransferFuncs::Visit(Stmt *S) {
     if (AD.Observer)
       AD.Observer->ObserveStmt(S, currentBlock, AD, LiveState);
 
-    if (getCFG().isBlkExpr(S))
-      LiveState(S, AD) = Dead;
+    if (getCFG().isBlkExpr(S)) {
+      if (Expr *E = dyn_cast<Expr>(S)) 
+        LiveState(E->IgnoreParens(), AD) = Dead;
+      else
+        LiveState(S, AD) = Dead;
+    }
 
     StmtVisitor<TransferFuncs,void>::Visit(S);
   }
@@ -157,7 +161,10 @@ void TransferFuncs::Visit(Stmt *S) {
   }
   else {
     // For block-level expressions, mark that they are live.
-    LiveState(S,AD) = Alive;
+    if (Expr *E = dyn_cast<Expr>(S)) 
+      LiveState(E->IgnoreParens(), AD) = Alive;
+    else
+      LiveState(S, AD) = Alive;
   }
 }
   
@@ -174,6 +181,9 @@ void TransferFuncs::VisitTerminator(CFGBlock* B) {
     return;
 
   assert (getCFG().isBlkExpr(E));
+
+  if (const Expr *Ex = dyn_cast<Expr>(E))
+    E = Ex->IgnoreParens();
   LiveState(E, AD) = Alive;
 }
 
index 0729ce2f7750f02f83aff5fcfc2c69e025805d6a..84992c6bb25f18ea178e49fd8d70a5abf9814a49 100644 (file)
@@ -50,3 +50,15 @@ int PR8962_b (int *t) {
   return *t; // expected-warning {{null pointer}}
 }
 
+int PR8962_c (int *t) {
+  // If the last element in a StmtExpr was a ParenExpr, it's still live
+  if (({ (t ? (_Bool)0 : (_Bool)1); })) return 0;
+  return *t; // no-warning
+}
+
+int PR8962_d (int *t) {
+  // If the last element in a StmtExpr is an __extension__, it's still live
+  if (({ __extension__(t ? (_Bool)0 : (_Bool)1); })) return 0;
+  return *t; // no-warning
+}
+