View | Details | Raw Unified | Return to bug 26167
Collapse All | Expand All

(-)pristine/gcc/builtins.c (-9 / +1 lines)
Lines 6735-6749 integer_valued_real_p (tree t) Link Here
6735
	     && integer_valued_real_p (TREE_OPERAND (t, 2));
6735
	     && integer_valued_real_p (TREE_OPERAND (t, 2));
6736
6736
6737
    case REAL_CST:
6737
    case REAL_CST:
6738
      if (! TREE_CONSTANT_OVERFLOW (t))
6738
      return real_isinteger (TREE_REAL_CST_PTR (t), TYPE_MODE (TREE_TYPE (t)));
6739
      {
6740
	REAL_VALUE_TYPE c, cint;
6741
6742
	c = TREE_REAL_CST (t);
6743
	real_trunc (&cint, TYPE_MODE (TREE_TYPE (t)), &c);
6744
	return real_identical (&c, &cint);
6745
      }
6746
      break;
6747
6739
6748
    case NOP_EXPR:
6740
    case NOP_EXPR:
6749
      {
6741
      {
(-)pristine/gcc/c-common.c (-27 / +149 lines)
Lines 948-978 overflow_warning (tree value) Link Here
948
    }
948
    }
949
}
949
}
950
950
951
/* Print a warning if a large constant is truncated to unsigned,
952
   or if -Wconversion is used and a constant < 0 is converted to unsigned.
953
   Invoke this function on every expression that might be implicitly
954
   converted to an unsigned type.  */
955
956
static void
957
unsigned_conversion_warning (tree result, tree operand)
958
{
959
  tree type = TREE_TYPE (result);
960
961
  if (TREE_CODE (operand) == INTEGER_CST
962
      && TREE_CODE (type) == INTEGER_TYPE
963
      && TYPE_UNSIGNED (type)
964
      && skip_evaluation == 0
965
      && !int_fits_type_p (operand, type))
966
    {
967
      if (!int_fits_type_p (operand, c_common_signed_type (type)))
968
	/* This detects cases like converting -129 or 256 to unsigned char.  */
969
	warning (OPT_Woverflow,
970
		 "large integer implicitly truncated to unsigned type");
971
      else
972
	warning (OPT_Wconversion,
973
		 "negative integer implicitly converted to unsigned type");
974
    }
975
}
976
951
977
/* Print a warning about casts that might indicate violation
952
/* Print a warning about casts that might indicate violation
978
   of strict aliasing rules if -Wstrict-aliasing is used and
953
   of strict aliasing rules if -Wstrict-aliasing is used and
Lines 1067-1072 vector_types_convertible_p (tree t1, tre Link Here
1067
		== INTEGRAL_TYPE_P (TREE_TYPE (t2)));
1042
		== INTEGRAL_TYPE_P (TREE_TYPE (t2)));
1068
}
1043
}
1069
1044
1045
/* Warns if the conversion of EXPR to TYPE may alter a value.
1046
   This function is called from convert_and_check().  */
1047
1048
void
1049
coercion_warning (tree type, tree expr)
1050
{
1051
  bool give_warning = false;
1052
1053
  unsigned int formal_prec = TYPE_PRECISION (type);
1054
1055
  if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST)
1056
    {
1057
      /* Warn for real constant that is not an exact integer coerced
1058
         to integer type.  */
1059
      if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
1060
          && TREE_CODE (type) == INTEGER_TYPE)
1061
        {
1062
          if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (TREE_TYPE (expr))))
1063
            give_warning = true;
1064
        }
1065
      /* Warn for an integer constant that does not fit into integer type.  */
1066
      else if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
1067
               && TREE_CODE (type) == INTEGER_TYPE
1068
               && !int_fits_type_p (expr, type))
1069
        {
1070
          if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (TREE_TYPE (expr)))
1071
            warning (OPT_Wcoercion,
1072
                     "negative integer implicitly converted to unsigned type");
1073
          else
1074
        give_warning = true;
1075
        }
1076
      else if (TREE_CODE (type) == REAL_TYPE)
1077
        {
1078
          /* Warn for an integer constant that does not fit into real type.  */
1079
          if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE)
1080
            {
1081
              REAL_VALUE_TYPE a = real_value_from_int_cst (0, expr);
1082
              if (!exact_real_truncate (TYPE_MODE (type), &a))
1083
                give_warning = true;
1084
            }
1085
          else if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
1086
            {
1087
              /* If there is no conversion between binary and decimal
1088
                 float types, then warn only when precision is
1089
                 narrowed and the constant does not fit into the new
1090
                 precision.  */
1091
              if (DECIMAL_FLOAT_TYPE_P (type) == DECIMAL_FLOAT_TYPE_P (TREE_TYPE (expr)))
1092
                {
1093
                  if (formal_prec < TYPE_PRECISION (TREE_TYPE (expr)))
1094
                    {
1095
                      REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
1096
                      if (!exact_real_truncate (TYPE_MODE (type),&a))
1097
                        give_warning = true;
1098
                    }
1099
                }
1100
              /* If there is a conversion between binary and decimal
1101
                 float types, then we must be sure that the conversion
1102
                 is exact.  */
1103
              else
1104
            {
1105
              REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
1106
              if (!exact_real_truncate (TYPE_MODE (type), &a))
1107
                give_warning = true;
1108
            }
1109
        }
1110
        }
1111
1112
      if (give_warning)
1113
        warning (OPT_Wcoercion,
1114
                 "coercion as %qT alters %qT constant value",
1115
                 type, TREE_TYPE (expr));
1116
    }
1117
  else /* 'expr' is not a constant.  */
1118
    {
1119
      /* Warn for real types coerced to integer types.  */
1120
      if (TREE_CODE (type) == INTEGER_TYPE
1121
          && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
1122
        give_warning = true;
1123
1124
      /* Warn for integer types coerced to real types if and only if
1125
         all the range of values of the integer type cannot be
1126
         represented by the real type.  */
1127
      else if (TREE_CODE (type) == REAL_TYPE
1128
               && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE)
1129
        {
1130
          tree type_low_bound = TYPE_MIN_VALUE (TREE_TYPE (expr));
1131
          tree type_high_bound = TYPE_MAX_VALUE (TREE_TYPE (expr));
1132
          REAL_VALUE_TYPE real_low_bound = real_value_from_int_cst (0, type_low_bound);
1133
          REAL_VALUE_TYPE real_high_bound = real_value_from_int_cst (0, type_high_bound);
1134
1135
          if (!exact_real_truncate (TYPE_MODE (type), &real_low_bound)
1136
              || !exact_real_truncate (TYPE_MODE (type), &real_high_bound))
1137
            give_warning = true;
1138
        }
1139
1140
      else if (TREE_CODE (type) == REAL_TYPE
1141
               && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
1142
        {
1143
          /* Warn for coercions between binary and decimal float types
1144
             and for real types coerced to smaller real types.  */
1145
          if (DECIMAL_FLOAT_TYPE_P (type) != DECIMAL_FLOAT_TYPE_P (TREE_TYPE (expr))
1146
              || formal_prec < TYPE_PRECISION (TREE_TYPE (expr)))
1147
        give_warning = true;
1148
        }
1149
1150
      else if (TREE_CODE  (type) == INTEGER_TYPE
1151
               && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE)
1152
        {
1153
          /* Warn for integer types coerced to smaller integer types.  */
1154
          if (formal_prec < TYPE_PRECISION (TREE_TYPE (expr))
1155
              /* When they are the same width but different signedness,
1156
                 then the value may change.  */
1157
              || (formal_prec == TYPE_PRECISION (TREE_TYPE (expr))
1158
                  && TYPE_UNSIGNED (TREE_TYPE (expr)) != TYPE_UNSIGNED (type))
1159
              /* Even when coerced to a bigger type, if the type is
1160
                 unsigned but expr is signed, then negative values
1161
                 will be changed.  */
1162
              || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (TREE_TYPE (expr))))
1163
            give_warning = true;
1164
        }
1165
1166
      if (give_warning)
1167
        warning (OPT_Wcoercion,
1168
                 "coercion to %qT from %qT may alter its value",
1169
                 type, TREE_TYPE (expr));
1170
    }
1171
}
1172
1070
/* Convert EXPR to TYPE, warning about conversion problems with constants.
1173
/* Convert EXPR to TYPE, warning about conversion problems with constants.
1071
   Invoke this function on every expression that is converted implicitly,
1174
   Invoke this function on every expression that is converted implicitly,
1072
   i.e. because of language rules and not because of an explicit cast.  */
