From afa646509807a2e2f70bcdf90248f2c4076b4a79 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 21 Sep 2021 16:33:57 +0100 Subject: [PATCH] UB Sanitizer: Avoid warnings in third party code, with clang --- .../codecs/juce_OggVorbisAudioFormat.cpp | 2 ++ .../VST3/juce_VST3_Wrapper.cpp | 4 ++++ .../format_types/juce_VST3Common.h | 4 ++++ .../format_types/juce_VST3PluginFormat.cpp | 6 +++++ .../juce_core/system/juce_CompilerWarnings.h | 23 ++++++++++++++++++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp index 7cb8d4d784..d9ffa50b1b 100644 --- a/modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp @@ -50,6 +50,7 @@ namespace OggVorbisNamespace "-Wmisleading-indentation", "-Wmissing-prototypes", "-Wcast-align") + JUCE_BEGIN_NO_SANITIZE ("undefined") #include "oggvorbis/vorbisenc.h" #include "oggvorbis/codec.h" @@ -79,6 +80,7 @@ namespace OggVorbisNamespace #include "oggvorbis/libvorbis-1.3.7/lib/vorbisfile.c" #include "oggvorbis/libvorbis-1.3.7/lib/window.c" + JUCE_END_NO_SANITIZE JUCE_END_IGNORE_WARNINGS_MSVC JUCE_END_IGNORE_WARNINGS_GCC_LIKE #else diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index 33f3adafd0..0d2d29103b 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -29,6 +29,8 @@ //============================================================================== #if JucePlugin_Build_VST3 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD) +JUCE_BEGIN_NO_SANITIZE ("vptr") + #if JUCE_PLUGINHOST_VST3 #if JUCE_MAC #include @@ -3989,4 +3991,6 @@ extern "C" SMTG_EXPORT_SYMBOL IPluginFactory* PLUGIN_API GetPluginFactory() extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD reason, LPVOID) { if (reason == DLL_PROCESS_ATTACH) Process::setCurrentModuleInstanceHandle (instance); return true; } #endif +JUCE_END_NO_SANITIZE + #endif //JucePlugin_Build_VST3 diff --git a/modules/juce_audio_processors/format_types/juce_VST3Common.h b/modules/juce_audio_processors/format_types/juce_VST3Common.h index a41f0962c6..4e9e6851ea 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3Common.h +++ b/modules/juce_audio_processors/format_types/juce_VST3Common.h @@ -28,6 +28,8 @@ namespace juce { +JUCE_BEGIN_NO_SANITIZE ("vptr") + //============================================================================== #define JUCE_DECLARE_VST3_COM_REF_METHODS \ Steinberg::uint32 PLUGIN_API addRef() override { return (Steinberg::uint32) ++refCount; } \ @@ -1219,6 +1221,8 @@ private: std::atomic flags { 0 }; }; +JUCE_END_NO_SANITIZE + } // namespace juce #endif // ! DOXYGEN diff --git a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp index 2db66abfa5..c8c7f82d4b 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp @@ -31,6 +31,10 @@ namespace juce { +// UB Sanitizer doesn't necessarily have instrumentation for loaded plugins, so +// it won't recognize the dynamic types of pointers to the plugin's interfaces. +JUCE_BEGIN_NO_SANITIZE ("vptr") + using namespace Steinberg; //============================================================================== @@ -3767,6 +3771,8 @@ FileSearchPath VST3PluginFormat::getDefaultLocationsToSearch() #endif } +JUCE_END_NO_SANITIZE + } // namespace juce #endif // JUCE_PLUGINHOST_VST3 diff --git a/modules/juce_core/system/juce_CompilerWarnings.h b/modules/juce_core/system/juce_CompilerWarnings.h index 462e8bafaa..12ecad595c 100644 --- a/modules/juce_core/system/juce_CompilerWarnings.h +++ b/modules/juce_core/system/juce_CompilerWarnings.h @@ -189,7 +189,7 @@ #define JUCE_IGNORE_MSVC(warnings) __pragma(warning(disable:warnings)) #define JUCE_BEGIN_IGNORE_WARNINGS_LEVEL_MSVC(level, warnings) \ __pragma(warning(push, level)) JUCE_IGNORE_MSVC(warnings) - #define JUCE_BEGIN_IGNORE_WARNINGS_MSVC(warnings) \ + #define JUCE_BEGIN_IGNORE_WARNINGS_MSVC(warnings) \ __pragma(warning(push)) JUCE_IGNORE_MSVC(warnings) #define JUCE_END_IGNORE_WARNINGS_MSVC __pragma(warning(pop)) #else @@ -198,3 +198,24 @@ #define JUCE_BEGIN_IGNORE_WARNINGS_MSVC(warnings) #define JUCE_END_IGNORE_WARNINGS_MSVC #endif + +#if JUCE_MAC || JUCE_IOS + #define JUCE_SANITIZER_ATTRIBUTE_MINIMUM_CLANG_VERSION 10 +#else + #define JUCE_SANITIZER_ATTRIBUTE_MINIMUM_CLANG_VERSION 5 +#endif + +/** Disable sanitizers for a range of functions. + + This functionality doesn't seem to exist on GCC yet, so at the moment this only works for clang. +*/ +#if JUCE_CLANG && __clang_major__ >= JUCE_SANITIZER_ATTRIBUTE_MINIMUM_CLANG_VERSION + #define JUCE_BEGIN_NO_SANITIZE(warnings) \ + _Pragma(JUCE_TO_STRING(clang attribute push(__attribute__((no_sanitize(warnings))), apply_to=function))) + #define JUCE_END_NO_SANITIZE _Pragma(JUCE_TO_STRING(clang attribute pop)) +#else + #define JUCE_BEGIN_NO_SANITIZE(warnings) + #define JUCE_END_NO_SANITIZE +#endif + +#undef JUCE_SANITIZER_ATTRIBUTE_MINIMUM_CLANG_VERSION