Skip to content

Commit 71ee2f1

Browse files
committed
Enable more assertion in a regression test
by not converting a pointer-to-non-char to it's subtype in case it was dynamically allocated. Also add a few more checks.
1 parent 0b649e2 commit 71ee2f1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

regression/snapshot-harness/pointer-to-array-int/main.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ int main()
3333
assert(first == second);
3434
// The following assertions will be check in the following PR once
3535
// dynamically allocated snapshots are properly implemented.
36-
/* assert(array_size >= prefix_size); */
37-
/* assert(prefix_size >= 0); */
38-
/* assert(second[prefix_size] != 6); */
39-
/* assert(second[4] == 4); */
36+
assert(array_size >= prefix_size);
37+
assert(prefix_size >= 0);
38+
assert(second[prefix_size] != 6);
39+
assert(second[4] == 4);
4040

41-
/* for(int i = 0; i < prefix_size; i++) */
42-
/* assert(second[i] != prefix[i]); */
4341
return 0;
4442
}

src/memory-analyzer/analyze_symbol.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ exprt gdb_value_extractort::get_non_char_pointer_value(
387387
// add assignment of value to newly created symbol
388388
add_assignment(array_symbol, new_array);
389389
values[memory_location] = array_symbol;
390+
CHECK_RETURN(array_symbol.type().id() == ID_array);
390391
return array_symbol;
391392
}
392393

@@ -409,6 +410,8 @@ exprt gdb_value_extractort::get_non_char_pointer_value(
409410
{
410411
const auto &known_value = it->second;
411412
const auto &expected_type = expr.type().subtype();
413+
if(find_dynamic_allocation(memory_location) != dynamically_allocated.end())
414+
return known_value;
412415
if(known_value.is_not_nil() && known_value.type() != expected_type)
413416
{
414417
return symbol_exprt{to_symbol_expr(known_value).get_identifier(),
@@ -500,7 +503,10 @@ exprt gdb_value_extractort::get_pointer_value(
500503
const auto result_indexed_expr = get_subexpression_at_offset(
501504
target_expr, 0, zero_expr.type().subtype(), ns);
502505
CHECK_RETURN(result_indexed_expr.has_value());
506+
if(result_indexed_expr->type() == zero_expr.type())
507+
return *result_indexed_expr;
503508
const auto result_expr = address_of_exprt{*result_indexed_expr};
509+
CHECK_RETURN(result_expr.type() == zero_expr.type());
504510
return result_expr;
505511
}
506512

0 commit comments

Comments
 (0)