Skip to content

[cxx-interop] NFC: fix bad merge #59965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 1 addition & 62 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,66 +440,6 @@ ClangImporter::~ClangImporter() {

#pragma mark Module loading

static Optional<StringRef> getModuleMapFilePath(StringRef name,
SearchPathOptions &Opts,
llvm::Triple triple,
SmallVectorImpl<char> &buffer) {
StringRef platform = swift::getPlatformNameForTriple(triple);
StringRef arch = swift::getMajorArchitectureName(triple);

StringRef SDKPath = Opts.getSDKPath();
if (!SDKPath.empty()) {
buffer.clear();
buffer.append(SDKPath.begin(), SDKPath.end());
llvm::sys::path::append(buffer, "usr", "lib", "swift");
llvm::sys::path::append(buffer, platform, arch, name);

// Only specify the module map if that file actually exists. It may not;
// for example in the case that `swiftc -target x86_64-unknown-linux-gnu
// -emit-ir` is invoked using a Swift compiler not built for Linux targets.
if (llvm::sys::fs::exists(buffer))
return StringRef(buffer.data(), buffer.size());
}

if (!Opts.RuntimeResourcePath.empty()) {
buffer.clear();
buffer.append(Opts.RuntimeResourcePath.begin(),
Opts.RuntimeResourcePath.end());
llvm::sys::path::append(buffer, platform, arch, name);

// Only specify the module map if that file actually exists. It may not;
// for example in the case that `swiftc -target x86_64-unknown-linux-gnu
// -emit-ir` is invoked using a Swift compiler not built for Linux targets.
if (llvm::sys::fs::exists(buffer))
return StringRef(buffer.data(), buffer.size());
}

return None;
}

/// Finds the glibc.modulemap file relative to the provided resource dir.
///
/// Note that the module map used for Glibc depends on the target we're
/// compiling for, and is not included in the resource directory with the other
/// implicit module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
static Optional<StringRef>
getGlibcModuleMapPath(SearchPathOptions &Opts, llvm::Triple triple,
SmallVectorImpl<char> &buffer) {
return getModuleMapFilePath("glibc.modulemap", Opts, triple, buffer);
}

static Optional<StringRef>
getLibStdCxxModuleMapPath(SearchPathOptions &opts, llvm::Triple triple,
SmallVectorImpl<char> &buffer) {
return getModuleMapFilePath("libstdcxx.modulemap", opts, triple, buffer);
}

static Optional<StringRef>
getLibShimCxxModuleMapPath(SearchPathOptions &Opts, llvm::Triple triple,
SmallVectorImpl<char> &buffer) {
return getModuleMapFilePath("libcxxshim.modulemap", Opts, triple, buffer);
}

static bool clangSupportsPragmaAttributeWithSwiftAttr() {
clang::AttributeCommonInfo swiftAttrInfo(clang::SourceRange(),
clang::AttributeCommonInfo::AT_SwiftAttr,
Expand Down Expand Up @@ -613,8 +553,7 @@ importer::getNormalInvocationArguments(
});
}

SmallString<128> buffer;
if (auto path = getLibShimCxxModuleMapPath(searchPathOpts, triple, buffer)) {
if (auto path = getCxxShimModuleMapPath(searchPathOpts, triple)) {
invocationArgStrs.push_back((Twine("-fmodule-map-file=") + *path).str());
}

Expand Down
6 changes: 6 additions & 0 deletions lib/ClangImporter/ClangIncludePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ getLibStdCxxModuleMapPath(SearchPathOptions &opts, const llvm::Triple &triple) {
return getActualModuleMapPath("libstdcxx.modulemap", opts, triple);
}

Optional<SmallString<128>>
swift::getCxxShimModuleMapPath(SearchPathOptions &opts,
const llvm::Triple &triple) {
return getActualModuleMapPath("libcxxshim.modulemap", opts, triple);
}

static llvm::opt::InputArgList
parseClangDriverArgs(const clang::driver::Driver &clangDriver,
const ArrayRef<const char *> args) {
Expand Down
3 changes: 3 additions & 0 deletions lib/ClangImporter/ClangIncludePaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace swift {
SmallVector<std::pair<std::string, std::string>, 2>
getClangInvocationFileMapping(ASTContext &ctx);

Optional<SmallString<128>> getCxxShimModuleMapPath(SearchPathOptions &opts,
const llvm::Triple &triple);

} // namespace swift

#endif // SWIFT_CLANG_INCLUDE_PATHS_H