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