# avoid needlessly creating global constants · gitcafe/zig

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

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

Visibility: public

Requested revision: 8e68d43ad373e643797209d59e6f10aa12b4c038

Requested commit: 8e68d43ad373e643797209d59e6f10aa12b4c038

Commit: 8e68d43ad373e643797209d59e6f10aa12b4c038

Tree: e2f3995a2f4db98e1a6b093d905defb2827cdcc0

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

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

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