authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-28 00:29:20-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-28 00:29:20-05:00
log6568be575cb87c2f54aad2dfa20d1f35471d2224
tree88d5964a4281f5c814717023024676539576751d
parent0f449a3ec180f710f8b54023d2c3b3dffcce5ec8
parent556f22a751e47d572404992befe15c09c0f2eb0b

Merge branch 'bnoordhuis-fix795'


2 files changed, 15 insertions(+), 1 deletions(-)

src/analyze.cpp+3-1
...@@ -997,7 +997,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -997,7 +997,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
997 gen_param_info->src_index = i;997 gen_param_info->src_index = i;
998 gen_param_info->gen_index = SIZE_MAX;998 gen_param_info->gen_index = SIZE_MAX;
999999
1000 ensure_complete_type(g, type_entry);1000 type_ensure_zero_bits_known(g, type_entry);
1001 if (type_has_bits(type_entry)) {1001 if (type_has_bits(type_entry)) {
1002 TypeTableEntry *gen_type;1002 TypeTableEntry *gen_type;
1003 if (handle_is_ptr(type_entry)) {1003 if (handle_is_ptr(type_entry)) {
...@@ -2129,6 +2129,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {...@@ -2129,6 +2129,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
21292129
2130 if (enum_type->data.enumeration.zero_bits_loop_flag) {2130 if (enum_type->data.enumeration.zero_bits_loop_flag) {
2131 enum_type->data.enumeration.zero_bits_known = true;2131 enum_type->data.enumeration.zero_bits_known = true;
2132 enum_type->data.enumeration.zero_bits_loop_flag = false;
2132 return;2133 return;
2133 }2134 }
21342135
...@@ -2283,6 +2284,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {...@@ -2283,6 +2284,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
2283 // the alignment is pointer width, then assert that the first field is within that2284 // the alignment is pointer width, then assert that the first field is within that
2284 // alignment2285 // alignment
2285 struct_type->data.structure.zero_bits_known = true;2286 struct_type->data.structure.zero_bits_known = true;
2287 struct_type->data.structure.zero_bits_loop_flag = false;
2286 if (struct_type->data.structure.abi_alignment == 0) {2288 if (struct_type->data.structure.abi_alignment == 0) {
2287 if (struct_type->data.structure.layout == ContainerLayoutPacked) {2289 if (struct_type->data.structure.layout == ContainerLayoutPacked) {
2288 struct_type->data.structure.abi_alignment = 1;2290 struct_type->data.structure.abi_alignment = 1;
test/compile_errors.zig+12
...@@ -3090,4 +3090,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3090,4 +3090,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3090 ,3090 ,
3091 ".tmp_source.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",3091 ".tmp_source.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",
3092 ".tmp_source.zig:3:5: note: field 'A' has type 'i32'");3092 ".tmp_source.zig:3:5: note: field 'A' has type 'i32'");
3093
3094 cases.add("self-referencing function pointer field",
3095 \\const S = struct {
3096 \\ f: fn(_: S) void,
3097 \\};
3098 \\fn f(_: S) void {
3099 \\}
3100 \\export fn entry() void {
3101 \\ var _ = S { .f = f };
3102 \\}
3103 ,
3104 ".tmp_source.zig:4:9: error: type 'S' is not copyable; cannot pass by value");
3093}3105}