Skip to content

Commit 5601e35

Browse files
authored
[memprof] Use COMPILER_RT_TEST_COMPILER
Unlike the other compiler-rt unit tests MemProf was not using the `generate_compiler_rt_tests()` helper that ensures the test is compiled using the test compiler (generally the Clang binary built earlier). This was exposed by #83088 because it started adding Clang-specific flags to COMPILER_RT_UNITTEST_CFLAGS if the compiler ID matched "Clang". This change should fix the buildbots that compile compiler-rt using a GCC compiler with LLVM_ENABLE_PROJECTS=compiler-rt. Reviewed By: vitalybuka Pull Request: #88074
1 parent 3009228 commit 5601e35

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

compiler-rt/lib/memprof/tests/CMakeLists.txt

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,47 @@ if(NOT WIN32)
4141
list(APPEND MEMPROF_UNITTEST_LINK_FLAGS -pthread)
4242
endif()
4343

44+
set(MEMPROF_UNITTEST_DEPS)
45+
if (TARGET cxx-headers OR HAVE_LIBCXX)
46+
list(APPEND MEMPROF_UNITTEST_DEPS cxx-headers)
47+
endif()
48+
4449
set(MEMPROF_UNITTEST_LINK_LIBRARIES
4550
${COMPILER_RT_UNWINDER_LINK_LIBS}
4651
${SANITIZER_TEST_CXX_LIBRARIES})
47-
list(APPEND MEMPROF_UNITTEST_LINK_LIBRARIES "dl")
48-
49-
if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST MEMPROF_SUPPORTED_ARCH)
50-
# MemProf unit tests are only run on the host machine.
51-
set(arch ${COMPILER_RT_DEFAULT_TARGET_ARCH})
52+
append_list_if(COMPILER_RT_HAS_LIBDL -ldl MEMPROF_UNITTEST_LINK_LIBRARIES)
5253

53-
add_executable(MemProfUnitTests
54-
${MEMPROF_UNITTESTS}
55-
${COMPILER_RT_GTEST_SOURCE}
56-
${COMPILER_RT_GMOCK_SOURCE}
57-
${MEMPROF_SOURCES}
54+
# Adds memprof tests for each architecture.
55+
macro(add_memprof_tests_for_arch arch)
56+
set(MEMPROF_TEST_RUNTIME_OBJECTS
5857
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
5958
$<TARGET_OBJECTS:RTSanitizerCommonCoverage.${arch}>
6059
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
6160
$<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
62-
$<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>)
63-
set_target_compile_flags(MemProfUnitTests ${MEMPROF_UNITTEST_CFLAGS})
64-
set_target_link_flags(MemProfUnitTests ${MEMPROF_UNITTEST_LINK_FLAGS})
65-
target_link_libraries(MemProfUnitTests ${MEMPROF_UNITTEST_LINK_LIBRARIES})
66-
67-
if (TARGET cxx-headers OR HAVE_LIBCXX)
68-
add_dependencies(MemProfUnitTests cxx-headers)
69-
endif()
61+
$<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>
62+
)
63+
set(MEMPROF_TEST_RUNTIME RTMemProfTest.${arch})
64+
add_library(${MEMPROF_TEST_RUNTIME} STATIC ${MEMPROF_TEST_RUNTIME_OBJECTS})
65+
set_target_properties(${MEMPROF_TEST_RUNTIME} PROPERTIES
66+
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
67+
FOLDER "Compiler-RT Runtime tests")
68+
set(MEMPROF_TEST_OBJECTS)
69+
generate_compiler_rt_tests(MEMPROF_TEST_OBJECTS
70+
MemProfUnitTests "MemProf-${arch}-UnitTest" ${arch}
71+
RUNTIME ${MEMPROF_TEST_RUNTIME}
72+
DEPS ${MEMPROF_UNITTEST_DEPS}
73+
SOURCES ${MEMPROF_UNITTESTS} ${MEMPROF_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
74+
COMPILE_DEPS ${MEMPROF_UNIT_TEST_HEADERS}
75+
CFLAGS ${MEMPROF_UNITTEST_CFLAGS}
76+
LINK_FLAGS ${MEMPROF_UNITTEST_LINK_FLAGS} ${MEMPROF_UNITTEST_LINK_LIBRARIES})
77+
endmacro()
7078

71-
set_target_properties(MemProfUnitTests PROPERTIES
72-
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
79+
# MemProf unit tests testsuite.
80+
add_custom_target(MemProfUnitTests)
81+
set_target_properties(MemProfUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
82+
if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST MEMPROF_SUPPORTED_ARCH)
83+
# MemProf unit tests are only run on the host machine.
84+
foreach(arch ${COMPILER_RT_DEFAULT_TARGET_ARCH})
85+
add_memprof_tests_for_arch(${arch})
86+
endforeach()
7387
endif()

0 commit comments

Comments
 (0)