Skip to content

Commit c828c23

Browse files
author
Andrea Orru
committedMar 14, 2018
Tests for zero-bit field compiler error
1 parent 7ac4403 commit c828c23

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
 

‎src/ir.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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
}

1 commit comments

Comments
 (1)

andrewrk commented on Mar 14, 2018

@andrewrk
Member

tests failed. if you don't want to run the tests, that's ok, make a pull request and the CI will run the tests, and then we can merge when they pass.

Please sign in to comment.