<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, May 4, 2015 at 12:34 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Mon, May 4, 2015 at 12:31 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Mon, May 4, 2015 at 12:28 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Fri, May 1, 2015 at 2:22 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: Fri May 1 16:22:17 2015<br>
New Revision: 236350<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=236350&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=236350&view=rev</a><br>
Log:<br>
[modules] Add -fmodules-local-submodule-visibility flag.<br>
<br>
This flag specifies that the normal visibility rules should be used even for<br>
local submodules (submodules of the currently-being-built module). Thus names<br>
will only be visible if a header / module that declares them has actually been<br>
included / imported, and not merely because a submodule that happened to be<br>
built earlier declared those names. This also removes the need to modularize<br>
bottom-up:</blockquote><div><br></div></span><div>Nice!</div><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> textually-included headers will be included into every submodule<br>
that includes them, since their include guards will not leak between modules.<br></blockquote><div><br></div></span><div>So is the idea that all of the textually included declarations of in each submodule will be merged so that they don't cause issues?</div></div></div></div></blockquote><div><br></div></span><div>Yes. We already do that in the case where we have an imported-but-not-visible declaration and we parse another (this happens if a textually-included header is included into both a module and a user of that module).</div></div></div></div></blockquote><div><br></div></span><div>Ah... This has changed since last Fall, right?</div></div></div></div></blockquote><div><br></div><div>Yes, that's a fairly recent change.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>This explains why I was unable to reproduce some sorts of issues that I was running into when initially experimenting with modules for PS4.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- Sean Silva</div></font></span><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><font color="#888888"><div>-- Sean Silva</div></font></span><div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
So far, this only governs visibility of macros, not of declarations, so is not<br>
ready for real use yet.<br>
<br>
Modified:<br>
cfe/trunk/include/clang/Basic/LangOptions.def<br>
cfe/trunk/include/clang/Basic/Module.h<br>
cfe/trunk/include/clang/Driver/CC1Options.td<br>
cfe/trunk/include/clang/Lex/Preprocessor.h<br>
cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
cfe/trunk/lib/Lex/PPLexerChange.cpp<br>
cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
cfe/trunk/test/Modules/macro-ambiguity.cpp<br>
cfe/trunk/test/Modules/macro-reexport.cpp<br>
cfe/trunk/test/Modules/macros.c<br>
cfe/trunk/test/Modules/macros2.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/LangOptions.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)<br>
+++ cfe/trunk/include/clang/Basic/LangOptions.def Fri May 1 16:22:17 2015<br>
@@ -130,6 +130,7 @@ COMPATIBLE_LANGOPT(ModulesStrictDeclUse,<br>
LANGOPT(ModulesErrorRecovery, 1, 1, "automatically import modules as needed when performing error recovery")<br>
BENIGN_LANGOPT(ModulesImplicitMaps, 1, 1, "use files called module.modulemap implicitly as module maps")<br>
BENIGN_LANGOPT(ImplicitModules, 1, 1, "build modules that are not specified via -fmodule-file")<br>
+COMPATIBLE_LANGOPT(ModulesLocalVisibility, 1, 0, "local submodule visibility")<br>
COMPATIBLE_LANGOPT(Optimize , 1, 0, "__OPTIMIZE__ predefined macro")<br>
COMPATIBLE_LANGOPT(OptimizeSize , 1, 0, "__OPTIMIZE_SIZE__ predefined macro")<br>
LANGOPT(Static , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)")<br>
<br>
Modified: cfe/trunk/include/clang/Basic/Module.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/Module.h (original)<br>
+++ cfe/trunk/include/clang/Basic/Module.h Fri May 1 16:22:17 2015<br>
@@ -480,14 +480,24 @@ private:<br>
class VisibleModuleSet {<br>
public:<br>
VisibleModuleSet() : Generation(0) {}<br>
+ VisibleModuleSet(VisibleModuleSet &&O)<br>
+ : ImportLocs(std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {<br>
+ O.ImportLocs.clear();<br>
+ ++O.Generation;<br>
+ }<br>
<br>
+ /// Move from another visible modules set. Guaranteed to leave the source<br>
+ /// empty and bump the generation on both.<br>
VisibleModuleSet &operator=(VisibleModuleSet &&O) {<br>
ImportLocs = std::move(O.ImportLocs);<br>
+ O.ImportLocs.clear();<br>
+ ++O.Generation;<br>
++Generation;<br>
return *this;<br>
}<br>
<br>
- /// \brief Get the current visibility generation.<br>
+ /// \brief Get the current visibility generation. Incremented each time the<br>
+ /// set of visible modules changes in any way.<br>
unsigned getGeneration() const { return Generation; }<br>
<br>
/// \brief Determine whether a module is visible.<br>
<br>
Modified: cfe/trunk/include/clang/Driver/CC1Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)<br>
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri May 1 16:22:17 2015<br>
@@ -347,6 +347,10 @@ def fmodule_map_file_home_is_cwd : Flag<<br>
def fmodule_feature : Separate<["-"], "fmodule-feature">,<br>
MetaVarName<"<feature>">,<br>
HelpText<"Enable <feature> in module map requires declarations">;<br>
+def fmodules_local_submodule_visibility :<br>
+ Flag<["-"], "fmodules-local-submodule-visibility">,<br>
+ HelpText<"Enforce name visibility rules across submodules of the same "<br>
+ "top-level module.">;<br>
<br>
let Group = Action_Group in {<br>
<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=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)<br>
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri May 1 16:22:17 2015<br>
@@ -466,12 +466,15 @@ class Preprocessor : public RefCountedBa<br>
return Info->OverriddenMacros;<br>
return None;<br>
}<br>
- void setOverriddenMacros(ArrayRef<ModuleMacro*> Overrides) {<br>
+ void setOverriddenMacros(Preprocessor &PP,<br>
+ 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>
+ if (Overrides.empty())<br>
+ return;<br>
+ Info = new (PP.getPreprocessorAllocator())<br>
+ ModuleMacroInfo(State.get<MacroDirective *>());<br>
+ State = Info;<br>
}<br>
Info->OverriddenMacros.clear();<br>
Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),<br>
@@ -498,16 +501,11 @@ class Preprocessor : public RefCountedBa<br>
Module *M;<br>
/// The location at which the module was included.<br>
SourceLocation ImportLoc;<br>
-<br>
- struct SavedMacroInfo {<br>
- SavedMacroInfo() : Latest(nullptr) {}<br>
- MacroDirective *Latest;<br>
- llvm::TinyPtrVector<ModuleMacro*> Overridden;<br>
- };<br>
/// The macros that were visible before we entered the module.<br>
- llvm::DenseMap<const IdentifierInfo*, SavedMacroInfo> Macros;<br>
+ MacroMap Macros;<br>
+ /// The set of modules that was visible in the surrounding submodule.<br>
+ VisibleModuleSet VisibleModules;<br>
<br>
- // FIXME: VisibleModules?<br>
// FIXME: CounterValue?<br>
// FIXME: PragmaPushMacroInfo?<br>
};<br>
@@ -662,6 +660,7 @@ public:<br>
HeaderSearch &getHeaderSearchInfo() const { return HeaderInfo; }<br>
<br>
IdentifierTable &getIdentifierTable() { return Identifiers; }<br>
+ const IdentifierTable &getIdentifierTable() const { return Identifiers; }<br>
SelectorTable &getSelectorTable() { return Selectors; }<br>
Builtin::Context &getBuiltinInfo() { return BuiltinInfo; }<br>
llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; }<br>
<br>
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri May 1 16:22:17 2015<br>
@@ -1508,6 +1508,8 @@ static void ParseLangArgs(LangOptions &O<br>
Opts.ModulesStrictDeclUse = Args.hasArg(OPT_fmodules_strict_decluse);<br>
Opts.ModulesDeclUse =<br>
Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse;<br>
+ Opts.ModulesLocalVisibility =<br>
+ Args.hasArg(OPT_fmodules_local_submodule_visibility);<br>
Opts.ModulesSearchAll = Opts.Modules &&<br>
!Args.hasArg(OPT_fno_modules_search_all) &&<br>
Args.hasArg(OPT_fmodules_search_all);<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=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)<br>
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Fri May 1 16:22:17 2015<br>
@@ -612,16 +612,25 @@ void Preprocessor::HandleMicrosoftCommen<br>
void Preprocessor::EnterSubmodule(Module *M, SourceLocation ImportLoc) {<br>
// Save the current state for future imports.<br>
BuildingSubmoduleStack.push_back(BuildingSubmoduleInfo(M, ImportLoc));<br>
-<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>
- 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>
+ Info.Macros.swap(Macros);<br>
+ // Save our visible modules set. This is guaranteed to clear the set.<br>
+ if (getLangOpts().ModulesLocalVisibility)<br>
+ Info.VisibleModules = std::move(VisibleModules);<br>
+<br>
+ // Determine the set of starting macros for this submodule.<br>
+ // FIXME: If we re-enter a submodule, should we restore its MacroDirectives?<br>
+ auto &StartingMacros = (getLangOpts().ModulesLocalVisibility &&<br>
+ BuildingSubmoduleStack.size() > 1)<br>
+ ? BuildingSubmoduleStack[0].Macros<br>
+ : Info.Macros;<br>
+<br>
+ // Restore to the starting state.<br>
+ // FIXME: Do this lazily, when each macro name is first referenced.<br>
+ for (auto &Macro : StartingMacros) {<br>
+ MacroState MS(Macro.second.getLatest());<br>
+ MS.setOverriddenMacros(*this, MS.getOverriddenMacros());<br>
+ Macros.insert(std::make_pair(Macro.first, std::move(MS)));<br>
}<br>
}<br>
<br>
@@ -631,19 +640,35 @@ 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>
- auto SavedInfo = Info.Macros.lookup(II);<br>
+ auto &OuterInfo = Info.Macros[II];<br>
+<br>
+ // Find the starting point for the MacroDirective chain in this submodule.<br>
+ auto *OldMD = OuterInfo.getLatest();<br>
+ if (getLangOpts().ModulesLocalVisibility &&<br>
+ BuildingSubmoduleStack.size() > 1) {<br>
+ auto &PredefMacros = BuildingSubmoduleStack[0].Macros;<br>
+ auto PredefMacroIt = PredefMacros.find(Macro.first);<br>
+ if (PredefMacroIt == PredefMacros.end())<br>
+ OldMD = nullptr;<br>
+ else<br>
+ OldMD = PredefMacroIt->second.getLatest();<br>
+ }<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 != SavedInfo.Latest;<br>
+ for (auto *MD = Macro.second.getLatest(); MD != OldMD;<br>
MD = MD->getPrevious()) {<br>
assert(MD && "broken macro directive chain");<br>
<br>
// Skip macros defined in other submodules we #included along the way.<br>
- Module *Mod = getModuleContainingLocation(MD->getLocation());<br>
- if (Mod != Info.M)<br>
- continue;<br>
+ // There's no point doing this if we're tracking local submodule<br>
+ // visibiltiy, since there can be no such directives in our list.<br>
+ if (!getLangOpts().ModulesLocalVisibility) {<br>
+ Module *Mod = getModuleContainingLocation(MD->getLocation());<br>
+ if (Mod != Info.M)<br>
+ continue;<br>
+ }<br>
<br>
if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) {<br>
// The latest visibility directive for a name in a submodule affects<br>
@@ -667,11 +692,21 @@ void Preprocessor::LeaveSubmodule() {<br>
}<br>
}<br>
<br>
- // Restore the macro's overrides list.<br>
- Macro.second.setOverriddenMacros(SavedInfo.Overridden);<br>
+ // Maintain a single macro directive chain if we're not tracking<br>
+ // per-submodule macro visibility.<br>
+ if (!getLangOpts().ModulesLocalVisibility)<br>
+ OuterInfo.setLatest(Macro.second.getLatest());<br>
}<br>
<br>
- makeModuleVisible(Info.M, Info.ImportLoc);<br>
+ // Put back the old macros.<br>
+ std::swap(Info.Macros, Macros);<br>
+<br>
+ if (getLangOpts().ModulesLocalVisibility)<br>
+ VisibleModules = std::move(Info.VisibleModules);<br>
+<br>
+ // A nested #include makes the included submodule visible.<br>
+ if (BuildingSubmoduleStack.size() > 1)<br>
+ makeModuleVisible(Info.M, Info.ImportLoc);<br>
<br>
BuildingSubmoduleStack.pop_back();<br>
}<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri May 1 16:22:17 2015<br>
@@ -2019,37 +2019,23 @@ void ASTWriter::WritePreprocessor(const<br>
// Loop over all the macro directives that are live at the end of the file,<br>
// emitting each to the PP section.<br>
<br>
- // Construct the list of macro directives that need to be serialized.<br>
- typedef std::pair<const IdentifierInfo *, MacroDirective *> MacroChain;<br>
- SmallVector<MacroChain, 2> MacroDirectives;<br>
- for (Preprocessor::macro_iterator<br>
- I = PP.macro_begin(/*IncludeExternalMacros=*/false),<br>
- E = PP.macro_end(/*IncludeExternalMacros=*/false);<br>
- I != E; ++I) {<br>
- MacroDirectives.push_back(std::make_pair(I->first, I->second.getLatest()));<br>
- }<br>
-<br>
+ // Construct the list of identifiers with macro directives that need to be<br>
+ // serialized.<br>
+ SmallVector<const IdentifierInfo *, 128> MacroIdentifiers;<br>
+ for (auto &Id : PP.getIdentifierTable())<br>
+ if (Id.second->hadMacroDefinition() &&<br>
+ (!Id.second->isFromAST() ||<br>
+ Id.second->hasChangedSinceDeserialization()))<br>
+ MacroIdentifiers.push_back(Id.second);<br>
// Sort the set of macro definitions that need to be serialized by the<br>
// name of the macro, to provide a stable ordering.<br>
- int (*Cmp)(const MacroChain*, const MacroChain*) =<br>
- [](const MacroChain *A, const MacroChain *B) -> int {<br>
- return A->first->getName().compare(B->first->getName());<br>
- };<br>
- llvm::array_pod_sort(MacroDirectives.begin(), MacroDirectives.end(), Cmp);<br>
+ std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(),<br>
+ llvm::less_ptr<IdentifierInfo>());<br>
<br>
// Emit the macro directives as a list and associate the offset with the<br>
// identifier they belong to.<br>
- for (auto &Chain : MacroDirectives) {<br>
- const IdentifierInfo *Name = Chain.first;<br>
- MacroDirective *MD = Chain.second;<br>
-<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 && MD->isFromPCH() &&<br>
- Name->isFromAST() && !Name->hasChangedSinceDeserialization())<br>
- continue;<br>
-<br>
+ for (const IdentifierInfo *Name : MacroIdentifiers) {<br>
+ MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name);<br>
auto StartOffset = Stream.GetCurrentBitNo();<br>
<br>
// Emit the macro directives in reverse source order.<br>
@@ -2069,6 +2055,7 @@ void ASTWriter::WritePreprocessor(const<br>
}<br>
<br>
// Write out any exported module macros.<br>
+ bool EmittedModuleMacros = false;<br>
if (IsModule) {<br>
auto Leafs = PP.getLeafModuleMacros(Name);<br>
SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end());<br>
@@ -2079,7 +2066,7 @@ void ASTWriter::WritePreprocessor(const<br>
// Emit a record indicating this submodule exports this macro.<br>
ModuleMacroRecord.push_back(<br>
getSubmoduleID(Macro->getOwningModule()));<br>
- ModuleMacroRecord.push_back(getMacroID(Macro->getMacroInfo()));<br>
+ ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name));<br>
for (auto *M : Macro->overrides())<br>
ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule()));<br>
<br>
@@ -2090,10 +2077,12 @@ void ASTWriter::WritePreprocessor(const<br>
for (auto *M : Macro->overrides())<br>
if (++Visits[M] == M->getNumOverridingMacros())<br>
Worklist.push_back(M);<br>
+<br>
+ EmittedModuleMacros = true;<br>
}<br>
}<br>
<br>
- if (Record.empty())<br>
+ if (Record.empty() && !EmittedModuleMacros)<br>
continue;<br>
<br>
IdentMacroDirectivesOffsetMap[Name] = StartOffset;<br>
<br>
Modified: cfe/trunk/test/Modules/macro-ambiguity.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-ambiguity.cpp?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-ambiguity.cpp?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/macro-ambiguity.cpp (original)<br>
+++ cfe/trunk/test/Modules/macro-ambiguity.cpp Fri May 1 16:22:17 2015<br>
@@ -57,6 +57,27 @@<br>
// RUN: -fmodule-file=%t/c.pcm \<br>
// RUN: -fmodule-file=%t/d.pcm \<br>
// RUN: -Wambiguous-macro -verify macro-ambiguity.cpp<br>
+//<br>
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \<br>
+// RUN: -v -fmodules-local-submodule-visibility \<br>
+// RUN: -iquote Inputs/macro-ambiguity/a/quote \<br>
+// RUN: -isystem Inputs/macro-ambiguity/a/system \<br>
+// RUN: -iquote Inputs/macro-ambiguity/b/quote \<br>
+// RUN: -isystem Inputs/macro-ambiguity/b/system \<br>
+// RUN: -iquote Inputs/macro-ambiguity/c/quote \<br>
+// RUN: -isystem Inputs/macro-ambiguity/c/system \<br>
+// RUN: -iquote Inputs/macro-ambiguity/d/quote \<br>
+// RUN: -isystem Inputs/macro-ambiguity/d/system \<br>
+// RUN: -iquote Inputs/macro-ambiguity/e/quote \<br>
+// RUN: -isystem Inputs/macro-ambiguity/e/system \<br>
+// RUN: -fno-implicit-modules -fno-modules-implicit-maps \<br>
+// RUN: -fmodule-map-file-home-is-cwd \<br>
+// RUN: -fmodule-map-file=Inputs/macro-ambiguity/module.modulemap \<br>
+// RUN: -fmodule-file=%t/a.pcm \<br>
+// RUN: -fmodule-file=%t/b.pcm \<br>
+// RUN: -fmodule-file=%t/c.pcm \<br>
+// RUN: -fmodule-file=%t/d.pcm \<br>
+// RUN: -Wambiguous-macro -verify macro-ambiguity.cpp<br>
<br>
// Include the textual headers first to maximize the ways in which things can<br>
// become ambiguous.<br>
<br>
Modified: cfe/trunk/test/Modules/macro-reexport.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport.cpp?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport.cpp?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/macro-reexport.cpp (original)<br>
+++ cfe/trunk/test/Modules/macro-reexport.cpp Fri May 1 16:22:17 2015<br>
@@ -7,6 +7,15 @@<br>
// RUN: %clang_cc1 -fsyntax-only -DD2 -I%S/Inputs/macro-reexport -fmodules %s -fmodules-cache-path=%t -verify<br>
// RUN: %clang_cc1 -fsyntax-only -DF1 -I%S/Inputs/macro-reexport %s -fmodules-cache-path=%t -verify<br>
// RUN: %clang_cc1 -fsyntax-only -DF1 -I%S/Inputs/macro-reexport -fmodules %s -fmodules-cache-path=%t -verify<br>
+//<br>
+// RUN: %clang_cc1 -fmodules-local-submodule-visibility -fsyntax-only -DC1 -I%S/Inputs/macro-reexport %s -fmodules-cache-path=%t -verify<br>
+// RUN: %clang_cc1 -fmodules-local-submodule-visibility -fsyntax-only -DC1 -I%S/Inputs/macro-reexport -fmodules %s -fmodules-cache-path=%t -verify<br>
+// RUN: %clang_cc1 -fmodules-local-submodule-visibility -fsyntax-only -DD1 -I%S/Inputs/macro-reexport %s -fmodules-cache-path=%t -verify<br>
+// RUN: %clang_cc1 -fmodules-local-submodule-visibility -fsyntax-only -DD1 -I%S/Inputs/macro-reexport -fmodules %s -fmodules-cache-path=%t -verify<br>
+// RUN: %clang_cc1 -fmodules-local-submodule-visibility -fsyntax-only -DD2 -I%S/Inputs/macro-reexport %s -fmodules-cache-path=%t -verify<br>
+// RUN: %clang_cc1 -fmodules-local-submodule-visibility -fsyntax-only -DD2 -I%S/Inputs/macro-reexport -fmodules %s -fmodules-cache-path=%t -verify<br>
+// RUN: %clang_cc1 -fmodules-local-submodule-visibility -fsyntax-only -DF1 -I%S/Inputs/macro-reexport %s -fmodules-cache-path=%t -verify<br>
+// RUN: %clang_cc1 -fmodules-local-submodule-visibility -fsyntax-only -DF1 -I%S/Inputs/macro-reexport -fmodules %s -fmodules-cache-path=%t -verify<br>
<br>
#if defined(F1)<br>
#include "f1.h"<br>
<br>
Modified: cfe/trunk/test/Modules/macros.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros.c?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros.c?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/macros.c (original)<br>
+++ cfe/trunk/test/Modules/macros.c Fri May 1 16:22:17 2015<br>
@@ -1,9 +1,6 @@<br>
// RUN: rm -rf %t<br>
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_top %S/Inputs/module.map<br>
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_left %S/Inputs/module.map<br>
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_right %S/Inputs/module.map<br>
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros %S/Inputs/module.map<br>
// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s<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>
// These notes come from headers in modules, and are bogus.<br>
@@ -143,11 +140,20 @@ TOP_DEF_RIGHT_UNDEF *TDRUf() { return TD<br>
<br>
int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined<br>
<br>
-// FIXME: When macros_right.undef is built, macros_top is visible because<br>
-// the state from building macros_right leaks through, so macros_right.undef<br>
-// undefines macros_top's macro.<br>
-#ifdef TOP_RIGHT_UNDEF<br>
-# error TOP_RIGHT_UNDEF should not be defined<br>
+#ifdef LOCAL_VISIBILITY<br>
+// TOP_RIGHT_UNDEF should not be undefined, because macros_right.undef does<br>
+// not undefine macros_right's macro.<br>
+# ifndef TOP_RIGHT_UNDEF<br>
+# error TOP_RIGHT_UNDEF should still be defined<br>
+# endif<br>
+#else<br>
+// When macros_right.undef is built and local submodule visibility is not<br>
+// enabled, macros_top is visible because the state from building<br>
+// macros_right leaks through, so macros_right.undef undefines macros_top's<br>
+// macro.<br>
+# ifdef TOP_RIGHT_UNDEF<br>
+# error TOP_RIGHT_UNDEF should not be defined<br>
+# endif<br>
#endif<br>
<br>
@import macros_other;<br>
<br>
Modified: cfe/trunk/test/Modules/macros2.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros2.c?rev=236350&r1=236349&r2=236350&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros2.c?rev=236350&r1=236349&r2=236350&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/macros2.c (original)<br>
+++ cfe/trunk/test/Modules/macros2.c Fri May 1 16:22:17 2015<br>
@@ -1,9 +1,6 @@<br>
// RUN: rm -rf %t<br>
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_top %S/Inputs/module.map<br>
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_left %S/Inputs/module.map<br>
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_right %S/Inputs/module.map<br>
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros %S/Inputs/module.map<br>
// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s<br>
+// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s -DLOCAL_VISIBILITY<br>
<br>
// This test checks some of the same things as macros.c, but imports modules in<br>
// a different order.<br>
@@ -49,9 +46,15 @@ void test() {<br>
<br>
@import macros_right.undef;<br>
<br>
-// FIXME: See macros.c.<br>
-#ifdef TOP_RIGHT_UNDEF<br>
-# error TOP_RIGHT_UNDEF should not be defined<br>
+// See macros.c.<br>
+#ifdef LOCAL_VISIBILITY<br>
+# ifndef TOP_RIGHT_UNDEF<br>
+# error TOP_RIGHT_UNDEF should still be defined<br>
+# endif<br>
+#else<br>
+# ifdef TOP_RIGHT_UNDEF<br>
+# error TOP_RIGHT_UNDEF should not be defined<br>
+# endif<br>
#endif<br>
<br>
#ifndef TOP_OTHER_UNDEF1<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">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></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>