[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 02:15:07 PST 2021


kadircet updated this revision to Diff 330184.
kadircet added a comment.

- Add test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98483/new/

https://reviews.llvm.org/D98483

Files:
  clang/lib/Parse/ParsePragma.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===================================================================
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -1037,4 +1037,13 @@
               IsEmpty());
 }
 
+TEST_F(TokenCollectorTest, Pragmas) {
+  // Tokens coming from concatenations.
+  recordTokens(R"cpp(
+    void foo() {
+      #pragma unroll 4
+      for(int i=0;i<4;++i);
+    }
+  )cpp");
+}
 } // namespace
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.330184.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210312/b3e8fe10/attachment.bin>


More information about the cfe-commits mailing list