On 1/22/20 5:58 PM, Jason Merrill wrote:
On 1/22/20 1:20 PM, Jason Merrill wrote:
On 1/22/20 5:14 AM, Martin Liška wrote:
Hi.

Just for the record, after the change 526.blender_r fails due to:

blender/source/blender/blenlib/intern/math_color.c: In function 'rgb_float_to_uchar': blender/source/blender/blenlib/BLI_utildefines.h:251:22: error: conversion from 'float' to 'unsigned char' may change value [-Werror=float-conversion]
   251 | #define FTOCHAR(val) ((CHECK_TYPE_INLINE(val, float)), \
       |                      ^
blender/source/blender/blenlib/BLI_utildefines.h:257:13: note: in expansion of macro 'FTOCHAR'    257 |   (v1)[0] = FTOCHAR((v2[0]));                                           \
       |             ^~~~~~~
blender/source/blender/blenlib/intern/math_color.c:421:2: note: in expansion of macro 'F3TOCHAR3'
   421 |  F3TOCHAR3(col_f, r_col);
       |  ^~~~~~~~~

where the project sets -Werror=float-conversion dues to:
$ cat blender/source/blender/blenlib/BLI_strict_flags.h

#ifdef __GNUC__
#  if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406  /* gcc4.6+ only */
#    pragma GCC diagnostic error "-Wsign-compare"
#    pragma GCC diagnostic error "-Wconversion"
#  endif

Thanks, investigating.

I wasn't able to reproduce this particular error, but I saw a different one due to -funsigned-char, fixed thus:

One more tweak, tested powerpc64-linux-gnu.
commit 608199de99de8e4f64e92bdf8b96564d2adeae5e
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Jan 23 10:37:18 2020 -0500

    c-family: One more 40752 tweak for unsigned char.
    
    My last patch didn't fix all the failures on unsignd char targets.  We were
    missing one warning because by suppressing -Wsign-conversion for the second
    operand of + we missed an overflow that we want to warn about, and we
    properly don't warn about unsigned / or %.
    
            PR testsuite/93391 - PR 40752 test fails with unsigned plain char.
            * c-warn.c (conversion_warning): Change -Wsign-conversion handling.
            * lib/target-supports.exp (check_effective_target_unsigned_char):
            New.

diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 6c73317b4a6..9315cac683e 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -1315,10 +1315,14 @@ conversion_warning (location_t loc, tree type, tree expr, tree result)
 	    for (int i = 0; i < arith_ops; ++i)
 	      {
 		tree op = TREE_OPERAND (expr, i);
-		tree opr = convert (type, op);
 		/* Avoid -Wsign-conversion for (unsigned)(x + (-1)).  */
-		bool minus = TREE_CODE (expr) == PLUS_EXPR && i == 1;
-		if (unsafe_conversion_p (type, op, opr, !minus))
+		if (TREE_CODE (expr) == PLUS_EXPR && i == 1
+		    && INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
+		    && TREE_CODE (op) == INTEGER_CST
+		    && tree_int_cst_sgn (op) < 0)
+		  op = fold_build1 (NEGATE_EXPR, TREE_TYPE (op), op);
+		tree opr = convert (type, op);
+		if (unsafe_conversion_p (type, op, opr, true))
 		  goto op_unsafe;
 	      }
 	    /* The operands seem safe, we might still want to warn if
diff --git a/gcc/testsuite/c-c++-common/Wconversion-pr40752a.c b/gcc/testsuite/c-c++-common/Wconversion-pr40752a.c
index cd70e34c390..8e3ffae06f6 100644
--- a/gcc/testsuite/c-c++-common/Wconversion-pr40752a.c
+++ b/gcc/testsuite/c-c++-common/Wconversion-pr40752a.c
@@ -14,9 +14,10 @@ void foo(char c, char c2)
   c *= 2;			/* { dg-warning "conversion" } */
   c *= c2;			/* { dg-warning "conversion" } */
   c /= 2;
-  c /= c2;			/* { dg-warning "conversion" } */
+  /* If char is unsigned we avoid promoting to int.  */
+  c /= c2;  /* { dg-warning "conversion" "" { target { ! unsigned_char } } } */
   c %= 2;
-  c %= c2;			/* { dg-warning "conversion" } */
+  c %= c2;  /* { dg-warning "conversion" "" { target { ! unsigned_char } } } */
   c = -c2;			/* { dg-warning "conversion" } */
   c = ~c2;			/* { dg-warning "conversion" } */
   c = c2++;
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index f65a8100da9..3ca3dd3a9e4 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -3115,6 +3115,14 @@ proc check_effective_target_dfprt { } {
     }]
 }
 
+# Return 1 iff target has unsigned plain 'char' by default.
+
+proc check_effective_target_unsigned_char {} {
+    return [check_no_compiler_messages unsigned_char assembly {
+	char ar[(char)-1];
+    }]
+}
+
 proc check_effective_target_powerpc_popcntb_ok { } {
     return [check_cached_effective_target powerpc_popcntb_ok {
 

Reply via email to