diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-08 21:46:16 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-08 21:46:16 +0000 |
commit | bb4bf88c4cd66e1393b771e1c628e03f8718f4d2 (patch) | |
tree | 56a487c2d5c324338e2eaf003172baf05b94024d /gcc/cp/cvt.c | |
parent | 7deddfded2d013c07a639873a4c90bfed40fd03e (diff) | |
download | gcc-bb4bf88c4cd66e1393b771e1c628e03f8718f4d2.tar.gz |
2010-11-08 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 166453
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@166454 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/cvt.c')
-rw-r--r-- | gcc/cp/cvt.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index d2d6f4acdf9..2f7823f76d9 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -543,12 +543,35 @@ force_rvalue (tree expr) } -/* Fold away simple conversions, but make sure the result is an rvalue. */ +/* If EXPR and ORIG are INTEGER_CSTs, return a version of EXPR that has + TREE_OVERFLOW set only if it is set in ORIG. Otherwise, return EXPR + unchanged. */ + +static tree +ignore_overflows (tree expr, tree orig) +{ + if (TREE_CODE (expr) == INTEGER_CST + && TREE_CODE (orig) == INTEGER_CST + && TREE_OVERFLOW (expr) != TREE_OVERFLOW (orig)) + { + gcc_assert (!TREE_OVERFLOW (orig)); + /* Ensure constant sharing. */ + expr = build_int_cst_wide (TREE_TYPE (expr), + TREE_INT_CST_LOW (expr), + TREE_INT_CST_HIGH (expr)); + } + return expr; +} + +/* Fold away simple conversions, but make sure TREE_OVERFLOW is set + properly. */ tree cp_fold_convert (tree type, tree expr) { - return rvalue (fold_convert (type, expr)); + tree conv = fold_convert (type, expr); + conv = ignore_overflows (conv, expr); + return conv; } /* C++ conversions, preference to static cast conversions. */ @@ -661,6 +684,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags) if (INTEGRAL_CODE_P (code)) { tree intype = TREE_TYPE (e); + tree converted; if (TREE_CODE (type) == ENUMERAL_TYPE) { @@ -705,7 +729,10 @@ ocp_convert (tree type, tree expr, int convtype, int flags) if (code == BOOLEAN_TYPE) return cp_truthvalue_conversion (e); - return fold_if_not_in_template (convert_to_integer (type, e)); + converted = fold_if_not_in_template (convert_to_integer (type, e)); + + /* Ignore any integer overflow caused by the conversion. */ + return ignore_overflows (converted, e); } if (NULLPTR_TYPE_P (type) && e && null_ptr_cst_p (e)) return nullptr_node; |