diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-12-08 22:47:34 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-12-08 22:47:34 +0000 |
commit | efd5994d6a35b6b16b29cc59a0d9ef8a14d9c6f8 (patch) | |
tree | bbf326d826d9a0c5a66651080a5820a685d85557 /lib/Analysis/GRExprEngine.cpp | |
parent | 26b58cd65f5ae7b90d786b472a0ba527b14637e3 (diff) |
Add checking for zero-sized VLAs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60726 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/GRExprEngine.cpp')
-rw-r--r-- | lib/Analysis/GRExprEngine.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 8a32bfe952..fb52067573 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -1773,8 +1773,7 @@ void GRExprEngine::VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst) { if (!D || !isa<VarDecl>(D)) return; - const VarDecl* VD = dyn_cast<VarDecl>(D); - + const VarDecl* VD = dyn_cast<VarDecl>(D); Expr* InitEx = const_cast<Expr*>(VD->getInit()); // FIXME: static variables may have an initializer, but the second @@ -1812,6 +1811,33 @@ void GRExprEngine::VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst) { } else St = StateMgr.BindDecl(St, VD, 0, Count); + + + // Check if 'VD' is a VLA and if so check if has a non-zero size. + QualType T = getContext().getCanonicalType(VD->getType()); + if (VariableArrayType* VLA = dyn_cast<VariableArrayType>(T)) { + // FIXME: Handle multi-dimensional VLAs. + + Expr* SE = VLA->getSizeExpr(); + SVal Size = GetSVal(St, SE); + + bool isFeasibleZero = false; + const GRState* ZeroSt = Assume(St, Size, false, isFeasibleZero); + + bool isFeasibleNotZero = false; + St = Assume(St, Size, true, isFeasibleNotZero); + + if (isFeasibleZero) { + if (NodeTy* N = Builder->generateNode(DS, ZeroSt, Pred)) { + N->markAsSink(); + if (isFeasibleNotZero) ImplicitZeroSizedVLA.insert(N); + else ExplicitZeroSizedVLA.insert(N); + } + } + + if (!isFeasibleNotZero) + continue; + } MakeNode(Dst, DS, *I, St); } |