summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-03-25 14:39:13 -0700
committerGitHub <noreply@github.com>2019-03-25 14:39:13 -0700
commitbedcb920045dd68f522e29d90fc3804f84bc08d0 (patch)
tree77de94c1a9304bc2c7361234993ff1eafb4b45a4 /tests
parent3ae31a6ed8d79c23b2ab5a7d7d755dd7e42618f7 (diff)
Fix handling of enum tags that aren't literals (#926)
An `enum` case currently lowers to the IR as the value of its tag expression, so if we have: ```hlsl enum E { X = 99, } ``` then `X` will lower as IR for the expression `99` which is just a literal. If instead we have: ```hlsl enum E { X = 99u, } ``` then after type checking the expression is `int(99u)`, which will get emitted to the global (module) scope as a cast/conversion instruction, that then gets referenced at the use sites of `E.X`. The emit logic wasn't set up to handle the case of referencing something directly from the global scope, so this change makes it so that side-effect-free global instructions are treated just like literal constants. This simple handling is fine for now since it will only apply to `enum` tag values (true global constants declared with `static const` have different handling).
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/enum-tag-conversion.slang31
-rw-r--r--tests/compute/enum-tag-conversion.slang.expected.txt4
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/compute/enum-tag-conversion.slang b/tests/compute/enum-tag-conversion.slang
new file mode 100644
index 000000000..66b4923e5
--- /dev/null
+++ b/tests/compute/enum-tag-conversion.slang
@@ -0,0 +1,31 @@
+// enum-tag-conversion.slang
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+// Confirm that a value of `enum` type can have an initializer
+// that includes basic operations like type conversion.
+
+enum RoseColors
+{
+ Red = 16u,
+}
+
+int test(int val)
+{
+ return val + RoseColors.Red;
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ int val = int(tid);
+ val = test(val);
+
+ outputBuffer[tid] = val;
+} \ No newline at end of file
diff --git a/tests/compute/enum-tag-conversion.slang.expected.txt b/tests/compute/enum-tag-conversion.slang.expected.txt
new file mode 100644
index 000000000..a0d427709
--- /dev/null
+++ b/tests/compute/enum-tag-conversion.slang.expected.txt
@@ -0,0 +1,4 @@
+10
+11
+12
+13