This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gomp4 11/14] libgomp: avoid variable-length stack allocation in team.c
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Jakub Jelinek <jakub at redhat dot com>, Dmitry Melnik <dm at ispras dot ru>
- Date: Tue, 20 Oct 2015 21:34:33 +0300
- Subject: [gomp4 11/14] libgomp: avoid variable-length stack allocation in team.c
- Authentication-results: sourceware.org; auth=none
- References: <1445366076-16082-1-git-send-email-amonakov at ispras dot ru>
NVPTX does not support alloca or variable-length stack allocations, thus
heap allocation needs to be used instead. I've opted to make this a generic
change instead of guarding it with an #ifdef: libgomp usually leaves thread
stack size up to libc, so avoiding unbounded stack allocation makes sense.
* task.c (GOMP_task): Use a fixed-size on-stack buffer or a heap
allocation instead of a variable-size on-stack allocation.
---
libgomp/task.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/libgomp/task.c b/libgomp/task.c
index 74920d5..ffb7ed2 100644
--- a/libgomp/task.c
+++ b/libgomp/task.c
@@ -162,11 +162,16 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
thr->task = &task;
if (__builtin_expect (cpyfn != NULL, 0))
{
- char buf[arg_size + arg_align - 1];
+ long buf_size = arg_size + arg_align - 1;
+ char buf_fixed[2048], *buf = buf_fixed;
+ if (sizeof(buf_fixed) < buf_size)
+ buf = gomp_malloc (buf_size);
char *arg = (char *) (((uintptr_t) buf + arg_align - 1)
& ~(uintptr_t) (arg_align - 1));
cpyfn (arg, data);
fn (arg);
+ if (buf != buf_fixed)
+ free (buf);
}
else
fn (data);