]> granicus.if.org Git - clang/commitdiff
CFG bug fix: for sizeof(expressions), don't expand the control-flow
authorTed Kremenek <kremenek@apple.com>
Thu, 13 Dec 2007 22:44:18 +0000 (22:44 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 13 Dec 2007 22:44:18 +0000 (22:44 +0000)
of "expressions", since they are not really evaluated.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45015 91177308-0d34-0410-b5e6-96231b3b80d8

AST/CFG.cpp

index b93d77e3fa06117cc0a91da9d41684bf1a532744..43e6870511e221bde73b5f0a67bba99a4804974a 100644 (file)
@@ -225,8 +225,7 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* S, bool AlwaysAddStmt = false) {
       // of the ternary expression.
       CFGBlock* ConfluenceBlock = (Block) ? Block : createBlock();  
       ConfluenceBlock->appendStmt(C);
-      FinishBlock(ConfluenceBlock);
-      
+      FinishBlock(ConfluenceBlock);      
 
       // Create a block for the LHS expression if there is an LHS expression.
       // A GCC extension allows LHS to be NULL, causing the condition to
@@ -317,6 +316,20 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* S, bool AlwaysAddStmt = false) {
     case Stmt::StmtExprClass:
       return WalkAST_VisitStmtExpr(cast<StmtExpr>(S));
 
+    case Stmt::UnaryOperatorClass: {
+      UnaryOperator* U = cast<UnaryOperator>(S);
+      
+      // sizeof(expressions).  For such expressions,
+      // the subexpression is not really evaluated, so
+      // we don't care about control-flow within the sizeof.
+      if (U->getOpcode() == UnaryOperator::SizeOf) {
+        Block->appendStmt(S);
+        return Block;
+      }
+      
+      break;
+    }
+      
     case Stmt::BinaryOperatorClass: {
       BinaryOperator* B = cast<BinaryOperator>(S);
 
@@ -345,14 +358,16 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* S, bool AlwaysAddStmt = false) {
         addStmt(B->getRHS());
         return addStmt(B->getLHS());
       }
-
-      // Fall through to the default case.
+      
+      break;
     }
     
     default:
-      if (AlwaysAddStmt) Block->appendStmt(S);
-      return WalkAST_VisitChildren(S);
+      break;
   };
+      
+  if (AlwaysAddStmt) Block->appendStmt(S);
+  return WalkAST_VisitChildren(S);
 }
 
 /// WalkAST_VisitDeclSubExprs - Utility method to handle Decls contained in