https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106457
Bug ID: 106457 Summary: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: qinzhao at gcc dot gnu.org Target Milestone: --- During my work on updating array_at_struct_end_p with the new -fstrict-flex-array control, I noticed the following issue in the routine "array_at_struct_end_p" for the following small testing case: gcc/testsuite/g++.dg/debug/debug5.C // { dg-do compile } // { dg-require-effective-target alloca } int foo() { int a = 1; int b = 1; int e[a][b]; e[0][0] = 0; return e[a-1][b-1]; } when compiled with -O1 with the latest trunk gcc, when I used the gdb to debug it as: (gdb) break array_at_struct_end_p Breakpoint 1 at 0x1d4cdf8: file ../../latest_gcc/gcc/tree.cc, line 12690. (gdb) run Starting program: /home/opc/Work/GCC/build/gcc/cc1plus -quiet -iprefix /home/opc/Work/GCC/build/gcc/../lib/gcc/aarch64-unknown-linux-gnu/13.0.0/ -isystem /home/opc/Work/GCC/build/gcc/testsuite/g++/../../include -isystem /home/opc/Work/GCC/build/gcc/testsuite/g++/../../include-fixed -D_GNU_SOURCE t.C -quiet -dumpbase debug5.C -dumpbase-ext .C -mlittle-endian -mabi=lp64 -O1 -o debug5.s ... Breakpoint 1, array_at_struct_end_p (ref=0xfffff57a2b88) at ../../latest_gcc/gcc/tree.cc:12690 12690 if (TREE_CODE (ref) == ARRAY_REF ... (gdb) break 12784 Breakpoint 2 at 0x1d4d50c: file ../../latest_gcc/gcc/tree.cc, line 12784. (gdb) c Continuing. Breakpoint 2, array_at_struct_end_p (ref=0xfffff5771a70) at ../../latest_gcc/gcc/tree.cc:12784 12784 if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST (gdb) n 12786 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST) (gdb) n 12784 if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST (gdb) n 12787 return true; (gdb) n 12803 } it's obvious that the array reference " e[0][0]" is NOT an array at the end of a structure. the utility routine "array_at_struct_end_p" should NOT result true for such array reference. We should fix this issue in this routine.