diff --git a/playground/spslr_pinpoint.cpp b/playground/spslr_pinpoint.cpp index b285bbf..0b9cd84 100644 --- a/playground/spslr_pinpoint.cpp +++ b/playground/spslr_pinpoint.cpp @@ -336,7 +336,6 @@ static tree instrument_offsetof_maybe(tree ref) { tree cast_back = build1_loc(loc, NOP_EXPR, field_ptr_type, plus); tree new_ref = build1_loc(loc, INDIRECT_REF, result_type, cast_back); - return new_ref; } @@ -478,9 +477,8 @@ static tree gimple_instrument_offsetof_maybe(tree ref, gimple_stmt_iterator* gsi if (!gcrc.relevant) return NULL_TREE; - // Store base pointer in a temporary variable (as char*) + // Get base pointer - tree char_ptr_type = build_pointer_type(char_type_node); tree base_tmp = NULL_TREE; { tree base_ptr; @@ -492,11 +490,7 @@ static tree gimple_instrument_offsetof_maybe(tree ref, gimple_stmt_iterator* gsi base_ptr = build_fold_addr_expr(gcrc.base); } - tree base_char_ptr = fold_convert(char_ptr_type, base_ptr); - base_tmp = create_tmp_var(char_ptr_type, NULL); - - gimple* base_tmp_assignment = gimple_build_assign(base_tmp, base_char_ptr); - gsi_insert_before(gsi, base_tmp_assignment, GSI_SAME_STMT); + base_tmp = base_ptr; } // For each component ref in chain, add the member offset to the pointer @@ -520,10 +514,12 @@ static tree gimple_instrument_offsetof_maybe(tree ref, gimple_stmt_iterator* gsi gimple_call_set_lhs(call_stmt, offset_tmp); gsi_insert_before(gsi, call_stmt, GSI_SAME_STMT); - // Add call return value to current base pointer - tree addition = build2(POINTER_PLUS_EXPR, char_ptr_type, base_tmp, offset_tmp); - base_tmp = create_tmp_var(char_ptr_type, NULL); - gimple* addition_assignment = gimple_build_assign(base_tmp, addition); + // Add call return value to current base pointer (result is field pointer) + tree field_ptr_type = build_pointer_type(TREE_TYPE(cr.t)); + tree field_ptr = build2(POINTER_PLUS_EXPR, field_ptr_type, base_tmp, offset_tmp); + + base_tmp = create_tmp_var(field_ptr_type, NULL); + gimple* addition_assignment = gimple_build_assign(base_tmp, field_ptr); gsi_insert_before(gsi, addition_assignment, GSI_SAME_STMT); } else { // Add offsetof contant @@ -536,25 +532,20 @@ static tree gimple_instrument_offsetof_maybe(tree ref, gimple_stmt_iterator* gsi return NULL_TREE; } - // Add constant offset to current base pointer - tree addition = build2(POINTER_PLUS_EXPR, char_ptr_type, base_tmp, build_int_cst(sizetype, offset)); - base_tmp = create_tmp_var(char_ptr_type, NULL); - gimple* addition_assignment = gimple_build_assign(base_tmp, addition); + // Add constant offset to current base pointer (result is field pointer) + tree field_ptr_type = build_pointer_type(TREE_TYPE(cr.t)); + tree field_ptr = build2(POINTER_PLUS_EXPR, field_ptr_type, base_tmp, build_int_cst(sizetype, offset)); + + base_tmp = create_tmp_var(field_ptr_type, NULL); + gimple* addition_assignment = gimple_build_assign(base_tmp, field_ptr); gsi_insert_before(gsi, addition_assignment, GSI_SAME_STMT); } } - // Cast char pointer back to field pointer and dereference + // Current pointer is a field pointer -> dereference - tree field_ptr_type = build_pointer_type(TREE_TYPE(ref)); - - tree field_ptr = fold_convert(field_ptr_type, base_tmp); - tree field_ptr_tmp = create_tmp_var(field_ptr_type, NULL); - gimple* field_ptr_tmp_assignment = gimple_build_assign(field_ptr_tmp, field_ptr); - gsi_insert_before(gsi, field_ptr_tmp_assignment, GSI_SAME_STMT); - - tree offset0 = fold_convert(field_ptr_type, build_int_cst(sizetype, 0)); - tree result_ref = build2(MEM_REF, TREE_TYPE(ref), field_ptr_tmp, offset0); + tree offset0 = fold_convert(TREE_TYPE(base_tmp), build_int_cst(sizetype, 0)); + tree result_ref = build2(MEM_REF, TREE_TYPE(ref), base_tmp, offset0); return result_ref; }