Skip to content

Separate Primitive::Bool and make #[repr($int)] enums always use the ABI of $int - #165481

Draft
asquared31415 wants to merge 4 commits into
rust-lang:mainfrom
asquared31415:enum-int-repr
Draft

asquared31415 wants to merge 4 commits into
rust-lang:mainfrom
asquared31415:enum-int-repr

Conversation

@asquared31415

Copy link
Copy Markdown
Contributor

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 5, 2026
@rust-log-analyzer

This comment has been minimized.

@mu001999

mu001999 commented Nov 5, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 5, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 5, 2026
Separate `Primitive::Bool` and make `#[repr($int)]` enums always use the ABI of $int
@rust-log-analyzer

This comment has been minimized.

@asquared31415

Copy link
Copy Markdown
Contributor Author

oops i was so focused on making sure all the llvm-codegen tests passed that i appear to have forgotten to run the normal ui tests 😅

@rust-bors

rust-bors Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 309247f (309247f2d061081730fed50fb52ae20610509cc8)
Base parent: 2d20b42 (2d20b42b883dcfc014f3c2c56081eeb6091c2179)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (309247f): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary 3.2%, secondary 0.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.2% [2.1%, 3.8%] 3
Regressions ❌
(secondary)
2.5% [2.1%, 3.2%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.7% [-5.3%, -2.5%] 3
All ❌✅ (primary) 3.2% [2.1%, 3.8%] 3

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 480.462s -> 480.743s (0.06%)
Artifact size: 406.22 MiB -> 406.31 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 5, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Nov 6, 2026

@asquared31415 asquared31415 Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file is one of two meaningful test changes, the rest are debug layouts changing as expected.

This function and the corresponding function converting the other way are "regressed" in that now there will be an explicit trunc or zext. They were testing for the bad behavior (a repr(u8) that's actually a i1).

The trunc/ext should go away at the assembly level though.

View changes since the review

@asquared31415 asquared31415 Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file is the second meaningful test change.

The changes here are scary because I'm not quite sure of the requirements, but I asked on zulip for a second opinion.

I believe this is a correct change, with LLVM using more knowledge about the enum tag to generate a different instruction.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [codegen] tests/codegen-llvm/enum/enum-repr-abi.rs stdout ----
------FileCheck stdout------------------------------

------FileCheck stderr------------------------------
/checkout/tests/codegen-llvm/enum/enum-repr-abi.rs:59:11: error: CHECK: expected string not found in input
// CHECK: noundef range(i8 0, 2) i8 @enum_u8(i8 noundef range(i8 0, 2) %value)
          ^
/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/enum/enum-repr-abi/enum-repr-abi.ll:9:15: note: scanning from here
 ret i1 %value
              ^
/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/enum/enum-repr-abi/enum-repr-abi.ll:13:24: note: possible intended match here
define noundef zeroext range(i8 0, 2) i8 @enum_u8(i8 noundef zeroext range(i8 0, 2) %value) unnamed_addr #0 !guid !3 {
                       ^

Input file: /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/enum/enum-repr-abi/enum-repr-abi.ll
Check file: /checkout/tests/codegen-llvm/enum/enum-repr-abi.rs

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: ; ModuleID = 'enum_repr_abi.805d2cd8bf27c368-cgu.0' 
            2: source_filename = "enum_repr_abi.805d2cd8bf27c368-cgu.0" 
            3: target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20" 
            4: target triple = "wasm32-unknown-wasip3" 
            5:  
            6: ; Function Attrs: nounwind 
            7: define noundef zeroext i1 @enum_no_repr(i1 noundef zeroext %value) unnamed_addr #0 !guid !2 { 
            8: start: 
            9:  ret i1 %value 
check:59'0                  {   search range start (exclusive)
check:59'1                      error: no match found in search range
           10: } 
           11:  
           12: ; Function Attrs: nounwind 
           13: define noundef zeroext range(i8 0, 2) i8 @enum_u8(i8 noundef zeroext range(i8 0, 2) %value) unnamed_addr #0 !guid !3 { 
check:59'2                            ?                                                                                                 possible intended match
           14: start: 
           15:  ret i8 %value 
           16: } 
           17:  
           18: ; Function Attrs: nounwind 
           19: define noundef signext range(i8 0, 2) i8 @enum_i8(i8 noundef signext range(i8 0, 2) %value) unnamed_addr #0 !guid !4 { 
           20: start: 
           21:  ret i8 %value 
           22: } 
           23:  
           24: ; Function Attrs: nounwind 
           25: define noundef zeroext range(i16 0, 2) i16 @enum_u16(i16 noundef zeroext range(i16 0, 2) %value) unnamed_addr #0 !guid !5 { 
           26: start: 
           27:  ret i16 %value 
           28: } 
           29:  
           30: ; Function Attrs: nounwind 
           31: define noundef range(i32 0, 2) i32 @enum_i32(i32 noundef range(i32 0, 2) %value) unnamed_addr #0 !guid !6 { 
           32: start: 
           33:  ret i32 %value 
           34: } 
           35:  
           36: ; Function Attrs: nounwind 
           37: define noundef range(i64 0, 2) i64 @enum_i64(i64 noundef range(i64 0, 2) %value) unnamed_addr #0 !guid !7 { 
           38: start: 
           39:  ret i64 %value 
           40: } 
           41:  
           42: ; Function Attrs: nounwind 
           43: define void @enum_i128(ptr dead_on_unwind noalias nofree noundef writable sret([16 x i8]) align 16 captures(address) dereferenceable(16) %_0, i128 noundef range(i128 0, 2) %value) unnamed_addr #0 !guid !8 { 
           44: start: 
           45:  store i128 %value, ptr %_0, align 16 
           46:  ret void 
           47: } 
           48:  
           49: attributes #0 = { nounwind "target-cpu"="generic" } 
           50:  
           51: !llvm.module.flags = !{!0} 
           52: !llvm.ident = !{!1} 
           53:  
           54: !0 = !{i32 8, !"PIC Level", i32 2} 
           55: !1 = !{!"rustc version 1.101.0-nightly (149d891a5 2026-11-06)"} 
           56: !2 = !{i64 7142372588826038960} 
           57: !3 = !{i64 3005522049426393808} 
           58: !4 = !{i64 2664889430888216799} 
           59: !5 = !{i64 1841753866274790916} 
           60: !6 = !{i64 4824165952668233680} 
           61: !7 = !{i64 -4639840408103175374} 
           62: !8 = !{i64 -8238863365276373355} 
