[libcxx-commits] [PATCH] D108668: [libc++] XFAIL align.pass.cpp for PowerPC LE

Amy Kwan via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 25 14:04:34 PDT 2021


amyk added a subscriber: lkail.
amyk added a comment.

Thanks @Mordante! I've added the Bugzilla to the description.

Thanks @ldionne for taking a look at the patch. We are still looking into this and decided to XFAIL the test temporarily. I see that the assertion occurs because the following structs:

  struct LLIArr2 { long long int i[2]; }
  struct Padding { char c; /* padding */ long long int i; }

do not have the alignment that is expected (`alignof()` returns 8, while `sizeof()` returns 16), hence the assertion fails. Since this assertion fails, presumably the `this->is_lock_free()` check should not have been true to begin with.

----

@lkail assisted me in looking a bit more into this since I've posted the patch. For example, if I have a test of just the two structs:

  #include <atomic>
  #include <cassert>
  #include <stdio.h>
  
  template <typename T>
  struct atomic_test : public std::__atomic_base<T> {
    atomic_test() {
      if (this->is_lock_free()) {
        using AtomicImpl = decltype(this->__a_);
        printf("alignof() = %lu, sizeof() = %lu\n",
             alignof(AtomicImpl), sizeof(AtomicImpl));
        assert(alignof(AtomicImpl) >= sizeof(AtomicImpl) &&
               "expected natural alignment for lock-free type");
      }
    }
  };
  
  int main(int, char**) {
  
  #define CHECK_ALIGNMENT(T)                                                     \
    do {                                                                         \
      typedef T type;                                                            \
      atomic_test<type> t;                                                       \
    } while (0)
  
    CHECK_ALIGNMENT(struct LLIArr2 { long long int i[2]; });
    CHECK_ALIGNMENT(struct Padding { char c; /* padding */ long long int i; });
  
    return 0;
  }

This may have something to do with the test using the PowerPC GNU libatomic. The executable that is compiled looks like it is linking in the system libatomic by default, and doing so causes the assert.

  $ clang++ reduced.cpp -O3 -stdlib=libc++ -L/home/amyk/llvm/build/lib -latomic -Wl,-rpath=/home/amyk/llvm/build/lib
  
  $ ./a.out
  alignof() = 8, sizeof() = 16
  a.out: foo.cc:13: atomic_test<LLIArr2>::atomic_test() [T = LLIArr2]: Assertion `alignof(AtomicImpl) >= sizeof(AtomicImpl) && "expected natural alignment for lock-free type"' failed.
  Aborted
  
  $ ldd a.out
  	linux-vdso64.so.1 (0x00007817de440000)
  	libatomic.so.1 => /usr/lib/powerpc64le-linux-gnu/libatomic.so.1 (0x00007817de400000)
  	libc++.so.1 => /home/amyk/llvm/build/lib/libc++.so.1 (0x00007817de2f0000)
  	libc++abi.so.1 => /home/amyk/llvm/build/lib/libc++abi.so.1 (0x00007817de280000)
  	libm.so.6 => /lib/powerpc64le-linux-gnu/libm.so.6 (0x00007817de130000)
  	libgcc_s.so.1 => /lib/powerpc64le-linux-gnu/libgcc_s.so.1 (0x00007817de0f0000)
  	libc.so.6 => /lib/powerpc64le-linux-gnu/libc.so.6 (0x00007817ddec0000)
  	libpthread.so.0 => /lib/powerpc64le-linux-gnu/libpthread.so.0 (0x00007817dde70000)
  	librt.so.1 => /lib/powerpc64le-linux-gnu/librt.so.1 (0x00007817dde40000)
  	/lib64/ld64.so.2 (0x00007817de460000)

However, when we build and use the libatomic from compiler-rt, and compile the test, this test passes.

I am not sure if using the system libatomic is expected and if not, I am not sure if making it use compiler-rt's libatomic is something that can be achieve through the libc++ test CMake files (or something similar)?



================
Comment at: libcxx/test/libcxx/atomics/atomics.align/align.pass.cpp:21
 // std::atomic when used with __attribute__((vector(X))).
-// XFAIL: gcc
+// XFAIL: gcc, powerpc64le, powerpcle
 
----------------
ldionne wrote:
> Also, where do we define the `powerpc64le` and `powerpcle` Lit features? IMO, this should be something of the form `XFAIL: target=<the-triple-you-target>`.
Thanks for the suggestion. 
I've put those LIT features there as they were previously used before in other tests, but I can try the approach with `XFAIL: target=`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108668



More information about the libcxx-commits mailing list