https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118909
Bug ID: 118909 Summary: OpenMP reduction array is always allocated on stack, cause stack overflow with large array reduction. Product: gcc Version: 14.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgomp Assignee: unassigned at gcc dot gnu.org Reporter: z00823823 at outlook dot com CC: jakub at gcc dot gnu.org Target Milestone: --- Dear maintainer: The openmp always alloc the recution array on stack, cause stack overflow with large array. Here is an example: ```c #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { double *test = NULL; for (size_t size = 1;; size += 1024) { test = malloc(size * sizeof(double)); if (test == NULL) { printf("Failed to allocate %zu doubles\n", size); break; } printf("test: %p\n", test); #pragma omp parallel reduction(+ : test[0 : size]) num_threads(2) { test[0] = 0; #pragma omp critical { printf("frame address: %p\n", __builtin_frame_address(0)); printf("test: %p\n", test); } } free(test); printf("Allocated %zu doubles\n\n", size); } } ``` Run it for a while until it crashs. On my laptop it crashs with size > 1046529 (approximately 8MB). An online version can be found here: https://godbolt.org/z/v1o6K9a1b