Skip to content

Commit ab578f7

Browse files
committed
Make machdep arguments labeled in constFold
1 parent 617f6e4 commit ab578f7

7 files changed

Lines changed: 67 additions & 67 deletions

File tree

src/check.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ and checkInit (i: init) : typ =
639639
match elen with
640640
| None -> 0L
641641
| Some e -> (ignore (checkExp true e);
642-
match getInteger (constFold true e) with
642+
match getInteger (constFold ~machdep:true e) with
643643
Some len -> Z.to_int64 len (* Z on purpose, we don't want to ignore overflows here *)
644644
| None ->
645645
ignore (warn "Array length is not a constant");

src/cil.ml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ and bitsSizeOf t =
24982498
addTrailing max (8 * alignOf_int t)
24992499

25002500
| TArray(bt, Some len, _) -> begin
2501-
match constFold true len with
2501+
match constFold ~machdep:true len with
25022502
Const(CInt(l,lk,_)) ->
25032503
let sz = mul_cilint (mkCilintIk lk l) (cilint_of_int (bitsSizeOf bt)) in
25042504
(* Check for overflow.
@@ -2585,9 +2585,9 @@ and bitsOffset (baset: typ) (off: offset) : int * int =
25852585
will also compute compiler-dependent expressions such as sizeof.
25862586
See also {!constFoldVisitor}, which will run constFold on all
25872587
expressions in a given AST node.*)
2588-
and constFold (machdep: bool) (e: exp) : exp =
2588+
and constFold ~(machdep: bool) (e: exp) : exp =
25892589
match e with
2590-
BinOp(bop, e1, e2, tres) -> constFoldBinOp machdep bop e1 e2 tres
2590+
BinOp(bop, e1, e2, tres) -> constFoldBinOp ~machdep bop e1 e2 tres
25912591
| UnOp(unop, e1, tres) -> begin
25922592
try
25932593
let tk =
@@ -2596,7 +2596,7 @@ and constFold (machdep: bool) (e: exp) : exp =
25962596
| TEnum (ei, _) -> ei.ekind
25972597
| _ -> raise Not_found (* probably a float *)
25982598
in
2599-
match constFold machdep e1 with
2599+
match constFold ~machdep e1 with
26002600
| Const(CInt(i,ik,s)) -> begin
26012601
let ic = mkCilintIk ik i in
26022602
match unop with
@@ -2609,14 +2609,14 @@ and constFold (machdep: bool) (e: exp) : exp =
26092609
end
26102610
(* Characters are integers *)
26112611
| Const(CChr c) -> Const(charConstToInt c)
2612-
| Const(CEnum (v, _, _)) -> constFold machdep v
2612+
| Const(CEnum (v, _, _)) -> constFold ~machdep v
26132613
| SizeOf t when machdep -> begin
26142614
try
26152615
let bs = bitsSizeOf t in
26162616
kinteger !kindOfSizeOf (bs / 8)
26172617
with SizeOfError _ -> e
26182618
end
2619-
| SizeOfE e when machdep -> constFold machdep (SizeOf (typeOf e))
2619+
| SizeOfE e when machdep -> constFold ~machdep (SizeOf (typeOf e))
26202620
| SizeOfStr s when machdep -> kinteger !kindOfSizeOf (1 + String.length s)
26212621
| AlignOf t when machdep -> kinteger !kindOfSizeOf (alignOf_int t)
26222622
| AlignOfE e when machdep -> begin
@@ -2626,7 +2626,7 @@ and constFold (machdep: bool) (e: exp) : exp =
26262626
Const (CStr _) ->
26272627
kinteger !kindOfSizeOf !M.theMachine.M.alignof_str
26282628
(* For an array, it is the alignment of the array ! *)
2629-
| _ -> constFold machdep (AlignOf (typeOf e))
2629+
| _ -> constFold ~machdep (AlignOf (typeOf e))
26302630
end
26312631

26322632
| CastE (k, it,
@@ -2636,13 +2636,13 @@ and constFold (machdep: bool) (e: exp) : exp =
26362636
let start, width = bitsOffset bt off in
26372637
if start mod 8 <> 0 then
26382638
E.s (error "Using offset of bitfield");
2639-
constFold machdep (CastE(k, it, (kinteger !kindOfSizeOf (start / 8))))
2639+
constFold ~machdep (CastE(k, it, (kinteger !kindOfSizeOf (start / 8))))
26402640
with SizeOfError _ -> e
26412641
end
26422642

26432643

26442644
| CastE (k, t, e) -> begin
2645-
match constFold machdep e, unrollType t with
2645+
match constFold ~machdep e, unrollType t with
26462646
(* Might truncate silently *)
26472647
| Const(CInt(i,k,_)), TInt(nk,a)
26482648
(* It's okay to drop a cast to const.
@@ -2652,28 +2652,28 @@ and constFold (machdep: bool) (e: exp) : exp =
26522652
Const(CInt(i', nk, None))
26532653
| e', _ -> CastE (k, t, e')
26542654
end
2655-
| Lval lv -> Lval (constFoldLval machdep lv)
2656-
| AddrOf lv -> AddrOf (constFoldLval machdep lv)
2657-
| StartOf lv -> StartOf (constFoldLval machdep lv)
2655+
| Lval lv -> Lval (constFoldLval ~machdep lv)
2656+
| AddrOf lv -> AddrOf (constFoldLval ~machdep lv)
2657+
| StartOf lv -> StartOf (constFoldLval ~machdep lv)
26582658
| _ -> e
26592659

2660-
and constFoldLval machdep (host,offset) =
2660+
and constFoldLval ~machdep (host,offset) =
26612661
let newhost =
26622662
match host with
2663-
| Mem e -> Mem (constFold machdep e)
2663+
| Mem e -> Mem (constFold ~machdep e)
26642664
| Var _ -> host
26652665
in
2666-
let rec constFoldOffset machdep = function
2666+
let rec constFoldOffset ~machdep = function
26672667
| NoOffset -> NoOffset
2668-
| Field (fi,offset) -> Field (fi, constFoldOffset machdep offset)
2669-
| Index (exp,offset) -> Index (constFold machdep exp,
2670-
constFoldOffset machdep offset)
2668+
| Field (fi,offset) -> Field (fi, constFoldOffset ~machdep offset)
2669+
| Index (exp,offset) -> Index (constFold ~machdep exp,
2670+
constFoldOffset ~machdep offset)
26712671
in
2672-
(newhost, constFoldOffset machdep offset)
2672+
(newhost, constFoldOffset ~machdep offset)
26732673

2674-
and constFoldBinOp (machdep: bool) bop e1 e2 tres =
2675-
let e1' = constFold machdep e1 in
2676-
let e2' = constFold machdep e2 in
2674+
and constFoldBinOp ~(machdep: bool) bop e1 e2 tres =
2675+
let e1' = constFold ~machdep e1 in
2676+
let e2' = constFold ~machdep e2 in
26772677
if isIntegralType tres then begin
26782678
let newe =
26792679
let tk =
@@ -2780,7 +2780,7 @@ let isNullPtrConstant e =
27802780
| CastE (_, TPtr (TVoid [], []), e) -> isNullPtrConstant e (* no qualifiers allowed on void or ptr *)
27812781
| e -> isZero e
27822782
in
2783-
isNullPtrConstant (constFold true e)
2783+
isNullPtrConstant (constFold ~machdep:true e)
27842784

27852785
let rec isConstant = function
27862786
| Const _ -> true
@@ -5712,7 +5712,7 @@ class constFoldVisitorClass (machdep: bool) : cilVisitor = object
57125712
| _ -> DoChildren
57135713
method! vexpr (e: exp) =
57145714
(* Do it bottom up *)
5715-
ChangeDoChildrenPost (e, constFold machdep)
5715+
ChangeDoChildrenPost (e, constFold ~machdep)
57165716

57175717
end
57185718
let constFoldVisitor (machdep: bool) = new constFoldVisitorClass machdep
@@ -6016,7 +6016,7 @@ let rec typeSigWithAttrs ?(ignoreSign=false) doattr t =
60166016
let l' =
60176017
match l with
60186018
Some l -> begin
6019-
match constFold true l with
6019+
match constFold ~machdep:true l with
60206020
Const(CInt(i, _, _)) -> Some i
60216021
| e -> None (* Returning None for length in a typesig if the length is not a constant (VLA) *)
60226022
end
@@ -6179,14 +6179,14 @@ let existsType (f: typ -> existsAction) (t: typ) : bool =
61796179
let increm (e: exp) (i: int) =
61806180
let et = typeOf e in
61816181
let bop = if isPointerType et then PlusPI else PlusA in
6182-
constFold false (BinOp(bop, e, integer i, et))
6182+
constFold ~machdep:false (BinOp(bop, e, integer i, et))
61836183

61846184
exception LenOfArray
61856185
let lenOfArray (eo: exp option) : int =
61866186
match eo with
61876187
None -> raise LenOfArray
61886188
| Some e -> begin
6189-
match constFold true e with
6189+
match constFold ~machdep:true e with
61906190
| Const(CInt(ni, _, _)) when compare_cilint ni zero_cilint >= 0 ->
61916191
cilint_to_int ni
61926192
| e -> raise LenOfArray
@@ -6239,7 +6239,7 @@ let rec makeZeroInit (t: typ) : init =
62396239

62406240
| TArray(bt, Some len, _) as t' ->
62416241
let n =
6242-
match constFold true len with
6242+
match constFold ~machdep:true len with
62436243
Const(CInt(n, _, _)) -> cilint_to_int n
62446244
| _ -> E.s (E.unimp "Cannot understand length of array")
62456245
in
@@ -6282,7 +6282,7 @@ let foldLeftCompound
62826282
(* See how many more we have to do *)
62836283
match leno with
62846284
Some lene when implicit -> begin
6285-
match constFold true lene with
6285+
match constFold ~machdep:true lene with
62866286
Const(CInt(i, _, _)) ->
62876287
let len_array = cilint_to_int i in
62886288
let len_init = List.length initl in
@@ -6578,7 +6578,7 @@ let caseRangeFold (l: label list) =
65786578
| ((Case _ | Default _ | Label _) as x) :: xs -> fold (x :: acc) xs
65796579
| CaseRange(el, eh, loc, eloc) :: xs ->
65806580
let il, ih, ik =
6581-
match constFold true el, constFold true eh with
6581+
match constFold ~machdep:true el, constFold ~machdep:true eh with
65826582
Const(CInt(il, ilk, _)), Const(CInt(ih, ihk, _)) ->
65836583
mkCilintIk ilk il, mkCilintIk ihk ih, commonIntKind ilk ihk
65846584
| _ -> E.s (error "Cannot understand the constants in case range (%a and %a)" d_exp el d_exp eh)

src/cil.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,12 +1691,12 @@ val charConstToInt: char -> constant
16911691
will also compute compiler-dependent expressions such as sizeof.
16921692
See also {!constFoldVisitor}, which will run constFold on all
16931693
expressions in a given AST node.*)
1694-
val constFold: bool -> exp -> exp
1694+
val constFold: machdep:bool -> exp -> exp
16951695

16961696
(** Do constant folding on a binary operation. The bulk of the work done by
16971697
[constFold] is done here. If the first argument is true then
16981698
will also compute compiler-dependent expressions such as sizeof *)
1699-
val constFoldBinOp: bool -> binop -> exp -> exp -> typ -> exp
1699+
val constFoldBinOp: machdep:bool -> binop -> exp -> exp -> typ -> exp
17001700

17011701
(** Increment an expression. Can be arithmetic or pointer type *)
17021702
val increm: exp -> int -> exp

src/expcompare.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let rec compareExp (e1: exp) (e2: exp) : bool =
6060
| CastE(k1, t1, e1), CastE(k2, t2, e2) ->
6161
k1 = k2 && t1 == t2 && compareExp e1 e2
6262
| _ -> begin
63-
match getInteger (constFold true e1), getInteger (constFold true e2) with
63+
match getInteger (constFold ~machdep:true e1), getInteger (constFold ~machdep:true e2) with
6464
Some i1, Some i2 -> compare_cilint i1 i2 = 0
6565
| _ -> false
6666
end

src/ext/zrapp/deadcodeelim.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ let rec compareExp (e1: exp) (e2: exp) : bool =
213213
| BinOp(bop1, l1, r1, _), BinOp(bop2, l2, r2, _) ->
214214
bop1 = bop2 && compareExp l1 l2 && compareExp r1 r2
215215
| _ -> begin
216-
match getInteger (constFold true e1), getInteger (constFold true e2) with
216+
match getInteger (constFold ~machdep:true e1), getInteger (constFold ~machdep:true e2) with
217217
Some i1, Some i2 -> compare_cilint i1 i2 = 0
218218
| _ -> false
219219
end

0 commit comments

Comments
 (0)