[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)
Dan McGregor via cfe-commits
cfe-commits at lists.llvm.org
Mon May 26 15:08:01 PDT 2025
https://github.com/dankm updated https://github.com/llvm/llvm-project/pull/141250
>From 8e534d8fe14d70e4fa65dc6d8dad8ad4de73caae Mon Sep 17 00:00:00 2001
From: Dan McGregor <dan.mcgregor at usask.ca>
Date: Fri, 23 May 2025 10:19:22 -0600
Subject: [PATCH] [Clang] Remap paths in OpenMP runtime calls
Apply the debug prefix mapping to the OpenMP location strings.
Fixes https://github.com/llvm/llvm-project/issues/82541
---
clang/lib/CodeGen/CGOpenMPRuntime.cpp | 19 ++++++++++++++-----
clang/test/CodeGen/openmp-prefix-map.c | 21 +++++++++++++++++++++
2 files changed, 35 insertions(+), 5 deletions(-)
create mode 100644 clang/test/CodeGen/openmp-prefix-map.c
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e458d437d085a..d0ac4de71524f 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1352,7 +1352,12 @@ static StringRef getIdentStringFromSourceLocation(CodeGenFunction &CGF,
llvm::raw_svector_ostream OS(Buffer);
// Build debug location
PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
- OS << ";" << PLoc.getFilename() << ";";
+ OS << ";";
+ if (CGF.getDebugInfo())
+ OS << CGF.getDebugInfo()->remapDIPath(PLoc.getFilename());
+ else
+ OS << PLoc.getFilename();
+ OS << ";";
if (const auto *FD = dyn_cast_or_null<FunctionDecl>(CGF.CurFuncDecl))
OS << FD->getQualifiedNameAsString();
OS << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;";
@@ -1373,7 +1378,9 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF,
if (const auto *FD = dyn_cast_or_null<FunctionDecl>(CGF.CurFuncDecl))
FunctionName = FD->getQualifiedNameAsString();
PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
- const char *FileName = PLoc.getFilename();
+ assert(CGF.getDebugInfo() &&
+ "No debug information in current CodeGenFunction");
+ std::string FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename());
unsigned Line = PLoc.getLine();
unsigned Column = PLoc.getColumn();
SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line,
@@ -8841,9 +8848,11 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
}
PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
- return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName,
- PLoc.getLine(), PLoc.getColumn(),
- SrcLocStrSize);
+ assert(CGF.getDebugInfo() &&
+ "No debug information in current CodeGenFunction");
+ return OMPBuilder.getOrCreateSrcLocStr(
+ CGF.getDebugInfo()->remapDIPath(PLoc.getFilename()), ExprName,
+ PLoc.getLine(), PLoc.getColumn(), SrcLocStrSize);
}
/// Emit the arrays used to pass the captures and map information to the
/// offloading runtime library. If there is no map or capture information,
diff --git a/clang/test/CodeGen/openmp-prefix-map.c b/clang/test/CodeGen/openmp-prefix-map.c
new file mode 100644
index 0000000000000..be3429c267215
--- /dev/null
+++ b/clang/test/CodeGen/openmp-prefix-map.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -debug-info-kind=standalone -fopenmp %s -emit-llvm -o - -disable-llvm-optzns -fdebug-prefix-map=%S=.| FileCheck -DPREFIX=%S %s
+
+// CHECK-NOT: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";[[PREFIX]]{{.*}}.c;foo;{{[0-9]+}};{{[0-9]+}};;\00"
+
+void work1(int, int);
+void work2(int, int);
+void work12(int, int);
+
+void foo(int q) {
+ int p = 2;
+
+ #pragma omp parallel firstprivate(q, p)
+ work1(p, q);
+
+ #pragma omp parallel for firstprivate(p, q)
+ for (int i = 0; i < q; i++)
+ work2(i, p);
+
+ #pragma omp target teams firstprivate(p)
+ work12(p, p);
+}
More information about the cfe-commits
mailing list