-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
"distinct uint64" type corruption on 32-bit, when using {.borrow.} operators #13902
Comments
It seems to only apply to borrowed operators with var params. This one works: proc `+`*(x: Slot, y: uint64): Slot {.borrow.} |
This used to work in 1.0.6 and appeared in 1.2.0 |
Regression introduced by this commit: 19cab9f Paging @timotheecour. What looks suspicious in there is that a new "frameMsgLen" field is added unconditionally to Adding I thought adding the missing struct field to this anonymous struct copy of Line 622 in 19cab9f
I'm out of ideas for what could cause a wrong length assumption for that struct. |
I don't think that's the problem. Your problem lies in the C code: nimln_(9, "/tmp/test.nim"); if (nimAddInt(s__1PREurDxZ5w0Xbv7yMs9aWw, 1ULL, &TM__ipcYmBC9bj9a1BW35ABoB1Kw_3)) { raiseOverflow(); }; s__1PREurDxZ5w0Xbv7yMs9aWw = (NU64)(TM__ipcYmBC9bj9a1BW35ABoB1Kw_3); This code is used to add integers, and on 32bit systems, they'll be treated as 32bit ints. That's where the corruption came from. This regression was introduced and/or surfaced by @Araq's #13626. |
I used |
i will look into it in a bit, today |
Guess I catched another regression: distinct uints still have their bounds checked. |
I believe you've used git bisect incorrectly :-) /cc @Araq (and also verified manually right before and right after this commit) btw, maybe it's time to look more closely into the other comments that have been marked as resolved but IMO are still valid on that PR (even if some of these refer to pre-existing issues) These concern bound checking codegen issues and potential double evaluation bugs/performance bugs, eg #13626 (comment) amongst others |
Doubt it. I started from 6e0c06f mentioned by leorize as working, on IRC, then manually verified the result by checking out 8088633 which works and 19cab9f which fails. It may be possible that the problem appeared and disappeared as the stack changed in unrelated places, but keep in mind that it's solved by removing "frameMsgLen" from |
I found the bug and am fixing it in #13907 (just a 1 line change, plus a test). note that it also fixes a (related) cpp codegen compilation error |
I have said it elsewhere, "git bisect" can have false positives and other ways for bug hunting are much more effective. Like, I dunno, trying to understand what's actually going on. |
It's about reducing the search space. it's trivial to write a nim wrapper on top of |
) [backport:1.2] * fix #13902 distinct uint64 type corruption on 32-bit with borrow Co-authored-by: Timothee Cour <[email protected]>
) [backport:1.2] * fix #13902 distinct uint64 type corruption on 32-bit with borrow Co-authored-by: Timothee Cour <[email protected]> (cherry picked from commit 95fd8ae)
The problem only appears when borrowed operators for a "distinct uint64" type force a type inference.
Example
Compiling and running a 32-bit binary on a 64-bit Linux system:
nim c -r --cpu:i386 --passC:"-m32" --passL:-m32 uint64.nim
Current Output
Expected Output
Additional Information
Found when porting nim-beacon-chain to Nim-1.2.0: status-im/nimbus-eth2#829
The text was updated successfully, but these errors were encountered: