r236369 - [modules] If a module #includes a modular header that #undef's its macro, it
Richard Smith
richard-llvm at metafoo.co.uk
Fri May 1 17:45:56 PDT 2015
Author: rsmith
Date: Fri May 1 19:45:56 2015
New Revision: 236369
URL: http://llvm.org/viewvc/llvm-project?rev=236369&view=rev
Log:
[modules] If a module #includes a modular header that #undef's its macro, it
should not export the macro.
... at least, not unless we have local submodule visibility enabled.
Added:
cfe/trunk/test/Modules/Inputs/macro-masking/
cfe/trunk/test/Modules/Inputs/macro-masking/a.h
cfe/trunk/test/Modules/Inputs/macro-masking/b.h
cfe/trunk/test/Modules/Inputs/macro-masking/module.modulemap
cfe/trunk/test/Modules/macro-masking.cpp
Modified:
cfe/trunk/include/clang/Basic/Module.h
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/Basic/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=236369&r1=236368&r2=236369&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Fri May 1 19:45:56 2015
@@ -205,7 +205,7 @@ public:
/// \brief The set of modules imported by this module, and on which this
/// module depends.
- SmallVector<Module *, 2> Imports;
+ llvm::SmallSetVector<Module *, 2> Imports;
/// \brief Describes an exported module.
///
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=236369&r1=236368&r2=236369&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Fri May 1 19:45:56 2015
@@ -620,8 +620,7 @@ void Preprocessor::EnterSubmodule(Module
// Determine the set of starting macros for this submodule.
// FIXME: If we re-enter a submodule, should we restore its MacroDirectives?
- auto &StartingMacros = (getLangOpts().ModulesLocalVisibility &&
- BuildingSubmoduleStack.size() > 1)
+ auto &StartingMacros = getLangOpts().ModulesLocalVisibility
? BuildingSubmoduleStack[0].Macros
: Info.Macros;
@@ -661,13 +660,13 @@ void Preprocessor::LeaveSubmodule() {
MD = MD->getPrevious()) {
assert(MD && "broken macro directive chain");
- // Skip macros defined in other submodules we #included along the way.
+ // Stop on macros defined in other submodules we #included along the way.
// There's no point doing this if we're tracking local submodule
- // visibiltiy, since there can be no such directives in our list.
+ // visibility, since there can be no such directives in our list.
if (!getLangOpts().ModulesLocalVisibility) {
Module *Mod = getModuleContainingLocation(MD->getLocation());
if (Mod != Info.M)
- continue;
+ break;
}
if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) {
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=236369&r1=236368&r2=236369&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri May 1 19:45:56 2015
@@ -763,9 +763,6 @@ void Preprocessor::LexAfterModuleImport(
}
void Preprocessor::makeModuleVisible(Module *M, SourceLocation Loc) {
- if (VisibleModules.isVisible(M))
- return;
-
VisibleModules.setVisible(
M, Loc, [](Module *) {},
[&](ArrayRef<Module *> Path, Module *Conflict, StringRef Message) {
@@ -779,7 +776,7 @@ void Preprocessor::makeModuleVisible(Mod
// Add this module to the imports list of the currently-built submodule.
if (!BuildingSubmoduleStack.empty())
- BuildingSubmoduleStack.back().M->Imports.push_back(M);
+ BuildingSubmoduleStack.back().M->Imports.insert(M);
}
bool Preprocessor::FinishLexStringLiteral(Token &Result, std::string &String,
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=236369&r1=236368&r2=236369&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri May 1 19:45:56 2015
@@ -3442,7 +3442,7 @@ ASTReader::ASTReadResult ASTReader::Read
case UnresolvedModuleRef::Import:
if (ResolvedMod)
- Unresolved.Mod->Imports.push_back(ResolvedMod);
+ Unresolved.Mod->Imports.insert(ResolvedMod);
continue;
case UnresolvedModuleRef::Export:
Added: cfe/trunk/test/Modules/Inputs/macro-masking/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macro-masking/a.h?rev=236369&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macro-masking/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/macro-masking/a.h Fri May 1 19:45:56 2015
@@ -0,0 +1,2 @@
+#define MACRO
+#include "b.h"
Added: cfe/trunk/test/Modules/Inputs/macro-masking/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macro-masking/b.h?rev=236369&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macro-masking/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/macro-masking/b.h Fri May 1 19:45:56 2015
@@ -0,0 +1 @@
+#undef MACRO
Added: cfe/trunk/test/Modules/Inputs/macro-masking/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macro-masking/module.modulemap?rev=236369&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macro-masking/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/macro-masking/module.modulemap Fri May 1 19:45:56 2015
@@ -0,0 +1,4 @@
+module X {
+ module A { header "a.h" export * }
+ module B { header "b.h" export * }
+}
Added: cfe/trunk/test/Modules/macro-masking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-masking.cpp?rev=236369&view=auto
==============================================================================
--- cfe/trunk/test/Modules/macro-masking.cpp (added)
+++ cfe/trunk/test/Modules/macro-masking.cpp Fri May 1 19:45:56 2015
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fsyntax-only -fmodules %s -fmodules-cache-path=%t -verify -I%S/Inputs/macro-masking
+// RxN: %clang_cc1 -fsyntax-only -fmodules -fmodules-local-submodule-visibility %s -fmodules-cache-path=%t -verify -I%S/Inputs/macro-masking -DLOCAL_VISIBILITY
+// expected-no-diagnostics
+
+#include "a.h"
+
+#ifdef LOCAL_VISIBILITY
+# ifndef MACRO
+# error should still be defined, undef does not override define
+# endif
+#else
+# ifdef MACRO
+# error should have been undefined!
+# endif
+#endif
More information about the cfe-commits
mailing list