Skip to content

Commit 1587505

Browse files
committed
Fix an issue in is_threadedt where the is_threaded property was not propagated back to function call sites
1 parent 0e2f389 commit 1587505

File tree

5 files changed

+81
-29
lines changed

5 files changed

+81
-29
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
int x;
3+
4+
void func2()
5+
{
6+
x = 3;
7+
}
8+
9+
void func1()
10+
{
11+
x = 1;
12+
func2();
13+
x = 2;
14+
}
15+
16+
int main()
17+
{
18+
x = 4;
19+
__CPROVER_ASYNC_0:
20+
func1();
21+
x = 5;
22+
23+
return 0;
24+
}
25+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
--show-threaded
4+
activate-multi-line-match
5+
x = 2;\nIs threaded: True
6+
--
7+
^warning: ignoring

src/analyses/is_threaded.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,33 @@ class is_threaded_domaint:public ai_domain_baset
1515
{
1616
public:
1717
bool reachable;
18-
bool has_spawn;
1918
bool is_threaded;
2019

21-
inline is_threaded_domaint():
20+
is_threaded_domaint():
2221
reachable(false),
23-
has_spawn(false),
2422
is_threaded(false)
2523
{
2624
// this is bottom
2725
}
2826

29-
inline bool merge(
27+
bool merge(
3028
const is_threaded_domaint &src,
3129
locationt from,
3230
locationt to)
3331
{
32+
// assert(src.reachable);
33+
34+
if(!src.reachable)
35+
return false;
36+
3437
bool old_reachable=reachable;
35-
if(src.reachable)
36-
reachable=true;
37-
38-
bool old_h_s=has_spawn;
39-
if(src.has_spawn &&
40-
(from->is_end_function() ||
41-
from->function==to->function))
42-
has_spawn=true;
43-
44-
bool old_i_t=is_threaded;
45-
if(has_spawn ||
46-
(src.is_threaded &&
47-
!from->is_end_function()))
48-
is_threaded=true;
38+
bool old_is_threaded=is_threaded;
39+
40+
reachable=true;
41+
is_threaded|=src.is_threaded;
4942

5043
return old_reachable!=reachable ||
51-
old_i_t!=is_threaded ||
52-
old_h_s!=has_spawn;
44+
old_is_threaded!=is_threaded;
5345
}
5446

5547
void transform(
@@ -58,30 +50,31 @@ class is_threaded_domaint:public ai_domain_baset
5850
ai_baset &ai,
5951
const namespacet &ns) final
6052
{
53+
// assert(reachable);
54+
6155
if(!reachable)
6256
return;
63-
if(from->is_start_thread() ||
64-
to->is_end_thread())
65-
{
66-
has_spawn=true;
57+
58+
if(from->is_start_thread())
6759
is_threaded=true;
68-
}
6960
}
7061

7162
void make_bottom() final
7263
{
73-
reachable=has_spawn=is_threaded=false;
64+
reachable=false;
65+
is_threaded=false;
7466
}
7567

7668
void make_top() final
7769
{
78-
reachable=has_spawn=is_threaded=true;
70+
reachable=true;
71+
is_threaded=true;
7972
}
8073

8174
void make_entry() final
8275
{
8376
reachable=true;
84-
has_spawn=is_threaded=false;
77+
is_threaded=false;
8578
}
8679
};
8780

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Author: Daniel Kroening, [email protected]
5252
#include <analyses/reaching_definitions.h>
5353
#include <analyses/dependence_graph.h>
5454
#include <analyses/constant_propagator.h>
55+
#include <analyses/is_threaded.h>
5556

5657
#include <cbmc/version.h>
5758

@@ -246,6 +247,31 @@ int goto_instrument_parse_optionst::doit()
246247
}
247248
}
248249

250+
if(cmdline.isset("show-threaded"))
251+
{
252+
namespacet ns(symbol_table);
253+
254+
is_threadedt is_threaded(goto_functions);
255+
256+
forall_goto_functions(f_it, goto_functions)
257+
{
258+
std::cout << "////" << std::endl;
259+
std::cout << "//// Function: " << f_it->first << std::endl;
260+
std::cout << "////" << std::endl;
261+
std::cout << std::endl;
262+
263+
const goto_programt &goto_program=f_it->second.body;
264+
265+
forall_goto_program_instructions(i_it, goto_program)
266+
{
267+
goto_program.output_instruction(ns, "", std::cout, i_it);
268+
std::cout << "Is threaded: " << (is_threaded(i_it)?"True":"False")
269+
<< std::endl;
270+
std::cout << std::endl;
271+
}
272+
}
273+
}
274+
249275
if(cmdline.isset("show-value-sets"))
250276
{
251277
do_indirect_call_and_rtti_removal();

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ Author: Daniel Kroening, [email protected]
6767
"(interpreter)(show-reaching-definitions)(count-eloc)(list-eloc)" \
6868
"(list-symbols)(list-undefined-functions)" \
6969
"(z3)(add-library)(show-dependence-graph)" \
70-
"(horn)(skip-loops):(apply-code-contracts)(model-argc-argv):"
70+
"(horn)(skip-loops):(apply-code-contracts)(model-argc-argv):" \
71+
"(show-threaded)"
7172

7273
class goto_instrument_parse_optionst:
7374
public parse_options_baset,

0 commit comments

Comments
 (0)