@@ -159,33 +159,42 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
159
159
bool StackProtector::HasAddressTaken (const Instruction *AI,
160
160
SmallPtrSetImpl<const PHINode *> &VisitedPHIs) {
161
161
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 ())
164
166
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 ))
167
170
return true ;
168
- } else if (const CallInst *CI = dyn_cast<CallInst>(U)) {
171
+ break ;
172
+ case Instruction::Call: {
169
173
// Ignore intrinsics that are not calls. TODO: Use isLoweredToCall().
174
+ const auto *CI = cast<CallInst>(I);
170
175
if (!isa<DbgInfoIntrinsic>(CI) && !CI->isLifetimeStartOrEnd ())
171
176
return true ;
172
- } else if (isa<InvokeInst>(U)) {
177
+ break ;
178
+ }
179
+ case Instruction::Invoke:
173
180
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))
176
185
return true ;
177
- } else if (const PHINode *PN = dyn_cast<PHINode>(U)) {
186
+ break ;
187
+ case Instruction::PHI: {
178
188
// Keep track of what PHI nodes we have already visited to ensure
179
189
// they are only visited once.
190
+ const auto *PN = cast<PHINode>(I);
180
191
if (VisitedPHIs.insert (PN).second )
181
192
if (HasAddressTaken (PN, VisitedPHIs))
182
193
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 ;
189
198
}
190
199
}
191
200
return false ;
0 commit comments