Skip to content

Commit 7af05ae

Browse files
atrosinenkodyung
authored andcommitted
[AArch64][PAC] Emit !dbg locations in *_vfpthunk_ functions (#179688)
The usage of pointers to member functions with Pointer Authentication requires generation of `*_vfpthunk_` functions. These thunk functions can be later inlined and optimized by replacing the indirect call instruction with a direct one and then inlining that function call. In absence of `!dbg` metadata attached to the original call instruction, such inlining ultimately results in an assertion "!dbg attachment points at wrong subprogram for function" in the assertions-enabled builds. By manually executing `opt` with `-verify-each` option on the LLVM IR produced by the frontend, an actual issue can be observed: "inlinable function call in a function with debug info must have a !dbg location" after the replacement of indirect call instruction with the direct one takes place. This commit fixes the issue by attaching artificial `!dbg` locations to the original call instruction (as well as most other instructions in `*_vfpthunk_` function) the same way it is done for other compiler-generated helper functions. (cherry picked from commit 903acc2)
1 parent fe58a85 commit 7af05ae

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3479,6 +3479,10 @@ ItaniumCXXABI::getOrCreateVirtualFunctionPointerThunk(const CXXMethodDecl *MD) {
34793479

34803480
CGF.StartFunction(GlobalDecl(), FnInfo.getReturnType(), ThunkFn, FnInfo,
34813481
FunctionArgs, MD->getLocation(), SourceLocation());
3482+
3483+
// Emit an artificial location for this function.
3484+
auto AL = ApplyDebugLocation::CreateArtificial(CGF);
3485+
34823486
llvm::Value *ThisVal = loadIncomingCXXThis(CGF);
34833487
setCXXABIThisValue(CGF, ThisVal);
34843488

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics \
2+
// RUN: -emit-llvm -std=c++11 -O1 -disable-llvm-passes \
3+
// RUN: -debug-info-kind=limited %s -o - | FileCheck %s
4+
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics \
5+
// RUN: -emit-llvm -std=c++11 -O1 -disable-llvm-passes \
6+
// RUN: -debug-info-kind=limited %s -o - | FileCheck %s
7+
8+
// Check that compiler-generated *_vfpthunk_ function has a !dbg location
9+
// attached to the call instruction.
10+
11+
// CHECK: define {{.*}}@_ZN1A2f0Ev_vfpthunk_({{.*}})
12+
// CHECK-SAME: !dbg ![[SCOPE_INDEX:[0-9]+]]
13+
// CHECK-NOT: define
14+
// CHECK: %[[DISCR:[0-9]+]] = call i64 @llvm.ptrauth.blend(i64 %{{[0-9]+}}, i64 9385)
15+
// CHECK-NOT: define
16+
// CHECK: musttail call void %{{[0-9]+}}(ptr
17+
// CHECK-SAME: [ "ptrauth"(i32 0, i64 %[[DISCR]]) ]
18+
// CHECK-SAME: !dbg ![[LOCATION_INDEX:[0-9]+]]
19+
20+
// CHECK: ![[SCOPE_INDEX]] = distinct !DISubprogram(
21+
// CHECK-SAME: linkageName: "_ZN1A2f0Ev_vfpthunk_"
22+
// CHECK-SAME: flags: DIFlagArtificial | DIFlagThunk
23+
// CHECK: ![[LOCATION_INDEX]] = !DILocation(line: 0, scope: ![[SCOPE_INDEX]])
24+
25+
volatile long T;
26+
27+
struct A {
28+
virtual void f0() {
29+
T = 0;
30+
}
31+
};
32+
typedef void (A::*MFP)();
33+
34+
void caller() {
35+
A a;
36+
37+
MFP x = &A::f0;
38+
(a.*x)();
39+
}

0 commit comments

Comments
 (0)