[cfe-commits] r54618 - /cfe/trunk/Driver/ASTConsumers.cpp
Nico Weber
nicolasweber at gmx.de
Sun Aug 10 12:20:06 PDT 2008
Author: nico
Date: Sun Aug 10 14:20:05 2008
New Revision: 54618
URL: http://llvm.org/viewvc/llvm-project?rev=54618&view=rev
Log:
Do not crash with -serialize.
This happened because seralization was done in the constructor, and at that time the TranslationUnit is no longer valid.
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=54618&r1=54617&r2=54618&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Sun Aug 10 14:20:05 2008
@@ -526,16 +526,10 @@
class ASTSerializer : public ASTConsumer {
protected:
- TranslationUnit* TU;
Diagnostic& Diags;
public:
- ASTSerializer(Diagnostic& diags) : TU(0), Diags(diags) {}
-
- virtual void InitializeTU(TranslationUnit &tu) {
- TU = &tu;
- }
-
+ ASTSerializer(Diagnostic& diags) : Diags(diags) {}
};
class SingleFileSerializer : public ASTSerializer {
@@ -544,10 +538,10 @@
SingleFileSerializer(const llvm::sys::Path& F, Diagnostic& diags)
: ASTSerializer(diags), FName(F) {}
- ~SingleFileSerializer() {
+ virtual void HandleTranslationUnit(TranslationUnit& TU) {
if (Diags.hasErrorOccurred())
return;
- EmitASTBitcodeFile(TU, FName);
+ EmitASTBitcodeFile(&TU, FName);
}
};
@@ -557,12 +551,11 @@
BuildSerializer(const llvm::sys::Path& dir, Diagnostic& diags)
: ASTSerializer(diags), EmitDir(dir) {}
- ~BuildSerializer() {
-
- if (!TU || Diags.hasErrorOccurred())
+ virtual void HandleTranslationUnit(TranslationUnit& TU) {
+ if (Diags.hasErrorOccurred())
return;
- SourceManager& SourceMgr = TU->getContext().getSourceManager();
+ SourceManager& SourceMgr = TU.getContext().getSourceManager();
unsigned ID = SourceMgr.getMainFileID();
assert (ID && "MainFileID not set!");
const FileEntry* FE = SourceMgr.getFileEntryForID(ID);
@@ -586,7 +579,7 @@
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.
More information about the cfe-commits
mailing list