From 5d8e56c2ebf22cc1320aa26d8ed6877bd03036cb Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Mon, 29 Jul 2024 10:12:33 -0700 Subject: [PATCH] aro_translate_c: do not translate _Static_assert declarations This does not completely ignore static asserts - they are validated by aro during parsing; any failures will render an error and non-zero exit code. Emit a warning comment that _Static_asserts are not translated - this matches the behavior of the existing clang-based translate-c. Aro currently does not store source locations for _Static_assert declarations so I've hard-coded token index 0 for now. --- lib/compiler/aro_translate_c.zig | 2 ++ test/cases/translate_c/_Static_assert.c | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 test/cases/translate_c/_Static_assert.c diff --git a/lib/compiler/aro_translate_c.zig b/lib/compiler/aro_translate_c.zig index 3a08f1ee59..372734ace9 100644 --- a/lib/compiler/aro_translate_c.zig +++ b/lib/compiler/aro_translate_c.zig @@ -228,6 +228,7 @@ fn prepopulateGlobalNameTable(c: *Context) !void { const decl_name = c.tree.tokSlice(data.decl.name); try c.global_names.put(c.gpa, decl_name, {}); }, + .static_assert => {}, else => unreachable, } } @@ -305,6 +306,7 @@ fn transDecl(c: *Context, scope: *Scope, decl: NodeIndex) !void { => { try transVarDecl(c, decl, null); }, + .static_assert => try warn(c, &c.global_scope.base, 0, "ignoring _Static_assert declaration", .{}), else => unreachable, } } diff --git a/test/cases/translate_c/_Static_assert.c b/test/cases/translate_c/_Static_assert.c new file mode 100644 index 0000000000..8ecc639e9d --- /dev/null +++ b/test/cases/translate_c/_Static_assert.c @@ -0,0 +1,7 @@ +_Static_assert(1 == 1, ""); + +// translate-c +// target=x86_64-linux +// c_frontend=aro +// +// tmp.c:1:1: warning: ignoring _Static_assert declaration