[clang] a6acf3f - Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)"
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 5 13:18:06 PDT 2023
On Thu, Oct 5, 2023 at 4:08 PM Kazu Hirata via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
>
>
> Author: Kazu Hirata
> Date: 2023-10-05T13:08:24-07:00
> New Revision: a6acf3fd49a20c570a390af2a3c84e10b9545b68
>
> URL: https://github.com/llvm/llvm-project/commit/a6acf3fd49a20c570a390af2a3c84e10b9545b68
> DIFF: https://github.com/llvm/llvm-project/commit/a6acf3fd49a20c570a390af2a3c84e10b9545b68.diff
>
> LOG: 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
That's expected; we removed a parameter that appeared to be unused and
was causing problems. Is lld using the parameter that was removed? If
so, what was the intent of overriding the diagnostics engine?
~Aaron
>
> Added:
>
>
> Modified:
> clang/include/clang/Serialization/ASTWriter.h
> clang/lib/Frontend/ASTUnit.cpp
> clang/lib/Serialization/ASTWriter.cpp
> clang/lib/Serialization/GeneratePCH.cpp
>
> Removed:
>
>
>
> ################################################################################
> diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h
> index 98445d40ebd82c3..f2c7c03ff093607 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 85157c3b21b6648..016f88a43a56ddd 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<char> &Buffer,
> - Sema &S, raw_ostream &OS) {
> - Writer.WriteAST(S, std::string(), nullptr, "");
> +static bool serializeUnit(ASTWriter &Writer,
> + SmallVectorImpl<char> &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<char> &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<unsigned, int, 2>;
>
> diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
> index 0acd86de06ba404..201e2fcaaec91aa 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 cf8084333811f13..601a24b4aec46ad 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;
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list