This is an improvement to the design of internal function .ACCESS_WITH_SIZE.
Currently, the .ACCESS_WITH_SIZE is designed as:
ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE, CLASS_OF_SIZE,
TYPE_OF_SIZE, ACCESS_MODE, TYPE_SIZE_UNIT for element)
which returns the REF_TO_OBJ same as the 1st argument;
1st argument REF_TO_OBJ: The reference to the object;
2nd argument REF_TO_SIZE: The reference to the size of the object,
3rd argument CLASS_OF_SIZE: The size referenced by the REF_TO_SIZE represents
0: the number of bytes.
1: the number of the elements of the object type;
4th argument TYPE_OF_SIZE: A constant 0 with its TYPE being the same as the
TYPE of the object referenced by REF_TO_SIZE
5th argument ACCESS_MODE:
-1: Unknown access semantics
0: none
1: read_only
2: write_only
3: read_write
6th argument: The TYPE_SIZE_UNIT of the element TYPE of the FAM when 3rd
argument is 1. NULL when 3rd argument is 0.
Among the 6 arguments:
A. The 3rd argument CLASS_OF_SIZE is not needed. If the REF_TO_SIZE represents
the number of bytes, simply pass 1 to the TYPE_SIZE_UNIT argument.
B. The 4th and the 5th arguments can be combined into 1 argument, whose TYPE
represents the TYPE_OF_SIZE, and the constant value represents the
ACCESS_MODE.
As a result, the new design of the .ACCESS_WITH_SIZE is:
ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE,
TYPE_OF_SIZE + ACCESS_MODE, TYPE_SIZE_UNIT for element)
which returns the REF_TO_OBJ same as the 1st argument;
1st argument REF_TO_OBJ: The reference to the object;
2nd argument REF_TO_SIZE: The reference to the size of the object,
3rd argument TYPE_OF_SIZE + ACCESS_MODE: An integer constant with a pointer
TYPE.
The pointee TYPE of the pointer TYPE is the TYPE of the object referenced
by REF_TO_SIZE.
The integer constant value represents the ACCESS_MODE:
0: none
1: read_only
2: write_only
3: read_write
4th argument: The TYPE_SIZE_UNIT of the element TYPE of the array.
gcc/c-family/ChangeLog:
* c-ubsan.cc (get_bound_from_access_with_size): Adjust the position
of the arguments per the new design.
gcc/c/ChangeLog:
* c-typeck.cc (build_access_with_size_for_counted_by): Update comments.
Adjust the arguments per the new design.
gcc/ChangeLog:
* internal-fn.cc (expand_ACCESS_WITH_SIZE): Update comments.
* internal-fn.def (ACCESS_WITH_SIZE): Update comments.
* tree-object-size.cc (access_with_size_object_size): Update comments.
Adjust the arguments per the new design.
return NULL_TREE;
tree ref_to_size = CALL_EXPR_ARG (call, 1);
- unsigned int class_of_size = TREE_INT_CST_LOW (CALL_EXPR_ARG (call, 2));
- tree type = TREE_TYPE (CALL_EXPR_ARG (call, 3));
+ tree type = TREE_TYPE (TREE_TYPE (CALL_EXPR_ARG (call, 2)));
tree size = fold_build2 (MEM_REF, type, unshare_expr (ref_to_size),
build_int_cst (ptr_type_node, 0));
/* If size is negative value, treat it as zero. */
build_zero_cst (type), size);
}
- /* Only when class_of_size is 1, i.e, the number of the elements of
- the object type, return the size. */
- if (class_of_size != 1)
- return NULL_TREE;
- else
- size = fold_convert (sizetype, size);
+ size = fold_convert (sizetype, size);
return size;
}
to:
- (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, 1, (TYPE_OF_SIZE)0, -1,
+ (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
TYPE_SIZE_UNIT for element)
NOTE: The return type of this function is the POINTER type pointing
The type of the first argument of this function is a POINTER type
to the original flexible array type.
- The 4th argument of the call is a constant 0 with the TYPE of the
- object pointed by COUNTED_BY_REF.
+ The 3rd argument of the call is a constant 0 with the pointer TYPE whose
+ pointee type is the TYPE of the object pointed by COUNTED_BY_REF.
- The 6th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
- of the FAM.
+ The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
+ of the array.
*/
static tree
= c_fully_fold (array_to_pointer_conversion (loc, ref), false, NULL);
tree second_param
= c_fully_fold (counted_by_ref, false, NULL);
+ tree third_param = build_int_cst (build_pointer_type (counted_by_type), 0);
tree call
= build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE,
- result_type, 6,
+ result_type, 4,
first_param,
second_param,
- build_int_cst (integer_type_node, 1),
- build_int_cst (counted_by_type, 0),
- build_int_cst (integer_type_node, -1),
+ third_param,
element_size);
+
/* Wrap the call with an INDIRECT_REF with the flexible array type. */
call = build1 (INDIRECT_REF, TREE_TYPE (ref), call);
SET_EXPR_LOCATION (call, loc);
}
/* Expand the IFN_ACCESS_WITH_SIZE function:
- ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE, CLASS_OF_SIZE,
- TYPE_OF_SIZE, ACCESS_MODE, TYPE_SIZE_UNIT for element)
+ ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE,
+ TYPE_OF_SIZE + ACCESS_MODE, TYPE_SIZE_UNIT for element)
which returns the REF_TO_OBJ same as the 1st argument;
1st argument REF_TO_OBJ: The reference to the object;
2nd argument REF_TO_SIZE: The reference to the size of the object,
- 3rd argument CLASS_OF_SIZE: The size referenced by the REF_TO_SIZE represents
- 0: the number of bytes.
- 1: the number of the elements of the object type;
- 4th argument TYPE_OF_SIZE: A constant 0 with its TYPE being the same as the
- TYPE of the object referenced by REF_TO_SIZE
- 5th argument ACCESS_MODE:
- -1: Unknown access semantics
- 0: none
- 1: read_only
- 2: write_only
- 3: read_write
- 6th argument: The TYPE_SIZE_UNIT of the element TYPE of the FAM when the
- 3rd argument is 1; NULL when the 3rd argument is 0.
+ 3rd argument TYPE_OF_SIZE + ACCESS_MODE: An integer constant with a pointer
+ TYPE.
+ The pointee TYPE of the pointer TYPE is the TYPE of the object referenced
+ by REF_TO_SIZE.
+ The integer constant value represents the ACCESS_MODE:
+ 0: none
+ 1: read_only
+ 2: write_only
+ 3: read_write
+
+ 4th argument: The TYPE_SIZE_UNIT of the element TYPE of the array.
Both the return type and the type of the first argument of this
function have been converted from the incomplete array type to
/* A function to associate the access size and access mode information
with the corresponding reference to an object. It only reads from the
- 2nd and the 6th arguments. */
+ 2nd and the 4th arguments. */
DEF_INTERNAL_FN (ACCESS_WITH_SIZE, ECF_PURE | ECF_LEAF | ECF_NOTHROW, NULL)
/* DIM_SIZE and DIM_POS return the size of a particular compute
/* Compute __builtin_object_size for a CALL to .ACCESS_WITH_SIZE,
OBJECT_SIZE_TYPE is the second argument from __builtin_object_size.
- The 2nd, 3rd, 4th and 6th parameters of the call determine the size of
+ The 2nd, 3rd, and 4th parameters of the call determine the size of
the CALL:
2nd argument REF_TO_SIZE: The reference to the size of the object,
- 3rd argument CLASS_OF_SIZE: The size referenced by the REF_TO_SIZE represents
- 0: the number of bytes;
- 1: the number of the elements of the object type;
- 4th argument TYPE_OF_SIZE: A constant 0 with its TYPE being the same as the
- TYPE of the object referenced by REF_TO_SIZE
- 6th argument: The TYPE_SIZE_UNIT of the element TYPE of the FAM when the
- 3rd argument is 1; NULL when the 3rd argument is 0. */
+ 3rd argument TYPE_OF_SIZE + ACCESS_MODE: An integer constant with a pointer
+ TYPE.
+ The pointee TYPE of this pointer TYPE is the TYPE of the object referenced
+ by REF_TO_SIZE.
+
+ 4th argument: The TYPE_SIZE_UNIT of the element TYPE of the array. */
static tree
access_with_size_object_size (const gcall *call, int object_size_type)
gcc_assert (gimple_call_internal_p (call, IFN_ACCESS_WITH_SIZE));
tree ref_to_size = gimple_call_arg (call, 1);
- unsigned int class_of_size = TREE_INT_CST_LOW (gimple_call_arg (call, 2));
- tree type = TREE_TYPE (gimple_call_arg (call, 3));
+ tree type = TREE_TYPE (TREE_TYPE (gimple_call_arg (call, 2)));
- /* The 6th argument is the TYPE_SIZE_UNIT for the element of the original
+ /* The 4th argument is the TYPE_SIZE_UNIT for the element of the original
flexible array. */
- tree element_size = gimple_call_arg (call, 5);
-
- gcc_assert ((class_of_size == 1 && element_size)
- || (class_of_size == 0 && !element_size));
+ tree element_size = gimple_call_arg (call, 3);
tree size = fold_build2 (MEM_REF, type, ref_to_size,
build_int_cst (ptr_type_node, 0));
build_zero_cst (type), size);
}
- if (class_of_size == 1)
- size = size_binop (MULT_EXPR,
- fold_convert (sizetype, size),
- fold_convert (sizetype, element_size));
- else
- size = fold_convert (sizetype, size);
+ size = size_binop (MULT_EXPR,
+ fold_convert (sizetype, size),
+ fold_convert (sizetype, element_size));
if (!todo)
todo = TODO_update_ssa_only_virtuals;