summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-lower-to-ir.cpp13
-rw-r--r--tests/bugs/multiple-definitions.slang22
2 files changed, 35 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index e9381268b..ad7cec773 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -7154,6 +7154,19 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
auto funcDecl = as<FunctionDeclBase>(dd);
SLANG_ASSERT(funcDecl);
lowerFuncDecl(funcDecl);
+
+ // Note: Because we are iterating over multiple declarations,
+ // but only one will be registered as the value for `decl`
+ // in the global mapping by `ensureDecl()`, we have to take
+ // responsibility here for registering a lowered value
+ // for the remaining (non-primary) declarations.
+ //
+ // It doesn't really matter which one we register here, because
+ // they will all have the same mangled name in the IR, but we
+ // default to the `result` that is returned from this visitor,
+ // so that all the declarations share the same IR representative.
+ //
+ setGlobalValue(context->shared, funcDecl, result);
}
return result;
}
diff --git a/tests/bugs/multiple-definitions.slang b/tests/bugs/multiple-definitions.slang
new file mode 100644
index 000000000..5361c97bc
--- /dev/null
+++ b/tests/bugs/multiple-definitions.slang
@@ -0,0 +1,22 @@
+// multiple-definitions.slang
+//TEST:SIMPLE:-entry main -o multiple-definitions.hlsl
+
+__specialized_for_target(hlsl)
+int a(int x)
+{
+ int r = 0;
+ for(int i = 0; i < x; ++i) ++r;
+ return r;
+}
+
+__specialized_for_target(glsl)
+int a(int x)
+{
+ int r = 0;
+ for(int i = 0; i < x; ++i) ++r;
+ return r;
+}
+
+[shader("compute")]
+void main()
+{}