invoke.texi (Warning Options): Add -Wconversion-sign.
2007-05-19 Manuel Lopez-Ibanez <manu@gcc.gnu.org> * doc/invoke.texi (Warning Options): Add -Wconversion-sign. (Wconversion): Update description. (Wconversion-sign): New. * c.opt (Wconversion-sign): New. * c-opts.c (c_common_post_options): Uninitialized Wconversion-sign means disabled for C++. Otherwise, take the status of Wconversion. * c-common.c (conversion_warning): Warn with either Wconversion or Wconversion-sign. (warnings_for_convert_and_check): Conditions are already checked by conversion_warning. (convert_and_check): Don't check warnings if the conversion failed. cp/ * cvt.c (cp_convert_and_check): Don't check warnings if the conversion failed. testsuite/ * gcc.dg/Wconversion-integer.c: Group testcases and add more. * gcc.dg/Wconversion-sign.c: New. * gcc.dg/Wconversion-integer-no-sign.c: New. * g++.dg/warn/Wconversion-integer.C: Move some warnings to Wconversion-sign.C * g++.dg/warn/Wconversion-sign.C: New. * g++.old-deja/g++.other/warn4.C: Update. * g++.dg/warn/Wconversion1.C: Likewise. From-SVN: r124856
This commit is contained in:
parent
4fc2b4ff18
commit
7060db96db
|
@ -1,3 +1,17 @@
|
|||
2007-05-19 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
|
||||
|
||||
* doc/invoke.texi (Warning Options): Add -Wconversion-sign.
|
||||
(Wconversion): Update description.
|
||||
(Wconversion-sign): New.
|
||||
* c.opt (Wconversion-sign): New.
|
||||
* c-opts.c (c_common_post_options): Uninitialized Wconversion-sign
|
||||
means disabled for C++. Otherwise, take the status of Wconversion.
|
||||
* c-common.c (conversion_warning): Warn with either Wconversion or
|
||||
Wconversion-sign.
|
||||
(warnings_for_convert_and_check): Conditions are already checked by
|
||||
conversion_warning.
|
||||
(convert_and_check): Don't check warnings if the conversion failed.
|
||||
|
||||
2007-05-19 Andy Hutchinson <HutchinsonAndy@netscape.net>
|
||||
Anatoly Sokolov <aesok@dol.ru>
|
||||
|
||||
|
|
|
@ -1204,6 +1204,9 @@ conversion_warning (tree type, tree expr)
|
|||
|
||||
unsigned int formal_prec = TYPE_PRECISION (type);
|
||||
|
||||
if (!warn_conversion && !warn_sign_conversion)
|
||||
return;
|
||||
|
||||
if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST)
|
||||
{
|
||||
/* Warn for real constant that is not an exact integer converted
|
||||
|
@ -1220,10 +1223,13 @@ conversion_warning (tree type, tree expr)
|
|||
&& !int_fits_type_p (expr, type))
|
||||
{
|
||||
if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (TREE_TYPE (expr)))
|
||||
warning (OPT_Wconversion,
|
||||
"negative integer implicitly converted to unsigned type");
|
||||
else
|
||||
give_warning = true;
|
||||
warning (OPT_Wsign_conversion,
|
||||
"negative integer implicitly converted to unsigned type");
|
||||
else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (TREE_TYPE (expr)))
|
||||
warning (OPT_Wsign_conversion,
|
||||
"conversion of unsigned constant value to negative integer");
|
||||
else
|
||||
give_warning = true;
|
||||
}
|
||||
else if (TREE_CODE (type) == REAL_TYPE)
|
||||
{
|
||||
|
@ -1261,16 +1267,20 @@ conversion_warning (tree type, tree expr)
|
|||
&& TREE_CODE (type) == INTEGER_TYPE)
|
||||
{
|
||||
/* Warn for integer types converted to smaller integer types. */
|
||||
if (formal_prec < TYPE_PRECISION (TREE_TYPE (expr))
|
||||
/* When they are the same width but different signedness,
|
||||
then the value may change. */
|
||||
|| (formal_prec == TYPE_PRECISION (TREE_TYPE (expr))
|
||||
&& TYPE_UNSIGNED (TREE_TYPE (expr)) != TYPE_UNSIGNED (type))
|
||||
/* Even when converted to a bigger type, if the type is
|
||||
unsigned but expr is signed, then negative values
|
||||
will be changed. */
|
||||
|| (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (TREE_TYPE (expr))))
|
||||
give_warning = true;
|
||||
if (formal_prec < TYPE_PRECISION (TREE_TYPE (expr)))
|
||||
give_warning = true;
|
||||
|
||||
/* When they are the same width but different signedness,
|
||||
then the value may change. */
|
||||
else if ((formal_prec == TYPE_PRECISION (TREE_TYPE (expr))
|
||||
&& TYPE_UNSIGNED (TREE_TYPE (expr)) != TYPE_UNSIGNED (type))
|
||||
/* Even when converted to a bigger type, if the type is
|
||||
unsigned but expr is signed, then negative values
|
||||
will be changed. */
|
||||
|| (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (TREE_TYPE (expr))))
|
||||
warning (OPT_Wsign_conversion,
|
||||
"conversion to %qT from %qT may change the sign of the result",
|
||||
type, TREE_TYPE (expr));
|
||||
}
|
||||
|
||||
/* Warn for integer types converted to real types if and only if
|
||||
|
@ -1327,7 +1337,7 @@ warnings_for_convert_and_check (tree type, tree expr, tree result)
|
|||
if (!int_fits_type_p (expr, c_common_signed_type (type)))
|
||||
warning (OPT_Woverflow,
|
||||
"large integer implicitly truncated to unsigned type");
|
||||
else if (warn_conversion)
|
||||
else
|
||||
conversion_warning (type, expr);
|
||||
}
|
||||
else if (!int_fits_type_p (expr, unsigned_type_for (type)))
|
||||
|
@ -1341,13 +1351,13 @@ warnings_for_convert_and_check (tree type, tree expr, tree result)
|
|||
warning (OPT_Woverflow,
|
||||
"overflow in implicit constant conversion");
|
||||
|
||||
else if (warn_conversion)
|
||||
else
|
||||
conversion_warning (type, expr);
|
||||
}
|
||||
else if (TREE_CODE (result) == INTEGER_CST && TREE_OVERFLOW (result))
|
||||
warning (OPT_Woverflow,
|
||||
"overflow in implicit constant conversion");
|
||||
else if (warn_conversion)
|
||||
else
|
||||
conversion_warning (type, expr);
|
||||
}
|
||||
|
||||
|
@ -1366,7 +1376,7 @@ convert_and_check (tree type, tree expr)
|
|||
|
||||
result = convert (type, expr);
|
||||
|
||||
if (!skip_evaluation && !TREE_OVERFLOW_P (expr))
|
||||
if (!skip_evaluation && !TREE_OVERFLOW_P (expr) && result != error_mark_node)
|
||||
warnings_for_convert_and_check (type, expr, result);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1104,7 +1104,14 @@ c_common_post_options (const char **pfilename)
|
|||
}
|
||||
if (flag_inline_functions)
|
||||
flag_inline_trees = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* In C, -Wconversion enables -Wsign-conversion (unless disabled
|
||||
through -Wno-sign-conversion). While in C++,
|
||||
-Wsign-conversion needs to be requested explicitly. */
|
||||
if (warn_sign_conversion == -1)
|
||||
warn_sign_conversion = (c_dialect_cxx ()) ? 0 : warn_conversion;
|
||||
|
||||
|
||||
/* Special format checking options don't work without -Wformat; warn if
|
||||
they are used. */
|
||||
|
|
|
@ -164,6 +164,10 @@ Wconversion
|
|||
C ObjC C++ ObjC++ Var(warn_conversion) Warning
|
||||
Warn for implicit type conversions that may change a value
|
||||
|
||||
Wsign-conversion
|
||||
C ObjC C++ ObjC++ Var(warn_sign_conversion) Init(-1)
|
||||
Warn for implicit type conversions between signed and unsigned integers
|
||||
|
||||
Wctor-dtor-privacy
|
||||
C++ ObjC++ Var(warn_ctor_dtor_privacy) Warning
|
||||
Warn when all constructors and destructors are private
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2007-05-19 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
|
||||
|
||||
* cvt.c (cp_convert_and_check): Don't check warnings if the
|
||||
conversion failed.
|
||||
|
||||
2007-05-18 Geoffrey Keating <geoffk@apple.com>
|
||||
|
||||
* mangle.c (write_real_cst): Use 'unsigned long' for %lx.
|
||||
|
|
|
@ -610,7 +610,7 @@ cp_convert_and_check (tree type, tree expr)
|
|||
|
||||
result = cp_convert (type, expr);
|
||||
|
||||
if (!skip_evaluation && !TREE_OVERFLOW_P (expr))
|
||||
if (!skip_evaluation && !TREE_OVERFLOW_P (expr) && result != error_mark_node)
|
||||
warnings_for_convert_and_check (type, expr, result);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -227,7 +227,7 @@ Objective-C and Objective-C++ Dialects}.
|
|||
-w -Wextra -Wall -Waddress -Waggregate-return -Warray-bounds @gol
|
||||
-Wno-attributes -Wc++-compat -Wc++0x-compat -Wcast-align -Wcast-qual @gol
|
||||
-Wchar-subscripts -Wclobbered -Wcomment @gol
|
||||
-Wconversion -Wcoverage-mismatch -Wno-deprecated-declarations @gol
|
||||
-Wconversion -Wcoverage-mismatch -Wno-deprecated-declarations @gol
|
||||
-Wdisabled-optimization -Wno-div-by-zero @gol
|
||||
-Wempty-body -Wno-endif-labels @gol
|
||||
-Werror -Werror=* @gol
|
||||
|
@ -247,7 +247,7 @@ Objective-C and Objective-C++ Dialects}.
|
|||
-Wparentheses -Wpointer-arith -Wno-pointer-to-int-cast @gol
|
||||
-Wredundant-decls @gol
|
||||
-Wreturn-type -Wsequence-point -Wshadow @gol
|
||||
-Wsign-compare -Wstack-protector @gol
|
||||
-Wsign-compare -Wsign-conversion -Wstack-protector @gol
|
||||
-Wstrict-aliasing -Wstrict-aliasing=n @gol
|
||||
-Wstrict-overflow -Wstrict-overflow=@var{n} @gol
|
||||
-Wswitch -Wswitch-default -Wswitch-enum @gol
|
||||
|
@ -3437,19 +3437,24 @@ Warn for variables that might be changed by @samp{longjmp} or
|
|||
|
||||
@item -Wconversion
|
||||
@opindex Wconversion
|
||||
@opindex Wno-conversion
|
||||
Warn for implicit conversions that may alter a value. This includes
|
||||
conversions between real and integer, like @code{abs (x)} when
|
||||
@code{x} is @code{double}; conversions between signed and unsigned,
|
||||
like @code{unsigned ui = -1}; and conversions to smaller types, like
|
||||
@code{sqrtf (M_PI)}. Do not warn for explicit casts like @code{abs
|
||||
((int) x)} and @code{ui = (unsigned) -1}, or if the value is not
|
||||
changed by the conversion like in @code{abs (2.0)}.
|
||||
changed by the conversion like in @code{abs (2.0)}. Warnings about
|
||||
conversions between signed and unsigned integers can be disabled by
|
||||
using @option{-Wno-sign-conversion}.
|
||||
|
||||
For C++, also warn for conversions between @code{NULL} and non-pointer
|
||||
types; confusing overload resolution for user-defined conversions; and
|
||||
conversions that will never use a type conversion operator:
|
||||
conversions to @code{void}, the same type, a base class or a reference
|
||||
to them.
|
||||
to them. Warnings about conversions between signed and unsigned
|
||||
integers are disabled by default in C++ unless
|
||||
@option{-Wsign-conversion} is explicitly enabled.
|
||||
|
||||
@item -Wempty-body
|
||||
@opindex Wempty-body
|
||||
|
@ -3468,6 +3473,14 @@ an incorrect result when the signed value is converted to unsigned.
|
|||
This warning is also enabled by @option{-Wextra}; to get the other warnings
|
||||
of @option{-Wextra} without this warning, use @samp{-Wextra -Wno-sign-compare}.
|
||||
|
||||
@item -Wsign-conversion
|
||||
@opindex Wsign-conversion
|
||||
@opindex Wno-sign-conversion
|
||||
Warn for implicit conversions that may change the sign of an integer
|
||||
value, like assigning a signed integer expression to an unsigned
|
||||
integer variable. An explicit cast silences the warning. In C, this
|
||||
option is enabled also by @option{-Wconversion}.
|
||||
|
||||
@item -Waddress
|
||||
@opindex Waddress
|
||||
@opindex Wno-address
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
2007-05-19 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
|
||||
|
||||
* gcc.dg/Wconversion-integer.c: Group testcases and add more.
|
||||
* gcc.dg/Wconversion-sign.c: New.
|
||||
* gcc.dg/Wconversion-integer-no-sign.c: New.
|
||||
* g++.dg/warn/Wconversion-integer.C: Move some warnings to
|
||||
Wconversion-sign.C
|
||||
* g++.dg/warn/Wconversion-sign.C: New.
|
||||
* g++.old-deja/g++.other/warn4.C: Update.
|
||||
* g++.dg/warn/Wconversion1.C: Likewise.
|
||||
|
||||
2007-05-19 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
||||
|
||||
* gcc.dg/torture/builtin-math-2.c: Add gamma_r/lgamma_r tests.
|
||||
|
|
|
@ -18,49 +18,14 @@ void h (int x)
|
|||
unsigned char uc = 3;
|
||||
signed char sc = 3;
|
||||
|
||||
fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
uc = -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" } */
|
||||
uc = x ? 1U : -1; /* { dg-warning "conversion" } */
|
||||
/* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 25 } */
|
||||
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "conversion" } */
|
||||
/* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 27 } */
|
||||
|
||||
uc = x ? 1 : -1; /* { dg-warning "conversion" } */
|
||||
|
||||
uc = x ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */
|
||||
|
||||
fuc ('A');
|
||||
uc = 'A';
|
||||
uc = (unsigned char) -1;
|
||||
|
||||
fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
ui = -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 "conversion" } */
|
||||
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */
|
||||
|
||||
ui = -1 * (1 * -1);
|
||||
ui = (unsigned) -1;
|
||||
|
||||
fsc (uc); /* { dg-warning "conversion" } */
|
||||
sc = uc; /* { dg-warning "conversion" } */
|
||||
fuc (sc); /* { dg-warning "conversion" } */
|
||||
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 (sc); /* { dg-warning "conversion" } */
|
||||
ui = sc; /* { dg-warning "conversion" } */
|
||||
|
||||
fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
uc = ui; /* { dg-warning "conversion" } */
|
||||
uc = si; /* { dg-warning "conversion" } */
|
||||
sc = ui; /* { dg-warning "conversion" } */
|
||||
sc = si; /* { dg-warning "conversion" } */
|
||||
fuc (ui); /* { dg-warning "conversion" } */
|
||||
fuc (si); /* { dg-warning "conversion" } */
|
||||
fsc (ui); /* { dg-warning "conversion" } */
|
||||
fsc (si); /* { dg-warning "conversion" } */
|
||||
|
||||
fsi (si);
|
||||
fui (ui);
|
||||
|
@ -72,12 +37,37 @@ void h (int x)
|
|||
ui = 'A';
|
||||
fsi ('A');
|
||||
si = 'A';
|
||||
|
||||
fuc ('A');
|
||||
uc = 'A';
|
||||
|
||||
fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1U; /* { dg-warning "conversion" } */
|
||||
uc = x ? 1U : -1; /* { dg-warning "conversion" } */
|
||||
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "conversion" } */
|
||||
uc = x ? 1 : -1; /* { dg-warning "conversion" } */
|
||||
uc = x ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */
|
||||
ui = x ? 1U : -1; /* Warned by -Wsign-conversion. */
|
||||
ui = x ? INT_MIN : 1U; /* Warned by -Wsign-conversion. */
|
||||
ui = ui ? SCHAR_MIN : 1U; /* Warned by -Wsign-conversion. */
|
||||
ui = 1U * -1; /* Warned by -Wsign-conversion. */
|
||||
ui = ui + INT_MIN; /* Warned by -Wsign-conversion. */
|
||||
ui = x ? 1 : -1; /* Warned by -Wsign-conversion. */
|
||||
ui = ui ? SCHAR_MIN : 1; /* Warned by -Wsign-conversion. */
|
||||
|
||||
fuc (-1); /* Warned by -Wsign-conversion. */
|
||||
uc = -1; /* Warned by -Wsign-conversion. */
|
||||
fui (-1); /* Warned by -Wsign-conversion. */
|
||||
ui = -1; /* Warned by -Wsign-conversion. */
|
||||
fuc ('\xa0'); /* Warned by -Wsign-conversion. */
|
||||
uc = '\xa0'; /* Warned by -Wsign-conversion. */
|
||||
fui ('\xa0'); /* Warned by -Wsign-conversion. */
|
||||
ui = '\xa0'; /* Warned by -Wsign-conversion. */
|
||||
fsi (0x80000000); /* Warned by -Wsign-conversion. */
|
||||
si = 0x80000000; /* Warned by -Wsign-conversion. */
|
||||
|
||||
|
||||
fsi (UINT_MAX - 1); /* Warned by -Wsign-conversion. */
|
||||
si = UINT_MAX - 1; /* Warned by -Wsign-conversion. */
|
||||
fsi (UINT_MAX - 1U); /* Warned by -Wsign-conversion. */
|
||||
si = UINT_MAX - 1U; /* Warned by -Wsign-conversion. */
|
||||
fsi (UINT_MAX/3U);
|
||||
si = UINT_MAX/3U;
|
||||
fsi (UINT_MAX/3);
|
||||
|
@ -85,11 +75,20 @@ void h (int x)
|
|||
fui (UINT_MAX - 1);
|
||||
ui = UINT_MAX - 1;
|
||||
|
||||
fsi (0x80000000); /* { dg-warning "conversion" } */
|
||||
si = 0x80000000; /* { dg-warning "conversion" } */
|
||||
uc = (unsigned char) -1;
|
||||
ui = -1 * (1 * -1);
|
||||
ui = (unsigned) -1;
|
||||
|
||||
fsc (uc); /* Warned by -Wsign-conversion. */
|
||||
sc = uc; /* Warned by -Wsign-conversion. */
|
||||
fuc (sc); /* Warned by -Wsign-conversion. */
|
||||
uc = sc; /* Warned by -Wsign-conversion. */
|
||||
fsi (ui); /* Warned by -Wsign-conversion. */
|
||||
si = ui; /* Warned by -Wsign-conversion. */
|
||||
fui (si); /* Warned by -Wsign-conversion. */
|
||||
ui = si; /* Warned by -Wsign-conversion. */
|
||||
fui (sc); /* Warned by -Wsign-conversion. */
|
||||
ui = sc; /* Warned by -Wsign-conversion. */
|
||||
}
|
||||
|
||||
|
||||
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
|
||||
|
||||
unsigned fui (unsigned a) { return a + -1; } /* Warned by -Wsign-conversion. */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// { dg-options "-fsigned-char -Wconversion" }
|
||||
// { dg-options "-fsigned-char -Wsign-conversion" }
|
||||
|
||||
char c1 = 1024; // { dg-warning "overflow" }
|
||||
char c2 = char(1024);
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
/* Test for diagnostics for implicit conversions between signed and
|
||||
unsigned integer types.
|
||||
C++ equivalent of gcc/testsuite/gcc.dg/Wsign-conversion.c */
|
||||
|
||||
// { dg-do compile }
|
||||
// { dg-options "-fsigned-char -Wsign-conversion" }
|
||||
#include <limits.h>
|
||||
|
||||
void fsc (signed char sc);
|
||||
void fuc (unsigned char uc);
|
||||
unsigned fui (unsigned int ui);
|
||||
void fsi (signed int ui);
|
||||
|
||||
void h (int x)
|
||||
{
|
||||
unsigned int ui = 3;
|
||||
int si = 3;
|
||||
unsigned char uc = 3;
|
||||
signed char sc = 3;
|
||||
|
||||
uc = ui;
|
||||
uc = si;
|
||||
sc = ui;
|
||||
sc = si;
|
||||
fuc (ui);
|
||||
fuc (si);
|
||||
fsc (ui);
|
||||
fsc (si);
|
||||
|
||||
fsi (si);
|
||||
fui (ui);
|
||||
fsi (uc);
|
||||
si = uc;
|
||||
fui (uc);
|
||||
ui = uc;
|
||||
fui ('A');
|
||||
ui = 'A';
|
||||
fsi ('A');
|
||||
si = 'A';
|
||||
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;
|
||||
uc = x ? SCHAR_MIN : 1;
|
||||
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 "conversion" } */
|
||||
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "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" } */
|
||||
fsi (0x80000000); /* { dg-warning "conversion" } */
|
||||
si = 0x80000000; /* { dg-warning "conversion" } */
|
||||
|
||||
|
||||
fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1U; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX/3U);
|
||||
si = UINT_MAX/3U;
|
||||
fsi (UINT_MAX/3);
|
||||
si = UINT_MAX/3;
|
||||
fui (UINT_MAX - 1);
|
||||
ui = UINT_MAX - 1;
|
||||
|
||||
uc = (unsigned char) -1;
|
||||
ui = -1 * (1 * -1);
|
||||
ui = (unsigned) -1;
|
||||
|
||||
fsc (uc); /* { dg-warning "conversion" } */
|
||||
sc = uc; /* { dg-warning "conversion" } */
|
||||
fuc (sc); /* { dg-warning "conversion" } */
|
||||
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 (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" } */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// { dg-do assemble }
|
||||
// { dg-options "-Wconversion" }
|
||||
// { dg-options "-Wsign-conversion" }
|
||||
|
||||
// Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
// Contributed by Nathan Sidwell 21 Nov 1999 <nathan@acm.org>
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/* Test for diagnostics for implicit conversions between integer types
|
||||
These tests come from gcc/testsuite/gcc.dg/overflow-warn-2.c */
|
||||
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-std=c99 -fsigned-char -Wconversion -Wno-sign-conversion" } */
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
void fsc (signed char sc);
|
||||
void fuc (unsigned char uc);
|
||||
unsigned fui (unsigned int ui);
|
||||
void fsi (signed int ui);
|
||||
|
||||
void h (int x)
|
||||
{
|
||||
unsigned int ui = 3;
|
||||
int si = 3;
|
||||
unsigned char uc = 3;
|
||||
signed char sc = 3;
|
||||
|
||||
uc = ui; /* { dg-warning "conversion" } */
|
||||
uc = si; /* { dg-warning "conversion" } */
|
||||
sc = ui; /* { dg-warning "conversion" } */
|
||||
sc = si; /* { dg-warning "conversion" } */
|
||||
fuc (ui); /* { dg-warning "conversion" } */
|
||||
fuc (si); /* { dg-warning "conversion" } */
|
||||
fsc (ui); /* { dg-warning "conversion" } */
|
||||
fsc (si); /* { dg-warning "conversion" } */
|
||||
|
||||
fsi (si);
|
||||
fui (ui);
|
||||
fsi (uc);
|
||||
si = uc;
|
||||
fui (uc);
|
||||
ui = uc;
|
||||
fui ('A');
|
||||
ui = 'A';
|
||||
fsi ('A');
|
||||
si = 'A';
|
||||
fuc ('A');
|
||||
uc = 'A';
|
||||
|
||||
uc = x ? 1U : -1; /* { dg-warning "conversion" } */
|
||||
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "conversion" } */
|
||||
uc = x ? 1 : -1; /* { dg-warning "conversion" } */
|
||||
uc = x ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */
|
||||
ui = x ? 1U : -1; /* Warned by -Wsign-conversion. */
|
||||
ui = x ? INT_MIN : 1U; /* Warned by -Wsign-conversion. */
|
||||
ui = ui ? SCHAR_MIN : 1U; /* Warned by -Wsign-conversion. */
|
||||
ui = 1U * -1; /* Warned by -Wsign-conversion. */
|
||||
ui = ui + INT_MIN; /* Warned by -Wsign-conversion. */
|
||||
ui = x ? 1 : -1; /* Warned by -Wsign-conversion. */
|
||||
ui = ui ? SCHAR_MIN : 1; /* Warned by -Wsign-conversion. */
|
||||
|
||||
fuc (-1); /* Warned by -Wsign-conversion. */
|
||||
uc = -1; /* Warned by -Wsign-conversion. */
|
||||
fui (-1); /* Warned by -Wsign-conversion. */
|
||||
ui = -1; /* Warned by -Wsign-conversion. */
|
||||
fuc ('\xa0'); /* Warned by -Wsign-conversion. */
|
||||
uc = '\xa0'; /* Warned by -Wsign-conversion. */
|
||||
fui ('\xa0'); /* Warned by -Wsign-conversion. */
|
||||
ui = '\xa0'; /* Warned by -Wsign-conversion. */
|
||||
fsi (0x80000000); /* Warned by -Wsign-conversion. */
|
||||
si = 0x80000000; /* Warned by -Wsign-conversion. */
|
||||
|
||||
|
||||
fsi (UINT_MAX - 1); /* Warned by -Wsign-conversion. */
|
||||
si = UINT_MAX - 1; /* Warned by -Wsign-conversion. */
|
||||
fsi (UINT_MAX - 1U); /* Warned by -Wsign-conversion. */
|
||||
si = UINT_MAX - 1U; /* Warned by -Wsign-conversion. */
|
||||
fsi (UINT_MAX/3U);
|
||||
si = UINT_MAX/3U;
|
||||
fsi (UINT_MAX/3);
|
||||
si = UINT_MAX/3;
|
||||
fui (UINT_MAX - 1);
|
||||
ui = UINT_MAX - 1;
|
||||
|
||||
uc = (unsigned char) -1;
|
||||
ui = -1 * (1 * -1);
|
||||
ui = (unsigned) -1;
|
||||
|
||||
fsc (uc); /* Warned by -Wsign-conversion. */
|
||||
sc = uc; /* Warned by -Wsign-conversion. */
|
||||
fuc (sc); /* Warned by -Wsign-conversion. */
|
||||
uc = sc; /* Warned by -Wsign-conversion. */
|
||||
fsi (ui); /* Warned by -Wsign-conversion. */
|
||||
si = ui; /* Warned by -Wsign-conversion. */
|
||||
fui (si); /* Warned by -Wsign-conversion. */
|
||||
ui = si; /* Warned by -Wsign-conversion. */
|
||||
fui (sc); /* Warned by -Wsign-conversion. */
|
||||
ui = sc; /* Warned by -Wsign-conversion. */
|
||||
}
|
||||
|
||||
unsigned fui (unsigned a) { return a + -1; } /* Warned by -Wsign-conversion. */
|
||||
|
||||
|
|
@ -18,25 +18,34 @@ void h (int x)
|
|||
unsigned char uc = 3;
|
||||
signed char sc = 3;
|
||||
|
||||
fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
uc = -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" } */
|
||||
uc = x ? 1U : -1; /* { dg-warning "conversion" } */
|
||||
/* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 25 } */
|
||||
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "conversion" } */
|
||||
/* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 27 } */
|
||||
|
||||
uc = x ? 1 : -1; /* { dg-warning "conversion" } */
|
||||
|
||||
uc = x ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */
|
||||
uc = ui; /* { dg-warning "conversion" } */
|
||||
uc = si; /* { dg-warning "conversion" } */
|
||||
sc = ui; /* { dg-warning "conversion" } */
|
||||
sc = si; /* { dg-warning "conversion" } */
|
||||
fuc (ui); /* { dg-warning "conversion" } */
|
||||
fuc (si); /* { dg-warning "conversion" } */
|
||||
fsc (ui); /* { dg-warning "conversion" } */
|
||||
fsc (si); /* { dg-warning "conversion" } */
|
||||
|
||||
fsi (si);
|
||||
fui (ui);
|
||||
fsi (uc);
|
||||
si = uc;
|
||||
fui (uc);
|
||||
ui = uc;
|
||||
fui ('A');
|
||||
ui = 'A';
|
||||
fsi ('A');
|
||||
si = 'A';
|
||||
fuc ('A');
|
||||
uc = 'A';
|
||||
uc = (unsigned char) -1;
|
||||
|
||||
fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
uc = x ? 1U : -1; /* { dg-warning "conversion" } */
|
||||
/* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 43 } */
|
||||
uc = x ? SCHAR_MIN : 1U; /* { dg-warning "conversion" } */
|
||||
/* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 45 } */
|
||||
uc = x ? 1 : -1; /* { dg-warning "conversion" } */
|
||||
uc = x ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */
|
||||
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" } */
|
||||
|
@ -45,6 +54,30 @@ void h (int x)
|
|||
ui = x ? 1 : -1; /* { dg-warning "conversion" } */
|
||||
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "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" } */
|
||||
fsi (0x80000000); /* { dg-warning "conversion" } */
|
||||
si = 0x80000000; /* { dg-warning "conversion" } */
|
||||
|
||||
|
||||
fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1U; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX/3U);
|
||||
si = UINT_MAX/3U;
|
||||
fsi (UINT_MAX/3);
|
||||
si = UINT_MAX/3;
|
||||
fui (UINT_MAX - 1);
|
||||
ui = UINT_MAX - 1;
|
||||
|
||||
uc = (unsigned char) -1;
|
||||
ui = -1 * (1 * -1);
|
||||
ui = (unsigned) -1;
|
||||
|
||||
|
@ -58,38 +91,8 @@ void h (int x)
|
|||
ui = si; /* { dg-warning "conversion" } */
|
||||
fui (sc); /* { dg-warning "conversion" } */
|
||||
ui = sc; /* { dg-warning "conversion" } */
|
||||
|
||||
fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
|
||||
fsi (si);
|
||||
fui (ui);
|
||||
fsi (uc);
|
||||
si = uc;
|
||||
fui (uc);
|
||||
ui = uc;
|
||||
fui ('A');
|
||||
ui = 'A';
|
||||
fsi ('A');
|
||||
si = 'A';
|
||||
|
||||
|
||||
fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1U; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX/3U);
|
||||
si = UINT_MAX/3U;
|
||||
fsi (UINT_MAX/3);
|
||||
si = UINT_MAX/3;
|
||||
fui (UINT_MAX - 1);
|
||||
ui = UINT_MAX - 1;
|
||||
|
||||
fsi (0x80000000); /* { dg-warning "conversion" } */
|
||||
si = 0x80000000; /* { dg-warning "conversion" } */
|
||||
}
|
||||
|
||||
|
||||
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/* Test for diagnostics for implicit conversions between signed and
|
||||
unsigned integer types.
|
||||
These tests come from gcc/testsuite/gcc.dg/overflow-warn-2.c */
|
||||
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-std=c99 -fsigned-char -Wsign-conversion" } */
|
||||
#include <limits.h>
|
||||
|
||||
void fsc (signed char sc);
|
||||
void fuc (unsigned char uc);
|
||||
unsigned fui (unsigned int ui);
|
||||
void fsi (signed int ui);
|
||||
|
||||
void h (int x)
|
||||
{
|
||||
unsigned int ui = 3;
|
||||
int si = 3;
|
||||
unsigned char uc = 3;
|
||||
signed char sc = 3;
|
||||
|
||||
uc = ui;
|
||||
uc = si;
|
||||
sc = ui;
|
||||
sc = si;
|
||||
fuc (ui);
|
||||
fuc (si);
|
||||
fsc (ui);
|
||||
fsc (si);
|
||||
|
||||
fsi (si);
|
||||
fui (ui);
|
||||
fsi (uc);
|
||||
si = uc;
|
||||
fui (uc);
|
||||
ui = uc;
|
||||
fui ('A');
|
||||
ui = 'A';
|
||||
fsi ('A');
|
||||
si = 'A';
|
||||
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;
|
||||
uc = x ? SCHAR_MIN : 1;
|
||||
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 "conversion" } */
|
||||
ui = ui ? SCHAR_MIN : 1; /* { dg-warning "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" } */
|
||||
fsi (0x80000000); /* { dg-warning "conversion" } */
|
||||
si = 0x80000000; /* { dg-warning "conversion" } */
|
||||
|
||||
|
||||
fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */
|
||||
si = UINT_MAX - 1U; /* { dg-warning "conversion" } */
|
||||
fsi (UINT_MAX/3U);
|
||||
si = UINT_MAX/3U;
|
||||
fsi (UINT_MAX/3);
|
||||
si = UINT_MAX/3;
|
||||
fui (UINT_MAX - 1);
|
||||
ui = UINT_MAX - 1;
|
||||
|
||||
uc = (unsigned char) -1;
|
||||
ui = -1 * (1 * -1);
|
||||
ui = (unsigned) -1;
|
||||
|
||||
fsc (uc); /* { dg-warning "conversion" } */
|
||||
sc = uc; /* { dg-warning "conversion" } */
|
||||
fuc (sc); /* { dg-warning "conversion" } */
|
||||
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 (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" } */
|
||||
|
||||
|
Loading…
Reference in New Issue