diff options
author | Marek Polacek <polacek@redhat.com> | 2015-07-23 13:54:06 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2015-07-23 13:54:06 +0000 |
commit | dc891fe75e30646dea032b06ab484d814c7e05b6 (patch) | |
tree | a2fc3d77b00bbd4499e2b82dfff536de8c0727c1 /gcc/c-family | |
parent | 62fb67d77a7a68c5cfa7d78d751817b68ea78a87 (diff) | |
download | gcc-dc891fe75e30646dea032b06ab484d814c7e05b6.zip gcc-dc891fe75e30646dea032b06ab484d814c7e05b6.tar.gz gcc-dc891fe75e30646dea032b06ab484d814c7e05b6.tar.bz2 |
re PR sanitizer/66908 (Uninitialized variable when compiled with UBsan)
PR sanitizer/66908
* c-ubsan.c: Include gimplify.h.
(ubsan_instrument_division): Unshare OP0 and OP1.
(ubsan_instrument_shift): Likewise.
* c-c++-common/ubsan/pr66908.c: New test.
From-SVN: r226110
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-family/c-ubsan.c | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9751ba9..04c2fd6 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2015-07-23 Marek Polacek <polacek@redhat.com> + + PR sanitizer/66908 + * c-ubsan.c: Include gimplify.h. + (ubsan_instrument_division): Unshare OP0 and OP1. + (ubsan_instrument_shift): Likewise. + 2015-07-20 Marek Polacek <polacek@redhat.com> Richard Sandiford <richard.sandiford@arm.com> diff --git a/gcc/c-family/c-ubsan.c b/gcc/c-family/c-ubsan.c index 0baf118..3869511 100644 --- a/gcc/c-family/c-ubsan.c +++ b/gcc/c-family/c-ubsan.c @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "internal-fn.h" #include "stor-layout.h" #include "builtins.h" +#include "gimplify.h" /* Instrument division by zero and INT_MIN / -1. If not instrumenting, return NULL_TREE. */ @@ -54,6 +55,9 @@ ubsan_instrument_division (location_t loc, tree op0, tree op1) gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (op0)) == TYPE_MAIN_VARIANT (TREE_TYPE (op1))); + op0 = unshare_expr (op0); + op1 = unshare_expr (op1); + if (TREE_CODE (type) == INTEGER_TYPE && (flag_sanitize & SANITIZE_DIVIDE)) t = fold_build2 (EQ_EXPR, boolean_type_node, @@ -134,6 +138,9 @@ ubsan_instrument_shift (location_t loc, enum tree_code code, HOST_WIDE_INT op0_prec = TYPE_PRECISION (type0); tree uprecm1 = build_int_cst (op1_utype, op0_prec - 1); + op0 = unshare_expr (op0); + op1 = unshare_expr (op1); + t = fold_convert_loc (loc, op1_utype, op1); t = fold_build2 (GT_EXPR, boolean_type_node, t, uprecm1); |