diff --git a/Makefile b/Makefile index 240acd41a..97385178b 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,10 @@ endif # SANITIZE *implies* DEBUG +ifeq ($(MEMSANITIZE),1) + CXXFLAGS += -g3 -O0 -fsanitize=memory -fno-omit-frame-pointer -fsanitize=undefined + CFLAGS += -g3 -O0 -fsanitize=memory -fno-omit-frame-pointer -fsanitize=undefined +else ifeq ($(SANITIZE),1) CXXFLAGS += -g3 -O0 -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined CFLAGS += -g3 -O0 -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined @@ -36,6 +40,7 @@ else CFLAGS += -O3 endif # ifeq ($(DEBUG),1) endif # ifeq ($(SANITIZE),1) +endif # ifeq ($(MEMSANITIZE),1) MAINEXECUTABLES=parse minify json2json jsonstats statisticalmodel TESTEXECUTABLES=jsoncheck numberparsingcheck stringparsingcheck diff --git a/include/simdjson/common_defs.h b/include/simdjson/common_defs.h index 059a6afec..a485e28b5 100644 --- a/include/simdjson/common_defs.h +++ b/include/simdjson/common_defs.h @@ -64,6 +64,12 @@ # endif #endif +#if defined(__has_feature) +# if (__has_feature(memory_sanitizer)) +#define LENIENT_MEM_SANITIZER __attribute__((no_sanitize("memory"))) +# endif +#endif + #define really_inline inline __attribute__((always_inline, unused)) #define never_inline inline __attribute__((noinline, unused)) @@ -83,4 +89,8 @@ #ifndef ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER #define ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER #endif +#ifndef LENIENT_MEM_SANITIZER +#define LENIENT_MEM_SANITIZER +#endif + #endif // SIMDJSON_COMMON_DEFS_H diff --git a/include/simdjson/stringparsing.h b/include/simdjson/stringparsing.h index 588a4dba8..08632cb13 100644 --- a/include/simdjson/stringparsing.h +++ b/include/simdjson/stringparsing.h @@ -76,7 +76,7 @@ really_inline bool handle_unicode_codepoint(const uint8_t **src_ptr, uint8_t **d #include #endif -WARN_UNUSED ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER +WARN_UNUSED ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER LENIENT_MEM_SANITIZER really_inline bool parse_string(UNUSED const uint8_t *buf, UNUSED size_t len, ParsedJson &pj, UNUSED const uint32_t depth, UNUSED uint32_t offset) { #ifdef SIMDJSON_SKIPSTRINGPARSING // for performance analysis, it is sometimes useful to skip parsing diff --git a/src/stage2_build_tape.cpp b/src/stage2_build_tape.cpp index b3a7f3c2e..f3bf15b66 100644 --- a/src/stage2_build_tape.cpp +++ b/src/stage2_build_tape.cpp @@ -70,7 +70,7 @@ really_inline bool is_valid_null_atom(const uint8_t *loc) { * The JSON is parsed to a tape, see the accompanying tape.md file * for documentation. ***********/ -WARN_UNUSED ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER +WARN_UNUSED ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER LENIENT_MEM_SANITIZER int unified_machine(const uint8_t *buf, size_t len, ParsedJson &pj) { uint32_t i = 0; // index of the structural character (0,1,2,3...) uint32_t idx; // location of the structural character in the input (buf)