-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
Conversation
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.
@llvm/pr-subscribers-flang-openmp Author: Michael Klemm (mjklemm) ChangesWhen 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:
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));
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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(); | ||
} |
There was a problem hiding this comment.
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:
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:
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
.
There was a problem hiding this 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.
Co-authored-by: Michael Kruse <[email protected]>
Is there reason you do not want to normalize the filename for hashing? |
@kparzysz @jdoerfert Ping :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I am still curious. You will get different IDs for |
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.