]> granicus.if.org Git - llvm/commitdiff
[safestack] Requires a valid TargetMachine to be passed to the SafeStack pass.
authorDavid L Kreitzer <david.l.kreitzer@intel.com>
Tue, 4 Oct 2016 20:31:32 +0000 (20:31 +0000)
committerDavid L Kreitzer <david.l.kreitzer@intel.com>
Tue, 4 Oct 2016 20:31:32 +0000 (20:31 +0000)
Patch by Michael LeMay

Differential revision: http://reviews.llvm.org/D24896

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283248 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SafeStack.cpp

index 4a1b9958a5b5f39f640bec3ca145d21ed1618291..7fc46c20234df0975687aff21a4ab433103838b8 100644 (file)
@@ -358,9 +358,8 @@ bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) {
 
 Value *SafeStack::getOrCreateUnsafeStackPtr(IRBuilder<> &IRB, Function &F) {
   // Check if there is a target-specific location for the unsafe stack pointer.
-  if (TL)
-    if (Value *V = TL->getSafeStackPointerLocation(IRB))
-      return V;
+  if (Value *V = TL->getSafeStackPointerLocation(IRB))
+    return V;
 
   // Otherwise, assume the target links with compiler-rt, which provides a
   // thread-local variable with a magic name.
@@ -393,9 +392,7 @@ Value *SafeStack::getOrCreateUnsafeStackPtr(IRBuilder<> &IRB, Function &F) {
 }
 
 Value *SafeStack::getStackGuard(IRBuilder<> &IRB, Function &F) {
-  Value *StackGuardVar = nullptr;
-  if (TL)
-    StackGuardVar = TL->getIRStackGuard(IRB);
+  Value *StackGuardVar = TL->getIRStackGuard(IRB);
   if (!StackGuardVar)
     StackGuardVar =
         F.getParent()->getOrInsertGlobal("__stack_chk_guard", StackPtrTy);
@@ -752,7 +749,9 @@ bool SafeStack::runOnFunction(Function &F) {
     return false;
   }
 
-  TL = TM ? TM->getSubtargetImpl(F)->getTargetLowering() : nullptr;
+  if (!TM)
+    report_fatal_error("Target machine is required");
+  TL = TM->getSubtargetImpl(F)->getTargetLowering();
   SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
 
   ++NumFunctions;