https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106662

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
As I wrote on omp-lang, I believe this is UB.
simd doesn't accept firstprivate clause, but does accept lastprivate.
So, each SIMD lane's private j starts uninitialized (or for C++ default
constructed but for int that is the same thing) and the value from the SIMD
lane corresponding to last iteration is copied over to the private copy of j
in the worksharing-loop.
With simd, one has basically these data-sharing possibilities:
1) no data sharing clause, then it works kind like "shared", all SIMD lanes
   read the same variable, they'd better not to store it as that would be
   a data race
2) private - each SIMD lane has its private copy of the var,
   uninitialized/default-constructed at the start, destroyed at the end
3) lastprivate - likewise, but before it is destroyed, the SIMD lane
   corresponding to last iteration copies to original var
4) linear - must be integral, each SIMD lane gets the private var initialized
   with the original list value + step * SIMD_lane_# and the last iteration
   effect like lastprivate

Reply via email to