aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2016-06-08 19:03:17 +0000
committerJakub Jelinek <jakub@gcc.gnu.org>2016-06-08 21:03:17 +0200
commit44a845ca0e592ca187fbab07ac9e055b20fb11cc (patch)
tree3a15f43474585970a2b22a98bf6ff1b46fcf075f /gcc/c
parent379aea728edb345f42b19dfade5529f8f9e8a6da (diff)
downloadgcc-44a845ca0e592ca187fbab07ac9e055b20fb11cc.zip
gcc-44a845ca0e592ca187fbab07ac9e055b20fb11cc.tar.gz
gcc-44a845ca0e592ca187fbab07ac9e055b20fb11cc.tar.bz2
re PR c++/70507 (integer overflow builtins not constant expressions)
PR c++/70507 PR c/68120 * builtins.def (BUILT_IN_ADD_OVERFLOW_P, BUILT_IN_SUB_OVERFLOW_P, BUILT_IN_MUL_OVERFLOW_P): New builtins. * builtins.c: Include gimple-fold.h. (fold_builtin_arith_overflow): Handle BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P. (fold_builtin_3): Likewise. * doc/extend.texi (Integer Overflow Builtins): Document __builtin_{add,sub,mul}_overflow_p. gcc/c/ * c-typeck.c (convert_arguments): Don't promote last argument of BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P. gcc/cp/ * constexpr.c: Include gimple-fold.h. (cxx_eval_internal_function): New function. (cxx_eval_call_expression): Call it. (potential_constant_expression_1): Handle integer arithmetic overflow built-ins. * tree.c (builtin_valid_in_constant_expr_p): Handle BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P. gcc/c-family/ * c-common.c (check_builtin_function_arguments): Handle BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P. gcc/testsuite/ * c-c++-common/builtin-arith-overflow-1.c: Add test cases. * c-c++-common/builtin-arith-overflow-2.c: New test. * g++.dg/ext/builtin-arith-overflow-1.C: New test. * g++.dg/cpp0x/constexpr-arith-overflow.C: New test. * g++.dg/cpp1y/constexpr-arith-overflow.C: New test. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r237238
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog8
-rw-r--r--gcc/c/c-typeck.c17
2 files changed, 22 insertions, 3 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 9f0b91a..4d30245 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,11 @@
+2016-06-08 Martin Sebor <msebor@redhat.com>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/70507
+ PR c/68120
+ * c-typeck.c (convert_arguments): Don't promote last argument
+ of BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P.
+
2016-06-08 Marek Polacek <polacek@redhat.com>
PR c/71418
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index cd8e9e5..a681d76 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -3186,6 +3186,7 @@ convert_arguments (location_t loc, vec<location_t> arg_loc, tree typelist,
const bool type_generic = fundecl
&& lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
bool type_generic_remove_excess_precision = false;
+ bool type_generic_overflow_p = false;
tree selector;
/* Change pointer to function to the function itself for
@@ -3215,8 +3216,15 @@ convert_arguments (location_t loc, vec<location_t> arg_loc, tree typelist,
type_generic_remove_excess_precision = true;
break;
+ case BUILT_IN_ADD_OVERFLOW_P:
+ case BUILT_IN_SUB_OVERFLOW_P:
+ case BUILT_IN_MUL_OVERFLOW_P:
+ /* The last argument of these type-generic builtins
+ should not be promoted. */
+ type_generic_overflow_p = true;
+ break;
+
default:
- type_generic_remove_excess_precision = false;
break;
}
}
@@ -3466,9 +3474,12 @@ convert_arguments (location_t loc, vec<location_t> arg_loc, tree typelist,
parmval = convert (double_type_node, val);
}
}
- else if (excess_precision && !type_generic)
+ else if ((excess_precision && !type_generic)
+ || (type_generic_overflow_p && parmnum == 2))
/* A "double" argument with excess precision being passed
- without a prototype or in variable arguments. */
+ without a prototype or in variable arguments.
+ The last argument of __builtin_*_overflow_p should not be
+ promoted. */
parmval = convert (valtype, val);
else if ((invalid_func_diag =
targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))