Skip to content

fix(mir-importer): refuse device statics with a nested SharedArray or Barrier (#1727) - #1750

Open
arpanpathak wants to merge 1 commit into
NVIDIA:mainfrom
arpanpathak:fix/1727-nested-shared-statics
Open

arpanpathak wants to merge 1 commit into
NVIDIA:mainfrom
arpanpathak:fix/1727-nested-shared-statics

Conversation

@arpanpathak

Copy link
Copy Markdown
Contributor

A static like static mut WRAPPED: (Barrier, u32) was placed in global memory, but &raw mut WRAPPED.0 is a shared-memory pointer. The importer cast the global address to addrspace(3), which LLVM treats as undefined, and the PTX read an unassigned register. The build succeeded.

The importer now refuses such a static when it materializes the global, with:
device static `WRAPPED` contains a `Barrier` inside another type; shared-memory types are only supported as the whole type of a static.
The check walks only inline storage (struct and enum fields with generic arguments substituted, arrays, slices, tuples). It reuses the walker behind the nested-union check, which now takes a predicate.

Still accepted: static mut BAR: Barrier, static mut S: SharedArray<T, N>, pointer statics such as static mut P: *mut Barrier, and zero-sized markers like PhantomData<Barrier>.
Now refused as well: static mut BARS: [Barrier; 4]. It had the same bug, since &raw mut BARS[i] is also a shared-memory pointer into a global.

Tested: a new error_static_nested_shared fixture with the issue's reproducer, pinned in smoketest.sh and listed in STATUS.md. It fails the smoketest without this change and passes with it. cargo test -p mir-importer -p mir-lower passes. barrier, cluster and addressof_sharedarray still build.

Fixes #1727

… Barrier (NVIDIA#1727)

A static such as `static mut WRAPPED: (Barrier, u32)` was placed in global
memory while `&raw mut WRAPPED.0` is typed as a shared-memory pointer, so
the importer emitted an addrspace(1) -> addrspace(3) cast and the PTX read
an unassigned register. The build succeeded silently.

Refuse such a static where it is materialized as a global. The check walks
only inline storage (struct/enum fields with generic arguments substituted,
arrays, slices, tuples), reusing the nested-union walker, which now takes a
predicate. Whole-type `Barrier`/`SharedArray` statics, pointer statics such
as `*mut Barrier`, and `PhantomData<Barrier>` stay legal. `[Barrier; N]` is
now refused, since it had the same bug.

Add the `error_static_nested_shared` fixture, pinned in smoketest.sh and
listed in STATUS.md.

Signed-off-by: Arpan Pathak <arpan.pathak47@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@arpanpathak
arpanpathak marked this pull request as ready for review November 5, 2026 21:54

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mir-importer: shared-memory field of a wrapper static gets a global address

1 participant