[llvm] 9902362 - Support: Use sys::path::is_style_{posix,windows}() in a few places
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 29 12:09:48 PDT 2021
Author: Duncan P. N. Exon Smith
Date: 2021-10-29T12:09:41-07:00
New Revision: 99023627010bbfefb71e25a2b4d056de1cbd354e
URL: https://github.com/llvm/llvm-project/commit/99023627010bbfefb71e25a2b4d056de1cbd354e
DIFF: https://github.com/llvm/llvm-project/commit/99023627010bbfefb71e25a2b4d056de1cbd354e.diff
LOG: Support: Use sys::path::is_style_{posix,windows}() in a few places
Use the new sys::path::is_style_posix() and is_style_windows() in a few
places that need to detect the system's native path style.
In llvm/lib/Support/Path.cpp, this patch removes most uses of the
private `real_style()`, where is_style_posix() and is_style_windows()
are just a little tidier.
Elsewhere, this removes `_WIN32` macro checks. Added a FIXME to a
FileManagerTest that seemed fishy, but maintained the existing
behaviour.
Differential Revision: https://reviews.llvm.org/D112289
Added:
Modified:
clang/include/clang/Basic/JsonSupport.h
clang/lib/Basic/FileManager.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChain.cpp
clang/lib/Lex/PPDirectives.cpp
clang/unittests/Basic/FileManagerTest.cpp
clang/unittests/Driver/ToolChainTest.cpp
clang/unittests/Lex/HeaderSearchTest.cpp
clang/unittests/Tooling/RefactoringTest.cpp
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Support/GraphWriter.cpp
llvm/lib/Support/Path.cpp
llvm/tools/lli/lli.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/JsonSupport.h b/clang/include/clang/Basic/JsonSupport.h
index 6cd3f4d57b846..2ccb08e4bdaa2 100644
--- a/clang/include/clang/Basic/JsonSupport.h
+++ b/clang/include/clang/Basic/JsonSupport.h
@@ -12,6 +12,7 @@
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <iterator>
@@ -98,18 +99,19 @@ inline void printSourceLocationAsJson(raw_ostream &Out, SourceLocation Loc,
if (AddBraces)
Out << "{ ";
std::string filename(PLoc.getFilename());
-#ifdef _WIN32
- // Remove forbidden Windows path characters
- auto RemoveIt =
- std::remove_if(filename.begin(), filename.end(), [](auto Char) {
- static const char ForbiddenChars[] = "<>*?\"|";
- return std::find(std::begin(ForbiddenChars), std::end(ForbiddenChars),
- Char) != std::end(ForbiddenChars);
- });
- filename.erase(RemoveIt, filename.end());
- // Handle windows-specific path delimiters.
- std::replace(filename.begin(), filename.end(), '\\', '/');
-#endif
+ if (is_style_windows(llvm::sys::path::Style::native)) {
+ // Remove forbidden Windows path characters
+ auto RemoveIt =
+ std::remove_if(filename.begin(), filename.end(), [](auto Char) {
+ static const char ForbiddenChars[] = "<>*?\"|";
+ return std::find(std::begin(ForbiddenChars),
+ std::end(ForbiddenChars),
+ Char) != std::end(ForbiddenChars);
+ });
+ filename.erase(RemoveIt, filename.end());
+ // Handle windows-specific path delimiters.
+ std::replace(filename.begin(), filename.end(), '\\', '/');
+ }
Out << "\"line\": " << PLoc.getLine()
<< ", \"column\": " << PLoc.getColumn()
<< ", \"file\": \"" << filename << "\"";
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index c4eae6acd7b04..1cb52d5594d59 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -123,16 +123,16 @@ FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) {
DirName != llvm::sys::path::root_path(DirName) &&
llvm::sys::path::is_separator(DirName.back()))
DirName = DirName.substr(0, DirName.size()-1);
-#ifdef _WIN32
- // Fixing a problem with "clang C:test.c" on Windows.
- // Stat("C:") does not recognize "C:" as a valid directory
- std::string DirNameStr;
- if (DirName.size() > 1 && DirName.back() == ':' &&
- DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) {
- DirNameStr = DirName.str() + '.';
- DirName = DirNameStr;
+ if (is_style_windows(llvm::sys::path::Style::native)) {
+ // Fixing a problem with "clang C:test.c" on Windows.
+ // Stat("C:") does not recognize "C:" as a valid directory
+ std::string DirNameStr;
+ if (DirName.size() > 1 && DirName.back() == ':' &&
+ DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) {
+ DirNameStr = DirName.str() + '.';
+ DirName = DirNameStr;
+ }
}
-#endif
++NumDirLookups;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5b64ca8657d0e..2ddb753660e40 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4899,11 +4899,11 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
bool MultipleArchs,
StringRef OffloadingPrefix) const {
std::string BoundArch = OrigBoundArch.str();
-#if defined(_WIN32)
- // BoundArch may contains ':', which is invalid in file names on Windows,
- // therefore replace it with '%'.
- std::replace(BoundArch.begin(), BoundArch.end(), ':', '@');
-#endif
+ if (is_style_windows(llvm::sys::path::Style::native)) {
+ // BoundArch may contains ':', which is invalid in file names on Windows,
+ // therefore replace it with '%'.
+ std::replace(BoundArch.begin(), BoundArch.end(), ':', '@');
+ }
llvm::PrettyStackTraceString CrashInfo("Computing output path");
// Output to a user requested destination?
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index df205c37f0639..debaf9e7bd536 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -169,10 +169,11 @@ static const DriverSuffix *FindDriverSuffix(StringRef ProgName, size_t &Pos) {
/// present and lower-casing the string on Windows.
static std::string normalizeProgramName(llvm::StringRef Argv0) {
std::string ProgName = std::string(llvm::sys::path::stem(Argv0));
-#ifdef _WIN32
- // Transform to lowercase for case insensitive file systems.
- std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(), ::tolower);
-#endif
+ if (is_style_windows(llvm::sys::path::Style::native)) {
+ // Transform to lowercase for case insensitive file systems.
+ std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
+ ::tolower);
+ }
return ProgName;
}
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index ea14921b3aeaf..1c2439ac91021 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2012,20 +2012,16 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
SourceLocation FilenameLoc = FilenameTok.getLocation();
StringRef LookupFilename = Filename;
-#ifdef _WIN32
- llvm::sys::path::Style BackslashStyle = llvm::sys::path::Style::windows;
-#else
// Normalize slashes when compiling with -fms-extensions on non-Windows. This
// is unnecessary on Windows since the filesystem there handles backslashes.
SmallString<128> NormalizedPath;
- llvm::sys::path::Style BackslashStyle = llvm::sys::path::Style::posix;
- if (LangOpts.MicrosoftExt) {
+ llvm::sys::path::Style BackslashStyle = llvm::sys::path::Style::native;
+ if (is_style_posix(BackslashStyle) && LangOpts.MicrosoftExt) {
NormalizedPath = Filename.str();
llvm::sys::path::native(NormalizedPath);
LookupFilename = NormalizedPath;
BackslashStyle = llvm::sys::path::Style::windows;
}
-#endif
Optional<FileEntryRef> File = LookupHeaderIncludeOrImport(
CurDir, Filename, FilenameLoc, FilenameRange, FilenameTok,
diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp
index a122747efdc11..3c058a07f23ed 100644
--- a/clang/unittests/Basic/FileManagerTest.cpp
+++ b/clang/unittests/Basic/FileManagerTest.cpp
@@ -31,18 +31,18 @@ class FakeStatCache : public FileSystemStatCache {
void InjectFileOrDirectory(const char *Path, ino_t INode, bool IsFile,
const char *StatPath) {
-#ifndef _WIN32
SmallString<128> NormalizedPath(Path);
- llvm::sys::path::native(NormalizedPath);
- Path = NormalizedPath.c_str();
-
SmallString<128> NormalizedStatPath;
- if (StatPath) {
- NormalizedStatPath = StatPath;
- llvm::sys::path::native(NormalizedStatPath);
- StatPath = NormalizedStatPath.c_str();
+ if (is_style_posix(llvm::sys::path::Style::native)) {
+ llvm::sys::path::native(NormalizedPath);
+ Path = NormalizedPath.c_str();
+
+ if (StatPath) {
+ NormalizedStatPath = StatPath;
+ llvm::sys::path::native(NormalizedStatPath);
+ StatPath = NormalizedStatPath.c_str();
+ }
}
-#endif
if (!StatPath)
StatPath = Path;
@@ -74,11 +74,11 @@ class FakeStatCache : public FileSystemStatCache {
bool isFile,
std::unique_ptr<llvm::vfs::File> *F,
llvm::vfs::FileSystem &FS) override {
-#ifndef _WIN32
SmallString<128> NormalizedPath(Path);
- llvm::sys::path::native(NormalizedPath);
- Path = NormalizedPath.c_str();
-#endif
+ if (is_style_posix(llvm::sys::path::Style::native)) {
+ llvm::sys::path::native(NormalizedPath);
+ Path = NormalizedPath.c_str();
+ }
if (StatCalls.count(Path) != 0) {
Status = StatCalls[Path];
@@ -436,13 +436,16 @@ TEST_F(FileManagerTest, getVirtualFileWithDifferentName) {
#endif // !_WIN32
+static StringRef getSystemRoot() {
+ return is_style_windows(llvm::sys::path::Style::native) ? "C:/" : "/";
+}
+
TEST_F(FileManagerTest, makeAbsoluteUsesVFS) {
- SmallString<64> CustomWorkingDir;
-#ifdef _WIN32
- CustomWorkingDir = "C:";
-#else
- CustomWorkingDir = "/";
-#endif
+ // FIXME: Should this be using a root path / call getSystemRoot()? For now,
+ // avoiding that and leaving the test as-is.
+ SmallString<64> CustomWorkingDir =
+ is_style_windows(llvm::sys::path::Style::native) ? StringRef("C:")
+ : StringRef("/");
llvm::sys::path::append(CustomWorkingDir, "some", "weird", "path");
auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>(
@@ -464,12 +467,7 @@ TEST_F(FileManagerTest, makeAbsoluteUsesVFS) {
// getVirtualFile should always fill the real path.
TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) {
- SmallString<64> CustomWorkingDir;
-#ifdef _WIN32
- CustomWorkingDir = "C:/";
-#else
- CustomWorkingDir = "/";
-#endif
+ SmallString<64> CustomWorkingDir = getSystemRoot();
auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>(
new llvm::vfs::InMemoryFileSystem);
@@ -497,12 +495,7 @@ TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) {
}
TEST_F(FileManagerTest, getFileDontOpenRealPath) {
- SmallString<64> CustomWorkingDir;
-#ifdef _WIN32
- CustomWorkingDir = "C:/";
-#else
- CustomWorkingDir = "/";
-#endif
+ SmallString<64> CustomWorkingDir = getSystemRoot();
auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>(
new llvm::vfs::InMemoryFileSystem);
diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index 2bf727dfd2b4f..62ad6f7d53714 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -85,9 +85,8 @@ TEST(ToolChainTest, VFSGCCInstallation) {
llvm::raw_string_ostream OS(S);
C->getDefaultToolChain().printVerboseInfo(OS);
}
-#if _WIN32
- std::replace(S.begin(), S.end(), '\\', '/');
-#endif
+ if (is_style_windows(llvm::sys::path::Style::native))
+ std::replace(S.begin(), S.end(), '\\', '/');
EXPECT_EQ(
"Found candidate GCC installation: "
"/usr/lib/gcc/arm-linux-gnueabihf/4.6.3\n"
@@ -110,9 +109,8 @@ TEST(ToolChainTest, VFSGCCInstallation) {
llvm::raw_string_ostream OS(S);
C->getDefaultToolChain().printVerboseInfo(OS);
}
-#if _WIN32
- std::replace(S.begin(), S.end(), '\\', '/');
-#endif
+ if (is_style_windows(llvm::sys::path::Style::native))
+ std::replace(S.begin(), S.end(), '\\', '/');
// Test that 4.5.3 from --sysroot is not overridden by 4.6.3 (larger
// version) from /usr.
EXPECT_EQ("Found candidate GCC installation: "
@@ -153,9 +151,8 @@ TEST(ToolChainTest, VFSGCCInstallationRelativeDir) {
llvm::raw_string_ostream OS(S);
C->getDefaultToolChain().printVerboseInfo(OS);
}
-#if _WIN32
- std::replace(S.begin(), S.end(), '\\', '/');
-#endif
+ if (is_style_windows(llvm::sys::path::Style::windows))
+ std::replace(S.begin(), S.end(), '\\', '/');
EXPECT_EQ("Found candidate GCC installation: "
"/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"
"Selected GCC installation: "
diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp
index 78e2a2ca5e309..6ceec7c9cc0f1 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -188,11 +188,11 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) {
std::string HeaderDirName = "/tmp/Sources/Foo/Headers/";
std::string HeaderName = "Foo.h";
-#ifdef _WIN32
- // Force header path to be absolute on windows.
- // As headermap content should represent absolute locations.
- HeaderDirName = "C:" + HeaderDirName;
-#endif /*_WIN32*/
+ if (is_style_windows(llvm::sys::path::Style::native)) {
+ // Force header path to be absolute on windows.
+ // As headermap content should represent absolute locations.
+ HeaderDirName = "C:" + HeaderDirName;
+ }
test::HMapFileMockMaker<FileTy> Maker(File);
auto a = Maker.addString("Foo/Foo.h");
diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp
index d239aba31d1d3..c71a7243396a1 100644
--- a/clang/unittests/Tooling/RefactoringTest.cpp
+++ b/clang/unittests/Tooling/RefactoringTest.cpp
@@ -1031,18 +1031,17 @@ TEST_F(MergeReplacementsTest, OverlappingRanges) {
toReplacements({{"", 0, 3, "cc"}, {"", 3, 3, "dd"}}));
}
+static constexpr bool usesWindowsPaths() {
+ return is_style_windows(llvm::sys::path::Style::native);
+}
+
TEST(DeduplicateByFileTest, PathsWithDots) {
std::map<std::string, Replacements> FileToReplaces;
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS(
new llvm::vfs::InMemoryFileSystem());
FileManager FileMgr(FileSystemOptions(), VFS);
-#if !defined(_WIN32)
- StringRef Path1 = "a/b/.././c.h";
- StringRef Path2 = "a/c.h";
-#else
- StringRef Path1 = "a\\b\\..\\.\\c.h";
- StringRef Path2 = "a\\c.h";
-#endif
+ StringRef Path1 = usesWindowsPaths() ? "a\\b\\..\\.\\c.h" : "a/b/.././c.h";
+ StringRef Path2 = usesWindowsPaths() ? "a\\c.h" : "a/c.h";
EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer("")));
EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer("")));
FileToReplaces[std::string(Path1)] = Replacements();
@@ -1057,13 +1056,8 @@ TEST(DeduplicateByFileTest, PathWithDotSlash) {
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS(
new llvm::vfs::InMemoryFileSystem());
FileManager FileMgr(FileSystemOptions(), VFS);
-#if !defined(_WIN32)
- StringRef Path1 = "./a/b/c.h";
- StringRef Path2 = "a/b/c.h";
-#else
- StringRef Path1 = ".\\a\\b\\c.h";
- StringRef Path2 = "a\\b\\c.h";
-#endif
+ StringRef Path1 = usesWindowsPaths() ? ".\\a\\b\\c.h" : "./a/b/c.h";
+ StringRef Path2 = usesWindowsPaths() ? "a\\b\\c.h" : "a/b/c.h";
EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer("")));
EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer("")));
FileToReplaces[std::string(Path1)] = Replacements();
@@ -1078,13 +1072,8 @@ TEST(DeduplicateByFileTest, NonExistingFilePath) {
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS(
new llvm::vfs::InMemoryFileSystem());
FileManager FileMgr(FileSystemOptions(), VFS);
-#if !defined(_WIN32)
- StringRef Path1 = "./a/b/c.h";
- StringRef Path2 = "a/b/c.h";
-#else
- StringRef Path1 = ".\\a\\b\\c.h";
- StringRef Path2 = "a\\b\\c.h";
-#endif
+ StringRef Path1 = usesWindowsPaths() ? ".\\a\\b\\c.h" : "./a/b/c.h";
+ StringRef Path2 = usesWindowsPaths() ? "a\\b\\c.h" : "a/b/c.h";
FileToReplaces[std::string(Path1)] = Replacements();
FileToReplaces[std::string(Path2)] = Replacements();
FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces);
diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h
index e43da9c94f355..38f426ff04432 100644
--- a/llvm/include/llvm/Support/VirtualFileSystem.h
+++ b/llvm/include/llvm/Support/VirtualFileSystem.h
@@ -788,12 +788,7 @@ class RedirectingFileSystem : public vfs::FileSystem {
/// Whether to perform case-sensitive comparisons.
///
/// Currently, case-insensitive matching only works correctly with ASCII.
- bool CaseSensitive =
-#ifdef _WIN32
- false;
-#else
- true;
-#endif
+ bool CaseSensitive = is_style_posix(sys::path::Style::native);
/// IsRelativeOverlay marks whether a ExternalContentsPrefixDir path must
/// be prefixed in every 'external-contents' when reading from YAML files.
diff --git a/llvm/lib/Support/GraphWriter.cpp b/llvm/lib/Support/GraphWriter.cpp
index b41869aba95fb..696e6b7a99d8c 100644
--- a/llvm/lib/Support/GraphWriter.cpp
+++ b/llvm/lib/Support/GraphWriter.cpp
@@ -23,11 +23,12 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
-#include <system_error>
#include <string>
+#include <system_error>
#include <vector>
using namespace llvm;
@@ -94,11 +95,8 @@ StringRef llvm::DOT::getColorString(unsigned ColorNumber) {
static std::string replaceIllegalFilenameChars(std::string Filename,
const char ReplacementChar) {
-#ifdef _WIN32
- std::string IllegalChars = "\\/:?\"<>|";
-#else
- std::string IllegalChars = "/";
-#endif
+ std::string IllegalChars =
+ is_style_windows(sys::path::Style::native) ? "\\/:?\"<>|" : "/";
for (char IllegalChar : IllegalChars) {
std::replace(Filename.begin(), Filename.end(), IllegalChar,
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 89fe9233fa0a9..a5045f6f1cb8c 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -64,7 +64,7 @@ namespace {
if (path.empty())
return path;
- if (real_style(style) == Style::windows) {
+ if (is_style_windows(style)) {
// C:
if (path.size() >= 2 &&
std::isalpha(static_cast<unsigned char>(path[0])) && path[1] == ':')
@@ -96,7 +96,7 @@ namespace {
size_t pos = str.find_last_of(separators(style), str.size() - 1);
- if (real_style(style) == Style::windows) {
+ if (is_style_windows(style)) {
if (pos == StringRef::npos)
pos = str.find_last_of(':', str.size() - 2);
}
@@ -111,7 +111,7 @@ namespace {
// directory in str, it returns StringRef::npos.
size_t root_dir_start(StringRef str, Style style) {
// case "c:/"
- if (real_style(style) == Style::windows) {
+ if (is_style_windows(style)) {
if (str.size() > 2 && str[1] == ':' && is_separator(str[2], style))
return 2;
}
@@ -257,7 +257,7 @@ const_iterator &const_iterator::operator++() {
// Root dir.
if (was_net ||
// c:/
- (real_style(S) == Style::windows && Component.endswith(":"))) {
+ (is_style_windows(S) && Component.endswith(":"))) {
Component = Path.substr(Position, 1);
return *this;
}
@@ -346,7 +346,7 @@ StringRef root_path(StringRef path, Style style) {
if (b != e) {
bool has_net =
b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
- bool has_drive = (real_style(style) == Style::windows) && b->endswith(":");
+ bool has_drive = is_style_windows(style) && b->endswith(":");
if (has_net || has_drive) {
if ((++pos != e) && is_separator((*pos)[0], style)) {
@@ -371,7 +371,7 @@ StringRef root_name(StringRef path, Style style) {
if (b != e) {
bool has_net =
b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
- bool has_drive = (real_style(style) == Style::windows) && b->endswith(":");
+ bool has_drive = is_style_windows(style) && b->endswith(":");
if (has_net || has_drive) {
// just {C:,//net}, return the first component.
@@ -388,7 +388,7 @@ StringRef root_directory(StringRef path, Style style) {
if (b != e) {
bool has_net =
b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
- bool has_drive = (real_style(style) == Style::windows) && b->endswith(":");
+ bool has_drive = is_style_windows(style) && b->endswith(":");
if ((has_net || has_drive) &&
// {C:,//net}, skip to the next component.
@@ -495,7 +495,7 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension,
static bool starts_with(StringRef Path, StringRef Prefix,
Style style = Style::native) {
// Windows prefix matching : case and separator insensitive
- if (real_style(style) == Style::windows) {
+ if (is_style_windows(style)) {
if (Path.size() < Prefix.size())
return false;
for (size_t I = 0, E = Prefix.size(); I != E; ++I) {
@@ -546,7 +546,7 @@ void native(const Twine &path, SmallVectorImpl<char> &result, Style style) {
void native(SmallVectorImpl<char> &Path, Style style) {
if (Path.empty())
return;
- if (real_style(style) == Style::windows) {
+ if (is_style_windows(style)) {
std::replace(Path.begin(), Path.end(), '/', '\\');
if (Path[0] == '~' && (Path.size() == 1 || is_separator(Path[1], style))) {
SmallString<128> PathHome;
@@ -560,7 +560,7 @@ void native(SmallVectorImpl<char> &Path, Style style) {
}
std::string convert_to_slash(StringRef path, Style style) {
- if (real_style(style) != Style::windows)
+ if (is_style_posix(style))
return std::string(path);
std::string s = path.str();
@@ -595,13 +595,13 @@ StringRef extension(StringRef path, Style style) {
bool is_separator(char value, Style style) {
if (value == '/')
return true;
- if (real_style(style) == Style::windows)
+ if (is_style_windows(style))
return value == '\\';
return false;
}
StringRef get_separator(Style style) {
- if (real_style(style) == Style::windows)
+ if (is_style_windows(style))
return "\\";
return "/";
}
@@ -667,8 +667,7 @@ bool is_absolute(const Twine &path, Style style) {
StringRef p = path.toStringRef(path_storage);
bool rootDir = has_root_directory(p, style);
- bool rootName =
- (real_style(style) != Style::windows) || has_root_name(p, style);
+ bool rootName = is_style_posix(style) || has_root_name(p, style);
return rootDir && rootName;
}
@@ -682,7 +681,7 @@ bool is_absolute_gnu(const Twine &path, Style style) {
if (!p.empty() && is_separator(p.front(), style))
return true;
- if (real_style(style) == Style::windows) {
+ if (is_style_windows(style)) {
// Handle drive letter pattern (a character followed by ':') on Windows.
if (p.size() >= 2 && (p[0] && p[1] == ':'))
return true;
@@ -902,8 +901,7 @@ void make_absolute(const Twine ¤t_directory,
bool rootName = path::has_root_name(p);
// Already absolute.
- if ((rootName || real_style(Style::native) != Style::windows) &&
- rootDirectory)
+ if ((rootName || is_style_posix(Style::native)) && rootDirectory)
return;
// All of the following conditions will need the current directory.
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index d51b064633c45..d20daa07196bb 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -355,13 +355,12 @@ class LLIObjectCache : public ObjectCache {
return false;
std::string CacheSubdir = ModID.substr(PrefixLength);
-#if defined(_WIN32)
- // Transform "X:\foo" => "/X\foo" for convenience.
- if (isalpha(CacheSubdir[0]) && CacheSubdir[1] == ':') {
+ // Transform "X:\foo" => "/X\foo" for convenience on Windows.
+ if (is_style_windows(llvm::sys::path::Style::native) &&
+ isalpha(CacheSubdir[0]) && CacheSubdir[1] == ':') {
CacheSubdir[1] = CacheSubdir[0];
CacheSubdir[0] = '/';
}
-#endif
CacheName = CacheDir + CacheSubdir;
size_t pos = CacheName.rfind('.');
More information about the llvm-commits
mailing list