diff --git a/compiler-rt/test/hwasan/TestCases/musttail.cpp b/compiler-rt/test/hwasan/TestCases/musttail.cpp new file mode 100644 --- /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 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1531,9 +1531,14 @@ } } - if (isa(Inst) || isa(Inst) || - isa(Inst)) + if (isa(Inst)) { + if (CallInst *CI = Inst.getParent()->getTerminatingMustTailCall()) + RetVec.push_back(CI); + else + RetVec.push_back(&Inst); + } else if (isa(Inst)) { RetVec.push_back(&Inst); + } if (auto *DVI = dyn_cast(&Inst)) { for (Value *V : DVI->location_ops()) {