authorgravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-13 22:07:40-07:00
committergravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-13 22:07:40-07:00
logc828c23f71055fc4614ada20a20fb1c7bfee50c6
tree2c601b10869b3ea4ee287a44ae5bf37b08445569
parent7ac44037db686b93de25b6d826f596985d79ea42

Tests for zero-bit field compiler error


2 files changed, 14 insertions(+), 4 deletions(-)

src/ir.cpp+4-4
......@@ -15223,10 +15223,10 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
1522315223 }
1522415224
1522515225 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;
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;
1523015230 }
1523115231 size_t byte_offset = LLVMOffsetOfElement(ira->codegen->target_data_ref, container_type->type_ref, field->gen_index);
1523215232 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
test/compile_errors.zig+10
......@@ -3141,4 +3141,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31413141 \\}
31423142 ,
31433143 ".tmp_source.zig:4:9: error: type 'S' is not copyable; cannot pass by value");
3144
3145 cases.add("taking offset of void field in struct",
3146 \\const Empty = struct {
3147 \\ val: void,
3148 \\};
3149 \\export fn foo() void {
3150 \\ const fieldOffset = @offsetOf(Empty, "val");
3151 \\}
3152 ,
3153 ".tmp_source.zig:5:42: error: zero-bit field 'val' has no offset in struct 'Empty'");
31443154}