PR c/80731 - poor -Woverflow warnings

gcc/c-family/ChangeLog:

	PR c/80731
	* c-common.h (unsafe_conversion_p): Add a function argument.
	* c-common.c (unsafe_conversion_p): Same.
	Add type names and values to diagnostics.
	(scalar_to_vector): Adjust.
	* c-warn.c (constant_expression_error): Add a function argument.
	Add type names and values to diagnostics.
	(conversion_warning): Add a function argument.
	Add type names and values to diagnostics.
	(warnings_for_convert_and_check): Same.

gcc/c/ChangeLog:

	PR c/80731
	* c-fold.c (c_fully_fold_internal): Adjust.
	* c-typeck.c (parser_build_unary_op): Adjust.

gcc/cp/ChangeLog:

	PR c/80731
	* call.c (fully_fold_internal): Adjust.

gcc/testsuite/ChangeLog:

	PR c/80731
	* c-c++-common/Wfloat-conversion.c: Adjust.
	* c-c++-common/dfp/convert-int-saturate.c: Same.
	* c-c++-common/pr68657-1.c: Same.
	* g++.dg/ext/utf-cvt.C: Same.
	* g++.dg/ext/utf16-4.C: Same.
	* g++.dg/warn/Wconversion-real-integer-3.C: Same.
	* g++.dg/warn/Wconversion-real-integer2.C: Same.
	* g++.dg/warn/Wconversion3.C: Same.
	* g++.dg/warn/Wconversion4.C: Same.
	* g++.dg/warn/Wsign-conversion.C: Same.
	* g++.dg/warn/overflow-warn-1.C: Same.
	* g++.dg/warn/overflow-warn-3.C: Same.
	* g++.dg/warn/overflow-warn-4.C: Same.
	* g++.dg/warn/pr35635.C: Same.
	* g++.old-deja/g++.mike/enum1.C: Same.
	* gcc.dg/Wconversion-3.c: Same.
	* gcc.dg/Wconversion-5.c: Same.
	* gcc.dg/Wconversion-complex-c99.c: Same.
	* gcc.dg/Wconversion-complex-gnu.c: Same.
	* gcc.dg/Wconversion-integer.c: Same.
	* gcc.dg/Wsign-conversion.c: Same.
	* gcc.dg/bitfld-2.c: Same.
	* gcc.dg/c90-const-expr-11.c: Same.
	* gcc.dg/c90-const-expr-7.c: Same.
	* gcc.dg/c99-const-expr-7.c: Same.
	* gcc.dg/overflow-warn-1.c: Same.
	* gcc.dg/overflow-warn-2.c: Same.
	* gcc.dg/overflow-warn-3.c: Same.
	* gcc.dg/overflow-warn-4.c: Same.
	* gcc.dg/overflow-warn-5.c: Same.
	* gcc.dg/overflow-warn-8.c: Same.
	* gcc.dg/overflow-warn-9.c: New test.
	* gcc.dg/pr35635.c: Adjust.
	* gcc.dg/pr59940.c: Same.
	* gcc.dg/pr59963-2.c: Same.
	* gcc.dg/pr60114.c: Same.
	* gcc.dg/switch-warn-2.c: Same.
	* gcc.dg/utf-cvt.c: Same.
	* gcc.dg/utf16-4.c: Same.

From-SVN: r248431
This commit is contained in:
Martin Sebor 2017-05-24 22:07:21 +00:00 committed by Martin Sebor
parent 1ab4db9379
commit 3cd211af99
49 changed files with 569 additions and 322 deletions

View file

@ -1,3 +1,16 @@
2017-05-24 Martin Sebor <msebor@redhat.com>
PR c/80731
* c-common.h (unsafe_conversion_p): Add a function argument.
* c-common.c (unsafe_conversion_p): Same.
Add type names and values to diagnostics.
(scalar_to_vector): Adjust.
* c-warn.c (constant_expression_error): Add a function argument.
Add type names and values to diagnostics.
(conversion_warning): Add a function argument.
Add type names and values to diagnostics.
(warnings_for_convert_and_check): Same.
2017-05-19 Jason Merrill <jason@redhat.com>
* c-warn.c (match_case_to_enum_1): Don't warn about enums with no

View file

