Index: docs/Modules.rst =================================================================== --- docs/Modules.rst +++ docs/Modules.rst @@ -466,6 +466,8 @@ *target feature* A specific target feature (e.g., ``sse4``, ``avx``, ``neon``) is available. +*platform variant* + A specific os/platform variant (e.g. ``ios``, ``macos``, ``android``, ``win32``, ``linux``, etc) is available. **Example:** The ``std`` module can be extended to also include C++ and C++11 headers using a *requires-declaration*: Index: lib/Basic/Module.cpp =================================================================== --- lib/Basic/Module.cpp +++ lib/Basic/Module.cpp @@ -93,7 +93,8 @@ .Case("opencl", LangOpts.OpenCL) .Case("tls", Target.isTLSSupported()) .Case("zvector", LangOpts.ZVector) - .Default(Target.hasFeature(Feature)); + .Default(Target.hasFeature(Feature) || + Target.getPlatformName() == Feature); if (!HasFeature) HasFeature = std::find(LangOpts.ModuleFeatures.begin(), LangOpts.ModuleFeatures.end(), Index: test/Modules/target-platform-features.m =================================================================== --- /dev/null +++ test/Modules/target-platform-features.m @@ -0,0 +1,33 @@ +// Clear and create directories +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: mkdir %t/cache +// RUN: mkdir %t/Inputs + +// Build module map file +// RUN: echo "module RequiresMacOS {" >> %t/Inputs/module.map +// RUN: echo " requires macos" >> %t/Inputs/module.map +// RUN: echo "}" >> %t/Inputs/module.map +// RUN: echo "module RequiresNotiOS {" >> %t/Inputs/module.map +// RUN: echo " requires !ios" >> %t/Inputs/module.map +// RUN: echo "}" >> %t/Inputs/module.map +// RUN: echo "module RequiresMain {" >> %t/Inputs/module.map +// RUN: echo " module SubRequiresNotiOS {" >> %t/Inputs/module.map +// RUN: echo " requires !ios" >> %t/Inputs/module.map +// RUN: echo " }" >> %t/Inputs/module.map +// RUN: echo "}" >> %t/Inputs/module.map + +// RUN: %clang_cc1 -triple=x86_64-apple-macosx10.6 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/Inputs -verify %s -fblocks -fobjc-arc +// expected-no-diagnostics + +// RUN: not %clang_cc1 -triple=arm64-apple-ios -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/Inputs %s -fblocks -fobjc-arc 2> %t.notios +// RUN: FileCheck %s -check-prefix=CHECK-IOS < %t.notios + +// CHECK-IOS: module 'RequiresMacOS' requires feature 'macos' +@import RequiresMacOS; +// CHECK-IOS: module 'RequiresNotiOS' is incompatible with feature 'ios' +@import RequiresNotiOS; + +// We should never get errors for submodules that don't match +// CHECK-IOS-NOT: module 'RequiresMain' +@import RequiresMain;