Commit 6f1e9668 by Richard Sandiford Committed by Richard Sandiford

[C++] Opt out of GNU vector extensions for built-in SVE types

This is the C++ equivalent of r277950.  The changes are very similar
to there.  Perhaps the only noteworthy thing (that I know of) is that
the patch continues to treat !gnu_vector_type_p vector types as literal
types/potential constexprs.  Disabling the GNU vector extensions
shouldn't in itself stop the types from being literal types, since
whatever the target provides instead might be constexpr material.

2019-12-04  Richard Sandiford  <richard.sandiford@arm.com>

gcc/cp/
	* cp-tree.h (CP_AGGREGATE_TYPE_P): Check for gnu_vector_type_p
	instead of VECTOR_TYPE.
	* call.c (build_conditional_expr_1): Restrict vector handling
	to vectors that satisfy gnu_vector_type_p.
	* cvt.c (ocp_convert): Only allow vectors to be converted
	to bool if they satisfy gnu_vector_type_p.
	(build_expr_type_conversion): Only allow conversions from
	vectors if they satisfy gnu_vector_type_p.
	* typeck.c (cp_build_binary_op): Only allow binary operators to be
	applied to vectors if they satisfy gnu_vector_type_p.
	(cp_build_unary_op): Likewise unary operators.
	(build_reinterpret_cast_1):

gcc/testsuite/
	* g++.target/aarch64/sve/acle/general-c++/gnu_vectors_1.C: New test.
	* g++.target/aarch64/sve/acle/general-c++/gnu_vectors_2.C: New test.

From-SVN: r278957
parent a8a5f4cc
2019-12-04 Richard Sandiford <richard.sandiford@arm.com>
* cp-tree.h (CP_AGGREGATE_TYPE_P): Check for gnu_vector_type_p
instead of VECTOR_TYPE.
* call.c (build_conditional_expr_1): Restrict vector handling
to vectors that satisfy gnu_vector_type_p.
* cvt.c (ocp_convert): Only allow vectors to be converted
to bool if they satisfy gnu_vector_type_p.
(build_expr_type_conversion): Only allow conversions from
vectors if they satisfy gnu_vector_type_p.
* typeck.c (cp_build_binary_op): Only allow binary operators to be
applied to vectors if they satisfy gnu_vector_type_p.
(cp_build_unary_op): Likewise unary operators.
(build_reinterpret_cast_1):
2019-12-03 Jakub Jelinek <jakub@redhat.com> 2019-12-03 Jakub Jelinek <jakub@redhat.com>
* cp-tree.h (enum cp_tree_index): Add CPTI_SOURCE_LOCATION_IMPL. * cp-tree.h (enum cp_tree_index): Add CPTI_SOURCE_LOCATION_IMPL.
......
...@@ -5093,7 +5093,8 @@ build_conditional_expr_1 (const op_location_t &loc, ...@@ -5093,7 +5093,8 @@ build_conditional_expr_1 (const op_location_t &loc,
orig_arg2 = arg2; orig_arg2 = arg2;
orig_arg3 = arg3; orig_arg3 = arg3;
if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg1))) if (gnu_vector_type_p (TREE_TYPE (arg1))
&& VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg1)))
{ {
tree arg1_type = TREE_TYPE (arg1); tree arg1_type = TREE_TYPE (arg1);
...@@ -5172,7 +5173,8 @@ build_conditional_expr_1 (const op_location_t &loc, ...@@ -5172,7 +5173,8 @@ build_conditional_expr_1 (const op_location_t &loc,
arg3_type = vtype; arg3_type = vtype;
} }
if (VECTOR_TYPE_P (arg2_type) != VECTOR_TYPE_P (arg3_type)) if ((gnu_vector_type_p (arg2_type) && !VECTOR_TYPE_P (arg3_type))
|| (gnu_vector_type_p (arg3_type) && !VECTOR_TYPE_P (arg2_type)))
{ {
enum stv_conv convert_flag = enum stv_conv convert_flag =
scalar_to_vector (loc, VEC_COND_EXPR, arg2, arg3, scalar_to_vector (loc, VEC_COND_EXPR, arg2, arg3,
...@@ -5203,7 +5205,9 @@ build_conditional_expr_1 (const op_location_t &loc, ...@@ -5203,7 +5205,9 @@ build_conditional_expr_1 (const op_location_t &loc,
} }
} }
if (!same_type_p (arg2_type, arg3_type) if (!gnu_vector_type_p (arg2_type)
|| !gnu_vector_type_p (arg3_type)
|| !same_type_p (arg2_type, arg3_type)
|| maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type), || maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type),
TYPE_VECTOR_SUBPARTS (arg2_type)) TYPE_VECTOR_SUBPARTS (arg2_type))
|| TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type)) || TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type))
......
...@@ -4254,7 +4254,7 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) ...@@ -4254,7 +4254,7 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
As an extension, we also treat vectors as aggregates. Keep these As an extension, we also treat vectors as aggregates. Keep these
checks in ascending code order. */ checks in ascending code order. */
#define CP_AGGREGATE_TYPE_P(TYPE) \ #define CP_AGGREGATE_TYPE_P(TYPE) \
(TREE_CODE (TYPE) == VECTOR_TYPE \ (gnu_vector_type_p (TYPE) \
|| TREE_CODE (TYPE) == ARRAY_TYPE \ || TREE_CODE (TYPE) == ARRAY_TYPE \
|| (CLASS_TYPE_P (TYPE) && COMPLETE_TYPE_P (TYPE) && !CLASSTYPE_NON_AGGREGATE (TYPE))) || (CLASS_TYPE_P (TYPE) && COMPLETE_TYPE_P (TYPE) && !CLASSTYPE_NON_AGGREGATE (TYPE)))
......
...@@ -836,6 +836,14 @@ ocp_convert (tree type, tree expr, int convtype, int flags, ...@@ -836,6 +836,14 @@ ocp_convert (tree type, tree expr, int convtype, int flags,
return error_mark_node; return error_mark_node;
} }
if (VECTOR_TYPE_P (intype) && !gnu_vector_type_p (intype))
{
if (complain & tf_error)
error_at (loc, "could not convert %qE from %qH to %qI", expr,
TREE_TYPE (expr), type);
return error_mark_node;
}
/* We can't implicitly convert a scoped enum to bool, so convert /* We can't implicitly convert a scoped enum to bool, so convert
to the underlying type first. */ to the underlying type first. */
if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC)) if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))
...@@ -1763,8 +1771,11 @@ build_expr_type_conversion (int desires, tree expr, bool complain) ...@@ -1763,8 +1771,11 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
tf_warning_or_error) tf_warning_or_error)
: NULL_TREE; : NULL_TREE;
case COMPLEX_TYPE:
case VECTOR_TYPE: case VECTOR_TYPE:
if (!gnu_vector_type_p (basetype))
return NULL_TREE;
/* FALLTHROUGH */
case COMPLEX_TYPE:
if ((desires & WANT_VECTOR_OR_COMPLEX) == 0) if ((desires & WANT_VECTOR_OR_COMPLEX) == 0)
return NULL_TREE; return NULL_TREE;
switch (TREE_CODE (TREE_TYPE (basetype))) switch (TREE_CODE (TREE_TYPE (basetype)))
......
...@@ -4547,7 +4547,8 @@ cp_build_binary_op (const op_location_t &location, ...@@ -4547,7 +4547,8 @@ cp_build_binary_op (const op_location_t &location,
/* In case when one of the operands of the binary operation is /* In case when one of the operands of the binary operation is
a vector and another is a scalar -- convert scalar to vector. */ a vector and another is a scalar -- convert scalar to vector. */
if ((code0 == VECTOR_TYPE) != (code1 == VECTOR_TYPE)) if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
|| (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
{ {
enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1, enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1,
complain & tf_error); complain & tf_error);
...@@ -4740,7 +4741,7 @@ cp_build_binary_op (const op_location_t &location, ...@@ -4740,7 +4741,7 @@ cp_build_binary_op (const op_location_t &location,
case TRUTH_ORIF_EXPR: case TRUTH_ORIF_EXPR:
case TRUTH_AND_EXPR: case TRUTH_AND_EXPR:
case TRUTH_OR_EXPR: case TRUTH_OR_EXPR:
if (!VECTOR_TYPE_P (type0) && VECTOR_TYPE_P (type1)) if (!VECTOR_TYPE_P (type0) && gnu_vector_type_p (type1))
{ {
if (!COMPARISON_CLASS_P (op1)) if (!COMPARISON_CLASS_P (op1))
op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1, op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
...@@ -4758,7 +4759,8 @@ cp_build_binary_op (const op_location_t &location, ...@@ -4758,7 +4759,8 @@ cp_build_binary_op (const op_location_t &location,
else else
gcc_unreachable (); gcc_unreachable ();
} }
if (VECTOR_TYPE_P (type0)) if (gnu_vector_type_p (type0)
&& (!VECTOR_TYPE_P (type1) || gnu_vector_type_p (type1)))
{ {
if (!COMPARISON_CLASS_P (op0)) if (!COMPARISON_CLASS_P (op0))
op0 = cp_build_binary_op (EXPR_LOCATION (op0), NE_EXPR, op0, op0 = cp_build_binary_op (EXPR_LOCATION (op0), NE_EXPR, op0,
...@@ -4791,13 +4793,15 @@ cp_build_binary_op (const op_location_t &location, ...@@ -4791,13 +4793,15 @@ cp_build_binary_op (const op_location_t &location,
Also set SHORT_SHIFT if shifting rightward. */ Also set SHORT_SHIFT if shifting rightward. */
case RSHIFT_EXPR: case RSHIFT_EXPR:
if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE if (gnu_vector_type_p (type0)
&& TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE) && code1 == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
{ {
result_type = type0; result_type = type0;
converted = 1; converted = 1;
} }
else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE else if (gnu_vector_type_p (type0)
&& gnu_vector_type_p (type1)
&& TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
&& known_eq (TYPE_VECTOR_SUBPARTS (type0), && known_eq (TYPE_VECTOR_SUBPARTS (type0),
...@@ -4837,13 +4841,15 @@ cp_build_binary_op (const op_location_t &location, ...@@ -4837,13 +4841,15 @@ cp_build_binary_op (const op_location_t &location,
break; break;
case LSHIFT_EXPR: case LSHIFT_EXPR:
if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE if (gnu_vector_type_p (type0)
&& code1 == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE) && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
{ {
result_type = type0; result_type = type0;
converted = 1; converted = 1;
} }
else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE else if (gnu_vector_type_p (type0)
&& gnu_vector_type_p (type1)
&& TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
&& known_eq (TYPE_VECTOR_SUBPARTS (type0), && known_eq (TYPE_VECTOR_SUBPARTS (type0),
...@@ -4896,7 +4902,7 @@ cp_build_binary_op (const op_location_t &location, ...@@ -4896,7 +4902,7 @@ cp_build_binary_op (const op_location_t &location,
case EQ_EXPR: case EQ_EXPR:
case NE_EXPR: case NE_EXPR:
if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE) if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
goto vector_compare; goto vector_compare;
if ((complain & tf_warning) if ((complain & tf_warning)
&& c_inhibit_evaluation_warnings == 0 && c_inhibit_evaluation_warnings == 0
...@@ -5186,7 +5192,7 @@ cp_build_binary_op (const op_location_t &location, ...@@ -5186,7 +5192,7 @@ cp_build_binary_op (const op_location_t &location,
"in unspecified behavior"); "in unspecified behavior");
} }
if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE) if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
{ {
vector_compare: vector_compare:
tree intt; tree intt;
...@@ -5341,7 +5347,7 @@ cp_build_binary_op (const op_location_t &location, ...@@ -5341,7 +5347,7 @@ cp_build_binary_op (const op_location_t &location,
{ {
arithmetic_types_p = 0; arithmetic_types_p = 0;
/* Vector arithmetic is only allowed when both sides are vectors. */ /* Vector arithmetic is only allowed when both sides are vectors. */
if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE) if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
{ {
if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)) if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
|| !vector_types_compatible_elements_p (type0, type1)) || !vector_types_compatible_elements_p (type0, type1))
...@@ -6435,7 +6441,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert, ...@@ -6435,7 +6441,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert,
break; break;
case TRUTH_NOT_EXPR: case TRUTH_NOT_EXPR:
if (VECTOR_TYPE_P (TREE_TYPE (arg))) if (gnu_vector_type_p (TREE_TYPE (arg)))
return cp_build_binary_op (input_location, EQ_EXPR, arg, return cp_build_binary_op (input_location, EQ_EXPR, arg,
build_zero_cst (TREE_TYPE (arg)), complain); build_zero_cst (TREE_TYPE (arg)), complain);
arg = perform_implicit_conversion (boolean_type_node, arg, arg = perform_implicit_conversion (boolean_type_node, arg,
...@@ -7811,9 +7817,9 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, ...@@ -7811,9 +7817,9 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
"is conditionally-supported"); "is conditionally-supported");
return build_nop_reinterpret (type, expr); return build_nop_reinterpret (type, expr);
} }
else if (VECTOR_TYPE_P (type)) else if (gnu_vector_type_p (type))
return convert_to_vector (type, expr); return convert_to_vector (type, expr);
else if (VECTOR_TYPE_P (intype) else if (gnu_vector_type_p (intype)
&& INTEGRAL_OR_ENUMERATION_TYPE_P (type)) && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
return convert_to_integer_nofold (type, expr); return convert_to_integer_nofold (type, expr);
else else
......
2019-12-04 Richard Sandiford <richard.sandiford@arm.com>
* g++.target/aarch64/sve/acle/general-c++/gnu_vectors_1.C: New test.
* g++.target/aarch64/sve/acle/general-c++/gnu_vectors_2.C: New test.
2019-12-04 Jakub Jelinek <jakub@redhat.com> 2019-12-04 Jakub Jelinek <jakub@redhat.com>
PR fortran/92756 PR fortran/92756
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment