diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2023-01-19 17:02:42 -0800 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2023-01-20 13:37:36 -0800 |
commit | c3efd52770ca964ba46287298c1d2f7697fd446c (patch) | |
tree | ba336fee3953bfb00a7c8bbacb6764b85a415770 /clang/lib/Basic/Module.cpp | |
parent | 743fbcb79d9af759377df5f5929ffdd38ff52b09 (diff) | |
download | llvm-c3efd52770ca964ba46287298c1d2f7697fd446c.zip llvm-c3efd52770ca964ba46287298c1d2f7697fd446c.tar.gz llvm-c3efd52770ca964ba46287298c1d2f7697fd446c.tar.bz2 |
[clang][modules] Disallow importing private framework in the implementation
Whenever we are compiling implementation of a framework (with the `-fmodule-name=FW` option), we never translate `#import <FW/Header.h>` to an import, regardless of whether "Header.h" belongs to "FW" or "FW_Private". For the same reasons, we also disallow `@import FW`. However, we still allow `@import FW_Private`. This patch disallows that a well, to be consistent with the rest of the rules.
Reviewed By: benlangmuir
Differential Revision: https://reviews.llvm.org/D142167
Diffstat (limited to 'clang/lib/Basic/Module.cpp')
-rw-r--r-- | clang/lib/Basic/Module.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index aa82a99..9c4c834 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -148,6 +148,26 @@ bool Module::isUnimportable(const LangOptions &LangOpts, llvm_unreachable("could not find a reason why module is unimportable"); } +// The -fmodule-name option tells the compiler to textually include headers in +// the specified module, meaning Clang won't build the specified module. This +// is useful in a number of situations, for instance, when building a library +// that vends a module map, one might want to avoid hitting intermediate build +// products containing the module map or avoid finding the system installed +// modulemap for that library. +bool Module::isForBuilding(const LangOptions &LangOpts) const { + StringRef TopLevelName = getTopLevelModuleName(); + StringRef CurrentModule = LangOpts.CurrentModule; + + // When building framework Foo, we want to make sure that Foo *and* + // Foo_Private are textually included and no modules are built for both. + if (getTopLevelModule()->IsFramework && + CurrentModule == LangOpts.ModuleName && + !CurrentModule.endswith("_Private") && TopLevelName.endswith("_Private")) + TopLevelName = TopLevelName.drop_back(8); + + return TopLevelName == CurrentModule; +} + bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target, Requirement &Req, UnresolvedHeaderDirective &MissingHeader, |