What is Nostr?
John Regehr /
npub15xj…5a5k
2024-11-18 15:49:21

John Regehr on Nostr: here's a silly C function that LLVM can (correctly) optimize into just a return ...

here's a silly C function that LLVM can (correctly) optimize into just a return instruction: https://gcc.godbolt.org/z/93c9nnsjb

but, on my Mac, the assert gets expanded to include a builtin_expect:

(__builtin_expect(!(a), 0) ? __assert_rtn(__func__, "test.c", 7, "a") : (void)0);

clang turns that into an LLVM assume(), which ends up getting in the way of the optimization that makes the function go away. so, precisely the opposite of the intended effect!! ugh.
Author Public Key
npub15xjwk4qzx56p5tdsmzsge7m5ahztkp4nzmrmkw2cp324t888rwsswe5a5k