Skip to content

Commit a9345a7

Browse files
committed
Add test to cover callback/internal linkage/addresstaken case.
1 parent 9ac4b00 commit a9345a7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Tests that callback function whose address is taken is attached Type ID metadata
2+
// as it is a potential indirect call target.
3+
4+
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fexperimental-call-graph-section \
5+
// RUN: -emit-llvm -o %t %s
6+
// RUN: FileCheck %s < %t
7+
8+
////////////////////////////////////////////////////////////////////////////////
9+
typedef void (*CallbackFn)(int);
10+
11+
// Callback function with "internal" linkage.
12+
// CHECK-DAG: define internal void @_ZL10myCallbacki({{.*}} !type [[F_CALLBACK:![0-9]+]]
13+
static void myCallback(int value)
14+
{
15+
volatile int sink = value;
16+
(void)sink;
17+
}
18+
19+
int takeCallbackAddress() {
20+
// Take the address of the callback explicitly (address-taken function)
21+
CallbackFn cb = &myCallback;
22+
// Store the address in a volatile pointer to keep it observable
23+
volatile void* addr = (void*)cb;
24+
(void)addr;
25+
26+
return 0;
27+
}
28+
29+
// CHECK-DAG: [[F_CALLBACK]] = !{i64 0, !"_ZTSFviE.generalized"}

0 commit comments

Comments
 (0)