[cfe-commits] r54590 - /cfe/trunk/Driver/ASTConsumers.cpp
Nico Weber
nicolasweber at gmx.de
Sat Aug 9 11:32:12 PDT 2008
Author: nico
Date: Sat Aug 9 13:32:11 2008
New Revision: 54590
URL: http://llvm.org/viewvc/llvm-project?rev=54590&view=rev
Log:
do not serialize invalid asts. this fixes bug #2637
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=54590&r1=54589&r2=54590&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Sat Aug 9 13:32:11 2008
@@ -14,6 +14,7 @@
#include "ASTConsumers.h"
#include "HTMLDiagnostics.h"
#include "clang/AST/TranslationUnit.h"
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/FileManager.h"
#include "clang/AST/AST.h"
@@ -526,9 +527,10 @@
class ASTSerializer : public ASTConsumer {
protected:
TranslationUnit* TU;
+ Diagnostic& Diags;
public:
- ASTSerializer() : TU(0) {}
+ ASTSerializer(Diagnostic& diags) : TU(0), Diags(diags) {}
virtual void InitializeTU(TranslationUnit &tu) {
TU = &tu;
@@ -539,9 +541,12 @@
class SingleFileSerializer : public ASTSerializer {
const llvm::sys::Path FName;
public:
- SingleFileSerializer(const llvm::sys::Path& F) : FName(F) {}
+ SingleFileSerializer(const llvm::sys::Path& F, Diagnostic& diags)
+ : ASTSerializer(diags), FName(F) {}
~SingleFileSerializer() {
+ if (Diags.hasErrorOccurred())
+ return;
EmitASTBitcodeFile(TU, FName);
}
};
@@ -549,11 +554,12 @@
class BuildSerializer : public ASTSerializer {
llvm::sys::Path EmitDir;
public:
- BuildSerializer(const llvm::sys::Path& dir) : EmitDir(dir) {}
+ BuildSerializer(const llvm::sys::Path& dir, Diagnostic& diags)
+ : ASTSerializer(diags), EmitDir(dir) {}
~BuildSerializer() {
- if (!TU)
+ if (!TU || Diags.hasErrorOccurred())
return;
SourceManager& SourceMgr = TU->getContext().getSourceManager();
@@ -624,7 +630,7 @@
// FIXME: We should probably only allow using BuildSerializer when
// the ASTs come from parsed source files, and not from .ast files.
- return new BuildSerializer(EmitDir);
+ return new BuildSerializer(EmitDir, Diags);
}
// The user did not specify an output directory for serialized ASTs.
@@ -633,7 +639,7 @@
llvm::sys::Path FName(InFile.c_str());
FName.appendSuffix("ast");
- return new SingleFileSerializer(FName);
+ return new SingleFileSerializer(FName, Diags);
}
class LLVMCodeGenWriter : public ASTConsumer {
More information about the cfe-commits
mailing list