I found that Rcpp packages compiled with -fsanitize=address frequently crash on OS-X. I cannot reproduce this problem on linux so perhaps I am not using asan correctly, or perhaps it is related to the fact that R for Mac has been compiled on osx 10.9 and I'm using 10.11. For regular C packages, asan on osx does seem to work as expected. Here a minimal reproducible example: https://github.com/jeroenooms/asantest. It resizes a vector a few times and then crashes. It works fine if asan is commented out in the package Makevars. Compiler info: jeroen$ cc --version Apple LLVM version 7.0.0 (clang-700.0.72) Target: x86_64-apple-darwin15.0.0 Thread model: posix Crash output:
test()
=================================================================
==10663==ERROR: AddressSanitizer: unknown-crash on address
0x7fca66019d94 at pc 0x00010b4313d5 bp 0x7fff576d57f0 sp
0x7fff576d4fa0
WRITE of size 8 at 0x7fca66019d94 thread T0
#0 0x10b4313d4 in __asan_memcpy
(/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/7.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib+0x393d4)
#1 0x10b3ed3a8 in std::__1::vector<int, std::__1::allocator<int>
::__swap_out_circular_buffer(std::__1::__split_buffer<int,
std::__1::allocator<int>&>&) memory:1582
#2 0x10b3ed0b7 in std::__1::vector<int, std::__1::allocator<int>
::__append(unsigned long) vector:1047
#3 0x10b3ecb3a in test(int) test.cpp:7
#4 0x10b3e98c7 in asantest_test RcppExports.cpp:15
#5 0x1085a4966 in do_dotcall dotcode.c:1251
#6 0x1085d0acb in Rf_eval eval.c:655
#7 0x10862a2b2 in do_begin eval.c:1716
#8 0x1085d0cfd in Rf_eval eval.c:627
#9 0x108627387 in Rf_applyClosure eval.c:1039
#10 0x1085d0c06 in Rf_eval eval.c:674
#11 0x10865b1d2 in Rf_ReplIteration main.c:258
#12 0x10865c6d4 in R_ReplConsole main.c:308
#13 0x10865c608 in run_Rmainloop main.c:1006
#14 0x108528f3a in main
(/Library/Frameworks/R.framework/Resources/bin/exec/R+0x100000f3a)
#15 0x7fff9d9d75ac in start (/usr/lib/system/libdyld.dylib+0x35ac)
#16 0x0 (<unknown module>)
AddressSanitizer can not describe address in more detail (wild memory
access suspected).
SUMMARY: AddressSanitizer: unknown-crash ??:0 __asan_memcpy