Skip to content

Commit 0556138

Browse files
committed
[clang][cli] Expose -fno-cxx-modules in cc1
For some use-cases, it might be useful to be able to turn off modules for C++ in `-cc1`. (The feature is implied by `-std=C++20`.) This patch exposes the `-fno-cxx-modules` option in `-cc1`. Reviewed By: arphaman Differential Revision: https://reviews.llvm.org/D106864
1 parent 9102a16 commit 0556138

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ defvar render_script = LangOpts<"RenderScript">;
467467
defvar hip = LangOpts<"HIP">;
468468
defvar gnu_mode = LangOpts<"GNUMode">;
469469
defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
470-
defvar cpp_modules = LangOpts<"CPlusPlusModules">;
471470

472471
defvar std = !strconcat("LangStandard::getLangStandardForKind(", lang_std.KeyPath, ")");
473472

@@ -1332,8 +1331,11 @@ defm cxx_exceptions: BoolFOption<"cxx-exceptions",
13321331
defm async_exceptions: BoolFOption<"async-exceptions",
13331332
LangOpts<"EHAsynch">, DefaultFalse,
13341333
PosFlag<SetTrue, [CC1Option], "Enable EH Asynchronous exceptions">, NegFlag<SetFalse>>;
1335-
def fcxx_modules : Flag <["-"], "fcxx-modules">, Group<f_Group>,
1336-
Flags<[NoXarchOption]>;
1334+
defm cxx_modules : BoolFOption<"cxx-modules",
1335+
LangOpts<"CPlusPlusModules">, Default<cpp20.KeyPath>,
1336+
NegFlag<SetFalse, [CC1Option], "Disable">, PosFlag<SetTrue, [], "Enable">,
1337+
BothFlags<[NoXarchOption], " modules for C++">>,
1338+
ShouldParseIf<cplusplus.KeyPath>;
13371339
def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, Group<f_Group>;
13381340
def fdebug_pass_structure : Flag<["-"], "fdebug-pass-structure">, Group<f_Group>;
13391341
def fdepfile_entry : Joined<["-"], "fdepfile-entry=">,
@@ -2154,7 +2156,7 @@ def fmodules_ts : Flag <["-"], "fmodules-ts">, Group<f_Group>,
21542156
Flags<[CC1Option]>, HelpText<"Enable support for the C++ Modules TS">,
21552157
MarshallingInfoFlag<LangOpts<"ModulesTS">>;
21562158
defm modules : BoolFOption<"modules",
2157-
LangOpts<"Modules">, Default<!strconcat(fmodules_ts.KeyPath, "||", cpp_modules.KeyPath)>,
2159+
LangOpts<"Modules">, Default<!strconcat(fmodules_ts.KeyPath, "||", fcxx_modules.KeyPath)>,
21582160
PosFlag<SetTrue, [CC1Option], "Enable the 'modules' language feature">,
21592161
NegFlag<SetFalse>, BothFlags<[NoXarchOption, CoreOption]>>;
21602162
def fmodule_maps : Flag <["-"], "fmodule-maps">, Flags<[CoreOption]>, Alias<fimplicit_module_maps>;
@@ -2213,8 +2215,6 @@ def fno_diagnostics_color : Flag<["-"], "fno-diagnostics-color">, Group<f_Group>
22132215
Flags<[CoreOption, NoXarchOption]>;
22142216
def fno_common : Flag<["-"], "fno-common">, Group<f_Group>, Flags<[CC1Option]>,
22152217
HelpText<"Compile common globals like normal definitions">;
2216-
def fno_cxx_modules : Flag <["-"], "fno-cxx-modules">, Group<f_Group>,
2217-
Flags<[NoXarchOption]>;
22182218
defm digraphs : BoolFOption<"digraphs",
22192219
LangOpts<"Digraphs">, Default<std#".hasDigraphs()">,
22202220
PosFlag<SetTrue, [], "Enable alternative token representations '<:', ':>', '<%', '%>', '%:', '%:%:' (default)">,
@@ -5298,7 +5298,7 @@ def fmodules_local_submodule_visibility :
52985298
HelpText<"Enforce name visibility rules across submodules of the same "
52995299
"top-level module.">,
53005300
MarshallingInfoFlag<LangOpts<"ModulesLocalVisibility">>,
5301-
ImpliedByAnyOf<[fmodules_ts.KeyPath, cpp_modules.KeyPath]>;
5301+
ImpliedByAnyOf<[fmodules_ts.KeyPath, fcxx_modules.KeyPath]>;
53025302
def fmodules_codegen :
53035303
Flag<["-"], "fmodules-codegen">,
53045304
HelpText<"Generate code for uses of this module that assumes an explicit "

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,8 +3150,6 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
31503150
Opts.HexFloats = Std.hasHexFloats();
31513151
Opts.ImplicitInt = Std.hasImplicitInt();
31523152

3153-
Opts.CPlusPlusModules = Opts.CPlusPlus20;
3154-
31553153
// Set OpenCL Version.
31563154
Opts.OpenCL = Std.isOpenCL();
31573155
if (LangStd == LangStandard::lang_opencl10)

clang/test/Modules/cxx20-disable.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: rm -rf %t && mkdir %t
2+
// RUN: %clang_cc1 -x objective-c++ -std=c++20 -I %t %s -verify=enabled
3+
// RUN: %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s -verify=disabled
4+
5+
// enabled-no-diagnostics
6+
7+
// The spelling of these errors is misleading.
8+
// The important thing is Clang rejected C++20 modules syntax.
9+
export module Foo; // disabled-error{{expected template}}
10+
// disabled-error@-1{{unknown type name 'module'}}

0 commit comments

Comments
 (0)