[PATCH] D60644: [compiler-rt][builtins][sanitizers] Guard test cases with macros with GLIBC* macros

Amy Kwan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 08:22:27 PDT 2019


amyk marked an inline comment as done and an inline comment as not done.
amyk added inline comments.


================
Comment at: compiler-rt/test/sanitizer_common/TestCases/Posix/getpw_getgr.cc:76
+  // Run this if we're using the C++11 ABI. There seems to be an issue
+  // that maybe related to _GLIBCXX_USE_CXX11_ABI and the string assigned.
+#if _GLIBCXX_USE_CXX11_ABI
----------------
hubert.reinterpretcast wrote:
> Since we now have a better understanding of the issue, the solution seems to be that the test should not be using `std::string`.
> 
> ```
> diff -U0 a/getpw_getgr.cc b/getpw_getgr.cc
> --- a/getpw_getgr.cc    2019-03-08 12:56:26.499543426 -0500
> +++ b/getpw_getgr.cc    2019-04-25 10:06:56.240191290 -0400
> @@ -11 +10,0 @@
> -#include <string>
> @@ -13 +12 @@
> -std::string any_group;
> +std::unique_ptr<char []> any_group;
> @@ -51,2 +50,5 @@
> -  if (any_group.empty())
> -    any_group = result->gr_name;
> +  if (!any_group) {
> +    auto len = strlen(result->gr_name);
> +    any_group.reset(new char[len + 1]);
> +    memcpy(any_group.get(), result->gr_name, len + 1);
> +  }
> @@ -75 +77 @@
> -  test<group>(&getgrnam, any_group.c_str());
> +  test<group>(&getgrnam, any_group.get());
> @@ -94 +96 @@
> -  test_r<group>(&getgrnam_r, any_group.c_str());
> +  test_r<group>(&getgrnam_r, any_group.get());
> ```
Yes. I saw the reply on the mailing list; thank you for that. I was going to look into something like this. I will try these changes and report back. 

This could be a silly question, but are there any other alternatives to `unique_ptr`, or is there a specific reason we should use this? 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60644/new/

https://reviews.llvm.org/D60644





More information about the llvm-commits mailing list