@@ -87,6 +87,11 @@ Optional<FileSystem> &FileSystem::InstanceImpl() {
8787
8888vfs::directory_iterator FileSystem::DirBegin (const FileSpec &file_spec,
8989 std::error_code &ec) {
90+ if (!file_spec) {
91+ ec = std::error_code (static_cast <int >(errc::no_such_file_or_directory),
92+ std::system_category ());
93+ return {};
94+ }
9095 return DirBegin (file_spec.GetPath (), ec);
9196}
9297
@@ -97,6 +102,9 @@ vfs::directory_iterator FileSystem::DirBegin(const Twine &dir,
97102
98103llvm::ErrorOr<vfs::Status>
99104FileSystem::GetStatus (const FileSpec &file_spec) const {
105+ if (!file_spec)
106+ return std::error_code (static_cast <int >(errc::no_such_file_or_directory),
107+ std::system_category ());
100108 return GetStatus (file_spec.GetPath ());
101109}
102110
@@ -106,6 +114,8 @@ llvm::ErrorOr<vfs::Status> FileSystem::GetStatus(const Twine &path) const {
106114
107115sys::TimePoint<>
108116FileSystem::GetModificationTime (const FileSpec &file_spec) const {
117+ if (!file_spec)
118+ return sys::TimePoint<>();
109119 return GetModificationTime (file_spec.GetPath ());
110120}
111121
@@ -117,6 +127,8 @@ sys::TimePoint<> FileSystem::GetModificationTime(const Twine &path) const {
117127}
118128
119129uint64_t FileSystem::GetByteSize (const FileSpec &file_spec) const {
130+ if (!file_spec)
131+ return 0 ;
120132 return GetByteSize (file_spec.GetPath ());
121133}
122134
@@ -133,6 +145,8 @@ uint32_t FileSystem::GetPermissions(const FileSpec &file_spec) const {
133145
134146uint32_t FileSystem::GetPermissions (const FileSpec &file_spec,
135147 std::error_code &ec) const {
148+ if (!file_spec)
149+ return sys::fs::perms::perms_not_known;
136150 return GetPermissions (file_spec.GetPath (), ec);
137151}
138152
@@ -154,15 +168,15 @@ uint32_t FileSystem::GetPermissions(const Twine &path,
154168bool FileSystem::Exists (const Twine &path) const { return m_fs->exists (path); }
155169
156170bool FileSystem::Exists (const FileSpec &file_spec) const {
157- return Exists (file_spec.GetPath ());
171+ return file_spec && Exists (file_spec.GetPath ());
158172}
159173
160174bool FileSystem::Readable (const Twine &path) const {
161175 return GetPermissions (path) & sys::fs::perms::all_read;
162176}
163177
164178bool FileSystem::Readable (const FileSpec &file_spec) const {
165- return Readable (file_spec.GetPath ());
179+ return file_spec && Readable (file_spec.GetPath ());
166180}
167181
168182bool FileSystem::IsDirectory (const Twine &path) const {
@@ -173,7 +187,7 @@ bool FileSystem::IsDirectory(const Twine &path) const {
173187}
174188
175189bool FileSystem::IsDirectory (const FileSpec &file_spec) const {
176- return IsDirectory (file_spec.GetPath ());
190+ return file_spec && IsDirectory (file_spec.GetPath ());
177191}
178192
179193bool FileSystem::IsLocal (const Twine &path) const {
@@ -183,7 +197,7 @@ bool FileSystem::IsLocal(const Twine &path) const {
183197}
184198
185199bool FileSystem::IsLocal (const FileSpec &file_spec) const {
186- return IsLocal (file_spec.GetPath ());
200+ return file_spec && IsLocal (file_spec.GetPath ());
187201}
188202
189203void FileSystem::EnumerateDirectory (Twine path, bool find_directories,
@@ -261,6 +275,9 @@ void FileSystem::Resolve(SmallVectorImpl<char> &path) {
261275}
262276
263277void FileSystem::Resolve (FileSpec &file_spec) {
278+ if (!file_spec)
279+ return ;
280+
264281 // Extract path from the FileSpec.
265282 SmallString<128 > path;
266283 file_spec.GetPath (path);
0 commit comments