# Support taking extern pointers at comptime · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/d3ebd428650748e60db70dd2171cc044855814b1)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: d3ebd428650748e60db70dd2171cc044855814b1

Requested commit: d3ebd428650748e60db70dd2171cc044855814b1

Commit: d3ebd428650748e60db70dd2171cc044855814b1

Tree: 877fd512be87b46adf73c8143d0c721e9d9849c0

Author: yvt

Committer: Andrew Kelley

## Message

```
Support taking extern pointers at comptime

This commit makes it possible to obtain pointers to `extern` variables
at comptime.

 - `ir_get_var_ptr` employs several checks to determine if the given
   variable is eligible for obtaining its pointer at comptime. This
   commit alters these checks to consider `extern` variables, which have
   runtime values, as eligible.

 - After this change, it's now possible for `render_const_val` to be
   called for `extern` variables. This commit modifies
   `render_const_val` to suppress the value generation for `extern`
   variables.

 - `do_code_gen` now creates `ZigValue::llvm_global` of `extern`
   variables before iterating through module-level variables so that
   other module-level variables can refer to them.

This solution is incomplete since there are several cases still
failing:

 - `global_var.array[n..m]`
 - `&global_var.array[i]`
 - `&global_var.inner_struct.value`
 - `&global_array[i]`

Closes #5349

```

## Parents

- [3b26e508638e96997aff3d5ef2c42a917bf86cc8](https://git.cafe/gitcafe/zig/commit/3b26e508638e96997aff3d5ef2c42a917bf86cc8?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/d3ebd428650748e60db70dd2171cc044855814b1?format=markdown)
