From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id F23683856255; Wed, 11 May 2022 06:22:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F23683856255 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-10103] ubsan: Use -fno{, -}sanitize=float-divide-by-zero for float division by zero recovery [PR102515] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 8837138d292eb4221a5d5a985d25e487a127539d X-Git-Newrev: f806bea0a6c1c5b7d517c7aee053c21b4d2155c6 Message-Id: <20220511062236.F23683856255@sourceware.org> Date: Wed, 11 May 2022 06:22:36 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2022 06:22:37 -0000 https://gcc.gnu.org/g:f806bea0a6c1c5b7d517c7aee053c21b4d2155c6 commit r9-10103-gf806bea0a6c1c5b7d517c7aee053c21b4d2155c6 Author: Jakub Jelinek Date: Fri Oct 1 14:27:32 2021 +0200 ubsan: Use -fno{,-}sanitize=float-divide-by-zero for float division by zero recovery [PR102515] We've been using -f{,no-}sanitize-recover=integer-divide-by-zero to decide on the float -fsanitize=float-divide-by-zero instrumentation _abort suffix. This patch fixes it to use -f{,no-}sanitize-recover=float-divide-by-zero for it instead. 2021-10-01 Jakub Jelinek Richard Biener PR sanitizer/102515 gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Check the right flag_sanitize_recover bit, depending on which sanitization is done. gcc/testsuite/ * c-c++-common/ubsan/float-div-by-zero-2.c: New test. (cherry picked from commit 9c1a633d96926357155d4702b66f8a0ec856a81f) Diff: --- gcc/c-family/c-ubsan.c | 10 +++++++--- gcc/testsuite/c-c++-common/ubsan/float-div-by-zero-2.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gcc/c-family/c-ubsan.c b/gcc/c-family/c-ubsan.c index e4e2c7a1ce8..c0142a642ae 100644 --- a/gcc/c-family/c-ubsan.c +++ b/gcc/c-family/c-ubsan.c @@ -41,6 +41,7 @@ ubsan_instrument_division (location_t loc, tree op0, tree op1) { tree t, tt; tree type = TREE_TYPE (op0); + enum sanitize_code flag = SANITIZE_DIVIDE; /* At this point both operands should have the same type, because they are already converted to RESULT_TYPE. @@ -58,8 +59,11 @@ ubsan_instrument_division (location_t loc, tree op0, tree op1) op1, build_int_cst (type, 0)); else if (TREE_CODE (type) == REAL_TYPE && sanitize_flags_p (SANITIZE_FLOAT_DIVIDE)) - t = fold_build2 (EQ_EXPR, boolean_type_node, - op1, build_real (type, dconst0)); + { + t = fold_build2 (EQ_EXPR, boolean_type_node, + op1, build_real (type, dconst0)); + flag = SANITIZE_FLOAT_DIVIDE; + } else return NULL_TREE; @@ -95,7 +99,7 @@ ubsan_instrument_division (location_t loc, tree op0, tree op1) NULL_TREE); data = build_fold_addr_expr_loc (loc, data); enum built_in_function bcode - = (flag_sanitize_recover & SANITIZE_DIVIDE) + = (flag_sanitize_recover & flag) ? BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW : BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT; tt = builtin_decl_explicit (bcode); diff --git a/gcc/testsuite/c-c++-common/ubsan/float-div-by-zero-2.c b/gcc/testsuite/c-c++-common/ubsan/float-div-by-zero-2.c new file mode 100644 index 00000000000..61d050ae23b --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/float-div-by-zero-2.c @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-shouldfail "ubsan" } */ +/* { dg-options "-fsanitize=float-divide-by-zero -fno-sanitize-recover=float-divide-by-zero -fsanitize-recover=integer-divide-by-zero" } */ + +int +main (void) +{ + volatile float a = 1.3f; + volatile double b = 0.0; + volatile int c = 4; + volatile float res; + + res = a / b; + + return 0; +} + +/* { dg-output "division by zero" } */