public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> 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] Date: Wed, 11 May 2022 06:22:36 +0000 (GMT) [thread overview] Message-ID: <20220511062236.F23683856255@sourceware.org> (raw) https://gcc.gnu.org/g:f806bea0a6c1c5b7d517c7aee053c21b4d2155c6 commit r9-10103-gf806bea0a6c1c5b7d517c7aee053c21b4d2155c6 Author: Jakub Jelinek <jakub@redhat.com> 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 <jakub@redhat.com> Richard Biener <rguenther@suse.de> 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" } */
reply other threads:[~2022-05-11 6:22 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220511062236.F23683856255@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).