summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-07-16 21:41:09 -0700
committerGitHub <noreply@github.com>2025-07-17 04:41:09 +0000
commit5937e1e6bb3afcf84b01abadcf1eb527933449f3 (patch)
tree5bf183e1d83e2827fc9b3663a549b7a83f363663
parentcff6eab5453fba6e29e2ff4167c36fdb31d624b3 (diff)
Fix duplicate mangled names for interface requirements (#7764)
* Fix duplicate mangled names for interface requirements Remove linkage decorations from interface method requirement values to prevent duplicate mangled names and allow DCE to clean up unused functions. Interface requirements only need the type information, not the linkage, so the generated IRFunc with export decorations was causing conflicts. Fixes #7761 Co-authored-by: Yong He <csyonghe@users.noreply.github.com> * Move linkage decoration removal into default case of switch Move the removeLinkageDecorations call into the default case of the switch statement so it only applies to general requirements and not special cases like associated types. Co-authored-by: Yong He <csyonghe@users.noreply.github.com> * Remove conditional check for linkage decoration removal Apply removeLinkageDecorations unconditionally to interface requirement values to ensure all requirement values have their linkage decorations removed. Co-authored-by: Yong He <csyonghe@users.noreply.github.com> * Change removeLinkageDecorations parameter type from IRGlobalValueWithCode* to IRInst* This fixes build errors by allowing the function to accept the broader IRInst* type, making it compatible with the unconditional call in the interface requirement processing. Co-authored-by: Yong He <csyonghe@users.noreply.github.com> * format code (#7787) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Yong He <csyonghe@users.noreply.github.com> Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
-rw-r--r--source/slang/slang-ir-util.cpp15
-rw-r--r--source/slang/slang-ir-util.h2
-rw-r--r--source/slang/slang-lower-to-ir.cpp5
3 files changed, 15 insertions, 7 deletions
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp
index c8d76569f..1b11f8165 100644
--- a/source/slang/slang-ir-util.cpp
+++ b/source/slang/slang-ir-util.cpp
@@ -997,12 +997,15 @@ void sortBlocksInFunc(IRGlobalValueWithCode* func)
block->insertAtEnd(func);
}
-void removeLinkageDecorations(IRGlobalValueWithCode* func)
+void removeLinkageDecorations(IRInst* inst)
{
+ if (!inst)
+ return;
+
List<IRInst*> toRemove;
- for (auto inst : func->getDecorations())
+ for (auto decoration : inst->getDecorations())
{
- switch (inst->getOp())
+ switch (decoration->getOp())
{
case kIROp_ImportDecoration:
case kIROp_ExportDecoration:
@@ -1013,14 +1016,14 @@ void removeLinkageDecorations(IRGlobalValueWithCode* func)
case kIROp_CudaDeviceExportDecoration:
case kIROp_DllExportDecoration:
case kIROp_HLSLExportDecoration:
- toRemove.add(inst);
+ toRemove.add(decoration);
break;
default:
break;
}
}
- for (auto inst : toRemove)
- inst->removeAndDeallocate();
+ for (auto decoration : toRemove)
+ decoration->removeAndDeallocate();
}
void setInsertBeforeOrdinaryInst(IRBuilder* builder, IRInst* inst)
diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h
index f47026185..77c464b1f 100644
--- a/source/slang/slang-ir-util.h
+++ b/source/slang/slang-ir-util.h
@@ -253,7 +253,7 @@ IRInst* emitLoopBlocks(
void sortBlocksInFunc(IRGlobalValueWithCode* func);
// Remove all linkage decorations from func.
-void removeLinkageDecorations(IRGlobalValueWithCode* func);
+void removeLinkageDecorations(IRInst* inst);
IRInst* findInterfaceRequirement(IRInterfaceType* type, IRInst* key);
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index 4b232e829..1f5909e94 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -9344,6 +9344,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
switch (requirementVal->getOp())
{
default:
+ // Remove linkage decorations from the requirement value to prevent
+ // duplicate mangled names and allow DCE to clean up unused functions.
+ // Interface requirements only need the type information, not the linkage.
+ removeLinkageDecorations(requirementVal);
+
// For the majority of requirements, we only care about its type in an
// interface definition, so we store only the type from the lowered IR
// in the interface entry.