-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.Category: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
I hoped this would work
const fn get_3() -> u32
{
3
}
pub unsafe fn use_get_3()
{
asm!("" : : "i"(get_3()))
}
but it generates (without optimizations)
%0 = call i32 @_ZN8rust_out5get_317hccb90954bf88bf3cE()
call void asm "", "i,~{dirflag},~{fpsr},~{flags}"(i32 %0)
giving error: invalid operand for inline asm constraint 'i'
.
The current solution seems to be
pub unsafe fn use_three()
{
const THREE: u32 = get_3();
asm!("" : : "i"(THREE))
}
which generates
call void asm "", "i,~{dirflag},~{fpsr},~{flags}"(i32 3)
like I hoped the first case would.
Could we make the first case guaranteed to work?
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.Category: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.