From 34c7d3dd939b876f29abd4e3fff4e9f1cf87ccf7 Mon Sep 17 00:00:00 2001 From: Oliver Old Date: Thu, 20 May 2021 00:55:11 +0200 Subject: [PATCH] Main: Disable vptr checks for Singleton constructor (#2032) UBSan complains a lot about the this pointer not being of type T* which is correct during construction, but ultimately doesn't matter. This change disables the vptr check on the Singleton constructor to avoid errors from UBSan. --- OgreMain/include/OgreSingleton.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/OgreMain/include/OgreSingleton.h b/OgreMain/include/OgreSingleton.h index be07e9c1198..66323a15b1b 100644 --- a/OgreMain/include/OgreSingleton.h +++ b/OgreMain/include/OgreSingleton.h @@ -80,6 +80,14 @@ template class Singleton static T* msSingleton; public: +#if defined(__has_attribute) +# if __has_attribute(no_sanitize) + // The `static_cast` happens so early in the construction of the inheriting + // classes that the `this` pointer is still detected as the super class + // pointer. Therefore, disabling vptr checks. + __attribute__((no_sanitize("vptr"))) +# endif +#endif Singleton(void) { OgreAssert(!msSingleton, "There can be only one singleton");