Skip to content

Commit 7341d54

Browse files
committed
translate-c: support macro with 'assert(false && "error message")'
closes ziglang#14642 with modified fix suggested by @Vexu in ziglang#14642 (comment)
1 parent 7fb5a0b commit 7341d54

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/translate_c.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,6 +5793,10 @@ fn macroIntToBool(c: *Context, node: Node) !Node {
57935793
if (isBoolRes(node)) {
57945794
return node;
57955795
}
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

57975801
return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.zero_literal.init() });
57985802
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
void 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));

0 commit comments

Comments
 (0)