-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD][COFF] Fix ARM64 EC chunks comparator #75407
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
@llvm/pr-subscribers-lld @llvm/pr-subscribers-platform-windows Author: Alexandre Ganea (aganea) ChangesFix string weak ordering relationship. Since we were only testing Full diff: https://github.com/llvm/llvm-project/pull/75407.diff 1 Files Affected:
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 89e0f5b2df7441..0d28091efef2b1 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1480,7 +1480,8 @@ void Writer::sortECChunks() {
llvm::stable_sort(sec->chunks, [=](const Chunk *a, const Chunk *b) {
std::optional<chpe_range_type> aType = a->getArm64ECRangeType(),
bType = b->getArm64ECRangeType();
- return !aType || (bType && *aType < *bType);
+ return (!aType ? 0 : (unsigned)*aType + 1) <
+ (!bType ? 0 : (unsigned)*bType + 1);
});
}
}
|
return (!aType ? 0 : (unsigned)*aType + 1) < | ||
(!bType ? 0 : (unsigned)*bType + 1); |
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.
Good catch, thanks! C-style casts are generally discouraged in LLVM, in this case I think we could entirely avoid casts by tweaking the expression:
return (!aType ? 0 : (unsigned)*aType + 1) < | |
(!bType ? 0 : (unsigned)*bType + 1); | |
return bType && (!aType || *aType < *bType); |
It would be also nice to have a test. In this case, reproducing it depends on STL implementation detail, so a mistake like this may not be caught on some setups, but I was able to reproduce the problem on Linux+libstdc++ with: https://gist.github.com/cjacek/7cac304bb03583d90452425cc71101b3
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.
Thanks for getting back! Since you already have a diff ready do you mind sending out the PR & landing it? I can close this in that case.
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.
Sure, I created #75495.
Spotted by Alexandre Ganea in llvm#75407.
Spotted by Alexandre Ganea in #75407.
Spotted by Alexandre Ganea in llvm#75407.
Fix string weak ordering relationship. Since we were only testing
!aType
before,comp(a, b)
andcomp(b, a)
would both returntrue
if both values werenullopt
This has been found by the Debug MS-STL.