[PATCH] D89439: [cmake] Add LLVM_UBSAN_FLAGS, to allow overriding UBSan flags
Vedant Kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 19:12:14 PDT 2020
vsk created this revision.
vsk added reviewers: JDevlieghere, kastiglione.
Herald added a subscriber: mgorny.
Herald added a project: LLVM.
vsk requested review of this revision.
Allow overriding the default set of flags used to enable UBSan when
building llvm.
This can be used to test new checks or opt out of certain checks.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89439
Files:
llvm/CMakeLists.txt
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/docs/CMake.rst
Index: llvm/docs/CMake.rst
===================================================================
--- llvm/docs/CMake.rst
+++ llvm/docs/CMake.rst
@@ -428,6 +428,11 @@
are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``,
``DataFlow``, and ``Address;Undefined``. Defaults to empty string.
+**LLVM_UBSAN_FLAGS**:STRING
+ Defines the set of compile flags used to enable UBSan. Only used if
+ ``LLVM_USE_SANITIZER`` contains ``Undefined``. This can be used to override
+ the default set of UBSan flags.
+
**LLVM_ENABLE_LTO**:STRING
Add ``-flto`` or ``-flto=`` flags to the compile and link command
lines, enabling link-time optimization. Possible values are ``Off``,
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -776,8 +776,7 @@
endif()
elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
append_common_sanitizer_flags()
- append("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all"
- CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif (LLVM_USE_SANITIZER STREQUAL "Thread")
append_common_sanitizer_flags()
append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
@@ -786,8 +785,8 @@
elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
append_common_sanitizer_flags()
- append("-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all"
- CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif (LLVM_USE_SANITIZER STREQUAL "Leaks")
append_common_sanitizer_flags()
append("-fsanitize=leak" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -487,6 +487,10 @@
set(LLVM_USE_SANITIZER "" CACHE STRING
"Define the sanitizer used to build binaries and tests.")
option(LLVM_OPTIMIZE_SANITIZED_BUILDS "Pass -O1 on debug sanitizer builds" ON)
+set(LLVM_UBSAN_FLAGS
+ "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all"
+ CACHE STRING
+ "Compile flags set to enable UBSan. Only used if LLVM_USE_SANITIZER contains 'Undefined'.")
set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH
"Path to fuzzing library for linking with fuzz targets")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89439.298277.patch
Type: text/x-patch
Size: 2686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201015/e9491c3e/attachment.bin>
More information about the llvm-commits
mailing list