Skip to content

[only tests] Add tests for current read/write unaligned behaviour#158341

Closed
scottmcm wants to merge 2 commits into
rust-lang:mainfrom
scottmcm:unaligned-pinning
Closed

[only tests] Add tests for current read/write unaligned behaviour#158341
scottmcm wants to merge 2 commits into
rust-lang:mainfrom
scottmcm:unaligned-pinning

Conversation

@scottmcm

Copy link
Copy Markdown
Member

This adds some tests to record what we're currently doing for read_unaligned and write_unaligned.

I had part of this in #158202, but I'm going to close that in favour of a different approach (#158291 being the first part of that) so figured I'd check in tests showing current behaviour to help make the fix PRs clearer.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 24, 2026
@rustbot

rustbot commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the unaligned-pinning branch from 177fe9d to d6f80bf Compare June 24, 2026 05:00
@mejrs

mejrs commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

I'm not qualified to review this sort of stuff

r? @folkertdev perhaps?

@rustbot rustbot assigned folkertdev and unassigned mejrs Jun 24, 2026
@scottmcm scottmcm marked this pull request as draft June 25, 2026 05:06
@scottmcm

Copy link
Copy Markdown
Member Author

Moving to draft because it'll conflict with #158345

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 25, 2026
@scottmcm scottmcm force-pushed the unaligned-pinning branch from d6f80bf to 6308be0 Compare June 25, 2026 05:09
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 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/read_write_unaligned.rs stdout ----
------FileCheck stdout------------------------------

------FileCheck stderr------------------------------
/checkout/tests/codegen-llvm/read_write_unaligned.rs:27:17: error: CHECK-NEXT: is not on the line after the previous match
 // CHECK-NEXT: ret i16 [[TEMP]]
                ^
/checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll:19:2: note: 'next' match was here
 ret i16 %_2.sroa.0.0.copyload
 ^
/checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll:16:53: note: previous match ended here
 %_2.sroa.0.0.copyload = load i16, ptr %ptr, align 1
                                                    ^
/checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll:17:1: note: non-matching line after previous match is here
 %0 = icmp ne i16 %_2.sroa.0.0.copyload, 0
^

Input file: /checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll
Check file: /checkout/tests/codegen-llvm/read_write_unaligned.rs

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

Input was:
<<<<<<
         1: ; ModuleID = 'read_write_unaligned.e30f5481d8566fd2-cgu.0' 
         2: source_filename = "read_write_unaligned.e30f5481d8566fd2-cgu.0" 
         3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" 
         4: target triple = "aarch64-unknown-linux-gnu" 
         5:  
         6: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable 
         7: define noundef nonnull ptr @read_unaligned_ptr(ptr noundef readonly captures(none) %ptr) unnamed_addr #0 { 
         8: start: 
         9:  %_2.sroa.0.0.copyload = load ptr, ptr %ptr, align 1, !nonnull !4, !noundef !4 
        10:  ret ptr %_2.sroa.0.0.copyload 
        11: } 
        12:  
        13: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read, inaccessiblemem: write) uwtable 
        14: define noundef range(i16 1, 0) i16 @read_unaligned_i16(ptr noundef readonly captures(none) %ptr) unnamed_addr #1 { 
        15: start: 
        16:  %_2.sroa.0.0.copyload = load i16, ptr %ptr, align 1 
        17:  %0 = icmp ne i16 %_2.sroa.0.0.copyload, 0 
        18:  tail call void @llvm.assume(i1 %0) 
        19:  ret i16 %_2.sroa.0.0.copyload 
