slice types no longer have field access
* 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 script
This commit is contained in:
parent
5a57610039
commit
057a5d4898
@ -71,6 +71,7 @@ pub fn build(b: *Builder) !void {
|
||||
const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
|
||||
const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;
|
||||
const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;
|
||||
const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;
|
||||
const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false;
|
||||
if (!skip_self_hosted) {
|
||||
test_step.dependOn(&exe.step);
|
||||
@ -115,11 +116,11 @@ pub fn build(b: *Builder) !void {
|
||||
const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
|
||||
fmt_step.dependOn(&fmt_build_zig.step);
|
||||
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes));
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, skip_non_native));
|
||||
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes));
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, skip_non_native));
|
||||
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes));
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, skip_non_native));
|
||||
|
||||
test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
|
||||
test_step.dependOn(tests.addBuildExampleTests(b, test_filter, modes));
|
||||
|
13
src/ir.cpp
13
src/ir.cpp
@ -16178,18 +16178,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
|
||||
|
||||
if (type_is_invalid(child_type)) {
|
||||
return ira->codegen->invalid_instruction;
|
||||
} else if (is_container(child_type)) {
|
||||
if (is_slice(child_type) && buf_eql_str(field_name, "Child")) {
|
||||
bool ptr_is_const = true;
|
||||
bool ptr_is_volatile = false;
|
||||
TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index];
|
||||
assert(ptr_field->type_entry->id == ZigTypeIdPointer);
|
||||
ZigType *child_type = ptr_field->type_entry->data.pointer.child_type;
|
||||
return ir_get_const_ptr(ira, &field_ptr_instruction->base,
|
||||
create_const_type(ira->codegen, child_type),
|
||||
ira->codegen->builtin_types.entry_type,
|
||||
ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
|
||||
}
|
||||
} else if (is_container(child_type) && !is_slice(child_type)) {
|
||||
if (child_type->id == ZigTypeIdEnum) {
|
||||
if ((err = ensure_complete_type(ira->codegen, child_type)))
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
@ -2,6 +2,16 @@ const tests = @import("tests.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"field access of slices",
|
||||
\\export fn entry() void {
|
||||
\\ var slice: []i32 = undefined;
|
||||
\\ const info = @typeOf(slice).unknown;
|
||||
\\}
|
||||
,
|
||||
"tmp.zig:3:32: error: type '[]i32' does not support field access",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"peer cast then implicit cast const pointer to mutable C pointer",
|
||||
\\export fn func() void {
|
||||
|
@ -13,12 +13,6 @@ test "compile time slice of pointer to hard coded address" {
|
||||
expect(y.len == 0x400);
|
||||
}
|
||||
|
||||
test "slice child property" {
|
||||
var array: [5]i32 = undefined;
|
||||
var slice = array[0..];
|
||||
expect(@typeOf(slice).Child == i32);
|
||||
}
|
||||
|
||||
test "runtime safety lets us slice from len..len" {
|
||||
var an_array = []u8{
|
||||
1,
|
||||
|
@ -165,10 +165,20 @@ pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
||||
return cases.step;
|
||||
}
|
||||
|
||||
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 {
|
||||
pub fn addPkgTests(
|
||||
b: *build.Builder,
|
||||
test_filter: ?[]const u8,
|
||||
root_src: []const u8,
|
||||
name: []const u8,
|
||||
desc: []const u8,
|
||||
modes: []const Mode,
|
||||
skip_non_native: bool,
|
||||
) *build.Step {
|
||||
const step = b.step(b.fmt("test-{}", name), desc);
|
||||
for (test_targets) |test_target| {
|
||||
const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
|
||||
if (skip_non_native and !is_native)
|
||||
continue;
|
||||
for (modes) |mode| {
|
||||
for ([]bool{ false, true }) |link_libc| {
|
||||
for ([]bool{ false, true }) |single_threaded| {
|
||||
|
Loading…
x
Reference in New Issue
Block a user