aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-06-12 13:49:57 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-06-12 13:49:57 -0400
commit35352e0f489882b9d5919ffd569e7dcda990f39b (patch)
treea4eba9b0275509a44d7b3fb5f919cbbbdb836920 /src/ir.cpp
parent278c7a2bc398ac71afc9b9b392e863a758abb5fd (diff)
downloadzig-35352e0f489882b9d5919ffd569e7dcda990f39b.tar.gz
zig-35352e0f489882b9d5919ffd569e7dcda990f39b.zip
fix alignment problem with `@bitCast` result location
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index acf9e0ca00..d0ad7f944c 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -14812,6 +14812,7 @@ static bool type_can_bit_cast(ZigType *t) {
static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
ResultLoc *result_loc, ZigType *value_type, IrInstruction *value)
{
+ Error err;
if (result_loc->resolved_loc != nullptr) {
// allow to redo the result location if the value is known and comptime and the previous one isn't
if (value == nullptr || !instr_is_comptime(value) || instr_is_comptime(result_loc->resolved_loc)) {
@@ -14962,7 +14963,18 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
{
return parent_result_loc;
}
- ZigType *ptr_type = get_pointer_to_type(ira->codegen, value_type, false);
+ ZigType *parent_ptr_type = parent_result_loc->value.type;
+ assert(parent_ptr_type->id == ZigTypeIdPointer);
+ if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
+ ResolveStatusAlignmentKnown)))
+ {
+ return ira->codegen->invalid_instruction;
+ }
+ uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
+ parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
+ parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
+
result_loc->written = true;
result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
ptr_type, result_bit_cast->base.source_instruction, false);