aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-02-26 11:11:28 -0500
committerGitHub <noreply@github.com>2020-02-26 11:11:28 -0500
commitc4a2734aa08a9e810680d7be2c976fe3ae67cc5b (patch)
tree762fb4fe3e6a334f8845c0fb5ccffd685b65ebcb /src/analyze.cpp
parentaa2aad229c96427f8b9130a3665a1f6ad768ec4c (diff)
parentd2535c003c6188fcc362028e01ef9f7fb3356727 (diff)
downloadzig-c4a2734aa08a9e810680d7be2c976fe3ae67cc5b.tar.gz
zig-c4a2734aa08a9e810680d7be2c976fe3ae67cc5b.zip
Merge pull request #4561 from LemonBoy/fix-4536-1
Resend of #4552
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;
}