[llvm] 6c25b20 - [OMPIRBuilder] Use correct API to get filename. (#195866)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 6 02:24:50 PDT 2026
Author: Abid Qadeer
Date: 2026-05-06T10:24:45+01:00
New Revision: 6c25b20a51263f312f6a7a67da6700e9aed8b3a8
URL: https://github.com/llvm/llvm-project/commit/6c25b20a51263f312f6a7a67da6700e9aed8b3a8
DIFF: https://github.com/llvm/llvm-project/commit/6c25b20a51263f312f6a7a67da6700e9aed8b3a8.diff
LOG: [OMPIRBuilder] Use correct API to get filename. (#195866)
Fix incorrect OpenMP source location in ident strings (e.g. showing
"FIRModule" instead of the real source file for Flang).
This addresses issue #195333 (filename part): we were deriving the file
path from `DIFile::getSource()`, which returns optional *embedded*
source contents, not the path/name of the file on disk. It usually
returns `std::nullopt`, so the code fell back to the LLVM module name
(`M.getName()`), which is often "FIRModule" for FIR lowering.
This issue is a regression of D85938 (9240e48a588c) which switched from
`DILocation::getFilename()` to `DIFile::getSource()`.
Restore use of the location’s filename (`DILocation::getFilename()`) so
the ident string gets the actual source file name when available.
Added:
Modified:
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 5a4f12d91d540..e59e44df4ce91 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -1187,10 +1187,8 @@ Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(DebugLoc DL,
DILocation *DIL = DL.get();
if (!DIL)
return getOrCreateDefaultSrcLocStr(SrcLocStrSize);
- StringRef FileName = M.getName();
- if (DIFile *DIF = DIL->getFile())
- if (std::optional<StringRef> Source = DIF->getSource())
- FileName = *Source;
+ StringRef FileName =
+ !DIL->getFilename().empty() ? DIL->getFilename() : M.getName();
StringRef Function = DIL->getScope()->getSubprogram()->getName();
if (Function.empty() && F)
Function = F->getName();
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index b5bb82276298f..acfa993855b2e 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -210,8 +210,7 @@ class OpenMPIRBuilderTest : public testing::Test {
BB = BasicBlock::Create(Ctx, "", F);
DIBuilder DIB(*M);
- auto File = DIB.createFile("test.dbg", "/src", std::nullopt,
- std::optional<StringRef>("/src/test.dbg"));
+ auto File = DIB.createFile("test.dbg", "/");
auto CU = DIB.createCompileUnit(DISourceLanguageName(dwarf::DW_LANG_C),
File, "llvm-C", true, "", 0);
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
@@ -625,7 +624,7 @@ TEST_F(OpenMPIRBuilderTest, DbgLoc) {
dyn_cast<ConstantDataArray>(SrcStrGlob->getInitializer());
if (!SrcSrc)
return;
- EXPECT_EQ(SrcSrc->getAsCString(), ";/src/test.dbg;foo;3;7;;");
+ EXPECT_EQ(SrcSrc->getAsCString(), ";test.dbg;foo;3;7;;");
}
TEST_F(OpenMPIRBuilderTest, ParallelSimpleGPU) {
More information about the llvm-commits
mailing list