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

2023-05-15 Thread Michael Klein via Phabricator via cfe-commits
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


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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-05-16 Thread Michael Klein via Phabricator via cfe-commits
mkmvzlb added a comment.

In D150552#4345391 , @steakhal wrote:

> Thanks for the patch. Should I commit this on your behalf?

Thanks for reviewing and - in advance - for commit: --author "Michael Klein 
"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150552

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits