This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for c/3414 (clarify malloc attribute)
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 4 Jan 2004 20:38:38 +0000 (UTC)
- Subject: Patch for c/3414 (clarify malloc attribute)
This patch addresses PR c/3414 by clarifying the documentation of the
malloc attribute. It is silent about whether realloc has the required
property while telling users how they can determine whether their own
realloc-type functions have the property. It passes "make info" and
"make dvi". Applied to mainline.
2004-01-04 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/3414
* doc/extend.texi: Clarify definition of malloc attribute.
--- GCC.orig/gcc/doc/extend.texi 2003-12-19 11:55:22.000000000 +0000
+++ GCC/gcc/doc/extend.texi 2004-01-04 20:27:59.000000000 +0000
@@ -1,4 +1,4 @@
-@c Copyright (C) 1988,1989,1992,1993,1994,1996,1998,1999,2000,2001,2002, 2003
+@c Copyright (C) 1988,1989,1992,1993,1994,1996,1998,1999,2000,2001,2002,2003,2004
@c Free Software Foundation, Inc.
@c This is part of the GCC manual.
@c For copying conditions, see the file gcc.texi.
@@ -2355,9 +2355,14 @@
@item malloc
@cindex @code{malloc} attribute
The @code{malloc} attribute is used to tell the compiler that a function
-may be treated as if it were the malloc function. The compiler assumes
-that calls to malloc result in pointers that cannot alias anything.
+may be treated as if any non-@code{NULL} pointer it returns cannot
+alias any other pointer valid when the function returns.
This will often improve optimization.
+Standard functions with this property include @code{malloc} and
+@code{calloc}. @code{realloc}-like functions have this property as
+long as the old pointer is never referred to (including comparing it
+to the new pointer) after the function returns a non-@code{NULL}
+value.
@item alias ("@var{target}")
@cindex @code{alias} attribute
--
Joseph S. Myers
jsm@polyomino.org.uk