[Bug c/105294] New: restrict pointer - disagreement with specification
muecker at gwdg dot de
gcc-bugzilla@gcc.gnu.org
Sat Apr 16 18:47:57 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105294
Bug ID: 105294
Summary: restrict pointer - disagreement with specification
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: muecker at gwdg dot de
Target Milestone: ---
Here is an example where GCC/Clang assume that variables
may not alias where the C spec seems to say otherwise.
This example is based on one found by Hubert Tong
after discussions with him (and Ralf Jung).
Probably the spec should be changed instead of the
compilers.
Note that when removing the first restrict, clang but
not GCC still does the optimization, which hints at
a missed optimization opportunity (assuming a
change in spec which generally makes this valid).
https://godbolt.org/z/K89jdd473
int f(int * q, int * restrict p, int * restrict s)
{
int x;
int *r = &x;
if (p == q)
r = s;
*p = 13;
*r = 42; // `&(*r)` is based on both `p`, `s`!
return *p;
}
int main(void)
{
int q;
return f(&q, &q, &q);
}
More information about the Gcc-bugs
mailing list