watchos-standard-layout.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // RUN: %clang_cc1 -fsyntax-only -triple armv7k-apple-darwin-watchos -fdump-record-layouts %s | FileCheck %s
  2. // WatchOS, 64-bit iOS, and WebAssembly use the C++11 definition of POD to
  3. // determine whether we can reuse the tail padding of a struct (POD is
  4. // "trivially copyable and standard layout"). The definition of standard
  5. // layout changed some time around C++17; check that we still use the old
  6. // ABI rule.
  7. // B is not standard-layout, but it was under C++11's rule, so we pack
  8. // C::d into its tail padding anyway.
  9. struct A { int : 0; };
  10. struct B : A { int n; char c[3]; };
  11. struct C : B { char d; };
  12. int c = sizeof(C);
  13. static_assert(!__is_standard_layout(B));
  14. // CHECK:*** Dumping AST Record Layout
  15. // CHECK: 0 | struct C
  16. // CHECK-NEXT: 0 | struct B (base)
  17. // CHECK-NEXT: 0 | struct A (base) (empty)
  18. // CHECK-NEXT: 0:- | int
  19. // CHECK-NEXT: 0 | int n
  20. // CHECK-NEXT: 4 | char [3] c
  21. // CHECK-NEXT: 8 | char d
  22. // CHECK-NEXT: | [sizeof=12, dsize=9, align=4,
  23. // CHECK-NEXT: | nvsize=9, nvalign=4]
  24. // F is not standard-layout due to the repeated D base class, but it was under
  25. // C++11's rule, so we pack G::d into its tail padding anyway.
  26. struct D {};
  27. struct E : D {};
  28. struct F : D, E { int n; char c[3]; };
  29. struct G : F { G(const G&); char d; };
  30. int g = sizeof(G);
  31. static_assert(!__is_standard_layout(F));
  32. // CHECK:*** Dumping AST Record Layout
  33. // CHECK: 0 | struct G
  34. // CHECK-NEXT: 0 | struct F (base)
  35. // CHECK-NEXT: 0 | struct D (base) (empty)
  36. // CHECK-NEXT: 1 | struct E (base) (empty)
  37. // CHECK-NEXT: 1 | struct D (base) (empty)
  38. // CHECK-NEXT: 0 | int n
  39. // CHECK-NEXT: 4 | char [3] c
  40. // CHECK-NEXT: 8 | char d
  41. // CHECK-NEXT: | [sizeof=12, dsize=9, align=4,
  42. // CHECK-NEXT: | nvsize=9, nvalign=4]