From 2bd896b9560e8310198c01a1b50f28910ba13baf Mon Sep 17 00:00:00 2001 From: Paul Robinson Date: Mon, 30 Sep 2019 15:08:38 +0000 Subject: [PATCH] [SSP] [2/3] Refactor an if/dyn_cast chain to switch on opcode. NFC Differential Revision: https://reviews.llvm.org/D67844 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373219 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/StackProtector.cpp | 39 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp index dc215a033fc..7cce1c597ff 100644 --- a/lib/CodeGen/StackProtector.cpp +++ b/lib/CodeGen/StackProtector.cpp @@ -158,33 +158,42 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge, bool StackProtector::HasAddressTaken(const Instruction *AI) { for (const User *U : AI->users()) { - if (const StoreInst *SI = dyn_cast(U)) { - if (AI == SI->getValueOperand()) + const auto *I = cast(U); + switch (I->getOpcode()) { + case Instruction::Store: + if (AI == cast(I)->getValueOperand()) return true; - } else if (const PtrToIntInst *SI = dyn_cast(U)) { - if (AI == SI->getOperand(0)) + break; + case Instruction::PtrToInt: + if (AI == cast(I)->getOperand(0)) return true; - } else if (const CallInst *CI = dyn_cast(U)) { + break; + case Instruction::Call: { // Ignore intrinsics that are not calls. TODO: Use isLoweredToCall(). + const auto *CI = cast(I); if (!isa(CI) && !CI->isLifetimeStartOrEnd()) return true; - } else if (isa(U)) { + break; + } + case Instruction::Invoke: return true; - } else if (const SelectInst *SI = dyn_cast(U)) { - if (HasAddressTaken(SI)) + case Instruction::BitCast: + case Instruction::GetElementPtr: + case Instruction::Select: + if (HasAddressTaken(I)) return true; - } else if (const PHINode *PN = dyn_cast(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(I); if (VisitedPHIs.insert(PN).second) if (HasAddressTaken(PN)) return true; - } else if (const GetElementPtrInst *GEP = dyn_cast(U)) { - if (HasAddressTaken(GEP)) - return true; - } else if (const BitCastInst *BI = dyn_cast(U)) { - if (HasAddressTaken(BI)) - return true; + break; + } + default: + break; } } return false; -- 2.40.0