https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119399
Bug ID: 119399
Summary: Overlap check in vectorized code may invoke UB
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Target Milestone: ---
Compile the function below for X86_64 with -O3:
void foo(int *p, int *q, int n)
{
for (int i = 0; i < n; i++)
p[i] = q[i] + 1;
}
The vectorizer adds code performing an overlap check:
<bb 14>:
_7 = q_11(D) + 4;
_25 = p_12(D) - _7;
_26 = (sizetype) _25;
_27 = _26 > 8;
_28 = _27;
if (_28 != 0)
goto <bb 11>;
else
goto <bb 12>;
This takes the difference between two pointers that may point to different
objects, which invokes UB if the distance between the objects are too large to
fit in the result type.