Skip to content

Commit 0e01c89

Browse files
committed
Use get_fresh_aux_symbol to create $array_size and fix its type
An array_size symbol should be of type size_type(), and we can safely rely on common logic to find fresh symbols.
1 parent 480f19e commit 0e01c89

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--program-only
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
\(__CPROVER_size_t\)x\$array_size
10+
--
11+
There should not be any type cast of x$array_size to __CPROVER_size_t, because
12+
it already is of that type.

src/ansi-c/c_typecheck_type.cpp

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/arith_tools.h>
1717
#include <util/c_types.h>
1818
#include <util/config.h>
19+
#include <util/fresh_symbol.h>
1920
#include <util/mathematical_types.h>
2021
#include <util/pointer_offset_size.h>
2122
#include <util/simplify_expr.h>
@@ -608,44 +609,25 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
608609
throw 0;
609610
}
610611

611-
// Need to pull out! We insert new symbol.
612-
unsigned count=0;
613-
irep_idt temp_identifier;
614-
std::string suffix;
615-
616-
do
617-
{
618-
suffix="$array_size"+std::to_string(count);
619-
temp_identifier=id2string(current_symbol.name)+suffix;
620-
count++;
621-
}
622-
while(symbol_table.symbols.find(temp_identifier)!=
623-
symbol_table.symbols.end());
624-
625-
// add the symbol to symbol table
626-
auxiliary_symbolt new_symbol;
627-
new_symbol.name=temp_identifier;
628-
new_symbol.pretty_name=id2string(current_symbol.pretty_name)+suffix;
629-
new_symbol.base_name=id2string(current_symbol.base_name)+suffix;
630-
new_symbol.type=size.type();
612+
symbolt &new_symbol = get_fresh_aux_symbol(
613+
size_type(),
614+
id2string(current_symbol.name) + "$array_size",
615+
id2string(current_symbol.base_name) + "$array_size",
616+
size_source_location,
617+
mode,
618+
symbol_table);
631619
new_symbol.type.set(ID_C_constant, true);
632-
new_symbol.value=size;
633-
new_symbol.location = size_source_location;
634-
new_symbol.mode = mode;
635-
636-
symbol_table.add(new_symbol);
620+
new_symbol.value = typecast_exprt::conditional_cast(size, size_type());
637621

638622
// produce the code that declares and initializes the symbol
639-
symbol_exprt symbol_expr;
640-
symbol_expr.set_identifier(temp_identifier);
641-
symbol_expr.type()=new_symbol.type;
623+
symbol_exprt symbol_expr = new_symbol.symbol_expr();
642624

643625
code_declt declaration(symbol_expr);
644626
declaration.add_source_location() = size_source_location;
645627

646628
code_assignt assignment;
647629
assignment.lhs()=symbol_expr;
648-
assignment.rhs()=size;
630+
assignment.rhs() = new_symbol.value;
649631
assignment.add_source_location() = size_source_location;
650632

651633
// store the code

0 commit comments

Comments
 (0)