authorgravatar for evan@lagerdata.comEvan Haas <evan@lagerdata.com> 2024-07-31 09:22:25-07:00
committergravatar for evan@lagerdata.comEvan Haas <evan@lagerdata.com> 2024-07-31 10:04:21-07:00
logaa5a1105e838fbf2f9f918c2a544be6fa0c35e22
tree18b5652adf611245d6318c060803f528cd3e256f
parent6c632d52f903b97d28210a6a4155eee8e6704d33
signaturebadge-check Signed by SSH key SHA256:cf2/TFgSxv2uRX26INvFSw25Prr1Dy9H8MiRXgLpok4

aro_translate_c: do not translate atomic types


2 files changed, 32 insertions(+), 0 deletions(-)

lib/compiler/aro_translate_c.zig+24
...@@ -78,6 +78,17 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: ZigNode) !void {...@@ -78,6 +78,17 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: ZigNode) !void {
78 }78 }
79}79}
8080
81fn fail(
82 c: *Context,
83 err: anytype,
84 source_loc: TokenIndex,
85 comptime format: []const u8,
86 args: anytype,
87) (@TypeOf(err) || error{OutOfMemory}) {
88 try warn(c, &c.global_scope.base, source_loc, format, args);
89 return err;
90}
91
81fn failDecl(c: *Context, loc: TokenIndex, name: []const u8, comptime format: []const u8, args: anytype) Error!void {92fn failDecl(c: *Context, loc: TokenIndex, name: []const u8, comptime format: []const u8, args: anytype) Error!void {
82 // location93 // location
83 // pub const name = @compileError(msg);94 // pub const name = @compileError(msg);
...@@ -687,8 +698,21 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const Type.Enum, field_...@@ -687,8 +698,21 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const Type.Enum, field_
687 }698 }
688}699}
689700
701fn getTypeStr(c: *Context, ty: Type) ![]const u8 {
702 var buf: std.ArrayListUnmanaged(u8) = .{};
703 defer buf.deinit(c.gpa);
704 const w = buf.writer(c.gpa);
705 try ty.print(c.mapper, c.comp.langopts, w);
706 return c.arena.dupe(u8, buf.items);
707}
708
690fn transType(c: *Context, scope: *Scope, raw_ty: Type, qual_handling: Type.QualHandling, source_loc: TokenIndex) TypeError!ZigNode {709fn transType(c: *Context, scope: *Scope, raw_ty: Type, qual_handling: Type.QualHandling, source_loc: TokenIndex) TypeError!ZigNode {
691 const ty = raw_ty.canonicalize(qual_handling);710 const ty = raw_ty.canonicalize(qual_handling);
711 if (ty.qual.atomic) {
712 const type_name = try getTypeStr(c, ty);
713 return fail(c, error.UnsupportedType, source_loc, "unsupported type: '{s}'", .{type_name});
714 }
715
692 switch (ty.specifier) {716 switch (ty.specifier) {
693 .void => return ZigTag.type.create(c.arena, "anyopaque"),717 .void => return ZigTag.type.create(c.arena, "anyopaque"),
694 .bool => return ZigTag.type.create(c.arena, "bool"),718 .bool => return ZigTag.type.create(c.arena, "bool"),
test/cases/translate_c/atomic types.c created+8
...@@ -0,0 +1,8 @@
1typedef _Atomic(int) AtomicInt;
2
3// translate-c
4// target=x86_64-linux
5// c_frontend=aro
6//
7// tmp.c:1:22: warning: unsupported type: '_Atomic(int)'
8// pub const AtomicInt = @compileError("unable to resolve typedef child type");