Skip to content

LLVM does not accept generated inline assembly with variable+offset #2257

@JohanEngelen

Description

@JohanEngelen

Testcase:

void foo()
{
    uint[4] a;
    asm pure nothrow @nogc {
        mov a, EAX;
        mov a+4, EBX;
    }
}

When compiled with ldc2 -c -fsanitize=address test.d, we get the error:

<inline asm>:1:16: error: unknown token in expression
        movl %ebx, 4+(%rcx)
                      ^
LLVM ERROR: Error parsing inline asm

Strangely, when I compile manually to LLVM IR and then use llc to obtain assembly output, everything works fine. So I can't reproduce it from LLVM IR onwards.

The inline asm looks like this in LLVM IR:

  call void asm sideeffect "movl %eax, $0\0A\09movl %ebx, 4+$1", "=*m,=*m,~{memory}"([4 x i32]* %3, [4 x i32]* %3)

without -fsanitize=address, the $1 resolves to ebp plus an offset; with -fsanitize=address, the $1 resolves to a register without any offset and that's invalid (i.e. "4+(%rcx)" is not valid but "4+32(%rcx)" is). At least that's what I think is what's going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvmRelated to LLVMsanitizersASan, libFuzzer, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions