freebsd-src icon indicating copy to clipboard operation
freebsd-src copied to clipboard

Perfer sys/cdefs.h __unreachable over the builtin

Open collinfunk opened this issue 1 year ago • 2 comments

The __builtin_unreachable macro provided by Clang and GCC is a hint to the compiler used for optimization. The programs work fine even if the compiler doesn't support it. The sys/cdefs.h has had __unreachable for 9 years (commit 732b31de5d9244bd1cc98192e09ee1881e9f55e9). It expands to the builtin if it is available. In the rare case that it is unsupported it expands to a null statement so compilation does not fail.

collinfunk avatar Feb 13 '24 04:02 collinfunk

@bsdimp @emaste ISO C 23 N2826 adds the function-like macro unreachable() to stddef.h. Can I submit a separate patch proposing that change? I'm not sure if it is something left up to the GCC/Clang people to include with their headers though...

collinfunk avatar Feb 13 '24 04:02 collinfunk

this needs one commit per subsystem.

Oops, my bad. Split into three commits, one for each program.

collinfunk avatar Feb 16 '24 17:02 collinfunk

Landed this... go ahead and start to implement the c23 defined macro if you can do it w/o problems on older C compilers.

bsdimp avatar Apr 12 '24 22:04 bsdimp

OK, automation still bad, but I caught it this time.

bsdimp avatar Apr 12 '24 22:04 bsdimp