[libc-commits] [libc] [libc] Add `__builtin_expect` tag on assert conditions; NFC (PR #99498)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Thu Jul 18 08:51:22 PDT 2024


jhuber6 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.

https://github.com/llvm/llvm-project/pull/99498


More information about the libc-commits mailing list