authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-06 11:48:46+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-06 11:48:46+03:00
logc0b269bf46d6257112f08a3c48904dd5654c97e8
treec4f45c70b182651219412b46700fc0364cae9bac
parent52f0adb3052b284102f2a96c083c5dd28b7941d8
signature Commit is signed but in an unrecognized format.

translate-c: small patch to fix bultin type detection


2 files changed, 4 insertions(+), 5 deletions(-)

src-self-hosted/translate_c.zig+2-3
......@@ -669,7 +669,7 @@ fn transTypeDefAsBuiltin(c: *Context, typedef_decl: *const ZigClangTypedefNameDe
669669}
670670
671671fn checkForBuiltinTypedef(checked_name: []const u8) !?[]const u8 {
672 const table = comptime [_][2][]const u8{
672 const table = [_][2][]const u8{
673673 .{ "uint8_t", "u8" },
674674 .{ "int8_t", "i8" },
675675 .{ "uint16_t", "u16" },
......@@ -1409,10 +1409,9 @@ fn transDeclStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangDeclStmt)
14091409
14101410 const underlying_qual = ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl);
14111411 const underlying_type = ZigClangQualType_getTypePtr(underlying_qual);
1412 const underlying_name = try c.str(ZigClangType_getTypeClassName(underlying_type));
14131412
14141413 const mangled_name = try block_scope.makeMangledName(c, name);
1415 if (try checkForBuiltinTypedef(underlying_name)) |builtin| {
1414 if (try checkForBuiltinTypedef(name)) |builtin| {
14161415 try block_scope.variables.push(.{
14171416 .alias = builtin,
14181417 .name = mangled_name,
test/run_translated_c.zig+2-2
......@@ -245,12 +245,12 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
245245 , "");
246246
247247 cases.add("scoped typedef",
248 \\#include <stdint.h>
249248 \\int main(int argc, char **argv) {
250249 \\ typedef int Foo;
251250 \\ typedef Foo Bar;
252251 \\ typedef void (*func)(int);
253 \\ typedef uint32_t Number;
252 \\ typedef int uint32_t;
253 \\ uint32_t a;
254254 \\ Foo i;
255255 \\ Bar j;
256256 \\ return 0;