Closed
Description
#[derive(Clone, Copy)]
pub enum Foo {
A, B, C, D,
}
pub fn foo(v: *const Foo) -> Foo {
let k: Option<Foo> = unsafe { Some(*v) };
return k.unwrap();
}
compiles to
example::foo:
mov al, byte ptr [rdi]
ret
but replacing *v
with v.read()
#[derive(Clone, Copy)]
pub enum Foo {
A, B, C, D,
}
pub fn foo(v: *const Foo) -> Foo {
let k: Option<Foo> = unsafe { Some(v.read()) };
return k.unwrap();
}
compiles to:
example::foo:
push rax
mov al, byte ptr [rdi]
cmp al, 4
je .LBB0_1
pop rcx
ret
.LBB0_1:
lea rdi, [rip + .L__unnamed_1]
lea rdx, [rip + .L__unnamed_2]
mov esi, 43
call qword ptr [rip + core::panicking::panic@GOTPCREL]
ud2
This came up from #71257
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generationCategory: This is a bug.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.