[llvm-commits] [compiler-rt] r159345 - in /compiler-rt/trunk/lib/asan/tests: CMakeLists.txt asan_mac_test.mm

Alexey Samsonov samsonov at google.com
Thu Jun 28 05:19:52 PDT 2012


Author: samsonov
Date: Thu Jun 28 07:19:52 2012
New Revision: 159345

URL: http://llvm.org/viewvc/llvm-project?rev=159345&view=rev
Log:
[ASan] cmake support for running asan unit tests on Mac

Modified:
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=159345&r1=159344&r2=159345&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Thu Jun 28 07:19:52 2012
@@ -14,6 +14,11 @@
 include_directories(..)
 include_directories(../..)
 
+set(ASAN_UNITTEST_COMMON_CFLAGS 
+  -Wall
+  -fvisibility=hidden
+)
+
 add_custom_target(AsanTests)
 set_target_properties(AsanTests PROPERTIES FOLDER "ASan tests")
 function(add_asan_test testname)
@@ -23,6 +28,17 @@
 	else()
 		target_link_libraries(${testname} clang_rt.asan-x86_64)
 	endif()
+	if (APPLE)
+		# Darwin-specific linker flags.
+		set_target_properties(${testname} PROPERTIES
+		  LINK_FLAGS "-framework Foundation")
+	endif()
+	get_property(compile_flags TARGET ${testname} PROPERTY COMPILE_FLAGS)
+	foreach(arg ${ASAN_UNITTEST_COMMON_CFLAGS})
+	  set(add_compile_flags "${add_compile_flags} ${arg}")
+	endforeach(arg ${ASAN_UNITTEST_COMMON_CFLAGS})
+	set_property(TARGET ${testname} PROPERTY COMPILE_FLAGS
+	  "${compile_flags} ${add_compile_flags}")
 endfunction()
 
 add_asan_test(AsanNoInstrumentationTests
@@ -30,7 +46,7 @@
 	asan_break_optimization.cc
 	)
 
-set(ASAN_EXTRA_CFLAGS
+set(ASAN_GTEST_INCLUDE_CFLAGS
   -I${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include
   -I${LLVM_MAIN_SRC_DIR}/include
   -I${LLVM_BINARY_DIR}/include
@@ -38,6 +54,19 @@
   -D__STDC_LIMIT_MACROS
 )
 
+set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS
+  ${ASAN_UNITTEST_COMMON_CFLAGS}
+  ${ASAN_GTEST_INCLUDE_CFLAGS}
+  -faddress-sanitizer
+  -O2
+  -g
+  -mllvm "-asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore"
+  -DASAN_HAS_BLACKLIST=1
+  -DASAN_HAS_EXCEPTIONS=1
+  -DASAN_NEEDS_SEGV=1
+  -DASAN_UAR=0
+)
+
 # We only support building instrumented tests when we're not cross compiling
 # and targeting a unix-like system where we can predict viable compilation and
 # linking strategies.
@@ -46,16 +75,11 @@
   # This function is a custom routine to manage manually compiling source files
   # for unit tests with the just-built Clang binary, using the ASan
   # instrumentation, and linking them into a test executable.
-  function(add_asan_compile_command source)
+  function(add_asan_compile_cxx_command source)
     add_custom_command(
       OUTPUT "${source}.asan.o"
       COMMAND clang
-              -faddress-sanitizer ${ASAN_CFLAGS} ${ASAN_EXTRA_CFLAGS}
-              -mllvm "-asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore"
-              -DASAN_HAS_BLACKLIST=1
-              -DASAN_HAS_EXCEPTIONS=1
-              -DASAN_NEEDS_SEGV=1
-              -DASAN_UAR=0
+              ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS}
               -c -o "${source}.asan.o"
               ${CMAKE_CURRENT_SOURCE_DIR}/${source}
       MAIN_DEPENDENCY ${source}
@@ -63,12 +87,34 @@
       )
   endfunction()
 
-  add_asan_compile_command(asan_globals_test.cc)
-  add_asan_compile_command(asan_test.cc)
+  function(add_asan_compile_objc_command source)
+    add_custom_command(
+      OUTPUT "${source}.asan.o"
+      COMMAND clang
+              ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS}
+              -ObjC -c -o "${source}.asan.o"
+              ${CMAKE_CURRENT_SOURCE_DIR}/${source}
+      MAIN_DEPENDENCY ${source}
+      DEPENDS clang ${ARGN}
+      )
+  endfunction()
+
+  add_asan_compile_cxx_command(asan_globals_test.cc)
+  add_asan_compile_cxx_command(asan_test.cc)
+  set(ASAN_INSTRUMENTED_TESTS 
+    asan_globals_test.cc.asan.o
+    asan_test.cc.asan.o
+  )
+  if (APPLE)
+    add_asan_compile_objc_command(asan_mac_test.mm)
+    set(ASAN_INSTRUMENTED_TESTS
+      ${ASAN_INSTRUMENTED_TESTS}
+      asan_mac_test.mm.asan.o
+    )
+  endif()
 
 	add_asan_test(AsanInstrumentationTests
-		asan_globals_test.cc.asan.o
-		asan_test.cc.asan.o
+		${ASAN_INSTRUMENTED_TESTS}
 		asan_break_optimization.cc
 		)
 

Modified: compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm?rev=159345&r1=159344&r2=159345&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm Thu Jun 28 07:19:52 2012
@@ -14,6 +14,7 @@
   void *mem =  CFAllocatorAllocate(kCFAllocatorDefault, 5, 0);
   CFAllocatorDeallocate(kCFAllocatorDefault, mem);
   CFAllocatorDeallocate(kCFAllocatorDefault, mem);
+  return 0;
 }
 
 void CFAllocatorSystemDefaultDoubleFree() {





More information about the llvm-commits mailing list