diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-08-30 19:11:31 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-08-30 19:11:31 -0700 |
| commit | ea4ef832e364d48b4670c71d948782df12e5e4ca (patch) | |
| tree | b1c395eb2cd6b22d0c5feb55c5d73323dc7aa967 | |
| parent | fb81ba87620467de11db6b904741b4aafc7cb756 (diff) | |
| download | zig-ea4ef832e364d48b4670c71d948782df12e5e4ca.tar.gz zig-ea4ef832e364d48b4670c71d948782df12e5e4ca.zip | |
fix llvm 15 translate-c regressions
by inserting explicit casts.
closes #12682
| -rw-r--r-- | test/run_translated_c.zig | 29 | ||||
| -rw-r--r-- | test/translate_c.zig | 110 |
2 files changed, 65 insertions, 74 deletions
diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig index 4b3d97cb17..71654afba4 100644 --- a/test/run_translated_c.zig +++ b/test/run_translated_c.zig @@ -1868,21 +1868,16 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { \\} , ""); - // Regressed with LLVM 15: - // https://github.com/ziglang/zig/issues/12682 - if (false) { - // The C standard does not require function pointers to be convertible to any integer type. - // However, POSIX requires that function pointers have the same representation as `void *` - // so that dlsym() can work - cases.add("Function to integral", - \\#include <stdint.h> - \\int main(void) { - \\#if defined(__UINTPTR_MAX__) && __has_include(<unistd.h>) - \\ uintptr_t x = main; - \\ x = (uintptr_t)main; - \\#endif - \\ return 0; - \\} - , ""); - } + // The C standard does not require function pointers to be convertible to any integer type. + // However, POSIX requires that function pointers have the same representation as `void *` + // so that dlsym() can work + cases.add("Function to integral", + \\#include <stdint.h> + \\int main(void) { + \\#if defined(__UINTPTR_MAX__) && __has_include(<unistd.h>) + \\ uintptr_t x = (uintptr_t)main; + \\#endif + \\ return 0; + \\} + , ""); } diff --git a/test/translate_c.zig b/test/translate_c.zig index f0c8ad45f3..17fe13330c 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -3173,63 +3173,59 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} }); - // Regressed with LLVM 15: - // https://github.com/ziglang/zig/issues/12682 - if (false) { - if (builtin.zig_backend != .stage1) { - cases.add("implicit casts", - \\#include <stdbool.h> - \\ - \\void fn_int(int x); - \\void fn_f32(float x); - \\void fn_f64(double x); - \\void fn_char(char x); - \\void fn_bool(bool x); - \\void fn_ptr(void *x); - \\ - \\void call() { - \\ fn_int(3.0f); - \\ fn_int(3.0); - \\ fn_int('ABCD'); - \\ fn_f32(3); - \\ fn_f64(3); - \\ fn_char('3'); - \\ fn_char('\x1'); - \\ fn_char(0); - \\ fn_f32(3.0f); - \\ fn_f64(3.0); - \\ fn_bool(123); - \\ fn_bool(0); - \\ fn_bool(&fn_int); - \\ fn_int(&fn_int); - \\ fn_ptr(42); - \\} - , &[_][]const u8{ - \\pub extern fn fn_int(x: c_int) void; - \\pub extern fn fn_f32(x: f32) void; - \\pub extern fn fn_f64(x: f64) void; - \\pub extern fn fn_char(x: u8) void; - \\pub extern fn fn_bool(x: bool) void; - \\pub extern fn fn_ptr(x: ?*anyopaque) void; - \\pub export fn call() void { - \\ fn_int(@floatToInt(c_int, 3.0)); - \\ fn_int(@floatToInt(c_int, 3.0)); - \\ fn_int(@as(c_int, 1094861636)); - \\ fn_f32(@intToFloat(f32, @as(c_int, 3))); - \\ fn_f64(@intToFloat(f64, @as(c_int, 3))); - \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3')))); - \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01')))); - \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0)))); - \\ fn_f32(3.0); - \\ fn_f64(3.0); - \\ fn_bool(@as(c_int, 123) != 0); - \\ fn_bool(@as(c_int, 0) != 0); - \\ fn_bool(@ptrToInt(&fn_int) != 0); - \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int))); - \\ fn_ptr(@intToPtr(?*anyopaque, @as(c_int, 42))); - \\} - }); - } + if (builtin.zig_backend != .stage1) { + cases.add("implicit casts", + \\#include <stdbool.h> + \\ + \\void fn_int(int x); + \\void fn_f32(float x); + \\void fn_f64(double x); + \\void fn_char(char x); + \\void fn_bool(bool x); + \\void fn_ptr(void *x); + \\ + \\void call() { + \\ fn_int(3.0f); + \\ fn_int(3.0); + \\ fn_int('ABCD'); + \\ fn_f32(3); + \\ fn_f64(3); + \\ fn_char('3'); + \\ fn_char('\x1'); + \\ fn_char(0); + \\ fn_f32(3.0f); + \\ fn_f64(3.0); + \\ fn_bool(123); + \\ fn_bool(0); + \\ fn_bool(&fn_int); + \\ fn_int((int)&fn_int); + \\ fn_ptr((void *)42); + \\} + , &[_][]const u8{ + \\pub extern fn fn_int(x: c_int) void; + \\pub extern fn fn_f32(x: f32) void; + \\pub extern fn fn_f64(x: f64) void; + \\pub extern fn fn_char(x: u8) void; + \\pub extern fn fn_bool(x: bool) void; + \\pub extern fn fn_ptr(x: ?*anyopaque) void; + \\pub export fn call() void { + \\ fn_int(@floatToInt(c_int, 3.0)); + \\ fn_int(@floatToInt(c_int, 3.0)); + \\ fn_int(@as(c_int, 1094861636)); + \\ fn_f32(@intToFloat(f32, @as(c_int, 3))); + \\ fn_f64(@intToFloat(f64, @as(c_int, 3))); + \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3')))); + \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01')))); + \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0)))); + \\ fn_f32(3.0); + \\ fn_f64(3.0); + \\ fn_bool(@as(c_int, 123) != 0); + \\ fn_bool(@as(c_int, 0) != 0); + \\ fn_bool(@ptrToInt(&fn_int) != 0); + \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int))); + \\ fn_ptr(@intToPtr(?*anyopaque, @as(c_int, 42))); + \\} + }); } if (builtin.zig_backend != .stage1) { |
