[PATCH] D151511: Enable building with UBSAN + enable_ubsan_clang_cl on windows
Duo Wang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 26 10:14:40 PDT 2023
dwang updated this revision to Diff 526109.
dwang added a comment.
- Update ubsan_ignorelist to exempt false-positives for 0-sized objects. Build crashes if those files are not exempted.
- Refine HandleLLVMOptions.cmake
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151511/new/
https://reviews.llvm.org/D151511
Files:
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/utils/sanitizers/ubsan_ignorelist.txt
Index: llvm/utils/sanitizers/ubsan_ignorelist.txt
===================================================================
--- llvm/utils/sanitizers/ubsan_ignorelist.txt
+++ llvm/utils/sanitizers/ubsan_ignorelist.txt
@@ -14,3 +14,10 @@
# libstdc++ 8.0.1 casts an under-aligned pointer to type type_info:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85930
src:*bits/shared_ptr_base.h
+
+# UBSAN reports false-positive for 0-sized objects
+# https://github.com/llvm/llvm-project/issues/61775
+src:*/ADT/StringMap.h
+src:*/Support/AllocatorBase.h
+src:*/ADT/StringMapEntry.h
+src:*/ADT/SmallPtrSet.h
\ No newline at end of file
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -846,7 +846,7 @@
endif()
macro(append_common_sanitizer_flags)
- if (NOT MSVC)
+ if (NOT MSVC OR CLANG_CL)
# Append -fno-omit-frame-pointer and turn on debug info to get better
# stack traces.
add_flag_if_supported("-fno-omit-frame-pointer" FNO_OMIT_FRAME_POINTER)
@@ -925,23 +925,18 @@
message(FATAL_ERROR "This sanitizer not yet supported in a MinGW environment: ${LLVM_USE_SANITIZER}")
endif()
elseif(MSVC)
- if (LLVM_USE_SANITIZER STREQUAL "Address")
- append_common_sanitizer_flags()
- append("/fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
- if (NOT CLANG_CL)
- # Not compatible with /RTC flags.
- foreach (flags_opt_to_scrub
- CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE})
- string (REGEX REPLACE "(^| )/RTC[1csu]*($| )" " "
- "${flags_opt_to_scrub}" "${${flags_opt_to_scrub}}")
- endforeach()
+ if (NOT LLVM_USE_SANITIZER MATCHES "^(Address|Undefined|Address;Undefined|Undefined;Address)$")
+ message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${LLVM_USE_SANITIZER}")
+ endif()
+ append_common_sanitizer_flags()
+ if (LINKER_IS_LLD_LINK)
+ if (LLVM_HOST_TRIPLE MATCHES "i[2-6]86-.*")
+ set(arch "i386")
+ else()
+ set(arch "x86_64")
endif()
- if (LINKER_IS_LLD_LINK)
- if (LLVM_HOST_TRIPLE MATCHES "i[2-6]86-.*")
- set(arch "i386")
- else()
- set(arch "x86_64")
- endif()
+ # Prepare ASAN runtime if needed
+ if (LLVM_USE_SANITIZER MATCHES ".*Address.*")
if (${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
append("/wholearchive:clang_rt.asan-${arch}.lib /wholearchive:clang_rt.asan_cxx-${arch}.lib"
CMAKE_EXE_LINKER_FLAGS)
@@ -952,8 +947,26 @@
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
endif()
endif()
- else()
- message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${LLVM_USE_SANITIZER}")
+ endif()
+ if (LLVM_USE_SANITIZER MATCHES ".*Address.*")
+ if (NOT CLANG_CL)
+ append("/fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ # Not compatible with /RTC flags.
+ foreach (flags_opt_to_scrub
+ CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE})
+ string (REGEX REPLACE "(^| )/RTC[1csu]*($| )" " "
+ "${flags_opt_to_scrub}" "${${flags_opt_to_scrub}}")
+ endforeach()
+ else()
+ append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ endif()
+ endif()
+ if (LLVM_USE_SANITIZER MATCHES ".*Undefined.*")
+ if (NOT CLANG_CL)
+ message(FATAL_ERROR "This sanitizer only supported in the clang-cl: Undefined")
+ endif()
+ append("-D_ITERATOR_DEBUG_LEVEL=0" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append(${LLVM_UBSAN_FLAGS} CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endif()
else()
message(FATAL_ERROR "LLVM_USE_SANITIZER is not supported on this platform.")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151511.526109.patch
Type: text/x-patch
Size: 4006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230526/64c3ec2a/attachment.bin>
More information about the llvm-commits
mailing list