Skip to content

Fix crash when scalarizing OOB access - #8942

Open
Chris B (llvm-beanz) wants to merge 6 commits into
microsoft:mainfrom
llvm-beanz:sroa-crash
Open

Chris B (llvm-beanz) wants to merge 6 commits into
microsoft:mainfrom
llvm-beanz:sroa-crash

Conversation

@llvm-beanz

@llvm-beanz Chris B (llvm-beanz) commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

The SROA HLSL pass misses checking that a GEP index is inbounds, which can cause an OOB memory access.

This is not the complete fix for #8940, but it addresses the optimizer crash.

Assisted-by: GitHub Copilot

The SROA HLSL pass misses checking that a GEP index is inbounds, which
can cause an OOB memory access.

This is not the complete fix for microsoft#8940, but it addresses the optimizer
crash.

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

Out-of-bounds accesses to scalarized internal globals can still trigger the same crash.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Adds vector-index bounds validation to prevent SROA crashes.

Changes:

  • Rejects out-of-range constant vector indices during local-allocation scalarization.
  • Adds regression coverage for valid, negative, nested, and oversized indices.
  • Documents the optimizer crash fix.
File Description
lib/​Transforms/​Scalar/​ScalarReplAggregatesHLSL.cpp Validates constant vector indices.
tools/​clang/​test/​DXC/​Passes/​ScalarReplHLSL/​vector-index-bounds.ll Adds regression tests.
docs/​ReleaseNotes.md Records the bug fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp Outdated
Copilot AI review requested due to automatic review settings September 22, 2026 15:32

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The targeted bounds check correctly prevents unsafe scalarization and is supported by focused regression coverage.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Copilot AI review requested due to automatic review settings September 22, 2026 16:36

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The bounds checks cover both local and global scalarization paths with focused regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 22, 2026 18:16

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

The bounds validation can still accept negative indices, risking miscompilation or out-of-bounds failure.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Comment thread lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp Outdated
Copilot AI review requested due to automatic review settings September 22, 2026 19:52

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

Critical and moderate index-validation defects must be fixed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment on lines +1370 to +1371
if (GEPIt->isVectorTy() && IdxVal && !isValidVectorIndex(IdxVal, arraySize))
return MarkUnsafe(Info, GEPI);
Copilot AI review requested due to automatic review settings September 22, 2026 19:58

Copilot AI left a comment

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.

Copilot review overview

🔵 Needs a closer look

The bounds check misses the relevant vector index, and the global path lacks effective regression coverage.

Review effort: Balanced
Findings: 1 High severity

Open (1)

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

Status: New

Development

Successfully merging this pull request may close these issues.

4 participants