| ... | @@ -2278,17 +2278,16 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) { | ... | @@ -2278,17 +2278,16 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) { |
| 2278 | return; | 2278 | return; |
| 2279 | | 2279 | |
| 2280 | if (struct_type->data.structure.zero_bits_loop_flag) { | 2280 | if (struct_type->data.structure.zero_bits_loop_flag) { |
| 2281 | // If we get here it's due to recursion. From this we conclude that the struct is | 2281 | // If we get here it's due to recursion. This is a design flaw in the compiler, |
| 2282 | // not zero bits, and if abi_alignment == 0 we further conclude that the first field | 2282 | // we should be able to still figure out alignment, but here we give up and say that |
| 2283 | // is a pointer to this very struct, or a function pointer with parameters that | 2283 | // the alignment is pointer width, then assert that the first field is within that |
| 2284 | // reference such a type. | 2284 | // alignment |
| 2285 | struct_type->data.structure.zero_bits_known = true; | 2285 | struct_type->data.structure.zero_bits_known = true; |
| 2286 | if (struct_type->data.structure.abi_alignment == 0) { | 2286 | if (struct_type->data.structure.abi_alignment == 0) { |
| 2287 | if (struct_type->data.structure.layout == ContainerLayoutPacked) { | 2287 | if (struct_type->data.structure.layout == ContainerLayoutPacked) { |
| 2288 | struct_type->data.structure.abi_alignment = 1; | 2288 | struct_type->data.structure.abi_alignment = 1; |
| 2289 | } else { | 2289 | } else { |
| 2290 | struct_type->data.structure.abi_alignment = LLVMABIAlignmentOfType(g->target_data_ref, | 2290 | struct_type->data.structure.abi_alignment = LLVMABIAlignmentOfType(g->target_data_ref, LLVMPointerType(LLVMInt8Type(), 0)); |
| 2291 | LLVMPointerType(LLVMInt8Type(), 0)); | | |
| 2292 | } | 2291 | } |
| 2293 | } | 2292 | } |
| 2294 | return; | 2293 | return; |
| ... | @@ -2352,11 +2351,17 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) { | ... | @@ -2352,11 +2351,17 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) { |
| 2352 | if (gen_field_index == 0) { | 2351 | if (gen_field_index == 0) { |
| 2353 | if (struct_type->data.structure.layout == ContainerLayoutPacked) { | 2352 | if (struct_type->data.structure.layout == ContainerLayoutPacked) { |
| 2354 | struct_type->data.structure.abi_alignment = 1; | 2353 | struct_type->data.structure.abi_alignment = 1; |
| 2355 | } else { | 2354 | } else if (struct_type->data.structure.abi_alignment == 0) { |
| 2356 | // Alignment of structs is the alignment of the first field, for now. | 2355 | // Alignment of structs is the alignment of the first field, for now. |
| 2357 | // TODO change this when we re-order struct fields (issue #168) | 2356 | // TODO change this when we re-order struct fields (issue #168) |
| 2358 | struct_type->data.structure.abi_alignment = get_abi_alignment(g, field_type); | 2357 | struct_type->data.structure.abi_alignment = get_abi_alignment(g, field_type); |
| 2359 | assert(struct_type->data.structure.abi_alignment != 0); | 2358 | assert(struct_type->data.structure.abi_alignment != 0); |
| | 2359 | } else { |
| | 2360 | // due to a design flaw in the compiler we assumed that alignment was |
| | 2361 | // pointer width, so we assert that this wasn't violated. |
| | 2362 | if (get_abi_alignment(g, field_type) > struct_type->data.structure.abi_alignment) { |
| | 2363 | zig_panic("compiler design flaw: incorrect alignment assumption"); |
| | 2364 | } |
| 2360 | } | 2365 | } |
| 2361 | } | 2366 | } |
| 2362 | | 2367 | |