next:27      !~~~~~~~~~~~~~~~~~~~~~~~~~~~~  error: match on wrong line
        20: } 
        21:  
        22: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable 
        23: define void @typed_copy_unaligned_i32(ptr noundef readonly captures(none) %src, ptr noundef writeonly captures(none) initializes((0, 4)) %dst) unnamed_addr #2 { 
        24: start: 
        25:  %_4.sroa.0.0.copyload = load i32, ptr %src, align 1 
        26:  store i32 %_4.sroa.0.0.copyload, ptr %dst, align 1 
        27:  ret void 
        28: } 
        29:  
        30: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable 
        31: define void @write_unaligned_i64(ptr noundef writeonly captures(none) initializes((0, 8)) %ptr, i64 noundef range(i64 1, 0) %val) unnamed_addr #3 { 
        32: start: 
        33:  store i64 %val, ptr %ptr, align 1 
        34:  ret void 
        35: } 
        36:  
        37: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable 
        38: define void @read_unaligned_huge(ptr dead_on_unwind noalias nofree noundef writable writeonly sret([8192 x i8]) align 128 captures(none) dereferenceable(8192) initializes((0, 8192)) %_0, ptr noundef readonly captures(none) %ptr) unnamed_addr #2 { 
        39: start: 
        40:  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 128 dereferenceable(8192) %_0, ptr noundef nonnull align 1 dereferenceable(8192) %ptr, i64 8192, i1 false) 
        41:  ret void 
        42: } 
        43:  
        44: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable 
        45: define void @write_unaligned_huge(ptr noundef writeonly captures(none) initializes((0, 8192)) %ptr, ptr dead_on_return noalias nofree noundef readonly align 128 captures(none) dereferenceable(8192) %val) unnamed_addr #2 { 
        46: start: 
        47:  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(8192) %ptr, ptr noundef nonnull align 128 dereferenceable(8192) %val, i64 8192, i1 false) 
        48:  ret void 
        49: } 
        50:  
        51: ; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) 
        52: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #4 
        53:  
        54: ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) 
        55: declare void @llvm.assume(i1 noundef) #5 
        56:  
        57: attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
        58: attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read, inaccessiblemem: write) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
        59: attributes #2 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
        60: attributes #3 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
        61: attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) } 
        62: attributes #5 = { mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) } 
        63:  
        64: !llvm.module.flags = !{!0, !1, !2} 
        65: !llvm.ident = !{!3} 
        66:  
        67: !0 = !{i32 8, !"PIC Level", i32 2} 
        68: !1 = !{i32 7, !"uwtable", i32 2} 
        69: !2 = !{i32 7, !"frame-pointer", i32 1} 
        70: !3 = !{!"rustc version 1.98.0-nightly (53db257c2 2026-06-25)"} 
        71: !4 = !{} 
>>>>>>

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

error: verification with 'FileCheck' failed
status: exit status: 1
command: "/usr/lib/llvm-21/bin/FileCheck" "--input-file" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll" "/checkout/tests/codegen-llvm/read_write_unaligned.rs" "--check-prefix=CHECK" "--allow-unused-prefixes" "--dump-input-context" "100"
stdout: none
--- stderr -------------------------------
/checkout/tests/codegen-llvm/read_write_unaligned.rs:27:17: error: CHECK-NEXT: is not on the line after the previous match
 // CHECK-NEXT: ret i16 [[TEMP]]
                ^
/checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll:19:2: note: 'next' match was here
 ret i16 %_2.sroa.0.0.copyload
 ^
/checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll:16:53: note: previous match ended here
 %_2.sroa.0.0.copyload = load i16, ptr %ptr, align 1
                                                    ^
/checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll:17:1: note: non-matching line after previous match is here
 %0 = icmp ne i16 %_2.sroa.0.0.copyload, 0
^

Input file: /checkout/obj/build/aarch64-unknown-linux-gnu/test/codegen-llvm/read_write_unaligned/read_write_unaligned.ll
Check file: /checkout/tests/codegen-llvm/read_write_unaligned.rs

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

