[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Profile / cxx-lambda.cpp
blob589f922c70782c00d3101c729a7e8a8d0ddb6946
1 // Tests for instrumentation of C++11 lambdas
3 // RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument=clang > %tgen
4 // RUN: FileCheck -allow-deprecated-dag-overlap --input-file=%tgen -check-prefix=PGOGEN %s
5 // RUN: FileCheck -allow-deprecated-dag-overlap --input-file=%tgen -check-prefix=LMBGEN %s
7 // RUN: llvm-profdata merge %S/Inputs/cxx-lambda.proftext -o %t.profdata
8 // RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse
9 // RUN: FileCheck -allow-deprecated-dag-overlap --input-file=%tuse -check-prefix=PGOUSE %s
10 // RUN: FileCheck -allow-deprecated-dag-overlap --input-file=%tuse -check-prefix=LMBUSE %s
12 // PGOGEN: @[[LWC:__profc__Z7lambdasv]] = {{(private|internal)}} global [4 x i64] zeroinitializer
13 // PGOGEN: @[[MAC:__profc_main]] = {{(private|internal)}} global [1 x i64] zeroinitializer
14 // LMBGEN: @[[LFC:"__profc_cxx_lambda.cpp__ZZ7lambdasvENK3\$_0clEi"]] = {{(private|internal)}} global [4 x i64] zeroinitializer
16 // PGOGEN-LABEL: define {{.*}}void @_Z7lambdasv()
17 // PGOUSE-LABEL: define {{.*}}void @_Z7lambdasv()
18 // PGOGEN: store {{.*}} @[[LWC]]
19 void lambdas() {
20 int i = 1;
22 // LMBGEN-LABEL: define internal{{( [0-9_a-z]*cc)?( noundef)?( zeroext)?}} i1 @"_ZZ7lambdasvENK3$_0clEi"(
23 // LMBUSE-LABEL: define internal{{( [0-9_a-z]*cc)?( noundef)?( zeroext)?}} i1 @"_ZZ7lambdasvENK3$_0clEi"(
24 // LMBGEN: store {{.*}} @[[LFC]]
25 auto f = [&i](int k) {
26 // LMBGEN: store {{.*}} @[[LFC]], i32 0, i32 1
27 // LMBUSE: br {{.*}} !prof ![[LF1:[0-9]+]]
28 if (i > 0) {
30 // LMBGEN: store {{.*}} @[[LFC]], i32 0, i32 2
31 // LMBUSE: br {{.*}} !prof ![[LF2:[0-9]+]]
32 return k && i;
35 // PGOGEN: store {{.*}} @[[LWC]], i32 0, i32 1
36 // PGOUSE: br {{.*}} !prof ![[LW1:[0-9]+]]
37 if (i) {}
39 // PGOGEN: store {{.*}} @[[LWC]], i32 0, i32 2
40 // PGOUSE: br {{.*}} !prof ![[LW2:[0-9]+]]
41 for (i = 0; i < 10; ++i)
42 f(9 - i);
44 // PGOGEN: store {{.*}} @[[LWC]], i32 0, i32 3
45 // PGOUSE: br {{.*}} !prof ![[LW3:[0-9]+]]
46 if (i) {}
49 // PGOUSE-DAG: ![[LW1]] = !{!"branch_weights", i32 2, i32 1}
50 // PGOUSE-DAG: ![[LW2]] = !{!"branch_weights", i32 11, i32 2}
51 // PGOUSE-DAG: ![[LW3]] = !{!"branch_weights", i32 2, i32 1}
53 // LMBUSE-DAG: ![[LF1]] = !{!"branch_weights", i32 10, i32 2}
54 // LMBUSE-DAG: ![[LF2]] = !{!"branch_weights", i32 10, i32 2}
56 int main(int argc, const char *argv[]) {
57 lambdas();
58 return 0;