Skip to content

llvm: fix lowering of runtime refs to comptime-only decls#13166

Merged
andrewrk merged 1 commit intoziglang:masterfrom
jacobly0:ref-to-comptime
Oct 15, 2022
Merged

llvm: fix lowering of runtime refs to comptime-only decls#13166
andrewrk merged 1 commit intoziglang:masterfrom
jacobly0:ref-to-comptime

Conversation

@jacobly0
Copy link
Member

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 #12025

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 ziglang#12025
@andrewrk andrewrk merged commit cb0e22d into ziglang:master Oct 15, 2022
@jacobly0 jacobly0 deleted the ref-to-comptime branch October 16, 2022 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stage2 LLVM: module fails to validate due to uninitialized global

2 participants