Skip to content

Commit 7ac4403

Browse files
author
Andrea Orru
committedMar 14, 2018
Compiler error when taking @offsetof of void struct member
closes #739
1 parent 2a6ad23 commit 7ac4403

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed
 

‎src/ir.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -15222,6 +15222,12 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
1522215222
return ira->codegen->builtin_types.entry_invalid;
1522315223
}
1522415224

15225+
if (field->type_entry->zero_bits) {
15226+
ir_add_error(ira, field_name_value,
15227+
buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
15228+
buf_ptr(field_name), buf_ptr(&container_type->name)));
15229+
return ira->codegen->builtin_types.entry_invalid;
15230+
}
1522515231
size_t byte_offset = LLVMOffsetOfElement(ira->codegen->target_data_ref, container_type->type_ref, field->gen_index);
1522615232
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1522715233
bigint_init_unsigned(&out_val->data.x_bigint, byte_offset);

1 commit comments

Comments
 (1)

andrewrk commented on Mar 14, 2018

@andrewrk
Member

can you add a test to test/compile_errors.zig ?

Please sign in to comment.