Author: dergachev Date: Fri Dec 16 06:21:55 2016 New Revision: 289939 URL: http://llvm.org/viewvc/llvm-project?rev=289939&view=rev Log: [analyzer] Add another exception for Qt in MallocChecker
Treat pointers passed to QObject::connectImpl() as escaping. rdar://problem/29550440 Differential Revision: https://reviews.llvm.org/D27717 Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp cfe/trunk/test/Analysis/Inputs/qt-simulator.h cfe/trunk/test/Analysis/qt_malloc.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=289939&r1=289938&r2=289939&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Fri Dec 16 06:21:55 2016 @@ -2579,6 +2579,11 @@ bool MallocChecker::mayFreeAnyEscapedMem return true; } + if (FName == "connectImpl" && + FD->getQualifiedNameAsString() == "QObject::connectImpl") { + 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 Modified: cfe/trunk/test/Analysis/Inputs/qt-simulator.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/qt-simulator.h?rev=289939&r1=289938&r2=289939&view=diff ============================================================================== --- cfe/trunk/test/Analysis/Inputs/qt-simulator.h (original) +++ cfe/trunk/test/Analysis/Inputs/qt-simulator.h Fri Dec 16 06:21:55 2016 @@ -1,6 +1,23 @@ #pragma clang system_header +namespace QtPrivate { +struct QSlotObjectBase {}; +} + +namespace Qt { +enum ConnectionType {}; +} + +struct QMetaObject { + struct Connection {}; +}; + struct QObject { + static QMetaObject::Connection connectImpl(const QObject *, void **, + const QObject *, void **, + QtPrivate::QSlotObjectBase *, + Qt::ConnectionType, + const int *, const QMetaObject *); }; struct QEvent { Modified: cfe/trunk/test/Analysis/qt_malloc.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/qt_malloc.cpp?rev=289939&r1=289938&r2=289939&view=diff ============================================================================== --- cfe/trunk/test/Analysis/qt_malloc.cpp (original) +++ cfe/trunk/test/Analysis/qt_malloc.cpp Fri Dec 16 06:21:55 2016 @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus -analyzer-store=region -verify %s +// RUN: %clang_cc1 -std=c++11 -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" @@ -13,3 +13,9 @@ void send(QObject *obj) QEvent *e4 = new QEvent(QEvent::None); QApplication::postEvent(obj, e4); } + +void connect(QObject *obj) { + obj->connectImpl(nullptr, nullptr, nullptr, nullptr, + new QtPrivate::QSlotObjectBase(), (Qt::ConnectionType)0, + nullptr, nullptr); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits