__builtin_memchr usually used in str find;
further read:
Reference:
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
https://news.ycombinator.com/item?id=11760293
e.g.
__builtin_popcount
__builtin_popcountl
Reference:
(msvc) __assume
(gcc/clang) __builtin_unreachable()
(c++23) std::unreachable
[[noreturn]] inline void unreachable()
{
// Uses compiler specific extensions if possible.
// Even if no extension is used, undefined behavior is still raised by
// an empty function body and the noreturn attribute.
#ifdef __GNUC__ // GCC, Clang, ICC
__builtin_unreachable();
#elifdef _MSC_VER // MSVC
__assume(false);
#endif
}
__builtin_unreachable__builtin_unreachable is used to indicate that a specific point in the program cannot be reached, even if the compiler might otherwise think it can. This is useful to improve optimization and eliminates certain warnings. For example, without the __builtin_unreachable in the example below, the compiler assumes that the inline asm can fall through and prints a “function declared ‘noreturn’ should not return” warning.__builtin_unreachable()
void myabort(void) __attribute__((noreturn));
void myabort(void) {
asm("int3");
__builtin_unreachable();
}
__builtin_unreachable() builtin has completely undefined behavior. Since it has undefined behavior, it is a statement that it is never reached and the optimizer can take advantage of this to produce better code. This builtin takes no arguments and produces a void result.__has_builtin(__builtin_unreachable).