summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-12-23 21:13:52 +0000
committerTed Kremenek <kremenek@apple.com>2009-12-23 21:13:52 +0000
commit40ee0cc813b369f699f0a5af566f7947bad017b2 (patch)
treeb1c9af8087273b094f52ae097de3034c0b470938 /clang/lib/AST/ASTContext.cpp
parent04e7ae6a575a7a7a9e8c712962eed6174905a189 (diff)
downloadbcm5719-llvm-40ee0cc813b369f699f0a5af566f7947bad017b2.tar.gz
bcm5719-llvm-40ee0cc813b369f699f0a5af566f7947bad017b2.zip
Tidy up ~ASTContext a bit by turning orphan compound statements into
for loops. Also do not manually free the Type objects when the 'FreeMemory' flag is set, as they will be deallocated when the BumpPtrAllocator is destroyed. llvm-svn: 92047
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
-rw-r--r--clang/lib/AST/ASTContext.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 0e36a0ad1cf..bba169938b5 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -56,44 +56,43 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
}
ASTContext::~ASTContext() {
- // Deallocate all the types.
- while (!Types.empty()) {
- Types.back()->Destroy(*this);
- Types.pop_back();
- }
+ if (FreeMemory) {
+ // Deallocate all the types.
+ while (!Types.empty()) {
+ Types.back()->Destroy(*this);
+ Types.pop_back();
+ }
- {
- llvm::FoldingSet<ExtQuals>::iterator
- I = ExtQualNodes.begin(), E = ExtQualNodes.end();
- while (I != E)
+ for (llvm::FoldingSet<ExtQuals>::iterator
+ I = ExtQualNodes.begin(), E = ExtQualNodes.end(); I != E; ) {
+ // Increment in loop to prevent using deallocated memory.
Deallocate(&*I++);
+ }
}
- {
- llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
- I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end();
- while (I != E) {
- ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second);
- delete R;
- }
+ for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
+ I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
+ // Increment in loop to prevent using deallocated memory.
+ ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second);
+ delete R;
}
- {
- llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>::iterator
- I = ObjCLayouts.begin(), E = ObjCLayouts.end();
- while (I != E) {
- ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second);
- delete R;
- }
+ for (llvm::DenseMap<const ObjCContainerDecl*,
+ const ASTRecordLayout*>::iterator
+ I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) {
+ // Increment in loop to prevent using deallocated memory.
+ ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second);
+ delete R;
}
// Destroy nested-name-specifiers.
for (llvm::FoldingSet<NestedNameSpecifier>::iterator
NNS = NestedNameSpecifiers.begin(),
NNSEnd = NestedNameSpecifiers.end();
- NNS != NNSEnd;
- /* Increment in loop */)
+ NNS != NNSEnd; ) {
+ // Increment in loop to prevent using deallocated memory.
(*NNS++).Destroy(*this);
+ }
if (GlobalNestedNameSpecifier)
GlobalNestedNameSpecifier->Destroy(*this);
OpenPOWER on IntegriCloud