[committed] openmp: omp_alloc(0, ...) should return NULL.

Jakub Jelinek jakub@redhat.com
Sat May 30 12:05:09 GMT 2020


Hi!

The language committee decided that there is no reason to follow malloc
size 0 behavior and we can just offer a single choice of what will be done.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2020-05-30  Jakub Jelinek  <jakub@redhat.com>

	* allocator.c (omp_alloc): For size == 0, return NULL early.

	* testsuite/libgomp.c-c++-common/alloc-4.c: New test.

--- libgomp/allocator.c.jj	2020-05-19 14:06:49.289061481 +0200
+++ libgomp/allocator.c	2020-05-29 13:12:43.778359480 +0200
@@ -201,6 +201,9 @@ omp_alloc (size_t size, omp_allocator_ha
   size_t alignment, new_size;
   void *ptr, *ret;
 
+  if (__builtin_expect (size == 0, 0))
+    return NULL;
+
 retry:
   if (allocator == omp_null_allocator)
     {
--- libgomp/testsuite/libgomp.c-c++-common/alloc-4.c.jj	2020-05-29 13:18:01.537684832 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/alloc-4.c	2020-05-29 13:21:29.804620958 +0200
@@ -0,0 +1,25 @@
+#include <omp.h>
+#include <stdlib.h>
+
+const omp_alloctrait_t traits[]
+= { { omp_atk_pool_size, 1 },
+    { omp_atk_fallback, omp_atv_abort_fb } };
+
+int
+main ()
+{
+  omp_allocator_handle_t a;
+
+  if (omp_alloc (0, omp_null_allocator) != NULL)
+    abort ();
+  a = omp_init_allocator (omp_default_mem_space, 2, traits);
+  if (a != omp_null_allocator)
+    {
+      if (omp_alloc (0, a) != NULL
+	  || omp_alloc (0, a) != NULL
+	  || omp_alloc (0, a) != NULL)
+	abort ();
+      omp_destroy_allocator (a);
+    }
+  return 0;
+}

	Jakub



More information about the Gcc-patches mailing list