Skip to content

Commit 798f651

Browse files
authored
Merge pull request #4703 from hannes-steffenhagen-diffblue/feature/goto-analyzer-usability
Preparation to make goto-analyzer work with the goto_verifiert framework
2 parents f175f75 + 0f4a362 commit 798f651

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

src/analyses/ai.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ class ai_baset
6868
}
6969

7070
/// Run abstract interpretation on a whole program
71-
void operator()(const goto_modelt &goto_model)
71+
void operator()(const abstract_goto_modelt &goto_model)
7272
{
73-
const namespacet ns(goto_model.symbol_table);
74-
initialize(goto_model.goto_functions);
75-
entry_state(goto_model.goto_functions);
76-
fixedpoint(goto_model.goto_functions, ns);
73+
const namespacet ns(goto_model.get_symbol_table());
74+
initialize(goto_model.get_goto_functions());
75+
entry_state(goto_model.get_goto_functions());
76+
fixedpoint(goto_model.get_goto_functions(), ns);
7777
finalize();
7878
}
7979

@@ -374,7 +374,7 @@ class ai_baset
374374
/// \ref ai_baset#operator()(const irep_idt&,const goto_programt&, <!--
375375
/// --> const namespacet&),
376376
/// \ref ai_baset#operator()(const goto_functionst&,const namespacet&)
377-
/// and \ref ai_baset#operator()(const goto_modelt&)
377+
/// and \ref ai_baset#operator()(const abstract_goto_modelt&)
378378
/// 2. Accessing the results of an analysis, by looking up the result
379379
/// for a given location \p l using
380380
/// \ref ait#operator[](goto_programt::const_targett).

src/goto-analyzer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ target_link_libraries(goto-analyzer-lib
1212
cpp
1313
linking
1414
big-int
15+
goto-checker
1516
goto-programs
1617
analyses
1718
pointer-analysis

src/goto-analyzer/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
1313
../cpp/cpp$(LIBEXT) \
1414
../linking/linking$(LIBEXT) \
1515
../big-int/big-int$(LIBEXT) \
16+
../goto-checker/goto-checker$(LIBEXT) \
1617
../goto-programs/goto-programs$(LIBEXT) \
1718
../analyses/analyses$(LIBEXT) \
1819
../pointer-analysis/pointer-analysis$(LIBEXT) \

src/goto-analyzer/module_dependencies.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ analyses
33
assembler
44
cpp
55
goto-analyzer
6+
goto-checker
67
goto-programs
78
java_bytecode # will go away
89
langapi # should go away

src/goto-analyzer/static_verifier.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,49 @@ struct static_verifier_resultt
2727
irep_idt function_id;
2828
};
2929

30+
void static_verifier(
31+
const abstract_goto_modelt &abstract_goto_model,
32+
const ai_baset &ai,
33+
propertiest &properties)
34+
{
35+
const namespacet ns{abstract_goto_model.get_symbol_table()};
36+
// this is mutable because we want to change the property status
37+
// in this loop
38+
for(auto &property : properties)
39+
{
40+
auto &property_status = property.second.status;
41+
const goto_programt::const_targett &property_location = property.second.pc;
42+
exprt condition = property_location->get_condition();
43+
const std::unique_ptr<ai_baset::statet> predecessor_state_copy =
44+
ai.abstract_state_before(property_location);
45+
// simplify the condition given the domain information we have
46+
// about the state right before the assertion is evaluated
47+
predecessor_state_copy->ai_simplify(condition, ns);
48+
// if the condition simplifies to true the assertion always succeeds
49+
if(condition.is_true())
50+
{
51+
property_status = property_statust::PASS;
52+
}
53+
// if the condition simplifies to false the assertion always fails
54+
else if(condition.is_false())
55+
{
56+
property_status = property_statust::FAIL;
57+
}
58+
// if the domain state is bottom then the assertion is definitely
59+
// unreachable
60+
else if(predecessor_state_copy->is_bottom())
61+
{
62+
property_status = property_statust::NOT_REACHABLE;
63+
}
64+
// if the condition isn't definitely true, false or unreachable
65+
// we don't know whether or not it may fail
66+
else
67+
{
68+
property_status = property_statust::UNKNOWN;
69+
}
70+
}
71+
}
72+
3073
/// Makes a status message string from a status.
3174
static const char *message(const static_verifier_resultt::statust &status)
3275
{

src/goto-analyzer/static_verifier.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ Author: Martin Brain, [email protected]
99
#ifndef CPROVER_GOTO_ANALYZER_STATIC_VERIFIER_H
1010
#define CPROVER_GOTO_ANALYZER_STATIC_VERIFIER_H
1111

12+
#include <goto-checker/properties.h>
1213
#include <iosfwd>
1314

15+
class abstract_goto_modelt;
1416
class ai_baset;
1517
class goto_modelt;
1618
class message_handlert;
@@ -23,4 +25,15 @@ bool static_verifier(
2325
message_handlert &,
2426
std::ostream &);
2527

28+
/// Use the information from the abstract interpreter to fill out the statuses
29+
/// of the passed properties
30+
/// \param abstract_goto_model The goto program to verify
31+
/// \param ai The abstract interpreter (should be run to fixpoint
32+
/// before calling this function)
33+
/// \param properties The properties to fill out
34+
void static_verifier(
35+
const abstract_goto_modelt &abstract_goto_model,
36+
const ai_baset &ai,
37+
propertiest &properties);
38+
2639
#endif // CPROVER_GOTO_ANALYZER_STATIC_VERIFIER_H

0 commit comments

Comments
 (0)