Commit 140592a0 by Anthony Green Committed by Anthony Green

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
parent 8b4b9b7a
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) Sun Nov 28 13:21:00 1999 Jeffrey A Law (law@cygnus.com)
* pa.md (reload shift-add patterns): Remove. * pa.md (reload shift-add patterns): Remove.
......
...@@ -140,7 +140,7 @@ int skip_evaluation; ...@@ -140,7 +140,7 @@ int skip_evaluation;
enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION, 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_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED, 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, enum format_type { printf_format_type, scanf_format_type,
strftime_format_type }; strftime_format_type };
...@@ -481,6 +481,7 @@ init_attributes () ...@@ -481,6 +481,7 @@ init_attributes ()
add_attribute (A_ALIAS, "alias", 1, 1, 1); add_attribute (A_ALIAS, "alias", 1, 1, 1);
add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 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_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 /* Default implementation of valid_lang_attribute, below. By default, there
...@@ -617,6 +618,13 @@ decl_attributes (node, attributes, prefix_attributes) ...@@ -617,6 +618,13 @@ decl_attributes (node, attributes, prefix_attributes)
warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
break; 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: case A_UNUSED:
if (is_type) if (is_type)
TREE_USED (type) = 1; TREE_USED (type) = 1;
......
...@@ -546,10 +546,14 @@ special_function_p (name, fndecl, returns_twice, is_longjmp, ...@@ -546,10 +546,14 @@ special_function_p (name, fndecl, returns_twice, is_longjmp,
{ {
*returns_twice = 0; *returns_twice = 0;
*is_longjmp = 0; *is_longjmp = 0;
*is_malloc = 0;
*may_be_alloca = 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', /* Exclude functions not at the file scope, or not `extern',
since they are not the magic functions we would otherwise since they are not the magic functions we would otherwise
think they are. */ think they are. */
...@@ -602,8 +606,8 @@ special_function_p (name, fndecl, returns_twice, is_longjmp, ...@@ -602,8 +606,8 @@ special_function_p (name, fndecl, returns_twice, is_longjmp,
else if (tname[0] == 'l' && tname[1] == 'o' else if (tname[0] == 'l' && tname[1] == 'o'
&& ! strcmp (tname, "longjmp")) && ! strcmp (tname, "longjmp"))
*is_longjmp = 1; *is_longjmp = 1;
/* XXX should have "malloc" attribute on functions instead /* Do not add any more malloc-like functions to this list,
of recognizing them by name. */ instead mark as malloc functions using the malloc attribute. */
else if (! strcmp (tname, "malloc") else if (! strcmp (tname, "malloc")
|| ! strcmp (tname, "calloc") || ! strcmp (tname, "calloc")
|| ! strcmp (tname, "realloc") || ! strcmp (tname, "realloc")
......
...@@ -1310,6 +1310,7 @@ hack ((union foo) x); ...@@ -1310,6 +1310,7 @@ hack ((union foo) x);
@cindex functions that never return @cindex functions that never return
@cindex functions that have no side effects @cindex functions that have no side effects
@cindex functions in arbitrary sections @cindex functions in arbitrary sections
@cindex functions that bahave like malloc
@cindex @code{volatile} applied to function @cindex @code{volatile} applied to function
@cindex @code{const} applied to function @cindex @code{const} applied to function
@cindex functions with @code{printf}, @code{scanf} or @code{strftime} style arguments @cindex functions with @code{printf}, @code{scanf} or @code{strftime} style arguments
...@@ -1323,10 +1324,10 @@ carefully. ...@@ -1323,10 +1324,10 @@ carefully.
The keyword @code{__attribute__} allows you to specify special The keyword @code{__attribute__} allows you to specify special
attributes when making a declaration. This keyword is followed by an 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{noreturn}, @code{const}, @code{format},
@code{no_instrument_function}, @code{section}, @code{no_instrument_function}, @code{section}, @code{constructor},
@code{constructor}, @code{destructor}, @code{unused} and @code{weak} are @code{destructor}, @code{unused}, @code{weak} and @code{malloc} are
currently defined for functions. Other attributes, including currently defined for functions. Other attributes, including
@code{section} are supported for variables declarations (@pxref{Variable @code{section} are supported for variables declarations (@pxref{Variable
Attributes}) and for types (@pxref{Type Attributes}). Attributes}) and for types (@pxref{Type Attributes}).
...@@ -1540,6 +1541,13 @@ also be used with non-function declarations. Weak symbols are supported ...@@ -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 for ELF targets, and also for a.out targets when using the GNU assembler
and linker. 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") @item alias ("target")
@cindex @code{alias} attribute @cindex @code{alias} attribute
The @code{alias} attribute causes the declaration to be emitted as an The @code{alias} attribute causes the declaration to be emitted as an
......
...@@ -1238,6 +1238,11 @@ struct tree_type ...@@ -1238,6 +1238,11 @@ struct tree_type
to redefine for any purpose whatever. */ to redefine for any purpose whatever. */
#define DECL_BUILT_IN_NONANSI(NODE) ((NODE)->common.unsigned_flag) #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 /* Nonzero in a FIELD_DECL means it is a bit field, and must be accessed
specially. */ specially. */
#define DECL_BIT_FIELD(NODE) (DECL_CHECK (NODE)->decl.bit_field_flag) #define DECL_BIT_FIELD(NODE) (DECL_CHECK (NODE)->decl.bit_field_flag)
...@@ -1370,6 +1375,7 @@ struct tree_decl ...@@ -1370,6 +1375,7 @@ struct tree_decl
unsigned no_instrument_function_entry_exit : 1; unsigned no_instrument_function_entry_exit : 1;
unsigned no_check_memory_usage : 1; unsigned no_check_memory_usage : 1;
unsigned comdat_flag : 1; unsigned comdat_flag : 1;
unsigned malloc_flag : 1;
/* For a FUNCTION_DECL, if inline, this is the size of frame needed. /* 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. If built-in, this is the code for which built-in function.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment