diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 30cf0bc071..9de3dff94f 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -5764,7 +5764,22 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, .Keyword_float => return transCreateNodeIdentifierUnchecked(c, "f32"), .Keyword_short => return transCreateNodeIdentifierUnchecked(c, "c_short"), .Keyword_char => return transCreateNodeIdentifierUnchecked(c, "c_char"), - .Keyword_unsigned => return transCreateNodeIdentifierUnchecked(c, "c_uint"), + .Keyword_unsigned => if (it.next()) |t| { + switch (t.id) { + .Keyword_short => return transCreateNodeIdentifierUnchecked(c, "c_ushort"), + .Keyword_int => return transCreateNodeIdentifierUnchecked(c, "c_uint"), + .Keyword_long => if (it.peek() != null and it.peek().?.id == .Keyword_long) { + _ = it.next(); + return transCreateNodeIdentifierUnchecked(c, "c_ulonglong"); + } else return transCreateNodeIdentifierUnchecked(c, "c_ulong"), + else => { + _ = it.prev(); + return transCreateNodeIdentifierUnchecked(c, "c_uint"); + }, + } + } else { + return transCreateNodeIdentifierUnchecked(c, "c_uint"); + }, .Identifier => { const mangled_name = scope.getAlias(source[tok.start..tok.end]); return transCreateNodeIdentifier(c, mangled_name); diff --git a/test/translate_c.zig b/test/translate_c.zig index d12b2ab860..c1c4ef07fa 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -2715,6 +2715,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const BAR = (@import("std").meta.cast(?*c_void, a)); }); + cases.add("macro with cast to unsigned short, long, and long long", + \\#define CURLAUTH_BASIC_BUT_USHORT ((unsigned short) 1) + \\#define CURLAUTH_BASIC ((unsigned long) 1) + \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1) + , &[_][]const u8{ + \\pub const CURLAUTH_BASIC_BUT_USHORT = (@import("std").meta.cast(c_ushort, 1)); + \\pub const CURLAUTH_BASIC = (@import("std").meta.cast(c_ulong, 1)); + \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = (@import("std").meta.cast(c_ulonglong, 1)); + }); + cases.add("macro conditional operator", \\#define FOO a ? b : c , &[_][]const u8{