AddressSanitizer

Introduction

AddressSanitizer is a fast memory error detector. It consists of a compiler instrumentation module and a run-time library. The tool can detect the following types of bugs: Typical slowdown introduced by AddressSanitizer is 2x.

Usage

In order to use AddressSanitizer simply compile and link your program with -faddress-sanitizer flag and optimization level -O1 or higher and then run it. If a bug is detected, the program will print an error message and exit.

__has_feature(address_sanitizer)

In some cases one may need to execute different code depending on whether AddressSanitizer is enabled. __has_feature can be used for this purpose.
#if defined(__has_feature) && __has_feature(address_sanitizer)
  code that runs only under AddressSanitizer
#else
  code that does not run under AddressSanitizer
#endif

Supported Platforms

AddressSanitizer is supported on the following platforms:

Limitations

Current Status

AddressSanitizer is work-in-progress and is not yet fully functional in the LLVM/Clang head. For the up-to-date usable version and full documentation refer to http://code.google.com/p/address-sanitizer.