[llvm] 905f874 - [cmake] Add LLVM_UBSAN_FLAGS, to allow overriding UBSan flags
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 26 15:48:28 PDT 2020
Author: Vedant Kumar
Date: 2020-10-26T15:48:19-07:00
New Revision: 905f874c449cc114d74eaeb19639664779fd0b6e
URL: https://github.com/llvm/llvm-project/commit/905f874c449cc114d74eaeb19639664779fd0b6e
DIFF: https://github.com/llvm/llvm-project/commit/905f874c449cc114d74eaeb19639664779fd0b6e.diff
LOG: [cmake] Add LLVM_UBSAN_FLAGS, to allow overriding UBSan flags
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.
Differential Revision: https://reviews.llvm.org/D89439
Added:
Modified:
llvm/CMakeLists.txt
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/docs/CMake.rst
Removed:
################################################################################
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index ebc6733b5873..21563e151180 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -487,6 +487,10 @@ endif( LLVM_USE_PERF )
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")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index ddf2b6e3b688..78ed1c06ac9d 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -776,8 +776,7 @@ if(LLVM_USE_SANITIZER)
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 @@ if(LLVM_USE_SANITIZER)
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)
diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 5a73b7d45211..bb821b417ad9 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -428,6 +428,11 @@ LLVM-specific variables
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``,
More information about the llvm-commits
mailing list