@ -1227,16 +1227,24 @@ int_safely_convertible_to_real_p (const_tree from_type, const_tree to_type)
can return SAFE_CONVERSION (zero) in that case. Function can produce
signedness warnings if PRODUCE_WARNS is true.
RESULT, when non-null is the result of the conversion. When constant
it is included in the text of diagnostics.
Function allows conversions from complex constants to non-complex types,
provided that imaginary part is zero and real part can be safely converted
to TYPE. */
enum conversion_safety
unsafe_conversion_p (location_t loc, tree type, tree expr, bool produce_warns)
unsafe_conversion_p (location_t loc, tree type, tree expr, tree result,
bool produce_warns)
{
enum conversion_safety give_warning = SAFE_CONVERSION; /* is 0 or false */
tree expr_type = TREE_TYPE (expr);
loc = expansion_point_location_if_in_system_header (loc);
bool cstresult = (result
&& TREE_CODE_CLASS (TREE_CODE (result)) == tcc_constant);
loc = expansion_point_location_if_in_system_header (loc);
if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST)
{
@ -1262,14 +1270,31 @@ unsafe_conversion_p (location_t loc, tree type, tree expr, bool produce_warns)
&& tree_int_cst_sgn (expr) < 0)
{
if (produce_warns)
warning_at (loc, OPT_Wsign_conversion, "negative integer"
" implicitly converted to unsigned type");
{
if (cstresult)
warning_at (loc, OPT_Wsign_conversion,
"unsigned conversion from %qT to %qT "
"changes value from %qE to %qE",
expr_type, type, expr, result);
else
warning_at (loc, OPT_Wsign_conversion,
"unsigned conversion from %qT to %qT "
"changes the value of %qE",
expr_type, type, expr);
}
}
else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type))
{
if (produce_warns)
warning_at (loc, OPT_Wsign_conversion, "conversion of unsigned"
" constant value to negative integer");
if (cstresult)
warning_at (loc, OPT_Wsign_conversion,
"signed conversion from %qT to %qT changes "
"value from %qE to %qE",
expr_type, type, expr, result);
else
warning_at (loc, OPT_Wsign_conversion,
"signed conversion from %qT to %qT changes "
"the value of %qE",
expr_type, type, expr);
}
else
give_warning = UNSAFE_OTHER;
@ -1308,7 +1333,7 @@ unsafe_conversion_p (location_t loc, tree type, tree expr, bool produce_warns)
with different type of EXPR, but it is still safe, because when EXPR
is a constant, it's type is not used in text of generated warnings
(otherwise they could sound misleading). */
return unsafe_conversion_p (loc, type, TREE_REALPART (expr),
return unsafe_conversion_p (loc, type, TREE_REALPART (expr), result,
produce_warns);
/* Conversion from complex constant with non-zero imaginary part. */
else
@ -1328,9 +1353,10 @@ unsafe_conversion_p (location_t loc, tree type, tree expr, bool produce_warns)
Possible solution: add a separate function for checking
constants and combine result of two calls appropriately. */
enum conversion_safety re_safety =
unsafe_conversion_p (loc, type, TREE_REALPART (expr), false);
unsafe_conversion_p (loc, type, TREE_REALPART (expr),
result, false);
enum conversion_safety im_safety =
unsafe_conversion_p (loc, type, imag_part, false);
unsafe_conversion_p (loc, type, imag_part, result, false);
/* Merge the results into appropriate single warning. */
@ -7654,7 +7680,8 @@ scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
if (TREE_CODE (type0) == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
{
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0, false))
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0,
NULL_TREE, false))
{
if (complain)
error_at (loc, "conversion of scalar %qT to vector %qT "
@ -7702,7 +7729,8 @@ scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
if (TREE_CODE (type0) == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
{
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0, false))
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0,
NULL_TREE, false))
{
if (complain)
error_at (loc, "conversion of scalar %qT to vector %qT "
@ -7717,7 +7745,8 @@ scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
|| TREE_CODE (type0) == INTEGER_TYPE)
&& SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1)))
{
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0, false))
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0,
NULL_TREE, false))
{
if (complain)
error_at (loc, "conversion of scalar %qT to vector %qT "

View file

@ -832,7 +832,7 @@ extern tree c_common_signed_type (tree);
extern tree c_common_signed_or_unsigned_type (int, tree);
extern void c_common_init_ts (void);
extern tree c_build_bitfield_integer_type (unsigned HOST_WIDE_INT, int);
extern enum conversion_safety unsafe_conversion_p (location_t, tree, tree,
extern enum conversion_safety unsafe_conversion_p (location_t, tree, tree, tree,
bool);
extern bool decl_with_nonnull_addr_p (const_tree);
extern tree c_fully_fold (tree, bool, bool *);
@ -1483,7 +1483,7 @@ extern bool cilk_recognize_spawn (tree, tree *);
/* In c-warn.c. */
extern void constant_expression_warning (tree);
extern void constant_expression_error (tree);
extern void overflow_warning (location_t, tree);
extern void overflow_warning (location_t, tree, tree = NULL_TREE);
extern void warn_logical_operator (location_t, enum tree_code, tree,
enum tree_code, tree, enum tree_code, tree);
extern void warn_tautological_cmp (location_t, enum tree_code, tree, tree);

View file

@ -63,8 +63,9 @@ constant_expression_error (tree value)
error ("overflow in constant expression");
}
/* Print a warning if an expression had overflow in folding and its
operands hadn't.
/* Print a warning if an expression result VALUE had an overflow
in folding and its operands hadn't. EXPR, which may be null, is
the operand of the expression.
Invoke this function on every expression that
(1) appears in the source code, and
@ -75,42 +76,74 @@ constant_expression_error (tree value)
already overflowed. */
void
overflow_warning (location_t loc, tree value)
overflow_warning (location_t loc, tree value, tree expr)
{
if (c_inhibit_evaluation_warnings != 0)
return;
const char *warnfmt = NULL;
switch (TREE_CODE (value))
{
case INTEGER_CST:
warning_at (loc, OPT_Woverflow, "integer overflow in expression");
warnfmt = (expr
? G_("integer overflow in expression %qE of type %qT "
"results in %qE")
: G_("integer overflow in expression of type %qT "
"results in %qE"));
break;
case REAL_CST:
warning_at (loc, OPT_Woverflow,
"floating point overflow in expression");
warnfmt = (expr
? G_ ("floating point overflow in expression %qE "
"of type %qT results in %qE")
: G_ ("floating point overflow in expression of type %qT "
"results in %qE"));
break;
case FIXED_CST:
warning_at (loc, OPT_Woverflow, "fixed-point overflow in expression");
warnfmt = (expr
? G_("fixed-point overflow in expression %qE of type %qT "
"results in %qE")
: G_("fixed-point overflow in expression of type %qT "
"results in %qE"));
break;
case VECTOR_CST:
warning_at (loc, OPT_Woverflow, "vector overflow in expression");
warnfmt = (expr
? G_("vector overflow in expression %qE of type %qT "
"results in %qE")
: G_("vector overflow in expression of type %qT "
"results in %qE"));
break;
case COMPLEX_CST:
if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST)
warning_at (loc, OPT_Woverflow,
"complex integer overflow in expression");
warnfmt = (expr
? G_("complex integer overflow in expression %qE "
"of type %qT results in %qE")
: G_("complex integer overflow in expression of type %qT "
"results in %qE"));
else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST)
warning_at (loc, OPT_Woverflow,
"complex floating point overflow in expression");
warnfmt = (expr
? G_("complex floating point overflow in expression %qE "
"of type %qT results in %qE")
: G_("complex floating point overflow in expression "
"of type %qT results in %qE"));
else
return;
break;
default:
break;
return;
}
if (expr)
warning_at (loc, OPT_Woverflow, warnfmt, expr, TREE_TYPE (expr), value);
else
warning_at (loc, OPT_Woverflow, warnfmt, TREE_TYPE (value), value);
TREE_NO_WARNING (value) = 1;
}
/* Helper function for walk_tree. Unwrap C_MAYBE_CONST_EXPRs in an expression
@ -930,7 +963,7 @@ check_main_parameter_types (tree decl)
This is a helper function for warnings_for_convert_and_check. */
static void
conversion_warning (location_t loc, tree type, tree expr)
conversion_warning (location_t loc, tree type, tree expr, tree result)
{
tree expr_type = TREE_TYPE (expr);
enum conversion_safety conversion_kind;
@ -971,43 +1004,49 @@ conversion_warning (location_t loc, tree type, tree expr)
case REAL_CST:
case INTEGER_CST:
case COMPLEX_CST:
conversion_kind = unsafe_conversion_p (loc, type, expr, true);
if (conversion_kind == UNSAFE_REAL)
warning_at (loc, OPT_Wfloat_conversion,
"conversion to %qT alters %qT constant value",
type, expr_type);
else if (conversion_kind)
warning_at (loc, OPT_Wconversion,
"conversion to %qT alters %qT constant value",
type, expr_type);
return;
case COND_EXPR:
{
conversion_kind = unsafe_conversion_p (loc, type, expr, result, true);
int warnopt;
if (conversion_kind == UNSAFE_REAL)
warnopt = OPT_Wfloat_conversion;
else if (conversion_kind)
warnopt = OPT_Wconversion;
else
break;
if (TREE_CODE_CLASS (TREE_CODE (result)) == tcc_constant)
warning_at (loc, warnopt,
"conversion from %qT to %qT changes value from %qE to %qE",
expr_type, type, expr, result);
else
warning_at (loc, warnopt,
"conversion from %qT to %qT changes the value of %qE",
expr_type, type, expr);
break;
}
case COND_EXPR:
{
/* In case of COND_EXPR, we do not care about the type of
COND_EXPR, only about the conversion of each operand. */
tree op1 = TREE_OPERAND (expr, 1);
tree op2 = TREE_OPERAND (expr, 2);
conversion_warning (loc, type, op1);
conversion_warning (loc, type, op2);
conversion_warning (loc, type, op1, result);
conversion_warning (loc, type, op2, result);
return;
}
default: /* 'expr' is not a constant. */
conversion_kind = unsafe_conversion_p (loc, type, expr, true);
if (conversion_kind == UNSAFE_REAL)
conversion_kind = unsafe_conversion_p (loc, type, expr, result, true);
if (conversion_kind == UNSAFE_IMAGINARY)
warning_at (loc, OPT_Wconversion,
"conversion from %qT to to %qT discards imaginary "
"component",
expr_type, type);
else if (conversion_kind == UNSAFE_REAL || conversion_kind)
warning_at (loc, OPT_Wfloat_conversion,
"conversion to %qT from %qT may alter its value",
type, expr_type);
else if (conversion_kind == UNSAFE_IMAGINARY)
warning_at (loc, OPT_Wconversion,
"conversion to %qT from %qT discards imaginary component",
type, expr_type);
else if (conversion_kind)
warning_at (loc, OPT_Wconversion,
"conversion to %qT from %qT may alter its value",
type, expr_type);
"conversion from %qT to %qT may change value",
expr_type, type);
}
}
@ -1021,6 +1060,10 @@ warnings_for_convert_and_check (location_t loc, tree type, tree expr,
{
loc = expansion_point_location_if_in_system_header (loc);
bool cst = TREE_CODE_CLASS (TREE_CODE (result)) == tcc_constant;
tree exprtype = TREE_TYPE (expr);
if (TREE_CODE (expr) == INTEGER_CST
&& (TREE_CODE (type) == INTEGER_TYPE
|| TREE_CODE (type) == ENUMERAL_TYPE)
@ -1036,31 +1079,76 @@ warnings_for_convert_and_check (location_t loc, tree type, tree expr,
/* This detects cases like converting -129 or 256 to
unsigned char. */
if (!int_fits_type_p (expr, c_common_signed_type (type)))
warning_at (loc, OPT_Woverflow,
"large integer implicitly truncated to unsigned type");
{
if (cst)
warning_at (loc, OPT_Woverflow,
(TYPE_UNSIGNED (exprtype)
? G_("conversion from %qT to %qT "
"changes value from %qE to %qE")
: G_("unsigned conversion from %qT to %qT "
"changes value from %qE to %qE")),
exprtype, type, expr, result);
else
warning_at (loc, OPT_Woverflow,
(TYPE_UNSIGNED (exprtype)
? G_("conversion from %qT to %qT "
"changes the value of %qE")
: G_("unsigned conversion from %qT to %qT "
"changes the value of %qE")),
exprtype, type, expr);
}
else
conversion_warning (loc, type, expr);
conversion_warning (loc, type, expr, result);
}
else if (!int_fits_type_p (expr, c_common_unsigned_type (type)))
warning_at (loc, OPT_Woverflow,
"overflow in implicit constant conversion");
{
if (cst)
warning_at (loc, OPT_Woverflow,
"overflow in conversion from %qT to %qT "
"changes value from %qE to %qE",
exprtype, type, expr, result);
else
warning_at (loc, OPT_Woverflow,
"overflow in conversion from %qT to %qT "
"changes the value of %qE",
exprtype, type, expr);
}
/* No warning for converting 0x80000000 to int. */
else if (pedantic
&& (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE
|| TYPE_PRECISION (TREE_TYPE (expr))
&& (TREE_CODE (exprtype) != INTEGER_TYPE
|| TYPE_PRECISION (exprtype)
!= TYPE_PRECISION (type)))
warning_at (loc, OPT_Woverflow,
"overflow in implicit constant conversion");
{
if (cst)
warning_at (loc, OPT_Woverflow,
"overflow in conversion from %qT to %qT "
"changes value from %qE to %qE",
exprtype, type, expr, result);
else
warning_at (loc, OPT_Woverflow,
"overflow in conversion from %qT to %qT "
"changes the value of %qE",
exprtype, type, expr);
}
else
conversion_warning (loc, type, expr);
conversion_warning (loc, type, expr, result);
}
else if ((TREE_CODE (result) == INTEGER_CST
|| TREE_CODE (result) == FIXED_CST) && TREE_OVERFLOW (result))
warning_at (loc, OPT_Woverflow,
"overflow in implicit constant conversion");
{
if (cst)
warning_at (loc, OPT_Woverflow,
"overflow in conversion from %qT to %qT "
"chages value from %qE to %qE",
exprtype, type, expr, result);
else
warning_at (loc, OPT_Woverflow,
"overflow in conversion from %qT to %qT "
"chages the value of %qE",
exprtype, type, expr);
}
else
conversion_warning (loc, type, expr);
conversion_warning (loc, type, expr, result);
}
/* Subroutines of c_do_switch_warnings, called via splay_tree_foreach.

View file

@ -1,3 +1,9 @@
2017-05-24 Martin Sebor <msebor@redhat.com>
PR c/80731
* c-fold.c (c_fully_fold_internal): Adjust.
* c-typeck.c (parser_build_unary_op): Adjust.
2017-05-23 Thomas Schwinge <thomas@codesourcery.com>
* c-parser.c (OACC_KERNELS_CLAUSE_MASK): Add

View file

@ -307,7 +307,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
if (TREE_OVERFLOW_P (ret)
&& !TREE_OVERFLOW_P (op0)
&& !TREE_OVERFLOW_P (op1))
overflow_warning (EXPR_LOC_OR_LOC (expr, input_location), ret);
overflow_warning (EXPR_LOC_OR_LOC (expr, input_location), ret, expr);
if (code == LSHIFT_EXPR
&& TREE_CODE (orig_op0) != INTEGER_CST
&& TREE_CODE (TREE_TYPE (orig_op0)) == INTEGER_TYPE
@ -428,7 +428,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
default:
if (TREE_OVERFLOW_P (ret) && !TREE_OVERFLOW_P (op0))
overflow_warning (EXPR_LOCATION (expr), ret);
overflow_warning (EXPR_LOCATION (expr), ret, op0);
break;
}
goto out;

View file

@ -3588,7 +3588,7 @@ parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
result.value = build_unary_op (loc, code, arg.value, false);
if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
overflow_warning (loc, result.value);
overflow_warning (loc, result.value, arg.value);
}
/* We are typically called when parsing a prefix token at LOC acting on

View file

@ -1,3 +1,8 @@
2017-05-24 Martin Sebor <msebor@redhat.com>
PR c/80731
* call.c (fully_fold_internal): Adjust.
2017-05-24 Nathan Sidwell <nathan@acm.org>
* cp-tree.h (ovl_skip_hidden): Declare.

View file

@ -4814,14 +4814,14 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3,
but the warnings (like Wsign-conversion) have already been
given by the scalar build_conditional_expr_1. We still check
unsafe_conversion_p to forbid truncating long long -> float. */
if (unsafe_conversion_p (loc, stype, arg2, false))
if (unsafe_conversion_p (loc, stype, arg2, NULL_TREE, false))
{
if (complain & tf_error)
error_at (loc, "conversion of scalar %qT to vector %qT "
"involves truncation", arg2_type, vtype);
return error_mark_node;
}
if (unsafe_conversion_p (loc, stype, arg3, false))
if (unsafe_conversion_p (loc, stype, arg3, NULL_TREE, false))
{
if (complain & tf_error)
error_at (loc, "conversion of scalar %qT to vector %qT "

View file

@ -1,3 +1,46 @@
2017-05-24 Martin Sebor <msebor@redhat.com>
PR c/80731
* c-c++-common/Wfloat-conversion.c: Adjust.
* c-c++-common/dfp/convert-int-saturate.c: Same.
* c-c++-common/pr68657-1.c: Same.
* g++.dg/ext/utf-cvt.C: Same.
* g++.dg/ext/utf16-4.C: Same.
* g++.dg/warn/Wconversion-real-integer-3.C: Same.
* g++.dg/warn/Wconversion-real-integer2.C: Same.
* g++.dg/warn/Wconversion3.C: Same.
* g++.dg/warn/Wconversion4.C: Same.
* g++.dg/warn/Wsign-conversion.C: Same.
* g++.dg/warn/overflow-warn-1.C: Same.
* g++.dg/warn/overflow-warn-3.C: Same.
* g++.dg/warn/overflow-warn-4.C: Same.
* g++.dg/warn/pr35635.C: Same.
* g++.old-deja/g++.mike/enum1.C: Same.
* gcc.dg/Wconversion-3.c: Same.
* gcc.dg/Wconversion-5.c: Same.
* gcc.dg/Wconversion-complex-c99.c: Same.
* gcc.dg/Wconversion-complex-gnu.c: Same.
* gcc.dg/Wconversion-integer.c: Same.
* gcc.dg/Wsign-conversion.c: Same.
* gcc.dg/bitfld-2.c: Same.
* gcc.dg/c90-const-expr-11.c: Same.
* gcc.dg/c90-const-expr-7.c: Same.
* gcc.dg/c99-const-expr-7.c: Same.
* gcc.dg/overflow-warn-1.c: Same.
* gcc.dg/overflow-warn-2.c: Same.
* gcc.dg/overflow-warn-3.c: Same.
* gcc.dg/overflow-warn-4.c: Same.
* gcc.dg/overflow-warn-5.c: Same.
* gcc.dg/overflow-warn-8.c: Same.
* gcc.dg/overflow-warn-9.c: New test.
* gcc.dg/pr35635.c: Adjust.
* gcc.dg/pr59940.c: Same.
* gcc.dg/pr59963-2.c: Same.
* gcc.dg/pr60114.c: Same.
* gcc.dg/switch-warn-2.c: Same.
* gcc.dg/utf-cvt.c: Same.
* gcc.dg/utf16-4.c: Same.
2017-05-24 Jakub Jelinek <jakub@redhat.com>
* g++.dg/ext/integer-pack2.C: Require int32 effective target.

View file

@ -29,30 +29,30 @@ void h (void)
double d = 0;
long double ld = 0;
ffloat (3.1); /* { dg-warning "conversion to 'float' alters 'double' constant value" } */
vfloat = 3.1; /* { dg-warning "conversion to 'float' alters 'double' constant value" } */
ffloat (3.1L); /* { dg-warning "conversion to 'float' alters 'long double' constant value" } */
vfloat = 3.1L; /* { dg-warning "conversion to 'float' alters 'long double' constant value" } */
fdouble (3.1L); /* { dg-warning "conversion to 'double' alters 'long double' constant value" "" { target large_long_double } } */
vdouble = 3.1L; /* { dg-warning "conversion to 'double' alters 'long double' constant value" "" { target large_long_double } } */
ffloat (vdouble); /* { dg-warning "conversion to 'float' from 'double' may alter its value" } */
vfloat = vdouble; /* { dg-warning "conversion to 'float' from 'double' may alter its value" } */
ffloat (vlongdouble); /* { dg-warning "conversion to 'float' from 'long double' may alter its value" } */
vfloat = vlongdouble; /* { dg-warning "conversion to 'float' from 'long double' may alter its value" } */
fdouble (vlongdouble); /* { dg-warning "conversion to 'double' from 'long double' may alter its value" "" { target large_long_double } } */
vdouble = vlongdouble; /* { dg-warning "conversion to 'double' from 'long double' may alter its value" "" { target large_long_double } } */
ffloat (3.1); /* { dg-warning "conversion from .double. to .float. changes value" } */
vfloat = 3.1; /* { dg-warning "conversion from .double. to .float. changes value" } */
ffloat (3.1L); /* { dg-warning "conversion from .long double. to .float. changes value" } */
vfloat = 3.1L; /* { dg-warning "conversion from .long double. to .float. changes value" } */
fdouble (3.1L); /* { dg-warning "conversion from .long double. to .double. changes value" "" { target large_long_double } } */
vdouble = 3.1L; /* { dg-warning "conversion from .long double. to .double. changes value" "" { target large_long_double } } */
ffloat (vdouble); /* { dg-warning "conversion from .double. to .float. may change value" } */
vfloat = vdouble; /* { dg-warning "conversion from .double. to .float. may change value" } */
ffloat (vlongdouble); /* { dg-warning "conversion from .long double. to .float. may change value" } */
vfloat = vlongdouble; /* { dg-warning "conversion from .long double. to .float. may change value" } */
fdouble (vlongdouble); /* { dg-warning "conversion from .long double. to .double. may change value" } */
vdouble = vlongdouble; /* { dg-warning "conversion from .long double. to .double. may change value" } */
fsi (3.1f); /* { dg-warning "conversion to 'int' alters 'float' constant value" } */
si = 3.1f; /* { dg-warning "conversion to 'int' alters 'float' constant value" } */
fsi (3.1); /* { dg-warning "conversion to 'int' alters 'double' constant value" } */
si = 3.1; /* { dg-warning "conversion to 'int' alters 'double' constant value" } */
fsi (d); /* { dg-warning "conversion to 'int' from 'double' may alter its value" } */
si = d; /* { dg-warning "conversion to 'int' from 'double' may alter its value" } */
ffloat (INT_MAX); /* { dg-warning "conversion to 'float' alters 'int' constant value" } */
vfloat = INT_MAX; /* { dg-warning "conversion to 'float' alters 'int' constant value" } */
ffloat (16777217); /* { dg-warning "conversion to 'float' alters 'int' constant value" } */
vfloat = 16777217; /* { dg-warning "conversion to 'float' alters 'int' constant value" } */
fsi (3.1f); /* { dg-warning "conversion from .float. to .int. changes value" } */
si = 3.1f; /* { dg-warning "conversion from .float. to .int. changes value" } */
fsi (3.1); /* { dg-warning "conversion from .double. to .int. changes value" } */
si = 3.1; /* { dg-warning "conversion from .double. to .int. changes value" } */
fsi (d); /* { dg-warning "conversion from .double. to .int. may change value" } */
si = d; /* { dg-warning "conversion from .double. to .int. may change value" } */
ffloat (INT_MAX); /* { dg-warning "conversion from .int. to .float. changes value" } */
vfloat = INT_MAX; /* { dg-warning "conversion from .int. to .float. changes value" } */
ffloat (16777217); /* { dg-warning "conversion from .int. to .float. changes value from .16777217." } */
vfloat = 16777217; /* { dg-warning "conversion from .int. to .float. changes value from .16777217." } */
sc = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion to 'signed char' alters 'double' constant value" } */
uc = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion to 'unsigned char' alters 'double' constant value" } */
sc = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion from .double. to .signed char. changes the value of .2\.1" } */
uc = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion from .double. to .unsigned char. changes the value of .2\.1" } */
}

View file

@ -23,40 +23,40 @@ main ()
{
/* Unsigned. */
usi = DEC32_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
usi = DEC32_MAX; /* { dg-warning "overflow in conversion" } */
if (usi != UINT_MAX)
FAILURE
usi = DEC64_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
usi = DEC64_MAX; /* { dg-warning "overflow in conversion" } */
if (usi != UINT_MAX)
FAILURE
usi = DEC128_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
usi = DEC128_MAX; /* { dg-warning "overflow in conversion" } */
if (usi != UINT_MAX)
FAILURE
/* Signed. */
si = DEC32_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
si = DEC32_MAX; /* { dg-warning "overflow in conversion" } */
if (si != INT_MAX)
FAILURE
si = DEC64_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
si = DEC64_MAX; /* { dg-warning "overflow in conversion" } */
if (si != INT_MAX)
FAILURE
si = DEC128_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
si = DEC128_MAX; /* { dg-warning "overflow in conversion" } */
if (si != INT_MAX)
FAILURE
si = - DEC32_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
si = - DEC32_MAX; /* { dg-warning "overflow in conversion" } */
if (si != INT_MIN)
FAILURE
si = - DEC64_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
si = - DEC64_MAX; /* { dg-warning "overflow in conversion" } */
if (si != INT_MIN)
FAILURE
si = - DEC128_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
si = - DEC128_MAX; /* { dg-warning "overflow in conversion" } */
if (si != INT_MIN)
FAILURE

View file

@ -5,14 +5,14 @@
void
f1 (void)
{
unsigned int a = -5; /* { dg-error "negative integer implicitly converted to unsigned type" } */
unsigned int a = -5; /* { dg-error "unsigned conversion from .int. to .unsigned int. changes value from .-5. to .\[0-9\]+." } */
(void) a;
}
int
f2 (void)
{
return 3.1f; /* { dg-error "conversion to 'int' alters 'float' constant value" } */
return 3.1f; /* { dg-error "conversion from .float. to .int. changes value" } */
}
int f3 (char *);

View file

@ -21,9 +21,9 @@ extern void full (unsigned long long);
void m(char16_t c0, char32_t c1)
{
f_c (c0); /* { dg-warning "alter its value" } */
fsc (c0); /* { dg-warning "alter its value" } */
fuc (c0); /* { dg-warning "alter its value" } */
f_c (c0); /* { dg-warning "conversion from .char16_t. to .char. may change value" } */
fsc (c0); /* { dg-warning "change value" } */
fuc (c0); /* { dg-warning "change value" } */
f_s (c0); /* { dg-warning "change the sign" } */
fss (c0); /* { dg-warning "change the sign" } */
fus (c0);
@ -37,12 +37,12 @@ void m(char16_t c0, char32_t c1)
fsll (c0);
full (c0);
f_c (c1); /* { dg-warning "alter its value" } */
fsc (c1); /* { dg-warning "alter its value" } */
fuc (c1); /* { dg-warning "alter its value" } */
f_s (c1); /* { dg-warning "alter its value" } */
fss (c1); /* { dg-warning "alter its value" } */
fus (c1); /* { dg-warning "alter its value" } */
f_c (c1); /* { dg-warning "change value" } */
fsc (c1); /* { dg-warning "change value" } */
fuc (c1); /* { dg-warning "change value" } */
f_s (c1); /* { dg-warning "change value" } */
fss (c1); /* { dg-warning "change value" } */
fus (c1); /* { dg-warning "change value" } */
f_i (c1); /* { dg-warning "change the sign" } */
fsi (c1); /* { dg-warning "change the sign" } */
fui (c1);

View file

@ -10,9 +10,9 @@ const static char16_t c2 = u'\U00064321'; /* { dg-warning "constant too long" }
const static char16_t c3 = 'a';
const static char16_t c4 = U'a';
const static char16_t c5 = U'\u2029';
const static char16_t c6 = U'\U00064321'; /* { dg-warning "implicitly truncated" } */
const static char16_t c6 = U'\U00064321'; /* { dg-warning "conversion from .char32_t. to .char16_t. changes value from .410401. to .17185." } */
const static char16_t c7 = L'a';
const static char16_t c8 = L'\u2029';
const static char16_t c9 = L'\U00064321'; /* { dg-warning "implicitly truncated" "" { target { 4byte_wchar_t } } } */
const static char16_t c9 = L'\U00064321'; /* { dg-warning "unsigned conversion from .wchar_t. to .char16_t. changes value from .410401. to .17185." "" { target { 4byte_wchar_t } } } */
/* { dg-warning "constant too long" "" { target { ! 4byte_wchar_t } } .-1 } */
int main () {}

View file

@ -16,5 +16,5 @@ void h (void)
// the locus that inside the source code here, at the relevant
// line below, even with -ftrack-macro-expansion. We don't want
// it to point to the any locus that is inside the system header.
vfloat = INT_MAX; // { dg-warning "conversion to .float. alters .int. constant value" }
vfloat = INT_MAX; // { dg-warning "conversion from .int. to .float. changes value from .2147483647. to " }
}

View file

@ -23,7 +23,7 @@
//
// That is more useful.
#define INT_MAX __INT_MAX__ // { dg-warning "17: conversion to .float. alters .int. constant value" }
#define INT_MAX __INT_MAX__ // { dg-warning "17: conversion from 'int' to 'float' changes value from .2147483647. to " }
float vfloat;

View file

@ -19,9 +19,9 @@ void test1 (void)
unsigned char f = (int) uc;
signed char g = (int) sc;
unsigned char h = (unsigned int) (short int) uc;
signed char i = (int) (unsigned short int) sc; // { dg-warning "may alter its value" }
unsigned char j = (unsigned int) (short int) us; // { dg-warning "may alter its value" }
signed char k = (int) (unsigned short int) ss; // { dg-warning "may alter its value" }
signed char i = (int) (unsigned short int) sc; // { dg-warning "may change value" }
unsigned char j = (unsigned int) (short int) us; // { dg-warning "may change value" }
signed char k = (int) (unsigned short int) ss; // { dg-warning "may change value" }
}
void test2 (void)

View file

@ -7,7 +7,7 @@ class Test
{
void eval()
{
foo(bar()); // { dg-warning "may alter its value" }
foo(bar()); // { dg-warning "may change value" }
}
unsigned int bar() const

View file

@ -40,26 +40,26 @@ void h (int x)
fuc ('A');
uc = 'A';
uc = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? 1U : -1; /* { dg-warning "unsigned conversion" } */
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "unsigned conversion" } */
uc = x ? 1 : -1; /* { dg-warning "unsigned conversion" } */
uc = x ? SCHAR_MIN : 1; /* { dg-warning "unsigned conversion" } */
ui = x ? 1U : -1; /* { dg-warning "unsigned conversion" } */
ui = x ? INT_MIN : 1U; /* { dg-warning "unsigned conversion" } */
ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "unsigned conversion" } */
ui = 1U * -1; /* { dg-warning "unsigned conversion" } */
ui = ui + INT_MIN; /* { dg-warning "unsigned conversion" } */
ui = x ? 1 : -1; /* { dg-warning "unsigned conversion" } */
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "unsigned conversion" } */
fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fuc (-1); /* { dg-warning "unsigned conversion" } */
uc = -1; /* { dg-warning "unsigned conversion" } */
fui (-1); /* { dg-warning "unsigned conversion" } */
ui = -1; /* { dg-warning "unsigned conversion" } */
fuc ('\xa0'); /* { dg-warning "unsigned conversion" } */
uc = '\xa0'; /* { dg-warning "unsigned conversion" } */
fui ('\xa0');/* { dg-warning "unsigned conversion" } */
ui = '\xa0'; /* { dg-warning "unsigned conversion" } */
fsi (0x80000000); /* { dg-warning "conversion" } */
si = 0x80000000; /* { dg-warning "conversion" } */
@ -91,5 +91,5 @@ void h (int x)
ui = sc; /* { dg-warning "conversion" } */
}
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "unsigned conversion" } */

