[PATCH] D34668: llvm-nm: Add suport for symbol demangling (-C/--demangle)

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 11:16:32 PDT 2017


Sam Clegg <sbc at google.com> writes:

> On Tue, Jun 27, 2017 at 5:35 PM, Rafael Avila de Espindola
> <rafael.espindola at gmail.com> wrote:
>> Sam Clegg via Phabricator <reviews at reviews.llvm.org> writes:
>>> +static Optional<std::string> demangle(StringRef Name, bool StripUnderscore) {
>>> +  if (StripUnderscore && Name.size() > 0 && Name[0] == '_')
>>> +    Name = Name.substr(1);
>>> +
>>> +  if (Name.size() < 2 || !Name.startswith("_Z"))
>>> +    return None;
>>
>> I don't think you need the .size() checks. It is safe to just use startswith.
>
> I'm checking for >2 so this checking more than just startswith its
> checking there is something more.. but maybe that is overkill

I am not sure I follow. If we don't take the if, then it is true that

Name.size >= 2 && Name.startswith("_Z")

But the startswith implies that the size is >= 2.

> The MachO object itself is needed further down in this function.

Ah, thanks.

LGTM with just the size() check changed. Do you have commit access.

Cheers,
Rafael


More information about the llvm-commits mailing list