Skip to content

Conversation

@kkysen
Copy link
Contributor

@kkysen kkysen commented Oct 28, 2025

A test for #1435. It was broken by #1266 (specifically, 7eaa39f, which also doesn't compile). It seems we're not handling the U suffix, which requires a temporary cast to c_uint before getting coerced to int32_t/i32.

4a4c0cc is the current snapshot, while 36d829e is what it was before #1266, which still compiles.

@kkysen kkysen force-pushed the kkysen/out-of-range-int branch from 36d829e to d1799d6 Compare October 28, 2025 05:49
@fw-immunant
Copy link
Contributor

Ah, my bad re: 7eaa39f not compiling--it depends on 67e6eeb but got reordered prior to it during cleanup of that PR.

I believe the problem here is referenced by the doc comment for literal_kind_matches_ty:

Return whether the literal can be directly translated as this type. This does not check that the literal fits into the type's range of values (as doing so is in general dependent on the target platform), just that it is the appropriate kind for the type.

For fixed-size types like int32_t, we can relatively easily check the literal against their fixed bounds, but for types like libc::c_int we need to be able to determine the bounds for int on the target platform.

Copy link
Contributor Author

@kkysen kkysen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for types like libc::c_int we need to be able to determine the bounds for int on the target platform.

See #1442 now, but I chose to use the narrowest bound for platform-dependent types like int so that the resulting code works on all platforms.

@kkysen
Copy link
Contributor Author

kkysen commented Nov 1, 2025

@kkysen kkysen closed this Nov 1, 2025
@kkysen kkysen deleted the kkysen/out-of-range-int branch November 1, 2025 08:13
kkysen added a commit that referenced this pull request Nov 24, 2025
* Fixes #1435.
* Supersedes #1436.

This first reverts the part of 7eaa39f that broke #1435, which is
omitting casts from literals where the type already matches without
checking if the literal is within that type's range. Then tests are
added and then `fn literal_kind_matches_ty` is fixed to also check the
type's range. If the literal may be out of range on any possible
platform, then a cast remains.

I didn't add a float to these tests since floats go through a different
code path (there's no cast generated for them). So for them, we need to
explicitly generate a cast if it's out of range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants