Skip to content

Commit a50e63b

Browse files
Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)
The issue #53952 is reported indicating clang is giving a crashing pch file, when hasErrors is been passed incorrectly to WriteAST method. To fix the issue, the parameter has been removed and instead we're relying on the results of `hasUncompilableErrorOccured()` instead of letting the caller override it. Fixes #53952
1 parent f320065 commit a50e63b

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ class ASTWriter : public ASTDeserializationListener,
613613
/// the module but currently is merely a random 32-bit number.
614614
ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
615615
Module *WritingModule, StringRef isysroot,
616-
bool hasErrors = false,
617616
bool ShouldCacheASTInMemory = false);
618617

619618
/// Emit a token.

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,12 +2341,9 @@ bool ASTUnit::Save(StringRef File) {
23412341
return false;
23422342
}
23432343

2344-
static bool serializeUnit(ASTWriter &Writer,
2345-
SmallVectorImpl<char> &Buffer,
2346-
Sema &S,
2347-
bool hasErrors,
2348-
raw_ostream &OS) {
2349-
Writer.WriteAST(S, std::string(), nullptr, "", hasErrors);
2344+
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
2345+
Sema &S, raw_ostream &OS) {
2346+
Writer.WriteAST(S, std::string(), nullptr, "");
23502347

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

23582355
bool ASTUnit::serialize(raw_ostream &OS) {
2359-
// For serialization we are lenient if the errors were only warn-as-error kind.
2360-
bool hasErrors = getDiagnostics().hasUncompilableErrorOccurred();
2361-
23622356
if (WriterData)
2363-
return serializeUnit(WriterData->Writer, WriterData->Buffer,
2364-
getSema(), hasErrors, OS);
2357+
return serializeUnit(WriterData->Writer, WriterData->Buffer, getSema(), OS);
23652358

23662359
SmallString<128> Buffer;
23672360
llvm::BitstreamWriter Stream(Buffer);
23682361
InMemoryModuleCache ModuleCache;
23692362
ASTWriter Writer(Stream, Buffer, ModuleCache, {});
2370-
return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS);
2363+
return serializeUnit(Writer, Buffer, getSema(), OS);
23712364
}
23722365

23732366
using SLocRemap = ContinuousRangeMap<unsigned, int, 2>;

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4622,12 +4622,12 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const {
46224622

46234623
ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile,
46244624
Module *WritingModule, StringRef isysroot,
4625-
bool hasErrors,
46264625
bool ShouldCacheASTInMemory) {
46274626
llvm::TimeTraceScope scope("WriteAST", OutputFile);
46284627
WritingAST = true;
46294628

4630-
ASTHasCompilerErrors = hasErrors;
4629+
ASTHasCompilerErrors =
4630+
SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred();
46314631

46324632
// Emit the file header.
46334633
Stream.Emit((unsigned)'C', 8);

clang/lib/Serialization/GeneratePCH.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,8 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
6565

6666
// Emit the PCH file to the Buffer.
6767
assert(SemaPtr && "No Sema?");
68-
Buffer->Signature =
69-
Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot,
70-
// For serialization we are lenient if the errors were
71-
// only warn-as-error kind.
72-
PP.getDiagnostics().hasUncompilableErrorOccurred(),
73-
ShouldCacheASTInMemory);
68+
Buffer->Signature = Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot,
69+
ShouldCacheASTInMemory);
7470

7571
Buffer->IsComplete = true;
7672
}

0 commit comments

Comments
 (0)