[llvm] StackProtector: use isInTailCallPosition to verify tail call position (PR #68997)

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 08:36:43 PDT 2023


================
@@ -520,17 +521,12 @@ bool StackProtector::InsertStackProtectors() {
     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_or_null<CallInst>(Prev)) {
+      if (CI->isTailCall() && isInTailCallPosition(*CI, *TM)) {
         CheckLoc = Prev;
+      }
----------------
compnerd wrote:

I don't know if it really does (LLVM style does allow you to elide unnecessary braces which does help density. I would at least drop the inner ones, but like @RKSimon, I would personally prefer dropping both sets.

https://github.com/llvm/llvm-project/pull/68997


More information about the llvm-commits mailing list