diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-02-26 10:05:04 +0100 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-02-26 10:05:04 +0100 |
| commit | d2535c003c6188fcc362028e01ef9f7fb3356727 (patch) | |
| tree | d6cb0c35e9d541af21ce2ed015e6f2b33a29c9c7 /src/analyze.cpp | |
| parent | b46efcde82436e73c73dab132f73aeff98673894 (diff) | |
| download | zig-d2535c003c6188fcc362028e01ef9f7fb3356727.tar.gz zig-d2535c003c6188fcc362028e01ef9f7fb3356727.zip | |
ir: Fix regression with self-referencing containers
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 5ee5f44643..41ae69f803 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1131,17 +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)) + + // 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; } |
