diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-04-17 23:23:15 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-17 23:23:15 -0700 |
| commit | d3fd7470e6b71aa080415a3a7c207faebe21b00f (patch) | |
| tree | de3b9c1642fbea11392bfaf170de31a6d80b2826 /tests | |
| parent | 5dd27a26da9b6b6191f3b1eba0f38f85714c1ae3 (diff) | |
Implement if(let ...) syntax (#3673) (#3958)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/language-feature/if-let/if-let-1.slang | 89 | ||||
| -rw-r--r-- | tests/language-feature/if-let/if-let-diagnose-1.slang | 53 | ||||
| -rw-r--r-- | tests/language-feature/if-let/if-let-diagnose.slang | 42 | ||||
| -rw-r--r-- | tests/language-feature/if-let/if-let.slang | 38 |
4 files changed, 222 insertions, 0 deletions
diff --git a/tests/language-feature/if-let/if-let-1.slang b/tests/language-feature/if-let/if-let-1.slang new file mode 100644 index 000000000..c197f26ea --- /dev/null +++ b/tests/language-feature/if-let/if-let-1.slang @@ -0,0 +1,89 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -compute -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cuda -compute -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + + +interface IFoo +{ + int foo(int a); +} + +struct MyImpl1 : IFoo +{ + int foo(int a) { return a; } +} + +struct MyImpl2 : IFoo +{ + int foo(int a) { return a + 5; } +} + +int test(IFoo foo, int idx) +{ + int val = 0; + if (let a = foo as MyImpl1) + { + val = a.foo(idx); + } + else if (let a = foo as MyImpl2) + { + val = a.foo(idx); + } + return (val); +} + +int test1<T>(T t) +{ + if (let a = t as uint) + { + return 1; + } + else if(let a = t as float) + { + return 2; + } + else if (let a = t as double) + { + return 3; + } + else if (let a = t as int) + { + return 4; + } + else if (let a = t as uint64_t) + { + return 5; + } + else + { + return 6; + } +} + + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + MyImpl1 impl1; + MyImpl2 impl2; + // CHECK: 1 + // CHECK: 7 + outputBuffer[0] = test(impl1, 1); + outputBuffer[1] = test(impl2, 2); + + // CHECK: 1 + outputBuffer[2] = test1(2U); + // CHECK: 2 + outputBuffer[3] = test1(2.0f); + // CHECK: 3 + outputBuffer[4] = test1(2.0lf); + // CHECK: 4 + outputBuffer[5] = test1(2); + // CHECK: 5 + outputBuffer[6] = test1(2LLU); + // CHECK: 6 + outputBuffer[7] = test1(impl1); +} diff --git a/tests/language-feature/if-let/if-let-diagnose-1.slang b/tests/language-feature/if-let/if-let-diagnose-1.slang new file mode 100644 index 000000000..2322abb1a --- /dev/null +++ b/tests/language-feature/if-let/if-let-diagnose-1.slang @@ -0,0 +1,53 @@ +//TEST:SIMPLE(filecheck=CHECK): -target glsl -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=CHECK): -target cuda -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=CHECK): -target cpp -stage compute -entry computeMain + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + + +interface IFoo +{ + int foo(int a); +} + +struct MyImpl : IFoo +{ + int foo(int a) { return a; } +} + +struct MyImpl1 : IFoo +{ + int foo(int a) { return a; } +} + +int test(IFoo foo, int idx) +{ + int val = 0; + if (let a = foo as MyImpl) + { + val = a.foo(idx); + } + // CHECK: error 30015: undefined identifier 'a'. + else if(a == none) + { + val = -1; + } + else + { + // CHECK: error 30015: undefined identifier 'a'. + if (a == none) + { + val = -1; + } + } + return (val); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + MyImpl1 impl; + outputBuffer[dispatchThreadID.x] = test(impl, dispatchThreadID.x); +} diff --git a/tests/language-feature/if-let/if-let-diagnose.slang b/tests/language-feature/if-let/if-let-diagnose.slang new file mode 100644 index 000000000..4e9aa69c7 --- /dev/null +++ b/tests/language-feature/if-let/if-let-diagnose.slang @@ -0,0 +1,42 @@ +//TEST:SIMPLE(filecheck=CHECK): -target glsl -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=CHECK): -target cuda -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=CHECK): -target cpp -stage compute -entry computeMain + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + + +interface IFoo +{ + int foo(int a); +} + +struct MyImpl : IFoo +{ + int foo(int a) { return a; } +} + +struct MyImpl1 : IFoo +{ + int foo(int a) { return a; } +} + +int test(IFoo foo, int idx) +{ + int val = 0; + // CHECK: error 20002: syntax error. + if ((let a = foo as MyImpl)) + { + val = a.foo(idx); + } + return (val); +} + + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + MyImpl impl; + outputBuffer[dispatchThreadID.x] = test(impl, dispatchThreadID.x); +} diff --git a/tests/language-feature/if-let/if-let.slang b/tests/language-feature/if-let/if-let.slang new file mode 100644 index 000000000..5bb31030f --- /dev/null +++ b/tests/language-feature/if-let/if-let.slang @@ -0,0 +1,38 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -compute -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cuda -compute -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + + +interface IFoo +{ + int foo(int a); +} + +struct MyImpl : IFoo +{ + int foo(int a) { return a; } +} + +int test(IFoo foo, int idx) +{ + int val = 0; + if (let a = foo as MyImpl) + { + val = a.foo(idx); + } + return (val); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + MyImpl impl; + // CHECK: 0 + // CHECK: 1 + // CHECK: 2 + // CHECK: 3 + outputBuffer[dispatchThreadID.x] = test(impl, dispatchThreadID.x); +} |
