diff options
Diffstat (limited to 'source/slang/slang-ir-clone.cpp')
| -rw-r--r-- | source/slang/slang-ir-clone.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/source/slang/slang-ir-clone.cpp b/source/slang/slang-ir-clone.cpp index df0555f9b..9f9349f99 100644 --- a/source/slang/slang-ir-clone.cpp +++ b/source/slang/slang-ir-clone.cpp @@ -228,7 +228,26 @@ IRInst* cloneInst( SLANG_ASSERT(builder); SLANG_ASSERT(oldInst); - auto newInst = cloneInstAndOperands( + IRInst* newInst = nullptr; + if( env->mapOldValToNew.TryGetValue(oldInst, newInst) ) + { + // In this case, somebody is trying to clone an + // instruction that already had been cloned + // (e.g., trying to clone a `param` in a function + // body that had already been mapped to a specialization) + // so we will make the operation safer and more + // convenient by just returning the registered value. + // + // TODO: There might be cases where the client doesn't + // want this convenience feature (because it could + // accidentally mask a bug), so we should consider + // having two versions of `cloneInst()` with one + // explicitly not including this feature. + // + return newInst; + } + + newInst = cloneInstAndOperands( env, builder, oldInst); env->mapOldValToNew.Add(oldInst, newInst); |
