Skip to content

Commit eba7b0f

Browse files
authored
Merge pull request #1823 from goblint/bitfield-z-overflow
Fix `IntervalDomain.top_of` `Z.Overflow` for 63-bit bitfields
2 parents c4ca481 + d6cef91 commit eba7b0f

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

src/cdomain/value/cdomains/int/intervalDomain.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct
1111

1212
let top_of ?bitfield ik =
1313
match bitfield with
14-
| Some b when b <= Ints_t.to_int (range ik |> snd) ->
14+
| Some b when b <= Z.numbits (Size.range ik |> snd) ->
1515
let signed_lower_bound = Ints_t.neg @@ Ints_t.shift_left Ints_t.one (b - 1) in
1616
let unsigned_upper_bound = Ints_t.sub (Ints_t.shift_left Ints_t.one b) Ints_t.one in
1717
if GoblintCil.isSigned ik then

src/framework/constraints.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ open Goblint_constraint.ConstrSys
99
open GobConfig
1010

1111

12+
type Goblint_backtrace.mark += TfLocation of location
13+
14+
let () = Goblint_backtrace.register_mark_printer (function
15+
| TfLocation loc ->
16+
Some ("transfer function at " ^ CilType.Location.show loc)
17+
| _ -> None (* for other marks *)
18+
)
19+
20+
1221
module type Increment =
1322
sig
1423
val increment: increment_data option
@@ -343,14 +352,6 @@ struct
343352
| Skip -> tf_skip var edge prev_node
344353
end getl sidel demandl getg sideg d
345354

346-
type Goblint_backtrace.mark += TfLocation of location
347-
348-
let () = Goblint_backtrace.register_mark_printer (function
349-
| TfLocation loc ->
350-
Some ("transfer function at " ^ CilType.Location.show loc)
351-
| _ -> None (* for other marks *)
352-
)
353-
354355
let tf var getl sidel demandl getg sideg prev_node (_,edge) d (f,t) =
355356
let old_loc = !Goblint_tracing.current_loc in
356357
let old_loc2 = !Goblint_tracing.next_loc in

src/framework/control.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ struct
321321
if M.tracing then M.trace "con" "Initializer %a" CilType.Location.pretty loc;
322322
(*incr count;
323323
if (get_bool "dbg.verbose")&& (!count mod 1000 = 0) then Printf.printf "%d %!" !count; *)
324-
Goblint_tracing.current_loc := loc;
325324
match edge with
326325
| MyCFG.Entry func ->
327326
if M.tracing then M.trace "global_inits" "Entry %a" d_lval (var func.svar);
@@ -341,11 +340,19 @@ struct
341340
res'
342341
| _ -> failwith "Unsupported global initializer edge"
343342
in
343+
let transfer_func st (loc, edge) =
344+
let old_loc = !Goblint_tracing.current_loc in
345+
Goblint_tracing.current_loc := loc;
346+
(* TODO: next_loc? *)
347+
Goblint_backtrace.protect ~mark:(fun () -> Constraints.TfLocation loc) ~finally:(fun () ->
348+
Goblint_tracing.current_loc := old_loc;
349+
) (fun () ->
350+
transfer_func st (loc, edge)
351+
)
352+
in
344353
let with_externs = do_extern_inits man file in
345354
(*if (get_bool "dbg.verbose") then Printf.printf "Number of init. edges : %d\nWorking:" (List.length edges); *)
346-
let old_loc = !Goblint_tracing.current_loc in
347355
let result : Spec.D.t = List.fold_left transfer_func with_externs edges in
348-
Goblint_tracing.current_loc := old_loc;
349356
if M.tracing then M.trace "global_inits" "startstate: %a" Spec.D.pretty result;
350357
result, !funs
351358
in
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// PARAM: --enable ana.int.interval
2+
#include <stdint.h>
3+
4+
// NOCRASH: global initializer for 63-bit bitfield used to crash with Z.Overflow in interval domain
5+
// From: sv-benchmarks/c/intel-tdx-module/tdg_vp_vmcall__requirement__invalid_input_bitmap_havoc_memory.i
6+
struct
7+
{
8+
uint64_t notify_ept_faults : 1;
9+
uint64_t reserved_63_1 : 63;
10+
} g;
11+
12+
int main() {
13+
return 0;
14+
}

0 commit comments

Comments
 (0)