Skip to content

Commit 9ae435c

Browse files
authored
Merge pull request herd#1793 from herd/fix-label-null
[litmus] Fix label zero Zero is a legitimate value for a register that holds a label (type `ins_t *`). Print it as `0`, as **herd7** does.
2 parents e8199fc + 5d4ea0a commit 9ae435c

3 files changed

Lines changed: 42 additions & 20 deletions

File tree

litmus/preSi.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ module Make
202202
let some_labels test =
203203
do_precise || do_label_init || see_faults test
204204

205-
let need_symbols env test = see_faults test || U.label_in_outs env test
206-
207205
(***************)
208206
(* File header *)
209207
(***************)
@@ -742,8 +740,11 @@ module Make
742740
O.o "} labels_t;" ;
743741
O.o ""
744742
end ;
745-
if need_symbols env test then begin
746-
UD.dump_label_defs CfgLoc.all_labels ;
743+
let pp_faults = see_faults test
744+
and pp_labels = U.label_in_outs env test in
745+
let need_symbols = pp_faults || pp_labels in
746+
if need_symbols then begin
747+
UD.dump_label_defs ~pp_faults ~pp_labels CfgLoc.all_labels ;
747748
UD.dump_label_funcs do_self CfgLoc.all_labels (T.get_nprocs test)
748749
end ;
749750
if see_faults test || U.ptr_in_outs env test then
@@ -758,7 +759,7 @@ module Make
758759
(fun t -> match Compile.get_fmt Cfg.hexa t with
759760
| CType.Direct fmt|CType.Macro fmt ->
760761
if Cfg.hexa then "0x%" ^ fmt else "%" ^ fmt)
761-
{|label:"P%s"|} locs env
762+
locs env
762763

