<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Jul 29, 2018 at 8:44 PM David Majnemer <<a href="mailto:david.majnemer@gmail.com">david.majnemer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sun, Jul 29, 2018 at 8:12 PM Zachary Turner via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
+static bool startsWithLocalScopePattern(StringView S) {<br>
+ if (!S.consumeFront('?'))<br>
+ return false;<br>
+ if (S.size() < 2)<br>
+ return false;<br>
+<br>
+ size_t End = S.find('?');<br>
+ if (End == StringView::npos)<br>
+ return false;<br>
+ StringView Candidate = S.substr(0, End);<br>
+ if (Candidate.empty())<br>
+ return false;<br>
+<br>
+ // \?[0-9]\?<br>
+ // ?@? is the discriminator 0.<br>
+ if (Candidate.size() == 1)<br>
+ return Candidate[0] == '@' || (Candidate[0] >= '0' && Candidate[0] <= '9');<br>
+<br>
+ // If it's not 0-9, then it's an encoded number terminated with an @<br>
+ if (Candidate.back() != '@')<br>
+ return false;<br>
+ Candidate = Candidate.dropBack();<br>
+<br>
+ // An encoded number starts with B-P and all subsequent digits are in A-P.<br>
+ // Note that the reason the first digit cannot be A is two fold. First, it<br>
+ // would create an ambiguity with ?A which delimits the beginning of an<br>
+ // anonymous namespace. Second, A represents 0, and you don't start a multi<br>
+ // digit number with a leading 0. Presumably the anonymous namespace<br>
+ // ambiguity is also why single digit encoded numbers use 0-9 rather than A-J.<br>
+ if (Candidate[0] < 'B' || Candidate[0] > 'P')<br></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>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.<br></div><div>Perhaps something like:</div></div></div></blockquote><div><br></div><div>I handled it earlier. Note the `if (Candidate.size() == 1)` branch now also returns true if Candidate[0] == '@'.</div><div><br></div><div>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. </div></div></div>