| Issue |
183881
|
| Summary |
Clang generates invalid code (crash) for template pack expansion when using `-nostdlib` and `-O0`
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
gab462
|
Minimal example:
```c
struct typ {
long a;
long b;
};
struct typ2 {
long a;
long b;
};
auto func(typ s) -> void {
}
template <typename ...A>
auto unpack(A... args) -> typ2 {
(func(args), ...);
return {};
}
extern "C" auto _start() -> void {
typ var = { 4 , 4 };
typ2 r = unpack(var);
register long ret asm("rax") = 60;
register long r0 asm("rdi") = 0;
__asm__ volatile(
"syscall"
: "+r"(ret)
: "r"(r0)
: "rcx", "r11", "memory");
}
```
Compile with `-nostdlib -e _start`. The program terminates with SIGSEGV at the parameter pack expansion (according to gdb). Checked trunk on godbolt and the results are the same.
The problem disappears with any of these conditions:
- Using anything other than `-O0`
- `typ` fits into one register (two `int`s max on my machine)
- `typ2` fits into one register
- `typ2` is big enough for a `memset` optimization to kick in (more than two `long`s on my machine)
- `unpack()` returns void
- Not using `-nostdlib` and doing a normal `int main` with `return 0`
My machine: `Linux kde 6.18.9-zen1-2-zen`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs