Skip to content

Commit cd19403

Browse files
committed
CFG: add throwing links from calls to out?
1 parent 777d950 commit cd19403

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/cfg/cfg-traversal.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,21 @@ struct CFGWalker : public PostWalker<SubType, VisitorType> {
161161
// exit blocks to flow to.
162162
bool hasSyntheticExit = false;
163163

164+
// Given a basic block, add a link to the exit block, indicating this block
165+
// can reach the outside (unwind).
166+
void linkToExit(BasicBlock* block) {
167+
// TODO simplify exit/hasSynth
168+
if (!hasSyntheticExit) {
169+
exit = makeBasicBlock();
170+
hasSyntheticExit = true;
171+
}
172+
link(block, exit);
173+
}
174+
164175
static void doEndReturn(SubType* self, Expression** currp) {
165176
auto* last = self->currBasicBlock;
166177
self->startUnreachableBlock();
167-
if (!self->exit) {
168-
// This is our first exit block and may be our only exit block, so just
169-
// set it.
170-
self->exit = last;
171-
} else if (!self->hasSyntheticExit) {
172-
// We now have multiple exit blocks, so we need to create a synthetic one.
173-
// It will be added to the list of basic blocks at the end of the
174-
// function.
175-
auto* lastExit = self->exit;
176-
self->exit = self->makeBasicBlock();
177-
self->link(lastExit, self->exit);
178-
self->link(last, self->exit);
179-
self->hasSyntheticExit = true;
180-
} else {
181-
// We already have a synthetic exit block. Just link it up.
182-
self->link(last, self->exit);
183-
}
178+
self->linkToExit(last);
184179
}
185180

186181
static void doStartIfTrue(SubType* self, Expression** currp) {
@@ -354,6 +349,11 @@ struct CFGWalker : public PostWalker<SubType, VisitorType> {
354349
// the outside) can only happen at the end of basic blocks.
355350
auto* last = self->currBasicBlock;
356351
self->link(last, self->startBasicBlock());
352+
353+
if (!self->ignoreBranchesOutsideOfFunc) {
354+
// Add a branch to the outside of the func.
355+
self->linkToExit(last);
356+
}
357357
}
358358
}
359359

0 commit comments

Comments
 (0)