Vadim Markovtsev 323d4b6f68 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>
2014-01-15 07:32:52 +00:00
..
2010-12-06 12:05:11 +01:00
2013-09-30 18:42:13 -07:00
2014-01-03 15:58:40 -08:00
2014-01-10 15:32:31 -08:00
2013-08-13 14:30:59 -07:00
2014-01-09 12:37:12 -08:00
2011-09-28 12:17:34 -07:00
2014-01-09 15:45:07 -08:00
2010-01-15 15:57:02 -08:00
2012-09-13 16:54:57 -07:00
2009-03-03 19:28:35 -08:00
2009-03-03 19:28:35 -08:00
2010-01-15 15:01:44 -08:00
2014-01-09 13:54:49 -08:00
2010-06-11 14:39:39 -07:00
2012-09-04 14:11:28 +02:00