Skip to content

Conversation

@dankm
Copy link
Contributor

@dankm dankm commented May 23, 2025

Apply the debug prefix mapping to the OpenMP location strings.

Fixes #82541

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. clang:openmp OpenMP related changes to Clang labels May 23, 2025
@llvmbot
Copy link
Member

llvmbot commented May 23, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Dan McGregor (dankm)

Changes

Apply the debug prefix mapping to the OpenMP location strings.

Fixes #82541


Full diff: https://github.com/llvm/llvm-project/pull/141250.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+17-3)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e458d437d085a..196c28071bfd6 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() << ";;";
@@ -1370,10 +1375,14 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF,
     SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize);
   } else {
     std::string FunctionName;
+    std::string FileName;
     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();
+    if (CGF.getDebugInfo())
+      FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename());
+    else
+      FileName = PLoc.getFilename();
     unsigned Line = PLoc.getLine();
     unsigned Column = PLoc.getColumn();
     SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line,
@@ -8840,8 +8849,13 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
     ExprName = MapExprs.getMapDecl()->getNameAsString();
   }
 
+  std::string FileName;
   PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
-  return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName,
+  if (CGF.getDebugInfo())
+    FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename());
+  else
+    FileName = PLoc.getFilename();
+  return OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName,
                                          PLoc.getLine(), PLoc.getColumn(),
                                          SrcLocStrSize);
 }

@dankm
Copy link
Contributor Author

dankm commented May 23, 2025

I do need to add tests for this, but wanted to get the general idea up for comments.

@github-actions
Copy link

github-actions bot commented May 23, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@dankm dankm force-pushed the openmp-path-remap branch 2 times, most recently from 7fdc69f to b8f8274 Compare May 23, 2025 18:20
@dankm
Copy link
Contributor Author

dankm commented May 23, 2025

I do need to add tests for this, but wanted to get the general idea up for comments.

Latest update includes basic tests as well.

@dankm dankm force-pushed the openmp-path-remap branch from b8f8274 to 1478c32 Compare May 23, 2025 18:48
@dankm
Copy link
Contributor Author

dankm commented May 26, 2025

@jdoerfert it looks like you wrote the original code I'm modifying here, so I'd like your feedback. Don't know who else would be interested here.

@dankm dankm force-pushed the openmp-path-remap branch from 1478c32 to 8e534d8 Compare May 26, 2025 22:07
@dankm
Copy link
Contributor Author

dankm commented May 26, 2025

Neat, the original was good, and apparently some tests don't run on my system. Going back to to that version :/

Apply the debug prefix mapping to the OpenMP location strings.

Fixes llvm#82541
@dankm dankm force-pushed the openmp-path-remap branch from 8e534d8 to e4fc23b Compare May 26, 2025 22:37
@dankm
Copy link
Contributor Author

dankm commented May 27, 2025

@jdoerfert it looks like you wrote the original code I'm modifying here, so I'd like your feedback. Don't know who else would be interested here.

Hm, @alexey-bataev looks like this is arguably conformance related too.

@dankm dankm requested a review from alexey-bataev May 28, 2025 18:32
@dankm
Copy link
Contributor Author

dankm commented May 28, 2025

If people are good with this, I don't have commit access, so I'd appreciate somebody merging.

@alexey-bataev alexey-bataev merged commit b5e84ca into llvm:main Jun 5, 2025
11 checks passed
@dankm
Copy link
Contributor Author

dankm commented Jun 5, 2025

Thank you, @alexey-bataev for your review and your merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Absolute file name for source file emitted with -fopenmp

3 participants