diff options
author | Liqiang TAO <taolq@outlook.com> | 2025-03-31 02:21:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-30 11:21:19 -0700 |
commit | 1f7f268f304d02f0cea33ab63a21de57ba4a5a3c (patch) | |
tree | 3ccd7479cfbe54745f80faa90c8eb177f9a90887 /llvm/lib/CodeGen/StackProtector.cpp | |
parent | 5715510d00d44d97a0024caf864e649225372281 (diff) | |
download | llvm-1f7f268f304d02f0cea33ab63a21de57ba4a5a3c.zip llvm-1f7f268f304d02f0cea33ab63a21de57ba4a5a3c.tar.gz llvm-1f7f268f304d02f0cea33ab63a21de57ba4a5a3c.tar.bz2 |
StackProtector: use isInTailCallPosition to verify tail call position (#68997)
The issue is caused by [D133860](https://reviews.llvm.org/D133860).
The guard would be inserted in wrong place in some cases, like the test
case showed below.
This patch fixed the issue by using `isInTailCallPosition()` to verify
whether the tail call is in right position.
Diffstat (limited to 'llvm/lib/CodeGen/StackProtector.cpp')
-rw-r--r-- | llvm/lib/CodeGen/StackProtector.cpp | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp index e823df3..eb07e5d 100644 --- a/llvm/lib/CodeGen/StackProtector.cpp +++ b/llvm/lib/CodeGen/StackProtector.cpp @@ -20,6 +20,7 @@ #include "llvm/Analysis/BranchProbabilityInfo.h" #include "llvm/Analysis/MemoryLocation.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" +#include "llvm/CodeGen/Analysis.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetLowering.h" #include "llvm/CodeGen/TargetPassConfig.h" @@ -625,18 +626,11 @@ bool InsertStackProtectors(const TargetMachine *TM, Function *F, HasIRCheck = true; // If we're instrumenting a block with a tail call, the check has to be - // inserted before the call rather than between it and the return. The - // verifier guarantees that a tail call is either directly before the - // return or with a single correct bitcast of the return value in between so - // we don't need to worry about many situations here. + // inserted before the call rather than between it and the return. Instruction *Prev = CheckLoc->getPrevNonDebugInstruction(); - if (Prev && isa<CallInst>(Prev) && cast<CallInst>(Prev)->isTailCall()) - CheckLoc = Prev; - else if (Prev) { - Prev = Prev->getPrevNonDebugInstruction(); - if (Prev && isa<CallInst>(Prev) && cast<CallInst>(Prev)->isTailCall()) + if (auto *CI = dyn_cast_if_present<CallInst>(Prev)) + if (CI->isTailCall() && isInTailCallPosition(*CI, *TM)) CheckLoc = Prev; - } // Generate epilogue instrumentation. The epilogue intrumentation can be // function-based or inlined depending on which mechanism the target is |