translate-c: check for builtin typedef macro identifiers

Closes #6292
This commit is contained in:
Vexu 2020-09-09 16:29:16 +03:00
parent 7d487a4162
commit 749417a1f3
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
2 changed files with 4 additions and 1 deletions

View File

@ -5881,7 +5881,7 @@ fn parseCPrimaryExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*ast.N
},
.Identifier => {
const mangled_name = scope.getAlias(slice);
return transCreateNodeIdentifier(c, mangled_name);
return transCreateNodeIdentifier(c, checkForBuiltinTypedef(mangled_name) orelse mangled_name);
},
.LParen => {
const inner_node = try parseCExpr(c, m, scope);

View File

@ -2761,12 +2761,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
cases.add("macro cast",
\\#define FOO(bar) baz((void *)(baz))
\\#define BAR (void*) a
\\#define BAZ (uint32_t)(2)
, &[_][]const u8{
\\pub inline fn FOO(bar: anytype) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) {
\\ return baz((@import("std").meta.cast(?*c_void, baz)));
\\}
,
\\pub const BAR = (@import("std").meta.cast(?*c_void, a));
,
\\pub const BAZ = (@import("std").meta.cast(u32, 2));
});
cases.add("macro with cast to unsigned short, long, and long long",