From patchwork Mon Oct 11 14:37:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 46106 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A26B3857C6B for ; Mon, 11 Oct 2021 14:38:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A26B3857C6B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633963098; bh=U/arz1kmmoIwgQZTkWxQ+28MT3iRQxivh+TQAgT59uM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=g/vuzCsoBRP1wytDEAlVjmHYkIlsjqqgWImbMonxyOJabw/T0bHIw0uFl8VZLnRk/ ibdNd2u0QRBGw7uOP2l++ld50V8RWBJOidOXUhGg2P4+e8na+NMb+BLyASOttLPda7 1OEyRJ3N1eiH4l2MMj3IIHt/HjoUK+yq/qp2TmfQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 23FCF3858006 for ; Mon, 11 Oct 2021 14:37:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 23FCF3858006 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-550-jIbhUb_fNtS0_bG0vDpAAA-1; Mon, 11 Oct 2021 10:37:44 -0400 X-MC-Unique: jIbhUb_fNtS0_bG0vDpAAA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1CBEBD520; Mon, 11 Oct 2021 14:37:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.109]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 665602C175; Mon, 11 Oct 2021 14:37:43 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 19BEbePG3941376 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 11 Oct 2021 16:37:40 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 19BEbd363941373; Mon, 11 Oct 2021 16:37:39 +0200 Date: Mon, 11 Oct 2021 16:37:39 +0200 To: gcc-patches@gcc.gnu.org Subject: [PATCH] libgomp: alloc* test fixes [PR102628, PR102668] Message-ID: <20211011143739.GX304296@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: Tobias Burnus Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 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 --- 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