Commit d62b1c932e

fn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com>
2022-03-19 18:08:17
translate-c: add missing builtins used by CRuby
1 parent ad5770e
Changed files (2)
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
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"