Skip to content

Commit 930971c

Browse files
committed
Fix implicit pthread_exit on main thread return (closes #1767)
According to pthread_exit man page, returning from a thread function implicitly calls pthread_exit only on non-main threads. This avoids a strange cast (with overflow check) at normal return from main.
1 parent c27fb50 commit 930971c

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/analyses/base.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,10 +2058,12 @@ struct
20582058
let st' = set ~man ~t_override nst (return_var ()) t_override rv in
20592059
match ThreadId.get_current ask with
20602060
| `Lifted tid when ThreadReturn.is_current ask ->
2061-
(* Evaluate exp and cast the resulting value to the void-pointer-type.
2062-
Casting to the right type here avoids precision loss on joins. *)
2063-
let rv = VD.cast ~torg:(Cilfacade.typeOf exp) Cil.voidPtrType rv in
2064-
man.sideg (V.thread tid) (G.create_thread rv);
2061+
if not (ThreadIdDomain.Thread.is_main tid) then (
2062+
(* Evaluate exp and cast the resulting value to the void-pointer-type.
2063+
Casting to the right type here avoids precision loss on joins. *)
2064+
let rv = VD.cast ~torg:(Cilfacade.typeOf exp) Cil.voidPtrType rv in
2065+
man.sideg (V.thread tid) (G.create_thread rv)
2066+
);
20652067
Priv.thread_return ask (priv_getg man.global) (priv_sideg man.sideg) tid st'
20662068
| _ -> st'
20672069
) nst exp

0 commit comments

Comments
 (0)