Skip to content

Anonymous allocations in statics get duplicated for multiple codegen units #79738

Closed
@RalfJung

Description

@RalfJung

According to analysis performed by @bjorn3, this code actually leads to two allocations containing 42, i.e., FOO and BAR point to different things. The linker later merges the two, so the issue is currently not directly observable. However, it becomes observable when things are mutable.

I think this is a bug. When a static is defined as pub static BAR: &i32 = crate::a::FOO;, IMO we should guarantee that BAR and FOO have the same value. I see no lee-way here for duplicating the memory they both point to.

Cc @oli-obk

Metadata

Metadata

Assignees

Labels

A-codegenArea: Code generationA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions