[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 11 08:48:11 PDT 2024


=?utf-8?q?Kristóf?= Umann <dkszelethus at gmail.com>,
=?utf-8?q?Kristóf?= Umann <dkszelethus at gmail.com>,
=?utf-8?q?Kristóf?= Umann <dkszelethus at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/94957 at github.com>


================
@@ -696,6 +730,69 @@ struct StreamOperationEvaluator {
 
 } // end anonymous namespace
 
+//===----------------------------------------------------------------------===//
+// Definition of NoStreamStateChangeVisitor.
+//===----------------------------------------------------------------------===//
+
+namespace {
+class NoStreamStateChangeVisitor final : public NoOwnershipChangeVisitor {
+protected:
+  /// Syntactically checks whether the callee is a freeing function. Since
+  /// we have no path-sensitive information on this call (we would need a
+  /// CallEvent instead of a CallExpr for that), its possible that a
+  /// freeing function was called indirectly through a function pointer,
+  /// but we are not able to tell, so this is a best effort analysis.
+  bool isFreeingCallAsWritten(const CallExpr &Call) const {
+    const auto *StreamChk = static_cast<const StreamChecker *>(&Checker);
+    if (StreamChk->FCloseDesc.matchesAsWritten(Call))
+      return true;
+
+    return false;
----------------
steakhal wrote:

```suggestion
    return StreamChk->FCloseDesc.matchesAsWritten(Call));
```

But given the complexity of the `FCloseDesc` member, I'd simply suggest inlining here. That would enable us to omit the static cast that makes this a bit ugly.

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


More information about the cfe-commits mailing list