Index: lib/CodeGen/SafeStack.cpp =================================================================== --- lib/CodeGen/SafeStack.cpp +++ lib/CodeGen/SafeStack.cpp @@ -459,6 +459,9 @@ AllocaInst *StackGuardSlot, Value *StackGuard) { Value *V = IRB.CreateLoad(StackGuardSlot); Value *Cmp = IRB.CreateICmpNE(StackGuard, V); + PointerType *GuardPtrType = dyn_cast(StackGuard->getType()); + // Zero the protector after it was checked to prohibit leaks. + IRB.CreateStore(ConstantPointerNull::get(GuardPtrType), StackGuardSlot, true); auto SuccessProb = BranchProbabilityInfo::getBranchProbStackProtector(true); auto FailureProb = BranchProbabilityInfo::getBranchProbStackProtector(false); Index: lib/CodeGen/StackProtector.cpp =================================================================== --- lib/CodeGen/StackProtector.cpp +++ lib/CodeGen/StackProtector.cpp @@ -445,6 +445,7 @@ // %1 = // %2 = load StackGuardSlot // %3 = cmp i1 %1, %2 + // store 0, StackGuardSlot // br i1 %3, label %SP_return, label %CallStackCheckFailBlk // // SP_return: @@ -480,6 +481,9 @@ Value *Guard = getStackGuard(TLI, M, B); LoadInst *LI2 = B.CreateLoad(AI, true); Value *Cmp = B.CreateICmpEQ(Guard, LI2); + PointerType *GuardPtrType = dyn_cast(Guard->getType()); + // Zero the protector after it was checked to prohibit leaks. + B.CreateStore(ConstantPointerNull::get(GuardPtrType), AI, true); auto SuccessProb = BranchProbabilityInfo::getBranchProbStackProtector(true); auto FailureProb =