The result of pointer subtraction is of type ptrdiff_t, which is not necessarily the same underlying type as ssize_t. This can lead to a compilation error since std::min requires both parameters to be the same type.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
LGTM, but maybe give @alexander-shaposhnikov a chance to comment (i.e. give it a day or two to land this or until he responds).
My comment about using size_t instead are not a blocker, just an opinion.
Whenever this is ready to land, if you need us to land this, please comment so and we will submit.
llvm/lib/ObjCopy/MachO/MachOWriter.cpp | ||
---|---|---|
522–525 | I am sorry for the initial blunder and sorry for breaking this for 32 bits platforms. I was wondering why we did this original. The StringRef constructor needs size_t for its second argument. BlockSize is already size_t. Because of the while loop check HashReadEnd - CurrHashReadPosition has to be positive. I wonder if the right thing here is casting to size_t. (ssize_t has a weird range. It is not a "signed size_t", but a size_t that allows -1 to be returned. But in any case, there's no negative numbers being handled here, it is just a ptrdiff_t which we know to be positive). |
llvm/lib/ObjCopy/MachO/MachOWriter.cpp | ||
---|---|---|
522–525 | I suspect it might originate from https://github.com/llvm/llvm-project/blob/5ba0a9571b3ee3bc76f65e16549012a440d5a0fb/lld/MachO/SyntheticSections.cpp#L1243 |
Now using size_t for the two casts, since that is what the StringRef constructor actually takes.
Thanks for the reviews. I don't have commit access, so could someone who does please commit at your convenience?
What username and email would you like for the commit message? See https://llvm.org/docs/Phabricator.html#committing-someone-s-change-from-phabricator for reference of what we need.
I am sorry for the initial blunder and sorry for breaking this for 32 bits platforms.
I was wondering why we did this original. The StringRef constructor needs size_t for its second argument. BlockSize is already size_t. Because of the while loop check HashReadEnd - CurrHashReadPosition has to be positive. I wonder if the right thing here is casting to size_t.
(ssize_t has a weird range. It is not a "signed size_t", but a size_t that allows -1 to be returned. But in any case, there's no negative numbers being handled here, it is just a ptrdiff_t which we know to be positive).