Index: include/llvm/Support/FileSystem.h =================================================================== --- include/llvm/Support/FileSystem.h +++ include/llvm/Support/FileSystem.h @@ -1031,8 +1031,10 @@ State->HasNoPushRequest = false; else { ErrorOr st = State->Stack.top()->status(); - if (!st) return *this; - if (is_directory(*st)) { + if (!st) { + ec = st.getError(); + return *this; + } else if (is_directory(*st)) { State->Stack.push(directory_iterator(*State->Stack.top(), ec, Follow)); if (ec) return *this; if (State->Stack.top() != end_itr) { Index: tools/llvm-cov/CodeCoverage.cpp =================================================================== --- tools/llvm-cov/CodeCoverage.cpp +++ tools/llvm-cov/CodeCoverage.cpp @@ -199,7 +199,7 @@ if (PathRemapping) addCollectedPath(Path); else - error("Missing source file", Path); + warning("Source file doesn't exit, proceeded by ignoring it.", Path); return; } @@ -210,13 +210,17 @@ if (llvm::sys::fs::is_directory(Status)) { std::error_code EC; + std::string PathBeforeErrorOccurs; for (llvm::sys::fs::recursive_directory_iterator F(Path, EC), E; F != E && !EC; F.increment(EC)) { + PathBeforeErrorOccurs = F->path(); if (llvm::sys::fs::is_regular_file(F->path())) addCollectedPath(F->path()); } - if (EC) - warning(EC.message(), Path); + if (EC) { + warning(EC.message(), PathBeforeErrorOccurs); + warning("Code coverage results may be incomplete."); + } } } Index: unittests/Support/Path.cpp =================================================================== --- unittests/Support/Path.cpp +++ unittests/Support/Path.cpp @@ -901,27 +901,17 @@ ASSERT_TRUE(std::equal(visited.begin(), visited.end(), expected.begin())); visited.clear(); - // The recursive directory iterator has to stat the file, so we need to skip - // the broken symlinks. - for (fs::recursive_directory_iterator - i(Twine(TestDirectory) + "/symlink", ec), - e; - i != e; i.increment(ec)) { - ASSERT_NO_ERROR(ec); - - ErrorOr status = i->status(); - if (status.getError() == - std::make_error_code(std::errc::no_such_file_or_directory)) { - i.no_push(); - continue; + // Iterator throws an error if encouters a broken symlink with follow_symlinks + // being true. + bool ErrorOccured = false; + for (fs::recursive_directory_iterator i( + Twine(TestDirectory) + "/symlink", ec), e; i != e; i.increment(ec)) { + if (!ec) { + ErrorOccured = true; + break; } - - visited.push_back(path::filename(i->path())); } - std::sort(visited.begin(), visited.end()); - expected = {"b", "bb", "d", "da", "dd", "ddd", "ddd"}; - ASSERT_TRUE(visited.size() == expected.size()); - ASSERT_TRUE(std::equal(visited.begin(), visited.end(), expected.begin())); + ASSERT_TRUE(ErrorOccured); visited.clear(); // This recursive directory iterator doesn't follow symlinks, so we don't need