summaryrefslogtreecommitdiff
path: root/source/slang/slang-lower-to-ir.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-12 14:40:30 -0700
committerGitHub <noreply@github.com>2024-04-12 14:40:30 -0700
commitb937207dccd05f700855e9aeb3f7c375b595b827 (patch)
tree19146073437f9f02c7784f974519cce02ca7a6db /source/slang/slang-lower-to-ir.cpp
parent565a871ad899c01dc6a1b4bdb1b9d2bc4281758f (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.cpp14
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