[PATCH] D14170: Fix false positive warning about memory leak for QApplication::postEvent
Evgeniy Dushistov via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 18 19:18:17 PST 2015
Dushistov updated this revision to Diff 40596.
Dushistov added a comment.
Make test for usage of different variants of postEvent more robust.
http://reviews.llvm.org/D14170
Files:
lib/StaticAnalyzer/Checkers/MallocChecker.cpp
test/Analysis/Inputs/qt-simulator.h
test/Analysis/qt_malloc.cpp
Index: test/Analysis/qt_malloc.cpp
===================================================================
--- /dev/null
+++ test/Analysis/qt_malloc.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus -analyzer-store=region -verify %s
+// expected-no-diagnostics
+#include "Inputs/qt-simulator.h"
+
+void send(QObject *obj)
+{
+ QEvent *e1 = new QEvent(QEvent::None);
+ static_cast<QApplication *>(QCoreApplication::instance())->postEvent(obj, e1);
+ QEvent *e2 = new QEvent(QEvent::None);
+ QCoreApplication::instance()->postEvent(obj, e2);
+ QEvent *e3 = new QEvent(QEvent::None);
+ QCoreApplication::postEvent(obj, e3);
+ QEvent *e4 = new QEvent(QEvent::None);
+ QApplication::postEvent(obj, e4);
+}
Index: test/Analysis/Inputs/qt-simulator.h
===================================================================
--- /dev/null
+++ test/Analysis/Inputs/qt-simulator.h
@@ -0,0 +1,16 @@
+#pragma clang system_header
+
+struct QObject {
+};
+
+struct QEvent {
+ enum Type { None };
+ QEvent(Type) {}
+};
+
+struct QCoreApplication : public QObject {
+ static void postEvent(QObject *receiver, QEvent *event);
+ static QCoreApplication *instance();
+};
+
+struct QApplication : public QCoreApplication {};
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2511,6 +2511,11 @@
return true;
}
+ if (FName == "postEvent" &&
+ FD->getQualifiedNameAsString() == "QCoreApplication::postEvent") {
+ 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: D14170.40596.patch
Type: text/x-patch
Size: 1928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151119/9e97e7ae/attachment-0001.bin>
More information about the cfe-commits
mailing list