https://github.com/abidh updated https://github.com/llvm/llvm-project/pull/219548
>From 3c223f4711e85a30fbbf14c9be2456e90e86163b Mon Sep 17 00:00:00 2001 From: Abid Qadeer <[email protected]> Date: Fri, 21 Aug 2026 20:38:30 +0100 Subject: [PATCH 1/3] [CGOpenMPRuntime] Keep the current debug location when handing off to OMPIRBuilder. Both callsites took clang's insertion point but not its debug location, which selected the LocationDescription constructor that leaves the location empty. Because updateToLocation() installs the location unconditionally, that actively cleared the location clang had established, and the __kmpc_global_thread_num and target data calls emitted from there lost their !dbg. Passing the builder carries the location across too. Co-authored-by: Cursor <[email protected]> --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 80d20f3259822..1ad07936e6f05 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1422,7 +1422,7 @@ llvm::Value *CGOpenMPRuntime::getThreadID(CodeGenFunction &CGF, // the clang invariants used below might be broken. if (CGM.getLangOpts().OpenMPIRBuilder) { SmallString<128> Buffer; - OMPBuilder.updateToLocation(CGF.Builder.saveIP()); + OMPBuilder.updateToLocation(CGF.Builder); uint32_t SrcLocStrSize; auto *SrcLocStr = OMPBuilder.getOrCreateSrcLocStr( getIdentStringFromSourceLocation(CGF, Loc, Buffer), SrcLocStrSize); @@ -11811,7 +11811,7 @@ void CGOpenMPRuntime::emitTargetDataCalls( CGF.AllocaInsertPt->getIterator()); InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(), CGF.Builder.GetInsertPoint()); - llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP); + llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CGF.Builder); llvm::OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTargetData( OmpLoc, AllocaIP, CodeGenIP, /*DeallocBlocks=*/{}, DeviceID, >From 620e34a0b86d1dd9b014a903f514c44b8efaed03 Mon Sep 17 00:00:00 2001 From: Abid Qadeer <[email protected]> Date: Fri, 28 Aug 2026 18:32:26 +0100 Subject: [PATCH 2/3] [CGOpenMPRuntime] Add a test for the debug location hand-off to OMPIRBuilder. Cover both places that lost the location: the thread-num call getThreadID() delegates to the builder when -fopenmp-enable-irbuilder is on, and the branch createTargetData() emits for the 'if' clause of a target data region. The mapper calls in that region are not useful here because restoreIP() reinstalls a location from the instruction at the insertion point, so they keep their !dbg either way. Co-authored-by: Cursor <[email protected]> --- .../OpenMP/debug-info-ompirbuilder-handoff.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 clang/test/OpenMP/debug-info-ompirbuilder-handoff.c diff --git a/clang/test/OpenMP/debug-info-ompirbuilder-handoff.c b/clang/test/OpenMP/debug-info-ompirbuilder-handoff.c new file mode 100644 index 0000000000000..fe29b0e26dbd7 --- /dev/null +++ b/clang/test/OpenMP/debug-info-ompirbuilder-handoff.c @@ -0,0 +1,35 @@ +// Check that the debug location clang has established survives the hand-off to +// the OpenMPIRBuilder, so that the IR the builder emits on clang's behalf still +// carries a !dbg attachment. + +// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown \ +// RUN: -debug-info-kind=limited -emit-llvm %s -o - | FileCheck %s --check-prefix=GTID + +// RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown \ +// RUN: -fopenmp-targets=x86_64-unknown-linux-gnu -debug-info-kind=limited \ +// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=TDATA + +int cond; +void use(int); + +// CGOpenMPRuntime::getThreadID() defers to the OpenMPIRBuilder when it is +// enabled, so the thread-num call is emitted by the builder. + +// GTID-LABEL: define {{.*}}@single_region +// GTID: entry: +// GTID-NEXT: call i32 @__kmpc_global_thread_num({{.*}}), !dbg +void single_region(void) { +#pragma omp single + use(1); +} + +// CGOpenMPRuntime::emitTargetDataCalls() passes the 'if' condition down to +// OpenMPIRBuilder::createTargetData(), which emits the branch on it. + +// TDATA-LABEL: define {{.*}}@target_data_if +// TDATA: %[[TOBOOL:.+]] = icmp ne i32 %{{.+}}, 0, !dbg +// TDATA-NEXT: br i1 %[[TOBOOL]], label %{{.+}}, label %{{.+}}, !dbg +void target_data_if(int *p) { +#pragma omp target data map(tofrom : p[0 : 4]) if (cond) + use(2); +} >From 5b63dd41e88ac69df0160f6ba4a4b56b678d269d Mon Sep 17 00:00:00 2001 From: Abid Qadeer <[email protected]> Date: Thu, 10 Sep 2026 17:57:45 +0100 Subject: [PATCH 3/3] [CGOpenMPRuntime] Fold the hand-off test into a single run line. Review feedback was that the test read oddly. Both hand-offs are reachable in one configuration, so the two run lines and their check prefixes collapse into one: getThreadID() needs -fopenmp-enable-irbuilder to delegate to the builder, and the target data region needs an offload target to be expanded at all. Enabling both leaves the target data lowering unchanged apart from the number of the ident_t global. The checks now bind the metadata node clang established and require the instruction the builder emits to reuse it, which states the hand-off directly instead of only asserting that some !dbg is present. Comments record why the second case watches the branch of the 'if' clause rather than the mapper calls. Co-authored-by: Cursor <[email protected]> --- .../OpenMP/debug-info-ompirbuilder-handoff.c | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/clang/test/OpenMP/debug-info-ompirbuilder-handoff.c b/clang/test/OpenMP/debug-info-ompirbuilder-handoff.c index fe29b0e26dbd7..036b04a932bb2 100644 --- a/clang/test/OpenMP/debug-info-ompirbuilder-handoff.c +++ b/clang/test/OpenMP/debug-info-ompirbuilder-handoff.c @@ -3,32 +3,35 @@ // carries a !dbg attachment. // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple x86_64-unknown-unknown \ -// RUN: -debug-info-kind=limited -emit-llvm %s -o - | FileCheck %s --check-prefix=GTID - -// RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown \ // RUN: -fopenmp-targets=x86_64-unknown-linux-gnu -debug-info-kind=limited \ -// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=TDATA +// RUN: -emit-llvm %s -o - | FileCheck %s int cond; void use(int); // CGOpenMPRuntime::getThreadID() defers to the OpenMPIRBuilder when it is -// enabled, so the thread-num call is emitted by the builder. +// enabled, so the thread-num call is emitted by the builder and must inherit +// the location clang was holding. -// GTID-LABEL: define {{.*}}@single_region -// GTID: entry: -// GTID-NEXT: call i32 @__kmpc_global_thread_num({{.*}}), !dbg +// CHECK-LABEL: define {{.*}}@single_region +// CHECK: entry: +// CHECK-NEXT: call i32 @__kmpc_global_thread_num({{.*}}), !dbg ![[LOC:[0-9]+]] +// CHECK-NEXT: call i32 @__kmpc_single({{.*}}), !dbg ![[LOC]] void single_region(void) { #pragma omp single use(1); } // CGOpenMPRuntime::emitTargetDataCalls() passes the 'if' condition down to -// OpenMPIRBuilder::createTargetData(), which emits the branch on it. +// OpenMPIRBuilder::createTargetData(), which emits the branch on it. The mapper +// calls of the region are not useful here because restoreIP() reinstalls a +// location from the instruction at the insertion point, so they keep their !dbg +// either way; this branch is emitted before that happens and is the only +// observable witness on that path. -// TDATA-LABEL: define {{.*}}@target_data_if -// TDATA: %[[TOBOOL:.+]] = icmp ne i32 %{{.+}}, 0, !dbg -// TDATA-NEXT: br i1 %[[TOBOOL]], label %{{.+}}, label %{{.+}}, !dbg +// CHECK-LABEL: define {{.*}}@target_data_if +// CHECK: %[[TOBOOL:.+]] = icmp ne i32 %{{.+}}, 0, !dbg ![[LOC2:[0-9]+]] +// CHECK-NEXT: br i1 %[[TOBOOL]], label %{{.+}}, label %{{.+}}, !dbg ![[LOC2]] void target_data_if(int *p) { #pragma omp target data map(tofrom : p[0 : 4]) if (cond) use(2); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
