authorgravatar for twostepted@gmail.comTravis Staloch <twostepted@gmail.com> 2024-04-11 07:39:47-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-04-11 14:39:47+00:00
log3d1652070acd01b7c871615702916425cd292a8a
tree8f4a270c2a0db5a68dd1986bd75460d425065b12
parentf7a76bdfe3bc05034f895913261a743a83ca3c78
signaturebadge-check Signed by PGP key B5690EEEBB952194

translate-c: support macro with 'assert(false && "error message")'

closes #14642 with modified fix suggested by Vexu in https://github.com/ziglang/zig/issues/14642#issuecomment-1775476042

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

src/translate_c.zig+4
...@@ -5793,6 +5793,10 @@ fn macroIntToBool(c: *Context, node: Node) !Node {...@@ -5793,6 +5793,10 @@ fn macroIntToBool(c: *Context, node: Node) !Node {
5793 if (isBoolRes(node)) {5793 if (isBoolRes(node)) {
5794 return node;5794 return node;
5795 }5795 }
5796 if (node.tag() == .string_literal) {
5797 const int_from_ptr = try Tag.int_from_ptr.create(c.arena, node);
5798 return Tag.not_equal.create(c.arena, .{ .lhs = int_from_ptr, .rhs = Tag.zero_literal.init() });
5799 }
57965800
5797 return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.zero_literal.init() });5801 return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.zero_literal.init() });
5798}5802}
test/cases/translate_c/assert_with_strlit.c created+8
...@@ -0,0 +1,8 @@
1
2void assert(int x) {}
3#define FOO assert(0 && "error message")
4
5// translate-c
6// c_frontend=clang
7//
8// pub const FOO = assert((@as(c_int, 0) != 0) and (@intFromPtr("error message") != 0));