Skip to content

Commit 914928c

Browse files
Use mode of entry function to generate __CPROVER__start
Previously, when we compiled for instance a C file with no `main()` with goto-cc it would have no __CPROVER__start. CBMC would use the following logic to determine the entry point: 1. If `--function` is not passed, use existing `__CPROVER__start` -- in our case, we don't have an existing `__CPROVER__start`, so this doesn't work for us 2. If `--function` _is_ passed, and a `__CPROVER__start` exists: Generate a new entry point calling the passed entry function, based on the mode of the existing `__CPROVER__start` (I am not sure why this mode rather than the mode of `--function`) 3. Otherwise, iterate over the non-binary input files, determine the language to use based on The file extension for each source file, and try to generate an appropriate `__CPROVER__start` based on that The situation of having a single goto-binary with no `__CPROVER__start` as the input file doesn't fit any of these cases, so regardless of whether `--function` is passed CBMC is going to fail, complaining that it can't find or generate an entry point. This adds a fourth case to the list: 4. If `--function` is passed and there is no `__CPROVER__start`, select the language based on the mode of the function parameter and use it to generate `__CPROVER__start` This commit doesn't add tests for this change, but #4014 adds tests that, in the absence of this change, require hack-y workarounds (such as passing an empty file with a `.c` extension to force C mode for case 3 in the list above) to work.
1 parent 6f692d7 commit 914928c

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

src/goto-programs/initialize_goto_model.cpp

+40-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@ Author: Daniel Kroening, [email protected]
2929
#include "goto_convert_functions.h"
3030
#include "read_goto_binary.h"
3131

32+
/// Generate an entry point that calls a function with the given name, based on
33+
/// the functions language mode in the symbol table
34+
static bool generate_entry_point_for_function(
35+
const irep_idt &entry_function_name,
36+
const optionst &options,
37+
goto_modelt &goto_model,
38+
message_handlert &message_handler)
39+
{
40+
auto const entry_function_sym =
41+
goto_model.symbol_table.lookup(entry_function_name);
42+
if(entry_function_sym == nullptr)
43+
{
44+
throw invalid_command_line_argument_exceptiont{
45+
// NOLINTNEXTLINE(whitespace/braces)
46+
std::string{"couldn't find function with name `"} +
47+
id2string(entry_function_name) + "' in symbol table",
48+
"--function"};
49+
}
50+
PRECONDITION(!entry_function_sym->mode.empty());
51+
auto const entry_language = get_language_from_mode(entry_function_sym->mode);
52+
CHECK_RETURN(entry_language != nullptr);
53+
entry_language->set_message_handler(message_handler);
54+
entry_language->set_language_options(options);
55+
return entry_language->generate_support_functions(goto_model.symbol_table);
56+
}
57+
3258
goto_modelt initialize_goto_model(
3359
const std::vector<std::string> &files,
3460
message_handlert &message_handler,
@@ -133,10 +159,20 @@ goto_modelt initialize_goto_model(
133159
}
134160
else if(!binaries_provided_start)
135161
{
136-
// Allow all language front-ends to try to provide the user-specified
137-
// (--function) entry-point, or some language-specific default:
138-
entry_point_generation_failed=
139-
language_files.generate_support_functions(goto_model.symbol_table);
162+
if(options.is_set("function"))
163+
{
164+
// no entry point is present; Use the mode of the specified entry function
165+
// to generate one
166+
entry_point_generation_failed = generate_entry_point_for_function(
167+
options.get_option("function"), options, goto_model, message_handler);
168+
}
169+
if(entry_point_generation_failed || !options.is_set("function"))
170+
{
171+
// Allow all language front-ends to try to provide the user-specified
172+
// (--function) entry-point, or some language-specific default:
173+
entry_point_generation_failed =
174+
language_files.generate_support_functions(goto_model.symbol_table);
175+
}
140176
}
141177

142178
if(entry_point_generation_failed)

0 commit comments

Comments
 (0)