brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.9 KiB · 1d0a9be Raw
230 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,itanium %s -triple x86_64-unknown-linux -std=c++112// RUN: %clang_cc1 -fsyntax-only -verify=expected,windows %s -triple x86_64-windows-msvc -std=c++113// RUN: %clang_cc1 -fsyntax-only -verify=expected,scei %s -triple x86_64-scei-ps4 -std=c++114 5 6void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}7 8// Should not crash.9template <class>10class __attribute__((trivial_abi)) a { a(a &&); };11#if defined(_WIN64) && !defined(__MINGW32__)12// On Windows/MSVC, to be trivial-for-calls, an object must be trivially copyable.13// (And it is only trivially relocatable, currently, if it is trivial for calls.)14// In this case, it is suppressed by an explicitly defined move constructor.15// Similar concerns apply to later tests that have #if defined(_WIN64) && !defined(__MINGW32__)16static_assert(!__is_trivially_relocatable(a<int>), ""); // expected-warning{{deprecated}}17static_assert(!__builtin_is_cpp_trivially_relocatable(a<int>), "");18#else19static_assert(__is_trivially_relocatable(a<int>), ""); // expected-warning{{deprecated}}20static_assert(!__builtin_is_cpp_trivially_relocatable(a<int>), "");21#endif22 23struct [[clang::trivial_abi]] S0 {24  int a;25};26static_assert(__is_trivially_relocatable(S0), ""); // expected-warning{{deprecated}}27static_assert(__builtin_is_cpp_trivially_relocatable(S0), "");28 29struct __attribute__((trivial_abi)) S1 {30  int a;31};32static_assert(__is_trivially_relocatable(S1), ""); // expected-warning{{deprecated}}33static_assert(__builtin_is_cpp_trivially_relocatable(S1), "");34 35 36struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}} expected-note {{is polymorphic}}37  virtual void m();38};39static_assert(!__is_trivially_relocatable(S3), ""); // expected-warning{{deprecated}}40static_assert(__builtin_is_cpp_trivially_relocatable(S3), "");41 42 43struct S3_2 {44  virtual void m();45} __attribute__((trivial_abi)); // expected-warning {{'trivial_abi' cannot be applied to 'S3_2'}} expected-note {{is polymorphic}}46static_assert(!__is_trivially_relocatable(S3_2), ""); // expected-warning{{deprecated}}47static_assert(__builtin_is_cpp_trivially_relocatable(S3_2), "");48 49struct __attribute__((trivial_abi)) S3_3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3_3'}} expected-note {{has a field of a non-trivial class type}}50  S3_3(S3_3 &&);51  S3_2 s32;52};53#ifdef __ORBIS__54// The ClangABI4OrPS4 calling convention kind passes classes in registers if the55// copy constructor is trivial for calls *or deleted*, while other platforms do56// not accept deleted constructors.57static_assert(__is_trivially_relocatable(S3_3), ""); // expected-warning{{deprecated}}58static_assert(!__builtin_is_cpp_trivially_relocatable(S3_3), "");59 60#else61static_assert(!__is_trivially_relocatable(S3_3), ""); // expected-warning{{deprecated}}62static_assert(!__builtin_is_cpp_trivially_relocatable(S3_3), "");63 64#endif65 66// Diagnose invalid trivial_abi even when the type is templated because it has a non-trivial field.67template <class T>68struct __attribute__((trivial_abi)) S3_4 { // expected-warning {{'trivial_abi' cannot be applied to 'S3_4'}} expected-note {{has a field of a non-trivial class type}}69  S3_4(S3_4 &&);70  S3_2 s32;71};72static_assert(!__is_trivially_relocatable(S3_4<int>), ""); // expected-warning{{deprecated}}73static_assert(!__builtin_is_cpp_trivially_relocatable(S3_4<int>), "");74 75 76struct S4 {77  int a;78};79static_assert(__is_trivially_relocatable(S4), ""); // expected-warning{{deprecated}}80static_assert(__builtin_is_cpp_trivially_relocatable(S4), "");81 82 83struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}} expected-note {{has a virtual base}}84};85static_assert(!__is_trivially_relocatable(S5), ""); // expected-warning{{deprecated}}86static_assert(!__builtin_is_cpp_trivially_relocatable(S5), "");87 88 89struct __attribute__((trivial_abi)) S9 : public S4 {90};91static_assert(__is_trivially_relocatable(S9), ""); // expected-warning{{deprecated}}92static_assert(__builtin_is_cpp_trivially_relocatable(S9), "");93 94 95struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' attribute takes no arguments}}96  int a;97};98 99// Do not warn about deleted ctors  when 'trivial_abi' is used to annotate a template class.100template <class T>101struct __attribute__((trivial_abi)) S10 {102  T p;103};104 105S10<int *> p1;106static_assert(__is_trivially_relocatable(S10<int>), ""); // expected-warning{{deprecated}}107static_assert(__builtin_is_cpp_trivially_relocatable(S10<int>), "");108 109static_assert(__is_trivially_relocatable(S10<S3>), ""); // expected-warning{{deprecated}}110static_assert(__builtin_is_cpp_trivially_relocatable(S10<S3>), "");111 112 113template <class T>114struct S14 {115  T a;116};117 118template <class T>119struct __attribute__((trivial_abi)) S15 : S14<T> {120};121 122S15<int> s15;123static_assert(__is_trivially_relocatable(S15<int>), ""); // expected-warning{{deprecated}}124static_assert(__builtin_is_cpp_trivially_relocatable(S15<int>), "");125 126static_assert(__is_trivially_relocatable(S15<S3>), ""); // expected-warning{{deprecated}}127static_assert(__builtin_is_cpp_trivially_relocatable(S15<S3>), "");128 129template <class T>130struct __attribute__((trivial_abi)) S16 {131  S14<T> a;132};133static_assert(__is_trivially_relocatable(S16<int>), ""); // expected-warning{{deprecated}}134static_assert(__builtin_is_cpp_trivially_relocatable(S16<int>), "");135 136static_assert(__is_trivially_relocatable(S16<S3>), ""); // expected-warning{{deprecated}}137static_assert(__builtin_is_cpp_trivially_relocatable(S16<S3>), "");138 139S16<int> s16;140 141template <class T>142struct __attribute__((trivial_abi)) S17 {143};144 145S17<int> s17;146static_assert(__is_trivially_relocatable(S17<int>), ""); // expected-warning{{deprecated}}147static_assert(__builtin_is_cpp_trivially_relocatable(S17<int>), "");148 149static_assert(__is_trivially_relocatable(S17<S3>), ""); // expected-warning{{deprecated}}150static_assert(__builtin_is_cpp_trivially_relocatable(S17<S3>), "");151 152 153namespace deletedCopyMoveConstructor {154struct __attribute__((trivial_abi)) CopyMoveDeleted { // expected-warning {{'trivial_abi' cannot be applied to 'CopyMoveDeleted'}} expected-note {{copy constructors and move constructors are all deleted}}155  CopyMoveDeleted(const CopyMoveDeleted &) = delete;156  CopyMoveDeleted(CopyMoveDeleted &&) = delete;157};158#ifdef __ORBIS__159static_assert(__is_trivially_relocatable(CopyMoveDeleted), ""); // expected-warning{{deprecated}}160static_assert(!__builtin_is_cpp_trivially_relocatable(CopyMoveDeleted), "");161 162#else163static_assert(!__is_trivially_relocatable(CopyMoveDeleted), ""); // expected-warning{{deprecated}}164static_assert(!__builtin_is_cpp_trivially_relocatable(CopyMoveDeleted), "");165 166#endif167 168struct __attribute__((trivial_abi)) S18 { // expected-warning {{'trivial_abi' cannot be applied to 'S18'}} \169                                          // itanium-note {{'trivial_abi' is disallowed on 'S18' because it has a field of a non-trivial class type}} \170                                          // windows-note {{'trivial_abi' is disallowed on 'S18' because it has a field of a non-trivial class type}} \171                                          // scei-note {{'trivial_abi' is disallowed on 'S18' because its copy constructors and move constructors are all deleted}}172  CopyMoveDeleted a;173};174#ifdef __ORBIS__175static_assert(__is_trivially_relocatable(S18), ""); // expected-warning{{deprecated}}176static_assert(!__builtin_is_cpp_trivially_relocatable(S18), "");177#else178static_assert(!__is_trivially_relocatable(S18), ""); // expected-warning{{deprecated}}179static_assert(!__builtin_is_cpp_trivially_relocatable(S18), "");180#endif181 182struct __attribute__((trivial_abi)) CopyDeleted {183  CopyDeleted(const CopyDeleted &) = delete;184  CopyDeleted(CopyDeleted &&) = default;185};186#if defined(_WIN64) && !defined(__MINGW32__)187static_assert(!__is_trivially_relocatable(CopyDeleted), ""); // expected-warning{{deprecated}}188static_assert(!__builtin_is_cpp_trivially_relocatable(CopyDeleted), "");189 190#else191static_assert(__is_trivially_relocatable(CopyDeleted), ""); // expected-warning{{deprecated}}192static_assert(!__builtin_is_cpp_trivially_relocatable(CopyDeleted), "");193#endif194 195struct __attribute__((trivial_abi)) MoveDeleted {196  MoveDeleted(const MoveDeleted &) = default;197  MoveDeleted(MoveDeleted &&) = delete;198};199static_assert(__is_trivially_relocatable(MoveDeleted), ""); // expected-warning{{deprecated}}200static_assert(!__builtin_is_cpp_trivially_relocatable(MoveDeleted), "");201struct __attribute__((trivial_abi)) S19 { // expected-warning {{'trivial_abi' cannot be applied to 'S19'}} \202                                          // itanium-note {{'trivial_abi' is disallowed on 'S19' because its copy constructors and move constructors are all deleted}} \203                                          // windows-note {{'trivial_abi' is disallowed on 'S19' because it has a field of a non-trivial class type}} \204                                          // scei-note {{'trivial_abi' is disallowed on 'S19' because its copy constructors and move constructors are all deleted}}205  CopyDeleted a;206  MoveDeleted b;207};208#ifdef __ORBIS__209static_assert(__is_trivially_relocatable(S19), ""); // expected-warning{{deprecated}}210static_assert(!__builtin_is_cpp_trivially_relocatable(S19), "");211#else212static_assert(!__is_trivially_relocatable(S19), ""); // expected-warning{{deprecated}}213static_assert(!__builtin_is_cpp_trivially_relocatable(S19), "");214#endif215 216// This is fine since the move constructor isn't deleted.217struct __attribute__((trivial_abi)) S20 {218  int &&a; // a member of rvalue reference type deletes the copy constructor.219};220#if defined(_WIN64) && !defined(__MINGW32__)221static_assert(!__is_trivially_relocatable(S20), ""); // expected-warning{{deprecated}}222static_assert(!__builtin_is_cpp_trivially_relocatable(S20), "");223 224#else225static_assert(__is_trivially_relocatable(S20), ""); // expected-warning{{deprecated}}226static_assert(!__builtin_is_cpp_trivially_relocatable(S20), "");227 228#endif229} // namespace deletedCopyMoveConstructor230