aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2001-02-12 09:34:30 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2001-02-12 09:34:30 +0100
commitd02b54f66dac63bbd4bc7c5b44f2b9f6459d81dd (patch)
tree0b7df8968036ccd7157ea67cb1f4b25c98fab59a /gcc/c-common.c
parentb1012f1b4ca901ced4d2ff3ccbb64887cbf42381 (diff)
downloadgcc-d02b54f66dac63bbd4bc7c5b44f2b9f6459d81dd.zip
gcc-d02b54f66dac63bbd4bc7c5b44f2b9f6459d81dd.tar.gz
gcc-d02b54f66dac63bbd4bc7c5b44f2b9f6459d81dd.tar.bz2
c-common.c (constant_fits_type_p): New function.
* c-common.c (constant_fits_type_p): New function. (convert_and_check): Use it. * gcc.c-torture/compile/20010209-1.c: New test. From-SVN: r39596
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index dfa5813..5d3510c 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -232,6 +232,7 @@ static void add_attribute PARAMS ((enum attrs, const char *,
int, int, int));
static void init_attributes PARAMS ((void));
static int default_valid_lang_attribute PARAMS ((tree, tree, tree, tree));
+static int constant_fits_type_p PARAMS ((tree, tree));
/* Keep a stack of if statements. We record the number of compound
statements seen up to the if keyword, as well as the line number
@@ -1189,6 +1190,20 @@ unsigned_conversion_warning (result, operand)
}
}
+/* Nonzero if constant C has a value that is permissible
+ for type TYPE (an INTEGER_TYPE). */
+
+static int
+constant_fits_type_p (c, type)
+ tree c, type;
+{
+ if (TREE_CODE (c) == INTEGER_CST)
+ return int_fits_type_p (c, type);
+
+ c = convert (type, c);
+ return !TREE_OVERFLOW (c);
+}
+
/* Convert EXPR to TYPE, warning about conversion problems with constants.
Invoke this function on every expression that is converted implicitly,
i.e. because of language rules and not because of an explicit cast. */
@@ -1216,7 +1231,7 @@ convert_and_check (type, expr)
don't warn unless pedantic. */
if ((pedantic
|| TREE_UNSIGNED (type)
- || ! int_fits_type_p (expr, unsigned_type (type)))
+ || ! constant_fits_type_p (expr, unsigned_type (type)))
&& skip_evaluation == 0)
warning ("overflow in implicit constant conversion");
}