| 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-LABEL: define internal void @_ZL10myCallbacki( |
| 13 |
// CHECK-SAME: {{.*}} !type [[F_CALLBACK:![0-9]+]] |
| 14 |
static void myCallback(int value) |
| 15 |
{ |
| 16 |
volatile int sink = value; |
| 17 |
(void)sink; |
| 18 |
} |
| 19 |
|
| 20 |
int takeCallbackAddress() { |
| 21 |
// Take the address of the callback explicitly (address-taken function) |
| 22 |
CallbackFn cb = &myCallback; |
| 23 |
// Store the address in a volatile pointer to keep it observable |
| 24 |
volatile void* addr = (void*)cb; |
| 25 |
(void)addr; |
| 26 |
|
| 27 |
return 0; |
| 28 |
} |
| 29 |
|
| 30 |
// CHECK: [[F_CALLBACK]] = !{i64 0, !"_ZTSFviE.generalized"} |