aboutsummaryrefslogtreecommitdiff
path: root/gcc/convert.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-02-08 10:31:47 -0500
committerJason Merrill <jason@gcc.gnu.org>2016-02-08 10:31:47 -0500
commit415594bb5c49d69f5350401d07abac62bce8656a (patch)
treefffcfe2c7dae6ee698e378ab02e9cdf2d86a254e /gcc/convert.c
parentae9dd7f3f8219057b459356c8234bf4aa73f7e1e (diff)
downloadgcc-415594bb5c49d69f5350401d07abac62bce8656a.zip
gcc-415594bb5c49d69f5350401d07abac62bce8656a.tar.gz
gcc-415594bb5c49d69f5350401d07abac62bce8656a.tar.bz2
re PR c++/69631 (Bogus overflow in constant expression error)
PR c++/69631 gcc/ * convert.c (convert_to_integer_1): Check dofold on truncation distribution. (convert_to_pointer_maybe_fold, convert_to_real_maybe_fold) (convert_to_integer_maybe_fold, convert_to_complex_maybe_fold): Rename from *_nofold. * convert.h (convert_to_pointer_nofold, convert_to_integer_nofold) (convert_to_real_nofold, convert_to_complex_nofold): New inlines. gcc/cp/ * cp-tree.h (CONV_FOLD, CONV_BACKEND_CONVERT): New. * cvt.c (convert): Pass CONV_BACKEND_CONVERT. (ocp_convert): Use *_maybe_fold. (cp_convert_to_pointer): Add dofold parameter. * cp-gimplify.c (cp_fold) [CONVERT_EXPR]: Call convert. From-SVN: r233216
Diffstat (limited to 'gcc/convert.c')
-rw-r--r--gcc/convert.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/gcc/convert.c b/gcc/convert.c
index dd7d818..dca1d2b 100644
--- a/gcc/convert.c
+++ b/gcc/convert.c
@@ -105,12 +105,12 @@ convert_to_pointer (tree type, tree expr)
}
/* A wrapper around convert_to_pointer_1 that only folds the
- expression if it is CONSTANT_CLASS_P. */
+ expression if DOFOLD, or if it is CONSTANT_CLASS_P. */
tree
-convert_to_pointer_nofold (tree type, tree expr)
+convert_to_pointer_maybe_fold (tree type, tree expr, bool dofold)
{
- return convert_to_pointer_1 (type, expr, CONSTANT_CLASS_P (expr));
+ return convert_to_pointer_1 (type, expr, dofold || CONSTANT_CLASS_P (expr));
}
/* Convert EXPR to some floating-point type TYPE.
@@ -403,12 +403,12 @@ convert_to_real (tree type, tree expr)
}
/* A wrapper around convert_to_real_1 that only folds the
- expression if it is CONSTANT_CLASS_P. */
+ expression if DOFOLD, or if it is CONSTANT_CLASS_P. */
tree
-convert_to_real_nofold (tree type, tree expr)
+convert_to_real_maybe_fold (tree type, tree expr, bool dofold)
{
- return convert_to_real_1 (type, expr, CONSTANT_CLASS_P (expr));
+ return convert_to_real_1 (type, expr, dofold || CONSTANT_CLASS_P (expr));
}
/* Convert EXPR to some integer (or enum) type TYPE.
@@ -669,6 +669,7 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
two narrow values can be combined in their narrow type even to
make a wider result--are handled by "shorten" in build_binary_op. */
+ if (dofold)
switch (ex_form)
{
case RSHIFT_EXPR:
@@ -857,9 +858,6 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
/* This is not correct for ABS_EXPR,
since we must test the sign before truncation. */
{
- if (!dofold)
- break;
-
/* Do the arithmetic in type TYPEX,
then convert result to TYPE. */
tree typex = type;
@@ -895,7 +893,6 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
the conditional and never loses. A COND_EXPR may have a throw
as one operand, which then has void type. Just leave void
operands as they are. */
- if (dofold)
return
fold_build3 (COND_EXPR, type, TREE_OPERAND (expr, 0),
VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 1)))
@@ -968,19 +965,13 @@ convert_to_integer (tree type, tree expr)
return convert_to_integer_1 (type, expr, true);
}
-/* Convert EXPR to some integer (or enum) type TYPE.
-
- EXPR must be pointer, integer, discrete (enum, char, or bool), float,
- fixed-point or vector; in other cases error is called.
-
- The result of this is always supposed to be a newly created tree node
- not in use in any existing structure. The tree node isn't folded,
- beside EXPR is of constant class. */
+/* A wrapper around convert_to_complex_1 that only folds the
+ expression if DOFOLD, or if it is CONSTANT_CLASS_P. */
tree
-convert_to_integer_nofold (tree type, tree expr)
+convert_to_integer_maybe_fold (tree type, tree expr, bool dofold)
{
- return convert_to_integer_1 (type, expr, CONSTANT_CLASS_P (expr));
+ return convert_to_integer_1 (type, expr, dofold || CONSTANT_CLASS_P (expr));
}
/* Convert EXPR to the complex type TYPE in the usual ways. If FOLD_P is
@@ -1059,12 +1050,12 @@ convert_to_complex (tree type, tree expr)
}
/* A wrapper around convert_to_complex_1 that only folds the
- expression if it is CONSTANT_CLASS_P. */
+ expression if DOFOLD, or if it is CONSTANT_CLASS_P. */
tree
-convert_to_complex_nofold (tree type, tree expr)
+convert_to_complex_maybe_fold (tree type, tree expr, bool dofold)
{
- return convert_to_complex_1 (type, expr, CONSTANT_CLASS_P (expr));
+ return convert_to_complex_1 (type, expr, dofold || CONSTANT_CLASS_P (expr));
}
/* Convert EXPR to the vector type TYPE in the usual ways. */