cp_build_addr_expr (aref, tf_warning_or_error));
/* Remember this as a method reference, for later devirtualization. */
- aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr, idx);
+ aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr,
+ fold_convert (TREE_TYPE (instance_ptr), idx));
return aref;
}
static tree
resolve_virtual_fun_from_obj_type_ref (tree ref)
{
- tree obj_type = TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref));
+ tree obj_type = TREE_TYPE (OBJ_TYPE_REF_TOKEN (ref));
HOST_WIDE_INT index = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref));
tree fun = BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type)));
while (index)
&& TREE_CODE (TREE_OPERAND (function, 0)) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (TREE_OPERAND (function, 0), 0))
== FUNCTION_DECL)
- {
- function = build3 (OBJ_TYPE_REF, TREE_TYPE (function),
- TREE_OPERAND (function, 0),
- first_param, size_zero_node);
- }
+ function = build3 (OBJ_TYPE_REF, TREE_TYPE (function),
+ TREE_OPERAND (function, 0), first_param,
+ build_int_cst (TREE_TYPE (first_param), 0));
return function;
}
parms->quick_push (TREE_VALUE (method_params));
/* Build an obj_type_ref, with the correct cast for the method call. */
- t = build3 (OBJ_TYPE_REF, sender_cast, method, lookup_object, size_zero_node);
+ t = build3 (OBJ_TYPE_REF, sender_cast, method, lookup_object,
+ build_int_cst (TREE_TYPE (lookup_object), 0));
t = build_function_call_vec (loc, vNULL, t, parms, NULL);
vec_free (parms);
return t;
/* Build an obj_type_ref, with the correct cast for the method call. */
t = build3 (OBJ_TYPE_REF, sender_cast, method,
- lookup_object, size_zero_node);
+ lookup_object, build_int_cst (TREE_TYPE (lookup_object), 0));
t = build_function_call_vec (loc, vNULL, t, parms, NULL);
vec_free (parms);
return t;
method_params = tree_cons (NULL_TREE, lookup_object,
tree_cons (NULL_TREE, selector,
method_params));
- t = build3 (OBJ_TYPE_REF, sender_cast, sender, lookup_object, size_zero_node);
+ t = build3 (OBJ_TYPE_REF, sender_cast, sender, lookup_object,
+ build_int_cst (TREE_TYPE (lookup_object), 0));
ret_val = build_function_call (input_location, t, method_params);
if (check_for_nil)
{
/* Build an obj_type_ref, with the correct cast for the method call. */
t = build3 (OBJ_TYPE_REF, sender_cast, method,
- lookup_object, size_zero_node);
+ lookup_object, build_int_cst (TREE_TYPE (lookup_object), 0));
tree ret_val = build_function_call_vec (loc, vNULL, t, parms, NULL);
vec_free (parms);
if (check_for_nil)
--- /dev/null
+// PR c++/101597
+// { dg-do compile }
+// { dg-options "-O2 -Warray-bounds" }
+
+typedef __SIZE_TYPE__ size_t;
+struct S { virtual void *foo (size_t) __attribute__((alloc_size (2))); };
+
+int
+foo (void *p)
+{
+ char *q = static_cast<char *> (static_cast<S *> (p)->foo (32));
+ return q[64]; // { dg-warning "array subscript 64 is outside array bounds of" }
+}
OBJ_TYPE_REF_OBJECT: Is the object on whose behalf the lookup is
being performed. Through this the optimizers may be able to statically
determine the dynamic type of the object.
- OBJ_TYPE_REF_TOKEN: An integer index to the virtual method table. */
+ OBJ_TYPE_REF_TOKEN: An integer index to the virtual method table.
+ The integer index should have as type the original type of
+ OBJ_TYPE_REF_OBJECT; as pointer type conversions are useless in GIMPLE,
+ the type of OBJ_TYPE_REF_OBJECT can change to an unrelated pointer
+ type during optimizations. */
DEFTREECODE (OBJ_TYPE_REF, "obj_type_ref", tcc_expression, 3)
/* Used to represent the brace-enclosed initializers for a structure or an