aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-03-04 04:18:04 +0000
committerTed Kremenek <kremenek@apple.com>2008-03-04 04:18:04 +0000
commit16d81566604ca44ef8e71a6807e16944223e5ace (patch)
treea5925d45fec70ba2bcd367d2e0f5f3c443647451
parented2d2edecc0c5b92df99baf0ee31ac915b2e7c6a (diff)
Add transfer function support for the default initialization of static
variables that are pointers or integers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47880 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Analysis/GRExprEngine.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/Analysis/GRExprEngine.cpp b/Analysis/GRExprEngine.cpp
index 9513deb3f1..8db5a14be4 100644
--- a/Analysis/GRExprEngine.cpp
+++ b/Analysis/GRExprEngine.cpp
@@ -623,8 +623,34 @@ void GRExprEngine::VisitDeclStmt(DeclStmt* DS, GRExprEngine::NodeTy* Pred,
// FIXME: static variables may have an initializer, but the second
// time a function is called those values may not be current.
- St = SetRVal(St, lval::DeclVal(VD),
- Ex ? GetRVal(St, Ex) : UndefinedVal());
+ if ( VD->getStorageClass() == VarDecl::Static) {
+
+ QualType T = VD->getType();
+
+ // C99: 6.7.8 Initialization
+ // If an object that has static storage duration is not initialized
+ // explicitly, then:
+ // —if it has pointer type, it is initialized to a null pointer;
+ // —if it has arithmetic type, it is initialized to (positive or
+ // unsigned) zero;
+
+ if (T->isPointerType()) {
+
+ St = SetRVal(St, lval::DeclVal(VD),
+ lval::ConcreteInt(ValMgr.getValue(0, T)));
+ }
+ else if (T->isIntegerType()) {
+
+ St = SetRVal(St, lval::DeclVal(VD),
+ nonlval::ConcreteInt(ValMgr.getValue(0, T)));
+ }
+
+ // FIXME: Handle structs. Now we treat their values as unknown.
+ }
+ else
+ St = SetRVal(St, lval::DeclVal(VD),
+ Ex ? GetRVal(St, Ex) : UndefinedVal());
+
}
}