[PATCH] Module use declarations

Lawrence Crowl crowl at google.com
Fri Jun 28 14:32:44 PDT 2013


Hi doug.gregor,

This patch adds a check that ensures that modules only use modules they have so declared.

USER INTERFACE

Add a statement on intended module use to the module.map grammar. This statement is modeled on the existing export statement.

    use wildcard-module-id

This enforcement is off by default, but may be turned on with the new option -fmodules-decluse.

When enforcing the module semantics, we also need to consider a source file part of a module. This is achieved with a compiler option -fmodule-source-for=<module-id>.

The compiler at present only applies restrictions to the module directly being built. To add indirect checks, use the option -fmodules-indirect-check. This indirect flag is also applied to private header use.

IMPLEMENTATION

The module checking is done from within Preprocessor::LookupFile, and the code there has been refactored. The preprocessor now has two routines for determining the relationship between modules at an include/import, getModuleOfIncluder and getModuleOfIncludee.

The -fmodule-source-for=<module-id> value is stored in ModuleMap::SourceModule. However, because module compilations inherit object file command lines, use Preprocessor::getSourceModule() to obtain the current source module.

The type ExportDecl in Module has been generalized to WildModuleRef, likewise UnresolvedExportDecl to UnresolvedWildModuleRef. There has been refactoring to avoid duplicate code in using these types.

MISSING

This patch is missing serialization of 'use' declarations, for which I need some feedback. See the FIXME comments.

The error messages from module compilations are supressed, which makes diagnosing issues tough.


http://llvm-reviews.chandlerc.com/D1063

Files:
  test/Modules/declare-use1.cpp
  test/Modules/declare-use2.cpp
  test/Modules/Inputs/declare-use/a.h
  test/Modules/Inputs/declare-use/b.h
  test/Modules/Inputs/declare-use/c.h
  test/Modules/Inputs/declare-use/d.h
  test/Modules/Inputs/declare-use/e.h
  test/Modules/Inputs/declare-use/f.h
  test/Modules/Inputs/declare-use/g.h
  test/Modules/Inputs/declare-use/h.h
  test/Modules/Inputs/declare-use/g1.h
  test/Modules/Inputs/declare-use/h1.h
  test/Modules/Inputs/declare-use/module.map
  include/clang/Basic/LangOptions.h
  include/clang/Basic/Module.h
  include/clang/Basic/LangOptions.def
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Lex/ModuleMap.h
  include/clang/Lex/Preprocessor.h
  include/clang/Driver/Options.td
  docs/Modules.rst
  lib/Sema/Sema.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/ModuleMap.cpp
  lib/Driver/Tools.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Basic/Module.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1063.1.patch
Type: text/x-patch
Size: 38531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130628/c2a88abe/attachment.bin>


More information about the cfe-commits mailing list