Skip to content

Emit valid debug info for LinAlg matrix handles - #9187

Open
Damyan Pepper (damyanp) wants to merge 2 commits into
microsoft:mainfrom
damyanp:damyanp-linalg-debug-encoding
Open

Damyan Pepper (damyanp) wants to merge 2 commits into
microsoft:mainfrom
damyanp:damyanp-linalg-debug-encoding

Conversation

@damyanp

@damyanp Damyan Pepper (damyanp) commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

CGDebugInfo had no case for __builtin_LinAlgMatrix, so it passed an uninitialized DWARF encoding to createBasicType. Any -Zi shader using a LinAlg matrix could emit debug metadata that fails to reassemble.

Describe the matrix as an opaque, memberless struct so debuggers treat it like other opaque handles. Add a default: llvm_unreachable to the encoding switch, because DXC disables -Wswitch and nothing else would catch the next unhandled builtin.

Fixes #9183

Assisted-by: Copilot

CGDebugInfo::CreateType(const BuiltinType *) had no case for
BuiltinType::LinAlgMatrix, so the DWARF encoding passed to
createBasicType was uninitialized. Depending on build and optimization
level this produced garbage encodings that LLParser rejects (limit 255),
breaking disassemble/reassemble of any -Zi shader that uses a LinAlg
matrix, whether as a local, parameter, array element, struct member or
through the dx::linalg::Matrix wrapper.

Describe the handle as an opaque, memberless structure sized from the
ASTContext, initialize the encoding, and assert that every builtin
reaching createBasicType has one.

Fixes microsoft#9183

Co-authored-by: Copilot App <[email protected]>
Comment thread tools/clang/lib/CodeGen/CGDebugInfo.cpp Outdated
break;
}
// HLSL Change - catch builtins that were given no debug encoding.
assert(Encoding != 0 && "Unhandled builtin type in debug info");

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.

Why not add a default case that is llvm_unreachable or just enable the compiler warning so that warning as errors flags this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Switched to llvm_unreachable. Considering enabling the compiler warning, but this'll generate 138 warnings, will consider this in a followup.

@damyanp
Damyan Pepper (damyanp) marked this pull request as ready for review December 3, 2026 20:05
Copilot AI balanced review requested due to automatic review settings December 3, 2026 20:05

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.

🟡 Changes recommended

The FileCheck negative assertions leave gaps between DAG matches, allowing an unwanted __builtin_LinAlgMatrix DIBasicType to escape detection.

1 open issue
What changed in this PR

Fixes #9183 by giving LinAlg matrix handles valid, opaque debug metadata so disassembled DXIL can be reassembled.

Changes:

  • Represents matrix handles as memberless structs and rejects unhandled builtin types.
  • Adds debug-metadata, assembler round-trip, and PIX offset tests.
  • Documents the fix in release notes.
File Description
tools/​clang/​test/​CodeGenDXIL/​hlsl/​linalg/​linalg-matrix-debug-info.hlsl Adds regression coverage for matrix debug information.
tools/​clang/​lib/​CodeGen/​CGDebugInfo.cpp Emits opaque matrix types and guards builtin handling.
docs/​ReleaseNotes.md Records the debug-information fix.

Review effort: Balanced

// RUN: FileCheck %s --check-prefix=CHECK < %t.o3.ll
// RUN: %dxa %t.o3.ll -o %t.o3.dxil

// RUN: %dxc -T cs_6_10 -E main -fcgl -Zi -enable-16bit-types %s | FileCheck %s --check-prefix=SHAPES

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.

Debug info for __builtin_LinAlgMatrix has an uninitialized DWARF encoding

3 participants