diff options
author | Jakub Jelinek <jakub@redhat.com> | 2015-01-05 22:46:31 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2015-01-05 22:46:31 +0100 |
commit | e534110031564716a1e495a38bf8d893b23a5993 (patch) | |
tree | 0fb2cd367e6916c7cd83f6635fec9facebcc58a5 /gcc/c/c-convert.c | |
parent | 15aed8c4609257ea0280553ad2a5946bdaf06ec9 (diff) | |
download | gcc-e534110031564716a1e495a38bf8d893b23a5993.zip gcc-e534110031564716a1e495a38bf8d893b23a5993.tar.gz gcc-e534110031564716a1e495a38bf8d893b23a5993.tar.bz2 |
re PR sanitizer/64344 ([UBSAN] ICE with -fsanitize=float-cast-overflow [ICE in -fsanitize=float-cast-overflow])
PR sanitizer/64344
* ubsan.h (ubsan_instrument_float_cast): Add ARG argument.
* ubsan.c (ubsan_instrument_float_cast): Add ARG argument, pass
it to libubsan handler instead of EXPR. Fold comparisons earlier,
if the result is integer_zerop, return NULL_TREE.
* convert.c (convert_to_integer): Pass expr as ARG.
c/
* c-typeck.c (convert_for_assignment, c_finish_return): For
-fsanitize=float-cast-overflow casts from REAL_TYPE to integer/enum
types also set in_late_binary_op around convert call.
* c-convert.c (convert): For -fsanitize=float-cast-overflow REAL_TYPE
to integral type casts, if not in_late_binary_op, pass c_fully_fold
result on expr as last argument to ubsan_instrument_float_cast,
if in_late_binary_op, don't use c_save_expr but save_expr.
testsuite/
* c-c++-common/ubsan/pr64344-1.c: New test.
* c-c++-common/ubsan/pr64344-2.c: New test.
From-SVN: r219201
Diffstat (limited to 'gcc/c/c-convert.c')
-rw-r--r-- | gcc/c/c-convert.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/gcc/c/c-convert.c b/gcc/c/c-convert.c index cd78085..c0da134 100644 --- a/gcc/c/c-convert.c +++ b/gcc/c/c-convert.c @@ -117,8 +117,18 @@ convert (tree type, tree expr) && !lookup_attribute ("no_sanitize_undefined", DECL_ATTRIBUTES (current_function_decl))) { - expr = c_save_expr (expr); - tree check = ubsan_instrument_float_cast (loc, type, expr); + tree arg; + if (in_late_binary_op) + { + expr = save_expr (expr); + arg = expr; + } + else + { + expr = c_save_expr (expr); + arg = c_fully_fold (expr, false, NULL); + } + tree check = ubsan_instrument_float_cast (loc, type, expr, arg); expr = fold_build1 (FIX_TRUNC_EXPR, type, expr); if (check == NULL) return expr; |