Skip to content

Commit

Permalink
Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors mem…
Browse files Browse the repository at this point in the history
…ber variable correctly based on the PP diagnostics. (#68127)"

This reverts commit a50e63b.

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
  • Loading branch information
kazutakahirata committed Oct 5, 2023
1 parent 964a252 commit a6acf3f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Serialization/ASTWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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>;
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions clang/lib/Serialization/GeneratePCH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a6acf3f

Please sign in to comment.