Q_ASSERT and Clang static analyzer

Hi Jordan,

Qt has its own assertion facility which is apparently not recognized
by the static analyzer. Qt calls one of the following functions when
an assertion fails: qt_assert and qt_assert_x, qt_check_pointer,
qBadAlloc.

Do you think it is reasonable to add these to list in
NoReturnFunctionChecker.cpp?

Dmitri

I don't see those function names in a quick Google search. In particular, qt_check_pointer seems to be an opaque function called in the true case or the false case, which means simply pretending it's noreturn is the wrong thing to do. qtFatal seems like the normal assertion failure function. http://qt-project.org/doc/qt-5.1/qtcore/qtglobal.html#Q_ASSERT

Obviously, the best case is to get them to start using __attribute__((noreturn)) and/or __attribute__((analyzer_noreturn)). I can see adding qtFatal to the list, though, since Qt is a fairly widespread toolkit.

Jordan

Jordan Rose wrote:

Obviously, the best case is to get them to start using
__attribute__((noreturn)) and/or __attribute__((analyzer_noreturn)). I can
see adding qtFatal to the list, though, since Qt is a fairly widespread
toolkit.

qt_assert is already __attribute__((noreturn)).

#ifndef Q_CC_MSVC
Q_NORETURN
#endif
Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int
line) Q_DECL_NOTHROW;

Thanks,

Steve.

I don't see those function names in a quick Google search.

Seems like Google is doing typo correction which is not helpful in
this case. Here's a link:
http://qt.gitorious.org/qt/qtbase/blobs/stable/src/corelib/global/qglobal.h

In particular, qt_check_pointer seems to be an opaque function called in the true case or the false case,

I don't think so. See the Q_CHECK_PTR macro.

Dmitri

That's true. I missed the Q_NORETURN because it is on a separate
line. Sorry for the noise -- I will investigate more then.

Dmitri

Then...why isn't it working? Dmitri, if you have a test case, please file a Bugzilla report, I guess.

Jordan

OK, I found why. Because the noreturn attribute was added to the
declaration only in Qt 5. In Qt 4, which will be still relevant for
at least a few years from now, qt_assert is not marked with noreturn:

http://qt.gitorious.org/qt/qt/blobs/4.8/src/corelib/global/qglobal.h#line1815

Dmitri

Okay, seems reasonable to me.

Jordan

Jordan Rose wrote:

Obviously, the best case is to get them to start using
attribute((noreturn)) and/or attribute((analyzer_noreturn)). I can
see adding qtFatal to the list, though, since Qt is a fairly widespread
toolkit.

qt_assert is already attribute((noreturn)).

#ifndef Q_CC_MSVC
Q_NORETURN
#endif
Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int
line) Q_DECL_NOTHROW;

Then…why isn’t it working? Dmitri, if you have a test case, please file a Bugzilla report, I guess.

OK, I found why. Because the noreturn attribute was added to the
declaration only in Qt 5. In Qt 4, which will be still relevant for
at least a few years from now, qt_assert is not marked with noreturn:

http://qt.gitorious.org/qt/qt/blobs/4.8/src/corelib/global/qglobal.h#line1815

Okay, seems reasonable to me.

I am not very keen on modifying the analyzer code to support old versions of Qt…

(If you were to do this, please put in a comment stating that that is temporary and should be removed. )