| ... | ... | @@ -1131,17 +1131,26 @@ Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent |
| 1131 | 1131 | Error err; |
| 1132 | 1132 | if (type_val->special != ConstValSpecialLazy) { |
| 1133 | 1133 | assert(type_val->special == ConstValSpecialStatic); |
| 1134 | | if ((type_val->data.x_type->id == ZigTypeIdStruct && |
| 1135 | | type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) || |
| 1136 | | (type_val->data.x_type->id == ZigTypeIdUnion && |
| 1137 | | type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits)) |
| 1134 | |
| 1135 | // Self-referencing types via pointers are allowed and have non-zero size |
| 1136 | ZigType *ty = type_val->data.x_type; |
| 1137 | while (ty->id == ZigTypeIdPointer && |
| 1138 | !ty->data.unionation.resolve_loop_flag_zero_bits) |
| 1139 | { |
| 1140 | ty = ty->data.pointer.child_type; |
| 1141 | } |
| 1142 | |
| 1143 | if ((ty->id == ZigTypeIdStruct && ty->data.structure.resolve_loop_flag_zero_bits) || |
| 1144 | (ty->id == ZigTypeIdUnion && ty->data.unionation.resolve_loop_flag_zero_bits) || |
| 1145 | (ty->id == ZigTypeIdPointer && ty->data.pointer.resolve_loop_flag_zero_bits)) |
| 1138 | 1146 | { |
| 1139 | | // Does a struct/union which contains a pointer field to itself have bits? Yes. |
| 1140 | 1147 | *is_zero_bits = false; |
| 1141 | 1148 | return ErrorNone; |
| 1142 | 1149 | } |
| 1150 | |
| 1143 | 1151 | if ((err = type_resolve(g, type_val->data.x_type, ResolveStatusZeroBitsKnown))) |
| 1144 | 1152 | return err; |
| 1153 | |
| 1145 | 1154 | *is_zero_bits = (type_val->data.x_type->abi_size == 0); |
| 1146 | 1155 | return ErrorNone; |
| 1147 | 1156 | } |