[compiler-rt] r253576 - [LSan] Fix tests with some libstdc++ implementations.

Alexey Samsonov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 09:18:03 PST 2015


Author: samsonov
Date: Thu Nov 19 11:18:02 2015
New Revision: 253576

URL: http://llvm.org/viewvc/llvm-project?rev=253576&view=rev
Log:
[LSan] Fix tests with some libstdc++ implementations.

Summary:
Newer libstdc++ has global pool, which is filled with objects
allocated during libstdc++ initialization, and never released.
Using use_globals=0 in the lit tests results in these objects
being treated as leaks.

Fix this by porting several tests to plain C, and introducing
a simple sanity test case for __lsan::ScopedDisabler.

Reviewers: kcc, ygribov

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D14798

Added:
    compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.c
      - copied, changed from r253560, compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc
    compiler-rt/trunk/test/lsan/TestCases/disabler.c
      - copied, changed from r253560, compiler-rt/trunk/test/lsan/TestCases/disabler.cc
    compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.c
      - copied, changed from r253560, compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc
    compiler-rt/trunk/test/lsan/TestCases/ignore_object.c
      - copied, changed from r253560, compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc
Removed:
    compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc
    compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc
    compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc
Modified:
    compiler-rt/trunk/test/lsan/TestCases/disabler.cc

