Issue 96427
Summary [x86] Invalid assembly given inverted meaning
Labels new issue
Assignees
Reporter workingjubilee
    The following LLVMIR is misassembled:

```llvm
; ModuleID = 'example.1737988f50a8444b-cgu.0'
source_filename = "example.1737988f50a8444b-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; example::lea_sub
; Function Attrs: nonlazybind uwtable
define i64 @_ZN7example7lea_sub17h65e6a411b5553049E(i64 %x) unnamed_addr #0 {
start:
  %y = alloca [8 x i8], align 8
  %0 = call i64 asm sideeffect alignstack inteldialect "xor rax, rax\0Alea rax, [rax - 8 * rdx]", "=&{ax},{dx},~{dirflag},~{fpsr},~{flags},~{memory}"(i64 %x), !srcloc !3
  store i64 %0, ptr %y, align 8
  %_0 = load i64, ptr %y, align 8
  ret i64 %_0
}

attributes #0 = { nonlazybind uwtable "probe-stack"="inline-asm" "target-cpu"="x86-64" }

!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 2, !"RtLibUseGOT", i32 1}
!2 = !{!"rustc version 1.79.0 (129f3b996 2024-06-10)"}
!3 = !{i32 0, i32 106, i32 130}
```

Note that `"xor rax, rax\0Alea rax, [rax - 8 * rdx]"`!

Here is the assembly output from llc:
```asm
example::lea_sub::h65e6a411b5553049: # @example::lea_sub::h65e6a411b5553049
        push    rax
        mov rdx, rdi

        xor     rax, rax
        lea     rax, [rax + 8*rdx]

        mov     qword ptr [rsp], rax
        pop     rcx
 ret
```

Note the `-` in `lea rax, [rax - 8 * rdx]` became a `+` in `lea rax, [rax + 8*rdx]`. The assembly is invalid, but the assembling is incorrect instead of rejecting it.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to