diff options
| author | Cody Tapscott <topolarity@tapscott.me> | 2022-02-16 11:40:33 -0700 |
|---|---|---|
| committer | Cody Tapscott <topolarity@tapscott.me> | 2022-02-16 12:57:11 -0700 |
| commit | 1639fd4c45ee816c7c67963fbff3513a32f5737b (patch) | |
| tree | e39a4ed7294dbe274d296484485eedadf91ac17d /test/behavior/basic.zig | |
| parent | c4baa6696e3580455438c756a023cafe645b91b5 (diff) | |
| download | zig-1639fd4c45ee816c7c67963fbff3513a32f5737b.tar.gz zig-1639fd4c45ee816c7c67963fbff3513a32f5737b.zip | |
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
Diffstat (limited to 'test/behavior/basic.zig')
| -rw-r--r-- | test/behavior/basic.zig | 32 |
1 files changed, 32 insertions, 0 deletions
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); |
