Skip to content

Commit d8fdb5e

Browse files
authored
Merge pull request #6130 from Bigcheese/objc-lsv-stable
[Clang][driver][cc1] Fix handling of of C++20 modules in ObjectiveC++
2 parents 9c08d21 + 5446d50 commit d8fdb5e

File tree

6 files changed

+70
-11
lines changed

6 files changed

+70
-11
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,9 @@ def err_test_module_file_extension_format : Error<
483483
"-ftest-module-file-extension argument '%0' is not of the required form "
484484
"'blockname:major:minor:hashed:user info'">;
485485

486+
def err_modules_no_lsv : Error<"%select{C++20|Modules TS}0 modules require "
487+
"the -fmodules-local-submodule-visibility -cc1 option">;
488+
486489
def err_drv_extract_api_wrong_kind : Error<
487490
"header file '%0' input '%1' does not match the type of prior input "
488491
"in api extraction; use '-x %2' to override">;

clang/include/clang/Driver/Options.td

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ defvar render_script = LangOpts<"RenderScript">;
492492
defvar hip = LangOpts<"HIP">;
493493
defvar gnu_mode = LangOpts<"GNUMode">;
494494
defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
495+
defvar objc = LangOpts<"ObjC">;
495496

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

@@ -1443,8 +1444,9 @@ defm async_exceptions: BoolFOption<"async-exceptions",
14431444
LangOpts<"EHAsynch">, DefaultFalse,
14441445
PosFlag<SetTrue, [CC1Option], "Enable EH Asynchronous exceptions">, NegFlag<SetFalse>>;
14451446
defm cxx_modules : BoolFOption<"cxx-modules",
1446-
LangOpts<"CPlusPlusModules">, Default<cpp20.KeyPath>,
1447-
NegFlag<SetFalse, [CC1Option], "Disable">, PosFlag<SetTrue, [], "Enable">,
1447+
// FIXME: improve tblgen to not need strconcat here.
1448+
LangOpts<"CPlusPlusModules">, Default<!strconcat(cpp20.KeyPath, " && !", objc.KeyPath)>,
1449+
NegFlag<SetFalse, [CC1Option], "Disable">, PosFlag<SetTrue, [CC1Option], "Enable">,
14481450
BothFlags<[NoXarchOption], " modules for C++">>,
14491451
ShouldParseIf<cplusplus.KeyPath>;
14501452
def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, Group<f_Group>;
@@ -5692,12 +5694,15 @@ defm fimplicit_modules_use_lock : BoolOption<"f", "implicit-modules-use-lock",
56925694
"duplicating work in competing clang invocations.">>;
56935695
// FIXME: We only need this in C++ modules / Modules TS if we might textually
56945696
// enter a different module (eg, when building a header unit).
5695-
def fmodules_local_submodule_visibility :
5696-
Flag<["-"], "fmodules-local-submodule-visibility">,
5697-
HelpText<"Enforce name visibility rules across submodules of the same "
5698-
"top-level module.">,
5699-
MarshallingInfoFlag<LangOpts<"ModulesLocalVisibility">>,
5700-
ImpliedByAnyOf<[fmodules_ts.KeyPath, fcxx_modules.KeyPath]>;
5697+
defm modules_local_submodule_visibility :
5698+
BoolFOption<"modules-local-submodule-visibility",
5699+
LangOpts<"ModulesLocalVisibility">,
5700+
// FIXME: improve tblgen to not need strconcat here.
5701+
Default<!strconcat("(", fmodules_ts.KeyPath, "||", fcxx_modules.KeyPath,
5702+
")")>,
5703+
PosFlag<SetTrue, [], "name visibility rules across submodules of the same "
5704+
"top-level module">,
5705+
NegFlag<SetFalse>>;
57015706
def fmodules_codegen :
57025707
Flag<["-"], "fmodules-codegen">,
57035708
HelpText<"Generate code for uses of this module that assumes an explicit "

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,6 +4087,9 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
40874087
(Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX);
40884088
}
40894089

4090+
if ((Opts.ModulesTS || Opts.CPlusPlusModules) && !Opts.ModulesLocalVisibility)
4091+
Diags.Report(diag::err_modules_no_lsv) << (Opts.CPlusPlusModules ? 0 : 1);
4092+
40904093
if (Arg *A = Args.getLastArg(options::OPT_fgnuc_version_EQ)) {
40914094
// Check that the version has 1 to 3 components and the minor and patch
40924095
// versions fit in two decimal digits.

clang/test/Modules/cxx20-disable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// 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
2+
// RUN: %clang_cc1 -x objective-c++ -std=c++20 -fcxx-modules -I %t %s -verify=enabled -fmodules-local-submodule-visibility
3+
// RUN: %clang_cc1 -x objective-c++ -std=c++20 -I %t %s -verify=disabled
44

55
// enabled-no-diagnostics
66

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps \
4+
// RUN: -fmodules-cache-path=%t -fsyntax-only -I %t/include -x objective-c++ \
5+
// RUN: %t/tu.m -verify
6+
// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps \
7+
// RUN: -fmodules-cache-path=%t -fsyntax-only -I %t/include -x objective-c++ \
8+
// RUN: %t/tu2.m -verify -fmodules-local-submodule-visibility
9+
10+
// RUN: not %clang_cc1 -std=c++20 -fmodules -fcxx-modules -fimplicit-module-maps \
11+
// RUN: -fmodules-cache-path=%t -fsyntax-only -I %t/include -x objective-c++ \
12+
// RUN: %t/driver.mm -fno-modules-local-submodule-visibility 2>&1 \
13+
// RUN: | FileCheck %t/driver.mm -check-prefix=CPP20
14+
// RUN: not %clang_cc1 -std=c++20 -fmodules-ts -fimplicit-module-maps \
15+
// RUN: -fmodules-cache-path=%t -fsyntax-only -I %t/include -x objective-c++ \
16+
// RUN: %t/driver.mm -fno-modules-local-submodule-visibility 2>&1 \
17+
// RUN: | FileCheck %t/driver.mm -check-prefix=TS
18+
19+
//--- include/module.modulemap
20+
21+
module M {
22+
module A {
23+
header "A.h"
24+
export *
25+
}
26+
module B {
27+
header "B.h"
28+
export *
29+
}
30+
}
31+
32+
//--- include/A.h
33+
#define A 1
34+
35+
//--- include/B.h
36+
inline int B = A;
37+
38+
//--- tu.m
39+
@import M;
40+
int i = B;
41+
// expected-no-diagnostics
42+
43+
//--- tu2.m
44+
@import M; // expected-error {{could not build module 'M'}}
45+
46+
//--- driver.mm
47+
// CPP20: error: C++20 modules require the -fmodules-local-submodule-visibility -cc1 option
48+
// TS: error: Modules TS modules require the -fmodules-local-submodule-visibility -cc1 option

clang/test/Modules/import-syntax.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x objective-c++ -DAT_IMPORT=1 %s
99
//
1010
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x c++ -fmodules-ts -DIMPORT=1 %s
11-
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x objective-c++ -fmodules-ts -DIMPORT=1 %s
11+
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -fmodules-local-submodule-visibility -verify -x objective-c++ -fmodules-ts -DIMPORT=1 %s
1212
//
1313
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x c -DPRAGMA %s
1414
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x objective-c -DPRAGMA %s

0 commit comments

Comments
 (0)