On 12/14/13 12:53, Jakub Jelinek wrote:
2013-12-14  Jakub Jelinek  <ja...@redhat.com>

        * ubsan.c: Include tree-ssanames.h, asan.h and gimplify-me.h.
        (ubsan_type_descriptor): Handle BOOLEAN_TYPE and ENUMERAL_TYPE
        like INTEGER_TYPE.
        (instrument_bool_enum_load): New function.
        (ubsan_pass): Call it.
        (gate_ubsan): Also enable for SANITIZE_BOOL or SANITIZE_ENUM.
        * asan.c (create_cond_insert_point): No longer static.
        * asan.h (create_cond_insert_point): Declare.
        * sanitizer.def (BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE): New
        built-in.
        * opts.c (common_handle_option): Handle -fsanitize=bool and
        -fsanitize=enum.
        * builtins.c (fold_builtin_memory_op): When sanitizing bool
        and enum loads, don't use enum or bool types for memcpy folding.
        * flag-types.h (SANITIZE_BOOL, SANITIZE_ENUM): New.
        (SANITIZE_UNDEFINED): Or these in.

        * c-c++-common/ubsan/load-bool-enum.c: New test.
OK with nits noted below fixed:

+
+  int modebitsize = GET_MODE_BITSIZE (TYPE_MODE (type));
+  HOST_WIDE_INT bitsize, bitpos;
+  tree offset;
+  enum machine_mode mode;
+  int volatilep = 0, unsignedp = 0;
+  tree base = get_inner_reference (rhs, &bitsize, &bitpos, &offset, &mode,
+                                  &unsignedp, &volatilep, false);
+  tree utype = build_nonstandard_integer_type (modebitsize, 1);
+
+  if ((TREE_CODE (base) == VAR_DECL && DECL_HARD_REGISTER (base))
+      || (bitpos % modebitsize) != 0
+      || bitsize != modebitsize
+      || GET_MODE_BITSIZE (TYPE_MODE (utype)) != modebitsize
+      || TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME)
+    return;
+
+  location_t loc = gimple_location (stmt);
+  tree ptype = build_pointer_type (TREE_TYPE (rhs));
+  tree atype = reference_alias_ptr_type (rhs);
+  gimple g = gimple_build_assign (make_ssa_name (ptype, NULL),
+                                 build_fold_addr_expr (rhs));
+  gimple_set_location (g, loc);
+  gsi_insert_before (gsi, g, GSI_SAME_STMT);
+  tree mem = build2 (MEM_REF, utype, gimple_assign_lhs (g),
+                    build_int_cst (atype, 0));
+  tree urhs = make_ssa_name (utype, NULL);
+  g = gimple_build_assign (urhs, mem);
+  gimple_set_location (g, loc);
+  gsi_insert_before (gsi, g, GSI_SAME_STMT);
+  minv = fold_convert (utype, minv);
+  maxv = fold_convert (utype, maxv);
+  if (!integer_zerop (minv))
+    {
+      g = gimple_build_assign_with_ops (MINUS_EXPR,
+                                       make_ssa_name (utype, NULL),
+                                       urhs, minv);
+      gimple_set_location (g, loc);
+      gsi_insert_before (gsi, g, GSI_SAME_STMT);
+    }
+
+  gimple_stmt_iterator gsi2 = *gsi;
+  basic_block then_bb, fallthru_bb;
+  *gsi = create_cond_insert_point (gsi, /*before_p=*/true,
+                                  /*then_more_likely_p=*/false,
+                                  /*create_then_fallthru_edge=*/true,
+                                  &then_bb, &fallthru_bb);
Ick (comments embedded in argumust list). Is there some compelling reason for those comments?

OK with that trivial fix.

jeff

Reply via email to