diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-15 17:17:59 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-15 17:17:59 -0700 |
| commit | 186126c2a4032424e1b1cdb8ac379fb2beab7429 (patch) | |
| tree | 32aa04aa0e19f7a9b4d51677c2051a3b7d7048c4 /src/type.zig | |
| parent | 0536c25578fa15e2326eb1061f6db61d6ad3cd65 (diff) | |
| download | zig-186126c2a4032424e1b1cdb8ac379fb2beab7429.tar.gz zig-186126c2a4032424e1b1cdb8ac379fb2beab7429.zip | |
stage2: make hasCodeGenBits() always true for pointers
* LLVM backend: The `alloc` AIR instruction as well as pointer
constants which point to a 0-bit element type now call a common
codepath to produce a `*const llvm.Value` which is a non-zero pointer
with a bogus-but-properly-aligned address.
* LLVM backend: improve the lowering of optional types.
* Type: `hasCodeGenBits()` now returns `true` for pointers even when
it returns `false` for their element types.
Effectively, #6706 is now implemented in stage2 but not stage1.
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/type.zig b/src/type.zig index 9ddeb507af..a37a3bfc03 100644 --- a/src/type.zig +++ b/src/type.zig @@ -1420,6 +1420,15 @@ pub const Type = extern union { .@"anyframe", .anyframe_T, .@"opaque", + .single_const_pointer, + .single_mut_pointer, + .many_const_pointer, + .many_mut_pointer, + .c_const_pointer, + .c_mut_pointer, + .const_slice, + .mut_slice, + .pointer, => true, .function => !self.castTag(.function).?.data.is_generic, @@ -1480,17 +1489,7 @@ pub const Type = extern union { .array, .vector => self.elemType().hasCodeGenBits() and self.arrayLen() != 0, .array_u8 => self.arrayLen() != 0, - .array_sentinel, - .single_const_pointer, - .single_mut_pointer, - .many_const_pointer, - .many_mut_pointer, - .c_const_pointer, - .c_mut_pointer, - .const_slice, - .mut_slice, - .pointer, - => self.childType().hasCodeGenBits(), + .array_sentinel => self.childType().hasCodeGenBits(), .int_signed, .int_unsigned => self.cast(Payload.Bits).?.data != 0, @@ -2370,7 +2369,7 @@ pub const Type = extern union { .optional => { var buf: Payload.ElemType = undefined; const child_type = self.optionalChild(&buf); - // optionals of zero sized pointers behave like bools + // optionals of zero sized types behave like bools, not pointers if (!child_type.hasCodeGenBits()) return false; if (child_type.zigTypeTag() != .Pointer) return false; |
