diff options
author | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-09-13 21:15:20 +0000 |
---|---|---|
committer | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-09-13 21:15:20 +0000 |
commit | 618c555bbefd2c73a874590deeb952df08a7af8e (patch) | |
tree | 20c165031da3f6927a5a5d63257b681dbac88d2e /llvm/lib/CodeGen/SafeStack.cpp | |
parent | 44550600f295b4bd3486da95507d37c600d1539e (diff) | |
download | llvm-618c555bbefd2c73a874590deeb952df08a7af8e.zip llvm-618c555bbefd2c73a874590deeb952df08a7af8e.tar.gz llvm-618c555bbefd2c73a874590deeb952df08a7af8e.tar.bz2 |
[CodeGen] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 313194
Diffstat (limited to 'llvm/lib/CodeGen/SafeStack.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SafeStack.cpp | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp index 8584a9b..8cc6bb0 100644 --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -1,4 +1,4 @@ -//===-- SafeStack.cpp - Safe Stack Insertion ------------------------------===// +//===- SafeStack.cpp - Safe Stack Insertion -------------------------------===// // // The LLVM Compiler Infrastructure // @@ -17,37 +17,56 @@ #include "SafeStackColoring.h" #include "SafeStackLayout.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" -#include "llvm/ADT/Triple.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/BranchProbabilityInfo.h" +#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" -#include "llvm/CodeGen/Passes.h" +#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/CodeGen/TargetPassConfig.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/CallSite.h" +#include "llvm/IR/ConstantRange.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/InstIterator.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Use.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" #include "llvm/Pass.h" -#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/Format.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/raw_os_ostream.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetLowering.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetSubtargetInfo.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Local.h" -#include "llvm/Transforms/Utils/ModuleUtils.h" +#include <algorithm> +#include <cassert> +#include <cstdint> +#include <string> +#include <utility> using namespace llvm; using namespace llvm::safestack; @@ -255,16 +274,16 @@ bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) { assert(V == UI.get()); switch (I->getOpcode()) { - case Instruction::Load: { + case Instruction::Load: if (!IsAccessSafe(UI, DL.getTypeStoreSize(I->getType()), AllocaPtr, AllocaSize)) return false; break; - } + case Instruction::VAArg: // "va-arg" from a pointer is safe. break; - case Instruction::Store: { + case Instruction::Store: if (V == I->getOperand(0)) { // Stored the pointer - conservatively assume it may be unsafe. DEBUG(dbgs() << "[SafeStack] Unsafe alloca: " << *AllocaPtr @@ -276,11 +295,10 @@ bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) { AllocaPtr, AllocaSize)) return false; break; - } - case Instruction::Ret: { + + case Instruction::Ret: // Information leak. return false; - } case Instruction::Call: case Instruction::Invoke: { @@ -372,7 +390,7 @@ void SafeStack::findInsts(Function &F, StackRestorePoints.push_back(LP); } else if (auto II = dyn_cast<IntrinsicInst>(&I)) { if (II->getIntrinsicID() == Intrinsic::gcroot) - llvm::report_fatal_error( + report_fatal_error( "gcroot intrinsic not compatible with safestack attribute"); } } @@ -764,11 +782,12 @@ bool SafeStack::run() { } class SafeStackLegacyPass : public FunctionPass { - const TargetMachine *TM; + const TargetMachine *TM = nullptr; public: static char ID; // Pass identification, replacement for typeid.. - SafeStackLegacyPass() : FunctionPass(ID), TM(nullptr) { + + SafeStackLegacyPass() : FunctionPass(ID) { initializeSafeStackLegacyPassPass(*PassRegistry::getPassRegistry()); } @@ -817,9 +836,10 @@ public: } }; -} // anonymous namespace +} // end anonymous namespace char SafeStackLegacyPass::ID = 0; + INITIALIZE_PASS_BEGIN(SafeStackLegacyPass, DEBUG_TYPE, "Safe Stack instrumentation pass", false, false) INITIALIZE_PASS_DEPENDENCY(TargetPassConfig) |