Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5793,6 +5793,10 @@ fn macroIntToBool(c: *Context, node: Node) !Node {
if (isBoolRes(node)) {
return node;
}
if (node.tag() == .string_literal) {
const int_from_ptr = try Tag.int_from_ptr.create(c.arena, node);
return Tag.not_equal.create(c.arena, .{ .lhs = int_from_ptr, .rhs = Tag.zero_literal.init() });
}

return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.zero_literal.init() });
}
Expand Down
8 changes: 8 additions & 0 deletions test/cases/translate_c/assert_with_strlit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

void assert(int x) {}
#define FOO assert(0 && "error message")

// translate-c
// c_frontend=clang
//
// pub const FOO = assert((@as(c_int, 0) != 0) and (@intFromPtr("error message") != 0));