ptitSeb opened issue #5653:
Thanks for filing a feature request! Please fill out the TODOs below.
Feature
With 0.90 of Cranelift,
InsBuilder::trap_if(...)was removed, and replaced withInsbuild::trapnz(...)andInsBuilder::trapz(...), but thetrap_if(...)allowed for more case than just Equal and Different (like for exampleUnsignedGreaterThanOrEqual).Benefit
Easy
OutOfBoundtrap for exampleImplementation
Add more
trapXX(...)liketrapnz(..)/trapz(..)Alternatives
Manual jmp over / unconditional trap, but that's a bit cumbersome.
cfallin commented on issue #5653:
You should be able to do a
trapnzon anicmpresult with any comparison op, I think?
ptitSeb commented on issue #5653:
so, an
icmpto get a value, than a test on that value to finaly do a trapz() or trapnz()? That's a solution, but still lot more complex then previoustrap_if
bjorn3 commented on issue #5653:
You can do
icmpwith the IntCC for the condition in which you want to trap and then directly pass the result oficmptotrapnz. For exampletrap_if uge v0, v1would turn into
v2 = icmp uge v0, v1 trapnz v2
jameysharp commented on issue #5653:
I believe the intent was that for
UnsignedGreaterThanOrEqualyou'd useicmplike this:v2 = icmp uge v0, v1 trapnz v2, user0There are some special cases which might help, like the
uadd_overflow_trapinstruction, or using the carry output ofiadd_coutas the input totrapnz.Do those options cover your needs?
ptitSeb commented on issue #5653:
Ok, thanks. the icmp / trapnz is good enough. I'll check the
uadd_overflow_traptoo also.
ptitSeb commented on issue #5653:
I guess I can close the ticket as my understanding of
trapz/trapnzwas eronuous: it doesn't take a CFlag but a Value (and so it's not a direct replacement totrap_if)
jameysharp commented on issue #5653:
Right,
trapifwas removed as part of our effort to remove integer/floating-point CPU flags from CLIF. So yeah, I'll go ahead and close this. Thanks for asking the question though—it's always good to hear from folks who are using Cranelift!
jameysharp closed issue #5653:
Thanks for filing a feature request! Please fill out the TODOs below.
Feature
With 0.90 of Cranelift,
InsBuilder::trap_if(...)was removed, and replaced withInsbuild::trapnz(...)andInsBuilder::trapz(...), but thetrap_if(...)allowed for more case than just Equal and Different (like for exampleUnsignedGreaterThanOrEqual).Benefit
Easy
OutOfBoundtrap for exampleImplementation
Add more
trapXX(...)liketrapnz(..)/trapz(..)Alternatives
Manual jmp over / unconditional trap, but that's a bit cumbersome.
Last updated: Dec 06 2025 at 06:05 UTC