1 ; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/callback-external-addr.perfscript --binary=%S/Inputs/callback-external-addr.perfbin --output=%t --skip-symbolization
2 ; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-UNWINDER
4 ; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/callback-external-addr.perfscript --binary=%S/Inputs/callback-external-addr.perfbin --output=%t --profile-summary-cold-count=0 --csspgo-preinliner=0 --gen-cs-nested-profile=0
5 ; RUN: FileCheck %s --input-file %t
7 ; Test if call stack is correctly truncated.
8 ; CHECK-UNWINDER-NOT: main:3 @ bar
9 ; CHECK-UNWINDER-NOT: main:3 @ foo
10 ; CHECK-UNWINDER-NOT: qux:3 @ baz
11 ; CHECK-UNWINDER-NOT: qux:3 @ bar
13 ; Test if return to wrong internal target
14 ; CHECK-UNWINDER-NOT: baz:0 @ bar
15 ; CHECK-UNWINDER-NOT: bar:0 @ baz
16 ; CHECK-UNWINDER-NOT: baz:0 @ main
17 ; CHECK-UNWINDER-NOT: bar:0 @ foo
18 ; CHECK-UNWINDER-NOT: baz:0 @ qux
20 ; Test for callback return from internal address to external address.
21 ; [foo:2 @ qux:2 @ callBeforeReturn] and [foo:2 @ qux:4 @ callAfterReturn] should exist
22 ; which means the callback return won't interrupt the previous call stack
28 ; CHECK-UNWINDER: ffffffffffc00001->690:13
29 ; CHECK-UNWINDER: ffffffffffc00001->6a0:7
30 ; CHECK-UNWINDER: ffffffffffc00001->715:7
31 ; CHECK-UNWINDER: ffffffffffc00001->730:5
32 ; CHECK-UNWINDER: ffffffffffc00001->7b0:5
33 ; CHECK-UNWINDER: [bar]
35 ; CHECK-UNWINDER: 690-69e:13
37 ; CHECK-UNWINDER: [baz]
39 ; CHECK-UNWINDER: 6a0-6ae:7
41 ; CHECK-UNWINDER: [foo]
43 ; CHECK-UNWINDER: 730-747:5
44 ; CHECK-UNWINDER: 74c-751:5
46 ; CHECK-UNWINDER: 747->6d0:5
47 ; CHECK-UNWINDER: [foo:2 @ qux]
49 ; CHECK-UNWINDER: 6d0-6e7:5
50 ; CHECK-UNWINDER: 6ec-710:6
51 ; CHECK-UNWINDER: 715-71b:7
52 ; CHECK-UNWINDER: 720-72b:6
54 ; CHECK-UNWINDER: 6e7->6b0:6
55 ; CHECK-UNWINDER: 71b->6c0:7
56 ; CHECK-UNWINDER: 72b->74c:6
57 ; CHECK-UNWINDER: [foo:2 @ qux:2 @ callBeforeReturn]
59 ; CHECK-UNWINDER: 6b0-6be:6
61 ; CHECK-UNWINDER: 6be->6ec:7
62 ; CHECK-UNWINDER: [foo:2 @ qux:4 @ callAfterReturn]
64 ; CHECK-UNWINDER: 6c0-6ce:7
66 ; CHECK-UNWINDER: 6ce->720:7
67 ; CHECK-UNWINDER: [main]
69 ; CHECK-UNWINDER: 77d-7ab:5
70 ; CHECK-UNWINDER: 7b0-7bf:5
72 ; CHECK-UNWINDER: 7bf->77d:5
74 ; CHECK: [foo:2 @ qux]:132:5
77 ; CHECK: 2: 6 callBeforeReturn:6
79 ; CHECK: 4: 7 callAfterReturn:7
95 ; CHECK: [foo:2 @ qux:4 @ callAfterReturn]:49:7
98 ; CHECK: [foo:2 @ qux:2 @ callBeforeReturn]:42:6
103 ; clang -shared -fPIC -o libcallback.so libcallback.c
105 int callback(int *cnt, int (*func1)(int), int (*func2)(int), int p) {
107 return func1(p) + func2(p);
111 ; clang test.c -O0 -g -fno-optimize-sibling-calls -fdebug-info-for-profiling -L $PWD -lcallback -fno-inline
117 int callback(int *cnt, int (*func1)(int), int (*func2)(int), int p);
127 int callBeforeReturn(int p) {
131 int callAfterReturn(int p) {
137 int ret = callBeforeReturn(p);
138 ret = callback(&callbackCnt, bar, baz, ret);
139 ret = callAfterReturn(ret);
150 for (int i = 0; i < 1000 * 1000; i++) {
151 sum += callback(&callbackCnt, foo, bar, i);
153 printf("callback count=%d, sum=%d\n", callbackCnt, sum);