| author | |
| committer | |
| log | 6b1a823b2b30d9318c9877dbdbd3d02fa939fba0 |
| tree | 6e5afdad2397ac7224119811583d19107b6e517a |
| parent | 325e0f5f0e8a9ce2540ec3ec5b7cbbecac15257a |
| parent | 9cf6c1ad11bb5f0247ff3458cba5f3bd156d1fb9 |
| signature |
compiler: add error for unnecessary use of 'var'633 files changed, 3309 insertions(+), 2039 deletions(-)
doc/langref.html.in+121-94| ... | @@ -2609,16 +2609,17 @@ test "Basic vector usage" { | ... | @@ -2609,16 +2609,17 @@ test "Basic vector usage" { |
| 2609 | 2609 | ||
| 2610 | test "Conversion between vectors, arrays, and slices" { | 2610 | test "Conversion between vectors, arrays, and slices" { |
| 2611 | // Vectors and fixed-length arrays can be automatically assigned back and forth | 2611 | // Vectors and fixed-length arrays can be automatically assigned back and forth |
| 2612 | var arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 }; | 2612 | const arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 }; |
| 2613 | var vec: @Vector(4, f32) = arr1; | 2613 | const vec: @Vector(4, f32) = arr1; |
| 2614 | var arr2: [4]f32 = vec; | 2614 | const arr2: [4]f32 = vec; |
| 2615 | try expectEqual(arr1, arr2); | 2615 | try expectEqual(arr1, arr2); |
| 2616 | 2616 | ||
| 2617 | // You can also assign from a slice with comptime-known length to a vector using .* | 2617 | // You can also assign from a slice with comptime-known length to a vector using .* |
| 2618 | const vec2: @Vector(2, f32) = arr1[1..3].*; | 2618 | const vec2: @Vector(2, f32) = arr1[1..3].*; |
| 2619 | 2619 | ||
| 2620 | var slice: []const f32 = &arr1; | 2620 | const slice: []const f32 = &arr1; |
| 2621 | var offset: u32 = 1; | 2621 | var offset: u32 = 1; // var to make it runtime-known |
| 2622 | _ = &offset; // suppress 'var is never mutated' error | ||
| 2622 | // To extract a comptime-known length from a runtime-known offset, | 2623 | // To extract a comptime-known length from a runtime-known offset, |
| 2623 | // first extract a new slice from the starting offset, then an array of | 2624 | // first extract a new slice from the starting offset, then an array of |
| 2624 | // comptime-known length | 2625 | // comptime-known length |
| ... | @@ -2732,7 +2733,8 @@ test "pointer arithmetic with many-item pointer" { | ... | @@ -2732,7 +2733,8 @@ test "pointer arithmetic with many-item pointer" { |
| 2732 | 2733 | ||
| 2733 | test "pointer arithmetic with slices" { | 2734 | test "pointer arithmetic with slices" { |
| 2734 | var array = [_]i32{ 1, 2, 3, 4 }; | 2735 | var array = [_]i32{ 1, 2, 3, 4 }; |
| 2735 | var length: usize = 0; | 2736 | var length: usize = 0; // var to make it runtime-known |
| 2737 | _ = &length; // suppress 'var is never mutated' error | ||
| 2736 | var slice = array[length..array.len]; | 2738 | var slice = array[length..array.len]; |
| 2737 | 2739 | ||
| 2738 | try expect(slice[0] == 1); | 2740 | try expect(slice[0] == 1); |
| ... | @@ -2759,7 +2761,8 @@ const expect = @import("std").testing.expect; | ... | @@ -2759,7 +2761,8 @@ const expect = @import("std").testing.expect; |
| 2759 | 2761 | ||
| 2760 | test "pointer slicing" { | 2762 | test "pointer slicing" { |
| 2761 | var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | 2763 | var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; |
| 2762 | var start: usize = 2; | 2764 | var start: usize = 2; // var to make it runtime-known |
| 2765 | _ = &start; // suppress 'var is never mutated' error | ||
| 2763 | const slice = array[start..4]; | 2766 | const slice = array[start..4]; |
| 2764 | try expect(slice.len == 2); | 2767 | try expect(slice.len == 2); |
| 2765 | 2768 | ||
| ... | @@ -2961,8 +2964,9 @@ const std = @import("std"); | ... | @@ -2961,8 +2964,9 @@ const std = @import("std"); |
| 2961 | const expect = std.testing.expect; | 2964 | const expect = std.testing.expect; |
| 2962 | 2965 | ||
| 2963 | test "allowzero" { | 2966 | test "allowzero" { |
| 2964 | var zero: usize = 0; | 2967 | var zero: usize = 0; // var to make to runtime-known |
| 2965 | var ptr: *allowzero i32 = @ptrFromInt(zero); | 2968 | _ = &zero; // suppress 'var is never mutated' error |
| 2969 | const ptr: *allowzero i32 = @ptrFromInt(zero); | ||
| 2966 | try expect(@intFromPtr(ptr) == 0); | 2970 | try expect(@intFromPtr(ptr) == 0); |
| 2967 | } | 2971 | } |
| 2968 | {#code_end#} | 2972 | {#code_end#} |
| ... | @@ -3006,6 +3010,7 @@ const expect = @import("std").testing.expect; | ... | @@ -3006,6 +3010,7 @@ const expect = @import("std").testing.expect; |
| 3006 | test "basic slices" { | 3010 | test "basic slices" { |
| 3007 | var array = [_]i32{ 1, 2, 3, 4 }; | 3011 | var array = [_]i32{ 1, 2, 3, 4 }; |
| 3008 | var known_at_runtime_zero: usize = 0; | 3012 | var known_at_runtime_zero: usize = 0; |
| 3013 | _ = &known_at_runtime_zero; | ||
| 3009 | const slice = array[known_at_runtime_zero..array.len]; | 3014 | const slice = array[known_at_runtime_zero..array.len]; |
| 3010 | try expect(@TypeOf(slice) == []i32); | 3015 | try expect(@TypeOf(slice) == []i32); |
| 3011 | try expect(&slice[0] == &array[0]); | 3016 | try expect(&slice[0] == &array[0]); |
| ... | @@ -3020,6 +3025,7 @@ test "basic slices" { | ... | @@ -3020,6 +3025,7 @@ test "basic slices" { |
| 3020 | // to perform some optimisations like recognising a comptime-known length when | 3025 | // to perform some optimisations like recognising a comptime-known length when |
| 3021 | // the start position is only known at runtime. | 3026 | // the start position is only known at runtime. |
| 3022 | var runtime_start: usize = 1; | 3027 | var runtime_start: usize = 1; |
| 3028 | _ = &runtime_start; | ||
| 3023 | const length = 2; | 3029 | const length = 2; |
| 3024 | const array_ptr_len = array[runtime_start..][0..length]; | 3030 | const array_ptr_len = array[runtime_start..][0..length]; |
| 3025 | try expect(@TypeOf(array_ptr_len) == *[length]i32); | 3031 | try expect(@TypeOf(array_ptr_len) == *[length]i32); |
| ... | @@ -3056,7 +3062,8 @@ test "using slices for strings" { | ... | @@ -3056,7 +3062,8 @@ test "using slices for strings" { |
| 3056 | var all_together: [100]u8 = undefined; | 3062 | var all_together: [100]u8 = undefined; |
| 3057 | // You can use slice syntax with at least one runtime-known index on an | 3063 | // You can use slice syntax with at least one runtime-known index on an |
| 3058 | // array to convert an array into a slice. | 3064 | // array to convert an array into a slice. |
| 3059 | var start : usize = 0; | 3065 | var start: usize = 0; |
| 3066 | _ = &start; | ||
| 3060 | const all_together_slice = all_together[start..]; | 3067 | const all_together_slice = all_together[start..]; |
| 3061 | // String concatenation example. | 3068 | // String concatenation example. |
| 3062 | const hello_world = try fmt.bufPrint(all_together_slice, "{s} {s}", .{ hello, world }); | 3069 | const hello_world = try fmt.bufPrint(all_together_slice, "{s} {s}", .{ hello, world }); |
| ... | @@ -3075,6 +3082,7 @@ test "slice pointer" { | ... | @@ -3075,6 +3082,7 @@ test "slice pointer" { |
| 3075 | // A pointer to an array can be sliced just like an array: | 3082 | // A pointer to an array can be sliced just like an array: |
| 3076 | var start: usize = 0; | 3083 | var start: usize = 0; |
| 3077 | var end: usize = 5; | 3084 | var end: usize = 5; |
| 3085 | _ = .{ &start, &end }; | ||
| 3078 | const slice = ptr[start..end]; | 3086 | const slice = ptr[start..end]; |
| 3079 | // The slice is mutable because we sliced a mutable pointer. | 3087 | // The slice is mutable because we sliced a mutable pointer. |
| 3080 | try expect(@TypeOf(slice) == []u8); | 3088 | try expect(@TypeOf(slice) == []u8); |
| ... | @@ -3121,6 +3129,7 @@ const expect = std.testing.expect; | ... | @@ -3121,6 +3129,7 @@ const expect = std.testing.expect; |
| 3121 | test "0-terminated slicing" { | 3129 | test "0-terminated slicing" { |
| 3122 | var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 }; | 3130 | var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 }; |
| 3123 | var runtime_length: usize = 3; | 3131 | var runtime_length: usize = 3; |
| 3132 | _ = &runtime_length; | ||
| 3124 | const slice = array[0..runtime_length :0]; | 3133 | const slice = array[0..runtime_length :0]; |
| 3125 | 3134 | ||
| 3126 | try expect(@TypeOf(slice) == [:0]u8); | 3135 | try expect(@TypeOf(slice) == [:0]u8); |
| ... | @@ -3143,6 +3152,7 @@ test "sentinel mismatch" { | ... | @@ -3143,6 +3152,7 @@ test "sentinel mismatch" { |
| 3143 | // This does not match the indicated sentinel value of `0` and will lead | 3152 | // This does not match the indicated sentinel value of `0` and will lead |
| 3144 | // to a runtime panic. | 3153 | // to a runtime panic. |
| 3145 | var runtime_length: usize = 2; | 3154 | var runtime_length: usize = 2; |
| 3155 | _ = &runtime_length; | ||
| 3146 | const slice = array[0..runtime_length :0]; | 3156 | const slice = array[0..runtime_length :0]; |
| 3147 | 3157 | ||
| 3148 | _ = slice; | 3158 | _ = slice; |
| ... | @@ -3266,7 +3276,7 @@ test "linked list" { | ... | @@ -3266,7 +3276,7 @@ test "linked list" { |
| 3266 | // do this: | 3276 | // do this: |
| 3267 | try expect(LinkedList(i32) == LinkedList(i32)); | 3277 | try expect(LinkedList(i32) == LinkedList(i32)); |
| 3268 | 3278 | ||
| 3269 | var list = LinkedList(i32) { | 3279 | const list = LinkedList(i32){ |
| 3270 | .first = null, | 3280 | .first = null, |
| 3271 | .last = null, | 3281 | .last = null, |
| 3272 | .len = 0, | 3282 | .len = 0, |
| ... | @@ -3278,12 +3288,12 @@ test "linked list" { | ... | @@ -3278,12 +3288,12 @@ test "linked list" { |
| 3278 | const ListOfInts = LinkedList(i32); | 3288 | const ListOfInts = LinkedList(i32); |
| 3279 | try expect(ListOfInts == LinkedList(i32)); | 3289 | try expect(ListOfInts == LinkedList(i32)); |
| 3280 | 3290 | ||
| 3281 | var node = ListOfInts.Node { | 3291 | var node = ListOfInts.Node{ |
| 3282 | .prev = null, | 3292 | .prev = null, |
| 3283 | .next = null, | 3293 | .next = null, |
| 3284 | .data = 1234, | 3294 | .data = 1234, |
| 3285 | }; | 3295 | }; |
| 3286 | var list2 = LinkedList(i32) { | 3296 | const list2 = LinkedList(i32){ |
| 3287 | .first = &node, | 3297 | .first = &node, |
| 3288 | .last = &node, | 3298 | .last = &node, |
| 3289 | .len = 1, | 3299 | .len = 1, |
| ... | @@ -3372,13 +3382,13 @@ test "@bitCast between packed structs" { | ... | @@ -3372,13 +3382,13 @@ test "@bitCast between packed structs" { |
| 3372 | fn doTheTest() !void { | 3382 | fn doTheTest() !void { |
| 3373 | try expect(@sizeOf(Full) == 2); | 3383 | try expect(@sizeOf(Full) == 2); |
| 3374 | try expect(@sizeOf(Divided) == 2); | 3384 | try expect(@sizeOf(Divided) == 2); |
| 3375 | var full = Full{ .number = 0x1234 }; | 3385 | const full = Full{ .number = 0x1234 }; |
| 3376 | var divided: Divided = @bitCast(full); | 3386 | const divided: Divided = @bitCast(full); |
| 3377 | try expect(divided.half1 == 0x34); | 3387 | try expect(divided.half1 == 0x34); |
| 3378 | try expect(divided.quarter3 == 0x2); | 3388 | try expect(divided.quarter3 == 0x2); |
| 3379 | try expect(divided.quarter4 == 0x1); | 3389 | try expect(divided.quarter4 == 0x1); |
| 3380 | 3390 | ||
| 3381 | var ordered: [2]u8 = @bitCast(full); | 3391 | const ordered: [2]u8 = @bitCast(full); |
| 3382 | switch (native_endian) { | 3392 | switch (native_endian) { |
| 3383 | .big => { | 3393 | .big => { |
| 3384 | try expect(ordered[0] == 0x12); | 3394 | try expect(ordered[0] == 0x12); |
| ... | @@ -3586,7 +3596,7 @@ const expect = std.testing.expect; | ... | @@ -3586,7 +3596,7 @@ const expect = std.testing.expect; |
| 3586 | const Point = struct {x: i32, y: i32}; | 3596 | const Point = struct {x: i32, y: i32}; |
| 3587 | 3597 | ||
| 3588 | test "anonymous struct literal" { | 3598 | test "anonymous struct literal" { |
| 3589 | var pt: Point = .{ | 3599 | const pt: Point = .{ |
| 3590 | .x = 13, | 3600 | .x = 13, |
| 3591 | .y = 67, | 3601 | .y = 67, |
| 3592 | }; | 3602 | }; |
| ... | @@ -4051,14 +4061,14 @@ const Number = union { | ... | @@ -4051,14 +4061,14 @@ const Number = union { |
| 4051 | }; | 4061 | }; |
| 4052 | 4062 | ||
| 4053 | test "anonymous union literal syntax" { | 4063 | test "anonymous union literal syntax" { |
| 4054 | var i: Number = .{.int = 42}; | 4064 | const i: Number = .{ .int = 42 }; |
| 4055 | var f = makeNumber(); | 4065 | const f = makeNumber(); |
| 4056 | try expect(i.int == 42); | 4066 | try expect(i.int == 42); |
| 4057 | try expect(f.float == 12.34); | 4067 | try expect(f.float == 12.34); |
| 4058 | } | 4068 | } |
| 4059 | 4069 | ||
| 4060 | fn makeNumber() Number { | 4070 | fn makeNumber() Number { |
| 4061 | return .{.float = 12.34}; | 4071 | return .{ .float = 12.34 }; |
| 4062 | } | 4072 | } |
| 4063 | {#code_end#} | 4073 | {#code_end#} |
| 4064 | {#header_close#} | 4074 | {#header_close#} |
| ... | @@ -4098,7 +4108,7 @@ test "call foo" { | ... | @@ -4098,7 +4108,7 @@ test "call foo" { |
| 4098 | test "access variable after block scope" { | 4108 | test "access variable after block scope" { |
| 4099 | { | 4109 | { |
| 4100 | var x: i32 = 1; | 4110 | var x: i32 = 1; |
| 4101 | _ = x; | 4111 | _ = &x; |
| 4102 | } | 4112 | } |
| 4103 | x += 1; | 4113 | x += 1; |
| 4104 | } | 4114 | } |
| ... | @@ -4149,7 +4159,7 @@ test "separate scopes" { | ... | @@ -4149,7 +4159,7 @@ test "separate scopes" { |
| 4149 | } | 4159 | } |
| 4150 | { | 4160 | { |
| 4151 | var pi: bool = true; | 4161 | var pi: bool = true; |
| 4152 | _ = pi; | 4162 | _ = π |
| 4153 | } | 4163 | } |
| 4154 | } | 4164 | } |
| 4155 | {#code_end#} | 4165 | {#code_end#} |
| ... | @@ -4423,7 +4433,7 @@ fn withSwitch(any: AnySlice) usize { | ... | @@ -4423,7 +4433,7 @@ fn withSwitch(any: AnySlice) usize { |
| 4423 | } | 4433 | } |
| 4424 | 4434 | ||
| 4425 | test "inline for and inline else similarity" { | 4435 | test "inline for and inline else similarity" { |
| 4426 | var any = AnySlice{ .c = "hello" }; | 4436 | const any = AnySlice{ .c = "hello" }; |
| 4427 | try expect(withFor(any) == 5); | 4437 | try expect(withFor(any) == 5); |
| 4428 | try expect(withSwitch(any) == 5); | 4438 | try expect(withSwitch(any) == 5); |
| 4429 | } | 4439 | } |
| ... | @@ -4455,7 +4465,7 @@ fn getNum(u: U) u32 { | ... | @@ -4455,7 +4465,7 @@ fn getNum(u: U) u32 { |
| 4455 | } | 4465 | } |
| 4456 | 4466 | ||
| 4457 | test "test" { | 4467 | test "test" { |
| 4458 | var u = U{ .b = 42 }; | 4468 | const u = U{ .b = 42 }; |
| 4459 | try expect(getNum(u) == 42); | 4469 | try expect(getNum(u) == 42); |
| 4460 | } | 4470 | } |
| 4461 | {#code_end#} | 4471 | {#code_end#} |
| ... | @@ -4762,7 +4772,7 @@ test "multi object for" { | ... | @@ -4762,7 +4772,7 @@ test "multi object for" { |
| 4762 | } | 4772 | } |
| 4763 | 4773 | ||
| 4764 | test "for reference" { | 4774 | test "for reference" { |
| 4765 | var items = [_]i32 { 3, 4, 2 }; | 4775 | var items = [_]i32{ 3, 4, 2 }; |
| 4766 | 4776 | ||
| 4767 | // Iterate over the slice by reference by | 4777 | // Iterate over the slice by reference by |
| 4768 | // specifying that the capture value is a pointer. | 4778 | // specifying that the capture value is a pointer. |
| ... | @@ -4777,7 +4787,7 @@ test "for reference" { | ... | @@ -4777,7 +4787,7 @@ test "for reference" { |
| 4777 | 4787 | ||
| 4778 | test "for else" { | 4788 | test "for else" { |
| 4779 | // For allows an else attached to it, the same as a while loop. | 4789 | // For allows an else attached to it, the same as a while loop. |
| 4780 | var items = [_]?i32 { 3, 4, null, 5 }; | 4790 | const items = [_]?i32{ 3, 4, null, 5 }; |
| 4781 | 4791 | ||
| 4782 | // For loops can also be used as expressions. | 4792 | // For loops can also be used as expressions. |
| 4783 | // Similar to while loops, when you break from a for loop, the else branch is not evaluated. | 4793 | // Similar to while loops, when you break from a for loop, the else branch is not evaluated. |
| ... | @@ -5347,7 +5357,7 @@ fn addFortyTwo(x: anytype) @TypeOf(x) { | ... | @@ -5347,7 +5357,7 @@ fn addFortyTwo(x: anytype) @TypeOf(x) { |
| 5347 | test "fn type inference" { | 5357 | test "fn type inference" { |
| 5348 | try expect(addFortyTwo(1) == 43); | 5358 | try expect(addFortyTwo(1) == 43); |
| 5349 | try expect(@TypeOf(addFortyTwo(1)) == comptime_int); | 5359 | try expect(@TypeOf(addFortyTwo(1)) == comptime_int); |
| 5350 | var y: i64 = 2; | 5360 | const y: i64 = 2; |
| 5351 | try expect(addFortyTwo(y) == 44); | 5361 | try expect(addFortyTwo(y) == 44); |
| 5352 | try expect(@TypeOf(addFortyTwo(y)) == i64); | 5362 | try expect(@TypeOf(addFortyTwo(y)) == i64); |
| 5353 | } | 5363 | } |
| ... | @@ -5795,7 +5805,7 @@ fn getData() !u32 { | ... | @@ -5795,7 +5805,7 @@ fn getData() !u32 { |
| 5795 | } | 5805 | } |
| 5796 | 5806 | ||
| 5797 | fn genFoos(allocator: Allocator, num: usize) ![]Foo { | 5807 | fn genFoos(allocator: Allocator, num: usize) ![]Foo { |
| 5798 | var foos = try allocator.alloc(Foo, num); | 5808 | const foos = try allocator.alloc(Foo, num); |
| 5799 | errdefer allocator.free(foos); | 5809 | errdefer allocator.free(foos); |
| 5800 | 5810 | ||
| 5801 | for (foos, 0..) |*foo, i| { | 5811 | for (foos, 0..) |*foo, i| { |
| ... | @@ -5833,7 +5843,7 @@ fn getData() !u32 { | ... | @@ -5833,7 +5843,7 @@ fn getData() !u32 { |
| 5833 | } | 5843 | } |
| 5834 | 5844 | ||
| 5835 | fn genFoos(allocator: Allocator, num: usize) ![]Foo { | 5845 | fn genFoos(allocator: Allocator, num: usize) ![]Foo { |
| 5836 | var foos = try allocator.alloc(Foo, num); | 5846 | const foos = try allocator.alloc(Foo, num); |
| 5837 | errdefer allocator.free(foos); | 5847 | errdefer allocator.free(foos); |
| 5838 | 5848 | ||
| 5839 | // Used to track how many foos have been initialized | 5849 | // Used to track how many foos have been initialized |
| ... | @@ -6325,13 +6335,13 @@ test "optional pointers" { | ... | @@ -6325,13 +6335,13 @@ test "optional pointers" { |
| 6325 | </p> | 6335 | </p> |
| 6326 | {#code_begin|test|test_type_coercion#} | 6336 | {#code_begin|test|test_type_coercion#} |
| 6327 | test "type coercion - variable declaration" { | 6337 | test "type coercion - variable declaration" { |
| 6328 | var a: u8 = 1; | 6338 | const a: u8 = 1; |
| 6329 | var b: u16 = a; | 6339 | const b: u16 = a; |
| 6330 | _ = b; | 6340 | _ = b; |
| 6331 | } | 6341 | } |
| 6332 | 6342 | ||
| 6333 | test "type coercion - function call" { | 6343 | test "type coercion - function call" { |
| 6334 | var a: u8 = 1; | 6344 | const a: u8 = 1; |
| 6335 | foo(a); | 6345 | foo(a); |
| 6336 | } | 6346 | } |
| 6337 | 6347 | ||
| ... | @@ -6340,8 +6350,8 @@ fn foo(b: u16) void { | ... | @@ -6340,8 +6350,8 @@ fn foo(b: u16) void { |
| 6340 | } | 6350 | } |
| 6341 | 6351 | ||
| 6342 | test "type coercion - @as builtin" { | 6352 | test "type coercion - @as builtin" { |
| 6343 | var a: u8 = 1; | 6353 | const a: u8 = 1; |
| 6344 | var b = @as(u16, a); | 6354 | const b = @as(u16, a); |
| 6345 | _ = b; | 6355 | _ = b; |
| 6346 | } | 6356 | } |
| 6347 | {#code_end#} | 6357 | {#code_end#} |
| ... | @@ -6366,7 +6376,7 @@ test "type coercion - @as builtin" { | ... | @@ -6366,7 +6376,7 @@ test "type coercion - @as builtin" { |
| 6366 | {#code_begin|test|test_no_op_casts#} | 6376 | {#code_begin|test|test_no_op_casts#} |
| 6367 | test "type coercion - const qualification" { | 6377 | test "type coercion - const qualification" { |
| 6368 | var a: i32 = 1; | 6378 | var a: i32 = 1; |
| 6369 | var b: *i32 = &a; | 6379 | const b: *i32 = &a; |
| 6370 | foo(b); | 6380 | foo(b); |
| 6371 | } | 6381 | } |
| 6372 | 6382 | ||
| ... | @@ -6399,26 +6409,26 @@ const expect = std.testing.expect; | ... | @@ -6399,26 +6409,26 @@ const expect = std.testing.expect; |
| 6399 | const mem = std.mem; | 6409 | const mem = std.mem; |
| 6400 | 6410 | ||
| 6401 | test "integer widening" { | 6411 | test "integer widening" { |
| 6402 | var a: u8 = 250; | 6412 | const a: u8 = 250; |
| 6403 | var b: u16 = a; | 6413 | const b: u16 = a; |
| 6404 | var c: u32 = b; | 6414 | const c: u32 = b; |
| 6405 | var d: u64 = c; | 6415 | const d: u64 = c; |
| 6406 | var e: u64 = d; | 6416 | const e: u64 = d; |
| 6407 | var f: u128 = e; | 6417 | const f: u128 = e; |
| 6408 | try expect(f == a); | 6418 | try expect(f == a); |
| 6409 | } | 6419 | } |
| 6410 | 6420 | ||
| 6411 | test "implicit unsigned integer to signed integer" { | 6421 | test "implicit unsigned integer to signed integer" { |
| 6412 | var a: u8 = 250; | 6422 | const a: u8 = 250; |
| 6413 | var b: i16 = a; | 6423 | const b: i16 = a; |
| 6414 | try expect(b == 250); | 6424 | try expect(b == 250); |
| 6415 | } | 6425 | } |
| 6416 | 6426 | ||
| 6417 | test "float widening" { | 6427 | test "float widening" { |
| 6418 | var a: f16 = 12.34; | 6428 | const a: f16 = 12.34; |
| 6419 | var b: f32 = a; | 6429 | const b: f32 = a; |
| 6420 | var c: f64 = b; | 6430 | const c: f64 = b; |
| 6421 | var d: f128 = c; | 6431 | const d: f128 = c; |
| 6422 | try expect(d == a); | 6432 | try expect(d == a); |
| 6423 | } | 6433 | } |
| 6424 | {#code_end#} | 6434 | {#code_end#} |
| ... | @@ -6435,7 +6445,7 @@ test "float widening" { | ... | @@ -6435,7 +6445,7 @@ test "float widening" { |
| 6435 | {#code_begin|test_err|test_ambiguous_coercion#} | 6445 | {#code_begin|test_err|test_ambiguous_coercion#} |
| 6436 | // Compile time coercion of float to int | 6446 | // Compile time coercion of float to int |
| 6437 | test "implicit cast to comptime_int" { | 6447 | test "implicit cast to comptime_int" { |
| 6438 | var f: f32 = 54.0 / 5; | 6448 | const f: f32 = 54.0 / 5; |
| 6439 | _ = f; | 6449 | _ = f; |
| 6440 | } | 6450 | } |
| 6441 | {#code_end#} | 6451 | {#code_end#} |
| ... | @@ -6449,31 +6459,31 @@ const expect = std.testing.expect; | ... | @@ -6449,31 +6459,31 @@ const expect = std.testing.expect; |
| 6449 | // const modifier on the element type. Useful in particular for | 6459 | // const modifier on the element type. Useful in particular for |
| 6450 | // String literals. | 6460 | // String literals. |
| 6451 | test "*const [N]T to []const T" { | 6461 | test "*const [N]T to []const T" { |
| 6452 | var x1: []const u8 = "hello"; | 6462 | const x1: []const u8 = "hello"; |
| 6453 | var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; | 6463 | const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; |
| 6454 | try expect(std.mem.eql(u8, x1, x2)); | 6464 | try expect(std.mem.eql(u8, x1, x2)); |
| 6455 | 6465 | ||
| 6456 | var y: []const f32 = &[2]f32{ 1.2, 3.4 }; | 6466 | const y: []const f32 = &[2]f32{ 1.2, 3.4 }; |
| 6457 | try expect(y[0] == 1.2); | 6467 | try expect(y[0] == 1.2); |
| 6458 | } | 6468 | } |
| 6459 | 6469 | ||
| 6460 | // Likewise, it works when the destination type is an error union. | 6470 | // Likewise, it works when the destination type is an error union. |
| 6461 | test "*const [N]T to E![]const T" { | 6471 | test "*const [N]T to E![]const T" { |
| 6462 | var x1: anyerror![]const u8 = "hello"; | 6472 | const x1: anyerror![]const u8 = "hello"; |
| 6463 | var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; | 6473 | const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; |
| 6464 | try expect(std.mem.eql(u8, try x1, try x2)); | 6474 | try expect(std.mem.eql(u8, try x1, try x2)); |
| 6465 | 6475 | ||
| 6466 | var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 }; | 6476 | const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 }; |
| 6467 | try expect((try y)[0] == 1.2); | 6477 | try expect((try y)[0] == 1.2); |
| 6468 | } | 6478 | } |
| 6469 | 6479 | ||
| 6470 | // Likewise, it works when the destination type is an optional. | 6480 | // Likewise, it works when the destination type is an optional. |
| 6471 | test "*const [N]T to ?[]const T" { | 6481 | test "*const [N]T to ?[]const T" { |
| 6472 | var x1: ?[]const u8 = "hello"; | 6482 | const x1: ?[]const u8 = "hello"; |
| 6473 | var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; | 6483 | const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; |
| 6474 | try expect(std.mem.eql(u8, x1.?, x2.?)); | 6484 | try expect(std.mem.eql(u8, x1.?, x2.?)); |
| 6475 | 6485 | ||
| 6476 | var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 }; | 6486 | const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 }; |
| 6477 | try expect(y.?[0] == 1.2); | 6487 | try expect(y.?[0] == 1.2); |
| 6478 | } | 6488 | } |
| 6479 | 6489 | ||
| ... | @@ -6609,18 +6619,18 @@ const U2 = union(enum) { | ... | @@ -6609,18 +6619,18 @@ const U2 = union(enum) { |
| 6609 | }; | 6619 | }; |
| 6610 | 6620 | ||
| 6611 | test "coercion between unions and enums" { | 6621 | test "coercion between unions and enums" { |
| 6612 | var u = U{ .two = 12.34 }; | 6622 | const u = U{ .two = 12.34 }; |
| 6613 | var e: E = u; // coerce union to enum | 6623 | const e: E = u; // coerce union to enum |
| 6614 | try expect(e == E.two); | 6624 | try expect(e == E.two); |
| 6615 | 6625 | ||
| 6616 | const three = E.three; | 6626 | const three = E.three; |
| 6617 | var u_2: U = three; // coerce enum to union | 6627 | const u_2: U = three; // coerce enum to union |
| 6618 | try expect(u_2 == E.three); | 6628 | try expect(u_2 == E.three); |
| 6619 | 6629 | ||
| 6620 | var u_3: U = .three; // coerce enum literal to union | 6630 | const u_3: U = .three; // coerce enum literal to union |
| 6621 | try expect(u_3 == E.three); | 6631 | try expect(u_3 == E.three); |
| 6622 | 6632 | ||
| 6623 | var u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type. | 6633 | const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type. |
| 6624 | try expect(u_4.tag() == 1); | 6634 | try expect(u_4.tag() == 1); |
| 6625 | 6635 | ||
| 6626 | // The following example is invalid. | 6636 | // The following example is invalid. |
| ... | @@ -6698,9 +6708,9 @@ const expect = std.testing.expect; | ... | @@ -6698,9 +6708,9 @@ const expect = std.testing.expect; |
| 6698 | const mem = std.mem; | 6708 | const mem = std.mem; |
| 6699 | 6709 | ||
| 6700 | test "peer resolve int widening" { | 6710 | test "peer resolve int widening" { |
| 6701 | var a: i8 = 12; | 6711 | const a: i8 = 12; |
| 6702 | var b: i16 = 34; | 6712 | const b: i16 = 34; |
| 6703 | var c = a + b; | 6713 | const c = a + b; |
| 6704 | try expect(c == 46); | 6714 | try expect(c == 46); |
| 6705 | try expect(@TypeOf(c) == i16); | 6715 | try expect(@TypeOf(c) == i16); |
| 6706 | } | 6716 | } |
| ... | @@ -6809,6 +6819,7 @@ export fn entry() void { | ... | @@ -6809,6 +6819,7 @@ export fn entry() void { |
| 6809 | var x: void = {}; | 6819 | var x: void = {}; |
| 6810 | var y: void = {}; | 6820 | var y: void = {}; |
| 6811 | x = y; | 6821 | x = y; |
| 6822 | y = x; | ||
| 6812 | } | 6823 | } |
| 6813 | {#code_end#} | 6824 | {#code_end#} |
| 6814 | <p>When this turns into machine code, there is no code generated in the | 6825 | <p>When this turns into machine code, there is no code generated in the |
| ... | @@ -7121,6 +7132,7 @@ fn performFn(start_value: i32) i32 { | ... | @@ -7121,6 +7132,7 @@ fn performFn(start_value: i32) i32 { |
| 7121 | // expect(performFn('w', 99) == 99); | 7132 | // expect(performFn('w', 99) == 99); |
| 7122 | fn performFn(start_value: i32) i32 { | 7133 | fn performFn(start_value: i32) i32 { |
| 7123 | var result: i32 = start_value; | 7134 | var result: i32 = start_value; |
| 7135 | _ = &result; | ||
| 7124 | return result; | 7136 | return result; |
| 7125 | } | 7137 | } |
| 7126 | {#end_syntax_block#} | 7138 | {#end_syntax_block#} |
| ... | @@ -8664,8 +8676,9 @@ test "@hasDecl" { | ... | @@ -8664,8 +8676,9 @@ test "@hasDecl" { |
| 8664 | </p> | 8676 | </p> |
| 8665 | {#code_begin|test_err|test_intCast_builtin|cast truncated bits#} | 8677 | {#code_begin|test_err|test_intCast_builtin|cast truncated bits#} |
| 8666 | test "integer cast panic" { | 8678 | test "integer cast panic" { |
| 8667 | var a: u16 = 0xabcd; | 8679 | var a: u16 = 0xabcd; // runtime-known |
| 8668 | var b: u8 = @intCast(a); | 8680 | _ = &a; |
| 8681 | const b: u8 = @intCast(a); | ||
| 8669 | _ = b; | 8682 | _ = b; |
| 8670 | } | 8683 | } |
| 8671 | {#code_end#} | 8684 | {#code_end#} |
| ... | @@ -8825,7 +8838,7 @@ const expect = std.testing.expect; | ... | @@ -8825,7 +8838,7 @@ const expect = std.testing.expect; |
| 8825 | test "@wasmMemoryGrow" { | 8838 | test "@wasmMemoryGrow" { |
| 8826 | if (native_arch != .wasm32) return error.SkipZigTest; | 8839 | if (native_arch != .wasm32) return error.SkipZigTest; |
| 8827 | 8840 | ||
| 8828 | var prev = @wasmMemorySize(0); | 8841 | const prev = @wasmMemorySize(0); |
| 8829 | try expect(prev == @wasmMemoryGrow(0, 1)); | 8842 | try expect(prev == @wasmMemoryGrow(0, 1)); |
| 8830 | try expect(prev + 1 == @wasmMemorySize(0)); | 8843 | try expect(prev + 1 == @wasmMemorySize(0)); |
| 8831 | } | 8844 | } |
| ... | @@ -9560,8 +9573,8 @@ const std = @import("std"); | ... | @@ -9560,8 +9573,8 @@ const std = @import("std"); |
| 9560 | const expect = std.testing.expect; | 9573 | const expect = std.testing.expect; |
| 9561 | 9574 | ||
| 9562 | test "integer truncation" { | 9575 | test "integer truncation" { |
| 9563 | var a: u16 = 0xabcd; | 9576 | const a: u16 = 0xabcd; |
| 9564 | var b: u8 = @truncate(a); | 9577 | const b: u8 = @truncate(a); |
| 9565 | try expect(b == 0xcd); | 9578 | try expect(b == 0xcd); |
| 9566 | } | 9579 | } |
| 9567 | {#code_end#} | 9580 | {#code_end#} |
| ... | @@ -9845,7 +9858,7 @@ comptime { | ... | @@ -9845,7 +9858,7 @@ comptime { |
| 9845 | <p>At runtime:</p> | 9858 | <p>At runtime:</p> |
| 9846 | {#code_begin|exe_err|runtime_index_out_of_bounds#} | 9859 | {#code_begin|exe_err|runtime_index_out_of_bounds#} |
| 9847 | pub fn main() void { | 9860 | pub fn main() void { |
| 9848 | var x = foo("hello"); | 9861 | const x = foo("hello"); |
| 9849 | _ = x; | 9862 | _ = x; |
| 9850 | } | 9863 | } |
| 9851 | 9864 | ||
| ... | @@ -9858,7 +9871,7 @@ fn foo(x: []const u8) u8 { | ... | @@ -9858,7 +9871,7 @@ fn foo(x: []const u8) u8 { |
| 9858 | <p>At compile-time:</p> | 9871 | <p>At compile-time:</p> |
| 9859 | {#code_begin|test_err|test_comptime_invalid_cast|type 'u32' cannot represent integer value '-1'#} | 9872 | {#code_begin|test_err|test_comptime_invalid_cast|type 'u32' cannot represent integer value '-1'#} |
| 9860 | comptime { | 9873 | comptime { |
| 9861 | var value: i32 = -1; | 9874 | const value: i32 = -1; |
| 9862 | const unsigned: u32 = @intCast(value); | 9875 | const unsigned: u32 = @intCast(value); |
| 9863 | _ = unsigned; | 9876 | _ = unsigned; |
| 9864 | } | 9877 | } |
| ... | @@ -9868,8 +9881,9 @@ comptime { | ... | @@ -9868,8 +9881,9 @@ comptime { |
| 9868 | const std = @import("std"); | 9881 | const std = @import("std"); |
| 9869 | 9882 | ||
| 9870 | pub fn main() void { | 9883 | pub fn main() void { |
| 9871 | var value: i32 = -1; | 9884 | var value: i32 = -1; // runtime-known |
| 9872 | var unsigned: u32 = @intCast(value); | 9885 | _ = &value; |
| 9886 | const unsigned: u32 = @intCast(value); | ||
| 9873 | std.debug.print("value: {}\n", .{unsigned}); | 9887 | std.debug.print("value: {}\n", .{unsigned}); |
| 9874 | } | 9888 | } |
| 9875 | {#code_end#} | 9889 | {#code_end#} |
| ... | @@ -9891,7 +9905,8 @@ comptime { | ... | @@ -9891,7 +9905,8 @@ comptime { |
| 9891 | const std = @import("std"); | 9905 | const std = @import("std"); |
| 9892 | 9906 | ||
| 9893 | pub fn main() void { | 9907 | pub fn main() void { |
| 9894 | var spartan_count: u16 = 300; | 9908 | var spartan_count: u16 = 300; // runtime-known |
| 9909 | _ = &spartan_count; | ||
| 9895 | const byte: u8 = @intCast(spartan_count); | 9910 | const byte: u8 = @intCast(spartan_count); |
| 9896 | std.debug.print("value: {}\n", .{byte}); | 9911 | std.debug.print("value: {}\n", .{byte}); |
| 9897 | } | 9912 | } |
| ... | @@ -9975,7 +9990,7 @@ pub fn main() !void { | ... | @@ -9975,7 +9990,7 @@ pub fn main() !void { |
| 9975 | {#code_begin|exe|addWithOverflow_builtin#} | 9990 | {#code_begin|exe|addWithOverflow_builtin#} |
| 9976 | const print = @import("std").debug.print; | 9991 | const print = @import("std").debug.print; |
| 9977 | pub fn main() void { | 9992 | pub fn main() void { |
| 9978 | var byte: u8 = 255; | 9993 | const byte: u8 = 255; |
| 9979 | 9994 | ||
| 9980 | const ov = @addWithOverflow(byte, 10); | 9995 | const ov = @addWithOverflow(byte, 10); |
| 9981 | if (ov[1] != 0) { | 9996 | if (ov[1] != 0) { |
| ... | @@ -10025,8 +10040,9 @@ comptime { | ... | @@ -10025,8 +10040,9 @@ comptime { |
| 10025 | const std = @import("std"); | 10040 | const std = @import("std"); |
| 10026 | 10041 | ||
| 10027 | pub fn main() void { | 10042 | pub fn main() void { |
| 10028 | var x: u8 = 0b01010101; | 10043 | var x: u8 = 0b01010101; // runtime-known |
| 10029 | var y = @shlExact(x, 2); | 10044 | _ = &x; |
| 10045 | const y = @shlExact(x, 2); | ||
| 10030 | std.debug.print("value: {}\n", .{y}); | 10046 | std.debug.print("value: {}\n", .{y}); |
| 10031 | } | 10047 | } |
| 10032 | {#code_end#} | 10048 | {#code_end#} |
| ... | @@ -10044,8 +10060,9 @@ comptime { | ... | @@ -10044,8 +10060,9 @@ comptime { |
| 10044 | const std = @import("std"); | 10060 | const std = @import("std"); |
| 10045 | 10061 | ||
| 10046 | pub fn main() void { | 10062 | pub fn main() void { |
| 10047 | var x: u8 = 0b10101010; | 10063 | var x: u8 = 0b10101010; // runtime-known |
| 10048 | var y = @shrExact(x, 2); | 10064 | _ = &x; |
| 10065 | const y = @shrExact(x, 2); | ||
| 10049 | std.debug.print("value: {}\n", .{y}); | 10066 | std.debug.print("value: {}\n", .{y}); |
| 10050 | } | 10067 | } |
| 10051 | {#code_end#} | 10068 | {#code_end#} |
| ... | @@ -10067,7 +10084,8 @@ const std = @import("std"); | ... | @@ -10067,7 +10084,8 @@ const std = @import("std"); |
| 10067 | pub fn main() void { | 10084 | pub fn main() void { |
| 10068 | var a: u32 = 1; | 10085 | var a: u32 = 1; |
| 10069 | var b: u32 = 0; | 10086 | var b: u32 = 0; |
| 10070 | var c = a / b; | 10087 | _ = .{ &a, &b }; |
| 10088 | const c = a / b; | ||
| 10071 | std.debug.print("value: {}\n", .{c}); | 10089 | std.debug.print("value: {}\n", .{c}); |
| 10072 | } | 10090 | } |
| 10073 | {#code_end#} | 10091 | {#code_end#} |
| ... | @@ -10089,7 +10107,8 @@ const std = @import("std"); | ... | @@ -10089,7 +10107,8 @@ const std = @import("std"); |
| 10089 | pub fn main() void { | 10107 | pub fn main() void { |
| 10090 | var a: u32 = 10; | 10108 | var a: u32 = 10; |
| 10091 | var b: u32 = 0; | 10109 | var b: u32 = 0; |
| 10092 | var c = a % b; | 10110 | _ = .{ &a, &b }; |
| 10111 | const c = a % b; | ||
| 10093 | std.debug.print("value: {}\n", .{c}); | 10112 | std.debug.print("value: {}\n", .{c}); |
| 10094 | } | 10113 | } |
| 10095 | {#code_end#} | 10114 | {#code_end#} |
| ... | @@ -10111,7 +10130,8 @@ const std = @import("std"); | ... | @@ -10111,7 +10130,8 @@ const std = @import("std"); |
| 10111 | pub fn main() void { | 10130 | pub fn main() void { |
| 10112 | var a: u32 = 10; | 10131 | var a: u32 = 10; |
| 10113 | var b: u32 = 3; | 10132 | var b: u32 = 3; |
| 10114 | var c = @divExact(a, b); | 10133 | _ = .{ &a, &b }; |
| 10134 | const c = @divExact(a, b); | ||
| 10115 | std.debug.print("value: {}\n", .{c}); | 10135 | std.debug.print("value: {}\n", .{c}); |
| 10116 | } | 10136 | } |
| 10117 | {#code_end#} | 10137 | {#code_end#} |
| ... | @@ -10131,7 +10151,8 @@ const std = @import("std"); | ... | @@ -10131,7 +10151,8 @@ const std = @import("std"); |
| 10131 | 10151 | ||
| 10132 | pub fn main() void { | 10152 | pub fn main() void { |
| 10133 | var optional_number: ?i32 = null; | 10153 | var optional_number: ?i32 = null; |
| 10134 | var number = optional_number.?; | 10154 | _ = &optional_number; |
| 10155 | const number = optional_number.?; | ||
| 10135 | std.debug.print("value: {}\n", .{number}); | 10156 | std.debug.print("value: {}\n", .{number}); |
| 10136 | } | 10157 | } |
| 10137 | {#code_end#} | 10158 | {#code_end#} |
| ... | @@ -10212,9 +10233,10 @@ comptime { | ... | @@ -10212,9 +10233,10 @@ comptime { |
| 10212 | const std = @import("std"); | 10233 | const std = @import("std"); |
| 10213 | 10234 | ||
| 10214 | pub fn main() void { | 10235 | pub fn main() void { |
| 10215 | var err = error.AnError; | 10236 | const err = error.AnError; |
| 10216 | var number = @intFromError(err) + 500; | 10237 | var number = @intFromError(err) + 500; |
| 10217 | var invalid_err = @errorFromInt(number); | 10238 | _ = &number; |
| 10239 | const invalid_err = @errorFromInt(number); | ||
| 10218 | std.debug.print("value: {}\n", .{invalid_err}); | 10240 | std.debug.print("value: {}\n", .{invalid_err}); |
| 10219 | } | 10241 | } |
| 10220 | {#code_end#} | 10242 | {#code_end#} |
| ... | @@ -10245,7 +10267,8 @@ const Foo = enum { | ... | @@ -10245,7 +10267,8 @@ const Foo = enum { |
| 10245 | 10267 | ||
| 10246 | pub fn main() void { | 10268 | pub fn main() void { |
| 10247 | var a: u2 = 3; | 10269 | var a: u2 = 3; |
| 10248 | var b: Foo = @enumFromInt(a); | 10270 | _ = &a; |
| 10271 | const b: Foo = @enumFromInt(a); | ||
| 10249 | std.debug.print("value: {s}\n", .{@tagName(b)}); | 10272 | std.debug.print("value: {s}\n", .{@tagName(b)}); |
| 10250 | } | 10273 | } |
| 10251 | {#code_end#} | 10274 | {#code_end#} |
| ... | @@ -10402,17 +10425,18 @@ fn bar(f: *Foo) void { | ... | @@ -10402,17 +10425,18 @@ fn bar(f: *Foo) void { |
| 10402 | <p>At compile-time:</p> | 10425 | <p>At compile-time:</p> |
| 10403 | {#code_begin|test_err|test_comptime_out_of_bounds_float_to_integer_cast|float value '4294967296' cannot be stored in integer type 'i32'#} | 10426 | {#code_begin|test_err|test_comptime_out_of_bounds_float_to_integer_cast|float value '4294967296' cannot be stored in integer type 'i32'#} |
| 10404 | comptime { | 10427 | comptime { |
| 10405 | 	const float: f32 = 4294967296; | 10428 | const float: f32 = 4294967296; |
| 10406 | 	const int: i32 = @intFromFloat(float); | 10429 | const int: i32 = @intFromFloat(float); |
| 10407 | 	_ = int; | 10430 | _ = int; |
| 10408 | } | 10431 | } |
| 10409 | {#code_end#} | 10432 | {#code_end#} |
| 10410 | <p>At runtime:</p> | 10433 | <p>At runtime:</p> |
| 10411 | {#code_begin|exe_err|runtime_out_of_bounds_float_to_integer_cast#} | 10434 | {#code_begin|exe_err|runtime_out_of_bounds_float_to_integer_cast#} |
| 10412 | pub fn main() void { | 10435 | pub fn main() void { |
| 10413 | 	var float: f32 = 4294967296; | 10436 | var float: f32 = 4294967296; // runtime-known |
| 10414 | 	var int: i32 = @intFromFloat(float); | 10437 | _ = &float; |
| 10415 | 	_ = int; | 10438 | const int: i32 = @intFromFloat(float); |
| 10439 | _ = int; | ||
| 10416 | } | 10440 | } |
| 10417 | {#code_end#} | 10441 | {#code_end#} |
| 10418 | {#header_close#} | 10442 | {#header_close#} |
| ... | @@ -10435,7 +10459,8 @@ comptime { | ... | @@ -10435,7 +10459,8 @@ comptime { |
| 10435 | {#code_begin|exe_err|runtime_invalid_null_pointer_cast#} | 10459 | {#code_begin|exe_err|runtime_invalid_null_pointer_cast#} |
| 10436 | pub fn main() void { | 10460 | pub fn main() void { |
| 10437 | var opt_ptr: ?*i32 = null; | 10461 | var opt_ptr: ?*i32 = null; |
| 10438 | var ptr: *i32 = @ptrCast(opt_ptr); | 10462 | _ = &opt_ptr; |
| 10463 | const ptr: *i32 = @ptrCast(opt_ptr); | ||
| 10439 | _ = ptr; | 10464 | _ = ptr; |
| 10440 | } | 10465 | } |
| 10441 | {#code_end#} | 10466 | {#code_end#} |
| ... | @@ -11120,7 +11145,9 @@ int foo(void) { | ... | @@ -11120,7 +11145,9 @@ int foo(void) { |
| 11120 | {#code_begin|syntax|macro#} | 11145 | {#code_begin|syntax|macro#} |
| 11121 | pub export fn foo() c_int { | 11146 | pub export fn foo() c_int { |
| 11122 | var a: c_int = 1; | 11147 | var a: c_int = 1; |
| 11148 | _ = &a; | ||
| 11123 | var b: c_int = 2; | 11149 | var b: c_int = 2; |
| 11150 | _ = &b; | ||
| 11124 | return a + b; | 11151 | return a + b; |
| 11125 | } | 11152 | } |
| 11126 | pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected token .Equal"); // macro.c:1:9 | 11153 | pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected token .Equal"); // macro.c:1:9 |
lib/build_runner.zig+1-1| ... | @@ -24,7 +24,7 @@ pub fn main() !void { | ... | @@ -24,7 +24,7 @@ pub fn main() !void { |
| 24 | }; | 24 | }; |
| 25 | const arena = thread_safe_arena.allocator(); | 25 | const arena = thread_safe_arena.allocator(); |
| 26 | 26 | ||
| 27 | var args = try process.argsAlloc(arena); | 27 | const args = try process.argsAlloc(arena); |
| 28 | 28 | ||
| 29 | // skip my own exe name | 29 | // skip my own exe name |
| 30 | var arg_idx: usize = 1; | 30 | var arg_idx: usize = 1; |
lib/compiler_rt/absvdi2_test.zig+1-1| ... | @@ -3,7 +3,7 @@ const testing = @import("std").testing; | ... | @@ -3,7 +3,7 @@ const testing = @import("std").testing; |
| 3 | const __absvdi2 = @import("absvdi2.zig").__absvdi2; | 3 | const __absvdi2 = @import("absvdi2.zig").__absvdi2; |
| 4 | 4 | ||
| 5 | fn test__absvdi2(a: i64, expected: i64) !void { | 5 | fn test__absvdi2(a: i64, expected: i64) !void { |
| 6 | var result = __absvdi2(a); | 6 | const result = __absvdi2(a); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/absvsi2_test.zig+1-1| ... | @@ -3,7 +3,7 @@ const testing = @import("std").testing; | ... | @@ -3,7 +3,7 @@ const testing = @import("std").testing; |
| 3 | const __absvsi2 = @import("absvsi2.zig").__absvsi2; | 3 | const __absvsi2 = @import("absvsi2.zig").__absvsi2; |
| 4 | 4 | ||
| 5 | fn test__absvsi2(a: i32, expected: i32) !void { | 5 | fn test__absvsi2(a: i32, expected: i32) !void { |
| 6 | var result = __absvsi2(a); | 6 | const result = __absvsi2(a); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/absvti2_test.zig+1-1| ... | @@ -3,7 +3,7 @@ const testing = @import("std").testing; | ... | @@ -3,7 +3,7 @@ const testing = @import("std").testing; |
| 3 | const __absvti2 = @import("absvti2.zig").__absvti2; | 3 | const __absvti2 = @import("absvti2.zig").__absvti2; |
| 4 | 4 | ||
| 5 | fn test__absvti2(a: i128, expected: i128) !void { | 5 | fn test__absvti2(a: i128, expected: i128) !void { |
| 6 | var result = __absvti2(a); | 6 | const result = __absvti2(a); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/addo.zig+1-1| ... | @@ -18,7 +18,7 @@ comptime { | ... | @@ -18,7 +18,7 @@ comptime { |
| 18 | inline fn addoXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { | 18 | inline fn addoXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { |
| 19 | @setRuntimeSafety(builtin.is_test); | 19 | @setRuntimeSafety(builtin.is_test); |
| 20 | overflow.* = 0; | 20 | overflow.* = 0; |
| 21 | var sum: ST = a +% b; | 21 | const sum: ST = a +% b; |
| 22 | // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract | 22 | // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract |
| 23 | // Let sum = a +% b == a + b + carry == wraparound addition. | 23 | // Let sum = a +% b == a + b + carry == wraparound addition. |
| 24 | // Overflow in a+b+carry occurs, iff a and b have opposite signs | 24 | // Overflow in a+b+carry occurs, iff a and b have opposite signs |
lib/compiler_rt/addodi4_test.zig+2-2| ... | @@ -6,8 +6,8 @@ const math = std.math; | ... | @@ -6,8 +6,8 @@ const math = std.math; |
| 6 | fn test__addodi4(a: i64, b: i64) !void { | 6 | fn test__addodi4(a: i64, b: i64) !void { |
| 7 | var result_ov: c_int = undefined; | 7 | var result_ov: c_int = undefined; |
| 8 | var expected_ov: c_int = undefined; | 8 | var expected_ov: c_int = undefined; |
| 9 | var result = addv.__addodi4(a, b, &result_ov); | 9 | const result = addv.__addodi4(a, b, &result_ov); |
| 10 | var expected: i64 = simple_addodi4(a, b, &expected_ov); | 10 | const expected: i64 = simple_addodi4(a, b, &expected_ov); |
| 11 | try testing.expectEqual(expected, result); | 11 | try testing.expectEqual(expected, result); |
| 12 | try testing.expectEqual(expected_ov, result_ov); | 12 | try testing.expectEqual(expected_ov, result_ov); |
| 13 | } | 13 | } |
lib/compiler_rt/addosi4_test.zig+2-2| ... | @@ -4,8 +4,8 @@ const testing = @import("std").testing; | ... | @@ -4,8 +4,8 @@ const testing = @import("std").testing; |
| 4 | fn test__addosi4(a: i32, b: i32) !void { | 4 | fn test__addosi4(a: i32, b: i32) !void { |
| 5 | var result_ov: c_int = undefined; | 5 | var result_ov: c_int = undefined; |
| 6 | var expected_ov: c_int = undefined; | 6 | var expected_ov: c_int = undefined; |
| 7 | var result = addv.__addosi4(a, b, &result_ov); | 7 | const result = addv.__addosi4(a, b, &result_ov); |
| 8 | var expected: i32 = simple_addosi4(a, b, &expected_ov); | 8 | const expected: i32 = simple_addosi4(a, b, &expected_ov); |
| 9 | try testing.expectEqual(expected, result); | 9 | try testing.expectEqual(expected, result); |
| 10 | try testing.expectEqual(expected_ov, result_ov); | 10 | try testing.expectEqual(expected_ov, result_ov); |
| 11 | } | 11 | } |
lib/compiler_rt/addoti4_test.zig+2-2| ... | @@ -6,8 +6,8 @@ const math = std.math; | ... | @@ -6,8 +6,8 @@ const math = std.math; |
| 6 | fn test__addoti4(a: i128, b: i128) !void { | 6 | fn test__addoti4(a: i128, b: i128) !void { |
| 7 | var result_ov: c_int = undefined; | 7 | var result_ov: c_int = undefined; |
| 8 | var expected_ov: c_int = undefined; | 8 | var expected_ov: c_int = undefined; |
| 9 | var result = addv.__addoti4(a, b, &result_ov); | 9 | const result = addv.__addoti4(a, b, &result_ov); |
| 10 | var expected: i128 = simple_addoti4(a, b, &expected_ov); | 10 | const expected: i128 = simple_addoti4(a, b, &expected_ov); |
| 11 | try testing.expectEqual(expected, result); | 11 | try testing.expectEqual(expected, result); |
| 12 | try testing.expectEqual(expected_ov, result_ov); | 12 | try testing.expectEqual(expected_ov, result_ov); |
| 13 | } | 13 | } |
lib/compiler_rt/bswapdi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); | ... | @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__bswapdi2(a: u64, expected: u64) !void { | 4 | fn test__bswapdi2(a: u64, expected: u64) !void { |
| 5 | var result = bswap.__bswapdi2(a); | 5 | const result = bswap.__bswapdi2(a); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/bswapsi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); | ... | @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__bswapsi2(a: u32, expected: u32) !void { | 4 | fn test__bswapsi2(a: u32, expected: u32) !void { |
| 5 | var result = bswap.__bswapsi2(a); | 5 | const result = bswap.__bswapsi2(a); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/bswapti2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); | ... | @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__bswapti2(a: u128, expected: u128) !void { | 4 | fn test__bswapti2(a: u128, expected: u128) !void { |
| 5 | var result = bswap.__bswapti2(a); | 5 | const result = bswap.__bswapti2(a); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/ceil.zig+1-1| ... | @@ -32,7 +32,7 @@ pub fn __ceilh(x: f16) callconv(.C) f16 { | ... | @@ -32,7 +32,7 @@ pub fn __ceilh(x: f16) callconv(.C) f16 { |
| 32 | 32 | ||
| 33 | pub fn ceilf(x: f32) callconv(.C) f32 { | 33 | pub fn ceilf(x: f32) callconv(.C) f32 { |
| 34 | var u: u32 = @bitCast(x); | 34 | var u: u32 = @bitCast(x); |
| 35 | var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; | 35 | const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; |
| 36 | var m: u32 = undefined; | 36 | var m: u32 = undefined; |
| 37 | 37 | ||
| 38 | // TODO: Shouldn't need this explicit check. | 38 | // TODO: Shouldn't need this explicit check. |
lib/compiler_rt/clzdi2_test.zig+2-2| ... | @@ -2,8 +2,8 @@ const clz = @import("count0bits.zig"); | ... | @@ -2,8 +2,8 @@ const clz = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__clzdi2(a: u64, expected: i64) !void { | 4 | fn test__clzdi2(a: u64, expected: i64) !void { |
| 5 | var x: i64 = @bitCast(a); | 5 | const x: i64 = @bitCast(a); |
| 6 | var result = clz.__clzdi2(x); | 6 | const result = clz.__clzdi2(x); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/clzti2_test.zig+2-2| ... | @@ -2,8 +2,8 @@ const clz = @import("count0bits.zig"); | ... | @@ -2,8 +2,8 @@ const clz = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__clzti2(a: u128, expected: i64) !void { | 4 | fn test__clzti2(a: u128, expected: i64) !void { |
| 5 | var x: i128 = @bitCast(a); | 5 | const x: i128 = @bitCast(a); |
| 6 | var result = clz.__clzti2(x); | 6 | const result = clz.__clzti2(x); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/cmpdi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); | ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__cmpdi2(a: i64, b: i64, expected: i64) !void { | 4 | fn test__cmpdi2(a: i64, b: i64, expected: i64) !void { |
| 5 | var result = cmp.__cmpdi2(a, b); | 5 | const result = cmp.__cmpdi2(a, b); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/cmpsi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); | ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__cmpsi2(a: i32, b: i32, expected: i32) !void { | 4 | fn test__cmpsi2(a: i32, b: i32, expected: i32) !void { |
| 5 | var result = cmp.__cmpsi2(a, b); | 5 | const result = cmp.__cmpsi2(a, b); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/cmpti2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); | ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__cmpti2(a: i128, b: i128, expected: i128) !void { | 4 | fn test__cmpti2(a: i128, b: i128, expected: i128) !void { |
| 5 | var result = cmp.__cmpti2(a, b); | 5 | const result = cmp.__cmpti2(a, b); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/ctzdi2_test.zig+2-2| ... | @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); | ... | @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ctzdi2(a: u64, expected: i32) !void { | 4 | fn test__ctzdi2(a: u64, expected: i32) !void { |
| 5 | var x: i64 = @bitCast(a); | 5 | const x: i64 = @bitCast(a); |
| 6 | var result = ctz.__ctzdi2(x); | 6 | const result = ctz.__ctzdi2(x); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/ctzsi2_test.zig+2-2| ... | @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); | ... | @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ctzsi2(a: u32, expected: i32) !void { | 4 | fn test__ctzsi2(a: u32, expected: i32) !void { |
| 5 | var x: i32 = @bitCast(a); | 5 | const x: i32 = @bitCast(a); |
| 6 | var result = ctz.__ctzsi2(x); | 6 | const result = ctz.__ctzsi2(x); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/ctzti2_test.zig+2-2| ... | @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); | ... | @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ctzti2(a: u128, expected: i32) !void { | 4 | fn test__ctzti2(a: u128, expected: i32) !void { |
| 5 | var x: i128 = @bitCast(a); | 5 | const x: i128 = @bitCast(a); |
| 6 | var result = ctz.__ctzti2(x); | 6 | const result = ctz.__ctzti2(x); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/divc3_test.zig+20-20| ... | @@ -19,20 +19,20 @@ test { | ... | @@ -19,20 +19,20 @@ test { |
| 19 | 19 | ||
| 20 | fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void { | 20 | fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void { |
| 21 | { | 21 | { |
| 22 | var a: T = 1.0; | 22 | const a: T = 1.0; |
| 23 | var b: T = 0.0; | 23 | const b: T = 0.0; |
| 24 | var c: T = -1.0; | 24 | const c: T = -1.0; |
| 25 | var d: T = 0.0; | 25 | const d: T = 0.0; |
| 26 | 26 | ||
| 27 | const result = f(a, b, c, d); | 27 | const result = f(a, b, c, d); |
| 28 | try expect(result.real == -1.0); | 28 | try expect(result.real == -1.0); |
| 29 | try expect(result.imag == 0.0); | 29 | try expect(result.imag == 0.0); |
| 30 | } | 30 | } |
| 31 | { | 31 | { |
| 32 | var a: T = 1.0; | 32 | const a: T = 1.0; |
| 33 | var b: T = 0.0; | 33 | const b: T = 0.0; |
| 34 | var c: T = -4.0; | 34 | const c: T = -4.0; |
| 35 | var d: T = 0.0; | 35 | const d: T = 0.0; |
| 36 | 36 | ||
| 37 | const result = f(a, b, c, d); | 37 | const result = f(a, b, c, d); |
| 38 | try expect(result.real == -0.25); | 38 | try expect(result.real == -0.25); |
| ... | @@ -41,10 +41,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) | ... | @@ -41,10 +41,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) |
| 41 | { | 41 | { |
| 42 | // if the first operand is an infinity and the second operand is a finite number, then the | 42 | // if the first operand is an infinity and the second operand is a finite number, then the |
| 43 | // result of the / operator is an infinity; | 43 | // result of the / operator is an infinity; |
| 44 | var a: T = -math.inf(T); | 44 | const a: T = -math.inf(T); |
| 45 | var b: T = 0.0; | 45 | const b: T = 0.0; |
| 46 | var c: T = -4.0; | 46 | const c: T = -4.0; |
| 47 | var d: T = 1.0; | 47 | const d: T = 1.0; |
| 48 | 48 | ||
| 49 | const result = f(a, b, c, d); | 49 | const result = f(a, b, c, d); |
| 50 | try expect(result.real == math.inf(T)); | 50 | try expect(result.real == math.inf(T)); |
| ... | @@ -53,10 +53,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) | ... | @@ -53,10 +53,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) |
| 53 | { | 53 | { |
| 54 | // if the first operand is a finite number and the second operand is an infinity, then the | 54 | // if the first operand is a finite number and the second operand is an infinity, then the |
| 55 | // result of the / operator is a zero; | 55 | // result of the / operator is a zero; |
| 56 | var a: T = 17.2; | 56 | const a: T = 17.2; |
| 57 | var b: T = 0.0; | 57 | const b: T = 0.0; |
| 58 | var c: T = -math.inf(T); | 58 | const c: T = -math.inf(T); |
| 59 | var d: T = 0.0; | 59 | const d: T = 0.0; |
| 60 | 60 | ||
| 61 | const result = f(a, b, c, d); | 61 | const result = f(a, b, c, d); |
| 62 | try expect(result.real == -0.0); | 62 | try expect(result.real == -0.0); |
| ... | @@ -65,10 +65,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) | ... | @@ -65,10 +65,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) |
| 65 | { | 65 | { |
| 66 | // if the first operand is a nonzero finite number or an infinity and the second operand is | 66 | // if the first operand is a nonzero finite number or an infinity and the second operand is |
| 67 | // a zero, then the result of the / operator is an infinity | 67 | // a zero, then the result of the / operator is an infinity |
| 68 | var a: T = 1.1; | 68 | const a: T = 1.1; |
| 69 | var b: T = 0.1; | 69 | const b: T = 0.1; |
| 70 | var c: T = 0.0; | 70 | const c: T = 0.0; |
| 71 | var d: T = 0.0; | 71 | const d: T = 0.0; |
| 72 | 72 | ||
| 73 | const result = f(a, b, c, d); | 73 | const result = f(a, b, c, d); |
| 74 | try expect(result.real == math.inf(T)); | 74 | try expect(result.real == math.inf(T)); |
lib/compiler_rt/divxf3.zig+2-2| ... | @@ -162,7 +162,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -162,7 +162,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 162 | // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0). | 162 | // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0). |
| 163 | // Right shift the quotient if it falls in the [1,2) range and adjust the | 163 | // Right shift the quotient if it falls in the [1,2) range and adjust the |
| 164 | // exponent accordingly. | 164 | // exponent accordingly. |
| 165 | var quotient: u64 = if (quotient128 < (integerBit << 1)) b: { | 165 | const quotient: u64 = if (quotient128 < (integerBit << 1)) b: { |
| 166 | quotientExponent -= 1; | 166 | quotientExponent -= 1; |
| 167 | break :b @intCast(quotient128); | 167 | break :b @intCast(quotient128); |
| 168 | } else @intCast(quotient128 >> 1); | 168 | } else @intCast(quotient128 >> 1); |
| ... | @@ -177,7 +177,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -177,7 +177,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 177 | // | 177 | // |
| 178 | // If r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we | 178 | // If r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we |
| 179 | // already have the correct result. The exact halfway case cannot occur. | 179 | // already have the correct result. The exact halfway case cannot occur. |
| 180 | var residual: u64 = -%(quotient *% q63b); | 180 | const residual: u64 = -%(quotient *% q63b); |
| 181 | 181 | ||
| 182 | const writtenExponent = quotientExponent + exponentBias; | 182 | const writtenExponent = quotientExponent + exponentBias; |
| 183 | if (writtenExponent >= maxExponent) { | 183 | if (writtenExponent >= maxExponent) { |
lib/compiler_rt/emutls.zig+11-11| ... | @@ -57,8 +57,8 @@ const simple_allocator = struct { | ... | @@ -57,8 +57,8 @@ const simple_allocator = struct { |
| 57 | 57 | ||
| 58 | /// Resize a slice. | 58 | /// Resize a slice. |
| 59 | pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T { | 59 | pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T { |
| 60 | var c_ptr: *anyopaque = @ptrCast(slice.ptr); | 60 | const c_ptr: *anyopaque = @ptrCast(slice.ptr); |
| 61 | var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort())); | 61 | const new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort())); |
| 62 | return new_array[0..len]; | 62 | return new_array[0..len]; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| ... | @@ -78,7 +78,7 @@ const ObjectArray = struct { | ... | @@ -78,7 +78,7 @@ const ObjectArray = struct { |
| 78 | 78 | ||
| 79 | /// create a new ObjectArray with n slots. must call deinit() to deallocate. | 79 | /// create a new ObjectArray with n slots. must call deinit() to deallocate. |
| 80 | pub fn init(n: usize) *ObjectArray { | 80 | pub fn init(n: usize) *ObjectArray { |
| 81 | var array = simple_allocator.alloc(ObjectArray); | 81 | const array = simple_allocator.alloc(ObjectArray); |
| 82 | 82 | ||
| 83 | array.* = ObjectArray{ | 83 | array.* = ObjectArray{ |
| 84 | .slots = simple_allocator.allocSlice(?ObjectPointer, n), | 84 | .slots = simple_allocator.allocSlice(?ObjectPointer, n), |
| ... | @@ -166,7 +166,7 @@ const current_thread_storage = struct { | ... | @@ -166,7 +166,7 @@ const current_thread_storage = struct { |
| 166 | const size = @max(16, index); | 166 | const size = @max(16, index); |
| 167 | 167 | ||
| 168 | // create a new array and store it. | 168 | // create a new array and store it. |
| 169 | var array: *ObjectArray = ObjectArray.init(size); | 169 | const array: *ObjectArray = ObjectArray.init(size); |
| 170 | current_thread_storage.setspecific(array); | 170 | current_thread_storage.setspecific(array); |
| 171 | return array; | 171 | return array; |
| 172 | } | 172 | } |
| ... | @@ -304,13 +304,13 @@ const emutls_control = extern struct { | ... | @@ -304,13 +304,13 @@ const emutls_control = extern struct { |
| 304 | test "simple_allocator" { | 304 | test "simple_allocator" { |
| 305 | if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest; | 305 | if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest; |
| 306 | 306 | ||
| 307 | var data1: *[64]u8 = simple_allocator.alloc([64]u8); | 307 | const data1: *[64]u8 = simple_allocator.alloc([64]u8); |
| 308 | defer simple_allocator.free(data1); | 308 | defer simple_allocator.free(data1); |
| 309 | for (data1) |*c| { | 309 | for (data1) |*c| { |
| 310 | c.* = 0xff; | 310 | c.* = 0xff; |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | var data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64); | 313 | const data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64); |
| 314 | defer simple_allocator.free(data2); | 314 | defer simple_allocator.free(data2); |
| 315 | for (data2[0..63]) |*c| { | 315 | for (data2[0..63]) |*c| { |
| 316 | c.* = 0xff; | 316 | c.* = 0xff; |
| ... | @@ -324,7 +324,7 @@ test "__emutls_get_address zeroed" { | ... | @@ -324,7 +324,7 @@ test "__emutls_get_address zeroed" { |
| 324 | try expect(ctl.object.index == 0); | 324 | try expect(ctl.object.index == 0); |
| 325 | 325 | ||
| 326 | // retrieve a variable from ctl | 326 | // retrieve a variable from ctl |
| 327 | var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); | 327 | const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); |
| 328 | try expect(ctl.object.index != 0); // index has been allocated for this ctl | 328 | try expect(ctl.object.index != 0); // index has been allocated for this ctl |
| 329 | try expect(x.* == 0); // storage has been zeroed | 329 | try expect(x.* == 0); // storage has been zeroed |
| 330 | 330 | ||
| ... | @@ -332,7 +332,7 @@ test "__emutls_get_address zeroed" { | ... | @@ -332,7 +332,7 @@ test "__emutls_get_address zeroed" { |
| 332 | x.* = 1234; | 332 | x.* = 1234; |
| 333 | 333 | ||
| 334 | // retrieve a variable from ctl (same ctl) | 334 | // retrieve a variable from ctl (same ctl) |
| 335 | var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); | 335 | const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); |
| 336 | 336 | ||
| 337 | try expect(y.* == 1234); // same content that x.* | 337 | try expect(y.* == 1234); // same content that x.* |
| 338 | try expect(x == y); // same pointer | 338 | try expect(x == y); // same pointer |
| ... | @@ -345,7 +345,7 @@ test "__emutls_get_address with default_value" { | ... | @@ -345,7 +345,7 @@ test "__emutls_get_address with default_value" { |
| 345 | var ctl = emutls_control.init(usize, &value); | 345 | var ctl = emutls_control.init(usize, &value); |
| 346 | try expect(ctl.object.index == 0); | 346 | try expect(ctl.object.index == 0); |
| 347 | 347 | ||
| 348 | var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); | 348 | const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); |
| 349 | try expect(ctl.object.index != 0); | 349 | try expect(ctl.object.index != 0); |
| 350 | try expect(x.* == 5678); // storage initialized with default value | 350 | try expect(x.* == 5678); // storage initialized with default value |
| 351 | 351 | ||
| ... | @@ -354,7 +354,7 @@ test "__emutls_get_address with default_value" { | ... | @@ -354,7 +354,7 @@ test "__emutls_get_address with default_value" { |
| 354 | 354 | ||
| 355 | try expect(value == 5678); // the default value didn't change | 355 | try expect(value == 5678); // the default value didn't change |
| 356 | 356 | ||
| 357 | var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); | 357 | const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); |
| 358 | try expect(y.* == 9012); // the modified storage persists | 358 | try expect(y.* == 9012); // the modified storage persists |
| 359 | } | 359 | } |
| 360 | 360 | ||
| ... | @@ -364,7 +364,7 @@ test "test default_value with differents sizes" { | ... | @@ -364,7 +364,7 @@ test "test default_value with differents sizes" { |
| 364 | const testType = struct { | 364 | const testType = struct { |
| 365 | fn _testType(comptime T: type, value: T) !void { | 365 | fn _testType(comptime T: type, value: T) !void { |
| 366 | var ctl = emutls_control.init(T, &value); | 366 | var ctl = emutls_control.init(T, &value); |
| 367 | var x = ctl.get_typed_pointer(T); | 367 | const x = ctl.get_typed_pointer(T); |
| 368 | try expect(x.* == value); | 368 | try expect(x.* == value); |
| 369 | } | 369 | } |
| 370 | }._testType; | 370 | }._testType; |
lib/compiler_rt/exp.zig+1-1| ... | @@ -117,7 +117,7 @@ pub fn exp(x_: f64) callconv(.C) f64 { | ... | @@ -117,7 +117,7 @@ pub fn exp(x_: f64) callconv(.C) f64 { |
| 117 | const P5: f64 = 4.13813679705723846039e-08; | 117 | const P5: f64 = 4.13813679705723846039e-08; |
| 118 | 118 | ||
| 119 | var x = x_; | 119 | var x = x_; |
| 120 | var ux: u64 = @bitCast(x); | 120 | const ux: u64 = @bitCast(x); |
| 121 | var hx = ux >> 32; | 121 | var hx = ux >> 32; |
| 122 | const sign: i32 = @intCast(hx >> 31); | 122 | const sign: i32 = @intCast(hx >> 31); |
| 123 | hx &= 0x7FFFFFFF; | 123 | hx &= 0x7FFFFFFF; |
lib/compiler_rt/exp2.zig+1-1| ... | @@ -38,7 +38,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 { | ... | @@ -38,7 +38,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 { |
| 38 | const P3: f32 = 0x1.c6b348p-5; | 38 | const P3: f32 = 0x1.c6b348p-5; |
| 39 | const P4: f32 = 0x1.3b2c9cp-7; | 39 | const P4: f32 = 0x1.3b2c9cp-7; |
| 40 | 40 | ||
| 41 | var u: u32 = @bitCast(x); | 41 | const u: u32 = @bitCast(x); |
| 42 | const ix = u & 0x7FFFFFFF; | 42 | const ix = u & 0x7FFFFFFF; |
| 43 | 43 | ||
| 44 | // |x| > 126 | 44 | // |x| > 126 |
lib/compiler_rt/ffsdi2_test.zig+2-2| ... | @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); | ... | @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ffsdi2(a: u64, expected: i32) !void { | 4 | fn test__ffsdi2(a: u64, expected: i32) !void { |
| 5 | var x = @as(i64, @bitCast(a)); | 5 | const x = @as(i64, @bitCast(a)); |
| 6 | var result = ffs.__ffsdi2(x); | 6 | const result = ffs.__ffsdi2(x); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/ffssi2_test.zig+2-2| ... | @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); | ... | @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ffssi2(a: u32, expected: i32) !void { | 4 | fn test__ffssi2(a: u32, expected: i32) !void { |
| 5 | var x = @as(i32, @bitCast(a)); | 5 | const x = @as(i32, @bitCast(a)); |
| 6 | var result = ffs.__ffssi2(x); | 6 | const result = ffs.__ffssi2(x); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/ffsti2_test.zig+2-2| ... | @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); | ... | @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ffsti2(a: u128, expected: i32) !void { | 4 | fn test__ffsti2(a: u128, expected: i32) !void { |
| 5 | var x = @as(i128, @bitCast(a)); | 5 | const x = @as(i128, @bitCast(a)); |
| 6 | var result = ffs.__ffsti2(x); | 6 | const result = ffs.__ffsti2(x); |
| 7 | try testing.expectEqual(expected, result); | 7 | try testing.expectEqual(expected, result); |
| 8 | } | 8 | } |
| 9 | 9 |
lib/compiler_rt/float_from_int.zig+3-3| ... | @@ -18,12 +18,12 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { | ... | @@ -18,12 +18,12 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { |
| 18 | const max_exp = exp_bias; | 18 | const max_exp = exp_bias; |
| 19 | 19 | ||
| 20 | // Sign | 20 | // Sign |
| 21 | var abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x; | 21 | const abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x; |
| 22 | const sign_bit = if (x < 0) @as(uT, 1) << (float_bits - 1) else 0; | 22 | const sign_bit = if (x < 0) @as(uT, 1) << (float_bits - 1) else 0; |
| 23 | var result: uT = sign_bit; | 23 | var result: uT = sign_bit; |
| 24 | 24 | ||
| 25 | // Compute significand | 25 | // Compute significand |
| 26 | var exp = int_bits - @clz(abs_val) - 1; | 26 | const exp = int_bits - @clz(abs_val) - 1; |
| 27 | if (int_bits <= fractional_bits or exp <= fractional_bits) { | 27 | if (int_bits <= fractional_bits or exp <= fractional_bits) { |
| 28 | const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp)); | 28 | const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp)); |
| 29 | 29 | ||
| ... | @@ -31,7 +31,7 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { | ... | @@ -31,7 +31,7 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { |
| 31 | result = @as(uT, @intCast(abs_val)) << shift_amt; | 31 | result = @as(uT, @intCast(abs_val)) << shift_amt; |
| 32 | result ^= implicit_bit; // Remove implicit integer bit | 32 | result ^= implicit_bit; // Remove implicit integer bit |
| 33 | } else { | 33 | } else { |
| 34 | var shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits); | 34 | const shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits); |
| 35 | const exact_tie: bool = @ctz(abs_val) == shift_amt - 1; | 35 | const exact_tie: bool = @ctz(abs_val) == shift_amt - 1; |
| 36 | 36 | ||
| 37 | // Shift down result and remove implicit integer bit | 37 | // Shift down result and remove implicit integer bit |
lib/compiler_rt/fma.zig+16-16| ... | @@ -59,13 +59,13 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 { | ... | @@ -59,13 +59,13 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 { |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | const x1 = math.frexp(x); | 61 | const x1 = math.frexp(x); |
| 62 | var ex = x1.exponent; | 62 | const ex = x1.exponent; |
| 63 | var xs = x1.significand; | 63 | const xs = x1.significand; |
| 64 | const x2 = math.frexp(y); | 64 | const x2 = math.frexp(y); |
| 65 | var ey = x2.exponent; | 65 | const ey = x2.exponent; |
| 66 | var ys = x2.significand; | 66 | const ys = x2.significand; |
| 67 | const x3 = math.frexp(z); | 67 | const x3 = math.frexp(z); |
| 68 | var ez = x3.exponent; | 68 | const ez = x3.exponent; |
| 69 | var zs = x3.significand; | 69 | var zs = x3.significand; |
| 70 | 70 | ||
| 71 | var spread = ex + ey - ez; | 71 | var spread = ex + ey - ez; |
| ... | @@ -118,13 +118,13 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 { | ... | @@ -118,13 +118,13 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 { |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | const x1 = math.frexp(x); | 120 | const x1 = math.frexp(x); |
| 121 | var ex = x1.exponent; | 121 | const ex = x1.exponent; |
| 122 | var xs = x1.significand; | 122 | const xs = x1.significand; |
| 123 | const x2 = math.frexp(y); | 123 | const x2 = math.frexp(y); |
| 124 | var ey = x2.exponent; | 124 | const ey = x2.exponent; |
| 125 | var ys = x2.significand; | 125 | const ys = x2.significand; |
| 126 | const x3 = math.frexp(z); | 126 | const x3 = math.frexp(z); |
| 127 | var ez = x3.exponent; | 127 | const ez = x3.exponent; |
| 128 | var zs = x3.significand; | 128 | var zs = x3.significand; |
| 129 | 129 | ||
| 130 | var spread = ex + ey - ez; | 130 | var spread = ex + ey - ez; |
| ... | @@ -181,15 +181,15 @@ fn dd_mul(a: f64, b: f64) dd { | ... | @@ -181,15 +181,15 @@ fn dd_mul(a: f64, b: f64) dd { |
| 181 | var p = a * split; | 181 | var p = a * split; |
| 182 | var ha = a - p; | 182 | var ha = a - p; |
| 183 | ha += p; | 183 | ha += p; |
| 184 | var la = a - ha; | 184 | const la = a - ha; |
| 185 | 185 | ||
| 186 | p = b * split; | 186 | p = b * split; |
| 187 | var hb = b - p; | 187 | var hb = b - p; |
| 188 | hb += p; | 188 | hb += p; |
| 189 | var lb = b - hb; | 189 | const lb = b - hb; |
| 190 | 190 | ||
| 191 | p = ha * hb; | 191 | p = ha * hb; |
| 192 | var q = ha * lb + la * hb; | 192 | const q = ha * lb + la * hb; |
| 193 | 193 | ||
| 194 | ret.hi = p + q; | 194 | ret.hi = p + q; |
| 195 | ret.lo = p - ret.hi + q + la * lb; | 195 | ret.lo = p - ret.hi + q + la * lb; |
| ... | @@ -301,15 +301,15 @@ fn dd_mul128(a: f128, b: f128) dd128 { | ... | @@ -301,15 +301,15 @@ fn dd_mul128(a: f128, b: f128) dd128 { |
| 301 | var p = a * split; | 301 | var p = a * split; |
| 302 | var ha = a - p; | 302 | var ha = a - p; |
| 303 | ha += p; | 303 | ha += p; |
| 304 | var la = a - ha; | 304 | const la = a - ha; |
| 305 | 305 | ||
| 306 | p = b * split; | 306 | p = b * split; |
| 307 | var hb = b - p; | 307 | var hb = b - p; |
| 308 | hb += p; | 308 | hb += p; |
| 309 | var lb = b - hb; | 309 | const lb = b - hb; |
| 310 | 310 | ||
| 311 | p = ha * hb; | 311 | p = ha * hb; |
| 312 | var q = ha * lb + la * hb; | 312 | const q = ha * lb + la * hb; |
| 313 | 313 | ||
| 314 | ret.hi = p + q; | 314 | ret.hi = p + q; |
| 315 | ret.lo = p - ret.hi + q + la * lb; | 315 | ret.lo = p - ret.hi + q + la * lb; |
lib/compiler_rt/fmod.zig+8-8| ... | @@ -81,13 +81,13 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -81,13 +81,13 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { |
| 81 | if (expB == 0) expB = normalize(f80, &bRep); | 81 | if (expB == 0) expB = normalize(f80, &bRep); |
| 82 | 82 | ||
| 83 | var highA: u64 = 0; | 83 | var highA: u64 = 0; |
| 84 | var highB: u64 = 0; | 84 | const highB: u64 = 0; |
| 85 | var lowA: u64 = @truncate(aRep); | 85 | var lowA: u64 = @truncate(aRep); |
| 86 | var lowB: u64 = @truncate(bRep); | 86 | const lowB: u64 = @truncate(bRep); |
| 87 | 87 | ||
| 88 | while (expA > expB) : (expA -= 1) { | 88 | while (expA > expB) : (expA -= 1) { |
| 89 | var high = highA -% highB; | 89 | var high = highA -% highB; |
| 90 | var low = lowA -% lowB; | 90 | const low = lowA -% lowB; |
| 91 | if (lowA < lowB) { | 91 | if (lowA < lowB) { |
| 92 | high -%= 1; | 92 | high -%= 1; |
| 93 | } | 93 | } |
| ... | @@ -104,7 +104,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -104,7 +104,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | var high = highA -% highB; | 106 | var high = highA -% highB; |
| 107 | var low = lowA -% lowB; | 107 | const low = lowA -% lowB; |
| 108 | if (lowA < lowB) { | 108 | if (lowA < lowB) { |
| 109 | high -%= 1; | 109 | high -%= 1; |
| 110 | } | 110 | } |
| ... | @@ -194,13 +194,13 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { | ... | @@ -194,13 +194,13 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { |
| 194 | 194 | ||
| 195 | // OR in extra non-stored mantissa digit | 195 | // OR in extra non-stored mantissa digit |
| 196 | var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48; | 196 | var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48; |
| 197 | var highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48; | 197 | const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48; |
| 198 | var lowA: u64 = aPtr_u64[low_index]; | 198 | var lowA: u64 = aPtr_u64[low_index]; |
| 199 | var lowB: u64 = bPtr_u64[low_index]; | 199 | const lowB: u64 = bPtr_u64[low_index]; |
| 200 | 200 | ||
| 201 | while (expA > expB) : (expA -= 1) { | 201 | while (expA > expB) : (expA -= 1) { |
| 202 | var high = highA -% highB; | 202 | var high = highA -% highB; |
| 203 | var low = lowA -% lowB; | 203 | const low = lowA -% lowB; |
| 204 | if (lowA < lowB) { | 204 | if (lowA < lowB) { |
| 205 | high -%= 1; | 205 | high -%= 1; |
| 206 | } | 206 | } |
| ... | @@ -217,7 +217,7 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { | ... | @@ -217,7 +217,7 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | var high = highA -% highB; | 219 | var high = highA -% highB; |
| 220 | var low = lowA -% lowB; | 220 | const low = lowA -% lowB; |
| 221 | if (lowA < lowB) { | 221 | if (lowA < lowB) { |
| 222 | high -= 1; | 222 | high -= 1; |
| 223 | } | 223 | } |
lib/compiler_rt/mulc3.zig+1-1| ... | @@ -25,7 +25,7 @@ pub inline fn mulc3(comptime T: type, a_in: T, b_in: T, c_in: T, d_in: T) Comple | ... | @@ -25,7 +25,7 @@ pub inline fn mulc3(comptime T: type, a_in: T, b_in: T, c_in: T, d_in: T) Comple |
| 25 | const zero: T = 0.0; | 25 | const zero: T = 0.0; |
| 26 | const one: T = 1.0; | 26 | const one: T = 1.0; |
| 27 | 27 | ||
| 28 | var z = Complex(T){ | 28 | const z: Complex(T) = .{ |
| 29 | .real = ac - bd, | 29 | .real = ac - bd, |
| 30 | .imag = ad + bc, | 30 | .imag = ad + bc, |
| 31 | }; | 31 | }; |
lib/compiler_rt/mulc3_test.zig+16-16| ... | @@ -19,20 +19,20 @@ test { | ... | @@ -19,20 +19,20 @@ test { |
| 19 | 19 | ||
| 20 | fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void { | 20 | fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void { |
| 21 | { | 21 | { |
| 22 | var a: T = 1.0; | 22 | const a: T = 1.0; |
| 23 | var b: T = 0.0; | 23 | const b: T = 0.0; |
| 24 | var c: T = -1.0; | 24 | const c: T = -1.0; |
| 25 | var d: T = 0.0; | 25 | const d: T = 0.0; |
| 26 | 26 | ||
| 27 | const result = f(a, b, c, d); | 27 | const result = f(a, b, c, d); |
| 28 | try expect(result.real == -1.0); | 28 | try expect(result.real == -1.0); |
| 29 | try expect(result.imag == 0.0); | 29 | try expect(result.imag == 0.0); |
| 30 | } | 30 | } |
| 31 | { | 31 | { |
| 32 | var a: T = 1.0; | 32 | const a: T = 1.0; |
| 33 | var b: T = 0.0; | 33 | const b: T = 0.0; |
| 34 | var c: T = -4.0; | 34 | const c: T = -4.0; |
| 35 | var d: T = 0.0; | 35 | const d: T = 0.0; |
| 36 | 36 | ||
| 37 | const result = f(a, b, c, d); | 37 | const result = f(a, b, c, d); |
| 38 | try expect(result.real == -4.0); | 38 | try expect(result.real == -4.0); |
| ... | @@ -41,10 +41,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) | ... | @@ -41,10 +41,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) |
| 41 | { | 41 | { |
| 42 | // if one operand is an infinity and the other operand is a nonzero finite number or an infinity, | 42 | // if one operand is an infinity and the other operand is a nonzero finite number or an infinity, |
| 43 | // then the result of the * operator is an infinity; | 43 | // then the result of the * operator is an infinity; |
| 44 | var a: T = math.inf(T); | 44 | const a: T = math.inf(T); |
| 45 | var b: T = -math.inf(T); | 45 | const b: T = -math.inf(T); |
| 46 | var c: T = 1.0; | 46 | const c: T = 1.0; |
| 47 | var d: T = 0.0; | 47 | const d: T = 0.0; |
| 48 | 48 | ||
| 49 | const result = f(a, b, c, d); | 49 | const result = f(a, b, c, d); |
| 50 | try expect(result.real == math.inf(T)); | 50 | try expect(result.real == math.inf(T)); |
| ... | @@ -53,10 +53,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) | ... | @@ -53,10 +53,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T) |
| 53 | { | 53 | { |
| 54 | // if one operand is an infinity and the other operand is a nonzero finite number or an infinity, | 54 | // if one operand is an infinity and the other operand is a nonzero finite number or an infinity, |
| 55 | // then the result of the * operator is an infinity; | 55 | // then the result of the * operator is an infinity; |
| 56 | var a: T = math.inf(T); | 56 | const a: T = math.inf(T); |
| 57 | var b: T = -1.0; | 57 | const b: T = -1.0; |
| 58 | var c: T = 1.0; | 58 | const c: T = 1.0; |
| 59 | var d: T = math.inf(T); | 59 | const d: T = math.inf(T); |
| 60 | 60 | ||
| 61 | const result = f(a, b, c, d); | 61 | const result = f(a, b, c, d); |
| 62 | try expect(result.real == math.inf(T)); | 62 | try expect(result.real == math.inf(T)); |
lib/compiler_rt/mulo.zig+2-2| ... | @@ -20,7 +20,7 @@ comptime { | ... | @@ -20,7 +20,7 @@ comptime { |
| 20 | inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { | 20 | inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { |
| 21 | overflow.* = 0; | 21 | overflow.* = 0; |
| 22 | const min = math.minInt(ST); | 22 | const min = math.minInt(ST); |
| 23 | var res: ST = a *% b; | 23 | const res: ST = a *% b; |
| 24 | // Hacker's Delight section Overflow subsection Multiplication | 24 | // Hacker's Delight section Overflow subsection Multiplication |
| 25 | // case a=-2^{31}, b=-1 problem, because | 25 | // case a=-2^{31}, b=-1 problem, because |
| 26 | // on some machines a*b = -2^{31} with overflow | 26 | // on some machines a*b = -2^{31} with overflow |
| ... | @@ -41,7 +41,7 @@ inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int) | ... | @@ -41,7 +41,7 @@ inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int) |
| 41 | }; | 41 | }; |
| 42 | const min = math.minInt(ST); | 42 | const min = math.minInt(ST); |
| 43 | const max = math.maxInt(ST); | 43 | const max = math.maxInt(ST); |
| 44 | var res: EST = @as(EST, a) * @as(EST, b); | 44 | const res: EST = @as(EST, a) * @as(EST, b); |
| 45 | //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1} | 45 | //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1} |
| 46 | if (res < min or max < res) | 46 | if (res < min or max < res) |
| 47 | overflow.* = 1; | 47 | overflow.* = 1; |
lib/compiler_rt/negdi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const neg = @import("negXi2.zig"); | ... | @@ -2,7 +2,7 @@ const neg = @import("negXi2.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__negdi2(a: i64, expected: i64) !void { | 4 | fn test__negdi2(a: i64, expected: i64) !void { |
| 5 | var result = neg.__negdi2(a); | 5 | const result = neg.__negdi2(a); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/negsi2_test.zig+1-1| ... | @@ -5,7 +5,7 @@ const testing = std.testing; | ... | @@ -5,7 +5,7 @@ const testing = std.testing; |
| 5 | const print = std.debug.print; | 5 | const print = std.debug.print; |
| 6 | 6 | ||
| 7 | fn test__negsi2(a: i32, expected: i32) !void { | 7 | fn test__negsi2(a: i32, expected: i32) !void { |
| 8 | var result = neg.__negsi2(a); | 8 | const result = neg.__negsi2(a); |
| 9 | try testing.expectEqual(expected, result); | 9 | try testing.expectEqual(expected, result); |
| 10 | } | 10 | } |
| 11 | 11 |
lib/compiler_rt/negti2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const neg = @import("negXi2.zig"); | ... | @@ -2,7 +2,7 @@ const neg = @import("negXi2.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__negti2(a: i128, expected: i128) !void { | 4 | fn test__negti2(a: i128, expected: i128) !void { |
| 5 | var result = neg.__negti2(a); | 5 | const result = neg.__negti2(a); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/negvdi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); | ... | @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__negvdi2(a: i64, expected: i64) !void { | 4 | fn test__negvdi2(a: i64, expected: i64) !void { |
| 5 | var result = negv.__negvdi2(a); | 5 | const result = negv.__negvdi2(a); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/negvsi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); | ... | @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__negvsi2(a: i32, expected: i32) !void { | 4 | fn test__negvsi2(a: i32, expected: i32) !void { |
| 5 | var result = negv.__negvsi2(a); | 5 | const result = negv.__negvsi2(a); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/negvti2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); | ... | @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__negvti2(a: i128, expected: i128) !void { | 4 | fn test__negvti2(a: i128, expected: i128) !void { |
| 5 | var result = negv.__negvti2(a); | 5 | const result = negv.__negvti2(a); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/paritydi2_test.zig+3-3| ... | @@ -13,8 +13,8 @@ fn paritydi2Naive(a: i64) i32 { | ... | @@ -13,8 +13,8 @@ fn paritydi2Naive(a: i64) i32 { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn test__paritydi2(a: i64) !void { | 15 | fn test__paritydi2(a: i64) !void { |
| 16 | var x = parity.__paritydi2(a); | 16 | const x = parity.__paritydi2(a); |
| 17 | var expected: i64 = paritydi2Naive(a); | 17 | const expected: i64 = paritydi2Naive(a); |
| 18 | try testing.expectEqual(expected, x); | 18 | try testing.expectEqual(expected, x); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| ... | @@ -30,7 +30,7 @@ test "paritydi2" { | ... | @@ -30,7 +30,7 @@ test "paritydi2" { |
| 30 | var rnd = RndGen.init(42); | 30 | var rnd = RndGen.init(42); |
| 31 | var i: u32 = 0; | 31 | var i: u32 = 0; |
| 32 | while (i < 10_000) : (i += 1) { | 32 | while (i < 10_000) : (i += 1) { |
| 33 | var rand_num = rnd.random().int(i64); | 33 | const rand_num = rnd.random().int(i64); |
| 34 | try test__paritydi2(rand_num); | 34 | try test__paritydi2(rand_num); |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
lib/compiler_rt/paritysi2_test.zig+3-3| ... | @@ -13,8 +13,8 @@ fn paritysi2Naive(a: i32) i32 { | ... | @@ -13,8 +13,8 @@ fn paritysi2Naive(a: i32) i32 { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn test__paritysi2(a: i32) !void { | 15 | fn test__paritysi2(a: i32) !void { |
| 16 | var x = parity.__paritysi2(a); | 16 | const x = parity.__paritysi2(a); |
| 17 | var expected: i32 = paritysi2Naive(a); | 17 | const expected: i32 = paritysi2Naive(a); |
| 18 | try testing.expectEqual(expected, x); | 18 | try testing.expectEqual(expected, x); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| ... | @@ -30,7 +30,7 @@ test "paritysi2" { | ... | @@ -30,7 +30,7 @@ test "paritysi2" { |
| 30 | var rnd = RndGen.init(42); | 30 | var rnd = RndGen.init(42); |
| 31 | var i: u32 = 0; | 31 | var i: u32 = 0; |
| 32 | while (i < 10_000) : (i += 1) { | 32 | while (i < 10_000) : (i += 1) { |
| 33 | var rand_num = rnd.random().int(i32); | 33 | const rand_num = rnd.random().int(i32); |
| 34 | try test__paritysi2(rand_num); | 34 | try test__paritysi2(rand_num); |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
lib/compiler_rt/parityti2_test.zig+3-3| ... | @@ -13,8 +13,8 @@ fn parityti2Naive(a: i128) i32 { | ... | @@ -13,8 +13,8 @@ fn parityti2Naive(a: i128) i32 { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn test__parityti2(a: i128) !void { | 15 | fn test__parityti2(a: i128) !void { |
| 16 | var x = parity.__parityti2(a); | 16 | const x = parity.__parityti2(a); |
| 17 | var expected: i128 = parityti2Naive(a); | 17 | const expected: i128 = parityti2Naive(a); |
| 18 | try testing.expectEqual(expected, x); | 18 | try testing.expectEqual(expected, x); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| ... | @@ -30,7 +30,7 @@ test "parityti2" { | ... | @@ -30,7 +30,7 @@ test "parityti2" { |
| 30 | var rnd = RndGen.init(42); | 30 | var rnd = RndGen.init(42); |
| 31 | var i: u32 = 0; | 31 | var i: u32 = 0; |
| 32 | while (i < 10_000) : (i += 1) { | 32 | while (i < 10_000) : (i += 1) { |
| 33 | var rand_num = rnd.random().int(i128); | 33 | const rand_num = rnd.random().int(i128); |
| 34 | try test__parityti2(rand_num); | 34 | try test__parityti2(rand_num); |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
lib/compiler_rt/popcountdi2_test.zig+1-1| ... | @@ -29,7 +29,7 @@ test "popcountdi2" { | ... | @@ -29,7 +29,7 @@ test "popcountdi2" { |
| 29 | var rnd = RndGen.init(42); | 29 | var rnd = RndGen.init(42); |
| 30 | var i: u32 = 0; | 30 | var i: u32 = 0; |
| 31 | while (i < 10_000) : (i += 1) { | 31 | while (i < 10_000) : (i += 1) { |
| 32 | var rand_num = rnd.random().int(i64); | 32 | const rand_num = rnd.random().int(i64); |
| 33 | try test__popcountdi2(rand_num); | 33 | try test__popcountdi2(rand_num); |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
lib/compiler_rt/popcountsi2_test.zig+1-1| ... | @@ -29,7 +29,7 @@ test "popcountsi2" { | ... | @@ -29,7 +29,7 @@ test "popcountsi2" { |
| 29 | var rnd = RndGen.init(42); | 29 | var rnd = RndGen.init(42); |
| 30 | var i: u32 = 0; | 30 | var i: u32 = 0; |
| 31 | while (i < 10_000) : (i += 1) { | 31 | while (i < 10_000) : (i += 1) { |
| 32 | var rand_num = rnd.random().int(i32); | 32 | const rand_num = rnd.random().int(i32); |
| 33 | try test__popcountsi2(rand_num); | 33 | try test__popcountsi2(rand_num); |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
lib/compiler_rt/popcountti2_test.zig+1-1| ... | @@ -29,7 +29,7 @@ test "popcountti2" { | ... | @@ -29,7 +29,7 @@ test "popcountti2" { |
| 29 | var rnd = RndGen.init(42); | 29 | var rnd = RndGen.init(42); |
| 30 | var i: u32 = 0; | 30 | var i: u32 = 0; |
| 31 | while (i < 10_000) : (i += 1) { | 31 | while (i < 10_000) : (i += 1) { |
| 32 | var rand_num = rnd.random().int(i128); | 32 | const rand_num = rnd.random().int(i128); |
| 33 | try test__popcountti2(rand_num); | 33 | try test__popcountti2(rand_num); |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
lib/compiler_rt/powiXf2_test.zig+5-5| ... | @@ -9,27 +9,27 @@ const testing = std.testing; | ... | @@ -9,27 +9,27 @@ const testing = std.testing; |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | 10 | ||
| 11 | fn test__powihf2(a: f16, b: i32, expected: f16) !void { | 11 | fn test__powihf2(a: f16, b: i32, expected: f16) !void { |
| 12 | var result = powiXf2.__powihf2(a, b); | 12 | const result = powiXf2.__powihf2(a, b); |
| 13 | try testing.expectEqual(expected, result); | 13 | try testing.expectEqual(expected, result); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn test__powisf2(a: f32, b: i32, expected: f32) !void { | 16 | fn test__powisf2(a: f32, b: i32, expected: f32) !void { |
| 17 | var result = powiXf2.__powisf2(a, b); | 17 | const result = powiXf2.__powisf2(a, b); |
| 18 | try testing.expectEqual(expected, result); | 18 | try testing.expectEqual(expected, result); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn test__powidf2(a: f64, b: i32, expected: f64) !void { | 21 | fn test__powidf2(a: f64, b: i32, expected: f64) !void { |
| 22 | var result = powiXf2.__powidf2(a, b); | 22 | const result = powiXf2.__powidf2(a, b); |
| 23 | try testing.expectEqual(expected, result); | 23 | try testing.expectEqual(expected, result); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | fn test__powitf2(a: f128, b: i32, expected: f128) !void { | 26 | fn test__powitf2(a: f128, b: i32, expected: f128) !void { |
| 27 | var result = powiXf2.__powitf2(a, b); | 27 | const result = powiXf2.__powitf2(a, b); |
| 28 | try testing.expectEqual(expected, result); | 28 | try testing.expectEqual(expected, result); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | fn test__powixf2(a: f80, b: i32, expected: f80) !void { | 31 | fn test__powixf2(a: f80, b: i32, expected: f80) !void { |
| 32 | var result = powiXf2.__powixf2(a, b); | 32 | const result = powiXf2.__powixf2(a, b); |
| 33 | try testing.expectEqual(expected, result); | 33 | try testing.expectEqual(expected, result); |
| 34 | } | 34 | } |
| 35 | 35 |
lib/compiler_rt/subo.zig+1-1| ... | @@ -27,7 +27,7 @@ pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 { | ... | @@ -27,7 +27,7 @@ pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 { |
| 27 | 27 | ||
| 28 | inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { | 28 | inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { |
| 29 | overflow.* = 0; | 29 | overflow.* = 0; |
| 30 | var sum: ST = a -% b; | 30 | const sum: ST = a -% b; |
| 31 | // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract | 31 | // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract |
| 32 | // Let sum = a -% b == a - b - carry == wraparound subtraction. | 32 | // Let sum = a -% b == a - b - carry == wraparound subtraction. |
| 33 | // Overflow in a-b-carry occurs, iff a and b have opposite signs | 33 | // Overflow in a-b-carry occurs, iff a and b have opposite signs |
lib/compiler_rt/subodi4_test.zig+2-2| ... | @@ -6,8 +6,8 @@ const math = std.math; | ... | @@ -6,8 +6,8 @@ const math = std.math; |
| 6 | fn test__subodi4(a: i64, b: i64) !void { | 6 | fn test__subodi4(a: i64, b: i64) !void { |
| 7 | var result_ov: c_int = undefined; | 7 | var result_ov: c_int = undefined; |
| 8 | var expected_ov: c_int = undefined; | 8 | var expected_ov: c_int = undefined; |
| 9 | var result = subo.__subodi4(a, b, &result_ov); | 9 | const result = subo.__subodi4(a, b, &result_ov); |
| 10 | var expected: i64 = simple_subodi4(a, b, &expected_ov); | 10 | const expected: i64 = simple_subodi4(a, b, &expected_ov); |
| 11 | try testing.expectEqual(expected, result); | 11 | try testing.expectEqual(expected, result); |
| 12 | try testing.expectEqual(expected_ov, result_ov); | 12 | try testing.expectEqual(expected_ov, result_ov); |
| 13 | } | 13 | } |
lib/compiler_rt/subosi4_test.zig+2-2| ... | @@ -4,8 +4,8 @@ const testing = @import("std").testing; | ... | @@ -4,8 +4,8 @@ const testing = @import("std").testing; |
| 4 | fn test__subosi4(a: i32, b: i32) !void { | 4 | fn test__subosi4(a: i32, b: i32) !void { |
| 5 | var result_ov: c_int = undefined; | 5 | var result_ov: c_int = undefined; |
| 6 | var expected_ov: c_int = undefined; | 6 | var expected_ov: c_int = undefined; |
| 7 | var result = subo.__subosi4(a, b, &result_ov); | 7 | const result = subo.__subosi4(a, b, &result_ov); |
| 8 | var expected: i32 = simple_subosi4(a, b, &expected_ov); | 8 | const expected: i32 = simple_subosi4(a, b, &expected_ov); |
| 9 | try testing.expectEqual(expected, result); | 9 | try testing.expectEqual(expected, result); |
| 10 | try testing.expectEqual(expected_ov, result_ov); | 10 | try testing.expectEqual(expected_ov, result_ov); |
| 11 | } | 11 | } |
lib/compiler_rt/suboti4_test.zig+2-2| ... | @@ -6,8 +6,8 @@ const math = std.math; | ... | @@ -6,8 +6,8 @@ const math = std.math; |
| 6 | fn test__suboti4(a: i128, b: i128) !void { | 6 | fn test__suboti4(a: i128, b: i128) !void { |
| 7 | var result_ov: c_int = undefined; | 7 | var result_ov: c_int = undefined; |
| 8 | var expected_ov: c_int = undefined; | 8 | var expected_ov: c_int = undefined; |
| 9 | var result = subo.__suboti4(a, b, &result_ov); | 9 | const result = subo.__suboti4(a, b, &result_ov); |
| 10 | var expected: i128 = simple_suboti4(a, b, &expected_ov); | 10 | const expected: i128 = simple_suboti4(a, b, &expected_ov); |
| 11 | try testing.expectEqual(expected, result); | 11 | try testing.expectEqual(expected, result); |
| 12 | try testing.expectEqual(expected_ov, result_ov); | 12 | try testing.expectEqual(expected_ov, result_ov); |
| 13 | } | 13 | } |
lib/compiler_rt/ucmpdi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); | ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ucmpdi2(a: u64, b: u64, expected: i32) !void { | 4 | fn test__ucmpdi2(a: u64, b: u64, expected: i32) !void { |
| 5 | var result = cmp.__ucmpdi2(a, b); | 5 | const result = cmp.__ucmpdi2(a, b); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/ucmpsi2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); | ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ucmpsi2(a: u32, b: u32, expected: i32) !void { | 4 | fn test__ucmpsi2(a: u32, b: u32, expected: i32) !void { |
| 5 | var result = cmp.__ucmpsi2(a, b); | 5 | const result = cmp.__ucmpsi2(a, b); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/ucmpti2_test.zig+1-1| ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); | ... | @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); |
| 2 | const testing = @import("std").testing; | 2 | const testing = @import("std").testing; |
| 3 | 3 | ||
| 4 | fn test__ucmpti2(a: u128, b: u128, expected: i32) !void { | 4 | fn test__ucmpti2(a: u128, b: u128, expected: i32) !void { |
| 5 | var result = cmp.__ucmpti2(a, b); | 5 | const result = cmp.__ucmpti2(a, b); |
| 6 | try testing.expectEqual(expected, result); | 6 | try testing.expectEqual(expected, result); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/compiler_rt/udivmod.zig+4-4| ... | @@ -52,7 +52,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T { | ... | @@ -52,7 +52,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T { |
| 52 | if (rhat >= b) break; | 52 | if (rhat >= b) break; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | var un21 = un64 *% b +% un1 -% q1 *% v; | 55 | const un21 = un64 *% b +% un1 -% q1 *% v; |
| 56 | 56 | ||
| 57 | // Compute the second quotient digit | 57 | // Compute the second quotient digit |
| 58 | var q0 = un21 / vn1; | 58 | var q0 = un21 / vn1; |
| ... | @@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { | ... | @@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { |
| 101 | return 0; | 101 | return 0; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | var a: [2]HalfT = @bitCast(a_); | 104 | const a: [2]HalfT = @bitCast(a_); |
| 105 | var b: [2]HalfT = @bitCast(b_); | 105 | const b: [2]HalfT = @bitCast(b_); |
| 106 | var q: [2]HalfT = undefined; | 106 | var q: [2]HalfT = undefined; |
| 107 | var r: [2]HalfT = undefined; | 107 | var r: [2]HalfT = undefined; |
| 108 | 108 | ||
| ... | @@ -125,7 +125,7 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { | ... | @@ -125,7 +125,7 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | // 0 <= shift <= 63 | 127 | // 0 <= shift <= 63 |
| 128 | var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]); | 128 | const shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]); |
| 129 | var af: T = @bitCast(a); | 129 | var af: T = @bitCast(a); |
| 130 | var bf = @as(T, @bitCast(b)) << shift; | 130 | var bf = @as(T, @bitCast(b)) << shift; |
| 131 | q = @bitCast(@as(T, 0)); | 131 | q = @bitCast(@as(T, 0)); |
lib/compiler_rt/udivmodei4.zig+2-2| ... | @@ -116,7 +116,7 @@ pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) | ... | @@ -116,7 +116,7 @@ pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) |
| 116 | @setRuntimeSafety(builtin.is_test); | 116 | @setRuntimeSafety(builtin.is_test); |
| 117 | const u = u_p[0 .. bits / 32]; | 117 | const u = u_p[0 .. bits / 32]; |
| 118 | const v = v_p[0 .. bits / 32]; | 118 | const v = v_p[0 .. bits / 32]; |
| 119 | var q = r_q[0 .. bits / 32]; | 119 | const q = r_q[0 .. bits / 32]; |
| 120 | @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable; | 120 | @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| ... | @@ -124,7 +124,7 @@ pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) | ... | @@ -124,7 +124,7 @@ pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) |
| 124 | @setRuntimeSafety(builtin.is_test); | 124 | @setRuntimeSafety(builtin.is_test); |
| 125 | const u = u_p[0 .. bits / 32]; | 125 | const u = u_p[0 .. bits / 32]; |
| 126 | const v = v_p[0 .. bits / 32]; | 126 | const v = v_p[0 .. bits / 32]; |
| 127 | var r = r_p[0 .. bits / 32]; | 127 | const r = r_p[0 .. bits / 32]; |
| 128 | @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable; | 128 | @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable; |
| 129 | } | 129 | } |
| 130 | 130 |
lib/std/Build/Cache.zig+1-1| ... | @@ -141,7 +141,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath { | ... | @@ -141,7 +141,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath { |
| 141 | var i: u8 = 1; // Start at 1 to skip over checking the null prefix. | 141 | var i: u8 = 1; // Start at 1 to skip over checking the null prefix. |
| 142 | while (i < prefixes_slice.len) : (i += 1) { | 142 | while (i < prefixes_slice.len) : (i += 1) { |
| 143 | const p = prefixes_slice[i].path.?; | 143 | const p = prefixes_slice[i].path.?; |
| 144 | var sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) { | 144 | const sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) { |
| 145 | error.NotASubPath => continue, | 145 | error.NotASubPath => continue, |
| 146 | else => |e| return e, | 146 | else => |e| return e, |
| 147 | }; | 147 | }; |
lib/std/Build/Cache/DepTokenizer.zig+3-3| ... | @@ -950,7 +950,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void { | ... | @@ -950,7 +950,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void { |
| 950 | 950 | ||
| 951 | fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void { | 951 | fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void { |
| 952 | var buf: [80]u8 = undefined; | 952 | var buf: [80]u8 = undefined; |
| 953 | var text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len }); | 953 | const text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len }); |
| 954 | try out.writeAll(text); | 954 | try out.writeAll(text); |
| 955 | var i: usize = text.len; | 955 | var i: usize = text.len; |
| 956 | const end = 79; | 956 | const end = 79; |
| ... | @@ -983,12 +983,12 @@ fn hexDump(out: anytype, bytes: []const u8) !void { | ... | @@ -983,12 +983,12 @@ fn hexDump(out: anytype, bytes: []const u8) !void { |
| 983 | try printDecValue(out, offset, 8); | 983 | try printDecValue(out, offset, 8); |
| 984 | try out.writeAll(":"); | 984 | try out.writeAll(":"); |
| 985 | try out.writeAll(" "); | 985 | try out.writeAll(" "); |
| 986 | var end1 = @min(offset + n, offset + 8); | 986 | const end1 = @min(offset + n, offset + 8); |
| 987 | for (bytes[offset..end1]) |b| { | 987 | for (bytes[offset..end1]) |b| { |
| 988 | try out.writeAll(" "); | 988 | try out.writeAll(" "); |
| 989 | try printHexValue(out, b, 2); | 989 | try printHexValue(out, b, 2); |
| 990 | } | 990 | } |
| 991 | var end2 = offset + n; | 991 | const end2 = offset + n; |
| 992 | if (end2 > end1) { | 992 | if (end2 > end1) { |
| 993 | try out.writeAll(" "); | 993 | try out.writeAll(" "); |
| 994 | for (bytes[end1..end2]) |b| { | 994 | for (bytes[end1..end2]) |b| { |
lib/std/Build/Step/CheckObject.zig+1-1| ... | @@ -293,7 +293,7 @@ const Check = struct { | ... | @@ -293,7 +293,7 @@ const Check = struct { |
| 293 | 293 | ||
| 294 | /// Creates a new empty sequence of actions. | 294 | /// Creates a new empty sequence of actions. |
| 295 | pub fn checkStart(self: *CheckObject) void { | 295 | pub fn checkStart(self: *CheckObject) void { |
| 296 | var new_check = Check.create(self.step.owner.allocator); | 296 | const new_check = Check.create(self.step.owner.allocator); |
| 297 | self.checks.append(new_check) catch @panic("OOM"); | 297 | self.checks.append(new_check) catch @panic("OOM"); |
| 298 | } | 298 | } |
| 299 | 299 |
lib/std/Build/Step/ConfigHeader.zig+2-2| ... | @@ -307,8 +307,8 @@ fn render_cmake( | ... | @@ -307,8 +307,8 @@ fn render_cmake( |
| 307 | values: std.StringArrayHashMap(Value), | 307 | values: std.StringArrayHashMap(Value), |
| 308 | src_path: []const u8, | 308 | src_path: []const u8, |
| 309 | ) !void { | 309 | ) !void { |
| 310 | var build = step.owner; | 310 | const build = step.owner; |
| 311 | var allocator = build.allocator; | 311 | const allocator = build.allocator; |
| 312 | 312 | ||
| 313 | var values_copy = try values.clone(); | 313 | var values_copy = try values.clone(); |
| 314 | defer values_copy.deinit(); | 314 | defer values_copy.deinit(); |
lib/std/Build/Step/Run.zig+1-1| ... | @@ -301,7 +301,7 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void { | ... | @@ -301,7 +301,7 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void { |
| 301 | const env_map = getEnvMapInternal(self); | 301 | const env_map = getEnvMapInternal(self); |
| 302 | 302 | ||
| 303 | const key = "PATH"; | 303 | const key = "PATH"; |
| 304 | var prev_path = env_map.get(key); | 304 | const prev_path = env_map.get(key); |
| 305 | 305 | ||
| 306 | if (prev_path) |pp| { | 306 | if (prev_path) |pp| { |
| 307 | const new_path = b.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path }); | 307 | const new_path = b.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path }); |
lib/std/Progress.zig+1| ... | @@ -397,6 +397,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any | ... | @@ -397,6 +397,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any |
| 397 | 397 | ||
| 398 | test "basic functionality" { | 398 | test "basic functionality" { |
| 399 | var disable = true; | 399 | var disable = true; |
| 400 | _ = &disable; | ||
| 400 | if (disable) { | 401 | if (disable) { |
| 401 | // This test is disabled because it uses time.sleep() and is therefore slow. It also | 402 | // This test is disabled because it uses time.sleep() and is therefore slow. It also |
| 402 | // prints bogus progress data to stderr. | 403 | // prints bogus progress data to stderr. |
lib/std/Thread/WaitGroup.zig+1-1| ... | @@ -25,7 +25,7 @@ pub fn finish(self: *WaitGroup) void { | ... | @@ -25,7 +25,7 @@ pub fn finish(self: *WaitGroup) void { |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | pub fn wait(self: *WaitGroup) void { | 27 | pub fn wait(self: *WaitGroup) void { |
| 28 | var state = self.state.fetchAdd(is_waiting, .Acquire); | 28 | const state = self.state.fetchAdd(is_waiting, .Acquire); |
| 29 | assert(state & is_waiting == 0); | 29 | assert(state & is_waiting == 0); |
| 30 | 30 | ||
| 31 | if ((state / one_pending) > 0) { | 31 | if ((state / one_pending) > 0) { |
lib/std/array_hash_map.zig+3-3| ... | @@ -2076,11 +2076,11 @@ test "iterator hash map" { | ... | @@ -2076,11 +2076,11 @@ test "iterator hash map" { |
| 2076 | try reset_map.putNoClobber(1, 22); | 2076 | try reset_map.putNoClobber(1, 22); |
| 2077 | try reset_map.putNoClobber(2, 33); | 2077 | try reset_map.putNoClobber(2, 33); |
| 2078 | 2078 | ||
| 2079 | var keys = [_]i32{ | 2079 | const keys = [_]i32{ |
| 2080 | 0, 2, 1, | 2080 | 0, 2, 1, |
| 2081 | }; | 2081 | }; |
| 2082 | 2082 | ||
| 2083 | var values = [_]i32{ | 2083 | const values = [_]i32{ |
| 2084 | 11, 33, 22, | 2084 | 11, 33, 22, |
| 2085 | }; | 2085 | }; |
| 2086 | 2086 | ||
| ... | @@ -2116,7 +2116,7 @@ test "iterator hash map" { | ... | @@ -2116,7 +2116,7 @@ test "iterator hash map" { |
| 2116 | } | 2116 | } |
| 2117 | 2117 | ||
| 2118 | it.reset(); | 2118 | it.reset(); |
| 2119 | var entry = it.next().?; | 2119 | const entry = it.next().?; |
| 2120 | try testing.expect(entry.key_ptr.* == first_entry.key_ptr.*); | 2120 | try testing.expect(entry.key_ptr.* == first_entry.key_ptr.*); |
| 2121 | try testing.expect(entry.value_ptr.* == first_entry.value_ptr.*); | 2121 | try testing.expect(entry.value_ptr.* == first_entry.value_ptr.*); |
| 2122 | } | 2122 | } |
lib/std/array_list.zig+2-2| ... | @@ -979,7 +979,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -979,7 +979,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 979 | pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void { | 979 | pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void { |
| 980 | if (self.capacity >= new_capacity) return; | 980 | if (self.capacity >= new_capacity) return; |
| 981 | 981 | ||
| 982 | var better_capacity = growCapacity(self.capacity, new_capacity); | 982 | const better_capacity = growCapacity(self.capacity, new_capacity); |
| 983 | return self.ensureTotalCapacityPrecise(allocator, better_capacity); | 983 | return self.ensureTotalCapacityPrecise(allocator, better_capacity); |
| 984 | } | 984 | } |
| 985 | 985 | ||
| ... | @@ -1159,7 +1159,7 @@ test "std.ArrayList/ArrayListUnmanaged.init" { | ... | @@ -1159,7 +1159,7 @@ test "std.ArrayList/ArrayListUnmanaged.init" { |
| 1159 | } | 1159 | } |
| 1160 | 1160 | ||
| 1161 | { | 1161 | { |
| 1162 | var list = ArrayListUnmanaged(i32){}; | 1162 | const list = ArrayListUnmanaged(i32){}; |
| 1163 | 1163 | ||
| 1164 | try testing.expect(list.items.len == 0); | 1164 | try testing.expect(list.items.len == 0); |
| 1165 | try testing.expect(list.capacity == 0); | 1165 | try testing.expect(list.capacity == 0); |
lib/std/atomic/Atomic.zig+1-1| ... | @@ -125,7 +125,7 @@ pub fn Atomic(comptime T: type) type { | ... | @@ -125,7 +125,7 @@ pub fn Atomic(comptime T: type) type { |
| 125 | @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores"); | 125 | @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores"); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | comptime var success_is_stronger = switch (failure) { | 128 | const success_is_stronger = switch (failure) { |
| 129 | .SeqCst => success == .SeqCst, | 129 | .SeqCst => success == .SeqCst, |
| 130 | .AcqRel => @compileError(@tagName(failure) ++ " implies " ++ @tagName(Ordering.Release) ++ " which is only allowed on success"), | 130 | .AcqRel => @compileError(@tagName(failure) ++ " implies " ++ @tagName(Ordering.Release) ++ " which is only allowed on success"), |
| 131 | .Acquire => success == .SeqCst or success == .AcqRel or success == .Acquire, | 131 | .Acquire => success == .SeqCst or success == .AcqRel or success == .Acquire, |
lib/std/atomic/queue.zig+2-2| ... | @@ -175,11 +175,11 @@ const puts_per_thread = 500; | ... | @@ -175,11 +175,11 @@ const puts_per_thread = 500; |
| 175 | const put_thread_count = 3; | 175 | const put_thread_count = 3; |
| 176 | 176 | ||
| 177 | test "std.atomic.Queue" { | 177 | test "std.atomic.Queue" { |
| 178 | var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); | 178 | const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); |
| 179 | defer std.heap.page_allocator.free(plenty_of_memory); | 179 | defer std.heap.page_allocator.free(plenty_of_memory); |
| 180 | 180 | ||
| 181 | var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory); | 181 | var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory); |
| 182 | var a = fixed_buffer_allocator.threadSafeAllocator(); | 182 | const a = fixed_buffer_allocator.threadSafeAllocator(); |
| 183 | 183 | ||
| 184 | var queue = Queue(i32).init(); | 184 | var queue = Queue(i32).init(); |
| 185 | var context = Context{ | 185 | var context = Context{ |
lib/std/atomic/stack.zig+2-2| ... | @@ -85,11 +85,11 @@ const puts_per_thread = 500; | ... | @@ -85,11 +85,11 @@ const puts_per_thread = 500; |
| 85 | const put_thread_count = 3; | 85 | const put_thread_count = 3; |
| 86 | 86 | ||
| 87 | test "std.atomic.stack" { | 87 | test "std.atomic.stack" { |
| 88 | var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); | 88 | const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); |
| 89 | defer std.heap.page_allocator.free(plenty_of_memory); | 89 | defer std.heap.page_allocator.free(plenty_of_memory); |
| 90 | 90 | ||
| 91 | var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory); | 91 | var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory); |
| 92 | var a = fixed_buffer_allocator.threadSafeAllocator(); | 92 | const a = fixed_buffer_allocator.threadSafeAllocator(); |
| 93 | 93 | ||
| 94 | var stack = Stack(i32).init(); | 94 | var stack = Stack(i32).init(); |
| 95 | var context = Context{ | 95 | var context = Context{ |
lib/std/base64.zig+11-11| ... | @@ -239,7 +239,7 @@ pub const Base64Decoder = struct { | ... | @@ -239,7 +239,7 @@ pub const Base64Decoder = struct { |
| 239 | if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter; | 239 | if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter; |
| 240 | std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little); | 240 | std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little); |
| 241 | } | 241 | } |
| 242 | var remaining = source[fast_src_idx..]; | 242 | const remaining = source[fast_src_idx..]; |
| 243 | for (remaining, fast_src_idx..) |c, src_idx| { | 243 | for (remaining, fast_src_idx..) |c, src_idx| { |
| 244 | const d = decoder.char_to_index[c]; | 244 | const d = decoder.char_to_index[c]; |
| 245 | if (d == invalid_char) { | 245 | if (d == invalid_char) { |
| ... | @@ -259,7 +259,7 @@ pub const Base64Decoder = struct { | ... | @@ -259,7 +259,7 @@ pub const Base64Decoder = struct { |
| 259 | return error.InvalidPadding; | 259 | return error.InvalidPadding; |
| 260 | } | 260 | } |
| 261 | if (leftover_idx == null) return; | 261 | if (leftover_idx == null) return; |
| 262 | var leftover = source[leftover_idx.?..]; | 262 | const leftover = source[leftover_idx.?..]; |
| 263 | if (decoder.pad_char) |pad_char| { | 263 | if (decoder.pad_char) |pad_char| { |
| 264 | const padding_len = acc_len / 2; | 264 | const padding_len = acc_len / 2; |
| 265 | var padding_chars: usize = 0; | 265 | var padding_chars: usize = 0; |
| ... | @@ -338,7 +338,7 @@ pub const Base64DecoderWithIgnore = struct { | ... | @@ -338,7 +338,7 @@ pub const Base64DecoderWithIgnore = struct { |
| 338 | if (decoder.pad_char != null and padding_len != 0) return error.InvalidPadding; | 338 | if (decoder.pad_char != null and padding_len != 0) return error.InvalidPadding; |
| 339 | return dest_idx; | 339 | return dest_idx; |
| 340 | } | 340 | } |
| 341 | var leftover = source[leftover_idx.?..]; | 341 | const leftover = source[leftover_idx.?..]; |
| 342 | if (decoder.pad_char) |pad_char| { | 342 | if (decoder.pad_char) |pad_char| { |
| 343 | var padding_chars: usize = 0; | 343 | var padding_chars: usize = 0; |
| 344 | for (leftover) |c| { | 344 | for (leftover) |c| { |
| ... | @@ -483,7 +483,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ | ... | @@ -483,7 +483,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ |
| 483 | // Base64Decoder | 483 | // Base64Decoder |
| 484 | { | 484 | { |
| 485 | var buffer: [0x100]u8 = undefined; | 485 | var buffer: [0x100]u8 = undefined; |
| 486 | var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)]; | 486 | const decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)]; |
| 487 | try codecs.Decoder.decode(decoded, expected_encoded); | 487 | try codecs.Decoder.decode(decoded, expected_encoded); |
| 488 | try testing.expectEqualSlices(u8, expected_decoded, decoded); | 488 | try testing.expectEqualSlices(u8, expected_decoded, decoded); |
| 489 | } | 489 | } |
| ... | @@ -492,8 +492,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ | ... | @@ -492,8 +492,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ |
| 492 | { | 492 | { |
| 493 | const decoder_ignore_nothing = codecs.decoderWithIgnore(""); | 493 | const decoder_ignore_nothing = codecs.decoderWithIgnore(""); |
| 494 | var buffer: [0x100]u8 = undefined; | 494 | var buffer: [0x100]u8 = undefined; |
| 495 | var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)]; | 495 | const decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)]; |
| 496 | var written = try decoder_ignore_nothing.decode(decoded, expected_encoded); | 496 | const written = try decoder_ignore_nothing.decode(decoded, expected_encoded); |
| 497 | try testing.expect(written <= decoded.len); | 497 | try testing.expect(written <= decoded.len); |
| 498 | try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); | 498 | try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); |
| 499 | } | 499 | } |
| ... | @@ -502,8 +502,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ | ... | @@ -502,8 +502,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ |
| 502 | fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void { | 502 | fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void { |
| 503 | const decoder_ignore_space = codecs.decoderWithIgnore(" "); | 503 | const decoder_ignore_space = codecs.decoderWithIgnore(" "); |
| 504 | var buffer: [0x100]u8 = undefined; | 504 | var buffer: [0x100]u8 = undefined; |
| 505 | var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)]; | 505 | const decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)]; |
| 506 | var written = try decoder_ignore_space.decode(decoded, encoded); | 506 | const written = try decoder_ignore_space.decode(decoded, encoded); |
| 507 | try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); | 507 | try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); |
| 508 | } | 508 | } |
| 509 | 509 | ||
| ... | @@ -511,7 +511,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void | ... | @@ -511,7 +511,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void |
| 511 | const decoder_ignore_space = codecs.decoderWithIgnore(" "); | 511 | const decoder_ignore_space = codecs.decoderWithIgnore(" "); |
| 512 | var buffer: [0x100]u8 = undefined; | 512 | var buffer: [0x100]u8 = undefined; |
| 513 | if (codecs.Decoder.calcSizeForSlice(encoded)) |decoded_size| { | 513 | if (codecs.Decoder.calcSizeForSlice(encoded)) |decoded_size| { |
| 514 | var decoded = buffer[0..decoded_size]; | 514 | const decoded = buffer[0..decoded_size]; |
| 515 | if (codecs.Decoder.decode(decoded, encoded)) |_| { | 515 | if (codecs.Decoder.decode(decoded, encoded)) |_| { |
| 516 | return error.ExpectedError; | 516 | return error.ExpectedError; |
| 517 | } else |err| if (err != expected_err) return err; | 517 | } else |err| if (err != expected_err) return err; |
| ... | @@ -525,7 +525,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void | ... | @@ -525,7 +525,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void |
| 525 | fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { | 525 | fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { |
| 526 | const decoder_ignore_space = codecs.decoderWithIgnore(" "); | 526 | const decoder_ignore_space = codecs.decoderWithIgnore(" "); |
| 527 | var buffer: [0x100]u8 = undefined; | 527 | var buffer: [0x100]u8 = undefined; |
| 528 | var decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1]; | 528 | const decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1]; |
| 529 | if (decoder_ignore_space.decode(decoded, encoded)) |_| { | 529 | if (decoder_ignore_space.decode(decoded, encoded)) |_| { |
| 530 | return error.ExpectedError; | 530 | return error.ExpectedError; |
| 531 | } else |err| if (err != error.NoSpaceLeft) return err; | 531 | } else |err| if (err != error.NoSpaceLeft) return err; |
| ... | @@ -534,7 +534,7 @@ fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { | ... | @@ -534,7 +534,7 @@ fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { |
| 534 | fn testFourBytesDestNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { | 534 | fn testFourBytesDestNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { |
| 535 | const decoder_ignore_space = codecs.decoderWithIgnore(" "); | 535 | const decoder_ignore_space = codecs.decoderWithIgnore(" "); |
| 536 | var buffer: [0x100]u8 = undefined; | 536 | var buffer: [0x100]u8 = undefined; |
| 537 | var decoded = buffer[0..4]; | 537 | const decoded = buffer[0..4]; |
| 538 | if (decoder_ignore_space.decode(decoded, encoded)) |_| { | 538 | if (decoder_ignore_space.decode(decoded, encoded)) |_| { |
| 539 | return error.ExpectedError; | 539 | return error.ExpectedError; |
| 540 | } else |err| if (err != error.NoSpaceLeft) return err; | 540 | } else |err| if (err != error.NoSpaceLeft) return err; |
lib/std/buf_map.zig+1-2| ... | @@ -15,8 +15,7 @@ pub const BufMap = struct { | ... | @@ -15,8 +15,7 @@ pub const BufMap = struct { |
| 15 | /// That allocator will be used for both backing allocations | 15 | /// That allocator will be used for both backing allocations |
| 16 | /// and string deduplication. | 16 | /// and string deduplication. |
| 17 | pub fn init(allocator: Allocator) BufMap { | 17 | pub fn init(allocator: Allocator) BufMap { |
| 18 | var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) }; | 18 | return .{ .hash_map = BufMapHashMap.init(allocator) }; |
| 19 | return self; | ||
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | /// Free the backing storage of the map, as well as all | 21 | /// Free the backing storage of the map, as well as all |
lib/std/buf_set.zig+4-5| ... | @@ -17,8 +17,7 @@ pub const BufSet = struct { | ... | @@ -17,8 +17,7 @@ pub const BufSet = struct { |
| 17 | /// be used internally for both backing allocations and | 17 | /// be used internally for both backing allocations and |
| 18 | /// string duplication. | 18 | /// string duplication. |
| 19 | pub fn init(a: Allocator) BufSet { | 19 | pub fn init(a: Allocator) BufSet { |
| 20 | var self = BufSet{ .hash_map = BufSetHashMap.init(a) }; | 20 | return .{ .hash_map = BufSetHashMap.init(a) }; |
| 21 | return self; | ||
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | /// Free a BufSet along with all stored keys. | 23 | /// Free a BufSet along with all stored keys. |
| ... | @@ -76,8 +75,8 @@ pub const BufSet = struct { | ... | @@ -76,8 +75,8 @@ pub const BufSet = struct { |
| 76 | self: *const BufSet, | 75 | self: *const BufSet, |
| 77 | new_allocator: Allocator, | 76 | new_allocator: Allocator, |
| 78 | ) Allocator.Error!BufSet { | 77 | ) Allocator.Error!BufSet { |
| 79 | var cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator); | 78 | const cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator); |
| 80 | var cloned = BufSet{ .hash_map = cloned_hashmap }; | 79 | const cloned = BufSet{ .hash_map = cloned_hashmap }; |
| 81 | var it = cloned.hash_map.keyIterator(); | 80 | var it = cloned.hash_map.keyIterator(); |
| 82 | while (it.next()) |key_ptr| { | 81 | while (it.next()) |key_ptr| { |
| 83 | key_ptr.* = try cloned.copy(key_ptr.*); | 82 | key_ptr.* = try cloned.copy(key_ptr.*); |
| ... | @@ -134,7 +133,7 @@ test "BufSet clone" { | ... | @@ -134,7 +133,7 @@ test "BufSet clone" { |
| 134 | } | 133 | } |
| 135 | 134 | ||
| 136 | test "BufSet.clone with arena" { | 135 | test "BufSet.clone with arena" { |
| 137 | var allocator = std.testing.allocator; | 136 | const allocator = std.testing.allocator; |
| 138 | var arena = std.heap.ArenaAllocator.init(allocator); | 137 | var arena = std.heap.ArenaAllocator.init(allocator); |
| 139 | defer arena.deinit(); | 138 | defer arena.deinit(); |
| 140 | 139 |
lib/std/builtin.zig+3-4| ... | @@ -777,9 +777,8 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr | ... | @@ -777,9 +777,8 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr |
| 777 | } | 777 | } |
| 778 | 778 | ||
| 779 | var fmt: [256]u8 = undefined; | 779 | var fmt: [256]u8 = undefined; |
| 780 | var slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg}); | 780 | const slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg}); |
| 781 | 781 | const len = try std.unicode.utf8ToUtf16Le(utf16, slice); | |
| 782 | var len = try std.unicode.utf8ToUtf16Le(utf16, slice); | ||
| 783 | 782 | ||
| 784 | utf16[len] = 0; | 783 | utf16[len] = 0; |
| 785 | 784 | ||
| ... | @@ -790,7 +789,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr | ... | @@ -790,7 +789,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr |
| 790 | }; | 789 | }; |
| 791 | 790 | ||
| 792 | var exit_size: usize = 0; | 791 | var exit_size: usize = 0; |
| 793 | var exit_data = ExitData.create_exit_data(msg, &exit_size) catch null; | 792 | const exit_data = ExitData.create_exit_data(msg, &exit_size) catch null; |
| 794 | 793 | ||
| 795 | if (exit_data) |data| { | 794 | if (exit_data) |data| { |
| 796 | if (uefi.system_table.std_err) |out| { | 795 | if (uefi.system_table.std_err) |out| { |
lib/std/child_process.zig+1-1| ... | @@ -847,7 +847,7 @@ pub const ChildProcess = struct { | ... | @@ -847,7 +847,7 @@ pub const ChildProcess = struct { |
| 847 | } | 847 | } |
| 848 | 848 | ||
| 849 | windowsCreateProcessPathExt(self.allocator, &dir_buf, &app_buf, PATHEXT, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| { | 849 | windowsCreateProcessPathExt(self.allocator, &dir_buf, &app_buf, PATHEXT, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| { |
| 850 | var original_err = switch (no_path_err) { | 850 | const original_err = switch (no_path_err) { |
| 851 | error.FileNotFound, error.InvalidExe, error.AccessDenied => |e| e, | 851 | error.FileNotFound, error.InvalidExe, error.AccessDenied => |e| e, |
| 852 | error.UnrecoverableInvalidExe => return error.InvalidExe, | 852 | error.UnrecoverableInvalidExe => return error.InvalidExe, |
| 853 | else => |e| return e, | 853 | else => |e| return e, |
lib/std/coff.zig+1-1| ... | @@ -1075,7 +1075,7 @@ pub const Coff = struct { | ... | @@ -1075,7 +1075,7 @@ pub const Coff = struct { |
| 1075 | var stream = std.io.fixedBufferStream(data); | 1075 | var stream = std.io.fixedBufferStream(data); |
| 1076 | const reader = stream.reader(); | 1076 | const reader = stream.reader(); |
| 1077 | try stream.seekTo(pe_pointer_offset); | 1077 | try stream.seekTo(pe_pointer_offset); |
| 1078 | var coff_header_offset = try reader.readInt(u32, .little); | 1078 | const coff_header_offset = try reader.readInt(u32, .little); |
| 1079 | try stream.seekTo(coff_header_offset); | 1079 | try stream.seekTo(coff_header_offset); |
| 1080 | var buf: [4]u8 = undefined; | 1080 | var buf: [4]u8 = undefined; |
| 1081 | try reader.readNoEof(&buf); | 1081 | try reader.readNoEof(&buf); |
lib/std/compress/deflate/bits_utils.zig+2-2| ... | @@ -15,7 +15,7 @@ test "bitReverse" { | ... | @@ -15,7 +15,7 @@ test "bitReverse" { |
| 15 | out: u16, | 15 | out: u16, |
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | var reverse_bits_tests = [_]ReverseBitsTest{ | 18 | const reverse_bits_tests = [_]ReverseBitsTest{ |
| 19 | .{ .in = 1, .bit_count = 1, .out = 1 }, | 19 | .{ .in = 1, .bit_count = 1, .out = 1 }, |
| 20 | .{ .in = 1, .bit_count = 2, .out = 2 }, | 20 | .{ .in = 1, .bit_count = 2, .out = 2 }, |
| 21 | .{ .in = 1, .bit_count = 3, .out = 4 }, | 21 | .{ .in = 1, .bit_count = 3, .out = 4 }, |
| ... | @@ -27,7 +27,7 @@ test "bitReverse" { | ... | @@ -27,7 +27,7 @@ test "bitReverse" { |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | for (reverse_bits_tests) |h| { | 29 | for (reverse_bits_tests) |h| { |
| 30 | var v = bitReverse(u16, h.in, h.bit_count); | 30 | const v = bitReverse(u16, h.in, h.bit_count); |
| 31 | try std.testing.expectEqual(h.out, v); | 31 | try std.testing.expectEqual(h.out, v); |
| 32 | } | 32 | } |
| 33 | } | 33 | } |
lib/std/compress/deflate/compressor.zig+25-25| ... | @@ -156,8 +156,8 @@ fn levels(compression: Compression) CompressionLevel { | ... | @@ -156,8 +156,8 @@ fn levels(compression: Compression) CompressionLevel { |
| 156 | // up to length 'max'. Both slices must be at least 'max' | 156 | // up to length 'max'. Both slices must be at least 'max' |
| 157 | // bytes in size. | 157 | // bytes in size. |
| 158 | fn matchLen(a: []u8, b: []u8, max: u32) u32 { | 158 | fn matchLen(a: []u8, b: []u8, max: u32) u32 { |
| 159 | var bounded_a = a[0..max]; | 159 | const bounded_a = a[0..max]; |
| 160 | var bounded_b = b[0..max]; | 160 | const bounded_b = b[0..max]; |
| 161 | for (bounded_a, 0..) |av, i| { | 161 | for (bounded_a, 0..) |av, i| { |
| 162 | if (bounded_b[i] != av) { | 162 | if (bounded_b[i] != av) { |
| 163 | return @as(u32, @intCast(i)); | 163 | return @as(u32, @intCast(i)); |
| ... | @@ -191,7 +191,7 @@ fn bulkHash4(b: []u8, dst: []u32) u32 { | ... | @@ -191,7 +191,7 @@ fn bulkHash4(b: []u8, dst: []u32) u32 { |
| 191 | @as(u32, b[0]) << 24; | 191 | @as(u32, b[0]) << 24; |
| 192 | 192 | ||
| 193 | dst[0] = (hb *% hash_mul) >> (32 - hash_bits); | 193 | dst[0] = (hb *% hash_mul) >> (32 - hash_bits); |
| 194 | var end = b.len - min_match_length + 1; | 194 | const end = b.len - min_match_length + 1; |
| 195 | var i: u32 = 1; | 195 | var i: u32 = 1; |
| 196 | while (i < end) : (i += 1) { | 196 | while (i < end) : (i += 1) { |
| 197 | hb = (hb << 8) | @as(u32, b[i + 3]); | 197 | hb = (hb << 8) | @as(u32, b[i + 3]); |
| ... | @@ -305,7 +305,7 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -305,7 +305,7 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 305 | } | 305 | } |
| 306 | self.hash_offset += window_size; | 306 | self.hash_offset += window_size; |
| 307 | if (self.hash_offset > max_hash_offset) { | 307 | if (self.hash_offset > max_hash_offset) { |
| 308 | var delta = self.hash_offset - 1; | 308 | const delta = self.hash_offset - 1; |
| 309 | self.hash_offset -= delta; | 309 | self.hash_offset -= delta; |
| 310 | self.chain_head -|= delta; | 310 | self.chain_head -|= delta; |
| 311 | 311 | ||
| ... | @@ -369,31 +369,31 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -369,31 +369,31 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 369 | } | 369 | } |
| 370 | // Add all to window. | 370 | // Add all to window. |
| 371 | @memcpy(self.window[0..b.len], b); | 371 | @memcpy(self.window[0..b.len], b); |
| 372 | var n = b.len; | 372 | const n = b.len; |
| 373 | 373 | ||
| 374 | // Calculate 256 hashes at the time (more L1 cache hits) | 374 | // Calculate 256 hashes at the time (more L1 cache hits) |
| 375 | var loops = (n + 256 - min_match_length) / 256; | 375 | const loops = (n + 256 - min_match_length) / 256; |
| 376 | var j: usize = 0; | 376 | var j: usize = 0; |
| 377 | while (j < loops) : (j += 1) { | 377 | while (j < loops) : (j += 1) { |
| 378 | var index = j * 256; | 378 | const index = j * 256; |
| 379 | var end = index + 256 + min_match_length - 1; | 379 | var end = index + 256 + min_match_length - 1; |
| 380 | if (end > n) { | 380 | if (end > n) { |
| 381 | end = n; | 381 | end = n; |
| 382 | } | 382 | } |
| 383 | var to_check = self.window[index..end]; | 383 | const to_check = self.window[index..end]; |
| 384 | var dst_size = to_check.len - min_match_length + 1; | 384 | const dst_size = to_check.len - min_match_length + 1; |
| 385 | 385 | ||
| 386 | if (dst_size <= 0) { | 386 | if (dst_size <= 0) { |
| 387 | continue; | 387 | continue; |
| 388 | } | 388 | } |
| 389 | 389 | ||
| 390 | var dst = self.hash_match[0..dst_size]; | 390 | const dst = self.hash_match[0..dst_size]; |
| 391 | _ = self.bulk_hasher(to_check, dst); | 391 | _ = self.bulk_hasher(to_check, dst); |
| 392 | var new_h: u32 = 0; | 392 | var new_h: u32 = 0; |
| 393 | for (dst, 0..) |val, i| { | 393 | for (dst, 0..) |val, i| { |
| 394 | var di = i + index; | 394 | const di = i + index; |
| 395 | new_h = val; | 395 | new_h = val; |
| 396 | var hh = &self.hash_head[new_h & hash_mask]; | 396 | const hh = &self.hash_head[new_h & hash_mask]; |
| 397 | // Get previous value with the same hash. | 397 | // Get previous value with the same hash. |
| 398 | // Our chain should point to the previous value. | 398 | // Our chain should point to the previous value. |
| 399 | self.hash_prev[di & window_mask] = hh.*; | 399 | self.hash_prev[di & window_mask] = hh.*; |
| ... | @@ -447,13 +447,13 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -447,13 +447,13 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | var w_end = win[pos + length]; | 449 | var w_end = win[pos + length]; |
| 450 | var w_pos = win[pos..]; | 450 | const w_pos = win[pos..]; |
| 451 | var min_index = pos -| window_size; | 451 | const min_index = pos -| window_size; |
| 452 | 452 | ||
| 453 | var i = prev_head; | 453 | var i = prev_head; |
| 454 | while (tries > 0) : (tries -= 1) { | 454 | while (tries > 0) : (tries -= 1) { |
| 455 | if (w_end == win[i + length]) { | 455 | if (w_end == win[i + length]) { |
| 456 | var n = matchLen(win[i..], w_pos, min_match_look); | 456 | const n = matchLen(win[i..], w_pos, min_match_look); |
| 457 | 457 | ||
| 458 | if (n > length and (n > min_match_length or pos - i <= 4096)) { | 458 | if (n > length and (n > min_match_length or pos - i <= 4096)) { |
| 459 | length = n; | 459 | length = n; |
| ... | @@ -565,7 +565,7 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -565,7 +565,7 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 565 | while (true) { | 565 | while (true) { |
| 566 | assert(self.index <= self.window_end); | 566 | assert(self.index <= self.window_end); |
| 567 | 567 | ||
| 568 | var lookahead = self.window_end -| self.index; | 568 | const lookahead = self.window_end -| self.index; |
| 569 | if (lookahead < min_match_length + max_match_length) { | 569 | if (lookahead < min_match_length + max_match_length) { |
| 570 | if (!self.sync) { | 570 | if (!self.sync) { |
| 571 | break; | 571 | break; |
| ... | @@ -590,16 +590,16 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -590,16 +590,16 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 590 | if (self.index < self.max_insert_index) { | 590 | if (self.index < self.max_insert_index) { |
| 591 | // Update the hash | 591 | // Update the hash |
| 592 | self.hash = hash4(self.window[self.index .. self.index + min_match_length]); | 592 | self.hash = hash4(self.window[self.index .. self.index + min_match_length]); |
| 593 | var hh = &self.hash_head[self.hash & hash_mask]; | 593 | const hh = &self.hash_head[self.hash & hash_mask]; |
| 594 | self.chain_head = @as(u32, @intCast(hh.*)); | 594 | self.chain_head = @as(u32, @intCast(hh.*)); |
| 595 | self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head)); | 595 | self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head)); |
| 596 | hh.* = @as(u32, @intCast(self.index + self.hash_offset)); | 596 | hh.* = @as(u32, @intCast(self.index + self.hash_offset)); |
| 597 | } | 597 | } |
| 598 | var prev_length = self.length; | 598 | const prev_length = self.length; |
| 599 | var prev_offset = self.offset; | 599 | const prev_offset = self.offset; |
| 600 | self.length = min_match_length - 1; | 600 | self.length = min_match_length - 1; |
| 601 | self.offset = 0; | 601 | self.offset = 0; |
| 602 | var min_index = self.index -| window_size; | 602 | const min_index = self.index -| window_size; |
| 603 | 603 | ||
| 604 | if (self.hash_offset <= self.chain_head and | 604 | if (self.hash_offset <= self.chain_head and |
| 605 | self.chain_head - self.hash_offset >= min_index and | 605 | self.chain_head - self.hash_offset >= min_index and |
| ... | @@ -610,7 +610,7 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -610,7 +610,7 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 610 | prev_length < self.compression_level.lazy)) | 610 | prev_length < self.compression_level.lazy)) |
| 611 | { | 611 | { |
| 612 | { | 612 | { |
| 613 | var fmatch = self.findMatch( | 613 | const fmatch = self.findMatch( |
| 614 | self.index, | 614 | self.index, |
| 615 | self.chain_head -| self.hash_offset, | 615 | self.chain_head -| self.hash_offset, |
| 616 | min_match_length - 1, | 616 | min_match_length - 1, |
| ... | @@ -658,7 +658,7 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -658,7 +658,7 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 658 | self.hash = hash4(self.window[index .. index + min_match_length]); | 658 | self.hash = hash4(self.window[index .. index + min_match_length]); |
| 659 | // Get previous value with the same hash. | 659 | // Get previous value with the same hash. |
| 660 | // Our chain should point to the previous value. | 660 | // Our chain should point to the previous value. |
| 661 | var hh = &self.hash_head[self.hash & hash_mask]; | 661 | const hh = &self.hash_head[self.hash & hash_mask]; |
| 662 | self.hash_prev[index & window_mask] = hh.*; | 662 | self.hash_prev[index & window_mask] = hh.*; |
| 663 | // Set the head of the hash chain to us. | 663 | // Set the head of the hash chain to us. |
| 664 | hh.* = @as(u32, @intCast(index + self.hash_offset)); | 664 | hh.* = @as(u32, @intCast(index + self.hash_offset)); |
| ... | @@ -740,7 +740,7 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -740,7 +740,7 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 740 | // compressed form of data to its underlying writer. | 740 | // compressed form of data to its underlying writer. |
| 741 | while (buf.len > 0) { | 741 | while (buf.len > 0) { |
| 742 | try self.step(); | 742 | try self.step(); |
| 743 | var filled = self.fill(buf); | 743 | const filled = self.fill(buf); |
| 744 | buf = buf[filled..]; | 744 | buf = buf[filled..]; |
| 745 | } | 745 | } |
| 746 | 746 | ||
| ... | @@ -1097,12 +1097,12 @@ test "bulkHash4" { | ... | @@ -1097,12 +1097,12 @@ test "bulkHash4" { |
| 1097 | while (j < out.len) : (j += 1) { | 1097 | while (j < out.len) : (j += 1) { |
| 1098 | var y = out[0..j]; | 1098 | var y = out[0..j]; |
| 1099 | 1099 | ||
| 1100 | var dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1); | 1100 | const dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1); |
| 1101 | defer testing.allocator.free(dst); | 1101 | defer testing.allocator.free(dst); |
| 1102 | 1102 | ||
| 1103 | _ = bulkHash4(y, dst); | 1103 | _ = bulkHash4(y, dst); |
| 1104 | for (dst, 0..) |got, i| { | 1104 | for (dst, 0..) |got, i| { |
| 1105 | var want = hash4(y[i..]); | 1105 | const want = hash4(y[i..]); |
| 1106 | try testing.expectEqual(want, got); | 1106 | try testing.expectEqual(want, got); |
| 1107 | } | 1107 | } |
| 1108 | } | 1108 | } |
lib/std/compress/deflate/compressor_test.zig+16-16| ... | @@ -27,7 +27,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { | ... | @@ -27,7 +27,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { |
| 27 | var whole_buf = std.ArrayList(u8).init(testing.allocator); | 27 | var whole_buf = std.ArrayList(u8).init(testing.allocator); |
| 28 | defer whole_buf.deinit(); | 28 | defer whole_buf.deinit(); |
| 29 | 29 | ||
| 30 | var multi_writer = io.multiWriter(.{ | 30 | const multi_writer = io.multiWriter(.{ |
| 31 | divided_buf.writer(), | 31 | divided_buf.writer(), |
| 32 | whole_buf.writer(), | 32 | whole_buf.writer(), |
| 33 | }).writer(); | 33 | }).writer(); |
| ... | @@ -48,7 +48,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { | ... | @@ -48,7 +48,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { |
| 48 | defer decomp.deinit(); | 48 | defer decomp.deinit(); |
| 49 | 49 | ||
| 50 | // Write first half of the input and flush() | 50 | // Write first half of the input and flush() |
| 51 | var half: usize = (input.len + 1) / 2; | 51 | const half: usize = (input.len + 1) / 2; |
| 52 | var half_len: usize = half - 0; | 52 | var half_len: usize = half - 0; |
| 53 | { | 53 | { |
| 54 | _ = try comp.writer().writeAll(input[0..half]); | 54 | _ = try comp.writer().writeAll(input[0..half]); |
| ... | @@ -57,10 +57,10 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { | ... | @@ -57,10 +57,10 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { |
| 57 | try comp.flush(); | 57 | try comp.flush(); |
| 58 | 58 | ||
| 59 | // Read back | 59 | // Read back |
| 60 | var decompressed = try testing.allocator.alloc(u8, half_len); | 60 | const decompressed = try testing.allocator.alloc(u8, half_len); |
| 61 | defer testing.allocator.free(decompressed); | 61 | defer testing.allocator.free(decompressed); |
| 62 | 62 | ||
| 63 | var read = try decomp.reader().readAll(decompressed); // read at least half | 63 | const read = try decomp.reader().readAll(decompressed); // read at least half |
| 64 | try testing.expectEqual(half_len, read); | 64 | try testing.expectEqual(half_len, read); |
| 65 | try testing.expectEqualSlices(u8, input[0..half], decompressed); | 65 | try testing.expectEqualSlices(u8, input[0..half], decompressed); |
| 66 | } | 66 | } |
| ... | @@ -74,7 +74,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { | ... | @@ -74,7 +74,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { |
| 74 | try comp.close(); | 74 | try comp.close(); |
| 75 | 75 | ||
| 76 | // Read back | 76 | // Read back |
| 77 | var decompressed = try testing.allocator.alloc(u8, half_len); | 77 | const decompressed = try testing.allocator.alloc(u8, half_len); |
| 78 | defer testing.allocator.free(decompressed); | 78 | defer testing.allocator.free(decompressed); |
| 79 | 79 | ||
| 80 | var read = try decomp.reader().readAll(decompressed); | 80 | var read = try decomp.reader().readAll(decompressed); |
| ... | @@ -94,11 +94,11 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { | ... | @@ -94,11 +94,11 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { |
| 94 | try comp.close(); | 94 | try comp.close(); |
| 95 | 95 | ||
| 96 | // stream should work for ordinary reader too (reading whole_buf in one go) | 96 | // stream should work for ordinary reader too (reading whole_buf in one go) |
| 97 | var whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader(); | 97 | const whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader(); |
| 98 | var decomp = try decompressor(testing.allocator, whole_buf_reader, null); | 98 | var decomp = try decompressor(testing.allocator, whole_buf_reader, null); |
| 99 | defer decomp.deinit(); | 99 | defer decomp.deinit(); |
| 100 | 100 | ||
| 101 | var decompressed = try testing.allocator.alloc(u8, input.len); | 101 | const decompressed = try testing.allocator.alloc(u8, input.len); |
| 102 | defer testing.allocator.free(decompressed); | 102 | defer testing.allocator.free(decompressed); |
| 103 | 103 | ||
| 104 | _ = try decomp.reader().readAll(decompressed); | 104 | _ = try decomp.reader().readAll(decompressed); |
| ... | @@ -125,10 +125,10 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li | ... | @@ -125,10 +125,10 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li |
| 125 | var decomp = try decompressor(testing.allocator, fib.reader(), null); | 125 | var decomp = try decompressor(testing.allocator, fib.reader(), null); |
| 126 | defer decomp.deinit(); | 126 | defer decomp.deinit(); |
| 127 | 127 | ||
| 128 | var decompressed = try testing.allocator.alloc(u8, input.len); | 128 | const decompressed = try testing.allocator.alloc(u8, input.len); |
| 129 | defer testing.allocator.free(decompressed); | 129 | defer testing.allocator.free(decompressed); |
| 130 | 130 | ||
| 131 | var read: usize = try decomp.reader().readAll(decompressed); | 131 | const read: usize = try decomp.reader().readAll(decompressed); |
| 132 | try testing.expectEqual(input.len, read); | 132 | try testing.expectEqual(input.len, read); |
| 133 | try testing.expectEqualSlices(u8, input, decompressed); | 133 | try testing.expectEqualSlices(u8, input, decompressed); |
| 134 | 134 | ||
| ... | @@ -153,7 +153,7 @@ fn testToFromWithLimit(input: []const u8, limit: [11]u32) !void { | ... | @@ -153,7 +153,7 @@ fn testToFromWithLimit(input: []const u8, limit: [11]u32) !void { |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | test "deflate/inflate" { | 155 | test "deflate/inflate" { |
| 156 | var limits = [_]u32{0} ** 11; | 156 | const limits = [_]u32{0} ** 11; |
| 157 | 157 | ||
| 158 | var test0 = [_]u8{}; | 158 | var test0 = [_]u8{}; |
| 159 | var test1 = [_]u8{0x11}; | 159 | var test1 = [_]u8{0x11}; |
| ... | @@ -313,7 +313,7 @@ test "decompressor dictionary" { | ... | @@ -313,7 +313,7 @@ test "decompressor dictionary" { |
| 313 | try comp.writer().writeAll(text); | 313 | try comp.writer().writeAll(text); |
| 314 | try comp.close(); | 314 | try comp.close(); |
| 315 | 315 | ||
| 316 | var decompressed = try testing.allocator.alloc(u8, text.len); | 316 | const decompressed = try testing.allocator.alloc(u8, text.len); |
| 317 | defer testing.allocator.free(decompressed); | 317 | defer testing.allocator.free(decompressed); |
| 318 | 318 | ||
| 319 | var decomp = try decompressor( | 319 | var decomp = try decompressor( |
| ... | @@ -432,7 +432,7 @@ test "deflate/inflate string" { | ... | @@ -432,7 +432,7 @@ test "deflate/inflate string" { |
| 432 | }; | 432 | }; |
| 433 | 433 | ||
| 434 | inline for (deflate_inflate_string_tests) |t| { | 434 | inline for (deflate_inflate_string_tests) |t| { |
| 435 | var golden = @embedFile("testdata/" ++ t.filename); | 435 | const golden = @embedFile("testdata/" ++ t.filename); |
| 436 | try testToFromWithLimit(golden, t.limit); | 436 | try testToFromWithLimit(golden, t.limit); |
| 437 | } | 437 | } |
| 438 | } | 438 | } |
| ... | @@ -466,14 +466,14 @@ test "inflate reset" { | ... | @@ -466,14 +466,14 @@ test "inflate reset" { |
| 466 | var decomp = try decompressor(testing.allocator, fib.reader(), null); | 466 | var decomp = try decompressor(testing.allocator, fib.reader(), null); |
| 467 | defer decomp.deinit(); | 467 | defer decomp.deinit(); |
| 468 | 468 | ||
| 469 | var decompressed_0: []u8 = try decomp.reader() | 469 | const decompressed_0: []u8 = try decomp.reader() |
| 470 | .readAllAlloc(testing.allocator, math.maxInt(usize)); | 470 | .readAllAlloc(testing.allocator, math.maxInt(usize)); |
| 471 | defer testing.allocator.free(decompressed_0); | 471 | defer testing.allocator.free(decompressed_0); |
| 472 | 472 | ||
| 473 | fib = io.fixedBufferStream(compressed_strings[1].items); | 473 | fib = io.fixedBufferStream(compressed_strings[1].items); |
| 474 | try decomp.reset(fib.reader(), null); | 474 | try decomp.reset(fib.reader(), null); |
| 475 | 475 | ||
| 476 | var decompressed_1: []u8 = try decomp.reader() | 476 | const decompressed_1: []u8 = try decomp.reader() |
| 477 | .readAllAlloc(testing.allocator, math.maxInt(usize)); | 477 | .readAllAlloc(testing.allocator, math.maxInt(usize)); |
| 478 | defer testing.allocator.free(decompressed_1); | 478 | defer testing.allocator.free(decompressed_1); |
| 479 | 479 | ||
| ... | @@ -513,14 +513,14 @@ test "inflate reset dictionary" { | ... | @@ -513,14 +513,14 @@ test "inflate reset dictionary" { |
| 513 | var decomp = try decompressor(testing.allocator, fib.reader(), dict); | 513 | var decomp = try decompressor(testing.allocator, fib.reader(), dict); |
| 514 | defer decomp.deinit(); | 514 | defer decomp.deinit(); |
| 515 | 515 | ||
| 516 | var decompressed_0: []u8 = try decomp.reader() | 516 | const decompressed_0: []u8 = try decomp.reader() |
| 517 | .readAllAlloc(testing.allocator, math.maxInt(usize)); | 517 | .readAllAlloc(testing.allocator, math.maxInt(usize)); |
| 518 | defer testing.allocator.free(decompressed_0); | 518 | defer testing.allocator.free(decompressed_0); |
| 519 | 519 | ||
| 520 | fib = io.fixedBufferStream(compressed_strings[1].items); | 520 | fib = io.fixedBufferStream(compressed_strings[1].items); |
| 521 | try decomp.reset(fib.reader(), dict); | 521 | try decomp.reset(fib.reader(), dict); |
| 522 | 522 | ||
| 523 | var decompressed_1: []u8 = try decomp.reader() | 523 | const decompressed_1: []u8 = try decomp.reader() |
| 524 | .readAllAlloc(testing.allocator, math.maxInt(usize)); | 524 | .readAllAlloc(testing.allocator, math.maxInt(usize)); |
| 525 | defer testing.allocator.free(decompressed_1); | 525 | defer testing.allocator.free(decompressed_1); |
| 526 | 526 |
lib/std/compress/deflate/decompressor.zig+25-25| ... | @@ -136,11 +136,11 @@ const HuffmanDecoder = struct { | ... | @@ -136,11 +136,11 @@ const HuffmanDecoder = struct { |
| 136 | 136 | ||
| 137 | self.min = min; | 137 | self.min = min; |
| 138 | if (max > huffman_chunk_bits) { | 138 | if (max > huffman_chunk_bits) { |
| 139 | var num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits)); | 139 | const num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits)); |
| 140 | self.link_mask = @as(u32, @intCast(num_links - 1)); | 140 | self.link_mask = @as(u32, @intCast(num_links - 1)); |
| 141 | 141 | ||
| 142 | // create link tables | 142 | // create link tables |
| 143 | var link = next_code[huffman_chunk_bits + 1] >> 1; | 143 | const link = next_code[huffman_chunk_bits + 1] >> 1; |
| 144 | self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link); | 144 | self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link); |
| 145 | self.sub_chunks = ArrayList(u32).init(self.allocator); | 145 | self.sub_chunks = ArrayList(u32).init(self.allocator); |
| 146 | self.initialized = true; | 146 | self.initialized = true; |
| ... | @@ -148,7 +148,7 @@ const HuffmanDecoder = struct { | ... | @@ -148,7 +148,7 @@ const HuffmanDecoder = struct { |
| 148 | while (j < huffman_num_chunks) : (j += 1) { | 148 | while (j < huffman_num_chunks) : (j += 1) { |
| 149 | var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16))); | 149 | var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16))); |
| 150 | reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits)); | 150 | reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits)); |
| 151 | var off = j - @as(u32, @intCast(link)); | 151 | const off = j - @as(u32, @intCast(link)); |
| 152 | if (sanity) { | 152 | if (sanity) { |
| 153 | // check we are not overwriting an existing chunk | 153 | // check we are not overwriting an existing chunk |
| 154 | assert(self.chunks[reverse] == 0); | 154 | assert(self.chunks[reverse] == 0); |
| ... | @@ -168,9 +168,9 @@ const HuffmanDecoder = struct { | ... | @@ -168,9 +168,9 @@ const HuffmanDecoder = struct { |
| 168 | if (n == 0) { | 168 | if (n == 0) { |
| 169 | continue; | 169 | continue; |
| 170 | } | 170 | } |
| 171 | var ncode = next_code[n]; | 171 | const ncode = next_code[n]; |
| 172 | next_code[n] += 1; | 172 | next_code[n] += 1; |
| 173 | var chunk = @as(u16, @intCast((li << huffman_value_shift) | n)); | 173 | const chunk = @as(u16, @intCast((li << huffman_value_shift) | n)); |
| 174 | var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16))); | 174 | var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16))); |
| 175 | reverse >>= @as(u4, @intCast(16 - n)); | 175 | reverse >>= @as(u4, @intCast(16 - n)); |
| 176 | if (n <= huffman_chunk_bits) { | 176 | if (n <= huffman_chunk_bits) { |
| ... | @@ -187,14 +187,14 @@ const HuffmanDecoder = struct { | ... | @@ -187,14 +187,14 @@ const HuffmanDecoder = struct { |
| 187 | self.chunks[off] = chunk; | 187 | self.chunks[off] = chunk; |
| 188 | } | 188 | } |
| 189 | } else { | 189 | } else { |
| 190 | var j = reverse & (huffman_num_chunks - 1); | 190 | const j = reverse & (huffman_num_chunks - 1); |
| 191 | if (sanity) { | 191 | if (sanity) { |
| 192 | // Expect an indirect chunk | 192 | // Expect an indirect chunk |
| 193 | assert(self.chunks[j] & huffman_count_mask == huffman_chunk_bits + 1); | 193 | assert(self.chunks[j] & huffman_count_mask == huffman_chunk_bits + 1); |
| 194 | // Longer codes should have been | 194 | // Longer codes should have been |
| 195 | // associated with a link table above. | 195 | // associated with a link table above. |
| 196 | } | 196 | } |
| 197 | var value = self.chunks[j] >> huffman_value_shift; | 197 | const value = self.chunks[j] >> huffman_value_shift; |
| 198 | var link_tab = self.links[value]; | 198 | var link_tab = self.links[value]; |
| 199 | reverse >>= huffman_chunk_bits; | 199 | reverse >>= huffman_chunk_bits; |
| 200 | var off = reverse; | 200 | var off = reverse; |
| ... | @@ -354,8 +354,8 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -354,8 +354,8 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 354 | fn init(allocator: Allocator, in_reader: ReaderType, dict: ?[]const u8) !Self { | 354 | fn init(allocator: Allocator, in_reader: ReaderType, dict: ?[]const u8) !Self { |
| 355 | fixed_huffman_decoder = try fixedHuffmanDecoderInit(allocator); | 355 | fixed_huffman_decoder = try fixedHuffmanDecoderInit(allocator); |
| 356 | 356 | ||
| 357 | var bits = try allocator.create([max_num_lit + max_num_dist]u32); | 357 | const bits = try allocator.create([max_num_lit + max_num_dist]u32); |
| 358 | var codebits = try allocator.create([num_codes]u32); | 358 | const codebits = try allocator.create([num_codes]u32); |
| 359 | 359 | ||
| 360 | var dd = ddec.DictDecoder{}; | 360 | var dd = ddec.DictDecoder{}; |
| 361 | try dd.init(allocator, max_match_offset, dict); | 361 | try dd.init(allocator, max_match_offset, dict); |
| ... | @@ -416,7 +416,7 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -416,7 +416,7 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 416 | } | 416 | } |
| 417 | self.final = self.b & 1 == 1; | 417 | self.final = self.b & 1 == 1; |
| 418 | self.b >>= 1; | 418 | self.b >>= 1; |
| 419 | var typ = self.b & 3; | 419 | const typ = self.b & 3; |
| 420 | self.b >>= 2; | 420 | self.b >>= 2; |
| 421 | self.nb -= 1 + 2; | 421 | self.nb -= 1 + 2; |
| 422 | switch (typ) { | 422 | switch (typ) { |
| ... | @@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 494 | while (self.nb < 5 + 5 + 4) { | 494 | while (self.nb < 5 + 5 + 4) { |
| 495 | try self.moreBits(); | 495 | try self.moreBits(); |
| 496 | } | 496 | } |
| 497 | var nlit = @as(u32, @intCast(self.b & 0x1F)) + 257; | 497 | const nlit = @as(u32, @intCast(self.b & 0x1F)) + 257; |
| 498 | if (nlit > max_num_lit) { | 498 | if (nlit > max_num_lit) { |
| 499 | corrupt_input_error_offset = self.roffset; | 499 | corrupt_input_error_offset = self.roffset; |
| 500 | self.err = InflateError.CorruptInput; | 500 | self.err = InflateError.CorruptInput; |
| 501 | return InflateError.CorruptInput; | 501 | return InflateError.CorruptInput; |
| 502 | } | 502 | } |
| 503 | self.b >>= 5; | 503 | self.b >>= 5; |
| 504 | var ndist = @as(u32, @intCast(self.b & 0x1F)) + 1; | 504 | const ndist = @as(u32, @intCast(self.b & 0x1F)) + 1; |
| 505 | if (ndist > max_num_dist) { | 505 | if (ndist > max_num_dist) { |
| 506 | corrupt_input_error_offset = self.roffset; | 506 | corrupt_input_error_offset = self.roffset; |
| 507 | self.err = InflateError.CorruptInput; | 507 | self.err = InflateError.CorruptInput; |
| 508 | return InflateError.CorruptInput; | 508 | return InflateError.CorruptInput; |
| 509 | } | 509 | } |
| 510 | self.b >>= 5; | 510 | self.b >>= 5; |
| 511 | var nclen = @as(u32, @intCast(self.b & 0xF)) + 4; | 511 | const nclen = @as(u32, @intCast(self.b & 0xF)) + 4; |
| 512 | // num_codes is 19, so nclen is always valid. | 512 | // num_codes is 19, so nclen is always valid. |
| 513 | self.b >>= 4; | 513 | self.b >>= 4; |
| 514 | self.nb -= 5 + 5 + 4; | 514 | self.nb -= 5 + 5 + 4; |
| ... | @@ -536,9 +536,9 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -536,9 +536,9 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 536 | // HLIT + 257 code lengths, HDIST + 1 code lengths, | 536 | // HLIT + 257 code lengths, HDIST + 1 code lengths, |
| 537 | // using the code length Huffman code. | 537 | // using the code length Huffman code. |
| 538 | i = 0; | 538 | i = 0; |
| 539 | var n = nlit + ndist; | 539 | const n = nlit + ndist; |
| 540 | while (i < n) { | 540 | while (i < n) { |
| 541 | var x = try self.huffSym(&self.hd1); | 541 | const x = try self.huffSym(&self.hd1); |
| 542 | if (x < 16) { | 542 | if (x < 16) { |
| 543 | // Actual length. | 543 | // Actual length. |
| 544 | self.bits[i] = x; | 544 | self.bits[i] = x; |
| ... | @@ -618,7 +618,7 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -618,7 +618,7 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 618 | switch (self.step_state) { | 618 | switch (self.step_state) { |
| 619 | .init => { | 619 | .init => { |
| 620 | // Read literal and/or (length, distance) according to RFC section 3.2.3. | 620 | // Read literal and/or (length, distance) according to RFC section 3.2.3. |
| 621 | var v = try self.huffSym(self.hl.?); | 621 | const v = try self.huffSym(self.hl.?); |
| 622 | var n: u32 = 0; // number of bits extra | 622 | var n: u32 = 0; // number of bits extra |
| 623 | var length: u32 = 0; | 623 | var length: u32 = 0; |
| 624 | switch (v) { | 624 | switch (v) { |
| ... | @@ -699,7 +699,7 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -699,7 +699,7 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 699 | switch (dist) { | 699 | switch (dist) { |
| 700 | 0...3 => dist += 1, | 700 | 0...3 => dist += 1, |
| 701 | 4...max_num_dist - 1 => { // 4...29 | 701 | 4...max_num_dist - 1 => { // 4...29 |
| 702 | var nb = @as(u32, @intCast(dist - 2)) >> 1; | 702 | const nb = @as(u32, @intCast(dist - 2)) >> 1; |
| 703 | // have 1 bit in bottom of dist, need nb more. | 703 | // have 1 bit in bottom of dist, need nb more. |
| 704 | var extra = (dist & 1) << @as(u5, @intCast(nb)); | 704 | var extra = (dist & 1) << @as(u5, @intCast(nb)); |
| 705 | while (self.nb < nb) { | 705 | while (self.nb < nb) { |
| ... | @@ -757,14 +757,14 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -757,14 +757,14 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 757 | self.b = 0; | 757 | self.b = 0; |
| 758 | 758 | ||
| 759 | // Length then ones-complement of length. | 759 | // Length then ones-complement of length. |
| 760 | var nr: u32 = 4; | 760 | const nr: u32 = 4; |
| 761 | self.inner_reader.readNoEof(self.buf[0..nr]) catch { | 761 | self.inner_reader.readNoEof(self.buf[0..nr]) catch { |
| 762 | self.err = InflateError.UnexpectedEndOfStream; | 762 | self.err = InflateError.UnexpectedEndOfStream; |
| 763 | return InflateError.UnexpectedEndOfStream; | 763 | return InflateError.UnexpectedEndOfStream; |
| 764 | }; | 764 | }; |
| 765 | self.roffset += @as(u64, @intCast(nr)); | 765 | self.roffset += @as(u64, @intCast(nr)); |
| 766 | var n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8; | 766 | const n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8; |
| 767 | var nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8; | 767 | const nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8; |
| 768 | if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) { | 768 | if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) { |
| 769 | corrupt_input_error_offset = self.roffset; | 769 | corrupt_input_error_offset = self.roffset; |
| 770 | self.err = InflateError.CorruptInput; | 770 | self.err = InflateError.CorruptInput; |
| ... | @@ -789,7 +789,7 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -789,7 +789,7 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 789 | buf = buf[0..self.copy_len]; | 789 | buf = buf[0..self.copy_len]; |
| 790 | } | 790 | } |
| 791 | 791 | ||
| 792 | var cnt = try self.inner_reader.read(buf); | 792 | const cnt = try self.inner_reader.read(buf); |
| 793 | if (cnt < buf.len) { | 793 | if (cnt < buf.len) { |
| 794 | self.err = InflateError.UnexpectedEndOfStream; | 794 | self.err = InflateError.UnexpectedEndOfStream; |
| 795 | } | 795 | } |
| ... | @@ -819,7 +819,7 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -819,7 +819,7 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 819 | } | 819 | } |
| 820 | 820 | ||
| 821 | fn moreBits(self: *Self) InflateError!void { | 821 | fn moreBits(self: *Self) InflateError!void { |
| 822 | var c = self.inner_reader.readByte() catch |e| { | 822 | const c = self.inner_reader.readByte() catch |e| { |
| 823 | if (e == error.EndOfStream) { | 823 | if (e == error.EndOfStream) { |
| 824 | return InflateError.UnexpectedEndOfStream; | 824 | return InflateError.UnexpectedEndOfStream; |
| 825 | } | 825 | } |
| ... | @@ -845,7 +845,7 @@ pub fn Decompressor(comptime ReaderType: type) type { | ... | @@ -845,7 +845,7 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 845 | var b = self.b; | 845 | var b = self.b; |
| 846 | while (true) { | 846 | while (true) { |
| 847 | while (nb < n) { | 847 | while (nb < n) { |
| 848 | var c = self.inner_reader.readByte() catch |e| { | 848 | const c = self.inner_reader.readByte() catch |e| { |
| 849 | self.b = b; | 849 | self.b = b; |
| 850 | self.nb = nb; | 850 | self.nb = nb; |
| 851 | if (e == error.EndOfStream) { | 851 | if (e == error.EndOfStream) { |
| ... | @@ -1053,7 +1053,7 @@ test "inflate A Tale of Two Cities (1859) intro" { | ... | @@ -1053,7 +1053,7 @@ test "inflate A Tale of Two Cities (1859) intro" { |
| 1053 | defer decomp.deinit(); | 1053 | defer decomp.deinit(); |
| 1054 | 1054 | ||
| 1055 | var got: [700]u8 = undefined; | 1055 | var got: [700]u8 = undefined; |
| 1056 | var got_len = try decomp.reader().read(&got); | 1056 | const got_len = try decomp.reader().read(&got); |
| 1057 | try testing.expectEqual(@as(usize, 616), got_len); | 1057 | try testing.expectEqual(@as(usize, 616), got_len); |
| 1058 | try testing.expectEqualSlices(u8, expected, got[0..expected.len]); | 1058 | try testing.expectEqualSlices(u8, expected, got[0..expected.len]); |
| 1059 | } | 1059 | } |
| ... | @@ -1117,6 +1117,6 @@ fn decompress(input: []const u8) !void { | ... | @@ -1117,6 +1117,6 @@ fn decompress(input: []const u8) !void { |
| 1117 | const reader = fib.reader(); | 1117 | const reader = fib.reader(); |
| 1118 | var decomp = try decompressor(allocator, reader, null); | 1118 | var decomp = try decompressor(allocator, reader, null); |
| 1119 | defer decomp.deinit(); | 1119 | defer decomp.deinit(); |
| 1120 | var output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize)); | 1120 | const output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize)); |
| 1121 | defer std.testing.allocator.free(output); | 1121 | defer std.testing.allocator.free(output); |
| 1122 | } | 1122 | } |
lib/std/compress/deflate/deflate_fast.zig+32-32| ... | @@ -30,7 +30,7 @@ const table_size = 1 << table_bits; // Size of the table. | ... | @@ -30,7 +30,7 @@ const table_size = 1 << table_bits; // Size of the table. |
| 30 | const buffer_reset = math.maxInt(i32) - max_store_block_size * 2; | 30 | const buffer_reset = math.maxInt(i32) - max_store_block_size * 2; |
| 31 | 31 | ||
| 32 | fn load32(b: []u8, i: i32) u32 { | 32 | fn load32(b: []u8, i: i32) u32 { |
| 33 | var s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4]; | 33 | const s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4]; |
| 34 | return @as(u32, @intCast(s[0])) | | 34 | return @as(u32, @intCast(s[0])) | |
| 35 | @as(u32, @intCast(s[1])) << 8 | | 35 | @as(u32, @intCast(s[1])) << 8 | |
| 36 | @as(u32, @intCast(s[2])) << 16 | | 36 | @as(u32, @intCast(s[2])) << 16 | |
| ... | @@ -38,7 +38,7 @@ fn load32(b: []u8, i: i32) u32 { | ... | @@ -38,7 +38,7 @@ fn load32(b: []u8, i: i32) u32 { |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | fn load64(b: []u8, i: i32) u64 { | 40 | fn load64(b: []u8, i: i32) u64 { |
| 41 | var s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))]; | 41 | const s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))]; |
| 42 | return @as(u64, @intCast(s[0])) | | 42 | return @as(u64, @intCast(s[0])) | |
| 43 | @as(u64, @intCast(s[1])) << 8 | | 43 | @as(u64, @intCast(s[1])) << 8 | |
| 44 | @as(u64, @intCast(s[2])) << 16 | | 44 | @as(u64, @intCast(s[2])) << 16 | |
| ... | @@ -117,7 +117,7 @@ pub const DeflateFast = struct { | ... | @@ -117,7 +117,7 @@ pub const DeflateFast = struct { |
| 117 | // s_limit is when to stop looking for offset/length copies. The input_margin | 117 | // s_limit is when to stop looking for offset/length copies. The input_margin |
| 118 | // lets us use a fast path for emitLiteral in the main loop, while we are | 118 | // lets us use a fast path for emitLiteral in the main loop, while we are |
| 119 | // looking for copies. | 119 | // looking for copies. |
| 120 | var s_limit = @as(i32, @intCast(src.len - input_margin)); | 120 | const s_limit = @as(i32, @intCast(src.len - input_margin)); |
| 121 | 121 | ||
| 122 | // next_emit is where in src the next emitLiteral should start from. | 122 | // next_emit is where in src the next emitLiteral should start from. |
| 123 | var next_emit: i32 = 0; | 123 | var next_emit: i32 = 0; |
| ... | @@ -147,18 +147,18 @@ pub const DeflateFast = struct { | ... | @@ -147,18 +147,18 @@ pub const DeflateFast = struct { |
| 147 | var candidate: TableEntry = undefined; | 147 | var candidate: TableEntry = undefined; |
| 148 | while (true) { | 148 | while (true) { |
| 149 | s = next_s; | 149 | s = next_s; |
| 150 | var bytes_between_hash_lookups = skip >> 5; | 150 | const bytes_between_hash_lookups = skip >> 5; |
| 151 | next_s = s + bytes_between_hash_lookups; | 151 | next_s = s + bytes_between_hash_lookups; |
| 152 | skip += bytes_between_hash_lookups; | 152 | skip += bytes_between_hash_lookups; |
| 153 | if (next_s > s_limit) { | 153 | if (next_s > s_limit) { |
| 154 | break :outer; | 154 | break :outer; |
| 155 | } | 155 | } |
| 156 | candidate = self.table[next_hash & table_mask]; | 156 | candidate = self.table[next_hash & table_mask]; |
| 157 | var now = load32(src, next_s); | 157 | const now = load32(src, next_s); |
| 158 | self.table[next_hash & table_mask] = .{ .offset = s + self.cur, .val = cv }; | 158 | self.table[next_hash & table_mask] = .{ .offset = s + self.cur, .val = cv }; |
| 159 | next_hash = hash(now); | 159 | next_hash = hash(now); |
| 160 | 160 | ||
| 161 | var offset = s - (candidate.offset - self.cur); | 161 | const offset = s - (candidate.offset - self.cur); |
| 162 | if (offset > max_match_offset or cv != candidate.val) { | 162 | if (offset > max_match_offset or cv != candidate.val) { |
| 163 | // Out of range or not matched. | 163 | // Out of range or not matched. |
| 164 | cv = now; | 164 | cv = now; |
| ... | @@ -187,8 +187,8 @@ pub const DeflateFast = struct { | ... | @@ -187,8 +187,8 @@ pub const DeflateFast = struct { |
| 187 | // Extend the 4-byte match as long as possible. | 187 | // Extend the 4-byte match as long as possible. |
| 188 | // | 188 | // |
| 189 | s += 4; | 189 | s += 4; |
| 190 | var t = candidate.offset - self.cur + 4; | 190 | const t = candidate.offset - self.cur + 4; |
| 191 | var l = self.matchLen(s, t, src); | 191 | const l = self.matchLen(s, t, src); |
| 192 | 192 | ||
| 193 | // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset) | 193 | // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset) |
| 194 | dst[tokens_count.*] = token.matchToken( | 194 | dst[tokens_count.*] = token.matchToken( |
| ... | @@ -209,20 +209,20 @@ pub const DeflateFast = struct { | ... | @@ -209,20 +209,20 @@ pub const DeflateFast = struct { |
| 209 | // are faster as one load64 call (with some shifts) instead of | 209 | // are faster as one load64 call (with some shifts) instead of |
| 210 | // three load32 calls. | 210 | // three load32 calls. |
| 211 | var x = load64(src, s - 1); | 211 | var x = load64(src, s - 1); |
| 212 | var prev_hash = hash(@as(u32, @truncate(x))); | 212 | const prev_hash = hash(@as(u32, @truncate(x))); |
| 213 | self.table[prev_hash & table_mask] = TableEntry{ | 213 | self.table[prev_hash & table_mask] = TableEntry{ |
| 214 | .offset = self.cur + s - 1, | 214 | .offset = self.cur + s - 1, |
| 215 | .val = @as(u32, @truncate(x)), | 215 | .val = @as(u32, @truncate(x)), |
| 216 | }; | 216 | }; |
| 217 | x >>= 8; | 217 | x >>= 8; |
| 218 | var curr_hash = hash(@as(u32, @truncate(x))); | 218 | const curr_hash = hash(@as(u32, @truncate(x))); |
| 219 | candidate = self.table[curr_hash & table_mask]; | 219 | candidate = self.table[curr_hash & table_mask]; |
| 220 | self.table[curr_hash & table_mask] = TableEntry{ | 220 | self.table[curr_hash & table_mask] = TableEntry{ |
| 221 | .offset = self.cur + s, | 221 | .offset = self.cur + s, |
| 222 | .val = @as(u32, @truncate(x)), | 222 | .val = @as(u32, @truncate(x)), |
| 223 | }; | 223 | }; |
| 224 | 224 | ||
| 225 | var offset = s - (candidate.offset - self.cur); | 225 | const offset = s - (candidate.offset - self.cur); |
| 226 | if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) { | 226 | if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) { |
| 227 | cv = @as(u32, @truncate(x >> 8)); | 227 | cv = @as(u32, @truncate(x >> 8)); |
| 228 | next_hash = hash(cv); | 228 | next_hash = hash(cv); |
| ... | @@ -261,7 +261,7 @@ pub const DeflateFast = struct { | ... | @@ -261,7 +261,7 @@ pub const DeflateFast = struct { |
| 261 | // If we are inside the current block | 261 | // If we are inside the current block |
| 262 | if (t >= 0) { | 262 | if (t >= 0) { |
| 263 | var b = src[@as(usize, @intCast(t))..]; | 263 | var b = src[@as(usize, @intCast(t))..]; |
| 264 | var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))]; | 264 | const a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))]; |
| 265 | b = b[0..a.len]; | 265 | b = b[0..a.len]; |
| 266 | // Extend the match to be as long as possible. | 266 | // Extend the match to be as long as possible. |
| 267 | for (a, 0..) |_, i| { | 267 | for (a, 0..) |_, i| { |
| ... | @@ -273,7 +273,7 @@ pub const DeflateFast = struct { | ... | @@ -273,7 +273,7 @@ pub const DeflateFast = struct { |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | // We found a match in the previous block. | 275 | // We found a match in the previous block. |
| 276 | var tp = @as(i32, @intCast(self.prev_len)) + t; | 276 | const tp = @as(i32, @intCast(self.prev_len)) + t; |
| 277 | if (tp < 0) { | 277 | if (tp < 0) { |
| 278 | return 0; | 278 | return 0; |
| 279 | } | 279 | } |
| ... | @@ -293,7 +293,7 @@ pub const DeflateFast = struct { | ... | @@ -293,7 +293,7 @@ pub const DeflateFast = struct { |
| 293 | 293 | ||
| 294 | // If we reached our limit, we matched everything we are | 294 | // If we reached our limit, we matched everything we are |
| 295 | // allowed to in the previous block and we return. | 295 | // allowed to in the previous block and we return. |
| 296 | var n = @as(i32, @intCast(b.len)); | 296 | const n = @as(i32, @intCast(b.len)); |
| 297 | if (@as(u32, @intCast(s + n)) == s1) { | 297 | if (@as(u32, @intCast(s + n)) == s1) { |
| 298 | return n; | 298 | return n; |
| 299 | } | 299 | } |
| ... | @@ -366,7 +366,7 @@ test "best speed match 1/3" { | ... | @@ -366,7 +366,7 @@ test "best speed match 1/3" { |
| 366 | .cur = 0, | 366 | .cur = 0, |
| 367 | }; | 367 | }; |
| 368 | var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 }; | 368 | var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 }; |
| 369 | var got: i32 = e.matchLen(3, -3, &current); | 369 | const got: i32 = e.matchLen(3, -3, &current); |
| 370 | try expectEqual(@as(i32, 6), got); | 370 | try expectEqual(@as(i32, 6), got); |
| 371 | } | 371 | } |
| 372 | { | 372 | { |
| ... | @@ -379,7 +379,7 @@ test "best speed match 1/3" { | ... | @@ -379,7 +379,7 @@ test "best speed match 1/3" { |
| 379 | .cur = 0, | 379 | .cur = 0, |
| 380 | }; | 380 | }; |
| 381 | var current = [_]u8{ 2, 4, 5, 0, 1, 2, 3, 4, 5 }; | 381 | var current = [_]u8{ 2, 4, 5, 0, 1, 2, 3, 4, 5 }; |
| 382 | var got: i32 = e.matchLen(3, -3, &current); | 382 | const got: i32 = e.matchLen(3, -3, &current); |
| 383 | try expectEqual(@as(i32, 3), got); | 383 | try expectEqual(@as(i32, 3), got); |
| 384 | } | 384 | } |
| 385 | { | 385 | { |
| ... | @@ -392,7 +392,7 @@ test "best speed match 1/3" { | ... | @@ -392,7 +392,7 @@ test "best speed match 1/3" { |
| 392 | .cur = 0, | 392 | .cur = 0, |
| 393 | }; | 393 | }; |
| 394 | var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 }; | 394 | var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 }; |
| 395 | var got: i32 = e.matchLen(3, -3, &current); | 395 | const got: i32 = e.matchLen(3, -3, &current); |
| 396 | try expectEqual(@as(i32, 2), got); | 396 | try expectEqual(@as(i32, 2), got); |
| 397 | } | 397 | } |
| 398 | { | 398 | { |
| ... | @@ -405,7 +405,7 @@ test "best speed match 1/3" { | ... | @@ -405,7 +405,7 @@ test "best speed match 1/3" { |
| 405 | .cur = 0, | 405 | .cur = 0, |
| 406 | }; | 406 | }; |
| 407 | var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; | 407 | var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; |
| 408 | var got: i32 = e.matchLen(0, -1, &current); | 408 | const got: i32 = e.matchLen(0, -1, &current); |
| 409 | try expectEqual(@as(i32, 4), got); | 409 | try expectEqual(@as(i32, 4), got); |
| 410 | } | 410 | } |
| 411 | { | 411 | { |
| ... | @@ -418,7 +418,7 @@ test "best speed match 1/3" { | ... | @@ -418,7 +418,7 @@ test "best speed match 1/3" { |
| 418 | .cur = 0, | 418 | .cur = 0, |
| 419 | }; | 419 | }; |
| 420 | var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; | 420 | var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; |
| 421 | var got: i32 = e.matchLen(4, -7, &current); | 421 | const got: i32 = e.matchLen(4, -7, &current); |
| 422 | try expectEqual(@as(i32, 5), got); | 422 | try expectEqual(@as(i32, 5), got); |
| 423 | } | 423 | } |
| 424 | { | 424 | { |
| ... | @@ -431,7 +431,7 @@ test "best speed match 1/3" { | ... | @@ -431,7 +431,7 @@ test "best speed match 1/3" { |
| 431 | .cur = 0, | 431 | .cur = 0, |
| 432 | }; | 432 | }; |
| 433 | var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; | 433 | var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; |
| 434 | var got: i32 = e.matchLen(0, -1, &current); | 434 | const got: i32 = e.matchLen(0, -1, &current); |
| 435 | try expectEqual(@as(i32, 0), got); | 435 | try expectEqual(@as(i32, 0), got); |
| 436 | } | 436 | } |
| 437 | { | 437 | { |
| ... | @@ -444,7 +444,7 @@ test "best speed match 1/3" { | ... | @@ -444,7 +444,7 @@ test "best speed match 1/3" { |
| 444 | .cur = 0, | 444 | .cur = 0, |
| 445 | }; | 445 | }; |
| 446 | var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; | 446 | var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; |
| 447 | var got: i32 = e.matchLen(1, 0, &current); | 447 | const got: i32 = e.matchLen(1, 0, &current); |
| 448 | try expectEqual(@as(i32, 0), got); | 448 | try expectEqual(@as(i32, 0), got); |
| 449 | } | 449 | } |
| 450 | } | 450 | } |
| ... | @@ -462,7 +462,7 @@ test "best speed match 2/3" { | ... | @@ -462,7 +462,7 @@ test "best speed match 2/3" { |
| 462 | .cur = 0, | 462 | .cur = 0, |
| 463 | }; | 463 | }; |
| 464 | var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; | 464 | var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; |
| 465 | var got: i32 = e.matchLen(1, -5, &current); | 465 | const got: i32 = e.matchLen(1, -5, &current); |
| 466 | try expectEqual(@as(i32, 0), got); | 466 | try expectEqual(@as(i32, 0), got); |
| 467 | } | 467 | } |
| 468 | { | 468 | { |
| ... | @@ -475,7 +475,7 @@ test "best speed match 2/3" { | ... | @@ -475,7 +475,7 @@ test "best speed match 2/3" { |
| 475 | .cur = 0, | 475 | .cur = 0, |
| 476 | }; | 476 | }; |
| 477 | var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; | 477 | var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; |
| 478 | var got: i32 = e.matchLen(1, -1, &current); | 478 | const got: i32 = e.matchLen(1, -1, &current); |
| 479 | try expectEqual(@as(i32, 0), got); | 479 | try expectEqual(@as(i32, 0), got); |
| 480 | } | 480 | } |
| 481 | { | 481 | { |
| ... | @@ -488,7 +488,7 @@ test "best speed match 2/3" { | ... | @@ -488,7 +488,7 @@ test "best speed match 2/3" { |
| 488 | .cur = 0, | 488 | .cur = 0, |
| 489 | }; | 489 | }; |
| 490 | var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; | 490 | var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; |
| 491 | var got: i32 = e.matchLen(1, 0, &current); | 491 | const got: i32 = e.matchLen(1, 0, &current); |
| 492 | try expectEqual(@as(i32, 3), got); | 492 | try expectEqual(@as(i32, 3), got); |
| 493 | } | 493 | } |
| 494 | { | 494 | { |
| ... | @@ -501,7 +501,7 @@ test "best speed match 2/3" { | ... | @@ -501,7 +501,7 @@ test "best speed match 2/3" { |
| 501 | .cur = 0, | 501 | .cur = 0, |
| 502 | }; | 502 | }; |
| 503 | var current = [_]u8{ 3, 4, 5 }; | 503 | var current = [_]u8{ 3, 4, 5 }; |
| 504 | var got: i32 = e.matchLen(0, -3, &current); | 504 | const got: i32 = e.matchLen(0, -3, &current); |
| 505 | try expectEqual(@as(i32, 3), got); | 505 | try expectEqual(@as(i32, 3), got); |
| 506 | } | 506 | } |
| 507 | } | 507 | } |
| ... | @@ -564,11 +564,11 @@ test "best speed match 2/2" { | ... | @@ -564,11 +564,11 @@ test "best speed match 2/2" { |
| 564 | }; | 564 | }; |
| 565 | 565 | ||
| 566 | for (cases) |c| { | 566 | for (cases) |c| { |
| 567 | var previous = try testing.allocator.alloc(u8, c.previous); | 567 | const previous = try testing.allocator.alloc(u8, c.previous); |
| 568 | defer testing.allocator.free(previous); | 568 | defer testing.allocator.free(previous); |
| 569 | @memset(previous, 0); | 569 | @memset(previous, 0); |
| 570 | 570 | ||
| 571 | var current = try testing.allocator.alloc(u8, c.current); | 571 | const current = try testing.allocator.alloc(u8, c.current); |
| 572 | defer testing.allocator.free(current); | 572 | defer testing.allocator.free(current); |
| 573 | @memset(current, 0); | 573 | @memset(current, 0); |
| 574 | 574 | ||
| ... | @@ -579,7 +579,7 @@ test "best speed match 2/2" { | ... | @@ -579,7 +579,7 @@ test "best speed match 2/2" { |
| 579 | .allocator = undefined, | 579 | .allocator = undefined, |
| 580 | .cur = 0, | 580 | .cur = 0, |
| 581 | }; | 581 | }; |
| 582 | var got: i32 = e.matchLen(c.s, c.t, current); | 582 | const got: i32 = e.matchLen(c.s, c.t, current); |
| 583 | try expectEqual(@as(i32, c.expected), got); | 583 | try expectEqual(@as(i32, c.expected), got); |
| 584 | } | 584 | } |
| 585 | } | 585 | } |
| ... | @@ -609,10 +609,10 @@ test "best speed shift offsets" { | ... | @@ -609,10 +609,10 @@ test "best speed shift offsets" { |
| 609 | // Second part should pick up matches from the first block. | 609 | // Second part should pick up matches from the first block. |
| 610 | tokens_count = 0; | 610 | tokens_count = 0; |
| 611 | enc.encode(&tokens, &tokens_count, &test_data); | 611 | enc.encode(&tokens, &tokens_count, &test_data); |
| 612 | var want_first_tokens = tokens_count; | 612 | const want_first_tokens = tokens_count; |
| 613 | tokens_count = 0; | 613 | tokens_count = 0; |
| 614 | enc.encode(&tokens, &tokens_count, &test_data); | 614 | enc.encode(&tokens, &tokens_count, &test_data); |
| 615 | var want_second_tokens = tokens_count; | 615 | const want_second_tokens = tokens_count; |
| 616 | 616 | ||
| 617 | try expect(want_first_tokens > want_second_tokens); | 617 | try expect(want_first_tokens > want_second_tokens); |
| 618 | 618 | ||
| ... | @@ -657,7 +657,7 @@ test "best speed reset" { | ... | @@ -657,7 +657,7 @@ test "best speed reset" { |
| 657 | const ArrayList = std.ArrayList; | 657 | const ArrayList = std.ArrayList; |
| 658 | 658 | ||
| 659 | const input_size = 65536; | 659 | const input_size = 65536; |
| 660 | var input = try testing.allocator.alloc(u8, input_size); | 660 | const input = try testing.allocator.alloc(u8, input_size); |
| 661 | defer testing.allocator.free(input); | 661 | defer testing.allocator.free(input); |
| 662 | 662 | ||
| 663 | var i: usize = 0; | 663 | var i: usize = 0; |
| ... | @@ -699,7 +699,7 @@ test "best speed reset" { | ... | @@ -699,7 +699,7 @@ test "best speed reset" { |
| 699 | // Reset until we are right before the wraparound. | 699 | // Reset until we are right before the wraparound. |
| 700 | // Each reset adds max_match_offset to the offset. | 700 | // Each reset adds max_match_offset to the offset. |
| 701 | i = 0; | 701 | i = 0; |
| 702 | var limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset; | 702 | const limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset; |
| 703 | while (i < limit) : (i += 1) { | 703 | while (i < limit) : (i += 1) { |
| 704 | // skip ahead to where we are close to wrap around... | 704 | // skip ahead to where we are close to wrap around... |
| 705 | comp.reset(discard.writer()); | 705 | comp.reset(discard.writer()); |
lib/std/compress/deflate/deflate_fast_test.zig+9-9| ... | @@ -39,18 +39,18 @@ test "best speed" { | ... | @@ -39,18 +39,18 @@ test "best speed" { |
| 39 | var tc_15 = [_]u32{ 65536, 129 }; | 39 | var tc_15 = [_]u32{ 65536, 129 }; |
| 40 | var tc_16 = [_]u32{ 65536, 65536, 256 }; | 40 | var tc_16 = [_]u32{ 65536, 65536, 256 }; |
| 41 | var tc_17 = [_]u32{ 65536, 65536, 65536 }; | 41 | var tc_17 = [_]u32{ 65536, 65536, 65536 }; |
| 42 | var test_cases = [_][]u32{ | 42 | const test_cases = [_][]u32{ |
| 43 | &tc_01, &tc_02, &tc_03, &tc_04, &tc_05, &tc_06, &tc_07, &tc_08, &tc_09, &tc_10, | 43 | &tc_01, &tc_02, &tc_03, &tc_04, &tc_05, &tc_06, &tc_07, &tc_08, &tc_09, &tc_10, |
| 44 | &tc_11, &tc_12, &tc_13, &tc_14, &tc_15, &tc_16, &tc_17, | 44 | &tc_11, &tc_12, &tc_13, &tc_14, &tc_15, &tc_16, &tc_17, |
| 45 | }; | 45 | }; |
| 46 | 46 | ||
| 47 | for (test_cases) |tc| { | 47 | for (test_cases) |tc| { |
| 48 | var firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 }; | 48 | const firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 }; |
| 49 | 49 | ||
| 50 | for (firsts) |first_n| { | 50 | for (firsts) |first_n| { |
| 51 | tc[0] = first_n; | 51 | tc[0] = first_n; |
| 52 | 52 | ||
| 53 | var to_flush = [_]bool{ false, true }; | 53 | const to_flush = [_]bool{ false, true }; |
| 54 | for (to_flush) |flush| { | 54 | for (to_flush) |flush| { |
| 55 | var compressed = ArrayList(u8).init(testing.allocator); | 55 | var compressed = ArrayList(u8).init(testing.allocator); |
| 56 | defer compressed.deinit(); | 56 | defer compressed.deinit(); |
| ... | @@ -75,14 +75,14 @@ test "best speed" { | ... | @@ -75,14 +75,14 @@ test "best speed" { |
| 75 | 75 | ||
| 76 | try comp.close(); | 76 | try comp.close(); |
| 77 | 77 | ||
| 78 | var decompressed = try testing.allocator.alloc(u8, want.items.len); | 78 | const decompressed = try testing.allocator.alloc(u8, want.items.len); |
| 79 | defer testing.allocator.free(decompressed); | 79 | defer testing.allocator.free(decompressed); |
| 80 | 80 | ||
| 81 | var fib = io.fixedBufferStream(compressed.items); | 81 | var fib = io.fixedBufferStream(compressed.items); |
| 82 | var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null); | 82 | var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null); |
| 83 | defer decomp.deinit(); | 83 | defer decomp.deinit(); |
| 84 | 84 | ||
| 85 | var read = try decomp.reader().readAll(decompressed); | 85 | const read = try decomp.reader().readAll(decompressed); |
| 86 | _ = decomp.close(); | 86 | _ = decomp.close(); |
| 87 | 87 | ||
| 88 | try testing.expectEqual(want.items.len, read); | 88 | try testing.expectEqual(want.items.len, read); |
| ... | @@ -109,7 +109,7 @@ test "best speed max match offset" { | ... | @@ -109,7 +109,7 @@ test "best speed max match offset" { |
| 109 | for (extras) |extra| { | 109 | for (extras) |extra| { |
| 110 | var offset_adj: i32 = -5; | 110 | var offset_adj: i32 = -5; |
| 111 | while (offset_adj <= 5) : (offset_adj += 1) { | 111 | while (offset_adj <= 5) : (offset_adj += 1) { |
| 112 | var offset = deflate_const.max_match_offset + offset_adj; | 112 | const offset = deflate_const.max_match_offset + offset_adj; |
| 113 | 113 | ||
| 114 | // Make src to be a []u8 of the form | 114 | // Make src to be a []u8 of the form |
| 115 | //	fmt("{s}{s}{s}{s}{s}", .{abc, zeros0, xyzMaybe, abc, zeros1}) | 115 | //	fmt("{s}{s}{s}{s}{s}", .{abc, zeros0, xyzMaybe, abc, zeros1}) |
| ... | @@ -119,7 +119,7 @@ test "best speed max match offset" { | ... | @@ -119,7 +119,7 @@ test "best speed max match offset" { |
| 119 | //	zeros1 is between 0 and 30 zeros. | 119 | //	zeros1 is between 0 and 30 zeros. |
| 120 | // The difference between the two abc's will be offset, which | 120 | // The difference between the two abc's will be offset, which |
| 121 | // is max_match_offset plus or minus a small adjustment. | 121 | // is max_match_offset plus or minus a small adjustment. |
| 122 | var src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra)))); | 122 | const src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra)))); |
| 123 | var src = try testing.allocator.alloc(u8, src_len); | 123 | var src = try testing.allocator.alloc(u8, src_len); |
| 124 | defer testing.allocator.free(src); | 124 | defer testing.allocator.free(src); |
| 125 | 125 | ||
| ... | @@ -143,13 +143,13 @@ test "best speed max match offset" { | ... | @@ -143,13 +143,13 @@ test "best speed max match offset" { |
| 143 | try comp.writer().writeAll(src); | 143 | try comp.writer().writeAll(src); |
| 144 | _ = try comp.close(); | 144 | _ = try comp.close(); |
| 145 | 145 | ||
| 146 | var decompressed = try testing.allocator.alloc(u8, src.len); | 146 | const decompressed = try testing.allocator.alloc(u8, src.len); |
| 147 | defer testing.allocator.free(decompressed); | 147 | defer testing.allocator.free(decompressed); |
| 148 | 148 | ||
| 149 | var fib = io.fixedBufferStream(compressed.items); | 149 | var fib = io.fixedBufferStream(compressed.items); |
| 150 | var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null); | 150 | var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null); |
| 151 | defer decomp.deinit(); | 151 | defer decomp.deinit(); |
| 152 | var read = try decomp.reader().readAll(decompressed); | 152 | const read = try decomp.reader().readAll(decompressed); |
| 153 | _ = decomp.close(); | 153 | _ = decomp.close(); |
| 154 | 154 | ||
| 155 | try testing.expectEqual(src.len, read); | 155 | try testing.expectEqual(src.len, read); |
lib/std/compress/deflate/dict_decoder.zig+7-7| ... | @@ -123,7 +123,7 @@ pub const DictDecoder = struct { | ... | @@ -123,7 +123,7 @@ pub const DictDecoder = struct { |
| 123 | // This invariant must be kept: 0 < dist <= histSize() | 123 | // This invariant must be kept: 0 < dist <= histSize() |
| 124 | pub fn writeCopy(self: *Self, dist: u32, length: u32) u32 { | 124 | pub fn writeCopy(self: *Self, dist: u32, length: u32) u32 { |
| 125 | assert(0 < dist and dist <= self.histSize()); | 125 | assert(0 < dist and dist <= self.histSize()); |
| 126 | var dst_base = self.wr_pos; | 126 | const dst_base = self.wr_pos; |
| 127 | var dst_pos = dst_base; | 127 | var dst_pos = dst_base; |
| 128 | var src_pos: i32 = @as(i32, @intCast(dst_pos)) - @as(i32, @intCast(dist)); | 128 | var src_pos: i32 = @as(i32, @intCast(dst_pos)) - @as(i32, @intCast(dist)); |
| 129 | var end_pos = dst_pos + length; | 129 | var end_pos = dst_pos + length; |
| ... | @@ -175,12 +175,12 @@ pub const DictDecoder = struct { | ... | @@ -175,12 +175,12 @@ pub const DictDecoder = struct { |
| 175 | // This invariant must be kept: 0 < dist <= histSize() | 175 | // This invariant must be kept: 0 < dist <= histSize() |
| 176 | pub fn tryWriteCopy(self: *Self, dist: u32, length: u32) u32 { | 176 | pub fn tryWriteCopy(self: *Self, dist: u32, length: u32) u32 { |
| 177 | var dst_pos = self.wr_pos; | 177 | var dst_pos = self.wr_pos; |
| 178 | var end_pos = dst_pos + length; | 178 | const end_pos = dst_pos + length; |
| 179 | if (dst_pos < dist or end_pos > self.hist.len) { | 179 | if (dst_pos < dist or end_pos > self.hist.len) { |
| 180 | return 0; | 180 | return 0; |
| 181 | } | 181 | } |
| 182 | var dst_base = dst_pos; | 182 | const dst_base = dst_pos; |
| 183 | var src_pos = dst_pos - dist; | 183 | const src_pos = dst_pos - dist; |
| 184 | 184 | ||
| 185 | // Copy possibly overlapping section before destination position. | 185 | // Copy possibly overlapping section before destination position. |
| 186 | while (dst_pos < end_pos) { | 186 | while (dst_pos < end_pos) { |
| ... | @@ -195,7 +195,7 @@ pub const DictDecoder = struct { | ... | @@ -195,7 +195,7 @@ pub const DictDecoder = struct { |
| 195 | // emitted to the user. The data returned by readFlush must be fully consumed | 195 | // emitted to the user. The data returned by readFlush must be fully consumed |
| 196 | // before calling any other DictDecoder methods. | 196 | // before calling any other DictDecoder methods. |
| 197 | pub fn readFlush(self: *Self) []u8 { | 197 | pub fn readFlush(self: *Self) []u8 { |
| 198 | var to_read = self.hist[self.rd_pos..self.wr_pos]; | 198 | const to_read = self.hist[self.rd_pos..self.wr_pos]; |
| 199 | self.rd_pos = self.wr_pos; | 199 | self.rd_pos = self.wr_pos; |
| 200 | if (self.wr_pos == self.hist.len) { | 200 | if (self.wr_pos == self.hist.len) { |
| 201 | self.wr_pos = 0; | 201 | self.wr_pos = 0; |
| ... | @@ -279,7 +279,7 @@ test "dictionary decoder" { | ... | @@ -279,7 +279,7 @@ test "dictionary decoder" { |
| 279 | length: u32, // Length of copy or insertion | 279 | length: u32, // Length of copy or insertion |
| 280 | }; | 280 | }; |
| 281 | 281 | ||
| 282 | var poem_refs = [_]PoemRefs{ | 282 | const poem_refs = [_]PoemRefs{ |
| 283 | .{ .dist = 0, .length = 38 }, .{ .dist = 33, .length = 3 }, .{ .dist = 0, .length = 48 }, | 283 | .{ .dist = 0, .length = 38 }, .{ .dist = 33, .length = 3 }, .{ .dist = 0, .length = 48 }, |
| 284 | .{ .dist = 79, .length = 3 }, .{ .dist = 0, .length = 11 }, .{ .dist = 34, .length = 5 }, | 284 | .{ .dist = 79, .length = 3 }, .{ .dist = 0, .length = 11 }, .{ .dist = 34, .length = 5 }, |
| 285 | .{ .dist = 0, .length = 6 }, .{ .dist = 23, .length = 7 }, .{ .dist = 0, .length = 8 }, | 285 | .{ .dist = 0, .length = 6 }, .{ .dist = 23, .length = 7 }, .{ .dist = 0, .length = 8 }, |
| ... | @@ -368,7 +368,7 @@ test "dictionary decoder" { | ... | @@ -368,7 +368,7 @@ test "dictionary decoder" { |
| 368 | fn writeString(dst_dd: *DictDecoder, dst: anytype, str: []const u8) !void { | 368 | fn writeString(dst_dd: *DictDecoder, dst: anytype, str: []const u8) !void { |
| 369 | var string = str; | 369 | var string = str; |
| 370 | while (string.len > 0) { | 370 | while (string.len > 0) { |
| 371 | var cnt = DictDecoder.copy(dst_dd.writeSlice(), string); | 371 | const cnt = DictDecoder.copy(dst_dd.writeSlice(), string); |
| 372 | dst_dd.writeMark(cnt); | 372 | dst_dd.writeMark(cnt); |
| 373 | string = string[cnt..]; | 373 | string = string[cnt..]; |
| 374 | if (dst_dd.availWrite() == 0) { | 374 | if (dst_dd.availWrite() == 0) { |
lib/std/compress/deflate/huffman_bit_writer.zig+43-43| ... | @@ -134,7 +134,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -134,7 +134,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 134 | self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits)); | 134 | self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits)); |
| 135 | self.nbits += nb; | 135 | self.nbits += nb; |
| 136 | if (self.nbits >= 48) { | 136 | if (self.nbits >= 48) { |
| 137 | var bits = self.bits; | 137 | const bits = self.bits; |
| 138 | self.bits >>= 48; | 138 | self.bits >>= 48; |
| 139 | self.nbits -= 48; | 139 | self.nbits -= 48; |
| 140 | var n = self.nbytes; | 140 | var n = self.nbytes; |
| ... | @@ -224,7 +224,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -224,7 +224,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 224 | while (size != bad_code) : (in_index += 1) { | 224 | while (size != bad_code) : (in_index += 1) { |
| 225 | // INVARIANT: We have seen "count" copies of size that have not yet | 225 | // INVARIANT: We have seen "count" copies of size that have not yet |
| 226 | // had output generated for them. | 226 | // had output generated for them. |
| 227 | var next_size = codegen[in_index]; | 227 | const next_size = codegen[in_index]; |
| 228 | if (next_size == size) { | 228 | if (next_size == size) { |
| 229 | count += 1; | 229 | count += 1; |
| 230 | continue; | 230 | continue; |
| ... | @@ -295,12 +295,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -295,12 +295,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 295 | while (num_codegens > 4 and self.codegen_freq[codegen_order[num_codegens - 1]] == 0) { | 295 | while (num_codegens > 4 and self.codegen_freq[codegen_order[num_codegens - 1]] == 0) { |
| 296 | num_codegens -= 1; | 296 | num_codegens -= 1; |
| 297 | } | 297 | } |
| 298 | var header = 3 + 5 + 5 + 4 + (3 * num_codegens) + | 298 | const header = 3 + 5 + 5 + 4 + (3 * num_codegens) + |
| 299 | self.codegen_encoding.bitLength(self.codegen_freq[0..]) + | 299 | self.codegen_encoding.bitLength(self.codegen_freq[0..]) + |
| 300 | self.codegen_freq[16] * 2 + | 300 | self.codegen_freq[16] * 2 + |
| 301 | self.codegen_freq[17] * 3 + | 301 | self.codegen_freq[17] * 3 + |
| 302 | self.codegen_freq[18] * 7; | 302 | self.codegen_freq[18] * 7; |
| 303 | var size = header + | 303 | const size = header + |
| 304 | lit_enc.bitLength(self.literal_freq) + | 304 | lit_enc.bitLength(self.literal_freq) + |
| 305 | off_enc.bitLength(self.offset_freq) + | 305 | off_enc.bitLength(self.offset_freq) + |
| 306 | extra_bits; | 306 | extra_bits; |
| ... | @@ -339,7 +339,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -339,7 +339,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 339 | self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits)); | 339 | self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits)); |
| 340 | self.nbits += @as(u32, @intCast(c.len)); | 340 | self.nbits += @as(u32, @intCast(c.len)); |
| 341 | if (self.nbits >= 48) { | 341 | if (self.nbits >= 48) { |
| 342 | var bits = self.bits; | 342 | const bits = self.bits; |
| 343 | self.bits >>= 48; | 343 | self.bits >>= 48; |
| 344 | self.nbits -= 48; | 344 | self.nbits -= 48; |
| 345 | var n = self.nbytes; | 345 | var n = self.nbytes; |
| ... | @@ -386,13 +386,13 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -386,13 +386,13 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 386 | 386 | ||
| 387 | var i: u32 = 0; | 387 | var i: u32 = 0; |
| 388 | while (i < num_codegens) : (i += 1) { | 388 | while (i < num_codegens) : (i += 1) { |
| 389 | var value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len)); | 389 | const value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len)); |
| 390 | try self.writeBits(@as(u32, @intCast(value)), 3); | 390 | try self.writeBits(@as(u32, @intCast(value)), 3); |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | i = 0; | 393 | i = 0; |
| 394 | while (true) { | 394 | while (true) { |
| 395 | var code_word: u32 = @as(u32, @intCast(self.codegen[i])); | 395 | const code_word: u32 = @as(u32, @intCast(self.codegen[i])); |
| 396 | i += 1; | 396 | i += 1; |
| 397 | if (code_word == bad_code) { | 397 | if (code_word == bad_code) { |
| 398 | break; | 398 | break; |
| ... | @@ -458,14 +458,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -458,14 +458,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 458 | return; | 458 | return; |
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | var lit_and_off = self.indexTokens(tokens); | 461 | const lit_and_off = self.indexTokens(tokens); |
| 462 | var num_literals = lit_and_off.num_literals; | 462 | const num_literals = lit_and_off.num_literals; |
| 463 | var num_offsets = lit_and_off.num_offsets; | 463 | const num_offsets = lit_and_off.num_offsets; |
| 464 | 464 | ||
| 465 | var extra_bits: u32 = 0; | 465 | var extra_bits: u32 = 0; |
| 466 | var ret = storedSizeFits(input); | 466 | const ret = storedSizeFits(input); |
| 467 | var stored_size = ret.size; | 467 | const stored_size = ret.size; |
| 468 | var storable = ret.storable; | 468 | const storable = ret.storable; |
| 469 | 469 | ||
| 470 | if (storable) { | 470 | if (storable) { |
| 471 | // We only bother calculating the costs of the extra bits required by | 471 | // We only bother calculating the costs of the extra bits required by |
| ... | @@ -504,12 +504,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -504,12 +504,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 504 | &self.offset_encoding, | 504 | &self.offset_encoding, |
| 505 | ); | 505 | ); |
| 506 | self.codegen_encoding.generate(self.codegen_freq[0..], 7); | 506 | self.codegen_encoding.generate(self.codegen_freq[0..], 7); |
| 507 | var dynamic_size = self.dynamicSize( | 507 | const dynamic_size = self.dynamicSize( |
| 508 | &self.literal_encoding, | 508 | &self.literal_encoding, |
| 509 | &self.offset_encoding, | 509 | &self.offset_encoding, |
| 510 | extra_bits, | 510 | extra_bits, |
| 511 | ); | 511 | ); |
| 512 | var dyn_size = dynamic_size.size; | 512 | const dyn_size = dynamic_size.size; |
| 513 | num_codegens = dynamic_size.num_codegens; | 513 | num_codegens = dynamic_size.num_codegens; |
| 514 | 514 | ||
| 515 | if (dyn_size < size) { | 515 | if (dyn_size < size) { |
| ... | @@ -551,9 +551,9 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -551,9 +551,9 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 551 | return; | 551 | return; |
| 552 | } | 552 | } |
| 553 | 553 | ||
| 554 | var total_tokens = self.indexTokens(tokens); | 554 | const total_tokens = self.indexTokens(tokens); |
| 555 | var num_literals = total_tokens.num_literals; | 555 | const num_literals = total_tokens.num_literals; |
| 556 | var num_offsets = total_tokens.num_offsets; | 556 | const num_offsets = total_tokens.num_offsets; |
| 557 | 557 | ||
| 558 | // Generate codegen and codegenFrequencies, which indicates how to encode | 558 | // Generate codegen and codegenFrequencies, which indicates how to encode |
| 559 | // the literal_encoding and the offset_encoding. | 559 | // the literal_encoding and the offset_encoding. |
| ... | @@ -564,15 +564,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -564,15 +564,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 564 | &self.offset_encoding, | 564 | &self.offset_encoding, |
| 565 | ); | 565 | ); |
| 566 | self.codegen_encoding.generate(self.codegen_freq[0..], 7); | 566 | self.codegen_encoding.generate(self.codegen_freq[0..], 7); |
| 567 | var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0); | 567 | const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0); |
| 568 | var size = dynamic_size.size; | 568 | const size = dynamic_size.size; |
| 569 | var num_codegens = dynamic_size.num_codegens; | 569 | const num_codegens = dynamic_size.num_codegens; |
| 570 | 570 | ||
| 571 | // Store bytes, if we don't get a reasonable improvement. | 571 | // Store bytes, if we don't get a reasonable improvement. |
| 572 | 572 | ||
| 573 | var stored_size = storedSizeFits(input); | 573 | const stored_size = storedSizeFits(input); |
| 574 | var ssize = stored_size.size; | 574 | const ssize = stored_size.size; |
| 575 | var storable = stored_size.storable; | 575 | const storable = stored_size.storable; |
| 576 | if (storable and ssize < (size + (size >> 4))) { | 576 | if (storable and ssize < (size + (size >> 4))) { |
| 577 | try self.writeStoredHeader(input.?.len, eof); | 577 | try self.writeStoredHeader(input.?.len, eof); |
| 578 | try self.writeBytes(input.?); | 578 | try self.writeBytes(input.?); |
| ... | @@ -611,8 +611,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -611,8 +611,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 611 | self.literal_freq[token.literal(t)] += 1; | 611 | self.literal_freq[token.literal(t)] += 1; |
| 612 | continue; | 612 | continue; |
| 613 | } | 613 | } |
| 614 | var length = token.length(t); | 614 | const length = token.length(t); |
| 615 | var offset = token.offset(t); | 615 | const offset = token.offset(t); |
| 616 | self.literal_freq[length_codes_start + token.lengthCode(length)] += 1; | 616 | self.literal_freq[length_codes_start + token.lengthCode(length)] += 1; |
| 617 | self.offset_freq[token.offsetCode(offset)] += 1; | 617 | self.offset_freq[token.offsetCode(offset)] += 1; |
| 618 | } | 618 | } |
| ... | @@ -660,21 +660,21 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -660,21 +660,21 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 660 | continue; | 660 | continue; |
| 661 | } | 661 | } |
| 662 | // Write the length | 662 | // Write the length |
| 663 | var length = token.length(t); | 663 | const length = token.length(t); |
| 664 | var length_code = token.lengthCode(length); | 664 | const length_code = token.lengthCode(length); |
| 665 | try self.writeCode(le_codes[length_code + length_codes_start]); | 665 | try self.writeCode(le_codes[length_code + length_codes_start]); |
| 666 | var extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code])); | 666 | const extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code])); |
| 667 | if (extra_length_bits > 0) { | 667 | if (extra_length_bits > 0) { |
| 668 | var extra_length = @as(u32, @intCast(length - length_base[length_code])); | 668 | const extra_length = @as(u32, @intCast(length - length_base[length_code])); |
| 669 | try self.writeBits(extra_length, extra_length_bits); | 669 | try self.writeBits(extra_length, extra_length_bits); |
| 670 | } | 670 | } |
| 671 | // Write the offset | 671 | // Write the offset |
| 672 | var offset = token.offset(t); | 672 | const offset = token.offset(t); |
| 673 | var offset_code = token.offsetCode(offset); | 673 | const offset_code = token.offsetCode(offset); |
| 674 | try self.writeCode(oe_codes[offset_code]); | 674 | try self.writeCode(oe_codes[offset_code]); |
| 675 | var extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code])); | 675 | const extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code])); |
| 676 | if (extra_offset_bits > 0) { | 676 | if (extra_offset_bits > 0) { |
| 677 | var extra_offset = @as(u32, @intCast(offset - offset_base[offset_code])); | 677 | const extra_offset = @as(u32, @intCast(offset - offset_base[offset_code])); |
| 678 | try self.writeBits(extra_offset, extra_offset_bits); | 678 | try self.writeBits(extra_offset, extra_offset_bits); |
| 679 | } | 679 | } |
| 680 | } | 680 | } |
| ... | @@ -718,15 +718,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -718,15 +718,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 718 | &self.huff_offset, | 718 | &self.huff_offset, |
| 719 | ); | 719 | ); |
| 720 | self.codegen_encoding.generate(self.codegen_freq[0..], 7); | 720 | self.codegen_encoding.generate(self.codegen_freq[0..], 7); |
| 721 | var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0); | 721 | const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0); |
| 722 | var size = dynamic_size.size; | 722 | const size = dynamic_size.size; |
| 723 | num_codegens = dynamic_size.num_codegens; | 723 | num_codegens = dynamic_size.num_codegens; |
| 724 | 724 | ||
| 725 | // Store bytes, if we don't get a reasonable improvement. | 725 | // Store bytes, if we don't get a reasonable improvement. |
| 726 | 726 | ||
| 727 | var stored_size_ret = storedSizeFits(input); | 727 | const stored_size_ret = storedSizeFits(input); |
| 728 | var ssize = stored_size_ret.size; | 728 | const ssize = stored_size_ret.size; |
| 729 | var storable = stored_size_ret.storable; | 729 | const storable = stored_size_ret.storable; |
| 730 | 730 | ||
| 731 | if (storable and ssize < (size + (size >> 4))) { | 731 | if (storable and ssize < (size + (size >> 4))) { |
| 732 | try self.writeStoredHeader(input.len, eof); | 732 | try self.writeStoredHeader(input.len, eof); |
| ... | @@ -736,18 +736,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -736,18 +736,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 736 | 736 | ||
| 737 | // Huffman. | 737 | // Huffman. |
| 738 | try self.writeDynamicHeader(num_literals, num_offsets, num_codegens, eof); | 738 | try self.writeDynamicHeader(num_literals, num_offsets, num_codegens, eof); |
| 739 | var encoding = self.literal_encoding.codes[0..257]; | 739 | const encoding = self.literal_encoding.codes[0..257]; |
| 740 | var n = self.nbytes; | 740 | var n = self.nbytes; |
| 741 | for (input) |t| { | 741 | for (input) |t| { |
| 742 | // Bitwriting inlined, ~30% speedup | 742 | // Bitwriting inlined, ~30% speedup |
| 743 | var c = encoding[t]; | 743 | const c = encoding[t]; |
| 744 | self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits)); | 744 | self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits)); |
| 745 | self.nbits += @as(u32, @intCast(c.len)); | 745 | self.nbits += @as(u32, @intCast(c.len)); |
| 746 | if (self.nbits < 48) { | 746 | if (self.nbits < 48) { |
| 747 | continue; | 747 | continue; |
| 748 | } | 748 | } |
| 749 | // Store 6 bytes | 749 | // Store 6 bytes |
| 750 | var bits = self.bits; | 750 | const bits = self.bits; |
| 751 | self.bits >>= 48; | 751 | self.bits >>= 48; |
| 752 | self.nbits -= 48; | 752 | self.nbits -= 48; |
| 753 | var bytes = self.bytes[n..][0..6]; | 753 | var bytes = self.bytes[n..][0..6]; |
| ... | @@ -1679,7 +1679,7 @@ fn testWriterEOF(ttype: TestType, ht_tokens: []const token.Token, input: []const | ... | @@ -1679,7 +1679,7 @@ fn testWriterEOF(ttype: TestType, ht_tokens: []const token.Token, input: []const |
| 1679 | 1679 | ||
| 1680 | try bw.flush(); | 1680 | try bw.flush(); |
| 1681 | 1681 | ||
| 1682 | var b = buf.items; | 1682 | const b = buf.items; |
| 1683 | try expect(b.len > 0); | 1683 | try expect(b.len > 0); |
| 1684 | try expect(b[0] & 1 == 1); | 1684 | try expect(b[0] & 1 == 1); |
| 1685 | } | 1685 | } |
lib/std/compress/deflate/huffman_code.zig+8-8| ... | @@ -96,7 +96,7 @@ pub const HuffmanEncoder = struct { | ... | @@ -96,7 +96,7 @@ pub const HuffmanEncoder = struct { |
| 96 | mem.sort(LiteralNode, self.lfs, {}, byFreq); | 96 | mem.sort(LiteralNode, self.lfs, {}, byFreq); |
| 97 | 97 | ||
| 98 | // Get the number of literals for each bit count | 98 | // Get the number of literals for each bit count |
| 99 | var bit_count = self.bitCounts(list, max_bits); | 99 | const bit_count = self.bitCounts(list, max_bits); |
| 100 | // And do the assignment | 100 | // And do the assignment |
| 101 | self.assignEncodingAndSize(bit_count, list); | 101 | self.assignEncodingAndSize(bit_count, list); |
| 102 | } | 102 | } |
| ... | @@ -128,7 +128,7 @@ pub const HuffmanEncoder = struct { | ... | @@ -128,7 +128,7 @@ pub const HuffmanEncoder = struct { |
| 128 | // that should be encoded in i bits. | 128 | // that should be encoded in i bits. |
| 129 | fn bitCounts(self: *HuffmanEncoder, list: []LiteralNode, max_bits_to_use: usize) []u32 { | 129 | fn bitCounts(self: *HuffmanEncoder, list: []LiteralNode, max_bits_to_use: usize) []u32 { |
| 130 | var max_bits = max_bits_to_use; | 130 | var max_bits = max_bits_to_use; |
| 131 | var n = list.len; | 131 | const n = list.len; |
| 132 | 132 | ||
| 133 | assert(max_bits < max_bits_limit); | 133 | assert(max_bits < max_bits_limit); |
| 134 | 134 | ||
| ... | @@ -184,10 +184,10 @@ pub const HuffmanEncoder = struct { | ... | @@ -184,10 +184,10 @@ pub const HuffmanEncoder = struct { |
| 184 | continue; | 184 | continue; |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | var prev_freq = l.last_freq; | 187 | const prev_freq = l.last_freq; |
| 188 | if (l.next_char_freq < l.next_pair_freq) { | 188 | if (l.next_char_freq < l.next_pair_freq) { |
| 189 | // The next item on this row is a leaf node. | 189 | // The next item on this row is a leaf node. |
| 190 | var next = leaf_counts[level][level] + 1; | 190 | const next = leaf_counts[level][level] + 1; |
| 191 | l.last_freq = l.next_char_freq; | 191 | l.last_freq = l.next_char_freq; |
| 192 | // Lower leaf_counts are the same of the previous node. | 192 | // Lower leaf_counts are the same of the previous node. |
| 193 | leaf_counts[level][level] = next; | 193 | leaf_counts[level][level] = next; |
| ... | @@ -236,7 +236,7 @@ pub const HuffmanEncoder = struct { | ... | @@ -236,7 +236,7 @@ pub const HuffmanEncoder = struct { |
| 236 | 236 | ||
| 237 | var bit_count = self.bit_count[0 .. max_bits + 1]; | 237 | var bit_count = self.bit_count[0 .. max_bits + 1]; |
| 238 | var bits: u32 = 1; | 238 | var bits: u32 = 1; |
| 239 | var counts = &leaf_counts[max_bits]; | 239 | const counts = &leaf_counts[max_bits]; |
| 240 | { | 240 | { |
| 241 | var level = max_bits; | 241 | var level = max_bits; |
| 242 | while (level > 0) : (level -= 1) { | 242 | while (level > 0) : (level -= 1) { |
| ... | @@ -267,7 +267,7 @@ pub const HuffmanEncoder = struct { | ... | @@ -267,7 +267,7 @@ pub const HuffmanEncoder = struct { |
| 267 | // are encoded using "bits" bits, and get the values | 267 | // are encoded using "bits" bits, and get the values |
| 268 | // code, code + 1, .... The code values are | 268 | // code, code + 1, .... The code values are |
| 269 | // assigned in literal order (not frequency order). | 269 | // assigned in literal order (not frequency order). |
| 270 | var chunk = list[list.len - @as(u32, @intCast(bits)) ..]; | 270 | const chunk = list[list.len - @as(u32, @intCast(bits)) ..]; |
| 271 | 271 | ||
| 272 | self.lns = chunk; | 272 | self.lns = chunk; |
| 273 | mem.sort(LiteralNode, self.lns, {}, byLiteral); | 273 | mem.sort(LiteralNode, self.lns, {}, byLiteral); |
| ... | @@ -303,7 +303,7 @@ pub fn newHuffmanEncoder(allocator: Allocator, size: u32) !HuffmanEncoder { | ... | @@ -303,7 +303,7 @@ pub fn newHuffmanEncoder(allocator: Allocator, size: u32) !HuffmanEncoder { |
| 303 | 303 | ||
| 304 | // Generates a HuffmanCode corresponding to the fixed literal table | 304 | // Generates a HuffmanCode corresponding to the fixed literal table |
| 305 | pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder { | 305 | pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder { |
| 306 | var h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies); | 306 | const h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies); |
| 307 | var codes = h.codes; | 307 | var codes = h.codes; |
| 308 | var ch: u16 = 0; | 308 | var ch: u16 = 0; |
| 309 | 309 | ||
| ... | @@ -338,7 +338,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder { | ... | @@ -338,7 +338,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder { |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder { | 340 | pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder { |
| 341 | var h = try newHuffmanEncoder(allocator, 30); | 341 | const h = try newHuffmanEncoder(allocator, 30); |
| 342 | var codes = h.codes; | 342 | var codes = h.codes; |
| 343 | for (codes, 0..) |_, ch| { | 343 | for (codes, 0..) |_, ch| { |
| 344 | codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @as(u16, @intCast(ch)), 5), .len = 5 }; | 344 | codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @as(u16, @intCast(ch)), 5), .len = 5 }; |
lib/std/compress/zstandard.zig+1-1| ... | @@ -268,7 +268,7 @@ test "zstandard decompression" { | ... | @@ -268,7 +268,7 @@ test "zstandard decompression" { |
| 268 | const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3"); | 268 | const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3"); |
| 269 | const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19"); | 269 | const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19"); |
| 270 | 270 | ||
| 271 | var buffer = try std.testing.allocator.alloc(u8, uncompressed.len); | 271 | const buffer = try std.testing.allocator.alloc(u8, uncompressed.len); |
| 272 | defer std.testing.allocator.free(buffer); | 272 | defer std.testing.allocator.free(buffer); |
| 273 | 273 | ||
| 274 | const res3 = try decompress.decode(buffer, compressed3, true); | 274 | const res3 = try decompress.decode(buffer, compressed3, true); |
lib/std/compress/zstandard/decode/huffman.zig+1-1| ... | @@ -54,7 +54,7 @@ fn decodeFseHuffmanTreeSlice(src: []const u8, compressed_size: usize, weights: * | ... | @@ -54,7 +54,7 @@ fn decodeFseHuffmanTreeSlice(src: []const u8, compressed_size: usize, weights: * |
| 54 | 54 | ||
| 55 | const start_index = std.math.cast(usize, counting_reader.bytes_read) orelse | 55 | const start_index = std.math.cast(usize, counting_reader.bytes_read) orelse |
| 56 | return error.MalformedHuffmanTree; | 56 | return error.MalformedHuffmanTree; |
| 57 | var huff_data = src[start_index..compressed_size]; | 57 | const huff_data = src[start_index..compressed_size]; |
| 58 | var huff_bits: readers.ReverseBitReader = undefined; | 58 | var huff_bits: readers.ReverseBitReader = undefined; |
| 59 | huff_bits.init(huff_data) catch return error.MalformedHuffmanTree; | 59 | huff_bits.init(huff_data) catch return error.MalformedHuffmanTree; |
| 60 | 60 |
lib/std/compress/zstandard/decompress.zig+2-2| ... | @@ -304,7 +304,7 @@ pub fn decodeZstandardFrame( | ... | @@ -304,7 +304,7 @@ pub fn decodeZstandardFrame( |
| 304 | 304 | ||
| 305 | var frame_context = context: { | 305 | var frame_context = context: { |
| 306 | var fbs = std.io.fixedBufferStream(src[consumed_count..]); | 306 | var fbs = std.io.fixedBufferStream(src[consumed_count..]); |
| 307 | var source = fbs.reader(); | 307 | const source = fbs.reader(); |
| 308 | const frame_header = try decodeZstandardHeader(source); | 308 | const frame_header = try decodeZstandardHeader(source); |
| 309 | consumed_count += fbs.pos; | 309 | consumed_count += fbs.pos; |
| 310 | break :context FrameContext.init( | 310 | break :context FrameContext.init( |
| ... | @@ -447,7 +447,7 @@ pub fn decodeZstandardFrameArrayList( | ... | @@ -447,7 +447,7 @@ pub fn decodeZstandardFrameArrayList( |
| 447 | 447 | ||
| 448 | var frame_context = context: { | 448 | var frame_context = context: { |
| 449 | var fbs = std.io.fixedBufferStream(src[consumed_count..]); | 449 | var fbs = std.io.fixedBufferStream(src[consumed_count..]); |
| 450 | var source = fbs.reader(); | 450 | const source = fbs.reader(); |
| 451 | const frame_header = try decodeZstandardHeader(source); | 451 | const frame_header = try decodeZstandardHeader(source); |
| 452 | consumed_count += fbs.pos; | 452 | consumed_count += fbs.pos; |
| 453 | break :context try FrameContext.init(frame_header, window_size_max, verify_checksum); | 453 | break :context try FrameContext.init(frame_header, window_size_max, verify_checksum); |
lib/std/crypto/25519/curve25519.zig+1-1| ... | @@ -129,7 +129,7 @@ test "non-affine edwards25519 to curve25519 projection" { | ... | @@ -129,7 +129,7 @@ test "non-affine edwards25519 to curve25519 projection" { |
| 129 | const skh = "90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e"; | 129 | const skh = "90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e"; |
| 130 | var sk: [32]u8 = undefined; | 130 | var sk: [32]u8 = undefined; |
| 131 | _ = std.fmt.hexToBytes(&sk, skh) catch unreachable; | 131 | _ = std.fmt.hexToBytes(&sk, skh) catch unreachable; |
| 132 | var edp = try crypto.ecc.Edwards25519.basePoint.mul(sk); | 132 | const edp = try crypto.ecc.Edwards25519.basePoint.mul(sk); |
| 133 | const xp = try Curve25519.fromEdwards25519(edp); | 133 | const xp = try Curve25519.fromEdwards25519(edp); |
| 134 | const expected_hex = "cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378"; | 134 | const expected_hex = "cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378"; |
| 135 | var expected: [32]u8 = undefined; | 135 | var expected: [32]u8 = undefined; |
lib/std/crypto/25519/field.zig+1-1| ... | @@ -416,7 +416,7 @@ pub const Fe = struct { | ... | @@ -416,7 +416,7 @@ pub const Fe = struct { |
| 416 | 416 | ||
| 417 | /// Compute the square root of `x2`, returning `error.NotSquare` if `x2` was not a square | 417 | /// Compute the square root of `x2`, returning `error.NotSquare` if `x2` was not a square |
| 418 | pub fn sqrt(x2: Fe) NotSquareError!Fe { | 418 | pub fn sqrt(x2: Fe) NotSquareError!Fe { |
| 419 | var x2_copy = x2; | 419 | const x2_copy = x2; |
| 420 | const x = x2.uncheckedSqrt(); | 420 | const x = x2.uncheckedSqrt(); |
| 421 | const check = x.sq().sub(x2_copy); | 421 | const check = x.sq().sub(x2_copy); |
| 422 | if (check.isZero()) { | 422 | if (check.isZero()) { |
lib/std/crypto/Certificate.zig+1-1| ... | @@ -982,7 +982,7 @@ pub const rsa = struct { | ... | @@ -982,7 +982,7 @@ pub const rsa = struct { |
| 982 | if (mgf_len > mgf_out_buf.len) { // Modulus > 4096 bits | 982 | if (mgf_len > mgf_out_buf.len) { // Modulus > 4096 bits |
| 983 | return error.InvalidSignature; | 983 | return error.InvalidSignature; |
| 984 | } | 984 | } |
| 985 | var mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length]; | 985 | const mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length]; |
| 986 | var dbMask = try MGF1(Hash, mgf_out, h, mgf_len); | 986 | var dbMask = try MGF1(Hash, mgf_out, h, mgf_len); |
| 987 | 987 | ||
| 988 | // 8. Let DB = maskedDB \xor dbMask. | 988 | // 8. Let DB = maskedDB \xor dbMask. |
lib/std/crypto/aes.zig+1-1| ... | @@ -47,7 +47,7 @@ test "ctr" { | ... | @@ -47,7 +47,7 @@ test "ctr" { |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | var out: [exp_out.len]u8 = undefined; | 49 | var out: [exp_out.len]u8 = undefined; |
| 50 | var ctx = Aes128.initEnc(key); | 50 | const ctx = Aes128.initEnc(key); |
| 51 | ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big); | 51 | ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big); |
| 52 | try testing.expectEqualSlices(u8, exp_out[0..], out[0..]); | 52 | try testing.expectEqualSlices(u8, exp_out[0..], out[0..]); |
| 53 | } | 53 | } |
lib/std/crypto/aes_ocb.zig+1-1| ... | @@ -95,7 +95,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -95,7 +95,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 95 | var ktop_: Block = undefined; | 95 | var ktop_: Block = undefined; |
| 96 | aes_enc_ctx.encrypt(&ktop_, &nx); | 96 | aes_enc_ctx.encrypt(&ktop_, &nx); |
| 97 | const ktop = mem.readInt(u128, &ktop_, .big); | 97 | const ktop = mem.readInt(u128, &ktop_, .big); |
| 98 | var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56))); | 98 | const stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56))); |
| 99 | var offset: Block = undefined; | 99 | var offset: Block = undefined; |
| 100 | mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big); | 100 | mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big); |
| 101 | return offset; | 101 | return offset; |
lib/std/crypto/argon2.zig+1-1| ... | @@ -565,7 +565,7 @@ const PhcFormatHasher = struct { | ... | @@ -565,7 +565,7 @@ const PhcFormatHasher = struct { |
| 565 | const expected_hash = hash_result.hash.constSlice(); | 565 | const expected_hash = hash_result.hash.constSlice(); |
| 566 | var hash_buf: [max_hash_len]u8 = undefined; | 566 | var hash_buf: [max_hash_len]u8 = undefined; |
| 567 | if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; | 567 | if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; |
| 568 | var hash = hash_buf[0..expected_hash.len]; | 568 | const hash = hash_buf[0..expected_hash.len]; |
| 569 | 569 | ||
| 570 | try kdf(allocator, hash, password, hash_result.salt.constSlice(), params, mode); | 570 | try kdf(allocator, hash, password, hash_result.salt.constSlice(), params, mode); |
| 571 | if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; | 571 | if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; |
lib/std/crypto/ascon.zig+1-2| ... | @@ -42,8 +42,7 @@ pub fn State(comptime endian: std.builtin.Endian) type { | ... | @@ -42,8 +42,7 @@ pub fn State(comptime endian: std.builtin.Endian) type { |
| 42 | 42 | ||
| 43 | /// Initialize the state from u64 words in native endianness. | 43 | /// Initialize the state from u64 words in native endianness. |
| 44 | pub fn initFromWords(initial_state: [5]u64) Self { | 44 | pub fn initFromWords(initial_state: [5]u64) Self { |
| 45 | var state = Self{ .st = initial_state }; | 45 | return .{ .st = initial_state }; |
| 46 | return state; | ||
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | /// Initialize the state for Ascon XOF | 48 | /// Initialize the state for Ascon XOF |
lib/std/crypto/bcrypt.zig+1-1| ... | @@ -431,7 +431,7 @@ pub fn bcrypt( | ... | @@ -431,7 +431,7 @@ pub fn bcrypt( |
| 431 | const trimmed_len = @min(password.len, password_buf.len - 1); | 431 | const trimmed_len = @min(password.len, password_buf.len - 1); |
| 432 | @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]); | 432 | @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]); |
| 433 | password_buf[trimmed_len] = 0; | 433 | password_buf[trimmed_len] = 0; |
| 434 | var passwordZ = password_buf[0 .. trimmed_len + 1]; | 434 | const passwordZ = password_buf[0 .. trimmed_len + 1]; |
| 435 | state.expand(salt[0..], passwordZ); | 435 | state.expand(salt[0..], passwordZ); |
| 436 | 436 | ||
| 437 | const rounds: u64 = @as(u64, 1) << params.rounds_log; | 437 | const rounds: u64 = @as(u64, 1) << params.rounds_log; |
lib/std/crypto/blake3.zig+1-1| ... | @@ -241,7 +241,7 @@ const Output = struct { | ... | @@ -241,7 +241,7 @@ const Output = struct { |
| 241 | var out_block_it = ChunkIterator.init(output, 2 * OUT_LEN); | 241 | var out_block_it = ChunkIterator.init(output, 2 * OUT_LEN); |
| 242 | var output_block_counter: usize = 0; | 242 | var output_block_counter: usize = 0; |
| 243 | while (out_block_it.next()) |out_block| { | 243 | while (out_block_it.next()) |out_block| { |
| 244 | var words = compress( | 244 | const words = compress( |
| 245 | self.input_chaining_value, | 245 | self.input_chaining_value, |
| 246 | self.block_words, | 246 | self.block_words, |
| 247 | self.block_len, | 247 | self.block_len, |
lib/std/crypto/ecdsa.zig+1-1| ... | @@ -201,7 +201,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -201,7 +201,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 201 | const scalar_encoded_length = Curve.scalar.encoded_length; | 201 | const scalar_encoded_length = Curve.scalar.encoded_length; |
| 202 | const h_len = @max(Hash.digest_length, scalar_encoded_length); | 202 | const h_len = @max(Hash.digest_length, scalar_encoded_length); |
| 203 | var h: [h_len]u8 = [_]u8{0} ** h_len; | 203 | var h: [h_len]u8 = [_]u8{0} ** h_len; |
| 204 | var h_slice = h[h_len - Hash.digest_length .. h_len]; | 204 | const h_slice = h[h_len - Hash.digest_length .. h_len]; |
| 205 | self.h.final(h_slice); | 205 | self.h.final(h_slice); |
| 206 | 206 | ||
| 207 | std.debug.assert(h.len >= scalar_encoded_length); | 207 | std.debug.assert(h.len >= scalar_encoded_length); |
lib/std/crypto/pbkdf2.zig+2-4| ... | @@ -255,10 +255,8 @@ test "Very large dk_len" { | ... | @@ -255,10 +255,8 @@ test "Very large dk_len" { |
| 255 | const c = 1; | 255 | const c = 1; |
| 256 | const dk_len = 1 << 33; | 256 | const dk_len = 1 << 33; |
| 257 | 257 | ||
| 258 | var dk = try std.testing.allocator.alloc(u8, dk_len); | 258 | const dk = try std.testing.allocator.alloc(u8, dk_len); |
| 259 | defer { | 259 | defer std.testing.allocator.free(dk); |
| 260 | std.testing.allocator.free(dk); | ||
| 261 | } | ||
| 262 | 260 | ||
| 263 | // Just verify this doesn't crash with an overflow | 261 | // Just verify this doesn't crash with an overflow |
| 264 | try pbkdf2(dk, p, s, c, HmacSha1); | 262 | try pbkdf2(dk, p, s, c, HmacSha1); |
lib/std/crypto/pcurves/common.zig+1-1| ... | @@ -71,7 +71,7 @@ pub fn Field(comptime params: FieldParams) type { | ... | @@ -71,7 +71,7 @@ pub fn Field(comptime params: FieldParams) type { |
| 71 | 71 | ||
| 72 | /// Unpack a field element. | 72 | /// Unpack a field element. |
| 73 | pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe { | 73 | pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe { |
| 74 | var s = if (endian == .little) s_ else orderSwap(s_); | 74 | const s = if (endian == .little) s_ else orderSwap(s_); |
| 75 | try rejectNonCanonical(s, .little); | 75 | try rejectNonCanonical(s, .little); |
| 76 | var limbs_z: NonMontgomeryDomainFieldElement = undefined; | 76 | var limbs_z: NonMontgomeryDomainFieldElement = undefined; |
| 77 | fiat.fromBytes(&limbs_z, s); | 77 | fiat.fromBytes(&limbs_z, s); |
lib/std/crypto/poly1305.zig+3-3| ... | @@ -90,8 +90,8 @@ pub const Poly1305 = struct { | ... | @@ -90,8 +90,8 @@ pub const Poly1305 = struct { |
| 90 | h2 = t2 & 3; | 90 | h2 = t2 & 3; |
| 91 | 91 | ||
| 92 | // Add c*(4+1) | 92 | // Add c*(4+1) |
| 93 | var cclo = t2 & ~@as(u64, 3); | 93 | const cclo = t2 & ~@as(u64, 3); |
| 94 | var cchi = t3; | 94 | const cchi = t3; |
| 95 | v = @addWithOverflow(h0, cclo); | 95 | v = @addWithOverflow(h0, cclo); |
| 96 | h0 = v[0]; | 96 | h0 = v[0]; |
| 97 | v = add(h1, cchi, v[1]); | 97 | v = add(h1, cchi, v[1]); |
| ... | @@ -163,7 +163,7 @@ pub const Poly1305 = struct { | ... | @@ -163,7 +163,7 @@ pub const Poly1305 = struct { |
| 163 | 163 | ||
| 164 | var h0 = st.h[0]; | 164 | var h0 = st.h[0]; |
| 165 | var h1 = st.h[1]; | 165 | var h1 = st.h[1]; |
| 166 | var h2 = st.h[2]; | 166 | const h2 = st.h[2]; |
| 167 | 167 | ||
| 168 | // H - (2^130 - 5) | 168 | // H - (2^130 - 5) |
| 169 | var v = @subWithOverflow(h0, 0xfffffffffffffffb); | 169 | var v = @subWithOverflow(h0, 0xfffffffffffffffb); |
lib/std/crypto/salsa20.zig+3-3| ... | @@ -605,8 +605,8 @@ test "xsalsa20poly1305 box" { | ... | @@ -605,8 +605,8 @@ test "xsalsa20poly1305 box" { |
| 605 | crypto.random.bytes(&msg); | 605 | crypto.random.bytes(&msg); |
| 606 | crypto.random.bytes(&nonce); | 606 | crypto.random.bytes(&nonce); |
| 607 | 607 | ||
| 608 | var kp1 = try Box.KeyPair.create(null); | 608 | const kp1 = try Box.KeyPair.create(null); |
| 609 | var kp2 = try Box.KeyPair.create(null); | 609 | const kp2 = try Box.KeyPair.create(null); |
| 610 | try Box.seal(boxed[0..], msg[0..], nonce, kp1.public_key, kp2.secret_key); | 610 | try Box.seal(boxed[0..], msg[0..], nonce, kp1.public_key, kp2.secret_key); |
| 611 | try Box.open(msg2[0..], boxed[0..], nonce, kp2.public_key, kp1.secret_key); | 611 | try Box.open(msg2[0..], boxed[0..], nonce, kp2.public_key, kp1.secret_key); |
| 612 | } | 612 | } |
| ... | @@ -617,7 +617,7 @@ test "xsalsa20poly1305 sealedbox" { | ... | @@ -617,7 +617,7 @@ test "xsalsa20poly1305 sealedbox" { |
| 617 | var boxed: [msg.len + SealedBox.seal_length]u8 = undefined; | 617 | var boxed: [msg.len + SealedBox.seal_length]u8 = undefined; |
| 618 | crypto.random.bytes(&msg); | 618 | crypto.random.bytes(&msg); |
| 619 | 619 | ||
| 620 | var kp = try Box.KeyPair.create(null); | 620 | const kp = try Box.KeyPair.create(null); |
| 621 | try SealedBox.seal(boxed[0..], msg[0..], kp.public_key); | 621 | try SealedBox.seal(boxed[0..], msg[0..], kp.public_key); |
| 622 | try SealedBox.open(msg2[0..], boxed[0..], kp); | 622 | try SealedBox.open(msg2[0..], boxed[0..], kp); |
| 623 | } | 623 | } |
lib/std/crypto/scrypt.zig+7-7| ... | @@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 { | ... | @@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 { |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void { | 89 | fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void { |
| 90 | var x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]); | 90 | const x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]); |
| 91 | var y: []align(16) u32 = @alignCast(xy[32 * r ..]); | 91 | const y: []align(16) u32 = @alignCast(xy[32 * r ..]); |
| 92 | 92 | ||
| 93 | for (x, 0..) |*v1, j| { | 93 | for (x, 0..) |*v1, j| { |
| 94 | v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little); | 94 | v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little); |
| ... | @@ -191,9 +191,9 @@ pub fn kdf( | ... | @@ -191,9 +191,9 @@ pub fn kdf( |
| 191 | params.r > max_int / 256 or | 191 | params.r > max_int / 256 or |
| 192 | n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters; | 192 | n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters; |
| 193 | 193 | ||
| 194 | var xy = try allocator.alignedAlloc(u32, 16, 64 * params.r); | 194 | const xy = try allocator.alignedAlloc(u32, 16, 64 * params.r); |
| 195 | defer allocator.free(xy); | 195 | defer allocator.free(xy); |
| 196 | var v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r); | 196 | const v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r); |
| 197 | defer allocator.free(v); | 197 | defer allocator.free(v); |
| 198 | var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r); | 198 | var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r); |
| 199 | defer allocator.free(dk); | 199 | defer allocator.free(dk); |
| ... | @@ -263,7 +263,7 @@ const crypt_format = struct { | ... | @@ -263,7 +263,7 @@ const crypt_format = struct { |
| 263 | const value = self.constSlice(); | 263 | const value = self.constSlice(); |
| 264 | const len = Codec.encodedLen(value.len); | 264 | const len = Codec.encodedLen(value.len); |
| 265 | if (len > buf.len) return EncodingError.NoSpaceLeft; | 265 | if (len > buf.len) return EncodingError.NoSpaceLeft; |
| 266 | var encoded = buf[0..len]; | 266 | const encoded = buf[0..len]; |
| 267 | Codec.encode(encoded, value); | 267 | Codec.encode(encoded, value); |
| 268 | return encoded; | 268 | return encoded; |
| 269 | } | 269 | } |
| ... | @@ -439,7 +439,7 @@ const PhcFormatHasher = struct { | ... | @@ -439,7 +439,7 @@ const PhcFormatHasher = struct { |
| 439 | const expected_hash = hash_result.hash.constSlice(); | 439 | const expected_hash = hash_result.hash.constSlice(); |
| 440 | var hash_buf: [max_hash_len]u8 = undefined; | 440 | var hash_buf: [max_hash_len]u8 = undefined; |
| 441 | if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; | 441 | if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; |
| 442 | var hash = hash_buf[0..expected_hash.len]; | 442 | const hash = hash_buf[0..expected_hash.len]; |
| 443 | try kdf(allocator, hash, password, hash_result.salt.constSlice(), params); | 443 | try kdf(allocator, hash, password, hash_result.salt.constSlice(), params); |
| 444 | if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; | 444 | if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; |
| 445 | } | 445 | } |
| ... | @@ -487,7 +487,7 @@ const CryptFormatHasher = struct { | ... | @@ -487,7 +487,7 @@ const CryptFormatHasher = struct { |
| 487 | const expected_hash = hash_result.hash.constSlice(); | 487 | const expected_hash = hash_result.hash.constSlice(); |
| 488 | var hash_buf: [max_hash_len]u8 = undefined; | 488 | var hash_buf: [max_hash_len]u8 = undefined; |
| 489 | if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; | 489 | if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; |
| 490 | var hash = hash_buf[0..expected_hash.len]; | 490 | const hash = hash_buf[0..expected_hash.len]; |
| 491 | try kdf(allocator, hash, password, hash_result.salt, params); | 491 | try kdf(allocator, hash, password, hash_result.salt, params); |
| 492 | if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; | 492 | if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; |
| 493 | } | 493 | } |
lib/std/crypto/tls/Client.zig+3-3| ... | @@ -491,7 +491,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In | ... | @@ -491,7 +491,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In |
| 491 | try all_extd.ensure(4); | 491 | try all_extd.ensure(4); |
| 492 | const et = all_extd.decode(tls.ExtensionType); | 492 | const et = all_extd.decode(tls.ExtensionType); |
| 493 | const ext_size = all_extd.decode(u16); | 493 | const ext_size = all_extd.decode(u16); |
| 494 | var extd = try all_extd.sub(ext_size); | 494 | const extd = try all_extd.sub(ext_size); |
| 495 | _ = extd; | 495 | _ = extd; |
| 496 | switch (et) { | 496 | switch (et) { |
| 497 | .server_name => {}, | 497 | .server_name => {}, |
| ... | @@ -516,7 +516,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In | ... | @@ -516,7 +516,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In |
| 516 | while (!certs_decoder.eof()) { | 516 | while (!certs_decoder.eof()) { |
| 517 | try certs_decoder.ensure(3); | 517 | try certs_decoder.ensure(3); |
| 518 | const cert_size = certs_decoder.decode(u24); | 518 | const cert_size = certs_decoder.decode(u24); |
| 519 | var certd = try certs_decoder.sub(cert_size); | 519 | const certd = try certs_decoder.sub(cert_size); |
| 520 | 520 | ||
| 521 | const subject_cert: Certificate = .{ | 521 | const subject_cert: Certificate = .{ |
| 522 | .buffer = certd.buf, | 522 | .buffer = certd.buf, |
| ... | @@ -552,7 +552,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In | ... | @@ -552,7 +552,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In |
| 552 | 552 | ||
| 553 | try certs_decoder.ensure(2); | 553 | try certs_decoder.ensure(2); |
| 554 | const total_ext_size = certs_decoder.decode(u16); | 554 | const total_ext_size = certs_decoder.decode(u16); |
| 555 | var all_extd = try certs_decoder.sub(total_ext_size); | 555 | const all_extd = try certs_decoder.sub(total_ext_size); |
| 556 | _ = all_extd; | 556 | _ = all_extd; |
| 557 | } | 557 | } |
| 558 | }, | 558 | }, |
lib/std/debug.zig+4-4| ... | @@ -812,7 +812,7 @@ pub fn writeStackTraceWindows( | ... | @@ -812,7 +812,7 @@ pub fn writeStackTraceWindows( |
| 812 | var addr_buf: [1024]usize = undefined; | 812 | var addr_buf: [1024]usize = undefined; |
| 813 | const n = walkStackWindows(addr_buf[0..], context); | 813 | const n = walkStackWindows(addr_buf[0..], context); |
| 814 | const addrs = addr_buf[0..n]; | 814 | const addrs = addr_buf[0..n]; |
| 815 | var start_i: usize = if (start_addr) |saddr| blk: { | 815 | const start_i: usize = if (start_addr) |saddr| blk: { |
| 816 | for (addrs, 0..) |addr, i| { | 816 | for (addrs, 0..) |addr, i| { |
| 817 | if (addr == saddr) break :blk i; | 817 | if (addr == saddr) break :blk i; |
| 818 | } | 818 | } |
| ... | @@ -1158,7 +1158,7 @@ pub fn readElfDebugInfo( | ... | @@ -1158,7 +1158,7 @@ pub fn readElfDebugInfo( |
| 1158 | var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue; | 1158 | var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue; |
| 1159 | defer zlib_stream.deinit(); | 1159 | defer zlib_stream.deinit(); |
| 1160 | 1160 | ||
| 1161 | var decompressed_section = try allocator.alloc(u8, chdr.ch_size); | 1161 | const decompressed_section = try allocator.alloc(u8, chdr.ch_size); |
| 1162 | errdefer allocator.free(decompressed_section); | 1162 | errdefer allocator.free(decompressed_section); |
| 1163 | 1163 | ||
| 1164 | const read = zlib_stream.reader().readAll(decompressed_section) catch continue; | 1164 | const read = zlib_stream.reader().readAll(decompressed_section) catch continue; |
| ... | @@ -2046,7 +2046,7 @@ pub const ModuleDebugInfo = switch (native_os) { | ... | @@ -2046,7 +2046,7 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 2046 | }; | 2046 | }; |
| 2047 | 2047 | ||
| 2048 | try DW.openDwarfDebugInfo(&di, allocator); | 2048 | try DW.openDwarfDebugInfo(&di, allocator); |
| 2049 | var info = OFileInfo{ | 2049 | const info = OFileInfo{ |
| 2050 | .di = di, | 2050 | .di = di, |
| 2051 | .addr_table = addr_table, | 2051 | .addr_table = addr_table, |
| 2052 | }; | 2052 | }; |
| ... | @@ -2122,7 +2122,7 @@ pub const ModuleDebugInfo = switch (native_os) { | ... | @@ -2122,7 +2122,7 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 2122 | 2122 | ||
| 2123 | // Check if its debug infos are already in the cache | 2123 | // Check if its debug infos are already in the cache |
| 2124 | const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0); | 2124 | const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0); |
| 2125 | var o_file_info = self.ofiles.getPtr(o_file_path) orelse | 2125 | const o_file_info = self.ofiles.getPtr(o_file_path) orelse |
| 2126 | (self.loadOFile(allocator, o_file_path) catch |err| switch (err) { | 2126 | (self.loadOFile(allocator, o_file_path) catch |err| switch (err) { |
| 2127 | error.FileNotFound, | 2127 | error.FileNotFound, |
| 2128 | error.MissingDebugInfo, | 2128 | error.MissingDebugInfo, |
lib/std/dwarf.zig+5-5| ... | @@ -622,7 +622,7 @@ fn parseFormValue(allocator: mem.Allocator, in_stream: anytype, form_id: u64, en | ... | @@ -622,7 +622,7 @@ fn parseFormValue(allocator: mem.Allocator, in_stream: anytype, form_id: u64, en |
| 622 | return parseFormValue(allocator, in_stream, child_form_id, endian, is_64); | 622 | return parseFormValue(allocator, in_stream, child_form_id, endian, is_64); |
| 623 | } | 623 | } |
| 624 | const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64)); | 624 | const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64)); |
| 625 | var frame = try allocator.create(F); | 625 | const frame = try allocator.create(F); |
| 626 | defer allocator.destroy(frame); | 626 | defer allocator.destroy(frame); |
| 627 | return await @asyncCall(frame, {}, parseFormValue, .{ allocator, in_stream, child_form_id, endian, is_64 }); | 627 | return await @asyncCall(frame, {}, parseFormValue, .{ allocator, in_stream, child_form_id, endian, is_64 }); |
| 628 | }, | 628 | }, |
| ... | @@ -1034,7 +1034,7 @@ pub const DwarfInfo = struct { | ... | @@ -1034,7 +1034,7 @@ pub const DwarfInfo = struct { |
| 1034 | // specified by DW_AT.low_pc or to some other value encoded | 1034 | // specified by DW_AT.low_pc or to some other value encoded |
| 1035 | // in the list itself. | 1035 | // in the list itself. |
| 1036 | // If no starting value is specified use zero. | 1036 | // If no starting value is specified use zero. |
| 1037 | var base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) { | 1037 | const base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) { |
| 1038 | error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135 | 1038 | error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135 |
| 1039 | else => return err, | 1039 | else => return err, |
| 1040 | }; | 1040 | }; |
| ... | @@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct { | ... | @@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct { |
| 1438 | if (opcode == LNS.extended_op) { | 1438 | if (opcode == LNS.extended_op) { |
| 1439 | const op_size = try leb.readULEB128(u64, in); | 1439 | const op_size = try leb.readULEB128(u64, in); |
| 1440 | if (op_size < 1) return badDwarf(); | 1440 | if (op_size < 1) return badDwarf(); |
| 1441 | var sub_op = try in.readByte(); | 1441 | const sub_op = try in.readByte(); |
| 1442 | switch (sub_op) { | 1442 | switch (sub_op) { |
| 1443 | LNE.end_sequence => { | 1443 | LNE.end_sequence => { |
| 1444 | prog.end_sequence = true; | 1444 | prog.end_sequence = true; |
| ... | @@ -2308,7 +2308,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo | ... | @@ -2308,7 +2308,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo |
| 2308 | else => return badDwarf(), | 2308 | else => return badDwarf(), |
| 2309 | }; | 2309 | }; |
| 2310 | 2310 | ||
| 2311 | var base = switch (enc & EH.PE.rel_mask) { | 2311 | const base = switch (enc & EH.PE.rel_mask) { |
| 2312 | EH.PE.pcrel => ctx.pc_rel_base, | 2312 | EH.PE.pcrel => ctx.pc_rel_base, |
| 2313 | EH.PE.textrel => ctx.text_rel_base orelse return error.PointerBaseNotSpecified, | 2313 | EH.PE.textrel => ctx.text_rel_base orelse return error.PointerBaseNotSpecified, |
| 2314 | EH.PE.datarel => ctx.data_rel_base orelse return error.PointerBaseNotSpecified, | 2314 | EH.PE.datarel => ctx.data_rel_base orelse return error.PointerBaseNotSpecified, |
| ... | @@ -2624,7 +2624,7 @@ pub const CommonInformationEntry = struct { | ... | @@ -2624,7 +2624,7 @@ pub const CommonInformationEntry = struct { |
| 2624 | var has_aug_data = false; | 2624 | var has_aug_data = false; |
| 2625 | 2625 | ||
| 2626 | var aug_str_len: usize = 0; | 2626 | var aug_str_len: usize = 0; |
| 2627 | var aug_str_start = stream.pos; | 2627 | const aug_str_start = stream.pos; |
| 2628 | var aug_byte = try reader.readByte(); | 2628 | var aug_byte = try reader.readByte(); |
| 2629 | while (aug_byte != 0) : (aug_byte = try reader.readByte()) { | 2629 | while (aug_byte != 0) : (aug_byte = try reader.readByte()) { |
| 2630 | switch (aug_byte) { | 2630 | switch (aug_byte) { |
lib/std/dwarf/expressions.zig+4-4| ... | @@ -443,7 +443,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { | ... | @@ -443,7 +443,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { |
| 443 | OP.xderef_type, | 443 | OP.xderef_type, |
| 444 | => { | 444 | => { |
| 445 | if (self.stack.items.len == 0) return error.InvalidExpression; | 445 | if (self.stack.items.len == 0) return error.InvalidExpression; |
| 446 | var addr = try self.stack.items[self.stack.items.len - 1].asIntegral(); | 446 | const addr = try self.stack.items[self.stack.items.len - 1].asIntegral(); |
| 447 | const addr_space_identifier: ?usize = switch (opcode) { | 447 | const addr_space_identifier: ?usize = switch (opcode) { |
| 448 | OP.xderef, | 448 | OP.xderef, |
| 449 | OP.xderef_size, | 449 | OP.xderef_size, |
| ... | @@ -1350,7 +1350,7 @@ test "DWARF expressions" { | ... | @@ -1350,7 +1350,7 @@ test "DWARF expressions" { |
| 1350 | 1350 | ||
| 1351 | // Arithmetic and Logical Operations | 1351 | // Arithmetic and Logical Operations |
| 1352 | { | 1352 | { |
| 1353 | var context = ExpressionContext{}; | 1353 | const context = ExpressionContext{}; |
| 1354 | 1354 | ||
| 1355 | stack_machine.reset(); | 1355 | stack_machine.reset(); |
| 1356 | program.clearRetainingCapacity(); | 1356 | program.clearRetainingCapacity(); |
| ... | @@ -1474,7 +1474,7 @@ test "DWARF expressions" { | ... | @@ -1474,7 +1474,7 @@ test "DWARF expressions" { |
| 1474 | 1474 | ||
| 1475 | // Control Flow Operations | 1475 | // Control Flow Operations |
| 1476 | { | 1476 | { |
| 1477 | var context = ExpressionContext{}; | 1477 | const context = ExpressionContext{}; |
| 1478 | const expected = .{ | 1478 | const expected = .{ |
| 1479 | .{ OP.le, 1, 1, 0 }, | 1479 | .{ OP.le, 1, 1, 0 }, |
| 1480 | .{ OP.ge, 1, 0, 1 }, | 1480 | .{ OP.ge, 1, 0, 1 }, |
| ... | @@ -1531,7 +1531,7 @@ test "DWARF expressions" { | ... | @@ -1531,7 +1531,7 @@ test "DWARF expressions" { |
| 1531 | 1531 | ||
| 1532 | // Type conversions | 1532 | // Type conversions |
| 1533 | { | 1533 | { |
| 1534 | var context = ExpressionContext{}; | 1534 | const context = ExpressionContext{}; |
| 1535 | stack_machine.reset(); | 1535 | stack_machine.reset(); |
| 1536 | program.clearRetainingCapacity(); | 1536 | program.clearRetainingCapacity(); |
| 1537 | 1537 |
lib/std/enums.zig+4-1| ... | @@ -123,6 +123,7 @@ pub fn directEnumArray( | ... | @@ -123,6 +123,7 @@ pub fn directEnumArray( |
| 123 | test "std.enums.directEnumArray" { | 123 | test "std.enums.directEnumArray" { |
| 124 | const E = enum(i4) { a = 4, b = 6, c = 2 }; | 124 | const E = enum(i4) { a = 4, b = 6, c = 2 }; |
| 125 | var runtime_false: bool = false; | 125 | var runtime_false: bool = false; |
| 126 | _ = &runtime_false; | ||
| 126 | const array = directEnumArray(E, bool, 4, .{ | 127 | const array = directEnumArray(E, bool, 4, .{ |
| 127 | .a = true, | 128 | .a = true, |
| 128 | .b = runtime_false, | 129 | .b = runtime_false, |
| ... | @@ -165,6 +166,7 @@ pub fn directEnumArrayDefault( | ... | @@ -165,6 +166,7 @@ pub fn directEnumArrayDefault( |
| 165 | test "std.enums.directEnumArrayDefault" { | 166 | test "std.enums.directEnumArrayDefault" { |
| 166 | const E = enum(i4) { a = 4, b = 6, c = 2 }; | 167 | const E = enum(i4) { a = 4, b = 6, c = 2 }; |
| 167 | var runtime_false: bool = false; | 168 | var runtime_false: bool = false; |
| 169 | _ = &runtime_false; | ||
| 168 | const array = directEnumArrayDefault(E, bool, false, 4, .{ | 170 | const array = directEnumArrayDefault(E, bool, false, 4, .{ |
| 169 | .a = true, | 171 | .a = true, |
| 170 | .b = runtime_false, | 172 | .b = runtime_false, |
| ... | @@ -179,6 +181,7 @@ test "std.enums.directEnumArrayDefault" { | ... | @@ -179,6 +181,7 @@ test "std.enums.directEnumArrayDefault" { |
| 179 | test "std.enums.directEnumArrayDefault slice" { | 181 | test "std.enums.directEnumArrayDefault slice" { |
| 180 | const E = enum(i4) { a = 4, b = 6, c = 2 }; | 182 | const E = enum(i4) { a = 4, b = 6, c = 2 }; |
| 181 | var runtime_b = "b"; | 183 | var runtime_b = "b"; |
| 184 | _ = &runtime_b; | ||
| 182 | const array = directEnumArrayDefault(E, []const u8, "default", 4, .{ | 185 | const array = directEnumArrayDefault(E, []const u8, "default", 4, .{ |
| 183 | .a = "a", | 186 | .a = "a", |
| 184 | .b = runtime_b, | 187 | .b = runtime_b, |
| ... | @@ -196,7 +199,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E { | ... | @@ -196,7 +199,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E { |
| 196 | return comptime blk: { | 199 | return comptime blk: { |
| 197 | const V = @TypeOf(value); | 200 | const V = @TypeOf(value); |
| 198 | if (V == E) break :blk value; | 201 | if (V == E) break :blk value; |
| 199 | var name: ?[]const u8 = switch (@typeInfo(V)) { | 202 | const name: ?[]const u8 = switch (@typeInfo(V)) { |
| 200 | .EnumLiteral, .Enum => @tagName(value), | 203 | .EnumLiteral, .Enum => @tagName(value), |
| 201 | .Pointer => if (std.meta.trait.isZigString(V)) value else null, | 204 | .Pointer => if (std.meta.trait.isZigString(V)) value else null, |
| 202 | else => null, | 205 | else => null, |
lib/std/event/group.zig+1-1| ... | @@ -66,7 +66,7 @@ pub fn Group(comptime ReturnType: type) type { | ... | @@ -66,7 +66,7 @@ pub fn Group(comptime ReturnType: type) type { |
| 66 | /// `func` must be async and have return type `ReturnType`. | 66 | /// `func` must be async and have return type `ReturnType`. |
| 67 | /// Thread-safe. | 67 | /// Thread-safe. |
| 68 | pub fn call(self: *Self, comptime func: anytype, args: anytype) error{OutOfMemory}!void { | 68 | pub fn call(self: *Self, comptime func: anytype, args: anytype) error{OutOfMemory}!void { |
| 69 | var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args))); | 69 | const frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args))); |
| 70 | errdefer self.allocator.destroy(frame); | 70 | errdefer self.allocator.destroy(frame); |
| 71 | const node = try self.allocator.create(AllocStack.Node); | 71 | const node = try self.allocator.create(AllocStack.Node); |
| 72 | errdefer self.allocator.destroy(node); | 72 | errdefer self.allocator.destroy(node); |
lib/std/event/loop.zig+1-1| ... | @@ -753,7 +753,7 @@ pub const Loop = struct { | ... | @@ -753,7 +753,7 @@ pub const Loop = struct { |
| 753 | } | 753 | } |
| 754 | }; | 754 | }; |
| 755 | 755 | ||
| 756 | var run_frame = try alloc.create(@Frame(Wrapper.run)); | 756 | const run_frame = try alloc.create(@Frame(Wrapper.run)); |
| 757 | run_frame.* = async Wrapper.run(args, self, alloc); | 757 | run_frame.* = async Wrapper.run(args, self, alloc); |
| 758 | } | 758 | } |
| 759 | 759 |
lib/std/event/rwlock.zig+4-4| ... | @@ -228,7 +228,7 @@ test "std.event.RwLock" { | ... | @@ -228,7 +228,7 @@ test "std.event.RwLock" { |
| 228 | } | 228 | } |
| 229 | fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { | 229 | fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { |
| 230 | var read_nodes: [100]Loop.NextTickNode = undefined; | 230 | var read_nodes: [100]Loop.NextTickNode = undefined; |
| 231 | for (read_nodes) |*read_node| { | 231 | for (&read_nodes) |*read_node| { |
| 232 | const frame = allocator.create(@Frame(readRunner)) catch @panic("memory"); | 232 | const frame = allocator.create(@Frame(readRunner)) catch @panic("memory"); |
| 233 | read_node.data = frame; | 233 | read_node.data = frame; |
| 234 | frame.* = async readRunner(lock); | 234 | frame.* = async readRunner(lock); |
| ... | @@ -236,19 +236,19 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { | ... | @@ -236,19 +236,19 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | var write_nodes: [shared_it_count]Loop.NextTickNode = undefined; | 238 | var write_nodes: [shared_it_count]Loop.NextTickNode = undefined; |
| 239 | for (write_nodes) |*write_node| { | 239 | for (&write_nodes) |*write_node| { |
| 240 | const frame = allocator.create(@Frame(writeRunner)) catch @panic("memory"); | 240 | const frame = allocator.create(@Frame(writeRunner)) catch @panic("memory"); |
| 241 | write_node.data = frame; | 241 | write_node.data = frame; |
| 242 | frame.* = async writeRunner(lock); | 242 | frame.* = async writeRunner(lock); |
| 243 | Loop.instance.?.onNextTick(write_node); | 243 | Loop.instance.?.onNextTick(write_node); |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | for (write_nodes) |*write_node| { | 246 | for (&write_nodes) |*write_node| { |
| 247 | const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data)); | 247 | const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data)); |
| 248 | await casted; | 248 | await casted; |
| 249 | allocator.destroy(casted); | 249 | allocator.destroy(casted); |
| 250 | } | 250 | } |
| 251 | for (read_nodes) |*read_node| { | 251 | for (&read_nodes) |*read_node| { |
| 252 | const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data)); | 252 | const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data)); |
| 253 | await casted; | 253 | await casted; |
| 254 | allocator.destroy(casted); | 254 | allocator.destroy(casted); |
lib/std/fmt.zig+11-9| ... | @@ -1296,10 +1296,10 @@ pub fn formatFloatDecimal( | ... | @@ -1296,10 +1296,10 @@ pub fn formatFloatDecimal( |
| 1296 | errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal); | 1296 | errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal); |
| 1297 | 1297 | ||
| 1298 | // exp < 0 means the leading is always 0 as errol result is normalized. | 1298 | // exp < 0 means the leading is always 0 as errol result is normalized. |
| 1299 | var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; | 1299 | const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; |
| 1300 | 1300 | ||
| 1301 | // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this. | 1301 | // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this. |
| 1302 | var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); | 1302 | const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); |
| 1303 | 1303 | ||
| 1304 | if (num_digits_whole > 0) { | 1304 | if (num_digits_whole > 0) { |
| 1305 | // We may have to zero pad, for instance 1e4 requires zero padding. | 1305 | // We may have to zero pad, for instance 1e4 requires zero padding. |
| ... | @@ -1354,10 +1354,10 @@ pub fn formatFloatDecimal( | ... | @@ -1354,10 +1354,10 @@ pub fn formatFloatDecimal( |
| 1354 | } | 1354 | } |
| 1355 | } else { | 1355 | } else { |
| 1356 | // exp < 0 means the leading is always 0 as errol result is normalized. | 1356 | // exp < 0 means the leading is always 0 as errol result is normalized. |
| 1357 | var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; | 1357 | const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; |
| 1358 | 1358 | ||
| 1359 | // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this. | 1359 | // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this. |
| 1360 | var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); | 1360 | const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); |
| 1361 | 1361 | ||
| 1362 | if (num_digits_whole > 0) { | 1362 | if (num_digits_whole > 0) { |
| 1363 | // We may have to zero pad, for instance 1e4 requires zero padding. | 1363 | // We may have to zero pad, for instance 1e4 requires zero padding. |
| ... | @@ -2218,6 +2218,7 @@ test "slice" { | ... | @@ -2218,6 +2218,7 @@ test "slice" { |
| 2218 | } | 2218 | } |
| 2219 | { | 2219 | { |
| 2220 | var runtime_zero: usize = 0; | 2220 | var runtime_zero: usize = 0; |
| 2221 | _ = &runtime_zero; | ||
| 2221 | const value = @as([*]align(1) const []const u8, @ptrFromInt(0xdeadbeef))[runtime_zero..runtime_zero]; | 2222 | const value = @as([*]align(1) const []const u8, @ptrFromInt(0xdeadbeef))[runtime_zero..runtime_zero]; |
| 2222 | try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value}); | 2223 | try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value}); |
| 2223 | } | 2224 | } |
| ... | @@ -2232,6 +2233,7 @@ test "slice" { | ... | @@ -2232,6 +2233,7 @@ test "slice" { |
| 2232 | { | 2233 | { |
| 2233 | var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 }; | 2234 | var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 }; |
| 2234 | var runtime_zero: usize = 0; | 2235 | var runtime_zero: usize = 0; |
| 2236 | _ = &runtime_zero; | ||
| 2235 | try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {any}", .{int_slice[runtime_zero..]}); | 2237 | try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {any}", .{int_slice[runtime_zero..]}); |
| 2236 | try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]}); | 2238 | try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]}); |
| 2237 | try expectFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]}); | 2239 | try expectFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]}); |
| ... | @@ -2794,14 +2796,14 @@ test "padding" { | ... | @@ -2794,14 +2796,14 @@ test "padding" { |
| 2794 | } | 2796 | } |
| 2795 | 2797 | ||
| 2796 | test "decimal float padding" { | 2798 | test "decimal float padding" { |
| 2797 | var number: f32 = 3.1415; | 2799 | const number: f32 = 3.1415; |
| 2798 | try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number}); | 2800 | try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number}); |
| 2799 | try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number}); | 2801 | try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number}); |
| 2800 | try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number}); | 2802 | try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number}); |
| 2801 | } | 2803 | } |
| 2802 | 2804 | ||
| 2803 | test "sci float padding" { | 2805 | test "sci float padding" { |
| 2804 | var number: f32 = 3.1415; | 2806 | const number: f32 = 3.1415; |
| 2805 | try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number}); | 2807 | try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number}); |
| 2806 | try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number}); | 2808 | try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number}); |
| 2807 | try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number}); | 2809 | try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number}); |
| ... | @@ -2825,7 +2827,7 @@ test "named arguments" { | ... | @@ -2825,7 +2827,7 @@ test "named arguments" { |
| 2825 | } | 2827 | } |
| 2826 | 2828 | ||
| 2827 | test "runtime width specifier" { | 2829 | test "runtime width specifier" { |
| 2828 | var width: usize = 9; | 2830 | const width: usize = 9; |
| 2829 | try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width }); | 2831 | try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width }); |
| 2830 | try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width }); | 2832 | try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width }); |
| 2831 | try expectFmt(" hello", "{s:[1]}", .{ "hello", width }); | 2833 | try expectFmt(" hello", "{s:[1]}", .{ "hello", width }); |
| ... | @@ -2833,8 +2835,8 @@ test "runtime width specifier" { | ... | @@ -2833,8 +2835,8 @@ test "runtime width specifier" { |
| 2833 | } | 2835 | } |
| 2834 | 2836 | ||
| 2835 | test "runtime precision specifier" { | 2837 | test "runtime precision specifier" { |
| 2836 | var number: f32 = 3.1415; | 2838 | const number: f32 = 3.1415; |
| 2837 | var precision: usize = 2; | 2839 | const precision: usize = 2; |
| 2838 | try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision }); | 2840 | try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision }); |
| 2839 | try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision }); | 2841 | try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision }); |
| 2840 | } | 2842 | } |
lib/std/fmt/errol.zig+2-2| ... | @@ -367,8 +367,8 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal { | ... | @@ -367,8 +367,8 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal { |
| 367 | var lo = ((fpprev(val) - n) + mid) / 2.0; | 367 | var lo = ((fpprev(val) - n) + mid) / 2.0; |
| 368 | var hi = ((fpnext(val) - n) + mid) / 2.0; | 368 | var hi = ((fpnext(val) - n) + mid) / 2.0; |
| 369 | 369 | ||
| 370 | var buf_index = u64toa(u, buffer); | 370 | const buf_index = u64toa(u, buffer); |
| 371 | var exp = @as(i32, @intCast(buf_index)); | 371 | const exp: i32 = @intCast(buf_index); |
| 372 | var j = buf_index; | 372 | var j = buf_index; |
| 373 | buffer[j] = 0; | 373 | buffer[j] = 0; |
| 374 | 374 |
lib/std/fmt/parse_float/parse.zig+2-2| ... | @@ -105,7 +105,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool | ... | @@ -105,7 +105,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool |
| 105 | // parse initial digits before dot | 105 | // parse initial digits before dot |
| 106 | var mantissa: MantissaT = 0; | 106 | var mantissa: MantissaT = 0; |
| 107 | tryParseDigits(MantissaT, stream, &mantissa, info.base); | 107 | tryParseDigits(MantissaT, stream, &mantissa, info.base); |
| 108 | var int_end = stream.offsetTrue(); | 108 | const int_end = stream.offsetTrue(); |
| 109 | var n_digits = @as(isize, @intCast(stream.offsetTrue())); | 109 | var n_digits = @as(isize, @intCast(stream.offsetTrue())); |
| 110 | // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count | 110 | // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count |
| 111 | if (info.base == 16) n_digits -= 2; | 111 | if (info.base == 16) n_digits -= 2; |
| ... | @@ -188,7 +188,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool | ... | @@ -188,7 +188,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool |
| 188 | // than 19 digits. That means we must have a decimal | 188 | // than 19 digits. That means we must have a decimal |
| 189 | // point, and at least 1 fractional digit. | 189 | // point, and at least 1 fractional digit. |
| 190 | stream.advance(1); | 190 | stream.advance(1); |
| 191 | var marker = stream.offsetTrue(); | 191 | const marker = stream.offsetTrue(); |
| 192 | tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits); | 192 | tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits); |
| 193 | break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue())); | 193 | break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue())); |
| 194 | } | 194 | } |
lib/std/fs.zig+2-2| ... | @@ -1689,7 +1689,7 @@ pub const Dir = struct { | ... | @@ -1689,7 +1689,7 @@ pub const Dir = struct { |
| 1689 | } | 1689 | } |
| 1690 | if (builtin.os.tag == .windows) { | 1690 | if (builtin.os.tag == .windows) { |
| 1691 | var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined; | 1691 | var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined; |
| 1692 | var dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer); | 1692 | const dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer); |
| 1693 | if (builtin.link_libc) { | 1693 | if (builtin.link_libc) { |
| 1694 | return os.chdirW(dir_path); | 1694 | return os.chdirW(dir_path); |
| 1695 | } | 1695 | } |
| ... | @@ -1810,7 +1810,7 @@ pub const Dir = struct { | ... | @@ -1810,7 +1810,7 @@ pub const Dir = struct { |
| 1810 | const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | | 1810 | const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | |
| 1811 | w.SYNCHRONIZE | w.FILE_TRAVERSE; | 1811 | w.SYNCHRONIZE | w.FILE_TRAVERSE; |
| 1812 | const flags: u32 = if (iterable) base_flags | w.FILE_LIST_DIRECTORY else base_flags; | 1812 | const flags: u32 = if (iterable) base_flags | w.FILE_LIST_DIRECTORY else base_flags; |
| 1813 | var dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{ | 1813 | const dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{ |
| 1814 | .no_follow = args.no_follow, | 1814 | .no_follow = args.no_follow, |
| 1815 | .create_disposition = w.FILE_OPEN, | 1815 | .create_disposition = w.FILE_OPEN, |
| 1816 | }); | 1816 | }); |
lib/std/fs/get_app_data_dir.zig+4| ... | @@ -57,6 +57,10 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi | ... | @@ -57,6 +57,10 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi |
| 57 | }, | 57 | }, |
| 58 | .haiku => { | 58 | .haiku => { |
| 59 | var dir_path_ptr: [*:0]u8 = undefined; | 59 | var dir_path_ptr: [*:0]u8 = undefined; |
| 60 | if (true) { | ||
| 61 | _ = &dir_path_ptr; | ||
| 62 | @compileError("TODO: init dir_path_ptr"); | ||
| 63 | } | ||
| 60 | // TODO look into directory_which | 64 | // TODO look into directory_which |
| 61 | const be_user_settings = 0xbbe; | 65 | const be_user_settings = 0xbbe; |
| 62 | const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1); | 66 | const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1); |
lib/std/fs/test.zig+1-1| ... | @@ -80,7 +80,7 @@ const TestContext = struct { | ... | @@ -80,7 +80,7 @@ const TestContext = struct { |
| 80 | transform_fn: *const PathType.TransformFn, | 80 | transform_fn: *const PathType.TransformFn, |
| 81 | 81 | ||
| 82 | pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext { | 82 | pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext { |
| 83 | var tmp = tmpIterableDir(.{}); | 83 | const tmp = tmpIterableDir(.{}); |
| 84 | return .{ | 84 | return .{ |
| 85 | .path_type = path_type, | 85 | .path_type = path_type, |
| 86 | .arena = ArenaAllocator.init(allocator), | 86 | .arena = ArenaAllocator.init(allocator), |
lib/std/fs/watch.zig+3-3| ... | @@ -116,7 +116,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -116,7 +116,7 @@ pub fn Watch(comptime V: type) type { |
| 116 | }, | 116 | }, |
| 117 | }; | 117 | }; |
| 118 | 118 | ||
| 119 | var buf = try allocator.alloc(Event.Error!Event, event_buf_count); | 119 | const buf = try allocator.alloc(Event.Error!Event, event_buf_count); |
| 120 | self.channel.init(buf); | 120 | self.channel.init(buf); |
| 121 | self.os_data.putter_frame = async self.linuxEventPutter(); | 121 | self.os_data.putter_frame = async self.linuxEventPutter(); |
| 122 | return self; | 122 | return self; |
| ... | @@ -132,7 +132,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -132,7 +132,7 @@ pub fn Watch(comptime V: type) type { |
| 132 | }, | 132 | }, |
| 133 | }; | 133 | }; |
| 134 | 134 | ||
| 135 | var buf = try allocator.alloc(Event.Error!Event, event_buf_count); | 135 | const buf = try allocator.alloc(Event.Error!Event, event_buf_count); |
| 136 | self.channel.init(buf); | 136 | self.channel.init(buf); |
| 137 | return self; | 137 | return self; |
| 138 | }, | 138 | }, |
| ... | @@ -147,7 +147,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -147,7 +147,7 @@ pub fn Watch(comptime V: type) type { |
| 147 | }, | 147 | }, |
| 148 | }; | 148 | }; |
| 149 | 149 | ||
| 150 | var buf = try allocator.alloc(Event.Error!Event, event_buf_count); | 150 | const buf = try allocator.alloc(Event.Error!Event, event_buf_count); |
| 151 | self.channel.init(buf); | 151 | self.channel.init(buf); |
| 152 | return self; | 152 | return self; |
| 153 | }, | 153 | }, |
lib/std/hash/auto_hash.zig+1| ... | @@ -280,6 +280,7 @@ test "hash slice shallow" { | ... | @@ -280,6 +280,7 @@ test "hash slice shallow" { |
| 280 | const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 }; | 280 | const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 }; |
| 281 | // TODO audit deep/shallow - maybe it has the wrong behavior with respect to array pointers and slices | 281 | // TODO audit deep/shallow - maybe it has the wrong behavior with respect to array pointers and slices |
| 282 | var runtime_zero: usize = 0; | 282 | var runtime_zero: usize = 0; |
| 283 | _ = &runtime_zero; | ||
| 283 | const a = array1[runtime_zero..]; | 284 | const a = array1[runtime_zero..]; |
| 284 | const b = array2[runtime_zero..]; | 285 | const b = array2[runtime_zero..]; |
| 285 | const c = array1[runtime_zero..3]; | 286 | const c = array1[runtime_zero..3]; |
lib/std/hash/cityhash.zig+1-1| ... | @@ -271,7 +271,7 @@ pub const CityHash64 = struct { | ... | @@ -271,7 +271,7 @@ pub const CityHash64 = struct { |
| 271 | var b1: u64 = b; | 271 | var b1: u64 = b; |
| 272 | a1 +%= w; | 272 | a1 +%= w; |
| 273 | b1 = rotr64(b1 +% a1 +% z, 21); | 273 | b1 = rotr64(b1 +% a1 +% z, 21); |
| 274 | var c: u64 = a1; | 274 | const c: u64 = a1; |
| 275 | a1 +%= x; | 275 | a1 +%= x; |
| 276 | a1 +%= y; | 276 | a1 +%= y; |
| 277 | b1 +%= rotr64(a1, 44); | 277 | b1 +%= rotr64(a1, 44); |
lib/std/hash/murmur.zig+25-31| ... | @@ -134,7 +134,7 @@ pub const Murmur2_64 = struct { | ... | @@ -134,7 +134,7 @@ pub const Murmur2_64 = struct { |
| 134 | const m: u64 = 0xc6a4a7935bd1e995; | 134 | const m: u64 = 0xc6a4a7935bd1e995; |
| 135 | const len: u64 = 4; | 135 | const len: u64 = 4; |
| 136 | var h1: u64 = seed ^ (len *% m); | 136 | var h1: u64 = seed ^ (len *% m); |
| 137 | var k1: u64 = v; | 137 | const k1: u64 = v; |
| 138 | h1 ^= k1; | 138 | h1 ^= k1; |
| 139 | h1 *%= m; | 139 | h1 *%= m; |
| 140 | h1 ^= h1 >> 47; | 140 | h1 ^= h1 >> 47; |
| ... | @@ -282,16 +282,14 @@ pub const Murmur3_32 = struct { | ... | @@ -282,16 +282,14 @@ pub const Murmur3_32 = struct { |
| 282 | const verify = @import("verify.zig"); | 282 | const verify = @import("verify.zig"); |
| 283 | 283 | ||
| 284 | test "murmur2_32" { | 284 | test "murmur2_32" { |
| 285 | var v0: u32 = 0x12345678; | 285 | const v0: u32 = 0x12345678; |
| 286 | var v1: u64 = 0x1234567812345678; | 286 | const v1: u64 = 0x1234567812345678; |
| 287 | var v0le: u32 = v0; | 287 | const v0le: u32, const v1le: u64 = switch (native_endian) { |
| 288 | var v1le: u64 = v1; | 288 | .little => .{ v0, v1 }, |
| 289 | if (native_endian == .big) { | 289 | .big => .{ @byteSwap(v0), @byteSwap(v1) }, |
| 290 | v0le = @byteSwap(v0le); | 290 | }; |
| 291 | v1le = @byteSwap(v1le); | 291 | try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0)); |
| 292 | } | 292 | try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1)); |
| 293 | try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0)); | ||
| 294 | try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1)); | ||
| 295 | } | 293 | } |
| 296 | 294 | ||
| 297 | test "murmur2_32 smhasher" { | 295 | test "murmur2_32 smhasher" { |
| ... | @@ -306,16 +304,14 @@ test "murmur2_32 smhasher" { | ... | @@ -306,16 +304,14 @@ test "murmur2_32 smhasher" { |
| 306 | } | 304 | } |
| 307 | 305 | ||
| 308 | test "murmur2_64" { | 306 | test "murmur2_64" { |
| 309 | var v0: u32 = 0x12345678; | 307 | const v0: u32 = 0x12345678; |
| 310 | var v1: u64 = 0x1234567812345678; | 308 | const v1: u64 = 0x1234567812345678; |
| 311 | var v0le: u32 = v0; | 309 | const v0le: u32, const v1le: u64 = switch (native_endian) { |
| 312 | var v1le: u64 = v1; | 310 | .little => .{ v0, v1 }, |
| 313 | if (native_endian == .big) { | 311 | .big => .{ @byteSwap(v0), @byteSwap(v1) }, |
| 314 | v0le = @byteSwap(v0le); | 312 | }; |
| 315 | v1le = @byteSwap(v1le); | 313 | try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0)); |
| 316 | } | 314 | try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1)); |
| 317 | try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0)); | ||
| 318 | try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1)); | ||
| 319 | } | 315 | } |
| 320 | 316 | ||
| 321 | test "mumur2_64 smhasher" { | 317 | test "mumur2_64 smhasher" { |
| ... | @@ -330,16 +326,14 @@ test "mumur2_64 smhasher" { | ... | @@ -330,16 +326,14 @@ test "mumur2_64 smhasher" { |
| 330 | } | 326 | } |
| 331 | 327 | ||
| 332 | test "murmur3_32" { | 328 | test "murmur3_32" { |
| 333 | var v0: u32 = 0x12345678; | 329 | const v0: u32 = 0x12345678; |
| 334 | var v1: u64 = 0x1234567812345678; | 330 | const v1: u64 = 0x1234567812345678; |
| 335 | var v0le: u32 = v0; | 331 | const v0le: u32, const v1le: u64 = switch (native_endian) { |
| 336 | var v1le: u64 = v1; | 332 | .little => .{ v0, v1 }, |
| 337 | if (native_endian == .big) { | 333 | .big => .{ @byteSwap(v0), @byteSwap(v1) }, |
| 338 | v0le = @byteSwap(v0le); | 334 | }; |
| 339 | v1le = @byteSwap(v1le); | 335 | try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0)); |
| 340 | } | 336 | try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1)); |
| 341 | try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0)); | ||
| 342 | try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1)); | ||
| 343 | } | 337 | } |
| 344 | 338 | ||
| 345 | test "mumur3_32 smhasher" { | 339 | test "mumur3_32 smhasher" { |
lib/std/hash_map.zig+4-4| ... | @@ -1484,8 +1484,8 @@ pub fn HashMapUnmanaged( | ... | @@ -1484,8 +1484,8 @@ pub fn HashMapUnmanaged( |
| 1484 | 1484 | ||
| 1485 | var i: Size = 0; | 1485 | var i: Size = 0; |
| 1486 | var metadata = self.metadata.?; | 1486 | var metadata = self.metadata.?; |
| 1487 | var keys_ptr = self.keys(); | 1487 | const keys_ptr = self.keys(); |
| 1488 | var values_ptr = self.values(); | 1488 | const values_ptr = self.values(); |
| 1489 | while (i < self.capacity()) : (i += 1) { | 1489 | while (i < self.capacity()) : (i += 1) { |
| 1490 | if (metadata[i].isUsed()) { | 1490 | if (metadata[i].isUsed()) { |
| 1491 | other.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], new_ctx); | 1491 | other.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], new_ctx); |
| ... | @@ -1521,8 +1521,8 @@ pub fn HashMapUnmanaged( | ... | @@ -1521,8 +1521,8 @@ pub fn HashMapUnmanaged( |
| 1521 | const old_capacity = self.capacity(); | 1521 | const old_capacity = self.capacity(); |
| 1522 | var i: Size = 0; | 1522 | var i: Size = 0; |
| 1523 | var metadata = self.metadata.?; | 1523 | var metadata = self.metadata.?; |
| 1524 | var keys_ptr = self.keys(); | 1524 | const keys_ptr = self.keys(); |
| 1525 | var values_ptr = self.values(); | 1525 | const values_ptr = self.values(); |
| 1526 | while (i < old_capacity) : (i += 1) { | 1526 | while (i < old_capacity) : (i += 1) { |
| 1527 | if (metadata[i].isUsed()) { | 1527 | if (metadata[i].isUsed()) { |
| 1528 | map.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], ctx); | 1528 | map.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], ctx); |
lib/std/heap.zig+9-9| ... | @@ -81,10 +81,10 @@ const CAllocator = struct { | ... | @@ -81,10 +81,10 @@ const CAllocator = struct { |
| 81 | // Thin wrapper around regular malloc, overallocate to account for | 81 | // Thin wrapper around regular malloc, overallocate to account for |
| 82 | // alignment padding and store the original malloc()'ed pointer before | 82 | // alignment padding and store the original malloc()'ed pointer before |
| 83 | // the aligned address. | 83 | // the aligned address. |
| 84 | var unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null)); | 84 | const unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null)); |
| 85 | const unaligned_addr = @intFromPtr(unaligned_ptr); | 85 | const unaligned_addr = @intFromPtr(unaligned_ptr); |
| 86 | const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment); | 86 | const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment); |
| 87 | var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); | 87 | const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); |
| 88 | getHeader(aligned_ptr).* = unaligned_ptr; | 88 | getHeader(aligned_ptr).* = unaligned_ptr; |
| 89 | 89 | ||
| 90 | return aligned_ptr; | 90 | return aligned_ptr; |
| ... | @@ -661,12 +661,12 @@ test "FixedBufferAllocator.reset" { | ... | @@ -661,12 +661,12 @@ test "FixedBufferAllocator.reset" { |
| 661 | const X = 0xeeeeeeeeeeeeeeee; | 661 | const X = 0xeeeeeeeeeeeeeeee; |
| 662 | const Y = 0xffffffffffffffff; | 662 | const Y = 0xffffffffffffffff; |
| 663 | 663 | ||
| 664 | var x = try allocator.create(u64); | 664 | const x = try allocator.create(u64); |
| 665 | x.* = X; | 665 | x.* = X; |
| 666 | try testing.expectError(error.OutOfMemory, allocator.create(u64)); | 666 | try testing.expectError(error.OutOfMemory, allocator.create(u64)); |
| 667 | 667 | ||
| 668 | fba.reset(); | 668 | fba.reset(); |
| 669 | var y = try allocator.create(u64); | 669 | const y = try allocator.create(u64); |
| 670 | y.* = Y; | 670 | y.* = Y; |
| 671 | 671 | ||
| 672 | // we expect Y to have overwritten X. | 672 | // we expect Y to have overwritten X. |
| ... | @@ -691,9 +691,9 @@ test "FixedBufferAllocator Reuse memory on realloc" { | ... | @@ -691,9 +691,9 @@ test "FixedBufferAllocator Reuse memory on realloc" { |
| 691 | var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); | 691 | var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); |
| 692 | const allocator = fixed_buffer_allocator.allocator(); | 692 | const allocator = fixed_buffer_allocator.allocator(); |
| 693 | 693 | ||
| 694 | var slice0 = try allocator.alloc(u8, 5); | 694 | const slice0 = try allocator.alloc(u8, 5); |
| 695 | try testing.expect(slice0.len == 5); | 695 | try testing.expect(slice0.len == 5); |
| 696 | var slice1 = try allocator.realloc(slice0, 10); | 696 | const slice1 = try allocator.realloc(slice0, 10); |
| 697 | try testing.expect(slice1.ptr == slice0.ptr); | 697 | try testing.expect(slice1.ptr == slice0.ptr); |
| 698 | try testing.expect(slice1.len == 10); | 698 | try testing.expect(slice1.len == 10); |
| 699 | try testing.expectError(error.OutOfMemory, allocator.realloc(slice1, 11)); | 699 | try testing.expectError(error.OutOfMemory, allocator.realloc(slice1, 11)); |
| ... | @@ -706,8 +706,8 @@ test "FixedBufferAllocator Reuse memory on realloc" { | ... | @@ -706,8 +706,8 @@ test "FixedBufferAllocator Reuse memory on realloc" { |
| 706 | var slice0 = try allocator.alloc(u8, 2); | 706 | var slice0 = try allocator.alloc(u8, 2); |
| 707 | slice0[0] = 1; | 707 | slice0[0] = 1; |
| 708 | slice0[1] = 2; | 708 | slice0[1] = 2; |
| 709 | var slice1 = try allocator.alloc(u8, 2); | 709 | const slice1 = try allocator.alloc(u8, 2); |
| 710 | var slice2 = try allocator.realloc(slice0, 4); | 710 | const slice2 = try allocator.realloc(slice0, 4); |
| 711 | try testing.expect(slice0.ptr != slice2.ptr); | 711 | try testing.expect(slice0.ptr != slice2.ptr); |
| 712 | try testing.expect(slice1.ptr != slice2.ptr); | 712 | try testing.expect(slice1.ptr != slice2.ptr); |
| 713 | try testing.expect(slice2[0] == 1); | 713 | try testing.expect(slice2[0] == 1); |
| ... | @@ -757,7 +757,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void { | ... | @@ -757,7 +757,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void { |
| 757 | allocator.free(slice); | 757 | allocator.free(slice); |
| 758 | 758 | ||
| 759 | // Zero-length allocation | 759 | // Zero-length allocation |
| 760 | var empty = try allocator.alloc(u8, 0); | 760 | const empty = try allocator.alloc(u8, 0); |
| 761 | allocator.free(empty); | 761 | allocator.free(empty); |
| 762 | // Allocation with zero-sized types | 762 | // Allocation with zero-sized types |
| 763 | const zero_bit_ptr = try allocator.create(u0); | 763 | const zero_bit_ptr = try allocator.create(u0); |
lib/std/heap/arena_allocator.zig+1-1| ... | @@ -257,7 +257,7 @@ test "ArenaAllocator (reset with preheating)" { | ... | @@ -257,7 +257,7 @@ test "ArenaAllocator (reset with preheating)" { |
| 257 | rounds -= 1; | 257 | rounds -= 1; |
| 258 | _ = arena_allocator.reset(.retain_capacity); | 258 | _ = arena_allocator.reset(.retain_capacity); |
| 259 | var alloced_bytes: usize = 0; | 259 | var alloced_bytes: usize = 0; |
| 260 | var total_size: usize = random.intRangeAtMost(usize, 256, 16384); | 260 | const total_size: usize = random.intRangeAtMost(usize, 256, 16384); |
| 261 | while (alloced_bytes < total_size) { | 261 | while (alloced_bytes < total_size) { |
| 262 | const size = random.intRangeAtMost(usize, 16, 256); | 262 | const size = random.intRangeAtMost(usize, 16, 256); |
| 263 | const alignment = 32; | 263 | const alignment = 32; |
lib/std/heap/general_purpose_allocator.zig+3-3| ... | @@ -512,7 +512,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -512,7 +512,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 512 | var buckets = &self.buckets[bucket_index]; | 512 | var buckets = &self.buckets[bucket_index]; |
| 513 | const slot_count = @divExact(page_size, size_class); | 513 | const slot_count = @divExact(page_size, size_class); |
| 514 | if (self.cur_buckets[bucket_index] == null or self.cur_buckets[bucket_index].?.alloc_cursor == slot_count) { | 514 | if (self.cur_buckets[bucket_index] == null or self.cur_buckets[bucket_index].?.alloc_cursor == slot_count) { |
| 515 | var new_bucket = try self.createBucket(size_class); | 515 | const new_bucket = try self.createBucket(size_class); |
| 516 | errdefer self.freeBucket(new_bucket, size_class); | 516 | errdefer self.freeBucket(new_bucket, size_class); |
| 517 | const node = try self.bucket_node_pool.create(); | 517 | const node = try self.bucket_node_pool.create(); |
| 518 | node.key = new_bucket; | 518 | node.key = new_bucket; |
| ... | @@ -526,7 +526,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -526,7 +526,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 526 | const slot_index = bucket.alloc_cursor; | 526 | const slot_index = bucket.alloc_cursor; |
| 527 | bucket.alloc_cursor += 1; | 527 | bucket.alloc_cursor += 1; |
| 528 | 528 | ||
| 529 | var used_bits_byte = bucket.usedBits(slot_index / 8); | 529 | const used_bits_byte = bucket.usedBits(slot_index / 8); |
| 530 | const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary | 530 | const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary |
| 531 | used_bits_byte.* |= (@as(u8, 1) << used_bit_index); | 531 | used_bits_byte.* |= (@as(u8, 1) << used_bit_index); |
| 532 | bucket.used_count += 1; | 532 | bucket.used_count += 1; |
| ... | @@ -915,7 +915,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -915,7 +915,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 915 | if (bucket.used_count == 0) { | 915 | if (bucket.used_count == 0) { |
| 916 | var entry = self.buckets[bucket_index].getEntryFor(bucket); | 916 | var entry = self.buckets[bucket_index].getEntryFor(bucket); |
| 917 | // save the node for destruction/insertion into in empty_buckets | 917 | // save the node for destruction/insertion into in empty_buckets |
| 918 | var node = entry.node.?; | 918 | const node = entry.node.?; |
| 919 | entry.set(null); | 919 | entry.set(null); |
| 920 | if (self.cur_buckets[bucket_index] == bucket) { | 920 | if (self.cur_buckets[bucket_index] == bucket) { |
| 921 | self.cur_buckets[bucket_index] = null; | 921 | self.cur_buckets[bucket_index] = null; |
lib/std/heap/memory_pool.zig+1-1| ... | @@ -172,7 +172,7 @@ test "memory pool: preheating (success)" { | ... | @@ -172,7 +172,7 @@ test "memory pool: preheating (success)" { |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | test "memory pool: preheating (failure)" { | 174 | test "memory pool: preheating (failure)" { |
| 175 | var failer = std.testing.failing_allocator; | 175 | const failer = std.testing.failing_allocator; |
| 176 | try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initPreheated(failer, 5)); | 176 | try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initPreheated(failer, 5)); |
| 177 | } | 177 | } |
| 178 | 178 |
lib/std/http/Client.zig+1-1| ... | @@ -144,7 +144,7 @@ pub const ConnectionPool = struct { | ... | @@ -144,7 +144,7 @@ pub const ConnectionPool = struct { |
| 144 | pool.mutex.lock(); | 144 | pool.mutex.lock(); |
| 145 | defer pool.mutex.unlock(); | 145 | defer pool.mutex.unlock(); |
| 146 | 146 | ||
| 147 | var next = pool.free.first; | 147 | const next = pool.free.first; |
| 148 | _ = next; | 148 | _ = next; |
| 149 | while (pool.free_len > new_size) { | 149 | while (pool.free_len > new_size) { |
| 150 | const popped = pool.free.popFirst() orelse unreachable; | 150 | const popped = pool.free.popFirst() orelse unreachable; |
lib/std/http/protocol.zig+6-9| ... | @@ -765,10 +765,9 @@ test "HeadersParser.read length" { | ... | @@ -765,10 +765,9 @@ test "HeadersParser.read length" { |
| 765 | var r = HeadersParser.initDynamic(256); | 765 | var r = HeadersParser.initDynamic(256); |
| 766 | defer r.header_bytes.deinit(std.testing.allocator); | 766 | defer r.header_bytes.deinit(std.testing.allocator); |
| 767 | const data = "GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5\r\n\r\nHello"; | 767 | const data = "GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5\r\n\r\nHello"; |
| 768 | var fbs = std.io.fixedBufferStream(data); | ||
| 769 | 768 | ||
| 770 | var conn = MockBufferedConnection{ | 769 | var conn: MockBufferedConnection = .{ |
| 771 | .conn = fbs, | 770 | .conn = std.io.fixedBufferStream(data), |
| 772 | }; | 771 | }; |
| 773 | 772 | ||
| 774 | while (true) { // read headers | 773 | while (true) { // read headers |
| ... | @@ -796,10 +795,9 @@ test "HeadersParser.read chunked" { | ... | @@ -796,10 +795,9 @@ test "HeadersParser.read chunked" { |
| 796 | var r = HeadersParser.initDynamic(256); | 795 | var r = HeadersParser.initDynamic(256); |
| 797 | defer r.header_bytes.deinit(std.testing.allocator); | 796 | defer r.header_bytes.deinit(std.testing.allocator); |
| 798 | const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\n\r\n"; | 797 | const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\n\r\n"; |
| 799 | var fbs = std.io.fixedBufferStream(data); | ||
| 800 | 798 | ||
| 801 | var conn = MockBufferedConnection{ | 799 | var conn: MockBufferedConnection = .{ |
| 802 | .conn = fbs, | 800 | .conn = std.io.fixedBufferStream(data), |
| 803 | }; | 801 | }; |
| 804 | 802 | ||
| 805 | while (true) { // read headers | 803 | while (true) { // read headers |
| ... | @@ -826,10 +824,9 @@ test "HeadersParser.read chunked trailer" { | ... | @@ -826,10 +824,9 @@ test "HeadersParser.read chunked trailer" { |
| 826 | var r = HeadersParser.initDynamic(256); | 824 | var r = HeadersParser.initDynamic(256); |
| 827 | defer r.header_bytes.deinit(std.testing.allocator); | 825 | defer r.header_bytes.deinit(std.testing.allocator); |
| 828 | const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\nContent-Type: text/plain\r\n\r\n"; | 826 | const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\nContent-Type: text/plain\r\n\r\n"; |
| 829 | var fbs = std.io.fixedBufferStream(data); | ||
| 830 | 827 | ||
| 831 | var conn = MockBufferedConnection{ | 828 | var conn: MockBufferedConnection = .{ |
| 832 | .conn = fbs, | 829 | .conn = std.io.fixedBufferStream(data), |
| 833 | }; | 830 | }; |
| 834 | 831 | ||
| 835 | while (true) { // read headers | 832 | while (true) { // read headers |
lib/std/io/Reader/test.zig+8-8| ... | @@ -91,13 +91,13 @@ test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until th | ... | @@ -91,13 +91,13 @@ test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until th |
| 91 | const reader = fis.reader(); | 91 | const reader = fis.reader(); |
| 92 | 92 | ||
| 93 | { | 93 | { |
| 94 | var result = try reader.readUntilDelimiterAlloc(a, '\n', 5); | 94 | const result = try reader.readUntilDelimiterAlloc(a, '\n', 5); |
| 95 | defer a.free(result); | 95 | defer a.free(result); |
| 96 | try std.testing.expectEqualStrings("0000", result); | 96 | try std.testing.expectEqualStrings("0000", result); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | { | 99 | { |
| 100 | var result = try reader.readUntilDelimiterAlloc(a, '\n', 5); | 100 | const result = try reader.readUntilDelimiterAlloc(a, '\n', 5); |
| 101 | defer a.free(result); | 101 | defer a.free(result); |
| 102 | try std.testing.expectEqualStrings("1234", result); | 102 | try std.testing.expectEqualStrings("1234", result); |
| 103 | } | 103 | } |
| ... | @@ -112,7 +112,7 @@ test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" { | ... | @@ -112,7 +112,7 @@ test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" { |
| 112 | const reader = fis.reader(); | 112 | const reader = fis.reader(); |
| 113 | 113 | ||
| 114 | { | 114 | { |
| 115 | var result = try reader.readUntilDelimiterAlloc(a, '\n', 5); | 115 | const result = try reader.readUntilDelimiterAlloc(a, '\n', 5); |
| 116 | defer a.free(result); | 116 | defer a.free(result); |
| 117 | try std.testing.expectEqualStrings("", result); | 117 | try std.testing.expectEqualStrings("", result); |
| 118 | } | 118 | } |
| ... | @@ -126,7 +126,7 @@ test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList wi | ... | @@ -126,7 +126,7 @@ test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList wi |
| 126 | 126 | ||
| 127 | try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterAlloc(a, '\n', 5)); | 127 | try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterAlloc(a, '\n', 5)); |
| 128 | 128 | ||
| 129 | var result = try reader.readUntilDelimiterAlloc(a, '\n', 5); | 129 | const result = try reader.readUntilDelimiterAlloc(a, '\n', 5); |
| 130 | defer a.free(result); | 130 | defer a.free(result); |
| 131 | try std.testing.expectEqualStrings("67", result); | 131 | try std.testing.expectEqualStrings("67", result); |
| 132 | } | 132 | } |
| ... | @@ -219,13 +219,13 @@ test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read unt | ... | @@ -219,13 +219,13 @@ test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read unt |
| 219 | const reader = fis.reader(); | 219 | const reader = fis.reader(); |
| 220 | 220 | ||
| 221 | { | 221 | { |
| 222 | var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; | 222 | const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; |
| 223 | defer a.free(result); | 223 | defer a.free(result); |
| 224 | try std.testing.expectEqualStrings("0000", result); | 224 | try std.testing.expectEqualStrings("0000", result); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | { | 227 | { |
| 228 | var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; | 228 | const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; |
| 229 | defer a.free(result); | 229 | defer a.free(result); |
| 230 | try std.testing.expectEqualStrings("1234", result); | 230 | try std.testing.expectEqualStrings("1234", result); |
| 231 | } | 231 | } |
| ... | @@ -240,7 +240,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" { | ... | @@ -240,7 +240,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" { |
| 240 | const reader = fis.reader(); | 240 | const reader = fis.reader(); |
| 241 | 241 | ||
| 242 | { | 242 | { |
| 243 | var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; | 243 | const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; |
| 244 | defer a.free(result); | 244 | defer a.free(result); |
| 245 | try std.testing.expectEqualStrings("", result); | 245 | try std.testing.expectEqualStrings("", result); |
| 246 | } | 246 | } |
| ... | @@ -254,7 +254,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayLi | ... | @@ -254,7 +254,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayLi |
| 254 | 254 | ||
| 255 | try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)); | 255 | try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)); |
| 256 | 256 | ||
| 257 | var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; | 257 | const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; |
| 258 | defer a.free(result); | 258 | defer a.free(result); |
| 259 | try std.testing.expectEqualStrings("67", result); | 259 | try std.testing.expectEqualStrings("67", result); |
| 260 | } | 260 | } |
lib/std/io/buffered_reader.zig+15-10| ... | @@ -131,8 +131,9 @@ test "io.BufferedReader Block" { | ... | @@ -131,8 +131,9 @@ test "io.BufferedReader Block" { |
| 131 | 131 | ||
| 132 | // len out == block | 132 | // len out == block |
| 133 | { | 133 | { |
| 134 | var block_reader = BlockReader.init(block, 2); | 134 | var test_buf_reader: BufferedReader(4, BlockReader) = .{ |
| 135 | var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader }; | 135 | .unbuffered_reader = BlockReader.init(block, 2), |
| 136 | }; | ||
| 136 | var out_buf: [4]u8 = undefined; | 137 | var out_buf: [4]u8 = undefined; |
| 137 | _ = try test_buf_reader.read(&out_buf); | 138 | _ = try test_buf_reader.read(&out_buf); |
| 138 | try testing.expectEqualSlices(u8, &out_buf, block); | 139 | try testing.expectEqualSlices(u8, &out_buf, block); |
| ... | @@ -143,8 +144,9 @@ test "io.BufferedReader Block" { | ... | @@ -143,8 +144,9 @@ test "io.BufferedReader Block" { |
| 143 | 144 | ||
| 144 | // len out < block | 145 | // len out < block |
| 145 | { | 146 | { |
| 146 | var block_reader = BlockReader.init(block, 2); | 147 | var test_buf_reader: BufferedReader(4, BlockReader) = .{ |
| 147 | var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader }; | 148 | .unbuffered_reader = BlockReader.init(block, 2), |
| 149 | }; | ||
| 148 | var out_buf: [3]u8 = undefined; | 150 | var out_buf: [3]u8 = undefined; |
| 149 | _ = try test_buf_reader.read(&out_buf); | 151 | _ = try test_buf_reader.read(&out_buf); |
| 150 | try testing.expectEqualSlices(u8, &out_buf, "012"); | 152 | try testing.expectEqualSlices(u8, &out_buf, "012"); |
| ... | @@ -157,8 +159,9 @@ test "io.BufferedReader Block" { | ... | @@ -157,8 +159,9 @@ test "io.BufferedReader Block" { |
| 157 | 159 | ||
| 158 | // len out > block | 160 | // len out > block |
| 159 | { | 161 | { |
| 160 | var block_reader = BlockReader.init(block, 2); | 162 | var test_buf_reader: BufferedReader(4, BlockReader) = .{ |
| 161 | var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader }; | 163 | .unbuffered_reader = BlockReader.init(block, 2), |
| 164 | }; | ||
| 162 | var out_buf: [5]u8 = undefined; | 165 | var out_buf: [5]u8 = undefined; |
| 163 | _ = try test_buf_reader.read(&out_buf); | 166 | _ = try test_buf_reader.read(&out_buf); |
| 164 | try testing.expectEqualSlices(u8, &out_buf, "01230"); | 167 | try testing.expectEqualSlices(u8, &out_buf, "01230"); |
| ... | @@ -169,8 +172,9 @@ test "io.BufferedReader Block" { | ... | @@ -169,8 +172,9 @@ test "io.BufferedReader Block" { |
| 169 | 172 | ||
| 170 | // len out == 0 | 173 | // len out == 0 |
| 171 | { | 174 | { |
| 172 | var block_reader = BlockReader.init(block, 2); | 175 | var test_buf_reader: BufferedReader(4, BlockReader) = .{ |
| 173 | var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader }; | 176 | .unbuffered_reader = BlockReader.init(block, 2), |
| 177 | }; | ||
| 174 | var out_buf: [0]u8 = undefined; | 178 | var out_buf: [0]u8 = undefined; |
| 175 | _ = try test_buf_reader.read(&out_buf); | 179 | _ = try test_buf_reader.read(&out_buf); |
| 176 | try testing.expectEqualSlices(u8, &out_buf, ""); | 180 | try testing.expectEqualSlices(u8, &out_buf, ""); |
| ... | @@ -178,8 +182,9 @@ test "io.BufferedReader Block" { | ... | @@ -178,8 +182,9 @@ test "io.BufferedReader Block" { |
| 178 | 182 | ||
| 179 | // len bufreader buf > block | 183 | // len bufreader buf > block |
| 180 | { | 184 | { |
| 181 | var block_reader = BlockReader.init(block, 2); | 185 | var test_buf_reader: BufferedReader(5, BlockReader) = .{ |
| 182 | var test_buf_reader = BufferedReader(5, BlockReader){ .unbuffered_reader = block_reader }; | 186 | .unbuffered_reader = BlockReader.init(block, 2), |
| 187 | }; | ||
| 183 | var out_buf: [4]u8 = undefined; | 188 | var out_buf: [4]u8 = undefined; |
| 184 | _ = try test_buf_reader.read(&out_buf); | 189 | _ = try test_buf_reader.read(&out_buf); |
| 185 | try testing.expectEqualSlices(u8, &out_buf, block); | 190 | try testing.expectEqualSlices(u8, &out_buf, block); |
lib/std/io/test.zig+2-2| ... | @@ -167,13 +167,13 @@ test "updateTimes" { | ... | @@ -167,13 +167,13 @@ test "updateTimes" { |
| 167 | file.close(); | 167 | file.close(); |
| 168 | tmp.dir.deleteFile(tmp_file_name) catch {}; | 168 | tmp.dir.deleteFile(tmp_file_name) catch {}; |
| 169 | } | 169 | } |
| 170 | var stat_old = try file.stat(); | 170 | const stat_old = try file.stat(); |
| 171 | // Set atime and mtime to 5s before | 171 | // Set atime and mtime to 5s before |
| 172 | try file.updateTimes( | 172 | try file.updateTimes( |
| 173 | stat_old.atime - 5 * std.time.ns_per_s, | 173 | stat_old.atime - 5 * std.time.ns_per_s, |
| 174 | stat_old.mtime - 5 * std.time.ns_per_s, | 174 | stat_old.mtime - 5 * std.time.ns_per_s, |
| 175 | ); | 175 | ); |
| 176 | var stat_new = try file.stat(); | 176 | const stat_new = try file.stat(); |
| 177 | try expect(stat_new.atime < stat_old.atime); | 177 | try expect(stat_new.atime < stat_old.atime); |
| 178 | try expect(stat_new.mtime < stat_old.mtime); | 178 | try expect(stat_new.mtime < stat_old.mtime); |
| 179 | } | 179 | } |
lib/std/json/dynamic_test.zig+9-9| ... | @@ -190,15 +190,15 @@ test "Value.jsonStringify" { | ... | @@ -190,15 +190,15 @@ test "Value.jsonStringify" { |
| 190 | var obj = ObjectMap.init(testing.allocator); | 190 | var obj = ObjectMap.init(testing.allocator); |
| 191 | defer obj.deinit(); | 191 | defer obj.deinit(); |
| 192 | try obj.putNoClobber("a", .{ .string = "b" }); | 192 | try obj.putNoClobber("a", .{ .string = "b" }); |
| 193 | var array = [_]Value{ | 193 | const array = [_]Value{ |
| 194 | Value.null, | 194 | .null, |
| 195 | Value{ .bool = true }, | 195 | .{ .bool = true }, |
| 196 | Value{ .integer = 42 }, | 196 | .{ .integer = 42 }, |
| 197 | Value{ .number_string = "43" }, | 197 | .{ .number_string = "43" }, |
| 198 | Value{ .float = 42 }, | 198 | .{ .float = 42 }, |
| 199 | Value{ .string = "weeee" }, | 199 | .{ .string = "weeee" }, |
| 200 | Value{ .array = Array.fromOwnedSlice(undefined, &vals) }, | 200 | .{ .array = Array.fromOwnedSlice(undefined, &vals) }, |
| 201 | Value{ .object = obj }, | 201 | .{ .object = obj }, |
| 202 | }; | 202 | }; |
| 203 | var buffer: [0x1000]u8 = undefined; | 203 | var buffer: [0x1000]u8 = undefined; |
| 204 | var fbs = std.io.fixedBufferStream(&buffer); | 204 | var fbs = std.io.fixedBufferStream(&buffer); |
lib/std/json/static_test.zig+9-9| ... | @@ -533,7 +533,7 @@ test "parse into struct with misc fields" { | ... | @@ -533,7 +533,7 @@ test "parse into struct with misc fields" { |
| 533 | string: []const u8, | 533 | string: []const u8, |
| 534 | }; | 534 | }; |
| 535 | }; | 535 | }; |
| 536 | var document_str = | 536 | const document_str = |
| 537 | \\{ | 537 | \\{ |
| 538 | \\ "int": 420, | 538 | \\ "int": 420, |
| 539 | \\ "float": 3.14, | 539 | \\ "float": 3.14, |
| ... | @@ -588,7 +588,7 @@ test "parse into struct with strings and arrays with sentinels" { | ... | @@ -588,7 +588,7 @@ test "parse into struct with strings and arrays with sentinels" { |
| 588 | data: [:99]const i32, | 588 | data: [:99]const i32, |
| 589 | simple_data: []const i32, | 589 | simple_data: []const i32, |
| 590 | }; | 590 | }; |
| 591 | var document_str = | 591 | const document_str = |
| 592 | \\{ | 592 | \\{ |
| 593 | \\ "language": "zig", | 593 | \\ "language": "zig", |
| 594 | \\ "language_without_sentinel": "zig again!", | 594 | \\ "language_without_sentinel": "zig again!", |
| ... | @@ -634,7 +634,7 @@ test "parse into struct ignoring unknown fields" { | ... | @@ -634,7 +634,7 @@ test "parse into struct ignoring unknown fields" { |
| 634 | language: []const u8, | 634 | language: []const u8, |
| 635 | }; | 635 | }; |
| 636 | 636 | ||
| 637 | var str = | 637 | const str = |
| 638 | \\{ | 638 | \\{ |
| 639 | \\ "int": 420, | 639 | \\ "int": 420, |
| 640 | \\ "float": 3.14, | 640 | \\ "float": 3.14, |
| ... | @@ -685,7 +685,7 @@ test "parse into tuple" { | ... | @@ -685,7 +685,7 @@ test "parse into tuple" { |
| 685 | std.meta.Tuple(&.{ u8, []const u8, u8 }), | 685 | std.meta.Tuple(&.{ u8, []const u8, u8 }), |
| 686 | Union, | 686 | Union, |
| 687 | }); | 687 | }); |
| 688 | var str = | 688 | const str = |
| 689 | \\[ | 689 | \\[ |
| 690 | \\ 420, | 690 | \\ 420, |
| 691 | \\ 3.14, | 691 | \\ 3.14, |
| ... | @@ -789,7 +789,7 @@ test "parse into vector" { | ... | @@ -789,7 +789,7 @@ test "parse into vector" { |
| 789 | vec_i32: @Vector(4, i32), | 789 | vec_i32: @Vector(4, i32), |
| 790 | vec_f32: @Vector(2, f32), | 790 | vec_f32: @Vector(2, f32), |
| 791 | }; | 791 | }; |
| 792 | var s = | 792 | const s = |
| 793 | \\{ | 793 | \\{ |
| 794 | \\ "vec_f32": [1.5, 2.5], | 794 | \\ "vec_f32": [1.5, 2.5], |
| 795 | \\ "vec_i32": [4, 5, 6, 7] | 795 | \\ "vec_i32": [4, 5, 6, 7] |
| ... | @@ -821,7 +821,7 @@ test "json parse partial" { | ... | @@ -821,7 +821,7 @@ test "json parse partial" { |
| 821 | num: u32, | 821 | num: u32, |
| 822 | yes: bool, | 822 | yes: bool, |
| 823 | }; | 823 | }; |
| 824 | var str = | 824 | const str = |
| 825 | \\{ | 825 | \\{ |
| 826 | \\ "outer": { | 826 | \\ "outer": { |
| 827 | \\ "key1": { | 827 | \\ "key1": { |
| ... | @@ -835,7 +835,7 @@ test "json parse partial" { | ... | @@ -835,7 +835,7 @@ test "json parse partial" { |
| 835 | \\ } | 835 | \\ } |
| 836 | \\} | 836 | \\} |
| 837 | ; | 837 | ; |
| 838 | var allocator = testing.allocator; | 838 | const allocator = testing.allocator; |
| 839 | var scanner = JsonScanner.initCompleteInput(allocator, str); | 839 | var scanner = JsonScanner.initCompleteInput(allocator, str); |
| 840 | defer scanner.deinit(); | 840 | defer scanner.deinit(); |
| 841 | 841 | ||
| ... | @@ -876,13 +876,13 @@ test "json parse allocate when streaming" { | ... | @@ -876,13 +876,13 @@ test "json parse allocate when streaming" { |
| 876 | not_const: []u8, | 876 | not_const: []u8, |
| 877 | is_const: []const u8, | 877 | is_const: []const u8, |
| 878 | }; | 878 | }; |
| 879 | var str = | 879 | const str = |
| 880 | \\{ | 880 | \\{ |
| 881 | \\ "not_const": "non const string", | 881 | \\ "not_const": "non const string", |
| 882 | \\ "is_const": "const string" | 882 | \\ "is_const": "const string" |
| 883 | \\} | 883 | \\} |
| 884 | ; | 884 | ; |
| 885 | var allocator = testing.allocator; | 885 | const allocator = testing.allocator; |
| 886 | var arena = ArenaAllocator.init(allocator); | 886 | var arena = ArenaAllocator.init(allocator); |
| 887 | defer arena.deinit(); | 887 | defer arena.deinit(); |
| 888 | 888 |
lib/std/math.zig+2-1| ... | @@ -427,6 +427,7 @@ test "clamp" { | ... | @@ -427,6 +427,7 @@ test "clamp" { |
| 427 | 427 | ||
| 428 | // Mix of comptime and non-comptime | 428 | // Mix of comptime and non-comptime |
| 429 | var i: i32 = 1; | 429 | var i: i32 = 1; |
| 430 | _ = &i; | ||
| 430 | try testing.expect(std.math.clamp(i, 0, 1) == 1); | 431 | try testing.expect(std.math.clamp(i, 0, 1) == 1); |
| 431 | } | 432 | } |
| 432 | 433 | ||
| ... | @@ -1113,7 +1114,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { | ... | @@ -1113,7 +1114,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { |
| 1113 | comptime assert(info.signedness == .unsigned); | 1114 | comptime assert(info.signedness == .unsigned); |
| 1114 | const PromotedType = std.meta.Int(info.signedness, info.bits + 1); | 1115 | const PromotedType = std.meta.Int(info.signedness, info.bits + 1); |
| 1115 | const overflowBit = @as(PromotedType, 1) << info.bits; | 1116 | const overflowBit = @as(PromotedType, 1) << info.bits; |
| 1116 | var x = ceilPowerOfTwoPromote(T, value); | 1117 | const x = ceilPowerOfTwoPromote(T, value); |
| 1117 | if (overflowBit & x != 0) { | 1118 | if (overflowBit & x != 0) { |
| 1118 | return error.Overflow; | 1119 | return error.Overflow; |
| 1119 | } | 1120 | } |
lib/std/math/atan.zig+2-2| ... | @@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 { | ... | @@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 { |
| 143 | }; | 143 | }; |
| 144 | 144 | ||
| 145 | var x = x_; | 145 | var x = x_; |
| 146 | var ux = @as(u64, @bitCast(x)); | 146 | const ux: u64 = @bitCast(x); |
| 147 | var ix = @as(u32, @intCast(ux >> 32)); | 147 | var ix: u32 = @intCast(ux >> 32); |
| 148 | const sign = ix >> 31; | 148 | const sign = ix >> 31; |
| 149 | ix &= 0x7FFFFFFF; | 149 | ix &= 0x7FFFFFFF; |
| 150 | 150 |
lib/std/math/atan2.zig+8-8| ... | @@ -104,7 +104,7 @@ fn atan2_32(y: f32, x: f32) f32 { | ... | @@ -104,7 +104,7 @@ fn atan2_32(y: f32, x: f32) f32 { |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | // z = atan(|y / x|) with correct underflow | 106 | // z = atan(|y / x|) with correct underflow |
| 107 | var z = z: { | 107 | const z = z: { |
| 108 | if ((m & 2) != 0 and iy + (26 << 23) < ix) { | 108 | if ((m & 2) != 0 and iy + (26 << 23) < ix) { |
| 109 | break :z 0.0; | 109 | break :z 0.0; |
| 110 | } else { | 110 | } else { |
| ... | @@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 { | ... | @@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 { |
| 129 | return x + y; | 129 | return x + y; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | var ux = @as(u64, @bitCast(x)); | 132 | const ux: u64 = @bitCast(x); |
| 133 | var ix = @as(u32, @intCast(ux >> 32)); | 133 | var ix: u32 = @intCast(ux >> 32); |
| 134 | var lx = @as(u32, @intCast(ux & 0xFFFFFFFF)); | 134 | const lx: u32 = @intCast(ux & 0xFFFFFFFF); |
| 135 | 135 | ||
| 136 | var uy = @as(u64, @bitCast(y)); | 136 | const uy: u64 = @bitCast(y); |
| 137 | var iy = @as(u32, @intCast(uy >> 32)); | 137 | var iy: u32 = @intCast(uy >> 32); |
| 138 | var ly = @as(u32, @intCast(uy & 0xFFFFFFFF)); | 138 | const ly: u32 = @intCast(uy & 0xFFFFFFFF); |
| 139 | 139 | ||
| 140 | // x = 1.0 | 140 | // x = 1.0 |
| 141 | if ((ix -% 0x3FF00000) | lx == 0) { | 141 | if ((ix -% 0x3FF00000) | lx == 0) { |
| ... | @@ -194,7 +194,7 @@ fn atan2_64(y: f64, x: f64) f64 { | ... | @@ -194,7 +194,7 @@ fn atan2_64(y: f64, x: f64) f64 { |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | // z = atan(|y / x|) with correct underflow | 196 | // z = atan(|y / x|) with correct underflow |
| 197 | var z = z: { | 197 | const z = z: { |
| 198 | if ((m & 2) != 0 and iy +% (64 << 20) < ix) { | 198 | if ((m & 2) != 0 and iy +% (64 << 20) < ix) { |
| 199 | break :z 0.0; | 199 | break :z 0.0; |
| 200 | } else { | 200 | } else { |
lib/std/math/big/int.zig+5-5| ... | @@ -797,7 +797,7 @@ pub const Mutable = struct { | ... | @@ -797,7 +797,7 @@ pub const Mutable = struct { |
| 797 | // 0b0..01..1000 with @log2(@sizeOf(Limb)) consecutive ones | 797 | // 0b0..01..1000 with @log2(@sizeOf(Limb)) consecutive ones |
| 798 | const endian_mask: usize = (@sizeOf(Limb) - 1) << 3; | 798 | const endian_mask: usize = (@sizeOf(Limb) - 1) << 3; |
| 799 | 799 | ||
| 800 | var bytes = std.mem.sliceAsBytes(r.limbs); | 800 | const bytes = std.mem.sliceAsBytes(r.limbs); |
| 801 | var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb)); | 801 | var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb)); |
| 802 | 802 | ||
| 803 | var k: usize = 0; | 803 | var k: usize = 0; |
| ... | @@ -1407,7 +1407,7 @@ pub const Mutable = struct { | ... | @@ -1407,7 +1407,7 @@ pub const Mutable = struct { |
| 1407 | } | 1407 | } |
| 1408 | 1408 | ||
| 1409 | // Avoid copying u to s by swapping u and s | 1409 | // Avoid copying u to s by swapping u and s |
| 1410 | var tmp_s = s; | 1410 | const tmp_s = s; |
| 1411 | s = u; | 1411 | s = u; |
| 1412 | u = tmp_s; | 1412 | u = tmp_s; |
| 1413 | } | 1413 | } |
| ... | @@ -1911,7 +1911,7 @@ pub const Mutable = struct { | ... | @@ -1911,7 +1911,7 @@ pub const Mutable = struct { |
| 1911 | var positive = true; | 1911 | var positive = true; |
| 1912 | if (signedness == .signed) { | 1912 | if (signedness == .signed) { |
| 1913 | const total_bits = bit_offset + bit_count; | 1913 | const total_bits = bit_offset + bit_count; |
| 1914 | var last_byte = switch (endian) { | 1914 | const last_byte = switch (endian) { |
| 1915 | .little => ((total_bits + 7) / 8) - 1, | 1915 | .little => ((total_bits + 7) / 8) - 1, |
| 1916 | .big => buffer.len - ((total_bits + 7) / 8), | 1916 | .big => buffer.len - ((total_bits + 7) / 8), |
| 1917 | }; | 1917 | }; |
| ... | @@ -3161,7 +3161,7 @@ pub const Managed = struct { | ... | @@ -3161,7 +3161,7 @@ pub const Managed = struct { |
| 3161 | 3161 | ||
| 3162 | /// r = a ^ b | 3162 | /// r = a ^ b |
| 3163 | pub fn bitXor(r: *Managed, a: *const Managed, b: *const Managed) !void { | 3163 | pub fn bitXor(r: *Managed, a: *const Managed, b: *const Managed) !void { |
| 3164 | var cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive()); | 3164 | const cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive()); |
| 3165 | try r.ensureCapacity(cap); | 3165 | try r.ensureCapacity(cap); |
| 3166 | 3166 | ||
| 3167 | var m = r.toMutable(); | 3167 | var m = r.toMutable(); |
| ... | @@ -4178,7 +4178,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void { | ... | @@ -4178,7 +4178,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void { |
| 4178 | // most significant bit set. | 4178 | // most significant bit set. |
| 4179 | // Square the result if the current bit is zero, square and multiply by a if | 4179 | // Square the result if the current bit is zero, square and multiply by a if |
| 4180 | // it is one. | 4180 | // it is one. |
| 4181 | var exp_bits = 32 - 1 - b_leading_zeros; | 4181 | const exp_bits = 32 - 1 - b_leading_zeros; |
| 4182 | var exp = b << @as(u5, @intCast(1 + b_leading_zeros)); | 4182 | var exp = b << @as(u5, @intCast(1 + b_leading_zeros)); |
| 4183 | 4183 | ||
| 4184 | var i: usize = 0; | 4184 | var i: usize = 0; |
lib/std/math/big/int_test.zig+28-9| ... | @@ -300,20 +300,18 @@ test "big.int twos complement limit set" { | ... | @@ -300,20 +300,18 @@ test "big.int twos complement limit set" { |
| 300 | }; | 300 | }; |
| 301 | 301 | ||
| 302 | inline for (test_types) |T| { | 302 | inline for (test_types) |T| { |
| 303 | // To work around 'control flow attempts to use compile-time variable at runtime' | 303 | const int_info = @typeInfo(T).Int; |
| 304 | const U = T; | ||
| 305 | const int_info = @typeInfo(U).Int; | ||
| 306 | 304 | ||
| 307 | var a = try Managed.init(testing.allocator); | 305 | var a = try Managed.init(testing.allocator); |
| 308 | defer a.deinit(); | 306 | defer a.deinit(); |
| 309 | 307 | ||
| 310 | try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits); | 308 | try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits); |
| 311 | var max: U = maxInt(U); | 309 | const max: T = maxInt(T); |
| 312 | try testing.expect(max == try a.to(U)); | 310 | try testing.expect(max == try a.to(T)); |
| 313 | 311 | ||
| 314 | try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits); | 312 | try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits); |
| 315 | var min: U = minInt(U); | 313 | const min: T = minInt(T); |
| 316 | try testing.expect(min == try a.to(U)); | 314 | try testing.expect(min == try a.to(T)); |
| 317 | } | 315 | } |
| 318 | } | 316 | } |
| 319 | 317 | ||
| ... | @@ -519,6 +517,9 @@ test "big.int add multi-single" { | ... | @@ -519,6 +517,9 @@ test "big.int add multi-single" { |
| 519 | test "big.int add multi-multi" { | 517 | test "big.int add multi-multi" { |
| 520 | var op1: u128 = 0xefefefef7f7f7f7f; | 518 | var op1: u128 = 0xefefefef7f7f7f7f; |
| 521 | var op2: u128 = 0xfefefefe9f9f9f9f; | 519 | var op2: u128 = 0xfefefefe9f9f9f9f; |
| 520 | // These must be runtime-known to prevent this comparison being tautological, as the | ||
| 521 | // compiler uses `std.math.big.int` internally to add these values at comptime. | ||
| 522 | _ = .{ &op1, &op2 }; | ||
| 522 | var a = try Managed.initSet(testing.allocator, op1); | 523 | var a = try Managed.initSet(testing.allocator, op1); |
| 523 | defer a.deinit(); | 524 | defer a.deinit(); |
| 524 | var b = try Managed.initSet(testing.allocator, op2); | 525 | var b = try Managed.initSet(testing.allocator, op2); |
| ... | @@ -833,6 +834,7 @@ test "big.int sub multi-single" { | ... | @@ -833,6 +834,7 @@ test "big.int sub multi-single" { |
| 833 | test "big.int sub multi-multi" { | 834 | test "big.int sub multi-multi" { |
| 834 | var op1: u128 = 0xefefefefefefefefefefefef; | 835 | var op1: u128 = 0xefefefefefefefefefefefef; |
| 835 | var op2: u128 = 0xabababababababababababab; | 836 | var op2: u128 = 0xabababababababababababab; |
| 837 | _ = .{ &op1, &op2 }; | ||
| 836 | 838 | ||
| 837 | var a = try Managed.initSet(testing.allocator, op1); | 839 | var a = try Managed.initSet(testing.allocator, op1); |
| 838 | defer a.deinit(); | 840 | defer a.deinit(); |
| ... | @@ -920,6 +922,8 @@ test "big.int mul multi-multi" { | ... | @@ -920,6 +922,8 @@ test "big.int mul multi-multi" { |
| 920 | 922 | ||
| 921 | var op1: u256 = 0x998888efefefefefefefef; | 923 | var op1: u256 = 0x998888efefefefefefefef; |
| 922 | var op2: u256 = 0x333000abababababababab; | 924 | var op2: u256 = 0x333000abababababababab; |
| 925 | _ = .{ &op1, &op2 }; | ||
| 926 | |||
| 923 | var a = try Managed.initSet(testing.allocator, op1); | 927 | var a = try Managed.initSet(testing.allocator, op1); |
| 924 | defer a.deinit(); | 928 | defer a.deinit(); |
| 925 | var b = try Managed.initSet(testing.allocator, op2); | 929 | var b = try Managed.initSet(testing.allocator, op2); |
| ... | @@ -1042,6 +1046,8 @@ test "big.int mulWrap multi-multi unsigned" { | ... | @@ -1042,6 +1046,8 @@ test "big.int mulWrap multi-multi unsigned" { |
| 1042 | 1046 | ||
| 1043 | var op1: u256 = 0x998888efefefefefefefef; | 1047 | var op1: u256 = 0x998888efefefefefefefef; |
| 1044 | var op2: u256 = 0x333000abababababababab; | 1048 | var op2: u256 = 0x333000abababababababab; |
| 1049 | _ = .{ &op1, &op2 }; | ||
| 1050 | |||
| 1045 | var a = try Managed.initSet(testing.allocator, op1); | 1051 | var a = try Managed.initSet(testing.allocator, op1); |
| 1046 | defer a.deinit(); | 1052 | defer a.deinit(); |
| 1047 | var b = try Managed.initSet(testing.allocator, op2); | 1053 | var b = try Managed.initSet(testing.allocator, op2); |
| ... | @@ -1164,6 +1170,7 @@ test "big.int div single-single with rem" { | ... | @@ -1164,6 +1170,7 @@ test "big.int div single-single with rem" { |
| 1164 | test "big.int div multi-single no rem" { | 1170 | test "big.int div multi-single no rem" { |
| 1165 | var op1: u128 = 0xffffeeeeddddcccc; | 1171 | var op1: u128 = 0xffffeeeeddddcccc; |
| 1166 | var op2: u128 = 34; | 1172 | var op2: u128 = 34; |
| 1173 | _ = .{ &op1, &op2 }; | ||
| 1167 | 1174 | ||
| 1168 | var a = try Managed.initSet(testing.allocator, op1); | 1175 | var a = try Managed.initSet(testing.allocator, op1); |
| 1169 | defer a.deinit(); | 1176 | defer a.deinit(); |
| ... | @@ -1183,6 +1190,7 @@ test "big.int div multi-single no rem" { | ... | @@ -1183,6 +1190,7 @@ test "big.int div multi-single no rem" { |
| 1183 | test "big.int div multi-single with rem" { | 1190 | test "big.int div multi-single with rem" { |
| 1184 | var op1: u128 = 0xffffeeeeddddcccf; | 1191 | var op1: u128 = 0xffffeeeeddddcccf; |
| 1185 | var op2: u128 = 34; | 1192 | var op2: u128 = 34; |
| 1193 | _ = .{ &op1, &op2 }; | ||
| 1186 | 1194 | ||
| 1187 | var a = try Managed.initSet(testing.allocator, op1); | 1195 | var a = try Managed.initSet(testing.allocator, op1); |
| 1188 | defer a.deinit(); | 1196 | defer a.deinit(); |
| ... | @@ -1202,6 +1210,7 @@ test "big.int div multi-single with rem" { | ... | @@ -1202,6 +1210,7 @@ test "big.int div multi-single with rem" { |
| 1202 | test "big.int div multi>2-single" { | 1210 | test "big.int div multi>2-single" { |
| 1203 | var op1: u128 = 0xfefefefefefefefefefefefefefefefe; | 1211 | var op1: u128 = 0xfefefefefefefefefefefefefefefefe; |
| 1204 | var op2: u128 = 0xefab8; | 1212 | var op2: u128 = 0xefab8; |
| 1213 | _ = .{ &op1, &op2 }; | ||
| 1205 | 1214 | ||
| 1206 | var a = try Managed.initSet(testing.allocator, op1); | 1215 | var a = try Managed.initSet(testing.allocator, op1); |
| 1207 | defer a.deinit(); | 1216 | defer a.deinit(); |
| ... | @@ -2106,6 +2115,8 @@ test "big.int sat shift-left signed multi positive" { | ... | @@ -2106,6 +2115,8 @@ test "big.int sat shift-left signed multi positive" { |
| 2106 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 2115 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 2107 | 2116 | ||
| 2108 | var x: SignedDoubleLimb = 1; | 2117 | var x: SignedDoubleLimb = 1; |
| 2118 | _ = &x; | ||
| 2119 | |||
| 2109 | const shift = @bitSizeOf(SignedDoubleLimb) - 1; | 2120 | const shift = @bitSizeOf(SignedDoubleLimb) - 1; |
| 2110 | 2121 | ||
| 2111 | var a = try Managed.initSet(testing.allocator, x); | 2122 | var a = try Managed.initSet(testing.allocator, x); |
| ... | @@ -2119,6 +2130,8 @@ test "big.int sat shift-left signed multi negative" { | ... | @@ -2119,6 +2130,8 @@ test "big.int sat shift-left signed multi negative" { |
| 2119 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 2130 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 2120 | 2131 | ||
| 2121 | var x: SignedDoubleLimb = -1; | 2132 | var x: SignedDoubleLimb = -1; |
| 2133 | _ = &x; | ||
| 2134 | |||
| 2122 | const shift = @bitSizeOf(SignedDoubleLimb) - 1; | 2135 | const shift = @bitSizeOf(SignedDoubleLimb) - 1; |
| 2123 | 2136 | ||
| 2124 | var a = try Managed.initSet(testing.allocator, x); | 2137 | var a = try Managed.initSet(testing.allocator, x); |
| ... | @@ -2130,6 +2143,8 @@ test "big.int sat shift-left signed multi negative" { | ... | @@ -2130,6 +2143,8 @@ test "big.int sat shift-left signed multi negative" { |
| 2130 | 2143 | ||
| 2131 | test "big.int bitNotWrap unsigned simple" { | 2144 | test "big.int bitNotWrap unsigned simple" { |
| 2132 | var x: u10 = 123; | 2145 | var x: u10 = 123; |
| 2146 | _ = &x; | ||
| 2147 | |||
| 2133 | var a = try Managed.initSet(testing.allocator, x); | 2148 | var a = try Managed.initSet(testing.allocator, x); |
| 2134 | defer a.deinit(); | 2149 | defer a.deinit(); |
| 2135 | 2150 | ||
| ... | @@ -2149,6 +2164,8 @@ test "big.int bitNotWrap unsigned multi" { | ... | @@ -2149,6 +2164,8 @@ test "big.int bitNotWrap unsigned multi" { |
| 2149 | 2164 | ||
| 2150 | test "big.int bitNotWrap signed simple" { | 2165 | test "big.int bitNotWrap signed simple" { |
| 2151 | var x: i11 = -456; | 2166 | var x: i11 = -456; |
| 2167 | _ = &x; | ||
| 2168 | |||
| 2152 | var a = try Managed.initSet(testing.allocator, -456); | 2169 | var a = try Managed.initSet(testing.allocator, -456); |
| 2153 | defer a.deinit(); | 2170 | defer a.deinit(); |
| 2154 | 2171 | ||
| ... | @@ -2306,6 +2323,8 @@ test "big.int bitwise xor simple" { | ... | @@ -2306,6 +2323,8 @@ test "big.int bitwise xor simple" { |
| 2306 | test "big.int bitwise xor multi-limb" { | 2323 | test "big.int bitwise xor multi-limb" { |
| 2307 | var x: DoubleLimb = maxInt(Limb) + 1; | 2324 | var x: DoubleLimb = maxInt(Limb) + 1; |
| 2308 | var y: DoubleLimb = maxInt(Limb); | 2325 | var y: DoubleLimb = maxInt(Limb); |
| 2326 | _ = .{ &x, &y }; | ||
| 2327 | |||
| 2309 | var a = try Managed.initSet(testing.allocator, x); | 2328 | var a = try Managed.initSet(testing.allocator, x); |
| 2310 | defer a.deinit(); | 2329 | defer a.deinit(); |
| 2311 | var b = try Managed.initSet(testing.allocator, y); | 2330 | var b = try Managed.initSet(testing.allocator, y); |
| ... | @@ -2548,7 +2567,7 @@ test "big.int gcd one large" { | ... | @@ -2548,7 +2567,7 @@ test "big.int gcd one large" { |
| 2548 | 2567 | ||
| 2549 | test "big.int mutable to managed" { | 2568 | test "big.int mutable to managed" { |
| 2550 | const allocator = testing.allocator; | 2569 | const allocator = testing.allocator; |
| 2551 | var limbs_buf = try allocator.alloc(Limb, 8); | 2570 | const limbs_buf = try allocator.alloc(Limb, 8); |
| 2552 | defer allocator.free(limbs_buf); | 2571 | defer allocator.free(limbs_buf); |
| 2553 | 2572 | ||
| 2554 | var a = Mutable.init(limbs_buf, 0xdeadbeef); | 2573 | var a = Mutable.init(limbs_buf, 0xdeadbeef); |
| ... | @@ -2965,7 +2984,7 @@ test "big int conversion write twos complement zero" { | ... | @@ -2965,7 +2984,7 @@ test "big int conversion write twos complement zero" { |
| 2965 | // (2) should correctly interpret bytes based on the provided endianness | 2984 | // (2) should correctly interpret bytes based on the provided endianness |
| 2966 | // (3) should ignore any bits from bit_count to 8 * abi_size | 2985 | // (3) should ignore any bits from bit_count to 8 * abi_size |
| 2967 | 2986 | ||
| 2968 | var bit_count: usize = 12 * 8 + 1; | 2987 | const bit_count: usize = 12 * 8 + 1; |
| 2969 | var buffer: []const u8 = undefined; | 2988 | var buffer: []const u8 = undefined; |
| 2970 | 2989 | ||
| 2971 | buffer = &([_]u8{0} ** 13); | 2990 | buffer = &([_]u8{0} ** 13); |
lib/std/math/cbrt.zig+2-2| ... | @@ -102,7 +102,7 @@ fn cbrt64(x: f64) f64 { | ... | @@ -102,7 +102,7 @@ fn cbrt64(x: f64) f64 { |
| 102 | 102 | ||
| 103 | // cbrt to 23 bits | 103 | // cbrt to 23 bits |
| 104 | // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x) | 104 | // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x) |
| 105 | var r = (t * t) * (t / x); | 105 | const r = (t * t) * (t / x); |
| 106 | t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4)); | 106 | t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4)); |
| 107 | 107 | ||
| 108 | // Round t away from 0 to 23 bits | 108 | // Round t away from 0 to 23 bits |
| ... | @@ -113,7 +113,7 @@ fn cbrt64(x: f64) f64 { | ... | @@ -113,7 +113,7 @@ fn cbrt64(x: f64) f64 { |
| 113 | // one step newton to 53 bits | 113 | // one step newton to 53 bits |
| 114 | const s = t * t; | 114 | const s = t * t; |
| 115 | var q = x / s; | 115 | var q = x / s; |
| 116 | var w = t + t; | 116 | const w = t + t; |
| 117 | q = (q - t) / (w + q); | 117 | q = (q - t) / (w + q); |
| 118 | 118 | ||
| 119 | return t + t * q; | 119 | return t + t * q; |
lib/std/math/complex/atan.zig+2-2| ... | @@ -55,7 +55,7 @@ fn atan32(z: Complex(f32)) Complex(f32) { | ... | @@ -55,7 +55,7 @@ fn atan32(z: Complex(f32)) Complex(f32) { |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | var t = 0.5 * math.atan2(f32, 2.0 * x, a); | 57 | var t = 0.5 * math.atan2(f32, 2.0 * x, a); |
| 58 | var w = redupif32(t); | 58 | const w = redupif32(t); |
| 59 | 59 | ||
| 60 | t = y - 1.0; | 60 | t = y - 1.0; |
| 61 | a = x2 + t * t; | 61 | a = x2 + t * t; |
| ... | @@ -104,7 +104,7 @@ fn atan64(z: Complex(f64)) Complex(f64) { | ... | @@ -104,7 +104,7 @@ fn atan64(z: Complex(f64)) Complex(f64) { |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | var t = 0.5 * math.atan2(f64, 2.0 * x, a); | 106 | var t = 0.5 * math.atan2(f64, 2.0 * x, a); |
| 107 | var w = redupif64(t); | 107 | const w = redupif64(t); |
| 108 | 108 | ||
| 109 | t = y - 1.0; | 109 | t = y - 1.0; |
| 110 | a = x2 + t * t; | 110 | a = x2 + t * t; |
lib/std/math/ilogb.zig+2-2| ... | @@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 { | ... | @@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 { |
| 38 | 38 | ||
| 39 | const absMask = signBit - 1; | 39 | const absMask = signBit - 1; |
| 40 | 40 | ||
| 41 | var u = @as(Z, @bitCast(x)) & absMask; | 41 | const u = @as(Z, @bitCast(x)) & absMask; |
| 42 | var e = @as(i32, @intCast(u >> significandBits)); | 42 | const e: i32 = @intCast(u >> significandBits); |
| 43 | 43 | ||
| 44 | if (e == 0) { | 44 | if (e == 0) { |
| 45 | if (u == 0) { | 45 | if (u == 0) { |
lib/std/math/log1p.zig+4-4| ... | @@ -33,8 +33,8 @@ fn log1p_32(x: f32) f32 { | ... | @@ -33,8 +33,8 @@ fn log1p_32(x: f32) f32 { |
| 33 | const Lg3: f32 = 0x91e9ee.0p-25; | 33 | const Lg3: f32 = 0x91e9ee.0p-25; |
| 34 | const Lg4: f32 = 0xf89e26.0p-26; | 34 | const Lg4: f32 = 0xf89e26.0p-26; |
| 35 | 35 | ||
| 36 | const u = @as(u32, @bitCast(x)); | 36 | const u: u32 = @bitCast(x); |
| 37 | var ix = u; | 37 | const ix = u; |
| 38 | var k: i32 = 1; | 38 | var k: i32 = 1; |
| 39 | var f: f32 = undefined; | 39 | var f: f32 = undefined; |
| 40 | var c: f32 = undefined; | 40 | var c: f32 = undefined; |
| ... | @@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 { | ... | @@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 { |
| 112 | const Lg6: f64 = 1.531383769920937332e-01; | 112 | const Lg6: f64 = 1.531383769920937332e-01; |
| 113 | const Lg7: f64 = 1.479819860511658591e-01; | 113 | const Lg7: f64 = 1.479819860511658591e-01; |
| 114 | 114 | ||
| 115 | var ix = @as(u64, @bitCast(x)); | 115 | const ix: u64 = @bitCast(x); |
| 116 | var hx = @as(u32, @intCast(ix >> 32)); | 116 | const hx: u32 = @intCast(ix >> 32); |
| 117 | var k: i32 = 1; | 117 | var k: i32 = 1; |
| 118 | var c: f64 = undefined; | 118 | var c: f64 = undefined; |
| 119 | var f: f64 = undefined; | 119 | var f: f64 = undefined; |
lib/std/math/sqrt.zig+1-1| ... | @@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) { | ... | @@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) { |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | while (one != 0) { | 52 | while (one != 0) { |
| 53 | var c = op >= res + one; | 53 | const c = op >= res + one; |
| 54 | if (c) op -= res + one; | 54 | if (c) op -= res + one; |
| 55 | res >>= 1; | 55 | res >>= 1; |
| 56 | if (c) res += one; | 56 | if (c) res += one; |
lib/std/mem.zig+13-12| ... | @@ -403,11 +403,11 @@ test "zeroes" { | ... | @@ -403,11 +403,11 @@ test "zeroes" { |
| 403 | b: u32, | 403 | b: u32, |
| 404 | }; | 404 | }; |
| 405 | 405 | ||
| 406 | var c = zeroes(C_union); | 406 | const c = zeroes(C_union); |
| 407 | try testing.expectEqual(@as(u8, 0), c.a); | 407 | try testing.expectEqual(@as(u8, 0), c.a); |
| 408 | try testing.expectEqual(@as(u32, 0), c.b); | 408 | try testing.expectEqual(@as(u32, 0), c.b); |
| 409 | 409 | ||
| 410 | comptime var comptime_union = zeroes(C_union); | 410 | const comptime_union = comptime zeroes(C_union); |
| 411 | try testing.expectEqual(@as(u8, 0), comptime_union.a); | 411 | try testing.expectEqual(@as(u8, 0), comptime_union.a); |
| 412 | try testing.expectEqual(@as(u32, 0), comptime_union.b); | 412 | try testing.expectEqual(@as(u32, 0), comptime_union.b); |
| 413 | 413 | ||
| ... | @@ -3399,7 +3399,7 @@ test "reverseIterator" { | ... | @@ -3399,7 +3399,7 @@ test "reverseIterator" { |
| 3399 | try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*); | 3399 | try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*); |
| 3400 | try testing.expectEqual(@as(?*const i32, null), it.nextPtr()); | 3400 | try testing.expectEqual(@as(?*const i32, null), it.nextPtr()); |
| 3401 | 3401 | ||
| 3402 | var mut_slice: []i32 = &array; | 3402 | const mut_slice: []i32 = &array; |
| 3403 | var mut_it = reverseIterator(mut_slice); | 3403 | var mut_it = reverseIterator(mut_slice); |
| 3404 | mut_it.nextPtr().?.* += 1; | 3404 | mut_it.nextPtr().?.* += 1; |
| 3405 | mut_it.nextPtr().?.* += 2; | 3405 | mut_it.nextPtr().?.* += 2; |
| ... | @@ -3419,7 +3419,7 @@ test "reverseIterator" { | ... | @@ -3419,7 +3419,7 @@ test "reverseIterator" { |
| 3419 | try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*); | 3419 | try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*); |
| 3420 | try testing.expectEqual(@as(?*const i32, null), it.nextPtr()); | 3420 | try testing.expectEqual(@as(?*const i32, null), it.nextPtr()); |
| 3421 | 3421 | ||
| 3422 | var mut_ptr_to_array: *[2]i32 = &array; | 3422 | const mut_ptr_to_array: *[2]i32 = &array; |
| 3423 | var mut_it = reverseIterator(mut_ptr_to_array); | 3423 | var mut_it = reverseIterator(mut_ptr_to_array); |
| 3424 | mut_it.nextPtr().?.* += 1; | 3424 | mut_it.nextPtr().?.* += 1; |
| 3425 | mut_it.nextPtr().?.* += 2; | 3425 | mut_it.nextPtr().?.* += 2; |
| ... | @@ -3581,7 +3581,7 @@ test "replacementSize" { | ... | @@ -3581,7 +3581,7 @@ test "replacementSize" { |
| 3581 | 3581 | ||
| 3582 | /// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory. | 3582 | /// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory. |
| 3583 | pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T { | 3583 | pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T { |
| 3584 | var output = try allocator.alloc(T, replacementSize(T, input, needle, replacement)); | 3584 | const output = try allocator.alloc(T, replacementSize(T, input, needle, replacement)); |
| 3585 | _ = replace(T, input, needle, replacement, output); | 3585 | _ = replace(T, input, needle, replacement, output); |
| 3586 | return output; | 3586 | return output; |
| 3587 | } | 3587 | } |
| ... | @@ -3693,8 +3693,8 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) { | ... | @@ -3693,8 +3693,8 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) { |
| 3693 | test "alignPointer" { | 3693 | test "alignPointer" { |
| 3694 | const S = struct { | 3694 | const S = struct { |
| 3695 | fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void { | 3695 | fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void { |
| 3696 | var ptr = @as(T, @ptrFromInt(base)); | 3696 | const ptr: T = @ptrFromInt(base); |
| 3697 | var aligned = alignPointer(ptr, align_to); | 3697 | const aligned = alignPointer(ptr, align_to); |
| 3698 | try testing.expectEqual(expected, @intFromPtr(aligned)); | 3698 | try testing.expectEqual(expected, @intFromPtr(aligned)); |
| 3699 | } | 3699 | } |
| 3700 | }; | 3700 | }; |
| ... | @@ -3848,7 +3848,7 @@ test "bytesAsValue" { | ... | @@ -3848,7 +3848,7 @@ test "bytesAsValue" { |
| 3848 | .big => "\xC0\xDE\xFA\xCE", | 3848 | .big => "\xC0\xDE\xFA\xCE", |
| 3849 | .little => "\xCE\xFA\xDE\xC0", | 3849 | .little => "\xCE\xFA\xDE\xC0", |
| 3850 | }.*; | 3850 | }.*; |
| 3851 | var codeface = bytesAsValue(u32, &codeface_bytes); | 3851 | const codeface = bytesAsValue(u32, &codeface_bytes); |
| 3852 | try testing.expect(codeface.* == 0xC0DEFACE); | 3852 | try testing.expect(codeface.* == 0xC0DEFACE); |
| 3853 | codeface.* = 0; | 3853 | codeface.* = 0; |
| 3854 | for (codeface_bytes) |b| | 3854 | for (codeface_bytes) |b| |
| ... | @@ -3941,6 +3941,7 @@ test "bytesAsSlice" { | ... | @@ -3941,6 +3941,7 @@ test "bytesAsSlice" { |
| 3941 | { | 3941 | { |
| 3942 | const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF }; | 3942 | const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF }; |
| 3943 | var runtime_zero: usize = 0; | 3943 | var runtime_zero: usize = 0; |
| 3944 | _ = &runtime_zero; | ||
| 3944 | const slice = bytesAsSlice(u16, bytes[runtime_zero..]); | 3945 | const slice = bytesAsSlice(u16, bytes[runtime_zero..]); |
| 3945 | try testing.expect(slice.len == 2); | 3946 | try testing.expect(slice.len == 2); |
| 3946 | try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD); | 3947 | try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD); |
| ... | @@ -3957,6 +3958,7 @@ test "bytesAsSlice keeps pointer alignment" { | ... | @@ -3957,6 +3958,7 @@ test "bytesAsSlice keeps pointer alignment" { |
| 3957 | { | 3958 | { |
| 3958 | var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; | 3959 | var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; |
| 3959 | var runtime_zero: usize = 0; | 3960 | var runtime_zero: usize = 0; |
| 3961 | _ = &runtime_zero; | ||
| 3960 | const numbers = bytesAsSlice(u32, bytes[runtime_zero..]); | 3962 | const numbers = bytesAsSlice(u32, bytes[runtime_zero..]); |
| 3961 | try comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); | 3963 | try comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); |
| 3962 | } | 3964 | } |
| ... | @@ -3967,8 +3969,8 @@ test "bytesAsSlice on a packed struct" { | ... | @@ -3967,8 +3969,8 @@ test "bytesAsSlice on a packed struct" { |
| 3967 | a: u8, | 3969 | a: u8, |
| 3968 | }; | 3970 | }; |
| 3969 | 3971 | ||
| 3970 | var b = [1]u8{9}; | 3972 | const b: [1]u8 = .{9}; |
| 3971 | var f = bytesAsSlice(F, &b); | 3973 | const f = bytesAsSlice(F, &b); |
| 3972 | try testing.expect(f[0].a == 9); | 3974 | try testing.expect(f[0].a == 9); |
| 3973 | } | 3975 | } |
| 3974 | 3976 | ||
| ... | @@ -4120,8 +4122,7 @@ pub const alignForwardGeneric = @compileError("renamed to alignForward"); | ... | @@ -4120,8 +4122,7 @@ pub const alignForwardGeneric = @compileError("renamed to alignForward"); |
| 4120 | /// result eventually gets discarded. | 4122 | /// result eventually gets discarded. |
| 4121 | // TODO: use @declareSideEffect() when it is available - https://github.com/ziglang/zig/issues/6168 | 4123 | // TODO: use @declareSideEffect() when it is available - https://github.com/ziglang/zig/issues/6168 |
| 4122 | pub fn doNotOptimizeAway(val: anytype) void { | 4124 | pub fn doNotOptimizeAway(val: anytype) void { |
| 4123 | var a: u8 = 0; | 4125 | if (@inComptime()) return; |
| 4124 | if (@typeInfo(@TypeOf(.{a})).Struct.fields[0].is_comptime) return; | ||
| 4125 | 4126 | ||
| 4126 | const max_gp_register_bits = @bitSizeOf(c_long); | 4127 | const max_gp_register_bits = @bitSizeOf(c_long); |
| 4127 | const t = @typeInfo(@TypeOf(val)); | 4128 | const t = @typeInfo(@TypeOf(val)); |
lib/std/meta.zig+9-8| ... | @@ -738,7 +738,7 @@ test "std.meta.TagPayload" { | ... | @@ -738,7 +738,7 @@ test "std.meta.TagPayload" { |
| 738 | }, | 738 | }, |
| 739 | }; | 739 | }; |
| 740 | const MovedEvent = TagPayload(Event, Event.Moved); | 740 | const MovedEvent = TagPayload(Event, Event.Moved); |
| 741 | var e: Event = undefined; | 741 | const e: Event = .{ .Moved = undefined }; |
| 742 | try testing.expect(MovedEvent == @TypeOf(e.Moved)); | 742 | try testing.expect(MovedEvent == @TypeOf(e.Moved)); |
| 743 | } | 743 | } |
| 744 | 744 | ||
| ... | @@ -839,13 +839,12 @@ test "std.meta.eql" { | ... | @@ -839,13 +839,12 @@ test "std.meta.eql" { |
| 839 | try testing.expect(eql(u_1, u_3)); | 839 | try testing.expect(eql(u_1, u_3)); |
| 840 | try testing.expect(!eql(u_1, u_2)); | 840 | try testing.expect(!eql(u_1, u_2)); |
| 841 | 841 | ||
| 842 | var a1 = "abcdef".*; | 842 | const a1 = "abcdef".*; |
| 843 | var a2 = "abcdef".*; | 843 | const a2 = "abcdef".*; |
| 844 | var a3 = "ghijkl".*; | 844 | const a3 = "ghijkl".*; |
| 845 | 845 | ||
| 846 | try testing.expect(eql(a1, a2)); | 846 | try testing.expect(eql(a1, a2)); |
| 847 | try testing.expect(!eql(a1, a3)); | 847 | try testing.expect(!eql(a1, a3)); |
| 848 | try testing.expect(!eql(a1[0..], a2[0..])); | ||
| 849 | 848 | ||
| 850 | const EU = struct { | 849 | const EU = struct { |
| 851 | fn tst(err: bool) !u8 { | 850 | fn tst(err: bool) !u8 { |
| ... | @@ -859,9 +858,9 @@ test "std.meta.eql" { | ... | @@ -859,9 +858,9 @@ test "std.meta.eql" { |
| 859 | try testing.expect(!eql(EU.tst(false), EU.tst(true))); | 858 | try testing.expect(!eql(EU.tst(false), EU.tst(true))); |
| 860 | 859 | ||
| 861 | const V = @Vector(4, u32); | 860 | const V = @Vector(4, u32); |
| 862 | var v1: V = @splat(1); | 861 | const v1: V = @splat(1); |
| 863 | var v2: V = @splat(1); | 862 | const v2: V = @splat(1); |
| 864 | var v3: V = @splat(2); | 863 | const v3: V = @splat(2); |
| 865 | 864 | ||
| 866 | try testing.expect(eql(v1, v2)); | 865 | try testing.expect(eql(v1, v2)); |
| 867 | try testing.expect(!eql(v1, v3)); | 866 | try testing.expect(!eql(v1, v3)); |
| ... | @@ -879,6 +878,8 @@ test "intToEnum with error return" { | ... | @@ -879,6 +878,8 @@ test "intToEnum with error return" { |
| 879 | 878 | ||
| 880 | var zero: u8 = 0; | 879 | var zero: u8 = 0; |
| 881 | var one: u16 = 1; | 880 | var one: u16 = 1; |
| 881 | _ = &zero; | ||
| 882 | _ = &one; | ||
| 882 | try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A); | 883 | try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A); |
| 883 | try testing.expect(intToEnum(E2, one) catch unreachable == E2.B); | 884 | try testing.expect(intToEnum(E2, one) catch unreachable == E2.B); |
| 884 | try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A); | 885 | try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A); |
lib/std/meta/trait.zig+5-2| ... | @@ -225,6 +225,7 @@ test "isSingleItemPtr" { | ... | @@ -225,6 +225,7 @@ test "isSingleItemPtr" { |
| 225 | try comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); | 225 | try comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); |
| 226 | try comptime testing.expect(!isSingleItemPtr(@TypeOf(array))); | 226 | try comptime testing.expect(!isSingleItemPtr(@TypeOf(array))); |
| 227 | var runtime_zero: usize = 0; | 227 | var runtime_zero: usize = 0; |
| 228 | _ = &runtime_zero; | ||
| 228 | try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1]))); | 229 | try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1]))); |
| 229 | } | 230 | } |
| 230 | 231 | ||
| ... | @@ -253,6 +254,7 @@ pub fn isSlice(comptime T: type) bool { | ... | @@ -253,6 +254,7 @@ pub fn isSlice(comptime T: type) bool { |
| 253 | test "isSlice" { | 254 | test "isSlice" { |
| 254 | const array = [_]u8{0} ** 10; | 255 | const array = [_]u8{0} ** 10; |
| 255 | var runtime_zero: usize = 0; | 256 | var runtime_zero: usize = 0; |
| 257 | _ = &runtime_zero; | ||
| 256 | try testing.expect(isSlice(@TypeOf(array[runtime_zero..]))); | 258 | try testing.expect(isSlice(@TypeOf(array[runtime_zero..]))); |
| 257 | try testing.expect(!isSlice(@TypeOf(array))); | 259 | try testing.expect(!isSlice(@TypeOf(array))); |
| 258 | try testing.expect(!isSlice(@TypeOf(&array[0]))); | 260 | try testing.expect(!isSlice(@TypeOf(&array[0]))); |
| ... | @@ -341,8 +343,9 @@ pub fn isConstPtr(comptime T: type) bool { | ... | @@ -341,8 +343,9 @@ pub fn isConstPtr(comptime T: type) bool { |
| 341 | } | 343 | } |
| 342 | 344 | ||
| 343 | test "isConstPtr" { | 345 | test "isConstPtr" { |
| 344 | var t = @as(u8, 0); | 346 | var t: u8 = 0; |
| 345 | const c = @as(u8, 0); | 347 | t = t; |
| 348 | const c: u8 = 0; | ||
| 346 | try testing.expect(isConstPtr(*const @TypeOf(t))); | 349 | try testing.expect(isConstPtr(*const @TypeOf(t))); |
| 347 | try testing.expect(isConstPtr(@TypeOf(&c))); | 350 | try testing.expect(isConstPtr(@TypeOf(&c))); |
| 348 | try testing.expect(!isConstPtr(*@TypeOf(t))); | 351 | try testing.expect(!isConstPtr(*@TypeOf(t))); |
lib/std/net.zig+4-4| ... | @@ -662,7 +662,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream { | ... | @@ -662,7 +662,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream { |
| 662 | fn if_nametoindex(name: []const u8) !u32 { | 662 | fn if_nametoindex(name: []const u8) !u32 { |
| 663 | if (builtin.target.os.tag == .linux) { | 663 | if (builtin.target.os.tag == .linux) { |
| 664 | var ifr: os.ifreq = undefined; | 664 | var ifr: os.ifreq = undefined; |
| 665 | var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0); | 665 | const sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0); |
| 666 | defer os.closeSocket(sockfd); | 666 | defer os.closeSocket(sockfd); |
| 667 | 667 | ||
| 668 | @memcpy(ifr.ifrn.name[0..name.len], name); | 668 | @memcpy(ifr.ifrn.name[0..name.len], name); |
| ... | @@ -1375,7 +1375,7 @@ fn linuxLookupNameFromDns( | ... | @@ -1375,7 +1375,7 @@ fn linuxLookupNameFromDns( |
| 1375 | rc: ResolvConf, | 1375 | rc: ResolvConf, |
| 1376 | port: u16, | 1376 | port: u16, |
| 1377 | ) !void { | 1377 | ) !void { |
| 1378 | var ctx = dpc_ctx{ | 1378 | const ctx = dpc_ctx{ |
| 1379 | .addrs = addrs, | 1379 | .addrs = addrs, |
| 1380 | .canon = canon, | 1380 | .canon = canon, |
| 1381 | .port = port, | 1381 | .port = port, |
| ... | @@ -1591,8 +1591,8 @@ fn resMSendRc( | ... | @@ -1591,8 +1591,8 @@ fn resMSendRc( |
| 1591 | }}; | 1591 | }}; |
| 1592 | const retry_interval = timeout / attempts; | 1592 | const retry_interval = timeout / attempts; |
| 1593 | var next: u32 = 0; | 1593 | var next: u32 = 0; |
| 1594 | var t2: u64 = @as(u64, @bitCast(std.time.milliTimestamp())); | 1594 | var t2: u64 = @bitCast(std.time.milliTimestamp()); |
| 1595 | var t0 = t2; | 1595 | const t0 = t2; |
| 1596 | var t1 = t2 - retry_interval; | 1596 | var t1 = t2 - retry_interval; |
| 1597 | 1597 | ||
| 1598 | var servfail_retry: usize = undefined; | 1598 | var servfail_retry: usize = undefined; |
lib/std/net/test.zig+5-5| ... | @@ -33,12 +33,12 @@ test "parse and render IPv6 addresses" { | ... | @@ -33,12 +33,12 @@ test "parse and render IPv6 addresses" { |
| 33 | "::ffff:123.5.123.5", | 33 | "::ffff:123.5.123.5", |
| 34 | }; | 34 | }; |
| 35 | for (ips, 0..) |ip, i| { | 35 | for (ips, 0..) |ip, i| { |
| 36 | var addr = net.Address.parseIp6(ip, 0) catch unreachable; | 36 | const addr = net.Address.parseIp6(ip, 0) catch unreachable; |
| 37 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; | 37 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; |
| 38 | try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); | 38 | try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); |
| 39 | 39 | ||
| 40 | if (builtin.os.tag == .linux) { | 40 | if (builtin.os.tag == .linux) { |
| 41 | var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable; | 41 | const addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable; |
| 42 | var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable; | 42 | var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable; |
| 43 | try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3])); | 43 | try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3])); |
| 44 | } | 44 | } |
| ... | @@ -80,7 +80,7 @@ test "parse and render IPv4 addresses" { | ... | @@ -80,7 +80,7 @@ test "parse and render IPv4 addresses" { |
| 80 | "123.255.0.91", | 80 | "123.255.0.91", |
| 81 | "127.0.0.1", | 81 | "127.0.0.1", |
| 82 | }) |ip| { | 82 | }) |ip| { |
| 83 | var addr = net.Address.parseIp4(ip, 0) catch unreachable; | 83 | const addr = net.Address.parseIp4(ip, 0) catch unreachable; |
| 84 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; | 84 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; |
| 85 | try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2])); | 85 | try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2])); |
| 86 | } | 86 | } |
| ... | @@ -303,10 +303,10 @@ test "listen on a unix socket, send bytes, receive bytes" { | ... | @@ -303,10 +303,10 @@ test "listen on a unix socket, send bytes, receive bytes" { |
| 303 | var server = net.StreamServer.init(.{}); | 303 | var server = net.StreamServer.init(.{}); |
| 304 | defer server.deinit(); | 304 | defer server.deinit(); |
| 305 | 305 | ||
| 306 | var socket_path = try generateFileName("socket.unix"); | 306 | const socket_path = try generateFileName("socket.unix"); |
| 307 | defer testing.allocator.free(socket_path); | 307 | defer testing.allocator.free(socket_path); |
| 308 | 308 | ||
| 309 | var socket_addr = try net.Address.initUnix(socket_path); | 309 | const socket_addr = try net.Address.initUnix(socket_path); |
| 310 | defer std.fs.cwd().deleteFile(socket_path) catch {}; | 310 | defer std.fs.cwd().deleteFile(socket_path) catch {}; |
| 311 | try server.listen(socket_addr); | 311 | try server.listen(socket_addr); |
| 312 | 312 |
lib/std/os.zig+6-6| ... | @@ -4642,7 +4642,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr | ... | @@ -4642,7 +4642,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr |
| 4642 | const path_w = try windows.sliceToPrefixedFileW(dirfd, path); | 4642 | const path_w = try windows.sliceToPrefixedFileW(dirfd, path); |
| 4643 | return faccessatW(dirfd, path_w.span().ptr, mode, flags); | 4643 | return faccessatW(dirfd, path_w.span().ptr, mode, flags); |
| 4644 | } else if (builtin.os.tag == .wasi and !builtin.link_libc) { | 4644 | } else if (builtin.os.tag == .wasi and !builtin.link_libc) { |
| 4645 | var resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path }; | 4645 | const resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path }; |
| 4646 | 4646 | ||
| 4647 | const file = blk: { | 4647 | const file = blk: { |
| 4648 | break :blk fstatat(dirfd, path, flags); | 4648 | break :blk fstatat(dirfd, path, flags); |
| ... | @@ -4775,7 +4775,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { | ... | @@ -4775,7 +4775,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { |
| 4775 | } | 4775 | } |
| 4776 | } | 4776 | } |
| 4777 | 4777 | ||
| 4778 | var fds: [2]fd_t = try pipe(); | 4778 | const fds: [2]fd_t = try pipe(); |
| 4779 | errdefer { | 4779 | errdefer { |
| 4780 | close(fds[0]); | 4780 | close(fds[0]); |
| 4781 | close(fds[1]); | 4781 | close(fds[1]); |
| ... | @@ -6709,7 +6709,7 @@ pub fn dn_expand( | ... | @@ -6709,7 +6709,7 @@ pub fn dn_expand( |
| 6709 | // loop invariants: p<end, dest<dend | 6709 | // loop invariants: p<end, dest<dend |
| 6710 | if ((p[0] & 0xc0) != 0) { | 6710 | if ((p[0] & 0xc0) != 0) { |
| 6711 | if (p + 1 == end) return error.InvalidDnsPacket; | 6711 | if (p + 1 == end) return error.InvalidDnsPacket; |
| 6712 | var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1]; | 6712 | const j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1]; |
| 6713 | if (len == std.math.maxInt(usize)) len = @intFromPtr(p) + 2 - @intFromPtr(comp_dn.ptr); | 6713 | if (len == std.math.maxInt(usize)) len = @intFromPtr(p) + 2 - @intFromPtr(comp_dn.ptr); |
| 6714 | if (j >= msg.len) return error.InvalidDnsPacket; | 6714 | if (j >= msg.len) return error.InvalidDnsPacket; |
| 6715 | p = msg.ptr + j; | 6715 | p = msg.ptr + j; |
| ... | @@ -7285,7 +7285,7 @@ pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError; | ... | @@ -7285,7 +7285,7 @@ pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError; |
| 7285 | pub const TimerFdSetError = TimerFdGetError || error{Canceled}; | 7285 | pub const TimerFdSetError = TimerFdGetError || error{Canceled}; |
| 7286 | 7286 | ||
| 7287 | pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t { | 7287 | pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t { |
| 7288 | var rc = linux.timerfd_create(clokid, flags); | 7288 | const rc = linux.timerfd_create(clokid, flags); |
| 7289 | return switch (errno(rc)) { | 7289 | return switch (errno(rc)) { |
| 7290 | .SUCCESS => @as(fd_t, @intCast(rc)), | 7290 | .SUCCESS => @as(fd_t, @intCast(rc)), |
| 7291 | .INVAL => unreachable, | 7291 | .INVAL => unreachable, |
| ... | @@ -7299,7 +7299,7 @@ pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t { | ... | @@ -7299,7 +7299,7 @@ pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t { |
| 7299 | } | 7299 | } |
| 7300 | 7300 | ||
| 7301 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, old_value: ?*linux.itimerspec) TimerFdSetError!void { | 7301 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, old_value: ?*linux.itimerspec) TimerFdSetError!void { |
| 7302 | var rc = linux.timerfd_settime(fd, flags, new_value, old_value); | 7302 | const rc = linux.timerfd_settime(fd, flags, new_value, old_value); |
| 7303 | return switch (errno(rc)) { | 7303 | return switch (errno(rc)) { |
| 7304 | .SUCCESS => {}, | 7304 | .SUCCESS => {}, |
| 7305 | .BADF => error.InvalidHandle, | 7305 | .BADF => error.InvalidHandle, |
| ... | @@ -7312,7 +7312,7 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, | ... | @@ -7312,7 +7312,7 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, |
| 7312 | 7312 | ||
| 7313 | pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec { | 7313 | pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec { |
| 7314 | var curr_value: linux.itimerspec = undefined; | 7314 | var curr_value: linux.itimerspec = undefined; |
| 7315 | var rc = linux.timerfd_gettime(fd, &curr_value); | 7315 | const rc = linux.timerfd_gettime(fd, &curr_value); |
| 7316 | return switch (errno(rc)) { | 7316 | return switch (errno(rc)) { |
| 7317 | .SUCCESS => return curr_value, | 7317 | .SUCCESS => return curr_value, |
| 7318 | .BADF => error.InvalidHandle, | 7318 | .BADF => error.InvalidHandle, |
lib/std/os/linux.zig+1| ... | @@ -1326,6 +1326,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize | ... | @@ -1326,6 +1326,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize |
| 1326 | next_unsent = i + 1; | 1326 | next_unsent = i + 1; |
| 1327 | break; | 1327 | break; |
| 1328 | } | 1328 | } |
| 1329 | size += iov.iov_len; | ||
| 1329 | } | 1330 | } |
| 1330 | } | 1331 | } |
| 1331 | if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR) | 1332 | if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR) |
lib/std/os/linux/io_uring.zig+20-19| ... | @@ -137,7 +137,7 @@ pub const IO_Uring = struct { | ... | @@ -137,7 +137,7 @@ pub const IO_Uring = struct { |
| 137 | // We must therefore use wrapping addition and subtraction to avoid a runtime crash. | 137 | // We must therefore use wrapping addition and subtraction to avoid a runtime crash. |
| 138 | const next = self.sq.sqe_tail +% 1; | 138 | const next = self.sq.sqe_tail +% 1; |
| 139 | if (next -% head > self.sq.sqes.len) return error.SubmissionQueueFull; | 139 | if (next -% head > self.sq.sqes.len) return error.SubmissionQueueFull; |
| 140 | var sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask]; | 140 | const sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask]; |
| 141 | self.sq.sqe_tail = next; | 141 | self.sq.sqe_tail = next; |
| 142 | return sqe; | 142 | return sqe; |
| 143 | } | 143 | } |
| ... | @@ -279,7 +279,7 @@ pub const IO_Uring = struct { | ... | @@ -279,7 +279,7 @@ pub const IO_Uring = struct { |
| 279 | const ready = self.cq_ready(); | 279 | const ready = self.cq_ready(); |
| 280 | const count = @min(cqes.len, ready); | 280 | const count = @min(cqes.len, ready); |
| 281 | var head = self.cq.head.*; | 281 | var head = self.cq.head.*; |
| 282 | var tail = head +% count; | 282 | const tail = head +% count; |
| 283 | // TODO Optimize this by using 1 or 2 memcpy's (if the tail wraps) rather than a loop. | 283 | // TODO Optimize this by using 1 or 2 memcpy's (if the tail wraps) rather than a loop. |
| 284 | var i: usize = 0; | 284 | var i: usize = 0; |
| 285 | // Do not use "less-than" operator since head and tail may wrap: | 285 | // Do not use "less-than" operator since head and tail may wrap: |
| ... | @@ -1916,7 +1916,7 @@ test "splice/read" { | ... | @@ -1916,7 +1916,7 @@ test "splice/read" { |
| 1916 | var buffer_read = [_]u8{98} ** 20; | 1916 | var buffer_read = [_]u8{98} ** 20; |
| 1917 | _ = try file_src.write(&buffer_write); | 1917 | _ = try file_src.write(&buffer_write); |
| 1918 | 1918 | ||
| 1919 | var fds = try os.pipe(); | 1919 | const fds = try os.pipe(); |
| 1920 | const pipe_offset: u64 = std.math.maxInt(u64); | 1920 | const pipe_offset: u64 = std.math.maxInt(u64); |
| 1921 | 1921 | ||
| 1922 | const sqe_splice_to_pipe = try ring.splice(0x11111111, fd_src, 0, fds[1], pipe_offset, buffer_write.len); | 1922 | const sqe_splice_to_pipe = try ring.splice(0x11111111, fd_src, 0, fds[1], pipe_offset, buffer_write.len); |
| ... | @@ -2045,6 +2045,7 @@ test "openat" { | ... | @@ -2045,6 +2045,7 @@ test "openat" { |
| 2045 | // Workaround for LLVM bug: https://github.com/ziglang/zig/issues/12014 | 2045 | // Workaround for LLVM bug: https://github.com/ziglang/zig/issues/12014 |
| 2046 | const path_addr = if (builtin.zig_backend == .stage2_llvm) p: { | 2046 | const path_addr = if (builtin.zig_backend == .stage2_llvm) p: { |
| 2047 | var workaround = path; | 2047 | var workaround = path; |
| 2048 | _ = &workaround; | ||
| 2048 | break :p @intFromPtr(workaround); | 2049 | break :p @intFromPtr(workaround); |
| 2049 | } else @intFromPtr(path); | 2050 | } else @intFromPtr(path); |
| 2050 | 2051 | ||
| ... | @@ -2199,7 +2200,7 @@ test "sendmsg/recvmsg" { | ... | @@ -2199,7 +2200,7 @@ test "sendmsg/recvmsg" { |
| 2199 | var iovecs_recv = [_]os.iovec{ | 2200 | var iovecs_recv = [_]os.iovec{ |
| 2200 | os.iovec{ .iov_base = &buffer_recv, .iov_len = buffer_recv.len }, | 2201 | os.iovec{ .iov_base = &buffer_recv, .iov_len = buffer_recv.len }, |
| 2201 | }; | 2202 | }; |
| 2202 | var addr = [_]u8{0} ** 4; | 2203 | const addr = [_]u8{0} ** 4; |
| 2203 | var address_recv = net.Address.initIp4(addr, 0); | 2204 | var address_recv = net.Address.initIp4(addr, 0); |
| 2204 | var msg_recv: os.msghdr = os.msghdr{ | 2205 | var msg_recv: os.msghdr = os.msghdr{ |
| 2205 | .name = &address_recv.any, | 2206 | .name = &address_recv.any, |
| ... | @@ -2676,7 +2677,7 @@ test "shutdown" { | ... | @@ -2676,7 +2677,7 @@ test "shutdown" { |
| 2676 | var slen: os.socklen_t = address.getOsSockLen(); | 2677 | var slen: os.socklen_t = address.getOsSockLen(); |
| 2677 | try os.getsockname(server, &address.any, &slen); | 2678 | try os.getsockname(server, &address.any, &slen); |
| 2678 | 2679 | ||
| 2679 | var shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD); | 2680 | const shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD); |
| 2680 | try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode); | 2681 | try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode); |
| 2681 | try testing.expectEqual(@as(i32, server), shutdown_sqe.fd); | 2682 | try testing.expectEqual(@as(i32, server), shutdown_sqe.fd); |
| 2682 | 2683 | ||
| ... | @@ -2702,7 +2703,7 @@ test "shutdown" { | ... | @@ -2702,7 +2703,7 @@ test "shutdown" { |
| 2702 | const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); | 2703 | const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); |
| 2703 | defer os.close(server); | 2704 | defer os.close(server); |
| 2704 | 2705 | ||
| 2705 | var shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) { | 2706 | const shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) { |
| 2706 | else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), | 2707 | else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), |
| 2707 | }; | 2708 | }; |
| 2708 | try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode); | 2709 | try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode); |
| ... | @@ -2740,7 +2741,7 @@ test "renameat" { | ... | @@ -2740,7 +2741,7 @@ test "renameat" { |
| 2740 | 2741 | ||
| 2741 | // Submit renameat | 2742 | // Submit renameat |
| 2742 | 2743 | ||
| 2743 | var sqe = try ring.renameat( | 2744 | const sqe = try ring.renameat( |
| 2744 | 0x12121212, | 2745 | 0x12121212, |
| 2745 | tmp.dir.fd, | 2746 | tmp.dir.fd, |
| 2746 | old_path, | 2747 | old_path, |
| ... | @@ -2807,7 +2808,7 @@ test "unlinkat" { | ... | @@ -2807,7 +2808,7 @@ test "unlinkat" { |
| 2807 | 2808 | ||
| 2808 | // Submit unlinkat | 2809 | // Submit unlinkat |
| 2809 | 2810 | ||
| 2810 | var sqe = try ring.unlinkat( | 2811 | const sqe = try ring.unlinkat( |
| 2811 | 0x12121212, | 2812 | 0x12121212, |
| 2812 | tmp.dir.fd, | 2813 | tmp.dir.fd, |
| 2813 | path, | 2814 | path, |
| ... | @@ -2854,7 +2855,7 @@ test "mkdirat" { | ... | @@ -2854,7 +2855,7 @@ test "mkdirat" { |
| 2854 | 2855 | ||
| 2855 | // Submit mkdirat | 2856 | // Submit mkdirat |
| 2856 | 2857 | ||
| 2857 | var sqe = try ring.mkdirat( | 2858 | const sqe = try ring.mkdirat( |
| 2858 | 0x12121212, | 2859 | 0x12121212, |
| 2859 | tmp.dir.fd, | 2860 | tmp.dir.fd, |
| 2860 | path, | 2861 | path, |
| ... | @@ -2902,7 +2903,7 @@ test "symlinkat" { | ... | @@ -2902,7 +2903,7 @@ test "symlinkat" { |
| 2902 | 2903 | ||
| 2903 | // Submit symlinkat | 2904 | // Submit symlinkat |
| 2904 | 2905 | ||
| 2905 | var sqe = try ring.symlinkat( | 2906 | const sqe = try ring.symlinkat( |
| 2906 | 0x12121212, | 2907 | 0x12121212, |
| 2907 | path, | 2908 | path, |
| 2908 | tmp.dir.fd, | 2909 | tmp.dir.fd, |
| ... | @@ -2953,7 +2954,7 @@ test "linkat" { | ... | @@ -2953,7 +2954,7 @@ test "linkat" { |
| 2953 | 2954 | ||
| 2954 | // Submit linkat | 2955 | // Submit linkat |
| 2955 | 2956 | ||
| 2956 | var sqe = try ring.linkat( | 2957 | const sqe = try ring.linkat( |
| 2957 | 0x12121212, | 2958 | 0x12121212, |
| 2958 | tmp.dir.fd, | 2959 | tmp.dir.fd, |
| 2959 | first_path, | 2960 | first_path, |
| ... | @@ -3032,7 +3033,7 @@ test "provide_buffers: read" { | ... | @@ -3032,7 +3033,7 @@ test "provide_buffers: read" { |
| 3032 | 3033 | ||
| 3033 | var i: usize = 0; | 3034 | var i: usize = 0; |
| 3034 | while (i < buffers.len) : (i += 1) { | 3035 | while (i < buffers.len) : (i += 1) { |
| 3035 | var sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); | 3036 | const sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); |
| 3036 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); | 3037 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); |
| 3037 | try testing.expectEqual(@as(i32, fd), sqe.fd); | 3038 | try testing.expectEqual(@as(i32, fd), sqe.fd); |
| 3038 | try testing.expectEqual(@as(u64, 0), sqe.addr); | 3039 | try testing.expectEqual(@as(u64, 0), sqe.addr); |
| ... | @@ -3058,7 +3059,7 @@ test "provide_buffers: read" { | ... | @@ -3058,7 +3059,7 @@ test "provide_buffers: read" { |
| 3058 | // This read should fail | 3059 | // This read should fail |
| 3059 | 3060 | ||
| 3060 | { | 3061 | { |
| 3061 | var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); | 3062 | const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); |
| 3062 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); | 3063 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); |
| 3063 | try testing.expectEqual(@as(i32, fd), sqe.fd); | 3064 | try testing.expectEqual(@as(i32, fd), sqe.fd); |
| 3064 | try testing.expectEqual(@as(u64, 0), sqe.addr); | 3065 | try testing.expectEqual(@as(u64, 0), sqe.addr); |
| ... | @@ -3097,7 +3098,7 @@ test "provide_buffers: read" { | ... | @@ -3097,7 +3098,7 @@ test "provide_buffers: read" { |
| 3097 | // Final read which should work | 3098 | // Final read which should work |
| 3098 | 3099 | ||
| 3099 | { | 3100 | { |
| 3100 | var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); | 3101 | const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); |
| 3101 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); | 3102 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); |
| 3102 | try testing.expectEqual(@as(i32, fd), sqe.fd); | 3103 | try testing.expectEqual(@as(i32, fd), sqe.fd); |
| 3103 | try testing.expectEqual(@as(u64, 0), sqe.addr); | 3104 | try testing.expectEqual(@as(u64, 0), sqe.addr); |
| ... | @@ -3158,7 +3159,7 @@ test "remove_buffers" { | ... | @@ -3158,7 +3159,7 @@ test "remove_buffers" { |
| 3158 | // Remove 3 buffers | 3159 | // Remove 3 buffers |
| 3159 | 3160 | ||
| 3160 | { | 3161 | { |
| 3161 | var sqe = try ring.remove_buffers(0xbababababa, 3, group_id); | 3162 | const sqe = try ring.remove_buffers(0xbababababa, 3, group_id); |
| 3162 | try testing.expectEqual(linux.IORING_OP.REMOVE_BUFFERS, sqe.opcode); | 3163 | try testing.expectEqual(linux.IORING_OP.REMOVE_BUFFERS, sqe.opcode); |
| 3163 | try testing.expectEqual(@as(i32, 3), sqe.fd); | 3164 | try testing.expectEqual(@as(i32, 3), sqe.fd); |
| 3164 | try testing.expectEqual(@as(u64, 0), sqe.addr); | 3165 | try testing.expectEqual(@as(u64, 0), sqe.addr); |
| ... | @@ -3270,7 +3271,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -3270,7 +3271,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 3270 | 3271 | ||
| 3271 | var i: usize = 0; | 3272 | var i: usize = 0; |
| 3272 | while (i < buffers.len) : (i += 1) { | 3273 | while (i < buffers.len) : (i += 1) { |
| 3273 | var sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); | 3274 | const sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); |
| 3274 | try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); | 3275 | try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); |
| 3275 | try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); | 3276 | try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); |
| 3276 | try testing.expectEqual(@as(u64, 0), sqe.addr); | 3277 | try testing.expectEqual(@as(u64, 0), sqe.addr); |
| ... | @@ -3299,7 +3300,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -3299,7 +3300,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 3299 | // This recv should fail | 3300 | // This recv should fail |
| 3300 | 3301 | ||
| 3301 | { | 3302 | { |
| 3302 | var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); | 3303 | const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); |
| 3303 | try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); | 3304 | try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); |
| 3304 | try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); | 3305 | try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); |
| 3305 | try testing.expectEqual(@as(u64, 0), sqe.addr); | 3306 | try testing.expectEqual(@as(u64, 0), sqe.addr); |
| ... | @@ -3349,7 +3350,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -3349,7 +3350,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 3349 | @memset(mem.sliceAsBytes(&buffers), 1); | 3350 | @memset(mem.sliceAsBytes(&buffers), 1); |
| 3350 | 3351 | ||
| 3351 | { | 3352 | { |
| 3352 | var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); | 3353 | const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); |
| 3353 | try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); | 3354 | try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); |
| 3354 | try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); | 3355 | try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); |
| 3355 | try testing.expectEqual(@as(u64, 0), sqe.addr); | 3356 | try testing.expectEqual(@as(u64, 0), sqe.addr); |
| ... | @@ -3477,7 +3478,7 @@ test "accept multishot" { | ... | @@ -3477,7 +3478,7 @@ test "accept multishot" { |
| 3477 | var nr: usize = 4; // number of clients to connect | 3478 | var nr: usize = 4; // number of clients to connect |
| 3478 | while (nr > 0) : (nr -= 1) { | 3479 | while (nr > 0) : (nr -= 1) { |
| 3479 | // connect client | 3480 | // connect client |
| 3480 | var client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); | 3481 | const client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); |
| 3481 | errdefer os.closeSocket(client); | 3482 | errdefer os.closeSocket(client); |
| 3482 | try os.connect(client, &address.any, address.getOsSockLen()); | 3483 | try os.connect(client, &address.any, address.getOsSockLen()); |
| 3483 | 3484 |
lib/std/os/plan9.zig+1-1| ... | @@ -278,7 +278,7 @@ pub fn sbrk(n: usize) usize { | ... | @@ -278,7 +278,7 @@ pub fn sbrk(n: usize) usize { |
| 278 | bloc = @intFromPtr(&ExecData.end); | 278 | bloc = @intFromPtr(&ExecData.end); |
| 279 | bloc_max = @intFromPtr(&ExecData.end); | 279 | bloc_max = @intFromPtr(&ExecData.end); |
| 280 | } | 280 | } |
| 281 | var bl = std.mem.alignForward(usize, bloc, std.mem.page_size); | 281 | const bl = std.mem.alignForward(usize, bloc, std.mem.page_size); |
| 282 | const n_aligned = std.mem.alignForward(usize, n, std.mem.page_size); | 282 | const n_aligned = std.mem.alignForward(usize, n, std.mem.page_size); |
| 283 | if (bl + n_aligned > bloc_max) { | 283 | if (bl + n_aligned > bloc_max) { |
| 284 | // we need to allocate | 284 | // we need to allocate |
lib/std/os/test.zig+15-15| ... | @@ -58,7 +58,7 @@ test "chdir smoke test" { | ... | @@ -58,7 +58,7 @@ test "chdir smoke test" { |
| 58 | { | 58 | { |
| 59 | // Create a tmp directory | 59 | // Create a tmp directory |
| 60 | var tmp_dir_buf: [fs.MAX_PATH_BYTES]u8 = undefined; | 60 | var tmp_dir_buf: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 61 | var tmp_dir_path = path: { | 61 | const tmp_dir_path = path: { |
| 62 | var allocator = std.heap.FixedBufferAllocator.init(&tmp_dir_buf); | 62 | var allocator = std.heap.FixedBufferAllocator.init(&tmp_dir_buf); |
| 63 | break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{ old_cwd, "zig-test-tmp" }); | 63 | break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{ old_cwd, "zig-test-tmp" }); |
| 64 | }; | 64 | }; |
| ... | @@ -72,7 +72,7 @@ test "chdir smoke test" { | ... | @@ -72,7 +72,7 @@ test "chdir smoke test" { |
| 72 | 72 | ||
| 73 | // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase | 73 | // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase |
| 74 | var resolved_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined; | 74 | var resolved_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 75 | var resolved_cwd = path: { | 75 | const resolved_cwd = path: { |
| 76 | var allocator = std.heap.FixedBufferAllocator.init(&resolved_cwd_buf); | 76 | var allocator = std.heap.FixedBufferAllocator.init(&resolved_cwd_buf); |
| 77 | break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{new_cwd}); | 77 | break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{new_cwd}); |
| 78 | }; | 78 | }; |
| ... | @@ -523,7 +523,7 @@ test "pipe" { | ... | @@ -523,7 +523,7 @@ test "pipe" { |
| 523 | if (native_os == .windows or native_os == .wasi) | 523 | if (native_os == .windows or native_os == .wasi) |
| 524 | return error.SkipZigTest; | 524 | return error.SkipZigTest; |
| 525 | 525 | ||
| 526 | var fds = try os.pipe(); | 526 | const fds = try os.pipe(); |
| 527 | try expect((try os.write(fds[1], "hello")) == 5); | 527 | try expect((try os.write(fds[1], "hello")) == 5); |
| 528 | var buf: [16]u8 = undefined; | 528 | var buf: [16]u8 = undefined; |
| 529 | try expect((try os.read(fds[0], buf[0..])) == 5); | 529 | try expect((try os.read(fds[0], buf[0..])) == 5); |
| ... | @@ -533,7 +533,7 @@ test "pipe" { | ... | @@ -533,7 +533,7 @@ test "pipe" { |
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | test "argsAlloc" { | 535 | test "argsAlloc" { |
| 536 | var args = try std.process.argsAlloc(std.testing.allocator); | 536 | const args = try std.process.argsAlloc(std.testing.allocator); |
| 537 | std.process.argsFree(std.testing.allocator, args); | 537 | std.process.argsFree(std.testing.allocator, args); |
| 538 | } | 538 | } |
| 539 | 539 | ||
| ... | @@ -1087,7 +1087,7 @@ test "timerfd" { | ... | @@ -1087,7 +1087,7 @@ test "timerfd" { |
| 1087 | return error.SkipZigTest; | 1087 | return error.SkipZigTest; |
| 1088 | 1088 | ||
| 1089 | const linux = os.linux; | 1089 | const linux = os.linux; |
| 1090 | var tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC); | 1090 | const tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC); |
| 1091 | defer os.close(tfd); | 1091 | defer os.close(tfd); |
| 1092 | 1092 | ||
| 1093 | // Fire event 10_000_000ns = 10ms after the os.timerfd_settime call. | 1093 | // Fire event 10_000_000ns = 10ms after the os.timerfd_settime call. |
| ... | @@ -1097,8 +1097,8 @@ test "timerfd" { | ... | @@ -1097,8 +1097,8 @@ test "timerfd" { |
| 1097 | var fds: [1]os.pollfd = .{.{ .fd = tfd, .events = os.linux.POLL.IN, .revents = 0 }}; | 1097 | var fds: [1]os.pollfd = .{.{ .fd = tfd, .events = os.linux.POLL.IN, .revents = 0 }}; |
| 1098 | try expectEqual(@as(usize, 1), try os.poll(&fds, -1)); // -1 => infinite waiting | 1098 | try expectEqual(@as(usize, 1), try os.poll(&fds, -1)); // -1 => infinite waiting |
| 1099 | 1099 | ||
| 1100 | var git = try os.timerfd_gettime(tfd); | 1100 | const git = try os.timerfd_gettime(tfd); |
| 1101 | var expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } }; | 1101 | const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } }; |
| 1102 | try expectEqual(expect_disarmed_timer, git); | 1102 | try expectEqual(expect_disarmed_timer, git); |
| 1103 | } | 1103 | } |
| 1104 | 1104 | ||
| ... | @@ -1128,11 +1128,11 @@ test "read with empty buffer" { | ... | @@ -1128,11 +1128,11 @@ test "read with empty buffer" { |
| 1128 | break :blk try fs.realpathAlloc(allocator, relative_path); | 1128 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 1129 | }; | 1129 | }; |
| 1130 | 1130 | ||
| 1131 | var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); | 1131 | const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 1132 | var file = try fs.cwd().createFile(file_path, .{ .read = true }); | 1132 | var file = try fs.cwd().createFile(file_path, .{ .read = true }); |
| 1133 | defer file.close(); | 1133 | defer file.close(); |
| 1134 | 1134 | ||
| 1135 | var bytes = try allocator.alloc(u8, 0); | 1135 | const bytes = try allocator.alloc(u8, 0); |
| 1136 | 1136 | ||
| 1137 | _ = try os.read(file.handle, bytes); | 1137 | _ = try os.read(file.handle, bytes); |
| 1138 | } | 1138 | } |
| ... | @@ -1153,11 +1153,11 @@ test "pread with empty buffer" { | ... | @@ -1153,11 +1153,11 @@ test "pread with empty buffer" { |
| 1153 | break :blk try fs.realpathAlloc(allocator, relative_path); | 1153 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 1154 | }; | 1154 | }; |
| 1155 | 1155 | ||
| 1156 | var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); | 1156 | const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 1157 | var file = try fs.cwd().createFile(file_path, .{ .read = true }); | 1157 | var file = try fs.cwd().createFile(file_path, .{ .read = true }); |
| 1158 | defer file.close(); | 1158 | defer file.close(); |
| 1159 | 1159 | ||
| 1160 | var bytes = try allocator.alloc(u8, 0); | 1160 | const bytes = try allocator.alloc(u8, 0); |
| 1161 | 1161 | ||
| 1162 | _ = try os.pread(file.handle, bytes, 0); | 1162 | _ = try os.pread(file.handle, bytes, 0); |
| 1163 | } | 1163 | } |
| ... | @@ -1178,11 +1178,11 @@ test "write with empty buffer" { | ... | @@ -1178,11 +1178,11 @@ test "write with empty buffer" { |
| 1178 | break :blk try fs.realpathAlloc(allocator, relative_path); | 1178 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 1179 | }; | 1179 | }; |
| 1180 | 1180 | ||
| 1181 | var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); | 1181 | const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 1182 | var file = try fs.cwd().createFile(file_path, .{}); | 1182 | var file = try fs.cwd().createFile(file_path, .{}); |
| 1183 | defer file.close(); | 1183 | defer file.close(); |
| 1184 | 1184 | ||
| 1185 | var bytes = try allocator.alloc(u8, 0); | 1185 | const bytes = try allocator.alloc(u8, 0); |
| 1186 | 1186 | ||
| 1187 | _ = try os.write(file.handle, bytes); | 1187 | _ = try os.write(file.handle, bytes); |
| 1188 | } | 1188 | } |
| ... | @@ -1203,11 +1203,11 @@ test "pwrite with empty buffer" { | ... | @@ -1203,11 +1203,11 @@ test "pwrite with empty buffer" { |
| 1203 | break :blk try fs.realpathAlloc(allocator, relative_path); | 1203 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 1204 | }; | 1204 | }; |
| 1205 | 1205 | ||
| 1206 | var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); | 1206 | const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 1207 | var file = try fs.cwd().createFile(file_path, .{}); | 1207 | var file = try fs.cwd().createFile(file_path, .{}); |
| 1208 | defer file.close(); | 1208 | defer file.close(); |
| 1209 | 1209 | ||
| 1210 | var bytes = try allocator.alloc(u8, 0); | 1210 | const bytes = try allocator.alloc(u8, 0); |
| 1211 | 1211 | ||
| 1212 | _ = try os.pwrite(file.handle, bytes, 0); | 1212 | _ = try os.pwrite(file.handle, bytes, 0); |
| 1213 | } | 1213 | } |
lib/std/os/uefi.zig+3-4| ... | @@ -149,11 +149,10 @@ pub const TimeCapabilities = extern struct { | ... | @@ -149,11 +149,10 @@ pub const TimeCapabilities = extern struct { |
| 149 | pub const FileHandle = *opaque {}; | 149 | pub const FileHandle = *opaque {}; |
| 150 | 150 | ||
| 151 | test "GUID formatting" { | 151 | test "GUID formatting" { |
| 152 | var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 }; | 152 | const bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 }; |
| 153 | const guid: Guid = @bitCast(bytes); | ||
| 153 | 154 | ||
| 154 | var guid = @as(Guid, @bitCast(bytes)); | 155 | const str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid}); |
| 155 | |||
| 156 | var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid}); | ||
| 157 | defer std.testing.allocator.free(str); | 156 | defer std.testing.allocator.free(str); |
| 158 | 157 | ||
| 159 | try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287")); | 158 | try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287")); |
lib/std/os/uefi/device_path.zig+2-2| ... | @@ -213,7 +213,7 @@ pub const DevicePath = union(Type) { | ... | @@ -213,7 +213,7 @@ pub const DevicePath = union(Type) { |
| 213 | // multiple adr entries can optionally follow | 213 | // multiple adr entries can optionally follow |
| 214 | pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 { | 214 | pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 { |
| 215 | // self.length is a minimum of 8 with one adr which is size 4. | 215 | // self.length is a minimum of 8 with one adr which is size 4. |
| 216 | var entries = (self.length - 4) / @sizeOf(u32); | 216 | const entries = (self.length - 4) / @sizeOf(u32); |
| 217 | return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries]; | 217 | return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries]; |
| 218 | } | 218 | } |
| 219 | }; | 219 | }; |
| ... | @@ -431,7 +431,7 @@ pub const DevicePath = union(Type) { | ... | @@ -431,7 +431,7 @@ pub const DevicePath = union(Type) { |
| 431 | device_product_id: u16 align(1), | 431 | device_product_id: u16 align(1), |
| 432 | 432 | ||
| 433 | pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 { | 433 | pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 { |
| 434 | var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16); | 434 | const serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16); |
| 435 | return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len]; | 435 | return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len]; |
| 436 | } | 436 | } |
| 437 | }; | 437 | }; |
lib/std/os/uefi/pool_allocator.zig+1-1| ... | @@ -34,7 +34,7 @@ const UefiPoolAllocator = struct { | ... | @@ -34,7 +34,7 @@ const UefiPoolAllocator = struct { |
| 34 | const unaligned_addr = @intFromPtr(unaligned_ptr); | 34 | const unaligned_addr = @intFromPtr(unaligned_ptr); |
| 35 | const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align); | 35 | const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align); |
| 36 | 36 | ||
| 37 | var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); | 37 | const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); |
| 38 | getHeader(aligned_ptr).* = unaligned_ptr; | 38 | getHeader(aligned_ptr).* = unaligned_ptr; |
| 39 | 39 | ||
| 40 | return aligned_ptr; | 40 | return aligned_ptr; |
lib/std/os/uefi/protocol/device_path.zig+2-3| ... | @@ -43,7 +43,7 @@ pub const DevicePath = extern struct { | ... | @@ -43,7 +43,7 @@ pub const DevicePath = extern struct { |
| 43 | 43 | ||
| 44 | /// Creates a file device path from the existing device path and a file path. | 44 | /// Creates a file device path from the existing device path and a file path. |
| 45 | pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath { | 45 | pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath { |
| 46 | var path_size = self.size(); | 46 | const path_size = self.size(); |
| 47 | 47 | ||
| 48 | // 2 * (path.len + 1) for the path and its null terminator, which are u16s | 48 | // 2 * (path.len + 1) for the path and its null terminator, which are u16s |
| 49 | // DevicePath for the extra node before the end | 49 | // DevicePath for the extra node before the end |
| ... | @@ -82,8 +82,7 @@ pub const DevicePath = extern struct { | ... | @@ -82,8 +82,7 @@ pub const DevicePath = extern struct { |
| 82 | // Got the associated union type for self.type, now | 82 | // Got the associated union type for self.type, now |
| 83 | // we need to initialize it and its subtype | 83 | // we need to initialize it and its subtype |
| 84 | if (self.type == enum_value) { | 84 | if (self.type == enum_value) { |
| 85 | var subtype = self.initSubtype(ufield.type); | 85 | const subtype = self.initSubtype(ufield.type); |
| 86 | |||
| 87 | if (subtype) |sb| { | 86 | if (subtype) |sb| { |
| 88 | // e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } } | 87 | // e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } } |
| 89 | return @unionInit(uefi.DevicePath, ufield.name, sb); | 88 | return @unionInit(uefi.DevicePath, ufield.name, sb); |
lib/std/os/windows.zig+3-3| ... | @@ -1166,7 +1166,7 @@ test "QueryObjectName" { | ... | @@ -1166,7 +1166,7 @@ test "QueryObjectName" { |
| 1166 | const handle = tmp.dir.fd; | 1166 | const handle = tmp.dir.fd; |
| 1167 | var out_buffer: [PATH_MAX_WIDE]u16 = undefined; | 1167 | var out_buffer: [PATH_MAX_WIDE]u16 = undefined; |
| 1168 | 1168 | ||
| 1169 | var result_path = try QueryObjectName(handle, &out_buffer); | 1169 | const result_path = try QueryObjectName(handle, &out_buffer); |
| 1170 | const required_len_in_u16 = result_path.len + @divExact(@intFromPtr(result_path.ptr) - @intFromPtr(&out_buffer), 2) + 1; | 1170 | const required_len_in_u16 = result_path.len + @divExact(@intFromPtr(result_path.ptr) - @intFromPtr(&out_buffer), 2) + 1; |
| 1171 | //insufficient size | 1171 | //insufficient size |
| 1172 | try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1])); | 1172 | try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1])); |
| ... | @@ -2045,8 +2045,8 @@ pub fn eqlIgnoreCaseUtf8(a: []const u8, b: []const u8) bool { | ... | @@ -2045,8 +2045,8 @@ pub fn eqlIgnoreCaseUtf8(a: []const u8, b: []const u8) bool { |
| 2045 | }; | 2045 | }; |
| 2046 | 2046 | ||
| 2047 | while (true) { | 2047 | while (true) { |
| 2048 | var a_cp = a_utf8_it.nextCodepoint() orelse break; | 2048 | const a_cp = a_utf8_it.nextCodepoint() orelse break; |
| 2049 | var b_cp = b_utf8_it.nextCodepoint() orelse return false; | 2049 | const b_cp = b_utf8_it.nextCodepoint() orelse return false; |
| 2050 | 2050 | ||
| 2051 | if (a_cp <= std.math.maxInt(u16) and b_cp <= std.math.maxInt(u16)) { | 2051 | if (a_cp <= std.math.maxInt(u16) and b_cp <= std.math.maxInt(u16)) { |
| 2052 | if (a_cp != b_cp and upcaseImpl(@intCast(a_cp)) != upcaseImpl(@intCast(b_cp))) { | 2052 | if (a_cp != b_cp and upcaseImpl(@intCast(a_cp)) != upcaseImpl(@intCast(b_cp))) { |
lib/std/pdb.zig+1-1| ... | @@ -897,7 +897,7 @@ const Msf = struct { | ... | @@ -897,7 +897,7 @@ const Msf = struct { |
| 897 | return error.UnhandledBigDirectoryStream; // cf. BlockMapAddr comment. | 897 | return error.UnhandledBigDirectoryStream; // cf. BlockMapAddr comment. |
| 898 | 898 | ||
| 899 | try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr); | 899 | try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr); |
| 900 | var dir_blocks = try allocator.alloc(u32, dir_block_count); | 900 | const dir_blocks = try allocator.alloc(u32, dir_block_count); |
| 901 | for (dir_blocks) |*b| { | 901 | for (dir_blocks) |*b| { |
| 902 | b.* = try in.readInt(u32, .little); | 902 | b.* = try in.readInt(u32, .little); |
| 903 | } | 903 | } |
lib/std/priority_dequeue.zig+5-5| ... | @@ -82,8 +82,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar | ... | @@ -82,8 +82,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar |
| 82 | }; | 82 | }; |
| 83 | 83 | ||
| 84 | fn getStartForSiftUp(self: Self, child: T, index: usize) StartIndexAndLayer { | 84 | fn getStartForSiftUp(self: Self, child: T, index: usize) StartIndexAndLayer { |
| 85 | var child_index = index; | 85 | const child_index = index; |
| 86 | var parent_index = parentIndex(child_index); | 86 | const parent_index = parentIndex(child_index); |
| 87 | const parent = self.items[parent_index]; | 87 | const parent = self.items[parent_index]; |
| 88 | 88 | ||
| 89 | const min_layer = self.nextIsMinLayer(); | 89 | const min_layer = self.nextIsMinLayer(); |
| ... | @@ -115,7 +115,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar | ... | @@ -115,7 +115,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar |
| 115 | fn doSiftUp(self: *Self, start_index: usize, target_order: Order) void { | 115 | fn doSiftUp(self: *Self, start_index: usize, target_order: Order) void { |
| 116 | var child_index = start_index; | 116 | var child_index = start_index; |
| 117 | while (child_index > 2) { | 117 | while (child_index > 2) { |
| 118 | var grandparent_index = grandparentIndex(child_index); | 118 | const grandparent_index = grandparentIndex(child_index); |
| 119 | const child = self.items[child_index]; | 119 | const child = self.items[child_index]; |
| 120 | const grandparent = self.items[grandparent_index]; | 120 | const grandparent = self.items[grandparent_index]; |
| 121 | 121 | ||
| ... | @@ -286,8 +286,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar | ... | @@ -286,8 +286,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar |
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | fn bestItemAtIndices(self: Self, index1: usize, index2: usize, target_order: Order) ItemAndIndex { | 288 | fn bestItemAtIndices(self: Self, index1: usize, index2: usize, target_order: Order) ItemAndIndex { |
| 289 | var item1 = self.getItem(index1); | 289 | const item1 = self.getItem(index1); |
| 290 | var item2 = self.getItem(index2); | 290 | const item2 = self.getItem(index2); |
| 291 | return self.bestItem(item1, item2, target_order); | 291 | return self.bestItem(item1, item2, target_order); |
| 292 | } | 292 | } |
| 293 | 293 |
lib/std/priority_queue.zig+1-1| ... | @@ -470,7 +470,7 @@ test "std.PriorityQueue: remove at index" { | ... | @@ -470,7 +470,7 @@ test "std.PriorityQueue: remove at index" { |
| 470 | break idx; | 470 | break idx; |
| 471 | idx += 1; | 471 | idx += 1; |
| 472 | } else unreachable; | 472 | } else unreachable; |
| 473 | var sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 }; | 473 | const sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 }; |
| 474 | try expectEqual(queue.removeIndex(two_idx), 2); | 474 | try expectEqual(queue.removeIndex(two_idx), 2); |
| 475 | 475 | ||
| 476 | var i: usize = 0; | 476 | var i: usize = 0; |
lib/std/process.zig+12-12| ... | @@ -298,9 +298,9 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap { | ... | @@ -298,9 +298,9 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap { |
| 298 | return result; | 298 | return result; |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | var environ = try allocator.alloc([*:0]u8, environ_count); | 301 | const environ = try allocator.alloc([*:0]u8, environ_count); |
| 302 | defer allocator.free(environ); | 302 | defer allocator.free(environ); |
| 303 | var environ_buf = try allocator.alloc(u8, environ_buf_size); | 303 | const environ_buf = try allocator.alloc(u8, environ_buf_size); |
| 304 | defer allocator.free(environ_buf); | 304 | defer allocator.free(environ_buf); |
| 305 | 305 | ||
| 306 | const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr); | 306 | const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr); |
| ... | @@ -412,7 +412,7 @@ pub fn hasEnvVar(allocator: Allocator, key: []const u8) error{OutOfMemory}!bool | ... | @@ -412,7 +412,7 @@ pub fn hasEnvVar(allocator: Allocator, key: []const u8) error{OutOfMemory}!bool |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | test "os.getEnvVarOwned" { | 414 | test "os.getEnvVarOwned" { |
| 415 | var ga = std.testing.allocator; | 415 | const ga = std.testing.allocator; |
| 416 | try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV")); | 416 | try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV")); |
| 417 | } | 417 | } |
| 418 | 418 | ||
| ... | @@ -477,10 +477,10 @@ pub const ArgIteratorWasi = struct { | ... | @@ -477,10 +477,10 @@ pub const ArgIteratorWasi = struct { |
| 477 | return &[_][:0]u8{}; | 477 | return &[_][:0]u8{}; |
| 478 | } | 478 | } |
| 479 | 479 | ||
| 480 | var argv = try allocator.alloc([*:0]u8, count); | 480 | const argv = try allocator.alloc([*:0]u8, count); |
| 481 | defer allocator.free(argv); | 481 | defer allocator.free(argv); |
| 482 | 482 | ||
| 483 | var argv_buf = try allocator.alloc(u8, buf_size); | 483 | const argv_buf = try allocator.alloc(u8, buf_size); |
| 484 | 484 | ||
| 485 | switch (w.args_get(argv.ptr, argv_buf.ptr)) { | 485 | switch (w.args_get(argv.ptr, argv_buf.ptr)) { |
| 486 | .SUCCESS => {}, | 486 | .SUCCESS => {}, |
| ... | @@ -551,7 +551,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { | ... | @@ -551,7 +551,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { |
| 551 | 551 | ||
| 552 | /// cmd_line_utf8 MUST remain valid and constant while using this instance | 552 | /// cmd_line_utf8 MUST remain valid and constant while using this instance |
| 553 | pub fn init(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self { | 553 | pub fn init(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self { |
| 554 | var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1); | 554 | const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1); |
| 555 | errdefer allocator.free(buffer); | 555 | errdefer allocator.free(buffer); |
| 556 | 556 | ||
| 557 | return Self{ | 557 | return Self{ |
| ... | @@ -564,7 +564,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { | ... | @@ -564,7 +564,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { |
| 564 | 564 | ||
| 565 | /// cmd_line_utf8 will be free'd (with the allocator) on deinit() | 565 | /// cmd_line_utf8 will be free'd (with the allocator) on deinit() |
| 566 | pub fn initTakeOwnership(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self { | 566 | pub fn initTakeOwnership(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self { |
| 567 | var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1); | 567 | const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1); |
| 568 | errdefer allocator.free(buffer); | 568 | errdefer allocator.free(buffer); |
| 569 | 569 | ||
| 570 | return Self{ | 570 | return Self{ |
| ... | @@ -577,8 +577,8 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { | ... | @@ -577,8 +577,8 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { |
| 577 | 577 | ||
| 578 | /// cmd_line_utf16le MUST be encoded UTF16-LE, and is converted to UTF-8 in an internal buffer | 578 | /// cmd_line_utf16le MUST be encoded UTF16-LE, and is converted to UTF-8 in an internal buffer |
| 579 | pub fn initUtf16le(allocator: Allocator, cmd_line_utf16le: [*:0]const u16) InitUtf16leError!Self { | 579 | pub fn initUtf16le(allocator: Allocator, cmd_line_utf16le: [*:0]const u16) InitUtf16leError!Self { |
| 580 | var utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0); | 580 | const utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0); |
| 581 | var cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) { | 581 | const cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) { |
| 582 | error.ExpectedSecondSurrogateHalf, | 582 | error.ExpectedSecondSurrogateHalf, |
| 583 | error.DanglingSurrogateHalf, | 583 | error.DanglingSurrogateHalf, |
| 584 | error.UnexpectedSecondSurrogateHalf, | 584 | error.UnexpectedSecondSurrogateHalf, |
| ... | @@ -588,7 +588,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { | ... | @@ -588,7 +588,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { |
| 588 | }; | 588 | }; |
| 589 | errdefer allocator.free(cmd_line); | 589 | errdefer allocator.free(cmd_line); |
| 590 | 590 | ||
| 591 | var buffer = try allocator.alloc(u8, cmd_line.len + 1); | 591 | const buffer = try allocator.alloc(u8, cmd_line.len + 1); |
| 592 | errdefer allocator.free(buffer); | 592 | errdefer allocator.free(buffer); |
| 593 | 593 | ||
| 594 | return Self{ | 594 | return Self{ |
| ... | @@ -681,7 +681,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { | ... | @@ -681,7 +681,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { |
| 681 | 0 => { | 681 | 0 => { |
| 682 | self.emitBackslashes(backslash_count); | 682 | self.emitBackslashes(backslash_count); |
| 683 | self.buffer[self.end] = 0; | 683 | self.buffer[self.end] = 0; |
| 684 | var token = self.buffer[self.start..self.end :0]; | 684 | const token = self.buffer[self.start..self.end :0]; |
| 685 | self.end += 1; | 685 | self.end += 1; |
| 686 | self.start = self.end; | 686 | self.start = self.end; |
| 687 | return token; | 687 | return token; |
| ... | @@ -713,7 +713,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { | ... | @@ -713,7 +713,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { |
| 713 | self.emitCharacter(character); | 713 | self.emitCharacter(character); |
| 714 | } else { | 714 | } else { |
| 715 | self.buffer[self.end] = 0; | 715 | self.buffer[self.end] = 0; |
| 716 | var token = self.buffer[self.start..self.end :0]; | 716 | const token = self.buffer[self.start..self.end :0]; |
| 717 | self.end += 1; | 717 | self.end += 1; |
| 718 | self.start = self.end; | 718 | self.start = self.end; |
| 719 | return token; | 719 | return token; |
lib/std/rand/test.zig+2-2| ... | @@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" { | ... | @@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" { |
| 332 | while (i < num_numbers) : (i += 1) { | 332 | while (i < num_numbers) : (i += 1) { |
| 333 | const rand_f32 = random.float(f32); | 333 | const rand_f32 = random.float(f32); |
| 334 | const rand_f64 = random.float(f64); | 334 | const rand_f64 = random.float(f64); |
| 335 | var f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets))))); | 335 | const f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets))))); |
| 336 | if (f32_put.found_existing) { | 336 | if (f32_put.found_existing) { |
| 337 | f32_put.value_ptr.* += 1; | 337 | f32_put.value_ptr.* += 1; |
| 338 | } else { | 338 | } else { |
| 339 | f32_put.value_ptr.* = 1; | 339 | f32_put.value_ptr.* = 1; |
| 340 | } | 340 | } |
| 341 | var f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets))))); | 341 | const f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets))))); |
| 342 | if (f64_put.found_existing) { | 342 | if (f64_put.found_existing) { |
| 343 | f64_put.value_ptr.* += 1; | 343 | f64_put.value_ptr.* += 1; |
| 344 | } else { | 344 | } else { |
lib/std/sort.zig+1-1| ... | @@ -387,7 +387,7 @@ test "sort fuzz testing" { | ... | @@ -387,7 +387,7 @@ test "sort fuzz testing" { |
| 387 | var i: usize = 0; | 387 | var i: usize = 0; |
| 388 | while (i < test_case_count) : (i += 1) { | 388 | while (i < test_case_count) : (i += 1) { |
| 389 | const array_size = random.intRangeLessThan(usize, 0, 1000); | 389 | const array_size = random.intRangeLessThan(usize, 0, 1000); |
| 390 | var array = try testing.allocator.alloc(i32, array_size); | 390 | const array = try testing.allocator.alloc(i32, array_size); |
| 391 | defer testing.allocator.free(array); | 391 | defer testing.allocator.free(array); |
| 392 | // populate with random data | 392 | // populate with random data |
| 393 | for (array) |*item| { | 393 | for (array) |*item| { |
lib/std/sort/block.zig+2-2| ... | @@ -302,8 +302,8 @@ pub fn block( | ... | @@ -302,8 +302,8 @@ pub fn block( |
| 302 | } else { | 302 | } else { |
| 303 | iterator.begin(); | 303 | iterator.begin(); |
| 304 | while (!iterator.finished()) { | 304 | while (!iterator.finished()) { |
| 305 | var A = iterator.nextRange(); | 305 | const A = iterator.nextRange(); |
| 306 | var B = iterator.nextRange(); | 306 | const B = iterator.nextRange(); |
| 307 | 307 | ||
| 308 | if (lessThan(context, items[B.end - 1], items[A.start])) { | 308 | if (lessThan(context, items[B.end - 1], items[A.start])) { |
| 309 | // the two ranges are in reverse order, so a simple rotation should fix it | 309 | // the two ranges are in reverse order, so a simple rotation should fix it |
lib/std/sort/pdq.zig+4-4| ... | @@ -276,10 +276,10 @@ fn chosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint { | ... | @@ -276,10 +276,10 @@ fn chosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint { |
| 276 | // max_swaps is the maximum number of swaps allowed in this function | 276 | // max_swaps is the maximum number of swaps allowed in this function |
| 277 | const max_swaps = 4 * 3; | 277 | const max_swaps = 4 * 3; |
| 278 | 278 | ||
| 279 | var len = b - a; | 279 | const len = b - a; |
| 280 | var i = a + len / 4 * 1; | 280 | const i = a + len / 4 * 1; |
| 281 | var j = a + len / 4 * 2; | 281 | const j = a + len / 4 * 2; |
| 282 | var k = a + len / 4 * 3; | 282 | const k = a + len / 4 * 3; |
| 283 | var swaps: usize = 0; | 283 | var swaps: usize = 0; |
| 284 | 284 | ||
| 285 | if (len >= 8) { | 285 | if (len >= 8) { |
lib/std/tar.zig+1-1| ... | @@ -218,7 +218,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi | ... | @@ -218,7 +218,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi |
| 218 | if (file_size == 0 and unstripped_file_name.len == 0) return; | 218 | if (file_size == 0 and unstripped_file_name.len == 0) return; |
| 219 | const file_name = try stripComponents(unstripped_file_name, options.strip_components); | 219 | const file_name = try stripComponents(unstripped_file_name, options.strip_components); |
| 220 | 220 | ||
| 221 | var file = dir.createFile(file_name, .{}) catch |err| switch (err) { | 221 | const file = dir.createFile(file_name, .{}) catch |err| switch (err) { |
| 222 | error.FileNotFound => again: { | 222 | error.FileNotFound => again: { |
| 223 | const code = code: { | 223 | const code = code: { |
| 224 | if (std.fs.path.dirname(file_name)) |dir_name| { | 224 | if (std.fs.path.dirname(file_name)) |dir_name| { |
lib/std/testing.zig+10-10| ... | @@ -399,7 +399,7 @@ fn SliceDiffer(comptime T: type) type { | ... | @@ -399,7 +399,7 @@ fn SliceDiffer(comptime T: type) type { |
| 399 | 399 | ||
| 400 | pub fn write(self: Self, writer: anytype) !void { | 400 | pub fn write(self: Self, writer: anytype) !void { |
| 401 | for (self.expected, 0..) |value, i| { | 401 | for (self.expected, 0..) |value, i| { |
| 402 | var full_index = self.start_index + i; | 402 | const full_index = self.start_index + i; |
| 403 | const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true; | 403 | const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true; |
| 404 | if (diff) try self.ttyconf.setColor(writer, .red); | 404 | if (diff) try self.ttyconf.setColor(writer, .red); |
| 405 | if (@typeInfo(T) == .Pointer) { | 405 | if (@typeInfo(T) == .Pointer) { |
| ... | @@ -424,7 +424,7 @@ const BytesDiffer = struct { | ... | @@ -424,7 +424,7 @@ const BytesDiffer = struct { |
| 424 | // to avoid having to calculate diffs twice per chunk | 424 | // to avoid having to calculate diffs twice per chunk |
| 425 | var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 }; | 425 | var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 }; |
| 426 | for (chunk, 0..) |byte, i| { | 426 | for (chunk, 0..) |byte, i| { |
| 427 | var absolute_byte_index = (expected_iterator.index - chunk.len) + i; | 427 | const absolute_byte_index = (expected_iterator.index - chunk.len) + i; |
| 428 | const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true; | 428 | const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true; |
| 429 | if (diff) diffs.set(i); | 429 | if (diff) diffs.set(i); |
| 430 | try self.writeByteDiff(writer, "{X:0>2} ", byte, diff); | 430 | try self.writeByteDiff(writer, "{X:0>2} ", byte, diff); |
| ... | @@ -565,13 +565,13 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir { | ... | @@ -565,13 +565,13 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir { |
| 565 | var sub_path: [TmpDir.sub_path_len]u8 = undefined; | 565 | var sub_path: [TmpDir.sub_path_len]u8 = undefined; |
| 566 | _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes); | 566 | _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes); |
| 567 | 567 | ||
| 568 | var cwd = std.fs.cwd(); | 568 | const cwd = std.fs.cwd(); |
| 569 | var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch | 569 | var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch |
| 570 | @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir"); | 570 | @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir"); |
| 571 | defer cache_dir.close(); | 571 | defer cache_dir.close(); |
| 572 | var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch | 572 | const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch |
| 573 | @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir"); | 573 | @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir"); |
| 574 | var dir = parent_dir.makeOpenPath(&sub_path, opts) catch | 574 | const dir = parent_dir.makeOpenPath(&sub_path, opts) catch |
| 575 | @panic("unable to make tmp dir for testing: unable to make and open the tmp dir"); | 575 | @panic("unable to make tmp dir for testing: unable to make and open the tmp dir"); |
| 576 | 576 | ||
| 577 | return .{ | 577 | return .{ |
| ... | @@ -587,13 +587,13 @@ pub fn tmpIterableDir(opts: std.fs.Dir.OpenDirOptions) TmpIterableDir { | ... | @@ -587,13 +587,13 @@ pub fn tmpIterableDir(opts: std.fs.Dir.OpenDirOptions) TmpIterableDir { |
| 587 | var sub_path: [TmpIterableDir.sub_path_len]u8 = undefined; | 587 | var sub_path: [TmpIterableDir.sub_path_len]u8 = undefined; |
| 588 | _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes); | 588 | _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes); |
| 589 | 589 | ||
| 590 | var cwd = std.fs.cwd(); | 590 | const cwd = std.fs.cwd(); |
| 591 | var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch | 591 | var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch |
| 592 | @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir"); | 592 | @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir"); |
| 593 | defer cache_dir.close(); | 593 | defer cache_dir.close(); |
| 594 | var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch | 594 | const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch |
| 595 | @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir"); | 595 | @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir"); |
| 596 | var dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch | 596 | const dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch |
| 597 | @panic("unable to make tmp dir for testing: unable to make and open the tmp dir"); | 597 | @panic("unable to make tmp dir for testing: unable to make and open the tmp dir"); |
| 598 | 598 | ||
| 599 | return .{ | 599 | return .{ |
| ... | @@ -618,8 +618,8 @@ test "expectEqual nested array" { | ... | @@ -618,8 +618,8 @@ test "expectEqual nested array" { |
| 618 | } | 618 | } |
| 619 | 619 | ||
| 620 | test "expectEqual vector" { | 620 | test "expectEqual vector" { |
| 621 | var a: @Vector(4, u32) = @splat(4); | 621 | const a: @Vector(4, u32) = @splat(4); |
| 622 | var b: @Vector(4, u32) = @splat(4); | 622 | const b: @Vector(4, u32) = @splat(4); |
| 623 | 623 | ||
| 624 | try expectEqual(a, b); | 624 | try expectEqual(a, b); |
| 625 | } | 625 | } |
lib/std/treap.zig+1-1| ... | @@ -379,7 +379,7 @@ test "std.Treap: insert, find, replace, remove" { | ... | @@ -379,7 +379,7 @@ test "std.Treap: insert, find, replace, remove" { |
| 379 | const key = node.key; | 379 | const key = node.key; |
| 380 | 380 | ||
| 381 | // find the entry by-key and by-node after having been inserted. | 381 | // find the entry by-key and by-node after having been inserted. |
| 382 | var entry = treap.getEntryFor(node.key); | 382 | const entry = treap.getEntryFor(node.key); |
| 383 | try testing.expectEqual(entry.key, key); | 383 | try testing.expectEqual(entry.key, key); |
| 384 | try testing.expectEqual(entry.node, node); | 384 | try testing.expectEqual(entry.node, node); |
| 385 | try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node); | 385 | try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node); |
lib/std/unicode.zig+1-1| ... | @@ -242,7 +242,7 @@ pub fn utf8ValidateSlice(input: []const u8) bool { | ... | @@ -242,7 +242,7 @@ pub fn utf8ValidateSlice(input: []const u8) bool { |
| 242 | s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, | 242 | s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
| 243 | }; | 243 | }; |
| 244 | 244 | ||
| 245 | var n = remaining.len; | 245 | const n = remaining.len; |
| 246 | var i: usize = 0; | 246 | var i: usize = 0; |
| 247 | while (i < n) { | 247 | while (i < n) { |
| 248 | const first_byte = remaining[i]; | 248 | const first_byte = remaining[i]; |
lib/std/zig/Parse.zig+1-2| ... | @@ -3516,7 +3516,6 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers { | ... | @@ -3516,7 +3516,6 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers { |
| 3516 | var saw_const = false; | 3516 | var saw_const = false; |
| 3517 | var saw_volatile = false; | 3517 | var saw_volatile = false; |
| 3518 | var saw_allowzero = false; | 3518 | var saw_allowzero = false; |
| 3519 | var saw_addrspace = false; | ||
| 3520 | while (true) { | 3519 | while (true) { |
| 3521 | switch (p.token_tags[p.tok_i]) { | 3520 | switch (p.token_tags[p.tok_i]) { |
| 3522 | .keyword_align => { | 3521 | .keyword_align => { |
| ... | @@ -3557,7 +3556,7 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers { | ... | @@ -3557,7 +3556,7 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers { |
| 3557 | saw_allowzero = true; | 3556 | saw_allowzero = true; |
| 3558 | }, | 3557 | }, |
| 3559 | .keyword_addrspace => { | 3558 | .keyword_addrspace => { |
| 3560 | if (saw_addrspace) { | 3559 | if (result.addrspace_node != 0) { |
| 3561 | try p.warn(.extra_addrspace_qualifier); | 3560 | try p.warn(.extra_addrspace_qualifier); |
| 3562 | } | 3561 | } |
| 3563 | result.addrspace_node = try p.parseAddrSpace(); | 3562 | result.addrspace_node = try p.parseAddrSpace(); |
lib/std/zig/c_translation.zig+8-7| ... | @@ -129,6 +129,7 @@ test "cast" { | ... | @@ -129,6 +129,7 @@ test "cast" { |
| 129 | try testing.expectEqual(@as(?*anyopaque, @ptrFromInt(2)), cast(?*anyopaque, @as(*u8, @ptrFromInt(2)))); | 129 | try testing.expectEqual(@as(?*anyopaque, @ptrFromInt(2)), cast(?*anyopaque, @as(*u8, @ptrFromInt(2)))); |
| 130 | 130 | ||
| 131 | var foo: c_int = -1; | 131 | var foo: c_int = -1; |
| 132 | _ = &foo; | ||
| 132 | try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); | 133 | try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); |
| 133 | try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); | 134 | try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); |
| 134 | try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); | 135 | try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); |
| ... | @@ -601,22 +602,22 @@ test "WL_CONTAINER_OF" { | ... | @@ -601,22 +602,22 @@ test "WL_CONTAINER_OF" { |
| 601 | a: u32 = 0, | 602 | a: u32 = 0, |
| 602 | b: u32 = 0, | 603 | b: u32 = 0, |
| 603 | }; | 604 | }; |
| 604 | var x = S{}; | 605 | const x = S{}; |
| 605 | var y = S{}; | 606 | const y = S{}; |
| 606 | var ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b"); | 607 | const ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b"); |
| 607 | try testing.expectEqual(&x, ptr); | 608 | try testing.expectEqual(&x, ptr); |
| 608 | } | 609 | } |
| 609 | 610 | ||
| 610 | test "CAST_OR_CALL casting" { | 611 | test "CAST_OR_CALL casting" { |
| 611 | var arg = @as(c_int, 1000); | 612 | const arg: c_int = 1000; |
| 612 | var casted = Macros.CAST_OR_CALL(u8, arg); | 613 | const casted = Macros.CAST_OR_CALL(u8, arg); |
| 613 | try testing.expectEqual(cast(u8, arg), casted); | 614 | try testing.expectEqual(cast(u8, arg), casted); |
| 614 | 615 | ||
| 615 | const S = struct { | 616 | const S = struct { |
| 616 | x: u32 = 0, | 617 | x: u32 = 0, |
| 617 | }; | 618 | }; |
| 618 | var s = S{}; | 619 | var s: S = .{}; |
| 619 | var casted_ptr = Macros.CAST_OR_CALL(*u8, &s); | 620 | const casted_ptr = Macros.CAST_OR_CALL(*u8, &s); |
| 620 | try testing.expectEqual(cast(*u8, &s), casted_ptr); | 621 | try testing.expectEqual(cast(*u8, &s), casted_ptr); |
| 621 | } | 622 | } |
| 622 | 623 |
lib/std/zig/perf_test.zig+1-1| ... | @@ -32,7 +32,7 @@ pub fn main() !void { | ... | @@ -32,7 +32,7 @@ pub fn main() !void { |
| 32 | 32 | ||
| 33 | fn testOnce() usize { | 33 | fn testOnce() usize { |
| 34 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 34 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 35 | var allocator = fixed_buf_alloc.allocator(); | 35 | const allocator = fixed_buf_alloc.allocator(); |
| 36 | _ = std.zig.Ast.parse(allocator, source, .zig) catch @panic("parse failure"); | 36 | _ = std.zig.Ast.parse(allocator, source, .zig) catch @panic("parse failure"); |
| 37 | return fixed_buf_alloc.end_index; | 37 | return fixed_buf_alloc.end_index; |
| 38 | } | 38 | } |
lib/std/zig/render.zig+1-1| ... | @@ -3495,7 +3495,7 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { | ... | @@ -3495,7 +3495,7 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { |
| 3495 | /// Turns all one-shot indents into regular indents | 3495 | /// Turns all one-shot indents into regular indents |
| 3496 | /// Returns number of indents that must now be manually popped | 3496 | /// Returns number of indents that must now be manually popped |
| 3497 | pub fn lockOneShotIndent(self: *Self) usize { | 3497 | pub fn lockOneShotIndent(self: *Self) usize { |
| 3498 | var locked_count = self.indent_one_shot_count; | 3498 | const locked_count = self.indent_one_shot_count; |
| 3499 | self.indent_one_shot_count = 0; | 3499 | self.indent_one_shot_count = 0; |
| 3500 | return locked_count; | 3500 | return locked_count; |
| 3501 | } | 3501 | } |
lib/std/zig/string_literal.zig+1-1| ... | @@ -288,7 +288,7 @@ test "parse" { | ... | @@ -288,7 +288,7 @@ test "parse" { |
| 288 | 288 | ||
| 289 | var fixed_buf_mem: [64]u8 = undefined; | 289 | var fixed_buf_mem: [64]u8 = undefined; |
| 290 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(&fixed_buf_mem); | 290 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(&fixed_buf_mem); |
| 291 | var alloc = fixed_buf_alloc.allocator(); | 291 | const alloc = fixed_buf_alloc.allocator(); |
| 292 | 292 | ||
| 293 | try expectError(error.InvalidLiteral, parseAlloc(alloc, "\"\\x6\"")); | 293 | try expectError(error.InvalidLiteral, parseAlloc(alloc, "\"\\x6\"")); |
| 294 | try expect(eql(u8, "foo\nbar", try parseAlloc(alloc, "\"foo\\nbar\""))); | 294 | try expect(eql(u8, "foo\nbar", try parseAlloc(alloc, "\"foo\\nbar\""))); |
lib/std/zig/system/NativeTargetInfo.zig+1-1| ... | @@ -189,7 +189,7 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo { | ... | @@ -189,7 +189,7 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo { |
| 189 | // native CPU architecture as being different than the current target), we use this: | 189 | // native CPU architecture as being different than the current target), we use this: |
| 190 | const cpu_arch = cross_target.getCpuArch(); | 190 | const cpu_arch = cross_target.getCpuArch(); |
| 191 | 191 | ||
| 192 | var cpu = switch (cross_target.cpu_model) { | 192 | const cpu = switch (cross_target.cpu_model) { |
| 193 | .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target), | 193 | .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target), |
| 194 | .baseline => Target.Cpu.baseline(cpu_arch), | 194 | .baseline => Target.Cpu.baseline(cpu_arch), |
| 195 | .determined_by_cpu_arch => if (cross_target.cpu_arch == null) | 195 | .determined_by_cpu_arch => if (cross_target.cpu_arch == null) |
src/Air.zig+1-1| ... | @@ -1787,7 +1787,7 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool { | ... | @@ -1787,7 +1787,7 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool { |
| 1787 | => false, | 1787 | => false, |
| 1788 | 1788 | ||
| 1789 | .assembly => { | 1789 | .assembly => { |
| 1790 | var extra = air.extraData(Air.Asm, data.ty_pl.payload); | 1790 | const extra = air.extraData(Air.Asm, data.ty_pl.payload); |
| 1791 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; | 1791 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| 1792 | return is_volatile or if (extra.data.outputs_len == 1) | 1792 | return is_volatile or if (extra.data.outputs_len == 1) |
| 1793 | @as(Air.Inst.Ref, @enumFromInt(air.extra[extra.end])) != .none | 1793 | @as(Air.Inst.Ref, @enumFromInt(air.extra[extra.end])) != .none |
src/AstGen.zig+44-16| ... | @@ -1226,7 +1226,7 @@ fn awaitExpr( | ... | @@ -1226,7 +1226,7 @@ fn awaitExpr( |
| 1226 | try astgen.errNoteNode(gz.suspend_node, "suspend block here", .{}), | 1226 | try astgen.errNoteNode(gz.suspend_node, "suspend block here", .{}), |
| 1227 | }); | 1227 | }); |
| 1228 | } | 1228 | } |
| 1229 | const operand = try expr(gz, scope, .{ .rl = .none }, rhs_node); | 1229 | const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node); |
| 1230 | const result = if (gz.nosuspend_node != 0) | 1230 | const result = if (gz.nosuspend_node != 0) |
| 1231 | try gz.addExtendedPayload(.await_nosuspend, Zir.Inst.UnNode{ | 1231 | try gz.addExtendedPayload(.await_nosuspend, Zir.Inst.UnNode{ |
| 1232 | .node = gz.nodeIndexToRelative(node), | 1232 | .node = gz.nodeIndexToRelative(node), |
| ... | @@ -1248,7 +1248,7 @@ fn resumeExpr( | ... | @@ -1248,7 +1248,7 @@ fn resumeExpr( |
| 1248 | const tree = astgen.tree; | 1248 | const tree = astgen.tree; |
| 1249 | const node_datas = tree.nodes.items(.data); | 1249 | const node_datas = tree.nodes.items(.data); |
| 1250 | const rhs_node = node_datas[node].lhs; | 1250 | const rhs_node = node_datas[node].lhs; |
| 1251 | const operand = try expr(gz, scope, .{ .rl = .none }, rhs_node); | 1251 | const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node); |
| 1252 | const result = try gz.addUnNode(.@"resume", operand, node); | 1252 | const result = try gz.addUnNode(.@"resume", operand, node); |
| 1253 | return rvalue(gz, ri, result, node); | 1253 | return rvalue(gz, ri, result, node); |
| 1254 | } | 1254 | } |
| ... | @@ -1971,6 +1971,17 @@ fn comptimeExpr( | ... | @@ -1971,6 +1971,17 @@ fn comptimeExpr( |
| 1971 | .block_two, .block_two_semicolon, .block, .block_semicolon => { | 1971 | .block_two, .block_two_semicolon, .block, .block_semicolon => { |
| 1972 | const token_tags = tree.tokens.items(.tag); | 1972 | const token_tags = tree.tokens.items(.tag); |
| 1973 | const lbrace = main_tokens[node]; | 1973 | const lbrace = main_tokens[node]; |
| 1974 | // Careful! We can't pass in the real result location here, since it may | ||
| 1975 | // refer to runtime memory. A runtime-to-comptime boundary has to remove | ||
| 1976 | // result location information, compute the result, and copy it to the true | ||
| 1977 | // result location at runtime. We do this below as well. | ||
| 1978 | const ty_only_ri: ResultInfo = .{ | ||
| 1979 | .ctx = ri.ctx, | ||
| 1980 | .rl = if (try ri.rl.resultType(gz, node)) |res_ty| | ||
| 1981 | .{ .coerced_ty = res_ty } | ||
| 1982 | else | ||
| 1983 | .none, | ||
| 1984 | }; | ||
| 1974 | if (token_tags[lbrace - 1] == .colon and | 1985 | if (token_tags[lbrace - 1] == .colon and |
| 1975 | token_tags[lbrace - 2] == .identifier) | 1986 | token_tags[lbrace - 2] == .identifier) |
| 1976 | { | 1987 | { |
| ... | @@ -1985,17 +1996,13 @@ fn comptimeExpr( | ... | @@ -1985,17 +1996,13 @@ fn comptimeExpr( |
| 1985 | else | 1996 | else |
| 1986 | stmts[0..2]; | 1997 | stmts[0..2]; |
| 1987 | 1998 | ||
| 1988 | // Careful! We can't pass in the real result location here, since it may | 1999 | const block_ref = try labeledBlockExpr(gz, scope, ty_only_ri, node, stmt_slice, true); |
| 1989 | // refer to runtime memory. A runtime-to-comptime boundary has to remove | ||
| 1990 | // result location information, compute the result, and copy it to the true | ||
| 1991 | // result location at runtime. We do this below as well. | ||
| 1992 | const block_ref = try labeledBlockExpr(gz, scope, .{ .rl = .none }, node, stmt_slice, true); | ||
| 1993 | return rvalue(gz, ri, block_ref, node); | 2000 | return rvalue(gz, ri, block_ref, node); |
| 1994 | }, | 2001 | }, |
| 1995 | .block, .block_semicolon => { | 2002 | .block, .block_semicolon => { |
| 1996 | const stmts = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; | 2003 | const stmts = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; |
| 1997 | // Replace result location and copy back later - see above. | 2004 | // Replace result location and copy back later - see above. |
| 1998 | const block_ref = try labeledBlockExpr(gz, scope, .{ .rl = .none }, node, stmts, true); | 2005 | const block_ref = try labeledBlockExpr(gz, scope, ty_only_ri, node, stmts, true); |
| 1999 | return rvalue(gz, ri, block_ref, node); | 2006 | return rvalue(gz, ri, block_ref, node); |
| 2000 | }, | 2007 | }, |
| 2001 | else => unreachable, | 2008 | else => unreachable, |
| ... | @@ -2013,7 +2020,14 @@ fn comptimeExpr( | ... | @@ -2013,7 +2020,14 @@ fn comptimeExpr( |
| 2013 | 2020 | ||
| 2014 | const block_inst = try gz.makeBlockInst(.block_comptime, node); | 2021 | const block_inst = try gz.makeBlockInst(.block_comptime, node); |
| 2015 | // Replace result location and copy back later - see above. | 2022 | // Replace result location and copy back later - see above. |
| 2016 | const block_result = try expr(&block_scope, scope, .{ .rl = .none }, node); | 2023 | const ty_only_ri: ResultInfo = .{ |
| 2024 | .ctx = ri.ctx, | ||
| 2025 | .rl = if (try ri.rl.resultType(gz, node)) |res_ty| | ||
| 2026 | .{ .coerced_ty = res_ty } | ||
| 2027 | else | ||
| 2028 | .none, | ||
| 2029 | }; | ||
| 2030 | const block_result = try expr(&block_scope, scope, ty_only_ri, node); | ||
| 2017 | if (!gz.refIsNoReturn(block_result)) { | 2031 | if (!gz.refIsNoReturn(block_result)) { |
| 2018 | _ = try block_scope.addBreak(.@"break", block_inst, block_result); | 2032 | _ = try block_scope.addBreak(.@"break", block_inst, block_result); |
| 2019 | } | 2033 | } |
| ... | @@ -2941,11 +2955,19 @@ fn checkUsed(gz: *GenZir, outer_scope: *Scope, inner_scope: *Scope) InnerError!v | ... | @@ -2941,11 +2955,19 @@ fn checkUsed(gz: *GenZir, outer_scope: *Scope, inner_scope: *Scope) InnerError!v |
| 2941 | const s = scope.cast(Scope.LocalPtr).?; | 2955 | const s = scope.cast(Scope.LocalPtr).?; |
| 2942 | if (s.used == 0 and s.discarded == 0) { | 2956 | if (s.used == 0 and s.discarded == 0) { |
| 2943 | try astgen.appendErrorTok(s.token_src, "unused {s}", .{@tagName(s.id_cat)}); | 2957 | try astgen.appendErrorTok(s.token_src, "unused {s}", .{@tagName(s.id_cat)}); |
| 2944 | } else if (s.used != 0 and s.discarded != 0) { | 2958 | } else { |
| 2945 | try astgen.appendErrorTokNotes(s.discarded, "pointless discard of {s}", .{@tagName(s.id_cat)}, &[_]u32{ | 2959 | if (s.used != 0 and s.discarded != 0) { |
| 2946 | try gz.astgen.errNoteTok(s.used, "used here", .{}), | 2960 | try astgen.appendErrorTokNotes(s.discarded, "pointless discard of {s}", .{@tagName(s.id_cat)}, &[_]u32{ |
| 2947 | }); | 2961 | try astgen.errNoteTok(s.used, "used here", .{}), |
| 2962 | }); | ||
| 2963 | } | ||
| 2964 | if (s.id_cat == .@"local variable" and !s.used_as_lvalue) { | ||
| 2965 | try astgen.appendErrorTokNotes(s.token_src, "local variable is never mutated", .{}, &.{ | ||
| 2966 | try astgen.errNoteTok(s.token_src, "consider using 'const'", .{}), | ||
| 2967 | }); | ||
| 2968 | } | ||
| 2948 | } | 2969 | } |
| 2970 | |||
| 2949 | scope = s.parent; | 2971 | scope = s.parent; |
| 2950 | }, | 2972 | }, |
| 2951 | .defer_normal, .defer_error => scope = scope.cast(Scope.Defer).?.parent, | 2973 | .defer_normal, .defer_error => scope = scope.cast(Scope.Defer).?.parent, |
| ... | @@ -6699,7 +6721,7 @@ fn forExpr( | ... | @@ -6699,7 +6721,7 @@ fn forExpr( |
| 6699 | }; | 6721 | }; |
| 6700 | } | 6722 | } |
| 6701 | 6723 | ||
| 6702 | var then_node = for_full.ast.then_expr; | 6724 | const then_node = for_full.ast.then_expr; |
| 6703 | var then_scope = parent_gz.makeSubBlock(&cond_scope.base); | 6725 | var then_scope = parent_gz.makeSubBlock(&cond_scope.base); |
| 6704 | defer then_scope.unstack(); | 6726 | defer then_scope.unstack(); |
| 6705 | 6727 | ||
| ... | @@ -7579,7 +7601,10 @@ fn localVarRef( | ... | @@ -7579,7 +7601,10 @@ fn localVarRef( |
| 7579 | ); | 7601 | ); |
| 7580 | 7602 | ||
| 7581 | switch (ri.rl) { | 7603 | switch (ri.rl) { |
| 7582 | .ref, .ref_coerced_ty => return ptr_inst, | 7604 | .ref, .ref_coerced_ty => { |
| 7605 | local_ptr.used_as_lvalue = true; | ||
| 7606 | return ptr_inst; | ||
| 7607 | }, | ||
| 7583 | else => { | 7608 | else => { |
| 7584 | const loaded = try gz.addUnNode(.load, ptr_inst, ident); | 7609 | const loaded = try gz.addUnNode(.load, ptr_inst, ident); |
| 7585 | return rvalueNoCoercePreRef(gz, ri, loaded, ident); | 7610 | return rvalueNoCoercePreRef(gz, ri, loaded, ident); |
| ... | @@ -8149,7 +8174,7 @@ fn typeOf( | ... | @@ -8149,7 +8174,7 @@ fn typeOf( |
| 8149 | } | 8174 | } |
| 8150 | const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len; | 8175 | const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len; |
| 8151 | const payload_index = try reserveExtra(astgen, payload_size + args.len); | 8176 | const payload_index = try reserveExtra(astgen, payload_size + args.len); |
| 8152 | var args_index = payload_index + payload_size; | 8177 | const args_index = payload_index + payload_size; |
| 8153 | 8178 | ||
| 8154 | const typeof_inst = try gz.addExtendedMultiOpPayloadIndex(.typeof_peer, payload_index, args.len); | 8179 | const typeof_inst = try gz.addExtendedMultiOpPayloadIndex(.typeof_peer, payload_index, args.len); |
| 8155 | 8180 | ||
| ... | @@ -10948,6 +10973,9 @@ const Scope = struct { | ... | @@ -10948,6 +10973,9 @@ const Scope = struct { |
| 10948 | /// Track the identifier where it is discarded, like this `_ = foo;`. | 10973 | /// Track the identifier where it is discarded, like this `_ = foo;`. |
| 10949 | /// 0 means never discarded. | 10974 | /// 0 means never discarded. |
| 10950 | discarded: Ast.TokenIndex = 0, | 10975 | discarded: Ast.TokenIndex = 0, |
| 10976 | /// Whether this value is used as an lvalue after inititialization. | ||
| 10977 | /// If not, we know it can be `const`, so will emit a compile error if it is `var`. | ||
| 10978 | used_as_lvalue: bool = false, | ||
| 10951 | /// String table index. | 10979 | /// String table index. |
| 10952 | name: u32, | 10980 | name: u32, |
| 10953 | id_cat: IdCat, | 10981 | id_cat: IdCat, |
src/Autodoc.zig+50-50| ... | @@ -985,7 +985,7 @@ fn walkInstruction( | ... | @@ -985,7 +985,7 @@ fn walkInstruction( |
| 985 | }, | 985 | }, |
| 986 | .import => { | 986 | .import => { |
| 987 | const str_tok = data[@intFromEnum(inst)].str_tok; | 987 | const str_tok = data[@intFromEnum(inst)].str_tok; |
| 988 | var path = str_tok.get(file.zir); | 988 | const path = str_tok.get(file.zir); |
| 989 | 989 | ||
| 990 | // importFile cannot error out since all files | 990 | // importFile cannot error out since all files |
| 991 | // are already loaded at this point | 991 | // are already loaded at this point |
| ... | @@ -1210,7 +1210,7 @@ fn walkInstruction( | ... | @@ -1210,7 +1210,7 @@ fn walkInstruction( |
| 1210 | .compile_error => { | 1210 | .compile_error => { |
| 1211 | const un_node = data[@intFromEnum(inst)].un_node; | 1211 | const un_node = data[@intFromEnum(inst)].un_node; |
| 1212 | 1212 | ||
| 1213 | var operand: DocData.WalkResult = try self.walkRef( | 1213 | const operand: DocData.WalkResult = try self.walkRef( |
| 1214 | file, | 1214 | file, |
| 1215 | parent_scope, | 1215 | parent_scope, |
| 1216 | parent_src, | 1216 | parent_src, |
| ... | @@ -1252,7 +1252,7 @@ fn walkInstruction( | ... | @@ -1252,7 +1252,7 @@ fn walkInstruction( |
| 1252 | const byte_count = str.len * @sizeOf(std.math.big.Limb); | 1252 | const byte_count = str.len * @sizeOf(std.math.big.Limb); |
| 1253 | const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count]; | 1253 | const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count]; |
| 1254 | 1254 | ||
| 1255 | var limbs = try self.arena.alloc(std.math.big.Limb, str.len); | 1255 | const limbs = try self.arena.alloc(std.math.big.Limb, str.len); |
| 1256 | @memcpy(std.mem.sliceAsBytes(limbs)[0..limb_bytes.len], limb_bytes); | 1256 | @memcpy(std.mem.sliceAsBytes(limbs)[0..limb_bytes.len], limb_bytes); |
| 1257 | 1257 | ||
| 1258 | const big_int = std.math.big.int.Const{ | 1258 | const big_int = std.math.big.int.Const{ |
| ... | @@ -1281,7 +1281,7 @@ fn walkInstruction( | ... | @@ -1281,7 +1281,7 @@ fn walkInstruction( |
| 1281 | const slice_index = self.exprs.items.len; | 1281 | const slice_index = self.exprs.items.len; |
| 1282 | try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); | 1282 | try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); |
| 1283 | 1283 | ||
| 1284 | var lhs: DocData.WalkResult = try self.walkRef( | 1284 | const lhs: DocData.WalkResult = try self.walkRef( |
| 1285 | file, | 1285 | file, |
| 1286 | parent_scope, | 1286 | parent_scope, |
| 1287 | parent_src, | 1287 | parent_src, |
| ... | @@ -1289,7 +1289,7 @@ fn walkInstruction( | ... | @@ -1289,7 +1289,7 @@ fn walkInstruction( |
| 1289 | false, | 1289 | false, |
| 1290 | call_ctx, | 1290 | call_ctx, |
| 1291 | ); | 1291 | ); |
| 1292 | var start: DocData.WalkResult = try self.walkRef( | 1292 | const start: DocData.WalkResult = try self.walkRef( |
| 1293 | file, | 1293 | file, |
| 1294 | parent_scope, | 1294 | parent_scope, |
| 1295 | parent_src, | 1295 | parent_src, |
| ... | @@ -1321,7 +1321,7 @@ fn walkInstruction( | ... | @@ -1321,7 +1321,7 @@ fn walkInstruction( |
| 1321 | const slice_index = self.exprs.items.len; | 1321 | const slice_index = self.exprs.items.len; |
| 1322 | try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); | 1322 | try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); |
| 1323 | 1323 | ||
| 1324 | var lhs: DocData.WalkResult = try self.walkRef( | 1324 | const lhs: DocData.WalkResult = try self.walkRef( |
| 1325 | file, | 1325 | file, |
| 1326 | parent_scope, | 1326 | parent_scope, |
| 1327 | parent_src, | 1327 | parent_src, |
| ... | @@ -1329,7 +1329,7 @@ fn walkInstruction( | ... | @@ -1329,7 +1329,7 @@ fn walkInstruction( |
| 1329 | false, | 1329 | false, |
| 1330 | call_ctx, | 1330 | call_ctx, |
| 1331 | ); | 1331 | ); |
| 1332 | var start: DocData.WalkResult = try self.walkRef( | 1332 | const start: DocData.WalkResult = try self.walkRef( |
| 1333 | file, | 1333 | file, |
| 1334 | parent_scope, | 1334 | parent_scope, |
| 1335 | parent_src, | 1335 | parent_src, |
| ... | @@ -1337,7 +1337,7 @@ fn walkInstruction( | ... | @@ -1337,7 +1337,7 @@ fn walkInstruction( |
| 1337 | false, | 1337 | false, |
| 1338 | call_ctx, | 1338 | call_ctx, |
| 1339 | ); | 1339 | ); |
| 1340 | var end: DocData.WalkResult = try self.walkRef( | 1340 | const end: DocData.WalkResult = try self.walkRef( |
| 1341 | file, | 1341 | file, |
| 1342 | parent_scope, | 1342 | parent_scope, |
| 1343 | parent_src, | 1343 | parent_src, |
| ... | @@ -1371,7 +1371,7 @@ fn walkInstruction( | ... | @@ -1371,7 +1371,7 @@ fn walkInstruction( |
| 1371 | const slice_index = self.exprs.items.len; | 1371 | const slice_index = self.exprs.items.len; |
| 1372 | try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); | 1372 | try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); |
| 1373 | 1373 | ||
| 1374 | var lhs: DocData.WalkResult = try self.walkRef( | 1374 | const lhs: DocData.WalkResult = try self.walkRef( |
| 1375 | file, | 1375 | file, |
| 1376 | parent_scope, | 1376 | parent_scope, |
| 1377 | parent_src, | 1377 | parent_src, |
| ... | @@ -1379,7 +1379,7 @@ fn walkInstruction( | ... | @@ -1379,7 +1379,7 @@ fn walkInstruction( |
| 1379 | false, | 1379 | false, |
| 1380 | call_ctx, | 1380 | call_ctx, |
| 1381 | ); | 1381 | ); |
| 1382 | var start: DocData.WalkResult = try self.walkRef( | 1382 | const start: DocData.WalkResult = try self.walkRef( |
| 1383 | file, | 1383 | file, |
| 1384 | parent_scope, | 1384 | parent_scope, |
| 1385 | parent_src, | 1385 | parent_src, |
| ... | @@ -1387,7 +1387,7 @@ fn walkInstruction( | ... | @@ -1387,7 +1387,7 @@ fn walkInstruction( |
| 1387 | false, | 1387 | false, |
| 1388 | call_ctx, | 1388 | call_ctx, |
| 1389 | ); | 1389 | ); |
| 1390 | var end: DocData.WalkResult = try self.walkRef( | 1390 | const end: DocData.WalkResult = try self.walkRef( |
| 1391 | file, | 1391 | file, |
| 1392 | parent_scope, | 1392 | parent_scope, |
| 1393 | parent_src, | 1393 | parent_src, |
| ... | @@ -1395,7 +1395,7 @@ fn walkInstruction( | ... | @@ -1395,7 +1395,7 @@ fn walkInstruction( |
| 1395 | false, | 1395 | false, |
| 1396 | call_ctx, | 1396 | call_ctx, |
| 1397 | ); | 1397 | ); |
| 1398 | var sentinel: DocData.WalkResult = try self.walkRef( | 1398 | const sentinel: DocData.WalkResult = try self.walkRef( |
| 1399 | file, | 1399 | file, |
| 1400 | parent_scope, | 1400 | parent_scope, |
| 1401 | parent_src, | 1401 | parent_src, |
| ... | @@ -1436,7 +1436,7 @@ fn walkInstruction( | ... | @@ -1436,7 +1436,7 @@ fn walkInstruction( |
| 1436 | const slice_index = self.exprs.items.len; | 1436 | const slice_index = self.exprs.items.len; |
| 1437 | try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); | 1437 | try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); |
| 1438 | 1438 | ||
| 1439 | var lhs: DocData.WalkResult = try self.walkRef( | 1439 | const lhs: DocData.WalkResult = try self.walkRef( |
| 1440 | file, | 1440 | file, |
| 1441 | parent_scope, | 1441 | parent_scope, |
| 1442 | parent_src, | 1442 | parent_src, |
| ... | @@ -1444,7 +1444,7 @@ fn walkInstruction( | ... | @@ -1444,7 +1444,7 @@ fn walkInstruction( |
| 1444 | false, | 1444 | false, |
| 1445 | call_ctx, | 1445 | call_ctx, |
| 1446 | ); | 1446 | ); |
| 1447 | var start: DocData.WalkResult = try self.walkRef( | 1447 | const start: DocData.WalkResult = try self.walkRef( |
| 1448 | file, | 1448 | file, |
| 1449 | parent_scope, | 1449 | parent_scope, |
| 1450 | parent_src, | 1450 | parent_src, |
| ... | @@ -1452,7 +1452,7 @@ fn walkInstruction( | ... | @@ -1452,7 +1452,7 @@ fn walkInstruction( |
| 1452 | false, | 1452 | false, |
| 1453 | call_ctx, | 1453 | call_ctx, |
| 1454 | ); | 1454 | ); |
| 1455 | var len: DocData.WalkResult = try self.walkRef( | 1455 | const len: DocData.WalkResult = try self.walkRef( |
| 1456 | file, | 1456 | file, |
| 1457 | parent_scope, | 1457 | parent_scope, |
| 1458 | parent_src, | 1458 | parent_src, |
| ... | @@ -1460,7 +1460,7 @@ fn walkInstruction( | ... | @@ -1460,7 +1460,7 @@ fn walkInstruction( |
| 1460 | false, | 1460 | false, |
| 1461 | call_ctx, | 1461 | call_ctx, |
| 1462 | ); | 1462 | ); |
| 1463 | var sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none) | 1463 | const sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none) |
| 1464 | try self.walkRef( | 1464 | try self.walkRef( |
| 1465 | file, | 1465 | file, |
| 1466 | parent_scope, | 1466 | parent_scope, |
| ... | @@ -1574,7 +1574,7 @@ fn walkInstruction( | ... | @@ -1574,7 +1574,7 @@ fn walkInstruction( |
| 1574 | const binop_index = self.exprs.items.len; | 1574 | const binop_index = self.exprs.items.len; |
| 1575 | try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); | 1575 | try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); |
| 1576 | 1576 | ||
| 1577 | var lhs: DocData.WalkResult = try self.walkRef( | 1577 | const lhs: DocData.WalkResult = try self.walkRef( |
| 1578 | file, | 1578 | file, |
| 1579 | parent_scope, | 1579 | parent_scope, |
| 1580 | parent_src, | 1580 | parent_src, |
| ... | @@ -1582,7 +1582,7 @@ fn walkInstruction( | ... | @@ -1582,7 +1582,7 @@ fn walkInstruction( |
| 1582 | false, | 1582 | false, |
| 1583 | call_ctx, | 1583 | call_ctx, |
| 1584 | ); | 1584 | ); |
| 1585 | var rhs: DocData.WalkResult = try self.walkRef( | 1585 | const rhs: DocData.WalkResult = try self.walkRef( |
| 1586 | file, | 1586 | file, |
| 1587 | parent_scope, | 1587 | parent_scope, |
| 1588 | parent_src, | 1588 | parent_src, |
| ... | @@ -1620,7 +1620,7 @@ fn walkInstruction( | ... | @@ -1620,7 +1620,7 @@ fn walkInstruction( |
| 1620 | const binop_index = self.exprs.items.len; | 1620 | const binop_index = self.exprs.items.len; |
| 1621 | try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); | 1621 | try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); |
| 1622 | 1622 | ||
| 1623 | var lhs: DocData.WalkResult = try self.walkRef( | 1623 | const lhs: DocData.WalkResult = try self.walkRef( |
| 1624 | file, | 1624 | file, |
| 1625 | parent_scope, | 1625 | parent_scope, |
| 1626 | parent_src, | 1626 | parent_src, |
| ... | @@ -1628,7 +1628,7 @@ fn walkInstruction( | ... | @@ -1628,7 +1628,7 @@ fn walkInstruction( |
| 1628 | false, | 1628 | false, |
| 1629 | call_ctx, | 1629 | call_ctx, |
| 1630 | ); | 1630 | ); |
| 1631 | var rhs: DocData.WalkResult = try self.walkRef( | 1631 | const rhs: DocData.WalkResult = try self.walkRef( |
| 1632 | file, | 1632 | file, |
| 1633 | parent_scope, | 1633 | parent_scope, |
| 1634 | parent_src, | 1634 | parent_src, |
| ... | @@ -1786,7 +1786,7 @@ fn walkInstruction( | ... | @@ -1786,7 +1786,7 @@ fn walkInstruction( |
| 1786 | const pl_node = data[@intFromEnum(inst)].pl_node; | 1786 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1787 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 1787 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1788 | 1788 | ||
| 1789 | var rhs: DocData.WalkResult = try self.walkRef( | 1789 | const rhs: DocData.WalkResult = try self.walkRef( |
| 1790 | file, | 1790 | file, |
| 1791 | parent_scope, | 1791 | parent_scope, |
| 1792 | parent_src, | 1792 | parent_src, |
| ... | @@ -1801,7 +1801,7 @@ fn walkInstruction( | ... | @@ -1801,7 +1801,7 @@ fn walkInstruction( |
| 1801 | const rhs_index = self.exprs.items.len; | 1801 | const rhs_index = self.exprs.items.len; |
| 1802 | try self.exprs.append(self.arena, rhs.expr); | 1802 | try self.exprs.append(self.arena, rhs.expr); |
| 1803 | 1803 | ||
| 1804 | var lhs: DocData.WalkResult = try self.walkRef( | 1804 | const lhs: DocData.WalkResult = try self.walkRef( |
| 1805 | file, | 1805 | file, |
| 1806 | parent_scope, | 1806 | parent_scope, |
| 1807 | parent_src, | 1807 | parent_src, |
| ... | @@ -1850,7 +1850,7 @@ fn walkInstruction( | ... | @@ -1850,7 +1850,7 @@ fn walkInstruction( |
| 1850 | const binop_index = self.exprs.items.len; | 1850 | const binop_index = self.exprs.items.len; |
| 1851 | try self.exprs.append(self.arena, .{ .builtinBin = .{ .lhs = 0, .rhs = 0 } }); | 1851 | try self.exprs.append(self.arena, .{ .builtinBin = .{ .lhs = 0, .rhs = 0 } }); |
| 1852 | 1852 | ||
| 1853 | var lhs: DocData.WalkResult = try self.walkRef( | 1853 | const lhs: DocData.WalkResult = try self.walkRef( |
| 1854 | file, | 1854 | file, |
| 1855 | parent_scope, | 1855 | parent_scope, |
| 1856 | parent_src, | 1856 | parent_src, |
| ... | @@ -1858,7 +1858,7 @@ fn walkInstruction( | ... | @@ -1858,7 +1858,7 @@ fn walkInstruction( |
| 1858 | false, | 1858 | false, |
| 1859 | call_ctx, | 1859 | call_ctx, |
| 1860 | ); | 1860 | ); |
| 1861 | var rhs: DocData.WalkResult = try self.walkRef( | 1861 | const rhs: DocData.WalkResult = try self.walkRef( |
| 1862 | file, | 1862 | file, |
| 1863 | parent_scope, | 1863 | parent_scope, |
| 1864 | parent_src, | 1864 | parent_src, |
| ... | @@ -1882,7 +1882,7 @@ fn walkInstruction( | ... | @@ -1882,7 +1882,7 @@ fn walkInstruction( |
| 1882 | const pl_node = data[@intFromEnum(inst)].pl_node; | 1882 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1883 | const extra = file.zir.extraData(Zir.Inst.MulAdd, pl_node.payload_index); | 1883 | const extra = file.zir.extraData(Zir.Inst.MulAdd, pl_node.payload_index); |
| 1884 | 1884 | ||
| 1885 | var mul1: DocData.WalkResult = try self.walkRef( | 1885 | const mul1: DocData.WalkResult = try self.walkRef( |
| 1886 | file, | 1886 | file, |
| 1887 | parent_scope, | 1887 | parent_scope, |
| 1888 | parent_src, | 1888 | parent_src, |
| ... | @@ -1890,7 +1890,7 @@ fn walkInstruction( | ... | @@ -1890,7 +1890,7 @@ fn walkInstruction( |
| 1890 | false, | 1890 | false, |
| 1891 | call_ctx, | 1891 | call_ctx, |
| 1892 | ); | 1892 | ); |
| 1893 | var mul2: DocData.WalkResult = try self.walkRef( | 1893 | const mul2: DocData.WalkResult = try self.walkRef( |
| 1894 | file, | 1894 | file, |
| 1895 | parent_scope, | 1895 | parent_scope, |
| 1896 | parent_src, | 1896 | parent_src, |
| ... | @@ -1898,7 +1898,7 @@ fn walkInstruction( | ... | @@ -1898,7 +1898,7 @@ fn walkInstruction( |
| 1898 | false, | 1898 | false, |
| 1899 | call_ctx, | 1899 | call_ctx, |
| 1900 | ); | 1900 | ); |
| 1901 | var add: DocData.WalkResult = try self.walkRef( | 1901 | const add: DocData.WalkResult = try self.walkRef( |
| 1902 | file, | 1902 | file, |
| 1903 | parent_scope, | 1903 | parent_scope, |
| 1904 | parent_src, | 1904 | parent_src, |
| ... | @@ -1914,7 +1914,7 @@ fn walkInstruction( | ... | @@ -1914,7 +1914,7 @@ fn walkInstruction( |
| 1914 | const add_index = self.exprs.items.len; | 1914 | const add_index = self.exprs.items.len; |
| 1915 | try self.exprs.append(self.arena, add.expr); | 1915 | try self.exprs.append(self.arena, add.expr); |
| 1916 | 1916 | ||
| 1917 | var type_index: usize = self.exprs.items.len; | 1917 | const type_index: usize = self.exprs.items.len; |
| 1918 | try self.exprs.append(self.arena, add.typeRef orelse .{ .type = @intFromEnum(Ref.type_type) }); | 1918 | try self.exprs.append(self.arena, add.typeRef orelse .{ .type = @intFromEnum(Ref.type_type) }); |
| 1919 | 1919 | ||
| 1920 | return DocData.WalkResult{ | 1920 | return DocData.WalkResult{ |
| ... | @@ -1933,7 +1933,7 @@ fn walkInstruction( | ... | @@ -1933,7 +1933,7 @@ fn walkInstruction( |
| 1933 | const pl_node = data[@intFromEnum(inst)].pl_node; | 1933 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1934 | const extra = file.zir.extraData(Zir.Inst.UnionInit, pl_node.payload_index); | 1934 | const extra = file.zir.extraData(Zir.Inst.UnionInit, pl_node.payload_index); |
| 1935 | 1935 | ||
| 1936 | var union_type: DocData.WalkResult = try self.walkRef( | 1936 | const union_type: DocData.WalkResult = try self.walkRef( |
| 1937 | file, | 1937 | file, |
| 1938 | parent_scope, | 1938 | parent_scope, |
| 1939 | parent_src, | 1939 | parent_src, |
| ... | @@ -1941,7 +1941,7 @@ fn walkInstruction( | ... | @@ -1941,7 +1941,7 @@ fn walkInstruction( |
| 1941 | false, | 1941 | false, |
| 1942 | call_ctx, | 1942 | call_ctx, |
| 1943 | ); | 1943 | ); |
| 1944 | var field_name: DocData.WalkResult = try self.walkRef( | 1944 | const field_name: DocData.WalkResult = try self.walkRef( |
| 1945 | file, | 1945 | file, |
| 1946 | parent_scope, | 1946 | parent_scope, |
| 1947 | parent_src, | 1947 | parent_src, |
| ... | @@ -1949,7 +1949,7 @@ fn walkInstruction( | ... | @@ -1949,7 +1949,7 @@ fn walkInstruction( |
| 1949 | false, | 1949 | false, |
| 1950 | call_ctx, | 1950 | call_ctx, |
| 1951 | ); | 1951 | ); |
| 1952 | var init: DocData.WalkResult = try self.walkRef( | 1952 | const init: DocData.WalkResult = try self.walkRef( |
| 1953 | file, | 1953 | file, |
| 1954 | parent_scope, | 1954 | parent_scope, |
| 1955 | parent_src, | 1955 | parent_src, |
| ... | @@ -1980,7 +1980,7 @@ fn walkInstruction( | ... | @@ -1980,7 +1980,7 @@ fn walkInstruction( |
| 1980 | const pl_node = data[@intFromEnum(inst)].pl_node; | 1980 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1981 | const extra = file.zir.extraData(Zir.Inst.BuiltinCall, pl_node.payload_index); | 1981 | const extra = file.zir.extraData(Zir.Inst.BuiltinCall, pl_node.payload_index); |
| 1982 | 1982 | ||
| 1983 | var modifier: DocData.WalkResult = try self.walkRef( | 1983 | const modifier: DocData.WalkResult = try self.walkRef( |
| 1984 | file, | 1984 | file, |
| 1985 | parent_scope, | 1985 | parent_scope, |
| 1986 | parent_src, | 1986 | parent_src, |
| ... | @@ -1989,7 +1989,7 @@ fn walkInstruction( | ... | @@ -1989,7 +1989,7 @@ fn walkInstruction( |
| 1989 | call_ctx, | 1989 | call_ctx, |
| 1990 | ); | 1990 | ); |
| 1991 | 1991 | ||
| 1992 | var callee: DocData.WalkResult = try self.walkRef( | 1992 | const callee: DocData.WalkResult = try self.walkRef( |
| 1993 | file, | 1993 | file, |
| 1994 | parent_scope, | 1994 | parent_scope, |
| 1995 | parent_src, | 1995 | parent_src, |
| ... | @@ -1998,7 +1998,7 @@ fn walkInstruction( | ... | @@ -1998,7 +1998,7 @@ fn walkInstruction( |
| 1998 | call_ctx, | 1998 | call_ctx, |
| 1999 | ); | 1999 | ); |
| 2000 | 2000 | ||
| 2001 | var args: DocData.WalkResult = try self.walkRef( | 2001 | const args: DocData.WalkResult = try self.walkRef( |
| 2002 | file, | 2002 | file, |
| 2003 | parent_scope, | 2003 | parent_scope, |
| 2004 | parent_src, | 2004 | parent_src, |
| ... | @@ -2028,7 +2028,7 @@ fn walkInstruction( | ... | @@ -2028,7 +2028,7 @@ fn walkInstruction( |
| 2028 | const pl_node = data[@intFromEnum(inst)].pl_node; | 2028 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2029 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 2029 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 2030 | 2030 | ||
| 2031 | var lhs: DocData.WalkResult = try self.walkRef( | 2031 | const lhs: DocData.WalkResult = try self.walkRef( |
| 2032 | file, | 2032 | file, |
| 2033 | parent_scope, | 2033 | parent_scope, |
| 2034 | parent_src, | 2034 | parent_src, |
| ... | @@ -2036,7 +2036,7 @@ fn walkInstruction( | ... | @@ -2036,7 +2036,7 @@ fn walkInstruction( |
| 2036 | false, | 2036 | false, |
| 2037 | call_ctx, | 2037 | call_ctx, |
| 2038 | ); | 2038 | ); |
| 2039 | var rhs: DocData.WalkResult = try self.walkRef( | 2039 | const rhs: DocData.WalkResult = try self.walkRef( |
| 2040 | file, | 2040 | file, |
| 2041 | parent_scope, | 2041 | parent_scope, |
| 2042 | parent_src, | 2042 | parent_src, |
| ... | @@ -2060,7 +2060,7 @@ fn walkInstruction( | ... | @@ -2060,7 +2060,7 @@ fn walkInstruction( |
| 2060 | const pl_node = data[@intFromEnum(inst)].pl_node; | 2060 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2061 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 2061 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 2062 | 2062 | ||
| 2063 | var lhs: DocData.WalkResult = try self.walkRef( | 2063 | const lhs: DocData.WalkResult = try self.walkRef( |
| 2064 | file, | 2064 | file, |
| 2065 | parent_scope, | 2065 | parent_scope, |
| 2066 | parent_src, | 2066 | parent_src, |
| ... | @@ -2068,7 +2068,7 @@ fn walkInstruction( | ... | @@ -2068,7 +2068,7 @@ fn walkInstruction( |
| 2068 | false, | 2068 | false, |
| 2069 | call_ctx, | 2069 | call_ctx, |
| 2070 | ); | 2070 | ); |
| 2071 | var rhs: DocData.WalkResult = try self.walkRef( | 2071 | const rhs: DocData.WalkResult = try self.walkRef( |
| 2072 | file, | 2072 | file, |
| 2073 | parent_scope, | 2073 | parent_scope, |
| 2074 | parent_src, | 2074 | parent_src, |
| ... | @@ -2090,7 +2090,7 @@ fn walkInstruction( | ... | @@ -2090,7 +2090,7 @@ fn walkInstruction( |
| 2090 | // .elem_type => { | 2090 | // .elem_type => { |
| 2091 | // const un_node = data[@intFromEnum(inst)].un_node; | 2091 | // const un_node = data[@intFromEnum(inst)].un_node; |
| 2092 | 2092 | ||
| 2093 | // var operand: DocData.WalkResult = try self.walkRef( | 2093 | // const operand: DocData.WalkResult = try self.walkRef( |
| 2094 | // file, | 2094 | // file, |
| 2095 | // parent_scope, parent_src, | 2095 | // parent_scope, parent_src, |
| 2096 | // un_node.operand, | 2096 | // un_node.operand, |
| ... | @@ -2158,7 +2158,7 @@ fn walkInstruction( | ... | @@ -2158,7 +2158,7 @@ fn walkInstruction( |
| 2158 | address_space = ref_result.expr; | 2158 | address_space = ref_result.expr; |
| 2159 | extra_index += 1; | 2159 | extra_index += 1; |
| 2160 | } | 2160 | } |
| 2161 | var bit_start: ?DocData.Expr = null; | 2161 | const bit_start: ?DocData.Expr = null; |
| 2162 | if (ptr.flags.has_bit_range) { | 2162 | if (ptr.flags.has_bit_range) { |
| 2163 | const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index])); | 2163 | const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index])); |
| 2164 | const ref_result = try self.walkRef( | 2164 | const ref_result = try self.walkRef( |
| ... | @@ -2292,7 +2292,7 @@ fn walkInstruction( | ... | @@ -2292,7 +2292,7 @@ fn walkInstruction( |
| 2292 | const array_data = try self.arena.alloc(usize, operands.len - 1); | 2292 | const array_data = try self.arena.alloc(usize, operands.len - 1); |
| 2293 | 2293 | ||
| 2294 | std.debug.assert(operands.len > 0); | 2294 | std.debug.assert(operands.len > 0); |
| 2295 | var array_type = try self.walkRef( | 2295 | const array_type = try self.walkRef( |
| 2296 | file, | 2296 | file, |
| 2297 | parent_scope, | 2297 | parent_scope, |
| 2298 | parent_src, | 2298 | parent_src, |
| ... | @@ -2352,7 +2352,7 @@ fn walkInstruction( | ... | @@ -2352,7 +2352,7 @@ fn walkInstruction( |
| 2352 | const array_data = try self.arena.alloc(usize, operands.len - 1); | 2352 | const array_data = try self.arena.alloc(usize, operands.len - 1); |
| 2353 | 2353 | ||
| 2354 | std.debug.assert(operands.len > 0); | 2354 | std.debug.assert(operands.len > 0); |
| 2355 | var array_type = try self.walkRef( | 2355 | const array_type = try self.walkRef( |
| 2356 | file, | 2356 | file, |
| 2357 | parent_scope, | 2357 | parent_scope, |
| 2358 | parent_src, | 2358 | parent_src, |
| ... | @@ -2578,7 +2578,7 @@ fn walkInstruction( | ... | @@ -2578,7 +2578,7 @@ fn walkInstruction( |
| 2578 | const pl_node = data[@intFromEnum(inst)].pl_node; | 2578 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2579 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); | 2579 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 2580 | const body = file.zir.extra[extra.end..][extra.data.body_len - 1]; | 2580 | const body = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 2581 | var operand: DocData.WalkResult = try self.walkRef( | 2581 | const operand: DocData.WalkResult = try self.walkRef( |
| 2582 | file, | 2582 | file, |
| 2583 | parent_scope, | 2583 | parent_scope, |
| 2584 | parent_src, | 2584 | parent_src, |
| ... | @@ -2903,7 +2903,7 @@ fn walkInstruction( | ... | @@ -2903,7 +2903,7 @@ fn walkInstruction( |
| 2903 | => { | 2903 | => { |
| 2904 | const un_node = data[@intFromEnum(inst)].un_node; | 2904 | const un_node = data[@intFromEnum(inst)].un_node; |
| 2905 | 2905 | ||
| 2906 | var operand: DocData.WalkResult = try self.walkRef( | 2906 | const operand: DocData.WalkResult = try self.walkRef( |
| 2907 | file, | 2907 | file, |
| 2908 | parent_scope, | 2908 | parent_scope, |
| 2909 | parent_src, | 2909 | parent_src, |
| ... | @@ -2920,7 +2920,7 @@ fn walkInstruction( | ... | @@ -2920,7 +2920,7 @@ fn walkInstruction( |
| 2920 | .struct_init_empty_ref_result => { | 2920 | .struct_init_empty_ref_result => { |
| 2921 | const un_node = data[@intFromEnum(inst)].un_node; | 2921 | const un_node = data[@intFromEnum(inst)].un_node; |
| 2922 | 2922 | ||
| 2923 | var operand: DocData.WalkResult = try self.walkRef( | 2923 | const operand: DocData.WalkResult = try self.walkRef( |
| 2924 | file, | 2924 | file, |
| 2925 | parent_scope, | 2925 | parent_scope, |
| 2926 | parent_src, | 2926 | parent_src, |
| ... | @@ -3937,7 +3937,7 @@ fn walkInstruction( | ... | @@ -3937,7 +3937,7 @@ fn walkInstruction( |
| 3937 | try self.exprs.append(self.arena, last_type); | 3937 | try self.exprs.append(self.arena, last_type); |
| 3938 | 3938 | ||
| 3939 | const ptr_index = self.exprs.items.len; | 3939 | const ptr_index = self.exprs.items.len; |
| 3940 | var ptr: DocData.WalkResult = try self.walkRef( | 3940 | const ptr: DocData.WalkResult = try self.walkRef( |
| 3941 | file, | 3941 | file, |
| 3942 | parent_scope, | 3942 | parent_scope, |
| 3943 | parent_src, | 3943 | parent_src, |
| ... | @@ -3948,7 +3948,7 @@ fn walkInstruction( | ... | @@ -3948,7 +3948,7 @@ fn walkInstruction( |
| 3948 | try self.exprs.append(self.arena, ptr.expr); | 3948 | try self.exprs.append(self.arena, ptr.expr); |
| 3949 | 3949 | ||
| 3950 | const expected_value_index = self.exprs.items.len; | 3950 | const expected_value_index = self.exprs.items.len; |
| 3951 | var expected_value: DocData.WalkResult = try self.walkRef( | 3951 | const expected_value: DocData.WalkResult = try self.walkRef( |
| 3952 | file, | 3952 | file, |
| 3953 | parent_scope, | 3953 | parent_scope, |
| 3954 | parent_src, | 3954 | parent_src, |
| ... | @@ -3959,7 +3959,7 @@ fn walkInstruction( | ... | @@ -3959,7 +3959,7 @@ fn walkInstruction( |
| 3959 | try self.exprs.append(self.arena, expected_value.expr); | 3959 | try self.exprs.append(self.arena, expected_value.expr); |
| 3960 | 3960 | ||
| 3961 | const new_value_index = self.exprs.items.len; | 3961 | const new_value_index = self.exprs.items.len; |
| 3962 | var new_value: DocData.WalkResult = try self.walkRef( | 3962 | const new_value: DocData.WalkResult = try self.walkRef( |
| 3963 | file, | 3963 | file, |
| 3964 | parent_scope, | 3964 | parent_scope, |
| 3965 | parent_src, | 3965 | parent_src, |
| ... | @@ -3970,7 +3970,7 @@ fn walkInstruction( | ... | @@ -3970,7 +3970,7 @@ fn walkInstruction( |
| 3970 | try self.exprs.append(self.arena, new_value.expr); | 3970 | try self.exprs.append(self.arena, new_value.expr); |
| 3971 | 3971 | ||
| 3972 | const success_order_index = self.exprs.items.len; | 3972 | const success_order_index = self.exprs.items.len; |
| 3973 | var success_order: DocData.WalkResult = try self.walkRef( | 3973 | const success_order: DocData.WalkResult = try self.walkRef( |
| 3974 | file, | 3974 | file, |
| 3975 | parent_scope, | 3975 | parent_scope, |
| 3976 | parent_src, | 3976 | parent_src, |
| ... | @@ -3981,7 +3981,7 @@ fn walkInstruction( | ... | @@ -3981,7 +3981,7 @@ fn walkInstruction( |
| 3981 | try self.exprs.append(self.arena, success_order.expr); | 3981 | try self.exprs.append(self.arena, success_order.expr); |
| 3982 | 3982 | ||
| 3983 | const failure_order_index = self.exprs.items.len; | 3983 | const failure_order_index = self.exprs.items.len; |
| 3984 | var failure_order: DocData.WalkResult = try self.walkRef( | 3984 | const failure_order: DocData.WalkResult = try self.walkRef( |
| 3985 | file, | 3985 | file, |
| 3986 | parent_scope, | 3986 | parent_scope, |
| 3987 | parent_src, | 3987 | parent_src, |
src/Compilation.zig+6-6| ... | @@ -1759,7 +1759,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1759,7 +1759,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1759 | 1759 | ||
| 1760 | const digest = hash.final(); | 1760 | const digest = hash.final(); |
| 1761 | const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest }); | 1761 | const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest }); |
| 1762 | var artifact_dir = try options.local_cache_directory.handle.makeOpenPath(artifact_sub_dir, .{}); | 1762 | const artifact_dir = try options.local_cache_directory.handle.makeOpenPath(artifact_sub_dir, .{}); |
| 1763 | owned_link_dir = artifact_dir; | 1763 | owned_link_dir = artifact_dir; |
| 1764 | const link_artifact_directory: Directory = .{ | 1764 | const link_artifact_directory: Directory = .{ |
| 1765 | .handle = artifact_dir, | 1765 | .handle = artifact_dir, |
| ... | @@ -2173,7 +2173,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -2173,7 +2173,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 2173 | // LLD might drop some symbols as unused during LTO and GCing, therefore, | 2173 | // LLD might drop some symbols as unused during LTO and GCing, therefore, |
| 2174 | // we force mark them for resolution here. | 2174 | // we force mark them for resolution here. |
| 2175 | 2175 | ||
| 2176 | var tls_index_sym = switch (comp.getTarget().cpu.arch) { | 2176 | const tls_index_sym = switch (comp.getTarget().cpu.arch) { |
| 2177 | .x86 => "__tls_index", | 2177 | .x86 => "__tls_index", |
| 2178 | else => "_tls_index", | 2178 | else => "_tls_index", |
| 2179 | }; | 2179 | }; |
| ... | @@ -2576,7 +2576,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2576,7 +2576,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2576 | var artifact_dir = try comp.local_cache_directory.handle.openDir(o_sub_path, .{}); | 2576 | var artifact_dir = try comp.local_cache_directory.handle.openDir(o_sub_path, .{}); |
| 2577 | defer artifact_dir.close(); | 2577 | defer artifact_dir.close(); |
| 2578 | 2578 | ||
| 2579 | var dir_path = try comp.local_cache_directory.join(comp.gpa, &.{o_sub_path}); | 2579 | const dir_path = try comp.local_cache_directory.join(comp.gpa, &.{o_sub_path}); |
| 2580 | defer comp.gpa.free(dir_path); | 2580 | defer comp.gpa.free(dir_path); |
| 2581 | 2581 | ||
| 2582 | module.zig_cache_artifact_directory = .{ | 2582 | module.zig_cache_artifact_directory = .{ |
| ... | @@ -4961,7 +4961,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 | ... | @@ -4961,7 +4961,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 |
| 4961 | 4961 | ||
| 4962 | var cli_diagnostics = resinator.cli.Diagnostics.init(comp.gpa); | 4962 | var cli_diagnostics = resinator.cli.Diagnostics.init(comp.gpa); |
| 4963 | defer cli_diagnostics.deinit(); | 4963 | defer cli_diagnostics.deinit(); |
| 4964 | var options = resinator.cli.parse(comp.gpa, resinator_args.items, &cli_diagnostics) catch |err| switch (err) { | 4964 | const options = resinator.cli.parse(comp.gpa, resinator_args.items, &cli_diagnostics) catch |err| switch (err) { |
| 4965 | error.ParseError => { | 4965 | error.ParseError => { |
| 4966 | return comp.failWin32ResourceCli(win32_resource, &cli_diagnostics); | 4966 | return comp.failWin32ResourceCli(win32_resource, &cli_diagnostics); |
| 4967 | }, | 4967 | }, |
| ... | @@ -5062,7 +5062,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 | ... | @@ -5062,7 +5062,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 |
| 5062 | log.warn("failed to delete '{s}': {s}", .{ out_dep_path, @errorName(err) }); | 5062 | log.warn("failed to delete '{s}': {s}", .{ out_dep_path, @errorName(err) }); |
| 5063 | }; | 5063 | }; |
| 5064 | 5064 | ||
| 5065 | var full_input = std.fs.cwd().readFileAlloc(arena, out_rcpp_path, std.math.maxInt(usize)) catch |err| switch (err) { | 5065 | const full_input = std.fs.cwd().readFileAlloc(arena, out_rcpp_path, std.math.maxInt(usize)) catch |err| switch (err) { |
| 5066 | error.OutOfMemory => return error.OutOfMemory, | 5066 | error.OutOfMemory => return error.OutOfMemory, |
| 5067 | else => |e| { | 5067 | else => |e| { |
| 5068 | return comp.failWin32Resource(win32_resource, "failed to read preprocessed file '{s}': {s}", .{ out_rcpp_path, @errorName(e) }); | 5068 | return comp.failWin32Resource(win32_resource, "failed to read preprocessed file '{s}': {s}", .{ out_rcpp_path, @errorName(e) }); |
| ... | @@ -5072,7 +5072,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 | ... | @@ -5072,7 +5072,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 |
| 5072 | var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(arena, full_input, full_input, .{ .initial_filename = rc_src.src_path }); | 5072 | var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(arena, full_input, full_input, .{ .initial_filename = rc_src.src_path }); |
| 5073 | defer mapping_results.mappings.deinit(arena); | 5073 | defer mapping_results.mappings.deinit(arena); |
| 5074 | 5074 | ||
| 5075 | var final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); | 5075 | const final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); |
| 5076 | 5076 | ||
| 5077 | var output_file = zig_cache_tmp_dir.createFile(out_res_path, .{}) catch |err| { | 5077 | var output_file = zig_cache_tmp_dir.createFile(out_res_path, .{}) catch |err| { |
| 5078 | return comp.failWin32Resource(win32_resource, "failed to create output file '{s}': {s}", .{ out_res_path, @errorName(err) }); | 5078 | return comp.failWin32Resource(win32_resource, "failed to create output file '{s}': {s}", .{ out_res_path, @errorName(err) }); |
src/Package/Fetch/git.zig+9-9| ... | @@ -83,7 +83,7 @@ pub const Repository = struct { | ... | @@ -83,7 +83,7 @@ pub const Repository = struct { |
| 83 | ) !void { | 83 | ) !void { |
| 84 | try repository.odb.seekOid(commit_oid); | 84 | try repository.odb.seekOid(commit_oid); |
| 85 | const tree_oid = tree_oid: { | 85 | const tree_oid = tree_oid: { |
| 86 | var commit_object = try repository.odb.readObject(); | 86 | const commit_object = try repository.odb.readObject(); |
| 87 | if (commit_object.type != .commit) return error.NotACommit; | 87 | if (commit_object.type != .commit) return error.NotACommit; |
| 88 | break :tree_oid try getCommitTree(commit_object.data); | 88 | break :tree_oid try getCommitTree(commit_object.data); |
| 89 | }; | 89 | }; |
| ... | @@ -122,14 +122,14 @@ pub const Repository = struct { | ... | @@ -122,14 +122,14 @@ pub const Repository = struct { |
| 122 | var file = try dir.createFile(entry.name, .{}); | 122 | var file = try dir.createFile(entry.name, .{}); |
| 123 | defer file.close(); | 123 | defer file.close(); |
| 124 | try repository.odb.seekOid(entry.oid); | 124 | try repository.odb.seekOid(entry.oid); |
| 125 | var file_object = try repository.odb.readObject(); | 125 | const file_object = try repository.odb.readObject(); |
| 126 | if (file_object.type != .blob) return error.InvalidFile; | 126 | if (file_object.type != .blob) return error.InvalidFile; |
| 127 | try file.writeAll(file_object.data); | 127 | try file.writeAll(file_object.data); |
| 128 | try file.sync(); | 128 | try file.sync(); |
| 129 | }, | 129 | }, |
| 130 | .symlink => { | 130 | .symlink => { |
| 131 | try repository.odb.seekOid(entry.oid); | 131 | try repository.odb.seekOid(entry.oid); |
| 132 | var symlink_object = try repository.odb.readObject(); | 132 | const symlink_object = try repository.odb.readObject(); |
| 133 | if (symlink_object.type != .blob) return error.InvalidFile; | 133 | if (symlink_object.type != .blob) return error.InvalidFile; |
| 134 | const link_name = symlink_object.data; | 134 | const link_name = symlink_object.data; |
| 135 | dir.symLink(link_name, entry.name, .{}) catch |e| { | 135 | dir.symLink(link_name, entry.name, .{}) catch |e| { |
| ... | @@ -1230,7 +1230,7 @@ fn resolveDeltaChain( | ... | @@ -1230,7 +1230,7 @@ fn resolveDeltaChain( |
| 1230 | const delta_offset = delta_offsets[i]; | 1230 | const delta_offset = delta_offsets[i]; |
| 1231 | try pack.seekTo(delta_offset); | 1231 | try pack.seekTo(delta_offset); |
| 1232 | const delta_header = try EntryHeader.read(pack.reader()); | 1232 | const delta_header = try EntryHeader.read(pack.reader()); |
| 1233 | var delta_data = try readObjectRaw(allocator, pack.reader(), delta_header.uncompressedLength()); | 1233 | const delta_data = try readObjectRaw(allocator, pack.reader(), delta_header.uncompressedLength()); |
| 1234 | defer allocator.free(delta_data); | 1234 | defer allocator.free(delta_data); |
| 1235 | var delta_stream = std.io.fixedBufferStream(delta_data); | 1235 | var delta_stream = std.io.fixedBufferStream(delta_data); |
| 1236 | const delta_reader = delta_stream.reader(); | 1236 | const delta_reader = delta_stream.reader(); |
| ... | @@ -1238,7 +1238,7 @@ fn resolveDeltaChain( | ... | @@ -1238,7 +1238,7 @@ fn resolveDeltaChain( |
| 1238 | const expanded_size = try readSizeVarInt(delta_reader); | 1238 | const expanded_size = try readSizeVarInt(delta_reader); |
| 1239 | 1239 | ||
| 1240 | const expanded_alloc_size = std.math.cast(usize, expanded_size) orelse return error.ObjectTooLarge; | 1240 | const expanded_alloc_size = std.math.cast(usize, expanded_size) orelse return error.ObjectTooLarge; |
| 1241 | var expanded_data = try allocator.alloc(u8, expanded_alloc_size); | 1241 | const expanded_data = try allocator.alloc(u8, expanded_alloc_size); |
| 1242 | errdefer allocator.free(expanded_data); | 1242 | errdefer allocator.free(expanded_data); |
| 1243 | var expanded_delta_stream = std.io.fixedBufferStream(expanded_data); | 1243 | var expanded_delta_stream = std.io.fixedBufferStream(expanded_data); |
| 1244 | var base_stream = std.io.fixedBufferStream(base_data); | 1244 | var base_stream = std.io.fixedBufferStream(base_data); |
| ... | @@ -1259,7 +1259,7 @@ fn readObjectRaw(allocator: Allocator, reader: anytype, size: u64) ![]u8 { | ... | @@ -1259,7 +1259,7 @@ fn readObjectRaw(allocator: Allocator, reader: anytype, size: u64) ![]u8 { |
| 1259 | var buffered_reader = std.io.bufferedReader(reader); | 1259 | var buffered_reader = std.io.bufferedReader(reader); |
| 1260 | var decompress_stream = try std.compress.zlib.decompressStream(allocator, buffered_reader.reader()); | 1260 | var decompress_stream = try std.compress.zlib.decompressStream(allocator, buffered_reader.reader()); |
| 1261 | defer decompress_stream.deinit(); | 1261 | defer decompress_stream.deinit(); |
| 1262 | var data = try allocator.alloc(u8, alloc_size); | 1262 | const data = try allocator.alloc(u8, alloc_size); |
| 1263 | errdefer allocator.free(data); | 1263 | errdefer allocator.free(data); |
| 1264 | try decompress_stream.reader().readNoEof(data); | 1264 | try decompress_stream.reader().readNoEof(data); |
| 1265 | _ = decompress_stream.reader().readByte() catch |e| switch (e) { | 1265 | _ = decompress_stream.reader().readByte() catch |e| switch (e) { |
| ... | @@ -1290,14 +1290,14 @@ fn expandDelta(base_object: anytype, delta_reader: anytype, writer: anytype) !vo | ... | @@ -1290,14 +1290,14 @@ fn expandDelta(base_object: anytype, delta_reader: anytype, writer: anytype) !vo |
| 1290 | size2: bool, | 1290 | size2: bool, |
| 1291 | size3: bool, | 1291 | size3: bool, |
| 1292 | } = @bitCast(inst.value); | 1292 | } = @bitCast(inst.value); |
| 1293 | var offset_parts: packed struct { offset1: u8, offset2: u8, offset3: u8, offset4: u8 } = .{ | 1293 | const offset_parts: packed struct { offset1: u8, offset2: u8, offset3: u8, offset4: u8 } = .{ |
| 1294 | .offset1 = if (available.offset1) try delta_reader.readByte() else 0, | 1294 | .offset1 = if (available.offset1) try delta_reader.readByte() else 0, |
| 1295 | .offset2 = if (available.offset2) try delta_reader.readByte() else 0, | 1295 | .offset2 = if (available.offset2) try delta_reader.readByte() else 0, |
| 1296 | .offset3 = if (available.offset3) try delta_reader.readByte() else 0, | 1296 | .offset3 = if (available.offset3) try delta_reader.readByte() else 0, |
| 1297 | .offset4 = if (available.offset4) try delta_reader.readByte() else 0, | 1297 | .offset4 = if (available.offset4) try delta_reader.readByte() else 0, |
| 1298 | }; | 1298 | }; |
| 1299 | const offset: u32 = @bitCast(offset_parts); | 1299 | const offset: u32 = @bitCast(offset_parts); |
| 1300 | var size_parts: packed struct { size1: u8, size2: u8, size3: u8 } = .{ | 1300 | const size_parts: packed struct { size1: u8, size2: u8, size3: u8 } = .{ |
| 1301 | .size1 = if (available.size1) try delta_reader.readByte() else 0, | 1301 | .size1 = if (available.size1) try delta_reader.readByte() else 0, |
| 1302 | .size2 = if (available.size2) try delta_reader.readByte() else 0, | 1302 | .size2 = if (available.size2) try delta_reader.readByte() else 0, |
| 1303 | .size3 = if (available.size3) try delta_reader.readByte() else 0, | 1303 | .size3 = if (available.size3) try delta_reader.readByte() else 0, |
| ... | @@ -1414,7 +1414,7 @@ test "packfile indexing and checkout" { | ... | @@ -1414,7 +1414,7 @@ test "packfile indexing and checkout" { |
| 1414 | defer walker.deinit(); | 1414 | defer walker.deinit(); |
| 1415 | while (try walker.next()) |entry| { | 1415 | while (try walker.next()) |entry| { |
| 1416 | if (entry.kind != .file) continue; | 1416 | if (entry.kind != .file) continue; |
| 1417 | var path = try testing.allocator.dupe(u8, entry.path); | 1417 | const path = try testing.allocator.dupe(u8, entry.path); |
| 1418 | errdefer testing.allocator.free(path); | 1418 | errdefer testing.allocator.free(path); |
| 1419 | mem.replaceScalar(u8, path, std.fs.path.sep, '/'); | 1419 | mem.replaceScalar(u8, path, std.fs.path.sep, '/'); |
| 1420 | try actual_files.append(testing.allocator, path); | 1420 | try actual_files.append(testing.allocator, path); |
src/Sema.zig+9-9| ... | @@ -22899,7 +22899,7 @@ fn checkSimdBinOp( | ... | @@ -22899,7 +22899,7 @@ fn checkSimdBinOp( |
| 22899 | const rhs_ty = sema.typeOf(uncasted_rhs); | 22899 | const rhs_ty = sema.typeOf(uncasted_rhs); |
| 22900 | 22900 | ||
| 22901 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); | 22901 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 22902 | var vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen(mod) else null; | 22902 | const vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen(mod) else null; |
| 22903 | const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{ | 22903 | const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{ |
| 22904 | .override = &[_]?LazySrcLoc{ lhs_src, rhs_src }, | 22904 | .override = &[_]?LazySrcLoc{ lhs_src, rhs_src }, |
| 22905 | }); | 22905 | }); |
| ... | @@ -23286,8 +23286,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -23286,8 +23286,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 23286 | 23286 | ||
| 23287 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 23287 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 23288 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); | 23288 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| 23289 | var a = try sema.resolveInst(extra.a); | 23289 | const a = try sema.resolveInst(extra.a); |
| 23290 | var b = try sema.resolveInst(extra.b); | 23290 | const b = try sema.resolveInst(extra.b); |
| 23291 | var mask = try sema.resolveInst(extra.mask); | 23291 | var mask = try sema.resolveInst(extra.mask); |
| 23292 | var mask_ty = sema.typeOf(mask); | 23292 | var mask_ty = sema.typeOf(mask); |
| 23293 | 23293 | ||
| ... | @@ -23328,7 +23328,7 @@ fn analyzeShuffle( | ... | @@ -23328,7 +23328,7 @@ fn analyzeShuffle( |
| 23328 | .child = elem_ty.toIntern(), | 23328 | .child = elem_ty.toIntern(), |
| 23329 | }); | 23329 | }); |
| 23330 | 23330 | ||
| 23331 | var maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) { | 23331 | const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) { |
| 23332 | .Array, .Vector => sema.typeOf(a).arrayLen(mod), | 23332 | .Array, .Vector => sema.typeOf(a).arrayLen(mod), |
| 23333 | .Undefined => null, | 23333 | .Undefined => null, |
| 23334 | else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{ | 23334 | else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{ |
| ... | @@ -23336,7 +23336,7 @@ fn analyzeShuffle( | ... | @@ -23336,7 +23336,7 @@ fn analyzeShuffle( |
| 23336 | sema.typeOf(a).fmt(sema.mod), | 23336 | sema.typeOf(a).fmt(sema.mod), |
| 23337 | }), | 23337 | }), |
| 23338 | }; | 23338 | }; |
| 23339 | var maybe_b_len = switch (sema.typeOf(b).zigTypeTag(mod)) { | 23339 | const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(mod)) { |
| 23340 | .Array, .Vector => sema.typeOf(b).arrayLen(mod), | 23340 | .Array, .Vector => sema.typeOf(b).arrayLen(mod), |
| 23341 | .Undefined => null, | 23341 | .Undefined => null, |
| 23342 | else => return sema.fail(block, b_src, "expected vector or array with element type '{}', found '{}'", .{ | 23342 | else => return sema.fail(block, b_src, "expected vector or array with element type '{}', found '{}'", .{ |
| ... | @@ -23801,7 +23801,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23801,7 +23801,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23801 | const call_src = inst_data.src(); | 23801 | const call_src = inst_data.src(); |
| 23802 | 23802 | ||
| 23803 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; | 23803 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| 23804 | var func = try sema.resolveInst(extra.callee); | 23804 | const func = try sema.resolveInst(extra.callee); |
| 23805 | 23805 | ||
| 23806 | const modifier_ty = try sema.getBuiltinType("CallModifier"); | 23806 | const modifier_ty = try sema.getBuiltinType("CallModifier"); |
| 23807 | const air_ref = try sema.resolveInst(extra.modifier); | 23807 | const air_ref = try sema.resolveInst(extra.modifier); |
| ... | @@ -23859,7 +23859,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23859,7 +23859,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23859 | return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(sema.mod)}); | 23859 | return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(sema.mod)}); |
| 23860 | } | 23860 | } |
| 23861 | 23861 | ||
| 23862 | var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod)); | 23862 | const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod)); |
| 23863 | for (resolved_args, 0..) |*resolved, i| { | 23863 | for (resolved_args, 0..) |*resolved, i| { |
| 23864 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty); | 23864 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty); |
| 23865 | } | 23865 | } |
| ... | @@ -33274,8 +33274,8 @@ fn resolvePeerTypes( | ... | @@ -33274,8 +33274,8 @@ fn resolvePeerTypes( |
| 33274 | else => {}, | 33274 | else => {}, |
| 33275 | } | 33275 | } |
| 33276 | 33276 | ||
| 33277 | var peer_tys = try sema.arena.alloc(?Type, instructions.len); | 33277 | const peer_tys = try sema.arena.alloc(?Type, instructions.len); |
| 33278 | var peer_vals = try sema.arena.alloc(?Value, instructions.len); | 33278 | const peer_vals = try sema.arena.alloc(?Value, instructions.len); |
| 33279 | 33279 | ||
| 33280 | for (instructions, peer_tys, peer_vals) |inst, *ty, *val| { | 33280 | for (instructions, peer_tys, peer_vals) |inst, *ty, *val| { |
| 33281 | ty.* = sema.typeOf(inst); | 33281 | ty.* = sema.typeOf(inst); |
src/arch/riscv64/CodeGen.zig+5| ... | @@ -2648,6 +2648,11 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -2648,6 +2648,11 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 2648 | // conventions | 2648 | // conventions |
| 2649 | var next_register: usize = 0; | 2649 | var next_register: usize = 0; |
| 2650 | var next_stack_offset: u32 = 0; | 2650 | var next_stack_offset: u32 = 0; |
| 2651 | // TODO: this is never assigned, which is a bug, but I don't know how this code works | ||
| 2652 | // well enough to try and fix it. I *think* `next_register += next_stack_offset` is | ||
| 2653 | // supposed to be `next_stack_offset += param_size` in every case where it appears. | ||
| 2654 | _ = &next_stack_offset; | ||
| 2655 | |||
| 2651 | const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 }; | 2656 | const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 }; |
| 2652 | 2657 | ||
| 2653 | for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| { | 2658 | for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| { |
src/arch/sparc64/CodeGen.zig+4| ... | @@ -4481,6 +4481,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) | ... | @@ -4481,6 +4481,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) |
| 4481 | 4481 | ||
| 4482 | var next_register: usize = 0; | 4482 | var next_register: usize = 0; |
| 4483 | var next_stack_offset: u32 = 0; | 4483 | var next_stack_offset: u32 = 0; |
| 4484 | // TODO: this is never assigned, which is a bug, but I don't know how this code works | ||
| 4485 | // well enough to try and fix it. I *think* `next_register += next_stack_offset` is | ||
| 4486 | // supposed to be `next_stack_offset += param_size` in every case where it appears. | ||
| 4487 | _ = &next_stack_offset; | ||
| 4484 | 4488 | ||
| 4485 | // The caller puts the argument in %o0-%o5, which becomes %i0-%i5 inside the callee. | 4489 | // The caller puts the argument in %o0-%o5, which becomes %i0-%i5 inside the callee. |
| 4486 | const argument_registers = switch (role) { | 4490 | const argument_registers = switch (role) { |
src/arch/wasm/CodeGen.zig+4-4| ... | @@ -2139,7 +2139,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -2139,7 +2139,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2139 | const mod = func.bin_file.base.options.module.?; | 2139 | const mod = func.bin_file.base.options.module.?; |
| 2140 | const child_type = func.typeOfIndex(inst).childType(mod); | 2140 | const child_type = func.typeOfIndex(inst).childType(mod); |
| 2141 | 2141 | ||
| 2142 | var result = result: { | 2142 | const result = result: { |
| 2143 | if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) { | 2143 | if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) { |
| 2144 | break :result try func.allocStack(Type.usize); // create pointer to void | 2144 | break :result try func.allocStack(Type.usize); // create pointer to void |
| 2145 | } | 2145 | } |
| ... | @@ -5001,7 +5001,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -5001,7 +5001,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5001 | return func.finishAir(inst, try WValue.toLocal(.stack, func, elem_ty), &.{ bin_op.lhs, bin_op.rhs }); | 5001 | return func.finishAir(inst, try WValue.toLocal(.stack, func, elem_ty), &.{ bin_op.lhs, bin_op.rhs }); |
| 5002 | }, | 5002 | }, |
| 5003 | else => { | 5003 | else => { |
| 5004 | var stack_vec = try func.allocStack(array_ty); | 5004 | const stack_vec = try func.allocStack(array_ty); |
| 5005 | try func.store(stack_vec, array, array_ty, 0); | 5005 | try func.store(stack_vec, array, array_ty, 0); |
| 5006 | 5006 | ||
| 5007 | // Is a non-unrolled vector (v128) | 5007 | // Is a non-unrolled vector (v128) |
| ... | @@ -5944,7 +5944,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro | ... | @@ -5944,7 +5944,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro |
| 5944 | rhs.free(func); | 5944 | rhs.free(func); |
| 5945 | }; | 5945 | }; |
| 5946 | 5946 | ||
| 5947 | var bin_op = try (try func.binOp(lhs, rhs, lhs_ty, op)).toLocal(func, lhs_ty); | 5947 | const bin_op = try (try func.binOp(lhs, rhs, lhs_ty, op)).toLocal(func, lhs_ty); |
| 5948 | var result = if (wasm_bits != int_info.bits) blk: { | 5948 | var result = if (wasm_bits != int_info.bits) blk: { |
| 5949 | break :blk try (try func.wrapOperand(bin_op, lhs_ty)).toLocal(func, lhs_ty); | 5949 | break :blk try (try func.wrapOperand(bin_op, lhs_ty)).toLocal(func, lhs_ty); |
| 5950 | } else bin_op; | 5950 | } else bin_op; |
| ... | @@ -6335,7 +6335,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -6335,7 +6335,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6335 | const lhs_ext = try func.fpext(lhs, ty, Type.f32); | 6335 | const lhs_ext = try func.fpext(lhs, ty, Type.f32); |
| 6336 | const addend_ext = try func.fpext(addend, ty, Type.f32); | 6336 | const addend_ext = try func.fpext(addend, ty, Type.f32); |
| 6337 | // call to compiler-rt `fn fmaf(f32, f32, f32) f32` | 6337 | // call to compiler-rt `fn fmaf(f32, f32, f32) f32` |
| 6338 | var result = try func.callIntrinsic( | 6338 | const result = try func.callIntrinsic( |
| 6339 | "fmaf", | 6339 | "fmaf", |
| 6340 | &.{ .f32_type, .f32_type, .f32_type }, | 6340 | &.{ .f32_type, .f32_type, .f32_type }, |
| 6341 | Type.f32, | 6341 | Type.f32, |
src/arch/x86_64/CodeGen.zig+1-1| ... | @@ -2181,7 +2181,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { | ... | @@ -2181,7 +2181,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { |
| 2181 | const ret_reg = param_regs[0]; | 2181 | const ret_reg = param_regs[0]; |
| 2182 | const enum_mcv = MCValue{ .register = param_regs[1] }; | 2182 | const enum_mcv = MCValue{ .register = param_regs[1] }; |
| 2183 | 2183 | ||
| 2184 | var exitlude_jump_relocs = try self.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(mod)); | 2184 | const exitlude_jump_relocs = try self.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(mod)); |
| 2185 | defer self.gpa.free(exitlude_jump_relocs); | 2185 | defer self.gpa.free(exitlude_jump_relocs); |
| 2186 | 2186 | ||
| 2187 | const data_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp); | 2187 | const data_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp); |
src/arch/x86_64/Disassembler.zig+1-2| ... | @@ -234,13 +234,12 @@ fn inst(encoding: Encoding, args: struct { | ... | @@ -234,13 +234,12 @@ fn inst(encoding: Encoding, args: struct { |
| 234 | op3: Instruction.Operand = .none, | 234 | op3: Instruction.Operand = .none, |
| 235 | op4: Instruction.Operand = .none, | 235 | op4: Instruction.Operand = .none, |
| 236 | }) Instruction { | 236 | }) Instruction { |
| 237 | var i = Instruction{ .encoding = encoding, .prefix = args.prefix, .ops = .{ | 237 | return .{ .encoding = encoding, .prefix = args.prefix, .ops = .{ |
| 238 | args.op1, | 238 | args.op1, |
| 239 | args.op2, | 239 | args.op2, |
| 240 | args.op3, | 240 | args.op3, |
| 241 | args.op4, | 241 | args.op4, |
| 242 | } }; | 242 | } }; |
| 243 | return i; | ||
| 244 | } | 243 | } |
| 245 | 244 | ||
| 246 | const Prefixes = struct { | 245 | const Prefixes = struct { |
src/arch/x86_64/Lower.zig+1-1| ... | @@ -342,7 +342,7 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand) | ... | @@ -342,7 +342,7 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand) |
| 342 | .Lib => lower.bin_file.options.link_mode == .Static, | 342 | .Lib => lower.bin_file.options.link_mode == .Static, |
| 343 | }; | 343 | }; |
| 344 | 344 | ||
| 345 | var emit_prefix = prefix; | 345 | const emit_prefix = prefix; |
| 346 | var emit_mnemonic = mnemonic; | 346 | var emit_mnemonic = mnemonic; |
| 347 | var emit_ops_storage: [4]Operand = undefined; | 347 | var emit_ops_storage: [4]Operand = undefined; |
| 348 | const emit_ops = emit_ops_storage[0..ops.len]; | 348 | const emit_ops = emit_ops_storage[0..ops.len]; |
src/arch/x86_64/encoder.zig+2-2| ... | @@ -244,7 +244,7 @@ pub const Instruction = struct { | ... | @@ -244,7 +244,7 @@ pub const Instruction = struct { |
| 244 | }), | 244 | }), |
| 245 | }, | 245 | }, |
| 246 | .imm => |imm| if (enc_op.isSigned()) { | 246 | .imm => |imm| if (enc_op.isSigned()) { |
| 247 | var imms = imm.asSigned(enc_op.immBitSize()); | 247 | const imms = imm.asSigned(enc_op.immBitSize()); |
| 248 | if (imms < 0) try writer.writeByte('-'); | 248 | if (imms < 0) try writer.writeByte('-'); |
| 249 | try writer.print("0x{x}", .{@abs(imms)}); | 249 | try writer.print("0x{x}", .{@abs(imms)}); |
| 250 | } else try writer.print("0x{x}", .{imm.asUnsigned(enc_op.immBitSize())}), | 250 | } else try writer.print("0x{x}", .{imm.asUnsigned(enc_op.immBitSize())}), |
| ... | @@ -1077,7 +1077,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co | ... | @@ -1077,7 +1077,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co |
| 1077 | const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)}); | 1077 | const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)}); |
| 1078 | defer testing.allocator.free(given_fmt); | 1078 | defer testing.allocator.free(given_fmt); |
| 1079 | const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?; | 1079 | const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?; |
| 1080 | var padding = try testing.allocator.alloc(u8, idx + 5); | 1080 | const padding = try testing.allocator.alloc(u8, idx + 5); |
| 1081 | defer testing.allocator.free(padding); | 1081 | defer testing.allocator.free(padding); |
| 1082 | @memset(padding, ' '); | 1082 | @memset(padding, ' '); |
| 1083 | std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ | 1083 | std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ |
src/aro_translate_c.zig+2-2| ... | @@ -346,7 +346,7 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { | ... | @@ -346,7 +346,7 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { |
| 346 | defer block_scope.deinit(); | 346 | defer block_scope.deinit(); |
| 347 | 347 | ||
| 348 | var scope = &block_scope.base; | 348 | var scope = &block_scope.base; |
| 349 | _ = scope; | 349 | _ = &scope; |
| 350 | 350 | ||
| 351 | var param_id: c_uint = 0; | 351 | var param_id: c_uint = 0; |
| 352 | for (proto_payload.data.params, fn_ty.data.func.params) |*param, param_info| { | 352 | for (proto_payload.data.params, fn_ty.data.func.params) |*param, param_info| { |
| ... | @@ -534,7 +534,7 @@ fn transFnType( | ... | @@ -534,7 +534,7 @@ fn transFnType( |
| 534 | ctx: FnProtoContext, | 534 | ctx: FnProtoContext, |
| 535 | ) !ZigNode { | 535 | ) !ZigNode { |
| 536 | const param_count: usize = fn_ty.data.func.params.len; | 536 | const param_count: usize = fn_ty.data.func.params.len; |
| 537 | var fn_params = try c.arena.alloc(ast.Payload.Param, param_count); | 537 | const fn_params = try c.arena.alloc(ast.Payload.Param, param_count); |
| 538 | 538 | ||
| 539 | for (fn_ty.data.func.params, fn_params) |param_info, *param_node| { | 539 | for (fn_ty.data.func.params, fn_params) |param_info, *param_node| { |
| 540 | const param_ty = param_info.ty; | 540 | const param_ty = param_info.ty; |
src/codegen.zig+1-1| ... | @@ -368,7 +368,7 @@ pub fn generateSymbol( | ... | @@ -368,7 +368,7 @@ pub fn generateSymbol( |
| 368 | .bytes => |bytes| try code.appendSlice(bytes), | 368 | .bytes => |bytes| try code.appendSlice(bytes), |
| 369 | .elems, .repeated_elem => { | 369 | .elems, .repeated_elem => { |
| 370 | var index: u64 = 0; | 370 | var index: u64 = 0; |
| 371 | var len_including_sentinel = | 371 | const len_including_sentinel = |
| 372 | array_type.len + @intFromBool(array_type.sentinel != .none); | 372 | array_type.len + @intFromBool(array_type.sentinel != .none); |
| 373 | while (index < len_including_sentinel) : (index += 1) { | 373 | while (index < len_including_sentinel) : (index += 1) { |
| 374 | switch (try generateSymbol(bin_file, src_loc, .{ | 374 | switch (try generateSymbol(bin_file, src_loc, .{ |
src/codegen/llvm/BitcodeReader.zig+1-1| ... | @@ -410,7 +410,7 @@ fn readVbr(bc: *BitcodeReader, comptime T: type, bits: u7) !T { | ... | @@ -410,7 +410,7 @@ fn readVbr(bc: *BitcodeReader, comptime T: type, bits: u7) !T { |
| 410 | var result: u64 = 0; | 410 | var result: u64 = 0; |
| 411 | var shift: u6 = 0; | 411 | var shift: u6 = 0; |
| 412 | while (true) { | 412 | while (true) { |
| 413 | var chunk = try bc.readFixed(u64, bits); | 413 | const chunk = try bc.readFixed(u64, bits); |
| 414 | result |= (chunk & (chunk_msb - 1)) << shift; | 414 | result |= (chunk & (chunk_msb - 1)) << shift; |
| 415 | if (chunk & chunk_msb == 0) break; | 415 | if (chunk & chunk_msb == 0) break; |
| 416 | shift += chunk_bits; | 416 | shift += chunk_bits; |
src/codegen/spirv.zig+4-4| ... | @@ -1284,7 +1284,7 @@ const DeclGen = struct { | ... | @@ -1284,7 +1284,7 @@ const DeclGen = struct { |
| 1284 | 1284 | ||
| 1285 | const elem_ty = ty.childType(mod); | 1285 | const elem_ty = ty.childType(mod); |
| 1286 | const elem_ty_ref = try self.resolveType(elem_ty, .indirect); | 1286 | const elem_ty_ref = try self.resolveType(elem_ty, .indirect); |
| 1287 | var total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse { | 1287 | const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse { |
| 1288 | return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(mod)}); | 1288 | return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(mod)}); |
| 1289 | }; | 1289 | }; |
| 1290 | const ty_ref = if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) blk: { | 1290 | const ty_ref = if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) blk: { |
| ... | @@ -2115,7 +2115,7 @@ const DeclGen = struct { | ... | @@ -2115,7 +2115,7 @@ const DeclGen = struct { |
| 2115 | const child_ty = ty.childType(mod); | 2115 | const child_ty = ty.childType(mod); |
| 2116 | const vector_len = ty.vectorLen(mod); | 2116 | const vector_len = ty.vectorLen(mod); |
| 2117 | 2117 | ||
| 2118 | var constituents = try self.gpa.alloc(IdRef, vector_len); | 2118 | const constituents = try self.gpa.alloc(IdRef, vector_len); |
| 2119 | defer self.gpa.free(constituents); | 2119 | defer self.gpa.free(constituents); |
| 2120 | 2120 | ||
| 2121 | for (constituents, 0..) |*constituent, i| { | 2121 | for (constituents, 0..) |*constituent, i| { |
| ... | @@ -2312,7 +2312,7 @@ const DeclGen = struct { | ... | @@ -2312,7 +2312,7 @@ const DeclGen = struct { |
| 2312 | if (ty.isVector(mod)) { | 2312 | if (ty.isVector(mod)) { |
| 2313 | const child_ty = ty.childType(mod); | 2313 | const child_ty = ty.childType(mod); |
| 2314 | const vector_len = ty.vectorLen(mod); | 2314 | const vector_len = ty.vectorLen(mod); |
| 2315 | var constituents = try self.gpa.alloc(IdRef, vector_len); | 2315 | const constituents = try self.gpa.alloc(IdRef, vector_len); |
| 2316 | defer self.gpa.free(constituents); | 2316 | defer self.gpa.free(constituents); |
| 2317 | 2317 | ||
| 2318 | for (constituents, 0..) |*constituent, i| { | 2318 | for (constituents, 0..) |*constituent, i| { |
| ... | @@ -2727,7 +2727,7 @@ const DeclGen = struct { | ... | @@ -2727,7 +2727,7 @@ const DeclGen = struct { |
| 2727 | const child_ty = ty.childType(mod); | 2727 | const child_ty = ty.childType(mod); |
| 2728 | const vector_len = ty.vectorLen(mod); | 2728 | const vector_len = ty.vectorLen(mod); |
| 2729 | 2729 | ||
| 2730 | var constituents = try self.gpa.alloc(IdRef, vector_len); | 2730 | const constituents = try self.gpa.alloc(IdRef, vector_len); |
| 2731 | defer self.gpa.free(constituents); | 2731 | defer self.gpa.free(constituents); |
| 2732 | 2732 | ||
| 2733 | for (constituents, 0..) |*constituent, i| { | 2733 | for (constituents, 0..) |*constituent, i| { |
src/link/C.zig+1-1| ... | @@ -103,7 +103,7 @@ pub fn openPath(gpa: Allocator, sub_path: []const u8, options: link.Options) !*C | ... | @@ -103,7 +103,7 @@ pub fn openPath(gpa: Allocator, sub_path: []const u8, options: link.Options) !*C |
| 103 | }); | 103 | }); |
| 104 | errdefer file.close(); | 104 | errdefer file.close(); |
| 105 | 105 | ||
| 106 | var c_file = try gpa.create(C); | 106 | const c_file = try gpa.create(C); |
| 107 | errdefer gpa.destroy(c_file); | 107 | errdefer gpa.destroy(c_file); |
| 108 | 108 | ||
| 109 | c_file.* = .{ | 109 | c_file.* = .{ |
src/link/Coff.zig+5-5| ... | @@ -563,7 +563,7 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme | ... | @@ -563,7 +563,7 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme |
| 563 | 563 | ||
| 564 | // First we look for an appropriately sized free list node. | 564 | // First we look for an appropriately sized free list node. |
| 565 | // The list is unordered. We'll just take the first thing that works. | 565 | // The list is unordered. We'll just take the first thing that works. |
| 566 | var vaddr = blk: { | 566 | const vaddr = blk: { |
| 567 | var i: usize = 0; | 567 | var i: usize = 0; |
| 568 | while (i < free_list.items.len) { | 568 | while (i < free_list.items.len) { |
| 569 | const big_atom_index = free_list.items[i]; | 569 | const big_atom_index = free_list.items[i]; |
| ... | @@ -815,7 +815,7 @@ fn writeAtom(self: *Coff, atom_index: Atom.Index, code: []u8) !void { | ... | @@ -815,7 +815,7 @@ fn writeAtom(self: *Coff, atom_index: Atom.Index, code: []u8) !void { |
| 815 | } | 815 | } |
| 816 | 816 | ||
| 817 | fn debugMem(allocator: Allocator, handle: std.ChildProcess.Id, pvaddr: std.os.windows.LPVOID, code: []const u8) !void { | 817 | fn debugMem(allocator: Allocator, handle: std.ChildProcess.Id, pvaddr: std.os.windows.LPVOID, code: []const u8) !void { |
| 818 | var buffer = try allocator.alloc(u8, code.len); | 818 | const buffer = try allocator.alloc(u8, code.len); |
| 819 | defer allocator.free(buffer); | 819 | defer allocator.free(buffer); |
| 820 | const memread = try std.os.windows.ReadProcessMemory(handle, pvaddr, buffer); | 820 | const memread = try std.os.windows.ReadProcessMemory(handle, pvaddr, buffer); |
| 821 | log.debug("to write: {x}", .{std.fmt.fmtSliceHexLower(code)}); | 821 | log.debug("to write: {x}", .{std.fmt.fmtSliceHexLower(code)}); |
| ... | @@ -1071,7 +1071,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air: | ... | @@ -1071,7 +1071,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air: |
| 1071 | &code_buffer, | 1071 | &code_buffer, |
| 1072 | .none, | 1072 | .none, |
| 1073 | ); | 1073 | ); |
| 1074 | var code = switch (res) { | 1074 | const code = switch (res) { |
| 1075 | .ok => code_buffer.items, | 1075 | .ok => code_buffer.items, |
| 1076 | .fail => |em| { | 1076 | .fail => |em| { |
| 1077 | decl.analysis = .codegen_failure; | 1077 | decl.analysis = .codegen_failure; |
| ... | @@ -1132,7 +1132,7 @@ fn lowerConst(self: *Coff, name: []const u8, tv: TypedValue, required_alignment: | ... | @@ -1132,7 +1132,7 @@ fn lowerConst(self: *Coff, name: []const u8, tv: TypedValue, required_alignment: |
| 1132 | const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{ | 1132 | const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{ |
| 1133 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, | 1133 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, |
| 1134 | }); | 1134 | }); |
| 1135 | var code = switch (res) { | 1135 | const code = switch (res) { |
| 1136 | .ok => code_buffer.items, | 1136 | .ok => code_buffer.items, |
| 1137 | .fail => |em| return .{ .fail = em }, | 1137 | .fail => |em| return .{ .fail = em }, |
| 1138 | }; | 1138 | }; |
| ... | @@ -1196,7 +1196,7 @@ pub fn updateDecl( | ... | @@ -1196,7 +1196,7 @@ pub fn updateDecl( |
| 1196 | }, &code_buffer, .none, .{ | 1196 | }, &code_buffer, .none, .{ |
| 1197 | .parent_atom_index = atom.getSymbolIndex().?, | 1197 | .parent_atom_index = atom.getSymbolIndex().?, |
| 1198 | }); | 1198 | }); |
| 1199 | var code = switch (res) { | 1199 | const code = switch (res) { |
| 1200 | .ok => code_buffer.items, | 1200 | .ok => code_buffer.items, |
| 1201 | .fail => |em| { | 1201 | .fail => |em| { |
| 1202 | decl.analysis = .codegen_failure; | 1202 | decl.analysis = .codegen_failure; |
src/link/Dwarf.zig+3-3| ... | @@ -303,7 +303,7 @@ pub const DeclState = struct { | ... | @@ -303,7 +303,7 @@ pub const DeclState = struct { |
| 303 | // DW.AT.name, DW.FORM.string | 303 | // DW.AT.name, DW.FORM.string |
| 304 | try dbg_info_buffer.writer().print("{d}\x00", .{field_index}); | 304 | try dbg_info_buffer.writer().print("{d}\x00", .{field_index}); |
| 305 | // DW.AT.type, DW.FORM.ref4 | 305 | // DW.AT.type, DW.FORM.ref4 |
| 306 | var index = dbg_info_buffer.items.len; | 306 | const index = dbg_info_buffer.items.len; |
| 307 | try dbg_info_buffer.resize(index + 4); | 307 | try dbg_info_buffer.resize(index + 4); |
| 308 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); | 308 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); |
| 309 | // DW.AT.data_member_location, DW.FORM.udata | 309 | // DW.AT.data_member_location, DW.FORM.udata |
| ... | @@ -329,7 +329,7 @@ pub const DeclState = struct { | ... | @@ -329,7 +329,7 @@ pub const DeclState = struct { |
| 329 | // DW.AT.name, DW.FORM.string | 329 | // DW.AT.name, DW.FORM.string |
| 330 | try dbg_info_buffer.writer().print("{d}\x00", .{field_index}); | 330 | try dbg_info_buffer.writer().print("{d}\x00", .{field_index}); |
| 331 | // DW.AT.type, DW.FORM.ref4 | 331 | // DW.AT.type, DW.FORM.ref4 |
| 332 | var index = dbg_info_buffer.items.len; | 332 | const index = dbg_info_buffer.items.len; |
| 333 | try dbg_info_buffer.resize(index + 4); | 333 | try dbg_info_buffer.resize(index + 4); |
| 334 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); | 334 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); |
| 335 | // DW.AT.data_member_location, DW.FORM.udata | 335 | // DW.AT.data_member_location, DW.FORM.udata |
| ... | @@ -350,7 +350,7 @@ pub const DeclState = struct { | ... | @@ -350,7 +350,7 @@ pub const DeclState = struct { |
| 350 | dbg_info_buffer.appendSliceAssumeCapacity(field_name); | 350 | dbg_info_buffer.appendSliceAssumeCapacity(field_name); |
| 351 | dbg_info_buffer.appendAssumeCapacity(0); | 351 | dbg_info_buffer.appendAssumeCapacity(0); |
| 352 | // DW.AT.type, DW.FORM.ref4 | 352 | // DW.AT.type, DW.FORM.ref4 |
| 353 | var index = dbg_info_buffer.items.len; | 353 | const index = dbg_info_buffer.items.len; |
| 354 | try dbg_info_buffer.resize(index + 4); | 354 | try dbg_info_buffer.resize(index + 4); |
| 355 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); | 355 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); |
| 356 | // DW.AT.data_member_location, DW.FORM.udata | 356 | // DW.AT.data_member_location, DW.FORM.udata |
src/link/Elf.zig+5-5| ... | @@ -967,7 +967,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -967,7 +967,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 967 | // --verbose-link | 967 | // --verbose-link |
| 968 | if (self.base.options.verbose_link) try self.dumpArgv(comp); | 968 | if (self.base.options.verbose_link) try self.dumpArgv(comp); |
| 969 | 969 | ||
| 970 | var csu = try CsuObjects.init(arena, self.base.options, comp); | 970 | const csu = try CsuObjects.init(arena, self.base.options, comp); |
| 971 | const compiler_rt_path: ?[]const u8 = blk: { | 971 | const compiler_rt_path: ?[]const u8 = blk: { |
| 972 | if (comp.compiler_rt_lib) |x| break :blk x.full_object_path; | 972 | if (comp.compiler_rt_lib) |x| break :blk x.full_object_path; |
| 973 | if (comp.compiler_rt_obj) |x| break :blk x.full_object_path; | 973 | if (comp.compiler_rt_obj) |x| break :blk x.full_object_path; |
| ... | @@ -1493,7 +1493,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { | ... | @@ -1493,7 +1493,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { |
| 1493 | } else null; | 1493 | } else null; |
| 1494 | const gc_sections = self.base.options.gc_sections orelse false; | 1494 | const gc_sections = self.base.options.gc_sections orelse false; |
| 1495 | 1495 | ||
| 1496 | var csu = try CsuObjects.init(arena, self.base.options, comp); | 1496 | const csu = try CsuObjects.init(arena, self.base.options, comp); |
| 1497 | const compiler_rt_path: ?[]const u8 = blk: { | 1497 | const compiler_rt_path: ?[]const u8 = blk: { |
| 1498 | if (comp.compiler_rt_lib) |x| break :blk x.full_object_path; | 1498 | if (comp.compiler_rt_lib) |x| break :blk x.full_object_path; |
| 1499 | if (comp.compiler_rt_obj) |x| break :blk x.full_object_path; | 1499 | if (comp.compiler_rt_obj) |x| break :blk x.full_object_path; |
| ... | @@ -2599,7 +2599,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v | ... | @@ -2599,7 +2599,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v |
| 2599 | try argv.append(full_out_path); | 2599 | try argv.append(full_out_path); |
| 2600 | 2600 | ||
| 2601 | // csu prelude | 2601 | // csu prelude |
| 2602 | var csu = try CsuObjects.init(arena, self.base.options, comp); | 2602 | const csu = try CsuObjects.init(arena, self.base.options, comp); |
| 2603 | if (csu.crt0) |v| try argv.append(v); | 2603 | if (csu.crt0) |v| try argv.append(v); |
| 2604 | if (csu.crti) |v| try argv.append(v); | 2604 | if (csu.crti) |v| try argv.append(v); |
| 2605 | if (csu.crtbegin) |v| try argv.append(v); | 2605 | if (csu.crtbegin) |v| try argv.append(v); |
| ... | @@ -3852,7 +3852,7 @@ fn sortPhdrs(self: *Elf) error{OutOfMemory}!void { | ... | @@ -3852,7 +3852,7 @@ fn sortPhdrs(self: *Elf) error{OutOfMemory}!void { |
| 3852 | backlinks[entry.phndx] = @as(u16, @intCast(i)); | 3852 | backlinks[entry.phndx] = @as(u16, @intCast(i)); |
| 3853 | } | 3853 | } |
| 3854 | 3854 | ||
| 3855 | var slice = try self.phdrs.toOwnedSlice(gpa); | 3855 | const slice = try self.phdrs.toOwnedSlice(gpa); |
| 3856 | defer gpa.free(slice); | 3856 | defer gpa.free(slice); |
| 3857 | 3857 | ||
| 3858 | try self.phdrs.ensureTotalCapacityPrecise(gpa, slice.len); | 3858 | try self.phdrs.ensureTotalCapacityPrecise(gpa, slice.len); |
| ... | @@ -3957,7 +3957,7 @@ fn sortShdrs(self: *Elf) !void { | ... | @@ -3957,7 +3957,7 @@ fn sortShdrs(self: *Elf) !void { |
| 3957 | backlinks[entry.shndx] = @as(u16, @intCast(i)); | 3957 | backlinks[entry.shndx] = @as(u16, @intCast(i)); |
| 3958 | } | 3958 | } |
| 3959 | 3959 | ||
| 3960 | var slice = try self.shdrs.toOwnedSlice(gpa); | 3960 | const slice = try self.shdrs.toOwnedSlice(gpa); |
| 3961 | defer gpa.free(slice); | 3961 | defer gpa.free(slice); |
| 3962 | 3962 | ||
| 3963 | try self.shdrs.ensureTotalCapacityPrecise(gpa, slice.len); | 3963 | try self.shdrs.ensureTotalCapacityPrecise(gpa, slice.len); |
src/link/Elf/eh_frame.zig+1-1| ... | @@ -217,7 +217,7 @@ pub const Iterator = struct { | ... | @@ -217,7 +217,7 @@ pub const Iterator = struct { |
| 217 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); | 217 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); |
| 218 | const reader = stream.reader(); | 218 | const reader = stream.reader(); |
| 219 | 219 | ||
| 220 | var size = try reader.readInt(u32, .little); | 220 | const size = try reader.readInt(u32, .little); |
| 221 | if (size == 0xFFFFFFFF) @panic("TODO"); | 221 | if (size == 0xFFFFFFFF) @panic("TODO"); |
| 222 | 222 | ||
| 223 | const id = try reader.readInt(u32, .little); | 223 | const id = try reader.readInt(u32, .little); |
src/link/MachO.zig+9-7| ... | @@ -1923,6 +1923,8 @@ fn resolveBoundarySymbols(self: *MachO) !void { | ... | @@ -1923,6 +1923,8 @@ fn resolveBoundarySymbols(self: *MachO) !void { |
| 1923 | _ = self.unresolved.swapRemove(global_index); | 1923 | _ = self.unresolved.swapRemove(global_index); |
| 1924 | continue; | 1924 | continue; |
| 1925 | } | 1925 | } |
| 1926 | |||
| 1927 | next_sym += 1; | ||
| 1926 | } | 1928 | } |
| 1927 | } | 1929 | } |
| 1928 | 1930 | ||
| ... | @@ -2250,7 +2252,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air: | ... | @@ -2250,7 +2252,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air: |
| 2250 | else | 2252 | else |
| 2251 | try codegen.generateFunction(&self.base, decl.srcLoc(mod), func_index, air, liveness, &code_buffer, .none); | 2253 | try codegen.generateFunction(&self.base, decl.srcLoc(mod), func_index, air, liveness, &code_buffer, .none); |
| 2252 | 2254 | ||
| 2253 | var code = switch (res) { | 2255 | const code = switch (res) { |
| 2254 | .ok => code_buffer.items, | 2256 | .ok => code_buffer.items, |
| 2255 | .fail => |em| { | 2257 | .fail => |em| { |
| 2256 | decl.analysis = .codegen_failure; | 2258 | decl.analysis = .codegen_failure; |
| ... | @@ -2330,7 +2332,7 @@ fn lowerConst( | ... | @@ -2330,7 +2332,7 @@ fn lowerConst( |
| 2330 | const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{ | 2332 | const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{ |
| 2331 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, | 2333 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, |
| 2332 | }); | 2334 | }); |
| 2333 | var code = switch (res) { | 2335 | const code = switch (res) { |
| 2334 | .ok => code_buffer.items, | 2336 | .ok => code_buffer.items, |
| 2335 | .fail => |em| return .{ .fail = em }, | 2337 | .fail => |em| return .{ .fail = em }, |
| 2336 | }; | 2338 | }; |
| ... | @@ -2416,7 +2418,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo | ... | @@ -2416,7 +2418,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo |
| 2416 | .parent_atom_index = sym_index, | 2418 | .parent_atom_index = sym_index, |
| 2417 | }); | 2419 | }); |
| 2418 | 2420 | ||
| 2419 | var code = switch (res) { | 2421 | const code = switch (res) { |
| 2420 | .ok => code_buffer.items, | 2422 | .ok => code_buffer.items, |
| 2421 | .fail => |em| { | 2423 | .fail => |em| { |
| 2422 | decl.analysis = .codegen_failure; | 2424 | decl.analysis = .codegen_failure; |
| ... | @@ -2585,7 +2587,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D | ... | @@ -2585,7 +2587,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D |
| 2585 | .parent_atom_index = init_sym_index, | 2587 | .parent_atom_index = init_sym_index, |
| 2586 | }); | 2588 | }); |
| 2587 | 2589 | ||
| 2588 | var code = switch (res) { | 2590 | const code = switch (res) { |
| 2589 | .ok => code_buffer.items, | 2591 | .ok => code_buffer.items, |
| 2590 | .fail => |em| { | 2592 | .fail => |em| { |
| 2591 | decl.analysis = .codegen_failure; | 2593 | decl.analysis = .codegen_failure; |
| ... | @@ -3425,7 +3427,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm | ... | @@ -3425,7 +3427,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm |
| 3425 | 3427 | ||
| 3426 | // First we look for an appropriately sized free list node. | 3428 | // First we look for an appropriately sized free list node. |
| 3427 | // The list is unordered. We'll just take the first thing that works. | 3429 | // The list is unordered. We'll just take the first thing that works. |
| 3428 | var vaddr = blk: { | 3430 | const vaddr = blk: { |
| 3429 | var i: usize = 0; | 3431 | var i: usize = 0; |
| 3430 | while (i < free_list.items.len) { | 3432 | while (i < free_list.items.len) { |
| 3431 | const big_atom_index = free_list.items[i]; | 3433 | const big_atom_index = free_list.items[i]; |
| ... | @@ -3969,7 +3971,7 @@ fn writeDyldInfoData(self: *MachO) !void { | ... | @@ -3969,7 +3971,7 @@ fn writeDyldInfoData(self: *MachO) !void { |
| 3969 | link_seg.filesize = needed_size; | 3971 | link_seg.filesize = needed_size; |
| 3970 | assert(mem.isAlignedGeneric(u64, link_seg.fileoff + link_seg.filesize, @alignOf(u64))); | 3972 | assert(mem.isAlignedGeneric(u64, link_seg.fileoff + link_seg.filesize, @alignOf(u64))); |
| 3971 | 3973 | ||
| 3972 | var buffer = try gpa.alloc(u8, needed_size); | 3974 | const buffer = try gpa.alloc(u8, needed_size); |
| 3973 | defer gpa.free(buffer); | 3975 | defer gpa.free(buffer); |
| 3974 | @memset(buffer, 0); | 3976 | @memset(buffer, 0); |
| 3975 | 3977 | ||
| ... | @@ -5226,7 +5228,7 @@ fn reportMissingLibraryError( | ... | @@ -5226,7 +5228,7 @@ fn reportMissingLibraryError( |
| 5226 | ) error{OutOfMemory}!void { | 5228 | ) error{OutOfMemory}!void { |
| 5227 | const gpa = self.base.allocator; | 5229 | const gpa = self.base.allocator; |
| 5228 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 5230 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 5229 | var notes = try gpa.alloc(File.ErrorMsg, checked_paths.len); | 5231 | const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len); |
| 5230 | errdefer gpa.free(notes); | 5232 | errdefer gpa.free(notes); |
| 5231 | for (checked_paths, notes) |path, *note| { | 5233 | for (checked_paths, notes) |path, *note| { |
| 5232 | note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) }; | 5234 | note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) }; |
src/link/MachO/Archive.zig+3-3| ... | @@ -98,7 +98,7 @@ pub fn parse(self: *Archive, allocator: Allocator, reader: anytype) !void { | ... | @@ -98,7 +98,7 @@ pub fn parse(self: *Archive, allocator: Allocator, reader: anytype) !void { |
| 98 | _ = try reader.readBytesNoEof(SARMAG); | 98 | _ = try reader.readBytesNoEof(SARMAG); |
| 99 | self.header = try reader.readStruct(ar_hdr); | 99 | self.header = try reader.readStruct(ar_hdr); |
| 100 | const name_or_length = try self.header.nameOrLength(); | 100 | const name_or_length = try self.header.nameOrLength(); |
| 101 | var embedded_name = try parseName(allocator, name_or_length, reader); | 101 | const embedded_name = try parseName(allocator, name_or_length, reader); |
| 102 | log.debug("parsing archive '{s}' at '{s}'", .{ embedded_name, self.name }); | 102 | log.debug("parsing archive '{s}' at '{s}'", .{ embedded_name, self.name }); |
| 103 | defer allocator.free(embedded_name); | 103 | defer allocator.free(embedded_name); |
| 104 | 104 | ||
| ... | @@ -124,7 +124,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader: | ... | @@ -124,7 +124,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader: |
| 124 | 124 | ||
| 125 | fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void { | 125 | fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void { |
| 126 | const symtab_size = try reader.readInt(u32, .little); | 126 | const symtab_size = try reader.readInt(u32, .little); |
| 127 | var symtab = try allocator.alloc(u8, symtab_size); | 127 | const symtab = try allocator.alloc(u8, symtab_size); |
| 128 | defer allocator.free(symtab); | 128 | defer allocator.free(symtab); |
| 129 | 129 | ||
| 130 | reader.readNoEof(symtab) catch { | 130 | reader.readNoEof(symtab) catch { |
| ... | @@ -133,7 +133,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! | ... | @@ -133,7 +133,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! |
| 133 | }; | 133 | }; |
| 134 | 134 | ||
| 135 | const strtab_size = try reader.readInt(u32, .little); | 135 | const strtab_size = try reader.readInt(u32, .little); |
| 136 | var strtab = try allocator.alloc(u8, strtab_size); | 136 | const strtab = try allocator.alloc(u8, strtab_size); |
| 137 | defer allocator.free(strtab); | 137 | defer allocator.free(strtab); |
| 138 | 138 | ||
| 139 | reader.readNoEof(strtab) catch { | 139 | reader.readNoEof(strtab) catch { |
src/link/MachO/Dylib.zig+3-3| ... | @@ -167,7 +167,7 @@ pub fn parseFromBinary( | ... | @@ -167,7 +167,7 @@ pub fn parseFromBinary( |
| 167 | .REEXPORT_DYLIB => { | 167 | .REEXPORT_DYLIB => { |
| 168 | if (should_lookup_reexports) { | 168 | if (should_lookup_reexports) { |
| 169 | // Parse install_name to dependent dylib. | 169 | // Parse install_name to dependent dylib. |
| 170 | var id = try Id.fromLoadCommand( | 170 | const id = try Id.fromLoadCommand( |
| 171 | allocator, | 171 | allocator, |
| 172 | cmd.cast(macho.dylib_command).?, | 172 | cmd.cast(macho.dylib_command).?, |
| 173 | cmd.getDylibPathName(), | 173 | cmd.getDylibPathName(), |
| ... | @@ -410,7 +410,7 @@ pub fn parseFromStub( | ... | @@ -410,7 +410,7 @@ pub fn parseFromStub( |
| 410 | 410 | ||
| 411 | log.debug(" (found re-export '{s}')", .{lib}); | 411 | log.debug(" (found re-export '{s}')", .{lib}); |
| 412 | 412 | ||
| 413 | var dep_id = try Id.default(allocator, lib); | 413 | const dep_id = try Id.default(allocator, lib); |
| 414 | try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id }); | 414 | try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id }); |
| 415 | } | 415 | } |
| 416 | } | 416 | } |
| ... | @@ -527,7 +527,7 @@ pub fn parseFromStub( | ... | @@ -527,7 +527,7 @@ pub fn parseFromStub( |
| 527 | 527 | ||
| 528 | log.debug(" (found re-export '{s}')", .{lib}); | 528 | log.debug(" (found re-export '{s}')", .{lib}); |
| 529 | 529 | ||
| 530 | var dep_id = try Id.default(allocator, lib); | 530 | const dep_id = try Id.default(allocator, lib); |
| 531 | try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id }); | 531 | try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id }); |
| 532 | } | 532 | } |
| 533 | } | 533 | } |
src/link/MachO/Trie.zig+8-8| ... | @@ -150,7 +150,7 @@ pub fn deinit(self: *Trie, allocator: Allocator) void { | ... | @@ -150,7 +150,7 @@ pub fn deinit(self: *Trie, allocator: Allocator) void { |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | test "Trie node count" { | 152 | test "Trie node count" { |
| 153 | var gpa = testing.allocator; | 153 | const gpa = testing.allocator; |
| 154 | var trie: Trie = .{}; | 154 | var trie: Trie = .{}; |
| 155 | defer trie.deinit(gpa); | 155 | defer trie.deinit(gpa); |
| 156 | try trie.init(gpa); | 156 | try trie.init(gpa); |
| ... | @@ -196,7 +196,7 @@ test "Trie node count" { | ... | @@ -196,7 +196,7 @@ test "Trie node count" { |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | test "Trie basic" { | 198 | test "Trie basic" { |
| 199 | var gpa = testing.allocator; | 199 | const gpa = testing.allocator; |
| 200 | var trie: Trie = .{}; | 200 | var trie: Trie = .{}; |
| 201 | defer trie.deinit(gpa); | 201 | defer trie.deinit(gpa); |
| 202 | try trie.init(gpa); | 202 | try trie.init(gpa); |
| ... | @@ -254,7 +254,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void { | ... | @@ -254,7 +254,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void { |
| 254 | const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)}); | 254 | const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)}); |
| 255 | defer testing.allocator.free(given_fmt); | 255 | defer testing.allocator.free(given_fmt); |
| 256 | const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?; | 256 | const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?; |
| 257 | var padding = try testing.allocator.alloc(u8, idx + 5); | 257 | const padding = try testing.allocator.alloc(u8, idx + 5); |
| 258 | defer testing.allocator.free(padding); | 258 | defer testing.allocator.free(padding); |
| 259 | @memset(padding, ' '); | 259 | @memset(padding, ' '); |
| 260 | std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding }); | 260 | std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding }); |
| ... | @@ -292,7 +292,7 @@ test "write Trie to a byte stream" { | ... | @@ -292,7 +292,7 @@ test "write Trie to a byte stream" { |
| 292 | 0x3, 0x0, 0x80, 0x20, 0x0, // terminal node | 292 | 0x3, 0x0, 0x80, 0x20, 0x0, // terminal node |
| 293 | }; | 293 | }; |
| 294 | 294 | ||
| 295 | var buffer = try gpa.alloc(u8, trie.size); | 295 | const buffer = try gpa.alloc(u8, trie.size); |
| 296 | defer gpa.free(buffer); | 296 | defer gpa.free(buffer); |
| 297 | var stream = std.io.fixedBufferStream(buffer); | 297 | var stream = std.io.fixedBufferStream(buffer); |
| 298 | { | 298 | { |
| ... | @@ -331,7 +331,7 @@ test "parse Trie from byte stream" { | ... | @@ -331,7 +331,7 @@ test "parse Trie from byte stream" { |
| 331 | 331 | ||
| 332 | try trie.finalize(gpa); | 332 | try trie.finalize(gpa); |
| 333 | 333 | ||
| 334 | var out_buffer = try gpa.alloc(u8, trie.size); | 334 | const out_buffer = try gpa.alloc(u8, trie.size); |
| 335 | defer gpa.free(out_buffer); | 335 | defer gpa.free(out_buffer); |
| 336 | var out_stream = std.io.fixedBufferStream(out_buffer); | 336 | var out_stream = std.io.fixedBufferStream(out_buffer); |
| 337 | _ = try trie.write(out_stream.writer()); | 337 | _ = try trie.write(out_stream.writer()); |
| ... | @@ -362,7 +362,7 @@ test "ordering bug" { | ... | @@ -362,7 +362,7 @@ test "ordering bug" { |
| 362 | 0x00, 0x12, 0x03, 0x00, 0xD8, 0x0A, 0x00, | 362 | 0x00, 0x12, 0x03, 0x00, 0xD8, 0x0A, 0x00, |
| 363 | }; | 363 | }; |
| 364 | 364 | ||
| 365 | var buffer = try gpa.alloc(u8, trie.size); | 365 | const buffer = try gpa.alloc(u8, trie.size); |
| 366 | defer gpa.free(buffer); | 366 | defer gpa.free(buffer); |
| 367 | var stream = std.io.fixedBufferStream(buffer); | 367 | var stream = std.io.fixedBufferStream(buffer); |
| 368 | // Writing finalized trie again should yield the same result. | 368 | // Writing finalized trie again should yield the same result. |
| ... | @@ -426,7 +426,7 @@ pub const Node = struct { | ... | @@ -426,7 +426,7 @@ pub const Node = struct { |
| 426 | // To: A -> C -> B | 426 | // To: A -> C -> B |
| 427 | const mid = try allocator.create(Node); | 427 | const mid = try allocator.create(Node); |
| 428 | mid.* = .{ .base = self.base }; | 428 | mid.* = .{ .base = self.base }; |
| 429 | var to_label = try allocator.dupe(u8, edge.label[match..]); | 429 | const to_label = try allocator.dupe(u8, edge.label[match..]); |
| 430 | allocator.free(edge.label); | 430 | allocator.free(edge.label); |
| 431 | const to_node = edge.to; | 431 | const to_node = edge.to; |
| 432 | edge.to = mid; | 432 | edge.to = mid; |
| ... | @@ -573,7 +573,7 @@ pub const Node = struct { | ... | @@ -573,7 +573,7 @@ pub const Node = struct { |
| 573 | /// Updates offset of this node in the output byte stream. | 573 | /// Updates offset of this node in the output byte stream. |
| 574 | fn finalize(self: *Node, offset_in_trie: u64) !FinalizeResult { | 574 | fn finalize(self: *Node, offset_in_trie: u64) !FinalizeResult { |
| 575 | var stream = std.io.countingWriter(std.io.null_writer); | 575 | var stream = std.io.countingWriter(std.io.null_writer); |
| 576 | var writer = stream.writer(); | 576 | const writer = stream.writer(); |
| 577 | 577 | ||
| 578 | var node_size: u64 = 0; | 578 | var node_size: u64 = 0; |
| 579 | if (self.terminal_info) |info| { | 579 | if (self.terminal_info) |info| { |
src/link/MachO/UnwindInfo.zig+1-1| ... | @@ -417,7 +417,7 @@ pub fn collect(info: *UnwindInfo, macho_file: *MachO) !void { | ... | @@ -417,7 +417,7 @@ pub fn collect(info: *UnwindInfo, macho_file: *MachO) !void { |
| 417 | gop.value_ptr.count += 1; | 417 | gop.value_ptr.count += 1; |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | var slice = common_encodings_counts.values(); | 420 | const slice = common_encodings_counts.values(); |
| 421 | mem.sort(CommonEncWithCount, slice, {}, CommonEncWithCount.greaterThan); | 421 | mem.sort(CommonEncWithCount, slice, {}, CommonEncWithCount.greaterThan); |
| 422 | 422 | ||
| 423 | var i: u7 = 0; | 423 | var i: u7 = 0; |
src/link/MachO/eh_frame.zig+1-1| ... | @@ -586,7 +586,7 @@ pub const Iterator = struct { | ... | @@ -586,7 +586,7 @@ pub const Iterator = struct { |
| 586 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); | 586 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); |
| 587 | const reader = stream.reader(); | 587 | const reader = stream.reader(); |
| 588 | 588 | ||
| 589 | var size = try reader.readInt(u32, .little); | 589 | const size = try reader.readInt(u32, .little); |
| 590 | if (size == 0xFFFFFFFF) { | 590 | if (size == 0xFFFFFFFF) { |
| 591 | log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{}); | 591 | log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{}); |
| 592 | return error.BadDwarfCfi; | 592 | return error.BadDwarfCfi; |
src/link/MachO/load_commands.zig+1-1| ... | @@ -112,7 +112,7 @@ pub fn calcMinHeaderPad(gpa: Allocator, options: *const link.Options, ctx: CalcL | ... | @@ -112,7 +112,7 @@ pub fn calcMinHeaderPad(gpa: Allocator, options: *const link.Options, ctx: CalcL |
| 112 | log.debug("minimum requested headerpad size 0x{x}", .{padding + @sizeOf(macho.mach_header_64)}); | 112 | log.debug("minimum requested headerpad size 0x{x}", .{padding + @sizeOf(macho.mach_header_64)}); |
| 113 | 113 | ||
| 114 | if (options.headerpad_max_install_names) { | 114 | if (options.headerpad_max_install_names) { |
| 115 | var min_headerpad_size: u32 = try calcLCsSize(gpa, options, ctx, true); | 115 | const min_headerpad_size: u32 = try calcLCsSize(gpa, options, ctx, true); |
| 116 | log.debug("headerpad_max_install_names minimum headerpad size 0x{x}", .{ | 116 | log.debug("headerpad_max_install_names minimum headerpad size 0x{x}", .{ |
| 117 | min_headerpad_size + @sizeOf(macho.mach_header_64), | 117 | min_headerpad_size + @sizeOf(macho.mach_header_64), |
| 118 | }); | 118 | }); |
src/link/MachO/zld.zig+1-1| ... | @@ -503,7 +503,7 @@ pub fn linkWithZld( | ... | @@ -503,7 +503,7 @@ pub fn linkWithZld( |
| 503 | const size = math.cast(usize, linkedit.fileoff - start) orelse return error.Overflow; | 503 | const size = math.cast(usize, linkedit.fileoff - start) orelse return error.Overflow; |
| 504 | if (size > 0) { | 504 | if (size > 0) { |
| 505 | log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start }); | 505 | log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start }); |
| 506 | var padding = try gpa.alloc(u8, size); | 506 | const padding = try gpa.alloc(u8, size); |
| 507 | defer gpa.free(padding); | 507 | defer gpa.free(padding); |
| 508 | @memset(padding, 0); | 508 | @memset(padding, 0); |
| 509 | try macho_file.base.file.?.pwriteAll(padding, start); | 509 | try macho_file.base.file.?.pwriteAll(padding, start); |
src/link/Plan9.zig+6-6| ... | @@ -300,7 +300,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Plan9 { | ... | @@ -300,7 +300,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Plan9 { |
| 300 | else => return error.UnsupportedP9Architecture, | 300 | else => return error.UnsupportedP9Architecture, |
| 301 | }; | 301 | }; |
| 302 | 302 | ||
| 303 | var arena_allocator = std.heap.ArenaAllocator.init(gpa); | 303 | const arena_allocator = std.heap.ArenaAllocator.init(gpa); |
| 304 | 304 | ||
| 305 | const self = try gpa.create(Plan9); | 305 | const self = try gpa.create(Plan9); |
| 306 | self.* = .{ | 306 | self.* = .{ |
| ... | @@ -467,7 +467,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I | ... | @@ -467,7 +467,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I |
| 467 | 467 | ||
| 468 | const sym_index = try self.allocateSymbolIndex(); | 468 | const sym_index = try self.allocateSymbolIndex(); |
| 469 | const new_atom_idx = try self.createAtom(); | 469 | const new_atom_idx = try self.createAtom(); |
| 470 | var info: Atom = .{ | 470 | const info: Atom = .{ |
| 471 | .type = .d, | 471 | .type = .d, |
| 472 | .offset = null, | 472 | .offset = null, |
| 473 | .sym_index = sym_index, | 473 | .sym_index = sym_index, |
| ... | @@ -496,7 +496,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I | ... | @@ -496,7 +496,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I |
| 496 | }, | 496 | }, |
| 497 | }; | 497 | }; |
| 498 | // duped_code is freed when the unnamed const is freed | 498 | // duped_code is freed when the unnamed const is freed |
| 499 | var duped_code = try self.base.allocator.dupe(u8, code); | 499 | const duped_code = try self.base.allocator.dupe(u8, code); |
| 500 | errdefer self.base.allocator.free(duped_code); | 500 | errdefer self.base.allocator.free(duped_code); |
| 501 | const new_atom = self.getAtomPtr(new_atom_idx); | 501 | const new_atom = self.getAtomPtr(new_atom_idx); |
| 502 | new_atom.* = info; | 502 | new_atom.* = info; |
| ... | @@ -1024,7 +1024,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void { | ... | @@ -1024,7 +1024,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void { |
| 1024 | const decl = mod.declPtr(decl_index); | 1024 | const decl = mod.declPtr(decl_index); |
| 1025 | const is_fn = decl.val.isFuncBody(mod); | 1025 | const is_fn = decl.val.isFuncBody(mod); |
| 1026 | if (is_fn) { | 1026 | if (is_fn) { |
| 1027 | var symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?; | 1027 | const symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?; |
| 1028 | var submap = symidx_and_submap.functions; | 1028 | var submap = symidx_and_submap.functions; |
| 1029 | if (submap.fetchSwapRemove(decl_index)) |removed_entry| { | 1029 | if (submap.fetchSwapRemove(decl_index)) |removed_entry| { |
| 1030 | self.base.allocator.free(removed_entry.value.code); | 1030 | self.base.allocator.free(removed_entry.value.code); |
| ... | @@ -1204,7 +1204,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind | ... | @@ -1204,7 +1204,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind |
| 1204 | }, | 1204 | }, |
| 1205 | }; | 1205 | }; |
| 1206 | // duped_code is freed when the atom is freed | 1206 | // duped_code is freed when the atom is freed |
| 1207 | var duped_code = try self.base.allocator.dupe(u8, code); | 1207 | const duped_code = try self.base.allocator.dupe(u8, code); |
| 1208 | errdefer self.base.allocator.free(duped_code); | 1208 | errdefer self.base.allocator.free(duped_code); |
| 1209 | self.getAtomPtr(atom_index).code = .{ | 1209 | self.getAtomPtr(atom_index).code = .{ |
| 1210 | .code_ptr = duped_code.ptr, | 1210 | .code_ptr = duped_code.ptr, |
| ... | @@ -1489,7 +1489,7 @@ pub fn lowerAnonDecl(self: *Plan9, decl_val: InternPool.Index, src_loc: Module.S | ... | @@ -1489,7 +1489,7 @@ pub fn lowerAnonDecl(self: *Plan9, decl_val: InternPool.Index, src_loc: Module.S |
| 1489 | // to put it in some location. | 1489 | // to put it in some location. |
| 1490 | // ... | 1490 | // ... |
| 1491 | const gpa = self.base.allocator; | 1491 | const gpa = self.base.allocator; |
| 1492 | var gop = try self.anon_decls.getOrPut(gpa, decl_val); | 1492 | const gop = try self.anon_decls.getOrPut(gpa, decl_val); |
| 1493 | const mod = self.base.options.module.?; | 1493 | const mod = self.base.options.module.?; |
| 1494 | if (!gop.found_existing) { | 1494 | if (!gop.found_existing) { |
| 1495 | const ty = mod.intern_pool.typeOf(decl_val).toType(); | 1495 | const ty = mod.intern_pool.typeOf(decl_val).toType(); |
src/link/Wasm.zig+5-5| ... | @@ -860,7 +860,7 @@ fn resolveSymbolsInArchives(wasm: *Wasm) !void { | ... | @@ -860,7 +860,7 @@ fn resolveSymbolsInArchives(wasm: *Wasm) !void { |
| 860 | // Parse object and and resolve symbols again before we check remaining | 860 | // Parse object and and resolve symbols again before we check remaining |
| 861 | // undefined symbols. | 861 | // undefined symbols. |
| 862 | const object_file_index = @as(u16, @intCast(wasm.objects.items.len)); | 862 | const object_file_index = @as(u16, @intCast(wasm.objects.items.len)); |
| 863 | var object = try archive.parseObject(wasm.base.allocator, offset.items[0]); | 863 | const object = try archive.parseObject(wasm.base.allocator, offset.items[0]); |
| 864 | try wasm.objects.append(wasm.base.allocator, object); | 864 | try wasm.objects.append(wasm.base.allocator, object); |
| 865 | try wasm.resolveSymbolsInObject(object_file_index); | 865 | try wasm.resolveSymbolsInObject(object_file_index); |
| 866 | 866 | ||
| ... | @@ -1344,7 +1344,7 @@ pub fn deinit(wasm: *Wasm) void { | ... | @@ -1344,7 +1344,7 @@ pub fn deinit(wasm: *Wasm) void { |
| 1344 | /// Will re-use slots when a symbol was freed at an earlier stage. | 1344 | /// Will re-use slots when a symbol was freed at an earlier stage. |
| 1345 | pub fn allocateSymbol(wasm: *Wasm) !u32 { | 1345 | pub fn allocateSymbol(wasm: *Wasm) !u32 { |
| 1346 | try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1); | 1346 | try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1); |
| 1347 | var symbol: Symbol = .{ | 1347 | const symbol: Symbol = .{ |
| 1348 | .name = std.math.maxInt(u32), // will be set after updateDecl as well as during atom creation for decls | 1348 | .name = std.math.maxInt(u32), // will be set after updateDecl as well as during atom creation for decls |
| 1349 | .flags = @intFromEnum(Symbol.Flag.WASM_SYM_BINDING_LOCAL), | 1349 | .flags = @intFromEnum(Symbol.Flag.WASM_SYM_BINDING_LOCAL), |
| 1350 | .tag = .undefined, // will be set after updateDecl | 1350 | .tag = .undefined, // will be set after updateDecl |
| ... | @@ -1655,7 +1655,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3 | ... | @@ -1655,7 +1655,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3 |
| 1655 | symbol.setUndefined(true); | 1655 | symbol.setUndefined(true); |
| 1656 | 1656 | ||
| 1657 | const sym_index = if (wasm.symbols_free_list.popOrNull()) |index| index else blk: { | 1657 | const sym_index = if (wasm.symbols_free_list.popOrNull()) |index| index else blk: { |
| 1658 | var index = @as(u32, @intCast(wasm.symbols.items.len)); | 1658 | const index: u32 = @intCast(wasm.symbols.items.len); |
| 1659 | try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1); | 1659 | try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1); |
| 1660 | wasm.symbols.items.len += 1; | 1660 | wasm.symbols.items.len += 1; |
| 1661 | break :blk index; | 1661 | break :blk index; |
| ... | @@ -2632,7 +2632,7 @@ fn setupImports(wasm: *Wasm) !void { | ... | @@ -2632,7 +2632,7 @@ fn setupImports(wasm: *Wasm) !void { |
| 2632 | 2632 | ||
| 2633 | // We copy the import to a new import to ensure the names contain references | 2633 | // We copy the import to a new import to ensure the names contain references |
| 2634 | // to the internal string table, rather than of the object file. | 2634 | // to the internal string table, rather than of the object file. |
| 2635 | var new_imp: types.Import = .{ | 2635 | const new_imp: types.Import = .{ |
| 2636 | .module_name = try wasm.string_table.put(wasm.base.allocator, object.string_table.get(import.module_name)), | 2636 | .module_name = try wasm.string_table.put(wasm.base.allocator, object.string_table.get(import.module_name)), |
| 2637 | .name = try wasm.string_table.put(wasm.base.allocator, object.string_table.get(import.name)), | 2637 | .name = try wasm.string_table.put(wasm.base.allocator, object.string_table.get(import.name)), |
| 2638 | .kind = import.kind, | 2638 | .kind = import.kind, |
| ... | @@ -3800,7 +3800,7 @@ fn writeToFile( | ... | @@ -3800,7 +3800,7 @@ fn writeToFile( |
| 3800 | const table_loc = wasm.findGlobalSymbol("__indirect_function_table").?; | 3800 | const table_loc = wasm.findGlobalSymbol("__indirect_function_table").?; |
| 3801 | const table_sym = table_loc.getSymbol(wasm); | 3801 | const table_sym = table_loc.getSymbol(wasm); |
| 3802 | 3802 | ||
| 3803 | var flags: u32 = if (table_sym.index == 0) 0x0 else 0x02; // passive with implicit 0-index table or set table index manually | 3803 | const flags: u32 = if (table_sym.index == 0) 0x0 else 0x02; // passive with implicit 0-index table or set table index manually |
| 3804 | try leb.writeULEB128(binary_writer, flags); | 3804 | try leb.writeULEB128(binary_writer, flags); |
| 3805 | if (flags == 0x02) { | 3805 | if (flags == 0x02) { |
| 3806 | try leb.writeULEB128(binary_writer, table_sym.index); | 3806 | try leb.writeULEB128(binary_writer, table_sym.index); |
src/link/Wasm/Object.zig+3-3| ... | @@ -252,7 +252,7 @@ fn checkLegacyIndirectFunctionTable(object: *Object) !?Symbol { | ... | @@ -252,7 +252,7 @@ fn checkLegacyIndirectFunctionTable(object: *Object) !?Symbol { |
| 252 | return error.MissingTableSymbols; | 252 | return error.MissingTableSymbols; |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | var table_import: types.Import = for (object.imports) |imp| { | 255 | const table_import: types.Import = for (object.imports) |imp| { |
| 256 | if (imp.kind == .table) { | 256 | if (imp.kind == .table) { |
| 257 | break imp; | 257 | break imp; |
| 258 | } | 258 | } |
| ... | @@ -512,7 +512,7 @@ fn Parser(comptime ReaderType: type) type { | ... | @@ -512,7 +512,7 @@ fn Parser(comptime ReaderType: type) type { |
| 512 | try assertEnd(reader); | 512 | try assertEnd(reader); |
| 513 | }, | 513 | }, |
| 514 | .code => { | 514 | .code => { |
| 515 | var start = reader.context.bytes_left; | 515 | const start = reader.context.bytes_left; |
| 516 | var index: u32 = 0; | 516 | var index: u32 = 0; |
| 517 | const count = try readLeb(u32, reader); | 517 | const count = try readLeb(u32, reader); |
| 518 | while (index < count) : (index += 1) { | 518 | while (index < count) : (index += 1) { |
| ... | @@ -532,7 +532,7 @@ fn Parser(comptime ReaderType: type) type { | ... | @@ -532,7 +532,7 @@ fn Parser(comptime ReaderType: type) type { |
| 532 | } | 532 | } |
| 533 | }, | 533 | }, |
| 534 | .data => { | 534 | .data => { |
| 535 | var start = reader.context.bytes_left; | 535 | const start = reader.context.bytes_left; |
| 536 | var index: u32 = 0; | 536 | var index: u32 = 0; |
| 537 | const count = try readLeb(u32, reader); | 537 | const count = try readLeb(u32, reader); |
| 538 | while (index < count) : (index += 1) { | 538 | while (index < count) : (index += 1) { |
src/link/tapi/yaml.zig+1-1| ... | @@ -491,7 +491,7 @@ pub fn stringify(allocator: Allocator, input: anytype, writer: anytype) !void { | ... | @@ -491,7 +491,7 @@ pub fn stringify(allocator: Allocator, input: anytype, writer: anytype) !void { |
| 491 | var arena = ArenaAllocator.init(allocator); | 491 | var arena = ArenaAllocator.init(allocator); |
| 492 | defer arena.deinit(); | 492 | defer arena.deinit(); |
| 493 | 493 | ||
| 494 | var maybe_value = try Value.encode(arena.allocator(), input); | 494 | const maybe_value = try Value.encode(arena.allocator(), input); |
| 495 | 495 | ||
| 496 | if (maybe_value) |value| { | 496 | if (maybe_value) |value| { |
| 497 | // TODO should we output as an explicit doc? | 497 | // TODO should we output as an explicit doc? |
src/main.zig+7-7| ... | @@ -4479,7 +4479,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -4479,7 +4479,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4479 | try stdout_writer.writeByte('\n'); | 4479 | try stdout_writer.writeByte('\n'); |
| 4480 | } | 4480 | } |
| 4481 | 4481 | ||
| 4482 | var full_input = full_input: { | 4482 | const full_input = full_input: { |
| 4483 | if (options.preprocess != .no) { | 4483 | if (options.preprocess != .no) { |
| 4484 | if (!build_options.have_llvm) { | 4484 | if (!build_options.have_llvm) { |
| 4485 | fatal("clang not available: compiler built without LLVM extensions", .{}); | 4485 | fatal("clang not available: compiler built without LLVM extensions", .{}); |
| ... | @@ -4526,7 +4526,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -4526,7 +4526,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4526 | } | 4526 | } |
| 4527 | 4527 | ||
| 4528 | if (process.can_spawn) { | 4528 | if (process.can_spawn) { |
| 4529 | var result = std.ChildProcess.run(.{ | 4529 | const result = std.ChildProcess.run(.{ |
| 4530 | .allocator = gpa, | 4530 | .allocator = gpa, |
| 4531 | .argv = argv.items, | 4531 | .argv = argv.items, |
| 4532 | .max_output_bytes = std.math.maxInt(u32), | 4532 | .max_output_bytes = std.math.maxInt(u32), |
| ... | @@ -4593,7 +4593,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -4593,7 +4593,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4593 | var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(gpa, full_input, full_input, .{ .initial_filename = options.input_filename }); | 4593 | var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(gpa, full_input, full_input, .{ .initial_filename = options.input_filename }); |
| 4594 | defer mapping_results.mappings.deinit(gpa); | 4594 | defer mapping_results.mappings.deinit(gpa); |
| 4595 | 4595 | ||
| 4596 | var final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); | 4596 | const final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); |
| 4597 | 4597 | ||
| 4598 | var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| { | 4598 | var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| { |
| 4599 | try resinator.utils.renderErrorMessage(stderr.writer(), stderr_config, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) }); | 4599 | try resinator.utils.renderErrorMessage(stderr.writer(), stderr_config, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) }); |
| ... | @@ -4762,7 +4762,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void { | ... | @@ -4762,7 +4762,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void { |
| 4762 | 4762 | ||
| 4763 | const libc_installation: ?*LibCInstallation = libc: { | 4763 | const libc_installation: ?*LibCInstallation = libc: { |
| 4764 | if (input_file) |libc_file| { | 4764 | if (input_file) |libc_file| { |
| 4765 | var libc = try arena.create(LibCInstallation); | 4765 | const libc = try arena.create(LibCInstallation); |
| 4766 | libc.* = LibCInstallation.parse(arena, libc_file, cross_target) catch |err| { | 4766 | libc.* = LibCInstallation.parse(arena, libc_file, cross_target) catch |err| { |
| 4767 | fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) }); | 4767 | fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) }); |
| 4768 | }; | 4768 | }; |
| ... | @@ -4781,7 +4781,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void { | ... | @@ -4781,7 +4781,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void { |
| 4781 | const target = cross_target.toTarget(); | 4781 | const target = cross_target.toTarget(); |
| 4782 | const is_native_abi = cross_target.isNativeAbi(); | 4782 | const is_native_abi = cross_target.isNativeAbi(); |
| 4783 | 4783 | ||
| 4784 | var libc_dirs = Compilation.detectLibCIncludeDirs( | 4784 | const libc_dirs = Compilation.detectLibCIncludeDirs( |
| 4785 | arena, | 4785 | arena, |
| 4786 | zig_lib_directory.path.?, | 4786 | zig_lib_directory.path.?, |
| 4787 | target, | 4787 | target, |
| ... | @@ -4960,7 +4960,7 @@ pub const usage_build = | ... | @@ -4960,7 +4960,7 @@ pub const usage_build = |
| 4960 | pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | 4960 | pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4961 | const work_around_btrfs_bug = builtin.os.tag == .linux and | 4961 | const work_around_btrfs_bug = builtin.os.tag == .linux and |
| 4962 | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); | 4962 | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); |
| 4963 | var color: Color = .auto; | 4963 | const color: Color = .auto; |
| 4964 | 4964 | ||
| 4965 | // We want to release all the locks before executing the child process, so we make a nice | 4965 | // We want to release all the locks before executing the child process, so we make a nice |
| 4966 | // big block here to ensure the cleanup gets run when we extract out our argv. | 4966 | // big block here to ensure the cleanup gets run when we extract out our argv. |
| ... | @@ -6001,7 +6001,7 @@ const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true, | ... | @@ -6001,7 +6001,7 @@ const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true, |
| 6001 | /// Initialize the arguments from a Response File. "*.rsp" | 6001 | /// Initialize the arguments from a Response File. "*.rsp" |
| 6002 | fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile { | 6002 | fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile { |
| 6003 | const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit | 6003 | const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit |
| 6004 | var cmd_line = try fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes); | 6004 | const cmd_line = try fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes); |
| 6005 | errdefer allocator.free(cmd_line); | 6005 | errdefer allocator.free(cmd_line); |
| 6006 | 6006 | ||
| 6007 | return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line); | 6007 | return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line); |
src/resinator/bmp.zig+1-1| ... | @@ -120,7 +120,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { | ... | @@ -120,7 +120,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { |
| 120 | var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined; | 120 | var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined; |
| 121 | std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little); | 121 | std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little); |
| 122 | reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; | 122 | reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; |
| 123 | var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); | 123 | const dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); |
| 124 | structFieldsLittleToNative(BITMAPCOREHEADER, dib_header); | 124 | structFieldsLittleToNative(BITMAPCOREHEADER, dib_header); |
| 125 | 125 | ||
| 126 | // > The size of the color palette is calculated from the BitsPerPixel value. | 126 | // > The size of the color palette is calculated from the BitsPerPixel value. |
src/resinator/cli.zig+5-5| ... | @@ -163,15 +163,15 @@ pub const Options = struct { | ... | @@ -163,15 +163,15 @@ pub const Options = struct { |
| 163 | // we shouldn't change anything. | 163 | // we shouldn't change anything. |
| 164 | if (val_ptr.* == .undefine) return; | 164 | if (val_ptr.* == .undefine) return; |
| 165 | // Otherwise, the new value takes precedence. | 165 | // Otherwise, the new value takes precedence. |
| 166 | var duped_value = try self.allocator.dupe(u8, value); | 166 | const duped_value = try self.allocator.dupe(u8, value); |
| 167 | errdefer self.allocator.free(duped_value); | 167 | errdefer self.allocator.free(duped_value); |
| 168 | val_ptr.deinit(self.allocator); | 168 | val_ptr.deinit(self.allocator); |
| 169 | val_ptr.* = .{ .define = duped_value }; | 169 | val_ptr.* = .{ .define = duped_value }; |
| 170 | return; | 170 | return; |
| 171 | } | 171 | } |
| 172 | var duped_key = try self.allocator.dupe(u8, identifier); | 172 | const duped_key = try self.allocator.dupe(u8, identifier); |
| 173 | errdefer self.allocator.free(duped_key); | 173 | errdefer self.allocator.free(duped_key); |
| 174 | var duped_value = try self.allocator.dupe(u8, value); | 174 | const duped_value = try self.allocator.dupe(u8, value); |
| 175 | errdefer self.allocator.free(duped_value); | 175 | errdefer self.allocator.free(duped_value); |
| 176 | try self.symbols.put(self.allocator, duped_key, .{ .define = duped_value }); | 176 | try self.symbols.put(self.allocator, duped_key, .{ .define = duped_value }); |
| 177 | } | 177 | } |
| ... | @@ -183,7 +183,7 @@ pub const Options = struct { | ... | @@ -183,7 +183,7 @@ pub const Options = struct { |
| 183 | action.* = .{ .undefine = {} }; | 183 | action.* = .{ .undefine = {} }; |
| 184 | return; | 184 | return; |
| 185 | } | 185 | } |
| 186 | var duped_key = try self.allocator.dupe(u8, identifier); | 186 | const duped_key = try self.allocator.dupe(u8, identifier); |
| 187 | errdefer self.allocator.free(duped_key); | 187 | errdefer self.allocator.free(duped_key); |
| 188 | try self.symbols.put(self.allocator, duped_key, .{ .undefine = {} }); | 188 | try self.symbols.put(self.allocator, duped_key, .{ .undefine = {} }); |
| 189 | } | 189 | } |
| ... | @@ -828,7 +828,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -828,7 +828,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 828 | } | 828 | } |
| 829 | } | 829 | } |
| 830 | 830 | ||
| 831 | var positionals = args[arg_i..]; | 831 | const positionals = args[arg_i..]; |
| 832 | 832 | ||
| 833 | if (positionals.len < 1) { | 833 | if (positionals.len < 1) { |
| 834 | var err_details = Diagnostics.ErrorDetails{ .print_args = false, .arg_index = arg_i }; | 834 | var err_details = Diagnostics.ErrorDetails{ .print_args = false, .arg_index = arg_i }; |
src/resinator/code_pages.zig+3-3| ... | @@ -302,8 +302,8 @@ pub const Utf8 = struct { | ... | @@ -302,8 +302,8 @@ pub const Utf8 = struct { |
| 302 | 302 | ||
| 303 | pub fn decode(bytes: []const u8) Codepoint { | 303 | pub fn decode(bytes: []const u8) Codepoint { |
| 304 | std.debug.assert(bytes.len > 0); | 304 | std.debug.assert(bytes.len > 0); |
| 305 | var first_byte = bytes[0]; | 305 | const first_byte = bytes[0]; |
| 306 | var expected_len = sequenceLength(first_byte) orelse { | 306 | const expected_len = sequenceLength(first_byte) orelse { |
| 307 | return .{ .value = Codepoint.invalid, .byte_len = 1 }; | 307 | return .{ .value = Codepoint.invalid, .byte_len = 1 }; |
| 308 | }; | 308 | }; |
| 309 | if (expected_len == 1) return .{ .value = first_byte, .byte_len = 1 }; | 309 | if (expected_len == 1) return .{ .value = first_byte, .byte_len = 1 }; |
| ... | @@ -367,7 +367,7 @@ pub const Utf8 = struct { | ... | @@ -367,7 +367,7 @@ pub const Utf8 = struct { |
| 367 | 367 | ||
| 368 | test "Utf8.WellFormedDecoder" { | 368 | test "Utf8.WellFormedDecoder" { |
| 369 | const invalid_utf8 = "\xF0\x80"; | 369 | const invalid_utf8 = "\xF0\x80"; |
| 370 | var decoded = Utf8.WellFormedDecoder.decode(invalid_utf8); | 370 | const decoded = Utf8.WellFormedDecoder.decode(invalid_utf8); |
| 371 | try std.testing.expectEqual(Codepoint.invalid, decoded.value); | 371 | try std.testing.expectEqual(Codepoint.invalid, decoded.value); |
| 372 | try std.testing.expectEqual(@as(usize, 2), decoded.byte_len); | 372 | try std.testing.expectEqual(@as(usize, 2), decoded.byte_len); |
| 373 | } | 373 | } |
src/resinator/comments.zig+4-4| ... | @@ -206,9 +206,9 @@ inline fn handleMultilineCarriageReturn( | ... | @@ -206,9 +206,9 @@ inline fn handleMultilineCarriageReturn( |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | pub fn removeCommentsAlloc(allocator: Allocator, source: []const u8, source_mappings: ?*SourceMappings) ![]u8 { | 208 | pub fn removeCommentsAlloc(allocator: Allocator, source: []const u8, source_mappings: ?*SourceMappings) ![]u8 { |
| 209 | var buf = try allocator.alloc(u8, source.len); | 209 | const buf = try allocator.alloc(u8, source.len); |
| 210 | errdefer allocator.free(buf); | 210 | errdefer allocator.free(buf); |
| 211 | var result = removeComments(source, buf, source_mappings); | 211 | const result = removeComments(source, buf, source_mappings); |
| 212 | return allocator.realloc(buf, result.len); | 212 | return allocator.realloc(buf, result.len); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| ... | @@ -326,7 +326,7 @@ test "remove comments with mappings" { | ... | @@ -326,7 +326,7 @@ test "remove comments with mappings" { |
| 326 | try mappings.set(allocator, 3, .{ .start_line = 3, .end_line = 3, .filename_offset = 0 }); | 326 | try mappings.set(allocator, 3, .{ .start_line = 3, .end_line = 3, .filename_offset = 0 }); |
| 327 | defer mappings.deinit(allocator); | 327 | defer mappings.deinit(allocator); |
| 328 | 328 | ||
| 329 | var result = removeComments(&mut_source, &mut_source, &mappings); | 329 | const result = removeComments(&mut_source, &mut_source, &mappings); |
| 330 | 330 | ||
| 331 | try std.testing.expectEqualStrings("blahblah", result); | 331 | try std.testing.expectEqualStrings("blahblah", result); |
| 332 | try std.testing.expectEqual(@as(usize, 1), mappings.mapping.items.len); | 332 | try std.testing.expectEqual(@as(usize, 1), mappings.mapping.items.len); |
| ... | @@ -335,6 +335,6 @@ test "remove comments with mappings" { | ... | @@ -335,6 +335,6 @@ test "remove comments with mappings" { |
| 335 | 335 | ||
| 336 | test "in place" { | 336 | test "in place" { |
| 337 | var mut_source = "blah /* comment */ blah".*; | 337 | var mut_source = "blah /* comment */ blah".*; |
| 338 | var result = removeComments(&mut_source, &mut_source, null); | 338 | const result = removeComments(&mut_source, &mut_source, null); |
| 339 | try std.testing.expectEqualStrings("blah blah", result); | 339 | try std.testing.expectEqualStrings("blah blah", result); |
| 340 | } | 340 | } |
src/resinator/compile.zig+4-4| ... | @@ -666,7 +666,7 @@ pub const Compiler = struct { | ... | @@ -666,7 +666,7 @@ pub const Compiler = struct { |
| 666 | }, | 666 | }, |
| 667 | }, | 667 | }, |
| 668 | .dib => { | 668 | .dib => { |
| 669 | var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); | 669 | const bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); |
| 670 | if (native_endian == .big) { | 670 | if (native_endian == .big) { |
| 671 | std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header); | 671 | std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header); |
| 672 | } | 672 | } |
| ... | @@ -1773,13 +1773,13 @@ pub const Compiler = struct { | ... | @@ -1773,13 +1773,13 @@ pub const Compiler = struct { |
| 1773 | } | 1773 | } |
| 1774 | try data_writer.writeByteNTimes(0, num_padding); | 1774 | try data_writer.writeByteNTimes(0, num_padding); |
| 1775 | 1775 | ||
| 1776 | var style = if (control.style) |style_expression| | 1776 | const style = if (control.style) |style_expression| |
| 1777 | // Certain styles are implied by the control type | 1777 | // Certain styles are implied by the control type |
| 1778 | evaluateFlagsExpressionWithDefault(res.ControlClass.getImpliedStyle(control_type), style_expression, self.source, self.input_code_pages) | 1778 | evaluateFlagsExpressionWithDefault(res.ControlClass.getImpliedStyle(control_type), style_expression, self.source, self.input_code_pages) |
| 1779 | else | 1779 | else |
| 1780 | res.ControlClass.getImpliedStyle(control_type); | 1780 | res.ControlClass.getImpliedStyle(control_type); |
| 1781 | 1781 | ||
| 1782 | var exstyle = if (control.exstyle) |exstyle_expression| | 1782 | const exstyle = if (control.exstyle) |exstyle_expression| |
| 1783 | evaluateFlagsExpressionWithDefault(0, exstyle_expression, self.source, self.input_code_pages) | 1783 | evaluateFlagsExpressionWithDefault(0, exstyle_expression, self.source, self.input_code_pages) |
| 1784 | else | 1784 | else |
| 1785 | 0; | 1785 | 0; |
| ... | @@ -3205,7 +3205,7 @@ pub const StringTable = struct { | ... | @@ -3205,7 +3205,7 @@ pub const StringTable = struct { |
| 3205 | const trimmed_string = trim: { | 3205 | const trimmed_string = trim: { |
| 3206 | // Two NUL characters in a row act as a terminator | 3206 | // Two NUL characters in a row act as a terminator |
| 3207 | // Note: This is only the case for STRINGTABLE strings | 3207 | // Note: This is only the case for STRINGTABLE strings |
| 3208 | var trimmed = trimToDoubleNUL(u16, utf16_string); | 3208 | const trimmed = trimToDoubleNUL(u16, utf16_string); |
| 3209 | // We also want to trim any trailing NUL characters | 3209 | // We also want to trim any trailing NUL characters |
| 3210 | break :trim std.mem.trimRight(u16, trimmed, &[_]u16{0}); | 3210 | break :trim std.mem.trimRight(u16, trimmed, &[_]u16{0}); |
| 3211 | }; | 3211 | }; |
src/resinator/lang.zig+1-1| ... | @@ -98,7 +98,7 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId { | ... | @@ -98,7 +98,7 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId { |
| 98 | var normalized_buf: [longest_known_tag]u8 = undefined; | 98 | var normalized_buf: [longest_known_tag]u8 = undefined; |
| 99 | // To allow e.g. `de-de_phoneb` to get looked up as `de-de`, we need to | 99 | // To allow e.g. `de-de_phoneb` to get looked up as `de-de`, we need to |
| 100 | // omit the suffix, but only if the tag contains a valid alternate sort order. | 100 | // omit the suffix, but only if the tag contains a valid alternate sort order. |
| 101 | var tag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] else tag; | 101 | const tag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] else tag; |
| 102 | const normalized_tag = normalizeTag(tag_to_normalize, &normalized_buf); | 102 | const normalized_tag = normalizeTag(tag_to_normalize, &normalized_buf); |
| 103 | return std.meta.stringToEnum(LanguageId, normalized_tag) orelse { | 103 | return std.meta.stringToEnum(LanguageId, normalized_tag) orelse { |
| 104 | // special case for a tag that has been mapped to the same ID | 104 | // special case for a tag that has been mapped to the same ID |
src/resinator/parse.zig+6-6| ... | @@ -100,7 +100,7 @@ pub const Parser = struct { | ... | @@ -100,7 +100,7 @@ pub const Parser = struct { |
| 100 | // because it almost always leads to unhelpful error messages | 100 | // because it almost always leads to unhelpful error messages |
| 101 | // (usually it will end up with bogus things like 'file | 101 | // (usually it will end up with bogus things like 'file |
| 102 | // not found: {') | 102 | // not found: {') |
| 103 | var statement = try self.parseStatement(); | 103 | const statement = try self.parseStatement(); |
| 104 | try statements.append(statement); | 104 | try statements.append(statement); |
| 105 | } | 105 | } |
| 106 | } | 106 | } |
| ... | @@ -698,7 +698,7 @@ pub const Parser = struct { | ... | @@ -698,7 +698,7 @@ pub const Parser = struct { |
| 698 | .dlginclude => { | 698 | .dlginclude => { |
| 699 | const common_resource_attributes = try self.parseCommonResourceAttributes(); | 699 | const common_resource_attributes = try self.parseCommonResourceAttributes(); |
| 700 | 700 | ||
| 701 | var filename_expression = try self.parseExpression(.{ | 701 | const filename_expression = try self.parseExpression(.{ |
| 702 | .allowed_types = .{ .string = true }, | 702 | .allowed_types = .{ .string = true }, |
| 703 | }); | 703 | }); |
| 704 | 704 | ||
| ... | @@ -756,7 +756,7 @@ pub const Parser = struct { | ... | @@ -756,7 +756,7 @@ pub const Parser = struct { |
| 756 | return &node.base; | 756 | return &node.base; |
| 757 | } | 757 | } |
| 758 | 758 | ||
| 759 | var filename_expression = try self.parseExpression(.{ | 759 | const filename_expression = try self.parseExpression(.{ |
| 760 | // Don't tell the user that numbers are accepted since we error on | 760 | // Don't tell the user that numbers are accepted since we error on |
| 761 | // number expressions and regular number literals are treated as unquoted | 761 | // number expressions and regular number literals are treated as unquoted |
| 762 | // literals rather than numbers, so from the users perspective | 762 | // literals rather than numbers, so from the users perspective |
| ... | @@ -934,8 +934,8 @@ pub const Parser = struct { | ... | @@ -934,8 +934,8 @@ pub const Parser = struct { |
| 934 | style = try optional_param_parser.parse(.{ .not_expression_allowed = true }); | 934 | style = try optional_param_parser.parse(.{ .not_expression_allowed = true }); |
| 935 | } | 935 | } |
| 936 | 936 | ||
| 937 | var exstyle: ?*Node = try optional_param_parser.parse(.{ .not_expression_allowed = true }); | 937 | const exstyle: ?*Node = try optional_param_parser.parse(.{ .not_expression_allowed = true }); |
| 938 | var help_id: ?*Node = switch (resource) { | 938 | const help_id: ?*Node = switch (resource) { |
| 939 | .dialogex => try optional_param_parser.parse(.{}), | 939 | .dialogex => try optional_param_parser.parse(.{}), |
| 940 | else => null, | 940 | else => null, |
| 941 | }; | 941 | }; |
| ... | @@ -1526,7 +1526,7 @@ pub const Parser = struct { | ... | @@ -1526,7 +1526,7 @@ pub const Parser = struct { |
| 1526 | 1526 | ||
| 1527 | pub fn toErrorDetails(options: ParseExpressionOptions, token: Token) ErrorDetails { | 1527 | pub fn toErrorDetails(options: ParseExpressionOptions, token: Token) ErrorDetails { |
| 1528 | // TODO: expected_types_override interaction with is_known_to_be_number_expression? | 1528 | // TODO: expected_types_override interaction with is_known_to_be_number_expression? |
| 1529 | var expected_types = options.expected_types_override orelse ErrorDetails.ExpectedTypes{ | 1529 | const expected_types = options.expected_types_override orelse ErrorDetails.ExpectedTypes{ |
| 1530 | .number = options.allowed_types.number, | 1530 | .number = options.allowed_types.number, |
| 1531 | .number_expression = options.allowed_types.number, | 1531 | .number_expression = options.allowed_types.number, |
| 1532 | .string_literal = options.allowed_types.string and !options.is_known_to_be_number_expression, | 1532 | .string_literal = options.allowed_types.string and !options.is_known_to_be_number_expression, |
src/resinator/res.zig+2-2| ... | @@ -357,7 +357,7 @@ pub const NameOrOrdinal = union(enum) { | ... | @@ -357,7 +357,7 @@ pub const NameOrOrdinal = union(enum) { |
| 357 | /// RC compiler would have allowed them, so that a proper warning/error | 357 | /// RC compiler would have allowed them, so that a proper warning/error |
| 358 | /// can be emitted. | 358 | /// can be emitted. |
| 359 | pub fn maybeNonAsciiOrdinalFromString(bytes: SourceBytes) ?NameOrOrdinal { | 359 | pub fn maybeNonAsciiOrdinalFromString(bytes: SourceBytes) ?NameOrOrdinal { |
| 360 | var buf = bytes.slice; | 360 | const buf = bytes.slice; |
| 361 | const radix = 10; | 361 | const radix = 10; |
| 362 | if (buf.len > 2 and buf[0] == '0') { | 362 | if (buf.len > 2 and buf[0] == '0') { |
| 363 | switch (buf[1]) { | 363 | switch (buf[1]) { |
| ... | @@ -514,7 +514,7 @@ test "NameOrOrdinal" { | ... | @@ -514,7 +514,7 @@ test "NameOrOrdinal" { |
| 514 | { | 514 | { |
| 515 | var expected = blk: { | 515 | var expected = blk: { |
| 516 | // the input before the 𐐷 character, but uppercased | 516 | // the input before the 𐐷 character, but uppercased |
| 517 | var expected_u8_bytes = "00614982008907933748980730280674788429543776231864944218790698304852300002973622122844631429099469274282385299397783838528QFFL7SHNSIETG0QKLR1UYPBTUV1PMFQRRA0VJDG354GQEDJMUPGPP1W1EXVNTZVEIZ6K3IPQM1AWGEYALMEODYVEZGOD3MFMGEY8FNR4JUETTB1PZDEWSNDRGZUA8SNXP3NGO"; | 517 | const expected_u8_bytes = "00614982008907933748980730280674788429543776231864944218790698304852300002973622122844631429099469274282385299397783838528QFFL7SHNSIETG0QKLR1UYPBTUV1PMFQRRA0VJDG354GQEDJMUPGPP1W1EXVNTZVEIZ6K3IPQM1AWGEYALMEODYVEZGOD3MFMGEY8FNR4JUETTB1PZDEWSNDRGZUA8SNXP3NGO"; |
| 518 | var buf: [256:0]u16 = undefined; | 518 | var buf: [256:0]u16 = undefined; |
| 519 | for (expected_u8_bytes, 0..) |byte, i| { | 519 | for (expected_u8_bytes, 0..) |byte, i| { |
| 520 | buf[i] = std.mem.nativeToLittle(u16, byte); | 520 | buf[i] = std.mem.nativeToLittle(u16, byte); |
src/resinator/source_mapping.zig+2-2| ... | @@ -251,7 +251,7 @@ pub fn handleLineCommand(allocator: Allocator, line_command: []const u8, current | ... | @@ -251,7 +251,7 @@ pub fn handleLineCommand(allocator: Allocator, line_command: []const u8, current |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | pub fn parseAndRemoveLineCommandsAlloc(allocator: Allocator, source: []const u8, options: ParseAndRemoveLineCommandsOptions) !ParseLineCommandsResult { | 253 | pub fn parseAndRemoveLineCommandsAlloc(allocator: Allocator, source: []const u8, options: ParseAndRemoveLineCommandsOptions) !ParseLineCommandsResult { |
| 254 | var buf = try allocator.alloc(u8, source.len); | 254 | const buf = try allocator.alloc(u8, source.len); |
| 255 | errdefer allocator.free(buf); | 255 | errdefer allocator.free(buf); |
| 256 | var result = try parseAndRemoveLineCommands(allocator, source, buf, options); | 256 | var result = try parseAndRemoveLineCommands(allocator, source, buf, options); |
| 257 | result.result = try allocator.realloc(buf, result.result.len); | 257 | result.result = try allocator.realloc(buf, result.result.len); |
| ... | @@ -440,7 +440,7 @@ pub const SourceMappings = struct { | ... | @@ -440,7 +440,7 @@ pub const SourceMappings = struct { |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | pub fn set(self: *SourceMappings, allocator: Allocator, line_num: usize, span: SourceSpan) !void { | 442 | pub fn set(self: *SourceMappings, allocator: Allocator, line_num: usize, span: SourceSpan) !void { |
| 443 | var ptr = try self.expandAndGet(allocator, line_num); | 443 | const ptr = try self.expandAndGet(allocator, line_num); |
| 444 | ptr.* = span; | 444 | ptr.* = span; |
| 445 | } | 445 | } |
| 446 | 446 |
src/translate_c.zig+5-5| ... | @@ -456,7 +456,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void { | ... | @@ -456,7 +456,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void { |
| 456 | block_scope.return_type = return_qt; | 456 | block_scope.return_type = return_qt; |
| 457 | defer block_scope.deinit(); | 457 | defer block_scope.deinit(); |
| 458 | 458 | ||
| 459 | var scope = &block_scope.base; | 459 | const scope = &block_scope.base; |
| 460 | 460 | ||
| 461 | var param_id: c_uint = 0; | 461 | var param_id: c_uint = 0; |
| 462 | for (proto_node.data.params) |*param| { | 462 | for (proto_node.data.params) |*param| { |
| ... | @@ -1363,7 +1363,7 @@ fn transSimpleOffsetOfExpr(c: *Context, expr: *const clang.OffsetOfExpr) TransEr | ... | @@ -1363,7 +1363,7 @@ fn transSimpleOffsetOfExpr(c: *Context, expr: *const clang.OffsetOfExpr) TransEr |
| 1363 | if (c.decl_table.get(@intFromPtr(record_decl.getCanonicalDecl()))) |type_name| { | 1363 | if (c.decl_table.get(@intFromPtr(record_decl.getCanonicalDecl()))) |type_name| { |
| 1364 | const type_node = try Tag.type.create(c.arena, type_name); | 1364 | const type_node = try Tag.type.create(c.arena, type_name); |
| 1365 | 1365 | ||
| 1366 | var raw_field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin()); | 1366 | const raw_field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin()); |
| 1367 | const quoted_field_name = try std.fmt.allocPrint(c.arena, "\"{s}\"", .{raw_field_name}); | 1367 | const quoted_field_name = try std.fmt.allocPrint(c.arena, "\"{s}\"", .{raw_field_name}); |
| 1368 | const field_name_node = try Tag.string_literal.create(c.arena, quoted_field_name); | 1368 | const field_name_node = try Tag.string_literal.create(c.arena, quoted_field_name); |
| 1369 | 1369 | ||
| ... | @@ -1967,7 +1967,7 @@ fn transBoolExpr( | ... | @@ -1967,7 +1967,7 @@ fn transBoolExpr( |
| 1967 | return Node{ .tag_if_small_enough = @intFromEnum(([2]Tag{ .true_literal, .false_literal })[@intFromBool(is_zero)]) }; | 1967 | return Node{ .tag_if_small_enough = @intFromEnum(([2]Tag{ .true_literal, .false_literal })[@intFromBool(is_zero)]) }; |
| 1968 | } | 1968 | } |
| 1969 | 1969 | ||
| 1970 | var res = try transExpr(c, scope, expr, used); | 1970 | const res = try transExpr(c, scope, expr, used); |
| 1971 | if (isBoolRes(res)) { | 1971 | if (isBoolRes(res)) { |
| 1972 | return maybeSuppressResult(c, used, res); | 1972 | return maybeSuppressResult(c, used, res); |
| 1973 | } | 1973 | } |
| ... | @@ -3477,7 +3477,7 @@ fn cIsFunctionDeclRef(expr: *const clang.Expr) bool { | ... | @@ -3477,7 +3477,7 @@ fn cIsFunctionDeclRef(expr: *const clang.Expr) bool { |
| 3477 | 3477 | ||
| 3478 | fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result_used: ResultUsed) TransError!Node { | 3478 | fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result_used: ResultUsed) TransError!Node { |
| 3479 | const callee = stmt.getCallee(); | 3479 | const callee = stmt.getCallee(); |
| 3480 | var raw_fn_expr = try transExpr(c, scope, callee, .used); | 3480 | const raw_fn_expr = try transExpr(c, scope, callee, .used); |
| 3481 | 3481 | ||
| 3482 | var is_ptr = false; | 3482 | var is_ptr = false; |
| 3483 | const fn_ty = qualTypeGetFnProto(callee.getType(), &is_ptr); | 3483 | const fn_ty = qualTypeGetFnProto(callee.getType(), &is_ptr); |
| ... | @@ -5889,7 +5889,7 @@ fn escapeUnprintables(ctx: *Context, m: *MacroCtx) ![]const u8 { | ... | @@ -5889,7 +5889,7 @@ fn escapeUnprintables(ctx: *Context, m: *MacroCtx) ![]const u8 { |
| 5889 | 5889 | ||
| 5890 | const formatter = std.fmt.fmtSliceEscapeLower(zigified); | 5890 | const formatter = std.fmt.fmtSliceEscapeLower(zigified); |
| 5891 | const encoded_size = @as(usize, @intCast(std.fmt.count("{s}", .{formatter}))); | 5891 | const encoded_size = @as(usize, @intCast(std.fmt.count("{s}", .{formatter}))); |
| 5892 | var output = try ctx.arena.alloc(u8, encoded_size); | 5892 | const output = try ctx.arena.alloc(u8, encoded_size); |
| 5893 | return std.fmt.bufPrint(output, "{s}", .{formatter}) catch |err| switch (err) { | 5893 | return std.fmt.bufPrint(output, "{s}", .{formatter}) catch |err| switch (err) { |
| 5894 | error.NoSpaceLeft => unreachable, | 5894 | error.NoSpaceLeft => unreachable, |
| 5895 | else => |e| return e, | 5895 | else => |e| return e, |
src/translate_c/ast.zig+7-2| ... | @@ -1625,13 +1625,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { | ... | @@ -1625,13 +1625,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 1625 | }); | 1625 | }); |
| 1626 | const main_token = try c.addToken(.equal, "="); | 1626 | const main_token = try c.addToken(.equal, "="); |
| 1627 | if (payload.value.tag() == .identifier) { | 1627 | if (payload.value.tag() == .identifier) { |
| 1628 | // Render as `_ = @TypeOf(foo);` to avoid tripping "pointless discard" error. | 1628 | // Render as `_ = &foo;` to avoid tripping "pointless discard" and "local variable never mutated" errors. |
| 1629 | var addr_of_pl: Payload.UnOp = .{ | ||
| 1630 | .base = .{ .tag = .address_of }, | ||
| 1631 | .data = payload.value, | ||
| 1632 | }; | ||
| 1633 | const addr_of: Node = .{ .ptr_otherwise = &addr_of_pl.base }; | ||
| 1629 | return c.addNode(.{ | 1634 | return c.addNode(.{ |
| 1630 | .tag = .assign, | 1635 | .tag = .assign, |
| 1631 | .main_token = main_token, | 1636 | .main_token = main_token, |
| 1632 | .data = .{ | 1637 | .data = .{ |
| 1633 | .lhs = lhs, | 1638 | .lhs = lhs, |
| 1634 | .rhs = try renderBuiltinCall(c, "@TypeOf", &.{payload.value}), | 1639 | .rhs = try renderNode(c, addr_of), |
| 1635 | }, | 1640 | }, |
| 1636 | }); | 1641 | }); |
| 1637 | } else { | 1642 | } else { |
src/translate_c/common.zig+8| ... | @@ -291,6 +291,14 @@ pub fn ScopeExtra(comptime Context: type, comptime Type: type) type { | ... | @@ -291,6 +291,14 @@ pub fn ScopeExtra(comptime Context: type, comptime Type: type) type { |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | pub fn skipVariableDiscard(inner: *Scope, name: []const u8) void { | 293 | pub fn skipVariableDiscard(inner: *Scope, name: []const u8) void { |
| 294 | if (true) { | ||
| 295 | // TODO: due to 'local variable is never mutated' errors, we can | ||
| 296 | // only skip discards if a variable is used as an lvalue, which | ||
| 297 | // we don't currently have detection for in translate-c. | ||
| 298 | // Once #17584 is completed, perhaps we can do away with this | ||
| 299 | // logic entirely, and instead rely on render to fixup code. | ||
| 300 | return; | ||
| 301 | } | ||
| 294 | var scope = inner; | 302 | var scope = inner; |
| 295 | while (true) { | 303 | while (true) { |
| 296 | switch (scope.id) { | 304 | switch (scope.id) { |
src/value.zig+3-3| ... | @@ -2136,7 +2136,7 @@ pub const Value = struct { | ... | @@ -2136,7 +2136,7 @@ pub const Value = struct { |
| 2136 | lhs_bigint.limbs.len + rhs_bigint.limbs.len, | 2136 | lhs_bigint.limbs.len + rhs_bigint.limbs.len, |
| 2137 | ); | 2137 | ); |
| 2138 | var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; | 2138 | var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; |
| 2139 | var limbs_buffer = try arena.alloc( | 2139 | const limbs_buffer = try arena.alloc( |
| 2140 | std.math.big.Limb, | 2140 | std.math.big.Limb, |
| 2141 | std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), | 2141 | std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), |
| 2142 | ); | 2142 | ); |
| ... | @@ -2249,7 +2249,7 @@ pub const Value = struct { | ... | @@ -2249,7 +2249,7 @@ pub const Value = struct { |
| 2249 | ), | 2249 | ), |
| 2250 | ); | 2250 | ); |
| 2251 | var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; | 2251 | var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; |
| 2252 | var limbs_buffer = try arena.alloc( | 2252 | const limbs_buffer = try arena.alloc( |
| 2253 | std.math.big.Limb, | 2253 | std.math.big.Limb, |
| 2254 | std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), | 2254 | std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), |
| 2255 | ); | 2255 | ); |
| ... | @@ -2788,7 +2788,7 @@ pub const Value = struct { | ... | @@ -2788,7 +2788,7 @@ pub const Value = struct { |
| 2788 | lhs_bigint.limbs.len + rhs_bigint.limbs.len, | 2788 | lhs_bigint.limbs.len + rhs_bigint.limbs.len, |
| 2789 | ); | 2789 | ); |
| 2790 | var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; | 2790 | var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; |
| 2791 | var limbs_buffer = try allocator.alloc( | 2791 | const limbs_buffer = try allocator.alloc( |
| 2792 | std.math.big.Limb, | 2792 | std.math.big.Limb, |
| 2793 | std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), | 2793 | std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), |
| 2794 | ); | 2794 | ); |
src/windows_sdk.zig+9-9| ... | @@ -69,7 +69,7 @@ fn iterateAndFilterBySemVer(iterator: *std.fs.IterableDir.Iterator, allocator: s | ... | @@ -69,7 +69,7 @@ fn iterateAndFilterBySemVer(iterator: *std.fs.IterableDir.Iterator, allocator: s |
| 69 | try dirs_filtered_list.append(subfolder_name_allocated); | 69 | try dirs_filtered_list.append(subfolder_name_allocated); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | var dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice(); | 72 | const dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice(); |
| 73 | // Keep in mind that order of these names is not guaranteed by Windows, | 73 | // Keep in mind that order of these names is not guaranteed by Windows, |
| 74 | // so we cannot just reverse or "while (popOrNull())" this ArrayList. | 74 | // so we cannot just reverse or "while (popOrNull())" this ArrayList. |
| 75 | std.mem.sortUnstable([]const u8, dirs_filtered_slice, {}, struct { | 75 | std.mem.sortUnstable([]const u8, dirs_filtered_slice, {}, struct { |
| ... | @@ -129,7 +129,7 @@ const RegistryUtf8 = struct { | ... | @@ -129,7 +129,7 @@ const RegistryUtf8 = struct { |
| 129 | const value_utf16le = try registry_utf16le.getString(allocator, subkey_utf16le, value_name_utf16le); | 129 | const value_utf16le = try registry_utf16le.getString(allocator, subkey_utf16le, value_name_utf16le); |
| 130 | defer allocator.free(value_utf16le); | 130 | defer allocator.free(value_utf16le); |
| 131 | 131 | ||
| 132 | var value_utf8: []u8 = std.unicode.utf16leToUtf8Alloc(allocator, value_utf16le) catch |err| switch (err) { | 132 | const value_utf8: []u8 = std.unicode.utf16leToUtf8Alloc(allocator, value_utf16le) catch |err| switch (err) { |
| 133 | error.OutOfMemory => return error.OutOfMemory, | 133 | error.OutOfMemory => return error.OutOfMemory, |
| 134 | else => return error.StringNotFound, | 134 | else => return error.StringNotFound, |
| 135 | }; | 135 | }; |
| ... | @@ -246,7 +246,7 @@ const RegistryUtf16Le = struct { | ... | @@ -246,7 +246,7 @@ const RegistryUtf16Le = struct { |
| 246 | else => return error.NotAString, | 246 | else => return error.NotAString, |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | var value_utf16le_buf: []u16 = try allocator.alloc(u16, std.math.divCeil(u32, value_utf16le_buf_size, 2) catch unreachable); | 249 | const value_utf16le_buf: []u16 = try allocator.alloc(u16, std.math.divCeil(u32, value_utf16le_buf_size, 2) catch unreachable); |
| 250 | errdefer allocator.free(value_utf16le_buf); | 250 | errdefer allocator.free(value_utf16le_buf); |
| 251 | 251 | ||
| 252 | return_code_int = windows.advapi32.RegGetValueW( | 252 | return_code_int = windows.advapi32.RegGetValueW( |
| ... | @@ -354,7 +354,7 @@ pub const Windows10Sdk = struct { | ... | @@ -354,7 +354,7 @@ pub const Windows10Sdk = struct { |
| 354 | defer v10_key.closeKey(); | 354 | defer v10_key.closeKey(); |
| 355 | 355 | ||
| 356 | const path: []const u8 = path10: { | 356 | const path: []const u8 = path10: { |
| 357 | var path_maybe_with_trailing_slash = v10_key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) { | 357 | const path_maybe_with_trailing_slash = v10_key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) { |
| 358 | error.NotAString => return error.Windows10SdkNotFound, | 358 | error.NotAString => return error.Windows10SdkNotFound, |
| 359 | error.ValueNameNotFound => return error.Windows10SdkNotFound, | 359 | error.ValueNameNotFound => return error.Windows10SdkNotFound, |
| 360 | error.StringNotFound => return error.Windows10SdkNotFound, | 360 | error.StringNotFound => return error.Windows10SdkNotFound, |
| ... | @@ -381,7 +381,7 @@ pub const Windows10Sdk = struct { | ... | @@ -381,7 +381,7 @@ pub const Windows10Sdk = struct { |
| 381 | const version: []const u8 = version10: { | 381 | const version: []const u8 = version10: { |
| 382 | 382 | ||
| 383 | // note(dimenus): Microsoft doesn't include the .0 in the ProductVersion key.... | 383 | // note(dimenus): Microsoft doesn't include the .0 in the ProductVersion key.... |
| 384 | var version_without_0 = v10_key.getString(allocator, "", "ProductVersion") catch |err| switch (err) { | 384 | const version_without_0 = v10_key.getString(allocator, "", "ProductVersion") catch |err| switch (err) { |
| 385 | error.NotAString => return error.Windows10SdkNotFound, | 385 | error.NotAString => return error.Windows10SdkNotFound, |
| 386 | error.ValueNameNotFound => return error.Windows10SdkNotFound, | 386 | error.ValueNameNotFound => return error.Windows10SdkNotFound, |
| 387 | error.StringNotFound => return error.Windows10SdkNotFound, | 387 | error.StringNotFound => return error.Windows10SdkNotFound, |
| ... | @@ -445,7 +445,7 @@ pub const Windows81Sdk = struct { | ... | @@ -445,7 +445,7 @@ pub const Windows81Sdk = struct { |
| 445 | /// After finishing work, call `free(allocator)`. | 445 | /// After finishing work, call `free(allocator)`. |
| 446 | fn find(allocator: std.mem.Allocator, roots_key: *const RegistryUtf8) error{ OutOfMemory, Windows81SdkNotFound, PathTooLong, VersionTooLong }!Windows81Sdk { | 446 | fn find(allocator: std.mem.Allocator, roots_key: *const RegistryUtf8) error{ OutOfMemory, Windows81SdkNotFound, PathTooLong, VersionTooLong }!Windows81Sdk { |
| 447 | const path: []const u8 = path81: { | 447 | const path: []const u8 = path81: { |
| 448 | var path_maybe_with_trailing_slash = roots_key.getString(allocator, "", "KitsRoot81") catch |err| switch (err) { | 448 | const path_maybe_with_trailing_slash = roots_key.getString(allocator, "", "KitsRoot81") catch |err| switch (err) { |
| 449 | error.NotAString => return error.Windows81SdkNotFound, | 449 | error.NotAString => return error.Windows81SdkNotFound, |
| 450 | error.ValueNameNotFound => return error.Windows81SdkNotFound, | 450 | error.ValueNameNotFound => return error.Windows81SdkNotFound, |
| 451 | error.StringNotFound => return error.Windows81SdkNotFound, | 451 | error.StringNotFound => return error.Windows81SdkNotFound, |
| ... | @@ -752,7 +752,7 @@ const MsvcLibDir = struct { | ... | @@ -752,7 +752,7 @@ const MsvcLibDir = struct { |
| 752 | 752 | ||
| 753 | const config_subkey = std.fmt.bufPrint(config_subkey_buf[0..], "Software\\Microsoft\\VisualStudio\\{s}_Config", .{vs_version}) catch unreachable; | 753 | const config_subkey = std.fmt.bufPrint(config_subkey_buf[0..], "Software\\Microsoft\\VisualStudio\\{s}_Config", .{vs_version}) catch unreachable; |
| 754 | 754 | ||
| 755 | var source_directories_value = visualstudio_registry.getString(allocator, config_subkey, "Source Directories") catch |err| switch (err) { | 755 | const source_directories_value = visualstudio_registry.getString(allocator, config_subkey, "Source Directories") catch |err| switch (err) { |
| 756 | error.OutOfMemory => return error.OutOfMemory, | 756 | error.OutOfMemory => return error.OutOfMemory, |
| 757 | else => continue, | 757 | else => continue, |
| 758 | }; | 758 | }; |
| ... | @@ -768,7 +768,7 @@ const MsvcLibDir = struct { | ... | @@ -768,7 +768,7 @@ const MsvcLibDir = struct { |
| 768 | var source_directories_splitted = std.mem.splitScalar(u8, source_directories, ';'); | 768 | var source_directories_splitted = std.mem.splitScalar(u8, source_directories, ';'); |
| 769 | 769 | ||
| 770 | const msvc_dir: []const u8 = msvc_dir: { | 770 | const msvc_dir: []const u8 = msvc_dir: { |
| 771 | var msvc_include_dir_maybe_with_trailing_slash = try allocator.dupe(u8, source_directories_splitted.first()); | 771 | const msvc_include_dir_maybe_with_trailing_slash = try allocator.dupe(u8, source_directories_splitted.first()); |
| 772 | 772 | ||
| 773 | if (msvc_include_dir_maybe_with_trailing_slash.len > std.fs.MAX_PATH_BYTES or !std.fs.path.isAbsolute(msvc_include_dir_maybe_with_trailing_slash)) { | 773 | if (msvc_include_dir_maybe_with_trailing_slash.len > std.fs.MAX_PATH_BYTES or !std.fs.path.isAbsolute(msvc_include_dir_maybe_with_trailing_slash)) { |
| 774 | allocator.free(msvc_include_dir_maybe_with_trailing_slash); | 774 | allocator.free(msvc_include_dir_maybe_with_trailing_slash); |
| ... | @@ -833,7 +833,7 @@ const MsvcLibDir = struct { | ... | @@ -833,7 +833,7 @@ const MsvcLibDir = struct { |
| 833 | const vs7_key = RegistryUtf8.openKey("SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7") catch return error.PathNotFound; | 833 | const vs7_key = RegistryUtf8.openKey("SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7") catch return error.PathNotFound; |
| 834 | defer vs7_key.closeKey(); | 834 | defer vs7_key.closeKey(); |
| 835 | try_vs7_key: { | 835 | try_vs7_key: { |
| 836 | var path_maybe_with_trailing_slash = vs7_key.getString(allocator, "", "14.0") catch |err| switch (err) { | 836 | const path_maybe_with_trailing_slash = vs7_key.getString(allocator, "", "14.0") catch |err| switch (err) { |
| 837 | error.OutOfMemory => return error.OutOfMemory, | 837 | error.OutOfMemory => return error.OutOfMemory, |
| 838 | else => break :try_vs7_key, | 838 | else => break :try_vs7_key, |
| 839 | }; | 839 | }; |
test/behavior/abs.zig+33| ... | @@ -16,26 +16,32 @@ test "@abs integers" { | ... | @@ -16,26 +16,32 @@ test "@abs integers" { |
| 16 | fn testAbsIntegers() !void { | 16 | fn testAbsIntegers() !void { |
| 17 | { | 17 | { |
| 18 | var x: i32 = -1000; | 18 | var x: i32 = -1000; |
| 19 | _ = &x; | ||
| 19 | try expect(@abs(x) == 1000); | 20 | try expect(@abs(x) == 1000); |
| 20 | } | 21 | } |
| 21 | { | 22 | { |
| 22 | var x: i32 = 0; | 23 | var x: i32 = 0; |
| 24 | _ = &x; | ||
| 23 | try expect(@abs(x) == 0); | 25 | try expect(@abs(x) == 0); |
| 24 | } | 26 | } |
| 25 | { | 27 | { |
| 26 | var x: i32 = 1000; | 28 | var x: i32 = 1000; |
| 29 | _ = &x; | ||
| 27 | try expect(@abs(x) == 1000); | 30 | try expect(@abs(x) == 1000); |
| 28 | } | 31 | } |
| 29 | { | 32 | { |
| 30 | var x: i64 = std.math.minInt(i64); | 33 | var x: i64 = std.math.minInt(i64); |
| 34 | _ = &x; | ||
| 31 | try expect(@abs(x) == @as(u64, -std.math.minInt(i64))); | 35 | try expect(@abs(x) == @as(u64, -std.math.minInt(i64))); |
| 32 | } | 36 | } |
| 33 | { | 37 | { |
| 34 | var x: i5 = -1; | 38 | var x: i5 = -1; |
| 39 | _ = &x; | ||
| 35 | try expect(@abs(x) == 1); | 40 | try expect(@abs(x) == 1); |
| 36 | } | 41 | } |
| 37 | { | 42 | { |
| 38 | var x: i5 = -5; | 43 | var x: i5 = -5; |
| 44 | _ = &x; | ||
| 39 | try expect(@abs(x) == 5); | 45 | try expect(@abs(x) == 5); |
| 40 | } | 46 | } |
| 41 | comptime { | 47 | comptime { |
| ... | @@ -56,22 +62,27 @@ test "@abs unsigned integers" { | ... | @@ -56,22 +62,27 @@ test "@abs unsigned integers" { |
| 56 | fn testAbsUnsignedIntegers() !void { | 62 | fn testAbsUnsignedIntegers() !void { |
| 57 | { | 63 | { |
| 58 | var x: u32 = 1000; | 64 | var x: u32 = 1000; |
| 65 | _ = &x; | ||
| 59 | try expect(@abs(x) == 1000); | 66 | try expect(@abs(x) == 1000); |
| 60 | } | 67 | } |
| 61 | { | 68 | { |
| 62 | var x: u32 = 0; | 69 | var x: u32 = 0; |
| 70 | _ = &x; | ||
| 63 | try expect(@abs(x) == 0); | 71 | try expect(@abs(x) == 0); |
| 64 | } | 72 | } |
| 65 | { | 73 | { |
| 66 | var x: u32 = 1000; | 74 | var x: u32 = 1000; |
| 75 | _ = &x; | ||
| 67 | try expect(@abs(x) == 1000); | 76 | try expect(@abs(x) == 1000); |
| 68 | } | 77 | } |
| 69 | { | 78 | { |
| 70 | var x: u5 = 1; | 79 | var x: u5 = 1; |
| 80 | _ = &x; | ||
| 71 | try expect(@abs(x) == 1); | 81 | try expect(@abs(x) == 1); |
| 72 | } | 82 | } |
| 73 | { | 83 | { |
| 74 | var x: u5 = 5; | 84 | var x: u5 = 5; |
| 85 | _ = &x; | ||
| 75 | try expect(@abs(x) == 5); | 86 | try expect(@abs(x) == 5); |
| 76 | } | 87 | } |
| 77 | comptime { | 88 | comptime { |
| ... | @@ -102,27 +113,33 @@ test "@abs floats" { | ... | @@ -102,27 +113,33 @@ test "@abs floats" { |
| 102 | fn testAbsFloats(comptime T: type) !void { | 113 | fn testAbsFloats(comptime T: type) !void { |
| 103 | { | 114 | { |
| 104 | var x: T = -2.62; | 115 | var x: T = -2.62; |
| 116 | _ = &x; | ||
| 105 | try expect(@abs(x) == 2.62); | 117 | try expect(@abs(x) == 2.62); |
| 106 | } | 118 | } |
| 107 | { | 119 | { |
| 108 | var x: T = 2.62; | 120 | var x: T = 2.62; |
| 121 | _ = &x; | ||
| 109 | try expect(@abs(x) == 2.62); | 122 | try expect(@abs(x) == 2.62); |
| 110 | } | 123 | } |
| 111 | { | 124 | { |
| 112 | var x: T = 0.0; | 125 | var x: T = 0.0; |
| 126 | _ = &x; | ||
| 113 | try expect(@abs(x) == 0.0); | 127 | try expect(@abs(x) == 0.0); |
| 114 | } | 128 | } |
| 115 | { | 129 | { |
| 116 | var x: T = -std.math.pi; | 130 | var x: T = -std.math.pi; |
| 131 | _ = &x; | ||
| 117 | try expect(@abs(x) == std.math.pi); | 132 | try expect(@abs(x) == std.math.pi); |
| 118 | } | 133 | } |
| 119 | 134 | ||
| 120 | { | 135 | { |
| 121 | var x: T = -std.math.inf(T); | 136 | var x: T = -std.math.inf(T); |
| 137 | _ = &x; | ||
| 122 | try expect(@abs(x) == std.math.inf(T)); | 138 | try expect(@abs(x) == std.math.inf(T)); |
| 123 | } | 139 | } |
| 124 | { | 140 | { |
| 125 | var x: T = std.math.inf(T); | 141 | var x: T = std.math.inf(T); |
| 142 | _ = &x; | ||
| 126 | try expect(@abs(x) == std.math.inf(T)); | 143 | try expect(@abs(x) == std.math.inf(T)); |
| 127 | } | 144 | } |
| 128 | comptime { | 145 | comptime { |
| ... | @@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void { | ... | @@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void { |
| 164 | { | 181 | { |
| 165 | var x: I32 = @splat(-10); | 182 | var x: I32 = @splat(-10); |
| 166 | var y: U32 = @splat(10); | 183 | var y: U32 = @splat(10); |
| 184 | _ = .{ &x, &y }; | ||
| 167 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); | 185 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 168 | } | 186 | } |
| 169 | { | 187 | { |
| 170 | var x: I32 = @splat(10); | 188 | var x: I32 = @splat(10); |
| 171 | var y: U32 = @splat(10); | 189 | var y: U32 = @splat(10); |
| 190 | _ = .{ &x, &y }; | ||
| 172 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); | 191 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 173 | } | 192 | } |
| 174 | { | 193 | { |
| 175 | var x: I32 = @splat(0); | 194 | var x: I32 = @splat(0); |
| 176 | var y: U32 = @splat(0); | 195 | var y: U32 = @splat(0); |
| 196 | _ = .{ &x, &y }; | ||
| 177 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); | 197 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 178 | } | 198 | } |
| 179 | { | 199 | { |
| 180 | var x: I64 = @splat(-10); | 200 | var x: I64 = @splat(-10); |
| 181 | var y: U64 = @splat(10); | 201 | var y: U64 = @splat(10); |
| 202 | _ = .{ &x, &y }; | ||
| 182 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); | 203 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); |
| 183 | } | 204 | } |
| 184 | { | 205 | { |
| 185 | var x: I64 = @splat(std.math.minInt(i64)); | 206 | var x: I64 = @splat(std.math.minInt(i64)); |
| 186 | var y: U64 = @splat(-std.math.minInt(i64)); | 207 | var y: U64 = @splat(-std.math.minInt(i64)); |
| 208 | _ = .{ &x, &y }; | ||
| 187 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); | 209 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); |
| 188 | } | 210 | } |
| 189 | { | 211 | { |
| 190 | var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 }); | 212 | var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 }); |
| 191 | var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 }); | 213 | var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 }); |
| 214 | _ = .{ &x, &y }; | ||
| 192 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); | 215 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 193 | } | 216 | } |
| 194 | } | 217 | } |
| ... | @@ -225,26 +248,31 @@ fn testAbsUnsignedIntVectors(comptime len: comptime_int) !void { | ... | @@ -225,26 +248,31 @@ fn testAbsUnsignedIntVectors(comptime len: comptime_int) !void { |
| 225 | { | 248 | { |
| 226 | var x: U32 = @splat(10); | 249 | var x: U32 = @splat(10); |
| 227 | var y: U32 = @splat(10); | 250 | var y: U32 = @splat(10); |
| 251 | _ = .{ &x, &y }; | ||
| 228 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); | 252 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 229 | } | 253 | } |
| 230 | { | 254 | { |
| 231 | var x: U32 = @splat(10); | 255 | var x: U32 = @splat(10); |
| 232 | var y: U32 = @splat(10); | 256 | var y: U32 = @splat(10); |
| 257 | _ = .{ &x, &y }; | ||
| 233 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); | 258 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 234 | } | 259 | } |
| 235 | { | 260 | { |
| 236 | var x: U32 = @splat(0); | 261 | var x: U32 = @splat(0); |
| 237 | var y: U32 = @splat(0); | 262 | var y: U32 = @splat(0); |
| 263 | _ = .{ &x, &y }; | ||
| 238 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); | 264 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 239 | } | 265 | } |
| 240 | { | 266 | { |
| 241 | var x: U64 = @splat(10); | 267 | var x: U64 = @splat(10); |
| 242 | var y: U64 = @splat(10); | 268 | var y: U64 = @splat(10); |
| 269 | _ = .{ &x, &y }; | ||
| 243 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); | 270 | try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); |
| 244 | } | 271 | } |
| 245 | { | 272 | { |
| 246 | var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); | 273 | var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); |
| 247 | var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); | 274 | var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); |
| 275 | _ = .{ &x, &y }; | ||
| 248 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); | 276 | try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); |
| 249 | } | 277 | } |
| 250 | } | 278 | } |
| ... | @@ -346,26 +374,31 @@ fn testAbsFloatVectors(comptime T: type, comptime len: comptime_int) !void { | ... | @@ -346,26 +374,31 @@ fn testAbsFloatVectors(comptime T: type, comptime len: comptime_int) !void { |
| 346 | { | 374 | { |
| 347 | var x: V = @splat(-7.5); | 375 | var x: V = @splat(-7.5); |
| 348 | var y: V = @splat(7.5); | 376 | var y: V = @splat(7.5); |
| 377 | _ = .{ &x, &y }; | ||
| 349 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); | 378 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 350 | } | 379 | } |
| 351 | { | 380 | { |
| 352 | var x: V = @splat(7.5); | 381 | var x: V = @splat(7.5); |
| 353 | var y: V = @splat(7.5); | 382 | var y: V = @splat(7.5); |
| 383 | _ = .{ &x, &y }; | ||
| 354 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); | 384 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 355 | } | 385 | } |
| 356 | { | 386 | { |
| 357 | var x: V = @splat(0.0); | 387 | var x: V = @splat(0.0); |
| 358 | var y: V = @splat(0.0); | 388 | var y: V = @splat(0.0); |
| 389 | _ = .{ &x, &y }; | ||
| 359 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); | 390 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 360 | } | 391 | } |
| 361 | { | 392 | { |
| 362 | var x: V = @splat(-std.math.pi); | 393 | var x: V = @splat(-std.math.pi); |
| 363 | var y: V = @splat(std.math.pi); | 394 | var y: V = @splat(std.math.pi); |
| 395 | _ = .{ &x, &y }; | ||
| 364 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); | 396 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 365 | } | 397 | } |
| 366 | { | 398 | { |
| 367 | var x: V = @splat(std.math.pi); | 399 | var x: V = @splat(std.math.pi); |
| 368 | var y: V = @splat(std.math.pi); | 400 | var y: V = @splat(std.math.pi); |
| 401 | _ = .{ &x, &y }; | ||
| 369 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); | 402 | try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); |
| 370 | } | 403 | } |
| 371 | } | 404 | } |
test/behavior/align.zig+12-2| ... | @@ -29,6 +29,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" { | ... | @@ -29,6 +29,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" { |
| 29 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 29 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 30 | 30 | ||
| 31 | var runtime_index: usize = 1; | 31 | var runtime_index: usize = 1; |
| 32 | _ = &runtime_index; | ||
| 32 | const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; | 33 | const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; |
| 33 | try expect(@TypeOf(slice) == []u8); | 34 | try expect(@TypeOf(slice) == []u8); |
| 34 | try expect(slice.len == 0); | 35 | try expect(slice.len == 0); |
| ... | @@ -438,6 +439,7 @@ test "runtime-known array index has best alignment possible" { | ... | @@ -438,6 +439,7 @@ test "runtime-known array index has best alignment possible" { |
| 438 | // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 | 439 | // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 |
| 439 | var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; | 440 | var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; |
| 440 | var runtime_zero: usize = 0; | 441 | var runtime_zero: usize = 0; |
| 442 | _ = &runtime_zero; | ||
| 441 | comptime assert(@TypeOf(smaller[runtime_zero..]) == []align(2) u32); | 443 | comptime assert(@TypeOf(smaller[runtime_zero..]) == []align(2) u32); |
| 442 | comptime assert(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32); | 444 | comptime assert(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32); |
| 443 | try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32); | 445 | try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32); |
| ... | @@ -464,6 +466,7 @@ test "alignment of function with c calling convention" { | ... | @@ -464,6 +466,7 @@ test "alignment of function with c calling convention" { |
| 464 | const a = @alignOf(@TypeOf(nothing)); | 466 | const a = @alignOf(@TypeOf(nothing)); |
| 465 | 467 | ||
| 466 | var runtime_nothing = &nothing; | 468 | var runtime_nothing = &nothing; |
| 469 | _ = &runtime_nothing; | ||
| 467 | const casted1: *align(a) const u8 = @ptrCast(runtime_nothing); | 470 | const casted1: *align(a) const u8 = @ptrCast(runtime_nothing); |
| 468 | const casted2: *const fn () callconv(.C) void = @ptrCast(casted1); | 471 | const casted2: *const fn () callconv(.C) void = @ptrCast(casted1); |
| 469 | casted2(); | 472 | casted2(); |
| ... | @@ -486,6 +489,7 @@ test "read 128-bit field from default aligned struct in stack memory" { | ... | @@ -486,6 +489,7 @@ test "read 128-bit field from default aligned struct in stack memory" { |
| 486 | .nevermind = 1, | 489 | .nevermind = 1, |
| 487 | .badguy = 12, | 490 | .badguy = 12, |
| 488 | }; | 491 | }; |
| 492 | _ = &default_aligned; | ||
| 489 | try expect(12 == default_aligned.badguy); | 493 | try expect(12 == default_aligned.badguy); |
| 490 | } | 494 | } |
| 491 | 495 | ||
| ... | @@ -577,12 +581,16 @@ test "comptime alloc alignment" { | ... | @@ -577,12 +581,16 @@ test "comptime alloc alignment" { |
| 577 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 581 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 578 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 582 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 579 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 583 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 584 | if (builtin.zig_backend == .stage2_llvm and builtin.target.cpu.arch == .x86) { | ||
| 585 | // https://github.com/ziglang/zig/issues/18034 | ||
| 586 | return error.SkipZigTest; | ||
| 587 | } | ||
| 580 | 588 | ||
| 581 | comptime var bytes1 = [_]u8{0}; | 589 | comptime var bytes1 = [_]u8{0}; |
| 582 | _ = bytes1; | 590 | _ = &bytes1; |
| 583 | 591 | ||
| 584 | comptime var bytes2 align(256) = [_]u8{0}; | 592 | comptime var bytes2 align(256) = [_]u8{0}; |
| 585 | var bytes2_addr = @intFromPtr(&bytes2); | 593 | const bytes2_addr = @intFromPtr(&bytes2); |
| 586 | try expect(bytes2_addr & 0xff == 0); | 594 | try expect(bytes2_addr & 0xff == 0); |
| 587 | } | 595 | } |
| 588 | 596 | ||
| ... | @@ -591,6 +599,7 @@ test "@alignCast null" { | ... | @@ -591,6 +599,7 @@ test "@alignCast null" { |
| 591 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 599 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 592 | 600 | ||
| 593 | var ptr: ?*anyopaque = null; | 601 | var ptr: ?*anyopaque = null; |
| 602 | _ = &ptr; | ||
| 594 | const aligned: ?*anyopaque = @alignCast(ptr); | 603 | const aligned: ?*anyopaque = @alignCast(ptr); |
| 595 | try expect(aligned == null); | 604 | try expect(aligned == null); |
| 596 | } | 605 | } |
| ... | @@ -637,6 +646,7 @@ test "alignment of zero-bit types is respected" { | ... | @@ -637,6 +646,7 @@ test "alignment of zero-bit types is respected" { |
| 637 | var s32: S align(32) = .{}; | 646 | var s32: S align(32) = .{}; |
| 638 | 647 | ||
| 639 | var zero: usize = 0; | 648 | var zero: usize = 0; |
| 649 | _ = &zero; | ||
| 640 | 650 | ||
| 641 | try expect(@intFromPtr(&s) % @alignOf(usize) == 0); | 651 | try expect(@intFromPtr(&s) % @alignOf(usize) == 0); |
| 642 | try expect(@intFromPtr(&s.arr) % @alignOf(usize) == 0); | 652 | try expect(@intFromPtr(&s.arr) % @alignOf(usize) == 0); |
test/behavior/alignof.zig+1| ... | @@ -31,6 +31,7 @@ test "correct alignment for elements and slices of aligned array" { | ... | @@ -31,6 +31,7 @@ test "correct alignment for elements and slices of aligned array" { |
| 31 | var buf: [1024]u8 align(64) = undefined; | 31 | var buf: [1024]u8 align(64) = undefined; |
| 32 | var start: usize = 1; | 32 | var start: usize = 1; |
| 33 | var end: usize = undefined; | 33 | var end: usize = undefined; |
| 34 | _ = .{ &start, &end }; | ||
| 34 | try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8)); | 35 | try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8)); |
| 35 | try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8)); | 36 | try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8)); |
| 36 | try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8)); | 37 | try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8)); |
test/behavior/array.zig+26-7| ... | @@ -138,6 +138,7 @@ test "array literal with specified size" { | ... | @@ -138,6 +138,7 @@ test "array literal with specified size" { |
| 138 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 138 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 139 | 139 | ||
| 140 | var array = [2]u8{ 1, 2 }; | 140 | var array = [2]u8{ 1, 2 }; |
| 141 | _ = &array; | ||
| 141 | try expect(array[0] == 1); | 142 | try expect(array[0] == 1); |
| 142 | try expect(array[1] == 2); | 143 | try expect(array[1] == 2); |
| 143 | } | 144 | } |
| ... | @@ -146,7 +147,7 @@ test "array len field" { | ... | @@ -146,7 +147,7 @@ test "array len field" { |
| 146 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 147 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 147 | 148 | ||
| 148 | var arr = [4]u8{ 0, 0, 0, 0 }; | 149 | var arr = [4]u8{ 0, 0, 0, 0 }; |
| 149 | var ptr = &arr; | 150 | const ptr = &arr; |
| 150 | try expect(arr.len == 4); | 151 | try expect(arr.len == 4); |
| 151 | try comptime expect(arr.len == 4); | 152 | try comptime expect(arr.len == 4); |
| 152 | try expect(ptr.len == 4); | 153 | try expect(ptr.len == 4); |
| ... | @@ -163,7 +164,8 @@ test "array with sentinels" { | ... | @@ -163,7 +164,8 @@ test "array with sentinels" { |
| 163 | { | 164 | { |
| 164 | var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; | 165 | var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; |
| 165 | try expect(zero_sized[0] == 0xde); | 166 | try expect(zero_sized[0] == 0xde); |
| 166 | var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized)); | 167 | var reinterpreted: *[1]u8 = @ptrCast(&zero_sized); |
| 168 | _ = &reinterpreted; | ||
| 167 | try expect(reinterpreted[0] == 0xde); | 169 | try expect(reinterpreted[0] == 0xde); |
| 168 | } | 170 | } |
| 169 | var arr: [3:0x55]u8 = undefined; | 171 | var arr: [3:0x55]u8 = undefined; |
| ... | @@ -225,6 +227,7 @@ test "implicit comptime in array type size" { | ... | @@ -225,6 +227,7 @@ test "implicit comptime in array type size" { |
| 225 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 227 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 226 | 228 | ||
| 227 | var arr: [plusOne(10)]bool = undefined; | 229 | var arr: [plusOne(10)]bool = undefined; |
| 230 | _ = &arr; | ||
| 228 | try expect(arr.len == 11); | 231 | try expect(arr.len == 11); |
| 229 | } | 232 | } |
| 230 | 233 | ||
| ... | @@ -281,6 +284,7 @@ test "anonymous list literal syntax" { | ... | @@ -281,6 +284,7 @@ test "anonymous list literal syntax" { |
| 281 | const S = struct { | 284 | const S = struct { |
| 282 | fn doTheTest() !void { | 285 | fn doTheTest() !void { |
| 283 | var array: [4]u8 = .{ 1, 2, 3, 4 }; | 286 | var array: [4]u8 = .{ 1, 2, 3, 4 }; |
| 287 | _ = &array; | ||
| 284 | try expect(array[0] == 1); | 288 | try expect(array[0] == 1); |
| 285 | try expect(array[1] == 2); | 289 | try expect(array[1] == 2); |
| 286 | try expect(array[2] == 3); | 290 | try expect(array[2] == 3); |
| ... | @@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" { | ... | @@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" { |
| 365 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 369 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 366 | 370 | ||
| 367 | var two: i32 = 2; | 371 | var two: i32 = 2; |
| 372 | _ = &two; | ||
| 368 | const x: []const i32 = &[_]i32{two}; | 373 | const x: []const i32 = &[_]i32{two}; |
| 369 | try expect(x[0] == 2); | 374 | try expect(x[0] == 2); |
| 370 | } | 375 | } |
| ... | @@ -472,6 +477,7 @@ test "anonymous literal in array" { | ... | @@ -472,6 +477,7 @@ test "anonymous literal in array" { |
| 472 | .{ .a = 3 }, | 477 | .{ .a = 3 }, |
| 473 | .{ .b = 3 }, | 478 | .{ .b = 3 }, |
| 474 | }; | 479 | }; |
| 480 | _ = &array; | ||
| 475 | try expect(array[0].a == 3); | 481 | try expect(array[0].a == 3); |
| 476 | try expect(array[0].b == 4); | 482 | try expect(array[0].b == 4); |
| 477 | try expect(array[1].a == 2); | 483 | try expect(array[1].a == 2); |
| ... | @@ -489,8 +495,10 @@ test "access the null element of a null terminated array" { | ... | @@ -489,8 +495,10 @@ test "access the null element of a null terminated array" { |
| 489 | const S = struct { | 495 | const S = struct { |
| 490 | fn doTheTest() !void { | 496 | fn doTheTest() !void { |
| 491 | var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; | 497 | var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; |
| 498 | _ = &array; | ||
| 492 | try expect(array[4] == 0); | 499 | try expect(array[4] == 0); |
| 493 | var len: usize = 4; | 500 | var len: usize = 4; |
| 501 | _ = &len; | ||
| 494 | try expect(array[len] == 0); | 502 | try expect(array[len] == 0); |
| 495 | } | 503 | } |
| 496 | }; | 504 | }; |
| ... | @@ -510,6 +518,7 @@ test "type deduction for array subscript expression" { | ... | @@ -510,6 +518,7 @@ test "type deduction for array subscript expression" { |
| 510 | try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]); | 518 | try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]); |
| 511 | var v1 = false; | 519 | var v1 = false; |
| 512 | try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]); | 520 | try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]); |
| 521 | _ = .{ &array, &v0, &v1 }; | ||
| 513 | } | 522 | } |
| 514 | }; | 523 | }; |
| 515 | try S.doTheTest(); | 524 | try S.doTheTest(); |
| ... | @@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" { | ... | @@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" { |
| 529 | fill_post: u8 = 0xAA, | 538 | fill_post: u8 = 0xAA, |
| 530 | }; | 539 | }; |
| 531 | var x = T{}; | 540 | var x = T{}; |
| 532 | var as_slice = mem.asBytes(&x); | 541 | const as_slice = mem.asBytes(&x); |
| 533 | try expect(@as(usize, 3) == as_slice.len); | 542 | try expect(@as(usize, 3) == as_slice.len); |
| 534 | try expect(@as(u8, 0x55) == as_slice[0]); | 543 | try expect(@as(u8, 0x55) == as_slice[0]); |
| 535 | try expect(@as(u8, 0xAA) == as_slice[2]); | 544 | try expect(@as(u8, 0xAA) == as_slice[2]); |
| ... | @@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" { | ... | @@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" { |
| 559 | }; | 568 | }; |
| 560 | 569 | ||
| 561 | var t: S = .{ .list = .{ .s = undefined } }; | 570 | var t: S = .{ .list = .{ .s = undefined } }; |
| 571 | _ = &t; | ||
| 562 | try expect(@as(usize, 0) == t.list.x); | 572 | try expect(@as(usize, 0) == t.list.x); |
| 563 | } | 573 | } |
| 564 | 574 | ||
| ... | @@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" { | ... | @@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" { |
| 576 | 586 | ||
| 577 | fn doTheTest() !void { | 587 | fn doTheTest() !void { |
| 578 | var x1: u8 = 42; | 588 | var x1: u8 = 42; |
| 589 | _ = &x1; | ||
| 579 | const t1 = .{ x1, 56, 54 }; | 590 | const t1 = .{ x1, 56, 54 }; |
| 580 | var arr1: [3]u8 = t1; | 591 | const arr1: [3]u8 = t1; |
| 581 | try expect(arr1[0] == 42); | 592 | try expect(arr1[0] == 42); |
| 582 | try expect(arr1[1] == 56); | 593 | try expect(arr1[1] == 56); |
| 583 | try expect(arr1[2] == 54); | 594 | try expect(arr1[2] == 54); |
| 584 | 595 | ||
| 585 | var x2: U = .{ .a = 42 }; | 596 | var x2: U = .{ .a = 42 }; |
| 597 | _ = &x2; | ||
| 586 | const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } }; | 598 | const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } }; |
| 587 | var arr2: [3]U = t2; | 599 | const arr2: [3]U = t2; |
| 588 | try expect(arr2[0].a == 42); | 600 | try expect(arr2[0].a == 42); |
| 589 | try expect(arr2[1].b == true); | 601 | try expect(arr2[1].b == true); |
| 590 | try expect(mem.eql(u8, arr2[2].c, "hello")); | 602 | try expect(mem.eql(u8, arr2[2].c, "hello")); |
| ... | @@ -608,15 +620,17 @@ test "type coercion of pointer to anon struct literal to pointer to array" { | ... | @@ -608,15 +620,17 @@ test "type coercion of pointer to anon struct literal to pointer to array" { |
| 608 | 620 | ||
| 609 | fn doTheTest() !void { | 621 | fn doTheTest() !void { |
| 610 | var x1: u8 = 42; | 622 | var x1: u8 = 42; |
| 623 | _ = &x1; | ||
| 611 | const t1 = &.{ x1, 56, 54 }; | 624 | const t1 = &.{ x1, 56, 54 }; |
| 612 | var arr1: *const [3]u8 = t1; | 625 | const arr1: *const [3]u8 = t1; |
| 613 | try expect(arr1[0] == 42); | 626 | try expect(arr1[0] == 42); |
| 614 | try expect(arr1[1] == 56); | 627 | try expect(arr1[1] == 56); |
| 615 | try expect(arr1[2] == 54); | 628 | try expect(arr1[2] == 54); |
| 616 | 629 | ||
| 617 | var x2: U = .{ .a = 42 }; | 630 | var x2: U = .{ .a = 42 }; |
| 631 | _ = &x2; | ||
| 618 | const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } }; | 632 | const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } }; |
| 619 | var arr2: *const [3]U = t2; | 633 | const arr2: *const [3]U = t2; |
| 620 | try expect(arr2[0].a == 42); | 634 | try expect(arr2[0].a == 42); |
| 621 | try expect(arr2[1].b == true); | 635 | try expect(arr2[1].b == true); |
| 622 | try expect(mem.eql(u8, arr2[2].c, "hello")); | 636 | try expect(mem.eql(u8, arr2[2].c, "hello")); |
| ... | @@ -656,6 +670,7 @@ test "array init of container level array variable" { | ... | @@ -656,6 +670,7 @@ test "array init of container level array variable" { |
| 656 | } | 670 | } |
| 657 | noinline fn bar(x: usize, y: usize) void { | 671 | noinline fn bar(x: usize, y: usize) void { |
| 658 | var tmp: [2]usize = .{ x, y }; | 672 | var tmp: [2]usize = .{ x, y }; |
| 673 | _ = &tmp; | ||
| 659 | pair = tmp; | 674 | pair = tmp; |
| 660 | } | 675 | } |
| 661 | }; | 676 | }; |
| ... | @@ -668,6 +683,7 @@ test "array init of container level array variable" { | ... | @@ -668,6 +683,7 @@ test "array init of container level array variable" { |
| 668 | 683 | ||
| 669 | test "runtime initialized sentinel-terminated array literal" { | 684 | test "runtime initialized sentinel-terminated array literal" { |
| 670 | var c: u16 = 300; | 685 | var c: u16 = 300; |
| 686 | _ = &c; | ||
| 671 | const f = &[_:0x9999]u16{c}; | 687 | const f = &[_:0x9999]u16{c}; |
| 672 | const g = @as(*const [4]u8, @ptrCast(f)); | 688 | const g = @as(*const [4]u8, @ptrCast(f)); |
| 673 | try std.testing.expect(g[2] == 0x99); | 689 | try std.testing.expect(g[2] == 0x99); |
| ... | @@ -681,6 +697,7 @@ test "array of array agregate init" { | ... | @@ -681,6 +697,7 @@ test "array of array agregate init" { |
| 681 | 697 | ||
| 682 | var a = [1]u32{11} ** 10; | 698 | var a = [1]u32{11} ** 10; |
| 683 | var b = [1][10]u32{a} ** 2; | 699 | var b = [1][10]u32{a} ** 2; |
| 700 | _ = .{ &a, &b }; | ||
| 684 | try std.testing.expect(b[1][1] == 11); | 701 | try std.testing.expect(b[1][1] == 11); |
| 685 | } | 702 | } |
| 686 | 703 | ||
| ... | @@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" { | ... | @@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" { |
| 778 | test "slice initialized through reference to anonymous array init provides result types" { | 795 | test "slice initialized through reference to anonymous array init provides result types" { |
| 779 | var my_u32: u32 = 123; | 796 | var my_u32: u32 = 123; |
| 780 | var my_u64: u64 = 456; | 797 | var my_u64: u64 = 456; |
| 798 | _ = .{ &my_u32, &my_u64 }; | ||
| 781 | const foo: []const u16 = &.{ | 799 | const foo: []const u16 = &.{ |
| 782 | @intCast(my_u32), | 800 | @intCast(my_u32), |
| 783 | @intCast(my_u64), | 801 | @intCast(my_u64), |
| ... | @@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul | ... | @@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul |
| 790 | test "pointer to array initialized through reference to anonymous array init provides result types" { | 808 | test "pointer to array initialized through reference to anonymous array init provides result types" { |
| 791 | var my_u32: u32 = 123; | 809 | var my_u32: u32 = 123; |
| 792 | var my_u64: u64 = 456; | 810 | var my_u64: u64 = 456; |
| 811 | _ = .{ &my_u32, &my_u64 }; | ||
| 793 | const foo: *const [4]u16 = &.{ | 812 | const foo: *const [4]u16 = &.{ |
| 794 | @intCast(my_u32), | 813 | @intCast(my_u32), |
| 795 | @intCast(my_u64), | 814 | @intCast(my_u64), |
test/behavior/asm.zig+1| ... | @@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" { | ... | @@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" { |
| 180 | if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly | 180 | if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly |
| 181 | 181 | ||
| 182 | var x: u32 = 15; | 182 | var x: u32 = 15; |
| 183 | _ = &x; | ||
| 183 | const double = asm ("add %[ret:w], %[in:w], %[in:w]" | 184 | const double = asm ("add %[ret:w], %[in:w], %[in:w]" |
| 184 | : [ret] "=r" (-> u32), | 185 | : [ret] "=r" (-> u32), |
| 185 | : [in] "r" (x), | 186 | : [in] "r" (x), |
test/behavior/async_fn.zig+22-10| ... | @@ -137,11 +137,13 @@ test "@frameSize" { | ... | @@ -137,11 +137,13 @@ test "@frameSize" { |
| 137 | fn doTheTest() !void { | 137 | fn doTheTest() !void { |
| 138 | { | 138 | { |
| 139 | var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other)); | 139 | var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other)); |
| 140 | _ = &ptr; | ||
| 140 | const size = @frameSize(ptr); | 141 | const size = @frameSize(ptr); |
| 141 | try expect(size == @sizeOf(@Frame(other))); | 142 | try expect(size == @sizeOf(@Frame(other))); |
| 142 | } | 143 | } |
| 143 | { | 144 | { |
| 144 | var ptr = @as(fn () callconv(.Async) void, @ptrCast(first)); | 145 | var ptr = @as(fn () callconv(.Async) void, @ptrCast(first)); |
| 146 | _ = &ptr; | ||
| 145 | const size = @frameSize(ptr); | 147 | const size = @frameSize(ptr); |
| 146 | try expect(size == @sizeOf(@Frame(first))); | 148 | try expect(size == @sizeOf(@Frame(first))); |
| 147 | } | 149 | } |
| ... | @@ -153,7 +155,7 @@ test "@frameSize" { | ... | @@ -153,7 +155,7 @@ test "@frameSize" { |
| 153 | fn other(param: i32) void { | 155 | fn other(param: i32) void { |
| 154 | _ = param; | 156 | _ = param; |
| 155 | var local: i32 = undefined; | 157 | var local: i32 = undefined; |
| 156 | _ = local; | 158 | _ = &local; |
| 157 | suspend {} | 159 | suspend {} |
| 158 | } | 160 | } |
| 159 | }; | 161 | }; |
| ... | @@ -239,7 +241,7 @@ test "coroutine await" { | ... | @@ -239,7 +241,7 @@ test "coroutine await" { |
| 239 | 241 | ||
| 240 | await_seq('a'); | 242 | await_seq('a'); |
| 241 | var p = async await_amain(); | 243 | var p = async await_amain(); |
| 242 | _ = p; | 244 | _ = &p; |
| 243 | await_seq('f'); | 245 | await_seq('f'); |
| 244 | resume await_a_promise; | 246 | resume await_a_promise; |
| 245 | await_seq('i'); | 247 | await_seq('i'); |
| ... | @@ -279,7 +281,7 @@ test "coroutine await early return" { | ... | @@ -279,7 +281,7 @@ test "coroutine await early return" { |
| 279 | 281 | ||
| 280 | early_seq('a'); | 282 | early_seq('a'); |
| 281 | var p = async early_amain(); | 283 | var p = async early_amain(); |
| 282 | _ = p; | 284 | _ = &p; |
| 283 | early_seq('f'); | 285 | early_seq('f'); |
| 284 | try expect(early_final_result == 1234); | 286 | try expect(early_final_result == 1234); |
| 285 | try expect(std.mem.eql(u8, &early_points, "abcdef")); | 287 | try expect(std.mem.eql(u8, &early_points, "abcdef")); |
| ... | @@ -329,6 +331,7 @@ test "async fn pointer in a struct field" { | ... | @@ -329,6 +331,7 @@ test "async fn pointer in a struct field" { |
| 329 | bar: fn (*i32) callconv(.Async) void, | 331 | bar: fn (*i32) callconv(.Async) void, |
| 330 | }; | 332 | }; |
| 331 | var foo = Foo{ .bar = simpleAsyncFn2 }; | 333 | var foo = Foo{ .bar = simpleAsyncFn2 }; |
| 334 | _ = &foo; | ||
| 332 | var bytes: [64]u8 align(16) = undefined; | 335 | var bytes: [64]u8 align(16) = undefined; |
| 333 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); | 336 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 334 | try comptime expect(@TypeOf(f) == anyframe->void); | 337 | try comptime expect(@TypeOf(f) == anyframe->void); |
| ... | @@ -367,6 +370,7 @@ test "@asyncCall with return type" { | ... | @@ -367,6 +370,7 @@ test "@asyncCall with return type" { |
| 367 | } | 370 | } |
| 368 | }; | 371 | }; |
| 369 | var foo = Foo{ .bar = Foo.middle }; | 372 | var foo = Foo{ .bar = Foo.middle }; |
| 373 | _ = &foo; | ||
| 370 | var bytes: [150]u8 align(16) = undefined; | 374 | var bytes: [150]u8 align(16) = undefined; |
| 371 | var aresult: i32 = 0; | 375 | var aresult: i32 = 0; |
| 372 | _ = @asyncCall(&bytes, &aresult, foo.bar, .{}); | 376 | _ = @asyncCall(&bytes, &aresult, foo.bar, .{}); |
| ... | @@ -385,6 +389,7 @@ test "async fn with inferred error set" { | ... | @@ -385,6 +389,7 @@ test "async fn with inferred error set" { |
| 385 | fn doTheTest() !void { | 389 | fn doTheTest() !void { |
| 386 | var frame: [1]@Frame(middle) = undefined; | 390 | var frame: [1]@Frame(middle) = undefined; |
| 387 | var fn_ptr = middle; | 391 | var fn_ptr = middle; |
| 392 | _ = &fn_ptr; | ||
| 388 | var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined; | 393 | var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined; |
| 389 | _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{}); | 394 | _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{}); |
| 390 | resume global_frame; | 395 | resume global_frame; |
| ... | @@ -827,7 +832,7 @@ test "alignment of local variables in async functions" { | ... | @@ -827,7 +832,7 @@ test "alignment of local variables in async functions" { |
| 827 | const S = struct { | 832 | const S = struct { |
| 828 | fn doTheTest() !void { | 833 | fn doTheTest() !void { |
| 829 | var y: u8 = 123; | 834 | var y: u8 = 123; |
| 830 | _ = y; | 835 | _ = &y; |
| 831 | var x: u8 align(128) = 1; | 836 | var x: u8 align(128) = 1; |
| 832 | try expect(@intFromPtr(&x) % 128 == 0); | 837 | try expect(@intFromPtr(&x) % 128 == 0); |
| 833 | } | 838 | } |
| ... | @@ -843,7 +848,7 @@ test "no reason to resolve frame still works" { | ... | @@ -843,7 +848,7 @@ test "no reason to resolve frame still works" { |
| 843 | } | 848 | } |
| 844 | fn simpleNothing() void { | 849 | fn simpleNothing() void { |
| 845 | var x: i32 = 1234; | 850 | var x: i32 = 1234; |
| 846 | _ = x; | 851 | _ = &x; |
| 847 | } | 852 | } |
| 848 | 853 | ||
| 849 | test "async call a generic function" { | 854 | test "async call a generic function" { |
| ... | @@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" { | ... | @@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" { |
| 913 | if (x == 0) return; | 918 | if (x == 0) return; |
| 914 | clobberStack(x - 1); | 919 | clobberStack(x - 1); |
| 915 | var y: i32 = x; | 920 | var y: i32 = x; |
| 916 | _ = y; | 921 | _ = &y; |
| 917 | } | 922 | } |
| 918 | 923 | ||
| 919 | fn bar(f: *@Frame(foo)) void { | 924 | fn bar(f: *@Frame(foo)) void { |
| 920 | var pt = Point{ .x = 1, .y = 2 }; | 925 | var pt = Point{ .x = 1, .y = 2 }; |
| 926 | _ = &pt; | ||
| 921 | f.* = async foo(pt); | 927 | f.* = async foo(pt); |
| 922 | var result = await f; | 928 | const result = await f; |
| 923 | expect(result == 1) catch @panic("test failure"); | 929 | expect(result == 1) catch @panic("test failure"); |
| 924 | } | 930 | } |
| 925 | 931 | ||
| ... | @@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" { | ... | @@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" { |
| 1141 | bar: fn (*i32) callconv(.Async) i32, | 1147 | bar: fn (*i32) callconv(.Async) i32, |
| 1142 | }; | 1148 | }; |
| 1143 | var foo = Foo{ .bar = S.simple2 }; | 1149 | var foo = Foo{ .bar = S.simple2 }; |
| 1150 | _ = &foo; | ||
| 1144 | var bytes: [64]u8 align(16) = undefined; | 1151 | var bytes: [64]u8 align(16) = undefined; |
| 1145 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); | 1152 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 1146 | try comptime expect(@TypeOf(f) == anyframe->i32); | 1153 | try comptime expect(@TypeOf(f) == anyframe->i32); |
| ... | @@ -1465,7 +1472,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" { | ... | @@ -1465,7 +1472,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" { |
| 1465 | // the for loop spills still happen even though there is a VarDecl in scope | 1472 | // the for loop spills still happen even though there is a VarDecl in scope |
| 1466 | // before the suspend. | 1473 | // before the suspend. |
| 1467 | var anything = true; | 1474 | var anything = true; |
| 1468 | _ = anything; | 1475 | _ = &anything; |
| 1469 | suspend { | 1476 | suspend { |
| 1470 | global_frame = @frame(); | 1477 | global_frame = @frame(); |
| 1471 | } | 1478 | } |
| ... | @@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" { | ... | @@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" { |
| 1538 | 1545 | ||
| 1539 | fn foo() void { | 1546 | fn foo() void { |
| 1540 | var a: u128 = 99; | 1547 | var a: u128 = 99; |
| 1548 | _ = &a; | ||
| 1541 | bar(10, .{a}) catch unreachable; | 1549 | bar(10, .{a}) catch unreachable; |
| 1542 | } | 1550 | } |
| 1543 | 1551 | ||
| ... | @@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" { | ... | @@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" { |
| 1590 | const stack_size = 1000; | 1598 | const stack_size = 1000; |
| 1591 | var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined; | 1599 | var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined; |
| 1592 | var func: fn () callconv(.Async) anyerror!void = bar; | 1600 | var func: fn () callconv(.Async) anyerror!void = bar; |
| 1601 | _ = &func; | ||
| 1593 | return await @asyncCall(&stack_frame, {}, func, .{}); | 1602 | return await @asyncCall(&stack_frame, {}, func, .{}); |
| 1594 | } | 1603 | } |
| 1595 | 1604 | ||
| ... | @@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" { | ... | @@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" { |
| 1614 | 1623 | ||
| 1615 | fn foo() void { | 1624 | fn foo() void { |
| 1616 | var opt: ?usize = 1234; | 1625 | var opt: ?usize = 1234; |
| 1626 | _ = &opt; | ||
| 1617 | if (opt) |x| { | 1627 | if (opt) |x| { |
| 1618 | bar(); | 1628 | bar(); |
| 1619 | global_int += x; | 1629 | global_int += x; |
| ... | @@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" { | ... | @@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" { |
| 1863 | var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; | 1873 | var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; |
| 1864 | // The function pointer must not be comptime-known. | 1874 | // The function pointer must not be comptime-known. |
| 1865 | var t = S.f; | 1875 | var t = S.f; |
| 1876 | _ = &t; | ||
| 1866 | var frame_ptr = @asyncCall(&buffer, {}, t, .{ | 1877 | var frame_ptr = @asyncCall(&buffer, {}, t, .{ |
| 1867 | F0, | 1878 | F0, |
| 1868 | .{ .f0 = 1, .f1 = 2 }, | 1879 | .{ .f0 = 1, .f1 = 2 }, |
| ... | @@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" { | ... | @@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" { |
| 1870 | [_]u8{ 1, 2, 3, 4, 5 }, | 1881 | [_]u8{ 1, 2, 3, 4, 5 }, |
| 1871 | F2, | 1882 | F2, |
| 1872 | }); | 1883 | }); |
| 1873 | _ = frame_ptr; | 1884 | _ = &frame_ptr; |
| 1874 | } | 1885 | } |
| 1875 | 1886 | ||
| 1876 | test "@asyncCall with arguments having non-standard alignment" { | 1887 | test "@asyncCall with arguments having non-standard alignment" { |
| ... | @@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" { | ... | @@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" { |
| 1893 | var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; | 1904 | var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; |
| 1894 | // The function pointer must not be comptime-known. | 1905 | // The function pointer must not be comptime-known. |
| 1895 | var t = S.f; | 1906 | var t = S.f; |
| 1907 | _ = &t; | ||
| 1896 | var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 }); | 1908 | var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 }); |
| 1897 | _ = frame_ptr; | 1909 | _ = &frame_ptr; |
| 1898 | } | 1910 | } |
test/behavior/await_struct.zig+1-1| ... | @@ -14,7 +14,7 @@ test "coroutine await struct" { | ... | @@ -14,7 +14,7 @@ test "coroutine await struct" { |
| 14 | 14 | ||
| 15 | await_seq('a'); | 15 | await_seq('a'); |
| 16 | var p = async await_amain(); | 16 | var p = async await_amain(); |
| 17 | _ = p; | 17 | _ = &p; |
| 18 | await_seq('f'); | 18 | await_seq('f'); |
| 19 | resume await_a_promise; | 19 | resume await_a_promise; |
| 20 | await_seq('i'); | 20 | await_seq('i'); |
test/behavior/basic.zig+16-3| ... | @@ -118,6 +118,7 @@ fn thisIsAColdFn() void { | ... | @@ -118,6 +118,7 @@ fn thisIsAColdFn() void { |
| 118 | 118 | ||
| 119 | test "unicode escape in character literal" { | 119 | test "unicode escape in character literal" { |
| 120 | var a: u24 = '\u{01f4a9}'; | 120 | var a: u24 = '\u{01f4a9}'; |
| 121 | _ = &a; | ||
| 121 | try expect(a == 128169); | 122 | try expect(a == 128169); |
| 122 | } | 123 | } |
| 123 | 124 | ||
| ... | @@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" { | ... | @@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" { |
| 362 | } | 363 | } |
| 363 | fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA { | 364 | fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA { |
| 364 | var a = ptr; | 365 | var a = ptr; |
| 366 | _ = &a; | ||
| 365 | return a; | 367 | return a; |
| 366 | } | 368 | } |
| 367 | 369 | ||
| ... | @@ -441,6 +443,7 @@ test "double implicit cast in same expression" { | ... | @@ -441,6 +443,7 @@ test "double implicit cast in same expression" { |
| 441 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 443 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 442 | 444 | ||
| 443 | var x = @as(i32, @as(u16, nine())); | 445 | var x = @as(i32, @as(u16, nine())); |
| 446 | _ = &x; | ||
| 444 | try expect(x == 9); | 447 | try expect(x == 9); |
| 445 | } | 448 | } |
| 446 | fn nine() u8 { | 449 | fn nine() u8 { |
| ... | @@ -570,6 +573,7 @@ test "comptime cast fn to ptr" { | ... | @@ -570,6 +573,7 @@ test "comptime cast fn to ptr" { |
| 570 | 573 | ||
| 571 | test "equality compare fn ptrs" { | 574 | test "equality compare fn ptrs" { |
| 572 | var a = &emptyFn; | 575 | var a = &emptyFn; |
| 576 | _ = &a; | ||
| 573 | try expect(a == a); | 577 | try expect(a == a); |
| 574 | } | 578 | } |
| 575 | 579 | ||
| ... | @@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" { | ... | @@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" { |
| 611 | const S = struct { | 615 | const S = struct { |
| 612 | fn doTheTest() !void { | 616 | fn doTheTest() !void { |
| 613 | var index: usize = 1; | 617 | var index: usize = 1; |
| 618 | _ = &index; | ||
| 614 | const ptr = &pieces[index].field; | 619 | const ptr = &pieces[index].field; |
| 615 | try expect(ptr.* == 2); | 620 | try expect(ptr.* == 2); |
| 616 | } | 621 | } |
| ... | @@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" { | ... | @@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" { |
| 785 | 790 | ||
| 786 | test "if expression type coercion" { | 791 | test "if expression type coercion" { |
| 787 | var cond: bool = true; | 792 | var cond: bool = true; |
| 793 | _ = &cond; | ||
| 788 | const x: u16 = if (cond) 1 else 0; | 794 | const x: u16 = if (cond) 1 else 0; |
| 789 | try expect(@as(u16, x) == 1); | 795 | try expect(@as(u16, x) == 1); |
| 790 | } | 796 | } |
| ... | @@ -825,6 +831,7 @@ test "discarding the result of various expressions" { | ... | @@ -825,6 +831,7 @@ test "discarding the result of various expressions" { |
| 825 | 831 | ||
| 826 | test "labeled block implicitly ends in a break" { | 832 | test "labeled block implicitly ends in a break" { |
| 827 | var a = false; | 833 | var a = false; |
| 834 | _ = &a; | ||
| 828 | blk: { | 835 | blk: { |
| 829 | if (a) break :blk; | 836 | if (a) break :blk; |
| 830 | } | 837 | } |
| ... | @@ -852,6 +859,7 @@ test "catch in block has correct result location" { | ... | @@ -852,6 +859,7 @@ test "catch in block has correct result location" { |
| 852 | test "labeled block with runtime branch forwards its result location type to break statements" { | 859 | test "labeled block with runtime branch forwards its result location type to break statements" { |
| 853 | const E = enum { a, b }; | 860 | const E = enum { a, b }; |
| 854 | var a = false; | 861 | var a = false; |
| 862 | _ = &a; | ||
| 855 | const e: E = blk: { | 863 | const e: E = blk: { |
| 856 | if (a) { | 864 | if (a) { |
| 857 | break :blk .a; | 865 | break :blk .a; |
| ... | @@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" { | ... | @@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" { |
| 872 | }; | 880 | }; |
| 873 | const s: ?*S = blk: { | 881 | const s: ?*S = blk: { |
| 874 | var a = try S.foo(); | 882 | var a = try S.foo(); |
| 875 | 883 | _ = &a; | |
| 876 | _ = a; | ||
| 877 | break :blk null; | 884 | break :blk null; |
| 878 | }; | 885 | }; |
| 879 | _ = s; | 886 | _ = s; |
| ... | @@ -894,6 +901,7 @@ test "weird array and tuple initializations" { | ... | @@ -894,6 +901,7 @@ test "weird array and tuple initializations" { |
| 894 | const E = enum { a, b }; | 901 | const E = enum { a, b }; |
| 895 | const S = struct { e: E }; | 902 | const S = struct { e: E }; |
| 896 | var a = false; | 903 | var a = false; |
| 904 | _ = &a; | ||
| 897 | const b = S{ .e = .a }; | 905 | const b = S{ .e = .a }; |
| 898 | 906 | ||
| 899 | _ = &[_]S{ | 907 | _ = &[_]S{ |
| ... | @@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" { | ... | @@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" { |
| 1009 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1017 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1010 | 1018 | ||
| 1011 | var a: u32 = 0; | 1019 | var a: u32 = 0; |
| 1020 | _ = &a; | ||
| 1012 | var b: [2]u32 = undefined; | 1021 | var b: [2]u32 = undefined; |
| 1013 | b[0] = @as(u32, switch (a) { | 1022 | b[0] = @as(u32, switch (a) { |
| 1014 | 1 => 1, | 1023 | 1 => 1, |
| ... | @@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" { | ... | @@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" { |
| 1110 | } | 1119 | } |
| 1111 | }; | 1120 | }; |
| 1112 | var optional: ?Loc = .{}; | 1121 | var optional: ?Loc = .{}; |
| 1113 | var foo = Container.init(optional orelse .{}); | 1122 | _ = &optional; |
| 1123 | const foo = Container.init(optional orelse .{}); | ||
| 1114 | try expect(foo.a.?.start == -1); | 1124 | try expect(foo.a.?.start == -1); |
| 1115 | } | 1125 | } |
| 1116 | 1126 | ||
| ... | @@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" { | ... | @@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" { |
| 1153 | test "pointer to struct literal with runtime field is constant" { | 1163 | test "pointer to struct literal with runtime field is constant" { |
| 1154 | const S = struct { data: usize }; | 1164 | const S = struct { data: usize }; |
| 1155 | var runtime_zero: usize = 0; | 1165 | var runtime_zero: usize = 0; |
| 1166 | _ = &runtime_zero; | ||
| 1156 | const ptr = &S{ .data = runtime_zero }; | 1167 | const ptr = &S{ .data = runtime_zero }; |
| 1157 | try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const); | 1168 | try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const); |
| 1158 | } | 1169 | } |
| ... | @@ -1163,6 +1174,7 @@ test "integer compare" { | ... | @@ -1163,6 +1174,7 @@ test "integer compare" { |
| 1163 | var z: T = 0; | 1174 | var z: T = 0; |
| 1164 | var p: T = 123; | 1175 | var p: T = 123; |
| 1165 | var n: T = -123; | 1176 | var n: T = -123; |
| 1177 | _ = .{ &z, &p, &n }; | ||
| 1166 | try expect(z == z and z != p and z != n); | 1178 | try expect(z == z and z != p and z != n); |
| 1167 | try expect(p == p and p != n and n == n); | 1179 | try expect(p == p and p != n and n == n); |
| 1168 | try expect(z > n and z < p and z >= n and z <= p); | 1180 | try expect(z > n and z < p and z >= n and z <= p); |
| ... | @@ -1180,6 +1192,7 @@ test "integer compare" { | ... | @@ -1180,6 +1192,7 @@ test "integer compare" { |
| 1180 | fn doTheTestUnsigned(comptime T: type) !void { | 1192 | fn doTheTestUnsigned(comptime T: type) !void { |
| 1181 | var z: T = 0; | 1193 | var z: T = 0; |
| 1182 | var p: T = 123; | 1194 | var p: T = 123; |
| 1195 | _ = .{ &z, &p }; | ||
| 1183 | try expect(z == z and z != p); | 1196 | try expect(z == z and z != p); |
| 1184 | try expect(p == p); | 1197 | try expect(p == p); |
| 1185 | try expect(z < p and z <= p); | 1198 | try expect(z < p and z <= p); |
test/behavior/bit_shifting.zig+2-2| ... | @@ -99,9 +99,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c | ... | @@ -99,9 +99,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c |
| 99 | // #2225 | 99 | // #2225 |
| 100 | test "comptime shr of BigInt" { | 100 | test "comptime shr of BigInt" { |
| 101 | comptime { | 101 | comptime { |
| 102 | var n0 = 0xdeadbeef0000000000000000; | 102 | const n0 = 0xdeadbeef0000000000000000; |
| 103 | try expect(n0 >> 64 == 0xdeadbeef); | 103 | try expect(n0 >> 64 == 0xdeadbeef); |
| 104 | var n1 = 17908056155735594659; | 104 | const n1 = 17908056155735594659; |
| 105 | try expect(n1 >> 64 == 0); | 105 | try expect(n1 >> 64 == 0); |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
test/behavior/bitcast.zig+19-7| ... | @@ -149,8 +149,9 @@ test "bitcast literal [4]u8 param to u32" { | ... | @@ -149,8 +149,9 @@ test "bitcast literal [4]u8 param to u32" { |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | test "bitcast generates a temporary value" { | 151 | test "bitcast generates a temporary value" { |
| 152 | var y = @as(u16, 0x55AA); | 152 | var y: u16 = 0x55AA; |
| 153 | const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y)))); | 153 | _ = &y; |
| 154 | const x: u16 = @bitCast(@as([2]u8, @bitCast(y))); | ||
| 154 | try expect(y == x); | 155 | try expect(y == x); |
| 155 | } | 156 | } |
| 156 | 157 | ||
| ... | @@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" { | ... | @@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" { |
| 171 | const S = struct { | 172 | const S = struct { |
| 172 | fn doTheTest() !void { | 173 | fn doTheTest() !void { |
| 173 | var full = Full{ .number = 0x1234 }; | 174 | var full = Full{ .number = 0x1234 }; |
| 174 | var two_halves = @as(Divided, @bitCast(full)); | 175 | _ = &full; |
| 176 | const two_halves: Divided = @bitCast(full); | ||
| 175 | try expect(two_halves.half1 == 0x34); | 177 | try expect(two_halves.half1 == 0x34); |
| 176 | try expect(two_halves.quarter3 == 0x2); | 178 | try expect(two_halves.quarter3 == 0x2); |
| 177 | try expect(two_halves.quarter4 == 0x1); | 179 | try expect(two_halves.quarter4 == 0x1); |
| ... | @@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" { | ... | @@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" { |
| 195 | const S = struct { | 197 | const S = struct { |
| 196 | fn doTheTest() !void { | 198 | fn doTheTest() !void { |
| 197 | var full = Full{ .number = 0x1234 }; | 199 | var full = Full{ .number = 0x1234 }; |
| 198 | var two_halves = @as(TwoHalves, @bitCast(full)); | 200 | _ = &full; |
| 201 | const two_halves: TwoHalves = @bitCast(full); | ||
| 199 | switch (native_endian) { | 202 | switch (native_endian) { |
| 200 | .big => { | 203 | .big => { |
| 201 | try expect(two_halves.half1 == 0x12); | 204 | try expect(two_halves.half1 == 0x12); |
| ... | @@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" { | ... | @@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" { |
| 225 | const S = struct { | 228 | const S = struct { |
| 226 | fn doTheTest() !void { | 229 | fn doTheTest() !void { |
| 227 | var move = LevelUpMove{ .move_id = 1, .level = 2 }; | 230 | var move = LevelUpMove{ .move_id = 1, .level = 2 }; |
| 228 | var v = @as(u16, @bitCast(move)); | 231 | _ = &move; |
| 229 | var back_to_a_move = @as(LevelUpMove, @bitCast(v)); | 232 | const v: u16 = @bitCast(move); |
| 233 | const back_to_a_move: LevelUpMove = @bitCast(v); | ||
| 230 | try expect(back_to_a_move.move_id == 1); | 234 | try expect(back_to_a_move.move_id == 1); |
| 231 | try expect(back_to_a_move.level == 2); | 235 | try expect(back_to_a_move.level == 2); |
| 232 | } | 236 | } |
| ... | @@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" { | ... | @@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" { |
| 312 | const S = struct { | 316 | const S = struct { |
| 313 | fn doTheTest() !void { | 317 | fn doTheTest() !void { |
| 314 | var foo = Foo{}; | 318 | var foo = Foo{}; |
| 315 | var v = @as(Foo2, @bitCast(foo)); | 319 | _ = &foo; |
| 320 | const v: Foo2 = @bitCast(foo); | ||
| 316 | try expect(v.a == foo.a); | 321 | try expect(v.a == foo.a); |
| 317 | try expect(v.b == foo.b); | 322 | try expect(v.b == foo.b); |
| 318 | try expect(v.c == foo.c); | 323 | try expect(v.c == foo.c); |
| ... | @@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" { | ... | @@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" { |
| 354 | 359 | ||
| 355 | // S -> Int | 360 | // S -> Int |
| 356 | var s: S = .{}; | 361 | var s: S = .{}; |
| 362 | _ = &s; | ||
| 357 | try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{}))); | 363 | try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{}))); |
| 358 | 364 | ||
| 359 | // Int -> S | 365 | // Int -> S |
| 360 | var i: Int = 0; | 366 | var i: Int = 0; |
| 367 | _ = &i; | ||
| 361 | const rt_cast = @as(S, @bitCast(i)); | 368 | const rt_cast = @as(S, @bitCast(i)); |
| 362 | const ct_cast = comptime @as(S, @bitCast(@as(Int, 0))); | 369 | const ct_cast = comptime @as(S, @bitCast(@as(Int, 0))); |
| 363 | inline for (@typeInfo(S).Struct.fields) |field| { | 370 | inline for (@typeInfo(S).Struct.fields) |field| { |
| ... | @@ -376,6 +383,7 @@ test "comptime bitcast with fields following f80" { | ... | @@ -376,6 +383,7 @@ test "comptime bitcast with fields following f80" { |
| 376 | const FloatT = extern struct { f: f80, x: u128 align(16) }; | 383 | const FloatT = extern struct { f: f80, x: u128 align(16) }; |
| 377 | const x: FloatT = .{ .f = 0.5, .x = 123 }; | 384 | const x: FloatT = .{ .f = 0.5, .x = 123 }; |
| 378 | var x_as_uint: u256 = comptime @as(u256, @bitCast(x)); | 385 | var x_as_uint: u256 = comptime @as(u256, @bitCast(x)); |
| 386 | _ = &x_as_uint; | ||
| 379 | 387 | ||
| 380 | try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f); | 388 | try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f); |
| 381 | try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x); | 389 | try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x); |
| ... | @@ -428,6 +436,7 @@ test "bitcast nan float does not modify signaling bit" { | ... | @@ -428,6 +436,7 @@ test "bitcast nan float does not modify signaling bit" { |
| 428 | try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const)); | 436 | try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const)); |
| 429 | 437 | ||
| 430 | var snan_f16_var = math.snan(f16); | 438 | var snan_f16_var = math.snan(f16); |
| 439 | _ = &snan_f16_var; | ||
| 431 | try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var))); | 440 | try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var))); |
| 432 | try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var)); | 441 | try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var)); |
| 433 | 442 | ||
| ... | @@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" { | ... | @@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" { |
| 437 | try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const)); | 446 | try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const)); |
| 438 | 447 | ||
| 439 | var snan_f32_var = math.snan(f32); | 448 | var snan_f32_var = math.snan(f32); |
| 449 | _ = &snan_f32_var; | ||
| 440 | try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var))); | 450 | try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var))); |
| 441 | try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var)); | 451 | try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var)); |
| 442 | 452 | ||
| ... | @@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" { | ... | @@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" { |
| 446 | try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const)); | 456 | try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const)); |
| 447 | 457 | ||
| 448 | var snan_f64_var = math.snan(f64); | 458 | var snan_f64_var = math.snan(f64); |
| 459 | _ = &snan_f64_var; | ||
| 449 | try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var))); | 460 | try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var))); |
| 450 | try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var)); | 461 | try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var)); |
| 451 | 462 | ||
| ... | @@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" { | ... | @@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" { |
| 455 | try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const)); | 466 | try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const)); |
| 456 | 467 | ||
| 457 | var snan_f128_var = math.snan(f128); | 468 | var snan_f128_var = math.snan(f128); |
| 469 | _ = &snan_f128_var; | ||
| 458 | try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var))); | 470 | try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var))); |
| 459 | try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var)); | 471 | try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var)); |
| 460 | } | 472 | } |
test/behavior/bitreverse.zig+26-4| ... | @@ -86,11 +86,30 @@ fn testBitReverse() !void { | ... | @@ -86,11 +86,30 @@ fn testBitReverse() !void { |
| 86 | try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24)); | 86 | try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24)); |
| 87 | var neg32: i32 = -16773785; | 87 | var neg32: i32 = -16773785; |
| 88 | try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32)); | 88 | try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32)); |
| 89 | |||
| 90 | _ = .{ | ||
| 91 | &num0, | ||
| 92 | &num5, | ||
| 93 | &num8, | ||
| 94 | &num16, | ||
| 95 | &num24, | ||
| 96 | &num32, | ||
| 97 | &num40, | ||
| 98 | &num48, | ||
| 99 | &num56, | ||
| 100 | &num64, | ||
| 101 | &num128, | ||
| 102 | &neg8, | ||
| 103 | &neg16, | ||
| 104 | &neg24, | ||
| 105 | &neg32, | ||
| 106 | }; | ||
| 89 | } | 107 | } |
| 90 | 108 | ||
| 91 | fn vector8() !void { | 109 | fn vector8() !void { |
| 92 | var v = @Vector(2, u8){ 0x12, 0x23 }; | 110 | var v = @Vector(2, u8){ 0x12, 0x23 }; |
| 93 | var result = @bitReverse(v); | 111 | _ = &v; |
| 112 | const result = @bitReverse(v); | ||
| 94 | try expect(result[0] == 0x48); | 113 | try expect(result[0] == 0x48); |
| 95 | try expect(result[1] == 0xc4); | 114 | try expect(result[1] == 0xc4); |
| 96 | } | 115 | } |
| ... | @@ -109,7 +128,8 @@ test "bitReverse vectors u8" { | ... | @@ -109,7 +128,8 @@ test "bitReverse vectors u8" { |
| 109 | 128 | ||
| 110 | fn vector16() !void { | 129 | fn vector16() !void { |
| 111 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; | 130 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; |
| 112 | var result = @bitReverse(v); | 131 | _ = &v; |
| 132 | const result = @bitReverse(v); | ||
| 113 | try expect(result[0] == 0x2c48); | 133 | try expect(result[0] == 0x2c48); |
| 114 | try expect(result[1] == 0xa2c4); | 134 | try expect(result[1] == 0xa2c4); |
| 115 | } | 135 | } |
| ... | @@ -128,7 +148,8 @@ test "bitReverse vectors u16" { | ... | @@ -128,7 +148,8 @@ test "bitReverse vectors u16" { |
| 128 | 148 | ||
| 129 | fn vector24() !void { | 149 | fn vector24() !void { |
| 130 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; | 150 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; |
| 131 | var result = @bitReverse(v); | 151 | _ = &v; |
| 152 | const result = @bitReverse(v); | ||
| 132 | try expect(result[0] == 0x6a2c48); | 153 | try expect(result[0] == 0x6a2c48); |
| 133 | try expect(result[1] == 0xe6a2c4); | 154 | try expect(result[1] == 0xe6a2c4); |
| 134 | } | 155 | } |
| ... | @@ -147,7 +168,8 @@ test "bitReverse vectors u24" { | ... | @@ -147,7 +168,8 @@ test "bitReverse vectors u24" { |
| 147 | 168 | ||
| 148 | fn vector0() !void { | 169 | fn vector0() !void { |
| 149 | var v = @Vector(2, u0){ 0, 0 }; | 170 | var v = @Vector(2, u0){ 0, 0 }; |
| 150 | var result = @bitReverse(v); | 171 | _ = &v; |
| 172 | const result = @bitReverse(v); | ||
| 151 | try expect(result[0] == 0); | 173 | try expect(result[0] == 0); |
| 152 | try expect(result[1] == 0); | 174 | try expect(result[1] == 0); |
| 153 | } | 175 | } |
test/behavior/bugs/10147.zig+4-2| ... | @@ -10,9 +10,11 @@ test "test calling @clz on both vector and scalar inputs" { | ... | @@ -10,9 +10,11 @@ test "test calling @clz on both vector and scalar inputs" { |
| 10 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 10 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 11 | 11 | ||
| 12 | var x: u32 = 0x1; | 12 | var x: u32 = 0x1; |
| 13 | _ = &x; | ||
| 13 | var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; | 14 | var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; |
| 14 | var a = @clz(x); | 15 | _ = &y; |
| 15 | var b = @clz(y); | 16 | const a = @clz(x); |
| 17 | const b = @clz(y); | ||
| 16 | try std.testing.expectEqual(@as(u6, 31), a); | 18 | try std.testing.expectEqual(@as(u6, 31), a); |
| 17 | try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); | 19 | try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); |
| 18 | } | 20 | } |
test/behavior/bugs/10970.zig+1| ... | @@ -9,6 +9,7 @@ test "breaking from a loop in an if statement" { | ... | @@ -9,6 +9,7 @@ test "breaking from a loop in an if statement" { |
| 9 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 9 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 10 | 10 | ||
| 11 | var cond = true; | 11 | var cond = true; |
| 12 | _ = &cond; | ||
| 12 | const opt = while (cond) { | 13 | const opt = while (cond) { |
| 13 | if (retOpt()) |opt| { | 14 | if (retOpt()) |opt| { |
| 14 | break opt; | 15 | break opt; |
test/behavior/bugs/11046.zig+1| ... | @@ -2,6 +2,7 @@ const builtin = @import("builtin"); | ... | @@ -2,6 +2,7 @@ const builtin = @import("builtin"); |
| 2 | 2 | ||
| 3 | fn foo() !void { | 3 | fn foo() !void { |
| 4 | var a = true; | 4 | var a = true; |
| 5 | _ = &a; | ||
| 5 | if (a) return error.Foo; | 6 | if (a) return error.Foo; |
| 6 | return error.Bar; | 7 | return error.Bar; |
| 7 | } | 8 | } |
test/behavior/bugs/11139.zig+1| ... | @@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 { | ... | @@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 { |
| 21 | S{ .x = 15 }, | 21 | S{ .x = 15 }, |
| 22 | }, | 22 | }, |
| 23 | }; | 23 | }; |
| 24 | _ = &cases; | ||
| 24 | return cases[0][0].x; | 25 | return cases[0][0].x; |
| 25 | } | 26 | } |
test/behavior/bugs/11159.zig+3-3| ... | @@ -4,7 +4,7 @@ const builtin = @import("builtin"); | ... | @@ -4,7 +4,7 @@ const builtin = @import("builtin"); |
| 4 | test { | 4 | test { |
| 5 | const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); | 5 | const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); |
| 6 | var a: T = .{ 0, 0 }; | 6 | var a: T = .{ 0, 0 }; |
| 7 | _ = a; | 7 | _ = &a; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | test { | 10 | test { |
| ... | @@ -13,7 +13,7 @@ test { | ... | @@ -13,7 +13,7 @@ test { |
| 13 | comptime y: u32 = 0, | 13 | comptime y: u32 = 0, |
| 14 | }; | 14 | }; |
| 15 | var a: S = .{}; | 15 | var a: S = .{}; |
| 16 | _ = a; | 16 | _ = &a; |
| 17 | var b = S{}; | 17 | var b = S{}; |
| 18 | _ = b; | 18 | _ = &b; |
| 19 | } | 19 | } |
test/behavior/bugs/11162.zig+2-1| ... | @@ -6,8 +6,9 @@ test "aggregate initializers should allow initializing comptime fields, verifyin | ... | @@ -6,8 +6,9 @@ test "aggregate initializers should allow initializing comptime fields, verifyin |
| 6 | if (true) return error.SkipZigTest; // TODO | 6 | if (true) return error.SkipZigTest; // TODO |
| 7 | 7 | ||
| 8 | var x: u32 = 15; | 8 | var x: u32 = 15; |
| 9 | _ = &x; | ||
| 9 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); | 10 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); |
| 10 | var a: T = .{ -1234, 5678, x + 1 }; | 11 | const a: T = .{ -1234, 5678, x + 1 }; |
| 11 | 12 | ||
| 12 | try expect(a[0] == -1234); | 13 | try expect(a[0] == -1234); |
| 13 | try expect(a[1] == 5678); | 14 | try expect(a[1] == 5678); |
test/behavior/bugs/11165.zig+2-2| ... | @@ -18,7 +18,7 @@ test "bytes" { | ... | @@ -18,7 +18,7 @@ test "bytes" { |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | var u_2 = U{ .s = s_1 }; | 20 | var u_2 = U{ .s = s_1 }; |
| 21 | _ = u_2; | 21 | _ = &u_2; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | test "aggregate" { | 24 | test "aggregate" { |
| ... | @@ -40,5 +40,5 @@ test "aggregate" { | ... | @@ -40,5 +40,5 @@ test "aggregate" { |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | var u_2 = U{ .s = s_1 }; | 42 | var u_2 = U{ .s = s_1 }; |
| 43 | _ = u_2; | 43 | _ = &u_2; |
| 44 | } | 44 | } |
test/behavior/bugs/11181.zig+1-1| ... | @@ -21,5 +21,5 @@ test "var inferred array of slices" { | ... | @@ -21,5 +21,5 @@ test "var inferred array of slices" { |
| 21 | .{ .v = false }, | 21 | .{ .v = false }, |
| 22 | }, | 22 | }, |
| 23 | }; | 23 | }; |
| 24 | _ = decls; | 24 | _ = &decls; |
| 25 | } | 25 | } |
test/behavior/bugs/12000.zig+1| ... | @@ -11,5 +11,6 @@ test { | ... | @@ -11,5 +11,6 @@ test { |
| 11 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 11 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 12 | 12 | ||
| 13 | var t: T = .{ .next = null }; | 13 | var t: T = .{ .next = null }; |
| 14 | _ = &t; | ||
| 14 | try std.testing.expect(t.next == null); | 15 | try std.testing.expect(t.next == null); |
| 15 | } | 16 | } |
test/behavior/bugs/12025.zig+1| ... | @@ -5,6 +5,7 @@ test { | ... | @@ -5,6 +5,7 @@ test { |
| 5 | .foo = &1, | 5 | .foo = &1, |
| 6 | .bar = &2, | 6 | .bar = &2, |
| 7 | }; | 7 | }; |
| 8 | _ = &st; | ||
| 8 | 9 | ||
| 9 | inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { | 10 | inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { |
| 10 | _ = field; | 11 | _ = field; |
test/behavior/bugs/12092.zig+1| ... | @@ -19,6 +19,7 @@ test { | ... | @@ -19,6 +19,7 @@ test { |
| 19 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 19 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 20 | 20 | ||
| 21 | var baz: u32 = 24; | 21 | var baz: u32 = 24; |
| 22 | _ = &baz; | ||
| 22 | try takeFoo(&.{ | 23 | try takeFoo(&.{ |
| 23 | .a = .{ | 24 | .a = .{ |
| 24 | .b = baz, | 25 | .b = baz, |
test/behavior/bugs/12498.zig+1| ... | @@ -4,5 +4,6 @@ const expect = std.testing.expect; | ... | @@ -4,5 +4,6 @@ const expect = std.testing.expect; |
| 4 | const S = struct { a: usize }; | 4 | const S = struct { a: usize }; |
| 5 | test "lazy abi size used in comparison" { | 5 | test "lazy abi size used in comparison" { |
| 6 | var rhs: i32 = 100; | 6 | var rhs: i32 = 100; |
| 7 | _ = &rhs; | ||
| 7 | try expect(@sizeOf(S) < rhs); | 8 | try expect(@sizeOf(S) < rhs); |
| 8 | } | 9 | } |
test/behavior/bugs/12776.zig+1| ... | @@ -22,6 +22,7 @@ const CPU = packed struct { | ... | @@ -22,6 +22,7 @@ const CPU = packed struct { |
| 22 | } | 22 | } |
| 23 | fn tick(self: *CPU) !void { | 23 | fn tick(self: *CPU) !void { |
| 24 | var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F); | 24 | var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F); |
| 25 | _ = &queued_interrupts; | ||
| 25 | if (self.interrupts and queued_interrupts != 0) { | 26 | if (self.interrupts and queued_interrupts != 0) { |
| 26 | self.interrupts = false; | 27 | self.interrupts = false; |
| 27 | } | 28 | } |
test/behavior/bugs/12891.zig+5| ... | @@ -4,26 +4,31 @@ const builtin = @import("builtin"); | ... | @@ -4,26 +4,31 @@ const builtin = @import("builtin"); |
| 4 | test "issue12891" { | 4 | test "issue12891" { |
| 5 | const f = 10.0; | 5 | const f = 10.0; |
| 6 | var i: usize = 0; | 6 | var i: usize = 0; |
| 7 | _ = &i; | ||
| 7 | try std.testing.expect(i < f); | 8 | try std.testing.expect(i < f); |
| 8 | } | 9 | } |
| 9 | test "nan" { | 10 | test "nan" { |
| 10 | const f = comptime std.math.nan(f64); | 11 | const f = comptime std.math.nan(f64); |
| 11 | var i: usize = 0; | 12 | var i: usize = 0; |
| 13 | _ = &i; | ||
| 12 | try std.testing.expect(!(f < i)); | 14 | try std.testing.expect(!(f < i)); |
| 13 | } | 15 | } |
| 14 | test "inf" { | 16 | test "inf" { |
| 15 | const f = comptime std.math.inf(f64); | 17 | const f = comptime std.math.inf(f64); |
| 16 | var i: usize = 0; | 18 | var i: usize = 0; |
| 19 | _ = &i; | ||
| 17 | try std.testing.expect(f > i); | 20 | try std.testing.expect(f > i); |
| 18 | } | 21 | } |
| 19 | test "-inf < 0" { | 22 | test "-inf < 0" { |
| 20 | const f = comptime -std.math.inf(f64); | 23 | const f = comptime -std.math.inf(f64); |
| 21 | var i: usize = 0; | 24 | var i: usize = 0; |
| 25 | _ = &i; | ||
| 22 | try std.testing.expect(f < i); | 26 | try std.testing.expect(f < i); |
| 23 | } | 27 | } |
| 24 | test "inf >= 1" { | 28 | test "inf >= 1" { |
| 25 | const f = comptime std.math.inf(f64); | 29 | const f = comptime std.math.inf(f64); |
| 26 | var i: usize = 1; | 30 | var i: usize = 1; |
| 31 | _ = &i; | ||
| 27 | try std.testing.expect(f >= i); | 32 | try std.testing.expect(f >= i); |
| 28 | } | 33 | } |
| 29 | test "isNan(nan * 1)" { | 34 | test "isNan(nan * 1)" { |
test/behavior/bugs/12972.zig+1| ... | @@ -12,6 +12,7 @@ test { | ... | @@ -12,6 +12,7 @@ test { |
| 12 | f(&.{c}); | 12 | f(&.{c}); |
| 13 | 13 | ||
| 14 | var v: u8 = 42; | 14 | var v: u8 = 42; |
| 15 | _ = &v; | ||
| 15 | f(&[_:null]?u8{v}); | 16 | f(&[_:null]?u8{v}); |
| 16 | f(&.{v}); | 17 | f(&.{v}); |
| 17 | } | 18 | } |
test/behavior/bugs/12984.zig+1-1| ... | @@ -16,5 +16,5 @@ test "simple test" { | ... | @@ -16,5 +16,5 @@ test "simple test" { |
| 16 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 16 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 17 | 17 | ||
| 18 | var c: CustomDraw = undefined; | 18 | var c: CustomDraw = undefined; |
| 19 | _ = c; | 19 | _ = &c; |
| 20 | } | 20 | } |
test/behavior/bugs/13128.zig+1| ... | @@ -18,6 +18,7 @@ test "runtime union init, most-aligned field != largest" { | ... | @@ -18,6 +18,7 @@ test "runtime union init, most-aligned field != largest" { |
| 18 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 18 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 19 | 19 | ||
| 20 | var x: u8 = 1; | 20 | var x: u8 = 1; |
| 21 | _ = &x; | ||
| 21 | try foo(.{ .x = x }); | 22 | try foo(.{ .x = x }); |
| 22 | 23 | ||
| 23 | const val: U = @unionInit(U, "x", x); | 24 | const val: U = @unionInit(U, "x", x); |
test/behavior/bugs/13159.zig+1| ... | @@ -13,5 +13,6 @@ test { | ... | @@ -13,5 +13,6 @@ test { |
| 13 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 13 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 14 | 14 | ||
| 15 | var foo = Bar.Baz.fizz; | 15 | var foo = Bar.Baz.fizz; |
| 16 | _ = &foo; | ||
| 16 | try expect(foo == .fizz); | 17 | try expect(foo == .fizz); |
| 17 | } | 18 | } |
test/behavior/bugs/13285.zig+1-1| ... | @@ -8,7 +8,7 @@ test { | ... | @@ -8,7 +8,7 @@ test { |
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 9 | 9 | ||
| 10 | var a: Crasher = undefined; | 10 | var a: Crasher = undefined; |
| 11 | var crasher_ptr = &a; | 11 | const crasher_ptr = &a; |
| 12 | var crasher_local = crasher_ptr.*; | 12 | var crasher_local = crasher_ptr.*; |
| 13 | const crasher_local_ptr = &crasher_local; | 13 | const crasher_local_ptr = &crasher_local; |
| 14 | crasher_local_ptr.lets_crash = 1; | 14 | crasher_local_ptr.lets_crash = 1; |
test/behavior/bugs/13366.zig+2| ... | @@ -18,9 +18,11 @@ test { | ... | @@ -18,9 +18,11 @@ test { |
| 18 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 18 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 19 | 19 | ||
| 20 | var a: u32 = 16; | 20 | var a: u32 = 16; |
| 21 | _ = &a; | ||
| 21 | var reason = .{ .c_import = .{ .a = a } }; | 22 | var reason = .{ .c_import = .{ .a = a } }; |
| 22 | var block = Block{ | 23 | var block = Block{ |
| 23 | .reason = &reason, | 24 | .reason = &reason, |
| 24 | }; | 25 | }; |
| 26 | _ = &block; | ||
| 25 | try expect(block.reason.?.c_import.a == 16); | 27 | try expect(block.reason.?.c_import.a == 16); |
| 26 | } | 28 | } |
test/behavior/bugs/13714.zig+1| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var image: [1]u8 = undefined; | 2 | var image: [1]u8 = undefined; |
| 3 | _ = &image; | ||
| 3 | _ = @shlExact(@as(u16, image[0]), 8); | 4 | _ = @shlExact(@as(u16, image[0]), 8); |
| 4 | } | 5 | } |
test/behavior/bugs/13785.zig+1| ... | @@ -9,5 +9,6 @@ test { | ... | @@ -9,5 +9,6 @@ test { |
| 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 10 | 10 | ||
| 11 | var a: u8 = 0; | 11 | var a: u8 = 0; |
| 12 | _ = &a; | ||
| 12 | try std.io.null_writer.print("\n{} {}\n", .{ a, S{} }); | 13 | try std.io.null_writer.print("\n{} {}\n", .{ a, S{} }); |
| 13 | } | 14 | } |
test/behavior/bugs/1381.zig+1| ... | @@ -20,6 +20,7 @@ test "union that needs padding bytes inside an array" { | ... | @@ -20,6 +20,7 @@ test "union that needs padding bytes inside an array" { |
| 20 | A{ .B = B{ .D = 1 } }, | 20 | A{ .B = B{ .D = 1 } }, |
| 21 | A{ .B = B{ .D = 1 } }, | 21 | A{ .B = B{ .D = 1 } }, |
| 22 | }; | 22 | }; |
| 23 | _ = &as; | ||
| 23 | 24 | ||
| 24 | const a = as[0].B; | 25 | const a = as[0].B; |
| 25 | try std.testing.expect(a.D == 1); | 26 | try std.testing.expect(a.D == 1); |
test/behavior/bugs/1442.zig+1| ... | @@ -12,5 +12,6 @@ test "const error union field alignment" { | ... | @@ -12,5 +12,6 @@ test "const error union field alignment" { |
| 12 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 12 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 13 | 13 | ||
| 14 | var union_or_err: anyerror!Union = Union{ .Color = 1234 }; | 14 | var union_or_err: anyerror!Union = Union{ .Color = 1234 }; |
| 15 | _ = &union_or_err; | ||
| 15 | try std.testing.expect((union_or_err catch unreachable).Color == 1234); | 16 | try std.testing.expect((union_or_err catch unreachable).Color == 1234); |
| 16 | } | 17 | } |
test/behavior/bugs/1500.zig+1| ... | @@ -8,6 +8,7 @@ const B = *const fn (A) void; | ... | @@ -8,6 +8,7 @@ const B = *const fn (A) void; |
| 8 | test "allow these dependencies" { | 8 | test "allow these dependencies" { |
| 9 | var a: A = undefined; | 9 | var a: A = undefined; |
| 10 | var b: B = undefined; | 10 | var b: B = undefined; |
| 11 | _ = .{ &a, &b }; | ||
| 11 | if (false) { | 12 | if (false) { |
| 12 | a; | 13 | a; |
| 13 | b; | 14 | b; |
test/behavior/bugs/1735.zig+1-1| ... | @@ -45,6 +45,6 @@ test "initialization" { | ... | @@ -45,6 +45,6 @@ test "initialization" { |
| 45 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | 45 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 46 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 46 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 47 | 47 | ||
| 48 | var t = a.init(); | 48 | const t = a.init(); |
| 49 | try std.testing.expect(t.foo.len == 0); | 49 | try std.testing.expect(t.foo.len == 0); |
| 50 | } | 50 | } |
test/behavior/bugs/2557.zig+1-1| ... | @@ -2,5 +2,5 @@ test { | ... | @@ -2,5 +2,5 @@ test { |
| 2 | var a = if (true) { | 2 | var a = if (true) { |
| 3 | return; | 3 | return; |
| 4 | } else true; | 4 | } else true; |
| 5 | _ = a; | 5 | _ = &a; |
| 6 | } | 6 | } |
test/behavior/bugs/3468.zig+1| ... | @@ -3,4 +3,5 @@ test "pointer deref next to assignment" { | ... | @@ -3,4 +3,5 @@ test "pointer deref next to assignment" { |
| 3 | var a:i32=2; | 3 | var a:i32=2; |
| 4 | var b=&a; | 4 | var b=&a; |
| 5 | b.*=3; | 5 | b.*=3; |
| 6 | _=&b; | ||
| 6 | } | 7 | } |
test/behavior/bugs/3586.zig+1-1| ... | @@ -12,5 +12,5 @@ test "fixed" { | ... | @@ -12,5 +12,5 @@ test "fixed" { |
| 12 | var ctr = Container{ | 12 | var ctr = Container{ |
| 13 | .params = NoteParams{}, | 13 | .params = NoteParams{}, |
| 14 | }; | 14 | }; |
| 15 | _ = ctr; | 15 | _ = &ctr; |
| 16 | } | 16 | } |
test/behavior/bugs/4560.zig+1| ... | @@ -11,6 +11,7 @@ test "fixed" { | ... | @@ -11,6 +11,7 @@ test "fixed" { |
| 11 | .max_distance_from_start_index = 456, | 11 | .max_distance_from_start_index = 456, |
| 12 | }, | 12 | }, |
| 13 | }; | 13 | }; |
| 14 | _ = &s; | ||
| 14 | try std.testing.expect(s.a == 1); | 15 | try std.testing.expect(s.a == 1); |
| 15 | try std.testing.expect(s.b.size == 123); | 16 | try std.testing.expect(s.b.size == 123); |
| 16 | try std.testing.expect(s.b.max_distance_from_start_index == 456); | 17 | try std.testing.expect(s.b.max_distance_from_start_index == 456); |
test/behavior/bugs/6047.zig+1| ... | @@ -6,6 +6,7 @@ fn getError() !void { | ... | @@ -6,6 +6,7 @@ fn getError() !void { |
| 6 | 6 | ||
| 7 | fn getError2() !void { | 7 | fn getError2() !void { |
| 8 | var a: u8 = 'c'; | 8 | var a: u8 = 'c'; |
| 9 | _ = &a; | ||
| 9 | try if (a == 'a') getError() else if (a == 'b') getError() else getError(); | 10 | try if (a == 'a') getError() else if (a == 'b') getError() else getError(); |
| 10 | } | 11 | } |
| 11 | 12 |
test/behavior/bugs/624.zig+1| ... | @@ -25,5 +25,6 @@ test "foo" { | ... | @@ -25,5 +25,6 @@ test "foo" { |
| 25 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 25 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 26 | 26 | ||
| 27 | var allocator = ContextAllocator{ .n = 10 }; | 27 | var allocator = ContextAllocator{ .n = 10 }; |
| 28 | _ = &allocator; | ||
| 28 | try expect(allocator.n == 10); | 29 | try expect(allocator.n == 10); |
| 29 | } | 30 | } |
test/behavior/bugs/656.zig+1| ... | @@ -22,6 +22,7 @@ fn foo(a: bool, b: bool) !void { | ... | @@ -22,6 +22,7 @@ fn foo(a: bool, b: bool) !void { |
| 22 | var prefix_op = PrefixOp{ | 22 | var prefix_op = PrefixOp{ |
| 23 | .AddrOf = Value{ .align_expr = 1234 }, | 23 | .AddrOf = Value{ .align_expr = 1234 }, |
| 24 | }; | 24 | }; |
| 25 | _ = &prefix_op; | ||
| 25 | if (a) {} else { | 26 | if (a) {} else { |
| 26 | switch (prefix_op) { | 27 | switch (prefix_op) { |
| 27 | PrefixOp.AddrOf => |addr_of_info| { | 28 | PrefixOp.AddrOf => |addr_of_info| { |
test/behavior/bugs/6781.zig+2-1| ... | @@ -51,7 +51,8 @@ pub const JournalHeader = packed struct { | ... | @@ -51,7 +51,8 @@ pub const JournalHeader = packed struct { |
| 51 | return @as(u128, @bitCast(target[0..hash_chain_root_size].*)); | 51 | return @as(u128, @bitCast(target[0..hash_chain_root_size].*)); |
| 52 | } else { | 52 | } else { |
| 53 | var array = target[0..hash_chain_root_size].*; | 53 | var array = target[0..hash_chain_root_size].*; |
| 54 | return @as(u128, @bitCast(array)); | 54 | _ = &array; |
| 55 | return @bitCast(array); | ||
| 55 | } | 56 | } |
| 56 | } | 57 | } |
| 57 | 58 |
test/behavior/bugs/679.zig+1| ... | @@ -14,5 +14,6 @@ const Element = struct { | ... | @@ -14,5 +14,6 @@ const Element = struct { |
| 14 | test "false dependency loop in struct definition" { | 14 | test "false dependency loop in struct definition" { |
| 15 | const listType = ElementList; | 15 | const listType = ElementList; |
| 16 | var x: listType = 42; | 16 | var x: listType = 42; |
| 17 | _ = &x; | ||
| 17 | try expect(x == 42); | 18 | try expect(x == 42); |
| 18 | } | 19 | } |
test/behavior/bugs/6905.zig+5-3| ... | @@ -6,13 +6,15 @@ test "sentinel-terminated 0-length slices" { | ... | @@ -6,13 +6,15 @@ test "sentinel-terminated 0-length slices" { |
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 8 | 8 | ||
| 9 | var u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; | 9 | const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; |
| 10 | 10 | ||
| 11 | var index: u8 = 2; | 11 | var index: u8 = 2; |
| 12 | var slice = u32s[index..index :2]; | 12 | _ = &index; |
| 13 | var array_ptr = u32s[2..2 :2]; | 13 | const slice = u32s[index..index :2]; |
| 14 | const array_ptr = u32s[2..2 :2]; | ||
| 14 | const comptime_known_array_value = u32s[2..2 :2].*; | 15 | const comptime_known_array_value = u32s[2..2 :2].*; |
| 15 | var runtime_array_value = u32s[2..2 :2].*; | 16 | var runtime_array_value = u32s[2..2 :2].*; |
| 17 | _ = &runtime_array_value; | ||
| 16 | 18 | ||
| 17 | try expect(slice[0] == 2); | 19 | try expect(slice[0] == 2); |
| 18 | try expect(array_ptr[0] == 2); | 20 | try expect(array_ptr[0] == 2); |
test/behavior/bugs/7187.zig+1-1| ... | @@ -5,7 +5,7 @@ const expect = std.testing.expect; | ... | @@ -5,7 +5,7 @@ const expect = std.testing.expect; |
| 5 | test "miscompilation with bool return type" { | 5 | test "miscompilation with bool return type" { |
| 6 | var x: usize = 1; | 6 | var x: usize = 1; |
| 7 | var y: bool = getFalse(); | 7 | var y: bool = getFalse(); |
| 8 | _ = y; | 8 | _ = .{ &x, &y }; |
| 9 | 9 | ||
| 10 | try expect(x == 1); | 10 | try expect(x == 1); |
| 11 | } | 11 | } |
test/behavior/bugs/726.zig+4-2| ... | @@ -7,7 +7,8 @@ test "@ptrCast from const to nullable" { | ... | @@ -7,7 +7,8 @@ test "@ptrCast from const to nullable" { |
| 7 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 7 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 8 | 8 | ||
| 9 | const c: u8 = 4; | 9 | const c: u8 = 4; |
| 10 | var x: ?*const u8 = @as(?*const u8, @ptrCast(&c)); | 10 | var x: ?*const u8 = @ptrCast(&c); |
| 11 | _ = &x; | ||
| 11 | try expect(x.?.* == 4); | 12 | try expect(x.?.* == 4); |
| 12 | } | 13 | } |
| 13 | 14 | ||
| ... | @@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" { | ... | @@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" { |
| 19 | const container = struct { | 20 | const container = struct { |
| 20 | var c: u8 = 4; | 21 | var c: u8 = 4; |
| 21 | }; | 22 | }; |
| 22 | var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c)); | 23 | var x: ?*const u8 = @ptrCast(&container.c); |
| 24 | _ = &x; | ||
| 23 | try expect(x.?.* == 4); | 25 | try expect(x.?.* == 4); |
| 24 | } | 26 | } |
test/behavior/bugs/7325.zig+2| ... | @@ -85,6 +85,7 @@ test { | ... | @@ -85,6 +85,7 @@ test { |
| 85 | var param: ParamType = .{ | 85 | var param: ParamType = .{ |
| 86 | .one_of = .{ .name = "name" }, | 86 | .one_of = .{ .name = "name" }, |
| 87 | }; | 87 | }; |
| 88 | _ = &param; | ||
| 88 | var arg: CallArg = .{ | 89 | var arg: CallArg = .{ |
| 89 | .value = .{ | 90 | .value = .{ |
| 90 | .literal_enum_value = .{ | 91 | .literal_enum_value = .{ |
| ... | @@ -92,6 +93,7 @@ test { | ... | @@ -92,6 +93,7 @@ test { |
| 92 | }, | 93 | }, |
| 93 | }, | 94 | }, |
| 94 | }; | 95 | }; |
| 96 | _ = &arg; | ||
| 95 | 97 | ||
| 96 | const result = try genExpression(arg.value); | 98 | const result = try genExpression(arg.value); |
| 97 | switch (result) { | 99 | switch (result) { |
test/behavior/bugs/9584.zig+1| ... | @@ -60,6 +60,7 @@ test { | ... | @@ -60,6 +60,7 @@ test { |
| 60 | .g = false, | 60 | .g = false, |
| 61 | .h = false, | 61 | .h = false, |
| 62 | }; | 62 | }; |
| 63 | _ = &flags; | ||
| 63 | var x = X{ | 64 | var x = X{ |
| 64 | .x = flags, | 65 | .x = flags, |
| 65 | }; | 66 | }; |
test/behavior/byteswap.zig+8-4| ... | @@ -56,7 +56,8 @@ test "@byteSwap integers" { | ... | @@ -56,7 +56,8 @@ test "@byteSwap integers" { |
| 56 | 56 | ||
| 57 | fn vector8() !void { | 57 | fn vector8() !void { |
| 58 | var v = @Vector(2, u8){ 0x12, 0x13 }; | 58 | var v = @Vector(2, u8){ 0x12, 0x13 }; |
| 59 | var result = @byteSwap(v); | 59 | _ = &v; |
| 60 | const result = @byteSwap(v); | ||
| 60 | try expect(result[0] == 0x12); | 61 | try expect(result[0] == 0x12); |
| 61 | try expect(result[1] == 0x13); | 62 | try expect(result[1] == 0x13); |
| 62 | } | 63 | } |
| ... | @@ -75,7 +76,8 @@ test "@byteSwap vectors u8" { | ... | @@ -75,7 +76,8 @@ test "@byteSwap vectors u8" { |
| 75 | 76 | ||
| 76 | fn vector16() !void { | 77 | fn vector16() !void { |
| 77 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; | 78 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; |
| 78 | var result = @byteSwap(v); | 79 | _ = &v; |
| 80 | const result = @byteSwap(v); | ||
| 79 | try expect(result[0] == 0x3412); | 81 | try expect(result[0] == 0x3412); |
| 80 | try expect(result[1] == 0x4523); | 82 | try expect(result[1] == 0x4523); |
| 81 | } | 83 | } |
| ... | @@ -94,7 +96,8 @@ test "@byteSwap vectors u16" { | ... | @@ -94,7 +96,8 @@ test "@byteSwap vectors u16" { |
| 94 | 96 | ||
| 95 | fn vector24() !void { | 97 | fn vector24() !void { |
| 96 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; | 98 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; |
| 97 | var result = @byteSwap(v); | 99 | _ = &v; |
| 100 | const result = @byteSwap(v); | ||
| 98 | try expect(result[0] == 0x563412); | 101 | try expect(result[0] == 0x563412); |
| 99 | try expect(result[1] == 0x674523); | 102 | try expect(result[1] == 0x674523); |
| 100 | } | 103 | } |
| ... | @@ -113,7 +116,8 @@ test "@byteSwap vectors u24" { | ... | @@ -113,7 +116,8 @@ test "@byteSwap vectors u24" { |
| 113 | 116 | ||
| 114 | fn vector0() !void { | 117 | fn vector0() !void { |
| 115 | var v = @Vector(2, u0){ 0, 0 }; | 118 | var v = @Vector(2, u0){ 0, 0 }; |
| 116 | var result = @byteSwap(v); | 119 | _ = &v; |
| 120 | const result = @byteSwap(v); | ||
| 117 | try expect(result[0] == 0); | 121 | try expect(result[0] == 0); |
| 118 | try expect(result[1] == 0); | 122 | try expect(result[1] == 0); |
| 119 | } | 123 | } |
test/behavior/call.zig+5| ... | @@ -47,6 +47,7 @@ test "basic invocations" { | ... | @@ -47,6 +47,7 @@ test "basic invocations" { |
| 47 | { | 47 | { |
| 48 | // call of non comptime-known function | 48 | // call of non comptime-known function |
| 49 | var alias_foo = &foo; | 49 | var alias_foo = &foo; |
| 50 | _ = &alias_foo; | ||
| 50 | try expect(@call(.no_async, alias_foo, .{}) == 1234); | 51 | try expect(@call(.no_async, alias_foo, .{}) == 1234); |
| 51 | try expect(@call(.never_tail, alias_foo, .{}) == 1234); | 52 | try expect(@call(.never_tail, alias_foo, .{}) == 1234); |
| 52 | try expect(@call(.never_inline, alias_foo, .{}) == 1234); | 53 | try expect(@call(.never_inline, alias_foo, .{}) == 1234); |
| ... | @@ -66,6 +67,7 @@ test "tuple parameters" { | ... | @@ -66,6 +67,7 @@ test "tuple parameters" { |
| 66 | }.add; | 67 | }.add; |
| 67 | var a: i32 = 12; | 68 | var a: i32 = 12; |
| 68 | var b: i32 = 34; | 69 | var b: i32 = 34; |
| 70 | _ = .{ &a, &b }; | ||
| 69 | try expect(@call(.auto, add, .{ a, 34 }) == 46); | 71 | try expect(@call(.auto, add, .{ a, 34 }) == 46); |
| 70 | try expect(@call(.auto, add, .{ 12, b }) == 46); | 72 | try expect(@call(.auto, add, .{ 12, b }) == 46); |
| 71 | try expect(@call(.auto, add, .{ a, b }) == 46); | 73 | try expect(@call(.auto, add, .{ a, b }) == 46); |
| ... | @@ -101,6 +103,7 @@ test "result location of function call argument through runtime condition and st | ... | @@ -101,6 +103,7 @@ test "result location of function call argument through runtime condition and st |
| 101 | } | 103 | } |
| 102 | }; | 104 | }; |
| 103 | var runtime = true; | 105 | var runtime = true; |
| 106 | _ = &runtime; | ||
| 104 | try namespace.foo(.{ | 107 | try namespace.foo(.{ |
| 105 | .e = if (!runtime) .a else .b, | 108 | .e = if (!runtime) .a else .b, |
| 106 | }); | 109 | }); |
| ... | @@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" { | ... | @@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" { |
| 445 | 448 | ||
| 446 | var rt_u16: u16 = 123; | 449 | var rt_u16: u16 = 123; |
| 447 | var rt_u32: u32 = 0x10000222; | 450 | var rt_u32: u32 = 0x10000222; |
| 451 | _ = .{ &rt_u16, &rt_u32 }; | ||
| 448 | 452 | ||
| 449 | try S.f(u8, @intCast(rt_u16)); | 453 | try S.f(u8, @intCast(rt_u16)); |
| 450 | try S.f(u8, @intCast(123)); | 454 | try S.f(u8, @intCast(123)); |
| ... | @@ -470,6 +474,7 @@ test "argument to generic function has correct result type" { | ... | @@ -470,6 +474,7 @@ test "argument to generic function has correct result type" { |
| 470 | 474 | ||
| 471 | fn doTheTest() !void { | 475 | fn doTheTest() !void { |
| 472 | var t = true; | 476 | var t = true; |
| 477 | _ = &t; | ||
| 473 | 478 | ||
| 474 | // Since the enum literal passes through a runtime conditional here, these can only | 479 | // Since the enum literal passes through a runtime conditional here, these can only |
| 475 | // compile if RLS provides the correct result type to the argument | 480 | // compile if RLS provides the correct result type to the argument |
test/behavior/cast.zig+123-42| ... | @@ -58,6 +58,7 @@ test "@intCast to comptime_int" { | ... | @@ -58,6 +58,7 @@ test "@intCast to comptime_int" { |
| 58 | test "implicit cast comptime numbers to any type when the value fits" { | 58 | test "implicit cast comptime numbers to any type when the value fits" { |
| 59 | const a: u64 = 255; | 59 | const a: u64 = 255; |
| 60 | var b: u8 = a; | 60 | var b: u8 = a; |
| 61 | _ = &b; | ||
| 61 | try expect(b == 255); | 62 | try expect(b == 255); |
| 62 | } | 63 | } |
| 63 | 64 | ||
| ... | @@ -273,7 +274,7 @@ test "implicit cast from *[N]T to [*c]T" { | ... | @@ -273,7 +274,7 @@ test "implicit cast from *[N]T to [*c]T" { |
| 273 | 274 | ||
| 274 | test "*usize to *void" { | 275 | test "*usize to *void" { |
| 275 | var i = @as(usize, 0); | 276 | var i = @as(usize, 0); |
| 276 | var v = @as(*void, @ptrCast(&i)); | 277 | const v: *void = @ptrCast(&i); |
| 277 | v.* = {}; | 278 | v.* = {}; |
| 278 | } | 279 | } |
| 279 | 280 | ||
| ... | @@ -391,7 +392,8 @@ test "peer type unsigned int to signed" { | ... | @@ -391,7 +392,8 @@ test "peer type unsigned int to signed" { |
| 391 | var w: u31 = 5; | 392 | var w: u31 = 5; |
| 392 | var x: u8 = 7; | 393 | var x: u8 = 7; |
| 393 | var y: i32 = -5; | 394 | var y: i32 = -5; |
| 394 | var a = w + y + x; | 395 | _ = .{ &w, &x, &y }; |
| 396 | const a = w + y + x; | ||
| 395 | try comptime expect(@TypeOf(a) == i32); | 397 | try comptime expect(@TypeOf(a) == i32); |
| 396 | try expect(a == 7); | 398 | try expect(a == 7); |
| 397 | } | 399 | } |
| ... | @@ -401,8 +403,9 @@ test "expected [*c]const u8, found [*:0]const u8" { | ... | @@ -401,8 +403,9 @@ test "expected [*c]const u8, found [*:0]const u8" { |
| 401 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 403 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 402 | 404 | ||
| 403 | var a: [*:0]const u8 = "hello"; | 405 | var a: [*:0]const u8 = "hello"; |
| 404 | var b: [*c]const u8 = a; | 406 | _ = &a; |
| 405 | var c: [*:0]const u8 = b; | 407 | const b: [*c]const u8 = a; |
| 408 | const c: [*:0]const u8 = b; | ||
| 406 | try expect(std.mem.eql(u8, c[0..5], "hello")); | 409 | try expect(std.mem.eql(u8, c[0..5], "hello")); |
| 407 | } | 410 | } |
| 408 | 411 | ||
| ... | @@ -609,14 +612,16 @@ test "@intCast on vector" { | ... | @@ -609,14 +612,16 @@ test "@intCast on vector" { |
| 609 | fn doTheTest() !void { | 612 | fn doTheTest() !void { |
| 610 | // Upcast (implicit, equivalent to @intCast) | 613 | // Upcast (implicit, equivalent to @intCast) |
| 611 | var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa }; | 614 | var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa }; |
| 612 | var up1 = @as(@Vector(2, u16), up0); | 615 | _ = &up0; |
| 613 | var up2 = @as(@Vector(2, u32), up0); | 616 | const up1 = @as(@Vector(2, u16), up0); |
| 614 | var up3 = @as(@Vector(2, u64), up0); | 617 | const up2 = @as(@Vector(2, u32), up0); |
| 618 | const up3 = @as(@Vector(2, u64), up0); | ||
| 615 | // Downcast (safety-checked) | 619 | // Downcast (safety-checked) |
| 616 | var down0 = up3; | 620 | var down0 = up3; |
| 617 | var down1 = @as(@Vector(2, u32), @intCast(down0)); | 621 | _ = &down0; |
| 618 | var down2 = @as(@Vector(2, u16), @intCast(down0)); | 622 | const down1 = @as(@Vector(2, u32), @intCast(down0)); |
| 619 | var down3 = @as(@Vector(2, u8), @intCast(down0)); | 623 | const down2 = @as(@Vector(2, u16), @intCast(down0)); |
| 624 | const down3 = @as(@Vector(2, u8), @intCast(down0)); | ||
| 620 | 625 | ||
| 621 | try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa })); | 626 | try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa })); |
| 622 | try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa })); | 627 | try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa })); |
| ... | @@ -629,7 +634,8 @@ test "@intCast on vector" { | ... | @@ -629,7 +634,8 @@ test "@intCast on vector" { |
| 629 | 634 | ||
| 630 | fn doTheTestFloat() !void { | 635 | fn doTheTestFloat() !void { |
| 631 | var vec: @Vector(2, f32) = @splat(1234.0); | 636 | var vec: @Vector(2, f32) = @splat(1234.0); |
| 632 | var wider: @Vector(2, f64) = vec; | 637 | _ = &vec; |
| 638 | const wider: @Vector(2, f64) = vec; | ||
| 633 | try expect(wider[0] == 1234.0); | 639 | try expect(wider[0] == 1234.0); |
| 634 | try expect(wider[1] == 1234.0); | 640 | try expect(wider[1] == 1234.0); |
| 635 | } | 641 | } |
| ... | @@ -648,7 +654,8 @@ test "@floatCast cast down" { | ... | @@ -648,7 +654,8 @@ test "@floatCast cast down" { |
| 648 | 654 | ||
| 649 | { | 655 | { |
| 650 | var double: f64 = 0.001534; | 656 | var double: f64 = 0.001534; |
| 651 | var single = @as(f32, @floatCast(double)); | 657 | _ = &double; |
| 658 | const single = @as(f32, @floatCast(double)); | ||
| 652 | try expect(single == 0.001534); | 659 | try expect(single == 0.001534); |
| 653 | } | 660 | } |
| 654 | { | 661 | { |
| ... | @@ -672,6 +679,7 @@ test "peer type resolution: unreachable, error set, unreachable" { | ... | @@ -672,6 +679,7 @@ test "peer type resolution: unreachable, error set, unreachable" { |
| 672 | Unexpected, | 679 | Unexpected, |
| 673 | }; | 680 | }; |
| 674 | var err = Error.SystemResources; | 681 | var err = Error.SystemResources; |
| 682 | _ = &err; | ||
| 675 | const transformed_err = switch (err) { | 683 | const transformed_err = switch (err) { |
| 676 | error.FileDescriptorAlreadyPresentInSet => unreachable, | 684 | error.FileDescriptorAlreadyPresentInSet => unreachable, |
| 677 | error.OperationCausesCircularLoop => unreachable, | 685 | error.OperationCausesCircularLoop => unreachable, |
| ... | @@ -821,10 +829,11 @@ test "peer cast *[0]T to E![]const T" { | ... | @@ -821,10 +829,11 @@ test "peer cast *[0]T to E![]const T" { |
| 821 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 829 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 822 | 830 | ||
| 823 | var buffer: [5]u8 = "abcde".*; | 831 | var buffer: [5]u8 = "abcde".*; |
| 824 | var buf: anyerror![]const u8 = buffer[0..]; | 832 | const buf: anyerror![]const u8 = buffer[0..]; |
| 825 | var b = false; | 833 | var b = false; |
| 826 | var y = if (b) &[0]u8{} else buf; | 834 | _ = &b; |
| 827 | var z = if (!b) buf else &[0]u8{}; | 835 | const y = if (b) &[0]u8{} else buf; |
| 836 | const z = if (!b) buf else &[0]u8{}; | ||
| 828 | try expect(mem.eql(u8, "abcde", y catch unreachable)); | 837 | try expect(mem.eql(u8, "abcde", y catch unreachable)); |
| 829 | try expect(mem.eql(u8, "abcde", z catch unreachable)); | 838 | try expect(mem.eql(u8, "abcde", z catch unreachable)); |
| 830 | } | 839 | } |
| ... | @@ -835,9 +844,10 @@ test "peer cast *[0]T to []const T" { | ... | @@ -835,9 +844,10 @@ test "peer cast *[0]T to []const T" { |
| 835 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 844 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 836 | 845 | ||
| 837 | var buffer: [5]u8 = "abcde".*; | 846 | var buffer: [5]u8 = "abcde".*; |
| 838 | var buf: []const u8 = buffer[0..]; | 847 | const buf: []const u8 = buffer[0..]; |
| 839 | var b = false; | 848 | var b = false; |
| 840 | var y = if (b) &[0]u8{} else buf; | 849 | _ = &b; |
| 850 | const y = if (b) &[0]u8{} else buf; | ||
| 841 | try expect(mem.eql(u8, "abcde", y)); | 851 | try expect(mem.eql(u8, "abcde", y)); |
| 842 | } | 852 | } |
| 843 | 853 | ||
| ... | @@ -846,6 +856,7 @@ test "peer cast *[N]T to [*]T" { | ... | @@ -846,6 +856,7 @@ test "peer cast *[N]T to [*]T" { |
| 846 | 856 | ||
| 847 | var array = [4:99]i32{ 1, 2, 3, 4 }; | 857 | var array = [4:99]i32{ 1, 2, 3, 4 }; |
| 848 | var dest: [*]i32 = undefined; | 858 | var dest: [*]i32 = undefined; |
| 859 | _ = &dest; | ||
| 849 | try expect(@TypeOf(&array, dest) == [*]i32); | 860 | try expect(@TypeOf(&array, dest) == [*]i32); |
| 850 | try expect(@TypeOf(dest, &array) == [*]i32); | 861 | try expect(@TypeOf(dest, &array) == [*]i32); |
| 851 | } | 862 | } |
| ... | @@ -879,8 +890,8 @@ test "peer cast [:x]T to []T" { | ... | @@ -879,8 +890,8 @@ test "peer cast [:x]T to []T" { |
| 879 | const S = struct { | 890 | const S = struct { |
| 880 | fn doTheTest() !void { | 891 | fn doTheTest() !void { |
| 881 | var array = [4:0]i32{ 1, 2, 3, 4 }; | 892 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 882 | var slice: [:0]i32 = &array; | 893 | const slice: [:0]i32 = &array; |
| 883 | var dest: []i32 = slice; | 894 | const dest: []i32 = slice; |
| 884 | try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); | 895 | try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); |
| 885 | } | 896 | } |
| 886 | }; | 897 | }; |
| ... | @@ -895,7 +906,8 @@ test "peer cast [N:x]T to [N]T" { | ... | @@ -895,7 +906,8 @@ test "peer cast [N:x]T to [N]T" { |
| 895 | const S = struct { | 906 | const S = struct { |
| 896 | fn doTheTest() !void { | 907 | fn doTheTest() !void { |
| 897 | var array = [4:0]i32{ 1, 2, 3, 4 }; | 908 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 898 | var dest: [4]i32 = array; | 909 | _ = &array; |
| 910 | const dest: [4]i32 = array; | ||
| 899 | try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 })); | 911 | try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 })); |
| 900 | } | 912 | } |
| 901 | }; | 913 | }; |
| ... | @@ -910,7 +922,7 @@ test "peer cast *[N:x]T to *[N]T" { | ... | @@ -910,7 +922,7 @@ test "peer cast *[N:x]T to *[N]T" { |
| 910 | const S = struct { | 922 | const S = struct { |
| 911 | fn doTheTest() !void { | 923 | fn doTheTest() !void { |
| 912 | var array = [4:0]i32{ 1, 2, 3, 4 }; | 924 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 913 | var dest: *[4]i32 = &array; | 925 | const dest: *[4]i32 = &array; |
| 914 | try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); | 926 | try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); |
| 915 | } | 927 | } |
| 916 | }; | 928 | }; |
| ... | @@ -925,7 +937,7 @@ test "peer cast [*:x]T to [*]T" { | ... | @@ -925,7 +937,7 @@ test "peer cast [*:x]T to [*]T" { |
| 925 | const S = struct { | 937 | const S = struct { |
| 926 | fn doTheTest() !void { | 938 | fn doTheTest() !void { |
| 927 | var array = [4:99]i32{ 1, 2, 3, 4 }; | 939 | var array = [4:99]i32{ 1, 2, 3, 4 }; |
| 928 | var dest: [*]i32 = &array; | 940 | const dest: [*]i32 = &array; |
| 929 | try expect(dest[0] == 1); | 941 | try expect(dest[0] == 1); |
| 930 | try expect(dest[1] == 2); | 942 | try expect(dest[1] == 2); |
| 931 | try expect(dest[2] == 3); | 943 | try expect(dest[2] == 3); |
| ... | @@ -945,8 +957,8 @@ test "peer cast [:x]T to [*:x]T" { | ... | @@ -945,8 +957,8 @@ test "peer cast [:x]T to [*:x]T" { |
| 945 | const S = struct { | 957 | const S = struct { |
| 946 | fn doTheTest() !void { | 958 | fn doTheTest() !void { |
| 947 | var array = [4:0]i32{ 1, 2, 3, 4 }; | 959 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 948 | var slice: [:0]i32 = &array; | 960 | const slice: [:0]i32 = &array; |
| 949 | var dest: [*:0]i32 = slice; | 961 | const dest: [*:0]i32 = slice; |
| 950 | try expect(dest[0] == 1); | 962 | try expect(dest[0] == 1); |
| 951 | try expect(dest[1] == 2); | 963 | try expect(dest[1] == 2); |
| 952 | try expect(dest[2] == 3); | 964 | try expect(dest[2] == 3); |
| ... | @@ -998,6 +1010,7 @@ test "peer type resolution implicit cast to variable type" { | ... | @@ -998,6 +1010,7 @@ test "peer type resolution implicit cast to variable type" { |
| 998 | 1010 | ||
| 999 | test "variable initialization uses result locations properly with regards to the type" { | 1011 | test "variable initialization uses result locations properly with regards to the type" { |
| 1000 | var b = true; | 1012 | var b = true; |
| 1013 | _ = &b; | ||
| 1001 | const x: i32 = if (b) 1 else 2; | 1014 | const x: i32 = if (b) 1 else 2; |
| 1002 | try expect(x == 1); | 1015 | try expect(x == 1); |
| 1003 | } | 1016 | } |
| ... | @@ -1025,7 +1038,7 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" { | ... | @@ -1025,7 +1038,7 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" { |
| 1025 | 1038 | ||
| 1026 | var array: [4:0]u8 = undefined; | 1039 | var array: [4:0]u8 = undefined; |
| 1027 | array[4] = 0; // TODO remove this when #4372 is solved | 1040 | array[4] = 0; // TODO remove this when #4372 is solved |
| 1028 | var slice: [:0]u8 = array[0..4 :0]; | 1041 | const slice: [:0]u8 = array[0..4 :0]; |
| 1029 | try comptime expect(@TypeOf(slice, "hi") == [:0]const u8); | 1042 | try comptime expect(@TypeOf(slice, "hi") == [:0]const u8); |
| 1030 | try comptime expect(@TypeOf("hi", slice) == [:0]const u8); | 1043 | try comptime expect(@TypeOf("hi", slice) == [:0]const u8); |
| 1031 | } | 1044 | } |
| ... | @@ -1042,6 +1055,7 @@ test "peer type resolve array pointer and unknown pointer" { | ... | @@ -1042,6 +1055,7 @@ test "peer type resolve array pointer and unknown pointer" { |
| 1042 | var array: [4]u8 = undefined; | 1055 | var array: [4]u8 = undefined; |
| 1043 | var const_ptr: [*]const u8 = undefined; | 1056 | var const_ptr: [*]const u8 = undefined; |
| 1044 | var ptr: [*]u8 = undefined; | 1057 | var ptr: [*]u8 = undefined; |
| 1058 | _ = .{ &const_ptr, &ptr }; | ||
| 1045 | 1059 | ||
| 1046 | try comptime expect(@TypeOf(&array, ptr) == [*]u8); | 1060 | try comptime expect(@TypeOf(&array, ptr) == [*]u8); |
| 1047 | try comptime expect(@TypeOf(ptr, &array) == [*]u8); | 1061 | try comptime expect(@TypeOf(ptr, &array) == [*]u8); |
| ... | @@ -1090,6 +1104,7 @@ test "implicit cast from [*]T to ?*anyopaque" { | ... | @@ -1090,6 +1104,7 @@ test "implicit cast from [*]T to ?*anyopaque" { |
| 1090 | 1104 | ||
| 1091 | var a = [_]u8{ 3, 2, 1 }; | 1105 | var a = [_]u8{ 3, 2, 1 }; |
| 1092 | var runtime_zero: usize = 0; | 1106 | var runtime_zero: usize = 0; |
| 1107 | _ = &runtime_zero; | ||
| 1093 | incrementVoidPtrArray(a[runtime_zero..].ptr, 3); | 1108 | incrementVoidPtrArray(a[runtime_zero..].ptr, 3); |
| 1094 | try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); | 1109 | try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); |
| 1095 | } | 1110 | } |
| ... | @@ -1151,11 +1166,11 @@ test "implicit ptr to *anyopaque" { | ... | @@ -1151,11 +1166,11 @@ test "implicit ptr to *anyopaque" { |
| 1151 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1166 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1152 | 1167 | ||
| 1153 | var a: u32 = 1; | 1168 | var a: u32 = 1; |
| 1154 | var ptr: *align(@alignOf(u32)) anyopaque = &a; | 1169 | const ptr: *align(@alignOf(u32)) anyopaque = &a; |
| 1155 | var b: *u32 = @as(*u32, @ptrCast(ptr)); | 1170 | const b: *u32 = @as(*u32, @ptrCast(ptr)); |
| 1156 | try expect(b.* == 1); | 1171 | try expect(b.* == 1); |
| 1157 | var ptr2: ?*align(@alignOf(u32)) anyopaque = &a; | 1172 | const ptr2: ?*align(@alignOf(u32)) anyopaque = &a; |
| 1158 | var c: *u32 = @as(*u32, @ptrCast(ptr2.?)); | 1173 | const c: *u32 = @as(*u32, @ptrCast(ptr2.?)); |
| 1159 | try expect(c.* == 1); | 1174 | try expect(c.* == 1); |
| 1160 | } | 1175 | } |
| 1161 | 1176 | ||
| ... | @@ -1264,6 +1279,7 @@ test "implicit cast *[0]T to E![]const u8" { | ... | @@ -1264,6 +1279,7 @@ test "implicit cast *[0]T to E![]const u8" { |
| 1264 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1279 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1265 | 1280 | ||
| 1266 | var x = @as(anyerror![]const u8, &[0]u8{}); | 1281 | var x = @as(anyerror![]const u8, &[0]u8{}); |
| 1282 | _ = &x; | ||
| 1267 | try expect((x catch unreachable).len == 0); | 1283 | try expect((x catch unreachable).len == 0); |
| 1268 | } | 1284 | } |
| 1269 | 1285 | ||
| ... | @@ -1274,6 +1290,7 @@ test "cast from array reference to fn: comptime fn ptr" { | ... | @@ -1274,6 +1290,7 @@ test "cast from array reference to fn: comptime fn ptr" { |
| 1274 | } | 1290 | } |
| 1275 | test "cast from array reference to fn: runtime fn ptr" { | 1291 | test "cast from array reference to fn: runtime fn ptr" { |
| 1276 | var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); | 1292 | var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); |
| 1293 | _ = &f; | ||
| 1277 | try expect(@intFromPtr(f) == @intFromPtr(&global_array)); | 1294 | try expect(@intFromPtr(f) == @intFromPtr(&global_array)); |
| 1278 | } | 1295 | } |
| 1279 | 1296 | ||
| ... | @@ -1285,7 +1302,8 @@ test "*const [N]null u8 to ?[]const u8" { | ... | @@ -1285,7 +1302,8 @@ test "*const [N]null u8 to ?[]const u8" { |
| 1285 | const S = struct { | 1302 | const S = struct { |
| 1286 | fn doTheTest() !void { | 1303 | fn doTheTest() !void { |
| 1287 | var a = "Hello"; | 1304 | var a = "Hello"; |
| 1288 | var b: ?[]const u8 = a; | 1305 | _ = &a; |
| 1306 | const b: ?[]const u8 = a; | ||
| 1289 | try expect(mem.eql(u8, b.?, "Hello")); | 1307 | try expect(mem.eql(u8, b.?, "Hello")); |
| 1290 | } | 1308 | } |
| 1291 | }; | 1309 | }; |
| ... | @@ -1318,12 +1336,13 @@ test "assignment to optional pointer result loc" { | ... | @@ -1318,12 +1336,13 @@ test "assignment to optional pointer result loc" { |
| 1318 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1336 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1319 | 1337 | ||
| 1320 | var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct }; | 1338 | var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct }; |
| 1339 | _ = &foo; | ||
| 1321 | try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct))); | 1340 | try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct))); |
| 1322 | } | 1341 | } |
| 1323 | 1342 | ||
| 1324 | test "cast between *[N]void and []void" { | 1343 | test "cast between *[N]void and []void" { |
| 1325 | var a: [4]void = undefined; | 1344 | var a: [4]void = undefined; |
| 1326 | var b: []void = &a; | 1345 | const b: []void = &a; |
| 1327 | try expect(b.len == 4); | 1346 | try expect(b.len == 4); |
| 1328 | } | 1347 | } |
| 1329 | 1348 | ||
| ... | @@ -1351,6 +1370,7 @@ test "cast f16 to wider types" { | ... | @@ -1351,6 +1370,7 @@ test "cast f16 to wider types" { |
| 1351 | const S = struct { | 1370 | const S = struct { |
| 1352 | fn doTheTest() !void { | 1371 | fn doTheTest() !void { |
| 1353 | var x: f16 = 1234.0; | 1372 | var x: f16 = 1234.0; |
| 1373 | _ = &x; | ||
| 1354 | try expect(@as(f32, 1234.0) == x); | 1374 | try expect(@as(f32, 1234.0) == x); |
| 1355 | try expect(@as(f64, 1234.0) == x); | 1375 | try expect(@as(f64, 1234.0) == x); |
| 1356 | try expect(@as(f128, 1234.0) == x); | 1376 | try expect(@as(f128, 1234.0) == x); |
| ... | @@ -1370,6 +1390,7 @@ test "cast f128 to narrower types" { | ... | @@ -1370,6 +1390,7 @@ test "cast f128 to narrower types" { |
| 1370 | const S = struct { | 1390 | const S = struct { |
| 1371 | fn doTheTest() !void { | 1391 | fn doTheTest() !void { |
| 1372 | var x: f128 = 1234.0; | 1392 | var x: f128 = 1234.0; |
| 1393 | _ = &x; | ||
| 1373 | try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x))); | 1394 | try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x))); |
| 1374 | try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x))); | 1395 | try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x))); |
| 1375 | try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x))); | 1396 | try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x))); |
| ... | @@ -1404,6 +1425,7 @@ test "cast i8 fn call peers to i32 result" { | ... | @@ -1404,6 +1425,7 @@ test "cast i8 fn call peers to i32 result" { |
| 1404 | const S = struct { | 1425 | const S = struct { |
| 1405 | fn doTheTest() !void { | 1426 | fn doTheTest() !void { |
| 1406 | var cond = true; | 1427 | var cond = true; |
| 1428 | _ = &cond; | ||
| 1407 | const value: i32 = if (cond) smallBoi() else bigBoi(); | 1429 | const value: i32 = if (cond) smallBoi() else bigBoi(); |
| 1408 | try expect(value == 123); | 1430 | try expect(value == 123); |
| 1409 | } | 1431 | } |
| ... | @@ -1424,7 +1446,8 @@ test "cast compatible optional types" { | ... | @@ -1424,7 +1446,8 @@ test "cast compatible optional types" { |
| 1424 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1446 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1425 | 1447 | ||
| 1426 | var a: ?[:0]const u8 = null; | 1448 | var a: ?[:0]const u8 = null; |
| 1427 | var b: ?[]const u8 = a; | 1449 | _ = &a; |
| 1450 | const b: ?[]const u8 = a; | ||
| 1428 | try expect(b == null); | 1451 | try expect(b == null); |
| 1429 | } | 1452 | } |
| 1430 | 1453 | ||
| ... | @@ -1434,6 +1457,7 @@ test "coerce undefined single-item pointer of array to error union of slice" { | ... | @@ -1434,6 +1457,7 @@ test "coerce undefined single-item pointer of array to error union of slice" { |
| 1434 | 1457 | ||
| 1435 | const a = @as([*]u8, undefined)[0..0]; | 1458 | const a = @as([*]u8, undefined)[0..0]; |
| 1436 | var b: error{a}![]const u8 = a; | 1459 | var b: error{a}![]const u8 = a; |
| 1460 | _ = &b; | ||
| 1437 | const s = try b; | 1461 | const s = try b; |
| 1438 | try expect(s.len == 0); | 1462 | try expect(s.len == 0); |
| 1439 | } | 1463 | } |
| ... | @@ -1442,6 +1466,7 @@ test "pointer to empty struct literal to mutable slice" { | ... | @@ -1442,6 +1466,7 @@ test "pointer to empty struct literal to mutable slice" { |
| 1442 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1466 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1443 | 1467 | ||
| 1444 | var x: []i32 = &.{}; | 1468 | var x: []i32 = &.{}; |
| 1469 | _ = &x; | ||
| 1445 | try expect(x.len == 0); | 1470 | try expect(x.len == 0); |
| 1446 | } | 1471 | } |
| 1447 | 1472 | ||
| ... | @@ -1466,7 +1491,7 @@ test "coerce between pointers of compatible differently-named floats" { | ... | @@ -1466,7 +1491,7 @@ test "coerce between pointers of compatible differently-named floats" { |
| 1466 | else => @compileError("unreachable"), | 1491 | else => @compileError("unreachable"), |
| 1467 | }; | 1492 | }; |
| 1468 | var f1: F = 12.34; | 1493 | var f1: F = 12.34; |
| 1469 | var f2: *c_longdouble = &f1; | 1494 | const f2: *c_longdouble = &f1; |
| 1470 | f2.* += 1; | 1495 | f2.* += 1; |
| 1471 | try expect(f1 == @as(F, 12.34) + 1); | 1496 | try expect(f1 == @as(F, 12.34) + 1); |
| 1472 | } | 1497 | } |
| ... | @@ -1507,8 +1532,9 @@ test "implicit cast from [:0]T to [*c]T" { | ... | @@ -1507,8 +1532,9 @@ test "implicit cast from [:0]T to [*c]T" { |
| 1507 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1532 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 1508 | 1533 | ||
| 1509 | var a: [:0]const u8 = "foo"; | 1534 | var a: [:0]const u8 = "foo"; |
| 1510 | var b: [*c]const u8 = a; | 1535 | _ = &a; |
| 1511 | var c = std.mem.span(b); | 1536 | const b: [*c]const u8 = a; |
| 1537 | const c = std.mem.span(b); | ||
| 1512 | try expect(c.len == a.len); | 1538 | try expect(c.len == a.len); |
| 1513 | try expect(c.ptr == a.ptr); | 1539 | try expect(c.ptr == a.ptr); |
| 1514 | } | 1540 | } |
| ... | @@ -1544,6 +1570,7 @@ test "single item pointer to pointer to array to slice" { | ... | @@ -1544,6 +1570,7 @@ test "single item pointer to pointer to array to slice" { |
| 1544 | 1570 | ||
| 1545 | test "peer type resolution forms error union" { | 1571 | test "peer type resolution forms error union" { |
| 1546 | var foo: i32 = 123; | 1572 | var foo: i32 = 123; |
| 1573 | _ = &foo; | ||
| 1547 | const result = if (foo < 0) switch (-foo) { | 1574 | const result = if (foo < 0) switch (-foo) { |
| 1548 | 0 => unreachable, | 1575 | 0 => unreachable, |
| 1549 | 42 => error.AccessDenied, | 1576 | 42 => error.AccessDenied, |
| ... | @@ -1561,7 +1588,7 @@ test "@constCast without a result location" { | ... | @@ -1561,7 +1588,7 @@ test "@constCast without a result location" { |
| 1561 | 1588 | ||
| 1562 | test "@volatileCast without a result location" { | 1589 | test "@volatileCast without a result location" { |
| 1563 | var x: i32 = 1234; | 1590 | var x: i32 = 1234; |
| 1564 | var y: *volatile i32 = &x; | 1591 | const y: *volatile i32 = &x; |
| 1565 | const z = @volatileCast(y); | 1592 | const z = @volatileCast(y); |
| 1566 | try expect(@TypeOf(z) == *i32); | 1593 | try expect(@TypeOf(z) == *i32); |
| 1567 | try expect(z.* == 1234); | 1594 | try expect(z.* == 1234); |
| ... | @@ -1585,10 +1612,12 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice" | ... | @@ -1585,10 +1612,12 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice" |
| 1585 | fn doTheTest(comptime T: type, comptime s: T) !void { | 1612 | fn doTheTest(comptime T: type, comptime s: T) !void { |
| 1586 | var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000)); | 1613 | var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000)); |
| 1587 | var b: []T = @as(*[3]T, @ptrFromInt(0x2000)); | 1614 | var b: []T = @as(*[3]T, @ptrFromInt(0x2000)); |
| 1615 | _ = .{ &a, &b }; | ||
| 1588 | comptime assert(@TypeOf(a, b) == []const T); | 1616 | comptime assert(@TypeOf(a, b) == []const T); |
| 1589 | comptime assert(@TypeOf(b, a) == []const T); | 1617 | comptime assert(@TypeOf(b, a) == []const T); |
| 1590 | 1618 | ||
| 1591 | var t = true; | 1619 | var t = true; |
| 1620 | _ = &t; | ||
| 1592 | const r1 = if (t) a else b; | 1621 | const r1 = if (t) a else b; |
| 1593 | const r2 = if (t) b else a; | 1622 | const r2 = if (t) b else a; |
| 1594 | 1623 | ||
| ... | @@ -1611,10 +1640,12 @@ test "peer type resolution: float and comptime-known fixed-width integer" { | ... | @@ -1611,10 +1640,12 @@ test "peer type resolution: float and comptime-known fixed-width integer" { |
| 1611 | 1640 | ||
| 1612 | const i: u8 = 100; | 1641 | const i: u8 = 100; |
| 1613 | var f: f32 = 1.234; | 1642 | var f: f32 = 1.234; |
| 1643 | _ = &f; | ||
| 1614 | comptime assert(@TypeOf(i, f) == f32); | 1644 | comptime assert(@TypeOf(i, f) == f32); |
| 1615 | comptime assert(@TypeOf(f, i) == f32); | 1645 | comptime assert(@TypeOf(f, i) == f32); |
| 1616 | 1646 | ||
| 1617 | var t = true; | 1647 | var t = true; |
| 1648 | _ = &t; | ||
| 1618 | const r1 = if (t) i else f; | 1649 | const r1 = if (t) i else f; |
| 1619 | const r2 = if (t) f else i; | 1650 | const r2 = if (t) f else i; |
| 1620 | 1651 | ||
| ... | @@ -1631,10 +1662,12 @@ test "peer type resolution: same array type with sentinel" { | ... | @@ -1631,10 +1662,12 @@ test "peer type resolution: same array type with sentinel" { |
| 1631 | 1662 | ||
| 1632 | var a: [2:0]u32 = .{ 0, 1 }; | 1663 | var a: [2:0]u32 = .{ 0, 1 }; |
| 1633 | var b: [2:0]u32 = .{ 2, 3 }; | 1664 | var b: [2:0]u32 = .{ 2, 3 }; |
| 1665 | _ = .{ &a, &b }; | ||
| 1634 | comptime assert(@TypeOf(a, b) == [2:0]u32); | 1666 | comptime assert(@TypeOf(a, b) == [2:0]u32); |
| 1635 | comptime assert(@TypeOf(b, a) == [2:0]u32); | 1667 | comptime assert(@TypeOf(b, a) == [2:0]u32); |
| 1636 | 1668 | ||
| 1637 | var t = true; | 1669 | var t = true; |
| 1670 | _ = &t; | ||
| 1638 | const r1 = if (t) a else b; | 1671 | const r1 = if (t) a else b; |
| 1639 | const r2 = if (t) b else a; | 1672 | const r2 = if (t) b else a; |
| 1640 | 1673 | ||
| ... | @@ -1651,10 +1684,12 @@ test "peer type resolution: array with sentinel and array without sentinel" { | ... | @@ -1651,10 +1684,12 @@ test "peer type resolution: array with sentinel and array without sentinel" { |
| 1651 | 1684 | ||
| 1652 | var a: [2:0]u32 = .{ 0, 1 }; | 1685 | var a: [2:0]u32 = .{ 0, 1 }; |
| 1653 | var b: [2]u32 = .{ 2, 3 }; | 1686 | var b: [2]u32 = .{ 2, 3 }; |
| 1687 | _ = .{ &a, &b }; | ||
| 1654 | comptime assert(@TypeOf(a, b) == [2]u32); | 1688 | comptime assert(@TypeOf(a, b) == [2]u32); |
| 1655 | comptime assert(@TypeOf(b, a) == [2]u32); | 1689 | comptime assert(@TypeOf(b, a) == [2]u32); |
| 1656 | 1690 | ||
| 1657 | var t = true; | 1691 | var t = true; |
| 1692 | _ = &t; | ||
| 1658 | const r1 = if (t) a else b; | 1693 | const r1 = if (t) a else b; |
| 1659 | const r2 = if (t) b else a; | 1694 | const r2 = if (t) b else a; |
| 1660 | 1695 | ||
| ... | @@ -1671,10 +1706,12 @@ test "peer type resolution: array and vector with same child type" { | ... | @@ -1671,10 +1706,12 @@ test "peer type resolution: array and vector with same child type" { |
| 1671 | 1706 | ||
| 1672 | var arr: [2]u32 = .{ 0, 1 }; | 1707 | var arr: [2]u32 = .{ 0, 1 }; |
| 1673 | var vec: @Vector(2, u32) = .{ 2, 3 }; | 1708 | var vec: @Vector(2, u32) = .{ 2, 3 }; |
| 1709 | _ = .{ &arr, &vec }; | ||
| 1674 | comptime assert(@TypeOf(arr, vec) == @Vector(2, u32)); | 1710 | comptime assert(@TypeOf(arr, vec) == @Vector(2, u32)); |
| 1675 | comptime assert(@TypeOf(vec, arr) == @Vector(2, u32)); | 1711 | comptime assert(@TypeOf(vec, arr) == @Vector(2, u32)); |
| 1676 | 1712 | ||
| 1677 | var t = true; | 1713 | var t = true; |
| 1714 | _ = &t; | ||
| 1678 | const r1 = if (t) arr else vec; | 1715 | const r1 = if (t) arr else vec; |
| 1679 | const r2 = if (t) vec else arr; | 1716 | const r2 = if (t) vec else arr; |
| 1680 | 1717 | ||
| ... | @@ -1694,10 +1731,12 @@ test "peer type resolution: array with smaller child type and vector with larger | ... | @@ -1694,10 +1731,12 @@ test "peer type resolution: array with smaller child type and vector with larger |
| 1694 | 1731 | ||
| 1695 | var arr: [2]u8 = .{ 0, 1 }; | 1732 | var arr: [2]u8 = .{ 0, 1 }; |
| 1696 | var vec: @Vector(2, u64) = .{ 2, 3 }; | 1733 | var vec: @Vector(2, u64) = .{ 2, 3 }; |
| 1734 | _ = .{ &arr, &vec }; | ||
| 1697 | comptime assert(@TypeOf(arr, vec) == @Vector(2, u64)); | 1735 | comptime assert(@TypeOf(arr, vec) == @Vector(2, u64)); |
| 1698 | comptime assert(@TypeOf(vec, arr) == @Vector(2, u64)); | 1736 | comptime assert(@TypeOf(vec, arr) == @Vector(2, u64)); |
| 1699 | 1737 | ||
| 1700 | var t = true; | 1738 | var t = true; |
| 1739 | _ = &t; | ||
| 1701 | const r1 = if (t) arr else vec; | 1740 | const r1 = if (t) arr else vec; |
| 1702 | const r2 = if (t) vec else arr; | 1741 | const r2 = if (t) vec else arr; |
| 1703 | 1742 | ||
| ... | @@ -1715,10 +1754,12 @@ test "peer type resolution: error union and optional of same type" { | ... | @@ -1715,10 +1754,12 @@ test "peer type resolution: error union and optional of same type" { |
| 1715 | const E = error{Foo}; | 1754 | const E = error{Foo}; |
| 1716 | var a: E!*u8 = error.Foo; | 1755 | var a: E!*u8 = error.Foo; |
| 1717 | var b: ?*u8 = null; | 1756 | var b: ?*u8 = null; |
| 1757 | _ = .{ &a, &b }; | ||
| 1718 | comptime assert(@TypeOf(a, b) == E!?*u8); | 1758 | comptime assert(@TypeOf(a, b) == E!?*u8); |
| 1719 | comptime assert(@TypeOf(b, a) == E!?*u8); | 1759 | comptime assert(@TypeOf(b, a) == E!?*u8); |
| 1720 | 1760 | ||
| 1721 | var t = true; | 1761 | var t = true; |
| 1762 | _ = &t; | ||
| 1722 | const r1 = if (t) a else b; | 1763 | const r1 = if (t) a else b; |
| 1723 | const r2 = if (t) b else a; | 1764 | const r2 = if (t) b else a; |
| 1724 | 1765 | ||
| ... | @@ -1734,11 +1775,13 @@ test "peer type resolution: C pointer and @TypeOf(null)" { | ... | @@ -1734,11 +1775,13 @@ test "peer type resolution: C pointer and @TypeOf(null)" { |
| 1734 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1775 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1735 | 1776 | ||
| 1736 | var a: [*c]c_int = 0x1000; | 1777 | var a: [*c]c_int = 0x1000; |
| 1778 | _ = &a; | ||
| 1737 | const b = null; | 1779 | const b = null; |
| 1738 | comptime assert(@TypeOf(a, b) == [*c]c_int); | 1780 | comptime assert(@TypeOf(a, b) == [*c]c_int); |
| 1739 | comptime assert(@TypeOf(b, a) == [*c]c_int); | 1781 | comptime assert(@TypeOf(b, a) == [*c]c_int); |
| 1740 | 1782 | ||
| 1741 | var t = true; | 1783 | var t = true; |
| 1784 | _ = &t; | ||
| 1742 | const r1 = if (t) a else b; | 1785 | const r1 = if (t) a else b; |
| 1743 | const r2 = if (t) b else a; | 1786 | const r2 = if (t) b else a; |
| 1744 | 1787 | ||
| ... | @@ -1755,8 +1798,9 @@ test "peer type resolution: three-way resolution combines error set and optional | ... | @@ -1755,8 +1798,9 @@ test "peer type resolution: three-way resolution combines error set and optional |
| 1755 | 1798 | ||
| 1756 | const E = error{Foo}; | 1799 | const E = error{Foo}; |
| 1757 | var a: E = error.Foo; | 1800 | var a: E = error.Foo; |
| 1758 | var b: *const [5:0]u8 = @as(*const [5:0]u8, @ptrFromInt(0x1000)); | 1801 | var b: *const [5:0]u8 = @ptrFromInt(0x1000); |
| 1759 | var c: ?[*:0]u8 = null; | 1802 | var c: ?[*:0]u8 = null; |
| 1803 | _ = .{ &a, &b, &c }; | ||
| 1760 | comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8); | 1804 | comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8); |
| 1761 | comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8); | 1805 | comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8); |
| 1762 | comptime assert(@TypeOf(b, a, c) == E!?[*:0]const u8); | 1806 | comptime assert(@TypeOf(b, a, c) == E!?[*:0]const u8); |
| ... | @@ -1765,6 +1809,7 @@ test "peer type resolution: three-way resolution combines error set and optional | ... | @@ -1765,6 +1809,7 @@ test "peer type resolution: three-way resolution combines error set and optional |
| 1765 | comptime assert(@TypeOf(c, b, a) == E!?[*:0]const u8); | 1809 | comptime assert(@TypeOf(c, b, a) == E!?[*:0]const u8); |
| 1766 | 1810 | ||
| 1767 | var x: u8 = 0; | 1811 | var x: u8 = 0; |
| 1812 | _ = &x; | ||
| 1768 | const r1 = switch (x) { | 1813 | const r1 = switch (x) { |
| 1769 | 0 => a, | 1814 | 0 => a, |
| 1770 | 1 => b, | 1815 | 1 => b, |
| ... | @@ -1797,10 +1842,12 @@ test "peer type resolution: vector and optional vector" { | ... | @@ -1797,10 +1842,12 @@ test "peer type resolution: vector and optional vector" { |
| 1797 | 1842 | ||
| 1798 | var a: ?@Vector(3, u32) = .{ 0, 1, 2 }; | 1843 | var a: ?@Vector(3, u32) = .{ 0, 1, 2 }; |
| 1799 | var b: @Vector(3, u32) = .{ 3, 4, 5 }; | 1844 | var b: @Vector(3, u32) = .{ 3, 4, 5 }; |
| 1845 | _ = .{ &a, &b }; | ||
| 1800 | comptime assert(@TypeOf(a, b) == ?@Vector(3, u32)); | 1846 | comptime assert(@TypeOf(a, b) == ?@Vector(3, u32)); |
| 1801 | comptime assert(@TypeOf(b, a) == ?@Vector(3, u32)); | 1847 | comptime assert(@TypeOf(b, a) == ?@Vector(3, u32)); |
| 1802 | 1848 | ||
| 1803 | var t = true; | 1849 | var t = true; |
| 1850 | _ = &t; | ||
| 1804 | const r1 = if (t) a else b; | 1851 | const r1 = if (t) a else b; |
| 1805 | const r2 = if (t) b else a; | 1852 | const r2 = if (t) b else a; |
| 1806 | 1853 | ||
| ... | @@ -1816,11 +1863,13 @@ test "peer type resolution: optional fixed-width int and comptime_int" { | ... | @@ -1816,11 +1863,13 @@ test "peer type resolution: optional fixed-width int and comptime_int" { |
| 1816 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1863 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1817 | 1864 | ||
| 1818 | var a: ?i32 = 42; | 1865 | var a: ?i32 = 42; |
| 1866 | _ = &a; | ||
| 1819 | const b: comptime_int = 50; | 1867 | const b: comptime_int = 50; |
| 1820 | comptime assert(@TypeOf(a, b) == ?i32); | 1868 | comptime assert(@TypeOf(a, b) == ?i32); |
| 1821 | comptime assert(@TypeOf(b, a) == ?i32); | 1869 | comptime assert(@TypeOf(b, a) == ?i32); |
| 1822 | 1870 | ||
| 1823 | var t = true; | 1871 | var t = true; |
| 1872 | _ = &t; | ||
| 1824 | const r1 = if (t) a else b; | 1873 | const r1 = if (t) a else b; |
| 1825 | const r2 = if (t) b else a; | 1874 | const r2 = if (t) b else a; |
| 1826 | 1875 | ||
| ... | @@ -1836,12 +1885,14 @@ test "peer type resolution: array and tuple" { | ... | @@ -1836,12 +1885,14 @@ test "peer type resolution: array and tuple" { |
| 1836 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1885 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1837 | 1886 | ||
| 1838 | var arr: [3]i32 = .{ 1, 2, 3 }; | 1887 | var arr: [3]i32 = .{ 1, 2, 3 }; |
| 1888 | _ = &arr; | ||
| 1839 | const tup = .{ 4, 5, 6 }; | 1889 | const tup = .{ 4, 5, 6 }; |
| 1840 | 1890 | ||
| 1841 | comptime assert(@TypeOf(arr, tup) == [3]i32); | 1891 | comptime assert(@TypeOf(arr, tup) == [3]i32); |
| 1842 | comptime assert(@TypeOf(tup, arr) == [3]i32); | 1892 | comptime assert(@TypeOf(tup, arr) == [3]i32); |
| 1843 | 1893 | ||
| 1844 | var t = true; | 1894 | var t = true; |
| 1895 | _ = &t; | ||
| 1845 | const r1 = if (t) arr else tup; | 1896 | const r1 = if (t) arr else tup; |
| 1846 | const r2 = if (t) tup else arr; | 1897 | const r2 = if (t) tup else arr; |
| 1847 | 1898 | ||
| ... | @@ -1858,12 +1909,14 @@ test "peer type resolution: vector and tuple" { | ... | @@ -1858,12 +1909,14 @@ test "peer type resolution: vector and tuple" { |
| 1858 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1909 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1859 | 1910 | ||
| 1860 | var vec: @Vector(3, i32) = .{ 1, 2, 3 }; | 1911 | var vec: @Vector(3, i32) = .{ 1, 2, 3 }; |
| 1912 | _ = &vec; | ||
| 1861 | const tup = .{ 4, 5, 6 }; | 1913 | const tup = .{ 4, 5, 6 }; |
| 1862 | 1914 | ||
| 1863 | comptime assert(@TypeOf(vec, tup) == @Vector(3, i32)); | 1915 | comptime assert(@TypeOf(vec, tup) == @Vector(3, i32)); |
| 1864 | comptime assert(@TypeOf(tup, vec) == @Vector(3, i32)); | 1916 | comptime assert(@TypeOf(tup, vec) == @Vector(3, i32)); |
| 1865 | 1917 | ||
| 1866 | var t = true; | 1918 | var t = true; |
| 1919 | _ = &t; | ||
| 1867 | const r1 = if (t) vec else tup; | 1920 | const r1 = if (t) vec else tup; |
| 1868 | const r2 = if (t) tup else vec; | 1921 | const r2 = if (t) tup else vec; |
| 1869 | 1922 | ||
| ... | @@ -1881,6 +1934,7 @@ test "peer type resolution: vector and array and tuple" { | ... | @@ -1881,6 +1934,7 @@ test "peer type resolution: vector and array and tuple" { |
| 1881 | 1934 | ||
| 1882 | var vec: @Vector(2, i8) = .{ 10, 20 }; | 1935 | var vec: @Vector(2, i8) = .{ 10, 20 }; |
| 1883 | var arr: [2]i8 = .{ 30, 40 }; | 1936 | var arr: [2]i8 = .{ 30, 40 }; |
| 1937 | _ = .{ &vec, &arr }; | ||
| 1884 | const tup = .{ 50, 60 }; | 1938 | const tup = .{ 50, 60 }; |
| 1885 | 1939 | ||
| 1886 | comptime assert(@TypeOf(vec, arr, tup) == @Vector(2, i8)); | 1940 | comptime assert(@TypeOf(vec, arr, tup) == @Vector(2, i8)); |
| ... | @@ -1891,6 +1945,7 @@ test "peer type resolution: vector and array and tuple" { | ... | @@ -1891,6 +1945,7 @@ test "peer type resolution: vector and array and tuple" { |
| 1891 | comptime assert(@TypeOf(tup, arr, vec) == @Vector(2, i8)); | 1945 | comptime assert(@TypeOf(tup, arr, vec) == @Vector(2, i8)); |
| 1892 | 1946 | ||
| 1893 | var x: u8 = 0; | 1947 | var x: u8 = 0; |
| 1948 | _ = &x; | ||
| 1894 | const r1 = switch (x) { | 1949 | const r1 = switch (x) { |
| 1895 | 0 => vec, | 1950 | 0 => vec, |
| 1896 | 1 => arr, | 1951 | 1 => arr, |
| ... | @@ -1921,11 +1976,13 @@ test "peer type resolution: empty tuple pointer and slice" { | ... | @@ -1921,11 +1976,13 @@ test "peer type resolution: empty tuple pointer and slice" { |
| 1921 | 1976 | ||
| 1922 | var a: [:0]const u8 = "Hello"; | 1977 | var a: [:0]const u8 = "Hello"; |
| 1923 | var b = &.{}; | 1978 | var b = &.{}; |
| 1979 | _ = .{ &a, &b }; | ||
| 1924 | 1980 | ||
| 1925 | comptime assert(@TypeOf(a, b) == []const u8); | 1981 | comptime assert(@TypeOf(a, b) == []const u8); |
| 1926 | comptime assert(@TypeOf(b, a) == []const u8); | 1982 | comptime assert(@TypeOf(b, a) == []const u8); |
| 1927 | 1983 | ||
| 1928 | var t = true; | 1984 | var t = true; |
| 1985 | _ = &t; | ||
| 1929 | const r1 = if (t) a else b; | 1986 | const r1 = if (t) a else b; |
| 1930 | const r2 = if (t) b else a; | 1987 | const r2 = if (t) b else a; |
| 1931 | 1988 | ||
| ... | @@ -1940,11 +1997,13 @@ test "peer type resolution: tuple pointer and slice" { | ... | @@ -1940,11 +1997,13 @@ test "peer type resolution: tuple pointer and slice" { |
| 1940 | 1997 | ||
| 1941 | var a: [:0]const u8 = "Hello"; | 1998 | var a: [:0]const u8 = "Hello"; |
| 1942 | var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; | 1999 | var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; |
| 2000 | _ = .{ &a, &b }; | ||
| 1943 | 2001 | ||
| 1944 | comptime assert(@TypeOf(a, b) == []const u8); | 2002 | comptime assert(@TypeOf(a, b) == []const u8); |
| 1945 | comptime assert(@TypeOf(b, a) == []const u8); | 2003 | comptime assert(@TypeOf(b, a) == []const u8); |
| 1946 | 2004 | ||
| 1947 | var t = true; | 2005 | var t = true; |
| 2006 | _ = &t; | ||
| 1948 | const r1 = if (t) a else b; | 2007 | const r1 = if (t) a else b; |
| 1949 | const r2 = if (t) b else a; | 2008 | const r2 = if (t) b else a; |
| 1950 | 2009 | ||
| ... | @@ -1959,11 +2018,13 @@ test "peer type resolution: tuple pointer and optional slice" { | ... | @@ -1959,11 +2018,13 @@ test "peer type resolution: tuple pointer and optional slice" { |
| 1959 | 2018 | ||
| 1960 | var a: ?[:0]const u8 = null; | 2019 | var a: ?[:0]const u8 = null; |
| 1961 | var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; | 2020 | var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; |
| 2021 | _ = .{ &a, &b }; | ||
| 1962 | 2022 | ||
| 1963 | comptime assert(@TypeOf(a, b) == ?[]const u8); | 2023 | comptime assert(@TypeOf(a, b) == ?[]const u8); |
| 1964 | comptime assert(@TypeOf(b, a) == ?[]const u8); | 2024 | comptime assert(@TypeOf(b, a) == ?[]const u8); |
| 1965 | 2025 | ||
| 1966 | var t = true; | 2026 | var t = true; |
| 2027 | _ = &t; | ||
| 1967 | const r1 = if (t) a else b; | 2028 | const r1 = if (t) a else b; |
| 1968 | const r2 = if (t) b else a; | 2029 | const r2 = if (t) b else a; |
| 1969 | 2030 | ||
| ... | @@ -1986,6 +2047,7 @@ test "peer type resolution: many compatible pointers" { | ... | @@ -1986,6 +2047,7 @@ test "peer type resolution: many compatible pointers" { |
| 1986 | @as([*]u8, &buf), | 2047 | @as([*]u8, &buf), |
| 1987 | @as(*const [5]u8, "foo-4"), | 2048 | @as(*const [5]u8, "foo-4"), |
| 1988 | }; | 2049 | }; |
| 2050 | _ = &vals; | ||
| 1989 | 2051 | ||
| 1990 | // Check every possible permutation of types in @TypeOf | 2052 | // Check every possible permutation of types in @TypeOf |
| 1991 | @setEvalBranchQuota(5000); | 2053 | @setEvalBranchQuota(5000); |
| ... | @@ -2015,6 +2077,7 @@ test "peer type resolution: many compatible pointers" { | ... | @@ -2015,6 +2077,7 @@ test "peer type resolution: many compatible pointers" { |
| 2015 | comptime assert(perms == 5 * 4 * 3 * 2 * 1); | 2077 | comptime assert(perms == 5 * 4 * 3 * 2 * 1); |
| 2016 | 2078 | ||
| 2017 | var x: u8 = 0; | 2079 | var x: u8 = 0; |
| 2080 | _ = &x; | ||
| 2018 | inline for (0..5) |i| { | 2081 | inline for (0..5) |i| { |
| 2019 | const r = switch (x) { | 2082 | const r = switch (x) { |
| 2020 | 0 => vals[i], | 2083 | 0 => vals[i], |
| ... | @@ -2057,6 +2120,7 @@ test "peer type resolution: tuples with comptime fields" { | ... | @@ -2057,6 +2120,7 @@ test "peer type resolution: tuples with comptime fields" { |
| 2057 | } | 2120 | } |
| 2058 | 2121 | ||
| 2059 | var t = true; | 2122 | var t = true; |
| 2123 | _ = &t; | ||
| 2060 | const r1 = if (t) a else b; | 2124 | const r1 = if (t) a else b; |
| 2061 | const r2 = if (t) b else a; | 2125 | const r2 = if (t) b else a; |
| 2062 | 2126 | ||
| ... | @@ -2074,13 +2138,15 @@ test "peer type resolution: C pointer and many pointer" { | ... | @@ -2074,13 +2138,15 @@ test "peer type resolution: C pointer and many pointer" { |
| 2074 | 2138 | ||
| 2075 | var buf = "hello".*; | 2139 | var buf = "hello".*; |
| 2076 | 2140 | ||
| 2077 | var a: [*c]u8 = &buf; | 2141 | const a: [*c]u8 = &buf; |
| 2078 | var b: [*:0]const u8 = "world"; | 2142 | var b: [*:0]const u8 = "world"; |
| 2143 | _ = &b; | ||
| 2079 | 2144 | ||
| 2080 | comptime assert(@TypeOf(a, b) == [*c]const u8); | 2145 | comptime assert(@TypeOf(a, b) == [*c]const u8); |
| 2081 | comptime assert(@TypeOf(b, a) == [*c]const u8); | 2146 | comptime assert(@TypeOf(b, a) == [*c]const u8); |
| 2082 | 2147 | ||
| 2083 | var t = true; | 2148 | var t = true; |
| 2149 | _ = &t; | ||
| 2084 | const r1 = if (t) a else b; | 2150 | const r1 = if (t) a else b; |
| 2085 | const r2 = if (t) b else a; | 2151 | const r2 = if (t) b else a; |
| 2086 | 2152 | ||
| ... | @@ -2097,9 +2163,9 @@ test "peer type resolution: pointer attributes are combined correctly" { | ... | @@ -2097,9 +2163,9 @@ test "peer type resolution: pointer attributes are combined correctly" { |
| 2097 | var buf_b align(4) = "bar".*; | 2163 | var buf_b align(4) = "bar".*; |
| 2098 | var buf_c align(4) = "baz".*; | 2164 | var buf_c align(4) = "baz".*; |
| 2099 | 2165 | ||
| 2100 | var a: [*:0]align(4) const u8 = &buf_a; | 2166 | const a: [*:0]align(4) const u8 = &buf_a; |
| 2101 | var b: *align(2) volatile [3:0]u8 = &buf_b; | 2167 | const b: *align(2) volatile [3:0]u8 = &buf_b; |
| 2102 | var c: [*:0]align(4) u8 = &buf_c; | 2168 | const c: [*:0]align(4) u8 = &buf_c; |
| 2103 | 2169 | ||
| 2104 | comptime assert(@TypeOf(a, b, c) == [*:0]align(2) const volatile u8); | 2170 | comptime assert(@TypeOf(a, b, c) == [*:0]align(2) const volatile u8); |
| 2105 | comptime assert(@TypeOf(a, c, b) == [*:0]align(2) const volatile u8); | 2171 | comptime assert(@TypeOf(a, c, b) == [*:0]align(2) const volatile u8); |
| ... | @@ -2109,6 +2175,7 @@ test "peer type resolution: pointer attributes are combined correctly" { | ... | @@ -2109,6 +2175,7 @@ test "peer type resolution: pointer attributes are combined correctly" { |
| 2109 | comptime assert(@TypeOf(c, b, a) == [*:0]align(2) const volatile u8); | 2175 | comptime assert(@TypeOf(c, b, a) == [*:0]align(2) const volatile u8); |
| 2110 | 2176 | ||
| 2111 | var x: u8 = 0; | 2177 | var x: u8 = 0; |
| 2178 | _ = &x; | ||
| 2112 | const r1 = switch (x) { | 2179 | const r1 = switch (x) { |
| 2113 | 0 => a, | 2180 | 0 => a, |
| 2114 | 1 => b, | 2181 | 1 => b, |
| ... | @@ -2254,6 +2321,7 @@ test "@floatCast on vector" { | ... | @@ -2254,6 +2321,7 @@ test "@floatCast on vector" { |
| 2254 | const S = struct { | 2321 | const S = struct { |
| 2255 | fn doTheTest() !void { | 2322 | fn doTheTest() !void { |
| 2256 | var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 }; | 2323 | var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 }; |
| 2324 | _ = &a; | ||
| 2257 | const b: @Vector(3, f32) = @floatCast(a); | 2325 | const b: @Vector(3, f32) = @floatCast(a); |
| 2258 | try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b); | 2326 | try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b); |
| 2259 | } | 2327 | } |
| ... | @@ -2274,6 +2342,7 @@ test "@ptrFromInt on vector" { | ... | @@ -2274,6 +2342,7 @@ test "@ptrFromInt on vector" { |
| 2274 | const S = struct { | 2342 | const S = struct { |
| 2275 | fn doTheTest() !void { | 2343 | fn doTheTest() !void { |
| 2276 | var a: @Vector(3, usize) = .{ 0x1000, 0x2000, 0x3000 }; | 2344 | var a: @Vector(3, usize) = .{ 0x1000, 0x2000, 0x3000 }; |
| 2345 | _ = &a; | ||
| 2277 | const b: @Vector(3, *anyopaque) = @ptrFromInt(a); | 2346 | const b: @Vector(3, *anyopaque) = @ptrFromInt(a); |
| 2278 | try expectEqual(@Vector(3, *anyopaque){ | 2347 | try expectEqual(@Vector(3, *anyopaque){ |
| 2279 | @ptrFromInt(0x1000), | 2348 | @ptrFromInt(0x1000), |
| ... | @@ -2302,6 +2371,7 @@ test "@intFromPtr on vector" { | ... | @@ -2302,6 +2371,7 @@ test "@intFromPtr on vector" { |
| 2302 | @ptrFromInt(0x2000), | 2371 | @ptrFromInt(0x2000), |
| 2303 | @ptrFromInt(0x3000), | 2372 | @ptrFromInt(0x3000), |
| 2304 | }; | 2373 | }; |
| 2374 | _ = &a; | ||
| 2305 | const b: @Vector(3, usize) = @intFromPtr(a); | 2375 | const b: @Vector(3, usize) = @intFromPtr(a); |
| 2306 | try expectEqual(@Vector(3, usize){ 0x1000, 0x2000, 0x3000 }, b); | 2376 | try expectEqual(@Vector(3, usize){ 0x1000, 0x2000, 0x3000 }, b); |
| 2307 | } | 2377 | } |
| ... | @@ -2322,6 +2392,7 @@ test "@floatFromInt on vector" { | ... | @@ -2322,6 +2392,7 @@ test "@floatFromInt on vector" { |
| 2322 | const S = struct { | 2392 | const S = struct { |
| 2323 | fn doTheTest() !void { | 2393 | fn doTheTest() !void { |
| 2324 | var a: @Vector(3, u32) = .{ 10, 20, 30 }; | 2394 | var a: @Vector(3, u32) = .{ 10, 20, 30 }; |
| 2395 | _ = &a; | ||
| 2325 | const b: @Vector(3, f32) = @floatFromInt(a); | 2396 | const b: @Vector(3, f32) = @floatFromInt(a); |
| 2326 | try expectEqual(@Vector(3, f32){ 10.0, 20.0, 30.0 }, b); | 2397 | try expectEqual(@Vector(3, f32){ 10.0, 20.0, 30.0 }, b); |
| 2327 | } | 2398 | } |
| ... | @@ -2342,6 +2413,7 @@ test "@intFromFloat on vector" { | ... | @@ -2342,6 +2413,7 @@ test "@intFromFloat on vector" { |
| 2342 | const S = struct { | 2413 | const S = struct { |
| 2343 | fn doTheTest() !void { | 2414 | fn doTheTest() !void { |
| 2344 | var a: @Vector(3, f32) = .{ 10.3, 20.5, 30.7 }; | 2415 | var a: @Vector(3, f32) = .{ 10.3, 20.5, 30.7 }; |
| 2416 | _ = &a; | ||
| 2345 | const b: @Vector(3, u32) = @intFromFloat(a); | 2417 | const b: @Vector(3, u32) = @intFromFloat(a); |
| 2346 | try expectEqual(@Vector(3, u32){ 10, 20, 30 }, b); | 2418 | try expectEqual(@Vector(3, u32){ 10, 20, 30 }, b); |
| 2347 | } | 2419 | } |
| ... | @@ -2362,6 +2434,7 @@ test "@intFromBool on vector" { | ... | @@ -2362,6 +2434,7 @@ test "@intFromBool on vector" { |
| 2362 | const S = struct { | 2434 | const S = struct { |
| 2363 | fn doTheTest() !void { | 2435 | fn doTheTest() !void { |
| 2364 | var a: @Vector(3, bool) = .{ false, true, false }; | 2436 | var a: @Vector(3, bool) = .{ false, true, false }; |
| 2437 | _ = &a; | ||
| 2365 | const b: @Vector(3, u1) = @intFromBool(a); | 2438 | const b: @Vector(3, u1) = @intFromBool(a); |
| 2366 | try expectEqual(@Vector(3, u1){ 0, 1, 0 }, b); | 2439 | try expectEqual(@Vector(3, u1){ 0, 1, 0 }, b); |
| 2367 | } | 2440 | } |
| ... | @@ -2385,7 +2458,8 @@ test "15-bit int to float" { | ... | @@ -2385,7 +2458,8 @@ test "15-bit int to float" { |
| 2385 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | 2458 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 2386 | 2459 | ||
| 2387 | var a: u15 = 42; | 2460 | var a: u15 = 42; |
| 2388 | var b: f32 = @floatFromInt(a); | 2461 | _ = &a; |
| 2462 | const b: f32 = @floatFromInt(a); | ||
| 2389 | try expect(b == 42.0); | 2463 | try expect(b == 42.0); |
| 2390 | } | 2464 | } |
| 2391 | 2465 | ||
| ... | @@ -2417,6 +2491,7 @@ test "result information is preserved through many nested structures" { | ... | @@ -2417,6 +2491,7 @@ test "result information is preserved through many nested structures" { |
| 2417 | const T = *const ?E!struct { x: ?*const E!?u8 }; | 2491 | const T = *const ?E!struct { x: ?*const E!?u8 }; |
| 2418 | 2492 | ||
| 2419 | var val: T = &.{ .x = &@truncate(0x1234) }; | 2493 | var val: T = &.{ .x = &@truncate(0x1234) }; |
| 2494 | _ = &val; | ||
| 2420 | 2495 | ||
| 2421 | const struct_val = val.*.? catch unreachable; | 2496 | const struct_val = val.*.? catch unreachable; |
| 2422 | const int_val = (struct_val.x.?.* catch unreachable).?; | 2497 | const int_val = (struct_val.x.?.* catch unreachable).?; |
| ... | @@ -2439,6 +2514,7 @@ test "@intCast vector of signed integer" { | ... | @@ -2439,6 +2514,7 @@ test "@intCast vector of signed integer" { |
| 2439 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 2514 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 2440 | 2515 | ||
| 2441 | var x: @Vector(4, i32) = .{ 1, 2, 3, 4 }; | 2516 | var x: @Vector(4, i32) = .{ 1, 2, 3, 4 }; |
| 2517 | _ = &x; | ||
| 2442 | const y: @Vector(4, i8) = @intCast(x); | 2518 | const y: @Vector(4, i8) = @intCast(x); |
| 2443 | 2519 | ||
| 2444 | try expect(y[0] == 1); | 2520 | try expect(y[0] == 1); |
| ... | @@ -2446,3 +2522,8 @@ test "@intCast vector of signed integer" { | ... | @@ -2446,3 +2522,8 @@ test "@intCast vector of signed integer" { |
| 2446 | try expect(y[2] == 3); | 2522 | try expect(y[2] == 3); |
| 2447 | try expect(y[3] == 4); | 2523 | try expect(y[3] == 4); |
| 2448 | } | 2524 | } |
| 2525 | |||
| 2526 | test "result type is preserved into comptime block" { | ||
| 2527 | const x: u32 = comptime @intCast(123); | ||
| 2528 | try expect(x == 123); | ||
| 2529 | } |
test/behavior/cast_int.zig+17-2| ... | @@ -12,7 +12,8 @@ test "@intCast i32 to u7" { | ... | @@ -12,7 +12,8 @@ test "@intCast i32 to u7" { |
| 12 | 12 | ||
| 13 | var x: u128 = maxInt(u128); | 13 | var x: u128 = maxInt(u128); |
| 14 | var y: i32 = 120; | 14 | var y: i32 = 120; |
| 15 | var z = x >> @as(u7, @intCast(y)); | 15 | _ = .{ &x, &y }; |
| 16 | const z = x >> @as(u7, @intCast(y)); | ||
| 16 | try expect(z == 0xff); | 17 | try expect(z == 0xff); |
| 17 | } | 18 | } |
| 18 | 19 | ||
| ... | @@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" { | ... | @@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" { |
| 23 | 24 | ||
| 24 | var x: i8 = -5; | 25 | var x: i8 = -5; |
| 25 | var y: i32 = -5; | 26 | var y: i32 = -5; |
| 27 | _ = .{ &x, &y }; | ||
| 26 | try expect(y == x); | 28 | try expect(y == x); |
| 27 | 29 | ||
| 28 | var x2: i32 = -5; | 30 | var x2: i32 = -5; |
| 29 | var y2: i8 = -5; | 31 | var y2: i8 = -5; |
| 32 | _ = .{ &x2, &y2 }; | ||
| 30 | try expect(y2 == @as(i8, @intCast(x2))); | 33 | try expect(y2 == @as(i8, @intCast(x2))); |
| 31 | } | 34 | } |
| 32 | 35 | ||
| 33 | test "coerce non byte-sized integers accross 32bits boundary" { | 36 | test "coerce non byte-sized integers accross 32bits boundary" { |
| 34 | { | 37 | { |
| 35 | var v: u21 = 6417; | 38 | var v: u21 = 6417; |
| 39 | _ = &v; | ||
| 36 | const a: u32 = v; | 40 | const a: u32 = v; |
| 37 | const b: u64 = v; | 41 | const b: u64 = v; |
| 38 | const c: u64 = a; | 42 | const c: u64 = a; |
| 39 | var w: u64 = 0x1234567812345678; | 43 | var w: u64 = 0x1234567812345678; |
| 44 | _ = &w; | ||
| 40 | const d: u21 = @truncate(w); | 45 | const d: u21 = @truncate(w); |
| 41 | const e: u60 = d; | 46 | const e: u60 = d; |
| 42 | try expectEqual(@as(u32, 6417), a); | 47 | try expectEqual(@as(u32, 6417), a); |
| ... | @@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { | ... | @@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 48 | 53 | ||
| 49 | { | 54 | { |
| 50 | var v: u10 = 234; | 55 | var v: u10 = 234; |
| 56 | _ = &v; | ||
| 51 | const a: u32 = v; | 57 | const a: u32 = v; |
| 52 | const b: u64 = v; | 58 | const b: u64 = v; |
| 53 | const c: u64 = a; | 59 | const c: u64 = a; |
| 54 | var w: u64 = 0x1234567812345678; | 60 | var w: u64 = 0x1234567812345678; |
| 61 | _ = &w; | ||
| 55 | const d: u10 = @truncate(w); | 62 | const d: u10 = @truncate(w); |
| 56 | const e: u60 = d; | 63 | const e: u60 = d; |
| 57 | try expectEqual(@as(u32, 234), a); | 64 | try expectEqual(@as(u32, 234), a); |
| ... | @@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { | ... | @@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 62 | } | 69 | } |
| 63 | { | 70 | { |
| 64 | var v: u7 = 11; | 71 | var v: u7 = 11; |
| 72 | _ = &v; | ||
| 65 | const a: u32 = v; | 73 | const a: u32 = v; |
| 66 | const b: u64 = v; | 74 | const b: u64 = v; |
| 67 | const c: u64 = a; | 75 | const c: u64 = a; |
| 68 | var w: u64 = 0x1234567812345678; | 76 | var w: u64 = 0x1234567812345678; |
| 77 | _ = &w; | ||
| 69 | const d: u7 = @truncate(w); | 78 | const d: u7 = @truncate(w); |
| 70 | const e: u60 = d; | 79 | const e: u60 = d; |
| 71 | try expectEqual(@as(u32, 11), a); | 80 | try expectEqual(@as(u32, 11), a); |
| ... | @@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { | ... | @@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 77 | 86 | ||
| 78 | { | 87 | { |
| 79 | var v: i21 = -6417; | 88 | var v: i21 = -6417; |
| 89 | _ = &v; | ||
| 80 | const a: i32 = v; | 90 | const a: i32 = v; |
| 81 | const b: i64 = v; | 91 | const b: i64 = v; |
| 82 | const c: i64 = a; | 92 | const c: i64 = a; |
| 83 | var w: i64 = -12345; | 93 | var w: i64 = -12345; |
| 94 | _ = &w; | ||
| 84 | const d: i21 = @intCast(w); | 95 | const d: i21 = @intCast(w); |
| 85 | const e: i60 = d; | 96 | const e: i60 = d; |
| 86 | try expectEqual(@as(i32, -6417), a); | 97 | try expectEqual(@as(i32, -6417), a); |
| ... | @@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { | ... | @@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 92 | 103 | ||
| 93 | { | 104 | { |
| 94 | var v: i10 = -234; | 105 | var v: i10 = -234; |
| 106 | _ = &v; | ||
| 95 | const a: i32 = v; | 107 | const a: i32 = v; |
| 96 | const b: i64 = v; | 108 | const b: i64 = v; |
| 97 | const c: i64 = a; | 109 | const c: i64 = a; |
| 98 | var w: i64 = -456; | 110 | var w: i64 = -456; |
| 111 | _ = &w; | ||
| 99 | const d: i10 = @intCast(w); | 112 | const d: i10 = @intCast(w); |
| 100 | const e: i60 = d; | 113 | const e: i60 = d; |
| 101 | try expectEqual(@as(i32, -234), a); | 114 | try expectEqual(@as(i32, -234), a); |
| ... | @@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { | ... | @@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { |
| 106 | } | 119 | } |
| 107 | { | 120 | { |
| 108 | var v: i7 = -11; | 121 | var v: i7 = -11; |
| 122 | _ = &v; | ||
| 109 | const a: i32 = v; | 123 | const a: i32 = v; |
| 110 | const b: i64 = v; | 124 | const b: i64 = v; |
| 111 | const c: i64 = a; | 125 | const c: i64 = a; |
| 112 | var w: i64 = -42; | 126 | var w: i64 = -42; |
| 127 | _ = &w; | ||
| 113 | const d: i7 = @intCast(w); | 128 | const d: i7 = @intCast(w); |
| 114 | const e: i60 = d; | 129 | const e: i60 = d; |
| 115 | try expectEqual(@as(i32, -11), a); | 130 | try expectEqual(@as(i32, -11), a); |
| ... | @@ -152,7 +167,7 @@ test "load non byte-sized optional value" { | ... | @@ -152,7 +167,7 @@ test "load non byte-sized optional value" { |
| 152 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 167 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 153 | 168 | ||
| 154 | // note: this bug is triggered by the == operator, expectEqual will hide it | 169 | // note: this bug is triggered by the == operator, expectEqual will hide it |
| 155 | var opt: ?Piece = try Piece.charToPiece('p'); | 170 | const opt: ?Piece = try Piece.charToPiece('p'); |
| 156 | try expect(opt.?.type == .PAWN); | 171 | try expect(opt.?.type == .PAWN); |
| 157 | try expect(opt.?.color == .BLACK); | 172 | try expect(opt.?.color == .BLACK); |
| 158 | 173 |
test/behavior/comptime_memory.zig+1-1| ... | @@ -280,7 +280,7 @@ test "dance on linker values" { | ... | @@ -280,7 +280,7 @@ test "dance on linker values" { |
| 280 | if (ptr_size > @sizeOf(Bits)) | 280 | if (ptr_size > @sizeOf(Bits)) |
| 281 | try doTypePunBitsTest(&weird_ptr[1]); | 281 | try doTypePunBitsTest(&weird_ptr[1]); |
| 282 | 282 | ||
| 283 | var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr)); | 283 | const arr_bytes: *[2][ptr_size]u8 = @ptrCast(&arr); |
| 284 | 284 | ||
| 285 | var rebuilt_bytes: [ptr_size]u8 = undefined; | 285 | var rebuilt_bytes: [ptr_size]u8 = undefined; |
| 286 | var i: usize = 0; | 286 | var i: usize = 0; |
test/behavior/destructure.zig+4| ... | @@ -7,6 +7,7 @@ test "simple destructure" { | ... | @@ -7,6 +7,7 @@ test "simple destructure" { |
| 7 | fn doTheTest() !void { | 7 | fn doTheTest() !void { |
| 8 | var x: u32 = undefined; | 8 | var x: u32 = undefined; |
| 9 | x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 }; | 9 | x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 }; |
| 10 | _ = &z; | ||
| 10 | 11 | ||
| 11 | comptime assert(@TypeOf(y) == u16); | 12 | comptime assert(@TypeOf(y) == u16); |
| 12 | 13 | ||
| ... | @@ -25,6 +26,7 @@ test "destructure with comptime syntax" { | ... | @@ -25,6 +26,7 @@ test "destructure with comptime syntax" { |
| 25 | fn doTheTest() void { | 26 | fn doTheTest() void { |
| 26 | comptime var x: f32 = undefined; | 27 | comptime var x: f32 = undefined; |
| 27 | comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var | 28 | comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var |
| 29 | _ = &z; | ||
| 28 | 30 | ||
| 29 | comptime assert(@TypeOf(y) == comptime_int); | 31 | comptime assert(@TypeOf(y) == comptime_int); |
| 30 | comptime assert(@TypeOf(z) == comptime_int); | 32 | comptime assert(@TypeOf(z) == comptime_int); |
| ... | @@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" { | ... | @@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" { |
| 112 | test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" { | 114 | test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" { |
| 113 | var z: u32 = undefined; | 115 | var z: u32 = undefined; |
| 114 | var x: u8, const y, z = .{ 1, 2, 3 }; | 116 | var x: u8, const y, z = .{ 1, 2, 3 }; |
| 117 | _ = &x; | ||
| 115 | 118 | ||
| 116 | comptime assert(@TypeOf(y) == comptime_int); | 119 | comptime assert(@TypeOf(y) == comptime_int); |
| 117 | comptime assert(y == 2); | 120 | comptime assert(y == 2); |
| ... | @@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn | ... | @@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn |
| 122 | 125 | ||
| 123 | test "destructure of tuple with comptime fields results in some comptime-known values" { | 126 | test "destructure of tuple with comptime fields results in some comptime-known values" { |
| 124 | var runtime: u32 = 42; | 127 | var runtime: u32 = 42; |
| 128 | _ = &runtime; | ||
| 125 | const a, const b, const c, const d = .{ 123, runtime, 456, runtime }; | 129 | const a, const b, const c, const d = .{ 123, runtime, 456, runtime }; |
| 126 | 130 | ||
| 127 | // a, c are comptime-known | 131 | // a, c are comptime-known |
test/behavior/empty_union.zig+4| ... | @@ -5,12 +5,14 @@ const expect = std.testing.expect; | ... | @@ -5,12 +5,14 @@ const expect = std.testing.expect; |
| 5 | test "switch on empty enum" { | 5 | test "switch on empty enum" { |
| 6 | const E = enum {}; | 6 | const E = enum {}; |
| 7 | var e: E = undefined; | 7 | var e: E = undefined; |
| 8 | _ = &e; | ||
| 8 | switch (e) {} | 9 | switch (e) {} |
| 9 | } | 10 | } |
| 10 | 11 | ||
| 11 | test "switch on empty enum with a specified tag type" { | 12 | test "switch on empty enum with a specified tag type" { |
| 12 | const E = enum(u8) {}; | 13 | const E = enum(u8) {}; |
| 13 | var e: E = undefined; | 14 | var e: E = undefined; |
| 15 | _ = &e; | ||
| 14 | switch (e) {} | 16 | switch (e) {} |
| 15 | } | 17 | } |
| 16 | 18 | ||
| ... | @@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" { | ... | @@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" { |
| 19 | 21 | ||
| 20 | const U = union(enum(u8)) {}; | 22 | const U = union(enum(u8)) {}; |
| 21 | var u: U = undefined; | 23 | var u: U = undefined; |
| 24 | _ = &u; | ||
| 22 | switch (u) {} | 25 | switch (u) {} |
| 23 | } | 26 | } |
| 24 | 27 | ||
| ... | @@ -28,6 +31,7 @@ test "switch on empty tagged union" { | ... | @@ -28,6 +31,7 @@ test "switch on empty tagged union" { |
| 28 | const E = enum {}; | 31 | const E = enum {}; |
| 29 | const U = union(E) {}; | 32 | const U = union(E) {}; |
| 30 | var u: U = undefined; | 33 | var u: U = undefined; |
| 34 | _ = &u; | ||
| 31 | switch (u) {} | 35 | switch (u) {} |
| 32 | } | 36 | } |
| 33 | 37 |
test/behavior/enum.zig+11-4| ... | @@ -579,6 +579,7 @@ test "enum literal cast to enum" { | ... | @@ -579,6 +579,7 @@ test "enum literal cast to enum" { |
| 579 | 579 | ||
| 580 | var color1: Color = .Auto; | 580 | var color1: Color = .Auto; |
| 581 | var color2 = Color.Auto; | 581 | var color2 = Color.Auto; |
| 582 | _ = .{ &color1, &color2 }; | ||
| 582 | try expect(color1 == color2); | 583 | try expect(color1 == color2); |
| 583 | } | 584 | } |
| 584 | 585 | ||
| ... | @@ -663,7 +664,8 @@ test "empty non-exhaustive enum" { | ... | @@ -663,7 +664,8 @@ test "empty non-exhaustive enum" { |
| 663 | const E = enum(u8) { _ }; | 664 | const E = enum(u8) { _ }; |
| 664 | 665 | ||
| 665 | fn doTheTest(y: u8) !void { | 666 | fn doTheTest(y: u8) !void { |
| 666 | var e = @as(E, @enumFromInt(y)); | 667 | var e: E = @enumFromInt(y); |
| 668 | _ = &e; | ||
| 667 | try expect(switch (e) { | 669 | try expect(switch (e) { |
| 668 | _ => true, | 670 | _ => true, |
| 669 | }); | 671 | }); |
| ... | @@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" { | ... | @@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" { |
| 858 | const State = enum { Start }; | 860 | const State = enum { Start }; |
| 859 | test "switch on enum with one member is comptime-known" { | 861 | test "switch on enum with one member is comptime-known" { |
| 860 | var state = State.Start; | 862 | var state = State.Start; |
| 863 | _ = &state; | ||
| 861 | switch (state) { | 864 | switch (state) { |
| 862 | State.Start => return, | 865 | State.Start => return, |
| 863 | } | 866 | } |
| ... | @@ -917,7 +920,8 @@ test "enum literal casting to tagged union" { | ... | @@ -917,7 +920,8 @@ test "enum literal casting to tagged union" { |
| 917 | 920 | ||
| 918 | var t = true; | 921 | var t = true; |
| 919 | var x: Arch = .x86_64; | 922 | var x: Arch = .x86_64; |
| 920 | var y = if (t) x else .x86_64; | 923 | _ = .{ &t, &x }; |
| 924 | const y = if (t) x else .x86_64; | ||
| 921 | switch (y) { | 925 | switch (y) { |
| 922 | .x86_64 => {}, | 926 | .x86_64 => {}, |
| 923 | else => @panic("fail"), | 927 | else => @panic("fail"), |
| ... | @@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" { | ... | @@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" { |
| 1031 | B = 0, | 1035 | B = 0, |
| 1032 | }; | 1036 | }; |
| 1033 | var b = LocalFoo.B; | 1037 | var b = LocalFoo.B; |
| 1038 | _ = &b; | ||
| 1034 | try expect(mem.eql(u8, @tagName(b), "B")); | 1039 | try expect(mem.eql(u8, @tagName(b), "B")); |
| 1035 | } | 1040 | } |
| 1036 | 1041 | ||
| ... | @@ -1055,6 +1060,7 @@ test "tag name with signed enum values" { | ... | @@ -1055,6 +1060,7 @@ test "tag name with signed enum values" { |
| 1055 | delta = 65, | 1060 | delta = 65, |
| 1056 | }; | 1061 | }; |
| 1057 | var b = LocalFoo.bravo; | 1062 | var b = LocalFoo.bravo; |
| 1063 | _ = &b; | ||
| 1058 | try expect(mem.eql(u8, @tagName(b), "bravo")); | 1064 | try expect(mem.eql(u8, @tagName(b), "bravo")); |
| 1059 | } | 1065 | } |
| 1060 | 1066 | ||
| ... | @@ -1135,13 +1141,13 @@ test "tag name functions are unique" { | ... | @@ -1135,13 +1141,13 @@ test "tag name functions are unique" { |
| 1135 | const E = enum { a, b }; | 1141 | const E = enum { a, b }; |
| 1136 | var b = E.a; | 1142 | var b = E.a; |
| 1137 | var a = @tagName(b); | 1143 | var a = @tagName(b); |
| 1138 | _ = a; | 1144 | _ = .{ &a, &b }; |
| 1139 | } | 1145 | } |
| 1140 | { | 1146 | { |
| 1141 | const E = enum { a, b, c, d, e, f }; | 1147 | const E = enum { a, b, c, d, e, f }; |
| 1142 | var b = E.a; | 1148 | var b = E.a; |
| 1143 | var a = @tagName(b); | 1149 | var a = @tagName(b); |
| 1144 | _ = a; | 1150 | _ = .{ &a, &b }; |
| 1145 | } | 1151 | } |
| 1146 | } | 1152 | } |
| 1147 | 1153 | ||
| ... | @@ -1189,6 +1195,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" { | ... | @@ -1189,6 +1195,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" { |
| 1189 | test "runtime int to enum with one possible value" { | 1195 | test "runtime int to enum with one possible value" { |
| 1190 | const E = enum { one }; | 1196 | const E = enum { one }; |
| 1191 | var runtime: usize = 0; | 1197 | var runtime: usize = 0; |
| 1198 | _ = &runtime; | ||
| 1192 | if (@as(E, @enumFromInt(runtime)) != .one) { | 1199 | if (@as(E, @enumFromInt(runtime)) != .one) { |
| 1193 | @compileError("test failed"); | 1200 | @compileError("test failed"); |
| 1194 | } | 1201 | } |
test/behavior/error.zig+14-8| ... | @@ -102,8 +102,7 @@ test "widen cast integer payload of error union function call" { | ... | @@ -102,8 +102,7 @@ test "widen cast integer payload of error union function call" { |
| 102 | 102 | ||
| 103 | const S = struct { | 103 | const S = struct { |
| 104 | fn errorable() !u64 { | 104 | fn errorable() !u64 { |
| 105 | var x = @as(u64, try number()); | 105 | return @as(u64, try number()); |
| 106 | return x; | ||
| 107 | } | 106 | } |
| 108 | 107 | ||
| 109 | fn number() anyerror!u32 { | 108 | fn number() anyerror!u32 { |
| ... | @@ -119,7 +118,7 @@ test "debug info for optional error set" { | ... | @@ -119,7 +118,7 @@ test "debug info for optional error set" { |
| 119 | 118 | ||
| 120 | const SomeError = error{ Hello, Hello2 }; | 119 | const SomeError = error{ Hello, Hello2 }; |
| 121 | var a_local_variable: ?SomeError = null; | 120 | var a_local_variable: ?SomeError = null; |
| 122 | _ = a_local_variable; | 121 | _ = &a_local_variable; |
| 123 | } | 122 | } |
| 124 | 123 | ||
| 125 | test "implicit cast to optional to error union to return result loc" { | 124 | test "implicit cast to optional to error union to return result loc" { |
| ... | @@ -160,6 +159,7 @@ fn entry() void { | ... | @@ -160,6 +159,7 @@ fn entry() void { |
| 160 | 159 | ||
| 161 | fn entryPtr() void { | 160 | fn entryPtr() void { |
| 162 | var ptr = &bar2; | 161 | var ptr = &bar2; |
| 162 | _ = &ptr; | ||
| 163 | fooPtr(ptr); | 163 | fooPtr(ptr); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| ... | @@ -226,9 +226,9 @@ const Set1 = error{ A, B }; | ... | @@ -226,9 +226,9 @@ const Set1 = error{ A, B }; |
| 226 | const Set2 = error{ A, C }; | 226 | const Set2 = error{ A, C }; |
| 227 | 227 | ||
| 228 | fn testExplicitErrorSetCast(set1: Set1) !void { | 228 | fn testExplicitErrorSetCast(set1: Set1) !void { |
| 229 | var x = @as(Set2, @errorCast(set1)); | 229 | const x: Set2 = @errorCast(set1); |
| 230 | try expect(@TypeOf(x) == Set2); | 230 | try expect(@TypeOf(x) == Set2); |
| 231 | var y = @as(Set1, @errorCast(x)); | 231 | const y: Set1 = @errorCast(x); |
| 232 | try expect(@TypeOf(y) == Set1); | 232 | try expect(@TypeOf(y) == Set1); |
| 233 | try expect(y == error.A); | 233 | try expect(y == error.A); |
| 234 | } | 234 | } |
| ... | @@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" { | ... | @@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" { |
| 408 | }; | 408 | }; |
| 409 | 409 | ||
| 410 | fn errorable() !i32 { | 410 | fn errorable() !i32 { |
| 411 | var x: Foo = (try getFoo()) orelse return error.Other; | 411 | const x: Foo = (try getFoo()) orelse return error.Other; |
| 412 | return x.a; | 412 | return x.a; |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | fn errorable2() !i32 { | 415 | fn errorable2() !i32 { |
| 416 | var x: Foo = (try getFoo2()) orelse return error.Other; | 416 | const x: Foo = (try getFoo2()) orelse return error.Other; |
| 417 | return x.a; | 417 | return x.a; |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | fn errorable3() !i32 { | 420 | fn errorable3() !i32 { |
| 421 | var x: Foo = (try getFoo3()) orelse return error.Other; | 421 | const x: Foo = (try getFoo3()) orelse return error.Other; |
| 422 | return x.a; | 422 | return x.a; |
| 423 | } | 423 | } |
| 424 | 424 | ||
| ... | @@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" { | ... | @@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" { |
| 673 | const a: error{B}!void = {}; | 673 | const a: error{B}!void = {}; |
| 674 | const b: error{A}!void = {}; | 674 | const b: error{A}!void = {}; |
| 675 | var cond = true; | 675 | var cond = true; |
| 676 | _ = &cond; | ||
| 676 | const err = if (cond) a else b; | 677 | const err = if (cond) a else b; |
| 677 | try err; | 678 | try err; |
| 678 | } | 679 | } |
| ... | @@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" { | ... | @@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" { |
| 681 | const S = struct { | 682 | const S = struct { |
| 682 | fn foo() !void { | 683 | fn foo() !void { |
| 683 | var a = false; | 684 | var a = false; |
| 685 | _ = &a; | ||
| 684 | if (a) { | 686 | if (a) { |
| 685 | const b: error{A}!void = error.A; | 687 | const b: error{A}!void = error.A; |
| 686 | return b; | 688 | return b; |
| ... | @@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" { | ... | @@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" { |
| 831 | 833 | ||
| 832 | fn foo() anyerror!I { | 834 | fn foo() anyerror!I { |
| 833 | var i: I = .{ .x = 1234 }; | 835 | var i: I = .{ .x = 1234 }; |
| 836 | _ = &i; | ||
| 834 | return i; | 837 | return i; |
| 835 | } | 838 | } |
| 836 | }; | 839 | }; |
| ... | @@ -842,6 +845,7 @@ test "compare error union and error set" { | ... | @@ -842,6 +845,7 @@ test "compare error union and error set" { |
| 842 | 845 | ||
| 843 | var a: anyerror = error.Foo; | 846 | var a: anyerror = error.Foo; |
| 844 | var b: anyerror!u32 = error.Bar; | 847 | var b: anyerror!u32 = error.Bar; |
| 848 | _ = &a; | ||
| 845 | 849 | ||
| 846 | try expect(a != b); | 850 | try expect(a != b); |
| 847 | try expect(b != a); | 851 | try expect(b != a); |
| ... | @@ -863,6 +867,7 @@ fn non_errorable() void { | ... | @@ -863,6 +867,7 @@ fn non_errorable() void { |
| 863 | // This test is needed because stage 2's fix for #1923 means that catch blocks interact | 867 | // This test is needed because stage 2's fix for #1923 means that catch blocks interact |
| 864 | // with the error return trace index. | 868 | // with the error return trace index. |
| 865 | var x: error{Foo}!void = {}; | 869 | var x: error{Foo}!void = {}; |
| 870 | _ = &x; | ||
| 866 | return x catch {}; | 871 | return x catch {}; |
| 867 | } | 872 | } |
| 868 | 873 | ||
| ... | @@ -902,6 +907,7 @@ test "optional error union return type" { | ... | @@ -902,6 +907,7 @@ test "optional error union return type" { |
| 902 | const S = struct { | 907 | const S = struct { |
| 903 | fn foo() ?anyerror!u32 { | 908 | fn foo() ?anyerror!u32 { |
| 904 | var x: u32 = 1234; | 909 | var x: u32 = 1234; |
| 910 | _ = &x; | ||
| 905 | return @as(anyerror!u32, x); | 911 | return @as(anyerror!u32, x); |
| 906 | } | 912 | } |
| 907 | }; | 913 | }; |
test/behavior/eval.zig+39-20| ... | @@ -37,6 +37,7 @@ fn gimme1or2(comptime a: bool) i32 { | ... | @@ -37,6 +37,7 @@ fn gimme1or2(comptime a: bool) i32 { |
| 37 | const x: i32 = 1; | 37 | const x: i32 = 1; |
| 38 | const y: i32 = 2; | 38 | const y: i32 = 2; |
| 39 | comptime var z: i32 = if (a) x else y; | 39 | comptime var z: i32 = if (a) x else y; |
| 40 | _ = &z; | ||
| 40 | return z; | 41 | return z; |
| 41 | } | 42 | } |
| 42 | test "inline variable gets result of const if" { | 43 | test "inline variable gets result of const if" { |
| ... | @@ -74,6 +75,7 @@ test "constant expressions" { | ... | @@ -74,6 +75,7 @@ test "constant expressions" { |
| 74 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 75 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 75 | 76 | ||
| 76 | var array: [array_size]u8 = undefined; | 77 | var array: [array_size]u8 = undefined; |
| 78 | _ = &array; | ||
| 77 | try expect(@sizeOf(@TypeOf(array)) == 20); | 79 | try expect(@sizeOf(@TypeOf(array)) == 20); |
| 78 | } | 80 | } |
| 79 | const array_size: u8 = 20; | 81 | const array_size: u8 = 20; |
| ... | @@ -129,7 +131,7 @@ test "pointer to type" { | ... | @@ -129,7 +131,7 @@ test "pointer to type" { |
| 129 | comptime { | 131 | comptime { |
| 130 | var T: type = i32; | 132 | var T: type = i32; |
| 131 | try expect(T == i32); | 133 | try expect(T == i32); |
| 132 | var ptr = &T; | 134 | const ptr = &T; |
| 133 | try expect(@TypeOf(ptr) == *type); | 135 | try expect(@TypeOf(ptr) == *type); |
| 134 | ptr.* = f32; | 136 | ptr.* = f32; |
| 135 | try expect(T == f32); | 137 | try expect(T == f32); |
| ... | @@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void { | ... | @@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void { |
| 372 | test "zero extend from u0 to u1" { | 374 | test "zero extend from u0 to u1" { |
| 373 | var zero_u0: u0 = 0; | 375 | var zero_u0: u0 = 0; |
| 374 | var zero_u1: u1 = zero_u0; | 376 | var zero_u1: u1 = zero_u0; |
| 377 | _ = .{ &zero_u0, &zero_u1 }; | ||
| 375 | try expect(zero_u1 == 0); | 378 | try expect(zero_u1 == 0); |
| 376 | } | 379 | } |
| 377 | 380 | ||
| ... | @@ -408,6 +411,7 @@ test "inline for with same type but different values" { | ... | @@ -408,6 +411,7 @@ test "inline for with same type but different values" { |
| 408 | var res: usize = 0; | 411 | var res: usize = 0; |
| 409 | inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| { | 412 | inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| { |
| 410 | var a: T = undefined; | 413 | var a: T = undefined; |
| 414 | _ = &a; | ||
| 411 | res += a.len; | 415 | res += a.len; |
| 412 | } | 416 | } |
| 413 | try expect(res == 5); | 417 | try expect(res == 5); |
| ... | @@ -460,9 +464,9 @@ test "comptime shl" { | ... | @@ -460,9 +464,9 @@ test "comptime shl" { |
| 460 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 464 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 461 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 465 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 462 | 466 | ||
| 463 | var a: u128 = 3; | 467 | const a: u128 = 3; |
| 464 | var b: u7 = 63; | 468 | const b: u7 = 63; |
| 465 | var c: u128 = 3 << 63; | 469 | const c: u128 = 3 << 63; |
| 466 | try expect((a << b) == c); | 470 | try expect((a << b) == c); |
| 467 | } | 471 | } |
| 468 | 472 | ||
| ... | @@ -489,6 +493,7 @@ test "comptime shlWithOverflow" { | ... | @@ -489,6 +493,7 @@ test "comptime shlWithOverflow" { |
| 489 | 493 | ||
| 490 | const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0]; | 494 | const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0]; |
| 491 | var a = ~@as(u64, 0); | 495 | var a = ~@as(u64, 0); |
| 496 | _ = &a; | ||
| 492 | const rt_shifted = @shlWithOverflow(a, 16)[0]; | 497 | const rt_shifted = @shlWithOverflow(a, 16)[0]; |
| 493 | 498 | ||
| 494 | try expect(ct_shifted == rt_shifted); | 499 | try expect(ct_shifted == rt_shifted); |
| ... | @@ -521,7 +526,8 @@ test "runtime 128 bit integer division" { | ... | @@ -521,7 +526,8 @@ test "runtime 128 bit integer division" { |
| 521 | 526 | ||
| 522 | var a: u128 = 152313999999999991610955792383; | 527 | var a: u128 = 152313999999999991610955792383; |
| 523 | var b: u128 = 10000000000000000000; | 528 | var b: u128 = 10000000000000000000; |
| 524 | var c = a / b; | 529 | _ = .{ &a, &b }; |
| 530 | const c = a / b; | ||
| 525 | try expect(c == 15231399999); | 531 | try expect(c == 15231399999); |
| 526 | } | 532 | } |
| 527 | 533 | ||
| ... | @@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio | ... | @@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio |
| 555 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 561 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 556 | 562 | ||
| 557 | var runtime = [1]i32{3}; | 563 | var runtime = [1]i32{3}; |
| 564 | _ = &runtime; | ||
| 558 | comptime var i: usize = 0; | 565 | comptime var i: usize = 0; |
| 559 | inline while (i < 2) : (i += 1) { | 566 | inline while (i < 2) : (i += 1) { |
| 560 | const result = if (i == 0) [1]i32{2} else runtime; | 567 | const result = if (i == 0) [1]i32{2} else runtime; |
| ... | @@ -692,7 +699,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" { | ... | @@ -692,7 +699,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" { |
| 692 | }; | 699 | }; |
| 693 | 700 | ||
| 694 | const s = S{ .a = 2 }; | 701 | const s = S{ .a = 2 }; |
| 695 | var b = s.b(); | 702 | const b = s.b(); |
| 696 | try expect(b == 2); | 703 | try expect(b == 2); |
| 697 | } | 704 | } |
| 698 | 705 | ||
| ... | @@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" { | ... | @@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" { |
| 759 | 766 | ||
| 760 | var a = [2]u3{ 1, 7 }; | 767 | var a = [2]u3{ 1, 7 }; |
| 761 | var b = [3]u8{ 200, 225, 255 }; | 768 | var b = [3]u8{ 200, 225, 255 }; |
| 762 | var c = a ++ b; | 769 | _ = .{ &a, &b }; |
| 770 | const c = a ++ b; | ||
| 763 | comptime assert(@TypeOf(c) == [5]u8); | 771 | comptime assert(@TypeOf(c) == [5]u8); |
| 764 | try expect(c[0] == 1); | 772 | try expect(c[0] == 1); |
| 765 | try expect(c[1] == 7); | 773 | try expect(c[1] == 7); |
| ... | @@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" { | ... | @@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" { |
| 775 | 783 | ||
| 776 | var a = [2]u3{ 1, 7 }; | 784 | var a = [2]u3{ 1, 7 }; |
| 777 | var b = [3]u8{ 200, 225, 255 }; | 785 | var b = [3]u8{ 200, 225, 255 }; |
| 778 | var c = &a ++ &b; | 786 | const c = &a ++ &b; |
| 779 | comptime assert(@TypeOf(c) == *[5]u8); | 787 | comptime assert(@TypeOf(c) == *[5]u8); |
| 780 | try expect(c[0] == 1); | 788 | try expect(c[0] == 1); |
| 781 | try expect(c[1] == 7); | 789 | try expect(c[1] == 7); |
| ... | @@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" { | ... | @@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" { |
| 791 | 799 | ||
| 792 | var a = [2]u3{ 1, 7 }; | 800 | var a = [2]u3{ 1, 7 }; |
| 793 | var b = [3:69]u8{ 200, 225, 255 }; | 801 | var b = [3:69]u8{ 200, 225, 255 }; |
| 794 | var c = a ++ b; | 802 | _ = .{ &a, &b }; |
| 803 | const c = a ++ b; | ||
| 795 | comptime assert(@TypeOf(c) == [5:69]u8); | 804 | comptime assert(@TypeOf(c) == [5:69]u8); |
| 796 | try expect(c[0] == 1); | 805 | try expect(c[0] == 1); |
| 797 | try expect(c[1] == 7); | 806 | try expect(c[1] == 7); |
| 798 | try expect(c[2] == 200); | 807 | try expect(c[2] == 200); |
| 799 | try expect(c[3] == 225); | 808 | try expect(c[3] == 225); |
| 800 | try expect(c[4] == 255); | 809 | try expect(c[4] == 255); |
| 801 | var ptr: [*]const u8 = &c; | 810 | const ptr: [*]const u8 = &c; |
| 802 | try expect(ptr[5] == 69); | 811 | try expect(ptr[5] == 69); |
| 803 | } | 812 | } |
| 804 | 813 | ||
| ... | @@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" { | ... | @@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" { |
| 808 | 817 | ||
| 809 | var a = [2]u3{ 1, 7 }; | 818 | var a = [2]u3{ 1, 7 }; |
| 810 | var b = [3:69]u8{ 200, 225, 255 }; | 819 | var b = [3:69]u8{ 200, 225, 255 }; |
| 811 | var c = &a ++ &b; | 820 | const c = &a ++ &b; |
| 812 | comptime assert(@TypeOf(c) == *[5:69]u8); | 821 | comptime assert(@TypeOf(c) == *[5:69]u8); |
| 813 | try expect(c[0] == 1); | 822 | try expect(c[0] == 1); |
| 814 | try expect(c[1] == 7); | 823 | try expect(c[1] == 7); |
| 815 | try expect(c[2] == 200); | 824 | try expect(c[2] == 200); |
| 816 | try expect(c[3] == 225); | 825 | try expect(c[3] == 225); |
| 817 | try expect(c[4] == 255); | 826 | try expect(c[4] == 255); |
| 818 | var ptr: [*]const u8 = c; | 827 | const ptr: [*]const u8 = c; |
| 819 | try expect(ptr[5] == 69); | 828 | try expect(ptr[5] == 69); |
| 820 | } | 829 | } |
| 821 | 830 | ||
| ... | @@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" { | ... | @@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" { |
| 825 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 834 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 826 | 835 | ||
| 827 | var a = [2:7]u3{ 1, 6 }; | 836 | var a = [2:7]u3{ 1, 6 }; |
| 828 | var b = a ** 2; | 837 | _ = &a; |
| 838 | const b = a ** 2; | ||
| 829 | comptime assert(@TypeOf(b) == [4:7]u3); | 839 | comptime assert(@TypeOf(b) == [4:7]u3); |
| 830 | try expect(b[0] == 1); | 840 | try expect(b[0] == 1); |
| 831 | try expect(b[1] == 6); | 841 | try expect(b[1] == 6); |
| 832 | try expect(b[2] == 1); | 842 | try expect(b[2] == 1); |
| 833 | try expect(b[3] == 6); | 843 | try expect(b[3] == 6); |
| 834 | var ptr: [*]const u3 = &b; | 844 | const ptr: [*]const u3 = &b; |
| 835 | try expect(ptr[4] == 7); | 845 | try expect(ptr[4] == 7); |
| 836 | } | 846 | } |
| 837 | 847 | ||
| ... | @@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" { | ... | @@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" { |
| 841 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 851 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 842 | 852 | ||
| 843 | var a = [2:7]u3{ 1, 6 }; | 853 | var a = [2:7]u3{ 1, 6 }; |
| 844 | var b = &a ** 2; | 854 | const b = &a ** 2; |
| 845 | comptime assert(@TypeOf(b) == *[4:7]u3); | 855 | comptime assert(@TypeOf(b) == *[4:7]u3); |
| 846 | try expect(b[0] == 1); | 856 | try expect(b[0] == 1); |
| 847 | try expect(b[1] == 6); | 857 | try expect(b[1] == 6); |
| 848 | try expect(b[2] == 1); | 858 | try expect(b[2] == 1); |
| 849 | try expect(b[3] == 6); | 859 | try expect(b[3] == 6); |
| 850 | var ptr: [*]const u3 = b; | 860 | const ptr: [*]const u3 = b; |
| 851 | try expect(ptr[4] == 7); | 861 | try expect(ptr[4] == 7); |
| 852 | } | 862 | } |
| 853 | 863 | ||
| ... | @@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" { | ... | @@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" { |
| 913 | .x = i, | 923 | .x = i, |
| 914 | }; | 924 | }; |
| 915 | } | 925 | } |
| 916 | var ptr = @as([*]S, @ptrCast(&array)); | 926 | var ptr: [*]S = @ptrCast(&array); |
| 917 | var x = ptr[0].x; | 927 | const x = ptr[0].x; |
| 918 | assert(x == 0); | 928 | assert(x == 0); |
| 919 | ptr += 1; | 929 | ptr += 1; |
| 920 | assert(ptr[1].x == 2); | 930 | assert(ptr[1].x == 2); |
| ... | @@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" { | ... | @@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" { |
| 953 | const S = struct { | 963 | const S = struct { |
| 954 | fn b(c: anytype) !void { | 964 | fn b(c: anytype) !void { |
| 955 | const D = struct { c: @TypeOf(c) }; | 965 | const D = struct { c: @TypeOf(c) }; |
| 956 | var d = D{ .c = c }; | 966 | const d: D = .{ .c = c }; |
| 957 | try expect(d.c == 1234); | 967 | try expect(d.c == 1234); |
| 958 | } | 968 | } |
| 959 | }; | 969 | }; |
| 960 | var c: i32 = 1234; | 970 | var c: i32 = 1234; |
| 971 | _ = &c; | ||
| 961 | try S.b(c); | 972 | try S.b(c); |
| 962 | } | 973 | } |
| 963 | 974 | ||
| ... | @@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" { | ... | @@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" { |
| 966 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 977 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 967 | 978 | ||
| 968 | var x: u32 = 1234; | 979 | var x: u32 = 1234; |
| 980 | _ = &x; | ||
| 969 | const S = struct { val: @TypeOf(x + 100) }; | 981 | const S = struct { val: @TypeOf(x + 100) }; |
| 970 | const s: S = .{ .val = x }; | 982 | const s: S = .{ .val = x }; |
| 971 | try expect(s.val == 1234); | 983 | try expect(s.val == 1234); |
| ... | @@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea | ... | @@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea |
| 977 | const S = struct { | 989 | const S = struct { |
| 978 | fn doTheTest() !void { | 990 | fn doTheTest() !void { |
| 979 | var runtime: u8 = 'b'; | 991 | var runtime: u8 = 'b'; |
| 992 | _ = &runtime; | ||
| 980 | inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { | 993 | inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { |
| 981 | bar(); | 994 | bar(); |
| 982 | if (byte == runtime) { | 995 | if (byte == runtime) { |
| ... | @@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t | ... | @@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t |
| 1010 | const S = struct { | 1023 | const S = struct { |
| 1011 | fn doTheTest() !void { | 1024 | fn doTheTest() !void { |
| 1012 | var runtime: u8 = 'b'; | 1025 | var runtime: u8 = 'b'; |
| 1026 | _ = &runtime; | ||
| 1013 | outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| { | 1027 | outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| { |
| 1014 | inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { | 1028 | inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { |
| 1015 | bar(outer_byte); | 1029 | bar(outer_byte); |
| ... | @@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" { | ... | @@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" { |
| 1387 | 1401 | ||
| 1388 | test "inline for inside a runtime condition" { | 1402 | test "inline for inside a runtime condition" { |
| 1389 | var a = false; | 1403 | var a = false; |
| 1404 | _ = &a; | ||
| 1390 | if (a) { | 1405 | if (a) { |
| 1391 | const arr = .{ 1, 2, 3 }; | 1406 | const arr = .{ 1, 2, 3 }; |
| 1392 | inline for (arr) |val| { | 1407 | inline for (arr) |val| { |
| ... | @@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" { | ... | @@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" { |
| 1522 | 1537 | ||
| 1523 | const array = [1]u8{'A'} ++ [1]?u8{null}; | 1538 | const array = [1]u8{'A'} ++ [1]?u8{null}; |
| 1524 | var index: usize = 0; | 1539 | var index: usize = 0; |
| 1540 | _ = &index; | ||
| 1525 | try expect(array[index].? == 'A'); | 1541 | try expect(array[index].? == 'A'); |
| 1526 | } | 1542 | } |
| 1527 | 1543 | ||
| ... | @@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" { | ... | @@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" { |
| 1556 | var v: @This() = c; | 1572 | var v: @This() = c; |
| 1557 | }; | 1573 | }; |
| 1558 | var p = &S.c; | 1574 | var p = &S.c; |
| 1575 | _ = &p; | ||
| 1559 | try std.testing.expect(p.x == S.c.x); | 1576 | try std.testing.expect(p.x == S.c.x); |
| 1560 | S.v.x = 2; | 1577 | S.v.x = 2; |
| 1561 | try std.testing.expect(p.x == S.c.x); | 1578 | try std.testing.expect(p.x == S.c.x); |
| ... | @@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" { | ... | @@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" { |
| 1625 | test "if inside a switch" { | 1642 | test "if inside a switch" { |
| 1626 | var condition = true; | 1643 | var condition = true; |
| 1627 | var wave_type: u32 = 0; | 1644 | var wave_type: u32 = 0; |
| 1628 | var sample: i32 = switch (wave_type) { | 1645 | _ = .{ &condition, &wave_type }; |
| 1646 | const sample: i32 = switch (wave_type) { | ||
| 1629 | 0 => if (condition) 2 else 3, | 1647 | 0 => if (condition) 2 else 3, |
| 1630 | 1 => 100, | 1648 | 1 => 100, |
| 1631 | 2 => 200, | 1649 | 2 => 200, |
| ... | @@ -1673,6 +1691,7 @@ test "@inComptime" { | ... | @@ -1673,6 +1691,7 @@ test "@inComptime" { |
| 1673 | comptime { | 1691 | comptime { |
| 1674 | var foo = [3]u8{ 0x55, 0x55, 0x55 }; | 1692 | var foo = [3]u8{ 0x55, 0x55, 0x55 }; |
| 1675 | var bar = [2]u8{ 1, 2 }; | 1693 | var bar = [2]u8{ 1, 2 }; |
| 1694 | _ = .{ &foo, &bar }; | ||
| 1676 | foo[0..2].* = bar; | 1695 | foo[0..2].* = bar; |
| 1677 | assert(foo[0] == 1); | 1696 | assert(foo[0] == 1); |
| 1678 | assert(foo[1] == 2); | 1697 | assert(foo[1] == 2); |
test/behavior/extern_struct_zero_size_fields.zig+1-1| ... | @@ -17,5 +17,5 @@ const T = extern struct { | ... | @@ -17,5 +17,5 @@ const T = extern struct { |
| 17 | 17 | ||
| 18 | test { | 18 | test { |
| 19 | var t: T = .{}; | 19 | var t: T = .{}; |
| 20 | _ = t; | 20 | _ = &t; |
| 21 | } | 21 | } |
test/behavior/floatop.zig+150-14| ... | @@ -42,6 +42,8 @@ test "add f80/f128/c_longdouble" { | ... | @@ -42,6 +42,8 @@ test "add f80/f128/c_longdouble" { |
| 42 | fn testAdd(comptime T: type) !void { | 42 | fn testAdd(comptime T: type) !void { |
| 43 | var one_point_two_five: T = 1.25; | 43 | var one_point_two_five: T = 1.25; |
| 44 | var two_point_seven_five: T = 2.75; | 44 | var two_point_seven_five: T = 2.75; |
| 45 | _ = &one_point_two_five; | ||
| 46 | _ = &two_point_seven_five; | ||
| 45 | try expect(one_point_two_five + two_point_seven_five == 4); | 47 | try expect(one_point_two_five + two_point_seven_five == 4); |
| 46 | } | 48 | } |
| 47 | 49 | ||
| ... | @@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" { | ... | @@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" { |
| 74 | fn testSub(comptime T: type) !void { | 76 | fn testSub(comptime T: type) !void { |
| 75 | var one_point_two_five: T = 1.25; | 77 | var one_point_two_five: T = 1.25; |
| 76 | var two_point_seven_five: T = 2.75; | 78 | var two_point_seven_five: T = 2.75; |
| 79 | _ = &one_point_two_five; | ||
| 80 | _ = &two_point_seven_five; | ||
| 77 | try expect(one_point_two_five - two_point_seven_five == -1.5); | 81 | try expect(one_point_two_five - two_point_seven_five == -1.5); |
| 78 | } | 82 | } |
| 79 | 83 | ||
| ... | @@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" { | ... | @@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" { |
| 106 | fn testMul(comptime T: type) !void { | 110 | fn testMul(comptime T: type) !void { |
| 107 | var one_point_two_five: T = 1.25; | 111 | var one_point_two_five: T = 1.25; |
| 108 | var two_point_seven_five: T = 2.75; | 112 | var two_point_seven_five: T = 2.75; |
| 113 | _ = &one_point_two_five; | ||
| 114 | _ = &two_point_seven_five; | ||
| 109 | try expect(one_point_two_five * two_point_seven_five == 3.4375); | 115 | try expect(one_point_two_five * two_point_seven_five == 3.4375); |
| 110 | } | 116 | } |
| 111 | 117 | ||
| ... | @@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void { | ... | @@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void { |
| 152 | { | 158 | { |
| 153 | // No decimal part | 159 | // No decimal part |
| 154 | var x: T = 1.0; | 160 | var x: T = 1.0; |
| 161 | _ = &x; | ||
| 155 | try expect(x == 1.0); | 162 | try expect(x == 1.0); |
| 156 | try expect(x != 0.0); | 163 | try expect(x != 0.0); |
| 157 | try expect(x > 0.0); | 164 | try expect(x > 0.0); |
| ... | @@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void { | ... | @@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void { |
| 162 | { | 169 | { |
| 163 | // Non-zero decimal part | 170 | // Non-zero decimal part |
| 164 | var x: T = 1.5; | 171 | var x: T = 1.5; |
| 172 | _ = &x; | ||
| 165 | try expect(x != 1.0); | 173 | try expect(x != 1.0); |
| 166 | try expect(x != 2.0); | 174 | try expect(x != 2.0); |
| 167 | try expect(x > 1.0); | 175 | try expect(x > 1.0); |
| ... | @@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void { | ... | @@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void { |
| 184 | math.floatMax(T), | 192 | math.floatMax(T), |
| 185 | math.inf(T), | 193 | math.inf(T), |
| 186 | }; | 194 | }; |
| 195 | _ = &edges; | ||
| 187 | for (edges, 0..) |rhs, rhs_i| { | 196 | for (edges, 0..) |rhs, rhs_i| { |
| 188 | for (edges, 0..) |lhs, lhs_i| { | 197 | for (edges, 0..) |lhs, lhs_i| { |
| 189 | const no_nan = lhs_i != 5 and rhs_i != 5; | 198 | const no_nan = lhs_i != 5 and rhs_i != 5; |
| ... | @@ -212,6 +221,7 @@ test "different sized float comparisons" { | ... | @@ -212,6 +221,7 @@ test "different sized float comparisons" { |
| 212 | fn testDifferentSizedFloatComparisons() !void { | 221 | fn testDifferentSizedFloatComparisons() !void { |
| 213 | var a: f16 = 1; | 222 | var a: f16 = 1; |
| 214 | var b: f64 = 2; | 223 | var b: f64 = 2; |
| 224 | _ = .{ &a, &b }; | ||
| 215 | try expect(a < b); | 225 | try expect(a < b); |
| 216 | } | 226 | } |
| 217 | 227 | ||
| ... | @@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" { | ... | @@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" { |
| 240 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 250 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 241 | 251 | ||
| 242 | const a: f128 = -2; | 252 | const a: f128 = -2; |
| 243 | var b = @as(i64, @intFromFloat(a)); | 253 | var b: i64 = @intFromFloat(a); |
| 254 | _ = &b; | ||
| 244 | try expect(@as(i64, -2) == b); | 255 | try expect(@as(i64, -2) == b); |
| 245 | } | 256 | } |
| 246 | 257 | ||
| ... | @@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void { | ... | @@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void { |
| 331 | try expect(math.isNan(@sqrt(neg_one))); | 342 | try expect(math.isNan(@sqrt(neg_one))); |
| 332 | var nan: T = math.nan(T); | 343 | var nan: T = math.nan(T); |
| 333 | try expect(math.isNan(@sqrt(nan))); | 344 | try expect(math.isNan(@sqrt(nan))); |
| 345 | |||
| 346 | _ = .{ | ||
| 347 | &four, | ||
| 348 | &nine, | ||
| 349 | &twenty_five, | ||
| 350 | &sixty_four, | ||
| 351 | &one_point_one, | ||
| 352 | &two, | ||
| 353 | &three_point_six, | ||
| 354 | &sixty_four_point_one, | ||
| 355 | &twelve, | ||
| 356 | &thirteen, | ||
| 357 | &fourteen, | ||
| 358 | &a, | ||
| 359 | &b, | ||
| 360 | &c, | ||
| 361 | &inf, | ||
| 362 | &zero, | ||
| 363 | &neg_zero, | ||
| 364 | &neg_one, | ||
| 365 | &nan, | ||
| 366 | }; | ||
| 334 | } | 367 | } |
| 335 | 368 | ||
| 336 | test "@sqrt with vectors" { | 369 | test "@sqrt with vectors" { |
| ... | @@ -345,7 +378,8 @@ test "@sqrt with vectors" { | ... | @@ -345,7 +378,8 @@ test "@sqrt with vectors" { |
| 345 | 378 | ||
| 346 | fn testSqrtWithVectors() !void { | 379 | fn testSqrtWithVectors() !void { |
| 347 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; | 380 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 348 | var result = @sqrt(v); | 381 | _ = &v; |
| 382 | const result = @sqrt(v); | ||
| 349 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); | 383 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); |
| 350 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); | 384 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); |
| 351 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); | 385 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); |
| ... | @@ -394,8 +428,10 @@ test "@sin f80/f128/c_longdouble" { | ... | @@ -394,8 +428,10 @@ test "@sin f80/f128/c_longdouble" { |
| 394 | fn testSin(comptime T: type) !void { | 428 | fn testSin(comptime T: type) !void { |
| 395 | const eps = epsForType(T); | 429 | const eps = epsForType(T); |
| 396 | var zero: T = 0; | 430 | var zero: T = 0; |
| 431 | _ = &zero; | ||
| 397 | try expect(@sin(zero) == 0); | 432 | try expect(@sin(zero) == 0); |
| 398 | var pi: T = math.pi; | 433 | var pi: T = math.pi; |
| 434 | _ = &pi; | ||
| 399 | try expect(math.approxEqAbs(T, @sin(pi), 0, eps)); | 435 | try expect(math.approxEqAbs(T, @sin(pi), 0, eps)); |
| 400 | try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps)); | 436 | try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps)); |
| 401 | try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps)); | 437 | try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps)); |
| ... | @@ -414,7 +450,8 @@ test "@sin with vectors" { | ... | @@ -414,7 +450,8 @@ test "@sin with vectors" { |
| 414 | 450 | ||
| 415 | fn testSinWithVectors() !void { | 451 | fn testSinWithVectors() !void { |
| 416 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; | 452 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 417 | var result = @sin(v); | 453 | _ = &v; |
| 454 | const result = @sin(v); | ||
| 418 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); | 455 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); |
| 419 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); | 456 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); |
| 420 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon)); | 457 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon)); |
| ... | @@ -463,8 +500,10 @@ test "@cos f80/f128/c_longdouble" { | ... | @@ -463,8 +500,10 @@ test "@cos f80/f128/c_longdouble" { |
| 463 | fn testCos(comptime T: type) !void { | 500 | fn testCos(comptime T: type) !void { |
| 464 | const eps = epsForType(T); | 501 | const eps = epsForType(T); |
| 465 | var zero: T = 0; | 502 | var zero: T = 0; |
| 503 | _ = &zero; | ||
| 466 | try expect(@cos(zero) == 1); | 504 | try expect(@cos(zero) == 1); |
| 467 | var pi: T = math.pi; | 505 | var pi: T = math.pi; |
| 506 | _ = &pi; | ||
| 468 | try expect(math.approxEqAbs(T, @cos(pi), -1, eps)); | 507 | try expect(math.approxEqAbs(T, @cos(pi), -1, eps)); |
| 469 | try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps)); | 508 | try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps)); |
| 470 | try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps)); | 509 | try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps)); |
| ... | @@ -483,7 +522,8 @@ test "@cos with vectors" { | ... | @@ -483,7 +522,8 @@ test "@cos with vectors" { |
| 483 | 522 | ||
| 484 | fn testCosWithVectors() !void { | 523 | fn testCosWithVectors() !void { |
| 485 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; | 524 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 486 | var result = @cos(v); | 525 | _ = &v; |
| 526 | const result = @cos(v); | ||
| 487 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); | 527 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); |
| 488 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); | 528 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); |
| 489 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon)); | 529 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon)); |
| ... | @@ -532,8 +572,10 @@ test "@tan f80/f128/c_longdouble" { | ... | @@ -532,8 +572,10 @@ test "@tan f80/f128/c_longdouble" { |
| 532 | fn testTan(comptime T: type) !void { | 572 | fn testTan(comptime T: type) !void { |
| 533 | const eps = epsForType(T); | 573 | const eps = epsForType(T); |
| 534 | var zero: T = 0; | 574 | var zero: T = 0; |
| 575 | _ = &zero; | ||
| 535 | try expect(@tan(zero) == 0); | 576 | try expect(@tan(zero) == 0); |
| 536 | var pi: T = math.pi; | 577 | var pi: T = math.pi; |
| 578 | _ = &pi; | ||
| 537 | try expect(math.approxEqAbs(T, @tan(pi), 0, eps)); | 579 | try expect(math.approxEqAbs(T, @tan(pi), 0, eps)); |
| 538 | try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps)); | 580 | try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps)); |
| 539 | try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps)); | 581 | try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps)); |
| ... | @@ -552,7 +594,8 @@ test "@tan with vectors" { | ... | @@ -552,7 +594,8 @@ test "@tan with vectors" { |
| 552 | 594 | ||
| 553 | fn testTanWithVectors() !void { | 595 | fn testTanWithVectors() !void { |
| 554 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; | 596 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 555 | var result = @tan(v); | 597 | _ = &v; |
| 598 | const result = @tan(v); | ||
| 556 | try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon)); | 599 | try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon)); |
| 557 | try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon)); | 600 | try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon)); |
| 558 | try expect(math.approxEqAbs(f32, @tan(@as(f32, 3.3)), result[2], epsilon)); | 601 | try expect(math.approxEqAbs(f32, @tan(@as(f32, 3.3)), result[2], epsilon)); |
| ... | @@ -600,11 +643,17 @@ test "@exp f80/f128/c_longdouble" { | ... | @@ -600,11 +643,17 @@ test "@exp f80/f128/c_longdouble" { |
| 600 | 643 | ||
| 601 | fn testExp(comptime T: type) !void { | 644 | fn testExp(comptime T: type) !void { |
| 602 | const eps = epsForType(T); | 645 | const eps = epsForType(T); |
| 646 | |||
| 603 | var zero: T = 0; | 647 | var zero: T = 0; |
| 648 | _ = &zero; | ||
| 604 | try expect(@exp(zero) == 1); | 649 | try expect(@exp(zero) == 1); |
| 650 | |||
| 605 | var two: T = 2; | 651 | var two: T = 2; |
| 652 | _ = &two; | ||
| 606 | try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps)); | 653 | try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps)); |
| 654 | |||
| 607 | var five: T = 5; | 655 | var five: T = 5; |
| 656 | _ = &five; | ||
| 608 | try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps)); | 657 | try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps)); |
| 609 | } | 658 | } |
| 610 | 659 | ||
| ... | @@ -621,7 +670,8 @@ test "@exp with vectors" { | ... | @@ -621,7 +670,8 @@ test "@exp with vectors" { |
| 621 | 670 | ||
| 622 | fn testExpWithVectors() !void { | 671 | fn testExpWithVectors() !void { |
| 623 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; | 672 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 624 | var result = @exp(v); | 673 | _ = &v; |
| 674 | const result = @exp(v); | ||
| 625 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); | 675 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); |
| 626 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon)); | 676 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon)); |
| 627 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon)); | 677 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon)); |
| ... | @@ -675,6 +725,7 @@ fn testExp2(comptime T: type) !void { | ... | @@ -675,6 +725,7 @@ fn testExp2(comptime T: type) !void { |
| 675 | try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps)); | 725 | try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps)); |
| 676 | var four_point_five: T = 4.5; | 726 | var four_point_five: T = 4.5; |
| 677 | try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps)); | 727 | try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps)); |
| 728 | _ = .{ &two, &one_point_five, &four_point_five }; | ||
| 678 | } | 729 | } |
| 679 | 730 | ||
| 680 | test "@exp2 with @vectors" { | 731 | test "@exp2 with @vectors" { |
| ... | @@ -690,7 +741,8 @@ test "@exp2 with @vectors" { | ... | @@ -690,7 +741,8 @@ test "@exp2 with @vectors" { |
| 690 | 741 | ||
| 691 | fn testExp2WithVectors() !void { | 742 | fn testExp2WithVectors() !void { |
| 692 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; | 743 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 693 | var result = @exp2(v); | 744 | _ = &v; |
| 745 | const result = @exp2(v); | ||
| 694 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); | 746 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); |
| 695 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon)); | 747 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon)); |
| 696 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon)); | 748 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon)); |
| ... | @@ -744,6 +796,7 @@ fn testLog(comptime T: type) !void { | ... | @@ -744,6 +796,7 @@ fn testLog(comptime T: type) !void { |
| 744 | try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps)); | 796 | try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps)); |
| 745 | var five: T = 5; | 797 | var five: T = 5; |
| 746 | try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps)); | 798 | try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps)); |
| 799 | _ = .{ &e, &two, &five }; | ||
| 747 | } | 800 | } |
| 748 | 801 | ||
| 749 | test "@log with @vectors" { | 802 | test "@log with @vectors" { |
| ... | @@ -756,7 +809,8 @@ test "@log with @vectors" { | ... | @@ -756,7 +809,8 @@ test "@log with @vectors" { |
| 756 | 809 | ||
| 757 | { | 810 | { |
| 758 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; | 811 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 759 | var result = @log(v); | 812 | _ = &v; |
| 813 | const result = @log(v); | ||
| 760 | try expect(@log(@as(f32, 1.1)) == result[0]); | 814 | try expect(@log(@as(f32, 1.1)) == result[0]); |
| 761 | try expect(@log(@as(f32, 2.2)) == result[1]); | 815 | try expect(@log(@as(f32, 2.2)) == result[1]); |
| 762 | try expect(@log(@as(f32, 0.3)) == result[2]); | 816 | try expect(@log(@as(f32, 0.3)) == result[2]); |
| ... | @@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void { | ... | @@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void { |
| 811 | try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps)); | 865 | try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps)); |
| 812 | var ten: T = 10; | 866 | var ten: T = 10; |
| 813 | try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps)); | 867 | try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps)); |
| 868 | _ = .{ &four, &six, &ten }; | ||
| 814 | } | 869 | } |
| 815 | 870 | ||
| 816 | test "@log2 with vectors" { | 871 | test "@log2 with vectors" { |
| ... | @@ -830,7 +885,8 @@ test "@log2 with vectors" { | ... | @@ -830,7 +885,8 @@ test "@log2 with vectors" { |
| 830 | 885 | ||
| 831 | fn testLog2WithVectors() !void { | 886 | fn testLog2WithVectors() !void { |
| 832 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; | 887 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 833 | var result = @log2(v); | 888 | _ = &v; |
| 889 | const result = @log2(v); | ||
| 834 | try expect(@log2(@as(f32, 1.1)) == result[0]); | 890 | try expect(@log2(@as(f32, 1.1)) == result[0]); |
| 835 | try expect(@log2(@as(f32, 2.2)) == result[1]); | 891 | try expect(@log2(@as(f32, 2.2)) == result[1]); |
| 836 | try expect(@log2(@as(f32, 0.3)) == result[2]); | 892 | try expect(@log2(@as(f32, 0.3)) == result[2]); |
| ... | @@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void { | ... | @@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void { |
| 884 | try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps)); | 940 | try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps)); |
| 885 | var fifty: T = 50; | 941 | var fifty: T = 50; |
| 886 | try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps)); | 942 | try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps)); |
| 943 | _ = .{ &hundred, &fifteen, &fifty }; | ||
| 887 | } | 944 | } |
| 888 | 945 | ||
| 889 | test "@log10 with vectors" { | 946 | test "@log10 with vectors" { |
| ... | @@ -899,7 +956,8 @@ test "@log10 with vectors" { | ... | @@ -899,7 +956,8 @@ test "@log10 with vectors" { |
| 899 | 956 | ||
| 900 | fn testLog10WithVectors() !void { | 957 | fn testLog10WithVectors() !void { |
| 901 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; | 958 | var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 902 | var result = @log10(v); | 959 | _ = &v; |
| 960 | const result = @log10(v); | ||
| 903 | try expect(@log10(@as(f32, 1.1)) == result[0]); | 961 | try expect(@log10(@as(f32, 1.1)) == result[0]); |
| 904 | try expect(@log10(@as(f32, 2.2)) == result[1]); | 962 | try expect(@log10(@as(f32, 2.2)) == result[1]); |
| 905 | try expect(@log10(@as(f32, 0.3)) == result[2]); | 963 | try expect(@log10(@as(f32, 0.3)) == result[2]); |
| ... | @@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void { | ... | @@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void { |
| 987 | try expect(math.isPositiveInf(@abs(neg_inf))); | 1045 | try expect(math.isPositiveInf(@abs(neg_inf))); |
| 988 | var nan: T = math.nan(T); | 1046 | var nan: T = math.nan(T); |
| 989 | try expect(math.isNan(@abs(nan))); | 1047 | try expect(math.isNan(@abs(nan))); |
| 1048 | |||
| 1049 | _ = .{ | ||
| 1050 | &two_point_five, | ||
| 1051 | &neg_two_point_five, | ||
| 1052 | &twelve, | ||
| 1053 | &neg_fourteen, | ||
| 1054 | &one, | ||
| 1055 | &neg_one, | ||
| 1056 | &min, | ||
| 1057 | &neg_min, | ||
| 1058 | &max, | ||
| 1059 | &neg_max, | ||
| 1060 | &zero, | ||
| 1061 | &neg_zero, | ||
| 1062 | &true_min, | ||
| 1063 | &neg_true_min, | ||
| 1064 | &inf, | ||
| 1065 | &neg_inf, | ||
| 1066 | &nan, | ||
| 1067 | }; | ||
| 990 | } | 1068 | } |
| 991 | 1069 | ||
| 992 | test "@abs with vectors" { | 1070 | test "@abs with vectors" { |
| ... | @@ -1001,7 +1079,8 @@ test "@abs with vectors" { | ... | @@ -1001,7 +1079,8 @@ test "@abs with vectors" { |
| 1001 | 1079 | ||
| 1002 | fn testFabsWithVectors() !void { | 1080 | fn testFabsWithVectors() !void { |
| 1003 | var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; | 1081 | var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 1004 | var result = @abs(v); | 1082 | _ = &v; |
| 1083 | const result = @abs(v); | ||
| 1005 | try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon)); | 1084 | try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon)); |
| 1006 | try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon)); | 1085 | try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon)); |
| 1007 | try expect(math.approxEqAbs(f32, @abs(@as(f32, 0.3)), result[2], epsilon)); | 1086 | try expect(math.approxEqAbs(f32, @abs(@as(f32, 0.3)), result[2], epsilon)); |
| ... | @@ -1070,6 +1149,17 @@ fn testFloor(comptime T: type) !void { | ... | @@ -1070,6 +1149,17 @@ fn testFloor(comptime T: type) !void { |
| 1070 | try expect(@floor(fourteen_point_seven) == 14.0); | 1149 | try expect(@floor(fourteen_point_seven) == 14.0); |
| 1071 | var neg_fourteen_point_seven: T = -14.7; | 1150 | var neg_fourteen_point_seven: T = -14.7; |
| 1072 | try expect(@floor(neg_fourteen_point_seven) == -15.0); | 1151 | try expect(@floor(neg_fourteen_point_seven) == -15.0); |
| 1152 | |||
| 1153 | _ = .{ | ||
| 1154 | &two_point_one, | ||
| 1155 | &neg_two_point_one, | ||
| 1156 | &three_point_five, | ||
| 1157 | &neg_three_point_five, | ||
| 1158 | &twelve, | ||
| 1159 | &neg_twelve, | ||
| 1160 | &fourteen_point_seven, | ||
| 1161 | &neg_fourteen_point_seven, | ||
| 1162 | }; | ||
| 1073 | } | 1163 | } |
| 1074 | 1164 | ||
| 1075 | test "@floor with vectors" { | 1165 | test "@floor with vectors" { |
| ... | @@ -1086,7 +1176,8 @@ test "@floor with vectors" { | ... | @@ -1086,7 +1176,8 @@ test "@floor with vectors" { |
| 1086 | 1176 | ||
| 1087 | fn testFloorWithVectors() !void { | 1177 | fn testFloorWithVectors() !void { |
| 1088 | var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; | 1178 | var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 1089 | var result = @floor(v); | 1179 | _ = &v; |
| 1180 | const result = @floor(v); | ||
| 1090 | try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); | 1181 | try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); |
| 1091 | try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon)); | 1182 | try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon)); |
| 1092 | try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon)); | 1183 | try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon)); |
| ... | @@ -1155,6 +1246,17 @@ fn testCeil(comptime T: type) !void { | ... | @@ -1155,6 +1246,17 @@ fn testCeil(comptime T: type) !void { |
| 1155 | try expect(@ceil(fourteen_point_seven) == 15.0); | 1246 | try expect(@ceil(fourteen_point_seven) == 15.0); |
| 1156 | var neg_fourteen_point_seven: T = -14.7; | 1247 | var neg_fourteen_point_seven: T = -14.7; |
| 1157 | try expect(@ceil(neg_fourteen_point_seven) == -14.0); | 1248 | try expect(@ceil(neg_fourteen_point_seven) == -14.0); |
| 1249 | |||
| 1250 | _ = .{ | ||
| 1251 | &two_point_one, | ||
| 1252 | &neg_two_point_one, | ||
| 1253 | &three_point_five, | ||
| 1254 | &neg_three_point_five, | ||
| 1255 | &twelve, | ||
| 1256 | &neg_twelve, | ||
| 1257 | &fourteen_point_seven, | ||
| 1258 | &neg_fourteen_point_seven, | ||
| 1259 | }; | ||
| 1158 | } | 1260 | } |
| 1159 | 1261 | ||
| 1160 | test "@ceil with vectors" { | 1262 | test "@ceil with vectors" { |
| ... | @@ -1171,7 +1273,8 @@ test "@ceil with vectors" { | ... | @@ -1171,7 +1273,8 @@ test "@ceil with vectors" { |
| 1171 | 1273 | ||
| 1172 | fn testCeilWithVectors() !void { | 1274 | fn testCeilWithVectors() !void { |
| 1173 | var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; | 1275 | var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 1174 | var result = @ceil(v); | 1276 | _ = &v; |
| 1277 | const result = @ceil(v); | ||
| 1175 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); | 1278 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); |
| 1176 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon)); | 1279 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon)); |
| 1177 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon)); | 1280 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon)); |
| ... | @@ -1250,6 +1353,17 @@ fn testTrunc(comptime T: type) !void { | ... | @@ -1250,6 +1353,17 @@ fn testTrunc(comptime T: type) !void { |
| 1250 | try expect(@trunc(fourteen_point_seven) == 14.0); | 1353 | try expect(@trunc(fourteen_point_seven) == 14.0); |
| 1251 | var neg_fourteen_point_seven: T = -14.7; | 1354 | var neg_fourteen_point_seven: T = -14.7; |
| 1252 | try expect(@trunc(neg_fourteen_point_seven) == -14.0); | 1355 | try expect(@trunc(neg_fourteen_point_seven) == -14.0); |
| 1356 | |||
| 1357 | _ = .{ | ||
| 1358 | &two_point_one, | ||
| 1359 | &neg_two_point_one, | ||
| 1360 | &three_point_five, | ||
| 1361 | &neg_three_point_five, | ||
| 1362 | &twelve, | ||
| 1363 | &neg_twelve, | ||
| 1364 | &fourteen_point_seven, | ||
| 1365 | &neg_fourteen_point_seven, | ||
| 1366 | }; | ||
| 1253 | } | 1367 | } |
| 1254 | 1368 | ||
| 1255 | test "@trunc with vectors" { | 1369 | test "@trunc with vectors" { |
| ... | @@ -1266,7 +1380,8 @@ test "@trunc with vectors" { | ... | @@ -1266,7 +1380,8 @@ test "@trunc with vectors" { |
| 1266 | 1380 | ||
| 1267 | fn testTruncWithVectors() !void { | 1381 | fn testTruncWithVectors() !void { |
| 1268 | var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; | 1382 | var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 1269 | var result = @trunc(v); | 1383 | _ = &v; |
| 1384 | const result = @trunc(v); | ||
| 1270 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); | 1385 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); |
| 1271 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon)); | 1386 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon)); |
| 1272 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon)); | 1387 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon)); |
| ... | @@ -1365,6 +1480,27 @@ fn testNeg(comptime T: type) !void { | ... | @@ -1365,6 +1480,27 @@ fn testNeg(comptime T: type) !void { |
| 1365 | var neg_nan: T = -math.nan(T); | 1480 | var neg_nan: T = -math.nan(T); |
| 1366 | try expect(math.isNan(-neg_nan)); | 1481 | try expect(math.isNan(-neg_nan)); |
| 1367 | try expect(!math.signbit(-neg_nan)); | 1482 | try expect(!math.signbit(-neg_nan)); |
| 1483 | |||
| 1484 | _ = .{ | ||
| 1485 | &two_point_five, | ||
| 1486 | &neg_two_point_five, | ||
| 1487 | &twelve, | ||
| 1488 | &neg_fourteen, | ||
| 1489 | &one, | ||
| 1490 | &neg_one, | ||
| 1491 | &min, | ||
| 1492 | &neg_min, | ||
| 1493 | &max, | ||
| 1494 | &neg_max, | ||
| 1495 | &zero, | ||
| 1496 | &neg_zero, | ||
| 1497 | &true_min, | ||
| 1498 | &neg_true_min, | ||
| 1499 | &inf, | ||
| 1500 | &neg_inf, | ||
| 1501 | &nan, | ||
| 1502 | &neg_nan, | ||
| 1503 | }; | ||
| 1368 | } | 1504 | } |
| 1369 | 1505 | ||
| 1370 | test "eval @setFloatMode at compile-time" { | 1506 | test "eval @setFloatMode at compile-time" { |
test/behavior/fn.zig+9-4| ... | @@ -21,6 +21,7 @@ fn testLocVars(b: i32) void { | ... | @@ -21,6 +21,7 @@ fn testLocVars(b: i32) void { |
| 21 | 21 | ||
| 22 | test "mutable local variables" { | 22 | test "mutable local variables" { |
| 23 | var zero: i32 = 0; | 23 | var zero: i32 = 0; |
| 24 | _ = &zero; | ||
| 24 | try expect(zero == 0); | 25 | try expect(zero == 0); |
| 25 | 26 | ||
| 26 | var i = @as(i32, 0); | 27 | var i = @as(i32, 0); |
| ... | @@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 { | ... | @@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 { |
| 70 | test "return inner function which references comptime variable of outer function" { | 71 | test "return inner function which references comptime variable of outer function" { |
| 71 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 72 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 72 | 73 | ||
| 73 | var func = outer(10); | 74 | const func = outer(10); |
| 74 | try expect(func(3) == 7); | 75 | try expect(func(3) == 7); |
| 75 | } | 76 | } |
| 76 | 77 | ||
| ... | @@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" { | ... | @@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" { |
| 259 | 260 | ||
| 260 | const S = struct { | 261 | const S = struct { |
| 261 | fn entry() !void { | 262 | fn entry() !void { |
| 262 | var x = Foo{ | 263 | const x = Foo{ |
| 263 | .field = optionalPtr(), | 264 | .field = optionalPtr(), |
| 264 | }; | 265 | }; |
| 265 | try expect(x.field.?.* == 999); | 266 | try expect(x.field.?.* == 999); |
| ... | @@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" { | ... | @@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" { |
| 386 | const S = struct { | 387 | const S = struct { |
| 387 | fn doTheTest() !void { | 388 | fn doTheTest() !void { |
| 388 | var x: i32 = 1; | 389 | var x: i32 = 1; |
| 390 | _ = &x; | ||
| 389 | try expect(foo(x) == 10); | 391 | try expect(foo(x) == 10); |
| 390 | try expect(foo(i32) == 20); | 392 | try expect(foo(i32) == 20); |
| 391 | } | 393 | } |
| ... | @@ -413,11 +415,11 @@ test "import passed byref to function in return type" { | ... | @@ -413,11 +415,11 @@ test "import passed byref to function in return type" { |
| 413 | 415 | ||
| 414 | const S = struct { | 416 | const S = struct { |
| 415 | fn get() @import("std").ArrayListUnmanaged(i32) { | 417 | fn get() @import("std").ArrayListUnmanaged(i32) { |
| 416 | var x: @import("std").ArrayListUnmanaged(i32) = .{}; | 418 | const x: @import("std").ArrayListUnmanaged(i32) = .{}; |
| 417 | return x; | 419 | return x; |
| 418 | } | 420 | } |
| 419 | }; | 421 | }; |
| 420 | var list = S.get(); | 422 | const list = S.get(); |
| 421 | try expect(list.items.len == 0); | 423 | try expect(list.items.len == 0); |
| 422 | } | 424 | } |
| 423 | 425 | ||
| ... | @@ -434,11 +436,13 @@ test "implicit cast function to function ptr" { | ... | @@ -434,11 +436,13 @@ test "implicit cast function to function ptr" { |
| 434 | } | 436 | } |
| 435 | }; | 437 | }; |
| 436 | var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue; | 438 | var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue; |
| 439 | _ = &fnPtr1; | ||
| 437 | try expect(fnPtr1() == 123); | 440 | try expect(fnPtr1() == 123); |
| 438 | const S2 = struct { | 441 | const S2 = struct { |
| 439 | extern fn someFunctionThatReturnsAValue() c_int; | 442 | extern fn someFunctionThatReturnsAValue() c_int; |
| 440 | }; | 443 | }; |
| 441 | var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue; | 444 | var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue; |
| 445 | _ = &fnPtr2; | ||
| 442 | try expect(fnPtr2() == 123); | 446 | try expect(fnPtr2() == 123); |
| 443 | } | 447 | } |
| 444 | 448 | ||
| ... | @@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" { | ... | @@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" { |
| 588 | const bar = foo; | 592 | const bar = foo; |
| 589 | }; | 593 | }; |
| 590 | var a = &S.bar; | 594 | var a = &S.bar; |
| 595 | _ = &a; | ||
| 591 | try std.testing.expect(S.foo() == a()); | 596 | try std.testing.expect(S.foo() == a()); |
| 592 | } | 597 | } |
test/behavior/fn_in_struct_in_comptime.zig+1-2| ... | @@ -5,8 +5,7 @@ fn get_foo() fn (*u8) usize { | ... | @@ -5,8 +5,7 @@ fn get_foo() fn (*u8) usize { |
| 5 | comptime { | 5 | comptime { |
| 6 | return struct { | 6 | return struct { |
| 7 | fn func(ptr: *u8) usize { | 7 | fn func(ptr: *u8) usize { |
| 8 | var u = @intFromPtr(ptr); | 8 | return @intFromPtr(ptr); |
| 9 | return u; | ||
| 10 | } | 9 | } |
| 11 | }.func; | 10 | }.func; |
| 12 | } | 11 | } |
test/behavior/for.zig+13-6| ... | @@ -26,7 +26,7 @@ test "break from outer for loop" { | ... | @@ -26,7 +26,7 @@ test "break from outer for loop" { |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | fn testBreakOuter() !void { | 28 | fn testBreakOuter() !void { |
| 29 | var array = "aoeu"; | 29 | const array = "aoeu"; |
| 30 | var count: usize = 0; | 30 | var count: usize = 0; |
| 31 | outer: for (array) |_| { | 31 | outer: for (array) |_| { |
| 32 | for (array) |_| { | 32 | for (array) |_| { |
| ... | @@ -43,7 +43,7 @@ test "continue outer for loop" { | ... | @@ -43,7 +43,7 @@ test "continue outer for loop" { |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | fn testContinueOuter() !void { | 45 | fn testContinueOuter() !void { |
| 46 | var array = "aoeu"; | 46 | const array = "aoeu"; |
| 47 | var counter: usize = 0; | 47 | var counter: usize = 0; |
| 48 | outer: for (array) |_| { | 48 | outer: for (array) |_| { |
| 49 | for (array) |_| { | 49 | for (array) |_| { |
| ... | @@ -137,7 +137,7 @@ test "2 break statements and an else" { | ... | @@ -137,7 +137,7 @@ test "2 break statements and an else" { |
| 137 | fn entry(t: bool, f: bool) !void { | 137 | fn entry(t: bool, f: bool) !void { |
| 138 | var buf: [10]u8 = undefined; | 138 | var buf: [10]u8 = undefined; |
| 139 | var ok = false; | 139 | var ok = false; |
| 140 | ok = for (buf) |item| { | 140 | ok = for (&buf) |*item| { |
| 141 | _ = item; | 141 | _ = item; |
| 142 | if (f) break false; | 142 | if (f) break false; |
| 143 | if (t) break true; | 143 | if (t) break true; |
| ... | @@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" { | ... | @@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" { |
| 201 | 201 | ||
| 202 | const S = struct { | 202 | const S = struct { |
| 203 | fn doTheTest(slice: []const u8) !void { | 203 | fn doTheTest(slice: []const u8) !void { |
| 204 | var ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len]; | 204 | const ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len]; |
| 205 | for (ptr, 0..) |x, i| try expect(x == i + 1); | 205 | for (ptr, 0..) |x, i| try expect(x == i + 1); |
| 206 | for (ptr, 0..) |*x, i| try expect(x.* == i + 1); | 206 | for (ptr, 0..) |*x, i| try expect(x.* == i + 1); |
| 207 | } | 207 | } |
| ... | @@ -230,6 +230,7 @@ test "for loop with else branch" { | ... | @@ -230,6 +230,7 @@ test "for loop with else branch" { |
| 230 | 230 | ||
| 231 | { | 231 | { |
| 232 | var x = [_]u32{ 1, 2 }; | 232 | var x = [_]u32{ 1, 2 }; |
| 233 | _ = &x; | ||
| 233 | const q = for (x) |y| { | 234 | const q = for (x) |y| { |
| 234 | if ((y & 1) != 0) continue; | 235 | if ((y & 1) != 0) continue; |
| 235 | break y * 2; | 236 | break y * 2; |
| ... | @@ -238,6 +239,7 @@ test "for loop with else branch" { | ... | @@ -238,6 +239,7 @@ test "for loop with else branch" { |
| 238 | } | 239 | } |
| 239 | { | 240 | { |
| 240 | var x = [_]u32{ 1, 2 }; | 241 | var x = [_]u32{ 1, 2 }; |
| 242 | _ = &x; | ||
| 241 | const q = for (x) |y| { | 243 | const q = for (x) |y| { |
| 242 | if ((y & 1) != 0) continue; | 244 | if ((y & 1) != 0) continue; |
| 243 | break y * 2; | 245 | break y * 2; |
| ... | @@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" { | ... | @@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" { |
| 310 | 312 | ||
| 311 | const slice: []const u8 = "blah"; | 313 | const slice: []const u8 = "blah"; |
| 312 | var start: usize = 0; | 314 | var start: usize = 0; |
| 315 | _ = &start; | ||
| 313 | 316 | ||
| 314 | for (slice, start..4, 1..5) |a, b, c| { | 317 | for (slice, start..4, 1..5) |a, b, c| { |
| 315 | if (a == 'b') { | 318 | if (a == 'b') { |
| ... | @@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" { | ... | @@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" { |
| 394 | 397 | ||
| 395 | const comptime_slice = "hello"; | 398 | const comptime_slice = "hello"; |
| 396 | var runtime_i: usize = 3; | 399 | var runtime_i: usize = 3; |
| 400 | _ = &runtime_i; | ||
| 397 | 401 | ||
| 398 | const S = struct { | 402 | const S = struct { |
| 399 | var ok: usize = 0; | 403 | var ok: usize = 0; |
| ... | @@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" { | ... | @@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" { |
| 424 | 428 | ||
| 425 | var runtime_slice = "hello"; | 429 | var runtime_slice = "hello"; |
| 426 | var runtime_i: usize = 3; | 430 | var runtime_i: usize = 3; |
| 431 | _ = &runtime_i; | ||
| 427 | 432 | ||
| 428 | const S = struct { | 433 | const S = struct { |
| 429 | var ok: usize = 0; | 434 | var ok: usize = 0; |
| ... | @@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" { | ... | @@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" { |
| 484 | 489 | ||
| 485 | { | 490 | { |
| 486 | var cond = false; | 491 | var cond = false; |
| 487 | var opt = for (0..1) |_| { | 492 | _ = &cond; |
| 493 | const opt = for (0..1) |_| { | ||
| 488 | if (cond) break cond; | 494 | if (cond) break cond; |
| 489 | } else null; | 495 | } else null; |
| 490 | try expectEqual(@as(?bool, null), opt); | 496 | try expectEqual(@as(?bool, null), opt); |
| 491 | } | 497 | } |
| 492 | { | 498 | { |
| 493 | var cond = true; | 499 | var cond = true; |
| 494 | var opt = for (0..1) |_| { | 500 | _ = &cond; |
| 501 | const opt = for (0..1) |_| { | ||
| 495 | if (cond) break cond; | 502 | if (cond) break cond; |
| 496 | } else null; | 503 | } else null; |
| 497 | try expectEqual(@as(?bool, true), opt); | 504 | try expectEqual(@as(?bool, true), opt); |
test/behavior/generics.zig+2| ... | @@ -102,6 +102,7 @@ test "type constructed by comptime function call" { | ... | @@ -102,6 +102,7 @@ test "type constructed by comptime function call" { |
| 102 | 102 | ||
| 103 | fn SimpleList(comptime L: usize) type { | 103 | fn SimpleList(comptime L: usize) type { |
| 104 | var mutable_T = u8; | 104 | var mutable_T = u8; |
| 105 | _ = &mutable_T; | ||
| 105 | const T = mutable_T; | 106 | const T = mutable_T; |
| 106 | return struct { | 107 | return struct { |
| 107 | array: [L]T, | 108 | array: [L]T, |
| ... | @@ -238,6 +239,7 @@ test "function parameter is generic" { | ... | @@ -238,6 +239,7 @@ test "function parameter is generic" { |
| 238 | } | 239 | } |
| 239 | }; | 240 | }; |
| 240 | var rng: u32 = 2; | 241 | var rng: u32 = 2; |
| 242 | _ = &rng; | ||
| 241 | S.init(rng, S.fill); | 243 | S.init(rng, S.fill); |
| 242 | } | 244 | } |
| 243 | 245 |
test/behavior/if.zig+12-5| ... | @@ -61,6 +61,7 @@ test "unwrap mutable global var" { | ... | @@ -61,6 +61,7 @@ test "unwrap mutable global var" { |
| 61 | test "labeled break inside comptime if inside runtime if" { | 61 | test "labeled break inside comptime if inside runtime if" { |
| 62 | var answer: i32 = 0; | 62 | var answer: i32 = 0; |
| 63 | var c = true; | 63 | var c = true; |
| 64 | _ = &c; | ||
| 64 | if (c) { | 65 | if (c) { |
| 65 | answer = if (true) blk: { | 66 | answer = if (true) blk: { |
| 66 | break :blk @as(i32, 42); | 67 | break :blk @as(i32, 42); |
| ... | @@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" { | ... | @@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" { |
| 73 | const Num = enum { One, Two }; | 74 | const Num = enum { One, Two }; |
| 74 | 75 | ||
| 75 | var t = true; | 76 | var t = true; |
| 77 | _ = &t; | ||
| 76 | const x = if (t) Num.Two else unreachable; | 78 | const x = if (t) Num.Two else unreachable; |
| 77 | try expect(x == .Two); | 79 | try expect(x == .Two); |
| 78 | } | 80 | } |
| ... | @@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" { | ... | @@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" { |
| 103 | try expect(x == 2); | 105 | try expect(x == 2); |
| 104 | 106 | ||
| 105 | var b = true; | 107 | var b = true; |
| 108 | _ = &b; | ||
| 106 | const y: i32 = if (b) 1 else 2; | 109 | const y: i32 = if (b) 1 else 2; |
| 107 | try expect(y == 1); | 110 | try expect(y == 1); |
| 108 | } | 111 | } |
| ... | @@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" { | ... | @@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" { |
| 118 | 121 | ||
| 119 | var self: []const u8 = "abcdef"; | 122 | var self: []const u8 = "abcdef"; |
| 120 | var index: usize = 0; | 123 | var index: usize = 0; |
| 121 | var left_index = (index << 1) + 1; | 124 | _ = .{ &self, &index }; |
| 122 | var right_index = left_index + 1; | 125 | const left_index = (index << 1) + 1; |
| 123 | var left = if (left_index < self.len) self[left_index] else null; | 126 | const right_index = left_index + 1; |
| 124 | var right = if (right_index < self.len) self[right_index] else null; | 127 | const left = if (left_index < self.len) self[left_index] else null; |
| 128 | const right = if (right_index < self.len) self[right_index] else null; | ||
| 125 | try expect(left_index < self.len); | 129 | try expect(left_index < self.len); |
| 126 | try expect(right_index < self.len); | 130 | try expect(right_index < self.len); |
| 127 | try expect(left.? == 98); | 131 | try expect(left.? == 98); |
| ... | @@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti | ... | @@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti |
| 135 | 139 | ||
| 136 | const A = struct { b: u64, c: u64 }; | 140 | const A = struct { b: u64, c: u64 }; |
| 137 | var d: bool = true; | 141 | var d: bool = true; |
| 142 | _ = &d; | ||
| 138 | const e = if (d) A{ .b = 15, .c = 30 } else null; | 143 | const e = if (d) A{ .b = 15, .c = 30 } else null; |
| 139 | try expect(e != null); | 144 | try expect(e != null); |
| 140 | } | 145 | } |
| ... | @@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti | ... | @@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti |
| 142 | test "result location with inferred type ends up being pointer to comptime_int" { | 147 | test "result location with inferred type ends up being pointer to comptime_int" { |
| 143 | var a: ?u32 = 1234; | 148 | var a: ?u32 = 1234; |
| 144 | var b: u32 = 2000; | 149 | var b: u32 = 2000; |
| 145 | var c = if (a) |d| blk: { | 150 | _ = .{ &a, &b }; |
| 151 | const c = if (a) |d| blk: { | ||
| 146 | if (d < b) break :blk @as(u32, 1); | 152 | if (d < b) break :blk @as(u32, 1); |
| 147 | break :blk 0; | 153 | break :blk 0; |
| 148 | } else @as(u32, 0); | 154 | } else @as(u32, 0); |
| ... | @@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int" | ... | @@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int" |
| 152 | test "if-@as-if chain" { | 158 | test "if-@as-if chain" { |
| 153 | var fast = true; | 159 | var fast = true; |
| 154 | var very_fast = false; | 160 | var very_fast = false; |
| 161 | _ = .{ &fast, &very_fast }; | ||
| 155 | 162 | ||
| 156 | const num_frames = if (fast) | 163 | const num_frames = if (fast) |
| 157 | @as(u32, if (very_fast) 16 else 4) | 164 | @as(u32, if (very_fast) 16 else 4) |
test/behavior/inline_switch.zig+8| ... | @@ -22,6 +22,7 @@ test "inline prong ranges" { | ... | @@ -22,6 +22,7 @@ test "inline prong ranges" { |
| 22 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 22 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 23 | 23 | ||
| 24 | var x: usize = 0; | 24 | var x: usize = 0; |
| 25 | _ = &x; | ||
| 25 | switch (x) { | 26 | switch (x) { |
| 26 | inline 0...20, 24 => |item| { | 27 | inline 0...20, 24 => |item| { |
| 27 | if (item > 25) @compileError("bad"); | 28 | if (item > 25) @compileError("bad"); |
| ... | @@ -36,6 +37,7 @@ test "inline switch enums" { | ... | @@ -36,6 +37,7 @@ test "inline switch enums" { |
| 36 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 37 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 37 | 38 | ||
| 38 | var x: E = .a; | 39 | var x: E = .a; |
| 40 | _ = &x; | ||
| 39 | switch (x) { | 41 | switch (x) { |
| 40 | inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"), | 42 | inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"), |
| 41 | inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"), | 43 | inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"), |
| ... | @@ -49,6 +51,7 @@ test "inline switch unions" { | ... | @@ -49,6 +51,7 @@ test "inline switch unions" { |
| 49 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 51 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 50 | 52 | ||
| 51 | var x: U = .a; | 53 | var x: U = .a; |
| 54 | _ = &x; | ||
| 52 | switch (x) { | 55 | switch (x) { |
| 53 | inline .a, .b => |aorb, tag| { | 56 | inline .a, .b => |aorb, tag| { |
| 54 | if (tag == .a) { | 57 | if (tag == .a) { |
| ... | @@ -74,6 +77,7 @@ test "inline else bool" { | ... | @@ -74,6 +77,7 @@ test "inline else bool" { |
| 74 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 77 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 75 | 78 | ||
| 76 | var a = true; | 79 | var a = true; |
| 80 | _ = &a; | ||
| 77 | switch (a) { | 81 | switch (a) { |
| 78 | true => {}, | 82 | true => {}, |
| 79 | inline else => |val| if (val != false) @compileError("bad"), | 83 | inline else => |val| if (val != false) @compileError("bad"), |
| ... | @@ -86,6 +90,7 @@ test "inline else error" { | ... | @@ -86,6 +90,7 @@ test "inline else error" { |
| 86 | 90 | ||
| 87 | const Err = error{ a, b, c }; | 91 | const Err = error{ a, b, c }; |
| 88 | var a = Err.a; | 92 | var a = Err.a; |
| 93 | _ = &a; | ||
| 89 | switch (a) { | 94 | switch (a) { |
| 90 | error.a => {}, | 95 | error.a => {}, |
| 91 | inline else => |val| comptime if (val == error.a) @compileError("bad"), | 96 | inline else => |val| comptime if (val == error.a) @compileError("bad"), |
| ... | @@ -98,6 +103,7 @@ test "inline else enum" { | ... | @@ -98,6 +103,7 @@ test "inline else enum" { |
| 98 | 103 | ||
| 99 | const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 }; | 104 | const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 }; |
| 100 | var a: E2 = .a; | 105 | var a: E2 = .a; |
| 106 | _ = &a; | ||
| 101 | switch (a) { | 107 | switch (a) { |
| 102 | .a, .b => {}, | 108 | .a, .b => {}, |
| 103 | inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"), | 109 | inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"), |
| ... | @@ -109,6 +115,7 @@ test "inline else int with gaps" { | ... | @@ -109,6 +115,7 @@ test "inline else int with gaps" { |
| 109 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 115 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 110 | 116 | ||
| 111 | var a: u8 = 0; | 117 | var a: u8 = 0; |
| 118 | _ = &a; | ||
| 112 | switch (a) { | 119 | switch (a) { |
| 113 | 1...125, 128...254 => {}, | 120 | 1...125, 128...254 => {}, |
| 114 | inline else => |val| { | 121 | inline else => |val| { |
| ... | @@ -126,6 +133,7 @@ test "inline else int all values" { | ... | @@ -126,6 +133,7 @@ test "inline else int all values" { |
| 126 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 133 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 127 | 134 | ||
| 128 | var a: u2 = 0; | 135 | var a: u2 = 0; |
| 136 | _ = &a; | ||
| 129 | switch (a) { | 137 | switch (a) { |
| 130 | inline else => |val| { | 138 | inline else => |val| { |
| 131 | if (val != 0 and | 139 | if (val != 0 and |
test/behavior/int128.zig+3| ... | @@ -39,6 +39,7 @@ test "undefined 128 bit int" { | ... | @@ -39,6 +39,7 @@ test "undefined 128 bit int" { |
| 39 | 39 | ||
| 40 | var undef: u128 = undefined; | 40 | var undef: u128 = undefined; |
| 41 | var undef_signed: i128 = undefined; | 41 | var undef_signed: i128 = undefined; |
| 42 | _ = .{ &undef, &undef_signed }; | ||
| 42 | try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef); | 43 | try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef); |
| 43 | } | 44 | } |
| 44 | 45 | ||
| ... | @@ -73,6 +74,7 @@ test "truncate int128" { | ... | @@ -73,6 +74,7 @@ test "truncate int128" { |
| 73 | 74 | ||
| 74 | { | 75 | { |
| 75 | var buff: u128 = maxInt(u128); | 76 | var buff: u128 = maxInt(u128); |
| 77 | _ = &buff; | ||
| 76 | try expect(@as(u64, @truncate(buff)) == maxInt(u64)); | 78 | try expect(@as(u64, @truncate(buff)) == maxInt(u64)); |
| 77 | try expect(@as(u90, @truncate(buff)) == maxInt(u90)); | 79 | try expect(@as(u90, @truncate(buff)) == maxInt(u90)); |
| 78 | try expect(@as(u128, @truncate(buff)) == maxInt(u128)); | 80 | try expect(@as(u128, @truncate(buff)) == maxInt(u128)); |
| ... | @@ -80,6 +82,7 @@ test "truncate int128" { | ... | @@ -80,6 +82,7 @@ test "truncate int128" { |
| 80 | 82 | ||
| 81 | { | 83 | { |
| 82 | var buff: i128 = maxInt(i128); | 84 | var buff: i128 = maxInt(i128); |
| 85 | _ = &buff; | ||
| 83 | try expect(@as(i64, @truncate(buff)) == -1); | 86 | try expect(@as(i64, @truncate(buff)) == -1); |
| 84 | try expect(@as(i90, @truncate(buff)) == -1); | 87 | try expect(@as(i90, @truncate(buff)) == -1); |
| 85 | try expect(@as(i128, @truncate(buff)) == maxInt(i128)); | 88 | try expect(@as(i128, @truncate(buff)) == maxInt(i128)); |
test/behavior/int_comparison_elision.zig+1| ... | @@ -30,6 +30,7 @@ fn testIntEdges(comptime T: type) void { | ... | @@ -30,6 +30,7 @@ fn testIntEdges(comptime T: type) void { |
| 30 | const max = maxInt(T); | 30 | const max = maxInt(T); |
| 31 | 31 | ||
| 32 | var runtime_val: T = undefined; | 32 | var runtime_val: T = undefined; |
| 33 | _ = &runtime_val; | ||
| 33 | 34 | ||
| 34 | if (min > runtime_val) @compileError("analyzed impossible branch"); | 35 | if (min > runtime_val) @compileError("analyzed impossible branch"); |
| 35 | if (min <= runtime_val) {} else @compileError("analyzed impossible branch"); | 36 | if (min <= runtime_val) {} else @compileError("analyzed impossible branch"); |
test/behavior/int_div.zig+2| ... | @@ -100,11 +100,13 @@ test "large integer division" { | ... | @@ -100,11 +100,13 @@ test "large integer division" { |
| 100 | { | 100 | { |
| 101 | var numerator: u256 = 99999999999999999997315645440; | 101 | var numerator: u256 = 99999999999999999997315645440; |
| 102 | var divisor: u256 = 10000000000000000000000000000; | 102 | var divisor: u256 = 10000000000000000000000000000; |
| 103 | _ = .{ &numerator, &divisor }; | ||
| 103 | try expect(numerator / divisor == 9); | 104 | try expect(numerator / divisor == 9); |
| 104 | } | 105 | } |
| 105 | { | 106 | { |
| 106 | var numerator: u256 = 99999999999999999999000000000000000000000; | 107 | var numerator: u256 = 99999999999999999999000000000000000000000; |
| 107 | var divisor: u256 = 10000000000000000000000000000000000000000; | 108 | var divisor: u256 = 10000000000000000000000000000000000000000; |
| 109 | _ = .{ &numerator, &divisor }; | ||
| 108 | try expect(numerator / divisor == 9); | 110 | try expect(numerator / divisor == 9); |
| 109 | } | 111 | } |
| 110 | } | 112 | } |
test/behavior/math.zig+53-5| ... | @@ -624,7 +624,8 @@ const DivResult = struct { | ... | @@ -624,7 +624,8 @@ const DivResult = struct { |
| 624 | 624 | ||
| 625 | test "bit shift a u1" { | 625 | test "bit shift a u1" { |
| 626 | var x: u1 = 1; | 626 | var x: u1 = 1; |
| 627 | var y = x << 0; | 627 | _ = &x; |
| 628 | const y = x << 0; | ||
| 628 | try expect(y == 1); | 629 | try expect(y == 1); |
| 629 | } | 630 | } |
| 630 | 631 | ||
| ... | @@ -692,7 +693,8 @@ test "128-bit multiplication" { | ... | @@ -692,7 +693,8 @@ test "128-bit multiplication" { |
| 692 | { | 693 | { |
| 693 | var a: u128 = 0xffffffffffffffff; | 694 | var a: u128 = 0xffffffffffffffff; |
| 694 | var b: u128 = 100; | 695 | var b: u128 = 100; |
| 695 | var c = a * b; | 696 | _ = .{ &a, &b }; |
| 697 | const c = a * b; | ||
| 696 | try expect(c == 0x63ffffffffffffff9c); | 698 | try expect(c == 0x63ffffffffffffff9c); |
| 697 | } | 699 | } |
| 698 | } | 700 | } |
| ... | @@ -704,18 +706,21 @@ test "@addWithOverflow" { | ... | @@ -704,18 +706,21 @@ test "@addWithOverflow" { |
| 704 | 706 | ||
| 705 | { | 707 | { |
| 706 | var a: u8 = 250; | 708 | var a: u8 = 250; |
| 709 | _ = &a; | ||
| 707 | const ov = @addWithOverflow(a, 100); | 710 | const ov = @addWithOverflow(a, 100); |
| 708 | try expect(ov[0] == 94); | 711 | try expect(ov[0] == 94); |
| 709 | try expect(ov[1] == 1); | 712 | try expect(ov[1] == 1); |
| 710 | } | 713 | } |
| 711 | { | 714 | { |
| 712 | var a: u8 = 100; | 715 | var a: u8 = 100; |
| 716 | _ = &a; | ||
| 713 | const ov = @addWithOverflow(a, 150); | 717 | const ov = @addWithOverflow(a, 150); |
| 714 | try expect(ov[0] == 250); | 718 | try expect(ov[0] == 250); |
| 715 | try expect(ov[1] == 0); | 719 | try expect(ov[1] == 0); |
| 716 | } | 720 | } |
| 717 | { | 721 | { |
| 718 | var a: u8 = 200; | 722 | var a: u8 = 200; |
| 723 | _ = &a; | ||
| 719 | var b: u8 = 99; | 724 | var b: u8 = 99; |
| 720 | var ov = @addWithOverflow(a, b); | 725 | var ov = @addWithOverflow(a, b); |
| 721 | try expect(ov[0] == 43); | 726 | try expect(ov[0] == 43); |
| ... | @@ -729,6 +734,7 @@ test "@addWithOverflow" { | ... | @@ -729,6 +734,7 @@ test "@addWithOverflow" { |
| 729 | { | 734 | { |
| 730 | var a: usize = 6; | 735 | var a: usize = 6; |
| 731 | var b: usize = 6; | 736 | var b: usize = 6; |
| 737 | _ = .{ &a, &b }; | ||
| 732 | const ov = @addWithOverflow(a, b); | 738 | const ov = @addWithOverflow(a, b); |
| 733 | try expect(ov[0] == 12); | 739 | try expect(ov[0] == 12); |
| 734 | try expect(ov[1] == 0); | 740 | try expect(ov[1] == 0); |
| ... | @@ -737,6 +743,7 @@ test "@addWithOverflow" { | ... | @@ -737,6 +743,7 @@ test "@addWithOverflow" { |
| 737 | { | 743 | { |
| 738 | var a: isize = -6; | 744 | var a: isize = -6; |
| 739 | var b: isize = -6; | 745 | var b: isize = -6; |
| 746 | _ = .{ &a, &b }; | ||
| 740 | const ov = @addWithOverflow(a, b); | 747 | const ov = @addWithOverflow(a, b); |
| 741 | try expect(ov[0] == -12); | 748 | try expect(ov[0] == -12); |
| 742 | try expect(ov[1] == 0); | 749 | try expect(ov[1] == 0); |
| ... | @@ -772,18 +779,21 @@ test "basic @mulWithOverflow" { | ... | @@ -772,18 +779,21 @@ test "basic @mulWithOverflow" { |
| 772 | 779 | ||
| 773 | { | 780 | { |
| 774 | var a: u8 = 86; | 781 | var a: u8 = 86; |
| 782 | _ = &a; | ||
| 775 | const ov = @mulWithOverflow(a, 3); | 783 | const ov = @mulWithOverflow(a, 3); |
| 776 | try expect(ov[0] == 2); | 784 | try expect(ov[0] == 2); |
| 777 | try expect(ov[1] == 1); | 785 | try expect(ov[1] == 1); |
| 778 | } | 786 | } |
| 779 | { | 787 | { |
| 780 | var a: u8 = 85; | 788 | var a: u8 = 85; |
| 789 | _ = &a; | ||
| 781 | const ov = @mulWithOverflow(a, 3); | 790 | const ov = @mulWithOverflow(a, 3); |
| 782 | try expect(ov[0] == 255); | 791 | try expect(ov[0] == 255); |
| 783 | try expect(ov[1] == 0); | 792 | try expect(ov[1] == 0); |
| 784 | } | 793 | } |
| 785 | 794 | ||
| 786 | var a: u8 = 123; | 795 | var a: u8 = 123; |
| 796 | _ = &a; | ||
| 787 | var b: u8 = 2; | 797 | var b: u8 = 2; |
| 788 | var ov = @mulWithOverflow(a, b); | 798 | var ov = @mulWithOverflow(a, b); |
| 789 | try expect(ov[0] == 246); | 799 | try expect(ov[0] == 246); |
| ... | @@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" { |
| 802 | 812 | ||
| 803 | { | 813 | { |
| 804 | var a: u5 = 3; | 814 | var a: u5 = 3; |
| 815 | _ = &a; | ||
| 805 | var b: u5 = 10; | 816 | var b: u5 = 10; |
| 806 | var ov = @mulWithOverflow(a, b); | 817 | var ov = @mulWithOverflow(a, b); |
| 807 | try expect(ov[0] == 30); | 818 | try expect(ov[0] == 30); |
| ... | @@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" { |
| 815 | 826 | ||
| 816 | { | 827 | { |
| 817 | var a: i5 = 3; | 828 | var a: i5 = 3; |
| 829 | _ = &a; | ||
| 818 | var b: i5 = -5; | 830 | var b: i5 = -5; |
| 819 | var ov = @mulWithOverflow(a, b); | 831 | var ov = @mulWithOverflow(a, b); |
| 820 | try expect(ov[0] == -15); | 832 | try expect(ov[0] == -15); |
| ... | @@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" { |
| 828 | 840 | ||
| 829 | { | 841 | { |
| 830 | var a: u8 = 3; | 842 | var a: u8 = 3; |
| 843 | _ = &a; | ||
| 831 | var b: u8 = 85; | 844 | var b: u8 = 85; |
| 832 | 845 | ||
| 833 | var ov = @mulWithOverflow(a, b); | 846 | var ov = @mulWithOverflow(a, b); |
| ... | @@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" { |
| 842 | 855 | ||
| 843 | { | 856 | { |
| 844 | var a: i8 = 3; | 857 | var a: i8 = 3; |
| 858 | _ = &a; | ||
| 845 | var b: i8 = -42; | 859 | var b: i8 = -42; |
| 846 | var ov = @mulWithOverflow(a, b); | 860 | var ov = @mulWithOverflow(a, b); |
| 847 | try expect(ov[0] == -126); | 861 | try expect(ov[0] == -126); |
| ... | @@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" { |
| 855 | 869 | ||
| 856 | { | 870 | { |
| 857 | var a: u14 = 3; | 871 | var a: u14 = 3; |
| 872 | _ = &a; | ||
| 858 | var b: u14 = 0x1555; | 873 | var b: u14 = 0x1555; |
| 859 | var ov = @mulWithOverflow(a, b); | 874 | var ov = @mulWithOverflow(a, b); |
| 860 | try expect(ov[0] == 0x3fff); | 875 | try expect(ov[0] == 0x3fff); |
| ... | @@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" { |
| 868 | 883 | ||
| 869 | { | 884 | { |
| 870 | var a: i14 = 3; | 885 | var a: i14 = 3; |
| 886 | _ = &a; | ||
| 871 | var b: i14 = -0xaaa; | 887 | var b: i14 = -0xaaa; |
| 872 | var ov = @mulWithOverflow(a, b); | 888 | var ov = @mulWithOverflow(a, b); |
| 873 | try expect(ov[0] == -0x1ffe); | 889 | try expect(ov[0] == -0x1ffe); |
| ... | @@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" { |
| 880 | 896 | ||
| 881 | { | 897 | { |
| 882 | var a: u16 = 3; | 898 | var a: u16 = 3; |
| 899 | _ = &a; | ||
| 883 | var b: u16 = 0x5555; | 900 | var b: u16 = 0x5555; |
| 884 | var ov = @mulWithOverflow(a, b); | 901 | var ov = @mulWithOverflow(a, b); |
| 885 | try expect(ov[0] == 0xffff); | 902 | try expect(ov[0] == 0xffff); |
| ... | @@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" { |
| 893 | 910 | ||
| 894 | { | 911 | { |
| 895 | var a: i16 = 3; | 912 | var a: i16 = 3; |
| 913 | _ = &a; | ||
| 896 | var b: i16 = -0x2aaa; | 914 | var b: i16 = -0x2aaa; |
| 897 | var ov = @mulWithOverflow(a, b); | 915 | var ov = @mulWithOverflow(a, b); |
| 898 | try expect(ov[0] == -0x7ffe); | 916 | try expect(ov[0] == -0x7ffe); |
| ... | @@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" { |
| 906 | 924 | ||
| 907 | { | 925 | { |
| 908 | var a: u30 = 3; | 926 | var a: u30 = 3; |
| 927 | _ = &a; | ||
| 909 | var b: u30 = 0x15555555; | 928 | var b: u30 = 0x15555555; |
| 910 | var ov = @mulWithOverflow(a, b); | 929 | var ov = @mulWithOverflow(a, b); |
| 911 | try expect(ov[0] == 0x3fffffff); | 930 | try expect(ov[0] == 0x3fffffff); |
| ... | @@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" { |
| 919 | 938 | ||
| 920 | { | 939 | { |
| 921 | var a: i30 = 3; | 940 | var a: i30 = 3; |
| 941 | _ = &a; | ||
| 922 | var b: i30 = -0xaaaaaaa; | 942 | var b: i30 = -0xaaaaaaa; |
| 923 | var ov = @mulWithOverflow(a, b); | 943 | var ov = @mulWithOverflow(a, b); |
| 924 | try expect(ov[0] == -0x1ffffffe); | 944 | try expect(ov[0] == -0x1ffffffe); |
| ... | @@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" { |
| 932 | 952 | ||
| 933 | { | 953 | { |
| 934 | var a: u32 = 3; | 954 | var a: u32 = 3; |
| 955 | _ = &a; | ||
| 935 | var b: u32 = 0x55555555; | 956 | var b: u32 = 0x55555555; |
| 936 | var ov = @mulWithOverflow(a, b); | 957 | var ov = @mulWithOverflow(a, b); |
| 937 | try expect(ov[0] == 0xffffffff); | 958 | try expect(ov[0] == 0xffffffff); |
| ... | @@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" { | ... | @@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" { |
| 945 | 966 | ||
| 946 | { | 967 | { |
| 947 | var a: i32 = 3; | 968 | var a: i32 = 3; |
| 969 | _ = &a; | ||
| 948 | var b: i32 = -0x2aaaaaaa; | 970 | var b: i32 = -0x2aaaaaaa; |
| 949 | var ov = @mulWithOverflow(a, b); | 971 | var ov = @mulWithOverflow(a, b); |
| 950 | try expect(ov[0] == -0x7ffffffe); | 972 | try expect(ov[0] == -0x7ffffffe); |
| ... | @@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" { | ... | @@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" { |
| 967 | 989 | ||
| 968 | { | 990 | { |
| 969 | var a: u62 = 3; | 991 | var a: u62 = 3; |
| 992 | _ = &a; | ||
| 970 | var b: u62 = 0x1555555555555555; | 993 | var b: u62 = 0x1555555555555555; |
| 971 | var ov = @mulWithOverflow(a, b); | 994 | var ov = @mulWithOverflow(a, b); |
| 972 | try expect(ov[0] == 0x3fffffffffffffff); | 995 | try expect(ov[0] == 0x3fffffffffffffff); |
| ... | @@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" { | ... | @@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" { |
| 980 | 1003 | ||
| 981 | { | 1004 | { |
| 982 | var a: i62 = 3; | 1005 | var a: i62 = 3; |
| 1006 | _ = &a; | ||
| 983 | var b: i62 = -0xaaaaaaaaaaaaaaa; | 1007 | var b: i62 = -0xaaaaaaaaaaaaaaa; |
| 984 | var ov = @mulWithOverflow(a, b); | 1008 | var ov = @mulWithOverflow(a, b); |
| 985 | try expect(ov[0] == -0x1ffffffffffffffe); | 1009 | try expect(ov[0] == -0x1ffffffffffffffe); |
| ... | @@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" { | ... | @@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" { |
| 993 | 1017 | ||
| 994 | { | 1018 | { |
| 995 | var a: u64 = 3; | 1019 | var a: u64 = 3; |
| 1020 | _ = &a; | ||
| 996 | var b: u64 = 0x5555555555555555; | 1021 | var b: u64 = 0x5555555555555555; |
| 997 | var ov = @mulWithOverflow(a, b); | 1022 | var ov = @mulWithOverflow(a, b); |
| 998 | try expect(ov[0] == 0xffffffffffffffff); | 1023 | try expect(ov[0] == 0xffffffffffffffff); |
| ... | @@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" { | ... | @@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" { |
| 1006 | 1031 | ||
| 1007 | { | 1032 | { |
| 1008 | var a: i64 = 3; | 1033 | var a: i64 = 3; |
| 1034 | _ = &a; | ||
| 1009 | var b: i64 = -0x2aaaaaaaaaaaaaaa; | 1035 | var b: i64 = -0x2aaaaaaaaaaaaaaa; |
| 1010 | var ov = @mulWithOverflow(a, b); | 1036 | var ov = @mulWithOverflow(a, b); |
| 1011 | try expect(ov[0] == -0x7ffffffffffffffe); | 1037 | try expect(ov[0] == -0x7ffffffffffffffe); |
| ... | @@ -1025,12 +1051,14 @@ test "@subWithOverflow" { | ... | @@ -1025,12 +1051,14 @@ test "@subWithOverflow" { |
| 1025 | 1051 | ||
| 1026 | { | 1052 | { |
| 1027 | var a: u8 = 1; | 1053 | var a: u8 = 1; |
| 1054 | _ = &a; | ||
| 1028 | const ov = @subWithOverflow(a, 2); | 1055 | const ov = @subWithOverflow(a, 2); |
| 1029 | try expect(ov[0] == 255); | 1056 | try expect(ov[0] == 255); |
| 1030 | try expect(ov[1] == 1); | 1057 | try expect(ov[1] == 1); |
| 1031 | } | 1058 | } |
| 1032 | { | 1059 | { |
| 1033 | var a: u8 = 1; | 1060 | var a: u8 = 1; |
| 1061 | _ = &a; | ||
| 1034 | const ov = @subWithOverflow(a, 1); | 1062 | const ov = @subWithOverflow(a, 1); |
| 1035 | try expect(ov[0] == 0); | 1063 | try expect(ov[0] == 0); |
| 1036 | try expect(ov[1] == 0); | 1064 | try expect(ov[1] == 0); |
| ... | @@ -1038,6 +1066,7 @@ test "@subWithOverflow" { | ... | @@ -1038,6 +1066,7 @@ test "@subWithOverflow" { |
| 1038 | 1066 | ||
| 1039 | { | 1067 | { |
| 1040 | var a: u8 = 1; | 1068 | var a: u8 = 1; |
| 1069 | _ = &a; | ||
| 1041 | var b: u8 = 2; | 1070 | var b: u8 = 2; |
| 1042 | var ov = @subWithOverflow(a, b); | 1071 | var ov = @subWithOverflow(a, b); |
| 1043 | try expect(ov[0] == 255); | 1072 | try expect(ov[0] == 255); |
| ... | @@ -1051,6 +1080,7 @@ test "@subWithOverflow" { | ... | @@ -1051,6 +1080,7 @@ test "@subWithOverflow" { |
| 1051 | { | 1080 | { |
| 1052 | var a: usize = 6; | 1081 | var a: usize = 6; |
| 1053 | var b: usize = 6; | 1082 | var b: usize = 6; |
| 1083 | _ = .{ &a, &b }; | ||
| 1054 | const ov = @subWithOverflow(a, b); | 1084 | const ov = @subWithOverflow(a, b); |
| 1055 | try expect(ov[0] == 0); | 1085 | try expect(ov[0] == 0); |
| 1056 | try expect(ov[1] == 0); | 1086 | try expect(ov[1] == 0); |
| ... | @@ -1059,6 +1089,7 @@ test "@subWithOverflow" { | ... | @@ -1059,6 +1089,7 @@ test "@subWithOverflow" { |
| 1059 | { | 1089 | { |
| 1060 | var a: isize = -6; | 1090 | var a: isize = -6; |
| 1061 | var b: isize = -6; | 1091 | var b: isize = -6; |
| 1092 | _ = .{ &a, &b }; | ||
| 1062 | const ov = @subWithOverflow(a, b); | 1093 | const ov = @subWithOverflow(a, b); |
| 1063 | try expect(ov[0] == 0); | 1094 | try expect(ov[0] == 0); |
| 1064 | try expect(ov[1] == 0); | 1095 | try expect(ov[1] == 0); |
| ... | @@ -1072,6 +1103,7 @@ test "@shlWithOverflow" { | ... | @@ -1072,6 +1103,7 @@ test "@shlWithOverflow" { |
| 1072 | 1103 | ||
| 1073 | { | 1104 | { |
| 1074 | var a: u4 = 2; | 1105 | var a: u4 = 2; |
| 1106 | _ = &a; | ||
| 1075 | var b: u2 = 1; | 1107 | var b: u2 = 1; |
| 1076 | var ov = @shlWithOverflow(a, b); | 1108 | var ov = @shlWithOverflow(a, b); |
| 1077 | try expect(ov[0] == 4); | 1109 | try expect(ov[0] == 4); |
| ... | @@ -1085,6 +1117,7 @@ test "@shlWithOverflow" { | ... | @@ -1085,6 +1117,7 @@ test "@shlWithOverflow" { |
| 1085 | 1117 | ||
| 1086 | { | 1118 | { |
| 1087 | var a: i9 = 127; | 1119 | var a: i9 = 127; |
| 1120 | _ = &a; | ||
| 1088 | var b: u4 = 1; | 1121 | var b: u4 = 1; |
| 1089 | var ov = @shlWithOverflow(a, b); | 1122 | var ov = @shlWithOverflow(a, b); |
| 1090 | try expect(ov[0] == 254); | 1123 | try expect(ov[0] == 254); |
| ... | @@ -1108,6 +1141,7 @@ test "@shlWithOverflow" { | ... | @@ -1108,6 +1141,7 @@ test "@shlWithOverflow" { |
| 1108 | } | 1141 | } |
| 1109 | { | 1142 | { |
| 1110 | var a: u16 = 0b0000_0000_0000_0011; | 1143 | var a: u16 = 0b0000_0000_0000_0011; |
| 1144 | _ = &a; | ||
| 1111 | var b: u4 = 15; | 1145 | var b: u4 = 15; |
| 1112 | var ov = @shlWithOverflow(a, b); | 1146 | var ov = @shlWithOverflow(a, b); |
| 1113 | try expect(ov[0] == 0b1000_0000_0000_0000); | 1147 | try expect(ov[0] == 0b1000_0000_0000_0000); |
| ... | @@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" { | ... | @@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" { |
| 1124 | 1158 | ||
| 1125 | { | 1159 | { |
| 1126 | var a: u0 = 0; | 1160 | var a: u0 = 0; |
| 1161 | _ = &a; | ||
| 1127 | const ov = @addWithOverflow(a, 0); | 1162 | const ov = @addWithOverflow(a, 0); |
| 1128 | try expect(ov[1] == 0); | 1163 | try expect(ov[1] == 0); |
| 1129 | try expect(ov[1] == 0); | 1164 | try expect(ov[1] == 0); |
| 1130 | } | 1165 | } |
| 1131 | { | 1166 | { |
| 1132 | var a: u0 = 0; | 1167 | var a: u0 = 0; |
| 1168 | _ = &a; | ||
| 1133 | const ov = @subWithOverflow(a, 0); | 1169 | const ov = @subWithOverflow(a, 0); |
| 1134 | try expect(ov[1] == 0); | 1170 | try expect(ov[1] == 0); |
| 1135 | try expect(ov[1] == 0); | 1171 | try expect(ov[1] == 0); |
| 1136 | } | 1172 | } |
| 1137 | { | 1173 | { |
| 1138 | var a: u0 = 0; | 1174 | var a: u0 = 0; |
| 1175 | _ = &a; | ||
| 1139 | const ov = @mulWithOverflow(a, 0); | 1176 | const ov = @mulWithOverflow(a, 0); |
| 1140 | try expect(ov[1] == 0); | 1177 | try expect(ov[1] == 0); |
| 1141 | try expect(ov[1] == 0); | 1178 | try expect(ov[1] == 0); |
| 1142 | } | 1179 | } |
| 1143 | { | 1180 | { |
| 1144 | var a: u0 = 0; | 1181 | var a: u0 = 0; |
| 1182 | _ = &a; | ||
| 1145 | const ov = @shlWithOverflow(a, 0); | 1183 | const ov = @shlWithOverflow(a, 0); |
| 1146 | try expect(ov[1] == 0); | 1184 | try expect(ov[1] == 0); |
| 1147 | try expect(ov[1] == 0); | 1185 | try expect(ov[1] == 0); |
| ... | @@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and | ... | @@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and |
| 1157 | try expect(-6 % 3 == 0); | 1195 | try expect(-6 % 3 == 0); |
| 1158 | 1196 | ||
| 1159 | var undef: i32 = undefined; | 1197 | var undef: i32 = undefined; |
| 1198 | _ = &undef; | ||
| 1160 | if (0 % undef != 0) { | 1199 | if (0 % undef != 0) { |
| 1161 | @compileError("0 as numerator should return comptime zero independent of denominator"); | 1200 | @compileError("0 as numerator should return comptime zero independent of denominator"); |
| 1162 | } | 1201 | } |
| ... | @@ -1183,18 +1222,22 @@ test "quad hex float literal parsing accurate" { | ... | @@ -1183,18 +1222,22 @@ test "quad hex float literal parsing accurate" { |
| 1183 | fn doTheTest() !void { | 1222 | fn doTheTest() !void { |
| 1184 | { | 1223 | { |
| 1185 | var f: f128 = 0x1.2eab345678439abcdefea56782346p+5; | 1224 | var f: f128 = 0x1.2eab345678439abcdefea56782346p+5; |
| 1225 | _ = &f; | ||
| 1186 | try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234); | 1226 | try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234); |
| 1187 | } | 1227 | } |
| 1188 | { | 1228 | { |
| 1189 | var f: f128 = 0x1.edcb34a235253948765432134674fp-1; | 1229 | var f: f128 = 0x1.edcb34a235253948765432134674fp-1; |
| 1230 | _ = &f; | ||
| 1190 | try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even | 1231 | try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even |
| 1191 | } | 1232 | } |
| 1192 | { | 1233 | { |
| 1193 | var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50; | 1234 | var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50; |
| 1235 | _ = &f; | ||
| 1194 | try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50); | 1236 | try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50); |
| 1195 | } | 1237 | } |
| 1196 | { | 1238 | { |
| 1197 | var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9; | 1239 | var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9; |
| 1240 | _ = &f; | ||
| 1198 | try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568); | 1241 | try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568); |
| 1199 | } | 1242 | } |
| 1200 | const exp2ft = [_]f64{ | 1243 | const exp2ft = [_]f64{ |
| ... | @@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" { | ... | @@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" { |
| 1294 | fn doTheTest() !void { | 1337 | fn doTheTest() !void { |
| 1295 | var x: u0 = 0; | 1338 | var x: u0 = 0; |
| 1296 | var y: u0 = 0; | 1339 | var y: u0 = 0; |
| 1340 | _ = .{ &x, &y }; | ||
| 1297 | try expectEqual(@as(u0, 0), x << 0); | 1341 | try expectEqual(@as(u0, 0), x << 0); |
| 1298 | try expectEqual(@as(u0, 0), x >> 0); | 1342 | try expectEqual(@as(u0, 0), x >> 0); |
| 1299 | try expectEqual(@as(u0, 0), x << y); | 1343 | try expectEqual(@as(u0, 0), x << y); |
| ... | @@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" { | ... | @@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" { |
| 1310 | 1354 | ||
| 1311 | test "comptime float rem int" { | 1355 | test "comptime float rem int" { |
| 1312 | comptime { | 1356 | comptime { |
| 1313 | var x = @as(f32, 1) % 2; | 1357 | const x = @as(f32, 1) % 2; |
| 1314 | try expect(x == 1.0); | 1358 | try expect(x == 1.0); |
| 1315 | } | 1359 | } |
| 1316 | } | 1360 | } |
| ... | @@ -1511,7 +1555,8 @@ test "vector integer addition" { | ... | @@ -1511,7 +1555,8 @@ test "vector integer addition" { |
| 1511 | fn doTheTest() !void { | 1555 | fn doTheTest() !void { |
| 1512 | var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; | 1556 | var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; |
| 1513 | var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; | 1557 | var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; |
| 1514 | var result = a + b; | 1558 | _ = .{ &a, &b }; |
| 1559 | const result = a + b; | ||
| 1515 | var result_array: [4]i32 = result; | 1560 | var result_array: [4]i32 = result; |
| 1516 | const expected = [_]i32{ 6, 8, 10, 12 }; | 1561 | const expected = [_]i32{ 6, 8, 10, 12 }; |
| 1517 | try expectEqualSlices(i32, &expected, &result_array); | 1562 | try expectEqualSlices(i32, &expected, &result_array); |
| ... | @@ -1552,6 +1597,7 @@ test "NaN comparison f80" { | ... | @@ -1552,6 +1597,7 @@ test "NaN comparison f80" { |
| 1552 | fn testNanEqNan(comptime F: type) !void { | 1597 | fn testNanEqNan(comptime F: type) !void { |
| 1553 | var nan1 = math.nan(F); | 1598 | var nan1 = math.nan(F); |
| 1554 | var nan2 = math.nan(F); | 1599 | var nan2 = math.nan(F); |
| 1600 | _ = .{ &nan1, &nan2 }; | ||
| 1555 | try expect(nan1 != nan2); | 1601 | try expect(nan1 != nan2); |
| 1556 | try expect(!(nan1 == nan2)); | 1602 | try expect(!(nan1 == nan2)); |
| 1557 | try expect(!(nan1 > nan2)); | 1603 | try expect(!(nan1 > nan2)); |
| ... | @@ -1571,6 +1617,7 @@ test "vector comparison" { | ... | @@ -1571,6 +1617,7 @@ test "vector comparison" { |
| 1571 | fn doTheTest() !void { | 1617 | fn doTheTest() !void { |
| 1572 | var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 }; | 1618 | var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 }; |
| 1573 | var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 }; | 1619 | var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 }; |
| 1620 | _ = .{ &a, &b }; | ||
| 1574 | try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false })); | 1621 | try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false })); |
| 1575 | try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false })); | 1622 | try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false })); |
| 1576 | try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false })); | 1623 | try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false })); |
| ... | @@ -1609,7 +1656,8 @@ test "signed zeros are represented properly" { | ... | @@ -1609,7 +1656,8 @@ test "signed zeros are represented properly" { |
| 1609 | fn testOne(comptime T: type) !void { | 1656 | fn testOne(comptime T: type) !void { |
| 1610 | const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); | 1657 | const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); |
| 1611 | var as_fp_val = -@as(T, 0.0); | 1658 | var as_fp_val = -@as(T, 0.0); |
| 1612 | var as_uint_val = @as(ST, @bitCast(as_fp_val)); | 1659 | _ = &as_fp_val; |
| 1660 | const as_uint_val: ST = @bitCast(as_fp_val); | ||
| 1613 | // Ensure the sign bit is set. | 1661 | // Ensure the sign bit is set. |
| 1614 | try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1); | 1662 | try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1); |
| 1615 | } | 1663 | } |
test/behavior/maximum_minimum.zig+23-6| ... | @@ -15,6 +15,7 @@ test "@max" { | ... | @@ -15,6 +15,7 @@ test "@max" { |
| 15 | var x: i32 = 10; | 15 | var x: i32 = 10; |
| 16 | var y: f32 = 0.68; | 16 | var y: f32 = 0.68; |
| 17 | var nan: f32 = std.math.nan(f32); | 17 | var nan: f32 = std.math.nan(f32); |
| 18 | _ = .{ &x, &y, &nan }; | ||
| 18 | try expect(@as(i32, 10) == @max(@as(i32, -3), x)); | 19 | try expect(@as(i32, 10) == @max(@as(i32, -3), x)); |
| 19 | try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y)); | 20 | try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y)); |
| 20 | try expect(y == @max(nan, y)); | 21 | try expect(y == @max(nan, y)); |
| ... | @@ -38,17 +39,20 @@ test "@max on vectors" { | ... | @@ -38,17 +39,20 @@ test "@max on vectors" { |
| 38 | fn doTheTest() !void { | 39 | fn doTheTest() !void { |
| 39 | var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; | 40 | var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 40 | var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; | 41 | var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 41 | var x = @max(a, b); | 42 | const x = @max(a, b); |
| 43 | _ = .{ &a, &b }; | ||
| 42 | try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 })); | 44 | try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 })); |
| 43 | 45 | ||
| 44 | var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; | 46 | var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; |
| 45 | var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; | 47 | var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; |
| 46 | var y = @max(c, d); | 48 | const y = @max(c, d); |
| 49 | _ = .{ &c, &d }; | ||
| 47 | try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 })); | 50 | try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 })); |
| 48 | 51 | ||
| 49 | var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; | 52 | var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; |
| 50 | var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; | 53 | var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; |
| 51 | var z = @max(e, f); | 54 | const z = @max(e, f); |
| 55 | _ = .{ &e, &f }; | ||
| 52 | try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); | 56 | try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); |
| 53 | } | 57 | } |
| 54 | }; | 58 | }; |
| ... | @@ -66,6 +70,7 @@ test "@min" { | ... | @@ -66,6 +70,7 @@ test "@min" { |
| 66 | var x: i32 = 10; | 70 | var x: i32 = 10; |
| 67 | var y: f32 = 0.68; | 71 | var y: f32 = 0.68; |
| 68 | var nan: f32 = std.math.nan(f32); | 72 | var nan: f32 = std.math.nan(f32); |
| 73 | _ = .{ &x, &y, &nan }; | ||
| 69 | try expect(@as(i32, -3) == @min(@as(i32, -3), x)); | 74 | try expect(@as(i32, -3) == @min(@as(i32, -3), x)); |
| 70 | try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y)); | 75 | try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y)); |
| 71 | try expect(y == @min(nan, y)); | 76 | try expect(y == @min(nan, y)); |
| ... | @@ -89,17 +94,20 @@ test "@min for vectors" { | ... | @@ -89,17 +94,20 @@ test "@min for vectors" { |
| 89 | fn doTheTest() !void { | 94 | fn doTheTest() !void { |
| 90 | var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; | 95 | var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 91 | var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; | 96 | var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 92 | var x = @min(a, b); | 97 | _ = .{ &a, &b }; |
| 98 | const x = @min(a, b); | ||
| 93 | try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 })); | 99 | try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 })); |
| 94 | 100 | ||
| 95 | var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; | 101 | var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; |
| 96 | var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; | 102 | var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; |
| 97 | var y = @min(c, d); | 103 | _ = .{ &c, &d }; |
| 104 | const y = @min(c, d); | ||
| 98 | try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 })); | 105 | try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 })); |
| 99 | 106 | ||
| 100 | var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; | 107 | var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; |
| 101 | var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; | 108 | var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; |
| 102 | var z = @max(e, f); | 109 | _ = .{ &e, &f }; |
| 110 | const z = @max(e, f); | ||
| 103 | try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); | 111 | try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); |
| 104 | } | 112 | } |
| 105 | }; | 113 | }; |
| ... | @@ -119,6 +127,7 @@ test "@min/max for floats" { | ... | @@ -119,6 +127,7 @@ test "@min/max for floats" { |
| 119 | fn doTheTest(comptime T: type) !void { | 127 | fn doTheTest(comptime T: type) !void { |
| 120 | var x: T = -3.14; | 128 | var x: T = -3.14; |
| 121 | var y: T = 5.27; | 129 | var y: T = 5.27; |
| 130 | _ = .{ &x, &y }; | ||
| 122 | try expectEqual(x, @min(x, y)); | 131 | try expectEqual(x, @min(x, y)); |
| 123 | try expectEqual(x, @min(y, x)); | 132 | try expectEqual(x, @min(y, x)); |
| 124 | try expectEqual(y, @max(x, y)); | 133 | try expectEqual(y, @max(x, y)); |
| ... | @@ -126,6 +135,7 @@ test "@min/max for floats" { | ... | @@ -126,6 +135,7 @@ test "@min/max for floats" { |
| 126 | 135 | ||
| 127 | if (T != comptime_float) { | 136 | if (T != comptime_float) { |
| 128 | var nan: T = std.math.nan(T); | 137 | var nan: T = std.math.nan(T); |
| 138 | _ = &nan; | ||
| 129 | try expectEqual(y, @max(nan, y)); | 139 | try expectEqual(y, @max(nan, y)); |
| 130 | try expectEqual(y, @max(y, nan)); | 140 | try expectEqual(y, @max(y, nan)); |
| 131 | } | 141 | } |
| ... | @@ -175,6 +185,7 @@ test "@min/@max notices bounds" { | ... | @@ -175,6 +185,7 @@ test "@min/@max notices bounds" { |
| 175 | var x: u16 = 20; | 185 | var x: u16 = 20; |
| 176 | const y = 30; | 186 | const y = 30; |
| 177 | var z: u32 = 100; | 187 | var z: u32 = 100; |
| 188 | _ = .{ &x, &z }; | ||
| 178 | const min = @min(x, y, z); | 189 | const min = @min(x, y, z); |
| 179 | const max = @max(x, y, z); | 190 | const max = @max(x, y, z); |
| 180 | try expectEqual(x, min); | 191 | try expectEqual(x, min); |
| ... | @@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" { | ... | @@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" { |
| 194 | var x: @Vector(2, u16) = .{ 140, 40 }; | 205 | var x: @Vector(2, u16) = .{ 140, 40 }; |
| 195 | const y: @Vector(2, u64) = .{ 5, 100 }; | 206 | const y: @Vector(2, u64) = .{ 5, 100 }; |
| 196 | var z: @Vector(2, u32) = .{ 10, 300 }; | 207 | var z: @Vector(2, u32) = .{ 10, 300 }; |
| 208 | _ = .{ &x, &z }; | ||
| 197 | const min = @min(x, y, z); | 209 | const min = @min(x, y, z); |
| 198 | const max = @max(x, y, z); | 210 | const max = @max(x, y, z); |
| 199 | try expectEqual(@Vector(2, u32){ 5, 40 }, min); | 211 | try expectEqual(@Vector(2, u32){ 5, 40 }, min); |
| ... | @@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" { | ... | @@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" { |
| 224 | var x: u16 = 123; | 236 | var x: u16 = 123; |
| 225 | var y: u32 = 456; | 237 | var y: u32 = 456; |
| 226 | var z: u8 = 10; | 238 | var z: u8 = 10; |
| 239 | _ = .{ &x, &y, &z }; | ||
| 227 | 240 | ||
| 228 | const min = @min(x, y, z); | 241 | const min = @min(x, y, z); |
| 229 | const max = @max(x, y, z); | 242 | const max = @max(x, y, z); |
| ... | @@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" { | ... | @@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" { |
| 246 | var x: @Vector(2, u16) = .{ 30, 67 }; | 259 | var x: @Vector(2, u16) = .{ 30, 67 }; |
| 247 | var y: @Vector(2, u32) = .{ 20, 500 }; | 260 | var y: @Vector(2, u32) = .{ 20, 500 }; |
| 248 | var z: @Vector(2, u8) = .{ 60, 15 }; | 261 | var z: @Vector(2, u8) = .{ 60, 15 }; |
| 262 | _ = .{ &x, &y, &z }; | ||
| 249 | 263 | ||
| 250 | const min = @min(x, y, z); | 264 | const min = @min(x, y, z); |
| 251 | const max = @max(x, y, z); | 265 | const max = @max(x, y, z); |
| ... | @@ -263,6 +277,7 @@ test "@min/@max notices bounds from types when comptime-known value is undef" { | ... | @@ -263,6 +277,7 @@ test "@min/@max notices bounds from types when comptime-known value is undef" { |
| 263 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 277 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 264 | 278 | ||
| 265 | var x: u32 = 1_000_000; | 279 | var x: u32 = 1_000_000; |
| 280 | _ = &x; | ||
| 266 | const y: u16 = undefined; | 281 | const y: u16 = undefined; |
| 267 | // y is comptime-known, but is undef, so bounds cannot be refined using its value | 282 | // y is comptime-known, but is undef, so bounds cannot be refined using its value |
| 268 | 283 | ||
| ... | @@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known | ... | @@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known |
| 285 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest; | 300 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest; |
| 286 | 301 | ||
| 287 | var x: @Vector(2, u32) = .{ 1_000_000, 12345 }; | 302 | var x: @Vector(2, u32) = .{ 1_000_000, 12345 }; |
| 303 | _ = &x; | ||
| 288 | const y: @Vector(2, u16) = .{ 10, undefined }; | 304 | const y: @Vector(2, u16) = .{ 10, undefined }; |
| 289 | // y is comptime-known, but an element is undef, so bounds cannot be refined using its value | 305 | // y is comptime-known, but an element is undef, so bounds cannot be refined using its value |
| 290 | 306 | ||
| ... | @@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known | ... | @@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known |
| 302 | test "@min/@max of signed and unsigned runtime integers" { | 318 | test "@min/@max of signed and unsigned runtime integers" { |
| 303 | var x: i32 = -1; | 319 | var x: i32 = -1; |
| 304 | var y: u31 = 1; | 320 | var y: u31 = 1; |
| 321 | _ = .{ &x, &y }; | ||
| 305 | 322 | ||
| 306 | const min = @min(x, y); | 323 | const min = @min(x, y); |
| 307 | const max = @max(x, y); | 324 | const max = @max(x, y); |
test/behavior/memcpy.zig+1| ... | @@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void { | ... | @@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void { |
| 57 | var str = "hello".*; | 57 | var str = "hello".*; |
| 58 | var buf: [5]u8 = undefined; | 58 | var buf: [5]u8 = undefined; |
| 59 | var len: usize = 5; | 59 | var len: usize = 5; |
| 60 | _ = &len; | ||
| 60 | @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]); | 61 | @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]); |
| 61 | try expect(buf[0] == 'h'); | 62 | try expect(buf[0] == 'h'); |
| 62 | try expect(buf[1] == 'e'); | 63 | try expect(buf[1] == 'e'); |
test/behavior/memset.zig+5-2| ... | @@ -46,7 +46,8 @@ fn testMemsetSlice() !void { | ... | @@ -46,7 +46,8 @@ fn testMemsetSlice() !void { |
| 46 | // memset slice to non-undefined, ABI size == 1 | 46 | // memset slice to non-undefined, ABI size == 1 |
| 47 | var array: [20]u8 = undefined; | 47 | var array: [20]u8 = undefined; |
| 48 | var len = array.len; | 48 | var len = array.len; |
| 49 | var slice = array[0..len]; | 49 | _ = &len; |
| 50 | const slice = array[0..len]; | ||
| 50 | @memset(slice, 'A'); | 51 | @memset(slice, 'A'); |
| 51 | try expect(slice[0] == 'A'); | 52 | try expect(slice[0] == 'A'); |
| 52 | try expect(slice[11] == 'A'); | 53 | try expect(slice[11] == 'A'); |
| ... | @@ -56,7 +57,8 @@ fn testMemsetSlice() !void { | ... | @@ -56,7 +57,8 @@ fn testMemsetSlice() !void { |
| 56 | // memset slice to non-undefined, ABI size > 1 | 57 | // memset slice to non-undefined, ABI size > 1 |
| 57 | var array: [20]u32 = undefined; | 58 | var array: [20]u32 = undefined; |
| 58 | var len = array.len; | 59 | var len = array.len; |
| 59 | var slice = array[0..len]; | 60 | _ = &len; |
| 61 | const slice = array[0..len]; | ||
| 60 | @memset(slice, 1234); | 62 | @memset(slice, 1234); |
| 61 | try expect(slice[0] == 1234); | 63 | try expect(slice[0] == 1234); |
| 62 | try expect(slice[11] == 1234); | 64 | try expect(slice[11] == 1234); |
| ... | @@ -111,6 +113,7 @@ test "memset with large array element, runtime known" { | ... | @@ -111,6 +113,7 @@ test "memset with large array element, runtime known" { |
| 111 | const A = [128]u64; | 113 | const A = [128]u64; |
| 112 | var buf: [5]A = undefined; | 114 | var buf: [5]A = undefined; |
| 113 | var runtime_known_element = [_]u64{0} ** 128; | 115 | var runtime_known_element = [_]u64{0} ** 128; |
| 116 | _ = &runtime_known_element; | ||
| 114 | @memset(&buf, runtime_known_element); | 117 | @memset(&buf, runtime_known_element); |
| 115 | for (buf[0]) |elem| try expect(elem == 0); | 118 | for (buf[0]) |elem| try expect(elem == 0); |
| 116 | for (buf[1]) |elem| try expect(elem == 0); | 119 | for (buf[1]) |elem| try expect(elem == 0); |
test/behavior/muladd.zig+15-5| ... | @@ -21,12 +21,14 @@ fn testMulAdd() !void { | ... | @@ -21,12 +21,14 @@ fn testMulAdd() !void { |
| 21 | var a: f32 = 5.5; | 21 | var a: f32 = 5.5; |
| 22 | var b: f32 = 2.5; | 22 | var b: f32 = 2.5; |
| 23 | var c: f32 = 6.25; | 23 | var c: f32 = 6.25; |
| 24 | _ = .{ &a, &b, &c }; | ||
| 24 | try expect(@mulAdd(f32, a, b, c) == 20); | 25 | try expect(@mulAdd(f32, a, b, c) == 20); |
| 25 | } | 26 | } |
| 26 | { | 27 | { |
| 27 | var a: f64 = 5.5; | 28 | var a: f64 = 5.5; |
| 28 | var b: f64 = 2.5; | 29 | var b: f64 = 2.5; |
| 29 | var c: f64 = 6.25; | 30 | var c: f64 = 6.25; |
| 31 | _ = .{ &a, &b, &c }; | ||
| 30 | try expect(@mulAdd(f64, a, b, c) == 20); | 32 | try expect(@mulAdd(f64, a, b, c) == 20); |
| 31 | } | 33 | } |
| 32 | } | 34 | } |
| ... | @@ -46,6 +48,7 @@ fn testMulAdd16() !void { | ... | @@ -46,6 +48,7 @@ fn testMulAdd16() !void { |
| 46 | var a: f16 = 5.5; | 48 | var a: f16 = 5.5; |
| 47 | var b: f16 = 2.5; | 49 | var b: f16 = 2.5; |
| 48 | var c: f16 = 6.25; | 50 | var c: f16 = 6.25; |
| 51 | _ = .{ &a, &b, &c }; | ||
| 49 | try expect(@mulAdd(f16, a, b, c) == 20); | 52 | try expect(@mulAdd(f16, a, b, c) == 20); |
| 50 | } | 53 | } |
| 51 | 54 | ||
| ... | @@ -65,6 +68,7 @@ fn testMulAdd80() !void { | ... | @@ -65,6 +68,7 @@ fn testMulAdd80() !void { |
| 65 | var a: f16 = 5.5; | 68 | var a: f16 = 5.5; |
| 66 | var b: f80 = 2.5; | 69 | var b: f80 = 2.5; |
| 67 | var c: f80 = 6.25; | 70 | var c: f80 = 6.25; |
| 71 | _ = .{ &a, &b, &c }; | ||
| 68 | try expect(@mulAdd(f80, a, b, c) == 20); | 72 | try expect(@mulAdd(f80, a, b, c) == 20); |
| 69 | } | 73 | } |
| 70 | 74 | ||
| ... | @@ -84,6 +88,7 @@ fn testMulAdd128() !void { | ... | @@ -84,6 +88,7 @@ fn testMulAdd128() !void { |
| 84 | var a: f16 = 5.5; | 88 | var a: f16 = 5.5; |
| 85 | var b: f128 = 2.5; | 89 | var b: f128 = 2.5; |
| 86 | var c: f128 = 6.25; | 90 | var c: f128 = 6.25; |
| 91 | _ = .{ &a, &b, &c }; | ||
| 87 | try expect(@mulAdd(f128, a, b, c) == 20); | 92 | try expect(@mulAdd(f128, a, b, c) == 20); |
| 88 | } | 93 | } |
| 89 | 94 | ||
| ... | @@ -91,7 +96,8 @@ fn vector16() !void { | ... | @@ -91,7 +96,8 @@ fn vector16() !void { |
| 91 | var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 }; | 96 | var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 }; |
| 92 | var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 }; | 97 | var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 }; |
| 93 | var c = @Vector(4, f16){ 6.25, 6.25, 6.25, 6.25 }; | 98 | var c = @Vector(4, f16){ 6.25, 6.25, 6.25, 6.25 }; |
| 94 | var x = @mulAdd(@Vector(4, f16), a, b, c); | 99 | _ = .{ &a, &b, &c }; |
| 100 | const x = @mulAdd(@Vector(4, f16), a, b, c); | ||
| 95 | 101 | ||
| 96 | try expect(x[0] == 20); | 102 | try expect(x[0] == 20); |
| 97 | try expect(x[1] == 20); | 103 | try expect(x[1] == 20); |
| ... | @@ -115,7 +121,8 @@ fn vector32() !void { | ... | @@ -115,7 +121,8 @@ fn vector32() !void { |
| 115 | var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 }; | 121 | var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 }; |
| 116 | var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 }; | 122 | var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 }; |
| 117 | var c = @Vector(4, f32){ 6.25, 6.25, 6.25, 6.25 }; | 123 | var c = @Vector(4, f32){ 6.25, 6.25, 6.25, 6.25 }; |
| 118 | var x = @mulAdd(@Vector(4, f32), a, b, c); | 124 | _ = .{ &a, &b, &c }; |
| 125 | const x = @mulAdd(@Vector(4, f32), a, b, c); | ||
| 119 | 126 | ||
| 120 | try expect(x[0] == 20); | 127 | try expect(x[0] == 20); |
| 121 | try expect(x[1] == 20); | 128 | try expect(x[1] == 20); |
| ... | @@ -139,7 +146,8 @@ fn vector64() !void { | ... | @@ -139,7 +146,8 @@ fn vector64() !void { |
| 139 | var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 }; | 146 | var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 }; |
| 140 | var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 }; | 147 | var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 }; |
| 141 | var c = @Vector(4, f64){ 6.25, 6.25, 6.25, 6.25 }; | 148 | var c = @Vector(4, f64){ 6.25, 6.25, 6.25, 6.25 }; |
| 142 | var x = @mulAdd(@Vector(4, f64), a, b, c); | 149 | _ = .{ &a, &b, &c }; |
| 150 | const x = @mulAdd(@Vector(4, f64), a, b, c); | ||
| 143 | 151 | ||
| 144 | try expect(x[0] == 20); | 152 | try expect(x[0] == 20); |
| 145 | try expect(x[1] == 20); | 153 | try expect(x[1] == 20); |
| ... | @@ -163,7 +171,8 @@ fn vector80() !void { | ... | @@ -163,7 +171,8 @@ fn vector80() !void { |
| 163 | var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 }; | 171 | var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 }; |
| 164 | var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 }; | 172 | var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 }; |
| 165 | var c = @Vector(4, f80){ 6.25, 6.25, 6.25, 6.25 }; | 173 | var c = @Vector(4, f80){ 6.25, 6.25, 6.25, 6.25 }; |
| 166 | var x = @mulAdd(@Vector(4, f80), a, b, c); | 174 | _ = .{ &a, &b, &c }; |
| 175 | const x = @mulAdd(@Vector(4, f80), a, b, c); | ||
| 167 | try expect(x[0] == 20); | 176 | try expect(x[0] == 20); |
| 168 | try expect(x[1] == 20); | 177 | try expect(x[1] == 20); |
| 169 | try expect(x[2] == 20); | 178 | try expect(x[2] == 20); |
| ... | @@ -187,7 +196,8 @@ fn vector128() !void { | ... | @@ -187,7 +196,8 @@ fn vector128() !void { |
| 187 | var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 }; | 196 | var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 }; |
| 188 | var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 }; | 197 | var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 }; |
| 189 | var c = @Vector(4, f128){ 6.25, 6.25, 6.25, 6.25 }; | 198 | var c = @Vector(4, f128){ 6.25, 6.25, 6.25, 6.25 }; |
| 190 | var x = @mulAdd(@Vector(4, f128), a, b, c); | 199 | _ = .{ &a, &b, &c }; |
| 200 | const x = @mulAdd(@Vector(4, f128), a, b, c); | ||
| 191 | 201 | ||
| 192 | try expect(x[0] == 20); | 202 | try expect(x[0] == 20); |
| 193 | try expect(x[1] == 20); | 203 | try expect(x[1] == 20); |
test/behavior/null.zig+1| ... | @@ -134,6 +134,7 @@ test "optional pointer to 0 bit type null value at runtime" { | ... | @@ -134,6 +134,7 @@ test "optional pointer to 0 bit type null value at runtime" { |
| 134 | 134 | ||
| 135 | const EmptyStruct = struct {}; | 135 | const EmptyStruct = struct {}; |
| 136 | var x: ?*EmptyStruct = null; | 136 | var x: ?*EmptyStruct = null; |
| 137 | _ = &x; | ||
| 137 | try expect(x == null); | 138 | try expect(x == null); |
| 138 | } | 139 | } |
| 139 | 140 |
test/behavior/optional.zig+13-6| ... | @@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" { | ... | @@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" { |
| 11 | 11 | ||
| 12 | const S = struct { | 12 | const S = struct { |
| 13 | fn entry() bool { | 13 | fn entry() bool { |
| 14 | var x: i32 = 1234; | 14 | const x: i32 = 1234; |
| 15 | return foo(x); | 15 | return foo(x); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| ... | @@ -29,7 +29,7 @@ test "optional pointer to size zero struct" { | ... | @@ -29,7 +29,7 @@ test "optional pointer to size zero struct" { |
| 29 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 29 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 30 | 30 | ||
| 31 | var e = EmptyStruct{}; | 31 | var e = EmptyStruct{}; |
| 32 | var o: ?*EmptyStruct = &e; | 32 | const o: ?*EmptyStruct = &e; |
| 33 | try expect(o != null); | 33 | try expect(o != null); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| ... | @@ -63,6 +63,7 @@ test "optional with void type" { | ... | @@ -63,6 +63,7 @@ test "optional with void type" { |
| 63 | x: ?void, | 63 | x: ?void, |
| 64 | }; | 64 | }; |
| 65 | var x = Foo{ .x = null }; | 65 | var x = Foo{ .x = null }; |
| 66 | _ = &x; | ||
| 66 | try expect(x.x == null); | 67 | try expect(x.x == null); |
| 67 | } | 68 | } |
| 68 | 69 | ||
| ... | @@ -102,6 +103,7 @@ test "nested optional field in struct" { | ... | @@ -102,6 +103,7 @@ test "nested optional field in struct" { |
| 102 | var s = S1{ | 103 | var s = S1{ |
| 103 | .x = S2{ .y = 127 }, | 104 | .x = S2{ .y = 127 }, |
| 104 | }; | 105 | }; |
| 106 | _ = &s; | ||
| 105 | try expect(s.x.?.y == 127); | 107 | try expect(s.x.?.y == 127); |
| 106 | } | 108 | } |
| 107 | 109 | ||
| ... | @@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void { | ... | @@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void { |
| 120 | var five: i32 = 5; | 122 | var five: i32 = 5; |
| 121 | var int_n: ?i32 = null; | 123 | var int_n: ?i32 = null; |
| 122 | 124 | ||
| 125 | _ = .{ &ten, &opt_ten, &five, &int_n }; | ||
| 126 | |||
| 123 | try expect(int_n != ten); | 127 | try expect(int_n != ten); |
| 124 | try expect(opt_ten == ten); | 128 | try expect(opt_ten == ten); |
| 125 | try expect(opt_ten != five); | 129 | try expect(opt_ten != five); |
| ... | @@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" { | ... | @@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" { |
| 208 | }; | 212 | }; |
| 209 | }; | 213 | }; |
| 210 | 214 | ||
| 211 | var n = S.Node.new(); | 215 | const n = S.Node.new(); |
| 212 | try expect(n.data == null); | 216 | try expect(n.data == null); |
| 213 | } | 217 | } |
| 214 | 218 | ||
| ... | @@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" { | ... | @@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" { |
| 252 | const S = struct { | 256 | const S = struct { |
| 253 | fn doTheTest() !void { | 257 | fn doTheTest() !void { |
| 254 | var y = Foo{}; | 258 | var y = Foo{}; |
| 255 | var z = y.thing(); | 259 | const z = y.thing(); |
| 256 | try expect(z != null); | 260 | try expect(z != null); |
| 257 | } | 261 | } |
| 258 | 262 | ||
| ... | @@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" { | ... | @@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" { |
| 425 | 429 | ||
| 426 | fn foo() ?I { | 430 | fn foo() ?I { |
| 427 | var i: I = .{ .x = 1234 }; | 431 | var i: I = .{ .x = 1234 }; |
| 432 | _ = &i; | ||
| 428 | return i; | 433 | return i; |
| 429 | } | 434 | } |
| 430 | }; | 435 | }; |
| ... | @@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" { | ... | @@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" { |
| 450 | const Thing = struct { n: i32 }; | 455 | const Thing = struct { n: i32 }; |
| 451 | var a = false; | 456 | var a = false; |
| 452 | var b = false; | 457 | var b = false; |
| 458 | _ = .{ &a, &b }; | ||
| 453 | 459 | ||
| 454 | var result1 = if (a) | 460 | const result1 = if (a) |
| 455 | Thing{ .n = 1 } | 461 | Thing{ .n = 1 } |
| 456 | else | 462 | else |
| 457 | null; | 463 | null; |
| 458 | try expect(result1 == null); | 464 | try expect(result1 == null); |
| 459 | try expect(@TypeOf(result1) == ?Thing); | 465 | try expect(@TypeOf(result1) == ?Thing); |
| 460 | 466 | ||
| 461 | var result2 = if (a) | 467 | const result2 = if (a) |
| 462 | Thing{ .n = 0 } | 468 | Thing{ .n = 0 } |
| 463 | else if (b) | 469 | else if (b) |
| 464 | Thing{ .n = 1 } | 470 | Thing{ .n = 1 } |
| ... | @@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" { | ... | @@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" { |
| 486 | 492 | ||
| 487 | test "variable of optional of noreturn" { | 493 | test "variable of optional of noreturn" { |
| 488 | var null_opv: ?noreturn = null; | 494 | var null_opv: ?noreturn = null; |
| 495 | _ = &null_opv; | ||
| 489 | try std.testing.expectEqual(@as(?noreturn, null), null_opv); | 496 | try std.testing.expectEqual(@as(?noreturn, null), null_opv); |
| 490 | } | 497 | } |
test/behavior/packed-struct.zig+10-5| ... | @@ -479,10 +479,9 @@ test "load pointer from packed struct" { | ... | @@ -479,10 +479,9 @@ test "load pointer from packed struct" { |
| 479 | y: u32, | 479 | y: u32, |
| 480 | }; | 480 | }; |
| 481 | var a: A = .{ .index = 123 }; | 481 | var a: A = .{ .index = 123 }; |
| 482 | var b_list: []const B = &.{.{ .x = &a, .y = 99 }}; | 482 | const b_list: []const B = &.{.{ .x = &a, .y = 99 }}; |
| 483 | for (b_list) |b| { | 483 | for (b_list) |b| { |
| 484 | var i = b.x.index; | 484 | try expect(b.x.index == 123); |
| 485 | try expect(i == 123); | ||
| 486 | } | 485 | } |
| 487 | } | 486 | } |
| 488 | 487 | ||
| ... | @@ -770,6 +769,7 @@ test "nested packed struct field access test" { | ... | @@ -770,6 +769,7 @@ test "nested packed struct field access test" { |
| 770 | }; | 769 | }; |
| 771 | 770 | ||
| 772 | var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } }; | 771 | var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } }; |
| 772 | _ = &arg; | ||
| 773 | try std.testing.expect(arg.b.c == 1); | 773 | try std.testing.expect(arg.b.c == 1); |
| 774 | try std.testing.expect(arg.b.d == 2); | 774 | try std.testing.expect(arg.b.d == 2); |
| 775 | try std.testing.expect(arg.g.h == 6); | 775 | try std.testing.expect(arg.g.h == 6); |
| ... | @@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" { | ... | @@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" { |
| 790 | }; | 790 | }; |
| 791 | 791 | ||
| 792 | var k: u8 = 123; | 792 | var k: u8 = 123; |
| 793 | _ = &k; | ||
| 793 | var v: A = .{ | 794 | var v: A = .{ |
| 794 | .p1 = .{ .a = k + 1, .b = k }, | 795 | .p1 = .{ .a = k + 1, .b = k }, |
| 795 | .p2 = .{ .a = k + 1, .b = k }, | 796 | .p2 = .{ .a = k + 1, .b = k }, |
| ... | @@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" { | ... | @@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" { |
| 833 | 834 | ||
| 834 | fn doTheTest() !void { | 835 | fn doTheTest() !void { |
| 835 | var k: u8 = 123; | 836 | var k: u8 = 123; |
| 837 | _ = &k; | ||
| 836 | var v: A = .{ | 838 | var v: A = .{ |
| 837 | .p1 = .{ .a = k + 1, .b = k }, | 839 | .p1 = .{ .a = k + 1, .b = k }, |
| 838 | .p2 = .{ .a = k + 1, .b = k }, | 840 | .p2 = .{ .a = k + 1, .b = k }, |
| ... | @@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" { | ... | @@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" { |
| 877 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 879 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 878 | 880 | ||
| 879 | var z: u8 = 123; | 881 | var z: u8 = 123; |
| 882 | _ = &z; | ||
| 880 | try (packed struct { | 883 | try (packed struct { |
| 881 | x: u8, | 884 | x: u8, |
| 882 | pub fn m(s: @This()) !void { | 885 | pub fn m(s: @This()) !void { |
| ... | @@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" { | ... | @@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" { |
| 941 | 944 | ||
| 942 | const T = packed struct { val: u8 }; | 945 | const T = packed struct { val: u8 }; |
| 943 | var val: u8 = 123; | 946 | var val: u8 = 123; |
| 947 | _ = &val; | ||
| 944 | const t = @as(u8, @bitCast(T{ .val = val })); | 948 | const t = @as(u8, @bitCast(T{ .val = val })); |
| 945 | try expect(t == val); | 949 | try expect(t == val); |
| 946 | } | 950 | } |
| ... | @@ -976,7 +980,8 @@ test "store undefined to packed result location" { | ... | @@ -976,7 +980,8 @@ test "store undefined to packed result location" { |
| 976 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 980 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 977 | 981 | ||
| 978 | var x: u4 = 0; | 982 | var x: u4 = 0; |
| 979 | var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; | 983 | _ = &x; |
| 984 | const s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; | ||
| 980 | try expectEqual(x, s.x); | 985 | try expectEqual(x, s.x); |
| 981 | } | 986 | } |
| 982 | 987 | ||
| ... | @@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init | ... | @@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init |
| 1004 | } | 1009 | } |
| 1005 | }; | 1010 | }; |
| 1006 | 1011 | ||
| 1007 | var s = S.init(true); | 1012 | const s = S.init(true); |
| 1008 | // note: this bug is triggered by the == operator, expectEqual will hide it | 1013 | // note: this bug is triggered by the == operator, expectEqual will hide it |
| 1009 | try expect(@as(i2, 0) == s.ps.x); | 1014 | try expect(@as(i2, 0) == s.ps.x); |
| 1010 | try expect(@as(i2, 1) == s.ps.y); | 1015 | try expect(@as(i2, 1) == s.ps.y); |
test/behavior/pointers.zig+37-23| ... | @@ -11,7 +11,7 @@ test "dereference pointer" { | ... | @@ -11,7 +11,7 @@ test "dereference pointer" { |
| 11 | 11 | ||
| 12 | fn testDerefPtr() !void { | 12 | fn testDerefPtr() !void { |
| 13 | var x: i32 = 1234; | 13 | var x: i32 = 1234; |
| 14 | var y = &x; | 14 | const y = &x; |
| 15 | y.* += 1; | 15 | y.* += 1; |
| 16 | try expect(x == 1235); | 16 | try expect(x == 1235); |
| 17 | } | 17 | } |
| ... | @@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" { | ... | @@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" { |
| 53 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 53 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 54 | 54 | ||
| 55 | var y: u8 = 11; | 55 | var y: u8 = 11; |
| 56 | var x: [*c]u8 = &y; | 56 | const x: [*c]u8 = &y; |
| 57 | var z: *u8 = x; | 57 | const z: *u8 = x; |
| 58 | z.* += 1; | 58 | z.* += 1; |
| 59 | try expect(y == 12); | 59 | try expect(y == 12); |
| 60 | } | 60 | } |
| ... | @@ -74,6 +74,7 @@ test "assigning integer to C pointer" { | ... | @@ -74,6 +74,7 @@ test "assigning integer to C pointer" { |
| 74 | var ptr2: [*c]u8 = x; | 74 | var ptr2: [*c]u8 = x; |
| 75 | var ptr3: [*c]u8 = 1; | 75 | var ptr3: [*c]u8 = 1; |
| 76 | var ptr4: [*c]u8 = y; | 76 | var ptr4: [*c]u8 = y; |
| 77 | _ = .{ &x, &y, &ptr, &ptr2, &ptr3, &ptr4 }; | ||
| 77 | 78 | ||
| 78 | try expect(ptr == ptr2); | 79 | try expect(ptr == ptr2); |
| 79 | try expect(ptr3 == ptr4); | 80 | try expect(ptr3 == ptr4); |
| ... | @@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" { | ... | @@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" { |
| 88 | fn doTheTest() !void { | 89 | fn doTheTest() !void { |
| 89 | var ptr1: [*c]u32 = 0; | 90 | var ptr1: [*c]u32 = 0; |
| 90 | var ptr2 = ptr1 + 10; | 91 | var ptr2 = ptr1 + 10; |
| 92 | _ = &ptr1; | ||
| 91 | try expect(ptr1 == 0); | 93 | try expect(ptr1 == 0); |
| 92 | try expect(ptr1 >= 0); | 94 | try expect(ptr1 >= 0); |
| 93 | try expect(ptr1 <= 0); | 95 | try expect(ptr1 <= 0); |
| ... | @@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void { | ... | @@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void { |
| 125 | } | 127 | } |
| 126 | 128 | ||
| 127 | test "peer type resolution with C pointers" { | 129 | test "peer type resolution with C pointers" { |
| 128 | var ptr_one: *u8 = undefined; | 130 | const ptr_one: *u8 = undefined; |
| 129 | var ptr_many: [*]u8 = undefined; | 131 | const ptr_many: [*]u8 = undefined; |
| 130 | var ptr_c: [*c]u8 = undefined; | 132 | const ptr_c: [*c]u8 = undefined; |
| 131 | var t = true; | 133 | var t = true; |
| 132 | var x1 = if (t) ptr_one else ptr_c; | 134 | _ = &t; |
| 133 | var x2 = if (t) ptr_many else ptr_c; | 135 | const x1 = if (t) ptr_one else ptr_c; |
| 134 | var x3 = if (t) ptr_c else ptr_one; | 136 | const x2 = if (t) ptr_many else ptr_c; |
| 135 | var x4 = if (t) ptr_c else ptr_many; | 137 | const x3 = if (t) ptr_c else ptr_one; |
| 138 | const x4 = if (t) ptr_c else ptr_many; | ||
| 136 | try expect(@TypeOf(x1) == [*c]u8); | 139 | try expect(@TypeOf(x1) == [*c]u8); |
| 137 | try expect(@TypeOf(x2) == [*c]u8); | 140 | try expect(@TypeOf(x2) == [*c]u8); |
| 138 | try expect(@TypeOf(x3) == [*c]u8); | 141 | try expect(@TypeOf(x3) == [*c]u8); |
| ... | @@ -141,8 +144,9 @@ test "peer type resolution with C pointers" { | ... | @@ -141,8 +144,9 @@ test "peer type resolution with C pointers" { |
| 141 | 144 | ||
| 142 | test "peer type resolution with C pointer and const pointer" { | 145 | test "peer type resolution with C pointer and const pointer" { |
| 143 | var ptr_c: [*c]u8 = undefined; | 146 | var ptr_c: [*c]u8 = undefined; |
| 144 | const ptr_const: u8 = undefined; | 147 | var ptr_const: *const u8 = &undefined; |
| 145 | try expect(@TypeOf(ptr_c, &ptr_const) == [*c]const u8); | 148 | _ = .{ &ptr_c, &ptr_const }; |
| 149 | try expect(@TypeOf(ptr_c, ptr_const) == [*c]const u8); | ||
| 146 | } | 150 | } |
| 147 | 151 | ||
| 148 | test "implicit casting between C pointer and optional non-C pointer" { | 152 | test "implicit casting between C pointer and optional non-C pointer" { |
| ... | @@ -151,9 +155,10 @@ test "implicit casting between C pointer and optional non-C pointer" { | ... | @@ -151,9 +155,10 @@ test "implicit casting between C pointer and optional non-C pointer" { |
| 151 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 155 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 152 | 156 | ||
| 153 | var slice: []const u8 = "aoeu"; | 157 | var slice: []const u8 = "aoeu"; |
| 158 | _ = &slice; | ||
| 154 | const opt_many_ptr: ?[*]const u8 = slice.ptr; | 159 | const opt_many_ptr: ?[*]const u8 = slice.ptr; |
| 155 | var ptr_opt_many_ptr = &opt_many_ptr; | 160 | var ptr_opt_many_ptr = &opt_many_ptr; |
| 156 | var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; | 161 | const c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; |
| 157 | try expect(c_ptr.*.* == 'a'); | 162 | try expect(c_ptr.*.* == 'a'); |
| 158 | ptr_opt_many_ptr = c_ptr; | 163 | ptr_opt_many_ptr = c_ptr; |
| 159 | try expect(ptr_opt_many_ptr.*.?[1] == 'o'); | 164 | try expect(ptr_opt_many_ptr.*.?[1] == 'o'); |
| ... | @@ -192,11 +197,12 @@ test "allowzero pointer and slice" { | ... | @@ -192,11 +197,12 @@ test "allowzero pointer and slice" { |
| 192 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | 197 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 193 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 198 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 194 | 199 | ||
| 195 | var ptr = @as([*]allowzero i32, @ptrFromInt(0)); | 200 | var ptr: [*]allowzero i32 = @ptrFromInt(0); |
| 196 | var opt_ptr: ?[*]allowzero i32 = ptr; | 201 | const opt_ptr: ?[*]allowzero i32 = ptr; |
| 197 | try expect(opt_ptr != null); | 202 | try expect(opt_ptr != null); |
| 198 | try expect(@intFromPtr(ptr) == 0); | 203 | try expect(@intFromPtr(ptr) == 0); |
| 199 | var runtime_zero: usize = 0; | 204 | var runtime_zero: usize = 0; |
| 205 | _ = &runtime_zero; | ||
| 200 | var slice = ptr[runtime_zero..10]; | 206 | var slice = ptr[runtime_zero..10]; |
| 201 | try comptime expect(@TypeOf(slice) == []allowzero i32); | 207 | try comptime expect(@TypeOf(slice) == []allowzero i32); |
| 202 | try expect(@intFromPtr(&slice[5]) == 20); | 208 | try expect(@intFromPtr(&slice[5]) == 20); |
| ... | @@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" { | ... | @@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" { |
| 211 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 217 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 212 | 218 | ||
| 213 | var x: [*c]i32 = null; | 219 | var x: [*c]i32 = null; |
| 220 | _ = &x; | ||
| 214 | try expect(x == null); | 221 | try expect(x == null); |
| 215 | try expect(null == x); | 222 | try expect(null == x); |
| 216 | try expect(!(x != null)); | 223 | try expect(!(x != null)); |
| ... | @@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" { | ... | @@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" { |
| 236 | try comptime expect((y orelse ptr_othery) == ptr_othery); | 243 | try comptime expect((y orelse ptr_othery) == ptr_othery); |
| 237 | 244 | ||
| 238 | var n: i32 = 1234; | 245 | var n: i32 = 1234; |
| 239 | var x1: [*c]i32 = &n; | 246 | const x1: [*c]i32 = &n; |
| 240 | try expect(!(x1 == null)); | 247 | try expect(!(x1 == null)); |
| 241 | try expect(!(null == x1)); | 248 | try expect(!(null == x1)); |
| 242 | try expect(x1 != null); | 249 | try expect(x1 != null); |
| ... | @@ -279,9 +286,9 @@ test "null terminated pointer" { | ... | @@ -279,9 +286,9 @@ test "null terminated pointer" { |
| 279 | const S = struct { | 286 | const S = struct { |
| 280 | fn doTheTest() !void { | 287 | fn doTheTest() !void { |
| 281 | var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' }; | 288 | var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' }; |
| 282 | var zero_ptr: [*:0]const u8 = @as([*:0]const u8, @ptrCast(&array_with_zero)); | 289 | const zero_ptr: [*:0]const u8 = @ptrCast(&array_with_zero); |
| 283 | var no_zero_ptr: [*]const u8 = zero_ptr; | 290 | const no_zero_ptr: [*]const u8 = zero_ptr; |
| 284 | var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr)); | 291 | const zero_ptr_again: [*:0]const u8 = @ptrCast(no_zero_ptr); |
| 285 | try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello")); | 292 | try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello")); |
| 286 | } | 293 | } |
| 287 | }; | 294 | }; |
| ... | @@ -296,7 +303,7 @@ test "allow any sentinel" { | ... | @@ -296,7 +303,7 @@ test "allow any sentinel" { |
| 296 | const S = struct { | 303 | const S = struct { |
| 297 | fn doTheTest() !void { | 304 | fn doTheTest() !void { |
| 298 | var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 }; | 305 | var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 }; |
| 299 | var ptr: [*:std.math.minInt(i32)]i32 = &array; | 306 | const ptr: [*:std.math.minInt(i32)]i32 = &array; |
| 300 | try expect(ptr[4] == std.math.minInt(i32)); | 307 | try expect(ptr[4] == std.math.minInt(i32)); |
| 301 | } | 308 | } |
| 302 | }; | 309 | }; |
| ... | @@ -317,6 +324,7 @@ test "pointer sentinel with enums" { | ... | @@ -317,6 +324,7 @@ test "pointer sentinel with enums" { |
| 317 | 324 | ||
| 318 | fn doTheTest() !void { | 325 | fn doTheTest() !void { |
| 319 | var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; | 326 | var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; |
| 327 | _ = &ptr; | ||
| 320 | try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731 | 328 | try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731 |
| 321 | } | 329 | } |
| 322 | }; | 330 | }; |
| ... | @@ -332,6 +340,7 @@ test "pointer sentinel with optional element" { | ... | @@ -332,6 +340,7 @@ test "pointer sentinel with optional element" { |
| 332 | const S = struct { | 340 | const S = struct { |
| 333 | fn doTheTest() !void { | 341 | fn doTheTest() !void { |
| 334 | var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; | 342 | var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; |
| 343 | _ = &ptr; | ||
| 335 | try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731 | 344 | try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731 |
| 336 | } | 345 | } |
| 337 | }; | 346 | }; |
| ... | @@ -348,6 +357,7 @@ test "pointer sentinel with +inf" { | ... | @@ -348,6 +357,7 @@ test "pointer sentinel with +inf" { |
| 348 | fn doTheTest() !void { | 357 | fn doTheTest() !void { |
| 349 | const inf_f32 = comptime std.math.inf(f32); | 358 | const inf_f32 = comptime std.math.inf(f32); |
| 350 | var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 }; | 359 | var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 360 | _ = &ptr; | ||
| 351 | try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731 | 361 | try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731 |
| 352 | } | 362 | } |
| 353 | }; | 363 | }; |
| ... | @@ -366,6 +376,7 @@ test "pointer arithmetic affects the alignment" { | ... | @@ -366,6 +376,7 @@ test "pointer arithmetic affects the alignment" { |
| 366 | { | 376 | { |
| 367 | var ptr: [*]align(8) u32 = undefined; | 377 | var ptr: [*]align(8) u32 = undefined; |
| 368 | var x: usize = 1; | 378 | var x: usize = 1; |
| 379 | _ = .{ &ptr, &x }; | ||
| 369 | 380 | ||
| 370 | try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8); | 381 | try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8); |
| 371 | const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4 | 382 | const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4 |
| ... | @@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" { | ... | @@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" { |
| 380 | { | 391 | { |
| 381 | var ptr: [*]align(8) [3]u8 = undefined; | 392 | var ptr: [*]align(8) [3]u8 = undefined; |
| 382 | var x: usize = 1; | 393 | var x: usize = 1; |
| 394 | _ = .{ &ptr, &x }; | ||
| 383 | 395 | ||
| 384 | const ptr1 = ptr + 17; // 3 * 17 = 51 | 396 | const ptr1 = ptr + 17; // 3 * 17 = 51 |
| 385 | try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1); | 397 | try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1); |
| ... | @@ -467,8 +479,8 @@ test "array slicing to slice" { | ... | @@ -467,8 +479,8 @@ test "array slicing to slice" { |
| 467 | const S = struct { | 479 | const S = struct { |
| 468 | fn doTheTest() !void { | 480 | fn doTheTest() !void { |
| 469 | var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 }; | 481 | var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 }; |
| 470 | var sub: *[2]i32 = str[1..3]; | 482 | const sub: *[2]i32 = str[1..3]; |
| 471 | var slice: []i32 = sub; // used to cause failures | 483 | const slice: []i32 = sub; // used to cause failures |
| 472 | try testing.expect(slice.len == 2); | 484 | try testing.expect(slice.len == 2); |
| 473 | try testing.expect(slice[0] == 2); | 485 | try testing.expect(slice[0] == 2); |
| 474 | } | 486 | } |
| ... | @@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" { | ... | @@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" { |
| 495 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 507 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 496 | 508 | ||
| 497 | const s: [:0]const u8 = "foo"; | 509 | const s: [:0]const u8 = "foo"; |
| 498 | var p = @as([*c]const u8, @ptrCast(s)); | 510 | var p: [*c]const u8 = @ptrCast(s); |
| 511 | _ = &p; | ||
| 499 | try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0)); | 512 | try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0)); |
| 500 | } | 513 | } |
| 501 | 514 | ||
| ... | @@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" { | ... | @@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" { |
| 527 | test "result type preserved through multiple references" { | 540 | test "result type preserved through multiple references" { |
| 528 | const S = struct { x: u32 }; | 541 | const S = struct { x: u32 }; |
| 529 | var my_u64: u64 = 12345; | 542 | var my_u64: u64 = 12345; |
| 543 | _ = &my_u64; | ||
| 530 | const foo: *const *const *const S = &&&.{ | 544 | const foo: *const *const *const S = &&&.{ |
| 531 | .x = @intCast(my_u64), | 545 | .x = @intCast(my_u64), |
| 532 | }; | 546 | }; |
test/behavior/popcount.zig+10| ... | @@ -26,6 +26,7 @@ test "@popCount 128bit integer" { | ... | @@ -26,6 +26,7 @@ test "@popCount 128bit integer" { |
| 26 | 26 | ||
| 27 | { | 27 | { |
| 28 | var x: u128 = 0b11111111000110001100010000100001000011000011100101010001; | 28 | var x: u128 = 0b11111111000110001100010000100001000011000011100101010001; |
| 29 | _ = &x; | ||
| 29 | try expect(@popCount(x) == 24); | 30 | try expect(@popCount(x) == 24); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| ... | @@ -35,30 +36,37 @@ test "@popCount 128bit integer" { | ... | @@ -35,30 +36,37 @@ test "@popCount 128bit integer" { |
| 35 | fn testPopCountIntegers() !void { | 36 | fn testPopCountIntegers() !void { |
| 36 | { | 37 | { |
| 37 | var x: u32 = 0xffffffff; | 38 | var x: u32 = 0xffffffff; |
| 39 | _ = &x; | ||
| 38 | try expect(@popCount(x) == 32); | 40 | try expect(@popCount(x) == 32); |
| 39 | } | 41 | } |
| 40 | { | 42 | { |
| 41 | var x: u5 = 0x1f; | 43 | var x: u5 = 0x1f; |
| 44 | _ = &x; | ||
| 42 | try expect(@popCount(x) == 5); | 45 | try expect(@popCount(x) == 5); |
| 43 | } | 46 | } |
| 44 | { | 47 | { |
| 45 | var x: u32 = 0xaa; | 48 | var x: u32 = 0xaa; |
| 49 | _ = &x; | ||
| 46 | try expect(@popCount(x) == 4); | 50 | try expect(@popCount(x) == 4); |
| 47 | } | 51 | } |
| 48 | { | 52 | { |
| 49 | var x: u32 = 0xaaaaaaaa; | 53 | var x: u32 = 0xaaaaaaaa; |
| 54 | _ = &x; | ||
| 50 | try expect(@popCount(x) == 16); | 55 | try expect(@popCount(x) == 16); |
| 51 | } | 56 | } |
| 52 | { | 57 | { |
| 53 | var x: u32 = 0xaaaaaaaa; | 58 | var x: u32 = 0xaaaaaaaa; |
| 59 | _ = &x; | ||
| 54 | try expect(@popCount(x) == 16); | 60 | try expect(@popCount(x) == 16); |
| 55 | } | 61 | } |
| 56 | { | 62 | { |
| 57 | var x: i16 = -1; | 63 | var x: i16 = -1; |
| 64 | _ = &x; | ||
| 58 | try expect(@popCount(x) == 16); | 65 | try expect(@popCount(x) == 16); |
| 59 | } | 66 | } |
| 60 | { | 67 | { |
| 61 | var x: i8 = -120; | 68 | var x: i8 = -120; |
| 69 | _ = &x; | ||
| 62 | try expect(@popCount(x) == 2); | 70 | try expect(@popCount(x) == 2); |
| 63 | } | 71 | } |
| 64 | comptime { | 72 | comptime { |
| ... | @@ -81,12 +89,14 @@ test "@popCount vectors" { | ... | @@ -81,12 +89,14 @@ test "@popCount vectors" { |
| 81 | fn testPopCountVectors() !void { | 89 | fn testPopCountVectors() !void { |
| 82 | { | 90 | { |
| 83 | var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; | 91 | var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; |
| 92 | _ = &x; | ||
| 84 | const expected = [1]u6{32} ** 8; | 93 | const expected = [1]u6{32} ** 8; |
| 85 | const result: [8]u6 = @popCount(x); | 94 | const result: [8]u6 = @popCount(x); |
| 86 | try expect(std.mem.eql(u6, &expected, &result)); | 95 | try expect(std.mem.eql(u6, &expected, &result)); |
| 87 | } | 96 | } |
| 88 | { | 97 | { |
| 89 | var x: @Vector(8, i16) = [1]i16{-1} ** 8; | 98 | var x: @Vector(8, i16) = [1]i16{-1} ** 8; |
| 99 | _ = &x; | ||
| 90 | const expected = [1]u5{16} ** 8; | 100 | const expected = [1]u5{16} ** 8; |
| 91 | const result: [8]u5 = @popCount(x); | 101 | const result: [8]u5 = @popCount(x); |
| 92 | try expect(std.mem.eql(u5, &expected, &result)); | 102 | try expect(std.mem.eql(u5, &expected, &result)); |
test/behavior/prefetch.zig+1| ... | @@ -6,6 +6,7 @@ test "@prefetch()" { | ... | @@ -6,6 +6,7 @@ test "@prefetch()" { |
| 6 | 6 | ||
| 7 | var a: [2]u32 = .{ 42, 42 }; | 7 | var a: [2]u32 = .{ 42, 42 }; |
| 8 | var a_len = a.len; | 8 | var a_len = a.len; |
| 9 | _ = &a_len; | ||
| 9 | 10 | ||
| 10 | @prefetch(&a, .{}); | 11 | @prefetch(&a, .{}); |
| 11 | 12 |
test/behavior/ptrcast.zig+14-14| ... | @@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void { | ... | @@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void { |
| 71 | c: u8, | 71 | c: u8, |
| 72 | }; | 72 | }; |
| 73 | 73 | ||
| 74 | var ptr = @as(*const S, @ptrCast(&bytes)); | 74 | const ptr: *const S = @ptrCast(&bytes); |
| 75 | var val = ptr.c; | 75 | const val = ptr.c; |
| 76 | try expect(val == 5); | 76 | try expect(val == 5); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| ... | @@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void { | ... | @@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void { |
| 95 | a: u32 align(2), | 95 | a: u32 align(2), |
| 96 | c: u8, | 96 | c: u8, |
| 97 | }; | 97 | }; |
| 98 | var ptr = @as(*const S2, @ptrCast(&bytes)); | 98 | const ptr: *const S2 = @ptrCast(&bytes); |
| 99 | var val = ptr.c; | 99 | const val = ptr.c; |
| 100 | try expect(val == 5); | 100 | try expect(val == 5); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| ... | @@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void { | ... | @@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void { |
| 121 | a2: u16, | 121 | a2: u16, |
| 122 | c: u8, | 122 | c: u8, |
| 123 | }; | 123 | }; |
| 124 | var ptr = @as(*const S2, @ptrCast(&bytes)); | 124 | const ptr: *const S2 = @ptrCast(&bytes); |
| 125 | var val = ptr.c; | 125 | const val = ptr.c; |
| 126 | try expect(val == 5); | 126 | try expect(val == 5); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| ... | @@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" { | ... | @@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" { |
| 138 | c: u8, | 138 | c: u8, |
| 139 | }; | 139 | }; |
| 140 | comptime var ptr = @as(*const S, @ptrCast(&bytes)); | 140 | comptime var ptr = @as(*const S, @ptrCast(&bytes)); |
| 141 | var val = &ptr.c; | 141 | const val = &ptr.c; |
| 142 | try expect(val.* == 5); | 142 | try expect(val.* == 5); |
| 143 | 143 | ||
| 144 | // Test lowering an elem ptr | 144 | // Test lowering an elem ptr |
| 145 | comptime var src_value = S{ .a = 15, .c = 5 }; | 145 | comptime var src_value = S{ .a = 15, .c = 5 }; |
| 146 | comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); | 146 | comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); |
| 147 | var val2 = &ptr2[4]; | 147 | const val2 = &ptr2[4]; |
| 148 | try expect(val2.* == 5); | 148 | try expect(val2.* == 5); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| ... | @@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" { | ... | @@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" { |
| 160 | c: u8, | 160 | c: u8, |
| 161 | }; | 161 | }; |
| 162 | comptime var ptr = @as(*const S, @ptrCast(&bytes)); | 162 | comptime var ptr = @as(*const S, @ptrCast(&bytes)); |
| 163 | var val = &ptr.c; | 163 | const val = &ptr.c; |
| 164 | try expect(val.* == 5); | 164 | try expect(val.* == 5); |
| 165 | 165 | ||
| 166 | // Test lowering an elem ptr | 166 | // Test lowering an elem ptr |
| 167 | comptime var src_value = S{ .a = 15, .c = 5 }; | 167 | comptime var src_value = S{ .a = 15, .c = 5 }; |
| 168 | comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); | 168 | comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); |
| 169 | var val2 = &ptr2[4]; | 169 | const val2 = &ptr2[4]; |
| 170 | try expect(val2.* == 5); | 170 | try expect(val2.* == 5); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| ... | @@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" { | ... | @@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" { |
| 233 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 233 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 234 | 234 | ||
| 235 | var buf: [4]u8 = "aoeu".*; | 235 | var buf: [4]u8 = "aoeu".*; |
| 236 | var x: ?[*]u8 = &buf; | 236 | const x: ?[*]u8 = &buf; |
| 237 | var y: ?*anyopaque = x; | 237 | const y: ?*anyopaque = x; |
| 238 | var z = @as(*[4]u8, @ptrCast(y)); | 238 | const z: *[4]u8 = @ptrCast(y); |
| 239 | try expect(std.mem.eql(u8, z, "aoeu")); | 239 | try expect(std.mem.eql(u8, z, "aoeu")); |
| 240 | } | 240 | } |
| 241 | 241 | ||
| ... | @@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" { | ... | @@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" { |
| 276 | } | 276 | } |
| 277 | }; | 277 | }; |
| 278 | comptime { | 278 | comptime { |
| 279 | var x = S.transmute([]u8, i32, undefined); | 279 | const x = S.transmute([]u8, i32, undefined); |
| 280 | _ = x; | 280 | _ = x; |
| 281 | } | 281 | } |
| 282 | } | 282 | } |
test/behavior/ptrfromint.zig+1| ... | @@ -9,6 +9,7 @@ test "casting integer address to function pointer" { | ... | @@ -9,6 +9,7 @@ test "casting integer address to function pointer" { |
| 9 | 9 | ||
| 10 | fn addressToFunction() void { | 10 | fn addressToFunction() void { |
| 11 | var addr: usize = 0xdeadbee0; | 11 | var addr: usize = 0xdeadbee0; |
| 12 | _ = &addr; | ||
| 12 | _ = @as(*const fn () void, @ptrFromInt(addr)); | 13 | _ = @as(*const fn () void, @ptrFromInt(addr)); |
| 13 | } | 14 | } |
| 14 | 15 |
test/behavior/saturating_arithmetic.zig+2| ... | @@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" { | ... | @@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" { |
| 246 | 246 | ||
| 247 | const lhs_const: u8 = 1; | 247 | const lhs_const: u8 = 1; |
| 248 | var lhs_var: u8 = 1; | 248 | var lhs_var: u8 = 1; |
| 249 | _ = &lhs_var; | ||
| 249 | 250 | ||
| 250 | const rhs_const: usize = 8; | 251 | const rhs_const: usize = 8; |
| 251 | var rhs_var: usize = 8; | 252 | var rhs_var: usize = 8; |
| 253 | _ = &rhs_var; | ||
| 252 | 254 | ||
| 253 | try expect((lhs_const <<| 8) == 255); | 255 | try expect((lhs_const <<| 8) == 255); |
| 254 | try expect((lhs_const <<| rhs_const) == 255); | 256 | try expect((lhs_const <<| rhs_const) == 255); |
test/behavior/select.zig+8-4| ... | @@ -19,7 +19,8 @@ fn selectVectors() !void { | ... | @@ -19,7 +19,8 @@ fn selectVectors() !void { |
| 19 | var a = @Vector(4, bool){ true, false, true, false }; | 19 | var a = @Vector(4, bool){ true, false, true, false }; |
| 20 | var b = @Vector(4, i32){ -1, 4, 999, -31 }; | 20 | var b = @Vector(4, i32){ -1, 4, 999, -31 }; |
| 21 | var c = @Vector(4, i32){ -5, 1, 0, 1234 }; | 21 | var c = @Vector(4, i32){ -5, 1, 0, 1234 }; |
| 22 | var abc = @select(i32, a, b, c); | 22 | _ = .{ &a, &b, &c }; |
| 23 | const abc = @select(i32, a, b, c); | ||
| 23 | try expect(abc[0] == -1); | 24 | try expect(abc[0] == -1); |
| 24 | try expect(abc[1] == 1); | 25 | try expect(abc[1] == 1); |
| 25 | try expect(abc[2] == 999); | 26 | try expect(abc[2] == 999); |
| ... | @@ -28,7 +29,8 @@ fn selectVectors() !void { | ... | @@ -28,7 +29,8 @@ fn selectVectors() !void { |
| 28 | var x = @Vector(4, bool){ false, false, false, true }; | 29 | var x = @Vector(4, bool){ false, false, false, true }; |
| 29 | var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 }; | 30 | var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 }; |
| 30 | var z = @Vector(4, f32){ 0.0, 312.1, -145.9, 9993.55 }; | 31 | var z = @Vector(4, f32){ 0.0, 312.1, -145.9, 9993.55 }; |
| 31 | var xyz = @select(f32, x, y, z); | 32 | _ = .{ &x, &y, &z }; |
| 33 | const xyz = @select(f32, x, y, z); | ||
| 32 | try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); | 34 | try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); |
| 33 | } | 35 | } |
| 34 | 36 | ||
| ... | @@ -48,7 +50,8 @@ fn selectArrays() !void { | ... | @@ -48,7 +50,8 @@ fn selectArrays() !void { |
| 48 | var a = [4]bool{ false, true, false, true }; | 50 | var a = [4]bool{ false, true, false, true }; |
| 49 | var b = [4]usize{ 0, 1, 2, 3 }; | 51 | var b = [4]usize{ 0, 1, 2, 3 }; |
| 50 | var c = [4]usize{ 4, 5, 6, 7 }; | 52 | var c = [4]usize{ 4, 5, 6, 7 }; |
| 51 | var abc = @select(usize, a, b, c); | 53 | _ = .{ &a, &b, &c }; |
| 54 | const abc = @select(usize, a, b, c); | ||
| 52 | try expect(abc[0] == 4); | 55 | try expect(abc[0] == 4); |
| 53 | try expect(abc[1] == 1); | 56 | try expect(abc[1] == 1); |
| 54 | try expect(abc[2] == 6); | 57 | try expect(abc[2] == 6); |
| ... | @@ -57,6 +60,7 @@ fn selectArrays() !void { | ... | @@ -57,6 +60,7 @@ fn selectArrays() !void { |
| 57 | var x = [4]bool{ false, false, false, true }; | 60 | var x = [4]bool{ false, false, false, true }; |
| 58 | var y = [4]f32{ 0.001, 33.4, 836, -3381.233 }; | 61 | var y = [4]f32{ 0.001, 33.4, 836, -3381.233 }; |
| 59 | var z = [4]f32{ 0.0, 312.1, -145.9, 9993.55 }; | 62 | var z = [4]f32{ 0.0, 312.1, -145.9, 9993.55 }; |
| 60 | var xyz = @select(f32, x, y, z); | 63 | _ = .{ &x, &y, &z }; |
| 64 | const xyz = @select(f32, x, y, z); | ||
| 61 | try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); | 65 | try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); |
| 62 | } | 66 | } |
test/behavior/shuffle.zig+10-2| ... | @@ -13,7 +13,9 @@ test "@shuffle int" { | ... | @@ -13,7 +13,9 @@ test "@shuffle int" { |
| 13 | const S = struct { | 13 | const S = struct { |
| 14 | fn doTheTest() !void { | 14 | fn doTheTest() !void { |
| 15 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; | 15 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 16 | _ = &v; | ||
| 16 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; | 17 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 18 | _ = &x; | ||
| 17 | const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; | 19 | const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; |
| 18 | var res = @shuffle(i32, v, x, mask); | 20 | var res = @shuffle(i32, v, x, mask); |
| 19 | try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); | 21 | try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); |
| ... | @@ -29,12 +31,14 @@ test "@shuffle int" { | ... | @@ -29,12 +31,14 @@ test "@shuffle int" { |
| 29 | 31 | ||
| 30 | // Upcasting of b | 32 | // Upcasting of b |
| 31 | var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; | 33 | var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; |
| 34 | _ = &v2; | ||
| 32 | const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; | 35 | const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; |
| 33 | res = @shuffle(i32, x, v2, mask3); | 36 | res = @shuffle(i32, x, v2, mask3); |
| 34 | try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 })); | 37 | try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 })); |
| 35 | 38 | ||
| 36 | // Upcasting of a | 39 | // Upcasting of a |
| 37 | var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; | 40 | var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; |
| 41 | _ = &v3; | ||
| 38 | const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; | 42 | const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; |
| 39 | res = @shuffle(i32, v3, x, mask4); | 43 | res = @shuffle(i32, v3, x, mask4); |
| 40 | try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 })); | 44 | try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 })); |
| ... | @@ -55,9 +59,11 @@ test "@shuffle bool 1" { | ... | @@ -55,9 +59,11 @@ test "@shuffle bool 1" { |
| 55 | const S = struct { | 59 | const S = struct { |
| 56 | fn doTheTest() !void { | 60 | fn doTheTest() !void { |
| 57 | var x: @Vector(4, bool) = [4]bool{ false, true, false, true }; | 61 | var x: @Vector(4, bool) = [4]bool{ false, true, false, true }; |
| 62 | _ = &x; | ||
| 58 | var v: @Vector(2, bool) = [2]bool{ true, false }; | 63 | var v: @Vector(2, bool) = [2]bool{ true, false }; |
| 64 | _ = &v; | ||
| 59 | const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; | 65 | const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; |
| 60 | var res = @shuffle(bool, x, v, mask); | 66 | const res = @shuffle(bool, x, v, mask); |
| 61 | try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); | 67 | try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); |
| 62 | } | 68 | } |
| 63 | }; | 69 | }; |
| ... | @@ -81,9 +87,11 @@ test "@shuffle bool 2" { | ... | @@ -81,9 +87,11 @@ test "@shuffle bool 2" { |
| 81 | const S = struct { | 87 | const S = struct { |
| 82 | fn doTheTest() !void { | 88 | fn doTheTest() !void { |
| 83 | var x: @Vector(3, bool) = [3]bool{ false, true, false }; | 89 | var x: @Vector(3, bool) = [3]bool{ false, true, false }; |
| 90 | _ = &x; | ||
| 84 | var v: @Vector(2, bool) = [2]bool{ true, false }; | 91 | var v: @Vector(2, bool) = [2]bool{ true, false }; |
| 92 | _ = &v; | ||
| 85 | const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; | 93 | const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; |
| 86 | var res = @shuffle(bool, x, v, mask); | 94 | const res = @shuffle(bool, x, v, mask); |
| 87 | try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); | 95 | try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); |
| 88 | } | 96 | } |
| 89 | }; | 97 | }; |
test/behavior/sizeof_and_typeof.zig+6| ... | @@ -22,20 +22,24 @@ test "@TypeOf() with multiple arguments" { | ... | @@ -22,20 +22,24 @@ test "@TypeOf() with multiple arguments" { |
| 22 | var var_1: u32 = undefined; | 22 | var var_1: u32 = undefined; |
| 23 | var var_2: u8 = undefined; | 23 | var var_2: u8 = undefined; |
| 24 | var var_3: u64 = undefined; | 24 | var var_3: u64 = undefined; |
| 25 | _ = .{ &var_1, &var_2, &var_3 }; | ||
| 25 | try comptime expect(@TypeOf(var_1, var_2, var_3) == u64); | 26 | try comptime expect(@TypeOf(var_1, var_2, var_3) == u64); |
| 26 | } | 27 | } |
| 27 | { | 28 | { |
| 28 | var var_1: f16 = undefined; | 29 | var var_1: f16 = undefined; |
| 29 | var var_2: f32 = undefined; | 30 | var var_2: f32 = undefined; |
| 30 | var var_3: f64 = undefined; | 31 | var var_3: f64 = undefined; |
| 32 | _ = .{ &var_1, &var_2, &var_3 }; | ||
| 31 | try comptime expect(@TypeOf(var_1, var_2, var_3) == f64); | 33 | try comptime expect(@TypeOf(var_1, var_2, var_3) == f64); |
| 32 | } | 34 | } |
| 33 | { | 35 | { |
| 34 | var var_1: u16 = undefined; | 36 | var var_1: u16 = undefined; |
| 37 | _ = &var_1; | ||
| 35 | try comptime expect(@TypeOf(var_1, 0xffff) == u16); | 38 | try comptime expect(@TypeOf(var_1, 0xffff) == u16); |
| 36 | } | 39 | } |
| 37 | { | 40 | { |
| 38 | var var_1: f32 = undefined; | 41 | var var_1: f32 = undefined; |
| 42 | _ = &var_1; | ||
| 39 | try comptime expect(@TypeOf(var_1, 3.1415) == f32); | 43 | try comptime expect(@TypeOf(var_1, 3.1415) == f32); |
| 40 | } | 44 | } |
| 41 | } | 45 | } |
| ... | @@ -269,6 +273,7 @@ test "runtime instructions inside typeof in comptime only scope" { | ... | @@ -269,6 +273,7 @@ test "runtime instructions inside typeof in comptime only scope" { |
| 269 | 273 | ||
| 270 | { | 274 | { |
| 271 | var y: i8 = 2; | 275 | var y: i8 = 2; |
| 276 | _ = &y; | ||
| 272 | const i: [2]i8 = [_]i8{ 1, y }; | 277 | const i: [2]i8 = [_]i8{ 1, y }; |
| 273 | const T = struct { | 278 | const T = struct { |
| 274 | a: @TypeOf(i) = undefined, // causes crash | 279 | a: @TypeOf(i) = undefined, // causes crash |
| ... | @@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" { | ... | @@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" { |
| 279 | } | 284 | } |
| 280 | { | 285 | { |
| 281 | var y: i8 = 2; | 286 | var y: i8 = 2; |
| 287 | _ = &y; | ||
| 282 | const i = .{ 1, y }; | 288 | const i = .{ 1, y }; |
| 283 | const T = struct { | 289 | const T = struct { |
| 284 | b: @TypeOf(i[1]) = undefined, | 290 | b: @TypeOf(i[1]) = undefined, |
test/behavior/slice.zig+44-32| ... | @@ -23,7 +23,7 @@ comptime { | ... | @@ -23,7 +23,7 @@ comptime { |
| 23 | }; | 23 | }; |
| 24 | const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong }; | 24 | const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong }; |
| 25 | const list: []const type = &unsigned; | 25 | const list: []const type = &unsigned; |
| 26 | var pos = S.indexOfScalar(type, list, c_ulong).?; | 26 | const pos = S.indexOfScalar(type, list, c_ulong).?; |
| 27 | if (pos != 1) @compileError("bad pos"); | 27 | if (pos != 1) @compileError("bad pos"); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| ... | @@ -36,13 +36,14 @@ test "slicing" { | ... | @@ -36,13 +36,14 @@ test "slicing" { |
| 36 | 36 | ||
| 37 | var slice = array[5..10]; | 37 | var slice = array[5..10]; |
| 38 | 38 | ||
| 39 | if (slice.len != 5) unreachable; | 39 | try expect(slice.len == 5); |
| 40 | 40 | ||
| 41 | const ptr = &slice[0]; | 41 | const ptr = &slice[0]; |
| 42 | if (ptr.* != 1234) unreachable; | 42 | try expect(ptr.* == 1234); |
| 43 | 43 | ||
| 44 | var slice_rest = array[10..]; | 44 | var slice_rest = array[10..]; |
| 45 | if (slice_rest.len != 10) unreachable; | 45 | _ = &slice_rest; |
| 46 | try expect(slice_rest.len == 10); | ||
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | test "const slice" { | 49 | test "const slice" { |
| ... | @@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" { | ... | @@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" { |
| 79 | const S = struct { | 80 | const S = struct { |
| 80 | fn doTheTest() !void { | 81 | fn doTheTest() !void { |
| 81 | var slice: [:0]const u8 = "hello"; | 82 | var slice: [:0]const u8 = "hello"; |
| 82 | 83 | _ = &slice; | |
| 83 | try expect(slice.len == 5); | 84 | try expect(slice.len == 5); |
| 84 | try expect(slice[5] == 0); | 85 | try expect(slice[5] == 0); |
| 85 | } | 86 | } |
| ... | @@ -208,6 +209,7 @@ test "slice string literal has correct type" { | ... | @@ -208,6 +209,7 @@ test "slice string literal has correct type" { |
| 208 | try expect(@TypeOf(array[0..]) == *const [4]i32); | 209 | try expect(@TypeOf(array[0..]) == *const [4]i32); |
| 209 | } | 210 | } |
| 210 | var runtime_zero: usize = 0; | 211 | var runtime_zero: usize = 0; |
| 212 | _ = &runtime_zero; | ||
| 211 | try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); | 213 | try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); |
| 212 | const array = [_]i32{ 1, 2, 3, 4 }; | 214 | const array = [_]i32{ 1, 2, 3, 4 }; |
| 213 | try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32); | 215 | try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32); |
| ... | @@ -219,7 +221,8 @@ test "result location zero sized array inside struct field implicit cast to slic | ... | @@ -219,7 +221,8 @@ test "result location zero sized array inside struct field implicit cast to slic |
| 219 | const E = struct { | 221 | const E = struct { |
| 220 | entries: []u32, | 222 | entries: []u32, |
| 221 | }; | 223 | }; |
| 222 | var foo = E{ .entries = &[_]u32{} }; | 224 | var foo: E = .{ .entries = &[_]u32{} }; |
| 225 | _ = &foo; | ||
| 223 | try expect(foo.entries.len == 0); | 226 | try expect(foo.entries.len == 0); |
| 224 | } | 227 | } |
| 225 | 228 | ||
| ... | @@ -242,7 +245,8 @@ test "C pointer" { | ... | @@ -242,7 +245,8 @@ test "C pointer" { |
| 242 | 245 | ||
| 243 | var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf"; | 246 | var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf"; |
| 244 | var len: u32 = 10; | 247 | var len: u32 = 10; |
| 245 | var slice = buf[0..len]; | 248 | _ = &len; |
| 249 | const slice = buf[0..len]; | ||
| 246 | try expect(mem.eql(u8, "kjdhfkjdhf", slice)); | 250 | try expect(mem.eql(u8, "kjdhfkjdhf", slice)); |
| 247 | } | 251 | } |
| 248 | 252 | ||
| ... | @@ -255,6 +259,7 @@ test "C pointer slice access" { | ... | @@ -255,6 +259,7 @@ test "C pointer slice access" { |
| 255 | const c_ptr = @as([*c]const u32, @ptrCast(&buf)); | 259 | const c_ptr = @as([*c]const u32, @ptrCast(&buf)); |
| 256 | 260 | ||
| 257 | var runtime_zero: usize = 0; | 261 | var runtime_zero: usize = 0; |
| 262 | _ = &runtime_zero; | ||
| 258 | try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); | 263 | try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); |
| 259 | try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); | 264 | try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); |
| 260 | 265 | ||
| ... | @@ -306,11 +311,13 @@ test "obtaining a null terminated slice" { | ... | @@ -306,11 +311,13 @@ test "obtaining a null terminated slice" { |
| 306 | _ = ptr; | 311 | _ = ptr; |
| 307 | 312 | ||
| 308 | var runtime_len: usize = 3; | 313 | var runtime_len: usize = 3; |
| 314 | _ = &runtime_len; | ||
| 309 | const ptr2 = buf[0..runtime_len :0]; | 315 | const ptr2 = buf[0..runtime_len :0]; |
| 310 | // ptr2 is a null-terminated slice | 316 | // ptr2 is a null-terminated slice |
| 311 | try comptime expect(@TypeOf(ptr2) == [:0]u8); | 317 | try comptime expect(@TypeOf(ptr2) == [:0]u8); |
| 312 | try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8); | 318 | try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8); |
| 313 | var runtime_zero: usize = 0; | 319 | var runtime_zero: usize = 0; |
| 320 | _ = &runtime_zero; | ||
| 314 | try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8); | 321 | try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8); |
| 315 | } | 322 | } |
| 316 | 323 | ||
| ... | @@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" { | ... | @@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" { |
| 338 | const S = struct { | 345 | const S = struct { |
| 339 | fn doTheTest() !void { | 346 | fn doTheTest() !void { |
| 340 | var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff }; | 347 | var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 341 | var slice: []align(@alignOf(u16)) u8 = &array; | 348 | const slice: []align(@alignOf(u16)) u8 = &array; |
| 342 | var ptr = @as(*u16, @ptrCast(slice)); | 349 | const ptr: *u16 = @ptrCast(slice); |
| 343 | try expect(ptr.* == 65535); | 350 | try expect(ptr.* == 65535); |
| 344 | } | 351 | } |
| 345 | }; | 352 | }; |
| ... | @@ -357,8 +364,8 @@ test "slice multi-pointer without end" { | ... | @@ -357,8 +364,8 @@ test "slice multi-pointer without end" { |
| 357 | 364 | ||
| 358 | fn testPointer() !void { | 365 | fn testPointer() !void { |
| 359 | var array = [5]u8{ 1, 2, 3, 4, 5 }; | 366 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 360 | var pointer: [*]u8 = &array; | 367 | const pointer: [*]u8 = &array; |
| 361 | var slice = pointer[1..]; | 368 | const slice = pointer[1..]; |
| 362 | try comptime expect(@TypeOf(slice) == [*]u8); | 369 | try comptime expect(@TypeOf(slice) == [*]u8); |
| 363 | try expect(slice[0] == 2); | 370 | try expect(slice[0] == 2); |
| 364 | try expect(slice[1] == 3); | 371 | try expect(slice[1] == 3); |
| ... | @@ -366,13 +373,13 @@ test "slice multi-pointer without end" { | ... | @@ -366,13 +373,13 @@ test "slice multi-pointer without end" { |
| 366 | 373 | ||
| 367 | fn testPointerZ() !void { | 374 | fn testPointerZ() !void { |
| 368 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; | 375 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 369 | var pointer: [*:0]u8 = &array; | 376 | const pointer: [*:0]u8 = &array; |
| 370 | 377 | ||
| 371 | try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); | 378 | try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); |
| 372 | try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); | 379 | try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); |
| 373 | try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8); | 380 | try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8); |
| 374 | 381 | ||
| 375 | var slice = pointer[1..]; | 382 | const slice = pointer[1..]; |
| 376 | try comptime expect(@TypeOf(slice) == [*:0]u8); | 383 | try comptime expect(@TypeOf(slice) == [*:0]u8); |
| 377 | try expect(slice[0] == 2); | 384 | try expect(slice[0] == 2); |
| 378 | try expect(slice[1] == 3); | 385 | try expect(slice[1] == 3); |
| ... | @@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" { | ... | @@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 413 | 420 | ||
| 414 | fn testArray() !void { | 421 | fn testArray() !void { |
| 415 | var array = [5]u8{ 1, 2, 3, 4, 5 }; | 422 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 416 | var slice = array[1..3]; | 423 | const slice = array[1..3]; |
| 417 | try comptime expect(@TypeOf(slice) == *[2]u8); | 424 | try comptime expect(@TypeOf(slice) == *[2]u8); |
| 418 | try expect(slice[0] == 2); | 425 | try expect(slice[0] == 2); |
| 419 | try expect(slice[1] == 3); | 426 | try expect(slice[1] == 3); |
| ... | @@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" { | ... | @@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" { |
| 430 | fn testArray0() !void { | 437 | fn testArray0() !void { |
| 431 | { | 438 | { |
| 432 | var array = [0]u8{}; | 439 | var array = [0]u8{}; |
| 433 | var slice = array[0..0]; | 440 | const slice = array[0..0]; |
| 434 | try comptime expect(@TypeOf(slice) == *[0]u8); | 441 | try comptime expect(@TypeOf(slice) == *[0]u8); |
| 435 | } | 442 | } |
| 436 | { | 443 | { |
| 437 | var array = [0:0]u8{}; | 444 | var array = [0:0]u8{}; |
| 438 | var slice = array[0..0]; | 445 | const slice = array[0..0]; |
| 439 | try comptime expect(@TypeOf(slice) == *[0:0]u8); | 446 | try comptime expect(@TypeOf(slice) == *[0:0]u8); |
| 440 | try expect(slice[0] == 0); | 447 | try expect(slice[0] == 0); |
| 441 | } | 448 | } |
| ... | @@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" { | ... | @@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 443 | 450 | ||
| 444 | fn testArrayAlign() !void { | 451 | fn testArrayAlign() !void { |
| 445 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; | 452 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 446 | var slice = array[4..5]; | 453 | const slice = array[4..5]; |
| 447 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); | 454 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); |
| 448 | try expect(slice[0] == 5); | 455 | try expect(slice[0] == 5); |
| 449 | try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8); | 456 | try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8); |
| ... | @@ -452,7 +459,7 @@ test "slice syntax resulting in pointer-to-array" { | ... | @@ -452,7 +459,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 452 | fn testPointer() !void { | 459 | fn testPointer() !void { |
| 453 | var array = [5]u8{ 1, 2, 3, 4, 5 }; | 460 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 454 | var pointer: [*]u8 = &array; | 461 | var pointer: [*]u8 = &array; |
| 455 | var slice = pointer[1..3]; | 462 | const slice = pointer[1..3]; |
| 456 | try comptime expect(@TypeOf(slice) == *[2]u8); | 463 | try comptime expect(@TypeOf(slice) == *[2]u8); |
| 457 | try expect(slice[0] == 2); | 464 | try expect(slice[0] == 2); |
| 458 | try expect(slice[1] == 3); | 465 | try expect(slice[1] == 3); |
| ... | @@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" { | ... | @@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 467 | 474 | ||
| 468 | fn testPointer0() !void { | 475 | fn testPointer0() !void { |
| 469 | var pointer: [*]const u0 = &[1]u0{0}; | 476 | var pointer: [*]const u0 = &[1]u0{0}; |
| 470 | var slice = pointer[0..1]; | 477 | const slice = pointer[0..1]; |
| 471 | try comptime expect(@TypeOf(slice) == *const [1]u0); | 478 | try comptime expect(@TypeOf(slice) == *const [1]u0); |
| 472 | try expect(slice[0] == 0); | 479 | try expect(slice[0] == 0); |
| 473 | } | 480 | } |
| ... | @@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" { | ... | @@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 475 | fn testPointerAlign() !void { | 482 | fn testPointerAlign() !void { |
| 476 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; | 483 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 477 | var pointer: [*]align(4) u8 = &array; | 484 | var pointer: [*]align(4) u8 = &array; |
| 478 | var slice = pointer[4..5]; | 485 | const slice = pointer[4..5]; |
| 479 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); | 486 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); |
| 480 | try expect(slice[0] == 5); | 487 | try expect(slice[0] == 5); |
| 481 | try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8); | 488 | try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8); |
| ... | @@ -484,7 +491,7 @@ test "slice syntax resulting in pointer-to-array" { | ... | @@ -484,7 +491,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 484 | fn testSlice() !void { | 491 | fn testSlice() !void { |
| 485 | var array = [5]u8{ 1, 2, 3, 4, 5 }; | 492 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 486 | var src_slice: []u8 = &array; | 493 | var src_slice: []u8 = &array; |
| 487 | var slice = src_slice[1..3]; | 494 | const slice = src_slice[1..3]; |
| 488 | try comptime expect(@TypeOf(slice) == *[2]u8); | 495 | try comptime expect(@TypeOf(slice) == *[2]u8); |
| 489 | try expect(slice[0] == 2); | 496 | try expect(slice[0] == 2); |
| 490 | try expect(slice[1] == 3); | 497 | try expect(slice[1] == 3); |
| ... | @@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" { | ... | @@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" { |
| 513 | fn testSliceAlign() !void { | 520 | fn testSliceAlign() !void { |
| 514 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; | 521 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 515 | var src_slice: []align(4) u8 = &array; | 522 | var src_slice: []align(4) u8 = &array; |
| 516 | var slice = src_slice[4..5]; | 523 | const slice = src_slice[4..5]; |
| 517 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); | 524 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); |
| 518 | try expect(slice[0] == 5); | 525 | try expect(slice[0] == 5); |
| 519 | try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); | 526 | try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); |
| ... | @@ -616,13 +623,13 @@ test "slice pointer-to-array zero length" { | ... | @@ -616,13 +623,13 @@ test "slice pointer-to-array zero length" { |
| 616 | { | 623 | { |
| 617 | var array = [0]u8{}; | 624 | var array = [0]u8{}; |
| 618 | var src_slice: []u8 = &array; | 625 | var src_slice: []u8 = &array; |
| 619 | var slice = src_slice[0..0]; | 626 | const slice = src_slice[0..0]; |
| 620 | try expect(@TypeOf(slice) == *[0]u8); | 627 | try expect(@TypeOf(slice) == *[0]u8); |
| 621 | } | 628 | } |
| 622 | { | 629 | { |
| 623 | var array = [0:0]u8{}; | 630 | var array = [0:0]u8{}; |
| 624 | var src_slice: [:0]u8 = &array; | 631 | var src_slice: [:0]u8 = &array; |
| 625 | var slice = src_slice[0..0]; | 632 | const slice = src_slice[0..0]; |
| 626 | try expect(@TypeOf(slice) == *[0:0]u8); | 633 | try expect(@TypeOf(slice) == *[0:0]u8); |
| 627 | } | 634 | } |
| 628 | } | 635 | } |
| ... | @@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" { | ... | @@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" { |
| 630 | { | 637 | { |
| 631 | var array = [0]u8{}; | 638 | var array = [0]u8{}; |
| 632 | var src_slice: []u8 = &array; | 639 | var src_slice: []u8 = &array; |
| 633 | var slice = src_slice[0..0]; | 640 | const slice = src_slice[0..0]; |
| 634 | try comptime expect(@TypeOf(slice) == *[0]u8); | 641 | try comptime expect(@TypeOf(slice) == *[0]u8); |
| 635 | } | 642 | } |
| 636 | { | 643 | { |
| 637 | var array = [0:0]u8{}; | 644 | var array = [0:0]u8{}; |
| 638 | var src_slice: [:0]u8 = &array; | 645 | var src_slice: [:0]u8 = &array; |
| 639 | var slice = src_slice[0..0]; | 646 | const slice = src_slice[0..0]; |
| 640 | try comptime expect(@TypeOf(slice) == *[0]u8); | 647 | try comptime expect(@TypeOf(slice) == *[0]u8); |
| 641 | } | 648 | } |
| 642 | } | 649 | } |
| ... | @@ -655,17 +662,19 @@ test "type coercion of pointer to anon struct literal to pointer to slice" { | ... | @@ -655,17 +662,19 @@ test "type coercion of pointer to anon struct literal to pointer to slice" { |
| 655 | 662 | ||
| 656 | fn doTheTest() !void { | 663 | fn doTheTest() !void { |
| 657 | var x1: u8 = 42; | 664 | var x1: u8 = 42; |
| 665 | _ = &x1; | ||
| 658 | const t1 = &.{ x1, 56, 54 }; | 666 | const t1 = &.{ x1, 56, 54 }; |
| 659 | var slice1: []const u8 = t1; | 667 | const slice1: []const u8 = t1; |
| 660 | try expect(slice1.len == 3); | 668 | try expect(slice1.len == 3); |
| 661 | try expect(slice1[0] == 42); | 669 | try expect(slice1[0] == 42); |
| 662 | try expect(slice1[1] == 56); | 670 | try expect(slice1[1] == 56); |
| 663 | try expect(slice1[2] == 54); | 671 | try expect(slice1[2] == 54); |
| 664 | 672 | ||
| 665 | var x2: []const u8 = "hello"; | 673 | var x2: []const u8 = "hello"; |
| 674 | _ = &x2; | ||
| 666 | const t2 = &.{ x2, ", ", "world!" }; | 675 | const t2 = &.{ x2, ", ", "world!" }; |
| 667 | // @compileLog(@TypeOf(t2)); | 676 | // @compileLog(@TypeOf(t2)); |
| 668 | var slice2: []const []const u8 = t2; | 677 | const slice2: []const []const u8 = t2; |
| 669 | try expect(slice2.len == 3); | 678 | try expect(slice2.len == 3); |
| 670 | try expect(mem.eql(u8, slice2[0], "hello")); | 679 | try expect(mem.eql(u8, slice2[0], "hello")); |
| 671 | try expect(mem.eql(u8, slice2[1], ", ")); | 680 | try expect(mem.eql(u8, slice2[1], ", ")); |
| ... | @@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" { | ... | @@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" { |
| 680 | comptime { | 689 | comptime { |
| 681 | var a: []const u8 = "aoeu"; | 690 | var a: []const u8 = "aoeu"; |
| 682 | var b: []const u8 = "asdf"; | 691 | var b: []const u8 = "asdf"; |
| 692 | _ = .{ &a, &b }; | ||
| 683 | const c = a ++ b; | 693 | const c = a ++ b; |
| 684 | try expect(std.mem.eql(u8, c, "aoeuasdf")); | 694 | try expect(std.mem.eql(u8, c, "aoeuasdf")); |
| 685 | try expect(@TypeOf(c) == *const [8]u8); | 695 | try expect(@TypeOf(c) == *const [8]u8); |
| ... | @@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" { | ... | @@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" { |
| 689 | test "array mult of slice gives ptr to array" { | 699 | test "array mult of slice gives ptr to array" { |
| 690 | comptime { | 700 | comptime { |
| 691 | var a: []const u8 = "aoeu"; | 701 | var a: []const u8 = "aoeu"; |
| 702 | _ = &a; | ||
| 692 | const c = a ** 2; | 703 | const c = a ** 2; |
| 693 | try expect(std.mem.eql(u8, c, "aoeuaoeu")); | 704 | try expect(std.mem.eql(u8, c, "aoeuaoeu")); |
| 694 | try expect(@TypeOf(c) == *const [8]u8); | 705 | try expect(@TypeOf(c) == *const [8]u8); |
| ... | @@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" { | ... | @@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" { |
| 736 | const S = struct { | 747 | const S = struct { |
| 737 | fn do() !void { | 748 | fn do() !void { |
| 738 | var array = [_:0]u8{ 1, 2, 3, 4 }; | 749 | var array = [_:0]u8{ 1, 2, 3, 4 }; |
| 739 | var slice = array[4..5]; | 750 | const slice = array[4..5]; |
| 740 | try expect(slice.len == 1); | 751 | try expect(slice.len == 1); |
| 741 | try expect(slice[0] == 0); | 752 | try expect(slice[0] == 0); |
| 742 | try expect(@TypeOf(slice) == *[1]u8); | 753 | try expect(@TypeOf(slice) == *[1]u8); |
| ... | @@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" { | ... | @@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" { |
| 754 | const S = struct { | 765 | const S = struct { |
| 755 | fn do() !void { | 766 | fn do() !void { |
| 756 | var array = [_:0]u8{ 1, 2, 3, 4 }; | 767 | var array = [_:0]u8{ 1, 2, 3, 4 }; |
| 757 | var src_slice: [:0]u8 = &array; | 768 | const src_slice: [:0]u8 = &array; |
| 758 | var slice = src_slice[4..5]; | 769 | const slice = src_slice[4..5]; |
| 759 | try expect(slice.len == 1); | 770 | try expect(slice.len == 1); |
| 760 | try expect(slice[0] == 0); | 771 | try expect(slice[0] == 0); |
| 761 | try expect(@TypeOf(slice) == *[1]u8); | 772 | try expect(@TypeOf(slice) == *[1]u8); |
| ... | @@ -820,6 +831,7 @@ test "global slice field access" { | ... | @@ -820,6 +831,7 @@ test "global slice field access" { |
| 820 | 831 | ||
| 821 | test "slice of void" { | 832 | test "slice of void" { |
| 822 | var n: usize = 10; | 833 | var n: usize = 10; |
| 834 | _ = &n; | ||
| 823 | var arr: [12]void = undefined; | 835 | var arr: [12]void = undefined; |
| 824 | const slice = @as([]void, &arr)[0..n]; | 836 | const slice = @as([]void, &arr)[0..n]; |
| 825 | try expect(slice.len == n); | 837 | try expect(slice.len == n); |
| ... | @@ -827,7 +839,7 @@ test "slice of void" { | ... | @@ -827,7 +839,7 @@ test "slice of void" { |
| 827 | 839 | ||
| 828 | test "slice with dereferenced value" { | 840 | test "slice with dereferenced value" { |
| 829 | var a: usize = 0; | 841 | var a: usize = 0; |
| 830 | var idx: *usize = &a; | 842 | const idx: *usize = &a; |
| 831 | _ = blk: { | 843 | _ = blk: { |
| 832 | var array = [_]u8{}; | 844 | var array = [_]u8{}; |
| 833 | break :blk array[idx.*..]; | 845 | break :blk array[idx.*..]; |
test/behavior/struct.zig+44-21| ... | @@ -254,7 +254,8 @@ test "struct field init with catch" { | ... | @@ -254,7 +254,8 @@ test "struct field init with catch" { |
| 254 | const S = struct { | 254 | const S = struct { |
| 255 | fn doTheTest() !void { | 255 | fn doTheTest() !void { |
| 256 | var x: anyerror!isize = 1; | 256 | var x: anyerror!isize = 1; |
| 257 | var req = Foo{ | 257 | _ = &x; |
| 258 | const req = Foo{ | ||
| 258 | .field = x catch undefined, | 259 | .field = x catch undefined, |
| 259 | }; | 260 | }; |
| 260 | try expect(req.field == 1); | 261 | try expect(req.field == 1); |
| ... | @@ -505,7 +506,7 @@ test "packed struct fields are ordered from LSB to MSB" { | ... | @@ -505,7 +506,7 @@ test "packed struct fields are ordered from LSB to MSB" { |
| 505 | var all: u64 = 0x7765443322221111; | 506 | var all: u64 = 0x7765443322221111; |
| 506 | var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined; | 507 | var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined; |
| 507 | @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all))); | 508 | @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all))); |
| 508 | var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; | 509 | const bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; |
| 509 | 510 | ||
| 510 | try expect(bitfields.f1 == 0x1111); | 511 | try expect(bitfields.f1 == 0x1111); |
| 511 | try expect(bitfields.f2 == 0x2222); | 512 | try expect(bitfields.f2 == 0x2222); |
| ... | @@ -545,7 +546,7 @@ test "zero-bit field in packed struct" { | ... | @@ -545,7 +546,7 @@ test "zero-bit field in packed struct" { |
| 545 | y: void, | 546 | y: void, |
| 546 | }; | 547 | }; |
| 547 | var x: S = undefined; | 548 | var x: S = undefined; |
| 548 | _ = x; | 549 | _ = &x; |
| 549 | } | 550 | } |
| 550 | 551 | ||
| 551 | test "packed struct with non-ABI-aligned field" { | 552 | test "packed struct with non-ABI-aligned field" { |
| ... | @@ -624,6 +625,7 @@ test "default struct initialization fields" { | ... | @@ -624,6 +625,7 @@ test "default struct initialization fields" { |
| 624 | .b = 5, | 625 | .b = 5, |
| 625 | }; | 626 | }; |
| 626 | var five: i32 = 5; | 627 | var five: i32 = 5; |
| 628 | _ = &five; | ||
| 627 | const y = S{ | 629 | const y = S{ |
| 628 | .b = five, | 630 | .b = five, |
| 629 | }; | 631 | }; |
| ... | @@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" { | ... | @@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" { |
| 714 | }; | 716 | }; |
| 715 | 717 | ||
| 716 | var s = S{ .a = 2, .b = 0 }; | 718 | var s = S{ .a = 2, .b = 0 }; |
| 717 | var b_ptr = &s.b; | 719 | const b_ptr = &s.b; |
| 718 | try expect(s.b == 0); | 720 | try expect(s.b == 0); |
| 719 | b_ptr.* = 2; | 721 | b_ptr.* = 2; |
| 720 | try expect(s.b == 2); | 722 | try expect(s.b == 2); |
| ... | @@ -727,6 +729,7 @@ test "packed struct with u0 field access" { | ... | @@ -727,6 +729,7 @@ test "packed struct with u0 field access" { |
| 727 | f0: u0, | 729 | f0: u0, |
| 728 | }; | 730 | }; |
| 729 | var s = S{ .f0 = 0 }; | 731 | var s = S{ .f0 = 0 }; |
| 732 | _ = &s; | ||
| 730 | try comptime expect(s.f0 == 0); | 733 | try comptime expect(s.f0 == 0); |
| 731 | } | 734 | } |
| 732 | 735 | ||
| ... | @@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" { | ... | @@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" { |
| 788 | 791 | ||
| 789 | const S = struct { | 792 | const S = struct { |
| 790 | fn entry() !void { | 793 | fn entry() !void { |
| 791 | var x = makeBar(10); | 794 | const x = makeBar(10); |
| 792 | try expect(@as(i32, 10) == x.handle); | 795 | try expect(@as(i32, 10) == x.handle); |
| 793 | } | 796 | } |
| 794 | 797 | ||
| ... | @@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" { | ... | @@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" { |
| 827 | var s = &sx; | 830 | var s = &sx; |
| 828 | try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2")); | 831 | try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2")); |
| 829 | var v2 = U{ .Num = 123 }; | 832 | var v2 = U{ .Num = 123 }; |
| 833 | _ = &v2; | ||
| 830 | s.f2 = v2; | 834 | s.f2 = v2; |
| 831 | try expect(s.f2.Num == 123); | 835 | try expect(s.f2.Num == 123); |
| 832 | } | 836 | } |
| ... | @@ -852,7 +856,7 @@ test "packed struct field passed to generic function" { | ... | @@ -852,7 +856,7 @@ test "packed struct field passed to generic function" { |
| 852 | 856 | ||
| 853 | var p: S.P = undefined; | 857 | var p: S.P = undefined; |
| 854 | p.b = 29; | 858 | p.b = 29; |
| 855 | var loaded = S.genericReadPackedField(&p.b); | 859 | const loaded = S.genericReadPackedField(&p.b); |
| 856 | try expect(loaded == 29); | 860 | try expect(loaded == 29); |
| 857 | } | 861 | } |
| 858 | 862 | ||
| ... | @@ -871,6 +875,7 @@ test "anonymous struct literal syntax" { | ... | @@ -871,6 +875,7 @@ test "anonymous struct literal syntax" { |
| 871 | .x = 1, | 875 | .x = 1, |
| 872 | .y = 2, | 876 | .y = 2, |
| 873 | }; | 877 | }; |
| 878 | _ = &p; | ||
| 874 | try expect(p.x == 1); | 879 | try expect(p.x == 1); |
| 875 | try expect(p.y == 2); | 880 | try expect(p.y == 2); |
| 876 | } | 881 | } |
| ... | @@ -920,6 +925,7 @@ test "fully anonymous list literal" { | ... | @@ -920,6 +925,7 @@ test "fully anonymous list literal" { |
| 920 | 925 | ||
| 921 | test "tuple assigned to variable" { | 926 | test "tuple assigned to variable" { |
| 922 | var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) }; | 927 | var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) }; |
| 928 | _ = &vec; | ||
| 923 | try expect(vec.@"0" == 22); | 929 | try expect(vec.@"0" == 22); |
| 924 | try expect(vec.@"1" == 55); | 930 | try expect(vec.@"1" == 55); |
| 925 | try expect(vec.@"2" == 99); | 931 | try expect(vec.@"2" == 99); |
| ... | @@ -940,6 +946,7 @@ test "comptime struct field" { | ... | @@ -940,6 +946,7 @@ test "comptime struct field" { |
| 940 | comptime std.debug.assert(@sizeOf(T) == 4); | 946 | comptime std.debug.assert(@sizeOf(T) == 4); |
| 941 | 947 | ||
| 942 | var foo: T = undefined; | 948 | var foo: T = undefined; |
| 949 | _ = &foo; | ||
| 943 | try comptime expect(foo.b == 1234); | 950 | try comptime expect(foo.b == 1234); |
| 944 | } | 951 | } |
| 945 | 952 | ||
| ... | @@ -950,7 +957,7 @@ test "tuple element initialized with fn call" { | ... | @@ -950,7 +957,7 @@ test "tuple element initialized with fn call" { |
| 950 | 957 | ||
| 951 | const S = struct { | 958 | const S = struct { |
| 952 | fn doTheTest() !void { | 959 | fn doTheTest() !void { |
| 953 | var x = .{foo()}; | 960 | const x = .{foo()}; |
| 954 | try expectEqualSlices(u8, x[0], "hi"); | 961 | try expectEqualSlices(u8, x[0], "hi"); |
| 955 | } | 962 | } |
| 956 | fn foo() []const u8 { | 963 | fn foo() []const u8 { |
| ... | @@ -977,6 +984,7 @@ test "struct with union field" { | ... | @@ -977,6 +984,7 @@ test "struct with union field" { |
| 977 | var True = Value{ | 984 | var True = Value{ |
| 978 | .kind = .{ .Bool = true }, | 985 | .kind = .{ .Bool = true }, |
| 979 | }; | 986 | }; |
| 987 | _ = &True; | ||
| 980 | try expect(@as(u32, 2) == True.ref); | 988 | try expect(@as(u32, 2) == True.ref); |
| 981 | try expect(True.kind.Bool); | 989 | try expect(True.kind.Bool); |
| 982 | } | 990 | } |
| ... | @@ -996,6 +1004,7 @@ test "struct with 0-length union array field" { | ... | @@ -996,6 +1004,7 @@ test "struct with 0-length union array field" { |
| 996 | }; | 1004 | }; |
| 997 | 1005 | ||
| 998 | var s: S = undefined; | 1006 | var s: S = undefined; |
| 1007 | _ = &s; | ||
| 999 | try expectEqual(@as(usize, 0), s.zero_length.len); | 1008 | try expectEqual(@as(usize, 0), s.zero_length.len); |
| 1000 | } | 1009 | } |
| 1001 | 1010 | ||
| ... | @@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" { | ... | @@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" { |
| 1019 | 1028 | ||
| 1020 | fn doTheTest() !void { | 1029 | fn doTheTest() !void { |
| 1021 | var y: u32 = 42; | 1030 | var y: u32 = 42; |
| 1031 | _ = &y; | ||
| 1022 | const t0 = .{ .A = 123, .B = "foo", .C = {} }; | 1032 | const t0 = .{ .A = 123, .B = "foo", .C = {} }; |
| 1023 | const t1 = .{ .A = y, .B = "foo", .C = {} }; | 1033 | const t1 = .{ .A = y, .B = "foo", .C = {} }; |
| 1024 | const y0: S2 = t0; | 1034 | const y0: S2 = t0; |
| 1025 | var y1: S2 = t1; | 1035 | const y1: S2 = t1; |
| 1026 | try expect(y0.A == 123); | 1036 | try expect(y0.A == 123); |
| 1027 | try expect(std.mem.eql(u8, y0.B, "foo")); | 1037 | try expect(std.mem.eql(u8, y0.B, "foo")); |
| 1028 | try expect(y0.C == {}); | 1038 | try expect(y0.C == {}); |
| ... | @@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" { | ... | @@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" { |
| 1057 | 1067 | ||
| 1058 | fn doTheTest() !void { | 1068 | fn doTheTest() !void { |
| 1059 | var y: u32 = 42; | 1069 | var y: u32 = 42; |
| 1070 | _ = &y; | ||
| 1060 | const t0 = &.{ .A = 123, .B = "foo", .C = {} }; | 1071 | const t0 = &.{ .A = 123, .B = "foo", .C = {} }; |
| 1061 | const t1 = &.{ .A = y, .B = "foo", .C = {} }; | 1072 | const t1 = &.{ .A = y, .B = "foo", .C = {} }; |
| 1062 | const y0: *const S2 = t0; | 1073 | const y0: *const S2 = t0; |
| 1063 | var y1: *const S2 = t1; | 1074 | const y1: *const S2 = t1; |
| 1064 | try expect(y0.A == 123); | 1075 | try expect(y0.A == 123); |
| 1065 | try expect(std.mem.eql(u8, y0.B, "foo")); | 1076 | try expect(std.mem.eql(u8, y0.B, "foo")); |
| 1066 | try expect(y0.C == {}); | 1077 | try expect(y0.C == {}); |
| ... | @@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" { | ... | @@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" { |
| 1161 | } | 1172 | } |
| 1162 | 1173 | ||
| 1163 | fn doTheTest() !void { | 1174 | fn doTheTest() !void { |
| 1164 | var a = try (try foo()).?; | 1175 | const a = try (try foo()).?; |
| 1165 | var b = try bar().?; | 1176 | const b = try bar().?; |
| 1166 | try expect(a.a + b[1] == 3); | 1177 | try expect(a.a + b[1] == 3); |
| 1167 | } | 1178 | } |
| 1168 | }; | 1179 | }; |
| ... | @@ -1227,8 +1238,8 @@ test "typed init through error unions and optionals" { | ... | @@ -1227,8 +1238,8 @@ test "typed init through error unions and optionals" { |
| 1227 | } | 1238 | } |
| 1228 | 1239 | ||
| 1229 | fn doTheTest() !void { | 1240 | fn doTheTest() !void { |
| 1230 | var a = try (try foo()).?; | 1241 | const a = try (try foo()).?; |
| 1231 | var b = try bar().?; | 1242 | const b = try bar().?; |
| 1232 | try expect(a.a + b[1] == 3); | 1243 | try expect(a.a + b[1] == 3); |
| 1233 | } | 1244 | } |
| 1234 | }; | 1245 | }; |
| ... | @@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" { | ... | @@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" { |
| 1243 | 1254 | ||
| 1244 | const S = struct { x: i32 = 1234 }; | 1255 | const S = struct { x: i32 = 1234 }; |
| 1245 | var s: S = .{}; | 1256 | var s: S = .{}; |
| 1257 | _ = &s; | ||
| 1246 | try expect(s.x == 1234); | 1258 | try expect(s.x == 1234); |
| 1247 | } | 1259 | } |
| 1248 | 1260 | ||
| ... | @@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" { | ... | @@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" { |
| 1301 | fn doTheTest() !void { | 1313 | fn doTheTest() !void { |
| 1302 | const S = packed struct { a: u30 }; | 1314 | const S = packed struct { a: u30 }; |
| 1303 | var s1: S = .{ .a = 1 }; | 1315 | var s1: S = .{ .a = 1 }; |
| 1304 | var s2 = &s1; | 1316 | const s2 = &s1; |
| 1305 | try expect(s2.a == 1); | 1317 | try expect(s2.a == 1); |
| 1306 | var s3: S = undefined; | 1318 | var s3: S = undefined; |
| 1307 | var s4 = &s3; | 1319 | const s4 = &s3; |
| 1308 | _ = s4; | 1320 | _ = s4; |
| 1309 | } | 1321 | } |
| 1310 | }; | 1322 | }; |
| ... | @@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" { | ... | @@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" { |
| 1343 | }; | 1355 | }; |
| 1344 | }; | 1356 | }; |
| 1345 | var s: namespace.S = .{ .blah = 1234 }; | 1357 | var s: namespace.S = .{ .blah = 1234 }; |
| 1358 | _ = &s; | ||
| 1346 | try expect(s.size == 4); | 1359 | try expect(s.size == 4); |
| 1347 | } | 1360 | } |
| 1348 | 1361 | ||
| ... | @@ -1362,6 +1375,7 @@ test "under-aligned struct field" { | ... | @@ -1362,6 +1375,7 @@ test "under-aligned struct field" { |
| 1362 | data: U align(4), | 1375 | data: U align(4), |
| 1363 | }; | 1376 | }; |
| 1364 | var runtime: usize = 1234; | 1377 | var runtime: usize = 1234; |
| 1378 | _ = &runtime; | ||
| 1365 | const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; | 1379 | const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; |
| 1366 | const array = @as(*const [12]u8, @ptrCast(ptr)); | 1380 | const array = @as(*const [12]u8, @ptrCast(ptr)); |
| 1367 | const result = std.mem.readInt(u64, array[4..12], native_endian); | 1381 | const result = std.mem.readInt(u64, array[4..12], native_endian); |
| ... | @@ -1509,6 +1523,7 @@ test "function pointer in struct returns the struct" { | ... | @@ -1509,6 +1523,7 @@ test "function pointer in struct returns the struct" { |
| 1509 | } | 1523 | } |
| 1510 | }; | 1524 | }; |
| 1511 | var a = A.f(); | 1525 | var a = A.f(); |
| 1526 | _ = &a; | ||
| 1512 | try expect(a.f == A.f); | 1527 | try expect(a.f == A.f); |
| 1513 | } | 1528 | } |
| 1514 | 1529 | ||
| ... | @@ -1538,7 +1553,8 @@ test "optional field init with tuple" { | ... | @@ -1538,7 +1553,8 @@ test "optional field init with tuple" { |
| 1538 | a: ?struct { b: u32 }, | 1553 | a: ?struct { b: u32 }, |
| 1539 | }; | 1554 | }; |
| 1540 | var a: u32 = 0; | 1555 | var a: u32 = 0; |
| 1541 | var b = S{ | 1556 | _ = &a; |
| 1557 | const b = S{ | ||
| 1542 | .a = .{ .b = a }, | 1558 | .a = .{ .b = a }, |
| 1543 | }; | 1559 | }; |
| 1544 | try expect(b.a.?.b == a); | 1560 | try expect(b.a.?.b == a); |
| ... | @@ -1550,7 +1566,8 @@ test "if inside struct init inside if" { | ... | @@ -1550,7 +1566,8 @@ test "if inside struct init inside if" { |
| 1550 | const MyStruct = struct { x: u32 }; | 1566 | const MyStruct = struct { x: u32 }; |
| 1551 | const b: u32 = 5; | 1567 | const b: u32 = 5; |
| 1552 | var i: u32 = 1; | 1568 | var i: u32 = 1; |
| 1553 | var my_var = if (i < 5) | 1569 | _ = &i; |
| 1570 | const my_var = if (i < 5) | ||
| 1554 | MyStruct{ | 1571 | MyStruct{ |
| 1555 | .x = 1 + if (i > 0) b else 0, | 1572 | .x = 1 + if (i > 0) b else 0, |
| 1556 | } | 1573 | } |
| ... | @@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" { | ... | @@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" { |
| 1599 | var things = struct { | 1616 | var things = struct { |
| 1600 | comptime foo: i8 = 1, | 1617 | comptime foo: i8 = 1, |
| 1601 | }{}; | 1618 | }{}; |
| 1602 | 1619 | _ = &things; | |
| 1603 | comptime std.debug.assert(things.foo == 1); | 1620 | comptime std.debug.assert(things.foo == 1); |
| 1604 | } | 1621 | } |
| 1605 | 1622 | ||
| ... | @@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" { | ... | @@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" { |
| 1608 | comptime foo: i8 = 1, | 1625 | comptime foo: i8 = 1, |
| 1609 | }; | 1626 | }; |
| 1610 | var things = T{}; | 1627 | var things = T{}; |
| 1611 | 1628 | _ = &things; | |
| 1612 | comptime std.debug.assert(things.foo == 1); | 1629 | comptime std.debug.assert(things.foo == 1); |
| 1613 | } | 1630 | } |
| 1614 | 1631 | ||
| ... | @@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" { | ... | @@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" { |
| 1616 | var things: struct { | 1633 | var things: struct { |
| 1617 | comptime foo: i8 = 1, | 1634 | comptime foo: i8 = 1, |
| 1618 | } = .{}; | 1635 | } = .{}; |
| 1619 | 1636 | _ = &things; | |
| 1620 | comptime std.debug.assert(things.foo == 1); | 1637 | comptime std.debug.assert(things.foo == 1); |
| 1621 | } | 1638 | } |
| 1622 | 1639 | ||
| ... | @@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" { | ... | @@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" { |
| 1624 | var things: struct { | 1641 | var things: struct { |
| 1625 | comptime foo: i8 = 1, | 1642 | comptime foo: i8 = 1, |
| 1626 | } = undefined; // Segmentation fault at address 0x0 | 1643 | } = undefined; // Segmentation fault at address 0x0 |
| 1627 | 1644 | _ = &things; | |
| 1628 | comptime std.debug.assert(things.foo == 1); | 1645 | comptime std.debug.assert(things.foo == 1); |
| 1629 | } | 1646 | } |
| 1630 | } | 1647 | } |
| ... | @@ -1755,6 +1772,7 @@ test "runtime side-effects in comptime-known struct init" { | ... | @@ -1755,6 +1772,7 @@ test "runtime side-effects in comptime-known struct init" { |
| 1755 | test "pointer to struct initialized through reference to anonymous initializer provides result types" { | 1772 | test "pointer to struct initialized through reference to anonymous initializer provides result types" { |
| 1756 | const S = struct { a: u8, b: u16, c: *const anyopaque }; | 1773 | const S = struct { a: u8, b: u16, c: *const anyopaque }; |
| 1757 | var my_u16: u16 = 0xABCD; | 1774 | var my_u16: u16 = 0xABCD; |
| 1775 | _ = &my_u16; | ||
| 1758 | const s: *const S = &.{ | 1776 | const s: *const S = &.{ |
| 1759 | // intentionally out of order | 1777 | // intentionally out of order |
| 1760 | .c = @ptrCast("hello"), | 1778 | .c = @ptrCast("hello"), |
| ... | @@ -1792,6 +1810,7 @@ test "initializer uses own alignment" { | ... | @@ -1792,6 +1810,7 @@ test "initializer uses own alignment" { |
| 1792 | }; | 1810 | }; |
| 1793 | 1811 | ||
| 1794 | var s: S = .{}; | 1812 | var s: S = .{}; |
| 1813 | _ = &s; | ||
| 1795 | try expectEqual(4, @alignOf(S)); | 1814 | try expectEqual(4, @alignOf(S)); |
| 1796 | try expectEqual(@as(usize, 5), s.x); | 1815 | try expectEqual(@as(usize, 5), s.x); |
| 1797 | } | 1816 | } |
| ... | @@ -1802,6 +1821,7 @@ test "initializer uses own size" { | ... | @@ -1802,6 +1821,7 @@ test "initializer uses own size" { |
| 1802 | }; | 1821 | }; |
| 1803 | 1822 | ||
| 1804 | var s: S = .{}; | 1823 | var s: S = .{}; |
| 1824 | _ = &s; | ||
| 1805 | try expectEqual(4, @sizeOf(S)); | 1825 | try expectEqual(4, @sizeOf(S)); |
| 1806 | try expectEqual(@as(usize, 5), s.x); | 1826 | try expectEqual(@as(usize, 5), s.x); |
| 1807 | } | 1827 | } |
| ... | @@ -1815,6 +1835,7 @@ test "initializer takes a pointer to a variable inside its struct" { | ... | @@ -1815,6 +1835,7 @@ test "initializer takes a pointer to a variable inside its struct" { |
| 1815 | 1835 | ||
| 1816 | fn doTheTest() !void { | 1836 | fn doTheTest() !void { |
| 1817 | var foo: S = .{}; | 1837 | var foo: S = .{}; |
| 1838 | _ = &foo; | ||
| 1818 | try expectEqual(&S.instance, foo.s); | 1839 | try expectEqual(&S.instance, foo.s); |
| 1819 | } | 1840 | } |
| 1820 | }; | 1841 | }; |
| ... | @@ -1839,6 +1860,7 @@ test "circular dependency through pointer field of a struct" { | ... | @@ -1839,6 +1860,7 @@ test "circular dependency through pointer field of a struct" { |
| 1839 | }; | 1860 | }; |
| 1840 | }; | 1861 | }; |
| 1841 | var outer: S.StructOuter = .{}; | 1862 | var outer: S.StructOuter = .{}; |
| 1863 | _ = &outer; | ||
| 1842 | try expect(outer.middle.outer == null); | 1864 | try expect(outer.middle.outer == null); |
| 1843 | try expect(outer.middle.inner == null); | 1865 | try expect(outer.middle.inner == null); |
| 1844 | } | 1866 | } |
| ... | @@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" { | ... | @@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" { |
| 1855 | } | 1877 | } |
| 1856 | }; | 1878 | }; |
| 1857 | var s: S = .{}; | 1879 | var s: S = .{}; |
| 1880 | _ = &s; | ||
| 1858 | try expect(s.x == 123); | 1881 | try expect(s.x == 123); |
| 1859 | } | 1882 | } |
test/behavior/struct_contains_null_ptr_itself.zig+1| ... | @@ -7,6 +7,7 @@ test "struct contains null pointer which contains original struct" { | ... | @@ -7,6 +7,7 @@ test "struct contains null pointer which contains original struct" { |
| 7 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 7 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 8 | 8 | ||
| 9 | var x: ?*NodeLineComment = null; | 9 | var x: ?*NodeLineComment = null; |
| 10 | _ = &x; | ||
| 10 | try expect(x == null); | 11 | try expect(x == null); |
| 11 | } | 12 | } |
| 12 | 13 |
test/behavior/switch.zig+17-9| ... | @@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool { | ... | @@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool { |
| 157 | 157 | ||
| 158 | test "u0" { | 158 | test "u0" { |
| 159 | var val: u0 = 0; | 159 | var val: u0 = 0; |
| 160 | _ = &val; | ||
| 160 | switch (val) { | 161 | switch (val) { |
| 161 | 0 => try expect(val == 0), | 162 | 0 => try expect(val == 0), |
| 162 | } | 163 | } |
| ... | @@ -164,6 +165,7 @@ test "u0" { | ... | @@ -164,6 +165,7 @@ test "u0" { |
| 164 | 165 | ||
| 165 | test "undefined.u0" { | 166 | test "undefined.u0" { |
| 166 | var val: u0 = undefined; | 167 | var val: u0 = undefined; |
| 168 | _ = &val; | ||
| 167 | switch (val) { | 169 | switch (val) { |
| 168 | 0 => try expect(val == 0), | 170 | 0 => try expect(val == 0), |
| 169 | } | 171 | } |
| ... | @@ -173,6 +175,7 @@ test "switch with disjoint range" { | ... | @@ -173,6 +175,7 @@ test "switch with disjoint range" { |
| 173 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 175 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 174 | 176 | ||
| 175 | var q: u8 = 0; | 177 | var q: u8 = 0; |
| 178 | _ = &q; | ||
| 176 | switch (q) { | 179 | switch (q) { |
| 177 | 0...125 => {}, | 180 | 0...125 => {}, |
| 178 | 127...255 => {}, | 181 | 127...255 => {}, |
| ... | @@ -183,12 +186,8 @@ test "switch with disjoint range" { | ... | @@ -183,12 +186,8 @@ test "switch with disjoint range" { |
| 183 | test "switch variable for range and multiple prongs" { | 186 | test "switch variable for range and multiple prongs" { |
| 184 | const S = struct { | 187 | const S = struct { |
| 185 | fn doTheTest() !void { | 188 | fn doTheTest() !void { |
| 186 | var u: u8 = 16; | 189 | try doTheSwitch(16); |
| 187 | try doTheSwitch(u); | 190 | try doTheSwitch(42); |
| 188 | try comptime doTheSwitch(u); | ||
| 189 | var v: u8 = 42; | ||
| 190 | try doTheSwitch(v); | ||
| 191 | try comptime doTheSwitch(v); | ||
| 192 | } | 191 | } |
| 193 | fn doTheSwitch(q: u8) !void { | 192 | fn doTheSwitch(q: u8) !void { |
| 194 | switch (q) { | 193 | switch (q) { |
| ... | @@ -198,7 +197,8 @@ test "switch variable for range and multiple prongs" { | ... | @@ -198,7 +197,8 @@ test "switch variable for range and multiple prongs" { |
| 198 | } | 197 | } |
| 199 | } | 198 | } |
| 200 | }; | 199 | }; |
| 201 | _ = S; | 200 | try S.doTheTest(); |
| 201 | try comptime S.doTheTest(); | ||
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | var state: u32 = 0; | 204 | var state: u32 = 0; |
| ... | @@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" { | ... | @@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" { |
| 322 | }; | 322 | }; |
| 323 | 323 | ||
| 324 | var x: X = X{ .b = 10 }; | 324 | var x: X = X{ .b = 10 }; |
| 325 | var y: i32 = switch (x) { | 325 | _ = &x; |
| 326 | const y: i32 = switch (x) { | ||
| 326 | .a => unreachable, | 327 | .a => unreachable, |
| 327 | .b => |b| b + 1, | 328 | .b => |b| b + 1, |
| 328 | }; | 329 | }; |
| ... | @@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" { | ... | @@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" { |
| 357 | }; | 358 | }; |
| 358 | 359 | ||
| 359 | var foo = Foo{ .a = 1234 }; | 360 | var foo = Foo{ .a = 1234 }; |
| 361 | _ = &foo; | ||
| 360 | switch (foo) { | 362 | switch (foo) { |
| 361 | .a => |x| { | 363 | .a => |x| { |
| 362 | try expect(x == 1234); | 364 | try expect(x == 1234); |
| ... | @@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" { | ... | @@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" { |
| 406 | const S = struct { | 408 | const S = struct { |
| 407 | fn doTheTest() !void { | 409 | fn doTheTest() !void { |
| 408 | var x: i32 = 5; | 410 | var x: i32 = 5; |
| 411 | _ = &x; | ||
| 409 | switch (x + 10) { | 412 | switch (x + 10) { |
| 410 | 14 => @panic("fail"), | 413 | 14 => @panic("fail"), |
| 411 | 16 => @panic("fail"), | 414 | 16 => @panic("fail"), |
| ... | @@ -606,6 +609,7 @@ test "switch on error set with single else" { | ... | @@ -606,6 +609,7 @@ test "switch on error set with single else" { |
| 606 | const S = struct { | 609 | const S = struct { |
| 607 | fn doTheTest() !void { | 610 | fn doTheTest() !void { |
| 608 | var some: error{Foo} = error.Foo; | 611 | var some: error{Foo} = error.Foo; |
| 612 | _ = &some; | ||
| 609 | try expect(switch (some) { | 613 | try expect(switch (some) { |
| 610 | else => blk: { | 614 | else => blk: { |
| 611 | break :blk true; | 615 | break :blk true; |
| ... | @@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" { | ... | @@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" { |
| 672 | b = 2, | 676 | b = 2, |
| 673 | _, | 677 | _, |
| 674 | }; | 678 | }; |
| 675 | var e: E = @as(E, @enumFromInt(0)); | 679 | var e: E = @enumFromInt(0); |
| 680 | _ = &e; | ||
| 676 | switch (e) { | 681 | switch (e) { |
| 677 | @as(E, @enumFromInt(0)) => {}, | 682 | @as(E, @enumFromInt(0)) => {}, |
| 678 | .a => return error.TestFailed, | 683 | .a => return error.TestFailed, |
| ... | @@ -685,6 +690,7 @@ test "switch item sizeof" { | ... | @@ -685,6 +690,7 @@ test "switch item sizeof" { |
| 685 | const S = struct { | 690 | const S = struct { |
| 686 | fn doTheTest() !void { | 691 | fn doTheTest() !void { |
| 687 | var a: usize = 0; | 692 | var a: usize = 0; |
| 693 | _ = &a; | ||
| 688 | switch (a) { | 694 | switch (a) { |
| 689 | @sizeOf(struct {}) => {}, | 695 | @sizeOf(struct {}) => {}, |
| 690 | else => return error.TestFailed, | 696 | else => return error.TestFailed, |
| ... | @@ -699,6 +705,7 @@ test "comptime inline switch" { | ... | @@ -699,6 +705,7 @@ test "comptime inline switch" { |
| 699 | const U = union(enum) { a: type, b: type }; | 705 | const U = union(enum) { a: type, b: type }; |
| 700 | const value = comptime blk: { | 706 | const value = comptime blk: { |
| 701 | var u: U = .{ .a = u32 }; | 707 | var u: U = .{ .a = u32 }; |
| 708 | _ = &u; | ||
| 702 | break :blk switch (u) { | 709 | break :blk switch (u) { |
| 703 | inline .a, .b => |v| v, | 710 | inline .a, .b => |v| v, |
| 704 | }; | 711 | }; |
| ... | @@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" { | ... | @@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" { |
| 814 | 821 | ||
| 815 | // This is runtime-known so the following store isn't comptime-known. | 822 | // This is runtime-known so the following store isn't comptime-known. |
| 816 | var rt: u32 = 123; | 823 | var rt: u32 = 123; |
| 824 | _ = &rt; | ||
| 817 | val = .{ .a = rt }; // will not necessarily zero remaning payload memory | 825 | val = .{ .a = rt }; // will not necessarily zero remaning payload memory |
| 818 | 826 | ||
| 819 | // Fields intentionally backwards here | 827 | // Fields intentionally backwards here |
test/behavior/truncate.zig+17-12| ... | @@ -4,58 +4,62 @@ const expect = std.testing.expect; | ... | @@ -4,58 +4,62 @@ const expect = std.testing.expect; |
| 4 | 4 | ||
| 5 | test "truncate u0 to larger integer allowed and has comptime-known result" { | 5 | test "truncate u0 to larger integer allowed and has comptime-known result" { |
| 6 | var x: u0 = 0; | 6 | var x: u0 = 0; |
| 7 | _ = &x; | ||
| 7 | const y = @as(u8, @truncate(x)); | 8 | const y = @as(u8, @truncate(x)); |
| 8 | try comptime expect(y == 0); | 9 | try comptime expect(y == 0); |
| 9 | } | 10 | } |
| 10 | 11 | ||
| 11 | test "truncate.u0.literal" { | 12 | test "truncate.u0.literal" { |
| 12 | var z = @as(u0, @truncate(0)); | 13 | const z: u0 = @truncate(0); |
| 13 | try expect(z == 0); | 14 | try expect(z == 0); |
| 14 | } | 15 | } |
| 15 | 16 | ||
| 16 | test "truncate.u0.const" { | 17 | test "truncate.u0.const" { |
| 17 | const c0: usize = 0; | 18 | const c0: usize = 0; |
| 18 | var z = @as(u0, @truncate(c0)); | 19 | const z: u0 = @truncate(c0); |
| 19 | try expect(z == 0); | 20 | try expect(z == 0); |
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | test "truncate.u0.var" { | 23 | test "truncate.u0.var" { |
| 23 | var d: u8 = 2; | 24 | var d: u8 = 2; |
| 24 | var z = @as(u0, @truncate(d)); | 25 | _ = &d; |
| 26 | const z: u0 = @truncate(d); | ||
| 25 | try expect(z == 0); | 27 | try expect(z == 0); |
| 26 | } | 28 | } |
| 27 | 29 | ||
| 28 | test "truncate i0 to larger integer allowed and has comptime-known result" { | 30 | test "truncate i0 to larger integer allowed and has comptime-known result" { |
| 29 | var x: i0 = 0; | 31 | var x: i0 = 0; |
| 30 | const y = @as(i8, @truncate(x)); | 32 | _ = &x; |
| 33 | const y: i8 = @truncate(x); | ||
| 31 | try comptime expect(y == 0); | 34 | try comptime expect(y == 0); |
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | test "truncate.i0.literal" { | 37 | test "truncate.i0.literal" { |
| 35 | var z = @as(i0, @truncate(0)); | 38 | const z: i0 = @truncate(0); |
| 36 | try expect(z == 0); | 39 | try expect(z == 0); |
| 37 | } | 40 | } |
| 38 | 41 | ||
| 39 | test "truncate.i0.const" { | 42 | test "truncate.i0.const" { |
| 40 | const c0: isize = 0; | 43 | const c0: isize = 0; |
| 41 | var z = @as(i0, @truncate(c0)); | 44 | const z: i0 = @truncate(c0); |
| 42 | try expect(z == 0); | 45 | try expect(z == 0); |
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | test "truncate.i0.var" { | 48 | test "truncate.i0.var" { |
| 46 | var d: i8 = 2; | 49 | var d: i8 = 2; |
| 47 | var z = @as(i0, @truncate(d)); | 50 | _ = &d; |
| 51 | const z: i0 = @truncate(d); | ||
| 48 | try expect(z == 0); | 52 | try expect(z == 0); |
| 49 | } | 53 | } |
| 50 | 54 | ||
| 51 | test "truncate on comptime integer" { | 55 | test "truncate on comptime integer" { |
| 52 | var x = @as(u16, @truncate(9999)); | 56 | const x: u16 = @truncate(9999); |
| 53 | try expect(x == 9999); | 57 | try expect(x == 9999); |
| 54 | var y = @as(u16, @truncate(-21555)); | 58 | const y: u16 = @truncate(-21555); |
| 55 | try expect(y == 0xabcd); | 59 | try expect(y == 0xabcd); |
| 56 | var z = @as(i16, @truncate(-65537)); | 60 | const z: i16 = @truncate(-65537); |
| 57 | try expect(z == -1); | 61 | try expect(z == -1); |
| 58 | var w = @as(u1, @truncate(1 << 100)); | 62 | const w: u1 = @truncate(1 << 100); |
| 59 | try expect(w == 0); | 63 | try expect(w == 0); |
| 60 | } | 64 | } |
| 61 | 65 | ||
| ... | @@ -69,7 +73,8 @@ test "truncate on vectors" { | ... | @@ -69,7 +73,8 @@ test "truncate on vectors" { |
| 69 | const S = struct { | 73 | const S = struct { |
| 70 | fn doTheTest() !void { | 74 | fn doTheTest() !void { |
| 71 | var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 }; | 75 | var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 }; |
| 72 | var v2: @Vector(4, u8) = @truncate(v1); | 76 | _ = &v1; |
| 77 | const v2: @Vector(4, u8) = @truncate(v1); | ||
| 73 | try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 })); | 78 | try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 })); |
| 74 | } | 79 | } |
| 75 | }; | 80 | }; |
test/behavior/tuple.zig+25-8| ... | @@ -15,9 +15,10 @@ test "tuple concatenation" { | ... | @@ -15,9 +15,10 @@ test "tuple concatenation" { |
| 15 | fn doTheTest() !void { | 15 | fn doTheTest() !void { |
| 16 | var a: i32 = 1; | 16 | var a: i32 = 1; |
| 17 | var b: i32 = 2; | 17 | var b: i32 = 2; |
| 18 | var x = .{a}; | 18 | _ = .{ &a, &b }; |
| 19 | var y = .{b}; | 19 | const x = .{a}; |
| 20 | var c = x ++ y; | 20 | const y = .{b}; |
| 21 | const c = x ++ y; | ||
| 21 | try expect(@as(i32, 1) == c[0]); | 22 | try expect(@as(i32, 1) == c[0]); |
| 22 | try expect(@as(i32, 2) == c[1]); | 23 | try expect(@as(i32, 2) == c[1]); |
| 23 | } | 24 | } |
| ... | @@ -119,7 +120,7 @@ test "tuple initializer for var" { | ... | @@ -119,7 +120,7 @@ test "tuple initializer for var" { |
| 119 | .id = @as(usize, 2), | 120 | .id = @as(usize, 2), |
| 120 | .name = Bytes{ .id = 20 }, | 121 | .name = Bytes{ .id = 20 }, |
| 121 | }; | 122 | }; |
| 122 | _ = tmp; | 123 | _ = &tmp; |
| 123 | } | 124 | } |
| 124 | }; | 125 | }; |
| 125 | 126 | ||
| ... | @@ -157,6 +158,7 @@ test "array-like initializer for tuple types" { | ... | @@ -157,6 +158,7 @@ test "array-like initializer for tuple types" { |
| 157 | const S = struct { | 158 | const S = struct { |
| 158 | fn doTheTest() !void { | 159 | fn doTheTest() !void { |
| 159 | var obj: T = .{ -1234, 128 }; | 160 | var obj: T = .{ -1234, 128 }; |
| 161 | _ = &obj; | ||
| 160 | try expect(@as(i32, -1234) == obj[0]); | 162 | try expect(@as(i32, -1234) == obj[0]); |
| 161 | try expect(@as(u8, 128) == obj[1]); | 163 | try expect(@as(u8, 128) == obj[1]); |
| 162 | } | 164 | } |
| ... | @@ -171,6 +173,7 @@ test "anon struct as the result from a labeled block" { | ... | @@ -171,6 +173,7 @@ test "anon struct as the result from a labeled block" { |
| 171 | fn doTheTest() !void { | 173 | fn doTheTest() !void { |
| 172 | const precomputed = comptime blk: { | 174 | const precomputed = comptime blk: { |
| 173 | var x: i32 = 1234; | 175 | var x: i32 = 1234; |
| 176 | _ = &x; | ||
| 174 | break :blk .{ | 177 | break :blk .{ |
| 175 | .x = x, | 178 | .x = x, |
| 176 | }; | 179 | }; |
| ... | @@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" { | ... | @@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" { |
| 188 | fn doTheTest() !void { | 191 | fn doTheTest() !void { |
| 189 | const precomputed = comptime blk: { | 192 | const precomputed = comptime blk: { |
| 190 | var x: i32 = 1234; | 193 | var x: i32 = 1234; |
| 194 | _ = &x; | ||
| 191 | break :blk .{x}; | 195 | break :blk .{x}; |
| 192 | }; | 196 | }; |
| 193 | try expect(precomputed[0] == 1234); | 197 | try expect(precomputed[0] == 1234); |
| ... | @@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" { | ... | @@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" { |
| 201 | test "initializing tuple with explicit type" { | 205 | test "initializing tuple with explicit type" { |
| 202 | const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); | 206 | const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); |
| 203 | var a = T{ 0, 0 }; | 207 | var a = T{ 0, 0 }; |
| 204 | _ = a; | 208 | _ = &a; |
| 205 | } | 209 | } |
| 206 | 210 | ||
| 207 | test "initializing anon struct with explicit type" { | 211 | test "initializing anon struct with explicit type" { |
| 208 | const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) }); | 212 | const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) }); |
| 209 | var a = T{ .foo = 1, .bar = 2 }; | 213 | var a = T{ .foo = 1, .bar = 2 }; |
| 210 | _ = a; | 214 | _ = &a; |
| 211 | } | 215 | } |
| 212 | 216 | ||
| 213 | test "fieldParentPtr of tuple" { | 217 | test "fieldParentPtr of tuple" { |
| ... | @@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" { | ... | @@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" { |
| 216 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 220 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 217 | 221 | ||
| 218 | var x: u32 = 0; | 222 | var x: u32 = 0; |
| 223 | _ = &x; | ||
| 219 | const tuple = .{ x, x }; | 224 | const tuple = .{ x, x }; |
| 220 | try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1])); | 225 | try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1])); |
| 221 | } | 226 | } |
| ... | @@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" { | ... | @@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" { |
| 226 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 231 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 227 | 232 | ||
| 228 | var x: u32 = 0; | 233 | var x: u32 = 0; |
| 234 | _ = &x; | ||
| 229 | const anon_st = .{ .foo = x, .bar = x }; | 235 | const anon_st = .{ .foo = x, .bar = x }; |
| 230 | try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar)); | 236 | try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar)); |
| 231 | } | 237 | } |
| 232 | 238 | ||
| 233 | test "offsetOf tuple" { | 239 | test "offsetOf tuple" { |
| 234 | var x: u32 = 0; | 240 | var x: u32 = 0; |
| 241 | _ = &x; | ||
| 235 | const T = @TypeOf(.{ x, x }); | 242 | const T = @TypeOf(.{ x, x }); |
| 236 | try expect(@offsetOf(T, "1") == @sizeOf(u32)); | 243 | try expect(@offsetOf(T, "1") == @sizeOf(u32)); |
| 237 | } | 244 | } |
| 238 | 245 | ||
| 239 | test "offsetOf anon struct" { | 246 | test "offsetOf anon struct" { |
| 240 | var x: u32 = 0; | 247 | var x: u32 = 0; |
| 248 | _ = &x; | ||
| 241 | const T = @TypeOf(.{ .foo = x, .bar = x }); | 249 | const T = @TypeOf(.{ .foo = x, .bar = x }); |
| 242 | try expect(@offsetOf(T, "bar") == @sizeOf(u32)); | 250 | try expect(@offsetOf(T, "bar") == @sizeOf(u32)); |
| 243 | } | 251 | } |
| ... | @@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" { | ... | @@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" { |
| 247 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 255 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 248 | 256 | ||
| 249 | var x: u32 = 15; | 257 | var x: u32 = 15; |
| 258 | _ = &x; | ||
| 250 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); | 259 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); |
| 251 | var a: T = .{ -1234, 5678, x + 1 }; | 260 | var a: T = .{ -1234, 5678, x + 1 }; |
| 261 | _ = &a; | ||
| 252 | try expect(a[2] == 16); | 262 | try expect(a[2] == 16); |
| 253 | } | 263 | } |
| 254 | 264 | ||
| ... | @@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" { | ... | @@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" { |
| 257 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 267 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 258 | 268 | ||
| 259 | var x: u32 = 15; | 269 | var x: u32 = 15; |
| 270 | _ = &x; | ||
| 260 | const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x }); | 271 | const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x }); |
| 261 | var a: T = .{ .foo = -1234, .bar = x + 1 }; | 272 | var a: T = .{ .foo = -1234, .bar = x + 1 }; |
| 273 | _ = &a; | ||
| 262 | try expect(a.bar == 16); | 274 | try expect(a.bar == 16); |
| 263 | } | 275 | } |
| 264 | 276 | ||
| ... | @@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" { | ... | @@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" { |
| 338 | 350 | ||
| 339 | const T = std.meta.Tuple(&[_]type{ usize, void }); | 351 | const T = std.meta.Tuple(&[_]type{ usize, void }); |
| 340 | var t: T = .{ 5, {} }; | 352 | var t: T = .{ 5, {} }; |
| 353 | _ = &t; | ||
| 341 | try expect(t[0] == 5); | 354 | try expect(t[0] == 5); |
| 342 | } | 355 | } |
| 343 | 356 | ||
| ... | @@ -352,6 +365,7 @@ test "branching inside tuple literal" { | ... | @@ -352,6 +365,7 @@ test "branching inside tuple literal" { |
| 352 | } | 365 | } |
| 353 | }; | 366 | }; |
| 354 | var a = false; | 367 | var a = false; |
| 368 | _ = &a; | ||
| 355 | try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)}); | 369 | try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)}); |
| 356 | } | 370 | } |
| 357 | 371 | ||
| ... | @@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" { | ... | @@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" { |
| 363 | const E = union(enum) { e: []const u8 }; | 377 | const E = union(enum) { e: []const u8 }; |
| 364 | const W = union(enum) { w: E }; | 378 | const W = union(enum) { w: E }; |
| 365 | var e = E{ .e = "test" }; | 379 | var e = E{ .e = "test" }; |
| 380 | _ = &e; | ||
| 366 | const w = .{W{ .w = e }}; | 381 | const w = .{W{ .w = e }}; |
| 367 | try expectEqualStrings(w[0].w.e, "test"); | 382 | try expectEqualStrings(w[0].w.e, "test"); |
| 368 | } | 383 | } |
| ... | @@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" { | ... | @@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" { |
| 388 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 403 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 389 | 404 | ||
| 390 | var data: u8 = 0; | 405 | var data: u8 = 0; |
| 406 | _ = &data; | ||
| 391 | const x = .{ | 407 | const x = .{ |
| 392 | if (data != 0) "" else switch (@as(u1, @truncate(data))) { | 408 | if (data != 0) "" else switch (@as(u1, @truncate(data))) { |
| 393 | 0 => "up", | 409 | 0 => "up", |
| ... | @@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" { | ... | @@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" { |
| 446 | 462 | ||
| 447 | var x: u8 = 1; | 463 | var x: u8 = 1; |
| 448 | var y: u16 = 2; | 464 | var y: u16 = 2; |
| 449 | var t = .{ x, y }; | 465 | _ = .{ &x, &y }; |
| 450 | var s: struct { u8, u16 } = t; | 466 | const t = .{ x, y }; |
| 467 | const s: struct { u8, u16 } = t; | ||
| 451 | try expectEqual(x, s[0]); | 468 | try expectEqual(x, s[0]); |
| 452 | try expectEqual(y, s[1]); | 469 | try expectEqual(y, s[1]); |
| 453 | } | 470 | } |
test/behavior/tuple_declarations.zig+4-2| ... | @@ -38,17 +38,19 @@ test "Tuple declaration usage" { | ... | @@ -38,17 +38,19 @@ test "Tuple declaration usage" { |
| 38 | 38 | ||
| 39 | const T = struct { u32, []const u8 }; | 39 | const T = struct { u32, []const u8 }; |
| 40 | var t: T = .{ 1, "foo" }; | 40 | var t: T = .{ 1, "foo" }; |
| 41 | _ = &t; | ||
| 41 | try expect(t[0] == 1); | 42 | try expect(t[0] == 1); |
| 42 | try expectEqualStrings(t[1], "foo"); | 43 | try expectEqualStrings(t[1], "foo"); |
| 43 | 44 | ||
| 44 | var mul = t ** 3; | 45 | const mul = t ** 3; |
| 45 | try expect(@TypeOf(mul) != T); | 46 | try expect(@TypeOf(mul) != T); |
| 46 | try expect(mul.len == 6); | 47 | try expect(mul.len == 6); |
| 47 | try expect(mul[2] == 1); | 48 | try expect(mul[2] == 1); |
| 48 | try expectEqualStrings(mul[3], "foo"); | 49 | try expectEqualStrings(mul[3], "foo"); |
| 49 | 50 | ||
| 50 | var t2: T = .{ 2, "bar" }; | 51 | var t2: T = .{ 2, "bar" }; |
| 51 | var cat = t ++ t2; | 52 | _ = &t2; |
| 53 | const cat = t ++ t2; | ||
| 52 | try expect(@TypeOf(cat) != T); | 54 | try expect(@TypeOf(cat) != T); |
| 53 | try expect(cat.len == 4); | 55 | try expect(cat.len == 4); |
| 54 | try expect(cat[2] == 2); | 56 | try expect(cat[2] == 2); |
test/behavior/type.zig+3-2| ... | @@ -410,7 +410,8 @@ test "Type.Union" { | ... | @@ -410,7 +410,8 @@ test "Type.Union" { |
| 410 | .decls = &.{}, | 410 | .decls = &.{}, |
| 411 | }, | 411 | }, |
| 412 | }); | 412 | }); |
| 413 | var packed_untagged = PackedUntagged{ .signed = -1 }; | 413 | var packed_untagged: PackedUntagged = .{ .signed = -1 }; |
| 414 | _ = &packed_untagged; | ||
| 414 | try testing.expectEqual(@as(i32, -1), packed_untagged.signed); | 415 | try testing.expectEqual(@as(i32, -1), packed_untagged.signed); |
| 415 | try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); | 416 | try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); |
| 416 | 417 | ||
| ... | @@ -529,7 +530,7 @@ test "reified struct field name from optional payload" { | ... | @@ -529,7 +530,7 @@ test "reified struct field name from optional payload" { |
| 529 | .decls = &.{}, | 530 | .decls = &.{}, |
| 530 | .is_tuple = false, | 531 | .is_tuple = false, |
| 531 | } }); | 532 | } }); |
| 532 | var t: T = .{ .a = 123 }; | 533 | const t: T = .{ .a = 123 }; |
| 533 | try std.testing.expect(t.a == 123); | 534 | try std.testing.expect(t.a == 123); |
| 534 | } | 535 | } |
| 535 | } | 536 | } |
test/behavior/type_info.zig+1-1| ... | @@ -417,7 +417,7 @@ test "typeInfo with comptime parameter in struct fn def" { | ... | @@ -417,7 +417,7 @@ test "typeInfo with comptime parameter in struct fn def" { |
| 417 | } | 417 | } |
| 418 | }; | 418 | }; |
| 419 | comptime var info = @typeInfo(S); | 419 | comptime var info = @typeInfo(S); |
| 420 | _ = info; | 420 | _ = &info; |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | test "type info: vectors" { | 423 | test "type info: vectors" { |
test/behavior/union.zig+46-5| ... | @@ -171,6 +171,7 @@ test "constant tagged union with payload" { | ... | @@ -171,6 +171,7 @@ test "constant tagged union with payload" { |
| 171 | 171 | ||
| 172 | var empty = TaggedUnionWithPayload{ .Empty = {} }; | 172 | var empty = TaggedUnionWithPayload{ .Empty = {} }; |
| 173 | var full = TaggedUnionWithPayload{ .Full = 13 }; | 173 | var full = TaggedUnionWithPayload{ .Full = 13 }; |
| 174 | _ = .{ &empty, &full }; | ||
| 174 | shouldBeEmpty(empty); | 175 | shouldBeEmpty(empty); |
| 175 | shouldBeNotEmpty(full); | 176 | shouldBeNotEmpty(full); |
| 176 | } | 177 | } |
| ... | @@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 { | ... | @@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 { |
| 254 | 255 | ||
| 255 | fn testComparison() !void { | 256 | fn testComparison() !void { |
| 256 | var x = Payload{ .A = 42 }; | 257 | var x = Payload{ .A = 42 }; |
| 258 | _ = &x; | ||
| 257 | try expect(x == .A); | 259 | try expect(x == .A); |
| 258 | try expect(x != .B); | 260 | try expect(x != .B); |
| 259 | try expect(x != .C); | 261 | try expect(x != .C); |
| ... | @@ -288,6 +290,7 @@ test "cast union to tag type of union" { | ... | @@ -288,6 +290,7 @@ test "cast union to tag type of union" { |
| 288 | 290 | ||
| 289 | fn testCastUnionToTag() !void { | 291 | fn testCastUnionToTag() !void { |
| 290 | var u = TheUnion{ .B = 1234 }; | 292 | var u = TheUnion{ .B = 1234 }; |
| 293 | _ = &u; | ||
| 291 | try expect(@as(TheTag, u) == TheTag.B); | 294 | try expect(@as(TheTag, u) == TheTag.B); |
| 292 | } | 295 | } |
| 293 | 296 | ||
| ... | @@ -303,6 +306,7 @@ test "cast tag type of union to union" { | ... | @@ -303,6 +306,7 @@ test "cast tag type of union to union" { |
| 303 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 306 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 304 | 307 | ||
| 305 | var x: Value2 = Letter2.B; | 308 | var x: Value2 = Letter2.B; |
| 309 | _ = &x; | ||
| 306 | try expect(@as(Letter2, x) == Letter2.B); | 310 | try expect(@as(Letter2, x) == Letter2.B); |
| 307 | } | 311 | } |
| 308 | const Letter2 = enum { A, B, C }; | 312 | const Letter2 = enum { A, B, C }; |
| ... | @@ -318,6 +322,7 @@ test "implicit cast union to its tag type" { | ... | @@ -318,6 +322,7 @@ test "implicit cast union to its tag type" { |
| 318 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 322 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 319 | 323 | ||
| 320 | var x: Value2 = Letter2.B; | 324 | var x: Value2 = Letter2.B; |
| 325 | _ = &x; | ||
| 321 | try expect(x == Letter2.B); | 326 | try expect(x == Letter2.B); |
| 322 | try giveMeLetterB(x); | 327 | try giveMeLetterB(x); |
| 323 | } | 328 | } |
| ... | @@ -356,6 +361,7 @@ test "simple union(enum(u32))" { | ... | @@ -356,6 +361,7 @@ test "simple union(enum(u32))" { |
| 356 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 361 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 357 | 362 | ||
| 358 | var x = MultipleChoice.C; | 363 | var x = MultipleChoice.C; |
| 364 | _ = &x; | ||
| 359 | try expect(x == MultipleChoice.C); | 365 | try expect(x == MultipleChoice.C); |
| 360 | try expect(@intFromEnum(@as(Tag(MultipleChoice), x)) == 60); | 366 | try expect(@intFromEnum(@as(Tag(MultipleChoice), x)) == 60); |
| 361 | } | 367 | } |
| ... | @@ -420,9 +426,11 @@ test "union with only 1 field casted to its enum type" { | ... | @@ -420,9 +426,11 @@ test "union with only 1 field casted to its enum type" { |
| 420 | }; | 426 | }; |
| 421 | 427 | ||
| 422 | var e = Expr{ .Literal = Literal{ .Bool = true } }; | 428 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 429 | _ = &e; | ||
| 423 | const ExprTag = Tag(Expr); | 430 | const ExprTag = Tag(Expr); |
| 424 | try comptime expect(Tag(ExprTag) == u0); | 431 | try comptime expect(Tag(ExprTag) == u0); |
| 425 | var t = @as(ExprTag, e); | 432 | var t = @as(ExprTag, e); |
| 433 | _ = &t; | ||
| 426 | try expect(t == Expr.Literal); | 434 | try expect(t == Expr.Literal); |
| 427 | } | 435 | } |
| 428 | 436 | ||
| ... | @@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" { | ... | @@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" { |
| 494 | }; | 502 | }; |
| 495 | 503 | ||
| 496 | var v = U{ .A = 532 }; | 504 | var v = U{ .A = 532 }; |
| 505 | _ = &v; | ||
| 497 | try expect(v.A == 532); | 506 | try expect(v.A == 532); |
| 498 | } | 507 | } |
| 499 | 508 | ||
| ... | @@ -506,6 +515,7 @@ test "runtime tag name with single field" { | ... | @@ -506,6 +515,7 @@ test "runtime tag name with single field" { |
| 506 | }; | 515 | }; |
| 507 | 516 | ||
| 508 | var v = U{ .A = 42 }; | 517 | var v = U{ .A = 42 }; |
| 518 | _ = &v; | ||
| 509 | try expect(std.mem.eql(u8, @tagName(v), "A")); | 519 | try expect(std.mem.eql(u8, @tagName(v), "A")); |
| 510 | } | 520 | } |
| 511 | 521 | ||
| ... | @@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci | ... | @@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci |
| 698 | }; | 708 | }; |
| 699 | 709 | ||
| 700 | var e = Expr{ .Literal = Literal{ .Bool = true } }; | 710 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 711 | _ = &e; | ||
| 701 | try comptime expect(Tag(ExprTag) == comptime_int); | 712 | try comptime expect(Tag(ExprTag) == comptime_int); |
| 702 | comptime var t = @as(ExprTag, e); | 713 | const t = comptime @as(ExprTag, e); |
| 703 | try expect(t == Expr.Literal); | 714 | try expect(t == Expr.Literal); |
| 704 | try expect(@intFromEnum(t) == 33); | 715 | try expect(@intFromEnum(t) == 33); |
| 705 | try comptime expect(@intFromEnum(t) == 33); | 716 | try comptime expect(@intFromEnum(t) == 33); |
| ... | @@ -719,6 +730,7 @@ test "@intFromEnum works on unions" { | ... | @@ -719,6 +730,7 @@ test "@intFromEnum works on unions" { |
| 719 | const a = Bar{ .A = true }; | 730 | const a = Bar{ .A = true }; |
| 720 | var b = Bar{ .B = undefined }; | 731 | var b = Bar{ .B = undefined }; |
| 721 | var c = Bar.C; | 732 | var c = Bar.C; |
| 733 | _ = .{ &b, &c }; | ||
| 722 | try expect(@intFromEnum(a) == 0); | 734 | try expect(@intFromEnum(a) == 0); |
| 723 | try expect(@intFromEnum(b) == 1); | 735 | try expect(@intFromEnum(b) == 1); |
| 724 | try expect(@intFromEnum(c) == 2); | 736 | try expect(@intFromEnum(c) == 2); |
| ... | @@ -800,11 +812,13 @@ test "@unionInit stored to a const" { | ... | @@ -800,11 +812,13 @@ test "@unionInit stored to a const" { |
| 800 | fn doTheTest() !void { | 812 | fn doTheTest() !void { |
| 801 | { | 813 | { |
| 802 | var t = true; | 814 | var t = true; |
| 815 | _ = &t; | ||
| 803 | const u = @unionInit(U, "boolean", t); | 816 | const u = @unionInit(U, "boolean", t); |
| 804 | try expect(u.boolean); | 817 | try expect(u.boolean); |
| 805 | } | 818 | } |
| 806 | { | 819 | { |
| 807 | var byte: u8 = 69; | 820 | var byte: u8 = 69; |
| 821 | _ = &byte; | ||
| 808 | const u = @unionInit(U, "byte", byte); | 822 | const u = @unionInit(U, "byte", byte); |
| 809 | try expect(u.byte == 69); | 823 | try expect(u.byte == 69); |
| 810 | } | 824 | } |
| ... | @@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" { | ... | @@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" { |
| 849 | }; | 863 | }; |
| 850 | 864 | ||
| 851 | var value: UnionInitEnum = undefined; | 865 | var value: UnionInitEnum = undefined; |
| 852 | var value_ptr = &value; | 866 | const value_ptr = &value; |
| 853 | 867 | ||
| 854 | value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true); | 868 | value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true); |
| 855 | try expect(value.Boolean == true); | 869 | try expect(value.Boolean == true); |
| ... | @@ -906,7 +920,8 @@ test "anonymous union literal syntax" { | ... | @@ -906,7 +920,8 @@ test "anonymous union literal syntax" { |
| 906 | 920 | ||
| 907 | fn doTheTest() !void { | 921 | fn doTheTest() !void { |
| 908 | var i: Number = .{ .int = 42 }; | 922 | var i: Number = .{ .int = 42 }; |
| 909 | var f = makeNumber(); | 923 | _ = &i; |
| 924 | const f = makeNumber(); | ||
| 910 | try expect(i.int == 42); | 925 | try expect(i.int == 42); |
| 911 | try expect(f.float == 12.34); | 926 | try expect(f.float == 12.34); |
| 912 | } | 927 | } |
| ... | @@ -934,9 +949,11 @@ test "function call result coerces from tagged union to the tag" { | ... | @@ -934,9 +949,11 @@ test "function call result coerces from tagged union to the tag" { |
| 934 | 949 | ||
| 935 | fn doTheTest() !void { | 950 | fn doTheTest() !void { |
| 936 | var x: ArchTag = getArch1(); | 951 | var x: ArchTag = getArch1(); |
| 952 | _ = &x; | ||
| 937 | try expect(x == .One); | 953 | try expect(x == .One); |
| 938 | 954 | ||
| 939 | var y: ArchTag = getArch2(); | 955 | var y: ArchTag = getArch2(); |
| 956 | _ = &y; | ||
| 940 | try expect(y == .Two); | 957 | try expect(y == .Two); |
| 941 | } | 958 | } |
| 942 | 959 | ||
| ... | @@ -965,14 +982,17 @@ test "cast from anonymous struct to union" { | ... | @@ -965,14 +982,17 @@ test "cast from anonymous struct to union" { |
| 965 | }; | 982 | }; |
| 966 | fn doTheTest() !void { | 983 | fn doTheTest() !void { |
| 967 | var y: u32 = 42; | 984 | var y: u32 = 42; |
| 985 | _ = &y; | ||
| 968 | const t0 = .{ .A = 123 }; | 986 | const t0 = .{ .A = 123 }; |
| 969 | const t1 = .{ .B = "foo" }; | 987 | const t1 = .{ .B = "foo" }; |
| 970 | const t2 = .{ .C = {} }; | 988 | const t2 = .{ .C = {} }; |
| 971 | const t3 = .{ .A = y }; | 989 | const t3 = .{ .A = y }; |
| 972 | const x0: U = t0; | 990 | const x0: U = t0; |
| 973 | var x1: U = t1; | 991 | var x1: U = t1; |
| 992 | _ = &x1; | ||
| 974 | const x2: U = t2; | 993 | const x2: U = t2; |
| 975 | var x3: U = t3; | 994 | var x3: U = t3; |
| 995 | _ = &x3; | ||
| 976 | try expect(x0.A == 123); | 996 | try expect(x0.A == 123); |
| 977 | try expect(std.mem.eql(u8, x1.B, "foo")); | 997 | try expect(std.mem.eql(u8, x1.B, "foo")); |
| 978 | try expect(x2 == .C); | 998 | try expect(x2 == .C); |
| ... | @@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" { | ... | @@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" { |
| 996 | }; | 1016 | }; |
| 997 | fn doTheTest() !void { | 1017 | fn doTheTest() !void { |
| 998 | var y: u32 = 42; | 1018 | var y: u32 = 42; |
| 1019 | _ = &y; | ||
| 999 | const t0 = &.{ .A = 123 }; | 1020 | const t0 = &.{ .A = 123 }; |
| 1000 | const t1 = &.{ .B = "foo" }; | 1021 | const t1 = &.{ .B = "foo" }; |
| 1001 | const t2 = &.{ .C = {} }; | 1022 | const t2 = &.{ .C = {} }; |
| 1002 | const t3 = &.{ .A = y }; | 1023 | const t3 = &.{ .A = y }; |
| 1003 | const x0: *const U = t0; | 1024 | const x0: *const U = t0; |
| 1004 | var x1: *const U = t1; | 1025 | var x1: *const U = t1; |
| 1026 | _ = &x1; | ||
| 1005 | const x2: *const U = t2; | 1027 | const x2: *const U = t2; |
| 1006 | var x3: *const U = t3; | 1028 | var x3: *const U = t3; |
| 1029 | _ = &x3; | ||
| 1007 | try expect(x0.A == 123); | 1030 | try expect(x0.A == 123); |
| 1008 | try expect(std.mem.eql(u8, x1.B, "foo")); | 1031 | try expect(std.mem.eql(u8, x1.B, "foo")); |
| 1009 | try expect(x2.* == .C); | 1032 | try expect(x2.* == .C); |
| ... | @@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" { | ... | @@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" { |
| 1031 | }; | 1054 | }; |
| 1032 | fn doTheTest() !void { | 1055 | fn doTheTest() !void { |
| 1033 | var a = U{ .a = 2 }; | 1056 | var a = U{ .a = 2 }; |
| 1057 | _ = &a; | ||
| 1034 | switch (a) { | 1058 | switch (a) { |
| 1035 | .a => |val| try expect(val == 2), | 1059 | .a => |val| try expect(val == 2), |
| 1036 | .b => return error.Fail, | 1060 | .b => return error.Fail, |
| ... | @@ -1055,11 +1079,13 @@ test "containers with single-field enums" { | ... | @@ -1055,11 +1079,13 @@ test "containers with single-field enums" { |
| 1055 | fn doTheTest() !void { | 1079 | fn doTheTest() !void { |
| 1056 | var array1 = [1]A{A{ .f1 = {} }}; | 1080 | var array1 = [1]A{A{ .f1 = {} }}; |
| 1057 | var array2 = [1]B{B{ .f1 = {} }}; | 1081 | var array2 = [1]B{B{ .f1 = {} }}; |
| 1082 | _ = .{ &array1, &array2 }; | ||
| 1058 | try expect(array1[0] == .f1); | 1083 | try expect(array1[0] == .f1); |
| 1059 | try expect(array2[0] == .f1); | 1084 | try expect(array2[0] == .f1); |
| 1060 | 1085 | ||
| 1061 | var struct1 = C{ .a = A{ .f1 = {} } }; | 1086 | var struct1 = C{ .a = A{ .f1 = {} } }; |
| 1062 | var struct2 = D{ .a = B{ .f1 = {} } }; | 1087 | var struct2 = D{ .a = B{ .f1 = {} } }; |
| 1088 | _ = .{ &struct1, &struct2 }; | ||
| 1063 | try expect(struct1.a == .f1); | 1089 | try expect(struct1.a == .f1); |
| 1064 | try expect(struct2.a == .f1); | 1090 | try expect(struct2.a == .f1); |
| 1065 | } | 1091 | } |
| ... | @@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" { | ... | @@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" { |
| 1092 | 1118 | ||
| 1093 | fn doTheTest() !void { | 1119 | fn doTheTest() !void { |
| 1094 | var data: Data = .{ .no_op = {} }; | 1120 | var data: Data = .{ .no_op = {} }; |
| 1095 | _ = data; | 1121 | _ = &data; |
| 1096 | var o = Data.decode(&[_]u8{}); | 1122 | var o = Data.decode(&[_]u8{}); |
| 1123 | _ = &o; | ||
| 1097 | try expectEqual(Type.no_op, o); | 1124 | try expectEqual(Type.no_op, o); |
| 1098 | } | 1125 | } |
| 1099 | }; | 1126 | }; |
| ... | @@ -1156,6 +1183,7 @@ test "union with no result loc initiated with a runtime value" { | ... | @@ -1156,6 +1183,7 @@ test "union with no result loc initiated with a runtime value" { |
| 1156 | } | 1183 | } |
| 1157 | }; | 1184 | }; |
| 1158 | var a: u32 = 1; | 1185 | var a: u32 = 1; |
| 1186 | _ = &a; | ||
| 1159 | U.foo(U{ .a = a }); | 1187 | U.foo(U{ .a = a }); |
| 1160 | } | 1188 | } |
| 1161 | 1189 | ||
| ... | @@ -1174,6 +1202,7 @@ test "union with a large struct field" { | ... | @@ -1174,6 +1202,7 @@ test "union with a large struct field" { |
| 1174 | fn foo(_: @This()) void {} | 1202 | fn foo(_: @This()) void {} |
| 1175 | }; | 1203 | }; |
| 1176 | var s: S = undefined; | 1204 | var s: S = undefined; |
| 1205 | _ = &s; | ||
| 1177 | U.foo(U{ .s = s }); | 1206 | U.foo(U{ .s = s }); |
| 1178 | } | 1207 | } |
| 1179 | 1208 | ||
| ... | @@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" { | ... | @@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" { |
| 1207 | } | 1236 | } |
| 1208 | }; | 1237 | }; |
| 1209 | var b: u32 = 1; | 1238 | var b: u32 = 1; |
| 1239 | _ = &b; | ||
| 1210 | try (U{ .b = b }).doTheTest(); | 1240 | try (U{ .b = b }).doTheTest(); |
| 1211 | } | 1241 | } |
| 1212 | 1242 | ||
| ... | @@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" { | ... | @@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" { |
| 1226 | un: [110]u8, | 1256 | un: [110]u8, |
| 1227 | }; | 1257 | }; |
| 1228 | var a: ?U = .{ .un = [_]u8{0} ** 110 }; | 1258 | var a: ?U = .{ .un = [_]u8{0} ** 110 }; |
| 1259 | _ = &a; | ||
| 1229 | try expect(a != null); | 1260 | try expect(a != null); |
| 1230 | } | 1261 | } |
| 1231 | 1262 | ||
| ... | @@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" { | ... | @@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" { |
| 1246 | 1277 | ||
| 1247 | fn bar(arg_u: U) callconv(.C) U { | 1278 | fn bar(arg_u: U) callconv(.C) U { |
| 1248 | var u = arg_u; | 1279 | var u = arg_u; |
| 1280 | _ = &u; | ||
| 1249 | return u; | 1281 | return u; |
| 1250 | } | 1282 | } |
| 1251 | }; | 1283 | }; |
| ... | @@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" { | ... | @@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" { |
| 1324 | a: usize, | 1356 | a: usize, |
| 1325 | }; | 1357 | }; |
| 1326 | var i: isize = -1; | 1358 | var i: isize = -1; |
| 1359 | _ = &i; | ||
| 1327 | var u = @unionInit(U, "b", i); | 1360 | var u = @unionInit(U, "b", i); |
| 1328 | { | 1361 | { |
| 1329 | var a = u.b; | 1362 | var a = u.b; |
| 1363 | _ = &a; | ||
| 1330 | try expect(a == i); | 1364 | try expect(a == i); |
| 1331 | } | 1365 | } |
| 1332 | { | 1366 | { |
| 1333 | var a = &u.b; | 1367 | var a = &u.b; |
| 1368 | _ = &a; | ||
| 1334 | try expect(a.* == i); | 1369 | try expect(a.* == i); |
| 1335 | } | 1370 | } |
| 1336 | try expect(@intFromEnum(u) == 255); | 1371 | try expect(@intFromEnum(u) == 255); |
| ... | @@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" { | ... | @@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" { |
| 1508 | b: u8, | 1543 | b: u8, |
| 1509 | 1544 | ||
| 1510 | fn doTest(c: bool) !void { | 1545 | fn doTest(c: bool) !void { |
| 1511 | var u = if (c) .a else @This(){ .b = 0 }; | 1546 | const u = if (c) .a else @This(){ .b = 0 }; |
| 1512 | try expect(u == .a); | 1547 | try expect(u == .a); |
| 1513 | } | 1548 | } |
| 1514 | }; | 1549 | }; |
| ... | @@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" { | ... | @@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" { |
| 1947 | }; | 1982 | }; |
| 1948 | 1983 | ||
| 1949 | var s: S = .{}; | 1984 | var s: S = .{}; |
| 1985 | _ = &s; | ||
| 1950 | try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa)); | 1986 | try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa)); |
| 1951 | try expect(s.u.b == if (endian == .little) 0xaa else 0xdd); | 1987 | try expect(s.u.b == if (endian == .little) 0xaa else 0xdd); |
| 1952 | } | 1988 | } |
| ... | @@ -1966,6 +2002,7 @@ test "store of comptime reinterpreted memory to extern union" { | ... | @@ -1966,6 +2002,7 @@ test "store of comptime reinterpreted memory to extern union" { |
| 1966 | }; | 2002 | }; |
| 1967 | 2003 | ||
| 1968 | var u: U = reinterpreted; | 2004 | var u: U = reinterpreted; |
| 2005 | _ = &u; | ||
| 1969 | try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); | 2006 | try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); |
| 1970 | try expect(u.b == 0xaa); | 2007 | try expect(u.b == 0xaa); |
| 1971 | } | 2008 | } |
| ... | @@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" { | ... | @@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" { |
| 1985 | }; | 2022 | }; |
| 1986 | 2023 | ||
| 1987 | var u: U = reinterpreted; | 2024 | var u: U = reinterpreted; |
| 2025 | _ = &u; | ||
| 1988 | try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); | 2026 | try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); |
| 1989 | try expect(u.b == if (endian == .little) 0xaa else 0xdd); | 2027 | try expect(u.b == if (endian == .little) 0xaa else 0xdd); |
| 1990 | } | 2028 | } |
| ... | @@ -2018,6 +2056,7 @@ test "pass register-sized field as non-register-sized union" { | ... | @@ -2018,6 +2056,7 @@ test "pass register-sized field as non-register-sized union" { |
| 2018 | }; | 2056 | }; |
| 2019 | 2057 | ||
| 2020 | var x: usize = 42; | 2058 | var x: usize = 42; |
| 2059 | _ = &x; | ||
| 2021 | try S.taggedUnion(.{ .x = x }); | 2060 | try S.taggedUnion(.{ .x = x }); |
| 2022 | try S.untaggedUnion(.{ .x = x }); | 2061 | try S.untaggedUnion(.{ .x = x }); |
| 2023 | try S.externUnion(.{ .x = x }); | 2062 | try S.externUnion(.{ .x = x }); |
| ... | @@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" { | ... | @@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" { |
| 2039 | }; | 2078 | }; |
| 2040 | }; | 2079 | }; |
| 2041 | var outer: S.UnionOuter = .{}; | 2080 | var outer: S.UnionOuter = .{}; |
| 2081 | _ = &outer; | ||
| 2042 | try expect(outer.u.outer == null); | 2082 | try expect(outer.u.outer == null); |
| 2043 | try expect(outer.u.inner == null); | 2083 | try expect(outer.u.inner == null); |
| 2044 | } | 2084 | } |
| ... | @@ -2057,5 +2097,6 @@ test "pass nested union with rls" { | ... | @@ -2057,5 +2097,6 @@ test "pass nested union with rls" { |
| 2057 | }; | 2097 | }; |
| 2058 | 2098 | ||
| 2059 | var c: u7 = 32; | 2099 | var c: u7 = 32; |
| 2100 | _ = &c; | ||
| 2060 | try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } })); | 2101 | try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } })); |
| 2061 | } | 2102 | } |
test/behavior/var_args.zig+1| ... | @@ -147,6 +147,7 @@ test "simple variadic function" { | ... | @@ -147,6 +147,7 @@ test "simple variadic function" { |
| 147 | var runtime: bool = true; | 147 | var runtime: bool = true; |
| 148 | var a: i32 = 1; | 148 | var a: i32 = 1; |
| 149 | var b: i32 = 2; | 149 | var b: i32 = 2; |
| 150 | _ = .{ &runtime, &a, &b }; | ||
| 150 | try expect(1 == S.add(1, if (runtime) a else b)); | 151 | try expect(1 == S.add(1, if (runtime) a else b)); |
| 151 | } | 152 | } |
| 152 | } | 153 | } |
test/behavior/vector.zig+99-55| ... | @@ -40,6 +40,7 @@ test "vector wrap operators" { | ... | @@ -40,6 +40,7 @@ test "vector wrap operators" { |
| 40 | try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); | 40 | try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); |
| 41 | var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; | 41 | var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; |
| 42 | try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 })); | 42 | try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 })); |
| 43 | _ = .{ &v, &x, &z }; | ||
| 43 | } | 44 | } |
| 44 | }; | 45 | }; |
| 45 | try S.doTheTest(); | 46 | try S.doTheTest(); |
| ... | @@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" { | ... | @@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" { |
| 57 | fn doTheTest() !void { | 58 | fn doTheTest() !void { |
| 58 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; | 59 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 59 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; | 60 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; |
| 61 | _ = .{ &v, &x }; | ||
| 60 | try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); | 62 | try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); |
| 61 | try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); | 63 | try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); |
| 62 | try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); | 64 | try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); |
| ... | @@ -81,6 +83,7 @@ test "vector int operators" { | ... | @@ -81,6 +83,7 @@ test "vector int operators" { |
| 81 | fn doTheTest() !void { | 83 | fn doTheTest() !void { |
| 82 | var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; | 84 | var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; |
| 83 | var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; | 85 | var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; |
| 86 | _ = .{ &v, &x }; | ||
| 84 | try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); | 87 | try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); |
| 85 | try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); | 88 | try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); |
| 86 | try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); | 89 | try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); |
| ... | @@ -105,6 +108,7 @@ test "vector float operators" { | ... | @@ -105,6 +108,7 @@ test "vector float operators" { |
| 105 | fn doTheTest() !void { | 108 | fn doTheTest() !void { |
| 106 | var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 }; | 109 | var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 }; |
| 107 | var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 }; | 110 | var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 }; |
| 111 | _ = .{ &v, &x }; | ||
| 108 | try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 })); | 112 | try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 })); |
| 109 | try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 })); | 113 | try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 })); |
| 110 | try expect(mem.eql(T, &@as([4]T, v * x), &[4]T{ 10, 40, 90, 160 })); | 114 | try expect(mem.eql(T, &@as([4]T, v * x), &[4]T{ 10, 40, 90, 160 })); |
| ... | @@ -126,6 +130,7 @@ test "vector bit operators" { | ... | @@ -126,6 +130,7 @@ test "vector bit operators" { |
| 126 | fn doTheTest() !void { | 130 | fn doTheTest() !void { |
| 127 | var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; | 131 | var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; |
| 128 | var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; | 132 | var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; |
| 133 | _ = .{ &v, &x }; | ||
| 129 | try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); | 134 | try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); |
| 130 | try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); | 135 | try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); |
| 131 | try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); | 136 | try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); |
| ... | @@ -143,6 +148,7 @@ test "implicit cast vector to array" { | ... | @@ -143,6 +148,7 @@ test "implicit cast vector to array" { |
| 143 | const S = struct { | 148 | const S = struct { |
| 144 | fn doTheTest() !void { | 149 | fn doTheTest() !void { |
| 145 | var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; | 150 | var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; |
| 151 | _ = &a; | ||
| 146 | var result_array: [4]i32 = a; | 152 | var result_array: [4]i32 = a; |
| 147 | result_array = a; | 153 | result_array = a; |
| 148 | try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 })); | 154 | try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 })); |
| ... | @@ -160,8 +166,9 @@ test "array to vector" { | ... | @@ -160,8 +166,9 @@ test "array to vector" { |
| 160 | const S = struct { | 166 | const S = struct { |
| 161 | fn doTheTest() !void { | 167 | fn doTheTest() !void { |
| 162 | var foo: f32 = 3.14; | 168 | var foo: f32 = 3.14; |
| 163 | var arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; | 169 | _ = &foo; |
| 164 | var vec: @Vector(4, f32) = arr; | 170 | const arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; |
| 171 | const vec: @Vector(4, f32) = arr; | ||
| 165 | try expect(mem.eql(f32, &@as([4]f32, vec), &arr)); | 172 | try expect(mem.eql(f32, &@as([4]f32, vec), &arr)); |
| 166 | } | 173 | } |
| 167 | }; | 174 | }; |
| ... | @@ -180,25 +187,28 @@ test "array vector coercion - odd sizes" { | ... | @@ -180,25 +187,28 @@ test "array vector coercion - odd sizes" { |
| 180 | const S = struct { | 187 | const S = struct { |
| 181 | fn doTheTest() !void { | 188 | fn doTheTest() !void { |
| 182 | var foo1: i48 = 124578; | 189 | var foo1: i48 = 124578; |
| 183 | var vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; | 190 | _ = &foo1; |
| 184 | var arr1: [2]i48 = vec1; | 191 | const vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; |
| 192 | const arr1: [2]i48 = vec1; | ||
| 185 | try expect(vec1[0] == foo1 and vec1[1] == 1); | 193 | try expect(vec1[0] == foo1 and vec1[1] == 1); |
| 186 | try expect(arr1[0] == foo1 and arr1[1] == 1); | 194 | try expect(arr1[0] == foo1 and arr1[1] == 1); |
| 187 | 195 | ||
| 188 | var foo2: u4 = 5; | 196 | var foo2: u4 = 5; |
| 189 | var vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; | 197 | _ = &foo2; |
| 190 | var arr2: [2]u4 = vec2; | 198 | const vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; |
| 199 | const arr2: [2]u4 = vec2; | ||
| 191 | try expect(vec2[0] == foo2 and vec2[1] == 1); | 200 | try expect(vec2[0] == foo2 and vec2[1] == 1); |
| 192 | try expect(arr2[0] == foo2 and arr2[1] == 1); | 201 | try expect(arr2[0] == foo2 and arr2[1] == 1); |
| 193 | 202 | ||
| 194 | var foo3: u13 = 13; | 203 | var foo3: u13 = 13; |
| 195 | var vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; | 204 | _ = &foo3; |
| 196 | var arr3: [3]u13 = vec3; | 205 | const vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; |
| 206 | const arr3: [3]u13 = vec3; | ||
| 197 | try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1); | 207 | try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1); |
| 198 | try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1); | 208 | try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1); |
| 199 | 209 | ||
| 200 | var arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; | 210 | const arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; |
| 201 | var vec4: @Vector(4, u24) = arr4; | 211 | const vec4: @Vector(4, u24) = arr4; |
| 202 | try expect(vec4[0] == foo3 and vec4[1] == foo2 and vec4[2] == 0 and vec4[3] == 1); | 212 | try expect(vec4[0] == foo3 and vec4[1] == foo2 and vec4[2] == 0 and vec4[3] == 1); |
| 203 | } | 213 | } |
| 204 | }; | 214 | }; |
| ... | @@ -217,8 +227,9 @@ test "array to vector with element type coercion" { | ... | @@ -217,8 +227,9 @@ test "array to vector with element type coercion" { |
| 217 | const S = struct { | 227 | const S = struct { |
| 218 | fn doTheTest() !void { | 228 | fn doTheTest() !void { |
| 219 | var foo: f16 = 3.14; | 229 | var foo: f16 = 3.14; |
| 220 | var arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; | 230 | _ = &foo; |
| 221 | var vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; | 231 | const arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; |
| 232 | const vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; | ||
| 222 | try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32)); | 233 | try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32)); |
| 223 | } | 234 | } |
| 224 | }; | 235 | }; |
| ... | @@ -237,7 +248,8 @@ test "peer type resolution with coercible element types" { | ... | @@ -237,7 +248,8 @@ test "peer type resolution with coercible element types" { |
| 237 | var b: @Vector(2, u8) = .{ 1, 2 }; | 248 | var b: @Vector(2, u8) = .{ 1, 2 }; |
| 238 | var a: @Vector(2, u16) = .{ 2, 1 }; | 249 | var a: @Vector(2, u16) = .{ 2, 1 }; |
| 239 | var t: bool = true; | 250 | var t: bool = true; |
| 240 | var c = if (t) a else b; | 251 | _ = .{ &a, &b, &t }; |
| 252 | const c = if (t) a else b; | ||
| 241 | try std.testing.expect(@TypeOf(c) == @Vector(2, u16)); | 253 | try std.testing.expect(@TypeOf(c) == @Vector(2, u16)); |
| 242 | } | 254 | } |
| 243 | }; | 255 | }; |
| ... | @@ -285,22 +297,26 @@ test "vector casts of sizes not divisible by 8" { | ... | @@ -285,22 +297,26 @@ test "vector casts of sizes not divisible by 8" { |
| 285 | fn doTheTest() !void { | 297 | fn doTheTest() !void { |
| 286 | { | 298 | { |
| 287 | var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; | 299 | var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; |
| 288 | var x: [4]u3 = v; | 300 | _ = &v; |
| 301 | const x: [4]u3 = v; | ||
| 289 | try expect(mem.eql(u3, &x, &@as([4]u3, v))); | 302 | try expect(mem.eql(u3, &x, &@as([4]u3, v))); |
| 290 | } | 303 | } |
| 291 | { | 304 | { |
| 292 | var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; | 305 | var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; |
| 293 | var x: [4]u2 = v; | 306 | _ = &v; |
| 307 | const x: [4]u2 = v; | ||
| 294 | try expect(mem.eql(u2, &x, &@as([4]u2, v))); | 308 | try expect(mem.eql(u2, &x, &@as([4]u2, v))); |
| 295 | } | 309 | } |
| 296 | { | 310 | { |
| 297 | var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; | 311 | var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; |
| 298 | var x: [4]u1 = v; | 312 | _ = &v; |
| 313 | const x: [4]u1 = v; | ||
| 299 | try expect(mem.eql(u1, &x, &@as([4]u1, v))); | 314 | try expect(mem.eql(u1, &x, &@as([4]u1, v))); |
| 300 | } | 315 | } |
| 301 | { | 316 | { |
| 302 | var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; | 317 | var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; |
| 303 | var x: [4]bool = v; | 318 | _ = &v; |
| 319 | const x: [4]bool = v; | ||
| 304 | try expect(mem.eql(bool, &x, &@as([4]bool, v))); | 320 | try expect(mem.eql(bool, &x, &@as([4]bool, v))); |
| 305 | } | 321 | } |
| 306 | } | 322 | } |
| ... | @@ -327,7 +343,8 @@ test "vector @splat" { | ... | @@ -327,7 +343,8 @@ test "vector @splat" { |
| 327 | fn testForT(comptime N: comptime_int, v: anytype) !void { | 343 | fn testForT(comptime N: comptime_int, v: anytype) !void { |
| 328 | const T = @TypeOf(v); | 344 | const T = @TypeOf(v); |
| 329 | var vec: @Vector(N, T) = @splat(v); | 345 | var vec: @Vector(N, T) = @splat(v); |
| 330 | var as_array = @as([N]T, vec); | 346 | _ = &vec; |
| 347 | const as_array = @as([N]T, vec); | ||
| 331 | for (as_array) |elem| try expect(v == elem); | 348 | for (as_array) |elem| try expect(v == elem); |
| 332 | } | 349 | } |
| 333 | fn doTheTest() !void { | 350 | fn doTheTest() !void { |
| ... | @@ -412,6 +429,7 @@ test "load vector elements via runtime index" { | ... | @@ -412,6 +429,7 @@ test "load vector elements via runtime index" { |
| 412 | const S = struct { | 429 | const S = struct { |
| 413 | fn doTheTest() !void { | 430 | fn doTheTest() !void { |
| 414 | var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined }; | 431 | var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined }; |
| 432 | _ = &v; | ||
| 415 | var i: u32 = 0; | 433 | var i: u32 = 0; |
| 416 | try expect(v[i] == 1); | 434 | try expect(v[i] == 1); |
| 417 | i += 1; | 435 | i += 1; |
| ... | @@ -461,7 +479,7 @@ test "initialize vector which is a struct field" { | ... | @@ -461,7 +479,7 @@ test "initialize vector which is a struct field" { |
| 461 | var foo = Vec4Obj{ | 479 | var foo = Vec4Obj{ |
| 462 | .data = [_]f32{ 1, 2, 3, 4 }, | 480 | .data = [_]f32{ 1, 2, 3, 4 }, |
| 463 | }; | 481 | }; |
| 464 | _ = foo; | 482 | _ = &foo; |
| 465 | } | 483 | } |
| 466 | }; | 484 | }; |
| 467 | try S.doTheTest(); | 485 | try S.doTheTest(); |
| ... | @@ -481,6 +499,7 @@ test "vector comparison operators" { | ... | @@ -481,6 +499,7 @@ test "vector comparison operators" { |
| 481 | const V = @Vector(4, bool); | 499 | const V = @Vector(4, bool); |
| 482 | var v1: V = [_]bool{ true, false, true, false }; | 500 | var v1: V = [_]bool{ true, false, true, false }; |
| 483 | var v2: V = [_]bool{ false, true, false, true }; | 501 | var v2: V = [_]bool{ false, true, false, true }; |
| 502 | _ = .{ &v1, &v2 }; | ||
| 484 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1))); | 503 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1))); |
| 485 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2))); | 504 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2))); |
| 486 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v2))); | 505 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v2))); |
| ... | @@ -491,6 +510,7 @@ test "vector comparison operators" { | ... | @@ -491,6 +510,7 @@ test "vector comparison operators" { |
| 491 | var v1: @Vector(4, u32) = @splat(0xc0ffeeee); | 510 | var v1: @Vector(4, u32) = @splat(0xc0ffeeee); |
| 492 | var v2: @Vector(4, c_uint) = v1; | 511 | var v2: @Vector(4, c_uint) = v1; |
| 493 | var v3: @Vector(4, u32) = @splat(0xdeadbeef); | 512 | var v3: @Vector(4, u32) = @splat(0xdeadbeef); |
| 513 | _ = .{ &v1, &v2, &v3 }; | ||
| 494 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2))); | 514 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2))); |
| 495 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3))); | 515 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3))); |
| 496 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v3))); | 516 | try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v3))); |
| ... | @@ -499,6 +519,7 @@ test "vector comparison operators" { | ... | @@ -499,6 +519,7 @@ test "vector comparison operators" { |
| 499 | { | 519 | { |
| 500 | // Comptime-known LHS/RHS | 520 | // Comptime-known LHS/RHS |
| 501 | var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 }; | 521 | var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 }; |
| 522 | _ = &v1; | ||
| 502 | const v2: @Vector(4, u32) = @splat(2); | 523 | const v2: @Vector(4, u32) = @splat(2); |
| 503 | const v3: @Vector(4, bool) = [_]bool{ true, false, true, false }; | 524 | const v3: @Vector(4, bool) = [_]bool{ true, false, true, false }; |
| 504 | try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2))); | 525 | try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2))); |
| ... | @@ -604,7 +625,7 @@ test "vector bitwise not operator" { | ... | @@ -604,7 +625,7 @@ test "vector bitwise not operator" { |
| 604 | 625 | ||
| 605 | const S = struct { | 626 | const S = struct { |
| 606 | fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void { | 627 | fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void { |
| 607 | var y = ~x; | 628 | const y = ~x; |
| 608 | for (@as([4]T, y), 0..) |v, i| { | 629 | for (@as([4]T, y), 0..) |v, i| { |
| 609 | try expect(~x[i] == v); | 630 | try expect(~x[i] == v); |
| 610 | } | 631 | } |
| ... | @@ -640,14 +661,14 @@ test "vector shift operators" { | ... | @@ -640,14 +661,14 @@ test "vector shift operators" { |
| 640 | const TX = @typeInfo(@TypeOf(x)).Array.child; | 661 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 641 | const TY = @typeInfo(@TypeOf(y)).Array.child; | 662 | const TY = @typeInfo(@TypeOf(y)).Array.child; |
| 642 | 663 | ||
| 643 | var xv = @as(@Vector(N, TX), x); | 664 | const xv = @as(@Vector(N, TX), x); |
| 644 | var yv = @as(@Vector(N, TY), y); | 665 | const yv = @as(@Vector(N, TY), y); |
| 645 | 666 | ||
| 646 | var z0 = xv >> yv; | 667 | const z0 = xv >> yv; |
| 647 | for (@as([N]TX, z0), 0..) |v, i| { | 668 | for (@as([N]TX, z0), 0..) |v, i| { |
| 648 | try expect(x[i] >> y[i] == v); | 669 | try expect(x[i] >> y[i] == v); |
| 649 | } | 670 | } |
| 650 | var z1 = xv << yv; | 671 | const z1 = xv << yv; |
| 651 | for (@as([N]TX, z1), 0..) |v, i| { | 672 | for (@as([N]TX, z1), 0..) |v, i| { |
| 652 | try expect(x[i] << y[i] == v); | 673 | try expect(x[i] << y[i] == v); |
| 653 | } | 674 | } |
| ... | @@ -657,10 +678,10 @@ test "vector shift operators" { | ... | @@ -657,10 +678,10 @@ test "vector shift operators" { |
| 657 | const TX = @typeInfo(@TypeOf(x)).Array.child; | 678 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 658 | const TY = @typeInfo(@TypeOf(y)).Array.child; | 679 | const TY = @typeInfo(@TypeOf(y)).Array.child; |
| 659 | 680 | ||
| 660 | var xv = @as(@Vector(N, TX), x); | 681 | const xv = @as(@Vector(N, TX), x); |
| 661 | var yv = @as(@Vector(N, TY), y); | 682 | const yv = @as(@Vector(N, TY), y); |
| 662 | 683 | ||
| 663 | var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); | 684 | const z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); |
| 664 | for (@as([N]TX, z), 0..) |v, i| { | 685 | for (@as([N]TX, z), 0..) |v, i| { |
| 665 | const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i]; | 686 | const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i]; |
| 666 | try expect(check == v); | 687 | try expect(check == v); |
| ... | @@ -734,7 +755,7 @@ test "vector reduce operation" { | ... | @@ -734,7 +755,7 @@ test "vector reduce operation" { |
| 734 | const N = @typeInfo(@TypeOf(x)).Array.len; | 755 | const N = @typeInfo(@TypeOf(x)).Array.len; |
| 735 | const TX = @typeInfo(@TypeOf(x)).Array.child; | 756 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 736 | 757 | ||
| 737 | var r = @reduce(op, @as(@Vector(N, TX), x)); | 758 | const r = @reduce(op, @as(@Vector(N, TX), x)); |
| 738 | switch (@typeInfo(TX)) { | 759 | switch (@typeInfo(TX)) { |
| 739 | .Int, .Bool => try expect(expected == r), | 760 | .Int, .Bool => try expect(expected == r), |
| 740 | .Float => { | 761 | .Float => { |
| ... | @@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" { | ... | @@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" { |
| 892 | const __v4hi = @Vector(4, i16); | 913 | const __v4hi = @Vector(4, i16); |
| 893 | var v4_a = __v4hi{ 0, 0, 0, 0 }; | 914 | var v4_a = __v4hi{ 0, 0, 0, 0 }; |
| 894 | var v4_b = __v4hi{ 0, 0, 0, 0 }; | 915 | var v4_b = __v4hi{ 0, 0, 0, 0 }; |
| 895 | var shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){ | 916 | _ = .{ &v4_a, &v4_b }; |
| 917 | const shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){ | ||
| 896 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), | 918 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), |
| 897 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), | 919 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), |
| 898 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), | 920 | std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), |
| ... | @@ -915,7 +937,8 @@ test "saturating add" { | ... | @@ -915,7 +937,8 @@ test "saturating add" { |
| 915 | const u8x3 = @Vector(3, u8); | 937 | const u8x3 = @Vector(3, u8); |
| 916 | var lhs = u8x3{ 255, 254, 1 }; | 938 | var lhs = u8x3{ 255, 254, 1 }; |
| 917 | var rhs = u8x3{ 1, 2, 255 }; | 939 | var rhs = u8x3{ 1, 2, 255 }; |
| 918 | var result = lhs +| rhs; | 940 | _ = .{ &lhs, &rhs }; |
| 941 | const result = lhs +| rhs; | ||
| 919 | const expected = u8x3{ 255, 255, 255 }; | 942 | const expected = u8x3{ 255, 255, 255 }; |
| 920 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); | 943 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); |
| 921 | } | 944 | } |
| ... | @@ -923,7 +946,8 @@ test "saturating add" { | ... | @@ -923,7 +946,8 @@ test "saturating add" { |
| 923 | const i8x3 = @Vector(3, i8); | 946 | const i8x3 = @Vector(3, i8); |
| 924 | var lhs = i8x3{ 127, 126, 1 }; | 947 | var lhs = i8x3{ 127, 126, 1 }; |
| 925 | var rhs = i8x3{ 1, 2, 127 }; | 948 | var rhs = i8x3{ 1, 2, 127 }; |
| 926 | var result = lhs +| rhs; | 949 | _ = .{ &lhs, &rhs }; |
| 950 | const result = lhs +| rhs; | ||
| 927 | const expected = i8x3{ 127, 127, 127 }; | 951 | const expected = i8x3{ 127, 127, 127 }; |
| 928 | try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result))); | 952 | try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result))); |
| 929 | } | 953 | } |
| ... | @@ -947,7 +971,8 @@ test "saturating subtraction" { | ... | @@ -947,7 +971,8 @@ test "saturating subtraction" { |
| 947 | const u8x3 = @Vector(3, u8); | 971 | const u8x3 = @Vector(3, u8); |
| 948 | var lhs = u8x3{ 0, 0, 0 }; | 972 | var lhs = u8x3{ 0, 0, 0 }; |
| 949 | var rhs = u8x3{ 255, 255, 255 }; | 973 | var rhs = u8x3{ 255, 255, 255 }; |
| 950 | var result = lhs -| rhs; | 974 | _ = .{ &lhs, &rhs }; |
| 975 | const result = lhs -| rhs; | ||
| 951 | const expected = u8x3{ 0, 0, 0 }; | 976 | const expected = u8x3{ 0, 0, 0 }; |
| 952 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); | 977 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); |
| 953 | } | 978 | } |
| ... | @@ -973,7 +998,8 @@ test "saturating multiplication" { | ... | @@ -973,7 +998,8 @@ test "saturating multiplication" { |
| 973 | const u8x3 = @Vector(3, u8); | 998 | const u8x3 = @Vector(3, u8); |
| 974 | var lhs = u8x3{ 2, 2, 2 }; | 999 | var lhs = u8x3{ 2, 2, 2 }; |
| 975 | var rhs = u8x3{ 255, 255, 255 }; | 1000 | var rhs = u8x3{ 255, 255, 255 }; |
| 976 | var result = lhs *| rhs; | 1001 | _ = .{ &lhs, &rhs }; |
| 1002 | const result = lhs *| rhs; | ||
| 977 | const expected = u8x3{ 255, 255, 255 }; | 1003 | const expected = u8x3{ 255, 255, 255 }; |
| 978 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); | 1004 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); |
| 979 | } | 1005 | } |
| ... | @@ -997,7 +1023,8 @@ test "saturating shift-left" { | ... | @@ -997,7 +1023,8 @@ test "saturating shift-left" { |
| 997 | const u8x3 = @Vector(3, u8); | 1023 | const u8x3 = @Vector(3, u8); |
| 998 | var lhs = u8x3{ 1, 1, 1 }; | 1024 | var lhs = u8x3{ 1, 1, 1 }; |
| 999 | var rhs = u8x3{ 255, 255, 255 }; | 1025 | var rhs = u8x3{ 255, 255, 255 }; |
| 1000 | var result = lhs <<| rhs; | 1026 | _ = .{ &lhs, &rhs }; |
| 1027 | const result = lhs <<| rhs; | ||
| 1001 | const expected = u8x3{ 255, 255, 255 }; | 1028 | const expected = u8x3{ 255, 255, 255 }; |
| 1002 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); | 1029 | try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); |
| 1003 | } | 1030 | } |
| ... | @@ -1040,29 +1067,33 @@ test "@addWithOverflow" { | ... | @@ -1040,29 +1067,33 @@ test "@addWithOverflow" { |
| 1040 | { | 1067 | { |
| 1041 | var lhs = @Vector(4, u8){ 250, 250, 250, 250 }; | 1068 | var lhs = @Vector(4, u8){ 250, 250, 250, 250 }; |
| 1042 | var rhs = @Vector(4, u8){ 0, 5, 6, 10 }; | 1069 | var rhs = @Vector(4, u8){ 0, 5, 6, 10 }; |
| 1043 | var overflow = @addWithOverflow(lhs, rhs)[1]; | 1070 | _ = .{ &lhs, &rhs }; |
| 1044 | var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; | 1071 | const overflow = @addWithOverflow(lhs, rhs)[1]; |
| 1072 | const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; | ||
| 1045 | try expectEqual(expected, overflow); | 1073 | try expectEqual(expected, overflow); |
| 1046 | } | 1074 | } |
| 1047 | { | 1075 | { |
| 1048 | var lhs = @Vector(4, i8){ -125, -125, 125, 125 }; | 1076 | var lhs = @Vector(4, i8){ -125, -125, 125, 125 }; |
| 1049 | var rhs = @Vector(4, i8){ -3, -4, 2, 3 }; | 1077 | var rhs = @Vector(4, i8){ -3, -4, 2, 3 }; |
| 1050 | var overflow = @addWithOverflow(lhs, rhs)[1]; | 1078 | _ = .{ &lhs, &rhs }; |
| 1051 | var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | 1079 | const overflow = @addWithOverflow(lhs, rhs)[1]; |
| 1080 | const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | ||
| 1052 | try expectEqual(expected, overflow); | 1081 | try expectEqual(expected, overflow); |
| 1053 | } | 1082 | } |
| 1054 | { | 1083 | { |
| 1055 | var lhs = @Vector(4, u1){ 0, 0, 1, 1 }; | 1084 | var lhs = @Vector(4, u1){ 0, 0, 1, 1 }; |
| 1056 | var rhs = @Vector(4, u1){ 0, 1, 0, 1 }; | 1085 | var rhs = @Vector(4, u1){ 0, 1, 0, 1 }; |
| 1057 | var overflow = @addWithOverflow(lhs, rhs)[1]; | 1086 | _ = .{ &lhs, &rhs }; |
| 1058 | var expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; | 1087 | const overflow = @addWithOverflow(lhs, rhs)[1]; |
| 1088 | const expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; | ||
| 1059 | try expectEqual(expected, overflow); | 1089 | try expectEqual(expected, overflow); |
| 1060 | } | 1090 | } |
| 1061 | { | 1091 | { |
| 1062 | var lhs = @Vector(4, u0){ 0, 0, 0, 0 }; | 1092 | var lhs = @Vector(4, u0){ 0, 0, 0, 0 }; |
| 1063 | var rhs = @Vector(4, u0){ 0, 0, 0, 0 }; | 1093 | var rhs = @Vector(4, u0){ 0, 0, 0, 0 }; |
| 1064 | var overflow = @addWithOverflow(lhs, rhs)[1]; | 1094 | _ = .{ &lhs, &rhs }; |
| 1065 | var expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; | 1095 | const overflow = @addWithOverflow(lhs, rhs)[1]; |
| 1096 | const expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; | ||
| 1066 | try expectEqual(expected, overflow); | 1097 | try expectEqual(expected, overflow); |
| 1067 | } | 1098 | } |
| 1068 | } | 1099 | } |
| ... | @@ -1084,15 +1115,17 @@ test "@subWithOverflow" { | ... | @@ -1084,15 +1115,17 @@ test "@subWithOverflow" { |
| 1084 | { | 1115 | { |
| 1085 | var lhs = @Vector(2, u8){ 5, 5 }; | 1116 | var lhs = @Vector(2, u8){ 5, 5 }; |
| 1086 | var rhs = @Vector(2, u8){ 5, 6 }; | 1117 | var rhs = @Vector(2, u8){ 5, 6 }; |
| 1087 | var overflow = @subWithOverflow(lhs, rhs)[1]; | 1118 | _ = .{ &lhs, &rhs }; |
| 1088 | var expected: @Vector(2, u1) = .{ 0, 1 }; | 1119 | const overflow = @subWithOverflow(lhs, rhs)[1]; |
| 1120 | const expected: @Vector(2, u1) = .{ 0, 1 }; | ||
| 1089 | try expectEqual(expected, overflow); | 1121 | try expectEqual(expected, overflow); |
| 1090 | } | 1122 | } |
| 1091 | { | 1123 | { |
| 1092 | var lhs = @Vector(4, i8){ -120, -120, 120, 120 }; | 1124 | var lhs = @Vector(4, i8){ -120, -120, 120, 120 }; |
| 1093 | var rhs = @Vector(4, i8){ 8, 9, -7, -8 }; | 1125 | var rhs = @Vector(4, i8){ 8, 9, -7, -8 }; |
| 1094 | var overflow = @subWithOverflow(lhs, rhs)[1]; | 1126 | _ = .{ &lhs, &rhs }; |
| 1095 | var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | 1127 | const overflow = @subWithOverflow(lhs, rhs)[1]; |
| 1128 | const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | ||
| 1096 | try expectEqual(expected, overflow); | 1129 | try expectEqual(expected, overflow); |
| 1097 | } | 1130 | } |
| 1098 | } | 1131 | } |
| ... | @@ -1113,8 +1146,9 @@ test "@mulWithOverflow" { | ... | @@ -1113,8 +1146,9 @@ test "@mulWithOverflow" { |
| 1113 | fn doTheTest() !void { | 1146 | fn doTheTest() !void { |
| 1114 | var lhs = @Vector(4, u8){ 10, 10, 10, 10 }; | 1147 | var lhs = @Vector(4, u8){ 10, 10, 10, 10 }; |
| 1115 | var rhs = @Vector(4, u8){ 25, 26, 0, 30 }; | 1148 | var rhs = @Vector(4, u8){ 25, 26, 0, 30 }; |
| 1116 | var overflow = @mulWithOverflow(lhs, rhs)[1]; | 1149 | _ = .{ &lhs, &rhs }; |
| 1117 | var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | 1150 | const overflow = @mulWithOverflow(lhs, rhs)[1]; |
| 1151 | const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; | ||
| 1118 | try expectEqual(expected, overflow); | 1152 | try expectEqual(expected, overflow); |
| 1119 | } | 1153 | } |
| 1120 | }; | 1154 | }; |
| ... | @@ -1134,8 +1168,9 @@ test "@shlWithOverflow" { | ... | @@ -1134,8 +1168,9 @@ test "@shlWithOverflow" { |
| 1134 | fn doTheTest() !void { | 1168 | fn doTheTest() !void { |
| 1135 | var lhs = @Vector(4, u8){ 0, 1, 8, 255 }; | 1169 | var lhs = @Vector(4, u8){ 0, 1, 8, 255 }; |
| 1136 | var rhs = @Vector(4, u3){ 7, 7, 7, 7 }; | 1170 | var rhs = @Vector(4, u3){ 7, 7, 7, 7 }; |
| 1137 | var overflow = @shlWithOverflow(lhs, rhs)[1]; | 1171 | _ = .{ &lhs, &rhs }; |
| 1138 | var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; | 1172 | const overflow = @shlWithOverflow(lhs, rhs)[1]; |
| 1173 | const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; | ||
| 1139 | try expectEqual(expected, overflow); | 1174 | try expectEqual(expected, overflow); |
| 1140 | } | 1175 | } |
| 1141 | }; | 1176 | }; |
| ... | @@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" { | ... | @@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" { |
| 1161 | @Vector(2, u8){ 0, 1 }, | 1196 | @Vector(2, u8){ 0, 1 }, |
| 1162 | @Vector(2, u8){ 2, 3 }, | 1197 | @Vector(2, u8){ 2, 3 }, |
| 1163 | }; | 1198 | }; |
| 1164 | var a: []const @Vector(2, u8) = &small_bases; | 1199 | const a: []const @Vector(2, u8) = &small_bases; |
| 1165 | var a4 = a[1][1]; | 1200 | const a4 = a[1][1]; |
| 1166 | try expect(a4 == 3); | 1201 | try expect(a4 == 3); |
| 1167 | } | 1202 | } |
| 1168 | 1203 | ||
| ... | @@ -1183,6 +1218,7 @@ test "array of vectors is copied" { | ... | @@ -1183,6 +1218,7 @@ test "array of vectors is copied" { |
| 1183 | Vec3{ -345, -311, 381 }, | 1218 | Vec3{ -345, -311, 381 }, |
| 1184 | Vec3{ -661, -816, -575 }, | 1219 | Vec3{ -661, -816, -575 }, |
| 1185 | }; | 1220 | }; |
| 1221 | _ = &points; | ||
| 1186 | var points2: [20]Vec3 = undefined; | 1222 | var points2: [20]Vec3 = undefined; |
| 1187 | points2[0..points.len].* = points; | 1223 | points2[0..points.len].* = points; |
| 1188 | try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 }); | 1224 | try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 }); |
| ... | @@ -1244,6 +1280,7 @@ test "zero multiplicand" { | ... | @@ -1244,6 +1280,7 @@ test "zero multiplicand" { |
| 1244 | 1280 | ||
| 1245 | const zeros = @Vector(2, u32){ 0.0, 0.0 }; | 1281 | const zeros = @Vector(2, u32){ 0.0, 0.0 }; |
| 1246 | var ones = @Vector(2, u32){ 1.0, 1.0 }; | 1282 | var ones = @Vector(2, u32){ 1.0, 1.0 }; |
| 1283 | _ = &ones; | ||
| 1247 | 1284 | ||
| 1248 | _ = (ones * zeros)[0]; | 1285 | _ = (ones * zeros)[0]; |
| 1249 | _ = (zeros * zeros)[0]; | 1286 | _ = (zeros * zeros)[0]; |
| ... | @@ -1266,6 +1303,7 @@ test "@intCast to u0" { | ... | @@ -1266,6 +1303,7 @@ test "@intCast to u0" { |
| 1266 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1303 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 1267 | 1304 | ||
| 1268 | var zeros = @Vector(2, u32){ 0, 0 }; | 1305 | var zeros = @Vector(2, u32){ 0, 0 }; |
| 1306 | _ = &zeros; | ||
| 1269 | const casted = @as(@Vector(2, u0), @intCast(zeros)); | 1307 | const casted = @as(@Vector(2, u0), @intCast(zeros)); |
| 1270 | 1308 | ||
| 1271 | _ = casted[0]; | 1309 | _ = casted[0]; |
| ... | @@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" { | ... | @@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" { |
| 1292 | const mask = [5]i32{ -1, 0, 1, 2, 3 }; | 1330 | const mask = [5]i32{ -1, 0, 1, 2, 3 }; |
| 1293 | 1331 | ||
| 1294 | var a = [5]u32{ 3, 5, 7, 9, 0 }; | 1332 | var a = [5]u32{ 3, 5, 7, 9, 0 }; |
| 1295 | var b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask); | 1333 | _ = &a; |
| 1334 | const b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask); | ||
| 1296 | try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b); | 1335 | try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b); |
| 1297 | } | 1336 | } |
| 1298 | 1337 | ||
| ... | @@ -1320,6 +1359,7 @@ test "store packed vector element" { | ... | @@ -1320,6 +1359,7 @@ test "store packed vector element" { |
| 1320 | var v = @Vector(4, u1){ 1, 1, 1, 1 }; | 1359 | var v = @Vector(4, u1){ 1, 1, 1, 1 }; |
| 1321 | try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v); | 1360 | try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v); |
| 1322 | var index: usize = 0; | 1361 | var index: usize = 0; |
| 1362 | _ = &index; | ||
| 1323 | v[index] = 0; | 1363 | v[index] = 0; |
| 1324 | try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v); | 1364 | try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v); |
| 1325 | } | 1365 | } |
| ... | @@ -1337,6 +1377,7 @@ test "store to vector in slice" { | ... | @@ -1337,6 +1377,7 @@ test "store to vector in slice" { |
| 1337 | }; | 1377 | }; |
| 1338 | var s: []@Vector(3, f32) = &v; | 1378 | var s: []@Vector(3, f32) = &v; |
| 1339 | var i: usize = 1; | 1379 | var i: usize = 1; |
| 1380 | _ = &i; | ||
| 1340 | s[i] = s[0]; | 1381 | s[i] = s[0]; |
| 1341 | try expectEqual(v[1], v[0]); | 1382 | try expectEqual(v[1], v[0]); |
| 1342 | } | 1383 | } |
| ... | @@ -1378,6 +1419,7 @@ test "store vector with memset" { | ... | @@ -1378,6 +1419,7 @@ test "store vector with memset" { |
| 1378 | var kc = @Vector(2, i4){ 2, 3 }; | 1419 | var kc = @Vector(2, i4){ 2, 3 }; |
| 1379 | var kd = @Vector(2, u8){ 4, 5 }; | 1420 | var kd = @Vector(2, u8){ 4, 5 }; |
| 1380 | var ke = @Vector(2, i9){ 6, 7 }; | 1421 | var ke = @Vector(2, i9){ 6, 7 }; |
| 1422 | _ = .{ &ka, &kb, &kc, &kd, &ke }; | ||
| 1381 | @memset(&a, ka); | 1423 | @memset(&a, ka); |
| 1382 | @memset(&b, kb); | 1424 | @memset(&b, kb); |
| 1383 | @memset(&c, kc); | 1425 | @memset(&c, kc); |
| ... | @@ -1410,6 +1452,7 @@ test "compare vectors with different element types" { | ... | @@ -1410,6 +1452,7 @@ test "compare vectors with different element types" { |
| 1410 | 1452 | ||
| 1411 | var a: @Vector(2, u8) = .{ 1, 2 }; | 1453 | var a: @Vector(2, u8) = .{ 1, 2 }; |
| 1412 | var b: @Vector(2, u9) = .{ 3, 0 }; | 1454 | var b: @Vector(2, u9) = .{ 3, 0 }; |
| 1455 | _ = .{ &a, &b }; | ||
| 1413 | try expectEqual(@Vector(2, bool){ true, false }, a < b); | 1456 | try expectEqual(@Vector(2, bool){ true, false }, a < b); |
| 1414 | } | 1457 | } |
| 1415 | 1458 | ||
| ... | @@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" { | ... | @@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" { |
| 1465 | const VecB = @Vector(4, u32); | 1508 | const VecB = @Vector(4, u32); |
| 1466 | 1509 | ||
| 1467 | var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 }; | 1510 | var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 1468 | var vec_b: VecB = @bitCast(vec_a); | 1511 | _ = &vec_a; |
| 1469 | var vec_c: VecA = @bitCast(vec_b); | 1512 | const vec_b: VecB = @bitCast(vec_a); |
| 1513 | const vec_c: VecA = @bitCast(vec_b); | ||
| 1470 | try expectEqual(vec_a, vec_c); | 1514 | try expectEqual(vec_a, vec_c); |
| 1471 | } | 1515 | } |
| 1472 | }; | 1516 | }; |
test/behavior/void.zig+3-1| ... | @@ -38,16 +38,18 @@ test "void optional" { | ... | @@ -38,16 +38,18 @@ test "void optional" { |
| 38 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 38 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 39 | 39 | ||
| 40 | var x: ?void = {}; | 40 | var x: ?void = {}; |
| 41 | _ = &x; | ||
| 41 | try expect(x != null); | 42 | try expect(x != null); |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | test "void array as a local variable initializer" { | 45 | test "void array as a local variable initializer" { |
| 45 | var x = [_]void{{}} ** 1004; | 46 | var x = [_]void{{}} ** 1004; |
| 47 | _ = &x[0]; | ||
| 46 | _ = x[0]; | 48 | _ = x[0]; |
| 47 | } | 49 | } |
| 48 | 50 | ||
| 49 | const void_constant = {}; | 51 | const void_constant = {}; |
| 50 | test "reference to void constants" { | 52 | test "reference to void constants" { |
| 51 | var a = void_constant; | 53 | var a = void_constant; |
| 52 | _ = a; | 54 | _ = &a; |
| 53 | } | 55 | } |
test/behavior/wasm.zig+1| ... | @@ -4,6 +4,7 @@ const builtin = @import("builtin"); | ... | @@ -4,6 +4,7 @@ const builtin = @import("builtin"); |
| 4 | 4 | ||
| 5 | test "memory size and grow" { | 5 | test "memory size and grow" { |
| 6 | var prev = @wasmMemorySize(0); | 6 | var prev = @wasmMemorySize(0); |
| 7 | _ = &prev; | ||
| 7 | try expect(prev == @wasmMemoryGrow(0, 1)); | 8 | try expect(prev == @wasmMemoryGrow(0, 1)); |
| 8 | try expect(prev + 1 == @wasmMemorySize(0)); | 9 | try expect(prev + 1 == @wasmMemorySize(0)); |
| 9 | } | 10 | } |
test/behavior/widening.zig+5| ... | @@ -15,6 +15,7 @@ test "integer widening" { | ... | @@ -15,6 +15,7 @@ test "integer widening" { |
| 15 | var d: u64 = c; | 15 | var d: u64 = c; |
| 16 | var e: u64 = d; | 16 | var e: u64 = d; |
| 17 | var f: u128 = e; | 17 | var f: u128 = e; |
| 18 | _ = .{ &a, &b, &c, &d, &e, &f }; | ||
| 18 | try expect(f == a); | 19 | try expect(f == a); |
| 19 | } | 20 | } |
| 20 | 21 | ||
| ... | @@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" { | ... | @@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" { |
| 33 | 34 | ||
| 34 | var a: u8 = 250; | 35 | var a: u8 = 250; |
| 35 | var b: i16 = a; | 36 | var b: i16 = a; |
| 37 | _ = .{ &a, &b }; | ||
| 36 | try expect(b == 250); | 38 | try expect(b == 250); |
| 37 | } | 39 | } |
| 38 | 40 | ||
| ... | @@ -47,10 +49,12 @@ test "float widening" { | ... | @@ -47,10 +49,12 @@ test "float widening" { |
| 47 | var b: f32 = a; | 49 | var b: f32 = a; |
| 48 | var c: f64 = b; | 50 | var c: f64 = b; |
| 49 | var d: f128 = c; | 51 | var d: f128 = c; |
| 52 | _ = .{ &a, &b, &c, &d }; | ||
| 50 | try expect(a == b); | 53 | try expect(a == b); |
| 51 | try expect(b == c); | 54 | try expect(b == c); |
| 52 | try expect(c == d); | 55 | try expect(c == d); |
| 53 | var e: f80 = c; | 56 | var e: f80 = c; |
| 57 | _ = &e; | ||
| 54 | try expect(c == e); | 58 | try expect(c == e); |
| 55 | } | 59 | } |
| 56 | 60 | ||
| ... | @@ -63,6 +67,7 @@ test "float widening f16 to f128" { | ... | @@ -63,6 +67,7 @@ test "float widening f16 to f128" { |
| 63 | 67 | ||
| 64 | var x: f16 = 12.34; | 68 | var x: f16 = 12.34; |
| 65 | var y: f128 = x; | 69 | var y: f128 = x; |
| 70 | _ = .{ &x, &y }; | ||
| 66 | try expect(x == y); | 71 | try expect(x == y); |
| 67 | } | 72 | } |
| 68 | 73 |
test/c_abi/main.zig+32-31| ... | @@ -278,7 +278,7 @@ test "C ABI big struct" { | ... | @@ -278,7 +278,7 @@ test "C ABI big struct" { |
| 278 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; | 278 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; |
| 279 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 279 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 280 | 280 | ||
| 281 | var s = BigStruct{ | 281 | const s = BigStruct{ |
| 282 | .a = 1, | 282 | .a = 1, |
| 283 | .b = 2, | 283 | .b = 2, |
| 284 | .c = 3, | 284 | .c = 3, |
| ... | @@ -304,7 +304,7 @@ extern fn c_big_union(BigUnion) void; | ... | @@ -304,7 +304,7 @@ extern fn c_big_union(BigUnion) void; |
| 304 | test "C ABI big union" { | 304 | test "C ABI big union" { |
| 305 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 305 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 306 | 306 | ||
| 307 | var x = BigUnion{ | 307 | const x = BigUnion{ |
| 308 | .a = BigStruct{ | 308 | .a = BigStruct{ |
| 309 | .a = 1, | 309 | .a = 1, |
| 310 | .b = 2, | 310 | .b = 2, |
| ... | @@ -339,13 +339,13 @@ test "C ABI medium struct of ints and floats" { | ... | @@ -339,13 +339,13 @@ test "C ABI medium struct of ints and floats" { |
| 339 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 339 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 340 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; | 340 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 341 | 341 | ||
| 342 | var s = MedStructMixed{ | 342 | const s = MedStructMixed{ |
| 343 | .a = 1234, | 343 | .a = 1234, |
| 344 | .b = 100.0, | 344 | .b = 100.0, |
| 345 | .c = 1337.0, | 345 | .c = 1337.0, |
| 346 | }; | 346 | }; |
| 347 | c_med_struct_mixed(s); | 347 | c_med_struct_mixed(s); |
| 348 | var s2 = c_ret_med_struct_mixed(); | 348 | const s2 = c_ret_med_struct_mixed(); |
| 349 | try expect(s2.a == 1234); | 349 | try expect(s2.a == 1234); |
| 350 | try expect(s2.b == 100.0); | 350 | try expect(s2.b == 100.0); |
| 351 | try expect(s2.c == 1337.0); | 351 | try expect(s2.c == 1337.0); |
| ... | @@ -372,14 +372,14 @@ test "C ABI small struct of ints" { | ... | @@ -372,14 +372,14 @@ test "C ABI small struct of ints" { |
| 372 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 372 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 373 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; | 373 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 374 | 374 | ||
| 375 | var s = SmallStructInts{ | 375 | const s = SmallStructInts{ |
| 376 | .a = 1, | 376 | .a = 1, |
| 377 | .b = 2, | 377 | .b = 2, |
| 378 | .c = 3, | 378 | .c = 3, |
| 379 | .d = 4, | 379 | .d = 4, |
| 380 | }; | 380 | }; |
| 381 | c_small_struct_ints(s); | 381 | c_small_struct_ints(s); |
| 382 | var s2 = c_ret_small_struct_ints(); | 382 | const s2 = c_ret_small_struct_ints(); |
| 383 | try expect(s2.a == 1); | 383 | try expect(s2.a == 1); |
| 384 | try expect(s2.b == 2); | 384 | try expect(s2.b == 2); |
| 385 | try expect(s2.c == 3); | 385 | try expect(s2.c == 3); |
| ... | @@ -407,13 +407,13 @@ test "C ABI medium struct of ints" { | ... | @@ -407,13 +407,13 @@ test "C ABI medium struct of ints" { |
| 407 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 407 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 408 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; | 408 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 409 | 409 | ||
| 410 | var s = MedStructInts{ | 410 | const s = MedStructInts{ |
| 411 | .x = 1, | 411 | .x = 1, |
| 412 | .y = 2, | 412 | .y = 2, |
| 413 | .z = 3, | 413 | .z = 3, |
| 414 | }; | 414 | }; |
| 415 | c_med_struct_ints(s); | 415 | c_med_struct_ints(s); |
| 416 | var s2 = c_ret_med_struct_ints(); | 416 | const s2 = c_ret_med_struct_ints(); |
| 417 | try expect(s2.x == 1); | 417 | try expect(s2.x == 1); |
| 418 | try expect(s2.y == 2); | 418 | try expect(s2.y == 2); |
| 419 | try expect(s2.z == 3); | 419 | try expect(s2.z == 3); |
| ... | @@ -442,9 +442,9 @@ export fn zig_small_packed_struct(x: SmallPackedStruct) void { | ... | @@ -442,9 +442,9 @@ export fn zig_small_packed_struct(x: SmallPackedStruct) void { |
| 442 | } | 442 | } |
| 443 | 443 | ||
| 444 | test "C ABI small packed struct" { | 444 | test "C ABI small packed struct" { |
| 445 | var s = SmallPackedStruct{ .a = 0, .b = 1, .c = 2, .d = 3 }; | 445 | const s = SmallPackedStruct{ .a = 0, .b = 1, .c = 2, .d = 3 }; |
| 446 | c_small_packed_struct(s); | 446 | c_small_packed_struct(s); |
| 447 | var s2 = c_ret_small_packed_struct(); | 447 | const s2 = c_ret_small_packed_struct(); |
| 448 | try expect(s2.a == 0); | 448 | try expect(s2.a == 0); |
| 449 | try expect(s2.b == 1); | 449 | try expect(s2.b == 1); |
| 450 | try expect(s2.c == 2); | 450 | try expect(s2.c == 2); |
| ... | @@ -466,9 +466,9 @@ export fn zig_big_packed_struct(x: BigPackedStruct) void { | ... | @@ -466,9 +466,9 @@ export fn zig_big_packed_struct(x: BigPackedStruct) void { |
| 466 | test "C ABI big packed struct" { | 466 | test "C ABI big packed struct" { |
| 467 | if (!has_i128) return error.SkipZigTest; | 467 | if (!has_i128) return error.SkipZigTest; |
| 468 | 468 | ||
| 469 | var s = BigPackedStruct{ .a = 1, .b = 2 }; | 469 | const s = BigPackedStruct{ .a = 1, .b = 2 }; |
| 470 | c_big_packed_struct(s); | 470 | c_big_packed_struct(s); |
| 471 | var s2 = c_ret_big_packed_struct(); | 471 | const s2 = c_ret_big_packed_struct(); |
| 472 | try expect(s2.a == 1); | 472 | try expect(s2.a == 1); |
| 473 | try expect(s2.b == 2); | 473 | try expect(s2.b == 2); |
| 474 | } | 474 | } |
| ... | @@ -486,7 +486,7 @@ test "C ABI split struct of ints" { | ... | @@ -486,7 +486,7 @@ test "C ABI split struct of ints" { |
| 486 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 486 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 487 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; | 487 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 488 | 488 | ||
| 489 | var s = SplitStructInt{ | 489 | const s = SplitStructInt{ |
| 490 | .a = 1234, | 490 | .a = 1234, |
| 491 | .b = 100, | 491 | .b = 100, |
| 492 | .c = 1337, | 492 | .c = 1337, |
| ... | @@ -514,13 +514,13 @@ test "C ABI split struct of ints and floats" { | ... | @@ -514,13 +514,13 @@ test "C ABI split struct of ints and floats" { |
| 514 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 514 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 515 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; | 515 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 516 | 516 | ||
| 517 | var s = SplitStructMixed{ | 517 | const s = SplitStructMixed{ |
| 518 | .a = 1234, | 518 | .a = 1234, |
| 519 | .b = 100, | 519 | .b = 100, |
| 520 | .c = 1337.0, | 520 | .c = 1337.0, |
| 521 | }; | 521 | }; |
| 522 | c_split_struct_mixed(s); | 522 | c_split_struct_mixed(s); |
| 523 | var s2 = c_ret_split_struct_mixed(); | 523 | const s2 = c_ret_split_struct_mixed(); |
| 524 | try expect(s2.a == 1234); | 524 | try expect(s2.a == 1234); |
| 525 | try expect(s2.b == 100); | 525 | try expect(s2.b == 100); |
| 526 | try expect(s2.c == 1337.0); | 526 | try expect(s2.c == 1337.0); |
| ... | @@ -541,14 +541,14 @@ test "C ABI sret and byval together" { | ... | @@ -541,14 +541,14 @@ test "C ABI sret and byval together" { |
| 541 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; | 541 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; |
| 542 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 542 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 543 | 543 | ||
| 544 | var s = BigStruct{ | 544 | const s = BigStruct{ |
| 545 | .a = 1, | 545 | .a = 1, |
| 546 | .b = 2, | 546 | .b = 2, |
| 547 | .c = 3, | 547 | .c = 3, |
| 548 | .d = 4, | 548 | .d = 4, |
| 549 | .e = 5, | 549 | .e = 5, |
| 550 | }; | 550 | }; |
| 551 | var y = c_big_struct_both(s); | 551 | const y = c_big_struct_both(s); |
| 552 | try expect(y.a == 10); | 552 | try expect(y.a == 10); |
| 553 | try expect(y.b == 11); | 553 | try expect(y.b == 11); |
| 554 | try expect(y.c == 12); | 554 | try expect(y.c == 12); |
| ... | @@ -562,7 +562,7 @@ export fn zig_big_struct_both(x: BigStruct) BigStruct { | ... | @@ -562,7 +562,7 @@ export fn zig_big_struct_both(x: BigStruct) BigStruct { |
| 562 | expect(x.c == 32) catch @panic("test failure"); | 562 | expect(x.c == 32) catch @panic("test failure"); |
| 563 | expect(x.d == 33) catch @panic("test failure"); | 563 | expect(x.d == 33) catch @panic("test failure"); |
| 564 | expect(x.e == 34) catch @panic("test failure"); | 564 | expect(x.e == 34) catch @panic("test failure"); |
| 565 | var s = BigStruct{ | 565 | const s = BigStruct{ |
| 566 | .a = 20, | 566 | .a = 20, |
| 567 | .b = 21, | 567 | .b = 21, |
| 568 | .c = 22, | 568 | .c = 22, |
| ... | @@ -594,7 +594,7 @@ test "C ABI structs of floats as parameter" { | ... | @@ -594,7 +594,7 @@ test "C ABI structs of floats as parameter" { |
| 594 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 594 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 595 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; | 595 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 596 | 596 | ||
| 597 | var v3 = Vector3{ | 597 | const v3 = Vector3{ |
| 598 | .x = 3.0, | 598 | .x = 3.0, |
| 599 | .y = 6.0, | 599 | .y = 6.0, |
| 600 | .z = 12.0, | 600 | .z = 12.0, |
| ... | @@ -602,7 +602,7 @@ test "C ABI structs of floats as parameter" { | ... | @@ -602,7 +602,7 @@ test "C ABI structs of floats as parameter" { |
| 602 | c_small_struct_floats(v3); | 602 | c_small_struct_floats(v3); |
| 603 | c_small_struct_floats_extra(v3, "hello"); | 603 | c_small_struct_floats_extra(v3, "hello"); |
| 604 | 604 | ||
| 605 | var v5 = Vector5{ | 605 | const v5 = Vector5{ |
| 606 | .x = 76.0, | 606 | .x = 76.0, |
| 607 | .y = -1.0, | 607 | .y = -1.0, |
| 608 | .z = -12.0, | 608 | .z = -12.0, |
| ... | @@ -634,13 +634,13 @@ test "C ABI structs of ints as multiple parameters" { | ... | @@ -634,13 +634,13 @@ test "C ABI structs of ints as multiple parameters" { |
| 634 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 634 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 635 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; | 635 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 636 | 636 | ||
| 637 | var r1 = Rect{ | 637 | const r1 = Rect{ |
| 638 | .left = 1, | 638 | .left = 1, |
| 639 | .right = 21, | 639 | .right = 21, |
| 640 | .top = 16, | 640 | .top = 16, |
| 641 | .bottom = 4, | 641 | .bottom = 4, |
| 642 | }; | 642 | }; |
| 643 | var r2 = Rect{ | 643 | const r2 = Rect{ |
| 644 | .left = 178, | 644 | .left = 178, |
| 645 | .right = 189, | 645 | .right = 189, |
| 646 | .top = 21, | 646 | .top = 21, |
| ... | @@ -671,13 +671,13 @@ test "C ABI structs of floats as multiple parameters" { | ... | @@ -671,13 +671,13 @@ test "C ABI structs of floats as multiple parameters" { |
| 671 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; | 671 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; |
| 672 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 672 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 673 | 673 | ||
| 674 | var r1 = FloatRect{ | 674 | const r1 = FloatRect{ |
| 675 | .left = 1, | 675 | .left = 1, |
| 676 | .right = 21, | 676 | .right = 21, |
| 677 | .top = 16, | 677 | .top = 16, |
| 678 | .bottom = 4, | 678 | .bottom = 4, |
| 679 | }; | 679 | }; |
| 680 | var r2 = FloatRect{ | 680 | const r2 = FloatRect{ |
| 681 | .left = 178, | 681 | .left = 178, |
| 682 | .right = 189, | 682 | .right = 189, |
| 683 | .top = 21, | 683 | .top = 21, |
| ... | @@ -787,7 +787,7 @@ test "Struct with array as padding." { | ... | @@ -787,7 +787,7 @@ test "Struct with array as padding." { |
| 787 | 787 | ||
| 788 | c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 }); | 788 | c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 }); |
| 789 | 789 | ||
| 790 | var x = c_ret_struct_with_array(); | 790 | const x = c_ret_struct_with_array(); |
| 791 | try expect(x.a == 4); | 791 | try expect(x.a == 4); |
| 792 | try expect(x.b == 155); | 792 | try expect(x.b == 155); |
| 793 | } | 793 | } |
| ... | @@ -822,7 +822,7 @@ test "Float array like struct" { | ... | @@ -822,7 +822,7 @@ test "Float array like struct" { |
| 822 | }, | 822 | }, |
| 823 | }); | 823 | }); |
| 824 | 824 | ||
| 825 | var x = c_ret_float_array_struct(); | 825 | const x = c_ret_float_array_struct(); |
| 826 | try expect(x.origin.x == 1); | 826 | try expect(x.origin.x == 1); |
| 827 | try expect(x.origin.y == 2); | 827 | try expect(x.origin.y == 2); |
| 828 | try expect(x.size.width == 3); | 828 | try expect(x.size.width == 3); |
| ... | @@ -840,7 +840,7 @@ test "small simd vector" { | ... | @@ -840,7 +840,7 @@ test "small simd vector" { |
| 840 | 840 | ||
| 841 | c_small_vec(.{ 1, 2 }); | 841 | c_small_vec(.{ 1, 2 }); |
| 842 | 842 | ||
| 843 | var x = c_ret_small_vec(); | 843 | const x = c_ret_small_vec(); |
| 844 | try expect(x[0] == 3); | 844 | try expect(x[0] == 3); |
| 845 | try expect(x[1] == 4); | 845 | try expect(x[1] == 4); |
| 846 | } | 846 | } |
| ... | @@ -858,7 +858,7 @@ test "medium simd vector" { | ... | @@ -858,7 +858,7 @@ test "medium simd vector" { |
| 858 | 858 | ||
| 859 | c_medium_vec(.{ 1, 2, 3, 4 }); | 859 | c_medium_vec(.{ 1, 2, 3, 4 }); |
| 860 | 860 | ||
| 861 | var x = c_ret_medium_vec(); | 861 | const x = c_ret_medium_vec(); |
| 862 | try expect(x[0] == 5); | 862 | try expect(x[0] == 5); |
| 863 | try expect(x[1] == 6); | 863 | try expect(x[1] == 6); |
| 864 | try expect(x[2] == 7); | 864 | try expect(x[2] == 7); |
| ... | @@ -879,7 +879,7 @@ test "big simd vector" { | ... | @@ -879,7 +879,7 @@ test "big simd vector" { |
| 879 | 879 | ||
| 880 | c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 }); | 880 | c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 }); |
| 881 | 881 | ||
| 882 | var x = c_ret_big_vec(); | 882 | const x = c_ret_big_vec(); |
| 883 | try expect(x[0] == 9); | 883 | try expect(x[0] == 9); |
| 884 | try expect(x[1] == 10); | 884 | try expect(x[1] == 10); |
| 885 | try expect(x[2] == 11); | 885 | try expect(x[2] == 11); |
| ... | @@ -903,7 +903,7 @@ test "C ABI pointer sized float struct" { | ... | @@ -903,7 +903,7 @@ test "C ABI pointer sized float struct" { |
| 903 | 903 | ||
| 904 | c_ptr_size_float_struct(.{ .x = 1, .y = 2 }); | 904 | c_ptr_size_float_struct(.{ .x = 1, .y = 2 }); |
| 905 | 905 | ||
| 906 | var x = c_ret_ptr_size_float_struct(); | 906 | const x = c_ret_ptr_size_float_struct(); |
| 907 | try expect(x.x == 3); | 907 | try expect(x.x == 3); |
| 908 | try expect(x.y == 4); | 908 | try expect(x.y == 4); |
| 909 | } | 909 | } |
| ... | @@ -1102,6 +1102,7 @@ test "C function that takes byval struct called via function pointer" { | ... | @@ -1102,6 +1102,7 @@ test "C function that takes byval struct called via function pointer" { |
| 1102 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 1102 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 1103 | 1103 | ||
| 1104 | var fn_ptr = &c_func_ptr_byval; | 1104 | var fn_ptr = &c_func_ptr_byval; |
| 1105 | _ = &fn_ptr; | ||
| 1105 | fn_ptr( | 1106 | fn_ptr( |
| 1106 | @as(*anyopaque, @ptrFromInt(1)), | 1107 | @as(*anyopaque, @ptrFromInt(1)), |
| 1107 | @as(*anyopaque, @ptrFromInt(2)), | 1108 | @as(*anyopaque, @ptrFromInt(2)), |
| ... | @@ -1224,7 +1225,7 @@ extern fn stdcall_big_union(BigUnion) callconv(stdcall_callconv) void; | ... | @@ -1224,7 +1225,7 @@ extern fn stdcall_big_union(BigUnion) callconv(stdcall_callconv) void; |
| 1224 | test "Stdcall ABI big union" { | 1225 | test "Stdcall ABI big union" { |
| 1225 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; | 1226 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 1226 | 1227 | ||
| 1227 | var x = BigUnion{ | 1228 | const x = BigUnion{ |
| 1228 | .a = BigStruct{ | 1229 | .a = BigStruct{ |
| 1229 | .a = 1, | 1230 | .a = 1, |
| 1230 | .b = 2, | 1231 | .b = 2, |
test/cases/adding_numbers_at_runtime_and_comptime.2.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var x: usize = 3; | 2 | var x: usize = 3; |
| 3 | _ = &x; | ||
| 3 | const y = add(1, 2, x); | 4 | const y = add(1, 2, x); |
| 4 | if (y - 6 != 0) unreachable; | 5 | if (y - 6 != 0) unreachable; |
| 5 | } | 6 | } |
test/cases/array_in_anon_struct.zig+1| ... | @@ -2,6 +2,7 @@ const std = @import("std"); | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | ||
| 3 | noinline fn outer() u32 { | 3 | noinline fn outer() u32 { |
| 4 | var a: u32 = 42; | 4 | var a: u32 = 42; |
| 5 | _ = &a; | ||
| 5 | return inner(.{ | 6 | return inner(.{ |
| 6 | .unused = a, | 7 | .unused = a, |
| 7 | .value = [1]u32{0}, | 8 | .value = [1]u32{0}, |
test/cases/assert_function.17.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: u64 = 0xFFEEDDCCBBAA9988; | 2 | var i: u64 = 0xFFEEDDCCBBAA9988; |
| 3 | _ = &i; | ||
| 3 | assert(i == 0xFFEEDDCCBBAA9988); | 4 | assert(i == 0xFFEEDDCCBBAA9988); |
| 4 | } | 5 | } |
| 5 | 6 |
test/cases/bad_inferred_variable_type.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var x = null; | 2 | var x = null; |
| 3 | _ = x; | 3 | _ = &x; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| 6 | // error | 6 | // error |
test/cases/binary_operands.1.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: i32 = 2147483647; | 2 | var i: i32 = 2147483647; |
| 3 | _ = &i; | ||
| 3 | if (i +% 1 != -2147483648) unreachable; | 4 | if (i +% 1 != -2147483648) unreachable; |
| 4 | return; | 5 | return; |
| 5 | } | 6 | } |
test/cases/binary_operands.10.zig+1| ... | @@ -2,6 +2,7 @@ pub fn main() void { | ... | @@ -2,6 +2,7 @@ pub fn main() void { |
| 2 | var i: u32 = 5; | 2 | var i: u32 = 5; |
| 3 | i *= 7; | 3 | i *= 7; |
| 4 | var result: u32 = foo(i, 10); | 4 | var result: u32 = foo(i, 10); |
| 5 | _ = &result; | ||
| 5 | if (result != 350) unreachable; | 6 | if (result != 350) unreachable; |
| 6 | return; | 7 | return; |
| 7 | } | 8 | } |
test/cases/binary_operands.11.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: i32 = 2147483647; | 2 | var i: i32 = 2147483647; |
| 3 | _ = &i; | ||
| 3 | const result = i *% 2; | 4 | const result = i *% 2; |
| 4 | if (result != -2) unreachable; | 5 | if (result != -2) unreachable; |
| 5 | return; | 6 | return; |
test/cases/binary_operands.12.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: u3 = 3; | 2 | var i: u3 = 3; |
| 3 | _ = &i; | ||
| 3 | if (i *% 3 != 1) unreachable; | 4 | if (i *% 3 != 1) unreachable; |
| 4 | return; | 5 | return; |
| 5 | } | 6 | } |
test/cases/binary_operands.13.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: i4 = 3; | 2 | var i: i4 = 3; |
| 3 | _ = &i; | ||
| 3 | if (i *% 3 != -7) unreachable; | 4 | if (i *% 3 != -7) unreachable; |
| 4 | return; | 5 | return; |
| 5 | } | 6 | } |
test/cases/binary_operands.14.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: u32 = 352; | 2 | var i: u32 = 352; |
| 3 | i /= 7; // i = 50 | 3 | i /= 7; // i = 50 |
| 4 | var result: u32 = foo(i, 7); | 4 | const result: u32 = foo(i, 7); |
| 5 | if (result != 7) unreachable; | 5 | if (result != 7) unreachable; |
| 6 | return; | 6 | return; |
| 7 | } | 7 | } |
test/cases/binary_operands.2.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: i4 = 7; | 2 | var i: i4 = 7; |
| 3 | _ = &i; | ||
| 3 | if (i +% 1 != -8) unreachable; | 4 | if (i +% 1 != -8) unreachable; |
| 4 | return; | 5 | return; |
| 5 | } | 6 | } |
test/cases/binary_operands.3.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var i: u8 = 255; | 2 | var i: u8 = 255; |
| 3 | _ = &i; | ||
| 3 | return i +% 1; | 4 | return i +% 1; |
| 4 | } | 5 | } |
| 5 | 6 |
test/cases/binary_operands.4.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var i: u8 = 5; | 2 | var i: u8 = 5; |
| 3 | i += 20; | 3 | i += 20; |
| 4 | var result: u8 = foo(i, 10); | 4 | const result: u8 = foo(i, 10); |
| 5 | return result - 35; | 5 | return result - 35; |
| 6 | } | 6 | } |
| 7 | fn foo(x: u8, y: u8) u8 { | 7 | fn foo(x: u8, y: u8) u8 { |
test/cases/binary_operands.6.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: i32 = -2147483648; | 2 | var i: i32 = -2147483648; |
| 3 | _ = &i; | ||
| 3 | if (i -% 1 != 2147483647) unreachable; | 4 | if (i -% 1 != 2147483647) unreachable; |
| 4 | return; | 5 | return; |
| 5 | } | 6 | } |
test/cases/binary_operands.7.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: i7 = -64; | 2 | var i: i7 = -64; |
| 3 | _ = &i; | ||
| 3 | if (i -% 1 != 63) unreachable; | 4 | if (i -% 1 != 63) unreachable; |
| 4 | return; | 5 | return; |
| 5 | } | 6 | } |
test/cases/binary_operands.8.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: u4 = 0; | 2 | var i: u4 = 0; |
| 3 | _ = &i; | ||
| 3 | if (i -% 1 != 15) unreachable; | 4 | if (i -% 1 != 15) unreachable; |
| 4 | } | 5 | } |
| 5 | 6 |
test/cases/binary_operands.9.zig+1| ... | @@ -2,6 +2,7 @@ pub fn main() u8 { | ... | @@ -2,6 +2,7 @@ pub fn main() u8 { |
| 2 | var i: u8 = 5; | 2 | var i: u8 = 5; |
| 3 | i -= 3; | 3 | i -= 3; |
| 4 | var result: u8 = foo(i, 10); | 4 | var result: u8 = foo(i, 10); |
| 5 | _ = &result; | ||
| 5 | return result - 8; | 6 | return result - 8; |
| 6 | } | 7 | } |
| 7 | fn foo(x: u8, y: u8) u8 { | 8 | fn foo(x: u8, y: u8) u8 { |
test/cases/comparison_of_non-tagged_union_and_enum_literal.zig+2-1| ... | @@ -2,7 +2,8 @@ export fn entry() void { | ... | @@ -2,7 +2,8 @@ export fn entry() void { |
| 2 | const U = union { A: u32, B: u64 }; | 2 | const U = union { A: u32, B: u64 }; |
| 3 | var u = U{ .A = 42 }; | 3 | var u = U{ .A = 42 }; |
| 4 | var ok = u == .A; | 4 | var ok = u == .A; |
| 5 | _ = ok; | 5 | _ = &u; |
| 6 | _ = &ok; | ||
| 6 | } | 7 | } |
| 7 | 8 | ||
| 8 | // error | 9 | // error |
test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig+1-1| ... | @@ -6,7 +6,7 @@ const S2 = struct { | ... | @@ -6,7 +6,7 @@ const S2 = struct { |
| 6 | }; | 6 | }; |
| 7 | pub export fn entry() void { | 7 | pub export fn entry() void { |
| 8 | var s: S1 = undefined; | 8 | var s: S1 = undefined; |
| 9 | _ = s; | 9 | _ = &s; |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | // error | 12 | // error |
test/cases/compile_errors/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const Foo = struct { a: u32 }; | 1 | const Foo = struct { a: u32 }; |
| 2 | export fn a() void { | 2 | export fn a() void { |
| 3 | const T = [*c]Foo; | 3 | const T = [*c]Foo; |
| 4 | var t: T = undefined; | 4 | const t: T = undefined; |
| 5 | _ = t; | 5 | _ = t; |
| 6 | } | 6 | } |
| 7 | 7 |
test/cases/compile_errors/C_pointer_to_anyopaque.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | export fn a() void { | 1 | export fn a() void { |
| 2 | var x: *anyopaque = undefined; | 2 | var x: *anyopaque = undefined; |
| 3 | var y: [*c]anyopaque = x; | 3 | var y: [*c]anyopaque = x; |
| 4 | _ = y; | 4 | _ = .{ &x, &y }; |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
test/cases/compile_errors/accessing_runtime_parameter_from_outer_function.zig+2-2| ... | @@ -7,8 +7,8 @@ fn outer(y: u32) *const fn (u32) u32 { | ... | @@ -7,8 +7,8 @@ fn outer(y: u32) *const fn (u32) u32 { |
| 7 | return st.get; | 7 | return st.get; |
| 8 | } | 8 | } |
| 9 | export fn entry() void { | 9 | export fn entry() void { |
| 10 | var func = outer(10); | 10 | const func = outer(10); |
| 11 | var x = func(3); | 11 | const x = func(3); |
| 12 | _ = x; | 12 | _ = x; |
| 13 | } | 13 | } |
| 14 | 14 |
test/cases/compile_errors/add_on_undefined_value.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: i64 = undefined; | 2 | const a: i64 = undefined; |
| 3 | _ = a + a; | 3 | _ = a + a; |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/alignment_of_enum_field_specified.zig+1-1| ... | @@ -6,7 +6,7 @@ const Number = enum { | ... | @@ -6,7 +6,7 @@ const Number = enum { |
| 6 | // zig fmt: on | 6 | // zig fmt: on |
| 7 | 7 | ||
| 8 | export fn entry1() void { | 8 | export fn entry1() void { |
| 9 | var x: Number = undefined; | 9 | const x: Number = undefined; |
| 10 | _ = x; | 10 | _ = x; |
| 11 | } | 11 | } |
| 12 | 12 |
test/cases/compile_errors/ambiguous_coercion_of_division_operands.zig+6-6| ... | @@ -1,17 +1,17 @@ | ... | @@ -1,17 +1,17 @@ |
| 1 | export fn entry1() void { | 1 | export fn entry1() void { |
| 2 | var f: f32 = 54.0 / 5; | 2 | const f: f32 = 54.0 / 5; |
| 3 | _ = f; | 3 | _ = f; |
| 4 | } | 4 | } |
| 5 | export fn entry2() void { | 5 | export fn entry2() void { |
| 6 | var f: f32 = 54 / 5.0; | 6 | const f: f32 = 54 / 5.0; |
| 7 | _ = f; | 7 | _ = f; |
| 8 | } | 8 | } |
| 9 | export fn entry3() void { | 9 | export fn entry3() void { |
| 10 | var f: f32 = 55.0 / 5; | 10 | const f: f32 = 55.0 / 5; |
| 11 | _ = f; | 11 | _ = f; |
| 12 | } | 12 | } |
| 13 | export fn entry4() void { | 13 | export fn entry4() void { |
| 14 | var f: f32 = 55 / 5.0; | 14 | const f: f32 = 55 / 5.0; |
| 15 | _ = f; | 15 | _ = f; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| ... | @@ -19,5 +19,5 @@ export fn entry4() void { | ... | @@ -19,5 +19,5 @@ export fn entry4() void { |
| 19 | // backend=stage2 | 19 | // backend=stage2 |
| 20 | // target=native | 20 | // target=native |
| 21 | // | 21 | // |
| 22 | // :2:23: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4' | 22 | // :2:25: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4' |
| 23 | // :6:21: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4' | 23 | // :6:23: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4' |
test/cases/compile_errors/and_on_undefined_value.zig+2-1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: bool = undefined; | 2 | var a: bool = undefined; |
| 3 | _ = &a; | ||
| 3 | _ = a and a; | 4 | _ = a and a; |
| 4 | } | 5 | } |
| 5 | 6 | ||
| ... | @@ -7,4 +8,4 @@ comptime { | ... | @@ -7,4 +8,4 @@ comptime { |
| 7 | // backend=stage2 | 8 | // backend=stage2 |
| 8 | // target=native | 9 | // target=native |
| 9 | // | 10 | // |
| 10 | // :3:9: error: use of undefined value here causes undefined behavior | 11 | // :4:9: error: use of undefined value here causes undefined behavior |
test/cases/compile_errors/array_access_of_non_array.zig+1-1| ... | @@ -3,7 +3,7 @@ export fn f() void { | ... | @@ -3,7 +3,7 @@ export fn f() void { |
| 3 | bad[0] = bad[0]; | 3 | bad[0] = bad[0]; |
| 4 | } | 4 | } |
| 5 | export fn g() void { | 5 | export fn g() void { |
| 6 | var bad: bool = undefined; | 6 | const bad: bool = undefined; |
| 7 | _ = bad[0]; | 7 | _ = bad[0]; |
| 8 | } | 8 | } |
| 9 | 9 |
test/cases/compile_errors/array_access_of_type.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var b: u8[40] = undefined; | 2 | var b: u8[40] = undefined; |
| 3 | _ = b; | 3 | _ = &b; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| 6 | // error | 6 | // error |
test/cases/compile_errors/array_access_with_non_integer_index.zig+3-1| ... | @@ -2,11 +2,13 @@ export fn f() void { | ... | @@ -2,11 +2,13 @@ export fn f() void { |
| 2 | var array = "aoeu"; | 2 | var array = "aoeu"; |
| 3 | var bad = false; | 3 | var bad = false; |
| 4 | array[bad] = array[bad]; | 4 | array[bad] = array[bad]; |
| 5 | _ = &bad; | ||
| 5 | } | 6 | } |
| 6 | export fn g() void { | 7 | export fn g() void { |
| 7 | var array = "aoeu"; | 8 | var array = "aoeu"; |
| 8 | var bad = false; | 9 | var bad = false; |
| 9 | _ = array[bad]; | 10 | _ = array[bad]; |
| 11 | _ = .{ &array, &bad }; | ||
| 10 | } | 12 | } |
| 11 | 13 | ||
| 12 | // error | 14 | // error |
| ... | @@ -14,4 +16,4 @@ export fn g() void { | ... | @@ -14,4 +16,4 @@ export fn g() void { |
| 14 | // target=native | 16 | // target=native |
| 15 | // | 17 | // |
| 16 | // :4:11: error: expected type 'usize', found 'bool' | 18 | // :4:11: error: expected type 'usize', found 'bool' |
| 17 | // :9:15: error: expected type 'usize', found 'bool' | 19 | // :10:15: error: expected type 'usize', found 'bool' |
test/cases/compile_errors/array_init_invalid_elem_count.zig+6-6| ... | @@ -2,27 +2,27 @@ const V = @Vector(8, u8); | ... | @@ -2,27 +2,27 @@ const V = @Vector(8, u8); |
| 2 | const A = [8]u8; | 2 | const A = [8]u8; |
| 3 | comptime { | 3 | comptime { |
| 4 | var v: V = V{1}; | 4 | var v: V = V{1}; |
| 5 | _ = v; | 5 | _ = &v; |
| 6 | } | 6 | } |
| 7 | comptime { | 7 | comptime { |
| 8 | var v: V = V{}; | 8 | var v: V = V{}; |
| 9 | _ = v; | 9 | _ = &v; |
| 10 | } | 10 | } |
| 11 | comptime { | 11 | comptime { |
| 12 | var a: A = A{1}; | 12 | var a: A = A{1}; |
| 13 | _ = a; | 13 | _ = &a; |
| 14 | } | 14 | } |
| 15 | comptime { | 15 | comptime { |
| 16 | var a: A = A{}; | 16 | var a: A = A{}; |
| 17 | _ = a; | 17 | _ = &a; |
| 18 | } | 18 | } |
| 19 | pub export fn entry1() void { | 19 | pub export fn entry1() void { |
| 20 | var bla: V = .{ 1, 2, 3, 4 }; | 20 | var bla: V = .{ 1, 2, 3, 4 }; |
| 21 | _ = bla; | 21 | _ = &bla; |
| 22 | } | 22 | } |
| 23 | pub export fn entry2() void { | 23 | pub export fn entry2() void { |
| 24 | var bla: A = .{ 1, 2, 3, 4 }; | 24 | var bla: A = .{ 1, 2, 3, 4 }; |
| 25 | _ = bla; | 25 | _ = &bla; |
| 26 | } | 26 | } |
| 27 | const S = struct { | 27 | const S = struct { |
| 28 | list: [2]u8 = .{0}, | 28 | list: [2]u8 = .{0}, |
test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var a = &b; | 2 | var a = &b; |
| 3 | _ = a; | 3 | _ = &a; |
| 4 | } | 4 | } |
| 5 | inline fn b() void {} | 5 | inline fn b() void {} |
| 6 | 6 |
test/cases/compile_errors/assign_local_bad_coercion.zig+1-1| ... | @@ -9,7 +9,7 @@ export fn constEntry() u32 { | ... | @@ -9,7 +9,7 @@ export fn constEntry() u32 { |
| 9 | 9 | ||
| 10 | export fn varEntry() u32 { | 10 | export fn varEntry() u32 { |
| 11 | var x: u32 = g(); | 11 | var x: u32 = g(); |
| 12 | return x; | 12 | return (&x).*; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | // error | 15 | // error |
test/cases/compile_errors/assign_too_big_number_to_u16.zig+2-2| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var vga_mem: u16 = 0xB8000; | 2 | const vga_mem: u16 = 0xB8000; |
| 3 | _ = vga_mem; | 3 | _ = vga_mem; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| ... | @@ -7,4 +7,4 @@ export fn foo() void { | ... | @@ -7,4 +7,4 @@ export fn foo() void { |
| 7 | // backend=stage2 | 7 | // backend=stage2 |
| 8 | // target=native | 8 | // target=native |
| 9 | // | 9 | // |
| 10 | // :2:24: error: type 'u16' cannot represent integer value '753664' | 10 | // :2:26: error: type 'u16' cannot represent integer value '753664' |
test/cases/compile_errors/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig+2-2| ... | @@ -10,8 +10,8 @@ const S = struct { | ... | @@ -10,8 +10,8 @@ const S = struct { |
| 10 | export fn entry() void { | 10 | export fn entry() void { |
| 11 | var u = U{ .Ye = maybe(false) }; | 11 | var u = U{ .Ye = maybe(false) }; |
| 12 | var s = S{ .num = maybe(false) }; | 12 | var s = S{ .num = maybe(false) }; |
| 13 | _ = u; | 13 | _ = &u; |
| 14 | _ = s; | 14 | _ = &s; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | // error | 17 | // error |
test/cases/compile_errors/async/Frame_of_generic_function.zig+2-2| ... | @@ -1,10 +1,10 @@ | ... | @@ -1,10 +1,10 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var frame: @Frame(func) = undefined; | 2 | var frame: @Frame(func) = undefined; |
| 3 | _ = frame; | 3 | _ = &frame; |
| 4 | } | 4 | } |
| 5 | fn func(comptime T: type) void { | 5 | fn func(comptime T: type) void { |
| 6 | var x: T = undefined; | 6 | var x: T = undefined; |
| 7 | _ = x; | 7 | _ = &x; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | // error | 10 | // error |
test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig+1-1| ... | @@ -3,7 +3,7 @@ export fn entry() void { | ... | @@ -3,7 +3,7 @@ export fn entry() void { |
| 3 | } | 3 | } |
| 4 | fn amain() callconv(.Async) void { | 4 | fn amain() callconv(.Async) void { |
| 5 | var x: [@sizeOf(@Frame(amain))]u8 = undefined; | 5 | var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 6 | _ = x; | 6 | _ = &x; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | // error | 9 | // error |
test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig+1-1| ... | @@ -6,7 +6,7 @@ fn amain() callconv(.Async) void { | ... | @@ -6,7 +6,7 @@ fn amain() callconv(.Async) void { |
| 6 | } | 6 | } |
| 7 | fn other() void { | 7 | fn other() void { |
| 8 | var x: [@sizeOf(@Frame(amain))]u8 = undefined; | 8 | var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 9 | _ = x; | 9 | _ = &x; |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | // error | 12 | // error |
test/cases/compile_errors/async/bad_alignment_in_asynccall.zig+1| ... | @@ -2,6 +2,7 @@ export fn entry() void { | ... | @@ -2,6 +2,7 @@ export fn entry() void { |
| 2 | var ptr: fn () callconv(.Async) void = func; | 2 | var ptr: fn () callconv(.Async) void = func; |
| 3 | var bytes: [64]u8 = undefined; | 3 | var bytes: [64]u8 = undefined; |
| 4 | _ = @asyncCall(&bytes, {}, ptr, .{}); | 4 | _ = @asyncCall(&bytes, {}, ptr, .{}); |
| 5 | _ = &ptr; | ||
| 5 | } | 6 | } |
| 6 | fn func() callconv(.Async) void {} | 7 | fn func() callconv(.Async) void {} |
| 7 | 8 |
test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig+1-1| ... | @@ -5,7 +5,7 @@ export fn a() void { | ... | @@ -5,7 +5,7 @@ export fn a() void { |
| 5 | export fn b() void { | 5 | export fn b() void { |
| 6 | const f = async func(); | 6 | const f = async func(); |
| 7 | var x: anyframe = &f; | 7 | var x: anyframe = &f; |
| 8 | _ = x; | 8 | _ = &x; |
| 9 | } | 9 | } |
| 10 | fn func() void { | 10 | fn func() void { |
| 11 | suspend {} | 11 | suspend {} |
test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig+4-4| ... | @@ -12,7 +12,7 @@ fn rangeSum(x: i32) i32 { | ... | @@ -12,7 +12,7 @@ fn rangeSum(x: i32) i32 { |
| 12 | frame = null; | 12 | frame = null; |
| 13 | 13 | ||
| 14 | if (x == 0) return 0; | 14 | if (x == 0) return 0; |
| 15 | var child = rangeSumIndirect(x - 1); | 15 | const child = rangeSumIndirect(x - 1); |
| 16 | return child + 1; | 16 | return child + 1; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| ... | @@ -23,7 +23,7 @@ fn rangeSumIndirect(x: i32) i32 { | ... | @@ -23,7 +23,7 @@ fn rangeSumIndirect(x: i32) i32 { |
| 23 | frame = null; | 23 | frame = null; |
| 24 | 24 | ||
| 25 | if (x == 0) return 0; | 25 | if (x == 0) return 0; |
| 26 | var child = rangeSum(x - 1); | 26 | const child = rangeSum(x - 1); |
| 27 | return child + 1; | 27 | return child + 1; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| ... | @@ -32,5 +32,5 @@ fn rangeSumIndirect(x: i32) i32 { | ... | @@ -32,5 +32,5 @@ fn rangeSumIndirect(x: i32) i32 { |
| 32 | // target=native | 32 | // target=native |
| 33 | // | 33 | // |
| 34 | // tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself | 34 | // tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself |
| 35 | // tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here | 35 | // tmp.zig:15:35: note: when analyzing type '@Frame(rangeSum)' here |
| 36 | // tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here | 36 | // tmp.zig:28:25: note: when analyzing type '@Frame(rangeSumIndirect)' here |
test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var frame = async func(); | 2 | var frame = async func(); |
| 3 | var result = await frame; | 3 | var result = await frame; |
| 4 | _ = result; | 4 | _ = &result; |
| 5 | } | 5 | } |
| 6 | fn func() void { | 6 | fn func() void { |
| 7 | suspend {} | 7 | suspend {} |
test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig+1| ... | @@ -2,6 +2,7 @@ export fn entry() void { | ... | @@ -2,6 +2,7 @@ export fn entry() void { |
| 2 | var ptr = afunc; | 2 | var ptr = afunc; |
| 3 | var bytes: [100]u8 align(16) = undefined; | 3 | var bytes: [100]u8 align(16) = undefined; |
| 4 | _ = @asyncCall(&bytes, {}, ptr, .{}); | 4 | _ = @asyncCall(&bytes, {}, ptr, .{}); |
| 5 | _ = &ptr; | ||
| 5 | } | 6 | } |
| 6 | fn afunc() void {} | 7 | fn afunc() void {} |
| 7 | 8 |
test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig+3-3| ... | @@ -1,17 +1,17 @@ | ... | @@ -1,17 +1,17 @@ |
| 1 | export fn a() void { | 1 | export fn a() void { |
| 2 | var x: anyframe = undefined; | 2 | var x: anyframe = undefined; |
| 3 | var y: anyframe->i32 = x; | 3 | var y: anyframe->i32 = x; |
| 4 | _ = y; | 4 | _ = .{ &x, &y }; |
| 5 | } | 5 | } |
| 6 | export fn b() void { | 6 | export fn b() void { |
| 7 | var x: i32 = undefined; | 7 | var x: i32 = undefined; |
| 8 | var y: anyframe->i32 = x; | 8 | var y: anyframe->i32 = x; |
| 9 | _ = y; | 9 | _ = .{ &x, &y }; |
| 10 | } | 10 | } |
| 11 | export fn c() void { | 11 | export fn c() void { |
| 12 | var x: @Frame(func) = undefined; | 12 | var x: @Frame(func) = undefined; |
| 13 | var y: anyframe->i32 = &x; | 13 | var y: anyframe->i32 = &x; |
| 14 | _ = y; | 14 | _ = .{ &x, &y }; |
| 15 | } | 15 | } |
| 16 | fn func() void {} | 16 | fn func() void {} |
| 17 | 17 |
test/cases/compile_errors/async/runtime-known_async_function_called.zig+1| ... | @@ -4,6 +4,7 @@ export fn entry() void { | ... | @@ -4,6 +4,7 @@ export fn entry() void { |
| 4 | fn amain() void { | 4 | fn amain() void { |
| 5 | var ptr = afunc; | 5 | var ptr = afunc; |
| 6 | _ = ptr(); | 6 | _ = ptr(); |
| 7 | _ = &ptr; | ||
| 7 | } | 8 | } |
| 8 | fn afunc() callconv(.Async) void {} | 9 | fn afunc() callconv(.Async) void {} |
| 9 | 10 |
test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var ptr = afunc; | 2 | var ptr = afunc; |
| 3 | _ = async ptr(); | 3 | _ = async ptr(); |
| 4 | _ = &ptr; | ||
| 4 | } | 5 | } |
| 5 | 6 | ||
| 6 | fn afunc() callconv(.Async) void {} | 7 | fn afunc() callconv(.Async) void {} |
test/cases/compile_errors/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig+2-2| ... | @@ -1,9 +1,9 @@ | ... | @@ -1,9 +1,9 @@ |
| 1 | export fn entry(byte: u8) void { | 1 | export fn entry() void { |
| 2 | const w: i32 = 1234; | 2 | const w: i32 = 1234; |
| 3 | var x: *const i32 = &w; | 3 | var x: *const i32 = &w; |
| 4 | var y: *[1]i32 = x; | 4 | var y: *[1]i32 = x; |
| 5 | y[0] += 1; | 5 | y[0] += 1; |
| 6 | _ = byte; | 6 | _ = &x; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | // error | 9 | // error |
test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig+3-3| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | export fn a() void { | 1 | export fn a() void { |
| 2 | var x: [10]u8 = undefined; | 2 | var x: [10]u8 = undefined; |
| 3 | var y: []align(16) u8 = &x; | 3 | const y: []align(16) u8 = &x; |
| 4 | _ = y; | 4 | _ = y; |
| 5 | } | 5 | } |
| 6 | 6 | ||
| ... | @@ -8,5 +8,5 @@ export fn a() void { | ... | @@ -8,5 +8,5 @@ export fn a() void { |
| 8 | // backend=stage2 | 8 | // backend=stage2 |
| 9 | // target=native | 9 | // target=native |
| 10 | // | 10 | // |
| 11 | // :3:29: error: expected type '[]align(16) u8', found '*[10]u8' | 11 | // :3:31: error: expected type '[]align(16) u8', found '*[10]u8' |
| 12 | // :3:29: note: pointer alignment '1' cannot cast into pointer alignment '16' | 12 | // :3:31: note: pointer alignment '1' cannot cast into pointer alignment '16' |
test/cases/compile_errors/bad_alignment_type.zig+4-4| ... | @@ -1,9 +1,9 @@ | ... | @@ -1,9 +1,9 @@ |
| 1 | export fn entry1() void { | 1 | export fn entry1() void { |
| 2 | var x: []align(true) i32 = undefined; | 2 | const x: []align(true) i32 = undefined; |
| 3 | _ = x; | 3 | _ = x; |
| 4 | } | 4 | } |
| 5 | export fn entry2() void { | 5 | export fn entry2() void { |
| 6 | var x: *align(@as(f64, 12.34)) i32 = undefined; | 6 | const x: *align(@as(f64, 12.34)) i32 = undefined; |
| 7 | _ = x; | 7 | _ = x; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| ... | @@ -11,5 +11,5 @@ export fn entry2() void { | ... | @@ -11,5 +11,5 @@ export fn entry2() void { |
| 11 | // backend=stage2 | 11 | // backend=stage2 |
| 12 | // target=native | 12 | // target=native |
| 13 | // | 13 | // |
| 14 | // :2:20: error: expected type 'u32', found 'bool' | 14 | // :2:22: error: expected type 'u32', found 'bool' |
| 15 | // :6:19: error: fractional component prevents float value '12.34' from coercion to type 'u32' | 15 | // :6:21: error: fractional component prevents float value '12.34' from coercion to type 'u32' |
test/cases/compile_errors/bad_usage_of_call.zig+3-2| ... | @@ -11,7 +11,7 @@ export fn entry4() void { | ... | @@ -11,7 +11,7 @@ export fn entry4() void { |
| 11 | @call(.never_inline, bar, .{}); | 11 | @call(.never_inline, bar, .{}); |
| 12 | } | 12 | } |
| 13 | export fn entry5(c: bool) void { | 13 | export fn entry5(c: bool) void { |
| 14 | var baz = if (c) &baz1 else &baz2; | 14 | const baz = if (c) &baz1 else &baz2; |
| 15 | @call(.compile_time, baz, .{}); | 15 | @call(.compile_time, baz, .{}); |
| 16 | } | 16 | } |
| 17 | export fn entry6() void { | 17 | export fn entry6() void { |
| ... | @@ -22,6 +22,7 @@ export fn entry7() void { | ... | @@ -22,6 +22,7 @@ export fn entry7() void { |
| 22 | } | 22 | } |
| 23 | pub export fn entry() void { | 23 | pub export fn entry() void { |
| 24 | var call_me: *const fn () void = undefined; | 24 | var call_me: *const fn () void = undefined; |
| 25 | _ = &call_me; | ||
| 25 | @call(.always_inline, call_me, .{}); | 26 | @call(.always_inline, call_me, .{}); |
| 26 | } | 27 | } |
| 27 | 28 | ||
| ... | @@ -45,4 +46,4 @@ noinline fn dummy2() void {} | ... | @@ -45,4 +46,4 @@ noinline fn dummy2() void {} |
| 45 | // :15:26: error: modifier 'compile_time' requires a comptime-known function | 46 | // :15:26: error: modifier 'compile_time' requires a comptime-known function |
| 46 | // :18:9: error: 'always_inline' call of noinline function | 47 | // :18:9: error: 'always_inline' call of noinline function |
| 47 | // :21:9: error: 'always_inline' call of noinline function | 48 | // :21:9: error: 'always_inline' call of noinline function |
| 48 | // :25:27: error: modifier 'always_inline' requires a comptime-known function | 49 | // :26:27: error: modifier 'always_inline' requires a comptime-known function |
test/cases/compile_errors/binary_OR_operator_on_error_sets.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | pub const A = error.A; | 1 | pub const A = error.A; |
| 2 | pub const AB = A | error.B; | 2 | pub const AB = A | error.B; |
| 3 | export fn entry() void { | 3 | export fn entry() void { |
| 4 | var x: AB = undefined; | 4 | const x: AB = undefined; |
| 5 | _ = x; | 5 | _ = x; |
| 6 | } | 6 | } |
| 7 | 7 |
test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig+2-2| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn entry(byte: u8) void { | 1 | export fn entry(byte: u8) void { |
| 2 | var oops: u7 = @bitCast(byte); | 2 | const oops: u7 = @bitCast(byte); |
| 3 | _ = oops; | 3 | _ = oops; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| ... | @@ -7,4 +7,4 @@ export fn entry(byte: u8) void { | ... | @@ -7,4 +7,4 @@ export fn entry(byte: u8) void { |
| 7 | // backend=stage2 | 7 | // backend=stage2 |
| 8 | // target=native | 8 | // target=native |
| 9 | // | 9 | // |
| 10 | // :2:20: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits | 10 | // :2:22: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits |
test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf); | 2 | const f: f32 = 1.0; |
| 3 | const foo = (@as(u8, @bitCast(f)) == 0xf); | ||
| 3 | _ = foo; | 4 | _ = foo; |
| 4 | } | 5 | } |
| 5 | 6 | ||
| ... | @@ -7,4 +8,4 @@ export fn entry() void { | ... | @@ -7,4 +8,4 @@ export fn entry() void { |
| 7 | // backend=stage2 | 8 | // backend=stage2 |
| 8 | // target=native | 9 | // target=native |
| 9 | // | 10 | // |
| 10 | // :2:24: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits | 11 | // :3:26: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits |
test/cases/compile_errors/branch_in_comptime_only_scope_uses_condbr_inline.zig+5-3| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub export fn entry1() void { | 1 | pub export fn entry1() void { |
| 2 | var x: u32 = 3; | 2 | var x: u32 = 3; |
| 3 | _ = &x; | ||
| 3 | _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{ | 4 | _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{ |
| 4 | if (x > 1) 1 else -1, | 5 | if (x > 1) 1 else -1, |
| 5 | }); | 6 | }); |
| ... | @@ -7,6 +8,7 @@ pub export fn entry1() void { | ... | @@ -7,6 +8,7 @@ pub export fn entry1() void { |
| 7 | 8 | ||
| 8 | pub export fn entry2() void { | 9 | pub export fn entry2() void { |
| 9 | var y: ?i8 = -1; | 10 | var y: ?i8 = -1; |
| 11 | _ = &y; | ||
| 10 | _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{ | 12 | _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{ |
| 11 | y orelse 1, | 13 | y orelse 1, |
| 12 | }); | 14 | }); |
| ... | @@ -16,6 +18,6 @@ pub export fn entry2() void { | ... | @@ -16,6 +18,6 @@ pub export fn entry2() void { |
| 16 | // backend=stage2 | 18 | // backend=stage2 |
| 17 | // target=native | 19 | // target=native |
| 18 | // | 20 | // |
| 19 | // :4:15: error: unable to evaluate comptime expression | 21 | // :5:15: error: unable to evaluate comptime expression |
| 20 | // :4:13: note: operation is runtime due to this operand | 22 | // :5:13: note: operation is runtime due to this operand |
| 21 | // :11:11: error: unable to evaluate comptime expression | 23 | // :13:11: error: unable to evaluate comptime expression |
test/cases/compile_errors/break_void_result_location.zig+3-2| ... | @@ -10,6 +10,7 @@ export fn f2() void { | ... | @@ -10,6 +10,7 @@ export fn f2() void { |
| 10 | } | 10 | } |
| 11 | export fn f3() void { | 11 | export fn f3() void { |
| 12 | var t: bool = true; | 12 | var t: bool = true; |
| 13 | _ = &t; | ||
| 13 | const x: usize = while (t) { | 14 | const x: usize = while (t) { |
| 14 | break; | 15 | break; |
| 15 | }; | 16 | }; |
| ... | @@ -28,5 +29,5 @@ export fn f4() void { | ... | @@ -28,5 +29,5 @@ export fn f4() void { |
| 28 | // | 29 | // |
| 29 | // :2:22: error: expected type 'usize', found 'void' | 30 | // :2:22: error: expected type 'usize', found 'void' |
| 30 | // :7:9: error: expected type 'usize', found 'void' | 31 | // :7:9: error: expected type 'usize', found 'void' |
| 31 | // :14:9: error: expected type 'usize', found 'void' | 32 | // :15:9: error: expected type 'usize', found 'void' |
| 32 | // :20:9: error: expected type 'usize', found 'void' | 33 | // :21:9: error: expected type 'usize', found 'void' |
test/cases/compile_errors/c_pointer_to_void.zig+3-3| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var a: [*c]void = undefined; | 2 | const a: [*c]void = undefined; |
| 3 | _ = a; | 3 | _ = a; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| ... | @@ -7,5 +7,5 @@ export fn entry() void { | ... | @@ -7,5 +7,5 @@ export fn entry() void { |
| 7 | // backend=stage2 | 7 | // backend=stage2 |
| 8 | // target=native | 8 | // target=native |
| 9 | // | 9 | // |
| 10 | // :2:16: error: C pointers cannot point to non-C-ABI-compatible type 'void' | 10 | // :2:18: error: C pointers cannot point to non-C-ABI-compatible type 'void' |
| 11 | // :2:16: note: 'void' is a zero bit type; for C 'void' use 'anyopaque' | 11 | // :2:18: note: 'void' is a zero bit type; for C 'void' use 'anyopaque' |
test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig+3-3| ... | @@ -2,15 +2,15 @@ const F1 = fn () callconv(.Stdcall) void; | ... | @@ -2,15 +2,15 @@ const F1 = fn () callconv(.Stdcall) void; |
| 2 | const F2 = fn () callconv(.Fastcall) void; | 2 | const F2 = fn () callconv(.Fastcall) void; |
| 3 | const F3 = fn () callconv(.Thiscall) void; | 3 | const F3 = fn () callconv(.Thiscall) void; |
| 4 | export fn entry1() void { | 4 | export fn entry1() void { |
| 5 | var a: F1 = undefined; | 5 | const a: F1 = undefined; |
| 6 | _ = a; | 6 | _ = a; |
| 7 | } | 7 | } |
| 8 | export fn entry2() void { | 8 | export fn entry2() void { |
| 9 | var a: F2 = undefined; | 9 | const a: F2 = undefined; |
| 10 | _ = a; | 10 | _ = a; |
| 11 | } | 11 | } |
| 12 | export fn entry3() void { | 12 | export fn entry3() void { |
| 13 | var a: F3 = undefined; | 13 | const a: F3 = undefined; |
| 14 | _ = a; | 14 | _ = a; |
| 15 | } | 15 | } |
| 16 | 16 |
test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig+5-3| ... | @@ -4,6 +4,7 @@ export fn entry1() void { | ... | @@ -4,6 +4,7 @@ export fn entry1() void { |
| 4 | var a: fnty1 = undefined; | 4 | var a: fnty1 = undefined; |
| 5 | var b: fnty2 = undefined; | 5 | var b: fnty2 = undefined; |
| 6 | a = b; | 6 | a = b; |
| 7 | _ = &b; | ||
| 7 | } | 8 | } |
| 8 | 9 | ||
| 9 | pub const fnty3 = ?*const fn (u63) void; | 10 | pub const fnty3 = ?*const fn (u63) void; |
| ... | @@ -11,6 +12,7 @@ export fn entry2() void { | ... | @@ -11,6 +12,7 @@ export fn entry2() void { |
| 11 | var a: fnty3 = undefined; | 12 | var a: fnty3 = undefined; |
| 12 | var b: fnty2 = undefined; | 13 | var b: fnty2 = undefined; |
| 13 | a = b; | 14 | a = b; |
| 15 | _ = &b; | ||
| 14 | } | 16 | } |
| 15 | 17 | ||
| 16 | // error | 18 | // error |
| ... | @@ -21,6 +23,6 @@ export fn entry2() void { | ... | @@ -21,6 +23,6 @@ export fn entry2() void { |
| 21 | // :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void' | 23 | // :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void' |
| 22 | // :6:9: note: parameter 0 'u64' cannot cast into 'i8' | 24 | // :6:9: note: parameter 0 'u64' cannot cast into 'i8' |
| 23 | // :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values | 25 | // :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values |
| 24 | // :13:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void' | 26 | // :14:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void' |
| 25 | // :13:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void' | 27 | // :14:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void' |
| 26 | // :13:9: note: parameter 0 'u64' cannot cast into 'u63' | 28 | // :14:9: note: parameter 0 'u64' cannot cast into 'u63' |
test/cases/compile_errors/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig+3-3| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const SmallErrorSet = error{A}; | 1 | const SmallErrorSet = error{A}; |
| 2 | export fn entry() void { | 2 | export fn entry() void { |
| 3 | var x: SmallErrorSet!i32 = foo(); | 3 | const x: SmallErrorSet!i32 = foo(); |
| 4 | _ = x; | 4 | _ = x; |
| 5 | } | 5 | } |
| 6 | fn foo() anyerror!i32 { | 6 | fn foo() anyerror!i32 { |
| ... | @@ -11,5 +11,5 @@ fn foo() anyerror!i32 { | ... | @@ -11,5 +11,5 @@ fn foo() anyerror!i32 { |
| 11 | // backend=stage2 | 11 | // backend=stage2 |
| 12 | // target=native | 12 | // target=native |
| 13 | // | 13 | // |
| 14 | // :3:35: error: expected type 'error{A}!i32', found 'anyerror!i32' | 14 | // :3:37: error: expected type 'error{A}!i32', found 'anyerror!i32' |
| 15 | // :3:35: note: global error set cannot cast into a smaller set | 15 | // :3:37: note: global error set cannot cast into a smaller set |
test/cases/compile_errors/cast_global_error_set_to_error_set.zig+3-3| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const SmallErrorSet = error{A}; | 1 | const SmallErrorSet = error{A}; |
| 2 | export fn entry() void { | 2 | export fn entry() void { |
| 3 | var x: SmallErrorSet = foo(); | 3 | const x: SmallErrorSet = foo(); |
| 4 | _ = x; | 4 | _ = x; |
| 5 | } | 5 | } |
| 6 | fn foo() anyerror { | 6 | fn foo() anyerror { |
| ... | @@ -11,5 +11,5 @@ fn foo() anyerror { | ... | @@ -11,5 +11,5 @@ fn foo() anyerror { |
| 11 | // backend=stage2 | 11 | // backend=stage2 |
| 12 | // target=native | 12 | // target=native |
| 13 | // | 13 | // |
| 14 | // :3:31: error: expected type 'error{A}', found 'anyerror' | 14 | // :3:33: error: expected type 'error{A}', found 'anyerror' |
| 15 | // :3:31: note: global error set cannot cast into a smaller set | 15 | // :3:33: note: global error set cannot cast into a smaller set |
test/cases/compile_errors/catch_on_undefined_value.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: anyerror!bool = undefined; | 2 | const a: anyerror!bool = undefined; |
| 3 | if (a catch false) {} | 3 | if (a catch false) {} |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig+2-2| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var x: ?[3]i32 = undefined; | 2 | const x: ?[3]i32 = undefined; |
| 3 | var y: [3]i32 = undefined; | 3 | const y: [3]i32 = undefined; |
| 4 | _ = (x == y); | 4 | _ = (x == y); |
| 5 | } | 5 | } |
| 6 | 6 |
test/cases/compile_errors/comparison_operators_with_undefined_value.zig+6-6| ... | @@ -1,36 +1,36 @@ | ... | @@ -1,36 +1,36 @@ |
| 1 | // operator == | 1 | // operator == |
| 2 | comptime { | 2 | comptime { |
| 3 | var a: i64 = undefined; | 3 | const a: i64 = undefined; |
| 4 | var x: i32 = 0; | 4 | var x: i32 = 0; |
| 5 | if (a == a) x += 1; | 5 | if (a == a) x += 1; |
| 6 | } | 6 | } |
| 7 | // operator != | 7 | // operator != |
| 8 | comptime { | 8 | comptime { |
| 9 | var a: i64 = undefined; | 9 | const a: i64 = undefined; |
| 10 | var x: i32 = 0; | 10 | var x: i32 = 0; |
| 11 | if (a != a) x += 1; | 11 | if (a != a) x += 1; |
| 12 | } | 12 | } |
| 13 | // operator > | 13 | // operator > |
| 14 | comptime { | 14 | comptime { |
| 15 | var a: i64 = undefined; | 15 | const a: i64 = undefined; |
| 16 | var x: i32 = 0; | 16 | var x: i32 = 0; |
| 17 | if (a > a) x += 1; | 17 | if (a > a) x += 1; |
| 18 | } | 18 | } |
| 19 | // operator < | 19 | // operator < |
| 20 | comptime { | 20 | comptime { |
| 21 | var a: i64 = undefined; | 21 | const a: i64 = undefined; |
| 22 | var x: i32 = 0; | 22 | var x: i32 = 0; |
| 23 | if (a < a) x += 1; | 23 | if (a < a) x += 1; |
| 24 | } | 24 | } |
| 25 | // operator >= | 25 | // operator >= |
| 26 | comptime { | 26 | comptime { |
| 27 | var a: i64 = undefined; | 27 | const a: i64 = undefined; |
| 28 | var x: i32 = 0; | 28 | var x: i32 = 0; |
| 29 | if (a >= a) x += 1; | 29 | if (a >= a) x += 1; |
| 30 | } | 30 | } |
| 31 | // operator <= | 31 | // operator <= |
| 32 | comptime { | 32 | comptime { |
| 33 | var a: i64 = undefined; | 33 | const a: i64 = undefined; |
| 34 | var x: i32 = 0; | 34 | var x: i32 = 0; |
| 35 | if (a <= a) x += 1; | 35 | if (a <= a) x += 1; |
| 36 | } | 36 | } |
test/cases/compile_errors/compile_error_in_struct_init_expression.zig+1-1| ... | @@ -3,7 +3,7 @@ const Foo = struct { | ... | @@ -3,7 +3,7 @@ const Foo = struct { |
| 3 | b: i32, | 3 | b: i32, |
| 4 | }; | 4 | }; |
| 5 | export fn entry() void { | 5 | export fn entry() void { |
| 6 | var x = Foo{ | 6 | const x: Foo = .{ |
| 7 | .b = 5, | 7 | .b = 5, |
| 8 | }; | 8 | }; |
| 9 | _ = x; | 9 | _ = x; |
test/cases/compile_errors/compile_time_null_ptr_cast.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var opt_ptr: ?*i32 = null; | 2 | const opt_ptr: ?*i32 = null; |
| 3 | const ptr: *i32 = @ptrCast(opt_ptr); | 3 | const ptr: *i32 = @ptrCast(opt_ptr); |
| 4 | _ = ptr; | 4 | _ = ptr; |
| 5 | } | 5 | } |
test/cases/compile_errors/compile_time_undef_ptr_cast.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var undef_ptr: *i32 = undefined; | 2 | var undef_ptr: *i32 = undefined; |
| 3 | const ptr: *i32 = @ptrCast(undef_ptr); | 3 | const ptr: *i32 = @ptrCast(undef_ptr); |
| 4 | _ = &undef_ptr; | ||
| 4 | _ = ptr; | 5 | _ = ptr; |
| 5 | } | 6 | } |
| 6 | 7 |
test/cases/compile_errors/comptime_cast_enum_to_union_but_field_has_payload.zig+1-1| ... | @@ -6,7 +6,7 @@ const Value = union(Letter) { | ... | @@ -6,7 +6,7 @@ const Value = union(Letter) { |
| 6 | }; | 6 | }; |
| 7 | export fn entry() void { | 7 | export fn entry() void { |
| 8 | var x: Value = Letter.A; | 8 | var x: Value = Letter.A; |
| 9 | _ = x; | 9 | _ = &x; |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | // error | 12 | // error |
test/cases/compile_errors/comptime_continue_inside_runtime_if_bool.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var p: usize = undefined; | 2 | var p: usize = undefined; |
| 3 | _ = &p; | ||
| 3 | comptime var q = true; | 4 | comptime var q = true; |
| 4 | inline while (q) { | 5 | inline while (q) { |
| 5 | if (p == 11) continue; | 6 | if (p == 11) continue; |
| ... | @@ -11,5 +12,5 @@ export fn entry() void { | ... | @@ -11,5 +12,5 @@ export fn entry() void { |
| 11 | // backend=stage2 | 12 | // backend=stage2 |
| 12 | // target=native | 13 | // target=native |
| 13 | // | 14 | // |
| 14 | // :5:22: error: comptime control flow inside runtime block | 15 | // :6:22: error: comptime control flow inside runtime block |
| 15 | // :5:15: note: runtime control flow here | 16 | // :6:15: note: runtime control flow here |
test/cases/compile_errors/comptime_continue_inside_runtime_if_error.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var p: anyerror!i32 = undefined; | 2 | var p: anyerror!i32 = undefined; |
| 3 | _ = &p; | ||
| 3 | comptime var q = true; | 4 | comptime var q = true; |
| 4 | inline while (q) { | 5 | inline while (q) { |
| 5 | if (p) |_| continue else |_| {} | 6 | if (p) |_| continue else |_| {} |
| ... | @@ -11,5 +12,5 @@ export fn entry() void { | ... | @@ -11,5 +12,5 @@ export fn entry() void { |
| 11 | // backend=stage2 | 12 | // backend=stage2 |
| 12 | // target=native | 13 | // target=native |
| 13 | // | 14 | // |
| 14 | // :5:20: error: comptime control flow inside runtime block | 15 | // :6:20: error: comptime control flow inside runtime block |
| 15 | // :5:13: note: runtime control flow here | 16 | // :6:13: note: runtime control flow here |
test/cases/compile_errors/comptime_continue_inside_runtime_if_optional.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var p: ?i32 = undefined; | 2 | var p: ?i32 = undefined; |
| 3 | _ = &p; | ||
| 3 | comptime var q = true; | 4 | comptime var q = true; |
| 4 | inline while (q) { | 5 | inline while (q) { |
| 5 | if (p) |_| continue; | 6 | if (p) |_| continue; |
| ... | @@ -11,5 +12,5 @@ export fn entry() void { | ... | @@ -11,5 +12,5 @@ export fn entry() void { |
| 11 | // backend=stage2 | 12 | // backend=stage2 |
| 12 | // target=native | 13 | // target=native |
| 13 | // | 14 | // |
| 14 | // :5:20: error: comptime control flow inside runtime block | 15 | // :6:20: error: comptime control flow inside runtime block |
| 15 | // :5:13: note: runtime control flow here | 16 | // :6:13: note: runtime control flow here |
test/cases/compile_errors/comptime_continue_inside_runtime_switch.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var p: i32 = undefined; | 2 | var p: i32 = undefined; |
| 3 | _ = &p; | ||
| 3 | comptime var q = true; | 4 | comptime var q = true; |
| 4 | inline while (q) { | 5 | inline while (q) { |
| 5 | switch (p) { | 6 | switch (p) { |
| ... | @@ -14,5 +15,5 @@ export fn entry() void { | ... | @@ -14,5 +15,5 @@ export fn entry() void { |
| 14 | // backend=stage2 | 15 | // backend=stage2 |
| 15 | // target=native | 16 | // target=native |
| 16 | // | 17 | // |
| 17 | // :6:19: error: comptime control flow inside runtime block | 18 | // :7:19: error: comptime control flow inside runtime block |
| 18 | // :5:17: note: runtime control flow here | 19 | // :6:17: note: runtime control flow here |
test/cases/compile_errors/comptime_continue_inside_runtime_while_bool.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var p: usize = undefined; | 2 | var p: usize = undefined; |
| 3 | _ = &p; | ||
| 3 | comptime var q = true; | 4 | comptime var q = true; |
| 4 | outer: inline while (q) { | 5 | outer: inline while (q) { |
| 5 | while (p == 11) continue :outer; | 6 | while (p == 11) continue :outer; |
| ... | @@ -11,5 +12,5 @@ export fn entry() void { | ... | @@ -11,5 +12,5 @@ export fn entry() void { |
| 11 | // backend=stage2 | 12 | // backend=stage2 |
| 12 | // target=native | 13 | // target=native |
| 13 | // | 14 | // |
| 14 | // :5:25: error: comptime control flow inside runtime block | 15 | // :6:25: error: comptime control flow inside runtime block |
| 15 | // :5:18: note: runtime control flow here | 16 | // :6:18: note: runtime control flow here |
test/cases/compile_errors/comptime_continue_inside_runtime_while_error.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var p: anyerror!usize = undefined; | 2 | var p: anyerror!usize = undefined; |
| 3 | _ = &p; | ||
| 3 | comptime var q = true; | 4 | comptime var q = true; |
| 4 | outer: inline while (q) { | 5 | outer: inline while (q) { |
| 5 | while (p) |_| { | 6 | while (p) |_| { |
| ... | @@ -13,5 +14,5 @@ export fn entry() void { | ... | @@ -13,5 +14,5 @@ export fn entry() void { |
| 13 | // backend=stage2 | 14 | // backend=stage2 |
| 14 | // target=native | 15 | // target=native |
| 15 | // | 16 | // |
| 16 | // :6:13: error: comptime control flow inside runtime block | 17 | // :7:13: error: comptime control flow inside runtime block |
| 17 | // :5:16: note: runtime control flow here | 18 | // :6:16: note: runtime control flow here |
test/cases/compile_errors/comptime_continue_inside_runtime_while_optional.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var p: ?usize = undefined; | 2 | var p: ?usize = undefined; |
| 3 | _ = &p; | ||
| 3 | comptime var q = true; | 4 | comptime var q = true; |
| 4 | outer: inline while (q) { | 5 | outer: inline while (q) { |
| 5 | while (p) |_| continue :outer; | 6 | while (p) |_| continue :outer; |
| ... | @@ -11,5 +12,5 @@ export fn entry() void { | ... | @@ -11,5 +12,5 @@ export fn entry() void { |
| 11 | // backend=stage2 | 12 | // backend=stage2 |
| 12 | // target=native | 13 | // target=native |
| 13 | // | 14 | // |
| 14 | // :5:23: error: comptime control flow inside runtime block | 15 | // :6:23: error: comptime control flow inside runtime block |
| 15 | // :5:16: note: runtime control flow here | 16 | // :6:16: note: runtime control flow here |
test/cases/compile_errors/comptime_continue_to_outer_inline_loop.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | var a = false; | 2 | var a = false; |
| 3 | _ = &a; | ||
| 3 | const arr1 = .{ 1, 2, 3 }; | 4 | const arr1 = .{ 1, 2, 3 }; |
| 4 | loop: inline for (arr1) |val1| { | 5 | loop: inline for (arr1) |val1| { |
| 5 | _ = val1; | 6 | _ = val1; |
| ... | @@ -17,5 +18,5 @@ pub export fn entry() void { | ... | @@ -17,5 +18,5 @@ pub export fn entry() void { |
| 17 | // backend=stage2 | 18 | // backend=stage2 |
| 18 | // target=native | 19 | // target=native |
| 19 | // | 20 | // |
| 20 | // :9:30: error: comptime control flow inside runtime block | 21 | // :10:30: error: comptime control flow inside runtime block |
| 21 | // :6:13: note: runtime control flow here | 22 | // :7:13: note: runtime control flow here |
test/cases/compile_errors/comptime_if_inside_runtime_for.zig+4-3| ... | @@ -1,8 +1,9 @@ | ... | @@ -1,8 +1,9 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var x: u32 = 0; | 2 | var x: u32 = 0; |
| 3 | _ = &x; | ||
| 3 | for (0..1, 1..2) |_, _| { | 4 | for (0..1, 1..2) |_, _| { |
| 4 | var y = x + if (x == 0) 1 else 0; | 5 | var y = x + if (x == 0) 1 else 0; |
| 5 | _ = y; | 6 | _ = &y; |
| 6 | } | 7 | } |
| 7 | } | 8 | } |
| 8 | 9 | ||
| ... | @@ -10,5 +11,5 @@ export fn entry() void { | ... | @@ -10,5 +11,5 @@ export fn entry() void { |
| 10 | // backend=stage2 | 11 | // backend=stage2 |
| 11 | // target=native | 12 | // target=native |
| 12 | // | 13 | // |
| 13 | // :4:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow | 14 | // :5:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow |
| 14 | // :3:10: note: runtime control flow here | 15 | // :4:10: note: runtime control flow here |
test/cases/compile_errors/comptime_slice_of_an_undefined_slice.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: []u8 = undefined; | 2 | var a: []u8 = undefined; |
| 3 | var b = a[0..10]; | 3 | var b = a[0..10]; |
| 4 | _ = b; | 4 | _ = &b; |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
test/cases/compile_errors/comptime_struct_field_no_init_value.zig+1-1| ... | @@ -3,7 +3,7 @@ const Foo = struct { | ... | @@ -3,7 +3,7 @@ const Foo = struct { |
| 3 | }; | 3 | }; |
| 4 | export fn entry() void { | 4 | export fn entry() void { |
| 5 | var f: Foo = undefined; | 5 | var f: Foo = undefined; |
| 6 | _ = f; | 6 | _ = &f; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | // error | 9 | // error |
test/cases/compile_errors/comptime_vector_overflow_shows_the_index.zig+1-1| ... | @@ -2,7 +2,7 @@ comptime { | ... | @@ -2,7 +2,7 @@ comptime { |
| 2 | var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; | 2 | var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; |
| 3 | var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; | 3 | var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; |
| 4 | var x = a + b; | 4 | var x = a + b; |
| 5 | _ = x; | 5 | _ = .{ &a, &b, &x }; |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | // error | 8 | // error |
test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig+2-4| ... | @@ -1,9 +1,7 @@ | ... | @@ -1,9 +1,7 @@ |
| 1 | const ContextAllocator = MemoryPool(usize); | 1 | const ContextAllocator = MemoryPool(usize); |
| 2 | 2 | ||
| 3 | pub fn MemoryPool(comptime T: type) type { | 3 | pub fn MemoryPool(comptime T: type) type { |
| 4 | const free_list_t = @compileError( | 4 | const free_list_t = @compileError("aoeu"); |
| 5 | "aoeu", | ||
| 6 | ); | ||
| 7 | _ = T; | 5 | _ = T; |
| 8 | 6 | ||
| 9 | return struct { | 7 | return struct { |
| ... | @@ -12,7 +10,7 @@ pub fn MemoryPool(comptime T: type) type { | ... | @@ -12,7 +10,7 @@ pub fn MemoryPool(comptime T: type) type { |
| 12 | } | 10 | } |
| 13 | 11 | ||
| 14 | export fn entry() void { | 12 | export fn entry() void { |
| 15 | var allocator: ContextAllocator = undefined; | 13 | const allocator: ContextAllocator = undefined; |
| 16 | _ = allocator; | 14 | _ = allocator; |
| 17 | } | 15 | } |
| 18 | 16 |
test/cases/compile_errors/deref_on_undefined_value.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: *u8 = undefined; | 2 | const a: *u8 = undefined; |
| 3 | _ = a.*; | 3 | _ = a.*; |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/deref_slice_and_get_len_field.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var a: []u8 = undefined; | 2 | var a: []u8 = undefined; |
| 3 | _ = a.*.len; | 3 | _ = a.*.len; |
| 4 | _ = &a; | ||
| 4 | } | 5 | } |
| 5 | 6 | ||
| 6 | // error | 7 | // error |
test/cases/compile_errors/dereference_an_array.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | var s_buffer: [10]u8 = undefined; | 1 | var s_buffer: [10]u8 = undefined; |
| 2 | pub fn pass(in: []u8) []u8 { | 2 | pub fn pass(in: []u8) []u8 { |
| 3 | var out = &s_buffer; | 3 | var out = &s_buffer; |
| 4 | _ = &out; | ||
| 4 | out.*.* = in[0]; | 5 | out.*.* = in[0]; |
| 5 | return out.*[0..1]; | 6 | return out.*[0..1]; |
| 6 | } | 7 | } |
| ... | @@ -13,4 +14,4 @@ export fn entry() usize { | ... | @@ -13,4 +14,4 @@ export fn entry() usize { |
| 13 | // backend=stage2 | 14 | // backend=stage2 |
| 14 | // target=native | 15 | // target=native |
| 15 | // | 16 | // |
| 16 | // :4:10: error: cannot dereference non-pointer type '[10]u8' | 17 | // :5:10: error: cannot dereference non-pointer type '[10]u8' |
test/cases/compile_errors/dereferencing_invalid_payload_ptr_at_comptime.zig+1-1| ... | @@ -16,7 +16,7 @@ comptime { | ... | @@ -16,7 +16,7 @@ comptime { |
| 16 | _ = payload_ptr.*; | 16 | _ = payload_ptr.*; |
| 17 | } | 17 | } |
| 18 | comptime { | 18 | comptime { |
| 19 | var val: u8 = 15; | 19 | const val: u8 = 15; |
| 20 | var err_union: anyerror!u8 = val; | 20 | var err_union: anyerror!u8 = val; |
| 21 | 21 | ||
| 22 | const payload_ptr = &(err_union catch unreachable); | 22 | const payload_ptr = &(err_union catch unreachable); |
test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig+2-2| ... | @@ -8,11 +8,11 @@ const Bar = union { | ... | @@ -8,11 +8,11 @@ const Bar = union { |
| 8 | }; | 8 | }; |
| 9 | export fn a() void { | 9 | export fn a() void { |
| 10 | var foo: Foo = undefined; | 10 | var foo: Foo = undefined; |
| 11 | _ = foo; | 11 | _ = &foo; |
| 12 | } | 12 | } |
| 13 | export fn b() void { | 13 | export fn b() void { |
| 14 | var bar: Bar = undefined; | 14 | var bar: Bar = undefined; |
| 15 | _ = bar; | 15 | _ = &bar; |
| 16 | } | 16 | } |
| 17 | export fn c() void { | 17 | export fn c() void { |
| 18 | const baz = &@as(O, undefined); | 18 | const baz = &@as(O, undefined); |
test/cases/compile_errors/div_on_undefined_value.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: i64 = undefined; | 2 | var a: i64 = undefined; |
| 3 | _ = a / a; | 3 | _ = a / a; |
| 4 | _ = &a; | ||
| 4 | } | 5 | } |
| 5 | 6 | ||
| 6 | // error | 7 | // error |
test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig+4-3| ... | @@ -11,12 +11,13 @@ pub export fn entry2() void { | ... | @@ -11,12 +11,13 @@ pub export fn entry2() void { |
| 11 | fn func(_: ?*anyopaque) void {} | 11 | fn func(_: ?*anyopaque) void {} |
| 12 | pub export fn entry3() void { | 12 | pub export fn entry3() void { |
| 13 | var x: *?*usize = undefined; | 13 | var x: *?*usize = undefined; |
| 14 | 14 | _ = &x; | |
| 15 | const ptr: *const anyopaque = x; | 15 | const ptr: *const anyopaque = x; |
| 16 | _ = ptr; | 16 | _ = ptr; |
| 17 | } | 17 | } |
| 18 | export fn entry4() void { | 18 | export fn entry4() void { |
| 19 | var a: []*u32 = undefined; | 19 | var a: []*u32 = undefined; |
| 20 | _ = &a; | ||
| 20 | var b: []anyopaque = undefined; | 21 | var b: []anyopaque = undefined; |
| 21 | b = a; | 22 | b = a; |
| 22 | } | 23 | } |
| ... | @@ -32,5 +33,5 @@ export fn entry4() void { | ... | @@ -32,5 +33,5 @@ export fn entry4() void { |
| 32 | // :11:12: note: parameter type declared here | 33 | // :11:12: note: parameter type declared here |
| 33 | // :15:35: error: expected type '*const anyopaque', found '*?*usize' | 34 | // :15:35: error: expected type '*const anyopaque', found '*?*usize' |
| 34 | // :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque' | 35 | // :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque' |
| 35 | // :21:9: error: expected type '[]anyopaque', found '[]*u32' | 36 | // :22:9: error: expected type '[]anyopaque', found '[]*u32' |
| 36 | // :21:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque' | 37 | // :22:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque' |
test/cases/compile_errors/empty_switch_on_an_integer.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var x: u32 = 0; | 2 | const x: u32 = 0; |
| 3 | switch (x) {} | 3 | switch (x) {} |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | const E = enum(comptime_int) { a, b, c, _ }; | 2 | const E = enum(comptime_int) { a, b, c, _ }; |
| 3 | var e: E = .a; | 3 | var e: E = .a; |
| 4 | _ = e; | 4 | _ = &e; |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
test/cases/compile_errors/enum_field_value_references_enum.zig+1-1| ... | @@ -3,7 +3,7 @@ pub const Foo = enum(c_int) { | ... | @@ -3,7 +3,7 @@ pub const Foo = enum(c_int) { |
| 3 | C = D, | 3 | C = D, |
| 4 | }; | 4 | }; |
| 5 | export fn entry() void { | 5 | export fn entry() void { |
| 6 | var s: Foo = Foo.E; | 6 | const s: Foo = Foo.E; |
| 7 | _ = s; | 7 | _ = s; |
| 8 | } | 8 | } |
| 9 | const D = 1; | 9 | const D = 1; |
test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig+2-2| ... | @@ -3,7 +3,7 @@ const Foo = enum(u32) { | ... | @@ -3,7 +3,7 @@ const Foo = enum(u32) { |
| 3 | B = 11, | 3 | B = 11, |
| 4 | }; | 4 | }; |
| 5 | export fn entry() void { | 5 | export fn entry() void { |
| 6 | var x: Foo = @enumFromInt(0); | 6 | const x: Foo = @enumFromInt(0); |
| 7 | _ = x; | 7 | _ = x; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| ... | @@ -11,5 +11,5 @@ export fn entry() void { | ... | @@ -11,5 +11,5 @@ export fn entry() void { |
| 11 | // backend=stage2 | 11 | // backend=stage2 |
| 12 | // target=native | 12 | // target=native |
| 13 | // | 13 | // |
| 14 | // :6:18: error: enum 'tmp.Foo' has no tag with value '0' | 14 | // :6:20: error: enum 'tmp.Foo' has no tag with value '0' |
| 15 | // :1:13: note: enum declared here | 15 | // :1:13: note: enum declared here |
test/cases/compile_errors/enum_value_already_taken.zig+1-1| ... | @@ -6,7 +6,7 @@ const MultipleChoice = enum(u32) { | ... | @@ -6,7 +6,7 @@ const MultipleChoice = enum(u32) { |
| 6 | E = 60, | 6 | E = 60, |
| 7 | }; | 7 | }; |
| 8 | export fn entry() void { | 8 | export fn entry() void { |
| 9 | var x = MultipleChoice.C; | 9 | const x = MultipleChoice.C; |
| 10 | _ = x; | 10 | _ = x; |
| 11 | } | 11 | } |
| 12 | 12 |
test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig+1-1| ... | @@ -4,7 +4,7 @@ pub export fn entry() void { | ... | @@ -4,7 +4,7 @@ pub export fn entry() void { |
| 4 | e: u8, | 4 | e: u8, |
| 5 | }; | 5 | }; |
| 6 | var a = .{@sizeOf(bitfield)}; | 6 | var a = .{@sizeOf(bitfield)}; |
| 7 | _ = a; | 7 | _ = &a; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | // error | 10 | // error |
test/cases/compile_errors/error_union_operator_with_non_error_set_LHS.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | const z = i32!i32; | 2 | const z = i32!i32; |
| 3 | var x: z = undefined; | 3 | const x: z = undefined; |
| 4 | _ = x; | 4 | _ = x; |
| 5 | } | 5 | } |
| 6 | 6 |
test/cases/compile_errors/error_when_evaluating_return_type.zig+1-1| ... | @@ -6,7 +6,7 @@ const Foo = struct { | ... | @@ -6,7 +6,7 @@ const Foo = struct { |
| 6 | } | 6 | } |
| 7 | }; | 7 | }; |
| 8 | export fn entry() void { | 8 | export fn entry() void { |
| 9 | var rule_set = try Foo.init(); | 9 | const rule_set = try Foo.init(); |
| 10 | _ = rule_set; | 10 | _ = rule_set; |
| 11 | } | 11 | } |
| 12 | 12 |
test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig+3-2| ... | @@ -11,12 +11,13 @@ fn foo(a: u8, comptime PtrTy: type) S(PtrTy) { | ... | @@ -11,12 +11,13 @@ fn foo(a: u8, comptime PtrTy: type) S(PtrTy) { |
| 11 | } | 11 | } |
| 12 | pub export fn entry() void { | 12 | pub export fn entry() void { |
| 13 | var a: u8 = 1; | 13 | var a: u8 = 1; |
| 14 | _ = &a; | ||
| 14 | _ = foo(a, fn () void); | 15 | _ = foo(a, fn () void); |
| 15 | } | 16 | } |
| 16 | // error | 17 | // error |
| 17 | // backend=stage2 | 18 | // backend=stage2 |
| 18 | // target=native | 19 | // target=native |
| 19 | // | 20 | // |
| 20 | // :14:13: error: unable to resolve comptime value | 21 | // :15:13: error: unable to resolve comptime value |
| 21 | // :14:13: note: argument to function being called at comptime must be comptime-known | 22 | // :15:13: note: argument to function being called at comptime must be comptime-known |
| 22 | // :9:38: note: expression is evaluated at comptime because the generic function was instantiated with a comptime-only return type | 23 | // :9:38: note: expression is evaluated at comptime because the generic function was instantiated with a comptime-only return type |
test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig+3-3| ... | @@ -1,8 +1,8 @@ | ... | @@ -1,8 +1,8 @@ |
| 1 | const Set1 = error{ A, B }; | 1 | const Set1 = error{ A, B }; |
| 2 | const Set2 = error{ A, C }; | 2 | const Set2 = error{ A, C }; |
| 3 | comptime { | 3 | comptime { |
| 4 | var x = Set1.B; | 4 | const x = Set1.B; |
| 5 | var y: Set2 = @errorCast(x); | 5 | const y: Set2 = @errorCast(x); |
| 6 | _ = y; | 6 | _ = y; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| ... | @@ -10,4 +10,4 @@ comptime { | ... | @@ -10,4 +10,4 @@ comptime { |
| 10 | // backend=stage2 | 10 | // backend=stage2 |
| 11 | // target=native | 11 | // target=native |
| 12 | // | 12 | // |
| 13 | // :5:19: error: 'error.B' not a member of error set 'error{C,A}' | 13 | // :5:21: error: 'error.B' not a member of error set 'error{C,A}' |
test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig+2-2| ... | @@ -7,7 +7,7 @@ const Small = enum(u2) { | ... | @@ -7,7 +7,7 @@ const Small = enum(u2) { |
| 7 | 7 | ||
| 8 | export fn entry() void { | 8 | export fn entry() void { |
| 9 | var y = @as(f32, 3); | 9 | var y = @as(f32, 3); |
| 10 | var x: Small = @enumFromInt(y); | 10 | const x: Small = @enumFromInt((&y).*); |
| 11 | _ = x; | 11 | _ = x; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| ... | @@ -15,4 +15,4 @@ export fn entry() void { | ... | @@ -15,4 +15,4 @@ export fn entry() void { |
| 15 | // backend=stage2 | 15 | // backend=stage2 |
| 16 | // target=native | 16 | // target=native |
| 17 | // | 17 | // |
| 18 | // :10:33: error: expected integer type, found 'f32' | 18 | // :10:39: error: expected integer type, found 'f32' |
test/cases/compile_errors/extern_union_field_missing_type.zig+1-1| ... | @@ -2,7 +2,7 @@ const Letter = extern union { | ... | @@ -2,7 +2,7 @@ const Letter = extern union { |
| 2 | A, | 2 | A, |
| 3 | }; | 3 | }; |
| 4 | export fn entry() void { | 4 | export fn entry() void { |
| 5 | var a = Letter{ .A = {} }; | 5 | const a: Letter = .{ .A = {} }; |
| 6 | _ = a; | 6 | _ = a; |
| 7 | } | 7 | } |
| 8 | 8 |
test/cases/compile_errors/extern_union_given_enum_tag_type.zig+1-1| ... | @@ -9,7 +9,7 @@ const Payload = extern union(Letter) { | ... | @@ -9,7 +9,7 @@ const Payload = extern union(Letter) { |
| 9 | C: bool, | 9 | C: bool, |
| 10 | }; | 10 | }; |
| 11 | export fn entry() void { | 11 | export fn entry() void { |
| 12 | var a = Payload{ .A = 1234 }; | 12 | const a: Payload = .{ .A = 1234 }; |
| 13 | _ = a; | 13 | _ = a; |
| 14 | } | 14 | } |
| 15 | 15 |
test/cases/compile_errors/field_access_of_slices.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var slice: []i32 = undefined; | 2 | var slice: []i32 = undefined; |
| 3 | _ = &slice; | ||
| 3 | const info = @TypeOf(slice).unknown; | 4 | const info = @TypeOf(slice).unknown; |
| 4 | _ = info; | 5 | _ = info; |
| 5 | } | 6 | } |
| ... | @@ -8,5 +9,5 @@ export fn entry() void { | ... | @@ -8,5 +9,5 @@ export fn entry() void { |
| 8 | // backend=stage2 | 9 | // backend=stage2 |
| 9 | // target=native | 10 | // target=native |
| 10 | // | 11 | // |
| 11 | // :3:32: error: type '[]i32' has no members | 12 | // :4:32: error: type '[]i32' has no members |
| 12 | // :3:32: note: slice values have 'len' and 'ptr' members | 13 | // :4:32: note: slice values have 'len' and 'ptr' members |
test/cases/compile_errors/for.zig+4-3| ... | @@ -17,6 +17,7 @@ export fn c() void { | ... | @@ -17,6 +17,7 @@ export fn c() void { |
| 17 | for (buf) |*byte| { | 17 | for (buf) |*byte| { |
| 18 | _ = byte; | 18 | _ = byte; |
| 19 | } | 19 | } |
| 20 | _ = &buf; | ||
| 20 | } | 21 | } |
| 21 | export fn d() void { | 22 | export fn d() void { |
| 22 | const x: [*]const u8 = "hello"; | 23 | const x: [*]const u8 = "hello"; |
| ... | @@ -39,6 +40,6 @@ export fn d() void { | ... | @@ -39,6 +40,6 @@ export fn d() void { |
| 39 | // :10:14: note: for loop operand must be a range, array, slice, tuple, or vector | 40 | // :10:14: note: for loop operand must be a range, array, slice, tuple, or vector |
| 40 | // :17:16: error: pointer capture of non pointer type '[10]u8' | 41 | // :17:16: error: pointer capture of non pointer type '[10]u8' |
| 41 | // :17:10: note: consider using '&' here | 42 | // :17:10: note: consider using '&' here |
| 42 | // :24:5: error: unbounded for loop | 43 | // :25:5: error: unbounded for loop |
| 43 | // :24:10: note: type '[*]const u8' has no upper bound | 44 | // :25:10: note: type '[*]const u8' has no upper bound |
| 44 | // :24:18: note: type '[*]const u8' has no upper bound | 45 | // :25:18: note: type '[*]const u8' has no upper bound |
test/cases/compile_errors/for_loop_body_expression_ignored.zig+1-1| ... | @@ -7,7 +7,7 @@ export fn f1() void { | ... | @@ -7,7 +7,7 @@ export fn f1() void { |
| 7 | export fn f2() void { | 7 | export fn f2() void { |
| 8 | var x: anyerror!i32 = error.Bad; | 8 | var x: anyerror!i32 = error.Bad; |
| 9 | for ("hello") |_| returns() else unreachable; | 9 | for ("hello") |_| returns() else unreachable; |
| 10 | _ = x; | 10 | _ = &x; |
| 11 | } | 11 | } |
| 12 | export fn f3() void { | 12 | export fn f3() void { |
| 13 | for ("hello") |_| {} else true; | 13 | for ("hello") |_| {} else true; |
test/cases/compile_errors/function_ptr_alignment.zig+5-5| ... | @@ -1,24 +1,24 @@ | ... | @@ -1,24 +1,24 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: *align(2) @TypeOf(foo) = undefined; | 2 | var a: *align(2) @TypeOf(foo) = undefined; |
| 3 | _ = a; | 3 | _ = &a; |
| 4 | } | 4 | } |
| 5 | fn foo() void {} | 5 | fn foo() void {} |
| 6 | 6 | ||
| 7 | comptime { | 7 | comptime { |
| 8 | var a: *align(1) fn () void = undefined; | 8 | var a: *align(1) fn () void = undefined; |
| 9 | _ = a; | 9 | _ = &a; |
| 10 | } | 10 | } |
| 11 | comptime { | 11 | comptime { |
| 12 | var a: *align(2) fn () align(2) void = undefined; | 12 | var a: *align(2) fn () align(2) void = undefined; |
| 13 | _ = a; | 13 | _ = &a; |
| 14 | } | 14 | } |
| 15 | comptime { | 15 | comptime { |
| 16 | var a: *align(2) fn () void = undefined; | 16 | var a: *align(2) fn () void = undefined; |
| 17 | _ = a; | 17 | _ = &a; |
| 18 | } | 18 | } |
| 19 | comptime { | 19 | comptime { |
| 20 | var a: *align(1) fn () align(2) void = undefined; | 20 | var a: *align(1) fn () align(2) void = undefined; |
| 21 | _ = a; | 21 | _ = &a; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | // error | 24 | // error |
test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig+2-1| ... | @@ -3,6 +3,7 @@ const std = @import("std"); | ... | @@ -3,6 +3,7 @@ const std = @import("std"); |
| 3 | pub export fn entry() void { | 3 | pub export fn entry() void { |
| 4 | var ohnoes: *usize = undefined; | 4 | var ohnoes: *usize = undefined; |
| 5 | _ = sliceAsBytes(ohnoes); | 5 | _ = sliceAsBytes(ohnoes); |
| 6 | _ = &ohnoes; | ||
| 6 | } | 7 | } |
| 7 | fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {} | 8 | fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {} |
| 8 | 9 | ||
| ... | @@ -10,4 +11,4 @@ fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) { | ... | @@ -10,4 +11,4 @@ fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) { |
| 10 | // backend=llvm | 11 | // backend=llvm |
| 11 | // target=native | 12 | // target=native |
| 12 | // | 13 | // |
| 13 | // :7:63: error: expected type 'type', found 'bool' | 14 | // :8:63: error: expected type 'type', found 'bool' |
test/cases/compile_errors/generic_method_call_with_invalid_param.zig+5-4| ... | @@ -11,6 +11,7 @@ export fn callVoidMethodWithBool() void { | ... | @@ -11,6 +11,7 @@ export fn callVoidMethodWithBool() void { |
| 11 | export fn callComptimeBoolMethodWithRuntimeBool() void { | 11 | export fn callComptimeBoolMethodWithRuntimeBool() void { |
| 12 | const s = S{}; | 12 | const s = S{}; |
| 13 | var arg = true; | 13 | var arg = true; |
| 14 | _ = &arg; | ||
| 14 | s.comptimeBoolMethod(arg); | 15 | s.comptimeBoolMethod(arg); |
| 15 | } | 16 | } |
| 16 | 17 | ||
| ... | @@ -25,8 +26,8 @@ const S = struct { | ... | @@ -25,8 +26,8 @@ const S = struct { |
| 25 | // target=native | 26 | // target=native |
| 26 | // | 27 | // |
| 27 | // :3:18: error: expected type 'bool', found 'void' | 28 | // :3:18: error: expected type 'bool', found 'void' |
| 28 | // :18:43: note: parameter type declared here | ||
| 29 | // :8:18: error: expected type 'void', found 'bool' | ||
| 30 | // :19:43: note: parameter type declared here | 29 | // :19:43: note: parameter type declared here |
| 31 | // :14:26: error: runtime-known argument passed to comptime parameter | 30 | // :8:18: error: expected type 'void', found 'bool' |
| 32 | // :20:57: note: declared comptime here | 31 | // :20:43: note: parameter type declared here |
| 32 | // :15:26: error: runtime-known argument passed to comptime parameter | ||
| 33 | // :21:57: note: declared comptime here |
test/cases/compile_errors/ignored_expression_in_while_continuation.zig+6-4| ... | @@ -3,10 +3,12 @@ export fn a() void { | ... | @@ -3,10 +3,12 @@ export fn a() void { |
| 3 | } | 3 | } |
| 4 | export fn b() void { | 4 | export fn b() void { |
| 5 | var x: anyerror!i32 = 1234; | 5 | var x: anyerror!i32 = 1234; |
| 6 | _ = &x; | ||
| 6 | while (x) |_| : (bad()) {} else |_| {} | 7 | while (x) |_| : (bad()) {} else |_| {} |
| 7 | } | 8 | } |
| 8 | export fn c() void { | 9 | export fn c() void { |
| 9 | var x: ?i32 = 1234; | 10 | var x: ?i32 = 1234; |
| 11 | _ = &x; | ||
| 10 | while (x) |_| : (bad()) {} | 12 | while (x) |_| : (bad()) {} |
| 11 | } | 13 | } |
| 12 | fn bad() anyerror!void { | 14 | fn bad() anyerror!void { |
| ... | @@ -19,7 +21,7 @@ fn bad() anyerror!void { | ... | @@ -19,7 +21,7 @@ fn bad() anyerror!void { |
| 19 | // | 21 | // |
| 20 | // :2:24: error: error is ignored | 22 | // :2:24: error: error is ignored |
| 21 | // :2:24: note: consider using 'try', 'catch', or 'if' | 23 | // :2:24: note: consider using 'try', 'catch', or 'if' |
| 22 | // :6:25: error: error is ignored | 24 | // :7:25: error: error is ignored |
| 23 | // :6:25: note: consider using 'try', 'catch', or 'if' | 25 | // :7:25: note: consider using 'try', 'catch', or 'if' |
| 24 | // :10:25: error: error is ignored | 26 | // :12:25: error: error is ignored |
| 25 | // :10:25: note: consider using 'try', 'catch', or 'if' | 27 | // :12:25: note: consider using 'try', 'catch', or 'if' |
test/cases/compile_errors/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig+6-6| ... | @@ -1,32 +1,32 @@ | ... | @@ -1,32 +1,32 @@ |
| 1 | export fn a() void { | 1 | export fn a() void { |
| 2 | var x: [*c]u8 = undefined; | 2 | var x: [*c]u8 = undefined; |
| 3 | var y: *align(4) u8 = x; | 3 | var y: *align(4) u8 = x; |
| 4 | _ = y; | 4 | _ = .{ &x, &y }; |
| 5 | } | 5 | } |
| 6 | export fn b() void { | 6 | export fn b() void { |
| 7 | var x: [*c]const u8 = undefined; | 7 | var x: [*c]const u8 = undefined; |
| 8 | var y: *u8 = x; | 8 | var y: *u8 = x; |
| 9 | _ = y; | 9 | _ = .{ &x, &y }; |
| 10 | } | 10 | } |
| 11 | export fn c() void { | 11 | export fn c() void { |
| 12 | var x: [*c]u8 = undefined; | 12 | var x: [*c]u8 = undefined; |
| 13 | var y: *u32 = x; | 13 | var y: *u32 = x; |
| 14 | _ = y; | 14 | _ = .{ &x, &y }; |
| 15 | } | 15 | } |
| 16 | export fn d() void { | 16 | export fn d() void { |
| 17 | var y: *align(1) u32 = undefined; | 17 | var y: *align(1) u32 = undefined; |
| 18 | var x: [*c]u32 = y; | 18 | var x: [*c]u32 = y; |
| 19 | _ = x; | 19 | _ = .{ &x, &y }; |
| 20 | } | 20 | } |
| 21 | export fn e() void { | 21 | export fn e() void { |
| 22 | var y: *const u8 = undefined; | 22 | var y: *const u8 = undefined; |
| 23 | var x: [*c]u8 = y; | 23 | var x: [*c]u8 = y; |
| 24 | _ = x; | 24 | _ = .{ &x, &y }; |
| 25 | } | 25 | } |
| 26 | export fn f() void { | 26 | export fn f() void { |
| 27 | var y: *u8 = undefined; | 27 | var y: *u8 = undefined; |
| 28 | var x: [*c]u32 = y; | 28 | var x: [*c]u32 = y; |
| 29 | _ = x; | 29 | _ = .{ &x, &y }; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | // error | 32 | // error |
test/cases/compile_errors/implicit_cast_from_f64_to_f32.zig+1-1| ... | @@ -7,7 +7,7 @@ export fn entry() void { | ... | @@ -7,7 +7,7 @@ export fn entry() void { |
| 7 | export fn entry2() void { | 7 | export fn entry2() void { |
| 8 | var x1: f64 = 1.0; | 8 | var x1: f64 = 1.0; |
| 9 | var y2: f32 = x1; | 9 | var y2: f32 = x1; |
| 10 | _ = y2; | 10 | _ = .{ &x1, &y2 }; |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | // error | 13 | // error |
test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig+3-3| ... | @@ -4,7 +4,7 @@ export fn entry() void { | ... | @@ -4,7 +4,7 @@ export fn entry() void { |
| 4 | foo(Set1.B); | 4 | foo(Set1.B); |
| 5 | } | 5 | } |
| 6 | fn foo(set1: Set1) void { | 6 | fn foo(set1: Set1) void { |
| 7 | var x: Set2 = set1; | 7 | const x: Set2 = set1; |
| 8 | _ = x; | 8 | _ = x; |
| 9 | } | 9 | } |
| 10 | 10 | ||
| ... | @@ -12,5 +12,5 @@ fn foo(set1: Set1) void { | ... | @@ -12,5 +12,5 @@ fn foo(set1: Set1) void { |
| 12 | // backend=stage2 | 12 | // backend=stage2 |
| 13 | // target=native | 13 | // target=native |
| 14 | // | 14 | // |
| 15 | // :7:19: error: expected type 'error{C,A}', found 'error{A,B}' | 15 | // :7:21: error: expected type 'error{C,A}', found 'error{A,B}' |
| 16 | // :7:19: note: 'error.B' not a member of destination error set | 16 | // :7:21: note: 'error.B' not a member of destination error set |
test/cases/compile_errors/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig+9-4| ... | @@ -4,6 +4,9 @@ export fn entry() void { | ... | @@ -4,6 +4,9 @@ export fn entry() void { |
| 4 | var ptr_opt_many_ptr = &opt_many_ptr; | 4 | var ptr_opt_many_ptr = &opt_many_ptr; |
| 5 | var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; | 5 | var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; |
| 6 | ptr_opt_many_ptr = c_ptr; | 6 | ptr_opt_many_ptr = c_ptr; |
| 7 | _ = &slice; | ||
| 8 | _ = &ptr_opt_many_ptr; | ||
| 9 | _ = &c_ptr; | ||
| 7 | } | 10 | } |
| 8 | export fn entry2() void { | 11 | export fn entry2() void { |
| 9 | var buf: [4]u8 = "aoeu".*; | 12 | var buf: [4]u8 = "aoeu".*; |
| ... | @@ -11,7 +14,9 @@ export fn entry2() void { | ... | @@ -11,7 +14,9 @@ export fn entry2() void { |
| 11 | var opt_many_ptr: [*]u8 = slice.ptr; | 14 | var opt_many_ptr: [*]u8 = slice.ptr; |
| 12 | var ptr_opt_many_ptr = &opt_many_ptr; | 15 | var ptr_opt_many_ptr = &opt_many_ptr; |
| 13 | var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; | 16 | var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; |
| 14 | _ = c_ptr; | 17 | _ = &slice; |
| 18 | _ = &ptr_opt_many_ptr; | ||
| 19 | _ = &c_ptr; | ||
| 15 | } | 20 | } |
| 16 | 21 | ||
| 17 | // error | 22 | // error |
| ... | @@ -21,6 +26,6 @@ export fn entry2() void { | ... | @@ -21,6 +26,6 @@ export fn entry2() void { |
| 21 | // :6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8' | 26 | // :6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8' |
| 22 | // :6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8' | 27 | // :6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8' |
| 23 | // :6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8' | 28 | // :6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8' |
| 24 | // :13:35: error: expected type '[*c][*c]const u8', found '*[*]u8' | 29 | // :16:35: error: expected type '[*c][*c]const u8', found '*[*]u8' |
| 25 | // :13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8' | 30 | // :16:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8' |
| 26 | // :13:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8' | 31 | // :16:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8' |
test/cases/compile_errors/implicit_casting_null_c_pointer_to_zig_pointer.zig+3-2| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var c_ptr: [*c]u8 = 0; | 2 | var c_ptr: [*c]u8 = 0; |
| 3 | var zig_ptr: *u8 = c_ptr; | 3 | const zig_ptr: *u8 = c_ptr; |
| 4 | _ = &c_ptr; | ||
| 4 | _ = zig_ptr; | 5 | _ = zig_ptr; |
| 5 | } | 6 | } |
| 6 | 7 | ||
| ... | @@ -8,4 +9,4 @@ comptime { | ... | @@ -8,4 +9,4 @@ comptime { |
| 8 | // backend=stage2 | 9 | // backend=stage2 |
| 9 | // target=native | 10 | // target=native |
| 10 | // | 11 | // |
| 11 | // :3:24: error: null pointer casted to type '*u8' | 12 | // :3:26: error: null pointer casted to type '*u8' |
test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig+1-1| ... | @@ -7,7 +7,7 @@ const Small = enum(u2) { | ... | @@ -7,7 +7,7 @@ const Small = enum(u2) { |
| 7 | 7 | ||
| 8 | export fn entry() void { | 8 | export fn entry() void { |
| 9 | var x: u2 = Small.Two; | 9 | var x: u2 = Small.Two; |
| 10 | _ = x; | 10 | _ = &x; |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | // error | 13 | // error |
test/cases/compile_errors/incompatible sub-byte fields.zig	+4-3| ... | @@ -11,6 +11,7 @@ export fn entry() void { | ... | @@ -11,6 +11,7 @@ export fn entry() void { |
| 11 | var a = A{ .a = 2, .b = 2 }; | 11 | var a = A{ .a = 2, .b = 2 }; |
| 12 | var b = B{ .q = 22, .a = 3, .b = 2 }; | 12 | var b = B{ .q = 22, .a = 3, .b = 2 }; |
| 13 | var t: usize = 0; | 13 | var t: usize = 0; |
| 14 | _ = &t; | ||
| 14 | const ptr = switch (t) { | 15 | const ptr = switch (t) { |
| 15 | 0 => &a.a, | 16 | 0 => &a.a, |
| 16 | 1 => &b.a, | 17 | 1 => &b.a, |
| ... | @@ -24,6 +25,6 @@ export fn entry() void { | ... | @@ -24,6 +25,6 @@ export fn entry() void { |
| 24 | // backend=stage2 | 25 | // backend=stage2 |
| 25 | // target=native | 26 | // target=native |
| 26 | // | 27 | // |
| 27 | // :14:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2' | 28 | // :15:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2' |
| 28 | // :15:14: note: type '*align(1:0:1) u2' here | 29 | // :16:14: note: type '*align(1:0:1) u2' here |
| 29 | // :16:14: note: type '*align(2:8:2) u2' here | 30 | // :17:14: note: type '*align(2:8:2) u2' here |
test/cases/compile_errors/incompatible_sentinels.zig+2-2| ... | @@ -8,11 +8,11 @@ export fn entry2(ptr: [*]u8) [*:0]u8 { | ... | @@ -8,11 +8,11 @@ export fn entry2(ptr: [*]u8) [*:0]u8 { |
| 8 | } | 8 | } |
| 9 | export fn entry3() void { | 9 | export fn entry3() void { |
| 10 | var array: [2:0]u8 = [_:255]u8{ 1, 2 }; | 10 | var array: [2:0]u8 = [_:255]u8{ 1, 2 }; |
| 11 | _ = array; | 11 | _ = &array; |
| 12 | } | 12 | } |
| 13 | export fn entry4() void { | 13 | export fn entry4() void { |
| 14 | var array: [2:0]u8 = [_]u8{ 1, 2 }; | 14 | var array: [2:0]u8 = [_]u8{ 1, 2 }; |
| 15 | _ = array; | 15 | _ = &array; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | // error | 18 | // error |
test/cases/compile_errors/incorrect_pointer_dereference_syntax.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | var a: *u32 = undefined; | 2 | var a: *u32 = undefined; |
| 3 | _ = *a; | 3 | _ = *a; |
| 4 | _ = &a; | ||
| 4 | } | 5 | } |
| 5 | 6 | ||
| 6 | // error | 7 | // error |
test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig+4-4| ... | @@ -1,17 +1,17 @@ | ... | @@ -1,17 +1,17 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; | 2 | var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; |
| 3 | var slice: []u8 = &buf; | 3 | const slice: []u8 = &buf; |
| 4 | const a: u32 = 1234; | 4 | const a: u32 = 1234; |
| 5 | @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a))); | 5 | @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a))); |
| 6 | } | 6 | } |
| 7 | pub export fn entry1() void { | 7 | pub export fn entry1() void { |
| 8 | var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; | 8 | var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; |
| 9 | var ptr: *u8 = &buf[0]; | 9 | const ptr: *u8 = &buf[0]; |
| 10 | @memcpy(ptr, 0); | 10 | @memcpy(ptr, 0); |
| 11 | } | 11 | } |
| 12 | pub export fn entry2() void { | 12 | pub export fn entry2() void { |
| 13 | var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; | 13 | var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; |
| 14 | var ptr: *u8 = &buf[0]; | 14 | const ptr: *u8 = &buf[0]; |
| 15 | @memset(ptr, 0); | 15 | @memset(ptr, 0); |
| 16 | } | 16 | } |
| 17 | pub export fn non_matching_lengths() void { | 17 | pub export fn non_matching_lengths() void { |
| ... | @@ -29,7 +29,7 @@ pub export fn memcpy_const_dest_ptr() void { | ... | @@ -29,7 +29,7 @@ pub export fn memcpy_const_dest_ptr() void { |
| 29 | @memcpy(&buf1, &buf2); | 29 | @memcpy(&buf1, &buf2); |
| 30 | } | 30 | } |
| 31 | pub export fn memset_array() void { | 31 | pub export fn memset_array() void { |
| 32 | var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; | 32 | const buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; |
| 33 | @memcpy(buf, 1); | 33 | @memcpy(buf, 1); |
| 34 | } | 34 | } |
| 35 | 35 |
test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const array = [_]u8{}; | 1 | const array = [_]u8{}; |
| 2 | export fn foo() void { | 2 | export fn foo() void { |
| 3 | var index: usize = 0; | 3 | var index: usize = 0; |
| 4 | _ = &index; | ||
| 4 | const pointer = &array[index]; | 5 | const pointer = &array[index]; |
| 5 | _ = pointer; | 6 | _ = pointer; |
| 6 | } | 7 | } |
| ... | @@ -9,4 +10,4 @@ export fn foo() void { | ... | @@ -9,4 +10,4 @@ export fn foo() void { |
| 9 | // backend=stage2 | 10 | // backend=stage2 |
| 10 | // target=native | 11 | // target=native |
| 11 | // | 12 | // |
| 12 | // :4:27: error: indexing into empty array is not allowed | 13 | // :5:27: error: indexing into empty array is not allowed |
test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig+1-1| ... | @@ -6,7 +6,7 @@ fn acceptRuntime(value: u64) void { | ... | @@ -6,7 +6,7 @@ fn acceptRuntime(value: u64) void { |
| 6 | } | 6 | } |
| 7 | pub export fn entry() void { | 7 | pub export fn entry() void { |
| 8 | var value: u64 = 0; | 8 | var value: u64 = 0; |
| 9 | acceptRuntime(value); | 9 | acceptRuntime((&value).*); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | // error | 12 | // error |
test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig+6-4| ... | @@ -1,9 +1,11 @@ | ... | @@ -1,9 +1,11 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var a: f32 = 2; | 2 | var a: f32 = 2; |
| 3 | _ = &a; | ||
| 3 | _ = @as(comptime_int, @intFromFloat(a)); | 4 | _ = @as(comptime_int, @intFromFloat(a)); |
| 4 | } | 5 | } |
| 5 | export fn bar() void { | 6 | export fn bar() void { |
| 6 | var a: u32 = 2; | 7 | var a: u32 = 2; |
| 8 | _ = &a; | ||
| 7 | _ = @as(comptime_float, @floatFromInt(a)); | 9 | _ = @as(comptime_float, @floatFromInt(a)); |
| 8 | } | 10 | } |
| 9 | 11 | ||
| ... | @@ -11,7 +13,7 @@ export fn bar() void { | ... | @@ -11,7 +13,7 @@ export fn bar() void { |
| 11 | // backend=stage2 | 13 | // backend=stage2 |
| 12 | // target=native | 14 | // target=native |
| 13 | // | 15 | // |
| 14 | // :3:41: error: unable to resolve comptime value | 16 | // :4:41: error: unable to resolve comptime value |
| 15 | // :3:41: note: value being casted to 'comptime_int' must be comptime-known | 17 | // :4:41: note: value being casted to 'comptime_int' must be comptime-known |
| 16 | // :7:43: error: unable to resolve comptime value | 18 | // :9:43: error: unable to resolve comptime value |
| 17 | // :7:43: note: value being casted to 'comptime_float' must be comptime-known | 19 | // :9:43: note: value being casted to 'comptime_float' must be comptime-known |
test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig+2-2| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var b: *i32 = @ptrFromInt(0); | 2 | const b: *i32 = @ptrFromInt(0); |
| 3 | _ = b; | 3 | _ = b; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| ... | @@ -7,4 +7,4 @@ export fn entry() void { | ... | @@ -7,4 +7,4 @@ export fn entry() void { |
| 7 | // backend=stage2 | 7 | // backend=stage2 |
| 8 | // target=native | 8 | // target=native |
| 9 | // | 9 | // |
| 10 | // :2:31: error: pointer type '*i32' does not allow address zero | 10 | // :2:33: error: pointer type '*i32' does not allow address zero |
test/cases/compile_errors/int_to_err_global_invalid_number.zig+1-1| ... | @@ -5,7 +5,7 @@ const Set1 = error{ | ... | @@ -5,7 +5,7 @@ const Set1 = error{ |
| 5 | comptime { | 5 | comptime { |
| 6 | var x: u16 = 3; | 6 | var x: u16 = 3; |
| 7 | var y = @errorFromInt(x); | 7 | var y = @errorFromInt(x); |
| 8 | _ = y; | 8 | _ = .{ &x, &y }; |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | // error | 11 | // error |
test/cases/compile_errors/int_to_err_non_global_invalid_number.zig+3-3| ... | @@ -7,8 +7,8 @@ const Set2 = error{ | ... | @@ -7,8 +7,8 @@ const Set2 = error{ |
| 7 | C, | 7 | C, |
| 8 | }; | 8 | }; |
| 9 | comptime { | 9 | comptime { |
| 10 | var x = @intFromError(Set1.B); | 10 | const x = @intFromError(Set1.B); |
| 11 | var y: Set2 = @errorCast(@errorFromInt(x)); | 11 | const y: Set2 = @errorCast(@errorFromInt(x)); |
| 12 | _ = y; | 12 | _ = y; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| ... | @@ -16,4 +16,4 @@ comptime { | ... | @@ -16,4 +16,4 @@ comptime { |
| 16 | // backend=llvm | 16 | // backend=llvm |
| 17 | // target=native | 17 | // target=native |
| 18 | // | 18 | // |
| 19 | // :11:19: error: 'error.B' not a member of error set 'error{C,A}' | 19 | // :11:21: error: 'error.B' not a member of error set 'error{C,A}' |
test/cases/compile_errors/integer_cast_truncates_bits.zig+2-2| ... | @@ -11,12 +11,12 @@ export fn entry2() void { | ... | @@ -11,12 +11,12 @@ export fn entry2() void { |
| 11 | export fn entry3() void { | 11 | export fn entry3() void { |
| 12 | var spartan_count: u16 = 300; | 12 | var spartan_count: u16 = 300; |
| 13 | var byte: u8 = spartan_count; | 13 | var byte: u8 = spartan_count; |
| 14 | _ = byte; | 14 | _ = .{ &spartan_count, &byte }; |
| 15 | } | 15 | } |
| 16 | export fn entry4() void { | 16 | export fn entry4() void { |
| 17 | var signed: i8 = -1; | 17 | var signed: i8 = -1; |
| 18 | var unsigned: u64 = signed; | 18 | var unsigned: u64 = signed; |
| 19 | _ = unsigned; | 19 | _ = .{ &signed, &unsigned }; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | // error | 22 | // error |
test/cases/compile_errors/invalid_compare_string.zig+4-4| ... | @@ -1,20 +1,20 @@ | ... | @@ -1,20 +1,20 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a = "foo"; | 2 | const a = "foo"; |
| 3 | if (a == "foo") unreachable; | 3 | if (a == "foo") unreachable; |
| 4 | } | 4 | } |
| 5 | comptime { | 5 | comptime { |
| 6 | var a = "foo"; | 6 | const a = "foo"; |
| 7 | if (a == ("foo")) unreachable; // intentionally allow | 7 | if (a == ("foo")) unreachable; // intentionally allow |
| 8 | } | 8 | } |
| 9 | comptime { | 9 | comptime { |
| 10 | var a = "foo"; | 10 | const a = "foo"; |
| 11 | switch (a) { | 11 | switch (a) { |
| 12 | "foo" => unreachable, | 12 | "foo" => unreachable, |
| 13 | else => {}, | 13 | else => {}, |
| 14 | } | 14 | } |
| 15 | } | 15 | } |
| 16 | comptime { | 16 | comptime { |
| 17 | var a = "foo"; | 17 | const a = "foo"; |
| 18 | switch (a) { | 18 | switch (a) { |
| 19 | ("foo") => unreachable, // intentionally allow | 19 | ("foo") => unreachable, // intentionally allow |
| 20 | else => {}, | 20 | else => {}, |
test/cases/compile_errors/invalid_deref_on_switch_target.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var tile = Tile.Empty; | 2 | const tile = Tile.Empty; |
| 3 | switch (tile.*) { | 3 | switch (tile.*) { |
| 4 | Tile.Empty => {}, | 4 | Tile.Empty => {}, |
| 5 | Tile.Filled => {}, | 5 | Tile.Filled => {}, |
test/cases/compile_errors/invalid_float_casts.zig+8-4| ... | @@ -1,17 +1,21 @@ | ... | @@ -1,17 +1,21 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var a: f32 = 2; | 2 | var a: f32 = 2; |
| 3 | _ = &a; | ||
| 3 | _ = @as(comptime_float, @floatCast(a)); | 4 | _ = @as(comptime_float, @floatCast(a)); |
| 4 | } | 5 | } |
| 5 | export fn bar() void { | 6 | export fn bar() void { |
| 6 | var a: f32 = 2; | 7 | var a: f32 = 2; |
| 8 | _ = &a; | ||
| 7 | _ = @as(f32, @intFromFloat(a)); | 9 | _ = @as(f32, @intFromFloat(a)); |
| 8 | } | 10 | } |
| 9 | export fn baz() void { | 11 | export fn baz() void { |
| 10 | var a: f32 = 2; | 12 | var a: f32 = 2; |
| 13 | _ = &a; | ||
| 11 | _ = @as(f32, @floatFromInt(a)); | 14 | _ = @as(f32, @floatFromInt(a)); |
| 12 | } | 15 | } |
| 13 | export fn qux() void { | 16 | export fn qux() void { |
| 14 | var a: u32 = 2; | 17 | var a: u32 = 2; |
| 18 | _ = &a; | ||
| 15 | _ = @as(f32, @floatCast(a)); | 19 | _ = @as(f32, @floatCast(a)); |
| 16 | } | 20 | } |
| 17 | 21 | ||
| ... | @@ -19,7 +23,7 @@ export fn qux() void { | ... | @@ -19,7 +23,7 @@ export fn qux() void { |
| 19 | // backend=stage2 | 23 | // backend=stage2 |
| 20 | // target=native | 24 | // target=native |
| 21 | // | 25 | // |
| 22 | // :3:40: error: unable to cast runtime value to 'comptime_float' | 26 | // :4:40: error: unable to cast runtime value to 'comptime_float' |
| 23 | // :7:18: error: expected integer type, found 'f32' | 27 | // :9:18: error: expected integer type, found 'f32' |
| 24 | // :11:32: error: expected integer type, found 'f32' | 28 | // :14:32: error: expected integer type, found 'f32' |
| 25 | // :15:29: error: expected float or vector type, found 'u32' | 29 | // :19:29: error: expected float or vector type, found 'u32' |
test/cases/compile_errors/invalid_inline_else_type.zig+6-3| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub export fn entry1() void { | 1 | pub export fn entry1() void { |
| 2 | var a: anyerror = undefined; | 2 | var a: anyerror = undefined; |
| 3 | _ = &a; | ||
| 3 | switch (a) { | 4 | switch (a) { |
| 4 | inline else => {}, | 5 | inline else => {}, |
| 5 | } | 6 | } |
| ... | @@ -7,12 +8,14 @@ pub export fn entry1() void { | ... | @@ -7,12 +8,14 @@ pub export fn entry1() void { |
| 7 | const E = enum(u8) { a, _ }; | 8 | const E = enum(u8) { a, _ }; |
| 8 | pub export fn entry2() void { | 9 | pub export fn entry2() void { |
| 9 | var a: E = undefined; | 10 | var a: E = undefined; |
| 11 | _ = &a; | ||
| 10 | switch (a) { | 12 | switch (a) { |
| 11 | inline else => {}, | 13 | inline else => {}, |
| 12 | } | 14 | } |
| 13 | } | 15 | } |
| 14 | pub export fn entry3() void { | 16 | pub export fn entry3() void { |
| 15 | var a: *u32 = undefined; | 17 | var a: *u32 = undefined; |
| 18 | _ = &a; | ||
| 16 | switch (a) { | 19 | switch (a) { |
| 17 | inline else => {}, | 20 | inline else => {}, |
| 18 | } | 21 | } |
| ... | @@ -22,6 +25,6 @@ pub export fn entry3() void { | ... | @@ -22,6 +25,6 @@ pub export fn entry3() void { |
| 22 | // backend=stage2 | 25 | // backend=stage2 |
| 23 | // target=native | 26 | // target=native |
| 24 | // | 27 | // |
| 25 | // :4:21: error: cannot enumerate values of type 'anyerror' for 'inline else' | 28 | // :5:21: error: cannot enumerate values of type 'anyerror' for 'inline else' |
| 26 | // :11:21: error: cannot enumerate values of type 'tmp.E' for 'inline else' | 29 | // :13:21: error: cannot enumerate values of type 'tmp.E' for 'inline else' |
| 27 | // :17:21: error: cannot enumerate values of type '*u32' for 'inline else' | 30 | // :20:21: error: cannot enumerate values of type '*u32' for 'inline else' |
test/cases/compile_errors/invalid_int_casts.zig+8-4| ... | @@ -1,17 +1,21 @@ | ... | @@ -1,17 +1,21 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var a: u32 = 2; | 2 | var a: u32 = 2; |
| 3 | _ = &a; | ||
| 3 | _ = @as(comptime_int, @intCast(a)); | 4 | _ = @as(comptime_int, @intCast(a)); |
| 4 | } | 5 | } |
| 5 | export fn bar() void { | 6 | export fn bar() void { |
| 6 | var a: u32 = 2; | 7 | var a: u32 = 2; |
| 8 | _ = &a; | ||
| 7 | _ = @as(u32, @floatFromInt(a)); | 9 | _ = @as(u32, @floatFromInt(a)); |
| 8 | } | 10 | } |
| 9 | export fn baz() void { | 11 | export fn baz() void { |
| 10 | var a: u32 = 2; | 12 | var a: u32 = 2; |
| 13 | _ = &a; | ||
| 11 | _ = @as(u32, @intFromFloat(a)); | 14 | _ = @as(u32, @intFromFloat(a)); |
| 12 | } | 15 | } |
| 13 | export fn qux() void { | 16 | export fn qux() void { |
| 14 | var a: f32 = 2; | 17 | var a: f32 = 2; |
| 18 | _ = &a; | ||
| 15 | _ = @as(u32, @intCast(a)); | 19 | _ = @as(u32, @intCast(a)); |
| 16 | } | 20 | } |
| 17 | 21 | ||
| ... | @@ -19,7 +23,7 @@ export fn qux() void { | ... | @@ -19,7 +23,7 @@ export fn qux() void { |
| 19 | // backend=stage2 | 23 | // backend=stage2 |
| 20 | // target=native | 24 | // target=native |
| 21 | // | 25 | // |
| 22 | // :3:36: error: unable to cast runtime value to 'comptime_int' | 26 | // :4:36: error: unable to cast runtime value to 'comptime_int' |
| 23 | // :7:18: error: expected float type, found 'u32' | 27 | // :9:18: error: expected float type, found 'u32' |
| 24 | // :11:32: error: expected float type, found 'u32' | 28 | // :14:32: error: expected float type, found 'u32' |
| 25 | // :15:27: error: expected integer or vector, found 'f32' | 29 | // :19:27: error: expected integer or vector, found 'f32' |
test/cases/compile_errors/invalid_multiple_dereferences.zig+5-4| ... | @@ -1,11 +1,12 @@ | ... | @@ -1,11 +1,12 @@ |
| 1 | export fn a() void { | 1 | export fn a() void { |
| 2 | var box = Box{ .field = 0 }; | 2 | var box = Box{ .field = 0 }; |
| 3 | _ = &box; | ||
| 3 | box.*.field = 1; | 4 | box.*.field = 1; |
| 4 | } | 5 | } |
| 5 | export fn b() void { | 6 | export fn b() void { |
| 6 | var box = Box{ .field = 0 }; | 7 | var box = Box{ .field = 0 }; |
| 7 | var boxPtr = &box; | 8 | const box_ptr = &box; |
| 8 | boxPtr.*.*.field = 1; | 9 | box_ptr.*.*.field = 1; |
| 9 | } | 10 | } |
| 10 | pub const Box = struct { | 11 | pub const Box = struct { |
| 11 | field: i32, | 12 | field: i32, |
| ... | @@ -15,5 +16,5 @@ pub const Box = struct { | ... | @@ -15,5 +16,5 @@ pub const Box = struct { |
| 15 | // backend=stage2 | 16 | // backend=stage2 |
| 16 | // target=native | 17 | // target=native |
| 17 | // | 18 | // |
| 18 | // :3:8: error: cannot dereference non-pointer type 'tmp.Box' | 19 | // :4:8: error: cannot dereference non-pointer type 'tmp.Box' |
| 19 | // :8:13: error: cannot dereference non-pointer type 'tmp.Box' | 20 | // :9:14: error: cannot dereference non-pointer type 'tmp.Box' |
test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig+2-2| ... | @@ -10,12 +10,12 @@ const U = union(E) { | ... | @@ -10,12 +10,12 @@ const U = union(E) { |
| 10 | export fn foo() void { | 10 | export fn foo() void { |
| 11 | var e: E = @enumFromInt(15); | 11 | var e: E = @enumFromInt(15); |
| 12 | var u: U = e; | 12 | var u: U = e; |
| 13 | _ = u; | 13 | _ = .{ &e, &u }; |
| 14 | } | 14 | } |
| 15 | export fn bar() void { | 15 | export fn bar() void { |
| 16 | const e: E = @enumFromInt(15); | 16 | const e: E = @enumFromInt(15); |
| 17 | var u: U = e; | 17 | var u: U = e; |
| 18 | _ = u; | 18 | _ = &u; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | // error | 21 | // error |
test/cases/compile_errors/invalid_peer_type_resolution.zig+20-18| ... | @@ -1,11 +1,13 @@ | ... | @@ -1,11 +1,13 @@ |
| 1 | export fn optionalVector() void { | 1 | export fn optionalVector() void { |
| 2 | var x: ?@Vector(10, i32) = undefined; | 2 | var x: ?@Vector(10, i32) = undefined; |
| 3 | var y: @Vector(11, i32) = undefined; | 3 | var y: @Vector(11, i32) = undefined; |
| 4 | _ = .{ &x, &y }; | ||
| 4 | _ = @TypeOf(x, y); | 5 | _ = @TypeOf(x, y); |
| 5 | } | 6 | } |
| 6 | export fn badTupleField() void { | 7 | export fn badTupleField() void { |
| 7 | var x = .{ @as(u8, 0), @as(u32, 1) }; | 8 | var x = .{ @as(u8, 0), @as(u32, 1) }; |
| 8 | var y = .{ @as(u8, 1), "hello" }; | 9 | var y = .{ @as(u8, 1), "hello" }; |
| 10 | _ = .{ &x, &y }; | ||
| 9 | _ = @TypeOf(x, y); | 11 | _ = @TypeOf(x, y); |
| 10 | } | 12 | } |
| 11 | export fn badNestedField() void { | 13 | export fn badNestedField() void { |
| ... | @@ -30,21 +32,21 @@ export fn incompatiblePointers4() void { | ... | @@ -30,21 +32,21 @@ export fn incompatiblePointers4() void { |
| 30 | // backend=llvm | 32 | // backend=llvm |
| 31 | // target=native | 33 | // target=native |
| 32 | // | 34 | // |
| 33 | // :4:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)' | 35 | // :5:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)' |
| 34 | // :4:17: note: type '?@Vector(10, i32)' here | 36 | // :5:17: note: type '?@Vector(10, i32)' here |
| 35 | // :4:20: note: type '@Vector(11, i32)' here | 37 | // :5:20: note: type '@Vector(11, i32)' here |
| 36 | // :9:9: error: struct field '1' has conflicting types | 38 | // :11:9: error: struct field '1' has conflicting types |
| 37 | // :9:9: note: incompatible types: 'u32' and '*const [5:0]u8' | 39 | // :11:9: note: incompatible types: 'u32' and '*const [5:0]u8' |
| 38 | // :9:17: note: type 'u32' here | 40 | // :11:17: note: type 'u32' here |
| 39 | // :9:20: note: type '*const [5:0]u8' here | 41 | // :11:20: note: type '*const [5:0]u8' here |
| 40 | // :14:9: error: struct field 'bar' has conflicting types | 42 | // :16:9: error: struct field 'bar' has conflicting types |
| 41 | // :14:9: note: struct field '1' has conflicting types | 43 | // :16:9: note: struct field '1' has conflicting types |
| 42 | // :14:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8' | 44 | // :16:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8' |
| 43 | // :14:17: note: type 'comptime_int' here | 45 | // :16:17: note: type 'comptime_int' here |
| 44 | // :14:20: note: type '*const [2:0]u8' here | 46 | // :16:20: note: type '*const [2:0]u8' here |
| 45 | // :19:9: error: incompatible types: '[]const u8' and '[*:0]const u8' | 47 | // :21:9: error: incompatible types: '[]const u8' and '[*:0]const u8' |
| 46 | // :19:17: note: type '[]const u8' here | 48 | // :21:17: note: type '[]const u8' here |
| 47 | // :19:20: note: type '[*:0]const u8' here | 49 | // :21:20: note: type '[*:0]const u8' here |
| 48 | // :26:9: error: incompatible types: '[]const u8' and '[*]const u8' | 50 | // :28:9: error: incompatible types: '[]const u8' and '[*]const u8' |
| 49 | // :26:23: note: type '[]const u8' here | 51 | // :28:23: note: type '[]const u8' here |
| 50 | // :26:26: note: type '[*]const u8' here | 52 | // :28:26: note: type '[*]const u8' here |
test/cases/compile_errors/invalid_store_to_comptime_field.zig+13-11| ... | @@ -17,8 +17,9 @@ pub export fn entry2() void { | ... | @@ -17,8 +17,9 @@ pub export fn entry2() void { |
| 17 | var list = .{ 1, 2, 3 }; | 17 | var list = .{ 1, 2, 3 }; |
| 18 | var list2 = @TypeOf(list){ .@"0" = 1, .@"1" = 2, .@"2" = 3 }; | 18 | var list2 = @TypeOf(list){ .@"0" = 1, .@"1" = 2, .@"2" = 3 }; |
| 19 | var list3 = @TypeOf(list){ 1, 2, 4 }; | 19 | var list3 = @TypeOf(list){ 1, 2, 4 }; |
| 20 | _ = list2; | 20 | _ = &list; |
| 21 | _ = list3; | 21 | _ = &list2; |
| 22 | _ = &list3; | ||
| 22 | } | 23 | } |
| 23 | pub export fn entry3() void { | 24 | pub export fn entry3() void { |
| 24 | const U = struct { | 25 | const U = struct { |
| ... | @@ -46,6 +47,7 @@ pub export fn entry5() void { | ... | @@ -46,6 +47,7 @@ pub export fn entry5() void { |
| 46 | } | 47 | } |
| 47 | pub export fn entry6() void { | 48 | pub export fn entry6() void { |
| 48 | var x: u32 = 15; | 49 | var x: u32 = 15; |
| 50 | _ = &x; | ||
| 49 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); | 51 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); |
| 50 | const S = struct { | 52 | const S = struct { |
| 51 | fn foo(_: T) void {} | 53 | fn foo(_: T) void {} |
| ... | @@ -74,12 +76,12 @@ pub export fn entry8() void { | ... | @@ -74,12 +76,12 @@ pub export fn entry8() void { |
| 74 | // :6:9: error: value stored in comptime field does not match the default value of the field | 76 | // :6:9: error: value stored in comptime field does not match the default value of the field |
| 75 | // :14:9: error: value stored in comptime field does not match the default value of the field | 77 | // :14:9: error: value stored in comptime field does not match the default value of the field |
| 76 | // :19:38: error: value stored in comptime field does not match the default value of the field | 78 | // :19:38: error: value stored in comptime field does not match the default value of the field |
| 77 | // :31:19: error: value stored in comptime field does not match the default value of the field | 79 | // :32:19: error: value stored in comptime field does not match the default value of the field |
| 78 | // :25:29: note: default value set here | 80 | // :26:29: note: default value set here |
| 79 | // :41:19: error: value stored in comptime field does not match the default value of the field | 81 | // :42:19: error: value stored in comptime field does not match the default value of the field |
| 80 | // :35:29: note: default value set here | 82 | // :36:29: note: default value set here |
| 81 | // :45:12: error: value stored in comptime field does not match the default value of the field | 83 | // :46:12: error: value stored in comptime field does not match the default value of the field |
| 82 | // :53:25: error: value stored in comptime field does not match the default value of the field | 84 | // :55:25: error: value stored in comptime field does not match the default value of the field |
| 83 | // :66:36: error: value stored in comptime field does not match the default value of the field | 85 | // :68:36: error: value stored in comptime field does not match the default value of the field |
| 84 | // :59:30: error: value stored in comptime field does not match the default value of the field | 86 | // :61:30: error: value stored in comptime field does not match the default value of the field |
| 85 | // :57:29: note: default value set here | 87 | // :59:29: note: default value set here |
test/cases/compile_errors/invalid_struct_field.zig+3-2| ... | @@ -8,6 +8,7 @@ export fn f() void { | ... | @@ -8,6 +8,7 @@ export fn f() void { |
| 8 | export fn g() void { | 8 | export fn g() void { |
| 9 | var a: A = undefined; | 9 | var a: A = undefined; |
| 10 | const y = a.bar; | 10 | const y = a.bar; |
| 11 | _ = &a; | ||
| 11 | _ = y; | 12 | _ = y; |
| 12 | } | 13 | } |
| 13 | export fn e() void { | 14 | export fn e() void { |
| ... | @@ -26,5 +27,5 @@ export fn e() void { | ... | @@ -26,5 +27,5 @@ export fn e() void { |
| 26 | // :1:11: note: struct declared here | 27 | // :1:11: note: struct declared here |
| 27 | // :10:17: error: no field named 'bar' in struct 'tmp.A' | 28 | // :10:17: error: no field named 'bar' in struct 'tmp.A' |
| 28 | // :1:11: note: struct declared here | 29 | // :1:11: note: struct declared here |
| 29 | // :18:45: error: no field named 'f' in struct 'tmp.e.B' | 30 | // :19:45: error: no field named 'f' in struct 'tmp.e.B' |
| 30 | // :14:15: note: struct declared here | 31 | // :15:15: note: struct declared here |
test/cases/compile_errors/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig+2-2| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var foo: u32 = @This(){}; | 2 | const foo: u32 = @This(){}; |
| 3 | _ = foo; | 3 | _ = foo; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| ... | @@ -7,5 +7,5 @@ export fn entry() void { | ... | @@ -7,5 +7,5 @@ export fn entry() void { |
| 7 | // backend=stage2 | 7 | // backend=stage2 |
| 8 | // target=native | 8 | // target=native |
| 9 | // | 9 | // |
| 10 | // :2:27: error: expected type 'u32', found 'tmp' | 10 | // :2:29: error: expected type 'u32', found 'tmp' |
| 11 | // :1:1: note: struct declared here | 11 | // :1:1: note: struct declared here |
test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig+1-1| ... | @@ -4,7 +4,7 @@ export fn foo1() void { | ... | @@ -4,7 +4,7 @@ export fn foo1() void { |
| 4 | _ = word; | 4 | _ = word; |
| 5 | } | 5 | } |
| 6 | export fn foo2() void { | 6 | export fn foo2() void { |
| 7 | var bytes: []const u8 = &[_]u8{ 1, 2 }; | 7 | const bytes: []const u8 = &[_]u8{ 1, 2 }; |
| 8 | const word: u16 = @bitCast(bytes); | 8 | const word: u16 = @bitCast(bytes); |
| 9 | _ = word; | 9 | _ = word; |
| 10 | } | 10 | } |
test/cases/compile_errors/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig+5-5| ... | @@ -1,14 +1,14 @@ | ... | @@ -1,14 +1,14 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var u: ?*anyopaque = null; | 2 | var u: ?*anyopaque = null; |
| 3 | var v: *anyopaque = undefined; | 3 | var v: *anyopaque = undefined; |
| 4 | v = u; | 4 | v = (&u).*; |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
| 8 | // backend=stage2 | 8 | // backend=stage2 |
| 9 | // target=native | 9 | // target=native |
| 10 | // | 10 | // |
| 11 | // :4:9: error: expected type '*anyopaque', found '?*anyopaque' | 11 | // :4:13: error: expected type '*anyopaque', found '?*anyopaque' |
| 12 | // :4:9: note: cannot convert optional to payload type | 12 | // :4:13: note: cannot convert optional to payload type |
| 13 | // :4:9: note: consider using '.?', 'orelse', or 'if' | 13 | // :4:13: note: consider using '.?', 'orelse', or 'if' |
| 14 | // :4:9: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque' | 14 | // :4:13: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque' |
test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig+2-1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | comptime var T: type = undefined; | 2 | comptime var T: type = undefined; |
| 3 | _ = &T; | ||
| 3 | const S = struct { x: *T }; | 4 | const S = struct { x: *T }; |
| 4 | const I = @typeInfo(S); | 5 | const I = @typeInfo(S); |
| 5 | _ = I; | 6 | _ = I; |
| ... | @@ -9,4 +10,4 @@ export fn foo() void { | ... | @@ -9,4 +10,4 @@ export fn foo() void { |
| 9 | // backend=stage2 | 10 | // backend=stage2 |
| 10 | // target=native | 11 | // target=native |
| 11 | // | 12 | // |
| 12 | // :3:28: error: use of undefined value here causes undefined behavior | 13 | // :4:28: error: use of undefined value here causes undefined behavior |
test/cases/compile_errors/load_vector_pointer_with_unknown_runtime_index.zig+1-1| ... | @@ -3,7 +3,7 @@ export fn entry() void { | ... | @@ -3,7 +3,7 @@ export fn entry() void { |
| 3 | 3 | ||
| 4 | var i: u32 = 0; | 4 | var i: u32 = 0; |
| 5 | var x = loadv(&v[i]); | 5 | var x = loadv(&v[i]); |
| 6 | _ = x; | 6 | _ = .{ &i, &x }; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | fn loadv(ptr: anytype) i31 { | 9 | fn loadv(ptr: anytype) i31 { |
test/cases/compile_errors/memset_no_length.zig+6-4| ... | @@ -1,9 +1,11 @@ | ... | @@ -1,9 +1,11 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var ptr: [*]u8 = undefined; | 2 | var ptr: [*]u8 = undefined; |
| 3 | _ = &ptr; | ||
| 3 | @memset(ptr, 123); | 4 | @memset(ptr, 123); |
| 4 | } | 5 | } |
| 5 | export fn bar() void { | 6 | export fn bar() void { |
| 6 | var ptr: [*c]bool = undefined; | 7 | var ptr: [*c]bool = undefined; |
| 8 | _ = &ptr; | ||
| 7 | @memset(ptr, true); | 9 | @memset(ptr, true); |
| 8 | } | 10 | } |
| 9 | 11 | ||
| ... | @@ -11,7 +13,7 @@ export fn bar() void { | ... | @@ -11,7 +13,7 @@ export fn bar() void { |
| 11 | // backend=stage2 | 13 | // backend=stage2 |
| 12 | // target=native | 14 | // target=native |
| 13 | // | 15 | // |
| 14 | // :3:5: error: unknown @memset length | 16 | // :4:5: error: unknown @memset length |
| 15 | // :3:13: note: destination type '[*]u8' provides no length | 17 | // :4:13: note: destination type '[*]u8' provides no length |
| 16 | // :7:5: error: unknown @memset length | 18 | // :9:5: error: unknown @memset length |
| 17 | // :7:13: note: destination type '[*c]bool' provides no length | 19 | // :9:13: note: destination type '[*c]bool' provides no length |
test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig+1-1| ... | @@ -7,7 +7,7 @@ pub fn getGeo3DTex2D() Geo3DTex2D { | ... | @@ -7,7 +7,7 @@ pub fn getGeo3DTex2D() Geo3DTex2D { |
| 7 | }; | 7 | }; |
| 8 | } | 8 | } |
| 9 | export fn entry() void { | 9 | export fn entry() void { |
| 10 | var geo_data = getGeo3DTex2D(); | 10 | const geo_data = getGeo3DTex2D(); |
| 11 | _ = geo_data; | 11 | _ = geo_data; |
| 12 | } | 12 | } |
| 13 | 13 |
test/cases/compile_errors/missing_else_clause.zig+2-2| ... | @@ -14,7 +14,7 @@ fn h() void { | ... | @@ -14,7 +14,7 @@ fn h() void { |
| 14 | // https://github.com/ziglang/zig/issues/12743 | 14 | // https://github.com/ziglang/zig/issues/12743 |
| 15 | const T = struct { oh_no: *u32 }; | 15 | const T = struct { oh_no: *u32 }; |
| 16 | var x: T = if (false) {}; | 16 | var x: T = if (false) {}; |
| 17 | _ = x; | 17 | _ = &x; |
| 18 | } | 18 | } |
| 19 | fn k(b: bool) void { | 19 | fn k(b: bool) void { |
| 20 | // block_ptr case | 20 | // block_ptr case |
| ... | @@ -22,7 +22,7 @@ fn k(b: bool) void { | ... | @@ -22,7 +22,7 @@ fn k(b: bool) void { |
| 22 | var x = if (b) blk: { | 22 | var x = if (b) blk: { |
| 23 | break :blk if (false) T{ .oh_no = 2 }; | 23 | break :blk if (false) T{ .oh_no = 2 }; |
| 24 | } else T{ .oh_no = 1 }; | 24 | } else T{ .oh_no = 1 }; |
| 25 | _ = x; | 25 | _ = &x; |
| 26 | } | 26 | } |
| 27 | export fn entry() void { | 27 | export fn entry() void { |
| 28 | f(true); | 28 | f(true); |
test/cases/compile_errors/missing_parameter_name_of_generic_function.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | fn dump(anytype) void {} | 1 | fn dump(anytype) void {} |
| 2 | export fn entry() void { | 2 | export fn entry() void { |
| 3 | var a: u8 = 9; | 3 | var a: u8 = 9; |
| 4 | dump(a); | 4 | dump((&a).*); |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig+1-1| ... | @@ -24,7 +24,7 @@ pub const JsonNode = struct { | ... | @@ -24,7 +24,7 @@ pub const JsonNode = struct { |
| 24 | fn foo() void { | 24 | fn foo() void { |
| 25 | var jll: JasonList = undefined; | 25 | var jll: JasonList = undefined; |
| 26 | jll.init(1234); | 26 | jll.init(1234); |
| 27 | var jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} }; | 27 | const jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} }; |
| 28 | _ = jd; | 28 | _ = jd; |
| 29 | } | 29 | } |
| 30 | 30 |
test/cases/compile_errors/mod_on_undefined_value.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: i64 = undefined; | 2 | var a: i64 = undefined; |
| 3 | _ = a % a; | 3 | _ = a % a; |
| 4 | _ = &a; | ||
| 4 | } | 5 | } |
| 5 | 6 | ||
| 6 | // error | 7 | // error |
test/cases/compile_errors/mult_on_undefined_value.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: i64 = undefined; | 2 | const a: i64 = undefined; |
| 3 | _ = a * a; | 3 | _ = a * a; |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/negate_on_undefined_value.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: i64 = undefined; | 2 | const a: i64 = undefined; |
| 3 | _ = -a; | 3 | _ = -a; |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/nested_vectors.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | const V1 = @Vector(4, u8); | 2 | const V1 = @Vector(4, u8); |
| 3 | const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } }); | 3 | const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } }); |
| 4 | var v: V2 = undefined; | 4 | const v: V2 = undefined; |
| 5 | _ = v; | 5 | _ = v; |
| 6 | } | 6 | } |
| 7 | 7 |
test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig+7-7| ... | @@ -1,30 +1,30 @@ | ... | @@ -1,30 +1,30 @@ |
| 1 | export fn entry1() void { | 1 | export fn entry1() void { |
| 2 | var m2 = &2; | 2 | var m2 = &2; |
| 3 | _ = m2; | 3 | _ = &m2; |
| 4 | } | 4 | } |
| 5 | export fn entry2() void { | 5 | export fn entry2() void { |
| 6 | var a = undefined; | 6 | var a = undefined; |
| 7 | _ = a; | 7 | _ = &a; |
| 8 | } | 8 | } |
| 9 | export fn entry3() void { | 9 | export fn entry3() void { |
| 10 | var b = 1; | 10 | var b = 1; |
| 11 | _ = b; | 11 | _ = &b; |
| 12 | } | 12 | } |
| 13 | export fn entry4() void { | 13 | export fn entry4() void { |
| 14 | var c = 1.0; | 14 | var c = 1.0; |
| 15 | _ = c; | 15 | _ = &c; |
| 16 | } | 16 | } |
| 17 | export fn entry5() void { | 17 | export fn entry5() void { |
| 18 | var d = null; | 18 | var d = null; |
| 19 | _ = d; | 19 | _ = &d; |
| 20 | } | 20 | } |
| 21 | export fn entry6(opaque_: *Opaque) void { | 21 | export fn entry6(opaque_: *Opaque) void { |
| 22 | var e = opaque_.*; | 22 | var e = opaque_.*; |
| 23 | _ = e; | 23 | _ = &e; |
| 24 | } | 24 | } |
| 25 | export fn entry7() void { | 25 | export fn entry7() void { |
| 26 | var f = i32; | 26 | var f = i32; |
| 27 | _ = f; | 27 | _ = &f; |
| 28 | } | 28 | } |
| 29 | const Opaque = opaque {}; | 29 | const Opaque = opaque {}; |
| 30 | export fn entry8() void { | 30 | export fn entry8() void { |
test/cases/compile_errors/non-integer_tag_type_to_enum.zig+1-1| ... | @@ -3,7 +3,7 @@ const Foo = enum(f32) { | ... | @@ -3,7 +3,7 @@ const Foo = enum(f32) { |
| 3 | }; | 3 | }; |
| 4 | export fn entry() void { | 4 | export fn entry() void { |
| 5 | var f: Foo = undefined; | 5 | var f: Foo = undefined; |
| 6 | _ = f; | 6 | _ = &f; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | // error | 9 | // error |
test/cases/compile_errors/non_void_error_union_payload_ignored.zig+4-2| ... | @@ -5,6 +5,7 @@ pub export fn entry1() void { | ... | @@ -5,6 +5,7 @@ pub export fn entry1() void { |
| 5 | } else |_| { | 5 | } else |_| { |
| 6 | // bar | 6 | // bar |
| 7 | } | 7 | } |
| 8 | _ = &x; | ||
| 8 | } | 9 | } |
| 9 | pub export fn entry2() void { | 10 | pub export fn entry2() void { |
| 10 | var x: anyerror!usize = 5; | 11 | var x: anyerror!usize = 5; |
| ... | @@ -13,6 +14,7 @@ pub export fn entry2() void { | ... | @@ -13,6 +14,7 @@ pub export fn entry2() void { |
| 13 | } else |_| { | 14 | } else |_| { |
| 14 | // bar | 15 | // bar |
| 15 | } | 16 | } |
| 17 | _ = &x; | ||
| 16 | } | 18 | } |
| 17 | 19 | ||
| 18 | // error | 20 | // error |
| ... | @@ -21,5 +23,5 @@ pub export fn entry2() void { | ... | @@ -21,5 +23,5 @@ pub export fn entry2() void { |
| 21 | // | 23 | // |
| 22 | // :3:5: error: error union payload is ignored | 24 | // :3:5: error: error union payload is ignored |
| 23 | // :3:5: note: payload value can be explicitly ignored with '|_|' | 25 | // :3:5: note: payload value can be explicitly ignored with '|_|' |
| 24 | // :11:5: error: error union payload is ignored | 26 | // :12:5: error: error union payload is ignored |
| 25 | // :11:5: note: payload value can be explicitly ignored with '|_|' | 27 | // :12:5: note: payload value can be explicitly ignored with '|_|' |
test/cases/compile_errors/not_an_enum_type.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var self: Error = undefined; | 2 | var self: Error = undefined; |
| 3 | switch (self) { | 3 | switch ((&self).*) { |
| 4 | InvalidToken => |x| return x.token, | 4 | InvalidToken => |x| return x.token, |
| 5 | ExpectedVarDeclOrFn => |x| return x.token, | 5 | ExpectedVarDeclOrFn => |x| return x.token, |
| 6 | } | 6 | } |
test/cases/compile_errors/or_on_undefined_value.zig+2-1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: bool = undefined; | 2 | var a: bool = undefined; |
| 3 | _ = &a; | ||
| 3 | _ = a or a; | 4 | _ = a or a; |
| 4 | } | 5 | } |
| 5 | 6 | ||
| ... | @@ -7,4 +8,4 @@ comptime { | ... | @@ -7,4 +8,4 @@ comptime { |
| 7 | // backend=stage2 | 8 | // backend=stage2 |
| 8 | // target=native | 9 | // target=native |
| 9 | // | 10 | // |
| 10 | // :3:9: error: use of undefined value here causes undefined behavior | 11 | // :4:9: error: use of undefined value here causes undefined behavior |
test/cases/compile_errors/orelse_on_undefined_value.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: ?bool = undefined; | 2 | const a: ?bool = undefined; |
| 3 | _ = a orelse false; | 3 | _ = a orelse false; |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/out_of_bounds_index.zig+8-8| ... | @@ -1,29 +1,29 @@ | ... | @@ -1,29 +1,29 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var array = [_:0]u8{ 1, 2, 3, 4 }; | 2 | var array = [_:0]u8{ 1, 2, 3, 4 }; |
| 3 | var src_slice: [:0]u8 = &array; | 3 | var src_slice: [:0]u8 = &array; |
| 4 | var slice = src_slice[2..6]; | 4 | const slice = src_slice[2..6]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | comptime { | 7 | comptime { |
| 8 | var array = [_:0]u8{ 1, 2, 3, 4 }; | 8 | var array = [_:0]u8{ 1, 2, 3, 4 }; |
| 9 | var slice = array[2..6]; | 9 | const slice = array[2..6]; |
| 10 | _ = slice; | 10 | _ = slice; |
| 11 | } | 11 | } |
| 12 | comptime { | 12 | comptime { |
| 13 | var array = [_]u8{ 1, 2, 3, 4 }; | 13 | var array = [_]u8{ 1, 2, 3, 4 }; |
| 14 | var slice = array[2..5]; | 14 | const slice = array[2..5]; |
| 15 | _ = slice; | 15 | _ = slice; |
| 16 | } | 16 | } |
| 17 | comptime { | 17 | comptime { |
| 18 | var array = [_:0]u8{ 1, 2, 3, 4 }; | 18 | var array = [_:0]u8{ 1, 2, 3, 4 }; |
| 19 | var slice = array[3..2]; | 19 | const slice = array[3..2]; |
| 20 | _ = slice; | 20 | _ = slice; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | // error | 23 | // error |
| 24 | // target=native | 24 | // target=native |
| 25 | // | 25 | // |
| 26 | // :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) | 26 | // :4:32: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) |
| 27 | // :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel) | 27 | // :9:28: error: end index 6 out of bounds for array of length 4 +1 (sentinel) |
| 28 | // :14:26: error: end index 5 out of bounds for array of length 4 | 28 | // :14:28: error: end index 5 out of bounds for array of length 4 |
| 29 | // :19:23: error: start index 3 is larger than end index 2 | 29 | // :19:25: error: start index 3 is larger than end index 2 |
test/cases/compile_errors/overflow_in_enum_value_allocation.zig+1-1| ... | @@ -3,7 +3,7 @@ const Moo = enum(u8) { | ... | @@ -3,7 +3,7 @@ const Moo = enum(u8) { |
| 3 | Over, | 3 | Over, |
| 4 | }; | 4 | }; |
| 5 | pub export fn entry() void { | 5 | pub export fn entry() void { |
| 6 | var y = Moo.Last; | 6 | const y = Moo.Last; |
| 7 | _ = y; | 7 | _ = y; |
| 8 | } | 8 | } |
| 9 | 9 |
test/cases/compile_errors/packed_union_given_enum_tag_type.zig+1-1| ... | @@ -9,7 +9,7 @@ const Payload = packed union(Letter) { | ... | @@ -9,7 +9,7 @@ const Payload = packed union(Letter) { |
| 9 | C: bool, | 9 | C: bool, |
| 10 | }; | 10 | }; |
| 11 | export fn entry() void { | 11 | export fn entry() void { |
| 12 | var a = Payload{ .A = 1234 }; | 12 | const a: Payload = .{ .A = 1234 }; |
| 13 | _ = a; | 13 | _ = a; |
| 14 | } | 14 | } |
| 15 | 15 |
test/cases/compile_errors/packed_union_with_automatic_layout_field.zig+1-1| ... | @@ -7,7 +7,7 @@ const Payload = packed union { | ... | @@ -7,7 +7,7 @@ const Payload = packed union { |
| 7 | B: bool, | 7 | B: bool, |
| 8 | }; | 8 | }; |
| 9 | export fn entry() void { | 9 | export fn entry() void { |
| 10 | var a = Payload{ .B = true }; | 10 | const a: Payload = .{ .B = true }; |
| 11 | _ = a; | 11 | _ = a; |
| 12 | } | 12 | } |
| 13 | 13 |
test/cases/compile_errors/pointer_arithmetic_on_pointer-to-array.zig+5-5| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var x: [10]u8 = undefined; | 2 | var x: [10]u8 = undefined; |
| 3 | var y = &x; | 3 | const y = &x; |
| 4 | var z = y + 1; | 4 | const z = y + 1; |
| 5 | _ = z; | 5 | _ = z; |
| 6 | } | 6 | } |
| 7 | 7 | ||
| ... | @@ -9,6 +9,6 @@ export fn foo() void { | ... | @@ -9,6 +9,6 @@ export fn foo() void { |
| 9 | // backend=stage2 | 9 | // backend=stage2 |
| 10 | // target=native | 10 | // target=native |
| 11 | // | 11 | // |
| 12 | // :4:15: error: incompatible types: '*[10]u8' and 'comptime_int' | 12 | // :4:17: error: incompatible types: '*[10]u8' and 'comptime_int' |
| 13 | // :4:13: note: type '*[10]u8' here | 13 | // :4:15: note: type '*[10]u8' here |
| 14 | // :4:17: note: type 'comptime_int' here | 14 | // :4:19: note: type 'comptime_int' here |
test/cases/compile_errors/pointer_to_anyopaque_slice.zig+1| ... | @@ -2,6 +2,7 @@ export fn x() void { | ... | @@ -2,6 +2,7 @@ export fn x() void { |
| 2 | var a: *u32 = undefined; | 2 | var a: *u32 = undefined; |
| 3 | var b: []anyopaque = undefined; | 3 | var b: []anyopaque = undefined; |
| 4 | b = a; | 4 | b = a; |
| 5 | _ = &a; | ||
| 5 | } | 6 | } |
| 6 | 7 | ||
| 7 | // error | 8 | // error |
test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | var y: [*]align(4) u8 = @ptrFromInt(5); | 2 | var y: [*]align(4) u8 = @ptrFromInt(5); |
| 3 | _ = y; | 3 | _ = &y; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| 6 | // error | 6 | // error |
test/cases/compile_errors/recursive_inline_fn.zig+2-1| ... | @@ -8,6 +8,7 @@ inline fn foo(x: i32) i32 { | ... | @@ -8,6 +8,7 @@ inline fn foo(x: i32) i32 { |
| 8 | 8 | ||
| 9 | pub export fn entry() void { | 9 | pub export fn entry() void { |
| 10 | var x: i32 = 4; | 10 | var x: i32 = 4; |
| 11 | _ = &x; | ||
| 11 | _ = foo(x) == 20; | 12 | _ = foo(x) == 20; |
| 12 | } | 13 | } |
| 13 | 14 | ||
| ... | @@ -32,4 +33,4 @@ pub export fn entry2() void { | ... | @@ -32,4 +33,4 @@ pub export fn entry2() void { |
| 32 | // target=native | 33 | // target=native |
| 33 | // | 34 | // |
| 34 | // :5:27: error: inline call is recursive | 35 | // :5:27: error: inline call is recursive |
| 35 | // :23:10: error: inline call is recursive | 36 | // :24:10: error: inline call is recursive |
test/cases/compile_errors/reference_to_const_data.zig+6-3| ... | @@ -5,10 +5,12 @@ export fn foo() void { | ... | @@ -5,10 +5,12 @@ export fn foo() void { |
| 5 | export fn bar() void { | 5 | export fn bar() void { |
| 6 | var ptr = &@as(u32, 2); | 6 | var ptr = &@as(u32, 2); |
| 7 | ptr.* = 2; | 7 | ptr.* = 2; |
| 8 | _ = &ptr; | ||
| 8 | } | 9 | } |
| 9 | export fn baz() void { | 10 | export fn baz() void { |
| 10 | var ptr = &true; | 11 | var ptr = &true; |
| 11 | ptr.* = false; | 12 | ptr.* = false; |
| 13 | _ = &ptr; | ||
| 12 | } | 14 | } |
| 13 | export fn qux() void { | 15 | export fn qux() void { |
| 14 | const S = struct { | 16 | const S = struct { |
| ... | @@ -21,6 +23,7 @@ export fn qux() void { | ... | @@ -21,6 +23,7 @@ export fn qux() void { |
| 21 | export fn quux() void { | 23 | export fn quux() void { |
| 22 | var x = &@returnAddress(); | 24 | var x = &@returnAddress(); |
| 23 | x.* = 6; | 25 | x.* = 6; |
| 26 | _ = &x; | ||
| 24 | } | 27 | } |
| 25 | 28 | ||
| 26 | // error | 29 | // error |
| ... | @@ -29,6 +32,6 @@ export fn quux() void { | ... | @@ -29,6 +32,6 @@ export fn quux() void { |
| 29 | // | 32 | // |
| 30 | // :3:8: error: cannot assign to constant | 33 | // :3:8: error: cannot assign to constant |
| 31 | // :7:8: error: cannot assign to constant | 34 | // :7:8: error: cannot assign to constant |
| 32 | // :11:8: error: cannot assign to constant | 35 | // :12:8: error: cannot assign to constant |
| 33 | // :19:8: error: cannot assign to constant | 36 | // :21:8: error: cannot assign to constant |
| 34 | // :23:6: error: cannot assign to constant | 37 | // :25:6: error: cannot assign to constant |
test/cases/compile_errors/reify_typeOf_with_incompatible_arguments.zig+1| ... | @@ -2,6 +2,7 @@ export fn entry() void { | ... | @@ -2,6 +2,7 @@ export fn entry() void { |
| 2 | var var_1: f32 = undefined; | 2 | var var_1: f32 = undefined; |
| 3 | var var_2: u32 = undefined; | 3 | var var_2: u32 = undefined; |
| 4 | _ = @TypeOf(var_1, var_2); | 4 | _ = @TypeOf(var_1, var_2); |
| 5 | _ = .{ &var_1, &var_2 }; | ||
| 5 | } | 6 | } |
| 6 | 7 | ||
| 7 | // error | 8 | // error |
test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var damn = Container{ | 2 | const damn = Container{ |
| 3 | .not_optional = getOptional(), | 3 | .not_optional = getOptional(), |
| 4 | }; | 4 | }; |
| 5 | _ = damn; | 5 | _ = damn; |
test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig+1-1| ... | @@ -2,7 +2,7 @@ export fn entry() void { | ... | @@ -2,7 +2,7 @@ export fn entry() void { |
| 2 | var damn = Container{ | 2 | var damn = Container{ |
| 3 | .not_optional = getOptional(i32), | 3 | .not_optional = getOptional(i32), |
| 4 | }; | 4 | }; |
| 5 | _ = damn; | 5 | _ = &damn; |
| 6 | } | 6 | } |
| 7 | pub fn getOptional(comptime T: type) ?T { | 7 | pub fn getOptional(comptime T: type) ?T { |
| 8 | return 0; | 8 | return 0; |
test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig+1| ... | @@ -5,6 +5,7 @@ const Foo = struct { | ... | @@ -5,6 +5,7 @@ const Foo = struct { |
| 5 | export fn f() void { | 5 | export fn f() void { |
| 6 | var x: u8 = 0; | 6 | var x: u8 = 0; |
| 7 | const foo = Foo{ .Bar = x, .Baz = u8 }; | 7 | const foo = Foo{ .Bar = x, .Baz = u8 }; |
| 8 | _ = &x; | ||
| 8 | _ = foo; | 9 | _ = foo; |
| 9 | } | 10 | } |
| 10 | 11 |
test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig+3-2| ... | @@ -4,6 +4,7 @@ const Foo = union { | ... | @@ -4,6 +4,7 @@ const Foo = union { |
| 4 | }; | 4 | }; |
| 5 | export fn f() void { | 5 | export fn f() void { |
| 6 | var x: u8 = 0; | 6 | var x: u8 = 0; |
| 7 | _ = &x; | ||
| 7 | const foo = Foo{ .Bar = x }; | 8 | const foo = Foo{ .Bar = x }; |
| 8 | _ = foo; | 9 | _ = foo; |
| 9 | } | 10 | } |
| ... | @@ -12,5 +13,5 @@ export fn f() void { | ... | @@ -12,5 +13,5 @@ export fn f() void { |
| 12 | // backend=stage2 | 13 | // backend=stage2 |
| 13 | // target=native | 14 | // target=native |
| 14 | // | 15 | // |
| 15 | // :7:23: error: unable to resolve comptime value | 16 | // :8:23: error: unable to resolve comptime value |
| 16 | // :7:23: note: initializer of comptime only union must be comptime-known | 17 | // :8:23: note: initializer of comptime only union must be comptime-known |
test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig+2-2| ... | @@ -8,7 +8,7 @@ export fn entry() void { | ... | @@ -8,7 +8,7 @@ export fn entry() void { |
| 8 | foo(Letter.A); | 8 | foo(Letter.A); |
| 9 | } | 9 | } |
| 10 | fn foo(l: Letter) void { | 10 | fn foo(l: Letter) void { |
| 11 | var x: Value = l; | 11 | const x: Value = l; |
| 12 | _ = x; | 12 | _ = x; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| ... | @@ -16,6 +16,6 @@ fn foo(l: Letter) void { | ... | @@ -16,6 +16,6 @@ fn foo(l: Letter) void { |
| 16 | // backend=stage2 | 16 | // backend=stage2 |
| 17 | // target=native | 17 | // target=native |
| 18 | // | 18 | // |
| 19 | // :11:20: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields | 19 | // :11:22: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields |
| 20 | // :3:5: note: field 'A' has type 'i32' | 20 | // :3:5: note: field 'A' has type 'i32' |
| 21 | // :2:15: note: union declared here | 21 | // :2:15: note: union declared here |
test/cases/compile_errors/runtime_indexing_comptime_array.zig+4-2| ... | @@ -13,12 +13,14 @@ pub export fn entry2() void { | ... | @@ -13,12 +13,14 @@ pub export fn entry2() void { |
| 13 | const test_fns = [_]TestFn{ foo, bar }; | 13 | const test_fns = [_]TestFn{ foo, bar }; |
| 14 | var i: usize = 0; | 14 | var i: usize = 0; |
| 15 | _ = test_fns[i]; | 15 | _ = test_fns[i]; |
| 16 | _ = &i; | ||
| 16 | } | 17 | } |
| 17 | pub export fn entry3() void { | 18 | pub export fn entry3() void { |
| 18 | const TestFn = fn () void; | 19 | const TestFn = fn () void; |
| 19 | const test_fns = [_]TestFn{ foo, bar }; | 20 | const test_fns = [_]TestFn{ foo, bar }; |
| 20 | var i: usize = 0; | 21 | var i: usize = 0; |
| 21 | _ = &test_fns[i]; | 22 | _ = &test_fns[i]; |
| 23 | _ = &i; | ||
| 22 | } | 24 | } |
| 23 | // error | 25 | // error |
| 24 | // target=native | 26 | // target=native |
| ... | @@ -28,5 +30,5 @@ pub export fn entry3() void { | ... | @@ -28,5 +30,5 @@ pub export fn entry3() void { |
| 28 | // :7:10: note: use '*const fn () void' for a function pointer type | 30 | // :7:10: note: use '*const fn () void' for a function pointer type |
| 29 | // :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known | 31 | // :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known |
| 30 | // :15:17: note: use '*const fn () void' for a function pointer type | 32 | // :15:17: note: use '*const fn () void' for a function pointer type |
| 31 | // :21:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known | 33 | // :22:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known |
| 32 | // :21:18: note: use '*const fn () void' for a function pointer type | 34 | // :22:18: note: use '*const fn () void' for a function pointer type |
test/cases/compile_errors/runtime_to_comptime_num.zig+12-8| ... | @@ -1,19 +1,23 @@ | ... | @@ -1,19 +1,23 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | var a: u32 = 0; | 2 | var a: u32 = 0; |
| 3 | _ = &a; | ||
| 3 | _ = @as(comptime_int, a); | 4 | _ = @as(comptime_int, a); |
| 4 | } | 5 | } |
| 5 | pub export fn entry2() void { | 6 | pub export fn entry2() void { |
| 6 | var a: u32 = 0; | 7 | var a: u32 = 0; |
| 8 | _ = &a; | ||
| 7 | _ = @as(comptime_float, a); | 9 | _ = @as(comptime_float, a); |
| 8 | } | 10 | } |
| 9 | pub export fn entry3() void { | 11 | pub export fn entry3() void { |
| 10 | comptime var aa: comptime_float = 0.0; | 12 | comptime var aa: comptime_float = 0.0; |
| 11 | var a: f32 = 4; | 13 | var a: f32 = 4; |
| 14 | _ = &a; | ||
| 12 | aa = a; | 15 | aa = a; |
| 13 | } | 16 | } |
| 14 | pub export fn entry4() void { | 17 | pub export fn entry4() void { |
| 15 | comptime var aa: comptime_int = 0.0; | 18 | comptime var aa: comptime_int = 0.0; |
| 16 | var a: f32 = 4; | 19 | var a: f32 = 4; |
| 20 | _ = &a; | ||
| 17 | aa = a; | 21 | aa = a; |
| 18 | } | 22 | } |
| 19 | 23 | ||
| ... | @@ -21,11 +25,11 @@ pub export fn entry4() void { | ... | @@ -21,11 +25,11 @@ pub export fn entry4() void { |
| 21 | // backend=stage2 | 25 | // backend=stage2 |
| 22 | // target=native | 26 | // target=native |
| 23 | // | 27 | // |
| 24 | // :3:27: error: unable to resolve comptime value | 28 | // :4:27: error: unable to resolve comptime value |
| 25 | // :3:27: note: value being casted to 'comptime_int' must be comptime-known | 29 | // :4:27: note: value being casted to 'comptime_int' must be comptime-known |
| 26 | // :7:29: error: unable to resolve comptime value | 30 | // :9:29: error: unable to resolve comptime value |
| 27 | // :7:29: note: value being casted to 'comptime_float' must be comptime-known | 31 | // :9:29: note: value being casted to 'comptime_float' must be comptime-known |
| 28 | // :12:10: error: unable to resolve comptime value | 32 | // :15:10: error: unable to resolve comptime value |
| 29 | // :12:10: note: value being casted to 'comptime_float' must be comptime-known | 33 | // :15:10: note: value being casted to 'comptime_float' must be comptime-known |
| 30 | // :17:10: error: unable to resolve comptime value | 34 | // :21:10: error: unable to resolve comptime value |
| 31 | // :17:10: note: value being casted to 'comptime_int' must be comptime-known | 35 | // :21:10: note: value being casted to 'comptime_int' must be comptime-known |
test/cases/compile_errors/runtime_value_in_switch_prong.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | var byte: u8 = 1; | 2 | var byte: u8 = 1; |
| 3 | switch (byte) { | 3 | switch ((&byte).*) { |
| 4 | byte => {}, | 4 | byte => {}, |
| 5 | else => {}, | 5 | else => {}, |
| 6 | } | 6 | } |
test/cases/compile_errors/self_referential_struct_requires_comptime.zig+1-1| ... | @@ -4,7 +4,7 @@ const S = struct { | ... | @@ -4,7 +4,7 @@ const S = struct { |
| 4 | }; | 4 | }; |
| 5 | pub export fn entry() void { | 5 | pub export fn entry() void { |
| 6 | var s: S = undefined; | 6 | var s: S = undefined; |
| 7 | _ = s; | 7 | _ = &s; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | // error | 10 | // error |
test/cases/compile_errors/self_referential_union_requires_comptime.zig+1-1| ... | @@ -4,7 +4,7 @@ const U = union { | ... | @@ -4,7 +4,7 @@ const U = union { |
| 4 | }; | 4 | }; |
| 5 | pub export fn entry() void { | 5 | pub export fn entry() void { |
| 6 | var u: U = undefined; | 6 | var u: U = undefined; |
| 7 | _ = u; | 7 | _ = &u; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | // error | 10 | // error |
test/cases/compile_errors/shift_by_negative_comptime_integer.zig+2-2| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a = 1 >> -1; | 2 | const a = 1 >> -1; |
| 3 | _ = a; | 3 | _ = a; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| ... | @@ -7,4 +7,4 @@ comptime { | ... | @@ -7,4 +7,4 @@ comptime { |
| 7 | // backend=stage2 | 7 | // backend=stage2 |
| 8 | // target=native | 8 | // target=native |
| 9 | // | 9 | // |
| 10 | // :2:18: error: shift by negative amount '-1' | 10 | // :2:20: error: shift by negative amount '-1' |
test/cases/compile_errors/shift_on_type_with_non-power-of-two_size.zig+8-4| ... | @@ -2,18 +2,22 @@ export fn entry() void { | ... | @@ -2,18 +2,22 @@ export fn entry() void { |
| 2 | const S = struct { | 2 | const S = struct { |
| 3 | fn a() void { | 3 | fn a() void { |
| 4 | var x: u24 = 42; | 4 | var x: u24 = 42; |
| 5 | _ = &x; | ||
| 5 | _ = x >> 24; | 6 | _ = x >> 24; |
| 6 | } | 7 | } |
| 7 | fn b() void { | 8 | fn b() void { |
| 8 | var x: u24 = 42; | 9 | var x: u24 = 42; |
| 10 | _ = &x; | ||
| 9 | _ = x << 24; | 11 | _ = x << 24; |
| 10 | } | 12 | } |
| 11 | fn c() void { | 13 | fn c() void { |
| 12 | var x: u24 = 42; | 14 | var x: u24 = 42; |
| 15 | _ = &x; | ||
| 13 | _ = @shlExact(x, 24); | 16 | _ = @shlExact(x, 24); |
| 14 | } | 17 | } |
| 15 | fn d() void { | 18 | fn d() void { |
| 16 | var x: u24 = 42; | 19 | var x: u24 = 42; |
| 20 | _ = &x; | ||
| 17 | _ = @shrExact(x, 24); | 21 | _ = @shrExact(x, 24); |
| 18 | } | 22 | } |
| 19 | }; | 23 | }; |
| ... | @@ -27,7 +31,7 @@ export fn entry() void { | ... | @@ -27,7 +31,7 @@ export fn entry() void { |
| 27 | // backend=stage2 | 31 | // backend=stage2 |
| 28 | // target=native | 32 | // target=native |
| 29 | // | 33 | // |
| 30 | // :5:22: error: shift amount '24' is too large for operand type 'u24' | 34 | // :6:22: error: shift amount '24' is too large for operand type 'u24' |
| 31 | // :9:22: error: shift amount '24' is too large for operand type 'u24' | 35 | // :11:22: error: shift amount '24' is too large for operand type 'u24' |
| 32 | // :13:30: error: shift amount '24' is too large for operand type 'u24' | 36 | // :16:30: error: shift amount '24' is too large for operand type 'u24' |
| 33 | // :17:30: error: shift amount '24' is too large for operand type 'u24' | 37 | // :21:30: error: shift amount '24' is too large for operand type 'u24' |
test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig+4-2| ... | @@ -6,10 +6,12 @@ export fn entry1(x: u8) u8 { | ... | @@ -6,10 +6,12 @@ export fn entry1(x: u8) u8 { |
| 6 | } | 6 | } |
| 7 | export fn entry2() void { | 7 | export fn entry2() void { |
| 8 | var x: u5 = 1; | 8 | var x: u5 = 1; |
| 9 | _ = &x; | ||
| 9 | _ = @shlExact(12345, x); | 10 | _ = @shlExact(12345, x); |
| 10 | } | 11 | } |
| 11 | export fn entry3() void { | 12 | export fn entry3() void { |
| 12 | var x: u5 = 1; | 13 | var x: u5 = 1; |
| 14 | _ = &x; | ||
| 13 | _ = @shrExact(12345, x); | 15 | _ = @shrExact(12345, x); |
| 14 | } | 16 | } |
| 15 | 17 | ||
| ... | @@ -19,5 +21,5 @@ export fn entry3() void { | ... | @@ -19,5 +21,5 @@ export fn entry3() void { |
| 19 | // | 21 | // |
| 20 | // :2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known | 22 | // :2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known |
| 21 | // :5:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known | 23 | // :5:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known |
| 22 | // :9:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known | 24 | // :10:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known |
| 23 | // :13:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known | 25 | // :15:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known |
test/cases/compile_errors/shuffle_with_selected_index_past_first_vector_length.zig+4-4| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; | 2 | const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; |
| 3 | const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; | 3 | const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; |
| 4 | var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); | 4 | const z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); |
| 5 | _ = z; | 5 | _ = z; |
| 6 | } | 6 | } |
| 7 | 7 | ||
| ... | @@ -9,6 +9,6 @@ export fn entry() void { | ... | @@ -9,6 +9,6 @@ export fn entry() void { |
| 9 | // backend=stage2 | 9 | // backend=stage2 |
| 10 | // target=native | 10 | // target=native |
| 11 | // | 11 | // |
| 12 | // :4:39: error: mask index '4' has out-of-bounds selection | 12 | // :4:41: error: mask index '4' has out-of-bounds selection |
| 13 | // :4:27: note: selected index '7' out of bounds of '@Vector(4, u32)' | 13 | // :4:29: note: selected index '7' out of bounds of '@Vector(4, u32)' |
| 14 | // :4:30: note: selections from the second vector are specified with negative numbers | 14 | // :4:32: note: selections from the second vector are specified with negative numbers |
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig+2-3| ... | @@ -1,11 +1,10 @@ | ... | @@ -1,11 +1,10 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16; | 2 | const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16; |
| 3 | var value = @as(*const []const u8, @ptrCast(&bytes)).*; | 3 | _ = @as(*const []const u8, @ptrCast(&bytes)).*; |
| 4 | _ = value; | ||
| 5 | } | 4 | } |
| 6 | 5 | ||
| 7 | // error | 6 | // error |
| 8 | // backend=stage2 | 7 | // backend=stage2 |
| 9 | // target=native | 8 | // target=native |
| 10 | // | 9 | // |
| 11 | // :3:57: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. | 10 | // :3:49: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. |
test/cases/compile_errors/slice_of_null_pointer.zig+3-3| ... | @@ -1,11 +1,11 @@ | ... | @@ -1,11 +1,11 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var x: [*c]u8 = null; | 2 | var x: [*c]u8 = null; |
| 3 | var runtime_len: usize = 0; | 3 | var runtime_len: usize = 0; |
| 4 | var y = x[0..runtime_len]; | 4 | _ = &runtime_len; |
| 5 | _ = y; | 5 | _ = x[0..runtime_len]; |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | // error | 8 | // error |
| 9 | // target=native | 9 | // target=native |
| 10 | // | 10 | // |
| 11 | // :4:14: error: slice of null pointer | 11 | // :5:10: error: slice of null pointer |
test/cases/compile_errors/slice_sentinel_mismatch-2.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | fn foo() [:0]u8 { | 1 | fn foo() [:0]u8 { |
| 2 | var x: []u8 = undefined; | 2 | const x: []u8 = undefined; |
| 3 | return x; | 3 | return x; |
| 4 | } | 4 | } |
| 5 | comptime { | 5 | comptime { |
test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig+1-2| ... | @@ -7,8 +7,7 @@ const Small = enum(u2) { | ... | @@ -7,8 +7,7 @@ const Small = enum(u2) { |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | export fn entry() void { | 9 | export fn entry() void { |
| 10 | var x = Small.One; | 10 | _ = Small.One; |
| 11 | _ = x; | ||
| 12 | } | 11 | } |
| 13 | 12 | ||
| 14 | // error | 13 | // error |
test/cases/compile_errors/specify_non-integer_enum_tag_type.zig+1-1| ... | @@ -5,7 +5,7 @@ const Small = enum(f32) { | ... | @@ -5,7 +5,7 @@ const Small = enum(f32) { |
| 5 | }; | 5 | }; |
| 6 | 6 | ||
| 7 | export fn entry() void { | 7 | export fn entry() void { |
| 8 | var x = Small.One; | 8 | const x = Small.One; |
| 9 | _ = x; | 9 | _ = x; |
| 10 | } | 10 | } |
| 11 | 11 |
test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig+1-1| ... | @@ -2,7 +2,7 @@ export fn entry() void { | ... | @@ -2,7 +2,7 @@ export fn entry() void { |
| 2 | var sp = asm volatile ("mov %[foo], sp" | 2 | var sp = asm volatile ("mov %[foo], sp" |
| 3 | : [bar] "=r" (-> usize), | 3 | : [bar] "=r" (-> usize), |
| 4 | ); | 4 | ); |
| 5 | _ = sp; | 5 | _ = &sp; |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | // error | 8 | // error |
test/cases/compile_errors/store_vector_pointer_with_unknown_runtime_index.zig+2-1| ... | @@ -2,6 +2,7 @@ export fn entry() void { | ... | @@ -2,6 +2,7 @@ export fn entry() void { |
| 2 | var v: @Vector(4, i31) = [_]i31{ 1, 5, 3, undefined }; | 2 | var v: @Vector(4, i31) = [_]i31{ 1, 5, 3, undefined }; |
| 3 | 3 | ||
| 4 | var i: u32 = 0; | 4 | var i: u32 = 0; |
| 5 | _ = &i; | ||
| 5 | storev(&v[i], 42); | 6 | storev(&v[i], 42); |
| 6 | } | 7 | } |
| 7 | 8 | ||
| ... | @@ -13,4 +14,4 @@ fn storev(ptr: anytype, val: i31) void { | ... | @@ -13,4 +14,4 @@ fn storev(ptr: anytype, val: i31) void { |
| 13 | // backend=llvm | 14 | // backend=llvm |
| 14 | // target=native | 15 | // target=native |
| 15 | // | 16 | // |
| 16 | // :9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31' | 17 | // :10:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31' |
test/cases/compile_errors/sub_on_undefined_value.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | var a: i64 = undefined; | 2 | const a: i64 = undefined; |
| 3 | _ = a - a; | 3 | _ = a - a; |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/switch_capture_incompatible_types.zig+2-2| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | export fn f() void { | 1 | export fn f() void { |
| 2 | const U = union(enum) { a: u32, b: *u8 }; | 2 | const U = union(enum) { a: u32, b: *u8 }; |
| 3 | var u: U = undefined; | 3 | var u: U = undefined; |
| 4 | switch (u) { | 4 | switch ((&u).*) { |
| 5 | .a, .b => |val| _ = val, | 5 | .a, .b => |val| _ = val, |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| ... | @@ -9,7 +9,7 @@ export fn f() void { | ... | @@ -9,7 +9,7 @@ export fn f() void { |
| 9 | export fn g() void { | 9 | export fn g() void { |
| 10 | const U = union(enum) { a: u64, b: u32 }; | 10 | const U = union(enum) { a: u64, b: u32 }; |
| 11 | var u: U = undefined; | 11 | var u: U = undefined; |
| 12 | switch (u) { | 12 | switch ((&u).*) { |
| 13 | .a, .b => |*ptr| _ = ptr, | 13 | .a, .b => |*ptr| _ = ptr, |
| 14 | } | 14 | } |
| 15 | } | 15 | } |
test/cases/compile_errors/switch_on_enum_with_1_field_with_no_prongs.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const Foo = enum { M }; | 1 | const Foo = enum { M }; |
| 2 | 2 | ||
| 3 | export fn entry() void { | 3 | export fn entry() void { |
| 4 | var f = Foo.M; | 4 | const f = Foo.M; |
| 5 | switch (f) {} | 5 | switch (f) {} |
| 6 | } | 6 | } |
| 7 | 7 |
test/cases/compile_errors/switch_on_slice.zig+2-1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | var a: [:0]const u8 = "foo"; | 2 | var a: [:0]const u8 = "foo"; |
| 3 | _ = &a; | ||
| 3 | switch (a) { | 4 | switch (a) { |
| 4 | ("--version"), ("version") => unreachable, | 5 | ("--version"), ("version") => unreachable, |
| 5 | else => {}, | 6 | else => {}, |
| ... | @@ -10,4 +11,4 @@ pub export fn entry() void { | ... | @@ -10,4 +11,4 @@ pub export fn entry() void { |
| 10 | // backend=stage2 | 11 | // backend=stage2 |
| 11 | // target=native | 12 | // target=native |
| 12 | // | 13 | // |
| 13 | // :3:13: error: switch on type '[:0]const u8' | 14 | // :4:13: error: switch on type '[:0]const u8' |
test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig+2-2| ... | @@ -1,12 +1,12 @@ | ... | @@ -1,12 +1,12 @@ |
| 1 | pub export fn entry1() void { | 1 | pub export fn entry1() void { |
| 2 | var x: i32 = 0; | 2 | const x: i32 = 0; |
| 3 | switch (x) { | 3 | switch (x) { |
| 4 | 6...1 => {}, | 4 | 6...1 => {}, |
| 5 | else => unreachable, | 5 | else => unreachable, |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | pub export fn entr2() void { | 8 | pub export fn entr2() void { |
| 9 | var x: i32 = 0; | 9 | const x: i32 = 0; |
| 10 | switch (x) { | 10 | switch (x) { |
| 11 | -1...-5 => {}, | 11 | -1...-5 => {}, |
| 12 | else => unreachable, | 12 | else => unreachable, |
test/cases/compile_errors/switch_with_overlapping_case_ranges.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var q: u8 = 0; | 2 | var q: u8 = 0; |
| 3 | switch (q) { | 3 | switch ((&q).*) { |
| 4 | 1...2 => {}, | 4 | 1...2 => {}, |
| 5 | 0...255 => {}, | 5 | 0...255 => {}, |
| 6 | } | 6 | } |
test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig+1-1| ... | @@ -3,7 +3,7 @@ const E = enum { | ... | @@ -3,7 +3,7 @@ const E = enum { |
| 3 | b, | 3 | b, |
| 4 | }; | 4 | }; |
| 5 | pub export fn entry() void { | 5 | pub export fn entry() void { |
| 6 | var e: E = .b; | 6 | const e: E = .b; |
| 7 | switch (e) { | 7 | switch (e) { |
| 8 | .a => {}, | 8 | .a => {}, |
| 9 | .b => {}, | 9 | .b => {}, |
test/cases/compile_errors/switching_with_non-exhaustive_enums.zig+3-3| ... | @@ -8,21 +8,21 @@ const U = union(E) { | ... | @@ -8,21 +8,21 @@ const U = union(E) { |
| 8 | b: u32, | 8 | b: u32, |
| 9 | }; | 9 | }; |
| 10 | pub export fn entry1() void { | 10 | pub export fn entry1() void { |
| 11 | var e: E = .b; | 11 | const e: E = .b; |
| 12 | switch (e) { // error: switch not handling the tag `b` | 12 | switch (e) { // error: switch not handling the tag `b` |
| 13 | .a => {}, | 13 | .a => {}, |
| 14 | _ => {}, | 14 | _ => {}, |
| 15 | } | 15 | } |
| 16 | } | 16 | } |
| 17 | pub export fn entry2() void { | 17 | pub export fn entry2() void { |
| 18 | var e: E = .b; | 18 | const e: E = .b; |
| 19 | switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong | 19 | switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong |
| 20 | .a => {}, | 20 | .a => {}, |
| 21 | .b => {}, | 21 | .b => {}, |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
| 24 | pub export fn entry3() void { | 24 | pub export fn entry3() void { |
| 25 | var u = U{ .a = 2 }; | 25 | const u = U{ .a = 2 }; |
| 26 | switch (u) { // error: `_` prong not allowed when switching on tagged union | 26 | switch (u) { // error: `_` prong not allowed when switching on tagged union |
| 27 | .a => {}, | 27 | .a => {}, |
| 28 | .b => {}, | 28 | .b => {}, |
test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig+3-4| ... | @@ -3,14 +3,13 @@ const FloatInt = extern union { | ... | @@ -3,14 +3,13 @@ const FloatInt = extern union { |
| 3 | Int: i32, | 3 | Int: i32, |
| 4 | }; | 4 | }; |
| 5 | export fn entry() void { | 5 | export fn entry() void { |
| 6 | var fi = FloatInt{ .Float = 123.45 }; | 6 | const fi: FloatInt = .{ .Float = 123.45 }; |
| 7 | var tagName = @tagName(fi); | 7 | _ = @tagName(fi); |
| 8 | _ = tagName; | ||
| 9 | } | 8 | } |
| 10 | 9 | ||
| 11 | // error | 10 | // error |
| 12 | // backend=stage2 | 11 | // backend=stage2 |
| 13 | // target=native | 12 | // target=native |
| 14 | // | 13 | // |
| 15 | // :7:19: error: union 'tmp.FloatInt' is untagged | 14 | // :7:9: error: union 'tmp.FloatInt' is untagged |
| 16 | // :1:25: note: union declared here | 15 | // :1:25: note: union declared here |
test/cases/compile_errors/truncate_sign_mismatch.zig+8-8| ... | @@ -1,25 +1,25 @@ | ... | @@ -1,25 +1,25 @@ |
| 1 | export fn entry1() i8 { | 1 | export fn entry1() i8 { |
| 2 | var x: u32 = 10; | 2 | var x: u32 = 10; |
| 3 | return @truncate(x); | 3 | return @truncate((&x).*); |
| 4 | } | 4 | } |
| 5 | export fn entry2() u8 { | 5 | export fn entry2() u8 { |
| 6 | var x: i32 = -10; | 6 | var x: i32 = -10; |
| 7 | return @truncate(x); | 7 | return @truncate((&x).*); |
| 8 | } | 8 | } |
| 9 | export fn entry3() i8 { | 9 | export fn entry3() i8 { |
| 10 | comptime var x: u32 = 10; | 10 | comptime var x: u32 = 10; |
| 11 | return @truncate(x); | 11 | return @truncate((&x).*); |
| 12 | } | 12 | } |
| 13 | export fn entry4() u8 { | 13 | export fn entry4() u8 { |
| 14 | comptime var x: i32 = -10; | 14 | comptime var x: i32 = -10; |
| 15 | return @truncate(x); | 15 | return @truncate((&x).*); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | // error | 18 | // error |
| 19 | // backend=stage2 | 19 | // backend=stage2 |
| 20 | // target=native | 20 | // target=native |
| 21 | // | 21 | // |
| 22 | // :3:22: error: expected signed integer type, found 'u32' | 22 | // :3:26: error: expected signed integer type, found 'u32' |
| 23 | // :7:22: error: expected unsigned integer type, found 'i32' | 23 | // :7:26: error: expected unsigned integer type, found 'i32' |
| 24 | // :11:22: error: expected signed integer type, found 'u32' | 24 | // :11:26: error: expected signed integer type, found 'u32' |
| 25 | // :15:22: error: expected unsigned integer type, found 'i32' | 25 | // :15:26: error: expected unsigned integer type, found 'i32' |
test/cases/compile_errors/tuple_init_edge_cases.zig+23-18| ... | @@ -1,49 +1,54 @@ | ... | @@ -1,49 +1,54 @@ |
| 1 | pub export fn entry1() void { | 1 | pub export fn entry1() void { |
| 2 | const T = @TypeOf(.{ 123, 3 }); | 2 | const T = @TypeOf(.{ 123, 3 }); |
| 3 | var b = T{ .@"1" = 3 }; | 3 | var b = T{ .@"1" = 3 }; |
| 4 | _ = b; | 4 | _ = &b; |
| 5 | var c = T{ 123, 3 }; | 5 | var c = T{ 123, 3 }; |
| 6 | _ = c; | 6 | _ = &c; |
| 7 | var d = T{}; | 7 | var d = T{}; |
| 8 | _ = d; | 8 | _ = &d; |
| 9 | } | 9 | } |
| 10 | pub export fn entry2() void { | 10 | pub export fn entry2() void { |
| 11 | var a: u32 = 2; | 11 | var a: u32 = 2; |
| 12 | _ = &a; | ||
| 12 | const T = @TypeOf(.{ 123, a }); | 13 | const T = @TypeOf(.{ 123, a }); |
| 13 | var b = T{ .@"1" = 3 }; | 14 | var b = T{ .@"1" = 3 }; |
| 14 | _ = b; | 15 | _ = &b; |
| 15 | var c = T{ 123, 3 }; | 16 | var c = T{ 123, 3 }; |
| 16 | _ = c; | 17 | _ = &c; |
| 17 | var d = T{}; | 18 | var d = T{}; |
| 18 | _ = d; | 19 | _ = &d; |
| 19 | } | 20 | } |
| 20 | pub export fn entry3() void { | 21 | pub export fn entry3() void { |
| 21 | var a: u32 = 2; | 22 | var a: u32 = 2; |
| 23 | _ = &a; | ||
| 22 | const T = @TypeOf(.{ 123, a }); | 24 | const T = @TypeOf(.{ 123, a }); |
| 23 | var b = T{ .@"0" = 123 }; | 25 | var b = T{ .@"0" = 123 }; |
| 24 | _ = b; | 26 | _ = &b; |
| 25 | } | 27 | } |
| 26 | comptime { | 28 | comptime { |
| 27 | var a: u32 = 2; | 29 | var a: u32 = 2; |
| 30 | _ = &a; | ||
| 28 | const T = @TypeOf(.{ 123, a }); | 31 | const T = @TypeOf(.{ 123, a }); |
| 29 | var b = T{ .@"0" = 123 }; | 32 | var b = T{ .@"0" = 123 }; |
| 30 | _ = b; | 33 | _ = &b; |
| 31 | var c = T{ 123, 2 }; | 34 | var c = T{ 123, 2 }; |
| 32 | _ = c; | 35 | _ = &c; |
| 33 | var d = T{}; | 36 | var d = T{}; |
| 34 | _ = d; | 37 | _ = &d; |
| 35 | } | 38 | } |
| 36 | pub export fn entry4() void { | 39 | pub export fn entry4() void { |
| 37 | var a: u32 = 2; | 40 | var a: u32 = 2; |
| 41 | _ = &a; | ||
| 38 | const T = @TypeOf(.{ 123, a }); | 42 | const T = @TypeOf(.{ 123, a }); |
| 39 | var b = T{ 123, 4, 5 }; | 43 | var b = T{ 123, 4, 5 }; |
| 40 | _ = b; | 44 | _ = &b; |
| 41 | } | 45 | } |
| 42 | pub export fn entry5() void { | 46 | pub export fn entry5() void { |
| 43 | var a: u32 = 2; | 47 | var a: u32 = 2; |
| 48 | _ = &a; | ||
| 44 | const T = @TypeOf(.{ 123, a }); | 49 | const T = @TypeOf(.{ 123, a }); |
| 45 | var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 }; | 50 | var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 }; |
| 46 | _ = b; | 51 | _ = &b; |
| 47 | } | 52 | } |
| 48 | pub const Consideration = struct { | 53 | pub const Consideration = struct { |
| 49 | curve: Curve, | 54 | curve: Curve, |
| ... | @@ -64,9 +69,9 @@ pub export fn entry6() void { | ... | @@ -64,9 +69,9 @@ pub export fn entry6() void { |
| 64 | // backend=stage2 | 69 | // backend=stage2 |
| 65 | // target=native | 70 | // target=native |
| 66 | // | 71 | // |
| 67 | // :17:14: error: missing tuple field with index 1 | 72 | // :18:14: error: missing tuple field with index 1 |
| 68 | // :23:14: error: missing tuple field with index 1 | 73 | // :25:14: error: missing tuple field with index 1 |
| 69 | // :39:14: error: expected at most 2 tuple fields; found 3 | 74 | // :43:14: error: expected at most 2 tuple fields; found 3 |
| 70 | // :45:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}' | 75 | // :50:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}' |
| 71 | // :58:37: error: missing tuple field with index 3 | 76 | // :63:37: error: missing tuple field with index 3 |
| 72 | // :53:32: note: struct declared here | 77 | // :58:32: note: struct declared here |
test/cases/compile_errors/uncreachable_else_prong_err_set.zig deleted-25| ... | @@ -1,25 +0,0 @@ | ||
| 1 | pub export fn complex() void { | ||
| 2 | var a: error{ Foo, Bar } = error.Foo; | ||
| 3 | switch (a) { | ||
| 4 | error.Foo => unreachable, | ||
| 5 | error.Bar => unreachable, | ||
| 6 | else => { | ||
| 7 | @compileError("<something complex here>"); | ||
| 8 | }, | ||
| 9 | } | ||
| 10 | } | ||
| 11 | |||
| 12 | pub export fn simple() void { | ||
| 13 | var a: error{ Foo, Bar } = error.Foo; | ||
| 14 | switch (a) { | ||
| 15 | error.Foo => unreachable, | ||
| 16 | error.Bar => unreachable, | ||
| 17 | else => |e| return e, | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | // error | ||
| 22 | // backend=llvm | ||
| 23 | // target=native | ||
| 24 | // | ||
| 25 | // :6:14: error: unreachable else prong; all cases already handled | ||
test/cases/compile_errors/union_access_of_inactive_field.zig+1| ... | @@ -5,6 +5,7 @@ const U = union { | ... | @@ -5,6 +5,7 @@ const U = union { |
| 5 | comptime { | 5 | comptime { |
| 6 | var u: U = .{ .a = {} }; | 6 | var u: U = .{ .a = {} }; |
| 7 | const v = u.b; | 7 | const v = u.b; |
| 8 | _ = &u; | ||
| 8 | _ = v; | 9 | _ = v; |
| 9 | } | 10 | } |
| 10 | 11 |
test/cases/compile_errors/union_auto-enum_value_already_taken.zig+1-1| ... | @@ -6,7 +6,7 @@ const MultipleChoice = union(enum(u32)) { | ... | @@ -6,7 +6,7 @@ const MultipleChoice = union(enum(u32)) { |
| 6 | E = 60, | 6 | E = 60, |
| 7 | }; | 7 | }; |
| 8 | export fn entry() void { | 8 | export fn entry() void { |
| 9 | var x = MultipleChoice{ .C = {} }; | 9 | const x: MultipleChoice = .{ .C = {} }; |
| 10 | _ = x; | 10 | _ = x; |
| 11 | } | 11 | } |
| 12 | 12 |
test/cases/compile_errors/union_duplicate_enum_field.zig+1-1| ... | @@ -5,7 +5,7 @@ const U = union(E) { | ... | @@ -5,7 +5,7 @@ const U = union(E) { |
| 5 | }; | 5 | }; |
| 6 | 6 | ||
| 7 | export fn foo() void { | 7 | export fn foo() void { |
| 8 | var u: U = .{ .a = 123 }; | 8 | const u: U = .{ .a = 123 }; |
| 9 | _ = u; | 9 | _ = u; |
| 10 | } | 10 | } |
| 11 | 11 |
test/cases/compile_errors/union_enum_field_does_not_match_enum.zig+1-1| ... | @@ -10,7 +10,7 @@ const Payload = union(Letter) { | ... | @@ -10,7 +10,7 @@ const Payload = union(Letter) { |
| 10 | D: bool, | 10 | D: bool, |
| 11 | }; | 11 | }; |
| 12 | export fn entry() void { | 12 | export fn entry() void { |
| 13 | var a = Payload{ .A = 1234 }; | 13 | const a: Payload = .{ .A = 1234 }; |
| 14 | _ = a; | 14 | _ = a; |
| 15 | } | 15 | } |
| 16 | 16 |
test/cases/compile_errors/union_noreturn_field_initialized.zig+3-3| ... | @@ -9,7 +9,7 @@ pub export fn entry1() void { | ... | @@ -9,7 +9,7 @@ pub export fn entry1() void { |
| 9 | }; | 9 | }; |
| 10 | 10 | ||
| 11 | var a = U{ .b = undefined }; | 11 | var a = U{ .b = undefined }; |
| 12 | _ = a; | 12 | _ = &a; |
| 13 | } | 13 | } |
| 14 | pub export fn entry2() void { | 14 | pub export fn entry2() void { |
| 15 | const U = union(enum) { | 15 | const U = union(enum) { |
| ... | @@ -25,7 +25,7 @@ pub export fn entry3() void { | ... | @@ -25,7 +25,7 @@ pub export fn entry3() void { |
| 25 | }; | 25 | }; |
| 26 | var e = @typeInfo(U).Union.tag_type.?.a; | 26 | var e = @typeInfo(U).Union.tag_type.?.a; |
| 27 | var u: U = undefined; | 27 | var u: U = undefined; |
| 28 | u = e; | 28 | u = (&e).*; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | // error | 31 | // error |
| ... | @@ -38,6 +38,6 @@ pub export fn entry3() void { | ... | @@ -38,6 +38,6 @@ pub export fn entry3() void { |
| 38 | // :19:10: error: cannot initialize 'noreturn' field of union | 38 | // :19:10: error: cannot initialize 'noreturn' field of union |
| 39 | // :16:9: note: field 'a' declared here | 39 | // :16:9: note: field 'a' declared here |
| 40 | // :15:15: note: union declared here | 40 | // :15:15: note: union declared here |
| 41 | // :28:9: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field | 41 | // :28:13: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field |
| 42 | // :23:9: note: 'noreturn' field here | 42 | // :23:9: note: 'noreturn' field here |
| 43 | // :22:15: note: union declared here | 43 | // :22:15: note: union declared here |
test/cases/compile_errors/union_runtime_coercion_from_enum.zig+1-1| ... | @@ -11,7 +11,7 @@ fn foo() E { | ... | @@ -11,7 +11,7 @@ fn foo() E { |
| 11 | } | 11 | } |
| 12 | export fn doTheTest() u64 { | 12 | export fn doTheTest() u64 { |
| 13 | var u: U = foo(); | 13 | var u: U = foo(); |
| 14 | return u.b; | 14 | return (&u).b; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | // error | 17 | // error |
test/cases/compile_errors/unreachable_else_prong_err_set.zig created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | pub export fn complex() void { | ||
| 2 | var a: error{ Foo, Bar } = error.Foo; | ||
| 3 | _ = &a; | ||
| 4 | switch (a) { | ||
| 5 | error.Foo => unreachable, | ||
| 6 | error.Bar => unreachable, | ||
| 7 | else => { | ||
| 8 | @compileError("<something complex here>"); | ||
| 9 | }, | ||
| 10 | } | ||
| 11 | } | ||
| 12 | |||
| 13 | pub export fn simple() void { | ||
| 14 | var a: error{ Foo, Bar } = error.Foo; | ||
| 15 | _ = &a; | ||
| 16 | switch (a) { | ||
| 17 | error.Foo => unreachable, | ||
| 18 | error.Bar => unreachable, | ||
| 19 | else => |e| return e, | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | // error | ||
| 24 | // backend=llvm | ||
| 25 | // target=native | ||
| 26 | // | ||
| 27 | // :7:14: error: unreachable else prong; all cases already handled | ||
test/cases/compile_errors/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig+5-6| ... | @@ -1,16 +1,15 @@ | ... | @@ -1,16 +1,15 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var x: i32 = 1234; | 2 | var x: i32 = 1234; |
| 3 | var p: *i32 = &x; | 3 | var p: *i32 = &x; |
| 4 | var pp: *?*i32 = &p; | 4 | const pp: *?*i32 = &p; |
| 5 | pp.* = null; | 5 | pp.* = null; |
| 6 | var y = p.*; | 6 | _ = p.*; |
| 7 | _ = y; | ||
| 8 | } | 7 | } |
| 9 | 8 | ||
| 10 | // error | 9 | // error |
| 11 | // backend=stage2 | 10 | // backend=stage2 |
| 12 | // target=native | 11 | // target=native |
| 13 | // | 12 | // |
| 14 | // :4:22: error: expected type '*?*i32', found '**i32' | 13 | // :4:24: error: expected type '*?*i32', found '**i32' |
| 15 | // :4:22: note: pointer type child '*i32' cannot cast into pointer type child '?*i32' | 14 | // :4:24: note: pointer type child '*i32' cannot cast into pointer type child '?*i32' |
| 16 | // :4:22: note: mutable '*i32' allows illegal null values stored to type '?*i32' | 15 | // :4:24: note: mutable '*i32' allows illegal null values stored to type '?*i32' |
test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | var v = 25; | 1 | var v = 25; |
| 2 | export fn entry() void { | 2 | export fn entry() void { |
| 3 | var arr: [v]u8 = undefined; | 3 | var arr: [v]u8 = undefined; |
| 4 | _ = arr; | 4 | _ = &arr; |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
test/cases/compile_errors/var_never_mutated.zig created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | fn entry0() void { | ||
| 2 | var a: u32 = 1 + 2; | ||
| 3 | _ = a; | ||
| 4 | } | ||
| 5 | |||
| 6 | fn entry1() void { | ||
| 7 | const a: u32 = 1; | ||
| 8 | const b: u32 = 2; | ||
| 9 | var c = a + b; | ||
| 10 | const d = c; | ||
| 11 | _ = d; | ||
| 12 | } | ||
| 13 | |||
| 14 | fn entry2() void { | ||
| 15 | var a: u32 = 123; | ||
| 16 | foo(a); | ||
| 17 | } | ||
| 18 | |||
| 19 | fn foo(_: u32) void {} | ||
| 20 | |||
| 21 | // error | ||
| 22 | // | ||
| 23 | // :2:9: error: local variable is never mutated | ||
| 24 | // :2:9: note: consider using 'const' | ||
| 25 | // :9:9: error: local variable is never mutated | ||
| 26 | // :9:9: note: consider using 'const' | ||
| 27 | // :15:9: error: local variable is never mutated | ||
| 28 | // :15:9: note: consider using 'const' | ||
test/cases/compile_errors/variable_with_type_noreturn.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | export fn entry9() void { | 1 | export fn entry9() void { |
| 2 | var z: noreturn = return; | 2 | var z: noreturn = return; |
| 3 | _ = z; | 3 | _ = &z; |
| 4 | } | 4 | } |
| 5 | 5 | ||
| 6 | // error | 6 | // error |
test/cases/compile_errors/variadic_arg_validation.zig+5-4| ... | @@ -7,6 +7,7 @@ pub export fn entry() void { | ... | @@ -7,6 +7,7 @@ pub export fn entry() void { |
| 7 | pub export fn entry1() void { | 7 | pub export fn entry1() void { |
| 8 | var arr: [2]u8 = undefined; | 8 | var arr: [2]u8 = undefined; |
| 9 | _ = printf("%d\n", arr); | 9 | _ = printf("%d\n", arr); |
| 10 | _ = &arr; | ||
| 10 | } | 11 | } |
| 11 | 12 | ||
| 12 | pub export fn entry2() void { | 13 | pub export fn entry2() void { |
| ... | @@ -23,7 +24,7 @@ pub export fn entry3() void { | ... | @@ -23,7 +24,7 @@ pub export fn entry3() void { |
| 23 | // | 24 | // |
| 24 | // :4:33: error: integer and float literals passed to variadic function must be casted to a fixed-size number type | 25 | // :4:33: error: integer and float literals passed to variadic function must be casted to a fixed-size number type |
| 25 | // :9:24: error: arrays must be passed by reference to variadic function | 26 | // :9:24: error: arrays must be passed by reference to variadic function |
| 26 | // :13:24: error: cannot pass 'u48' to variadic function | 27 | // :14:24: error: cannot pass 'u48' to variadic function |
| 27 | // :13:24: note: only integers with 0 or power of two bits are extern compatible | 28 | // :14:24: note: only integers with 0 or power of two bits are extern compatible |
| 28 | // :17:24: error: cannot pass 'void' to variadic function | 29 | // :18:24: error: cannot pass 'void' to variadic function |
| 29 | // :17:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque' | 30 | // :18:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque' |
test/cases/compile_errors/while_loop_body_expression_ignored.zig+16-12| ... | @@ -6,18 +6,22 @@ export fn f1() void { | ... | @@ -6,18 +6,22 @@ export fn f1() void { |
| 6 | } | 6 | } |
| 7 | export fn f2() void { | 7 | export fn f2() void { |
| 8 | var x: ?i32 = null; | 8 | var x: ?i32 = null; |
| 9 | _ = &x; | ||
| 9 | while (x) |_| returns(); | 10 | while (x) |_| returns(); |
| 10 | } | 11 | } |
| 11 | export fn f3() void { | 12 | export fn f3() void { |
| 12 | var x: anyerror!i32 = error.Bad; | 13 | var x: anyerror!i32 = error.Bad; |
| 14 | _ = &x; | ||
| 13 | while (x) |_| returns() else |_| unreachable; | 15 | while (x) |_| returns() else |_| unreachable; |
| 14 | } | 16 | } |
| 15 | export fn f4() void { | 17 | export fn f4() void { |
| 16 | var a = true; | 18 | var a = true; |
| 19 | _ = &a; | ||
| 17 | while (a) {} else true; | 20 | while (a) {} else true; |
| 18 | } | 21 | } |
| 19 | export fn f5() void { | 22 | export fn f5() void { |
| 20 | var a = true; | 23 | var a = true; |
| 24 | _ = &a; | ||
| 21 | const foo = while (a) returns() else true; | 25 | const foo = while (a) returns() else true; |
| 22 | _ = foo; | 26 | _ = foo; |
| 23 | } | 27 | } |
| ... | @@ -29,15 +33,15 @@ export fn f5() void { | ... | @@ -29,15 +33,15 @@ export fn f5() void { |
| 29 | // :5:25: error: value of type 'usize' ignored | 33 | // :5:25: error: value of type 'usize' ignored |
| 30 | // :5:25: note: all non-void values must be used | 34 | // :5:25: note: all non-void values must be used |
| 31 | // :5:25: note: this error can be suppressed by assigning the value to '_' | 35 | // :5:25: note: this error can be suppressed by assigning the value to '_' |
| 32 | // :9:26: error: value of type 'usize' ignored | 36 | // :10:26: error: value of type 'usize' ignored |
| 33 | // :9:26: note: all non-void values must be used | 37 | // :10:26: note: all non-void values must be used |
| 34 | // :9:26: note: this error can be suppressed by assigning the value to '_' | 38 | // :10:26: note: this error can be suppressed by assigning the value to '_' |
| 35 | // :13:26: error: value of type 'usize' ignored | 39 | // :15:26: error: value of type 'usize' ignored |
| 36 | // :13:26: note: all non-void values must be used | 40 | // :15:26: note: all non-void values must be used |
| 37 | // :13:26: note: this error can be suppressed by assigning the value to '_' | 41 | // :15:26: note: this error can be suppressed by assigning the value to '_' |
| 38 | // :17:23: error: value of type 'bool' ignored | 42 | // :20:23: error: value of type 'bool' ignored |
| 39 | // :17:23: note: all non-void values must be used | 43 | // :20:23: note: all non-void values must be used |
| 40 | // :17:23: note: this error can be suppressed by assigning the value to '_' | 44 | // :20:23: note: this error can be suppressed by assigning the value to '_' |
| 41 | // :21:34: error: value of type 'usize' ignored | 45 | // :25:34: error: value of type 'usize' ignored |
| 42 | // :21:34: note: all non-void values must be used | 46 | // :25:34: note: all non-void values must be used |
| 43 | // :21:34: note: this error can be suppressed by assigning the value to '_' | 47 | // :25:34: note: this error can be suppressed by assigning the value to '_' |
test/cases/compile_errors/while_loop_break_value_ignored.zig+4-2| ... | @@ -7,6 +7,7 @@ export fn f1() void { | ... | @@ -7,6 +7,7 @@ export fn f1() void { |
| 7 | while (a) { | 7 | while (a) { |
| 8 | break returns(); | 8 | break returns(); |
| 9 | } | 9 | } |
| 10 | _ = &a; | ||
| 10 | } | 11 | } |
| 11 | 12 | ||
| 12 | export fn f2() void { | 13 | export fn f2() void { |
| ... | @@ -16,6 +17,7 @@ export fn f2() void { | ... | @@ -16,6 +17,7 @@ export fn f2() void { |
| 16 | break :outer returns(); | 17 | break :outer returns(); |
| 17 | } | 18 | } |
| 18 | } | 19 | } |
| 20 | _ = &x; | ||
| 19 | } | 21 | } |
| 20 | 22 | ||
| 21 | // error | 23 | // error |
| ... | @@ -24,5 +26,5 @@ export fn f2() void { | ... | @@ -24,5 +26,5 @@ export fn f2() void { |
| 24 | // | 26 | // |
| 25 | // :7:5: error: incompatible types: 'usize' and 'void' | 27 | // :7:5: error: incompatible types: 'usize' and 'void' |
| 26 | // :8:22: note: type 'usize' here | 28 | // :8:22: note: type 'usize' here |
| 27 | // :14:12: error: incompatible types: 'usize' and 'void' | 29 | // :15:12: error: incompatible types: 'usize' and 'void' |
| 28 | // :16:33: note: type 'usize' here | 30 | // :17:33: note: type 'usize' here |
test/cases/compile_errors/wrong_type_passed_to_panic.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | var e = error.Foo; | 2 | const e = error.Foo; |
| 3 | @panic(e); | 3 | @panic(e); |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_log.0.zig+1-1| ... | @@ -4,7 +4,7 @@ export fn _start() noreturn { | ... | @@ -4,7 +4,7 @@ export fn _start() noreturn { |
| 4 | @compileLog(b, 20, f, x); | 4 | @compileLog(b, 20, f, x); |
| 5 | @compileLog(1000); | 5 | @compileLog(1000); |
| 6 | var bruh: usize = true; | 6 | var bruh: usize = true; |
| 7 | _ = bruh; | 7 | _ = .{ &f, &bruh }; |
| 8 | unreachable; | 8 | unreachable; |
| 9 | } | 9 | } |
| 10 | export fn other() void { | 10 | export fn other() void { |
test/cases/compile_log.1.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | export fn _start() noreturn { | 1 | export fn _start() noreturn { |
| 2 | const b = true; | 2 | const b = true; |
| 3 | var f: u32 = 1; | 3 | var f: u32 = 1; |
| 4 | _ = &f; | ||
| 4 | @compileLog(b, 20, f, x); | 5 | @compileLog(b, 20, f, x); |
| 5 | @compileLog(1000); | 6 | @compileLog(1000); |
| 6 | unreachable; | 7 | unreachable; |
test/cases/comptime_var.0.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var a: u32 = 0; | 2 | var a: u32 = 0; |
| 3 | _ = &a; | ||
| 3 | comptime var b: u32 = 0; | 4 | comptime var b: u32 = 0; |
| 4 | if (a == 0) b = 3; | 5 | if (a == 0) b = 3; |
| 5 | } | 6 | } |
| ... | @@ -9,5 +10,5 @@ pub fn main() void { | ... | @@ -9,5 +10,5 @@ pub fn main() void { |
| 9 | // target=x86_64-macos,x86_64-linux | 10 | // target=x86_64-macos,x86_64-linux |
| 10 | // link_libc=true | 11 | // link_libc=true |
| 11 | // | 12 | // |
| 12 | // :4:19: error: store to comptime variable depends on runtime condition | 13 | // :5:19: error: store to comptime variable depends on runtime condition |
| 13 | // :4:11: note: runtime condition here | 14 | // :5:11: note: runtime condition here |
test/cases/comptime_var.1.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var a: u32 = 0; | 2 | var a: u32 = 0; |
| 3 | _ = &a; | ||
| 3 | comptime var b: u32 = 0; | 4 | comptime var b: u32 = 0; |
| 4 | switch (a) { | 5 | switch (a) { |
| 5 | 0 => {}, | 6 | 0 => {}, |
test/cases/comptime_var.5.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var a: u32 = 0; | 2 | var a: u32 = 0; |
| 3 | _ = &a; | ||
| 3 | if (a == 0) { | 4 | if (a == 0) { |
| 4 | comptime var b: u32 = 0; | 5 | comptime var b: u32 = 0; |
| 5 | b = 1; | 6 | b = 1; |
test/cases/conditions.5.zig+1| ... | @@ -10,6 +10,7 @@ fn assert(ok: bool) void { | ... | @@ -10,6 +10,7 @@ fn assert(ok: bool) void { |
| 10 | fn foo(ok: bool) i32 { | 10 | fn foo(ok: bool) i32 { |
| 11 | const val: i32 = blk: { | 11 | const val: i32 = blk: { |
| 12 | var x: i32 = 1; | 12 | var x: i32 = 1; |
| 13 | _ = &x; | ||
| 13 | if (!ok) break :blk x + @as(i32, 9); | 14 | if (!ok) break :blk x + @as(i32, 9); |
| 14 | break :blk x + @as(i32, 19); | 15 | break :blk x + @as(i32, 19); |
| 15 | }; | 16 | }; |
test/cases/decl_value_arena.zig+1-1| ... | @@ -14,7 +14,7 @@ pub const Connection = struct { | ... | @@ -14,7 +14,7 @@ pub const Connection = struct { |
| 14 | 14 | ||
| 15 | pub fn main() void { | 15 | pub fn main() void { |
| 16 | var conn: Connection = undefined; | 16 | var conn: Connection = undefined; |
| 17 | _ = conn; | 17 | _ = &conn; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | // run | 20 | // run |
test/cases/enum_values.0.zig+2-2| ... | @@ -4,8 +4,8 @@ pub fn main() void { | ... | @@ -4,8 +4,8 @@ pub fn main() void { |
| 4 | var number1 = Number.One; | 4 | var number1 = Number.One; |
| 5 | var number2: Number = .Two; | 5 | var number2: Number = .Two; |
| 6 | if (false) { | 6 | if (false) { |
| 7 | number1; | 7 | &number1; |
| 8 | number2; | 8 | &number2; |
| 9 | } | 9 | } |
| 10 | const number3: Number = @enumFromInt(2); | 10 | const number3: Number = @enumFromInt(2); |
| 11 | if (@intFromEnum(number3) != 2) { | 11 | if (@intFromEnum(number3) != 2) { |
test/cases/enum_values.1.zig+3| ... | @@ -2,7 +2,9 @@ const Number = enum { One, Two, Three }; | ... | @@ -2,7 +2,9 @@ const Number = enum { One, Two, Three }; |
| 2 | 2 | ||
| 3 | pub fn main() void { | 3 | pub fn main() void { |
| 4 | var number1 = Number.One; | 4 | var number1 = Number.One; |
| 5 | _ = &number1; | ||
| 5 | var number2: Number = .Two; | 6 | var number2: Number = .Two; |
| 7 | _ = &number2; | ||
| 6 | const number3: Number = @enumFromInt(2); | 8 | const number3: Number = @enumFromInt(2); |
| 7 | assert(number1 != number2); | 9 | assert(number1 != number2); |
| 8 | assert(number2 != number3); | 10 | assert(number2 != number3); |
| ... | @@ -10,6 +12,7 @@ pub fn main() void { | ... | @@ -10,6 +12,7 @@ pub fn main() void { |
| 10 | assert(@intFromEnum(number2) == 1); | 12 | assert(@intFromEnum(number2) == 1); |
| 11 | assert(@intFromEnum(number3) == 2); | 13 | assert(@intFromEnum(number3) == 2); |
| 12 | var x: Number = .Two; | 14 | var x: Number = .Two; |
| 15 | _ = &x; | ||
| 13 | assert(number2 == x); | 16 | assert(number2 == x); |
| 14 | 17 | ||
| 15 | return; | 18 | return; |
test/cases/error_in_nested_declaration.zig+1-1| ... | @@ -19,7 +19,7 @@ const S2 = struct { | ... | @@ -19,7 +19,7 @@ const S2 = struct { |
| 19 | 19 | ||
| 20 | pub export fn entry2() void { | 20 | pub export fn entry2() void { |
| 21 | var s: S2 = undefined; | 21 | var s: S2 = undefined; |
| 22 | _ = s; | 22 | _ = &s; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | // error | 25 | // error |
test/cases/error_unions.0.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var e1 = error.Foo; | 2 | var e1 = error.Foo; |
| 3 | var e2 = error.Bar; | 3 | var e2 = error.Bar; |
| 4 | _ = .{ &e1, &e2 }; | ||
| 4 | assert(e1 != e2); | 5 | assert(e1 != e2); |
| 5 | assert(e1 == error.Foo); | 6 | assert(e1 == error.Foo); |
| 6 | assert(e2 == error.Bar); | 7 | assert(e2 == error.Bar); |
test/cases/error_unions.1.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var e: anyerror!u8 = 5; | 2 | var e: anyerror!u8 = 5; |
| 3 | _ = &e; | ||
| 3 | const i = e catch 10; | 4 | const i = e catch 10; |
| 4 | return i - 5; | 5 | return i - 5; |
| 5 | } | 6 | } |
test/cases/error_unions.2.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var e: anyerror!u8 = error.Foo; | 2 | var e: anyerror!u8 = error.Foo; |
| 3 | _ = &e; | ||
| 3 | const i = e catch 10; | 4 | const i = e catch 10; |
| 4 | return i - 10; | 5 | return i - 10; |
| 5 | } | 6 | } |
test/cases/error_unions.3.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var e = foo(); | 2 | var e = foo(); |
| 3 | _ = &e; | ||
| 3 | const i = e catch 69; | 4 | const i = e catch 69; |
| 4 | return i - 5; | 5 | return i - 5; |
| 5 | } | 6 | } |
test/cases/error_unions.4.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var e = foo(); | 2 | var e = foo(); |
| 3 | _ = &e; | ||
| 3 | const i = e catch 69; | 4 | const i = e catch 69; |
| 4 | return i - 69; | 5 | return i - 69; |
| 5 | } | 6 | } |
test/cases/error_unions.5.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var e = foo(); | 2 | var e = foo(); |
| 3 | _ = &e; | ||
| 3 | const i = e catch 42; | 4 | const i = e catch 42; |
| 4 | return i - 42; | 5 | return i - 42; |
| 5 | } | 6 | } |
test/cases/f32_passed_to_variadic_fn.zig+2-2| ... | @@ -2,8 +2,8 @@ extern fn printf(format: [*:0]const u8, ...) c_int; | ... | @@ -2,8 +2,8 @@ extern fn printf(format: [*:0]const u8, ...) c_int; |
| 2 | pub fn main() void { | 2 | pub fn main() void { |
| 3 | var a: f64 = 2.0; | 3 | var a: f64 = 2.0; |
| 4 | var b: f32 = 10.0; | 4 | var b: f32 = 10.0; |
| 5 | _ = printf("f64: %f\n", a); | 5 | _ = printf("f64: %f\n", (&a).*); |
| 6 | _ = printf("f32: %f\n", b); | 6 | _ = printf("f32: %f\n", (&b).*); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | // run | 9 | // run |
test/cases/inner_func_accessing_outer_var.zig+3-2| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn f() void { | 1 | pub fn f() void { |
| 2 | var bar: bool = true; | 2 | var bar: bool = true; |
| 3 | _ = &bar; | ||
| 3 | const S = struct { | 4 | const S = struct { |
| 4 | fn baz() bool { | 5 | fn baz() bool { |
| 5 | return bar; | 6 | return bar; |
| ... | @@ -10,6 +11,6 @@ pub fn f() void { | ... | @@ -10,6 +11,6 @@ pub fn f() void { |
| 10 | 11 | ||
| 11 | // error | 12 | // error |
| 12 | // | 13 | // |
| 13 | // :5:20: error: mutable 'bar' not accessible from here | 14 | // :6:20: error: mutable 'bar' not accessible from here |
| 14 | // :2:9: note: declared mutable here | 15 | // :2:9: note: declared mutable here |
| 15 | // :3:15: note: crosses namespace boundary here | 16 | // :4:15: note: crosses namespace boundary here |
test/cases/llvm/blocks.zig+1| ... | @@ -5,6 +5,7 @@ fn assert(ok: bool) void { | ... | @@ -5,6 +5,7 @@ fn assert(ok: bool) void { |
| 5 | fn foo(ok: bool) i32 { | 5 | fn foo(ok: bool) i32 { |
| 6 | const val: i32 = blk: { | 6 | const val: i32 = blk: { |
| 7 | var x: i32 = 1; | 7 | var x: i32 = 1; |
| 8 | _ = &x; | ||
| 8 | if (!ok) break :blk x + 9; | 9 | if (!ok) break :blk x + 9; |
| 9 | break :blk x + 19; | 10 | break :blk x + 19; |
| 10 | }; | 11 | }; |
test/cases/llvm/f_segment_address_space_reading_and_writing.zig+1| ... | @@ -35,6 +35,7 @@ pub fn main() void { | ... | @@ -35,6 +35,7 @@ pub fn main() void { |
| 35 | assert(getFs() == @intFromPtr(&test_value)); | 35 | assert(getFs() == @intFromPtr(&test_value)); |
| 36 | 36 | ||
| 37 | var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0); | 37 | var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0); |
| 38 | _ = &test_ptr; | ||
| 38 | assert(test_ptr.* == 12345); | 39 | assert(test_ptr.* == 12345); |
| 39 | test_ptr.* = 98765; | 40 | test_ptr.* = 98765; |
| 40 | assert(test_value == 98765); | 41 | assert(test_value == 98765); |
test/cases/llvm/nested_blocks.zig+1-1| ... | @@ -10,7 +10,7 @@ fn foo(ok: bool) i32 { | ... | @@ -10,7 +10,7 @@ fn foo(ok: bool) i32 { |
| 10 | }; | 10 | }; |
| 11 | break :blk val2 + 10; | 11 | break :blk val2 + 10; |
| 12 | }; | 12 | }; |
| 13 | return val; | 13 | return (&val).*; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | pub fn main() void { | 16 | pub fn main() void { |
test/cases/llvm/optionals.zig+4| ... | @@ -7,8 +7,10 @@ pub fn main() void { | ... | @@ -7,8 +7,10 @@ pub fn main() void { |
| 7 | var null_val: ?i32 = null; | 7 | var null_val: ?i32 = null; |
| 8 | 8 | ||
| 9 | var val1: i32 = opt_val.?; | 9 | var val1: i32 = opt_val.?; |
| 10 | _ = &val1; | ||
| 10 | const val1_1: i32 = opt_val.?; | 11 | const val1_1: i32 = opt_val.?; |
| 11 | var ptr_val1 = &(opt_val.?); | 12 | var ptr_val1 = &(opt_val.?); |
| 13 | _ = &ptr_val1; | ||
| 12 | const ptr_val1_1 = &(opt_val.?); | 14 | const ptr_val1_1 = &(opt_val.?); |
| 13 | 15 | ||
| 14 | var val2: i32 = null_val orelse 20; | 16 | var val2: i32 = null_val orelse 20; |
| ... | @@ -16,9 +18,11 @@ pub fn main() void { | ... | @@ -16,9 +18,11 @@ pub fn main() void { |
| 16 | 18 | ||
| 17 | var value: i32 = 20; | 19 | var value: i32 = 20; |
| 18 | var ptr_val2 = &(null_val orelse value); | 20 | var ptr_val2 = &(null_val orelse value); |
| 21 | _ = &ptr_val2; | ||
| 19 | 22 | ||
| 20 | const val3 = opt_val orelse 30; | 23 | const val3 = opt_val orelse 30; |
| 21 | var val3_var = opt_val orelse 30; | 24 | var val3_var = opt_val orelse 30; |
| 25 | _ = &val3_var; | ||
| 22 | 26 | ||
| 23 | assert(val1 == 10); | 27 | assert(val1 == 10); |
| 24 | assert(val1_1 == 10); | 28 | assert(val1_1 == 10); |
test/cases/llvm/simple_addition_and_subtraction.zig+1| ... | @@ -4,6 +4,7 @@ fn add(a: i32, b: i32) i32 { | ... | @@ -4,6 +4,7 @@ fn add(a: i32, b: i32) i32 { |
| 4 | 4 | ||
| 5 | pub fn main() void { | 5 | pub fn main() void { |
| 6 | var a: i32 = -5; | 6 | var a: i32 = -5; |
| 7 | _ = &a; | ||
| 7 | const x = add(a, 7); | 8 | const x = add(a, 7); |
| 8 | var y = add(2, 0); | 9 | var y = add(2, 0); |
| 9 | y -= x; | 10 | y -= x; |
test/cases/locals.0.zig+2-2| ... | @@ -3,8 +3,8 @@ pub fn main() void { | ... | @@ -3,8 +3,8 @@ pub fn main() void { |
| 3 | var y: f32 = 42.0; | 3 | var y: f32 = 42.0; |
| 4 | var x: u8 = 10; | 4 | var x: u8 = 10; |
| 5 | if (false) { | 5 | if (false) { |
| 6 | y; | 6 | &y; |
| 7 | x; | 7 | &x / &i; |
| 8 | } | 8 | } |
| 9 | if (i != 5) unreachable; | 9 | if (i != 5) unreachable; |
| 10 | } | 10 | } |
test/cases/locals.1.zig+2-1| ... | @@ -1,8 +1,9 @@ | ... | @@ -1,8 +1,9 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i: u8 = 5; | 2 | var i: u8 = 5; |
| 3 | var y: f32 = 42.0; | 3 | var y: f32 = 42.0; |
| 4 | _ = y; | 4 | _ = &y; |
| 5 | var x: u8 = 10; | 5 | var x: u8 = 10; |
| 6 | _ = &x; | ||
| 6 | foo(i, x); | 7 | foo(i, x); |
| 7 | i = x; | 8 | i = x; |
| 8 | if (i != 10) unreachable; | 9 | if (i != 10) unreachable; |
test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var x: usize = 5; | 2 | var x: usize = 5; |
| 3 | _ = &x; | ||
| 3 | const y = mul(2, 3, x); | 4 | const y = mul(2, 3, x); |
| 4 | if (y - 30 != 0) unreachable; | 5 | if (y - 30 != 0) unreachable; |
| 5 | } | 6 | } |
test/cases/only_1_function_and_it_gets_updated.1.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | pub export fn _start() noreturn { | 1 | pub export fn _start() noreturn { |
| 2 | var dummy: u32 = 10; | 2 | var dummy: u32 = 10; |
| 3 | _ = dummy; | 3 | _ = &dummy; |
| 4 | while (true) {} | 4 | while (true) {} |
| 5 | } | 5 | } |
| 6 | 6 |
test/cases/optionals.0.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var x: ?u8 = 5; | 2 | var x: ?u8 = 5; |
| 3 | _ = &x; | ||
| 3 | var y: u8 = 0; | 4 | var y: u8 = 0; |
| 4 | if (x) |val| { | 5 | if (x) |val| { |
| 5 | y = val; | 6 | y = val; |
test/cases/optionals.1.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var x: ?u8 = null; | 2 | var x: ?u8 = null; |
| 3 | _ = &x; | ||
| 3 | var y: u8 = 0; | 4 | var y: u8 = 0; |
| 4 | if (x) |val| { | 5 | if (x) |val| { |
| 5 | y = val; | 6 | y = val; |
test/cases/optionals.2.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var x: ?u8 = 5; | 2 | var x: ?u8 = 5; |
| 3 | _ = &x; | ||
| 3 | return x.? - 5; | 4 | return x.? - 5; |
| 4 | } | 5 | } |
| 5 | 6 |
test/cases/optionals.3.zig+1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var x: u8 = 5; | 2 | var x: u8 = 5; |
| 3 | var y: ?u8 = x; | 3 | var y: ?u8 = x; |
| 4 | _ = .{ &x, &y }; | ||
| 4 | return y.? - 5; | 5 | return y.? - 5; |
| 5 | } | 6 | } |
| 6 | 7 |
test/cases/runtime_bitwise_and.zig+1| ... | @@ -7,6 +7,7 @@ pub fn main() void { | ... | @@ -7,6 +7,7 @@ pub fn main() void { |
| 7 | var m2: u32 = 0b0000; | 7 | var m2: u32 = 0b0000; |
| 8 | assert(m1 & 0b1010 == 0b1010); | 8 | assert(m1 & 0b1010 == 0b1010); |
| 9 | assert(m2 & 0b1010 == 0b0000); | 9 | assert(m2 & 0b1010 == 0b0000); |
| 10 | _ = .{ &i, &j, &m1, &m2 }; | ||
| 10 | } | 11 | } |
| 11 | fn assert(b: bool) void { | 12 | fn assert(b: bool) void { |
| 12 | if (!b) unreachable; | 13 | if (!b) unreachable; |
test/cases/runtime_bitwise_or.zig+1| ... | @@ -7,6 +7,7 @@ pub fn main() void { | ... | @@ -7,6 +7,7 @@ pub fn main() void { |
| 7 | var m2: u32 = 0b0000; | 7 | var m2: u32 = 0b0000; |
| 8 | assert(m1 | 0b1010 == 0b1111); | 8 | assert(m1 | 0b1010 == 0b1111); |
| 9 | assert(m2 | 0b1010 == 0b1010); | 9 | assert(m2 | 0b1010 == 0b1010); |
| 10 | _ = .{ &i, &j, &m1, &m2 }; | ||
| 10 | } | 11 | } |
| 11 | fn assert(b: bool) void { | 12 | fn assert(b: bool) void { |
| 12 | if (!b) unreachable; | 13 | if (!b) unreachable; |
test/cases/safety/@asyncCall with too small a frame.zig	+2-1| ... | @@ -13,8 +13,9 @@ pub fn main() !void { | ... | @@ -13,8 +13,9 @@ pub fn main() !void { |
| 13 | } | 13 | } |
| 14 | var bytes: [1]u8 align(16) = undefined; | 14 | var bytes: [1]u8 align(16) = undefined; |
| 15 | var ptr = other; | 15 | var ptr = other; |
| 16 | _ = &ptr; | ||
| 16 | var frame = @asyncCall(&bytes, {}, ptr, .{}); | 17 | var frame = @asyncCall(&bytes, {}, ptr, .{}); |
| 17 | _ = frame; | 18 | _ = &frame; |
| 18 | return error.TestFailed; | 19 | return error.TestFailed; |
| 19 | } | 20 | } |
| 20 | fn other() callconv(.Async) void { | 21 | fn other() callconv(.Async) void { |
test/cases/safety/@intCast to u0.zig	+1-1| ... | @@ -14,7 +14,7 @@ pub fn main() !void { | ... | @@ -14,7 +14,7 @@ pub fn main() !void { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn bar(one: u1, not_zero: i32) void { | 16 | fn bar(one: u1, not_zero: i32) void { |
| 17 | var x = one << @as(u0, @intCast(not_zero)); | 17 | const x = one << @intCast(not_zero); |
| 18 | _ = x; | 18 | _ = x; |
| 19 | } | 19 | } |
| 20 | // run | 20 | // run |
test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig	+2-1| ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var zero: usize = 0; | 11 | var zero: usize = 0; |
| 12 | var b: *u8 = @ptrFromInt(zero); | 12 | _ = &zero; |
| 13 | const b: *u8 = @ptrFromInt(zero); | ||
| 13 | _ = b; | 14 | _ = b; |
| 14 | return error.TestFailed; | 15 | return error.TestFailed; |
| 15 | } | 16 | } |
test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig	+2-1| ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var zero: usize = 0; | 11 | var zero: usize = 0; |
| 12 | var b: *i32 = @ptrFromInt(zero); | 12 | _ = &zero; |
| 13 | const b: *i32 = @ptrFromInt(zero); | ||
| 13 | _ = b; | 14 | _ = b; |
| 14 | return error.TestFailed; | 15 | return error.TestFailed; |
| 15 | } | 16 | } |
test/cases/safety/@ptrFromInt with misaligned address.zig	+2-1| ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var x: usize = 5; | 11 | var x: usize = 5; |
| 12 | var y: [*]align(4) u8 = @ptrFromInt(x); | 12 | _ = &x; |
| 13 | const y: [*]align(4) u8 = @ptrFromInt(x); | ||
| 13 | _ = y; | 14 | _ = y; |
| 14 | return error.TestFailed; | 15 | return error.TestFailed; |
| 15 | } | 16 | } |
test/cases/safety/@tagName on corrupted enum value.zig	+1-1| ... | @@ -16,7 +16,7 @@ const E = enum(u32) { | ... | @@ -16,7 +16,7 @@ const E = enum(u32) { |
| 16 | pub fn main() !void { | 16 | pub fn main() !void { |
| 17 | var e: E = undefined; | 17 | var e: E = undefined; |
| 18 | @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55); | 18 | @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55); |
| 19 | var n = @tagName(e); | 19 | const n = @tagName(e); |
| 20 | _ = n; | 20 | _ = n; |
| 21 | return error.TestFailed; | 21 | return error.TestFailed; |
| 22 | } | 22 | } |
test/cases/safety/@tagName on corrupted union value.zig	+2-2| ... | @@ -16,8 +16,8 @@ const U = union(enum(u32)) { | ... | @@ -16,8 +16,8 @@ const U = union(enum(u32)) { |
| 16 | pub fn main() !void { | 16 | pub fn main() !void { |
| 17 | var u: U = undefined; | 17 | var u: U = undefined; |
| 18 | @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55); | 18 | @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55); |
| 19 | var t: @typeInfo(U).Union.tag_type.? = u; | 19 | const t: @typeInfo(U).Union.tag_type.? = u; |
| 20 | var n = @tagName(t); | 20 | const n = @tagName(t); |
| 21 | _ = n; | 21 | _ = n; |
| 22 | return error.TestFailed; | 22 | return error.TestFailed; |
| 23 | } | 23 | } |
test/cases/safety/array slice sentinel mismatch non-scalar.zig	+1-1| ... | @@ -11,7 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -11,7 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | const S = struct { a: u32 }; | 12 | const S = struct { a: u32 }; |
| 13 | var arr = [_]S{ .{ .a = 1 }, .{ .a = 2 } }; | 13 | var arr = [_]S{ .{ .a = 1 }, .{ .a = 2 } }; |
| 14 | var s = arr[0..1 :.{ .a = 1 }]; | 14 | const s = arr[0..1 :.{ .a = 1 }]; |
| 15 | _ = s; | 15 | _ = s; |
| 16 | return error.TestFailed; | 16 | return error.TestFailed; |
| 17 | } | 17 | } |
test/cases/safety/exact division failure - vectors.zig	+2-2| ... | @@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; | 12 | const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; |
| 13 | var b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 }; | 13 | const b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 }; |
| 14 | const x = divExact(a, b); | 14 | const x = divExact(a, b); |
| 15 | _ = x; | 15 | _ = x; |
| 16 | return error.TestFailed; | 16 | return error.TestFailed; |
test/cases/safety/for_len_mismatch.zig+1| ... | @@ -12,6 +12,7 @@ pub fn main() !void { | ... | @@ -12,6 +12,7 @@ pub fn main() !void { |
| 12 | var runtime_i: usize = 1; | 12 | var runtime_i: usize = 1; |
| 13 | var j: usize = 3; | 13 | var j: usize = 3; |
| 14 | var slice = "too long"; | 14 | var slice = "too long"; |
| 15 | _ = .{ &runtime_i, &j, &slice }; | ||
| 15 | for (runtime_i..j, slice) |a, b| { | 16 | for (runtime_i..j, slice) |a, b| { |
| 16 | _ = a; | 17 | _ = a; |
| 17 | _ = b; | 18 | _ = b; |
test/cases/safety/for_len_mismatch_three.zig+1| ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var slice: []const u8 = "hello"; | 12 | var slice: []const u8 = "hello"; |
| 13 | _ = &slice; | ||
| 13 | for (10..20, slice, 20..30) |a, b, c| { | 14 | for (10..20, slice, 20..30) |a, b, c| { |
| 14 | _ = a; | 15 | _ = a; |
| 15 | _ = b; | 16 | _ = b; |
test/cases/safety/integer division by zero - vectors.zig	+2-2| ... | @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; | 11 | const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; |
| 12 | var b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 }; | 12 | const b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 }; |
| 13 | const x = div0(a, b); | 13 | const x = div0(a, b); |
| 14 | _ = x; | 14 | _ = x; |
| 15 | return error.TestFailed; | 15 | return error.TestFailed; |
test/cases/safety/memcpy_alias.zig+1| ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [2]u8{ 1, 2 } ** 5; | 11 | var buffer = [2]u8{ 1, 2 } ** 5; |
| 12 | var len: usize = 5; | 12 | var len: usize = 5; |
| 13 | _ = &len; | ||
| 13 | @memcpy(buffer[0..len], buffer[4 .. 4 + len]); | 14 | @memcpy(buffer[0..len], buffer[4 .. 4 + len]); |
| 14 | } | 15 | } |
| 15 | // run | 16 | // run |
test/cases/safety/memcpy_len_mismatch.zig+1| ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [2]u8{ 1, 2 } ** 5; | 11 | var buffer = [2]u8{ 1, 2 } ** 5; |
| 12 | var len: usize = 5; | 12 | var len: usize = 5; |
| 13 | _ = &len; | ||
| 13 | @memcpy(buffer[0..len], buffer[len .. len + 4]); | 14 | @memcpy(buffer[0..len], buffer[len .. len + 4]); |
| 14 | } | 15 | } |
| 15 | // run | 16 | // run |
test/cases/safety/memset_slice_undefined_bytes.zig+1| ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [6]u8{ 1, 2, 3, 4, 5, 6 }; | 11 | var buffer = [6]u8{ 1, 2, 3, 4, 5, 6 }; |
| 12 | var len = buffer.len; | 12 | var len = buffer.len; |
| 13 | _ = &len; | ||
| 13 | @memset(buffer[0..len], undefined); | 14 | @memset(buffer[0..len], undefined); |
| 14 | var x: u8 = buffer[1]; | 15 | var x: u8 = buffer[1]; |
| 15 | x += buffer[2]; | 16 | x += buffer[2]; |
test/cases/safety/memset_slice_undefined_large.zig+1| ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [6]i32{ 1, 2, 3, 4, 5, 6 }; | 11 | var buffer = [6]i32{ 1, 2, 3, 4, 5, 6 }; |
| 12 | var len = buffer.len; | 12 | var len = buffer.len; |
| 13 | _ = &len; | ||
| 13 | @memset(buffer[0..len], undefined); | 14 | @memset(buffer[0..len], undefined); |
| 14 | var x: i32 = buffer[1]; | 15 | var x: i32 = buffer[1]; |
| 15 | x += buffer[2]; | 16 | x += buffer[2]; |
test/cases/safety/optional unwrap operator on C pointer.zig	+2-1| ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var ptr: [*c]i32 = null; | 11 | var ptr: [*c]i32 = null; |
| 12 | var b = ptr.?; | 12 | _ = &ptr; |
| 13 | const b = ptr.?; | ||
| 13 | _ = b; | 14 | _ = b; |
| 14 | return error.TestFailed; | 15 | return error.TestFailed; |
| 15 | } | 16 | } |
test/cases/safety/optional unwrap operator on null pointer.zig	+2-1| ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var ptr: ?*i32 = null; | 11 | var ptr: ?*i32 = null; |
| 12 | var b = ptr.?; | 12 | _ = &ptr; |
| 13 | const b = ptr.?; | ||
| 13 | _ = b; | 14 | _ = b; |
| 14 | return error.TestFailed; | 15 | return error.TestFailed; |
| 15 | } | 16 | } |
test/cases/safety/pointer casting null to non-optional pointer.zig	+2-1| ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var c_ptr: [*c]u8 = 0; | 12 | var c_ptr: [*c]u8 = 0; |
| 13 | var zig_ptr: *u8 = c_ptr; | 13 | _ = &c_ptr; |
| 14 | const zig_ptr: *u8 = c_ptr; | ||
| 14 | _ = zig_ptr; | 15 | _ = zig_ptr; |
| 15 | return error.TestFailed; | 16 | return error.TestFailed; |
| 16 | } | 17 | } |
test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig	+1-1| ... | @@ -10,7 +10,7 @@ fn foo() void { | ... | @@ -10,7 +10,7 @@ fn foo() void { |
| 10 | global_frame = @frame(); | 10 | global_frame = @frame(); |
| 11 | } | 11 | } |
| 12 | var f = async bar(@frame()); | 12 | var f = async bar(@frame()); |
| 13 | _ = f; | 13 | _ = &f; |
| 14 | std.os.exit(1); | 14 | std.os.exit(1); |
| 15 | } | 15 | } |
| 16 | 16 |
test/cases/safety/resuming a non-suspended function which never been suspended.zig	+1-1| ... | @@ -7,7 +7,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -7,7 +7,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 7 | } | 7 | } |
| 8 | fn foo() void { | 8 | fn foo() void { |
| 9 | var f = async bar(@frame()); | 9 | var f = async bar(@frame()); |
| 10 | _ = f; | 10 | _ = &f; |
| 11 | std.os.exit(1); | 11 | std.os.exit(1); |
| 12 | } | 12 | } |
| 13 | 13 |
test/cases/safety/shift left by huge amount.zig	+2-1| ... | @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var x: u24 = 42; | 12 | var x: u24 = 42; |
| 13 | var y: u5 = 24; | 13 | var y: u5 = 24; |
| 14 | var z = x >> y; | 14 | _ = .{ &x, &y }; |
| 15 | const z = x >> y; | ||
| 15 | _ = z; | 16 | _ = z; |
| 16 | return error.TestFailed; | 17 | return error.TestFailed; |
| 17 | } | 18 | } |
test/cases/safety/shift right by huge amount.zig	+2-1| ... | @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var x: u24 = 42; | 12 | var x: u24 = 42; |
| 13 | var y: u5 = 24; | 13 | var y: u5 = 24; |
| 14 | var z = x << y; | 14 | _ = .{ &x, &y }; |
| 15 | const z = x << y; | ||
| 15 | _ = z; | 16 | _ = z; |
| 16 | return error.TestFailed; | 17 | return error.TestFailed; |
| 17 | } | 18 | } |
test/cases/safety/signed integer division overflow - vectors.zig	+2-2| ... | @@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 }; | 12 | const a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 }; |
| 13 | var b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 }; | 13 | const b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 }; |
| 14 | const x = div(a, b); | 14 | const x = div(a, b); |
| 15 | if (x[2] == 32767) return error.Whatever; | 15 | if (x[2] == 32767) return error.Whatever; |
| 16 | return error.TestFailed; | 16 | return error.TestFailed; |
test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig	+2-1| ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var value: c_short = -1; | 11 | var value: c_short = -1; |
| 12 | var casted: u32 = @intCast(value); | 12 | _ = &value; |
| 13 | const casted: u32 = @intCast(value); | ||
| 13 | _ = casted; | 14 | _ = casted; |
| 14 | return error.TestFailed; | 15 | return error.TestFailed; |
| 15 | } | 16 | } |
test/cases/safety/signed-unsigned vector cast.zig	+2-1| ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var x: @Vector(4, i32) = @splat(-2147483647); | 12 | var x: @Vector(4, i32) = @splat(-2147483647); |
| 13 | var y: @Vector(4, u32) = @intCast(x); | 13 | _ = &x; |
| 14 | const y: @Vector(4, u32) = @intCast(x); | ||
| 14 | _ = y; | 15 | _ = y; |
| 15 | return error.TestFailed; | 16 | return error.TestFailed; |
| 16 | } | 17 | } |
test/cases/safety/slice start index greater than end index.zig	+1| ... | @@ -11,6 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -11,6 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var a: usize = 1; | 12 | var a: usize = 1; |
| 13 | var b: usize = 10; | 13 | var b: usize = 10; |
| 14 | _ = .{ &a, &b }; | ||
| 14 | var buf: [16]u8 = undefined; | 15 | var buf: [16]u8 = undefined; |
| 15 | 16 | ||
| 16 | const slice = buf[b..a]; | 17 | const slice = buf[b..a]; |
test/cases/safety/slice with sentinel out of bounds - runtime len.zig	+1| ... | @@ -12,6 +12,7 @@ pub fn main() !void { | ... | @@ -12,6 +12,7 @@ pub fn main() !void { |
| 12 | var buf = [4]u8{ 'a', 'b', 'c', 0 }; | 12 | var buf = [4]u8{ 'a', 'b', 'c', 0 }; |
| 13 | const input: []u8 = &buf; | 13 | const input: []u8 = &buf; |
| 14 | var len: usize = 4; | 14 | var len: usize = 4; |
| 15 | _ = &len; | ||
| 15 | const slice = input[0..len :0]; | 16 | const slice = input[0..len :0]; |
| 16 | _ = slice; | 17 | _ = slice; |
| 17 | return error.TestFailed; | 18 | return error.TestFailed; |
test/cases/safety/slicing null C pointer - runtime len.zig	+2-1| ... | @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var ptr: [*c]const u32 = null; | 12 | var ptr: [*c]const u32 = null; |
| 13 | var len: usize = 3; | 13 | var len: usize = 3; |
| 14 | var slice = ptr[0..len]; | 14 | _ = &len; |
| 15 | const slice = ptr[0..len]; | ||
| 15 | _ = slice; | 16 | _ = slice; |
| 16 | return error.TestFailed; | 17 | return error.TestFailed; |
| 17 | } | 18 | } |
test/cases/safety/slicing null C pointer.zig	+2-1| ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var ptr: [*c]const u32 = null; | 12 | var ptr: [*c]const u32 = null; |
| 13 | var slice = ptr[0..3]; | 13 | _ = &ptr; |
| 14 | const slice = ptr[0..3]; | ||
| 14 | _ = slice; | 15 | _ = slice; |
| 15 | return error.TestFailed; | 16 | return error.TestFailed; |
| 16 | } | 17 | } |
test/cases/safety/truncating vector cast.zig	+2-1| ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var x: @Vector(4, u32) = @splat(0xdeadbeef); | 12 | var x: @Vector(4, u32) = @splat(0xdeadbeef); |
| 13 | var y: @Vector(4, u16) = @intCast(x); | 13 | _ = &x; |
| 14 | const y: @Vector(4, u16) = @intCast(x); | ||
| 14 | _ = y; | 15 | _ = y; |
| 15 | return error.TestFailed; | 16 | return error.TestFailed; |
| 16 | } | 17 | } |
test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig	+2-1| ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var value: u8 = 245; | 11 | var value: u8 = 245; |
| 12 | var casted: i8 = @intCast(value); | 12 | _ = &value; |
| 13 | const casted: i8 = @intCast(value); | ||
| 13 | _ = casted; | 14 | _ = casted; |
| 14 | return error.TestFailed; | 15 | return error.TestFailed; |
| 15 | } | 16 | } |
test/cases/safety/unsigned-signed vector cast.zig	+2-1| ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var x: @Vector(4, u32) = @splat(0x80000000); | 12 | var x: @Vector(4, u32) = @splat(0x80000000); |
| 13 | var y: @Vector(4, i32) = @intCast(x); | 13 | _ = &x; |
| 14 | const y: @Vector(4, i32) = @intCast(x); | ||
| 14 | _ = y; | 15 | _ = y; |
| 15 | return error.TestFailed; | 16 | return error.TestFailed; |
| 16 | } | 17 | } |
test/cases/safety/vector integer addition overflow.zig	+2-2| ... | @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 }; | 11 | const a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 }; |
| 12 | var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; | 12 | const b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; |
| 13 | const x = add(a, b); | 13 | const x = add(a, b); |
| 14 | _ = x; | 14 | _ = x; |
| 15 | return error.TestFailed; | 15 | return error.TestFailed; |
test/cases/safety/vector integer multiplication overflow.zig	+2-2| ... | @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 }; | 11 | const a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 }; |
| 12 | var b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 }; | 12 | const b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 }; |
| 13 | const x = mul(b, a); | 13 | const x = mul(b, a); |
| 14 | _ = x; | 14 | _ = x; |
| 15 | return error.TestFailed; | 15 | return error.TestFailed; |
test/cases/safety/vector integer negation overflow.zig	+1| ... | @@ -9,6 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -9,6 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 }; | 11 | var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 }; |
| 12 | _ = &a; | ||
| 12 | const x = neg(a); | 13 | const x = neg(a); |
| 13 | _ = x; | 14 | _ = x; |
| 14 | return error.TestFailed; | 15 | return error.TestFailed; |
test/cases/safety/vector integer subtraction overflow.zig	+2-2| ... | @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 }; | 11 | const a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 }; |
| 12 | var b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 }; | 12 | const b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 }; |
| 13 | const x = sub(b, a); | 13 | const x = sub(b, a); |
| 14 | _ = x; | 14 | _ = x; |
| 15 | return error.TestFailed; | 15 | return error.TestFailed; |
test/cases/structs.0.zig+1| ... | @@ -2,6 +2,7 @@ const Example = struct { x: u8 }; | ... | @@ -2,6 +2,7 @@ const Example = struct { x: u8 }; |
| 2 | 2 | ||
| 3 | pub fn main() u8 { | 3 | pub fn main() u8 { |
| 4 | var example: Example = .{ .x = 5 }; | 4 | var example: Example = .{ .x = 5 }; |
| 5 | _ = &example; | ||
| 5 | return example.x - 5; | 6 | return example.x - 5; |
| 6 | } | 7 | } |
| 7 | 8 |
test/cases/structs.2.zig+1| ... | @@ -2,6 +2,7 @@ const Example = struct { x: u8, y: u8 }; | ... | @@ -2,6 +2,7 @@ const Example = struct { x: u8, y: u8 }; |
| 2 | 2 | ||
| 3 | pub fn main() u8 { | 3 | pub fn main() u8 { |
| 4 | var example: Example = .{ .x = 5, .y = 10 }; | 4 | var example: Example = .{ .x = 5, .y = 10 }; |
| 5 | _ = &example; | ||
| 5 | return example.y + example.x - 15; | 6 | return example.y + example.x - 15; |
| 6 | } | 7 | } |
| 7 | 8 |
test/cases/structs.3.zig+1| ... | @@ -3,6 +3,7 @@ const Example = struct { x: u8, y: u8 }; | ... | @@ -3,6 +3,7 @@ const Example = struct { x: u8, y: u8 }; |
| 3 | pub fn main() u8 { | 3 | pub fn main() u8 { |
| 4 | var example: Example = .{ .x = 5, .y = 10 }; | 4 | var example: Example = .{ .x = 5, .y = 10 }; |
| 5 | var example2: Example = .{ .x = 10, .y = 20 }; | 5 | var example2: Example = .{ .x = 10, .y = 20 }; |
| 6 | _ = &example2; | ||
| 6 | 7 | ||
| 7 | example = example2; | 8 | example = example2; |
| 8 | return example.y + example.x - 30; | 9 | return example.y + example.x - 30; |
test/cases/switch.0.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var val: u8 = 1; | 2 | var val: u8 = 1; |
| 3 | var a: u8 = switch (val) { | 3 | _ = &val; |
| 4 | const a: u8 = switch (val) { | ||
| 4 | 0, 1 => 2, | 5 | 0, 1 => 2, |
| 5 | 2 => 3, | 6 | 2 => 3, |
| 6 | 3 => 4, | 7 | 3 => 4, |
test/cases/switch.1.zig+2| ... | @@ -1,11 +1,13 @@ | ... | @@ -1,11 +1,13 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var val: u8 = 2; | 2 | var val: u8 = 2; |
| 3 | _ = &val; | ||
| 3 | var a: u8 = switch (val) { | 4 | var a: u8 = switch (val) { |
| 4 | 0, 1 => 2, | 5 | 0, 1 => 2, |
| 5 | 2 => 3, | 6 | 2 => 3, |
| 6 | 3 => 4, | 7 | 3 => 4, |
| 7 | else => 5, | 8 | else => 5, |
| 8 | }; | 9 | }; |
| 10 | _ = &a; | ||
| 9 | 11 | ||
| 10 | return a - 3; | 12 | return a - 3; |
| 11 | } | 13 | } |
test/cases/switch.2.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | pub fn main() u8 { | 1 | pub fn main() u8 { |
| 2 | var val: u8 = 10; | 2 | var val: u8 = 10; |
| 3 | var a: u8 = switch (val) { | 3 | _ = &val; |
| 4 | const a: u8 = switch (val) { | ||
| 4 | 0, 1 => 2, | 5 | 0, 1 => 2, |
| 5 | 2 => 3, | 6 | 2 => 3, |
| 6 | 3 => 4, | 7 | 3 => 4, |
test/cases/switch.3.zig+2-1| ... | @@ -2,7 +2,8 @@ const MyEnum = enum { One, Two, Three }; | ... | @@ -2,7 +2,8 @@ const MyEnum = enum { One, Two, Three }; |
| 2 | 2 | ||
| 3 | pub fn main() u8 { | 3 | pub fn main() u8 { |
| 4 | var val: MyEnum = .Two; | 4 | var val: MyEnum = .Two; |
| 5 | var a: u8 = switch (val) { | 5 | _ = &val; |
| 6 | const a: u8 = switch (val) { | ||
| 6 | .One => 1, | 7 | .One => 1, |
| 7 | .Two => 2, | 8 | .Two => 2, |
| 8 | .Three => 3, | 9 | .Three => 3, |
test/cases/type_of.0.zig+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var x: usize = 0; | 2 | var x: usize = 0; |
| 3 | _ = &x; | ||
| 3 | const z = @TypeOf(x, @as(u128, 5)); | 4 | const z = @TypeOf(x, @as(u128, 5)); |
| 4 | assert(z == u128); | 5 | assert(z == u128); |
| 5 | } | 6 | } |
test/cases/while_loops.1.zig+1| ... | @@ -2,6 +2,7 @@ pub fn main() u8 { | ... | @@ -2,6 +2,7 @@ pub fn main() u8 { |
| 2 | var i: u8 = 0; | 2 | var i: u8 = 0; |
| 3 | while (i < @as(u8, 10)) { | 3 | while (i < @as(u8, 10)) { |
| 4 | var x: u8 = 1; | 4 | var x: u8 = 1; |
| 5 | _ = &x; | ||
| 5 | i += x; | 6 | i += x; |
| 6 | } | 7 | } |
| 7 | return i - 10; | 8 | return i - 10; |
test/cases/while_loops.2.zig+1| ... | @@ -2,6 +2,7 @@ pub fn main() u8 { | ... | @@ -2,6 +2,7 @@ pub fn main() u8 { |
| 2 | var i: u8 = 0; | 2 | var i: u8 = 0; |
| 3 | while (i < @as(u8, 10)) { | 3 | while (i < @as(u8, 10)) { |
| 4 | var x: u8 = 1; | 4 | var x: u8 = 1; |
| 5 | _ = &x; | ||
| 5 | i += x; | 6 | i += x; |
| 6 | if (i == @as(u8, 5)) break; | 7 | if (i == @as(u8, 5)) break; |
| 7 | } | 8 | } |
test/compare_output.zig+2-2| ... | @@ -165,7 +165,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -165,7 +165,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 165 | \\const y : u16 = 5678; | 165 | \\const y : u16 = 5678; |
| 166 | \\pub fn main() void { | 166 | \\pub fn main() void { |
| 167 | \\ var x_local : i32 = print_ok(x); | 167 | \\ var x_local : i32 = print_ok(x); |
| 168 | \\ _ = x_local; | 168 | \\ _ = &x_local; |
| 169 | \\} | 169 | \\} |
| 170 | \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) { | 170 | \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) { |
| 171 | \\ _ = val; | 171 | \\ _ = val; |
| ... | @@ -504,7 +504,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -504,7 +504,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 504 | \\ | 504 | \\ |
| 505 | \\pub fn main() !void { | 505 | \\pub fn main() !void { |
| 506 | \\ var allocator_buf: [10]u8 = undefined; | 506 | \\ var allocator_buf: [10]u8 = undefined; |
| 507 | \\ var fba = std.heap.FixedBufferAllocator.init(&allocator_buf); | 507 | \\ const fba = std.heap.FixedBufferAllocator.init(&allocator_buf); |
| 508 | \\ var fba_wrapped = std.mem.validationWrap(fba); | 508 | \\ var fba_wrapped = std.mem.validationWrap(fba); |
| 509 | \\ var logging_allocator = std.heap.loggingAllocator(fba_wrapped.allocator()); | 509 | \\ var logging_allocator = std.heap.loggingAllocator(fba_wrapped.allocator()); |
| 510 | \\ const allocator = logging_allocator.allocator(); | 510 | \\ const allocator = logging_allocator.allocator(); |
test/link/wasm/archive/main.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | var a: f16 = 2.2; | 2 | var a: f16 = 2.2; |
| 3 | _ = &a; | ||
| 3 | // this will pull-in compiler-rt | 4 | // this will pull-in compiler-rt |
| 4 | var b = @trunc(a); | 5 | const b = @trunc(a); |
| 5 | _ = b; | 6 | _ = b; |
| 6 | } | 7 | } |
test/src/Cases.zig+2-5| ... | @@ -1161,10 +1161,7 @@ const TestManifest = struct { | ... | @@ -1161,10 +1161,7 @@ const TestManifest = struct { |
| 1161 | fn getDefaultParser(comptime T: type) ParseFn(T) { | 1161 | fn getDefaultParser(comptime T: type) ParseFn(T) { |
| 1162 | if (T == CrossTarget) return struct { | 1162 | if (T == CrossTarget) return struct { |
| 1163 | fn parse(str: []const u8) anyerror!T { | 1163 | fn parse(str: []const u8) anyerror!T { |
| 1164 | var opts = CrossTarget.ParseOptions{ | 1164 | return CrossTarget.parse(.{ .arch_os_abi = str }); |
| 1165 | .arch_os_abi = str, | ||
| 1166 | }; | ||
| 1167 | return try CrossTarget.parse(opts); | ||
| 1168 | } | 1165 | } |
| 1169 | }.parse; | 1166 | }.parse; |
| 1170 | 1167 | ||
| ... | @@ -1691,7 +1688,7 @@ fn runOneCase( | ... | @@ -1691,7 +1688,7 @@ fn runOneCase( |
| 1691 | var argv = std.ArrayList([]const u8).init(allocator); | 1688 | var argv = std.ArrayList([]const u8).init(allocator); |
| 1692 | defer argv.deinit(); | 1689 | defer argv.deinit(); |
| 1693 | 1690 | ||
| 1694 | var exec_result = x: { | 1691 | const exec_result = x: { |
| 1695 | var exec_node = update_node.start("execute", 0); | 1692 | var exec_node = update_node.start("execute", 0); |
| 1696 | exec_node.activate(); | 1693 | exec_node.activate(); |
| 1697 | defer exec_node.end(); | 1694 | defer exec_node.end(); |
test/standalone/extern/main.zig+2-2| ... | @@ -6,8 +6,8 @@ const getHidden = @extern(*const fn () callconv(.C) u32, .{ .name = "getHidden" | ... | @@ -6,8 +6,8 @@ const getHidden = @extern(*const fn () callconv(.C) u32, .{ .name = "getHidden" |
| 6 | const T = extern struct { x: u32 }; | 6 | const T = extern struct { x: u32 }; |
| 7 | 7 | ||
| 8 | test { | 8 | test { |
| 9 | var mut_val_ptr = @extern(*f64, .{ .name = "mut_val" }); | 9 | const mut_val_ptr = @extern(*f64, .{ .name = "mut_val" }); |
| 10 | var const_val_ptr = @extern(*const T, .{ .name = "const_val" }); | 10 | const const_val_ptr = @extern(*const T, .{ .name = "const_val" }); |
| 11 | 11 | ||
| 12 | assert(getHidden() == 0); | 12 | assert(getHidden() == 0); |
| 13 | updateHidden(123); | 13 | updateHidden(123); |
test/standalone/main_return_error/error_u8_non_zero.zig+1-2| ... | @@ -1,8 +1,7 @@ | ... | @@ -1,8 +1,7 @@ |
| 1 | const Err = error{Foo}; | 1 | const Err = error{Foo}; |
| 2 | 2 | ||
| 3 | fn foo() u8 { | 3 | fn foo() u8 { |
| 4 | var x = @as(u8, @intCast(9)); | 4 | return @intCast(9); |
| 5 | return x; | ||
| 6 | } | 5 | } |
| 7 | 6 | ||
| 8 | pub fn main() !u8 { | 7 | pub fn main() !u8 { |
test/standalone/stack_iterator/shared_lib_unwind.zig+1-1| ... | @@ -9,7 +9,7 @@ noinline fn frame4(expected: *[5]usize, unwound: *[5]usize) void { | ... | @@ -9,7 +9,7 @@ noinline fn frame4(expected: *[5]usize, unwound: *[5]usize) void { |
| 9 | var context: debug.ThreadContext = undefined; | 9 | var context: debug.ThreadContext = undefined; |
| 10 | testing.expect(debug.getContext(&context)) catch @panic("failed to getContext"); | 10 | testing.expect(debug.getContext(&context)) catch @panic("failed to getContext"); |
| 11 | 11 | ||
| 12 | var debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); | 12 | const debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); |
| 13 | var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext"); | 13 | var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext"); |
| 14 | defer it.deinit(); | 14 | defer it.deinit(); |
| 15 | 15 |
test/standalone/stack_iterator/unwind.zig+2-2| ... | @@ -9,7 +9,7 @@ noinline fn frame3(expected: *[4]usize, unwound: *[4]usize) void { | ... | @@ -9,7 +9,7 @@ noinline fn frame3(expected: *[4]usize, unwound: *[4]usize) void { |
| 9 | var context: debug.ThreadContext = undefined; | 9 | var context: debug.ThreadContext = undefined; |
| 10 | testing.expect(debug.getContext(&context)) catch @panic("failed to getContext"); | 10 | testing.expect(debug.getContext(&context)) catch @panic("failed to getContext"); |
| 11 | 11 | ||
| 12 | var debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); | 12 | const debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); |
| 13 | var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext"); | 13 | var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext"); |
| 14 | defer it.deinit(); | 14 | defer it.deinit(); |
| 15 | 15 | ||
| ... | @@ -76,7 +76,7 @@ noinline fn frame1(expected: *[4]usize, unwound: *[4]usize) void { | ... | @@ -76,7 +76,7 @@ noinline fn frame1(expected: *[4]usize, unwound: *[4]usize) void { |
| 76 | // Use a stack frame that is too big to encode in __unwind_info's stack-immediate encoding | 76 | // Use a stack frame that is too big to encode in __unwind_info's stack-immediate encoding |
| 77 | // to exercise the stack-indirect encoding path | 77 | // to exercise the stack-indirect encoding path |
| 78 | var pad: [std.math.maxInt(u8) * @sizeOf(usize) + 1]u8 = undefined; | 78 | var pad: [std.math.maxInt(u8) * @sizeOf(usize) + 1]u8 = undefined; |
| 79 | _ = pad; | 79 | _ = std.mem.doNotOptimizeAway(&pad); |
| 80 | 80 | ||
| 81 | frame2(expected, unwound); | 81 | frame2(expected, unwound); |
| 82 | } | 82 | } |
test/standalone/use_alias/main.zig+1| ... | @@ -6,5 +6,6 @@ test "symbol exists" { | ... | @@ -6,5 +6,6 @@ test "symbol exists" { |
| 6 | .a = 1, | 6 | .a = 1, |
| 7 | .b = 1, | 7 | .b = 1, |
| 8 | }; | 8 | }; |
| 9 | _ = &foo; | ||
| 9 | try expect(foo.a + foo.b == 2); | 10 | try expect(foo.a + foo.b == 2); |
| 10 | } | 11 | } |
test/standalone/windows_spawn/main.zig+1-1| ... | @@ -158,7 +158,7 @@ fn testExec(allocator: std.mem.Allocator, command: []const u8, expected_stdout: | ... | @@ -158,7 +158,7 @@ fn testExec(allocator: std.mem.Allocator, command: []const u8, expected_stdout: |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | fn testExecWithCwd(allocator: std.mem.Allocator, command: []const u8, cwd: ?[]const u8, expected_stdout: []const u8) !void { | 160 | fn testExecWithCwd(allocator: std.mem.Allocator, command: []const u8, cwd: ?[]const u8, expected_stdout: []const u8) !void { |
| 161 | var result = try std.ChildProcess.run(.{ | 161 | const result = try std.ChildProcess.run(.{ |
| 162 | .allocator = allocator, | 162 | .allocator = allocator, |
| 163 | .argv = &[_][]const u8{command}, | 163 | .argv = &[_][]const u8{command}, |
| 164 | .cwd = cwd, | 164 | .cwd = cwd, |
test/standalone/zerolength_check/src/main.zig+3-3| ... | @@ -1,14 +1,14 @@ | ... | @@ -1,14 +1,14 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | test { | 3 | test { |
| 4 | var dest = foo(); | 4 | const dest = foo(); |
| 5 | var source = foo(); | 5 | const source = foo(); |
| 6 | 6 | ||
| 7 | @memcpy(dest, source); | 7 | @memcpy(dest, source); |
| 8 | @memset(dest, 4); | 8 | @memset(dest, 4); |
| 9 | @memset(dest, undefined); | 9 | @memset(dest, undefined); |
| 10 | 10 | ||
| 11 | var dest2 = foo2(); | 11 | const dest2 = foo2(); |
| 12 | @memset(dest2, 0); | 12 | @memset(dest2, 0); |
| 13 | } | 13 | } |
| 14 | 14 |
test/translate_c.zig+237-59| ... | @@ -37,6 +37,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -37,6 +37,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 37 | , &[_][]const u8{ | 37 | , &[_][]const u8{ |
| 38 | \\pub export fn foo(arg_a: c_int) void { | 38 | \\pub export fn foo(arg_a: c_int) void { |
| 39 | \\ var a = arg_a; | 39 | \\ var a = arg_a; |
| 40 | \\ _ = &a; | ||
| 40 | \\ while (true) { | 41 | \\ while (true) { |
| 41 | \\ if (a != 0) break; | 42 | \\ if (a != 0) break; |
| 42 | \\ } | 43 | \\ } |
| ... | @@ -81,9 +82,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -81,9 +82,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 81 | , &[_][]const u8{ | 82 | , &[_][]const u8{ |
| 82 | \\pub export fn foo(arg_x: c_ulong) c_ulong { | 83 | \\pub export fn foo(arg_x: c_ulong) c_ulong { |
| 83 | \\ var x = arg_x; | 84 | \\ var x = arg_x; |
| 85 | \\ _ = &x; | ||
| 84 | \\ const union_unnamed_1 = extern union { | 86 | \\ const union_unnamed_1 = extern union { |
| 85 | \\ _x: c_ulong, | 87 | \\ _x: c_ulong, |
| 86 | \\ }; | 88 | \\ }; |
| 89 | \\ _ = &union_unnamed_1; | ||
| 87 | \\ return (union_unnamed_1{ | 90 | \\ return (union_unnamed_1{ |
| 88 | \\ ._x = x, | 91 | \\ ._x = x, |
| 89 | \\ })._x; | 92 | \\ })._x; |
| ... | @@ -123,10 +126,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -123,10 +126,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 123 | \\pub export fn foo() void { | 126 | \\pub export fn foo() void { |
| 124 | \\ while (true) if (true) { | 127 | \\ while (true) if (true) { |
| 125 | \\ var a: c_int = 1; | 128 | \\ var a: c_int = 1; |
| 126 | \\ _ = @TypeOf(a); | 129 | \\ _ = &a; |
| 127 | \\ } else { | 130 | \\ } else { |
| 128 | \\ var b: c_int = 2; | 131 | \\ var b: c_int = 2; |
| 129 | \\ _ = @TypeOf(b); | 132 | \\ _ = &b; |
| 130 | \\ }; | 133 | \\ }; |
| 131 | \\ if (true) if (true) {}; | 134 | \\ if (true) if (true) {}; |
| 132 | \\} | 135 | \\} |
| ... | @@ -142,6 +145,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -142,6 +145,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 142 | \\pub extern fn bar(...) c_int; | 145 | \\pub extern fn bar(...) c_int; |
| 143 | \\pub export fn foo() void { | 146 | \\pub export fn foo() void { |
| 144 | \\ var a: c_int = undefined; | 147 | \\ var a: c_int = undefined; |
| 148 | \\ _ = &a; | ||
| 145 | \\ if (a != 0) a = 2 else _ = bar(); | 149 | \\ if (a != 0) a = 2 else _ = bar(); |
| 146 | \\} | 150 | \\} |
| 147 | }); | 151 | }); |
| ... | @@ -194,24 +198,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -194,24 +198,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 194 | \\ B: c_int = @import("std").mem.zeroes(c_int), | 198 | \\ B: c_int = @import("std").mem.zeroes(c_int), |
| 195 | \\ C: c_int = @import("std").mem.zeroes(c_int), | 199 | \\ C: c_int = @import("std").mem.zeroes(c_int), |
| 196 | \\ }; | 200 | \\ }; |
| 201 | \\ _ = &struct_Foo; | ||
| 197 | \\ var a: struct_Foo = struct_Foo{ | 202 | \\ var a: struct_Foo = struct_Foo{ |
| 198 | \\ .A = @as(c_int, 0), | 203 | \\ .A = @as(c_int, 0), |
| 199 | \\ .B = 0, | 204 | \\ .B = 0, |
| 200 | \\ .C = 0, | 205 | \\ .C = 0, |
| 201 | \\ }; | 206 | \\ }; |
| 202 | \\ _ = @TypeOf(a); | 207 | \\ _ = &a; |
| 203 | \\ { | 208 | \\ { |
| 204 | \\ const struct_Foo_1 = extern struct { | 209 | \\ const struct_Foo_1 = extern struct { |
| 205 | \\ A: c_int = @import("std").mem.zeroes(c_int), | 210 | \\ A: c_int = @import("std").mem.zeroes(c_int), |
| 206 | \\ B: c_int = @import("std").mem.zeroes(c_int), | 211 | \\ B: c_int = @import("std").mem.zeroes(c_int), |
| 207 | \\ C: c_int = @import("std").mem.zeroes(c_int), | 212 | \\ C: c_int = @import("std").mem.zeroes(c_int), |
| 208 | \\ }; | 213 | \\ }; |
| 214 | \\ _ = &struct_Foo_1; | ||
| 209 | \\ var a_2: struct_Foo_1 = struct_Foo_1{ | 215 | \\ var a_2: struct_Foo_1 = struct_Foo_1{ |
| 210 | \\ .A = @as(c_int, 0), | 216 | \\ .A = @as(c_int, 0), |
| 211 | \\ .B = 0, | 217 | \\ .B = 0, |
| 212 | \\ .C = 0, | 218 | \\ .C = 0, |
| 213 | \\ }; | 219 | \\ }; |
| 214 | \\ _ = @TypeOf(a_2); | 220 | \\ _ = &a_2; |
| 215 | \\ } | 221 | \\ } |
| 216 | \\} | 222 | \\} |
| 217 | }); | 223 | }); |
| ... | @@ -240,24 +246,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -240,24 +246,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 240 | \\ B: c_int, | 246 | \\ B: c_int, |
| 241 | \\ C: c_int, | 247 | \\ C: c_int, |
| 242 | \\ }; | 248 | \\ }; |
| 243 | \\ _ = @TypeOf(union_unnamed_1); | 249 | \\ _ = &union_unnamed_1; |
| 244 | \\ const Foo = union_unnamed_1; | 250 | \\ const Foo = union_unnamed_1; |
| 251 | \\ _ = &Foo; | ||
| 245 | \\ var a: Foo = Foo{ | 252 | \\ var a: Foo = Foo{ |
| 246 | \\ .A = @as(c_int, 0), | 253 | \\ .A = @as(c_int, 0), |
| 247 | \\ }; | 254 | \\ }; |
| 248 | \\ _ = @TypeOf(a); | 255 | \\ _ = &a; |
| 249 | \\ { | 256 | \\ { |
| 250 | \\ const union_unnamed_2 = extern union { | 257 | \\ const union_unnamed_2 = extern union { |
| 251 | \\ A: c_int, | 258 | \\ A: c_int, |
| 252 | \\ B: c_int, | 259 | \\ B: c_int, |
| 253 | \\ C: c_int, | 260 | \\ C: c_int, |
| 254 | \\ }; | 261 | \\ }; |
| 255 | \\ _ = @TypeOf(union_unnamed_2); | 262 | \\ _ = &union_unnamed_2; |
| 256 | \\ const Foo_1 = union_unnamed_2; | 263 | \\ const Foo_1 = union_unnamed_2; |
| 264 | \\ _ = &Foo_1; | ||
| 257 | \\ var a_2: Foo_1 = Foo_1{ | 265 | \\ var a_2: Foo_1 = Foo_1{ |
| 258 | \\ .A = @as(c_int, 0), | 266 | \\ .A = @as(c_int, 0), |
| 259 | \\ }; | 267 | \\ }; |
| 260 | \\ _ = @TypeOf(a_2); | 268 | \\ _ = &a_2; |
| 261 | \\ } | 269 | \\ } |
| 262 | \\} | 270 | \\} |
| 263 | }); | 271 | }); |
| ... | @@ -268,6 +276,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -268,6 +276,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 268 | \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED) | 276 | \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED) |
| 269 | , &[_][]const u8{ | 277 | , &[_][]const u8{ |
| 270 | \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*anyopaque { | 278 | \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*anyopaque { |
| 279 | \\ _ = &x; | ||
| 271 | \\ return @import("std").zig.c_translation.cast(?*anyopaque, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED); | 280 | \\ return @import("std").zig.c_translation.cast(?*anyopaque, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED); |
| 272 | \\} | 281 | \\} |
| 273 | }); | 282 | }); |
| ... | @@ -310,6 +319,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -310,6 +319,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 310 | \\pub const VALUE = ((((@as(c_int, 1) + (@as(c_int, 2) * @as(c_int, 3))) + (@as(c_int, 4) * @as(c_int, 5))) + @as(c_int, 6)) << @as(c_int, 7)) | @intFromBool(@as(c_int, 8) == @as(c_int, 9)); | 319 | \\pub const VALUE = ((((@as(c_int, 1) + (@as(c_int, 2) * @as(c_int, 3))) + (@as(c_int, 4) * @as(c_int, 5))) + @as(c_int, 6)) << @as(c_int, 7)) | @intFromBool(@as(c_int, 8) == @as(c_int, 9)); |
| 311 | , | 320 | , |
| 312 | \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) { | 321 | \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) { |
| 322 | \\ _ = &p; | ||
| 313 | \\ return (@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16)); | 323 | \\ return (@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16)); |
| 314 | \\} | 324 | \\} |
| 315 | }); | 325 | }); |
| ... | @@ -325,7 +335,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -325,7 +335,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 325 | \\ const bar_1 = struct { | 335 | \\ const bar_1 = struct { |
| 326 | \\ threadlocal var static: c_int = 2; | 336 | \\ threadlocal var static: c_int = 2; |
| 327 | \\ }; | 337 | \\ }; |
| 328 | \\ _ = @TypeOf(bar_1); | 338 | \\ _ = &bar_1; |
| 329 | \\ return 0; | 339 | \\ return 0; |
| 330 | \\} | 340 | \\} |
| 331 | }); | 341 | }); |
| ... | @@ -344,7 +354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -344,7 +354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 344 | \\} | 354 | \\} |
| 345 | \\pub export fn bar() c_int { | 355 | \\pub export fn bar() c_int { |
| 346 | \\ var a: c_int = 2; | 356 | \\ var a: c_int = 2; |
| 347 | \\ _ = @TypeOf(a); | 357 | \\ _ = &a; |
| 348 | \\ return 0; | 358 | \\ return 0; |
| 349 | \\} | 359 | \\} |
| 350 | \\pub export fn baz() c_int { | 360 | \\pub export fn baz() c_int { |
| ... | @@ -359,7 +369,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -359,7 +369,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 359 | , &[_][]const u8{ | 369 | , &[_][]const u8{ |
| 360 | \\pub export fn main() void { | 370 | \\pub export fn main() void { |
| 361 | \\ var a: c_int = @as(c_int, @bitCast(@as(c_uint, @truncate(@alignOf(c_int))))); | 371 | \\ var a: c_int = @as(c_int, @bitCast(@as(c_uint, @truncate(@alignOf(c_int))))); |
| 362 | \\ _ = @TypeOf(a); | 372 | \\ _ = &a; |
| 363 | \\} | 373 | \\} |
| 364 | }); | 374 | }); |
| 365 | 375 | ||
| ... | @@ -390,6 +400,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -390,6 +400,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 390 | \\pub const Color = struct_Color; | 400 | \\pub const Color = struct_Color; |
| 391 | , | 401 | , |
| 392 | \\pub inline fn CLITERAL(@"type": anytype) @TypeOf(@"type") { | 402 | \\pub inline fn CLITERAL(@"type": anytype) @TypeOf(@"type") { |
| 403 | \\ _ = &@"type"; | ||
| 393 | \\ return @"type"; | 404 | \\ return @"type"; |
| 394 | \\} | 405 | \\} |
| 395 | , | 406 | , |
| ... | @@ -407,6 +418,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -407,6 +418,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 407 | \\}; | 418 | \\}; |
| 408 | , | 419 | , |
| 409 | \\pub inline fn A(_x: anytype) MyCStruct { | 420 | \\pub inline fn A(_x: anytype) MyCStruct { |
| 421 | \\ _ = &_x; | ||
| 410 | \\ return @import("std").mem.zeroInit(MyCStruct, .{ | 422 | \\ return @import("std").mem.zeroInit(MyCStruct, .{ |
| 411 | \\ .x = _x, | 423 | \\ .x = _x, |
| 412 | \\ }); | 424 | \\ }); |
| ... | @@ -438,6 +450,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -438,6 +450,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 438 | \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) | 450 | \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) |
| 439 | , &[_][]const u8{ | 451 | , &[_][]const u8{ |
| 440 | \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) { | 452 | \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) { |
| 453 | \\ _ = &_fp; | ||
| 441 | \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0); | 454 | \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0); |
| 442 | \\} | 455 | \\} |
| 443 | }); | 456 | }); |
| ... | @@ -447,6 +460,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -447,6 +460,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 447 | \\#define BAR 1 && 2 > 4 | 460 | \\#define BAR 1 && 2 > 4 |
| 448 | , &[_][]const u8{ | 461 | , &[_][]const u8{ |
| 449 | \\pub inline fn FOO(x: anytype) @TypeOf(@intFromBool(x >= @as(c_int, 0)) + @intFromBool(x >= @as(c_int, 0))) { | 462 | \\pub inline fn FOO(x: anytype) @TypeOf(@intFromBool(x >= @as(c_int, 0)) + @intFromBool(x >= @as(c_int, 0))) { |
| 463 | \\ _ = &x; | ||
| 450 | \\ return @intFromBool(x >= @as(c_int, 0)) + @intFromBool(x >= @as(c_int, 0)); | 464 | \\ return @intFromBool(x >= @as(c_int, 0)) + @intFromBool(x >= @as(c_int, 0)); |
| 451 | \\} | 465 | \\} |
| 452 | , | 466 | , |
| ... | @@ -507,11 +521,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -507,11 +521,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 507 | \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2)) | 521 | \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2)) |
| 508 | , &[_][]const u8{ | 522 | , &[_][]const u8{ |
| 509 | \\pub const foo = blk_1: { | 523 | \\pub const foo = blk_1: { |
| 510 | \\ _ = @TypeOf(foo); | 524 | \\ _ = &foo; |
| 511 | \\ break :blk_1 bar; | 525 | \\ break :blk_1 bar; |
| 512 | \\}; | 526 | \\}; |
| 513 | , | 527 | , |
| 514 | \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { | 528 | \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { |
| 529 | \\ _ = &x; | ||
| 515 | \\ return blk_1: { | 530 | \\ return blk_1: { |
| 516 | \\ _ = &x; | 531 | \\ _ = &x; |
| 517 | \\ _ = @as(c_int, 3); | 532 | \\ _ = @as(c_int, 3); |
| ... | @@ -642,6 +657,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -642,6 +657,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 642 | \\}; | 657 | \\}; |
| 643 | \\pub export fn foo(arg_x: [*c]outer) void { | 658 | \\pub export fn foo(arg_x: [*c]outer) void { |
| 644 | \\ var x = arg_x; | 659 | \\ var x = arg_x; |
| 660 | \\ _ = &x; | ||
| 645 | \\ x.*.unnamed_0.unnamed_0.y = @as(c_int, @bitCast(@as(c_uint, x.*.unnamed_0.x))); | 661 | \\ x.*.unnamed_0.unnamed_0.y = @as(c_int, @bitCast(@as(c_uint, x.*.unnamed_0.x))); |
| 646 | \\} | 662 | \\} |
| 647 | }); | 663 | }); |
| ... | @@ -728,8 +744,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -728,8 +744,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 728 | \\pub const struct_opaque_2 = opaque {}; | 744 | \\pub const struct_opaque_2 = opaque {}; |
| 729 | \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { | 745 | \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { |
| 730 | \\ var opaque_1 = arg_opaque_1; | 746 | \\ var opaque_1 = arg_opaque_1; |
| 747 | \\ _ = &opaque_1; | ||
| 731 | \\ var cast: ?*struct_opaque_2 = @as(?*struct_opaque_2, @ptrCast(opaque_1)); | 748 | \\ var cast: ?*struct_opaque_2 = @as(?*struct_opaque_2, @ptrCast(opaque_1)); |
| 732 | \\ _ = @TypeOf(cast); | 749 | \\ _ = &cast; |
| 733 | \\} | 750 | \\} |
| 734 | }); | 751 | }); |
| 735 | 752 | ||
| ... | @@ -764,7 +781,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -764,7 +781,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 764 | \\pub export fn my_fn() align(128) void {} | 781 | \\pub export fn my_fn() align(128) void {} |
| 765 | \\pub export fn other_fn() void { | 782 | \\pub export fn other_fn() void { |
| 766 | \\ var ARR: [16]u8 align(16) = undefined; | 783 | \\ var ARR: [16]u8 align(16) = undefined; |
| 767 | \\ _ = @TypeOf(ARR); | 784 | \\ _ = &ARR; |
| 768 | \\} | 785 | \\} |
| 769 | }); | 786 | }); |
| 770 | } | 787 | } |
| ... | @@ -801,17 +818,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -801,17 +818,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 801 | , &[_][]const u8{ | 818 | , &[_][]const u8{ |
| 802 | \\pub export fn foo() void { | 819 | \\pub export fn foo() void { |
| 803 | \\ var a: c_int = undefined; | 820 | \\ var a: c_int = undefined; |
| 804 | \\ _ = @TypeOf(a); | 821 | \\ _ = &a; |
| 805 | \\ var b: u8 = 123; | 822 | \\ var b: u8 = 123; |
| 806 | \\ _ = @TypeOf(b); | 823 | \\ _ = &b; |
| 807 | \\ const c: c_int = undefined; | 824 | \\ const c: c_int = undefined; |
| 808 | \\ _ = @TypeOf(c); | 825 | \\ _ = &c; |
| 809 | \\ const d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440))); | 826 | \\ const d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440))); |
| 810 | \\ _ = @TypeOf(d); | 827 | \\ _ = &d; |
| 811 | \\ var e: c_int = 10; | 828 | \\ var e: c_int = 10; |
| 812 | \\ _ = @TypeOf(e); | 829 | \\ _ = &e; |
| 813 | \\ var f: c_uint = 10; | 830 | \\ var f: c_uint = 10; |
| 814 | \\ _ = @TypeOf(f); | 831 | \\ _ = &f; |
| 815 | \\} | 832 | \\} |
| 816 | }); | 833 | }); |
| 817 | 834 | ||
| ... | @@ -827,6 +844,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -827,6 +844,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 827 | , &[_][]const u8{ | 844 | , &[_][]const u8{ |
| 828 | \\pub export fn foo() void { | 845 | \\pub export fn foo() void { |
| 829 | \\ var a: c_int = undefined; | 846 | \\ var a: c_int = undefined; |
| 847 | \\ _ = &a; | ||
| 830 | \\ _ = @as(c_int, 1); | 848 | \\ _ = @as(c_int, 1); |
| 831 | \\ _ = "hey"; | 849 | \\ _ = "hey"; |
| 832 | \\ _ = @as(c_int, 1) + @as(c_int, 1); | 850 | \\ _ = @as(c_int, 1) + @as(c_int, 1); |
| ... | @@ -870,7 +888,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -870,7 +888,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 870 | \\ const v2 = struct { | 888 | \\ const v2 = struct { |
| 871 | \\ const static: [5:0]u8 = "2.2.2".*; | 889 | \\ const static: [5:0]u8 = "2.2.2".*; |
| 872 | \\ }; | 890 | \\ }; |
| 873 | \\ _ = @TypeOf(v2); | 891 | \\ _ = &v2; |
| 874 | \\} | 892 | \\} |
| 875 | }); | 893 | }); |
| 876 | 894 | ||
| ... | @@ -912,8 +930,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -912,8 +930,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 912 | \\pub extern fn foo() void; | 930 | \\pub extern fn foo() void; |
| 913 | \\pub export fn bar() void { | 931 | \\pub export fn bar() void { |
| 914 | \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo)); | 932 | \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo)); |
| 933 | \\ _ = &func_ptr; | ||
| 915 | \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr))))); | 934 | \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr))))); |
| 916 | \\ _ = @TypeOf(typed_func_ptr); | 935 | \\ _ = &typed_func_ptr; |
| 917 | \\} | 936 | \\} |
| 918 | }); | 937 | }); |
| 919 | 938 | ||
| ... | @@ -953,8 +972,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -953,8 +972,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 953 | , &[_][]const u8{ | 972 | , &[_][]const u8{ |
| 954 | \\pub export fn s() c_int { | 973 | \\pub export fn s() c_int { |
| 955 | \\ var a: c_int = undefined; | 974 | \\ var a: c_int = undefined; |
| 975 | \\ _ = &a; | ||
| 956 | \\ var b: c_int = undefined; | 976 | \\ var b: c_int = undefined; |
| 977 | \\ _ = &b; | ||
| 957 | \\ var c: c_int = undefined; | 978 | \\ var c: c_int = undefined; |
| 979 | \\ _ = &c; | ||
| 958 | \\ c = a + b; | 980 | \\ c = a + b; |
| 959 | \\ c = a - b; | 981 | \\ c = a - b; |
| 960 | \\ c = a * b; | 982 | \\ c = a * b; |
| ... | @@ -964,8 +986,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -964,8 +986,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 964 | \\} | 986 | \\} |
| 965 | \\pub export fn u() c_uint { | 987 | \\pub export fn u() c_uint { |
| 966 | \\ var a: c_uint = undefined; | 988 | \\ var a: c_uint = undefined; |
| 989 | \\ _ = &a; | ||
| 967 | \\ var b: c_uint = undefined; | 990 | \\ var b: c_uint = undefined; |
| 991 | \\ _ = &b; | ||
| 968 | \\ var c: c_uint = undefined; | 992 | \\ var c: c_uint = undefined; |
| 993 | \\ _ = &c; | ||
| 969 | \\ c = a +% b; | 994 | \\ c = a +% b; |
| 970 | \\ c = a -% b; | 995 | \\ c = a -% b; |
| 971 | \\ c = a *% b; | 996 | \\ c = a *% b; |
| ... | @@ -1360,7 +1385,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1360,7 +1385,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1360 | , &[_][]const u8{ | 1385 | , &[_][]const u8{ |
| 1361 | \\pub export fn foo() void { | 1386 | \\pub export fn foo() void { |
| 1362 | \\ var a: c_int = undefined; | 1387 | \\ var a: c_int = undefined; |
| 1363 | \\ _ = @TypeOf(a); | 1388 | \\ _ = &a; |
| 1389 | \\ _ = &a; | ||
| 1364 | \\} | 1390 | \\} |
| 1365 | }); | 1391 | }); |
| 1366 | 1392 | ||
| ... | @@ -1372,6 +1398,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1372,6 +1398,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1372 | , &[_][]const u8{ | 1398 | , &[_][]const u8{ |
| 1373 | \\pub export fn foo() ?*anyopaque { | 1399 | \\pub export fn foo() ?*anyopaque { |
| 1374 | \\ var x: [*c]c_ushort = undefined; | 1400 | \\ var x: [*c]c_ushort = undefined; |
| 1401 | \\ _ = &x; | ||
| 1375 | \\ return @as(?*anyopaque, @ptrCast(x)); | 1402 | \\ return @as(?*anyopaque, @ptrCast(x)); |
| 1376 | \\} | 1403 | \\} |
| 1377 | }); | 1404 | }); |
| ... | @@ -1496,6 +1523,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1496,6 +1523,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1496 | \\pub export fn foo() void { | 1523 | \\pub export fn foo() void { |
| 1497 | \\ { | 1524 | \\ { |
| 1498 | \\ var i: c_int = 0; | 1525 | \\ var i: c_int = 0; |
| 1526 | \\ _ = &i; | ||
| 1499 | \\ while (i != 0) : (i += 1) {} | 1527 | \\ while (i != 0) : (i += 1) {} |
| 1500 | \\ } | 1528 | \\ } |
| 1501 | \\} | 1529 | \\} |
| ... | @@ -1519,6 +1547,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1519,6 +1547,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1519 | , &[_][]const u8{ | 1547 | , &[_][]const u8{ |
| 1520 | \\pub export fn foo() void { | 1548 | \\pub export fn foo() void { |
| 1521 | \\ var i: c_int = undefined; | 1549 | \\ var i: c_int = undefined; |
| 1550 | \\ _ = &i; | ||
| 1522 | \\ { | 1551 | \\ { |
| 1523 | \\ i = 3; | 1552 | \\ i = 3; |
| 1524 | \\ while (i != 0) : (i -= 1) {} | 1553 | \\ while (i != 0) : (i -= 1) {} |
| ... | @@ -1562,6 +1591,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1562,6 +1591,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1562 | , &[_][]const u8{ | 1591 | , &[_][]const u8{ |
| 1563 | \\pub export fn ptrcast() [*c]f32 { | 1592 | \\pub export fn ptrcast() [*c]f32 { |
| 1564 | \\ var a: [*c]c_int = undefined; | 1593 | \\ var a: [*c]c_int = undefined; |
| 1594 | \\ _ = &a; | ||
| 1565 | \\ return @as([*c]f32, @ptrCast(@alignCast(a))); | 1595 | \\ return @as([*c]f32, @ptrCast(@alignCast(a))); |
| 1566 | \\} | 1596 | \\} |
| 1567 | }); | 1597 | }); |
| ... | @@ -1574,6 +1604,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1574,6 +1604,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1574 | , &[_][]const u8{ | 1604 | , &[_][]const u8{ |
| 1575 | \\pub export fn ptrptrcast() [*c][*c]f32 { | 1605 | \\pub export fn ptrptrcast() [*c][*c]f32 { |
| 1576 | \\ var a: [*c][*c]c_int = undefined; | 1606 | \\ var a: [*c][*c]c_int = undefined; |
| 1607 | \\ _ = &a; | ||
| 1577 | \\ return @as([*c][*c]f32, @ptrCast(@alignCast(a))); | 1608 | \\ return @as([*c][*c]f32, @ptrCast(@alignCast(a))); |
| 1578 | \\} | 1609 | \\} |
| 1579 | }); | 1610 | }); |
| ... | @@ -1597,25 +1628,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1597,25 +1628,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1597 | , &[_][]const u8{ | 1628 | , &[_][]const u8{ |
| 1598 | \\pub export fn test_ptr_cast() void { | 1629 | \\pub export fn test_ptr_cast() void { |
| 1599 | \\ var p: ?*anyopaque = undefined; | 1630 | \\ var p: ?*anyopaque = undefined; |
| 1631 | \\ _ = &p; | ||
| 1600 | \\ { | 1632 | \\ { |
| 1601 | \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); | 1633 | \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); |
| 1602 | \\ _ = @TypeOf(to_char); | 1634 | \\ _ = &to_char; |
| 1603 | \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p))); | 1635 | \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p))); |
| 1604 | \\ _ = @TypeOf(to_short); | 1636 | \\ _ = &to_short; |
| 1605 | \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p))); | 1637 | \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p))); |
| 1606 | \\ _ = @TypeOf(to_int); | 1638 | \\ _ = &to_int; |
| 1607 | \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p))); | 1639 | \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p))); |
| 1608 | \\ _ = @TypeOf(to_longlong); | 1640 | \\ _ = &to_longlong; |
| 1609 | \\ } | 1641 | \\ } |
| 1610 | \\ { | 1642 | \\ { |
| 1611 | \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); | 1643 | \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); |
| 1612 | \\ _ = @TypeOf(to_char); | 1644 | \\ _ = &to_char; |
| 1613 | \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p))); | 1645 | \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p))); |
| 1614 | \\ _ = @TypeOf(to_short); | 1646 | \\ _ = &to_short; |
| 1615 | \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p))); | 1647 | \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p))); |
| 1616 | \\ _ = @TypeOf(to_int); | 1648 | \\ _ = &to_int; |
| 1617 | \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p))); | 1649 | \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p))); |
| 1618 | \\ _ = @TypeOf(to_longlong); | 1650 | \\ _ = &to_longlong; |
| 1619 | \\ } | 1651 | \\ } |
| 1620 | \\} | 1652 | \\} |
| 1621 | }); | 1653 | }); |
| ... | @@ -1633,8 +1665,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1633,8 +1665,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1633 | , &[_][]const u8{ | 1665 | , &[_][]const u8{ |
| 1634 | \\pub export fn while_none_bool() c_int { | 1666 | \\pub export fn while_none_bool() c_int { |
| 1635 | \\ var a: c_int = undefined; | 1667 | \\ var a: c_int = undefined; |
| 1668 | \\ _ = &a; | ||
| 1636 | \\ var b: f32 = undefined; | 1669 | \\ var b: f32 = undefined; |
| 1670 | \\ _ = &b; | ||
| 1637 | \\ var c: ?*anyopaque = undefined; | 1671 | \\ var c: ?*anyopaque = undefined; |
| 1672 | \\ _ = &c; | ||
| 1638 | \\ while (a != 0) return 0; | 1673 | \\ while (a != 0) return 0; |
| 1639 | \\ while (b != 0) return 1; | 1674 | \\ while (b != 0) return 1; |
| 1640 | \\ while (c != null) return 2; | 1675 | \\ while (c != null) return 2; |
| ... | @@ -1655,8 +1690,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1655,8 +1690,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1655 | , &[_][]const u8{ | 1690 | , &[_][]const u8{ |
| 1656 | \\pub export fn for_none_bool() c_int { | 1691 | \\pub export fn for_none_bool() c_int { |
| 1657 | \\ var a: c_int = undefined; | 1692 | \\ var a: c_int = undefined; |
| 1693 | \\ _ = &a; | ||
| 1658 | \\ var b: f32 = undefined; | 1694 | \\ var b: f32 = undefined; |
| 1695 | \\ _ = &b; | ||
| 1659 | \\ var c: ?*anyopaque = undefined; | 1696 | \\ var c: ?*anyopaque = undefined; |
| 1697 | \\ _ = &c; | ||
| 1660 | \\ while (a != 0) return 0; | 1698 | \\ while (a != 0) return 0; |
| 1661 | \\ while (b != 0) return 1; | 1699 | \\ while (b != 0) return 1; |
| 1662 | \\ while (c != null) return 2; | 1700 | \\ while (c != null) return 2; |
| ... | @@ -1693,6 +1731,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1693,6 +1731,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1693 | , &[_][]const u8{ | 1731 | , &[_][]const u8{ |
| 1694 | \\pub export fn foo() void { | 1732 | \\pub export fn foo() void { |
| 1695 | \\ var x: [*c]c_int = undefined; | 1733 | \\ var x: [*c]c_int = undefined; |
| 1734 | \\ _ = &x; | ||
| 1696 | \\ x.* = 1; | 1735 | \\ x.* = 1; |
| 1697 | \\} | 1736 | \\} |
| 1698 | }); | 1737 | }); |
| ... | @@ -1706,7 +1745,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1706,7 +1745,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1706 | , &[_][]const u8{ | 1745 | , &[_][]const u8{ |
| 1707 | \\pub export fn foo() c_int { | 1746 | \\pub export fn foo() c_int { |
| 1708 | \\ var x: c_int = 1234; | 1747 | \\ var x: c_int = 1234; |
| 1748 | \\ _ = &x; | ||
| 1709 | \\ var ptr: [*c]c_int = &x; | 1749 | \\ var ptr: [*c]c_int = &x; |
| 1750 | \\ _ = &ptr; | ||
| 1710 | \\ return ptr.*; | 1751 | \\ return ptr.*; |
| 1711 | \\} | 1752 | \\} |
| 1712 | }); | 1753 | }); |
| ... | @@ -1719,6 +1760,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1719,6 +1760,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1719 | , &[_][]const u8{ | 1760 | , &[_][]const u8{ |
| 1720 | \\pub export fn foo() c_int { | 1761 | \\pub export fn foo() c_int { |
| 1721 | \\ var x: c_int = undefined; | 1762 | \\ var x: c_int = undefined; |
| 1763 | \\ _ = &x; | ||
| 1722 | \\ return ~x; | 1764 | \\ return ~x; |
| 1723 | \\} | 1765 | \\} |
| 1724 | }); | 1766 | }); |
| ... | @@ -1736,8 +1778,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1736,8 +1778,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1736 | , &[_][]const u8{ | 1778 | , &[_][]const u8{ |
| 1737 | \\pub export fn foo() c_int { | 1779 | \\pub export fn foo() c_int { |
| 1738 | \\ var a: c_int = undefined; | 1780 | \\ var a: c_int = undefined; |
| 1781 | \\ _ = &a; | ||
| 1739 | \\ var b: f32 = undefined; | 1782 | \\ var b: f32 = undefined; |
| 1783 | \\ _ = &b; | ||
| 1740 | \\ var c: ?*anyopaque = undefined; | 1784 | \\ var c: ?*anyopaque = undefined; |
| 1785 | \\ _ = &c; | ||
| 1741 | \\ return @intFromBool(!(a == @as(c_int, 0))); | 1786 | \\ return @intFromBool(!(a == @as(c_int, 0))); |
| 1742 | \\ return @intFromBool(!(a != 0)); | 1787 | \\ return @intFromBool(!(a != 0)); |
| 1743 | \\ return @intFromBool(!(b != 0)); | 1788 | \\ return @intFromBool(!(b != 0)); |
| ... | @@ -1859,11 +1904,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1859,11 +1904,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1859 | \\ var arr: [10]u8 = [1]u8{ | 1904 | \\ var arr: [10]u8 = [1]u8{ |
| 1860 | \\ 1, | 1905 | \\ 1, |
| 1861 | \\ } ++ [1]u8{0} ** 9; | 1906 | \\ } ++ [1]u8{0} ** 9; |
| 1862 | \\ _ = @TypeOf(arr); | 1907 | \\ _ = &arr; |
| 1863 | \\ var arr1: [10][*c]u8 = [1][*c]u8{ | 1908 | \\ var arr1: [10][*c]u8 = [1][*c]u8{ |
| 1864 | \\ null, | 1909 | \\ null, |
| 1865 | \\ } ++ [1][*c]u8{null} ** 9; | 1910 | \\ } ++ [1][*c]u8{null} ** 9; |
| 1866 | \\ _ = @TypeOf(arr1); | 1911 | \\ _ = &arr1; |
| 1867 | \\} | 1912 | \\} |
| 1868 | }); | 1913 | }); |
| 1869 | 1914 | ||
| ... | @@ -2051,10 +2096,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2051,10 +2096,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2051 | \\pub extern var c: c_int; | 2096 | \\pub extern var c: c_int; |
| 2052 | , | 2097 | , |
| 2053 | \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) { | 2098 | \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) { |
| 2099 | \\ _ = &c_1; | ||
| 2054 | \\ return c_1 * @as(c_int, 2); | 2100 | \\ return c_1 * @as(c_int, 2); |
| 2055 | \\} | 2101 | \\} |
| 2056 | , | 2102 | , |
| 2057 | \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { | 2103 | \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { |
| 2104 | \\ _ = &L; | ||
| 2105 | \\ _ = &b; | ||
| 2058 | \\ return L + b; | 2106 | \\ return L + b; |
| 2059 | \\} | 2107 | \\} |
| 2060 | , | 2108 | , |
| ... | @@ -2107,16 +2155,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2107,16 +2155,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2107 | \\pub var c: c_int = 4; | 2155 | \\pub var c: c_int = 4; |
| 2108 | \\pub export fn foo(arg_c_1: u8) void { | 2156 | \\pub export fn foo(arg_c_1: u8) void { |
| 2109 | \\ var c_1 = arg_c_1; | 2157 | \\ var c_1 = arg_c_1; |
| 2110 | \\ _ = @TypeOf(c_1); | 2158 | \\ _ = &c_1; |
| 2111 | \\ var a_2: c_int = undefined; | 2159 | \\ var a_2: c_int = undefined; |
| 2160 | \\ _ = &a_2; | ||
| 2112 | \\ var b_3: u8 = 123; | 2161 | \\ var b_3: u8 = 123; |
| 2162 | \\ _ = &b_3; | ||
| 2113 | \\ b_3 = @as(u8, @bitCast(@as(i8, @truncate(a_2)))); | 2163 | \\ b_3 = @as(u8, @bitCast(@as(i8, @truncate(a_2)))); |
| 2114 | \\ { | 2164 | \\ { |
| 2115 | \\ var d: c_int = 5; | 2165 | \\ var d: c_int = 5; |
| 2116 | \\ _ = @TypeOf(d); | 2166 | \\ _ = &d; |
| 2117 | \\ } | 2167 | \\ } |
| 2118 | \\ var d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440))); | 2168 | \\ var d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440))); |
| 2119 | \\ _ = @TypeOf(d); | 2169 | \\ _ = &d; |
| 2120 | \\} | 2170 | \\} |
| 2121 | }); | 2171 | }); |
| 2122 | 2172 | ||
| ... | @@ -2150,7 +2200,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2150,7 +2200,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2150 | , &[_][]const u8{ | 2200 | , &[_][]const u8{ |
| 2151 | \\pub export fn foo() void { | 2201 | \\pub export fn foo() void { |
| 2152 | \\ var a: c_int = undefined; | 2202 | \\ var a: c_int = undefined; |
| 2203 | \\ _ = &a; | ||
| 2153 | \\ var b: c_int = undefined; | 2204 | \\ var b: c_int = undefined; |
| 2205 | \\ _ = &b; | ||
| 2154 | \\ a = blk: { | 2206 | \\ a = blk: { |
| 2155 | \\ const tmp = @as(c_int, 2); | 2207 | \\ const tmp = @as(c_int, 2); |
| 2156 | \\ b = tmp; | 2208 | \\ b = tmp; |
| ... | @@ -2180,11 +2232,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2180,11 +2232,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2180 | , &[_][]const u8{ | 2232 | , &[_][]const u8{ |
| 2181 | \\pub export fn foo() c_int { | 2233 | \\pub export fn foo() c_int { |
| 2182 | \\ var a: c_int = 5; | 2234 | \\ var a: c_int = 5; |
| 2235 | \\ _ = &a; | ||
| 2183 | \\ while (true) { | 2236 | \\ while (true) { |
| 2184 | \\ a = 2; | 2237 | \\ a = 2; |
| 2185 | \\ } | 2238 | \\ } |
| 2186 | \\ while (true) { | 2239 | \\ while (true) { |
| 2187 | \\ var a_1: c_int = 4; | 2240 | \\ var a_1: c_int = 4; |
| 2241 | \\ _ = &a_1; | ||
| 2188 | \\ a_1 = 9; | 2242 | \\ a_1 = 9; |
| 2189 | \\ return blk: { | 2243 | \\ return blk: { |
| 2190 | \\ _ = @as(c_int, 6); | 2244 | \\ _ = @as(c_int, 6); |
| ... | @@ -2193,6 +2247,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2193,6 +2247,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2193 | \\ } | 2247 | \\ } |
| 2194 | \\ while (true) { | 2248 | \\ while (true) { |
| 2195 | \\ var a_1: c_int = 2; | 2249 | \\ var a_1: c_int = 2; |
| 2250 | \\ _ = &a_1; | ||
| 2196 | \\ a_1 = 12; | 2251 | \\ a_1 = 12; |
| 2197 | \\ } | 2252 | \\ } |
| 2198 | \\ while (true) { | 2253 | \\ while (true) { |
| ... | @@ -2214,10 +2269,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2214,10 +2269,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2214 | \\pub export fn foo() void { | 2269 | \\pub export fn foo() void { |
| 2215 | \\ { | 2270 | \\ { |
| 2216 | \\ var i: c_int = 2; | 2271 | \\ var i: c_int = 2; |
| 2272 | \\ _ = &i; | ||
| 2217 | \\ var b: c_int = 4; | 2273 | \\ var b: c_int = 4; |
| 2218 | \\ _ = @TypeOf(b); | 2274 | \\ _ = &b; |
| 2219 | \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { | 2275 | \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { |
| 2220 | \\ var a: c_int = 2; | 2276 | \\ var a: c_int = 2; |
| 2277 | \\ _ = &a; | ||
| 2221 | \\ _ = blk: { | 2278 | \\ _ = blk: { |
| 2222 | \\ _ = blk_1: { | 2279 | \\ _ = blk_1: { |
| 2223 | \\ a = 6; | 2280 | \\ a = 6; |
| ... | @@ -2228,7 +2285,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2228,7 +2285,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2228 | \\ } | 2285 | \\ } |
| 2229 | \\ } | 2286 | \\ } |
| 2230 | \\ var i: u8 = 2; | 2287 | \\ var i: u8 = 2; |
| 2231 | \\ _ = @TypeOf(i); | 2288 | \\ _ = &i; |
| 2232 | \\} | 2289 | \\} |
| 2233 | }); | 2290 | }); |
| 2234 | 2291 | ||
| ... | @@ -2309,7 +2366,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2309,7 +2366,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2309 | , &[_][]const u8{ | 2366 | , &[_][]const u8{ |
| 2310 | \\pub export fn switch_fn(arg_i: c_int) void { | 2367 | \\pub export fn switch_fn(arg_i: c_int) void { |
| 2311 | \\ var i = arg_i; | 2368 | \\ var i = arg_i; |
| 2369 | \\ _ = &i; | ||
| 2312 | \\ var res: c_int = 0; | 2370 | \\ var res: c_int = 0; |
| 2371 | \\ _ = &res; | ||
| 2313 | \\ while (true) { | 2372 | \\ while (true) { |
| 2314 | \\ switch (i) { | 2373 | \\ switch (i) { |
| 2315 | \\ @as(c_int, 0) => { | 2374 | \\ @as(c_int, 0) => { |
| ... | @@ -2398,7 +2457,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2398,7 +2457,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2398 | , &[_][]const u8{ | 2457 | , &[_][]const u8{ |
| 2399 | \\pub export fn max(arg_a: c_int) void { | 2458 | \\pub export fn max(arg_a: c_int) void { |
| 2400 | \\ var a = arg_a; | 2459 | \\ var a = arg_a; |
| 2460 | \\ _ = &a; | ||
| 2401 | \\ var tmp: c_int = undefined; | 2461 | \\ var tmp: c_int = undefined; |
| 2462 | \\ _ = &tmp; | ||
| 2402 | \\ tmp = a; | 2463 | \\ tmp = a; |
| 2403 | \\ a = tmp; | 2464 | \\ a = tmp; |
| 2404 | \\} | 2465 | \\} |
| ... | @@ -2412,8 +2473,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2412,8 +2473,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2412 | , &[_][]const u8{ | 2473 | , &[_][]const u8{ |
| 2413 | \\pub export fn max(arg_a: c_int) void { | 2474 | \\pub export fn max(arg_a: c_int) void { |
| 2414 | \\ var a = arg_a; | 2475 | \\ var a = arg_a; |
| 2476 | \\ _ = &a; | ||
| 2415 | \\ var b: c_int = undefined; | 2477 | \\ var b: c_int = undefined; |
| 2478 | \\ _ = &b; | ||
| 2416 | \\ var c: c_int = undefined; | 2479 | \\ var c: c_int = undefined; |
| 2480 | \\ _ = &c; | ||
| 2417 | \\ c = blk: { | 2481 | \\ c = blk: { |
| 2418 | \\ const tmp = a; | 2482 | \\ const tmp = a; |
| 2419 | \\ b = tmp; | 2483 | \\ b = tmp; |
| ... | @@ -2442,6 +2506,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2442,6 +2506,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2442 | , &[_][]const u8{ | 2506 | , &[_][]const u8{ |
| 2443 | \\pub export fn int_from_float(arg_a: f32) c_int { | 2507 | \\pub export fn int_from_float(arg_a: f32) c_int { |
| 2444 | \\ var a = arg_a; | 2508 | \\ var a = arg_a; |
| 2509 | \\ _ = &a; | ||
| 2445 | \\ return @as(c_int, @intFromFloat(a)); | 2510 | \\ return @as(c_int, @intFromFloat(a)); |
| 2446 | \\} | 2511 | \\} |
| 2447 | }); | 2512 | }); |
| ... | @@ -2465,27 +2530,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2465,27 +2530,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2465 | , &[_][]const u8{ | 2530 | , &[_][]const u8{ |
| 2466 | \\pub export fn escapes() [*c]const u8 { | 2531 | \\pub export fn escapes() [*c]const u8 { |
| 2467 | \\ var a: u8 = '\''; | 2532 | \\ var a: u8 = '\''; |
| 2468 | \\ _ = @TypeOf(a); | 2533 | \\ _ = &a; |
| 2469 | \\ var b: u8 = '\\'; | 2534 | \\ var b: u8 = '\\'; |
| 2470 | \\ _ = @TypeOf(b); | 2535 | \\ _ = &b; |
| 2471 | \\ var c: u8 = '\x07'; | 2536 | \\ var c: u8 = '\x07'; |
| 2472 | \\ _ = @TypeOf(c); | 2537 | \\ _ = &c; |
| 2473 | \\ var d: u8 = '\x08'; | 2538 | \\ var d: u8 = '\x08'; |
| 2474 | \\ _ = @TypeOf(d); | 2539 | \\ _ = &d; |
| 2475 | \\ var e: u8 = '\x0c'; | 2540 | \\ var e: u8 = '\x0c'; |
| 2476 | \\ _ = @TypeOf(e); | 2541 | \\ _ = &e; |
| 2477 | \\ var f: u8 = '\n'; | 2542 | \\ var f: u8 = '\n'; |
| 2478 | \\ _ = @TypeOf(f); | 2543 | \\ _ = &f; |
| 2479 | \\ var g: u8 = '\r'; | 2544 | \\ var g: u8 = '\r'; |
| 2480 | \\ _ = @TypeOf(g); | 2545 | \\ _ = &g; |
| 2481 | \\ var h: u8 = '\t'; | 2546 | \\ var h: u8 = '\t'; |
| 2482 | \\ _ = @TypeOf(h); | 2547 | \\ _ = &h; |
| 2483 | \\ var i: u8 = '\x0b'; | 2548 | \\ var i: u8 = '\x0b'; |
| 2484 | \\ _ = @TypeOf(i); | 2549 | \\ _ = &i; |
| 2485 | \\ var j: u8 = '\x00'; | 2550 | \\ var j: u8 = '\x00'; |
| 2486 | \\ _ = @TypeOf(j); | 2551 | \\ _ = &j; |
| 2487 | \\ var k: u8 = '"'; | 2552 | \\ var k: u8 = '"'; |
| 2488 | \\ _ = @TypeOf(k); | 2553 | \\ _ = &k; |
| 2489 | \\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\""; | 2554 | \\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\""; |
| 2490 | \\} | 2555 | \\} |
| 2491 | }); | 2556 | }); |
| ... | @@ -2505,11 +2570,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2505,11 +2570,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2505 | , &[_][]const u8{ | 2570 | , &[_][]const u8{ |
| 2506 | \\pub export fn foo() void { | 2571 | \\pub export fn foo() void { |
| 2507 | \\ var a: c_int = 2; | 2572 | \\ var a: c_int = 2; |
| 2573 | \\ _ = &a; | ||
| 2508 | \\ while (true) { | 2574 | \\ while (true) { |
| 2509 | \\ a = a - @as(c_int, 1); | 2575 | \\ a = a - @as(c_int, 1); |
| 2510 | \\ if (!(a != 0)) break; | 2576 | \\ if (!(a != 0)) break; |
| 2511 | \\ } | 2577 | \\ } |
| 2512 | \\ var b: c_int = 2; | 2578 | \\ var b: c_int = 2; |
| 2579 | \\ _ = &b; | ||
| 2513 | \\ while (true) { | 2580 | \\ while (true) { |
| 2514 | \\ b = b - @as(c_int, 1); | 2581 | \\ b = b - @as(c_int, 1); |
| 2515 | \\ if (!(b != 0)) break; | 2582 | \\ if (!(b != 0)) break; |
| ... | @@ -2550,21 +2617,37 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2550,21 +2617,37 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2550 | \\pub const SomeTypedef = c_int; | 2617 | \\pub const SomeTypedef = c_int; |
| 2551 | \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*anyopaque) c_int { | 2618 | \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*anyopaque) c_int { |
| 2552 | \\ var a = arg_a; | 2619 | \\ var a = arg_a; |
| 2620 | \\ _ = &a; | ||
| 2553 | \\ var b = arg_b; | 2621 | \\ var b = arg_b; |
| 2622 | \\ _ = &b; | ||
| 2554 | \\ var c = arg_c; | 2623 | \\ var c = arg_c; |
| 2624 | \\ _ = &c; | ||
| 2555 | \\ var d: enum_Foo = @as(c_uint, @bitCast(FooA)); | 2625 | \\ var d: enum_Foo = @as(c_uint, @bitCast(FooA)); |
| 2626 | \\ _ = &d; | ||
| 2556 | \\ var e: c_int = @intFromBool((a != 0) and (b != 0)); | 2627 | \\ var e: c_int = @intFromBool((a != 0) and (b != 0)); |
| 2628 | \\ _ = &e; | ||
| 2557 | \\ var f: c_int = @intFromBool((b != 0) and (c != null)); | 2629 | \\ var f: c_int = @intFromBool((b != 0) and (c != null)); |
| 2630 | \\ _ = &f; | ||
| 2558 | \\ var g: c_int = @intFromBool((a != 0) and (c != null)); | 2631 | \\ var g: c_int = @intFromBool((a != 0) and (c != null)); |
| 2632 | \\ _ = &g; | ||
| 2559 | \\ var h: c_int = @intFromBool((a != 0) or (b != 0)); | 2633 | \\ var h: c_int = @intFromBool((a != 0) or (b != 0)); |
| 2634 | \\ _ = &h; | ||
| 2560 | \\ var i: c_int = @intFromBool((b != 0) or (c != null)); | 2635 | \\ var i: c_int = @intFromBool((b != 0) or (c != null)); |
| 2636 | \\ _ = &i; | ||
| 2561 | \\ var j: c_int = @intFromBool((a != 0) or (c != null)); | 2637 | \\ var j: c_int = @intFromBool((a != 0) or (c != null)); |
| 2638 | \\ _ = &j; | ||
| 2562 | \\ var k: c_int = @intFromBool((a != 0) or (@as(c_int, @bitCast(d)) != 0)); | 2639 | \\ var k: c_int = @intFromBool((a != 0) or (@as(c_int, @bitCast(d)) != 0)); |
| 2640 | \\ _ = &k; | ||
| 2563 | \\ var l: c_int = @intFromBool((@as(c_int, @bitCast(d)) != 0) and (b != 0)); | 2641 | \\ var l: c_int = @intFromBool((@as(c_int, @bitCast(d)) != 0) and (b != 0)); |
| 2642 | \\ _ = &l; | ||
| 2564 | \\ var m: c_int = @intFromBool((c != null) or (d != 0)); | 2643 | \\ var m: c_int = @intFromBool((c != null) or (d != 0)); |
| 2644 | \\ _ = &m; | ||
| 2565 | \\ var td: SomeTypedef = 44; | 2645 | \\ var td: SomeTypedef = 44; |
| 2646 | \\ _ = &td; | ||
| 2566 | \\ var o: c_int = @intFromBool((td != 0) or (b != 0)); | 2647 | \\ var o: c_int = @intFromBool((td != 0) or (b != 0)); |
| 2648 | \\ _ = &o; | ||
| 2567 | \\ var p: c_int = @intFromBool((c != null) and (td != 0)); | 2649 | \\ var p: c_int = @intFromBool((c != null) and (td != 0)); |
| 2650 | \\ _ = &p; | ||
| 2568 | \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p; | 2651 | \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p; |
| 2569 | \\} | 2652 | \\} |
| 2570 | , | 2653 | , |
| ... | @@ -2604,7 +2687,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2604,7 +2687,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2604 | , &[_][]const u8{ | 2687 | , &[_][]const u8{ |
| 2605 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2688 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2606 | \\ var a = arg_a; | 2689 | \\ var a = arg_a; |
| 2690 | \\ _ = &a; | ||
| 2607 | \\ var b = arg_b; | 2691 | \\ var b = arg_b; |
| 2692 | \\ _ = &b; | ||
| 2608 | \\ return (a & b) ^ (a | b); | 2693 | \\ return (a & b) ^ (a | b); |
| 2609 | \\} | 2694 | \\} |
| 2610 | }); | 2695 | }); |
| ... | @@ -2623,14 +2708,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2623,14 +2708,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2623 | , &[_][]const u8{ | 2708 | , &[_][]const u8{ |
| 2624 | \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int { | 2709 | \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int { |
| 2625 | \\ var a = arg_a; | 2710 | \\ var a = arg_a; |
| 2711 | \\ _ = &a; | ||
| 2626 | \\ var b = arg_b; | 2712 | \\ var b = arg_b; |
| 2713 | \\ _ = &b; | ||
| 2627 | \\ var c: c_int = @intFromBool(a < b); | 2714 | \\ var c: c_int = @intFromBool(a < b); |
| 2715 | \\ _ = &c; | ||
| 2628 | \\ var d: c_int = @intFromBool(a > b); | 2716 | \\ var d: c_int = @intFromBool(a > b); |
| 2717 | \\ _ = &d; | ||
| 2629 | \\ var e: c_int = @intFromBool(a <= b); | 2718 | \\ var e: c_int = @intFromBool(a <= b); |
| 2719 | \\ _ = &e; | ||
| 2630 | \\ var f: c_int = @intFromBool(a >= b); | 2720 | \\ var f: c_int = @intFromBool(a >= b); |
| 2721 | \\ _ = &f; | ||
| 2631 | \\ var g: c_int = @intFromBool(c < d); | 2722 | \\ var g: c_int = @intFromBool(c < d); |
| 2723 | \\ _ = &g; | ||
| 2632 | \\ var h: c_int = @intFromBool(e < f); | 2724 | \\ var h: c_int = @intFromBool(e < f); |
| 2725 | \\ _ = &h; | ||
| 2633 | \\ var i: c_int = @intFromBool(g < h); | 2726 | \\ var i: c_int = @intFromBool(g < h); |
| 2727 | \\ _ = &i; | ||
| 2634 | \\ return i; | 2728 | \\ return i; |
| 2635 | \\} | 2729 | \\} |
| 2636 | }); | 2730 | }); |
| ... | @@ -2646,7 +2740,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2646,7 +2740,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2646 | , &[_][]const u8{ | 2740 | , &[_][]const u8{ |
| 2647 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2741 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2648 | \\ var a = arg_a; | 2742 | \\ var a = arg_a; |
| 2743 | \\ _ = &a; | ||
| 2649 | \\ var b = arg_b; | 2744 | \\ var b = arg_b; |
| 2745 | \\ _ = &b; | ||
| 2650 | \\ if (a == b) return a; | 2746 | \\ if (a == b) return a; |
| 2651 | \\ if (a != b) return b; | 2747 | \\ if (a != b) return b; |
| 2652 | \\ return a; | 2748 | \\ return a; |
| ... | @@ -2663,6 +2759,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2663,6 +2759,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2663 | \\pub const yes = [*c]u8; | 2759 | \\pub const yes = [*c]u8; |
| 2664 | \\pub export fn foo() void { | 2760 | \\pub export fn foo() void { |
| 2665 | \\ var a: yes = undefined; | 2761 | \\ var a: yes = undefined; |
| 2762 | \\ _ = &a; | ||
| 2666 | \\ if (a != null) { | 2763 | \\ if (a != null) { |
| 2667 | \\ _ = @as(c_int, 2); | 2764 | \\ _ = @as(c_int, 2); |
| 2668 | \\ } | 2765 | \\ } |
| ... | @@ -2681,7 +2778,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2681,7 +2778,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2681 | \\pub export fn foo() c_int { | 2778 | \\pub export fn foo() c_int { |
| 2682 | \\ return blk: { | 2779 | \\ return blk: { |
| 2683 | \\ var a: c_int = 1; | 2780 | \\ var a: c_int = 1; |
| 2684 | \\ _ = @TypeOf(a); | 2781 | \\ _ = &a; |
| 2782 | \\ _ = &a; | ||
| 2685 | \\ break :blk a; | 2783 | \\ break :blk a; |
| 2686 | \\ }; | 2784 | \\ }; |
| 2687 | \\} | 2785 | \\} |
| ... | @@ -2707,6 +2805,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2707,6 +2805,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2707 | \\pub export var b: f32 = 2.0; | 2805 | \\pub export var b: f32 = 2.0; |
| 2708 | \\pub export fn foo() void { | 2806 | \\pub export fn foo() void { |
| 2709 | \\ var c: [*c]struct_Foo = undefined; | 2807 | \\ var c: [*c]struct_Foo = undefined; |
| 2808 | \\ _ = &c; | ||
| 2710 | \\ _ = a.b; | 2809 | \\ _ = a.b; |
| 2711 | \\ _ = c.*.b; | 2810 | \\ _ = c.*.b; |
| 2712 | \\} | 2811 | \\} |
| ... | @@ -2726,6 +2825,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2726,6 +2825,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2726 | \\pub export var array: [100]c_int = [1]c_int{0} ** 100; | 2825 | \\pub export var array: [100]c_int = [1]c_int{0} ** 100; |
| 2727 | \\pub export fn foo(arg_index: c_int) c_int { | 2826 | \\pub export fn foo(arg_index: c_int) c_int { |
| 2728 | \\ var index = arg_index; | 2827 | \\ var index = arg_index; |
| 2828 | \\ _ = &index; | ||
| 2729 | \\ return array[@as(c_uint, @intCast(index))]; | 2829 | \\ return array[@as(c_uint, @intCast(index))]; |
| 2730 | \\} | 2830 | \\} |
| 2731 | , | 2831 | , |
| ... | @@ -2740,7 +2840,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2740,7 +2840,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2740 | , &[_][]const u8{ | 2840 | , &[_][]const u8{ |
| 2741 | \\pub export fn foo() void { | 2841 | \\pub export fn foo() void { |
| 2742 | \\ var a: [10]c_int = undefined; | 2842 | \\ var a: [10]c_int = undefined; |
| 2843 | \\ _ = &a; | ||
| 2743 | \\ var i: c_int = 0; | 2844 | \\ var i: c_int = 0; |
| 2845 | \\ _ = &i; | ||
| 2744 | \\ a[@as(c_uint, @intCast(i))] = 0; | 2846 | \\ a[@as(c_uint, @intCast(i))] = 0; |
| 2745 | \\} | 2847 | \\} |
| 2746 | }); | 2848 | }); |
| ... | @@ -2753,7 +2855,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2753,7 +2855,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2753 | , &[_][]const u8{ | 2855 | , &[_][]const u8{ |
| 2754 | \\pub export fn foo() void { | 2856 | \\pub export fn foo() void { |
| 2755 | \\ var a: [10]c_longlong = undefined; | 2857 | \\ var a: [10]c_longlong = undefined; |
| 2858 | \\ _ = &a; | ||
| 2756 | \\ var i: c_longlong = 0; | 2859 | \\ var i: c_longlong = 0; |
| 2860 | \\ _ = &i; | ||
| 2757 | \\ a[@as(usize, @intCast(i))] = 0; | 2861 | \\ a[@as(usize, @intCast(i))] = 0; |
| 2758 | \\} | 2862 | \\} |
| 2759 | }); | 2863 | }); |
| ... | @@ -2766,7 +2870,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2766,7 +2870,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2766 | , &[_][]const u8{ | 2870 | , &[_][]const u8{ |
| 2767 | \\pub export fn foo() void { | 2871 | \\pub export fn foo() void { |
| 2768 | \\ var a: [10]c_uint = undefined; | 2872 | \\ var a: [10]c_uint = undefined; |
| 2873 | \\ _ = &a; | ||
| 2769 | \\ var i: c_uint = 0; | 2874 | \\ var i: c_uint = 0; |
| 2875 | \\ _ = &i; | ||
| 2770 | \\ a[i] = 0; | 2876 | \\ a[i] = 0; |
| 2771 | \\} | 2877 | \\} |
| 2772 | }); | 2878 | }); |
| ... | @@ -2776,6 +2882,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2776,6 +2882,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2776 | \\int bar(int x) { return x; } | 2882 | \\int bar(int x) { return x; } |
| 2777 | , &[_][]const u8{ | 2883 | , &[_][]const u8{ |
| 2778 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) { | 2884 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) { |
| 2885 | \\ _ = &arg; | ||
| 2779 | \\ return bar(arg); | 2886 | \\ return bar(arg); |
| 2780 | \\} | 2887 | \\} |
| 2781 | }); | 2888 | }); |
| ... | @@ -2785,7 +2892,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2785,7 +2892,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2785 | \\int bar(void) { return 0; } | 2892 | \\int bar(void) { return 0; } |
| 2786 | , &[_][]const u8{ | 2893 | , &[_][]const u8{ |
| 2787 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) { | 2894 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) { |
| 2788 | \\ _ = @TypeOf(arg); | 2895 | \\ _ = &arg; |
| 2789 | \\ return bar(); | 2896 | \\ return bar(); |
| 2790 | \\} | 2897 | \\} |
| 2791 | }); | 2898 | }); |
| ... | @@ -2801,7 +2908,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2801,7 +2908,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2801 | , &[_][]const u8{ | 2908 | , &[_][]const u8{ |
| 2802 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2909 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2803 | \\ var a = arg_a; | 2910 | \\ var a = arg_a; |
| 2911 | \\ _ = &a; | ||
| 2804 | \\ var b = arg_b; | 2912 | \\ var b = arg_b; |
| 2913 | \\ _ = &b; | ||
| 2805 | \\ if ((a < b) or (a == b)) return b; | 2914 | \\ if ((a < b) or (a == b)) return b; |
| 2806 | \\ if ((a >= b) and (a == b)) return a; | 2915 | \\ if ((a >= b) and (a == b)) return a; |
| 2807 | \\ return a; | 2916 | \\ return a; |
| ... | @@ -2823,7 +2932,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2823,7 +2932,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2823 | , &[_][]const u8{ | 2932 | , &[_][]const u8{ |
| 2824 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2933 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2825 | \\ var a = arg_a; | 2934 | \\ var a = arg_a; |
| 2935 | \\ _ = &a; | ||
| 2826 | \\ var b = arg_b; | 2936 | \\ var b = arg_b; |
| 2937 | \\ _ = &b; | ||
| 2827 | \\ if (a < b) return b; | 2938 | \\ if (a < b) return b; |
| 2828 | \\ if (a < b) return b else return a; | 2939 | \\ if (a < b) return b else return a; |
| 2829 | \\ if (a < b) {} else {} | 2940 | \\ if (a < b) {} else {} |
| ... | @@ -2844,14 +2955,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2844,14 +2955,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2844 | \\pub export fn foo() void { | 2955 | \\pub export fn foo() void { |
| 2845 | \\ if (true) { | 2956 | \\ if (true) { |
| 2846 | \\ var a: c_int = 2; | 2957 | \\ var a: c_int = 2; |
| 2847 | \\ _ = @TypeOf(a); | 2958 | \\ _ = &a; |
| 2848 | \\ } | 2959 | \\ } |
| 2849 | \\ if ((blk: { | 2960 | \\ if ((blk: { |
| 2850 | \\ _ = @as(c_int, 2); | 2961 | \\ _ = @as(c_int, 2); |
| 2851 | \\ break :blk @as(c_int, 5); | 2962 | \\ break :blk @as(c_int, 5); |
| 2852 | \\ }) != 0) { | 2963 | \\ }) != 0) { |
| 2853 | \\ var a: c_int = 2; | 2964 | \\ var a: c_int = 2; |
| 2854 | \\ _ = @TypeOf(a); | 2965 | \\ _ = &a; |
| 2855 | \\ } | 2966 | \\ } |
| 2856 | \\} | 2967 | \\} |
| 2857 | }); | 2968 | }); |
| ... | @@ -2874,9 +2985,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2874,9 +2985,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2874 | \\; | 2985 | \\; |
| 2875 | \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*anyopaque, arg_d: enum_SomeEnum) c_int { | 2986 | \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*anyopaque, arg_d: enum_SomeEnum) c_int { |
| 2876 | \\ var a = arg_a; | 2987 | \\ var a = arg_a; |
| 2988 | \\ _ = &a; | ||
| 2877 | \\ var b = arg_b; | 2989 | \\ var b = arg_b; |
| 2990 | \\ _ = &b; | ||
| 2878 | \\ var c = arg_c; | 2991 | \\ var c = arg_c; |
| 2992 | \\ _ = &c; | ||
| 2879 | \\ var d = arg_d; | 2993 | \\ var d = arg_d; |
| 2994 | \\ _ = &d; | ||
| 2880 | \\ if (a != 0) return 0; | 2995 | \\ if (a != 0) return 0; |
| 2881 | \\ if (b != 0) return 1; | 2996 | \\ if (b != 0) return 1; |
| 2882 | \\ if (c != null) return 2; | 2997 | \\ if (c != null) return 2; |
| ... | @@ -2904,6 +3019,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2904,6 +3019,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2904 | , &[_][]const u8{ | 3019 | , &[_][]const u8{ |
| 2905 | \\pub export fn abs(arg_a: c_int) c_int { | 3020 | \\pub export fn abs(arg_a: c_int) c_int { |
| 2906 | \\ var a = arg_a; | 3021 | \\ var a = arg_a; |
| 3022 | \\ _ = &a; | ||
| 2907 | \\ return if (a < @as(c_int, 0)) -a else a; | 3023 | \\ return if (a < @as(c_int, 0)) -a else a; |
| 2908 | \\} | 3024 | \\} |
| 2909 | }); | 3025 | }); |
| ... | @@ -2924,16 +3040,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2924,16 +3040,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2924 | , &[_][]const u8{ | 3040 | , &[_][]const u8{ |
| 2925 | \\pub export fn foo1(arg_a: c_uint) c_uint { | 3041 | \\pub export fn foo1(arg_a: c_uint) c_uint { |
| 2926 | \\ var a = arg_a; | 3042 | \\ var a = arg_a; |
| 3043 | \\ _ = &a; | ||
| 2927 | \\ a +%= 1; | 3044 | \\ a +%= 1; |
| 2928 | \\ return a; | 3045 | \\ return a; |
| 2929 | \\} | 3046 | \\} |
| 2930 | \\pub export fn foo2(arg_a: c_int) c_int { | 3047 | \\pub export fn foo2(arg_a: c_int) c_int { |
| 2931 | \\ var a = arg_a; | 3048 | \\ var a = arg_a; |
| 3049 | \\ _ = &a; | ||
| 2932 | \\ a += 1; | 3050 | \\ a += 1; |
| 2933 | \\ return a; | 3051 | \\ return a; |
| 2934 | \\} | 3052 | \\} |
| 2935 | \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int { | 3053 | \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int { |
| 2936 | \\ var a = arg_a; | 3054 | \\ var a = arg_a; |
| 3055 | \\ _ = &a; | ||
| 2937 | \\ a += 1; | 3056 | \\ a += 1; |
| 2938 | \\ return a; | 3057 | \\ return a; |
| 2939 | \\} | 3058 | \\} |
| ... | @@ -2959,7 +3078,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2959,7 +3078,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2959 | \\} | 3078 | \\} |
| 2960 | \\pub export fn bar() void { | 3079 | \\pub export fn bar() void { |
| 2961 | \\ var f: ?*const fn () callconv(.C) void = &foo; | 3080 | \\ var f: ?*const fn () callconv(.C) void = &foo; |
| 3081 | \\ _ = &f; | ||
| 2962 | \\ var b: ?*const fn () callconv(.C) c_int = &baz; | 3082 | \\ var b: ?*const fn () callconv(.C) c_int = &baz; |
| 3083 | \\ _ = &b; | ||
| 2963 | \\ f.?(); | 3084 | \\ f.?(); |
| 2964 | \\ f.?(); | 3085 | \\ f.?(); |
| 2965 | \\ foo(); | 3086 | \\ foo(); |
| ... | @@ -2985,7 +3106,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2985,7 +3106,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2985 | , &[_][]const u8{ | 3106 | , &[_][]const u8{ |
| 2986 | \\pub export fn foo() void { | 3107 | \\pub export fn foo() void { |
| 2987 | \\ var i: c_int = 0; | 3108 | \\ var i: c_int = 0; |
| 3109 | \\ _ = &i; | ||
| 2988 | \\ var u: c_uint = 0; | 3110 | \\ var u: c_uint = 0; |
| 3111 | \\ _ = &u; | ||
| 2989 | \\ i += 1; | 3112 | \\ i += 1; |
| 2990 | \\ i -= 1; | 3113 | \\ i -= 1; |
| 2991 | \\ u +%= 1; | 3114 | \\ u +%= 1; |
| ... | @@ -3024,7 +3147,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3024,7 +3147,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3024 | , &[_][]const u8{ | 3147 | , &[_][]const u8{ |
| 3025 | \\pub export fn log2(arg_a: c_uint) c_int { | 3148 | \\pub export fn log2(arg_a: c_uint) c_int { |
| 3026 | \\ var a = arg_a; | 3149 | \\ var a = arg_a; |
| 3150 | \\ _ = &a; | ||
| 3027 | \\ var i: c_int = 0; | 3151 | \\ var i: c_int = 0; |
| 3152 | \\ _ = &i; | ||
| 3028 | \\ while (a > @as(c_uint, @bitCast(@as(c_int, 0)))) { | 3153 | \\ while (a > @as(c_uint, @bitCast(@as(c_int, 0)))) { |
| 3029 | \\ a >>= @intCast(@as(c_int, 1)); | 3154 | \\ a >>= @intCast(@as(c_int, 1)); |
| 3030 | \\ } | 3155 | \\ } |
| ... | @@ -3044,7 +3169,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3044,7 +3169,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3044 | , &[_][]const u8{ | 3169 | , &[_][]const u8{ |
| 3045 | \\pub export fn log2(arg_a: u32) c_int { | 3170 | \\pub export fn log2(arg_a: u32) c_int { |
| 3046 | \\ var a = arg_a; | 3171 | \\ var a = arg_a; |
| 3172 | \\ _ = &a; | ||
| 3047 | \\ var i: c_int = 0; | 3173 | \\ var i: c_int = 0; |
| 3174 | \\ _ = &i; | ||
| 3048 | \\ while (a > @as(u32, @bitCast(@as(c_int, 0)))) { | 3175 | \\ while (a > @as(u32, @bitCast(@as(c_int, 0)))) { |
| 3049 | \\ a >>= @intCast(@as(c_int, 1)); | 3176 | \\ a >>= @intCast(@as(c_int, 1)); |
| 3050 | \\ } | 3177 | \\ } |
| ... | @@ -3072,7 +3199,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3072,7 +3199,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3072 | , &[_][]const u8{ | 3199 | , &[_][]const u8{ |
| 3073 | \\pub export fn foo() void { | 3200 | \\pub export fn foo() void { |
| 3074 | \\ var a: c_int = 0; | 3201 | \\ var a: c_int = 0; |
| 3202 | \\ _ = &a; | ||
| 3075 | \\ var b: c_uint = 0; | 3203 | \\ var b: c_uint = 0; |
| 3204 | \\ _ = &b; | ||
| 3076 | \\ a += blk: { | 3205 | \\ a += blk: { |
| 3077 | \\ const ref = &a; | 3206 | \\ const ref = &a; |
| 3078 | \\ ref.* += @as(c_int, 1); | 3207 | \\ ref.* += @as(c_int, 1); |
| ... | @@ -3151,6 +3280,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3151,6 +3280,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3151 | , &[_][]const u8{ | 3280 | , &[_][]const u8{ |
| 3152 | \\pub export fn foo() void { | 3281 | \\pub export fn foo() void { |
| 3153 | \\ var a: c_uint = 0; | 3282 | \\ var a: c_uint = 0; |
| 3283 | \\ _ = &a; | ||
| 3154 | \\ a +%= blk: { | 3284 | \\ a +%= blk: { |
| 3155 | \\ const ref = &a; | 3285 | \\ const ref = &a; |
| 3156 | \\ ref.* +%= @as(c_uint, @bitCast(@as(c_int, 1))); | 3286 | \\ ref.* +%= @as(c_uint, @bitCast(@as(c_int, 1))); |
| ... | @@ -3210,7 +3340,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3210,7 +3340,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3210 | , &[_][]const u8{ | 3340 | , &[_][]const u8{ |
| 3211 | \\pub export fn foo() void { | 3341 | \\pub export fn foo() void { |
| 3212 | \\ var i: c_int = 0; | 3342 | \\ var i: c_int = 0; |
| 3343 | \\ _ = &i; | ||
| 3213 | \\ var u: c_uint = 0; | 3344 | \\ var u: c_uint = 0; |
| 3345 | \\ _ = &u; | ||
| 3214 | \\ i += 1; | 3346 | \\ i += 1; |
| 3215 | \\ i -= 1; | 3347 | \\ i -= 1; |
| 3216 | \\ u +%= 1; | 3348 | \\ u +%= 1; |
| ... | @@ -3305,6 +3437,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3305,6 +3437,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3305 | \\pub fn bar() callconv(.C) void {} | 3437 | \\pub fn bar() callconv(.C) void {} |
| 3306 | \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void { | 3438 | \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void { |
| 3307 | \\ var baz = arg_baz; | 3439 | \\ var baz = arg_baz; |
| 3440 | \\ _ = &baz; | ||
| 3308 | \\ bar(); | 3441 | \\ bar(); |
| 3309 | \\ _ = baz.?(); | 3442 | \\ _ = baz.?(); |
| 3310 | \\} | 3443 | \\} |
| ... | @@ -3331,7 +3464,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3331,7 +3464,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3331 | \\#define a 2 | 3464 | \\#define a 2 |
| 3332 | , &[_][]const u8{ | 3465 | , &[_][]const u8{ |
| 3333 | \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*anyopaque, baz))) { | 3466 | \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*anyopaque, baz))) { |
| 3334 | \\ _ = @TypeOf(bar); | 3467 | \\ _ = &bar; |
| 3335 | \\ return baz(@import("std").zig.c_translation.cast(?*anyopaque, baz)); | 3468 | \\ return baz(@import("std").zig.c_translation.cast(?*anyopaque, baz)); |
| 3336 | \\} | 3469 | \\} |
| 3337 | , | 3470 | , |
| ... | @@ -3375,10 +3508,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3375,10 +3508,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3375 | \\#define MAX(a, b) ((b) > (a) ? (b) : (a)) | 3508 | \\#define MAX(a, b) ((b) > (a) ? (b) : (a)) |
| 3376 | , &[_][]const u8{ | 3509 | , &[_][]const u8{ |
| 3377 | \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) { | 3510 | \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) { |
| 3511 | \\ _ = &a; | ||
| 3512 | \\ _ = &b; | ||
| 3378 | \\ return if (b < a) b else a; | 3513 | \\ return if (b < a) b else a; |
| 3379 | \\} | 3514 | \\} |
| 3380 | , | 3515 | , |
| 3381 | \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) { | 3516 | \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) { |
| 3517 | \\ _ = &a; | ||
| 3518 | \\ _ = &b; | ||
| 3382 | \\ return if (b > a) b else a; | 3519 | \\ return if (b > a) b else a; |
| 3383 | \\} | 3520 | \\} |
| 3384 | }); | 3521 | }); |
| ... | @@ -3390,7 +3527,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3390,7 +3527,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3390 | , &[_][]const u8{ | 3527 | , &[_][]const u8{ |
| 3391 | \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int { | 3528 | \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int { |
| 3392 | \\ var p = arg_p; | 3529 | \\ var p = arg_p; |
| 3530 | \\ _ = &p; | ||
| 3393 | \\ var x = arg_x; | 3531 | \\ var x = arg_x; |
| 3532 | \\ _ = &x; | ||
| 3394 | \\ return blk: { | 3533 | \\ return blk: { |
| 3395 | \\ const tmp = x; | 3534 | \\ const tmp = x; |
| 3396 | \\ (blk_1: { | 3535 | \\ (blk_1: { |
| ... | @@ -3417,6 +3556,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3417,6 +3556,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3417 | \\} | 3556 | \\} |
| 3418 | \\pub export fn bar(arg_x: c_long) c_ushort { | 3557 | \\pub export fn bar(arg_x: c_long) c_ushort { |
| 3419 | \\ var x = arg_x; | 3558 | \\ var x = arg_x; |
| 3559 | \\ _ = &x; | ||
| 3420 | \\ return @as(c_ushort, @bitCast(@as(c_short, @truncate(x)))); | 3560 | \\ return @as(c_ushort, @bitCast(@as(c_short, @truncate(x)))); |
| 3421 | \\} | 3561 | \\} |
| 3422 | }); | 3562 | }); |
| ... | @@ -3429,6 +3569,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3429,6 +3569,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3429 | , &[_][]const u8{ | 3569 | , &[_][]const u8{ |
| 3430 | \\pub export fn foo(arg_bar_1: c_int) void { | 3570 | \\pub export fn foo(arg_bar_1: c_int) void { |
| 3431 | \\ var bar_1 = arg_bar_1; | 3571 | \\ var bar_1 = arg_bar_1; |
| 3572 | \\ _ = &bar_1; | ||
| 3432 | \\ bar_1 = 2; | 3573 | \\ bar_1 = 2; |
| 3433 | \\} | 3574 | \\} |
| 3434 | \\pub export var bar: c_int = 4; | 3575 | \\pub export var bar: c_int = 4; |
| ... | @@ -3442,6 +3583,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3442,6 +3583,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3442 | , &[_][]const u8{ | 3583 | , &[_][]const u8{ |
| 3443 | \\pub export fn foo(arg_bar_1: c_int) void { | 3584 | \\pub export fn foo(arg_bar_1: c_int) void { |
| 3444 | \\ var bar_1 = arg_bar_1; | 3585 | \\ var bar_1 = arg_bar_1; |
| 3586 | \\ _ = &bar_1; | ||
| 3445 | \\ bar_1 = 2; | 3587 | \\ bar_1 = 2; |
| 3446 | \\} | 3588 | \\} |
| 3447 | , | 3589 | , |
| ... | @@ -3471,14 +3613,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3471,14 +3613,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3471 | , &[_][]const u8{ | 3613 | , &[_][]const u8{ |
| 3472 | \\pub export fn foo(arg_a: [*c]c_int) void { | 3614 | \\pub export fn foo(arg_a: [*c]c_int) void { |
| 3473 | \\ var a = arg_a; | 3615 | \\ var a = arg_a; |
| 3474 | \\ _ = @TypeOf(a); | 3616 | \\ _ = &a; |
| 3475 | \\} | 3617 | \\} |
| 3476 | \\pub export fn bar(arg_a: [*c]const c_int) void { | 3618 | \\pub export fn bar(arg_a: [*c]const c_int) void { |
| 3477 | \\ var a = arg_a; | 3619 | \\ var a = arg_a; |
| 3620 | \\ _ = &a; | ||
| 3478 | \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))); | 3621 | \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))); |
| 3479 | \\} | 3622 | \\} |
| 3480 | \\pub export fn baz(arg_a: [*c]volatile c_int) void { | 3623 | \\pub export fn baz(arg_a: [*c]volatile c_int) void { |
| 3481 | \\ var a = arg_a; | 3624 | \\ var a = arg_a; |
| 3625 | \\ _ = &a; | ||
| 3482 | \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))); | 3626 | \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))); |
| 3483 | \\} | 3627 | \\} |
| 3484 | }); | 3628 | }); |
| ... | @@ -3493,9 +3637,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3493,9 +3637,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3493 | , &[_][]const u8{ | 3637 | , &[_][]const u8{ |
| 3494 | \\pub export fn foo(arg_x: bool) bool { | 3638 | \\pub export fn foo(arg_x: bool) bool { |
| 3495 | \\ var x = arg_x; | 3639 | \\ var x = arg_x; |
| 3640 | \\ _ = &x; | ||
| 3496 | \\ var a: bool = @as(c_int, @intFromBool(x)) != @as(c_int, 1); | 3641 | \\ var a: bool = @as(c_int, @intFromBool(x)) != @as(c_int, 1); |
| 3642 | \\ _ = &a; | ||
| 3497 | \\ var b: bool = @as(c_int, @intFromBool(a)) != @as(c_int, 0); | 3643 | \\ var b: bool = @as(c_int, @intFromBool(a)) != @as(c_int, 0); |
| 3644 | \\ _ = &b; | ||
| 3498 | \\ var c: bool = @intFromPtr(&foo) != 0; | 3645 | \\ var c: bool = @intFromPtr(&foo) != 0; |
| 3646 | \\ _ = &c; | ||
| 3499 | \\ return foo(@as(c_int, @intFromBool(c)) != @as(c_int, @intFromBool(b))); | 3647 | \\ return foo(@as(c_int, @intFromBool(c)) != @as(c_int, @intFromBool(b))); |
| 3500 | \\} | 3648 | \\} |
| 3501 | }); | 3649 | }); |
| ... | @@ -3506,7 +3654,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3506,7 +3654,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3506 | \\} | 3654 | \\} |
| 3507 | , &[_][]const u8{ | 3655 | , &[_][]const u8{ |
| 3508 | \\pub export fn max(x: c_int, arg_y: c_int) c_int { | 3656 | \\pub export fn max(x: c_int, arg_y: c_int) c_int { |
| 3657 | \\ _ = &x; | ||
| 3509 | \\ var y = arg_y; | 3658 | \\ var y = arg_y; |
| 3659 | \\ _ = &y; | ||
| 3510 | \\ return if (x > y) x else y; | 3660 | \\ return if (x > y) x else y; |
| 3511 | \\} | 3661 | \\} |
| 3512 | }); | 3662 | }); |
| ... | @@ -3567,6 +3717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3567,6 +3717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3567 | \\ | 3717 | \\ |
| 3568 | , &[_][]const u8{ | 3718 | , &[_][]const u8{ |
| 3569 | \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) { | 3719 | \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) { |
| 3720 | \\ _ = &dpy; | ||
| 3570 | \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen; | 3721 | \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen; |
| 3571 | \\} | 3722 | \\} |
| 3572 | }); | 3723 | }); |
| ... | @@ -3809,6 +3960,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3809,6 +3960,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3809 | \\ const foo = struct { | 3960 | \\ const foo = struct { |
| 3810 | \\ var static: struct_FOO = @import("std").mem.zeroes(struct_FOO); | 3961 | \\ var static: struct_FOO = @import("std").mem.zeroes(struct_FOO); |
| 3811 | \\ }; | 3962 | \\ }; |
| 3963 | \\ _ = &foo; | ||
| 3812 | \\ return foo.static.x; | 3964 | \\ return foo.static.x; |
| 3813 | \\} | 3965 | \\} |
| 3814 | }); | 3966 | }); |
| ... | @@ -3830,13 +3982,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3830,13 +3982,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3830 | , &[_][]const u8{ | 3982 | , &[_][]const u8{ |
| 3831 | \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int { | 3983 | \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int { |
| 3832 | \\ var x = arg_x; | 3984 | \\ var x = arg_x; |
| 3985 | \\ _ = &x; | ||
| 3833 | \\ var y = arg_y; | 3986 | \\ var y = arg_y; |
| 3834 | \\ _ = @TypeOf(y); | 3987 | \\ _ = &y; |
| 3835 | \\ return x; | 3988 | \\ return x; |
| 3836 | \\} | 3989 | \\} |
| 3837 | , | 3990 | , |
| 3838 | \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) { | 3991 | \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) { |
| 3839 | \\ _ = @TypeOf(B); | 3992 | \\ _ = &A; |
| 3993 | \\ _ = &B; | ||
| 3840 | \\ return A; | 3994 | \\ return A; |
| 3841 | \\} | 3995 | \\} |
| 3842 | }); | 3996 | }); |
| ... | @@ -3911,6 +4065,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3911,6 +4065,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3911 | , &[_][]const u8{ | 4065 | , &[_][]const u8{ |
| 3912 | \\pub export fn foo() void { | 4066 | \\pub export fn foo() void { |
| 3913 | \\ var a: c_int = undefined; | 4067 | \\ var a: c_int = undefined; |
| 4068 | \\ _ = &a; | ||
| 3914 | \\ if ((blk: { | 4069 | \\ if ((blk: { |
| 3915 | \\ const tmp = @intFromBool(@as(c_int, 1) > @as(c_int, 0)); | 4070 | \\ const tmp = @intFromBool(@as(c_int, 1) > @as(c_int, 0)); |
| 3916 | \\ a = tmp; | 4071 | \\ a = tmp; |
| ... | @@ -3929,9 +4084,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3929,9 +4084,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3929 | , &[_][]const u8{ | 4084 | , &[_][]const u8{ |
| 3930 | \\pub export fn foo() void { | 4085 | \\pub export fn foo() void { |
| 3931 | \\ var a: S = undefined; | 4086 | \\ var a: S = undefined; |
| 4087 | \\ _ = &a; | ||
| 3932 | \\ var b: S = undefined; | 4088 | \\ var b: S = undefined; |
| 4089 | \\ _ = &b; | ||
| 3933 | \\ var c: c_longlong = @divExact(@as(c_longlong, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); | 4090 | \\ var c: c_longlong = @divExact(@as(c_longlong, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); |
| 3934 | \\ _ = @TypeOf(c); | 4091 | \\ _ = &c; |
| 3935 | \\} | 4092 | \\} |
| 3936 | }); | 4093 | }); |
| 3937 | } else { | 4094 | } else { |
| ... | @@ -3944,9 +4101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3944,9 +4101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3944 | , &[_][]const u8{ | 4101 | , &[_][]const u8{ |
| 3945 | \\pub export fn foo() void { | 4102 | \\pub export fn foo() void { |
| 3946 | \\ var a: S = undefined; | 4103 | \\ var a: S = undefined; |
| 4104 | \\ _ = &a; | ||
| 3947 | \\ var b: S = undefined; | 4105 | \\ var b: S = undefined; |
| 4106 | \\ _ = &b; | ||
| 3948 | \\ var c: c_long = @divExact(@as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); | 4107 | \\ var c: c_long = @divExact(@as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); |
| 3949 | \\ _ = @TypeOf(c); | 4108 | \\ _ = &c; |
| 3950 | \\} | 4109 | \\} |
| 3951 | }); | 4110 | }); |
| 3952 | } | 4111 | } |
| ... | @@ -3973,7 +4132,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3973,7 +4132,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3973 | , &[_][]const u8{ | 4132 | , &[_][]const u8{ |
| 3974 | \\pub export fn foo() void { | 4133 | \\pub export fn foo() void { |
| 3975 | \\ var n: c_int = undefined; | 4134 | \\ var n: c_int = undefined; |
| 4135 | \\ _ = &n; | ||
| 3976 | \\ var tmp: c_int = 1; | 4136 | \\ var tmp: c_int = 1; |
| 4137 | \\ _ = &tmp; | ||
| 3977 | \\ if ((blk: { | 4138 | \\ if ((blk: { |
| 3978 | \\ const tmp_1 = tmp; | 4139 | \\ const tmp_1 = tmp; |
| 3979 | \\ n = tmp_1; | 4140 | \\ n = tmp_1; |
| ... | @@ -3990,7 +4151,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3990,7 +4151,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3990 | , &[_][]const u8{ | 4151 | , &[_][]const u8{ |
| 3991 | \\pub export fn foo() void { | 4152 | \\pub export fn foo() void { |
| 3992 | \\ var tmp: c_int = undefined; | 4153 | \\ var tmp: c_int = undefined; |
| 4154 | \\ _ = &tmp; | ||
| 3993 | \\ var n: c_int = 1; | 4155 | \\ var n: c_int = 1; |
| 4156 | \\ _ = &n; | ||
| 3994 | \\ if ((blk: { | 4157 | \\ if ((blk: { |
| 3995 | \\ const tmp_1 = n; | 4158 | \\ const tmp_1 = n; |
| 3996 | \\ tmp = tmp_1; | 4159 | \\ tmp = tmp_1; |
| ... | @@ -4007,7 +4170,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -4007,7 +4170,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 4007 | , &[_][]const u8{ | 4170 | , &[_][]const u8{ |
| 4008 | \\pub export fn foo() void { | 4171 | \\pub export fn foo() void { |
| 4009 | \\ var n: c_int = undefined; | 4172 | \\ var n: c_int = undefined; |
| 4173 | \\ _ = &n; | ||
| 4010 | \\ var ref: c_int = 1; | 4174 | \\ var ref: c_int = 1; |
| 4175 | \\ _ = &ref; | ||
| 4011 | \\ if ((blk: { | 4176 | \\ if ((blk: { |
| 4012 | \\ const tmp = blk_1: { | 4177 | \\ const tmp = blk_1: { |
| 4013 | \\ const ref_2 = &ref; | 4178 | \\ const ref_2 = &ref; |
| ... | @@ -4028,7 +4193,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -4028,7 +4193,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 4028 | , &[_][]const u8{ | 4193 | , &[_][]const u8{ |
| 4029 | \\pub export fn foo() void { | 4194 | \\pub export fn foo() void { |
| 4030 | \\ var n: c_int = undefined; | 4195 | \\ var n: c_int = undefined; |
| 4196 | \\ _ = &n; | ||
| 4031 | \\ var ref: c_int = 1; | 4197 | \\ var ref: c_int = 1; |
| 4198 | \\ _ = &ref; | ||
| 4032 | \\ if ((blk: { | 4199 | \\ if ((blk: { |
| 4033 | \\ const tmp = blk_1: { | 4200 | \\ const tmp = blk_1: { |
| 4034 | \\ const ref_2 = &ref; | 4201 | \\ const ref_2 = &ref; |
| ... | @@ -4050,7 +4217,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -4050,7 +4217,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 4050 | , &[_][]const u8{ | 4217 | , &[_][]const u8{ |
| 4051 | \\pub export fn foo() void { | 4218 | \\pub export fn foo() void { |
| 4052 | \\ var n: c_int = undefined; | 4219 | \\ var n: c_int = undefined; |
| 4220 | \\ _ = &n; | ||
| 4053 | \\ var ref: c_int = 1; | 4221 | \\ var ref: c_int = 1; |
| 4222 | \\ _ = &ref; | ||
| 4054 | \\ if ((blk: { | 4223 | \\ if ((blk: { |
| 4055 | \\ const ref_1 = &n; | 4224 | \\ const ref_1 = &n; |
| 4056 | \\ ref_1.* += ref; | 4225 | \\ ref_1.* += ref; |
| ... | @@ -4067,7 +4236,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -4067,7 +4236,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 4067 | , &[_][]const u8{ | 4236 | , &[_][]const u8{ |
| 4068 | \\pub export fn foo() void { | 4237 | \\pub export fn foo() void { |
| 4069 | \\ var ref: c_int = undefined; | 4238 | \\ var ref: c_int = undefined; |
| 4239 | \\ _ = &ref; | ||
| 4070 | \\ var n: c_int = 1; | 4240 | \\ var n: c_int = 1; |
| 4241 | \\ _ = &n; | ||
| 4071 | \\ if ((blk: { | 4242 | \\ if ((blk: { |
| 4072 | \\ const ref_1 = &ref; | 4243 | \\ const ref_1 = &ref; |
| 4073 | \\ ref_1.* += n; | 4244 | \\ ref_1.* += n; |
| ... | @@ -4085,8 +4256,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -4085,8 +4256,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 4085 | , &[_][]const u8{ | 4256 | , &[_][]const u8{ |
| 4086 | \\pub export fn foo() void { | 4257 | \\pub export fn foo() void { |
| 4087 | \\ var f: c_int = 1; | 4258 | \\ var f: c_int = 1; |
| 4259 | \\ _ = &f; | ||
| 4088 | \\ var n: c_int = undefined; | 4260 | \\ var n: c_int = undefined; |
| 4261 | \\ _ = &n; | ||
| 4089 | \\ var cond_temp: c_int = 1; | 4262 | \\ var cond_temp: c_int = 1; |
| 4263 | \\ _ = &cond_temp; | ||
| 4090 | \\ if ((blk: { | 4264 | \\ if ((blk: { |
| 4091 | \\ const tmp = blk_1: { | 4265 | \\ const tmp = blk_1: { |
| 4092 | \\ const cond_temp_2 = cond_temp; | 4266 | \\ const cond_temp_2 = cond_temp; |
| ... | @@ -4107,8 +4281,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -4107,8 +4281,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 4107 | , &[_][]const u8{ | 4281 | , &[_][]const u8{ |
| 4108 | \\pub export fn foo() void { | 4282 | \\pub export fn foo() void { |
| 4109 | \\ var cond_temp: c_int = 1; | 4283 | \\ var cond_temp: c_int = 1; |
| 4284 | \\ _ = &cond_temp; | ||
| 4110 | \\ var n: c_int = undefined; | 4285 | \\ var n: c_int = undefined; |
| 4286 | \\ _ = &n; | ||
| 4111 | \\ var f: c_int = 1; | 4287 | \\ var f: c_int = 1; |
| 4288 | \\ _ = &f; | ||
| 4112 | \\ if ((blk: { | 4289 | \\ if ((blk: { |
| 4113 | \\ const tmp = blk_1: { | 4290 | \\ const tmp = blk_1: { |
| 4114 | \\ const cond_temp_2 = f; | 4291 | \\ const cond_temp_2 = f; |
| ... | @@ -4149,6 +4326,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -4149,6 +4326,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 4149 | , &[_][]const u8{ | 4326 | , &[_][]const u8{ |
| 4150 | \\pub export fn somefunc() void { | 4327 | \\pub export fn somefunc() void { |
| 4151 | \\ var y: c_int = undefined; | 4328 | \\ var y: c_int = undefined; |
| 4329 | \\ _ = &y; | ||
| 4152 | \\ _ = blk: { | 4330 | \\ _ = blk: { |
| 4153 | \\ y = 1; | 4331 | \\ y = 1; |
| 4154 | \\ }; | 4332 | \\ }; |
tools/gen_spirv_spec.zig+2-2| ... | @@ -23,7 +23,7 @@ pub fn main() !void { | ... | @@ -23,7 +23,7 @@ pub fn main() !void { |
| 23 | var scanner = std.json.Scanner.initCompleteInput(allocator, spec); | 23 | var scanner = std.json.Scanner.initCompleteInput(allocator, spec); |
| 24 | var diagnostics = std.json.Diagnostics{}; | 24 | var diagnostics = std.json.Diagnostics{}; |
| 25 | scanner.enableDiagnostics(&diagnostics); | 25 | scanner.enableDiagnostics(&diagnostics); |
| 26 | var parsed = std.json.parseFromTokenSource(g.CoreRegistry, allocator, &scanner, .{}) catch |err| { | 26 | const parsed = std.json.parseFromTokenSource(g.CoreRegistry, allocator, &scanner, .{}) catch |err| { |
| 27 | std.debug.print("line,col: {},{}\n", .{ diagnostics.getLine(), diagnostics.getColumn() }); | 27 | std.debug.print("line,col: {},{}\n", .{ diagnostics.getLine(), diagnostics.getColumn() }); |
| 28 | return err; | 28 | return err; |
| 29 | }; | 29 | }; |
| ... | @@ -466,7 +466,7 @@ fn renderBitEnum( | ... | @@ -466,7 +466,7 @@ fn renderBitEnum( |
| 466 | 466 | ||
| 467 | std.debug.assert(@popCount(value) == 1); | 467 | std.debug.assert(@popCount(value) == 1); |
| 468 | 468 | ||
| 469 | var bitpos = std.math.log2_int(u32, value); | 469 | const bitpos = std.math.log2_int(u32, value); |
| 470 | if (flags_by_bitpos[bitpos]) |*existing| { | 470 | if (flags_by_bitpos[bitpos]) |*existing| { |
| 471 | const tag_index = std.mem.indexOfDiff(u8, enumerant.enumerant, enumerants[existing.*].enumerant).?; | 471 | const tag_index = std.mem.indexOfDiff(u8, enumerant.enumerant, enumerants[existing.*].enumerant).?; |
| 472 | const enum_priority = tagPriorityScore(enumerant.enumerant[tag_index..]); | 472 | const enum_priority = tagPriorityScore(enumerant.enumerant[tag_index..]); |
tools/generate_linux_syscalls.zig+1-1| ... | @@ -35,7 +35,7 @@ pub fn main() !void { | ... | @@ -35,7 +35,7 @@ pub fn main() !void { |
| 35 | 35 | ||
| 36 | // As of 5.17.1, the largest table is 23467 bytes. | 36 | // As of 5.17.1, the largest table is 23467 bytes. |
| 37 | // 32k should be enough for now. | 37 | // 32k should be enough for now. |
| 38 | var buf = try allocator.alloc(u8, 1 << 15); | 38 | const buf = try allocator.alloc(u8, 1 << 15); |
| 39 | const linux_dir = try std.fs.openDirAbsolute(linux_path, .{}); | 39 | const linux_dir = try std.fs.openDirAbsolute(linux_path, .{}); |
| 40 | 40 | ||
| 41 | try writer.writeAll( | 41 | try writer.writeAll( |