Skip to content

Commit a6acf3f

Browse files
Revert "Fixes and closes llvm#53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (llvm#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
1 parent 964a252 commit a6acf3f

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

clang/include/clang/Serialization/ASTWriter.h

+1
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ 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,
616617
bool ShouldCacheASTInMemory = false);
617618

618619
/// Emit a token.

clang/lib/Frontend/ASTUnit.cpp

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

2344-
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
2345-
Sema &S, raw_ostream &OS) {
2346-
Writer.WriteAST(S, std::string(), nullptr, "");
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);
23472350

23482351
// Write the generated bitstream to "Out".
23492352
if (!Buffer.empty())
@@ -2353,14 +2356,18 @@ static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
23532356
}
23542357

23552358
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+
23562362
if (WriterData)
2357-
return serializeUnit(WriterData->Writer, WriterData->Buffer, getSema(), OS);
2363+
return serializeUnit(WriterData->Writer, WriterData->Buffer,
2364+
getSema(), hasErrors, OS);
23582365

23592366
SmallString<128> Buffer;
23602367
llvm::BitstreamWriter Stream(Buffer);
23612368
InMemoryModuleCache ModuleCache;
23622369
ASTWriter Writer(Stream, Buffer, ModuleCache, {});
2363-
return serializeUnit(Writer, Buffer, getSema(), OS);
2370+
return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS);
23642371
}
23652372

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

clang/lib/Serialization/ASTWriter.cpp

+2-2
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,
46254626
bool ShouldCacheASTInMemory) {
46264627
llvm::TimeTraceScope scope("WriteAST", OutputFile);
46274628
WritingAST = true;
46284629

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

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

clang/lib/Serialization/GeneratePCH.cpp

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

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

7175
Buffer->IsComplete = true;
7276
}

0 commit comments

Comments
 (0)