Skip to content

Commit

Permalink
Type: avoid overflow computing size of large _BitInt's
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed May 3, 2024
1 parent baef5b6 commit 43cb31f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aro/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ pub fn sizeof(ty: Type, comp: *const Compilation) ?u64 {
.double => comp.target.c_type_byte_size(.double),
.float128 => 16,
.bit_int => {
return std.mem.alignForward(u64, (ty.data.int.bits + 7) / 8, ty.alignof(comp));
return std.mem.alignForward(u64, (@as(u32, ty.data.int.bits) + 7) / 8, ty.alignof(comp));
},
// zig fmt: off
.complex_char, .complex_schar, .complex_uchar, .complex_short, .complex_ushort, .complex_int,
Expand Down
1 change: 1 addition & 0 deletions test/cases/_BitInt.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum E: _BitInt(512) {
A=6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047WB,
B,
};
_Static_assert(sizeof(_BitInt(65535)) == 8192, "");

#define EXPECTED_ERRORS "_BitInt.c:3:1: warning: '_BitInt' in C17 and earlier is a Clang extension' [-Wbit-int-extension]" \
"_BitInt.c:13:1: error: _BitInt of bit sizes greater than 65535 not supported" \
Expand Down

0 comments on commit 43cb31f

Please sign in to comment.