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