aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Robinson <paul.robinson@sony.com>2019-09-30 15:08:38 +0000
committerTom Stellard <tstellar@redhat.com>2019-11-21 15:41:34 -0800
commit76817ab1e1043d269f415928fabd3f4a533b7e83 (patch)
treedf0da914280fd5fe642c7cda6dd04c15979ac62c
parentc1d76f45b49744023a33dd024066ce27a89beed9 (diff)
downloadllvm-76817ab1e1043d269f415928fabd3f4a533b7e83.zip
llvm-76817ab1e1043d269f415928fabd3f4a533b7e83.tar.gz
llvm-76817ab1e1043d269f415928fabd3f4a533b7e83.tar.bz2
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 ------------------------------------------------------------------------
-rw-r--r--llvm/lib/CodeGen/StackProtector.cpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index aa55bb3..68e902c2 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/lib/CodeGen/StackProtector.cpp
@@ -159,33 +159,42 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
bool StackProtector::HasAddressTaken(const Instruction *AI,
SmallPtrSetImpl<const PHINode *> &VisitedPHIs) {
for (const User *U : AI->users()) {
- if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
- if (AI == SI->getValueOperand())
+ const auto *I = cast<Instruction>(U);
+ switch (I->getOpcode()) {
+ case Instruction::Store:
+ if (AI == cast<StoreInst>(I)->getValueOperand())
return true;
- } else if (const PtrToIntInst *SI = dyn_cast<PtrToIntInst>(U)) {
- if (AI == SI->getOperand(0))
+ break;
+ case Instruction::PtrToInt:
+ if (AI == cast<PtrToIntInst>(I)->getOperand(0))
return true;
- } else if (const CallInst *CI = dyn_cast<CallInst>(U)) {
+ break;
+ case Instruction::Call: {
// Ignore intrinsics that are not calls. TODO: Use isLoweredToCall().
+ const auto *CI = cast<CallInst>(I);
if (!isa<DbgInfoIntrinsic>(CI) && !CI->isLifetimeStartOrEnd())
return true;
- } else if (isa<InvokeInst>(U)) {
+ break;
+ }
+ case Instruction::Invoke:
return true;
- } else if (const SelectInst *SI = dyn_cast<SelectInst>(U)) {
- if (HasAddressTaken(SI, VisitedPHIs))
+ case Instruction::BitCast:
+ case Instruction::GetElementPtr:
+ case Instruction::Select:
+ if (HasAddressTaken(I, VisitedPHIs))
return true;
- } else if (const PHINode *PN = dyn_cast<PHINode>(U)) {
+ break;
+ case Instruction::PHI: {
// Keep track of what PHI nodes we have already visited to ensure
// they are only visited once.
+ const auto *PN = cast<PHINode>(I);
if (VisitedPHIs.insert(PN).second)
if (HasAddressTaken(PN, VisitedPHIs))
return true;
- } else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
- if (HasAddressTaken(GEP, VisitedPHIs))
- return true;
- } else if (const BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
- if (HasAddressTaken(BI, VisitedPHIs))
- return true;
+ break;
+ }
+ default:
+ break;
}
}
return false;