From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hallvard B Furuseth To: gcc-gnats@gcc.gnu.org Cc: h.b.furuseth@usit.uio.no Subject: c/3414: Inaccurate documentation of __attribute__((malloc)) Date: Mon, 25 Jun 2001 13:36:00 -0000 Message-id: X-SW-Source: 2001-06/msg01057.html List-Id: >Number: 3414 >Category: c >Synopsis: Inaccurate documentation of __attribute__((malloc)) >Confidential: no >Severity: non-critical >Priority: low >Responsible: unassigned >State: open >Class: doc-bug >Submitter-Id: net >Arrival-Date: Mon Jun 25 13:36:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Hallvard B Furuseth >Release: 3.0 >Organization: >Environment: System: SunOS bombur.uio.no 5.8 Generic_108528-03 sun4u sparc SUNW,Ultra-5_10 Architecture: sun4 host: sparc-sun-solaris2.8 build: sparc-sun-solaris2.8 target: sparc-sun-solaris2.8 configured with: ./configure --quiet --enable-version-specific-runtime-libs --prefix=/usit/bombur/hbf --program-suffix=-3.0 >Description: From @item malloc, @node Function Attributes: "The `malloc' attribute is used to tell the compiler that a function may be treated as if it were the malloc function." The compiler could assume several things about that; e.g. that the return value will be aligned for any data type. However, the rest of the paragraph is: "The compiler assumes that calls to malloc result in a pointers that cannot alias anything. This will often improve optimization." Is this the *only* assumption __attribute__((malloc)) causes? Incidentally, it also assumes that the program uses malloc correctly - here is a malloc which _can_ alias something: free(x = malloc(10)); if (x == (y = malloc(10))) { ... } (BTW, typo: "a pointers" should be "a pointer". >How-To-Repeat: >Fix: I'm guessing that you mean something like this, but I have not checked. Sorry if my English is a bit clumsy: The @code{malloc} attribute is used to tell the compiler that a function returns a pointer which cannot alias anything (or a null pointer), i.e. i behaves like the @code{malloc} function. This will often improve optimization. Note that this may break programs that incorrectly uses the value of such a pointer after it has been invalidated (in the case of malloced pointers by calling @code{free()}, even if the pointer is not dereferenced. >Release-Note: >Audit-Trail: >Unformatted: