https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111017
Bug ID: 111017 Summary: [OpenMP] Wrong code with non-rectangular loop nest Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: openmp, wrong-code Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: jakub at gcc dot gnu.org Target Milestone: --- At a glance, the following looks fine to me - but it fails with UBSAN as follows: test.c:10:15: runtime error: index -42 out of bounds for type 'int [1024]' test.c:10:8: runtime error: index -42 out of bounds for type 'int [1024]' ================================================================= ==619433==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7f2942e01060 at pc 0x000000401856 bp 0x7f29415fecb0 sp 0x7f29415feca8 READ of size 4 at 0x7f2942e01060 thread T1 test.c:10:22: runtime error: index -4210096 out of bounds for type 'int [1024]' #define DIM 32 #define N (DIM*DIM) int main() { int a[N] = {}, b[N] = {}, c[N]; #pragma omp parallel for collapse(2) for (int i = 0; i < DIM; i++) { for (int j = (i*DIM); j < (i*DIM + DIM); j++) { c[j] = a[j] + b[j]; } } } Longer version using 'target teams loop', which segfault here (w/o offloading configured + w/o UBSAN): https://github.com/SOLLVE/sollve_vv/blob/master/tests/5.0/teams_loop/test_target_teams_loop_collapse.c