<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/113488>113488</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
riscv64 apparent miscompilation causing segfault
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bscarlet
</td>
</tr>
</table>
<pre>
The following program segfaults for me when compiled and run:
```
#include <cstdarg>
struct Foo {
char *buf0;
char *buf1;
};
void (*x)(Foo *);
static void x_impl(Foo *) {}
void vfoo(char *buf0, const char *, va_list ap) {
char buf1[80];
Foo f{.buf0 = buf0, .buf1 = buf1};
x = x_impl;
va_list ap2;
va_copy(ap2, ap);
x(&f);
va_end(ap2);
}
void foo(const char *format, ...) {
va_list ap;
va_start(ap, format);
char buffer[4096];
vfoo(buffer, format, ap);
va_end(ap);
}
int main(int argc, char **argv) {
foo("");
return 0;
}
```
Using
`clang ... -O1 -mrvv-vector-bits=512 -target riscv64-unknown-linux -march=rv64gcv1p0 ...`
(... includes flags I don't think are relevant, like paths about my environment etc, and - among other things - examining the output assembly)
This problem started for me at the merge of
https://github.com/llvm/llvm-project/pull/110809
This tarball contains the source above, and the assembly I get with and without the problem.
[riscv-varargs-crash.tgz](https://github.com/user-attachments/files/17497474/riscv-varargs-crash.tgz)
The differences in the assembly do look to me like probably results of the above merge.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1vqzgX_jXO5ogIDASyYNHevJHu6t3cWVcHcwBPjY1sQ9v59SM7oU3SmSuNhMAc-3w8z_kwOicHTdSw8pmVpx0ufjS2aZ1Aq8jvWtN9NL9Ggt4oZd6kHmC2ZrA4gaOhx0V5B72xMBG8jaRBmGmWijpA3YFdNMufWHpi6fY-pNfn8stzqYVaOgKW_xDOd2gHlv_vVsV5uwgPZ2OAVc8XGYgRLTD-1C59yvJNeivOPsWsOn2t43s1sgPGa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