Skip to content

Commit

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

This reverts commit a6acf3f and
relands a50e63b. The original revert
was done by mistake.
  • Loading branch information
AaronBallman committed Oct 6, 2023
1 parent ff48816 commit 46518a1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
1 change: 0 additions & 1 deletion clang/include/clang/Serialization/ASTWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ 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: 5 additions & 12 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2341,12 +2341,9 @@ bool ASTUnit::Save(StringRef File) {
return false;
}

static bool serializeUnit(ASTWriter &Writer,
SmallVectorImpl<char> &Buffer,
Sema &S,
bool hasErrors,
raw_ostream &OS) {
Writer.WriteAST(S, std::string(), nullptr, "", hasErrors);
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
Sema &S, raw_ostream &OS) {
Writer.WriteAST(S, std::string(), nullptr, "");

// Write the generated bitstream to "Out".
if (!Buffer.empty())
Expand All @@ -2356,18 +2353,14 @@ static bool serializeUnit(ASTWriter &Writer,
}

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(), hasErrors, OS);
return serializeUnit(WriterData->Writer, WriterData->Buffer, getSema(), OS);

SmallString<128> Buffer;
llvm::BitstreamWriter Stream(Buffer);
InMemoryModuleCache ModuleCache;
ASTWriter Writer(Stream, Buffer, ModuleCache, {});
return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS);
return serializeUnit(Writer, Buffer, getSema(), 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 = hasErrors;
ASTHasCompilerErrors =
SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred();

// Emit the file header.
Stream.Emit((unsigned)'C', 8);
Expand Down
8 changes: 2 additions & 6 deletions clang/lib/Serialization/GeneratePCH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {

// Emit the PCH file to the Buffer.
assert(SemaPtr && "No Sema?");
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->Signature = Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot,
ShouldCacheASTInMemory);

Buffer->IsComplete = true;
}
Expand Down

0 comments on commit 46518a1

Please sign in to comment.