[llvm] [IR] Check that arguments of naked function are not used (PR #104757)

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 12:34:09 PDT 2024


e-kud wrote:

@nikic I think we need a special handling for `sret` arguments:
I try to compile:
```
__attribute__((naked))
double _Complex square(int num) {
    __asm__("");
}
```
with `-O2 -target x86_64-pc-windows`

And I got
```
cannot use argument of naked function
ptr %0
```

This is because we have this IR initially (alloca+store are optimized out later):
```
; Function Attrs: naked noinline nounwind uwtable
define dso_local void @square(ptr dead_on_unwind writable sret({ double, double }) align 8 %0, i32 noundef %1) #0 !dbg !9 {
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8
  call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags}"() #1, !dbg !15, !srcloc !16
  unreachable, !dbg !17
}
```

https://godbolt.org/z/rY7h3sE76

So it looks like there is no problem from user's side. But the verification fails due to compiler internal reasons.

https://github.com/llvm/llvm-project/pull/104757


More information about the llvm-commits mailing list