View file

@ -102,14 +102,14 @@ void
h2 (void)
{
fsc (SCHAR_MAX + 1);
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fsc (UCHAR_MAX);
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fuc (-1);
fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (UCHAR_MAX + 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
fuc (SCHAR_MIN);
fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (SCHAR_MIN - 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
fuc (-UCHAR_MAX); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
}
void fui (unsigned int);

View file

@ -100,15 +100,15 @@ void fsc (signed char);
void
h2 (void)
{
fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fsc (UCHAR_MAX); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fuc (-1);
fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (UCHAR_MAX + 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
fuc (SCHAR_MIN);
fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (SCHAR_MIN - 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
fuc (-UCHAR_MAX); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
}
void fui (unsigned int);

View file

@ -103,15 +103,15 @@ void fsc (signed char);
void
h2 (void)
{
fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in conversion" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in conversion" } */
fsc (UCHAR_MAX); /* { dg-warning "overflow in conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in conversion" } */
fuc (-1);
fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (UCHAR_MAX + 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
fuc (SCHAR_MIN);
fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (SCHAR_MIN - 1); /* { dg-warning "unsigned conversion" } */
fuc (-UCHAR_MAX); /* { dg-warning "unsigned conversion" } */
}
void fui (unsigned int);

View file

@ -63,7 +63,7 @@ void func3()
warn. */
uchar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */
uchar_x = bar != 0
? (unsigned char) 1024 /* { dg-warning "negative integer implicitly converted to unsigned type" } */
? (unsigned char) 1024 /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes the value of .-1." } */
: -1;
}

View file

@ -8,4 +8,4 @@ struct Type {
void setBTK();
};
void Type::setBTK() { kind = DTK; } // { dg-warning "truncate" }
void Type::setBTK() { kind = DTK; } // { dg-warning "conversion from '\[^\n\r]+' to .unsigned char:1. changes value from" }

View file

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O2 -Wconversion" } */
unsigned f(unsigned a) { return a + -1; } /* { dg-warning "negative" } */
unsigned f(unsigned a) { return a + -1; } /* { dg-warning "conversion" } */

View file

@ -19,9 +19,9 @@ void test1 (void)
unsigned char f = (int) uc;
signed char g = (int) sc;
unsigned char h = (unsigned int) (short int) uc;
signed char i = (int) (unsigned short int) sc; /* { dg-warning "may alter its value" "" { target { int32plus } } } */
unsigned char j = (unsigned int) (short int) us; /* { dg-warning "may alter its value" } */
signed char k = (int) (unsigned short int) ss; /* { dg-warning "may alter its value" } */
signed char i = (int) (unsigned short int) sc; /* { dg-warning "conversion from .int. to .signed char. may change value" "" { target { int32plus } } } */
unsigned char j = (unsigned int) (short int) us; /* { dg-warning "may change value" } */
signed char k = (int) (unsigned short int) ss; /* { dg-warning "may change value" } */
}
void test2 (void)

View file

@ -63,10 +63,10 @@ var_complex_narrowing (void)
double _Complex doublec = 0.;
vdoublec = floatc;
vfloatc = doublec; /* { dg-warning "float-conversion" } */
vfloatc = doublec; /* { dg-warning "conversion from .complex double. to .complex float. may change value" } */
fdoublec (floatc);
ffloatc (doublec); /* { dg-warning "float-conversion" } */
ffloatc (doublec); /* { dg-warning "conversion from .complex double. to .complex float. may change value" } */
}
/* Check implicit conversions of complex values to integers. */

View file

@ -32,11 +32,11 @@ var_float_to_int (void)
{
double _Complex doublec = 0.;
fsic (doublec); /* { dg-warning "float-conversion" } */
fuic (doublec); /* { dg-warning "float-conversion" } */
fsic (doublec); /* { dg-warning "conversion" } */
fuic (doublec); /* { dg-warning "conversion" } */
vsic = doublec; /* { dg-warning "float-conversion" } */
vuic = doublec; /* { dg-warning "float-conversion" } */
vsic = doublec; /* { dg-warning "conversion" } */
vuic = doublec; /* { dg-warning "conversion" } */
}
/* Check implicit conversions of integer complex-domain values to integer
@ -75,9 +75,9 @@ const_float_to_int (void)
vsic = 1. - 1.i;
vuic = 1. + 1.i;
fsic (0.5 + 0.i); /* { dg-warning "float-conversion" } */
vsic = 0.5 + 0.i; /* { dg-warning "float-conversion" } */
fuic (0.5 + 0.i); /* { dg-warning "float-conversion" } */
fsic (0.5 + 0.i); /* { dg-warning "conversion" } */
vsic = 0.5 + 0.i; /* { dg-warning "conversion" } */
fuic (0.5 + 0.i); /* { dg-warning "conversion" } */
}
/* Check implicit conversions of integer complex-domain constants to integer
@ -96,8 +96,8 @@ const_complex_int_to_real_int (void)
fui (UINT_MAX + 1ull + 0i); /* { dg-warning "conversion" } */
vui = UINT_MAX + 1ull + 0i; /* { dg-warning "conversion" } */
ffloat (UINT_MAX + 0i); /* { dg-warning "float-conversion" } */
vfloat = UINT_MAX + 0i; /* { dg-warning "float-conversion" } */
ffloat (UINT_MAX + 0i); /* { dg-warning "conversion" } */
vfloat = UINT_MAX + 0i; /* { dg-warning "conversion" } */
}
void
@ -116,12 +116,12 @@ const_complex_int_narrowing (void)
vuic = (UINT_MAX + 1ull) + 1i; /* { dg-warning "conversion" } */
vuic = (UINT_MAX + 1ull) + (UINT_MAX + 1ull) * 1i; /* { dg-warning "conversion" } */
ffloatc (UINT_MAX * 1i); /* { dg-warning "float-conversion" } */
ffloatc (UINT_MAX + 1i); /* { dg-warning "float-conversion" } */
ffloatc (UINT_MAX + UINT_MAX * 1i); /* { dg-warning "float-conversion" } */
ffloatc (UINT_MAX * 1i); /* { dg-warning "conversion" } */
ffloatc (UINT_MAX + 1i); /* { dg-warning "conversion" } */
ffloatc (UINT_MAX + UINT_MAX * 1i); /* { dg-warning "conversion" } */
vfloatc = UINT_MAX * 1i; /* { dg-warning "float-conversion" } */
vfloatc = UINT_MAX + 1i; /* { dg-warning "float-conversion" } */
vfloatc = UINT_MAX + UINT_MAX * 1i; /* { dg-warning "float-conversion" } */
vfloatc = UINT_MAX * 1i; /* { dg-warning "conversion" } */
vfloatc = UINT_MAX + 1i; /* { dg-warning "conversion" } */
vfloatc = UINT_MAX + UINT_MAX * 1i; /* { dg-warning "conversion" } */
}

