-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. #68127
Conversation
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.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-modules ChangesThe 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. Full diff: https://github.com/llvm/llvm-project/pull/68127.diff 1 Files Affected:
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);
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix does not look correct but perhaps someone else will have more insight.
…ted by the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix, the changes LGTM! The precommit CI failure appears to be unrelated to these changes. I don't think this requires test coverage or a release note.
…ber variable correctly based on the PP diagnostics. (#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
Hi @AaronBallman I could see a revert of my change here: https://reviews.llvm.org/rGa6acf3fd49a20c570a390af2a3c84e10b9545b68 Can you please help me confirm whether the change is accepted or reverted. Should we resubmit the changes here? Thanks |
Not sure but the issue in the reverted commit seems like a backporting issue, so you may need to backport the changes in case. But I'd say wait for Aaron comment. |
There was a mix-up. I landed the original changes, @kazutakahirata saw what appeared to be a linker error after pulling those changes down and did a revert, but that turned out to be an issue local to their machine so I've reverted the revert (re-landing the original changes). So the code should be in now and should hopefully stay in,. |
Thanks for taking care of this @AaronBallman |
Thank you @AaronBallman! |
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.