Skip to content

Commit b76f4d3

Browse files
Fixes and closes llvm#53952
The issue llvm#53952 is reported indicating clang is giving a crashing pch file, when hasErrors is been passed incorrectly to WriteAST method. To fix the issue, I have a added an assertion to make sure the given value of ASTHasCompilerErrors is matching with Preprocessor diagnostics. And this assertion will get triggered inside Debug builds. For release builds, based on the conditional check, forcefully set the ASTHasCompilerErrors member variable to a valid value from Preprocessor.
1 parent c3b01b4 commit b76f4d3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4628,6 +4628,12 @@ ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile,
46284628
WritingAST = true;
46294629

46304630
ASTHasCompilerErrors = hasErrors;
4631+
bool trueHasErrors = SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred();
4632+
assert(ASTHasCompilerErrors == trueHasErrors);
4633+
if (trueHasErrors != ASTHasCompilerErrors) {
4634+
// forcing the compiler errors flag to be set correctly
4635+
ASTHasCompilerErrors = trueHasErrors;
4636+
}
46314637

46324638
// Emit the file header.
46334639
Stream.Emit((unsigned)'C', 8);

0 commit comments

Comments
 (0)