<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62271>62271</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
memcpy fails with address spaces
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mafemergency
</td>
</tr>
</table>
<pre>
```c
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <immintrin.h>
char src[4096];
char dst[4096];
int main(void) {
_writefsbase_u64((uintptr_t) src);
char __attribute__((address_space(257))) *seg_src = NULL;
memcpy(dst, seg_src, sizeof(dst));
}
```
compiled with `-mfsgsbase` on x86_64 windows this example fails with the error
```
fatal error: error in backend: cannot lower memory intrinsic in address space 257
```
additionally with `-fno-builtin`
```
error: passing '__attribute__((address_space(257))) char *' to parameter of type 'const void *' changes
address space of pointer
```
copying large structs where either pointer has an address space without an explicit memcpy exhibits
similar behaviour. smaller memcpys (128 bytes or less) work as expected.
to test on linux consider using `_writegsbase_u64` and `address_space(256)` instead
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE2PozgQ_TXOpdQRmITAgUP39PZptLc9I2MXUDvGRnbRSfbXrwzp6WS3Z6WNELF49flelVWMNDjERhxfxPF1pxYefWgm1eOEYUCnr7vOm2sjymx7tMheRfYsZEFO28UgiOJbZGOw34-i-O0XMDn-DziQG34J0zSRSyb3FutbjypADFocXw5ZXYrjqyhe7iAT-Qtoe5NjmBQ5Iat3T0bIGsTpp0XdngMx9rFTEdulPAhZCVkt5Hjm0HIyT4llfRe2XpO2rWIO1C2Mbbu5KWMCxtjGWWkUspLHU_JcHxDyOeLQxqBBFK_w-x_fv9_HnHDS81XIKjUjv8HNdj3SX-j7D6h-KOb0ejt86PbAm59msmjgTDyCKLOnqY_D2qsoM_AOLlXZlgc4kzP-HIFHioAXNc0WoVdk4-bKIwKG4MOXyXrFyt7w4nk7ADnolP6BzqRvWjnnGaw_Y4AJJx-usIkdSSfbG3WwUgeJuK8yKWOIyTtl7fWzqd75p24hy-Q-CXh0_FncnDbBDSDk6f8KuKou5LOQJ2APswpqQsYAvge-zphiau8iQxq0D0s9Kjdg3MqA9ffYq-9h9uQYvyZX-_maCrYqDAiRw6I5wnnEgIDEI4YPdxhVBPVPKhNLfuEE4GW2pIlhmzXAy0gd8a22SBNZFaDDUb2TX8Ie4qSs3QTT8zWCkFUuK-iujBF8AIsxJmbOPvwAlSZnRs1o9ltE9sAYOc2ZJbdcILFDBgMsmwZltq3f8Ll-ZQbKmQT9W4syCVFmQC4yKrMzTWHqolY7bPKykllRVXW-G5u-KPpS9UV1MFlpdFEpnWfHYy1lWakaTztqZCaL7CDzLM_yIt-rvFZHVeZl3Wed7pQ4ZDgpsntr36e9D8OOYlywKaU85TurOrRxvUqldHiGFRRSpps1NMnnqVuGKA6ZpcjxMwoTW2xu9N_t14NkcbcE24zMcxTFs5BvQr4NxOPS7bWfhHxL4W5_T3Pwf6JmId_WIqKQb2uRfwcAAP__GLnZpA">