From 7b976eb81080d015eb33c43afa7ac6d015eee10d Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 31 Dec 2024 19:07:10 +0100 Subject: [PATCH] Build: Add OpenSubdiv patch to silence ASAN warnings Until upstream PR #1343 is merged. --- .../build_environment/cmake/opensubdiv.cmake | 5 + .../patches/opensubdiv_1343.diff | 97 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 build_files/build_environment/patches/opensubdiv_1343.diff diff --git a/build_files/build_environment/cmake/opensubdiv.cmake b/build_files/build_environment/cmake/opensubdiv.cmake index e4e743a776c..16788cf8233 100644 --- a/build_files/build_environment/cmake/opensubdiv.cmake +++ b/build_files/build_environment/cmake/opensubdiv.cmake @@ -32,6 +32,11 @@ ExternalProject_Add(external_opensubdiv PREFIX ${BUILD_DIR}/opensubdiv CMAKE_GENERATOR ${PLATFORM_ALT_GENERATOR} + PATCH_COMMAND + ${PATCH_CMD} -p 1 -d + ${BUILD_DIR}/opensubdiv/src/external_opensubdiv < + ${PATCH_DIR}/opensubdiv_1343.diff + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBDIR}/opensubdiv -Wno-dev ${DEFAULT_CMAKE_FLAGS} diff --git a/build_files/build_environment/patches/opensubdiv_1343.diff b/build_files/build_environment/patches/opensubdiv_1343.diff new file mode 100644 index 00000000000..c5724cc3b4d --- /dev/null +++ b/build_files/build_environment/patches/opensubdiv_1343.diff @@ -0,0 +1,97 @@ +From 2a1dd46bbd14b6fdc6540c76422ac4e9bd8ab724 Mon Sep 17 00:00:00 2001 +From: Brecht Van Lommel +Date: Fri, 13 Dec 2024 02:31:45 +0100 +Subject: [PATCH] Fix address sanitizer warnings with stencil table casting + +For compatibility, StencilTableReal is cast to StencilTable, which has +the same data layout but it's not actually an instance of that class. And so +using static_cast is not strictly correct. Use reinterpret_cast instead. +--- + opensubdiv/far/patchTable.h | 6 +++--- + opensubdiv/far/stencilTableFactory.h | 12 ++++++------ + 2 files changed, 9 insertions(+), 9 deletions(-) + +diff --git a/opensubdiv/far/patchTable.h b/opensubdiv/far/patchTable.h +index d2e9d5a614..6731d788f6 100644 +--- a/opensubdiv/far/patchTable.h ++++ b/opensubdiv/far/patchTable.h +@@ -777,19 +777,19 @@ PatchTable::LocalPointFaceVaryingStencilPrecisionMatchesType() const { + inline StencilTable const * + PatchTable::GetLocalPointStencilTable() const { + assert(LocalPointStencilPrecisionMatchesType()); +- return static_cast(_localPointStencils.Get()); ++ return reinterpret_cast(_localPointStencils.Get()); + } + inline StencilTable const * + PatchTable::GetLocalPointVaryingStencilTable() const { + assert(LocalPointVaryingStencilPrecisionMatchesType()); +- return static_cast( ++ return reinterpret_cast( + _localPointVaryingStencils.Get()); + } + inline StencilTable const * + PatchTable::GetLocalPointFaceVaryingStencilTable(int channel) const { + assert(LocalPointFaceVaryingStencilPrecisionMatchesType()); + if (channel >= 0 && channel < (int)_localPointFaceVaryingStencils.size()) { +- return static_cast( ++ return reinterpret_cast( + _localPointFaceVaryingStencils[channel].Get()); + } + return NULL; +diff --git a/opensubdiv/far/stencilTableFactory.h b/opensubdiv/far/stencilTableFactory.h +index c2e95e1c3d..5b8d43f1dc 100644 +--- a/opensubdiv/far/stencilTableFactory.h ++++ b/opensubdiv/far/stencilTableFactory.h +@@ -293,14 +293,14 @@ class StencilTableFactory : public StencilTableFactoryReal { + static StencilTable const * Create( + TopologyRefiner const & refiner, Options options = Options()) { + +- return static_cast( ++ return reinterpret_cast( + BaseFactory::Create(refiner, options)); + } + + static StencilTable const * Create( + int numTables, StencilTable const ** tables) { + +- return static_cast( ++ return reinterpret_cast( + BaseFactory::Create(numTables, + reinterpret_cast(tables))); + } +@@ -311,7 +311,7 @@ class StencilTableFactory : public StencilTableFactoryReal { + StencilTable const *localPointStencilTable, + bool factorize = true) { + +- return static_cast( ++ return reinterpret_cast( + BaseFactory::AppendLocalPointStencilTable(refiner, + static_cast(baseStencilTable), + static_cast(localPointStencilTable), +@@ -324,7 +324,7 @@ class StencilTableFactory : public StencilTableFactoryReal { + StencilTable const *localPointStencilTable, + bool factorize = true) { + +- return static_cast( ++ return reinterpret_cast( + BaseFactory::AppendLocalPointStencilTableVarying(refiner, + static_cast(baseStencilTable), + static_cast(localPointStencilTable), +@@ -338,7 +338,7 @@ class StencilTableFactory : public StencilTableFactoryReal { + int channel = 0, + bool factorize = true) { + +- return static_cast( ++ return reinterpret_cast( + BaseFactory::AppendLocalPointStencilTableFaceVarying(refiner, + static_cast(baseStencilTable), + static_cast(localPointStencilTable), +@@ -364,7 +364,7 @@ class LimitStencilTableFactory : public LimitStencilTableFactoryReal { + PatchTable const * patchTable = 0, + Options options = Options()) { + +- return static_cast( ++ return reinterpret_cast( + BaseFactory::Create( + refiner, + locationArrays,