zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit d62b1c932e5c5ff9cd3e14b4f3f8c078a0fb43f9 (tree)
parent ad5770eba40e0cc425c7a1eab4d37c6f9788d670
Author: fn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com>
Date:   Sat, 19 Mar 2022 10:08:17 -0700

translate-c: add missing builtins used by CRuby


Diffstat:
MCMakeLists.txt | 1+
Mlib/std/zig/c_builtins.zig | 21+++++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -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" diff --git a/lib/std/zig/c_builtins.zig b/lib/std/zig/c_builtins.zig @@ -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