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