-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Cranelift: IR Reference example triggers debug assert on x86_64 #10118
Comments
In this snippet
you are loading from memory at address (The comments aren't load-bearing for the bug but I note too that you wrote "Converts ... to f32 from i32" which is inconsistent with a load -- usually I would reach for an int-to-float opcode to convert in the usual sense.) Our assertion failure message could absolutely be better here -- perhaps we could add "address with unexpected" or something like that. I'll note as well that the example IR you took from Hopefully this is a simple fix (use i64 types for addresses) -- let us know if that addresses your problem! |
@cfallin , thank you for the detailed answer.
Ah, I didn't think of that, but that does make sense! I can indeed get the example from the documentation to work by changing
Yeah, I think just something simple as changing that debug assert to be; debug_assert_eq!(ctx.output_ty(add, 0), types::I64, "address width of 64 expected, got 32"); would go a long way towards steering people in the right direction? I can file a pr with this change if you'd like me to. The discrepancy between debug and release builds is also a bit surprising to me, but that may be less of an easy fix as it probably requires adding an explicit check. |
Yes, if you're willing, a PR to make both of those changes would be very much appreciated! Happy to review. Thanks! |
Does the clif ir verifier catch this mistake? You need to explicitly enable it as it is kinda slow. |
I tried adding the same My exact setup is available in 70af5ce on (branch issue-10118-reproduction), it adds a crate
Which I take to mean the verifier is enabled, the documentation here also states it is enabled by default? Reproduction should be a matter of going to the crate and doing Context; I'm considering creating a toy compiler, just to learn more about compilers. On Sunday I was exploring Cranelift to see how approachable it is and whether I'd like to use it as the frontend and share datastructures (effectively I think I would attempt making a
Cool, I'll put something together. |
…e#10118) This adds additional information as to what is wrong when this assert is encountered.
…lliance#10118) Most people using this example will likely be on 64 bit systems, so it makes sense to target a system with 64 bit addressses with the example.
* Cranelift/x64 backend: improve pointer width assert. (#10118) This adds additional information as to what is wrong when this assert is encountered. * Cranelift/docs: Change pointer width in ir docs to 64 bits (#10118) Most people using this example will likely be on 64 bit systems, so it makes sense to target a system with 64 bit addressses with the example.
.clif
Test CaseThe Cranelift IR
average
example code from the docs/ir.md. I've already added that to the filetests test directory in caeafe2.Using
clif-util
;Manually, I reduced it to the following:
Instructions themselves seem fine to me, but today is the first day I'm looking at Cranelift at all, so I absolutely may be missing something obvious.
Steps to Reproduce
cd cranelift
cargo t
(note without--release
, test will pass with--release
).Note, the problem is with
x86_64
, this function compiles fine withaarch64
.Expected Results
I would expect the example function provided in the documentation to compile, it compiles on
aarch64
, which (to me at least) indicates the function is fine. I would expect this to also compile onx86_64
.Actual Results
A debug assert triggers on this line;
Backtrace
The relevant section from
isle_x64.rs
;Which seems to indicate the problem is originating from
Fpromote
.Versions and Environment
Cranelift version or commit: Current released;
0.116.1
, also tested on current main; 5dfccc0.Operating system: Ubuntu, stable rustc 1.84.0 (9fc6b4312 2025-01-07)
Architecture: x86_64
Extra Info
If I use a release build, target x86_64 and write the output to an object file using
cranelift_object::ObjectModule
. The provided symbol does work and correctly calculates averages.Disassembly of object and usage of it to calculate average
The text was updated successfully, but these errors were encountered: