summaryrefslogtreecommitdiff
path: root/gcc/c
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/c
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/c')
-rw-r--r--gcc/c/ChangeLog9
-rw-r--r--gcc/c/Make-lang.in2
-rw-r--r--gcc/c/c-typeck.c94
3 files changed, 13 insertions, 92 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 257b752cca4..93c72f0c69f 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,12 @@
+2012-10-09 Marc Glisse <marc.glisse@inria.fr>
+
+ PR c++/54427
+ * 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.
+
2012-10-04 Arnaud Charlet <charlet@adacore.com>
* c-decl.c (c_write_global_declarations): Fix handling of
diff --git a/gcc/c/Make-lang.in b/gcc/c/Make-lang.in
index a39c91cc0c6..93b8f64872d 100644
--- a/gcc/c/Make-lang.in
+++ b/gcc/c/Make-lang.in
@@ -192,5 +192,5 @@ c/c-parser.o : c/c-parser.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
c/c-typeck.o : c/c-typeck.c c/c-lang.h $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) $(C_TREE_H) $(TARGET_H) $(FLAGS_H) intl.h \
langhooks.h tree-iterator.h $(BITMAP_H) $(GIMPLE_H) \
- c-family/c-objc.h
+ c-family/c-objc.h c-family/c-common.h
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 5b4ad285874..ae6b3484b95 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. If not see
#include "bitmap.h"
#include "gimple.h"
#include "c-family/c-objc.h"
+#include "c-family/c-common.h"
/* Possible cases of implicit bad conversions. Used to select
diagnostic messages in convert_for_assignment. */
@@ -50,14 +51,6 @@ enum impl_conv {
ic_return
};
-/* Possibe cases of scalar_to_vector conversion. */
-enum stv_conv {
- stv_error, /* Error occured. */
- stv_nothing, /* Nothing happened. */
- stv_firstarg, /* First argument must be expanded. */
- stv_secondarg /* Second argument must be expanded. */
-};
-
/* The level of nesting inside "__alignof__". */
int in_alignof;
@@ -9375,88 +9368,6 @@ push_cleanup (tree decl, tree cleanup, bool eh_only)
TREE_OPERAND (stmt, 0) = list;
STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
}
-
-/* Convert scalar to vector for the range of operations. */
-static enum stv_conv
-scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1)
-{
- tree type0 = TREE_TYPE (op0);
- tree type1 = TREE_TYPE (op1);
- bool integer_only_op = false;
- enum stv_conv ret = stv_firstarg;
-
- gcc_assert (TREE_CODE (type0) == VECTOR_TYPE
- || TREE_CODE (type1) == VECTOR_TYPE);
- switch (code)
- {
- case RSHIFT_EXPR:
- case LSHIFT_EXPR:
- if (TREE_CODE (type0) == INTEGER_TYPE
- && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
- {
- if (unsafe_conversion_p (TREE_TYPE (type1), op0, false))
- {
- error_at (loc, "conversion of scalar to vector "
- "involves truncation");
- return stv_error;
- }
- else
- return stv_firstarg;
- }
- break;
-
- case BIT_IOR_EXPR:
- case BIT_XOR_EXPR:
- case BIT_AND_EXPR:
- integer_only_op = true;
- /* ... fall through ... */
-
- case PLUS_EXPR:
- case MINUS_EXPR:
- case MULT_EXPR:
- case TRUNC_DIV_EXPR:
- case TRUNC_MOD_EXPR:
- case RDIV_EXPR:
- if (TREE_CODE (type0) == VECTOR_TYPE)
- {
- tree tmp;
- ret = stv_secondarg;
- /* Swap TYPE0 with TYPE1 and OP0 with OP1 */
- tmp = type0; type0 = type1; type1 = tmp;
- tmp = op0; op0 = op1; op1 = tmp;
- }
-
- if (TREE_CODE (type0) == INTEGER_TYPE
- && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
- {
- if (unsafe_conversion_p (TREE_TYPE (type1), op0, false))
- {
- error_at (loc, "conversion of scalar to vector "
- "involves truncation");
- return stv_error;
- }
- return ret;
- }
- else if (!integer_only_op
- /* Allow integer --> real conversion if safe. */
- && (TREE_CODE (type0) == REAL_TYPE
- || TREE_CODE (type0) == INTEGER_TYPE)
- && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1)))
- {
- if (unsafe_conversion_p (TREE_TYPE (type1), op0, false))
- {
- error_at (loc, "conversion of scalar to vector "
- "involves truncation");
- return stv_error;
- }
- return ret;
- }
- default:
- break;
- }
-
- return stv_nothing;
-}
/* Build a binary-operation expression without default conversions.
CODE is the kind of expression to build.
@@ -9647,7 +9558,8 @@ build_binary_op (location_t location, enum tree_code code,
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);
+ enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1,
+ true);
switch (convert_flag)
{