[PATCH] D120540: [Driver] Enable to use C++20 modules standalone by -fcxx-modules

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 29 19:25:30 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG99eca8353808: [Driver] Enable to use C++20 standalne by -fcxx-modules (authored by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120540/new/

https://reviews.llvm.org/D120540

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.cpp
  clang/test/Modules/cxx-modules.cppm


Index: clang/test/Modules/cxx-modules.cppm
===================================================================
--- /dev/null
+++ clang/test/Modules/cxx-modules.cppm
@@ -0,0 +1,7 @@
+// This tests that we could use C++20 modules standalone.
+// RUN: %clang -std=c++03 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++11 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++14 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// RUN: %clang -std=c++17 -fcxx-modules -fsyntax-only -Xclang -verify %s
+// expected-no-diagnostics
+export module M;
Index: clang/test/Driver/modules.cpp
===================================================================
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -73,3 +73,14 @@
 // CHECK-HEADER-UNIT-USE: BAR;
 FOO;
 #endif
+
+// Check the independent use of -fcxx-modules
+//
+// RUN: %clang++ -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX17-MODULES
+// CHECK-CXX17-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX14-MODULES
+// CHECK-CXX14-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX11-MODULES
+// CHECK-CXX11-MODULES: "-fcxx-modules"
+// RUN: %clang++ -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX03-MODULES
+// CHECK-CXX03-MODULES: "-fcxx-modules"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3627,6 +3627,12 @@
     HaveModules = true;
   }
 
+  if (Args.hasFlag(options::OPT_fcxx_modules, options::OPT_fno_cxx_modules,
+                   false)) {
+    CmdArgs.push_back("-fcxx-modules");
+    HaveModules = true;
+  }
+
   // -fmodule-maps enables implicit reading of module map files. By default,
   // this is enabled if we are using Clang's flavor of precompiled modules.
   if (Args.hasFlag(options::OPT_fimplicit_module_maps,
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1410,7 +1410,7 @@
   PosFlag<SetTrue, [CC1Option], "Enable EH Asynchronous exceptions">, NegFlag<SetFalse>>;
 defm cxx_modules : BoolFOption<"cxx-modules",
   LangOpts<"CPlusPlusModules">, Default<cpp20.KeyPath>,
-  NegFlag<SetFalse, [CC1Option], "Disable">, PosFlag<SetTrue, [], "Enable">,
+  NegFlag<SetFalse, [CC1Option], "Disable">, PosFlag<SetTrue, [CC1Option], "Enable">,
   BothFlags<[NoXarchOption], " modules for C++">>,
   ShouldParseIf<cplusplus.KeyPath>;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, Group<f_Group>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120540.432818.patch
Type: text/x-patch
Size: 2855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220530/0c282fbb/attachment.bin>


More information about the cfe-commits mailing list