xref: /llvm-project/clang/test/OpenMP/debug_private.c (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1 // This testcase checks emission of debug info for variables inside
2 // private/firstprivate/lastprivate.
3 
4 // REQUIRES: x86-registered-target
5 
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 // RUN: %clang_cc1 -debug-info-kind=line-directives-only -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-tables-only -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=limited -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
10 // expected-no-diagnostics
11 
12 // CHECK: define internal i32 @.omp_task_entry.
13 
14 // CHECK:  #dbg_declare(ptr %.priv.ptr.addr.i, [[PRIV1:![0-9]+]], !DIExpression(DW_OP_deref),
15 // CHECK:  #dbg_declare(ptr %.priv.ptr.addr1.i, [[PRIV2:![0-9]+]], !DIExpression(DW_OP_deref),
16 // CHECK:  #dbg_declare(ptr %.firstpriv.ptr.addr.i, [[FPRIV:![0-9]+]], !DIExpression(DW_OP_deref),
17 // NEG-NOT: #dbg_declare
18 
19 // CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
20 // CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
21 // CHECK: [[FPRIV]] = !DILocalVariable(name: "fpriv"
22 
23 extern int printf(const char *, ...);
24 
foo(int n)25 int foo(int n) {
26   int res, priv1, priv2, fpriv;
27   fpriv = n + 4;
28 
29   if (n < 2)
30     return n;
31   else {
32 #pragma omp task shared(res) private(priv1, priv2) firstprivate(fpriv)
33     {
34       priv1 = n;
35       priv2 = n + 2;
36       printf("Task n=%d,priv1=%d,priv2=%d,fpriv=%d\n", n, priv1, priv2, fpriv);
37 
38       res = priv1 + priv2 + fpriv + foo(n - 1);
39     }
40 #pragma omp taskwait
41     return res;
42   }
43 }
44 
main()45 int main() {
46   int n = 10;
47   printf("foo(%d) = %d\n", n, foo(n));
48   return 0;
49 }
50