[Bug c++/115192] New: GCC 14.1.0 -O3 miscompilation on x86-64 (loops with vectors and scalars)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115192 Bug ID: 115192 Summary: GCC 14.1.0 -O3 miscompilation on x86-64 (loops with vectors and scalars) Product: gcc Version: 14.1.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 58268 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58268&action=edit Preprocessed source code It seems that GCC 14.1.0 with -O3 mis-compiles the attached code on x86-64. The key element seems to be loops that involve both arrays of vector types and arrays of scalar types. This is the expected output: $ g++-14 -Wall -Wextra -O2 test.cc -o test && ./test 0.00 0.00 3.00 3.00 9.00 9.00 This is the unexpected output that we got with -O3: $ g++-14 -Wall -Wextra -O3 test.cc -o test && ./test 0.00 0.00 3.00 3.00 6.00 6.00 I have attached the preprocessed source code produced by the following command, and I will attach also the full compiler output that I got: g++-14 -v -save-temps -Wall -Wextra -O3 test.cc -o test Compiler: GNU C++17 (Homebrew GCC 14.1.0) version 14.1.0 (x86_64-apple-darwin21), compiled by GNU C version 14.1.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP, Target: x86_64-apple-darwin21.6.0. This is GCC on Intel-macOS from Homebrew, but we originally noticed the problem in Intel-Linux, so it doesn't seem to be specific to macOS or Homebrew. However, I wasn't able to reproduce the bug on Apple M3, so it might be specific to x86-64.
[Bug c++/115192] GCC 14.1.0 -O3 miscompilation on x86-64 (loops with vectors and scalars)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115192 --- Comment #1 from Jukka Suomela --- Created attachment 58269 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58269&action=edit Compiler output
[Bug c++/115192] [14/15 regression] -O3 miscompilation on x86-64 (loops with vectors and scalars) since r14-2117
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115192 --- Comment #4 from Jukka Suomela --- Created attachment 58271 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58271&action=edit Another example, miscompiles with GCC 11 (-O3 -march=skylake) Here is a minor variant of the theme. This variant seems to fail already on GCC 11 if I compile with -O3 -march=skylake. Expected: $ g++-11 -Wall -Wextra test.cc -O2 -march=skylake -o test && ./test 0.00 0.00 11.00 22.00 22.00 44.00 Unexpected: $ g++-11 -Wall -Wextra test.cc -O3 -march=skylake -o test && ./test 0.00 0.00 11.00 22.00 11.00 22.00 This was with g++-11 (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 on x86_64-linux-gnu. In godbolt.org GCC 11.1 seemed to be the first version where this behavior started. (Apologies if this should be a separate bug report. I posted this here, as I suspect the bugs might be related.)
[Bug c/120327] New: OpenMP, triangular collapsed for-loop, maybe-uninitialized warning
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.