check:59'3                                      } search range end (exclusive)
>>>>>>

------------------------------------------

error: verification with 'FileCheck' failed
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/enum/enum-repr-abi/enum-repr-abi.ll" "/checkout/tests/codegen-llvm/enum/enum-repr-abi.rs" "--check-prefix=CHECK" "--allow-unused-prefixes" "--dump-input-context" "100"
stdout: none
--- stderr -------------------------------
/checkout/tests/codegen-llvm/enum/enum-repr-abi.rs:59:11: error: CHECK: expected string not found in input
// CHECK: noundef range(i8 0, 2) i8 @enum_u8(i8 noundef range(i8 0, 2) %value)
          ^
/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/enum/enum-repr-abi/enum-repr-abi.ll:9:15: note: scanning from here
 ret i1 %value
              ^
/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/enum/enum-repr-abi/enum-repr-abi.ll:13:24: note: possible intended match here
define noundef zeroext range(i8 0, 2) i8 @enum_u8(i8 noundef zeroext range(i8 0, 2) %value) unnamed_addr #0 !guid !3 {
                       ^

Input file: /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/enum/enum-repr-abi/enum-repr-abi.ll
Check file: /checkout/tests/codegen-llvm/enum/enum-repr-abi.rs

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: ; ModuleID = 'enum_repr_abi.805d2cd8bf27c368-cgu.0' 
            2: source_filename = "enum_repr_abi.805d2cd8bf27c368-cgu.0" 
            3: target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20" 
            4: target triple = "wasm32-unknown-wasip3" 
            5:  
            6: ; Function Attrs: nounwind 
            7: define noundef zeroext i1 @enum_no_repr(i1 noundef zeroext %value) unnamed_addr #0 !guid !2 { 
            8: start: 
            9:  ret i1 %value 
check:59'0                  {   search range start (exclusive)
check:59'1                      error: no match found in search range
           10: } 
           11:  
           12: ; Function Attrs: nounwind 
           13: define noundef zeroext range(i8 0, 2) i8 @enum_u8(i8 noundef zeroext range(i8 0, 2) %value) unnamed_addr #0 !guid !3 { 
check:59'2                            ?                                                                                                 possible intended match
           14: start: 
           15:  ret i8 %value 
           16: } 
           17:  
           18: ; Function Attrs: nounwind 
           19: define noundef signext range(i8 0, 2) i8 @enum_i8(i8 noundef signext range(i8 0, 2) %value) unnamed_addr #0 !guid !4 { 
           20: start: 
           21:  ret i8 %value 
           22: } 
           23:  
           24: ; Function Attrs: nounwind 
           25: define noundef zeroext range(i16 0, 2) i16 @enum_u16(i16 noundef zeroext range(i16 0, 2) %value) unnamed_addr #0 !guid !5 { 
           26: start: 
           27:  ret i16 %value 
           28: } 
           29:  
           30: ; Function Attrs: nounwind 
           31: define noundef range(i32 0, 2) i32 @enum_i32(i32 noundef range(i32 0, 2) %value) unnamed_addr #0 !guid !6 { 
           32: start: 
           33:  ret i32 %value 
           34: } 
           35:  
           36: ; Function Attrs: nounwind 
           37: define noundef range(i64 0, 2) i64 @enum_i64(i64 noundef range(i64 0, 2) %value) unnamed_addr #0 !guid !7 { 
           38: start: 
           39:  ret i64 %value 
           40: } 
           41:  
           42: ; Function Attrs: nounwind 
           43: define void @enum_i128(ptr dead_on_unwind noalias nofree noundef writable sret([16 x i8]) align 16 captures(address) dereferenceable(16) %_0, i128 noundef range(i128 0, 2) %value) unnamed_addr #0 !guid !8 { 
           44: start: 
           45:  store i128 %value, ptr %_0, align 16 
           46:  ret void 
           47: } 
           48:  
           49: attributes #0 = { nounwind "target-cpu"="generic" } 
           50:  
           51: !llvm.module.flags = !{!0} 
           52: !llvm.ident = !{!1} 
           53:  
           54: !0 = !{i32 8, !"PIC Level", i32 2} 
           55: !1 = !{!"rustc version 1.101.0-nightly (149d891a5 2026-11-06)"} 
           56: !2 = !{i64 7142372588826038960} 
           57: !3 = !{i64 3005522049426393808} 
           58: !4 = !{i64 2664889430888216799} 
           59: !5 = !{i64 1841753866274790916} 
           60: !6 = !{i64 4824165952668233680} 
           61: !7 = !{i64 -4639840408103175374} 
           62: !8 = !{i64 -8238863365276373355} 
check:59'3                                      } search range end (exclusive)
>>>>>>
------------------------------------------

---- [codegen] tests/codegen-llvm/enum/enum-repr-abi.rs stdout end ----

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect / dubious LLVM-level ABI for two-variant #[repr(u8)] enums: lowered to i1

5 participants