llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Devajith (devajithvs)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/177582.diff


2 Files Affected:

- (modified) clang/lib/Lex/HeaderSearch.cpp (+2-1) 
- (added) clang/test/Preprocessor/non-accessible-include.c (+10) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/177582
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to