summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2016-01-06 00:32:56 +0000
committerAnna Zaks <ganna@apple.com>2016-01-06 00:32:56 +0000
commit03f483353c768409e8ef4d19c5536bb7bcd3c1d7 (patch)
tree8a3defd1f537ff2d2a733ad5e968414f6b5b3995
parentac4c8a639cda8bc98dfb7f97f6e056db0ffeab59 (diff)
downloadbcm5719-llvm-03f483353c768409e8ef4d19c5536bb7bcd3c1d7.tar.gz
bcm5719-llvm-03f483353c768409e8ef4d19c5536bb7bcd3c1d7.zip
[analyzer] Fix false warning about memory leak for QApplication::postEvent
According to Qt documentation Qt takes care of memory allocated for QEvent: http://doc.qt.io/qt-4.8/qcoreapplication.html#postEvent A patch by Evgeniy Dushistov! Differential Revision: http://reviews.llvm.org/D14170 llvm-svn: 256887
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp10
-rw-r--r--clang/test/Analysis/Inputs/qt-simulator.h16
-rw-r--r--clang/test/Analysis/qt_malloc.cpp15
3 files changed, 41 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 713d9fe285a..ce2c19409dc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2508,6 +2508,16 @@ bool MallocChecker::mayFreeAnyEscapedMemoryOrIsModeledExplicitly(
return true;
}
+ if (FName == "postEvent" &&
+ FD->getQualifiedNameAsString() == "QCoreApplication::postEvent") {
+ 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
diff --git a/clang/test/Analysis/Inputs/qt-simulator.h b/clang/test/Analysis/Inputs/qt-simulator.h
new file mode 100644
index 00000000000..d1d6c0356b7
--- /dev/null
+++ b/clang/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 {};
diff --git a/clang/test/Analysis/qt_malloc.cpp b/clang/test/Analysis/qt_malloc.cpp
new file mode 100644
index 00000000000..d29835f73fa
--- /dev/null
+++ b/clang/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);
+}
OpenPOWER on IntegriCloud