Skip to content

Commit d6dd8e8

Browse files
committed
Hack to workaround a clang lto bug
We hit an assert in AllocStackHoisting that is only triggered in a release lto build. Clang forwards the read of parent basic block of 'AssignedLoc' in the next statement: auto *EntryBB = AssignedLoc->getFunction()->getEntryBlock(); // read AssignedLoc->ParentBB AssignedLoc->removeFromParent(); // writes AssignedLoc->ParentBB To this read: EntryBB->push_front(AssignedLoc); // read AssignedLoc->ParentBB and assert if non-null, *should reload* As a temporary workaround outline code to prevent the miscompile. rdar://29982182
1 parent 8caa0e6 commit d6dd8e8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ insertDeallocStackAtEndOf(SmallVectorImpl<SILInstruction *> &FunctionExits,
110110
}
111111
}
112112

113+
/// Hack to workaround a clang LTO bug.
114+
__attribute__((noinline))
115+
void moveAllocStackToBeginningOfBlock(AllocStackInst* AS, SILBasicBlock *BB) {
116+
AS->removeFromParent();
117+
BB->push_front(AS);
118+
}
119+
113120
/// Assign a single alloc_stack instruction to all the alloc_stacks in the
114121
/// partition.
115122
void Partition::assignStackLocation(
@@ -120,8 +127,7 @@ void Partition::assignStackLocation(
120127

121128
// Move this assigned location to the beginning of the entry block.
122129
auto *EntryBB = AssignedLoc->getFunction()->getEntryBlock();
123-
AssignedLoc->removeFromParent();
124-
EntryBB->push_front(AssignedLoc);
130+
moveAllocStackToBeginningOfBlock(AssignedLoc, EntryBB);
125131

126132
// Erase the dealloc_stacks.
127133
eraseDeallocStacks(AssignedLoc);

0 commit comments

Comments
 (0)