Generated foreach-body functions: Fix index when NOT using size_t#21705
Generated foreach-body functions: Fix index when NOT using size_t#21705dlang-bot merged 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @kinke! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
51cc35d to
14b9f46
Compare
ba8df90 to
fb38d82
Compare
Similar to issue dlang#21456, the druntime autodecoding helpers pass a pointer to the `size_t` array index. The generated foreach-body lambda used to load its index from that pointer, without verifying that the types match. So if the user uses an `int` index, it used to load the first 4 bytes, thus truncating to 32 bits on little-endian, but using the 32 upper bits for 64-bit big-endian targets. Solve this by adding a cast if needed.
fb38d82 to
86a877d
Compare
|
FYI @ibuclaw - I assume you've had to work around this somewhere too, to fix this for big-endian targets. |
A cherry-pick of dlang/dmd#21705.
Probably, PPCBE for example is not really given much love nowadays. Though I don't think the sparc-solaris port has raised this - I can give it a try on one of the port boxes to check the current behaviour. As this is a patch from 2013, have you tried runtime without this? |
|
At first I thought/hoped the old fix is superfluous by now, but I've checked the LLVM IR and seen that this is still a problem - the druntime helpers passing a pointer to a |
|
Running bootstrap on sparcv9-sun-solaris2.11, will test gdc-11 (last C++) and gdc-15. |
|
Yep, both exhibit runtime failure, I do see: So that's probably why no one's hit it on that target, library is built with |
Similar to issue #21456, the druntime autodecoding helpers pass a pointer to the
size_tarray index. The generated foreach-body lambda used to load its index from that pointer, without verifying that the types match. So if the user uses anintindex, it used to load the first 4 bytes, thus truncating to 32 bits on little-endian, but using the 32 upper bits for 64-bit big-endian targets. Solve this by adding a cast if needed.