Repository: rust
Issue: rustc SIGSEGV on asm macro when no more registers are availaible
Labels: E-easy,A-LLVM,E-needs-test,A-inline-assembly,T-compiler,C-bug,F-asm

Found while tinkering with the asm macro for embedded purposes.

It should be noted that it doesn't occurs when building in release.

### Code

See [asm_rustc_crash_debug_no_regs](https://github.com/Thog/asm_rustc_crash_debug_no_regs) for a minimal reproducer project.

```Rust
#![no_std]
#![feature(asm)]

#[derive(Debug)]
#[repr(C)]
pub struct ThreadContext {
    pub r: [u32; 16]
}

//#[naked]
#[no_mangle]
pub unsafe extern "C" fn arm_create_thread_context() -> ThreadContext {
    let r0: u32;
    let r1: u32;
    let r2: u32;
    let r3: u32;
    let r4: u32;
    let r5: u32;
    let r6: u32;
    let r7: u32;
    let r8: u32;
    let r9: u32;
    let r10: u32;
    let r11: u32;
    let r12: u32;
    let r13: u32;
    let r14: u32;
    let r15: u32;

    asm!(
        "mov {0}, r0",
        "mov {1}, r1",
        "mov {2}, r2",
        "mov {3}, r3",
        "mov {4}, r4",
        "mov {5}, r5",
        "mov {6}, r6",
        "mov {7}, r7",
        "mov {8}, r8",
        "mov {9}, r9",
        "mov {10}, r10",
        "mov {11}, r11",
        "mov {12}, r12",
        "mov {13}, r13",
        "mov {14}, r14",
        "mov {15}, r15",
        out(reg) r0,
        out(reg) r1,
        out(reg) r2,
        out(reg) r3,
        out(reg) r4,
        out(reg) r5,
        out(reg) r6,
        out(reg) r7,
        out(reg) r8,
        out(reg) r9,
        out(reg) r10,
        out(reg) r11,
        out(reg) r12,
        out(reg) r13,
        out(reg) r14,
        out(reg) r15,
    );
    
    ThreadContext {
        r: [r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15]
    }
}
```


### Meta
`rustc --version --verbose`:
```
rustc 1.58.0-nightly (82af160c2 2021-11-10)
binary: rustc
commit-hash: 82af160c2cb9c349a0373cba98d8ad7f911f0d34
commit-date: 2021-11-10
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
```

### Error output
`RUST_BACKTRACE=1 cargo build --target armv7a-none-eabi`:
```
   Compiling asm_rustc_crash_debug_no_regs v0.1.0 (/home/mary/dev/asm_rustc_crash_debug_no_regs)
error: inline assembly requires more registers than available
  --> src/lib.rs:31:10
   |
31 |         "mov {0}, r0",
   |          ^

/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-535ad5bbd58fc935.so(+0x4c9c03)[0x7f6aa65f1c03]
/usr/lib/libpthread.so.0(+0x13870)[0x7f6aa5da0870]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x3fa460c)[0x7f6aa4e4060c]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x3fa44ff)[0x7f6aa4e404ff]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x3fa4db3)[0x7f6aa4e40db3]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZNK4llvm10AsmPrinter13emitInlineAsmEPKNS_12MachineInstrE+0x525)[0x7f6aa3bc0715]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm10AsmPrinter16emitFunctionBodyEv+0xfcf)[0x7f6aa3bbd8ef]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x3fa4114)[0x7f6aa4e40114]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE+0xaa)[0x7f6aa3ba877a]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x6c9)[0x7f6aa3a6ffe9]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x7f6aa3a6f8ff]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x289)[0x7f6aa3e4bb89]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-535ad5bbd58fc935.so(+0x23fdbf4)[0x7f6aa8525bf4]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-535ad5bbd58fc935.so(+0x23f80b7)[0x7f6aa85200b7]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-535ad5bbd58fc935.so(+0x23fad06)[0x7f6aa8522d06]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-535ad5bbd58fc935.so(+0x238d69b)[0x7f6aa84b569b]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-535ad5bbd58fc935.so(+0x2387d1b)[0x7f6aa84afd1b]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-535ad5bbd58fc935.so(+0x23cff4f)[0x7f6aa84f7f4f]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-535ad5bbd58fc935.so(+0x23e1303)[0x7f6aa8509303]
/home/mary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/libstd-7387d118fba15d64.so(rust_metadata_std_a5529df289459975+0xa9a13)[0x7f6aa5e62a13]
/usr/lib/libpthread.so.0(+0x9259)[0x7f6aa5d96259]
/usr/lib/libc.so.6(clone+0x43)[0x7f6aa5cab5e3]
error: could not compile `asm_rustc_crash_debug_no_regs` due to previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name asm_rustc_crash_debug_no_regs --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=66f9ecd5d6840985 -C extra-filename=-66f9ecd5d6840985 --out-dir /home/mary/dev/asm_rustc_crash_debug_no_regs/target/armv7a-none-eabi/debug/deps --target armv7a-none-eabi -C incremental=/home/mary/dev/asm_rustc_crash_debug_no_regs/target/armv7a-none-eabi/debug/incremental -L dependency=/home/mary/dev/asm_rustc_crash_debug_no_regs/target/armv7a-none-eabi/debug/deps -L dependency=/home/mary/dev/asm_rustc_crash_debug_no_regs/target/debug/deps` (signal: 11, SIGSEGV: invalid memory reference)
```



<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"Lule321"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->