diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index 424a3440d4..017af5caee 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -252,7 +252,7 @@ private: void RecomputeNeedsHandleIdentifier() { NeedsHandleIdentifier = (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() | - isExtensionToken() | (getTokenID() == tok::kw___import__)); + isExtensionToken()); } }; diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 1ab6411e98..b14c7e8382 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -118,6 +118,9 @@ class Preprocessor : public llvm::RefCountedBase { /// \brief Whether we have already loaded macros from the external source. mutable bool ReadMacrosFromExternalSource : 1; + /// \brief Tracks the depth of Lex() Calls. + unsigned LexDepth; + /// Identifiers - This is mapping/lookup information for all identifiers in /// the program, including program keywords. mutable IdentifierTable Identifiers; @@ -531,6 +534,7 @@ public: /// Lex - To lex a token from the preprocessor, just pull a token from the /// current lexer or macro object. void Lex(Token &Result) { + ++LexDepth; if (CurLexer) CurLexer->Lex(Result); else if (CurPTHLexer) @@ -539,6 +543,11 @@ public: CurTokenLexer->Lex(Result); else CachingLex(Result); + --LexDepth; + + // If we have the __import__ keyword, handle the module import now. + if (Result.getKind() == tok::kw___import__ && LexDepth == 0) + HandleModuleImport(Result); } /// LexNonComment - Lex a token. If it's a comment, keep lexing until we get diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 1d1687d84b..51908bdb87 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -88,6 +88,8 @@ Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts, // We haven't read anything from the external source. ReadMacrosFromExternalSource = false; + LexDepth = 0; + // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro. // This gets unpoisoned where it is allowed. (Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned(); @@ -484,7 +486,7 @@ void Preprocessor::HandleIdentifier(Token &Identifier) { if (!DisableMacroExpansion && !Identifier.isExpandDisabled()) { if (MI->isEnabled()) { if (!HandleMacroExpandedIdentifier(Identifier, MI)) - goto finish; + return; } else { // C99 6.10.3.4p2 says that a disabled macro may never again be // expanded, even if it's in a context where it could be expanded in the @@ -506,12 +508,6 @@ void Preprocessor::HandleIdentifier(Token &Identifier) { // like "#define TY typeof", "TY(1) x". if (II.isExtensionToken() && !DisableMacroExpansion) Diag(Identifier, diag::ext_token_used); - -finish: - // If we have the start of a module import, handle it now. - if (Identifier.is(tok::kw___import__) && - !InMacroArgs && !DisableMacroExpansion) - HandleModuleImport(Identifier); } void Preprocessor::HandleModuleImport(Token &Import) { diff --git a/test/Modules/lookup.cpp b/test/Modules/lookup.cpp index a283eb9e6e..cae66211ca 100644 --- a/test/Modules/lookup.cpp +++ b/test/Modules/lookup.cpp @@ -18,7 +18,6 @@ void test(int i, float f) { // RUN: %clang_cc1 -emit-module -x c++ -o %T/lookup_right_cxx.pcm %S/Inputs/lookup_right.hpp // RUN: %clang_cc1 -x c++ -I %T %s -verify // RUN: %clang_cc1 -ast-print -x c++ -I %T %s | FileCheck -check-prefix=CHECK-PRINT %s -// XFAIL: win32 // CHECK-PRINT: int *f0(int *); // CHECK-PRINT: float *f0(float *);