aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAnthony Green <green@cygnus.com>1999-11-28 20:45:34 +0000
committerAnthony Green <green@gcc.gnu.org>1999-11-28 20:45:34 +0000
commit140592a0131cb2dc88d3f55b2671977f20c85be2 (patch)
tree64c16fe212dcb5f1d77505bd5b8e158441e8665e /gcc
parent8b4b9b7ad3d1bbc16516a5a73a6ba3c3c21d1822 (diff)
downloadgcc-140592a0131cb2dc88d3f55b2671977f20c85be2.zip
gcc-140592a0131cb2dc88d3f55b2671977f20c85be2.tar.gz
gcc-140592a0131cb2dc88d3f55b2671977f20c85be2.tar.bz2
tree.h (struct tree_decl): Add malloc_flag.
* tree.h (struct tree_decl): Add malloc_flag. (DECL_IS_MALLOC): Define. * c-common.c (attrs): Add A_MALLOC attribute. (init_attributes): Add this attribute to the table. (decl_attributes): Handle malloc attribute. * calls.c (special_function_p): Check for the malloc attribute. * extend.texi (Function Attributes): Document malloc attribute. From-SVN: r30689
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/c-common.c10
-rw-r--r--gcc/calls.c12
-rw-r--r--gcc/extend.texi14
-rw-r--r--gcc/tree.h6
5 files changed, 44 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f4f058e..109c834 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+1999-11-28 Anthony Green <green@cygnus.com>
+
+ * tree.h (struct tree_decl): Add malloc_flag.
+ (DECL_IS_MALLOC): Define.
+ * c-common.c (attrs): Add A_MALLOC attribute.
+ (init_attributes): Add this attribute to the table.
+ (decl_attributes): Handle malloc attribute.
+ * calls.c (special_function_p): Check for the malloc attribute.
+ * extend.texi (Function Attributes): Document malloc attribute.
+
Sun Nov 28 13:21:00 1999 Jeffrey A Law (law@cygnus.com)
* pa.md (reload shift-add patterns): Remove.
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 742eba0..10c1624 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -140,7 +140,7 @@ int skip_evaluation;
enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION,
A_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED,
- A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS};
+ A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS, A_MALLOC};
enum format_type { printf_format_type, scanf_format_type,
strftime_format_type };
@@ -481,6 +481,7 @@ init_attributes ()
add_attribute (A_ALIAS, "alias", 1, 1, 1);
add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1);
add_attribute (A_NO_CHECK_MEMORY_USAGE, "no_check_memory_usage", 0, 0, 1);
+ add_attribute (A_MALLOC, "malloc", 0, 0, 1);
}
/* Default implementation of valid_lang_attribute, below. By default, there
@@ -617,6 +618,13 @@ decl_attributes (node, attributes, prefix_attributes)
warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
break;
+ case A_MALLOC:
+ if (TREE_CODE (decl) == FUNCTION_DECL)
+ DECL_IS_MALLOC (decl) = 1;
+ else
+ warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
+ break;
+
case A_UNUSED:
if (is_type)
TREE_USED (type) = 1;
diff --git a/gcc/calls.c b/gcc/calls.c
index 48c0d5e..d880595 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -546,10 +546,14 @@ special_function_p (name, fndecl, returns_twice, is_longjmp,
{
*returns_twice = 0;
*is_longjmp = 0;
- *is_malloc = 0;
*may_be_alloca = 0;
- if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
+ /* The function decl may have the `malloc' attribute. */
+ *is_malloc = fndecl && DECL_IS_MALLOC (fndecl);
+
+ if (! is_malloc
+ && name != 0
+ && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
/* Exclude functions not at the file scope, or not `extern',
since they are not the magic functions we would otherwise
think they are. */
@@ -602,8 +606,8 @@ special_function_p (name, fndecl, returns_twice, is_longjmp,
else if (tname[0] == 'l' && tname[1] == 'o'
&& ! strcmp (tname, "longjmp"))
*is_longjmp = 1;
- /* XXX should have "malloc" attribute on functions instead
- of recognizing them by name. */
+ /* Do not add any more malloc-like functions to this list,
+ instead mark as malloc functions using the malloc attribute. */
else if (! strcmp (tname, "malloc")
|| ! strcmp (tname, "calloc")
|| ! strcmp (tname, "realloc")
diff --git a/gcc/extend.texi b/gcc/extend.texi
index 17f12c9..be217a3 100644
--- a/gcc/extend.texi
+++ b/gcc/extend.texi
@@ -1310,6 +1310,7 @@ hack ((union foo) x);
@cindex functions that never return
@cindex functions that have no side effects
@cindex functions in arbitrary sections
+@cindex functions that bahave like malloc
@cindex @code{volatile} applied to function
@cindex @code{const} applied to function
@cindex functions with @code{printf}, @code{scanf} or @code{strftime} style arguments
@@ -1323,10 +1324,10 @@ carefully.
The keyword @code{__attribute__} allows you to specify special
attributes when making a declaration. This keyword is followed by an
-attribute specification inside double parentheses. Nine attributes,
+attribute specification inside double parentheses. Ten attributes,
@code{noreturn}, @code{const}, @code{format},
-@code{no_instrument_function}, @code{section},
-@code{constructor}, @code{destructor}, @code{unused} and @code{weak} are
+@code{no_instrument_function}, @code{section}, @code{constructor},
+@code{destructor}, @code{unused}, @code{weak} and @code{malloc} are
currently defined for functions. Other attributes, including
@code{section} are supported for variables declarations (@pxref{Variable
Attributes}) and for types (@pxref{Type Attributes}).
@@ -1540,6 +1541,13 @@ also be used with non-function declarations. Weak symbols are supported
for ELF targets, and also for a.out targets when using the GNU assembler
and linker.
+@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 a pointers that cannot alias anything.
+This will often improve optimization.
+
@item alias ("target")
@cindex @code{alias} attribute
The @code{alias} attribute causes the declaration to be emitted as an
diff --git a/gcc/tree.h b/gcc/tree.h
index d805689..fcfa219 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1238,6 +1238,11 @@ struct tree_type
to redefine for any purpose whatever. */
#define DECL_BUILT_IN_NONANSI(NODE) ((NODE)->common.unsigned_flag)
+/* Nonzero in a FUNCTION_DECL means this function should be treated
+ as if it were a malloc, meaning it returns a pointer that is
+ not an alias. */
+#define DECL_IS_MALLOC(NODE) (DECL_CHECK (NODE)->decl.malloc_flag)
+
/* Nonzero in a FIELD_DECL means it is a bit field, and must be accessed
specially. */
#define DECL_BIT_FIELD(NODE) (DECL_CHECK (NODE)->decl.bit_field_flag)
@@ -1370,6 +1375,7 @@ struct tree_decl
unsigned no_instrument_function_entry_exit : 1;
unsigned no_check_memory_usage : 1;
unsigned comdat_flag : 1;
+ unsigned malloc_flag : 1;
/* For a FUNCTION_DECL, if inline, this is the size of frame needed.
If built-in, this is the code for which built-in function.