summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-12-07 18:18:31 -0800
committerGitHub <noreply@github.com>2020-12-07 18:18:31 -0800
commitb8e1f62fb9cc66481b35231149448e47f096d257 (patch)
tree4b12bca0e0648fb4424e6e0a0f3803c241b7b66e /source
parent0404fefd7f783d43b5bb636383797adbd593af51 (diff)
Fix a subtle bug introduced into type legalization (#1632)
The refactor of type legalization in PR #1594 introduced a subtle problem where an IR instruction might be removed from the hierachy (perhaps because its parent was removed during legalization) but would still be on the work list. Legalization of such instructions is wasteful (since it would never impact the output), but it also creates a problem if we try to insert new legalized instructions next to such a removed instruction. The logic for inserting an instruction before/after another asserts that the sibling instruction must have a parent, and leads to a failure in debug builds and a potential crash in release builds. This change adds a bit of defensive code to skip any instructions that appear to have been removed from the hierarchy (because they have no parent and are not the root/module instruction). An alternative approach would be to try to detect these instructions at the point where they would be added to the work list, but this approach seems simpler and more general.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-legalize-types.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/source/slang/slang-ir-legalize-types.cpp b/source/slang/slang-ir-legalize-types.cpp
index 91427ce9c..97571f117 100644
--- a/source/slang/slang-ir-legalize-types.cpp
+++ b/source/slang/slang-ir-legalize-types.cpp
@@ -2620,6 +2620,18 @@ struct IRTypeLegalizationPass
void processInst(IRInst* inst)
{
+ // It is possible that an insturction we
+ // encounterer during the legalization process
+ // will be one that was already removed or
+ // otherwise made redundant.
+ //
+ // We want to skip such instructions since there
+ // would not be a valid location at which to
+ // store their replacements.
+ //
+ if(!inst->getParent() && inst->op != kIROp_Module)
+ return;
+
// The main logic for legalizing an instruction is defined
// earlier in this file.
//