Skip to content

Commit 222e3e8

Browse files
committed
CHC: fixes Bool Integer Promotion Crash (CodeHawk-C Issue #69)
1 parent 9fc6ecd commit 222e3e8

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

CodeHawk/CHC/cchlib/cCHTypesUtil.ml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,17 @@ let is_longlong ik =
418418
match ik with ILongLong | IULongLong -> true | _ -> false
419419

420420

421-
(** {1 Integer promotion: C Standard 6.3.1.8}
421+
(** {1 Integer promotion: C Standard 6.3.1.1, 6.3.1.8}
422+
423+
The following may be used in an expression wherever an int or unsigned
424+
int may be used:
425+
- an object or expression with an integer type whose integer conversion
426+
rank is less than or equal to the rank of int and unsigned int.
427+
- a bit-field of type _Bool, int, signed int, unsigned int.
428+
429+
If an int can represent all values of the original type, the value is
430+
converted to an int; otherwise it is converted to an unsigned int. These
431+
are called the integer promotions. A
422432
423433
First, both types are promoted to either signed or unsigned int.
424434
@@ -442,21 +452,21 @@ let is_longlong ik =
442452
corresponding to the type of the operand with signed integer type.
443453
*)
444454

445-
let get_integer_promotion (ty1:typ) (ty2:typ) =
455+
let get_integer_promotion (ty1: typ) (ty2: typ) =
446456
let promote ik =
447457
match ik with
448-
| IChar | ISChar | IShort -> IInt
449-
| IUChar | IUShort -> IUInt
458+
| IChar | ISChar | IUChar | IShort | IBool -> IInt
459+
| IUShort -> IUInt
450460
| _ -> ik in
451-
let ik = match (ty1,ty2) with
452-
| (TInt (ik1,_), TInt (ik2,_)) ->
461+
let ik = match (ty1, ty2) with
462+
| (TInt (ik1, _), TInt (ik2, _)) ->
453463
let ik1 = promote ik1 in
454464
let ik2 = promote ik2 in
455465
if ik1 = ik2 then
456466
ik1
457467
else
458468
begin
459-
match (ik1,ik2) with
469+
match (ik1, ik2) with
460470
| (IInt, ILong) | (ILong, IInt) -> ILong
461471
| (IInt, ILongLong) | (ILongLong, IInt) -> ILongLong
462472
| (ILong, ILongLong) | (ILongLong, ILong) -> ILongLong

CodeHawk/CHC/cchlib/cCHVersion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ object (self)
6262
end
6363

6464
let version = new version_info_t
65-
~version:"0.3.0_20260304"
66-
~date:"2026-03-04"
65+
~version:"0.3.0_20260603"
66+
~date:"2026-06-03"

0 commit comments

Comments
 (0)