summaryrefslogtreecommitdiff
path: root/gcc/c-family/c-common.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2016-05-24 07:55:56 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2016-05-24 07:55:56 +0000
commitf17a223de829cb5fa0b32a9f12c22a4fa929506c (patch)
tree8563bc5695a3444a499e0c3f237354120053f294 /gcc/c-family/c-common.c
parent64fc0cd9b2a83a4b0301d8d7890bf27880d8384e (diff)
re PR middle-end/70434 (adding an extraneous cast to vector type results in inferior code)
2016-05-24 Richard Biener <rguenther@suse.de> PR middle-end/70434 PR c/69504 c-family/ * c-common.h (convert_vector_to_pointer_for_subscript): Rename to ... (convert_vector_to_array_for_subscript): ... this. * c-common.c (convert_vector_to_pointer_for_subscript): Use a VIEW_CONVERT_EXPR to an array type. Rename to ... (convert_vector_to_array_for_subscript): ... this. cp/ * expr.c (mark_exp_read): Handle VIEW_CONVERT_EXPR. * constexpr.c (cxx_eval_array_reference): Handle indexed vectors. * typeck.c (cp_build_array_ref): Adjust. c/ * c-typeck.c (build_array_ref): Do not complain about indexing non-lvalue vectors. Adjust for function name change. * tree-ssa.c (non_rewritable_mem_ref_base): Make sure to mark bases which are accessed with non-invariant indices. * gimple-fold.c (maybe_canonicalize_mem_ref_addr): Re-write constant index ARRAY_REFs of vectors into BIT_FIELD_REFs. * c-c++-common/vector-subscript-4.c: New testcase. * c-c++-common/vector-subscript-5.c: Likewise. From-SVN: r236630
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r--gcc/c-family/c-common.c60
1 files changed, 14 insertions, 46 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 146e8059c1a..4568cf62a98 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -12496,66 +12496,34 @@ build_userdef_literal (tree suffix_id, tree value,
return literal;
}
-/* For vector[index], convert the vector to a
- pointer of the underlying type. Return true if the resulting
- ARRAY_REF should not be an lvalue. */
+/* For vector[index], convert the vector to an array of the underlying type.
+ Return true if the resulting ARRAY_REF should not be an lvalue. */
bool
-convert_vector_to_pointer_for_subscript (location_t loc,
- tree *vecp, tree index)
+convert_vector_to_array_for_subscript (location_t loc,
+ tree *vecp, tree index)
{
bool ret = false;
if (VECTOR_TYPE_P (TREE_TYPE (*vecp)))
{
tree type = TREE_TYPE (*vecp);
- tree type1;
ret = !lvalue_p (*vecp);
+
if (TREE_CODE (index) == INTEGER_CST)
if (!tree_fits_uhwi_p (index)
|| tree_to_uhwi (index) >= TYPE_VECTOR_SUBPARTS (type))
warning_at (loc, OPT_Warray_bounds, "index value is out of bound");
- if (ret)
- {
- tree tmp = create_tmp_var_raw (type);
- DECL_SOURCE_LOCATION (tmp) = loc;
- *vecp = c_save_expr (*vecp);
- if (TREE_CODE (*vecp) == C_MAYBE_CONST_EXPR)
- {
- bool non_const = C_MAYBE_CONST_EXPR_NON_CONST (*vecp);
- *vecp = C_MAYBE_CONST_EXPR_EXPR (*vecp);
- *vecp
- = c_wrap_maybe_const (build4 (TARGET_EXPR, type, tmp,
- *vecp, NULL_TREE, NULL_TREE),
- non_const);
- }
- else
- *vecp = build4 (TARGET_EXPR, type, tmp, *vecp,
- NULL_TREE, NULL_TREE);
- SET_EXPR_LOCATION (*vecp, loc);
- c_common_mark_addressable_vec (tmp);
- }
- else
- c_common_mark_addressable_vec (*vecp);
- type = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
- type1 = build_pointer_type (TREE_TYPE (*vecp));
- bool ref_all = TYPE_REF_CAN_ALIAS_ALL (type1);
- if (!ref_all
- && !DECL_P (*vecp))
- {
- /* If the original vector isn't declared may_alias and it
- isn't a bare vector look if the subscripting would
- alias the vector we subscript, and if not, force ref-all. */
- alias_set_type vecset = get_alias_set (*vecp);
- alias_set_type sset = get_alias_set (type);
- if (!alias_sets_must_conflict_p (sset, vecset)
- && !alias_set_subset_of (sset, vecset))
- ref_all = true;
- }
- type = build_pointer_type_for_mode (type, ptr_mode, ref_all);
- *vecp = build1 (ADDR_EXPR, type1, *vecp);
- *vecp = convert (type, *vecp);
+ /* We are building an ARRAY_REF so mark the vector as addressable
+ to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
+ for function parameters. */
+ c_common_mark_addressable_vec (*vecp);
+
+ *vecp = build1 (VIEW_CONVERT_EXPR,
+ build_array_type_nelts (TREE_TYPE (type),
+ TYPE_VECTOR_SUBPARTS (type)),
+ *vecp);
}
return ret;
}