diff options
| author | Yong He <yonghe@outlook.com> | 2025-06-13 17:06:05 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-13 17:06:05 -0700 |
| commit | 84148b80b167f5102e5f4813671b97bc1faeb5f0 (patch) | |
| tree | 46efe753a0e87cb9c826cd55b85c36cb766fccc8 | |
| parent | 1d8f6f86d1a6d33ff6e6429206b94d72457e1378 (diff) | |
Fix a bug in empty array legalization. (#7444)
| -rw-r--r-- | source/slang/slang-ir-legalize-empty-array.cpp | 8 | ||||
| -rw-r--r-- | tests/language-feature/0-array-2.slang | 40 |
2 files changed, 45 insertions, 3 deletions
diff --git a/source/slang/slang-ir-legalize-empty-array.cpp b/source/slang/slang-ir-legalize-empty-array.cpp index 561327565..1f7d59783 100644 --- a/source/slang/slang-ir-legalize-empty-array.cpp +++ b/source/slang/slang-ir-legalize-empty-array.cpp @@ -71,15 +71,17 @@ struct EmptyArrayLoweringContext [&](IRGetElementPtr* gep) { const auto base = gep->getBase(); - return hasEmptyArrayPtrType(base) || base->getOp() == kIROp_undefined + return hasEmptyArrayPtrType(gep) || hasEmptyArrayPtrType(base) || + base->getOp() == kIROp_undefined ? builder.emitUndefined(gep->getDataType()) : nullptr; }, [&](IRFieldAddress* gep) { const auto base = gep->getBase(); - return base->getOp() == kIROp_undefined ? builder.emitUndefined(gep->getDataType()) - : nullptr; + return hasEmptyArrayPtrType(gep) || base->getOp() == kIROp_undefined + ? builder.emitUndefined(gep->getDataType()) + : nullptr; }, [&](IRLoad* load) { diff --git a/tests/language-feature/0-array-2.slang b/tests/language-feature/0-array-2.slang new file mode 100644 index 000000000..37d576d89 --- /dev/null +++ b/tests/language-feature/0-array-2.slang @@ -0,0 +1,40 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk + +public struct ContextND<let N: int> +{ + public uint3 thread_id; + public int[N] call_id; + + public ContextND<0> map(int) + { + return { thread_id }; + } + + public ContextND<M> map<let M : int>(int[M] mapping) + { + ContextND<M> result; + result.thread_id = thread_id; + for (int i = 0; i < M; ++i) + result.call_id[i] = call_id[mapping[i]]; + return result; + } +} + +typealias Context = ContextND<0>; + +//TEST_INPUT: set value = out ubuffer(data=[0 0 0 0], stride=4) +RWStructuredBuffer<int> value; + +void store(Context context, in int v) { value[0] = v; } + +[shader("compute")] +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + Context context = {dispatchThreadID}; + int c = 1; + int m_c = 0; + // CHECK: 1 + store(context.map(m_c), c); +}
\ No newline at end of file |
