Skip to content

Commit 6b51aeb

Browse files
Merge pull request #3947 from tautschnig/revert-symex-renaming
Revert symex renaming
2 parents f6f7ecd + 60ce997 commit 6b51aeb

File tree

5 files changed

+28
-119
lines changed

5 files changed

+28
-119
lines changed

regression/cbmc/vla1/main.c

Lines changed: 0 additions & 30 deletions
This file was deleted.

regression/cbmc/vla1/program-only.desc

Lines changed: 0 additions & 12 deletions
This file was deleted.

regression/cbmc/vla1/test.desc

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/ansi-c/c_typecheck_type.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ 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>
2019
#include <util/mathematical_types.h>
2120
#include <util/pointer_offset_size.h>
2221
#include <util/simplify_expr.h>
@@ -609,25 +608,43 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
609608
throw 0;
610609
}
611610

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);
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+
} while(symbol_table.symbols.find(temp_identifier) !=
622+
symbol_table.symbols.end());
623+
624+
// add the symbol to symbol table
625+
auxiliary_symbolt new_symbol;
626+
new_symbol.name = temp_identifier;
627+
new_symbol.pretty_name = id2string(current_symbol.pretty_name) + suffix;
628+
new_symbol.base_name = id2string(current_symbol.base_name) + suffix;
629+
new_symbol.type = size.type();
619630
new_symbol.type.set(ID_C_constant, true);
620-
new_symbol.value = typecast_exprt::conditional_cast(size, size_type());
631+
new_symbol.value = size;
632+
new_symbol.location = size_source_location;
633+
new_symbol.mode = mode;
634+
635+
symbol_table.add(new_symbol);
621636

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

625642
code_declt declaration(symbol_expr);
626643
declaration.add_source_location() = size_source_location;
627644

628645
code_assignt assignment;
629646
assignment.lhs()=symbol_expr;
630-
assignment.rhs() = new_symbol.value;
647+
assignment.rhs() = size;
631648
assignment.add_source_location() = size_source_location;
632649

633650
// store the code

src/goto-symex/goto_symex_state.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -618,70 +618,12 @@ void goto_symex_statet::rename_address(
618618
}
619619
}
620620

621-
/// Return true if, and only if, the \p type or one of its subtypes requires SSA
622-
/// renaming. Renaming is necessary when symbol expressions occur within the
623-
/// type, which is the case for arrays of non-constant size.
624-
static bool requires_renaming(const typet &type, const namespacet &ns)
625-
{
626-
if(type.id() == ID_array)
627-
{
628-
const auto &array_type = to_array_type(type);
629-
return requires_renaming(array_type.subtype(), ns) ||
630-
!array_type.size().is_constant();
631-
}
632-
else if(
633-
type.id() == ID_struct || type.id() == ID_union || type.id() == ID_class)
634-
{
635-
const struct_union_typet &s_u_type = to_struct_union_type(type);
636-
const struct_union_typet::componentst &components = s_u_type.components();
637-
638-
for(auto &component : components)
639-
{
640-
// be careful, or it might get cyclic
641-
if(
642-
component.type().id() != ID_pointer &&
643-
requires_renaming(component.type(), ns))
644-
{
645-
return true;
646-
}
647-
}
648-
649-
return false;
650-
}
651-
else if(type.id() == ID_pointer)
652-
{
653-
return requires_renaming(to_pointer_type(type).subtype(), ns);
654-
}
655-
else if(type.id() == ID_symbol_type)
656-
{
657-
const symbolt &symbol = ns.lookup(to_symbol_type(type));
658-
return requires_renaming(symbol.type, ns);
659-
}
660-
else if(type.id() == ID_union_tag)
661-
{
662-
const symbolt &symbol = ns.lookup(to_union_tag_type(type));
663-
return requires_renaming(symbol.type, ns);
664-
}
665-
else if(type.id() == ID_struct_tag)
666-
{
667-
const symbolt &symbol = ns.lookup(to_struct_tag_type(type));
668-
return requires_renaming(symbol.type, ns);
669-
}
670-
671-
return false;
672-
}
673-
674621
void goto_symex_statet::rename(
675622
typet &type,
676623
const irep_idt &l1_identifier,
677624
const namespacet &ns,
678625
levelt level)
679626
{
680-
// check whether there are symbol expressions in the type; if not, there
681-
// is no need to expand the struct/union tags in the type
682-
if(!requires_renaming(type, ns))
683-
return; // no action
684-
685627
// rename all the symbols with their last known value
686628
// to the given level
687629

0 commit comments

Comments
 (0)