Copied: compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.c (from r253560, compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.c?p2=compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.c&p1=compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc&r1=253560&r2=253576&rev=253576&view=diff
==============================================================================
--- compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc (original)
+++ compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.c Thu Nov 19 11:18:02 2015
@@ -4,7 +4,7 @@
 // additional cleanup tasks). LSan doesn't actually meet that goal 100%, but it
 // makes its best effort.
 // RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0"
-// RUN: %clangxx_lsan %s -o %t
+// RUN: %clang_lsan %s -o %t
 // RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=1 %run %t
 // RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=0 not %run %t 2>&1 | FileCheck %s
 

Removed: compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc?rev=253575&view=auto
==============================================================================
--- compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc (original)
+++ compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc (removed)
@@ -1,45 +0,0 @@
-// Regression test for thread lifetime tracking. Thread data should be
-// considered live during the thread's termination, at least until the
-// user-installed TSD destructors have finished running (since they may contain
-// additional cleanup tasks). LSan doesn't actually meet that goal 100%, but it
-// makes its best effort.
-// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0"
-// RUN: %clangxx_lsan %s -o %t
-// RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=1 %run %t
-// RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=0 not %run %t 2>&1 | FileCheck %s
-
-#include <assert.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "sanitizer/lsan_interface.h"
-
-pthread_key_t key;
-__thread void *p;
-
-void key_destructor(void *arg) {
-  // Generally this may happen on a different thread.
-  __lsan_do_leak_check();
-}
-
-void *thread_func(void *arg) {
-  p = malloc(1337);
-  fprintf(stderr, "Test alloc: %p.\n", p);
-  int res = pthread_setspecific(key, (void*)1);
-  assert(res == 0);
-  return 0;
-}
-
-int main() {
-  int res = pthread_key_create(&key, &key_destructor);
-  assert(res == 0);
-  pthread_t thread_id;
-  res = pthread_create(&thread_id, 0, thread_func, 0);
-  assert(res == 0);
-  res = pthread_join(thread_id, 0);
-  assert(res == 0);
-  return 0;
-}
-// CHECK: Test alloc: [[ADDR:.*]].
-// CHECK: [[ADDR]] (1337 bytes)

Copied: compiler-rt/trunk/test/lsan/TestCases/disabler.c (from r253560, compiler-rt/trunk/test/lsan/TestCases/disabler.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/TestCases/disabler.c?p2=compiler-rt/trunk/test/lsan/TestCases/disabler.c&p1=compiler-rt/trunk/test/lsan/TestCases/disabler.cc&r1=253560&r2=253576&rev=253576&view=diff
==============================================================================
--- compiler-rt/trunk/test/lsan/TestCases/disabler.cc (original)
+++ compiler-rt/trunk/test/lsan/TestCases/disabler.c Thu Nov 19 11:18:02 2015
@@ -1,6 +1,6 @@
-// Test for ScopedDisabler.
+// Test for __lsan_disable() / __lsan_enable().
 // RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0"
-// RUN: %clangxx_lsan %s -o %t
+// RUN: %clang_lsan %s -o %t
 // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s
 
 #include <stdio.h>
@@ -11,10 +11,11 @@
 int main() {
   void **p;
   {
-    __lsan::ScopedDisabler d;
-    p = new void *;
+    __lsan_disable();
+    p = malloc(sizeof(void *));
+    __lsan_enable();
   }
-  *reinterpret_cast<void **>(p) = malloc(666);
+  *p = malloc(666);
   void *q = malloc(1337);
   // Break optimization.
   fprintf(stderr, "Test alloc: %p.\n", q);

Modified: compiler-rt/trunk/test/lsan/TestCases/disabler.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/TestCases/disabler.cc?rev=253576&r1=253575&r2=253576&view=diff
==============================================================================
--- compiler-rt/trunk/test/lsan/TestCases/disabler.cc (original)
+++ compiler-rt/trunk/test/lsan/TestCases/disabler.cc Thu Nov 19 11:18:02 2015
@@ -13,11 +13,13 @@ int main() {
   {
     __lsan::ScopedDisabler d;
     p = new void *;
+    fprintf(stderr, "Test alloc p: %p.\n", p);
   }
-  *reinterpret_cast<void **>(p) = malloc(666);
+  *p = malloc(666);
   void *q = malloc(1337);
-  // Break optimization.
-  fprintf(stderr, "Test alloc: %p.\n", q);
+  fprintf(stderr, "Test alloc q: %p.\n", q);
   return 0;
 }
-// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)
+
+// CHECK: Test alloc p: [[ADDR:.*]].
+// CHECK-NOT: [[ADDR]]

Copied: compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.c (from r253560, compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.c?p2=compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.c&p1=compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc&r1=253560&r2=253576&rev=253576&view=diff
==============================================================================
--- compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc (original)
+++ compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.c Thu Nov 19 11:18:02 2015
@@ -1,6 +1,6 @@
 // Regression test. Disabler should not depend on TSD validity.
 // RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1"
-// RUN: %clangxx_lsan %s -o %t
+// RUN: %clang_lsan %s -o %t
 // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t
 
 #include <assert.h>
@@ -13,11 +13,12 @@
 pthread_key_t key;
 
 void key_destructor(void *arg) {
-  __lsan::ScopedDisabler d;
+  __lsan_disable();
   void *p = malloc(1337);
   // Break optimization.
   fprintf(stderr, "Test alloc: %p.\n", p);
   pthread_setspecific(key, 0);
+  __lsan_enable();
 }
 
 void *thread_func(void *arg) {

Removed: compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc?rev=253575&view=auto
==============================================================================
--- compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc (original)
+++ compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc (removed)
@@ -1,38 +0,0 @@
-// Regression test. Disabler should not depend on TSD validity.
-// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1"
-// RUN: %clangxx_lsan %s -o %t
-// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t
-
-#include <assert.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "sanitizer/lsan_interface.h"
-
-pthread_key_t key;
-
-void key_destructor(void *arg) {
-  __lsan::ScopedDisabler d;
-  void *p = malloc(1337);
-  // Break optimization.
-  fprintf(stderr, "Test alloc: %p.\n", p);
-  pthread_setspecific(key, 0);
-}
-
-void *thread_func(void *arg) {
-  int res = pthread_setspecific(key, (void*)1);
-  assert(res == 0);
-  return 0;
-}
-
-int main() {
-  int res = pthread_key_create(&key, &key_destructor);
-  assert(res == 0);
-  pthread_t thread_id;
-  res = pthread_create(&thread_id, 0, thread_func, 0);
-  assert(res == 0);
-  res = pthread_join(thread_id, 0);
-  assert(res == 0);
-  return 0;
-}

Copied: compiler-rt/trunk/test/lsan/TestCases/ignore_object.c (from r253560, compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/TestCases/ignore_object.c?p2=compiler-rt/trunk/test/lsan/TestCases/ignore_object.c&p1=compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc&r1=253560&r2=253576&rev=253576&view=diff
==============================================================================
--- compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc (original)
+++ compiler-rt/trunk/test/lsan/TestCases/ignore_object.c Thu Nov 19 11:18:02 2015
@@ -1,6 +1,6 @@
 // Test for __lsan_ignore_object().
 // RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0"
-// RUN: %clangxx_lsan %s -o %t
+// RUN: %clang_lsan %s -o %t
 // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s
 
 #include <stdio.h>
@@ -10,7 +10,7 @@
 
 int main() {
   // Explicitly ignored object.
-  void **p = new void *;
+  void **p = malloc(sizeof(void *));
   // Transitively ignored object.
   *p = malloc(666);
   // Non-ignored object.

Removed: compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc?rev=253575&view=auto
==============================================================================
--- compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc (original)
+++ compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc (removed)
@@ -1,23 +0,0 @@
-// Test for __lsan_ignore_object().
-// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0"
-// RUN: %clangxx_lsan %s -o %t
-// RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "sanitizer/lsan_interface.h"
-
-int main() {
-  // Explicitly ignored object.
-  void **p = new void *;
-  // Transitively ignored object.
-  *p = malloc(666);
-  // Non-ignored object.
-  volatile void *q = malloc(1337);
-  fprintf(stderr, "Test alloc: %p.\n", p);
-  __lsan_ignore_object(p);
-  return 0;
-}
-// CHECK: Test alloc: [[ADDR:.*]].
-// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)




More information about the llvm-commits mailing list