[PATCH] D118712: [HWASan] Properly handle musttail calls.

Matt Morehouse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 1 09:08:38 PST 2022


morehouse created this revision.
morehouse added reviewers: eugenis, vitalybuka.
Herald added a subscriber: hiraditya.
morehouse requested review of this revision.
Herald added projects: Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers.

Fixes a compile error when the `clang::musttail` attribute is used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118712

Files:
  compiler-rt/test/hwasan/TestCases/musttail.cpp
  llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1531,9 +1531,14 @@
         }
       }
 
-      if (isa<ReturnInst>(Inst) || isa<ResumeInst>(Inst) ||
-          isa<CleanupReturnInst>(Inst))
+      if (isa<ReturnInst>(Inst)) {
+        if (CallInst *CI = Inst.getParent()->getTerminatingMustTailCall())
+          RetVec.push_back(CI);
+        else
+          RetVec.push_back(&Inst);
+      } else if (isa<ResumeInst>(Inst) || isa<CleanupReturnInst>(Inst)) {
         RetVec.push_back(&Inst);
+      }
 
       if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) {
         for (Value *V : DVI->location_ops()) {
Index: compiler-rt/test/hwasan/TestCases/musttail.cpp
===================================================================
--- /dev/null
+++ compiler-rt/test/hwasan/TestCases/musttail.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx_hwasan -mllvm -hwasan-use-stack-safety=0 %s -o %t
+// RUN: %run %t
+//
+// REQUIRES: pointer-tagging
+
+__attribute__((noinline)) int bar(int X) { return X; }
+
+__attribute__((noinline)) int foo(int X) {
+  volatile int A = 5;
+  [[clang::musttail]] return bar(X + A);
+}
+
+int main(int Argc, char *Argv[]) { return foo(Argc) != 6; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118712.404963.patch
Type: text/x-patch
Size: 1392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220201/71829c60/attachment.bin>


More information about the llvm-commits mailing list