[compiler-rt] r359606 - [compiler-rt][builtins][sanitizers] Update compiler-rt test cases for

Amy Kwan via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 13:09:00 PDT 2019


Author: amyk
Date: Tue Apr 30 13:09:00 2019
New Revision: 359606

URL: http://llvm.org/viewvc/llvm-project?rev=359606&view=rev
Log:
[compiler-rt][builtins][sanitizers] Update compiler-rt test cases for
compatibility with system's toolchain

This patch aims to:
- Guard ompiler-rt/test/builtins/Unit/compiler_rt_logb_test.c with macros, so
the test runs on GLIBC versions >= 2.23. This is because the test relies on
comparing its computed values to libm. Oolder versions might not compute to the
same value as the compiler-rt value.
- Update compiler-rt/test/sanitizer_common/TestCases/Posix/getpw_getgr.cc
so that std::string is not used, since false positives may be detected.

Differential Revision: https://reviews.llvm.org/D60644

Modified:
    compiler-rt/trunk/test/builtins/Unit/compiler_rt_logb_test.c
    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getpw_getgr.cc

Modified: compiler-rt/trunk/test/builtins/Unit/compiler_rt_logb_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/compiler_rt_logb_test.c?rev=359606&r1=359605&r2=359606&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/compiler_rt_logb_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/compiler_rt_logb_test.c Tue Apr 30 13:09:00 2019
@@ -36,6 +36,10 @@ double cases[] = {
 };
 
 int main() {
+  // Do not the run the compiler-rt logb test case if using GLIBC version
+  // < 2.23. Older versions might not compute to the same value as the
+  // compiler-rt value.
+#if !defined(__GLIBC__) || (defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 23))
   const unsigned N = sizeof(cases) / sizeof(cases[0]);
   unsigned i;
   for (i = 0; i < N; ++i) {
@@ -57,6 +61,9 @@ int main() {
     if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1;
     x >>= 1;
   }
+#else
+  printf("skipped\n");
+#endif
 
   return 0;
 }

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getpw_getgr.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getpw_getgr.cc?rev=359606&r1=359605&r2=359606&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getpw_getgr.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getpw_getgr.cc Tue Apr 30 13:09:00 2019
@@ -8,9 +8,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <string>
 
-std::string any_group;
+std::unique_ptr<char []> any_group;
 const int N = 123456;
 
 void Check(const char *str) {
@@ -48,8 +47,11 @@ void Check(const group *result) {
   assert(result->gr_gid != N);
   for (char **mem = result->gr_mem; *mem; ++mem)
     Check(*mem);
-  if (any_group.empty())
-    any_group = result->gr_name;
+  if (!any_group) {
+    auto length = strlen(result->gr_name);
+    any_group.reset(new char[length + 1]);
+    memcpy(any_group.get(), result->gr_name, length + 1);
+  }
 }
 
 template <class T, class Fn, class... Args>
@@ -72,7 +74,7 @@ int main(int argc, const char *argv[]) {
   test<passwd>(&getpwuid, 0);
   test<passwd>(&getpwnam, "root");
   test<group>(&getgrgid, 0);
-  test<group>(&getgrnam, any_group.c_str());
+  test<group>(&getgrnam, any_group.get());
 
 #if !defined(__ANDROID__)
   setpwent();
@@ -91,7 +93,7 @@ int main(int argc, const char *argv[]) {
   test_r<passwd>(&getpwnam_r, "root");
 
   test_r<group>(&getgrgid_r, 0);
-  test_r<group>(&getgrnam_r, any_group.c_str());
+  test_r<group>(&getgrnam_r, any_group.get());
 
 #if defined(__linux__)
   auto pwd_file = [] {




More information about the llvm-commits mailing list