diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-09-26 22:58:57 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-09-26 22:58:57 +0000 |
commit | 610a09e409bea151a42dd907768f1e0c4b103f1f (patch) | |
tree | dd9366b3d348fbcbba99d4b527f92f51d4817c89 /lib | |
parent | a2c6912c416c2d9f79d18f3a88ab0ae2609286c3 (diff) |
Add CFG support for implicit-control flow for VLA size expressions within an SizeOfAlignOfTypeExpr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56706 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/CFG.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/AST/CFG.cpp b/lib/AST/CFG.cpp index 41ae454d44..0313ada82c 100644 --- a/lib/AST/CFG.cpp +++ b/lib/AST/CFG.cpp @@ -180,6 +180,18 @@ private: bool badCFG; }; + +static VariableArrayType* FindVA(Type* t) { + while (ArrayType* vt = dyn_cast<ArrayType>(t)) { + if (VariableArrayType* vat = dyn_cast<VariableArrayType>(vt)) + if (vat->getSizeExpr()) + return vat; + + t = vt->getElementType().getTypePtr(); + } + + return 0; +} /// BuildCFG - Constructs a CFG from an AST (a Stmt*). The AST can /// represent an arbitrary statement. Examples include a single expression @@ -405,6 +417,17 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) { case Stmt::StmtExprClass: return WalkAST_VisitStmtExpr(cast<StmtExpr>(Terminator)); + case Stmt::SizeOfAlignOfTypeExprClass: { + SizeOfAlignOfTypeExpr* E = cast<SizeOfAlignOfTypeExpr>(Terminator); + + // VLA types have expressions that must be evaluated. + for (VariableArrayType* VA = FindVA(E->getArgumentType().getTypePtr()); + VA != 0; VA = FindVA(VA->getElementType().getTypePtr())) + addStmt(VA->getSizeExpr()); + + return Block; + } + case Stmt::UnaryOperatorClass: { UnaryOperator* U = cast<UnaryOperator>(Terminator); @@ -475,18 +498,6 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) { if (AlwaysAddStmt) Block->appendStmt(Terminator); return WalkAST_VisitChildren(Terminator); } - -static VariableArrayType* FindVA(Type* t) { - while (ArrayType* vt = dyn_cast<ArrayType>(t)) { - if (VariableArrayType* vat = dyn_cast<VariableArrayType>(vt)) - if (vat->getSizeExpr()) - return vat; - - t = vt->getElementType().getTypePtr(); - } - - return 0; -} /// WalkAST_VisitDeclSubExpr - Utility method to add block-level expressions /// for initializers in Decls. |