View file

@ -40,28 +40,28 @@ void h (int x)
fuc ('A');
uc = 'A';
uc = x ? 1U : -1; /* { dg-warning " conversion" "conversion" } */
/* { dg-warning "negative integer implicitly converted to unsigned type" "implicit" { target *-*-* } .-1 } */
uc = x ? SCHAR_MIN : 1U; /* { dg-warning " conversion" "conversion" } */
/* { dg-warning "negative integer implicitly converted to unsigned type" "implicit" { target *-*-* } .-1 } */
uc = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? 1U : -1; /* { dg-warning "conversion from .unsigned int. to .unsigned char." } */
/* { dg-warning "unsigned conversion" "implicit" { target *-*-* } .-1 } */
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "unsigned conversion" } */
/* { dg-warning "conversion from .unsigned int. to .unsigned char." "implicit" { target *-*-* } .-1 } */
uc = x ? 1 : -1; /* { dg-warning "signed conversion" } */
uc = x ? SCHAR_MIN : 1; /* { dg-warning "signed conversion" } */
ui = x ? 1U : -1; /* { dg-warning "signed conversion" } */
ui = x ? INT_MIN : 1U; /* { dg-warning "signed conversion" } */
ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "signed conversion" } */
ui = 1U * -1; /* { dg-warning "signed conversion" } */
ui = ui + INT_MIN; /* { dg-warning "signed conversion" } */
ui = x ? 1 : -1; /* { dg-warning "signed conversion" } */
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "signed conversion" } */
fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fuc (-1); /* { dg-warning "signed conversion" } */
uc = -1; /* { dg-warning "signed conversion" } */
fui (-1); /* { dg-warning "signed conversion" } */
ui = -1; /* { dg-warning "signed conversion" } */
fuc ('\xa0'); /* { dg-warning "signed conversion" } */
uc = '\xa0'; /* { dg-warning "signed conversion" } */
fui ('\xa0');/* { dg-warning "signed conversion" } */
ui = '\xa0'; /* { dg-warning "signed conversion" } */
fsi (0x80000000); /* { dg-warning "conversion" } */
si = 0x80000000; /* { dg-warning "conversion" } */
@ -93,6 +93,6 @@ void h (int x)
ui = sc; /* { dg-warning "conversion" } */
}
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "signed conversion" } */

