| author | |
| committer | |
| log | 057a5d4898f70c6a8169c99375fbb8631e539051 |
| tree | 92484c1a4c095811ddea19032e85fde82582f600 |
| parent | 5a57610039b6150557b159fe9a8eb30088455dba |
| signature |
* fix crash when doing field access of slice types. closes #2486
* remove the deprecated Child property from slice types
* add -Dskip-non-native build option to build script5 files changed, 26 insertions(+), 22 deletions(-)
build.zig+4-3| ... | @@ -71,6 +71,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -71,6 +71,7 @@ pub fn build(b: *Builder) !void { |
| 71 | const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release; | 71 | const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release; |
| 72 | const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release; | 72 | const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release; |
| 73 | const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release; | 73 | const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release; |
| 74 | const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false; | ||
| 74 | const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false; | 75 | const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false; |
| 75 | if (!skip_self_hosted) { | 76 | if (!skip_self_hosted) { |
| 76 | test_step.dependOn(&exe.step); | 77 | test_step.dependOn(&exe.step); |
| ... | @@ -115,11 +116,11 @@ pub fn build(b: *Builder) !void { | ... | @@ -115,11 +116,11 @@ pub fn build(b: *Builder) !void { |
| 115 | const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works"); | 116 | const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works"); |
| 116 | fmt_step.dependOn(&fmt_build_zig.step); | 117 | fmt_step.dependOn(&fmt_build_zig.step); |
| 117 | 118 | ||
| 118 | test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes)); | 119 | test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, skip_non_native)); |
| 119 | 120 | ||
| 120 | test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes)); | 121 | test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, skip_non_native)); |
| 121 | 122 | ||
| 122 | test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes)); | 123 | test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, skip_non_native)); |
| 123 | 124 | ||
| 124 | test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); | 125 | test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); |
| 125 | test_step.dependOn(tests.addBuildExampleTests(b, test_filter, modes)); | 126 | test_step.dependOn(tests.addBuildExampleTests(b, test_filter, modes)); |
src/ir.cpp+1-12| ... | @@ -16178,18 +16178,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -16178,18 +16178,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 16178 | 16178 | ||
| 16179 | if (type_is_invalid(child_type)) { | 16179 | if (type_is_invalid(child_type)) { |
| 16180 | return ira->codegen->invalid_instruction; | 16180 | return ira->codegen->invalid_instruction; |
| 16181 | } else if (is_container(child_type)) { | 16181 | } else if (is_container(child_type) && !is_slice(child_type)) { |
| 16182 | if (is_slice(child_type) && buf_eql_str(field_name, "Child")) { | ||
| 16183 | bool ptr_is_const = true; | ||
| 16184 | bool ptr_is_volatile = false; | ||
| 16185 | TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index]; | ||
| 16186 | assert(ptr_field->type_entry->id == ZigTypeIdPointer); | ||
| 16187 | ZigType *child_type = ptr_field->type_entry->data.pointer.child_type; | ||
| 16188 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, | ||
| 16189 | create_const_type(ira->codegen, child_type), | ||
| 16190 | ira->codegen->builtin_types.entry_type, | ||
| 16191 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); | ||
| 16192 | } | ||
| 16193 | if (child_type->id == ZigTypeIdEnum) { | 16182 | if (child_type->id == ZigTypeIdEnum) { |
| 16194 | if ((err = ensure_complete_type(ira->codegen, child_type))) | 16183 | if ((err = ensure_complete_type(ira->codegen, child_type))) |
| 16195 | return ira->codegen->invalid_instruction; | 16184 | return ira->codegen->invalid_instruction; |
test/compile_errors.zig+10| ... | @@ -2,6 +2,16 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,16 @@ const tests = @import("tests.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add( | ||
| 6 | "field access of slices", | ||
| 7 | \\export fn entry() void { | ||
| 8 | \\ var slice: []i32 = undefined; | ||
| 9 | \\ const info = @typeOf(slice).unknown; | ||
| 10 | \\} | ||
| 11 | , | ||
| 12 | "tmp.zig:3:32: error: type '[]i32' does not support field access", | ||
| 13 | ); | ||
| 14 | |||
| 5 | cases.add( | 15 | cases.add( |
| 6 | "peer cast then implicit cast const pointer to mutable C pointer", | 16 | "peer cast then implicit cast const pointer to mutable C pointer", |
| 7 | \\export fn func() void { | 17 | \\export fn func() void { |
test/stage1/behavior/slice.zig-6| ... | @@ -13,12 +13,6 @@ test "compile time slice of pointer to hard coded address" { | ... | @@ -13,12 +13,6 @@ test "compile time slice of pointer to hard coded address" { |
| 13 | expect(y.len == 0x400); | 13 | expect(y.len == 0x400); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | test "slice child property" { | ||
| 17 | var array: [5]i32 = undefined; | ||
| 18 | var slice = array[0..]; | ||
| 19 | expect(@typeOf(slice).Child == i32); | ||
| 20 | } | ||
| 21 | |||
| 22 | test "runtime safety lets us slice from len..len" { | 16 | test "runtime safety lets us slice from len..len" { |
| 23 | var an_array = []u8{ | 17 | var an_array = []u8{ |
| 24 | 1, | 18 | 1, |
test/tests.zig+11-1| ... | @@ -165,10 +165,20 @@ pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { | ... | @@ -165,10 +165,20 @@ pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 165 | return cases.step; | 165 | return cases.step; |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | pub fn addPkgTests(b: *build.Builder, test_filter: ?[]const u8, root_src: []const u8, name: []const u8, desc: []const u8, modes: []const Mode) *build.Step { | 168 | pub fn addPkgTests( |
| 169 | b: *build.Builder, | ||
| 170 | test_filter: ?[]const u8, | ||
| 171 | root_src: []const u8, | ||
| 172 | name: []const u8, | ||
| 173 | desc: []const u8, | ||
| 174 | modes: []const Mode, | ||
| 175 | skip_non_native: bool, | ||
| 176 | ) *build.Step { | ||
| 169 | const step = b.step(b.fmt("test-{}", name), desc); | 177 | const step = b.step(b.fmt("test-{}", name), desc); |
| 170 | for (test_targets) |test_target| { | 178 | for (test_targets) |test_target| { |
| 171 | const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch); | 179 | const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch); |
| 180 | if (skip_non_native and !is_native) | ||
| 181 | continue; | ||
| 172 | for (modes) |mode| { | 182 | for (modes) |mode| { |
| 173 | for ([]bool{ false, true }) |link_libc| { | 183 | for ([]bool{ false, true }) |link_libc| { |
| 174 | for ([]bool{ false, true }) |single_threaded| { | 184 | for ([]bool{ false, true }) |single_threaded| { |