diff options
| author | Yong He <yonghe@outlook.com> | 2024-04-12 14:40:30 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-12 14:40:30 -0700 |
| commit | b937207dccd05f700855e9aeb3f7c375b595b827 (patch) | |
| tree | 19146073437f9f02c7784f974519cce02ca7a6db /source/slang/slang-lower-to-ir.cpp | |
| parent | 565a871ad899c01dc6a1b4bdb1b9d2bc4281758f (diff) | |
Fix IR lowering bug of do-while loops. (#3941)
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 3f776c1a1..855bde6a6 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -5890,6 +5890,12 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> { auto irCondition = getSimpleVal(context, lowerRValueExpr(context, condExpr)); + + // One thing to be careful here is that lowering irCondition + // may create additional blocks due to short circuiting, so + // the block we are current inserting into is not necessarily + // the same as `testLabel`. + // auto invCondition = builder->emitNot(irCondition->getDataType(), irCondition); // Now we want to `break` if the loop condition is false, @@ -5907,15 +5913,15 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> // // mergeBlock: // goto breakLabel; - auto mergeBlock = builder->emitBlock(); - builder->emitBranch(loopHead); - - builder->setInsertInto(testLabel); + auto mergeBlock = builder->createBlock(); builder->emitIfElse( invCondition, breakLabel, mergeBlock, mergeBlock); + + insertBlock(mergeBlock); + builder->emitBranch(loopHead); } // Finally we insert the label that a `break` will jump to |
