summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/CFG.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2013-03-28 18:43:15 +0000
committerTed Kremenek <kremenek@apple.com>2013-03-28 18:43:15 +0000
commit0dd8feee93baf81bb24fe69a41f75508de549495 (patch)
treed13fb9992e07b5e00b63b55a213d4d3d7fa8b8ae /clang/lib/Analysis/CFG.cpp
parentca5ce187fac45bc818dab205c0036c004a9862b7 (diff)
downloadbcm5719-llvm-0dd8feee93baf81bb24fe69a41f75508de549495.tar.gz
bcm5719-llvm-0dd8feee93baf81bb24fe69a41f75508de549495.zip
Add CFG logic to create a conditional branch for modeling static initializers.
This is an optional variant of the CFG. This allows analyses to model whether or not a static initializer has run, e.g.: static Foo x = bar(); For basic dataflow analysis in Sema we will just assume that the initializer always runs. For the static analyzer we can use this branch to accurately track whether or not initializers are on. This patch just adds the (opt-in) functionality to the CFG. The static analyzer still needs to be modified to adopt this feature. llvm-svn: 178263
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r--clang/lib/Analysis/CFG.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index f20f84c5c0f..f436ef3f6a3 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -1653,10 +1653,24 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) {
bool IsReference = false;
bool HasTemporaries = false;
+ // Guard static initializers under a branch.
+ CFGBlock *blockBeforeInit = 0;
+
// Destructors of temporaries in initialization expression should be called
// after initialization finishes.
Expr *Init = VD->getInit();
if (Init) {
+ if (BuildOpts.AddStaticInitBranches && VD->isStaticLocal()) {
+ // For static variables, we need to create a branch to track
+ // whether or not they are initialized.
+ if (Block) {
+ Succ = Block;
+ if (badCFG)
+ return 0;
+ }
+ blockBeforeInit = Succ;
+ }
+
IsReference = VD->getType()->isReferenceType();
HasTemporaries = isa<ExprWithCleanups>(Init);
@@ -1700,7 +1714,18 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) {
if (ScopePos && VD == *ScopePos)
++ScopePos;
- return Block ? Block : LastBlock;
+ CFGBlock *B = Block ? Block : LastBlock;
+ if (blockBeforeInit) {
+ Succ = B;
+ Block = 0;
+ CFGBlock *branchBlock = createBlock(false);
+ branchBlock->setTerminator(DS);
+ addSuccessor(branchBlock, blockBeforeInit);
+ addSuccessor(branchBlock, B);
+ B = branchBlock;
+ }
+
+ return B;
}
CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) {
@@ -3642,6 +3667,11 @@ public:
Terminator->printPretty(OS, Helper, Policy);
}
+ void VisitDeclStmt(DeclStmt *DS) {
+ VarDecl *VD = cast<VarDecl>(DS->getSingleDecl());
+ OS << "static init " << VD->getName();
+ }
+
void VisitForStmt(ForStmt *F) {
OS << "for (" ;
if (F->getInit())
OpenPOWER on IntegriCloud