1*67e74705SXin Li//==--- AttrDocs.td - Attribute documentation ----------------------------===// 2*67e74705SXin Li// 3*67e74705SXin Li// The LLVM Compiler Infrastructure 4*67e74705SXin Li// 5*67e74705SXin Li// This file is distributed under the University of Illinois Open Source 6*67e74705SXin Li// License. See LICENSE.TXT for details. 7*67e74705SXin Li// 8*67e74705SXin Li//===---------------------------------------------------------------------===// 9*67e74705SXin Li 10*67e74705SXin Lidef GlobalDocumentation { 11*67e74705SXin Li code Intro =[{.. 12*67e74705SXin Li ------------------------------------------------------------------- 13*67e74705SXin Li NOTE: This file is automatically generated by running clang-tblgen 14*67e74705SXin Li -gen-attr-docs. Do not edit this file by hand!! 15*67e74705SXin Li ------------------------------------------------------------------- 16*67e74705SXin Li 17*67e74705SXin Li=================== 18*67e74705SXin LiAttributes in Clang 19*67e74705SXin Li=================== 20*67e74705SXin Li.. contents:: 21*67e74705SXin Li :local: 22*67e74705SXin Li 23*67e74705SXin LiIntroduction 24*67e74705SXin Li============ 25*67e74705SXin Li 26*67e74705SXin LiThis page lists the attributes currently supported by Clang. 27*67e74705SXin Li}]; 28*67e74705SXin Li} 29*67e74705SXin Li 30*67e74705SXin Lidef SectionDocs : Documentation { 31*67e74705SXin Li let Category = DocCatVariable; 32*67e74705SXin Li let Content = [{ 33*67e74705SXin LiThe ``section`` attribute allows you to specify a specific section a 34*67e74705SXin Liglobal variable or function should be in after translation. 35*67e74705SXin Li }]; 36*67e74705SXin Li let Heading = "section (gnu::section, __declspec(allocate))"; 37*67e74705SXin Li} 38*67e74705SXin Li 39*67e74705SXin Lidef InitSegDocs : Documentation { 40*67e74705SXin Li let Category = DocCatVariable; 41*67e74705SXin Li let Content = [{ 42*67e74705SXin LiThe attribute applied by ``pragma init_seg()`` controls the section into 43*67e74705SXin Liwhich global initialization function pointers are emitted. It is only 44*67e74705SXin Liavailable with ``-fms-extensions``. Typically, this function pointer is 45*67e74705SXin Liemitted into ``.CRT$XCU`` on Windows. The user can change the order of 46*67e74705SXin Liinitialization by using a different section name with the same 47*67e74705SXin Li``.CRT$XC`` prefix and a suffix that sorts lexicographically before or 48*67e74705SXin Liafter the standard ``.CRT$XCU`` sections. See the init_seg_ 49*67e74705SXin Lidocumentation on MSDN for more information. 50*67e74705SXin Li 51*67e74705SXin Li.. _init_seg: http://msdn.microsoft.com/en-us/library/7977wcck(v=vs.110).aspx 52*67e74705SXin Li }]; 53*67e74705SXin Li} 54*67e74705SXin Li 55*67e74705SXin Lidef TLSModelDocs : Documentation { 56*67e74705SXin Li let Category = DocCatVariable; 57*67e74705SXin Li let Content = [{ 58*67e74705SXin LiThe ``tls_model`` attribute allows you to specify which thread-local storage 59*67e74705SXin Limodel to use. It accepts the following strings: 60*67e74705SXin Li 61*67e74705SXin Li* global-dynamic 62*67e74705SXin Li* local-dynamic 63*67e74705SXin Li* initial-exec 64*67e74705SXin Li* local-exec 65*67e74705SXin Li 66*67e74705SXin LiTLS models are mutually exclusive. 67*67e74705SXin Li }]; 68*67e74705SXin Li} 69*67e74705SXin Li 70*67e74705SXin Lidef ThreadDocs : Documentation { 71*67e74705SXin Li let Category = DocCatVariable; 72*67e74705SXin Li let Content = [{ 73*67e74705SXin LiThe ``__declspec(thread)`` attribute declares a variable with thread local 74*67e74705SXin Listorage. It is available under the ``-fms-extensions`` flag for MSVC 75*67e74705SXin Licompatibility. See the documentation for `__declspec(thread)`_ on MSDN. 76*67e74705SXin Li 77*67e74705SXin Li.. _`__declspec(thread)`: http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx 78*67e74705SXin Li 79*67e74705SXin LiIn Clang, ``__declspec(thread)`` is generally equivalent in functionality to the 80*67e74705SXin LiGNU ``__thread`` keyword. The variable must not have a destructor and must have 81*67e74705SXin Lia constant initializer, if any. The attribute only applies to variables 82*67e74705SXin Lideclared with static storage duration, such as globals, class static data 83*67e74705SXin Limembers, and static locals. 84*67e74705SXin Li }]; 85*67e74705SXin Li} 86*67e74705SXin Li 87*67e74705SXin Lidef CarriesDependencyDocs : Documentation { 88*67e74705SXin Li let Category = DocCatFunction; 89*67e74705SXin Li let Content = [{ 90*67e74705SXin LiThe ``carries_dependency`` attribute specifies dependency propagation into and 91*67e74705SXin Liout of functions. 92*67e74705SXin Li 93*67e74705SXin LiWhen specified on a function or Objective-C method, the ``carries_dependency`` 94*67e74705SXin Liattribute means that the return value carries a dependency out of the function, 95*67e74705SXin Liso that the implementation need not constrain ordering upon return from that 96*67e74705SXin Lifunction. Implementations of the function and its caller may choose to preserve 97*67e74705SXin Lidependencies instead of emitting memory ordering instructions such as fences. 98*67e74705SXin Li 99*67e74705SXin LiNote, this attribute does not change the meaning of the program, but may result 100*67e74705SXin Liin generation of more efficient code. 101*67e74705SXin Li }]; 102*67e74705SXin Li} 103*67e74705SXin Li 104*67e74705SXin Lidef C11NoReturnDocs : Documentation { 105*67e74705SXin Li let Category = DocCatFunction; 106*67e74705SXin Li let Content = [{ 107*67e74705SXin LiA function declared as ``_Noreturn`` shall not return to its caller. The 108*67e74705SXin Licompiler will generate a diagnostic for a function declared as ``_Noreturn`` 109*67e74705SXin Lithat appears to be capable of returning to its caller. 110*67e74705SXin Li }]; 111*67e74705SXin Li} 112*67e74705SXin Li 113*67e74705SXin Lidef CXX11NoReturnDocs : Documentation { 114*67e74705SXin Li let Category = DocCatFunction; 115*67e74705SXin Li let Content = [{ 116*67e74705SXin LiA function declared as ``[[noreturn]]`` shall not return to its caller. The 117*67e74705SXin Licompiler will generate a diagnostic for a function declared as ``[[noreturn]]`` 118*67e74705SXin Lithat appears to be capable of returning to its caller. 119*67e74705SXin Li }]; 120*67e74705SXin Li} 121*67e74705SXin Li 122*67e74705SXin Lidef AssertCapabilityDocs : Documentation { 123*67e74705SXin Li let Category = DocCatFunction; 124*67e74705SXin Li let Heading = "assert_capability (assert_shared_capability, clang::assert_capability, clang::assert_shared_capability)"; 125*67e74705SXin Li let Content = [{ 126*67e74705SXin LiMarks a function that dynamically tests whether a capability is held, and halts 127*67e74705SXin Lithe program if it is not held. 128*67e74705SXin Li }]; 129*67e74705SXin Li} 130*67e74705SXin Li 131*67e74705SXin Lidef AcquireCapabilityDocs : Documentation { 132*67e74705SXin Li let Category = DocCatFunction; 133*67e74705SXin Li let Heading = "acquire_capability (acquire_shared_capability, clang::acquire_capability, clang::acquire_shared_capability)"; 134*67e74705SXin Li let Content = [{ 135*67e74705SXin LiMarks a function as acquiring a capability. 136*67e74705SXin Li }]; 137*67e74705SXin Li} 138*67e74705SXin Li 139*67e74705SXin Lidef TryAcquireCapabilityDocs : Documentation { 140*67e74705SXin Li let Category = DocCatFunction; 141*67e74705SXin Li let Heading = "try_acquire_capability (try_acquire_shared_capability, clang::try_acquire_capability, clang::try_acquire_shared_capability)"; 142*67e74705SXin Li let Content = [{ 143*67e74705SXin LiMarks a function that attempts to acquire a capability. This function may fail to 144*67e74705SXin Liactually acquire the capability; they accept a Boolean value determining 145*67e74705SXin Liwhether acquiring the capability means success (true), or failing to acquire 146*67e74705SXin Lithe capability means success (false). 147*67e74705SXin Li }]; 148*67e74705SXin Li} 149*67e74705SXin Li 150*67e74705SXin Lidef ReleaseCapabilityDocs : Documentation { 151*67e74705SXin Li let Category = DocCatFunction; 152*67e74705SXin Li let Heading = "release_capability (release_shared_capability, clang::release_capability, clang::release_shared_capability)"; 153*67e74705SXin Li let Content = [{ 154*67e74705SXin LiMarks a function as releasing a capability. 155*67e74705SXin Li }]; 156*67e74705SXin Li} 157*67e74705SXin Li 158*67e74705SXin Lidef AssumeAlignedDocs : Documentation { 159*67e74705SXin Li let Category = DocCatFunction; 160*67e74705SXin Li let Content = [{ 161*67e74705SXin LiUse ``__attribute__((assume_aligned(<alignment>[,<offset>]))`` on a function 162*67e74705SXin Lideclaration to specify that the return value of the function (which must be a 163*67e74705SXin Lipointer type) has the specified offset, in bytes, from an address with the 164*67e74705SXin Lispecified alignment. The offset is taken to be zero if omitted. 165*67e74705SXin Li 166*67e74705SXin Li.. code-block:: c++ 167*67e74705SXin Li 168*67e74705SXin Li // The returned pointer value has 32-byte alignment. 169*67e74705SXin Li void *a() __attribute__((assume_aligned (32))); 170*67e74705SXin Li 171*67e74705SXin Li // The returned pointer value is 4 bytes greater than an address having 172*67e74705SXin Li // 32-byte alignment. 173*67e74705SXin Li void *b() __attribute__((assume_aligned (32, 4))); 174*67e74705SXin Li 175*67e74705SXin LiNote that this attribute provides information to the compiler regarding a 176*67e74705SXin Licondition that the code already ensures is true. It does not cause the compiler 177*67e74705SXin Lito enforce the provided alignment assumption. 178*67e74705SXin Li }]; 179*67e74705SXin Li} 180*67e74705SXin Li 181*67e74705SXin Lidef EnableIfDocs : Documentation { 182*67e74705SXin Li let Category = DocCatFunction; 183*67e74705SXin Li let Content = [{ 184*67e74705SXin Li.. Note:: Some features of this attribute are experimental. The meaning of 185*67e74705SXin Li multiple enable_if attributes on a single declaration is subject to change in 186*67e74705SXin Li a future version of clang. Also, the ABI is not standardized and the name 187*67e74705SXin Li mangling may change in future versions. To avoid that, use asm labels. 188*67e74705SXin Li 189*67e74705SXin LiThe ``enable_if`` attribute can be placed on function declarations to control 190*67e74705SXin Liwhich overload is selected based on the values of the function's arguments. 191*67e74705SXin LiWhen combined with the ``overloadable`` attribute, this feature is also 192*67e74705SXin Liavailable in C. 193*67e74705SXin Li 194*67e74705SXin Li.. code-block:: c++ 195*67e74705SXin Li 196*67e74705SXin Li int isdigit(int c); 197*67e74705SXin Li int isdigit(int c) __attribute__((enable_if(c <= -1 || c > 255, "chosen when 'c' is out of range"))) __attribute__((unavailable("'c' must have the value of an unsigned char or EOF"))); 198*67e74705SXin Li 199*67e74705SXin Li void foo(char c) { 200*67e74705SXin Li isdigit(c); 201*67e74705SXin Li isdigit(10); 202*67e74705SXin Li isdigit(-10); // results in a compile-time error. 203*67e74705SXin Li } 204*67e74705SXin Li 205*67e74705SXin LiThe enable_if attribute takes two arguments, the first is an expression written 206*67e74705SXin Liin terms of the function parameters, the second is a string explaining why this 207*67e74705SXin Lioverload candidate could not be selected to be displayed in diagnostics. The 208*67e74705SXin Liexpression is part of the function signature for the purposes of determining 209*67e74705SXin Liwhether it is a redeclaration (following the rules used when determining 210*67e74705SXin Liwhether a C++ template specialization is ODR-equivalent), but is not part of 211*67e74705SXin Lithe type. 212*67e74705SXin Li 213*67e74705SXin LiThe enable_if expression is evaluated as if it were the body of a 214*67e74705SXin Libool-returning constexpr function declared with the arguments of the function 215*67e74705SXin Liit is being applied to, then called with the parameters at the call site. If the 216*67e74705SXin Liresult is false or could not be determined through constant expression 217*67e74705SXin Lievaluation, then this overload will not be chosen and the provided string may 218*67e74705SXin Libe used in a diagnostic if the compile fails as a result. 219*67e74705SXin Li 220*67e74705SXin LiBecause the enable_if expression is an unevaluated context, there are no global 221*67e74705SXin Listate changes, nor the ability to pass information from the enable_if 222*67e74705SXin Liexpression to the function body. For example, suppose we want calls to 223*67e74705SXin Listrnlen(strbuf, maxlen) to resolve to strnlen_chk(strbuf, maxlen, size of 224*67e74705SXin Listrbuf) only if the size of strbuf can be determined: 225*67e74705SXin Li 226*67e74705SXin Li.. code-block:: c++ 227*67e74705SXin Li 228*67e74705SXin Li __attribute__((always_inline)) 229*67e74705SXin Li static inline size_t strnlen(const char *s, size_t maxlen) 230*67e74705SXin Li __attribute__((overloadable)) 231*67e74705SXin Li __attribute__((enable_if(__builtin_object_size(s, 0) != -1))), 232*67e74705SXin Li "chosen when the buffer size is known but 'maxlen' is not"))) 233*67e74705SXin Li { 234*67e74705SXin Li return strnlen_chk(s, maxlen, __builtin_object_size(s, 0)); 235*67e74705SXin Li } 236*67e74705SXin Li 237*67e74705SXin LiMultiple enable_if attributes may be applied to a single declaration. In this 238*67e74705SXin Licase, the enable_if expressions are evaluated from left to right in the 239*67e74705SXin Lifollowing manner. First, the candidates whose enable_if expressions evaluate to 240*67e74705SXin Lifalse or cannot be evaluated are discarded. If the remaining candidates do not 241*67e74705SXin Lishare ODR-equivalent enable_if expressions, the overload resolution is 242*67e74705SXin Liambiguous. Otherwise, enable_if overload resolution continues with the next 243*67e74705SXin Lienable_if attribute on the candidates that have not been discarded and have 244*67e74705SXin Liremaining enable_if attributes. In this way, we pick the most specific 245*67e74705SXin Lioverload out of a number of viable overloads using enable_if. 246*67e74705SXin Li 247*67e74705SXin Li.. code-block:: c++ 248*67e74705SXin Li 249*67e74705SXin Li void f() __attribute__((enable_if(true, ""))); // #1 250*67e74705SXin Li void f() __attribute__((enable_if(true, ""))) __attribute__((enable_if(true, ""))); // #2 251*67e74705SXin Li 252*67e74705SXin Li void g(int i, int j) __attribute__((enable_if(i, ""))); // #1 253*67e74705SXin Li void g(int i, int j) __attribute__((enable_if(j, ""))) __attribute__((enable_if(true))); // #2 254*67e74705SXin Li 255*67e74705SXin LiIn this example, a call to f() is always resolved to #2, as the first enable_if 256*67e74705SXin Liexpression is ODR-equivalent for both declarations, but #1 does not have another 257*67e74705SXin Lienable_if expression to continue evaluating, so the next round of evaluation has 258*67e74705SXin Lionly a single candidate. In a call to g(1, 1), the call is ambiguous even though 259*67e74705SXin Li#2 has more enable_if attributes, because the first enable_if expressions are 260*67e74705SXin Linot ODR-equivalent. 261*67e74705SXin Li 262*67e74705SXin LiQuery for this feature with ``__has_attribute(enable_if)``. 263*67e74705SXin Li 264*67e74705SXin LiNote that functions with one or more ``enable_if`` attributes may not have 265*67e74705SXin Litheir address taken, unless all of the conditions specified by said 266*67e74705SXin Li``enable_if`` are constants that evaluate to ``true``. For example: 267*67e74705SXin Li 268*67e74705SXin Li.. code-block:: c 269*67e74705SXin Li 270*67e74705SXin Li const int TrueConstant = 1; 271*67e74705SXin Li const int FalseConstant = 0; 272*67e74705SXin Li int f(int a) __attribute__((enable_if(a > 0, ""))); 273*67e74705SXin Li int g(int a) __attribute__((enable_if(a == 0 || a != 0, ""))); 274*67e74705SXin Li int h(int a) __attribute__((enable_if(1, ""))); 275*67e74705SXin Li int i(int a) __attribute__((enable_if(TrueConstant, ""))); 276*67e74705SXin Li int j(int a) __attribute__((enable_if(FalseConstant, ""))); 277*67e74705SXin Li 278*67e74705SXin Li void fn() { 279*67e74705SXin Li int (*ptr)(int); 280*67e74705SXin Li ptr = &f; // error: 'a > 0' is not always true 281*67e74705SXin Li ptr = &g; // error: 'a == 0 || a != 0' is not a truthy constant 282*67e74705SXin Li ptr = &h; // OK: 1 is a truthy constant 283*67e74705SXin Li ptr = &i; // OK: 'TrueConstant' is a truthy constant 284*67e74705SXin Li ptr = &j; // error: 'FalseConstant' is a constant, but not truthy 285*67e74705SXin Li } 286*67e74705SXin Li 287*67e74705SXin LiBecause ``enable_if`` evaluation happens during overload resolution, 288*67e74705SXin Li``enable_if`` may give unintuitive results when used with templates, depending 289*67e74705SXin Lion when overloads are resolved. In the example below, clang will emit a 290*67e74705SXin Lidiagnostic about no viable overloads for ``foo`` in ``bar``, but not in ``baz``: 291*67e74705SXin Li 292*67e74705SXin Li.. code-block:: c++ 293*67e74705SXin Li 294*67e74705SXin Li double foo(int i) __attribute__((enable_if(i > 0, ""))); 295*67e74705SXin Li void *foo(int i) __attribute__((enable_if(i <= 0, ""))); 296*67e74705SXin Li template <int I> 297*67e74705SXin Li auto bar() { return foo(I); } 298*67e74705SXin Li 299*67e74705SXin Li template <typename T> 300*67e74705SXin Li auto baz() { return foo(T::number); } 301*67e74705SXin Li 302*67e74705SXin Li struct WithNumber { constexpr static int number = 1; }; 303*67e74705SXin Li void callThem() { 304*67e74705SXin Li bar<sizeof(WithNumber)>(); 305*67e74705SXin Li baz<WithNumber>(); 306*67e74705SXin Li } 307*67e74705SXin Li 308*67e74705SXin LiThis is because, in ``bar``, ``foo`` is resolved prior to template 309*67e74705SXin Liinstantiation, so the value for ``I`` isn't known (thus, both ``enable_if`` 310*67e74705SXin Liconditions for ``foo`` fail). However, in ``baz``, ``foo`` is resolved during 311*67e74705SXin Litemplate instantiation, so the value for ``T::number`` is known. 312*67e74705SXin Li }]; 313*67e74705SXin Li} 314*67e74705SXin Li 315*67e74705SXin Lidef PassObjectSizeDocs : Documentation { 316*67e74705SXin Li let Category = DocCatVariable; // Technically it's a parameter doc, but eh. 317*67e74705SXin Li let Content = [{ 318*67e74705SXin Li.. Note:: The mangling of functions with parameters that are annotated with 319*67e74705SXin Li ``pass_object_size`` is subject to change. You can get around this by 320*67e74705SXin Li using ``__asm__("foo")`` to explicitly name your functions, thus preserving 321*67e74705SXin Li your ABI; also, non-overloadable C functions with ``pass_object_size`` are 322*67e74705SXin Li not mangled. 323*67e74705SXin Li 324*67e74705SXin LiThe ``pass_object_size(Type)`` attribute can be placed on function parameters to 325*67e74705SXin Liinstruct clang to call ``__builtin_object_size(param, Type)`` at each callsite 326*67e74705SXin Liof said function, and implicitly pass the result of this call in as an invisible 327*67e74705SXin Liargument of type ``size_t`` directly after the parameter annotated with 328*67e74705SXin Li``pass_object_size``. Clang will also replace any calls to 329*67e74705SXin Li``__builtin_object_size(param, Type)`` in the function by said implicit 330*67e74705SXin Liparameter. 331*67e74705SXin Li 332*67e74705SXin LiExample usage: 333*67e74705SXin Li 334*67e74705SXin Li.. code-block:: c 335*67e74705SXin Li 336*67e74705SXin Li int bzero1(char *const p __attribute__((pass_object_size(0)))) 337*67e74705SXin Li __attribute__((noinline)) { 338*67e74705SXin Li int i = 0; 339*67e74705SXin Li for (/**/; i < (int)__builtin_object_size(p, 0); ++i) { 340*67e74705SXin Li p[i] = 0; 341*67e74705SXin Li } 342*67e74705SXin Li return i; 343*67e74705SXin Li } 344*67e74705SXin Li 345*67e74705SXin Li int main() { 346*67e74705SXin Li char chars[100]; 347*67e74705SXin Li int n = bzero1(&chars[0]); 348*67e74705SXin Li assert(n == sizeof(chars)); 349*67e74705SXin Li return 0; 350*67e74705SXin Li } 351*67e74705SXin Li 352*67e74705SXin LiIf successfully evaluating ``__builtin_object_size(param, Type)`` at the 353*67e74705SXin Licallsite is not possible, then the "failed" value is passed in. So, using the 354*67e74705SXin Lidefinition of ``bzero1`` from above, the following code would exit cleanly: 355*67e74705SXin Li 356*67e74705SXin Li.. code-block:: c 357*67e74705SXin Li 358*67e74705SXin Li int main2(int argc, char *argv[]) { 359*67e74705SXin Li int n = bzero1(argv); 360*67e74705SXin Li assert(n == -1); 361*67e74705SXin Li return 0; 362*67e74705SXin Li } 363*67e74705SXin Li 364*67e74705SXin Li``pass_object_size`` plays a part in overload resolution. If two overload 365*67e74705SXin Licandidates are otherwise equally good, then the overload with one or more 366*67e74705SXin Liparameters with ``pass_object_size`` is preferred. This implies that the choice 367*67e74705SXin Libetween two identical overloads both with ``pass_object_size`` on one or more 368*67e74705SXin Liparameters will always be ambiguous; for this reason, having two such overloads 369*67e74705SXin Liis illegal. For example: 370*67e74705SXin Li 371*67e74705SXin Li.. code-block:: c++ 372*67e74705SXin Li 373*67e74705SXin Li #define PS(N) __attribute__((pass_object_size(N))) 374*67e74705SXin Li // OK 375*67e74705SXin Li void Foo(char *a, char *b); // Overload A 376*67e74705SXin Li // OK -- overload A has no parameters with pass_object_size. 377*67e74705SXin Li void Foo(char *a PS(0), char *b PS(0)); // Overload B 378*67e74705SXin Li // Error -- Same signature (sans pass_object_size) as overload B, and both 379*67e74705SXin Li // overloads have one or more parameters with the pass_object_size attribute. 380*67e74705SXin Li void Foo(void *a PS(0), void *b); 381*67e74705SXin Li 382*67e74705SXin Li // OK 383*67e74705SXin Li void Bar(void *a PS(0)); // Overload C 384*67e74705SXin Li // OK 385*67e74705SXin Li void Bar(char *c PS(1)); // Overload D 386*67e74705SXin Li 387*67e74705SXin Li void main() { 388*67e74705SXin Li char known[10], *unknown; 389*67e74705SXin Li Foo(unknown, unknown); // Calls overload B 390*67e74705SXin Li Foo(known, unknown); // Calls overload B 391*67e74705SXin Li Foo(unknown, known); // Calls overload B 392*67e74705SXin Li Foo(known, known); // Calls overload B 393*67e74705SXin Li 394*67e74705SXin Li Bar(known); // Calls overload D 395*67e74705SXin Li Bar(unknown); // Calls overload D 396*67e74705SXin Li } 397*67e74705SXin Li 398*67e74705SXin LiCurrently, ``pass_object_size`` is a bit restricted in terms of its usage: 399*67e74705SXin Li 400*67e74705SXin Li* Only one use of ``pass_object_size`` is allowed per parameter. 401*67e74705SXin Li 402*67e74705SXin Li* It is an error to take the address of a function with ``pass_object_size`` on 403*67e74705SXin Li any of its parameters. If you wish to do this, you can create an overload 404*67e74705SXin Li without ``pass_object_size`` on any parameters. 405*67e74705SXin Li 406*67e74705SXin Li* It is an error to apply the ``pass_object_size`` attribute to parameters that 407*67e74705SXin Li are not pointers. Additionally, any parameter that ``pass_object_size`` is 408*67e74705SXin Li applied to must be marked ``const`` at its function's definition. 409*67e74705SXin Li }]; 410*67e74705SXin Li} 411*67e74705SXin Li 412*67e74705SXin Lidef OverloadableDocs : Documentation { 413*67e74705SXin Li let Category = DocCatFunction; 414*67e74705SXin Li let Content = [{ 415*67e74705SXin LiClang provides support for C++ function overloading in C. Function overloading 416*67e74705SXin Liin C is introduced using the ``overloadable`` attribute. For example, one 417*67e74705SXin Limight provide several overloaded versions of a ``tgsin`` function that invokes 418*67e74705SXin Lithe appropriate standard function computing the sine of a value with ``float``, 419*67e74705SXin Li``double``, or ``long double`` precision: 420*67e74705SXin Li 421*67e74705SXin Li.. code-block:: c 422*67e74705SXin Li 423*67e74705SXin Li #include <math.h> 424*67e74705SXin Li float __attribute__((overloadable)) tgsin(float x) { return sinf(x); } 425*67e74705SXin Li double __attribute__((overloadable)) tgsin(double x) { return sin(x); } 426*67e74705SXin Li long double __attribute__((overloadable)) tgsin(long double x) { return sinl(x); } 427*67e74705SXin Li 428*67e74705SXin LiGiven these declarations, one can call ``tgsin`` with a ``float`` value to 429*67e74705SXin Lireceive a ``float`` result, with a ``double`` to receive a ``double`` result, 430*67e74705SXin Lietc. Function overloading in C follows the rules of C++ function overloading 431*67e74705SXin Lito pick the best overload given the call arguments, with a few C-specific 432*67e74705SXin Lisemantics: 433*67e74705SXin Li 434*67e74705SXin Li* Conversion from ``float`` or ``double`` to ``long double`` is ranked as a 435*67e74705SXin Li floating-point promotion (per C99) rather than as a floating-point conversion 436*67e74705SXin Li (as in C++). 437*67e74705SXin Li 438*67e74705SXin Li* A conversion from a pointer of type ``T*`` to a pointer of type ``U*`` is 439*67e74705SXin Li considered a pointer conversion (with conversion rank) if ``T`` and ``U`` are 440*67e74705SXin Li compatible types. 441*67e74705SXin Li 442*67e74705SXin Li* A conversion from type ``T`` to a value of type ``U`` is permitted if ``T`` 443*67e74705SXin Li and ``U`` are compatible types. This conversion is given "conversion" rank. 444*67e74705SXin Li 445*67e74705SXin LiThe declaration of ``overloadable`` functions is restricted to function 446*67e74705SXin Lideclarations and definitions. Most importantly, if any function with a given 447*67e74705SXin Liname is given the ``overloadable`` attribute, then all function declarations 448*67e74705SXin Liand definitions with that name (and in that scope) must have the 449*67e74705SXin Li``overloadable`` attribute. This rule even applies to redeclarations of 450*67e74705SXin Lifunctions whose original declaration had the ``overloadable`` attribute, e.g., 451*67e74705SXin Li 452*67e74705SXin Li.. code-block:: c 453*67e74705SXin Li 454*67e74705SXin Li int f(int) __attribute__((overloadable)); 455*67e74705SXin Li float f(float); // error: declaration of "f" must have the "overloadable" attribute 456*67e74705SXin Li 457*67e74705SXin Li int g(int) __attribute__((overloadable)); 458*67e74705SXin Li int g(int) { } // error: redeclaration of "g" must also have the "overloadable" attribute 459*67e74705SXin Li 460*67e74705SXin LiFunctions marked ``overloadable`` must have prototypes. Therefore, the 461*67e74705SXin Lifollowing code is ill-formed: 462*67e74705SXin Li 463*67e74705SXin Li.. code-block:: c 464*67e74705SXin Li 465*67e74705SXin Li int h() __attribute__((overloadable)); // error: h does not have a prototype 466*67e74705SXin Li 467*67e74705SXin LiHowever, ``overloadable`` functions are allowed to use a ellipsis even if there 468*67e74705SXin Liare no named parameters (as is permitted in C++). This feature is particularly 469*67e74705SXin Liuseful when combined with the ``unavailable`` attribute: 470*67e74705SXin Li 471*67e74705SXin Li.. code-block:: c++ 472*67e74705SXin Li 473*67e74705SXin Li void honeypot(...) __attribute__((overloadable, unavailable)); // calling me is an error 474*67e74705SXin Li 475*67e74705SXin LiFunctions declared with the ``overloadable`` attribute have their names mangled 476*67e74705SXin Liaccording to the same rules as C++ function names. For example, the three 477*67e74705SXin Li``tgsin`` functions in our motivating example get the mangled names 478*67e74705SXin Li``_Z5tgsinf``, ``_Z5tgsind``, and ``_Z5tgsine``, respectively. There are two 479*67e74705SXin Licaveats to this use of name mangling: 480*67e74705SXin Li 481*67e74705SXin Li* Future versions of Clang may change the name mangling of functions overloaded 482*67e74705SXin Li in C, so you should not depend on an specific mangling. To be completely 483*67e74705SXin Li safe, we strongly urge the use of ``static inline`` with ``overloadable`` 484*67e74705SXin Li functions. 485*67e74705SXin Li 486*67e74705SXin Li* The ``overloadable`` attribute has almost no meaning when used in C++, 487*67e74705SXin Li because names will already be mangled and functions are already overloadable. 488*67e74705SXin Li However, when an ``overloadable`` function occurs within an ``extern "C"`` 489*67e74705SXin Li linkage specification, it's name *will* be mangled in the same way as it 490*67e74705SXin Li would in C. 491*67e74705SXin Li 492*67e74705SXin LiQuery for this feature with ``__has_extension(attribute_overloadable)``. 493*67e74705SXin Li }]; 494*67e74705SXin Li} 495*67e74705SXin Li 496*67e74705SXin Lidef ObjCMethodFamilyDocs : Documentation { 497*67e74705SXin Li let Category = DocCatFunction; 498*67e74705SXin Li let Content = [{ 499*67e74705SXin LiMany methods in Objective-C have conventional meanings determined by their 500*67e74705SXin Liselectors. It is sometimes useful to be able to mark a method as having a 501*67e74705SXin Liparticular conventional meaning despite not having the right selector, or as 502*67e74705SXin Linot having the conventional meaning that its selector would suggest. For these 503*67e74705SXin Liuse cases, we provide an attribute to specifically describe the "method family" 504*67e74705SXin Lithat a method belongs to. 505*67e74705SXin Li 506*67e74705SXin Li**Usage**: ``__attribute__((objc_method_family(X)))``, where ``X`` is one of 507*67e74705SXin Li``none``, ``alloc``, ``copy``, ``init``, ``mutableCopy``, or ``new``. This 508*67e74705SXin Liattribute can only be placed at the end of a method declaration: 509*67e74705SXin Li 510*67e74705SXin Li.. code-block:: objc 511*67e74705SXin Li 512*67e74705SXin Li - (NSString *)initMyStringValue __attribute__((objc_method_family(none))); 513*67e74705SXin Li 514*67e74705SXin LiUsers who do not wish to change the conventional meaning of a method, and who 515*67e74705SXin Limerely want to document its non-standard retain and release semantics, should 516*67e74705SXin Liuse the retaining behavior attributes (``ns_returns_retained``, 517*67e74705SXin Li``ns_returns_not_retained``, etc). 518*67e74705SXin Li 519*67e74705SXin LiQuery for this feature with ``__has_attribute(objc_method_family)``. 520*67e74705SXin Li }]; 521*67e74705SXin Li} 522*67e74705SXin Li 523*67e74705SXin Lidef NoDebugDocs : Documentation { 524*67e74705SXin Li let Category = DocCatVariable; 525*67e74705SXin Li let Content = [{ 526*67e74705SXin LiThe ``nodebug`` attribute allows you to suppress debugging information for a 527*67e74705SXin Lifunction or method, or for a variable that is not a parameter or a non-static 528*67e74705SXin Lidata member. 529*67e74705SXin Li }]; 530*67e74705SXin Li} 531*67e74705SXin Li 532*67e74705SXin Lidef NoDuplicateDocs : Documentation { 533*67e74705SXin Li let Category = DocCatFunction; 534*67e74705SXin Li let Content = [{ 535*67e74705SXin LiThe ``noduplicate`` attribute can be placed on function declarations to control 536*67e74705SXin Liwhether function calls to this function can be duplicated or not as a result of 537*67e74705SXin Lioptimizations. This is required for the implementation of functions with 538*67e74705SXin Licertain special requirements, like the OpenCL "barrier" function, that might 539*67e74705SXin Lineed to be run concurrently by all the threads that are executing in lockstep 540*67e74705SXin Lion the hardware. For example this attribute applied on the function 541*67e74705SXin Li"nodupfunc" in the code below avoids that: 542*67e74705SXin Li 543*67e74705SXin Li.. code-block:: c 544*67e74705SXin Li 545*67e74705SXin Li void nodupfunc() __attribute__((noduplicate)); 546*67e74705SXin Li // Setting it as a C++11 attribute is also valid 547*67e74705SXin Li // void nodupfunc() [[clang::noduplicate]]; 548*67e74705SXin Li void foo(); 549*67e74705SXin Li void bar(); 550*67e74705SXin Li 551*67e74705SXin Li nodupfunc(); 552*67e74705SXin Li if (a > n) { 553*67e74705SXin Li foo(); 554*67e74705SXin Li } else { 555*67e74705SXin Li bar(); 556*67e74705SXin Li } 557*67e74705SXin Li 558*67e74705SXin Ligets possibly modified by some optimizations into code similar to this: 559*67e74705SXin Li 560*67e74705SXin Li.. code-block:: c 561*67e74705SXin Li 562*67e74705SXin Li if (a > n) { 563*67e74705SXin Li nodupfunc(); 564*67e74705SXin Li foo(); 565*67e74705SXin Li } else { 566*67e74705SXin Li nodupfunc(); 567*67e74705SXin Li bar(); 568*67e74705SXin Li } 569*67e74705SXin Li 570*67e74705SXin Liwhere the call to "nodupfunc" is duplicated and sunk into the two branches 571*67e74705SXin Liof the condition. 572*67e74705SXin Li }]; 573*67e74705SXin Li} 574*67e74705SXin Li 575*67e74705SXin Lidef NoSplitStackDocs : Documentation { 576*67e74705SXin Li let Category = DocCatFunction; 577*67e74705SXin Li let Content = [{ 578*67e74705SXin LiThe ``no_split_stack`` attribute disables the emission of the split stack 579*67e74705SXin Lipreamble for a particular function. It has no effect if ``-fsplit-stack`` 580*67e74705SXin Liis not specified. 581*67e74705SXin Li }]; 582*67e74705SXin Li} 583*67e74705SXin Li 584*67e74705SXin Lidef ObjCRequiresSuperDocs : Documentation { 585*67e74705SXin Li let Category = DocCatFunction; 586*67e74705SXin Li let Content = [{ 587*67e74705SXin LiSome Objective-C classes allow a subclass to override a particular method in a 588*67e74705SXin Liparent class but expect that the overriding method also calls the overridden 589*67e74705SXin Limethod in the parent class. For these cases, we provide an attribute to 590*67e74705SXin Lidesignate that a method requires a "call to ``super``" in the overriding 591*67e74705SXin Limethod in the subclass. 592*67e74705SXin Li 593*67e74705SXin Li**Usage**: ``__attribute__((objc_requires_super))``. This attribute can only 594*67e74705SXin Libe placed at the end of a method declaration: 595*67e74705SXin Li 596*67e74705SXin Li.. code-block:: objc 597*67e74705SXin Li 598*67e74705SXin Li - (void)foo __attribute__((objc_requires_super)); 599*67e74705SXin Li 600*67e74705SXin LiThis attribute can only be applied the method declarations within a class, and 601*67e74705SXin Linot a protocol. Currently this attribute does not enforce any placement of 602*67e74705SXin Liwhere the call occurs in the overriding method (such as in the case of 603*67e74705SXin Li``-dealloc`` where the call must appear at the end). It checks only that it 604*67e74705SXin Liexists. 605*67e74705SXin Li 606*67e74705SXin LiNote that on both OS X and iOS that the Foundation framework provides a 607*67e74705SXin Liconvenience macro ``NS_REQUIRES_SUPER`` that provides syntactic sugar for this 608*67e74705SXin Liattribute: 609*67e74705SXin Li 610*67e74705SXin Li.. code-block:: objc 611*67e74705SXin Li 612*67e74705SXin Li - (void)foo NS_REQUIRES_SUPER; 613*67e74705SXin Li 614*67e74705SXin LiThis macro is conditionally defined depending on the compiler's support for 615*67e74705SXin Lithis attribute. If the compiler does not support the attribute the macro 616*67e74705SXin Liexpands to nothing. 617*67e74705SXin Li 618*67e74705SXin LiOperationally, when a method has this annotation the compiler will warn if the 619*67e74705SXin Liimplementation of an override in a subclass does not call super. For example: 620*67e74705SXin Li 621*67e74705SXin Li.. code-block:: objc 622*67e74705SXin Li 623*67e74705SXin Li warning: method possibly missing a [super AnnotMeth] call 624*67e74705SXin Li - (void) AnnotMeth{}; 625*67e74705SXin Li ^ 626*67e74705SXin Li }]; 627*67e74705SXin Li} 628*67e74705SXin Li 629*67e74705SXin Lidef ObjCRuntimeNameDocs : Documentation { 630*67e74705SXin Li let Category = DocCatFunction; 631*67e74705SXin Li let Content = [{ 632*67e74705SXin LiBy default, the Objective-C interface or protocol identifier is used 633*67e74705SXin Liin the metadata name for that object. The `objc_runtime_name` 634*67e74705SXin Liattribute allows annotated interfaces or protocols to use the 635*67e74705SXin Lispecified string argument in the object's metadata name instead of the 636*67e74705SXin Lidefault name. 637*67e74705SXin Li 638*67e74705SXin Li**Usage**: ``__attribute__((objc_runtime_name("MyLocalName")))``. This attribute 639*67e74705SXin Lican only be placed before an @protocol or @interface declaration: 640*67e74705SXin Li 641*67e74705SXin Li.. code-block:: objc 642*67e74705SXin Li 643*67e74705SXin Li __attribute__((objc_runtime_name("MyLocalName"))) 644*67e74705SXin Li @interface Message 645*67e74705SXin Li @end 646*67e74705SXin Li 647*67e74705SXin Li }]; 648*67e74705SXin Li} 649*67e74705SXin Li 650*67e74705SXin Lidef ObjCRuntimeVisibleDocs : Documentation { 651*67e74705SXin Li let Category = DocCatFunction; 652*67e74705SXin Li let Content = [{ 653*67e74705SXin LiThis attribute specifies that the Objective-C class to which it applies is visible to the Objective-C runtime but not to the linker. Classes annotated with this attribute cannot be subclassed and cannot have categories defined for them. 654*67e74705SXin Li }]; 655*67e74705SXin Li} 656*67e74705SXin Li 657*67e74705SXin Lidef ObjCBoxableDocs : Documentation { 658*67e74705SXin Li let Category = DocCatFunction; 659*67e74705SXin Li let Content = [{ 660*67e74705SXin LiStructs and unions marked with the ``objc_boxable`` attribute can be used 661*67e74705SXin Liwith the Objective-C boxed expression syntax, ``@(...)``. 662*67e74705SXin Li 663*67e74705SXin Li**Usage**: ``__attribute__((objc_boxable))``. This attribute 664*67e74705SXin Lican only be placed on a declaration of a trivially-copyable struct or union: 665*67e74705SXin Li 666*67e74705SXin Li.. code-block:: objc 667*67e74705SXin Li 668*67e74705SXin Li struct __attribute__((objc_boxable)) some_struct { 669*67e74705SXin Li int i; 670*67e74705SXin Li }; 671*67e74705SXin Li union __attribute__((objc_boxable)) some_union { 672*67e74705SXin Li int i; 673*67e74705SXin Li float f; 674*67e74705SXin Li }; 675*67e74705SXin Li typedef struct __attribute__((objc_boxable)) _some_struct some_struct; 676*67e74705SXin Li 677*67e74705SXin Li // ... 678*67e74705SXin Li 679*67e74705SXin Li some_struct ss; 680*67e74705SXin Li NSValue *boxed = @(ss); 681*67e74705SXin Li 682*67e74705SXin Li }]; 683*67e74705SXin Li} 684*67e74705SXin Li 685*67e74705SXin Lidef AvailabilityDocs : Documentation { 686*67e74705SXin Li let Category = DocCatFunction; 687*67e74705SXin Li let Content = [{ 688*67e74705SXin LiThe ``availability`` attribute can be placed on declarations to describe the 689*67e74705SXin Lilifecycle of that declaration relative to operating system versions. Consider 690*67e74705SXin Lithe function declaration for a hypothetical function ``f``: 691*67e74705SXin Li 692*67e74705SXin Li.. code-block:: c++ 693*67e74705SXin Li 694*67e74705SXin Li void f(void) __attribute__((availability(macos,introduced=10.4,deprecated=10.6,obsoleted=10.7))); 695*67e74705SXin Li 696*67e74705SXin LiThe availability attribute states that ``f`` was introduced in Mac OS X 10.4, 697*67e74705SXin Lideprecated in Mac OS X 10.6, and obsoleted in Mac OS X 10.7. This information 698*67e74705SXin Liis used by Clang to determine when it is safe to use ``f``: for example, if 699*67e74705SXin LiClang is instructed to compile code for Mac OS X 10.5, a call to ``f()`` 700*67e74705SXin Lisucceeds. If Clang is instructed to compile code for Mac OS X 10.6, the call 701*67e74705SXin Lisucceeds but Clang emits a warning specifying that the function is deprecated. 702*67e74705SXin LiFinally, if Clang is instructed to compile code for Mac OS X 10.7, the call 703*67e74705SXin Lifails because ``f()`` is no longer available. 704*67e74705SXin Li 705*67e74705SXin LiThe availability attribute is a comma-separated list starting with the 706*67e74705SXin Liplatform name and then including clauses specifying important milestones in the 707*67e74705SXin Lideclaration's lifetime (in any order) along with additional information. Those 708*67e74705SXin Liclauses can be: 709*67e74705SXin Li 710*67e74705SXin Liintroduced=\ *version* 711*67e74705SXin Li The first version in which this declaration was introduced. 712*67e74705SXin Li 713*67e74705SXin Lideprecated=\ *version* 714*67e74705SXin Li The first version in which this declaration was deprecated, meaning that 715*67e74705SXin Li users should migrate away from this API. 716*67e74705SXin Li 717*67e74705SXin Liobsoleted=\ *version* 718*67e74705SXin Li The first version in which this declaration was obsoleted, meaning that it 719*67e74705SXin Li was removed completely and can no longer be used. 720*67e74705SXin Li 721*67e74705SXin Liunavailable 722*67e74705SXin Li This declaration is never available on this platform. 723*67e74705SXin Li 724*67e74705SXin Limessage=\ *string-literal* 725*67e74705SXin Li Additional message text that Clang will provide when emitting a warning or 726*67e74705SXin Li error about use of a deprecated or obsoleted declaration. Useful to direct 727*67e74705SXin Li users to replacement APIs. 728*67e74705SXin Li 729*67e74705SXin Lireplacement=\ *string-literal* 730*67e74705SXin Li Additional message text that Clang will use to provide Fix-It when emitting 731*67e74705SXin Li a warning about use of a deprecated declaration. The Fix-It will replace 732*67e74705SXin Li the deprecated declaration with the new declaration specified. 733*67e74705SXin Li 734*67e74705SXin LiMultiple availability attributes can be placed on a declaration, which may 735*67e74705SXin Licorrespond to different platforms. Only the availability attribute with the 736*67e74705SXin Liplatform corresponding to the target platform will be used; any others will be 737*67e74705SXin Liignored. If no availability attribute specifies availability for the current 738*67e74705SXin Litarget platform, the availability attributes are ignored. Supported platforms 739*67e74705SXin Liare: 740*67e74705SXin Li 741*67e74705SXin Li``ios`` 742*67e74705SXin Li Apple's iOS operating system. The minimum deployment target is specified by 743*67e74705SXin Li the ``-mios-version-min=*version*`` or ``-miphoneos-version-min=*version*`` 744*67e74705SXin Li command-line arguments. 745*67e74705SXin Li 746*67e74705SXin Li``macos`` 747*67e74705SXin Li Apple's Mac OS X operating system. The minimum deployment target is 748*67e74705SXin Li specified by the ``-mmacosx-version-min=*version*`` command-line argument. 749*67e74705SXin Li ``macosx`` is supported for backward-compatibility reasons, but it is 750*67e74705SXin Li deprecated. 751*67e74705SXin Li 752*67e74705SXin Li``tvos`` 753*67e74705SXin Li Apple's tvOS operating system. The minimum deployment target is specified by 754*67e74705SXin Li the ``-mtvos-version-min=*version*`` command-line argument. 755*67e74705SXin Li 756*67e74705SXin Li``watchos`` 757*67e74705SXin Li Apple's watchOS operating system. The minimum deployment target is specified by 758*67e74705SXin Li the ``-mwatchos-version-min=*version*`` command-line argument. 759*67e74705SXin Li 760*67e74705SXin LiA declaration can typically be used even when deploying back to a platform 761*67e74705SXin Liversion prior to when the declaration was introduced. When this happens, the 762*67e74705SXin Lideclaration is `weakly linked 763*67e74705SXin Li<https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html>`_, 764*67e74705SXin Lias if the ``weak_import`` attribute were added to the declaration. A 765*67e74705SXin Liweakly-linked declaration may or may not be present a run-time, and a program 766*67e74705SXin Lican determine whether the declaration is present by checking whether the 767*67e74705SXin Liaddress of that declaration is non-NULL. 768*67e74705SXin Li 769*67e74705SXin LiThe flag ``strict`` disallows using API when deploying back to a 770*67e74705SXin Liplatform version prior to when the declaration was introduced. An 771*67e74705SXin Liattempt to use such API before its introduction causes a hard error. 772*67e74705SXin LiWeakly-linking is almost always a better API choice, since it allows 773*67e74705SXin Liusers to query availability at runtime. 774*67e74705SXin Li 775*67e74705SXin LiIf there are multiple declarations of the same entity, the availability 776*67e74705SXin Liattributes must either match on a per-platform basis or later 777*67e74705SXin Lideclarations must not have availability attributes for that 778*67e74705SXin Liplatform. For example: 779*67e74705SXin Li 780*67e74705SXin Li.. code-block:: c 781*67e74705SXin Li 782*67e74705SXin Li void g(void) __attribute__((availability(macos,introduced=10.4))); 783*67e74705SXin Li void g(void) __attribute__((availability(macos,introduced=10.4))); // okay, matches 784*67e74705SXin Li void g(void) __attribute__((availability(ios,introduced=4.0))); // okay, adds a new platform 785*67e74705SXin Li void g(void); // okay, inherits both macos and ios availability from above. 786*67e74705SXin Li void g(void) __attribute__((availability(macos,introduced=10.5))); // error: mismatch 787*67e74705SXin Li 788*67e74705SXin LiWhen one method overrides another, the overriding method can be more widely available than the overridden method, e.g.,: 789*67e74705SXin Li 790*67e74705SXin Li.. code-block:: objc 791*67e74705SXin Li 792*67e74705SXin Li @interface A 793*67e74705SXin Li - (id)method __attribute__((availability(macos,introduced=10.4))); 794*67e74705SXin Li - (id)method2 __attribute__((availability(macos,introduced=10.4))); 795*67e74705SXin Li @end 796*67e74705SXin Li 797*67e74705SXin Li @interface B : A 798*67e74705SXin Li - (id)method __attribute__((availability(macos,introduced=10.3))); // okay: method moved into base class later 799*67e74705SXin Li - (id)method __attribute__((availability(macos,introduced=10.5))); // error: this method was available via the base class in 10.4 800*67e74705SXin Li @end 801*67e74705SXin Li }]; 802*67e74705SXin Li} 803*67e74705SXin Li 804*67e74705SXin Lidef WarnMaybeUnusedDocs : Documentation { 805*67e74705SXin Li let Category = DocCatVariable; 806*67e74705SXin Li let Heading = "maybe_unused, unused, gnu::unused"; 807*67e74705SXin Li let Content = [{ 808*67e74705SXin LiWhen passing the ``-Wunused`` flag to Clang, entities that are unused by the 809*67e74705SXin Liprogram may be diagnosed. The ``[[maybe_unused]]`` (or 810*67e74705SXin Li``__attribute__((unused))``) attribute can be used to silence such diagnostics 811*67e74705SXin Liwhen the entity cannot be removed. For instance, a local variable may exist 812*67e74705SXin Lisolely for use in an ``assert()`` statement, which makes the local variable 813*67e74705SXin Liunused when ``NDEBUG`` is defined. 814*67e74705SXin Li 815*67e74705SXin LiThe attribute may be applied to the declaration of a class, a typedef, a 816*67e74705SXin Livariable, a function or method, a function parameter, an enumeration, an 817*67e74705SXin Lienumerator, a non-static data member, or a label. 818*67e74705SXin Li 819*67e74705SXin Li.. code-block: c++ 820*67e74705SXin Li #include <cassert> 821*67e74705SXin Li 822*67e74705SXin Li [[maybe_unused]] void f([[maybe_unused]] bool thing1, 823*67e74705SXin Li [[maybe_unused]] bool thing2) { 824*67e74705SXin Li [[maybe_unused]] bool b = thing1 && thing2; 825*67e74705SXin Li assert(b); 826*67e74705SXin Li } 827*67e74705SXin Li }]; 828*67e74705SXin Li} 829*67e74705SXin Li 830*67e74705SXin Lidef WarnUnusedResultsDocs : Documentation { 831*67e74705SXin Li let Category = DocCatFunction; 832*67e74705SXin Li let Heading = "nodiscard, warn_unused_result, clang::warn_unused_result, gnu::warn_unused_result"; 833*67e74705SXin Li let Content = [{ 834*67e74705SXin LiClang supports the ability to diagnose when the results of a function call 835*67e74705SXin Liexpression are discarded under suspicious circumstances. A diagnostic is 836*67e74705SXin Ligenerated when a function or its return type is marked with ``[[nodiscard]]`` 837*67e74705SXin Li(or ``__attribute__((warn_unused_result))``) and the function call appears as a 838*67e74705SXin Lipotentially-evaluated discarded-value expression that is not explicitly cast to 839*67e74705SXin Li`void`. 840*67e74705SXin Li 841*67e74705SXin Li.. code-block: c++ 842*67e74705SXin Li struct [[nodiscard]] error_info { /*...*/ }; 843*67e74705SXin Li error_info enable_missile_safety_mode(); 844*67e74705SXin Li 845*67e74705SXin Li void launch_missiles(); 846*67e74705SXin Li void test_missiles() { 847*67e74705SXin Li enable_missile_safety_mode(); // diagnoses 848*67e74705SXin Li launch_missiles(); 849*67e74705SXin Li } 850*67e74705SXin Li error_info &foo(); 851*67e74705SXin Li void f() { foo(); } // Does not diagnose, error_info is a reference. 852*67e74705SXin Li }]; 853*67e74705SXin Li} 854*67e74705SXin Li 855*67e74705SXin Lidef FallthroughDocs : Documentation { 856*67e74705SXin Li let Category = DocCatStmt; 857*67e74705SXin Li let Heading = "fallthrough, clang::fallthrough"; 858*67e74705SXin Li let Content = [{ 859*67e74705SXin LiThe ``fallthrough`` (or ``clang::fallthrough``) attribute is used 860*67e74705SXin Lito annotate intentional fall-through 861*67e74705SXin Libetween switch labels. It can only be applied to a null statement placed at a 862*67e74705SXin Lipoint of execution between any statement and the next switch label. It is 863*67e74705SXin Licommon to mark these places with a specific comment, but this attribute is 864*67e74705SXin Limeant to replace comments with a more strict annotation, which can be checked 865*67e74705SXin Liby the compiler. This attribute doesn't change semantics of the code and can 866*67e74705SXin Libe used wherever an intended fall-through occurs. It is designed to mimic 867*67e74705SXin Licontrol-flow statements like ``break;``, so it can be placed in most places 868*67e74705SXin Liwhere ``break;`` can, but only if there are no statements on the execution path 869*67e74705SXin Libetween it and the next switch label. 870*67e74705SXin Li 871*67e74705SXin LiBy default, Clang does not warn on unannotated fallthrough from one ``switch`` 872*67e74705SXin Licase to another. Diagnostics on fallthrough without a corresponding annotation 873*67e74705SXin Lican be enabled with the ``-Wimplicit-fallthrough`` argument. 874*67e74705SXin Li 875*67e74705SXin LiHere is an example: 876*67e74705SXin Li 877*67e74705SXin Li.. code-block:: c++ 878*67e74705SXin Li 879*67e74705SXin Li // compile with -Wimplicit-fallthrough 880*67e74705SXin Li switch (n) { 881*67e74705SXin Li case 22: 882*67e74705SXin Li case 33: // no warning: no statements between case labels 883*67e74705SXin Li f(); 884*67e74705SXin Li case 44: // warning: unannotated fall-through 885*67e74705SXin Li g(); 886*67e74705SXin Li [[clang::fallthrough]]; 887*67e74705SXin Li case 55: // no warning 888*67e74705SXin Li if (x) { 889*67e74705SXin Li h(); 890*67e74705SXin Li break; 891*67e74705SXin Li } 892*67e74705SXin Li else { 893*67e74705SXin Li i(); 894*67e74705SXin Li [[clang::fallthrough]]; 895*67e74705SXin Li } 896*67e74705SXin Li case 66: // no warning 897*67e74705SXin Li p(); 898*67e74705SXin Li [[clang::fallthrough]]; // warning: fallthrough annotation does not 899*67e74705SXin Li // directly precede case label 900*67e74705SXin Li q(); 901*67e74705SXin Li case 77: // warning: unannotated fall-through 902*67e74705SXin Li r(); 903*67e74705SXin Li } 904*67e74705SXin Li }]; 905*67e74705SXin Li} 906*67e74705SXin Li 907*67e74705SXin Lidef ARMInterruptDocs : Documentation { 908*67e74705SXin Li let Category = DocCatFunction; 909*67e74705SXin Li let Content = [{ 910*67e74705SXin LiClang supports the GNU style ``__attribute__((interrupt("TYPE")))`` attribute on 911*67e74705SXin LiARM targets. This attribute may be attached to a function definition and 912*67e74705SXin Liinstructs the backend to generate appropriate function entry/exit code so that 913*67e74705SXin Liit can be used directly as an interrupt service routine. 914*67e74705SXin Li 915*67e74705SXin LiThe parameter passed to the interrupt attribute is optional, but if 916*67e74705SXin Liprovided it must be a string literal with one of the following values: "IRQ", 917*67e74705SXin Li"FIQ", "SWI", "ABORT", "UNDEF". 918*67e74705SXin Li 919*67e74705SXin LiThe semantics are as follows: 920*67e74705SXin Li 921*67e74705SXin Li- If the function is AAPCS, Clang instructs the backend to realign the stack to 922*67e74705SXin Li 8 bytes on entry. This is a general requirement of the AAPCS at public 923*67e74705SXin Li interfaces, but may not hold when an exception is taken. Doing this allows 924*67e74705SXin Li other AAPCS functions to be called. 925*67e74705SXin Li- If the CPU is M-class this is all that needs to be done since the architecture 926*67e74705SXin Li itself is designed in such a way that functions obeying the normal AAPCS ABI 927*67e74705SXin Li constraints are valid exception handlers. 928*67e74705SXin Li- If the CPU is not M-class, the prologue and epilogue are modified to save all 929*67e74705SXin Li non-banked registers that are used, so that upon return the user-mode state 930*67e74705SXin Li will not be corrupted. Note that to avoid unnecessary overhead, only 931*67e74705SXin Li general-purpose (integer) registers are saved in this way. If VFP operations 932*67e74705SXin Li are needed, that state must be saved manually. 933*67e74705SXin Li 934*67e74705SXin Li Specifically, interrupt kinds other than "FIQ" will save all core registers 935*67e74705SXin Li except "lr" and "sp". "FIQ" interrupts will save r0-r7. 936*67e74705SXin Li- If the CPU is not M-class, the return instruction is changed to one of the 937*67e74705SXin Li canonical sequences permitted by the architecture for exception return. Where 938*67e74705SXin Li possible the function itself will make the necessary "lr" adjustments so that 939*67e74705SXin Li the "preferred return address" is selected. 940*67e74705SXin Li 941*67e74705SXin Li Unfortunately the compiler is unable to make this guarantee for an "UNDEF" 942*67e74705SXin Li handler, where the offset from "lr" to the preferred return address depends on 943*67e74705SXin Li the execution state of the code which generated the exception. In this case 944*67e74705SXin Li a sequence equivalent to "movs pc, lr" will be used. 945*67e74705SXin Li }]; 946*67e74705SXin Li} 947*67e74705SXin Li 948*67e74705SXin Lidef MipsInterruptDocs : Documentation { 949*67e74705SXin Li let Category = DocCatFunction; 950*67e74705SXin Li let Content = [{ 951*67e74705SXin LiClang supports the GNU style ``__attribute__((interrupt("ARGUMENT")))`` attribute on 952*67e74705SXin LiMIPS targets. This attribute may be attached to a function definition and instructs 953*67e74705SXin Lithe backend to generate appropriate function entry/exit code so that it can be used 954*67e74705SXin Lidirectly as an interrupt service routine. 955*67e74705SXin Li 956*67e74705SXin LiBy default, the compiler will produce a function prologue and epilogue suitable for 957*67e74705SXin Lian interrupt service routine that handles an External Interrupt Controller (eic) 958*67e74705SXin Ligenerated interrupt. This behaviour can be explicitly requested with the "eic" 959*67e74705SXin Liargument. 960*67e74705SXin Li 961*67e74705SXin LiOtherwise, for use with vectored interrupt mode, the argument passed should be 962*67e74705SXin Liof the form "vector=LEVEL" where LEVEL is one of the following values: 963*67e74705SXin Li"sw0", "sw1", "hw0", "hw1", "hw2", "hw3", "hw4", "hw5". The compiler will 964*67e74705SXin Lithen set the interrupt mask to the corresponding level which will mask all 965*67e74705SXin Liinterrupts up to and including the argument. 966*67e74705SXin Li 967*67e74705SXin LiThe semantics are as follows: 968*67e74705SXin Li 969*67e74705SXin Li- The prologue is modified so that the Exception Program Counter (EPC) and 970*67e74705SXin Li Status coprocessor registers are saved to the stack. The interrupt mask is 971*67e74705SXin Li set so that the function can only be interrupted by a higher priority 972*67e74705SXin Li interrupt. The epilogue will restore the previous values of EPC and Status. 973*67e74705SXin Li 974*67e74705SXin Li- The prologue and epilogue are modified to save and restore all non-kernel 975*67e74705SXin Li registers as necessary. 976*67e74705SXin Li 977*67e74705SXin Li- The FPU is disabled in the prologue, as the floating pointer registers are not 978*67e74705SXin Li spilled to the stack. 979*67e74705SXin Li 980*67e74705SXin Li- The function return sequence is changed to use an exception return instruction. 981*67e74705SXin Li 982*67e74705SXin Li- The parameter sets the interrupt mask for the function corresponding to the 983*67e74705SXin Li interrupt level specified. If no mask is specified the interrupt mask 984*67e74705SXin Li defaults to "eic". 985*67e74705SXin Li }]; 986*67e74705SXin Li} 987*67e74705SXin Li 988*67e74705SXin Lidef TargetDocs : Documentation { 989*67e74705SXin Li let Category = DocCatFunction; 990*67e74705SXin Li let Content = [{ 991*67e74705SXin LiClang supports the GNU style ``__attribute__((target("OPTIONS")))`` attribute. 992*67e74705SXin LiThis attribute may be attached to a function definition and instructs 993*67e74705SXin Lithe backend to use different code generation options than were passed on the 994*67e74705SXin Licommand line. 995*67e74705SXin Li 996*67e74705SXin LiThe current set of options correspond to the existing "subtarget features" for 997*67e74705SXin Lithe target with or without a "-mno-" in front corresponding to the absence 998*67e74705SXin Liof the feature, as well as ``arch="CPU"`` which will change the default "CPU" 999*67e74705SXin Lifor the function. 1000*67e74705SXin Li 1001*67e74705SXin LiExample "subtarget features" from the x86 backend include: "mmx", "sse", "sse4.2", 1002*67e74705SXin Li"avx", "xop" and largely correspond to the machine specific options handled by 1003*67e74705SXin Lithe front end. 1004*67e74705SXin Li}]; 1005*67e74705SXin Li} 1006*67e74705SXin Li 1007*67e74705SXin Lidef DocCatAMDGPURegisterAttributes : 1008*67e74705SXin Li DocumentationCategory<"AMD GPU Register Attributes"> { 1009*67e74705SXin Li let Content = [{ 1010*67e74705SXin LiClang supports attributes for controlling register usage on AMD GPU 1011*67e74705SXin Litargets. These attributes may be attached to a kernel function 1012*67e74705SXin Lidefinition and is an optimization hint to the backend for the maximum 1013*67e74705SXin Linumber of registers to use. This is useful in cases where register 1014*67e74705SXin Lilimited occupancy is known to be an important factor for the 1015*67e74705SXin Liperformance for the kernel. 1016*67e74705SXin Li 1017*67e74705SXin LiThe semantics are as follows: 1018*67e74705SXin Li 1019*67e74705SXin Li- The backend will attempt to limit the number of used registers to 1020*67e74705SXin Li the specified value, but the exact number used is not 1021*67e74705SXin Li guaranteed. The number used may be rounded up to satisfy the 1022*67e74705SXin Li allocation requirements or ABI constraints of the subtarget. For 1023*67e74705SXin Li example, on Southern Islands VGPRs may only be allocated in 1024*67e74705SXin Li increments of 4, so requesting a limit of 39 VGPRs will really 1025*67e74705SXin Li attempt to use up to 40. Requesting more registers than the 1026*67e74705SXin Li subtarget supports will truncate to the maximum allowed. The backend 1027*67e74705SXin Li may also use fewer registers than requested whenever possible. 1028*67e74705SXin Li 1029*67e74705SXin Li- 0 implies the default no limit on register usage. 1030*67e74705SXin Li 1031*67e74705SXin Li- Ignored on older VLIW subtargets which did not have separate scalar 1032*67e74705SXin Li and vector registers, R600 through Northern Islands. 1033*67e74705SXin Li 1034*67e74705SXin Li}]; 1035*67e74705SXin Li} 1036*67e74705SXin Li 1037*67e74705SXin Li 1038*67e74705SXin Lidef AMDGPUNumVGPRDocs : Documentation { 1039*67e74705SXin Li let Category = DocCatAMDGPURegisterAttributes; 1040*67e74705SXin Li let Content = [{ 1041*67e74705SXin LiClang supports the 1042*67e74705SXin Li``__attribute__((amdgpu_num_vgpr(<num_registers>)))`` attribute on AMD 1043*67e74705SXin LiSouthern Islands GPUs and later for controlling the number of vector 1044*67e74705SXin Liregisters. A typical value would be between 4 and 256 in increments 1045*67e74705SXin Liof 4. 1046*67e74705SXin Li}]; 1047*67e74705SXin Li} 1048*67e74705SXin Li 1049*67e74705SXin Lidef AMDGPUNumSGPRDocs : Documentation { 1050*67e74705SXin Li let Category = DocCatAMDGPURegisterAttributes; 1051*67e74705SXin Li let Content = [{ 1052*67e74705SXin Li 1053*67e74705SXin LiClang supports the 1054*67e74705SXin Li``__attribute__((amdgpu_num_sgpr(<num_registers>)))`` attribute on AMD 1055*67e74705SXin LiSouthern Islands GPUs and later for controlling the number of scalar 1056*67e74705SXin Liregisters. A typical value would be between 8 and 104 in increments of 1057*67e74705SXin Li8. 1058*67e74705SXin Li 1059*67e74705SXin LiDue to common instruction constraints, an additional 2-4 SGPRs are 1060*67e74705SXin Litypically required for internal use depending on features used. This 1061*67e74705SXin Livalue is a hint for the total number of SGPRs to use, and not the 1062*67e74705SXin Linumber of user SGPRs, so no special consideration needs to be given 1063*67e74705SXin Lifor these. 1064*67e74705SXin Li}]; 1065*67e74705SXin Li} 1066*67e74705SXin Li 1067*67e74705SXin Lidef DocCatCallingConvs : DocumentationCategory<"Calling Conventions"> { 1068*67e74705SXin Li let Content = [{ 1069*67e74705SXin LiClang supports several different calling conventions, depending on the target 1070*67e74705SXin Liplatform and architecture. The calling convention used for a function determines 1071*67e74705SXin Lihow parameters are passed, how results are returned to the caller, and other 1072*67e74705SXin Lilow-level details of calling a function. 1073*67e74705SXin Li }]; 1074*67e74705SXin Li} 1075*67e74705SXin Li 1076*67e74705SXin Lidef PcsDocs : Documentation { 1077*67e74705SXin Li let Category = DocCatCallingConvs; 1078*67e74705SXin Li let Content = [{ 1079*67e74705SXin LiOn ARM targets, this attribute can be used to select calling conventions 1080*67e74705SXin Lisimilar to ``stdcall`` on x86. Valid parameter values are "aapcs" and 1081*67e74705SXin Li"aapcs-vfp". 1082*67e74705SXin Li }]; 1083*67e74705SXin Li} 1084*67e74705SXin Li 1085*67e74705SXin Lidef RegparmDocs : Documentation { 1086*67e74705SXin Li let Category = DocCatCallingConvs; 1087*67e74705SXin Li let Content = [{ 1088*67e74705SXin LiOn 32-bit x86 targets, the regparm attribute causes the compiler to pass 1089*67e74705SXin Lithe first three integer parameters in EAX, EDX, and ECX instead of on the 1090*67e74705SXin Listack. This attribute has no effect on variadic functions, and all parameters 1091*67e74705SXin Liare passed via the stack as normal. 1092*67e74705SXin Li }]; 1093*67e74705SXin Li} 1094*67e74705SXin Li 1095*67e74705SXin Lidef SysVABIDocs : Documentation { 1096*67e74705SXin Li let Category = DocCatCallingConvs; 1097*67e74705SXin Li let Content = [{ 1098*67e74705SXin LiOn Windows x86_64 targets, this attribute changes the calling convention of a 1099*67e74705SXin Lifunction to match the default convention used on Sys V targets such as Linux, 1100*67e74705SXin LiMac, and BSD. This attribute has no effect on other targets. 1101*67e74705SXin Li }]; 1102*67e74705SXin Li} 1103*67e74705SXin Li 1104*67e74705SXin Lidef MSABIDocs : Documentation { 1105*67e74705SXin Li let Category = DocCatCallingConvs; 1106*67e74705SXin Li let Content = [{ 1107*67e74705SXin LiOn non-Windows x86_64 targets, this attribute changes the calling convention of 1108*67e74705SXin Lia function to match the default convention used on Windows x86_64. This 1109*67e74705SXin Liattribute has no effect on Windows targets or non-x86_64 targets. 1110*67e74705SXin Li }]; 1111*67e74705SXin Li} 1112*67e74705SXin Li 1113*67e74705SXin Lidef StdCallDocs : Documentation { 1114*67e74705SXin Li let Category = DocCatCallingConvs; 1115*67e74705SXin Li let Content = [{ 1116*67e74705SXin LiOn 32-bit x86 targets, this attribute changes the calling convention of a 1117*67e74705SXin Lifunction to clear parameters off of the stack on return. This convention does 1118*67e74705SXin Linot support variadic calls or unprototyped functions in C, and has no effect on 1119*67e74705SXin Lix86_64 targets. This calling convention is used widely by the Windows API and 1120*67e74705SXin LiCOM applications. See the documentation for `__stdcall`_ on MSDN. 1121*67e74705SXin Li 1122*67e74705SXin Li.. _`__stdcall`: http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx 1123*67e74705SXin Li }]; 1124*67e74705SXin Li} 1125*67e74705SXin Li 1126*67e74705SXin Lidef FastCallDocs : Documentation { 1127*67e74705SXin Li let Category = DocCatCallingConvs; 1128*67e74705SXin Li let Content = [{ 1129*67e74705SXin LiOn 32-bit x86 targets, this attribute changes the calling convention of a 1130*67e74705SXin Lifunction to use ECX and EDX as register parameters and clear parameters off of 1131*67e74705SXin Lithe stack on return. This convention does not support variadic calls or 1132*67e74705SXin Liunprototyped functions in C, and has no effect on x86_64 targets. This calling 1133*67e74705SXin Liconvention is supported primarily for compatibility with existing code. Users 1134*67e74705SXin Liseeking register parameters should use the ``regparm`` attribute, which does 1135*67e74705SXin Linot require callee-cleanup. See the documentation for `__fastcall`_ on MSDN. 1136*67e74705SXin Li 1137*67e74705SXin Li.. _`__fastcall`: http://msdn.microsoft.com/en-us/library/6xa169sk.aspx 1138*67e74705SXin Li }]; 1139*67e74705SXin Li} 1140*67e74705SXin Li 1141*67e74705SXin Lidef ThisCallDocs : Documentation { 1142*67e74705SXin Li let Category = DocCatCallingConvs; 1143*67e74705SXin Li let Content = [{ 1144*67e74705SXin LiOn 32-bit x86 targets, this attribute changes the calling convention of a 1145*67e74705SXin Lifunction to use ECX for the first parameter (typically the implicit ``this`` 1146*67e74705SXin Liparameter of C++ methods) and clear parameters off of the stack on return. This 1147*67e74705SXin Liconvention does not support variadic calls or unprototyped functions in C, and 1148*67e74705SXin Lihas no effect on x86_64 targets. See the documentation for `__thiscall`_ on 1149*67e74705SXin LiMSDN. 1150*67e74705SXin Li 1151*67e74705SXin Li.. _`__thiscall`: http://msdn.microsoft.com/en-us/library/ek8tkfbw.aspx 1152*67e74705SXin Li }]; 1153*67e74705SXin Li} 1154*67e74705SXin Li 1155*67e74705SXin Lidef VectorCallDocs : Documentation { 1156*67e74705SXin Li let Category = DocCatCallingConvs; 1157*67e74705SXin Li let Content = [{ 1158*67e74705SXin LiOn 32-bit x86 *and* x86_64 targets, this attribute changes the calling 1159*67e74705SXin Liconvention of a function to pass vector parameters in SSE registers. 1160*67e74705SXin Li 1161*67e74705SXin LiOn 32-bit x86 targets, this calling convention is similar to ``__fastcall``. 1162*67e74705SXin LiThe first two integer parameters are passed in ECX and EDX. Subsequent integer 1163*67e74705SXin Liparameters are passed in memory, and callee clears the stack. On x86_64 1164*67e74705SXin Litargets, the callee does *not* clear the stack, and integer parameters are 1165*67e74705SXin Lipassed in RCX, RDX, R8, and R9 as is done for the default Windows x64 calling 1166*67e74705SXin Liconvention. 1167*67e74705SXin Li 1168*67e74705SXin LiOn both 32-bit x86 and x86_64 targets, vector and floating point arguments are 1169*67e74705SXin Lipassed in XMM0-XMM5. Homogenous vector aggregates of up to four elements are 1170*67e74705SXin Lipassed in sequential SSE registers if enough are available. If AVX is enabled, 1171*67e74705SXin Li256 bit vectors are passed in YMM0-YMM5. Any vector or aggregate type that 1172*67e74705SXin Licannot be passed in registers for any reason is passed by reference, which 1173*67e74705SXin Liallows the caller to align the parameter memory. 1174*67e74705SXin Li 1175*67e74705SXin LiSee the documentation for `__vectorcall`_ on MSDN for more details. 1176*67e74705SXin Li 1177*67e74705SXin Li.. _`__vectorcall`: http://msdn.microsoft.com/en-us/library/dn375768.aspx 1178*67e74705SXin Li }]; 1179*67e74705SXin Li} 1180*67e74705SXin Li 1181*67e74705SXin Lidef DocCatConsumed : DocumentationCategory<"Consumed Annotation Checking"> { 1182*67e74705SXin Li let Content = [{ 1183*67e74705SXin LiClang supports additional attributes for checking basic resource management 1184*67e74705SXin Liproperties, specifically for unique objects that have a single owning reference. 1185*67e74705SXin LiThe following attributes are currently supported, although **the implementation 1186*67e74705SXin Lifor these annotations is currently in development and are subject to change.** 1187*67e74705SXin Li }]; 1188*67e74705SXin Li} 1189*67e74705SXin Li 1190*67e74705SXin Lidef SetTypestateDocs : Documentation { 1191*67e74705SXin Li let Category = DocCatConsumed; 1192*67e74705SXin Li let Content = [{ 1193*67e74705SXin LiAnnotate methods that transition an object into a new state with 1194*67e74705SXin Li``__attribute__((set_typestate(new_state)))``. The new state must be 1195*67e74705SXin Liunconsumed, consumed, or unknown. 1196*67e74705SXin Li }]; 1197*67e74705SXin Li} 1198*67e74705SXin Li 1199*67e74705SXin Lidef CallableWhenDocs : Documentation { 1200*67e74705SXin Li let Category = DocCatConsumed; 1201*67e74705SXin Li let Content = [{ 1202*67e74705SXin LiUse ``__attribute__((callable_when(...)))`` to indicate what states a method 1203*67e74705SXin Limay be called in. Valid states are unconsumed, consumed, or unknown. Each 1204*67e74705SXin Liargument to this attribute must be a quoted string. E.g.: 1205*67e74705SXin Li 1206*67e74705SXin Li``__attribute__((callable_when("unconsumed", "unknown")))`` 1207*67e74705SXin Li }]; 1208*67e74705SXin Li} 1209*67e74705SXin Li 1210*67e74705SXin Lidef TestTypestateDocs : Documentation { 1211*67e74705SXin Li let Category = DocCatConsumed; 1212*67e74705SXin Li let Content = [{ 1213*67e74705SXin LiUse ``__attribute__((test_typestate(tested_state)))`` to indicate that a method 1214*67e74705SXin Lireturns true if the object is in the specified state.. 1215*67e74705SXin Li }]; 1216*67e74705SXin Li} 1217*67e74705SXin Li 1218*67e74705SXin Lidef ParamTypestateDocs : Documentation { 1219*67e74705SXin Li let Category = DocCatConsumed; 1220*67e74705SXin Li let Content = [{ 1221*67e74705SXin LiThis attribute specifies expectations about function parameters. Calls to an 1222*67e74705SXin Lifunction with annotated parameters will issue a warning if the corresponding 1223*67e74705SXin Liargument isn't in the expected state. The attribute is also used to set the 1224*67e74705SXin Liinitial state of the parameter when analyzing the function's body. 1225*67e74705SXin Li }]; 1226*67e74705SXin Li} 1227*67e74705SXin Li 1228*67e74705SXin Lidef ReturnTypestateDocs : Documentation { 1229*67e74705SXin Li let Category = DocCatConsumed; 1230*67e74705SXin Li let Content = [{ 1231*67e74705SXin LiThe ``return_typestate`` attribute can be applied to functions or parameters. 1232*67e74705SXin LiWhen applied to a function the attribute specifies the state of the returned 1233*67e74705SXin Livalue. The function's body is checked to ensure that it always returns a value 1234*67e74705SXin Liin the specified state. On the caller side, values returned by the annotated 1235*67e74705SXin Lifunction are initialized to the given state. 1236*67e74705SXin Li 1237*67e74705SXin LiWhen applied to a function parameter it modifies the state of an argument after 1238*67e74705SXin Lia call to the function returns. The function's body is checked to ensure that 1239*67e74705SXin Lithe parameter is in the expected state before returning. 1240*67e74705SXin Li }]; 1241*67e74705SXin Li} 1242*67e74705SXin Li 1243*67e74705SXin Lidef ConsumableDocs : Documentation { 1244*67e74705SXin Li let Category = DocCatConsumed; 1245*67e74705SXin Li let Content = [{ 1246*67e74705SXin LiEach ``class`` that uses any of the typestate annotations must first be marked 1247*67e74705SXin Liusing the ``consumable`` attribute. Failure to do so will result in a warning. 1248*67e74705SXin Li 1249*67e74705SXin LiThis attribute accepts a single parameter that must be one of the following: 1250*67e74705SXin Li``unknown``, ``consumed``, or ``unconsumed``. 1251*67e74705SXin Li }]; 1252*67e74705SXin Li} 1253*67e74705SXin Li 1254*67e74705SXin Lidef NoSanitizeDocs : Documentation { 1255*67e74705SXin Li let Category = DocCatFunction; 1256*67e74705SXin Li let Content = [{ 1257*67e74705SXin LiUse the ``no_sanitize`` attribute on a function declaration to specify 1258*67e74705SXin Lithat a particular instrumentation or set of instrumentations should not be 1259*67e74705SXin Liapplied to that function. The attribute takes a list of string literals, 1260*67e74705SXin Liwhich have the same meaning as values accepted by the ``-fno-sanitize=`` 1261*67e74705SXin Liflag. For example, ``__attribute__((no_sanitize("address", "thread")))`` 1262*67e74705SXin Lispecifies that AddressSanitizer and ThreadSanitizer should not be applied 1263*67e74705SXin Lito the function. 1264*67e74705SXin Li 1265*67e74705SXin LiSee :ref:`Controlling Code Generation <controlling-code-generation>` for a 1266*67e74705SXin Lifull list of supported sanitizer flags. 1267*67e74705SXin Li }]; 1268*67e74705SXin Li} 1269*67e74705SXin Li 1270*67e74705SXin Lidef NoSanitizeAddressDocs : Documentation { 1271*67e74705SXin Li let Category = DocCatFunction; 1272*67e74705SXin Li // This function has multiple distinct spellings, and so it requires a custom 1273*67e74705SXin Li // heading to be specified. The most common spelling is sufficient. 1274*67e74705SXin Li let Heading = "no_sanitize_address (no_address_safety_analysis, gnu::no_address_safety_analysis, gnu::no_sanitize_address)"; 1275*67e74705SXin Li let Content = [{ 1276*67e74705SXin Li.. _langext-address_sanitizer: 1277*67e74705SXin Li 1278*67e74705SXin LiUse ``__attribute__((no_sanitize_address))`` on a function declaration to 1279*67e74705SXin Lispecify that address safety instrumentation (e.g. AddressSanitizer) should 1280*67e74705SXin Linot be applied to that function. 1281*67e74705SXin Li }]; 1282*67e74705SXin Li} 1283*67e74705SXin Li 1284*67e74705SXin Lidef NoSanitizeThreadDocs : Documentation { 1285*67e74705SXin Li let Category = DocCatFunction; 1286*67e74705SXin Li let Heading = "no_sanitize_thread"; 1287*67e74705SXin Li let Content = [{ 1288*67e74705SXin Li.. _langext-thread_sanitizer: 1289*67e74705SXin Li 1290*67e74705SXin LiUse ``__attribute__((no_sanitize_thread))`` on a function declaration to 1291*67e74705SXin Lispecify that checks for data races on plain (non-atomic) memory accesses should 1292*67e74705SXin Linot be inserted by ThreadSanitizer. The function is still instrumented by the 1293*67e74705SXin Litool to avoid false positives and provide meaningful stack traces. 1294*67e74705SXin Li }]; 1295*67e74705SXin Li} 1296*67e74705SXin Li 1297*67e74705SXin Lidef NoSanitizeMemoryDocs : Documentation { 1298*67e74705SXin Li let Category = DocCatFunction; 1299*67e74705SXin Li let Heading = "no_sanitize_memory"; 1300*67e74705SXin Li let Content = [{ 1301*67e74705SXin Li.. _langext-memory_sanitizer: 1302*67e74705SXin Li 1303*67e74705SXin LiUse ``__attribute__((no_sanitize_memory))`` on a function declaration to 1304*67e74705SXin Lispecify that checks for uninitialized memory should not be inserted 1305*67e74705SXin Li(e.g. by MemorySanitizer). The function may still be instrumented by the tool 1306*67e74705SXin Lito avoid false positives in other places. 1307*67e74705SXin Li }]; 1308*67e74705SXin Li} 1309*67e74705SXin Li 1310*67e74705SXin Lidef DocCatTypeSafety : DocumentationCategory<"Type Safety Checking"> { 1311*67e74705SXin Li let Content = [{ 1312*67e74705SXin LiClang supports additional attributes to enable checking type safety properties 1313*67e74705SXin Lithat can't be enforced by the C type system. Use cases include: 1314*67e74705SXin Li 1315*67e74705SXin Li* MPI library implementations, where these attributes enable checking that 1316*67e74705SXin Li the buffer type matches the passed ``MPI_Datatype``; 1317*67e74705SXin Li* for HDF5 library there is a similar use case to MPI; 1318*67e74705SXin Li* checking types of variadic functions' arguments for functions like 1319*67e74705SXin Li ``fcntl()`` and ``ioctl()``. 1320*67e74705SXin Li 1321*67e74705SXin LiYou can detect support for these attributes with ``__has_attribute()``. For 1322*67e74705SXin Liexample: 1323*67e74705SXin Li 1324*67e74705SXin Li.. code-block:: c++ 1325*67e74705SXin Li 1326*67e74705SXin Li #if defined(__has_attribute) 1327*67e74705SXin Li # if __has_attribute(argument_with_type_tag) && \ 1328*67e74705SXin Li __has_attribute(pointer_with_type_tag) && \ 1329*67e74705SXin Li __has_attribute(type_tag_for_datatype) 1330*67e74705SXin Li # define ATTR_MPI_PWT(buffer_idx, type_idx) __attribute__((pointer_with_type_tag(mpi,buffer_idx,type_idx))) 1331*67e74705SXin Li /* ... other macros ... */ 1332*67e74705SXin Li # endif 1333*67e74705SXin Li #endif 1334*67e74705SXin Li 1335*67e74705SXin Li #if !defined(ATTR_MPI_PWT) 1336*67e74705SXin Li # define ATTR_MPI_PWT(buffer_idx, type_idx) 1337*67e74705SXin Li #endif 1338*67e74705SXin Li 1339*67e74705SXin Li int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */) 1340*67e74705SXin Li ATTR_MPI_PWT(1,3); 1341*67e74705SXin Li }]; 1342*67e74705SXin Li} 1343*67e74705SXin Li 1344*67e74705SXin Lidef ArgumentWithTypeTagDocs : Documentation { 1345*67e74705SXin Li let Category = DocCatTypeSafety; 1346*67e74705SXin Li let Heading = "argument_with_type_tag"; 1347*67e74705SXin Li let Content = [{ 1348*67e74705SXin LiUse ``__attribute__((argument_with_type_tag(arg_kind, arg_idx, 1349*67e74705SXin Litype_tag_idx)))`` on a function declaration to specify that the function 1350*67e74705SXin Liaccepts a type tag that determines the type of some other argument. 1351*67e74705SXin Li``arg_kind`` is an identifier that should be used when annotating all 1352*67e74705SXin Liapplicable type tags. 1353*67e74705SXin Li 1354*67e74705SXin LiThis attribute is primarily useful for checking arguments of variadic functions 1355*67e74705SXin Li(``pointer_with_type_tag`` can be used in most non-variadic cases). 1356*67e74705SXin Li 1357*67e74705SXin LiFor example: 1358*67e74705SXin Li 1359*67e74705SXin Li.. code-block:: c++ 1360*67e74705SXin Li 1361*67e74705SXin Li int fcntl(int fd, int cmd, ...) 1362*67e74705SXin Li __attribute__(( argument_with_type_tag(fcntl,3,2) )); 1363*67e74705SXin Li }]; 1364*67e74705SXin Li} 1365*67e74705SXin Li 1366*67e74705SXin Lidef PointerWithTypeTagDocs : Documentation { 1367*67e74705SXin Li let Category = DocCatTypeSafety; 1368*67e74705SXin Li let Heading = "pointer_with_type_tag"; 1369*67e74705SXin Li let Content = [{ 1370*67e74705SXin LiUse ``__attribute__((pointer_with_type_tag(ptr_kind, ptr_idx, type_tag_idx)))`` 1371*67e74705SXin Lion a function declaration to specify that the function accepts a type tag that 1372*67e74705SXin Lidetermines the pointee type of some other pointer argument. 1373*67e74705SXin Li 1374*67e74705SXin LiFor example: 1375*67e74705SXin Li 1376*67e74705SXin Li.. code-block:: c++ 1377*67e74705SXin Li 1378*67e74705SXin Li int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */) 1379*67e74705SXin Li __attribute__(( pointer_with_type_tag(mpi,1,3) )); 1380*67e74705SXin Li }]; 1381*67e74705SXin Li} 1382*67e74705SXin Li 1383*67e74705SXin Lidef TypeTagForDatatypeDocs : Documentation { 1384*67e74705SXin Li let Category = DocCatTypeSafety; 1385*67e74705SXin Li let Content = [{ 1386*67e74705SXin LiClang supports annotating type tags of two forms. 1387*67e74705SXin Li 1388*67e74705SXin Li* **Type tag that is an expression containing a reference to some declared 1389*67e74705SXin Li identifier.** Use ``__attribute__((type_tag_for_datatype(kind, type)))`` on a 1390*67e74705SXin Li declaration with that identifier: 1391*67e74705SXin Li 1392*67e74705SXin Li .. code-block:: c++ 1393*67e74705SXin Li 1394*67e74705SXin Li extern struct mpi_datatype mpi_datatype_int 1395*67e74705SXin Li __attribute__(( type_tag_for_datatype(mpi,int) )); 1396*67e74705SXin Li #define MPI_INT ((MPI_Datatype) &mpi_datatype_int) 1397*67e74705SXin Li 1398*67e74705SXin Li* **Type tag that is an integral literal.** Introduce a ``static const`` 1399*67e74705SXin Li variable with a corresponding initializer value and attach 1400*67e74705SXin Li ``__attribute__((type_tag_for_datatype(kind, type)))`` on that declaration, 1401*67e74705SXin Li for example: 1402*67e74705SXin Li 1403*67e74705SXin Li .. code-block:: c++ 1404*67e74705SXin Li 1405*67e74705SXin Li #define MPI_INT ((MPI_Datatype) 42) 1406*67e74705SXin Li static const MPI_Datatype mpi_datatype_int 1407*67e74705SXin Li __attribute__(( type_tag_for_datatype(mpi,int) )) = 42 1408*67e74705SXin Li 1409*67e74705SXin LiThe attribute also accepts an optional third argument that determines how the 1410*67e74705SXin Liexpression is compared to the type tag. There are two supported flags: 1411*67e74705SXin Li 1412*67e74705SXin Li* ``layout_compatible`` will cause types to be compared according to 1413*67e74705SXin Li layout-compatibility rules (C++11 [class.mem] p 17, 18). This is 1414*67e74705SXin Li implemented to support annotating types like ``MPI_DOUBLE_INT``. 1415*67e74705SXin Li 1416*67e74705SXin Li For example: 1417*67e74705SXin Li 1418*67e74705SXin Li .. code-block:: c++ 1419*67e74705SXin Li 1420*67e74705SXin Li /* In mpi.h */ 1421*67e74705SXin Li struct internal_mpi_double_int { double d; int i; }; 1422*67e74705SXin Li extern struct mpi_datatype mpi_datatype_double_int 1423*67e74705SXin Li __attribute__(( type_tag_for_datatype(mpi, struct internal_mpi_double_int, layout_compatible) )); 1424*67e74705SXin Li 1425*67e74705SXin Li #define MPI_DOUBLE_INT ((MPI_Datatype) &mpi_datatype_double_int) 1426*67e74705SXin Li 1427*67e74705SXin Li /* In user code */ 1428*67e74705SXin Li struct my_pair { double a; int b; }; 1429*67e74705SXin Li struct my_pair *buffer; 1430*67e74705SXin Li MPI_Send(buffer, 1, MPI_DOUBLE_INT /*, ... */); // no warning 1431*67e74705SXin Li 1432*67e74705SXin Li struct my_int_pair { int a; int b; } 1433*67e74705SXin Li struct my_int_pair *buffer2; 1434*67e74705SXin Li MPI_Send(buffer2, 1, MPI_DOUBLE_INT /*, ... */); // warning: actual buffer element 1435*67e74705SXin Li // type 'struct my_int_pair' 1436*67e74705SXin Li // doesn't match specified MPI_Datatype 1437*67e74705SXin Li 1438*67e74705SXin Li* ``must_be_null`` specifies that the expression should be a null pointer 1439*67e74705SXin Li constant, for example: 1440*67e74705SXin Li 1441*67e74705SXin Li .. code-block:: c++ 1442*67e74705SXin Li 1443*67e74705SXin Li /* In mpi.h */ 1444*67e74705SXin Li extern struct mpi_datatype mpi_datatype_null 1445*67e74705SXin Li __attribute__(( type_tag_for_datatype(mpi, void, must_be_null) )); 1446*67e74705SXin Li 1447*67e74705SXin Li #define MPI_DATATYPE_NULL ((MPI_Datatype) &mpi_datatype_null) 1448*67e74705SXin Li 1449*67e74705SXin Li /* In user code */ 1450*67e74705SXin Li MPI_Send(buffer, 1, MPI_DATATYPE_NULL /*, ... */); // warning: MPI_DATATYPE_NULL 1451*67e74705SXin Li // was specified but buffer 1452*67e74705SXin Li // is not a null pointer 1453*67e74705SXin Li }]; 1454*67e74705SXin Li} 1455*67e74705SXin Li 1456*67e74705SXin Lidef FlattenDocs : Documentation { 1457*67e74705SXin Li let Category = DocCatFunction; 1458*67e74705SXin Li let Content = [{ 1459*67e74705SXin LiThe ``flatten`` attribute causes calls within the attributed function to 1460*67e74705SXin Libe inlined unless it is impossible to do so, for example if the body of the 1461*67e74705SXin Licallee is unavailable or if the callee has the ``noinline`` attribute. 1462*67e74705SXin Li }]; 1463*67e74705SXin Li} 1464*67e74705SXin Li 1465*67e74705SXin Lidef FormatDocs : Documentation { 1466*67e74705SXin Li let Category = DocCatFunction; 1467*67e74705SXin Li let Content = [{ 1468*67e74705SXin Li 1469*67e74705SXin LiClang supports the ``format`` attribute, which indicates that the function 1470*67e74705SXin Liaccepts a ``printf`` or ``scanf``-like format string and corresponding 1471*67e74705SXin Liarguments or a ``va_list`` that contains these arguments. 1472*67e74705SXin Li 1473*67e74705SXin LiPlease see `GCC documentation about format attribute 1474*67e74705SXin Li<http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>`_ to find details 1475*67e74705SXin Liabout attribute syntax. 1476*67e74705SXin Li 1477*67e74705SXin LiClang implements two kinds of checks with this attribute. 1478*67e74705SXin Li 1479*67e74705SXin Li#. Clang checks that the function with the ``format`` attribute is called with 1480*67e74705SXin Li a format string that uses format specifiers that are allowed, and that 1481*67e74705SXin Li arguments match the format string. This is the ``-Wformat`` warning, it is 1482*67e74705SXin Li on by default. 1483*67e74705SXin Li 1484*67e74705SXin Li#. Clang checks that the format string argument is a literal string. This is 1485*67e74705SXin Li the ``-Wformat-nonliteral`` warning, it is off by default. 1486*67e74705SXin Li 1487*67e74705SXin Li Clang implements this mostly the same way as GCC, but there is a difference 1488*67e74705SXin Li for functions that accept a ``va_list`` argument (for example, ``vprintf``). 1489*67e74705SXin Li GCC does not emit ``-Wformat-nonliteral`` warning for calls to such 1490*67e74705SXin Li functions. Clang does not warn if the format string comes from a function 1491*67e74705SXin Li parameter, where the function is annotated with a compatible attribute, 1492*67e74705SXin Li otherwise it warns. For example: 1493*67e74705SXin Li 1494*67e74705SXin Li .. code-block:: c 1495*67e74705SXin Li 1496*67e74705SXin Li __attribute__((__format__ (__scanf__, 1, 3))) 1497*67e74705SXin Li void foo(const char* s, char *buf, ...) { 1498*67e74705SXin Li va_list ap; 1499*67e74705SXin Li va_start(ap, buf); 1500*67e74705SXin Li 1501*67e74705SXin Li vprintf(s, ap); // warning: format string is not a string literal 1502*67e74705SXin Li } 1503*67e74705SXin Li 1504*67e74705SXin Li In this case we warn because ``s`` contains a format string for a 1505*67e74705SXin Li ``scanf``-like function, but it is passed to a ``printf``-like function. 1506*67e74705SXin Li 1507*67e74705SXin Li If the attribute is removed, clang still warns, because the format string is 1508*67e74705SXin Li not a string literal. 1509*67e74705SXin Li 1510*67e74705SXin Li Another example: 1511*67e74705SXin Li 1512*67e74705SXin Li .. code-block:: c 1513*67e74705SXin Li 1514*67e74705SXin Li __attribute__((__format__ (__printf__, 1, 3))) 1515*67e74705SXin Li void foo(const char* s, char *buf, ...) { 1516*67e74705SXin Li va_list ap; 1517*67e74705SXin Li va_start(ap, buf); 1518*67e74705SXin Li 1519*67e74705SXin Li vprintf(s, ap); // warning 1520*67e74705SXin Li } 1521*67e74705SXin Li 1522*67e74705SXin Li In this case Clang does not warn because the format string ``s`` and 1523*67e74705SXin Li the corresponding arguments are annotated. If the arguments are 1524*67e74705SXin Li incorrect, the caller of ``foo`` will receive a warning. 1525*67e74705SXin Li }]; 1526*67e74705SXin Li} 1527*67e74705SXin Li 1528*67e74705SXin Lidef AlignValueDocs : Documentation { 1529*67e74705SXin Li let Category = DocCatType; 1530*67e74705SXin Li let Content = [{ 1531*67e74705SXin LiThe align_value attribute can be added to the typedef of a pointer type or the 1532*67e74705SXin Lideclaration of a variable of pointer or reference type. It specifies that the 1533*67e74705SXin Lipointer will point to, or the reference will bind to, only objects with at 1534*67e74705SXin Lileast the provided alignment. This alignment value must be some positive power 1535*67e74705SXin Liof 2. 1536*67e74705SXin Li 1537*67e74705SXin Li .. code-block:: c 1538*67e74705SXin Li 1539*67e74705SXin Li typedef double * aligned_double_ptr __attribute__((align_value(64))); 1540*67e74705SXin Li void foo(double & x __attribute__((align_value(128)), 1541*67e74705SXin Li aligned_double_ptr y) { ... } 1542*67e74705SXin Li 1543*67e74705SXin LiIf the pointer value does not have the specified alignment at runtime, the 1544*67e74705SXin Libehavior of the program is undefined. 1545*67e74705SXin Li }]; 1546*67e74705SXin Li} 1547*67e74705SXin Li 1548*67e74705SXin Lidef FlagEnumDocs : Documentation { 1549*67e74705SXin Li let Category = DocCatType; 1550*67e74705SXin Li let Content = [{ 1551*67e74705SXin LiThis attribute can be added to an enumerator to signal to the compiler that it 1552*67e74705SXin Liis intended to be used as a flag type. This will cause the compiler to assume 1553*67e74705SXin Lithat the range of the type includes all of the values that you can get by 1554*67e74705SXin Limanipulating bits of the enumerator when issuing warnings. 1555*67e74705SXin Li }]; 1556*67e74705SXin Li} 1557*67e74705SXin Li 1558*67e74705SXin Lidef EmptyBasesDocs : Documentation { 1559*67e74705SXin Li let Category = DocCatType; 1560*67e74705SXin Li let Content = [{ 1561*67e74705SXin LiThe empty_bases attribute permits the compiler to utilize the 1562*67e74705SXin Liempty-base-optimization more frequently. 1563*67e74705SXin LiThis attribute only applies to struct, class, and union types. 1564*67e74705SXin LiIt is only supported when using the Microsoft C++ ABI. 1565*67e74705SXin Li }]; 1566*67e74705SXin Li} 1567*67e74705SXin Li 1568*67e74705SXin Lidef LayoutVersionDocs : Documentation { 1569*67e74705SXin Li let Category = DocCatType; 1570*67e74705SXin Li let Content = [{ 1571*67e74705SXin LiThe layout_version attribute requests that the compiler utilize the class 1572*67e74705SXin Lilayout rules of a particular compiler version. 1573*67e74705SXin LiThis attribute only applies to struct, class, and union types. 1574*67e74705SXin LiIt is only supported when using the Microsoft C++ ABI. 1575*67e74705SXin Li }]; 1576*67e74705SXin Li} 1577*67e74705SXin Li 1578*67e74705SXin Lidef MSInheritanceDocs : Documentation { 1579*67e74705SXin Li let Category = DocCatType; 1580*67e74705SXin Li let Heading = "__single_inhertiance, __multiple_inheritance, __virtual_inheritance"; 1581*67e74705SXin Li let Content = [{ 1582*67e74705SXin LiThis collection of keywords is enabled under ``-fms-extensions`` and controls 1583*67e74705SXin Lithe pointer-to-member representation used on ``*-*-win32`` targets. 1584*67e74705SXin Li 1585*67e74705SXin LiThe ``*-*-win32`` targets utilize a pointer-to-member representation which 1586*67e74705SXin Livaries in size and alignment depending on the definition of the underlying 1587*67e74705SXin Liclass. 1588*67e74705SXin Li 1589*67e74705SXin LiHowever, this is problematic when a forward declaration is only available and 1590*67e74705SXin Lino definition has been made yet. In such cases, Clang is forced to utilize the 1591*67e74705SXin Limost general representation that is available to it. 1592*67e74705SXin Li 1593*67e74705SXin LiThese keywords make it possible to use a pointer-to-member representation other 1594*67e74705SXin Lithan the most general one regardless of whether or not the definition will ever 1595*67e74705SXin Libe present in the current translation unit. 1596*67e74705SXin Li 1597*67e74705SXin LiThis family of keywords belong between the ``class-key`` and ``class-name``: 1598*67e74705SXin Li 1599*67e74705SXin Li.. code-block:: c++ 1600*67e74705SXin Li 1601*67e74705SXin Li struct __single_inheritance S; 1602*67e74705SXin Li int S::*i; 1603*67e74705SXin Li struct S {}; 1604*67e74705SXin Li 1605*67e74705SXin LiThis keyword can be applied to class templates but only has an effect when used 1606*67e74705SXin Lion full specializations: 1607*67e74705SXin Li 1608*67e74705SXin Li.. code-block:: c++ 1609*67e74705SXin Li 1610*67e74705SXin Li template <typename T, typename U> struct __single_inheritance A; // warning: inheritance model ignored on primary template 1611*67e74705SXin Li template <typename T> struct __multiple_inheritance A<T, T>; // warning: inheritance model ignored on partial specialization 1612*67e74705SXin Li template <> struct __single_inheritance A<int, float>; 1613*67e74705SXin Li 1614*67e74705SXin LiNote that choosing an inheritance model less general than strictly necessary is 1615*67e74705SXin Lian error: 1616*67e74705SXin Li 1617*67e74705SXin Li.. code-block:: c++ 1618*67e74705SXin Li 1619*67e74705SXin Li struct __multiple_inheritance S; // error: inheritance model does not match definition 1620*67e74705SXin Li int S::*i; 1621*67e74705SXin Li struct S {}; 1622*67e74705SXin Li}]; 1623*67e74705SXin Li} 1624*67e74705SXin Li 1625*67e74705SXin Lidef MSNoVTableDocs : Documentation { 1626*67e74705SXin Li let Category = DocCatType; 1627*67e74705SXin Li let Content = [{ 1628*67e74705SXin LiThis attribute can be added to a class declaration or definition to signal to 1629*67e74705SXin Lithe compiler that constructors and destructors will not reference the virtual 1630*67e74705SXin Lifunction table. It is only supported when using the Microsoft C++ ABI. 1631*67e74705SXin Li }]; 1632*67e74705SXin Li} 1633*67e74705SXin Li 1634*67e74705SXin Lidef OptnoneDocs : Documentation { 1635*67e74705SXin Li let Category = DocCatFunction; 1636*67e74705SXin Li let Content = [{ 1637*67e74705SXin LiThe ``optnone`` attribute suppresses essentially all optimizations 1638*67e74705SXin Lion a function or method, regardless of the optimization level applied to 1639*67e74705SXin Lithe compilation unit as a whole. This is particularly useful when you 1640*67e74705SXin Lineed to debug a particular function, but it is infeasible to build the 1641*67e74705SXin Lientire application without optimization. Avoiding optimization on the 1642*67e74705SXin Lispecified function can improve the quality of the debugging information 1643*67e74705SXin Lifor that function. 1644*67e74705SXin Li 1645*67e74705SXin LiThis attribute is incompatible with the ``always_inline`` and ``minsize`` 1646*67e74705SXin Liattributes. 1647*67e74705SXin Li }]; 1648*67e74705SXin Li} 1649*67e74705SXin Li 1650*67e74705SXin Lidef LoopHintDocs : Documentation { 1651*67e74705SXin Li let Category = DocCatStmt; 1652*67e74705SXin Li let Heading = "#pragma clang loop"; 1653*67e74705SXin Li let Content = [{ 1654*67e74705SXin LiThe ``#pragma clang loop`` directive allows loop optimization hints to be 1655*67e74705SXin Lispecified for the subsequent loop. The directive allows vectorization, 1656*67e74705SXin Liinterleaving, and unrolling to be enabled or disabled. Vector width as well 1657*67e74705SXin Lias interleave and unrolling count can be manually specified. See 1658*67e74705SXin Li`language extensions 1659*67e74705SXin Li<http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations>`_ 1660*67e74705SXin Lifor details. 1661*67e74705SXin Li }]; 1662*67e74705SXin Li} 1663*67e74705SXin Li 1664*67e74705SXin Lidef UnrollHintDocs : Documentation { 1665*67e74705SXin Li let Category = DocCatStmt; 1666*67e74705SXin Li let Heading = "#pragma unroll, #pragma nounroll"; 1667*67e74705SXin Li let Content = [{ 1668*67e74705SXin LiLoop unrolling optimization hints can be specified with ``#pragma unroll`` and 1669*67e74705SXin Li``#pragma nounroll``. The pragma is placed immediately before a for, while, 1670*67e74705SXin Lido-while, or c++11 range-based for loop. 1671*67e74705SXin Li 1672*67e74705SXin LiSpecifying ``#pragma unroll`` without a parameter directs the loop unroller to 1673*67e74705SXin Liattempt to fully unroll the loop if the trip count is known at compile time and 1674*67e74705SXin Liattempt to partially unroll the loop if the trip count is not known at compile 1675*67e74705SXin Litime: 1676*67e74705SXin Li 1677*67e74705SXin Li.. code-block:: c++ 1678*67e74705SXin Li 1679*67e74705SXin Li #pragma unroll 1680*67e74705SXin Li for (...) { 1681*67e74705SXin Li ... 1682*67e74705SXin Li } 1683*67e74705SXin Li 1684*67e74705SXin LiSpecifying the optional parameter, ``#pragma unroll _value_``, directs the 1685*67e74705SXin Liunroller to unroll the loop ``_value_`` times. The parameter may optionally be 1686*67e74705SXin Lienclosed in parentheses: 1687*67e74705SXin Li 1688*67e74705SXin Li.. code-block:: c++ 1689*67e74705SXin Li 1690*67e74705SXin Li #pragma unroll 16 1691*67e74705SXin Li for (...) { 1692*67e74705SXin Li ... 1693*67e74705SXin Li } 1694*67e74705SXin Li 1695*67e74705SXin Li #pragma unroll(16) 1696*67e74705SXin Li for (...) { 1697*67e74705SXin Li ... 1698*67e74705SXin Li } 1699*67e74705SXin Li 1700*67e74705SXin LiSpecifying ``#pragma nounroll`` indicates that the loop should not be unrolled: 1701*67e74705SXin Li 1702*67e74705SXin Li.. code-block:: c++ 1703*67e74705SXin Li 1704*67e74705SXin Li #pragma nounroll 1705*67e74705SXin Li for (...) { 1706*67e74705SXin Li ... 1707*67e74705SXin Li } 1708*67e74705SXin Li 1709*67e74705SXin Li``#pragma unroll`` and ``#pragma unroll _value_`` have identical semantics to 1710*67e74705SXin Li``#pragma clang loop unroll(full)`` and 1711*67e74705SXin Li``#pragma clang loop unroll_count(_value_)`` respectively. ``#pragma nounroll`` 1712*67e74705SXin Liis equivalent to ``#pragma clang loop unroll(disable)``. See 1713*67e74705SXin Li`language extensions 1714*67e74705SXin Li<http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations>`_ 1715*67e74705SXin Lifor further details including limitations of the unroll hints. 1716*67e74705SXin Li }]; 1717*67e74705SXin Li} 1718*67e74705SXin Li 1719*67e74705SXin Lidef OpenCLUnrollHintDocs : Documentation { 1720*67e74705SXin Li let Category = DocCatStmt; 1721*67e74705SXin Li let Heading = "__attribute__((opencl_unroll_hint))"; 1722*67e74705SXin Li let Content = [{ 1723*67e74705SXin LiThe opencl_unroll_hint attribute qualifier can be used to specify that a loop 1724*67e74705SXin Li(for, while and do loops) can be unrolled. This attribute qualifier can be 1725*67e74705SXin Liused to specify full unrolling or partial unrolling by a specified amount. 1726*67e74705SXin LiThis is a compiler hint and the compiler may ignore this directive. See 1727*67e74705SXin Li`OpenCL v2.0 <https://www.khronos.org/registry/cl/specs/opencl-2.0.pdf>`_ 1728*67e74705SXin Lis6.11.5 for details. 1729*67e74705SXin Li }]; 1730*67e74705SXin Li} 1731*67e74705SXin Li 1732*67e74705SXin Lidef OpenCLAccessDocs : Documentation { 1733*67e74705SXin Li let Category = DocCatStmt; 1734*67e74705SXin Li let Heading = "__read_only, __write_only, __read_write (read_only, write_only, read_write)"; 1735*67e74705SXin Li let Content = [{ 1736*67e74705SXin LiThe access qualifiers must be used with image object arguments or pipe arguments 1737*67e74705SXin Lito declare if they are being read or written by a kernel or function. 1738*67e74705SXin Li 1739*67e74705SXin LiThe read_only/__read_only, write_only/__write_only and read_write/__read_write 1740*67e74705SXin Linames are reserved for use as access qualifiers and shall not be used otherwise. 1741*67e74705SXin Li 1742*67e74705SXin Li.. code-block:: c 1743*67e74705SXin Li 1744*67e74705SXin Li kernel void 1745*67e74705SXin Li foo (read_only image2d_t imageA, 1746*67e74705SXin Li write_only image2d_t imageB) { 1747*67e74705SXin Li ... 1748*67e74705SXin Li } 1749*67e74705SXin Li 1750*67e74705SXin LiIn the above example imageA is a read-only 2D image object, and imageB is a 1751*67e74705SXin Liwrite-only 2D image object. 1752*67e74705SXin Li 1753*67e74705SXin LiThe read_write (or __read_write) qualifier can not be used with pipe. 1754*67e74705SXin Li 1755*67e74705SXin LiMore details can be found in the OpenCL C language Spec v2.0, Section 6.6. 1756*67e74705SXin Li }]; 1757*67e74705SXin Li} 1758*67e74705SXin Li 1759*67e74705SXin Lidef DocOpenCLAddressSpaces : DocumentationCategory<"OpenCL Address Spaces"> { 1760*67e74705SXin Li let Content = [{ 1761*67e74705SXin LiThe address space qualifier may be used to specify the region of memory that is 1762*67e74705SXin Liused to allocate the object. OpenCL supports the following address spaces: 1763*67e74705SXin Li__generic(generic), __global(global), __local(local), __private(private), 1764*67e74705SXin Li__constant(constant). 1765*67e74705SXin Li 1766*67e74705SXin Li .. code-block:: c 1767*67e74705SXin Li 1768*67e74705SXin Li __constant int c = ...; 1769*67e74705SXin Li 1770*67e74705SXin Li __generic int* foo(global int* g) { 1771*67e74705SXin Li __local int* l; 1772*67e74705SXin Li private int p; 1773*67e74705SXin Li ... 1774*67e74705SXin Li return l; 1775*67e74705SXin Li } 1776*67e74705SXin Li 1777*67e74705SXin LiMore details can be found in the OpenCL C language Spec v2.0, Section 6.5. 1778*67e74705SXin Li }]; 1779*67e74705SXin Li} 1780*67e74705SXin Li 1781*67e74705SXin Lidef OpenCLAddressSpaceGenericDocs : Documentation { 1782*67e74705SXin Li let Category = DocOpenCLAddressSpaces; 1783*67e74705SXin Li let Content = [{ 1784*67e74705SXin LiThe generic address space attribute is only available with OpenCL v2.0 and later. 1785*67e74705SXin LiIt can be used with pointer types. Variables in global and local scope and 1786*67e74705SXin Lifunction parameters in non-kernel functions can have the generic address space 1787*67e74705SXin Litype attribute. It is intended to be a placeholder for any other address space 1788*67e74705SXin Liexcept for '__constant' in OpenCL code which can be used with multiple address 1789*67e74705SXin Lispaces. 1790*67e74705SXin Li }]; 1791*67e74705SXin Li} 1792*67e74705SXin Li 1793*67e74705SXin Lidef OpenCLAddressSpaceConstantDocs : Documentation { 1794*67e74705SXin Li let Category = DocOpenCLAddressSpaces; 1795*67e74705SXin Li let Content = [{ 1796*67e74705SXin LiThe constant address space attribute signals that an object is located in 1797*67e74705SXin Lia constant (non-modifiable) memory region. It is available to all work items. 1798*67e74705SXin LiAny type can be annotated with the constant address space attribute. Objects 1799*67e74705SXin Liwith the constant address space qualifier can be declared in any scope and must 1800*67e74705SXin Lihave an initializer. 1801*67e74705SXin Li }]; 1802*67e74705SXin Li} 1803*67e74705SXin Li 1804*67e74705SXin Lidef OpenCLAddressSpaceGlobalDocs : Documentation { 1805*67e74705SXin Li let Category = DocOpenCLAddressSpaces; 1806*67e74705SXin Li let Content = [{ 1807*67e74705SXin LiThe global address space attribute specifies that an object is allocated in 1808*67e74705SXin Liglobal memory, which is accessible by all work items. The content stored in this 1809*67e74705SXin Limemory area persists between kernel executions. Pointer types to the global 1810*67e74705SXin Liaddress space are allowed as function parameters or local variables. Starting 1811*67e74705SXin Liwith OpenCL v2.0, the global address space can be used with global (program 1812*67e74705SXin Liscope) variables and static local variable as well. 1813*67e74705SXin Li }]; 1814*67e74705SXin Li} 1815*67e74705SXin Li 1816*67e74705SXin Lidef OpenCLAddressSpaceLocalDocs : Documentation { 1817*67e74705SXin Li let Category = DocOpenCLAddressSpaces; 1818*67e74705SXin Li let Content = [{ 1819*67e74705SXin LiThe local address space specifies that an object is allocated in the local (work 1820*67e74705SXin Ligroup) memory area, which is accessible to all work items in the same work 1821*67e74705SXin Ligroup. The content stored in this memory region is not accessible after 1822*67e74705SXin Lithe kernel execution ends. In a kernel function scope, any variable can be in 1823*67e74705SXin Lithe local address space. In other scopes, only pointer types to the local address 1824*67e74705SXin Lispace are allowed. Local address space variables cannot have an initializer. 1825*67e74705SXin Li }]; 1826*67e74705SXin Li} 1827*67e74705SXin Li 1828*67e74705SXin Lidef OpenCLAddressSpacePrivateDocs : Documentation { 1829*67e74705SXin Li let Category = DocOpenCLAddressSpaces; 1830*67e74705SXin Li let Content = [{ 1831*67e74705SXin LiThe private address space specifies that an object is allocated in the private 1832*67e74705SXin Li(work item) memory. Other work items cannot access the same memory area and its 1833*67e74705SXin Licontent is destroyed after work item execution ends. Local variables can be 1834*67e74705SXin Lideclared in the private address space. Function arguments are always in the 1835*67e74705SXin Liprivate address space. Kernel function arguments of a pointer or an array type 1836*67e74705SXin Licannot point to the private address space. 1837*67e74705SXin Li }]; 1838*67e74705SXin Li} 1839*67e74705SXin Li 1840*67e74705SXin Lidef OpenCLNoSVMDocs : Documentation { 1841*67e74705SXin Li let Category = DocCatVariable; 1842*67e74705SXin Li let Content = [{ 1843*67e74705SXin LiOpenCL 2.0 supports the optional ``__attribute__((nosvm))`` qualifier for 1844*67e74705SXin Lipointer variable. It informs the compiler that the pointer does not refer 1845*67e74705SXin Lito a shared virtual memory region. See OpenCL v2.0 s6.7.2 for details. 1846*67e74705SXin Li 1847*67e74705SXin LiSince it is not widely used and has been removed from OpenCL 2.1, it is ignored 1848*67e74705SXin Liby Clang. 1849*67e74705SXin Li }]; 1850*67e74705SXin Li} 1851*67e74705SXin Lidef NullabilityDocs : DocumentationCategory<"Nullability Attributes"> { 1852*67e74705SXin Li let Content = [{ 1853*67e74705SXin LiWhether a particular pointer may be "null" is an important concern when working with pointers in the C family of languages. The various nullability attributes indicate whether a particular pointer can be null or not, which makes APIs more expressive and can help static analysis tools identify bugs involving null pointers. Clang supports several kinds of nullability attributes: the ``nonnull`` and ``returns_nonnull`` attributes indicate which function or method parameters and result types can never be null, while nullability type qualifiers indicate which pointer types can be null (``_Nullable``) or cannot be null (``_Nonnull``). 1854*67e74705SXin Li 1855*67e74705SXin LiThe nullability (type) qualifiers express whether a value of a given pointer type can be null (the ``_Nullable`` qualifier), doesn't have a defined meaning for null (the ``_Nonnull`` qualifier), or for which the purpose of null is unclear (the ``_Null_unspecified`` qualifier). Because nullability qualifiers are expressed within the type system, they are more general than the ``nonnull`` and ``returns_nonnull`` attributes, allowing one to express (for example) a nullable pointer to an array of nonnull pointers. Nullability qualifiers are written to the right of the pointer to which they apply. For example: 1856*67e74705SXin Li 1857*67e74705SXin Li .. code-block:: c 1858*67e74705SXin Li 1859*67e74705SXin Li // No meaningful result when 'ptr' is null (here, it happens to be undefined behavior). 1860*67e74705SXin Li int fetch(int * _Nonnull ptr) { return *ptr; } 1861*67e74705SXin Li 1862*67e74705SXin Li // 'ptr' may be null. 1863*67e74705SXin Li int fetch_or_zero(int * _Nullable ptr) { 1864*67e74705SXin Li return ptr ? *ptr : 0; 1865*67e74705SXin Li } 1866*67e74705SXin Li 1867*67e74705SXin Li // A nullable pointer to non-null pointers to const characters. 1868*67e74705SXin Li const char *join_strings(const char * _Nonnull * _Nullable strings, unsigned n); 1869*67e74705SXin Li 1870*67e74705SXin LiIn Objective-C, there is an alternate spelling for the nullability qualifiers that can be used in Objective-C methods and properties using context-sensitive, non-underscored keywords. For example: 1871*67e74705SXin Li 1872*67e74705SXin Li .. code-block:: objective-c 1873*67e74705SXin Li 1874*67e74705SXin Li @interface NSView : NSResponder 1875*67e74705SXin Li - (nullable NSView *)ancestorSharedWithView:(nonnull NSView *)aView; 1876*67e74705SXin Li @property (assign, nullable) NSView *superview; 1877*67e74705SXin Li @property (readonly, nonnull) NSArray *subviews; 1878*67e74705SXin Li @end 1879*67e74705SXin Li }]; 1880*67e74705SXin Li} 1881*67e74705SXin Li 1882*67e74705SXin Lidef TypeNonNullDocs : Documentation { 1883*67e74705SXin Li let Category = NullabilityDocs; 1884*67e74705SXin Li let Content = [{ 1885*67e74705SXin LiThe ``_Nonnull`` nullability qualifier indicates that null is not a meaningful value for a value of the ``_Nonnull`` pointer type. For example, given a declaration such as: 1886*67e74705SXin Li 1887*67e74705SXin Li .. code-block:: c 1888*67e74705SXin Li 1889*67e74705SXin Li int fetch(int * _Nonnull ptr); 1890*67e74705SXin Li 1891*67e74705SXin Lia caller of ``fetch`` should not provide a null value, and the compiler will produce a warning if it sees a literal null value passed to ``fetch``. Note that, unlike the declaration attribute ``nonnull``, the presence of ``_Nonnull`` does not imply that passing null is undefined behavior: ``fetch`` is free to consider null undefined behavior or (perhaps for backward-compatibility reasons) defensively handle null. 1892*67e74705SXin Li }]; 1893*67e74705SXin Li} 1894*67e74705SXin Li 1895*67e74705SXin Lidef TypeNullableDocs : Documentation { 1896*67e74705SXin Li let Category = NullabilityDocs; 1897*67e74705SXin Li let Content = [{ 1898*67e74705SXin LiThe ``_Nullable`` nullability qualifier indicates that a value of the ``_Nullable`` pointer type can be null. For example, given: 1899*67e74705SXin Li 1900*67e74705SXin Li .. code-block:: c 1901*67e74705SXin Li 1902*67e74705SXin Li int fetch_or_zero(int * _Nullable ptr); 1903*67e74705SXin Li 1904*67e74705SXin Lia caller of ``fetch_or_zero`` can provide null. 1905*67e74705SXin Li }]; 1906*67e74705SXin Li} 1907*67e74705SXin Li 1908*67e74705SXin Lidef TypeNullUnspecifiedDocs : Documentation { 1909*67e74705SXin Li let Category = NullabilityDocs; 1910*67e74705SXin Li let Content = [{ 1911*67e74705SXin LiThe ``_Null_unspecified`` nullability qualifier indicates that neither the ``_Nonnull`` nor ``_Nullable`` qualifiers make sense for a particular pointer type. It is used primarily to indicate that the role of null with specific pointers in a nullability-annotated header is unclear, e.g., due to overly-complex implementations or historical factors with a long-lived API. 1912*67e74705SXin Li }]; 1913*67e74705SXin Li} 1914*67e74705SXin Li 1915*67e74705SXin Lidef NonNullDocs : Documentation { 1916*67e74705SXin Li let Category = NullabilityDocs; 1917*67e74705SXin Li let Content = [{ 1918*67e74705SXin LiThe ``nonnull`` attribute indicates that some function parameters must not be null, and can be used in several different ways. It's original usage (`from GCC <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes>`_) is as a function (or Objective-C method) attribute that specifies which parameters of the function are nonnull in a comma-separated list. For example: 1919*67e74705SXin Li 1920*67e74705SXin Li .. code-block:: c 1921*67e74705SXin Li 1922*67e74705SXin Li extern void * my_memcpy (void *dest, const void *src, size_t len) 1923*67e74705SXin Li __attribute__((nonnull (1, 2))); 1924*67e74705SXin Li 1925*67e74705SXin LiHere, the ``nonnull`` attribute indicates that parameters 1 and 2 1926*67e74705SXin Licannot have a null value. Omitting the parenthesized list of parameter indices means that all parameters of pointer type cannot be null: 1927*67e74705SXin Li 1928*67e74705SXin Li .. code-block:: c 1929*67e74705SXin Li 1930*67e74705SXin Li extern void * my_memcpy (void *dest, const void *src, size_t len) 1931*67e74705SXin Li __attribute__((nonnull)); 1932*67e74705SXin Li 1933*67e74705SXin LiClang also allows the ``nonnull`` attribute to be placed directly on a function (or Objective-C method) parameter, eliminating the need to specify the parameter index ahead of type. For example: 1934*67e74705SXin Li 1935*67e74705SXin Li .. code-block:: c 1936*67e74705SXin Li 1937*67e74705SXin Li extern void * my_memcpy (void *dest __attribute__((nonnull)), 1938*67e74705SXin Li const void *src __attribute__((nonnull)), size_t len); 1939*67e74705SXin Li 1940*67e74705SXin LiNote that the ``nonnull`` attribute indicates that passing null to a non-null parameter is undefined behavior, which the optimizer may take advantage of to, e.g., remove null checks. The ``_Nonnull`` type qualifier indicates that a pointer cannot be null in a more general manner (because it is part of the type system) and does not imply undefined behavior, making it more widely applicable. 1941*67e74705SXin Li }]; 1942*67e74705SXin Li} 1943*67e74705SXin Li 1944*67e74705SXin Lidef ReturnsNonNullDocs : Documentation { 1945*67e74705SXin Li let Category = NullabilityDocs; 1946*67e74705SXin Li let Content = [{ 1947*67e74705SXin LiThe ``returns_nonnull`` attribute indicates that a particular function (or Objective-C method) always returns a non-null pointer. For example, a particular system ``malloc`` might be defined to terminate a process when memory is not available rather than returning a null pointer: 1948*67e74705SXin Li 1949*67e74705SXin Li .. code-block:: c 1950*67e74705SXin Li 1951*67e74705SXin Li extern void * malloc (size_t size) __attribute__((returns_nonnull)); 1952*67e74705SXin Li 1953*67e74705SXin LiThe ``returns_nonnull`` attribute implies that returning a null pointer is undefined behavior, which the optimizer may take advantage of. The ``_Nonnull`` type qualifier indicates that a pointer cannot be null in a more general manner (because it is part of the type system) and does not imply undefined behavior, making it more widely applicable 1954*67e74705SXin Li}]; 1955*67e74705SXin Li} 1956*67e74705SXin Li 1957*67e74705SXin Lidef NoAliasDocs : Documentation { 1958*67e74705SXin Li let Category = DocCatFunction; 1959*67e74705SXin Li let Content = [{ 1960*67e74705SXin LiThe ``noalias`` attribute indicates that the only memory accesses inside 1961*67e74705SXin Lifunction are loads and stores from objects pointed to by its pointer-typed 1962*67e74705SXin Liarguments, with arbitrary offsets. 1963*67e74705SXin Li }]; 1964*67e74705SXin Li} 1965*67e74705SXin Li 1966*67e74705SXin Lidef OMPDeclareSimdDocs : Documentation { 1967*67e74705SXin Li let Category = DocCatFunction; 1968*67e74705SXin Li let Heading = "#pragma omp declare simd"; 1969*67e74705SXin Li let Content = [{ 1970*67e74705SXin LiThe `declare simd` construct can be applied to a function to enable the creation 1971*67e74705SXin Liof one or more versions that can process multiple arguments using SIMD 1972*67e74705SXin Liinstructions from a single invocation in a SIMD loop. The `declare simd` 1973*67e74705SXin Lidirective is a declarative directive. There may be multiple `declare simd` 1974*67e74705SXin Lidirectives for a function. The use of a `declare simd` construct on a function 1975*67e74705SXin Lienables the creation of SIMD versions of the associated function that can be 1976*67e74705SXin Liused to process multiple arguments from a single invocation from a SIMD loop 1977*67e74705SXin Liconcurrently. 1978*67e74705SXin LiThe syntax of the `declare simd` construct is as follows: 1979*67e74705SXin Li 1980*67e74705SXin Li .. code-block:: c 1981*67e74705SXin Li 1982*67e74705SXin Li #pragma omp declare simd [clause[[,] clause] ...] new-line 1983*67e74705SXin Li [#pragma omp declare simd [clause[[,] clause] ...] new-line] 1984*67e74705SXin Li [...] 1985*67e74705SXin Li function definition or declaration 1986*67e74705SXin Li 1987*67e74705SXin Liwhere clause is one of the following: 1988*67e74705SXin Li 1989*67e74705SXin Li .. code-block:: c 1990*67e74705SXin Li 1991*67e74705SXin Li simdlen(length) 1992*67e74705SXin Li linear(argument-list[:constant-linear-step]) 1993*67e74705SXin Li aligned(argument-list[:alignment]) 1994*67e74705SXin Li uniform(argument-list) 1995*67e74705SXin Li inbranch 1996*67e74705SXin Li notinbranch 1997*67e74705SXin Li 1998*67e74705SXin Li }]; 1999*67e74705SXin Li} 2000*67e74705SXin Li 2001*67e74705SXin Lidef OMPDeclareTargetDocs : Documentation { 2002*67e74705SXin Li let Category = DocCatFunction; 2003*67e74705SXin Li let Heading = "#pragma omp declare target"; 2004*67e74705SXin Li let Content = [{ 2005*67e74705SXin LiThe `declare target` directive specifies that variables and functions are mapped 2006*67e74705SXin Lito a device for OpenMP offload mechanism. 2007*67e74705SXin Li 2008*67e74705SXin LiThe syntax of the declare target directive is as follows: 2009*67e74705SXin Li 2010*67e74705SXin Li .. code-block:: c 2011*67e74705SXin Li 2012*67e74705SXin Li #pragma omp declare target new-line 2013*67e74705SXin Li declarations-definition-seq 2014*67e74705SXin Li #pragma omp end declare target new-line 2015*67e74705SXin Li }]; 2016*67e74705SXin Li} 2017*67e74705SXin Li 2018*67e74705SXin Lidef NotTailCalledDocs : Documentation { 2019*67e74705SXin Li let Category = DocCatFunction; 2020*67e74705SXin Li let Content = [{ 2021*67e74705SXin LiThe ``not_tail_called`` attribute prevents tail-call optimization on statically bound calls. It has no effect on indirect calls. Virtual functions, objective-c methods, and functions marked as ``always_inline`` cannot be marked as ``not_tail_called``. 2022*67e74705SXin Li 2023*67e74705SXin LiFor example, it prevents tail-call optimization in the following case: 2024*67e74705SXin Li 2025*67e74705SXin Li .. code-block:: c 2026*67e74705SXin Li 2027*67e74705SXin Li int __attribute__((not_tail_called)) foo1(int); 2028*67e74705SXin Li 2029*67e74705SXin Li int foo2(int a) { 2030*67e74705SXin Li return foo1(a); // No tail-call optimization on direct calls. 2031*67e74705SXin Li } 2032*67e74705SXin Li 2033*67e74705SXin LiHowever, it doesn't prevent tail-call optimization in this case: 2034*67e74705SXin Li 2035*67e74705SXin Li .. code-block:: c 2036*67e74705SXin Li 2037*67e74705SXin Li int __attribute__((not_tail_called)) foo1(int); 2038*67e74705SXin Li 2039*67e74705SXin Li int foo2(int a) { 2040*67e74705SXin Li int (*fn)(int) = &foo1; 2041*67e74705SXin Li 2042*67e74705SXin Li // not_tail_called has no effect on an indirect call even if the call can be 2043*67e74705SXin Li // resolved at compile time. 2044*67e74705SXin Li return (*fn)(a); 2045*67e74705SXin Li } 2046*67e74705SXin Li 2047*67e74705SXin LiMarking virtual functions as ``not_tail_called`` is an error: 2048*67e74705SXin Li 2049*67e74705SXin Li .. code-block:: c++ 2050*67e74705SXin Li 2051*67e74705SXin Li class Base { 2052*67e74705SXin Li public: 2053*67e74705SXin Li // not_tail_called on a virtual function is an error. 2054*67e74705SXin Li [[clang::not_tail_called]] virtual int foo1(); 2055*67e74705SXin Li 2056*67e74705SXin Li virtual int foo2(); 2057*67e74705SXin Li 2058*67e74705SXin Li // Non-virtual functions can be marked ``not_tail_called``. 2059*67e74705SXin Li [[clang::not_tail_called]] int foo3(); 2060*67e74705SXin Li }; 2061*67e74705SXin Li 2062*67e74705SXin Li class Derived1 : public Base { 2063*67e74705SXin Li public: 2064*67e74705SXin Li int foo1() override; 2065*67e74705SXin Li 2066*67e74705SXin Li // not_tail_called on a virtual function is an error. 2067*67e74705SXin Li [[clang::not_tail_called]] int foo2() override; 2068*67e74705SXin Li }; 2069*67e74705SXin Li }]; 2070*67e74705SXin Li} 2071*67e74705SXin Li 2072*67e74705SXin Lidef InternalLinkageDocs : Documentation { 2073*67e74705SXin Li let Category = DocCatFunction; 2074*67e74705SXin Li let Content = [{ 2075*67e74705SXin LiThe ``internal_linkage`` attribute changes the linkage type of the declaration to internal. 2076*67e74705SXin LiThis is similar to C-style ``static``, but can be used on classes and class methods. When applied to a class definition, 2077*67e74705SXin Lithis attribute affects all methods and static data members of that class. 2078*67e74705SXin LiThis can be used to contain the ABI of a C++ library by excluding unwanted class methods from the export tables. 2079*67e74705SXin Li }]; 2080*67e74705SXin Li} 2081*67e74705SXin Li 2082*67e74705SXin Lidef DisableTailCallsDocs : Documentation { 2083*67e74705SXin Li let Category = DocCatFunction; 2084*67e74705SXin Li let Content = [{ 2085*67e74705SXin LiThe ``disable_tail_calls`` attribute instructs the backend to not perform tail call optimization inside the marked function. 2086*67e74705SXin Li 2087*67e74705SXin LiFor example: 2088*67e74705SXin Li 2089*67e74705SXin Li .. code-block:: c 2090*67e74705SXin Li 2091*67e74705SXin Li int callee(int); 2092*67e74705SXin Li 2093*67e74705SXin Li int foo(int a) __attribute__((disable_tail_calls)) { 2094*67e74705SXin Li return callee(a); // This call is not tail-call optimized. 2095*67e74705SXin Li } 2096*67e74705SXin Li 2097*67e74705SXin LiMarking virtual functions as ``disable_tail_calls`` is legal. 2098*67e74705SXin Li 2099*67e74705SXin Li .. code-block:: c++ 2100*67e74705SXin Li 2101*67e74705SXin Li int callee(int); 2102*67e74705SXin Li 2103*67e74705SXin Li class Base { 2104*67e74705SXin Li public: 2105*67e74705SXin Li [[clang::disable_tail_calls]] virtual int foo1() { 2106*67e74705SXin Li return callee(); // This call is not tail-call optimized. 2107*67e74705SXin Li } 2108*67e74705SXin Li }; 2109*67e74705SXin Li 2110*67e74705SXin Li class Derived1 : public Base { 2111*67e74705SXin Li public: 2112*67e74705SXin Li int foo1() override { 2113*67e74705SXin Li return callee(); // This call is tail-call optimized. 2114*67e74705SXin Li } 2115*67e74705SXin Li }; 2116*67e74705SXin Li 2117*67e74705SXin Li }]; 2118*67e74705SXin Li} 2119*67e74705SXin Li 2120*67e74705SXin Lidef AnyX86InterruptDocs : Documentation { 2121*67e74705SXin Li let Category = DocCatFunction; 2122*67e74705SXin Li let Content = [{ 2123*67e74705SXin LiClang supports the GNU style ``__attribute__((interrupt))`` attribute on 2124*67e74705SXin Lix86/x86-64 targets.The compiler generates function entry and exit sequences 2125*67e74705SXin Lisuitable for use in an interrupt handler when this attribute is present. 2126*67e74705SXin LiThe 'IRET' instruction, instead of the 'RET' instruction, is used to return 2127*67e74705SXin Lifrom interrupt or exception handlers. All registers, except for the EFLAGS 2128*67e74705SXin Liregister which is restored by the 'IRET' instruction, are preserved by the 2129*67e74705SXin Licompiler. 2130*67e74705SXin Li 2131*67e74705SXin LiAny interruptible-without-stack-switch code must be compiled with 2132*67e74705SXin Li-mno-red-zone since interrupt handlers can and will, because of the 2133*67e74705SXin Lihardware design, touch the red zone. 2134*67e74705SXin Li 2135*67e74705SXin Li1. interrupt handler must be declared with a mandatory pointer argument: 2136*67e74705SXin Li 2137*67e74705SXin Li .. code-block:: c 2138*67e74705SXin Li 2139*67e74705SXin Li struct interrupt_frame 2140*67e74705SXin Li { 2141*67e74705SXin Li uword_t ip; 2142*67e74705SXin Li uword_t cs; 2143*67e74705SXin Li uword_t flags; 2144*67e74705SXin Li uword_t sp; 2145*67e74705SXin Li uword_t ss; 2146*67e74705SXin Li }; 2147*67e74705SXin Li 2148*67e74705SXin Li __attribute__ ((interrupt)) 2149*67e74705SXin Li void f (struct interrupt_frame *frame) { 2150*67e74705SXin Li ... 2151*67e74705SXin Li } 2152*67e74705SXin Li 2153*67e74705SXin Li2. exception handler: 2154*67e74705SXin Li 2155*67e74705SXin Li The exception handler is very similar to the interrupt handler with 2156*67e74705SXin Li a different mandatory function signature: 2157*67e74705SXin Li 2158*67e74705SXin Li .. code-block:: c 2159*67e74705SXin Li 2160*67e74705SXin Li __attribute__ ((interrupt)) 2161*67e74705SXin Li void f (struct interrupt_frame *frame, uword_t error_code) { 2162*67e74705SXin Li ... 2163*67e74705SXin Li } 2164*67e74705SXin Li 2165*67e74705SXin Li and compiler pops 'ERROR_CODE' off stack before the 'IRET' instruction. 2166*67e74705SXin Li 2167*67e74705SXin Li The exception handler should only be used for exceptions which push an 2168*67e74705SXin Li error code and all other exceptions must use the interrupt handler. 2169*67e74705SXin Li The system will crash if the wrong handler is used. 2170*67e74705SXin Li }]; 2171*67e74705SXin Li} 2172*67e74705SXin Li 2173*67e74705SXin Lidef SwiftCallDocs : Documentation { 2174*67e74705SXin Li let Category = DocCatVariable; 2175*67e74705SXin Li let Content = [{ 2176*67e74705SXin LiThe ``swiftcall`` attribute indicates that a function should be called 2177*67e74705SXin Liusing the Swift calling convention for a function or function pointer. 2178*67e74705SXin Li 2179*67e74705SXin LiThe lowering for the Swift calling convention, as described by the Swift 2180*67e74705SXin LiABI documentation, occurs in multiple phases. The first, "high-level" 2181*67e74705SXin Liphase breaks down the formal parameters and results into innately direct 2182*67e74705SXin Liand indirect components, adds implicit paraameters for the generic 2183*67e74705SXin Lisignature, and assigns the context and error ABI treatments to parameters 2184*67e74705SXin Liwhere applicable. The second phase breaks down the direct parameters 2185*67e74705SXin Liand results from the first phase and assigns them to registers or the 2186*67e74705SXin Listack. The ``swiftcall`` convention only handles this second phase of 2187*67e74705SXin Lilowering; the C function type must accurately reflect the results 2188*67e74705SXin Liof the first phase, as follows: 2189*67e74705SXin Li 2190*67e74705SXin Li- Results classified as indirect by high-level lowering should be 2191*67e74705SXin Li represented as parameters with the ``swift_indirect_result`` attribute. 2192*67e74705SXin Li 2193*67e74705SXin Li- Results classified as direct by high-level lowering should be represented 2194*67e74705SXin Li as follows: 2195*67e74705SXin Li 2196*67e74705SXin Li - First, remove any empty direct results. 2197*67e74705SXin Li 2198*67e74705SXin Li - If there are no direct results, the C result type should be ``void``. 2199*67e74705SXin Li 2200*67e74705SXin Li - If there is one direct result, the C result type should be a type with 2201*67e74705SXin Li the exact layout of that result type. 2202*67e74705SXin Li 2203*67e74705SXin Li - If there are a multiple direct results, the C result type should be 2204*67e74705SXin Li a struct type with the exact layout of a tuple of those results. 2205*67e74705SXin Li 2206*67e74705SXin Li- Parameters classified as indirect by high-level lowering should be 2207*67e74705SXin Li represented as parameters of pointer type. 2208*67e74705SXin Li 2209*67e74705SXin Li- Parameters classified as direct by high-level lowering should be 2210*67e74705SXin Li omitted if they are empty types; otherwise, they should be represented 2211*67e74705SXin Li as a parameter type with a layout exactly matching the layout of the 2212*67e74705SXin Li Swift parameter type. 2213*67e74705SXin Li 2214*67e74705SXin Li- The context parameter, if present, should be represented as a trailing 2215*67e74705SXin Li parameter with the ``swift_context`` attribute. 2216*67e74705SXin Li 2217*67e74705SXin Li- The error result parameter, if present, should be represented as a 2218*67e74705SXin Li trailing parameter (always following a context parameter) with the 2219*67e74705SXin Li ``swift_error_result`` attribute. 2220*67e74705SXin Li 2221*67e74705SXin Li``swiftcall`` does not support variadic arguments or unprototyped functions. 2222*67e74705SXin Li 2223*67e74705SXin LiThe parameter ABI treatment attributes are aspects of the function type. 2224*67e74705SXin LiA function type which which applies an ABI treatment attribute to a 2225*67e74705SXin Liparameter is a different type from an otherwise-identical function type 2226*67e74705SXin Lithat does not. A single parameter may not have multiple ABI treatment 2227*67e74705SXin Liattributes. 2228*67e74705SXin Li 2229*67e74705SXin LiSupport for this feature is target-dependent, although it should be 2230*67e74705SXin Lisupported on every target that Swift supports. Query for this support 2231*67e74705SXin Liwith ``__has_attribute(swiftcall)``. This implies support for the 2232*67e74705SXin Li``swift_context``, ``swift_error_result``, and ``swift_indirect_result`` 2233*67e74705SXin Liattributes. 2234*67e74705SXin Li }]; 2235*67e74705SXin Li} 2236*67e74705SXin Li 2237*67e74705SXin Lidef SwiftContextDocs : Documentation { 2238*67e74705SXin Li let Category = DocCatVariable; 2239*67e74705SXin Li let Content = [{ 2240*67e74705SXin LiThe ``swift_context`` attribute marks a parameter of a ``swiftcall`` 2241*67e74705SXin Lifunction as having the special context-parameter ABI treatment. 2242*67e74705SXin Li 2243*67e74705SXin LiThis treatment generally passes the context value in a special register 2244*67e74705SXin Liwhich is normally callee-preserved. 2245*67e74705SXin Li 2246*67e74705SXin LiA ``swift_context`` parameter must either be the last parameter or must be 2247*67e74705SXin Lifollowed by a ``swift_error_result`` parameter (which itself must always be 2248*67e74705SXin Lithe last parameter). 2249*67e74705SXin Li 2250*67e74705SXin LiA context parameter must have pointer or reference type. 2251*67e74705SXin Li }]; 2252*67e74705SXin Li} 2253*67e74705SXin Li 2254*67e74705SXin Lidef SwiftErrorResultDocs : Documentation { 2255*67e74705SXin Li let Category = DocCatVariable; 2256*67e74705SXin Li let Content = [{ 2257*67e74705SXin LiThe ``swift_error_result`` attribute marks a parameter of a ``swiftcall`` 2258*67e74705SXin Lifunction as having the special error-result ABI treatment. 2259*67e74705SXin Li 2260*67e74705SXin LiThis treatment generally passes the underlying error value in and out of 2261*67e74705SXin Lithe function through a special register which is normally callee-preserved. 2262*67e74705SXin LiThis is modeled in C by pretending that the register is addressable memory: 2263*67e74705SXin Li 2264*67e74705SXin Li- The caller appears to pass the address of a variable of pointer type. 2265*67e74705SXin Li The current value of this variable is copied into the register before 2266*67e74705SXin Li the call; if the call returns normally, the value is copied back into the 2267*67e74705SXin Li variable. 2268*67e74705SXin Li 2269*67e74705SXin Li- The callee appears to receive the address of a variable. This address 2270*67e74705SXin Li is actually a hidden location in its own stack, initialized with the 2271*67e74705SXin Li value of the register upon entry. When the function returns normally, 2272*67e74705SXin Li the value in that hidden location is written back to the register. 2273*67e74705SXin Li 2274*67e74705SXin LiA ``swift_error_result`` parameter must be the last parameter, and it must be 2275*67e74705SXin Lipreceded by a ``swift_context`` parameter. 2276*67e74705SXin Li 2277*67e74705SXin LiA ``swift_error_result`` parameter must have type ``T**`` or ``T*&`` for some 2278*67e74705SXin Litype T. Note that no qualifiers are permitted on the intermediate level. 2279*67e74705SXin Li 2280*67e74705SXin LiIt is undefined behavior if the caller does not pass a pointer or 2281*67e74705SXin Lireference to a valid object. 2282*67e74705SXin Li 2283*67e74705SXin LiThe standard convention is that the error value itself (that is, the 2284*67e74705SXin Livalue stored in the apparent argument) will be null upon function entry, 2285*67e74705SXin Libut this is not enforced by the ABI. 2286*67e74705SXin Li }]; 2287*67e74705SXin Li} 2288*67e74705SXin Li 2289*67e74705SXin Lidef SwiftIndirectResultDocs : Documentation { 2290*67e74705SXin Li let Category = DocCatVariable; 2291*67e74705SXin Li let Content = [{ 2292*67e74705SXin LiThe ``swift_indirect_result`` attribute marks a parameter of a ``swiftcall`` 2293*67e74705SXin Lifunction as having the special indirect-result ABI treatmenet. 2294*67e74705SXin Li 2295*67e74705SXin LiThis treatment gives the parameter the target's normal indirect-result 2296*67e74705SXin LiABI treatment, which may involve passing it differently from an ordinary 2297*67e74705SXin Liparameter. However, only the first indirect result will receive this 2298*67e74705SXin Litreatment. Furthermore, low-level lowering may decide that a direct result 2299*67e74705SXin Limust be returned indirectly; if so, this will take priority over the 2300*67e74705SXin Li``swift_indirect_result`` parameters. 2301*67e74705SXin Li 2302*67e74705SXin LiA ``swift_indirect_result`` parameter must either be the first parameter or 2303*67e74705SXin Lifollow another ``swift_indirect_result`` parameter. 2304*67e74705SXin Li 2305*67e74705SXin LiA ``swift_indirect_result`` parameter must have type ``T*`` or ``T&`` for 2306*67e74705SXin Lisome object type ``T``. If ``T`` is a complete type at the point of 2307*67e74705SXin Lidefinition of a function, it is undefined behavior if the argument 2308*67e74705SXin Livalue does not point to storage of adequate size and alignment for a 2309*67e74705SXin Livalue of type ``T``. 2310*67e74705SXin Li 2311*67e74705SXin LiMaking indirect results explicit in the signature allows C functions to 2312*67e74705SXin Lidirectly construct objects into them without relying on language 2313*67e74705SXin Lioptimizations like C++'s named return value optimization (NRVO). 2314*67e74705SXin Li }]; 2315*67e74705SXin Li} 2316*67e74705SXin Li 2317*67e74705SXin Lidef AbiTagsDocs : Documentation { 2318*67e74705SXin Li let Category = DocCatFunction; 2319*67e74705SXin Li let Content = [{ 2320*67e74705SXin LiThe ``abi_tag`` attribute can be applied to a function, variable, class or 2321*67e74705SXin Liinline namespace declaration to modify the mangled name of the entity. It gives 2322*67e74705SXin Lithe ability to distinguish between different versions of the same entity but 2323*67e74705SXin Liwith different ABI versions supported. For example, a newer version of a class 2324*67e74705SXin Licould have a different set of data members and thus have a different size. Using 2325*67e74705SXin Lithe ``abi_tag`` attribute, it is possible to have different mangled names for 2326*67e74705SXin Lia global variable of the class type. Therefor, the old code could keep using 2327*67e74705SXin Lithe old manged name and the new code will use the new mangled name with tags. 2328*67e74705SXin Li }]; 2329*67e74705SXin Li} 2330*67e74705SXin Li 2331*67e74705SXin Lidef PreserveMostDocs : Documentation { 2332*67e74705SXin Li let Category = DocCatCallingConvs; 2333*67e74705SXin Li let Content = [{ 2334*67e74705SXin LiOn X86-64 and AArch64 targets, this attribute changes the calling convention of 2335*67e74705SXin Lia function. The ``preserve_most`` calling convention attempts to make the code 2336*67e74705SXin Liin the caller as unintrusive as possible. This convention behaves identically 2337*67e74705SXin Lito the ``C`` calling convention on how arguments and return values are passed, 2338*67e74705SXin Libut it uses a different set of caller/callee-saved registers. This alleviates 2339*67e74705SXin Lithe burden of saving and recovering a large register set before and after the 2340*67e74705SXin Licall in the caller. If the arguments are passed in callee-saved registers, 2341*67e74705SXin Lithen they will be preserved by the callee across the call. This doesn't 2342*67e74705SXin Liapply for values returned in callee-saved registers. 2343*67e74705SXin Li 2344*67e74705SXin Li- On X86-64 the callee preserves all general purpose registers, except for 2345*67e74705SXin Li R11. R11 can be used as a scratch register. Floating-point registers 2346*67e74705SXin Li (XMMs/YMMs) are not preserved and need to be saved by the caller. 2347*67e74705SXin Li 2348*67e74705SXin LiThe idea behind this convention is to support calls to runtime functions 2349*67e74705SXin Lithat have a hot path and a cold path. The hot path is usually a small piece 2350*67e74705SXin Liof code that doesn't use many registers. The cold path might need to call out to 2351*67e74705SXin Lianother function and therefore only needs to preserve the caller-saved 2352*67e74705SXin Liregisters, which haven't already been saved by the caller. The 2353*67e74705SXin Li`preserve_most` calling convention is very similar to the ``cold`` calling 2354*67e74705SXin Liconvention in terms of caller/callee-saved registers, but they are used for 2355*67e74705SXin Lidifferent types of function calls. ``coldcc`` is for function calls that are 2356*67e74705SXin Lirarely executed, whereas `preserve_most` function calls are intended to be 2357*67e74705SXin Lion the hot path and definitely executed a lot. Furthermore ``preserve_most`` 2358*67e74705SXin Lidoesn't prevent the inliner from inlining the function call. 2359*67e74705SXin Li 2360*67e74705SXin LiThis calling convention will be used by a future version of the Objective-C 2361*67e74705SXin Liruntime and should therefore still be considered experimental at this time. 2362*67e74705SXin LiAlthough this convention was created to optimize certain runtime calls to 2363*67e74705SXin Lithe Objective-C runtime, it is not limited to this runtime and might be used 2364*67e74705SXin Liby other runtimes in the future too. The current implementation only 2365*67e74705SXin Lisupports X86-64 and AArch64, but the intention is to support more architectures 2366*67e74705SXin Liin the future. 2367*67e74705SXin Li }]; 2368*67e74705SXin Li} 2369*67e74705SXin Li 2370*67e74705SXin Lidef PreserveAllDocs : Documentation { 2371*67e74705SXin Li let Category = DocCatCallingConvs; 2372*67e74705SXin Li let Content = [{ 2373*67e74705SXin LiOn X86-64 and AArch64 targets, this attribute changes the calling convention of 2374*67e74705SXin Lia function. The ``preserve_all`` calling convention attempts to make the code 2375*67e74705SXin Liin the caller even less intrusive than the ``preserve_most`` calling convention. 2376*67e74705SXin LiThis calling convention also behaves identical to the ``C`` calling convention 2377*67e74705SXin Lion how arguments and return values are passed, but it uses a different set of 2378*67e74705SXin Licaller/callee-saved registers. This removes the burden of saving and 2379*67e74705SXin Lirecovering a large register set before and after the call in the caller. If 2380*67e74705SXin Lithe arguments are passed in callee-saved registers, then they will be 2381*67e74705SXin Lipreserved by the callee across the call. This doesn't apply for values 2382*67e74705SXin Lireturned in callee-saved registers. 2383*67e74705SXin Li 2384*67e74705SXin Li- On X86-64 the callee preserves all general purpose registers, except for 2385*67e74705SXin Li R11. R11 can be used as a scratch register. Furthermore it also preserves 2386*67e74705SXin Li all floating-point registers (XMMs/YMMs). 2387*67e74705SXin Li 2388*67e74705SXin LiThe idea behind this convention is to support calls to runtime functions 2389*67e74705SXin Lithat don't need to call out to any other functions. 2390*67e74705SXin Li 2391*67e74705SXin LiThis calling convention, like the ``preserve_most`` calling convention, will be 2392*67e74705SXin Liused by a future version of the Objective-C runtime and should be considered 2393*67e74705SXin Liexperimental at this time. 2394*67e74705SXin Li }]; 2395*67e74705SXin Li} 2396*67e74705SXin Li 2397*67e74705SXin Lidef DeprecatedDocs : Documentation { 2398*67e74705SXin Li let Category = DocCatFunction; 2399*67e74705SXin Li let Content = [{ 2400*67e74705SXin LiThe ``deprecated`` attribute can be applied to a function, a variable, or a 2401*67e74705SXin Litype. This is useful when identifying functions, variables, or types that are 2402*67e74705SXin Liexpected to be removed in a future version of a program. 2403*67e74705SXin Li 2404*67e74705SXin LiConsider the function declaration for a hypothetical function ``f``: 2405*67e74705SXin Li 2406*67e74705SXin Li.. code-block:: c++ 2407*67e74705SXin Li 2408*67e74705SXin Li void f(void) __attribute__((deprecated("message", "replacement"))); 2409*67e74705SXin Li 2410*67e74705SXin LiWhen spelled as `__attribute__((deprecated))`, the deprecated attribute can have 2411*67e74705SXin Litwo optional string arguments. The first one is the message to display when 2412*67e74705SXin Liemitting the warning; the second one enables the compiler to provide a Fix-It 2413*67e74705SXin Lito replace the deprecated name with a new name. Otherwise, when spelled as 2414*67e74705SXin Li`[[gnu::deprecated]] or [[deprecated]]`, the attribute can have one optional 2415*67e74705SXin Listring argument which is the message to display when emitting the warning. 2416*67e74705SXin Li }]; 2417*67e74705SXin Li} 2418*67e74705SXin Li 2419*67e74705SXin Lidef IFuncDocs : Documentation { 2420*67e74705SXin Li let Category = DocCatFunction; 2421*67e74705SXin Li let Content = [{ 2422*67e74705SXin Li``__attribute__((ifunc("resolver")))`` is used to mark that the address of a declaration should be resolved at runtime by calling a resolver function. 2423*67e74705SXin Li 2424*67e74705SXin LiThe symbol name of the resolver function is given in quotes. A function with this name (after mangling) must be defined in the current translation unit; it may be ``static``. The resolver function should take no arguments and return a pointer. 2425*67e74705SXin Li 2426*67e74705SXin LiThe ``ifunc`` attribute may only be used on a function declaration. A function declaration with an ``ifunc`` attribute is considered to be a definition of the declared entity. The entity must not have weak linkage; for example, in C++, it cannot be applied to a declaration if a definition at that location would be considered inline. 2427*67e74705SXin Li 2428*67e74705SXin LiNot all targets support this attribute. ELF targets support this attribute when using binutils v2.20.1 or higher and glibc v2.11.1 or higher. Non-ELF targets currently do not support this attribute. 2429*67e74705SXin Li }]; 2430*67e74705SXin Li} 2431*67e74705SXin Li 2432*67e74705SXin Lidef LTOVisibilityDocs : Documentation { 2433*67e74705SXin Li let Category = DocCatType; 2434*67e74705SXin Li let Content = [{ 2435*67e74705SXin LiSee :doc:`LTOVisibility`. 2436*67e74705SXin Li }]; 2437*67e74705SXin Li} 2438*67e74705SXin Li 2439*67e74705SXin Lidef RenderScriptKernelAttributeDocs : Documentation { 2440*67e74705SXin Li let Category = DocCatFunction; 2441*67e74705SXin Li let Content = [{ 2442*67e74705SXin Li``__attribute__((kernel))`` is used to mark a ``kernel`` function in 2443*67e74705SXin LiRenderScript. 2444*67e74705SXin Li 2445*67e74705SXin LiIn RenderScript, ``kernel`` functions are used to express data-parallel 2446*67e74705SXin Licomputations. The RenderScript runtime efficiently parallelizes ``kernel`` 2447*67e74705SXin Lifunctions to run on computational resources such as multi-core CPUs and GPUs. 2448*67e74705SXin LiSee the RenderScript_ documentation for more information. 2449*67e74705SXin Li 2450*67e74705SXin Li.. _RenderScript: https://developer.android.com/guide/topics/renderscript/compute.html 2451*67e74705SXin Li }]; 2452*67e74705SXin Li} 2453*67e74705SXin Li 2454*67e74705SXin Lidef XRayDocs : Documentation { 2455*67e74705SXin Li let Category = DocCatFunction; 2456*67e74705SXin Li let Heading = "xray_always_instrument (clang::xray_always_instrument), xray_never_instrument (clang::xray_never_instrument)"; 2457*67e74705SXin Li let Content = [{ 2458*67e74705SXin Li``__attribute__((xray_always_instrument))`` or ``[[clang::xray_always_instrument]]`` is used to mark member functions (in C++), methods (in Objective C), and free functions (in C, C++, and Objective C) to be instrumented with XRay. This will cause the function to always have space at the beginning and exit points to allow for runtime patching. 2459*67e74705SXin Li 2460*67e74705SXin LiConversely, ``__attribute__((xray_never_instrument))`` or ``[[clang::xray_never_instrument]]`` will inhibit the insertion of these instrumentation points. 2461*67e74705SXin Li 2462*67e74705SXin LiIf a function has neither of these attributes, they become subject to the XRay heuristics used to determine whether a function should be instrumented or otherwise. 2463*67e74705SXin Li }]; 2464*67e74705SXin Li} 2465