AZ
pub fn baz() {
let x: u8 = 1234567.0 as u8;
println!("{}", x);
}
Она не содержит никакого бага или УБ, всегда компилируется такой код:
; Function Attrs: nonlazybind uwtable
define void @_ZN10playground3baz17h5ea5d7eb0f979146E() unnamed_addr #0 {
start:
%_10 = alloca [1 x { i8*, i8* }], align 8
%_3 = alloca %"core::fmt::Arguments", align 8
%x = alloca i8, align 1
call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %x)
%0 = bitcast %"core::fmt::Arguments"* %_3 to i8*
call void @llvm.lifetime.start.p0i8(i64 48, i8* nonnull %0)
%1 = bitcast [1 x { i8*, i8* }]* %_10 to i8*
call void @llvm.lifetime.start.p0i8(i64 16, i8* nonnull %1)
%2 = getelementptr inbounds [1 x { i8*, i8* }], [1 x { i8*, i8* }]* %_10, i64 0, i64 0, i32 0
store i8* %x, i8** %2, align 8
%3 = getelementptr inbounds [1 x { i8*, i8* }], [1 x { i8*, i8* }]* %_10, i64 0, i64 0, i32 1
store i8* bitcast (i1 (i8*, %"core::fmt::Formatter"*)* @"_ZN4core3fmt3num3imp51_$LT$impl$u20$core..fmt..Display$u20$for$u20$u8$GT$3fmt17h31b518634a8fab65E" to i8*), i8** %3, align 8
%4 = bitcast %"core::fmt::Arguments"* %_3 to [0 x { [0 x i8]*, i64 }]**
store [0 x { [0 x i8]*, i64 }]* bitcast (<{ i8*, [8 x i8], i8*, [8 x i8] }>* @anon.dde6f0dcb74d785c6d76682199d2b436.2 to [0 x { [0 x i8]*, i64 }]*), [0 x { [0 x i8]*, i64 }]** %4, align 8, !alias.scope !2, !noalias !5
%5 = getelementptr inbounds %"core::fmt::Arguments", %"core::fmt::Arguments"* %_3, i64 0, i32 1, i32 1
store i64 2, i64* %5, align 8, !alias.scope !2, !noalias !5
%6 = getelementptr inbounds %"core::fmt::Arguments", %"core::fmt::Arguments"* %_3, i64 0, i32 3, i32 0
store i64* null, i64** %6, align 8, !alias.scope !2, !noalias !5
%7 = getelementptr inbounds %"core::fmt::Arguments", %"core::fmt::Arguments"* %_3, i64 0, i32 5, i32 0
%8 = bitcast [0 x { i8*, i8* }]** %7 to [1 x { i8*, i8* }]**
store [1 x { i8*, i8* }]* %_10, [1 x { i8*, i8* }]** %8, align 8, !alias.scope !2, !noalias !5
%9 = getelementptr inbounds %"core::fmt::Arguments", %"core::fmt::Arguments"* %_3, i64 0, i32 5, i32 1
store i64 1, i64* %9, align 8, !alias.scope !2, !noalias !5
; call std::io::stdio::_print
call void @_ZN3std2io5stdio6_print17h7e1d4022dd9ebaeaE(%"core::fmt::Arguments"* noalias nocapture nonnull dereferenceable(48) %_3)
call void @llvm.lifetime.end.p0i8(i64 48, i8* nonnull %0)
call void @llvm.lifetime.end.p0i8(i64 16, i8* nonnull %1)
call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull %x)
ret void
}