mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
translate-c: add <assert.h> support
Implement __builtin_expect so C code that uses assert() can be translated.
This commit is contained in:
parent
9550db33cb
commit
45d220cac6
@ -182,3 +182,9 @@ pub fn __builtin_memcpy(
|
||||
@memcpy(dst_cast, src_cast, len);
|
||||
return dst;
|
||||
}
|
||||
|
||||
/// The return value of __builtin_expect is `expr`. `c` is the expected value
|
||||
/// of `expr` and is used as a hint to the compiler in C. Here it is unused.
|
||||
pub fn __builtin_expect(expr: c_long, c: c_long) callconv(.Inline) c_long {
|
||||
return expr;
|
||||
}
|
||||
|
@ -1106,4 +1106,27 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
|
||||
cases.add("handle assert.h",
|
||||
\\#include <assert.h>
|
||||
\\int main() {
|
||||
\\ int x = 1;
|
||||
\\ int *xp = &x;
|
||||
\\ assert(1);
|
||||
\\ assert(x != 0);
|
||||
\\ assert(xp);
|
||||
\\ assert(*xp);
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
|
||||
cases.add("NDEBUG disables assert",
|
||||
\\#define NDEBUG
|
||||
\\#include <assert.h>
|
||||
\\int main() {
|
||||
\\ assert(0);
|
||||
\\ assert(NULL);
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user