aboutsummaryrefslogtreecommitdiff
path: root/src/stage1
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-10-16 21:25:42 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-10-16 21:25:42 -0700
commit6850e54cc02ddf067d3c85d0f75afb1013df0d34 (patch)
tree23b09d503fe6384286bee704d3ddf7486cde976f /src/stage1
parent79ef96b6a4af3fff751d5d7ad679634643c4fc6e (diff)
parent2545f44db0ce3e88dc9c59a9cbb18e67e02cc1e4 (diff)
downloadzig-6850e54cc02ddf067d3c85d0f75afb1013df0d34.tar.gz
zig-6850e54cc02ddf067d3c85d0f75afb1013df0d34.zip
Merge branch 'vegecode-byteOffsetOf_fix'
closes #5713
Diffstat (limited to 'src/stage1')
-rw-r--r--src/stage1/ir.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp
index dc74fb9c14..ea9bf6ee8b 100644
--- a/src/stage1/ir.cpp
+++ b/src/stage1/ir.cpp
@@ -24646,7 +24646,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type);
}
-static TypeStructField *validate_byte_offset(IrAnalyze *ira,
+static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira,
IrInstGen *type_value,
IrInstGen *field_name_value,
size_t *byte_offset)
@@ -24694,11 +24694,12 @@ static IrInstGen *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstSr
return ira->codegen->invalid_inst_gen;
IrInstGen *field_name_value = instruction->field_name->child;
- size_t byte_offset = 0;
- if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset))
+ size_t host_int_byte_offset = 0;
+ TypeStructField *field = nullptr;
+ if (!(field = validate_host_int_byte_offset(ira, type_value, field_name_value, &host_int_byte_offset)))
return ira->codegen->invalid_inst_gen;
-
+ size_t byte_offset = host_int_byte_offset + (field->bit_offset_in_host / 8);
return ir_const_unsigned(ira, &instruction->base.base, byte_offset);
}
@@ -24707,12 +24708,12 @@ static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrc
if (type_is_invalid(type_value->value->type))
return ira->codegen->invalid_inst_gen;
IrInstGen *field_name_value = instruction->field_name->child;
- size_t byte_offset = 0;
+ size_t host_int_byte_offset = 0;
TypeStructField *field = nullptr;
- if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset)))
+ if (!(field = validate_host_int_byte_offset(ira, type_value, field_name_value, &host_int_byte_offset)))
return ira->codegen->invalid_inst_gen;
- size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host;
+ size_t bit_offset = host_int_byte_offset * 8 + field->bit_offset_in_host;
return ir_const_unsigned(ira, &instruction->base.base, bit_offset);
}