[PATCH] D98483: [clang] Mark re-injected tokens appropriately during pragma handling

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 12 00:37:46 PST 2021


kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a subscriber: usaxena95.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

This hides such tokens from TokenWatcher, preventing crashes in clients
trying to match spelled and expanded tokens.

Fixes https://github.com/clangd/clangd/issues/712


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98483

Files:
  clang/lib/Parse/ParsePragma.cpp


Index: clang/lib/Parse/ParsePragma.cpp
===================================================================
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -2607,6 +2607,7 @@
   Token EoF, AnnotTok;
   EoF.startToken();
   EoF.setKind(tok::eof);
+  EoF.setFlag(clang::Token::IsReinjected);
   AnnotTok.startToken();
   AnnotTok.setKind(tok::annot_pragma_ms_pragma);
   AnnotTok.setLocation(Tok.getLocation());
@@ -2614,6 +2615,7 @@
   SmallVector<Token, 8> TokenVector;
   // Suck up all of the tokens before the eod.
   for (; Tok.isNot(tok::eod); PP.Lex(Tok)) {
+    Tok.setFlag(clang::Token::IsReinjected);
     TokenVector.push_back(Tok);
     AnnotTok.setAnnotationEndLoc(Tok.getLocation());
   }
@@ -3159,6 +3161,7 @@
         break;
     }
 
+    Tok.setFlag(clang::Token::IsReinjected);
     ValueList.push_back(Tok);
     PP.Lex(Tok);
   }
@@ -3174,6 +3177,7 @@
 
   Token EOFTok;
   EOFTok.startToken();
+  EOFTok.setFlag(clang::Token::IsReinjected);
   EOFTok.setKind(tok::eof);
   EOFTok.setLocation(Tok.getLocation());
   ValueList.push_back(EOFTok); // Terminates expression for parsing.
@@ -3612,6 +3616,7 @@
           break;
       }
 
+      Tok.setFlag(clang::Token::IsReinjected);
       AttributeTokens.push_back(Tok);
       PP.Lex(Tok);
     }
@@ -3632,6 +3637,7 @@
     EOFTok.startToken();
     EOFTok.setKind(tok::eof);
     EOFTok.setLocation(EndLoc);
+    EOFTok.setFlag(clang::Token::IsReinjected);
     AttributeTokens.push_back(EOFTok);
 
     Info->Tokens =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98483.330172.patch
Type: text/x-patch
Size: 1516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210312/851893be/attachment.bin>


More information about the cfe-commits mailing list