[llvm] r338226 - [MS Demangler] Demangle symbols in function scopes.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 29 20:53:57 PDT 2018


On Sun, Jul 29, 2018 at 8:44 PM David Majnemer <david.majnemer at gmail.com>
wrote:

> On Sun, Jul 29, 2018 at 8:12 PM Zachary Turner via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>>
>> +static bool startsWithLocalScopePattern(StringView S) {
>> +  if (!S.consumeFront('?'))
>> +    return false;
>> +  if (S.size() < 2)
>> +    return false;
>> +
>> +  size_t End = S.find('?');
>> +  if (End == StringView::npos)
>> +    return false;
>> +  StringView Candidate = S.substr(0, End);
>> +  if (Candidate.empty())
>> +    return false;
>> +
>> +  // \?[0-9]\?
>> +  // ?@? is the discriminator 0.
>> +  if (Candidate.size() == 1)
>> +    return Candidate[0] == '@' || (Candidate[0] >= '0' && Candidate[0]
>> <= '9');
>> +
>> +  // If it's not 0-9, then it's an encoded number terminated with an @
>> +  if (Candidate.back() != '@')
>> +    return false;
>> +  Candidate = Candidate.dropBack();
>> +
>> +  // An encoded number starts with B-P and all subsequent digits are in
>> A-P.
>> +  // Note that the reason the first digit cannot be A is two fold.
>> First, it
>> +  // would create an ambiguity with ?A which delimits the beginning of an
>> +  // anonymous namespace.  Second, A represents 0, and you don't start a
>> multi
>> +  // digit number with a leading 0.  Presumably the anonymous namespace
>> +  // ambiguity is also why single digit encoded numbers use 0-9 rather
>> than A-J.
>> +  if (Candidate[0] < 'B' || Candidate[0] > 'P')
>>
>
> We just did a dropBack(). I think we need to check Candidate.empty()
> otherwise the range check against 'B' - 'P' will end up accessing Candidate
> out of bounds.
> Perhaps something like:
>

I handled it earlier.  Note the `if (Candidate.size() == 1)` branch now
also returns true if Candidate[0] == '@'.

So if it passes that branch size >= 2.  Then if it passes the next branch
we're guaranteed to have a string of the form S + '@', where S is
non-empty.  So after do the dropBack, we're non-empty.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180729/9d12909e/attachment.html>


More information about the llvm-commits mailing list