From a6acf3fd49a20c570a390af2a3c84e10b9545b68 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 5 Oct 2023 13:08:24 -0700 Subject: [PATCH] Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)" This reverts commit a50e63b38b931d945f97eac882278068221eca17. With clang-14.0.6 as the host compiler, I'm getting: ld.lld: error: undefined symbol: clang::ASTWriter::WriteAST(clang::Sema&, llvm::StringRef, clang::Module*, llvm::StringRef, bool, bool) >>> referenced by ASTUnit.cpp >>> ASTUnit.cpp.o:(clang::ASTUnit::serialize(llvm::raw_ostream&)) in archive lib/libclangFrontend.a --- clang/include/clang/Serialization/ASTWriter.h | 1 + clang/lib/Frontend/ASTUnit.cpp | 17 ++++++++++++----- clang/lib/Serialization/ASTWriter.cpp | 4 ++-- clang/lib/Serialization/GeneratePCH.cpp | 8 ++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 98445d40ebd82c..f2c7c03ff09360 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -613,6 +613,7 @@ class ASTWriter : public ASTDeserializationListener, /// the module but currently is merely a random 32-bit number. ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile, Module *WritingModule, StringRef isysroot, + bool hasErrors = false, bool ShouldCacheASTInMemory = false); /// Emit a token. diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 85157c3b21b664..016f88a43a56dd 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -2341,9 +2341,12 @@ bool ASTUnit::Save(StringRef File) { return false; } -static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl &Buffer, - Sema &S, raw_ostream &OS) { - Writer.WriteAST(S, std::string(), nullptr, ""); +static bool serializeUnit(ASTWriter &Writer, + SmallVectorImpl &Buffer, + Sema &S, + bool hasErrors, + raw_ostream &OS) { + Writer.WriteAST(S, std::string(), nullptr, "", hasErrors); // Write the generated bitstream to "Out". if (!Buffer.empty()) @@ -2353,14 +2356,18 @@ static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl &Buffer, } bool ASTUnit::serialize(raw_ostream &OS) { + // For serialization we are lenient if the errors were only warn-as-error kind. + bool hasErrors = getDiagnostics().hasUncompilableErrorOccurred(); + if (WriterData) - return serializeUnit(WriterData->Writer, WriterData->Buffer, getSema(), OS); + return serializeUnit(WriterData->Writer, WriterData->Buffer, + getSema(), hasErrors, OS); SmallString<128> Buffer; llvm::BitstreamWriter Stream(Buffer); InMemoryModuleCache ModuleCache; ASTWriter Writer(Stream, Buffer, ModuleCache, {}); - return serializeUnit(Writer, Buffer, getSema(), OS); + return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS); } using SLocRemap = ContinuousRangeMap; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 0acd86de06ba40..201e2fcaaec91a 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -4622,12 +4622,12 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile, Module *WritingModule, StringRef isysroot, + bool hasErrors, bool ShouldCacheASTInMemory) { llvm::TimeTraceScope scope("WriteAST", OutputFile); WritingAST = true; - ASTHasCompilerErrors = - SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred(); + ASTHasCompilerErrors = hasErrors; // Emit the file header. Stream.Emit((unsigned)'C', 8); diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp index cf8084333811f1..601a24b4aec46a 100644 --- a/clang/lib/Serialization/GeneratePCH.cpp +++ b/clang/lib/Serialization/GeneratePCH.cpp @@ -65,8 +65,12 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) { // Emit the PCH file to the Buffer. assert(SemaPtr && "No Sema?"); - Buffer->Signature = Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, - ShouldCacheASTInMemory); + Buffer->Signature = + Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, + // For serialization we are lenient if the errors were + // only warn-as-error kind. + PP.getDiagnostics().hasUncompilableErrorOccurred(), + ShouldCacheASTInMemory); Buffer->IsComplete = true; }