Skip to content

Commit 6a4233c

Browse files
authored
Merge pull request #6134 from Bigcheese/objc-lsv-stable2
[Clang][driver][cc1] Fix handling of of C++20 modules in ObjectiveC++
2 parents 2816fe5 + 102a29f commit 6a4233c

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
@@ -485,6 +485,9 @@ def err_test_module_file_extension_format : Error<
485485
"-ftest-module-file-extension argument '%0' is not of the required form "
486486
"'blockname:major:minor:hashed:user info'">;
487487

488+
def err_modules_no_lsv : Error<"%select{C++20|Modules TS}0 modules require "
489+
"the -fmodules-local-submodule-visibility -cc1 option">;
490+
488491
def err_drv_extract_api_wrong_kind : Error<
489492
"header file '%0' input '%1' does not match the type of prior input "
490493
"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
@@ -503,6 +503,7 @@ defvar hip = LangOpts<"HIP">;
503503
defvar gnu_mode = LangOpts<"GNUMode">;
504504
defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
505505
defvar hlsl = LangOpts<"HLSL">;
506+
defvar objc = LangOpts<"ObjC">;
506507

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

@@ -1502,8 +1503,9 @@ defm async_exceptions: BoolFOption<"async-exceptions",
15021503
LangOpts<"EHAsynch">, DefaultFalse,
15031504
PosFlag<SetTrue, [CC1Option], "Enable EH Asynchronous exceptions">, NegFlag<SetFalse>>;
15041505
defm cxx_modules : BoolFOption<"cxx-modules",
1505-
LangOpts<"CPlusPlusModules">, Default<cpp20.KeyPath>,
1506-
NegFlag<SetFalse, [CC1Option], "Disable">, PosFlag<SetTrue, [], "Enable">,
1506+
// FIXME: improve tblgen to not need strconcat here.
1507+
LangOpts<"CPlusPlusModules">, Default<!strconcat(cpp20.KeyPath, " && !", objc.KeyPath)>,
1508+
NegFlag<SetFalse, [CC1Option], "Disable">, PosFlag<SetTrue, [CC1Option], "Enable">,
15071509
BothFlags<[NoXarchOption], " modules for C++">>,
15081510
ShouldParseIf<cplusplus.KeyPath>;
15091511
def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, Group<f_Group>;
@@ -5910,12 +5912,15 @@ defm fimplicit_modules_use_lock : BoolOption<"f", "implicit-modules-use-lock",
59105912
"duplicating work in competing clang invocations.">>;
59115913
// FIXME: We only need this in C++ modules / Modules TS if we might textually
59125914
// enter a different module (eg, when building a header unit).
5913-
def fmodules_local_submodule_visibility :
5914-
Flag<["-"], "fmodules-local-submodule-visibility">,
5915-
HelpText<"Enforce name visibility rules across submodules of the same "
5916-
"top-level module.">,
5917-
MarshallingInfoFlag<LangOpts<"ModulesLocalVisibility">>,
5918-
ImpliedByAnyOf<[fmodules_ts.KeyPath, fcxx_modules.KeyPath]>;
5915+
defm modules_local_submodule_visibility :
5916+
BoolFOption<"modules-local-submodule-visibility",
5917+
LangOpts<"ModulesLocalVisibility">,
5918+
// FIXME: improve tblgen to not need strconcat here.
5919+
Default<!strconcat("(", fmodules_ts.KeyPath, "||", fcxx_modules.KeyPath,
5920+
")")>,
5921+
PosFlag<SetTrue, [], "name visibility rules across submodules of the same "
5922+
"top-level module">,
5923+
NegFlag<SetFalse>>;
59195924
def fmodules_codegen :
59205925
Flag<["-"], "fmodules-codegen">,
59215926
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
@@ -4102,6 +4102,9 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
41024102
(Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX);
41034103
}
41044104

4105+
if ((Opts.ModulesTS || Opts.CPlusPlusModules) && !Opts.ModulesLocalVisibility)
4106+
Diags.Report(diag::err_modules_no_lsv) << (Opts.CPlusPlusModules ? 0 : 1);
4107+
41054108
if (Arg *A = Args.getLastArg(options::OPT_fgnuc_version_EQ)) {
41064109
// Check that the version has 1 to 3 components and the minor and patch
41074110
// 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)