View file

@ -40,28 +40,28 @@ void h (int x)
fuc ('A');
uc = 'A';
uc = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = x ? 1U : -1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value from .-1. to .\[0-9\]+." } */
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value from .-\[0-9\]+. to .\[0-9\]+." } */
uc = x ? 1 : -1; /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes the value of .-1." } */
uc = x ? SCHAR_MIN : 1; /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes the value of .-\[0-9\]+." } */
ui = x ? 1U : -1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value from .-1. to .\[0-9\]+." } */
ui = x ? INT_MIN : 1U; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value from .-\[0-9\]+. to .\[0-9\]+." } */
ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value " } */
ui = 1U * -1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value " } */
ui = ui + INT_MIN; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value " } */
ui = x ? 1 : -1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes the value of .-1." } */
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes the value of " } */
fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
fsi (0x80000000); /* { dg-warning "conversion" } */
si = 0x80000000; /* { dg-warning "conversion" } */
fuc (-1); /* { dg-warning "unsigned conversion" } */
uc = -1; /* { dg-warning "unsigned conversion" } */
fui (-1); /* { dg-warning "unsigned conversion" } */
ui = -1; /* { dg-warning "unsigned conversion" } */
fuc ('\xa0'); /* { dg-warning "unsigned conversion" } */
uc = '\xa0'; /* { dg-warning "unsigned conversion" } */
fui ('\xa0');/* { dg-warning "unsigned conversion" } */
ui = '\xa0'; /* { dg-warning "unsigned conversion" } */
fsi (0x80000000); /* { dg-warning "signed conversion" } */
si = 0x80000000; /* { dg-warning "signed conversion" } */
fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */
@ -85,12 +85,12 @@ void h (int x)
uc = sc; /* { dg-warning "conversion" } */
fsi (ui); /* { dg-warning "conversion" } */
si = ui; /* { dg-warning "conversion" } */
fui (si); /* { dg-warning "conversion" } */
ui = si; /* { dg-warning "conversion" } */
fui (si); /* { dg-warning "conversion" } */
ui = si; /* { dg-warning "conversion" } */
fui (sc); /* { dg-warning "conversion" } */
ui = sc; /* { dg-warning "conversion" } */
}
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value" } */

