mirror of
https://github.com/ziglang/zig.git
synced 2025-12-24 07:03:11 +00:00
stage2: elem vals of many pointers need not deref pointers
By the time zirElemVal is reached for a many pointer, a load has already happened, making sure the operand is already dereferenced. This makes `mem.sliceTo` now work.
This commit is contained in:
parent
6ffa44554e
commit
55ccf4c7a8
@ -15629,15 +15629,13 @@ fn elemVal(
|
|||||||
return block.addBinOp(.slice_elem_val, array, elem_index);
|
return block.addBinOp(.slice_elem_val, array, elem_index);
|
||||||
},
|
},
|
||||||
.Many, .C => {
|
.Many, .C => {
|
||||||
const maybe_ptr_val = try sema.resolveDefinedValue(block, array_src, array);
|
const maybe_array_val = try sema.resolveDefinedValue(block, array_src, array);
|
||||||
const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
|
const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
|
||||||
|
|
||||||
const runtime_src = rs: {
|
const runtime_src = rs: {
|
||||||
const ptr_val = maybe_ptr_val orelse break :rs array_src;
|
const array_val = maybe_array_val orelse break :rs array_src;
|
||||||
const index_val = maybe_index_val orelse break :rs elem_index_src;
|
const index_val = maybe_index_val orelse break :rs elem_index_src;
|
||||||
const index = @intCast(usize, index_val.toUnsignedInt());
|
const index = @intCast(usize, index_val.toUnsignedInt());
|
||||||
const maybe_array_val = try sema.pointerDeref(block, array_src, ptr_val, array_ty);
|
|
||||||
const array_val = maybe_array_val orelse break :rs array_src;
|
|
||||||
const elem_val = try array_val.elemValue(sema.arena, index);
|
const elem_val = try array_val.elemValue(sema.arena, index);
|
||||||
return sema.addConstant(array_ty.elemType2(), elem_val);
|
return sema.addConstant(array_ty.elemType2(), elem_val);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -521,7 +521,11 @@ fn testCastPtrOfArrayToSliceAndPtr() !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
|
test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
|
||||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
const window_name = [1][*]const u8{"window name"};
|
const window_name = [1][*]const u8{"window name"};
|
||||||
const x: [*]const ?[*]const u8 = &window_name;
|
const x: [*]const ?[*]const u8 = &window_name;
|
||||||
|
|||||||
@ -279,7 +279,11 @@ test "array initialization types" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "null terminated pointer" {
|
test "null terminated pointer" {
|
||||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
const S = struct {
|
const S = struct {
|
||||||
fn doTheTest() !void {
|
fn doTheTest() !void {
|
||||||
@ -295,7 +299,11 @@ test "null terminated pointer" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "allow any sentinel" {
|
test "allow any sentinel" {
|
||||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
const S = struct {
|
const S = struct {
|
||||||
fn doTheTest() !void {
|
fn doTheTest() !void {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user