| author | |
| committer | |
| log | 0543def52f5ec2d76dc415da2546e478af491ac3 |
| tree | cd08fe58ac0bf9f030a9f079ad5dff2ab1d0f002 |
| parent | ff97bd21c3b6a5079f33ff389da0716a12806e29 |
The result of buildStructGEP is not always a GEP (sorry), so we can't
use getGEPResultElementType on it.
Closes #146415 files changed, 14 insertions(+), 12 deletions(-)
src/codegen/llvm.zig+3-3| ... | @@ -5558,7 +5558,7 @@ pub const FuncGen = struct { | ... | @@ -5558,7 +5558,7 @@ pub const FuncGen = struct { |
| 5558 | 5558 | ||
| 5559 | return fg.loadByRef(payload_ptr, payload_ty, payload_ty.abiAlignment(target), false); | 5559 | return fg.loadByRef(payload_ptr, payload_ty, payload_ty.abiAlignment(target), false); |
| 5560 | } | 5560 | } |
| 5561 | const load_inst = fg.builder.buildLoad(payload_ptr.getGEPResultElementType(), payload_ptr, ""); | 5561 | const load_inst = fg.builder.buildLoad(err_union_llvm_ty.structGetTypeAtIndex(offset), payload_ptr, ""); |
| 5562 | load_inst.setAlignment(payload_ty.abiAlignment(target)); | 5562 | load_inst.setAlignment(payload_ty.abiAlignment(target)); |
| 5563 | return load_inst; | 5563 | return load_inst; |
| 5564 | } | 5564 | } |
| ... | @@ -6792,7 +6792,7 @@ pub const FuncGen = struct { | ... | @@ -6792,7 +6792,7 @@ pub const FuncGen = struct { |
| 6792 | 6792 | ||
| 6793 | return self.loadByRef(payload_ptr, payload_ty, payload_ty.abiAlignment(target), false); | 6793 | return self.loadByRef(payload_ptr, payload_ty, payload_ty.abiAlignment(target), false); |
| 6794 | } | 6794 | } |
| 6795 | const load_inst = self.builder.buildLoad(payload_ptr.getGEPResultElementType(), payload_ptr, ""); | 6795 | const load_inst = self.builder.buildLoad(err_union_llvm_ty.structGetTypeAtIndex(offset), payload_ptr, ""); |
| 6796 | load_inst.setAlignment(payload_ty.abiAlignment(target)); | 6796 | load_inst.setAlignment(payload_ty.abiAlignment(target)); |
| 6797 | return load_inst; | 6797 | return load_inst; |
| 6798 | } | 6798 | } |
| ... | @@ -8580,7 +8580,7 @@ pub const FuncGen = struct { | ... | @@ -8580,7 +8580,7 @@ pub const FuncGen = struct { |
| 8580 | } | 8580 | } |
| 8581 | const tag_index = @boolToInt(layout.tag_align < layout.payload_align); | 8581 | const tag_index = @boolToInt(layout.tag_align < layout.payload_align); |
| 8582 | const tag_field_ptr = self.builder.buildStructGEP(llvm_un_ty, union_handle, tag_index, ""); | 8582 | const tag_field_ptr = self.builder.buildStructGEP(llvm_un_ty, union_handle, tag_index, ""); |
| 8583 | return self.builder.buildLoad(tag_field_ptr.getGEPResultElementType(), tag_field_ptr, ""); | 8583 | return self.builder.buildLoad(llvm_un_ty.structGetTypeAtIndex(tag_index), tag_field_ptr, ""); |
| 8584 | } else { | 8584 | } else { |
| 8585 | if (layout.payload_size == 0) { | 8585 | if (layout.payload_size == 0) { |
| 8586 | return union_handle; | 8586 | return union_handle; |
src/codegen/llvm/bindings.zig-3| ... | @@ -254,9 +254,6 @@ pub const Value = opaque { | ... | @@ -254,9 +254,6 @@ pub const Value = opaque { |
| 254 | pub const addFunctionAttr = ZigLLVMAddFunctionAttr; | 254 | pub const addFunctionAttr = ZigLLVMAddFunctionAttr; |
| 255 | extern fn ZigLLVMAddFunctionAttr(Fn: *Value, attr_name: [*:0]const u8, attr_value: [*:0]const u8) void; | 255 | extern fn ZigLLVMAddFunctionAttr(Fn: *Value, attr_name: [*:0]const u8, attr_value: [*:0]const u8) void; |
| 256 | 256 | ||
| 257 | pub const getGEPResultElementType = ZigLLVMGetGEPResultElementType; | ||
| 258 | extern fn ZigLLVMGetGEPResultElementType(GEP: *Value) *Type; | ||
| 259 | |||
| 260 | pub const addByValAttr = ZigLLVMAddByValAttr; | 257 | pub const addByValAttr = ZigLLVMAddByValAttr; |
| 261 | extern fn ZigLLVMAddByValAttr(Fn: *Value, ArgNo: c_uint, type: *Type) void; | 258 | extern fn ZigLLVMAddByValAttr(Fn: *Value, ArgNo: c_uint, type: *Type) void; |
| 262 | }; | 259 | }; |
src/zig_llvm.cpp-4| ... | @@ -1239,10 +1239,6 @@ void ZigLLVMSetCallElemTypeAttr(LLVMValueRef Call, size_t arg_index, LLVMTypeRef | ... | @@ -1239,10 +1239,6 @@ void ZigLLVMSetCallElemTypeAttr(LLVMValueRef Call, size_t arg_index, LLVMTypeRef |
| 1239 | Attribute::get(call_inst->getContext(), Attribute::ElementType, llvm_type)); | 1239 | Attribute::get(call_inst->getContext(), Attribute::ElementType, llvm_type)); |
| 1240 | } | 1240 | } |
| 1241 | 1241 | ||
| 1242 | LLVMTypeRef ZigLLVMGetGEPResultElementType(LLVMValueRef GEP) { | ||
| 1243 | return wrap(unwrap<GEPOperator>(GEP)->getResultElementType()); | ||
| 1244 | } | ||
| 1245 | |||
| 1246 | void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) { | 1242 | void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) { |
| 1247 | unwrap<Function>(function)->setPrefixData(unwrap<Constant>(data)); | 1243 | unwrap<Function>(function)->setPrefixData(unwrap<Constant>(data)); |
| 1248 | } | 1244 | } |
src/zig_llvm.h-2| ... | @@ -332,8 +332,6 @@ ZIG_EXTERN_C void ZigLLVMAddSretAttr(LLVMValueRef fn_ref, LLVMTypeRef type_val); | ... | @@ -332,8 +332,6 @@ ZIG_EXTERN_C void ZigLLVMAddSretAttr(LLVMValueRef fn_ref, LLVMTypeRef type_val); |
| 332 | ZIG_EXTERN_C void ZigLLVMAddFunctionElemTypeAttr(LLVMValueRef fn_ref, size_t arg_index, LLVMTypeRef elem_ty); | 332 | ZIG_EXTERN_C void ZigLLVMAddFunctionElemTypeAttr(LLVMValueRef fn_ref, size_t arg_index, LLVMTypeRef elem_ty); |
| 333 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); | 333 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); |
| 334 | 334 | ||
| 335 | ZIG_EXTERN_C LLVMTypeRef ZigLLVMGetGEPResultElementType(LLVMValueRef GEP); | ||
| 336 | |||
| 337 | ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv); | 335 | ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv); |
| 338 | 336 | ||
| 339 | 337 |
test/behavior/union.zig+11| ... | @@ -1529,3 +1529,14 @@ test "reinterpreting enum value inside packed union" { | ... | @@ -1529,3 +1529,14 @@ test "reinterpreting enum value inside packed union" { |
| 1529 | try U.doTest(); | 1529 | try U.doTest(); |
| 1530 | comptime try U.doTest(); | 1530 | comptime try U.doTest(); |
| 1531 | } | 1531 | } |
| 1532 | |||
| 1533 | test "access the tag of a global tagged union" { | ||
| 1534 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1535 | |||
| 1536 | const U = union(enum) { | ||
| 1537 | a, | ||
| 1538 | b: u8, | ||
| 1539 | var u: @This() = .a; | ||
| 1540 | }; | ||
| 1541 | try expect(U.u == .a); | ||
| 1542 | } |