diff options
author | mueller <mueller@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-25 21:18:15 +0000 |
---|---|---|
committer | mueller <mueller@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-25 21:18:15 +0000 |
commit | 4a29c97c96f0b3c1d102a225e4da92f2536547fe (patch) | |
tree | f9fc57995ca9957ad153664eb76e3a1d3b7c3a41 /gcc/c-common.c | |
parent | 9aad947b05a41449783d1cda7d14eb5f97277b55 (diff) | |
download | gcc-4a29c97c96f0b3c1d102a225e4da92f2536547fe.tar.gz |
2007-05-25 Dirk Mueller <dmueller@suse.de>
Marcus Meissner <meissner@suse.de>
* doc/extend.texi (alloc_size): New attribute.
* c-common.c (handle_alloc_size_attribute): New.
* tree-object-size.c (alloc_object_size): Use alloc_size
attribute, if available.
* testsuite/gcc.dg/attr-alloc_size.c: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125073 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index 48dcd5ddd0e..2edf807e91d 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -556,6 +556,7 @@ static tree handle_cleanup_attribute (tree *, tree, tree, int, bool *); static tree handle_warn_unused_result_attribute (tree *, tree, tree, int, bool *); static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *); +static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *); static void check_function_nonnull (tree, int, tree *); static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT); @@ -650,6 +651,8 @@ const struct attribute_spec c_common_attribute_table[] = handle_warn_unused_result_attribute }, { "sentinel", 0, 1, false, true, true, handle_sentinel_attribute }, + { "alloc_size", 1, 2, false, true, true, + handle_alloc_size_attribute }, { "cold", 0, 0, true, false, false, handle_cold_attribute }, { "hot", 0, 0, true, false, false, @@ -5579,6 +5582,37 @@ handle_malloc_attribute (tree *node, tree name, tree ARG_UNUSED (args), return NULL_TREE; } +/* Handle a "alloc_size" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_alloc_size_attribute (tree *node, tree ARG_UNUSED (name), tree args, + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + tree params = TYPE_ARG_TYPES (*node); + unsigned arg_count = 0; + + for (; TREE_CHAIN (params); params = TREE_CHAIN (params)) + arg_count ++; + + for (; args; args = TREE_CHAIN (args)) + { + tree position = TREE_VALUE (args); + + if (TREE_CODE (position) != INTEGER_CST + || TREE_INT_CST_HIGH (position) + || TREE_INT_CST_LOW (position) < 1 + || TREE_INT_CST_LOW (position) > arg_count ) + { + warning (OPT_Wattributes, + "alloc_size parameter outside range"); + *no_add_attrs = true; + return NULL_TREE; + } + } + return NULL_TREE; +} + /* Handle a "returns_twice" attribute; arguments as in struct attribute_spec.handler. */ |