Skip to content

Commit 297f48a

Browse files
committed
[constant-folding] Fix asan error.
1 parent 4df7b77 commit 297f48a

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,25 @@ ConstantFolder::processWorkList() {
17461746
continue;
17471747
}
17481748

1749+
// See if we have a CondFailMessage that we can canonicalize.
1750+
if (isApplyOfBuiltin(*I, BuiltinValueKind::CondFailMessage)) {
1751+
// See if our operand is a string literal inst. In such a case, fold into
1752+
// cond_fail instruction.
1753+
if (auto *sli = dyn_cast<StringLiteralInst>(I->getOperand(1))) {
1754+
if (sli->getEncoding() == StringLiteralInst::Encoding::UTF8) {
1755+
SILBuilderWithScope builder(I);
1756+
auto *cfi = builder.createCondFail(I->getLoc(), I->getOperand(0),
1757+
sli->getValue());
1758+
WorkList.insert(cfi);
1759+
recursivelyDeleteTriviallyDeadInstructions(
1760+
I, /*force*/ true,
1761+
[&](SILInstruction *DeadI) { WorkList.remove(DeadI); });
1762+
InvalidateInstructions = true;
1763+
}
1764+
}
1765+
continue;
1766+
}
1767+
17491768
// Go through all users of the constant and try to fold them.
17501769
FoldedUsers.clear();
17511770
for (auto Result : I->getResults()) {
@@ -1784,29 +1803,12 @@ ConstantFolder::processWorkList() {
17841803
WorkList.insert(User);
17851804
}
17861805

1787-
// See if we have a CondFailMessage. If we do, see if we can transform
1788-
// it into a UTF8.
1789-
if (auto *bi = dyn_cast<BuiltinInst>(User)) {
1790-
if (auto kind = bi->getBuiltinKind()) {
1791-
if (*kind == BuiltinValueKind::CondFailMessage) {
1792-
// See if our original instruction was a string literal inst.
1793-
if (auto *sli = dyn_cast<StringLiteralInst>(I)) {
1794-
if (sli->getEncoding() == StringLiteralInst::Encoding::UTF8) {
1795-
SILBuilderWithScope builder(bi);
1796-
auto *cfi = builder.createCondFail(
1797-
bi->getLoc(), bi->getOperand(0), sli->getValue());
1798-
WorkList.insert(cfi);
1799-
recursivelyDeleteTriviallyDeadInstructions(
1800-
bi, /*force*/ true,
1801-
[&](SILInstruction *DeadI) { WorkList.remove(DeadI); });
1802-
InvalidateInstructions = true;
1803-
continue;
1804-
}
1805-
}
1806-
1807-
// If we weren't able to simplify into a cond_fail, add it to the
1808-
// folded user set to see if the condfail msg is dead.
1809-
FoldedUsers.insert(bi);
1806+
// See if we have a CondFailMessage of a string_Literal. If we do, add
1807+
// it to the worklist, so we can clean it up.
1808+
if (isApplyOfBuiltin(*User, BuiltinValueKind::CondFailMessage)) {
1809+
if (auto *sli = dyn_cast<StringLiteralInst>(I)) {
1810+
if (sli->getEncoding() == StringLiteralInst::Encoding::UTF8) {
1811+
WorkList.insert(User);
18101812
}
18111813
}
18121814
}

0 commit comments

Comments
 (0)