763764
let some_test_vars test = Misc.consp test.T.globals
764765
let some_vars test = some_test_vars test || some_labels test
@@ -947,7 +948,7 @@ module Make
947948
(fun rloc -> match U.find_rloc_type rloc env with
948949
| Pointer _ when U.is_rloc_label rloc env ->
949950
None,
950-
([sprintf "instr_symb_name[p->%s]" (dump_rloc_tag_coded rloc)], [])
951+
([sprintf "instr_symb_label[p->%s]" (dump_rloc_tag_coded rloc)], [])
951952
| Pointer _ when U.is_rloc_tag_ptr rloc env ->
952953
None,
953954
([sprintf "pretty_addr[untagged(p->%s)]" (dump_rloc_tag_coded rloc);

litmus/skel.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ module Make
10691069
let sloc = A.dump_rloc_tag rloc in
10701070
match U.find_rloc_type rloc env with
10711071
| Pointer t when CType.is_ins_t t ->
1072-
sprintf " instr_symb_name[o[%s_f]]" sloc
1072+
sprintf " instr_symb_label[o[%s_f]]" sloc
10731073
| Pointer _ -> sprintf "pretty_addr[o[%s_f]]" sloc
10741074
| Array (t,sz) ->
10751075
let rec pp_rec k =
@@ -2932,7 +2932,8 @@ module Make
29322932
let env = U.build_env test in
29332933
dump_header test ;
29342934
if U.label_in_outs env test then
2935-
UD.dump_label_defs (T.all_labels test) ;
2935+
UD.dump_label_defs ~pp_labels:true ~pp_faults:false
2936+
(T.all_labels test) ;
29362937
UD.dump_getinstrs test ;
29372938
dump_read_timebase () ;
29382939
dump_threads test ;

litmus/skelUtil.ml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ module Make
159159
(* Some dumping stuff *)
160160
val register_type : 'loc -> CType.t -> CType.t
161161
val fmt_outcome_as_list :
162-
T.t -> (CType.base -> string) -> string -> A.RLocSet.t -> env
162+
T.t -> (CType.base -> string) -> A.RLocSet.t -> env
163163
-> (string * string list) list
164164
val fmt_outcome : T.t -> (CType.base -> string) -> A.RLocSet.t -> env -> string
165165
val fmt_faults : (A.V.v, A.FaultType.t) Fault.atom list -> string
@@ -224,7 +224,9 @@ module Make
224224
val define_label_offsets : env -> T.t -> unit
225225

226226
(* Dump definitions relating to labels in the post-condition *)
227-
val dump_label_defs : Label.Full.full list -> unit
227+
val dump_label_defs :
228+
pp_faults:bool -> pp_labels:bool ->
229+
Label.Full.full list -> unit
228230

229231
(* Dump functions relating to labels in the post-condition *)
230232
val dump_label_funcs : bool -> Label.Full.full list -> int -> unit
@@ -421,10 +423,10 @@ end
421423

422424
let register_type _loc t = t (* Systematically follow given type *)
423425

424-
let fmt_outcome_as_list test pp_fmt_base fmt_label rlocs env =
426+
let fmt_outcome_as_list test pp_fmt_base rlocs env =
425427
let tr_out = tr_out test in
426428
let rec pp_fmt t = match t with
427-
| CType.Pointer t when CType.is_ins_t t -> [fmt_label]
429+
| CType.Pointer t when CType.is_ins_t t -> ["%s";]
428430
| CType.Pointer t when CType.is_tag t -> ["%s";"%s"]
429431
| CType.Pointer _ -> ["%s"]
430432
| CType.Base "pteval_t" ->
@@ -448,7 +450,7 @@ end
448450
rlocs
449451

450452
let fmt_outcome test pp_fmt_base locs env =
451-
let pps = fmt_outcome_as_list test pp_fmt_base {|label:\"P%s\"|} locs env in
453+
let pps = fmt_outcome_as_list test pp_fmt_base locs env in
452454
String.concat " "
453455
(List.map
454456
(fun (p1,p2) -> sprintf "%s=%s;" p1 (String.concat "" p2))
@@ -777,27 +779,44 @@ end
777779
O.o ""
778780
end
779781

780-
let dump_label_defs lbls =
781-
O.f "#define %-25s 0" (instr_symb_id "UNKNOWN") ;
782+
let dump_label_defs ~pp_faults ~pp_labels lbls =
783+
O.f "#define %-25s 0" (instr_symb_id "NULL") ;
782784
(* Define indices for labels *)
783785
List.iteri
784786
(fun i (p,lbl) ->
785787
let flbl = OutUtils.fmt_lbl_var p lbl in
786788
O.f "#define %-25s %d" (instr_symb_id flbl) (i + 1))
787789
lbls ;
790+
O.f "#define %-25s %d"
791+
(instr_symb_id "UNKNOWN")
792+
(List.length lbls+1) ;
788793
O.o "" ;
789-
O.f "static const char *instr_symb_name[] = {" ;
790-
O.oi "\"UNKNOWN\"," ;
791-
(* Define names for inst symbols *)
792-
List.iter (fun (p,lbl) -> O.fi "\"%d:%s\","p lbl) lbls ;
793-
O.o "};" ;
794+
(* Define names for code pointers in faults *)
795+
if pp_faults then begin
796+
O.f "static const char *instr_symb_name[] = {" ;
797+
O.oi "\"NULL\"," ;
798+
List.iter (fun (p,lbl) -> O.fi "\"%d:%s\","p lbl) lbls ;
799+
O.oi "\"UNKNOWN\"," ;
800+
O.o "};" ;
801+
O.o ""
802+
end ;
803+
(* Define names for code pointers in outcome *)
804+
if pp_labels then begin
805+
O.f "static const char *instr_symb_label[] = {" ;
806+
O.oi "\"0\"," ;
807+
List.iter
808+
(fun (p,lbl) -> O.fi "\"label:\\\"P%d:%s\\\"\"," p lbl) lbls ;
809+
O.oi "\"UNKNOWN\"," ;
810+
O.o "};"
811+
end ;
794812
O.o ""
795813

796814
let dump_label_funcs_skel do_self lbls nprocs =
797815
if do_self then
798816
O.o "static int get_instr_symb_id(ctx_t *ctx, ins_t* ins, int i) {"
799817
else
800818
O.o "static int get_instr_symb_id(ctx_t *ctx, ins_t* ins) {" ;
819+
O.fi "if (!ins) return %s;" (instr_symb_id "NULL") ;
801820
for p=0 to nprocs - 1 do
802821
if List.exists (fun (p1,_) -> p = p1) lbls then begin
803822
let code = OutUtils.fmt_code p in
@@ -825,6 +844,7 @@ end
825844

826845
let dump_label_funcs_presi _do_self lbls _nprocs =
827846
O.o "static int get_instr_symb_id(labels_t *lbls, ins_t* pc) {" ;
847+
O.fi "if (!pc) return %s;" (instr_symb_id "NULL") ;
828848
List.iter
829849
(fun (p,lbl) ->
830850
let flbl = (OutUtils.fmt_lbl_var p lbl) in

0 commit comments

Comments
 (0)