diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-22 10:17:58 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-08-22 11:16:36 +0300 |
| commit | b0bcd4add29b6fbbe2bbc22719703d3c81ed594b (patch) | |
| tree | 8604903fa493cc8f9f328ffcefcd2bcea2f8b8bb /src/codegen | |
| parent | 74c7782c6083d398a4f0f126a4597c605d5223cd (diff) | |
| download | zig-b0bcd4add29b6fbbe2bbc22719703d3c81ed594b.tar.gz zig-b0bcd4add29b6fbbe2bbc22719703d3c81ed594b.zip | |
Sema: allow optional pointers in packed structs
Closes #12572
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/llvm.zig | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 5c537cd5bc..98458854d1 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -3417,7 +3417,10 @@ pub const DeclGen = struct { }); const ty_bit_size = @intCast(u16, field.ty.bitSize(target)); const small_int_ty = dg.context.intType(ty_bit_size); - const small_int_val = non_int_val.constBitCast(small_int_ty); + const small_int_val = if (field.ty.isPtrAtRuntime()) + non_int_val.constPtrToInt(small_int_ty) + else + non_int_val.constBitCast(small_int_ty); const shift_rhs = int_llvm_ty.constInt(running_bits, .False); // If the field is as large as the entire packed struct, this // zext would go from, e.g. i16 to i16. This is legal with @@ -5343,7 +5346,7 @@ pub const FuncGen = struct { const same_size_int = self.context.intType(elem_bits); const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, ""); return self.builder.buildBitCast(truncated_int, elem_llvm_ty, ""); - } else if (field_ty.zigTypeTag() == .Pointer) { + } else if (field_ty.isPtrAtRuntime()) { const elem_bits = @intCast(c_uint, field_ty.bitSize(target)); const same_size_int = self.context.intType(elem_bits); const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, ""); @@ -8408,7 +8411,7 @@ pub const FuncGen = struct { const non_int_val = try self.resolveInst(elem); const ty_bit_size = @intCast(u16, field.ty.bitSize(target)); const small_int_ty = self.dg.context.intType(ty_bit_size); - const small_int_val = if (field.ty.zigTypeTag() == .Pointer) + const small_int_val = if (field.ty.isPtrAtRuntime()) self.builder.buildPtrToInt(non_int_val, small_int_ty, "") else self.builder.buildBitCast(non_int_val, small_int_ty, ""); |
