Message ID | 20160113195616.GL25528@redhat.com |
---|---|
State | New |
Headers | show |
On Wed, 13 Jan 2016, Marek Polacek wrote: > On Wed, Jan 13, 2016 at 06:53:06PM +0000, Joseph Myers wrote: > > Will -Wsign-compare warnings be generated for the implicit signed / > > unsigned conversions in comparisons, as for scalar comparisons? > > Good point. No, with the previous patch -Wsign-compare would be quiet. But > since it probably should warn, I've added the warning (warn_for_sign_compare > isn't prepared to handle vectors so I've just used warning_at). > > Regtested on x86_64-linux, bootstrap in progress, but I don't expect any > problems. The C front-end changes are OK.
On Wed, Jan 13, 2016 at 11:11:52PM +0000, Joseph Myers wrote:
> The C front-end changes are OK.
Jason, is the C++ part of this patch here
<https://gcc.gnu.org/ml/gcc-patches/2016-01/msg00866.html>
(which is identical to the change in the C FE) ok?
Also, not sure about backporting this, maybe just to 5?
Marek
Ping. On Wed, Jan 20, 2016 at 12:31:51PM +0100, Marek Polacek wrote: > On Wed, Jan 13, 2016 at 11:11:52PM +0000, Joseph Myers wrote: > > The C front-end changes are OK. > > Jason, is the C++ part of this patch here > <https://gcc.gnu.org/ml/gcc-patches/2016-01/msg00866.html> > (which is identical to the change in the C FE) ok? > > Also, not sure about backporting this, maybe just to 5? Marek
On 01/27/2016 12:26 AM, Marek Polacek wrote: > Ping. > > On Wed, Jan 20, 2016 at 12:31:51PM +0100, Marek Polacek wrote: >> On Wed, Jan 13, 2016 at 11:11:52PM +0000, Joseph Myers wrote: >>> The C front-end changes are OK. >> >> Jason, is the C++ part of this patch here >> <https://gcc.gnu.org/ml/gcc-patches/2016-01/msg00866.html> >> (which is identical to the change in the C FE) ok? >> >> Also, not sure about backporting this, maybe just to 5? I'll go ahead and ack the C++ bits. This is fine for the trunk. WRT backporting, your call. jeff
On Wed, Jan 27, 2016 at 10:02:36AM -0700, Jeff Law wrote: > On 01/27/2016 12:26 AM, Marek Polacek wrote: > >Ping. > > > >On Wed, Jan 20, 2016 at 12:31:51PM +0100, Marek Polacek wrote: > >>On Wed, Jan 13, 2016 at 11:11:52PM +0000, Joseph Myers wrote: > >>>The C front-end changes are OK. > >> > >>Jason, is the C++ part of this patch here > >><https://gcc.gnu.org/ml/gcc-patches/2016-01/msg00866.html> > >>(which is identical to the change in the C FE) ok? > >> > >>Also, not sure about backporting this, maybe just to 5? > I'll go ahead and ack the C++ bits. This is fine for the trunk. Thanks. > WRT backporting, your call. I think I'll put it into GCC 5 (it's safe and should apply cleanly), but leave 4.9 alone. Marek
On Wed, Jan 27, 2016 at 9:45 AM, Marek Polacek <polacek@redhat.com> wrote: > On Wed, Jan 27, 2016 at 10:02:36AM -0700, Jeff Law wrote: >> On 01/27/2016 12:26 AM, Marek Polacek wrote: >> >Ping. >> > >> >On Wed, Jan 20, 2016 at 12:31:51PM +0100, Marek Polacek wrote: >> >>On Wed, Jan 13, 2016 at 11:11:52PM +0000, Joseph Myers wrote: >> >>>The C front-end changes are OK. >> >> >> >>Jason, is the C++ part of this patch here >> >><https://gcc.gnu.org/ml/gcc-patches/2016-01/msg00866.html> >> >>(which is identical to the change in the C FE) ok? >> >> >> >>Also, not sure about backporting this, maybe just to 5? >> I'll go ahead and ack the C++ bits. This is fine for the trunk. > > Thanks. > >> WRT backporting, your call. > > I think I'll put it into GCC 5 (it's safe and should apply cleanly), > but leave 4.9 alone. > > Marek I got FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for warnings, line 17) FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for warnings, line 18) FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for warnings, line 34) FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for warnings, line 35) on x86 on GCC 5 branch.
On Thu, Jan 28, 2016 at 04:47:04AM -0800, H.J. Lu wrote: > I got > > FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for > warnings, line 17) > FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for > warnings, line 18) > FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for > warnings, line 34) > FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for > warnings, line 35) Ah, patch(1) bogosity, fixed now. Sorry about that. Marek
On Thu, Jan 28, 2016 at 8:33 PM, Marek Polacek <polacek@redhat.com> wrote: > On Thu, Jan 28, 2016 at 04:47:04AM -0800, H.J. Lu wrote: >> I got >> >> FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for >> warnings, line 17) >> FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for >> warnings, line 18) >> FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for >> warnings, line 34) >> FAIL: c-c++-common/vector-compare-4.c -Wc++-compat (test for >> warnings, line 35) > > Ah, patch(1) bogosity, fixed now. Sorry about that. Note on i?86 I see (or x86_64 with -m32 -march=i586) /space/rguenther/src/svn/gcc-5-branch/gcc/testsuite/c-c++-common/vector-compare-4.c:29:1: warning: SSE vector return without SSE enabled changes the ABI [-Wpsabi]^M and thus the testcase fails (it has been adjusted for a similar kind of error on ppc on trunk but not yet on the branch(es)). Richard. > Marek
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 952041b..0fe1d46 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -11048,6 +11048,20 @@ build_binary_op (location_t location, enum tree_code code, return error_mark_node; } + /* It's not precisely specified how the usual arithmetic + conversions apply to the vector types. Here, we use + the unsigned type if one of the operands is signed and + the other one is unsigned. */ + if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1)) + { + if (!TYPE_UNSIGNED (type0)) + op0 = build1 (VIEW_CONVERT_EXPR, type1, op0); + else + op1 = build1 (VIEW_CONVERT_EXPR, type0, op1); + warning_at (location, OPT_Wsign_compare, "comparison between " + "types %qT and %qT", type0, type1); + } + /* Always construct signed integer vector type. */ intt = c_common_type_for_size (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type0))), 0); @@ -11201,6 +11215,20 @@ build_binary_op (location_t location, enum tree_code code, return error_mark_node; } + /* It's not precisely specified how the usual arithmetic + conversions apply to the vector types. Here, we use + the unsigned type if one of the operands is signed and + the other one is unsigned. */ + if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1)) + { + if (!TYPE_UNSIGNED (type0)) + op0 = build1 (VIEW_CONVERT_EXPR, type1, op0); + else + op1 = build1 (VIEW_CONVERT_EXPR, type0, op1); + warning_at (location, OPT_Wsign_compare, "comparison between " + "types %qT and %qT", type0, type1); + } + /* Always construct signed integer vector type. */ intt = c_common_type_for_size (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type0))), 0); diff --git gcc/cp/typeck.c gcc/cp/typeck.c index 472b41b..2f0035a 100644 --- gcc/cp/typeck.c +++ gcc/cp/typeck.c @@ -4813,6 +4813,20 @@ cp_build_binary_op (location_t location, return error_mark_node; } + /* It's not precisely specified how the usual arithmetic + conversions apply to the vector types. Here, we use + the unsigned type if one of the operands is signed and + the other one is unsigned. */ + if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1)) + { + if (!TYPE_UNSIGNED (type0)) + op0 = build1 (VIEW_CONVERT_EXPR, type1, op0); + else + op1 = build1 (VIEW_CONVERT_EXPR, type0, op1); + warning_at (location, OPT_Wsign_compare, "comparison between " + "types %qT and %qT", type0, type1); + } + /* Always construct signed integer vector type. */ intt = c_common_type_for_size (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type0))), 0); diff --git gcc/testsuite/c-c++-common/vector-compare-4.c gcc/testsuite/c-c++-common/vector-compare-4.c index e69de29..b44f474 100644 --- gcc/testsuite/c-c++-common/vector-compare-4.c +++ gcc/testsuite/c-c++-common/vector-compare-4.c @@ -0,0 +1,42 @@ +/* PR c/68062 */ +/* { dg-do compile } */ +/* { dg-options "-Wsign-compare" } */ + +typedef signed char __attribute__ ((vector_size (4))) v4qi; +typedef unsigned char __attribute__ ((vector_size (4))) uv4qi; +typedef signed int __attribute__ ((vector_size (4 * __SIZEOF_INT__))) v4si; +typedef unsigned int __attribute__ ((vector_size (4 * __SIZEOF_INT__))) uv4si; + +v4qi +fn1 (void) +{ + v4qi a = { 1, 2, 3, 4 }; + uv4qi b = { 4, 3, 2, 1 }; + v4qi v = { 0, 0, 0, 0 }; + + v += (a == b); /* { dg-warning "comparison between types" } */ + v += (a != b); /* { dg-warning "comparison between types" } */ + v += (a >= b); /* { dg-warning "comparison between types" } */ + v += (a <= b); /* { dg-warning "comparison between types" } */ + v += (a > b); /* { dg-warning "comparison between types" } */ + v += (a < b); /* { dg-warning "comparison between types" } */ + + return v; +} + +v4si +fn2 (void) +{ + v4si a = { 1, 2, 3, 4 }; + uv4si b = { 4, 3, 2, 1 }; + v4si v = { 0, 0, 0, 0 }; + + v += (a == b); /* { dg-warning "comparison between types" } */ + v += (a != b); /* { dg-warning "comparison between types" } */ + v += (a >= b); /* { dg-warning "comparison between types" } */ + v += (a <= b); /* { dg-warning "comparison between types" } */ + v += (a > b); /* { dg-warning "comparison between types" } */ + v += (a < b); /* { dg-warning "comparison between types" } */ + + return v; +}