Skip to content

Commit e71e647

Browse files
committed
Use the linker when adding library functions
This enables type checking of missing functions vs library-provided functions, and also enables type sanitisation as done by the linker.
1 parent 9d1d943 commit e71e647

7 files changed

+20
-11
lines changed

src/ansi-c/cprover_library.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ std::string get_cprover_library_text(
7676

7777
void cprover_c_library_factory(
7878
const std::set<irep_idt> &functions,
79-
symbol_tablet &symbol_table,
79+
const symbol_tablet &symbol_table,
80+
symbol_tablet &dest_symbol_table,
8081
message_handlert &message_handler)
8182
{
8283
if(config.ansi_c.lib==configt::ansi_ct::libt::LIB_NONE)
@@ -86,7 +87,7 @@ void cprover_c_library_factory(
8687

8788
library_text=get_cprover_library_text(functions, symbol_table);
8889

89-
add_library(library_text, symbol_table, message_handler);
90+
add_library(library_text, dest_symbol_table, message_handler);
9091
}
9192

9293
void add_library(

src/ansi-c/cprover_library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void add_library(
3434

3535
void cprover_c_library_factory(
3636
const std::set<irep_idt> &functions,
37+
const symbol_tablet &,
3738
symbol_tablet &,
3839
message_handlert &);
3940

src/cpp/cprover_library.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ static std::string get_cprover_library_text(
3737

3838
void cprover_cpp_library_factory(
3939
const std::set<irep_idt> &functions,
40-
symbol_tablet &symbol_table,
40+
const symbol_tablet &symbol_table,
41+
symbol_tablet &dest_symbol_table,
4142
message_handlert &message_handler)
4243
{
4344
if(config.ansi_c.lib == configt::ansi_ct::libt::LIB_NONE)
@@ -46,5 +47,5 @@ void cprover_cpp_library_factory(
4647
const std::string library_text =
4748
get_cprover_library_text(functions, symbol_table);
4849

49-
add_library(library_text, symbol_table, message_handler);
50+
add_library(library_text, dest_symbol_table, message_handler);
5051
}

src/cpp/cprover_library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class symbol_tablet;
1818

1919
void cprover_cpp_library_factory(
2020
const std::set<irep_idt> &functions,
21+
const symbol_tablet &,
2122
symbol_tablet &,
2223
message_handlert &);
2324

src/goto-programs/link_goto_model.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static bool link_functions(
9797

9898
in_dest_symbol_table.body.swap(src_func.body);
9999
in_dest_symbol_table.type=src_func.type;
100+
in_dest_symbol_table.parameter_identifiers = src_func.parameter_identifiers;
100101
}
101102
else if(src_func.body.instructions.empty() ||
102103
src_ns.lookup(src_it->first).is_weak)

src/goto-programs/link_to_library.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include "compute_called_functions.h"
1515
#include "goto_convert_functions.h"
16+
#include "link_goto_model.h"
1617

1718
/// Complete missing function definitions using the \p library.
1819
/// \param goto_model: goto model that may contain function calls and symbols
@@ -25,7 +26,7 @@ void link_to_library(
2526
goto_modelt &goto_model,
2627
message_handlert &message_handler,
2728
const std::function<
28-
void(const std::set<irep_idt> &, symbol_tablet &, message_handlert &)>
29+
void(const std::set<irep_idt> &, const symbol_tablet &, symbol_tablet &, message_handlert &)>
2930
&library)
3031
{
3132
// this needs a fixedpoint, as library functions
@@ -65,23 +66,26 @@ void link_to_library(
6566
if(missing_functions.empty())
6667
break;
6768

68-
library(missing_functions, goto_model.symbol_table, message_handler);
69+
goto_modelt library_model;
70+
library(missing_functions, goto_model.symbol_table, library_model.symbol_table, message_handler);
6971

7072
// convert to CFG
7173
for(const auto &id : missing_functions)
7274
{
7375
if(
74-
goto_model.symbol_table.symbols.find(id) !=
75-
goto_model.symbol_table.symbols.end())
76+
library_model.symbol_table.symbols.find(id) !=
77+
library_model.symbol_table.symbols.end())
7678
{
7779
goto_convert(
7880
id,
79-
goto_model.symbol_table,
80-
goto_model.goto_functions,
81+
library_model.symbol_table,
82+
library_model.goto_functions,
8183
message_handler);
8284
}
8385

8486
added_functions.insert(id);
8587
}
88+
89+
link_goto_model(goto_model, library_model, message_handler);
8690
}
8791
}

src/goto-programs/link_to_library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ void link_to_library(
2727
goto_modelt &,
2828
message_handlert &,
2929
const std::function<
30-
void(const std::set<irep_idt> &, symbol_tablet &, message_handlert &)> &);
30+
void(const std::set<irep_idt> &, const symbol_tablet &, symbol_tablet &, message_handlert &)> &);
3131

3232
#endif // CPROVER_GOTO_PROGRAMS_LINK_TO_LIBRARY_H

0 commit comments

Comments
 (0)