From f1d10d939739f1a4544926d807e4f0f9fb64be61 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 23 Aug 2011 23:05:04 +0000 Subject: [PATCH] Constify the result of CFGStmt::getStmt(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138408 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Analysis/CFG.h | 6 ++++-- lib/Analysis/CFG.cpp | 24 ++++++++++++------------ lib/Analysis/CFGStmtMap.cpp | 2 +- lib/Analysis/LiveVariables.cpp | 2 +- lib/Analysis/UninitializedValues.cpp | 6 +++--- lib/Sema/AnalysisBasedWarnings.cpp | 12 ++++++------ lib/StaticAnalyzer/Core/ExprEngine.cpp | 2 +- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/include/clang/Analysis/CFG.h b/include/clang/Analysis/CFG.h index f995dab7a4..c4f521d7a8 100644 --- a/include/clang/Analysis/CFG.h +++ b/include/clang/Analysis/CFG.h @@ -96,7 +96,9 @@ class CFGStmt : public CFGElement { public: CFGStmt(Stmt *S) : CFGElement(Statement, S) {} - Stmt *getStmt() const { return static_cast(Data1.getPointer()); } + const Stmt *getStmt() const { + return static_cast(Data1.getPointer()); + } static bool classof(const CFGElement *E) { return E->getKind() == Statement; @@ -622,7 +624,7 @@ public: for (CFGBlock::const_iterator BI=(*I)->begin(), BE=(*I)->end(); BI != BE; ++BI) { if (const CFGStmt *stmt = BI->getAs()) - O(stmt->getStmt()); + O(const_cast(stmt->getStmt())); } } diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index e0905eda21..f268c78dc5 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -3014,17 +3014,17 @@ namespace { typedef llvm::DenseMap BlkExprMapTy; } -static void FindSubExprAssignments(Stmt *S, - llvm::SmallPtrSet& Set) { +static void FindSubExprAssignments(const Stmt *S, + llvm::SmallPtrSet& 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(child)) + if (const BinaryOperator* B = dyn_cast(child)) if (B->isAssignmentOp()) Set.insert(B); FindSubExprAssignments(child, Set); @@ -3038,7 +3038,7 @@ static BlkExprMapTy* PopulateBlkExprMap(CFG& cfg) { // 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 SubExprAssignments; + llvm::SmallPtrSet 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 @@ static BlkExprMapTy* PopulateBlkExprMap(CFG& cfg) { const CFGStmt *CS = BI->getAs(); if (!CS) continue; - if (Expr *Exp = dyn_cast(CS->getStmt())) { + if (const Expr *Exp = dyn_cast(CS->getStmt())) { assert((Exp->IgnoreParens() == Exp) && "No parens on block-level exps"); - if (BinaryOperator* B = dyn_cast(Exp)) { + if (const BinaryOperator* B = dyn_cast(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 @@ public: static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper, const CFGElement &E) { if (const CFGStmt *CS = E.getAs()) { - Stmt *S = CS->getStmt(); + const Stmt *S = CS->getStmt(); if (Helper) { // special printing for statement-expressions. - if (StmtExpr *SE = dyn_cast(S)) { - CompoundStmt *Sub = SE->getSubStmt(); + if (const StmtExpr *SE = dyn_cast(S)) { + const CompoundStmt *Sub = SE->getSubStmt(); if (Sub->children()) { OS << "({ ... ; "; @@ -3374,7 +3374,7 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper, } } // special printing for comma expressions. - if (BinaryOperator* B = dyn_cast(S)) { + if (const BinaryOperator* B = dyn_cast(S)) { if (B->getOpcode() == BO_Comma) { OS << "... , "; Helper->handledStmt(B->getRHS(),OS); diff --git a/lib/Analysis/CFGStmtMap.cpp b/lib/Analysis/CFGStmtMap.cpp index 1fd5eedfeb..16df67678d 100644 --- a/lib/Analysis/CFGStmtMap.cpp +++ b/lib/Analysis/CFGStmtMap.cpp @@ -19,7 +19,7 @@ using namespace clang; -typedef llvm::DenseMap SMap; +typedef llvm::DenseMap SMap; static SMap *AsMap(void *m) { return (SMap*) m; } CFGStmtMap::~CFGStmtMap() { delete AsMap(M); } diff --git a/lib/Analysis/LiveVariables.cpp b/lib/Analysis/LiveVariables.cpp index 2a41bf863b..fb50f4c068 100644 --- a/lib/Analysis/LiveVariables.cpp +++ b/lib/Analysis/LiveVariables.cpp @@ -406,7 +406,7 @@ LiveVariables::computeLiveness(AnalysisContext &AC, for (CFGBlock::const_iterator bi = block->begin(), be = block->end(); bi != be; ++bi) { if (const CFGStmt *cs = bi->getAs()) { - if (BinaryOperator *BO = dyn_cast(cs->getStmt())) { + if (const BinaryOperator *BO = dyn_cast(cs->getStmt())) { if (BO->getOpcode() == BO_Assign) { if (const DeclRefExpr *DR = dyn_cast(BO->getLHS()->IgnoreParens())) { diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 77da2427c0..f0debc1f3e 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -164,7 +164,7 @@ ValueVector &CFGBlockValues::lazyCreate(ValueVector *&bv) { /// 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 @@ static BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) { if (!cstmt) return 0; - BinaryOperator *b = dyn_cast_or_null(cstmt->getStmt()); + const BinaryOperator *b = dyn_cast_or_null(cstmt->getStmt()); if (!b || !b->isLogicalOp()) return 0; @@ -653,7 +653,7 @@ static bool runOnBlock(const CFGBlock *block, const CFG &cfg, for (CFGBlock::const_iterator I = block->begin(), E = block->end(); I != E; ++I) { if (const CFGStmt *cs = dyn_cast(&*I)) { - tf.Visit(cs->getStmt()); + tf.Visit(const_cast(cs->getStmt())); } } tf.ProcessUses(); diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 99525bae9f..246a7db73c 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -170,7 +170,7 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) { } CFGStmt CS = cast(*ri); - Stmt *S = CS.getStmt(); + const Stmt *S = CS.getStmt(); if (isa(S)) { HasLiveReturn = true; continue; @@ -196,13 +196,13 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) { } bool NoReturnEdge = false; - if (CallExpr *C = dyn_cast(S)) { + if (const CallExpr *C = dyn_cast(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 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) { if (getFunctionExtInfo(calleeType).getNoReturn()) { NoReturnEdge = true; HasFakeEdge = true; - } else if (DeclRefExpr *DRE = dyn_cast(CEE)) { - ValueDecl *VD = DRE->getDecl(); + } else if (const DeclRefExpr *DRE = dyn_cast(CEE)) { + const ValueDecl *VD = DRE->getDecl(); if (VD->hasAttr()) { NoReturnEdge = true; HasFakeEdge = true; @@ -1095,7 +1095,7 @@ static void checkThreadSafety(Sema &S, AnalysisContext &AC) { for (CFGBlock::const_iterator BI = CurrBlock->begin(), BE = CurrBlock->end(); BI != BE; ++BI) { if (const CFGStmt *CfgStmt = dyn_cast(&*BI)) { - LocksetBuilder.Visit(CfgStmt->getStmt()); + LocksetBuilder.Visit(const_cast(CfgStmt->getStmt())); } } Exitset = LocksetBuilder.getLockset(); diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index a555b77296..6c318f756c 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -208,7 +208,7 @@ void ExprEngine::processCFGElement(const CFGElement E, case CFGElement::Invalid: llvm_unreachable("Unexpected CFGElement kind."); case CFGElement::Statement: - ProcessStmt(E.getAs()->getStmt(), builder); + ProcessStmt(const_cast(E.getAs()->getStmt()), builder); return; case CFGElement::Initializer: ProcessInitializer(E.getAs()->getInitializer(), builder); -- 2.40.0