#!/bin/sh
#
# To build a program with MemorySanitizer enabled, prefix it with this script:
#   with-msan make test PKG=./pkg/storage TAGS=stdmalloc TESTTIMEOUT=10m
# or
#   with-msan $(SHELL)
#
# MemorySanitizer is only available on Linux; this script assumes it is
# running in the cockroachdb/builder docker image.

export CC=clang
export CXX=clang++
export GOFLAGS="$GOFLAGS -msan"
export CGO_CPPFLAGS="$CGO_CPPFLAGS -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -I/libcxx_msan/include -I/libcxx_msan/include/c++/v1"
export CGO_LDFLAGS="$CGO_LDFLAGS -fsanitize=memory -stdlib=libc++ -L/libcxx_msan/lib -lc++abi -Wl,-rpath,/libcxx_msan/lib"

exec "$@"
