Skip to content

Commit 460032c

Browse files
authored
Merge pull request #6482 from martin-cs/refactor/remove-static-analysis
Port the last user of static_analysist
2 parents 92581d1 + 168901f commit 460032c

26 files changed

+268
-1198
lines changed

jbmc/unit/pointer-analysis/custom_value_set_analysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ SCENARIO("test_value_set_analysis",
198198
std::prev(test_function.instructions.end());
199199

200200
value_set_analysist normal_analysis(ns);
201-
normal_analysis(goto_model.goto_functions);
201+
normal_analysis(TEST_FUNCTION_NAME, test_function, ns);
202202
const auto &normal_function_end_vs=
203203
normal_analysis[test_function_end].value_set;
204204

205205
test_value_set_analysist test_analysis(ns);
206-
test_analysis(goto_model.goto_functions);
206+
test_analysis(TEST_FUNCTION_NAME, test_function, ns);
207207
const auto &test_function_end_vs=
208208
test_analysis[test_function_end].value_set;
209209

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdlib.h>
2+
3+
#define BIG 4096
4+
5+
int main()
6+
{
7+
// Uninitialized pointer
8+
int *u;
9+
10+
// Basic assignment
11+
u = NULL;
12+
int a;
13+
u = &a;
14+
15+
// Test merging and the loss of correlation
16+
int *p;
17+
int *q;
18+
int b;
19+
int c;
20+
int nondet;
21+
if(nondet)
22+
{
23+
p = &b;
24+
q = &c;
25+
}
26+
else
27+
{
28+
p = &c;
29+
q = &b;
30+
}
31+
32+
// Test widening
33+
int array[BIG];
34+
int *s = &(array[0]);
35+
for(int i = 0; i < BIG; ++i)
36+
{
37+
s = &array[i];
38+
}
39+
40+
return 0;
41+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CORE
2+
main.c
3+
--show-value-sets
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
main::1::u = \{ <main::1::u\$object, 0, signedbv\[32\]> \}
7+
main::1::u = \{ <NULL-object, 0, signedbv\[32\]> \}
8+
main::1::u = \{ <main::1::a, 0, signedbv\[32\]> \}
9+
main::1::p = \{ <main::1::b, 0, signedbv\[32\]> \}
10+
main::1::p = \{ <main::1::c, 0, signedbv\[32\]> \}
11+
main::1::q = \{ <main::1::b, 0, signedbv\[32\]>, <main::1::c, 0, signedbv\[32\]> \}
12+
main::1::p = \{ <main::1::b, 0, signedbv\[32\]>, <main::1::c, 0, signedbv\[32\]> \}
13+
main::1::s = \{ <main::1::array\[0\], \*, signedbv\[32\]> \}
14+
--
15+
--
16+
A few basic tests to check if value sets are being handled correctly.
17+
18+
It would be reasonable to ask about the checks for:
19+
20+
main::1::q = \{ <main::1::b, 0, signedbv\[32\]> \}
21+
main::1::q = \{ <main::1::c, 0, signedbv\[32\]> \}
22+
23+
but as domains are stored at the start of instructions the following merge will
24+
over-write it on one branch or the other. To keep the test portable it is best
25+
avoided.
26+
27+

src/analyses/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ SRC = ai.cpp \
2929
locals.cpp \
3030
reaching_definitions.cpp \
3131
sese_regions.cpp \
32-
static_analysis.cpp \
3332
uncaught_exceptions_analysis.cpp \
3433
uninitialized_domain.cpp \
3534
variable-sensitivity/abstract_environment.cpp \

src/analyses/README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ static analyses that instantiate them.
88

99
\section analyses-frameworks Frameworks:
1010

11-
There are currently three abstract interpretation frameworks provided in this
12-
directory. \ref analyses-ait, \ref analyses-flow-insensitive-analysis, and the
13-
deprecated and obsolete \ref analyses-static-analysist.
11+
There are currently two abstract interpretation frameworks provided in this
12+
directory. \ref analyses-ait and \ref analyses-flow-insensitive-analysis.
1413

1514
\subsection analyses-ait Abstract interpreter framework (ait)
1615

@@ -22,14 +21,6 @@ is provided by \ref ait. This analysis framework is currently location sensitive
2221
run after the function pointer removal and return removal passes. There is
2322
ongoing work to make this framework also support context sensitivity.
2423

25-
\subsection analyses-static-analysist Old Abstract interpreter framework (static_analysist)
26-
27-
The obsolete static analysis framework \ref static_analysist is only used by
28-
\ref value_set_analysist. This abstract interpretation framework is deprecated in
29-
favour of \ref analyses-ait, and should not be used as the basis for new code.
30-
This framework is location sensitive (one domain per code location), but is able
31-
to be run before function pointer removal and return removal phases.
32-
3324
\subsection analyses-flow-insensitive-analysis Flow-insensitive analysis (flow_insensitive_analysist)
3425

3526
Framework for flow-insensitive analyses. Maintains a single global abstract

src/analyses/ai.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,28 @@ class ai_baset
280280
const goto_programt &goto_program,
281281
std::ostream &out) const;
282282

283+
/// Output the abstract states for a single function as JSON
284+
/// \param ns: The namespace
285+
/// \param goto_program: The goto program
286+
/// \param function_id: The identifier used to find a symbol to
287+
/// identify the source language
288+
/// \return The JSON object
289+
virtual jsont output_json(
290+
const namespacet &ns,
291+
const irep_idt &function_id,
292+
const goto_programt &goto_program) const;
293+
294+
/// Output the abstract states for a single function as XML
295+
/// \param ns: The namespace
296+
/// \param goto_program: The goto program
297+
/// \param function_id: The identifier used to find a symbol to
298+
/// identify the source language
299+
/// \return The XML object
300+
virtual xmlt output_xml(
301+
const namespacet &ns,
302+
const irep_idt &function_id,
303+
const goto_programt &goto_program) const;
304+
283305
/// Output the abstract states for a whole program
284306
virtual void output(
285307
const namespacet &ns,
@@ -389,28 +411,6 @@ class ai_baset
389411
/// entry state required by the analysis
390412
trace_ptrt entry_state(const goto_functionst &goto_functions);
391413

392-
/// Output the abstract states for a single function as JSON
393-
/// \param ns: The namespace
394-
/// \param goto_program: The goto program
395-
/// \param function_id: The identifier used to find a symbol to
396-
/// identify the source language
397-
/// \return The JSON object
398-
virtual jsont output_json(
399-
const namespacet &ns,
400-
const irep_idt &function_id,
401-
const goto_programt &goto_program) const;
402-
403-
/// Output the abstract states for a single function as XML
404-
/// \param ns: The namespace
405-
/// \param goto_program: The goto program
406-
/// \param function_id: The identifier used to find a symbol to
407-
/// identify the source language
408-
/// \return The XML object
409-
virtual xmlt output_xml(
410-
const namespacet &ns,
411-
const irep_idt &function_id,
412-
const goto_programt &goto_program) const;
413-
414414
/// The work queue, sorted using the history's ordering operator
415415
typedef trace_sett working_sett;
416416

src/analyses/ai_domain.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,16 @@ class ai_domain_baset
113113
/// no states
114114
virtual void make_bottom() = 0;
115115

116-
/// all states -- the analysis doesn't use this,
116+
/// all states -- the analysis doesn't use this directly (see make_entry)
117117
/// and domains may refuse to implement it.
118118
virtual void make_top() = 0;
119119

120120
/// Make this domain a reasonable entry-point state
121-
virtual void make_entry() = 0;
121+
/// For most domains top is sufficient
122+
virtual void make_entry()
123+
{
124+
make_top();
125+
}
122126

123127
virtual bool is_bottom() const = 0;
124128

@@ -231,4 +235,21 @@ class ai_domain_factory_default_constructort
231235
}
232236
};
233237

