Skip to content

Commit b5e84ca

Browse files
authored
[Clang] Remap paths in OpenMP runtime calls (#82541) (#141250)
Apply the debug prefix mapping to the OpenMP location strings. Fixes #82541
1 parent a12f4f0 commit b5e84ca

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,12 @@ static StringRef getIdentStringFromSourceLocation(CodeGenFunction &CGF,
13521352
llvm::raw_svector_ostream OS(Buffer);
13531353
// Build debug location
13541354
PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
1355-
OS << ";" << PLoc.getFilename() << ";";
1355+
OS << ";";
1356+
if (auto *DbgInfo = CGF.getDebugInfo())
1357+
OS << DbgInfo->remapDIPath(PLoc.getFilename());
1358+
else
1359+
OS << PLoc.getFilename();
1360+
OS << ";";
13561361
if (const auto *FD = dyn_cast_or_null<FunctionDecl>(CGF.CurFuncDecl))
13571362
OS << FD->getQualifiedNameAsString();
13581363
OS << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;";
@@ -1370,10 +1375,14 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF,
13701375
SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize);
13711376
} else {
13721377
std::string FunctionName;
1378+
std::string FileName;
13731379
if (const auto *FD = dyn_cast_or_null<FunctionDecl>(CGF.CurFuncDecl))
13741380
FunctionName = FD->getQualifiedNameAsString();
13751381
PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
1376-
const char *FileName = PLoc.getFilename();
1382+
if (auto *DbgInfo = CGF.getDebugInfo())
1383+
FileName = DbgInfo->remapDIPath(PLoc.getFilename());
1384+
else
1385+
FileName = PLoc.getFilename();
13771386
unsigned Line = PLoc.getLine();
13781387
unsigned Column = PLoc.getColumn();
13791388
SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line,
@@ -8840,10 +8849,14 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
88408849
ExprName = MapExprs.getMapDecl()->getNameAsString();
88418850
}
88428851

8852+
std::string FileName;
88438853
PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
8844-
return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName,
8845-
PLoc.getLine(), PLoc.getColumn(),
8846-
SrcLocStrSize);
8854+
if (auto *DbgInfo = CGF.getDebugInfo())
8855+
FileName = DbgInfo->remapDIPath(PLoc.getFilename());
8856+
else
8857+
FileName = PLoc.getFilename();
8858+
return OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName, PLoc.getLine(),
8859+
PLoc.getColumn(), SrcLocStrSize);
88478860
}
88488861
/// Emit the arrays used to pass the captures and map information to the
88498862
/// offloading runtime library. If there is no map or capture information,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// 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
2+
3+
// CHECK-NOT: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";[[PREFIX]]{{.*}}.c;foo;{{[0-9]+}};{{[0-9]+}};;\00"
4+
5+
void work1(int, int);
6+
void work2(int, int);
7+
void work12(int, int);
8+
9+
void foo(int q) {
10+
int p = 2;
11+
12+
#pragma omp parallel firstprivate(q, p)
13+
work1(p, q);
14+
15+
#pragma omp parallel for firstprivate(p, q)
16+
for (int i = 0; i < q; i++)
17+
work2(i, p);
18+
19+
#pragma omp target teams firstprivate(p)
20+
work12(p, p);
21+
}

0 commit comments

Comments
 (0)