-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
kornelski, Kobzol and stepancheg
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.