xref: /llvm-project/llvm/test/tools/dsymutil/X86/Inputs/tail-call.cpp (revision f7052da6db8f85814adb2e1a6742d607e774bb88)
1*f7052da6SVedant Kumar /*
2*f7052da6SVedant Kumar  * This file is used to test dsymutil support for call site entries with tail
3*f7052da6SVedant Kumar  * calls (DW_AT_call_pc).
4*f7052da6SVedant Kumar  *
5*f7052da6SVedant Kumar  * Instructions for regenerating binaries (on Darwin/x86_64):
6*f7052da6SVedant Kumar  *
7*f7052da6SVedant Kumar  * 1. Copy the source to a top-level directory to work around having absolute
8*f7052da6SVedant Kumar  *    paths in the symtab's OSO entries.
9*f7052da6SVedant Kumar  *
10*f7052da6SVedant Kumar  *    mkdir -p /Inputs/ && cp tail-call.c /Inputs && cd /Inputs
11*f7052da6SVedant Kumar  *
12*f7052da6SVedant Kumar  * 2. Compile with call site info enabled. -O2 is used to get tail call
13*f7052da6SVedant Kumar  *    promotion.
14*f7052da6SVedant Kumar  *
15*f7052da6SVedant Kumar  *    clang -g -O2 tail-call.c -c -o tail-call.macho.x86_64.o
16*f7052da6SVedant Kumar  *    clang tail-call.macho.x86_64.o -o tail-call.macho.x86_64
17*f7052da6SVedant Kumar  *
18*f7052da6SVedant Kumar  * 3. Copy the binaries back into the repo's Inputs directory. You'll need
19*f7052da6SVedant Kumar  *    -oso-prepend-path=%p to link.
20*f7052da6SVedant Kumar  */
21*f7052da6SVedant Kumar 
22*f7052da6SVedant Kumar volatile int x;
23*f7052da6SVedant Kumar 
func2()24*f7052da6SVedant Kumar __attribute__((disable_tail_calls, noinline)) void func2() { x++; }
25*f7052da6SVedant Kumar 
func1()26*f7052da6SVedant Kumar __attribute__((noinline)) void func1() { func2(); /* tail */ }
27*f7052da6SVedant Kumar 
main()28*f7052da6SVedant Kumar __attribute__((disable_tail_calls)) int main() { func1(); /* regular */ }
29