[Bug sanitizer/66908] Uninitialized variable when compiled with UBsan
mpolacek at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jul 22 14:36:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66908
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Oh silly me! This should work; Maxim, could you possibly try this patch?
--- gcc/c-family/c-ubsan.c
+++ 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);
More information about the Gcc-bugs
mailing list