https://github.com/devajithvs created https://github.com/llvm/llvm-project/pull/177582
If part of the -I search path cannot be accessed (permissions), clang will throw an error, even if the header can be found in subsequent search path elements. This is counter productive as the compilation will seem to have failed due to that error, even though everyone is happy. Based on the original patch by Axel Naumann >From 0248d934607581e0f4ac79e40d22b5b01f918608 Mon Sep 17 00:00:00 2001 From: Axel Naumann <[email protected]> Date: Fri, 3 Mar 2023 12:37:00 +0100 Subject: [PATCH] [clang][HeaderSearch] Treat permission-denied include paths as non-fatal If part of the -I search path cannot be accessed (permissions), clang will throw an error, even if the header can be found in subsequent search path elements. This is counter productive as the compilation will seem to have failed due to that error, even though everyone is happy. Based on the original patch by Axel Naumann --- clang/lib/Lex/HeaderSearch.cpp | 3 ++- clang/test/Preprocessor/non-accessible-include.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 clang/test/Preprocessor/non-accessible-include.c diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 5f52d62bd36ed..689066cacc2e9 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -455,7 +455,8 @@ OptionalFileEntryRef HeaderSearch::getFileAndSuggestModule( std::error_code EC = llvm::errorToErrorCode(File.takeError()); if (EC != llvm::errc::no_such_file_or_directory && EC != llvm::errc::invalid_argument && - EC != llvm::errc::is_a_directory && EC != llvm::errc::not_a_directory) { + EC != llvm::errc::is_a_directory && EC != llvm::errc::not_a_directory && + EC != llvm::errc::permission_denied) { Diags.Report(IncludeLoc, diag::err_cannot_open_file) << FileName << EC.message(); } diff --git a/clang/test/Preprocessor/non-accessible-include.c b/clang/test/Preprocessor/non-accessible-include.c new file mode 100644 index 0000000000000..173e6e5745037 --- /dev/null +++ b/clang/test/Preprocessor/non-accessible-include.c @@ -0,0 +1,10 @@ +// Needs chmod +// UNSUPPORTED: system-windows +// +// RUN: chmod -R 755 %t +// RUN: rm -rf %t && mkdir -p %t/noaccess %t/haveaccess +// RUN: echo "int test();" > %t/haveaccess/test.h +// RUN: chmod 000 %t/noaccess +// RUN: %clang_cc1 -fsyntax-only -I %t/noaccess -I %t/haveaccess -verify %s + +#include "test.h" // expected-no-diagnostics _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
