[cfe-commits] r38687 - /cfe/cfe/trunk/Lex/Preprocessor.cpp
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:23:50 PDT 2007
Author: sabre
Date: Wed Jul 11 11:23:49 2007
New Revision: 38687
URL: http://llvm.org/viewvc/llvm-project?rev=38687&view=rev
Log:
Trivially expand macros like:
#define ENOMEMORYFORYOU ENOMEMORYFORYOU
Modified:
cfe/cfe/trunk/Lex/Preprocessor.cpp
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38687&r1=38686&r2=38687&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:49 2007
@@ -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".
More information about the cfe-commits
mailing list