summaryrefslogtreecommitdiff
path: root/gcc/convert.c
diff options
context:
space:
mode:
authorrms <rms@138bc75d-0d04-0410-961f-82ee72b054a4>1993-02-19 05:46:22 +0000
committerrms <rms@138bc75d-0d04-0410-961f-82ee72b054a4>1993-02-19 05:46:22 +0000
commit73b9aad73e10eb38680b1520bc2419a899388bee (patch)
tree16393033c7932c0f389c8ac240dbd5b3e19aa892 /gcc/convert.c
parent580dcbc32fa0fcbad5501d1e8455b86502cabe68 (diff)
downloadgcc-73b9aad73e10eb38680b1520bc2419a899388bee.tar.gz
(convert_to_integer): Warn if integer is truncated and that changes the value.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@3496 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/convert.c')
-rw-r--r--gcc/convert.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/convert.c b/gcc/convert.c
index c67f510188c..0833a5fbcd7 100644
--- a/gcc/convert.c
+++ b/gcc/convert.c
@@ -172,6 +172,30 @@ convert_to_integer (type, expr)
switch (ex_form)
{
+ case INTEGER_CST:
+ if (TREE_UNSIGNED (type))
+ {
+ if (TREE_INT_CST_LOW (expr) >> outprec)
+ warning ("integer constant truncated");
+ }
+ else
+ {
+ /* if the sign bit of the low-order part isn't replicated
+ through the entire high part, we have overflow */
+ int sign = TREE_INT_CST_LOW (expr) & (1 << (outprec - 1));
+ if (!sign) /* lower part positive */
+ {
+ if (TREE_INT_CST_LOW (expr) >> outprec)
+ warning ("integer constant truncated");
+ }
+ else
+ {
+ if ((TREE_INT_CST_LOW (expr) >> outprec) + 1)
+ warning ("integer constant truncated");
+ }
+ }
+ break;
+
case RSHIFT_EXPR:
/* We can pass truncation down through right shifting
when the shift count is a nonpositive constant. */