head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.1
	netbsd-11-0-RC3:1.1.1.1
	netbsd-11-0-RC2:1.1.1.1
	netbsd-11-0-RC1:1.1.1.1
	perseant-exfatfs-base-20250801:1.1.1.1
	netbsd-11:1.1.1.1.0.42
	netbsd-11-base:1.1.1.1
	netbsd-10-1-RELEASE:1.1.1.1
	perseant-exfatfs-base-20240630:1.1.1.1
	perseant-exfatfs:1.1.1.1.0.40
	perseant-exfatfs-base:1.1.1.1
	netbsd-9-4-RELEASE:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.1
	netbsd-10-0-RC6:1.1.1.1
	netbsd-10-0-RC5:1.1.1.1
	netbsd-10-0-RC4:1.1.1.1
	netbsd-10-0-RC3:1.1.1.1
	netbsd-10-0-RC2:1.1.1.1
	thorpej-ifq:1.1.1.1.0.38
	thorpej-ifq-base:1.1.1.1
	thorpej-altq-separation:1.1.1.1.0.36
	thorpej-altq-separation-base:1.1.1.1
	netbsd-10-0-RC1:1.1.1.1
	netbsd-10:1.1.1.1.0.34
	netbsd-10-base:1.1.1.1
	bouyer-sunxi-drm:1.1.1.1.0.32
	bouyer-sunxi-drm-base:1.1.1.1
	netbsd-9-3-RELEASE:1.1.1.1
	thorpej-i2c-spi-conf2:1.1.1.1.0.30
	thorpej-i2c-spi-conf2-base:1.1.1.1
	thorpej-futex2:1.1.1.1.0.28
	thorpej-futex2-base:1.1.1.1
	thorpej-cfargs2:1.1.1.1.0.26
	thorpej-cfargs2-base:1.1.1.1
	cjep_sun2x-base1:1.1.1.1
	cjep_sun2x:1.1.1.1.0.24
	cjep_sun2x-base:1.1.1.1
	cjep_staticlib_x-base1:1.1.1.1
	netbsd-9-2-RELEASE:1.1.1.1
	cjep_staticlib_x:1.1.1.1.0.22
	cjep_staticlib_x-base:1.1.1.1
	thorpej-i2c-spi-conf:1.1.1.1.0.20
	thorpej-i2c-spi-conf-base:1.1.1.1
	thorpej-cfargs:1.1.1.1.0.18
	thorpej-cfargs-base:1.1.1.1
	thorpej-futex:1.1.1.1.0.16
	thorpej-futex-base:1.1.1.1
	netbsd-9-1-RELEASE:1.1.1.1
	bouyer-xenpvh-base2:1.1.1.1
	phil-wifi-20200421:1.1.1.1
	bouyer-xenpvh-base1:1.1.1.1
	phil-wifi-20200411:1.1.1.1
	bouyer-xenpvh:1.1.1.1.0.14
	bouyer-xenpvh-base:1.1.1.1
	is-mlppp:1.1.1.1.0.12
	is-mlppp-base:1.1.1.1
	phil-wifi-20200406:1.1.1.1
	ad-namecache-base3:1.1.1.1
	netbsd-9-0-RELEASE:1.1.1.1
	netbsd-9-0-RC2:1.1.1.1
	ad-namecache-base2:1.1.1.1
	ad-namecache-base1:1.1.1.1
	ad-namecache:1.1.1.1.0.10
	ad-namecache-base:1.1.1.1
	netbsd-9-0-RC1:1.1.1.1
	phil-wifi-20191119:1.1.1.1
	netbsd-9:1.1.1.1.0.8
	netbsd-9-base:1.1.1.1
	phil-wifi:1.1.1.1.0.6
	phil-wifi-20190609:1.1.1.1
	isaki-audio2:1.1.1.1.0.4
	isaki-audio2-base:1.1.1.1
	pgoyette-compat-merge-20190127:1.1.1.1.2.2
	pgoyette-compat-20190127:1.1.1.1
	pgoyette-compat:1.1.1.1.0.2
	pgoyette-compat-20190118:1.1.1.1
	compiler-rt-350590:1.1.1.1
	LLVM:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2019.01.08.05.40.32;	author kamil;	state Exp;
