| ... | @@ -6355,12 +6355,17 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un | ... | @@ -6355,12 +6355,17 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un |
| 6355 | ConstParent *parent = &union_const_val->parent; | 6355 | ConstParent *parent = &union_const_val->parent; |
| 6356 | LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent); | 6356 | LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent); |
| 6357 | | 6357 | |
| | 6358 | // Slot in the structure where the payload is stored, if equal to SIZE_MAX |
| | 6359 | // the union has no tag and a single field and is collapsed into the field |
| | 6360 | // itself |
| | 6361 | size_t union_payload_index = union_const_val->type->data.unionation.gen_union_index; |
| | 6362 | |
| 6358 | ZigType *u32 = g->builtin_types.entry_u32; | 6363 | ZigType *u32 = g->builtin_types.entry_u32; |
| 6359 | LLVMValueRef indices[] = { | 6364 | LLVMValueRef indices[] = { |
| 6360 | LLVMConstNull(get_llvm_type(g, u32)), | 6365 | LLVMConstNull(get_llvm_type(g, u32)), |
| 6361 | LLVMConstInt(get_llvm_type(g, u32), 0, false), // TODO test const union with more aligned tag type than payload | 6366 | LLVMConstInt(get_llvm_type(g, u32), union_payload_index, false), |
| 6362 | }; | 6367 | }; |
| 6363 | return LLVMConstInBoundsGEP(base_ptr, indices, 2); | 6368 | return LLVMConstInBoundsGEP(base_ptr, indices, (union_payload_index != SIZE_MAX) ? 2 : 1); |
| 6364 | } | 6369 | } |
| 6365 | | 6370 | |
| 6366 | static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, ConstExprValue *const_val) { | 6371 | static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, ConstExprValue *const_val) { |