From: Jakub Jelinek <jakub@redhat.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: Alexander Monakov <amonakov@ispras.ru>,
David Malcolm <dmalcolm@redhat.com>,
gcc-patches@gcc.gnu.org, rguenther@suse.de, jakub@rehdat.com
Subject: Re: Implement removal of malloc/free pairs with NULL check
Date: Fri, 1 Nov 2024 13:52:44 +0100 [thread overview]
Message-ID: <ZyTPHKCmYoJmMQ42@tucnak> (raw)
In-Reply-To: <ZyTK5bizjtZIiKmi@kam.mff.cuni.cz>
On Fri, Nov 01, 2024 at 01:34:45PM +0100, Jan Hubicka wrote:
> >
> > malloc(SIZE_MAX / 2 + 1) does not succeed.
>
> Is malloc required to return NULL for block of half of address size or
> it is glibc behavior? Some time ago we was discussing possibility to
I don't see C23 saying that explicitly (though it e.g. says that
calloc is guaranteed to return NULL if nmemb * size computation wraps around),
but I think it is derived from the fact that on objects larger than half
of the address space one can't (at least on arches where
ptrdiff_t/size_t/void * have the same precision) perform correct pointer
arithmetics.
So, I think for calloc-like functions we need to be careful.
Or we could just use the ranger and do this only if the size is known
from value ranges not to be larger than half of the address space and
for calloc-like that there is no overflow?
> > Please reconsider? Why to we need to match LLVM here?
>
> Matching llvm is not really the goal. I implemented it since it is
> useful optimization for code that builds small objects on heap and
> compiler can optimize away their use. This is relatively common for
> code with higer abstraction penalty. My original motivation was
> std::vector and std::string consumers, but I think there is C code doing
> similar things, too, so it would be better to support both C and C++
> allocations.
Are most of such cases with variable sized allocations or fixed ones?
Jakub
next prev parent reply other threads:[~2024-11-01 12:52 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-31 16:06 Jan Hubicka
2024-10-31 17:22 ` David Malcolm
2024-11-01 10:41 ` Jan Hubicka
2024-11-01 11:11 ` Alexander Monakov
2024-11-01 12:34 ` Jan Hubicka
2024-11-01 12:52 ` Jakub Jelinek [this message]
2024-11-01 13:07 ` Jan Hubicka
2024-11-01 13:30 ` Jakub Jelinek
2024-11-02 12:31 ` Martin Uecker
2024-11-02 5:36 ` Sam James
2024-11-02 12:59 ` Alexander Monakov
2024-11-05 15:47 ` Jan Hubicka
2024-11-05 16:40 ` Jakub Jelinek
2024-11-05 17:15 ` Alexander Monakov
2024-11-05 17:22 ` Jakub Jelinek
2024-11-05 17:45 ` Alexander Monakov
2024-11-05 17:22 ` Jan Hubicka
2024-11-06 9:16 ` Richard Biener
2024-11-06 9:36 ` Jan Hubicka
2024-11-06 9:55 ` Richard Biener
2024-11-06 11:44 ` Alexander Monakov
2024-11-06 12:08 ` Jakub Jelinek
2024-11-06 17:48 ` Jakub Jelinek
2024-11-06 12:13 ` Richard Biener
2024-11-06 6:06 ` Sam James
2024-11-06 9:07 ` Richard Biener
2024-11-06 8:42 ` Sam James
2024-11-06 8:55 ` Andrew Pinski
2024-10-31 18:50 ` Andrew Pinski
2024-10-31 21:47 ` Sam James
2024-11-01 10:39 ` Jan Hubicka
2024-11-01 10:48 ` Jakub Jelinek
2024-11-01 12:24 ` Jan Hubicka
2024-11-06 8:55 ` Richard Biener
2024-11-06 9:03 ` Jakub Jelinek
2024-11-06 17:54 ` Jan Hubicka
2024-11-12 15:32 ` Jan Hubicka
2024-11-13 14:30 ` Richard Biener
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=ZyTPHKCmYoJmMQ42@tucnak \
--to=jakub@redhat.com \
--cc=amonakov@ispras.ru \
--cc=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=jakub@rehdat.com \
--cc=rguenther@suse.de \
/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).