summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp12
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp6
2 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index ef26aeb79a6..ec5b67fb788 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -991,6 +991,12 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
if (MI->isObjectLike()) {
// Object-like macros are very simple, just read their body.
while (Tok.isNot(tok::eom)) {
+ // If this token has a virtual location, resolve it down to its spelling
+ // location. This is not strictly needed, but avoids extra resolutions
+ // for macros that are expanded frequently.
+ if (!Tok.getLocation().isFileID())
+ Tok.setLocation(SourceMgr.getSpellingLoc(Tok.getLocation()));
+
MI->AddTokenToBody(Tok);
// Get the next token of the macro.
LexUnexpandedToken(Tok);
@@ -1000,6 +1006,12 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
// Otherwise, read the body of a function-like macro. This has to validate
// the # (stringize) operator.
while (Tok.isNot(tok::eom)) {
+ // If this token has a virtual location, resolve it down to its spelling
+ // location. This is not strictly needed, but avoids extra resolutions
+ // for macros that are expanded frequently.
+ if (!Tok.getLocation().isFileID())
+ Tok.setLocation(SourceMgr.getSpellingLoc(Tok.getLocation()));
+
MI->AddTokenToBody(Tok);
// Check C99 6.10.3.2p1: ensure that # operators are followed by macro
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 63caafaf504..518c84e8c38 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -340,6 +340,12 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
if (!MI->isEnabled())
Tok.setFlag(Token::DisableExpand);
}
+
+ // If this token has instantiation location, resolve it down to its
+ // spelling location. This is not strictly needed, but avoids extra
+ // resolutions for macros that are expanded frequently.
+ if (!Tok.getLocation().isFileID())
+ Tok.setLocation(SourceMgr.getSpellingLoc(Tok.getLocation()));
ArgTokens.push_back(Tok);
}
OpenPOWER on IntegriCloud