Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split the entry-point-generation phase into two parts #1394

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions regression/goto-cc-cbmc/mixed-c-library-goto-main/lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

int getone() {
return 1;
}
12 changes: 12 additions & 0 deletions regression/goto-cc-cbmc/mixed-c-library-goto-main/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

extern int getone();

#include <assert.h>

int main(int argc, char** argv) {
assert(getone()==1);
}

int altmain() {
assert(getone()==0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
lib.c --function altmain
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
lib.c
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
4 changes: 4 additions & 0 deletions regression/goto-cc-cbmc/mixed-goto-library-c-main/lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

int getone() {
return 1;
}
12 changes: 12 additions & 0 deletions regression/goto-cc-cbmc/mixed-goto-library-c-main/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

extern int getone();

#include <assert.h>

int main(int argc, char** argv) {
assert(getone()==1);
}

int altmain() {
assert(getone()==0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
lib.c --function altmain
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
lib.c
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
32 changes: 11 additions & 21 deletions src/ansi-c/ansi_c_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@ void ansi_c_languaget::modules_provided(std::set<std::string> &modules)
modules.insert(get_base_name(parse_path, true));
}

/// Generate a _start function for a specific function
/// \param entry_function_symbol_id: The symbol for the function that should be
/// used as the entry point
/// \param symbol_table: The symbol table for the program. The new _start
/// function symbol will be added to this table
/// \return Returns false if the _start method was generated correctly
bool ansi_c_languaget::generate_start_function(
const irep_idt &entry_function_symbol_id,
symbol_tablet &symbol_table)
{
return generate_ansi_c_start_function(
symbol_table.symbols.at(entry_function_symbol_id),
symbol_table,
*message_handler);
}

/// ANSI-C preprocessing
bool ansi_c_languaget::preprocess(
std::istream &instream,
Expand Down Expand Up @@ -140,13 +124,19 @@ bool ansi_c_languaget::typecheck(
return false;
}

bool ansi_c_languaget::final(symbol_tablet &symbol_table)
bool ansi_c_languaget::generate_support_functions(
symbol_tablet &symbol_table)
{
// Note this can happen here because C doesn't currently
// support lazy loading at the symbol-table level, and therefore
// function bodies have already been populated and external stub
// symbols created during the typecheck() phase. If it gains lazy
// loading support then stubs will need to be created during
// function body parsing, or else generate-stubs moved to the
// final phase.
generate_opaque_method_stubs(symbol_table);
if(ansi_c_entry_point(symbol_table, get_message_handler()))
return true;

return false;
// This creates __CPROVER_start and __CPROVER_initialize:
return ansi_c_entry_point(symbol_table, get_message_handler());
}

void ansi_c_languaget::show_parse(std::ostream &out)
Expand Down
10 changes: 3 additions & 7 deletions src/ansi-c/ansi_c_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class ansi_c_languaget:public languaget
std::istream &instream,
const std::string &path) override;

bool generate_support_functions(
symbol_tablet &symbol_table) override;

bool typecheck(
symbol_tablet &symbol_table,
const std::string &module) override;

bool final(
symbol_tablet &symbol_table) override;

void show_parse(std::ostream &out) override;

~ansi_c_languaget() override;
Expand Down Expand Up @@ -73,10 +73,6 @@ class ansi_c_languaget:public languaget

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

virtual bool generate_start_function(
const irep_idt &entry_function_symbol_id,
class symbol_tablet &symbol_table) override;

protected:
ansi_c_parse_treet parse_tree;
std::string parse_path;
Expand Down
16 changes: 0 additions & 16 deletions src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Author: Daniel Kroening, [email protected]
#include <goto-programs/show_properties.h>
#include <goto-programs/string_abstraction.h>
#include <goto-programs/string_instrumentation.h>
#include <goto-programs/rebuild_goto_start_function.h>

#include <goto-symex/rewrite_union.h>
#include <goto-symex/adjust_float_expressions.h>
Expand Down Expand Up @@ -630,21 +629,6 @@ int cbmc_parse_optionst::get_goto_program(
// are already compiled
return 6;

if(cmdline.isset("function"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed? What replaces this functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a duplicate of functionality already in initialize_goto_model -- it was previously overwriting the start function twice.

{
const std::string &function_id=cmdline.get_value("function");
rebuild_goto_start_functiont start_function_rebuilder(
get_message_handler(),
cmdline,
goto_model.symbol_table,
goto_model.goto_functions);

if(start_function_rebuilder(function_id))
{
return 6;
}
}

if(cmdline.isset("show-symbol-table"))
{
show_symbol_table(goto_model, ui_message_handler.get_ui());
Expand Down
2 changes: 1 addition & 1 deletion src/cbmc/cbmc_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Author: Daniel Kroening, [email protected]

#include <util/ui_message.h>
#include <util/parse_options.h>
#include <goto-programs/rebuild_goto_start_function.h>
#include <util/language.h>

#include <analyses/goto_check.h>

Expand Down
24 changes: 3 additions & 21 deletions src/cpp/cpp_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,6 @@ void cpp_languaget::modules_provided(std::set<std::string> &modules)
modules.insert(get_base_name(parse_path, true));
}

/// Generate a _start function for a specific function
/// \param entry_function_symbol_id: The symbol for the function that should be
/// used as the entry point
/// \param symbol_table: The symbol table for the program. The new _start
/// function symbol will be added to this table
/// \return Returns false if the _start method was generated correctly
bool cpp_languaget::generate_start_function(
const irep_idt &entry_function_symbol_id,
symbol_tablet &symbol_table)
{
return generate_ansi_c_start_function(
symbol_table.lookup(entry_function_symbol_id),
symbol_table,
*message_handler);
}

/// ANSI-C preprocessing
bool cpp_languaget::preprocess(
std::istream &instream,
Expand Down Expand Up @@ -150,12 +134,10 @@ bool cpp_languaget::typecheck(
return linking(symbol_table, new_symbol_table, get_message_handler());
}

bool cpp_languaget::final(symbol_tablet &symbol_table)
bool cpp_languaget::generate_support_functions(
symbol_tablet &symbol_table)
{
if(ansi_c_entry_point(symbol_table, get_message_handler()))
return true;

return false;
return ansi_c_entry_point(symbol_table, get_message_handler());
}

void cpp_languaget::show_parse(std::ostream &out)
Expand Down
10 changes: 3 additions & 7 deletions src/cpp/cpp_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class cpp_languaget:public languaget
std::istream &instream,
const std::string &path) override;

bool generate_support_functions(
symbol_tablet &symbol_table) override;

bool typecheck(
symbol_tablet &symbol_table,
const std::string &module) override;
Expand All @@ -43,9 +46,6 @@ class cpp_languaget:public languaget
const std::string &module,
class replace_symbolt &replace_symbol) const;

bool final(
symbol_tablet &symbol_table) override;

void show_parse(std::ostream &out) override;

// constructor, destructor
Expand Down Expand Up @@ -85,10 +85,6 @@ class cpp_languaget:public languaget

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

virtual bool generate_start_function(
const irep_idt &entry_function_symbol_id,
class symbol_tablet &symbol_table) override;

protected:
cpp_parse_treet cpp_parse_tree;
std::string parse_path;
Expand Down
2 changes: 1 addition & 1 deletion src/goto-analyzer/goto_analyzer_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Author: Daniel Kroening, [email protected]

#include <util/ui_message.h>
#include <util/parse_options.h>
#include <util/language.h>

#include <goto-programs/goto_model.h>
#include <goto-programs/show_goto_functions.h>
#include <goto-programs/rebuild_goto_start_function.h>

#include <analyses/goto_check.h>

Expand Down
62 changes: 40 additions & 22 deletions src/goto-programs/initialize_goto_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ bool initialize_goto_model(
sources.push_back(file);
}

language_filest language_files;
language_files.set_message_handler(message_handler);

if(!sources.empty())
{
language_filest language_files;

language_files.set_message_handler(message_handler);

for(const auto &filename : sources)
{
#ifdef _MSC_VER
Expand Down Expand Up @@ -114,19 +113,6 @@ bool initialize_goto_model(
msg.error() << "CONVERSION ERROR" << messaget::eom;
return true;
}

if(binaries.empty())
{
// Enable/disable stub generation for opaque methods
bool stubs_enabled=cmdline.isset("generate-opaque-stubs");
language_files.set_should_generate_opaque_method_stubs(stubs_enabled);

if(language_files.final(goto_model.symbol_table))
{
msg.error() << "CONVERSION ERROR" << messaget::eom;
return true;
}
}
}

for(const auto &file : binaries)
Expand All @@ -137,17 +123,49 @@ bool initialize_goto_model(
return true;
}

if(cmdline.isset("function"))
bool binaries_provided_start=
goto_model.symbol_table.has_symbol(goto_functionst::entry_point());

bool entry_point_generation_failed=false;

if(binaries_provided_start && cmdline.isset("function"))
{
const std::string &function_id=cmdline.get_value("function");
rebuild_goto_start_functiont start_function_rebuilder(
// Rebuild the entry-point, using the language annotation of the
// existing __CPROVER_start function:
rebuild_goto_start_functiont rebuild_existing_start(
msg.get_message_handler(),
cmdline,
goto_model.symbol_table,
goto_model.goto_functions);
entry_point_generation_failed=rebuild_existing_start();
}
else if(!binaries_provided_start)
{
// Unsure of the rationale for only generating stubs when there are no
// GOTO binaries in play; simply mirroring old code in language_uit here.
if(binaries.empty())
{
// Enable/disable stub generation for opaque methods
bool stubs_enabled=cmdline.isset("generate-opaque-stubs");
language_files.set_should_generate_opaque_method_stubs(stubs_enabled);
}

if(start_function_rebuilder(function_id))
return true;
// Allow all language front-ends to try to provide the user-specified
// (--function) entry-point, or some language-specific default:
entry_point_generation_failed=
language_files.generate_support_functions(goto_model.symbol_table);
}

if(entry_point_generation_failed)
{
msg.error() << "SUPPORT FUNCTION GENERATION ERROR" << messaget::eom;
return true;
}

if(language_files.final(goto_model.symbol_table))
{
msg.error() << "FINAL STAGE CONVERSION ERROR" << messaget::eom;
return true;
}

msg.status() << "Generating GOTO Program" << messaget::eom;
Expand Down
5 changes: 2 additions & 3 deletions src/goto-programs/rebuild_goto_start_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ rebuild_goto_start_functiont::rebuild_goto_start_functiont(
/// called from _start
/// \return Returns true if either the symbol is not found, or something went
/// wrong with generating the start_function. False otherwise.
bool rebuild_goto_start_functiont::operator()(
const irep_idt &entry_function)
bool rebuild_goto_start_functiont::operator()()
{
const irep_idt &mode=get_entry_point_mode();

Expand All @@ -59,7 +58,7 @@ bool rebuild_goto_start_functiont::operator()(
remove_existing_entry_point();

bool return_code=
language->generate_start_function(entry_function, symbol_table);
language->generate_support_functions(symbol_table);

// Remove the function from the goto_functions so it is copied back in
// from the symbol table during goto_convert
Expand Down
2 changes: 1 addition & 1 deletion src/goto-programs/rebuild_goto_start_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class rebuild_goto_start_functiont: public messaget
symbol_tablet &symbol_table,
goto_functionst &goto_functions);

bool operator()(const irep_idt &entry_function);
bool operator()();

private:
irep_idt get_entry_point_mode() const;
Expand Down
Loading