aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-10-27 12:50:38 +0000
committerDouglas Gregor <dgregor@apple.com>2008-10-27 12:50:38 +0000
commit3dda64ec0fad2fa60d882565d135ff598897fa9d (patch)
tree5af4d49fbb89e1121682d04ba281bfccc2d47692
parent4a1513e535f9db2027c60bc96a4276435743857c (diff)
When destroying a translation unit, deallocate its owned declarations in reverse order, because there may be dependencies among the declarations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58244 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Decl.h17
-rw-r--r--lib/AST/TranslationUnit.cpp4
-rw-r--r--test/SemaCXX/fntype-decl.cpp10
3 files changed, 15 insertions, 16 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index be8d842525..e1e34f44c5 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -514,23 +514,10 @@ public:
typedef ParmVarDecl * const *param_const_iterator;
param_iterator param_begin() { return ParamInfo; }
- param_iterator param_end() {
-
- // Special-case for handling typedefs:
- //
- // typedef void func_t(int x);
- // func_t a;
- //
- // In the case of the FunctionDecl for "a", there are no ParmVarDecls.
-
- return ParamInfo ? ParamInfo+param_size() : 0x0;
- }
+ param_iterator param_end() { return ParamInfo+param_size(); }
param_const_iterator param_begin() const { return ParamInfo; }
-
- param_const_iterator param_end() const {
- return ParamInfo ? ParamInfo+param_size() : 0x0;
- }
+ param_const_iterator param_end() const { return ParamInfo+param_size(); }
unsigned getNumParams() const;
const ParmVarDecl *getParamDecl(unsigned i) const {
diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp
index 659aa064de..42b7ceae1e 100644
--- a/lib/AST/TranslationUnit.cpp
+++ b/lib/AST/TranslationUnit.cpp
@@ -33,7 +33,9 @@ enum { BasicMetadataBlock = 1,
TranslationUnit::~TranslationUnit() {
if (OwnsDecls) {
llvm::DenseSet<Decl*> Killed;
- for (iterator I=begin(), E=end(); I!=E; ++I) {
+ for (std::vector<Decl*>::reverse_iterator I=TopLevelDecls.rbegin(),
+ E=TopLevelDecls.rend();
+ I!=E; ++I) {
if (Killed.count(*I)) continue;
Killed.insert(*I);
diff --git a/test/SemaCXX/fntype-decl.cpp b/test/SemaCXX/fntype-decl.cpp
index b54346624c..d9fb8bbb59 100644
--- a/test/SemaCXX/fntype-decl.cpp
+++ b/test/SemaCXX/fntype-decl.cpp
@@ -3,3 +3,13 @@
// PR2942
typedef void fn(int);
fn f;
+
+int g(int x, int y);
+int g(int x, int y = 2);
+
+typedef int g_type(int, int);
+g_type g;
+
+int h(int x) {
+ return g(x);
+}