-
Notifications
You must be signed in to change notification settings - Fork 13.4k
unsized_fn_params allows some unsized locals #111175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I forgot how exactly #78152 works, but for some reason it lets this pass. Either the analysis should reject this, or MIR building needs to not create an unsized local here. |
The bad MIR builing is here:
Any unsized function call operand other than a |
Current LLVMIR: https://rust.godbolt.org/z/7zx7Yvr9h source_filename = "example.f256f209c7383c27-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define void @_ZN7example14forget_unsized17h4990435afa880043E(ptr align 4 %0, i64 %1) unnamed_addr #0 {
%_2 = alloca [16 x i8], align 8
%input = alloca [16 x i8], align 8
store ptr %0, ptr %input, align 8
%2 = getelementptr inbounds i8, ptr %input, i64 8
store i64 %1, ptr %2, align 8
%3 = load ptr, ptr %input, align 8
%4 = getelementptr inbounds i8, ptr %input, i64 8
%5 = load i64, ptr %4, align 8
%6 = mul nuw nsw i64 %5, 4
%7 = add i64 %6, 3
%8 = alloca i8, i64 %7, align 1
%9 = ptrtoint ptr %8 to i64
%10 = sub i64 0, %9
%11 = and i64 %10, 3
%12 = getelementptr inbounds i8, ptr %8, i64 %11
call void @llvm.memcpy.p0.p0.i64(ptr align 1 %12, ptr align 1 %3, i64 %6, i1 false)
store ptr %12, ptr %_2, align 8
%13 = getelementptr inbounds i8, ptr %_2, i64 8
store i64 %5, ptr %13, align 8
ret void
}
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1
attributes #0 = { nonlazybind uwtable "probe-stack"="inline-asm" "target-cpu"="x86-64" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 2, !"RtLibUseGOT", i32 1}
!2 = !{!"rustc version 1.89.0-nightly (4d08223c0 2025-05-31)"} No significant differences aside from less struct types. |
Uh oh!
There was an error while loading. Please reload this page.
Found in rust-lang/miri#2872: this code
with
-Zmir-opt-level=0
generates this LLVM IRNotice the
alloca
. This is bad! Our alloca code path is unsound (it does not properly account for alignment); the point of theunsized_fn_params
feature gate (separate fromunsized_locals
) was to avoid hitting that code path.I repeat my stance that we should remove the unsound alloca code path (effectively de-imlementing unsized locals) to ensure this can never happen.
We don't have a MIR building ping group AFAIK, so Cc @rust-lang/wg-mir-opt I guess.
Here's a Miri testcase:
The text was updated successfully, but these errors were encountered: