Skip to content

Fix crash when heap subscript result is discarded - #8749

Open
Chris B (llvm-beanz) wants to merge 3 commits into
microsoft:mainfrom
llvm-beanz:crash-unused-heap-resource
Open

Fix crash when heap subscript result is discarded#8749
Chris B (llvm-beanz) wants to merge 3 commits into
microsoft:mainfrom
llvm-beanz:crash-unused-heap-resource

Conversation

@llvm-beanz

Copy link
Copy Markdown
Collaborator

Without this change DXC crashes if the result of a descriptor heap subscript is discarded. The crash is caused by not correctly handling lifetime marker intrinsics when rewriting resources that otherwise have no uses.

The fix here ignores bitcasts to i8* which are associated with lifetime markers when rewriting resource accesses.

This fix is a targeted "avoid the crash" fix, rather than wholistic since this rewriting really shouldn't be happening at the end of IR generation, it should likely be in a separate IR pass.

Assisted by: Copilot, Claude Sonnet 5.

Without this change DXC crashes if the result of a descriptor heap
subscript is discarded. The crash is caused by not correctly handling
lifetime marker intrinsics when rewriting resources that otherwise have
no uses.

The fix here ignores bitcasts to i8* which are associated with lifetime
markers when rewriting resource accesses.

This fix is a targeted "avoid the crash" fix, rather than wholistic
since this rewriting _really_ shouldn't be happening at the end of IR
generation, it should likely be in a separate IR pass.

Assisted by: Copilot, Claude Sonnet 5.

../tools/clang/test/CodeGenDXIL/discarded_dynamic_res.hlsl

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.

Pull request overview

Prevents DXC from crashing when discarded descriptor-heap subscripts leave lifetime-marker-only resource uses.

Changes:

  • Preserves lifetime-marker bitcasts during resource rewriting.
  • Adds regression coverage for resource and sampler heaps.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tools/clang/lib/CodeGen/CGHLSLMSFinishCodeGen.cpp Handles lifetime-only bitcasts safely.
tools/clang/test/CodeGenDXIL/discarded_dynamic_res.hlsl Tests discarded heap subscript expressions.

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

// later legalization passes (which already know how to handle
// bitcasts that are onlyUsedByLifetimeMarkers) will clean them up
// once resPtr has no other real uses.
if (BCI->getType()->getPointerElementType()->isIntegerTy(8)) {

@bob80905 Joshua Batista (bob80905) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Only nit is that the comments could be seen as verbose.

Copilot AI review requested due to automatic review settings August 10, 2026 19:51

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings August 10, 2026 19:55

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

docs/ReleaseNotes.md:35

  • CONTRIBUTING.md:136-140 requires release-note entries to be a single sentence and not link to specific PRs. This entry uses two sentences and links to a discussion on PR #8517; please condense it and remove the PR link.
- Fix a crash generating DXIL from sources containing a dynamic resource heap
  access that was discarded. Identified during development of SPIR-V support for
  [descriptor heaps](https://github.com/microsoft/DirectXShaderCompiler/pull/8517#discussion_r3752113078).

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