diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-26 18:54:04 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-26 18:54:04 +0000 |
commit | 31cf12c0a628ce452e325eec45eaed307059df27 (patch) | |
tree | 7470279d12c5dc2a47215ff25b518964544f08cf /clang/lib/AST/Decl.cpp | |
parent | 7d287cb7ed0188f85fa4730f3e3c079aff5457d9 (diff) | |
download | bcm5719-llvm-31cf12c0a628ce452e325eec45eaed307059df27.tar.gz bcm5719-llvm-31cf12c0a628ce452e325eec45eaed307059df27.zip |
When evaluating a VarDecl as a constant or determining whether it is
an integral constant expression, maintain a cache of the value and the
is-an-ICE flag within the VarDecl itself. This eliminates
exponential-time behavior of the Fibonacci template metaprogram.
llvm-svn: 72428
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 20fe39d0af5..6c620713f76 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -89,6 +89,15 @@ QualType ParmVarDecl::getOriginalType() const { return getType(); } +void VarDecl::setInit(ASTContext &C, Expr *I) { + if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) { + Eval->~EvaluatedStmt(); + C.Deallocate(Eval); + } + + Init = I; + } + bool VarDecl::isExternC(ASTContext &Context) const { if (!Context.getLangOptions().CPlusPlus) return (getDeclContext()->isTranslationUnit() && @@ -287,8 +296,13 @@ VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, void VarDecl::Destroy(ASTContext& C) { Expr *Init = getInit(); - if (Init) + if (Init) { Init->Destroy(C); + if (EvaluatedStmt *Eval = this->Init.dyn_cast<EvaluatedStmt *>()) { + Eval->~EvaluatedStmt(); + C.Deallocate(Eval); + } + } this->~VarDecl(); C.Deallocate((void *)this); } |