Skip to content

Commit b0efbc9

Browse files
committed
Add PointerConversion castkind
1 parent 6b079a7 commit b0efbc9

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/cil.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ and castkind =
621621
| DefaultArgumentPromotion
622622
| ArithmeticConversion
623623
| ConditionalConversion (* non-standard terminology *)
624+
| PointerConversion (* non-standard terminology *)
624625
| Unknown (* TODO: eventually remove *)
625626

626627
(** An lvalue denotes the contents of a range of memory addresses. This range
@@ -2887,6 +2888,7 @@ let d_castkind () k =
28872888
| DefaultArgumentPromotion -> text "DefaultArgumentPromotion"
28882889
| ArithmeticConversion -> text "ArithmeticConversion"
28892890
| ConditionalConversion -> text "ConditionalConversion"
2891+
| PointerConversion -> text "PointerConversion"
28902892
| Unknown -> text "Unknown"
28912893

28922894
let invalidStmt = mkStmt (Instr [])

src/cil.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ and castkind =
730730
| DefaultArgumentPromotion
731731
| ArithmeticConversion
732732
| ConditionalConversion (* non-standard terminology *)
733+
| PointerConversion (* non-standard terminology *)
733734
| Unknown (* TODO: eventually remove *)
734735

735736
(** {b Lvalues.} Lvalues are the sublanguage of expressions that can appear at the left of an assignment or as operand to the address-of operator.

src/expcompare.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ let rec stripCastsDeepForPtrArith (e:exp): exp =
238238
let e2 = stripCastsDeepForPtrArith e2 in
239239
if not(compareTypesNoAttributes ~ignoreSign:false
240240
(typeOf e1) (typeOf e2))
241-
then BinOp(MinusPP, mkCast ~kind:Unknown ~e:e1 ~newt:(typeOf e2), e2, t)
241+
then BinOp(MinusPP, mkCast ~kind:PointerConversion ~e:e1 ~newt:(typeOf e2), e2, t)
242242
else BinOp(MinusPP, e1, e2, t)
243243
| BinOp(op,e1,e2,t) ->
244244
let e1 = stripCastsDeepForPtrArith e1 in

src/frontc/cabs2cil.ml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,7 @@ let rec castTo ~kind
14711471
| DefaultArgumentPromotion
14721472
| ArithmeticConversion
14731473
| ConditionalConversion
1474+
| PointerConversion
14741475
| Unknown -> false
14751476
in
14761477
let debugCast = false in
@@ -5072,8 +5073,8 @@ and doBinOp (bop: binop) (e1: exp) (t1: typ) (e2: exp) (t2: typ) : typ * exp =
50725073
(* Cast both sides to an integer *)
50735074
let commontype = !upointType in
50745075
intType,
5075-
optConstFoldBinOp false bop (makeCastT ~kind:Unknown ~e:e1 ~oldt:t1 ~newt:commontype)
5076-
(makeCastT ~kind:Unknown ~e:e2 ~oldt:t2 ~newt:commontype) intType
5076+
optConstFoldBinOp false bop (makeCastT ~kind:PointerConversion ~e:e1 ~oldt:t1 ~newt:commontype)
5077+
(makeCastT ~kind:PointerConversion ~e:e2 ~oldt:t2 ~newt:commontype) intType
50775078
in
50785079

50795080
match bop with
@@ -5106,32 +5107,32 @@ and doBinOp (bop: binop) (e1: exp) (t1: typ) (e2: exp) (t2: typ) : typ * exp =
51065107
| MinusA when isPointerType t1 && isPointerType t2 ->
51075108
let commontype = t1 in
51085109
!ptrdiffType,
5109-
optConstFoldBinOp false MinusPP (makeCastT ~kind:Unknown ~e:e1 ~oldt:t1 ~newt:commontype)
5110-
(makeCastT ~kind:Unknown ~e:e2 ~oldt:t2 ~newt:commontype) !ptrdiffType
5110+
optConstFoldBinOp false MinusPP (makeCastT ~kind:PointerConversion ~e:e1 ~oldt:t1 ~newt:commontype)
5111+
(makeCastT ~kind:PointerConversion ~e:e2 ~oldt:t2 ~newt:commontype) !ptrdiffType
51115112
| (Le|Lt|Ge|Gt|Eq|Ne) when isPointerType t1 && isPointerType t2 ->
51125113
pointerComparison e1 t1 e2 t2
51135114
| (Eq|Ne) when isPointerType t1 && isZero e2 ->
5114-
pointerComparison e1 t1 (makeCastT ~kind:Unknown ~e:zero ~oldt:!upointType ~newt:t1) t1
5115+
pointerComparison e1 t1 (makeCastT ~kind:PointerConversion ~e:zero ~oldt:!upointType ~newt:t1) t1
51155116
| (Eq|Ne) when isPointerType t2 && isZero e1 ->
5116-
pointerComparison (makeCastT ~kind:Unknown ~e:zero ~oldt:!upointType ~newt:t2) t2 e2 t2
5117+
pointerComparison (makeCastT ~kind:PointerConversion ~e:zero ~oldt:!upointType ~newt:t2) t2 e2 t2
51175118

51185119
| (Eq|Ne) when isVariadicListType t1 && isZero e2 ->
51195120
ignore (warnOpt "Comparison of va_list and zero");
5120-
pointerComparison e1 t1 (makeCastT ~kind:Unknown ~e:zero ~oldt:!upointType ~newt:t1) t1
5121+
pointerComparison e1 t1 (makeCastT ~kind:PointerConversion ~e:zero ~oldt:!upointType ~newt:t1) t1
51215122
| (Eq|Ne) when isVariadicListType t2 && isZero e1 ->
51225123
ignore (warnOpt "Comparison of zero and va_list");
5123-
pointerComparison (makeCastT ~kind:Unknown ~e:zero ~oldt:!upointType ~newt:t2) t2 e2 t2
5124+
pointerComparison (makeCastT ~kind:PointerConversion ~e:zero ~oldt:!upointType ~newt:t2) t2 e2 t2
51245125

51255126
| (Eq|Ne|Le|Lt|Ge|Gt) when isPointerType t1 && isArithmeticType t2 ->
51265127
ignore (warnOpt "Comparison of pointer and non-pointer");
51275128
(* Cast both values to upointType *)
5128-
doBinOp bop (makeCastT ~kind:Unknown ~e:e1 ~oldt:t1 ~newt:!upointType) !upointType
5129-
(makeCastT ~kind:Unknown ~e:e2 ~oldt:t2 ~newt:!upointType) !upointType
5129+
doBinOp bop (makeCastT ~kind:PointerConversion ~e:e1 ~oldt:t1 ~newt:!upointType) !upointType
5130+
(makeCastT ~kind:PointerConversion ~e:e2 ~oldt:t2 ~newt:!upointType) !upointType
51305131
| (Eq|Ne|Le|Lt|Ge|Gt) when isArithmeticType t1 && isPointerType t2 ->
51315132
ignore (warnOpt "Comparison of pointer and non-pointer");
51325133
(* Cast both values to upointType *)
5133-
doBinOp bop (makeCastT ~kind:Unknown ~e:e1 ~oldt:t1 ~newt:!upointType) !upointType
5134-
(makeCastT ~kind:Unknown ~e:e2 ~oldt:t2 ~newt:!upointType) !upointType
5134+
doBinOp bop (makeCastT ~kind:PointerConversion ~e:e1 ~oldt:t1 ~newt:!upointType) !upointType
5135+
(makeCastT ~kind:PointerConversion ~e:e2 ~oldt:t2 ~newt:!upointType) !upointType
51355136

51365137
| _ -> E.s (error "Invalid operands to binary operator: %a" d_plainexp (BinOp(bop,e1,e2,intType)))
51375138

0 commit comments

Comments
 (0)