teemperor created this revision.

Calling `Preprocessor::getIdentifierInfo` is not automatically updating the 
returned identifier at the moment. This patch adds a flag that is ensuring by 
default that the returned IdentifierInfo is updated. The flag is true by 
default because that seems like the most logical behavior for this method. Can 
be turned off for performance reasons


https://reviews.llvm.org/D33004

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/Preprocessor.cpp


Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -245,6 +245,27 @@
   llvm::errs() << ">";
 }
 
+IdentifierInfo *Preprocessor::getIdentifierInfo(StringRef Name,
+                                                bool CheckOutOfDate) const {
+  IdentifierInfo &II = Identifiers.get(Name);
+  // If the information about this identifier is out of date, update it from
+  // the external source.
+  // We have to treat __VA_ARGS__ in a special way, since it gets
+  // serialized with isPoisoned = true, but our preprocessor may have
+  // unpoisoned it if we're defining a C99 macro.
+  if (CheckOutOfDate && II.isOutOfDate()) {
+    bool CurrentIsPoisoned = false;
+    if (&II == Ident__VA_ARGS__)
+      CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
+
+    updateOutOfDateIdentifier(II);
+
+    if (&II == Ident__VA_ARGS__)
+      II.setIsPoisoned(CurrentIsPoisoned);
+  }
+  return &II;
+}
+
 void Preprocessor::DumpLocation(SourceLocation Loc) const {
   Loc.dump(SourceMgr);
 }
@@ -646,23 +667,8 @@
 
   IdentifierInfo &II = *Identifier.getIdentifierInfo();
 
-  // If the information about this identifier is out of date, update it from
-  // the external source.
-  // We have to treat __VA_ARGS__ in a special way, since it gets
-  // serialized with isPoisoned = true, but our preprocessor may have
-  // unpoisoned it if we're defining a C99 macro.
-  if (II.isOutOfDate()) {
-    bool CurrentIsPoisoned = false;
-    if (&II == Ident__VA_ARGS__)
-      CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
-
-    updateOutOfDateIdentifier(II);
-    Identifier.setKind(II.getTokenID());
+  Identifier.setKind(II.getTokenID());
 
-    if (&II == Ident__VA_ARGS__)
-      II.setIsPoisoned(CurrentIsPoisoned);
-  }
-  
   // If this identifier was poisoned, and if it was not produced from a macro
   // expansion, emit an error.
   if (II.isPoisoned() && CurPPLexer) {
Index: include/clang/Lex/Preprocessor.h
===================================================================
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -939,11 +939,11 @@
   void setPredefines(const char *P) { Predefines = P; }
   void setPredefines(StringRef P) { Predefines = P; }
 
-  /// Return information about the specified preprocessor
-  /// identifier token.
-  IdentifierInfo *getIdentifierInfo(StringRef Name) const {
-    return &Identifiers.get(Name);
-  }
+  /// Return information about the specified preprocessor identifier token.
+  /// If \p CheckOutOfDate is true, then the returned information is ensured
+  /// to be not out of date.
+  IdentifierInfo *getIdentifierInfo(StringRef Name,
+                                    bool CheckOutOfDate = true) const;
 
   /// \brief Add the specified pragma handler to this preprocessor.
   ///


Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -245,6 +245,27 @@
   llvm::errs() << ">";
 }
 
+IdentifierInfo *Preprocessor::getIdentifierInfo(StringRef Name,
+                                                bool CheckOutOfDate) const {
+  IdentifierInfo &II = Identifiers.get(Name);
+  // If the information about this identifier is out of date, update it from
+  // the external source.
+  // We have to treat __VA_ARGS__ in a special way, since it gets
+  // serialized with isPoisoned = true, but our preprocessor may have
+  // unpoisoned it if we're defining a C99 macro.
+  if (CheckOutOfDate && II.isOutOfDate()) {
+    bool CurrentIsPoisoned = false;
+    if (&II == Ident__VA_ARGS__)
+      CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
+
+    updateOutOfDateIdentifier(II);
+
+    if (&II == Ident__VA_ARGS__)
+      II.setIsPoisoned(CurrentIsPoisoned);
+  }
+  return &II;
+}
+
 void Preprocessor::DumpLocation(SourceLocation Loc) const {
   Loc.dump(SourceMgr);
 }
@@ -646,23 +667,8 @@
 
   IdentifierInfo &II = *Identifier.getIdentifierInfo();
 
-  // If the information about this identifier is out of date, update it from
-  // the external source.
-  // We have to treat __VA_ARGS__ in a special way, since it gets
-  // serialized with isPoisoned = true, but our preprocessor may have
-  // unpoisoned it if we're defining a C99 macro.
-  if (II.isOutOfDate()) {
-    bool CurrentIsPoisoned = false;
-    if (&II == Ident__VA_ARGS__)
-      CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
-
-    updateOutOfDateIdentifier(II);
-    Identifier.setKind(II.getTokenID());
+  Identifier.setKind(II.getTokenID());
 
-    if (&II == Ident__VA_ARGS__)
-      II.setIsPoisoned(CurrentIsPoisoned);
-  }
-  
   // If this identifier was poisoned, and if it was not produced from a macro
   // expansion, emit an error.
   if (II.isPoisoned() && CurPPLexer) {
Index: include/clang/Lex/Preprocessor.h
===================================================================
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -939,11 +939,11 @@
   void setPredefines(const char *P) { Predefines = P; }
   void setPredefines(StringRef P) { Predefines = P; }
 
-  /// Return information about the specified preprocessor
-  /// identifier token.
-  IdentifierInfo *getIdentifierInfo(StringRef Name) const {
-    return &Identifiers.get(Name);
-  }
+  /// Return information about the specified preprocessor identifier token.
+  /// If \p CheckOutOfDate is true, then the returned information is ensured
+  /// to be not out of date.
+  IdentifierInfo *getIdentifierInfo(StringRef Name,
+                                    bool CheckOutOfDate = true) const;
 
   /// \brief Add the specified pragma handler to this preprocessor.
   ///
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D33004: getIdentif... Raphael Isemann via Phabricator via cfe-commits

Reply via email to