[compiler-rt] 96fa1ea - [sanitizer] Add basic qsort test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 26 12:03:34 PDT 2021


Author: Vitaly Buka
Date: 2021-08-26T12:03:26-07:00
New Revision: 96fa1eaae490fbed8a2f7d4c6b772112db48a10b

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

LOG: [sanitizer] Add basic qsort test

Added: 
    compiler-rt/test/sanitizer_common/TestCases/Posix/qsort.cpp

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/qsort.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/qsort.cpp
new file mode 100644
index 0000000000000..f2b90c47a3d5c
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/qsort.cpp
@@ -0,0 +1,24 @@
+// RUN: %clangxx -O2 %s -o %t
+
+#include <algorithm>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <vector>
+
+static int compare_ints(const void *a, const void *b) {
+  return *(const int *)b - *(const int *)a;
+}
+
+int main() {
+  std::vector<int> nums(100000);
+  for (auto &n : nums)
+    n = rand();
+
+  std::vector<int> to_qsort = nums;
+  qsort(to_qsort.data(), to_qsort.size(), sizeof(to_qsort[0]), &compare_ints);
+
+  std::sort(nums.begin(), nums.end());
+
+  assert(nums == to_qsort);
+}


        


More information about the llvm-commits mailing list