<div dir="ltr">Hi Richard,<div><br></div><div>Looks like this broke down ASan bootstrap: <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/3434/steps/check-clang%20asan/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/3434/steps/check-clang%20asan/logs/stdio</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 27, 2015 at 4:21 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Mon Apr 27 18:21:38 2015<br>
New Revision: 235941<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=235941&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=235941&view=rev</a><br>
Log:<br>
[modules] Incrementally compute the list of overridden module macros based on<br>
the active module macros at the point of definition, rather than reconstructing<br>
it from the macro history. No functionality change intended.<br>
<br>
Modified:<br>
  Â  cfe/trunk/include/clang/Lex/Preprocessor.h<br>
  Â  cfe/trunk/lib/Lex/PPDirectives.cpp<br>
  Â  cfe/trunk/lib/Lex/PPLexerChange.cpp<br>
  Â  cfe/trunk/lib/Lex/PPMacroExpansion.cpp<br>
  Â  cfe/trunk/lib/Lex/Preprocessor.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=235941&r1=235940&r2=235941&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=235941&r1=235940&r2=235941&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)<br>
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Mon Apr 27 18:21:38 2015<br>
@@ -364,57 +364,104 @@ class Preprocessor : public RefCountedBa<br>
  Â };<br>
  Â SmallVector<MacroExpandsInfo, 2> DelayedMacroExpandsCallbacks;<br>
<br>
+  /// Information about a name that has been used to define a module macro.<br>
+  struct ModuleMacroInfo {<br>
+  Â  ModuleMacroInfo(MacroDirective *MD)<br>
+  Â  Â  Â  : MD(MD), ActiveModuleMacrosGeneration(0) {}<br>
+<br>
+  Â  /// The most recent macro directive for this identifier.<br>
+  Â  MacroDirective *MD;<br>
+  Â  /// The active module macros for this identifier.<br>
+  Â  llvm::TinyPtrVector<ModuleMacro*> ActiveModuleMacros;<br>
+  Â  /// The generation number at which we last updated ActiveModuleMacros.<br>
+  Â  /// \see Preprocessor::MacroVisibilityGeneration.<br>
+  Â  unsigned ActiveModuleMacrosGeneration;<br>
+  Â  /// Whether this macro name is ambiguous.<br>
+  Â  bool IsAmbiguous;<br>
+  Â  /// The module macros that are overridden by this macro.<br>
+  Â  llvm::TinyPtrVector<ModuleMacro*> OverriddenMacros;<br>
+  };<br>
+<br>
  Â /// The state of a macro for an identifier.<br>
  Â class MacroState {<br>
-  Â  struct ExtInfo {<br>
-  Â  Â  ExtInfo(MacroDirective *MD) : MD(MD) {}<br>
-<br>
-  Â  Â  // The most recent macro directive for this identifier.<br>
-  Â  Â  MacroDirective *MD;<br>
-  Â  Â  // The module macros that are overridden by this macro.<br>
-  Â  Â  SmallVector<ModuleMacro*, 4> OverriddenMacros;<br>
-  Â  };<br>
+  Â  mutable llvm::PointerUnion<MacroDirective *, ModuleMacroInfo *> State;<br>
<br>
-  Â  llvm::PointerUnion<MacroDirective *, ExtInfo *> State;<br>
-<br>
-  Â  ExtInfo &getExtInfo(Preprocessor &PP) {<br>
-  Â  Â  auto *Ext = State.dyn_cast<ExtInfo*>();<br>
-  Â  Â  if (!Ext) {<br>
-  Â  Â  Â  Ext = new (PP.getPreprocessorAllocator())<br>
-  Â  Â  Â  Â  Â  ExtInfo(State.get<MacroDirective *>());<br>
-  Â  Â  Â  State = Ext;<br>
+  Â  ModuleMacroInfo *getModuleInfo(Preprocessor &PP, 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>
+  Â  Â  Â  Â  !PP.MacroVisibilityGeneration)<br>
+  Â  Â  Â  return nullptr;<br>
+<br>
+  Â  Â  auto *Info = State.dyn_cast<ModuleMacroInfo*>();<br>
+  Â  Â  if (!Info) {<br>
+  Â  Â  Â  Info = new (PP.getPreprocessorAllocator())<br>
+  Â  Â  Â  Â  Â  ModuleMacroInfo(State.get<MacroDirective *>());<br>
+  Â  Â  Â  State = Info;<br>
  Â  Â  Â }<br>
-  Â  Â  return *Ext;<br>
+<br>
+  Â  Â  if (PP.MacroVisibilityGeneration != Info->ActiveModuleMacrosGeneration)<br>
+  Â  Â  Â  PP.updateModuleMacroInfo(II, *Info);<br>
+  Â  Â  return Info;<br>
  Â  Â }<br>
<br>
  Â public:<br>
  Â  Â MacroState() : MacroState(nullptr) {}<br>
  Â  Â MacroState(MacroDirective *MD) : State(MD) {}<br>
  Â  Â MacroDirective *getLatest() const {<br>
-  Â  Â  if (auto *Ext = State.dyn_cast<ExtInfo*>())<br>
-  Â  Â  Â  return Ext->MD;<br>
+  Â  Â  if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())<br>
+  Â  Â  Â  return Info->MD;<br>
  Â  Â  Â return State.get<MacroDirective*>();<br>
  Â  Â }<br>
  Â  Â void setLatest(MacroDirective *MD) {<br>
-  Â  Â  if (auto *Ext = State.dyn_cast<ExtInfo*>())<br>
-  Â  Â  Â  Ext->MD = MD;<br>
+  Â  Â  if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())<br>
+  Â  Â  Â  Info->MD = MD;<br>
  Â  Â  Â else<br>
  Â  Â  Â  Â State = MD;<br>
  Â  Â }<br>
