Files
llvm-project/clang/test/CodeGen/call-graph-section-callback.cpp
Prabhu Rajasekaran 550b62cbcb [clang] callee_type metadata for indirect calls (#163233)
Create and add generalized type identifier metadata to indirect calls,
and to functions which are potential indirect call targets.

The functions carry the !type metadata. The indirect callsites carry a
list of !type metadata values under !callee_type metadata.

RFC:
https://discourse.llvm.org/t/rfc-call-graph-information-from-clang-llvm-for-c-c/88255
2025-10-21 08:02:52 -07:00

31 lines
965 B
C++

// Tests that callback function whose address is taken is attached Type ID metadata
// as it is a potential indirect call target.
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fexperimental-call-graph-section \
// RUN: -emit-llvm -o %t %s
// RUN: FileCheck %s < %t
////////////////////////////////////////////////////////////////////////////////
typedef void (*CallbackFn)(int);
// Callback function with "internal" linkage.
// CHECK-LABEL: define internal void @_ZL10myCallbacki(
// CHECK-SAME: {{.*}} !type [[F_CALLBACK:![0-9]+]]
static void myCallback(int value)
{
volatile int sink = value;
(void)sink;
}
int takeCallbackAddress() {
// Take the address of the callback explicitly (address-taken function)
CallbackFn cb = &myCallback;
// Store the address in a volatile pointer to keep it observable
volatile void* addr = (void*)cb;
(void)addr;
return 0;
}
// CHECK: [[F_CALLBACK]] = !{i64 0, !"_ZTSFviE.generalized"}