authorgravatar for kjs@scheibo.comKirk Scheibelhut <kjs@scheibo.com> 2021-11-20 14:31:18-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-22 21:33:08-05:00
log065f40a3c5886c9087a4b752c014459bb1dac9ba
tree93175e084209089ed28bef9f15d7222d58f73153
parented70f9981c0f164aab586261cd5363e04905bc42

stage1: improve packed struct array padding error message


2 files changed, 6 insertions(+), 5 deletions(-)

src/stage1/analyze.cpp+5-4
...@@ -1777,11 +1777,12 @@ static Error emit_error_unless_type_allowed_in_packed_container(CodeGen *g, ZigT...@@ -1777,11 +1777,12 @@ static Error emit_error_unless_type_allowed_in_packed_container(CodeGen *g, ZigT
1777 if ((err = emit_error_unless_type_allowed_in_packed_container(g, elem_type, source_node, container_name)))1777 if ((err = emit_error_unless_type_allowed_in_packed_container(g, elem_type, source_node, container_name)))
1778 return err;1778 return err;
1779 // TODO revisit this when doing https://github.com/ziglang/zig/issues/15121779 // TODO revisit this when doing https://github.com/ziglang/zig/issues/1512
1780 if (type_size(g, type_entry) * 8 == type_size_bits(g, type_entry))1780 size_t abi_size_in_bits = type_size(g, type_entry) * 8;
1781 return ErrorNone;1781 size_t size_in_bits = type_size_bits(g, type_entry);
1782 if (abi_size_in_bits == size_in_bits) return ErrorNone;
1782 add_node_error(g, source_node,1783 add_node_error(g, source_node,
1783 buf_sprintf("array of '%s' not allowed in packed %s due to padding bits",1784 buf_sprintf("array of '%s' not allowed in packed %s due to padding bits (must be padded from %zu to %zu bits)",
1784 buf_ptr(&elem_type->name), container_name));1785 buf_ptr(&elem_type->name), container_name, size_in_bits, abi_size_in_bits));
1785 return ErrorSemanticAnalyzeFail;1786 return ErrorSemanticAnalyzeFail;
1786 }1787 }
1787 case ZigTypeIdStruct:1788 case ZigTypeIdStruct:
test/compile_errors.zig+1-1
...@@ -2995,7 +2995,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -2995,7 +2995,7 @@ pub fn addCases(ctx: *TestContext) !void {
2995 \\};2995 \\};
2996 , &[_][]const u8{2996 , &[_][]const u8{
2997 "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",2997 "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
2998 "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits",2998 "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits)",
2999 "tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",2999 "tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
3000 "tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation",3000 "tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation",
3001 "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",3001 "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",