[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)

Vadim D. via cfe-commits cfe-commits at lists.llvm.org
Fri May 10 16:50:06 PDT 2024


================
@@ -572,32 +572,43 @@ struct FragmentCompiler {
 #else
     static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
 #endif
-    auto Filters = std::make_shared<std::vector<llvm::Regex>>();
-    for (auto &HeaderPattern : F.IgnoreHeader) {
-      // Anchor on the right.
-      std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
-      llvm::Regex CompiledRegex(AnchoredPattern, Flags);
-      std::string RegexError;
-      if (!CompiledRegex.isValid(RegexError)) {
-        diag(Warning,
-             llvm::formatv("Invalid regular expression '{0}': {1}",
-                           *HeaderPattern, RegexError)
-                 .str(),
-             HeaderPattern.Range);
-        continue;
+    std::shared_ptr<std::vector<llvm::Regex>> Filters;
+    if (!F.IgnoreHeader.empty()) {
----------------
vvd170501 wrote:

But then if `F.IgnoreHeader` is empty, we'll be allocating and deallocating an unneeded vector.

It's also possible to use `if (Filters->empty() && !AnalyzeSystemHeaders.has_value()) return;` and check `Filters->empty()`again  in line 601, but I wanted to remove the unneeded allocation.

https://github.com/llvm/llvm-project/pull/87208


More information about the cfe-commits mailing list