aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 95b2c77129..41ae69f803 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -1131,18 +1131,26 @@ Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent
Error err;
if (type_val->special != ConstValSpecialLazy) {
assert(type_val->special == ConstValSpecialStatic);
- if ((type_val->data.x_type->id == ZigTypeIdStruct &&
- type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||
- (type_val->data.x_type->id == ZigTypeIdUnion &&
- type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits) ||
- type_val->data.x_type->id == ZigTypeIdPointer)
+
+ // Self-referencing types via pointers are allowed and have non-zero size
+ ZigType *ty = type_val->data.x_type;
+ while (ty->id == ZigTypeIdPointer &&
+ !ty->data.unionation.resolve_loop_flag_zero_bits)
+ {
+ ty = ty->data.pointer.child_type;
+ }
+
+ if ((ty->id == ZigTypeIdStruct && ty->data.structure.resolve_loop_flag_zero_bits) ||
+ (ty->id == ZigTypeIdUnion && ty->data.unionation.resolve_loop_flag_zero_bits) ||
+ (ty->id == ZigTypeIdPointer && ty->data.pointer.resolve_loop_flag_zero_bits))
{
- // Does a struct/union which contains a pointer field to itself have bits? Yes.
*is_zero_bits = false;
return ErrorNone;
}
+
if ((err = type_resolve(g, type_val->data.x_type, ResolveStatusZeroBitsKnown)))
return err;
+
*is_zero_bits = (type_val->data.x_type->abi_size == 0);
return ErrorNone;
}