Skip to content

Commit

Permalink
Main: Disable vptr checks for Singleton constructor (#2032)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Oliver Old authored and paroj committed May 20, 2021
1 parent 6151fae commit 34c7d3d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions OgreMain/include/OgreSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ template <typename T> 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");
Expand Down

0 comments on commit 34c7d3d

Please sign in to comment.