Skip to content

Commit 0d6d6c3

Browse files
author
Frank Tetzel
committed
[CGP] Do not eliminate blocks which have their address taken
When eliminating a block, codegenprepare updates all blockaddress expressions which reference the block. In case the blockaddress is located in a different function, it leads to updates across function boundaries, which is problematic for a function pass like codegenprepare. If blockaddress is in a function defined before the current one, the update to the blockaddress is lost. This change adds a check to avoid eliminations of any block which has its address taken. Fixes: #161164 Change-Id: Ieebc50352234c332365d24ad0083cd51ae903e35
1 parent 50d65a5 commit 0d6d6c3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,12 @@ bool CodeGenPrepare::eliminateMostlyEmptyBlocks(Function &F) {
954954
bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB,
955955
BasicBlock *DestBB,
956956
bool isPreheader) {
957+
// Do not eliminate blocks which have their address taken.
958+
// This could lead to updates across functions which is problematic in a
959+
// function pass like codegenprepare. The update to a blockaddress in a
960+
// function defined before the function with the eliminated block is lost.
961+
if(BB->hasAddressTaken()) return false;
962+
957963
// Do not delete loop preheaders if doing so would create a critical edge.
958964
// Loop preheaders can be good locations to spill registers. If the
959965
// preheader is deleted and we create a critical edge, registers may be

0 commit comments

Comments
 (0)