From c828c23f71055fc4614ada20a20fb1c7bfee50c6 Mon Sep 17 00:00:00 2001 From: Andrea Orru Date: Tue, 13 Mar 2018 22:07:40 -0700 Subject: [PATCH] Tests for zero-bit field compiler error --- src/ir.cpp | 8 ++++---- test/compile_errors.zig | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index 797e58f991..51a538db59 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15223,10 +15223,10 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, } if (field->type_entry->zero_bits) { - ir_add_error(ira, field_name_value, - buf_sprintf("zero-bit field '%s' in struct '%s' has no offset", - buf_ptr(field_name), buf_ptr(&container_type->name))); - return ira->codegen->builtin_types.entry_invalid; + ir_add_error(ira, field_name_value, + buf_sprintf("zero-bit field '%s' in struct '%s' has no offset", + buf_ptr(field_name), buf_ptr(&container_type->name))); + return ira->codegen->builtin_types.entry_invalid; } size_t byte_offset = LLVMOffsetOfElement(ira->codegen->target_data_ref, container_type->type_ref, field->gen_index); ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 564ad5d521..027e000953 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -3141,4 +3141,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) void { \\} , ".tmp_source.zig:4:9: error: type 'S' is not copyable; cannot pass by value"); + + cases.add("taking offset of void field in struct", + \\const Empty = struct { + \\ val: void, + \\}; + \\export fn foo() void { + \\ const fieldOffset = @offsetOf(Empty, "val"); + \\} + , + ".tmp_source.zig:5:42: error: zero-bit field 'val' has no offset in struct 'Empty'"); }