aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-02-22 00:54:11 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-02-22 00:58:31 -0500
commit786677f80cf7fb34ad8ab45768b910296f9c34cf (patch)
treeff2b3a517fb53a80df27fe7230a52550b8927d64 /src/codegen.cpp
parentd794549985fc9a3fd6d6b1620be15d290f6a759f (diff)
downloadzig-786677f80cf7fb34ad8ab45768b910296f9c34cf.tar.gz
zig-786677f80cf7fb34ad8ab45768b910296f9c34cf.zip
fix regression with bit fields that align properly
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 5d98b22ab8..8fec6a4c51 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -1473,19 +1473,20 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
if (canon_child_type->id == TypeTableEntryIdStruct &&
canon_child_type->data.structure.layout == ContainerLayoutPacked)
{
- LLVMTypeRef ptr_u8_type_ref = LLVMPointerType(LLVMInt8Type(), 0);
- LLVMValueRef u8_array_ptr = LLVMBuildBitCast(g->builder, array_ptr, ptr_u8_type_ref, "");
size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count;
- assert(unaligned_bit_count != 0);
- assert(unaligned_bit_count % 8 == 0);
- LLVMValueRef elem_size_bytes = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
- unaligned_bit_count / 8, false);
- LLVMValueRef byte_offset = LLVMBuildNUWMul(g->builder, subscript_value, elem_size_bytes, "");
- LLVMValueRef indices[] = {
- byte_offset
- };
- LLVMValueRef elem_byte_ptr = LLVMBuildInBoundsGEP(g->builder, u8_array_ptr, indices, 1, "");
- return LLVMBuildBitCast(g->builder, elem_byte_ptr, LLVMPointerType(canon_child_type->type_ref, 0), "");
+ if (unaligned_bit_count != 0) {
+ LLVMTypeRef ptr_u8_type_ref = LLVMPointerType(LLVMInt8Type(), 0);
+ LLVMValueRef u8_array_ptr = LLVMBuildBitCast(g->builder, array_ptr, ptr_u8_type_ref, "");
+ assert(unaligned_bit_count % 8 == 0);
+ LLVMValueRef elem_size_bytes = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
+ unaligned_bit_count / 8, false);
+ LLVMValueRef byte_offset = LLVMBuildNUWMul(g->builder, subscript_value, elem_size_bytes, "");
+ LLVMValueRef indices[] = {
+ byte_offset
+ };
+ LLVMValueRef elem_byte_ptr = LLVMBuildInBoundsGEP(g->builder, u8_array_ptr, indices, 1, "");
+ return LLVMBuildBitCast(g->builder, elem_byte_ptr, LLVMPointerType(canon_child_type->type_ref, 0), "");
+ }
}
LLVMValueRef indices[] = {
LLVMConstNull(g->builtin_types.entry_usize->type_ref),