# avoid needlessly creating global constants · gitcafe/zig

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

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

Visibility: public

Requested revision: 7a8f391b0fa397eea4a9602a0132e0247d0f67b7

Requested commit: 7a8f391b0fa397eea4a9602a0132e0247d0f67b7

Commit: 7a8f391b0fa397eea4a9602a0132e0247d0f67b7

Tree: bec959df7cd42b36bea7ab80c93bda4283eee155

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

````
avoid needlessly creating global constants

This deletes some legacy cruft, and produces leaner object files.
Example:

```
var x: i32 = 1234;

export fn entry() i32 {
    return x;
}
```

This produces:

```
@x = internal unnamed_addr global i32 1234, align 4
@0 = internal unnamed_addr constant i32* @x, align 8
```

and @0 is never even used. After this commit, @0 is not produced.

This fixes a bug: Zig was creating invalid LLVM IR when one of these
globals that shouldn't exist takes the address of a thread local
variable. In LLVM 8.0.0rc2, it would produce a linker error. But
probably after my bug report is solved it will be caught by the IR
verifier.

https://bugs.llvm.org/show_bug.cgi?id=40652

````

## Parents

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

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