https://github.com/rajkumarananthu created 
https://github.com/llvm/llvm-project/pull/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, 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.

>From b76f4d351b3e55e2095e3be088a50fdb76d6b7f9 Mon Sep 17 00:00:00 2001
From: Rajkumar Ananthu <rajkumar.ananthu...@gmail.com>
Date: Tue, 3 Oct 2023 21:53:59 +0530
Subject: [PATCH] Fixes and closes #53952

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, 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.
---
 clang/lib/Serialization/ASTWriter.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 201e2fcaaec91aa..35f37de9b1850ad 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -4628,6 +4628,12 @@ ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, 
StringRef OutputFile,
   WritingAST = true;
 
   ASTHasCompilerErrors = hasErrors;
+  bool trueHasErrors = 
SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred();
+  assert(ASTHasCompilerErrors == trueHasErrors);
+  if (trueHasErrors != ASTHasCompilerErrors) {
+      // forcing the compiler errors flag to be set correctly
+      ASTHasCompilerErrors = trueHasErrors;
+  }
 
   // Emit the file header.
   Stream.Emit((unsigned)'C', 8);

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to