[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / debug_threadprivate_copyin.c
blobac86299ff1600dd7d0d400aa0daf11a9fc00c2b9
1 // This testcase checks emission of debug info for threadprivate variables
2 // present in any clause of OpenMP construct.
4 // REQUIRES: x86-registered-target
6 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
7 // expected-no-diagnostics
9 // CHECK: define internal void @main.omp_outlined_debug__(
10 // CHECK: #dbg_declare(ptr %.global_tid..addr,
11 // CHECK: #dbg_declare(ptr %.bound_tid..addr,
12 // CHECK: #dbg_declare(ptr %nt.addr
13 // CHECK: store ptr %gbl_dynamic_int, ptr %gbl_dynamic_int.addr, align 8
14 // CHECK-NOT: #dbg_declare(ptr %gbl_dynamic_int.addr
15 // CHECK-NOT: #dbg_declare(ptr %gbl_static_int.addr
17 extern int printf(const char *, ...);
18 extern void omp_set_num_threads(int);
19 extern int omp_get_num_threads(void);
20 extern int omp_get_thread_num(void);
22 int gbl_dynamic_int;
23 __thread int gbl_static_int;
25 #pragma omp threadprivate(gbl_dynamic_int)
27 int main() {
28 int nt = 0;
29 int offset = 10;
30 gbl_dynamic_int = 55;
31 gbl_static_int = 77;
33 omp_set_num_threads(4);
34 #pragma omp parallel copyin(gbl_dynamic_int, gbl_static_int)
36 int data;
37 int tid;
38 nt = omp_get_num_threads();
39 tid = omp_get_thread_num();
40 data = gbl_dynamic_int + gbl_static_int;
41 gbl_dynamic_int += 10;
42 gbl_static_int += 20;
43 #pragma omp barrier
44 if (tid == 0)
45 printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
46 nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
47 if (tid == 1)
48 printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
49 nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
50 if (tid == 2)
51 printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
52 nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
53 if (tid == 3)
54 printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
55 nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
58 return 0;