| author | |
| committer | |
| log | 31c49ad64ded02b9dde57f5d3ef102a771fa5cf7 |
| tree | d715ce49093cad93f00dff554b47b3b64a58fdc3 |
| parent | fc185a6f71b9bd611a6d808082999a9da0f107e8 |
| parent | 29314b64bd91be91e8f1d48a1b71eba68569be94 |
| signature |
run AstGen even when using the stage1 backend12 files changed, 585 insertions(+), 98 deletions(-)
CMakeLists.txt+6-1| ... | @@ -91,7 +91,12 @@ set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries | ... | @@ -91,7 +91,12 @@ set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries |
| 91 | set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary") | 91 | set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary") |
| 92 | set(ZIG_SINGLE_THREADED off CACHE BOOL "limit the zig compiler to use only 1 thread") | 92 | set(ZIG_SINGLE_THREADED off CACHE BOOL "limit the zig compiler to use only 1 thread") |
| 93 | set(ZIG_OMIT_STAGE2 off CACHE BOOL "omit the stage2 backend from stage1") | 93 | set(ZIG_OMIT_STAGE2 off CACHE BOOL "omit the stage2 backend from stage1") |
| 94 | set(ZIG_ENABLE_LOGGING off CACHE BOOL "enable logging") | 94 | |
| 95 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") | ||
| 96 | set(ZIG_ENABLE_LOGGING ON CACHE BOOL "enable logging") | ||
| 97 | else() | ||
| 98 | set(ZIG_ENABLE_LOGGING OFF CACHE BOOL "enable logging") | ||
| 99 | endif() | ||
| 95 | 100 | ||
| 96 | if("${ZIG_TARGET_TRIPLE}" STREQUAL "native") | 101 | if("${ZIG_TARGET_TRIPLE}" STREQUAL "native") |
| 97 | set(ZIG_USE_LLVM_CONFIG ON CACHE BOOL "use llvm-config to find LLVM libraries") | 102 | set(ZIG_USE_LLVM_CONFIG ON CACHE BOOL "use llvm-config to find LLVM libraries") |
ci/azure/linux_script+2-2| ... | @@ -59,9 +59,9 @@ unset CXX | ... | @@ -59,9 +59,9 @@ unset CXX |
| 59 | 59 | ||
| 60 | make $JOBS install | 60 | make $JOBS install |
| 61 | 61 | ||
| 62 | # Look for formatting errors and AST errors. | 62 | # Look for non-conforming code formatting. |
| 63 | # Formatting errors can be fixed by running `zig fmt` on the files printed here. | 63 | # Formatting errors can be fixed by running `zig fmt` on the files printed here. |
| 64 | release/bin/zig fmt --check --ast-check .. | 64 | release/bin/zig fmt --check .. |
| 65 | 65 | ||
| 66 | # Here we rebuild zig but this time using the Zig binary we just now produced to | 66 | # Here we rebuild zig but this time using the Zig binary we just now produced to |
| 67 | # build zig1.o rather than relying on the one built with stage0. See | 67 | # build zig1.o rather than relying on the one built with stage0. See |
doc/langref.html.in+54-24| ... | @@ -965,7 +965,7 @@ test "thread local storage" { | ... | @@ -965,7 +965,7 @@ test "thread local storage" { |
| 965 | thread2.wait(); | 965 | thread2.wait(); |
| 966 | } | 966 | } |
| 967 | 967 | ||
| 968 | fn testTls(context: void) void { | 968 | fn testTls(_: void) void { |
| 969 | assert(x == 1234); | 969 | assert(x == 1234); |
| 970 | x += 1; | 970 | x += 1; |
| 971 | assert(x == 1235); | 971 | assert(x == 1235); |
| ... | @@ -2502,6 +2502,8 @@ test "struct namespaced variable" { | ... | @@ -2502,6 +2502,8 @@ test "struct namespaced variable" { |
| 2502 | 2502 | ||
| 2503 | // you can still instantiate an empty struct | 2503 | // you can still instantiate an empty struct |
| 2504 | const does_nothing = Empty {}; | 2504 | const does_nothing = Empty {}; |
| 2505 | |||
| 2506 | _ = does_nothing; | ||
| 2505 | } | 2507 | } |
| 2506 | 2508 | ||
| 2507 | // struct field order is determined by the compiler for optimal performance. | 2509 | // struct field order is determined by the compiler for optimal performance. |
| ... | @@ -3026,11 +3028,12 @@ const Foo = enum { a, b, c }; | ... | @@ -3026,11 +3028,12 @@ const Foo = enum { a, b, c }; |
| 3026 | export fn entry(foo: Foo) void { } | 3028 | export fn entry(foo: Foo) void { } |
| 3027 | {#code_end#} | 3029 | {#code_end#} |
| 3028 | <p> | 3030 | <p> |
| 3029 | For a C-ABI-compatible enum, use {#syntax#}extern enum{#endsyntax#}: | 3031 | For a C-ABI-compatible enum, provide an explicit tag type to |
| 3032 | the enum: | ||
| 3030 | </p> | 3033 | </p> |
| 3031 | {#code_begin|obj#} | 3034 | {#code_begin|obj#} |
| 3032 | const Foo = extern enum { a, b, c }; | 3035 | const Foo = enum(c_int) { a, b, c }; |
| 3033 | export fn entry(foo: Foo) void { } | 3036 | export fn entry(foo: Foo) void { _ = foo; } |
| 3034 | {#code_end#} | 3037 | {#code_end#} |
| 3035 | {#header_close#} | 3038 | {#header_close#} |
| 3036 | 3039 | ||
| ... | @@ -3392,9 +3395,11 @@ test "inside test block" { | ... | @@ -3392,9 +3395,11 @@ test "inside test block" { |
| 3392 | test "separate scopes" { | 3395 | test "separate scopes" { |
| 3393 | { | 3396 | { |
| 3394 | const pi = 3.14; | 3397 | const pi = 3.14; |
| 3398 | _ = pi; | ||
| 3395 | } | 3399 | } |
| 3396 | { | 3400 | { |
| 3397 | var pi: bool = true; | 3401 | var pi: bool = true; |
| 3402 | _ = pi; | ||
| 3398 | } | 3403 | } |
| 3399 | } | 3404 | } |
| 3400 | {#code_end#} | 3405 | {#code_end#} |
| ... | @@ -3432,7 +3437,7 @@ test "switch simple" { | ... | @@ -3432,7 +3437,7 @@ test "switch simple" { |
| 3432 | // Switching on arbitrary expressions is allowed as long as the | 3437 | // Switching on arbitrary expressions is allowed as long as the |
| 3433 | // expression is known at compile-time. | 3438 | // expression is known at compile-time. |
| 3434 | zz => zz, | 3439 | zz => zz, |
| 3435 | comptime blk: { | 3440 | blk: { |
| 3436 | const d: u32 = 5; | 3441 | const d: u32 = 5; |
| 3437 | const e: u32 = 100; | 3442 | const e: u32 = 100; |
| 3438 | break :blk d + e; | 3443 | break :blk d + e; |
| ... | @@ -3831,7 +3836,7 @@ test "for basics" { | ... | @@ -3831,7 +3836,7 @@ test "for basics" { |
| 3831 | // To access the index of iteration, specify a second capture value. | 3836 | // To access the index of iteration, specify a second capture value. |
| 3832 | // This is zero-indexed. | 3837 | // This is zero-indexed. |
| 3833 | var sum2: i32 = 0; | 3838 | var sum2: i32 = 0; |
| 3834 | for (items) |value, i| { | 3839 | for (items) |_, i| { |
| 3835 | try expect(@TypeOf(i) == usize); | 3840 | try expect(@TypeOf(i) == usize); |
| 3836 | sum2 += @intCast(i32, i); | 3841 | sum2 += @intCast(i32, i); |
| 3837 | } | 3842 | } |
| ... | @@ -3984,7 +3989,7 @@ test "if optional" { | ... | @@ -3984,7 +3989,7 @@ test "if optional" { |
| 3984 | } | 3989 | } |
| 3985 | 3990 | ||
| 3986 | const b: ?u32 = null; | 3991 | const b: ?u32 = null; |
| 3987 | if (b) |value| { | 3992 | if (b) |_| { |
| 3988 | unreachable; | 3993 | unreachable; |
| 3989 | } else { | 3994 | } else { |
| 3990 | try expect(true); | 3995 | try expect(true); |
| ... | @@ -4021,11 +4026,13 @@ test "if error union" { | ... | @@ -4021,11 +4026,13 @@ test "if error union" { |
| 4021 | if (a) |value| { | 4026 | if (a) |value| { |
| 4022 | try expect(value == 0); | 4027 | try expect(value == 0); |
| 4023 | } else |err| { | 4028 | } else |err| { |
| 4029 | _ = err; | ||
| 4024 | unreachable; | 4030 | unreachable; |
| 4025 | } | 4031 | } |
| 4026 | 4032 | ||
| 4027 | const b: anyerror!u32 = error.BadValue; | 4033 | const b: anyerror!u32 = error.BadValue; |
| 4028 | if (b) |value| { | 4034 | if (b) |value| { |
| 4035 | _ = value; | ||
| 4029 | unreachable; | 4036 | unreachable; |
| 4030 | } else |err| { | 4037 | } else |err| { |
| 4031 | try expect(err == error.BadValue); | 4038 | try expect(err == error.BadValue); |
| ... | @@ -4045,13 +4052,13 @@ test "if error union" { | ... | @@ -4045,13 +4052,13 @@ test "if error union" { |
| 4045 | var c: anyerror!u32 = 3; | 4052 | var c: anyerror!u32 = 3; |
| 4046 | if (c) |*value| { | 4053 | if (c) |*value| { |
| 4047 | value.* = 9; | 4054 | value.* = 9; |
| 4048 | } else |err| { | 4055 | } else |_| { |
| 4049 | unreachable; | 4056 | unreachable; |
| 4050 | } | 4057 | } |
| 4051 | 4058 | ||
| 4052 | if (c) |value| { | 4059 | if (c) |value| { |
| 4053 | try expect(value == 9); | 4060 | try expect(value == 9); |
| 4054 | } else |err| { | 4061 | } else |_| { |
| 4055 | unreachable; | 4062 | unreachable; |
| 4056 | } | 4063 | } |
| 4057 | } | 4064 | } |
| ... | @@ -4064,18 +4071,20 @@ test "if error union with optional" { | ... | @@ -4064,18 +4071,20 @@ test "if error union with optional" { |
| 4064 | if (a) |optional_value| { | 4071 | if (a) |optional_value| { |
| 4065 | try expect(optional_value.? == 0); | 4072 | try expect(optional_value.? == 0); |
| 4066 | } else |err| { | 4073 | } else |err| { |
| 4074 | _ = err; | ||
| 4067 | unreachable; | 4075 | unreachable; |
| 4068 | } | 4076 | } |
| 4069 | 4077 | ||
| 4070 | const b: anyerror!?u32 = null; | 4078 | const b: anyerror!?u32 = null; |
| 4071 | if (b) |optional_value| { | 4079 | if (b) |optional_value| { |
| 4072 | try expect(optional_value == null); | 4080 | try expect(optional_value == null); |
| 4073 | } else |err| { | 4081 | } else |_| { |
| 4074 | unreachable; | 4082 | unreachable; |
| 4075 | } | 4083 | } |
| 4076 | 4084 | ||
| 4077 | const c: anyerror!?u32 = error.BadValue; | 4085 | const c: anyerror!?u32 = error.BadValue; |
| 4078 | if (c) |optional_value| { | 4086 | if (c) |optional_value| { |
| 4087 | _ = optional_value; | ||
| 4079 | unreachable; | 4088 | unreachable; |
| 4080 | } else |err| { | 4089 | } else |err| { |
| 4081 | try expect(err == error.BadValue); | 4090 | try expect(err == error.BadValue); |
| ... | @@ -4087,13 +4096,13 @@ test "if error union with optional" { | ... | @@ -4087,13 +4096,13 @@ test "if error union with optional" { |
| 4087 | if (optional_value.*) |*value| { | 4096 | if (optional_value.*) |*value| { |
| 4088 | value.* = 9; | 4097 | value.* = 9; |
| 4089 | } | 4098 | } |
| 4090 | } else |err| { | 4099 | } else |_| { |
| 4091 | unreachable; | 4100 | unreachable; |
| 4092 | } | 4101 | } |
| 4093 | 4102 | ||
| 4094 | if (d) |optional_value| { | 4103 | if (d) |optional_value| { |
| 4095 | try expect(optional_value.? == 9); | 4104 | try expect(optional_value.? == 9); |
| 4096 | } else |err| { | 4105 | } else |_| { |
| 4097 | unreachable; | 4106 | unreachable; |
| 4098 | } | 4107 | } |
| 4099 | } | 4108 | } |
| ... | @@ -4246,6 +4255,7 @@ test "type of unreachable" { | ... | @@ -4246,6 +4255,7 @@ test "type of unreachable" { |
| 4246 | {#code_begin|test#} | 4255 | {#code_begin|test#} |
| 4247 | fn foo(condition: bool, b: u32) void { | 4256 | fn foo(condition: bool, b: u32) void { |
| 4248 | const a = if (condition) b else return; | 4257 | const a = if (condition) b else return; |
| 4258 | _ = a; | ||
| 4249 | @panic("do something with a"); | 4259 | @panic("do something with a"); |
| 4250 | } | 4260 | } |
| 4251 | test "noreturn" { | 4261 | test "noreturn" { |
| ... | @@ -4574,7 +4584,7 @@ test "parse u64" { | ... | @@ -4574,7 +4584,7 @@ test "parse u64" { |
| 4574 | {#code_begin|syntax#} | 4584 | {#code_begin|syntax#} |
| 4575 | fn doAThing(str: []u8) void { | 4585 | fn doAThing(str: []u8) void { |
| 4576 | const number = parseU64(str, 10) catch 13; | 4586 | const number = parseU64(str, 10) catch 13; |
| 4577 | // ... | 4587 | _ = number; // ... |
| 4578 | } | 4588 | } |
| 4579 | {#code_end#} | 4589 | {#code_end#} |
| 4580 | <p> | 4590 | <p> |
| ... | @@ -4589,7 +4599,7 @@ fn doAThing(str: []u8) void { | ... | @@ -4589,7 +4599,7 @@ fn doAThing(str: []u8) void { |
| 4589 | {#code_begin|syntax#} | 4599 | {#code_begin|syntax#} |
| 4590 | fn doAThing(str: []u8) !void { | 4600 | fn doAThing(str: []u8) !void { |
| 4591 | const number = parseU64(str, 10) catch |err| return err; | 4601 | const number = parseU64(str, 10) catch |err| return err; |
| 4592 | // ... | 4602 | _ = number; // ... |
| 4593 | } | 4603 | } |
| 4594 | {#code_end#} | 4604 | {#code_end#} |
| 4595 | <p> | 4605 | <p> |
| ... | @@ -4598,7 +4608,7 @@ fn doAThing(str: []u8) !void { | ... | @@ -4598,7 +4608,7 @@ fn doAThing(str: []u8) !void { |
| 4598 | {#code_begin|syntax#} | 4608 | {#code_begin|syntax#} |
| 4599 | fn doAThing(str: []u8) !void { | 4609 | fn doAThing(str: []u8) !void { |
| 4600 | const number = try parseU64(str, 10); | 4610 | const number = try parseU64(str, 10); |
| 4601 | // ... | 4611 | _ = number; // ... |
| 4602 | } | 4612 | } |
| 4603 | {#code_end#} | 4613 | {#code_end#} |
| 4604 | <p> | 4614 | <p> |
| ... | @@ -5022,7 +5032,7 @@ extern fn malloc(size: size_t) ?*u8; | ... | @@ -5022,7 +5032,7 @@ extern fn malloc(size: size_t) ?*u8; |
| 5022 | 5032 | ||
| 5023 | fn doAThing() ?*Foo { | 5033 | fn doAThing() ?*Foo { |
| 5024 | const ptr = malloc(1234) orelse return null; | 5034 | const ptr = malloc(1234) orelse return null; |
| 5025 | // ... | 5035 | _ = ptr; // ... |
| 5026 | } | 5036 | } |
| 5027 | {#code_end#} | 5037 | {#code_end#} |
| 5028 | <p> | 5038 | <p> |
| ... | @@ -5135,6 +5145,7 @@ test "optional pointers" { | ... | @@ -5135,6 +5145,7 @@ test "optional pointers" { |
| 5135 | test "type coercion - variable declaration" { | 5145 | test "type coercion - variable declaration" { |
| 5136 | var a: u8 = 1; | 5146 | var a: u8 = 1; |
| 5137 | var b: u16 = a; | 5147 | var b: u16 = a; |
| 5148 | _ = b; | ||
| 5138 | } | 5149 | } |
| 5139 | 5150 | ||
| 5140 | test "type coercion - function call" { | 5151 | test "type coercion - function call" { |
| ... | @@ -5142,11 +5153,14 @@ test "type coercion - function call" { | ... | @@ -5142,11 +5153,14 @@ test "type coercion - function call" { |
| 5142 | foo(a); | 5153 | foo(a); |
| 5143 | } | 5154 | } |
| 5144 | 5155 | ||
| 5145 | fn foo(b: u16) void {} | 5156 | fn foo(b: u16) void { |
| 5157 | _ = b; | ||
| 5158 | } | ||
| 5146 | 5159 | ||
| 5147 | test "type coercion - @as builtin" { | 5160 | test "type coercion - @as builtin" { |
| 5148 | var a: u8 = 1; | 5161 | var a: u8 = 1; |
| 5149 | var b = @as(u16, a); | 5162 | var b = @as(u16, a); |
| 5163 | _ = b; | ||
| 5150 | } | 5164 | } |
| 5151 | {#code_end#} | 5165 | {#code_end#} |
| 5152 | <p> | 5166 | <p> |
| ... | @@ -5174,7 +5188,7 @@ test "type coercion - const qualification" { | ... | @@ -5174,7 +5188,7 @@ test "type coercion - const qualification" { |
| 5174 | foo(b); | 5188 | foo(b); |
| 5175 | } | 5189 | } |
| 5176 | 5190 | ||
| 5177 | fn foo(a: *const i32) void {} | 5191 | fn foo(_: *const i32) void {} |
| 5178 | {#code_end#} | 5192 | {#code_end#} |
| 5179 | <p> | 5193 | <p> |
| 5180 | In addition, pointers coerce to const optional pointers: | 5194 | In addition, pointers coerce to const optional pointers: |
| ... | @@ -5424,7 +5438,7 @@ test "coercion between unions and enums" { | ... | @@ -5424,7 +5438,7 @@ test "coercion between unions and enums" { |
| 5424 | test "coercion of zero bit types" { | 5438 | test "coercion of zero bit types" { |
| 5425 | var x: void = {}; | 5439 | var x: void = {}; |
| 5426 | var y: *void = x; | 5440 | var y: *void = x; |
| 5427 | //var z: void = y; // TODO | 5441 | _ = y; |
| 5428 | } | 5442 | } |
| 5429 | {#code_end#} | 5443 | {#code_end#} |
| 5430 | {#header_close#} | 5444 | {#header_close#} |
| ... | @@ -6569,6 +6583,7 @@ var x: i32 = 1; | ... | @@ -6569,6 +6583,7 @@ var x: i32 = 1; |
| 6569 | test "suspend with no resume" { | 6583 | test "suspend with no resume" { |
| 6570 | var frame = async func(); | 6584 | var frame = async func(); |
| 6571 | try expect(x == 2); | 6585 | try expect(x == 2); |
| 6586 | _ = frame; | ||
| 6572 | } | 6587 | } |
| 6573 | 6588 | ||
| 6574 | fn func() void { | 6589 | fn func() void { |
| ... | @@ -6800,6 +6815,7 @@ fn amain() !void { | ... | @@ -6800,6 +6815,7 @@ fn amain() !void { |
| 6800 | 6815 | ||
| 6801 | var global_download_frame: anyframe = undefined; | 6816 | var global_download_frame: anyframe = undefined; |
| 6802 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { | 6817 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 6818 | _ = url; // this is just an example, we don't actually do it! | ||
| 6803 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); | 6819 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); |
| 6804 | errdefer allocator.free(result); | 6820 | errdefer allocator.free(result); |
| 6805 | suspend { | 6821 | suspend { |
| ... | @@ -6811,6 +6827,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { | ... | @@ -6811,6 +6827,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 6811 | 6827 | ||
| 6812 | var global_file_frame: anyframe = undefined; | 6828 | var global_file_frame: anyframe = undefined; |
| 6813 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { | 6829 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 6830 | _ = filename; // this is just an example, we don't actually do it! | ||
| 6814 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); | 6831 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); |
| 6815 | errdefer allocator.free(result); | 6832 | errdefer allocator.free(result); |
| 6816 | suspend { | 6833 | suspend { |
| ... | @@ -6869,6 +6886,7 @@ fn amain() !void { | ... | @@ -6869,6 +6886,7 @@ fn amain() !void { |
| 6869 | } | 6886 | } |
| 6870 | 6887 | ||
| 6871 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { | 6888 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 6889 | _ = url; // this is just an example, we don't actually do it! | ||
| 6872 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); | 6890 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); |
| 6873 | errdefer allocator.free(result); | 6891 | errdefer allocator.free(result); |
| 6874 | std.debug.print("fetchUrl returning\n", .{}); | 6892 | std.debug.print("fetchUrl returning\n", .{}); |
| ... | @@ -6876,6 +6894,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { | ... | @@ -6876,6 +6894,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 6876 | } | 6894 | } |
| 6877 | 6895 | ||
| 6878 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { | 6896 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 6897 | _ = filename; // this is just an example, we don't actually do it! | ||
| 6879 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); | 6898 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); |
| 6880 | errdefer allocator.free(result); | 6899 | errdefer allocator.free(result); |
| 6881 | std.debug.print("readFile returning\n", .{}); | 6900 | std.debug.print("readFile returning\n", .{}); |
| ... | @@ -8584,6 +8603,7 @@ fn List(comptime T: type) type { | ... | @@ -8584,6 +8603,7 @@ fn List(comptime T: type) type { |
| 8584 | test "integer cast panic" { | 8603 | test "integer cast panic" { |
| 8585 | var a: u16 = 0xabcd; | 8604 | var a: u16 = 0xabcd; |
| 8586 | var b: u8 = @intCast(u8, a); | 8605 | var b: u8 = @intCast(u8, a); |
| 8606 | _ = b; | ||
| 8587 | } | 8607 | } |
| 8588 | {#code_end#} | 8608 | {#code_end#} |
| 8589 | <p> | 8609 | <p> |
| ... | @@ -8839,6 +8859,7 @@ comptime { | ... | @@ -8839,6 +8859,7 @@ comptime { |
| 8839 | {#code_begin|exe_err#} | 8859 | {#code_begin|exe_err#} |
| 8840 | pub fn main() void { | 8860 | pub fn main() void { |
| 8841 | var x = foo("hello"); | 8861 | var x = foo("hello"); |
| 8862 | _ = x; | ||
| 8842 | } | 8863 | } |
| 8843 | 8864 | ||
| 8844 | fn foo(x: []const u8) u8 { | 8865 | fn foo(x: []const u8) u8 { |
| ... | @@ -9107,6 +9128,7 @@ pub fn main() void { | ... | @@ -9107,6 +9128,7 @@ pub fn main() void { |
| 9107 | comptime { | 9128 | comptime { |
| 9108 | const optional_number: ?i32 = null; | 9129 | const optional_number: ?i32 = null; |
| 9109 | const number = optional_number.?; | 9130 | const number = optional_number.?; |
| 9131 | _ = number; | ||
| 9110 | } | 9132 | } |
| 9111 | {#code_end#} | 9133 | {#code_end#} |
| 9112 | <p>At runtime:</p> | 9134 | <p>At runtime:</p> |
| ... | @@ -9140,6 +9162,7 @@ pub fn main() void { | ... | @@ -9140,6 +9162,7 @@ pub fn main() void { |
| 9140 | {#code_begin|test_err|caught unexpected error 'UnableToReturnNumber'#} | 9162 | {#code_begin|test_err|caught unexpected error 'UnableToReturnNumber'#} |
| 9141 | comptime { | 9163 | comptime { |
| 9142 | const number = getNumberOrFail() catch unreachable; | 9164 | const number = getNumberOrFail() catch unreachable; |
| 9165 | _ = number; | ||
| 9143 | } | 9166 | } |
| 9144 | 9167 | ||
| 9145 | fn getNumberOrFail() !i32 { | 9168 | fn getNumberOrFail() !i32 { |
| ... | @@ -9187,6 +9210,7 @@ comptime { | ... | @@ -9187,6 +9210,7 @@ comptime { |
| 9187 | const err = error.AnError; | 9210 | const err = error.AnError; |
| 9188 | const number = @errorToInt(err) + 10; | 9211 | const number = @errorToInt(err) + 10; |
| 9189 | const invalid_err = @intToError(number); | 9212 | const invalid_err = @intToError(number); |
| 9213 | _ = invalid_err; | ||
| 9190 | } | 9214 | } |
| 9191 | {#code_end#} | 9215 | {#code_end#} |
| 9192 | <p>At runtime:</p> | 9216 | <p>At runtime:</p> |
| ... | @@ -9197,7 +9221,7 @@ pub fn main() void { | ... | @@ -9197,7 +9221,7 @@ pub fn main() void { |
| 9197 | var err = error.AnError; | 9221 | var err = error.AnError; |
| 9198 | var number = @errorToInt(err) + 500; | 9222 | var number = @errorToInt(err) + 500; |
| 9199 | var invalid_err = @intToError(number); | 9223 | var invalid_err = @intToError(number); |
| 9200 | std.debug.print("value: {}\n", .{number}); | 9224 | std.debug.print("value: {}\n", .{invalid_err}); |
| 9201 | } | 9225 | } |
| 9202 | {#code_end#} | 9226 | {#code_end#} |
| 9203 | {#header_close#} | 9227 | {#header_close#} |
| ... | @@ -9212,6 +9236,7 @@ const Foo = enum { | ... | @@ -9212,6 +9236,7 @@ const Foo = enum { |
| 9212 | comptime { | 9236 | comptime { |
| 9213 | const a: u2 = 3; | 9237 | const a: u2 = 3; |
| 9214 | const b = @intToEnum(Foo, a); | 9238 | const b = @intToEnum(Foo, a); |
| 9239 | _ = b; | ||
| 9215 | } | 9240 | } |
| 9216 | {#code_end#} | 9241 | {#code_end#} |
| 9217 | <p>At runtime:</p> | 9242 | <p>At runtime:</p> |
| ... | @@ -9396,6 +9421,7 @@ comptime { | ... | @@ -9396,6 +9421,7 @@ comptime { |
| 9396 | pub fn main() void { | 9421 | pub fn main() void { |
| 9397 | var opt_ptr: ?*i32 = null; | 9422 | var opt_ptr: ?*i32 = null; |
| 9398 | var ptr = @ptrCast(*i32, opt_ptr); | 9423 | var ptr = @ptrCast(*i32, opt_ptr); |
| 9424 | _ = ptr; | ||
| 9399 | } | 9425 | } |
| 9400 | {#code_end#} | 9426 | {#code_end#} |
| 9401 | {#header_close#} | 9427 | {#header_close#} |
| ... | @@ -9523,7 +9549,9 @@ pub fn main() !void { | ... | @@ -9523,7 +9549,9 @@ pub fn main() !void { |
| 9523 | This is why it is an error to pass a string literal to a mutable slice, like this: | 9549 | This is why it is an error to pass a string literal to a mutable slice, like this: |
| 9524 | </p> | 9550 | </p> |
| 9525 | {#code_begin|test_err|expected type '[]u8'#} | 9551 | {#code_begin|test_err|expected type '[]u8'#} |
| 9526 | fn foo(s: []u8) void {} | 9552 | fn foo(s: []u8) void { |
| 9553 | _ = s; | ||
| 9554 | } | ||
| 9527 | 9555 | ||
| 9528 | test "string literal to mutable slice" { | 9556 | test "string literal to mutable slice" { |
| 9529 | foo("hello"); | 9557 | foo("hello"); |
| ... | @@ -9531,7 +9559,9 @@ test "string literal to mutable slice" { | ... | @@ -9531,7 +9559,9 @@ test "string literal to mutable slice" { |
| 9531 | {#code_end#} | 9559 | {#code_end#} |
| 9532 | <p>However if you make the slice constant, then it works:</p> | 9560 | <p>However if you make the slice constant, then it works:</p> |
| 9533 | {#code_begin|test|strlit#} | 9561 | {#code_begin|test|strlit#} |
| 9534 | fn foo(s: []const u8) void {} | 9562 | fn foo(s: []const u8) void { |
| 9563 | _ = s; | ||
| 9564 | } | ||
| 9535 | 9565 | ||
| 9536 | test "string literal to constant slice" { | 9566 | test "string literal to constant slice" { |
| 9537 | foo("hello"); | 9567 | foo("hello"); |
| ... | @@ -10476,7 +10506,7 @@ coding style. | ... | @@ -10476,7 +10506,7 @@ coding style. |
| 10476 | </p> | 10506 | </p> |
| 10477 | {#header_close#} | 10507 | {#header_close#} |
| 10478 | {#header_open|Examples#} | 10508 | {#header_open|Examples#} |
| 10479 | {#code_begin|syntax#} | 10509 | <pre>{#syntax#} |
| 10480 | const namespace_name = @import("dir_name/file_name.zig"); | 10510 | const namespace_name = @import("dir_name/file_name.zig"); |
| 10481 | const TypeName = @import("dir_name/TypeName.zig"); | 10511 | const TypeName = @import("dir_name/TypeName.zig"); |
| 10482 | var global_var: i32 = undefined; | 10512 | var global_var: i32 = undefined; |
| ... | @@ -10520,7 +10550,7 @@ const XmlParser = struct { | ... | @@ -10520,7 +10550,7 @@ const XmlParser = struct { |
| 10520 | 10550 | ||
| 10521 | // The initials BE (Big Endian) are just another word in Zig identifier names. | 10551 | // The initials BE (Big Endian) are just another word in Zig identifier names. |
| 10522 | fn readU32Be() u32 {} | 10552 | fn readU32Be() u32 {} |
| 10523 | {#code_end#} | 10553 | {#endsyntax#}</pre> |
| 10524 | <p> | 10554 | <p> |
| 10525 | See the Zig Standard Library for more examples. | 10555 | See the Zig Standard Library for more examples. |
| 10526 | </p> | 10556 | </p> |
src/AstGen.zig+4| ... | @@ -3558,6 +3558,10 @@ fn structDeclInner( | ... | @@ -3558,6 +3558,10 @@ fn structDeclInner( |
| 3558 | const field_name = try astgen.identAsString(member.ast.name_token); | 3558 | const field_name = try astgen.identAsString(member.ast.name_token); |
| 3559 | fields_data.appendAssumeCapacity(field_name); | 3559 | fields_data.appendAssumeCapacity(field_name); |
| 3560 | 3560 | ||
| 3561 | if (member.ast.type_expr == 0) { | ||
| 3562 | return astgen.failTok(member.ast.name_token, "struct field missing type", .{}); | ||
| 3563 | } | ||
| 3564 | |||
| 3561 | const field_type: Zir.Inst.Ref = if (node_tags[member.ast.type_expr] == .@"anytype") | 3565 | const field_type: Zir.Inst.Ref = if (node_tags[member.ast.type_expr] == .@"anytype") |
| 3562 | .none | 3566 | .none |
| 3563 | else | 3567 | else |
src/Compilation.zig+89-59| ... | @@ -342,6 +342,7 @@ pub const AllErrors = struct { | ... | @@ -342,6 +342,7 @@ pub const AllErrors = struct { |
| 342 | const stderr = stderr_file.writer(); | 342 | const stderr = stderr_file.writer(); |
| 343 | switch (msg) { | 343 | switch (msg) { |
| 344 | .src => |src| { | 344 | .src => |src| { |
| 345 | try stderr.writeByteNTimes(' ', indent); | ||
| 345 | ttyconf.setColor(stderr, .Bold); | 346 | ttyconf.setColor(stderr, .Bold); |
| 346 | try stderr.print("{s}:{d}:{d}: ", .{ | 347 | try stderr.print("{s}:{d}:{d}: ", .{ |
| 347 | src.src_path, | 348 | src.src_path, |
| ... | @@ -349,7 +350,6 @@ pub const AllErrors = struct { | ... | @@ -349,7 +350,6 @@ pub const AllErrors = struct { |
| 349 | src.column + 1, | 350 | src.column + 1, |
| 350 | }); | 351 | }); |
| 351 | ttyconf.setColor(stderr, color); | 352 | ttyconf.setColor(stderr, color); |
| 352 | try stderr.writeByteNTimes(' ', indent); | ||
| 353 | try stderr.writeAll(kind); | 353 | try stderr.writeAll(kind); |
| 354 | ttyconf.setColor(stderr, .Reset); | 354 | ttyconf.setColor(stderr, .Reset); |
| 355 | ttyconf.setColor(stderr, .Bold); | 355 | ttyconf.setColor(stderr, .Bold); |
| ... | @@ -731,6 +731,7 @@ fn addPackageTableToCacheHash( | ... | @@ -731,6 +731,7 @@ fn addPackageTableToCacheHash( |
| 731 | hash: *Cache.HashHelper, | 731 | hash: *Cache.HashHelper, |
| 732 | arena: *std.heap.ArenaAllocator, | 732 | arena: *std.heap.ArenaAllocator, |
| 733 | pkg_table: Package.Table, | 733 | pkg_table: Package.Table, |
| 734 | seen_table: *std.AutoHashMap(*Package, void), | ||
| 734 | hash_type: union(enum) { path_bytes, files: *Cache.Manifest }, | 735 | hash_type: union(enum) { path_bytes, files: *Cache.Manifest }, |
| 735 | ) (error{OutOfMemory} || std.os.GetCwdError)!void { | 736 | ) (error{OutOfMemory} || std.os.GetCwdError)!void { |
| 736 | const allocator = &arena.allocator; | 737 | const allocator = &arena.allocator; |
| ... | @@ -755,6 +756,8 @@ fn addPackageTableToCacheHash( | ... | @@ -755,6 +756,8 @@ fn addPackageTableToCacheHash( |
| 755 | }.lessThan); | 756 | }.lessThan); |
| 756 | 757 | ||
| 757 | for (packages) |pkg| { | 758 | for (packages) |pkg| { |
| 759 | if ((try seen_table.getOrPut(pkg.value)).found_existing) continue; | ||
| 760 | |||
| 758 | // Finally insert the package name and path to the cache hash. | 761 | // Finally insert the package name and path to the cache hash. |
| 759 | hash.addBytes(pkg.key); | 762 | hash.addBytes(pkg.key); |
| 760 | switch (hash_type) { | 763 | switch (hash_type) { |
| ... | @@ -770,7 +773,7 @@ fn addPackageTableToCacheHash( | ... | @@ -770,7 +773,7 @@ fn addPackageTableToCacheHash( |
| 770 | }, | 773 | }, |
| 771 | } | 774 | } |
| 772 | // Recurse to handle the package's dependencies | 775 | // Recurse to handle the package's dependencies |
| 773 | try addPackageTableToCacheHash(hash, arena, pkg.value.table, hash_type); | 776 | try addPackageTableToCacheHash(hash, arena, pkg.value.table, seen_table, hash_type); |
| 774 | } | 777 | } |
| 775 | } | 778 | } |
| 776 | 779 | ||
| ... | @@ -1116,7 +1119,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1116,7 +1119,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1116 | { | 1119 | { |
| 1117 | var local_arena = std.heap.ArenaAllocator.init(gpa); | 1120 | var local_arena = std.heap.ArenaAllocator.init(gpa); |
| 1118 | defer local_arena.deinit(); | 1121 | defer local_arena.deinit(); |
| 1119 | try addPackageTableToCacheHash(&hash, &local_arena, root_pkg.table, .path_bytes); | 1122 | var seen_table = std.AutoHashMap(*Package, void).init(&local_arena.allocator); |
| 1123 | try addPackageTableToCacheHash(&hash, &local_arena, root_pkg.table, &seen_table, .path_bytes); | ||
| 1120 | } | 1124 | } |
| 1121 | hash.add(valgrind); | 1125 | hash.add(valgrind); |
| 1122 | hash.add(single_threaded); | 1126 | hash.add(single_threaded); |
| ... | @@ -1137,36 +1141,32 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1137,36 +1141,32 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1137 | artifact_sub_dir, | 1141 | artifact_sub_dir, |
| 1138 | }; | 1142 | }; |
| 1139 | 1143 | ||
| 1140 | // If we rely on stage1, we must not redundantly add these packages. | 1144 | const builtin_pkg = try Package.createWithDir( |
| 1141 | const use_stage1 = build_options.is_stage1 and use_llvm; | 1145 | gpa, |
| 1142 | if (!use_stage1) { | 1146 | zig_cache_artifact_directory, |
| 1143 | const builtin_pkg = try Package.createWithDir( | 1147 | null, |
| 1144 | gpa, | 1148 | "builtin.zig", |
| 1145 | zig_cache_artifact_directory, | 1149 | ); |
| 1146 | null, | 1150 | errdefer builtin_pkg.destroy(gpa); |
| 1147 | "builtin.zig", | ||
| 1148 | ); | ||
| 1149 | errdefer builtin_pkg.destroy(gpa); | ||
| 1150 | 1151 | ||
| 1151 | const std_pkg = try Package.createWithDir( | 1152 | const std_pkg = try Package.createWithDir( |
| 1152 | gpa, | 1153 | gpa, |
| 1153 | options.zig_lib_directory, | 1154 | options.zig_lib_directory, |
| 1154 | "std", | 1155 | "std", |
| 1155 | "std.zig", | 1156 | "std.zig", |
| 1156 | ); | 1157 | ); |
| 1157 | errdefer std_pkg.destroy(gpa); | 1158 | errdefer std_pkg.destroy(gpa); |
| 1158 | 1159 | ||
| 1159 | try root_pkg.addAndAdopt(gpa, "builtin", builtin_pkg); | 1160 | try root_pkg.addAndAdopt(gpa, "builtin", builtin_pkg); |
| 1160 | try root_pkg.add(gpa, "root", root_pkg); | 1161 | try root_pkg.add(gpa, "root", root_pkg); |
| 1161 | try root_pkg.addAndAdopt(gpa, "std", std_pkg); | 1162 | try root_pkg.addAndAdopt(gpa, "std", std_pkg); |
| 1162 | 1163 | ||
| 1163 | try std_pkg.add(gpa, "builtin", builtin_pkg); | 1164 | try std_pkg.add(gpa, "builtin", builtin_pkg); |
| 1164 | try std_pkg.add(gpa, "root", root_pkg); | 1165 | try std_pkg.add(gpa, "root", root_pkg); |
| 1165 | try std_pkg.add(gpa, "std", std_pkg); | 1166 | try std_pkg.add(gpa, "std", std_pkg); |
| 1166 | 1167 | ||
| 1167 | try builtin_pkg.add(gpa, "std", std_pkg); | 1168 | try builtin_pkg.add(gpa, "std", std_pkg); |
| 1168 | try builtin_pkg.add(gpa, "builtin", builtin_pkg); | 1169 | try builtin_pkg.add(gpa, "builtin", builtin_pkg); |
| 1169 | } | ||
| 1170 | 1170 | ||
| 1171 | // Pre-open the directory handles for cached ZIR code so that it does not need | 1171 | // Pre-open the directory handles for cached ZIR code so that it does not need |
| 1172 | // to redundantly happen for each AstGen operation. | 1172 | // to redundantly happen for each AstGen operation. |
| ... | @@ -1625,30 +1625,39 @@ pub fn update(self: *Compilation) !void { | ... | @@ -1625,30 +1625,39 @@ pub fn update(self: *Compilation) !void { |
| 1625 | // Add a Job for each C object. | 1625 | // Add a Job for each C object. |
| 1626 | try self.c_object_work_queue.ensureUnusedCapacity(self.c_object_table.count()); | 1626 | try self.c_object_work_queue.ensureUnusedCapacity(self.c_object_table.count()); |
| 1627 | for (self.c_object_table.keys()) |key| { | 1627 | for (self.c_object_table.keys()) |key| { |
| 1628 | assert(@ptrToInt(key) != 0xaaaa_aaaa_aaaa_aaaa); | ||
| 1629 | self.c_object_work_queue.writeItemAssumeCapacity(key); | 1628 | self.c_object_work_queue.writeItemAssumeCapacity(key); |
| 1630 | } | 1629 | } |
| 1631 | 1630 | ||
| 1632 | const use_stage1 = build_options.omit_stage2 or | 1631 | const use_stage1 = build_options.omit_stage2 or |
| 1633 | (build_options.is_stage1 and self.bin_file.options.use_llvm); | 1632 | (build_options.is_stage1 and self.bin_file.options.use_llvm); |
| 1634 | if (!use_stage1) { | 1633 | if (self.bin_file.options.module) |module| { |
| 1635 | if (self.bin_file.options.module) |module| { | 1634 | module.compile_log_text.shrinkAndFree(module.gpa, 0); |
| 1636 | module.compile_log_text.shrinkAndFree(module.gpa, 0); | 1635 | module.generation += 1; |
| 1637 | module.generation += 1; | 1636 | |
| 1638 | 1637 | // Make sure std.zig is inside the import_table. We unconditionally need | |
| 1639 | // Make sure std.zig is inside the import_table. We unconditionally need | 1638 | // it for start.zig. |
| 1640 | // it for start.zig. | 1639 | const std_pkg = module.root_pkg.table.get("std").?; |
| 1641 | const std_pkg = module.root_pkg.table.get("std").?; | 1640 | _ = try module.importPkg(std_pkg); |
| 1642 | _ = try module.importPkg(std_pkg); | 1641 | |
| 1643 | 1642 | // Normally we rely on importing std to in turn import the root source file | |
| 1644 | // Put a work item in for every known source file to detect if | 1643 | // in the start code, but when using the stage1 backend that won't happen, |
| 1645 | // it changed, and, if so, re-compute ZIR and then queue the job | 1644 | // so in order to run AstGen on the root source file we put it into the |
| 1646 | // to update it. | 1645 | // import_table here. |
| 1647 | try self.astgen_work_queue.ensureUnusedCapacity(module.import_table.count()); | 1646 | if (use_stage1) { |
| 1648 | for (module.import_table.values()) |value| { | 1647 | _ = try module.importPkg(module.root_pkg); |
| 1649 | self.astgen_work_queue.writeItemAssumeCapacity(value); | 1648 | } |
| 1650 | } | 1649 | |
| 1650 | // Put a work item in for every known source file to detect if | ||
| 1651 | // it changed, and, if so, re-compute ZIR and then queue the job | ||
| 1652 | // to update it. | ||
| 1653 | // We still want AstGen work items for stage1 so that we expose compile errors | ||
| 1654 | // that are implemented in stage2 but not stage1. | ||
| 1655 | try self.astgen_work_queue.ensureUnusedCapacity(module.import_table.count()); | ||
| 1656 | for (module.import_table.values()) |value| { | ||
| 1657 | self.astgen_work_queue.writeItemAssumeCapacity(value); | ||
| 1658 | } | ||
| 1651 | 1659 | ||
| 1660 | if (!use_stage1) { | ||
| 1652 | try self.work_queue.writeItem(.{ .analyze_pkg = std_pkg }); | 1661 | try self.work_queue.writeItem(.{ .analyze_pkg = std_pkg }); |
| 1653 | } | 1662 | } |
| 1654 | } | 1663 | } |
| ... | @@ -1915,7 +1924,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor | ... | @@ -1915,7 +1924,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1915 | // (at least for now) single-threaded main work queue. However, C object compilation | 1924 | // (at least for now) single-threaded main work queue. However, C object compilation |
| 1916 | // only needs to be finished by the end of this function. | 1925 | // only needs to be finished by the end of this function. |
| 1917 | 1926 | ||
| 1918 | var zir_prog_node = main_progress_node.start("AstGen", self.astgen_work_queue.count); | 1927 | var zir_prog_node = main_progress_node.start("AST Lowering", self.astgen_work_queue.count); |
| 1919 | defer zir_prog_node.end(); | 1928 | defer zir_prog_node.end(); |
| 1920 | 1929 | ||
| 1921 | var c_obj_prog_node = main_progress_node.start("Compile C Objects", self.c_source_files.len); | 1930 | var c_obj_prog_node = main_progress_node.start("Compile C Objects", self.c_source_files.len); |
| ... | @@ -1936,7 +1945,6 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor | ... | @@ -1936,7 +1945,6 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1936 | } | 1945 | } |
| 1937 | 1946 | ||
| 1938 | while (self.c_object_work_queue.readItem()) |c_object| { | 1947 | while (self.c_object_work_queue.readItem()) |c_object| { |
| 1939 | assert(@ptrToInt(c_object) != 0xaaaa_aaaa_aaaa_aaaa); | ||
| 1940 | self.work_queue_wait_group.start(); | 1948 | self.work_queue_wait_group.start(); |
| 1941 | try self.thread_pool.spawn(workerUpdateCObject, .{ | 1949 | try self.thread_pool.spawn(workerUpdateCObject, .{ |
| 1942 | self, c_object, &c_obj_prog_node, &self.work_queue_wait_group, | 1950 | self, c_object, &c_obj_prog_node, &self.work_queue_wait_group, |
| ... | @@ -1944,9 +1952,13 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor | ... | @@ -1944,9 +1952,13 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1944 | } | 1952 | } |
| 1945 | } | 1953 | } |
| 1946 | 1954 | ||
| 1947 | // Iterate over all the files and look for outdated and deleted declarations. | 1955 | const use_stage1 = build_options.omit_stage2 or |
| 1948 | if (self.bin_file.options.module) |mod| { | 1956 | (build_options.is_stage1 and self.bin_file.options.use_llvm); |
| 1949 | try mod.processOutdatedAndDeletedDecls(); | 1957 | if (!use_stage1) { |
| 1958 | // Iterate over all the files and look for outdated and deleted declarations. | ||
| 1959 | if (self.bin_file.options.module) |mod| { | ||
| 1960 | try mod.processOutdatedAndDeletedDecls(); | ||
| 1961 | } | ||
| 1950 | } | 1962 | } |
| 1951 | 1963 | ||
| 1952 | while (self.work_queue.readItem()) |work_item| switch (work_item) { | 1964 | while (self.work_queue.readItem()) |work_item| switch (work_item) { |
| ... | @@ -2319,6 +2331,9 @@ fn workerAstGenFile( | ... | @@ -2319,6 +2331,9 @@ fn workerAstGenFile( |
| 2319 | break :blk mod.importFile(file, import_path) catch continue; | 2331 | break :blk mod.importFile(file, import_path) catch continue; |
| 2320 | }; | 2332 | }; |
| 2321 | if (import_result.is_new) { | 2333 | if (import_result.is_new) { |
| 2334 | log.debug("AstGen of {s} has import '{s}'; queuing AstGen of {s}", .{ | ||
| 2335 | file.sub_file_path, import_path, import_result.file.sub_file_path, | ||
| 2336 | }); | ||
| 2322 | wg.start(); | 2337 | wg.start(); |
| 2323 | comp.thread_pool.spawn(workerAstGenFile, .{ | 2338 | comp.thread_pool.spawn(workerAstGenFile, .{ |
| 2324 | comp, import_result.file, prog_node, wg, | 2339 | comp, import_result.file, prog_node, wg, |
| ... | @@ -2540,13 +2555,23 @@ fn reportRetryableAstGenError( | ... | @@ -2540,13 +2555,23 @@ fn reportRetryableAstGenError( |
| 2540 | 2555 | ||
| 2541 | file.status = .retryable_failure; | 2556 | file.status = .retryable_failure; |
| 2542 | 2557 | ||
| 2543 | const err_msg = try Module.ErrorMsg.create(gpa, .{ | 2558 | const src_loc: Module.SrcLoc = .{ |
| 2544 | .file_scope = file, | 2559 | .file_scope = file, |
| 2545 | .parent_decl_node = 0, | 2560 | .parent_decl_node = 0, |
| 2546 | .lazy = .entire_file, | 2561 | .lazy = .entire_file, |
| 2547 | }, "unable to load {s}: {s}", .{ | 2562 | }; |
| 2548 | file.sub_file_path, @errorName(err), | 2563 | |
| 2549 | }); | 2564 | const err_msg = if (file.pkg.root_src_directory.path) |dir_path| |
| 2565 | try Module.ErrorMsg.create( | ||
| 2566 | gpa, | ||
| 2567 | src_loc, | ||
| 2568 | "unable to load {s}" ++ std.fs.path.sep_str ++ "{s}: {s}", | ||
| 2569 | .{ dir_path, file.sub_file_path, @errorName(err) }, | ||
| 2570 | ) | ||
| 2571 | else | ||
| 2572 | try Module.ErrorMsg.create(gpa, src_loc, "unable to load {s}: {s}", .{ | ||
| 2573 | file.sub_file_path, @errorName(err), | ||
| 2574 | }); | ||
| 2550 | errdefer err_msg.destroy(gpa); | 2575 | errdefer err_msg.destroy(gpa); |
| 2551 | 2576 | ||
| 2552 | { | 2577 | { |
| ... | @@ -3830,9 +3855,8 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node | ... | @@ -3830,9 +3855,8 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node |
| 3830 | 3855 | ||
| 3831 | _ = try man.addFile(main_zig_file, null); | 3856 | _ = try man.addFile(main_zig_file, null); |
| 3832 | { | 3857 | { |
| 3833 | var local_arena = std.heap.ArenaAllocator.init(comp.gpa); | 3858 | var seen_table = std.AutoHashMap(*Package, void).init(&arena_allocator.allocator); |
| 3834 | defer local_arena.deinit(); | 3859 | try addPackageTableToCacheHash(&man.hash, &arena_allocator, mod.root_pkg.table, &seen_table, .{ .files = &man }); |
| 3835 | try addPackageTableToCacheHash(&man.hash, &local_arena, mod.root_pkg.table, .{ .files = &man }); | ||
| 3836 | } | 3860 | } |
| 3837 | man.hash.add(comp.bin_file.options.valgrind); | 3861 | man.hash.add(comp.bin_file.options.valgrind); |
| 3838 | man.hash.add(comp.bin_file.options.single_threaded); | 3862 | man.hash.add(comp.bin_file.options.single_threaded); |
| ... | @@ -4103,6 +4127,12 @@ fn createStage1Pkg( | ... | @@ -4103,6 +4127,12 @@ fn createStage1Pkg( |
| 4103 | var children = std.ArrayList(*stage1.Pkg).init(arena); | 4127 | var children = std.ArrayList(*stage1.Pkg).init(arena); |
| 4104 | var it = pkg.table.iterator(); | 4128 | var it = pkg.table.iterator(); |
| 4105 | while (it.next()) |entry| { | 4129 | while (it.next()) |entry| { |
| 4130 | if (mem.eql(u8, entry.key_ptr.*, "std") or | ||
| 4131 | mem.eql(u8, entry.key_ptr.*, "builtin") or | ||
| 4132 | mem.eql(u8, entry.key_ptr.*, "root")) | ||
| 4133 | { | ||
| 4134 | continue; | ||
| 4135 | } | ||
| 4106 | try children.append(try createStage1Pkg(arena, entry.key_ptr.*, entry.value_ptr.*, child_pkg)); | 4136 | try children.append(try createStage1Pkg(arena, entry.key_ptr.*, entry.value_ptr.*, child_pkg)); |
| 4107 | } | 4137 | } |
| 4108 | break :blk children.items; | 4138 | break :blk children.items; |
src/Module.zig+3| ... | @@ -3185,6 +3185,9 @@ pub fn importFile( | ... | @@ -3185,6 +3185,9 @@ pub fn importFile( |
| 3185 | if (cur_file.pkg.table.get(import_string)) |pkg| { | 3185 | if (cur_file.pkg.table.get(import_string)) |pkg| { |
| 3186 | return mod.importPkg(pkg); | 3186 | return mod.importPkg(pkg); |
| 3187 | } | 3187 | } |
| 3188 | if (!mem.endsWith(u8, import_string, ".zig")) { | ||
| 3189 | return error.PackageNotFound; | ||
| 3190 | } | ||
| 3188 | const gpa = mod.gpa; | 3191 | const gpa = mod.gpa; |
| 3189 | 3192 | ||
| 3190 | // The resolved path is used as the key in the import table, to detect if | 3193 | // The resolved path is used as the key in the import table, to detect if |
src/codegen/x86_64.zig-1| ... | @@ -4,7 +4,6 @@ const mem = std.mem; | ... | @@ -4,7 +4,6 @@ const mem = std.mem; |
| 4 | const assert = std.debug.assert; | 4 | const assert = std.debug.assert; |
| 5 | const ArrayList = std.ArrayList; | 5 | const ArrayList = std.ArrayList; |
| 6 | const Allocator = std.mem.Allocator; | 6 | const Allocator = std.mem.Allocator; |
| 7 | const Type = @import("../Type.zig"); | ||
| 8 | const DW = std.dwarf; | 7 | const DW = std.dwarf; |
| 9 | 8 | ||
| 10 | // zig fmt: off | 9 | // zig fmt: off |
src/translate_c.zig+20-4| ... | @@ -151,6 +151,12 @@ const Scope = struct { | ... | @@ -151,6 +151,12 @@ const Scope = struct { |
| 151 | return true; | 151 | return true; |
| 152 | return scope.base.parent.?.contains(name); | 152 | return scope.base.parent.?.contains(name); |
| 153 | } | 153 | } |
| 154 | |||
| 155 | fn discardVariable(scope: *Block, c: *Context, name: []const u8) Error!void { | ||
| 156 | const name_node = try Tag.identifier.create(c.arena, name); | ||
| 157 | const discard = try Tag.discard.create(c.arena, name_node); | ||
| 158 | try scope.statements.append(discard); | ||
| 159 | } | ||
| 154 | }; | 160 | }; |
| 155 | 161 | ||
| 156 | const Root = struct { | 162 | const Root = struct { |
| ... | @@ -625,6 +631,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void { | ... | @@ -625,6 +631,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void { |
| 625 | const redecl_node = try Tag.arg_redecl.create(c.arena, .{ .actual = mangled_param_name, .mangled = arg_name }); | 631 | const redecl_node = try Tag.arg_redecl.create(c.arena, .{ .actual = mangled_param_name, .mangled = arg_name }); |
| 626 | try block_scope.statements.append(redecl_node); | 632 | try block_scope.statements.append(redecl_node); |
| 627 | } | 633 | } |
| 634 | try block_scope.discardVariable(c, mangled_param_name); | ||
| 628 | 635 | ||
| 629 | param_id += 1; | 636 | param_id += 1; |
| 630 | } | 637 | } |
| ... | @@ -827,6 +834,7 @@ fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNa | ... | @@ -827,6 +834,7 @@ fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNa |
| 827 | try addTopLevelDecl(c, name, node); | 834 | try addTopLevelDecl(c, name, node); |
| 828 | } else { | 835 | } else { |
| 829 | try scope.appendNode(node); | 836 | try scope.appendNode(node); |
| 837 | try bs.discardVariable(c, name); | ||
| 830 | } | 838 | } |
| 831 | } | 839 | } |
| 832 | 840 | ||
| ... | @@ -1077,6 +1085,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD | ... | @@ -1077,6 +1085,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD |
| 1077 | try c.alias_list.append(.{ .alias = bare_name, .name = name }); | 1085 | try c.alias_list.append(.{ .alias = bare_name, .name = name }); |
| 1078 | } else { | 1086 | } else { |
| 1079 | try scope.appendNode(Node.initPayload(&payload.base)); | 1087 | try scope.appendNode(Node.initPayload(&payload.base)); |
| 1088 | try bs.discardVariable(c, name); | ||
| 1080 | } | 1089 | } |
| 1081 | } | 1090 | } |
| 1082 | 1091 | ||
| ... | @@ -1128,8 +1137,10 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E | ... | @@ -1128,8 +1137,10 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E |
| 1128 | }); | 1137 | }); |
| 1129 | if (toplevel) | 1138 | if (toplevel) |
| 1130 | try addTopLevelDecl(c, enum_val_name, enum_const_def) | 1139 | try addTopLevelDecl(c, enum_val_name, enum_const_def) |
| 1131 | else | 1140 | else { |
| 1132 | try scope.appendNode(enum_const_def); | 1141 | try scope.appendNode(enum_const_def); |
| 1142 | try bs.discardVariable(c, enum_val_name); | ||
| 1143 | } | ||
| 1133 | } | 1144 | } |
| 1134 | 1145 | ||
| 1135 | const int_type = enum_decl.getIntegerType(); | 1146 | const int_type = enum_decl.getIntegerType(); |
| ... | @@ -1168,6 +1179,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E | ... | @@ -1168,6 +1179,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E |
| 1168 | try c.alias_list.append(.{ .alias = bare_name, .name = name }); | 1179 | try c.alias_list.append(.{ .alias = bare_name, .name = name }); |
| 1169 | } else { | 1180 | } else { |
| 1170 | try scope.appendNode(Node.initPayload(&payload.base)); | 1181 | try scope.appendNode(Node.initPayload(&payload.base)); |
| 1182 | try bs.discardVariable(c, name); | ||
| 1171 | } | 1183 | } |
| 1172 | } | 1184 | } |
| 1173 | 1185 | ||
| ... | @@ -1352,11 +1364,10 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE | ... | @@ -1352,11 +1364,10 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE |
| 1352 | init.* = converted_index; | 1364 | init.* = converted_index; |
| 1353 | } | 1365 | } |
| 1354 | 1366 | ||
| 1355 | const mask_init = try Tag.array_init.create(c.arena, .{ | 1367 | return Tag.array_init.create(c.arena, .{ |
| 1356 | .cond = mask_type, | 1368 | .cond = mask_type, |
| 1357 | .cases = init_list, | 1369 | .cases = init_list, |
| 1358 | }); | 1370 | }); |
| 1359 | return Tag.@"comptime".create(c.arena, mask_init); | ||
| 1360 | } | 1371 | } |
| 1361 | 1372 | ||
| 1362 | /// @typeInfo(@TypeOf(vec_node)).Vector.<field> | 1373 | /// @typeInfo(@TypeOf(vec_node)).Vector.<field> |
| ... | @@ -1766,6 +1777,7 @@ fn transDeclStmtOne( | ... | @@ -1766,6 +1777,7 @@ fn transDeclStmtOne( |
| 1766 | node = try Tag.static_local_var.create(c.arena, .{ .name = mangled_name, .init = node }); | 1777 | node = try Tag.static_local_var.create(c.arena, .{ .name = mangled_name, .init = node }); |
| 1767 | } | 1778 | } |
| 1768 | try block_scope.statements.append(node); | 1779 | try block_scope.statements.append(node); |
| 1780 | try block_scope.discardVariable(c, mangled_name); | ||
| 1769 | 1781 | ||
| 1770 | const cleanup_attr = var_decl.getCleanupAttribute(); | 1782 | const cleanup_attr = var_decl.getCleanupAttribute(); |
| 1771 | if (cleanup_attr) |fn_decl| { | 1783 | if (cleanup_attr) |fn_decl| { |
| ... | @@ -4903,6 +4915,10 @@ fn transMacroDefine(c: *Context, m: *MacroCtx) ParseError!void { | ... | @@ -4903,6 +4915,10 @@ fn transMacroDefine(c: *Context, m: *MacroCtx) ParseError!void { |
| 4903 | const scope = &c.global_scope.base; | 4915 | const scope = &c.global_scope.base; |
| 4904 | 4916 | ||
| 4905 | const init_node = try parseCExpr(c, m, scope); | 4917 | const init_node = try parseCExpr(c, m, scope); |
| 4918 | if (init_node.castTag(.identifier)) |ident_node| { | ||
| 4919 | if (mem.eql(u8, "_", ident_node.data)) | ||
| 4920 | return m.fail(c, "unable to translate C expr: illegal identifier _", .{}); | ||
| 4921 | } | ||
| 4906 | const last = m.next().?; | 4922 | const last = m.next().?; |
| 4907 | if (last != .Eof and last != .Nl) | 4923 | if (last != .Eof and last != .Nl) |
| 4908 | return m.fail(c, "unable to translate C expr: unexpected token .{s}", .{@tagName(last)}); | 4924 | return m.fail(c, "unable to translate C expr: unexpected token .{s}", .{@tagName(last)}); |
| ... | @@ -4933,7 +4949,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void { | ... | @@ -4933,7 +4949,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void { |
| 4933 | .name = mangled_name, | 4949 | .name = mangled_name, |
| 4934 | .type = Tag.@"anytype".init(), | 4950 | .type = Tag.@"anytype".init(), |
| 4935 | }); | 4951 | }); |
| 4936 | 4952 | try block_scope.discardVariable(c, mangled_name); | |
| 4937 | if (m.peek().? != .Comma) break; | 4953 | if (m.peek().? != .Comma) break; |
| 4938 | _ = m.next(); | 4954 | _ = m.next(); |
| 4939 | } | 4955 | } |
test/cli.zig+2| ... | @@ -116,6 +116,8 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { | ... | @@ -116,6 +116,8 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { |
| 116 | \\} | 116 | \\} |
| 117 | \\extern fn zig_panic() noreturn; | 117 | \\extern fn zig_panic() noreturn; |
| 118 | \\pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace) noreturn { | 118 | \\pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace) noreturn { |
| 119 | \\ _ = msg; | ||
| 120 | \\ _ = error_return_trace; | ||
| 119 | \\ zig_panic(); | 121 | \\ zig_panic(); |
| 120 | \\} | 122 | \\} |
| 121 | ); | 123 | ); |
test/compare_output.zig+16-2| ... | @@ -10,6 +10,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -10,6 +10,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 10 | \\ @cInclude("stdio.h"); | 10 | \\ @cInclude("stdio.h"); |
| 11 | \\}); | 11 | \\}); |
| 12 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { | 12 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { |
| 13 | \\ _ = argc; | ||
| 14 | \\ _ = argv; | ||
| 13 | \\ _ = c.puts("Hello, world!"); | 15 | \\ _ = c.puts("Hello, world!"); |
| 14 | \\ return 0; | 16 | \\ return 0; |
| 15 | \\} | 17 | \\} |
| ... | @@ -143,6 +145,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -143,6 +145,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 143 | \\}); | 145 | \\}); |
| 144 | \\ | 146 | \\ |
| 145 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { | 147 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { |
| 148 | \\ _ = argc; | ||
| 149 | \\ _ = argv; | ||
| 146 | \\ if (is_windows) { | 150 | \\ if (is_windows) { |
| 147 | \\ // we want actual \n, not \r\n | 151 | \\ // we want actual \n, not \r\n |
| 148 | \\ _ = c._setmode(1, c._O_BINARY); | 152 | \\ _ = c._setmode(1, c._O_BINARY); |
| ... | @@ -265,8 +269,10 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -265,8 +269,10 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 265 | \\const y : u16 = 5678; | 269 | \\const y : u16 = 5678; |
| 266 | \\pub fn main() void { | 270 | \\pub fn main() void { |
| 267 | \\ var x_local : i32 = print_ok(x); | 271 | \\ var x_local : i32 = print_ok(x); |
| 272 | \\ _ = x_local; | ||
| 268 | \\} | 273 | \\} |
| 269 | \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) { | 274 | \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) { |
| 275 | \\ _ = val; | ||
| 270 | \\ const stdout = io.getStdOut().writer(); | 276 | \\ const stdout = io.getStdOut().writer(); |
| 271 | \\ stdout.print("OK\n", .{}) catch unreachable; | 277 | \\ stdout.print("OK\n", .{}) catch unreachable; |
| 272 | \\ return 0; | 278 | \\ return 0; |
| ... | @@ -318,6 +324,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -318,6 +324,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 318 | \\}); | 324 | \\}); |
| 319 | \\ | 325 | \\ |
| 320 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { | 326 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { |
| 327 | \\ _ = argc; | ||
| 328 | \\ _ = argv; | ||
| 321 | \\ if (is_windows) { | 329 | \\ if (is_windows) { |
| 322 | \\ // we want actual \n, not \r\n | 330 | \\ // we want actual \n, not \r\n |
| 323 | \\ _ = c._setmode(1, c._O_BINARY); | 331 | \\ _ = c._setmode(1, c._O_BINARY); |
| ... | @@ -337,13 +345,19 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -337,13 +345,19 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 337 | \\const Foo = struct { | 345 | \\const Foo = struct { |
| 338 | \\ field1: Bar, | 346 | \\ field1: Bar, |
| 339 | \\ | 347 | \\ |
| 340 | \\ fn method(a: *const Foo) bool { return true; } | 348 | \\ fn method(a: *const Foo) bool { |
| 349 | \\ _ = a; | ||
| 350 | \\ return true; | ||
| 351 | \\ } | ||
| 341 | \\}; | 352 | \\}; |
| 342 | \\ | 353 | \\ |
| 343 | \\const Bar = struct { | 354 | \\const Bar = struct { |
| 344 | \\ field2: i32, | 355 | \\ field2: i32, |
| 345 | \\ | 356 | \\ |
| 346 | \\ fn method(b: *const Bar) bool { return true; } | 357 | \\ fn method(b: *const Bar) bool { |
| 358 | \\ _ = b; | ||
| 359 | \\ return true; | ||
| 360 | \\ } | ||
| 347 | \\}; | 361 | \\}; |
| 348 | \\ | 362 | \\ |
| 349 | \\pub fn main() void { | 363 | \\pub fn main() void { |
test/runtime_safety.zig+160-5| ... | @@ -4,6 +4,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -4,6 +4,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 4 | { | 4 | { |
| 5 | const check_panic_msg = | 5 | const check_panic_msg = |
| 6 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 6 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 7 | \\ _ = stack_trace; | ||
| 7 | \\ if (std.mem.eql(u8, message, "reached unreachable code")) { | 8 | \\ if (std.mem.eql(u8, message, "reached unreachable code")) { |
| 8 | \\ std.process.exit(126); // good | 9 | \\ std.process.exit(126); // good |
| 9 | \\ } | 10 | \\ } |
| ... | @@ -45,6 +46,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -45,6 +46,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 45 | { | 46 | { |
| 46 | const check_panic_msg = | 47 | const check_panic_msg = |
| 47 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 48 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 49 | \\ _ = stack_trace; | ||
| 48 | \\ if (std.mem.eql(u8, message, "invalid enum value")) { | 50 | \\ if (std.mem.eql(u8, message, "invalid enum value")) { |
| 49 | \\ std.process.exit(126); // good | 51 | \\ std.process.exit(126); // good |
| 50 | \\ } | 52 | \\ } |
| ... | @@ -62,6 +64,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -62,6 +64,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 62 | \\ var e: E = undefined; | 64 | \\ var e: E = undefined; |
| 63 | \\ @memset(@ptrCast([*]u8, &e), 0x55, @sizeOf(E)); | 65 | \\ @memset(@ptrCast([*]u8, &e), 0x55, @sizeOf(E)); |
| 64 | \\ var n = @tagName(e); | 66 | \\ var n = @tagName(e); |
| 67 | \\ _ = n; | ||
| 65 | \\} | 68 | \\} |
| 66 | ); | 69 | ); |
| 67 | 70 | ||
| ... | @@ -76,6 +79,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -76,6 +79,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 76 | \\ @memset(@ptrCast([*]u8, &u), 0x55, @sizeOf(U)); | 79 | \\ @memset(@ptrCast([*]u8, &u), 0x55, @sizeOf(U)); |
| 77 | \\ var t: @typeInfo(U).Union.tag_type.? = u; | 80 | \\ var t: @typeInfo(U).Union.tag_type.? = u; |
| 78 | \\ var n = @tagName(t); | 81 | \\ var n = @tagName(t); |
| 82 | \\ _ = n; | ||
| 79 | \\} | 83 | \\} |
| 80 | ); | 84 | ); |
| 81 | } | 85 | } |
| ... | @@ -83,6 +87,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -83,6 +87,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 83 | { | 87 | { |
| 84 | const check_panic_msg = | 88 | const check_panic_msg = |
| 85 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 89 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 90 | \\ _ = stack_trace; | ||
| 86 | \\ if (std.mem.eql(u8, message, "index out of bounds")) { | 91 | \\ if (std.mem.eql(u8, message, "index out of bounds")) { |
| 87 | \\ std.process.exit(126); // good | 92 | \\ std.process.exit(126); // good |
| 88 | \\ } | 93 | \\ } |
| ... | @@ -96,6 +101,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -96,6 +101,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 96 | \\pub fn main() void { | 101 | \\pub fn main() void { |
| 97 | \\ var buf = [4]u8{'a','b','c',0}; | 102 | \\ var buf = [4]u8{'a','b','c',0}; |
| 98 | \\ const slice = buf[0..4 :0]; | 103 | \\ const slice = buf[0..4 :0]; |
| 104 | \\ _ = slice; | ||
| 99 | \\} | 105 | \\} |
| 100 | ); | 106 | ); |
| 101 | cases.addRuntimeSafety("slicing operator with sentinel", | 107 | cases.addRuntimeSafety("slicing operator with sentinel", |
| ... | @@ -104,6 +110,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -104,6 +110,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 104 | \\pub fn main() void { | 110 | \\pub fn main() void { |
| 105 | \\ var buf = [4]u8{'a','b','c',0}; | 111 | \\ var buf = [4]u8{'a','b','c',0}; |
| 106 | \\ const slice = buf[0..:0]; | 112 | \\ const slice = buf[0..:0]; |
| 113 | \\ _ = slice; | ||
| 107 | \\} | 114 | \\} |
| 108 | ); | 115 | ); |
| 109 | cases.addRuntimeSafety("slicing operator with sentinel", | 116 | cases.addRuntimeSafety("slicing operator with sentinel", |
| ... | @@ -112,6 +119,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -112,6 +119,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 112 | \\pub fn main() void { | 119 | \\pub fn main() void { |
| 113 | \\ var buf_zero = [0]u8{}; | 120 | \\ var buf_zero = [0]u8{}; |
| 114 | \\ const slice = buf_zero[0..0 :0]; | 121 | \\ const slice = buf_zero[0..0 :0]; |
| 122 | \\ _ = slice; | ||
| 115 | \\} | 123 | \\} |
| 116 | ); | 124 | ); |
| 117 | cases.addRuntimeSafety("slicing operator with sentinel", | 125 | cases.addRuntimeSafety("slicing operator with sentinel", |
| ... | @@ -120,6 +128,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -120,6 +128,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 120 | \\pub fn main() void { | 128 | \\pub fn main() void { |
| 121 | \\ var buf_zero = [0]u8{}; | 129 | \\ var buf_zero = [0]u8{}; |
| 122 | \\ const slice = buf_zero[0..:0]; | 130 | \\ const slice = buf_zero[0..:0]; |
| 131 | \\ _ = slice; | ||
| 123 | \\} | 132 | \\} |
| 124 | ); | 133 | ); |
| 125 | cases.addRuntimeSafety("slicing operator with sentinel", | 134 | cases.addRuntimeSafety("slicing operator with sentinel", |
| ... | @@ -129,6 +138,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -129,6 +138,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 129 | \\ var buf_sentinel = [2:0]u8{'a','b'}; | 138 | \\ var buf_sentinel = [2:0]u8{'a','b'}; |
| 130 | \\ @ptrCast(*[3]u8, &buf_sentinel)[2] = 0; | 139 | \\ @ptrCast(*[3]u8, &buf_sentinel)[2] = 0; |
| 131 | \\ const slice = buf_sentinel[0..3 :0]; | 140 | \\ const slice = buf_sentinel[0..3 :0]; |
| 141 | \\ _ = slice; | ||
| 132 | \\} | 142 | \\} |
| 133 | ); | 143 | ); |
| 134 | cases.addRuntimeSafety("slicing operator with sentinel", | 144 | cases.addRuntimeSafety("slicing operator with sentinel", |
| ... | @@ -137,6 +147,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -137,6 +147,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 137 | \\pub fn main() void { | 147 | \\pub fn main() void { |
| 138 | \\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 }; | 148 | \\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 }; |
| 139 | \\ const slice = buf_slice[0..3 :0]; | 149 | \\ const slice = buf_slice[0..3 :0]; |
| 150 | \\ _ = slice; | ||
| 140 | \\} | 151 | \\} |
| 141 | ); | 152 | ); |
| 142 | cases.addRuntimeSafety("slicing operator with sentinel", | 153 | cases.addRuntimeSafety("slicing operator with sentinel", |
| ... | @@ -145,6 +156,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -145,6 +156,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 145 | \\pub fn main() void { | 156 | \\pub fn main() void { |
| 146 | \\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 }; | 157 | \\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 }; |
| 147 | \\ const slice = buf_slice[0.. :0]; | 158 | \\ const slice = buf_slice[0.. :0]; |
| 159 | \\ _ = slice; | ||
| 148 | \\} | 160 | \\} |
| 149 | ); | 161 | ); |
| 150 | } | 162 | } |
| ... | @@ -153,6 +165,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -153,6 +165,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 153 | \\const std = @import("std"); | 165 | \\const std = @import("std"); |
| 154 | \\const V = @import("std").meta.Vector; | 166 | \\const V = @import("std").meta.Vector; |
| 155 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 167 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 168 | \\ _ = stack_trace; | ||
| 156 | \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) { | 169 | \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) { |
| 157 | \\ std.process.exit(126); // good | 170 | \\ std.process.exit(126); // good |
| 158 | \\ } | 171 | \\ } |
| ... | @@ -161,6 +174,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -161,6 +174,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 161 | \\pub fn main() void { | 174 | \\pub fn main() void { |
| 162 | \\ var x = @splat(4, @as(u32, 0xdeadbeef)); | 175 | \\ var x = @splat(4, @as(u32, 0xdeadbeef)); |
| 163 | \\ var y = @intCast(V(4, u16), x); | 176 | \\ var y = @intCast(V(4, u16), x); |
| 177 | \\ _ = y; | ||
| 164 | \\} | 178 | \\} |
| 165 | ); | 179 | ); |
| 166 | 180 | ||
| ... | @@ -168,6 +182,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -168,6 +182,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 168 | \\const std = @import("std"); | 182 | \\const std = @import("std"); |
| 169 | \\const V = @import("std").meta.Vector; | 183 | \\const V = @import("std").meta.Vector; |
| 170 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 184 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 185 | \\ _ = stack_trace; | ||
| 171 | \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) { | 186 | \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) { |
| 172 | \\ std.process.exit(126); // good | 187 | \\ std.process.exit(126); // good |
| 173 | \\ } | 188 | \\ } |
| ... | @@ -176,6 +191,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -176,6 +191,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 176 | \\pub fn main() void { | 191 | \\pub fn main() void { |
| 177 | \\ var x = @splat(4, @as(u32, 0x80000000)); | 192 | \\ var x = @splat(4, @as(u32, 0x80000000)); |
| 178 | \\ var y = @intCast(V(4, i32), x); | 193 | \\ var y = @intCast(V(4, i32), x); |
| 194 | \\ _ = y; | ||
| 179 | \\} | 195 | \\} |
| 180 | ); | 196 | ); |
| 181 | 197 | ||
| ... | @@ -183,6 +199,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -183,6 +199,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 183 | \\const std = @import("std"); | 199 | \\const std = @import("std"); |
| 184 | \\const V = @import("std").meta.Vector; | 200 | \\const V = @import("std").meta.Vector; |
| 185 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 201 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 202 | \\ _ = stack_trace; | ||
| 186 | \\ if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) { | 203 | \\ if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) { |
| 187 | \\ std.process.exit(126); // good | 204 | \\ std.process.exit(126); // good |
| 188 | \\ } | 205 | \\ } |
| ... | @@ -191,12 +208,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -191,12 +208,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 191 | \\pub fn main() void { | 208 | \\pub fn main() void { |
| 192 | \\ var x = @splat(4, @as(i32, -2147483647)); | 209 | \\ var x = @splat(4, @as(i32, -2147483647)); |
| 193 | \\ var y = @intCast(V(4, u32), x); | 210 | \\ var y = @intCast(V(4, u32), x); |
| 211 | \\ _ = y; | ||
| 194 | \\} | 212 | \\} |
| 195 | ); | 213 | ); |
| 196 | 214 | ||
| 197 | cases.addRuntimeSafety("shift left by huge amount", | 215 | cases.addRuntimeSafety("shift left by huge amount", |
| 198 | \\const std = @import("std"); | 216 | \\const std = @import("std"); |
| 199 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 217 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 218 | \\ _ = stack_trace; | ||
| 200 | \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) { | 219 | \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) { |
| 201 | \\ std.process.exit(126); // good | 220 | \\ std.process.exit(126); // good |
| 202 | \\ } | 221 | \\ } |
| ... | @@ -206,12 +225,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -206,12 +225,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 206 | \\ var x: u24 = 42; | 225 | \\ var x: u24 = 42; |
| 207 | \\ var y: u5 = 24; | 226 | \\ var y: u5 = 24; |
| 208 | \\ var z = x >> y; | 227 | \\ var z = x >> y; |
| 228 | \\ _ = z; | ||
| 209 | \\} | 229 | \\} |
| 210 | ); | 230 | ); |
| 211 | 231 | ||
| 212 | cases.addRuntimeSafety("shift right by huge amount", | 232 | cases.addRuntimeSafety("shift right by huge amount", |
| 213 | \\const std = @import("std"); | 233 | \\const std = @import("std"); |
| 214 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 234 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 235 | \\ _ = stack_trace; | ||
| 215 | \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) { | 236 | \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) { |
| 216 | \\ std.process.exit(126); // good | 237 | \\ std.process.exit(126); // good |
| 217 | \\ } | 238 | \\ } |
| ... | @@ -221,12 +242,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -221,12 +242,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 221 | \\ var x: u24 = 42; | 242 | \\ var x: u24 = 42; |
| 222 | \\ var y: u5 = 24; | 243 | \\ var y: u5 = 24; |
| 223 | \\ var z = x << y; | 244 | \\ var z = x << y; |
| 245 | \\ _ = z; | ||
| 224 | \\} | 246 | \\} |
| 225 | ); | 247 | ); |
| 226 | 248 | ||
| 227 | cases.addRuntimeSafety("slice sentinel mismatch - optional pointers", | 249 | cases.addRuntimeSafety("slice sentinel mismatch - optional pointers", |
| 228 | \\const std = @import("std"); | 250 | \\const std = @import("std"); |
| 229 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 251 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 252 | \\ _ = stack_trace; | ||
| 230 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { | 253 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { |
| 231 | \\ std.process.exit(126); // good | 254 | \\ std.process.exit(126); // good |
| 232 | \\ } | 255 | \\ } |
| ... | @@ -235,12 +258,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -235,12 +258,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 235 | \\pub fn main() void { | 258 | \\pub fn main() void { |
| 236 | \\ var buf: [4]?*i32 = undefined; | 259 | \\ var buf: [4]?*i32 = undefined; |
| 237 | \\ const slice = buf[0..3 :null]; | 260 | \\ const slice = buf[0..3 :null]; |
| 261 | \\ _ = slice; | ||
| 238 | \\} | 262 | \\} |
| 239 | ); | 263 | ); |
| 240 | 264 | ||
| 241 | cases.addRuntimeSafety("slice sentinel mismatch - floats", | 265 | cases.addRuntimeSafety("slice sentinel mismatch - floats", |
| 242 | \\const std = @import("std"); | 266 | \\const std = @import("std"); |
| 243 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 267 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 268 | \\ _ = stack_trace; | ||
| 244 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { | 269 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { |
| 245 | \\ std.process.exit(126); // good | 270 | \\ std.process.exit(126); // good |
| 246 | \\ } | 271 | \\ } |
| ... | @@ -249,12 +274,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -249,12 +274,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 249 | \\pub fn main() void { | 274 | \\pub fn main() void { |
| 250 | \\ var buf: [4]f32 = undefined; | 275 | \\ var buf: [4]f32 = undefined; |
| 251 | \\ const slice = buf[0..3 :1.2]; | 276 | \\ const slice = buf[0..3 :1.2]; |
| 277 | \\ _ = slice; | ||
| 252 | \\} | 278 | \\} |
| 253 | ); | 279 | ); |
| 254 | 280 | ||
| 255 | cases.addRuntimeSafety("pointer slice sentinel mismatch", | 281 | cases.addRuntimeSafety("pointer slice sentinel mismatch", |
| 256 | \\const std = @import("std"); | 282 | \\const std = @import("std"); |
| 257 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 283 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 284 | \\ _ = stack_trace; | ||
| 258 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { | 285 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { |
| 259 | \\ std.process.exit(126); // good | 286 | \\ std.process.exit(126); // good |
| 260 | \\ } | 287 | \\ } |
| ... | @@ -264,12 +291,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -264,12 +291,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 264 | \\ var buf: [4]u8 = undefined; | 291 | \\ var buf: [4]u8 = undefined; |
| 265 | \\ const ptr: [*]u8 = &buf; | 292 | \\ const ptr: [*]u8 = &buf; |
| 266 | \\ const slice = ptr[0..3 :0]; | 293 | \\ const slice = ptr[0..3 :0]; |
| 294 | \\ _ = slice; | ||
| 267 | \\} | 295 | \\} |
| 268 | ); | 296 | ); |
| 269 | 297 | ||
| 270 | cases.addRuntimeSafety("slice slice sentinel mismatch", | 298 | cases.addRuntimeSafety("slice slice sentinel mismatch", |
| 271 | \\const std = @import("std"); | 299 | \\const std = @import("std"); |
| 272 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 300 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 301 | \\ _ = stack_trace; | ||
| 273 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { | 302 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { |
| 274 | \\ std.process.exit(126); // good | 303 | \\ std.process.exit(126); // good |
| 275 | \\ } | 304 | \\ } |
| ... | @@ -279,12 +308,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -279,12 +308,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 279 | \\ var buf: [4]u8 = undefined; | 308 | \\ var buf: [4]u8 = undefined; |
| 280 | \\ const slice = buf[0..]; | 309 | \\ const slice = buf[0..]; |
| 281 | \\ const slice2 = slice[0..3 :0]; | 310 | \\ const slice2 = slice[0..3 :0]; |
| 311 | \\ _ = slice2; | ||
| 282 | \\} | 312 | \\} |
| 283 | ); | 313 | ); |
| 284 | 314 | ||
| 285 | cases.addRuntimeSafety("array slice sentinel mismatch", | 315 | cases.addRuntimeSafety("array slice sentinel mismatch", |
| 286 | \\const std = @import("std"); | 316 | \\const std = @import("std"); |
| 287 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 317 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 318 | \\ _ = stack_trace; | ||
| 288 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { | 319 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { |
| 289 | \\ std.process.exit(126); // good | 320 | \\ std.process.exit(126); // good |
| 290 | \\ } | 321 | \\ } |
| ... | @@ -293,12 +324,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -293,12 +324,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 293 | \\pub fn main() void { | 324 | \\pub fn main() void { |
| 294 | \\ var buf: [4]u8 = undefined; | 325 | \\ var buf: [4]u8 = undefined; |
| 295 | \\ const slice = buf[0..3 :0]; | 326 | \\ const slice = buf[0..3 :0]; |
| 327 | \\ _ = slice; | ||
| 296 | \\} | 328 | \\} |
| 297 | ); | 329 | ); |
| 298 | 330 | ||
| 299 | cases.addRuntimeSafety("intToPtr with misaligned address", | 331 | cases.addRuntimeSafety("intToPtr with misaligned address", |
| 300 | \\const std = @import("std"); | 332 | \\const std = @import("std"); |
| 301 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 333 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 334 | \\ _ = stack_trace; | ||
| 302 | \\ if (std.mem.eql(u8, message, "incorrect alignment")) { | 335 | \\ if (std.mem.eql(u8, message, "incorrect alignment")) { |
| 303 | \\ std.os.exit(126); // good | 336 | \\ std.os.exit(126); // good |
| 304 | \\ } | 337 | \\ } |
| ... | @@ -307,16 +340,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -307,16 +340,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 307 | \\pub fn main() void { | 340 | \\pub fn main() void { |
| 308 | \\ var x: usize = 5; | 341 | \\ var x: usize = 5; |
| 309 | \\ var y = @intToPtr([*]align(4) u8, x); | 342 | \\ var y = @intToPtr([*]align(4) u8, x); |
| 343 | \\ _ = y; | ||
| 310 | \\} | 344 | \\} |
| 311 | ); | 345 | ); |
| 312 | 346 | ||
| 313 | cases.addRuntimeSafety("resuming a non-suspended function which never been suspended", | 347 | cases.addRuntimeSafety("resuming a non-suspended function which never been suspended", |
| 314 | \\const std = @import("std"); | 348 | \\const std = @import("std"); |
| 315 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 349 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 350 | \\ _ = message; | ||
| 351 | \\ _ = stack_trace; | ||
| 316 | \\ std.os.exit(126); | 352 | \\ std.os.exit(126); |
| 317 | \\} | 353 | \\} |
| 318 | \\fn foo() void { | 354 | \\fn foo() void { |
| 319 | \\ var f = async bar(@frame()); | 355 | \\ var f = async bar(@frame()); |
| 356 | \\ _ = f; | ||
| 320 | \\ std.os.exit(0); | 357 | \\ std.os.exit(0); |
| 321 | \\} | 358 | \\} |
| 322 | \\ | 359 | \\ |
| ... | @@ -335,6 +372,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -335,6 +372,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 335 | cases.addRuntimeSafety("resuming a non-suspended function which has been suspended and resumed", | 372 | cases.addRuntimeSafety("resuming a non-suspended function which has been suspended and resumed", |
| 336 | \\const std = @import("std"); | 373 | \\const std = @import("std"); |
| 337 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 374 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 375 | \\ _ = message; | ||
| 376 | \\ _ = stack_trace; | ||
| 338 | \\ std.os.exit(126); | 377 | \\ std.os.exit(126); |
| 339 | \\} | 378 | \\} |
| 340 | \\fn foo() void { | 379 | \\fn foo() void { |
| ... | @@ -342,6 +381,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -342,6 +381,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 342 | \\ global_frame = @frame(); | 381 | \\ global_frame = @frame(); |
| 343 | \\ } | 382 | \\ } |
| 344 | \\ var f = async bar(@frame()); | 383 | \\ var f = async bar(@frame()); |
| 384 | \\ _ = f; | ||
| 345 | \\ std.os.exit(0); | 385 | \\ std.os.exit(0); |
| 346 | \\} | 386 | \\} |
| 347 | \\ | 387 | \\ |
| ... | @@ -363,6 +403,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -363,6 +403,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 363 | cases.addRuntimeSafety("nosuspend function call, callee suspends", | 403 | cases.addRuntimeSafety("nosuspend function call, callee suspends", |
| 364 | \\const std = @import("std"); | 404 | \\const std = @import("std"); |
| 365 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 405 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 406 | \\ _ = message; | ||
| 407 | \\ _ = stack_trace; | ||
| 366 | \\ std.os.exit(126); | 408 | \\ std.os.exit(126); |
| 367 | \\} | 409 | \\} |
| 368 | \\pub fn main() void { | 410 | \\pub fn main() void { |
| ... | @@ -379,6 +421,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -379,6 +421,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 379 | cases.addRuntimeSafety("awaiting twice", | 421 | cases.addRuntimeSafety("awaiting twice", |
| 380 | \\const std = @import("std"); | 422 | \\const std = @import("std"); |
| 381 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 423 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 424 | \\ _ = message; | ||
| 425 | \\ _ = stack_trace; | ||
| 382 | \\ std.os.exit(126); | 426 | \\ std.os.exit(126); |
| 383 | \\} | 427 | \\} |
| 384 | \\var frame: anyframe = undefined; | 428 | \\var frame: anyframe = undefined; |
| ... | @@ -404,12 +448,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -404,12 +448,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 404 | cases.addRuntimeSafety("@asyncCall with too small a frame", | 448 | cases.addRuntimeSafety("@asyncCall with too small a frame", |
| 405 | \\const std = @import("std"); | 449 | \\const std = @import("std"); |
| 406 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 450 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 451 | \\ _ = message; | ||
| 452 | \\ _ = stack_trace; | ||
| 407 | \\ std.os.exit(126); | 453 | \\ std.os.exit(126); |
| 408 | \\} | 454 | \\} |
| 409 | \\pub fn main() void { | 455 | \\pub fn main() void { |
| 410 | \\ var bytes: [1]u8 align(16) = undefined; | 456 | \\ var bytes: [1]u8 align(16) = undefined; |
| 411 | \\ var ptr = other; | 457 | \\ var ptr = other; |
| 412 | \\ var frame = @asyncCall(&bytes, {}, ptr, .{}); | 458 | \\ var frame = @asyncCall(&bytes, {}, ptr, .{}); |
| 459 | \\ _ = frame; | ||
| 413 | \\} | 460 | \\} |
| 414 | \\fn other() callconv(.Async) void { | 461 | \\fn other() callconv(.Async) void { |
| 415 | \\ suspend {} | 462 | \\ suspend {} |
| ... | @@ -419,6 +466,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -419,6 +466,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 419 | cases.addRuntimeSafety("resuming a function which is awaiting a frame", | 466 | cases.addRuntimeSafety("resuming a function which is awaiting a frame", |
| 420 | \\const std = @import("std"); | 467 | \\const std = @import("std"); |
| 421 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 468 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 469 | \\ _ = message; | ||
| 470 | \\ _ = stack_trace; | ||
| 422 | \\ std.os.exit(126); | 471 | \\ std.os.exit(126); |
| 423 | \\} | 472 | \\} |
| 424 | \\pub fn main() void { | 473 | \\pub fn main() void { |
| ... | @@ -437,6 +486,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -437,6 +486,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 437 | cases.addRuntimeSafety("resuming a function which is awaiting a call", | 486 | cases.addRuntimeSafety("resuming a function which is awaiting a call", |
| 438 | \\const std = @import("std"); | 487 | \\const std = @import("std"); |
| 439 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 488 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 489 | \\ _ = message; | ||
| 490 | \\ _ = stack_trace; | ||
| 440 | \\ std.os.exit(126); | 491 | \\ std.os.exit(126); |
| 441 | \\} | 492 | \\} |
| 442 | \\pub fn main() void { | 493 | \\pub fn main() void { |
| ... | @@ -454,6 +505,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -454,6 +505,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 454 | cases.addRuntimeSafety("invalid resume of async function", | 505 | cases.addRuntimeSafety("invalid resume of async function", |
| 455 | \\const std = @import("std"); | 506 | \\const std = @import("std"); |
| 456 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 507 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 508 | \\ _ = message; | ||
| 509 | \\ _ = stack_trace; | ||
| 457 | \\ std.os.exit(126); | 510 | \\ std.os.exit(126); |
| 458 | \\} | 511 | \\} |
| 459 | \\pub fn main() void { | 512 | \\pub fn main() void { |
| ... | @@ -469,61 +522,78 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -469,61 +522,78 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 469 | cases.addRuntimeSafety(".? operator on null pointer", | 522 | cases.addRuntimeSafety(".? operator on null pointer", |
| 470 | \\const std = @import("std"); | 523 | \\const std = @import("std"); |
| 471 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 524 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 525 | \\ _ = message; | ||
| 526 | \\ _ = stack_trace; | ||
| 472 | \\ std.os.exit(126); | 527 | \\ std.os.exit(126); |
| 473 | \\} | 528 | \\} |
| 474 | \\pub fn main() void { | 529 | \\pub fn main() void { |
| 475 | \\ var ptr: ?*i32 = null; | 530 | \\ var ptr: ?*i32 = null; |
| 476 | \\ var b = ptr.?; | 531 | \\ var b = ptr.?; |
| 532 | \\ _ = b; | ||
| 477 | \\} | 533 | \\} |
| 478 | ); | 534 | ); |
| 479 | 535 | ||
| 480 | cases.addRuntimeSafety(".? operator on C pointer", | 536 | cases.addRuntimeSafety(".? operator on C pointer", |
| 481 | \\const std = @import("std"); | 537 | \\const std = @import("std"); |
| 482 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 538 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 539 | \\ _ = message; | ||
| 540 | \\ _ = stack_trace; | ||
| 483 | \\ std.os.exit(126); | 541 | \\ std.os.exit(126); |
| 484 | \\} | 542 | \\} |
| 485 | \\pub fn main() void { | 543 | \\pub fn main() void { |
| 486 | \\ var ptr: [*c]i32 = null; | 544 | \\ var ptr: [*c]i32 = null; |
| 487 | \\ var b = ptr.?; | 545 | \\ var b = ptr.?; |
| 546 | \\ _ = b; | ||
| 488 | \\} | 547 | \\} |
| 489 | ); | 548 | ); |
| 490 | 549 | ||
| 491 | cases.addRuntimeSafety("@intToPtr address zero to non-optional pointer", | 550 | cases.addRuntimeSafety("@intToPtr address zero to non-optional pointer", |
| 492 | \\const std = @import("std"); | 551 | \\const std = @import("std"); |
| 493 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 552 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 553 | \\ _ = message; | ||
| 554 | \\ _ = stack_trace; | ||
| 494 | \\ std.os.exit(126); | 555 | \\ std.os.exit(126); |
| 495 | \\} | 556 | \\} |
| 496 | \\pub fn main() void { | 557 | \\pub fn main() void { |
| 497 | \\ var zero: usize = 0; | 558 | \\ var zero: usize = 0; |
| 498 | \\ var b = @intToPtr(*i32, zero); | 559 | \\ var b = @intToPtr(*i32, zero); |
| 560 | \\ _ = b; | ||
| 499 | \\} | 561 | \\} |
| 500 | ); | 562 | ); |
| 501 | 563 | ||
| 502 | cases.addRuntimeSafety("@intToPtr address zero to non-optional byte-aligned pointer", | 564 | cases.addRuntimeSafety("@intToPtr address zero to non-optional byte-aligned pointer", |
| 503 | \\const std = @import("std"); | 565 | \\const std = @import("std"); |
| 504 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 566 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 567 | \\ _ = message; | ||
| 568 | \\ _ = stack_trace; | ||
| 505 | \\ std.os.exit(126); | 569 | \\ std.os.exit(126); |
| 506 | \\} | 570 | \\} |
| 507 | \\pub fn main() void { | 571 | \\pub fn main() void { |
| 508 | \\ var zero: usize = 0; | 572 | \\ var zero: usize = 0; |
| 509 | \\ var b = @intToPtr(*u8, zero); | 573 | \\ var b = @intToPtr(*u8, zero); |
| 574 | \\ _ = b; | ||
| 510 | \\} | 575 | \\} |
| 511 | ); | 576 | ); |
| 512 | 577 | ||
| 513 | cases.addRuntimeSafety("pointer casting null to non-optional pointer", | 578 | cases.addRuntimeSafety("pointer casting null to non-optional pointer", |
| 514 | \\const std = @import("std"); | 579 | \\const std = @import("std"); |
| 515 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 580 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 581 | \\ _ = message; | ||
| 582 | \\ _ = stack_trace; | ||
| 516 | \\ std.os.exit(126); | 583 | \\ std.os.exit(126); |
| 517 | \\} | 584 | \\} |
| 518 | \\pub fn main() void { | 585 | \\pub fn main() void { |
| 519 | \\ var c_ptr: [*c]u8 = 0; | 586 | \\ var c_ptr: [*c]u8 = 0; |
| 520 | \\ var zig_ptr: *u8 = c_ptr; | 587 | \\ var zig_ptr: *u8 = c_ptr; |
| 588 | \\ _ = zig_ptr; | ||
| 521 | \\} | 589 | \\} |
| 522 | ); | 590 | ); |
| 523 | 591 | ||
| 524 | cases.addRuntimeSafety("@intToEnum - no matching tag value", | 592 | cases.addRuntimeSafety("@intToEnum - no matching tag value", |
| 525 | \\const std = @import("std"); | 593 | \\const std = @import("std"); |
| 526 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 594 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 595 | \\ _ = message; | ||
| 596 | \\ _ = stack_trace; | ||
| 527 | \\ std.os.exit(126); | 597 | \\ std.os.exit(126); |
| 528 | \\} | 598 | \\} |
| 529 | \\const Foo = enum { | 599 | \\const Foo = enum { |
| ... | @@ -537,12 +607,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -537,12 +607,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 537 | \\fn bar(a: u2) Foo { | 607 | \\fn bar(a: u2) Foo { |
| 538 | \\ return @intToEnum(Foo, a); | 608 | \\ return @intToEnum(Foo, a); |
| 539 | \\} | 609 | \\} |
| 540 | \\fn baz(a: Foo) void {} | 610 | \\fn baz(_: Foo) void {} |
| 541 | ); | 611 | ); |
| 542 | 612 | ||
| 543 | cases.addRuntimeSafety("@floatToInt cannot fit - negative to unsigned", | 613 | cases.addRuntimeSafety("@floatToInt cannot fit - negative to unsigned", |
| 544 | \\const std = @import("std"); | 614 | \\const std = @import("std"); |
| 545 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 615 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 616 | \\ _ = message; | ||
| 617 | \\ _ = stack_trace; | ||
| 546 | \\ std.os.exit(126); | 618 | \\ std.os.exit(126); |
| 547 | \\} | 619 | \\} |
| 548 | \\pub fn main() void { | 620 | \\pub fn main() void { |
| ... | @@ -551,12 +623,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -551,12 +623,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 551 | \\fn bar(a: f32) u8 { | 623 | \\fn bar(a: f32) u8 { |
| 552 | \\ return @floatToInt(u8, a); | 624 | \\ return @floatToInt(u8, a); |
| 553 | \\} | 625 | \\} |
| 554 | \\fn baz(a: u8) void { } | 626 | \\fn baz(_: u8) void { } |
| 555 | ); | 627 | ); |
| 556 | 628 | ||
| 557 | cases.addRuntimeSafety("@floatToInt cannot fit - negative out of range", | 629 | cases.addRuntimeSafety("@floatToInt cannot fit - negative out of range", |
| 558 | \\const std = @import("std"); | 630 | \\const std = @import("std"); |
| 559 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 631 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 632 | \\ _ = message; | ||
| 633 | \\ _ = stack_trace; | ||
| 560 | \\ std.os.exit(126); | 634 | \\ std.os.exit(126); |
| 561 | \\} | 635 | \\} |
| 562 | \\pub fn main() void { | 636 | \\pub fn main() void { |
| ... | @@ -565,12 +639,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -565,12 +639,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 565 | \\fn bar(a: f32) i8 { | 639 | \\fn bar(a: f32) i8 { |
| 566 | \\ return @floatToInt(i8, a); | 640 | \\ return @floatToInt(i8, a); |
| 567 | \\} | 641 | \\} |
| 568 | \\fn baz(a: i8) void { } | 642 | \\fn baz(_: i8) void { } |
| 569 | ); | 643 | ); |
| 570 | 644 | ||
| 571 | cases.addRuntimeSafety("@floatToInt cannot fit - positive out of range", | 645 | cases.addRuntimeSafety("@floatToInt cannot fit - positive out of range", |
| 572 | \\const std = @import("std"); | 646 | \\const std = @import("std"); |
| 573 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 647 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 648 | \\ _ = message; | ||
| 649 | \\ _ = stack_trace; | ||
| 574 | \\ std.os.exit(126); | 650 | \\ std.os.exit(126); |
| 575 | \\} | 651 | \\} |
| 576 | \\pub fn main() void { | 652 | \\pub fn main() void { |
| ... | @@ -579,12 +655,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -579,12 +655,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 579 | \\fn bar(a: f32) u8 { | 655 | \\fn bar(a: f32) u8 { |
| 580 | \\ return @floatToInt(u8, a); | 656 | \\ return @floatToInt(u8, a); |
| 581 | \\} | 657 | \\} |
| 582 | \\fn baz(a: u8) void { } | 658 | \\fn baz(_: u8) void { } |
| 583 | ); | 659 | ); |
| 584 | 660 | ||
| 585 | cases.addRuntimeSafety("calling panic", | 661 | cases.addRuntimeSafety("calling panic", |
| 586 | \\const std = @import("std"); | 662 | \\const std = @import("std"); |
| 587 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 663 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 664 | \\ _ = message; | ||
| 665 | \\ _ = stack_trace; | ||
| 588 | \\ std.os.exit(126); | 666 | \\ std.os.exit(126); |
| 589 | \\} | 667 | \\} |
| 590 | \\pub fn main() void { | 668 | \\pub fn main() void { |
| ... | @@ -595,6 +673,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -595,6 +673,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 595 | cases.addRuntimeSafety("out of bounds slice access", | 673 | cases.addRuntimeSafety("out of bounds slice access", |
| 596 | \\const std = @import("std"); | 674 | \\const std = @import("std"); |
| 597 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 675 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 676 | \\ _ = message; | ||
| 677 | \\ _ = stack_trace; | ||
| 598 | \\ std.os.exit(126); | 678 | \\ std.os.exit(126); |
| 599 | \\} | 679 | \\} |
| 600 | \\pub fn main() void { | 680 | \\pub fn main() void { |
| ... | @@ -604,12 +684,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -604,12 +684,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 604 | \\fn bar(a: []const i32) i32 { | 684 | \\fn bar(a: []const i32) i32 { |
| 605 | \\ return a[4]; | 685 | \\ return a[4]; |
| 606 | \\} | 686 | \\} |
| 607 | \\fn baz(a: i32) void { } | 687 | \\fn baz(_: i32) void { } |
| 608 | ); | 688 | ); |
| 609 | 689 | ||
| 610 | cases.addRuntimeSafety("integer addition overflow", | 690 | cases.addRuntimeSafety("integer addition overflow", |
| 611 | \\const std = @import("std"); | 691 | \\const std = @import("std"); |
| 612 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 692 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 693 | \\ _ = message; | ||
| 694 | \\ _ = stack_trace; | ||
| 613 | \\ std.os.exit(126); | 695 | \\ std.os.exit(126); |
| 614 | \\} | 696 | \\} |
| 615 | \\pub fn main() !void { | 697 | \\pub fn main() !void { |
| ... | @@ -624,12 +706,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -624,12 +706,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 624 | cases.addRuntimeSafety("vector integer addition overflow", | 706 | cases.addRuntimeSafety("vector integer addition overflow", |
| 625 | \\const std = @import("std"); | 707 | \\const std = @import("std"); |
| 626 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 708 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 709 | \\ _ = message; | ||
| 710 | \\ _ = stack_trace; | ||
| 627 | \\ std.os.exit(126); | 711 | \\ std.os.exit(126); |
| 628 | \\} | 712 | \\} |
| 629 | \\pub fn main() void { | 713 | \\pub fn main() void { |
| 630 | \\ var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 }; | 714 | \\ var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 }; |
| 631 | \\ var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; | 715 | \\ var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; |
| 632 | \\ const x = add(a, b); | 716 | \\ const x = add(a, b); |
| 717 | \\ _ = x; | ||
| 633 | \\} | 718 | \\} |
| 634 | \\fn add(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) { | 719 | \\fn add(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) { |
| 635 | \\ return a + b; | 720 | \\ return a + b; |
| ... | @@ -639,12 +724,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -639,12 +724,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 639 | cases.addRuntimeSafety("vector integer subtraction overflow", | 724 | cases.addRuntimeSafety("vector integer subtraction overflow", |
| 640 | \\const std = @import("std"); | 725 | \\const std = @import("std"); |
| 641 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 726 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 727 | \\ _ = message; | ||
| 728 | \\ _ = stack_trace; | ||
| 642 | \\ std.os.exit(126); | 729 | \\ std.os.exit(126); |
| 643 | \\} | 730 | \\} |
| 644 | \\pub fn main() void { | 731 | \\pub fn main() void { |
| 645 | \\ var a: std.meta.Vector(4, u32) = [_]u32{ 1, 2, 8, 4 }; | 732 | \\ var a: std.meta.Vector(4, u32) = [_]u32{ 1, 2, 8, 4 }; |
| 646 | \\ var b: std.meta.Vector(4, u32) = [_]u32{ 5, 6, 7, 8 }; | 733 | \\ var b: std.meta.Vector(4, u32) = [_]u32{ 5, 6, 7, 8 }; |
| 647 | \\ const x = sub(b, a); | 734 | \\ const x = sub(b, a); |
| 735 | \\ _ = x; | ||
| 648 | \\} | 736 | \\} |
| 649 | \\fn sub(a: std.meta.Vector(4, u32), b: std.meta.Vector(4, u32)) std.meta.Vector(4, u32) { | 737 | \\fn sub(a: std.meta.Vector(4, u32), b: std.meta.Vector(4, u32)) std.meta.Vector(4, u32) { |
| 650 | \\ return a - b; | 738 | \\ return a - b; |
| ... | @@ -654,12 +742,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -654,12 +742,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 654 | cases.addRuntimeSafety("vector integer multiplication overflow", | 742 | cases.addRuntimeSafety("vector integer multiplication overflow", |
| 655 | \\const std = @import("std"); | 743 | \\const std = @import("std"); |
| 656 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 744 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 745 | \\ _ = message; | ||
| 746 | \\ _ = stack_trace; | ||
| 657 | \\ std.os.exit(126); | 747 | \\ std.os.exit(126); |
| 658 | \\} | 748 | \\} |
| 659 | \\pub fn main() void { | 749 | \\pub fn main() void { |
| 660 | \\ var a: std.meta.Vector(4, u8) = [_]u8{ 1, 2, 200, 4 }; | 750 | \\ var a: std.meta.Vector(4, u8) = [_]u8{ 1, 2, 200, 4 }; |
| 661 | \\ var b: std.meta.Vector(4, u8) = [_]u8{ 5, 6, 2, 8 }; | 751 | \\ var b: std.meta.Vector(4, u8) = [_]u8{ 5, 6, 2, 8 }; |
| 662 | \\ const x = mul(b, a); | 752 | \\ const x = mul(b, a); |
| 753 | \\ _ = x; | ||
| 663 | \\} | 754 | \\} |
| 664 | \\fn mul(a: std.meta.Vector(4, u8), b: std.meta.Vector(4, u8)) std.meta.Vector(4, u8) { | 755 | \\fn mul(a: std.meta.Vector(4, u8), b: std.meta.Vector(4, u8)) std.meta.Vector(4, u8) { |
| 665 | \\ return a * b; | 756 | \\ return a * b; |
| ... | @@ -669,11 +760,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -669,11 +760,14 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 669 | cases.addRuntimeSafety("vector integer negation overflow", | 760 | cases.addRuntimeSafety("vector integer negation overflow", |
| 670 | \\const std = @import("std"); | 761 | \\const std = @import("std"); |
| 671 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 762 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 763 | \\ _ = message; | ||
| 764 | \\ _ = stack_trace; | ||
| 672 | \\ std.os.exit(126); | 765 | \\ std.os.exit(126); |
| 673 | \\} | 766 | \\} |
| 674 | \\pub fn main() void { | 767 | \\pub fn main() void { |
| 675 | \\ var a: std.meta.Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 }; | 768 | \\ var a: std.meta.Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 }; |
| 676 | \\ const x = neg(a); | 769 | \\ const x = neg(a); |
| 770 | \\ _ = x; | ||
| 677 | \\} | 771 | \\} |
| 678 | \\fn neg(a: std.meta.Vector(4, i16)) std.meta.Vector(4, i16) { | 772 | \\fn neg(a: std.meta.Vector(4, i16)) std.meta.Vector(4, i16) { |
| 679 | \\ return -a; | 773 | \\ return -a; |
| ... | @@ -683,6 +777,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -683,6 +777,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 683 | cases.addRuntimeSafety("integer subtraction overflow", | 777 | cases.addRuntimeSafety("integer subtraction overflow", |
| 684 | \\const std = @import("std"); | 778 | \\const std = @import("std"); |
| 685 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 779 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 780 | \\ _ = message; | ||
| 781 | \\ _ = stack_trace; | ||
| 686 | \\ std.os.exit(126); | 782 | \\ std.os.exit(126); |
| 687 | \\} | 783 | \\} |
| 688 | \\pub fn main() !void { | 784 | \\pub fn main() !void { |
| ... | @@ -697,6 +793,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -697,6 +793,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 697 | cases.addRuntimeSafety("integer multiplication overflow", | 793 | cases.addRuntimeSafety("integer multiplication overflow", |
| 698 | \\const std = @import("std"); | 794 | \\const std = @import("std"); |
| 699 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 795 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 796 | \\ _ = message; | ||
| 797 | \\ _ = stack_trace; | ||
| 700 | \\ std.os.exit(126); | 798 | \\ std.os.exit(126); |
| 701 | \\} | 799 | \\} |
| 702 | \\pub fn main() !void { | 800 | \\pub fn main() !void { |
| ... | @@ -711,6 +809,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -711,6 +809,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 711 | cases.addRuntimeSafety("integer negation overflow", | 809 | cases.addRuntimeSafety("integer negation overflow", |
| 712 | \\const std = @import("std"); | 810 | \\const std = @import("std"); |
| 713 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 811 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 812 | \\ _ = message; | ||
| 813 | \\ _ = stack_trace; | ||
| 714 | \\ std.os.exit(126); | 814 | \\ std.os.exit(126); |
| 715 | \\} | 815 | \\} |
| 716 | \\pub fn main() !void { | 816 | \\pub fn main() !void { |
| ... | @@ -725,6 +825,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -725,6 +825,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 725 | cases.addRuntimeSafety("signed integer division overflow", | 825 | cases.addRuntimeSafety("signed integer division overflow", |
| 726 | \\const std = @import("std"); | 826 | \\const std = @import("std"); |
| 727 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 827 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 828 | \\ _ = message; | ||
| 829 | \\ _ = stack_trace; | ||
| 728 | \\ std.os.exit(126); | 830 | \\ std.os.exit(126); |
| 729 | \\} | 831 | \\} |
| 730 | \\pub fn main() !void { | 832 | \\pub fn main() !void { |
| ... | @@ -739,6 +841,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -739,6 +841,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 739 | cases.addRuntimeSafety("signed integer division overflow - vectors", | 841 | cases.addRuntimeSafety("signed integer division overflow - vectors", |
| 740 | \\const std = @import("std"); | 842 | \\const std = @import("std"); |
| 741 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 843 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 844 | \\ _ = message; | ||
| 845 | \\ _ = stack_trace; | ||
| 742 | \\ std.os.exit(126); | 846 | \\ std.os.exit(126); |
| 743 | \\} | 847 | \\} |
| 744 | \\pub fn main() !void { | 848 | \\pub fn main() !void { |
| ... | @@ -755,6 +859,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -755,6 +859,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 755 | cases.addRuntimeSafety("signed shift left overflow", | 859 | cases.addRuntimeSafety("signed shift left overflow", |
| 756 | \\const std = @import("std"); | 860 | \\const std = @import("std"); |
| 757 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 861 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 862 | \\ _ = message; | ||
| 863 | \\ _ = stack_trace; | ||
| 758 | \\ std.os.exit(126); | 864 | \\ std.os.exit(126); |
| 759 | \\} | 865 | \\} |
| 760 | \\pub fn main() !void { | 866 | \\pub fn main() !void { |
| ... | @@ -769,6 +875,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -769,6 +875,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 769 | cases.addRuntimeSafety("unsigned shift left overflow", | 875 | cases.addRuntimeSafety("unsigned shift left overflow", |
| 770 | \\const std = @import("std"); | 876 | \\const std = @import("std"); |
| 771 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 877 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 878 | \\ _ = message; | ||
| 879 | \\ _ = stack_trace; | ||
| 772 | \\ std.os.exit(126); | 880 | \\ std.os.exit(126); |
| 773 | \\} | 881 | \\} |
| 774 | \\pub fn main() !void { | 882 | \\pub fn main() !void { |
| ... | @@ -783,6 +891,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -783,6 +891,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 783 | cases.addRuntimeSafety("signed shift right overflow", | 891 | cases.addRuntimeSafety("signed shift right overflow", |
| 784 | \\const std = @import("std"); | 892 | \\const std = @import("std"); |
| 785 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 893 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 894 | \\ _ = message; | ||
| 895 | \\ _ = stack_trace; | ||
| 786 | \\ std.os.exit(126); | 896 | \\ std.os.exit(126); |
| 787 | \\} | 897 | \\} |
| 788 | \\pub fn main() !void { | 898 | \\pub fn main() !void { |
| ... | @@ -797,6 +907,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -797,6 +907,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 797 | cases.addRuntimeSafety("unsigned shift right overflow", | 907 | cases.addRuntimeSafety("unsigned shift right overflow", |
| 798 | \\const std = @import("std"); | 908 | \\const std = @import("std"); |
| 799 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 909 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 910 | \\ _ = message; | ||
| 911 | \\ _ = stack_trace; | ||
| 800 | \\ std.os.exit(126); | 912 | \\ std.os.exit(126); |
| 801 | \\} | 913 | \\} |
| 802 | \\pub fn main() !void { | 914 | \\pub fn main() !void { |
| ... | @@ -811,10 +923,13 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -811,10 +923,13 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 811 | cases.addRuntimeSafety("integer division by zero", | 923 | cases.addRuntimeSafety("integer division by zero", |
| 812 | \\const std = @import("std"); | 924 | \\const std = @import("std"); |
| 813 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 925 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 926 | \\ _ = message; | ||
| 927 | \\ _ = stack_trace; | ||
| 814 | \\ std.os.exit(126); | 928 | \\ std.os.exit(126); |
| 815 | \\} | 929 | \\} |
| 816 | \\pub fn main() void { | 930 | \\pub fn main() void { |
| 817 | \\ const x = div0(999, 0); | 931 | \\ const x = div0(999, 0); |
| 932 | \\ _ = x; | ||
| 818 | \\} | 933 | \\} |
| 819 | \\fn div0(a: i32, b: i32) i32 { | 934 | \\fn div0(a: i32, b: i32) i32 { |
| 820 | \\ return @divTrunc(a, b); | 935 | \\ return @divTrunc(a, b); |
| ... | @@ -824,12 +939,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -824,12 +939,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 824 | cases.addRuntimeSafety("integer division by zero - vectors", | 939 | cases.addRuntimeSafety("integer division by zero - vectors", |
| 825 | \\const std = @import("std"); | 940 | \\const std = @import("std"); |
| 826 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 941 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 942 | \\ _ = message; | ||
| 943 | \\ _ = stack_trace; | ||
| 827 | \\ std.os.exit(126); | 944 | \\ std.os.exit(126); |
| 828 | \\} | 945 | \\} |
| 829 | \\pub fn main() void { | 946 | \\pub fn main() void { |
| 830 | \\ var a: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 444}; | 947 | \\ var a: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 444}; |
| 831 | \\ var b: std.meta.Vector(4, i32) = [4]i32{111, 0, 333, 444}; | 948 | \\ var b: std.meta.Vector(4, i32) = [4]i32{111, 0, 333, 444}; |
| 832 | \\ const x = div0(a, b); | 949 | \\ const x = div0(a, b); |
| 950 | \\ _ = x; | ||
| 833 | \\} | 951 | \\} |
| 834 | \\fn div0(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) { | 952 | \\fn div0(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) { |
| 835 | \\ return @divTrunc(a, b); | 953 | \\ return @divTrunc(a, b); |
| ... | @@ -839,6 +957,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -839,6 +957,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 839 | cases.addRuntimeSafety("exact division failure", | 957 | cases.addRuntimeSafety("exact division failure", |
| 840 | \\const std = @import("std"); | 958 | \\const std = @import("std"); |
| 841 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 959 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 960 | \\ _ = message; | ||
| 961 | \\ _ = stack_trace; | ||
| 842 | \\ std.os.exit(126); | 962 | \\ std.os.exit(126); |
| 843 | \\} | 963 | \\} |
| 844 | \\pub fn main() !void { | 964 | \\pub fn main() !void { |
| ... | @@ -853,12 +973,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -853,12 +973,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 853 | cases.addRuntimeSafety("exact division failure - vectors", | 973 | cases.addRuntimeSafety("exact division failure - vectors", |
| 854 | \\const std = @import("std"); | 974 | \\const std = @import("std"); |
| 855 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 975 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 976 | \\ _ = message; | ||
| 977 | \\ _ = stack_trace; | ||
| 856 | \\ std.os.exit(126); | 978 | \\ std.os.exit(126); |
| 857 | \\} | 979 | \\} |
| 858 | \\pub fn main() !void { | 980 | \\pub fn main() !void { |
| 859 | \\ var a: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 444}; | 981 | \\ var a: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 444}; |
| 860 | \\ var b: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 441}; | 982 | \\ var b: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 441}; |
| 861 | \\ const x = divExact(a, b); | 983 | \\ const x = divExact(a, b); |
| 984 | \\ _ = x; | ||
| 862 | \\} | 985 | \\} |
| 863 | \\fn divExact(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) { | 986 | \\fn divExact(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) { |
| 864 | \\ return @divExact(a, b); | 987 | \\ return @divExact(a, b); |
| ... | @@ -868,6 +991,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -868,6 +991,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 868 | cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size", | 991 | cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size", |
| 869 | \\const std = @import("std"); | 992 | \\const std = @import("std"); |
| 870 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 993 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 994 | \\ _ = message; | ||
| 995 | \\ _ = stack_trace; | ||
| 871 | \\ std.os.exit(126); | 996 | \\ std.os.exit(126); |
| 872 | \\} | 997 | \\} |
| 873 | \\pub fn main() !void { | 998 | \\pub fn main() !void { |
| ... | @@ -882,6 +1007,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -882,6 +1007,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 882 | cases.addRuntimeSafety("value does not fit in shortening cast", | 1007 | cases.addRuntimeSafety("value does not fit in shortening cast", |
| 883 | \\const std = @import("std"); | 1008 | \\const std = @import("std"); |
| 884 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1009 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1010 | \\ _ = message; | ||
| 1011 | \\ _ = stack_trace; | ||
| 885 | \\ std.os.exit(126); | 1012 | \\ std.os.exit(126); |
| 886 | \\} | 1013 | \\} |
| 887 | \\pub fn main() !void { | 1014 | \\pub fn main() !void { |
| ... | @@ -896,6 +1023,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -896,6 +1023,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 896 | cases.addRuntimeSafety("value does not fit in shortening cast - u0", | 1023 | cases.addRuntimeSafety("value does not fit in shortening cast - u0", |
| 897 | \\const std = @import("std"); | 1024 | \\const std = @import("std"); |
| 898 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1025 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1026 | \\ _ = message; | ||
| 1027 | \\ _ = stack_trace; | ||
| 899 | \\ std.os.exit(126); | 1028 | \\ std.os.exit(126); |
| 900 | \\} | 1029 | \\} |
| 901 | \\pub fn main() !void { | 1030 | \\pub fn main() !void { |
| ... | @@ -910,6 +1039,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -910,6 +1039,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 910 | cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer", | 1039 | cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer", |
| 911 | \\const std = @import("std"); | 1040 | \\const std = @import("std"); |
| 912 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1041 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1042 | \\ _ = message; | ||
| 1043 | \\ _ = stack_trace; | ||
| 913 | \\ std.os.exit(126); | 1044 | \\ std.os.exit(126); |
| 914 | \\} | 1045 | \\} |
| 915 | \\pub fn main() !void { | 1046 | \\pub fn main() !void { |
| ... | @@ -924,28 +1055,35 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -924,28 +1055,35 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 924 | cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer - widening", | 1055 | cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer - widening", |
| 925 | \\const std = @import("std"); | 1056 | \\const std = @import("std"); |
| 926 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1057 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1058 | \\ _ = message; | ||
| 1059 | \\ _ = stack_trace; | ||
| 927 | \\ std.os.exit(126); | 1060 | \\ std.os.exit(126); |
| 928 | \\} | 1061 | \\} |
| 929 | \\pub fn main() void { | 1062 | \\pub fn main() void { |
| 930 | \\ var value: c_short = -1; | 1063 | \\ var value: c_short = -1; |
| 931 | \\ var casted = @intCast(u32, value); | 1064 | \\ var casted = @intCast(u32, value); |
| 1065 | \\ _ = casted; | ||
| 932 | \\} | 1066 | \\} |
| 933 | ); | 1067 | ); |
| 934 | 1068 | ||
| 935 | cases.addRuntimeSafety("unsigned integer not fitting in cast to signed integer - same bit count", | 1069 | cases.addRuntimeSafety("unsigned integer not fitting in cast to signed integer - same bit count", |
| 936 | \\const std = @import("std"); | 1070 | \\const std = @import("std"); |
| 937 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1071 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1072 | \\ _ = message; | ||
| 1073 | \\ _ = stack_trace; | ||
| 938 | \\ std.os.exit(126); | 1074 | \\ std.os.exit(126); |
| 939 | \\} | 1075 | \\} |
| 940 | \\pub fn main() void { | 1076 | \\pub fn main() void { |
| 941 | \\ var value: u8 = 245; | 1077 | \\ var value: u8 = 245; |
| 942 | \\ var casted = @intCast(i8, value); | 1078 | \\ var casted = @intCast(i8, value); |
| 1079 | \\ _ = casted; | ||
| 943 | \\} | 1080 | \\} |
| 944 | ); | 1081 | ); |
| 945 | 1082 | ||
| 946 | cases.addRuntimeSafety("unwrap error", | 1083 | cases.addRuntimeSafety("unwrap error", |
| 947 | \\const std = @import("std"); | 1084 | \\const std = @import("std"); |
| 948 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1085 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1086 | \\ _ = stack_trace; | ||
| 949 | \\ if (std.mem.eql(u8, message, "attempt to unwrap error: Whatever")) { | 1087 | \\ if (std.mem.eql(u8, message, "attempt to unwrap error: Whatever")) { |
| 950 | \\ std.os.exit(126); // good | 1088 | \\ std.os.exit(126); // good |
| 951 | \\ } | 1089 | \\ } |
| ... | @@ -962,6 +1100,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -962,6 +1100,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 962 | cases.addRuntimeSafety("cast integer to global error and no code matches", | 1100 | cases.addRuntimeSafety("cast integer to global error and no code matches", |
| 963 | \\const std = @import("std"); | 1101 | \\const std = @import("std"); |
| 964 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1102 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1103 | \\ _ = message; | ||
| 1104 | \\ _ = stack_trace; | ||
| 965 | \\ std.os.exit(126); | 1105 | \\ std.os.exit(126); |
| 966 | \\} | 1106 | \\} |
| 967 | \\pub fn main() void { | 1107 | \\pub fn main() void { |
| ... | @@ -975,6 +1115,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -975,6 +1115,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 975 | cases.addRuntimeSafety("@errSetCast error not present in destination", | 1115 | cases.addRuntimeSafety("@errSetCast error not present in destination", |
| 976 | \\const std = @import("std"); | 1116 | \\const std = @import("std"); |
| 977 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1117 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1118 | \\ _ = message; | ||
| 1119 | \\ _ = stack_trace; | ||
| 978 | \\ std.os.exit(126); | 1120 | \\ std.os.exit(126); |
| 979 | \\} | 1121 | \\} |
| 980 | \\const Set1 = error{A, B}; | 1122 | \\const Set1 = error{A, B}; |
| ... | @@ -990,6 +1132,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -990,6 +1132,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 990 | cases.addRuntimeSafety("@alignCast misaligned", | 1132 | cases.addRuntimeSafety("@alignCast misaligned", |
| 991 | \\const std = @import("std"); | 1133 | \\const std = @import("std"); |
| 992 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1134 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1135 | \\ _ = message; | ||
| 1136 | \\ _ = stack_trace; | ||
| 993 | \\ std.os.exit(126); | 1137 | \\ std.os.exit(126); |
| 994 | \\} | 1138 | \\} |
| 995 | \\pub fn main() !void { | 1139 | \\pub fn main() !void { |
| ... | @@ -1007,6 +1151,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -1007,6 +1151,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 1007 | cases.addRuntimeSafety("bad union field access", | 1151 | cases.addRuntimeSafety("bad union field access", |
| 1008 | \\const std = @import("std"); | 1152 | \\const std = @import("std"); |
| 1009 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1153 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1154 | \\ _ = message; | ||
| 1155 | \\ _ = stack_trace; | ||
| 1010 | \\ std.os.exit(126); | 1156 | \\ std.os.exit(126); |
| 1011 | \\} | 1157 | \\} |
| 1012 | \\ | 1158 | \\ |
| ... | @@ -1031,6 +1177,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -1031,6 +1177,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 1031 | cases.addRuntimeSafety("@intCast to u0", | 1177 | cases.addRuntimeSafety("@intCast to u0", |
| 1032 | \\const std = @import("std"); | 1178 | \\const std = @import("std"); |
| 1033 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1179 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1180 | \\ _ = message; | ||
| 1181 | \\ _ = stack_trace; | ||
| 1034 | \\ std.os.exit(126); | 1182 | \\ std.os.exit(126); |
| 1035 | \\} | 1183 | \\} |
| 1036 | \\ | 1184 | \\ |
| ... | @@ -1040,6 +1188,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -1040,6 +1188,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 1040 | \\ | 1188 | \\ |
| 1041 | \\fn bar(one: u1, not_zero: i32) void { | 1189 | \\fn bar(one: u1, not_zero: i32) void { |
| 1042 | \\ var x = one << @intCast(u0, not_zero); | 1190 | \\ var x = one << @intCast(u0, not_zero); |
| 1191 | \\ _ = x; | ||
| 1043 | \\} | 1192 | \\} |
| 1044 | ); | 1193 | ); |
| 1045 | 1194 | ||
| ... | @@ -1049,6 +1198,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -1049,6 +1198,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 1049 | \\const std = @import("std"); | 1198 | \\const std = @import("std"); |
| 1050 | \\ | 1199 | \\ |
| 1051 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1200 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1201 | \\ _ = message; | ||
| 1202 | \\ _ = stack_trace; | ||
| 1052 | \\ std.os.exit(126); | 1203 | \\ std.os.exit(126); |
| 1053 | \\} | 1204 | \\} |
| 1054 | \\ | 1205 | \\ |
| ... | @@ -1058,6 +1209,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -1058,6 +1209,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 1058 | \\ const p = nonFailing(); | 1209 | \\ const p = nonFailing(); |
| 1059 | \\ resume p; | 1210 | \\ resume p; |
| 1060 | \\ const p2 = async printTrace(p); | 1211 | \\ const p2 = async printTrace(p); |
| 1212 | \\ _ = p2; | ||
| 1061 | \\} | 1213 | \\} |
| 1062 | \\ | 1214 | \\ |
| 1063 | \\fn nonFailing() anyframe->anyerror!void { | 1215 | \\fn nonFailing() anyframe->anyerror!void { |
| ... | @@ -1084,12 +1236,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -1084,12 +1236,15 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 1084 | cases.addRuntimeSafety("slicing null C pointer", | 1236 | cases.addRuntimeSafety("slicing null C pointer", |
| 1085 | \\const std = @import("std"); | 1237 | \\const std = @import("std"); |
| 1086 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { | 1238 | \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { |
| 1239 | \\ _ = message; | ||
| 1240 | \\ _ = stack_trace; | ||
| 1087 | \\ std.os.exit(126); | 1241 | \\ std.os.exit(126); |
| 1088 | \\} | 1242 | \\} |
| 1089 | \\ | 1243 | \\ |
| 1090 | \\pub fn main() void { | 1244 | \\pub fn main() void { |
| 1091 | \\ var ptr: [*c]const u32 = null; | 1245 | \\ var ptr: [*c]const u32 = null; |
| 1092 | \\ var slice = ptr[0..3]; | 1246 | \\ var slice = ptr[0..3]; |
| 1247 | \\ _ = slice; | ||
| 1093 | \\} | 1248 | \\} |
| 1094 | ); | 1249 | ); |
| 1095 | } | 1250 | } |
test/translate_c.zig+229| ... | @@ -12,9 +12,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -12,9 +12,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 12 | , &[_][]const u8{ | 12 | , &[_][]const u8{ |
| 13 | \\pub export fn foo(arg_x: c_ulong) c_ulong { | 13 | \\pub export fn foo(arg_x: c_ulong) c_ulong { |
| 14 | \\ var x = arg_x; | 14 | \\ var x = arg_x; |
| 15 | \\ _ = x; | ||
| 15 | \\ const union_unnamed_1 = extern union { | 16 | \\ const union_unnamed_1 = extern union { |
| 16 | \\ _x: c_ulong, | 17 | \\ _x: c_ulong, |
| 17 | \\ }; | 18 | \\ }; |
| 19 | \\ _ = union_unnamed_1; | ||
| 18 | \\ return (union_unnamed_1{ | 20 | \\ return (union_unnamed_1{ |
| 19 | \\ ._x = x, | 21 | \\ ._x = x, |
| 20 | \\ })._x; | 22 | \\ })._x; |
| ... | @@ -54,8 +56,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -54,8 +56,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 54 | \\pub export fn foo() void { | 56 | \\pub export fn foo() void { |
| 55 | \\ while (true) if (true) { | 57 | \\ while (true) if (true) { |
| 56 | \\ var a: c_int = 1; | 58 | \\ var a: c_int = 1; |
| 59 | \\ _ = a; | ||
| 57 | \\ } else { | 60 | \\ } else { |
| 58 | \\ var b: c_int = 2; | 61 | \\ var b: c_int = 2; |
| 62 | \\ _ = b; | ||
| 59 | \\ }; | 63 | \\ }; |
| 60 | \\ if (true) if (true) {}; | 64 | \\ if (true) if (true) {}; |
| 61 | \\} | 65 | \\} |
| ... | @@ -71,6 +75,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -71,6 +75,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 71 | \\pub extern fn bar(...) c_int; | 75 | \\pub extern fn bar(...) c_int; |
| 72 | \\pub export fn foo() void { | 76 | \\pub export fn foo() void { |
| 73 | \\ var a: c_int = undefined; | 77 | \\ var a: c_int = undefined; |
| 78 | \\ _ = a; | ||
| 74 | \\ if (a != 0) a = 2 else _ = bar(); | 79 | \\ if (a != 0) a = 2 else _ = bar(); |
| 75 | \\} | 80 | \\} |
| 76 | }); | 81 | }); |
| ... | @@ -123,22 +128,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -123,22 +128,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 123 | \\ B: c_int, | 128 | \\ B: c_int, |
| 124 | \\ C: c_int, | 129 | \\ C: c_int, |
| 125 | \\ }; | 130 | \\ }; |
| 131 | \\ _ = struct_Foo; | ||
| 126 | \\ var a: struct_Foo = struct_Foo{ | 132 | \\ var a: struct_Foo = struct_Foo{ |
| 127 | \\ .A = @as(c_int, 0), | 133 | \\ .A = @as(c_int, 0), |
| 128 | \\ .B = 0, | 134 | \\ .B = 0, |
| 129 | \\ .C = 0, | 135 | \\ .C = 0, |
| 130 | \\ }; | 136 | \\ }; |
| 137 | \\ _ = a; | ||
| 131 | \\ { | 138 | \\ { |
| 132 | \\ const struct_Foo_1 = extern struct { | 139 | \\ const struct_Foo_1 = extern struct { |
| 133 | \\ A: c_int, | 140 | \\ A: c_int, |
| 134 | \\ B: c_int, | 141 | \\ B: c_int, |
| 135 | \\ C: c_int, | 142 | \\ C: c_int, |
| 136 | \\ }; | 143 | \\ }; |
| 144 | \\ _ = struct_Foo_1; | ||
| 137 | \\ var a_2: struct_Foo_1 = struct_Foo_1{ | 145 | \\ var a_2: struct_Foo_1 = struct_Foo_1{ |
| 138 | \\ .A = @as(c_int, 0), | 146 | \\ .A = @as(c_int, 0), |
| 139 | \\ .B = 0, | 147 | \\ .B = 0, |
| 140 | \\ .C = 0, | 148 | \\ .C = 0, |
| 141 | \\ }; | 149 | \\ }; |
| 150 | \\ _ = a_2; | ||
| 142 | \\ } | 151 | \\ } |
| 143 | \\} | 152 | \\} |
| 144 | }); | 153 | }); |
| ... | @@ -167,20 +176,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -167,20 +176,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 167 | \\ B: c_int, | 176 | \\ B: c_int, |
| 168 | \\ C: c_int, | 177 | \\ C: c_int, |
| 169 | \\ }; | 178 | \\ }; |
| 179 | \\ _ = union_unnamed_1; | ||
| 170 | \\ const Foo = union_unnamed_1; | 180 | \\ const Foo = union_unnamed_1; |
| 181 | \\ _ = Foo; | ||
| 171 | \\ var a: Foo = Foo{ | 182 | \\ var a: Foo = Foo{ |
| 172 | \\ .A = @as(c_int, 0), | 183 | \\ .A = @as(c_int, 0), |
| 173 | \\ }; | 184 | \\ }; |
| 185 | \\ _ = a; | ||
| 174 | \\ { | 186 | \\ { |
| 175 | \\ const union_unnamed_2 = extern union { | 187 | \\ const union_unnamed_2 = extern union { |
| 176 | \\ A: c_int, | 188 | \\ A: c_int, |
| 177 | \\ B: c_int, | 189 | \\ B: c_int, |
| 178 | \\ C: c_int, | 190 | \\ C: c_int, |
| 179 | \\ }; | 191 | \\ }; |
| 192 | \\ _ = union_unnamed_2; | ||
| 180 | \\ const Foo_1 = union_unnamed_2; | 193 | \\ const Foo_1 = union_unnamed_2; |
| 194 | \\ _ = Foo_1; | ||
| 181 | \\ var a_2: Foo_1 = Foo_1{ | 195 | \\ var a_2: Foo_1 = Foo_1{ |
| 182 | \\ .A = @as(c_int, 0), | 196 | \\ .A = @as(c_int, 0), |
| 183 | \\ }; | 197 | \\ }; |
| 198 | \\ _ = a_2; | ||
| 184 | \\ } | 199 | \\ } |
| 185 | \\} | 200 | \\} |
| 186 | }); | 201 | }); |
| ... | @@ -190,6 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -190,6 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 190 | \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED) | 205 | \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED) |
| 191 | , &[_][]const u8{ | 206 | , &[_][]const u8{ |
| 192 | \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*c_void { | 207 | \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*c_void { |
| 208 | \\ _ = x; | ||
| 193 | \\ return @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED); | 209 | \\ return @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED); |
| 194 | \\} | 210 | \\} |
| 195 | }); | 211 | }); |
| ... | @@ -231,6 +247,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -231,6 +247,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 231 | \\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)) | @boolToInt(@as(c_int, 8) == @as(c_int, 9)); | 247 | \\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)) | @boolToInt(@as(c_int, 8) == @as(c_int, 9)); |
| 232 | , | 248 | , |
| 233 | \\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))) { | 249 | \\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))) { |
| 250 | \\ _ = p; | ||
| 234 | \\ 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)); | 251 | \\ 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)); |
| 235 | \\} | 252 | \\} |
| 236 | }); | 253 | }); |
| ... | @@ -246,6 +263,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -246,6 +263,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 246 | \\ const bar_1 = struct { | 263 | \\ const bar_1 = struct { |
| 247 | \\ threadlocal var static: c_int = 2; | 264 | \\ threadlocal var static: c_int = 2; |
| 248 | \\ }; | 265 | \\ }; |
| 266 | \\ _ = bar_1; | ||
| 249 | \\ return 0; | 267 | \\ return 0; |
| 250 | \\} | 268 | \\} |
| 251 | }); | 269 | }); |
| ... | @@ -264,6 +282,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -264,6 +282,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 264 | \\} | 282 | \\} |
| 265 | \\pub export fn bar() c_int { | 283 | \\pub export fn bar() c_int { |
| 266 | \\ var a: c_int = 2; | 284 | \\ var a: c_int = 2; |
| 285 | \\ _ = a; | ||
| 267 | \\ return 0; | 286 | \\ return 0; |
| 268 | \\} | 287 | \\} |
| 269 | \\pub export fn baz() c_int { | 288 | \\pub export fn baz() c_int { |
| ... | @@ -278,6 +297,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -278,6 +297,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 278 | , &[_][]const u8{ | 297 | , &[_][]const u8{ |
| 279 | \\pub export fn main() void { | 298 | \\pub export fn main() void { |
| 280 | \\ var a: c_int = @bitCast(c_int, @truncate(c_uint, @alignOf(c_int))); | 299 | \\ var a: c_int = @bitCast(c_int, @truncate(c_uint, @alignOf(c_int))); |
| 300 | \\ _ = a; | ||
| 281 | \\} | 301 | \\} |
| 282 | }); | 302 | }); |
| 283 | 303 | ||
| ... | @@ -308,6 +328,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -308,6 +328,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 308 | \\pub const Color = struct_Color; | 328 | \\pub const Color = struct_Color; |
| 309 | , | 329 | , |
| 310 | \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) { | 330 | \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) { |
| 331 | \\ _ = type_1; | ||
| 311 | \\ return type_1; | 332 | \\ return type_1; |
| 312 | \\} | 333 | \\} |
| 313 | , | 334 | , |
| ... | @@ -325,6 +346,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -325,6 +346,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 325 | \\}; | 346 | \\}; |
| 326 | , | 347 | , |
| 327 | \\pub inline fn A(_x: anytype) MyCStruct { | 348 | \\pub inline fn A(_x: anytype) MyCStruct { |
| 349 | \\ _ = _x; | ||
| 328 | \\ return @import("std").mem.zeroInit(MyCStruct, .{ | 350 | \\ return @import("std").mem.zeroInit(MyCStruct, .{ |
| 329 | \\ .x = _x, | 351 | \\ .x = _x, |
| 330 | \\ }); | 352 | \\ }); |
| ... | @@ -355,6 +377,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -355,6 +377,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 355 | \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) | 377 | \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) |
| 356 | , &[_][]const u8{ | 378 | , &[_][]const u8{ |
| 357 | \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) { | 379 | \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) { |
| 380 | \\ _ = _fp; | ||
| 358 | \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0); | 381 | \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0); |
| 359 | \\} | 382 | \\} |
| 360 | }); | 383 | }); |
| ... | @@ -364,6 +387,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -364,6 +387,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 364 | \\#define BAR 1 && 2 > 4 | 387 | \\#define BAR 1 && 2 > 4 |
| 365 | , &[_][]const u8{ | 388 | , &[_][]const u8{ |
| 366 | \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0))) { | 389 | \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0))) { |
| 390 | \\ _ = x; | ||
| 367 | \\ return @boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0)); | 391 | \\ return @boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0)); |
| 368 | \\} | 392 | \\} |
| 369 | , | 393 | , |
| ... | @@ -426,6 +450,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -426,6 +450,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 426 | \\}; | 450 | \\}; |
| 427 | , | 451 | , |
| 428 | \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { | 452 | \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { |
| 453 | \\ _ = x; | ||
| 429 | \\ return blk: { | 454 | \\ return blk: { |
| 430 | \\ _ = &x; | 455 | \\ _ = &x; |
| 431 | \\ _ = @as(c_int, 3); | 456 | \\ _ = @as(c_int, 3); |
| ... | @@ -555,6 +580,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -555,6 +580,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 555 | \\}; | 580 | \\}; |
| 556 | \\pub export fn foo(arg_x: [*c]outer) void { | 581 | \\pub export fn foo(arg_x: [*c]outer) void { |
| 557 | \\ var x = arg_x; | 582 | \\ var x = arg_x; |
| 583 | \\ _ = x; | ||
| 558 | \\ x.*.unnamed_0.unnamed_0.y = @bitCast(c_int, @as(c_uint, x.*.unnamed_0.x)); | 584 | \\ x.*.unnamed_0.unnamed_0.y = @bitCast(c_int, @as(c_uint, x.*.unnamed_0.x)); |
| 559 | \\} | 585 | \\} |
| 560 | }); | 586 | }); |
| ... | @@ -641,7 +667,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -641,7 +667,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 641 | \\pub const struct_opaque_2 = opaque {}; | 667 | \\pub const struct_opaque_2 = opaque {}; |
| 642 | \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { | 668 | \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { |
| 643 | \\ var opaque_1 = arg_opaque_1; | 669 | \\ var opaque_1 = arg_opaque_1; |
| 670 | \\ _ = opaque_1; | ||
| 644 | \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1); | 671 | \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1); |
| 672 | \\ _ = cast; | ||
| 645 | \\} | 673 | \\} |
| 646 | }); | 674 | }); |
| 647 | 675 | ||
| ... | @@ -673,6 +701,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -673,6 +701,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 673 | \\pub export fn my_fn() align(128) void {} | 701 | \\pub export fn my_fn() align(128) void {} |
| 674 | \\pub export fn other_fn() void { | 702 | \\pub export fn other_fn() void { |
| 675 | \\ var ARR: [16]u8 align(16) = undefined; | 703 | \\ var ARR: [16]u8 align(16) = undefined; |
| 704 | \\ _ = ARR; | ||
| 676 | \\} | 705 | \\} |
| 677 | }); | 706 | }); |
| 678 | 707 | ||
| ... | @@ -708,11 +737,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -708,11 +737,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 708 | , &[_][]const u8{ | 737 | , &[_][]const u8{ |
| 709 | \\pub export fn foo() void { | 738 | \\pub export fn foo() void { |
| 710 | \\ var a: c_int = undefined; | 739 | \\ var a: c_int = undefined; |
| 740 | \\ _ = a; | ||
| 711 | \\ var b: u8 = 123; | 741 | \\ var b: u8 = 123; |
| 742 | \\ _ = b; | ||
| 712 | \\ const c: c_int = undefined; | 743 | \\ const c: c_int = undefined; |
| 744 | \\ _ = c; | ||
| 713 | \\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440)); | 745 | \\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440)); |
| 746 | \\ _ = d; | ||
| 714 | \\ var e: c_int = 10; | 747 | \\ var e: c_int = 10; |
| 748 | \\ _ = e; | ||
| 715 | \\ var f: c_uint = 10; | 749 | \\ var f: c_uint = 10; |
| 750 | \\ _ = f; | ||
| 716 | \\} | 751 | \\} |
| 717 | }); | 752 | }); |
| 718 | 753 | ||
| ... | @@ -728,6 +763,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -728,6 +763,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 728 | , &[_][]const u8{ | 763 | , &[_][]const u8{ |
| 729 | \\pub export fn foo() void { | 764 | \\pub export fn foo() void { |
| 730 | \\ var a: c_int = undefined; | 765 | \\ var a: c_int = undefined; |
| 766 | \\ _ = a; | ||
| 731 | \\ _ = @as(c_int, 1); | 767 | \\ _ = @as(c_int, 1); |
| 732 | \\ _ = "hey"; | 768 | \\ _ = "hey"; |
| 733 | \\ _ = @as(c_int, 1) + @as(c_int, 1); | 769 | \\ _ = @as(c_int, 1) + @as(c_int, 1); |
| ... | @@ -771,6 +807,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -771,6 +807,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 771 | \\ const v2 = struct { | 807 | \\ const v2 = struct { |
| 772 | \\ const static: [5:0]u8 = "2.2.2".*; | 808 | \\ const static: [5:0]u8 = "2.2.2".*; |
| 773 | \\ }; | 809 | \\ }; |
| 810 | \\ _ = v2; | ||
| 774 | \\} | 811 | \\} |
| 775 | }); | 812 | }); |
| 776 | 813 | ||
| ... | @@ -812,7 +849,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -812,7 +849,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 812 | \\pub extern fn foo() void; | 849 | \\pub extern fn foo() void; |
| 813 | \\pub export fn bar() void { | 850 | \\pub export fn bar() void { |
| 814 | \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo); | 851 | \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo); |
| 852 | \\ _ = func_ptr; | ||
| 815 | \\ var typed_func_ptr: ?fn () callconv(.C) void = @intToPtr(?fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr))); | 853 | \\ var typed_func_ptr: ?fn () callconv(.C) void = @intToPtr(?fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr))); |
| 854 | \\ _ = typed_func_ptr; | ||
| 816 | \\} | 855 | \\} |
| 817 | }); | 856 | }); |
| 818 | 857 | ||
| ... | @@ -842,8 +881,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -842,8 +881,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 842 | , &[_][]const u8{ | 881 | , &[_][]const u8{ |
| 843 | \\pub export fn s() c_int { | 882 | \\pub export fn s() c_int { |
| 844 | \\ var a: c_int = undefined; | 883 | \\ var a: c_int = undefined; |
| 884 | \\ _ = a; | ||
| 845 | \\ var b: c_int = undefined; | 885 | \\ var b: c_int = undefined; |
| 886 | \\ _ = b; | ||
| 846 | \\ var c: c_int = undefined; | 887 | \\ var c: c_int = undefined; |
| 888 | \\ _ = c; | ||
| 847 | \\ c = a + b; | 889 | \\ c = a + b; |
| 848 | \\ c = a - b; | 890 | \\ c = a - b; |
| 849 | \\ c = a * b; | 891 | \\ c = a * b; |
| ... | @@ -853,8 +895,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -853,8 +895,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 853 | \\} | 895 | \\} |
| 854 | \\pub export fn u() c_uint { | 896 | \\pub export fn u() c_uint { |
| 855 | \\ var a: c_uint = undefined; | 897 | \\ var a: c_uint = undefined; |
| 898 | \\ _ = a; | ||
| 856 | \\ var b: c_uint = undefined; | 899 | \\ var b: c_uint = undefined; |
| 900 | \\ _ = b; | ||
| 857 | \\ var c: c_uint = undefined; | 901 | \\ var c: c_uint = undefined; |
| 902 | \\ _ = c; | ||
| 858 | \\ c = a +% b; | 903 | \\ c = a +% b; |
| 859 | \\ c = a -% b; | 904 | \\ c = a -% b; |
| 860 | \\ c = a *% b; | 905 | \\ c = a *% b; |
| ... | @@ -1218,6 +1263,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1218,6 +1263,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1218 | \\pub export fn foo() void { | 1263 | \\pub export fn foo() void { |
| 1219 | \\ var a: c_int = undefined; | 1264 | \\ var a: c_int = undefined; |
| 1220 | \\ _ = a; | 1265 | \\ _ = a; |
| 1266 | \\ _ = a; | ||
| 1221 | \\} | 1267 | \\} |
| 1222 | }); | 1268 | }); |
| 1223 | 1269 | ||
| ... | @@ -1229,6 +1275,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1229,6 +1275,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1229 | , &[_][]const u8{ | 1275 | , &[_][]const u8{ |
| 1230 | \\pub export fn foo() ?*c_void { | 1276 | \\pub export fn foo() ?*c_void { |
| 1231 | \\ var x: [*c]c_ushort = undefined; | 1277 | \\ var x: [*c]c_ushort = undefined; |
| 1278 | \\ _ = x; | ||
| 1232 | \\ return @ptrCast(?*c_void, x); | 1279 | \\ return @ptrCast(?*c_void, x); |
| 1233 | \\} | 1280 | \\} |
| 1234 | }); | 1281 | }); |
| ... | @@ -1285,6 +1332,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1285,6 +1332,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1285 | \\pub export fn foo() void { | 1332 | \\pub export fn foo() void { |
| 1286 | \\ { | 1333 | \\ { |
| 1287 | \\ var i: c_int = 0; | 1334 | \\ var i: c_int = 0; |
| 1335 | \\ _ = i; | ||
| 1288 | \\ while (i != 0) : (i += 1) {} | 1336 | \\ while (i != 0) : (i += 1) {} |
| 1289 | \\ } | 1337 | \\ } |
| 1290 | \\} | 1338 | \\} |
| ... | @@ -1308,6 +1356,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1308,6 +1356,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1308 | , &[_][]const u8{ | 1356 | , &[_][]const u8{ |
| 1309 | \\pub export fn foo() void { | 1357 | \\pub export fn foo() void { |
| 1310 | \\ var i: c_int = undefined; | 1358 | \\ var i: c_int = undefined; |
| 1359 | \\ _ = i; | ||
| 1311 | \\ { | 1360 | \\ { |
| 1312 | \\ i = 3; | 1361 | \\ i = 3; |
| 1313 | \\ while (i != 0) : (i -= 1) {} | 1362 | \\ while (i != 0) : (i -= 1) {} |
| ... | @@ -1351,6 +1400,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1351,6 +1400,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1351 | , &[_][]const u8{ | 1400 | , &[_][]const u8{ |
| 1352 | \\pub export fn ptrcast() [*c]f32 { | 1401 | \\pub export fn ptrcast() [*c]f32 { |
| 1353 | \\ var a: [*c]c_int = undefined; | 1402 | \\ var a: [*c]c_int = undefined; |
| 1403 | \\ _ = a; | ||
| 1354 | \\ return @ptrCast([*c]f32, @alignCast(@import("std").meta.alignment(f32), a)); | 1404 | \\ return @ptrCast([*c]f32, @alignCast(@import("std").meta.alignment(f32), a)); |
| 1355 | \\} | 1405 | \\} |
| 1356 | }); | 1406 | }); |
| ... | @@ -1374,17 +1424,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1374,17 +1424,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1374 | , &[_][]const u8{ | 1424 | , &[_][]const u8{ |
| 1375 | \\pub export fn test_ptr_cast() void { | 1425 | \\pub export fn test_ptr_cast() void { |
| 1376 | \\ var p: ?*c_void = undefined; | 1426 | \\ var p: ?*c_void = undefined; |
| 1427 | \\ _ = p; | ||
| 1377 | \\ { | 1428 | \\ { |
| 1378 | \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment(u8), p)); | 1429 | \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment(u8), p)); |
| 1430 | \\ _ = to_char; | ||
| 1379 | \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment(c_short), p)); | 1431 | \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment(c_short), p)); |
| 1432 | \\ _ = to_short; | ||
| 1380 | \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment(c_int), p)); | 1433 | \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment(c_int), p)); |
| 1434 | \\ _ = to_int; | ||
| 1381 | \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment(c_longlong), p)); | 1435 | \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment(c_longlong), p)); |
| 1436 | \\ _ = to_longlong; | ||
| 1382 | \\ } | 1437 | \\ } |
| 1383 | \\ { | 1438 | \\ { |
| 1384 | \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment(u8), p)); | 1439 | \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment(u8), p)); |
| 1440 | \\ _ = to_char; | ||
| 1385 | \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment(c_short), p)); | 1441 | \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment(c_short), p)); |
| 1442 | \\ _ = to_short; | ||
| 1386 | \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment(c_int), p)); | 1443 | \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment(c_int), p)); |
| 1444 | \\ _ = to_int; | ||
| 1387 | \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment(c_longlong), p)); | 1445 | \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment(c_longlong), p)); |
| 1446 | \\ _ = to_longlong; | ||
| 1388 | \\ } | 1447 | \\ } |
| 1389 | \\} | 1448 | \\} |
| 1390 | }); | 1449 | }); |
| ... | @@ -1402,8 +1461,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1402,8 +1461,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1402 | , &[_][]const u8{ | 1461 | , &[_][]const u8{ |
| 1403 | \\pub export fn while_none_bool() c_int { | 1462 | \\pub export fn while_none_bool() c_int { |
| 1404 | \\ var a: c_int = undefined; | 1463 | \\ var a: c_int = undefined; |
| 1464 | \\ _ = a; | ||
| 1405 | \\ var b: f32 = undefined; | 1465 | \\ var b: f32 = undefined; |
| 1466 | \\ _ = b; | ||
| 1406 | \\ var c: ?*c_void = undefined; | 1467 | \\ var c: ?*c_void = undefined; |
| 1468 | \\ _ = c; | ||
| 1407 | \\ while (a != 0) return 0; | 1469 | \\ while (a != 0) return 0; |
| 1408 | \\ while (b != 0) return 1; | 1470 | \\ while (b != 0) return 1; |
| 1409 | \\ while (c != null) return 2; | 1471 | \\ while (c != null) return 2; |
| ... | @@ -1424,8 +1486,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1424,8 +1486,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1424 | , &[_][]const u8{ | 1486 | , &[_][]const u8{ |
| 1425 | \\pub export fn for_none_bool() c_int { | 1487 | \\pub export fn for_none_bool() c_int { |
| 1426 | \\ var a: c_int = undefined; | 1488 | \\ var a: c_int = undefined; |
| 1489 | \\ _ = a; | ||
| 1427 | \\ var b: f32 = undefined; | 1490 | \\ var b: f32 = undefined; |
| 1491 | \\ _ = b; | ||
| 1428 | \\ var c: ?*c_void = undefined; | 1492 | \\ var c: ?*c_void = undefined; |
| 1493 | \\ _ = c; | ||
| 1429 | \\ while (a != 0) return 0; | 1494 | \\ while (a != 0) return 0; |
| 1430 | \\ while (b != 0) return 1; | 1495 | \\ while (b != 0) return 1; |
| 1431 | \\ while (c != null) return 2; | 1496 | \\ while (c != null) return 2; |
| ... | @@ -1462,6 +1527,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1462,6 +1527,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1462 | , &[_][]const u8{ | 1527 | , &[_][]const u8{ |
| 1463 | \\pub export fn foo() void { | 1528 | \\pub export fn foo() void { |
| 1464 | \\ var x: [*c]c_int = undefined; | 1529 | \\ var x: [*c]c_int = undefined; |
| 1530 | \\ _ = x; | ||
| 1465 | \\ x.* = 1; | 1531 | \\ x.* = 1; |
| 1466 | \\} | 1532 | \\} |
| 1467 | }); | 1533 | }); |
| ... | @@ -1475,7 +1541,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1475,7 +1541,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1475 | , &[_][]const u8{ | 1541 | , &[_][]const u8{ |
| 1476 | \\pub export fn foo() c_int { | 1542 | \\pub export fn foo() c_int { |
| 1477 | \\ var x: c_int = 1234; | 1543 | \\ var x: c_int = 1234; |
| 1544 | \\ _ = x; | ||
| 1478 | \\ var ptr: [*c]c_int = &x; | 1545 | \\ var ptr: [*c]c_int = &x; |
| 1546 | \\ _ = ptr; | ||
| 1479 | \\ return ptr.*; | 1547 | \\ return ptr.*; |
| 1480 | \\} | 1548 | \\} |
| 1481 | }); | 1549 | }); |
| ... | @@ -1488,6 +1556,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1488,6 +1556,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1488 | , &[_][]const u8{ | 1556 | , &[_][]const u8{ |
| 1489 | \\pub export fn foo() c_int { | 1557 | \\pub export fn foo() c_int { |
| 1490 | \\ var x: c_int = undefined; | 1558 | \\ var x: c_int = undefined; |
| 1559 | \\ _ = x; | ||
| 1491 | \\ return ~x; | 1560 | \\ return ~x; |
| 1492 | \\} | 1561 | \\} |
| 1493 | }); | 1562 | }); |
| ... | @@ -1505,8 +1574,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1505,8 +1574,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1505 | , &[_][]const u8{ | 1574 | , &[_][]const u8{ |
| 1506 | \\pub export fn foo() c_int { | 1575 | \\pub export fn foo() c_int { |
| 1507 | \\ var a: c_int = undefined; | 1576 | \\ var a: c_int = undefined; |
| 1577 | \\ _ = a; | ||
| 1508 | \\ var b: f32 = undefined; | 1578 | \\ var b: f32 = undefined; |
| 1579 | \\ _ = b; | ||
| 1509 | \\ var c: ?*c_void = undefined; | 1580 | \\ var c: ?*c_void = undefined; |
| 1581 | \\ _ = c; | ||
| 1510 | \\ return @boolToInt(!(a == @as(c_int, 0))); | 1582 | \\ return @boolToInt(!(a == @as(c_int, 0))); |
| 1511 | \\ return @boolToInt(!(a != 0)); | 1583 | \\ return @boolToInt(!(a != 0)); |
| 1512 | \\ return @boolToInt(!(b != 0)); | 1584 | \\ return @boolToInt(!(b != 0)); |
| ... | @@ -1628,9 +1700,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1628,9 +1700,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1628 | \\ var arr: [10]u8 = [1]u8{ | 1700 | \\ var arr: [10]u8 = [1]u8{ |
| 1629 | \\ 1, | 1701 | \\ 1, |
| 1630 | \\ } ++ [1]u8{0} ** 9; | 1702 | \\ } ++ [1]u8{0} ** 9; |
| 1703 | \\ _ = arr; | ||
| 1631 | \\ var arr1: [10][*c]u8 = [1][*c]u8{ | 1704 | \\ var arr1: [10][*c]u8 = [1][*c]u8{ |
| 1632 | \\ null, | 1705 | \\ null, |
| 1633 | \\ } ++ [1][*c]u8{null} ** 9; | 1706 | \\ } ++ [1][*c]u8{null} ** 9; |
| 1707 | \\ _ = arr1; | ||
| 1634 | \\} | 1708 | \\} |
| 1635 | }); | 1709 | }); |
| 1636 | 1710 | ||
| ... | @@ -1817,10 +1891,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1817,10 +1891,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1817 | \\pub extern var c: c_int; | 1891 | \\pub extern var c: c_int; |
| 1818 | , | 1892 | , |
| 1819 | \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) { | 1893 | \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) { |
| 1894 | \\ _ = c_1; | ||
| 1820 | \\ return c_1 * @as(c_int, 2); | 1895 | \\ return c_1 * @as(c_int, 2); |
| 1821 | \\} | 1896 | \\} |
| 1822 | , | 1897 | , |
| 1823 | \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { | 1898 | \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { |
| 1899 | \\ _ = L; | ||
| 1900 | \\ _ = b; | ||
| 1824 | \\ return L + b; | 1901 | \\ return L + b; |
| 1825 | \\} | 1902 | \\} |
| 1826 | , | 1903 | , |
| ... | @@ -1872,13 +1949,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1872,13 +1949,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1872 | \\pub var c: c_int = 4; | 1949 | \\pub var c: c_int = 4; |
| 1873 | \\pub export fn foo(arg_c_1: u8) void { | 1950 | \\pub export fn foo(arg_c_1: u8) void { |
| 1874 | \\ var c_1 = arg_c_1; | 1951 | \\ var c_1 = arg_c_1; |
| 1952 | \\ _ = c_1; | ||
| 1875 | \\ var a_2: c_int = undefined; | 1953 | \\ var a_2: c_int = undefined; |
| 1954 | \\ _ = a_2; | ||
| 1876 | \\ var b_3: u8 = 123; | 1955 | \\ var b_3: u8 = 123; |
| 1956 | \\ _ = b_3; | ||
| 1877 | \\ b_3 = @bitCast(u8, @truncate(i8, a_2)); | 1957 | \\ b_3 = @bitCast(u8, @truncate(i8, a_2)); |
| 1878 | \\ { | 1958 | \\ { |
| 1879 | \\ var d: c_int = 5; | 1959 | \\ var d: c_int = 5; |
| 1960 | \\ _ = d; | ||
| 1880 | \\ } | 1961 | \\ } |
| 1881 | \\ var d: c_uint = @bitCast(c_uint, @as(c_int, 440)); | 1962 | \\ var d: c_uint = @bitCast(c_uint, @as(c_int, 440)); |
| 1963 | \\ _ = d; | ||
| 1882 | \\} | 1964 | \\} |
| 1883 | }); | 1965 | }); |
| 1884 | 1966 | ||
| ... | @@ -1912,7 +1994,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1912,7 +1994,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1912 | , &[_][]const u8{ | 1994 | , &[_][]const u8{ |
| 1913 | \\pub export fn foo() void { | 1995 | \\pub export fn foo() void { |
| 1914 | \\ var a: c_int = undefined; | 1996 | \\ var a: c_int = undefined; |
| 1997 | \\ _ = a; | ||
| 1915 | \\ var b: c_int = undefined; | 1998 | \\ var b: c_int = undefined; |
| 1999 | \\ _ = b; | ||
| 1916 | \\ a = blk: { | 2000 | \\ a = blk: { |
| 1917 | \\ const tmp = @as(c_int, 2); | 2001 | \\ const tmp = @as(c_int, 2); |
| 1918 | \\ b = tmp; | 2002 | \\ b = tmp; |
| ... | @@ -1942,11 +2026,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1942,11 +2026,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1942 | , &[_][]const u8{ | 2026 | , &[_][]const u8{ |
| 1943 | \\pub export fn foo() c_int { | 2027 | \\pub export fn foo() c_int { |
| 1944 | \\ var a: c_int = 5; | 2028 | \\ var a: c_int = 5; |
| 2029 | \\ _ = a; | ||
| 1945 | \\ while (true) { | 2030 | \\ while (true) { |
| 1946 | \\ a = 2; | 2031 | \\ a = 2; |
| 1947 | \\ } | 2032 | \\ } |
| 1948 | \\ while (true) { | 2033 | \\ while (true) { |
| 1949 | \\ var a_1: c_int = 4; | 2034 | \\ var a_1: c_int = 4; |
| 2035 | \\ _ = a_1; | ||
| 1950 | \\ a_1 = 9; | 2036 | \\ a_1 = 9; |
| 1951 | \\ return blk: { | 2037 | \\ return blk: { |
| 1952 | \\ _ = @as(c_int, 6); | 2038 | \\ _ = @as(c_int, 6); |
| ... | @@ -1955,6 +2041,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1955,6 +2041,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1955 | \\ } | 2041 | \\ } |
| 1956 | \\ while (true) { | 2042 | \\ while (true) { |
| 1957 | \\ var a_1: c_int = 2; | 2043 | \\ var a_1: c_int = 2; |
| 2044 | \\ _ = a_1; | ||
| 1958 | \\ a_1 = 12; | 2045 | \\ a_1 = 12; |
| 1959 | \\ } | 2046 | \\ } |
| 1960 | \\ while (true) { | 2047 | \\ while (true) { |
| ... | @@ -1976,9 +2063,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1976,9 +2063,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1976 | \\pub export fn foo() void { | 2063 | \\pub export fn foo() void { |
| 1977 | \\ { | 2064 | \\ { |
| 1978 | \\ var i: c_int = 2; | 2065 | \\ var i: c_int = 2; |
| 2066 | \\ _ = i; | ||
| 1979 | \\ var b: c_int = 4; | 2067 | \\ var b: c_int = 4; |
| 2068 | \\ _ = b; | ||
| 1980 | \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { | 2069 | \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { |
| 1981 | \\ var a: c_int = 2; | 2070 | \\ var a: c_int = 2; |
| 2071 | \\ _ = a; | ||
| 1982 | \\ _ = blk: { | 2072 | \\ _ = blk: { |
| 1983 | \\ _ = blk_1: { | 2073 | \\ _ = blk_1: { |
| 1984 | \\ a = 6; | 2074 | \\ a = 6; |
| ... | @@ -1989,6 +2079,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1989,6 +2079,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1989 | \\ } | 2079 | \\ } |
| 1990 | \\ } | 2080 | \\ } |
| 1991 | \\ var i: u8 = 2; | 2081 | \\ var i: u8 = 2; |
| 2082 | \\ _ = i; | ||
| 1992 | \\} | 2083 | \\} |
| 1993 | }); | 2084 | }); |
| 1994 | 2085 | ||
| ... | @@ -2061,7 +2152,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2061,7 +2152,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2061 | , &[_][]const u8{ | 2152 | , &[_][]const u8{ |
| 2062 | \\pub export fn switch_fn(arg_i: c_int) void { | 2153 | \\pub export fn switch_fn(arg_i: c_int) void { |
| 2063 | \\ var i = arg_i; | 2154 | \\ var i = arg_i; |
| 2155 | \\ _ = i; | ||
| 2064 | \\ var res: c_int = 0; | 2156 | \\ var res: c_int = 0; |
| 2157 | \\ _ = res; | ||
| 2065 | \\ while (true) { | 2158 | \\ while (true) { |
| 2066 | \\ switch (i) { | 2159 | \\ switch (i) { |
| 2067 | \\ @as(c_int, 0) => { | 2160 | \\ @as(c_int, 0) => { |
| ... | @@ -2150,7 +2243,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2150,7 +2243,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2150 | , &[_][]const u8{ | 2243 | , &[_][]const u8{ |
| 2151 | \\pub export fn max(arg_a: c_int) void { | 2244 | \\pub export fn max(arg_a: c_int) void { |
| 2152 | \\ var a = arg_a; | 2245 | \\ var a = arg_a; |
| 2246 | \\ _ = a; | ||
| 2153 | \\ var tmp: c_int = undefined; | 2247 | \\ var tmp: c_int = undefined; |
| 2248 | \\ _ = tmp; | ||
| 2154 | \\ tmp = a; | 2249 | \\ tmp = a; |
| 2155 | \\ a = tmp; | 2250 | \\ a = tmp; |
| 2156 | \\} | 2251 | \\} |
| ... | @@ -2164,8 +2259,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2164,8 +2259,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2164 | , &[_][]const u8{ | 2259 | , &[_][]const u8{ |
| 2165 | \\pub export fn max(arg_a: c_int) void { | 2260 | \\pub export fn max(arg_a: c_int) void { |
| 2166 | \\ var a = arg_a; | 2261 | \\ var a = arg_a; |
| 2262 | \\ _ = a; | ||
| 2167 | \\ var b: c_int = undefined; | 2263 | \\ var b: c_int = undefined; |
| 2264 | \\ _ = b; | ||
| 2168 | \\ var c: c_int = undefined; | 2265 | \\ var c: c_int = undefined; |
| 2266 | \\ _ = c; | ||
| 2169 | \\ c = blk: { | 2267 | \\ c = blk: { |
| 2170 | \\ const tmp = a; | 2268 | \\ const tmp = a; |
| 2171 | \\ b = tmp; | 2269 | \\ b = tmp; |
| ... | @@ -2194,6 +2292,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2194,6 +2292,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2194 | , &[_][]const u8{ | 2292 | , &[_][]const u8{ |
| 2195 | \\pub export fn float_to_int(arg_a: f32) c_int { | 2293 | \\pub export fn float_to_int(arg_a: f32) c_int { |
| 2196 | \\ var a = arg_a; | 2294 | \\ var a = arg_a; |
| 2295 | \\ _ = a; | ||
| 2197 | \\ return @floatToInt(c_int, a); | 2296 | \\ return @floatToInt(c_int, a); |
| 2198 | \\} | 2297 | \\} |
| 2199 | }); | 2298 | }); |
| ... | @@ -2217,16 +2316,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2217,16 +2316,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2217 | , &[_][]const u8{ | 2316 | , &[_][]const u8{ |
| 2218 | \\pub export fn escapes() [*c]const u8 { | 2317 | \\pub export fn escapes() [*c]const u8 { |
| 2219 | \\ var a: u8 = '\''; | 2318 | \\ var a: u8 = '\''; |
| 2319 | \\ _ = a; | ||
| 2220 | \\ var b: u8 = '\\'; | 2320 | \\ var b: u8 = '\\'; |
| 2321 | \\ _ = b; | ||
| 2221 | \\ var c: u8 = '\x07'; | 2322 | \\ var c: u8 = '\x07'; |
| 2323 | \\ _ = c; | ||
| 2222 | \\ var d: u8 = '\x08'; | 2324 | \\ var d: u8 = '\x08'; |
| 2325 | \\ _ = d; | ||
| 2223 | \\ var e: u8 = '\x0c'; | 2326 | \\ var e: u8 = '\x0c'; |
| 2327 | \\ _ = e; | ||
| 2224 | \\ var f: u8 = '\n'; | 2328 | \\ var f: u8 = '\n'; |
| 2329 | \\ _ = f; | ||
| 2225 | \\ var g: u8 = '\r'; | 2330 | \\ var g: u8 = '\r'; |
| 2331 | \\ _ = g; | ||
| 2226 | \\ var h: u8 = '\t'; | 2332 | \\ var h: u8 = '\t'; |
| 2333 | \\ _ = h; | ||
| 2227 | \\ var i: u8 = '\x0b'; | 2334 | \\ var i: u8 = '\x0b'; |
| 2335 | \\ _ = i; | ||
| 2228 | \\ var j: u8 = '\x00'; | 2336 | \\ var j: u8 = '\x00'; |
| 2337 | \\ _ = j; | ||
| 2229 | \\ var k: u8 = '"'; | 2338 | \\ var k: u8 = '"'; |
| 2339 | \\ _ = k; | ||
| 2230 | \\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\""; | 2340 | \\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\""; |
| 2231 | \\} | 2341 | \\} |
| 2232 | }); | 2342 | }); |
| ... | @@ -2246,11 +2356,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2246,11 +2356,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2246 | , &[_][]const u8{ | 2356 | , &[_][]const u8{ |
| 2247 | \\pub export fn foo() void { | 2357 | \\pub export fn foo() void { |
| 2248 | \\ var a: c_int = 2; | 2358 | \\ var a: c_int = 2; |
| 2359 | \\ _ = a; | ||
| 2249 | \\ while (true) { | 2360 | \\ while (true) { |
| 2250 | \\ a = a - @as(c_int, 1); | 2361 | \\ a = a - @as(c_int, 1); |
| 2251 | \\ if (!(a != 0)) break; | 2362 | \\ if (!(a != 0)) break; |
| 2252 | \\ } | 2363 | \\ } |
| 2253 | \\ var b: c_int = 2; | 2364 | \\ var b: c_int = 2; |
| 2365 | \\ _ = b; | ||
| 2254 | \\ while (true) { | 2366 | \\ while (true) { |
| 2255 | \\ b = b - @as(c_int, 1); | 2367 | \\ b = b - @as(c_int, 1); |
| 2256 | \\ if (!(b != 0)) break; | 2368 | \\ if (!(b != 0)) break; |
| ... | @@ -2291,21 +2403,37 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2291,21 +2403,37 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2291 | \\pub const SomeTypedef = c_int; | 2403 | \\pub const SomeTypedef = c_int; |
| 2292 | \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void) c_int { | 2404 | \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void) c_int { |
| 2293 | \\ var a = arg_a; | 2405 | \\ var a = arg_a; |
| 2406 | \\ _ = a; | ||
| 2294 | \\ var b = arg_b; | 2407 | \\ var b = arg_b; |
| 2408 | \\ _ = b; | ||
| 2295 | \\ var c = arg_c; | 2409 | \\ var c = arg_c; |
| 2410 | \\ _ = c; | ||
| 2296 | \\ var d: enum_Foo = @bitCast(c_uint, FooA); | 2411 | \\ var d: enum_Foo = @bitCast(c_uint, FooA); |
| 2412 | \\ _ = d; | ||
| 2297 | \\ var e: c_int = @boolToInt((a != 0) and (b != 0)); | 2413 | \\ var e: c_int = @boolToInt((a != 0) and (b != 0)); |
| 2414 | \\ _ = e; | ||
| 2298 | \\ var f: c_int = @boolToInt((b != 0) and (c != null)); | 2415 | \\ var f: c_int = @boolToInt((b != 0) and (c != null)); |
| 2416 | \\ _ = f; | ||
| 2299 | \\ var g: c_int = @boolToInt((a != 0) and (c != null)); | 2417 | \\ var g: c_int = @boolToInt((a != 0) and (c != null)); |
| 2418 | \\ _ = g; | ||
| 2300 | \\ var h: c_int = @boolToInt((a != 0) or (b != 0)); | 2419 | \\ var h: c_int = @boolToInt((a != 0) or (b != 0)); |
| 2420 | \\ _ = h; | ||
| 2301 | \\ var i: c_int = @boolToInt((b != 0) or (c != null)); | 2421 | \\ var i: c_int = @boolToInt((b != 0) or (c != null)); |
| 2422 | \\ _ = i; | ||
| 2302 | \\ var j: c_int = @boolToInt((a != 0) or (c != null)); | 2423 | \\ var j: c_int = @boolToInt((a != 0) or (c != null)); |
| 2424 | \\ _ = j; | ||
| 2303 | \\ var k: c_int = @boolToInt((a != 0) or (@bitCast(c_int, d) != 0)); | 2425 | \\ var k: c_int = @boolToInt((a != 0) or (@bitCast(c_int, d) != 0)); |
| 2426 | \\ _ = k; | ||
| 2304 | \\ var l: c_int = @boolToInt((@bitCast(c_int, d) != 0) and (b != 0)); | 2427 | \\ var l: c_int = @boolToInt((@bitCast(c_int, d) != 0) and (b != 0)); |
| 2428 | \\ _ = l; | ||
| 2305 | \\ var m: c_int = @boolToInt((c != null) or (d != 0)); | 2429 | \\ var m: c_int = @boolToInt((c != null) or (d != 0)); |
| 2430 | \\ _ = m; | ||
| 2306 | \\ var td: SomeTypedef = 44; | 2431 | \\ var td: SomeTypedef = 44; |
| 2432 | \\ _ = td; | ||
| 2307 | \\ var o: c_int = @boolToInt((td != 0) or (b != 0)); | 2433 | \\ var o: c_int = @boolToInt((td != 0) or (b != 0)); |
| 2434 | \\ _ = o; | ||
| 2308 | \\ var p: c_int = @boolToInt((c != null) and (td != 0)); | 2435 | \\ var p: c_int = @boolToInt((c != null) and (td != 0)); |
| 2436 | \\ _ = p; | ||
| 2309 | \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p; | 2437 | \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p; |
| 2310 | \\} | 2438 | \\} |
| 2311 | , | 2439 | , |
| ... | @@ -2345,7 +2473,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2345,7 +2473,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2345 | , &[_][]const u8{ | 2473 | , &[_][]const u8{ |
| 2346 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2474 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2347 | \\ var a = arg_a; | 2475 | \\ var a = arg_a; |
| 2476 | \\ _ = a; | ||
| 2348 | \\ var b = arg_b; | 2477 | \\ var b = arg_b; |
| 2478 | \\ _ = b; | ||
| 2349 | \\ return (a & b) ^ (a | b); | 2479 | \\ return (a & b) ^ (a | b); |
| 2350 | \\} | 2480 | \\} |
| 2351 | }); | 2481 | }); |
| ... | @@ -2364,14 +2494,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2364,14 +2494,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2364 | , &[_][]const u8{ | 2494 | , &[_][]const u8{ |
| 2365 | \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int { | 2495 | \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int { |
| 2366 | \\ var a = arg_a; | 2496 | \\ var a = arg_a; |
| 2497 | \\ _ = a; | ||
| 2367 | \\ var b = arg_b; | 2498 | \\ var b = arg_b; |
| 2499 | \\ _ = b; | ||
| 2368 | \\ var c: c_int = @boolToInt(a < b); | 2500 | \\ var c: c_int = @boolToInt(a < b); |
| 2501 | \\ _ = c; | ||
| 2369 | \\ var d: c_int = @boolToInt(a > b); | 2502 | \\ var d: c_int = @boolToInt(a > b); |
| 2503 | \\ _ = d; | ||
| 2370 | \\ var e: c_int = @boolToInt(a <= b); | 2504 | \\ var e: c_int = @boolToInt(a <= b); |
| 2505 | \\ _ = e; | ||
| 2371 | \\ var f: c_int = @boolToInt(a >= b); | 2506 | \\ var f: c_int = @boolToInt(a >= b); |
| 2507 | \\ _ = f; | ||
| 2372 | \\ var g: c_int = @boolToInt(c < d); | 2508 | \\ var g: c_int = @boolToInt(c < d); |
| 2509 | \\ _ = g; | ||
| 2373 | \\ var h: c_int = @boolToInt(e < f); | 2510 | \\ var h: c_int = @boolToInt(e < f); |
| 2511 | \\ _ = h; | ||
| 2374 | \\ var i: c_int = @boolToInt(g < h); | 2512 | \\ var i: c_int = @boolToInt(g < h); |
| 2513 | \\ _ = i; | ||
| 2375 | \\ return i; | 2514 | \\ return i; |
| 2376 | \\} | 2515 | \\} |
| 2377 | }); | 2516 | }); |
| ... | @@ -2387,7 +2526,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2387,7 +2526,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2387 | , &[_][]const u8{ | 2526 | , &[_][]const u8{ |
| 2388 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2527 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2389 | \\ var a = arg_a; | 2528 | \\ var a = arg_a; |
| 2529 | \\ _ = a; | ||
| 2390 | \\ var b = arg_b; | 2530 | \\ var b = arg_b; |
| 2531 | \\ _ = b; | ||
| 2391 | \\ if (a == b) return a; | 2532 | \\ if (a == b) return a; |
| 2392 | \\ if (a != b) return b; | 2533 | \\ if (a != b) return b; |
| 2393 | \\ return a; | 2534 | \\ return a; |
| ... | @@ -2404,6 +2545,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2404,6 +2545,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2404 | \\pub const yes = [*c]u8; | 2545 | \\pub const yes = [*c]u8; |
| 2405 | \\pub export fn foo() void { | 2546 | \\pub export fn foo() void { |
| 2406 | \\ var a: yes = undefined; | 2547 | \\ var a: yes = undefined; |
| 2548 | \\ _ = a; | ||
| 2407 | \\ if (a != null) { | 2549 | \\ if (a != null) { |
| 2408 | \\ _ = @as(c_int, 2); | 2550 | \\ _ = @as(c_int, 2); |
| 2409 | \\ } | 2551 | \\ } |
| ... | @@ -2423,6 +2565,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2423,6 +2565,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2423 | \\ return blk: { | 2565 | \\ return blk: { |
| 2424 | \\ var a: c_int = 1; | 2566 | \\ var a: c_int = 1; |
| 2425 | \\ _ = a; | 2567 | \\ _ = a; |
| 2568 | \\ _ = a; | ||
| 2426 | \\ break :blk a; | 2569 | \\ break :blk a; |
| 2427 | \\ }; | 2570 | \\ }; |
| 2428 | \\} | 2571 | \\} |
| ... | @@ -2448,6 +2591,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2448,6 +2591,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2448 | \\pub export var b: f32 = 2.0; | 2591 | \\pub export var b: f32 = 2.0; |
| 2449 | \\pub export fn foo() void { | 2592 | \\pub export fn foo() void { |
| 2450 | \\ var c: [*c]struct_Foo = undefined; | 2593 | \\ var c: [*c]struct_Foo = undefined; |
| 2594 | \\ _ = c; | ||
| 2451 | \\ _ = a.b; | 2595 | \\ _ = a.b; |
| 2452 | \\ _ = c.*.b; | 2596 | \\ _ = c.*.b; |
| 2453 | \\} | 2597 | \\} |
| ... | @@ -2467,6 +2611,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2467,6 +2611,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2467 | \\pub export var array: [100]c_int = [1]c_int{0} ** 100; | 2611 | \\pub export var array: [100]c_int = [1]c_int{0} ** 100; |
| 2468 | \\pub export fn foo(arg_index: c_int) c_int { | 2612 | \\pub export fn foo(arg_index: c_int) c_int { |
| 2469 | \\ var index = arg_index; | 2613 | \\ var index = arg_index; |
| 2614 | \\ _ = index; | ||
| 2470 | \\ return array[@intCast(c_uint, index)]; | 2615 | \\ return array[@intCast(c_uint, index)]; |
| 2471 | \\} | 2616 | \\} |
| 2472 | , | 2617 | , |
| ... | @@ -2481,7 +2626,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2481,7 +2626,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2481 | , &[_][]const u8{ | 2626 | , &[_][]const u8{ |
| 2482 | \\pub export fn foo() void { | 2627 | \\pub export fn foo() void { |
| 2483 | \\ var a: [10]c_int = undefined; | 2628 | \\ var a: [10]c_int = undefined; |
| 2629 | \\ _ = a; | ||
| 2484 | \\ var i: c_int = 0; | 2630 | \\ var i: c_int = 0; |
| 2631 | \\ _ = i; | ||
| 2485 | \\ a[@intCast(c_uint, i)] = 0; | 2632 | \\ a[@intCast(c_uint, i)] = 0; |
| 2486 | \\} | 2633 | \\} |
| 2487 | }); | 2634 | }); |
| ... | @@ -2494,7 +2641,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2494,7 +2641,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2494 | , &[_][]const u8{ | 2641 | , &[_][]const u8{ |
| 2495 | \\pub export fn foo() void { | 2642 | \\pub export fn foo() void { |
| 2496 | \\ var a: [10]c_longlong = undefined; | 2643 | \\ var a: [10]c_longlong = undefined; |
| 2644 | \\ _ = a; | ||
| 2497 | \\ var i: c_longlong = 0; | 2645 | \\ var i: c_longlong = 0; |
| 2646 | \\ _ = i; | ||
| 2498 | \\ a[@intCast(usize, i)] = 0; | 2647 | \\ a[@intCast(usize, i)] = 0; |
| 2499 | \\} | 2648 | \\} |
| 2500 | }); | 2649 | }); |
| ... | @@ -2507,7 +2656,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2507,7 +2656,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2507 | , &[_][]const u8{ | 2656 | , &[_][]const u8{ |
| 2508 | \\pub export fn foo() void { | 2657 | \\pub export fn foo() void { |
| 2509 | \\ var a: [10]c_uint = undefined; | 2658 | \\ var a: [10]c_uint = undefined; |
| 2659 | \\ _ = a; | ||
| 2510 | \\ var i: c_uint = 0; | 2660 | \\ var i: c_uint = 0; |
| 2661 | \\ _ = i; | ||
| 2511 | \\ a[i] = 0; | 2662 | \\ a[i] = 0; |
| 2512 | \\} | 2663 | \\} |
| 2513 | }); | 2664 | }); |
| ... | @@ -2516,6 +2667,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2516,6 +2667,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2516 | \\#define CALL(arg) bar(arg) | 2667 | \\#define CALL(arg) bar(arg) |
| 2517 | , &[_][]const u8{ | 2668 | , &[_][]const u8{ |
| 2518 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) { | 2669 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) { |
| 2670 | \\ _ = arg; | ||
| 2519 | \\ return bar(arg); | 2671 | \\ return bar(arg); |
| 2520 | \\} | 2672 | \\} |
| 2521 | }); | 2673 | }); |
| ... | @@ -2524,6 +2676,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2524,6 +2676,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2524 | \\#define CALL(arg) bar() | 2676 | \\#define CALL(arg) bar() |
| 2525 | , &[_][]const u8{ | 2677 | , &[_][]const u8{ |
| 2526 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) { | 2678 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) { |
| 2679 | \\ _ = arg; | ||
| 2527 | \\ return bar(); | 2680 | \\ return bar(); |
| 2528 | \\} | 2681 | \\} |
| 2529 | }); | 2682 | }); |
| ... | @@ -2539,7 +2692,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2539,7 +2692,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2539 | , &[_][]const u8{ | 2692 | , &[_][]const u8{ |
| 2540 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2693 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2541 | \\ var a = arg_a; | 2694 | \\ var a = arg_a; |
| 2695 | \\ _ = a; | ||
| 2542 | \\ var b = arg_b; | 2696 | \\ var b = arg_b; |
| 2697 | \\ _ = b; | ||
| 2543 | \\ if ((a < b) or (a == b)) return b; | 2698 | \\ if ((a < b) or (a == b)) return b; |
| 2544 | \\ if ((a >= b) and (a == b)) return a; | 2699 | \\ if ((a >= b) and (a == b)) return a; |
| 2545 | \\ return a; | 2700 | \\ return a; |
| ... | @@ -2561,7 +2716,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2561,7 +2716,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2561 | , &[_][]const u8{ | 2716 | , &[_][]const u8{ |
| 2562 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2717 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2563 | \\ var a = arg_a; | 2718 | \\ var a = arg_a; |
| 2719 | \\ _ = a; | ||
| 2564 | \\ var b = arg_b; | 2720 | \\ var b = arg_b; |
| 2721 | \\ _ = b; | ||
| 2565 | \\ if (a < b) return b; | 2722 | \\ if (a < b) return b; |
| 2566 | \\ if (a < b) return b else return a; | 2723 | \\ if (a < b) return b else return a; |
| 2567 | \\ if (a < b) {} else {} | 2724 | \\ if (a < b) {} else {} |
| ... | @@ -2582,12 +2739,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2582,12 +2739,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2582 | \\pub export fn foo() void { | 2739 | \\pub export fn foo() void { |
| 2583 | \\ if (true) { | 2740 | \\ if (true) { |
| 2584 | \\ var a: c_int = 2; | 2741 | \\ var a: c_int = 2; |
| 2742 | \\ _ = a; | ||
| 2585 | \\ } | 2743 | \\ } |
| 2586 | \\ if ((blk: { | 2744 | \\ if ((blk: { |
| 2587 | \\ _ = @as(c_int, 2); | 2745 | \\ _ = @as(c_int, 2); |
| 2588 | \\ break :blk @as(c_int, 5); | 2746 | \\ break :blk @as(c_int, 5); |
| 2589 | \\ }) != 0) { | 2747 | \\ }) != 0) { |
| 2590 | \\ var a: c_int = 2; | 2748 | \\ var a: c_int = 2; |
| 2749 | \\ _ = a; | ||
| 2591 | \\ } | 2750 | \\ } |
| 2592 | \\} | 2751 | \\} |
| 2593 | }); | 2752 | }); |
| ... | @@ -2610,9 +2769,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2610,9 +2769,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2610 | \\; | 2769 | \\; |
| 2611 | \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void, arg_d: enum_SomeEnum) c_int { | 2770 | \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void, arg_d: enum_SomeEnum) c_int { |
| 2612 | \\ var a = arg_a; | 2771 | \\ var a = arg_a; |
| 2772 | \\ _ = a; | ||
| 2613 | \\ var b = arg_b; | 2773 | \\ var b = arg_b; |
| 2774 | \\ _ = b; | ||
| 2614 | \\ var c = arg_c; | 2775 | \\ var c = arg_c; |
| 2776 | \\ _ = c; | ||
| 2615 | \\ var d = arg_d; | 2777 | \\ var d = arg_d; |
| 2778 | \\ _ = d; | ||
| 2616 | \\ if (a != 0) return 0; | 2779 | \\ if (a != 0) return 0; |
| 2617 | \\ if (b != 0) return 1; | 2780 | \\ if (b != 0) return 1; |
| 2618 | \\ if (c != null) return 2; | 2781 | \\ if (c != null) return 2; |
| ... | @@ -2640,6 +2803,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2640,6 +2803,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2640 | , &[_][]const u8{ | 2803 | , &[_][]const u8{ |
| 2641 | \\pub export fn abs(arg_a: c_int) c_int { | 2804 | \\pub export fn abs(arg_a: c_int) c_int { |
| 2642 | \\ var a = arg_a; | 2805 | \\ var a = arg_a; |
| 2806 | \\ _ = a; | ||
| 2643 | \\ return if (a < @as(c_int, 0)) -a else a; | 2807 | \\ return if (a < @as(c_int, 0)) -a else a; |
| 2644 | \\} | 2808 | \\} |
| 2645 | }); | 2809 | }); |
| ... | @@ -2660,16 +2824,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2660,16 +2824,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2660 | , &[_][]const u8{ | 2824 | , &[_][]const u8{ |
| 2661 | \\pub export fn foo1(arg_a: c_uint) c_uint { | 2825 | \\pub export fn foo1(arg_a: c_uint) c_uint { |
| 2662 | \\ var a = arg_a; | 2826 | \\ var a = arg_a; |
| 2827 | \\ _ = a; | ||
| 2663 | \\ a +%= 1; | 2828 | \\ a +%= 1; |
| 2664 | \\ return a; | 2829 | \\ return a; |
| 2665 | \\} | 2830 | \\} |
| 2666 | \\pub export fn foo2(arg_a: c_int) c_int { | 2831 | \\pub export fn foo2(arg_a: c_int) c_int { |
| 2667 | \\ var a = arg_a; | 2832 | \\ var a = arg_a; |
| 2833 | \\ _ = a; | ||
| 2668 | \\ a += 1; | 2834 | \\ a += 1; |
| 2669 | \\ return a; | 2835 | \\ return a; |
| 2670 | \\} | 2836 | \\} |
| 2671 | \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int { | 2837 | \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int { |
| 2672 | \\ var a = arg_a; | 2838 | \\ var a = arg_a; |
| 2839 | \\ _ = a; | ||
| 2673 | \\ a += 1; | 2840 | \\ a += 1; |
| 2674 | \\ return a; | 2841 | \\ return a; |
| 2675 | \\} | 2842 | \\} |
| ... | @@ -2695,7 +2862,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2695,7 +2862,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2695 | \\} | 2862 | \\} |
| 2696 | \\pub export fn bar() void { | 2863 | \\pub export fn bar() void { |
| 2697 | \\ var f: ?fn () callconv(.C) void = foo; | 2864 | \\ var f: ?fn () callconv(.C) void = foo; |
| 2865 | \\ _ = f; | ||
| 2698 | \\ var b: ?fn () callconv(.C) c_int = baz; | 2866 | \\ var b: ?fn () callconv(.C) c_int = baz; |
| 2867 | \\ _ = b; | ||
| 2699 | \\ f.?(); | 2868 | \\ f.?(); |
| 2700 | \\ f.?(); | 2869 | \\ f.?(); |
| 2701 | \\ foo(); | 2870 | \\ foo(); |
| ... | @@ -2721,7 +2890,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2721,7 +2890,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2721 | , &[_][]const u8{ | 2890 | , &[_][]const u8{ |
| 2722 | \\pub export fn foo() void { | 2891 | \\pub export fn foo() void { |
| 2723 | \\ var i: c_int = 0; | 2892 | \\ var i: c_int = 0; |
| 2893 | \\ _ = i; | ||
| 2724 | \\ var u: c_uint = 0; | 2894 | \\ var u: c_uint = 0; |
| 2895 | \\ _ = u; | ||
| 2725 | \\ i += 1; | 2896 | \\ i += 1; |
| 2726 | \\ i -= 1; | 2897 | \\ i -= 1; |
| 2727 | \\ u +%= 1; | 2898 | \\ u +%= 1; |
| ... | @@ -2760,7 +2931,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2760,7 +2931,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2760 | , &[_][]const u8{ | 2931 | , &[_][]const u8{ |
| 2761 | \\pub export fn log2(arg_a: c_uint) c_int { | 2932 | \\pub export fn log2(arg_a: c_uint) c_int { |
| 2762 | \\ var a = arg_a; | 2933 | \\ var a = arg_a; |
| 2934 | \\ _ = a; | ||
| 2763 | \\ var i: c_int = 0; | 2935 | \\ var i: c_int = 0; |
| 2936 | \\ _ = i; | ||
| 2764 | \\ while (a > @bitCast(c_uint, @as(c_int, 0))) { | 2937 | \\ while (a > @bitCast(c_uint, @as(c_int, 0))) { |
| 2765 | \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); | 2938 | \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); |
| 2766 | \\ } | 2939 | \\ } |
| ... | @@ -2780,7 +2953,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2780,7 +2953,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2780 | , &[_][]const u8{ | 2953 | , &[_][]const u8{ |
| 2781 | \\pub export fn log2(arg_a: u32) c_int { | 2954 | \\pub export fn log2(arg_a: u32) c_int { |
| 2782 | \\ var a = arg_a; | 2955 | \\ var a = arg_a; |
| 2956 | \\ _ = a; | ||
| 2783 | \\ var i: c_int = 0; | 2957 | \\ var i: c_int = 0; |
| 2958 | \\ _ = i; | ||
| 2784 | \\ while (a > @bitCast(c_uint, @as(c_int, 0))) { | 2959 | \\ while (a > @bitCast(c_uint, @as(c_int, 0))) { |
| 2785 | \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); | 2960 | \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); |
| 2786 | \\ } | 2961 | \\ } |
| ... | @@ -2808,7 +2983,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2808,7 +2983,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2808 | , &[_][]const u8{ | 2983 | , &[_][]const u8{ |
| 2809 | \\pub export fn foo() void { | 2984 | \\pub export fn foo() void { |
| 2810 | \\ var a: c_int = 0; | 2985 | \\ var a: c_int = 0; |
| 2986 | \\ _ = a; | ||
| 2811 | \\ var b: c_uint = 0; | 2987 | \\ var b: c_uint = 0; |
| 2988 | \\ _ = b; | ||
| 2812 | \\ a += blk: { | 2989 | \\ a += blk: { |
| 2813 | \\ const ref = &a; | 2990 | \\ const ref = &a; |
| 2814 | \\ ref.* += @as(c_int, 1); | 2991 | \\ ref.* += @as(c_int, 1); |
| ... | @@ -2887,6 +3064,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2887,6 +3064,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2887 | , &[_][]const u8{ | 3064 | , &[_][]const u8{ |
| 2888 | \\pub export fn foo() void { | 3065 | \\pub export fn foo() void { |
| 2889 | \\ var a: c_uint = 0; | 3066 | \\ var a: c_uint = 0; |
| 3067 | \\ _ = a; | ||
| 2890 | \\ a +%= blk: { | 3068 | \\ a +%= blk: { |
| 2891 | \\ const ref = &a; | 3069 | \\ const ref = &a; |
| 2892 | \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1)); | 3070 | \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1)); |
| ... | @@ -2946,7 +3124,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2946,7 +3124,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2946 | , &[_][]const u8{ | 3124 | , &[_][]const u8{ |
| 2947 | \\pub export fn foo() void { | 3125 | \\pub export fn foo() void { |
| 2948 | \\ var i: c_int = 0; | 3126 | \\ var i: c_int = 0; |
| 3127 | \\ _ = i; | ||
| 2949 | \\ var u: c_uint = 0; | 3128 | \\ var u: c_uint = 0; |
| 3129 | \\ _ = u; | ||
| 2950 | \\ i += 1; | 3130 | \\ i += 1; |
| 2951 | \\ i -= 1; | 3131 | \\ i -= 1; |
| 2952 | \\ u +%= 1; | 3132 | \\ u +%= 1; |
| ... | @@ -3041,6 +3221,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3041,6 +3221,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3041 | \\pub fn bar() callconv(.C) void {} | 3221 | \\pub fn bar() callconv(.C) void {} |
| 3042 | \\pub export fn foo(arg_baz: ?fn () callconv(.C) [*c]c_int) void { | 3222 | \\pub export fn foo(arg_baz: ?fn () callconv(.C) [*c]c_int) void { |
| 3043 | \\ var baz = arg_baz; | 3223 | \\ var baz = arg_baz; |
| 3224 | \\ _ = baz; | ||
| 3044 | \\ bar(); | 3225 | \\ bar(); |
| 3045 | \\ _ = baz.?(); | 3226 | \\ _ = baz.?(); |
| 3046 | \\} | 3227 | \\} |
| ... | @@ -3082,6 +3263,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3082,6 +3263,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3082 | \\#define BAZ (uint32_t)(2) | 3263 | \\#define BAZ (uint32_t)(2) |
| 3083 | , &[_][]const u8{ | 3264 | , &[_][]const u8{ |
| 3084 | \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*c_void, baz))) { | 3265 | \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*c_void, baz))) { |
| 3266 | \\ _ = bar; | ||
| 3085 | \\ return baz(@import("std").zig.c_translation.cast(?*c_void, baz)); | 3267 | \\ return baz(@import("std").zig.c_translation.cast(?*c_void, baz)); |
| 3086 | \\} | 3268 | \\} |
| 3087 | , | 3269 | , |
| ... | @@ -3122,10 +3304,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3122,10 +3304,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3122 | \\#define MAX(a, b) ((b) > (a) ? (b) : (a)) | 3304 | \\#define MAX(a, b) ((b) > (a) ? (b) : (a)) |
| 3123 | , &[_][]const u8{ | 3305 | , &[_][]const u8{ |
| 3124 | \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) { | 3306 | \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) { |
| 3307 | \\ _ = a; | ||
| 3308 | \\ _ = b; | ||
| 3125 | \\ return if (b < a) b else a; | 3309 | \\ return if (b < a) b else a; |
| 3126 | \\} | 3310 | \\} |
| 3127 | , | 3311 | , |
| 3128 | \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) { | 3312 | \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) { |
| 3313 | \\ _ = a; | ||
| 3314 | \\ _ = b; | ||
| 3129 | \\ return if (b > a) b else a; | 3315 | \\ return if (b > a) b else a; |
| 3130 | \\} | 3316 | \\} |
| 3131 | }); | 3317 | }); |
| ... | @@ -3137,7 +3323,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3137,7 +3323,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3137 | , &[_][]const u8{ | 3323 | , &[_][]const u8{ |
| 3138 | \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int { | 3324 | \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int { |
| 3139 | \\ var p = arg_p; | 3325 | \\ var p = arg_p; |
| 3326 | \\ _ = p; | ||
| 3140 | \\ var x = arg_x; | 3327 | \\ var x = arg_x; |
| 3328 | \\ _ = x; | ||
| 3141 | \\ return blk: { | 3329 | \\ return blk: { |
| 3142 | \\ const tmp = x; | 3330 | \\ const tmp = x; |
| 3143 | \\ (blk_1: { | 3331 | \\ (blk_1: { |
| ... | @@ -3164,6 +3352,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3164,6 +3352,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3164 | \\} | 3352 | \\} |
| 3165 | \\pub export fn bar(arg_x: c_long) c_ushort { | 3353 | \\pub export fn bar(arg_x: c_long) c_ushort { |
| 3166 | \\ var x = arg_x; | 3354 | \\ var x = arg_x; |
| 3355 | \\ _ = x; | ||
| 3167 | \\ return @bitCast(c_ushort, @truncate(c_short, x)); | 3356 | \\ return @bitCast(c_ushort, @truncate(c_short, x)); |
| 3168 | \\} | 3357 | \\} |
| 3169 | }); | 3358 | }); |
| ... | @@ -3176,6 +3365,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3176,6 +3365,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3176 | , &[_][]const u8{ | 3365 | , &[_][]const u8{ |
| 3177 | \\pub export fn foo(arg_bar_1: c_int) void { | 3366 | \\pub export fn foo(arg_bar_1: c_int) void { |
| 3178 | \\ var bar_1 = arg_bar_1; | 3367 | \\ var bar_1 = arg_bar_1; |
| 3368 | \\ _ = bar_1; | ||
| 3179 | \\ bar_1 = 2; | 3369 | \\ bar_1 = 2; |
| 3180 | \\} | 3370 | \\} |
| 3181 | \\pub export var bar: c_int = 4; | 3371 | \\pub export var bar: c_int = 4; |
| ... | @@ -3189,6 +3379,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3189,6 +3379,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3189 | , &[_][]const u8{ | 3379 | , &[_][]const u8{ |
| 3190 | \\pub export fn foo(arg_bar_1: c_int) void { | 3380 | \\pub export fn foo(arg_bar_1: c_int) void { |
| 3191 | \\ var bar_1 = arg_bar_1; | 3381 | \\ var bar_1 = arg_bar_1; |
| 3382 | \\ _ = bar_1; | ||
| 3192 | \\ bar_1 = 2; | 3383 | \\ bar_1 = 2; |
| 3193 | \\} | 3384 | \\} |
| 3194 | , | 3385 | , |
| ... | @@ -3218,13 +3409,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3218,13 +3409,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3218 | , &[_][]const u8{ | 3409 | , &[_][]const u8{ |
| 3219 | \\pub export fn foo(arg_a: [*c]c_int) void { | 3410 | \\pub export fn foo(arg_a: [*c]c_int) void { |
| 3220 | \\ var a = arg_a; | 3411 | \\ var a = arg_a; |
| 3412 | \\ _ = a; | ||
| 3221 | \\} | 3413 | \\} |
| 3222 | \\pub export fn bar(arg_a: [*c]const c_int) void { | 3414 | \\pub export fn bar(arg_a: [*c]const c_int) void { |
| 3223 | \\ var a = arg_a; | 3415 | \\ var a = arg_a; |
| 3416 | \\ _ = a; | ||
| 3224 | \\ foo(@intToPtr([*c]c_int, @ptrToInt(a))); | 3417 | \\ foo(@intToPtr([*c]c_int, @ptrToInt(a))); |
| 3225 | \\} | 3418 | \\} |
| 3226 | \\pub export fn baz(arg_a: [*c]volatile c_int) void { | 3419 | \\pub export fn baz(arg_a: [*c]volatile c_int) void { |
| 3227 | \\ var a = arg_a; | 3420 | \\ var a = arg_a; |
| 3421 | \\ _ = a; | ||
| 3228 | \\ foo(@intToPtr([*c]c_int, @ptrToInt(a))); | 3422 | \\ foo(@intToPtr([*c]c_int, @ptrToInt(a))); |
| 3229 | \\} | 3423 | \\} |
| 3230 | }); | 3424 | }); |
| ... | @@ -3239,9 +3433,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3239,9 +3433,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3239 | , &[_][]const u8{ | 3433 | , &[_][]const u8{ |
| 3240 | \\pub export fn foo(arg_x: bool) bool { | 3434 | \\pub export fn foo(arg_x: bool) bool { |
| 3241 | \\ var x = arg_x; | 3435 | \\ var x = arg_x; |
| 3436 | \\ _ = x; | ||
| 3242 | \\ var a: bool = @as(c_int, @boolToInt(x)) != @as(c_int, 1); | 3437 | \\ var a: bool = @as(c_int, @boolToInt(x)) != @as(c_int, 1); |
| 3438 | \\ _ = a; | ||
| 3243 | \\ var b: bool = @as(c_int, @boolToInt(a)) != @as(c_int, 0); | 3439 | \\ var b: bool = @as(c_int, @boolToInt(a)) != @as(c_int, 0); |
| 3440 | \\ _ = b; | ||
| 3244 | \\ var c: bool = @ptrToInt(foo) != 0; | 3441 | \\ var c: bool = @ptrToInt(foo) != 0; |
| 3442 | \\ _ = c; | ||
| 3245 | \\ return foo(@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b))); | 3443 | \\ return foo(@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b))); |
| 3246 | \\} | 3444 | \\} |
| 3247 | }); | 3445 | }); |
| ... | @@ -3252,7 +3450,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3252,7 +3450,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3252 | \\} | 3450 | \\} |
| 3253 | , &[_][]const u8{ | 3451 | , &[_][]const u8{ |
| 3254 | \\pub export fn max(x: c_int, arg_y: c_int) c_int { | 3452 | \\pub export fn max(x: c_int, arg_y: c_int) c_int { |
| 3453 | \\ _ = x; | ||
| 3255 | \\ var y = arg_y; | 3454 | \\ var y = arg_y; |
| 3455 | \\ _ = y; | ||
| 3256 | \\ return if (x > y) x else y; | 3456 | \\ return if (x > y) x else y; |
| 3257 | \\} | 3457 | \\} |
| 3258 | }); | 3458 | }); |
| ... | @@ -3313,6 +3513,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3313,6 +3513,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3313 | \\ | 3513 | \\ |
| 3314 | , &[_][]const u8{ | 3514 | , &[_][]const u8{ |
| 3315 | \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) { | 3515 | \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) { |
| 3516 | \\ _ = dpy; | ||
| 3316 | \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen; | 3517 | \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen; |
| 3317 | \\} | 3518 | \\} |
| 3318 | }); | 3519 | }); |
| ... | @@ -3532,6 +3733,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3532,6 +3733,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3532 | \\ const foo = struct { | 3733 | \\ const foo = struct { |
| 3533 | \\ var static: struct_FOO = @import("std").mem.zeroes(struct_FOO); | 3734 | \\ var static: struct_FOO = @import("std").mem.zeroes(struct_FOO); |
| 3534 | \\ }; | 3735 | \\ }; |
| 3736 | \\ _ = foo; | ||
| 3535 | \\ return foo.static.x; | 3737 | \\ return foo.static.x; |
| 3536 | \\} | 3738 | \\} |
| 3537 | }); | 3739 | }); |
| ... | @@ -3544,4 +3746,31 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3544,4 +3746,31 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3544 | \\pub const MAP_FAILED = @import("std").zig.c_translation.cast(?*c_void, -@as(c_int, 1)); | 3746 | \\pub const MAP_FAILED = @import("std").zig.c_translation.cast(?*c_void, -@as(c_int, 1)); |
| 3545 | \\pub const INVALID_HANDLE_VALUE = @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(LONG_PTR, -@as(c_int, 1))); | 3747 | \\pub const INVALID_HANDLE_VALUE = @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(LONG_PTR, -@as(c_int, 1))); |
| 3546 | }); | 3748 | }); |
| 3749 | |||
| 3750 | cases.add("discard local variables and function parameters", | ||
| 3751 | \\#define FOO(A, B) (A) + (B) | ||
| 3752 | \\int bar(int x, int y) { | ||
| 3753 | \\ return x; | ||
| 3754 | \\} | ||
| 3755 | , &[_][]const u8{ | ||
| 3756 | \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int { | ||
| 3757 | \\ var x = arg_x; | ||
| 3758 | \\ _ = x; | ||
| 3759 | \\ var y = arg_y; | ||
| 3760 | \\ _ = y; | ||
| 3761 | \\ return x; | ||
| 3762 | \\} | ||
| 3763 | , | ||
| 3764 | \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A + B) { | ||
| 3765 | \\ _ = A; | ||
| 3766 | \\ _ = B; | ||
| 3767 | \\ return A + B; | ||
| 3768 | \\} | ||
| 3769 | }); | ||
| 3770 | |||
| 3771 | cases.add("Don't allow underscore identifier in macros", | ||
| 3772 | \\#define FOO _ | ||
| 3773 | , &[_][]const u8{ | ||
| 3774 | \\pub const FOO = @compileError("unable to translate C expr: illegal identifier _"); | ||
| 3775 | }); | ||
| 3547 | } | 3776 | } |