[cfe-commits] r138408 - in /cfe/trunk: include/clang/Analysis/CFG.h lib/Analysis/CFG.cpp lib/Analysis/CFGStmtMap.cpp lib/Analysis/LiveVariables.cpp lib/Analysis/UninitializedValues.cpp lib/Sema/AnalysisBasedWarnings.cpp lib/StaticAnalyzer/Core/ExprEngine.cpp

Ted Kremenek kremenek at apple.com
Tue Aug 23 16:05:05 PDT 2011


Author: kremenek
Date: Tue Aug 23 18:05:04 2011
New Revision: 138408

URL: http://llvm.org/viewvc/llvm-project?rev=138408&view=rev
Log:
Constify the result of CFGStmt::getStmt().

Modified:
    cfe/trunk/include/clang/Analysis/CFG.h
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/lib/Analysis/CFGStmtMap.cpp
    cfe/trunk/lib/Analysis/LiveVariables.cpp
    cfe/trunk/lib/Analysis/UninitializedValues.cpp
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=138408&r1=138407&r2=138408&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Tue Aug 23 18:05:04 2011
@@ -96,7 +96,9 @@
 public:
   CFGStmt(Stmt *S) : CFGElement(Statement, S) {}
 
-  Stmt *getStmt() const { return static_cast<Stmt *>(Data1.getPointer()); }
+  const Stmt *getStmt() const { 
+    return static_cast<const Stmt *>(Data1.getPointer());
+  }
 
   static bool classof(const CFGElement *E) {
     return E->getKind() == Statement;
@@ -622,7 +624,7 @@
       for (CFGBlock::const_iterator BI=(*I)->begin(), BE=(*I)->end();
            BI != BE; ++BI) {
         if (const CFGStmt *stmt = BI->getAs<CFGStmt>())
-          O(stmt->getStmt());
+          O(const_cast<Stmt*>(stmt->getStmt()));
       }
   }
 

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=138408&r1=138407&r2=138408&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Aug 23 18:05:04 2011
@@ -3014,17 +3014,17 @@
   typedef llvm::DenseMap<const Stmt*,unsigned> BlkExprMapTy;
 }
 