branches
	1.1.1.1;
next	;
commitid	JxKaWKiFa0y4nW6B;

1.1.1.1
date	2019.01.08.05.40.32;	author kamil;	state Exp;
branches
	1.1.1.1.2.1
	1.1.1.1.6.1;
next	;
commitid	JxKaWKiFa0y4nW6B;

1.1.1.1.2.1
date	2019.01.08.05.40.32;	author pgoyette;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	Lmlzg3OVT2cd6f8B;

1.1.1.1.2.2
date	2019.01.18.08.50.51;	author pgoyette;	state Exp;
branches;
next	;
commitid	Lmlzg3OVT2cd6f8B;

1.1.1.1.6.1
date	2019.01.08.05.40.32;	author christos;	state dead;
branches;
next	1.1.1.1.6.2;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.1.6.2
date	2019.06.10.22.07.48;	author christos;	state Exp;
branches;
next	;
commitid	jtc8rnCzWiEEHGqB;


desc
@@


1.1
log
@Initial revision
@
text
@include(CheckCXXCompilerFlag)
include(CompilerRTCompile)
include(CompilerRTLink)

include_directories(..)
include_directories(../..)

set(MSAN_LIBCXX_CFLAGS
  -fsanitize=memory
  -fsanitize-memory-track-origins
  -Wno-pedantic)

# Unittest sources and build flags.
set(MSAN_UNITTEST_SOURCES msan_test.cc msan_test_main.cc)
set(MSAN_LOADABLE_SOURCE msan_loadable.cc)
set(MSAN_UNITTEST_HEADERS
  msan_test_config.h
  ../../../include/sanitizer/msan_interface.h
)
set(MSAN_UNITTEST_COMMON_CFLAGS
  -nostdinc++
  -isystem ${COMPILER_RT_LIBCXX_PATH}/include
  ${COMPILER_RT_UNITTEST_CFLAGS}
  ${COMPILER_RT_GTEST_CFLAGS}
  -I${COMPILER_RT_SOURCE_DIR}/include
  -I${COMPILER_RT_SOURCE_DIR}/lib
  -I${COMPILER_RT_SOURCE_DIR}/lib/msan
  -g
  -O2
  -fno-exceptions
  -fno-omit-frame-pointer
  -mno-omit-leaf-frame-pointer
  -Wno-deprecated-declarations
  -Wno-unused-variable
  -Wno-zero-length-array
  -Wno-uninitialized
  -Werror=sign-compare
  -Wno-gnu-zero-variadic-macro-arguments
)
# Remove -stdlib= which is unused when passing -nostdinc++.
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

set(MSAN_UNITTEST_INSTRUMENTED_CFLAGS
  ${MSAN_UNITTEST_COMMON_CFLAGS}
  -fsanitize=memory
  -fsanitize-memory-track-origins
  -mllvm -msan-keep-going=1
)
set(MSAN_UNITTEST_LINK_FLAGS
  -fsanitize=memory
  # Don't need -stdlib=libc++ because we explicitly list libc++.so in the linker
  # inputs.
  # FIXME: we build libcxx without cxxabi and need libstdc++ to provide it.
  -lstdc++
)

append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS)

macro(msan_compile obj_list source arch kind cflags)
  sanitizer_test_compile(
    ${obj_list} ${source} ${arch}
    KIND ${kind}
    COMPILE_DEPS ${MSAN_UNITTEST_HEADERS}
    DEPS gtest msan
    CFLAGS ${MSAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags}
  )
endmacro()

macro(msan_link_shared so_list so_name arch kind)
  cmake_parse_arguments(SOURCE "" "" "OBJECTS;LINK_FLAGS;DEPS" ${ARGN})
  set(output_so "${CMAKE_CURRENT_BINARY_DIR}/${so_name}.${arch}${kind}.so")
  get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
  if(NOT COMPILER_RT_STANDALONE_BUILD)
    list(APPEND SOURCE_DEPS msan)
  endif()
  clang_link_shared(${output_so}
                OBJECTS ${SOURCE_OBJECTS}
                LINK_FLAGS ${TARGET_LINK_FLAGS} ${SOURCE_LINK_FLAGS}
                DEPS ${SOURCE_DEPS})
  list(APPEND ${so_list} ${output_so})