<br>
+  Â  bool isAmbiguous(Preprocessor &PP, 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>
+  Â  Â  if (auto *Info = getModuleInfo(PP, II))<br>
+  Â  Â  Â  return Info->ActiveModuleMacros;<br>
+  Â  Â  return None;<br>
+  Â  }<br>
+<br>
  Â  Â MacroDirective::DefInfo findDirectiveAtLoc(SourceLocation Loc,<br>
  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  SourceManager &SourceMgr) const {<br>
+  Â  Â  // FIXME: Incorporate module macros into the result of this.<br>
  Â  Â  Â return getLatest()->findDirectiveAtLoc(Loc, SourceMgr);<br>
  Â  Â }<br>
<br>
-  Â  void addOverriddenMacro(Preprocessor &PP, ModuleMacro *MM) {<br>
-  Â  Â  getExtInfo(PP).OverriddenMacros.push_back(MM);<br>
+  Â  void overrideActiveModuleMacros(Preprocessor &PP, IdentifierInfo *II) {<br>
+  Â  Â  if (auto *Info = getModuleInfo(PP, II)) {<br>
+  Â  Â  Â  for (auto *Active : Info->ActiveModuleMacros)<br>
+  Â  Â  Â  Â  Info->OverriddenMacros.push_back(Active);<br>
+  Â  Â  Â  Info->ActiveModuleMacros.clear();<br>
+  Â  Â  Â  Info->IsAmbiguous = false;<br>
+  Â  Â  }<br>
  Â  Â }<br>
  Â  Â ArrayRef<ModuleMacro*> getOverriddenMacros() const {<br>
-  Â  Â  if (auto *Ext = State.dyn_cast<ExtInfo*>())<br>
-  Â  Â  Â  return Ext->OverriddenMacros;<br>
+  Â  Â  if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())<br>
+  Â  Â  Â  return Info->OverriddenMacros;<br>
  Â  Â  Â return None;<br>
  Â  Â }<br>
+  Â  void setOverriddenMacros(ArrayRef<ModuleMacro*> Overrides) {<br>
+  Â  Â  auto *Info = State.dyn_cast<ModuleMacroInfo*>();<br>
+  Â  Â  if (!Info) {<br>
+  Â  Â  Â  assert(Overrides.empty() &&<br>
+  Â  Â  Â  Â  Â  Â  Â "have overrides but never had module macro");<br>
+  Â  Â  Â  return;<br>
+  Â  Â  }<br>
+  Â  Â  Info->OverriddenMacros.clear();<br>
+  Â  Â  Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),<br>
+  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Overrides.begin(), Overrides.end());<br>
+  Â  Â  Info->ActiveModuleMacrosGeneration = 0;<br>
+  Â  }<br>
  Â };<br>
<br>
  Â typedef llvm::DenseMap<const IdentifierInfo *, MacroState> MacroMap;<br>
@@ -435,8 +482,13 @@ class Preprocessor : public RefCountedBa<br>
  Â  Â Module *M;<br>
  Â  Â /// The location at which the module was included.<br>
  Â  Â SourceLocation ImportLoc;<br>
