From: Marek Polacek Date: Fri, 7 Apr 2017 17:51:55 +0000 (+0000) Subject: re PR sanitizer/80348 (UBSAN: compile time crash in ubsan_instrument_division) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1ef532f452a10223cf9cd8f6955f066149d78498;p=gcc.git re PR sanitizer/80348 (UBSAN: compile time crash in ubsan_instrument_division) PR sanitizer/80348 * typeck.c (cp_build_binary_op): Convert COP[01] to ORIG_TYPE. * g++.dg/ubsan/div-by-zero-2.C: New test. From-SVN: r246770 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9b1f89d8ccd..5ffd1b74490 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-04-07 Marek Polacek + + PR sanitizer/80348 + * typeck.c (cp_build_binary_op): Convert COP[01] to ORIG_TYPE. + 2017-04-05 Jakub Jelinek PR c++/80309 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 79391c04fd6..65a34358192 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5218,10 +5218,12 @@ cp_build_binary_op (location_t location, original result_type. */ tree cop0 = op0; tree cop1 = op1; - if (orig_type != NULL && result_type != orig_type) + if (orig_type != NULL_TREE) { - cop0 = cp_convert (orig_type, op0, complain); - cop1 = cp_convert (orig_type, op1, complain); + if (TREE_TYPE (cop0) != orig_type) + cop0 = cp_convert (orig_type, op0, complain); + if (TREE_TYPE (cop1) != orig_type) + cop1 = cp_convert (orig_type, op1, complain); } instrument_expr = ubsan_instrument_division (location, cop0, cop1); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 94fe5a04af3..fbaef7a35ae 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-07 Marek Polacek + + PR sanitizer/80348 + * g++.dg/ubsan/div-by-zero-2.C: New test. + 2017-04-07 Vladimir Makarov PR rtl-optimization/70478 diff --git a/gcc/testsuite/g++.dg/ubsan/div-by-zero-2.C b/gcc/testsuite/g++.dg/ubsan/div-by-zero-2.C new file mode 100644 index 00000000000..d500ae62b4b --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/div-by-zero-2.C @@ -0,0 +1,10 @@ +// PR sanitizer/80348 +// { dg-do compile } +// { dg-options "-fsanitize=integer-divide-by-zero" } + +void +foo () +{ + if (0) + unsigned ((0 != 60806) > (0 != 0)) / 0; // { dg-warning "division by zero" } +}