[PATCH] D69011: Replace platform-dependent `stat` with `llvm::sys::fs::status`. NFC intended.
Volodymyr Sapsai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 15 16:13:47 PDT 2019
vsapsai created this revision.
vsapsai added reviewers: bruno, sammccall.
Herald added subscribers: ributzka, arphaman, dexonsmith, jkorous.
vsapsai added a comment.
The plan is to instrument `llvm::sys::fs::status` with `ALWAYS_ENABLED_STATITSTIC` to be able to catch regressions causing lots of `stat` calls. That's why replacing current `stat` calls. And it seems to be a good change regardless of future plans.
https://reviews.llvm.org/D69011
Files:
clang/lib/Frontend/CompilerInstance.cpp
clang/tools/libclang/CIndexCodeCompletion.cpp
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===================================================================
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -803,8 +803,8 @@
os << arg << ".pth";
}
pchName.push_back('\0');
- struct stat stat_results;
- if (stat(pchName.str().c_str(), &stat_results) == 0)
+ llvm::sys::fs::file_status stat_results;
+ if (!llvm::sys::fs::status(pchName, stat_results))
usesPCH = true;
continue;
}
Index: clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -50,8 +50,6 @@
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
-#include <sys/stat.h>
-#include <system_error>
#include <time.h>
#include <utility>
@@ -1388,16 +1386,16 @@
/// Prune the module cache of modules that haven't been accessed in
/// a long time.
static void pruneModuleCache(const HeaderSearchOptions &HSOpts) {
- struct stat StatBuf;
+ llvm::sys::fs::file_status StatBuf;
llvm::SmallString<128> TimestampFile;
TimestampFile = HSOpts.ModuleCachePath;
assert(!TimestampFile.empty());
llvm::sys::path::append(TimestampFile, "modules.timestamp");
// Try to stat() the timestamp file.
- if (::stat(TimestampFile.c_str(), &StatBuf)) {
+ if (std::error_code EC = llvm::sys::fs::status(TimestampFile, StatBuf)) {
// If the timestamp file wasn't there, create one now.
- if (errno == ENOENT) {
+ if (EC == std::errc::no_such_file_or_directory) {
writeTimestampFile(TimestampFile);
}
return;
@@ -1405,7 +1403,8 @@
// Check whether the time stamp is older than our pruning interval.
// If not, do nothing.
- time_t TimeStampModTime = StatBuf.st_mtime;
+ time_t TimeStampModTime =
+ llvm::sys::toTimeT(StatBuf.getLastModificationTime());
time_t CurrentTime = time(nullptr);
if (CurrentTime - TimeStampModTime <= time_t(HSOpts.ModuleCachePruneInterval))
return;
@@ -1437,11 +1436,11 @@
// Look at this file. If we can't stat it, there's nothing interesting
// there.
- if (::stat(File->path().c_str(), &StatBuf))
+ if (llvm::sys::fs::status(File->path(), StatBuf))
continue;
// If the file has been used recently enough, leave it there.
- time_t FileAccessTime = StatBuf.st_atime;
+ time_t FileAccessTime = llvm::sys::toTimeT(StatBuf.getLastAccessedTime());
if (CurrentTime - FileAccessTime <=
time_t(HSOpts.ModuleCachePruneAfter)) {
continue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69011.225129.patch
Type: text/x-patch
Size: 2760 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191015/ee5f20d7/attachment.bin>
More information about the cfe-commits
mailing list