From 1639fd4c45ee816c7c67963fbff3513a32f5737b Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 16 Feb 2022 11:40:33 -0700 Subject: Fix 2D array support for C backend This updates the C backend to use proper array types. In order to do that, this commit also: - fixes up elem_ptr and field_ptr handling - adds `renderTypecast` (renders in C typecast format, e.g. "int* [10]") - adds a bit special handling for undefined pointers, which is necessary to support slice/elem_ptr to undefined decls --- test/behavior/basic.zig | 32 ++++++++++++++++++++++++++++++++ test/behavior/undefined.zig | 5 +++++ 2 files changed, 37 insertions(+) (limited to 'test/behavior') diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 61c7de7a23..05c1f1cda3 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -436,6 +436,38 @@ test "array 2D const double ptr" { try testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]); } +test "array 2D const double ptr with offset" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; + + const rect_2d_vertexes = [_][2]f32{ + [_]f32{ 3.0, 4.239 }, + [_]f32{ 1.0, 2.0 }, + }; + try testArray2DConstDoublePtr(&rect_2d_vertexes[1][0]); +} + +test "array 3D const double ptr with offset" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + + const rect_3d_vertexes = [_][2][2]f32{ + [_][2]f32{ + [_]f32{ 3.0, 4.239 }, + [_]f32{ 3.5, 7.2 }, + }, + [_][2]f32{ + [_]f32{ 3.0, 4.239 }, + [_]f32{ 1.0, 2.0 }, + }, + }; + try testArray2DConstDoublePtr(&rect_3d_vertexes[1][1][0]); +} + fn testArray2DConstDoublePtr(ptr: *const f32) !void { const ptr2 = @ptrCast([*]const f32, ptr); try expect(ptr2[0] == 1.0); diff --git a/test/behavior/undefined.zig b/test/behavior/undefined.zig index 69fba3633d..280fbaf550 100644 --- a/test/behavior/undefined.zig +++ b/test/behavior/undefined.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const expect = std.testing.expect; const mem = std.mem; @@ -12,6 +13,10 @@ fn initStaticArray() [10]i32 { } const static_array = initStaticArray(); test "init static array to undefined" { + // This test causes `initStaticArray()` to be codegen'd, and the + // C backend does not yet support returning arrays, so it fails + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + try expect(static_array[0] == 1); try expect(static_array[4] == 2); try expect(static_array[7] == 3); -- cgit v1.2.3