diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5918,12 +5918,14 @@ "duplicating work in competing clang invocations.">>; // FIXME: We only need this in C++ modules / Modules TS if we might textually // enter a different module (eg, when building a header unit). -def fmodules_local_submodule_visibility : - Flag<["-"], "fmodules-local-submodule-visibility">, - HelpText<"Enforce name visibility rules across submodules of the same " - "top-level module.">, - MarshallingInfoFlag>, - ImpliedByAnyOf<[fmodules_ts.KeyPath, fcxx_modules.KeyPath]>; +defm modules_local_submodule_visibility : + BoolFOption<"modules-local-submodule-visibility", + LangOpts<"ModulesLocalVisibility">, + DefaultObjC")>, + PosFlag, + NegFlag>; def fmodules_codegen : Flag<["-"], "fmodules-codegen">, HelpText<"Generate code for uses of this module that assumes an explicit " diff --git a/clang/test/Modules/cxx20-disable.cpp b/clang/test/Modules/cxx20-disable.cpp --- a/clang/test/Modules/cxx20-disable.cpp +++ b/clang/test/Modules/cxx20-disable.cpp @@ -1,5 +1,5 @@ // RUN: rm -rf %t && mkdir %t -// RUN: %clang_cc1 -x objective-c++ -std=c++20 -I %t %s -verify=enabled +// RUN: %clang_cc1 -x objective-c++ -std=c++20 -I %t %s -verify=enabled -fmodules-local-submodule-visibility // RUN: %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s -verify=disabled // enabled-no-diagnostics diff --git a/clang/test/Modules/fno-modules-local-submodule-visibility.mm b/clang/test/Modules/fno-modules-local-submodule-visibility.mm new file mode 100644 --- /dev/null +++ b/clang/test/Modules/fno-modules-local-submodule-visibility.mm @@ -0,0 +1,35 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps \ +// RUN: -fmodules-cache-path=%t -fsyntax-only -I %t/include -x objective-c++ \ +// RUN: %t/tu.m -verify +// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps \ +// RUN: -fmodules-cache-path=%t -fsyntax-only -I %t/include -x objective-c++ \ +// RUN: %t/tu2.m -verify -fmodules-local-submodule-visibility + +//--- include/module.modulemap + +module M { + module A { + header "A.h" + export * + } + module B { + header "B.h" + export * + } +} + +//--- include/A.h +#define A 1 + +//--- include/B.h +inline int B = A; + +//--- tu.m +@import M; +int i = B; +// expected-no-diagnostics + +//--- tu2.m +@import M; // expected-error {{could not build module 'M'}} diff --git a/clang/test/Modules/import-syntax.c b/clang/test/Modules/import-syntax.c --- a/clang/test/Modules/import-syntax.c +++ b/clang/test/Modules/import-syntax.c @@ -8,7 +8,7 @@ // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x objective-c++ -DAT_IMPORT=1 %s // // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x c++ -fmodules-ts -DIMPORT=1 %s -// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x objective-c++ -fmodules-ts -DIMPORT=1 %s +// 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 // // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x c -DPRAGMA %s // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x objective-c -DPRAGMA %s