[clang] [NFC][analyzer] Use `CheckerBase::getName` in checker option handling (PR #131612)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 17 06:44:47 PDT 2025


================
@@ -74,21 +64,6 @@ TEST(StaticAnalyzerOptions, SearchInParentPackageTests) {
 TEST(StaticAnalyzerOptions, StringOptions) {
   AnalyzerOptions Opts;
   Opts.Config["Outer.Inner.CheckerOne:Option"] = "StringValue";
-
-  struct CheckerOneMock : CheckerBase {
-    StringRef getTagDescription() const override {
-      return "Outer.Inner.CheckerOne";
-    }
-  };
-
-  CheckerOneMock CheckerOne;
-  EXPECT_TRUE("StringValue" ==
-            Opts.getCheckerStringOption(&CheckerOne, "Option"));
-}
-
-TEST(StaticAnalyzerOptions, SubCheckerOptions) {
-  AnalyzerOptions Opts;
-  Opts.Config["Outer.Inner.CheckerOne:Option"] = "StringValue";
----------------
NagyDonat wrote:

The methods  `getChecker*Option`  are overloaded: their first argument can be either a `CheckerBase *` or a `StringRef` (a checker name). Historically the variant that takes a `CheckerBase *` was introduced first, and then commit 088b1c9cdcdb3d83fa730c1fcbae6db8252fe76d introduced the variant that takes a `StringRef` to support checkers with multiple parts.

This test file originally introduced mock checkers to validate the correctness of the logic; then later commit 088b1c9cdcdb3d83fa730c1fcbae6db8252fe76d introduced the case `SubCheckerOptions` to test that names passed as strings are also tested correctly.

This commit replaces the mock checkers with directly passed checker names because we cannot define mock checkers that return arbitrary values from `CheckerBase::getName()`. (Previously it was possible to just override `getTagDescription()` because it's a virtual method, but `getName()` has no reason to be virtual, and its return value cannot be easily manipulated due to strict access control and strong typing around checker name handling.)

However, the connection between the two variants of the methods `getChecker*Option` is _very_ trivial (if they get a checker pointer, they invoke `getName` and call the other overload), so I think it's acceptable that we no longer test differences between them.

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


More information about the cfe-commits mailing list