r284797 - [Modules] Add 'no_undeclared_includes' module map attribute

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 20 18:41:58 PDT 2016


Author: bruno
Date: Thu Oct 20 20:41:56 2016
New Revision: 284797

URL: http://llvm.org/viewvc/llvm-project?rev=284797&view=rev
Log:
[Modules] Add 'no_undeclared_includes' module map attribute

The 'no_undeclared_includes' attribute should be used in a module to
tell that only non-modular headers and headers from used modules are
accepted.

The main motivation behind this is to prevent dep cycles between system
libraries (such as darwin) and libc++.

Patch by Richard Smith!

Added:
    cfe/trunk/test/Modules/Inputs/libc-libcxx/
    cfe/trunk/test/Modules/Inputs/libc-libcxx/include/
    cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/
    cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/math.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/module.modulemap
    cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/stdlib.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/include/math.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/include/module.modulemap
    cfe/trunk/test/Modules/Inputs/libc-libcxx/include/stdlib.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/__config
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/math.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/module.modulemap
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stddef.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stdio.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stdlib.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/math.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stddef.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdint.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdio.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdlib.h
    cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/util.h
    cfe/trunk/test/Modules/libc-libcxx.cpp
Modified:
    cfe/trunk/docs/Modules.rst
    cfe/trunk/include/clang/Basic/Module.h
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/include/clang/Lex/ModuleMap.h
    cfe/trunk/lib/Basic/Module.cpp
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/lib/Lex/ModuleMap.cpp
    cfe/trunk/test/Modules/Inputs/System/usr/include/stdbool.h

Modified: cfe/trunk/docs/Modules.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Modules.rst?rev=284797&r1=284796&r2=284797&view=diff
==============================================================================
--- cfe/trunk/docs/Modules.rst (original)
+++ cfe/trunk/docs/Modules.rst Thu Oct 20 20:41:56 2016
@@ -365,6 +365,8 @@ The ``system`` attribute specifies that
 
 The ``extern_c`` attribute specifies that the module contains C code that can be used from within C++. When such a module is built for use in C++ code, all of the module's headers will be treated as if they were contained within an implicit ``extern "C"`` block. An import for a module with this attribute can appear within an ``extern "C"`` block. No other restrictions are lifted, however: the module currently cannot be imported within an ``extern "C"`` block in a namespace.
 
+The ``no_undeclared_includes`` attribute specifies that the module can only reach non-modular headers and headers from used modules. Since some headers could be present in more than one search path and map to different modules in each path, this mechanism helps clang to find the right header, i.e., prefer the one for the current module or in a submodule instead of the first usual match in the search paths.
+
 Modules can have a number of different kinds of members, each of which is described below:
 
 .. parsed-literal::

Modified: cfe/trunk/include/clang/Basic/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=284797&r1=284796&r2=284797&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Thu Oct 20 20:41:56 2016
@@ -201,6 +201,10 @@ public:
   /// built.
   unsigned ConfigMacrosExhaustive : 1;
 
