[PATCH] D67844: SSP: [2/3] Refactor an if-dyn_cast chain to switch on opcode. NFC
Paul Robinson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 08:09:02 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373219: [SSP] [2/3] Refactor an if/dyn_cast chain to switch on opcode. NFC (authored by probinson, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D67844?vs=221062&id=222439#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67844/new/
https://reviews.llvm.org/D67844
Files:
llvm/trunk/lib/CodeGen/StackProtector.cpp
Index: llvm/trunk/lib/CodeGen/StackProtector.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/StackProtector.cpp
+++ llvm/trunk/lib/CodeGen/StackProtector.cpp
@@ -158,33 +158,42 @@
bool StackProtector::HasAddressTaken(const Instruction *AI) {
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))
+ case Instruction::BitCast:
+ case Instruction::GetElementPtr:
+ case Instruction::Select:
+ if (HasAddressTaken(I))
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))
return true;
- } else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
- if (HasAddressTaken(GEP))
- return true;
- } else if (const BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
- if (HasAddressTaken(BI))
- return true;
+ break;
+ }
+ default:
+ break;
}
}
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67844.222439.patch
Type: text/x-patch
Size: 2218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/7ec8a594/attachment.bin>
More information about the llvm-commits
mailing list