authorgravatar for evan@lagerdata.comEvan Haas <evan@lagerdata.com> 2024-07-29 10:12:33-07:00
committergravatar for evan@lagerdata.comEvan Haas <evan@lagerdata.com> 2024-07-29 10:25:55-07:00
log5d8e56c2ebf22cc1320aa26d8ed6877bd03036cb
tree04d85873cf6a94718cdc29a97d7bb0ab1d598335
parentd7b9bbecaf6ba3ee924d7744ea720c67bc8f0a1b
signaturebadge-check Signed by SSH key SHA256:cf2/TFgSxv2uRX26INvFSw25Prr1Dy9H8MiRXgLpok4

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.

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

lib/compiler/aro_translate_c.zig+2
...@@ -228,6 +228,7 @@ fn prepopulateGlobalNameTable(c: *Context) !void {...@@ -228,6 +228,7 @@ fn prepopulateGlobalNameTable(c: *Context) !void {
228 const decl_name = c.tree.tokSlice(data.decl.name);228 const decl_name = c.tree.tokSlice(data.decl.name);
229 try c.global_names.put(c.gpa, decl_name, {});229 try c.global_names.put(c.gpa, decl_name, {});
230 },230 },
231 .static_assert => {},
231 else => unreachable,232 else => unreachable,
232 }233 }
233 }234 }
...@@ -305,6 +306,7 @@ fn transDecl(c: *Context, scope: *Scope, decl: NodeIndex) !void {...@@ -305,6 +306,7 @@ fn transDecl(c: *Context, scope: *Scope, decl: NodeIndex) !void {
305 => {306 => {
306 try transVarDecl(c, decl, null);307 try transVarDecl(c, decl, null);
307 },308 },
309 .static_assert => try warn(c, &c.global_scope.base, 0, "ignoring _Static_assert declaration", .{}),
308 else => unreachable,310 else => unreachable,
309 }311 }
310}312}
test/cases/translate_c/_Static_assert.c created+7
...@@ -0,0 +1,7 @@
1_Static_assert(1 == 1, "");
2
3// translate-c
4// target=x86_64-linux
5// c_frontend=aro
6//
7// tmp.c:1:1: warning: ignoring _Static_assert declaration