Skip to content

Commit 1cea359

Browse files
Do not fold on overflow for CABS Unop
1 parent 63acd3f commit 1cea359

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/cil.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,8 @@ val mkCilint : ikind -> int64 -> cilint
25842584

25852585
val mkCilintIk : ikind -> cilint -> cilint
25862586

2587+
val const_if_not_overflow : exp -> ikind -> cilint -> exp
2588+
25872589
(** The size of a type, in bytes. Returns a constant expression or a
25882590
* "sizeof" expression if it cannot compute the size. This function
25892591
* is architecture dependent, so you should only call this after you

src/frontc/cabs2cil.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,10 +3805,11 @@ and doExp (asconst: bool) (* This expression is used as a constant *)
38053805
let (se, e', t) = doExp asconst e (AExp None) in
38063806
if isIntegralType t then
38073807
let tres = integralPromotion t in
3808+
let fallback = UnOp(Neg, makeCastT ~e:e' ~oldt:t ~newt:tres, tres) in
38083809
let e'' =
38093810
match e', tres with
3810-
| Const(CInt(i, _, _)), TInt(ik, _) -> kintegerCilint ik (neg_cilint i)
3811-
| _ -> UnOp(Neg, makeCastT ~e:e' ~oldt:t ~newt:tres, tres)
3811+
| Const(CInt(i, _, _)), TInt(ik, _) -> const_if_not_overflow fallback ik (neg_cilint i)
3812+
| _ -> fallback
38123813
in
38133814
finishExp se e'' tres
38143815
else

0 commit comments

Comments
 (0)