Skip to content

Commit 6be5fd5

Browse files
authored
Merge pull request diffblue#1394 from smowton/smowton/feature/split_frontend_final_stage
Split the entry-point-generation phase into two parts
2 parents 6888dd2 + 901d745 commit 6be5fd5

26 files changed

+238
-221
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
int getone() {
3+
return 1;
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
extern int getone();
3+
4+
#include <assert.h>
5+
6+
int main(int argc, char** argv) {
7+
assert(getone()==1);
8+
}
9+
10+
int altmain() {
11+
assert(getone()==0);
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
lib.c --function altmain
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
lib.c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
int getone() {
3+
return 1;
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
extern int getone();
3+
4+
#include <assert.h>
5+
6+
int main(int argc, char** argv) {
7+
assert(getone()==1);
8+
}
9+
10+
int altmain() {
11+
assert(getone()==0);
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
lib.c --function altmain
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
lib.c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/ansi-c/ansi_c_language.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,6 @@ void ansi_c_languaget::modules_provided(std::set<std::string> &modules)
3636
modules.insert(get_base_name(parse_path, true));
3737
}
3838

39-
/// Generate a _start function for a specific function
40-
/// \param entry_function_symbol_id: The symbol for the function that should be
41-
/// used as the entry point
42-
/// \param symbol_table: The symbol table for the program. The new _start
43-
/// function symbol will be added to this table
44-
/// \return Returns false if the _start method was generated correctly
45-
bool ansi_c_languaget::generate_start_function(
46-
const irep_idt &entry_function_symbol_id,
47-
symbol_tablet &symbol_table)
48-
{
49-
return generate_ansi_c_start_function(
50-
symbol_table.symbols.at(entry_function_symbol_id),
51-
symbol_table,
52-
*message_handler);
53-
}
54-
5539
/// ANSI-C preprocessing
5640
bool ansi_c_languaget::preprocess(
5741
std::istream &instream,
@@ -140,13 +124,19 @@ bool ansi_c_languaget::typecheck(
140124
return false;
141125
}
142126

143-
bool ansi_c_languaget::final(symbol_tablet &symbol_table)
127+
bool ansi_c_languaget::generate_support_functions(
128+
symbol_tablet &symbol_table)
144129
{
130+
// Note this can happen here because C doesn't currently
131+
// support lazy loading at the symbol-table level, and therefore
132+
// function bodies have already been populated and external stub
133+
// symbols created during the typecheck() phase. If it gains lazy
134+
// loading support then stubs will need to be created during
135+
// function body parsing, or else generate-stubs moved to the
136+
// final phase.
145137
generate_opaque_method_stubs(symbol_table);
146-
if(ansi_c_entry_point(symbol_table, get_message_handler()))
147-
return true;
148-
149-
return false;
138+
// This creates __CPROVER_start and __CPROVER_initialize:
139+
return ansi_c_entry_point(symbol_table, get_message_handler());
150140
}
151141

152142
void ansi_c_languaget::show_parse(std::ostream &out)

src/ansi-c/ansi_c_language.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ class ansi_c_languaget:public languaget
3131
std::istream &instream,
3232
const std::string &path) override;
3333

34+
bool generate_support_functions(
35+
symbol_tablet &symbol_table) override;
36+
3437
bool typecheck(
3538
symbol_tablet &symbol_table,
3639
const std::string &module) override;
3740

38-
bool final(
39-
symbol_tablet &symbol_table) override;
40-
4141
void show_parse(std::ostream &out) override;
4242

4343
~ansi_c_languaget() override;
@@ -73,10 +73,6 @@ class ansi_c_languaget:public languaget
7373

7474
void modules_provided(std::set<std::string> &modules) override;
7575

76-
virtual bool generate_start_function(
77-
const irep_idt &entry_function_symbol_id,
78-
class symbol_tablet &symbol_table) override;
79-
8076
protected:
8177
ansi_c_parse_treet parse_tree;
8278
std::string parse_path;

0 commit comments

Comments
 (0)