Skip to content

Commit 4637f87

Browse files
committed
Fix virtual table construction
Functions are expected to have code_blockt values, don't do duplicate type checking, parameters are in the symbol table already, don't use code_function_callt.
1 parent f3550ea commit 4637f87

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

regression/cpp/virtual1/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <cassert>
2-
#include <cstdio>
1+
#include <assert.h>
2+
#include <stdio.h>
33

44
class base
55
{

regression/cpp/virtual1/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.cpp
33

44
^EXIT=0$

src/cpp/cpp_typecheck_compound_type.cpp

+19-26
Original file line numberDiff line numberDiff line change
@@ -613,42 +613,33 @@ void cpp_typecheckt::typecheck_compound_declarator(
613613
lookup(args[0].get(ID_C_identifier)).symbol_expr(),
614614
to_code_type(component.type()).parameters()[0].type());
615615

616+
side_effect_expr_function_callt expr_call;
617+
expr_call.function() =
618+
symbol_exprt(component.get_name(), component.type());
619+
expr_call.arguments().reserve(args.size());
620+
expr_call.arguments().push_back(late_cast);
621+
622+
for(const auto &arg : args)
623+
{
624+
expr_call.arguments().push_back(
625+
lookup(arg.get(ID_C_identifier)).symbol_expr());
626+
}
616627

617628
if(code_type.return_type().id()!=ID_empty &&
618629
code_type.return_type().id()!=ID_destructor)
619630
{
620-
side_effect_expr_function_callt expr_call;
621-
expr_call.function()=
622-
symbol_exprt(component.get_name(), component.type());
623631
expr_call.type()=to_code_type(component.type()).return_type();
624-
expr_call.arguments().reserve(args.size());
625-
expr_call.arguments().push_back(late_cast);
626-
627-
for(std::size_t i=1; i < args.size(); i++)
628-
{
629-
expr_call.arguments().push_back(
630-
namespacet(symbol_table).lookup(
631-
args[i].get(ID_C_identifier)).symbol_expr());
632-
}
632+
exprt already_typechecked(ID_already_typechecked);
633+
already_typechecked.move_to_operands(expr_call);
633634

634-
func_symb.value=code_returnt(expr_call);
635+
func_symb.value = code_returnt(already_typechecked).make_block();
635636
}
636637
else
637638
{
638-
code_function_callt code_func;
639-
code_func.function()=
640-
symbol_exprt(component.get_name(), component.type());
641-
code_func.arguments().reserve(args.size());
642-
code_func.arguments().push_back(late_cast);
639+
exprt already_typechecked(ID_already_typechecked);
640+
already_typechecked.move_to_operands(expr_call);
643641

644-
for(std::size_t i=1; i < args.size(); i++)
645-
{
646-
code_func.arguments().push_back(
647-
namespacet(symbol_table).lookup(
648-
args[i].get(ID_C_identifier)).symbol_expr());
649-
}
650-
651-
func_symb.value=code_func;
642+
func_symb.value = code_expressiont(already_typechecked).make_block();
652643
}
653644

654645
// add this new function to the list of components
@@ -664,6 +655,8 @@ void cpp_typecheckt::typecheck_compound_declarator(
664655
CHECK_RETURN(!failed);
665656
}
666657

658+
put_compound_into_scope(new_compo);
659+
667660
// next base
668661
virtual_bases.erase(virtual_bases.begin());
669662
}

src/cpp/cpp_typecheck_function.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ void cpp_typecheckt::convert_parameter(
3434

3535
parameter.set_identifier(identifier);
3636

37+
// the parameter may already have been set up if dealing with virtual methods
38+
const symbolt *check_symbol;
39+
if(!lookup(identifier, check_symbol))
40+
return;
41+
3742
symbolt symbol;
3843

3944
symbol.name=identifier;
@@ -93,7 +98,12 @@ void cpp_typecheckt::convert_function(symbolt &symbol)
9398
assert(symbol.value.id()==ID_code);
9499
assert(symbol.value.get(ID_statement)==ID_block);
95100

96-
symbol.value.copy_to_operands(dtor(msymb));
101+
if(
102+
!symbol.value.has_operands() || !symbol.value.op0().has_operands() ||
103+
symbol.value.op0().op0().id() != ID_already_typechecked)
104+
{
105+
symbol.value.copy_to_operands(dtor(msymb));
106+
}
97107
}
98108

99109
// enter appropriate scope

0 commit comments

Comments
 (0)