+<br>
+  Â  struct SavedMacroInfo {<br>
+  Â  Â  MacroDirective *Latest;<br>
+  Â  Â  llvm::TinyPtrVector<ModuleMacro*> Overridden;<br>
+  Â  };<br>
  Â  Â /// The macros that were visible before we entered the module.<br>
-  Â  MacroMap Macros;<br>
+  Â  llvm::DenseMap<const IdentifierInfo*, SavedMacroInfo> Macros;<br>
<br>
  Â  Â // FIXME: VisibleModules?<br>
  Â  Â // FIXME: CounterValue?<br>
@@ -447,6 +499,10 @@ class Preprocessor : public RefCountedBa<br>
  Â void EnterSubmodule(Module *M, SourceLocation ImportLoc);<br>
  Â void LeaveSubmodule();<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>
+<br>
  Â /// The set of known macros exported from modules.<br>
  Â llvm::FoldingSet<ModuleMacro> ModuleMacros;<br>
<br>
@@ -455,6 +511,10 @@ class Preprocessor : public RefCountedBa<br>
  Â llvm::DenseMap<const IdentifierInfo *, llvm::TinyPtrVector<ModuleMacro*>><br>
  Â  Â  Â LeafModuleMacros;<br>
<br>
+  /// The generation number for module macros. Incremented each time the set<br>
+  /// of modules with visible macros changes.<br>
+  unsigned MacroVisibilityGeneration;<br>
+<br>
  Â /// \brief Macros that we want to warn because they are not used at the end<br>
  Â /// of the translation unit.<br>
  Â ///<br>
<br>
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=235941&r1=235940&r2=235941&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=235941&r1=235940&r2=235941&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)<br>
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Apr 27 18:21:38 2015<br>
@@ -1693,6 +1693,7 @@ void Preprocessor::HandleIncludeDirectiv<br>
  Â  Â ModuleLoadResult Imported<br>
  Â  Â  Â = TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility,<br>
  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  /*IsIncludeDirective=*/true);<br>
+  Â  ++MacroVisibilityGeneration;<br>
  Â  Â assert((Imported == nullptr || Imported == SuggestedModule.getModule()) &&<br>
  Â  Â  Â  Â  Â  "the imported module is different than the suggested one");<br>
<br>
<br>
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=235941&r1=235940&r2=235941&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=235941&r1=235940&r2=235941&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)<br>
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Mon Apr 27 18:21:38 2015<br>
@@ -616,7 +616,13 @@ void Preprocessor::EnterSubmodule(Module<br>
  Â auto &Info = BuildingSubmoduleStack.back();<br>
  Â // Copy across our macros and start the submodule with the current state.<br>
  Â // FIXME: We should start each submodule with just the predefined macros.<br>
-  Info.Macros = Macros;<br>
+  for (auto &M : Macros) {<br>
+  Â  BuildingSubmoduleInfo::SavedMacroInfo SMI;<br>
+  Â  SMI.Latest = M.second.getLatest();<br>
+  Â  auto O = M.second.getOverriddenMacros();<br>
+  Â  SMI.Overridden.insert(SMI.Overridden.end(), O.begin(), O.end());<br>
+  Â  Info.Macros.insert(std::make_pair(M.first, SMI));<br>
+  }<br>
 }<br>
