diff options
Diffstat (limited to 'gcc/ubsan.cc')
-rw-r--r-- | gcc/ubsan.cc | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/gcc/ubsan.cc b/gcc/ubsan.cc index 35a7dbd..6d74825 100644 --- a/gcc/ubsan.cc +++ b/gcc/ubsan.cc @@ -358,10 +358,6 @@ get_ubsan_type_info_for_type (tree type) return 0; } -/* Counters for internal labels. ubsan_ids[0] for Lubsan_type, - ubsan_ids[1] for Lubsan_data labels. */ -static GTY(()) unsigned int ubsan_ids[2]; - /* Helper routine that returns ADDR_EXPR of a VAR_DECL of a type descriptor. It first looks into the hash table; if not found, create the VAR_DECL, put it into the hash table and return the @@ -552,10 +548,8 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle) TREE_READONLY (str) = 1; TREE_STATIC (str) = 1; - char tmp_name[32]; - ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_type", ubsan_ids[0]++); - decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name), - dtype); + decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, + generate_internal_label ("Lubsan_type"), dtype); TREE_STATIC (decl) = 1; TREE_PUBLIC (decl) = 0; DECL_ARTIFICIAL (decl) = 1; @@ -659,10 +653,8 @@ ubsan_create_data (const char *name, int loccnt, const location_t *ploc, ...) layout_type (ret); /* Now, fill in the type. */ - char tmp_name[32]; - ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_data", ubsan_ids[1]++); - tree var = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name), - ret); + tree var = build_decl (UNKNOWN_LOCATION, VAR_DECL, + generate_internal_label ("Lubsan_data"), ret); TREE_STATIC (var) = 1; TREE_PUBLIC (var) = 0; DECL_ARTIFICIAL (var) = 1; @@ -2046,9 +2038,9 @@ instrument_nonnull_arg (gimple_stmt_iterator *gsi) for (unsigned int i = 0; i < gimple_call_num_args (stmt); i++) { tree arg = gimple_call_arg (stmt, i); - tree arg2; + tree arg2, arg3; if (POINTER_TYPE_P (TREE_TYPE (arg)) - && infer_nonnull_range_by_attribute (stmt, arg, &arg2)) + && infer_nonnull_range_by_attribute (stmt, arg, &arg2, &arg3)) { gimple *g; if (!is_gimple_val (arg)) @@ -2058,6 +2050,8 @@ instrument_nonnull_arg (gimple_stmt_iterator *gsi) gsi_safe_insert_before (gsi, g); arg = gimple_assign_lhs (g); } + if (arg2 == arg3) + arg3 = NULL_TREE; if (arg2 && !is_gimple_val (arg2)) { g = gimple_build_assign (make_ssa_name (TREE_TYPE (arg2)), arg2); @@ -2065,6 +2059,13 @@ instrument_nonnull_arg (gimple_stmt_iterator *gsi) gsi_safe_insert_before (gsi, g); arg2 = gimple_assign_lhs (g); } + if (arg3 && !is_gimple_val (arg3)) + { + g = gimple_build_assign (make_ssa_name (TREE_TYPE (arg3)), arg3); + gimple_set_location (g, loc[0]); + gsi_safe_insert_before (gsi, g); + arg3 = gimple_assign_lhs (g); + } basic_block then_bb, fallthru_bb; *gsi = create_cond_insert_point (gsi, true, false, true, @@ -2088,6 +2089,18 @@ instrument_nonnull_arg (gimple_stmt_iterator *gsi) *gsi = gsi_after_labels (then_bb); } + if (arg3) + { + *gsi = create_cond_insert_point (gsi, true, false, true, + &then_bb, &fallthru_bb); + g = gimple_build_cond (NE_EXPR, arg3, + build_zero_cst (TREE_TYPE (arg3)), + NULL_TREE, NULL_TREE); + gimple_set_location (g, loc[0]); + gsi_insert_after (gsi, g, GSI_NEW_STMT); + + *gsi = gsi_after_labels (then_bb); + } if (flag_sanitize_trap & SANITIZE_NONNULL_ATTRIBUTE) g = gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0); else |