diff --git a/CMakeLists.txt b/CMakeLists.txt index b15b24d20..790fd584b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,9 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "MinSizeRel" OR "${CMAKE_BUILD_TYPE}" MATCHES " # versioned LLVMgold.so can drift out of sync with the compiler and break LTO linking. add_link_options(-fuse-ld=lld) endif() +elseif("${CMAKE_BUILD_TYPE}" MATCHES "Debug" AND NOT MSVC) + add_compile_options(-fsanitize=undefined -fno-sanitize-recover=undefined) + add_link_options(-fsanitize=undefined -fno-sanitize-recover=undefined) endif() if(ALIGNMENT_TEST) diff --git a/ext/lib/Marisa/CMakeLists.txt b/ext/lib/Marisa/CMakeLists.txt index 43b1cc795..778b97ec0 100644 --- a/ext/lib/Marisa/CMakeLists.txt +++ b/ext/lib/Marisa/CMakeLists.txt @@ -41,6 +41,11 @@ else() endif() # (DEFINED ENV{MARISA_ROOT}) +if("${CMAKE_BUILD_TYPE}" MATCHES "Debug" AND NOT MSVC) + # marisa-trie (keyset.cc, grimoire/vector/vector.h) passes nullptr to std::memcpy with length 0. + set_source_files_properties(${MARISA_SOURCES} PROPERTIES COMPILE_OPTIONS "-fno-sanitize=nonnull-attribute") +endif() + if(XCODE) add_library(marisa_objs INTERFACE) target_sources(marisa_objs INTERFACE ${MARISA_SOURCES}) diff --git a/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.cpp b/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.cpp index 81f535a63..384d8dd97 100644 --- a/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.cpp +++ b/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.cpp @@ -98,10 +98,11 @@ std::optional<::std::u16string> DictionaryMetaData_MMappedDictionary::getTypeOfV return {}; } -std::vector<::std::u16string> DictionaryMetaData_MMappedDictionary::getTypesOfValues(int64_t value) const { +std::vector<::std::u16string> DictionaryMetaData_MMappedDictionary::getTypesOfValues(uint64_t value) const +{ ::std::vector<::std::u16string> result; while (value != 0) { - const auto singleProperty = ((int64_t)(((uint64_t)(value ^ (value - 1))) >> 1)) + 1; + const auto singleProperty = ((value ^ (value - 1)) >> 1) + 1; value &= value - 1; const auto name = getTypeOfValue(singleProperty); if (name.has_value()) { diff --git a/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.hpp b/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.hpp index 31b185f06..9bfeed324 100644 --- a/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.hpp +++ b/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.hpp @@ -29,7 +29,8 @@ class INFLECTION_INTERNAL_API inflection::dictionary::DictionaryMetaData_MMapped ::std::optional getValueOfType(std::u16string_view type) const; int64_t getValuesOfTypes(const std::vector &types) const; ::std::optional<::std::u16string> getTypeOfValue(int64_t value) const; - ::std::vector<::std::u16string> getTypesOfValues(int64_t value) const; + ::std::vector<::std::u16string> getTypesOfValues(uint64_t value) const; + private: void getPropertyMapInternalIdentifiers(std::vector &propertyIdentifiers, int32_t startingOffset, int32_t length) const; typedef enum { diff --git a/test/src/inflection/dictionary/DictionaryMetaDataTest-c.cpp b/test/src/inflection/dictionary/DictionaryMetaDataTest-c.cpp index 6c69488ce..a4eedebd3 100644 --- a/test/src/inflection/dictionary/DictionaryMetaDataTest-c.cpp +++ b/test/src/inflection/dictionary/DictionaryMetaDataTest-c.cpp @@ -16,12 +16,12 @@ static void checkForFailure(UErrorCode* status) *status = U_ZERO_ERROR; } -std::vector convertToPropertyNames(const IDDictionaryMetaData* dictionary, int64_t value) +std::vector convertToPropertyNames(const IDDictionaryMetaData* dictionary, uint64_t value) { std::vector result; - char16_t name[64] = { }; + char16_t name[64] = { }; while (value != 0) { - const auto singleProperty = ((int64_t)(((uint64_t)(value ^ (value - 1))) >> 1)) + 1; + const auto singleProperty = ((value ^ (value - 1)) >> 1) + 1; value &= value - 1; auto error = U_ZERO_ERROR; int len = iddmd_getPropertyName(dictionary, singleProperty, name, std::size(name), &error); diff --git a/tools/buildDictionary/LexicalDictionaryBuilder.cpp b/tools/buildDictionary/LexicalDictionaryBuilder.cpp index 9fd228b79..95fcb2046 100644 --- a/tools/buildDictionary/LexicalDictionaryBuilder.cpp +++ b/tools/buildDictionary/LexicalDictionaryBuilder.cpp @@ -125,11 +125,11 @@ static ::std::map createBitsToContainerBitsMap( return valueBitsToContainerBits; } -static int64_t mapValueToContainerBits(int64_t binaryProperties, std::map bitmap) +static int64_t mapValueToContainerBits(uint64_t binaryProperties, std::map bitmap) { int64_t result = 0; while (binaryProperties != 0) { - auto singleProperty = ((int64_t) (((uint64_t) (binaryProperties ^ (binaryProperties - 1))) >> 1)) + 1; + auto singleProperty = ((binaryProperties ^ (binaryProperties - 1)) >> 1) + 1; binaryProperties &= binaryProperties - 1; auto newBitItr = bitmap.find(singleProperty); if (newBitItr == bitmap.end()) {