[PATCH] D152269: [StaticAnalyzer] Fix false negative on NilArgChecker when creating literal object

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 6 07:35:09 PDT 2023


steakhal added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp:151-164
+  auto ArgSVal = C.getSVal(E).getAs<DefinedOrUnknownSVal>();
+  if (!ArgSVal)
+    return;
+
+  ProgramStateRef StNonNull, StNull;
+  std::tie(StNonNull, StNull) = State->assume(*ArgSVal);
+
----------------
This means that we would raise an issue if `ArgSVal` might be null. We usually warn if we are sure there is a bug, aka. if it must be null. Consequently, the condition should be rather `StNull && !StNonNull` instead of just `StNull`.


================
Comment at: clang/test/Analysis/NSContainers.m:336-337
+void testCreateArrayLiteralWithNullableArg() {
+  (void)@[getNonnullFoo()]; // no warning
+  (void)@[getNullableFoo()]; // expected-warning {{Nullable pointer is passed to a callee that requires a non-null}}
+}
----------------
How about the case when it calls a `Foo * getMightBeNullFoo();`? I guess, it would still raise an issue, even though we couldn't prove that it must be null.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152269/new/

https://reviews.llvm.org/D152269



More information about the cfe-commits mailing list