https://github.com/devajithvs updated https://github.com/llvm/llvm-project/pull/177582
>From 622ce8d8098a6c0e67fc1a5ca7dee7856f892abd 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 due to permissions, Clang no longer treats this as a fatal error. Instead, it emits a warning pointing to the exact path that cannot be accessed while continuing the search in subsequent search path elements. Based on the original patch by Axel Naumann. --- clang/include/clang/Basic/DiagnosticCommonKinds.td | 1 + clang/lib/Lex/HeaderSearch.cpp | 7 +++++++ clang/test/Preprocessor/non-accessible-include.c | 9 +++++++++ 3 files changed, 17 insertions(+) create mode 100644 clang/test/Preprocessor/non-accessible-include.c diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td index 6e50e225a8cc1..b38dc5f43e26d 100644 --- a/clang/include/clang/Basic/DiagnosticCommonKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -389,6 +389,7 @@ def err_unable_to_rename_temp : Error< "unable to rename temporary '%0' to output file '%1': '%2'">; def err_unable_to_make_temp : Error< "unable to make temporary file: %0">; +def warn_cannot_access_file : Warning<"cannot access file '%0': %1">; def remark_sloc_usage : Remark< "source manager location address space usage:">, InGroup<DiagGroup<"sloc-usage">>, DefaultRemark, ShowInSystemHeader; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 5f52d62bd36ed..b462ec2af277a 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -453,6 +453,13 @@ OptionalFileEntryRef HeaderSearch::getFileAndSuggestModule( // For rare, surprising errors (e.g. "out of file handles"), diag the EC // message. std::error_code EC = llvm::errorToErrorCode(File.takeError()); + + if (EC == llvm::errc::permission_denied) { + Diags.Report(IncludeLoc, diag::warn_cannot_access_file) + << FileName << EC.message(); + return std::nullopt; + } + 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) { diff --git a/clang/test/Preprocessor/non-accessible-include.c b/clang/test/Preprocessor/non-accessible-include.c new file mode 100644 index 0000000000000..ee6f6834e9867 --- /dev/null +++ b/clang/test/Preprocessor/non-accessible-include.c @@ -0,0 +1,9 @@ +// Needs chmod +// UNSUPPORTED: system-windows +// +// RUN: chmod -R 755 %t; 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-warning {{cannot access file}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
