| author | |
| committer | |
| log | cb0e22db4e18dd803e1edd681c836fadbae0ea6f |
| tree | 0377d1540686d1e34998a171abb3a7f7ce53ca5e |
| parent | feab1ebe1bfea3955320a6acba69f0c6c79c0730 |
When we want a runtime pointer to a zero-bit value we use an undef
pointer, but what if we want a runtime pointer to a comptime-only value?
Normally, if `T` is a comptime-only type such as `*const comptime_int`,
then `*const T` would also be a comptime-only type, so anything
referencing a comptime-only value is usually also comptime-only, and
therefore not emitted to the executable.
However, what if instead we have a `*const anyopaque` pointing to a
comptime-only value? Certainly, `*const anyopaque` is a runtime type,
and so we need some runtime value to store, even when it happens to be
pointing to a comptime-only value. In this case we want to do the same
thing as we do when pointing to a zero-bit value, so we use
`hasRuntimeBits` to handle both cases instead of ignoring comptime.
Closes #120253 files changed, 12 insertions(+), 1 deletions(-)
src/codegen/llvm.zig+1-1| ... | ... | @@ -4077,7 +4077,7 @@ pub const DeclGen = struct { |
| 4077 | 4077 | } |
| 4078 | 4078 | |
| 4079 | 4079 | const is_fn_body = decl.ty.zigTypeTag() == .Fn; |
| 4080 | if (!is_fn_body and !decl.ty.hasRuntimeBitsIgnoreComptime()) { | |
| 4080 | if (!is_fn_body and !decl.ty.hasRuntimeBits()) { | |
| 4081 | 4081 | return self.lowerPtrToVoid(tv.ty); |
| 4082 | 4082 | } |
| 4083 | 4083 |
test/behavior.zig+1| ... | ... | @@ -83,6 +83,7 @@ test { |
| 83 | 83 | _ = @import("behavior/bugs/11213.zig"); |
| 84 | 84 | _ = @import("behavior/bugs/11816.zig"); |
| 85 | 85 | _ = @import("behavior/bugs/12003.zig"); |
| 86 | _ = @import("behavior/bugs/12025.zig"); | |
| 86 | 87 | _ = @import("behavior/bugs/12033.zig"); |
| 87 | 88 | _ = @import("behavior/bugs/12430.zig"); |
| 88 | 89 | _ = @import("behavior/bugs/12486.zig"); |
test/behavior/bugs/12025.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | test { | |
| 2 | comptime var st = .{ | |
| 3 | .foo = &1, | |
| 4 | .bar = &2, | |
| 5 | }; | |
| 6 | ||
| 7 | inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { | |
| 8 | _ = field; | |
| 9 | } | |
| 10 | } |