+  /// \brief Whether files in this module can only include non-modular headers
+  /// and headers from used modules.
+  unsigned NoUndeclaredIncludes : 1;
+
   /// \brief Describes the visibility of the various names within a
   /// particular module.
   enum NameVisibilityKind {

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=284797&r1=284796&r2=284797&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Thu Oct 20 20:41:56 2016
@@ -523,8 +523,10 @@ public:
   /// \brief Retrieve the module that corresponds to the given file, if any.
   ///
   /// \param File The header that we wish to map to a module.
-  ModuleMap::KnownHeader findModuleForHeader(const FileEntry *File) const;
-  
+  /// \param AllowTextual Whether we want to find textual headers too.
+  ModuleMap::KnownHeader findModuleForHeader(const FileEntry *File,
+                                             bool AllowTextual = false) const;
+
   /// \brief Read the contents of the given module map file.
   ///
   /// \param File The module map file.

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=284797&r1=284796&r2=284797&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Thu Oct 20 20:41:56 2016
@@ -171,7 +171,8 @@ private:
 
   /// \brief The set of attributes that can be attached to a module.
   struct Attributes {
-    Attributes() : IsSystem(), IsExternC(), IsExhaustive() {}
+    Attributes()
+        : IsSystem(), IsExternC(), IsExhaustive(), NoUndeclaredIncludes() {}
 
     /// \brief Whether this is a system module.
     unsigned IsSystem : 1;
@@ -181,6 +182,10 @@ private:
 
     /// \brief Whether this is an exhaustive set of configuration macros.
     unsigned IsExhaustive : 1;
+
+    /// \brief Whether files in this module can only include non-modular headers
+    /// and headers from used modules.
+    unsigned NoUndeclaredIncludes : 1;
   };
 
   /// \brief A directory for which framework modules can be inferred.
@@ -315,10 +320,15 @@ public:
   ///
   /// \param File The header file that is likely to be included.
   ///
+  /// \param AllowTextual If \c true and \p File is a textual header, return
+  /// its owning module. Otherwise, no KnownHeader will be returned if the
+  /// file is only known as a textual header.
+  ///
   /// \returns The module KnownHeader, which provides the module that owns the
   /// given header file.  The KnownHeader is default constructed to indicate
   /// that no module owns this header file.
-  KnownHeader findModuleForHeader(const FileEntry *File);
+  KnownHeader findModuleForHeader(const FileEntry *File,
+                                  bool AllowTextual = false);
 
   /// \brief Retrieve all the modules that contain the given header file. This
   /// may not include umbrella modules, nor information from external sources,

Modified: cfe/trunk/lib/Basic/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=284797&r1=284796&r2=284797&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Module.cpp (original)
+++ cfe/trunk/lib/Basic/Module.cpp Thu Oct 20 20:41:56 2016
@@ -33,7 +33,7 @@ Module::Module(StringRef Name, SourceLoc
       IsExplicit(IsExplicit), IsSystem(false), IsExternC(false),
       IsInferred(false), InferSubmodules(false), InferExplicitSubmodules(false),
       InferExportWildcard(false), ConfigMacrosExhaustive(false),
-      NameVisibility(Hidden) {
+      NoUndeclaredIncludes(false), NameVisibility(Hidden) {
   if (Parent) {
     if (!Parent->isAvailable())
       IsAvailable = false;
@@ -41,6 +41,8 @@ Module::Module(StringRef Name, SourceLoc
       IsSystem = true;
     if (Parent->IsExternC)
       IsExternC = true;
+    if (Parent->NoUndeclaredIncludes)
+      NoUndeclaredIncludes = true;
     IsMissingRequirement = Parent->IsMissingRequirement;
     
     Parent->SubModuleIndex[Name] = Parent->SubModules.size();
@@ -181,6 +183,11 @@ bool Module::directlyUses(const Module *
   for (auto *Use : Top->DirectUses)
     if (Requested->isSubModuleOf(Use))
       return true;
+
+  // Anyone is allowed to use our builtin stddef.h and its accompanying module.
+  if (!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t")
+    return true;
+
   return false;
 }
 

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=284797&r1=284796&r2=284797&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Thu Oct 20 20:41:56 2016
@@ -413,6 +413,12 @@ getTopFrameworkDir(FileManager &FileMgr,
   return TopFrameworkDir;
 }
 
+static bool needModuleLookup(Module *RequestingModule,
+                             bool HasSuggestedModule) {
+  return HasSuggestedModule ||
+         (RequestingModule && RequestingModule->NoUndeclaredIncludes);
+}
+
 /// DoFrameworkLookup - Do a lookup of the specified file in the current
 /// DirectoryLookup, which is a framework directory.
 const FileEntry *DirectoryLookup::DoFrameworkLookup(
@@ -508,7 +514,7 @@ const FileEntry *DirectoryLookup::DoFram
   }
 
   // If we found the header and are allowed to suggest a module, do so now.
-  if (FE && SuggestedModule) {
+  if (FE && needModuleLookup(RequestingModule, SuggestedModule)) {
     // Find the framework in which this header occurs.
     StringRef FrameworkPath = FE->getDir()->getName();
     bool FoundFramework = false;
@@ -1158,22 +1164,45 @@ bool HeaderSearch::hasModuleMap(StringRe
 }
 
 ModuleMap::KnownHeader
-HeaderSearch::findModuleForHeader(const FileEntry *File) const {
+HeaderSearch::findModuleForHeader(const FileEntry *File,
+                                  bool AllowTextual) const {
   if (ExternalSource) {
     // Make sure the external source has handled header info about this file,
     // which includes whether the file is part of a module.
     (void)getExistingFileInfo(File);
   }
-  return ModMap.findModuleForHeader(File);
+  return ModMap.findModuleForHeader(File, AllowTextual);
+}
+
+static bool suggestModule(HeaderSearch &HS, const FileEntry *File,
+                          Module *RequestingModule,
+                          ModuleMap::KnownHeader *SuggestedModule) {
+  ModuleMap::KnownHeader Module =
+      HS.findModuleForHeader(File, /*AllowTextual*/true);
+  if (SuggestedModule)
+    *SuggestedModule = (Module.getRole() & ModuleMap::TextualHeader)
+                           ? ModuleMap::KnownHeader()
+                           : Module;
+
+  // If this module specifies [no_undeclared_includes], we cannot find any
+  // file that's in a non-dependency module.
+  if (RequestingModule && Module && RequestingModule->NoUndeclaredIncludes) {
+    HS.getModuleMap().resolveUses(RequestingModule, /*Complain*/false);
+    if (!RequestingModule->directlyUses(Module.getModule())) {
+      return false;
+    }
+  }
+
+  return true;
 }
 
 bool HeaderSearch::findUsableModuleForHeader(
     const FileEntry *File, const DirectoryEntry *Root, Module *RequestingModule,
     ModuleMap::KnownHeader *SuggestedModule, bool IsSystemHeaderDir) {
-  if (File && SuggestedModule) {
+  if (File && needModuleLookup(RequestingModule, SuggestedModule)) {
     // If there is a module that corresponds to this header, suggest it.
     hasModuleMap(File->getName(), Root, IsSystemHeaderDir);
-    *SuggestedModule = findModuleForHeader(File);
+    return suggestModule(*this, File, RequestingModule, SuggestedModule);
   }
   return true;
 }
@@ -1182,7 +1211,7 @@ bool HeaderSearch::findUsableModuleForFr
     const FileEntry *File, StringRef FrameworkName, Module *RequestingModule,
     ModuleMap::KnownHeader *SuggestedModule, bool IsSystemFramework) {
   // If we're supposed to suggest a module, look for one now.
-  if (SuggestedModule) {
+  if (needModuleLookup(RequestingModule, SuggestedModule)) {
     // Find the top-level framework based on this framework.
     SmallVector<std::string, 4> SubmodulePath;
     const DirectoryEntry *TopFrameworkDir
@@ -1199,7 +1228,7 @@ bool HeaderSearch::findUsableModuleForFr
     // important so that we're consistent about whether this header
     // corresponds to a module. Possibly we should lock down framework modules
     // so that this is not possible.
-    *SuggestedModule = findModuleForHeader(File);
+    return suggestModule(*this, File, RequestingModule, SuggestedModule);
   }
   return true;
 }

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=284797&r1=284796&r2=284797&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Thu Oct 20 20:41:56 2016
@@ -327,9 +327,10 @@ static bool isBetterKnownHeader(const Mo
   return false;
 }
 
-ModuleMap::KnownHeader ModuleMap::findModuleForHeader(const FileEntry *File) {
+ModuleMap::KnownHeader ModuleMap::findModuleForHeader(const FileEntry *File,
+                                                      bool AllowTextual) {
   auto MakeResult = [&](ModuleMap::KnownHeader R) -> ModuleMap::KnownHeader {
-    if (R.getRole() & ModuleMap::TextualHeader)
+    if (!AllowTextual && R.getRole() & ModuleMap::TextualHeader)
       return ModuleMap::KnownHeader();
     return R;
   };
@@ -674,6 +675,8 @@ Module *ModuleMap::inferFrameworkModule(
           Attrs.IsSystem |= inferred->second.Attrs.IsSystem;
           Attrs.IsExternC |= inferred->second.Attrs.IsExternC;
           Attrs.IsExhaustive |= inferred->second.Attrs.IsExhaustive;
+          Attrs.NoUndeclaredIncludes |=
+              inferred->second.Attrs.NoUndeclaredIncludes;
           ModuleMapFile = inferred->second.ModuleMapFile;
         }
       }
@@ -711,6 +714,7 @@ Module *ModuleMap::inferFrameworkModule(
   Result->IsSystem |= Attrs.IsSystem;
   Result->IsExternC |= Attrs.IsExternC;
   Result->ConfigMacrosExhaustive |= Attrs.IsExhaustive;
+  Result->NoUndeclaredIncludes |= Attrs.NoUndeclaredIncludes;
   Result->Directory = FrameworkDir;
 
   // umbrella header "umbrella-header-name"
@@ -1309,7 +1313,9 @@ namespace {
     /// \brief The 'extern_c' attribute.
     AT_extern_c,
     /// \brief The 'exhaustive' attribute.
-    AT_exhaustive
+    AT_exhaustive,
+    /// \brief The 'no_undeclared_includes' attribute.
+    AT_no_undeclared_includes
   };
 }
 
@@ -1479,6 +1485,9 @@ void ModuleMapParser::parseModuleDecl()
     ActiveModule->IsSystem = true;
   if (Attrs.IsExternC)
     ActiveModule->IsExternC = true;
+  if (Attrs.NoUndeclaredIncludes ||
+      (!ActiveModule->Parent && ModuleName == "Darwin"))
+    ActiveModule->NoUndeclaredIncludes = true;
   ActiveModule->Directory = Directory;
 
   bool Done = false;
@@ -1845,13 +1854,7 @@ void ModuleMapParser::parseHeaderDecl(MM
         // If Clang supplies this header but the underlying system does not,
         // just silently swap in our builtin version. Otherwise, we'll end
         // up adding both (later).
-        //
-        // For local visibility, entirely replace the system file with our
-        // one and textually include the system one. We need to pass macros
-        // from our header to the system one if we #include_next it.
-        //
-        // FIXME: Can we do this in all cases?
-        if (BuiltinFile && (!File || Map.LangOpts.ModulesLocalVisibility)) {
+        if (BuiltinFile && !File) {
           File = BuiltinFile;
           RelativePathName = BuiltinPathName;
           BuiltinFile = nullptr;
@@ -1877,15 +1880,16 @@ void ModuleMapParser::parseHeaderDecl(MM
       Module::Header H = {RelativePathName.str(), File};
       Map.excludeHeader(ActiveModule, H);
     } else {
-      // If there is a builtin counterpart to this file, add it now, before
-      // the "real" header, so we build the built-in one first when building
-      // the module.
+      // If there is a builtin counterpart to this file, add it now as a textual
+      // header, so it can be #include_next'd by the wrapper header, and can
+      // receive macros from the wrapper header.
       if (BuiltinFile) {
         // FIXME: Taking the name from the FileEntry is unstable and can give
         // different results depending on how we've previously named that file
         // in this build.
         Module::Header H = { BuiltinFile->getName(), BuiltinFile };
-        Map.addHeader(ActiveModule, H, Role);
+        Map.addHeader(ActiveModule, H, ModuleMap::ModuleHeaderRole(
+                                           Role | ModuleMap::TextualHeader));
       }
 
       // Record this header.
@@ -2375,6 +2379,7 @@ bool ModuleMapParser::parseOptionalAttri
       = llvm::StringSwitch<AttributeKind>(Tok.getString())
           .Case("exhaustive", AT_exhaustive)
           .Case("extern_c", AT_extern_c)
+          .Case("no_undeclared_includes", AT_no_undeclared_includes)
           .Case("system", AT_system)
           .Default(AT_unknown);
     switch (Attribute) {
@@ -2394,6 +2399,10 @@ bool ModuleMapParser::parseOptionalAttri
     case AT_exhaustive:
       Attrs.IsExhaustive = true;
       break;
+
+    case AT_no_undeclared_includes:
+      Attrs.NoUndeclaredIncludes = true;
+      break;
     }
     consumeToken();
 

Modified: cfe/trunk/test/Modules/Inputs/System/usr/include/stdbool.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/System/usr/include/stdbool.h?rev=284797&r1=284796&r2=284797&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/System/usr/include/stdbool.h (original)
+++ cfe/trunk/test/Modules/Inputs/System/usr/include/stdbool.h Thu Oct 20 20:41:56 2016
@@ -1 +1 @@
-// Testing hack: does not define bool/true/false.
+#include_next <stdbool.h>

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/math.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c%2B%2B/math.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/math.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/math.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,2 @@
+#include_next <math.h>
+template<typename T> T abs(T t) { return (t < 0) ? -t : t; }

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c%2B%2B/module.modulemap?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/module.modulemap Thu Oct 20 20:41:56 2016
@@ -0,0 +1,4 @@
+module "libc++" {
+  module math { header "math.h" export * }
+  module stdlib { header "stdlib.h" export * }
+}

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/stdlib.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c%2B%2B/stdlib.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/stdlib.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/include/c++/stdlib.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1 @@
+#include_next "stdlib.h"

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/include/math.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/include/math.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/include/math.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/include/math.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1 @@
+int abs(int);

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/include/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/include/module.modulemap?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/include/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/include/module.modulemap Thu Oct 20 20:41:56 2016
@@ -0,0 +1,4 @@
+module libc [no_undeclared_includes] {
+  module math { header "math.h" export * }
+  module stdlib { header "stdlib.h" export * }
+}

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/include/stdlib.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/include/stdlib.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/include/stdlib.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/include/stdlib.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1 @@
+#include <math.h>

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/__config
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c%2B%2B/v1/__config?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/__config (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/__config Thu Oct 20 20:41:56 2016
@@ -0,0 +1,6 @@
+#ifndef _LIBCPP_CONFIG
+#define _LIBCPP_CONFIG
+
+#define __LIBCXX_CONFIG
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/math.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c%2B%2B/v1/math.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/math.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/math.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,7 @@
+#ifndef LIBCXX_MATH_H
+#define LIBCXX_MATH_H
+
+#include_next <math.h>
+template<typename T> T abs(T t) { return (t < 0) ? -t : t; }
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c%2B%2B/v1/module.modulemap?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/module.modulemap Thu Oct 20 20:41:56 2016
@@ -0,0 +1,7 @@
+module "libc++" {
+  module math { header "math.h" export * }
+  module stdlib { header "stdlib.h" export * }
+  module stddef { header "stddef.h" export * }
+  module stdio { textual header "stdio.h" export * }
+  module __config { header "__config" export * }
+}

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stddef.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c%2B%2B/v1/stddef.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stddef.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stddef.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,6 @@
+#ifndef LIBCXX_STDDEF_H
+#define LIBCXX_STDDEF_H
+
+#include <__config>
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stdio.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c%2B%2B/v1/stdio.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stdio.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stdio.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,6 @@
+#ifndef LIBCXX_STDIO_H
+#define LIBCXX_STDIO_H
+
+#include <__config>
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stdlib.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c%2B%2B/v1/stdlib.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stdlib.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/c++/v1/stdlib.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,6 @@
+#ifndef LIBCXX_STDLIB_H
+#define LIBCXX_STDLIB_H
+
+#include_next "stdlib.h"
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/math.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/math.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/math.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/math.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1 @@
+int abs(int);

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap Thu Oct 20 20:41:56 2016
@@ -0,0 +1,9 @@
+module libc [no_undeclared_includes] {
+  module math { header "math.h" export * }
+  module stdlib { header "stdlib.h" export * }
+  module stdatomic { header "stdatomic.h" export * }
+  module stddef { header "stddef.h" export * }
+  module stdint { header "stdint.h" export * }
+  module stdio { header "stdio.h" export * }
+  module util { header "util.h" export * }
+}

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stddef.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stddef.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stddef.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stddef.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,2 @@
+// stddef.h
+#include_next "stddef.h"

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdint.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdint.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdint.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdint.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,22 @@
+typedef char           int_least8_t;
+typedef short         int_least16_t;
+typedef int         int_least32_t;
+typedef long long int         int_least64_t;
+typedef unsigned char         uint_least8_t;
+typedef unsigned short       uint_least16_t;
+typedef unsigned int       uint_least32_t;
+typedef unsigned long long       uint_least64_t;
+
+typedef char           int_fast8_t;
+typedef short         int_fast16_t;
+typedef int         int_fast32_t;
+typedef long long int         int_fast64_t;
+typedef unsigned char         uint_fast8_t;
+typedef unsigned short       uint_fast16_t;
+typedef unsigned int       uint_fast32_t;
+typedef unsigned long long       uint_fast64_t;
+
+typedef int * intptr_t;
+typedef unsigned int * uintptr_t;
+typedef int intmax_t;
+typedef unsigned int uintmax_t;

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdio.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdio.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdio.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdio.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,4 @@
+#ifndef DARWIN_STDIO_H
+#define DARWIN_STDIO_H
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdlib.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdlib.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdlib.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdlib.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1 @@
+#include <math.h>

Added: cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/util.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/util.h?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/util.h (added)
+++ cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/util.h Thu Oct 20 20:41:56 2016
@@ -0,0 +1,6 @@
+#ifndef DARWIN_UTIL_H
+#define DARWIN_UTIL_H
+
+#include <stdio.h>
+
+#endif

Added: cfe/trunk/test/Modules/libc-libcxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/libc-libcxx.cpp?rev=284797&view=auto
==============================================================================
--- cfe/trunk/test/Modules/libc-libcxx.cpp (added)
+++ cfe/trunk/test/Modules/libc-libcxx.cpp Thu Oct 20 20:41:56 2016
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/libc-libcxx/include/c++ -I %S/Inputs/libc-libcxx/include %s -verify
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fmodules-local-submodule-visibility -nostdinc++ -isystem %S/Inputs/libc-libcxx/sysroot/usr/include/c++/v1 -isystem %S/Inputs/libc-libcxx/sysroot/usr/include -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+#include "math.h"
+
+int n = abs(0);
+float f = abs<float>(0.f);




More information about the cfe-commits mailing list