This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]