https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/213689

>From e11e853f5de5f27f7dc2bb36885e8b5fe5d4525d Mon Sep 17 00:00:00 2001
From: Qiu Chaofan <[email protected]>
Date: Mon, 3 Aug 2026 22:36:06 +0800
Subject: [PATCH] [clang] Fix include behavior for leading double slashes

LLVM path parsing sees path like "//foo.h" as network-style root name
instead of file in root directory, which makes compiler normalize
"//foo.h" to "foo.h" and search it unexpectedly in paths.

This change uses `is_absolute_gnu` instead so that path separator is
treated directly. Windows UNC paths are also seen as absolute.

Fixes #133174
---
 clang/docs/ReleaseNotes.md                                 | 3 +++
 clang/lib/Lex/HeaderSearch.cpp                             | 6 ++++--
 clang/test/Preprocessor/Inputs/leading-double-slash.h      | 0
 clang/test/Preprocessor/include-leading-double-backslash.c | 4 ++++
 clang/test/Preprocessor/include-leading-double-slash.c     | 3 +++
 5 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Preprocessor/Inputs/leading-double-slash.h
 create mode 100644 clang/test/Preprocessor/include-leading-double-backslash.c
 create mode 100644 clang/test/Preprocessor/include-leading-double-slash.c

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 2f13ec59483ee..ebf369ba3244c 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -447,6 +447,9 @@ features cannot lower the translation-unit ABI level;
   non-reproducible across runs. (#GH209639)
 
 #### Miscellaneous Bug Fixes
+- Fixed incorrect header search when filename starts with two path separators.
+  Clang now treats path in `#include <//foo.h>` as `/foo.h` instead of `foo.h`.
+  (GH#133174)
 
 #### Miscellaneous Clang Crashes Fixed
 - Fixed a crash when instantiating an invalid dependent friend destructor 
declaration in a class template. (#GH210234)
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index ecd80db10f2bd..61ac296b12453 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -967,8 +967,10 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
   if (SuggestedModule)
     *SuggestedModule = ModuleMap::KnownHeader();
 
-  // If 'Filename' is absolute, check to see if it exists and no searching.
-  if (llvm::sys::path::is_absolute(Filename)) {
+  // If 'Filename' is absolute under GNU rules, check it directly without
+  // searching in paths. Paths with leading native separator are treated as
+  // absolute, including '//' and Windows UNC paths.
+  if (llvm::sys::path::is_absolute_gnu(Filename)) {
     CurDir = nullptr;
 
     // If this was an #include_next "/absolute/file", fail.
diff --git a/clang/test/Preprocessor/Inputs/leading-double-slash.h 
b/clang/test/Preprocessor/Inputs/leading-double-slash.h
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Preprocessor/include-leading-double-backslash.c 
b/clang/test/Preprocessor/include-leading-double-backslash.c
new file mode 100644
index 0000000000000..3afc36eb63cb9
--- /dev/null
+++ b/clang/test/Preprocessor/include-leading-double-backslash.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 %s -verify -I %S/Inputs
+// REQUIRES: system-windows
+
+#include "\\leading-double-slash.h" // expected-error 
{{'\\leading-double-slash.h' file not found}}
diff --git a/clang/test/Preprocessor/include-leading-double-slash.c 
b/clang/test/Preprocessor/include-leading-double-slash.c
new file mode 100644
index 0000000000000..aa6b9af200270
--- /dev/null
+++ b/clang/test/Preprocessor/include-leading-double-slash.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 %s -verify -I %S/Inputs
+
+#include "//leading-double-slash.h" // expected-error 
{{'//leading-double-slash.h' file not found}}

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

Reply via email to