From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24661 invoked by alias); 6 Feb 2014 13:13:42 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24625 invoked by uid 48); 6 Feb 2014 13:13:39 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/60092] posix_memalign not recognized to derive alias and alignment info Date: Thu, 06 Feb 2014 13:13:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: alias, missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-02/txt/msg00589.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60092 --- Comment #6 from Jakub Jelinek --- (In reply to Marc Glisse from comment #4) > Hack: when the return value of posix_memalign is ignored, if the platform > supports it, replace with a call to aligned_alloc (C11), which has an easier > interface. The question is if posix_memalign is allowed to change errno. If it is, then making glibc contains say something like: extern int __REDIRECT_NTH (__posix_memalign_alias, (void ** __ptr, size_t __alignment, size_t __size), posix_memalign) __nonnull ((1)) __wur; extern void *__REDIRECT_NTH (__memalign_alias, (size_t __alignment, size_t __size), memalign) __attribute__ ((__malloc__, __alloc_size__ (2))); __extern_inline int posix_memalign (void **__ptr, size_t __alignment, size_t __size) { if (__builtin_constant_p (__alignment)) { if (__alignment == 0 || __alignment & (__alignment - 1)) != 0 || __alignment % sizeof (void *)) return EINVAL; void *__res = __memalign_alias (__alignment, __size); if (__res == NULL) return ENOMEM; *__ptr = __res; return 0; } return __posix_memalign_alias (__ptr, __alignment, __size); } But looking at glibc sources, even posix_memalign actually changes errno. Tbe problem with this inline version is that user aliasing bugs will trigger people more often, and that some hack will need to be find out for the EINVAL and ENOMEM values (because, stdlib.h is not supposed to include errno.h I guess, so it would need to be some __EINVAL/__ENOMEM value determined by configure or something).