From: Nico Weber Date: Thu, 8 Aug 2019 17:58:32 +0000 (+0000) Subject: clang: Diag running out of file handles while looking for files X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=442c97abef7f1986a67588c9ad59af875918b53a;p=clang clang: Diag running out of file handles while looking for files clang would only print "file not found" when it's unable to find a header file. If the reason for that is a file handle leak, that's not a very useful error message. For errors that aren't in a small whitelist ("file not found", "file is directory"), print an error with the strerror() output. This changes behavior in corner cases: If clang was out of file handles while looking in one -I dir but then suddenly wasn't when looking in the next -I dir, and both directories contained a file with the desired name, previously we'd silently return the file from the second directory. For this reason, it's important to ignore "is a directory" for this new diag: if a file foo/foo exists and -I -Ifoo are passed, an include of "foo" should successfully open file "foo" in directory "foo/" instead of complaining that "./foo" is a directory. No test since we mostly hit this when there's a handle leak somewhere, and currently there isn't one. I manually tested this with the repro steps in comment 2 on the bug below. Fixes PR42524. Differential Revision: https://reviews.llvm.org/D65956 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368322 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 60cb13ba15..7cadc1bde5 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -309,9 +309,18 @@ const FileEntry *HeaderSearch::getFileAndSuggestModule( ModuleMap::KnownHeader *SuggestedModule) { // If we have a module map that might map this header, load it and // check whether we'll have a suggestion for a module. - auto File = getFileMgr().getFile(FileName, /*OpenFile=*/true); - if (!File) + llvm::ErrorOr File = + getFileMgr().getFile(FileName, /*OpenFile=*/true); + if (!File) { + // For rare, surprising errors (e.g. "out of file handles"), diag the EC + // message. + std::error_code EC = File.getError(); + if (EC != std::errc::no_such_file_or_directory && + EC != std::errc::is_a_directory) { + Diags.Report(IncludeLoc, diag::err_cannot_open_file) << EC.message(); + } return nullptr; + } // If there is a module that corresponds to this header, suggest it. if (!findUsableModuleForHeader(*File, Dir ? Dir : (*File)->getDir(),