[PATCH] D114504: [clang][DebugInfo] Debug support for private variables inside an OpenMP task construct

Alok Kumar Sharma via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 23 22:59:14 PST 2021


alok created this revision.
alok added reviewers: aprantl, djtodoro.
alok added a project: debug-info.
Herald added subscribers: pengfei, guansong, yaxunl.
alok requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Currently variables appearing inside private/firstprivate/lastprivate
clause of openmp task construct are not visible inside lldb debugger.
This is because compiler does not generate debug info for it.

Please consider the testcase debug_private.c attached with patch.

  ```

(lldb) b 34
Breakpoint 1: where = a.out`.omp_task_entry. + 243 [inlined] .omp_outlined. + 157 at debug_private.c:28, address = 0x00000000004008f3
(lldb) r
Process 18475 launched: '/tmp/a.out' (x86_64)
Task n=10,priv1=10,priv2=12,fpriv=14
Process 18475 stopped

- thread #1, name = 'a.out', stop reason = breakpoint 1.1 frame #0: 0x00000000004008f3 a.out`.omp_task_entry. [inlined] .omp_outlined.(.global_tid.=0, .part_id.=0x000000000070d3d0, .privates.=0x000000000070d3e8, .copy_fn.=(a.out`.omp_task_privates_map. at debug_private.c:28), .task_t.=0x000000000070d3c0, __context=0x000000000070d3f8) at debug_private.c:34:13 31         priv2 = n + 2; 32         printf("Task n=%d,priv1=%d,priv2=%d,fpriv=%d\n",n,priv1,priv2,fpriv); 33

-> 34         res = priv1 + priv2 + fpriv + foo(n - 1);

  35       }
  36   #pragma omp taskwait
  37       return res;

(lldb) p priv1
error: <user expression 0>:1:1: use of undeclared identifier 'priv1'
priv1
^
(lldb) p priv2
error: <user expression 1>:1:1: use of undeclared identifier 'priv2'
priv2
^
(lldb) p fpriv
error: <user expression 2>:1:1: use of undeclared identifier 'fpriv'
fpriv
^

  

After the current patch, lldb is able to show the variables

  

(lldb) p priv1
(int) $0 = 10
(lldb) p priv2
(int) $1 = 12
(lldb) p fpriv
(int) $2 = 14

  ``


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114504

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_private.c


Index: clang/test/OpenMP/debug_private.c
===================================================================
--- /dev/null
+++ clang/test/OpenMP/debug_private.c
@@ -0,0 +1,45 @@
+// This testcase checks emission of debug info for variables inside
+// private/firstprivate/lastprivate.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal i32 @.omp_task_entry.
+
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+
+// CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
+// CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
+// CHECK: [[FPRIV]] = !DILocalVariable(name: "fpriv"
+
+extern int printf(const char *, ...);
+
+int foo(int n) {
+  int res, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+    return n;
+  else {
+#pragma omp task shared(res) private(priv1, priv2) firstprivate(fpriv)
+    {
+      priv1 = n;
+      priv2 = n + 2;
+      printf("Task n=%d,priv1=%d,priv2=%d,fpriv=%d\n",n,priv1,priv2,fpriv);
+
+      res = priv1 + priv2 + fpriv + foo(n - 1);
+    }
+#pragma omp taskwait
+    return res;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4510,6 +4510,10 @@
         Address Replacement(CGF.Builder.CreateLoad(Pair.second),
                             CGF.getContext().getDeclAlign(Pair.first));
         Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
+        if (auto *DI = CGF.getDebugInfo()) {
+          DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
+                                        CGF.Builder, true);
+        }
       }
       // Adjust mapping for internal locals by mapping actual memory instead of
       // a pointer to this memory.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114504.389395.patch
Type: text/x-patch
Size: 2411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211124/665434b9/attachment-0001.bin>


More information about the cfe-commits mailing list