* [committed] openmp: Add alloc_align attribute to omp_aligned_*alloc and testcase for omp_realloc
@ 2021-10-01 8:59 Jakub Jelinek
2021-10-01 9:32 ` [Patch] Add/update libgomp.fortran/alloc-*.f90 [Re: [committed] openmp: Add alloc_align attribute to omp_aligned_*alloc and testcase for omp_realloc] Tobias Burnus
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2021-10-01 8:59 UTC (permalink / raw)
To: gcc-patches; +Cc: Tobias Burnus
Hi!
This patch adds alloc_align attribute to omp_aligned_{,c}alloc so that if
the first argument is constant, GCC can assume requested alignment.
Additionally, it adds testsuite coverage for omp_realloc which I haven't
managed to write in the patch from yesterday.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
2021-10-01 Jakub Jelinek <jakub@redhat.com>
* omp.h.in (omp_aligned_alloc, omp_aligned_calloc): Add
__alloc_align__ (1) attribute.
* testsuite/libgomp.c-c++-common/alloc-9.c: New test.
--- libgomp/omp.h.in.jj 2021-09-30 09:29:56.738900869 +0200
+++ libgomp/omp.h.in 2021-09-30 10:49:33.853333699 +0200
@@ -306,7 +306,7 @@ extern void *omp_aligned_alloc (__SIZE_T
omp_allocator_handle_t
__GOMP_DEFAULT_NULL_ALLOCATOR)
__GOMP_NOTHROW __attribute__((__malloc__, __malloc__ (omp_free),
- __alloc_size__ (2)));
+ __alloc_size__ (2), __alloc_align__ (1)));
extern void *omp_calloc (__SIZE_TYPE__, __SIZE_TYPE__,
omp_allocator_handle_t __GOMP_DEFAULT_NULL_ALLOCATOR)
__GOMP_NOTHROW __attribute__((__malloc__, __malloc__ (omp_free),
@@ -315,7 +315,7 @@ extern void *omp_aligned_calloc (__SIZE_
omp_allocator_handle_t
__GOMP_DEFAULT_NULL_ALLOCATOR)
__GOMP_NOTHROW __attribute__((__malloc__, __malloc__ (omp_free),
- __alloc_size__ (2, 3)));
+ __alloc_size__ (2, 3), __alloc_align__ (1)));
extern void *omp_realloc (void *, __SIZE_TYPE__,
omp_allocator_handle_t __GOMP_DEFAULT_NULL_ALLOCATOR,
omp_allocator_handle_t __GOMP_DEFAULT_NULL_ALLOCATOR)
--- libgomp/testsuite/libgomp.c-c++-common/alloc-9.c.jj 2021-09-30 13:06:28.794494653 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/alloc-9.c 2021-09-30 15:26:42.717931994 +0200
@@ -0,0 +1,271 @@
+#include <omp.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+const omp_alloctrait_t traits2[]
+= { { omp_atk_alignment, 16 },
+ { omp_atk_sync_hint, omp_atv_default },
+ { omp_atk_access, omp_atv_default },
+ { omp_atk_pool_size, 1024 },
+ { omp_atk_fallback, omp_atv_default_mem_fb },
+ { omp_atk_partition, omp_atv_environment } };
+omp_alloctrait_t traits3[]
+= { { omp_atk_sync_hint, omp_atv_uncontended },
+ { omp_atk_alignment, 32 },
+ { omp_atk_access, omp_atv_all },
+ { omp_atk_pool_size, 512 },
+ { omp_atk_fallback, omp_atv_allocator_fb },
+ { omp_atk_fb_data, 0 },
+ { omp_atk_partition, omp_atv_default } };
+const omp_alloctrait_t traits4[]
+= { { omp_atk_alignment, 128 },
+ { omp_atk_pool_size, 1024 },
+ { omp_atk_fallback, omp_atv_null_fb } };
+
+int
+main ()
+{
+ int *volatile p = (int *) omp_alloc (3 * sizeof (int), omp_default_mem_alloc);
+ int *volatile q;
+ int *volatile r;
+ omp_alloctrait_t traits[3]
+ = { { omp_atk_alignment, 64 },
+ { omp_atk_fallback, omp_atv_null_fb },
+ { omp_atk_pool_size, 4096 } };
+ omp_alloctrait_t traits5[2]
+ = { { omp_atk_fallback, omp_atv_null_fb },
+ { omp_atk_pool_size, 4096 } };
+ omp_allocator_handle_t a, a2;
+
+ if ((((uintptr_t) p) % __alignof (int)) != 0)
+ abort ();
+ p[0] = 1;
+ p[1] = 2;
+ p[2] = 3;
+ p = (int *) omp_realloc (p, 4 * sizeof (int), omp_default_mem_alloc, omp_default_mem_alloc);
+ if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] != 1 || p[1] != 2 || p[2] != 3)
+ abort ();
+ p[0] = 4;
+ p[1] = 5;
+ p[2] = 6;
+ p[3] = 7;
+ p = (int *) omp_realloc (p, 2 * sizeof (int), omp_default_mem_alloc, omp_default_mem_alloc);
+ if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] != 4 || p[1] != 5)
+ abort ();
+ p[0] = 8;
+ p[1] = 9;
+ if (omp_realloc (p, 0, omp_null_allocator, omp_default_mem_alloc) != NULL)
+ abort ();
+ p = (int *) omp_realloc (NULL, 2 * sizeof (int), omp_default_mem_alloc, omp_null_allocator);
+ if ((((uintptr_t) p) % __alignof (int)) != 0)
+ abort ();
+ p[0] = 1;
+ p[1] = 2;
+ p = (int *) omp_realloc (p, 5 * sizeof (int), omp_default_mem_alloc, omp_default_mem_alloc);
+ if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] != 1 || p[1] != 2)
+ abort ();
+ p[0] = 3;
+ p[1] = 4;
+ p[2] = 5;
+ p[3] = 6;
+ p[4] = 7;
+ omp_free (p, omp_null_allocator);
+ omp_set_default_allocator (omp_default_mem_alloc);
+ if (omp_realloc (NULL, 0, omp_null_allocator, omp_null_allocator) != NULL)
+ abort ();
+ p = (int *) omp_alloc (sizeof (int), omp_null_allocator);
+ if ((((uintptr_t) p) % __alignof (int)) != 0)
+ abort ();
+ p[0] = 3;
+ p = (int *) omp_realloc (p, 3 * sizeof (int), omp_null_allocator, omp_null_allocator);
+ if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] != 3)
+ abort ();
+ p[0] = 4;
+ p[1] = 5;
+ p[2] = 6;
+ if (omp_realloc (p, 0, omp_null_allocator, omp_get_default_allocator ()) != NULL)
+ abort ();
+ a = omp_init_allocator (omp_default_mem_space, 3, traits);
+ if (a == omp_null_allocator)
+ abort ();
+ p = (int *) omp_alloc (sizeof (int), a);
+ if ((((uintptr_t) p) % 64) != 0)
+ abort ();
+ p[0] = 7;
+ p = (int *) omp_realloc (p, 3072, a, a);
+ if ((((uintptr_t) p) % 64) != 0 || p[0] != 7)
+ abort ();
+ p[0] = 1;
+ p[3071 / sizeof (int)] = 2;
+ q = (int *) omp_alloc (sizeof (int), a);
+ if ((((uintptr_t) q) % 64) != 0)
+ abort ();
+ q[0] = 8;
+ if (omp_realloc (q, 3072, a, a) != NULL)
+ abort ();
+ omp_free (p, a);
+ omp_free (q, a);
+ p = (int *) omp_alloc (sizeof (int), a);
+ p[0] = 42;
+ p = (int *) omp_realloc (p, 3072, a, a);
+ if (p[0] != 42)
+ abort ();
+ p[0] = 3;
+ p[3071 / sizeof (int)] = 4;
+ omp_realloc (p, 0, omp_null_allocator, omp_null_allocator);
+ omp_set_default_allocator (a);
+ if (omp_get_default_allocator () != a)
+ abort ();
+ p = (int *) omp_alloc (31, omp_null_allocator);
+ if (p == NULL)
+ abort ();
+ p = (int *) omp_realloc (p, 3072, omp_null_allocator, omp_null_allocator);
+ if (p == NULL)
+ abort ();
+ q = (int *) omp_alloc (sizeof (int), omp_null_allocator);
+ if (q == NULL)
+ abort ();
+ if (omp_realloc (q, 3072, omp_null_allocator, omp_null_allocator) != NULL)
+ abort ();
+ omp_free (p, a);
+ omp_free (q, a);
+ omp_destroy_allocator (a);
+
+ a = omp_init_allocator (omp_default_mem_space, 2, traits5);
+ if (a == omp_null_allocator)
+ abort ();
+ omp_set_default_allocator (a);
+ if (omp_get_default_allocator () != a)
+ abort ();
+ p = (int *) omp_alloc (3071, omp_null_allocator);
+ if (p == NULL)
+ abort ();
+ p = (int *) omp_realloc (p, 3072, omp_null_allocator, omp_null_allocator);
+ if (p == NULL)
+ abort ();
+ q = (int *) omp_alloc (sizeof (int), omp_null_allocator);
+ if (q == NULL)
+ abort ();
+ if (omp_realloc (q, 3072, omp_null_allocator, omp_null_allocator) != NULL)
+ abort ();
+ omp_free (p, a);
+ omp_free (q, a);
+ omp_destroy_allocator (a);
+
+ a = omp_init_allocator (omp_default_mem_space,
+ sizeof (traits2) / sizeof (traits2[0]),
+ traits2);
+ if (a == omp_null_allocator)
+ abort ();
+ if (traits3[5].key != omp_atk_fb_data)
+ abort ();
+ traits3[5].value = (uintptr_t) a;
+ a2 = omp_init_allocator (omp_default_mem_space,
+ sizeof (traits3) / sizeof (traits3[0]),
+ traits3);
+ if (a2 == omp_null_allocator)
+ abort ();
+ p = (int *) omp_alloc (sizeof (int), a2);
+ if ((((uintptr_t) p) % 32) != 0)
+ abort ();
+ p[0] = 84;
+ p = (int *) omp_realloc (p, 380, a2, a2);
+ if ((((uintptr_t) p) % 32) != 0 || p[0] != 84)
+ abort ();
+ p[0] = 5;
+ p[379 / sizeof (int)] = 6;
+ q = (int *) omp_alloc (sizeof (int), a2);
+ if ((((uintptr_t) q) % 32) != 0)
+ abort ();
+ q[0] = 42;
+ q = (int *) omp_realloc (q, 768, a2, a2);
+ if ((((uintptr_t) q) % 16) != 0 || q[0] != 42)
+ abort ();
+ q[0] = 7;
+ q[767 / sizeof (int)] = 8;
+ r = (int *) omp_realloc (NULL, 512, a2, omp_null_allocator);
+ if ((((uintptr_t) r) % __alignof (int)) != 0)
+ abort ();
+ r[0] = 9;
+ r[511 / sizeof (int)] = 10;
+ omp_free (p, omp_null_allocator);
+ omp_free (q, a2);
+ omp_free (r, omp_null_allocator);
+ p = (int *) omp_alloc (sizeof (int), a2);
+ if ((((uintptr_t) p) % 32) != 0)
+ abort ();
+ p[0] = 85;
+ p = (int *) omp_realloc (p, 420, a, a2);
+ if ((((uintptr_t) p) % 16) != 0 || p[0] != 85)
+ abort ();
+ p[0] = 5;
+ p[419 / sizeof (int)] = 6;
+ q = (int *) omp_alloc (sizeof (int), a);
+ if ((((uintptr_t) q) % 16) != 0)
+ abort ();
+ q[0] = 43;
+ q = (int *) omp_realloc (q, 420, a2, a);
+ if ((((uintptr_t) q) % 32) != 0 || q[0] != 43)
+ abort ();
+ q[0] = 44;
+ q[419 / sizeof (int)] = 8;
+ q = (int *) omp_realloc (q, 768, a2, a2);
+ if ((((uintptr_t) q) % 16) != 0 || q[0] != 44)
+ abort ();
+ q[0] = 7;
+ q[767 / sizeof (int)] = 8;
+ omp_free (p, omp_null_allocator);
+ omp_free (q, a2);
+ omp_destroy_allocator (a2);
+ omp_destroy_allocator (a);
+
+ a = omp_init_allocator (omp_default_mem_space,
+ sizeof (traits4) / sizeof (traits4[0]),
+ traits4);
+ if (a == omp_null_allocator)
+ abort ();
+ if (traits3[5].key != omp_atk_fb_data)
+ abort ();
+ traits3[5].value = (uintptr_t) a;
+ a2 = omp_init_allocator (omp_default_mem_space,
+ sizeof (traits3) / sizeof (traits3[0]),
+ traits3);
+ if (a2 == omp_null_allocator)
+ abort ();
+ omp_set_default_allocator (a2);
+#ifdef __cplusplus
+ p = static_cast <int *> (omp_realloc (NULL, 420));
+#else
+ p = (int *) omp_realloc (NULL, 420, omp_null_allocator, omp_null_allocator);
+#endif
+ if ((((uintptr_t) p) % 32) != 0)
+ abort ();
+ p[0] = 5;
+ p[419 / sizeof (int)] = 6;
+ q = (int *) omp_realloc (NULL, sizeof (int), omp_null_allocator, omp_null_allocator);
+ if ((((uintptr_t) q) % 32) != 0)
+ abort ();
+ q[0] = 99;
+ q = (int *) omp_realloc (q, 700, omp_null_allocator, omp_null_allocator);
+ if ((((uintptr_t) q) % 128) != 0 || q[0] != 99)
+ abort ();
+ q[0] = 7;
+ q[699 / sizeof (int)] = 8;
+ if (omp_realloc (NULL, 768, omp_null_allocator, omp_null_allocator) != NULL)
+ abort ();
+#ifdef __cplusplus
+ omp_free (p);
+ if (omp_realloc (q, 0) != NULL)
+ abort ();
+ omp_free (NULL);
+#else
+ omp_free (p, omp_null_allocator);
+ if (omp_realloc (q, 0, omp_null_allocator, omp_null_allocator) != NULL)
+ abort ();
+ omp_free (NULL, omp_null_allocator);
+#endif
+ omp_free (NULL, omp_null_allocator);
+ omp_destroy_allocator (a2);
+ omp_destroy_allocator (a);
+ return 0;
+}
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Patch] Add/update libgomp.fortran/alloc-*.f90 [Re: [committed] openmp: Add alloc_align attribute to omp_aligned_*alloc and testcase for omp_realloc]
2021-10-01 8:59 [committed] openmp: Add alloc_align attribute to omp_aligned_*alloc and testcase for omp_realloc Jakub Jelinek
@ 2021-10-01 9:32 ` Tobias Burnus
2021-10-01 9:42 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Tobias Burnus @ 2021-10-01 9:32 UTC (permalink / raw)
To: Jakub Jelinek, gcc-patches, fortran; +Cc: Tobias Burnus
[-- Attachment #1: Type: text/plain, Size: 611 bytes --]
... and attached the Fortran version of the C/C++ testcase.
OK?
Tobias
On 01.10.21 10:59, Jakub Jelinek wrote:
> 2021-10-01 Jakub Jelinek <jakub@redhat.com>
>
> * omp.h.in (omp_aligned_alloc, omp_aligned_calloc): Add
> __alloc_align__ (1) attribute.
> * testsuite/libgomp.c-c++-common/alloc-9.c: New test.
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: alloc-followup.diff --]
[-- Type: text/x-patch, Size: 14381 bytes --]
Add/update libgomp.fortran/alloc-*.f90
libgomp/ChangeLog:
* testsuite/libgomp.fortran/alloc-10.f90: Fix alignment check.
* testsuite/libgomp.fortran/alloc-7.f90: Fix array access.
* testsuite/libgomp.fortran/alloc-8.f90: Likewise.
* testsuite/libgomp.fortran/alloc-11.f90: New test for omp_realloc,
based on libgomp.c-c++-common/alloc-9.c.
libgomp/testsuite/libgomp.fortran/alloc-10.f90 | 4 +-
libgomp/testsuite/libgomp.fortran/alloc-11.f90 | 301 +++++++++++++++++++++++++
libgomp/testsuite/libgomp.fortran/alloc-7.f90 | 14 +-
libgomp/testsuite/libgomp.fortran/alloc-8.f90 | 2 +-
4 files changed, 311 insertions(+), 10 deletions(-)
diff --git a/libgomp/testsuite/libgomp.fortran/alloc-10.f90 b/libgomp/testsuite/libgomp.fortran/alloc-10.f90
index 060c16f312b..3eab8598dec 100644
--- a/libgomp/testsuite/libgomp.fortran/alloc-10.f90
+++ b/libgomp/testsuite/libgomp.fortran/alloc-10.f90
@@ -134,7 +134,7 @@ program main
ip(420 / c_sizeof (0)) = 6
q = omp_aligned_calloc (8_c_size_t, 24_c_size_t, 32_c_size_t, a2)
call c_f_pointer (q, iq, [768 / c_sizeof (0)])
- if (mod (TRANSFER (p, iptr), 16) /= 0) &
+ if (mod (TRANSFER (q, iptr), 16) /= 0) &
stop 18
do i = 1, 768 / c_sizeof (0)
if (iq(i) /= 0) &
@@ -144,7 +144,7 @@ program main
iq(768 / c_sizeof (0)) = 8
r = omp_aligned_calloc (8_c_size_t, 64_c_size_t, 8_c_size_t, a2)
call c_f_pointer (r, ir, [512 / c_sizeof (0)])
- if (mod (TRANSFER (p, iptr), 8) /= 0) &
+ if (mod (TRANSFER (r, iptr), 8) /= 0) &
stop 20
do i = 1, 512 / c_sizeof (0)
if (ir(i) /= 0) &
diff --git a/libgomp/testsuite/libgomp.fortran/alloc-11.f90 b/libgomp/testsuite/libgomp.fortran/alloc-11.f90
new file mode 100644
index 00000000000..22b4f92a336
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/alloc-11.f90
@@ -0,0 +1,301 @@
+! { dg-additional-sources alloc-7.c }
+! { dg-prune-output "command-line option '-fintrinsic-modules-path=.*' is valid for Fortran but not for C" }
+module m
+ use omp_lib
+ use iso_c_binding
+ implicit none
+
+ type (omp_alloctrait), parameter :: traits2(*) &
+ = [ omp_alloctrait (omp_atk_alignment, 16), &
+ omp_alloctrait (omp_atk_sync_hint, omp_atv_default), &
+ omp_alloctrait (omp_atk_access, omp_atv_default), &
+ omp_alloctrait (omp_atk_pool_size, 1024), &
+ omp_alloctrait (omp_atk_fallback, omp_atv_default_mem_fb), &
+ omp_alloctrait (omp_atk_partition, omp_atv_environment)]
+ type (omp_alloctrait) :: traits3(7) &
+ = [ omp_alloctrait (omp_atk_sync_hint, omp_atv_uncontended), &
+ omp_alloctrait (omp_atk_alignment, 32), &
+ omp_alloctrait (omp_atk_access, omp_atv_all), &
+ omp_alloctrait (omp_atk_pool_size, 512), &
+ omp_alloctrait (omp_atk_fallback, omp_atv_allocator_fb), &
+ omp_alloctrait (omp_atk_fb_data, 0), &
+ omp_alloctrait (omp_atk_partition, omp_atv_default)]
+
+ type (omp_alloctrait), parameter :: traits4(*) &
+ = [ omp_alloctrait (omp_atk_alignment, 128), &
+ omp_alloctrait (omp_atk_pool_size, 1024), &
+ omp_alloctrait (omp_atk_fallback, omp_atv_null_fb)]
+
+ interface
+ integer(c_int) function get__alignof_int () bind(C)
+ import :: c_int
+ end
+ end interface
+end module m
+
+program main
+ use m
+ implicit none (external, type)
+ type(c_ptr) :: p, q, r
+ integer, pointer, contiguous :: ip(:), iq(:), ir(:)
+ type (omp_alloctrait) :: traits(3)
+ type (omp_alloctrait) :: traits5(2)
+ integer (omp_allocator_handle_kind) :: a, a2
+ integer (c_ptrdiff_t) :: iptr
+
+ traits = [ omp_alloctrait (omp_atk_alignment, 64), &
+ omp_alloctrait (omp_atk_fallback, omp_atv_null_fb), &
+ omp_alloctrait (omp_atk_pool_size, 4096)]
+ traits5 = [ omp_alloctrait (omp_atk_fallback, omp_atv_null_fb), &
+ omp_alloctrait (omp_atk_pool_size, 4096)]
+
+ p = omp_alloc (3 * c_sizeof (0), omp_default_mem_alloc)
+ call c_f_pointer (p, ip, [3])
+ if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0) &
+ stop 1
+ ip(1) = 1
+ ip(2) = 2
+ ip(3) = 3
+ p = omp_realloc (p, 4 * c_sizeof (0), omp_default_mem_alloc, omp_default_mem_alloc)
+ call c_f_pointer (p, ip, [4])
+ if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0 &
+ .or. ip(1) /= 1 .or. ip(2) /= 2 .or. ip(3) /= 3) &
+ stop 2
+ ip(1) = 4
+ ip(2) = 5
+ ip(3) = 6
+ ip(4) = 7
+ p = omp_realloc (p, 2 * c_sizeof (0), omp_default_mem_alloc, omp_default_mem_alloc)
+ call c_f_pointer (p, ip, [2])
+ if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0 &
+ .or. ip(1) /= 4 .or. ip(2) /= 5) &
+ stop 3
+ ip(1) = 8
+ ip(2) = 9
+ if (c_associated (omp_realloc (p, 0_c_size_t, omp_null_allocator, omp_default_mem_alloc))) &
+ stop 4
+ p = omp_realloc (c_null_ptr, 2 * c_sizeof (0), omp_default_mem_alloc, omp_null_allocator)
+ call c_f_pointer (p, ip, [2])
+ if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0) &
+ stop 5
+ ip(1) = 1
+ ip(2) = 2
+ p = omp_realloc (p, 5 * c_sizeof (0), omp_default_mem_alloc, omp_default_mem_alloc)
+ call c_f_pointer (p, ip, [5])
+ if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0 &
+ .or. ip(1) /= 1 .or. ip(2) /= 2) &
+ stop 6
+ ip(1) = 3
+ ip(2) = 4
+ ip(3) = 5
+ ip(4) = 6
+ ip(5) = 7
+ call omp_free (p, omp_null_allocator)
+ call omp_set_default_allocator (omp_default_mem_alloc)
+ if (c_associated (omp_realloc (c_null_ptr, 0_c_size_t, omp_null_allocator, omp_null_allocator))) &
+ stop 7
+ p = omp_alloc (c_sizeof (0), omp_null_allocator)
+ call c_f_pointer (p, ip, [1])
+ if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0) &
+ stop 8
+ ip(1) = 3
+ p = omp_realloc (p, 3 * c_sizeof (0), omp_null_allocator, omp_null_allocator)
+ call c_f_pointer (p, ip, [3])
+ if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0 &
+ .or. ip(1) /= 3) &
+ stop 9
+ ip(1) = 4
+ ip(2) = 5
+ ip(3) = 6
+ if (c_associated (omp_realloc (p, 0_c_size_t, omp_null_allocator, omp_get_default_allocator ()))) &
+ stop 10
+ a = omp_init_allocator (omp_default_mem_space, 3, traits)
+ if (a == omp_null_allocator) &
+ stop 11
+ p = omp_alloc (c_sizeof (0), a)
+ call c_f_pointer (p, ip, [1])
+ if (mod (TRANSFER (p, iptr), 64) /= 0) &
+ stop 12
+ ip(1) = 7
+ p = omp_realloc (p, 3072_c_size_t, a, a)
+ call c_f_pointer (p, ip, [3072 / c_sizeof (0)])
+ if (mod (TRANSFER (p, iptr), 64) /= 0 &
+ .or. ip(1) /= 7) &
+ stop 13
+ ip(1) = 1
+ ip(3072 / c_sizeof (0)) = 2
+ q = omp_alloc (c_sizeof (0), a)
+ call c_f_pointer (q, iq, [1])
+ if (mod (TRANSFER (q, iptr), 64) /= 0) &
+ stop 14
+ iq(1) = 8
+ if (c_associated (omp_realloc (q, 3072_c_size_t, a, a))) &
+ stop 15
+ call omp_free (p, a)
+ call omp_free (q, a)
+ p = omp_alloc (c_sizeof (0), a)
+ call c_f_pointer (p, ip, [1])
+ ip(1) = 42
+ p = omp_realloc (p, 3072_c_size_t, a, a)
+ call c_f_pointer (p, ip, [3072 / c_sizeof (0)])
+ if (ip(1) /= 42) &
+ stop 16
+ ip(1) = 3
+ ip(3072 / c_sizeof (0)) = 4
+ ! ignore return value
+ r = omp_realloc (p, 0_c_size_t, omp_null_allocator, omp_null_allocator)
+ call omp_set_default_allocator (a)
+ if (omp_get_default_allocator () /= a) &
+ stop 17
+ p = omp_alloc (31_c_size_t, omp_null_allocator)
+ if (.not. c_associated (p)) &
+ stop 18
+ p = omp_realloc (p, 3072_c_size_t, omp_null_allocator, omp_null_allocator)
+ if (.not. c_associated (p)) &
+ stop 19
+ q = omp_alloc (c_sizeof (0), omp_null_allocator)
+ if (.not. c_associated (q)) &
+ stop 20
+ if (c_associated (omp_realloc (q, 3072_c_size_t, omp_null_allocator, omp_null_allocator))) &
+ stop 21
+ call omp_free (p, a)
+ call omp_free (q, a)
+ call omp_destroy_allocator (a)
+
+ a = omp_init_allocator (omp_default_mem_space, 2, traits5)
+ if (a == omp_null_allocator) &
+ stop 22
+ call omp_set_default_allocator (a)
+ if (omp_get_default_allocator () /= a) &
+ stop 23
+ p = omp_alloc (3071_c_size_t, omp_null_allocator)
+ if (.not. c_associated (p)) &
+ stop 24
+ p = omp_realloc (p, 3072_c_size_t, omp_null_allocator, omp_null_allocator)
+ if (.not. c_associated (p)) &
+ stop 25
+ q = omp_alloc (c_sizeof (0), omp_null_allocator)
+ if (.not. c_associated (q)) &
+ stop 26
+ if (c_associated (omp_realloc (q, 3072_c_size_t, omp_null_allocator, omp_null_allocator))) &
+ stop 27
+ call omp_free (p, a)
+ call omp_free (q, a)
+ call omp_destroy_allocator (a)
+
+ a = omp_init_allocator (omp_default_mem_space, size (traits2), traits2)
+ if (a == omp_null_allocator) &
+ stop 28
+ if (traits3(6)%key /= omp_atk_fb_data) &
+ stop 29
+ traits3(6)%value = a
+ a2 = omp_init_allocator (omp_default_mem_space, size (traits3), traits3)
+ if (a2 == omp_null_allocator) &
+ stop 30
+ p = omp_alloc (c_sizeof (0), a2)
+ call c_f_pointer (p, ip, [1])
+ if (mod (TRANSFER (p, iptr), 32) /= 0) &
+ stop 31
+ ip(1) = 84
+ p = omp_realloc (p, 380_c_size_t, a2, a2)
+ call c_f_pointer (p, ip, [380 / c_sizeof (0)])
+ if (mod (TRANSFER (p, iptr), 32) /= 0 &
+ .or. ip(1) /= 84) &
+ stop 32
+ ip(1) = 5
+ ip(380 / c_sizeof (0)) = 6
+ q = omp_alloc (c_sizeof (0), a2)
+ call c_f_pointer (q, iq, [1])
+ if (mod (TRANSFER (q, iptr), 32) /= 0) &
+ stop 33
+ iq(1) = 42
+ q = omp_realloc (q, 768_c_size_t, a2, a2)
+ call c_f_pointer (q, iq, [768 / c_sizeof (0)])
+ if (mod (TRANSFER (q, iptr), 16) /= 0 &
+ .or. iq(1) /= 42) &
+ stop 34
+ iq(1) = 7
+ iq(768 / c_sizeof (0)) = 8
+ r = omp_realloc (c_null_ptr, 512_c_size_t, a2, omp_null_allocator)
+ call c_f_pointer (r, ir, [512 / c_sizeof (0)])
+ if (mod (TRANSFER (r, iptr), get__alignof_int ()) /= 0) &
+ stop 35
+ ir(1) = 9
+ ir(512 / c_sizeof (0)) = 10
+ call omp_free (p, omp_null_allocator)
+ call omp_free (q, a2)
+ call omp_free (r, omp_null_allocator)
+ p = omp_alloc (c_sizeof (0), a2)
+ call c_f_pointer (p, ip, [1])
+ if (mod (TRANSFER (p, iptr), 32) /= 0) &
+ stop 36
+ ip(1) = 85
+ p = omp_realloc (p, 420_c_size_t, a, a2)
+ call c_f_pointer (p, ip, [420 / c_sizeof (0)])
+ if (mod (TRANSFER (p, iptr), 16) /= 0 &
+ .or. ip(1) /= 85) &
+ stop 37
+ ip(1) = 5
+ ip(420 / c_sizeof (0)) = 6
+ q = omp_alloc (c_sizeof (0), a)
+ call c_f_pointer (q, iq, [1])
+ if (mod (TRANSFER (q, iptr), 16) /= 0) &
+ stop 38
+ iq(1) = 43
+ q = omp_realloc (q, 420_c_size_t, a2, a)
+ call c_f_pointer (q, iq, [420 / c_sizeof (0)])
+ if (mod (TRANSFER (q, iptr), 32) /= 0 &
+ .or. iq(1) /= 43) &
+ stop 39
+ iq(1) = 44
+ iq(420 / c_sizeof (0)) = 8
+ q = omp_realloc (q, 768_c_size_t, a2, a2)
+ call c_f_pointer (q, iq, [768 / c_sizeof (0)])
+ if (mod (TRANSFER (q, iptr), 16) /= 0 &
+ .or. iq(1) /= 44) &
+ stop 40
+ iq(1) = 7
+ iq(768 / c_sizeof (0)) = 8
+ call omp_free (p, omp_null_allocator)
+ call omp_free (q, a2)
+ call omp_destroy_allocator (a2)
+ call omp_destroy_allocator (a)
+
+ a = omp_init_allocator (omp_default_mem_space, size (traits4), traits4)
+ if (a == omp_null_allocator) &
+ stop 41
+ if (traits3(6)%key /= omp_atk_fb_data) &
+ stop 1
+ traits3(6)%value = a
+ a2 = omp_init_allocator (omp_default_mem_space, size (traits3), traits3)
+ if (a2 == omp_null_allocator) &
+ stop 42
+ call omp_set_default_allocator (a2)
+ p = omp_realloc (c_null_ptr, 420_c_size_t, omp_null_allocator, omp_null_allocator)
+ call c_f_pointer (p, ip, [420 / c_sizeof (0)])
+ if (mod (TRANSFER (p, iptr), 32) /= 0) &
+ stop 43
+ ip(1) = 5
+ ip(420 / c_sizeof (0)) = 6
+ q = omp_realloc (c_null_ptr, c_sizeof (0), omp_null_allocator, omp_null_allocator)
+ call c_f_pointer (q, iq, [1])
+ if (mod (TRANSFER (q, iptr), 32) /= 0) &
+ stop 44
+ iq(1) = 99
+ q = omp_realloc (q, 700_c_size_t, omp_null_allocator, omp_null_allocator)
+ call c_f_pointer (q, iq, [700 / c_sizeof (0)])
+ if (mod (TRANSFER (q, iptr), 128) /= 0 &
+ .or. iq(1) /= 99) &
+ stop 45
+ iq(1) = 7
+ iq(700 / c_sizeof (0)) = 8
+ if (c_associated (omp_realloc (c_null_ptr, 768_c_size_t, omp_null_allocator, omp_null_allocator))) &
+ stop 46
+ call omp_free (p, omp_null_allocator)
+ if (c_associated (omp_realloc (q, 0_c_size_t, omp_null_allocator, omp_null_allocator))) &
+ stop 47
+ call omp_free (c_null_ptr, omp_null_allocator)
+ call omp_free (c_null_ptr, omp_null_allocator)
+ call omp_destroy_allocator (a2)
+ call omp_destroy_allocator (a)
+end program main
diff --git a/libgomp/testsuite/libgomp.fortran/alloc-7.f90 b/libgomp/testsuite/libgomp.fortran/alloc-7.f90
index d8c7eee8c25..57ecd839c26 100644
--- a/libgomp/testsuite/libgomp.fortran/alloc-7.f90
+++ b/libgomp/testsuite/libgomp.fortran/alloc-7.f90
@@ -50,17 +50,17 @@ program main
call c_f_pointer (p, ip, [3])
if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0) &
stop 1
- ip(0) = 1
- ip(1) = 2
- ip(2) = 3
+ ip(1) = 1
+ ip(2) = 2
+ ip(3) = 3
call omp_free (p, omp_default_mem_alloc)
p = omp_aligned_alloc (2 * c_sizeof (0), 2 * c_sizeof (0), omp_default_mem_alloc)
call c_f_pointer (p, ip, [2])
if (mod (TRANSFER (p, iptr), 2 * c_sizeof (0)) /= 0) &
stop 2
- ip(0) = 1
- ip(1) = 2
+ ip(1) = 1
+ ip(2) = 2
call omp_free (p, omp_null_allocator)
call omp_set_default_allocator (omp_default_mem_alloc)
@@ -68,7 +68,7 @@ program main
call c_f_pointer (p, ip, [2])
if (mod (TRANSFER (p, iptr), get__alignof_int ()) /= 0) &
stop 3
- ip(0) = 3
+ ip(1) = 3
call omp_free (p, omp_get_default_allocator ())
a = omp_init_allocator (omp_default_mem_space, 3, traits)
@@ -155,7 +155,7 @@ program main
call c_f_pointer (p, ip, [420/c_sizeof (0)])
if (mod (TRANSFER (p, iptr), 32) /= 0) &
stop 18
- ip(0) = 5
+ ip(1) = 5
ip(420 / c_sizeof (0)) = 6
q = omp_aligned_alloc (64_c_size_t, 768_c_size_t, omp_null_allocator)
diff --git a/libgomp/testsuite/libgomp.fortran/alloc-8.f90 b/libgomp/testsuite/libgomp.fortran/alloc-8.f90
index 4bff4d6ea29..059c368781e 100644
--- a/libgomp/testsuite/libgomp.fortran/alloc-8.f90
+++ b/libgomp/testsuite/libgomp.fortran/alloc-8.f90
@@ -41,7 +41,7 @@ program main
call omp_free (p, a)
large_sz = NOT (0_c_size_t)
large_sz = ISHFT (large_sz, -1)
- large_sz = large_sz + 1
+ large_sz = large_sz + 1 ! signed integer overflow
if (c_associated (omp_calloc (2_c_size_t, large_sz, a))) &
stop 7
if (c_associated (omp_calloc (large_sz, 1024_c_size_t, a))) &
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch] Add/update libgomp.fortran/alloc-*.f90 [Re: [committed] openmp: Add alloc_align attribute to omp_aligned_*alloc and testcase for omp_realloc]
2021-10-01 9:32 ` [Patch] Add/update libgomp.fortran/alloc-*.f90 [Re: [committed] openmp: Add alloc_align attribute to omp_aligned_*alloc and testcase for omp_realloc] Tobias Burnus
@ 2021-10-01 9:42 ` Jakub Jelinek
0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2021-10-01 9:42 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches, fortran
On Fri, Oct 01, 2021 at 11:32:24AM +0200, Tobias Burnus wrote:
> libgomp/ChangeLog:
>
> * testsuite/libgomp.fortran/alloc-10.f90: Fix alignment check.
> * testsuite/libgomp.fortran/alloc-7.f90: Fix array access.
> * testsuite/libgomp.fortran/alloc-8.f90: Likewise.
> * testsuite/libgomp.fortran/alloc-11.f90: New test for omp_realloc,
> based on libgomp.c-c++-common/alloc-9.c.
>
> libgomp/testsuite/libgomp.fortran/alloc-10.f90 | 4 +-
> libgomp/testsuite/libgomp.fortran/alloc-11.f90 | 301 +++++++++++++++++++++++++
> libgomp/testsuite/libgomp.fortran/alloc-7.f90 | 14 +-
> libgomp/testsuite/libgomp.fortran/alloc-8.f90 | 2 +-
> 4 files changed, 311 insertions(+), 10 deletions(-)
LGTM.
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-01 9:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 8:59 [committed] openmp: Add alloc_align attribute to omp_aligned_*alloc and testcase for omp_realloc Jakub Jelinek
2021-10-01 9:32 ` [Patch] Add/update libgomp.fortran/alloc-*.f90 [Re: [committed] openmp: Add alloc_align attribute to omp_aligned_*alloc and testcase for omp_realloc] Tobias Burnus
2021-10-01 9:42 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).