From db7f691624cf6573192435a5f9a0eb5ae4bd7980 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 21 Feb 2024 14:58:43 +1000 Subject: [PATCH] tools: prefer cast::ffs over reinterpret_cast for alignment warnings --- tools/hello.cpp | 2 +- tools/spec.py | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/hello.cpp b/tools/hello.cpp index 4ec9632..0d4c78c 100644 --- a/tools/hello.cpp +++ b/tools/hello.cpp @@ -299,7 +299,7 @@ VkResult _vkCreateDebugReportCallbackEXT ( const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback ) noexcept { - static auto fn = reinterpret_cast< + static auto fn = cruft::cast::ffs< decltype(_vkCreateDebugReportCallbackEXT)* > ( vkGetInstanceProcAddr ( diff --git a/tools/spec.py b/tools/spec.py index 1e5902c..1038969 100644 --- a/tools/spec.py +++ b/tools/spec.py @@ -850,6 +850,7 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry): #include "load/dispatch.hpp" #include + #include #include #include @@ -871,11 +872,11 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry): if (err != VK_SUCCESS) return err; - #define GET(NAME) res->table.NAME = reinterpret_cast (cruft::vk::load::v_table->vk_icdGetInstanceProcAddr (res->handle, #NAME)); + #define GET(NAME) res->table.NAME = cruft::cast::ffs (cruft::vk::load::v_table->vk_icdGetInstanceProcAddr (res->handle, #NAME)); MAP_INSTANCE_COMMANDS(GET) #undef GET - #define GET(NAME) if (!res->table.NAME) res->table.NAME = reinterpret_cast (res->table.vkGetInstanceProcAddr (res->handle, #NAME)); + #define GET(NAME) if (!res->table.NAME) res->table.NAME = cruft::cast::ffs (res->table.vkGetInstanceProcAddr (res->handle, #NAME)); MAP_INSTANCE_COMMANDS(GET) #undef GET @@ -885,7 +886,7 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry): 'vkGetInstanceProcAddr': """ std::clog << "InstanceProcAddr: " << pName << '\\n'; - #define ATTEMPT(NAME) if (!strcmp (#NAME, pName)) return reinterpret_cast (&NAME); + #define ATTEMPT(NAME) if (!strcmp (#NAME, pName)) return cruft::cast::ffs (&NAME); MAP_INSTANCE_COMMANDS(ATTEMPT) #undef ATTEMPT return nullptr; @@ -927,11 +928,11 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry): //MAP_INSTANCE_COMMANDS(GET) //#undef GET - #define GET(NAME) wrapped->table.NAME = wrapped->table.NAME ?: reinterpret_cast (cruft::vk::load::v_table->vk_icdGetInstanceProcAddr (entry->handle, #NAME)); + #define GET(NAME) wrapped->table.NAME = wrapped->table.NAME ?: cruft::cast::ffs (cruft::vk::load::v_table->vk_icdGetInstanceProcAddr (entry->handle, #NAME)); MAP_INSTANCE_COMMANDS(GET) #undef GET - #define GET(NAME) wrapped->table.NAME = wrapped->table.NAME ?: reinterpret_cast (entry->table.vkGetInstanceProcAddr (entry->handle, #NAME)); + #define GET(NAME) wrapped->table.NAME = wrapped->table.NAME ?: cruft::cast::ffs (entry->table.vkGetInstanceProcAddr (entry->handle, #NAME)); MAP_INSTANCE_COMMANDS(GET) #undef GET @@ -996,17 +997,19 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry): #include "vk.hpp" #include "load/vtable.hpp" #include "ostream.hpp" - + #include #include #include - + + #include + static void* g_lib; - + void init [[gnu::constructor]] (void) { g_lib = dlopen (getenv ("REAL_VULKAN"), RTLD_LAZY | RTLD_LOCAL); } - + void deinit [[gnu::destructor]] (void) { dlclose (g_lib); g_lib = nullptr; @@ -1014,7 +1017,6 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry): #pragma GCC diagnostic ignored "-Wsign-promo" """) - for obj in (i for i in q if isinstance(i, Command)): inner = "" if obj.name in ['vkGetInstanceProcAddr']: @@ -1029,7 +1031,7 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry): } #undef FWD - #define FWD(NAME) if (!strcmp(#NAME,pName)) { return reinterpret_cast (NAME); } + #define FWD(NAME) if (!strcmp(#NAME,pName)) { return cruft::cast::ffs (NAME); } MAP_INSTANCE_COMMANDS(FWD) #undef FWD std::clog << "Unhooked: " << pName << '\\n';