https://github.com/unterumarmung updated 
https://github.com/llvm/llvm-project/pull/189364

>From 0e566eeb5ce357901910b2834d5c01ef052d7cf8 Mon Sep 17 00:00:00 2001
From: Daniil Dudkin <[email protected]>
Date: Mon, 30 Mar 2026 14:24:55 +0300
Subject: [PATCH] [include-cleaner][NFC] expose and test `norlmalizePath`

Also fixes a bug where the root `/` path would become an empty string.
---
 clang-tools-extra/include-cleaner/lib/Types.cpp  |  4 +---
 .../include-cleaner/lib/TypesInternal.h          |  2 ++
 .../include-cleaner/unittests/TypesTest.cpp      | 16 +++++++++++++++-
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/include-cleaner/lib/Types.cpp 
b/clang-tools-extra/include-cleaner/lib/Types.cpp
index 7a637639edf8b..d7635c258e522 100644
--- a/clang-tools-extra/include-cleaner/lib/Types.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -100,14 +100,12 @@ std::string Include::quote() const {
       .str();
 }
 
-static llvm::SmallString<128> normalizePath(llvm::StringRef Path) {
+llvm::SmallString<128> normalizePath(llvm::StringRef Path) {
   namespace path = llvm::sys::path;
 
   llvm::SmallString<128> P = Path;
   path::remove_dots(P, /*remove_dot_dot=*/true);
   path::native(P, path::Style::posix);
-  while (!P.empty() && P.back() == '/')
-    P.pop_back();
   return P;
 }
 
diff --git a/clang-tools-extra/include-cleaner/lib/TypesInternal.h 
b/clang-tools-extra/include-cleaner/lib/TypesInternal.h
index 0bd2766c900ab..60c28956c13c9 100644
--- a/clang-tools-extra/include-cleaner/lib/TypesInternal.h
+++ b/clang-tools-extra/include-cleaner/lib/TypesInternal.h
@@ -96,6 +96,8 @@ template <typename T> struct Hinted : public T {
   }
 };
 
+llvm::SmallString<128> normalizePath(llvm::StringRef Path);
+
 } // namespace clang::include_cleaner
 
 #endif
diff --git a/clang-tools-extra/include-cleaner/unittests/TypesTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
index 609563da488e3..cdc719d620b4c 100644
--- a/clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
@@ -1,4 +1,4 @@
-//===-- RecordTest.cpp 
----------------------------------------------------===//
+//===-- TypesTest.cpp 
-----------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,6 +7,7 @@
 
//===----------------------------------------------------------------------===//
 
 #include "clang-include-cleaner/Types.h"
+#include "TypesInternal.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemOptions.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
@@ -98,5 +99,18 @@ TEST(RecordedIncludesTest, 
MatchVerbatimMixedAbsoluteRelative) {
   EXPECT_THAT(Inc.match(Header("<bar.h>")), IsEmpty());
 }
 
+TEST(NormalizePathTest, RemovesDotSegments) {
+  EXPECT_EQ(normalizePath("foo/./bar/../baz").str(), "foo/baz");
+  EXPECT_EQ(normalizePath("foo/bar/").str(), "foo/bar");
+}
+
+TEST(NormalizePathTest, CanonicalizesSeparators) {
+  EXPECT_EQ(normalizePath("foo\\bar").str(), "foo/bar");
+}
+
+TEST(NormalizePathTest, PreservesRootPath) {
+  EXPECT_EQ(normalizePath("/").str(), "/");
+}
+
 } // namespace
 } // namespace clang::include_cleaner

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

Reply via email to