Skip to content

Commit 2687495

Browse files
fix: rearrange so assert(false) not on return path
1 parent 156e5f1 commit 2687495

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

lib/seadsa/Graph.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ void Node::addAccessedType(unsigned off, llvm::Type *type) {
219219
tmp.push_back({o + i * sz, elementTy});
220220

221221
workList.insert(workList.end(), tmp.rbegin(), tmp.rend());
222-
} else if (const FixedVectorType *vty = dyn_cast<const FixedVectorType>(t)) {
222+
} else if (const FixedVectorType *vty =
223+
dyn_cast<const FixedVectorType>(t)) {
223224
uint64_t sz = vty->getElementType()->getPrimitiveSizeInBits() / 8;
224225
WorkList tmp;
225226
const size_t numElements(vty->getNumElements());
@@ -398,9 +399,8 @@ const Cell &Node::getLink(Field _f) const {
398399
assert(!FieldType::IsNotTypeAware());
399400
assert(!f.hasOmniType());
400401
Field omni = f.mkOmniField();
401-
if (m_links.count(omni)) return *m_links.at(omni);
402-
403-
assert(false); // unreachable
402+
assert(m_links.count(omni));
403+
return *m_links.at(omni);
404404
}
405405

406406
void Node::setLink(const Field _f, const Cell &c) {
@@ -463,7 +463,8 @@ void Node::addLink(Field _f, const Cell &c) {
463463
m_links = std::move(new_links);
464464

465465
// -- recreate links that have been removed by adding them through a cell
466-
// -- pointing to the current node. The cell takes care of resolving forwarding
466+
// -- pointing to the current node. The cell takes care of resolving
467+
// forwarding
467468
Cell cc(*this, 0);
468469
for (auto &kv : saved_links) {
469470
cc.addLink(kv.first, *kv.second);

lib/seadsa/RemovePtrToInt.cc

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,14 @@ static bool visitStoreInst(StoreInst *SI, Function &F, const DataLayout &DL,
168168
class PointerPromoter : public InstVisitor<PointerPromoter, Value *> {
169169
Type *m_ty;
170170
SmallPtrSetImpl<Instruction *> &m_toRemove;
171-
DenseMap<Value*, Value*> &m_toReplace;
171+
DenseMap<Value *, Value *> &m_toReplace;
172172
// -- to break cycles in PHINodes
173173
SmallPtrSet<Instruction *, 16> m_visited;
174174

175175
public:
176-
PointerPromoter(SmallPtrSetImpl<Instruction *> &toRemove, DenseMap<Value*, Value*> &toReplace)
177-
: m_ty(nullptr), m_toRemove(toRemove), m_toReplace(toReplace) {}
176+
PointerPromoter(SmallPtrSetImpl<Instruction *> &toRemove,
177+
DenseMap<Value *, Value *> &toReplace)
178+
: m_ty(nullptr), m_toRemove(toRemove), m_toReplace(toReplace) {}
178179

179180
Value *visitInstruction(Instruction &I) { return nullptr; }
180181

@@ -227,8 +228,9 @@ class PointerPromoter : public InstVisitor<PointerPromoter, Value *> {
227228
IRBuilder<> IRB(&I);
228229

229230
ptr = IRB.CreateBitCast(ptr, IRB.getInt8PtrTy());
230-
auto *gep = IRB.CreateGEP(ptr->getType()->getScalarType()->getPointerElementType(),
231-
ptr, {I.getOperand(1)});
231+
auto *gep =
232+
IRB.CreateGEP(ptr->getType()->getScalarType()->getPointerElementType(),
233+
ptr, I.getOperand(1));
232234
return IRB.CreateBitCast(gep, m_ty);
233235
}
234236

@@ -270,7 +272,7 @@ class PointerPromoter : public InstVisitor<PointerPromoter, Value *> {
270272
m_toRemove.insert(SI);
271273
} else if (isa<IntToPtrInst>(u)) {
272274
/* skip */;
273-
} else {
275+
} else {
274276
// -- if there is an interesting user, schedule it to be replaced
275277
if (!p2i) {
276278
IRB.SetInsertPoint(&I);
@@ -303,12 +305,11 @@ class PointerPromoter : public InstVisitor<PointerPromoter, Value *> {
303305
}
304306
};
305307

306-
static bool
307-
visitIntToPtrInst(IntToPtrInst *I2P, Function &F, const DataLayout &DL,
308-
DominatorTree &DT,
309-
SmallDenseMap<PHINode *, PHINode *> &NewPhis,
310-
SmallPtrSetImpl<Instruction *> &MaybeUnusedInsts,
311-
DenseMap<Value*, Value*> &RenameMap) {
308+
static bool visitIntToPtrInst(IntToPtrInst *I2P, Function &F,
309+
const DataLayout &DL, DominatorTree &DT,
310+
SmallDenseMap<PHINode *, PHINode *> &NewPhis,
311+
SmallPtrSetImpl<Instruction *> &MaybeUnusedInsts,
312+
DenseMap<Value *, Value *> &RenameMap) {
312313
assert(I2P);
313314

314315
auto *IntVal = I2P->getOperand(0);
@@ -413,7 +414,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
413414
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
414415
SmallPtrSet<StoreInst *, 8> StoresToErase;
415416
SmallPtrSet<Instruction *, 16> MaybeUnusedInsts;
416-
DenseMap<Value*, Value*> RenameMap;
417+
DenseMap<Value *, Value *> RenameMap;
417418
SmallDenseMap<PHINode *, PHINode *> NewPhis;
418419

419420
for (auto &BB : F) {
@@ -429,7 +430,8 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
429430
}
430431

431432
if (auto *I2P = dyn_cast<IntToPtrInst>(&I)) {
432-
Changed |= visitIntToPtrInst(I2P, F, DL, DT, NewPhis, MaybeUnusedInsts, RenameMap);
433+
Changed |= visitIntToPtrInst(I2P, F, DL, DT, NewPhis, MaybeUnusedInsts,
434+
RenameMap);
433435
continue;
434436
}
435437
}
@@ -442,7 +444,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
442444
llvm::make_filter_range(MaybeUnusedInsts, [](Instruction *I) {
443445
return isInstructionTriviallyDead(I);
444446
}));
445-
447+
446448
// TODO: RecursivelyDeleteTriviallyDeadInstructions takes a vector of
447449
// WeakTrackingVH since LLVM 11, which implies that `MaybeUnusedInsts` should
448450
// be a vector of WeakTrackingVH as well. See comment:
@@ -451,11 +453,10 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
451453
// removed before this call. So it should be safe to keep its original type
452454
// and map it to WeakTrackingVH as the following code does.
453455
SmallVector<WeakTrackingVH, 16> TriviallyDeadHandles;
454-
for (auto i : TriviallyDeadInstructions)
455-
TriviallyDeadHandles.emplace_back(WeakTrackingVH(i));
456-
457-
RecursivelyDeleteTriviallyDeadInstructions(TriviallyDeadHandles);
456+
for (auto i : TriviallyDeadInstructions)
457+
TriviallyDeadHandles.emplace_back(WeakTrackingVH(i));
458458

459+
RecursivelyDeleteTriviallyDeadInstructions(TriviallyDeadHandles);
459460

460461
for (auto kv : RenameMap) {
461462
kv.first->replaceAllUsesWith(kv.second);
@@ -464,9 +465,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
464465
DOG(llvm::errs() << "\n~~~~~~~ End of RP2I on " << F.getName() << " ~~~~~ \n";
465466
llvm::errs().flush());
466467

467-
if (Changed) {
468-
assert(!llvm::verifyFunction(F, &llvm::errs()));
469-
}
468+
if (Changed) { assert(!llvm::verifyFunction(F, &llvm::errs())); }
470469

471470
// llvm::errs() << F << "\n";
472471
return Changed;

0 commit comments

Comments
 (0)