EricWF created this revision.

In order for libc++ to add `<experimental/coroutine>` to its module map, there 
has to be a feature that can be used to detect if coroutines support is enabled 
in Clang.


https://reviews.llvm.org/D33538

Files:
  docs/Modules.rst
  lib/Basic/Module.cpp
  test/Modules/Inputs/DependsOnModule.framework/Headers/coroutines.h
  test/Modules/Inputs/DependsOnModule.framework/Headers/not_coroutines.h
  test/Modules/Inputs/DependsOnModule.framework/module.map
  test/Modules/requires-coroutines.mm


Index: test/Modules/requires-coroutines.mm
===================================================================
--- /dev/null
+++ test/Modules/requires-coroutines.mm
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules 
-fimplicit-module-maps -F %S/Inputs %s -verify
+// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules 
-fimplicit-module-maps -F %S/Inputs %s -verify -fcoroutines-ts -DCOROUTINES
+
+
+#ifdef COROUTINES
+@import DependsOnModule.Coroutines;
+@import DependsOnModule.NotCoroutines; // expected-error {{module 
'DependsOnModule.NotCoroutines' is incompatible with feature 'coroutines'}}
+#else
+@import DependsOnModule.NotCoroutines;
+@import DependsOnModule.Coroutines; // expected-error {{module 
'DependsOnModule.Coroutines' requires feature 'coroutines'}}
+#endif
Index: test/Modules/Inputs/DependsOnModule.framework/module.map
===================================================================
--- test/Modules/Inputs/DependsOnModule.framework/module.map
+++ test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -22,7 +22,14 @@
   explicit module CustomReq2 {
     requires custom_req2
   }
-
+  explicit module Coroutines {
+    requires coroutines
+    header "coroutines.h"
+  }
+  explicit module NotCoroutines {
+    requires !coroutines
+    header "not_coroutines.h"
+  }
   explicit framework module SubFramework {
     umbrella header "SubFramework.h"
 
Index: test/Modules/Inputs/DependsOnModule.framework/Headers/not_coroutines.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/DependsOnModule.framework/Headers/not_coroutines.h
@@ -0,0 +1,3 @@
+#ifdef __cpp_coroutines
+#error coroutines must NOT be enabled
+#endif
Index: test/Modules/Inputs/DependsOnModule.framework/Headers/coroutines.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/DependsOnModule.framework/Headers/coroutines.h
@@ -0,0 +1,3 @@
+#ifndef __cpp_coroutines
+#error coroutines must be enabled
+#endif
Index: lib/Basic/Module.cpp
===================================================================
--- lib/Basic/Module.cpp
+++ lib/Basic/Module.cpp
@@ -68,6 +68,7 @@
                         .Case("cplusplus11", LangOpts.CPlusPlus11)
                         .Case("freestanding", LangOpts.Freestanding)
                         .Case("gnuinlineasm", LangOpts.GNUAsm)
+                        .Case("coroutines", LangOpts.CoroutinesTS)
                         .Case("objc", LangOpts.ObjC1)
                         .Case("objc_arc", LangOpts.ObjCAutoRefCount)
                         .Case("opencl", LangOpts.OpenCL)
Index: docs/Modules.rst
===================================================================
--- docs/Modules.rst
+++ docs/Modules.rst
@@ -413,6 +413,9 @@
 blocks
   The "blocks" language feature is available.
 
+coroutines
+  Support for the coroutines TS is available.
+
 cplusplus
   C++ support is available.
 


Index: test/Modules/requires-coroutines.mm
===================================================================
--- /dev/null
+++ test/Modules/requires-coroutines.mm
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify
+// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify -fcoroutines-ts -DCOROUTINES
+
+
+#ifdef COROUTINES
+@import DependsOnModule.Coroutines;
+@import DependsOnModule.NotCoroutines; // expected-error {{module 'DependsOnModule.NotCoroutines' is incompatible with feature 'coroutines'}}
+#else
+@import DependsOnModule.NotCoroutines;
+@import DependsOnModule.Coroutines; // expected-error {{module 'DependsOnModule.Coroutines' requires feature 'coroutines'}}
+#endif
Index: test/Modules/Inputs/DependsOnModule.framework/module.map
===================================================================
--- test/Modules/Inputs/DependsOnModule.framework/module.map
+++ test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -22,7 +22,14 @@
   explicit module CustomReq2 {
     requires custom_req2
   }
-
+  explicit module Coroutines {
+    requires coroutines
+    header "coroutines.h"
+  }
+  explicit module NotCoroutines {
+    requires !coroutines
+    header "not_coroutines.h"
+  }
   explicit framework module SubFramework {
     umbrella header "SubFramework.h"
 
Index: test/Modules/Inputs/DependsOnModule.framework/Headers/not_coroutines.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/DependsOnModule.framework/Headers/not_coroutines.h
@@ -0,0 +1,3 @@
+#ifdef __cpp_coroutines
+#error coroutines must NOT be enabled
+#endif
Index: test/Modules/Inputs/DependsOnModule.framework/Headers/coroutines.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/DependsOnModule.framework/Headers/coroutines.h
@@ -0,0 +1,3 @@
+#ifndef __cpp_coroutines
+#error coroutines must be enabled
+#endif
Index: lib/Basic/Module.cpp
===================================================================
--- lib/Basic/Module.cpp
+++ lib/Basic/Module.cpp
@@ -68,6 +68,7 @@
                         .Case("cplusplus11", LangOpts.CPlusPlus11)
                         .Case("freestanding", LangOpts.Freestanding)
                         .Case("gnuinlineasm", LangOpts.GNUAsm)
+                        .Case("coroutines", LangOpts.CoroutinesTS)
                         .Case("objc", LangOpts.ObjC1)
                         .Case("objc_arc", LangOpts.ObjCAutoRefCount)
                         .Case("opencl", LangOpts.OpenCL)
Index: docs/Modules.rst
===================================================================
--- docs/Modules.rst
+++ docs/Modules.rst
@@ -413,6 +413,9 @@
 blocks
   The "blocks" language feature is available.
 
+coroutines
+  Support for the coroutines TS is available.
+
 cplusplus
   C++ support is available.
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to