Skip to content

Commit

Permalink
aro_translate_c: do not translate atomic types
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Jul 31, 2024
1 parent 6c632d5 commit aa5a110
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/compiler/aro_translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: ZigNode) !void {
}
}

fn fail(
c: *Context,
err: anytype,
source_loc: TokenIndex,
comptime format: []const u8,
args: anytype,
) (@TypeOf(err) || error{OutOfMemory}) {
try warn(c, &c.global_scope.base, source_loc, format, args);
return err;
}

fn failDecl(c: *Context, loc: TokenIndex, name: []const u8, comptime format: []const u8, args: anytype) Error!void {
// location
// pub const name = @compileError(msg);
Expand Down Expand Up @@ -687,8 +698,21 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const Type.Enum, field_
}
}

fn getTypeStr(c: *Context, ty: Type) ![]const u8 {
var buf: std.ArrayListUnmanaged(u8) = .{};
defer buf.deinit(c.gpa);
const w = buf.writer(c.gpa);
try ty.print(c.mapper, c.comp.langopts, w);
return c.arena.dupe(u8, buf.items);
}

fn transType(c: *Context, scope: *Scope, raw_ty: Type, qual_handling: Type.QualHandling, source_loc: TokenIndex) TypeError!ZigNode {
const ty = raw_ty.canonicalize(qual_handling);
if (ty.qual.atomic) {
const type_name = try getTypeStr(c, ty);
return fail(c, error.UnsupportedType, source_loc, "unsupported type: '{s}'", .{type_name});
}

switch (ty.specifier) {
.void => return ZigTag.type.create(c.arena, "anyopaque"),
.bool => return ZigTag.type.create(c.arena, "bool"),
Expand Down
8 changes: 8 additions & 0 deletions test/cases/translate_c/atomic types.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
typedef _Atomic(int) AtomicInt;

// translate-c
// target=x86_64-linux
// c_frontend=aro
//
// tmp.c:1:22: warning: unsupported type: '_Atomic(int)'
// pub const AtomicInt = @compileError("unable to resolve typedef child type");

0 comments on commit aa5a110

Please sign in to comment.