Skip to content

Commit 6a3e873

Browse files
committed
Move __builtin_bswap16 const check up
1 parent 847234f commit 6a3e873

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

src/frontc/cabs2cil.ml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,22 +4752,20 @@ and doExp (asconst: bool) (* This expression is used as a constant *)
47524752
prestype := intType
47534753
| _ -> ignore (warn "Invalid call to builtin_types_compatible_p");
47544754
end
4755-
else if fv.vname = "__builtin_bswap16" then
4755+
else if fv.vname = "__builtin_bswap16" && asconst && isEmpty (!prechunk ()) then (* to support pure switch cases in Linux kernel *)
47564756
begin
47574757
match !pargs with
4758-
[ arg ] -> begin
4759-
if asconst && isEmpty (!prechunk ()) then ( (* to support pure switch cases in Linux kernel *)
4760-
piscall := false;
4761-
prestype := TInt (IUShort, []); (* TODO: lookup via machdep? *)
4762-
let arg = CastE (IntegerPromotion, intType, arg) in (* bitwise operators will promote uint16 to int *) (* TODO: consider machdep? *)
4763-
pres :=
4764-
CastE (Internal, !prestype, (* force promoted int back to uint16 *)
4765-
BinOp (BOr,
4766-
BinOp (Shiftlt, arg, integer 8, intType),
4767-
BinOp (Shiftrt, arg, integer 8, intType),
4768-
intType)
4769-
);
4770-
)
4758+
| [ arg ] -> begin
4759+
piscall := false;
4760+
prestype := TInt (IUShort, []); (* TODO: lookup via machdep? *)
4761+
let arg = CastE (IntegerPromotion, intType, arg) in (* bitwise operators will promote uint16 to int *) (* TODO: consider machdep? *)
4762+
pres :=
4763+
CastE (Internal, !prestype, (* force promoted int back to uint16 *)
4764+
BinOp (BOr,
4765+
BinOp (Shiftlt, arg, integer 8, intType),
4766+
BinOp (Shiftrt, arg, integer 8, intType),
4767+
intType)
4768+
);
47714769
end
47724770
| _ ->
47734771
ignore (warn "Invalid call to builtin_bswap16");

0 commit comments

Comments
 (0)