[libc-commits] [libc] [libc] Add `__builtin_expect` tag on assert conditions; NFC (PR #99498)
Aaron Ballman via libc-commits
libc-commits at lists.llvm.org
Fri Jul 19 05:10:18 PDT 2024
AaronBallman wrote:
> > > I remember discussing something similar with @AaronBallman about adding `__builtin_assume` to the assert macros. I think the answer then was that the C standard specifies exactly what `assert` should look like so we can't change it? I think `LIBC_ASSERT` probably should though.
> >
> >
> > `__builtin_assume` is a bit different, no? This is properly `NFC`, it just has an off chance of helping codegen. I don't think any standard says much about how `assert` is implemented other than it will `abort` and maybe write something to `stderr` (and I guess the linux reference saying `__assert_fail` is defined) but this doesn't change any of those things.
>
> > Nope -- you cannot expand the argument given to assert if NDEBUG is defined (also, 7.2p1 defines what assert is required to expand to in this case.)
>
> Was the response I got earlier, but I guess that only applies to making `#define assert(cond) __builtin_assume(!cond);` so this might be fine.
Yeah, I think this is okay. One thing I did note when I reviewed the code is that the definition of `assert` changed in C23, it's now defined as `assert(...)` rather than `assert(e)`, see https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2829.htm for details.
https://github.com/llvm/llvm-project/pull/99498
More information about the libc-commits
mailing list