[PATCH] D23449: libcxx: Fix path.compare.pass expected result

Adhemerval Zanella via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 12 07:15:25 PDT 2016


zatrazz created this revision.
zatrazz added reviewers: jroelofs, danalbert, EricWF.
zatrazz added subscribers: rmaprath, aemerson, rengolin, cfe-commits.

The expected 'filesystem::path::compare' result states that for different
only the sign of result integer contains the information about passed
arguments.  This is because it uses the output of other compare function
(basic_string_view and char_traits) without further handling and
char_traits uses memcmp for final buffer comparison.

However for GLIBC on AArch64 the code:

  int ret = memcmp ("b/a/c", "a/b/c", 1);

Results in '64' where for x86_64 it results in '1'.

This patch fixes the expected 'filesystem::path::compare' by normalizing
all the results before assert comparison.

https://reviews.llvm.org/D23449

Files:
  test/std/experimental/filesystem/class.path/path.member/path.compare.pass.cpp

Index: test/std/experimental/filesystem/class.path/path.member/path.compare.pass.cpp
===================================================================
--- test/std/experimental/filesystem/class.path/path.member/path.compare.pass.cpp
+++ test/std/experimental/filesystem/class.path/path.member/path.compare.pass.cpp
@@ -73,6 +73,11 @@
 #undef LONGC
 #undef LONGD
 
+static inline int normalize_ret(int ret)
+{
+  return ret < 0 ? -1 : (ret > 0 ? 1 : 0);
+}
+
 int main()
 {
   using namespace fs;
@@ -86,13 +91,12 @@
       DisableAllocationGuard g; // none of these operations should allocate
 
       // check runtime results
-      int ret1 = p1.compare(p2);
-      int ret2 = p1.compare(R);
-      int ret3 = p1.compare(TC.RHS);
-      int ret4 = p1.compare(RV);
+      int ret1 = normalize_ret(p1.compare(p2));
+      int ret2 = normalize_ret(p1.compare(R));
+      int ret3 = normalize_ret(p1.compare(TC.RHS));
+      int ret4 = normalize_ret(p1.compare(RV));
       assert(ret1 == ret2 && ret1 == ret3 && ret1 == ret4);
-      int normalized_ret = ret1 < 0 ? -1 : (ret1 > 0 ? 1 : 0);
-      assert(normalized_ret == E);
+      assert(ret1 == E);
 
       // check signatures
       ASSERT_NOEXCEPT(p1.compare(p2));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23449.67836.patch
Type: text/x-patch
Size: 1223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160812/246d1442/attachment-0001.bin>


More information about the cfe-commits mailing list