diff --git a/clang/Driver/ASTConsumers.h b/clang/Driver/ASTConsumers.h index 37f825b5daec..43dd738c39ec 100644 --- a/clang/Driver/ASTConsumers.h +++ b/clang/Driver/ASTConsumers.h @@ -31,7 +31,7 @@ ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags); ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags); ASTConsumer *CreateLLVMEmitter(Diagnostic &Diags, const LangOptions &Features); ASTConsumer *CreateCodeRewriterTest(Diagnostic &Diags); -ASTConsumer *CreateSerializationTest(); +ASTConsumer *CreateSerializationTest(Diagnostic &Diags); } // end clang namespace diff --git a/clang/Driver/SerializationTest.cpp b/clang/Driver/SerializationTest.cpp index f8d4b7820e34..80049d4f2bb0 100644 --- a/clang/Driver/SerializationTest.cpp +++ b/clang/Driver/SerializationTest.cpp @@ -15,10 +15,12 @@ //===----------------------------------------------------------------------===// #include "ASTConsumers.h" +#include "clang/Basic/TargetInfo.h" #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/CFG.h" +#include "clang.h" #include "llvm/System/Path.h" #include "llvm/Support/Streams.h" #include "llvm/Support/MemoryBuffer.h" @@ -51,6 +53,7 @@ public: class SerializationTest : public ASTConsumer { ASTContext* Context; + Diagnostic &Diags; std::list Decls; enum { BasicMetadataBlock = 1, @@ -58,7 +61,7 @@ class SerializationTest : public ASTConsumer { DeclsBlock = 3 }; public: - SerializationTest() : Context(NULL) {}; + SerializationTest(Diagnostic &d) : Context(NULL), Diags(d) {}; ~SerializationTest(); virtual void Initialize(ASTContext& context, unsigned) { @@ -76,8 +79,8 @@ private: } // end anonymous namespace -ASTConsumer* clang::CreateSerializationTest() { - return new SerializationTest(); +ASTConsumer* clang::CreateSerializationTest(Diagnostic &Diags) { + return new SerializationTest(Diags); } static void WritePreamble(llvm::BitstreamWriter& Stream) { @@ -171,9 +174,10 @@ void SerializationTest::Serialize(llvm::sys::Path& Filename, llvm::cerr << "Faux-serializing: SourceManager.\n"; Sezr.EmitPtr(&Context->SourceMgr); - // "Fake" emit the Target. - llvm::cerr << "Faux-serializing: Target.\n"; + // Emit the Target. + llvm::cerr << "Serializing: Target.\n"; Sezr.EmitPtr(&Context->Target); + Sezr.EmitCStr(Context->Target.getTargetTriple()); Sezr.ExitBlock(); @@ -256,13 +260,21 @@ void SerializationTest::Deserialize(llvm::sys::Path& Filename, llvm::cerr << "Faux-Deserializing: SourceManager.\n"; Dezr.RegisterPtr(&Context->SourceMgr); - // "Fake" read the TargetInfo. - llvm::cerr << "Faux-Deserializing: Target.\n"; - Dezr.RegisterPtr(&Context->Target); - + { // Read the TargetInfo. + llvm::cerr << "Deserializing: Target.\n"; + llvm::SerializedPtrID PtrID = Dezr.ReadPtrID(); + char* triple = Dezr.ReadCStr(NULL,0,true); + std::vector triples; + triples.push_back(triple); + delete [] triple; + Dezr.RegisterPtr(PtrID,CreateTargetInfo(triples,Diags)); + } + // For Selectors, we must read the identifier table first because the // SelectorTable depends on the identifiers being already deserialized. - llvm::Deserializer::Location SelectorBlockLoc = Dezr.getCurrentBlockLocation(); + llvm::Deserializer::Location SelectorBlockLoc = + Dezr.getCurrentBlockLocation(); + Dezr.SkipBlock(); // Read the identifier table. diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index b403dd324a45..139febeda1c8 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -899,7 +899,7 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID, break; case TestSerialization: - Consumer = CreateSerializationTest(); + Consumer = CreateSerializationTest(PP.getDiagnostics()); break; case EmitLLVM: