Skip to content

add a 'language feature' detection facility for goto programs #7771

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

Merged
merged 1 commit into from
Nov 2, 2023
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
1 change: 1 addition & 0 deletions jbmc/src/jbmc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ generic_includes(jbmc-lib)

target_link_libraries(jbmc-lib
ansi-c
assembler
big-int
cbmc-lib
goto-checker
Expand Down
1 change: 1 addition & 0 deletions jbmc/src/jbmc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SRC = jbmc_main.cpp \

OBJ += ../$(CPROVER_DIR)/src/ansi-c/ansi-c$(LIBEXT) \
../java_bytecode/java_bytecode$(LIBEXT) \
../$(CPROVER_DIR)/src/assembler/assembler$(LIBEXT) \
../$(CPROVER_DIR)/src/linking/linking$(LIBEXT) \
../$(CPROVER_DIR)/src/big-int/big-int$(LIBEXT) \
../$(CPROVER_DIR)/src/goto-checker/goto-checker$(LIBEXT) \
Expand Down
19 changes: 19 additions & 0 deletions src/assembler/remove_asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,22 @@ void remove_asm(goto_modelt &goto_model)
{
remove_asm(goto_model.goto_functions, goto_model.symbol_table);
}

bool has_asm(const goto_functionst &goto_functions)
{
for(auto &function_it : goto_functions.function_map)
for(auto &instruction : function_it.second.body.instructions)
if(
instruction.is_other() &&
instruction.get_other().get_statement() == ID_asm)
{
return true;
}

return false;
}

bool has_asm(const goto_modelt &goto_model)
{
return has_asm(goto_model.goto_functions);
}
6 changes: 6 additions & 0 deletions src/assembler/remove_asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@ void remove_asm(goto_functionst &, symbol_tablet &);

void remove_asm(goto_modelt &);

/// returns true iff the given goto functions use asm instructions
bool has_asm(const goto_functionst &);

/// returns true iff the given goto model uses asm instructions
bool has_asm(const goto_modelt &);

#endif // CPROVER_ASSEMBLER_REMOVE_ASM_H
1 change: 1 addition & 0 deletions src/goto-checker/module_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
assembler
cbmc # symex_bmc will be moved next
goto-checker
goto-instrument
Expand Down
8 changes: 8 additions & 0 deletions src/goto-checker/multi_path_symex_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Author: Daniel Kroening, Peter Schrammel

#include <util/ui_message.h>

#include <goto-programs/remove_function_pointers.h>
#include <goto-programs/remove_vector.h>

#include <assembler/remove_asm.h>
#include <goto-symex/solver_hardness.h>

#include "bmc_util.h"
Expand All @@ -27,6 +31,10 @@ multi_path_symex_checkert::multi_path_symex_checkert(
equation_generated(false),
property_decider(options, ui_message_handler, equation, ns)
{
// check for certain unsupported language features
PRECONDITION(!has_asm(goto_model.get_goto_functions()));
PRECONDITION(!has_function_pointers(goto_model.get_goto_functions()));
PRECONDITION(!has_vector(goto_model.get_goto_functions()));
}

incremental_goto_checkert::resultt multi_path_symex_checkert::
Expand Down
27 changes: 27 additions & 0 deletions src/goto-programs/remove_function_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,30 @@ void remove_function_pointers(

rfp(goto_model.goto_functions);
}

bool has_function_pointers(const goto_programt &goto_program)
{
for(auto &instruction : goto_program.instructions)
if(
instruction.is_function_call() &&
instruction.call_function().id() == ID_dereference)
{
return true;
}

return false;
}

bool has_function_pointers(const goto_functionst &goto_functions)
{
for(auto &function_it : goto_functions.function_map)
if(has_function_pointers(function_it.second.body))
return true;

return false;
}

bool has_function_pointers(const goto_modelt &goto_model)
{
return has_function_pointers(goto_model.goto_functions);
}
9 changes: 9 additions & 0 deletions src/goto-programs/remove_function_pointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Date: June 2003

#include <unordered_set>

class goto_functionst;
class goto_modelt;
class message_handlert;
class symbol_tablet;
Expand Down Expand Up @@ -54,4 +55,12 @@ bool function_is_type_compatible(
const code_typet &function_type,
const namespacet &ns);

/// returns true iff any of the given goto functions has function calls via
/// a function pointer
bool has_function_pointers(const goto_functionst &);

/// returns true iff the given goto model has function calls via
/// a function pointer
bool has_function_pointers(const goto_modelt &);

#endif // CPROVER_GOTO_PROGRAMS_REMOVE_FUNCTION_POINTERS_H
22 changes: 22 additions & 0 deletions src/goto-programs/remove_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,25 @@ void remove_vector(goto_modelt &goto_model)
{
remove_vector(goto_model.symbol_table, goto_model.goto_functions);
}

bool has_vector(const goto_functionst &goto_functions)
{
for(auto &function_it : goto_functions.function_map)
for(auto &instruction : function_it.second.body.instructions)
{
bool has_vector = false;
instruction.apply([&has_vector](const exprt &expr) {
if(have_to_remove_vector(expr))
has_vector = true;
});
if(has_vector)
return true;
}

return false;
}

bool has_vector(const goto_modelt &goto_model)
{
return has_vector(goto_model.goto_functions);
}
8 changes: 8 additions & 0 deletions src/goto-programs/remove_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ void remove_vector(symbol_table_baset &, goto_functionst &);

void remove_vector(goto_modelt &);

/// returns true iff any of the given goto functions has instructions that use
/// the vector type
bool has_vector(const goto_functionst &);

/// returns true iff the given goto model has instructions that use
/// the vector type
bool has_vector(const goto_modelt &);

#endif // CPROVER_GOTO_PROGRAMS_REMOVE_VECTOR_H