endmacro()

# Main MemorySanitizer unit tests.
add_custom_target(MsanUnitTests)
set_target_properties(MsanUnitTests PROPERTIES FOLDER "MSan unit tests")

# Adds MSan unit tests and benchmarks for architecture.
macro(add_msan_tests_for_arch arch kind cflags)
  # Build gtest instrumented with MSan.
  set(MSAN_INST_GTEST)
  msan_compile(MSAN_INST_GTEST ${COMPILER_RT_GTEST_SOURCE} ${arch} "${kind}"
                               "${cflags}")

  # Instrumented tests.
  set(MSAN_INST_TEST_OBJECTS)
  foreach (SOURCE ${MSAN_UNITTEST_SOURCES})
    msan_compile(MSAN_INST_TEST_OBJECTS ${SOURCE} ${arch} "${kind}" "${cflags}")
  endforeach(SOURCE)

  # Instrumented loadable module objects.
  set(MSAN_INST_LOADABLE_OBJECTS)
  msan_compile(MSAN_INST_LOADABLE_OBJECTS ${MSAN_LOADABLE_SOURCE} ${arch} "${kind}"
               "-fPIC;${cflags}")

  # Instrumented loadable library tests.
  set(MSAN_LOADABLE_SO)
  msan_link_shared(MSAN_LOADABLE_SO "libmsan_loadable" ${arch} "${kind}"
                   OBJECTS ${MSAN_INST_LOADABLE_OBJECTS}
                   DEPS ${MSAN_INST_LOADABLE_OBJECTS})

  set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST})
  set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-build
                     ${MSAN_LOADABLE_SO})
  if(NOT COMPILER_RT_STANDALONE_BUILD)
    list(APPEND MSAN_TEST_DEPS msan)
  endif()
  get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
  add_compiler_rt_test(MsanUnitTests "Msan-${arch}${kind}-Test" ${arch}
    OBJECTS ${MSAN_TEST_OBJECTS} ${MSAN_LIBCXX_SO}
    DEPS ${MSAN_TEST_DEPS}
    LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
               ${TARGET_LINK_FLAGS}
               "-Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR}"
               "-Wl,-rpath=${LIBCXX_PREFIX}/lib")
endmacro()

# We should only build MSan unit tests if we can build instrumented libcxx.
if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_LIBCXX_PATH)
  foreach(arch ${MSAN_SUPPORTED_ARCH})
    get_target_flags_for_arch(${arch} TARGET_CFLAGS)
    set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch})
    add_custom_libcxx(libcxx_msan_${arch} ${LIBCXX_PREFIX}
      DEPS ${MSAN_RUNTIME_LIBRARIES}
      CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS}
      USE_TOOLCHAIN)
    set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}/lib/libc++.so)

    add_msan_tests_for_arch(${arch} "" "")
    add_msan_tests_for_arch(${arch} "-with-call"
                            "-mllvm;-msan-instrumentation-with-call-threshold=0")
  endforeach()
endif()
@


1.1.1.1
log
@Import compiler-rt r350590. LLVM sanitizers on top of unmodified files from compiler-rt-259194.
@
text
@@


1.1.1.1.6.1
log
@file CMakeLists.txt was added on branch phil-wifi on 2019-06-10 22:07:48 +0000
@
text
@d1 142
@


1.1.1.1.6.2
log
@Sync with HEAD
@
text
@a0 142
include(CheckCXXCompilerFlag)
include(CompilerRTCompile)
include(CompilerRTLink)

include_directories(..)
include_directories(../..)

set(MSAN_LIBCXX_CFLAGS
  -fsanitize=memory
  -fsanitize-memory-track-origins
  -Wno-pedantic)

