aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-object-size.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/tree-object-size.c')
-rw-r--r--gcc/tree-object-size.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index 4f6b230..d925a6c 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -401,25 +401,28 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
/* Compute __builtin_object_size for CALL, which is a GIMPLE_CALL.
- Handles various allocation calls. OBJECT_SIZE_TYPE is the second
- argument from __builtin_object_size. If unknown, return
- unknown[object_size_type]. */
+ Handles calls to functions declared with attribute alloc_size.
+ OBJECT_SIZE_TYPE is the second argument from __builtin_object_size.
+ If unknown, return unknown[object_size_type]. */
static unsigned HOST_WIDE_INT
alloc_object_size (const gcall *call, int object_size_type)
{
- tree callee, bytes = NULL_TREE;
- tree alloc_size;
- int arg1 = -1, arg2 = -1;
-
gcc_assert (is_gimple_call (call));
- callee = gimple_call_fndecl (call);
- if (!callee)
+ tree calltype;
+ if (tree callfn = gimple_call_fndecl (call))
+ calltype = TREE_TYPE (callfn);
+ else
+ calltype = gimple_call_fntype (call);
+
+ if (!calltype)
return unknown[object_size_type];
- alloc_size = lookup_attribute ("alloc_size",
- TYPE_ATTRIBUTES (TREE_TYPE (callee)));
+ /* Set to positions of alloc_size arguments. */
+ int arg1 = -1, arg2 = -1;
+ tree alloc_size = lookup_attribute ("alloc_size",
+ TYPE_ATTRIBUTES (calltype));
if (alloc_size && TREE_VALUE (alloc_size))
{
tree p = TREE_VALUE (alloc_size);
@@ -429,19 +432,6 @@ alloc_object_size (const gcall *call, int object_size_type)
arg2 = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (p)))-1;
}
- if (DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
- switch (DECL_FUNCTION_CODE (callee))
- {
- case BUILT_IN_CALLOC:
- arg2 = 1;
- /* fall through */
- case BUILT_IN_MALLOC:
- CASE_BUILT_IN_ALLOCA:
- arg1 = 0;
- default:
- break;
- }
-
if (arg1 < 0 || arg1 >= (int)gimple_call_num_args (call)
|| TREE_CODE (gimple_call_arg (call, arg1)) != INTEGER_CST
|| (arg2 >= 0
@@ -449,6 +439,7 @@ alloc_object_size (const gcall *call, int object_size_type)
|| TREE_CODE (gimple_call_arg (call, arg2)) != INTEGER_CST)))
return unknown[object_size_type];
+ tree bytes = NULL_TREE;
if (arg2 >= 0)
bytes = size_binop (MULT_EXPR,
fold_convert (sizetype, gimple_call_arg (call, arg1)),