[compiler-rt] b617dc4 - [test][lsan] Don't recompile the test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon May 8 00:43:23 PDT 2023


Author: Vitaly Buka
Date: 2023-05-08T00:43:04-07:00
New Revision: b617dc4c3a183722312ac7e333e4250ef1234a2c

URL: https://github.com/llvm/llvm-project/commit/b617dc4c3a183722312ac7e333e4250ef1234a2c
DIFF: https://github.com/llvm/llvm-project/commit/b617dc4c3a183722312ac7e333e4250ef1234a2c.diff

LOG: [test][lsan] Don't recompile the test

Added: 
    

Modified: 
    compiler-rt/test/lsan/TestCases/create_thread_leak.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp b/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp
index 79fe26547d47..14acd1472bfd 100644
--- a/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp
+++ b/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp
@@ -1,28 +1,35 @@
-// Check that sanitizer does not leak args when passing to a child thread.
+// Test handling of arg and retval of child thread.
 
-// RUN: %clangxx_lsan -pthread %s -o %t -DLEAK_ARG && %run not %t 10 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK123
-// RUN: %clangxx_lsan -pthread %s -o %t -DLEAK_RES && %run not %t 10 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK234
-// RUN: %clangxx_lsan -pthread %s -o %t -DLEAK_DETACH && %run not %t 10 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK234
+// RUN: %clangxx_lsan -pthread %s -o %t
+// RUN: %run not %t 10 1 0 0 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK123
+// RUN: %run not %t 10 0 1 0 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK234
+// RUN: %run not %t 10 0 0 1 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK234
 
 // FIXME: Remove "not". There is no leak.
 // False LEAK123 is broken for HWASAN.
 // False LEAK234 is broken for ASAN, HWASAN, LSAN.
-// RUN: %clangxx_lsan -pthread %s -o %t && %run %if asan %{ not %} %if hwasan %{ not %} %if lsan-standalone %{ not %} %t 10
+// RUN: %run %if asan %{ not %} %if hwasan %{ not %} %if lsan-standalone %{ not %} %t 10 0 0 0
 
 #include <pthread.h>
 #include <stdlib.h>
 
 #include <sanitizer/lsan_interface.h>
 
+int detach;
+int leak_arg;
+int leak_retval;
+
 static void *thread_free(void *args) {
-#ifndef LEAK_ARG
-  free(args);
-#endif
+  if (!leak_arg)
+    free(args);
   return malloc(234);
 }
 
 int main(int argc, char **argv) {
   int n = atoi(argv[1]);
+  leak_arg = atoi(argv[2]);
+  leak_retval = atoi(argv[3]);
+  detach = atoi(argv[4]);
   for (int i = 0; i < n; ++i) {
     pthread_t threads[10];
 
@@ -33,15 +40,14 @@ int main(int argc, char **argv) {
     }
 
     for (auto &thread : threads) {
-#ifdef LEAK_DETACH
-      pthread_detach(thread);
-      continue;
-#endif
+      if (detach) {
+        pthread_detach(thread);
+        continue;
+      }
       void *retval = 0;
       pthread_join(thread, &retval);
-#ifndef LEAK_RES
-      free(retval);
-#endif
+      if (!leak_retval)
+        free(retval);
     }
   }
   return 0;


        


More information about the llvm-commits mailing list