Index: include/llvm/Target/TargetLowering.h =================================================================== --- include/llvm/Target/TargetLowering.h +++ include/llvm/Target/TargetLowering.h @@ -169,6 +169,13 @@ virtual bool useSoftFloat() const { return false; } + /// A target may require that no pointer passed from one function to another + /// points to the main stack. Such a target must override this function to + /// return true. SafeStack must always be used for such a target, to move + /// any stack allocation to the unsafe stack that is the target of a pointer + /// passed to a subroutine. + virtual bool useOnlyLocalStackPointers() const { return false; } + /// Return the pointer type for the given address space, defaults to /// the pointer type from the data layout. /// FIXME: The default needs to be removed once all the code is updated. Index: lib/CodeGen/SafeStack.cpp =================================================================== --- lib/CodeGen/SafeStack.cpp +++ lib/CodeGen/SafeStack.cpp @@ -308,6 +308,11 @@ case Instruction::Invoke: { ImmutableCallSite CS(I); + // FIXME: A more precise solution may consider whether particular types + // of intrinsics necessitate moving allocations to the unsafe stack. + if (TL->useOnlyLocalStackPointers()) + return false; + if (const IntrinsicInst *II = dyn_cast(I)) { if (II->getIntrinsicID() == Intrinsic::lifetime_start || II->getIntrinsicID() == Intrinsic::lifetime_end) Index: lib/Target/X86/X86ISelLowering.h =================================================================== --- lib/Target/X86/X86ISelLowering.h +++ lib/Target/X86/X86ISelLowering.h @@ -655,6 +655,7 @@ unsigned getJumpTableEncoding() const override; bool useSoftFloat() const override; + bool useOnlyLocalStackPointers() const override; MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override { return MVT::i8; Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -1985,6 +1985,10 @@ return Subtarget.useSoftFloat(); } +bool X86TargetLowering::useOnlyLocalStackPointers() const { + return Subtarget.useSeparateStackSeg(); +} + const MCExpr * X86TargetLowering::LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI, const MachineBasicBlock *MBB,