Skip to content

Commit d388837

Browse files
authored
Merge pull request #22178 from gottesmm/pr-dddd2694ec260afaf09db5b3ad66c9a296e6c666
[ownership] Eliminate an unused bool return value and resulting dead …
2 parents 1761b4b + b56f6ee commit d388837

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

lib/SIL/LinearLifetimeChecker.cpp

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,21 @@ struct State {
8181

8282
void initializeAllNonConsumingUses(
8383
ArrayRef<BranchPropagatedUser> nonConsumingUsers);
84-
bool initializeAllConsumingUses(
84+
void initializeAllConsumingUses(
8585
ArrayRef<BranchPropagatedUser> consumingUsers,
8686
SmallVectorImpl<BrPropUserAndBlockPair> &predsToAddToWorklist);
8787

88-
/// Initializes state for a consuming use. Returns true if we have not yet
89-
/// seen a consuming use in the same block yet. Returns false if detect such a
90-
/// condition so users know that a use-after-free was detected.
91-
bool initializeConsumingUse(BranchPropagatedUser consumingUser,
88+
/// Initializes state for a consuming use.
89+
///
90+
/// If we are already tracking a consuming use for the block, this emits a
91+
/// double consume checker error.
92+
void initializeConsumingUse(BranchPropagatedUser consumingUser,
9293
SILBasicBlock *userBlock);
9394

94-
/// Returns true if the given block contains a non-consuming use that is
95-
/// strictly later in the block than a consuming use. If all
96-
/// non-consuming uses are before the consuming use, the block is
97-
/// removed from the blocksWithNonConsumingUses map to show that the uses
98-
/// were found to properly be post-dominated by a consuming use.
99-
bool checkForSameBlockUseAfterFree(BranchPropagatedUser consumingUser,
95+
/// Check that this newly initialized consuming user does not have any
96+
/// non-consuming uses after it. If the checker finds one, it emits a checker
97+
/// error.
98+
void checkForSameBlockUseAfterFree(BranchPropagatedUser consumingUser,
10099
SILBasicBlock *userBlock);
101100

102101
/// Once we have marked all of our producing blocks.
@@ -181,27 +180,22 @@ void State::initializeAllNonConsumingUses(
181180
// Consuming Use Initialization
182181
//===----------------------------------------------------------------------===//
183182

184-
bool State::initializeAllConsumingUses(
183+
void State::initializeAllConsumingUses(
185184
ArrayRef<BranchPropagatedUser> consumingUses,
186185
SmallVectorImpl<std::pair<BranchPropagatedUser, SILBasicBlock *>>
187186
&predsToAddToWorklist) {
188-
bool noErrors = true;
189187
for (BranchPropagatedUser user : consumingUses) {
190188
SILBasicBlock *userBlock = user.getParent();
191189

192-
// First initialize our state for the consuming user. This returns false if
193-
// we found another consuming instruction associated with userBlock and true
194-
// if we successfully associated user with userBlock.
195-
if (!initializeConsumingUse(user, userBlock)) {
196-
// We already handled the error.
197-
noErrors &= handleError([] {});
198-
}
190+
// First initialize our state for the consuming user.
191+
//
192+
// If we find another consuming instruction associated with userBlock this
193+
// will emit a checker error.
194+
initializeConsumingUse(user, userBlock);
199195

200-
// Then check if the given block has a use after free.
201-
if (checkForSameBlockUseAfterFree(user, userBlock)) {
202-
// We already handled the error.
203-
noErrors &= handleError([] {});
204-
}
196+
// Then check if the given block has a use after free and emit an error if
197+
// we find one.
198+
checkForSameBlockUseAfterFree(user, userBlock);
205199

206200
// If this user is in the same block as the value, do not visit
207201
// predecessors. We must be extra tolerant here since we allow for
@@ -216,32 +210,30 @@ bool State::initializeAllConsumingUses(
216210
predsToAddToWorklist.push_back({user, pred});
217211
}
218212
}
219-
220-
return noErrors;
221213
}
222214

223-
bool State::initializeConsumingUse(BranchPropagatedUser consumingUser,
215+
void State::initializeConsumingUse(BranchPropagatedUser consumingUser,
224216
SILBasicBlock *userBlock) {
225217
// Map this user to the block. If we already have a value for the block, then
226218
// we have a double consume and need to fail.
227219
if (blocksWithConsumingUses.insert(userBlock).second)
228-
return true;
220+
return;
229221

230-
return handleError([&] {
222+
handleError([&] {
231223
llvm::errs() << "Function: '" << value->getFunction()->getName() << "'\n"
232224
<< "Found over consume?!\n"
233225
<< "Value: " << *value << "User: " << *consumingUser
234226
<< "Block: bb" << userBlock->getDebugID() << "\n\n";
235227
});
236228
}
237229

238-
bool State::checkForSameBlockUseAfterFree(BranchPropagatedUser consumingUser,
230+
void State::checkForSameBlockUseAfterFree(BranchPropagatedUser consumingUser,
239231
SILBasicBlock *userBlock) {
240232
// If we do not have any consuming uses in the same block as our
241233
// consuming user, then we can not have a same block use-after-free.
242234
auto iter = blocksWithNonConsumingUses.find(userBlock);
243235
if (iter == blocksWithNonConsumingUses.end())
244-
return false;
236+
return;
245237

246238
BranchPropagatedUser nonConsumingUser = iter->second;
247239

@@ -252,14 +244,15 @@ bool State::checkForSameBlockUseAfterFree(BranchPropagatedUser consumingUser,
252244
// always consider the non-consuming use to be a use after free since
253245
// the cond branch user is in a previous block. So just bail early.
254246
if (consumingUser.isCondBranchUser()) {
255-
return !handleError([&]() {
247+
handleError([&]() {
256248
llvm::errs() << "Function: '" << value->getFunction()->getName() << "'\n"
257249
<< "Found use after free?!\n"
258250
<< "Value: " << *value
259251
<< "Consuming User: " << *consumingUser
260252
<< "Non Consuming User: " << *iter->second << "Block: bb"
261253
<< userBlock->getDebugID() << "\n\n";
262254
});
255+
return;
263256
}
264257

265258
// Ok. At this point, we know that our consuming user is not a cond branch
@@ -268,7 +261,7 @@ bool State::checkForSameBlockUseAfterFree(BranchPropagatedUser consumingUser,
268261
// consuming use. and continue.
269262
if (nonConsumingUser.isCondBranchUser()) {
270263
blocksWithNonConsumingUses.erase(iter);
271-
return false;
264+
return;
272265
}
273266

274267
// Otherwise, we know that both of our users are non-cond branch users and
@@ -278,19 +271,20 @@ bool State::checkForSameBlockUseAfterFree(BranchPropagatedUser consumingUser,
278271
[&nonConsumingUser](const SILInstruction &i) -> bool {
279272
return nonConsumingUser == &i;
280273
}) != userBlock->end()) {
281-
return !handleError([&] {
274+
handleError([&] {
282275
llvm::errs() << "Function: '" << value->getFunction()->getName() << "'\n"
283276
<< "Found use after free?!\n"
284277
<< "Value: " << *value
285278
<< "Consuming User: " << *consumingUser
286279
<< "Non Consuming User: " << *iter->second << "Block: bb"
287280
<< userBlock->getDebugID() << "\n\n";
288281
});
282+
return;
289283
}
290284

291285
// Erase the use since we know that it is properly joint post-dominated.
292286
blocksWithNonConsumingUses.erase(iter);
293-
return false;
287+
return;
294288
}
295289

296290
bool State::checkPredsForDoubleConsume(BranchPropagatedUser consumingUser,

0 commit comments

Comments
 (0)