Commit 8b7f6f5a authored by Lucian Grijincu's avatar Lucian Grijincu Committed by facebook-github-bot-4

folly: #define UNDEFINED_SANITIZER in ubsan mode

Summary:
Undefined Sanitizer doesn't define any macro to detect that it's active.

The build system should provide `-DUNDEFINED_SANITIZER` when building
with -fsanitize=undefined or any of the other flags from
http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html

FWIW: Chrome defines the same preprocessor symbol:
https://chromium.googlesource.com/chromium/src/+/ac18f489dca8c902e4dfaa1a28d716b7914121d0%5E%21/build/common.gypi

Reviewed By: andrewjcg

Differential Revision: D2885167

fb-gh-sync-id: e1129c0863bfde5d032c32e7d5cea7c43d82009f
parent 20bd643d
......@@ -56,4 +56,21 @@
# define FOLLY_DISABLE_ADDRESS_SANITIZER
#endif
#endif
/**
* ASAN/MSAN/TSAN define pre-processor symbols:
* ADDRESS_SANITIZER/MEMORY_SANITIZER/THREAD_SANITIZER.
*
* UBSAN doesn't define anything and makes it hard to
* conditionally compile.
*
* The build system should define UNDEFINED_SANITIZER=1 when UBSAN is
* used as folly whitelists some functions.
*/
#if UNDEFINED_SANITIZER
# define UBSAN_DISABLE(x) __attribute__((no_sanitize(x)))
#else
# define UBSAN_DISABLE(x)
#endif // UNDEFINED_SANITIZER
#endif // CPORTABILITY_H
......@@ -14,6 +14,8 @@
* limitations under the License.
*/
#include <folly/Portability.h>
#include <gtest/gtest.h>
namespace {
......@@ -30,7 +32,7 @@ void init() {
}
}
TEST(memcpy, zero_len) {
TEST(memcpy, zero_len) UBSAN_DISABLE("nonnull-attribute") {
// If length is 0, we shouldn't touch any memory. So this should
// not crash.
char* srcNull = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment