Skip to content

Commit de4e8bc

Browse files
committed
[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
1 parent 7a0cbe1 commit de4e8bc

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clangxx_hwasan -mllvm -hwasan-use-stack-safety=0 %s -o %t
2+
// RUN: %run %t
3+
//
4+
// REQUIRES: pointer-tagging
5+
6+
__attribute__((noinline)) int bar(int X) { return X; }
7+
8+
__attribute__((noinline)) int foo(int X) {
9+
volatile int A = 5;
10+
[[clang::musttail]] return bar(X + A);
11+
}
12+
13+
int main(int Argc, char *Argv[]) { return foo(Argc) != 6; }

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,9 +1531,14 @@ bool HWAddressSanitizer::sanitizeFunction(
15311531
}
15321532
}
15331533

1534-
if (isa<ReturnInst>(Inst) || isa<ResumeInst>(Inst) ||
1535-
isa<CleanupReturnInst>(Inst))
1534+
if (isa<ReturnInst>(Inst)) {
1535+
if (CallInst *CI = Inst.getParent()->getTerminatingMustTailCall())
1536+
RetVec.push_back(CI);
1537+
else
1538+
RetVec.push_back(&Inst);
1539+
} else if (isa<ResumeInst, CleanupReturnInst>(Inst)) {
15361540
RetVec.push_back(&Inst);
1541+
}
15371542

15381543
if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) {
15391544
for (Value *V : DVI->location_ops()) {

0 commit comments

Comments
 (0)