translate-c: add missing builtins used by CRuby

This commit is contained in:
fn ⌃ ⌥ 2022-03-19 10:08:17 -07:00 committed by GitHub
parent ad5770eba4
commit d62b1c932e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -573,6 +573,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/CrossTarget.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/c_builtins.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig"

View File

@ -228,6 +228,27 @@ pub inline fn __builtin_isinf_sign(x: anytype) c_int {
return if (std.math.isPositiveInf(x)) 1 else -1;
}
pub inline fn __has_builtin(func: anytype) c_int {
_ = func;
return @boolToInt(true);
}
pub inline fn __builtin_assume(cond: bool) void {
if (!cond) unreachable;
}
pub inline fn __builtin_unreachable() noreturn {
unreachable;
}
pub inline fn __builtin_constant_p(expr: anytype) c_int {
_ = expr;
return @boolToInt(false);
}
pub fn __builtin_mul_overflow(a: anytype, b: anytype, result: *@TypeOf(a, b)) c_int {
return @boolToInt(@mulWithOverflow(@TypeOf(a, b), a, b, result));
}
// __builtin_alloca_with_align is not currently implemented.
// It is used in a run-translated-c test and a test-translate-c test to ensure that non-implemented
// builtins are correctly demoted. If you implement __builtin_alloca_with_align, please update the