| author | |
| committer | |
| log | aa6fc29744de4008e97faf0f54ccb52ebbdf5ca2 |
| tree | 1ac1a1a0c2630c57f0cb54115e29ba96fff22677 |
| parent | 01a927a0cbc068a2174124ec6fe224200849dd3e |
Using the gen_index rather than the src_index is needed to handle
structures containing zero-sized or comptime only types.
Closes #70273 files changed, 24 insertions(+), 3 deletions(-)
src/stage1/codegen.cpp+6-3| ... | @@ -6878,9 +6878,12 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren | ... | @@ -6878,9 +6878,12 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren |
| 6878 | render_const_val(g, val, ""); | 6878 | render_const_val(g, val, ""); |
| 6879 | render_const_val_global(g, val, ""); | 6879 | render_const_val_global(g, val, ""); |
| 6880 | return val->llvm_global; | 6880 | return val->llvm_global; |
| 6881 | case ConstParentIdStruct: | 6881 | case ConstParentIdStruct: { |
| 6882 | return gen_const_ptr_struct_recursive(g, parent->data.p_struct.struct_val, | 6882 | ZigValue *struct_val = parent->data.p_struct.struct_val; |
| 6883 | parent->data.p_struct.field_index); | 6883 | size_t src_field_index = parent->data.p_struct.field_index; |
| 6884 | size_t gen_field_index = struct_val->type->data.structure.fields[src_field_index]->gen_index; | ||
| 6885 | return gen_const_ptr_struct_recursive(g, struct_val, gen_field_index); | ||
| 6886 | } | ||
| 6884 | case ConstParentIdErrUnionCode: | 6887 | case ConstParentIdErrUnionCode: |
| 6885 | return gen_const_ptr_err_union_code_recursive(g, parent->data.p_err_union_code.err_union_val); | 6888 | return gen_const_ptr_err_union_code_recursive(g, parent->data.p_err_union_code.err_union_val); |
| 6886 | case ConstParentIdErrUnionPayload: | 6889 | case ConstParentIdErrUnionPayload: |
test/stage1/behavior.zig+1| ... | @@ -56,6 +56,7 @@ comptime { | ... | @@ -56,6 +56,7 @@ comptime { |
| 56 | _ = @import("behavior/bugs/6456.zig"); | 56 | _ = @import("behavior/bugs/6456.zig"); |
| 57 | _ = @import("behavior/bugs/6781.zig"); | 57 | _ = @import("behavior/bugs/6781.zig"); |
| 58 | _ = @import("behavior/bugs/6850.zig"); | 58 | _ = @import("behavior/bugs/6850.zig"); |
| 59 | _ = @import("behavior/bugs/7027.zig"); | ||
| 59 | _ = @import("behavior/bugs/7047.zig"); | 60 | _ = @import("behavior/bugs/7047.zig"); |
| 60 | _ = @import("behavior/bugs/394.zig"); | 61 | _ = @import("behavior/bugs/394.zig"); |
| 61 | _ = @import("behavior/bugs/421.zig"); | 62 | _ = @import("behavior/bugs/421.zig"); |
test/stage1/behavior/bugs/7027.zig created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | const Foobar = struct { | ||
| 2 | myTypes: [128]type, | ||
| 3 | str: [1024]u8, | ||
| 4 | |||
| 5 | fn foo() @This() { | ||
| 6 | comptime var foobar: Foobar = undefined; | ||
| 7 | foobar.str = [_]u8{'a'} ** 1024; | ||
| 8 | return foobar; | ||
| 9 | } | ||
| 10 | }; | ||
| 11 | |||
| 12 | fn foo(arg: anytype) void {} | ||
| 13 | |||
| 14 | test "" { | ||
| 15 | comptime var foobar = Foobar.foo(); | ||
| 16 | foo(foobar.str[0..10]); | ||
| 17 | } | ||