From: Jacek Caban jacek@codeweavers.com
--- include/private/vkd3d_common.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h index 619665ad3..e69832b43 100644 --- a/include/private/vkd3d_common.h +++ b/include/private/vkd3d_common.h @@ -75,18 +75,20 @@ static inline size_t align(size_t addr, size_t alignment) return (addr + (alignment - 1)) & ~(alignment - 1); }
-#ifdef __GNUC__ +#ifdef __MINGW_PRINTF_FORMAT +# define VKD3D_PRINTF_FUNC(fmt, args) __attribute__((format(__MINGW_PRINTF_FORMAT, fmt, args))) +#elif defined(__GNUC__) +# define VKD3D_PRINTF_FUNC(fmt, args) __attribute__((format(printf, fmt, args))) +#else +# define VKD3D_PRINTF_FUNC(fmt, args) +#endif + +#if defined(__GNUC__) || defined(__clang__) # define VKD3D_NORETURN __attribute__((noreturn)) -# ifdef __MINGW_PRINTF_FORMAT -# define VKD3D_PRINTF_FUNC(fmt, args) __attribute__((format(__MINGW_PRINTF_FORMAT, fmt, args))) -# else -# define VKD3D_PRINTF_FUNC(fmt, args) __attribute__((format(printf, fmt, args))) -# endif # define VKD3D_UNUSED __attribute__((unused)) # define VKD3D_UNREACHABLE __builtin_unreachable() #else # define VKD3D_NORETURN -# define VKD3D_PRINTF_FUNC(fmt, args) # define VKD3D_UNUSED # define VKD3D_UNREACHABLE (void)0 #endif /* __GNUC__ */
Martin Storsjö (@mstorsjo) commented about include/private/vkd3d_common.h:
return (addr + (alignment - 1)) & ~(alignment - 1);
}
-#ifdef __GNUC__ +#ifdef __MINGW_PRINTF_FORMAT
I'm not sure if it's worth to move out the whole handling of `VKD3D_PRINTF_FUNC` here, instead of leaving it all where it was, and just change the `#ifdef __GNUC__` into `#if defined(__GNUC__) || defined(__clang__)` here.
I guess the only case where there's a behavioural difference, is if one would have `__MINGW_PRINTF_FORMAT` defined but neither `__GNUC__` or `__clang__` defined, i.e. be compiling with actual MSVC, but with mingw headers. That's not really a real case though - so it doesn't really matter, but I was just curious if there's any other advantage, to just keeping the code as it was and just change the one ifdef?
On Fri Nov 17 12:49:58 2023 +0000, Martin Storsjö wrote:
I'm not sure if it's worth to move out the whole handling of `VKD3D_PRINTF_FUNC` here, instead of leaving it all where it was, and just change the `#ifdef __GNUC__` into `#if defined(__GNUC__) || defined(__clang__)` here. I guess the only case where there's a behavioural difference, is if one would have `__MINGW_PRINTF_FORMAT` defined but neither `__GNUC__` or `__clang__` defined, i.e. be compiling with actual MSVC, but with mingw headers. That's not really a real case though - so it doesn't really matter, but I was just curious if there's any other advantage, to just keeping the code as it was and just change the one ifdef?
vkd3d suffers from the same problem as Wine before PE conversion: things like DWORD need to be ints instead of longs when building for Unix targets. It actually assumes ints in debug formats, which leads to various warnings. I didn't want to extend the problem to MSVC targets.
However, I took a deeper look at Wine build system and came out with: https://gitlab.winehq.org/wine/wine/-/merge_requests/4423. It's more comprehensive: aligns Clang builds with GCC ones, avoids warnings in other imported libraries as well and fixes both mingw and msvc Clang targets.
I will change this MR as you suggested, thanks!