-static void FindSubExprAssignments(Stmt *S,
-                                   llvm::SmallPtrSet<Expr*,50>& Set) {
+static void FindSubExprAssignments(const Stmt *S,
+                                   llvm::SmallPtrSet<const Expr*,50>& Set) {
   if (!S)
     return;
 
-  for (Stmt::child_range I = S->children(); I; ++I) {
-    Stmt *child = *I;
+  for (Stmt::const_child_range I = S->children(); I; ++I) {
+    const Stmt *child = *I;
     if (!child)
       continue;
 
-    if (BinaryOperator* B = dyn_cast<BinaryOperator>(child))
+    if (const BinaryOperator* B = dyn_cast<BinaryOperator>(child))
       if (B->isAssignmentOp()) Set.insert(B);
 
     FindSubExprAssignments(child, Set);
@@ -3038,7 +3038,7 @@
   // assignments that we want to *possibly* register as a block-level
   // expression.  Basically, if an assignment occurs both in a subexpression and
   // at the block-level, it is a block-level expression.
-  llvm::SmallPtrSet<Expr*,50> SubExprAssignments;
+  llvm::SmallPtrSet<const Expr*,50> SubExprAssignments;
 
   for (CFG::iterator I=cfg.begin(), E=cfg.end(); I != E; ++I)
     for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI)
@@ -3054,10 +3054,10 @@
       const CFGStmt *CS = BI->getAs<CFGStmt>();
       if (!CS)
         continue;
-      if (Expr *Exp = dyn_cast<Expr>(CS->getStmt())) {
+      if (const Expr *Exp = dyn_cast<Expr>(CS->getStmt())) {
         assert((Exp->IgnoreParens() == Exp) && "No parens on block-level exps");
 
-        if (BinaryOperator* B = dyn_cast<BinaryOperator>(Exp)) {
+        if (const BinaryOperator* B = dyn_cast<BinaryOperator>(Exp)) {
           // Assignment expressions that are not nested within another
           // expression are really "statements" whose value is never used by
           // another expression.
@@ -3358,13 +3358,13 @@
 static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper,
                        const CFGElement &E) {
   if (const CFGStmt *CS = E.getAs<CFGStmt>()) {
-    Stmt *S = CS->getStmt();
+    const Stmt *S = CS->getStmt();
     
     if (Helper) {
 
       // special printing for statement-expressions.
-      if (StmtExpr *SE = dyn_cast<StmtExpr>(S)) {
-        CompoundStmt *Sub = SE->getSubStmt();
+      if (const StmtExpr *SE = dyn_cast<StmtExpr>(S)) {
+        const CompoundStmt *Sub = SE->getSubStmt();
 
         if (Sub->children()) {
           OS << "({ ... ; ";
@@ -3374,7 +3374,7 @@
         }
       }
       // special printing for comma expressions.
-      if (BinaryOperator* B = dyn_cast<BinaryOperator>(S)) {
+      if (const BinaryOperator* B = dyn_cast<BinaryOperator>(S)) {
         if (B->getOpcode() == BO_Comma) {
           OS << "... , ";
           Helper->handledStmt(B->getRHS(),OS);

Modified: cfe/trunk/lib/Analysis/CFGStmtMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFGStmtMap.cpp?rev=138408&r1=138407&r2=138408&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFGStmtMap.cpp (original)
+++ cfe/trunk/lib/Analysis/CFGStmtMap.cpp Tue Aug 23 18:05:04 2011
@@ -19,7 +19,7 @@
 
 using namespace clang;
 
-typedef llvm::DenseMap<Stmt*,CFGBlock*> SMap;
+typedef llvm::DenseMap<const Stmt*, CFGBlock*> SMap;
 static SMap *AsMap(void *m) { return (SMap*) m; }
 
 CFGStmtMap::~CFGStmtMap() { delete AsMap(M); }

Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=138408&r1=138407&r2=138408&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Tue Aug 23 18:05:04 2011
@@ -406,7 +406,7 @@
       for (CFGBlock::const_iterator bi = block->begin(), be = block->end();
            bi != be; ++bi) {
         if (const CFGStmt *cs = bi->getAs<CFGStmt>()) {
-          if (BinaryOperator *BO = dyn_cast<BinaryOperator>(cs->getStmt())) {
+          if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(cs->getStmt())) {
             if (BO->getOpcode() == BO_Assign) {
               if (const DeclRefExpr *DR =
                     dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) {

Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=138408&r1=138407&r2=138408&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Tue Aug 23 18:05:04 2011
@@ -164,7 +164,7 @@
 /// This function pattern matches for a '&&' or '||' that appears at
 /// the beginning of a CFGBlock that also (1) has a terminator and 
 /// (2) has no other elements.  If such an expression is found, it is returned.
-static BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) {
+static const BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) {
   if (block->empty())
     return 0;
 
@@ -172,7 +172,7 @@
   if (!cstmt)
     return 0;
 
-  BinaryOperator *b = dyn_cast_or_null<BinaryOperator>(cstmt->getStmt());
+  const BinaryOperator *b = dyn_cast_or_null<BinaryOperator>(cstmt->getStmt());
   
   if (!b || !b->isLogicalOp())
     return 0;
@@ -653,7 +653,7 @@
   for (CFGBlock::const_iterator I = block->begin(), E = block->end(); 
        I != E; ++I) {
     if (const CFGStmt *cs = dyn_cast<CFGStmt>(&*I)) {
-      tf.Visit(cs->getStmt());
+      tf.Visit(const_cast<Stmt*>(cs->getStmt()));
     }
   }
   tf.ProcessUses();

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=138408&r1=138407&r2=138408&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Aug 23 18:05:04 2011
@@ -170,7 +170,7 @@
     }
 
     CFGStmt CS = cast<CFGStmt>(*ri);
-    Stmt *S = CS.getStmt();
+    const Stmt *S = CS.getStmt();
     if (isa<ReturnStmt>(S)) {
       HasLiveReturn = true;
       continue;
@@ -196,13 +196,13 @@
     }
 
     bool NoReturnEdge = false;
-    if (CallExpr *C = dyn_cast<CallExpr>(S)) {
+    if (const CallExpr *C = dyn_cast<CallExpr>(S)) {
       if (std::find(B.succ_begin(), B.succ_end(), &cfg->getExit())
             == B.succ_end()) {
         HasAbnormalEdge = true;
         continue;
       }
-      Expr *CEE = C->getCallee()->IgnoreParenCasts();
+      const Expr *CEE = C->getCallee()->IgnoreParenCasts();
       QualType calleeType = CEE->getType();
       if (calleeType == AC.getASTContext().BoundMemberTy) {
         calleeType = Expr::findBoundMemberType(CEE);
@@ -211,8 +211,8 @@
       if (getFunctionExtInfo(calleeType).getNoReturn()) {
         NoReturnEdge = true;
         HasFakeEdge = true;
-      } else if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
-        ValueDecl *VD = DRE->getDecl();
+      } else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
+        const ValueDecl *VD = DRE->getDecl();
         if (VD->hasAttr<NoReturnAttr>()) {
           NoReturnEdge = true;
           HasFakeEdge = true;
@@ -1095,7 +1095,7 @@
     for (CFGBlock::const_iterator BI = CurrBlock->begin(),
          BE = CurrBlock->end(); BI != BE; ++BI) {
       if (const CFGStmt *CfgStmt = dyn_cast<CFGStmt>(&*BI)) {
-        LocksetBuilder.Visit(CfgStmt->getStmt());
+        LocksetBuilder.Visit(const_cast<Stmt*>(CfgStmt->getStmt()));
       }
     }
     Exitset = LocksetBuilder.getLockset();

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=138408&r1=138407&r2=138408&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Aug 23 18:05:04 2011
@@ -208,7 +208,7 @@
     case CFGElement::Invalid:
       llvm_unreachable("Unexpected CFGElement kind.");
     case CFGElement::Statement:
-      ProcessStmt(E.getAs<CFGStmt>()->getStmt(), builder);
+      ProcessStmt(const_cast<Stmt*>(E.getAs<CFGStmt>()->getStmt()), builder);
       return;
     case CFGElement::Initializer:
       ProcessInitializer(E.getAs<CFGInitializer>()->getInitializer(), builder);





More information about the cfe-commits mailing list