Skip to content

RISC-V inline assembly ignores input register constraints #60391

Closed
@fintelia

Description

@fintelia

This code:

#![no_std]
#![feature(asm)]
#![feature(start)]
#![feature(lang_items)]

#[lang = "eh_personality"] extern fn eh_personality() {}
#[panic_handler] fn panic(info: &::core::panic::PanicInfo) -> ! { loop {} }
#[start] fn start(_argc: isize, _argv: *const *const u8) -> isize {0}
#[no_mangle] pub fn abort() -> ! { loop {} }

#[no_mangle]
pub fn _start(a: [u32; 6]) {
    unsafe {
        asm!(""
             :: "r{sp}"(a[4]), "r{t0}"(a[5])
             : "volatile"
        );
    }
}

When compiled for the riscv64imac target:

$ cargo rustc --release --target riscv64imac-unknown-none-elf

Ignores the input register constraints which say to use sp and t0 (defaulting to a0 and a1 instead):

0000000000011000 <_start>:
   11000:	01456583          	lwu	a1,20(a0)
   11004:	01056503          	lwu	a0,16(a0)
   11008:	8082                	ret

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.O-riscvTarget: RISC-V architectureT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions