Skip to content

Commit cb62568

Browse files
authored
Merge pull request #7771 from diffblue/goto-language-feature-tests
add a 'language feature' detection facility for goto programs
2 parents 4e4707c + 4408b1f commit cb62568

10 files changed

+102
-0
lines changed

jbmc/src/jbmc/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ generic_includes(jbmc-lib)
99

1010
target_link_libraries(jbmc-lib
1111
ansi-c
12+
assembler
1213
big-int
1314
cbmc-lib
1415
goto-checker

jbmc/src/jbmc/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SRC = jbmc_main.cpp \
44

55
OBJ += ../$(CPROVER_DIR)/src/ansi-c/ansi-c$(LIBEXT) \
66
../java_bytecode/java_bytecode$(LIBEXT) \
7+
../$(CPROVER_DIR)/src/assembler/assembler$(LIBEXT) \
78
../$(CPROVER_DIR)/src/linking/linking$(LIBEXT) \
89
../$(CPROVER_DIR)/src/big-int/big-int$(LIBEXT) \
910
../$(CPROVER_DIR)/src/goto-checker/goto-checker$(LIBEXT) \

src/assembler/remove_asm.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,22 @@ void remove_asm(goto_modelt &goto_model)
565565
{
566566
remove_asm(goto_model.goto_functions, goto_model.symbol_table);
567567
}
568+
569+
bool has_asm(const goto_functionst &goto_functions)
570+
{
571+
for(auto &function_it : goto_functions.function_map)
572+
for(auto &instruction : function_it.second.body.instructions)
573+
if(
574+
instruction.is_other() &&
575+
instruction.get_other().get_statement() == ID_asm)
576+
{
577+
return true;
578+
}
579+
580+
return false;
581+
}
582+
583+
bool has_asm(const goto_modelt &goto_model)
584+
{
585+
return has_asm(goto_model.goto_functions);
586+
}

src/assembler/remove_asm.h

+6
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,10 @@ void remove_asm(goto_functionst &, symbol_tablet &);
6060

6161
void remove_asm(goto_modelt &);
6262

63+
/// returns true iff the given goto functions use asm instructions
64+
bool has_asm(const goto_functionst &);
65+
66+
/// returns true iff the given goto model uses asm instructions
67+
bool has_asm(const goto_modelt &);
68+
6369
#endif // CPROVER_ASSEMBLER_REMOVE_ASM_H

src/goto-checker/module_dependencies.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
assembler
12
cbmc # symex_bmc will be moved next
23
goto-checker
34
goto-instrument

src/goto-checker/multi_path_symex_checker.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Author: Daniel Kroening, Peter Schrammel
1313

1414
#include <util/ui_message.h>
1515

16+
#include <goto-programs/remove_function_pointers.h>
17+
#include <goto-programs/remove_vector.h>
18+
19+
#include <assembler/remove_asm.h>
1620
#include <goto-symex/solver_hardness.h>
1721

1822
#include "bmc_util.h"
@@ -27,6 +31,10 @@ multi_path_symex_checkert::multi_path_symex_checkert(
2731
equation_generated(false),
2832
property_decider(options, ui_message_handler, equation, ns)
2933
{
34+
// check for certain unsupported language features
35+
PRECONDITION(!has_asm(goto_model.get_goto_functions()));
36+
PRECONDITION(!has_function_pointers(goto_model.get_goto_functions()));
37+
PRECONDITION(!has_vector(goto_model.get_goto_functions()));
3038
}
3139

3240
incremental_goto_checkert::resultt multi_path_symex_checkert::

src/goto-programs/remove_function_pointers.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,30 @@ void remove_function_pointers(
534534

535535
rfp(goto_model.goto_functions);
536536
}
537+
538+
bool has_function_pointers(const goto_programt &goto_program)
539+
{
540+
for(auto &instruction : goto_program.instructions)
541+
if(
542+
instruction.is_function_call() &&
543+
instruction.call_function().id() == ID_dereference)
544+
{
545+
return true;
546+
}
547+
548+
return false;
549+
}
550+
551+
bool has_function_pointers(const goto_functionst &goto_functions)
552+
{
553+
for(auto &function_it : goto_functions.function_map)
554+
if(has_function_pointers(function_it.second.body))
555+
return true;
556+
557+
return false;
558+
}
559+
560+
bool has_function_pointers(const goto_modelt &goto_model)
561+
{
562+
return has_function_pointers(goto_model.goto_functions);
563+
}

src/goto-programs/remove_function_pointers.h

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Date: June 2003
1818

1919
#include <unordered_set>
2020

21+
class goto_functionst;
2122
class goto_modelt;
2223
class message_handlert;
2324
class symbol_tablet;
@@ -54,4 +55,12 @@ bool function_is_type_compatible(
5455
const code_typet &function_type,
5556
const namespacet &ns);
5657

58+
/// returns true iff any of the given goto functions has function calls via
59+
/// a function pointer
60+
bool has_function_pointers(const goto_functionst &);
61+
62+
/// returns true iff the given goto model has function calls via
63+
/// a function pointer
64+
bool has_function_pointers(const goto_modelt &);
65+
5766
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_FUNCTION_POINTERS_H

src/goto-programs/remove_vector.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,25 @@ void remove_vector(goto_modelt &goto_model)
386386
{
387387
remove_vector(goto_model.symbol_table, goto_model.goto_functions);
388388
}
389+
390+
bool has_vector(const goto_functionst &goto_functions)
391+
{
392+
for(auto &function_it : goto_functions.function_map)
393+
for(auto &instruction : function_it.second.body.instructions)
394+
{
395+
bool has_vector = false;
396+
instruction.apply([&has_vector](const exprt &expr) {
397+
if(have_to_remove_vector(expr))
398+
has_vector = true;
399+
});
400+
if(has_vector)
401+
return true;
402+
}
403+
404+
return false;
405+
}
406+
407+
bool has_vector(const goto_modelt &goto_model)
408+
{
409+
return has_vector(goto_model.goto_functions);
410+
}

src/goto-programs/remove_vector.h

+8
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ void remove_vector(symbol_table_baset &, goto_functionst &);
2222

2323
void remove_vector(goto_modelt &);
2424

25+
/// returns true iff any of the given goto functions has instructions that use
26+
/// the vector type
27+
bool has_vector(const goto_functionst &);
28+
29+
/// returns true iff the given goto model has instructions that use
30+
/// the vector type
31+
bool has_vector(const goto_modelt &);
32+
2533
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_VECTOR_H

0 commit comments

Comments
 (0)