summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-lower-to-ir.cpp8
-rw-r--r--tests/bugs/switch-local-const.slang34
2 files changed, 41 insertions, 1 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index c58eed1c1..90780882d 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -6813,7 +6813,13 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor>
IRBuilder subBuilder = *getBuilder();
subBuilder.setInsertInto(info->initialBlock);
subContext.irBuilder = &subBuilder;
- auto caseVal = getSimpleVal(context, lowerRValueExpr(&subContext, caseStmt->expr));
+
+ auto constVal = as<ConstantIntVal>(caseStmt->exprVal);
+ SLANG_ASSERT(constVal);
+ auto caseType = lowerType(context, constVal->getType());
+ auto caseValInfo =
+ LoweredValInfo::simple(getBuilder()->getIntValue(caseType, constVal->getValue()));
+ auto caseVal = getSimpleVal(context, caseValInfo);
// Figure out where we are branching to.
auto label = getLabelForCase(info);
diff --git a/tests/bugs/switch-local-const.slang b/tests/bugs/switch-local-const.slang
new file mode 100644
index 000000000..30cd8a814
--- /dev/null
+++ b/tests/bugs/switch-local-const.slang
@@ -0,0 +1,34 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -dx12
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu
+
+// CHECK: 0
+// CHECK-NEXT: 1
+// CHECK-NEXT: 2
+
+//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+uint testFunc(uint n)
+{
+ const uint CONST_A = 0;
+ const uint CONST_B = 1;
+
+ switch (n)
+ {
+ case CONST_A:
+ return 0;
+ case CONST_B:
+ return 1;
+ }
+
+ return 2;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
+{
+ outputBuffer[0] = testFunc(0);
+ outputBuffer[1] = testFunc(1);
+ outputBuffer[2] = testFunc(2);
+}