| 461 | } |
| 462 | |
| 463 | void SafeStack::checkStackGuard(IRBuilder<> &IRB, Function &F, ReturnInst &RI, |
| 464 | AllocaInst *StackGuardSlot, Value *StackGuard) { |
| 465 | Value *V = IRB.CreateLoad(StackGuardSlot); |
| 466 | Value *Cmp = IRB.CreateICmpNE(StackGuard, V); |
| 467 | |
| 468 | auto SuccessProb = BranchProbabilityInfo::getBranchProbStackProtector(true); |
| 469 | auto FailureProb = BranchProbabilityInfo::getBranchProbStackProtector(false); |
| 470 | MDNode *Weights = MDBuilder(F.getContext()) |
| 471 | .createBranchWeights(SuccessProb.getNumerator(), |
| 472 | FailureProb.getNumerator()); |
| 473 | Instruction *CheckTerm = |
| 474 | SplitBlockAndInsertIfThen(Cmp, &RI, |
| 475 | /* Unreachable */ true, Weights); |
| 476 | IRBuilder<> IRBFail(CheckTerm); |
| 477 | // FIXME: respect -fsanitize-trap / -ftrap-function here? |
| 478 | Constant *StackChkFail = F.getParent()->getOrInsertFunction( |
| 479 | "__stack_chk_fail", IRB.getVoidTy()); |
| 480 | IRBFail.CreateCall(StackChkFail, {}); |
| 481 | } |
| 482 | |
| 483 | /// We explicitly compute and set the unsafe stack layout for all unsafe |
| 484 | /// static alloca instructions. We save the unsafe "base pointer" in the |
nothing calls this directly
no test coverage detected