<div dir="ltr">OK, I've checked in the fix, and I'll keep trying to make a testcase. If you construct one, please go ahead and check it in :)</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 4, 2015 at 12:52 PM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:kyrtzidis@apple.com" target="_blank">kyrtzidis@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I don’t have a reduced test case.</div><br><div><blockquote type="cite"><div>On May 4, 2015, at 12:50 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div><br><div><div dir="ltr">Thanks, do you have a testcase that you could check in? The fix would be:<div><pre>Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp     (revision 236400)
+++ lib/Serialization/ASTReader.cpp     (working copy)
@@ -1829,7 +1829,8 @@
     Earliest = MD;
   }
 
-  PP.setLoadedMacroDirective(II, Latest);
+  if (Latest)
+    PP.setLoadedMacroDirective(II, Latest);
 }
 
 ASTReader::InputFileInfo</pre></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 4, 2015 at 12:44 PM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:kyrtzidis@apple.com" target="_blank">kyrtzidis@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Thanks Richard!</div><div><br></div><div>There is another crash where a MacroDirective pointer is null, but unfortunately I don’t have a small test case, here’s how to reproduce on OSX:</div><div>It seems to crash when indexing the CoreFoundation pcm file.</div><div><br></div><div>$ cat /tmp/t.m<br>@import CoreFoundation;<br><br></div><div>$ env LIBCLANG_DISABLE_CRASH_RECOVERY=1 /path/to/Debug/bin/c-index-test -index-file-full -fmodules -fmodules-cache-path=/tmp/mcp /tmp/t.m<br>[enteredMainFile]: /tmp/t.m<br>[startedTranslationUnit]<br>[importedASTFile]: /tmp/mcp/LR9RPFKHW5SM/CoreFoundation-VHR5HL056G2W.pcm | loc: 1:1 | name: "CoreFoundation" | isImplicit: 0<br>[startedTranslationUnit]<br>Assertion failed: (II && MD), function setLoadedMacroDirective, file src/tools/clang/lib/Lex/PPMacroExpansion.cpp, line 64.<br>0  libclang.3.6.dylib       0x000000010cda4e5e llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 46<br>1  libclang.3.6.dylib       0x000000010cda6709 PrintStackTraceSignalHandler(void*) + 25<br>2  libclang.3.6.dylib       0x000000010cda6afe SignalHandler(int) + 526<br>3  libsystem_platform.dylib 0x00007fff8dcb0f1a _sigtramp + 26<br>4  libsystem_platform.dylib 0x6e696c202c707063 _sigtramp + 2661638499<br>5  libclang.3.6.dylib       0x000000010cda672b raise + 27<br>6  libclang.3.6.dylib       0x000000010cda67e2 abort + 18<br>7  libclang.3.6.dylib       0x000000010cda67c1 __assert_rtn + 129<br>8  libclang.3.6.dylib       0x000000010ba47d1f clang::Preprocessor::setLoadedMacroDirective(clang::IdentifierInfo*, clang::MacroDirective*) + 127<br>9  libclang.3.6.dylib       0x000000010d02e948 clang::ASTReader::resolvePendingMacro(clang::IdentifierInfo*, clang::ASTReader::PendingMacroInfo const&) + 2648<br>10 libclang.3.6.dylib       0x000000010d06125a clang::ASTReader::finishPendingActions() + 1786<br>11 libclang.3.6.dylib       0x000000010d062c02 clang::ASTReader::FinishedDeserializing() + 178<br>12 libclang.3.6.dylib       0x000000010d062ebc non-virtual thunk to clang::ASTReader::FinishedDeserializing() + 28<br>13 libclang.3.6.dylib       0x000000010b4e031c clang::ExternalASTSource::Deserializing::~Deserializing() + 28<br>14 libclang.3.6.dylib       0x000000010b4dc685 clang::ExternalASTSource::Deserializing::~Deserializing() + 21<br>15 libclang.3.6.dylib       0x000000010d05cfc6 clang::ASTReader::get(char const*, char const*) + 486<br>16 libclang.3.6.dylib       0x000000010d076df4 clang::ASTReader::get(llvm::StringRef) + 84<br>17 libclang.3.6.dylib       0x000000010d076f97 non-virtual thunk to clang::ASTReader::get(llvm::StringRef) + 55<br>18 libclang.3.6.dylib       0x000000010b213a0c clang::IdentifierTable::get(llvm::StringRef) + 572<br>19 libclang.3.6.dylib       0x000000010d05ea32 clang::ASTReader::DecodeIdentifierInfo(unsigned int) + 578<br>20 libclang.3.6.dylib       0x000000010d026020 clang::ASTReader::getLocalIdentifier(clang::serialization::ModuleFile&, unsigned int) + 64<br>21 libclang.3.6.dylib       0x000000010d04f501 clang::ASTReader::ReadPreprocessedEntity(unsigned int) + 1297<br>22 libclang.3.6.dylib       0x000000010d04f952 non-virtual thunk to clang::ASTReader::ReadPreprocessedEntity(unsigned int) + 34<br>23 libclang.3.6.dylib       0x000000010ba7220d clang::PreprocessingRecord::getLoadedPreprocessedEntity(unsigned int) + 317<br>24 libclang.3.6.dylib       0x000000010ba73c15 clang::PreprocessingRecord::getPreprocessedEntity(clang::PreprocessingRecord::PPEntityID) + 181<br>25 libclang.3.6.dylib       0x000000010b23662f clang::PreprocessingRecord::iterator::operator*() const + 159<br>26 libclang.3.6.dylib       0x000000010b313323 indexPreprocessingRecord(clang::ASTUnit&, clang::cxindex::IndexingContext&) + 163<br>27 libclang.3.6.dylib       0x000000010b30daa1 clang_indexTranslationUnit_Impl(void*) + 2289<br><br></div><br><div><blockquote type="cite"><div>On May 3, 2015, at 8:20 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_extra"><div class="gmail_quote">On Sat, May 2, 2015 at 7:43 PM, Argyrios Kyrtzidis<span> </span><span dir="ltr"><<a href="mailto:kyrtzidis@apple.com" target="_blank">kyrtzidis@apple.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Richard,<br><br>This commit crashes the preprocessing record (and in general PPCallbacks clients). To reproduce the crash try this change:<br><br>diff --git a/test/Modules/macros.c b/test/Modules/macros.c<br>index 0761669..d2dc326 100644<br>--- a/test/Modules/macros.c<br>+++ b/test/Modules/macros.c<br>@@ -1,5 +1,5 @@<br> // RUN: rm -rf %t<br>-// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s<br>+// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s -detailed-preprocessing-record<br> // RUN: %clang_cc1 -fmodules -DLOCAL_VISIBILITY -fmodules-local-submodule-visibility -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s<br> // RUN: not %clang_cc1 -E -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix CHECK-PREPROCESSED %s<br> // FIXME: When we have a syntax for modules in C, use that.<br><br>Could you take a look ?</blockquote><div><br></div><div>Thanks, should be fixed in r<span>236404; the PPCallbacks clients are now given the full macro information. This is an API change for PPCallbacks consumers, though.</span></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div>> On Apr 29, 2015, at 4:20 PM, Richard Smith <<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>> wrote:<br>><br>> Author: rsmith<br>> Date: Wed Apr 29 18:20:19 2015<br>> New Revision: 236176<br>><br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project?rev=236176&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=236176&view=rev</a><br>> Log:<br>> [modules] Stop trying to fake up a linear MacroDirective history.<br>><br>> Modules builds fundamentally have a non-linear macro history. In the interest<br>> of better source fidelity, represent the macro definition information<br>> faithfully: we have a linear macro directive history within each module, and at<br>> any point we have a unique "latest" local macro directive and a collection of<br>> visible imported directives. This also removes the attendent complexity of<br>> attempting to create a correct MacroDirective history (which we got wrong<br>> in the general case).<br>><br>> No functionality change intended.<br>><br>> Modified:<br>>    cfe/trunk/include/clang/AST/NSAPI.h<br>>    cfe/trunk/include/clang/Basic/IdentifierTable.h<br>>    cfe/trunk/include/clang/Lex/HeaderSearch.h<br>>    cfe/trunk/include/clang/Lex/Preprocessor.h<br>>    cfe/trunk/include/clang/Serialization/ASTReader.h<br>>    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp<br>>    cfe/trunk/lib/ARCMigrate/TransAPIUses.cpp<br>>    cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp<br>>    cfe/trunk/lib/ARCMigrate/TransUnusedInitDelegate.cpp<br>>    cfe/trunk/lib/ARCMigrate/Transforms.cpp<br>>    cfe/trunk/lib/ARCMigrate/Transforms.h<br>>    cfe/trunk/lib/AST/NSAPI.cpp<br>>    cfe/trunk/lib/Frontend/CompilerInstance.cpp<br>>    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp<br>>    cfe/trunk/lib/Lex/HeaderSearch.cpp<br>>    cfe/trunk/lib/Lex/MacroArgs.cpp<br>>    cfe/trunk/lib/Lex/PPDirectives.cpp<br>>    cfe/trunk/lib/Lex/PPExpressions.cpp<br>>    cfe/trunk/lib/Lex/PPLexerChange.cpp<br>>    cfe/trunk/lib/Lex/PPMacroExpansion.cpp<br>>    cfe/trunk/lib/Lex/Pragma.cpp<br>>    cfe/trunk/lib/Lex/Preprocessor.cpp<br>>    cfe/trunk/lib/Sema/SemaCodeComplete.cpp<br>>    cfe/trunk/lib/Sema/SemaExpr.cpp<br>>    cfe/trunk/lib/Sema/SemaFixItUtils.cpp<br>>    cfe/trunk/lib/Serialization/ASTReader.cpp<br>>    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp<br>>    cfe/trunk/lib/Serialization/ASTWriter.cpp<br>>    cfe/trunk/test/Index/complete-macros.c<br>>    cfe/trunk/test/Modules/macros.c<br>>    cfe/trunk/tools/libclang/CIndex.cpp<br>><br>> Modified: cfe/trunk/include/clang/AST/NSAPI.h<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/NSAPI.h?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/NSAPI.h?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/include/clang/AST/NSAPI.h (original)<br>> +++ cfe/trunk/include/clang/AST/NSAPI.h Wed Apr 29 18:20:19 2015<br>> @@ -216,6 +216,9 @@ public:<br>>   /// of that name in objective-c.<br>>   StringRef GetNSIntegralKind(QualType T) const;<br>><br>> +  /// \brief Returns \c true if \p Id is currently defined as a macro.<br>> +  bool isMacroDefined(StringRef Id) const;<br>> +<br>> private:<br>>   bool isObjCTypedef(QualType T, StringRef name, IdentifierInfo *&II) const;<br>>   bool isObjCEnumerator(const Expr *E,<br>><br>> Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)<br>> +++ cfe/trunk/include/clang/Basic/IdentifierTable.h Wed Apr 29 18:20:19 2015<br>> @@ -124,6 +124,7 @@ public:<br>>   }<br>><br>>   /// \brief Return true if this identifier is \#defined to some other value.<br>> +  /// \note The current definition may be in a module and not currently visible.<br>>   bool hasMacroDefinition() const {<br>>     return HasMacro;<br>>   }<br>><br>> Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)<br>> +++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Apr 29 18:20:19 2015<br>> @@ -32,6 +32,7 @@ class FileEntry;<br>> class FileManager;<br>> class HeaderSearchOptions;<br>> class IdentifierInfo;<br>> +class Preprocessor;<br>><br>> /// \brief The preprocessor keeps track of this information for each<br>> /// file that is \#included.<br>> @@ -419,8 +420,8 @@ public:<br>>   ///<br>>   /// \return false if \#including the file will have no effect or true<br>>   /// if we should include it.<br>> -  bool ShouldEnterIncludeFile(const FileEntry *File, bool isImport);<br>> -<br>> +  bool ShouldEnterIncludeFile(Preprocessor &PP, const FileEntry *File,<br>> +                              bool isImport);<br>><br>>   /// \brief Return whether the specified file is a normal header,<br>>   /// a system header, or a C++ friendly system header.<br>><br>> Modified: cfe/trunk/include/clang/Lex/Preprocessor.h<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/include/clang/Lex/Preprocessor.h (original)<br>> +++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Apr 29 18:20:19 2015<br>> @@ -386,7 +386,8 @@ class Preprocessor : public RefCountedBa<br>>   class MacroState {<br>>     mutable llvm::PointerUnion<MacroDirective *, ModuleMacroInfo *> State;<br>><br>> -    ModuleMacroInfo *getModuleInfo(Preprocessor &PP, IdentifierInfo *II) const {<br>> +    ModuleMacroInfo *getModuleInfo(Preprocessor &PP,<br>> +                                   const IdentifierInfo *II) const {<br>>       // FIXME: Find a spare bit on IdentifierInfo and store a<br>>       //        HasModuleMacros flag.<br>>       if (!II->hasMacroDefinition() || !PP.getLangOpts().Modules ||<br>> @@ -434,12 +435,12 @@ class Preprocessor : public RefCountedBa<br>>         State = MD;<br>>     }<br>><br>> -    bool isAmbiguous(Preprocessor &PP, IdentifierInfo *II) const {<br>> +    bool isAmbiguous(Preprocessor &PP, const IdentifierInfo *II) const {<br>>       auto *Info = getModuleInfo(PP, II);<br>>       return Info ? Info->IsAmbiguous : false;<br>>     }<br>> -    ArrayRef<ModuleMacro *> getActiveModuleMacros(Preprocessor &PP,<br>> -                                                  IdentifierInfo *II) const {<br>> +    ArrayRef<ModuleMacro *><br>> +    getActiveModuleMacros(Preprocessor &PP, const IdentifierInfo *II) const {<br>>       if (auto *Info = getModuleInfo(PP, II))<br>>         return Info->ActiveModuleMacros;<br>>       return None;<br>> @@ -755,33 +756,119 @@ public:<br>>   }<br>>   /// \}<br>><br>> -  /// \brief Given an identifier, return its latest MacroDirective if it is<br>> -  /// \#defined or null if it isn't \#define'd.<br>> -  MacroDirective *getMacroDirective(IdentifierInfo *II) const {<br>> +  /// \brief A description of the current definition of a macro.<br>> +  class MacroDefinition {<br>> +    llvm::PointerIntPair<DefMacroDirective*, 1, bool> LatestLocalAndAmbiguous;<br>> +    ArrayRef<ModuleMacro*> ModuleMacros;<br>> +  public:<br>> +    MacroDefinition() : LatestLocalAndAmbiguous(), ModuleMacros() {}<br>> +    MacroDefinition(DefMacroDirective *MD, ArrayRef<ModuleMacro *> MMs,<br>> +                    bool IsAmbiguous)<br>> +        : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}<br>> +<br>> +    /// \brief Determine whether there is a definition of this macro.<br>> +    explicit operator bool() const {<br>> +      return getLocalDirective() || !ModuleMacros.empty();<br>> +    }<br>> +<br>> +    /// \brief Get the MacroInfo that should be used for this definition.<br>> +    MacroInfo *getMacroInfo() const {<br>> +      if (!ModuleMacros.empty())<br>> +        return ModuleMacros.back()->getMacroInfo();<br>> +      if (auto *MD = getLocalDirective())<br>> +        return MD->getMacroInfo();<br>> +      return nullptr;<br>> +    }<br>> +<br>> +    /// \brief \c true if the definition is ambiguous, \c false otherwise.<br>> +    bool isAmbiguous() const { return LatestLocalAndAmbiguous.getInt(); }<br>> +<br>> +    /// \brief Get the latest non-imported, non-\#undef'd macro definition<br>> +    /// for this macro.<br>> +    DefMacroDirective *getLocalDirective() const {<br>> +      return LatestLocalAndAmbiguous.getPointer();<br>> +    }<br>> +<br>> +    /// \brief Get the active module macros for this macro.<br>> +    ArrayRef<ModuleMacro *> getModuleMacros() const {<br>> +      return ModuleMacros;<br>> +    }<br>> +<br>> +    template<typename Fn> void forAllDefinitions(Fn F) const {<br>> +      if (auto *MD = getLocalDirective())<br>> +        F(MD->getMacroInfo());<br>> +      for (auto *MM : getModuleMacros())<br>> +        F(MM->getMacroInfo());<br>> +    }<br>> +  };<br>> +<br>> +  bool isMacroDefined(StringRef Id) {<br>> +    return isMacroDefined(&Identifiers.get(Id));<br>> +  }<br>> +  bool isMacroDefined(const IdentifierInfo *II) {<br>> +    return II->hasMacroDefinition() &&<br>> +           (!getLangOpts().Modules || (bool)getMacroDefinition(II));<br>> +  }<br>> +<br>> +  MacroDefinition getMacroDefinition(const IdentifierInfo *II) {<br>>     if (!II->hasMacroDefinition())<br>> +      return MacroDefinition();<br>> +<br>> +    MacroState &S = Macros[II];<br>> +    auto *MD = S.getLatest();<br>> +    while (MD && isa<VisibilityMacroDirective>(MD))<br>> +      MD = MD->getPrevious();<br>> +    return MacroDefinition(dyn_cast_or_null<DefMacroDirective>(MD),<br>> +                           S.getActiveModuleMacros(*this, II),<br>> +                           S.isAmbiguous(*this, II));<br>> +  }<br>> +<br>> +  MacroDefinition getMacroDefinitionAtLoc(const IdentifierInfo *II,<br>> +                                          SourceLocation Loc) {<br>> +    if (!II->hadMacroDefinition())<br>> +      return MacroDefinition();<br>> +<br>> +    MacroState &S = Macros[II];<br>> +    MacroDirective::DefInfo DI;<br>> +    if (auto *MD = S.getLatest())<br>> +      DI = MD->findDirectiveAtLoc(Loc, getSourceManager());<br>> +    // FIXME: Compute the set of active module macros at the specified location.<br>> +    return MacroDefinition(DI.getDirective(),<br>> +                           S.getActiveModuleMacros(*this, II),<br>> +                           S.isAmbiguous(*this, II));<br>> +  }<br>> +<br>> +  /// \brief Given an identifier, return its latest non-imported MacroDirective<br>> +  /// if it is \#define'd and not \#undef'd, or null if it isn't \#define'd.<br>> +  MacroDirective *getLocalMacroDirective(const IdentifierInfo *II) const {<br>> +    if (!II->hasMacroDefinition())<br>> +      return nullptr;<br>> +<br>> +    auto *MD = getLocalMacroDirectiveHistory(II);<br>> +    if (!MD || MD->getDefinition().isUndefined())<br>>       return nullptr;<br>><br>> -    MacroDirective *MD = getMacroDirectiveHistory(II);<br>> -    assert(MD->isDefined() && "Macro is undefined!");<br>>     return MD;<br>>   }<br>><br>> -  const MacroInfo *getMacroInfo(IdentifierInfo *II) const {<br>> +  const MacroInfo *getMacroInfo(const IdentifierInfo *II) const {<br>>     return const_cast<Preprocessor*>(this)->getMacroInfo(II);<br>>   }<br>><br>> -  MacroInfo *getMacroInfo(IdentifierInfo *II) {<br>> -    if (MacroDirective *MD = getMacroDirective(II))<br>> -      return MD->getMacroInfo();<br>> +  MacroInfo *getMacroInfo(const IdentifierInfo *II) {<br>> +    if (!II->hasMacroDefinition())<br>> +      return nullptr;<br>> +    if (auto MD = getMacroDefinition(II))<br>> +      return MD.getMacroInfo();<br>>     return nullptr;<br>>   }<br>><br>> -  /// \brief Given an identifier, return the (probably #undef'd) MacroInfo<br>> -  /// representing the most recent macro definition.<br>> +  /// \brief Given an identifier, return the latest non-imported macro<br>> +  /// directive for that identifier.<br>>   ///<br>> -  /// One can iterate over all previous macro definitions from the most recent<br>> -  /// one. This should only be called for identifiers that hadMacroDefinition().<br>> -  MacroDirective *getMacroDirectiveHistory(const IdentifierInfo *II) const;<br>> +  /// One can iterate over all previous macro directives from the most recent<br>> +  /// one.<br>> +  MacroDirective *getLocalMacroDirectiveHistory(const IdentifierInfo *II) const;<br>><br>>   /// \brief Add a directive to the macro directive history for this identifier.<br>>   void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD);<br>> @@ -1580,7 +1667,7 @@ private:<br>><br>>   /// Update the set of active module macros and ambiguity flag for a module<br>>   /// macro name.<br>> -  void updateModuleMacroInfo(IdentifierInfo *II, ModuleMacroInfo &Info);<br>> +  void updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info);<br>><br>>   /// \brief Allocate a new MacroInfo object.<br>>   MacroInfo *AllocateMacroInfo();<br>> @@ -1644,7 +1731,7 @@ private:<br>>   /// If an identifier token is read that is to be expanded as a macro, handle<br>>   /// it and return the next token as 'Tok'.  If we lexed a token, return true;<br>>   /// otherwise the caller should lex again.<br>> -  bool HandleMacroExpandedIdentifier(Token &Tok, MacroDirective *MD);<br>> +  bool HandleMacroExpandedIdentifier(Token &Tok, const MacroDefinition &MD);<br>><br>>   /// \brief Cache macro expanded tokens for TokenLexers.<br>>   //<br>><br>> Modified: cfe/trunk/include/clang/Serialization/ASTReader.h<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/include/clang/Serialization/ASTReader.h (original)<br>> +++ cfe/trunk/include/clang/Serialization/ASTReader.h Wed Apr 29 18:20:19 2015<br>> @@ -576,54 +576,8 @@ private:<br>>   /// global submodule ID to produce a local ID.<br>>   GlobalSubmoduleMapType GlobalSubmoduleMap;<br>><br>> -  /// \brief Information on a macro definition or undefinition that is visible<br>> -  /// at the end of a submodule.<br>> -  struct ModuleMacroInfo;<br>> -<br>> -  /// \brief An entity that has been hidden.<br>> -  class HiddenName {<br>> -  public:<br>> -    enum NameKind {<br>> -      Declaration,<br>> -      Macro<br>> -    } Kind;<br>> -<br>> -  private:<br>> -    union {<br>> -      Decl *D;<br>> -      ModuleMacroInfo *MMI;<br>> -    };<br>> -<br>> -    IdentifierInfo *Id;<br>> -<br>> -  public:<br>> -    HiddenName(Decl *D) : Kind(Declaration), D(D), Id() { }<br>> -<br>> -    HiddenName(IdentifierInfo *II, ModuleMacroInfo *MMI)<br>> -      : Kind(Macro), MMI(MMI), Id(II) { }<br>> -<br>> -    NameKind getKind() const { return Kind; }<br>> -<br>> -    Decl *getDecl() const {<br>> -      assert(getKind() == Declaration && "Hidden name is not a declaration");<br>> -      return D;<br>> -    }<br>> -<br>> -    std::pair<IdentifierInfo *, ModuleMacroInfo *> getMacro() const {<br>> -      assert(getKind() == Macro && "Hidden name is not a macro!");<br>> -      return std::make_pair(Id, MMI);<br>> -    }<br>> -  };<br>> -<br>> -  typedef llvm::SmallDenseMap<IdentifierInfo*,<br>> -                              ModuleMacroInfo*> HiddenMacrosMap;<br>> -<br>>   /// \brief A set of hidden declarations.<br>> -  struct HiddenNames {<br>> -    SmallVector<Decl*, 2> HiddenDecls;<br>> -    HiddenMacrosMap HiddenMacros;<br>> -  };<br>> -<br>> +  typedef SmallVector<Decl*, 2> HiddenNames;<br>>   typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;<br>><br>>   /// \brief A mapping from each of the hidden submodules to the deserialized<br>> @@ -1850,20 +1804,6 @@ public:<br>><br>>   void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);<br>><br>> -  void installImportedMacro(IdentifierInfo *II, ModuleMacroInfo &MMI,<br>> -                            Module *Owner);<br>> -<br>> -  typedef llvm::TinyPtrVector<DefMacroDirective *> AmbiguousMacros;<br>> -  llvm::DenseMap<IdentifierInfo*, AmbiguousMacros> AmbiguousMacroDefs;<br>> -<br>> -  void removeOverriddenMacros(IdentifierInfo *II, SourceLocation Loc,<br>> -                              AmbiguousMacros &Ambig,<br>> -                              ArrayRef<ModuleMacro *> Overrides);<br>> -<br>> -  AmbiguousMacros *removeOverriddenMacros(IdentifierInfo *II,<br>> -                                          SourceLocation Loc,<br>> -                                          ArrayRef<ModuleMacro *> Overrides);<br>> -<br>>   /// \brief Retrieve the macro with the given ID.<br>>   MacroInfo *getMacro(serialization::MacroID ID);<br>><br>><br>> Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)<br>> +++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Apr 29 18:20:19 2015<br>> @@ -468,7 +468,7 @@ static void rewriteToObjCProperty(const<br>>   ASTContext &Context = NS.getASTContext();<br>>   bool LParenAdded = false;<br>>   std::string PropertyString = "@property ";<br>> -  if (UseNsIosOnlyMacro && Context.Idents.get("NS_NONATOMIC_IOSONLY").hasMacroDefinition()) {<br>> +  if (UseNsIosOnlyMacro && NS.isMacroDefined("NS_NONATOMIC_IOSONLY")) {<br>>     PropertyString += "(NS_NONATOMIC_IOSONLY";<br>>     LParenAdded = true;<br>>   } else if (!Atomic) {<br>> @@ -1277,7 +1277,7 @@ void ObjCMigrateASTConsumer::migrateNsRe<br>><br>>   QualType RT = OM->getReturnType();<br>>   if (!TypeIsInnerPointer(RT) ||<br>> -      !Ctx.Idents.get("NS_RETURNS_INNER_POINTER").hasMacroDefinition())<br>> +      !NSAPIObj->isMacroDefined("NS_RETURNS_INNER_POINTER"))<br>>     return;<br>><br>>   edit::Commit commit(*Editor);<br>> @@ -1288,9 +1288,9 @@ void ObjCMigrateASTConsumer::migrateNsRe<br>> void ObjCMigrateASTConsumer::migratePropertyNsReturnsInnerPointer(ASTContext &Ctx,<br>>                                                                   ObjCPropertyDecl *P) {<br>>   QualType T = P->getType();<br>> -<br>> +<br>>   if (!TypeIsInnerPointer(T) ||<br>> -      !Ctx.Idents.get("NS_RETURNS_INNER_POINTER").hasMacroDefinition())<br>> +      !NSAPIObj->isMacroDefined("NS_RETURNS_INNER_POINTER"))<br>>     return;<br>>   edit::Commit commit(*Editor);<br>>   commit.insertBefore(P->getLocEnd(), " NS_RETURNS_INNER_POINTER ");<br>> @@ -1408,7 +1408,7 @@ static bool AuditedType (QualType AT) {<br>> void ObjCMigrateASTConsumer::AnnotateImplicitBridging(ASTContext &Ctx) {<br>>   if (CFFunctionIBCandidates.empty())<br>>     return;<br>> -  if (!Ctx.Idents.get("CF_IMPLICIT_BRIDGING_ENABLED").hasMacroDefinition()) {<br>> +  if (!NSAPIObj->isMacroDefined("CF_IMPLICIT_BRIDGING_ENABLED")) {<br>>     CFFunctionIBCandidates.clear();<br>>     FileId = FileID();<br>>     return;<br>> @@ -1483,16 +1483,14 @@ void ObjCMigrateASTConsumer::AddCFAnnota<br>>     RetEffect Ret = CE.getReturnValue();<br>>     const char *AnnotationString = nullptr;<br>>     if (Ret.getObjKind() == RetEffect::CF) {<br>> -      if (Ret.isOwned() &&<br>> -          Ctx.Idents.get("CF_RETURNS_RETAINED").hasMacroDefinition())<br>> +      if (Ret.isOwned() && NSAPIObj->isMacroDefined("CF_RETURNS_RETAINED"))<br>>         AnnotationString = " CF_RETURNS_RETAINED";<br>>       else if (Ret.notOwned() &&<br>> -               Ctx.Idents.get("CF_RETURNS_NOT_RETAINED").hasMacroDefinition())<br>> +               NSAPIObj->isMacroDefined("CF_RETURNS_NOT_RETAINED"))<br>>         AnnotationString = " CF_RETURNS_NOT_RETAINED";<br>>     }<br>>     else if (Ret.getObjKind() == RetEffect::ObjC) {<br>> -      if (Ret.isOwned() &&<br>> -          Ctx.Idents.get("NS_RETURNS_RETAINED").hasMacroDefinition())<br>> +      if (Ret.isOwned() && NSAPIObj->isMacroDefined("NS_RETURNS_RETAINED"))<br>>         AnnotationString = " NS_RETURNS_RETAINED";<br>>     }<br>><br>> @@ -1509,13 +1507,13 @@ void ObjCMigrateASTConsumer::AddCFAnnota<br>>     const ParmVarDecl *pd = *pi;<br>>     ArgEffect AE = AEArgs[i];<br>>     if (AE == DecRef && !pd->hasAttr<CFConsumedAttr>() &&<br>> -        Ctx.Idents.get("CF_CONSUMED").hasMacroDefinition()) {<br>> +        NSAPIObj->isMacroDefined("CF_CONSUMED")) {<br>>       edit::Commit commit(*Editor);<br>>       commit.insertBefore(pd->getLocation(), "CF_CONSUMED ");<br>>       Editor->commit(commit);<br>>     }<br>>     else if (AE == DecRefMsg && !pd->hasAttr<NSConsumedAttr>() &&<br>> -             Ctx.Idents.get("NS_CONSUMED").hasMacroDefinition()) {<br>> +             NSAPIObj->isMacroDefined("NS_CONSUMED")) {<br>>       edit::Commit commit(*Editor);<br>>       commit.insertBefore(pd->getLocation(), "NS_CONSUMED ");<br>>       Editor->commit(commit);<br>> @@ -1600,11 +1598,10 @@ void ObjCMigrateASTConsumer::AddCFAnnota<br>>     RetEffect Ret = CE.getReturnValue();<br>>     const char *AnnotationString = nullptr;<br>>     if (Ret.getObjKind() == RetEffect::CF) {<br>> -      if (Ret.isOwned() &&<br>> -          Ctx.Idents.get("CF_RETURNS_RETAINED").hasMacroDefinition())<br>> +      if (Ret.isOwned() && NSAPIObj->isMacroDefined("CF_RETURNS_RETAINED"))<br>>         AnnotationString = " CF_RETURNS_RETAINED";<br>>       else if (Ret.notOwned() &&<br>> -               Ctx.Idents.get("CF_RETURNS_NOT_RETAINED").hasMacroDefinition())<br>> +               NSAPIObj->isMacroDefined("CF_RETURNS_NOT_RETAINED"))<br>>         AnnotationString = " CF_RETURNS_NOT_RETAINED";<br>>     }<br>>     else if (Ret.getObjKind() == RetEffect::ObjC) {<br>> @@ -1618,8 +1615,7 @@ void ObjCMigrateASTConsumer::AddCFAnnota<br>>           break;<br>><br>>         default:<br>> -          if (Ret.isOwned() &&<br>> -              Ctx.Idents.get("NS_RETURNS_RETAINED").hasMacroDefinition())<br>> +          if (Ret.isOwned() && NSAPIObj->isMacroDefined("NS_RETURNS_RETAINED"))<br>>             AnnotationString = " NS_RETURNS_RETAINED";<br>>           break;<br>>       }<br>> @@ -1638,7 +1634,7 @@ void ObjCMigrateASTConsumer::AddCFAnnota<br>>     const ParmVarDecl *pd = *pi;<br>>     ArgEffect AE = AEArgs[i];<br>>     if (AE == DecRef && !pd->hasAttr<CFConsumedAttr>() &&<br>> -        Ctx.Idents.get("CF_CONSUMED").hasMacroDefinition()) {<br>> +        NSAPIObj->isMacroDefined("CF_CONSUMED")) {<br>>       edit::Commit commit(*Editor);<br>>       commit.insertBefore(pd->getLocation(), "CF_CONSUMED ");<br>>       Editor->commit(commit);<br>> @@ -1658,12 +1654,12 @@ void ObjCMigrateASTConsumer::migrateAddM<br>>                                   MethodDecl->hasAttr<NSReturnsRetainedAttr>() ||<br>>                                   MethodDecl->hasAttr<NSReturnsNotRetainedAttr>() ||<br>>                                   MethodDecl->hasAttr<NSReturnsAutoreleasedAttr>());<br>> -<br>> -  if (CE.getReceiver() ==  DecRefMsg &&<br>> +<br>> +  if (CE.getReceiver() == DecRefMsg &&<br>>       !MethodDecl->hasAttr<NSConsumesSelfAttr>() &&<br>>       MethodDecl->getMethodFamily() != OMF_init &&<br>>       MethodDecl->getMethodFamily() != OMF_release &&<br>> -      Ctx.Idents.get("NS_CONSUMES_SELF").hasMacroDefinition()) {<br>> +      NSAPIObj->isMacroDefined("NS_CONSUMES_SELF")) {<br>>     edit::Commit commit(*Editor);<br>>     commit.insertBefore(MethodDecl->getLocEnd(), " NS_CONSUMES_SELF");<br>>     Editor->commit(commit);<br>> @@ -1729,7 +1725,7 @@ void ObjCMigrateASTConsumer::inferDesign<br>>   const ObjCInterfaceDecl *IFace = ImplD->getClassInterface();<br>>   if (!IFace || IFace->hasDesignatedInitializers())<br>>     return;<br>> -  if (!Ctx.Idents.get("NS_DESIGNATED_INITIALIZER").hasMacroDefinition())<br>> +  if (!NSAPIObj->isMacroDefined("NS_DESIGNATED_INITIALIZER"))<br>>     return;<br>><br>>   for (const auto *MD : ImplD->instance_methods()) {<br>><br>> Modified: cfe/trunk/lib/ARCMigrate/TransAPIUses.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransAPIUses.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransAPIUses.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/ARCMigrate/TransAPIUses.cpp (original)<br>> +++ cfe/trunk/lib/ARCMigrate/TransAPIUses.cpp Wed Apr 29 18:20:19 2015<br>> @@ -95,7 +95,7 @@ public:<br>>       Pass.TA.clearDiagnostic(diag::err_unavailable,<br>>                               diag::err_unavailable_message,<br>>                               E->getSelectorLoc(0));<br>> -      Pass.TA.replace(E->getSourceRange(), getNilString(Pass.Ctx));<br>> +      Pass.TA.replace(E->getSourceRange(), getNilString(Pass));<br>>     }<br>>     return true;<br>>   }<br>><br>> Modified: cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp (original)<br>> +++ cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp Wed Apr 29 18:20:19 2015<br>> @@ -145,7 +145,7 @@ public:<br>>       // when an exception is thrown.<br>>       Pass.TA.replace(RecContainer->getSourceRange(), RecRange);<br>>       std::string str = " = ";<br>> -      str += getNilString(Pass.Ctx);<br>> +      str += getNilString(Pass);<br>>       Pass.TA.insertAfterToken(RecRange.getEnd(), str);<br>>       return true;<br>>     }<br>><br>> Modified: cfe/trunk/lib/ARCMigrate/TransUnusedInitDelegate.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransUnusedInitDelegate.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransUnusedInitDelegate.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/ARCMigrate/TransUnusedInitDelegate.cpp (original)<br>> +++ cfe/trunk/lib/ARCMigrate/TransUnusedInitDelegate.cpp Wed Apr 29 18:20:19 2015<br>> @@ -58,7 +58,7 @@ public:<br>>       SourceRange ExprRange = ME->getSourceRange();<br>>       Pass.TA.insert(ExprRange.getBegin(), "if (!(self = ");<br>>       std::string retStr = ")) return ";<br>> -      retStr += getNilString(Pass.Ctx);<br>> +      retStr += getNilString(Pass);<br>>       Pass.TA.insertAfterToken(ExprRange.getEnd(), retStr);<br>>     }<br>>     return true;<br>><br>> Modified: cfe/trunk/lib/ARCMigrate/Transforms.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/ARCMigrate/Transforms.cpp (original)<br>> +++ cfe/trunk/lib/ARCMigrate/Transforms.cpp Wed Apr 29 18:20:19 2015<br>> @@ -16,6 +16,7 @@<br>> #include "clang/Basic/SourceManager.h"<br>> #include "clang/Basic/TargetInfo.h"<br>> #include "clang/Lex/Lexer.h"<br>> +#include "clang/Lex/Preprocessor.h"<br>> #include "clang/Sema/Sema.h"<br>> #include "clang/Sema/SemaDiagnostic.h"<br>> #include "llvm/ADT/DenseSet.h"<br>> @@ -212,11 +213,8 @@ bool trans::isGlobalVar(Expr *E) {<br>>   return false;<br>> }<br>><br>> -StringRef trans::getNilString(ASTContext &Ctx) {<br>> -  if (Ctx.Idents.get("nil").hasMacroDefinition())<br>> -    return "nil";<br>> -  else<br>> -    return "0";<br>> +StringRef trans::getNilString(MigrationPass &Pass) {<br>> +  return Pass.SemaRef.PP.isMacroDefined("nil") ? "nil" : "0";<br>> }<br>><br>> namespace {<br>><br>> Modified: cfe/trunk/lib/ARCMigrate/Transforms.h<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.h?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.h?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/ARCMigrate/Transforms.h (original)<br>> +++ cfe/trunk/lib/ARCMigrate/Transforms.h Wed Apr 29 18:20:19 2015<br>> @@ -180,7 +180,7 @@ SourceLocation findSemiAfterLocation(Sou<br>> bool hasSideEffects(Expr *E, ASTContext &Ctx);<br>> bool isGlobalVar(Expr *E);<br>> /// \brief Returns "nil" or "0" if 'nil' macro is not actually defined.<br>> -StringRef getNilString(ASTContext &Ctx);<br>> +StringRef getNilString(MigrationPass &Pass);<br>><br>> template <typename BODY_TRANS><br>> class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {<br>><br>> Modified: cfe/trunk/lib/AST/NSAPI.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/NSAPI.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/NSAPI.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/AST/NSAPI.cpp (original)<br>> +++ cfe/trunk/lib/AST/NSAPI.cpp Wed Apr 29 18:20:19 2015<br>> @@ -505,6 +505,11 @@ StringRef NSAPI::GetNSIntegralKind(QualT<br>>   return StringRef();<br>> }<br>><br>> +bool NSAPI::isMacroDefined(StringRef Id) const {<br>> +  // FIXME: Check whether the relevant module macros are visible.<br>> +  return Ctx.Idents.get(Id).hasMacroDefinition();<br>> +}<br>> +<br>> bool NSAPI::isObjCTypedef(QualType T,<br>>                           StringRef name, IdentifierInfo *&II) const {<br>>   if (!Ctx.getLangOpts().ObjC1)<br>><br>> Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)<br>> +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Apr 29 18:20:19 2015<br>> @@ -1084,79 +1084,51 @@ static void checkConfigMacro(Preprocesso<br>>   // not have changed.<br>>   if (!Id->hadMacroDefinition())<br>>     return;<br>> +  auto *LatestLocalMD = PP.getLocalMacroDirectiveHistory(Id);<br>><br>> -  // If this identifier does not currently have a macro definition,<br>> -  // check whether it had one on the command line.<br>> -  if (!Id->hasMacroDefinition()) {<br>> -    MacroDirective::DefInfo LatestDef =<br>> -        PP.getMacroDirectiveHistory(Id)->getDefinition();<br>> -    for (MacroDirective::DefInfo Def = LatestDef; Def;<br>> -           Def = Def.getPreviousDefinition()) {<br>> -      FileID FID = SourceMgr.getFileID(Def.getLocation());<br>> -      if (FID.isInvalid())<br>> -        continue;<br>> -<br>> -      // We only care about the predefines buffer.<br>> -      if (FID != PP.getPredefinesFileID())<br>> -        continue;<br>> -<br>> -      // This macro was defined on the command line, then #undef'd later.<br>> -      // Complain.<br>> -      PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)<br>> -        << true << ConfigMacro << Mod->getFullModuleName();<br>> -      if (LatestDef.isUndefined())<br>> -        PP.Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here)<br>> -          << true;<br>> -      return;<br>> -    }<br>> -<br>> -    // Okay: no definition in the predefines buffer.<br>> -    return;<br>> -  }<br>> -<br>> -  // This identifier has a macro definition. Check whether we had a definition<br>> -  // on the command line.<br>> -  MacroDirective::DefInfo LatestDef =<br>> -      PP.getMacroDirectiveHistory(Id)->getDefinition();<br>> -  MacroDirective::DefInfo PredefinedDef;<br>> -  for (MacroDirective::DefInfo Def = LatestDef; Def;<br>> -         Def = Def.getPreviousDefinition()) {<br>> -    FileID FID = SourceMgr.getFileID(Def.getLocation());<br>> -    if (FID.isInvalid())<br>> -      continue;<br>> -<br>> +  // Find the macro definition from the command line.<br>> +  MacroInfo *CmdLineDefinition = nullptr;<br>> +  for (auto *MD = LatestLocalMD; MD; MD = MD->getPrevious()) {<br>>     // We only care about the predefines buffer.<br>> -    if (FID != PP.getPredefinesFileID())<br>> +    FileID FID = SourceMgr.getFileID(MD->getLocation());<br>> +    if (FID.isInvalid() || FID != PP.getPredefinesFileID())<br>>       continue;<br>> -<br>> -    PredefinedDef = Def;<br>> +    if (auto *DMD = dyn_cast<DefMacroDirective>(MD))<br>> +      CmdLineDefinition = DMD->getMacroInfo();<br>>     break;<br>>   }<br>><br>> -  // If there was no definition for this macro in the predefines buffer,<br>> -  // complain.<br>> -  if (!PredefinedDef ||<br>> -      (!PredefinedDef.getLocation().isValid() &&<br>> -       PredefinedDef.getUndefLocation().isValid())) {<br>> +  auto *CurrentDefinition = PP.getMacroInfo(Id);<br>> +  if (CurrentDefinition == CmdLineDefinition) {<br>> +    // Macro matches. Nothing to do.<br>> +  } else if (!CurrentDefinition) {<br>> +    // This macro was defined on the command line, then #undef'd later.<br>> +    // Complain.<br>> +    PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)<br>> +      << true << ConfigMacro << Mod->getFullModuleName();<br>> +    auto LatestDef = LatestLocalMD->getDefinition();<br>> +    assert(LatestDef.isUndefined() &&<br>> +           "predefined macro went away with no #undef?");<br>> +    PP.Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here)<br>> +      << true;<br>> +    return;<br>> +  } else if (!CmdLineDefinition) {<br>> +    // There was no definition for this macro in the predefines buffer,<br>> +    // but there was a local definition. Complain.<br>>     PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)<br>>       << false << ConfigMacro << Mod->getFullModuleName();<br>> -    PP.Diag(LatestDef.getLocation(), diag::note_module_def_undef_here)<br>> +    PP.Diag(CurrentDefinition->getDefinitionLoc(),<br>> +            diag::note_module_def_undef_here)<br>> +      << false;<br>> +  } else if (!CurrentDefinition->isIdenticalTo(*CmdLineDefinition, PP,<br>> +                                               /*Syntactically=*/true)) {<br>> +    // The macro definitions differ.<br>> +    PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)<br>> +      << false << ConfigMacro << Mod->getFullModuleName();<br>> +    PP.Diag(CurrentDefinition->getDefinitionLoc(),<br>> +            diag::note_module_def_undef_here)<br>>       << false;<br>> -    return;<br>>   }<br>> -<br>> -  // If the current macro definition is the same as the predefined macro<br>> -  // definition, it's okay.<br>> -  if (LatestDef.getMacroInfo() == PredefinedDef.getMacroInfo() ||<br>> -      LatestDef.getMacroInfo()->isIdenticalTo(*PredefinedDef.getMacroInfo(),PP,<br>> -                                              /*Syntactically=*/true))<br>> -    return;<br>> -<br>> -  // The macro definitions differ.<br>> -  PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)<br>> -    << false << ConfigMacro << Mod->getFullModuleName();<br>> -  PP.Diag(LatestDef.getLocation(), diag::note_module_def_undef_here)<br>> -    << false;<br>> }<br>><br>> /// \brief Write a new timestamp file with the given path.<br>><br>> Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)<br>> +++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Wed Apr 29 18:20:19 2015<br>> @@ -686,9 +686,9 @@ static void DoPrintMacros(Preprocessor &<br>>   SmallVector<id_macro_pair, 128> MacrosByID;<br>>   for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();<br>>        I != E; ++I) {<br>> -    if (I->first->hasMacroDefinition())<br>> -      MacrosByID.push_back(<br>> -          id_macro_pair(I->first, I->second.getLatest()->getMacroInfo()));<br>> +    auto *MD = I->second.getLatest();<br>> +    if (MD && MD->isDefined())<br>> +      MacrosByID.push_back(id_macro_pair(I->first, MD->getMacroInfo()));<br>>   }<br>>   llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare);<br>><br>><br>> Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)<br>> +++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Apr 29 18:20:19 2015<br>> @@ -18,6 +18,7 @@<br>> #include "clang/Lex/HeaderSearchOptions.h"<br>> #include "clang/Lex/LexDiagnostic.h"<br>> #include "clang/Lex/Lexer.h"<br>> +#include "clang/Lex/Preprocessor.h"<br>> #include "llvm/ADT/APInt.h"<br>> #include "llvm/ADT/Hashing.h"<br>> #include "llvm/ADT/SmallString.h"<br>> @@ -1016,7 +1017,9 @@ void HeaderSearch::MarkFileModuleHeader(<br>>   HFI.setHeaderRole(Role);<br>> }<br>><br>> -bool HeaderSearch::ShouldEnterIncludeFile(const FileEntry *File, bool isImport){<br>> +bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,<br>> +                                          const FileEntry *File,<br>> +                                          bool isImport) {<br>>   ++NumIncluded; // Count # of attempted #includes.<br>><br>>   // Get information about this file.<br>> @@ -1041,7 +1044,7 @@ bool HeaderSearch::ShouldEnterIncludeFil<br>>   // if the macro that guards it is defined, we know the #include has no effect.<br>>   if (const IdentifierInfo *ControllingMacro<br>>       = FileInfo.getControllingMacro(ExternalLookup))<br>> -    if (ControllingMacro->hasMacroDefinition()) {<br>> +    if (PP.isMacroDefined(ControllingMacro)) {<br>>       ++NumMultiIncludeFileOptzn;<br>>       return false;<br>>     }<br>><br>> Modified: cfe/trunk/lib/Lex/MacroArgs.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroArgs.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroArgs.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Lex/MacroArgs.cpp (original)<br>> +++ cfe/trunk/lib/Lex/MacroArgs.cpp Wed Apr 29 18:20:19 2015<br>> @@ -133,12 +133,11 @@ bool MacroArgs::ArgNeedsPreexpansion(con<br>>   // If there are no identifiers in the argument list, or if the identifiers are<br>>   // known to not be macros, pre-expansion won't modify it.<br>>   for (; ArgTok->isNot(tok::eof); ++ArgTok)<br>> -    if (IdentifierInfo *II = ArgTok->getIdentifierInfo()) {<br>> -      if (II->hasMacroDefinition() && PP.getMacroInfo(II)->isEnabled())<br>> +    if (IdentifierInfo *II = ArgTok->getIdentifierInfo())<br>> +      if (II->hasMacroDefinition())<br>>         // Return true even though the macro could be a function-like macro<br>> -        // without a following '(' token.<br>> +        // without a following '(' token, or could be disabled, or not visible.<br>>         return true;<br>> -    }<br>>   return false;<br>> }<br>><br>><br>> Modified: cfe/trunk/lib/Lex/PPDirectives.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Lex/PPDirectives.cpp (original)<br>> +++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Apr 29 18:20:19 2015<br>> @@ -179,11 +179,13 @@ bool Preprocessor::CheckMacroName(Token<br>>     return Diag(MacroNameTok, diag::err_defined_macro_name);<br>>   }<br>><br>> -  if (isDefineUndef == MU_Undef && II->hasMacroDefinition() &&<br>> -      getMacroInfo(II)->isBuiltinMacro()) {<br>> -    // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4<br>> -    // and C++ [cpp.predefined]p4], but allow it as an extension.<br>> -    Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);<br>> +  if (isDefineUndef == MU_Undef) {<br>> +    auto *MI = getMacroInfo(II);<br>> +    if (MI && MI->isBuiltinMacro()) {<br>> +      // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4<br>> +      // and C++ [cpp.predefined]p4], but allow it as an extension.<br>> +      Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);<br>> +    }<br>>   }<br>><br>>   // If defining/undefining reserved identifier or a keyword, we need to issue<br>> @@ -1292,7 +1294,7 @@ void Preprocessor::HandleMacroPublicDire<br>><br>>   IdentifierInfo *II = MacroNameTok.getIdentifierInfo();<br>>   // Okay, we finally have a valid identifier to undef.<br>> -  MacroDirective *MD = getMacroDirective(II);<br>> +  MacroDirective *MD = getLocalMacroDirective(II);<br>><br>>   // If the macro is not defined, this is an error.<br>>   if (!MD) {<br>> @@ -1319,7 +1321,7 @@ void Preprocessor::HandleMacroPrivateDir<br>><br>>   IdentifierInfo *II = MacroNameTok.getIdentifierInfo();<br>>   // Okay, we finally have a valid identifier to undef.<br>> -  MacroDirective *MD = getMacroDirective(II);<br>> +  MacroDirective *MD = getLocalMacroDirective(II);<br>><br>>   // If the macro is not defined, this is an error.<br>>   if (!MD) {<br>> @@ -1757,7 +1759,7 @@ void Preprocessor::HandleIncludeDirectiv<br>><br>>   // Ask HeaderInfo if we should enter this #include file.  If not, #including<br>>   // this file will have no effect.<br>> -  if (!HeaderInfo.ShouldEnterIncludeFile(File, isImport)) {<br>> +  if (!HeaderInfo.ShouldEnterIncludeFile(*this, File, isImport)) {<br>>     if (Callbacks)<br>>       Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);<br>>     return;<br>> @@ -2295,16 +2297,19 @@ void Preprocessor::HandleUndefDirective(<br>>   // Check to see if this is the last token on the #undef line.<br>>   CheckEndOfDirective("undef");<br>><br>> -  // Okay, we finally have a valid identifier to undef.<br>> -  MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());<br>> -  const MacroInfo *MI = MD ? MD->getMacroInfo() : nullptr;<br>> +  // Okay, we have a valid identifier to undef.<br>> +  auto *II = MacroNameTok.getIdentifierInfo();<br>><br>>   // If the callbacks want to know, tell them about the macro #undef.<br>>   // Note: no matter if the macro was defined or not.<br>> -  if (Callbacks)<br>> +  if (Callbacks) {<br>> +    // FIXME: Tell callbacks about module macros.<br>> +    MacroDirective *MD = getLocalMacroDirective(II);<br>>     Callbacks->MacroUndefined(MacroNameTok, MD);<br>> +  }<br>><br>>   // If the macro is not defined, this is a noop undef, just return.<br>> +  const MacroInfo *MI = getMacroInfo(II);<br>>   if (!MI)<br>>     return;<br>><br>> @@ -2349,8 +2354,7 @@ void Preprocessor::HandleIfdefDirective(<br>>   CheckEndOfDirective(isIfndef ? "ifndef" : "ifdef");<br>><br>>   IdentifierInfo *MII = MacroNameTok.getIdentifierInfo();<br>> -  MacroDirective *MD = getMacroDirective(MII);<br>> -  MacroInfo *MI = MD ? MD->getMacroInfo() : nullptr;<br>> +  MacroInfo *MI = getMacroInfo(MII);<br>><br>>   if (CurPPLexer->getConditionalStackDepth() == 0) {<br>>     // If the start of a top-level #ifdef and if the macro is not defined,<br>> @@ -2369,6 +2373,8 @@ void Preprocessor::HandleIfdefDirective(<br>>     markMacroAsUsed(MI);<br>><br>>   if (Callbacks) {<br>> +    // FIXME: Tell callbacks about module macros.<br>> +    MacroDirective *MD = getLocalMacroDirective(MII);<br>>     if (isIfndef)<br>>       Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok, MD);<br>>     else<br>><br>> Modified: cfe/trunk/lib/Lex/PPExpressions.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Lex/PPExpressions.cpp (original)<br>> +++ cfe/trunk/lib/Lex/PPExpressions.cpp Wed Apr 29 18:20:19 2015<br>> @@ -108,15 +108,13 @@ static bool EvaluateDefined(PPValue &Res<br>><br>>   // Otherwise, we got an identifier, is it defined to something?<br>>   IdentifierInfo *II = PeekTok.getIdentifierInfo();<br>> -  Result.Val = II->hasMacroDefinition();<br>> +  Preprocessor::MacroDefinition Macro = PP.getMacroDefinition(II);<br>> +  Result.Val = !!Macro;<br>>   Result.Val.setIsUnsigned(false);  // Result is signed intmax_t.<br>><br>> -  MacroDirective *Macro = nullptr;<br>>   // If there is a macro, mark it used.<br>> -  if (Result.Val != 0 && ValueLive) {<br>> -    Macro = PP.getMacroDirective(II);<br>> -    PP.markMacroAsUsed(Macro->getMacroInfo());<br>> -  }<br>> +  if (Result.Val != 0 && ValueLive)<br>> +    PP.markMacroAsUsed(Macro.getMacroInfo());<br>><br>>   // Save macro token for callback.<br>>   Token macroToken(PeekTok);<br>> @@ -144,10 +142,8 @@ static bool EvaluateDefined(PPValue &Res<br>><br>>   // Invoke the 'defined' callback.<br>>   if (PPCallbacks *Callbacks = PP.getPPCallbacks()) {<br>> -    MacroDirective *MD = Macro;<br>> -    // Pass the MacroInfo for the macro name even if the value is dead.<br>> -    if (!MD && Result.Val != 0)<br>> -      MD = PP.getMacroDirective(II);<br>> +    // FIXME: Tell callbacks about module macros.<br>> +    MacroDirective *MD = Macro.getLocalDirective();<br>>     Callbacks->Defined(macroToken, MD,<br>>                        SourceRange(beginLoc, PeekTok.getLocation()));<br>>   }<br>><br>> Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)<br>> +++ cfe/trunk/lib/Lex/PPLexerChange.cpp Wed Apr 29 18:20:19 2015<br>> @@ -309,7 +309,7 @@ bool Preprocessor::HandleEndOfFile(Token<br>>         }<br>>         if (const IdentifierInfo *DefinedMacro =<br>>               CurPPLexer->MIOpt.GetDefinedMacro()) {<br>> -          if (!ControllingMacro->hasMacroDefinition() &&<br>> +          if (!isMacroDefined(ControllingMacro) &&<br>>               DefinedMacro != ControllingMacro &&<br>>               HeaderInfo.FirstTimeLexingFile(FE)) {<br>><br>><br>> Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)<br>> +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Wed Apr 29 18:20:19 2015<br>> @@ -34,12 +34,11 @@<br>> using namespace clang;<br>><br>> MacroDirective *<br>> -Preprocessor::getMacroDirectiveHistory(const IdentifierInfo *II) const {<br>> -  assert(II->hadMacroDefinition() && "Identifier has not been not a macro!");<br>> -<br>> +Preprocessor::getLocalMacroDirectiveHistory(const IdentifierInfo *II) const {<br>> +  if (!II->hadMacroDefinition())<br>> +    return nullptr;<br>>   auto Pos = Macros.find(II);<br>> -  assert(Pos != Macros.end() && "Identifier macro info is missing!");<br>> -  return Pos->second.getLatest();<br>> +  return Pos == Macros.end() ? nullptr : Pos->second.getLatest();<br>> }<br>><br>> void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){<br>> @@ -54,7 +53,7 @@ void Preprocessor::appendMacroDirective(<br>><br>>   // Set up the identifier as having associated macro history.<br>>   II->setHasMacroDefinition(true);<br>> -  if (!MD->isDefined())<br>> +  if (!MD->isDefined() && LeafModuleMacros.find(II) == LeafModuleMacros.end())<br>>     II->setHasMacroDefinition(false);<br>>   if (II->isFromAST() && !MD->isImported())<br>>     II->setChangedSinceDeserialization();<br>> @@ -69,7 +68,7 @@ void Preprocessor::setLoadedMacroDirecti<br>>   StoredMD = MD;<br>>   // Setup the identifier as having associated macro history.<br>>   II->setHasMacroDefinition(true);<br>> -  if (!MD->isDefined())<br>> +  if (!MD->isDefined() && LeafModuleMacros.find(II) == LeafModuleMacros.end())<br>>     II->setHasMacroDefinition(false);<br>> }<br>><br>> @@ -108,6 +107,8 @@ ModuleMacro *Preprocessor::addModuleMacr<br>><br>>   // The new macro is always a leaf macro.<br>>   LeafMacros.push_back(MM);<br>> +  // The identifier now has defined macros (that may or may not be visible).<br>> +  II->setHasMacroDefinition(true);<br>><br>>   New = true;<br>>   return MM;<br>> @@ -121,7 +122,7 @@ ModuleMacro *Preprocessor::getModuleMacr<br>>   return ModuleMacros.FindNodeOrInsertPos(ID, InsertPos);<br>> }<br>><br>> -void Preprocessor::updateModuleMacroInfo(IdentifierInfo *II,<br>> +void Preprocessor::updateModuleMacroInfo(const IdentifierInfo *II,<br>>                                          ModuleMacroInfo &Info) {<br>>   assert(Info.ActiveModuleMacrosGeneration != MacroVisibilityGeneration &&<br>>          "don't need to update this macro name info");<br>> @@ -156,14 +157,20 @@ void Preprocessor::updateModuleMacroInfo<br>>           Worklist.push_back(O);<br>>     }<br>>   }<br>> +  // Our reverse postorder walk found the macros in reverse order.<br>> +  std::reverse(Info.ActiveModuleMacros.begin(), Info.ActiveModuleMacros.end());<br>><br>>   // Determine whether the macro name is ambiguous.<br>> -  Info.IsAmbiguous = false;<br>>   MacroInfo *MI = nullptr;<br>> -  bool IsSystemMacro = false;<br>> -  if (auto *DMD = dyn_cast<DefMacroDirective>(Info.MD)) {<br>> -    MI = DMD->getInfo();<br>> -    IsSystemMacro = SourceMgr.isInSystemHeader(DMD->getLocation());<br>> +  bool IsSystemMacro = true;<br>> +  bool IsAmbiguous = false;<br>> +  if (auto *MD = Info.MD) {<br>> +    while (MD && isa<VisibilityMacroDirective>(MD))<br>> +      MD = MD->getPrevious();<br>> +    if (auto *DMD = dyn_cast_or_null<DefMacroDirective>(MD)) {<br>> +      MI = DMD->getInfo();<br>> +      IsSystemMacro &= SourceMgr.isInSystemHeader(DMD->getLocation());<br>> +    }<br>>   }<br>>   for (auto *Active : Info.ActiveModuleMacros) {<br>>     auto *NewMI = Active->getMacroInfo();<br>> @@ -177,13 +184,14 @@ void Preprocessor::updateModuleMacroInfo<br>>     //<br>>     // FIXME: Remove the defined-in-system-headers check. clang's limits.h<br>>     // overrides the system limits.h's macros, so there's no conflict here.<br>> -    IsSystemMacro &= Active->getOwningModule()->IsSystem;<br>> -    if (MI && NewMI != MI && !IsSystemMacro &&<br>> -        !MI->isIdenticalTo(*NewMI, *this, /*Syntactically=*/true)) {<br>> -      Info.IsAmbiguous = true;<br>> -      break;<br>> -    }<br>> +    if (MI && NewMI != MI &&<br>> +        !MI->isIdenticalTo(*NewMI, *this, /*Syntactically=*/true))<br>> +      IsAmbiguous = true;<br>> +    IsSystemMacro &= Active->getOwningModule()->IsSystem ||<br>> +                     SourceMgr.isInSystemHeader(NewMI->getDefinitionLoc());<br>> +    MI = NewMI;<br>>   }<br>> +  Info.IsAmbiguous = IsAmbiguous && !IsSystemMacro;<br>> }<br>><br>> /// RegisterBuiltinMacro - Register the specified identifier in the identifier<br>> @@ -270,10 +278,11 @@ static bool isTrivialSingleTokenExpansio<br>><br>>   // If the identifier is a macro, and if that macro is enabled, it may be<br>>   // expanded so it's not a trivial expansion.<br>> -  if (II->hasMacroDefinition() && PP.getMacroInfo(II)->isEnabled() &&<br>> -      // Fast expanding "#define X X" is ok, because X would be disabled.<br>> -      II != MacroIdent)<br>> -    return false;<br>> +  if (auto *ExpansionMI = PP.getMacroInfo(II))<br>> +    if (PP.getMacroInfo(II)->isEnabled() &&<br>> +        // Fast expanding "#define X X" is ok, because X would be disabled.<br>> +        II != MacroIdent)<br>> +      return false;<br>><br>>   // If this is an object-like macro invocation, it is safe to trivially expand<br>>   // it.<br>> @@ -336,10 +345,8 @@ bool Preprocessor::isNextPPTokenLParen()<br>> /// HandleMacroExpandedIdentifier - If an identifier token is read that is to be<br>> /// expanded as a macro, handle it and return the next token as 'Identifier'.<br>> bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,<br>> -                                                 MacroDirective *MD) {<br>> -  MacroDirective::DefInfo Def = MD->getDefinition();<br>> -  assert(Def.isValid());<br>> -  MacroInfo *MI = Def.getMacroInfo();<br>> +                                                 const MacroDefinition &M) {<br>> +  MacroInfo *MI = M.getMacroInfo();<br>><br>>   // If this is a macro expansion in the "#if !defined(x)" line for the file,<br>>   // then the macro could expand to different things in other contexts, we need<br>> @@ -348,7 +355,8 @@ bool Preprocessor::HandleMacroExpandedId<br>><br>>   // If this is a builtin macro, like __LINE__ or _Pragma, handle it specially.<br>>   if (MI->isBuiltinMacro()) {<br>> -    if (Callbacks) Callbacks->MacroExpands(Identifier, MD,<br>> +    // FIXME: Tell callbacks about module macros.<br>> +    if (Callbacks) Callbacks->MacroExpands(Identifier, M.getLocalDirective(),<br>>                                            Identifier.getLocation(),<br>>                                            /*Args=*/nullptr);<br>>     ExpandBuiltinMacro(Identifier);<br>> @@ -396,10 +404,13 @@ bool Preprocessor::HandleMacroExpandedId<br>>       // reading the function macro arguments. To ensure, in that case, that<br>>       // MacroExpands callbacks still happen in source order, queue this<br>>       // callback to have it happen after the function macro callback.<br>> +      // FIXME: Tell callbacks about module macros.<br>>       DelayedMacroExpandsCallbacks.push_back(<br>> -                              MacroExpandsInfo(Identifier, MD, ExpansionRange));<br>> +          MacroExpandsInfo(Identifier, M.getLocalDirective(), ExpansionRange));<br>>     } else {<br>> -      Callbacks->MacroExpands(Identifier, MD, ExpansionRange, Args);<br>> +      // FIXME: Tell callbacks about module macros.<br>> +      Callbacks->MacroExpands(Identifier, M.getLocalDirective(), ExpansionRange,<br>> +                              Args);<br>>       if (!DelayedMacroExpandsCallbacks.empty()) {<br>>         for (unsigned i=0, e = DelayedMacroExpandsCallbacks.size(); i!=e; ++i) {<br>>           MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];<br>> @@ -413,20 +424,16 @@ bool Preprocessor::HandleMacroExpandedId<br>>   }<br>><br>>   // If the macro definition is ambiguous, complain.<br>> -  if (Def.getDirective()->isAmbiguous()) {<br>> +  if (M.isAmbiguous()) {<br>>     Diag(Identifier, diag::warn_pp_ambiguous_macro)<br>>       << Identifier.getIdentifierInfo();<br>>     Diag(MI->getDefinitionLoc(), diag::note_pp_ambiguous_macro_chosen)<br>>       << Identifier.getIdentifierInfo();<br>> -    for (MacroDirective::DefInfo PrevDef = Def.getPreviousDefinition();<br>> -         PrevDef && !PrevDef.isUndefined();<br>> -         PrevDef = PrevDef.getPreviousDefinition()) {<br>> -      Diag(PrevDef.getMacroInfo()->getDefinitionLoc(),<br>> -           diag::note_pp_ambiguous_macro_other)<br>> -        << Identifier.getIdentifierInfo();<br>> -      if (!PrevDef.getDirective()->isAmbiguous())<br>> -        break;<br>> -    }<br>> +    M.forAllDefinitions([&](const MacroInfo *OtherMI) {<br>> +      if (OtherMI != MI)<br>> +        Diag(OtherMI->getDefinitionLoc(), diag::note_pp_ambiguous_macro_other)<br>> +          << Identifier.getIdentifierInfo();<br>> +    });<br>>   }<br>><br>>   // If we started lexing a macro, enter the macro expansion body.<br>><br>> Modified: cfe/trunk/lib/Lex/Pragma.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Lex/Pragma.cpp (original)<br>> +++ cfe/trunk/lib/Lex/Pragma.cpp Wed Apr 29 18:20:19 2015<br>> @@ -400,7 +400,7 @@ void Preprocessor::HandlePragmaPoison(To<br>>     if (II->isPoisoned()) continue;<br>><br>>     // If this is a macro identifier, emit a warning.<br>> -    if (II->hasMacroDefinition())<br>> +    if (isMacroDefined(II))<br>>       Diag(Tok, diag::pp_poisoning_existing_macro);<br>><br>>     // Finally, poison it!<br>> @@ -590,8 +590,7 @@ void Preprocessor::HandlePragmaPopMacro(<br>>     PragmaPushMacroInfo.find(IdentInfo);<br>>   if (iter != PragmaPushMacroInfo.end()) {<br>>     // Forget the MacroInfo currently associated with IdentInfo.<br>> -    if (MacroDirective *CurrentMD = getMacroDirective(IdentInfo)) {<br>> -      MacroInfo *MI = CurrentMD->getMacroInfo();<br>> +    if (MacroInfo *MI = getMacroInfo(IdentInfo)) {<br>>       if (MI->isWarnIfUnused())<br>>         WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());<br>>       appendMacroDirective(IdentInfo, AllocateUndefMacroDirective(MessageLoc));<br>><br>> Modified: cfe/trunk/lib/Lex/Preprocessor.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Lex/Preprocessor.cpp (original)<br>> +++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Apr 29 18:20:19 2015<br>> @@ -73,8 +73,7 @@ Preprocessor::Preprocessor(IntrusiveRefC<br>>       ModuleImportExpectsIdentifier(false), CodeCompletionReached(0),<br>>       MainFileDir(nullptr), SkipMainFilePreamble(0, true), CurPPLexer(nullptr),<br>>       CurDirLookup(nullptr), CurLexerKind(CLK_Lexer), CurSubmodule(nullptr),<br>> -      Callbacks(nullptr), MacroVisibilityGeneration(0),<br>> -      MacroArgCache(nullptr), Record(nullptr),<br>> +      Callbacks(nullptr), MacroArgCache(nullptr), Record(nullptr),<br>>       MIChainHead(nullptr), DeserialMIChainHead(nullptr) {<br>>   OwnsHeaderSearch = OwnsHeaders;<br>><br>> @@ -108,6 +107,9 @@ Preprocessor::Preprocessor(IntrusiveRefC<br>><br>>   // We haven't read anything from the external source.<br>>   ReadMacrosFromExternalSource = false;<br>> +  // We might already have some macros from an imported module (via a PCH or<br>> +  // preamble) if modules is enabled.<br>> +  MacroVisibilityGeneration = LangOpts.Modules ? 1 : 0;<br>><br>>   // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro.<br>>   // This gets unpoisoned where it is allowed.<br>> @@ -623,8 +625,8 @@ bool Preprocessor::HandleIdentifier(Toke<br>>   }<br>><br>>   // If this is a macro to be expanded, do it.<br>> -  if (MacroDirective *MD = getMacroDirective(&II)) {<br>> -    MacroInfo *MI = MD->getMacroInfo();<br>> +  if (MacroDefinition MD = getMacroDefinition(&II)) {<br>> +    auto *MI = MD.getMacroInfo();<br>>     if (!DisableMacroExpansion) {<br>>       if (!Identifier.isExpandDisabled() && MI->isEnabled()) {<br>>         // C99 6.10.3p10: If the preprocessing token immediately after the<br>><br>> Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)<br>> +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Apr 29 18:20:19 2015<br>> @@ -2017,7 +2017,7 @@ static void AddOrdinaryNameResults(Sema:<br>>     if (SemaRef.getLangOpts().C11) {<br>>       // _Alignof<br>>       Builder.AddResultTypeChunk("size_t");<br>> -      if (SemaRef.getASTContext().Idents.get("alignof").hasMacroDefinition())<br>> +      if (SemaRef.PP.isMacroDefined("alignof"))<br>>         Builder.AddTypedTextChunk("alignof");<br>>       else<br>>         Builder.AddTypedTextChunk("_Alignof");<br>> @@ -2085,15 +2085,14 @@ static void AddResultTypeChunk(ASTContex<br>>                                                     Result.getAllocator()));<br>> }<br>><br>> -static void MaybeAddSentinel(ASTContext &Context,<br>> +static void MaybeAddSentinel(Preprocessor &PP,<br>>                              const NamedDecl *FunctionOrMethod,<br>>                              CodeCompletionBuilder &Result) {<br>>   if (SentinelAttr *Sentinel = FunctionOrMethod->getAttr<SentinelAttr>())<br>>     if (Sentinel->getSentinel() == 0) {<br>> -      if (Context.getLangOpts().ObjC1 &&<br>> -          Context.Idents.get("nil").hasMacroDefinition())<br>> +      if (PP.getLangOpts().ObjC1 && PP.isMacroDefined("nil"))<br>>         Result.AddTextChunk(", nil");<br>> -      else if (Context.Idents.get("NULL").hasMacroDefinition())<br>> +      else if (PP.isMacroDefined("NULL"))<br>>         Result.AddTextChunk(", NULL");<br>>       else<br>>         Result.AddTextChunk(", (void*)0");<br>> @@ -2117,8 +2116,7 @@ static std::string formatObjCParamQualif<br>>   return Result;<br>> }<br>><br>> -static std::string FormatFunctionParameter(ASTContext &Context,<br>> -                                           const PrintingPolicy &Policy,<br>> +static std::string FormatFunctionParameter(const PrintingPolicy &Policy,<br>>                                            const ParmVarDecl *Param,<br>>                                            bool SuppressName = false,<br>>                                            bool SuppressBlock = false) {<br>> @@ -2217,7 +2215,7 @@ static std::string FormatFunctionParamet<br>>     for (unsigned I = 0, N = Block.getNumParams(); I != N; ++I) {<br>>       if (I)<br>>         Params += ", ";<br>> -      Params += FormatFunctionParameter(Context, Policy, Block.getParam(I),<br>> +      Params += FormatFunctionParameter(Policy, Block.getParam(I),<br>>                                         /*SuppressName=*/false,<br>>                                         /*SuppressBlock=*/true);<br>><br>> @@ -2247,7 +2245,7 @@ static std::string FormatFunctionParamet<br>> }<br>><br>> /// \brief Add function parameter chunks to the given code completion string.<br>> -static void AddFunctionParameterChunks(ASTContext &Context,<br>> +static void AddFunctionParameterChunks(Preprocessor &PP,<br>>                                        const PrintingPolicy &Policy,<br>>                                        const FunctionDecl *Function,<br>>                                        CodeCompletionBuilder &Result,<br>> @@ -2265,7 +2263,7 @@ static void AddFunctionParameterChunks(A<br>>                                 Result.getCodeCompletionTUInfo());<br>>       if (!FirstParameter)<br>>         Opt.AddChunk(CodeCompletionString::CK_Comma);<br>> -      AddFunctionParameterChunks(Context, Policy, Function, Opt, P, true);<br>> +      AddFunctionParameterChunks(PP, Policy, Function, Opt, P, true);<br>>       Result.AddOptionalChunk(Opt.TakeString());<br>>       break;<br>>     }<br>> @@ -2278,9 +2276,8 @@ static void AddFunctionParameterChunks(A<br>>     InOptional = false;<br>><br>>     // Format the placeholder string.<br>> -    std::string PlaceholderStr = FormatFunctionParameter(Context, Policy,<br>> -                                                         Param);<br>> -<br>> +    std::string PlaceholderStr = FormatFunctionParameter(Policy, Param);<br>> +<br>>     if (Function->isVariadic() && P == N - 1)<br>>       PlaceholderStr += ", ...";<br>><br>> @@ -2295,7 +2292,7 @@ static void AddFunctionParameterChunks(A<br>>       if (Proto->getNumParams() == 0)<br>>         Result.AddPlaceholderChunk("...");<br>><br>> -      MaybeAddSentinel(Context, Function, Result);<br>> +      MaybeAddSentinel(PP, Function, Result);<br>>     }<br>> }<br>><br>> @@ -2575,11 +2572,7 @@ CodeCompletionResult::CreateCodeCompleti<br>>   }<br>><br>>   if (Kind == RK_Macro) {<br>> -    const MacroDirective *MD = PP.getMacroDirectiveHistory(Macro);<br>> -    assert(MD && "Not a macro?");<br>> -    const MacroInfo *MI = MD->getMacroInfo();<br>> -    assert((!MD->isDefined() || MI) && "missing MacroInfo for define");<br>> -<br>> +    const MacroInfo *MI = PP.getMacroInfo(Macro);<br>>     Result.AddTypedTextChunk(<br>>                             Result.getAllocator().CopyString(Macro->getName()));<br>><br>> @@ -2654,7 +2647,7 @@ CodeCompletionResult::CreateCodeCompleti<br>>                                    Ctx, Policy);<br>>     AddTypedNameChunk(Ctx, Policy, ND, Result);<br>>     Result.AddChunk(CodeCompletionString::CK_LeftParen);<br>> -    AddFunctionParameterChunks(Ctx, Policy, Function, Result);<br>> +    AddFunctionParameterChunks(PP, Policy, Function, Result);<br>>     Result.AddChunk(CodeCompletionString::CK_RightParen);<br>>     AddFunctionTypeQualsToCompletionString(Result, Function);<br>>     return Result.TakeString();<br>> @@ -2708,7 +2701,7 @@ CodeCompletionResult::CreateCodeCompleti<br>><br>>     // Add the function parameters<br>>     Result.AddChunk(CodeCompletionString::CK_LeftParen);<br>> -    AddFunctionParameterChunks(Ctx, Policy, Function, Result);<br>> +    AddFunctionParameterChunks(PP, Policy, Function, Result);<br>>     Result.AddChunk(CodeCompletionString::CK_RightParen);<br>>     AddFunctionTypeQualsToCompletionString(Result, Function);<br>>     return Result.TakeString();<br>> @@ -2769,7 +2762,7 @@ CodeCompletionResult::CreateCodeCompleti<br>>       std::string Arg;<br>><br>>       if ((*P)->getType()->isBlockPointerType() && !DeclaringEntity)<br>> -        Arg = FormatFunctionParameter(Ctx, Policy, *P, true);<br>> +        Arg = FormatFunctionParameter(Policy, *P, true);<br>>       else {<br>>         (*P)->getType().getAsStringInternal(Arg, Policy);<br>>         Arg = "(" + formatObjCParamQualifiers((*P)->getObjCDeclQualifier())<br>> @@ -2800,7 +2793,7 @@ CodeCompletionResult::CreateCodeCompleti<br>>           Result.AddPlaceholderChunk(", ...");<br>>       }<br>><br>> -      MaybeAddSentinel(Ctx, Method, Result);<br>> +      MaybeAddSentinel(PP, Method, Result);<br>>     }<br>><br>>     return Result.TakeString();<br>> @@ -2854,8 +2847,7 @@ static void AddOverloadParameterChunks(A<br>>     // Format the placeholder string.<br>>     std::string Placeholder;<br>>     if (Function)<br>> -      Placeholder = FormatFunctionParameter(Context, Policy,<br>> -                                            Function->getParamDecl(P));<br>> +      Placeholder = FormatFunctionParameter(Policy, Function->getParamDecl(P));<br>>     else<br>>       Placeholder = Prototype->getParamType(P).getAsString(Policy);<br>><br>> @@ -3036,8 +3028,9 @@ static void AddMacroResults(Preprocessor<br>>   for (Preprocessor::macro_iterator M = PP.macro_begin(),<br>>                                  MEnd = PP.macro_end();<br>>        M != MEnd; ++M) {<br>> -    if (IncludeUndefined || M->first->hasMacroDefinition()) {<br>> -      if (MacroInfo *MI = M->second.getLatest()->getMacroInfo())<br>> +    auto MD = PP.getMacroDefinition(M->first);<br>> +    if (IncludeUndefined || MD) {<br>> +      if (MacroInfo *MI = MD.getMacroInfo())<br>>         if (MI->isUsedForHeaderGuard())<br>>           continue;<br>><br>> @@ -5122,7 +5115,7 @@ void Sema::CodeCompleteObjCPassingType(S<br>>   // an action, e.g.,<br>>   //   IBAction)<#selector#>:(id)sender<br>>   if (DS.getObjCDeclQualifier() == 0 && !IsParameter &&<br>> -      Context.Idents.get("IBAction").hasMacroDefinition()) {<br>> +      PP.isMacroDefined("IBAction")) {<br>>     CodeCompletionBuilder Builder(Results.getAllocator(),<br>>                                   Results.getCodeCompletionTUInfo(),<br>>                                   CCP_CodePattern, CXAvailability_Available);<br>><br>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Apr 29 18:20:19 2015<br>> @@ -450,12 +450,11 @@ void Sema::DiagnoseSentinelCalls(NamedDe<br>>   SourceLocation MissingNilLoc<br>>     = PP.getLocForEndOfToken(sentinelExpr->getLocEnd());<br>>   std::string NullValue;<br>> -  if (calleeType == CT_Method &&<br>> -      PP.getIdentifierInfo("nil")->hasMacroDefinition())<br>> +  if (calleeType == CT_Method && PP.isMacroDefined("nil"))<br>>     NullValue = "nil";<br>>   else if (getLangOpts().CPlusPlus11)<br>>     NullValue = "nullptr";<br>> -  else if (PP.getIdentifierInfo("NULL")->hasMacroDefinition())<br>> +  else if (PP.isMacroDefined("NULL"))<br>>     NullValue = "NULL";<br>>   else<br>>     NullValue = "(void*) 0";<br>><br>> Modified: cfe/trunk/lib/Sema/SemaFixItUtils.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaFixItUtils.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaFixItUtils.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Sema/SemaFixItUtils.cpp (original)<br>> +++ cfe/trunk/lib/Sema/SemaFixItUtils.cpp Wed Apr 29 18:20:19 2015<br>> @@ -161,11 +161,8 @@ bool ConversionFixItGenerator::tryToFixC<br>> }<br>><br>> static bool isMacroDefined(const Sema &S, SourceLocation Loc, StringRef Name) {<br>> -  const IdentifierInfo *II = &S.getASTContext().Idents.get(Name);<br>> -  if (!II->hadMacroDefinition()) return false;<br>> -<br>> -  MacroDirective *Macro = S.PP.getMacroDirectiveHistory(II);<br>> -  return Macro && Macro->findDirectiveAtLoc(Loc, S.getSourceManager());<br>> +  return (bool)S.PP.getMacroDefinitionAtLoc(&S.getASTContext().Idents.get(Name),<br>> +                                            Loc);<br>> }<br>><br>> static std::string getScalarZeroExpressionForType(<br>><br>> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)<br>> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Apr 29 18:20:19 2015<br>> @@ -1723,22 +1723,6 @@ void ASTReader::markIdentifierUpToDate(I<br>>     IdentifierGeneration[II] = getGeneration();<br>> }<br>><br>> -struct ASTReader::ModuleMacroInfo {<br>> -  ModuleMacro *MM;<br>> -  // FIXME: Remove this.<br>> -  ModuleFile *F;<br>> -<br>> -  bool isDefine() const { return MM->getMacroInfo(); }<br>> -<br>> -  ArrayRef<ModuleMacro *> getOverriddenMacros() const {<br>> -    return MM->overrides();<br>> -  }<br>> -<br>> -  MacroDirective *import(Preprocessor &PP, SourceLocation ImportLoc) const {<br>> -    return PP.AllocateImportedMacroDirective(MM, ImportLoc);<br>> -  }<br>> -};<br>> -<br>> void ASTReader::resolvePendingMacro(IdentifierInfo *II,<br>>                                     const PendingMacroInfo &PMInfo) {<br>>   ModuleFile &M = *PMInfo.M;<br>> @@ -1806,19 +1790,7 @@ void ASTReader::resolvePendingMacro(Iden<br>><br>>       bool Inserted = false;<br>>       Module *Owner = getSubmodule(MMR.SubModID);<br>> -      auto *MM = PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted);<br>> -      if (!Inserted)<br>> -        continue;<br>> -<br>> -      ModuleMacroInfo MMI = { MM, &M };<br>> -      if (Owner->NameVisibility == Module::Hidden) {<br>> -        // Macros in the owning module are hidden. Just remember this macro to<br>> -        // install if we make this module visible.<br>> -        HiddenNamesMap[Owner].HiddenMacros.insert(<br>> -            std::make_pair(II, new (Context) ModuleMacroInfo(MMI)));<br>> -      } else {<br>> -        installImportedMacro(II, MMI, Owner);<br>> -      }<br>> +      PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted);<br>>     }<br>>   }<br>><br>> @@ -1870,164 +1842,6 @@ void ASTReader::resolvePendingMacro(Iden<br>>   PP.setLoadedMacroDirective(II, Latest);<br>> }<br>><br>> -/// \brief For the given macro definitions, check if they are both in system<br>> -/// modules.<br>> -static bool areDefinedInSystemModules(MacroInfo *PrevMI, MacroInfo *NewMI,<br>> -                                      Module *NewOwner, ASTReader &Reader) {<br>> -  assert(PrevMI && NewMI);<br>> -  Module *PrevOwner = nullptr;<br>> -  if (SubmoduleID PrevModID = PrevMI->getOwningModuleID())<br>> -    PrevOwner = Reader.getSubmodule(PrevModID);<br>> -  if (PrevOwner && PrevOwner == NewOwner)<br>> -    return false;<br>> -  SourceManager &SrcMgr = Reader.getSourceManager();<br>> -  bool PrevInSystem = (PrevOwner && PrevOwner->IsSystem) ||<br>> -                      SrcMgr.isInSystemHeader(PrevMI->getDefinitionLoc());<br>> -  bool NewInSystem = (NewOwner && NewOwner->IsSystem) ||<br>> -                     SrcMgr.isInSystemHeader(NewMI->getDefinitionLoc());<br>> -  return PrevInSystem && NewInSystem;<br>> -}<br>> -<br>> -void ASTReader::removeOverriddenMacros(IdentifierInfo *II,<br>> -                                       SourceLocation ImportLoc,<br>> -                                       AmbiguousMacros &Ambig,<br>> -                                       ArrayRef<ModuleMacro *> Overrides) {<br>> -  for (ModuleMacro *Overridden : Overrides) {<br>> -    Module *Owner = Overridden->getOwningModule();<br>> -    // If this macro is not yet visible, remove it from the hidden names list.<br>> -    // It won't be there if we're in the middle of making the owner visible.<br>> -    auto HiddenIt = HiddenNamesMap.find(Owner);<br>> -    if (HiddenIt != HiddenNamesMap.end()) {<br>> -      HiddenNames &Hidden = HiddenIt->second;<br>> -      HiddenMacrosMap::iterator HI = Hidden.HiddenMacros.find(II);<br>> -      if (HI != Hidden.HiddenMacros.end()) {<br>> -        // Register the macro now so we don't lose it when we re-export.<br>> -        PP.appendMacroDirective(II, HI->second->import(PP, ImportLoc));<br>> -<br>> -        auto SubOverrides = HI->second->getOverriddenMacros();<br>> -        Hidden.HiddenMacros.erase(HI);<br>> -        removeOverriddenMacros(II, ImportLoc, Ambig, SubOverrides);<br>> -      }<br>> -    }<br>> -<br>> -    // If this macro is already in our list of conflicts, remove it from there.<br>> -    Ambig.erase(<br>> -        std::remove_if(Ambig.begin(), Ambig.end(), [&](DefMacroDirective *MD) {<br>> -          return getSubmodule(MD->getInfo()->getOwningModuleID()) == Owner;<br>> -        }),<br>> -        Ambig.end());<br>> -  }<br>> -}<br>> -<br>> -ASTReader::AmbiguousMacros *<br>> -ASTReader::removeOverriddenMacros(IdentifierInfo *II,<br>> -                                  SourceLocation ImportLoc,<br>> -                                  ArrayRef<ModuleMacro *> Overrides) {<br>> -  MacroDirective *Prev = PP.getMacroDirective(II);<br>> -  if (!Prev && Overrides.empty())<br>> -    return nullptr;<br>> -<br>> -  DefMacroDirective *PrevDef = Prev ? Prev->getDefinition().getDirective()<br>> -                                    : nullptr;<br>> -  if (PrevDef && PrevDef->isAmbiguous()) {<br>> -    // We had a prior ambiguity. Check whether we resolve it (or make it worse).<br>> -    AmbiguousMacros &Ambig = AmbiguousMacroDefs[II];<br>> -    Ambig.push_back(PrevDef);<br>> -<br>> -    removeOverriddenMacros(II, ImportLoc, Ambig, Overrides);<br>> -<br>> -    if (!Ambig.empty())<br>> -      return &Ambig;<br>> -<br>> -    AmbiguousMacroDefs.erase(II);<br>> -  } else {<br>> -    // There's no ambiguity yet. Maybe we're introducing one.<br>> -    AmbiguousMacros Ambig;<br>> -    if (PrevDef)<br>> -      Ambig.push_back(PrevDef);<br>> -<br>> -    removeOverriddenMacros(II, ImportLoc, Ambig, Overrides);<br>> -<br>> -    if (!Ambig.empty()) {<br>> -      AmbiguousMacros &Result = AmbiguousMacroDefs[II];<br>> -      std::swap(Result, Ambig);<br>> -      return &Result;<br>> -    }<br>> -  }<br>> -<br>> -  // We ended up with no ambiguity.<br>> -  return nullptr;<br>> -}<br>> -<br>> -void ASTReader::installImportedMacro(IdentifierInfo *II, ModuleMacroInfo &MMI,<br>> -                                     Module *Owner) {<br>> -  assert(II && Owner);<br>> -<br>> -  SourceLocation ImportLoc = Owner->MacroVisibilityLoc;<br>> -<br>> -  AmbiguousMacros *Prev =<br>> -      removeOverriddenMacros(II, ImportLoc, MMI.getOverriddenMacros());<br>> -<br>> -  // Create a synthetic macro definition corresponding to the import (or null<br>> -  // if this was an undefinition of the macro).<br>> -  MacroDirective *Imported = MMI.import(PP, ImportLoc);<br>> -  DefMacroDirective *MD = dyn_cast<DefMacroDirective>(Imported);<br>> -<br>> -  // If there's no ambiguity, just install the macro.<br>> -  if (!Prev) {<br>> -    PP.appendMacroDirective(II, Imported);<br>> -    return;<br>> -  }<br>> -  assert(!Prev->empty());<br>> -<br>> -  if (!MD) {<br>> -    // We imported a #undef that didn't remove all prior definitions. The most<br>> -    // recent prior definition remains, and we install it in the place of the<br>> -    // imported directive, as if by a local #pragma pop_macro.<br>> -    MacroInfo *NewMI = Prev->back()->getInfo();<br>> -    Prev->pop_back();<br>> -    MD = PP.AllocateDefMacroDirective(NewMI, ImportLoc);<br>> -<br>> -    // Install our #undef first so that we don't lose track of it. We'll replace<br>> -    // this with whichever macro definition ends up winning.<br>> -    PP.appendMacroDirective(II, Imported);<br>> -  }<br>> -<br>> -  // We're introducing a macro definition that creates or adds to an ambiguity.<br>> -  // We can resolve that ambiguity if this macro is token-for-token identical to<br>> -  // all of the existing definitions.<br>> -  MacroInfo *NewMI = MD->getInfo();<br>> -  assert(NewMI && "macro definition with no MacroInfo?");<br>> -  while (!Prev->empty()) {<br>> -    MacroInfo *PrevMI = Prev->back()->getInfo();<br>> -    assert(PrevMI && "macro definition with no MacroInfo?");<br>> -<br>> -    // Before marking the macros as ambiguous, check if this is a case where<br>> -    // both macros are in system headers. If so, we trust that the system<br>> -    // did not get it wrong. This also handles cases where Clang's own<br>> -    // headers have a different spelling of certain system macros:<br>> -    //   #define LONG_MAX __LONG_MAX__ (clang's limits.h)<br>> -    //   #define LONG_MAX 0x7fffffffffffffffL (system's limits.h)<br>> -    //<br>> -    // FIXME: Remove the defined-in-system-headers check. clang's limits.h<br>> -    // overrides the system limits.h's macros, so there's no conflict here.<br>> -    if (NewMI != PrevMI &&<br>> -        !PrevMI->isIdenticalTo(*NewMI, PP, /*Syntactically=*/true) &&<br>> -        !areDefinedInSystemModules(PrevMI, NewMI, Owner, *this))<br>> -      break;<br>> -<br>> -    // The previous definition is the same as this one (or both are defined in<br>> -    // system modules so we can assume they're equivalent); we don't need to<br>> -    // track it any more.<br>> -    Prev->pop_back();<br>> -  }<br>> -<br>> -  if (!Prev->empty())<br>> -    MD->setAmbiguous(true);<br>> -<br>> -  PP.appendMacroDirective(II, MD);<br>> -}<br>> -<br>> ASTReader::InputFileInfo<br>> ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) {<br>>   // Go find this input file.<br>> @@ -3422,7 +3236,7 @@ void ASTReader::makeNamesVisible(const H<br>>          "nothing to make visible?");<br>><br>>   // FIXME: Only do this if Owner->NameVisibility == AllVisible.<br>> -  for (Decl *D : Names.HiddenDecls) {<br>> +  for (Decl *D : Names) {<br>>     bool wasHidden = D->Hidden;<br>>     D->Hidden = false;<br>><br>> @@ -3432,9 +3246,6 @@ void ASTReader::makeNamesVisible(const H<br>>       }<br>>     }<br>>   }<br>> -<br>> -  for (const auto &Macro : Names.HiddenMacros)<br>> -    installImportedMacro(Macro.first, *Macro.second, Owner);<br>> }<br>><br>> void ASTReader::makeModuleVisible(Module *Mod,<br>><br>> Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)<br>> +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Apr 29 18:20:19 2015<br>> @@ -474,7 +474,7 @@ void ASTDeclReader::VisitDecl(Decl *D) {<br>><br>>           // Note that this declaration was hidden because its owning module is<br>>           // not yet visible.<br>> -          Reader.HiddenNamesMap[Owner].HiddenDecls.push_back(D);<br>> +          Reader.HiddenNamesMap[Owner].push_back(D);<br>>         }<br>>       }<br>>     }<br>> @@ -1402,8 +1402,8 @@ void ASTDeclReader::MergeDefinitionData(<br>>       else {<br>>         auto SubmoduleID = MergeDD.Definition->getOwningModuleID();<br>>         assert(SubmoduleID && "hidden definition in no module");<br>> -        Reader.HiddenNamesMap[Reader.getSubmodule(SubmoduleID)]<br>> -              .HiddenDecls.push_back(DD.Definition);<br>> +        Reader.HiddenNamesMap[Reader.getSubmodule(SubmoduleID)].push_back(<br>> +            DD.Definition);<br>>       }<br>>     }<br>>   }<br>> @@ -3816,7 +3816,7 @@ void ASTDeclReader::UpdateDecl(Decl *D,<br>>       if (Owner && Owner->NameVisibility != Module::AllVisible) {<br>>         // If Owner is made visible at some later point, make this declaration<br>>         // visible too.<br>> -        Reader.HiddenNamesMap[Owner].HiddenDecls.push_back(D);<br>> +        Reader.HiddenNamesMap[Owner].push_back(D);<br>>       } else {<br>>         // The declaration is now visible.<br>>         D->Hidden = false;<br>><br>> Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)<br>> +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Apr 29 18:20:19 2015<br>> @@ -2050,7 +2050,7 @@ void ASTWriter::WritePreprocessor(const<br>>     // If the macro or identifier need no updates, don't write the macro history<br>>     // for this one.<br>>     // FIXME: Chain the macro history instead of re-writing it.<br>> -    if (MD->isFromPCH() &&<br>> +    if (MD && MD->isFromPCH() &&<br>>         Name->isFromAST() && !Name->hasChangedSinceDeserialization())<br>>       continue;<br>><br>><br>> Modified: cfe/trunk/test/Index/complete-macros.c<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-macros.c?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-macros.c?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/test/Index/complete-macros.c (original)<br>> +++ cfe/trunk/test/Index/complete-macros.c Wed Apr 29 18:20:19 2015<br>> @@ -28,7 +28,7 @@ void test_variadic() {<br>> // RUN: c-index-test -code-completion-at=%s:7:1 %s -I%S | FileCheck -check-prefix=CHECK-CC0 %s<br>> // CHECK-CC0-NOT: FOO<br>> // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:1 %s -I%S | FileCheck -check-prefix=CHECK-CC1 %s<br>> -// CHECK-CC1: macro definition:{TypedText FOO}{LeftParen (}{Placeholder Arg1}{Comma , }{Placeholder Arg2}{RightParen )}<br>> +// CHECK-CC1: macro definition:{TypedText FOO} (70)<br>> // RUN: c-index-test -code-completion-at=%s:13:13 %s -I%S | FileCheck -check-prefix=CHECK-CC2 %s<br>> // RUN: c-index-test -code-completion-at=%s:14:8 %s -I%S | FileCheck -check-prefix=CHECK-CC2 %s<br>> // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:14:8 %s -I%S | FileCheck -check-prefix=CHECK-CC2 %s<br>><br>> Modified: cfe/trunk/test/Modules/macros.c<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros.c?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros.c?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/test/Modules/macros.c (original)<br>> +++ cfe/trunk/test/Modules/macros.c Wed Apr 29 18:20:19 2015<br>> @@ -13,6 +13,7 @@<br>> // expected-note@Inputs/macros_right.h:12{{expanding this definition of 'LEFT_RIGHT_DIFFERENT'}}<br>> // expected-note@Inputs/macros_right.h:13{{expanding this definition of 'LEFT_RIGHT_DIFFERENT2'}}<br>> // expected-note@Inputs/macros_left.h:14{{other definition of 'LEFT_RIGHT_DIFFERENT'}}<br>> +// expected-note@Inputs/macros_left.h:11{{other definition of 'LEFT_RIGHT_DIFFERENT2'}}<br>><br>> @import macros;<br>><br>><br>> Modified: cfe/trunk/tools/libclang/CIndex.cpp<br>> URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=236176&r1=236175&r2=236176&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=236176&r1=236175&r2=236176&view=diff</a><br>> ==============================================================================<br>> --- cfe/trunk/tools/libclang/CIndex.cpp (original)<br>> +++ cfe/trunk/tools/libclang/CIndex.cpp Wed Apr 29 18:20:19 2015<br>> @@ -7144,7 +7144,7 @@ MacroInfo *cxindex::getMacroInfo(const I<br>><br>>   ASTUnit *Unit = cxtu::getASTUnit(TU);<br>>   Preprocessor &PP = Unit->getPreprocessor();<br>> -  MacroDirective *MD = PP.getMacroDirectiveHistory(&II);<br>> +  MacroDirective *MD = PP.getLocalMacroDirectiveHistory(&II);<br>>   if (MD) {<br>>     for (MacroDirective::DefInfo<br>>            Def = MD->getDefinition(); Def; Def = Def.getPreviousDefinition()) {<br>> @@ -7201,7 +7201,7 @@ MacroDefinition *cxindex::checkForMacroI<br>>   if (std::find(MI->arg_begin(), MI->arg_end(), &II) != MI->arg_end())<br>>     return nullptr;<br>><br>> -  MacroDirective *InnerMD = PP.getMacroDirectiveHistory(&II);<br>> +  MacroDirective *InnerMD = PP.getLocalMacroDirectiveHistory(&II);<br>>   if (!InnerMD)<br>>     return nullptr;<br>><br>><br>><br>> _______________________________________________<br>> cfe-commits mailing list<br>><span> </span><a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>><span> </span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></div></blockquote></div></div></div></div></blockquote></div><br></div></blockquote></div><br></div>
</div></blockquote></div><br></div></blockquote></div><br></div>