-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[AsmWriter] Combine IsConstant and GetConstant (NFCI) #129288
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
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-llvm-ir Author: JP Hafer (jph-13) ChangesThe assert in GetConstant checks if Bound is constant. However, GetConstant is only called when IsConstant==true. Full diff: https://github.com/llvm/llvm-project/pull/129288.diff 1 Files Affected:
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index a52c4d88ac836..306186d200e26 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2117,7 +2117,6 @@ static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N,
};
auto GetConstant = [&](Metadata *Bound) -> int64_t {
- assert(IsConstant(Bound) && "Expected constant");
auto *BE = dyn_cast_or_null<DIExpression>(Bound);
return static_cast<int64_t>(BE->getElement(1));
};
|
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 assert in GetConstant checks if Bound is constant. However, GetConstant is only called when IsConstant==true.
Yes -- and the assert ensures that GetConstant is only used in cases where it is valid.
I think if you want to change this code, the better change would be to drop IsConstant and instead have GetConstant return an std::optional. Then you don't need separate IsConstant and GetConstant calls.
1e08ffe
to
6cdb4d4
Compare
Reverted the abort deletion and implented the solution @nikic recommend. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
6cdb4d4
to
1f9d563
Compare
Addressed code format violations. |
1f9d563
to
a4c0192
Compare
Can you rewrite the PR title/description? I don't think it matches what this changes does anymore. |
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.
This looks like a reasonable refactor to me.
Nit on the PR title, I'd go for something shorter and leave the why in the description. Maybe:
[AsmWriter] Combine IsConstant and GetConstant (NFCI)
-- which also says where the change is (AsmWriter
) and that no functional changes are intended (NFCI).
@jph-13 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
There was an assert in GetConstant checked if Bound is constant. However, GetConstant was only called when IsConstant==true. This refactor attempts to get rid of the assert by combining GetConstant and IsContstant.
There was an assert in GetConstant checked if Bound is constant. However, GetConstant was only called when IsConstant==true.
This refactor attempts to get rid of the assert by combining GetConstant and IsContstant.