-
Notifications
You must be signed in to change notification settings - Fork 336
Diagnose on initExpr of a global const
decl
#7711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0675d8a
Add diagnostic for const/uniform global variables with initializers
github-actions[bot] 9fd9f43
Add test case for global const/uniform variable diagnostic
github-actions[bot] 5ca5aab
Merge branch 'master' into claude/issue-7701-20250710_213741
ArielG-NV 52cee4a
Fix failing tests due to new global const diagnostic
github-actions[bot] 077f007
Allow specialization constants with initializers without static
github-actions[bot] 4a036c9
Merge branch 'master' into claude/issue-7701-20250710_213741
csyonghe 4219884
format code (#7765)
slangbot 4fe2a98
Remove static keyword from specialization constants and add comprehen…
github-actions[bot] d37f657
Add error for static specialization constants
github-actions[bot] 106186c
Update source/slang/slang-check-decl.cpp
ArielG-NV 976c951
Update tests/glsl/compute-shader-layout-id.slang
ArielG-NV b482bc7
Update tests/glsl/compute-shader-layout-id.slang
ArielG-NV eb9e565
Merge branch 'master' into claude/issue-7701-20250710_213741
ArielG-NV 8301bfb
Fix test case Claude broke
ArielG-NV 373b540
Merge branch 'master' into claude/issue-7701-20250710_213741
ArielG-NV 552778f
Update global-uniform.slang
ArielG-NV 550dea9
Update global-uniform.slang.expected
ArielG-NV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//TEST:SIMPLE(filecheck=CHK): -target hlsl -entry main | ||
|
||
// Test for diagnostic 31224: global const/uniform variables with initializers must be static | ||
// Exception: specialization constants are allowed to have initializers without static | ||
// Test for diagnostic 31219: specialization constants cannot be declared static | ||
|
||
// These should trigger error 31224 | ||
//CHK-DAG: ([[# @LINE + 1]]): error 31224: global const variable with initializer must be declared static: 'globalConstWithInit' | ||
const float globalConstWithInit = 1.0f; | ||
|
||
//CHK-DAG: ([[# @LINE + 1]]): error 31224: global const variable with initializer must be declared static: 'uniformWithInit' | ||
uniform float uniformWithInit = 2.0f; | ||
|
||
// These are valid and should not produce errors | ||
static const float staticConstWithInit = 3.0f; // OK - static const with init | ||
const float globalConstNoInit; // OK - const without init | ||
uniform float uniformNoInit; // OK - uniform without init | ||
|
||
// Specialization constants with initializers are allowed without static | ||
[SpecializationConstant] | ||
const int specConstInt = 42; // OK - specialization constant with init | ||
|
||
[vk::constant_id(5)] | ||
const float specConstFloat = 3.14f; // OK - vk constant id with init | ||
|
||
// These should trigger error 31219: static specialization constants are not allowed | ||
//CHK-DAG: ([[# @LINE + 2]]): error 31219: push or specialization constants cannot be 'static'. | ||
[SpecializationConstant] | ||
static const int staticSpecConstInt = 100; | ||
|
||
//CHK-DAG: ([[# @LINE + 2]]): error 31219: push or specialization constants cannot be 'static'. | ||
[vk::constant_id(7)] | ||
static const float staticSpecConstFloat = 2.71f; | ||
|
||
void functionScope() | ||
{ | ||
const float localConstWithInit = 4.0f; // OK - local const with init | ||
} | ||
|
||
struct MyStruct | ||
{ | ||
static const float memberStaticConst = 5.0f; // OK - member static const | ||
}; | ||
|
||
[shader("vertex")] | ||
float4 main() : SV_Position | ||
{ | ||
return float4(staticConstWithInit, 0, 0, 1); | ||
} |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.