Skip to content

Commit 58fec48

Browse files
Check for existing __VERIFIER_atomic_begin/end before creating varinfos
Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/769cff72-d99d-4307-a362-bf6f91c1dd2d Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
1 parent 522caf9 commit 58fec48

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/witness/yamlWitness.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ let loc_of_location (location: YamlWitnessType.Location.t): Cil.location = {
418418
synthetic = false;
419419
}
420420

421-
let ghost_atomic_begin = makeVarinfo true "__VERIFIER_atomic_begin" (TVoid [])
422-
let ghost_atomic_end = makeVarinfo true "__VERIFIER_atomic_end" (TVoid [])
423-
424421
(** Get the source location of an instruction, if available. *)
425422
let ghost_instr_loc = function
426423
| Set (_, _, loc, _)
@@ -439,7 +436,7 @@ let ghost_instr_loc = function
439436
ghostupdate;
440437
__VERIFIER_atomic_end();
441438
]} *)
442-
class ghostUpdateVisitor (updates : (string, Cil.instr list) Hashtbl.t) = object
439+
class ghostUpdateVisitor (updates : (string, Cil.instr list) Hashtbl.t) (atomic_begin : Cil.varinfo) (atomic_end : Cil.varinfo) = object
443440
inherit nopCilVisitor
444441

445442
method! vstmt s =
@@ -455,9 +452,9 @@ class ghostUpdateVisitor (updates : (string, Cil.instr list) Hashtbl.t) = object
455452
| None | Some [] -> [instr]
456453
| Some update_instrs ->
457454
let abegin = Formatcil.cInstr "%v:__VERIFIER_atomic_begin();" loc
458-
[("__VERIFIER_atomic_begin", Cil.Fv ghost_atomic_begin)] in
455+
[("__VERIFIER_atomic_begin", Cil.Fv atomic_begin)] in
459456
let aend = Formatcil.cInstr "%v:__VERIFIER_atomic_end();" loc
460-
[("__VERIFIER_atomic_end", Cil.Fv ghost_atomic_end)] in
457+
[("__VERIFIER_atomic_end", Cil.Fv atomic_end)] in
461458
abegin :: instr :: update_instrs @ [aend])
462459
) il in
463460
s.skind <- Instr new_il
@@ -591,8 +588,16 @@ let init () =
591588
M.error_noloc ~category:Witness "couldn't parse entry while extracting ghost updates: %s" m
592589
in
593590
List.iter collect_ghost_updates yaml_entries;
594-
if Hashtbl.length updates > 0 then
595-
visitCilFile (new ghostUpdateVisitor updates) file
591+
if Hashtbl.length updates > 0 then begin
592+
let find_or_make name =
593+
match find_global_var name with
594+
| Some v -> v
595+
| None -> makeVarinfo true name (TVoid [])
596+
in
597+
let atomic_begin = find_or_make "__VERIFIER_atomic_begin" in
598+
let atomic_end = find_or_make "__VERIFIER_atomic_end" in
599+
visitCilFile (new ghostUpdateVisitor updates atomic_begin atomic_end) file
600+
end
596601

597602
module ValidationResult =
598603
struct

0 commit comments

Comments
 (0)