summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorsandra <sandra@138bc75d-0d04-0410-961f-82ee72b054a4>2009-05-15 17:28:47 +0000
committersandra <sandra@138bc75d-0d04-0410-961f-82ee72b054a4>2009-05-15 17:28:47 +0000
commit275b395f894f16ac389cd8c5799e374080d3b188 (patch)
treedc6d7cf139391ffd759113efa90ed726e869d03c /gcc/fold-const.c
parent2206e042dfda2f740e1cbe8a5ed4e21da8f23e45 (diff)
downloadgcc-275b395f894f16ac389cd8c5799e374080d3b188.tar.gz
2009-05-15 Sandra Loosemore <sandra@codesourcery.com>
gcc/ * fold-const.c (fold_convert_const_real_from_real): Check for overflow. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@147589 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 32de681e8da..1a1a80f1f7f 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2327,7 +2327,24 @@ fold_convert_const_real_from_real (tree type, const_tree arg1)
real_convert (&value, TYPE_MODE (type), &TREE_REAL_CST (arg1));
t = build_real (type, value);
- TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1);
+ /* If converting an infinity or NAN to a representation that doesn't
+ have one, set the overflow bit so that we can produce some kind of
+ error message at the appropriate point if necessary. It's not the
+ most user-friendly message, but it's better than nothing. */
+ if (REAL_VALUE_ISINF (TREE_REAL_CST (arg1))
+ && !MODE_HAS_INFINITIES (TYPE_MODE (type)))
+ TREE_OVERFLOW (t) = 1;
+ else if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1))
+ && !MODE_HAS_NANS (TYPE_MODE (type)))
+ TREE_OVERFLOW (t) = 1;
+ /* Regular overflow, conversion produced an infinity in a mode that
+ can't represent them. */
+ else if (!MODE_HAS_INFINITIES (TYPE_MODE (type))
+ && REAL_VALUE_ISINF (value)
+ && !REAL_VALUE_ISINF (TREE_REAL_CST (arg1)))
+ TREE_OVERFLOW (t) = 1;
+ else
+ TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1);
return t;
}