From: Jakub Jelinek Date: Tue, 30 May 2017 08:16:31 +0000 (+0200) Subject: backport: re PR c/80097 (internal compiler error in c_fully_fold_internal with std... X-Git-Tag: releases/gcc-5.5.0~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61384973125cc0c0c530a2e696cb14deb261931e;p=thirdparty%2Fgcc.git backport: re PR c/80097 (internal compiler error in c_fully_fold_internal with std=c89 and -fsanitize=float-divide-by-zero) Backported from mainline 2017-03-21 Jakub Jelinek PR c/80097 * c-typeck.c (build_binary_op): Add EXCESS_PRECISION_EXPR only around optional COMPOUND_EXPR with ubsan instrumentation. * gcc.dg/ubsan/pr80097.c: New test. From-SVN: r248661 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 55d8225bf03b..510bb7fc500d 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,6 +1,12 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2017-03-21 Jakub Jelinek + + PR c/80097 + * c-typeck.c (build_binary_op): Add EXCESS_PRECISION_EXPR only around + optional COMPOUND_EXPR with ubsan instrumentation. + 2017-02-16 Jakub Jelinek PR c++/79512 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 8f3086e38f9e..ce20eead1393 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -11338,14 +11338,16 @@ build_binary_op (location_t location, enum tree_code code, else if (TREE_CODE (ret) != INTEGER_CST && int_operands && !in_late_binary_op) ret = note_integer_operands (ret); - if (semantic_result_type) - ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); protected_set_expr_location (ret, location); if (instrument_expr != NULL) ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret), instrument_expr, ret); + if (semantic_result_type) + ret = build1_loc (location, EXCESS_PRECISION_EXPR, + semantic_result_type, ret); + return ret; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 39e832846485..7f1612091ef3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2017-03-21 Jakub Jelinek + + PR c/80097 + * gcc.dg/ubsan/pr80097.c: New test. + 2017-03-10 Jakub Jelinek PR c++/79896 diff --git a/gcc/testsuite/gcc.dg/ubsan/pr80097.c b/gcc/testsuite/gcc.dg/ubsan/pr80097.c new file mode 100644 index 000000000000..4d48eea69c3b --- /dev/null +++ b/gcc/testsuite/gcc.dg/ubsan/pr80097.c @@ -0,0 +1,10 @@ +/* PR c/80097 */ +/* { dg-do compile } */ +/* { dg-options "-std=c89 -fsanitize=float-divide-by-zero" } */ + +int +foo (double a) +{ + int b = (1 / a >= 1); + return b; +}