View file

@ -11,13 +11,13 @@ struct bf
int b: 2;
};
struct bf p = {4, 0}; /* { dg-warning "truncated" } */
struct bf q = {0, 2}; /* { dg-warning "overflow" } */
struct bf r = {3, -2}; /* { dg-bogus "(truncated|overflow)" } */
struct bf p = {4, 0}; /* { dg-warning "unsigned conversion from .int. to 'unsigned char:2' changes value from .4. to .0." } */
struct bf q = {0, 2}; /* { dg-warning "overflow in conversion from .int. to .signed char:2. changes value from .2. to .-2." } */
struct bf r = {3, -2}; /* { dg-bogus "(trunc|overflow)" } */
void foo ()
{
p.a = 4, p.b = 0; /* { dg-warning "truncated" } */
q.a = 0, q.b = 2; /* { dg-warning "overflow" } */
r.a = 3, r.b = -2; /* { dg-bogus "(truncated|overflow)" } */
p.a = 4, p.b = 0; /* { dg-warning "unsigned conversion from .int. to .unsigned char:2. changes value from .4. to .0." } */
q.a = 0, q.b = 2; /* { dg-warning "overflow in conversion from .int. to .signed char:2. changes value from .2. to .-2." } */
r.a = 3, r.b = -2; /* { dg-bogus "(trunc|overflow)" } */
}

View file

@ -20,7 +20,7 @@ f (void)
/* Overflow. */
struct t b = { INT_MAX + 1 }; /* { dg-warning "integer overflow in expression" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
struct t c = { DBL_MAX }; /* { dg-warning "overflow in implicit constant conversion" } */
struct t c = { DBL_MAX }; /* { dg-warning "overflow in conversion from .double. to .int. chages value " } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
/* Bad operator outside sizeof. */
struct s d = { 1 ? 1.0 : atan (a.d) }; /* { dg-error "is not a constant expression|near initialization" } */

View file

@ -6,10 +6,10 @@
#include <float.h>
int a = DBL_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
int a = DBL_MAX; /* { dg-warning "overflow in conversion" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
int b = (int) DBL_MAX; /* { dg-error "overflow" } */
unsigned int c = -1.0; /* { dg-warning "overflow in implicit constant conversion" } */
unsigned int c = -1.0; /* { dg-warning "overflow in conversion" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
unsigned int d = (unsigned)-1.0; /* { dg-error "overflow" } */
@ -31,5 +31,5 @@ int h1 = (0 ? 0 >> -1: 0);
int i = -1 << 0;
int j[1] = { DBL_MAX }; /* { dg-warning "overflow in implicit constant conversion" } */
int j[1] = { DBL_MAX }; /* { dg-warning "overflow in conversion" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */

View file

@ -7,10 +7,10 @@
#include <float.h>
#include <limits.h>
int a = DBL_MAX; /* { dg-warning "overflow in implicit constant conversion" } */
int a = DBL_MAX; /* { dg-warning "overflow in conversion" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
int b = (int) DBL_MAX; /* { dg-error "overflow" } */
unsigned int c = -1.0; /* { dg-warning "overflow in implicit constant conversion" } */
unsigned int c = -1.0; /* { dg-warning "overflow in conversion" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
unsigned int d = (unsigned)-1.0; /* { dg-error "overflow" } */
@ -33,7 +33,7 @@ int h1 = (0 ? 0 >> -1: 0);
int i = -1 << 0;
/* { dg-error "constant" "constant" { target *-*-* } .-1 } */
int j[1] = { DBL_MAX }; /* { dg-warning "overflow in implicit constant conversion" } */
int j[1] = { DBL_MAX }; /* { dg-warning "overflow in conversion" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
int array[2] = { [0 * (INT_MAX + 1)] = 0 }; /* { dg-warning "integer overflow in expression" } */

View file

