diff options
| author | Yong He <yonghe@outlook.com> | 2024-06-11 23:58:25 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-11 23:58:25 -0700 |
| commit | 3fe4a77287345c303aeb985e24ee237f272e8eca (patch) | |
| tree | 59d5096a8f0e42286f8db2fb72d04f3db82f166f /tests | |
| parent | 5da06d43bb0997455211ca56597c4302b09909ab (diff) | |
Fix crash when using optional type in a generic. (#4341)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bugs/optional-generic.slang | 22 | ||||
| -rw-r--r-- | tests/bugs/optional.slang | 42 |
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/bugs/optional-generic.slang b/tests/bugs/optional-generic.slang new file mode 100644 index 000000000..16b466273 --- /dev/null +++ b/tests/bugs/optional-generic.slang @@ -0,0 +1,22 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-slang -compute +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-slang -compute -vk + + +Optional<T> genFunc<T : IArithmetic>(T v) +{ + if (v is int) + return v; + return none; +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name buffer + +RWStructuredBuffer<int> buffer; + +[numthreads(1,1,1)] +void computeMain() +{ + // BUF: 2 + buffer[0] = genFunc(2).value; +} + diff --git a/tests/bugs/optional.slang b/tests/bugs/optional.slang new file mode 100644 index 000000000..3512ba29f --- /dev/null +++ b/tests/bugs/optional.slang @@ -0,0 +1,42 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-slang -compute -vk + +interface IFoo +{ + void foo(); +} + +struct S : IFoo { int x; void foo(); } + +struct P +{ + IFoo f; +} +struct Tr +{ + int test<T:IArithmetic>(T t, inout P p) + { + const IFoo hit = p.f; + let castResult = hit as S; + if (!castResult.hasValue) + return 0; + return castResult.value.x; + } +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name buffer + +RWStructuredBuffer<int> buffer; + +[numthreads(1,1,1)] +void computeMain() +{ + P p; + S s; + s.x = 2; + p.f = s; + Tr tt; + // BUF: 2 + buffer[0] = tt.test(0, p); +} + |
