diff options
author | Roger Sayle <roger@eyesopen.com> | 2006-11-27 18:47:41 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2006-11-27 18:47:41 +0000 |
commit | 91c41804cbe481a939aa05f11f9a3d3acd64531a (patch) | |
tree | 5aad359f0e185e1bc8cb2318a9326272bdaa6c5f /gcc/c-common.c | |
parent | dbdbfff135d45b0767ab5617f24343dd3b15b8cd (diff) | |
download | gcc-91c41804cbe481a939aa05f11f9a3d3acd64531a.zip gcc-91c41804cbe481a939aa05f11f9a3d3acd64531a.tar.gz gcc-91c41804cbe481a939aa05f11f9a3d3acd64531a.tar.bz2 |
c-common.c (constant_fits_type_p): Delete.
2006-11-27 Roger Sayle <roger@eyesopen.com>
Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* c-common.c (constant_fits_type_p): Delete.
(unsigned_conversion_warning): Delete.
(conversion_warning): Integrate Wconversion warning from
unsigned_conversion_warning.
(convert_and_check): Integrate Woverflow warning from
unsigned_conversion_warning. Reorganize and simplify to avoid
dependence upon the middle-end setting TREE_OVERFLOW on integral
conversions, by using int_fits_type_p directly.
Co-Authored-By: Manuel López-Ibáñez <manu@gcc.gnu.org>
From-SVN: r119258
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 131 |
1 files changed, 57 insertions, 74 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index d576955..d7e98de 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -499,7 +499,6 @@ const struct fname_var_t fname_vars[] = {NULL, 0, 0}, }; -static int constant_fits_type_p (tree, tree); static tree check_case_value (tree); static bool check_case_bounds (tree, tree, tree *, tree *); @@ -957,32 +956,6 @@ overflow_warning (tree value) } } -/* Print a warning if a large constant is truncated to unsigned, - or if -Wconversion is used and a constant < 0 is converted to unsigned. - Invoke this function on every expression that might be implicitly - converted to an unsigned type. */ - -static void -unsigned_conversion_warning (tree result, tree operand) -{ - tree type = TREE_TYPE (result); - - if (TREE_CODE (operand) == INTEGER_CST - && TREE_CODE (type) == INTEGER_TYPE - && TYPE_UNSIGNED (type) - && skip_evaluation == 0 - && !int_fits_type_p (operand, type)) - { - if (!int_fits_type_p (operand, c_common_signed_type (type))) - /* This detects cases like converting -129 or 256 to unsigned char. */ - warning (OPT_Woverflow, - "large integer implicitly truncated to unsigned type"); - else - warning (OPT_Wconversion, - "negative integer implicitly converted to unsigned type"); - } -} - /* Print a warning about casts that might indicate violation of strict aliasing rules if -Wstrict-aliasing is used and strict aliasing mode is in effect. OTYPE is the original @@ -1100,19 +1073,6 @@ check_main_parameter_types (tree decl) } -/* Nonzero if constant C has a value that is permissible - for type TYPE (an INTEGER_TYPE). */ - -static int -constant_fits_type_p (tree c, tree type) -{ - if (TREE_CODE (c) == INTEGER_CST) - return int_fits_type_p (c, type); - - c = convert (type, c); - return !TREE_OVERFLOW (c); -} - /* Nonzero if vector types T1 and T2 can be converted to each other without an explicit cast. */ int @@ -1147,15 +1107,17 @@ conversion_warning (tree type, tree expr) if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (TREE_TYPE (expr)))) give_warning = true; } - /* Warn for an integer constant that does not fit into integer - type. However, warnings for negative constants converted to - unsigned types are detected by unsigned_conversion_warning. */ + /* Warn for an integer constant that does not fit into integer type. */ else if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE && TREE_CODE (type) == INTEGER_TYPE - && !int_fits_type_p (expr, type) - && !(TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (TREE_TYPE (expr)))) - give_warning = true; - + && !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; + } else if (TREE_CODE (type) == REAL_TYPE) { /* Warn for an integer constant that does not fit into real type. */ @@ -1241,42 +1203,63 @@ conversion_warning (tree type, tree expr) tree convert_and_check (tree type, tree expr) { - tree t = convert (type, expr); - if (TREE_CODE (t) == INTEGER_CST && TREE_OVERFLOW (t)) - { - TREE_OVERFLOW (t) = 0; + tree result; + + if (TREE_TYPE (expr) == type) + return expr; + + result = convert (type, expr); + + if (skip_evaluation) + return result; + + if (TREE_CODE (expr) == INTEGER_CST + && (TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && !int_fits_type_p (expr, type)) + { /* Do not diagnose overflow in a constant expression merely because a conversion overflowed. */ - TREE_CONSTANT_OVERFLOW (t) = CONSTANT_CLASS_P (expr) - && TREE_CONSTANT_OVERFLOW (expr); + if (TREE_OVERFLOW (result)) + { + TREE_CONSTANT_OVERFLOW (result) = TREE_CONSTANT_OVERFLOW (expr); + TREE_OVERFLOW (result) = TREE_OVERFLOW (expr); + } - /* No warning for converting 0x80000000 to int. */ - if (!(TYPE_UNSIGNED (type) < TYPE_UNSIGNED (TREE_TYPE (expr)) - && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE - && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr)))) + if (TYPE_UNSIGNED (type)) { - /* If EXPR fits in the unsigned version of TYPE, - don't warn unless pedantic. */ - if ((pedantic - || TYPE_UNSIGNED (type) - || !constant_fits_type_p (expr, - c_common_unsigned_type (type))) - && skip_evaluation == 0) + /* This detects cases like converting -129 or 256 to + unsigned char. */ + 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) + conversion_warning (type, expr); + } + else + { + if (!int_fits_type_p (expr, c_common_unsigned_type (type))) warning (OPT_Woverflow, "overflow in implicit constant conversion"); + /* No warning for converting 0x80000000 to int. */ + else if (pedantic + && (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE + || TYPE_PRECISION (TREE_TYPE (expr)) + != TYPE_PRECISION (type))) + warning (OPT_Woverflow, + "overflow in implicit constant conversion"); + else if (warn_conversion) + conversion_warning (type, expr); } - else if (warn_conversion && !skip_evaluation) - conversion_warning (type, expr); } - else - { - if (warn_conversion && !skip_evaluation) - conversion_warning (type, expr); - - unsigned_conversion_warning (t, expr); - } - return t; + else if (TREE_CODE (result) == INTEGER_CST && TREE_OVERFLOW (result)) + warning (OPT_Woverflow, + "overflow in implicit constant conversion"); + else if (warn_conversion) + conversion_warning (type, expr); + + return result; } /* A node in a list that describes references to variables (EXPR), which are |