[clang] [analyzer][NFC] Skip NumberObjectConversionChecker in TUs without number objects (PR #246446)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 26 09:54:27 PST 2026


================
@@ -345,6 +345,17 @@ NumberObjectConversionChecker::NumberObjectConversionChecker()
 void NumberObjectConversionChecker::checkASTCodeBody(const Decl *D,
                                                      AnalysisManager &AM,
                                                      BugReporter &BR) const {
+  // Every match involves a declaration with one of these names, so there is
+  // nothing to match if the translation unit has no such identifier.
+  // is_contained uses find, so the lookups do not create the identifiers.
+  static constexpr llvm::StringLiteral Names[] = {
+      "CFNumberRef", "CFBooleanRef", "OSBoolean", "OSNumber", "NSNumber"};
+  const IdentifierTable &Idents = AM.getASTContext().Idents;
+  if (llvm::none_of(Names, [&Idents](StringRef Name) {
+        return llvm::is_contained(Idents, Name);
+      }))
+    return;
----------------
steakhal wrote:

I hate when this looks so jagged. Either hoist the lambda to make the condition fit on a single line - or use braces.  Personally, I'd prefer hoisting the lambda.
```suggestion
      })) {
    return;
  }
```

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


More information about the cfe-commits mailing list