[PATCH] D79719: [AIX] Implement AIX special alignment rule about double/long double

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 28 19:48:56 PDT 2020


hubert.reinterpretcast added inline comments.


================
Comment at: clang/test/Layout/aix-double-struct-member.cpp:1
+// RUN: %clang_cc1 -emit-llvm-only -triple powerpc-ibm-aix-xcoff \
+// RUN:     -fdump-record-layouts -fsyntax-only %s 2>/dev/null | \
----------------
I am concerned that none of the tests actually create an instance of the classes under test and check the alignment (or related adjustments) in the IR. That is, we set up the preferred alignment value but don't check that we use it where we should.

As it is, it seems array new/delete has problems:
```
#include <assert.h>
extern "C" void *calloc(decltype(sizeof 0), decltype(sizeof 0));
extern "C" void free(void *);
extern "C" int printf(const char *, ...);

extern void *allocated_ptr;
extern decltype(sizeof 0) allocated_size;
struct B {
  double d;
  ~B() {}
  static void *operator new[](decltype(sizeof 0) sz);
  static void operator delete[](void *p, decltype(sizeof 0) sz);
};
B *allocBp();

#ifdef ALLOCBP
void *allocated_ptr;
decltype(sizeof 0) allocated_size;
void *B::operator new[](decltype(sizeof 0) sz) {
  void *alloc = calloc(1u, allocated_size = sz);
  printf("%p: %s\n", alloc, __PRETTY_FUNCTION__);
  printf("%zu\n", sz);
  return allocated_ptr = alloc;
}
void B::operator delete[](void *p, decltype(sizeof 0) sz) {
  printf("%p: %s\n", p, __PRETTY_FUNCTION__);
  printf("%zu\n", sz);
  assert(sz == allocated_size);
  assert(p == allocated_ptr);
  free(p);
}
B *allocBp() { return new B[2]; }
#endif

#ifdef MAIN
int main(void) { delete[] allocBp(); }
#endif
```

The `xlclang++` invocation from XL C/C++ generates padding before the 32-bit `new[]` cookie. I'm not seeing that padding with this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79719





More information about the cfe-commits mailing list