@ -85,14 +85,14 @@ void
h2 (void)
{
fsc (SCHAR_MAX + 1);
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value " } */
fsc (UCHAR_MAX);
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value from " } */
fuc (-1);
fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (UCHAR_MAX + 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value " } */
fuc (SCHAR_MIN);
fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (SCHAR_MIN - 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value " } */
fuc (-UCHAR_MAX); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value " } */
}
void fui (unsigned int);

View file

@ -86,21 +86,21 @@ h2 (void)
{
fsc (SCHAR_MAX + 1);
/* { dg-warning "passing argument 1 of 'fsc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
/* { dg-warning "passing argument 1 of 'fsc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
fsc (UCHAR_MAX);
/* { dg-warning "passing argument 1 of 'fsc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in conversion from 'int' to 'signed char' changes value " } */
/* { dg-warning "passing argument 1 of 'fsc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
fuc (-1);
/* { dg-warning "passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (UCHAR_MAX + 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value " } */
/* { dg-warning "passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
fuc (SCHAR_MIN);
/* { dg-warning "passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (SCHAR_MIN - 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value " } */
/* { dg-warning "passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (-UCHAR_MAX); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
/* { dg-warning "passing argument 1 of 'fuc' with different width due to prototype" "-Wtraditional-conversion" { target *-*-* } .-1 } */
}

View file

@ -91,15 +91,15 @@ void fsc (signed char);
void
h2 (void)
{
fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fsc (UCHAR_MAX); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value " } */
fuc (-1);
fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (UCHAR_MAX + 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
fuc (SCHAR_MIN);
fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (SCHAR_MIN - 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
fuc (-UCHAR_MAX); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
}
void fui (unsigned int);

View file

@ -21,7 +21,7 @@ enum e {
E5 = INT_MAX + 1, /* { dg-warning "integer overflow in expression" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
/* Again, overflow in evaluated subexpression. */
E6 = 0 * (INT_MAX + 1), /* { dg-warning "integer overflow in expression" } */
E6 = 0 * (INT_MAX + 1), /* { dg-warning "integer overflow in expression of type .int. results in .-\[0-9\]+." } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
/* A cast does not constitute overflow in conversion. */
E7 = (char) INT_MAX
@ -91,15 +91,15 @@ void fsc (signed char);
void
h2 (void)
{
fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */
fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in conversion from .int. to .signed char. changes value" } */
fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in conversion" } */
fsc (UCHAR_MAX); /* { dg-warning "overflow in conversion" } */
fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in conversion" } */
fuc (-1);
fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (UCHAR_MAX + 1); /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value" } */
fuc (SCHAR_MIN);
fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */
fuc (SCHAR_MIN - 1); /* { dg-warning "unsigned conversion" } */
fuc (-UCHAR_MAX); /* { dg-warning "unsigned conversion" } */
}
void fui (unsigned int);

View file

@ -3,5 +3,5 @@
/* { dg-options "-Woverflow" } */
unsigned char rx_async(unsigned char p) {
return p & 512; /* { dg-warning "overflow in implicit constant conversion" } */
return p & 512; /* { dg-warning "overflow in conversion from .int. to .unsigned char. chages value" } */
}

View file

@ -7,7 +7,7 @@ void foo (int j)
int i3 = 1 + INT_MAX; /* { dg-warning "integer overflow" } */
int i4 = +1 + INT_MAX; /* { dg-warning "integer overflow" } */
int i5 = (int)((double)1.0 + INT_MAX);
int i6 = (double)1.0 + INT_MAX; /* { dg-warning "overflow in implicit constant" } */
int i6 = (double)1.0 + INT_MAX; /* { dg-warning "overflow in conversion from .double. to .int. chages value" } */
int i7 = 0 ? (int)(double)1.0 + INT_MAX : 1;
int i8 = 1 ? 1 : (int)(double)1.0 + INT_MAX;
int i9 = j ? (int)(double)1.0 + INT_MAX : 1; /* { dg-warning "integer overflow" } */

View file

@ -0,0 +1,64 @@
/* PR c/80731 - poor -Woverflow warnings, missing detail
{ dg-do compile }
{ dg-options "-Wconversion -Woverflow -Wno-override-init -std=c99" }
{ dg-require-effective-target int32plus } */
#include <limits.h>
struct Types
{
signed char sc;
unsigned char uc;
signed short ss;
unsigned short us;
signed int si;
unsigned int ui;
signed long sl;
unsigned long ul;
signed long long sll;
unsigned long long ull;
};
const struct Types t1 = {
/* According to 6.3.1.3 of C11:
-2- Otherwise, if the new type is unsigned, the value is converted
by repeatedly adding or subtracting one more than the maximum
value that can be represented in the new type until the value
is in the range of the new type.
These conversions are diagnosed by -Wsign-conversion and -Wconversion,
respectively, by mentioning "unsigned conversion" if the conversion
results in sign change, and just "conversion" otherwise, as follows: */
.uc = SCHAR_MIN, /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value from .-128. to .128." } */
.uc = -1, /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes value from .-1. to .255." } */
.uc = UCHAR_MAX + 1, /* { dg-warning "conversion from 'int' to 'unsigned char' changes value from .256. to .0." } */
.uc = UCHAR_MAX * 2, /* { dg-warning "conversion from 'int' to 'unsigned char' changes value from .510. to .254." } */
/* According to 6.3.1.3 of C11:
-3- Otherwise, the new type is signed and the value cannot be
represented in it; either the result is implementation-defined
or an implementation-defined signal is raised.
In GCC such conversions wrap and are diagnosed by mentioning "overflow"
if the absolute value of the operand is in excess of the maximum of
the destination of type, and "conversion" otherwise, as follows: */
.sc = SCHAR_MAX + 1, /* { dg-warning "conversion from .int. to .signed char. changes value from .128. to .-128." } */
.sc = SCHAR_MAX + 2, /* { dg-warning "conversion from .int. to .signed char. changes value from .129. to .-127." } */
.sc = SCHAR_MAX * 2, /* { dg-warning "conversion from .int. to .signed char. changes value from .254. to .-2." } */
.sc = SCHAR_MAX * 2 + 3, /* { dg-warning "conversion from .int. to .signed char. changes value from .257. to .1." } */
.sc = SCHAR_MAX * 3 + 3, /* { dg-warning "conversion from .int. to .signed char. changes value from .384. to .-128." } */
.ss = SHRT_MAX + 1, /* { dg-warning "conversion from 'int' to 'short int' changes value from .32768. to .-32768." } */
.us = USHRT_MAX + 1, /* { dg-warning "unsigned conversion from .int. to .short unsigned int. changes value from .65536. to .0." } */
.si = INT_MAX + 1LU, /* { dg-warning "signed conversion from 'long unsigned int. to 'int' changes value from .2147483648. to .-2147483648." } */
.ui = UINT_MAX + 1L, /* { dg-warning "signed conversion from .long int. to .unsigned int. changes value from .4294967296. to .0." } */
.ui = UINT_MAX + 1LU, /* { dg-warning "conversion from .long unsigned int. to .unsigned int. changes value from .4294967296. to .0." } */
.sl = LONG_MAX + 1LU, /* { dg-warning "signed conversion from .long unsigned int. to .long int. changes value from .9223372036854775808. to .-9223372036854775808." } */
.ul = ULONG_MAX + 1LU /* there should be some warning here */
};

View file

@ -32,7 +32,7 @@ void func1()
/* At least one branch of ? does not fit in the destination, thus
warn. */
unsigned_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */
unsigned_bit.x = bar != 0 ? 0 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
unsigned_bit.x = bar != 0 ? 0 : -1; /* { dg-warning "-Wsign-conversion" } */
}
void func2()
@ -62,7 +62,7 @@ void func3()
/* At least one branch of ? does not fit in the destination, thus
warn. */
uchar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */
uchar_x = bar != 0 /* { dg-warning "negative integer implicitly converted to unsigned type" } */
uchar_x = bar != 0 /* { dg-warning "-Wsign-conversion" } */
? (unsigned char) 1024
: -1;
}

View file

@ -9,13 +9,13 @@ int
g (void)
{
sitype si = 12;
unsigned int ui = -1; /* { dg-warning "21:negative integer implicitly converted to unsigned type" } */
unsigned int ui = -1; /* { dg-warning "21:-Wsign-conversion" } */
unsigned char uc;
ui = si; /* { dg-warning "8:conversion" } */
si = 0x80000000; /* { dg-warning "8:conversion of unsigned constant value to negative integer" } */
si = 0x80000000; /* { dg-warning "8:-Wsign-conversion" } */
si = 3.2f; /* { dg-warning "8:conversion" } */
uc = 256; /* { dg-warning "8:large integer implicitly truncated to unsigned type" } */
si = 0x800000000; /* { dg-warning "8:overflow in implicit constant conversion" } */
uc = 256; /* { dg-warning "8:-Woverflow" } */
si = 0x800000000; /* { dg-warning "8:-Woverflow" } */
return f (si) /* { dg-warning "13:conversion" } */
+ f (si); /* { dg-warning "15:conversion" } */
}

View file

@ -1,7 +1,6 @@
/* PR c/59963 */
/* { dg-do compile } */
/* { dg-options "-Woverflow -Wconversion" } */
/* { dg-require-effective-target int32plus } */
extern void bar (unsigned char);
extern void bar8 (unsigned char, unsigned char, unsigned char, unsigned char,
@ -13,25 +12,25 @@ extern int f (short a, short b);
int
g (void)
{
return f (0xffffffffL, /* { dg-warning "13:overflow in implicit constant conversion" } */
0xffffffffL) /* { dg-warning "13:overflow in implicit constant conversion" } */
&& f (0xffffffffL, /* { dg-warning "9:overflow in implicit constant conversion" } */
0xffffffffL); /* { dg-warning "9:overflow in implicit constant conversion" } */
return f (0xffffffffL, /* { dg-warning "13:-Woverflow" } */
0xffffffffL) /* { dg-warning "13:-Woverflow" } */
&& f (0xffffffffL, /* { dg-warning "9:-Woverflow" } */
0xffffffffL); /* { dg-warning "9:-Woverflow" } */
}
void
foo (int i)
{
bar (256); /* { dg-warning "8:large integer implicitly truncated to unsigned type" } */
bar (256); /* { dg-warning "8:-Woverflow" } */
bar (6.66f); /* { dg-warning "8:conversion" } */
bar8 (-1, /* { dg-warning "9:negative integer implicitly converted to unsigned type" } */
-2, /* { dg-warning "3:negative integer implicitly converted to unsigned type" } */
-3, /* { dg-warning "4:negative integer implicitly converted to unsigned type" } */
-4, /* { dg-warning "5:negative integer implicitly converted to unsigned type" } */
-5, /* { dg-warning "6:negative integer implicitly converted to unsigned type" } */
-6, /* { dg-warning "7:negative integer implicitly converted to unsigned type" } */
-7, /* { dg-warning "8:negative integer implicitly converted to unsigned type" } */
-8); /* { dg-warning "9:negative integer implicitly converted to unsigned type" } */
bar8 (-1, /* { dg-warning "9:-Wsign-conversion" } */
-2, /* { dg-warning "3:-Wsign-conversion" } */
-3, /* { dg-warning "4:-Wsign-conversion" } */
-4, /* { dg-warning "5:-Wsign-conversion" } */
-5, /* { dg-warning "6:-Wsign-conversion" } */
-6, /* { dg-warning "7:-Wsign-conversion" } */
-7, /* { dg-warning "8:-Wsign-conversion" } */
-8); /* { dg-warning "9:-Wsign-conversion" } */
bazu (i, i); /* { dg-warning "9:conversion" } */
bazi (0x8, 0x80000000); /* { dg-warning "14:conversion of unsigned constant value to negative integer" "" { xfail int16 } } */
bazi (0x8, 0x80000000); /* { dg-warning "14:-Wsign-conversion" "" { xfail int16 } } */
}

View file

@ -5,28 +5,28 @@
struct S { int n, u[2]; };
const signed char z[] = {
[0] = 0x100, /* { dg-warning "9:overflow in implicit constant conversion" } */
[2] = 0x101, /* { dg-warning "9:overflow in implicit constant conversion" } */
[0] = 0x100, /* { dg-warning "9:-Woverflow" } */
[2] = 0x101, /* { dg-warning "9:-Woverflow" } */
};
int A[] = {
0, 0x80000000, /* { dg-warning "16:conversion of unsigned constant value to negative integer" } */
0xA, 0x80000000, /* { dg-warning "18:conversion of unsigned constant value to negative integer" } */
0xA, 0xA, 0x80000000 /* { dg-warning "23:conversion of unsigned constant value to negative integer" } */
0, 0x80000000, /* { dg-warning "16:-Wsign-conversion" } */
0xA, 0x80000000, /* { dg-warning "18:-Wsign-conversion" } */
0xA, 0xA, 0x80000000 /* { dg-warning "23:-Wsign-conversion" } */
};
int *p = (int []) { 0x80000000 }; /* { dg-warning "21:conversion of unsigned constant value to negative integer" } */
union { int k; } u = { .k = 0x80000000 }; /* { dg-warning "29:conversion of unsigned constant value to negative integer" } */
int *p = (int []) { 0x80000000 }; /* { dg-warning "21:-Wsign-conversion" } */
union { int k; } u = { .k = 0x80000000 }; /* { dg-warning "29:-Wsign-conversion" } */
typedef int H[];
void
foo (void)
{
signed char a[][3] = { { 0x100, /* { dg-warning "28:overflow in implicit constant conversion" } */
1, 0x100 }, /* { dg-warning "24:overflow in implicit constant conversion" } */
{ '\0', 0x100, '\0' } /* { dg-warning "27:overflow in implicit constant conversion" } */
signed char a[][3] = { { 0x100, /* { dg-warning "28:-Woverflow" } */
1, 0x100 }, /* { dg-warning "24:-Woverflow" } */
{ '\0', 0x100, '\0' } /* { dg-warning "27:-Woverflow" } */
};
(const signed char []) { 0x100 }; /* { dg-warning "28:overflow in implicit constant conversion" } */
(const signed char []) { 0x100 }; /* { dg-warning "28:-Woverflow" } */
(const float []) { 1e0, 1e1, 1e100 }; /* { dg-warning "32:conversion" } */
struct S s1 = { 0x80000000 }; /* { dg-warning "19:conversion of unsigned constant value to negative integer" } */
struct S s2 = { .n = 0x80000000 }; /* { dg-warning "24:conversion of unsigned constant value to negative integer" } */
struct S s3 = { .u[1] = 0x80000000 }; /* { dg-warning "27:conversion of unsigned constant value to negative integer" } */
H h = { 1, 2, 0x80000000 }; /* { dg-warning "17:conversion of unsigned constant value to negative integer" } */
struct S s1 = { 0x80000000 }; /* { dg-warning "19:-Wsign-conversion" } */
struct S s2 = { .n = 0x80000000 }; /* { dg-warning "24:-Wsign-conversion" } */
struct S s3 = { .u[1] = 0x80000000 }; /* { dg-warning "27:-Wsign-conversion" } */
H h = { 1, 2, 0x80000000 }; /* { dg-warning "17:-Wsign-conversion" } */
}

View file

@ -10,7 +10,7 @@ foo (unsigned int i)
{
switch (i)
{
case 123456123456ULL: /* { dg-warning "large integer implicitly truncated to unsigned type" } */
case 123456123456ULL: /* { dg-warning "conversion from .long long unsigned int. to .unsigned int. changes value" } */
return 0;
default:
return 3;

View file

@ -25,9 +25,9 @@ extern void full (unsigned long long);
void m (char16_t c0, char32_t c1)
{
f_c (c0); /* { dg-warning "alter its value" } */
fsc (c0); /* { dg-warning "alter its value" } */
fuc (c0); /* { dg-warning "alter its value" } */
f_c (c0); /* { dg-warning "conversion from .char16_t\[^\n\r\]*. to .char. may change value" } */
fsc (c0); /* { dg-warning "may change value" } */
fuc (c0); /* { dg-warning "may change value" } */
f_s (c0); /* { dg-warning "change the sign" } */
fss (c0); /* { dg-warning "change the sign" } */
fus (c0);
@ -41,12 +41,12 @@ void m (char16_t c0, char32_t c1)
fsll (c0);
full (c0);
f_c (c1); /* { dg-warning "alter its value" } */
fsc (c1); /* { dg-warning "alter its value" } */
fuc (c1); /* { dg-warning "alter its value" } */
f_s (c1); /* { dg-warning "alter its value" } */
fss (c1); /* { dg-warning "alter its value" } */
fus (c1); /* { dg-warning "alter its value" } */
f_c (c1); /* { dg-warning "may change value" } */
fsc (c1); /* { dg-warning "may change value" } */
fuc (c1); /* { dg-warning "may change value" } */
f_s (c1); /* { dg-warning "may change value" } */
fss (c1); /* { dg-warning "may change value" } */
fus (c1); /* { dg-warning "may change value" } */
f_i (c1); /* { dg-warning "change the sign" "" { target { ! int16 } } } */
fsi (c1); /* { dg-warning "change the sign" "" { target { ! int16 } } } */
fui (c1);

View file

@ -12,10 +12,10 @@ char16_t c2 = u'\U00064321'; /* { dg-warning "constant too long" } */
char16_t c3 = 'a';
char16_t c4 = U'a';
char16_t c5 = U'\u2029';
char16_t c6 = U'\U00064321'; /* { dg-warning "implicitly truncated" } */
char16_t c6 = U'\U00064321'; /* { dg-warning "conversion from .unsigned int. to .char16_t {aka short unsigned int}. changes value from .410401. to .17185." } */
char16_t c7 = L'a';
char16_t c8 = L'\u2029';
char16_t c9 = L'\U00064321'; /* { dg-warning "implicitly truncated" "" { target { 4byte_wchar_t } } } */
char16_t c9 = L'\U00064321'; /* { dg-warning "conversion" "" { target { 4byte_wchar_t } } } */
/* { dg-warning "constant too long" "" { target { ! 4byte_wchar_t } } .-1 } */
int main () {}