[PATCH] D101479: [Driver] Support libc++ in MSVC
Petr Hosek via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 28 11:27:52 PDT 2021
phosek created this revision.
phosek added reviewers: hans, rnk, thakis.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This implements support for using libc++ headers in MSVC toolchain.
We only support libc++ headers that are part of the toolchain, and
not headers installed elsewhere on the system.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101479
Files:
clang/lib/Driver/ToolChains/MSVC.cpp
clang/test/Driver/msvc-libcxx.cpp
Index: clang/test/Driver/msvc-libcxx.cpp
===================================================================
--- /dev/null
+++ clang/test/Driver/msvc-libcxx.cpp
@@ -0,0 +1,3 @@
+// RUN: %clangxx -target x86_64-pc-windows-msvc --stdlib=libc++ -### %s 2>&1 | FileCheck %s -check-prefix MSVC-LIBCXX
+
+// MSVC-LIBCXX: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}c++{{/|\\\\}}v1"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===================================================================
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1323,7 +1323,34 @@
void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
- // FIXME: There should probably be logic here to find libc++ on Windows.
+ if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+ DriverArgs.hasArg(options::OPT_nostdincxx))
+ return;
+
+ const Driver &D = getDriver();
+
+ auto AddLibcxxIncludePath = [&](StringRef Path) {
+ std::string Version = detectLibcxxVersion(Path);
+ if (Version.empty())
+ return;
+
+ SmallString<128> Dir(Path);
+ llvm::sys::path::append(Dir, "c++", Version);
+ addSystemInclude(DriverArgs, CC1Args, Dir);
+ };
+
+ switch (GetCXXStdlibType(DriverArgs)) {
+ case ToolChain::CST_Libcxx: {
+ SmallString<128> P(D.Dir);
+ llvm::sys::path::append(P, "..", "include");
+ AddLibcxxIncludePath(P);
+ break;
+ }
+
+ default:
+ // TODO: Shall we report an error for other C++ standard libraries?
+ break;
+ }
}
VersionTuple MSVCToolChain::computeMSVCVersion(const Driver *D,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101479.341276.patch
Type: text/x-patch
Size: 1661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210428/1b9962c4/attachment.bin>
More information about the cfe-commits
mailing list