-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[Transforms] LowerSwitch tries to get sext on i128
, causing an assertion error.
#59316
Comments
@llvm/issue-subscribers-bug |
int64_t APInt::getSExtValue()
on i128
caused assertion error.i128
, causing an assertion error.
I think option 2 is the only viable solution. LowerSwitch is not part of the default set of codegen passes; only enabled for amdgcn? Otherwise, this bug would have been noticed sooner. |
Another potential option (but I have no idea if it's viable): just bail out on switches with oversized type. Presumably, the default switch lowering can handle those minimally (otherwise every target would be crashing). Since oversized switches were never expected to exist for targets that use this pass, it shouldn't be a real-world concern as long as we don't crash? |
I am not really comfortable with bail out solution. That doesn't fit into the expectation of this pass (unless we document it explictly), other people may use it in the future and expecting it to work on i128 when in fact we bail, that could be a bigger problem. I am happy to apply option 2 when I have time. |
I think there is another discussion here I would like to talk about. @RKSimon It seems to me Here's one idea: |
There might be uses for an alternative helper (getLegalSExtValue?) but the existing getSExtValue/getZExtValue methods are very widespread and make use of being implicitly inrange. |
Something else that has encouraged people to use getSExtValue/getZExtValue is because APInt values don't work well with other APInt values if their bitwidths aren't the same - IMO at least the non-equality comparisons shouldn't have that limit. |
I wonder what would 'getLegalSExtValue' return, an option like I mentioned? I think another idea is to roll out new, safe APIs and try to slowly deprecate the old ones, if this API is widely used. |
Currently, APInt::getSExtValue and getZExtValue crashes on values with more than 64 bits. Users may accidently crash the compiler with this setting when the integer may be i128. As shown in #59316 In this patch we provide a trySExtValue and tryZExtValue to return an Optional, the user needs to explictly unwrap it and condsier the possibility where there my no value in it. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D139683
Currently, APInt::getSExtValue and getZExtValue crashes on values with more than 64 bits. Users may accidently crash the compiler with this setting when the integer may be i128. As shown in llvm#59316 In this patch we provide a trySExtValue and tryZExtValue to return an Optional, the user needs to explictly unwrap it and condsier the possibility where there my no value in it. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D139683
Candidate patch: https://reviews.llvm.org/D140747 |
This rewrite fixes llvm/llvm-project#59316. Previously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits. Using APInt fixes this problem. This patch also includes a test Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D140747
This rewrite fixes #59316. Previously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits. Using APInt fixes this problem. This patch also includes a test Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D140747
This rewrite fixes llvm/llvm-project#59316. Previously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits. Using APInt fixes this problem. This patch also includes a test Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D140747
I wrote an issue |
Currently, APInt::getSExtValue and getZExtValue crashes on values with more than 64 bits. Users may accidently crash the compiler with this setting when the integer may be i128. As shown in llvm/llvm-project#59316 In this patch we provide a trySExtValue and tryZExtValue to return an Optional, the user needs to explictly unwrap it and condsier the possibility where there my no value in it. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D139683
This rewrite fixes llvm/llvm-project#59316. Previously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits. Using APInt fixes this problem. This patch also includes a test Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D140747
This rewrite fixes llvm/llvm-project#59316. Previously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits. Using APInt fixes this problem. This patch also includes a test Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D140747
In
LowerSwitch
, we are assuming treating switch cases is smaller than int64 by directly asking for asext
value.However, this can go wrong if the case value is higher typed huge number.
For example, https://godbolt.org/z/f8cMnKnGE shows a case where we use
i128
and crashes the compiler.llvm-project/llvm/lib/Transforms/Utils/LowerSwitch.cpp
Line 331 in 7cf5581
Here is a stack trace:
I see two ways to fix it:
int64_t
and will be treated as signed integer.APInt
API.The text was updated successfully, but these errors were encountered: