Skip to content

Commit b892636

Browse files
committed
Explain why we retroactively change a static initializer to have a different type
1 parent 5e55679 commit b892636

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: compiler/rustc_codegen_llvm/src/consts.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,14 @@ impl<'ll> CodegenCx<'ll, '_> {
384384
let g = if val_llty == llty {
385385
g
386386
} else {
387-
// If we created the global with the wrong type,
388-
// correct the type.
387+
// codegen_static_initializer creates the global value just from the
388+
// `Allocation` data by generating one big struct value that is just
389+
// all the bytes and pointers after each other. This will almost never
390+
// match the type that the static was declared with. Unfortunately
391+
// we can't just LLVMConstBitCast our way out of it because that has very
392+
// specific rules on what can be cast. So instead of adding a new way to
393+
// generate static initializers that match the static's type, we picked
394+
// the easier option and retroactively change the type of the static item itself.
389395
let name = llvm::get_value_name(g).to_vec();
390396
llvm::set_value_name(g, b"");
391397

0 commit comments

Comments
 (0)