Skip to content

[202x][0005] Implement cbuffer contexts - #8935

Open
Chris B (llvm-beanz) wants to merge 4 commits into
microsoft:mainfrom
llvm-beanz:0005-cbuffer-contexts
Open

Chris B (llvm-beanz) wants to merge 4 commits into
microsoft:mainfrom
llvm-beanz:0005-cbuffer-contexts

Conversation

@llvm-beanz

@llvm-beanz Chris B (llvm-beanz) commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

This restricts the ability to nest namespaces and cbuffer/tbuffer declarations within cbuffers. This implements the language adopted by TC57 for the draft specification.

Fixes #8484

This restricts the ability to nest namespaces and cbuffer/tbuffer
declarations within cbuffers. This implements the language adopted by
TC57 for the draft specification.

Fixes microsoft#8484
../tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
../tools/clang/test/SemaHLSL/hlsl/202x-cbuffer-contexts.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

The user-visible language change needs release-note coverage, and a source comment typo should be corrected.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
What changed in this PR

Implements TC57 proposal 0005 by rejecting nested namespaces and buffer declarations in HLSL 202x buffers.

Changes:

  • Adds semantic validation and diagnostics.
  • Adds coverage for valid and invalid nesting.
File Description
SemaHLSL.cpp Validates buffer contents.
DiagnosticSemaKinds.td Defines the new diagnostic.
202x-cbuffer-contexts.hlsl Tests buffer-context restrictions.

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

Comment thread tools/clang/lib/Sema/SemaHLSL.cpp Outdated
Comment thread tools/clang/lib/Sema/SemaHLSL.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 21, 2026 15: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

🔵 Needs a closer look

The user-visible language change needs an Upcoming Release note.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 22, 2026 16:19

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

🔵 Needs a closer look

The denylist still accepts declaration kinds prohibited by the proposal.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Validate allowed declaration kinds instead of denying only two

tools/​clang/​lib/​Sema/​SemaHLSL.cpp:15394

This denylist does not enforce the proposal's allowed declaration set described above it. ParseCTBuffer parses arbitrary external declarations, so declarations such as typedef int T;, enum E { V };, namespace aliases, using declarations, and static_assert remain accepted in an HLSL 202x buffer because none is an HLSLBufferDecl or NamespaceDecl. Please validate against the proposal's allowed categories (including any permitted template wrappers) rather than only these two forbidden kinds, and add coverage for the other rejected declaration forms. The diagnostic path will also need to handle disallowed declarations that are not NamedDecl.

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 implementation does not enforce the documented declaration allowlist.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Comment on lines +15393 to +15394
if (getLangOpts().HLSLVersion >= hlsl::LangStd::v202x &&
(isa<HLSLBufferDecl>(Field) || isa<NamespaceDecl>(Field))) {
../tools/clang/include/clang/Basic/DiagnosticCommonKinds.td
../tools/clang/include/clang/Basic/DiagnosticGroups.td
../tools/clang/test/DXC/dumpPSV_LinAlgAccumulate.hlsl
../tools/clang/test/DXC/dumpPSV_LinAlgConstructions.hlsl
../tools/clang/test/DXC/dumpPSV_LinAlgMatrixMultiply.hlsl
../tools/clang/test/SemaHLSL/removed-keywords-2026-warnings.hlsl
../tools/clang/test/SemaHLSL/removed-keywords-202x.hlsl
Copilot AI review requested due to automatic review settings September 22, 2026 19:56

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

All reviewed changes are covered with no unresolved issues.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

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.

[202x][0005] Disallow namespace in cbuffer

3 participants