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