summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-01-16 09:15:02 -0800
committerGitHub <noreply@github.com>2019-01-16 09:15:02 -0800
commitc260e6aa3a7dc3e6794442daacde3ae23f029e0b (patch)
tree2985f616ac8085168b1c5dce13f566f217559fc9
parentf0633a7d0b1615f6b115d53763bedeeb857b7f3c (diff)
Fix a bug in IR linking (#777)
The IR linking logic was recently rewritten to use the (optional) `IRLinkageDecoration`s instead of assuming `IRGlobalVals` always have a mangled name field, and in that process a bug seems to have crept in where in the case that an instruction that would usually quality as a "global value" does *not* have linkage, we were failing to register the instruction we create in the output module as a replacement for the original instruction. This problem affects `static` variables inside of functions, leading to them potentially getting emitted multiple times.
-rw-r--r--source/slang/ir-link.cpp2
-rw-r--r--tests/bugs/static-var.slang22
-rw-r--r--tests/bugs/static-var.slang.expected.txt4
3 files changed, 27 insertions, 1 deletions
diff --git a/source/slang/ir-link.cpp b/source/slang/ir-link.cpp
index 586172cb2..25d3b40b6 100644
--- a/source/slang/ir-link.cpp
+++ b/source/slang/ir-link.cpp
@@ -990,7 +990,7 @@ IRInst* cloneGlobalValueWithLinkage(
{
// If there is no mangled name, then we assume this is a local symbol,
// and it can't possibly have multiple declarations.
- return cloneGlobalValueImpl(context, originalVal, IROriginalValuesForClone());
+ return cloneGlobalValueImpl(context, originalVal, IROriginalValuesForClone(originalVal));
}
//
diff --git a/tests/bugs/static-var.slang b/tests/bugs/static-var.slang
new file mode 100644
index 000000000..f060586ad
--- /dev/null
+++ b/tests/bugs/static-var.slang
@@ -0,0 +1,22 @@
+// gh-775-ext.slang
+//TEST(compute):COMPARE_COMPUTE:
+
+int test(int inVal)
+{
+ static int kVal = 16;
+ return inVal + kVal;
+}
+
+//TEST_INPUT:ubuffer(data=[9 9 9 9], stride=4):dxbinding(0),glbinding(0),out
+RWStructuredBuffer<int> outputBuffer : register(u0);
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ int inVal = int(tid);
+ int outVal = test(inVal);
+
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/bugs/static-var.slang.expected.txt b/tests/bugs/static-var.slang.expected.txt
new file mode 100644
index 000000000..a0d427709
--- /dev/null
+++ b/tests/bugs/static-var.slang.expected.txt
@@ -0,0 +1,4 @@
+10
+11
+12
+13