# Unittest sources and build flags.
set(MSAN_UNITTEST_SOURCES msan_test.cc msan_test_main.cc)
set(MSAN_LOADABLE_SOURCE msan_loadable.cc)
set(MSAN_UNITTEST_HEADERS
  msan_test_config.h
  ../../../include/sanitizer/msan_interface.h
)
set(MSAN_UNITTEST_COMMON_CFLAGS
  -nostdinc++
  -isystem ${COMPILER_RT_LIBCXX_PATH}/include
  ${COMPILER_RT_UNITTEST_CFLAGS}
  ${COMPILER_RT_GTEST_CFLAGS}
  -I${COMPILER_RT_SOURCE_DIR}/include
  -I${COMPILER_RT_SOURCE_DIR}/lib
  -I${COMPILER_RT_SOURCE_DIR}/lib/msan
  -g
  -O2
  -fno-exceptions
  -fno-omit-frame-pointer
  -mno-omit-leaf-frame-pointer
  -Wno-deprecated-declarations
  -Wno-unused-variable
  -Wno-zero-length-array
  -Wno-uninitialized
  -Werror=sign-compare
  -Wno-gnu-zero-variadic-macro-arguments
)
# Remove -stdlib= which is unused when passing -nostdinc++.
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

set(MSAN_UNITTEST_INSTRUMENTED_CFLAGS
  ${MSAN_UNITTEST_COMMON_CFLAGS}
  -fsanitize=memory
  -fsanitize-memory-track-origins
  -mllvm -msan-keep-going=1
)
set(MSAN_UNITTEST_LINK_FLAGS
  -fsanitize=memory
  # Don't need -stdlib=libc++ because we explicitly list libc++.so in the linker
  # inputs.
  # FIXME: we build libcxx without cxxabi and need libstdc++ to provide it.
  -lstdc++
)

append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS)

macro(msan_compile obj_list source arch kind cflags)
  sanitizer_test_compile(
    ${obj_list} ${source} ${arch}
    KIND ${kind}
    COMPILE_DEPS ${MSAN_UNITTEST_HEADERS}
    DEPS gtest msan
    CFLAGS ${MSAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags}
  )
endmacro()

macro(msan_link_shared so_list so_name arch kind)
  cmake_parse_arguments(SOURCE "" "" "OBJECTS;LINK_FLAGS;DEPS" ${ARGN})
  set(output_so "${CMAKE_CURRENT_BINARY_DIR}/${so_name}.${arch}${kind}.so")
  get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
  if(NOT COMPILER_RT_STANDALONE_BUILD)
    list(APPEND SOURCE_DEPS msan)
  endif()
  clang_link_shared(${output_so}
                OBJECTS ${SOURCE_OBJECTS}
                LINK_FLAGS ${TARGET_LINK_FLAGS} ${SOURCE_LINK_FLAGS}
                DEPS ${SOURCE_DEPS})
  list(APPEND ${so_list} ${output_so})
endmacro()

# Main MemorySanitizer unit tests.
add_custom_target(MsanUnitTests)
set_target_properties(MsanUnitTests PROPERTIES FOLDER "MSan unit tests")

# Adds MSan unit tests and benchmarks for architecture.
macro(add_msan_tests_for_arch arch kind cflags)
  # Build gtest instrumented with MSan.
  set(MSAN_INST_GTEST)
  msan_compile(MSAN_INST_GTEST ${COMPILER_RT_GTEST_SOURCE} ${arch} "${kind}"
                               "${cflags}")

  # Instrumented tests.
  set(MSAN_INST_TEST_OBJECTS)
  foreach (SOURCE ${MSAN_UNITTEST_SOURCES})
    msan_compile(MSAN_INST_TEST_OBJECTS ${SOURCE} ${arch} "${kind}" "${cflags}")
  endforeach(SOURCE)

  # Instrumented loadable module objects.
  set(MSAN_INST_LOADABLE_OBJECTS)
  msan_compile(MSAN_INST_LOADABLE_OBJECTS ${MSAN_LOADABLE_SOURCE} ${arch} "${kind}"
               "-fPIC;${cflags}")

  # Instrumented loadable library tests.
  set(MSAN_LOADABLE_SO)
  msan_link_shared(MSAN_LOADABLE_SO "libmsan_loadable" ${arch} "${kind}"
                   OBJECTS ${MSAN_INST_LOADABLE_OBJECTS}
                   DEPS ${MSAN_INST_LOADABLE_OBJECTS})

  set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST})
  set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-build
                     ${MSAN_LOADABLE_SO})
  if(NOT COMPILER_RT_STANDALONE_BUILD)
    list(APPEND MSAN_TEST_DEPS msan)
  endif()
  get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
  add_compiler_rt_test(MsanUnitTests "Msan-${arch}${kind}-Test" ${arch}
    OBJECTS ${MSAN_TEST_OBJECTS} ${MSAN_LIBCXX_SO}
    DEPS ${MSAN_TEST_DEPS}
    LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
               ${TARGET_LINK_FLAGS}
               "-Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR}"
               "-Wl,-rpath=${LIBCXX_PREFIX}/lib")
