Skip to content

Commit 8de6150

Browse files
committed
ADT: Remove == and != comparisons between ilist iterators and pointers
I missed == and != when I removed implicit conversions between iterators and pointers in r252380 since they were defined outside ilist_iterator. Since they depend on getNodePtrUnchecked(), they indirectly rely on UB. This commit removes all uses of these operators. (I'll delete the operators themselves in a separate commit so that it can be easily reverted if necessary.) There should be NFC here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261498 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d73d33f commit 8de6150

File tree

14 files changed

+25
-23
lines changed

14 files changed

+25
-23
lines changed

include/llvm/Analysis/LoopInfoImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
277277
}
278278
assert(HasInsideLoopPreds && "Loop block has no in-loop predecessors!");
279279
assert(HasInsideLoopSuccs && "Loop block has no in-loop successors!");
280-
assert(BB != getHeader()->getParent()->begin() &&
280+
assert(BB != &getHeader()->getParent()->front() &&
281281
"Loop contains function entry block!");
282282

283283
NumVisited++;

lib/Analysis/ScalarEvolutionExpander.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,9 +1654,9 @@ Value *SCEVExpander::expand(const SCEV *S) {
16541654
// there) so that it is guaranteed to dominate any user inside the loop.
16551655
if (L && SE.hasComputableLoopEvolution(S, L) && !PostIncLoops.count(L))
16561656
InsertPt = &*L->getHeader()->getFirstInsertionPt();
1657-
while (InsertPt != Builder.GetInsertPoint()
1658-
&& (isInsertedInstruction(InsertPt)
1659-
|| isa<DbgInfoIntrinsic>(InsertPt))) {
1657+
while (InsertPt->getIterator() != Builder.GetInsertPoint() &&
1658+
(isInsertedInstruction(InsertPt) ||
1659+
isa<DbgInfoIntrinsic>(InsertPt))) {
16601660
InsertPt = &*std::next(InsertPt->getIterator());
16611661
}
16621662
break;

lib/CodeGen/MachineLoopInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ void MachineLoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
5050
MachineBasicBlock *MachineLoop::getTopBlock() {
5151
MachineBasicBlock *TopMBB = getHeader();
5252
MachineFunction::iterator Begin = TopMBB->getParent()->begin();
53-
if (TopMBB != Begin) {
53+
if (TopMBB->getIterator() != Begin) {
5454
MachineBasicBlock *PriorMBB = &*std::prev(TopMBB->getIterator());
5555
while (contains(PriorMBB)) {
5656
TopMBB = PriorMBB;
57-
if (TopMBB == Begin) break;
57+
if (TopMBB->getIterator() == Begin)
58+
break;
5859
PriorMBB = &*std::prev(TopMBB->getIterator());
5960
}
6061
}
@@ -64,7 +65,7 @@ MachineBasicBlock *MachineLoop::getTopBlock() {
6465
MachineBasicBlock *MachineLoop::getBottomBlock() {
6566
MachineBasicBlock *BotMBB = getHeader();
6667
MachineFunction::iterator End = BotMBB->getParent()->end();
67-
if (BotMBB != std::prev(End)) {
68+
if (BotMBB->getIterator() != std::prev(End)) {
6869
MachineBasicBlock *NextMBB = &*std::next(BotMBB->getIterator());
6970
while (contains(NextMBB)) {
7071
BotMBB = NextMBB;

lib/CodeGen/MachineVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ MachineVerifier::visitMachineBasicBlockBefore(const MachineBasicBlock *MBB) {
560560
// it is an entry block or landing pad.
561561
for (const auto &LI : MBB->liveins()) {
562562
if (isAllocatable(LI.PhysReg) && !MBB->isEHPad() &&
563-
MBB != MBB->getParent()->begin()) {
563+
MBB->getIterator() != MBB->getParent()->begin()) {
564564
report("MBB has allocable live-in, but isn't entry or landing-pad.", MBB);
565565
}
566566
}

lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ void SelectionDAG::DeleteNode(SDNode *N) {
644644
}
645645

646646
void SelectionDAG::DeleteNodeNotInCSEMaps(SDNode *N) {
647-
assert(N != AllNodes.begin() && "Cannot delete the entry node!");
647+
assert(N->getIterator() != AllNodes.begin() &&
648+
"Cannot delete the entry node!");
648649
assert(N->use_empty() && "Cannot delete a node that is not dead!");
649650

650651
// Drop all of the operands and decrement used node's use counts.
@@ -6653,7 +6654,7 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
66536654
if (Degree == 0) {
66546655
// All of P's operands are sorted, so P may sorted now.
66556656
P->setNodeId(DAGSize++);
6656-
if (P != SortedPos)
6657+
if (P->getIterator() != SortedPos)
66576658
SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(P));
66586659
assert(SortedPos != AllNodes.end() && "Overran node list");
66596660
++SortedPos;
@@ -6662,7 +6663,7 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
66626663
P->setNodeId(Degree);
66636664
}
66646665
}
6665-
if (&Node == SortedPos) {
6666+
if (Node.getIterator() == SortedPos) {
66666667
#ifndef NDEBUG
66676668
allnodes_iterator I(N);
66686669
SDNode *S = &*++I;

lib/CodeGen/SjLjEHPrepare.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) {
419419
// directly to the caller's context, which is what we want anyway, so no need
420420
// to do anything here.
421421
for (BasicBlock &BB : F) {
422-
if (&BB == F.begin())
422+
if (&BB == &F.front())
423423
continue;
424424
for (Instruction &I : BB)
425425
if (I.mayThrow())
@@ -434,7 +434,7 @@ bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) {
434434
// Following any allocas not in the entry block, update the saved SP in the
435435
// jmpbuf to the new value.
436436
for (BasicBlock &BB : F) {
437-
if (&BB == F.begin())
437+
if (&BB == &F.front())
438438
continue;
439439
for (Instruction &I : BB) {
440440
if (auto *CI = dyn_cast<CallInst>(&I)) {

lib/Target/ARM/ARMConstantIslandPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,7 @@ adjustJTTargetBlockForward(MachineBasicBlock *BB, MachineBasicBlock *JTBB) {
22512251
// If the block ends in an unconditional branch, move it. The prior block
22522252
// has to have an analyzable terminator for us to move this one. Be paranoid
22532253
// and make sure we're not trying to move the entry block of the function.
2254-
if (!B && Cond.empty() && BB != MF->begin() &&
2254+
if (!B && Cond.empty() && BB != &MF->front() &&
22552255
!TII->AnalyzeBranch(*OldPrior, TBB, FBB, CondPrior)) {
22562256
BB->moveAfter(JTBB);
22572257
OldPrior->updateTerminator();

lib/Target/X86/X86MCInstLower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ static MachineBasicBlock::const_iterator
988988
PrevCrossBBInst(MachineBasicBlock::const_iterator MBBI) {
989989
const MachineBasicBlock *MBB = MBBI->getParent();
990990
while (MBBI == MBB->begin()) {
991-
if (MBB == MBB->getParent()->begin())
991+
if (MBB == &MBB->getParent()->front())
992992
return nullptr;
993993
MBB = MBB->getPrevNode();
994994
MBBI = MBB->end();

lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static bool addArgumentAttrs(const SCCNodeSet &SCCNodes) {
535535
UE = Tracker.Uses.end();
536536
UI != UE; ++UI) {
537537
Node->Uses.push_back(AG[*UI]);
538-
if (*UI != A)
538+
if (*UI != &*A)
539539
HasNonLocalUses = true;
540540
}
541541
}

lib/Transforms/ObjCARC/ObjCARCContract.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ bool ObjCARCContract::tryToPeepholeInstruction(
436436
// If it's an invoke, we have to cross a block boundary. And we have
437437
// to carefully dodge no-op instructions.
438438
do {
439-
if (&*BBI == InstParent->begin()) {
439+
if (BBI == InstParent->begin()) {
440440
BasicBlock *Pred = InstParent->getSinglePredecessor();
441441
if (!Pred)
442442
goto decline_rv_optimization;

0 commit comments

Comments
 (0)