summaryrefslogtreecommitdiffstats
path: root/clang/Driver/ASTConsumers.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-23 16:25:39 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-23 16:25:39 +0000
commit467297ab48cdc353f1059d292e22043271602d2b (patch)
tree2ea496552c574bb5823378391ad6152f9c536e50 /clang/Driver/ASTConsumers.cpp
parent107d369b8b6a5c870c4e807c1334aaec59e0a734 (diff)
downloadbcm5719-llvm-467297ab48cdc353f1059d292e22043271602d2b.tar.gz
bcm5719-llvm-467297ab48cdc353f1059d292e22043271602d2b.zip
TranslationUnit now owns IdentifierTable, TargetInfo, and Selectors objects
when it is constructed via deserialization. This is done by recording a flag indicating that this is the case, and it deletes these objects by getting the references stored in the ASTContext object. This fixes some memory leaks that occurs when we deserialize translation units from bitcode files. The rationale between having TranslationUnit sometimes own these objects and sometimes not is that a TranslationUnit object can be constructed from state generated by the parser (Preprocessor; semantic analyzer, etc.), and thus in these cases won't own the IdentifierTable or Selectors, etc. During deserialization, there is no Preprocessor, so somebody needs to own these objects in order for them to be properly reclaimed. llvm-svn: 50149
Diffstat (limited to 'clang/Driver/ASTConsumers.cpp')
-rw-r--r--clang/Driver/ASTConsumers.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/clang/Driver/ASTConsumers.cpp b/clang/Driver/ASTConsumers.cpp
index eaee94e51da..2f04ab78d4f 100644
--- a/clang/Driver/ASTConsumers.cpp
+++ b/clang/Driver/ASTConsumers.cpp
@@ -826,20 +826,24 @@ namespace {
class ASTSerializer : public ASTConsumer {
protected:
Diagnostic &Diags;
- TranslationUnit TU;
+ const LangOptions& lang;
+ TranslationUnit* TU;
+
public:
ASTSerializer(Diagnostic& diags, const LangOptions& LO)
- : Diags(diags), TU(LO) {}
+ : Diags(diags), lang(LO), TU(0) {}
+
+ virtual ~ASTSerializer() { delete TU; }
virtual void Initialize(ASTContext &Context) {
- TU.setContext(&Context);
+ if (!TU) TU = new TranslationUnit(Context, lang);
}
virtual void HandleTopLevelDecl(Decl *D) {
if (Diags.hasErrorOccurred())
return;
- TU.AddTopLevelDecl(D);
+ if (TU) TU->AddTopLevelDecl(D);
}
};
@@ -851,7 +855,7 @@ public:
: ASTSerializer(diags,LO), FName(F) {}
~SingleFileSerializer() {
- EmitASTBitcodeFile(TU,FName);
+ EmitASTBitcodeFile(TU, FName);
}
};
@@ -863,7 +867,11 @@ public:
: ASTSerializer(diags,LO), EmitDir(dir) {}
~BuildSerializer() {
- SourceManager& SourceMgr = TU.getASTContext()->getSourceManager();
+
+ if (!TU)
+ return;
+
+ SourceManager& SourceMgr = TU->getContext().getSourceManager();
unsigned ID = SourceMgr.getMainFileID();
assert (ID && "MainFileID not set!");
const FileEntry* FE = SourceMgr.getFileEntryForID(ID);
@@ -887,7 +895,7 @@ public:
sprintf(&buf[0], "%s-%llX.ast", FE->getName(), (uint64_t) FE->getInode());
FName.appendComponent(&buf[0]);
- EmitASTBitcodeFile(TU,FName);
+ EmitASTBitcodeFile(TU, FName);
// Now emit the sources.
OpenPOWER on IntegriCloud