You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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+.
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+.
Resolvesmicrosoft#8483
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.
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.
Chris B (llvm-beanz)
changed the title
[202x][0004] Disallow initializers on cbuffer members
[202x][0004] Disallow initializers ignored initializers
Oct 6, 2026
Chris B (llvm-beanz)
changed the title
[202x][0004] Disallow initializers ignored initializers
[202x][0004] Disallow ignored initializers
Oct 6, 2026
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
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.
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.
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
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 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