From d6553d65556779cf6825adbd374d9c3b95509d82 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Wed, 30 Oct 2024 09:30:37 +0100 Subject: [PATCH] Use compile option -fno-strict-aliasing to prevent breaking optimizations due to using reinterpret_cast --- CMakeLists.txt | 1 + README.md | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5ec65ea4..f280461d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ function( vulkan_hpp__setup_platform ) else() message( FATAL_ERROR, "Vulkan-Hpp: unhandled platform!" ) endif() + target_compile_options( ${TARGET_NAME} PRIVATE -fno-strict-aliasing ) endfunction() function( vulkan_hpp__setup_vulkan_include ) diff --git a/README.md b/README.md index d1970638a..efd10ac3c 100644 --- a/README.md +++ b/README.md @@ -846,6 +846,10 @@ Currently, there are just a couple of such defines: - `VULKAN_HPP_NO_TO_STRING`, which removes the various `vk::to_string` functions on enums and bitmasks. - `VULKAN_HPP_USE_REFLECT`, this one needs to be defined to use the reflection function on structures. It's very slow to compile, though! +### Strict aliasing issue + +As Vulkan-Hpp often needs to switch between C++ vk-types and corresponding bit-identical C-types, using `reinterpret_cast`, it is highly recommended to use the compile option `-fno-strict-aliasing` to prevent potentially breaking compile optimizations. + ## Configuration Options There are a couple of defines you can use to control the feature set and behaviour of `vulkan.hpp`: