https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129028
Bug ID: 129028
Summary: [14/15/16 Regression] Missing initialization of
initializer-list backing array inside omp simd
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: xingjian0330 at gmail dot com
Target Milestone: ---
GCC 16.2.0 on x86_64-linux-gnu produces incorrect results when iterating over
{1, 2} inside an OpenMP SIMD loop. Each outer iteration should store 3 in
out[i],
so the expected printed output is 3 3 3 3 and the expected exit status is 0.
Both examples use the same source and these shared compilation flags:
-Wall -Wextra -fopenmp-simd -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations
The only difference is the optimization flag:
- -O3: compilation succeeds without warnings. The inspected run prints
0 0 135168 105915861 and exits with status 1.
https://godbolt.org/z/GqYPGx1o4
- -O1: compilation succeeds but warns at the range-based for loop:
<source>:8:18: warning: '<anonymous>' is used uninitialized [-Wuninitialized]
The accompanying note points to the OpenMP pragma at line 5 as the
declaration.
The inspected run prints 0 0 0 0 and exits with status 1.
https://godbolt.org/z/3nrabd8aT
It looks like the problem is missing initialization of compiler-generated
storage.
I tested on GCC 13.(1,2,3,4) and all of these printed the expected result.
For GCC 14.(1,2,3,4) it printed 0 always.
For GCC 15.(1,2,3) it printed four same numbers but not 0.
For GCC 16.(1,2) it printed four different numbers.
All of the tests are done using Compiler Explorer and with
-O3 -Wall -Wextra -fopenmp-simd -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations
Source (repro.cpp; default GNU C++20 mode):
#include <cstdio>
#include <initializer_list>
int main() {
int out[16];
#pragma omp parallel for simd
for (int i = 0; i < 16; ++i) {
int sum = 0;
for (int x : {1, 2}) sum += x;
out[i] = sum;
}
std::printf("%d %d %d %d\n", out[0], out[1], out[2], out[3]);
for (int x : out) if (x != 3) return 1;
}
GCC 16.2.0 build configuration (from -v):
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-16.2.0/bin/g++
Target: x86_64-linux-gnu
Configured with: ../gcc-16.2.0/configure
--prefix=/opt/compiler-explorer/gcc-build/staging --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap
--enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --enable-clocale=gnu
--enable-languages=c,c++,fortran,ada,objc,obj-c++,go,d,m2,rust,cobol,algol68
--enable-ld=yes --enable-gold=yes --enable-libstdcxx-time=yes
--enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix
--with-pkgversion=Compiler-Explorer-Build-gcc--binutils-2.44
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.2.0 (Compiler-Explorer-Build-gcc--binutils-2.44)
compiled by GNU C version 11.4.0, GMP version 6.3.0, MPFR version 4.2.2, MPC
version 1.3.1, isl version isl-0.24-GMP