| author | |
| committer | |
| log | 7062c8a8865bbd2fb8181b579da552295cd68e6a |
| tree | afa5a38081c75c63599a1642a78266b347b1b5fd |
| parent | 0942bf73c90eabf87d0ca965b50beb0fd9a8fc8c |
3 files changed, 19 insertions(+), 1 deletions(-)
src/Sema.zig+6-1| ... | @@ -8001,7 +8001,12 @@ fn analyzePtrArithmetic( | ... | @@ -8001,7 +8001,12 @@ fn analyzePtrArithmetic( |
| 8001 | const offset_int = offset_val.toUnsignedInt(); | 8001 | const offset_int = offset_val.toUnsignedInt(); |
| 8002 | if (ptr_val.getUnsignedInt()) |addr| { | 8002 | if (ptr_val.getUnsignedInt()) |addr| { |
| 8003 | const target = sema.mod.getTarget(); | 8003 | const target = sema.mod.getTarget(); |
| 8004 | const elem_ty = ptr_ty.childType(); | 8004 | const ptr_child_ty = ptr_ty.childType(); |
| 8005 | const elem_ty = if (ptr_ty.isSinglePointer() and ptr_child_ty.zigTypeTag() == .Array) | ||
| 8006 | ptr_child_ty.childType() | ||
| 8007 | else | ||
| 8008 | ptr_child_ty; | ||
| 8009 | |||
| 8005 | const elem_size = elem_ty.abiSize(target); | 8010 | const elem_size = elem_ty.abiSize(target); |
| 8006 | const new_addr = switch (air_tag) { | 8011 | const new_addr = switch (air_tag) { |
| 8007 | .ptr_add => addr + elem_size * offset_int, | 8012 | .ptr_add => addr + elem_size * offset_int, |
test/behavior.zig+1| ... | @@ -65,6 +65,7 @@ test { | ... | @@ -65,6 +65,7 @@ test { |
| 65 | if (builtin.zig_is_stage2) { | 65 | if (builtin.zig_is_stage2) { |
| 66 | // When all comptime_memory.zig tests pass, #9646 can be closed. | 66 | // When all comptime_memory.zig tests pass, #9646 can be closed. |
| 67 | // _ = @import("behavior/comptime_memory.zig"); | 67 | // _ = @import("behavior/comptime_memory.zig"); |
| 68 | _ = @import("behavior/slice_stage2.zig"); | ||
| 68 | } else { | 69 | } else { |
| 69 | _ = @import("behavior/align_stage1.zig"); | 70 | _ = @import("behavior/align_stage1.zig"); |
| 70 | _ = @import("behavior/alignof.zig"); | 71 | _ = @import("behavior/alignof.zig"); |
test/behavior/slice_stage2.zig created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | |||
| 4 | const x = @intToPtr([*]i32, 0x1000)[0..0x500]; | ||
| 5 | const y = x[0x100..]; | ||
| 6 | test "compile time slice of pointer to hard coded address" { | ||
| 7 | try expect(@ptrToInt(x) == 0x1000); | ||
| 8 | try expect(x.len == 0x500); | ||
| 9 | |||
| 10 | try expect(@ptrToInt(y) == 0x1400); | ||
| 11 | try expect(y.len == 0x400); | ||
| 12 | } | ||