[PATCH] D150552: [analyzer] Fix QTimer::singleShot NewDeleteLeaks false positive

Michael Klein via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 15 02:50:25 PDT 2023


mkmvzlb created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mkmvzlb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes #39713


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150552

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/Inputs/qt-simulator.h
  clang/test/Analysis/qt_malloc.cpp


Index: clang/test/Analysis/qt_malloc.cpp
===================================================================
--- clang/test/Analysis/qt_malloc.cpp
+++ clang/test/Analysis/qt_malloc.cpp
@@ -19,3 +19,8 @@
                    new QtPrivate::QSlotObjectBase(), (Qt::ConnectionType)0,
                    nullptr, nullptr);
 }
+
+void singleShot(QTimer *timer) {
+  timer->singleShotImpl(0, (Qt::TimerType)0, nullptr,
+                        new QtPrivate::QSlotObjectBase());
+}
Index: clang/test/Analysis/Inputs/qt-simulator.h
===================================================================
--- clang/test/Analysis/Inputs/qt-simulator.h
+++ clang/test/Analysis/Inputs/qt-simulator.h
@@ -6,6 +6,7 @@
 
 namespace Qt {
 enum ConnectionType {};
+enum TimerType {};
 }
 
 struct QMetaObject {
@@ -31,3 +32,8 @@
 };
 
 struct QApplication : public QCoreApplication {};
+
+struct QTimer {
+  static void singleShotImpl(int, Qt::TimerType, const QObject *,
+                             QtPrivate::QSlotObjectBase *);
+};
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -3259,6 +3259,11 @@
     return true;
   }
 
+  if (FName == "singleShotImpl" &&
+      FD->getQualifiedNameAsString() == "QTimer::singleShotImpl") {
+    return true;
+  }
+
   // Handle cases where we know a buffer's /address/ can escape.
   // Note that the above checks handle some special cases where we know that
   // even though the address escapes, it's still our responsibility to free the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150552.522101.patch
Type: text/x-patch
Size: 1659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230515/d8ed73bf/attachment.bin>


More information about the cfe-commits mailing list