Skip to content

Commit 76817ab

Browse files
pogo59tstellar
authored andcommitted
Merging r373219:
------------------------------------------------------------------------ r373219 | probinson | 2019-09-30 08:08:38 -0700 (Mon, 30 Sep 2019) | 3 lines [SSP] [2/3] Refactor an if/dyn_cast chain to switch on opcode. NFC Differential Revision: https://reviews.llvm.org/D67844 ------------------------------------------------------------------------
1 parent c1d76f4 commit 76817ab

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

llvm/lib/CodeGen/StackProtector.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,33 +159,42 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
159159
bool StackProtector::HasAddressTaken(const Instruction *AI,
160160
SmallPtrSetImpl<const PHINode *> &VisitedPHIs) {
161161
for (const User *U : AI->users()) {
162-
if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
163-
if (AI == SI->getValueOperand())
162+
const auto *I = cast<Instruction>(U);
163+
switch (I->getOpcode()) {
164+
case Instruction::Store:
165+
if (AI == cast<StoreInst>(I)->getValueOperand())
164166
return true;
165-
} else if (const PtrToIntInst *SI = dyn_cast<PtrToIntInst>(U)) {
166-
if (AI == SI->getOperand(0))
167+
break;
168+
case Instruction::PtrToInt:
169+
if (AI == cast<PtrToIntInst>(I)->getOperand(0))
167170
return true;
168-
} else if (const CallInst *CI = dyn_cast<CallInst>(U)) {
171+
break;
172+
case Instruction::Call: {
169173
// Ignore intrinsics that are not calls. TODO: Use isLoweredToCall().
174+
const auto *CI = cast<CallInst>(I);
170175
if (!isa<DbgInfoIntrinsic>(CI) && !CI->isLifetimeStartOrEnd())
171176
return true;
172-
} else if (isa<InvokeInst>(U)) {
177+
break;
178+
}
179+
case Instruction::Invoke:
173180
return true;
174-
} else if (const SelectInst *SI = dyn_cast<SelectInst>(U)) {
175-
if (HasAddressTaken(SI, VisitedPHIs))
181+
case Instruction::BitCast:
182+
case Instruction::GetElementPtr:
183+
case Instruction::Select:
184+
if (HasAddressTaken(I, VisitedPHIs))
176185
return true;
177-
} else if (const PHINode *PN = dyn_cast<PHINode>(U)) {
186+
break;
187+
case Instruction::PHI: {
178188
// Keep track of what PHI nodes we have already visited to ensure
179189
// they are only visited once.
190+
const auto *PN = cast<PHINode>(I);
180191
if (VisitedPHIs.insert(PN).second)
181192
if (HasAddressTaken(PN, VisitedPHIs))
182193
return true;
183-
} else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
184-
if (HasAddressTaken(GEP, VisitedPHIs))
185-
return true;
186-
} else if (const BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
187-
if (HasAddressTaken(BI, VisitedPHIs))
188-
return true;
194+
break;
195+
}
196+
default:
197+
break;
189198
}
190199
}
191200
return false;

0 commit comments

Comments
 (0)