forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash when handling uninitialized resource type
close shader-slang#6328. When declare a var with struct type, if the struct has a resource type field and it doesn't provide explicit constructor, because slang won't implicit construct such variable at declare site if user doesn't explicitly call the initializer list, we should report the resource type field uninitialized as an error to prevent future possible crash when legalize any use of such variable.
- Loading branch information
1 parent
96529df
commit 6a98212
Showing
5 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,33 @@ | ||
//DIAGNOSTIC_TEST:SIMPLE: -target hlsl | ||
|
||
SamplerState sampler; | ||
|
||
struct Foo | ||
{ | ||
bool sample_bar = false; | ||
Texture2D<float4> bar = {}; | ||
}; | ||
|
||
struct Result | ||
{ | ||
float4 color = float4(0.0); | ||
}; | ||
|
||
Result process(in Foo foo) | ||
{ | ||
Result result = {}; | ||
|
||
if (foo.sample_bar) { | ||
result.color = foo.bar.Sample(sampler, float2(0.0, 0.0)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
[shader("compute")] | ||
[numthreads(8, 8, 1)] | ||
float4 cs_main(uint3 thread_id : SV_DispatchThreadID) { | ||
Foo foo; | ||
const let result = process(foo); | ||
return result.color; | ||
} |
This file contains 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,9 @@ | ||
result code = -1 | ||
standard error = { | ||
tests/diagnostics/test1.slang(31): warning 41016: use of uninitialized variable 'foo' | ||
const let result = process(foo); | ||
^ | ||
tests/diagnostics/test1.slang(5): error 56003: use of uninitialized resource type 'Texture2D'. | ||
struct Foo | ||
^~~ | ||
} |