aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-20 22:40:41 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-20 22:40:41 -0500
commit3ee9d06cbdb6bcaf561e7215c4c103c7ad65a72d (patch)
treec9f612c22c8e2d2e1191a5aab8fc2bfaebf4cfcd /src/codegen.cpp
parent079728752eca4cffbb4f7e8dc06d5e23b81d7627 (diff)
downloadzig-3ee9d06cbdb6bcaf561e7215c4c103c7ad65a72d.tar.gz
zig-3ee9d06cbdb6bcaf561e7215c4c103c7ad65a72d.zip
packed structs support comptime bitcasting
* `type_size_store` is no longer a thing. loading and storing a pointer to a value may dereference up to `@sizeOf(T)` bytes, even for integers such as `u24`. * fix `types_have_same_zig_comptime_repr` to not think that the same `ZigTypeId` means the `ConstExprValue` neccesarily has the same representation. * implement `buf_write_value_bytes` and `buf_read_value_bytes` for `ContainerLayoutPacked` closes #1120
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 86923a0bde..dbe0291299 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -3070,7 +3070,10 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
{
ZigType *wanted_type = instruction->base.value.type;
LLVMValueRef value = ir_llvm_value(g, instruction->value);
- return LLVMBuildBitCast(g->builder, value, wanted_type->type_ref, "");
+ // We either bitcast the value directly or bitcast the pointer which does a pointer cast
+ LLVMTypeRef wanted_type_ref = handle_is_ptr(wanted_type) ?
+ LLVMPointerType(wanted_type->type_ref, 0) : wanted_type->type_ref;
+ return LLVMBuildBitCast(g->builder, value, wanted_type_ref, "");
}
static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,