Skip to content

Fix ICE when using zero-length SIMD type in extern static#151495

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
enthropy7:fix-simd-zero-length-extern-static
Jan 23, 2026
Merged

Fix ICE when using zero-length SIMD type in extern static#151495
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
enthropy7:fix-simd-zero-length-extern-static

Conversation

@enthropy7

@enthropy7 enthropy7 commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

before my fix using a zero-length SIMD type in an extern static would cause an internal compiler error. now it properly shows a diagnostic error instead of panicking. it was because LayoutError::InvalidSimd wasn't handled in check_static_inhabited and fell through to a generic delayed_bug.

i added handling for InvalidSimd in check_static_inhabited (similar to SizeOverflow): when a SIMD type has an invalid layout, we call emit_err with Spanned to emit a normal error instead of an ICE. compiler now emits a clear error "the SIMD type Simd<u8, 0> has zero elements" with the correct span on the type, matching expected compiler behavior.

fixes #151451

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 22, 2026
@rustbot

rustbot commented Jan 22, 2026

Copy link
Copy Markdown
Collaborator

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer


unsafe extern "C" {
static VAR: Simd<u8, 0>;
//~^ ERROR the SIMD type `Simd<u8, 0>` has zero elements

@JonathanBrouwer JonathanBrouwer Jan 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a testcase for SimdLayoutError::TooManyLanes?

So sth like static VAR2: Simd<u8, 1_000_000>;

Previously, using a zero-length SIMD type in an extern static would
cause an internal compiler error. Now it properly emits a diagnostic
error instead of panicking.
@enthropy7 enthropy7 force-pushed the fix-simd-zero-length-extern-static branch from 88734ae to b970366 Compare January 22, 2026 18:16
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors r+ rollup
Thanks!

@rust-bors

rust-bors Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b970366 has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Jan 22, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #151412 (diagnostics: suggest deriving Default for enums)
 - #151495 (Fix ICE when using zero-length SIMD type in extern static)
 - #151497 (Fix typo: 'recieve' -> 'receive' in lldb-visualizers.md)

r? @ghost
@rust-bors rust-bors Bot merged commit cbab2f0 into rust-lang:main Jan 23, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 23, 2026
rust-timer added a commit that referenced this pull request Jan 23, 2026
Rollup merge of #151495 - enthropy7:fix-simd-zero-length-extern-static, r=JonathanBrouwer

Fix ICE when using zero-length SIMD type in extern static

before my fix using a zero-length SIMD type in an extern static would cause an internal compiler error. now it properly shows a diagnostic error instead of panicking. it was because `LayoutError::InvalidSimd` wasn't handled in `check_static_inhabited` and fell through to a generic `delayed_bug`.

i added handling for `InvalidSimd` in `check_static_inhabited` (similar to `SizeOverflow`): when a SIMD type has an invalid layout, we call `emit_err` with `Spanned` to emit a normal error instead of an ICE. compiler now emits a clear error `"the SIMD type Simd<u8, 0> has zero elements"` with the correct span on the type, matching expected compiler behavior.

fixes #151451
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jan 26, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#151412 (diagnostics: suggest deriving Default for enums)
 - rust-lang/rust#151495 (Fix ICE when using zero-length SIMD type in extern static)
 - rust-lang/rust#151497 (Fix typo: 'recieve' -> 'receive' in lldb-visualizers.md)

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: internal compiler error: InvalidSimd { ty: Simd<u8, 0_usize>, kind: ZeroLength }

3 participants