ChuanqiXu created this revision. ChuanqiXu added reviewers: jansvoboda11, sammccall, urnathan, Quuxplusone. ChuanqiXu added a project: clang. Herald added a subscriber: dang. ChuanqiXu requested review of this revision. Herald added a subscriber: cfe-commits.
This patch allows user to use C++20 module by `-fcxx-modules`. Previously, we could only use it under `-std=c++20`. Given that user could use C++20 coroutine standalonel by `-fcoroutines-ts`. It makes sense to offer an option to use C++20 modules without enabling C++20. Repository: rG LLVM Github Monorepo 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,4 @@ +// This tests that we could use C++20 modules standalone. +// RUN: %clang -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,8 @@ // CHECK-HEADER-UNIT-USE: BAR; FOO; #endif + +// Check the independent use of -fcxx-modules +// +// RUN: %clang -fcxx-modules -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX-MODULES +// CHECK-CXX-MODULES: "-fcxx-modules" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -3590,6 +3590,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 @@ -1386,7 +1386,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>;
Index: clang/test/Modules/cxx-modules.cppm =================================================================== --- /dev/null +++ clang/test/Modules/cxx-modules.cppm @@ -0,0 +1,4 @@ +// This tests that we could use C++20 modules standalone. +// RUN: %clang -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,8 @@ // CHECK-HEADER-UNIT-USE: BAR; FOO; #endif + +// Check the independent use of -fcxx-modules +// +// RUN: %clang -fcxx-modules -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-CXX-MODULES +// CHECK-CXX-MODULES: "-fcxx-modules" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -3590,6 +3590,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 @@ -1386,7 +1386,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>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits