forked from OSchip/llvm-project
[asan] enable LeakSanitizer (LSan) by default in asan. This only affects Linux x86_64. LSan has been used in various projects for more than half a year and we now consider it quite stable to be on by default.
llvm-svn: 206896
This commit is contained in:
parent
ec4f47ed1c
commit
c9db838267
|
@ -230,6 +230,7 @@ static void ParseFlagsFromString(Flags *f, const char *str) {
|
|||
void InitializeFlags(Flags *f, const char *env) {
|
||||
CommonFlags *cf = common_flags();
|
||||
SetCommonFlagsDefaults(cf);
|
||||
cf->detect_leaks = CAN_SANITIZE_LEAKS;
|
||||
cf->external_symbolizer_path = GetEnv("ASAN_SYMBOLIZER_PATH");
|
||||
cf->malloc_context_size = kDefaultMallocContextSize;
|
||||
cf->intercept_tls_get_addr = true;
|
||||
|
@ -288,13 +289,11 @@ void InitializeFlags(Flags *f, const char *env) {
|
|||
PrintFlagDescriptions();
|
||||
}
|
||||
|
||||
#if !CAN_SANITIZE_LEAKS
|
||||
if (cf->detect_leaks) {
|
||||
if (!CAN_SANITIZE_LEAKS && cf->detect_leaks) {
|
||||
Report("%s: detect_leaks is not supported on this platform.\n",
|
||||
SanitizerToolName);
|
||||
cf->detect_leaks = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Make "strict_init_order" imply "check_initialization_order".
|
||||
// TODO(samsonov): Use a single runtime flag for an init-order checker.
|
||||
|
|
|
@ -40,7 +40,7 @@ void SetCommonFlagsDefaults(CommonFlags *f) {
|
|||
f->malloc_context_size = 1;
|
||||
f->log_path = "stderr";
|
||||
f->verbosity = 0;
|
||||
f->detect_leaks = false;
|
||||
f->detect_leaks = true;
|
||||
f->leak_check_at_exit = true;
|
||||
f->allocator_may_return_null = false;
|
||||
f->print_summary = true;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
// Minimal test for LeakSanitizer+AddressSanitizer.
|
||||
// REQUIRES: asan-64-bits
|
||||
//
|
||||
// RUN: %clangxx_asan %s -o %t
|
||||
// RUN: ASAN_OPTIONS=detect_leaks=1 not %t 2>&1 | FileCheck %s
|
||||
// RUN: not %t 2>&1 | FileCheck %s
|
||||
// RUN: ASAN_OPTIONS=detect_leaks=0 %t
|
||||
#include <stdio.h>
|
||||
int *t;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
t = new int[argc - 1];
|
||||
printf("t: %p\n", t);
|
||||
t = 0;
|
||||
}
|
||||
// CHECK: LeakSanitizer: detected memory leaks
|
|
@ -52,10 +52,12 @@ int main(int argc, char **argv) {
|
|||
*t = 42;
|
||||
x = (char*)realloc(t, size);
|
||||
assert(*t == 42);
|
||||
free(t);
|
||||
}
|
||||
// The NULL pointer is printed differently on different systems, while (long)0
|
||||
// is always the same.
|
||||
fprintf(stderr, "x: %lx\n", (long)x);
|
||||
free(x);
|
||||
return x != 0;
|
||||
}
|
||||
// CHECK-mCRASH: malloc:
|
||||
|
|
|
@ -31,6 +31,8 @@ struct T : S {
|
|||
|
||||
struct U : S, T { virtual int v() { return 2; } };
|
||||
|
||||
T *p = 0; // Make p global so that lsan does not complain.
|
||||
|
||||
int main(int, char **argv) {
|
||||
T t;
|
||||
(void)t.a;
|
||||
|
@ -49,7 +51,6 @@ int main(int, char **argv) {
|
|||
(void)u.T::v();
|
||||
(void)((T&)u).S::v();
|
||||
|
||||
T *p = 0;
|
||||
char Buffer[sizeof(U)] = {};
|
||||
switch (argv[1][1]) {
|
||||
case '0':
|
||||
|
|
Loading…
Reference in New Issue