endmacro()

# We should only build MSan unit tests if we can build instrumented libcxx.
if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_LIBCXX_PATH)
  foreach(arch ${MSAN_SUPPORTED_ARCH})
    get_target_flags_for_arch(${arch} TARGET_CFLAGS)
    set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch})
    add_custom_libcxx(libcxx_msan_${arch} ${LIBCXX_PREFIX}
      DEPS ${MSAN_RUNTIME_LIBRARIES}
      CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS}
      USE_TOOLCHAIN)
    set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}/lib/libc++.so)

    add_msan_tests_for_arch(${arch} "" "")
    add_msan_tests_for_arch(${arch} "-with-call"
                            "-mllvm;-msan-instrumentation-with-call-threshold=0")
  endforeach()
endif()
@


1.1.1.1.2.1
log
@file CMakeLists.txt was added on branch pgoyette-compat on 2019-01-18 08:50:51 +0000
@
text
@d1 142
@


1.1.1.1.2.2
log
@Synch with HEAD
@
text
@a0 142
include(CheckCXXCompilerFlag)
include(CompilerRTCompile)
include(CompilerRTLink)

include_directories(..)
include_directories(../..)

set(MSAN_LIBCXX_CFLAGS
  -fsanitize=memory
  -fsanitize-memory-track-origins
  -Wno-pedantic)

# Unittest sources and build flags.
set(MSAN_UNITTEST_SOURCES msan_test.cc msan_test_main.cc)
set(MSAN_LOADABLE_SOURCE msan_loadable.cc)
set(MSAN_UNITTEST_HEADERS
  msan_test_config.h
  ../../../include/sanitizer/msan_interface.h
)
set(MSAN_UNITTEST_COMMON_CFLAGS
  -nostdinc++
  -isystem ${COMPILER_RT_LIBCXX_PATH}/include
  ${COMPILER_RT_UNITTEST_CFLAGS}
  ${COMPILER_RT_GTEST_CFLAGS}
  -I${COMPILER_RT_SOURCE_DIR}/include
  -I${COMPILER_RT_SOURCE_DIR}/lib
  -I${COMPILER_RT_SOURCE_DIR}/lib/msan
  -g
  -O2
  -fno-exceptions
  -fno-omit-frame-pointer
  -mno-omit-leaf-frame-pointer
  -Wno-deprecated-declarations
  -Wno-unused-variable
  -Wno-zero-length-array
  -Wno-uninitialized
  -Werror=sign-compare
  -Wno-gnu-zero-variadic-macro-arguments
)
# Remove -stdlib= which is unused when passing -nostdinc++.
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

set(MSAN_UNITTEST_INSTRUMENTED_CFLAGS
  ${MSAN_UNITTEST_COMMON_CFLAGS}
  -fsanitize=memory
  -fsanitize-memory-track-origins
  -mllvm -msan-keep-going=1
)
set(MSAN_UNITTEST_LINK_FLAGS
  -fsanitize=memory
  # Don't need -stdlib=libc++ because we explicitly list libc++.so in the linker
  # inputs.
  # FIXME: we build libcxx without cxxabi and need libstdc++ to provide it.
  -lstdc++
)

