[202x] Fix nesting cbuffers in namespaces - #8943
Open
Chris B (llvm-beanz) wants to merge 1 commit into
Open
Chris B (llvm-beanz) wants to merge 1 commit into
Chris B (llvm-beanz) wants to merge 1 commit into
Conversation
This is a long-standing bug in DXC, but in HLSL 202x since we're addressing a bunch of other issues around cbuffer/tbuffer semantics we also will address this here. With this change declarations placed inside a cbuffer are targeted to the enclosing declaration context which must be either a namespace or the top-level translation unit declaration context.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Nested buffers can still receive another buffer as their semantic declaration context instead of the enclosing namespace.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
What changed in this PR
Updates HLSL 202x buffer declaration contexts so namespace-scoped buffers and members resolve correctly.
Changes:
- Assigns buffer declarations to their enclosing context in HLSL 202x.
- Adds semantic, DXIL, and SPIR-V coverage.
- Documents the behavior change.
| File | Description |
|---|---|
tools/clang/lib/Sema/SemaHLSL.cpp |
Updates buffer declaration contexts. |
tools/clang/test/SemaHLSL/v202x/buffer-namespace-decl-context.hlsl |
Tests namespace lookup and AST structure. |
tools/clang/test/CodeGenDXIL/cbuffer.namespace.hlsl |
Tests DXIL generation. |
tools/clang/test/CodeGenSPIRV/cbuffer.namespace.hlsl |
Tests SPIR-V generation. |
docs/ReleaseNotes.md |
Documents the HLSL 202x change. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+15450
to
+15451
| if (C.getLangOpts().HLSLVersion >= hlsl::LangStd::v202x) | ||
| DC = lexicalParent; |
Collaborator
Author
There was a problem hiding this comment.
This is separately fixed in #8935, which disallows cbuffers in cbuffers and namespaces in cbuffers.
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.

This is a long-standing bug in DXC, but in HLSL 202x since we're addressing a bunch of other issues around cbuffer/tbuffer semantics we also will address this here.
With this change declarations placed inside a cbuffer are targeted to the enclosing declaration context which must be either a namespace or the top-level translation unit declaration context.