summaryrefslogtreecommitdiff
path: root/libc/tools/bionic_utils.py
diff options
context:
space:
mode:
authorVadim Markovtsev <gmarkhor@gmail.com>2014-01-13 11:54:42 +0400
committerVadim Markovtsev <gmarkhor@gmail.com>2014-01-15 07:32:52 +0000
commit323d4b6f6839b472ac02c31105727147660dc4db (patch)
treee5374de63274cd89e3bfcee3adfd4a0a3b89da00 /libc/tools/bionic_utils.py
parentae189740de6b03f06a06214122183a3774f5cb62 (diff)
Add "__noreturn" to assert and assert2
These functions should print assertion violation messages and then call abort(). They do really not return control flow afterwards. Consider the declaration of the similar __assert_fail from glibc: extern void __assert_fail (const char *__assertion, const char *__file, unsigned int __line, const char *__function) __THROW __attribute__ ((__noreturn__)); Bionic has __noreturn defined in sys/cdefs.h to be that GNU noreturn attribute. This patch has a practical value. Consider the following function: void check(void* ptr) { assert(ptr != NULL); } Without this patch applied, gcc (and presumably clang) shows even in debug mode: warning: unused parameter 'ptr' [-Wunused-parameter] In release mode, NDEBUG is defined and assert() becomes a no-op, as one should expect. Thus, the warning is shown correctly then. Another code sample: float array[2]; int i = 3; ... assert(i < 2); array[i] = 0; gcc says, warning: array subscript is below array bounds [-Warray-bounds] In other words, without noreturn attribute, assertions do not allow a compiler's static analyzer to properly understand the preconditions. Change-Id: I3be92e99787c528899cf243ed448c4730c00c45b Signed-off-by: Vadim Markovtsev <gmarkhor@gmail.com>
Diffstat (limited to 'libc/tools/bionic_utils.py')
0 files changed, 0 insertions, 0 deletions