https://gcc.gnu.org/g:bd817e6c6de038e82ff7d278ae52345313b22d7f
commit r15-9958-gbd817e6c6de038e82ff7d278ae52345313b22d7f Author: Jakub Jelinek <ja...@redhat.com> Date: Fri Jul 11 13:43:58 2025 +0200 testsuite: Add testcase for already fixed PR [PR120954] This was a regression introduced by r16-1893 (and its backports) for C++, though for C it had false positive warning for years. Fixed by r16-2000 (and its backports). 2025-07-11 Jakub Jelinek <ja...@redhat.com> PR c++/120954 * c-c++-common/Warray-bounds-11.c: New test. (cherry picked from commit 9eea49825ebb607f4b67de48c9cba1f85e005932) Diff: --- gcc/testsuite/c-c++-common/Warray-bounds-11.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gcc/testsuite/c-c++-common/Warray-bounds-11.c b/gcc/testsuite/c-c++-common/Warray-bounds-11.c new file mode 100644 index 000000000000..686a94d27615 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Warray-bounds-11.c @@ -0,0 +1,21 @@ +/* PR c++/120954 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds=2" } */ + +static const int a[32] = { 11, 12, 13, 14, 15 }; +static const int b[32] = { 21, 22, 23, 24, 25 }; +static const int c[32] = { 31, 32, 33, 34, 35 }; +static const int d[32] = { 111, 112, 113, 114, 115 }; +static const int e[32] = { 121, 122, 123, 124, 125 }; +static const int f[32] = { 131, 132, 133, 134, 135 }; + +int +foo (int x, int y) +{ + int r = 0; + if (x >= 0 && x < 32) + r = (y >= 4 ? (y >= 0x65 ? a : b ) : c)[x]; + else if (x >= 0x100 && x < 0x120) + r = (y >= 4 ? (y >= 0x65 ? d : e ) : f)[x - 0x100]; + return r; +}