[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / debug_task_shared.c
blobda52c9a5dd87139918a76530ad090318134ebdfe
1 // This testcase checks emission of debug info for variables
2 // inside shared clause of task construct.
4 // REQUIRES: x86-registered-target
6 // RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
7 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
8 // RUN: %clang_cc1 -debug-info-kind=line-directives-only -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
9 // RUN: %clang_cc1 -debug-info-kind=line-tables-only -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
10 // RUN: %clang_cc1 -debug-info-kind=limited -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
11 // expected-no-diagnostics
13 // CHECK-LABEL: define internal i32 @.omp_task_entry.
15 // CHECK-DAG: [[CONTEXT:%[0-9]+]] = load ptr, ptr %__context.addr.i, align 8
16 // CHECK-DAG: #dbg_declare(ptr [[CONTEXT]], [[SHARE2:![0-9]+]], !DIExpression(DW_OP_deref),
17 // CHECK-DAG: #dbg_declare(ptr [[CONTEXT]], [[SHARE3:![0-9]+]], !DIExpression(DW_OP_plus_uconst, 8, DW_OP_deref),
18 // CHECK-DAG: #dbg_declare(ptr [[CONTEXT]], [[SHARE1:![0-9]+]], !DIExpression(DW_OP_plus_uconst, 16, DW_OP_deref),
20 // CHECK-DAG: [[SHARE2]] = !DILocalVariable(name: "share2"
21 // CHECK-DAG: [[SHARE3]] = !DILocalVariable(name: "share3"
22 // CHECK-DAG: [[SHARE1]] = !DILocalVariable(name: "share1"
24 // NEG-LABEL: define internal i32 @.omp_task_entry.
25 // NEG: [[CONTEXT:%[0-9]+]] = load ptr, ptr %__context.addr.i, align 8
26 // NEG-NOT: #dbg_declare(ptr [[CONTEXT]], {{![0-9]+}}, !DIExpression(DW_OP_deref),
28 extern int printf(const char *, ...);
30 int foo(int n) {
31 int share1 = 9, share2 = 11, share3 = 13, priv1, priv2, fpriv;
32 fpriv = n + 4;
34 if (n < 2)
35 return n;
36 else {
37 #if SHARED
38 #pragma omp task shared(share1, share2) private(priv1, priv2) firstprivate(fpriv) shared(share3)
39 #else
40 #pragma omp task private(priv1, priv2) firstprivate(fpriv)
41 #endif
43 priv1 = n;
44 priv2 = n + 2;
45 share2 += share3;
46 printf("share1 = %d, share2 = %d, share3 = %d\n", share1, share2, share3);
47 share1 = priv1 + priv2 + fpriv + foo(n - 1) + share2 + share3;
49 #pragma omp taskwait
50 return share1 + share2 + share3;
54 int main() {
55 int n = 10;
56 printf("foo(%d) = %d\n", n, foo(n));
57 return 0;