This patch optimizes code in NDEBUG mode based on the conditions
that the program asserts. This patch, in other words, allows a
function like this
#include <assert.h>
#define NDEBUG
int f(char *x)
{
assert (x != NULL);
return x ? *x : 0;
}
to be compiled simply as
movl 4(%esp), %eax
movsbl (%eax), %eax
ret
The trick is to have assert invoke a const/noreturn function (returning
void) in NDEBUG mode, and to remove such invocations in ifcvt. I see
that this may likely not be the best way, hence the RFC. To link
this to assert, there will be a GCC-specific assert.h like
#ifndef __GCC_ASSERT_H
#define __GCC_ASSERT_H
#include_next <assert.h>
#if defined __OPTIMIZE__ && defined NDEBUG
#undef assert
extern void __gcc_verify (void) __attribute__ ((__const__,
__noreturn__));
#define assert(expr) ((void) ((expr) ? 0 : (__gcc_verify(), 0)))
#endif
#endif