summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-09 06:18:29 +0000
committerglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-09 06:18:29 +0000
commit41ed701aa7962118609ab7a37c741dd165a1e1c0 (patch)
tree41770fbb2dff0d56518b79bce3dd01c52d1b2759 /gcc/cp
parent913a7575316e16a95adf81eb285e4a77bd66b0a4 (diff)
downloadgcc-41ed701aa7962118609ab7a37c741dd165a1e1c0.tar.gz
2012-10-09 Marc Glisse <marc.glisse@inria.fr>
PR c++/54427 c/ * c-typeck.c: Include c-common.h. (enum stv_conv): Moved to c-common.h. (scalar_to_vector): Moved to c-common.c. (build_binary_op): Adapt to scalar_to_vector's new prototype. * Make-lang.in: c-typeck.c depends on c-common.h. c-family/ * c-common.c (scalar_to_vector): Moved from c-typeck.c. Support more operations. Make error messages optional. * c-common.h (enum stv_conv): Moved from c-typeck.c. (scalar_to_vector): Declare. cp/ * typeck.c (cp_build_binary_op): Handle mixed scalar-vector operations. [LSHIFT_EXPR, RSHIFT_EXPR]: Likewise. gcc/ * fold-const.c (fold_binary_loc): Use build_zero_cst instead of build_int_cst for a potential vector. testsuite/ * c-c++-common/vector-scalar.c: New testcase. * g++.dg/ext/vector18.C: New testcase. * g++.dg/ext/vector5.C: This is not an error anymore. * gcc.dg/init-vec-1.c: Move ... * c-c++-common/init-vec-1.c: ... here. Adapt error message. * gcc.c-torture/execute/vector-shift1.c: Move ... * c-c++-common/torture/vector-shift1.c: ... here. * gcc.dg/scal-to-vec1.c: Move ... * c-c++-common/scal-to-vec1.c: ... here. Avoid narrowing for C++11. Adapt error messages. * gcc.dg/convert-vec-1.c: Move ... * c-c++-common/convert-vec-1.c: ... here. * gcc.dg/scal-to-vec2.c: Move ... * c-c++-common/scal-to-vec2.c: ... here. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192238 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/typeck.c50
2 files changed, 55 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f4e7e6a1846..4c1d01abc8e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2012-10-09 Marc Glisse <marc.glisse@inria.fr>
+
+ PR c++/54427
+ * typeck.c (cp_build_binary_op): Handle mixed scalar-vector
+ operations.
+ [LSHIFT_EXPR, RSHIFT_EXPR]: Likewise.
+
2012-10-08 Jakub Jelinek <jakub@redhat.com>
PR c++/54858
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index ae4d0a44589..94e17c5aa00 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3912,6 +3912,40 @@ cp_build_binary_op (location_t location,
warning_at (loc, OPT_Wpointer_arith, "NULL used in arithmetic");
}
+ /* In case when one of the operands of the binary operation is
+ a vector and another is a scalar -- convert scalar to vector. */
+ if ((code0 == VECTOR_TYPE) != (code1 == VECTOR_TYPE))
+ {
+ enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1,
+ complain & tf_error);
+
+ switch (convert_flag)
+ {
+ case stv_error:
+ return error_mark_node;
+ case stv_firstarg:
+ {
+ op0 = convert (TREE_TYPE (type1), op0);
+ op0 = build_vector_from_val (type1, op0);
+ type0 = TREE_TYPE (op0);
+ code0 = TREE_CODE (type0);
+ converted = 1;
+ break;
+ }
+ case stv_secondarg:
+ {
+ op1 = convert (TREE_TYPE (type0), op1);
+ op1 = build_vector_from_val (type0, op1);
+ type1 = TREE_TYPE (op1);
+ code1 = TREE_CODE (type1);
+ converted = 1;
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
switch (code)
{
case MINUS_EXPR:
@@ -4035,7 +4069,13 @@ cp_build_binary_op (location_t location,
Also set SHORT_SHIFT if shifting rightward. */
case RSHIFT_EXPR:
- if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
+ if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE
+ && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
+ {
+ result_type = type0;
+ converted = 1;
+ }
+ else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
&& TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
&& TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1))
@@ -4072,7 +4112,13 @@ cp_build_binary_op (location_t location,
break;
case LSHIFT_EXPR:
- if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
+ if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE
+ && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
+ {
+ result_type = type0;
+ converted = 1;
+ }
+ else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
&& TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
&& TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1))