Skip to content

[202x][0004] Disallow ignored initializers - #8985

Merged
Chris B (llvm-beanz) merged 6 commits into
microsoft:mainfrom
llvm-beanz:cbuffer-initializers
Oct 6, 2026
Merged

Chris B (llvm-beanz) merged 6 commits into
microsoft:mainfrom
llvm-beanz:cbuffer-initializers

Conversation

@llvm-beanz

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

Copy link
Copy Markdown
Collaborator

This PR does two things: first it refactors the existing warning on ignored global initializers to move the general case (implicit cbuffer & groupshared) into Sema from the DXIL & SPIRV codegen layers. This generalization fixes issues where the warning wasn't firing, and expands it to all cbuffer members.

Second, this PR turns that warning into an error in HLSL 202x+.

Resolves #8483

This PR does two things: first it refactors the existing warning on
ignored global initializers to move the general case (implicit cbuffer)
into Sema from the DXIL & SPIRV codegen layers. This generalization
fixes issues where the warning wasn't firing, and expands it to all
cbuffer members.

Second, this PR turns that warning into an error in HLSL 202x+.

Resolves microsoft#8483

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

Moving diagnostics across semantic analysis and both backends leaves a DXIL groupshared-initializer warning gap that needs correction and human validation.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR moves ignored buffer-initializer diagnostics into HLSL semantic analysis and makes initializers on shader constants an error in HLSL 202x, addressing #8483.

Changes:

  • Adds version-dependent diagnostics for explicit buffers and implicit $Globals, with a suppressible warning in older versions.
  • Removes overlapping DXIL and SPIR-V warnings and updates regression tests.
  • Documents the HLSL 202x change in the release notes.
File Description
tools/​clang/​test/​SemaHLSL/​vector-syntax.hlsl Expects global-initializer warnings.
tools/​clang/​test/​SemaHLSL/​vector-syntax-exact-precision.hlsl Expects warnings with exact precision.
tools/​clang/​test/​SemaHLSL/​varmods-syntax.hlsl Updates modifier diagnostic expectations.
tools/​clang/​test/​SemaHLSL/​v2021-static-assert-not-keyword.hlsl Keeps the test global outside $Globals.
tools/​clang/​test/​SemaHLSL/​typemods-syntax.hlsl Expects explicit-buffer warnings.
tools/​clang/​test/​SemaHLSL/​subobjects-syntax.hlsl Expects warnings for two globals.
tools/​clang/​test/​SemaHLSL/​removed-keywords-202x.hlsl Keeps keyword-test globals outside $Globals.
tools/​clang/​test/​SemaHLSL/​rayquery-omm-diag-TU-export-sm65.hlsl Expects the new global warning.
tools/​clang/​test/​SemaHLSL/​hlsl/​buffer-initializers-pre202x.hlsl Tests warnings before 202x.
tools/​clang/​test/​SemaHLSL/​hlsl/​buffer-initializers-nowarn.hlsl Tests warning suppression.
tools/​clang/​test/​SemaHLSL/​hlsl/​buffer-initializers-202x.hlsl Tests 202x errors.
tools/​clang/​test/​HLSLFileCheckLit/​hlsl/​auto/​auto-no-reference.hlsl Keeps the test global outside $Globals.
tools/​clang/​test/​HLSL/​rewriter/​varmods-syntax_noerr.hlsl Updates rewriter-test warnings.
tools/​clang/​test/​HLSL/​rewriter/​typemods-syntax_noerr.hlsl Updates buffer-member warnings.
tools/​clang/​test/​HLSL/​rewriter/​cpp-errors_noerr.hlsl Expects global-initializer warnings.
tools/​clang/​test/​HLSL/​cpp-errors.hlsl Expects global-initializer warnings.
tools/​clang/​test/​HLSL/​cpp-errors-hv2015.hlsl Suppresses unrelated warnings.
tools/​clang/​test/​CodeGenSPIRV/​var.init.warning.ignored.hlsl Suppresses the new warning in a codegen test.
tools/​clang/​test/​CodeGenSPIRV/​var.init.tbuffer.hlsl Verifies tbuffer diagnostics.
tools/​clang/​test/​CodeGenSPIRV/​var.init.cbuffer.hlsl Verifies cbuffer diagnostics.
tools/​clang/​test/​CodeGenSPIRV/​var.globals.error.hlsl Updates expected diagnostics.
tools/​clang/​test/​CodeGenSPIRV/​implicit.global.ubo.hlsl Checks compilation under both language modes.
tools/​clang/​test/​CodeGenSPIRV/​groupshared.init.warning.hlsl Updates the SPIR-V groupshared warning.
tools/​clang/​lib/​SPIRV/​SpirvEmitter.cpp Removes buffer warnings; retains a groupshared warning.
tools/​clang/​lib/​SPIRV/​DeclResultIdMapper.cpp Removes the $Globals warning.
tools/​clang/​lib/​Sema/​SemaDecl.cpp Diagnoses buffer initializers by language version.
tools/​clang/​lib/​CodeGen/​CodeGenModule.cpp Removes DXIL global-initializer warnings.
tools/​clang/​include/​clang/​Basic/​DiagnosticSemaKinds.td Defines the warning and error messages.
tools/​clang/​include/​clang/​Basic/​DiagnosticGroups.td Adds a warning-suppression group.
docs/​ReleaseNotes.md Records 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 thread tools/clang/lib/Sema/SemaDecl.cpp
Copilot AI balanced review requested due to automatic review settings September 30, 2026 00:44

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 cross-backend diagnostic change warrants final human validation despite focused test coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Copilot AI balanced review requested due to automatic review settings September 30, 2026 01:15

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 diagnostic move changes compiler behavior across semantic analysis and two backends, so final human validation is warranted.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI balanced review requested due to automatic review settings September 30, 2026 15:32

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

