diff options
| author | LemonBoy <LemonBoy@users.noreply.github.com> | 2020-04-23 18:44:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-23 12:44:16 -0400 |
| commit | e6428f94013132b6a6284b053afb36d35af63c59 (patch) | |
| tree | 86275c7d4d6c0729a0905e4e9e2abca1371f1fed /src/codegen.cpp | |
| parent | 58d5c37409a7fc7fea2d6c536bf53c0193c5266a (diff) | |
| download | zig-e6428f94013132b6a6284b053afb36d35af63c59.tar.gz zig-e6428f94013132b6a6284b053afb36d35af63c59.zip | |
stage1: Fix bitcast of immediate to ptr type (#5131)
Consider a (legal according to the `@bitCast` rules) conversion from u16
to [2]u8: since the former is a scalar and the latter is a pointer
(arrays are represented at pointers in the codegen phase) we have to
allocate a temporary slot on the stack and then bitcast the resulting
pointer to the desired destination type.
Beware that this means the lifetime of the resulting value is the same
of the function it's contained in and for all intents and purposes
should be regarded as a local (eg. it should not escape).
Closes #4395
Closes #5121
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 730f2695e0..87881ccaf3 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3331,12 +3331,16 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable, LLVMPointerType(get_llvm_type(g, wanted_type), 0) : get_llvm_type(g, wanted_type); return LLVMBuildBitCast(g->builder, value, wanted_type_ref, ""); } else if (actual_is_ptr) { + // A scalar is wanted but we got a pointer LLVMTypeRef wanted_ptr_type_ref = LLVMPointerType(get_llvm_type(g, wanted_type), 0); LLVMValueRef bitcasted_ptr = LLVMBuildBitCast(g->builder, value, wanted_ptr_type_ref, ""); uint32_t alignment = get_abi_alignment(g, actual_type); return gen_load_untyped(g, bitcasted_ptr, alignment, false, ""); } else { - zig_unreachable(); + // A pointer is wanted but we got a scalar + assert(actual_type->id == ZigTypeIdPointer); + LLVMTypeRef wanted_ptr_type_ref = LLVMPointerType(get_llvm_type(g, wanted_type), 0); + return LLVMBuildBitCast(g->builder, value, wanted_ptr_type_ref, ""); } } |
