https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120327
Bug ID: 120327
Summary: OpenMP, triangular collapsed for-loop,
maybe-uninitialized warning
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jukka.suomela at aalto dot fi
Target Milestone: ---
Created attachment 61458
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61458&action=edit
Source code
It seems that when compiling OpenMP code with collapsed triangular for-loops
with optimization levels -O or -Og, I get the warning "'({anonymous})' may be
used uninitialized".
Moreover, it seems that "#pragma GCC diagnostic ignored" cannot be used to
silence this warning or turn it into a non-error (if I have -Werror enabled).
Source code:
----
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
int main(void) {
int n = 100;
#pragma omp parallel for collapse(2)
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
}
}
}
----
Compiler output:
----
% gcc-14 -Wall -Werror -fopenmp -O test.c
In function 'main._omp_fn.0':
cc1: error: '({anonymous})' may be used uninitialized
[-Werror=maybe-uninitialized]
cc1: all warnings being treated as errors
% gcc-12 -Wall -Werror -fopenmp -O test.c
In function 'main._omp_fn.0':
cc1: error: '({anonymous})' may be used uninitialized
[-Werror=maybe-uninitialized]
cc1: all warnings being treated as errors
% gcc-11 -Wall -Werror -fopenmp -Og test.c
test.c: In function 'main._omp_fn.0':
cc1: error: '({anonymous})' may be used uninitialized in this function
[-Werror=maybe-uninitialized]
cc1: all warnings being treated as errors
----
Compiler versions:
----
% gcc-14 --version
gcc-14 (Homebrew GCC 14.2.0_1) 14.2.0
% gcc-12 --version
gcc-12 (Homebrew GCC 12.4.0) 12.4.0
% gcc-11 --version
gcc-11 (Homebrew GCC 11.5.0) 11.5.0
----
System: aarch64-apple-darwin24, macOS 15.4.1 (but this doesn't seem to be
important, as I can reproduce this also on x86 Intel Linux).
The main problem for me is that #pragma GCC diagnostic ignored is not working,
so this leads to challenges in workflows that use -Werror.