Skip to content

[202x] Fix nesting cbuffers in namespaces - #8943

Open
Chris B (llvm-beanz) wants to merge 1 commit into
microsoft:mainfrom
llvm-beanz:cbuffer-namespaces
Open

Chris B (llvm-beanz) wants to merge 1 commit into
microsoft:mainfrom
llvm-beanz:cbuffer-namespaces

Conversation

@llvm-beanz

Copy link
Copy Markdown
Collaborator

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.

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.

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

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 Medium severity

Open (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;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is separately fixed in #8935, which disallows cbuffers in cbuffers and namespaces in cbuffers.

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.

2 participants