aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2013-02-21 20:58:29 +0000
committerDavid Blaikie <dblaikie@gmail.com>2013-02-21 20:58:29 +0000
commitfdf6a279c9a75c778eba382d9a156697092982a1 (patch)
treee67bc01445260b8cd78ddfd21f1a9f4fe059ac79 /lib/Analysis
parent05f8ff134d5f270bd7bfe4aaef491bd3febddea1 (diff)
Replace CFGElement llvm::cast support to be well-defined.
See r175462 for another example/more details. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175796 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/CFG.cpp40
-rw-r--r--lib/Analysis/CFGStmtMap.cpp4
-rw-r--r--lib/Analysis/LiveVariables.cpp12
-rw-r--r--lib/Analysis/ReachableCode.cpp4
-rw-r--r--lib/Analysis/ThreadSafety.cpp30
-rw-r--r--lib/Analysis/UninitializedValues.cpp4
6 files changed, 47 insertions, 47 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp
index 01553b884e..8754fe86a8 100644
--- a/lib/Analysis/CFG.cpp
+++ b/lib/Analysis/CFG.cpp
@@ -3338,7 +3338,7 @@ CFGImplicitDtor::getDestructorDecl(ASTContext &astContext) const {
llvm_unreachable("getDestructorDecl should only be used with "
"ImplicitDtors");
case CFGElement::AutomaticObjectDtor: {
- const VarDecl *var = cast<CFGAutomaticObjDtor>(this)->getVarDecl();
+ const VarDecl *var = castAs<CFGAutomaticObjDtor>().getVarDecl();
QualType ty = var->getType();
ty = ty.getNonReferenceType();
while (const ArrayType *arrayType = astContext.getAsArrayType(ty)) {
@@ -3351,7 +3351,7 @@ CFGImplicitDtor::getDestructorDecl(ASTContext &astContext) const {
}
case CFGElement::TemporaryDtor: {
const CXXBindTemporaryExpr *bindExpr =
- cast<CFGTemporaryDtor>(this)->getBindTemporaryExpr();
+ castAs<CFGTemporaryDtor>().getBindTemporaryExpr();
const CXXTemporary *temp = bindExpr->getTemporary();
return temp->getDestructor();
}
@@ -3406,8 +3406,8 @@ static BlkExprMapTy* PopulateBlkExprMap(CFG& cfg) {
for (CFG::iterator I=cfg.begin(), E=cfg.end(); I != E; ++I)
for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI)
- if (const CFGStmt *S = BI->getAs<CFGStmt>())
- FindSubExprAssignments(S->getStmt(), SubExprAssignments);
+ if (CFGStmt S = BI->getAs<CFGStmt>())
+ FindSubExprAssignments(S.getStmt(), SubExprAssignments);
for (CFG::iterator I=cfg.begin(), E=cfg.end(); I != E; ++I) {
@@ -3415,10 +3415,10 @@ static BlkExprMapTy* PopulateBlkExprMap(CFG& cfg) {
// block-level that are block-level expressions.
for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI) {
- const CFGStmt *CS = BI->getAs<CFGStmt>();
+ CFGStmt CS = BI->getAs<CFGStmt>();
if (!CS)
continue;
- if (const 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 (const BinaryOperator* B = dyn_cast<BinaryOperator>(Exp)) {
@@ -3531,8 +3531,8 @@ public:
unsigned j = 1;
for (CFGBlock::const_iterator BI = (*I)->begin(), BEnd = (*I)->end() ;
BI != BEnd; ++BI, ++j ) {
- if (const CFGStmt *SE = BI->getAs<CFGStmt>()) {
- const Stmt *stmt= SE->getStmt();
+ if (CFGStmt SE = BI->getAs<CFGStmt>()) {
+ const Stmt *stmt= SE.getStmt();
std::pair<unsigned, unsigned> P((*I)->getBlockID(), j);
StmtMap[stmt] = P;
@@ -3721,8 +3721,8 @@ public:
static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper,
const CFGElement &E) {
- if (const CFGStmt *CS = E.getAs<CFGStmt>()) {
- const Stmt *S = CS->getStmt();
+ if (CFGStmt CS = E.getAs<CFGStmt>()) {
+ const Stmt *S = CS.getStmt();
if (Helper) {
@@ -3769,8 +3769,8 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper,
if (isa<Expr>(S))
OS << '\n';
- } else if (const CFGInitializer *IE = E.getAs<CFGInitializer>()) {
- const CXXCtorInitializer *I = IE->getInitializer();
+ } else if (CFGInitializer IE = E.getAs<CFGInitializer>()) {
+ const CXXCtorInitializer *I = IE.getInitializer();
if (I->isBaseInitializer())
OS << I->getBaseClass()->getAsCXXRecordDecl()->getName();
else OS << I->getAnyMember()->getName();
@@ -3784,8 +3784,8 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper,
OS << " (Base initializer)\n";
else OS << " (Member initializer)\n";
- } else if (const CFGAutomaticObjDtor *DE = E.getAs<CFGAutomaticObjDtor>()){
- const VarDecl *VD = DE->getVarDecl();
+ } else if (CFGAutomaticObjDtor DE = E.getAs<CFGAutomaticObjDtor>()){
+ const VarDecl *VD = DE.getVarDecl();
Helper->handleDecl(VD, OS);
const Type* T = VD->getType().getTypePtr();
@@ -3796,20 +3796,20 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper,
OS << ".~" << T->getAsCXXRecordDecl()->getName().str() << "()";
OS << " (Implicit destructor)\n";
- } else if (const CFGBaseDtor *BE = E.getAs<CFGBaseDtor>()) {
- const CXXBaseSpecifier *BS = BE->getBaseSpecifier();
+ } else if (CFGBaseDtor BE = E.getAs<CFGBaseDtor>()) {
+ const CXXBaseSpecifier *BS = BE.getBaseSpecifier();
OS << "~" << BS->getType()->getAsCXXRecordDecl()->getName() << "()";
OS << " (Base object destructor)\n";
- } else if (const CFGMemberDtor *ME = E.getAs<CFGMemberDtor>()) {
- const FieldDecl *FD = ME->getFieldDecl();
+ } else if (CFGMemberDtor ME = E.getAs<CFGMemberDtor>()) {
+ const FieldDecl *FD = ME.getFieldDecl();
const Type *T = FD->getType()->getBaseElementTypeUnsafe();
OS << "this->" << FD->getName();
OS << ".~" << T->getAsCXXRecordDecl()->getName() << "()";
OS << " (Member object destructor)\n";
- } else if (const CFGTemporaryDtor *TE = E.getAs<CFGTemporaryDtor>()) {
- const CXXBindTemporaryExpr *BT = TE->getBindTemporaryExpr();
+ } else if (CFGTemporaryDtor TE = E.getAs<CFGTemporaryDtor>()) {
+ const CXXBindTemporaryExpr *BT = TE.getBindTemporaryExpr();
OS << "~" << BT->getType()->getAsCXXRecordDecl()->getName() << "()";
OS << " (Temporary object destructor)\n";
}
diff --git a/lib/Analysis/CFGStmtMap.cpp b/lib/Analysis/CFGStmtMap.cpp
index 16df67678d..7daeef9216 100644
--- a/lib/Analysis/CFGStmtMap.cpp
+++ b/lib/Analysis/CFGStmtMap.cpp
@@ -50,11 +50,11 @@ static void Accumulate(SMap &SM, CFGBlock *B) {
// First walk the block-level expressions.
for (CFGBlock::iterator I = B->begin(), E = B->end(); I != E; ++I) {
const CFGElement &CE = *I;
- const CFGStmt *CS = CE.getAs<CFGStmt>();
+ CFGStmt CS = CE.getAs<CFGStmt>();
if (!CS)
continue;
- CFGBlock *&Entry = SM[CS->getStmt()];
+ CFGBlock *&Entry = SM[CS.getStmt()];
// If 'Entry' is already initialized (e.g., a terminator was already),
// skip.
if (Entry)
diff --git a/lib/Analysis/LiveVariables.cpp b/lib/Analysis/LiveVariables.cpp
index 1f616f7a5d..519d5288b8 100644
--- a/lib/Analysis/LiveVariables.cpp
+++ b/lib/Analysis/LiveVariables.cpp
@@ -474,15 +474,15 @@ LiveVariablesImpl::runOnBlock(const CFGBlock *block,
ei = block->rend(); it != ei; ++it) {
const CFGElement &elem = *it;
- if (const CFGAutomaticObjDtor *Dtor = dyn_cast<CFGAutomaticObjDtor>(&elem)){
- val.liveDecls = DSetFact.add(val.liveDecls, Dtor->getVarDecl());
+ if (CFGAutomaticObjDtor Dtor = elem.getAs<CFGAutomaticObjDtor>()){
+ val.liveDecls = DSetFact.add(val.liveDecls, Dtor.getVarDecl());
continue;
}
- if (!isa<CFGStmt>(elem))
+ if (!elem.getAs<CFGStmt>())
continue;
- const Stmt *S = cast<CFGStmt>(elem).getStmt();
+ const Stmt *S = elem.castAs<CFGStmt>().getStmt();
TF.Visit(const_cast<Stmt*>(S));
stmtsToLiveness[S] = val;
}
@@ -534,8 +534,8 @@ LiveVariables::computeLiveness(AnalysisDeclContext &AC,
if (killAtAssign)
for (CFGBlock::const_iterator bi = block->begin(), be = block->end();
bi != be; ++bi) {
- if (const CFGStmt *cs = bi->getAs<CFGStmt>()) {
- if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(cs->getStmt())) {
+ if (CFGStmt cs = bi->getAs<CFGStmt>()) {
+ if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(cs.getStmt())) {
if (BO->getOpcode() == BO_Assign) {
if (const DeclRefExpr *DR =
dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) {
diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp
index 7bf01bbbe8..f85e2dee52 100644
--- a/lib/Analysis/ReachableCode.cpp
+++ b/lib/Analysis/ReachableCode.cpp
@@ -95,8 +95,8 @@ static bool isValidDeadStmt(const Stmt *S) {
const Stmt *DeadCodeScan::findDeadCode(const clang::CFGBlock *Block) {
for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I!=E; ++I)
- if (const CFGStmt *CS = I->getAs<CFGStmt>()) {
- const Stmt *S = CS->getStmt();
+ if (CFGStmt CS = I->getAs<CFGStmt>()) {
+ const Stmt *S = CS.getStmt();
if (isValidDeadStmt(S))
return S;
}
diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp
index 20d8f97e2d..2e3abc07b7 100644
--- a/lib/Analysis/ThreadSafety.cpp
+++ b/lib/Analysis/ThreadSafety.cpp
@@ -1350,8 +1350,8 @@ void LocalVariableMap::traverseCFG(CFG *CFGraph,
BE = CurrBlock->end(); BI != BE; ++BI) {
switch (BI->getKind()) {
case CFGElement::Statement: {
- const CFGStmt *CS = cast<CFGStmt>(&*BI);
- VMapBuilder.Visit(const_cast<Stmt*>(CS->getStmt()));
+ CFGStmt CS = BI->castAs<CFGStmt>();
+ VMapBuilder.Visit(const_cast<Stmt*>(CS.getStmt()));
break;
}
default:
@@ -1397,8 +1397,8 @@ static void findBlockLocations(CFG *CFGraph,
for (CFGBlock::const_reverse_iterator BI = CurrBlock->rbegin(),
BE = CurrBlock->rend(); BI != BE; ++BI) {
// FIXME: Handle other CFGElement kinds.
- if (const CFGStmt *CS = dyn_cast<CFGStmt>(&*BI)) {
- CurrBlockInfo->ExitLoc = CS->getStmt()->getLocStart();
+ if (CFGStmt CS = BI->getAs<CFGStmt>()) {
+ CurrBlockInfo->ExitLoc = CS.getStmt()->getLocStart();
break;
}
}
@@ -1410,8 +1410,8 @@ static void findBlockLocations(CFG *CFGraph,
for (CFGBlock::const_iterator BI = CurrBlock->begin(),
BE = CurrBlock->end(); BI != BE; ++BI) {
// FIXME: Handle other CFGElement kinds.
- if (const CFGStmt *CS = dyn_cast<CFGStmt>(&*BI)) {
- CurrBlockInfo->EntryLoc = CS->getStmt()->getLocStart();
+ if (CFGStmt CS = BI->getAs<CFGStmt>()) {
+ CurrBlockInfo->EntryLoc = CS.getStmt()->getLocStart();
break;
}
}
@@ -2234,8 +2234,8 @@ inline bool neverReturns(const CFGBlock* B) {
return false;
CFGElement Last = B->back();
- if (CFGStmt* S = dyn_cast<CFGStmt>(&Last)) {
- if (isa<CXXThrowExpr>(S->getStmt()))
+ if (CFGStmt S = Last.getAs<CFGStmt>()) {
+ if (isa<CXXThrowExpr>(S.getStmt()))
return true;
}
return false;
@@ -2444,22 +2444,22 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
BE = CurrBlock->end(); BI != BE; ++BI) {
switch (BI->getKind()) {
case CFGElement::Statement: {
- const CFGStmt *CS = cast<CFGStmt>(&*BI);
- LocksetBuilder.Visit(const_cast<Stmt*>(CS->getStmt()));
+ CFGStmt CS = BI->castAs<CFGStmt>();
+ LocksetBuilder.Visit(const_cast<Stmt*>(CS.getStmt()));
break;
}
// Ignore BaseDtor, MemberDtor, and TemporaryDtor for now.
case CFGElement::AutomaticObjectDtor: {
- const CFGAutomaticObjDtor *AD = cast<CFGAutomaticObjDtor>(&*BI);
- CXXDestructorDecl *DD = const_cast<CXXDestructorDecl*>(
- AD->getDestructorDecl(AC.getASTContext()));
+ CFGAutomaticObjDtor AD = BI->castAs<CFGAutomaticObjDtor>();
+ CXXDestructorDecl *DD = const_cast<CXXDestructorDecl *>(
+ AD.getDestructorDecl(AC.getASTContext()));
if (!DD->hasAttrs())
break;
// Create a dummy expression,
- VarDecl *VD = const_cast<VarDecl*>(AD->getVarDecl());
+ VarDecl *VD = const_cast<VarDecl*>(AD.getVarDecl());
DeclRefExpr DRE(VD, false, VD->getType(), VK_LValue,
- AD->getTriggerStmt()->getLocEnd());
+ AD.getTriggerStmt()->getLocEnd());
LocksetBuilder.handleCall(&DRE, DD);
break;
}
diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp
index 13af4353cd..022bb7d513 100644
--- a/lib/Analysis/UninitializedValues.cpp
+++ b/lib/Analysis/UninitializedValues.cpp
@@ -746,8 +746,8 @@ static bool runOnBlock(const CFGBlock *block, const CFG &cfg,
TransferFunctions tf(vals, cfg, block, ac, classification, handler);
for (CFGBlock::const_iterator I = block->begin(), E = block->end();
I != E; ++I) {
- if (const CFGStmt *cs = dyn_cast<CFGStmt>(&*I)) {
- tf.Visit(const_cast<Stmt*>(cs->getStmt()));
+ if (CFGStmt cs = I->getAs<CFGStmt>()) {
+ tf.Visit(const_cast<Stmt*>(cs.getStmt()));
}
}
return vals.updateValueVectorWithScratch(block);