[clang] 55e1441 - Revert "[Clang] Use virtual FS in processing config files"
Serge Pavlov via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 9 02:44:05 PDT 2022
Author: Serge Pavlov
Date: 2022-09-09T16:43:15+07:00
New Revision: 55e1441f7b5d01a37fc46eb1711f03ee69845316
URL: https://github.com/llvm/llvm-project/commit/55e1441f7b5d01a37fc46eb1711f03ee69845316
DIFF: https://github.com/llvm/llvm-project/commit/55e1441f7b5d01a37fc46eb1711f03ee69845316.diff
LOG: Revert "[Clang] Use virtual FS in processing config files"
This reverts commit 9424497e43aff088e014d65fd952ec557e28e6cf.
Some buildbots failed, reverted for investigation.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Driver/Driver.cpp
clang/unittests/Driver/ToolChainTest.cpp
llvm/include/llvm/Support/CommandLine.h
llvm/lib/Support/CommandLine.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4804856bc8f5c..155eababa81e6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -93,8 +93,6 @@ Bug Fixes
`Issue 57516 <https://github.com/llvm/llvm-project/issues/57516>`_
- Fix ``__builtin_assume_aligned`` crash when the 1st arg is array type. This fixes
`Issue 57169 <https://github.com/llvm/llvm-project/issues/57169>`_
-- Clang configuration files are now read through the virtual file system
- rather than the physical one, if these are
diff erent.
Improvements to Clang's diagnostics
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 217236f459a50..ca8e0e5240e1d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -911,8 +911,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
/// by Dirs.
///
static bool searchForFile(SmallVectorImpl<char> &FilePath,
- ArrayRef<StringRef> Dirs, StringRef FileName,
- llvm::vfs::FileSystem &FS) {
+ ArrayRef<StringRef> Dirs, StringRef FileName) {
SmallString<128> WPath;
for (const StringRef &Dir : Dirs) {
if (Dir.empty())
@@ -920,8 +919,7 @@ static bool searchForFile(SmallVectorImpl<char> &FilePath,
WPath.clear();
llvm::sys::path::append(WPath, Dir, FileName);
llvm::sys::path::native(WPath);
- auto Status = FS.status(WPath);
- if (Status && Status->getType() == llvm::sys::fs::file_type::regular_file) {
+ if (llvm::sys::fs::is_regular_file(WPath)) {
FilePath = std::move(WPath);
return true;
}
@@ -932,7 +930,7 @@ static bool searchForFile(SmallVectorImpl<char> &FilePath,
bool Driver::readConfigFile(StringRef FileName) {
// Try reading the given file.
SmallVector<const char *, 32> NewCfgArgs;
- if (!llvm::cl::readConfigFile(FileName, Saver, NewCfgArgs, getVFS())) {
+ if (!llvm::cl::readConfigFile(FileName, Saver, NewCfgArgs)) {
Diag(diag::err_drv_cannot_read_config_file) << FileName;
return true;
}
@@ -972,7 +970,7 @@ bool Driver::loadConfigFile() {
SmallString<128> CfgDir;
CfgDir.append(
CLOptions->getLastArgValue(options::OPT_config_system_dir_EQ));
- if (CfgDir.empty() || getVFS().makeAbsolute(CfgDir))
+ if (CfgDir.empty() || llvm::sys::fs::make_absolute(CfgDir))
SystemConfigDir.clear();
else
SystemConfigDir = static_cast<std::string>(CfgDir);
@@ -981,7 +979,7 @@ bool Driver::loadConfigFile() {
SmallString<128> CfgDir;
CfgDir.append(
CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ));
- if (CfgDir.empty() || getVFS().makeAbsolute(CfgDir))
+ if (CfgDir.empty() || llvm::sys::fs::make_absolute(CfgDir))
UserConfigDir.clear();
else
UserConfigDir = static_cast<std::string>(CfgDir);
@@ -1006,16 +1004,13 @@ bool Driver::loadConfigFile() {
// If argument contains directory separator, treat it as a path to
// configuration file.
if (llvm::sys::path::has_parent_path(CfgFileName)) {
- SmallString<128> CfgFilePath(CfgFileName);
- if (llvm::sys::path::is_relative(CfgFilePath)) {
- if (getVFS().makeAbsolute(CfgFilePath))
- return true;
- auto Status = getVFS().status(CfgFilePath);
- if (!Status ||
- Status->getType() != llvm::sys::fs::file_type::regular_file) {
- Diag(diag::err_drv_config_file_not_exist) << CfgFilePath;
- return true;
- }
+ SmallString<128> CfgFilePath;
+ if (llvm::sys::path::is_relative(CfgFileName))
+ llvm::sys::fs::current_path(CfgFilePath);
+ llvm::sys::path::append(CfgFilePath, CfgFileName);
+ if (!llvm::sys::fs::is_regular_file(CfgFilePath)) {
+ Diag(diag::err_drv_config_file_not_exist) << CfgFilePath;
+ return true;
}
return readConfigFile(CfgFilePath);
}
@@ -1074,19 +1069,17 @@ bool Driver::loadConfigFile() {
// Try to find config file. First try file with corrected architecture.
llvm::SmallString<128> CfgFilePath;
if (!FixedConfigFile.empty()) {
- if (searchForFile(CfgFilePath, CfgFileSearchDirs, FixedConfigFile,
- getVFS()))
+ if (searchForFile(CfgFilePath, CfgFileSearchDirs, FixedConfigFile))
return readConfigFile(CfgFilePath);
// If 'x86_64-clang.cfg' was not found, try 'x86_64.cfg'.
FixedConfigFile.resize(FixedArchPrefixLen);
FixedConfigFile.append(".cfg");
- if (searchForFile(CfgFilePath, CfgFileSearchDirs, FixedConfigFile,
- getVFS()))
+ if (searchForFile(CfgFilePath, CfgFileSearchDirs, FixedConfigFile))
return readConfigFile(CfgFilePath);
}
// Then try original file name.
- if (searchForFile(CfgFilePath, CfgFileSearchDirs, CfgFileName, getVFS()))
+ if (searchForFile(CfgFilePath, CfgFileSearchDirs, CfgFileName))
return readConfigFile(CfgFilePath);
// Finally try removing driver mode part: 'x86_64-clang.cfg' -> 'x86_64.cfg'.
@@ -1094,7 +1087,7 @@ bool Driver::loadConfigFile() {
!ClangNameParts.TargetPrefix.empty()) {
CfgFileName.assign(ClangNameParts.TargetPrefix);
CfgFileName.append(".cfg");
- if (searchForFile(CfgFilePath, CfgFileSearchDirs, CfgFileName, getVFS()))
+ if (searchForFile(CfgFilePath, CfgFileSearchDirs, CfgFileName))
return readConfigFile(CfgFilePath);
}
diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index a9ac309bdc113..3faa285bf9112 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -484,61 +484,4 @@ TEST(ToolChainTest, Toolsets) {
}
}
-TEST(ToolChainTest, ConfigFileSearch) {
- IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
- IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
- struct TestDiagnosticConsumer : public DiagnosticConsumer {};
- DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
- IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS(
- new llvm::vfs::InMemoryFileSystem);
-
-#ifdef _WIN32
- const char *TestRoot = "C:\\";
-#else
- const char *TestRoot = "/";
-#endif
- FS->setCurrentWorkingDirectory(TestRoot);
-
- FS->addFile(
- "/opt/sdk/root.cfg", 0,
- llvm::MemoryBuffer::getMemBuffer("--sysroot=/opt/sdk/platform0\n"));
- FS->addFile(
- "/home/test/sdk/root.cfg", 0,
- llvm::MemoryBuffer::getMemBuffer("--sysroot=/opt/sdk/platform1\n"));
- FS->addFile(
- "/home/test/bin/root.cfg", 0,
- llvm::MemoryBuffer::getMemBuffer("--sysroot=/opt/sdk/platform2\n"));
-
- {
- Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
- "clang LLVM compiler", FS);
- std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
- {"/home/test/bin/clang", "--config", "root.cfg",
- "--config-system-dir=/opt/sdk", "--config-user-dir=/home/test/sdk"}));
- ASSERT_TRUE(C);
- ASSERT_FALSE(C->containsError());
- EXPECT_EQ("/opt/sdk/platform1", TheDriver.SysRoot);
- }
- {
- Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
- "clang LLVM compiler", FS);
- std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
- {"/home/test/bin/clang", "--config", "root.cfg",
- "--config-system-dir=/opt/sdk", "--config-user-dir="}));
- ASSERT_TRUE(C);
- ASSERT_FALSE(C->containsError());
- EXPECT_EQ("/opt/sdk/platform0", TheDriver.SysRoot);
- }
- {
- Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
- "clang LLVM compiler", FS);
- std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
- {"/home/test/bin/clang", "--config", "root.cfg",
- "--config-system-dir=", "--config-user-dir="}));
- ASSERT_TRUE(C);
- ASSERT_FALSE(C->containsError());
- EXPECT_EQ("/opt/sdk/platform2", TheDriver.SysRoot);
- }
-}
-
} // end anonymous namespace.
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 58ded2ceee9d9..be1f54cfba368 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -2078,8 +2078,7 @@ void tokenizeConfigFile(StringRef Source, StringSaver &Saver,
/// current config file.
///
bool readConfigFile(StringRef CfgFileName, StringSaver &Saver,
- SmallVectorImpl<const char *> &Argv,
- llvm::vfs::FileSystem &FS);
+ SmallVectorImpl<const char *> &Argv);
/// Expand response files on a command line recursively using the given
/// StringSaver and tokenization strategy. Argv should contain the command line
@@ -2100,7 +2099,7 @@ bool readConfigFile(StringRef CfgFileName, StringSaver &Saver,
/// the current response file.
/// \param [in] FS File system used for all file access when running the tool.
/// \param [in] CurrentDir Path used to resolve relative rsp files. If set to
-/// None, the file system current directory is used instead.
+/// None, process' cwd is used instead.
/// \return true if all @files were expanded successfully or there were none.
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
SmallVectorImpl<const char *> &Argv, bool MarkEOLs,
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index d81e115844d34..b8375f64be813 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1264,17 +1264,10 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
// always have an absolute path deduced from the containing file.
SmallString<128> CurrDir;
if (llvm::sys::path::is_relative(FName)) {
- if (!CurrentDir) {
- if (auto CWD = FS.getCurrentWorkingDirectory()) {
- CurrDir = *CWD;
- } else {
- // TODO: The error should be propagated up the stack.
- llvm::consumeError(llvm::errorCodeToError(CWD.getError()));
- return false;
- }
- } else {
+ if (!CurrentDir)
+ llvm::sys::fs::current_path(CurrDir);
+ else
CurrDir = *CurrentDir;
- }
llvm::sys::path::append(CurrDir, FName);
FName = CurrDir.c_str();
}
@@ -1364,26 +1357,24 @@ bool cl::expandResponseFiles(int Argc, const char *const *Argv,
}
bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver,
- SmallVectorImpl<const char *> &Argv,
- llvm::vfs::FileSystem &FS) {
+ SmallVectorImpl<const char *> &Argv) {
SmallString<128> AbsPath;
if (sys::path::is_relative(CfgFile)) {
- AbsPath.assign(CfgFile);
- if (std::error_code EC = FS.makeAbsolute(AbsPath))
- return false;
+ llvm::sys::fs::current_path(AbsPath);
+ llvm::sys::path::append(AbsPath, CfgFile);
CfgFile = AbsPath.str();
}
- if (llvm::Error Err =
- ExpandResponseFile(CfgFile, Saver, cl::tokenizeConfigFile, Argv,
- /*MarkEOLs=*/false, /*RelativeNames=*/true,
- /*ExpandBasePath=*/true, FS)) {
+ if (llvm::Error Err = ExpandResponseFile(
+ CfgFile, Saver, cl::tokenizeConfigFile, Argv,
+ /*MarkEOLs=*/false, /*RelativeNames=*/true, /*ExpandBasePath=*/true,
+ *llvm::vfs::getRealFileSystem())) {
// TODO: The error should be propagated up the stack.
llvm::consumeError(std::move(Err));
return false;
}
return ExpandResponseFiles(Saver, cl::tokenizeConfigFile, Argv,
/*MarkEOLs=*/false, /*RelativeNames=*/true,
- /*ExpandBasePath=*/true, llvm::None, FS);
+ /*ExpandBasePath=*/true, llvm::None);
}
static void initCommonOptions();
More information about the cfe-commits
mailing list