From ea8755fda9a76294a711715142e861c8a3333ed2 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 11 Feb 2020 15:24:18 +0100 Subject: [PATCH 1/4] compiler-rt: Export the AEABI builtins when targeting thumb --- lib/std/special/compiler_rt.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index f5e83b5278..8d49fdbd2a 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -149,7 +149,7 @@ comptime { @export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage }); - if (builtin.arch.isARM() and !is_test) { + if ((builtin.arch.isARM() or builtin.arch.isThumb()) and !is_test) { @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage }); From f8fd8c481ad4778c580691ed374561cd650fd7d3 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 11 Feb 2020 15:28:30 +0100 Subject: [PATCH 2/4] test: Skip the atomic-on-fp test for riscv64 --- test/stage1/behavior/atomics.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/stage1/behavior/atomics.zig b/test/stage1/behavior/atomics.zig index 7155e80094..0347f6f94a 100644 --- a/test/stage1/behavior/atomics.zig +++ b/test/stage1/behavior/atomics.zig @@ -146,8 +146,8 @@ fn testAtomicStore() void { } test "atomicrmw with floats" { - if (builtin.arch == .aarch64 or builtin.arch == .arm) - return; + if (builtin.arch == .aarch64 or builtin.arch == .arm or builtin.arch == .riscv64) + return error.SkipZigTest; testAtomicRmwFloat(); } From b81c5be451b18597b38f606dc9a9f3255401190f Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 11 Feb 2020 15:29:06 +0100 Subject: [PATCH 3/4] riscv: Remove 'relax' from the baseline cpu features LLD doesn't implement relaxations at the moment. --- lib/std/target/riscv.zig | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/std/target/riscv.zig b/lib/std/target/riscv.zig index 315329306e..ddf1049a20 100644 --- a/lib/std/target/riscv.zig +++ b/lib/std/target/riscv.zig @@ -78,7 +78,6 @@ pub const cpu = struct { .d, .f, .m, - .relax, }), }; @@ -92,7 +91,6 @@ pub const cpu = struct { .d, .f, .m, - .relax, }), }; From 6c05f0949aa09ac41268097161bacf8dc047e195 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 11 Feb 2020 15:48:35 +0100 Subject: [PATCH 4/4] ir: Fix erroneous error message for ptr casts Don't blindly throw an error if two integer types are checked for compatibility. Bug reported in #4430 --- src/ir.cpp | 13 +++++++++---- test/stage1/behavior/cast.zig | 13 +++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index 7f2348caf2..3fc2ddadeb 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -11873,10 +11873,15 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted } if (wanted_type->id == ZigTypeIdInt && actual_type->id == ZigTypeIdInt) { - result.id = ConstCastResultIdIntShorten; - result.data.int_shorten = heap::c_allocator.allocate_nonzero(1); - result.data.int_shorten->wanted_type = wanted_type; - result.data.int_shorten->actual_type = actual_type; + if (wanted_type->data.integral.is_signed != actual_type->data.integral.is_signed || + wanted_type->data.integral.bit_count != actual_type->data.integral.bit_count) + { + result.id = ConstCastResultIdIntShorten; + result.data.int_shorten = heap::c_allocator.allocate_nonzero(1); + result.data.int_shorten->wanted_type = wanted_type; + result.data.int_shorten->actual_type = actual_type; + return result; + } return result; } diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index a70467e199..f393bfebb5 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -782,3 +782,16 @@ test "cast between [*c]T and ?[*:0]T on fn parameter" { }; S.doTheTest(); } + +test "cast between C pointer with different but compatible types" { + const S = struct { + fn foo(arg: [*]c_ushort) u16 { + return arg[0]; + } + fn doTheTest() void { + var x = [_]u16{ 4, 2, 1, 3 }; + expect(foo(@ptrCast([*]u16, &x)) == 4); + } + }; + S.doTheTest(); +}