<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96070>96070</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang 17] wrong code at -O2/O3 with restrict-qualified pointers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tangyixuan01
</td>
</tr>
</table>
<pre>
I think it is legal to call f(a+1,a) with restrict, and it replaces each element with a copy of the prior one. It seems that Clang-17 outputs wrong code with optimizations -O2/O3.
The behavior can be verified on Godbolt: [https://godbolt.org/z/jnYMvrfr7](url)
```c
int printf(const char *, ...);
void g(int*__restrict a, int* b)
{
*a = *b;
}
void f(int* c,int* d)
{
for(int i=0;i<99;++i)
g(c+i,d+i);
}
int main()
{
int a[100];
for (int i = 0; i < 100; ++i)
a[i] = i+1;
f(a+1, a);
for (int i = 0; i < 100; ++i)
printf("%d\n",a[i]);
return 0;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE2TozYQ_TXNpcuUkMzXgYONi9QeUnvJJactIQRoI0tEEt7M_vqUYOzxTCanrVJBI3W_99R0N_deTUbKBvIz5JeEr2G2rgncTC_qn5UbkiW9HV6aLxhmZf5CFVB51HLiGoNFwbXGEWjFgZ4zoC0HWuMPFWZ00genRADaIjdDjHRy0VxIj5KLGaWWV2nC7s1R2OUF7Yhhlrg4ZR1aI1P8EtBLefUYZh6w1dxMh6xEu4ZlDR5_OGsmFHaQO45dgrqqnzwoazwevlKg3VeWArkAOe3PP2aJvZz5LXIIbrCXeJNOjUoOaA3-Zofe6gDshJCf5xAWD-wEtAPaTftZat0EtPsJtPtu_vz95kZXQn4BWq1OA62f6aAg-xL7tzIh3s-EmDZhjQ8oZu4Q6CmmKk3TCMDOu_fNqgEnoJUyAejp27d7WpFH730X-zfO8jUQIyBHYJdo9A9AKC_P6jb88YGPAmj7ag6fgY7W7c6ogF0IsLMC1tabYBqXekRtssW-1Q73o__RERGvXBmg1We08ZhDfs4IiXlmz3rwLmi7bJS0mS1GZ3bG_-hC3LAU5JctRG21-4T5VM8xzfWv8z1-OFAKNB8gb81mtncl72mcDKszG_jHdN3LKRkaNtSs5olssjKrKnKs6iKZmzHPqiKrqeDkWJc1EYUQnLGxrkpSlEOfqIYSeiRFVmfsWGVFmomCSi56krN8yIsRjkReudKp1rdrrPVEeb_Kpi5ISRLNe6n9fWK4Jjod-nXycCRa-eDfwoIKepstIvYtZrFJnluWh0eLvh8ah79XrveOXKwyQTqfrE43H7pRhXntU2GvQLtI-vo6LM5-l3H0dJtwD7Tbtd8a-m8AAAD__wIrZWw">