Sitelet https://github.com/microsoft/DirectXShaderCompiler/pull/8974
Skip to content

Templates in cbuffers should be const - #8974

Open
Chris B (llvm-beanz) wants to merge 3 commits into
microsoft:mainfrom
llvm-beanz:templates-in-cbuffers
Open

Chris B (llvm-beanz) wants to merge 3 commits into
microsoft:mainfrom
llvm-beanz:templates-in-cbuffers

Conversation

@llvm-beanz

Copy link
Copy Markdown
Collaborator

Template declarations in cbuffers were not previously getting made const, this fixes that so that the compiler produces reasonable diagnostics instead of asserting in the optimizer.

Since without this change the compiler was just asserting, this doesn't break any existing code that would have compiled cleanly unless that code was fully dead and optimized away.

Fixes #8966

Template declarations in cbuffers were not previously getting made
`const`, this fixes that so that the compiler produces reasonable
diagnostics instead of asserting in the optimizer.

Since without this change the compiler was just asserting, this doesn't
break any existing code that would have compiled cleanly unless that
code was fully dead and optimized away.

Fixes microsoft#8966

../tools/clang/test/HLSL/rewriter/correct_rewrites/cpp-errors_gold.hlsl
../tools/clang/test/HLSL/rewriter/correct_rewrites/template-checks_gold.
hlsl
../tools/clang/test/HLSL/rewriter/correct_rewrites/typemods-syntax_gold.
hlsl
../tools/clang/test/HLSLFileCheck/hlsl/template/template_alias_empty_arg
.hlsl
../tools/clang/test/SemaHLSL/const-default-templates.hlsl
../tools/clang/test/SemaHLSL/hlsl/linalg/linalg-matrix-global.hlsl
../tools/clang/test/SemaHLSL/v202x/templates/template-right-angle-bracke
ts.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.

Copilot review overview

🟡 Changes recommended

Unhandled alias-template result types can still trigger an assertion, and the release note overstates the affected types.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Fixes implicit const qualification for numeric globals and cbuffer members using template-id types.

Changes:

  • Unwraps and instantiates template types before numeric classification.
  • Handles LinAlg matrices as nonnumeric.
  • Adds semantic tests, updates golden outputs, and documents the fix.
File Description
tools/​clang/​lib/​Parse/​ParseDecl.cpp Classifies unwrapped template types for implicit const.
tools/​clang/​lib/​Sema/​SemaHLSL.cpp Adds LinAlg matrix classification.
tools/​clang/​test/​SemaHLSL/​const-default-templates.hlsl Tests template-based implicit constness.
tools/​clang/​test/​SemaHLSL/​hlsl/​linalg/​linalg-matrix-global.hlsl Tests LinAlg matrix handling.
tools/​clang/​test/​SemaHLSL/​v202x/​templates/​template-right-angle-brackets.hlsl Updates template AST expectations.
tools/​clang/​test/​HLSLFileCheck/​hlsl/​template/​template_alias_empty_arg.hlsl Updates alias-template AST expectations.
tools/​clang/​test/​HLSL/​rewriter/​correct_rewrites/​typemods-syntax_gold.hlsl Updates rewritten matrix declarations.
tools/​clang/​test/​HLSL/​rewriter/​correct_rewrites/​template-checks_gold.hlsl Updates rewritten template matrix declaration.
tools/​clang/​test/​HLSL/​rewriter/​correct_rewrites/​cpp-errors_gold.hlsl Updates rewritten global matrix declaration.
docs/​ReleaseNotes.md Documents the compiler fix.

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

Comment thread docs/ReleaseNotes.md Outdated
Copilot AI review requested due to automatic review settings September 28, 2026 23: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 new LinAlg test expects no diagnostics for declarations that existing semantic validation necessarily rejects.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)

Comment thread tools/clang/test/SemaHLSL/hlsl/linalg/linalg-matrix-global.hlsl Outdated
Fixed internal compiler errors related to member method calls on ray payloads and updated behavior for global and constant buffer variables with template-id types to be implicitly const.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 28, 2026 23:48

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 new LinAlg test expects no diagnostics for declarations that necessarily produce existing non-static-global errors.

Review effort: Balanced
Findings: 2 High severity

Open (2)
Resolved since last review (1)

Comment thread tools/clang/test/SemaHLSL/hlsl/linalg/linalg-matrix-global.hlsl Outdated
Copilot AI review requested due to automatic review settings September 29, 2026 00:07

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 focused parser correction is supported by comprehensive regression coverage and consistent expected-output updates.

Review effort: Balanced
Findings: None

Resolved since last review (2)

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.

Template declarations in global cbuffer not marked const

2 participants