diff options
author | Richard Stallman <rms@gnu.org> | 1993-02-19 05:46:22 +0000 |
---|---|---|
committer | Richard Stallman <rms@gnu.org> | 1993-02-19 05:46:22 +0000 |
commit | 4c42625bf5de7f1ae018bc45594ec7e39589af75 (patch) | |
tree | 16393033c7932c0f389c8ac240dbd5b3e19aa892 /gcc | |
parent | 3c15ff863f7160d15ff3cba22f61078082ced134 (diff) | |
download | gcc-4c42625bf5de7f1ae018bc45594ec7e39589af75.zip gcc-4c42625bf5de7f1ae018bc45594ec7e39589af75.tar.gz gcc-4c42625bf5de7f1ae018bc45594ec7e39589af75.tar.bz2 |
(convert_to_integer): Warn if integer is truncated and that changes the value.
From-SVN: r3496
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/convert.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/convert.c b/gcc/convert.c index c67f510..0833a5f 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. */ |