Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/frontc/cabs2cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4752,6 +4752,22 @@ and doExp (asconst: bool) (* This expression is used as a constant *)
prestype := intType
| _ -> ignore (warn "Invalid call to builtin_types_compatible_p");
end
else if fv.vname = "__builtin_clzll" && asconst && isEmpty (!prechunk ()) then
begin
(* Constant-fold the argument and see if it is a constant *)
let countLeadingZeros (arg: cilint) pos = pos - Z.numbits arg
in
match !pargs with
[ arg ] -> begin
match constFold true arg with
(Const CInt (arg, kind, _)) ->
piscall := false;
pres := integer (countLeadingZeros arg 64);
prestype := intType
| _ -> ()
end
| _ -> ignore (warn "Invalid call to __builtin_clzll");
end
end
| _ -> ()
);
Expand Down
11 changes: 11 additions & 0 deletions test/small1/builtin_clzll.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct S1 {
int x : __builtin_choose_expr(__builtin_clzll(1) == 63, 1, -1),
: __builtin_choose_expr(__builtin_clzll(2) == 62, 1, -1),
: __builtin_choose_expr(__builtin_clzll(4) == 61, 1, -1),
: __builtin_choose_expr(__builtin_clzll(1024) == 53, 1, -1),
: __builtin_choose_expr(__builtin_clzll(1024 * 1024) == 43, 1, -1);
} s1 = {0};

int main() {
return 0;
}
1 change: 1 addition & 0 deletions test/testcil.pl
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ sub addToGroup {
addTest("testrun/builtin4 ");
addTest("test/builtin5 ");
addTest("test/builtin6 ");
addTest("testrun/builtin_clzll ");
addTest("test/sync-1 _GNUCC=1");
addTest("test/sync-2 _GNUCC=1");
addTest("test/sync-3 _GNUCC=1");
Expand Down