]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgomp/target.c: Fix buffer size for 'omp requires' diagnostic
authorTobias Burnus <tburnus@baylibre.com>
Thu, 19 Jun 2025 19:16:42 +0000 (21:16 +0200)
committerTobias Burnus <tburnus@baylibre.com>
Thu, 19 Jun 2025 19:16:42 +0000 (21:16 +0200)
One of the buffers that printed the list of set 'omp requires'
requirements missed the 'self' clause addition, being potentially
to short when all device-affecting clauses were passed. Solved it
by moving the sizeof(<string of all permitted values>" into a new
'#define' just above the associated gomp_requires_to_name function.

libgomp/ChangeLog:

* target.c (GOMP_REQUIRES_NAME_BUF_LEN): Define.
(GOMP_offload_register_ver, gomp_target_init): Use it for the
char buffer size.

libgomp/target.c

index a2a4a7299e588b678c1b9a8a0d7deab7ac55a976..cda092bd044cd357244970d8a1b149afa1bbad2c 100644 (file)
@@ -2641,6 +2641,10 @@ gomp_unload_image_from_device (struct gomp_device_descr *devicep,
     }
 }
 
+#define GOMP_REQUIRES_NAME_BUF_LEN \
+  sizeof ("unified_address, unified_shared_memory, " \
+         "self_maps, reverse_offload")
+
 static void
 gomp_requires_to_name (char *buf, size_t size, int requires_mask)
 {
@@ -2689,10 +2693,8 @@ GOMP_offload_register_ver (unsigned version, const void *host_table,
 
   if (omp_req && omp_requires_mask && omp_requires_mask != omp_req)
     {
-      char buf1[sizeof ("unified_address, unified_shared_memory, "
-                       "self_maps, reverse_offload")];
-      char buf2[sizeof ("unified_address, unified_shared_memory, "
-                       "self_maps, reverse_offload")];
+      char buf1[GOMP_REQUIRES_NAME_BUF_LEN];
+      char buf2[GOMP_REQUIRES_NAME_BUF_LEN];
       gomp_requires_to_name (buf2, sizeof (buf2),
                             omp_req != GOMP_REQUIRES_TARGET_USED
                             ? omp_req : omp_requires_mask);
@@ -5786,8 +5788,7 @@ gomp_target_init (void)
                    found = true;
                if (found)
                  {
-                   char buf[sizeof ("unified_address, unified_shared_memory, "
-                                    "reverse_offload")];
+                   char buf[GOMP_REQUIRES_NAME_BUF_LEN];
                    gomp_requires_to_name (buf, sizeof (buf), omp_req);
                    char *name = (char *) malloc (cur_len + 1);
                    memcpy (name, cur, cur_len);