ld64 is cool with leading 0x for hex command-line args, and we should be also.
Details
- Reviewers
MaskRay int3 - Group Reviewers
Restricted Project - Commits
- rG703d3f25976c: [lld-macho] Make lld::getInteger() tolerate leading "0x"/"0X" when base is 16
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
nvm, I see all the hex values in D88064 aren't actually strings that we parse... but I'm still curious to know how this is going to be used / tested
I just added the rationale to the diff summary.
While inspecting ld64, I leaned that it uses strtoull(3) for parsing hex command-line args, and strtoull(3) does this: " If base is zero or 16, the string may then include a "0x" prefix, and the number will be read in base 16"
How will it be used? Somewhere in the wild, we will avoid bugs.
Thanks for the explanation!
lld/test/MachO/headerpad.s | ||
---|---|---|
24 | wouldn't hurt to test the 0X case too |
lld/Common/Args.cpp | ||
---|---|---|
39 | If base == 0, to_integer can parse the 0x prefix. |
??????
If base == 0, to_integer can parse the 0x prefix.
This is unaddressed. Please see StringRef.cpp GetAutoSenseRadix.
I only skip 0x when base == 16. My change does nothing to alter the base == 0 case, and GetAutoSenseRadix continues to operate as before.
lld/Common/Args.cpp | ||
---|---|---|
39 | I am unclear about the intention of your statement. Are you suggesting that I change base to 0 and let to_integer() strip the 0x ? |
lld/Common/Args.cpp | ||
---|---|---|
39 | If you use base 0, to_integer does not need a change and you get 0x ability for free. |
lld/Common/Args.cpp | ||
---|---|---|
37–39 | Is this what you prefer? |
If base == 0, to_integer can parse the 0x prefix.