public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bugdal at aerifal dot cx" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug other/56955] documentation for attribute malloc contradicts itself Date: Tue, 20 May 2014 21:00:00 -0000 [thread overview] Message-ID: <bug-56955-4-OBVajvm1Ww@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-56955-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56955 --- Comment #10 from Rich Felker <bugdal at aerifal dot cx> --- I don't see how it's at all helpful for GCC to assume that memory obtained by __attribute__((__malloc__)) functions does not contain pointers to anything that existed before the call. This assumption only aids optimization in the case where a pointer residing in the obtained memory is used (e.g. dereferenced or compared with another pointer) before anything is stored to it. But with GCC's assumption, such use would be UB anyway and thus cannot occur in a correct program, so there's no sense in optimizing it. The alternative is much more reasonable: assume that a pointer residing in the obtained memory could alias any object whose address has already escaped (roughly, anything but automatic or static/internal-linkage objects whose addresses were not taken and passed to code the compiler can't see). This allows __attribute__((__malloc__)) to be applied to realloc-like functions as well as functions in third-party libraries which allocate non-opaque structures whose members may point to data that's also accessible via other paths. And as far as I can tell, it doesn't preclude any optimizations that could take place in a code path that doesn't invoke UB.
next prev parent reply other threads:[~2014-05-20 21:00 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-56955-4@http.gcc.gnu.org/bugzilla/> 2013-04-14 19:05 ` pinskia at gcc dot gnu.org 2013-04-14 19:47 ` sunfish at google dot com 2013-04-15 10:19 ` rguenth at gcc dot gnu.org 2013-04-15 14:53 ` sunfish at google dot com 2014-05-20 20:41 ` eggert at gnu dot org 2014-05-20 20:49 ` carlos at redhat dot com 2014-05-20 20:51 ` eggert at gnu dot org 2014-05-20 21:00 ` bugdal at aerifal dot cx [this message] 2014-05-21 0:31 ` eggert at gnu dot org 2014-05-21 1:26 ` sunfish at mozilla dot com 2014-05-21 4:22 ` eggert at gnu dot org 2014-05-21 12:09 ` rguenth at gcc dot gnu.org 2014-05-21 13:09 ` rguenth at gcc dot gnu.org 2014-05-21 14:33 ` sunfish at mozilla dot com 2014-05-21 15:14 ` eggert at gnu dot org 2014-05-22 14:14 ` eggert at gnu dot org 2014-05-23 10:11 ` rguenth at gcc dot gnu.org 2014-05-23 10:13 ` rguenth at gcc dot gnu.org
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=bug-56955-4-OBVajvm1Ww@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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: linkBe 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).