Skip to content

Commit 7fd6180

Browse files
committed
Fix concurrent traces generated via --trace
Traces had been cut off at the failing assertion without considering steps performed in threads with a higher thread id. The behaviour of --stop-on-fail was correct in this regard. The trace trimming must only be performed after re-ordering of steps according to their time stamps.
1 parent 610e9e4 commit 7fd6180

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// #include <pthread.h>
2+
#include <assert.h>
3+
4+
volatile unsigned x = 0, y = 0;
5+
volatile unsigned r1 = 0, r2 = 0;
6+
7+
void* thr1(void* arg) {
8+
x = 1;
9+
r1 = y + 1;
10+
return 0;
11+
}
12+
13+
void* thr2(void* arg) {
14+
y = 1;
15+
r2 = x + 1;
16+
return 0;
17+
}
18+
19+
int main(){
20+
// pthread_t t1, t2;
21+
// pthread_create(&t1, NULL, thr1, NULL);
22+
// pthread_create(&t2, NULL, thr2, NULL);
23+
__CPROVER_ASYNC_1: thr1(0);
24+
__CPROVER_ASYNC_2: thr2(0);
25+
assert(r1 != 1 || r2 != 1);
26+
return 0;
27+
}
28+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--mm tso --trace
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^[[:space:]]*r2=1u \(.*\)$
8+
--
9+
^warning: ignoring

src/goto-symex/build_goto_trace.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,17 @@ void build_goto_trace(
158158

159159
mp_integer current_time=0;
160160

161+
const goto_trace_stept *end_ptr=nullptr;
162+
bool end_step_seen=false;
163+
161164
for(symex_target_equationt::SSA_stepst::const_iterator
162165
it=target.SSA_steps.begin();
163-
it!=end_step;
166+
it!=target.SSA_steps.end();
164167
it++)
165168
{
169+
if(it==end_step)
170+
end_step_seen=true;
171+
166172
const symex_target_equationt::SSA_stept &SSA_step=*it;
167173

168174
if(prop_conv.l_get(SSA_step.guard_literal)!=tvt(true))
@@ -221,6 +227,8 @@ void build_goto_trace(
221227
goto_tracet::stepst &steps=time_map[current_time];
222228
steps.push_back(goto_trace_stept());
223229
goto_trace_stept &goto_trace_step=steps.back();
230+
if(!end_step_seen)
231+
end_ptr=&goto_trace_step;
224232

225233
goto_trace_step.thread_nr=SSA_step.source.thread_nr;
226234
goto_trace_step.pc=SSA_step.source.pc;
@@ -286,6 +294,17 @@ void build_goto_trace(
286294
for(auto &t_it : time_map)
287295
goto_trace.steps.splice(goto_trace.steps.end(), t_it.second);
288296

297+
// cut off the trace at the desired end
298+
for(goto_tracet::stepst::iterator
299+
s_it1=goto_trace.steps.begin();
300+
s_it1!=goto_trace.steps.end();
301+
++s_it1)
302+
if(end_step_seen && end_ptr==&(*s_it1))
303+
{
304+
goto_trace.trim_after(s_it1);
305+
break;
306+
}
307+
289308
// produce the step numbers
290309
unsigned step_nr=0;
291310

@@ -321,7 +340,7 @@ void build_goto_trace(
321340
s_it1++)
322341
if(s_it1->is_assert() && !s_it1->cond_value)
323342
{
324-
goto_trace.steps.erase(++s_it1, goto_trace.steps.end());
343+
goto_trace.trim_after(s_it1);
325344
break;
326345
}
327346
}

0 commit comments

Comments
 (0)