238+
template <typename domainT>
239+
class ai_domain_factory_location_constructort
240+
: public ai_domain_factoryt<domainT>
241+
{
242+
public:
243+
typedef ai_domain_factory_baset::statet statet;
244+
typedef ai_domain_factory_baset::locationt locationt;
245+
typedef ai_domain_factory_baset::trace_ptrt trace_ptrt;
246+
247+
std::unique_ptr<statet> make(locationt l) const override
248+
{
249+
auto d = util_make_unique<domainT>(l);
250+
CHECK_RETURN(d->is_bottom());
251+
return std::unique_ptr<statet>(d.release());
252+
}
253+
};
254+
234255
#endif

src/analyses/constant_propagator.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ class constant_propagator_domaint:public ai_domain_baset
6565
values.set_to_top();
6666
}
6767

68-
virtual void make_entry() final override
69-
{
70-
make_top();
71-
}
72-
7368
virtual bool is_bottom() const final override
7469
{
7570
return values.is_bot();

src/analyses/custom_bitvector_analysis.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ class custom_bitvector_domaint:public ai_domain_baset
5050
has_values=tvt(true);
5151
}
5252

53-
void make_entry() final override
54-
{
55-
make_top();
56-
}
57-
5853
bool is_bottom() const final override
5954
{
6055
DATA_INVARIANT(!has_values.is_false() ||

src/analyses/escape_analysis.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ class escape_domaint:public ai_domain_baset
7171
return has_values.is_true();
7272
}
7373

74-
void make_entry() override final
75-
{
76-
make_top();
77-
}
78-
7974
typedef union_find<irep_idt> aliasest;
8075
aliasest aliases;
8176

0 commit comments

Comments
 (0)