| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify=expected,itanium %s -triple x86_64-unknown-linux -std=c++11 |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify=expected,windows %s -triple x86_64-windows-msvc -std=c++11 |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -verify=expected,scei %s -triple x86_64-scei-ps4 -std=c++11 |
| 4 |
|
| 5 |
|
| 6 |
void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}} |
| 7 |
|
| 8 |
// Should not crash. |
| 9 |
template <class> |
| 10 |
class __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__) |
| 16 |
static_assert(!__is_trivially_relocatable(a<int>), ""); // expected-warning{{deprecated}} |
| 17 |
static_assert(!__builtin_is_cpp_trivially_relocatable(a<int>), ""); |
| 18 |
#else |
| 19 |
static_assert(__is_trivially_relocatable(a<int>), ""); // expected-warning{{deprecated}} |
| 20 |
static_assert(!__builtin_is_cpp_trivially_relocatable(a<int>), ""); |
| 21 |
#endif |
| 22 |
|
| 23 |
struct [[clang::trivial_abi]] S0 { |
| 24 |
int a; |
| 25 |
}; |
| 26 |
static_assert(__is_trivially_relocatable(S0), ""); // expected-warning{{deprecated}} |
| 27 |
static_assert(__builtin_is_cpp_trivially_relocatable(S0), ""); |
| 28 |
|
| 29 |
struct __attribute__((trivial_abi)) S1 { |
| 30 |
int a; |
| 31 |
}; |
| 32 |
static_assert(__is_trivially_relocatable(S1), ""); // expected-warning{{deprecated}} |
| 33 |
static_assert(__builtin_is_cpp_trivially_relocatable(S1), ""); |
| 34 |
|
| 35 |
|
| 36 |
struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}} expected-note {{is polymorphic}} |
| 37 |
virtual void m(); |
| 38 |
}; |
| 39 |
static_assert(!__is_trivially_relocatable(S3), ""); // expected-warning{{deprecated}} |
| 40 |
static_assert(__builtin_is_cpp_trivially_relocatable(S3), ""); |
| 41 |
|
| 42 |
|
| 43 |
struct S3_2 { |
| 44 |
virtual void m(); |
| 45 |
} __attribute__((trivial_abi)); // expected-warning {{'trivial_abi' cannot be applied to 'S3_2'}} expected-note {{is polymorphic}} |
| 46 |
static_assert(!__is_trivially_relocatable(S3_2), ""); // expected-warning{{deprecated}} |
| 47 |
static_assert(__builtin_is_cpp_trivially_relocatable(S3_2), ""); |
| 48 |
|
| 49 |
struct __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 the |
| 55 |
// copy constructor is trivial for calls *or deleted*, while other platforms do |
| 56 |
// not accept deleted constructors. |
| 57 |
static_assert(__is_trivially_relocatable(S3_3), ""); // expected-warning{{deprecated}} |
| 58 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S3_3), ""); |
| 59 |
|
| 60 |
#else |
| 61 |
static_assert(!__is_trivially_relocatable(S3_3), ""); // expected-warning{{deprecated}} |
| 62 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S3_3), ""); |
| 63 |
|
| 64 |
#endif |
| 65 |
|
| 66 |
// Diagnose invalid trivial_abi even when the type is templated because it has a non-trivial field. |
| 67 |
template <class T> |
| 68 |
struct __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 |
}; |
| 72 |
static_assert(!__is_trivially_relocatable(S3_4<int>), ""); // expected-warning{{deprecated}} |
| 73 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S3_4<int>), ""); |
| 74 |
|
| 75 |
|
| 76 |
struct S4 { |
| 77 |
int a; |
| 78 |
}; |
| 79 |
static_assert(__is_trivially_relocatable(S4), ""); // expected-warning{{deprecated}} |
| 80 |
static_assert(__builtin_is_cpp_trivially_relocatable(S4), ""); |
| 81 |
|
| 82 |
|
| 83 |
struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}} expected-note {{has a virtual base}} |
| 84 |
}; |
| 85 |
static_assert(!__is_trivially_relocatable(S5), ""); // expected-warning{{deprecated}} |
| 86 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S5), ""); |
| 87 |
|
| 88 |
|
| 89 |
struct __attribute__((trivial_abi)) S9 : public S4 { |
| 90 |
}; |
| 91 |
static_assert(__is_trivially_relocatable(S9), ""); // expected-warning{{deprecated}} |
| 92 |
static_assert(__builtin_is_cpp_trivially_relocatable(S9), ""); |
| 93 |
|
| 94 |
|
| 95 |
struct __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. |
| 100 |
template <class T> |
| 101 |
struct __attribute__((trivial_abi)) S10 { |
| 102 |
T p; |
| 103 |
}; |
| 104 |
|
| 105 |
S10<int *> p1; |
| 106 |
static_assert(__is_trivially_relocatable(S10<int>), ""); // expected-warning{{deprecated}} |
| 107 |
static_assert(__builtin_is_cpp_trivially_relocatable(S10<int>), ""); |
| 108 |
|
| 109 |
static_assert(__is_trivially_relocatable(S10<S3>), ""); // expected-warning{{deprecated}} |
| 110 |
static_assert(__builtin_is_cpp_trivially_relocatable(S10<S3>), ""); |
| 111 |
|
| 112 |
|
| 113 |
template <class T> |
| 114 |
struct S14 { |
| 115 |
T a; |
| 116 |
}; |
| 117 |
|
| 118 |
template <class T> |
| 119 |
struct __attribute__((trivial_abi)) S15 : S14<T> { |
| 120 |
}; |
| 121 |
|
| 122 |
S15<int> s15; |
| 123 |
static_assert(__is_trivially_relocatable(S15<int>), ""); // expected-warning{{deprecated}} |
| 124 |
static_assert(__builtin_is_cpp_trivially_relocatable(S15<int>), ""); |
| 125 |
|
| 126 |
static_assert(__is_trivially_relocatable(S15<S3>), ""); // expected-warning{{deprecated}} |
| 127 |
static_assert(__builtin_is_cpp_trivially_relocatable(S15<S3>), ""); |
| 128 |
|
| 129 |
template <class T> |
| 130 |
struct __attribute__((trivial_abi)) S16 { |
| 131 |
S14<T> a; |
| 132 |
}; |
| 133 |
static_assert(__is_trivially_relocatable(S16<int>), ""); // expected-warning{{deprecated}} |
| 134 |
static_assert(__builtin_is_cpp_trivially_relocatable(S16<int>), ""); |
| 135 |
|
| 136 |
static_assert(__is_trivially_relocatable(S16<S3>), ""); // expected-warning{{deprecated}} |
| 137 |
static_assert(__builtin_is_cpp_trivially_relocatable(S16<S3>), ""); |
| 138 |
|
| 139 |
S16<int> s16; |
| 140 |
|
| 141 |
template <class T> |
| 142 |
struct __attribute__((trivial_abi)) S17 { |
| 143 |
}; |
| 144 |
|
| 145 |
S17<int> s17; |
| 146 |
static_assert(__is_trivially_relocatable(S17<int>), ""); // expected-warning{{deprecated}} |
| 147 |
static_assert(__builtin_is_cpp_trivially_relocatable(S17<int>), ""); |
| 148 |
|
| 149 |
static_assert(__is_trivially_relocatable(S17<S3>), ""); // expected-warning{{deprecated}} |
| 150 |
static_assert(__builtin_is_cpp_trivially_relocatable(S17<S3>), ""); |
| 151 |
|
| 152 |
|
| 153 |
namespace deletedCopyMoveConstructor { |
| 154 |
struct __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__ |
| 159 |
static_assert(__is_trivially_relocatable(CopyMoveDeleted), ""); // expected-warning{{deprecated}} |
| 160 |
static_assert(!__builtin_is_cpp_trivially_relocatable(CopyMoveDeleted), ""); |
| 161 |
|
| 162 |
#else |
| 163 |
static_assert(!__is_trivially_relocatable(CopyMoveDeleted), ""); // expected-warning{{deprecated}} |
| 164 |
static_assert(!__builtin_is_cpp_trivially_relocatable(CopyMoveDeleted), ""); |
| 165 |
|
| 166 |
#endif |
| 167 |
|
| 168 |
struct __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__ |
| 175 |
static_assert(__is_trivially_relocatable(S18), ""); // expected-warning{{deprecated}} |
| 176 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S18), ""); |
| 177 |
#else |
| 178 |
static_assert(!__is_trivially_relocatable(S18), ""); // expected-warning{{deprecated}} |
| 179 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S18), ""); |
| 180 |
#endif |
| 181 |
|
| 182 |
struct __attribute__((trivial_abi)) CopyDeleted { |
| 183 |
CopyDeleted(const CopyDeleted &) = delete; |
| 184 |
CopyDeleted(CopyDeleted &&) = default; |
| 185 |
}; |
| 186 |
#if defined(_WIN64) && !defined(__MINGW32__) |
| 187 |
static_assert(!__is_trivially_relocatable(CopyDeleted), ""); // expected-warning{{deprecated}} |
| 188 |
static_assert(!__builtin_is_cpp_trivially_relocatable(CopyDeleted), ""); |
| 189 |
|
| 190 |
#else |
| 191 |
static_assert(__is_trivially_relocatable(CopyDeleted), ""); // expected-warning{{deprecated}} |
| 192 |
static_assert(!__builtin_is_cpp_trivially_relocatable(CopyDeleted), ""); |
| 193 |
#endif |
| 194 |
|
| 195 |
struct __attribute__((trivial_abi)) MoveDeleted { |
| 196 |
MoveDeleted(const MoveDeleted &) = default; |
| 197 |
MoveDeleted(MoveDeleted &&) = delete; |
| 198 |
}; |
| 199 |
static_assert(__is_trivially_relocatable(MoveDeleted), ""); // expected-warning{{deprecated}} |
| 200 |
static_assert(!__builtin_is_cpp_trivially_relocatable(MoveDeleted), ""); |
| 201 |
struct __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__ |
| 209 |
static_assert(__is_trivially_relocatable(S19), ""); // expected-warning{{deprecated}} |
| 210 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S19), ""); |
| 211 |
#else |
| 212 |
static_assert(!__is_trivially_relocatable(S19), ""); // expected-warning{{deprecated}} |
| 213 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S19), ""); |
| 214 |
#endif |
| 215 |
|
| 216 |
// This is fine since the move constructor isn't deleted. |
| 217 |
struct __attribute__((trivial_abi)) S20 { |
| 218 |
int &&a; // a member of rvalue reference type deletes the copy constructor. |
| 219 |
}; |
| 220 |
#if defined(_WIN64) && !defined(__MINGW32__) |
| 221 |
static_assert(!__is_trivially_relocatable(S20), ""); // expected-warning{{deprecated}} |
| 222 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S20), ""); |
| 223 |
|
| 224 |
#else |
| 225 |
static_assert(__is_trivially_relocatable(S20), ""); // expected-warning{{deprecated}} |
| 226 |
static_assert(!__builtin_is_cpp_trivially_relocatable(S20), ""); |
| 227 |
|
| 228 |
#endif |
| 229 |
} // namespace deletedCopyMoveConstructor |