From 69f34b359c0ec0d4517050fe274883421c4c119b Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 3 Aug 2025 16:09:42 +0100 Subject: Tidy up some extensions and remove some ifdefs Since this codebase is already extremely nonportable, I've decided to relax the obsessive ifdef-else-error usage around all the extensions. From now on, if there's no alternative to using an extension, we can just use that extension. If it's possible to do something in a relatively portable way, we can still try to do that in order to make the code somewhat reusable, in contexts where that makes sense. I also decided to use langext.h for naked functions and tail calls. If that's used in another codebase build with a different compiler, those just won't work, but that's fine. The benefit is really just that there's less ceremony in places where those are used, because it's likely there'll be a few more such places in the future, and it gets annoying reading all the double-underscore stuff all over the place. I still kind of want to do something about all the _WIN32 ifdefs too, but I've realised that doing so will lead to almost nothing actually being built on Linux. Then again, none of it currently runs on Linux so I guess that's a moot point. Will worry about it later, anyway. --- src/langext.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/langext.h') diff --git a/src/langext.h b/src/langext.h index d2d9a23..0624b71 100644 --- a/src/langext.h +++ b/src/langext.h @@ -17,6 +17,7 @@ #define unreachable __builtin_unreachable() #define assume(x) ((void)(!!(x) || (unreachable, 0))) #define cold __attribute((__cold__, __noinline__)) +#define asm_only __attribute((__naked__)) // N.B.: may not actually work in GCC? #else #define if_hot(x) if (x) #define if_cold(x) if (x) @@ -25,11 +26,13 @@ #define unreachable __assume(0) #define assume(x) ((void)(__assume(x), 0)) #define cold __declspec(noinline) +#define asm_only __declspec(naked) #else static inline _Noreturn void _invoke_ub() {} #define unreachable (_invoke_ub()) #define assume(x) ((void)(!!(x) || (_invoke_ub(), 0))) #define cold +//#define asm_only // Can't use this without Clang/GCC/MSVC. Too bad. #endif #endif @@ -63,6 +66,17 @@ static inline _Noreturn void _invoke_ub() {} #endif #endif +#ifdef __clang__ +#define tailcall \ + /* Clang forces us to use void return and THEN warns about it ._. */ \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wpedantic\"") \ + __attribute((musttail)) return \ + _Pragma("clang diagnostic pop") +#else +//#define tailcall // Can't use this without Clang. +#endif + #endif // vi: sw=4 ts=4 noet tw=80 cc=80 -- cgit v1.2.3-54-g00ecf