================
@@ -712,6 +712,16 @@ class TokenCollector::Builder {
 
   TokenBuffer build() && {
     assert(!Result.ExpandedTokens.empty());
+
+    // When the parser hits a hard limit (e.g. bracket depth or function scope
+    // depth), it halts prematurely and leaves the expanded token stream
+    // truncated with no final `eof` token. To keep the invariant, synthesize 
an
+    // `eof` at the location of the last collected token.
+    if (Result.ExpandedTokens.back().kind() != tok::eof) {
+      SourceLocation Loc = Result.ExpandedTokens.back().location();
+      Result.ExpandedTokens.emplace_back(Loc, 0, tok::eof);
+    }
+
     assert(Result.ExpandedTokens.back().kind() == tok::eof);
----------------
hokein wrote:

we can remove this assert now.

https://github.com/llvm/llvm-project/pull/196861
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to