[clang-tools-extra] [clang-tidy] Add llvm-regex check (PR #207407)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 19 05:37:38 PDT 2026
================
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "InvalidRegexPatternCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/Support/Regex.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::llvm_check {
+
+void InvalidRegexPatternCheck::registerMatchers(MatchFinder *Finder) {
+ // main matcher
+ auto IsConstllvmStringRef = qualType(
+ isConstQualified(), hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+ cxxRecordDecl(hasName("::llvm::StringRef"))))));
+ auto IsConstStdString = qualType(
+ isConstQualified(), hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+ cxxRecordDecl(hasName("::std::basic_string"))))));
+ auto GetStringLit = ignoringImplicit(stringLiteral().bind("stringLiteral"));
+ auto GetStringLiteralFromObject =
+ ignoringImplicit(cxxConstructExpr(hasAnyArgument(GetStringLit)));
+ auto IsConstCharPtr = pointerType(pointee(builtinType(), isConstQualified()));
+ auto IsCharArray = qualType(
+ hasUnqualifiedDesugaredType(arrayType(hasElementType(builtinType()))));
+ auto IsStdStringView = qualType(hasUnqualifiedDesugaredType(recordType(
+ hasDeclaration(cxxRecordDecl(hasName("::std::basic_string_view"))))));
+ auto AnyCastedToStringRef = ignoringImplicit(anyOf(
+ stringLiteral().bind("stringLiteral"),
+ declRefExpr(to(varDecl(
+ hasType(
+ qualType(anyOf(IsConstStdString, IsConstllvmStringRef,
+ IsStdStringView, IsConstCharPtr, IsCharArray))),
----------------
furtib wrote:
I think I have got rid of as much duplication as I could.
https://github.com/llvm/llvm-project/pull/207407
More information about the cfe-commits
mailing list