aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/pointers.zig
diff options
context:
space:
mode:
authordrew <reserveblue@protonmail.com>2021-11-14 18:28:44 -0800
committerAndrew Kelley <andrew@ziglang.org>2021-11-16 16:51:31 -0700
commit9bf1681990fe87a6b2e5fc644a89f1aece304579 (patch)
tree45617b8500c741e8de902852c0495b5c20279dbf /test/behavior/pointers.zig
parent952d865bd231834adad30905c469edc5a46d000a (diff)
downloadzig-9bf1681990fe87a6b2e5fc644a89f1aece304579.tar.gz
zig-9bf1681990fe87a6b2e5fc644a89f1aece304579.zip
C backend: basic big ints, fix airPtrToInt, array references, pointer arithmetic UB with NULL, implement airPtrElemPtr/Val, fix redundant indirection/references with arrays
-add additional test cases that were found to be passing -add basic int128 test cases which previously did not pass but weren't covered -most test cases in cast.zig now pass -i128/u128 or smaller int constants can now be rendered -unsigned int constants are now always suffixed with 'u' to prevent random compile errors -pointers with a val tag of 'zero' now just emit a 0 constant which coerces to the pointer type and fixes some warnings with ordered comparisons -pointers with a val tag of 'one' are now casted back to the pointer type -support pointers with a u64 val -fix bug where rendering an array's type will emit more indirection than is needed -render uint128_t/int128_t manually when needed -implement ptr_add/sub AIR handlers manually so they manually cast to int types which avoids UB if the result or ptr operand is NULL -implement airPtrElemVal/Ptr -airAlloc for arrays will not allocate a ref as the local for the array is already a reference/pointer to the array itself -fix airPtrToInt by casting to the int type
Diffstat (limited to 'test/behavior/pointers.zig')
-rw-r--r--test/behavior/pointers.zig12
1 files changed, 8 insertions, 4 deletions
diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig
index 69f9e2af2a..32b88a2522 100644
--- a/test/behavior/pointers.zig
+++ b/test/behavior/pointers.zig
@@ -61,12 +61,16 @@ test "initialize const optional C pointer to null" {
test "assigning integer to C pointer" {
var x: i32 = 0;
+ var y: i32 = 1;
var ptr: [*c]u8 = 0;
var ptr2: [*c]u8 = x;
- if (false) {
- ptr;
- ptr2;
- }
+ var ptr3: [*c]u8 = 1;
+ var ptr4: [*c]u8 = y;
+
+ try expect(ptr == ptr2);
+ try expect(ptr3 == ptr4);
+ try expect(ptr3 > ptr and ptr4 > ptr2 and y > x);
+ try expect(1 > ptr and y > ptr2 and 0 < ptr3 and x < ptr4);
}
test "C pointer comparison and arithmetic" {