aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2001-02-12 08:34:30 +0000
committerJakub Jelinek <jakub@redhat.com>2001-02-12 08:34:30 +0000
commita77e41f20ecff0f4731ab8d43e54629b25d29e50 (patch)
tree0b7df8968036ccd7157ea67cb1f4b25c98fab59a
parentcedc9eb67604c16c8ad82293f5dbb974554130ca (diff)
* c-common.c (constant_fits_type_p): New function.
(convert_and_check): Use it. * gcc.c-torture/compile/20010209-1.c: New test. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@39596 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-common.c17
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/20010209-1.c7
4 files changed, 32 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index acab701e406..fbaa4c6cd60 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2001-02-12 Jakub Jelinek <jakub@redhat.com>
+
+ * c-common.c (constant_fits_type_p): New function.
+ (convert_and_check): Use it.
+
2001-02-11 Mark Mitchell <mark@codesourcery.com>
* Makefile.in (GXX_ABI_FLAG): Don't define.
diff --git a/gcc/c-common.c b/gcc/c-common.c
index dfa58136f49..5d3510c8834 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");
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d17e44bdaa6..c8832787c32 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2001-02-12 Jakub Jelinek <jakub@redhat.com>
+
+ * gcc.c-torture/compile/20010209-1.c: New test.
+
2001-02-11 Jeffrey Oldham <oldham@codesourcery.com>
* g++.old-deja/g++.other/crash26.C: XFAIL if parser produces
diff --git a/gcc/testsuite/gcc.c-torture/compile/20010209-1.c b/gcc/testsuite/gcc.c-torture/compile/20010209-1.c
new file mode 100644
index 00000000000..20434644be6
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/20010209-1.c
@@ -0,0 +1,7 @@
+short int a;
+
+int main (void)
+{
+ a = 65535.0;
+ return 0;
+}