[compiler-rt] r206896 - [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.
Kostya Serebryany
kcc at google.com
Tue Apr 22 06:56:57 PDT 2014
Author: kcc
Date: Tue Apr 22 08:56:56 2014
New Revision: 206896
URL: http://llvm.org/viewvc/llvm-project?rev=206896&view=rev
Log:
[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.
Added:
compiler-rt/trunk/test/asan/TestCases/Linux/leak.cc
Modified:
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/trunk/test/asan/TestCases/allocator_returns_null.cc
compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=206896&r1=206895&r2=206896&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Apr 22 08:56:56 2014
@@ -230,6 +230,7 @@ static void ParseFlagsFromString(Flags *
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 cha
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.
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=206896&r1=206895&r2=206896&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Tue Apr 22 08:56:56 2014
@@ -40,7 +40,7 @@ void SetCommonFlagsDefaults(CommonFlags
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;
Added: compiler-rt/trunk/test/asan/TestCases/Linux/leak.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/leak.cc?rev=206896&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/leak.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/leak.cc Tue Apr 22 08:56:56 2014
@@ -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
Modified: compiler-rt/trunk/test/asan/TestCases/allocator_returns_null.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/allocator_returns_null.cc?rev=206896&r1=206895&r2=206896&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/allocator_returns_null.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/allocator_returns_null.cc Tue Apr 22 08:56:56 2014
@@ -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:
Modified: compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp?rev=206896&r1=206895&r2=206896&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp Tue Apr 22 08:56:56 2014
@@ -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':
More information about the llvm-commits
mailing list