This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/3414: Inaccurate documentation of __attribute__((malloc))
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c/3414: Inaccurate documentation of __attribute__((malloc))
- From: Hallvard B Furuseth <h dot b dot furuseth at usit dot uio dot no>
- Date: Mon, 25 Jun 2001 22:33:53 +0200
- Cc: h dot b dot furuseth at usit dot uio dot no
>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: