From efc3536f46d9c96daf1f12b587edc583445c3902 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 31 Mar 2016 08:49:09 +0000 Subject: [PATCH] re PR c++/70430 (Incorrect result for logical "and" operation with mixed vector and scalar) 2016-03-31 Richard Biener PR c++/70430 * typeck.c (cp_build_binary_op): Fix operand order of vector conditional in truth op handling. * g++.dg/ext/vector30.C: New testcase. From-SVN: r234611 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ext/vector30.C | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/vector30.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 91ad5ac341f3..96f02210aa91 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-03-31 Richard Biener + + PR c++/70430 + * typeck.c (cp_build_binary_op): Fix operand order of vector + conditional in truth op handling. + 2016-03-29 Jason Merrill PR c++/70353 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 447006cb3274..9e61090f57bf 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4364,7 +4364,7 @@ cp_build_binary_op (location_t location, { tree m1 = build_all_ones_cst (TREE_TYPE (op0)); tree z = build_zero_cst (TREE_TYPE (op0)); - op1 = build_conditional_expr (location, op1, z, m1, complain); + op1 = build_conditional_expr (location, op1, m1, z, complain); } else if (!COMPARISON_CLASS_P (op1)) op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8e2bd7341768..7df13570e3dc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-03-31 Richard Biener + + PR c++/70430 + * g++.dg/ext/vector30.C: New testcase. + 2016-03-30 Dominique d'Humieres Jerry DeLisle diff --git a/gcc/testsuite/g++.dg/ext/vector30.C b/gcc/testsuite/g++.dg/ext/vector30.C new file mode 100644 index 000000000000..68326e3db5b8 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/vector30.C @@ -0,0 +1,15 @@ +// PR c++/70430 +// { dg-do run } +extern "C" void abort (void); +typedef int v4si __attribute__ ((vector_size (16))); +int main() +{ + v4si b = {1,0,-1,2}, c; + c = b && 1; + if (c[0] != -1 || c[1] != 0 || c[2] != -1 || c[3] != -1) + abort (); + c = b && 0; + if (c[0] != 0 || c[1] != 0 || c[2] != 0 || c[3] != 0) + abort (); + return 0; +}