[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-04-22 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -454,52 +454,31 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  GlobList Globs(CheckGlob);
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
-Cur = Cur.trim();
-if (Cur.empty())
+  for (const auto  : Globs.getItems()) {
+const llvm::Regex  = Item.Regex;
+const llvm::StringRef Text = Item.Text;
+if (Text.starts_with("clang-diagnostic"))
   continue;
-Cur.consume_front("-");
-if (Cur.starts_with("clang-diagnostic"))
-  continue;
-if (Cur.contains('*')) {
-  SmallString<128> RegexText("^");
-  StringRef MetaChars("()^$|*+?.[]\\{}");
-  for (char C : Cur) {
-if (C == '*')
-  RegexText.push_back('.');
-else if (MetaChars.contains(C))
-  RegexText.push_back('\\');
-RegexText.push_back(C);
-  }
-  RegexText.push_back('$');
-  llvm::Regex Glob(RegexText);
-  std::string Error;
-  if (!Glob.isValid(Error)) {
-AnyInvalid = true;
-llvm::WithColor::error(llvm::errs(), Source)
-<< "building check glob '" << Cur << "' " << Error << "'\n";
-continue;
-  }
-  if (llvm::none_of(AllChecks.keys(),
-[](StringRef S) { return Glob.match(S); })) {
-AnyInvalid = true;
+if (llvm::none_of(AllChecks.keys(), [](StringRef S) {
+  llvm::errs() << S << '\n';
+  return Reg.match(S);
+})) {
+  AnyInvalid = true;
+  if (Item.Text.contains('*'))

PiotrZSL wrote:

This code is called only on --verify-config, performance is not a issue here.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-04-22 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-30 Thread Piotr Zegar via cfe-commits
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


https://github.com/PiotrZSL approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-29 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny edited 
https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-29 Thread Danny Mösch via cfe-commits


@@ -454,52 +454,31 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  GlobList Globs(CheckGlob);
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
-Cur = Cur.trim();
-if (Cur.empty())
+  for (const auto  : Globs.getItems()) {
+const llvm::Regex  = Item.Regex;
+const llvm::StringRef Text = Item.Text;
+if (Text.starts_with("clang-diagnostic"))
   continue;
-Cur.consume_front("-");
-if (Cur.starts_with("clang-diagnostic"))
-  continue;
-if (Cur.contains('*')) {
-  SmallString<128> RegexText("^");
-  StringRef MetaChars("()^$|*+?.[]\\{}");
-  for (char C : Cur) {
-if (C == '*')
-  RegexText.push_back('.');
-else if (MetaChars.contains(C))
-  RegexText.push_back('\\');
-RegexText.push_back(C);
-  }
-  RegexText.push_back('$');
-  llvm::Regex Glob(RegexText);
-  std::string Error;
-  if (!Glob.isValid(Error)) {
-AnyInvalid = true;
-llvm::WithColor::error(llvm::errs(), Source)
-<< "building check glob '" << Cur << "' " << Error << "'\n";
-continue;
-  }
-  if (llvm::none_of(AllChecks.keys(),
-[](StringRef S) { return Glob.match(S); })) {
-AnyInvalid = true;
+if (llvm::none_of(AllChecks.keys(), [](StringRef S) {
+  llvm::errs() << S << '\n';
+  return Reg.match(S);
+})) {
+  AnyInvalid = true;
+  if (Item.Text.contains('*'))

SimplyDanny wrote:

Fine for me. Yet, as I'm not that proficient with the detailed goals of the 
project, I'd like to ask @njames93 or @AaronBallman if this potentially slight 
performance decrease is acceptable.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-26 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/85591

From f015496c511b4c2898b9f4d65ebfe39a34c5119c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 17 Mar 2024 20:50:17 -0400
Subject: [PATCH 1/5] [clang-tidy] Improved --verify-config when using literal
 style in config file

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently
supported but was not implemented for the --verify-config options.
This means that clang-tidy would work properly but, using the --verify-config 
option
would raise an error due to some checks not being parsed properly.

Fixes #53737
---
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp  |  9 ++---
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 +++
 .../test/clang-tidy/infrastructure/verify-config.cpp | 12 
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 9f3d6b6db6cbca..b68a6215b383a6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;
+  llvm::StringRef Rest = CheckGlob;
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
+  while (!Cur.empty() || !Rest.empty()) {
+Cur = Rest.substr(0, Rest.find_first_of(",\n"));
+Rest = Rest.substr(Cur.size() + 1);
 Cur = Cur.trim();
+
 if (Cur.empty())
   continue;
 Cur.consume_front("-");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a604e9276668ae..3887384e713896 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -262,6 +262,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config
+
 Improvements to include-fixer
 -
 
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
index 421f8641281acb..3659285986482a 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
@@ -18,3 +18,15 @@
 // CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' 
doesn't match any known check [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'my-made-up-check' [-verify-config]
+
+// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n 
bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n 
readability-use-anyof*' > %T/MyClangTidyConfig
+// RUN: clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-OK
+// CHECK-VERIFY-BLOCK-OK: No config errors detected.
+
+// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n 
bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > 
%T/MyClangTidyConfigBad
+// RUN: not clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-BAD
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 
'bugprone-arguments-*' doesn't match any known check [-verify-config]
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown 
check 'bugprone-assert-side-effects'; did you mean 
'bugprone-assert-side-effect' [-verify-config]
+

From 0e2cb54934829f42069b06f599fa9e724bdf40b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sat, 23 Mar 2024 13:30:28 -0400
Subject: [PATCH 2/5] fixup! [clang-tidy] Improved --verify-config when using
 literal style in config file

Partially rewrote verifyChecks() to realign the checks parsing logic.

Instead of manually parsing the string of globs, verifyCHecks() now uses a 
GlobList which is responsible
to parse the string and return a list of regexes. This ensures that any changes 
made to the checks parsing logic
has to be made at only one place rather than two.
---
 clang-tools-extra/clang-tidy/GlobList.cpp | 14 ++--
 clang-tools-extra/clang-tidy/GlobList.h   |  4 ++
 .../clang-tidy/tool/ClangTidyMain.cpp 

[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-26 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 edited 
https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-26 Thread Félix-Antoine Constantin via cfe-commits


@@ -454,52 +454,31 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  GlobList Globs(CheckGlob);
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
-Cur = Cur.trim();
-if (Cur.empty())
+  for (const auto  : Globs.getItems()) {
+const llvm::Regex  = Item.Regex;
+const llvm::StringRef Text = Item.Text;
+if (Text.starts_with("clang-diagnostic"))
   continue;
-Cur.consume_front("-");
-if (Cur.starts_with("clang-diagnostic"))
-  continue;
-if (Cur.contains('*')) {
-  SmallString<128> RegexText("^");
-  StringRef MetaChars("()^$|*+?.[]\\{}");
-  for (char C : Cur) {
-if (C == '*')
-  RegexText.push_back('.');
-else if (MetaChars.contains(C))
-  RegexText.push_back('\\');
-RegexText.push_back(C);
-  }
-  RegexText.push_back('$');
-  llvm::Regex Glob(RegexText);
-  std::string Error;
-  if (!Glob.isValid(Error)) {
-AnyInvalid = true;
-llvm::WithColor::error(llvm::errs(), Source)
-<< "building check glob '" << Cur << "' " << Error << "'\n";
-continue;
-  }
-  if (llvm::none_of(AllChecks.keys(),
-[](StringRef S) { return Glob.match(S); })) {
-AnyInvalid = true;
+if (llvm::none_of(AllChecks.keys(), [](StringRef S) {
+  llvm::errs() << S << '\n';
+  return Reg.match(S);
+})) {
+  AnyInvalid = true;
+  if (Item.Text.contains('*'))

felix642 wrote:

You are right, I've changed slightly this function's semantics, but it 
shouldn't have any observable behaviour change for the end user.
Before my change, we would only create a regex and try to match it if the 
string contains any '*' character. But, since the GlobList implicitly generates 
a list of Regexes we always try to match the strings through regexp now. This 
won't make a difference since the generated regex will only match the exact 
string if it doesn't contain any '*', but it will be a bit less efficient since 
we are going through pattern matching rather than string comparison.

I've moved the condition with the '*' character at the of the method to 
preserve the error message that is displayed to the user in case we can't find 
any matching check. (Either with "check glob ... doesn't match" if it contains 
a '*' or "unknown check ..." if it doesn't). 

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-26 Thread Félix-Antoine Constantin via cfe-commits


@@ -454,52 +454,31 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  GlobList Globs(CheckGlob);
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
-Cur = Cur.trim();
-if (Cur.empty())
+  for (const auto  : Globs.getItems()) {
+const llvm::Regex  = Item.Regex;
+const llvm::StringRef Text = Item.Text;
+if (Text.starts_with("clang-diagnostic"))
   continue;
-Cur.consume_front("-");
-if (Cur.starts_with("clang-diagnostic"))
-  continue;
-if (Cur.contains('*')) {
-  SmallString<128> RegexText("^");
-  StringRef MetaChars("()^$|*+?.[]\\{}");
-  for (char C : Cur) {
-if (C == '*')
-  RegexText.push_back('.');
-else if (MetaChars.contains(C))
-  RegexText.push_back('\\');
-RegexText.push_back(C);
-  }
-  RegexText.push_back('$');
-  llvm::Regex Glob(RegexText);
-  std::string Error;
-  if (!Glob.isValid(Error)) {
-AnyInvalid = true;
-llvm::WithColor::error(llvm::errs(), Source)
-<< "building check glob '" << Cur << "' " << Error << "'\n";
-continue;
-  }
-  if (llvm::none_of(AllChecks.keys(),
-[](StringRef S) { return Glob.match(S); })) {
-AnyInvalid = true;
+if (llvm::none_of(AllChecks.keys(), [](StringRef S) {
+  llvm::errs() << S << '\n';

felix642 wrote:

No, I forgot to remove this print before committing, it should be fixed now. 
Thank you 

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-26 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/85591

From f015496c511b4c2898b9f4d65ebfe39a34c5119c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 17 Mar 2024 20:50:17 -0400
Subject: [PATCH 1/4] [clang-tidy] Improved --verify-config when using literal
 style in config file

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently
supported but was not implemented for the --verify-config options.
This means that clang-tidy would work properly but, using the --verify-config 
option
would raise an error due to some checks not being parsed properly.

Fixes #53737
---
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp  |  9 ++---
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 +++
 .../test/clang-tidy/infrastructure/verify-config.cpp | 12 
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 9f3d6b6db6cbca..b68a6215b383a6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;
+  llvm::StringRef Rest = CheckGlob;
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
+  while (!Cur.empty() || !Rest.empty()) {
+Cur = Rest.substr(0, Rest.find_first_of(",\n"));
+Rest = Rest.substr(Cur.size() + 1);
 Cur = Cur.trim();
+
 if (Cur.empty())
   continue;
 Cur.consume_front("-");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a604e9276668ae..3887384e713896 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -262,6 +262,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config
+
 Improvements to include-fixer
 -
 
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
index 421f8641281acb..3659285986482a 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
@@ -18,3 +18,15 @@
 // CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' 
doesn't match any known check [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'my-made-up-check' [-verify-config]
+
+// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n 
bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n 
readability-use-anyof*' > %T/MyClangTidyConfig
+// RUN: clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-OK
+// CHECK-VERIFY-BLOCK-OK: No config errors detected.
+
+// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n 
bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > 
%T/MyClangTidyConfigBad
+// RUN: not clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-BAD
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 
'bugprone-arguments-*' doesn't match any known check [-verify-config]
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown 
check 'bugprone-assert-side-effects'; did you mean 
'bugprone-assert-side-effect' [-verify-config]
+

From 0e2cb54934829f42069b06f599fa9e724bdf40b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sat, 23 Mar 2024 13:30:28 -0400
Subject: [PATCH 2/4] fixup! [clang-tidy] Improved --verify-config when using
 literal style in config file

Partially rewrote verifyChecks() to realign the checks parsing logic.

Instead of manually parsing the string of globs, verifyCHecks() now uses a 
GlobList which is responsible
to parse the string and return a list of regexes. This ensures that any changes 
made to the checks parsing logic
has to be made at only one place rather than two.
---
 clang-tools-extra/clang-tidy/GlobList.cpp | 14 ++--
 clang-tools-extra/clang-tidy/GlobList.h   |  4 ++
 .../clang-tidy/tool/ClangTidyMain.cpp 

[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-24 Thread Danny Mösch via cfe-commits


@@ -454,52 +454,31 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  GlobList Globs(CheckGlob);
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
-Cur = Cur.trim();
-if (Cur.empty())
+  for (const auto  : Globs.getItems()) {
+const llvm::Regex  = Item.Regex;
+const llvm::StringRef Text = Item.Text;

SimplyDanny wrote:

Fine from my point of view to inline both of these variables as it doesn't 
improve much to have them. If you insist to keep them, use them wherever 
`Item.` appears.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-24 Thread Danny Mösch via cfe-commits


@@ -454,52 +454,31 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  GlobList Globs(CheckGlob);
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
-Cur = Cur.trim();
-if (Cur.empty())
+  for (const auto  : Globs.getItems()) {
+const llvm::Regex  = Item.Regex;
+const llvm::StringRef Text = Item.Text;
+if (Text.starts_with("clang-diagnostic"))
   continue;
-Cur.consume_front("-");
-if (Cur.starts_with("clang-diagnostic"))
-  continue;
-if (Cur.contains('*')) {
-  SmallString<128> RegexText("^");
-  StringRef MetaChars("()^$|*+?.[]\\{}");
-  for (char C : Cur) {
-if (C == '*')
-  RegexText.push_back('.');
-else if (MetaChars.contains(C))
-  RegexText.push_back('\\');
-RegexText.push_back(C);
-  }
-  RegexText.push_back('$');
-  llvm::Regex Glob(RegexText);
-  std::string Error;
-  if (!Glob.isValid(Error)) {
-AnyInvalid = true;
-llvm::WithColor::error(llvm::errs(), Source)
-<< "building check glob '" << Cur << "' " << Error << "'\n";
-continue;
-  }
-  if (llvm::none_of(AllChecks.keys(),
-[](StringRef S) { return Glob.match(S); })) {
-AnyInvalid = true;
+if (llvm::none_of(AllChecks.keys(), [](StringRef S) {
+  llvm::errs() << S << '\n';
+  return Reg.match(S);
+})) {
+  AnyInvalid = true;
+  if (Item.Text.contains('*'))

SimplyDanny wrote:

Previously this came before the checks for matches in line 466. Seems like the 
semantic has so changed slightly if only performance-wise, hasn't it?

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-24 Thread Danny Mösch via cfe-commits


@@ -454,52 +454,31 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  GlobList Globs(CheckGlob);
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
-Cur = Cur.trim();
-if (Cur.empty())
+  for (const auto  : Globs.getItems()) {
+const llvm::Regex  = Item.Regex;
+const llvm::StringRef Text = Item.Text;
+if (Text.starts_with("clang-diagnostic"))
   continue;
-Cur.consume_front("-");
-if (Cur.starts_with("clang-diagnostic"))
-  continue;
-if (Cur.contains('*')) {
-  SmallString<128> RegexText("^");
-  StringRef MetaChars("()^$|*+?.[]\\{}");
-  for (char C : Cur) {
-if (C == '*')
-  RegexText.push_back('.');
-else if (MetaChars.contains(C))
-  RegexText.push_back('\\');
-RegexText.push_back(C);
-  }
-  RegexText.push_back('$');
-  llvm::Regex Glob(RegexText);
-  std::string Error;
-  if (!Glob.isValid(Error)) {
-AnyInvalid = true;
-llvm::WithColor::error(llvm::errs(), Source)
-<< "building check glob '" << Cur << "' " << Error << "'\n";
-continue;
-  }
-  if (llvm::none_of(AllChecks.keys(),
-[](StringRef S) { return Glob.match(S); })) {
-AnyInvalid = true;
+if (llvm::none_of(AllChecks.keys(), [](StringRef S) {
+  llvm::errs() << S << '\n';

SimplyDanny wrote:

Is this output intended?

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-24 Thread Danny Mösch via cfe-commits


@@ -19,12 +19,17 @@ static bool consumeNegativeIndicator(StringRef ) {
   return GlobList.consume_front("-");
 }
 
-// Converts first glob from the comma-separated list of globs to Regex and
-// removes it and the trailing comma from the GlobList.
-static llvm::Regex consumeGlob(StringRef ) {
+// Extract the first glob from the comma-separated list of globs

SimplyDanny wrote:

```suggestion
// Extracts the first glob from the comma-separated list of globs,
```

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-23 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -262,6 +262,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config.

PiotrZSL wrote:

I think this should be in line 103.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-23 Thread Félix-Antoine Constantin via cfe-commits

felix642 wrote:

Thank you for the review @SimplyDanny, as per your suggestion, I've rewrote 
part of my fix to unify the parsing logic rather than updating the duplicated 
code. The method now uses the GlobList which already handles correctly the 
regexes generation from the list of checks.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-23 Thread via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-23 Thread via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-23 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/85591

From f015496c511b4c2898b9f4d65ebfe39a34c5119c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 17 Mar 2024 20:50:17 -0400
Subject: [PATCH 1/3] [clang-tidy] Improved --verify-config when using literal
 style in config file

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently
supported but was not implemented for the --verify-config options.
This means that clang-tidy would work properly but, using the --verify-config 
option
would raise an error due to some checks not being parsed properly.

Fixes #53737
---
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp  |  9 ++---
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 +++
 .../test/clang-tidy/infrastructure/verify-config.cpp | 12 
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 9f3d6b6db6cbca..b68a6215b383a6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;
+  llvm::StringRef Rest = CheckGlob;
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
+  while (!Cur.empty() || !Rest.empty()) {
+Cur = Rest.substr(0, Rest.find_first_of(",\n"));
+Rest = Rest.substr(Cur.size() + 1);
 Cur = Cur.trim();
+
 if (Cur.empty())
   continue;
 Cur.consume_front("-");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a604e9276668ae..3887384e713896 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -262,6 +262,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config
+
 Improvements to include-fixer
 -
 
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
index 421f8641281acb..3659285986482a 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
@@ -18,3 +18,15 @@
 // CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' 
doesn't match any known check [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'my-made-up-check' [-verify-config]
+
+// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n 
bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n 
readability-use-anyof*' > %T/MyClangTidyConfig
+// RUN: clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-OK
+// CHECK-VERIFY-BLOCK-OK: No config errors detected.
+
+// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n 
bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > 
%T/MyClangTidyConfigBad
+// RUN: not clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-BAD
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 
'bugprone-arguments-*' doesn't match any known check [-verify-config]
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown 
check 'bugprone-assert-side-effects'; did you mean 
'bugprone-assert-side-effect' [-verify-config]
+

From 0e2cb54934829f42069b06f599fa9e724bdf40b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sat, 23 Mar 2024 13:30:28 -0400
Subject: [PATCH 2/3] fixup! [clang-tidy] Improved --verify-config when using
 literal style in config file

Partially rewrote verifyChecks() to realign the checks parsing logic.

Instead of manually parsing the string of globs, verifyCHecks() now uses a 
GlobList which is responsible
to parse the string and return a list of regexes. This ensures that any changes 
made to the checks parsing logic
has to be made at only one place rather than two.
---
 clang-tools-extra/clang-tidy/GlobList.cpp | 14 ++--
 clang-tools-extra/clang-tidy/GlobList.h   |  4 ++
 .../clang-tidy/tool/ClangTidyMain.cpp 

[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-18 Thread Danny Mösch via cfe-commits


@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;

SimplyDanny wrote:

Should be empty at first.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-18 Thread Danny Mösch via cfe-commits


@@ -251,6 +251,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config

SimplyDanny wrote:

```suggestion
  literal operator in the ``.clang-tidy`` config.
```

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny approved this pull request.

Seems like the parsing logic got duplicated. That eventually caused the 
misbehavior in verification. Alignment would be preferred.

From my point of view, the fix is okay for now though.

https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-18 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny edited 
https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Félix-Antoine Constantin (felix642)


Changes

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently supported but was not implemented for the --verify-config options. 
This means that clang-tidy would work properly but, using the --verify-config 
option would raise an error due to some checks not being parsed properly.

Fixes #53737

CC @SimplyDanny 

---
Full diff: https://github.com/llvm/llvm-project/pull/85591.diff


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp (+6-3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3) 
- (modified) clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
(+12) 


``diff
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 9f3d6b6db6cbca..b68a6215b383a6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;
+  llvm::StringRef Rest = CheckGlob;
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
+  while (!Cur.empty() || !Rest.empty()) {
+Cur = Rest.substr(0, Rest.find_first_of(",\n"));
+Rest = Rest.substr(Cur.size() + 1);
 Cur = Cur.trim();
+
 if (Cur.empty())
   continue;
 Cur.consume_front("-");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44680f79de6f54..a699aa9aadd908 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -251,6 +251,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config
+
 Improvements to include-fixer
 -
 
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
index 421f8641281acb..3659285986482a 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
@@ -18,3 +18,15 @@
 // CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' 
doesn't match any known check [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'my-made-up-check' [-verify-config]
+
+// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n 
bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n 
readability-use-anyof*' > %T/MyClangTidyConfig
+// RUN: clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-OK
+// CHECK-VERIFY-BLOCK-OK: No config errors detected.
+
+// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n 
bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > 
%T/MyClangTidyConfigBad
+// RUN: not clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-BAD
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 
'bugprone-arguments-*' doesn't match any known check [-verify-config]
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown 
check 'bugprone-assert-side-effects'; did you mean 
'bugprone-assert-side-effect' [-verify-config]
+

``




https://github.com/llvm/llvm-project/pull/85591
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-17 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 created 
https://github.com/llvm/llvm-project/pull/85591

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently supported but was not implemented for the --verify-config options. 
This means that clang-tidy would work properly but, using the --verify-config 
option would raise an error due to some checks not being parsed properly.

Fixes #53737

CC @SimplyDanny 

From 2ada09c8e10ecd05e3881995e96cfc2070331f05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 17 Mar 2024 20:50:17 -0400
Subject: [PATCH] [clang-tidy] Improved --verify-config when using literal
 style in config file

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently
supported but was not implemented for the --verify-config options.
This means that clang-tidy would work properly but, using the --verify-config 
option
would raise an error due to some checks not being parsed properly.

Fixes #53737
---
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp  |  9 ++---
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 +++
 .../test/clang-tidy/infrastructure/verify-config.cpp | 12 
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 9f3d6b6db6cbca..b68a6215b383a6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;
+  llvm::StringRef Rest = CheckGlob;
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
+  while (!Cur.empty() || !Rest.empty()) {
+Cur = Rest.substr(0, Rest.find_first_of(",\n"));
+Rest = Rest.substr(Cur.size() + 1);
 Cur = Cur.trim();
+
 if (Cur.empty())
   continue;
 Cur.consume_front("-");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44680f79de6f54..a699aa9aadd908 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -251,6 +251,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config
+
 Improvements to include-fixer
 -
 
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
index 421f8641281acb..3659285986482a 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
@@ -18,3 +18,15 @@
 // CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' 
doesn't match any known check [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'my-made-up-check' [-verify-config]
+
+// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n 
bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n 
readability-use-anyof*' > %T/MyClangTidyConfig
+// RUN: clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-OK
+// CHECK-VERIFY-BLOCK-OK: No config errors detected.
+
+// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n 
bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > 
%T/MyClangTidyConfigBad
+// RUN: not clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-BAD
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 
'bugprone-arguments-*' doesn't match any known check [-verify-config]
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown 
check 'bugprone-assert-side-effects'; did you mean 
'bugprone-assert-side-effect' [-verify-config]
+

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits