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 | 8f7afdd21e20036f6236e297d2841abcadf86f96 (patch) | |
tree | 0f6c2455b7188bb4f86ecaa1d5376e0989ef6ef2 /clang/lib/Analysis/GRExprEngine.cpp | |
parent | e598370ae9638f198d718d9dab724d64a7f37718 (diff) | |
download | bcm5719-llvm-8f7afdd21e20036f6236e297d2841abcadf86f96.tar.gz bcm5719-llvm-8f7afdd21e20036f6236e297d2841abcadf86f96.zip |
Add checking for zero-sized VLAs.
llvm-svn: 60726
Diffstat (limited to 'clang/lib/Analysis/GRExprEngine.cpp')
-rw-r--r-- | clang/lib/Analysis/GRExprEngine.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/clang/lib/Analysis/GRExprEngine.cpp b/clang/lib/Analysis/GRExprEngine.cpp index 8a32bfe9524..fb520675734 100644 --- a/clang/lib/Analysis/GRExprEngine.cpp +++ b/clang/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); } |