Skip to content

[clang][OpenMP] Fix bug #62099 - use hash value when inode ID cannot be determined #131646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2025

Conversation

mjklemm
Copy link
Contributor

@mjklemm mjklemm commented Mar 17, 2025

When creating the name of an outlined region, Clang uses the file's inode ID to generate a unique name. When the file does not exist, this causes a fatal abort of the compiler. This PR switches to a has value that is used instead.

When creating the name of an outlined region, Clang uses the file's
inode ID to generate a unique name.  When the file does not exist, this
causes a fatal abort of the compiler.  This PR switches to a has value
that is used instead.
@mjklemm mjklemm self-assigned this Mar 17, 2025
@llvmbot llvmbot added flang:openmp clang:openmp OpenMP related changes to Clang labels Mar 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 17, 2025

@llvm/pr-subscribers-flang-openmp

Author: Michael Klemm (mjklemm)

Changes

When creating the name of an outlined region, Clang uses the file's inode ID to generate a unique name. When the file does not exist, this causes a fatal abort of the compiler. This PR switches to a has value that is used instead.


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

1 Files Affected:

  • (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+10-6)
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 8dcebcdb8791d..dacbc00ec7819 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -9577,14 +9577,18 @@ OpenMPIRBuilder::getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
                                           StringRef ParentName) {
   sys::fs::UniqueID ID;
   auto FileIDInfo = CallBack();
-  if (auto EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID)) {
-    report_fatal_error(("Unable to get unique ID for file, during "
-                        "getTargetEntryUniqueInfo, error message: " +
-                        EC.message())
-                           .c_str());
+  uint64_t FileID{0};
+  auto EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID);
+  if (EC) {
+    // The inode ID could not be determined, so create a hash value
+    // the current file name and use that as an ID.
+    FileID = hash_value(FileIDInfo);
+  }
+  else {
+    FileID = ID.getFile();
   }
 
-  return TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(),
+  return TargetRegionEntryInfo(ParentName, ID.getDevice(), FileID,
                                std::get<1>(FileIDInfo));
 }
 

@mjklemm mjklemm changed the title [clang]{OpenMP] Fix bug #62099 - use hash value when inode ID cannot be determined [clang][OpenMP] Fix bug #62099 - use hash value when inode ID cannot be determined Mar 17, 2025
Copy link

github-actions bot commented Mar 17, 2025

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

Comment on lines 9580 to 9589
uint64_t FileID{0};
auto EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID);
if (EC) {
// The inode ID could not be determined, so create a hash value
// the current file name and use that as an ID.
FileID = hash_value(FileIDInfo);
}
else {
FileID = ID.getFile();
}
Copy link
Member

@Meinersbur Meinersbur Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM coding style applies here:

Suggested change
uint64_t FileID{0};
auto EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID);
if (EC) {
// The inode ID could not be determined, so create a hash value
// the current file name and use that as an ID.
FileID = hash_value(FileIDInfo);
}
else {
FileID = ID.getFile();
}
uint64_t FileID = 0;
// If the inode ID could not be determined, create a hash value
// the current file name and use that as an ID.
if (std::error_code EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID) {
FileID = hash_value(FileIDInfo);
else
FileID = ID.getFile();

Or as a lambda:

Suggested change
uint64_t FileID{0};
auto EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID);
if (EC) {
// The inode ID could not be determined, so create a hash value
// the current file name and use that as an ID.
FileID = hash_value(FileIDInfo);
}
else {
FileID = ID.getFile();
}
uint64_t FileID = [&]() {
sys::fs::UniqueID ID;
if (!sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID))
return ID.getFile();
return hash_value(FileIDInfo);
}();

You probably only want to hash the file name, not the line number: hash_value(std::get<0>(FileIDInfo)).
Consider normalizing the file path before hashing: sys::fs::real_path.

@mjklemm mjklemm requested a review from Meinersbur March 19, 2025 10:20
Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but some style questions not addressed.

@Meinersbur
Copy link
Member

Is there reason you do not want to normalize the filename for hashing?

@mjklemm
Copy link
Contributor Author

mjklemm commented Apr 2, 2025

@kparzysz @jdoerfert Ping :-)

Copy link
Contributor

@kparzysz kparzysz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mjklemm mjklemm merged commit 581f8bc into llvm:main Apr 2, 2025
11 checks passed
@Meinersbur
Copy link
Member

Meinersbur commented Apr 2, 2025

Is there reason you do not want to normalize the filename for hashing?

I am still curious. You will get different IDs for somedir/../file.cpp and file.cpp (and File.cpp on case-insesitive file systems)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:openmp OpenMP related changes to Clang flang:openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants