diff options
author | Sam McCall <sam.mccall@gmail.com> | 2023-09-22 22:29:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 22:29:25 +0200 |
commit | 7ca8c21af36acb117529e797b3d36e85a286ca47 (patch) | |
tree | bf108eb75872c3e90786030dfdc6b719554850d6 /clang/unittests/Driver/ToolChainTest.cpp | |
parent | 4a55d426967b9c70f5dea7b3a389e11393a4f4c4 (diff) | |
download | llvm-7ca8c21af36acb117529e797b3d36e85a286ca47.zip llvm-7ca8c21af36acb117529e797b3d36e85a286ca47.tar.gz llvm-7ca8c21af36acb117529e797b3d36e85a286ca47.tar.bz2 |
[Driver] Fix detection of libc++ with empty sysroot. (#66947)
b1e3cd1d79443603dc003441e07cdd8d30bb7f26 dropped the leading slash here,
presumably unintentionally.
(I don't understand Driver well enough to know how/where this is
supposed
to be tested, but it broke clangd on any project that uses the
system-installed -stdlib=libc++ on a standard debian install)
Diffstat (limited to 'clang/unittests/Driver/ToolChainTest.cpp')
-rw-r--r-- | clang/unittests/Driver/ToolChainTest.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp index ae567ab..731b6c9 100644 --- a/clang/unittests/Driver/ToolChainTest.cpp +++ b/clang/unittests/Driver/ToolChainTest.cpp @@ -19,10 +19,12 @@ #include "clang/Driver/Driver.h" #include "clang/Frontend/CompilerInstance.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include <memory> @@ -316,6 +318,52 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) { } } +MATCHER_P(jobHasArgs, Substr, "") { + const driver::Command &C = arg; + std::string Args = ""; + llvm::ListSeparator Sep(" "); + for (const char *Arg : C.getArguments()) { + Args += Sep; + Args += Arg; + } + if (is_style_windows(llvm::sys::path::Style::native)) + std::replace(Args.begin(), Args.end(), '\\', '/'); + if (llvm::StringRef(Args).contains(Substr)) + return true; + *result_listener << "whose args are '" << Args << "'"; + return false; +} + +TEST(ToolChainTest, VFSGnuLibcxxPathNoSysroot) { + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); + struct TestDiagnosticConsumer : public DiagnosticConsumer {}; + IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( + new llvm::vfs::InMemoryFileSystem); + + const char *EmptyFiles[] = { + "foo.cpp", + "/bin/clang", + "/usr/include/c++/v1/cstdio", + }; + + for (const char *Path : EmptyFiles) + InMemoryFileSystem->addFile(Path, 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + { + DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); + Driver TheDriver("/bin/clang", "x86_64-unknown-linux-gnu", Diags, + "clang LLVM compiler", InMemoryFileSystem); + std::unique_ptr<Compilation> C(TheDriver.BuildCompilation( + {"/bin/clang", "-fsyntax-only", "-stdlib=libc++", "foo.cpp"})); + ASSERT_TRUE(C); + EXPECT_THAT(C->getJobs(), testing::ElementsAre(jobHasArgs( + "-internal-isystem /usr/include/c++/v1"))); + } +} + TEST(ToolChainTest, DefaultDriverMode) { IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); |