diff options
Diffstat (limited to 'src/passes/Flatten.cpp')
-rw-r--r-- | src/passes/Flatten.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/passes/Flatten.cpp b/src/passes/Flatten.cpp index 37fa15b11..1c2cfbcd5 100644 --- a/src/passes/Flatten.cpp +++ b/src/passes/Flatten.cpp @@ -147,20 +147,24 @@ struct Flatten // arm preludes go in the arms. we must also remove an if value auto* originalIfTrue = iff->ifTrue; auto* originalIfFalse = iff->ifFalse; - auto type = iff->type; + auto type = iff->ifFalse ? Type::getLeastUpperBound(iff->ifTrue->type, + iff->ifFalse->type) + : Type::none; Expression* prelude = nullptr; if (type.isConcrete()) { Index temp = builder.addVar(getFunction(), type); if (iff->ifTrue->type.isConcrete()) { iff->ifTrue = builder.makeLocalSet(temp, iff->ifTrue); } - if (iff->ifFalse && iff->ifFalse->type.isConcrete()) { + if (iff->ifFalse->type.isConcrete()) { iff->ifFalse = builder.makeLocalSet(temp, iff->ifFalse); } - // the whole if (+any preludes from the condition) is now a prelude - prelude = rep; - // and we leave just a get of the value - rep = builder.makeLocalGet(temp, type); + if (curr->type.isConcrete()) { + // the whole if (+any preludes from the condition) is now a prelude + prelude = rep; + // and we leave just a get of the value + rep = builder.makeLocalGet(temp, type); + } } iff->ifTrue = getPreludesWithExpression(originalIfTrue, iff->ifTrue); if (iff->ifFalse) { |