| ... | ... | @@ -3705,12 +3705,24 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar |
| 3705 | 3705 | ConstParent *parent = &array_const_val->data.x_array.s_none.parent; |
| 3706 | 3706 | LLVMValueRef base_ptr = gen_parent_ptr(g, array_const_val, parent); |
| 3707 | 3707 | |
| 3708 | | TypeTableEntry *usize = g->builtin_types.entry_usize; |
| 3709 | | LLVMValueRef indices[] = { |
| 3710 | | LLVMConstNull(usize->type_ref), |
| 3711 | | LLVMConstInt(usize->type_ref, index, false), |
| 3712 | | }; |
| 3713 | | return LLVMConstInBoundsGEP(base_ptr, indices, 2); |
| 3708 | LLVMTypeKind el_type = LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(base_ptr))); |
| 3709 | if (el_type == LLVMArrayTypeKind) { |
| 3710 | TypeTableEntry *usize = g->builtin_types.entry_usize; |
| 3711 | LLVMValueRef indices[] = { |
| 3712 | LLVMConstNull(usize->type_ref), |
| 3713 | LLVMConstInt(usize->type_ref, index, false), |
| 3714 | }; |
| 3715 | return LLVMConstInBoundsGEP(base_ptr, indices, 2); |
| 3716 | } else if (el_type == LLVMStructTypeKind) { |
| 3717 | TypeTableEntry *u32 = g->builtin_types.entry_u32; |
| 3718 | LLVMValueRef indices[] = { |
| 3719 | LLVMConstNull(u32->type_ref), |
| 3720 | LLVMConstInt(u32->type_ref, index, false), |
| 3721 | }; |
| 3722 | return LLVMConstInBoundsGEP(base_ptr, indices, 2); |
| 3723 | } else { |
| 3724 | zig_unreachable(); |
| 3725 | } |
| 3714 | 3726 | } |
| 3715 | 3727 | |
| 3716 | 3728 | static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index) { |
| ... | ... | @@ -3732,7 +3744,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un |
| 3732 | 3744 | TypeTableEntry *u32 = g->builtin_types.entry_u32; |
| 3733 | 3745 | LLVMValueRef indices[] = { |
| 3734 | 3746 | LLVMConstNull(u32->type_ref), |
| 3735 | | LLVMConstInt(u32->type_ref, 0, false), |
| 3747 | LLVMConstInt(u32->type_ref, 0, false), // TODO test const union with more aligned tag type than payload |
| 3736 | 3748 | }; |
| 3737 | 3749 | return LLVMConstInBoundsGEP(base_ptr, indices, 2); |
| 3738 | 3750 | } |