diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-09-02 13:17:42 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-09-02 17:57:10 +0300 |
| commit | 7a8d9af4a94caeb74361c9462cd44a1e4356150b (patch) | |
| tree | c1496557509bcd1aa9581e6541bfecd1374160dc /src/codegen | |
| parent | 4462d082240d71e671a8d3d5fb3da81e70c4760e (diff) | |
| download | zig-7a8d9af4a94caeb74361c9462cd44a1e4356150b.tar.gz zig-7a8d9af4a94caeb74361c9462cd44a1e4356150b.zip | |
stage2 llvm: correct handling of zero-bit types in unionFieldPtr
Pointers to zero-bit types are not zero-bit types so the function should
return something.
Closes #12716
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/llvm.zig | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 6c138df060..5f8d1539a6 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -9051,7 +9051,7 @@ pub const FuncGen = struct { } }, }, - .Union => return self.unionFieldPtr(inst, struct_ptr, struct_ty, field_index), + .Union => return self.unionFieldPtr(inst, struct_ptr, struct_ty), else => unreachable, } } @@ -9061,16 +9061,13 @@ pub const FuncGen = struct { inst: Air.Inst.Index, union_ptr: *const llvm.Value, union_ty: Type, - field_index: c_uint, ) !?*const llvm.Value { - const union_obj = union_ty.cast(Type.Payload.Union).?.data; - const field = &union_obj.fields.values()[field_index]; const result_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst)); - if (!field.ty.hasRuntimeBitsIgnoreComptime()) { - return null; - } const target = self.dg.module.getTarget(); const layout = union_ty.unionGetLayout(target); + if (layout.payload_size == 0) { + return self.builder.buildBitCast(union_ptr, result_llvm_ty, ""); + } const payload_index = @boolToInt(layout.tag_align >= layout.payload_align); const union_field_ptr = self.builder.buildStructGEP(union_ptr, payload_index, ""); return self.builder.buildBitCast(union_field_ptr, result_llvm_ty, ""); |
