[clang] [clang-tools-extra] [clang-tidy] `bugprone-unchecked-optional-access`: handle `BloombergLP::bdlb:NullableValue::makeValue` to prevent false-positives (PR #144313)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 14 01:47:14 PDT 2025


================
@@ -985,6 +985,20 @@ auto buildTransferMatchSwitch() {
           isOptionalMemberCallWithNameMatcher(hasName("isNull")),
           transferOptionalIsNullCall)
 
+      // NullableValue::makeValue, NullableValue::makeValueInplace
+      // Only NullableValue has these methods, but this
+      // will also pass for other types
+      .CaseOfCFGStmt<CXXMemberCallExpr>(
+          isOptionalMemberCallWithNameMatcher(
+              hasAnyName("makeValue", "makeValueInplace")),
+          [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
+             LatticeTransferState &State) {
+            if (RecordStorageLocation *Loc =
+                    getImplicitObjectLocation(*E, State.Env)) {
+              setHasValue(*Loc, State.Env.getBoolLiteralValue(true), State.Env);
+            }
+          })
+
----------------
Xazax-hun wrote:

I'll defer to @ymand on the final decision what is the best way to do this. But in my opinion, this make a strong argument that the analysis instance should always be created by the client (e.g., we should pass the analysis instance to `diagnoseFunction` and similar) as all analyses might need different configuration options and we definitely don't want to deal with all that in a generic way in the framework. 

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


More information about the cfe-commits mailing list