append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS)

macro(msan_compile obj_list source arch kind cflags)
  sanitizer_test_compile(
    ${obj_list} ${source} ${arch}
    KIND ${kind}
    COMPILE_DEPS ${MSAN_UNITTEST_HEADERS}
    DEPS gtest msan
    CFLAGS ${MSAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags}
  )
endmacro()

macro(msan_link_shared so_list so_name arch kind)
  cmake_parse_arguments(SOURCE "" "" "OBJECTS;LINK_FLAGS;DEPS" ${ARGN})
  set(output_so "${CMAKE_CURRENT_BINARY_DIR}/${so_name}.${arch}${kind}.so")
  get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
  if(NOT COMPILER_RT_STANDALONE_BUILD)
    list(APPEND SOURCE_DEPS msan)
  endif()
  clang_link_shared(${output_so}
                OBJECTS ${SOURCE_OBJECTS}
                LINK_FLAGS ${TARGET_LINK_FLAGS} ${SOURCE_LINK_FLAGS}
                DEPS ${SOURCE_DEPS})
  list(APPEND ${so_list} ${output_so})
endmacro()

# Main MemorySanitizer unit tests.
add_custom_target(MsanUnitTests)
set_target_properties(MsanUnitTests PROPERTIES FOLDER "MSan unit tests")

# Adds MSan unit tests and benchmarks for architecture.
macro(add_msan_tests_for_arch arch kind cflags)
  # Build gtest instrumented with MSan.
  set(MSAN_INST_GTEST)
  msan_compile(MSAN_INST_GTEST ${COMPILER_RT_GTEST_SOURCE} ${arch} "${kind}"
                               "${cflags}")

  # Instrumented tests.
  set(MSAN_INST_TEST_OBJECTS)
  foreach (SOURCE ${MSAN_UNITTEST_SOURCES})
    msan_compile(MSAN_INST_TEST_OBJECTS ${SOURCE} ${arch} "${kind}" "${cflags}")
  endforeach(SOURCE)

  # Instrumented loadable module objects.
  set(MSAN_INST_LOADABLE_OBJECTS)
  msan_compile(MSAN_INST_LOADABLE_OBJECTS ${MSAN_LOADABLE_SOURCE} ${arch} "${kind}"
               "-fPIC;${cflags}")

  # Instrumented loadable library tests.
  set(MSAN_LOADABLE_SO)
  msan_link_shared(MSAN_LOADABLE_SO "libmsan_loadable" ${arch} "${kind}"
                   OBJECTS ${MSAN_INST_LOADABLE_OBJECTS}
                   DEPS ${MSAN_INST_LOADABLE_OBJECTS})

  set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST})
  set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-build
                     ${MSAN_LOADABLE_SO})
  if(NOT COMPILER_RT_STANDALONE_BUILD)
    list(APPEND MSAN_TEST_DEPS msan)
  endif()
  get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
  add_compiler_rt_test(MsanUnitTests "Msan-${arch}${kind}-Test" ${arch}
    OBJECTS ${MSAN_TEST_OBJECTS} ${MSAN_LIBCXX_SO}
    DEPS ${MSAN_TEST_DEPS}
    LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
               ${TARGET_LINK_FLAGS}
               "-Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR}"
               "-Wl,-rpath=${LIBCXX_PREFIX}/lib")
endmacro()

# We should only build MSan unit tests if we can build instrumented libcxx.
if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_LIBCXX_PATH)
  foreach(arch ${MSAN_SUPPORTED_ARCH})
    get_target_flags_for_arch(${arch} TARGET_CFLAGS)
    set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch})
    add_custom_libcxx(libcxx_msan_${arch} ${LIBCXX_PREFIX}
      DEPS ${MSAN_RUNTIME_LIBRARIES}
      CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS}
      USE_TOOLCHAIN)
    set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}/lib/libc++.so)

    add_msan_tests_for_arch(${arch} "" "")
    add_msan_tests_for_arch(${arch} "-with-call"
                            "-mllvm;-msan-instrumentation-with-call-threshold=0")
  endforeach()
endif()
@


