- Notifications
You must be signed in to change notification settings - Fork 15.5k
[Clang] Fix crash on malformed std::partial_ordering static members #172001
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
base: main
Are you sure you want to change the base?
Conversation
| Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
| @llvm/pr-subscribers-clang Author: Pankaj (code-pankaj) ChangesAdd a null check for Previously, this caused a crash in both freestanding ( Full diff: https://github.com/llvm/llvm-project/pull/172001.diff 1 Files Affected:
diff --git a/clang/lib/AST/ComparisonCategories.cpp b/clang/lib/AST/ComparisonCategories.cpp index 1b9c938e2ace3..431d6f77bc0a0 100644 --- a/clang/lib/AST/ComparisonCategories.cpp +++ b/clang/lib/AST/ComparisonCategories.cpp @@ -49,7 +49,7 @@ bool ComparisonCategoryInfo::ValueInfo::hasValidIntValue() const { // Before we attempt to get the value of the first field, ensure that we // actually have one (and only one) field. const auto *Record = VD->getType()->getAsCXXRecordDecl(); - if (Record->getNumFields() != 1 || + if (!Record || Record->getNumFields() != 1 || !Record->field_begin()->getType()->isIntegralOrEnumerationType()) return false; |
|
| If AI was used to create PR, please disclose it. And to what extent it was used. Please mention the issue fixed by this patch in PR description. Please add tests. Please add a release note entry. |
| Yes, GitHub Copilot was used to suggest code changes and commit messages. Will let you guys know after writing the test case. |
This fixes a crash (segmentation fault) when the standard library implementation of comparison categories (like `std::partial_ordering`) is malformed. Specifically, if the static members (like `equivalent`) are defined as a primitive type (e.g., `int`) instead of the comparison category type itself, the compiler previously attempted to process them incorrectly, leading to a crash. This patch adds strict type checking in `ComparisonCategoryInfo::lookupValueInfo`. If the found static member does not match the record type, it is rejected safely, triggering a diagnostic error instead of a crash. Fixes llvm#170015
| @tbaederr @zwuis Thanks for the Review! I have updated the PR based on the feedback. I moved the fix to I have also added the test and the Release Note entry. Please let me know if anything else is needed! |
Co-authored-by: Timm Baeder <tbaeder@redhat.com>
This fixes a crash (segmentation fault) when the standard library implementation of comparison categories (like
std::partial_ordering) is malformed.Specifically, if the static members (like
equivalent) are defined as a primitive type (e.g.,int) instead of the comparison category type itself, the compiler previously attempted to process them incorrectly, leading to a crash.This adds strict type checking in
ComparisonCategoryInfo::lookupValueInfo. If the found static member does not match the record type, it is rejected safely, triggering a diagnostic error instead of a crash.Fixes #170015