[clang-tools-extra] [include-cleaner] Check emptiness instead of occurences (PR #79154)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 07:21:05 PST 2024


https://github.com/kadircet created https://github.com/llvm/llvm-project/pull/79154

Our internal integration relies on injecting some default values to ignore/keep
lists. That means we can have filters, despite of not having occurences for the
flag.


>From 8b90af32711a435eeb19fd93f5dfa0a6cf94ffc2 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya <kadircet at google.com>
Date: Tue, 23 Jan 2024 16:18:32 +0100
Subject: [PATCH] [include-cleaner] Check emptiness instead of occurences

---
 clang-tools-extra/include-cleaner/test/tool.cpp           | 8 ++++++++
 clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/include-cleaner/test/tool.cpp b/clang-tools-extra/include-cleaner/test/tool.cpp
index de47b2a3f3778c..2155eec189d186 100644
--- a/clang-tools-extra/include-cleaner/test/tool.cpp
+++ b/clang-tools-extra/include-cleaner/test/tool.cpp
@@ -22,10 +22,18 @@ int x = foo();
 // IGNORE2-NOT: - "foobar.h"
 //     IGNORE2: + "foo.h"
 
+//        RUN: clang-include-cleaner -print=changes %s --ignore-headers= -- -I%S/Inputs/ | FileCheck --allow-empty --check-prefix=IGNORE3 %s
+//    IGNORE3: - "foobar.h"
+//    IGNORE3: + "foo.h"
+
 //        RUN: clang-include-cleaner -print=changes %s --only-headers="foo\.h" -- -I%S/Inputs/ | FileCheck --match-full-lines --allow-empty --check-prefix=ONLY %s
 //   ONLY-NOT: - "foobar.h"
 //       ONLY: + "foo.h"
 
+//        RUN: clang-include-cleaner -print=changes %s --only-headers= -- -I%S/Inputs/ | FileCheck --allow-empty --check-prefix=ONLY2 %s
+//      ONLY2: - "foobar.h"
+//      ONLY2: + "foo.h"
+
 //        RUN: clang-include-cleaner -print %s -- -I%S/Inputs/ | FileCheck --match-full-lines --check-prefix=PRINT %s
 //      PRINT: #include "foo.h"
 //  PRINT-NOT: {{^}}#include "foobar.h"{{$}}
diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index 132ad25411509d..3bc449b0152bba 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -262,9 +262,9 @@ std::function<bool(llvm::StringRef)> headerFilter() {
     return nullptr;
 
   return [OnlyMatches, IgnoreMatches](llvm::StringRef Header) {
-    if (OnlyHeaders.getNumOccurrences() && !OnlyMatches(Header))
+    if (!OnlyHeaders.empty() && !OnlyMatches(Header))
       return true;
-    if (IgnoreHeaders.getNumOccurrences() && IgnoreMatches(Header))
+    if (!IgnoreHeaders.empty() && IgnoreMatches(Header))
       return true;
     return false;
   };



More information about the cfe-commits mailing list