diff options
| author | Copilot <198982749+Copilot@users.noreply.github.com> | 2025-07-18 23:01:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-18 23:01:55 +0000 |
| commit | 4d514f792fc590e28579a184be8890613d0fdf9e (patch) | |
| tree | 5d069f7896ee05a51a3745bc34b3c4e1893efcfc /tests | |
| parent | 3df9fe8a8a1aa01db2651eacd1d8bec50d0ee90c (diff) | |
Fix enum array indexing by adding implicit conversion support (#7815)
* Initial plan
* Fix enum array indexing by adding implicit conversion support
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
* Update enum array indexing test to support GPU backends
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/language-feature/enums/enum-array-indexing.slang | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/language-feature/enums/enum-array-indexing.slang b/tests/language-feature/enums/enum-array-indexing.slang new file mode 100644 index 000000000..c9294ad0c --- /dev/null +++ b/tests/language-feature/enums/enum-array-indexing.slang @@ -0,0 +1,36 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -output-using-type + +// Test that enums can be used as array indices without explicit casting + +enum Fruit { Apple, Orange, Banana }; + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4) +RWStructuredBuffer<int> outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + int fruits[10]; + + // Initialize arrays with some values + for (int i = 0; i < 10; i++) + { + fruits[i] = i * 10; + } + + // Test basic enum indexing - this should work with our fix + int appleCost = fruits[Fruit::Apple]; // Should access fruits[0] = 0 + int orangeCost = fruits[Fruit::Orange]; // Should access fruits[1] = 10 + int bananaCost = fruits[Fruit::Banana]; // Should access fruits[2] = 20 + + // CHECK: 0 + outputBuffer[0] = appleCost; + // CHECK: 10 + outputBuffer[1] = orangeCost; + // CHECK: 20 + outputBuffer[2] = bananaCost; + // CHECK: 42 + outputBuffer[3] = 42; // Just a test value +}
\ No newline at end of file |
