diff options
| author | drew <reserveblue@protonmail.com> | 2021-11-14 18:28:44 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-11-16 16:51:31 -0700 |
| commit | 9bf1681990fe87a6b2e5fc644a89f1aece304579 (patch) | |
| tree | 45617b8500c741e8de902852c0495b5c20279dbf /test/behavior/int128.zig | |
| parent | 952d865bd231834adad30905c469edc5a46d000a (diff) | |
| download | zig-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/int128.zig')
| -rw-r--r-- | test/behavior/int128.zig | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/behavior/int128.zig b/test/behavior/int128.zig new file mode 100644 index 0000000000..444096ff18 --- /dev/null +++ b/test/behavior/int128.zig @@ -0,0 +1,43 @@ +const std = @import("std"); +const expect = std.testing.expect; +const maxInt = std.math.maxInt; +const minInt = std.math.minInt; + +test "uint128" { + var buff: u128 = maxInt(u128); + try expect(buff == maxInt(u128)); + + const magic_const = 0x12341234123412341234123412341234; + buff = magic_const; + + try expect(buff == magic_const); + try expect(magic_const == 0x12341234123412341234123412341234); + + buff = 0; + try expect(buff == @as(u128, 0)); +} + +test "undefined 128 bit int" { + @setRuntimeSafety(true); + + var undef: u128 = undefined; + var undef_signed: i128 = undefined; + try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @bitCast(u128, undef_signed) == undef); +} + +test "int128" { + var buff: i128 = -1; + try expect(buff < 0 and (buff + 1) == 0); + try expect(@intCast(i8, buff) == @as(i8, -1)); + + buff = minInt(i128); + try expect(buff < 0); + + // This should be uncommented once wrapping arithmetic is implemented for 128 bit ints: + // try expect(buff < 0 and (buff -% 1) > 0) +} + +test "truncate int128" { + var buff: u128 = maxInt(u128); + try expect(@truncate(u64, buff) == maxInt(u64)); +}
\ No newline at end of file |