1175
   i.e. because of language rules and not because of an explicit cast.  */
Lines 1074-1080 vector_types_convertible_p (tree t1, tre Link Here
1074
tree
1177
tree
1075
convert_and_check (tree type, tree expr)
1178
convert_and_check (tree type, tree expr)
1076
{
1179
{
1077
  tree t = convert (type, expr);
1180
  tree t;
1181
1182
  if (warn_coercion && !skip_evaluation)
1183
    coercion_warning (type, expr);
1184
1185
  t = convert (type, expr);
1078
  if (TREE_CODE (t) == INTEGER_CST)
1186
  if (TREE_CODE (t) == INTEGER_CST)
1079
    {
1187
    {
1080
      if (TREE_OVERFLOW (t))
1188
      if (TREE_OVERFLOW (t))
Lines 1101-1107 convert_and_check (tree type, tree expr) Link Here
1101
                       "overflow in implicit constant conversion");
1209
                       "overflow in implicit constant conversion");
1102
	}
1210
	}
1103
      else
1211
      else
1104
	unsigned_conversion_warning (t, expr);
1212
        {
1213
          /* Print a warning if a large constant is truncated to unsigned.  */
1214
          if (TREE_CODE (expr) == INTEGER_CST
1215
              && TREE_CODE (type) == INTEGER_TYPE
1216
              && TYPE_UNSIGNED (type)
1217
              && skip_evaluation == 0
1218
              && !int_fits_type_p (expr, type)
1219
              && !int_fits_type_p (expr, c_common_signed_type (type)))
1220
            {
1221
              /* This detects cases like converting -129 or 256 to
1222
                 unsigned char.  */
1223
              warning (OPT_Woverflow,
1224
                       "large integer implicitly truncated to unsigned type");
1225
            }
1226
        }
1105
    }
1227
    }
1106
  return t;
1228
  return t;
1107
}
1229
}
(-)pristine/gcc/c-common.h (+1 lines)
Lines 656-661 struct varray_head_tag; Link Here
656
extern void constant_expression_warning (tree);
656
extern void constant_expression_warning (tree);
657
extern void strict_aliasing_warning(tree, tree, tree);
657
extern void strict_aliasing_warning(tree, tree, tree);
658
extern void empty_body_warning (tree, tree);
658
extern void empty_body_warning (tree, tree);
659
extern void coercion_warning (tree type, tree expr);
659
extern tree convert_and_check (tree, tree);
660
extern tree convert_and_check (tree, tree);
660
extern void overflow_warning (tree);
661
extern void overflow_warning (tree);
661
extern bool c_determine_visibility (tree);
662
extern bool c_determine_visibility (tree);
(-)pristine/gcc/c.opt (-2 / +10 lines)
Lines 141-146 Wchar-subscripts Link Here
141
C ObjC C++ ObjC++ Var(warn_char_subscripts)
141
C ObjC C++ ObjC++ Var(warn_char_subscripts)
142
Warn about subscripts whose type is \"char\"
142
Warn about subscripts whose type is \"char\"
143
143
144
Wcoercion
145
C ObjC C++ ObjC++ Var(warn_coercion)
146
Warn for implicit type conversions that may change a value
147
144
Wcomment
148
Wcomment
145
C ObjC C++ ObjC++
149
C ObjC C++ ObjC++
146
Warn about possibly nested block comments, and C++ comments spanning more than one physical line
150
Warn about possibly nested block comments, and C++ comments spanning more than one physical line
Lines 150-157 C ObjC C++ ObjC++ Link Here
150
Synonym for -Wcomment
154
Synonym for -Wcomment
151
155
152
Wconversion
156
Wconversion
153
C ObjC C++ ObjC++ Var(warn_conversion)
157
C++ ObjC++ Var(warn_conversion)
154
Warn about possibly confusing type conversions
158
Undocumented
159
160
Wtraditional-conversion
161
C ObjC Var(warn_traditional_conversion)
162
Warn of prototypes causing type conversions different from what would happen in the absence of prototype
155
163
156
Wctor-dtor-privacy
164
Wctor-dtor-privacy
157
C++ ObjC++ Var(warn_ctor_dtor_privacy)
165
C++ ObjC++ Var(warn_ctor_dtor_privacy)
(-)pristine/gcc/cp/call.c (-5 / +4 lines)
Lines 4255-4265 convert_like_real (conversion *convs, tr Link Here
4255
      if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
4255
      if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
4256
	  && TREE_CODE (t) == INTEGER_TYPE)
4256
	  && TREE_CODE (t) == INTEGER_TYPE)
4257
	{
4257
	{
4258
	  if (fn)
4258
          convert_and_check (t, expr);
4259
	    warning (OPT_Wconversion, "passing %qT for argument %P to %qD",
4259
          /* There is another call to convert_and_check below, we just
4260
		     TREE_TYPE (expr), argnum, fn);
4260
             warn once.  */
4261
	  else
4261
          issue_conversion_warnings = false;
4262
	    warning (OPT_Wconversion, "converting to %qT from %qT", t, TREE_TYPE (expr));
4263
	}
4262
	}
4264
    }
4263
    }
