This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC/PATCH] Optimize code based on asserts even in NDEBUG mode
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: "Paolo Bonzini" <bonzini at gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Fri, 09 Apr 2004 14:03:57 +0200
- Subject: Re: [RFC/PATCH] Optimize code based on asserts even in NDEBUG mode
Paolo wrote:
> Is this crap?
I asked for a feature like this before, and I like the feature. But
there are problems with your implementation (as others pointed out).
First to just check for const and noreturn function attribute is asking
for trouble (as you're doing an invalid transformation).
Better invent a __builtin_assert() , or even a __builtin_gcc_assert()
which could have different semantics than C89 assert().
The whole point is to invent something that gcc can safely assume a
condition is true (or false) at the very end of optimization, so the
conditional check can be removed, i.e.
int f(char *x) {
if (__builtin_this_is_false(!(x != NULL)))
abort();
return x ? *x : 0;
}
this may have other uses than a (broken) assert optimization.
Of course, if in this case x _is_ actually NULL, we create wrong code,
but we were asked for this.
Richard.