Trivially expand macros like:
#define ENOMEMORYFORYOU ENOMEMORYFORYOU

llvm-svn: 38687
GitOrigin-RevId: 3ce1d1aac9d0b9fa7bb213616b1ce3a633ef7516
diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp
index b35ebe7..c3fc8b9 100644
--- a/Lex/Preprocessor.cpp
+++ b/Lex/Preprocessor.cpp
@@ -480,7 +480,8 @@
 
 /// isTrivialSingleTokenExpansion - Return true if MI, which has a single token
 /// in its expansion, currently expands to that token literally.
-static bool isTrivialSingleTokenExpansion(const MacroInfo *MI) {
+static bool isTrivialSingleTokenExpansion(const MacroInfo *MI,
+                                          const IdentifierInfo *MacroIdent) {
   IdentifierInfo *II = MI->getReplacementToken(0).getIdentifierInfo();
 
   // If the token isn't an identifier, it's always literally expanded.
@@ -488,7 +489,9 @@
   
   // If the identifier is a macro, and if that macro is enabled, it may be
   // expanded so it's not a trivial expansion.
-  if (II->getMacroInfo() && II->getMacroInfo()->isEnabled())
+  if (II->getMacroInfo() && II->getMacroInfo()->isEnabled() &&
+      // Fast expanding "#define X X" is ok, because X would be disabled.
+      II != MacroIdent)
     return false;
   
   // If this is an object-like macro invocation, it is safe to trivially expand
@@ -582,8 +585,8 @@
     ++NumFastMacroExpanded;
     return false;
     
-  } else if (MI->getNumTokens() == 1 && isTrivialSingleTokenExpansion(MI)) {
-    
+  } else if (MI->getNumTokens() == 1 &&
+             isTrivialSingleTokenExpansion(MI, Identifier.getIdentifierInfo())){
     // Otherwise, if this macro expands into a single trivially-expanded
     // token: expand it now.  This handles common cases like 
     // "#define VAL 42".