4265
4264
(-)pristine/gcc/c-typeck.c (-32 / +6 lines)
Lines 2396-2402 convert_arguments (tree typelist, tree v Link Here
2396
	    {
2396
	    {
2397
	      /* Optionally warn about conversions that
2397
	      /* Optionally warn about conversions that
2398
		 differ from the default conversions.  */
2398
		 differ from the default conversions.  */
2399
	      if (warn_conversion || warn_traditional)
2399
	      if (warn_traditional_conversion || warn_traditional)
2400
		{
2400
		{
2401
		  unsigned int formal_prec = TYPE_PRECISION (type);
2401
		  unsigned int formal_prec = TYPE_PRECISION (type);
2402
2402
Lines 2443-2479 convert_arguments (tree typelist, tree v Link Here
2443
			warning (0, "passing argument %d of %qE as %<float%> "
2443
			warning (0, "passing argument %d of %qE as %<float%> "
2444
				 "rather than %<double%> due to prototype",
2444
				 "rather than %<double%> due to prototype",
2445
				 argnum, rname);
2445
				 argnum, rname);
2446
2447
		      /* Warn if mismatch between argument and prototype
2448
			 for decimal float types.  Warn of conversions with
2449
			 binary float types and of precision narrowing due to
2450
			 prototype. */
2451
 		      else if (type != TREE_TYPE (val)
2452
			       && (type == dfloat32_type_node
2453
				   || type == dfloat64_type_node
2454
				   || type == dfloat128_type_node
2455
				   || TREE_TYPE (val) == dfloat32_type_node
2456
				   || TREE_TYPE (val) == dfloat64_type_node
2457
				   || TREE_TYPE (val) == dfloat128_type_node)
2458
			       && (formal_prec
2459
				   <= TYPE_PRECISION (TREE_TYPE (val))
2460
				   || (type == dfloat128_type_node
2461
				       && (TREE_TYPE (val)
2462
					   != dfloat64_type_node
2463
					   && (TREE_TYPE (val)
2464
					       != dfloat32_type_node)))
2465
				   || (type == dfloat64_type_node
2466
				       && (TREE_TYPE (val)
2467
					   != dfloat32_type_node))))
2468
			warning (0, "passing argument %d of %qE as %qT "
2469
				 "rather than %qT due to prototype",
2470
				 argnum, rname, type, TREE_TYPE (val));
2471
2472
		    }
2446
		    }
2473
		  /* Detect integer changing in width or signedness.
2447
		  /* Detect integer changing in width or signedness.
2474
		     These warnings are only activated with
2448
		     These warnings are only activated with
2475
		     -Wconversion, not with -Wtraditional.  */
2449
		     -Wtraditional-conversion, not with -Wtraditional.  */
2476
		  else if (warn_conversion && INTEGRAL_TYPE_P (type)
2450
		  else if (warn_traditional_conversion && INTEGRAL_TYPE_P (type)
2477
			   && INTEGRAL_TYPE_P (TREE_TYPE (val)))
2451
			   && INTEGRAL_TYPE_P (TREE_TYPE (val)))
2478
		    {
2452
		    {
2479
		      tree would_have_been = default_conversion (val);
2453
		      tree would_have_been = default_conversion (val);
Lines 2486-2492 convert_arguments (tree typelist, tree v Link Here
2486
			   and the actual arg is that enum type.  */
2460
			   and the actual arg is that enum type.  */
2487
			;
2461
			;
2488
		      else if (formal_prec != TYPE_PRECISION (type1))
2462
		      else if (formal_prec != TYPE_PRECISION (type1))
2489
			warning (OPT_Wconversion, "passing argument %d of %qE "
2463
			warning (OPT_Wtraditional_conversion, "passing argument %d of %qE "
2490
				 "with different width due to prototype",
2464
				 "with different width due to prototype",
2491
				 argnum, rname);
2465
				 argnum, rname);
2492
		      else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
2466
		      else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
Lines 2509-2519 convert_arguments (tree typelist, tree v Link Here
2509
			       && TYPE_UNSIGNED (TREE_TYPE (val)))
2483
			       && TYPE_UNSIGNED (TREE_TYPE (val)))
2510
			;
2484
			;
2511
		      else if (TYPE_UNSIGNED (type))
2485
		      else if (TYPE_UNSIGNED (type))
2512
			warning (OPT_Wconversion, "passing argument %d of %qE "
2486
			warning (OPT_Wtraditional_conversion, "passing argument %d of %qE "
2513
				 "as unsigned due to prototype",
2487
				 "as unsigned due to prototype",
2514
				 argnum, rname);
2488
				 argnum, rname);
2515
		      else
2489
		      else
2516
			warning (OPT_Wconversion, "passing argument %d of %qE "
2490
			warning (OPT_Wtraditional_conversion, "passing argument %d of %qE "
2517
				 "as signed due to prototype", argnum, rname);
2491
				 "as signed due to prototype", argnum, rname);
2518
		    }
2492
		    }
2519
		}
2493
		}
(-)pristine/gcc/dfp.c (+16 lines)
Lines 714-716 decimal_real_maxval (REAL_VALUE_TYPE *r, Link Here
714
  if (sign)
714
  if (sign)
715
    r->sig[0] |= 0x80000000;
715
    r->sig[0] |= 0x80000000;
716
}
716
}
717
718
/* Set R to the normalized version of A.  */
719
720
void
721
decimal_normalize (REAL_VALUE_TYPE *r)
722
{
723
  decNumber dn, dn2;
724
  decContext set;
725
726
  decContextDefault (&set, DEC_INIT_DECIMAL128);
727
  set.traps = 0;
728
  set.round = DEC_ROUND_DOWN;
729
  decimal128ToNumber ((decimal128 *)r->sig, &dn2);
730
  decNumberNormalize (&dn, &dn2, &set);
731
  decimal_from_decnumber (r, &dn, &set);
732
}
(-)pristine/gcc/dfp.h (+1 lines)
Lines 44-47 void decimal_real_maxval (REAL_VALUE_TYP Link Here
44
void decimal_real_to_integer2 (HOST_WIDE_INT *, HOST_WIDE_INT *, const REAL_VALUE_TYPE *);
44
void decimal_real_to_integer2 (HOST_WIDE_INT *, HOST_WIDE_INT *, const REAL_VALUE_TYPE *);
45
HOST_WIDE_INT decimal_real_to_integer (const REAL_VALUE_TYPE *);
45
HOST_WIDE_INT decimal_real_to_integer (const REAL_VALUE_TYPE *);
46
46
47
void decimal_normalize (REAL_VALUE_TYPE *);
47
#endif /* GCC_DFP_H */
48
#endif /* GCC_DFP_H */
(-)pristine/gcc/doc/invoke.texi (-9 / +14 lines)
Lines 223-230 Objective-C and Objective-C++ Dialects}. Link Here
223
@xref{Warning Options,,Options to Request or Suppress Warnings}.
223
@xref{Warning Options,,Options to Request or Suppress Warnings}.
224
@gccoptlist{-fsyntax-only  -pedantic  -pedantic-errors @gol
224
@gccoptlist{-fsyntax-only  -pedantic  -pedantic-errors @gol
225
-w  -Wextra  -Wall  -Waggregate-return -Walways-true -Wno-attributes @gol
225
-w  -Wextra  -Wall  -Waggregate-return -Walways-true -Wno-attributes @gol
226
-Wc++-compat -Wcast-align  -Wcast-qual  -Wchar-subscripts  -Wcomment @gol
226
-Wc++-compat -Wcast-align  -Wcast-qual  -Wchar-subscripts -Wcoercion @gol
227
-Wconversion  -Wno-deprecated-declarations @gol
227
-Wcomment -Wtraditional-conversion  -Wno-deprecated-declarations @gol
228
-Wdisabled-optimization  -Wno-div-by-zero  -Wno-endif-labels @gol
228
-Wdisabled-optimization  -Wno-div-by-zero  -Wno-endif-labels @gol
229
-Werror  -Werror-* -Werror-implicit-function-declaration @gol
229
-Werror  -Werror-* -Werror-implicit-function-declaration @gol
230
-Wfatal-errors  -Wfloat-equal  -Wformat  -Wformat=2 @gol
230
-Wfatal-errors  -Wfloat-equal  -Wformat  -Wformat=2 @gol
Lines 3028-3034 traditional C case. Link Here
3028
Conversions by prototypes between fixed/floating point values and vice
3028
Conversions by prototypes between fixed/floating point values and vice
3029
versa.  The absence of these prototypes when compiling with traditional
3029
versa.  The absence of these prototypes when compiling with traditional
3030
C would cause serious problems.  This is a subset of the possible
3030
C would cause serious problems.  This is a subset of the possible
3031
conversion warnings, for the full set use @option{-Wconversion}.
3031
conversion warnings, for the full set use @option{-Wtraditional-conversion}.
3032
3032
3033
@item
3033
@item
3034
Use of ISO C style function definitions.  This warning intentionally is
3034
Use of ISO C style function definitions.  This warning intentionally is
Lines 3116-3133 only if you have been very careful about Link Here
3116
declarations and prototypes.  Otherwise, it will just be a nuisance;
3116
declarations and prototypes.  Otherwise, it will just be a nuisance;
3117
this is why we did not make @option{-Wall} request these warnings.
3117
this is why we did not make @option{-Wall} request these warnings.
3118
3118
3119
@item -Wconversion
3119
@item -Wtraditional-conversion
3120
@opindex Wconversion
3120
@opindex Wtraditional-conversion
3121
Warn if a prototype causes a type conversion that is different from what
3121
Warn if a prototype causes a type conversion that is different from what
3122
would happen to the same argument in the absence of a prototype.  This
3122
would happen to the same argument in the absence of a prototype.  This
3123
includes conversions of fixed point to floating and vice versa, and
3123
includes conversions of fixed point to floating and vice versa, and
3124
conversions changing the width or signedness of a fixed point argument
3124
conversions changing the width or signedness of a fixed point argument
3125
except when the same as the default promotion.
3125
except when the same as the default promotion.
3126
3126
3127
Also, warn if a negative integer constant expression is implicitly
3127
@item -Wcoercion
3128
converted to an unsigned type.  For example, warn about the assignment
3128
@opindex Wcoercion
3129
@code{x = -1} if @code{x} is unsigned.  But do not warn about explicit
3129
Warn for implicit conversions that may alter a value. This includes
3130
casts like @code{(unsigned) -1}.
3130
conversions caused by function prototypes like @code{abs(x)} when
3131
@code{x} is real and by assignments like
3132
@code{unsigned x = -1}. Do not warn about explicit casts like
3133
@code{abs((int)x)} and @code{x = (unsigned) -1}, or if the value is not
3134
changed by the conversion like @code{abs(2.0)}.
3135
3131
3136
3132
@item -Wsign-compare
3137
@item -Wsign-compare
3133
@opindex Wsign-compare
3138
@opindex Wsign-compare
(-)pristine/gcc/doc/trouble.texi (-3 / +3 lines)
Lines 985-994 you are removing prototypes that were ma Link Here
985
the program worked before without any prototypes, it will work again
985
the program worked before without any prototypes, it will work again
986
without them.
986
without them.
987
987
988
@opindex Wconversion
988
@opindex Wtraditional-conversion
989
You can find all the places where this problem might occur by compiling
989
You can find all the places where this problem might occur by compiling
990
the program with the @option{-Wconversion} option.  It prints a warning
990
the program with the @option{-Wtraditional-conversion} option.  It
991
whenever an argument is converted.
991
prints a warning whenever an argument is converted.
992
992
993
@item
993
@item
994
Both conversion programs can be confused if there are macro calls in and
994
Both conversion programs can be confused if there are macro calls in and
(-)pristine/gcc/real.c (-1 / +27 lines)
Lines 482-488 normalize (REAL_VALUE_TYPE *r) Link Here
482
  int i, j;
482
  int i, j;
483
483
484
  if (r->decimal)
484
  if (r->decimal)
485
    {
486
      decimal_normalize(r);
485
    return;
487
    return;
488
    }
486
489
487
  /* Find the first word that is nonzero.  */
490
  /* Find the first word that is nonzero.  */
488
  for (i = SIGSZ - 1; i >= 0; i--)
491
  for (i = SIGSZ - 1; i >= 0; i--)
Lines 2503-2510 exact_real_truncate (enum machine_mode m Link Here
2503
  if (REAL_EXP (a) <= emin2m1)
2506
  if (REAL_EXP (a) <= emin2m1)
2504
    return false;
2507
    return false;
2505
2508
2506
  /* After conversion to the new mode, the value must be identical.  */
2507
  real_convert (&t, mode, a);
2509
  real_convert (&t, mode, a);
2510
2511
  if (a->decimal != t.decimal)
2512
    return !decimal_do_compare(&t, a, -1);
2513
2514
  /* After conversion to the new mode, the value must be identical.  */
2508
  return real_identical (&t, a);
2515
  return real_identical (&t, a);
2509
}
2516
}
2510
2517
Lines 4922-4924 real_copysign (REAL_VALUE_TYPE *r, const Link Here
4922
  r->sign = x->sign;
4929
  r->sign = x->sign;
4923
}
4930
}
4924
4931
4932
/* Check whether the real constant value given is an integer.  */
4933
4934
bool
4935
real_isinteger (const REAL_VALUE_TYPE *c, enum machine_mode mode)
4936
{
4937
  REAL_VALUE_TYPE cint;
4938
4939
  real_trunc (&cint, mode, c);
4940
4941
  if (c->decimal)
4942
    {
4943
      REAL_VALUE_TYPE cnorm;
4944
      cnorm = *c;
4945
      decimal_normalize (&cnorm);
4946
      return real_identical (&cnorm, &cint);
4947
    }
4948
4949
  return real_identical (c, &cint);
4950
}
(-)pristine/gcc/real.h (+3 lines)
Lines 425-428 extern void real_round (REAL_VALUE_TYPE Link Here
425
/* Set the sign of R to the sign of X.  */
425
/* Set the sign of R to the sign of X.  */
426
extern void real_copysign (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
426
extern void real_copysign (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
427
427
428
/* Check whether the real constant value given is an integer.  */
429
extern bool real_isinteger (const REAL_VALUE_TYPE *c, enum machine_mode mode);
430
428
#endif /* ! GCC_REAL_H */
431
#endif /* ! GCC_REAL_H */
(-)pristine/gcc/testsuite/gcc.dg/builtin-protos-1.c (-1 / +1 lines)
Lines 1-5 Link Here
1
/* { dg-do compile } */
1
/* { dg-do compile } */
2
/* { dg-options -Wconversion } */
2
/* { dg-options -Wtraditional-conversion } */
3
3
4
int
4
int
5
test_s (signed int x)
5
test_s (signed int x)
(-)pristine/gcc/testsuite/gcc.dg/dfp/Wcoercion-dfp.c (+78 lines)
Line 0 Link Here
1
/* { dg-do compile } */
2
/* { dg-options "-std=gnu99 -Wcoercion" } */
3
4
void fd32(_Decimal32);
5
void fd64(_Decimal64);
6
void fd128(_Decimal128);
7
void fint (int);
8
9
_Decimal32 d32;
10
_Decimal64 d64;
11
_Decimal128 d128;
12
13
float vfloat;
14
double vdouble;
15
long double vlongdouble;
16
17
void h()
18
{
19
  vfloat = 2.0df;
20
  vdouble = 2.0df;
21
  vlongdouble = 2.0df;
22
23
  vfloat = -7.0dd;
24
  vdouble = -7.0dd;
25
  vlongdouble = -7.0dd;
26
27
  vfloat = 30.0dl;
28
  vdouble = 30.0dl;
29
  vlongdouble = 30.0dl;
30
31
  d32 = 3;
32
  d64 = 3;
33
  d128 = 3;
34
  d32 = -2.0;
35
  d64 = -2.0;
36
  d128 = -2.0;
37
38
  fd128(d128);
39
  fd128(d64);
40
  fd128(d32);
41
  fd64(d64);
42
  fd64(d32);
43
  fd32(d32);
44
45
  fint(2.0df);
46
  fint(2.0dd);
47
  fint(2.0dl);
48
49
  d64 = 123.4df;
50
  d128 = 123.4df;
51
  d128 = 345.678dd;
52
  /* Conversions to smaller types for which the value fits.  */
53
  d32 = 3456.789dd;
54
  d32 = 123.4567dl;
55
  d64 = 1234567890.123456dl;
56
}
57
58
void g()
59
{
60
  vfloat = 2.1df; /* { dg-warning "coercion as 'float' alters '_Decimal32' constant value" } */
61
  vdouble = 2.1df; /* { dg-warning "coercion as 'double' alters '_Decimal32' constant value" } */
62
  vlongdouble = 2.1df; /* { dg-warning "coercion as 'long double' alters '_Decimal32' constant value" } */
63
  fint(2.1df); /* { dg-warning "coercion as 'int' alters '_Decimal32' constant value" } */
64
  fint(2.1dd); /* { dg-warning "coercion as 'int' alters '_Decimal64' constant value" } */
65
  fint(2.1dl); /* { dg-warning "coercion as 'int' alters '_Decimal128' constant value" } */
66
  d32 = 9.99999949E96DD; /* { dg-warning "coercion as '_Decimal32' alters '_Decimal64' constant value" } */
67
  d64 = 9.9999999999999995E384DL;  /* { dg-warning "coercion as '_Decimal64' alters '_Decimal128' constant value" } */
68
  fd32(d128); /* { dg-warning "coercion to '_Decimal32' from '_Decimal128' may alter its value" } */
69
  fd32(d64); /* { dg-warning "coercion to '_Decimal32' from '_Decimal64' may alter its value" } */
70
  fd64(d128); /* { dg-warning "coercion to '_Decimal64' from '_Decimal128' may alter its value" } */
71
  d32 = vfloat; /* { dg-warning "coercion to '_Decimal32' from 'float' may alter its value" } */
72
  d32 = vdouble; /* { dg-warning "coercion to '_Decimal32' from 'double' may alter its value" } */
73
  d64 = vdouble; /* { dg-warning "coercion to '_Decimal64' from 'double' may alter its value" } */
74
  d128 = vdouble; /* { dg-warning "coercion to '_Decimal128' from 'double' may alter its value" } */
75
  vfloat  = d32; /* { dg-warning "coercion to 'float' from '_Decimal32' may alter its value" } */
76
  vdouble = d32; /* { dg-warning "coercion to 'double' from '_Decimal32' may alter its value" } */
77
  vlongdouble = d32; /* { dg-warning "coercion to 'long double' from '_Decimal32' may alter its value" } */
78
}
(-)pristine/gcc/testsuite/gcc.dg/dfp/Wconversion-2.c (-44 lines)
Lines 1-44 Link Here
1
/* Test messages for -Wconversion (based on gcc.dg/Wconversion-2.c).  */
2
/* { dg-do compile } */
3
/* { dg-options "-std=gnu99 -Wconversion" } */
4
5
void fsi(signed int);
6
void fd32(_Decimal32);
7
void fd64(_Decimal64);
8
void fd128(_Decimal128);
9
10
struct s {
11
  void (*fsi)(signed int);
12
  void (*fd32)(_Decimal32);
13
  void (*fd64)(_Decimal64);
14
  void (*fd128)(_Decimal128);
15
} x;
16
17
signed int si;
18
unsigned int ui;
19
_Decimal32 d32;
20
_Decimal64 d64;
21
_Decimal128 d128;
22
23
void
24
g (void)
25
{
26
  fsi(d32); /* { dg-warning "warning: passing argument 1 of 'fsi' as integer rather than floating due to prototype" } */
27
  x.fsi(d32); /* { dg-warning "warning: passing argument 1 of 'x.fsi' as integer rather than floating due to prototype" } */
28
  fsi(d64); /* { dg-warning "warning: passing argument 1 of 'fsi' as integer rather than floating due to prototype" } */
29
  x.fsi(d64); /* { dg-warning "warning: passing argument 1 of 'x.fsi' as integer rather than floating due to prototype" } */
30
  fsi(d128); /* { dg-warning "warning: passing argument 1 of 'fsi' as integer rather than floating due to prototype" } */
31
  x.fsi(d128); /* { dg-warning "warning: passing argument 1 of 'x.fsi' as integer rather than floating due to prototype" } */
32
  fd32(si); /* { dg-warning "warning: passing argument 1 of 'fd32' as floating rather than integer due to prototype" } */
33
  x.fd32(si); /* { dg-warning "warning: passing argument 1 of 'x.fd32' as floating rather than integer due to prototype" } */  
34
  fd64(ui); /* { dg-warning "warning: passing argument 1 of 'fd64' as floating rather than integer due to prototype" } */
35
  x.fd64(ui); /* { dg-warning "warning: passing argument 1 of 'x.fd64' as floating rather than integer due to prototype" } */
36
  fd128(si); /* { dg-warning "warning: passing argument 1 of 'fd128' as floating rather than integer due to prototype" } */
37
  x.fd128(ui); /* { dg-warning "warning: passing argument 1 of 'x.fd128' as floating rather than integer due to prototype" } */  
38
  fd32(1.0); /* { dg-warning "warning: passing argument 1 of 'fd32' as '_Decimal32' rather than 'double' due to prototype" } */
39
  x.fd32(1.0); /* { dg-warning "warning: passing argument 1 of 'x.fd32' as '_Decimal32' rather than 'double' due to prototype" } */
40
  fd64(1.0); /* { dg-warning "warning: passing argument 1 of 'fd64' as '_Decimal64' rather than 'double' due to prototype" } */
41
  x.fd64(1.0); /* { dg-warning "warning: passing argument 1 of 'x.fd64' as '_Decimal64' rather than 'double' due to prototype" } */
42
  fd128(1.0); /* { dg-warning "warning: passing argument 1 of 'fd128' as '_Decimal128' rather than 'double' due to prototype" } */
43
  x.fd128(1.0); /* { dg-warning "warning: passing argument 1 of 'x.fd128' as '_Decimal128' rather than 'double' due to prototype" } */
44
}
(-)pristine/gcc/testsuite/gcc.dg/dfp/wtr-conversion-1.c (-75 lines)
Lines 1-75 Link Here
1
/* Test for -Wtraditional warnings on conversions by prototypes.
2
   Note, gcc should omit these warnings in system header files.
3
   Based on gcc.dg/wtr-conversion-1.c  */
4
5
/* { dg-do compile } */
6
/* { dg-options "-std=gnu99 -Wtraditional" } */
7
8
extern void foo_i (int);
9
extern void foo_f (float);
10
extern void foo_ld (long double);
11
extern void foo_d32 (_Decimal32);
12
extern void foo_d64 (_Decimal64);
13
extern void foo_d128 (_Decimal128);
14
15
extern int i;
16
extern float f;
17
extern long double ld;
18
extern _Decimal32 d32;
19
extern _Decimal64 d64;
20
extern _Decimal128 d128;
21
22
void
23
testfunc1 ()
24
{
25
  foo_i (i);
26
  foo_i (d32); /* { dg-warning "as integer rather than floating" "prototype conversion warning" } */
27
  foo_i (d64); /* { dg-warning "as integer rather than floating" "prototype convDersion warning" } */
28
  foo_i (d128); /* { dg-warning "as integer rather than floating" "prototype conversion warning" } */
29
  foo_d32 (i); /* { dg-warning "as floating rather than integer" "prototype conversion warning" } */
30
  foo_d32 (f); /* { dg-warning "as '_Decimal32' rather than 'float'" "prototype conversion warning" } */
31
  foo_d32 (ld); /* { dg-warning "as '_Decimal32' rather than 'long double'" "prototype conversion warning" } */
32
  foo_d32 (d64); /* { dg-warning "as '_Decimal32' rather than '_Decimal64'" "prototype conversion warning" } */
33
  foo_d32 (d128); /* { dg-warning "as '_Decimal32' rather than '_Decimal128'" "prototype conversion warning" } */
34
  foo_d64 (i); /* { dg-warning "as floating rather than integer" "prototype conversion warning" } */
35
  foo_d64 (f); /* { dg-warning "as '_Decimal64' rather than 'float'" "prototype conversion warning" } */
36
  foo_d64 (ld); /* { dg-warning "as '_Decimal64' rather than 'long double'" "prototype conversion warning" } */
37
  foo_d64 (d32); /* { dg-bogus "as '_Decimal64' rather than '_Decimal32'" "prototype conversion warning" } */
38
  foo_d64 (d128); /* { dg-warning "as '_Decimal64' rather than '_Decimal128'" "prototype conversion warning" } */
39
  foo_d128 (i); /* { dg-warning "as floating rather than integer" "prototype conversion warning" } */
40
  foo_d128 (f); /* { dg-warning "as '_Decimal128' rather than 'float'" "prototype conversion warning" } */
41
  foo_d128 (ld); /* { dg-warning "as '_Decimal128' rather than 'long double'" "prototype conversion warning" } */
42
  foo_d128 (d32); /* { dg-bogus "as '_Decimal128' rather than '_Decimal32'" "prototype conversion warning" } */
43
  foo_d128 (d64); /* { dg-bogus "as '_Decimal128' rather than '_Decimal64'" "prototype conversion warning" } */
44
  foo_d128 (d128); /* { dg-bogus "as '_Decimal128' rather than '_Decimal'" "prototype conversion warning" } */
45
}
46
  
47
# 54 "sys-header.h" 3
48
/* We are in system headers now, no -Wtraditional warnings should issue.  */
49
50
void
51
testfunc2 ()
52
{
53
  foo_i (i);
54
  foo_i (d32);
55
  foo_i (d64);
56
  foo_i (d128);
57
  foo_d32 (i);
58
  foo_d32 (f);
59
  foo_d32 (ld);
60
  foo_d32 (d32);
61
  foo_d32 (d64);
62
  foo_d32 (d128);
63
  foo_d64 (i);
64
  foo_d64 (f);
65
  foo_d64 (ld);
66
  foo_d64 (d32);
67
  foo_d64 (d64);
68
  foo_d64 (d128);
69
  foo_d128 (i);
70
  foo_d128 (f);
71
  foo_d128 (ld);
72
  foo_d128 (d32);
73
  foo_d128 (d64);
74
  foo_d128 (d128);
75
}
(-)pristine/gcc/testsuite/gcc.dg/overflow-warn-1.c (-1 / +1 lines)
Lines 102-108 void Link Here
102
h2i (int x)
102
h2i (int x)
103
{
103
{
104
  /* For some reason, we only give certain warnings for implicit
104
  /* For some reason, we only give certain warnings for implicit
105
     conversions among values of the same precision with -Wconversion,
105
     conversions among values of the same precision with -Wcoercion,
106
     while we don't give others at all.  */
106
     while we don't give others at all.  */
107
  fsi ((unsigned)INT_MAX + 1);
107
  fsi ((unsigned)INT_MAX + 1);
108
  si = (unsigned)INT_MAX + 1;
108
  si = (unsigned)INT_MAX + 1;
(-)pristine/gcc/testsuite/gcc.dg/overflow-warn-2.c (-22 / +22 lines)
Lines 1-7 Link Here
1
/* Test for diagnostics for constant overflow.  Test with -Wconversion.  */
1
/* Test for diagnostics for constant overflow.  Test with -Wtraditional-conversion.  */
2
/* Origin: Joseph Myers <joseph@codesourcery.com> */
2
/* Origin: Joseph Myers <joseph@codesourcery.com> */
3
/* { dg-do compile } */
3
/* { dg-do compile } */
4
/* { dg-options "-std=c99 -Wconversion" } */
4
/* { dg-options "-std=c99 -Wtraditional-conversion" } */
5
5
6
#include <limits.h>
6
#include <limits.h>
7
7
Lines 82-104 void Link Here
82
h2 (void)
82
h2 (void)
83
{
83
{
84
  fsc (SCHAR_MAX + 1);
84
  fsc (SCHAR_MAX + 1);
85
  /* { dg-warning "warning: passing argument 1 of 'fsc' with different width due to prototype" "-Wconversion" { target *-*-* } 84 } */
85
  /* { dg-warning "warning: passing argument 1 of 'fsc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 84 } */
86
  fsc (SCHAR_MIN - 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
86
  fsc (SCHAR_MIN - 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
87
  /* { dg-warning "warning: passing argument 1 of 'fsc' with different width due to prototype" "-Wconversion" { target *-*-* } 86 } */
87
  /* { dg-warning "warning: passing argument 1 of 'fsc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 86 } */
88
  fsc (UCHAR_MAX);
88
  fsc (UCHAR_MAX);
89
  /* { dg-warning "warning: passing argument 1 of 'fsc' with different width due to prototype" "-Wconversion" { target *-*-* } 88 } */
89
  /* { dg-warning "warning: passing argument 1 of 'fsc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 88 } */
90
  fsc (UCHAR_MAX + 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
90
  fsc (UCHAR_MAX + 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
91
  /* { dg-warning "warning: passing argument 1 of 'fsc' with different width due to prototype" "-Wconversion" { target *-*-* } 90 } */
91
  /* { dg-warning "warning: passing argument 1 of 'fsc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 90 } */
92
  fuc (-1); /* { dg-warning "warning: negative integer implicitly converted to unsigned type" } */
92
  fuc (-1);
93
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wconversion" { target *-*-* } 92 } */
93
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 92 } */
94
  fuc (UCHAR_MAX + 1); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
94
  fuc (UCHAR_MAX + 1); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
95
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wconversion" { target *-*-* } 94 } */
95
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 94 } */
96
  fuc (SCHAR_MIN); /* { dg-warning "warning: negative integer implicitly converted to unsigned type" } */
96
  fuc (SCHAR_MIN);
97
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wconversion" { target *-*-* } 96 } */
97
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 96 } */
98
  fuc (SCHAR_MIN - 1); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
98
  fuc (SCHAR_MIN - 1); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
99
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wconversion" { target *-*-* } 98 } */
99
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 98 } */
100
  fuc (-UCHAR_MAX); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
100
  fuc (-UCHAR_MAX); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
101
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wconversion" { target *-*-* } 100 } */
101
  /* { dg-warning "warning: passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } 100 } */
102
}
102
}
103
103
104
void fui (unsigned int);
104
void fui (unsigned int);
Lines 111-117 void Link Here
111
h2i (int x)
111
h2i (int x)
112
{
112
{
113
  /* For some reason, we only give certain warnings for implicit
113
  /* For some reason, we only give certain warnings for implicit
114
     conversions among values of the same precision with -Wconversion,
114
     conversions among values of the same precision with -Wtraditional-conversion,
115
     while we don't give others at all.  */
115
     while we don't give others at all.  */
116
  fsi ((unsigned)INT_MAX + 1); /* { dg-warning "warning: passing argument 1 of 'fsi' as signed due to prototype" } */
116
  fsi ((unsigned)INT_MAX + 1); /* { dg-warning "warning: passing argument 1 of 'fsi' as signed due to prototype" } */
117
  si = (unsigned)INT_MAX + 1;
117
  si = (unsigned)INT_MAX + 1;
Lines 121-132 h2i (int x) Link Here
121
  si = x ? (unsigned)INT_MAX + 2 : 1;
121
  si = x ? (unsigned)INT_MAX + 2 : 1;
122
  fsi (UINT_MAX); /* { dg-warning "warning: passing argument 1 of 'fsi' as signed due to prototype" } */
122
  fsi (UINT_MAX); /* { dg-warning "warning: passing argument 1 of 'fsi' as signed due to prototype" } */
123
  si = UINT_MAX;
123
  si = UINT_MAX;
124
  fui (-1); /* { dg-warning "warning: negative integer implicitly converted to unsigned type" } */
124
  fui (-1);
125
  /* { dg-warning "warning: passing argument 1 of 'fui' as unsigned due to prototype" "-Wconversion" { target *-*-* } 124 } */
125
  /* { dg-warning "warning: passing argument 1 of 'fui' as unsigned due to prototype" "-Wtraditional-conversion" { target *-*-* } 124 } */
126
  ui = -1; /* { dg-warning "warning: negative integer implicitly converted to unsigned type" } */
126
  ui = -1;
127
  ui = x ? -1 : 1U; /* { dg-warning "warning: negative integer implicitly converted to unsigned type" } */
127
  ui = x ? -1 : 1U;
128
  fui (INT_MIN); /* { dg-warning "warning: negative integer implicitly converted to unsigned type" } */
128
  fui (INT_MIN);
129
  /* { dg-warning "warning: passing argument 1 of 'fui' as unsigned due to prototype" "-Wconversion" { target *-*-* } 128 } */
129
  /* { dg-warning "warning: passing argument 1 of 'fui' as unsigned due to prototype" "-Wtraditional-conversion" { target *-*-* } 128 } */
130
  ui = INT_MIN; /* { dg-warning "warning: negative integer implicitly converted to unsigned type" } */
130
  ui = INT_MIN;
131
  ui = x ? INT_MIN : 1U; /* { dg-warning "warning: negative integer implicitly converted to unsigned type" } */
131
  ui = x ? INT_MIN : 1U;
132
}
132
}
(-)pristine/gcc/testsuite/gcc.dg/overflow-warn-3.c (-1 / +1 lines)
Lines 109-115 void Link Here
109
h2i (int x)
109
h2i (int x)
110
{
110
{
111
  /* For some reason, we only give certain warnings for implicit
111
  /* For some reason, we only give certain warnings for implicit
112
     conversions among values of the same precision with -Wconversion,
112
     conversions among values of the same precision with -Wcoercion,
113
     while we don't give others at all.  */
113
     while we don't give others at all.  */
114
  fsi ((unsigned)INT_MAX + 1);
114
  fsi ((unsigned)INT_MAX + 1);
115
  si = (unsigned)INT_MAX + 1;
115
  si = (unsigned)INT_MAX + 1;
(-)pristine/gcc/testsuite/gcc.dg/overflow-warn-4.c (-1 / +1 lines)
Lines 109-115 void Link Here
109
h2i (int x)
109
h2i (int x)
110
{
110
{
111
  /* For some reason, we only give certain warnings for implicit
111
  /* For some reason, we only give certain warnings for implicit
112
     conversions among values of the same precision with -Wconversion,
112
     conversions among values of the same precision with -Wcoercion
113
     while we don't give others at all.  */
113
     while we don't give others at all.  */
114
  fsi ((unsigned)INT_MAX + 1);
114
  fsi ((unsigned)INT_MAX + 1);
115
  si = (unsigned)INT_MAX + 1;
115
  si = (unsigned)INT_MAX + 1;
(-)pristine/gcc/testsuite/gcc.dg/Wcoercion-assignments.c (+87 lines)
Line 0 Link Here
1
/* Test for diagnostics for Wcoercion in assignments.
2
   Origin: Manuel Lopez-Ibanez <lopezibanez@gmail.com> */
3
4
/* { dg-do compile }
5
/* { dg-options "-fsigned-char -std=c99 -Wcoercion" } */
6
7
#include <limits.h>
8
#include <float.h>
9
10
# define M_PI		3.14159265358979323846	/* pi */
11
12
float  vfloat;
13
double vdouble;
14
long double vlongdouble;
15
16
char   vchar;
17
short int vshortint;
18
int vint;
19
long vlongint;
20
long long vlonglong;
21
22
void h(void)
23
{
24
  unsigned int ui = 3;
25
  int   si = 3;
26
  float  f = 3;
27
  double d = 3;
28
29
  vint = 3.1f; /* { dg-warning "coercion" } */
30
  vint = 3.1; /* { dg-warning "coercion" } */
31
  vfloat = INT_MAX; /* { dg-warning "coercion" } */
32
  vfloat = DBL_MIN; /* { dg-warning "coercion" } */
33
  vfloat = M_PI; /* { dg-warning "coercion" } */
34
  vfloat = 3.1; /* { dg-warning "coercion" } */
35
  vint = d; /* { dg-warning "coercion" } */
36
  vfloat = d; /* { dg-warning "coercion" } */
37
  vfloat = si; /* { dg-warning "coercion" } */
38
  vfloat = ui; /* { dg-warning "coercion" } */
39
  vfloat = 16777217; /* { dg-warning "coercion" } */
40
41
  /* No warning */
42
  vint = 3;
43
  vint = 3.0f;
44
  vint = 3.0;
45
  vint = 16777217.0f;
46
  vfloat = 3U;
47
  vfloat = 3;
48
  vfloat = INT_MIN;
49
  vdouble = UINT_MAX;
50
  vdouble = ui;
51
  vfloat = 3.0;
52
  vfloat = 3.1f;
53
  vfloat = 0.25;
54
  vfloat = f;
55
  vdouble = d;
56
  vdouble = f;
57
  vdouble = 16777217;
58
59
}
60
61
62
unsigned char vuc;
63
unsigned int vui;
64
65
void h2(void)
66
{
67
  unsigned int ui = 3;
68
  int   si = 3;
69
  unsigned char uc = 3;
70
  signed char   sc = 3;
71
72
  vint = ui;/* { dg-warning "coercion" } */
73
  vui = si; /* { dg-warning "coercion" } */
74
  vui = sc; /* { dg-warning "coercion" } */
75
  vui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
76
  vui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
77
  vuc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
78
79
  /* no warning */
80
  vint = uc;
81
  vui = uc;
82
  vui = 'A';
83
  vuc = 'A';
84
  vint = 'A';
85
  vchar = 'A';
86
  vchar = '\xa0';
87
}
(-)pristine/gcc/testsuite/gcc.dg/Wcoercion-calls.c (+87 lines)
Line 0 Link Here
1
/* Test for diagnostics for Wcoercion when passing arguments.
2
   Origin: Manuel Lopez-Ibanez <lopezibanez@gmail.com> */
3
4
/* { dg-do compile }
5
/* { dg-options "-fsigned-char -std=c99 -Wcoercion" } */
6
7
#include <limits.h>
8
#include <float.h>
9
10
# define M_PI		3.14159265358979323846	/* pi */
11
12
void fchar(char x);
13
void ffloat(float x);
14
void fdouble(double x);
15
void flongdouble(long double x);
16
17
void fshortint(short int x);
18
void fint(int x);
19
void flongint(long int x);
20
void flonglong(long long x);
21
22
void h(void)
23
{
24
  unsigned int ui = 3;
25
  int   si = 3;
26
  float  f = 3;
27
  double d = 3;
28
29
  fint(3.1f); /* { dg-warning "coercion" } */
30
  fint(3.1); /* { dg-warning "coercion" } */
31
  ffloat(INT_MAX); /* { dg-warning "coercion" } */
32
  ffloat(DBL_MIN); /* { dg-warning "coercion" } */
33
  ffloat(M_PI); /* { dg-warning "coercion" } */
34
  ffloat(3.1); /* { dg-warning "coercion" } */
35
  fint(d); /* { dg-warning "coercion" } */
36
  ffloat(d); /* { dg-warning "coercion" } */
37
  ffloat(si); /* { dg-warning "coercion" } */
38
  ffloat(ui); /* { dg-warning "coercion" } */
39
  ffloat(16777217); /* { dg-warning "coercion" } */
40
41
42
  fint(3);
43
  fint(3.0f);
44
  fint(3.0);
45
  fint(16777217.0f);
46
  ffloat(3U);
47
  ffloat(3);
48
  ffloat(INT_MIN);
49
  fdouble(UINT_MAX);
50
  fdouble(ui);
51
  ffloat(3.0);
52
  ffloat(3.1f);
53
  ffloat(0.25);
54
  ffloat(f);
55
  fdouble(d);
56
  fdouble(f);
57
  fdouble(16777217);
58
59
}
60
61
62
void fuc(unsigned char uc);
63
void fui(unsigned int  ui);
64
65
void h2(void)
66
{
67
  unsigned int ui = 3;
68
  int   si = 3;
69
  unsigned char uc = 3;
70
  signed char   sc = 3;
71
72
  fint(ui); /* { dg-warning "coercion" } */
73
  fui(si);/* { dg-warning "coercion" } */
74
  fui(sc); /* { dg-warning "coercion" } */
75
  fui(-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
76
  fui('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
77
  fuc('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
78
79
80
  fint(uc);
81
  fui(uc);
82
  fui('A');
83
  fuc('A');
84
  fint('A');
85
  fchar('A');
86
  fchar('\xa0');
87
}
(-)pristine/gcc/testsuite/gcc.dg/Wcoercion-negative-constants.c (+67 lines)
Line 0 Link Here
1
/* Test for diagnostics for negative constants coerced to unsigned types
2
   These tests come from gcc/testsuite/gcc.dg/overflow-warn-2.c
3
   Origin: Manuel Lopez-Ibanez <lopezibanez@gmail.com> */
4
5
/* { dg-do compile } */
6
/* { dg-options "-std=c99 -Wcoercion" } */
7
8
#include <limits.h>
9
10
void fuc (unsigned char);
11
12
void hc (int x)
13
{
14
  unsigned char uc;
15
16
  fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
17
  uc = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
18
  uc = x ? 1U : -1; /* { dg-warning "coercion to 'unsigned char' from 'unsigned int' may alter its value" } */
19
  /* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 18 } */
20
  uc = x ? SCHAR_MIN : 1U; /* { dg-warning "coercion to 'unsigned char' from 'unsigned int' may alter its value" } */
21
  /* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 20 } */
22
  uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
23
24
  fuc('A');
25
  uc = 'A';
26
27
  uc = x ? 1 : -1; /* { dg-warning "coercion to 'unsigned char' from 'int' may alter its value" } */
28
29
  uc = x ? SCHAR_MIN : 1; /* { dg-warning "coercion to 'unsigned char' from 'int' may alter its value" } */
30
}
31
32
unsigned fui (unsigned int ui);
33
unsigned fsi (signed int ui);
34
35
void hi (int x)
36
{
37
  unsigned ui;
38
39
  fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
40
  ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
41
  ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
42
  ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
43
  ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
44
  ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
45
  ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
46
47
  ui = -1 * (1 * -1);
48
  ui = (unsigned) -1;
49
50
  ui = x ? 1 : -1; /* { dg-warning "coercion to 'unsigned int' from 'int' may alter its value" } */
51
52
  ui = x ? INT_MIN : 1; /* { dg-warning "coercion to 'unsigned int' from 'int' may alter its value" } */
53
54
  ui = ui ? SCHAR_MIN : 1; /* { dg-warning "coercion to 'unsigned int' from 'int' may alter its value" } */
55
}
56
57
void hs(void)
58
{
59
  fsi(UINT_MAX - 1); /* { dg-warning "coercion as 'int' alters 'unsigned int' constant value" } */
60
  fsi(UINT_MAX - 1U); /* { dg-warning "coercion as 'int' alters 'unsigned int' constant value" } */
61
62
  fsi(UINT_MAX/3U);
63
  fsi(UINT_MAX/3);
64
  fui(UINT_MAX - 1);
65
}
66
67
unsigned fui(unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
(-)pristine/gcc/testsuite/gcc.dg/Wconversion-2.c (-2 / +2 lines)
Lines 1-8 Link Here
1
/* Test messages for -Wconversion, including that they are not
1
/* Test messages for -Wtraditional-conversion, including that they are not
2
   pedwarns.  */
2
   pedwarns.  */
3
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
3
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
4
/* { dg-do compile } */
4
/* { dg-do compile } */
5
/* { dg-options "-std=c99 -pedantic-errors -Wconversion" } */
5
/* { dg-options "-std=c99 -pedantic-errors -Wtraditional-conversion" } */
6
6
7
void fsc(signed char);
7
void fsc(signed char);
8
void fsi(signed int);
8
void fsi(signed int);
(-)pristine/gcc/testsuite/gcc.dg/Wconversion-3.c (-1 / +1 lines)
Lines 1-5 Link Here
1
/* { dg-do compile } */
1
/* { dg-do compile } */
2
/* { dg-options "-O2 -Wconversion" } */
2
/* { dg-options "-O2 -Wcoercion" } */
3
3
4
unsigned f(unsigned a) { return a + -1; }  /* { dg-warning "negative" } */
4
unsigned f(unsigned a) { return a + -1; }  /* { dg-warning "negative" } */
5
5
(-)pristine/gcc/testsuite/gcc.dg/Wconversion.c (-1 / +1 lines)
Lines 5-11 Link Here
5
   not used in the appropriate place in the warning code.  */
5
   not used in the appropriate place in the warning code.  */
6
6
7
/* { dg-do compile } */
7
/* { dg-do compile } */
8
/* { dg-options -Wconversion } */
8
/* { dg-options -Wtraditional-conversion } */
9
9
10
typedef enum { a } __attribute__((packed)) t;
10
typedef enum { a } __attribute__((packed)) t;
11
void f(t x) {}
11
void f(t x) {}
(-)pristine/gcc/testsuite/g++.dg/warn/conv2.C (-2 / +3 lines)
Lines 1-4 Link Here
1
// PR c++/13932
1
// PR c++/13932
2
// { dg-options "-Wconversion" }
2
// { dg-options "-Wcoercion" }
3
3
4
int i = 1.; // { dg-warning "converting" }
4
int i = 1.;
5
int j = 1.1; // { dg-warning "coercion" }
(-)pristine/gcc/testsuite/g++.old-deja/g++.other/warn4.C (-1 / +1 lines)
Lines 1-5 Link Here
1
// { dg-do assemble  }
1
// { dg-do assemble  }
2
// { dg-options "-Wconversion" }
2
// { dg-options "-Wcoercion" }
3
3
4
// Copyright (C) 1999 Free Software Foundation, Inc.
4
// Copyright (C) 1999 Free Software Foundation, Inc.
5
// Contributed by Nathan Sidwell 21 Nov 1999 <nathan@acm.org>
5
// Contributed by Nathan Sidwell 21 Nov 1999 <nathan@acm.org>
(-)pristine/gcc/testsuite/g++.old-deja/g++.warn/impint2.C (-1 / +2 lines)
Lines 1-8 Link Here
1
// { dg-do assemble  }
1
// { dg-do assemble  }
2
// { dg-options "-Wconversion" }
2
// { dg-options "-Wcoercion" }
3
3
4
// Copyright (C) 2000 Free Software Foundation, Inc.
4
// Copyright (C) 2000 Free Software Foundation, Inc.
5
// Contributed by Nathan Sidwell 6 Mar 2000 <nathan@codesourcery.com>
5
// Contributed by Nathan Sidwell 6 Mar 2000 <nathan@codesourcery.com>
6
// Modified by Manuel Lopez-Ibanez 7 Jul 2006 <lopezibanez@gmail.com>
6
7
7
// initialization to 'int' from to 'double' We expect consistent warnings
8
// initialization to 'int' from to 'double' We expect consistent warnings
8
// whenever a float is implicitly truncated to int, make sure references
9
// whenever a float is implicitly truncated to int, make sure references
(-)pristine/gcc/testsuite/g++.old-deja/g++.warn/impint.C (-1 / +3 lines)
Lines 1-7 Link Here
1
// { dg-do assemble  }
1
// { dg-do assemble  }
2
// { dg-options "-Wconversion" }
2
// { dg-options "-Wcoercion" }
3
3
// Copyright (C) 2000 Free Software Foundation, Inc.
4
// Copyright (C) 2000 Free Software Foundation, Inc.
4
// Contributed by Nathan Sidwell 24 Feb 2000 <nathan@codesourcery.com>
5
// Contributed by Nathan Sidwell 24 Feb 2000 <nathan@codesourcery.com>
6
// Modified by Manuel Lopez-Ibanez 7 Jul 2006 <lopezibanez@gmail.com>
5
7
6
// derived from a bug report by Johan Kuipers <j.kuipers@chello.nl>
8
// derived from a bug report by Johan Kuipers <j.kuipers@chello.nl>
7
// initialization to 'int' from to 'double' We expect consistent warnings
9
// initialization to 'int' from to 'double' We expect consistent warnings

Return to bug 26167