[Bug tree-optimization/90328] New: Wrong loop distribution with aliasing
glisse at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri May 3 14:28:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90328
Bug ID: 90328
Summary: Wrong loop distribution with aliasing
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: glisse at gcc dot gnu.org
Target Milestone: ---
I was investigating missed loop distribution opportunities probably related to
aliasing, and hit this case where gcc seems a bit too optimistic.
#include <new>
struct T { int* p; T(T const&t):p(t.p){} };
T* f(T* a,T* b){
for(int i=0;i<1024;++i){
a[i].~T();
new(a+i)T(b[i]);
}
return a;
}
This gets optimized to a call to memcpy.
However, I believe it is legal to call f(x+1,x) where x is an array of size
1025, where it should replace every element with a copy of the first one.
This seems related to "new" and the use of a constructor. It is true that this
implies that a[i] and b[i] cannot alias, but not that the whole a and b cannot
alias.
More information about the Gcc-bugs
mailing list