https://gcc.gnu.org/g:4a11605bc1f649ccfd2244e97553b838782d006a

commit r17-6013-g4a11605bc1f649ccfd2244e97553b838782d006a
Author: Arsen Arsenović <[email protected]>
Date:   Fri Nov 6 14:14:00 2026 +0000

    libgomp/plugin-gcn: fix kernarg allocation size
    
    We accidentally allocated kernargs without sufficient room for the
    target variable table.
    
    libgomp/ChangeLog:
    
            * plugin/plugin-gcn.c (allocate_session_kernargs): Use
            'kernargs_size' instead of 'sizeof (struct kernargs)'.
            * testsuite/libgomp.c-c++-common/kernel-launch-many-vars.c: New 
test.

Diff:
---
 libgomp/plugin/plugin-gcn.c                        |  2 +-
 .../libgomp.c-c++-common/kernel-launch-many-vars.c | 32 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index bfce10ef0426..ca006c977dc5 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -1927,7 +1927,7 @@ allocate_session_kernargs (struct gomp_offload_session 
*session,
       /* Cache miss.  */
       void *ka_addr;
       hsa_status_t status = hsa_fns.hsa_memory_allocate_fn
-       (agent->kernarg_region, sizeof (struct kernargs), &ka_addr);
+       (agent->kernarg_region, kernargs_size, &ka_addr);
       if (status != HSA_STATUS_SUCCESS)
        hsa_fatal ("Could not allocate memory for GCN kernel arguments", 
status);
 
diff --git a/libgomp/testsuite/libgomp.c-c++-common/kernel-launch-many-vars.c 
b/libgomp/testsuite/libgomp.c-c++-common/kernel-launch-many-vars.c
new file mode 100644
index 000000000000..e07055bf4930
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/kernel-launch-many-vars.c
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+/* { dg-require-effective-target offload_device } */
+
+/* Ensure that we correctly perform target offloading even if we have many
+   variables to map.  */
+
+#define C(x, y) x##y
+#define R4(x) C(x, 1), C(x, 2), C(x, 3), C(x, 4)
+#define R16(x) R4(C(x, 1)), R4(C(x, 2)), R4(C(x, 3)), R4(C(x, 4))
+#define R64(x) R16(C(x, 1)), R16(C(x, 2)), R16(C(x, 3)), R16(C(x, 4))
+#define R256(x) R64(C(x, 1)), R64(C(x, 2)), R64(C(x, 3)), R64(C(x, 4))
+#define R1024(x) R256(C(x, 1)), R256(C(x, 2)), R256(C(x, 3)), R256(C(x, 4))
+#define R4096(x) R1024(C(x, 1)), R1024(C(x, 2)), R1024(C(x, 3)), R1024(C(x, 4))
+
+#define P4(x) C(x, 1) = C(x, 2) = C(x, 3) = C(x, 4)
+#define P16(x) R4(C(x, 1)) = R4(C(x, 2)) = R4(C(x, 3)) = R4(C(x, 4))
+#define P64(x) R16(C(x, 1)) = R16(C(x, 2)) = R16(C(x, 3)) = R16(C(x, 4))
+#define P256(x) R64(C(x, 1)) = R64(C(x, 2)) = R64(C(x, 3)) = R64(C(x, 4))
+#define P1024(x) R256(C(x, 1)) = R256(C(x, 2)) = R256(C(x, 3)) = R256(C(x, 4))
+#define P4096(x) R1024(C(x, 1)) = R1024(C(x, 2)) = R1024(C(x, 3)) = R1024(C(x, 
4))
+
+static int R4096(x);
+
+int
+main ()
+{
+#pragma omp target map(tofrom: R4096(x))
+  {
+    volatile int v;
+    P4096(x) = v;
+  }
+}

Reply via email to