<br>
 void Preprocessor::LeaveSubmodule() {<br>
@@ -625,12 +631,12 @@ void Preprocessor::LeaveSubmodule() {<br>
  Â // Create ModuleMacros for any macros defined in this submodule.<br>
  Â for (auto &Macro : Macros) {<br>
  Â  Â auto *II = const_cast<IdentifierInfo*>(Macro.first);<br>
-  Â  MacroState State = Info.Macros.lookup(II);<br>
+  Â  auto SavedInfo = Info.Macros.lookup(II);<br>
<br>
  Â  Â // This module may have exported a new macro. If so, create a ModuleMacro<br>
  Â  Â // representing that fact.<br>
  Â  Â bool ExplicitlyPublic = false;<br>
-  Â  for (auto *MD = Macro.second.getLatest(); MD != State.getLatest();<br>
+  Â  for (auto *MD = Macro.second.getLatest(); MD != SavedInfo.Latest;<br>
  Â  Â  Â  Â  MD = MD->getPrevious()) {<br>
  Â  Â  Â // Skip macros defined in other submodules we #included along the way.<br>
  Â  Â  Â Module *Mod = getModuleContainingLocation(MD->getLocation());<br>
@@ -659,11 +665,15 @@ void Preprocessor::LeaveSubmodule() {<br>
  Â  Â  Â }<br>
  Â  Â }<br>
<br>
-  Â  // Update the macro to refer to the latest directive in the chain.<br>
-  Â  State.setLatest(Macro.second.getLatest());<br>
+  Â  // Restore the macro's overrides list.<br>
+  Â  Macro.second.setOverriddenMacros(SavedInfo.Overridden);<br>
+  }<br>
<br>
-  Â  // Restore the old macro state.<br>
-  Â  Macro.second = State;<br>
+  if (Info.M->NameVisibility < Module::MacrosVisible) {<br>
+  Â  Info.M->NameVisibility = Module::MacrosVisible;<br>
+  Â  Info.M->MacroVisibilityLoc = Info.ImportLoc;<br>
+  Â  ++MacroVisibilityGeneration;<br>
+  Â  // FIXME: Also mark any exported macros as visible, and check for conflicts.<br>
  Â }<br>
<br>
  Â BuildingSubmoduleStack.pop_back();<br>
<br>
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=235941&r1=235940&r2=235941&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=235941&r1=235940&r2=235941&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)<br>
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Mon Apr 27 18:21:38 2015<br>
@@ -50,6 +50,7 @@ void Preprocessor::appendMacroDirective(<br>
  Â auto *OldMD = StoredMD.getLatest();<br>
  Â MD->setPrevious(OldMD);<br>
  Â StoredMD.setLatest(MD);<br>
+  StoredMD.overrideActiveModuleMacros(*this, II);<br>
<br>
  Â // Set up the identifier as having associated macro history.<br>
  Â II->setHasMacroDefinition(true);<br>
@@ -57,43 +58,6 @@ void Preprocessor::appendMacroDirective(<br>
  Â  Â II->setHasMacroDefinition(false);<br>
  Â if (II->isFromAST() && !MD->isImported())<br>
  Â  Â II->setChangedSinceDeserialization();<br>
-<br>
-  // Accumulate any overridden imported macros.<br>
-  if (!MD->isImported() && getCurrentModule()) {<br>
-  Â  Module *OwningMod = getModuleContainingLocation(MD->getLocation());<br>
-  Â  if (!OwningMod)<br>
-  Â  Â  return;<br>
-<br>
-  Â  for (auto *PrevMD = OldMD; PrevMD; PrevMD = PrevMD->getPrevious()) {<br>
-  Â  Â  Module *DirectiveMod = getModuleContainingLocation(PrevMD->getLocation());<br>
-  Â  Â  if (ModuleMacro *PrevMM = PrevMD->getOwningModuleMacro())<br>
-  Â  Â  Â  StoredMD.addOverriddenMacro(*this, PrevMM);<br>
-  Â  Â  else if (ModuleMacro *PrevMM = getModuleMacro(DirectiveMod, II))<br>
-  Â  Â  Â  // The previous macro was from another submodule that we #included.<br>
-  Â  Â  Â  // FIXME: Create an import directive when importing a macro from a local<br>
-  Â  Â  Â  // submodule.<br>
-  Â  Â  Â  StoredMD.addOverriddenMacro(*this, PrevMM);<br>
-  Â  Â  else<br>
-  Â  Â  Â  // We're still within the module defining the previous macro. We don't<br>
-  Â  Â  Â  // override it.<br>
-  Â  Â  Â  break;<br>
-<br>
-  Â  Â  // Stop once we leave the original macro's submodule.<br>
-  Â  Â  //<br>
-  Â  Â  // Either this submodule #included another submodule of the same<br>
-  Â  Â  // module or it just happened to be built after the other module.<br>
-  Â  Â  // In the former case, we override the submodule's macro.<br>
-  Â  Â  //<br>
-  Â  Â  // FIXME: In the latter case, we shouldn't do so, but we can't tell<br>
-  Â  Â  // these cases apart.<br>
-  Â  Â  //<br>
-  Â  Â  // FIXME: We can leave this submodule and re-enter it if it #includes a<br>
-  Â  Â  // header within a different submodule of the same module. In such cases<br>
-  Â  Â  // the overrides list will be incomplete.<br>
-  Â  Â  if (DirectiveMod != OwningMod || !PrevMD->isImported())<br>
-  Â  Â  Â  break;<br>
-  Â  }<br>
-  }<br>
 }<br>
<br>
 void Preprocessor::setLoadedMacroDirective(IdentifierInfo *II,<br>
@@ -157,6 +121,71 @@ ModuleMacro *Preprocessor::getModuleMacr<br>
  Â return ModuleMacros.FindNodeOrInsertPos(ID, InsertPos);<br>
 }<br>
<br>
+void Preprocessor::updateModuleMacroInfo(IdentifierInfo *II,<br>
+  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â ModuleMacroInfo &Info) {<br>
+  assert(Info.ActiveModuleMacrosGeneration != MacroVisibilityGeneration &&<br>
+  Â  Â  Â  Â "don't need to update this macro name info");<br>
+  Info.ActiveModuleMacrosGeneration = MacroVisibilityGeneration;<br>
+<br>
+  auto Leaf = LeafModuleMacros.find(II);<br>
+  if (Leaf == LeafModuleMacros.end()) {<br>
+  Â  // No imported macros at all: nothing to do.<br>
+  Â  return;<br>
+  }<br>
+<br>
+  Info.ActiveModuleMacros.clear();<br>
+<br>
+  // Every macro that's locally overridden is overridden by a visible macro.<br>
+  llvm::DenseMap<ModuleMacro *, int> NumHiddenOverrides;<br>
+  for (auto *O : Info.OverriddenMacros)<br>
+  Â  NumHiddenOverrides[O] = -1;<br>
+<br>
+  // Collect all macros that are not overridden by a visible macro.<br>
+  llvm::SmallVector<ModuleMacro *, 16> Worklist(Leaf->second.begin(),<br>
+  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Leaf->second.end());<br>
+  while (!Worklist.empty()) {<br>
+  Â  auto *MM = Worklist.pop_back_val();<br>
+  Â  if (MM->getOwningModule()->NameVisibility >= Module::MacrosVisible) {<br>
+  Â  Â  // We only care about collecting definitions; undefinitions only act<br>
+  Â  Â  // to override other definitions.<br>
+  Â  Â  if (MM->getMacroInfo())<br>
+  Â  Â  Â  Info.ActiveModuleMacros.push_back(MM);<br>
+  Â  } else {<br>
+  Â  Â  for (auto *O : MM->overrides())<br>
+  Â  Â  Â  if ((unsigned)++NumHiddenOverrides[O] == O->getNumOverridingMacros())<br>
+  Â  Â  Â  Â  Worklist.push_back(O);<br>
+  Â  }<br>
+  }<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>
+  }<br>
+  for (auto *Active : Info.ActiveModuleMacros) {<br>
+  Â  auto *NewMI = Active->getMacroInfo();<br>
+<br>
+  Â  // Before marking the macro 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>
+  Â  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>
+  }<br>
+}<br>
+<br>
 /// RegisterBuiltinMacro - Register the specified identifier in the identifier<br>
 /// table and mark it as a builtin macro to be expanded.<br>
 static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char *Name){<br>
<br>
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=235941&r1=235940&r2=235941&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=235941&r1=235940&r2=235941&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)<br>
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Apr 27 18:21:38 2015<br>
@@ -73,7 +73,8 @@ 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), MacroArgCache(nullptr), Record(nullptr),<br>
+  Â  Â  Callbacks(nullptr), MacroVisibilityGeneration(0),<br>
+  Â  Â  MacroArgCache(nullptr), Record(nullptr),<br>
  Â  Â  Â MIChainHead(nullptr), DeserialMIChainHead(nullptr) {<br>
  Â OwnsHeaderSearch = OwnsHeaders;<br>
<br>
@@ -748,11 +749,13 @@ void Preprocessor::LexAfterModuleImport(<br>
  Â // If we have a non-empty module path, load the named module.<br>
  Â if (!ModuleImportPath.empty()) {<br>
  Â  Â Module *Imported = nullptr;<br>
-  Â  if (getLangOpts().Modules)<br>
+  Â  if (getLangOpts().Modules) {<br>
  Â  Â  Â Imported = TheModuleLoader.loadModule(ModuleImportLoc,<br>
  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â ModuleImportPath,<br>
  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Module::MacrosVisible,<br>
  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â /*IsIncludeDirective=*/false);<br>
+  Â  Â  ++MacroVisibilityGeneration;<br>
+  Â  }<br>
  Â  Â if (Callbacks && (getLangOpts().Modules || getLangOpts().DebuggerSupport))<br>
  Â  Â  Â Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported);<br>
  Â }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</div>