Input was:
<<<<<<
         1: ; ModuleID = 'read_write_unaligned.e30f5481d8566fd2-cgu.0' 
         2: source_filename = "read_write_unaligned.e30f5481d8566fd2-cgu.0" 
         3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" 
         4: target triple = "aarch64-unknown-linux-gnu" 
         5:  
         6: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable 
         7: define noundef nonnull ptr @read_unaligned_ptr(ptr noundef readonly captures(none) %ptr) unnamed_addr #0 { 
         8: start: 
         9:  %_2.sroa.0.0.copyload = load ptr, ptr %ptr, align 1, !nonnull !4, !noundef !4 
        10:  ret ptr %_2.sroa.0.0.copyload 
        11: } 
        12:  
        13: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read, inaccessiblemem: write) uwtable 
        14: define noundef range(i16 1, 0) i16 @read_unaligned_i16(ptr noundef readonly captures(none) %ptr) unnamed_addr #1 { 
        15: start: 
        16:  %_2.sroa.0.0.copyload = load i16, ptr %ptr, align 1 
        17:  %0 = icmp ne i16 %_2.sroa.0.0.copyload, 0 
        18:  tail call void @llvm.assume(i1 %0) 
        19:  ret i16 %_2.sroa.0.0.copyload 
next:27      !~~~~~~~~~~~~~~~~~~~~~~~~~~~~  error: match on wrong line
        20: } 
        21:  
        22: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable 
        23: define void @typed_copy_unaligned_i32(ptr noundef readonly captures(none) %src, ptr noundef writeonly captures(none) initializes((0, 4)) %dst) unnamed_addr #2 { 
        24: start: 
        25:  %_4.sroa.0.0.copyload = load i32, ptr %src, align 1 
        26:  store i32 %_4.sroa.0.0.copyload, ptr %dst, align 1 
        27:  ret void 
        28: } 
        29:  
        30: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable 
        31: define void @write_unaligned_i64(ptr noundef writeonly captures(none) initializes((0, 8)) %ptr, i64 noundef range(i64 1, 0) %val) unnamed_addr #3 { 
        32: start: 
        33:  store i64 %val, ptr %ptr, align 1 
        34:  ret void 
        35: } 
        36:  
        37: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable 
        38: define void @read_unaligned_huge(ptr dead_on_unwind noalias nofree noundef writable writeonly sret([8192 x i8]) align 128 captures(none) dereferenceable(8192) initializes((0, 8192)) %_0, ptr noundef readonly captures(none) %ptr) unnamed_addr #2 { 
        39: start: 
        40:  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 128 dereferenceable(8192) %_0, ptr noundef nonnull align 1 dereferenceable(8192) %ptr, i64 8192, i1 false) 
        41:  ret void 
        42: } 
        43:  
        44: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable 
        45: define void @write_unaligned_huge(ptr noundef writeonly captures(none) initializes((0, 8192)) %ptr, ptr dead_on_return noalias nofree noundef readonly align 128 captures(none) dereferenceable(8192) %val) unnamed_addr #2 { 
        46: start: 
        47:  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(8192) %ptr, ptr noundef nonnull align 128 dereferenceable(8192) %val, i64 8192, i1 false) 
        48:  ret void 
        49: } 
        50:  
        51: ; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) 
        52: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #4 
        53:  
        54: ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) 
        55: declare void @llvm.assume(i1 noundef) #5 
        56:  
        57: attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
        58: attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read, inaccessiblemem: write) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
        59: attributes #2 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
        60: attributes #3 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
        61: attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) } 
        62: attributes #5 = { mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) } 
        63:  
        64: !llvm.module.flags = !{!0, !1, !2} 
        65: !llvm.ident = !{!3} 
        66:  
        67: !0 = !{i32 8, !"PIC Level", i32 2} 
        68: !1 = !{i32 7, !"uwtable", i32 2} 
        69: !2 = !{i32 7, !"frame-pointer", i32 1} 
        70: !3 = !{!"rustc version 1.98.0-nightly (53db257c2 2026-06-25)"} 
        71: !4 = !{} 
>>>>>>
------------------------------------------

---- [codegen] tests/codegen-llvm/read_write_unaligned.rs stdout end ----

@scottmcm scottmcm closed this Jun 26, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants