Templates in cbuffers should be const - #8974
Open
Chris B (llvm-beanz) wants to merge 3 commits into
Open
Chris B (llvm-beanz) wants to merge 3 commits into
Chris B (llvm-beanz) wants to merge 3 commits into
Conversation
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
Chris B (llvm-beanz)
force-pushed
the
templates-in-cbuffers
branch
from
September 28, 2026 23:15
882f480 to
8dc030a
Compare
Contributor
There was a problem hiding this comment.
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
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.
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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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