A rewriter verification test still has unaccounted-for groupshared warnings and will fail.

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

Open (2)

Comment thread tools/clang/test/HLSL/rewriter/varmods-syntax_noerr.hlsl
Comment thread docs/ReleaseNotes.md

@hekota Helena Kotas (hekota) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Comment thread tools/clang/test/CodeGenSPIRV/var.init.cbuffer.hlsl Outdated
../tools/clang/test/CodeGenSPIRV/var.init.cbuffer.hlsl
Copilot AI balanced review requested due to automatic review settings October 1, 2026 02:43

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 centralized diagnostics match the intended versioned behavior and are covered across DXIL, SPIR-V, warning suppression, and buffer variants.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@llvm-beanz Chris B (llvm-beanz) changed the title [202x][0004] Disallow initializers on cbuffer members [202x][0004] Disallow initializers ignored initializers Oct 6, 2026
@llvm-beanz Chris B (llvm-beanz) changed the title [202x][0004] Disallow initializers ignored initializers [202x][0004] Disallow ignored initializers Oct 6, 2026

// CHECK: warning: Initializer of external global will be ignored
// CHECK-NEXT: groupshared uint testing = 0; No newline at end of file
} No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

newline

../tools/clang/test/CodeGenSPIRV/groupshared.init.warning.hlsl
Copilot AI balanced review requested due to automatic review settings October 6, 2026 19:33

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 diagnostic migration misses mixed aggregates and removes the warning for ignored SPIR-V resource initializers.

Review effort: Balanced
Findings: None

Previously missed (2)

In code that hasn't changed since last review

Medium severity Retain warnings for ignored external resource initializers

tools/​clang/​lib/​SPIRV/​SpirvEmitter.cpp:2191

Removing this warning also silences ignored external resource initializers, which the new Sema checks exclude. For example, when Texture2D a; Texture2D b = a; is emitted for SPIR-V, createExternVar(b) still creates an independent resource rather than evaluating the initializer, but now gives no warning. Retain the backend warning for resource and resource-only aggregate initializers, while leaving the buffer and groupshared diagnostics to Sema. Add a codegen diagnostic regression for this case.

Medium severity Handle mixed resource and numeric globals in initializer diagnostics

tools/​clang/​lib/​Sema/​SemaDecl.cpp:87

This numeric-only predicate excludes global structs containing both resource and numeric fields. DXIL still places their numeric fields in $Globals, as covered by tools/clang/test/HLSLFileCheck/hlsl/resource_binding/resource_in_cbuffer2.hlsl, and CodeGenModule.cpp still discards their initializers. An initialized mixed aggregate therefore misses both the warning in older language modes and the required HLSL 202x error now that the backend warning is removed. Classify mixed aggregates according to their constant-buffer storage, and add regression coverage for both language modes.

@llvm-beanz
Chris B (llvm-beanz) enabled auto-merge (squash) October 6, 2026 20:42
@llvm-beanz
Chris B (llvm-beanz) merged commit dba1207 into microsoft:main Oct 6, 2026
12 checks passed
@llvm-beanz
Chris B (llvm-beanz) deleted the cbuffer-initializers branch October 6, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[202x][0004] Error on cbuffer initializer

4 participants