gccrs: add repr_c_enums_larger_than_int lint - #4651
Open
lucasly-ba wants to merge 1 commit into
Open
Conversation
lucasly-ba
force-pushed
the
repr-c-enums-larger-than-int
branch
2 times, most recently
from
June 28, 2026 21:10
e144c27 to
d6cf7fd
Compare
philberty
requested changes
Jun 29, 2026
philberty
left a comment
Member
There was a problem hiding this comment.
Yeah i think we need to do const eval during type resolution of the enum disriminant variant
lucasly-ba
force-pushed
the
repr-c-enums-larger-than-int
branch
5 times, most recently
from
July 9, 2026 22:46
fe2558c to
795d6e9
Compare
Contributor
Author
P-E-P
reviewed
Jul 20, 2026
| return; | ||
|
|
||
| const int64_t c_int_min = -2147483648LL; | ||
| const int64_t c_uint_max = 4294967295LL; |
lucasly-ba
force-pushed
the
repr-c-enums-larger-than-int
branch
2 times, most recently
from
July 21, 2026 00:17
ef91dd8 to
b891dae
Compare
P-E-P
reviewed
Jul 23, 2026
| #include "options.h" | ||
| #include "rust-compile-base.h" | ||
| #include "rust-compile-context.h" | ||
| #include <cstdint> |
Member
There was a problem hiding this comment.
You cannot include a system header like this, you need rust-system.h
Warn on a `#[repr(C)]` enum whose discriminant fits into neither a C `int` nor a C `unsigned int`. Such an enum is non-portable: C only permits enums whose discriminants do not all fit into one of those two types since C23, and Rust interprets `repr(C)` discriminants as `isize`, so its size may not match the C one. The discriminant is const evaluated with query_compile_const_expr during type resolution, so any constant discriminant expression is handled. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (check_repr_c_enum_discriminants): New. (TypeCheckItem::visit): Check repr(C) enum discriminants. gcc/testsuite/ChangeLog: * rust/compile/repr-c-enums-larger-than-int_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
lucasly-ba
force-pushed
the
repr-c-enums-larger-than-int
branch
from
July 23, 2026 14:59
b891dae to
0cb6ec5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warn on a
#[repr(C)]enum whose discriminant fits into neither a Cintnor a Cunsigned int. Such an enum is non-portable: C only permits enums whose discriminants do not all fit into one of those two types since C23, and Rust interpretsrepr(C)discriminants asisize, so the size may not match the C one.