Skip to content
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

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

rajkumarananthu
Copy link
Contributor

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.

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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels Oct 3, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2023

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Changes

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.


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

1 Files Affected:

  • (modified) clang/lib/Serialization/ASTWriter.cpp (+6)
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);

@rajkumarananthu rajkumarananthu changed the title Fixes and closes #53952 Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. Oct 3, 2023
@github-actions
Copy link

github-actions bot commented Oct 3, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@shafik shafik requested review from ChuanqiXu9 and zygoloid October 4, 2023 00:46
Copy link
Collaborator

@shafik shafik left a 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.

clang/lib/Serialization/ASTWriter.cpp Outdated Show resolved Hide resolved
@rajkumarananthu rajkumarananthu requested a review from shafik October 4, 2023 03:19
Copy link
Collaborator

@AaronBallman AaronBallman left a 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.

@AaronBallman AaronBallman merged commit a50e63b into llvm:main Oct 5, 2023
kazutakahirata added a commit that referenced this pull request Oct 5, 2023
…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
@rajkumarananthu
Copy link
Contributor Author

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
Rajkumar Ananthu

@phyBrackets
Copy link
Member

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.

AaronBallman added a commit that referenced this pull request Oct 6, 2023
…rors member variable correctly based on the PP diagnostics. (#68127)""

This reverts commit a6acf3f and
relands a50e63b. The original revert
was done by mistake.
@AaronBallman
Copy link
Collaborator

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,.

@rajkumarananthu
Copy link
Contributor Author

Thanks for taking care of this @AaronBallman

@rajkumarananthu rajkumarananthu deleted the issue_53952 branch October 6, 2023 14:06
@kazutakahirata
Copy link
Contributor

Thank you @AaronBallman!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants