[clang] Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (PR #68127)

Rajkumar Ananthu via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 3 19:50:28 PDT 2023


================
@@ -4628,6 +4628,12 @@ ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile,
   WritingAST = true;
 
   ASTHasCompilerErrors = hasErrors;
+  bool trueHasErrors = SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred();
----------------
rajkumarananthu wrote:

Hi @shafik, thanks for your time for the review.

The scenario here is that, at line 4630 you can see the `ASTHasCompilerErrors` is being set using `hasErrors` which is an input to the method here `ASTWriter::WriteAST()`.

And if you see the description of the issue reported, the user is purposely passing the `hasErrors` as `false` even when there is a compiler error in the input file, because of this clang is giving a crashing pch file.

So, if the `hasErrors` is not a valid value, I am setting it to the correct value. May be I can just remove all the unnecessary code and just directly assign `ASTHasCompilerErrors = SemaRef.PP.getDiagnostics().hasUncompilableErrorOccured();` which will be correct.

And assertion I have added to detect this in debug build early, may be I am wrong, sorry for the confusion, it should not behave differently in release and debug builds.

Let me know what you think of this?

Thanks
Rajkumar Ananthu.

https://github.com/llvm/llvm-project/pull/68127


More information about the cfe-commits mailing list