Skip to content

[AVR] Invalid asm code "ldd rn, X+N" compiles and produces corrupted binary #109360

@Slickis

Description

@Slickis

AVR assembler instruction ldd is defined only for registers Y and Z, but not for X.
asm!() macro accepts it.

I tried this code:

#[no_mangle]
extern "C" fn main() {
    unsafe {
        ::core::arch::asm!("
                ldd   {tmp}, X+0
                ldd   {tmp}, X+1
            ",
            tmp = out(reg) _,
            in("X") &0xAABB_u16,
        );
    }
}

I expected to see this happen: compilation error.

Instead, this happened: rustc produces a binary with a corrupted code.

000000a6 <main>:
  a6:    a0 e0           ldi    r26, 0x00    ; 0
  a8:    b1 e0           ldi    r27, 0x01    ; 1
  aa:    88 81           ld     r24, Y
  ac:    89 81           ldd    r24, Y+1     ; 0x01
  ae:    08 95           ret

Pointer (0x0100) to a value is loaded into register X (r26:r27) following by reads from *Y.

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (22f247c6f 2023-03-13)
binary: rustc
commit-hash: 22f247c6f3ed388cb702d01c2ff27da658a8b353
commit-date: 2023-03-13
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Steps to reproduce:

repo: https://github.com/Slickis/rustc-ldd-x

git clone https://github.com/Slickis/rustc-ldd-x
cd rustc-ldd-x
make lss

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.O-AVRTarget: AVR processors (ATtiny, ATmega, etc.)llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixes

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions