- Modify the stack protector algorithm so that the stack slot is allocated in
  LLVM IR code and not in the selection DAG ISel. This is a cleaner solution.

- Fix the heuristic for determining if protectors are necessary. The previous
  one wasn't checking the proper type size.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58824 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
index a0c30ff..3e19b71 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
@@ -3801,14 +3801,10 @@
     MachineFrameInfo *MFI = MF.getFrameInfo();
     MVT PtrTy = TLI.getPointerTy();
 
-    // Retrieve the stack protector guard's value.
-    SDValue Src = getValue(I.getOperand(1));
+    SDValue Src = getValue(I.getOperand(1));   // The guard's value.
+    AllocaInst *Slot = cast<AllocaInst>(I.getOperand(2));
 
-    // Create a slot on the stack for the stack protector. It should go first
-    // before local variables are allocated.
-    unsigned Align =
-      TLI.getTargetData()->getPrefTypeAlignment(PtrTy.getTypeForMVT());
-    int FI = MFI->CreateStackObject(PtrTy.getSizeInBits() / 8, Align);
+    int FI = FuncInfo.StaticAllocaMap[Slot];
     MFI->setStackProtectorIndex(FI);
 
     SDValue FIN = DAG.getFrameIndex(FI, PtrTy);