This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Infering that the condition of a for loop is initially true?
Marc Glisse <marc.glisse@inria.fr> writes:
> assert is not what you want, since it completely disappears with
> -DNDEBUG. clang has __builtin_assume, with gcc you want a test and
> __builtin_unreachable. Replacing your assert with
> if(n==0)__builtin_unreachable();
To me, it would make sense to have assert expand to something like that,
when runtime checks are disabled with -NDEBUG.
After all, is a program fails an assertion, it can not be expected to
produce any meaningful results, even with run-time checks disabled using
-DNDEBUG. And it's somewhat counter-intutive, if -DNDEBUG produces a
binary in which the code downstream from assert statements are slightly
less well optimized.
I imagine the C standard might specify that assert "completely
disappears" if -DNDEBUG is defined. But maybe there's room for a
-fstrict-assert optimization flag, to let assert always guide
optimization?
Regards,
/Niels
--
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.