public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-808] libgomp: Don't define GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC for _aligned_malloc [PR105745]
Date: Sat, 28 May 2022 06:33:08 +0000 (GMT)	[thread overview]
Message-ID: <20220528063308.A17C03864805@sourceware.org> (raw)

https://gcc.gnu.org/g:42fd2cd932384288914174f4af7974a060972bff

commit r13-808-g42fd2cd932384288914174f4af7974a060972bff
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat May 28 08:30:47 2022 +0200

    libgomp: Don't define GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC for _aligned_malloc [PR105745]
    
    since apparently _aligned_malloc requires freeing with _aligned_free and:
     /* Defined if gomp_aligned_alloc doesn't use fallback version
        and free can be used instead of gomp_aligned_free.  */
     #define GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC 1
    so the second condition isn't satisfied.  For uses inside of the OpenMP
    allocators we can still use _aligned_malloc but we need to call _aligned_free
    in gomp_aligned_free.
    
    2022-05-28  Jakub Jelinek  <jakub@redhat.com>
    
            PR libgomp/105745
            * libgomp.h (GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC): Don't define for
            defined(HAVE__ALIGNED_MALLOC) case.
            * alloc.c (gomp_aligned_alloc): Move defined(HAVE__ALIGNED_MALLOC)
            handling as last option before fallback instead of first.
            (gomp_aligned_free): For defined(HAVE__ALIGNED_MALLOC) call
            _aligned_free.

Diff:
---
 libgomp/alloc.c   | 8 +++++---
 libgomp/libgomp.h | 1 -
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libgomp/alloc.c b/libgomp/alloc.c
index a2a25befdf3..c1bd72db6f1 100644
--- a/libgomp/alloc.c
+++ b/libgomp/alloc.c
@@ -65,9 +65,7 @@ gomp_aligned_alloc (size_t al, size_t size)
   void *ret;
   if (al < sizeof (void *))
     al = sizeof (void *);
-#ifdef HAVE__ALIGNED_MALLOC
-  ret = _aligned_malloc (size, al);
-#elif defined(HAVE_MEMALIGN)
+#ifdef HAVE_MEMALIGN
   {
     extern void *memalign (size_t, size_t);
     ret = memalign (al, size);
@@ -83,6 +81,8 @@ gomp_aligned_alloc (size_t al, size_t size)
     else
       ret = NULL;
   }
+#elif defined(HAVE__ALIGNED_MALLOC)
+  ret = _aligned_malloc (size, al);
 #else
   ret = NULL;
   if ((al & (al - 1)) == 0 && size)
@@ -106,6 +106,8 @@ gomp_aligned_free (void *ptr)
 {
 #ifdef GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC
   free (ptr);
+#elif defined(HAVE__ALIGNED_MALLOC)
+  _aligned_free (ptr);
 #else
   if (ptr)
     free (((void **) ptr)[-1]);
diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index 74487e540d3..c243c4d6cf4 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -87,7 +87,6 @@ enum memmodel
 /* alloc.c */
 
 #if defined(HAVE_ALIGNED_ALLOC) \
-    || defined(HAVE__ALIGNED_MALLOC) \
     || defined(HAVE_POSIX_MEMALIGN) \
     || defined(HAVE_MEMALIGN)
 /* Defined if gomp_aligned_alloc doesn't use fallback version


                 reply	other threads:[~2022-05-28  6:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220528063308.A17C03864805@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).