Skip to content

Commit

Permalink
Merge pull request #20883 from ehaas/aro-translate-c-no-panic
Browse files Browse the repository at this point in the history
aro-translate-c improvements
  • Loading branch information
andrewrk authored Aug 1, 2024
2 parents c08effc + 1cc74f3 commit 7c5ee3e
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 88 deletions.
235 changes: 186 additions & 49 deletions lib/compiler/aro_translate_c.zig

Large diffs are not rendered by default.

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");
6 changes: 6 additions & 0 deletions test/cases/translate_c/empty declaration.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;

// translate-c
// c_frontend=clang,aro
//
//
10 changes: 10 additions & 0 deletions test/cases/translate_c/function prototype with parenthesis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
void (f0) (void *L);
void ((f1)) (void *L);
void (((f2))) (void *L);

// translate-c
// c_frontend=clang,aro
//
// pub extern fn f0(L: ?*anyopaque) void;
// pub extern fn f1(L: ?*anyopaque) void;
// pub extern fn f2(L: ?*anyopaque) void;
6 changes: 6 additions & 0 deletions test/cases/translate_c/noreturn attribute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void foo(void) __attribute__((noreturn));

// translate-c
// c_frontend=aro,clang
//
// pub extern fn foo() noreturn;
8 changes: 8 additions & 0 deletions test/cases/translate_c/simple function prototypes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
void __attribute__((noreturn)) foo(void);
int bar(void);

// translate-c
// c_frontend=clang,aro
//
// pub extern fn foo() noreturn;
// pub extern fn bar() c_int;
10 changes: 10 additions & 0 deletions test/cases/translate_c/struct prototype used in func.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct Foo;
struct Foo *some_func(struct Foo *foo, int x);

// translate-c
// c_frontend=clang,aro
//
// pub const struct_Foo = opaque {};
// pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
//
// pub const Foo = struct_Foo;
39 changes: 0 additions & 39 deletions test/translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\};
});

cases.add("function prototype with parenthesis",
\\void (f0) (void *L);
\\void ((f1)) (void *L);
\\void (((f2))) (void *L);
, &[_][]const u8{
\\pub extern fn f0(L: ?*anyopaque) void;
\\pub extern fn f1(L: ?*anyopaque) void;
\\pub extern fn f2(L: ?*anyopaque) void;
});

cases.add("array initializer w/ typedef",
\\typedef unsigned char uuid_t[16];
\\static const uuid_t UUID_NULL __attribute__ ((unused)) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Expand All @@ -529,10 +519,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\};
});

cases.add("empty declaration",
\\;
, &[_][]const u8{""});

cases.add("#define hex literal with capital X",
\\#define VAL 0XF00D
, &[_][]const u8{
Expand Down Expand Up @@ -658,14 +644,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn my_fn() linksection("NEAR,.data") void {}
});

cases.add("simple function prototypes",
\\void __attribute__((noreturn)) foo(void);
\\int bar(void);
, &[_][]const u8{
\\pub extern fn foo() noreturn;
\\pub extern fn bar() c_int;
});

cases.add("simple var decls",
\\void foo(void) {
\\ int a;
Expand Down Expand Up @@ -796,12 +774,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\}
});

cases.add("noreturn attribute",
\\void foo(void) __attribute__((noreturn));
, &[_][]const u8{
\\pub extern fn foo() noreturn;
});

cases.add("always_inline attribute",
\\__attribute__((always_inline)) int foo() {
\\ return 5;
Expand Down Expand Up @@ -901,17 +873,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub const Foo = struct_Foo;
});

cases.add("struct prototype used in func",
\\struct Foo;
\\struct Foo *some_func(struct Foo *foo, int x);
, &[_][]const u8{
\\pub const struct_Foo = opaque {};
,
\\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
,
\\pub const Foo = struct_Foo;
});

cases.add("#define an unsigned integer literal",
\\#define CHANNEL_COUNT 24
, &[_][]const u8{
Expand Down

0 comments on commit 7c5ee3e

Please sign in to comment.