[llvm] de4e8bc - [HWASan] Properly handle musttail calls.
Matt Morehouse via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 1 11:24:02 PST 2022
Author: Matt Morehouse
Date: 2022-02-01T11:23:43-08:00
New Revision: de4e8bc3ace3eb64ac92166617056424f5bd5996
URL: https://github.com/llvm/llvm-project/commit/de4e8bc3ace3eb64ac92166617056424f5bd5996
DIFF: https://github.com/llvm/llvm-project/commit/de4e8bc3ace3eb64ac92166617056424f5bd5996.diff
LOG: [HWASan] Properly handle musttail calls.
Fixes a compile error when the `clang::musttail` attribute is used.
Reviewed By: eugenis
Differential Revision: https://reviews.llvm.org/D118712
Added:
compiler-rt/test/hwasan/TestCases/musttail.cpp
Modified:
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/hwasan/TestCases/musttail.cpp b/compiler-rt/test/hwasan/TestCases/musttail.cpp
new file mode 100644
index 000000000000..89b58e6331da
--- /dev/null
+++ b/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; }
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index fb10a99d1338..70b39449d243 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1531,9 +1531,14 @@ bool HWAddressSanitizer::sanitizeFunction(
}
}
- 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, CleanupReturnInst>(Inst)) {
RetVec.push_back(&Inst);
+ }
if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) {
for (Value *V : DVI->location_ops()) {
More information about the llvm-commits
mailing list