libgomp: alloc* test fixes [PR102628, PR102668]

Message ID 20211011143739.GX304296@tucnak
State New
Headers show
Series
  • libgomp: alloc* test fixes [PR102628, PR102668]
Related show

Commit Message

Jeff Law via Gcc-patches Oct. 11, 2021, 2:37 p.m.
Hi!

As reported, the alloc-9.c test and alloc-{1,2,3}.F* and alloc-11.f90
tests fail on powerpc64-linux with -m32.
The reason why it fails just there is that malloc doesn't guarantee there
128-bit alignment (historically glibc guaranteed 2 * sizeof (void *)
alignment from malloc).

There are two separate issues.
One is a thinko on my side.
In this part of alloc-9.c test (copied to alloc-11.f90), we have
2 allocators, a with pool size 1024B and alignment 16B and default fallback
and a2 with pool size 512B and alignment 32B and a as fallback allocator.
We start at no allocations in both at line 194 and do:
  p = (int *) omp_alloc (sizeof (int), a2);
// This succeeds in a2 and needs 4+overhead bytes (which includes the 32B alignment)
  p = (int *) omp_realloc (p, 420, a, a2);
// This allocates 420 bytes+overhead in a, with 16B alignment and deallocates the above
  q = (int *) omp_alloc (sizeof (int), a);
// This allocates 4+overhead bytes in a, with 16B alignment
  q = (int *) omp_realloc (q, 420, a2, a);
// This allocates 420+overhead in a2 with 32B alignment
  q = (int *) omp_realloc (q, 768, a2, a2);
// This attempts to reallocate, but as there are elevated alignment
// requirements doesn't try to just realloc (even if it wanted to try that
// a2 is almost full, with 512-420-overhead bytes left in it), so it
// tries to alloc in a2, but there is no space left in the pool, falls
// back to a, which already has 420+overhead bytes allocated in it and
// 1024-420-overhead bytes left and so fails too and fails to default
// non-pool allocator that allocates it, but doesn't guarantee alignment
// higher than malloc guarantees.
// But, the test expected 16B alignment.

So, I've slightly lowered the allocation sizes in that part of the test
420->320 and 768 -> 568, so that the last test still fails to allocate
in a2 (568 > 512-320-overhead) but succeeds in a as fallback, which was
the intent of the test.

Another thing is that alloc-1.F90 seems to be transcription of
libgomp.c-c++-common/alloc-1.c into Fortran, but alloc-1.c had:
  q = (int *) omp_alloc (768, a2);
  if ((((uintptr_t) q) % 16) != 0)
    abort ();
  q[0] = 7;
  q[767 / sizeof (int)] = 8;
  r = (int *) omp_alloc (512, a2);
  if ((((uintptr_t) r) % __alignof (int)) != 0)
    abort ();
there but Fortran has:
        cq = omp_alloc (768_c_size_t, a2)
        if (mod (transfer (cq, intptr), 16_c_intptr_t) /= 0) stop 12
        call c_f_pointer (cq, q, [768 / c_sizeof (i)])
        q(1) = 7
        q(768 / c_sizeof (i)) = 8
        cr = omp_alloc (512_c_size_t, a2)
        if (mod (transfer (cr, intptr), 16_c_intptr_t) /= 0) stop 13
I'm changing the latter to 4_c_intptr_t because other spots in the
testcase do that, Fortran sadly doesn't have c_alignof, but strictly
speaking it isn't correct, __alignof (int) could be on some architectures
smaller than 4.
So probably alloc-1.F90 etc. should also have
! { dg-additional-sources alloc-7.c }
! { dg-prune-output "command-line option '-fintrinsic-modules-path=.*' is valid for Fortran but not for C" }
and use get__alignof_int.

Tested on powerpc64-linux with -m32 and -m64, will commit after full
bootstrap/regtest on x86_64-linux and i686-linux.

2021-10-11  Jakub Jelinek  <jakub@redhat.com>

	PR libgomp/102628
	PR libgomp/102668
	* testsuite/libgomp.c-c++-common/alloc-9.c (main): Decrease
	allocation sizes from 420 to 320 and from 768 to 568.
	* testsuite/libgomp.fortran/alloc-11.f90: Likewise.
	* testsuite/libgomp.fortran/alloc-1.F90: Change expected alignment
	for cr from 16 to 4.


	Jakub

Patch

--- libgomp/testsuite/libgomp.c-c++-common/alloc-9.c.jj	2021-10-01 10:32:03.030954011 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/alloc-9.c	2021-10-11 15:34:07.719040377 +0200
@@ -195,25 +195,25 @@  main ()
   if ((((uintptr_t) p) % 32) != 0)
     abort ();
   p[0] = 85;
-  p = (int *) omp_realloc (p, 420, a, a2);
+  p = (int *) omp_realloc (p, 320, a, a2);
   if ((((uintptr_t) p) % 16) != 0 || p[0] != 85)
     abort ();
   p[0] = 5;
-  p[419 / sizeof (int)] = 6;
+  p[319 / 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);
+  q = (int *) omp_realloc (q, 320, 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);
+  q[319 / sizeof (int)] = 8;
+  q = (int *) omp_realloc (q, 568, a2, a2);
   if ((((uintptr_t) q) % 16) != 0 || q[0] != 44)
     abort ();
   q[0] = 7;
-  q[767 / sizeof (int)] = 8;
+  q[567 / sizeof (int)] = 8;
   omp_free (p, omp_null_allocator);
   omp_free (q, a2);
   omp_destroy_allocator (a2);
--- libgomp/testsuite/libgomp.fortran/alloc-11.f90.jj	2021-10-04 10:16:11.013138378 +0200
+++ libgomp/testsuite/libgomp.fortran/alloc-11.f90	2021-10-11 15:51:08.938495429 +0200
@@ -230,32 +230,32 @@  program main
   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)])
+  p = omp_realloc (p, 320_c_size_t, a, a2)
+  call c_f_pointer (p, ip, [320 / 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
+  ip(320 / 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)])
+  q = omp_realloc (q, 320_c_size_t, a2, a)
+  call c_f_pointer (q, iq, [320 / 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)])
+  iq(320 / c_sizeof (0)) = 8
+  q = omp_realloc (q, 568_c_size_t, a2, a2)
+  call c_f_pointer (q, iq, [568 / 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
+  iq(568 / c_sizeof (0)) = 8
   call omp_free (p, omp_null_allocator)
   call omp_free (q, a2)
   call omp_destroy_allocator (a2)
--- libgomp/testsuite/libgomp.fortran/alloc-1.F90.jj	2021-08-19 11:42:27.000000000 +0200
+++ libgomp/testsuite/libgomp.fortran/alloc-1.F90	2021-10-11 16:03:11.113196021 +0200
@@ -117,7 +117,7 @@ 
         q(1) = 7
         q(768 / c_sizeof (i)) = 8
         cr = omp_alloc (512_c_size_t, a2)
-        if (mod (transfer (cr, intptr), 16_c_intptr_t) /= 0) stop 13
+        if (mod (transfer (cr, intptr), 4_c_intptr_t) /= 0) stop 13
         call c_f_pointer (cr, r, [512 / c_sizeof (i)])
         r(1) = 9
         r(512 / c_sizeof (i)) = 10