1//==--- AttrDocs.td - Attribute documentation ----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9// To test that the documentation builds cleanly, you must run clang-tblgen to
10// convert the .td file into a .rst file, and then run sphinx to convert the
11// .rst file into an HTML file. After completing testing, you should revert the
12// generated .rst file so that the modified version does not get checked in to
13// version control.
14//
15// To run clang-tblgen to generate the .rst file:
16// clang-tblgen -gen-attr-docs -I <root>/llvm/tools/clang/include
17//   <root>/llvm/tools/clang/include/clang/Basic/Attr.td -o
18//   <root>/llvm/tools/clang/docs/AttributeReference.rst
19//
20// To run sphinx to generate the .html files (note that sphinx-build must be
21// available on the PATH):
22// Windows (from within the clang\docs directory):
23//   make.bat html
24// Non-Windows (from within the clang\docs directory):
25//   make -f Makefile.sphinx html
26
27def GlobalDocumentation {
28  code Intro =[{..
29  -------------------------------------------------------------------
30  NOTE: This file is automatically generated by running clang-tblgen
31  -gen-attr-docs. Do not edit this file by hand!!
32  -------------------------------------------------------------------
33
34===================
35Attributes in Clang
36===================
37.. contents::
38   :local:
39
40.. |br| raw:: html
41
42  <br/>
43
44Introduction
45============
46
47This page lists the attributes currently supported by Clang.
48}];
49}
50
51def SectionDocs : Documentation {
52  let Category = DocCatVariable;
53  let Content = [{
54The ``section`` attribute allows you to specify a specific section a
55global variable or function should be in after translation.
56  }];
57  let Heading = "section, __declspec(allocate)";
58}
59
60def InitSegDocs : Documentation {
61  let Category = DocCatVariable;
62  let Content = [{
63The attribute applied by ``pragma init_seg()`` controls the section into
64which global initialization function pointers are emitted.  It is only
65available with ``-fms-extensions``.  Typically, this function pointer is
66emitted into ``.CRT$XCU`` on Windows.  The user can change the order of
67initialization by using a different section name with the same
68``.CRT$XC`` prefix and a suffix that sorts lexicographically before or
69after the standard ``.CRT$XCU`` sections.  See the init_seg_
70documentation on MSDN for more information.
71
72.. _init_seg: http://msdn.microsoft.com/en-us/library/7977wcck(v=vs.110).aspx
73  }];
74}
75
76def TLSModelDocs : Documentation {
77  let Category = DocCatVariable;
78  let Content = [{
79The ``tls_model`` attribute allows you to specify which thread-local storage
80model to use. It accepts the following strings:
81
82* global-dynamic
83* local-dynamic
84* initial-exec
85* local-exec
86
87TLS models are mutually exclusive.
88  }];
89}
90
91def DLLExportDocs : Documentation {
92  let Category = DocCatVariable;
93  let Content = [{
94The ``__declspec(dllexport)`` attribute declares a variable, function, or
95Objective-C interface to be exported from the module.  It is available under the
96``-fdeclspec`` flag for compatibility with various compilers.  The primary use
97is for COFF object files which explicitly specify what interfaces are available
98for external use.  See the dllexport_ documentation on MSDN for more
99information.
100
101.. _dllexport: https://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx
102  }];
103}
104
105def DLLImportDocs : Documentation {
106  let Category = DocCatVariable;
107  let Content = [{
108The ``__declspec(dllimport)`` attribute declares a variable, function, or
109Objective-C interface to be imported from an external module.  It is available
110under the ``-fdeclspec`` flag for compatibility with various compilers.  The
111primary use is for COFF object files which explicitly specify what interfaces
112are imported from external modules.  See the dllimport_ documentation on MSDN
113for more information.
114
115.. _dllimport: https://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx
116  }];
117}
118
119def ThreadDocs : Documentation {
120  let Category = DocCatVariable;
121  let Content = [{
122The ``__declspec(thread)`` attribute declares a variable with thread local
123storage.  It is available under the ``-fms-extensions`` flag for MSVC
124compatibility.  See the documentation for `__declspec(thread)`_ on MSDN.
125
126.. _`__declspec(thread)`: http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx
127
128In Clang, ``__declspec(thread)`` is generally equivalent in functionality to the
129GNU ``__thread`` keyword.  The variable must not have a destructor and must have
130a constant initializer, if any.  The attribute only applies to variables
131declared with static storage duration, such as globals, class static data
132members, and static locals.
133  }];
134}
135
136def NoEscapeDocs : Documentation {
137  let Category = DocCatVariable;
138  let Content = [{
139``noescape`` placed on a function parameter of a pointer type is used to inform
140the compiler that the pointer cannot escape: that is, no reference to the object
141the pointer points to that is derived from the parameter value will survive
142after the function returns. Users are responsible for making sure parameters
143annotated with ``noescape`` do not actually escape. Calling ``free()`` on such
144a parameter does not constitute an escape.
145
146For 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
160Additionally, when the parameter is a `block pointer
161<https://clang.llvm.org/docs/BlockLanguageSpec.html>`, the same restriction
162applies 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
181def CarriesDependencyDocs : Documentation {
182  let Category = DocCatFunction;
183  let Content = [{
184The ``carries_dependency`` attribute specifies dependency propagation into and
185out of functions.
186
187When specified on a function or Objective-C method, the ``carries_dependency``
188attribute means that the return value carries a dependency out of the function,
189so that the implementation need not constrain ordering upon return from that
190function. Implementations of the function and its caller may choose to preserve
191dependencies instead of emitting memory ordering instructions such as fences.
192
193Note, this attribute does not change the meaning of the program, but may result
194in generation of more efficient code.
195  }];
196}
197
198def CPUSpecificCPUDispatchDocs : Documentation {
199  let Category = DocCatFunction;
200  let Content = [{
201The ``cpu_specific`` and ``cpu_dispatch`` attributes are used to define and
202resolve multiversioned functions. This form of multiversioning provides a
203mechanism for declaring versions across translation units and manually
204specifying the resolved function list. A specified CPU defines a set of minimum
205features that are required for the function to be called. The result of this is
206that future processors execute the most restrictive version of the function the
207new processor can execute.
208
209Function versions are defined with ``cpu_specific``, which takes one or more CPU
210names 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
226A dispatching (or resolving) function can be declared anywhere in a project's
227source code with ``cpu_dispatch``. This attribute takes one or more CPU names
228as a parameter (like ``cpu_specific``). Functions marked with ``cpu_dispatch``
229are not expected to be defined, only declared. If such a marked function has a
230definition, any side effects of the function are ignored; trivial function
231bodies 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
244Note that it is possible to have a resolving function that dispatches based on
245more or fewer options than are present in the program. Specifying fewer will
246result in the omitted options not being considered during resolution. Specifying
247a version for resolution that isn't defined in the program will result in a
248linking failure.
249
250It is also possible to specify a CPU name of ``generic`` which will be resolved
251if the executing processor doesn't satisfy the features required in the CPU
252name. The behavior of a program executing on a processor that doesn't satisfy
253any option of a multiversioned function is undefined.
254  }];
255}
256
257def SYCLKernelDocs : Documentation {
258  let Category = DocCatFunction;
259  let Content = [{
260The ``sycl_kernel`` attribute specifies that a function template will be used
261to outline device code and to generate an OpenCL kernel.
262Here is a code example of the SYCL program, which demonstrates the compiler's
263outlining job:
264
265.. code-block:: c++
266
267  int foo(int x) { return ++x; }
268
269  using namespace cl::sycl;
270  queue Q;
271  buffer<int, 1> a(range<1>{1024});
272  Q.submit([&](handler& cgh) {
273    auto A = a.get_access<access::mode::write>(cgh);
274    cgh.parallel_for<init_a>(range<1>{1024}, [=](id<1> index) {
275      A[index] = index[0] + foo(42);
276    });
277  }
278
279A C++ function object passed to the ``parallel_for`` is called a "SYCL kernel".
280A SYCL kernel defines the entry point to the "device part" of the code. The
281compiler will emit all symbols accessible from a "kernel". In this code
282example, the compiler will emit "foo" function.  More details about the
283compilation of functions for the device part can be found in the SYCL 1.2.1
284specification Section 6.4.
285To show to the compiler entry point to the "device part" of the code, the SYCL
286runtime can use the ``sycl_kernel`` attribute in the following way:
287
288.. code-block:: c++
289
290  namespace cl {
291  namespace sycl {
292  class handler {
293    template <typename KernelName, typename KernelType/*, ...*/>
294    __attribute__((sycl_kernel)) void sycl_kernel_function(KernelType KernelFuncObj) {
295      // ...
296      KernelFuncObj();
297    }
298
299    template <typename KernelName, typename KernelType, int Dims>
300    void parallel_for(range<Dims> NumWorkItems, KernelType KernelFunc) {
301  #ifdef __SYCL_DEVICE_ONLY__
302      sycl_kernel_function<KernelName, KernelType, Dims>(KernelFunc);
303  #else
304      // Host implementation
305  #endif
306    }
307  };
308  } // namespace sycl
309  } // namespace cl
310
311The compiler will also generate an OpenCL kernel using the function marked with
312the ``sycl_kernel`` attribute.
313Here is the list of SYCL device compiler expectations with regard to the
314function marked with the ``sycl_kernel`` attribute:
315
316- The function must be a template with at least two type template parameters.
317  The compiler generates an OpenCL kernel and uses the first template parameter
318  as a unique name for the generated OpenCL kernel. The host application uses
319  this unique name to invoke the OpenCL kernel generated for the SYCL kernel
320  specialized by this name and second template parameter ``KernelType`` (which
321  might be an unnamed function object type).
322- The function must have at least one parameter. The first parameter is
323  required to be a function object type (named or unnamed i.e. lambda). The
324  compiler uses function object type fields to generate OpenCL kernel
325  parameters.
326- The function must return void. The compiler reuses the body of marked functions to
327  generate the OpenCL kernel body, and the OpenCL kernel must return ``void``.
328
329The SYCL kernel in the previous code sample meets these expectations.
330  }];
331}
332
333def C11NoReturnDocs : Documentation {
334  let Category = DocCatFunction;
335  let Content = [{
336A function declared as ``_Noreturn`` shall not return to its caller. The
337compiler will generate a diagnostic for a function declared as ``_Noreturn``
338that appears to be capable of returning to its caller. Despite being a type
339specifier, the ``_Noreturn`` attribute cannot be specified on a function
340pointer type.
341  }];
342}
343
344def CXX11NoReturnDocs : Documentation {
345  let Category = DocCatFunction;
346  let Content = [{
347A function declared as ``[[noreturn]]`` shall not return to its caller. The
348compiler will generate a diagnostic for a function declared as ``[[noreturn]]``
349that appears to be capable of returning to its caller.
350  }];
351}
352
353def NoMergeDocs : Documentation {
354  let Category = DocCatFunction;
355  let Content = [{
356If a statement is marked ``nomerge`` and contains call experessions, those call
357expressions inside the statement will not be merged during optimization. This
358attribute can be used to prevent the optimizer from obscuring the source
359location of certain calls. For example, it will prevent tail merging otherwise
360identical code sequences that raise an exception or terminate the program. Tail
361merging normally reduces the precision of source location information, making
362stack traces less useful for debugging. This attribute gives the user control
363over the tradeoff between code size and debug information precision.
364  }];
365}
366
367def AssertCapabilityDocs : Documentation {
368  let Category = DocCatFunction;
369  let Heading = "assert_capability, assert_shared_capability";
370  let Content = [{
371Marks a function that dynamically tests whether a capability is held, and halts
372the program if it is not held.
373  }];
374}
375
376def AcquireCapabilityDocs : Documentation {
377  let Category = DocCatFunction;
378  let Heading = "acquire_capability, acquire_shared_capability";
379  let Content = [{
380Marks a function as acquiring a capability.
381  }];
382}
383
384def TryAcquireCapabilityDocs : Documentation {
385  let Category = DocCatFunction;
386  let Heading = "try_acquire_capability, try_acquire_shared_capability";
387  let Content = [{
388Marks a function that attempts to acquire a capability. This function may fail to
389actually acquire the capability; they accept a Boolean value determining
390whether acquiring the capability means success (true), or failing to acquire
391the capability means success (false).
392  }];
393}
394
395def ReleaseCapabilityDocs : Documentation {
396  let Category = DocCatFunction;
397  let Heading = "release_capability, release_shared_capability";
398  let Content = [{
399Marks a function as releasing a capability.
400  }];
401}
402
403def AssumeAlignedDocs : Documentation {
404  let Category = DocCatFunction;
405  let Content = [{
406Use ``__attribute__((assume_aligned(<alignment>[,<offset>]))`` on a function
407declaration to specify that the return value of the function (which must be a
408pointer type) has the specified offset, in bytes, from an address with the
409specified alignment. The offset is taken to be zero if omitted.
410
411.. code-block:: c++
412
413  // The returned pointer value has 32-byte alignment.
414  void *a() __attribute__((assume_aligned (32)));
415
416  // The returned pointer value is 4 bytes greater than an address having
417  // 32-byte alignment.
418  void *b() __attribute__((assume_aligned (32, 4)));
419
420Note that this attribute provides information to the compiler regarding a
421condition that the code already ensures is true. It does not cause the compiler
422to enforce the provided alignment assumption.
423  }];
424}
425
426def AllocSizeDocs : Documentation {
427  let Category = DocCatFunction;
428  let Content = [{
429The ``alloc_size`` attribute can be placed on functions that return pointers in
430order to hint to the compiler how many bytes of memory will be available at the
431returned pointer. ``alloc_size`` takes one or two arguments.
432
433- ``alloc_size(N)`` implies that argument number N equals the number of
434  available bytes at the returned pointer.
435- ``alloc_size(N, M)`` implies that the product of argument number N and
436  argument number M equals the number of available bytes at the returned
437  pointer.
438
439Argument numbers are 1-based.
440
441An example of how to use ``alloc_size``
442
443.. code-block:: c
444
445  void *my_malloc(int a) __attribute__((alloc_size(1)));
446  void *my_calloc(int a, int b) __attribute__((alloc_size(1, 2)));
447
448  int main() {
449    void *const p = my_malloc(100);
450    assert(__builtin_object_size(p, 0) == 100);
451    void *const a = my_calloc(20, 5);
452    assert(__builtin_object_size(a, 0) == 100);
453  }
454
455.. Note:: This attribute works differently in clang than it does in GCC.
456  Specifically, clang will only trace ``const`` pointers (as above); we give up
457  on pointers that are not marked as ``const``. In the vast majority of cases,
458  this is unimportant, because LLVM has support for the ``alloc_size``
459  attribute. However, this may cause mildly unintuitive behavior when used with
460  other attributes, such as ``enable_if``.
461  }];
462}
463
464def CodeSegDocs : Documentation {
465  let Category = DocCatFunction;
466  let Content = [{
467The ``__declspec(code_seg)`` attribute enables the placement of code into separate
468named segments that can be paged or locked in memory individually. This attribute
469is used to control the placement of instantiated templates and compiler-generated
470code. See the documentation for `__declspec(code_seg)`_ on MSDN.
471
472.. _`__declspec(code_seg)`: http://msdn.microsoft.com/en-us/library/dn636922.aspx
473  }];
474}
475
476def AllocAlignDocs : Documentation {
477  let Category = DocCatFunction;
478  let Content = [{
479Use ``__attribute__((alloc_align(<alignment>))`` on a function
480declaration to specify that the return value of the function (which must be a
481pointer type) is at least as aligned as the value of the indicated parameter. The
482parameter is given by its index in the list of formal parameters; the first
483parameter has index 1 unless the function is a C++ non-static member function,
484in which case the first parameter has index 2 to account for the implicit ``this``
485parameter.
486
487.. code-block:: c++
488
489  // The returned pointer has the alignment specified by the first parameter.
490  void *a(size_t align) __attribute__((alloc_align(1)));
491
492  // The returned pointer has the alignment specified by the second parameter.
493  void *b(void *v, size_t align) __attribute__((alloc_align(2)));
494
495  // The returned pointer has the alignment specified by the second visible
496  // parameter, however it must be adjusted for the implicit 'this' parameter.
497  void *Foo::b(void *v, size_t align) __attribute__((alloc_align(3)));
498
499Note that this attribute merely informs the compiler that a function always
500returns a sufficiently aligned pointer. It does not cause the compiler to
501emit code to enforce that alignment.  The behavior is undefined if the returned
502pointer is not sufficiently aligned.
503  }];
504}
505
506def EnableIfDocs : Documentation {
507  let Category = DocCatFunction;
508  let Content = [{
509.. Note:: Some features of this attribute are experimental. The meaning of
510  multiple enable_if attributes on a single declaration is subject to change in
511  a future version of clang. Also, the ABI is not standardized and the name
512  mangling may change in future versions. To avoid that, use asm labels.
513
514The ``enable_if`` attribute can be placed on function declarations to control
515which overload is selected based on the values of the function's arguments.
516When combined with the ``overloadable`` attribute, this feature is also
517available in C.
518
519.. code-block:: c++
520
521  int isdigit(int c);
522  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")));
523
524  void foo(char c) {
525    isdigit(c);
526    isdigit(10);
527    isdigit(-10);  // results in a compile-time error.
528  }
529
530The enable_if attribute takes two arguments, the first is an expression written
531in terms of the function parameters, the second is a string explaining why this
532overload candidate could not be selected to be displayed in diagnostics. The
533expression is part of the function signature for the purposes of determining
534whether it is a redeclaration (following the rules used when determining
535whether a C++ template specialization is ODR-equivalent), but is not part of
536the type.
537
538The enable_if expression is evaluated as if it were the body of a
539bool-returning constexpr function declared with the arguments of the function
540it is being applied to, then called with the parameters at the call site. If the
541result is false or could not be determined through constant expression
542evaluation, then this overload will not be chosen and the provided string may
543be used in a diagnostic if the compile fails as a result.
544
545Because the enable_if expression is an unevaluated context, there are no global
546state changes, nor the ability to pass information from the enable_if
547expression to the function body. For example, suppose we want calls to
548strnlen(strbuf, maxlen) to resolve to strnlen_chk(strbuf, maxlen, size of
549strbuf) only if the size of strbuf can be determined:
550
551.. code-block:: c++
552
553  __attribute__((always_inline))
554  static inline size_t strnlen(const char *s, size_t maxlen)
555    __attribute__((overloadable))
556    __attribute__((enable_if(__builtin_object_size(s, 0) != -1))),
557                             "chosen when the buffer size is known but 'maxlen' is not")))
558  {
559    return strnlen_chk(s, maxlen, __builtin_object_size(s, 0));
560  }
561
562Multiple enable_if attributes may be applied to a single declaration. In this
563case, the enable_if expressions are evaluated from left to right in the
564following manner. First, the candidates whose enable_if expressions evaluate to
565false or cannot be evaluated are discarded. If the remaining candidates do not
566share ODR-equivalent enable_if expressions, the overload resolution is
567ambiguous. Otherwise, enable_if overload resolution continues with the next
568enable_if attribute on the candidates that have not been discarded and have
569remaining enable_if attributes. In this way, we pick the most specific
570overload out of a number of viable overloads using enable_if.
571
572.. code-block:: c++
573
574  void f() __attribute__((enable_if(true, "")));  // #1
575  void f() __attribute__((enable_if(true, ""))) __attribute__((enable_if(true, "")));  // #2
576
577  void g(int i, int j) __attribute__((enable_if(i, "")));  // #1
578  void g(int i, int j) __attribute__((enable_if(j, ""))) __attribute__((enable_if(true)));  // #2
579
580In this example, a call to f() is always resolved to #2, as the first enable_if
581expression is ODR-equivalent for both declarations, but #1 does not have another
582enable_if expression to continue evaluating, so the next round of evaluation has
583only a single candidate. In a call to g(1, 1), the call is ambiguous even though
584#2 has more enable_if attributes, because the first enable_if expressions are
585not ODR-equivalent.
586
587Query for this feature with ``__has_attribute(enable_if)``.
588
589Note that functions with one or more ``enable_if`` attributes may not have
590their address taken, unless all of the conditions specified by said
591``enable_if`` are constants that evaluate to ``true``. For example:
592
593.. code-block:: c
594
595  const int TrueConstant = 1;
596  const int FalseConstant = 0;
597  int f(int a) __attribute__((enable_if(a > 0, "")));
598  int g(int a) __attribute__((enable_if(a == 0 || a != 0, "")));
599  int h(int a) __attribute__((enable_if(1, "")));
600  int i(int a) __attribute__((enable_if(TrueConstant, "")));
601  int j(int a) __attribute__((enable_if(FalseConstant, "")));
602
603  void fn() {
604    int (*ptr)(int);
605    ptr = &f; // error: 'a > 0' is not always true
606    ptr = &g; // error: 'a == 0 || a != 0' is not a truthy constant
607    ptr = &h; // OK: 1 is a truthy constant
608    ptr = &i; // OK: 'TrueConstant' is a truthy constant
609    ptr = &j; // error: 'FalseConstant' is a constant, but not truthy
610  }
611
612Because ``enable_if`` evaluation happens during overload resolution,
613``enable_if`` may give unintuitive results when used with templates, depending
614on when overloads are resolved. In the example below, clang will emit a
615diagnostic about no viable overloads for ``foo`` in ``bar``, but not in ``baz``:
616
617.. code-block:: c++
618
619  double foo(int i) __attribute__((enable_if(i > 0, "")));
620  void *foo(int i) __attribute__((enable_if(i <= 0, "")));
621  template <int I>
622  auto bar() { return foo(I); }
623
624  template <typename T>
625  auto baz() { return foo(T::number); }
626
627  struct WithNumber { constexpr static int number = 1; };
628  void callThem() {
629    bar<sizeof(WithNumber)>();
630    baz<WithNumber>();
631  }
632
633This is because, in ``bar``, ``foo`` is resolved prior to template
634instantiation, so the value for ``I`` isn't known (thus, both ``enable_if``
635conditions for ``foo`` fail). However, in ``baz``, ``foo`` is resolved during
636template instantiation, so the value for ``T::number`` is known.
637  }];
638}
639
640def DiagnoseIfDocs : Documentation {
641  let Category = DocCatFunction;
642  let Content = [{
643The ``diagnose_if`` attribute can be placed on function declarations to emit
644warnings or errors at compile-time if calls to the attributed function meet
645certain user-defined criteria. For example:
646
647.. code-block:: c
648
649  int abs(int a)
650    __attribute__((diagnose_if(a >= 0, "Redundant abs call", "warning")));
651  int must_abs(int a)
652    __attribute__((diagnose_if(a >= 0, "Redundant abs call", "error")));
653
654  int val = abs(1); // warning: Redundant abs call
655  int val2 = must_abs(1); // error: Redundant abs call
656  int val3 = abs(val);
657  int val4 = must_abs(val); // Because run-time checks are not emitted for
658                            // diagnose_if attributes, this executes without
659                            // issue.
660
661
662``diagnose_if`` is closely related to ``enable_if``, with a few key differences:
663
664* Overload resolution is not aware of ``diagnose_if`` attributes: they're
665  considered only after we select the best candidate from a given candidate set.
666* Function declarations that differ only in their ``diagnose_if`` attributes are
667  considered to be redeclarations of the same function (not overloads).
668* If the condition provided to ``diagnose_if`` cannot be evaluated, no
669  diagnostic will be emitted.
670
671Otherwise, ``diagnose_if`` is essentially the logical negation of ``enable_if``.
672
673As a result of bullet number two, ``diagnose_if`` attributes will stack on the
674same function. For example:
675
676.. code-block:: c
677
678  int foo() __attribute__((diagnose_if(1, "diag1", "warning")));
679  int foo() __attribute__((diagnose_if(1, "diag2", "warning")));
680
681  int bar = foo(); // warning: diag1
682                   // warning: diag2
683  int (*fooptr)(void) = foo; // warning: diag1
684                             // warning: diag2
685
686  constexpr int supportsAPILevel(int N) { return N < 5; }
687  int baz(int a)
688    __attribute__((diagnose_if(!supportsAPILevel(10),
689                               "Upgrade to API level 10 to use baz", "error")));
690  int baz(int a)
691    __attribute__((diagnose_if(!a, "0 is not recommended.", "warning")));
692
693  int (*bazptr)(int) = baz; // error: Upgrade to API level 10 to use baz
694  int v = baz(0); // error: Upgrade to API level 10 to use baz
695
696Query for this feature with ``__has_attribute(diagnose_if)``.
697  }];
698}
699
700def PassObjectSizeDocs : Documentation {
701  let Category = DocCatVariable; // Technically it's a parameter doc, but eh.
702  let Heading = "pass_object_size, pass_dynamic_object_size";
703  let Content = [{
704.. Note:: The mangling of functions with parameters that are annotated with
705  ``pass_object_size`` is subject to change. You can get around this by
706  using ``__asm__("foo")`` to explicitly name your functions, thus preserving
707  your ABI; also, non-overloadable C functions with ``pass_object_size`` are
708  not mangled.
709
710The ``pass_object_size(Type)`` attribute can be placed on function parameters to
711instruct clang to call ``__builtin_object_size(param, Type)`` at each callsite
712of said function, and implicitly pass the result of this call in as an invisible
713argument of type ``size_t`` directly after the parameter annotated with
714``pass_object_size``. Clang will also replace any calls to
715``__builtin_object_size(param, Type)`` in the function by said implicit
716parameter.
717
718Example usage:
719
720.. code-block:: c
721
722  int bzero1(char *const p __attribute__((pass_object_size(0))))
723      __attribute__((noinline)) {
724    int i = 0;
725    for (/**/; i < (int)__builtin_object_size(p, 0); ++i) {
726      p[i] = 0;
727    }
728    return i;
729  }
730
731  int main() {
732    char chars[100];
733    int n = bzero1(&chars[0]);
734    assert(n == sizeof(chars));
735    return 0;
736  }
737
738If successfully evaluating ``__builtin_object_size(param, Type)`` at the
739callsite is not possible, then the "failed" value is passed in. So, using the
740definition of ``bzero1`` from above, the following code would exit cleanly:
741
742.. code-block:: c
743
744  int main2(int argc, char *argv[]) {
745    int n = bzero1(argv);
746    assert(n == -1);
747    return 0;
748  }
749
750``pass_object_size`` plays a part in overload resolution. If two overload
751candidates are otherwise equally good, then the overload with one or more
752parameters with ``pass_object_size`` is preferred. This implies that the choice
753between two identical overloads both with ``pass_object_size`` on one or more
754parameters will always be ambiguous; for this reason, having two such overloads
755is illegal. For example:
756
757.. code-block:: c++
758
759  #define PS(N) __attribute__((pass_object_size(N)))
760  // OK
761  void Foo(char *a, char *b); // Overload A
762  // OK -- overload A has no parameters with pass_object_size.
763  void Foo(char *a PS(0), char *b PS(0)); // Overload B
764  // Error -- Same signature (sans pass_object_size) as overload B, and both
765  // overloads have one or more parameters with the pass_object_size attribute.
766  void Foo(void *a PS(0), void *b);
767
768  // OK
769  void Bar(void *a PS(0)); // Overload C
770  // OK
771  void Bar(char *c PS(1)); // Overload D
772
773  void main() {
774    char known[10], *unknown;
775    Foo(unknown, unknown); // Calls overload B
776    Foo(known, unknown); // Calls overload B
777    Foo(unknown, known); // Calls overload B
778    Foo(known, known); // Calls overload B
779
780    Bar(known); // Calls overload D
781    Bar(unknown); // Calls overload D
782  }
783
784Currently, ``pass_object_size`` is a bit restricted in terms of its usage:
785
786* Only one use of ``pass_object_size`` is allowed per parameter.
787
788* It is an error to take the address of a function with ``pass_object_size`` on
789  any of its parameters. If you wish to do this, you can create an overload
790  without ``pass_object_size`` on any parameters.
791
792* It is an error to apply the ``pass_object_size`` attribute to parameters that
793  are not pointers. Additionally, any parameter that ``pass_object_size`` is
794  applied to must be marked ``const`` at its function's definition.
795
796Clang also supports the ``pass_dynamic_object_size`` attribute, which behaves
797identically to ``pass_object_size``, but evaluates a call to
798``__builtin_dynamic_object_size`` at the callee instead of
799``__builtin_object_size``. ``__builtin_dynamic_object_size`` provides some extra
800runtime checks when the object size can't be determined at compile-time. You can
801read more about ``__builtin_dynamic_object_size`` `here
802<https://clang.llvm.org/docs/LanguageExtensions.html#evaluating-object-size-dynamically>`_.
803
804  }];
805}
806
807def OverloadableDocs : Documentation {
808  let Category = DocCatFunction;
809  let Content = [{
810Clang provides support for C++ function overloading in C.  Function overloading
811in C is introduced using the ``overloadable`` attribute.  For example, one
812might provide several overloaded versions of a ``tgsin`` function that invokes
813the appropriate standard function computing the sine of a value with ``float``,
814``double``, or ``long double`` precision:
815
816.. code-block:: c
817
818  #include <math.h>
819  float __attribute__((overloadable)) tgsin(float x) { return sinf(x); }
820  double __attribute__((overloadable)) tgsin(double x) { return sin(x); }
821  long double __attribute__((overloadable)) tgsin(long double x) { return sinl(x); }
822
823Given these declarations, one can call ``tgsin`` with a ``float`` value to
824receive a ``float`` result, with a ``double`` to receive a ``double`` result,
825etc.  Function overloading in C follows the rules of C++ function overloading
826to pick the best overload given the call arguments, with a few C-specific
827semantics:
828
829* Conversion from ``float`` or ``double`` to ``long double`` is ranked as a
830  floating-point promotion (per C99) rather than as a floating-point conversion
831  (as in C++).
832
833* A conversion from a pointer of type ``T*`` to a pointer of type ``U*`` is
834  considered a pointer conversion (with conversion rank) if ``T`` and ``U`` are
835  compatible types.
836
837* A conversion from type ``T`` to a value of type ``U`` is permitted if ``T``
838  and ``U`` are compatible types.  This conversion is given "conversion" rank.
839
840* If no viable candidates are otherwise available, we allow a conversion from a
841  pointer of type ``T*`` to a pointer of type ``U*``, where ``T`` and ``U`` are
842  incompatible. This conversion is ranked below all other types of conversions.
843  Please note: ``U`` lacking qualifiers that are present on ``T`` is sufficient
844  for ``T`` and ``U`` to be incompatible.
845
846The declaration of ``overloadable`` functions is restricted to function
847declarations and definitions.  If a function is marked with the ``overloadable``
848attribute, then all declarations and definitions of functions with that name,
849except for at most one (see the note below about unmarked overloads), must have
850the ``overloadable`` attribute.  In addition, redeclarations of a function with
851the ``overloadable`` attribute must have the ``overloadable`` attribute, and
852redeclarations of a function without the ``overloadable`` attribute must *not*
853have the ``overloadable`` attribute. e.g.,
854
855.. code-block:: c
856
857  int f(int) __attribute__((overloadable));
858  float f(float); // error: declaration of "f" must have the "overloadable" attribute
859  int f(int); // error: redeclaration of "f" must have the "overloadable" attribute
860
861  int g(int) __attribute__((overloadable));
862  int g(int) { } // error: redeclaration of "g" must also have the "overloadable" attribute
863
864  int h(int);
865  int h(int) __attribute__((overloadable)); // error: declaration of "h" must not
866                                            // have the "overloadable" attribute
867
868Functions marked ``overloadable`` must have prototypes.  Therefore, the
869following code is ill-formed:
870
871.. code-block:: c
872
873  int h() __attribute__((overloadable)); // error: h does not have a prototype
874
875However, ``overloadable`` functions are allowed to use a ellipsis even if there
876are no named parameters (as is permitted in C++).  This feature is particularly
877useful when combined with the ``unavailable`` attribute:
878
879.. code-block:: c++
880
881  void honeypot(...) __attribute__((overloadable, unavailable)); // calling me is an error
882
883Functions declared with the ``overloadable`` attribute have their names mangled
884according to the same rules as C++ function names.  For example, the three
885``tgsin`` functions in our motivating example get the mangled names
886``_Z5tgsinf``, ``_Z5tgsind``, and ``_Z5tgsine``, respectively.  There are two
887caveats to this use of name mangling:
888
889* Future versions of Clang may change the name mangling of functions overloaded
890  in C, so you should not depend on an specific mangling.  To be completely
891  safe, we strongly urge the use of ``static inline`` with ``overloadable``
892  functions.
893
894* The ``overloadable`` attribute has almost no meaning when used in C++,
895  because names will already be mangled and functions are already overloadable.
896  However, when an ``overloadable`` function occurs within an ``extern "C"``
897  linkage specification, it's name *will* be mangled in the same way as it
898  would in C.
899
900For the purpose of backwards compatibility, at most one function with the same
901name as other ``overloadable`` functions may omit the ``overloadable``
902attribute. In this case, the function without the ``overloadable`` attribute
903will not have its name mangled.
904
905For example:
906
907.. code-block:: c
908
909  // Notes with mangled names assume Itanium mangling.
910  int f(int);
911  int f(double) __attribute__((overloadable));
912  void foo() {
913    f(5); // Emits a call to f (not _Z1fi, as it would with an overload that
914          // was marked with overloadable).
915    f(1.0); // Emits a call to _Z1fd.
916  }
917
918Support for unmarked overloads is not present in some versions of clang. You may
919query for it using ``__has_extension(overloadable_unmarked)``.
920
921Query for this attribute with ``__has_attribute(overloadable)``.
922  }];
923}
924
925def ObjCMethodFamilyDocs : Documentation {
926  let Category = DocCatFunction;
927  let Content = [{
928Many methods in Objective-C have conventional meanings determined by their
929selectors. It is sometimes useful to be able to mark a method as having a
930particular conventional meaning despite not having the right selector, or as
931not having the conventional meaning that its selector would suggest. For these
932use cases, we provide an attribute to specifically describe the "method family"
933that a method belongs to.
934
935**Usage**: ``__attribute__((objc_method_family(X)))``, where ``X`` is one of
936``none``, ``alloc``, ``copy``, ``init``, ``mutableCopy``, or ``new``.  This
937attribute can only be placed at the end of a method declaration:
938
939.. code-block:: objc
940
941  - (NSString *)initMyStringValue __attribute__((objc_method_family(none)));
942
943Users who do not wish to change the conventional meaning of a method, and who
944merely want to document its non-standard retain and release semantics, should
945use the retaining behavior attributes (``ns_returns_retained``,
946``ns_returns_not_retained``, etc).
947
948Query for this feature with ``__has_attribute(objc_method_family)``.
949  }];
950}
951
952def RetainBehaviorDocs : Documentation {
953  let Category = DocCatFunction;
954  let Content = [{
955The behavior of a function with respect to reference counting for Foundation
956(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming
957convention (e.g. functions starting with "get" are assumed to return at
958``+0``).
959
960It can be overridden using a family of the following attributes.  In
961Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to
962a function communicates that the object is returned at ``+1``, and the caller
963is responsible for freeing it.
964Similarly, the annotation ``__attribute__((ns_returns_not_retained))``
965specifies that the object is returned at ``+0`` and the ownership remains with
966the callee.
967The annotation ``__attribute__((ns_consumes_self))`` specifies that
968the Objective-C method call consumes the reference to ``self``, e.g. by
969attaching it to a supplied parameter.
970Additionally, parameters can have an annotation
971``__attribute__((ns_consumed))``, which specifies that passing an owned object
972as that parameter effectively transfers the ownership, and the caller is no
973longer responsible for it.
974These attributes affect code generation when interacting with ARC code, and
975they are used by the Clang Static Analyzer.
976
977In C programs using CoreFoundation, a similar set of attributes:
978``__attribute__((cf_returns_not_retained))``,
979``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))``
980have the same respective semantics when applied to CoreFoundation objects.
981These attributes affect code generation when interacting with ARC code, and
982they are used by the Clang Static Analyzer.
983
984Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject),
985the same attribute family is present:
986``__attribute__((os_returns_not_retained))``,
987``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``,
988with the same respective semantics.
989Similar to ``__attribute__((ns_consumes_self))``,
990``__attribute__((os_consumes_this))`` specifies that the method call consumes
991the reference to "this" (e.g., when attaching it to a different object supplied
992as a parameter).
993Out parameters (parameters the function is meant to write into,
994either via pointers-to-pointers or references-to-pointers)
995may be annotated with ``__attribute__((os_returns_retained))``
996or ``__attribute__((os_returns_not_retained))`` which specifies that the object
997written into the out parameter should (or respectively should not) be released
998after use.
999Since often out parameters may or may not be written depending on the exit
1000code of the function,
1001annotations ``__attribute__((os_returns_retained_on_zero))``
1002and ``__attribute__((os_returns_retained_on_non_zero))`` specify that
1003an out parameter at ``+1`` is written if and only if the function returns a zero
1004(respectively non-zero) error code.
1005Observe that return-code-dependent out parameter annotations are only
1006available for retained out parameters, as non-retained object do not have to be
1007released by the callee.
1008These attributes are only used by the Clang Static Analyzer.
1009
1010The family of attributes ``X_returns_X_retained`` can be added to functions,
1011C++ methods, and Objective-C methods and properties.
1012Attributes ``X_consumed`` can be added to parameters of methods, functions,
1013and Objective-C methods.
1014  }];
1015}
1016
1017def NoDebugDocs : Documentation {
1018  let Category = DocCatVariable;
1019  let Content = [{
1020The ``nodebug`` attribute allows you to suppress debugging information for a
1021function or method, or for a variable that is not a parameter or a non-static
1022data member.
1023  }];
1024}
1025
1026def NoDuplicateDocs : Documentation {
1027  let Category = DocCatFunction;
1028  let Content = [{
1029The ``noduplicate`` attribute can be placed on function declarations to control
1030whether function calls to this function can be duplicated or not as a result of
1031optimizations. This is required for the implementation of functions with
1032certain special requirements, like the OpenCL "barrier" function, that might
1033need to be run concurrently by all the threads that are executing in lockstep
1034on the hardware. For example this attribute applied on the function
1035"nodupfunc" in the code below avoids that:
1036
1037.. code-block:: c
1038
1039  void nodupfunc() __attribute__((noduplicate));
1040  // Setting it as a C++11 attribute is also valid
1041  // void nodupfunc() [[clang::noduplicate]];
1042  void foo();
1043  void bar();
1044
1045  nodupfunc();
1046  if (a > n) {
1047    foo();
1048  } else {
1049    bar();
1050  }
1051
1052gets possibly modified by some optimizations into code similar to this:
1053
1054.. code-block:: c
1055
1056  if (a > n) {
1057    nodupfunc();
1058    foo();
1059  } else {
1060    nodupfunc();
1061    bar();
1062  }
1063
1064where the call to "nodupfunc" is duplicated and sunk into the two branches
1065of the condition.
1066  }];
1067}
1068
1069def ConvergentDocs : Documentation {
1070  let Category = DocCatFunction;
1071  let Content = [{
1072The ``convergent`` attribute can be placed on a function declaration. It is
1073translated into the LLVM ``convergent`` attribute, which indicates that the call
1074instructions of a function with this attribute cannot be made control-dependent
1075on any additional values.
1076
1077In languages designed for SPMD/SIMT programming model, e.g. OpenCL or CUDA,
1078the call instructions of a function with this attribute must be executed by
1079all work items or threads in a work group or sub group.
1080
1081This attribute is different from ``noduplicate`` because it allows duplicating
1082function calls if it can be proved that the duplicated function calls are
1083not made control-dependent on any additional values, e.g., unrolling a loop
1084executed by all work items.
1085
1086Sample usage:
1087.. code-block:: c
1088
1089  void convfunc(void) __attribute__((convergent));
1090  // Setting it as a C++11 attribute is also valid in a C++ program.
1091  // void convfunc(void) [[clang::convergent]];
1092
1093  }];
1094}
1095
1096def NoSplitStackDocs : Documentation {
1097  let Category = DocCatFunction;
1098  let Content = [{
1099The ``no_split_stack`` attribute disables the emission of the split stack
1100preamble for a particular function. It has no effect if ``-fsplit-stack``
1101is not specified.
1102  }];
1103}
1104
1105def NoUniqueAddressDocs : Documentation {
1106  let Category = DocCatField;
1107  let Content = [{
1108The ``no_unique_address`` attribute allows tail padding in a non-static data
1109member to overlap other members of the enclosing class (and in the special
1110case when the type is empty, permits it to fully overlap other members).
1111The field is laid out as if a base class were encountered at the corresponding
1112point within the class (except that it does not share a vptr with the enclosing
1113object).
1114
1115Example usage:
1116
1117.. code-block:: c++
1118
1119  template<typename T, typename Alloc> struct my_vector {
1120    T *p;
1121    [[no_unique_address]] Alloc alloc;
1122    // ...
1123  };
1124  static_assert(sizeof(my_vector<int, std::allocator<int>>) == sizeof(int*));
1125
1126``[[no_unique_address]]`` is a standard C++20 attribute. Clang supports its use
1127in C++11 onwards.
1128  }];
1129}
1130
1131def ObjCRequiresSuperDocs : Documentation {
1132  let Category = DocCatFunction;
1133  let Content = [{
1134Some Objective-C classes allow a subclass to override a particular method in a
1135parent class but expect that the overriding method also calls the overridden
1136method in the parent class. For these cases, we provide an attribute to
1137designate that a method requires a "call to ``super``" in the overriding
1138method in the subclass.
1139
1140**Usage**: ``__attribute__((objc_requires_super))``.  This attribute can only
1141be placed at the end of a method declaration:
1142
1143.. code-block:: objc
1144
1145  - (void)foo __attribute__((objc_requires_super));
1146
1147This attribute can only be applied the method declarations within a class, and
1148not a protocol.  Currently this attribute does not enforce any placement of
1149where the call occurs in the overriding method (such as in the case of
1150``-dealloc`` where the call must appear at the end).  It checks only that it
1151exists.
1152
1153Note that on both OS X and iOS that the Foundation framework provides a
1154convenience macro ``NS_REQUIRES_SUPER`` that provides syntactic sugar for this
1155attribute:
1156
1157.. code-block:: objc
1158
1159  - (void)foo NS_REQUIRES_SUPER;
1160
1161This macro is conditionally defined depending on the compiler's support for
1162this attribute.  If the compiler does not support the attribute the macro
1163expands to nothing.
1164
1165Operationally, when a method has this annotation the compiler will warn if the
1166implementation of an override in a subclass does not call super.  For example:
1167
1168.. code-block:: objc
1169
1170   warning: method possibly missing a [super AnnotMeth] call
1171   - (void) AnnotMeth{};
1172                      ^
1173  }];
1174}
1175
1176def ObjCRuntimeNameDocs : Documentation {
1177    let Category = DocCatDecl;
1178    let Content = [{
1179By default, the Objective-C interface or protocol identifier is used
1180in the metadata name for that object. The ``objc_runtime_name``
1181attribute allows annotated interfaces or protocols to use the
1182specified string argument in the object's metadata name instead of the
1183default name.
1184
1185**Usage**: ``__attribute__((objc_runtime_name("MyLocalName")))``.  This attribute
1186can only be placed before an @protocol or @interface declaration:
1187
1188.. code-block:: objc
1189
1190  __attribute__((objc_runtime_name("MyLocalName")))
1191  @interface Message
1192  @end
1193
1194    }];
1195}
1196
1197def ObjCRuntimeVisibleDocs : Documentation {
1198    let Category = DocCatDecl;
1199    let Content = [{
1200This attribute specifies that the Objective-C class to which it applies is
1201visible to the Objective-C runtime but not to the linker. Classes annotated
1202with this attribute cannot be subclassed and cannot have categories defined for
1203them.
1204    }];
1205}
1206
1207def ObjCClassStubDocs : Documentation {
1208    let Category = DocCatType;
1209    let Content = [{
1210This attribute specifies that the Objective-C class to which it applies is
1211instantiated at runtime.
1212
1213Unlike ``__attribute__((objc_runtime_visible))``, a class having this attribute
1214still has a "class stub" that is visible to the linker. This allows categories
1215to be defined. Static message sends with the class as a receiver use a special
1216access pattern to ensure the class is lazily instantiated from the class stub.
1217
1218Classes annotated with this attribute cannot be subclassed and cannot have
1219implementations defined for them. This attribute is intended for use in
1220Swift-generated headers for classes defined in Swift.
1221
1222Adding or removing this attribute to a class is an ABI-breaking change.
1223    }];
1224}
1225
1226def ObjCBoxableDocs : Documentation {
1227    let Category = DocCatDecl;
1228    let Content = [{
1229Structs and unions marked with the ``objc_boxable`` attribute can be used
1230with the Objective-C boxed expression syntax, ``@(...)``.
1231
1232**Usage**: ``__attribute__((objc_boxable))``. This attribute
1233can only be placed on a declaration of a trivially-copyable struct or union:
1234
1235.. code-block:: objc
1236
1237  struct __attribute__((objc_boxable)) some_struct {
1238    int i;
1239  };
1240  union __attribute__((objc_boxable)) some_union {
1241    int i;
1242    float f;
1243  };
1244  typedef struct __attribute__((objc_boxable)) _some_struct some_struct;
1245
1246  // ...
1247
1248  some_struct ss;
1249  NSValue *boxed = @(ss);
1250
1251    }];
1252}
1253
1254def AvailabilityDocs : Documentation {
1255  let Category = DocCatFunction;
1256  let Content = [{
1257The ``availability`` attribute can be placed on declarations to describe the
1258lifecycle of that declaration relative to operating system versions.  Consider
1259the function declaration for a hypothetical function ``f``:
1260
1261.. code-block:: c++
1262
1263  void f(void) __attribute__((availability(macos,introduced=10.4,deprecated=10.6,obsoleted=10.7)));
1264
1265The availability attribute states that ``f`` was introduced in macOS 10.4,
1266deprecated in macOS 10.6, and obsoleted in macOS 10.7.  This information
1267is used by Clang to determine when it is safe to use ``f``: for example, if
1268Clang is instructed to compile code for macOS 10.5, a call to ``f()``
1269succeeds.  If Clang is instructed to compile code for macOS 10.6, the call
1270succeeds but Clang emits a warning specifying that the function is deprecated.
1271Finally, if Clang is instructed to compile code for macOS 10.7, the call
1272fails because ``f()`` is no longer available.
1273
1274The availability attribute is a comma-separated list starting with the
1275platform name and then including clauses specifying important milestones in the
1276declaration's lifetime (in any order) along with additional information.  Those
1277clauses can be:
1278
1279introduced=\ *version*
1280  The first version in which this declaration was introduced.
1281
1282deprecated=\ *version*
1283  The first version in which this declaration was deprecated, meaning that
1284  users should migrate away from this API.
1285
1286obsoleted=\ *version*
1287  The first version in which this declaration was obsoleted, meaning that it
1288  was removed completely and can no longer be used.
1289
1290unavailable
1291  This declaration is never available on this platform.
1292
1293message=\ *string-literal*
1294  Additional message text that Clang will provide when emitting a warning or
1295  error about use of a deprecated or obsoleted declaration.  Useful to direct
1296  users to replacement APIs.
1297
1298replacement=\ *string-literal*
1299  Additional message text that Clang will use to provide Fix-It when emitting
1300  a warning about use of a deprecated declaration. The Fix-It will replace
1301  the deprecated declaration with the new declaration specified.
1302
1303Multiple availability attributes can be placed on a declaration, which may
1304correspond to different platforms. For most platforms, the availability
1305attribute with the platform corresponding to the target platform will be used;
1306any others will be ignored. However, the availability for ``watchOS`` and
1307``tvOS`` can be implicitly inferred from an ``iOS`` availability attribute.
1308Any explicit availability attributes for those platforms are still preferred over
1309the implicitly inferred availability attributes. If no availability attribute
1310specifies availability for the current target platform, the availability
1311attributes are ignored. Supported platforms are:
1312
1313``ios``
1314  Apple's iOS operating system.  The minimum deployment target is specified by
1315  the ``-mios-version-min=*version*`` or ``-miphoneos-version-min=*version*``
1316  command-line arguments.
1317
1318``macos``
1319  Apple's macOS operating system.  The minimum deployment target is
1320  specified by the ``-mmacosx-version-min=*version*`` command-line argument.
1321  ``macosx`` is supported for backward-compatibility reasons, but it is
1322  deprecated.
1323
1324``tvos``
1325  Apple's tvOS operating system.  The minimum deployment target is specified by
1326  the ``-mtvos-version-min=*version*`` command-line argument.
1327
1328``watchos``
1329  Apple's watchOS operating system.  The minimum deployment target is specified by
1330  the ``-mwatchos-version-min=*version*`` command-line argument.
1331
1332A declaration can typically be used even when deploying back to a platform
1333version prior to when the declaration was introduced.  When this happens, the
1334declaration is `weakly linked
1335<https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html>`_,
1336as if the ``weak_import`` attribute were added to the declaration.  A
1337weakly-linked declaration may or may not be present a run-time, and a program
1338can determine whether the declaration is present by checking whether the
1339address of that declaration is non-NULL.
1340
1341The flag ``strict`` disallows using API when deploying back to a
1342platform version prior to when the declaration was introduced.  An
1343attempt to use such API before its introduction causes a hard error.
1344Weakly-linking is almost always a better API choice, since it allows
1345users to query availability at runtime.
1346
1347If there are multiple declarations of the same entity, the availability
1348attributes must either match on a per-platform basis or later
1349declarations must not have availability attributes for that
1350platform. For example:
1351
1352.. code-block:: c
1353
1354  void g(void) __attribute__((availability(macos,introduced=10.4)));
1355  void g(void) __attribute__((availability(macos,introduced=10.4))); // okay, matches
1356  void g(void) __attribute__((availability(ios,introduced=4.0))); // okay, adds a new platform
1357  void g(void); // okay, inherits both macos and ios availability from above.
1358  void g(void) __attribute__((availability(macos,introduced=10.5))); // error: mismatch
1359
1360When one method overrides another, the overriding method can be more widely available than the overridden method, e.g.,:
1361
1362.. code-block:: objc
1363
1364  @interface A
1365  - (id)method __attribute__((availability(macos,introduced=10.4)));
1366  - (id)method2 __attribute__((availability(macos,introduced=10.4)));
1367  @end
1368
1369  @interface B : A
1370  - (id)method __attribute__((availability(macos,introduced=10.3))); // okay: method moved into base class later
1371  - (id)method __attribute__((availability(macos,introduced=10.5))); // error: this method was available via the base class in 10.4
1372  @end
1373
1374Starting with the macOS 10.12 SDK, the ``API_AVAILABLE`` macro from
1375``<os/availability.h>`` can simplify the spelling:
1376
1377.. code-block:: objc
1378
1379  @interface A
1380  - (id)method API_AVAILABLE(macos(10.11)));
1381  - (id)otherMethod API_AVAILABLE(macos(10.11), ios(11.0));
1382  @end
1383
1384Availability attributes can also be applied using a ``#pragma clang attribute``.
1385Any explicit availability attribute whose platform corresponds to the target
1386platform is applied to a declaration regardless of the availability attributes
1387specified in the pragma. For example, in the code below,
1388``hasExplicitAvailabilityAttribute`` will use the ``macOS`` availability
1389attribute that is specified with the declaration, whereas
1390``getsThePragmaAvailabilityAttribute`` will use the ``macOS`` availability
1391attribute that is applied by the pragma.
1392
1393.. code-block:: c
1394
1395  #pragma clang attribute push (__attribute__((availability(macOS, introduced=10.12))), apply_to=function)
1396  void getsThePragmaAvailabilityAttribute(void);
1397  void hasExplicitAvailabilityAttribute(void) __attribute__((availability(macos,introduced=10.4)));
1398  #pragma clang attribute pop
1399
1400For platforms like ``watchOS`` and ``tvOS``, whose availability attributes can
1401be implicitly inferred from an ``iOS`` availability attribute, the logic is
1402slightly more complex. The explicit and the pragma-applied availability
1403attributes whose platform corresponds to the target platform are applied as
1404described in the previous paragraph. However, the implicitly inferred attributes
1405are applied to a declaration only when there is no explicit or pragma-applied
1406availability attribute whose platform corresponds to the target platform. For
1407example, the function below will receive the ``tvOS`` availability from the
1408pragma rather than using the inferred ``iOS`` availability from the declaration:
1409
1410.. code-block:: c
1411
1412  #pragma clang attribute push (__attribute__((availability(tvOS, introduced=12.0))), apply_to=function)
1413  void getsThePragmaTVOSAvailabilityAttribute(void) __attribute__((availability(iOS,introduced=11.0)));
1414  #pragma clang attribute pop
1415
1416The compiler is also able to apply implicitly inferred attributes from a pragma
1417as well. For example, when targeting ``tvOS``, the function below will receive
1418a ``tvOS`` availability attribute that is implicitly inferred from the ``iOS``
1419availability attribute applied by the pragma:
1420
1421.. code-block:: c
1422
1423  #pragma clang attribute push (__attribute__((availability(iOS, introduced=12.0))), apply_to=function)
1424  void infersTVOSAvailabilityFromPragma(void);
1425  #pragma clang attribute pop
1426
1427The implicit attributes that are inferred from explicitly specified attributes
1428whose platform corresponds to the target platform are applied to the declaration
1429even if there is an availability attribute that can be inferred from a pragma.
1430For example, the function below will receive the ``tvOS, introduced=11.0``
1431availability that is inferred from the attribute on the declaration rather than
1432inferring availability from the pragma:
1433
1434.. code-block:: c
1435
1436  #pragma clang attribute push (__attribute__((availability(iOS, unavailable))), apply_to=function)
1437  void infersTVOSAvailabilityFromAttributeNextToDeclaration(void)
1438    __attribute__((availability(iOS,introduced=11.0)));
1439  #pragma clang attribute pop
1440
1441Also see the documentation for `@available
1442<http://clang.llvm.org/docs/LanguageExtensions.html#objective-c-available>`_
1443  }];
1444}
1445
1446def ExternalSourceSymbolDocs : Documentation {
1447  let Category = DocCatDecl;
1448  let Content = [{
1449The ``external_source_symbol`` attribute specifies that a declaration originates
1450from an external source and describes the nature of that source.
1451
1452The fact that Clang is capable of recognizing declarations that were defined
1453externally can be used to provide better tooling support for mixed-language
1454projects or projects that rely on auto-generated code. For instance, an IDE that
1455uses Clang and that supports mixed-language projects can use this attribute to
1456provide a correct 'jump-to-definition' feature. For a concrete example,
1457consider a protocol that's defined in a Swift file:
1458
1459.. code-block:: swift
1460
1461  @objc public protocol SwiftProtocol {
1462    func method()
1463  }
1464
1465This protocol can be used from Objective-C code by including a header file that
1466was generated by the Swift compiler. The declarations in that header can use
1467the ``external_source_symbol`` attribute to make Clang aware of the fact
1468that ``SwiftProtocol`` actually originates from a Swift module:
1469
1470.. code-block:: objc
1471
1472  __attribute__((external_source_symbol(language="Swift",defined_in="module")))
1473  @protocol SwiftProtocol
1474  @required
1475  - (void) method;
1476  @end
1477
1478Consequently, when 'jump-to-definition' is performed at a location that
1479references ``SwiftProtocol``, the IDE can jump to the original definition in
1480the Swift source file rather than jumping to the Objective-C declaration in the
1481auto-generated header file.
1482
1483The ``external_source_symbol`` attribute is a comma-separated list that includes
1484clauses that describe the origin and the nature of the particular declaration.
1485Those clauses can be:
1486
1487language=\ *string-literal*
1488  The name of the source language in which this declaration was defined.
1489
1490defined_in=\ *string-literal*
1491  The name of the source container in which the declaration was defined. The
1492  exact definition of source container is language-specific, e.g. Swift's
1493  source containers are modules, so ``defined_in`` should specify the Swift
1494  module name.
1495
1496generated_declaration
1497  This declaration was automatically generated by some tool.
1498
1499The clauses can be specified in any order. The clauses that are listed above are
1500all optional, but the attribute has to have at least one clause.
1501  }];
1502}
1503
1504def ConstInitDocs : Documentation {
1505  let Category = DocCatVariable;
1506  let Heading = "require_constant_initialization, constinit (C++20)";
1507  let Content = [{
1508This attribute specifies that the variable to which it is attached is intended
1509to have a `constant initializer <http://en.cppreference.com/w/cpp/language/constant_initialization>`_
1510according to the rules of [basic.start.static]. The variable is required to
1511have static or thread storage duration. If the initialization of the variable
1512is not a constant initializer an error will be produced. This attribute may
1513only be used in C++; the ``constinit`` spelling is only accepted in C++20
1514onwards.
1515
1516Note that in C++03 strict constant expression checking is not done. Instead
1517the attribute reports if Clang can emit the variable as a constant, even if it's
1518not technically a 'constant initializer'. This behavior is non-portable.
1519
1520Static storage duration variables with constant initializers avoid hard-to-find
1521bugs caused by the indeterminate order of dynamic initialization. They can also
1522be safely used during dynamic initialization across translation units.
1523
1524This attribute acts as a compile time assertion that the requirements
1525for constant initialization have been met. Since these requirements change
1526between dialects and have subtle pitfalls it's important to fail fast instead
1527of silently falling back on dynamic initialization.
1528
1529The first use of the attribute on a variable must be part of, or precede, the
1530initializing declaration of the variable. C++20 requires the ``constinit``
1531spelling of the attribute to be present on the initializing declaration if it
1532is used anywhere. The other spellings can be specified on a forward declaration
1533and omitted on a later initializing declaration.
1534
1535.. code-block:: c++
1536
1537  // -std=c++14
1538  #define SAFE_STATIC [[clang::require_constant_initialization]]
1539  struct T {
1540    constexpr T(int) {}
1541    ~T(); // non-trivial
1542  };
1543  SAFE_STATIC T x = {42}; // Initialization OK. Doesn't check destructor.
1544  SAFE_STATIC T y = 42; // error: variable does not have a constant initializer
1545  // copy initialization is not a constant expression on a non-literal type.
1546  }];
1547}
1548
1549def WarnMaybeUnusedDocs : Documentation {
1550  let Category = DocCatVariable;
1551  let Heading = "maybe_unused, unused";
1552  let Content = [{
1553When passing the ``-Wunused`` flag to Clang, entities that are unused by the
1554program may be diagnosed. The ``[[maybe_unused]]`` (or
1555``__attribute__((unused))``) attribute can be used to silence such diagnostics
1556when the entity cannot be removed. For instance, a local variable may exist
1557solely for use in an ``assert()`` statement, which makes the local variable
1558unused when ``NDEBUG`` is defined.
1559
1560The attribute may be applied to the declaration of a class, a typedef, a
1561variable, a function or method, a function parameter, an enumeration, an
1562enumerator, a non-static data member, or a label.
1563
1564.. code-block: c++
1565  #include <cassert>
1566
1567  [[maybe_unused]] void f([[maybe_unused]] bool thing1,
1568                          [[maybe_unused]] bool thing2) {
1569    [[maybe_unused]] bool b = thing1 && thing2;
1570    assert(b);
1571  }
1572  }];
1573}
1574
1575def WarnUnusedResultsDocs : Documentation {
1576  let Category = DocCatFunction;
1577  let Heading = "nodiscard, warn_unused_result";
1578  let Content  = [{
1579Clang supports the ability to diagnose when the results of a function call
1580expression are discarded under suspicious circumstances. A diagnostic is
1581generated when a function or its return type is marked with ``[[nodiscard]]``
1582(or ``__attribute__((warn_unused_result))``) and the function call appears as a
1583potentially-evaluated discarded-value expression that is not explicitly cast to
1584``void``.
1585
1586A string literal may optionally be provided to the attribute, which will be
1587reproduced in any resulting diagnostics. Redeclarations using different forms
1588of the attribute (with or without the string literal or with different string
1589literal contents) are allowed. If there are redeclarations of the entity with
1590differing string literals, it is unspecified which one will be used by Clang
1591in any resulting diagnostics.
1592
1593.. code-block: c++
1594  struct [[nodiscard]] error_info { /*...*/ };
1595  error_info enable_missile_safety_mode();
1596
1597  void launch_missiles();
1598  void test_missiles() {
1599    enable_missile_safety_mode(); // diagnoses
1600    launch_missiles();
1601  }
1602  error_info &foo();
1603  void f() { foo(); } // Does not diagnose, error_info is a reference.
1604
1605Additionally, discarded temporaries resulting from a call to a constructor
1606marked with ``[[nodiscard]]`` or a constructor of a type marked
1607``[[nodiscard]]`` will also diagnose. This also applies to type conversions that
1608use the annotated ``[[nodiscard]]`` constructor or result in an annotated type.
1609
1610.. code-block: c++
1611  struct [[nodiscard]] marked_type {/*..*/ };
1612  struct marked_ctor {
1613    [[nodiscard]] marked_ctor();
1614    marked_ctor(int);
1615  };
1616
1617  struct S {
1618    operator marked_type() const;
1619    [[nodiscard]] operator int() const;
1620  };
1621
1622  void usages() {
1623    marked_type(); // diagnoses.
1624    marked_ctor(); // diagnoses.
1625    marked_ctor(3); // Does not diagnose, int constructor isn't marked nodiscard.
1626
1627    S s;
1628    static_cast<marked_type>(s); // diagnoses
1629    (int)s; // diagnoses
1630  }
1631  }];
1632}
1633
1634def FallthroughDocs : Documentation {
1635  let Category = DocCatStmt;
1636  let Heading = "fallthrough";
1637  let Content = [{
1638The ``fallthrough`` (or ``clang::fallthrough``) attribute is used
1639to annotate intentional fall-through
1640between switch labels.  It can only be applied to a null statement placed at a
1641point of execution between any statement and the next switch label.  It is
1642common to mark these places with a specific comment, but this attribute is
1643meant to replace comments with a more strict annotation, which can be checked
1644by the compiler.  This attribute doesn't change semantics of the code and can
1645be used wherever an intended fall-through occurs.  It is designed to mimic
1646control-flow statements like ``break;``, so it can be placed in most places
1647where ``break;`` can, but only if there are no statements on the execution path
1648between it and the next switch label.
1649
1650By default, Clang does not warn on unannotated fallthrough from one ``switch``
1651case to another. Diagnostics on fallthrough without a corresponding annotation
1652can be enabled with the ``-Wimplicit-fallthrough`` argument.
1653
1654Here is an example:
1655
1656.. code-block:: c++
1657
1658  // compile with -Wimplicit-fallthrough
1659  switch (n) {
1660  case 22:
1661  case 33:  // no warning: no statements between case labels
1662    f();
1663  case 44:  // warning: unannotated fall-through
1664    g();
1665    [[clang::fallthrough]];
1666  case 55:  // no warning
1667    if (x) {
1668      h();
1669      break;
1670    }
1671    else {
1672      i();
1673      [[clang::fallthrough]];
1674    }
1675  case 66:  // no warning
1676    p();
1677    [[clang::fallthrough]]; // warning: fallthrough annotation does not
1678                            //          directly precede case label
1679    q();
1680  case 77:  // warning: unannotated fall-through
1681    r();
1682  }
1683  }];
1684}
1685
1686def ARMInterruptDocs : Documentation {
1687  let Category = DocCatFunction;
1688  let Heading = "interrupt (ARM)";
1689  let Content = [{
1690Clang supports the GNU style ``__attribute__((interrupt("TYPE")))`` attribute on
1691ARM targets. This attribute may be attached to a function definition and
1692instructs the backend to generate appropriate function entry/exit code so that
1693it can be used directly as an interrupt service routine.
1694
1695The parameter passed to the interrupt attribute is optional, but if
1696provided it must be a string literal with one of the following values: "IRQ",
1697"FIQ", "SWI", "ABORT", "UNDEF".
1698
1699The semantics are as follows:
1700
1701- If the function is AAPCS, Clang instructs the backend to realign the stack to
1702  8 bytes on entry. This is a general requirement of the AAPCS at public
1703  interfaces, but may not hold when an exception is taken. Doing this allows
1704  other AAPCS functions to be called.
1705- If the CPU is M-class this is all that needs to be done since the architecture
1706  itself is designed in such a way that functions obeying the normal AAPCS ABI
1707  constraints are valid exception handlers.
1708- If the CPU is not M-class, the prologue and epilogue are modified to save all
1709  non-banked registers that are used, so that upon return the user-mode state
1710  will not be corrupted. Note that to avoid unnecessary overhead, only
1711  general-purpose (integer) registers are saved in this way. If VFP operations
1712  are needed, that state must be saved manually.
1713
1714  Specifically, interrupt kinds other than "FIQ" will save all core registers
1715  except "lr" and "sp". "FIQ" interrupts will save r0-r7.
1716- If the CPU is not M-class, the return instruction is changed to one of the
1717  canonical sequences permitted by the architecture for exception return. Where
1718  possible the function itself will make the necessary "lr" adjustments so that
1719  the "preferred return address" is selected.
1720
1721  Unfortunately the compiler is unable to make this guarantee for an "UNDEF"
1722  handler, where the offset from "lr" to the preferred return address depends on
1723  the execution state of the code which generated the exception. In this case
1724  a sequence equivalent to "movs pc, lr" will be used.
1725  }];
1726}
1727
1728def BPFPreserveAccessIndexDocs : Documentation {
1729  let Category = DocCatFunction;
1730  let Content = [{
1731Clang supports the ``__attribute__((preserve_access_index))``
1732attribute for the BPF target. This attribute may be attached to a
1733struct or union declaration, where if -g is specified, it enables
1734preserving struct or union member access debuginfo indices of this
1735struct or union, similar to clang ``__builtin_preserve_acceess_index()``.
1736  }];
1737}
1738
1739def MipsInterruptDocs : Documentation {
1740  let Category = DocCatFunction;
1741  let Heading = "interrupt (MIPS)";
1742  let Content = [{
1743Clang supports the GNU style ``__attribute__((interrupt("ARGUMENT")))`` attribute on
1744MIPS targets. This attribute may be attached to a function definition and instructs
1745the backend to generate appropriate function entry/exit code so that it can be used
1746directly as an interrupt service routine.
1747
1748By default, the compiler will produce a function prologue and epilogue suitable for
1749an interrupt service routine that handles an External Interrupt Controller (eic)
1750generated interrupt. This behavior can be explicitly requested with the "eic"
1751argument.
1752
1753Otherwise, for use with vectored interrupt mode, the argument passed should be
1754of the form "vector=LEVEL" where LEVEL is one of the following values:
1755"sw0", "sw1", "hw0", "hw1", "hw2", "hw3", "hw4", "hw5". The compiler will
1756then set the interrupt mask to the corresponding level which will mask all
1757interrupts up to and including the argument.
1758
1759The semantics are as follows:
1760
1761- The prologue is modified so that the Exception Program Counter (EPC) and
1762  Status coprocessor registers are saved to the stack. The interrupt mask is
1763  set so that the function can only be interrupted by a higher priority
1764  interrupt. The epilogue will restore the previous values of EPC and Status.
1765
1766- The prologue and epilogue are modified to save and restore all non-kernel
1767  registers as necessary.
1768
1769- The FPU is disabled in the prologue, as the floating pointer registers are not
1770  spilled to the stack.
1771
1772- The function return sequence is changed to use an exception return instruction.
1773
1774- The parameter sets the interrupt mask for the function corresponding to the
1775  interrupt level specified. If no mask is specified the interrupt mask
1776  defaults to "eic".
1777  }];
1778}
1779
1780def MicroMipsDocs : Documentation {
1781  let Category = DocCatFunction;
1782  let Content = [{
1783Clang supports the GNU style ``__attribute__((micromips))`` and
1784``__attribute__((nomicromips))`` attributes on MIPS targets. These attributes
1785may be attached to a function definition and instructs the backend to generate
1786or not to generate microMIPS code for that function.
1787
1788These attributes override the ``-mmicromips`` and ``-mno-micromips`` options
1789on the command line.
1790  }];
1791}
1792
1793def MipsLongCallStyleDocs : Documentation {
1794  let Category = DocCatFunction;
1795  let Heading = "long_call, far";
1796  let Content = [{
1797Clang supports the ``__attribute__((long_call))``, ``__attribute__((far))``,
1798and ``__attribute__((near))`` attributes on MIPS targets. These attributes may
1799only be added to function declarations and change the code generated
1800by the compiler when directly calling the function. The ``near`` attribute
1801allows calls to the function to be made using the ``jal`` instruction, which
1802requires the function to be located in the same naturally aligned 256MB
1803segment as the caller.  The ``long_call`` and ``far`` attributes are synonyms
1804and require the use of a different call sequence that works regardless
1805of the distance between the functions.
1806
1807These attributes have no effect for position-independent code.
1808
1809These attributes take priority over command line switches such
1810as ``-mlong-calls`` and ``-mno-long-calls``.
1811  }];
1812}
1813
1814def MipsShortCallStyleDocs : Documentation {
1815  let Category = DocCatFunction;
1816  let Heading = "short_call, near";
1817  let Content = [{
1818Clang supports the ``__attribute__((long_call))``, ``__attribute__((far))``,
1819``__attribute__((short__call))``, and ``__attribute__((near))`` attributes
1820on MIPS targets. These attributes may only be added to function declarations
1821and change the code generated by the compiler when directly calling
1822the function. The ``short_call`` and ``near`` attributes are synonyms and
1823allow calls to the function to be made using the ``jal`` instruction, which
1824requires the function to be located in the same naturally aligned 256MB segment
1825as the caller.  The ``long_call`` and ``far`` attributes are synonyms and
1826require the use of a different call sequence that works regardless
1827of the distance between the functions.
1828
1829These attributes have no effect for position-independent code.
1830
1831These attributes take priority over command line switches such
1832as ``-mlong-calls`` and ``-mno-long-calls``.
1833  }];
1834}
1835
1836def RISCVInterruptDocs : Documentation {
1837  let Category = DocCatFunction;
1838  let Heading = "interrupt (RISCV)";
1839  let Content = [{
1840Clang supports the GNU style ``__attribute__((interrupt))`` attribute on RISCV
1841targets. This attribute may be attached to a function definition and instructs
1842the backend to generate appropriate function entry/exit code so that it can be
1843used directly as an interrupt service routine.
1844
1845Permissible values for this parameter are ``user``, ``supervisor``,
1846and ``machine``. If there is no parameter, then it defaults to machine.
1847
1848Repeated interrupt attribute on the same declaration will cause a warning
1849to be emitted. In case of repeated declarations, the last one prevails.
1850
1851Refer to:
1852https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Function-Attributes.html
1853https://riscv.org/specifications/privileged-isa/
1854The RISC-V Instruction Set Manual Volume II: Privileged Architecture
1855Version 1.10.
1856  }];
1857}
1858
1859def AVRInterruptDocs : Documentation {
1860  let Category = DocCatFunction;
1861  let Heading = "interrupt (AVR)";
1862  let Content = [{
1863Clang supports the GNU style ``__attribute__((interrupt))`` attribute on
1864AVR targets. This attribute may be attached to a function definition and instructs
1865the backend to generate appropriate function entry/exit code so that it can be used
1866directly as an interrupt service routine.
1867
1868On the AVR, the hardware globally disables interrupts when an interrupt is executed.
1869The first instruction of an interrupt handler declared with this attribute is a SEI
1870instruction to re-enable interrupts. See also the signal attribute that
1871does not insert a SEI instruction.
1872  }];
1873}
1874
1875def AVRSignalDocs : Documentation {
1876  let Category = DocCatFunction;
1877  let Content = [{
1878Clang supports the GNU style ``__attribute__((signal))`` attribute on
1879AVR targets. This attribute may be attached to a function definition and instructs
1880the backend to generate appropriate function entry/exit code so that it can be used
1881directly as an interrupt service routine.
1882
1883Interrupt handler functions defined with the signal attribute do not re-enable interrupts.
1884}];
1885}
1886
1887def TargetDocs : Documentation {
1888  let Category = DocCatFunction;
1889  let Content = [{
1890Clang supports the GNU style ``__attribute__((target("OPTIONS")))`` attribute.
1891This attribute may be attached to a function definition and instructs
1892the backend to use different code generation options than were passed on the
1893command line.
1894
1895The current set of options correspond to the existing "subtarget features" for
1896the target with or without a "-mno-" in front corresponding to the absence
1897of the feature, as well as ``arch="CPU"`` which will change the default "CPU"
1898for the function.
1899
1900For AArch64, the attribute also allows the "branch-protection=<args>" option,
1901where the permissible arguments and their effect on code generation are the same
1902as for the command-line option ``-mbranch-protection``.
1903
1904Example "subtarget features" from the x86 backend include: "mmx", "sse", "sse4.2",
1905"avx", "xop" and largely correspond to the machine specific options handled by
1906the front end.
1907
1908Additionally, this attribute supports function multiversioning for ELF based
1909x86/x86-64 targets, which can be used to create multiple implementations of the
1910same function that will be resolved at runtime based on the priority of their
1911``target`` attribute strings. A function is considered a multiversioned function
1912if either two declarations of the function have different ``target`` attribute
1913strings, or if it has a ``target`` attribute string of ``default``.  For
1914example:
1915
1916  .. code-block:: c++
1917
1918    __attribute__((target("arch=atom")))
1919    void foo() {} // will be called on 'atom' processors.
1920    __attribute__((target("default")))
1921    void foo() {} // will be called on any other processors.
1922
1923All multiversioned functions must contain a ``default`` (fallback)
1924implementation, otherwise usages of the function are considered invalid.
1925Additionally, a function may not become multiversioned after its first use.
1926}];
1927}
1928
1929def MinVectorWidthDocs : Documentation {
1930  let Category = DocCatFunction;
1931  let Content = [{
1932Clang supports the ``__attribute__((min_vector_width(width)))`` attribute. This
1933attribute may be attached to a function and informs the backend that this
1934function desires vectors of at least this width to be generated. Target-specific
1935maximum vector widths still apply. This means even if you ask for something
1936larger than the target supports, you will only get what the target supports.
1937This attribute is meant to be a hint to control target heuristics that may
1938generate narrower vectors than what the target hardware supports.
1939
1940This is currently used by the X86 target to allow some CPUs that support 512-bit
1941vectors to be limited to using 256-bit vectors to avoid frequency penalties.
1942This is currently enabled with the ``-prefer-vector-width=256`` command line
1943option. The ``min_vector_width`` attribute can be used to prevent the backend
1944from trying to split vector operations to match the ``prefer-vector-width``. All
1945X86 vector intrinsics from x86intrin.h already set this attribute. Additionally,
1946use of any of the X86-specific vector builtins will implicitly set this
1947attribute on the calling function. The intent is that explicitly writing vector
1948code using the X86 intrinsics will prevent ``prefer-vector-width`` from
1949affecting the code.
1950}];
1951}
1952
1953def DocCatAMDGPUAttributes : DocumentationCategory<"AMD GPU Attributes">;
1954
1955def AMDGPUFlatWorkGroupSizeDocs : Documentation {
1956  let Category = DocCatAMDGPUAttributes;
1957  let Content = [{
1958The flat work-group size is the number of work-items in the work-group size
1959specified when the kernel is dispatched. It is the product of the sizes of the
1960x, y, and z dimension of the work-group.
1961
1962Clang supports the
1963``__attribute__((amdgpu_flat_work_group_size(<min>, <max>)))`` attribute for the
1964AMDGPU target. This attribute may be attached to a kernel function definition
1965and is an optimization hint.
1966
1967``<min>`` parameter specifies the minimum flat work-group size, and ``<max>``
1968parameter specifies the maximum flat work-group size (must be greater than
1969``<min>``) to which all dispatches of the kernel will conform. Passing ``0, 0``
1970as ``<min>, <max>`` implies the default behavior (``128, 256``).
1971
1972If specified, the AMDGPU target backend might be able to produce better machine
1973code for barriers and perform scratch promotion by estimating available group
1974segment size.
1975
1976An error will be given if:
1977  - Specified values violate subtarget specifications;
1978  - Specified values are not compatible with values provided through other
1979    attributes.
1980  }];
1981}
1982
1983def AMDGPUWavesPerEUDocs : Documentation {
1984  let Category = DocCatAMDGPUAttributes;
1985  let Content = [{
1986A compute unit (CU) is responsible for executing the wavefronts of a work-group.
1987It is composed of one or more execution units (EU), which are responsible for
1988executing the wavefronts. An EU can have enough resources to maintain the state
1989of more than one executing wavefront. This allows an EU to hide latency by
1990switching between wavefronts in a similar way to symmetric multithreading on a
1991CPU. In order to allow the state for multiple wavefronts to fit on an EU, the
1992resources used by a single wavefront have to be limited. For example, the number
1993of SGPRs and VGPRs. Limiting such resources can allow greater latency hiding,
1994but can result in having to spill some register state to memory.
1995
1996Clang supports the ``__attribute__((amdgpu_waves_per_eu(<min>[, <max>])))``
1997attribute for the AMDGPU target. This attribute may be attached to a kernel
1998function definition and is an optimization hint.
1999
2000``<min>`` parameter specifies the requested minimum number of waves per EU, and
2001*optional* ``<max>`` parameter specifies the requested maximum number of waves
2002per EU (must be greater than ``<min>`` if specified). If ``<max>`` is omitted,
2003then there is no restriction on the maximum number of waves per EU other than
2004the one dictated by the hardware for which the kernel is compiled. Passing
2005``0, 0`` as ``<min>, <max>`` implies the default behavior (no limits).
2006
2007If specified, this attribute allows an advanced developer to tune the number of
2008wavefronts that are capable of fitting within the resources of an EU. The AMDGPU
2009target backend can use this information to limit resources, such as number of
2010SGPRs, number of VGPRs, size of available group and private memory segments, in
2011such a way that guarantees that at least ``<min>`` wavefronts and at most
2012``<max>`` wavefronts are able to fit within the resources of an EU. Requesting
2013more wavefronts can hide memory latency but limits available registers which
2014can result in spilling. Requesting fewer wavefronts can help reduce cache
2015thrashing, but can reduce memory latency hiding.
2016
2017This attribute controls the machine code generated by the AMDGPU target backend
2018to ensure it is capable of meeting the requested values. However, when the
2019kernel is executed, there may be other reasons that prevent meeting the request,
2020for example, there may be wavefronts from other kernels executing on the EU.
2021
2022An error will be given if:
2023  - Specified values violate subtarget specifications;
2024  - Specified values are not compatible with values provided through other
2025    attributes;
2026  - The AMDGPU target backend is unable to create machine code that can meet the
2027    request.
2028  }];
2029}
2030
2031def AMDGPUNumSGPRNumVGPRDocs : Documentation {
2032  let Category = DocCatAMDGPUAttributes;
2033  let Content = [{
2034Clang supports the ``__attribute__((amdgpu_num_sgpr(<num_sgpr>)))`` and
2035``__attribute__((amdgpu_num_vgpr(<num_vgpr>)))`` attributes for the AMDGPU
2036target. These attributes may be attached to a kernel function definition and are
2037an optimization hint.
2038
2039If these attributes are specified, then the AMDGPU target backend will attempt
2040to limit the number of SGPRs and/or VGPRs used to the specified value(s). The
2041number of used SGPRs and/or VGPRs may further be rounded up to satisfy the
2042allocation requirements or constraints of the subtarget. Passing ``0`` as
2043``num_sgpr`` and/or ``num_vgpr`` implies the default behavior (no limits).
2044
2045These attributes can be used to test the AMDGPU target backend. It is
2046recommended that the ``amdgpu_waves_per_eu`` attribute be used to control
2047resources such as SGPRs and VGPRs since it is aware of the limits for different
2048subtargets.
2049
2050An error will be given if:
2051  - Specified values violate subtarget specifications;
2052  - Specified values are not compatible with values provided through other
2053    attributes;
2054  - The AMDGPU target backend is unable to create machine code that can meet the
2055    request.
2056  }];
2057}
2058
2059def DocCatCallingConvs : DocumentationCategory<"Calling Conventions"> {
2060  let Content = [{
2061Clang supports several different calling conventions, depending on the target
2062platform and architecture. The calling convention used for a function determines
2063how parameters are passed, how results are returned to the caller, and other
2064low-level details of calling a function.
2065  }];
2066}
2067
2068def PcsDocs : Documentation {
2069  let Category = DocCatCallingConvs;
2070  let Content = [{
2071On ARM targets, this attribute can be used to select calling conventions
2072similar to ``stdcall`` on x86. Valid parameter values are "aapcs" and
2073"aapcs-vfp".
2074  }];
2075}
2076
2077def AArch64VectorPcsDocs : Documentation {
2078  let Category = DocCatCallingConvs;
2079  let Content = [{
2080On AArch64 targets, this attribute changes the calling convention of a
2081function to preserve additional floating-point and Advanced SIMD registers
2082relative to the default calling convention used for AArch64.
2083
2084This means it is more efficient to call such functions from code that performs
2085extensive floating-point and vector calculations, because fewer live SIMD and FP
2086registers need to be saved. This property makes it well-suited for e.g.
2087floating-point or vector math library functions, which are typically leaf
2088functions that require a small number of registers.
2089
2090However, using this attribute also means that it is more expensive to call
2091a function that adheres to the default calling convention from within such
2092a function. Therefore, it is recommended that this attribute is only used
2093for leaf functions.
2094
2095For more information, see the documentation for `aarch64_vector_pcs`_ on
2096the Arm Developer website.
2097
2098.. _`aarch64_vector_pcs`: https://developer.arm.com/products/software-development-tools/hpc/arm-compiler-for-hpc/vector-function-abi
2099  }];
2100}
2101
2102def RegparmDocs : Documentation {
2103  let Category = DocCatCallingConvs;
2104  let Content = [{
2105On 32-bit x86 targets, the regparm attribute causes the compiler to pass
2106the first three integer parameters in EAX, EDX, and ECX instead of on the
2107stack. This attribute has no effect on variadic functions, and all parameters
2108are passed via the stack as normal.
2109  }];
2110}
2111
2112def SysVABIDocs : Documentation {
2113  let Category = DocCatCallingConvs;
2114  let Content = [{
2115On Windows x86_64 targets, this attribute changes the calling convention of a
2116function to match the default convention used on Sys V targets such as Linux,
2117Mac, and BSD. This attribute has no effect on other targets.
2118  }];
2119}
2120
2121def MSABIDocs : Documentation {
2122  let Category = DocCatCallingConvs;
2123  let Content = [{
2124On non-Windows x86_64 targets, this attribute changes the calling convention of
2125a function to match the default convention used on Windows x86_64. This
2126attribute has no effect on Windows targets or non-x86_64 targets.
2127  }];
2128}
2129
2130def StdCallDocs : Documentation {
2131  let Category = DocCatCallingConvs;
2132  let Content = [{
2133On 32-bit x86 targets, this attribute changes the calling convention of a
2134function to clear parameters off of the stack on return. This convention does
2135not support variadic calls or unprototyped functions in C, and has no effect on
2136x86_64 targets. This calling convention is used widely by the Windows API and
2137COM applications.  See the documentation for `__stdcall`_ on MSDN.
2138
2139.. _`__stdcall`: http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx
2140  }];
2141}
2142
2143def FastCallDocs : Documentation {
2144  let Category = DocCatCallingConvs;
2145  let Content = [{
2146On 32-bit x86 targets, this attribute changes the calling convention of a
2147function to use ECX and EDX as register parameters and clear parameters off of
2148the stack on return. This convention does not support variadic calls or
2149unprototyped functions in C, and has no effect on x86_64 targets. This calling
2150convention is supported primarily for compatibility with existing code. Users
2151seeking register parameters should use the ``regparm`` attribute, which does
2152not require callee-cleanup.  See the documentation for `__fastcall`_ on MSDN.
2153
2154.. _`__fastcall`: http://msdn.microsoft.com/en-us/library/6xa169sk.aspx
2155  }];
2156}
2157
2158def RegCallDocs : Documentation {
2159  let Category = DocCatCallingConvs;
2160  let Content = [{
2161On x86 targets, this attribute changes the calling convention to
2162`__regcall`_ convention. This convention aims to pass as many arguments
2163as possible in registers. It also tries to utilize registers for the
2164return value whenever it is possible.
2165
2166.. _`__regcall`: https://software.intel.com/en-us/node/693069
2167  }];
2168}
2169
2170def ThisCallDocs : Documentation {
2171  let Category = DocCatCallingConvs;
2172  let Content = [{
2173On 32-bit x86 targets, this attribute changes the calling convention of a
2174function to use ECX for the first parameter (typically the implicit ``this``
2175parameter of C++ methods) and clear parameters off of the stack on return. This
2176convention does not support variadic calls or unprototyped functions in C, and
2177has no effect on x86_64 targets. See the documentation for `__thiscall`_ on
2178MSDN.
2179
2180.. _`__thiscall`: http://msdn.microsoft.com/en-us/library/ek8tkfbw.aspx
2181  }];
2182}
2183
2184def VectorCallDocs : Documentation {
2185  let Category = DocCatCallingConvs;
2186  let Content = [{
2187On 32-bit x86 *and* x86_64 targets, this attribute changes the calling
2188convention of a function to pass vector parameters in SSE registers.
2189
2190On 32-bit x86 targets, this calling convention is similar to ``__fastcall``.
2191The first two integer parameters are passed in ECX and EDX. Subsequent integer
2192parameters are passed in memory, and callee clears the stack.  On x86_64
2193targets, the callee does *not* clear the stack, and integer parameters are
2194passed in RCX, RDX, R8, and R9 as is done for the default Windows x64 calling
2195convention.
2196
2197On both 32-bit x86 and x86_64 targets, vector and floating point arguments are
2198passed in XMM0-XMM5. Homogeneous vector aggregates of up to four elements are
2199passed in sequential SSE registers if enough are available. If AVX is enabled,
2200256 bit vectors are passed in YMM0-YMM5. Any vector or aggregate type that
2201cannot be passed in registers for any reason is passed by reference, which
2202allows the caller to align the parameter memory.
2203
2204See the documentation for `__vectorcall`_ on MSDN for more details.
2205
2206.. _`__vectorcall`: http://msdn.microsoft.com/en-us/library/dn375768.aspx
2207  }];
2208}
2209
2210def DocCatConsumed : DocumentationCategory<"Consumed Annotation Checking"> {
2211  let Content = [{
2212Clang supports additional attributes for checking basic resource management
2213properties, specifically for unique objects that have a single owning reference.
2214The following attributes are currently supported, although **the implementation
2215for these annotations is currently in development and are subject to change.**
2216  }];
2217}
2218
2219def SetTypestateDocs : Documentation {
2220  let Category = DocCatConsumed;
2221  let Content = [{
2222Annotate methods that transition an object into a new state with
2223``__attribute__((set_typestate(new_state)))``.  The new state must be
2224unconsumed, consumed, or unknown.
2225  }];
2226}
2227
2228def CallableWhenDocs : Documentation {
2229  let Category = DocCatConsumed;
2230  let Content = [{
2231Use ``__attribute__((callable_when(...)))`` to indicate what states a method
2232may be called in.  Valid states are unconsumed, consumed, or unknown.  Each
2233argument to this attribute must be a quoted string.  E.g.:
2234
2235``__attribute__((callable_when("unconsumed", "unknown")))``
2236  }];
2237}
2238
2239def TestTypestateDocs : Documentation {
2240  let Category = DocCatConsumed;
2241  let Content = [{
2242Use ``__attribute__((test_typestate(tested_state)))`` to indicate that a method
2243returns true if the object is in the specified state..
2244  }];
2245}
2246
2247def ParamTypestateDocs : Documentation {
2248  let Category = DocCatConsumed;
2249  let Content = [{
2250This attribute specifies expectations about function parameters.  Calls to an
2251function with annotated parameters will issue a warning if the corresponding
2252argument isn't in the expected state.  The attribute is also used to set the
2253initial state of the parameter when analyzing the function's body.
2254  }];
2255}
2256
2257def ReturnTypestateDocs : Documentation {
2258  let Category = DocCatConsumed;
2259  let Content = [{
2260The ``return_typestate`` attribute can be applied to functions or parameters.
2261When applied to a function the attribute specifies the state of the returned
2262value.  The function's body is checked to ensure that it always returns a value
2263in the specified state.  On the caller side, values returned by the annotated
2264function are initialized to the given state.
2265
2266When applied to a function parameter it modifies the state of an argument after
2267a call to the function returns.  The function's body is checked to ensure that
2268the parameter is in the expected state before returning.
2269  }];
2270}
2271
2272def ConsumableDocs : Documentation {
2273  let Category = DocCatConsumed;
2274  let Content = [{
2275Each ``class`` that uses any of the typestate annotations must first be marked
2276using the ``consumable`` attribute.  Failure to do so will result in a warning.
2277
2278This attribute accepts a single parameter that must be one of the following:
2279``unknown``, ``consumed``, or ``unconsumed``.
2280  }];
2281}
2282
2283def NoSanitizeDocs : Documentation {
2284  let Category = DocCatFunction;
2285  let Content = [{
2286Use the ``no_sanitize`` attribute on a function or a global variable
2287declaration to specify that a particular instrumentation or set of
2288instrumentations should not be applied. The attribute takes a list of
2289string literals, which have the same meaning as values accepted by the
2290``-fno-sanitize=`` flag. For example,
2291``__attribute__((no_sanitize("address", "thread")))`` specifies that
2292AddressSanitizer and ThreadSanitizer should not be applied to the
2293function or variable.
2294
2295See :ref:`Controlling Code Generation <controlling-code-generation>` for a
2296full list of supported sanitizer flags.
2297  }];
2298}
2299
2300def NoSanitizeAddressDocs : Documentation {
2301  let Category = DocCatFunction;
2302  // This function has multiple distinct spellings, and so it requires a custom
2303  // heading to be specified. The most common spelling is sufficient.
2304  let Heading = "no_sanitize_address, no_address_safety_analysis";
2305  let Content = [{
2306.. _langext-address_sanitizer:
2307
2308Use ``__attribute__((no_sanitize_address))`` on a function or a global
2309variable declaration to specify that address safety instrumentation
2310(e.g. AddressSanitizer) should not be applied.
2311  }];
2312}
2313
2314def NoSanitizeThreadDocs : Documentation {
2315  let Category = DocCatFunction;
2316  let Heading = "no_sanitize_thread";
2317  let Content = [{
2318.. _langext-thread_sanitizer:
2319
2320Use ``__attribute__((no_sanitize_thread))`` on a function declaration to
2321specify that checks for data races on plain (non-atomic) memory accesses should
2322not be inserted by ThreadSanitizer. The function is still instrumented by the
2323tool to avoid false positives and provide meaningful stack traces.
2324  }];
2325}
2326
2327def NoSanitizeMemoryDocs : Documentation {
2328  let Category = DocCatFunction;
2329  let Heading = "no_sanitize_memory";
2330  let Content = [{
2331.. _langext-memory_sanitizer:
2332
2333Use ``__attribute__((no_sanitize_memory))`` on a function declaration to
2334specify that checks for uninitialized memory should not be inserted
2335(e.g. by MemorySanitizer). The function may still be instrumented by the tool
2336to avoid false positives in other places.
2337  }];
2338}
2339
2340def CFICanonicalJumpTableDocs : Documentation {
2341  let Category = DocCatFunction;
2342  let Heading = "cfi_canonical_jump_table";
2343  let Content = [{
2344.. _langext-cfi_canonical_jump_table:
2345
2346Use ``__attribute__((cfi_canonical_jump_table))`` on a function declaration to
2347make the function's CFI jump table canonical. See :ref:`the CFI documentation
2348<cfi-canonical-jump-tables>` for more details.
2349  }];
2350}
2351
2352def DocCatTypeSafety : DocumentationCategory<"Type Safety Checking"> {
2353  let Content = [{
2354Clang supports additional attributes to enable checking type safety properties
2355that can't be enforced by the C type system. To see warnings produced by these
2356checks, ensure that -Wtype-safety is enabled. Use cases include:
2357
2358* MPI library implementations, where these attributes enable checking that
2359  the buffer type matches the passed ``MPI_Datatype``;
2360* for HDF5 library there is a similar use case to MPI;
2361* checking types of variadic functions' arguments for functions like
2362  ``fcntl()`` and ``ioctl()``.
2363
2364You can detect support for these attributes with ``__has_attribute()``.  For
2365example:
2366
2367.. code-block:: c++
2368
2369  #if defined(__has_attribute)
2370  #  if __has_attribute(argument_with_type_tag) && \
2371        __has_attribute(pointer_with_type_tag) && \
2372        __has_attribute(type_tag_for_datatype)
2373  #    define ATTR_MPI_PWT(buffer_idx, type_idx) __attribute__((pointer_with_type_tag(mpi,buffer_idx,type_idx)))
2374  /* ... other macros ...  */
2375  #  endif
2376  #endif
2377
2378  #if !defined(ATTR_MPI_PWT)
2379  # define ATTR_MPI_PWT(buffer_idx, type_idx)
2380  #endif
2381
2382  int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */)
2383      ATTR_MPI_PWT(1,3);
2384  }];
2385}
2386
2387def ArgumentWithTypeTagDocs : Documentation {
2388  let Category = DocCatTypeSafety;
2389  let Heading = "argument_with_type_tag";
2390  let Content = [{
2391Use ``__attribute__((argument_with_type_tag(arg_kind, arg_idx,
2392type_tag_idx)))`` on a function declaration to specify that the function
2393accepts a type tag that determines the type of some other argument.
2394
2395This attribute is primarily useful for checking arguments of variadic functions
2396(``pointer_with_type_tag`` can be used in most non-variadic cases).
2397
2398In the attribute prototype above:
2399  * ``arg_kind`` is an identifier that should be used when annotating all
2400    applicable type tags.
2401  * ``arg_idx`` provides the position of a function argument. The expected type of
2402    this function argument will be determined by the function argument specified
2403    by ``type_tag_idx``. In the code example below, "3" means that the type of the
2404    function's third argument will be determined by ``type_tag_idx``.
2405  * ``type_tag_idx`` provides the position of a function argument. This function
2406    argument will be a type tag. The type tag will determine the expected type of
2407    the argument specified by ``arg_idx``. In the code example below, "2" means
2408    that the type tag associated with the function's second argument should agree
2409    with the type of the argument specified by ``arg_idx``.
2410
2411For example:
2412
2413.. code-block:: c++
2414
2415  int fcntl(int fd, int cmd, ...)
2416      __attribute__(( argument_with_type_tag(fcntl,3,2) ));
2417  // The function's second argument will be a type tag; this type tag will
2418  // determine the expected type of the function's third argument.
2419  }];
2420}
2421
2422def PointerWithTypeTagDocs : Documentation {
2423  let Category = DocCatTypeSafety;
2424  let Heading = "pointer_with_type_tag";
2425  let Content = [{
2426Use ``__attribute__((pointer_with_type_tag(ptr_kind, ptr_idx, type_tag_idx)))``
2427on a function declaration to specify that the function accepts a type tag that
2428determines the pointee type of some other pointer argument.
2429
2430In the attribute prototype above:
2431  * ``ptr_kind`` is an identifier that should be used when annotating all
2432    applicable type tags.
2433  * ``ptr_idx`` provides the position of a function argument; this function
2434    argument will have a pointer type. The expected pointee type of this pointer
2435    type will be determined by the function argument specified by
2436    ``type_tag_idx``. In the code example below, "1" means that the pointee type
2437    of the function's first argument will be determined by ``type_tag_idx``.
2438  * ``type_tag_idx`` provides the position of a function argument; this function
2439    argument will be a type tag. The type tag will determine the expected pointee
2440    type of the pointer argument specified by ``ptr_idx``. In the code example
2441    below, "3" means that the type tag associated with the function's third
2442    argument should agree with the pointee type of the pointer argument specified
2443    by ``ptr_idx``.
2444
2445For example:
2446
2447.. code-block:: c++
2448
2449  typedef int MPI_Datatype;
2450  int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */)
2451      __attribute__(( pointer_with_type_tag(mpi,1,3) ));
2452  // The function's 3rd argument will be a type tag; this type tag will
2453  // determine the expected pointee type of the function's 1st argument.
2454  }];
2455}
2456
2457def TypeTagForDatatypeDocs : Documentation {
2458  let Category = DocCatTypeSafety;
2459  let Content = [{
2460When declaring a variable, use
2461``__attribute__((type_tag_for_datatype(kind, type)))`` to create a type tag that
2462is tied to the ``type`` argument given to the attribute.
2463
2464In the attribute prototype above:
2465  * ``kind`` is an identifier that should be used when annotating all applicable
2466    type tags.
2467  * ``type`` indicates the name of the type.
2468
2469Clang supports annotating type tags of two forms.
2470
2471  * **Type tag that is a reference to a declared identifier.**
2472    Use ``__attribute__((type_tag_for_datatype(kind, type)))`` when declaring that
2473    identifier:
2474
2475    .. code-block:: c++
2476
2477      typedef int MPI_Datatype;
2478      extern struct mpi_datatype mpi_datatype_int
2479          __attribute__(( type_tag_for_datatype(mpi,int) ));
2480      #define MPI_INT ((MPI_Datatype) &mpi_datatype_int)
2481      // &mpi_datatype_int is a type tag. It is tied to type "int".
2482
2483  * **Type tag that is an integral literal.**
2484    Declare a ``static const`` variable with an initializer value and attach
2485    ``__attribute__((type_tag_for_datatype(kind, type)))`` on that declaration:
2486
2487    .. code-block:: c++
2488
2489      typedef int MPI_Datatype;
2490      static const MPI_Datatype mpi_datatype_int
2491          __attribute__(( type_tag_for_datatype(mpi,int) )) = 42;
2492      #define MPI_INT ((MPI_Datatype) 42)
2493      // The number 42 is a type tag. It is tied to type "int".
2494
2495
2496The ``type_tag_for_datatype`` attribute also accepts an optional third argument
2497that determines how the type of the function argument specified by either
2498``arg_idx`` or ``ptr_idx`` is compared against the type associated with the type
2499tag. (Recall that for the ``argument_with_type_tag`` attribute, the type of the
2500function argument specified by ``arg_idx`` is compared against the type
2501associated with the type tag. Also recall that for the ``pointer_with_type_tag``
2502attribute, the pointee type of the function argument specified by ``ptr_idx`` is
2503compared against the type associated with the type tag.) There are two supported
2504values for this optional third argument:
2505
2506  * ``layout_compatible`` will cause types to be compared according to
2507    layout-compatibility rules (In C++11 [class.mem] p 17, 18, see the
2508    layout-compatibility rules for two standard-layout struct types and for two
2509    standard-layout union types). This is useful when creating a type tag
2510    associated with a struct or union type. For example:
2511
2512    .. code-block:: c++
2513
2514      /* In mpi.h */
2515      typedef int MPI_Datatype;
2516      struct internal_mpi_double_int { double d; int i; };
2517      extern struct mpi_datatype mpi_datatype_double_int
2518          __attribute__(( type_tag_for_datatype(mpi,
2519                          struct internal_mpi_double_int, layout_compatible) ));
2520
2521      #define MPI_DOUBLE_INT ((MPI_Datatype) &mpi_datatype_double_int)
2522
2523      int MPI_Send(void *buf, int count, MPI_Datatype datatype, ...)
2524          __attribute__(( pointer_with_type_tag(mpi,1,3) ));
2525
2526      /* In user code */
2527      struct my_pair { double a; int b; };
2528      struct my_pair *buffer;
2529      MPI_Send(buffer, 1, MPI_DOUBLE_INT /*, ...  */); // no warning because the
2530                                                       // layout of my_pair is
2531                                                       // compatible with that of
2532                                                       // internal_mpi_double_int
2533
2534      struct my_int_pair { int a; int b; }
2535      struct my_int_pair *buffer2;
2536      MPI_Send(buffer2, 1, MPI_DOUBLE_INT /*, ...  */); // warning because the
2537                                                        // layout of my_int_pair
2538                                                        // does not match that of
2539                                                        // internal_mpi_double_int
2540
2541  * ``must_be_null`` specifies that the function argument specified by either
2542    ``arg_idx`` (for the ``argument_with_type_tag`` attribute) or ``ptr_idx`` (for
2543    the ``pointer_with_type_tag`` attribute) should be a null pointer constant.
2544    The second argument to the ``type_tag_for_datatype`` attribute is ignored. For
2545    example:
2546
2547    .. code-block:: c++
2548
2549      /* In mpi.h */
2550      typedef int MPI_Datatype;
2551      extern struct mpi_datatype mpi_datatype_null
2552          __attribute__(( type_tag_for_datatype(mpi, void, must_be_null) ));
2553
2554      #define MPI_DATATYPE_NULL ((MPI_Datatype) &mpi_datatype_null)
2555      int MPI_Send(void *buf, int count, MPI_Datatype datatype, ...)
2556          __attribute__(( pointer_with_type_tag(mpi,1,3) ));
2557
2558      /* In user code */
2559      struct my_pair { double a; int b; };
2560      struct my_pair *buffer;
2561      MPI_Send(buffer, 1, MPI_DATATYPE_NULL /*, ...  */); // warning: MPI_DATATYPE_NULL
2562                                                          // was specified but buffer
2563                                                          // is not a null pointer
2564  }];
2565}
2566
2567def FlattenDocs : Documentation {
2568  let Category = DocCatFunction;
2569  let Content = [{
2570The ``flatten`` attribute causes calls within the attributed function to
2571be inlined unless it is impossible to do so, for example if the body of the
2572callee is unavailable or if the callee has the ``noinline`` attribute.
2573  }];
2574}
2575
2576def FormatDocs : Documentation {
2577  let Category = DocCatFunction;
2578  let Content = [{
2579
2580Clang supports the ``format`` attribute, which indicates that the function
2581accepts a ``printf`` or ``scanf``-like format string and corresponding
2582arguments or a ``va_list`` that contains these arguments.
2583
2584Please see `GCC documentation about format attribute
2585<http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>`_ to find details
2586about attribute syntax.
2587
2588Clang implements two kinds of checks with this attribute.
2589
2590#. Clang checks that the function with the ``format`` attribute is called with
2591   a format string that uses format specifiers that are allowed, and that
2592   arguments match the format string.  This is the ``-Wformat`` warning, it is
2593   on by default.
2594
2595#. Clang checks that the format string argument is a literal string.  This is
2596   the ``-Wformat-nonliteral`` warning, it is off by default.
2597
2598   Clang implements this mostly the same way as GCC, but there is a difference
2599   for functions that accept a ``va_list`` argument (for example, ``vprintf``).
2600   GCC does not emit ``-Wformat-nonliteral`` warning for calls to such
2601   functions.  Clang does not warn if the format string comes from a function
2602   parameter, where the function is annotated with a compatible attribute,
2603   otherwise it warns.  For example:
2604
2605   .. code-block:: c
2606
2607     __attribute__((__format__ (__scanf__, 1, 3)))
2608     void foo(const char* s, char *buf, ...) {
2609       va_list ap;
2610       va_start(ap, buf);
2611
2612       vprintf(s, ap); // warning: format string is not a string literal
2613     }
2614
2615   In this case we warn because ``s`` contains a format string for a
2616   ``scanf``-like function, but it is passed to a ``printf``-like function.
2617
2618   If the attribute is removed, clang still warns, because the format string is
2619   not a string literal.
2620
2621   Another example:
2622
2623   .. code-block:: c
2624
2625     __attribute__((__format__ (__printf__, 1, 3)))
2626     void foo(const char* s, char *buf, ...) {
2627       va_list ap;
2628       va_start(ap, buf);
2629
2630       vprintf(s, ap); // warning
2631     }
2632
2633   In this case Clang does not warn because the format string ``s`` and
2634   the corresponding arguments are annotated.  If the arguments are
2635   incorrect, the caller of ``foo`` will receive a warning.
2636  }];
2637}
2638
2639def AlignValueDocs : Documentation {
2640  let Category = DocCatType;
2641  let Content = [{
2642The align_value attribute can be added to the typedef of a pointer type or the
2643declaration of a variable of pointer or reference type. It specifies that the
2644pointer will point to, or the reference will bind to, only objects with at
2645least the provided alignment. This alignment value must be some positive power
2646of 2.
2647
2648   .. code-block:: c
2649
2650     typedef double * aligned_double_ptr __attribute__((align_value(64)));
2651     void foo(double & x  __attribute__((align_value(128)),
2652              aligned_double_ptr y) { ... }
2653
2654If the pointer value does not have the specified alignment at runtime, the
2655behavior of the program is undefined.
2656  }];
2657}
2658
2659def FlagEnumDocs : Documentation {
2660  let Category = DocCatDecl;
2661  let Content = [{
2662This attribute can be added to an enumerator to signal to the compiler that it
2663is intended to be used as a flag type. This will cause the compiler to assume
2664that the range of the type includes all of the values that you can get by
2665manipulating bits of the enumerator when issuing warnings.
2666  }];
2667}
2668
2669def AsmLabelDocs : Documentation {
2670  let Category = DocCatDecl;
2671  let Content = [{
2672This attribute can be used on a function or variable to specify its symbol name.
2673
2674On some targets, all C symbols are prefixed by default with a single character, typically ``_``.  This was done historically to distinguish them from symbols used by other languages.  (This prefix is also added to the standard Itanium C++ ABI prefix on "mangled" symbol names, so that e.g. on such targets the true symbol name for a C++ variable declared as ``int cppvar;`` would be ``__Z6cppvar``; note the two underscores.)  This prefix is *not* added to the symbol names specified by the ``asm`` attribute; programmers wishing to match a C symbol name must compensate for this.
2675
2676For example, consider the following C code:
2677
2678.. code-block:: c
2679
2680  int var1 asm("altvar") = 1;  // "altvar" in symbol table.
2681  int var2 = 1; // "_var2" in symbol table.
2682
2683  void func1(void) asm("altfunc");
2684  void func1(void) {} // "altfunc" in symbol table.
2685  void func2(void) {} // "_func2" in symbol table.
2686
2687Clang's implementation of this attribute is compatible with GCC's, `documented here <https://gcc.gnu.org/onlinedocs/gcc/Asm-Labels.html>`_.
2688
2689While it is possible to use this attribute to name a special symbol used internally by the compiler, such as an LLVM intrinsic, this is neither recommended nor supported and may cause the compiler to crash or miscompile.  Users who wish to gain access to intrinsic behavior are strongly encouraged to request new builtin functions.
2690  }];
2691}
2692
2693def EnumExtensibilityDocs : Documentation {
2694  let Category = DocCatDecl;
2695  let Content = [{
2696Attribute ``enum_extensibility`` is used to distinguish between enum definitions
2697that are extensible and those that are not. The attribute can take either
2698``closed`` or ``open`` as an argument. ``closed`` indicates a variable of the
2699enum type takes a value that corresponds to one of the enumerators listed in the
2700enum definition or, when the enum is annotated with ``flag_enum``, a value that
2701can be constructed using values corresponding to the enumerators. ``open``
2702indicates a variable of the enum type can take any values allowed by the
2703standard and instructs clang to be more lenient when issuing warnings.
2704
2705.. code-block:: c
2706
2707  enum __attribute__((enum_extensibility(closed))) ClosedEnum {
2708    A0, A1
2709  };
2710
2711  enum __attribute__((enum_extensibility(open))) OpenEnum {
2712    B0, B1
2713  };
2714
2715  enum __attribute__((enum_extensibility(closed),flag_enum)) ClosedFlagEnum {
2716    C0 = 1 << 0, C1 = 1 << 1
2717  };
2718
2719  enum __attribute__((enum_extensibility(open),flag_enum)) OpenFlagEnum {
2720    D0 = 1 << 0, D1 = 1 << 1
2721  };
2722
2723  void foo1() {
2724    enum ClosedEnum ce;
2725    enum OpenEnum oe;
2726    enum ClosedFlagEnum cfe;
2727    enum OpenFlagEnum ofe;
2728
2729    ce = A1;           // no warnings
2730    ce = 100;          // warning issued
2731    oe = B1;           // no warnings
2732    oe = 100;          // no warnings
2733    cfe = C0 | C1;     // no warnings
2734    cfe = C0 | C1 | 4; // warning issued
2735    ofe = D0 | D1;     // no warnings
2736    ofe = D0 | D1 | 4; // no warnings
2737  }
2738
2739  }];
2740}
2741
2742def EmptyBasesDocs : Documentation {
2743  let Category = DocCatDecl;
2744  let Content = [{
2745The empty_bases attribute permits the compiler to utilize the
2746empty-base-optimization more frequently.
2747This attribute only applies to struct, class, and union types.
2748It is only supported when using the Microsoft C++ ABI.
2749  }];
2750}
2751
2752def LayoutVersionDocs : Documentation {
2753  let Category = DocCatDecl;
2754  let Content = [{
2755The layout_version attribute requests that the compiler utilize the class
2756layout rules of a particular compiler version.
2757This attribute only applies to struct, class, and union types.
2758It is only supported when using the Microsoft C++ ABI.
2759  }];
2760}
2761
2762def LifetimeBoundDocs : Documentation {
2763  let Category = DocCatFunction;
2764  let Content = [{
2765The ``lifetimebound`` attribute indicates that a resource owned by
2766a function parameter or implicit object parameter
2767is retained by the return value of the annotated function
2768(or, for a parameter of a constructor, in the value of the constructed object).
2769It is only supported in C++.
2770
2771This attribute provides an experimental implementation of the facility
2772described in the C++ committee paper `P0936R0 <http://wg21.link/p0936r0>`_,
2773and is subject to change as the design of the corresponding functionality
2774changes.
2775  }];
2776}
2777
2778def TrivialABIDocs : Documentation {
2779  let Category = DocCatDecl;
2780  let Content = [{
2781The ``trivial_abi`` attribute can be applied to a C++ class, struct, or union.
2782It instructs the compiler to pass and return the type using the C ABI for the
2783underlying type when the type would otherwise be considered non-trivial for the
2784purpose of calls.
2785A class annotated with ``trivial_abi`` can have non-trivial destructors or
2786copy/move constructors without automatically becoming non-trivial for the
2787purposes of calls. For example:
2788
2789  .. code-block:: c++
2790
2791    // A is trivial for the purposes of calls because ``trivial_abi`` makes the
2792    // user-provided special functions trivial.
2793    struct __attribute__((trivial_abi)) A {
2794      ~A();
2795      A(const A &);
2796      A(A &&);
2797      int x;
2798    };
2799
2800    // B's destructor and copy/move constructor are considered trivial for the
2801    // purpose of calls because A is trivial.
2802    struct B {
2803      A a;
2804    };
2805
2806If a type is trivial for the purposes of calls, has a non-trivial destructor,
2807and is passed as an argument by value, the convention is that the callee will
2808destroy the object before returning.
2809
2810Attribute ``trivial_abi`` has no effect in the following cases:
2811
2812- The class directly declares a virtual base or virtual methods.
2813- Copy constructors and move constructors of the class are all deleted.
2814- The class has a base class that is non-trivial for the purposes of calls.
2815- The class has a non-static data member whose type is non-trivial for the purposes of calls, which includes:
2816
2817  - classes that are non-trivial for the purposes of calls
2818  - __weak-qualified types in Objective-C++
2819  - arrays of any of the above
2820  }];
2821}
2822
2823def MSInheritanceDocs : Documentation {
2824  let Category = DocCatDecl;
2825  let Heading = "__single_inhertiance, __multiple_inheritance, __virtual_inheritance";
2826  let Content = [{
2827This collection of keywords is enabled under ``-fms-extensions`` and controls
2828the pointer-to-member representation used on ``*-*-win32`` targets.
2829
2830The ``*-*-win32`` targets utilize a pointer-to-member representation which
2831varies in size and alignment depending on the definition of the underlying
2832class.
2833
2834However, this is problematic when a forward declaration is only available and
2835no definition has been made yet.  In such cases, Clang is forced to utilize the
2836most general representation that is available to it.
2837
2838These keywords make it possible to use a pointer-to-member representation other
2839than the most general one regardless of whether or not the definition will ever
2840be present in the current translation unit.
2841
2842This family of keywords belong between the ``class-key`` and ``class-name``:
2843
2844.. code-block:: c++
2845
2846  struct __single_inheritance S;
2847  int S::*i;
2848  struct S {};
2849
2850This keyword can be applied to class templates but only has an effect when used
2851on full specializations:
2852
2853.. code-block:: c++
2854
2855  template <typename T, typename U> struct __single_inheritance A; // warning: inheritance model ignored on primary template
2856  template <typename T> struct __multiple_inheritance A<T, T>; // warning: inheritance model ignored on partial specialization
2857  template <> struct __single_inheritance A<int, float>;
2858
2859Note that choosing an inheritance model less general than strictly necessary is
2860an error:
2861
2862.. code-block:: c++
2863
2864  struct __multiple_inheritance S; // error: inheritance model does not match definition
2865  int S::*i;
2866  struct S {};
2867}];
2868}
2869
2870def MSNoVTableDocs : Documentation {
2871  let Category = DocCatDecl;
2872  let Content = [{
2873This attribute can be added to a class declaration or definition to signal to
2874the compiler that constructors and destructors will not reference the virtual
2875function table. It is only supported when using the Microsoft C++ ABI.
2876  }];
2877}
2878
2879def OptnoneDocs : Documentation {
2880  let Category = DocCatFunction;
2881  let Content = [{
2882The ``optnone`` attribute suppresses essentially all optimizations
2883on a function or method, regardless of the optimization level applied to
2884the compilation unit as a whole.  This is particularly useful when you
2885need to debug a particular function, but it is infeasible to build the
2886entire application without optimization.  Avoiding optimization on the
2887specified function can improve the quality of the debugging information
2888for that function.
2889
2890This attribute is incompatible with the ``always_inline`` and ``minsize``
2891attributes.
2892  }];
2893}
2894
2895def LoopHintDocs : Documentation {
2896  let Category = DocCatStmt;
2897  let Heading = "#pragma clang loop";
2898  let Content = [{
2899The ``#pragma clang loop`` directive allows loop optimization hints to be
2900specified for the subsequent loop. The directive allows pipelining to be
2901disabled, or vectorization, vector predication, interleaving, and unrolling to
2902be enabled or disabled. Vector width, vector predication, interleave count,
2903unrolling count, and the initiation interval for pipelining can be explicitly
2904specified. See `language extensions
2905<http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations>`_
2906for details.
2907  }];
2908}
2909
2910def UnrollHintDocs : Documentation {
2911  let Category = DocCatStmt;
2912  let Heading = "#pragma unroll, #pragma nounroll";
2913  let Content = [{
2914Loop unrolling optimization hints can be specified with ``#pragma unroll`` and
2915``#pragma nounroll``. The pragma is placed immediately before a for, while,
2916do-while, or c++11 range-based for loop.
2917
2918Specifying ``#pragma unroll`` without a parameter directs the loop unroller to
2919attempt to fully unroll the loop if the trip count is known at compile time and
2920attempt to partially unroll the loop if the trip count is not known at compile
2921time:
2922
2923.. code-block:: c++
2924
2925  #pragma unroll
2926  for (...) {
2927    ...
2928  }
2929
2930Specifying the optional parameter, ``#pragma unroll _value_``, directs the
2931unroller to unroll the loop ``_value_`` times.  The parameter may optionally be
2932enclosed in parentheses:
2933
2934.. code-block:: c++
2935
2936  #pragma unroll 16
2937  for (...) {
2938    ...
2939  }
2940
2941  #pragma unroll(16)
2942  for (...) {
2943    ...
2944  }
2945
2946Specifying ``#pragma nounroll`` indicates that the loop should not be unrolled:
2947
2948.. code-block:: c++
2949
2950  #pragma nounroll
2951  for (...) {
2952    ...
2953  }
2954
2955``#pragma unroll`` and ``#pragma unroll _value_`` have identical semantics to
2956``#pragma clang loop unroll(full)`` and
2957``#pragma clang loop unroll_count(_value_)`` respectively. ``#pragma nounroll``
2958is equivalent to ``#pragma clang loop unroll(disable)``.  See
2959`language extensions
2960<http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations>`_
2961for further details including limitations of the unroll hints.
2962  }];
2963}
2964
2965def PipelineHintDocs : Documentation {
2966  let Category = DocCatStmt;
2967  let Heading = "#pragma clang loop pipeline, #pragma clang loop pipeline_initiation_interval";
2968  let Content = [{
2969    Software Pipelining optimization is a technique used to optimize loops by
2970  utilizing instruction-level parallelism. It reorders loop instructions to
2971  overlap iterations. As a result, the next iteration starts before the previous
2972  iteration has finished. The module scheduling technique creates a schedule for
2973  one iteration such that when repeating at regular intervals, no inter-iteration
2974  dependencies are violated. This constant interval(in cycles) between the start
2975  of iterations is called the initiation interval. i.e. The initiation interval
2976  is the number of cycles between two iterations of an unoptimized loop in the
2977  newly created schedule. A new, optimized loop is created such that a single iteration
2978  of the loop executes in the same number of cycles as the initiation interval.
2979    For further details see <https://llvm.org/pubs/2005-06-17-LattnerMSThesis-book.pdf>.
2980
2981  ``#pragma clang loop pipeline and #pragma loop pipeline_initiation_interval``
2982  could be used as hints for the software pipelining optimization. The pragma is
2983  placed immediately before a for, while, do-while, or a C++11 range-based for
2984  loop.
2985
2986  Using ``#pragma clang loop pipeline(disable)`` avoids the software pipelining
2987  optimization. The disable state can only be specified:
2988
2989  .. code-block:: c++
2990
2991  #pragma clang loop pipeline(disable)
2992  for (...) {
2993    ...
2994  }
2995
2996  Using ``#pragma loop pipeline_initiation_interval`` instructs
2997  the software pipeliner to try the specified initiation interval.
2998  If a schedule was found then the resulting loop iteration would have
2999  the specified cycle count. If a schedule was not found then loop
3000  remains unchanged. The initiation interval must be a positive number
3001  greater than zero:
3002
3003  .. code-block:: c++
3004
3005  #pragma loop pipeline_initiation_interval(10)
3006  for (...) {
3007    ...
3008  }
3009
3010  }];
3011}
3012
3013def OpenCLUnrollHintDocs : Documentation {
3014  let Category = DocCatStmt;
3015  let Content = [{
3016The opencl_unroll_hint attribute qualifier can be used to specify that a loop
3017(for, while and do loops) can be unrolled. This attribute qualifier can be
3018used to specify full unrolling or partial unrolling by a specified amount.
3019This is a compiler hint and the compiler may ignore this directive. See
3020`OpenCL v2.0 <https://www.khronos.org/registry/cl/specs/opencl-2.0.pdf>`_
3021s6.11.5 for details.
3022  }];
3023}
3024
3025def OpenCLIntelReqdSubGroupSizeDocs : Documentation {
3026  let Category = DocCatStmt;
3027  let Content = [{
3028The optional attribute intel_reqd_sub_group_size can be used to indicate that
3029the kernel must be compiled and executed with the specified subgroup size. When
3030this attribute is present, get_max_sub_group_size() is guaranteed to return the
3031specified integer value. This is important for the correctness of many subgroup
3032algorithms, and in some cases may be used by the compiler to generate more optimal
3033code. See `cl_intel_required_subgroup_size
3034<https://www.khronos.org/registry/OpenCL/extensions/intel/cl_intel_required_subgroup_size.txt>`
3035for details.
3036  }];
3037}
3038
3039def OpenCLAccessDocs : Documentation {
3040  let Category = DocCatStmt;
3041  let Heading = "__read_only, __write_only, __read_write (read_only, write_only, read_write)";
3042  let Content = [{
3043The access qualifiers must be used with image object arguments or pipe arguments
3044to declare if they are being read or written by a kernel or function.
3045
3046The read_only/__read_only, write_only/__write_only and read_write/__read_write
3047names are reserved for use as access qualifiers and shall not be used otherwise.
3048
3049.. code-block:: c
3050
3051  kernel void
3052  foo (read_only image2d_t imageA,
3053       write_only image2d_t imageB) {
3054    ...
3055  }
3056
3057In the above example imageA is a read-only 2D image object, and imageB is a
3058write-only 2D image object.
3059
3060The read_write (or __read_write) qualifier can not be used with pipe.
3061
3062More details can be found in the OpenCL C language Spec v2.0, Section 6.6.
3063    }];
3064}
3065
3066def DocOpenCLAddressSpaces : DocumentationCategory<"OpenCL Address Spaces"> {
3067  let Content = [{
3068The address space qualifier may be used to specify the region of memory that is
3069used to allocate the object. OpenCL supports the following address spaces:
3070__generic(generic), __global(global), __local(local), __private(private),
3071__constant(constant).
3072
3073  .. code-block:: c
3074
3075    __constant int c = ...;
3076
3077    __generic int* foo(global int* g) {
3078      __local int* l;
3079      private int p;
3080      ...
3081      return l;
3082    }
3083
3084More details can be found in the OpenCL C language Spec v2.0, Section 6.5.
3085  }];
3086}
3087
3088def OpenCLAddressSpaceGenericDocs : Documentation {
3089  let Category = DocOpenCLAddressSpaces;
3090  let Heading = "__generic, generic, [[clang::opencl_generic]]";
3091  let Content = [{
3092The generic address space attribute is only available with OpenCL v2.0 and later.
3093It can be used with pointer types. Variables in global and local scope and
3094function parameters in non-kernel functions can have the generic address space
3095type attribute. It is intended to be a placeholder for any other address space
3096except for '__constant' in OpenCL code which can be used with multiple address
3097spaces.
3098  }];
3099}
3100
3101def OpenCLAddressSpaceConstantDocs : Documentation {
3102  let Category = DocOpenCLAddressSpaces;
3103  let Heading = "__constant, constant, [[clang::opencl_constant]]";
3104  let Content = [{
3105The constant address space attribute signals that an object is located in
3106a constant (non-modifiable) memory region. It is available to all work items.
3107Any type can be annotated with the constant address space attribute. Objects
3108with the constant address space qualifier can be declared in any scope and must
3109have an initializer.
3110  }];
3111}
3112
3113def OpenCLAddressSpaceGlobalDocs : Documentation {
3114  let Category = DocOpenCLAddressSpaces;
3115  let Heading = "__global, global, [[clang::opencl_global]]";
3116  let Content = [{
3117The global address space attribute specifies that an object is allocated in
3118global memory, which is accessible by all work items. The content stored in this
3119memory area persists between kernel executions. Pointer types to the global
3120address space are allowed as function parameters or local variables. Starting
3121with OpenCL v2.0, the global address space can be used with global (program
3122scope) variables and static local variable as well.
3123  }];
3124}
3125
3126def OpenCLAddressSpaceLocalDocs : Documentation {
3127  let Category = DocOpenCLAddressSpaces;
3128  let Heading = "__local, local, [[clang::opencl_local]]";
3129  let Content = [{
3130The local address space specifies that an object is allocated in the local (work
3131group) memory area, which is accessible to all work items in the same work
3132group. The content stored in this memory region is not accessible after
3133the kernel execution ends. In a kernel function scope, any variable can be in
3134the local address space. In other scopes, only pointer types to the local address
3135space are allowed. Local address space variables cannot have an initializer.
3136  }];
3137}
3138
3139def OpenCLAddressSpacePrivateDocs : Documentation {
3140  let Category = DocOpenCLAddressSpaces;
3141  let Heading = "__private, private, [[clang::opencl_private]]";
3142  let Content = [{
3143The private address space specifies that an object is allocated in the private
3144(work item) memory. Other work items cannot access the same memory area and its
3145content is destroyed after work item execution ends. Local variables can be
3146declared in the private address space. Function arguments are always in the
3147private address space. Kernel function arguments of a pointer or an array type
3148cannot point to the private address space.
3149  }];
3150}
3151
3152def OpenCLNoSVMDocs : Documentation {
3153  let Category = DocCatVariable;
3154  let Content = [{
3155OpenCL 2.0 supports the optional ``__attribute__((nosvm))`` qualifier for
3156pointer variable. It informs the compiler that the pointer does not refer
3157to a shared virtual memory region. See OpenCL v2.0 s6.7.2 for details.
3158
3159Since it is not widely used and has been removed from OpenCL 2.1, it is ignored
3160by Clang.
3161  }];
3162}
3163
3164def Ptr32Docs : Documentation {
3165  let Category = DocCatType;
3166  let Content = [{
3167The ``__ptr32`` qualifier represents a native pointer on a 32-bit system. On a
316864-bit system, a pointer with ``__ptr32`` is extended to a 64-bit pointer. The
3169``__sptr`` and ``__uptr`` qualifiers can be used to specify whether the pointer
3170is sign extended or zero extended. This qualifier is enabled under
3171``-fms-extensions``.
3172  }];
3173}
3174
3175def Ptr64Docs : Documentation {
3176  let Category = DocCatType;
3177  let Content = [{
3178The ``__ptr64`` qualifier represents a native pointer on a 64-bit system. On a
317932-bit system, a ``__ptr64`` pointer is truncated to a 32-bit pointer. This
3180qualifier is enabled under ``-fms-extensions``.
3181  }];
3182}
3183
3184def SPtrDocs : Documentation {
3185  let Category = DocCatType;
3186  let Content = [{
3187The ``__sptr`` qualifier specifies that a 32-bit pointer should be sign
3188extended when converted to a 64-bit pointer.
3189  }];
3190}
3191
3192def UPtrDocs : Documentation {
3193  let Category = DocCatType;
3194  let Content = [{
3195The ``__uptr`` qualifier specifies that a 32-bit pointer should be zero
3196extended when converted to a 64-bit pointer.
3197  }];
3198}
3199
3200
3201def NullabilityDocs : DocumentationCategory<"Nullability Attributes"> {
3202  let Content = [{
3203Whether 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``).
3204
3205The 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:
3206
3207  .. code-block:: c
3208
3209    // No meaningful result when 'ptr' is null (here, it happens to be undefined behavior).
3210    int fetch(int * _Nonnull ptr) { return *ptr; }
3211
3212    // 'ptr' may be null.
3213    int fetch_or_zero(int * _Nullable ptr) {
3214      return ptr ? *ptr : 0;
3215    }
3216
3217    // A nullable pointer to non-null pointers to const characters.
3218    const char *join_strings(const char * _Nonnull * _Nullable strings, unsigned n);
3219
3220In 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:
3221
3222  .. code-block:: objective-c
3223
3224    @interface NSView : NSResponder
3225      - (nullable NSView *)ancestorSharedWithView:(nonnull NSView *)aView;
3226      @property (assign, nullable) NSView *superview;
3227      @property (readonly, nonnull) NSArray *subviews;
3228    @end
3229  }];
3230}
3231
3232def TypeNonNullDocs : Documentation {
3233  let Category = NullabilityDocs;
3234  let Content = [{
3235The ``_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:
3236
3237  .. code-block:: c
3238
3239    int fetch(int * _Nonnull ptr);
3240
3241a 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.
3242  }];
3243}
3244
3245def TypeNullableDocs : Documentation {
3246  let Category = NullabilityDocs;
3247  let Content = [{
3248The ``_Nullable`` nullability qualifier indicates that a value of the ``_Nullable`` pointer type can be null. For example, given:
3249
3250  .. code-block:: c
3251
3252    int fetch_or_zero(int * _Nullable ptr);
3253
3254a caller of ``fetch_or_zero`` can provide null.
3255  }];
3256}
3257
3258def TypeNullUnspecifiedDocs : Documentation {
3259  let Category = NullabilityDocs;
3260  let Content = [{
3261The ``_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.
3262  }];
3263}
3264
3265def NonNullDocs : Documentation {
3266  let Category = NullabilityDocs;
3267  let Content = [{
3268The ``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:
3269
3270  .. code-block:: c
3271
3272    extern void * my_memcpy (void *dest, const void *src, size_t len)
3273                    __attribute__((nonnull (1, 2)));
3274
3275Here, the ``nonnull`` attribute indicates that parameters 1 and 2
3276cannot have a null value. Omitting the parenthesized list of parameter indices means that all parameters of pointer type cannot be null:
3277
3278  .. code-block:: c
3279
3280    extern void * my_memcpy (void *dest, const void *src, size_t len)
3281                    __attribute__((nonnull));
3282
3283Clang 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:
3284
3285  .. code-block:: c
3286
3287    extern void * my_memcpy (void *dest __attribute__((nonnull)),
3288                             const void *src __attribute__((nonnull)), size_t len);
3289
3290Note 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.
3291  }];
3292}
3293
3294def ReturnsNonNullDocs : Documentation {
3295  let Category = NullabilityDocs;
3296  let Content = [{
3297The ``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:
3298
3299  .. code-block:: c
3300
3301    extern void * malloc (size_t size) __attribute__((returns_nonnull));
3302
3303The ``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
3304}];
3305}
3306
3307def NoAliasDocs : Documentation {
3308  let Category = DocCatFunction;
3309  let Content = [{
3310The ``noalias`` attribute indicates that the only memory accesses inside
3311function are loads and stores from objects pointed to by its pointer-typed
3312arguments, with arbitrary offsets.
3313  }];
3314}
3315
3316def OMPDeclareSimdDocs : Documentation {
3317  let Category = DocCatFunction;
3318  let Heading = "#pragma omp declare simd";
3319  let Content = [{
3320The ``declare simd`` construct can be applied to a function to enable the creation
3321of one or more versions that can process multiple arguments using SIMD
3322instructions from a single invocation in a SIMD loop. The ``declare simd``
3323directive is a declarative directive. There may be multiple ``declare simd``
3324directives for a function. The use of a ``declare simd`` construct on a function
3325enables the creation of SIMD versions of the associated function that can be
3326used to process multiple arguments from a single invocation from a SIMD loop
3327concurrently.
3328The syntax of the ``declare simd`` construct is as follows:
3329
3330  .. code-block:: none
3331
3332    #pragma omp declare simd [clause[[,] clause] ...] new-line
3333    [#pragma omp declare simd [clause[[,] clause] ...] new-line]
3334    [...]
3335    function definition or declaration
3336
3337where clause is one of the following:
3338
3339  .. code-block:: none
3340
3341    simdlen(length)
3342    linear(argument-list[:constant-linear-step])
3343    aligned(argument-list[:alignment])
3344    uniform(argument-list)
3345    inbranch
3346    notinbranch
3347
3348  }];
3349}
3350
3351def OMPDeclareTargetDocs : Documentation {
3352  let Category = DocCatFunction;
3353  let Heading = "#pragma omp declare target";
3354  let Content = [{
3355The ``declare target`` directive specifies that variables and functions are mapped
3356to a device for OpenMP offload mechanism.
3357
3358The syntax of the declare target directive is as follows:
3359
3360  .. code-block:: c
3361
3362    #pragma omp declare target new-line
3363    declarations-definition-seq
3364    #pragma omp end declare target new-line
3365
3366or
3367
3368  .. code-block:: c
3369
3370    #pragma omp declare target (extended-list) new-line
3371
3372or
3373
3374  .. code-block:: c
3375
3376    #pragma omp declare target clause[ [,] clause ... ] new-line
3377
3378where clause is one of the following:
3379
3380
3381  .. code-block:: c
3382
3383     to(extended-list)
3384     link(list)
3385     device_type(host | nohost | any)
3386  }];
3387}
3388
3389def OMPDeclareVariantDocs : Documentation {
3390  let Category = DocCatFunction;
3391  let Heading = "#pragma omp declare variant";
3392  let Content = [{
3393The ``declare variant`` directive declares a specialized variant of a base
3394function and specifies the context in which that specialized variant is used.
3395The declare variant directive is a declarative directive.
3396The syntax of the ``declare variant`` construct is as follows:
3397
3398  .. code-block:: none
3399
3400    #pragma omp declare variant(variant-func-id) clause new-line
3401    [#pragma omp declare variant(variant-func-id) clause new-line]
3402    [...]
3403    function definition or declaration
3404
3405where clause is one of the following:
3406
3407  .. code-block:: none
3408
3409    match(context-selector-specification)
3410
3411and where ``variant-func-id`` is the name of a function variant that is either a
3412base language identifier or, for C++, a template-id.
3413
3414Clang provides the following context selector extensions, used via
3415``implementation={extension(EXTENSION)}``:
3416
3417  .. code-block:: none
3418
3419    match_all
3420    match_any
3421    match_none
3422
3423The match extensions change when the *entire* context selector is considered a
3424match for an OpenMP context. The default is ``all``, with ``none`` no trait in the
3425selector is allowed to be in the OpenMP context, with ``any`` a single trait in
3426both the selector and OpenMP context is sufficient. Only a single match
3427extension trait is allowed per context selector.
3428
3429  }];
3430}
3431
3432def NoStackProtectorDocs : Documentation {
3433  let Category = DocCatFunction;
3434  let Content = [{
3435Clang supports the ``__attribute__((no_stack_protector))`` attribute which disables
3436the stack protector on the specified function. This attribute is useful for
3437selectively disabling the stack protector on some functions when building with
3438``-fstack-protector`` compiler option.
3439
3440For example, it disables the stack protector for the function ``foo`` but function
3441``bar`` will still be built with the stack protector with the ``-fstack-protector``
3442option.
3443
3444.. code-block:: c
3445
3446    int __attribute__((no_stack_protector))
3447    foo (int x); // stack protection will be disabled for foo.
3448
3449    int bar(int y); // bar can be built with the stack protector.
3450
3451    }];
3452}
3453
3454def NotTailCalledDocs : Documentation {
3455  let Category = DocCatFunction;
3456  let Content = [{
3457The ``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``.
3458
3459For example, it prevents tail-call optimization in the following case:
3460
3461  .. code-block:: c
3462
3463    int __attribute__((not_tail_called)) foo1(int);
3464
3465    int foo2(int a) {
3466      return foo1(a); // No tail-call optimization on direct calls.
3467    }
3468
3469However, it doesn't prevent tail-call optimization in this case:
3470
3471  .. code-block:: c
3472
3473    int __attribute__((not_tail_called)) foo1(int);
3474
3475    int foo2(int a) {
3476      int (*fn)(int) = &foo1;
3477
3478      // not_tail_called has no effect on an indirect call even if the call can be
3479      // resolved at compile time.
3480      return (*fn)(a);
3481    }
3482
3483Marking virtual functions as ``not_tail_called`` is an error:
3484
3485  .. code-block:: c++
3486
3487    class Base {
3488    public:
3489      // not_tail_called on a virtual function is an error.
3490      [[clang::not_tail_called]] virtual int foo1();
3491
3492      virtual int foo2();
3493
3494      // Non-virtual functions can be marked ``not_tail_called``.
3495      [[clang::not_tail_called]] int foo3();
3496    };
3497
3498    class Derived1 : public Base {
3499    public:
3500      int foo1() override;
3501
3502      // not_tail_called on a virtual function is an error.
3503      [[clang::not_tail_called]] int foo2() override;
3504    };
3505  }];
3506}
3507
3508def NoThrowDocs : Documentation {
3509  let Category = DocCatFunction;
3510  let Content = [{
3511Clang supports the GNU style ``__attribute__((nothrow))`` and Microsoft style
3512``__declspec(nothrow)`` attribute as an equivalent of ``noexcept`` on function
3513declarations. This attribute informs the compiler that the annotated function
3514does not throw an exception. This prevents exception-unwinding. This attribute
3515is particularly useful on functions in the C Standard Library that are
3516guaranteed to not throw an exception.
3517    }];
3518}
3519
3520def InternalLinkageDocs : Documentation {
3521  let Category = DocCatFunction;
3522  let Content = [{
3523The ``internal_linkage`` attribute changes the linkage type of the declaration to internal.
3524This is similar to C-style ``static``, but can be used on classes and class methods. When applied to a class definition,
3525this attribute affects all methods and static data members of that class.
3526This can be used to contain the ABI of a C++ library by excluding unwanted class methods from the export tables.
3527  }];
3528}
3529
3530def ExcludeFromExplicitInstantiationDocs : Documentation {
3531  let Category = DocCatFunction;
3532  let Content = [{
3533The ``exclude_from_explicit_instantiation`` attribute opts-out a member of a
3534class template from being part of explicit template instantiations of that
3535class template. This means that an explicit instantiation will not instantiate
3536members of the class template marked with the attribute, but also that code
3537where an extern template declaration of the enclosing class template is visible
3538will not take for granted that an external instantiation of the class template
3539would provide those members (which would otherwise be a link error, since the
3540explicit instantiation won't provide those members). For example, let's say we
3541don't want the ``data()`` method to be part of libc++'s ABI. To make sure it
3542is not exported from the dylib, we give it hidden visibility:
3543
3544  .. code-block:: c++
3545
3546    // in <string>
3547    template <class CharT>
3548    class basic_string {
3549    public:
3550      __attribute__((__visibility__("hidden")))
3551      const value_type* data() const noexcept { ... }
3552    };
3553
3554    template class basic_string<char>;
3555
3556Since an explicit template instantiation declaration for ``basic_string<char>``
3557is provided, the compiler is free to assume that ``basic_string<char>::data()``
3558will be provided by another translation unit, and it is free to produce an
3559external call to this function. However, since ``data()`` has hidden visibility
3560and the explicit template instantiation is provided in a shared library (as
3561opposed to simply another translation unit), ``basic_string<char>::data()``
3562won't be found and a link error will ensue. This happens because the compiler
3563assumes that ``basic_string<char>::data()`` is part of the explicit template
3564instantiation declaration, when it really isn't. To tell the compiler that
3565``data()`` is not part of the explicit template instantiation declaration, the
3566``exclude_from_explicit_instantiation`` attribute can be used:
3567
3568  .. code-block:: c++
3569
3570    // in <string>
3571    template <class CharT>
3572    class basic_string {
3573    public:
3574      __attribute__((__visibility__("hidden")))
3575      __attribute__((exclude_from_explicit_instantiation))
3576      const value_type* data() const noexcept { ... }
3577    };
3578
3579    template class basic_string<char>;
3580
3581Now, the compiler won't assume that ``basic_string<char>::data()`` is provided
3582externally despite there being an explicit template instantiation declaration:
3583the compiler will implicitly instantiate ``basic_string<char>::data()`` in the
3584TUs where it is used.
3585
3586This attribute can be used on static and non-static member functions of class
3587templates, static data members of class templates and member classes of class
3588templates.
3589  }];
3590}
3591
3592def DisableTailCallsDocs : Documentation {
3593  let Category = DocCatFunction;
3594  let Content = [{
3595The ``disable_tail_calls`` attribute instructs the backend to not perform tail call optimization inside the marked function.
3596
3597For example:
3598
3599  .. code-block:: c
3600
3601    int callee(int);
3602
3603    int foo(int a) __attribute__((disable_tail_calls)) {
3604      return callee(a); // This call is not tail-call optimized.
3605    }
3606
3607Marking virtual functions as ``disable_tail_calls`` is legal.
3608
3609  .. code-block:: c++
3610
3611    int callee(int);
3612
3613    class Base {
3614    public:
3615      [[clang::disable_tail_calls]] virtual int foo1() {
3616        return callee(); // This call is not tail-call optimized.
3617      }
3618    };
3619
3620    class Derived1 : public Base {
3621    public:
3622      int foo1() override {
3623        return callee(); // This call is tail-call optimized.
3624      }
3625    };
3626
3627  }];
3628}
3629
3630def AnyX86NoCallerSavedRegistersDocs : Documentation {
3631  let Category = DocCatFunction;
3632  let Content = [{
3633Use this attribute to indicate that the specified function has no
3634caller-saved registers. That is, all registers are callee-saved except for
3635registers used for passing parameters to the function or returning parameters
3636from the function.
3637The compiler saves and restores any modified registers that were not used for
3638passing or returning arguments to the function.
3639
3640The user can call functions specified with the 'no_caller_saved_registers'
3641attribute from an interrupt handler without saving and restoring all
3642call-clobbered registers.
3643
3644Note that 'no_caller_saved_registers' attribute is not a calling convention.
3645In fact, it only overrides the decision of which registers should be saved by
3646the caller, but not how the parameters are passed from the caller to the callee.
3647
3648For example:
3649
3650  .. code-block:: c
3651
3652    __attribute__ ((no_caller_saved_registers, fastcall))
3653    void f (int arg1, int arg2) {
3654      ...
3655    }
3656
3657  In this case parameters 'arg1' and 'arg2' will be passed in registers.
3658  In this case, on 32-bit x86 targets, the function 'f' will use ECX and EDX as
3659  register parameters. However, it will not assume any scratch registers and
3660  should save and restore any modified registers except for ECX and EDX.
3661  }];
3662}
3663
3664def X86ForceAlignArgPointerDocs : Documentation {
3665  let Category = DocCatFunction;
3666  let Content = [{
3667Use this attribute to force stack alignment.
3668
3669Legacy x86 code uses 4-byte stack alignment. Newer aligned SSE instructions
3670(like 'movaps') that work with the stack require operands to be 16-byte aligned.
3671This attribute realigns the stack in the function prologue to make sure the
3672stack can be used with SSE instructions.
3673
3674Note that the x86_64 ABI forces 16-byte stack alignment at the call site.
3675Because of this, 'force_align_arg_pointer' is not needed on x86_64, except in
3676rare cases where the caller does not align the stack properly (e.g. flow
3677jumps from i386 arch code).
3678
3679  .. code-block:: c
3680
3681    __attribute__ ((force_align_arg_pointer))
3682    void f () {
3683      ...
3684    }
3685
3686  }];
3687}
3688
3689def AnyX86NoCfCheckDocs : Documentation {
3690  let Category = DocCatFunction;
3691  let Content = [{
3692Jump Oriented Programming attacks rely on tampering with addresses used by
3693indirect call / jmp, e.g. redirect control-flow to non-programmer
3694intended bytes in the binary.
3695X86 Supports Indirect Branch Tracking (IBT) as part of Control-Flow
3696Enforcement Technology (CET). IBT instruments ENDBR instructions used to
3697specify valid targets of indirect call / jmp.
3698The ``nocf_check`` attribute has two roles:
36991. Appertains to a function - do not add ENDBR instruction at the beginning of
3700the function.
37012. Appertains to a function pointer - do not track the target function of this
3702pointer (by adding nocf_check prefix to the indirect-call instruction).
3703}];
3704}
3705
3706def SwiftCallDocs : Documentation {
3707  let Category = DocCatVariable;
3708  let Content = [{
3709The ``swiftcall`` attribute indicates that a function should be called
3710using the Swift calling convention for a function or function pointer.
3711
3712The lowering for the Swift calling convention, as described by the Swift
3713ABI documentation, occurs in multiple phases.  The first, "high-level"
3714phase breaks down the formal parameters and results into innately direct
3715and indirect components, adds implicit parameters for the generic
3716signature, and assigns the context and error ABI treatments to parameters
3717where applicable.  The second phase breaks down the direct parameters
3718and results from the first phase and assigns them to registers or the
3719stack.  The ``swiftcall`` convention only handles this second phase of
3720lowering; the C function type must accurately reflect the results
3721of the first phase, as follows:
3722
3723- Results classified as indirect by high-level lowering should be
3724  represented as parameters with the ``swift_indirect_result`` attribute.
3725
3726- Results classified as direct by high-level lowering should be represented
3727  as follows:
3728
3729  - First, remove any empty direct results.
3730
3731  - If there are no direct results, the C result type should be ``void``.
3732
3733  - If there is one direct result, the C result type should be a type with
3734    the exact layout of that result type.
3735
3736  - If there are a multiple direct results, the C result type should be
3737    a struct type with the exact layout of a tuple of those results.
3738
3739- Parameters classified as indirect by high-level lowering should be
3740  represented as parameters of pointer type.
3741
3742- Parameters classified as direct by high-level lowering should be
3743  omitted if they are empty types; otherwise, they should be represented
3744  as a parameter type with a layout exactly matching the layout of the
3745  Swift parameter type.
3746
3747- The context parameter, if present, should be represented as a trailing
3748  parameter with the ``swift_context`` attribute.
3749
3750- The error result parameter, if present, should be represented as a
3751  trailing parameter (always following a context parameter) with the
3752  ``swift_error_result`` attribute.
3753
3754``swiftcall`` does not support variadic arguments or unprototyped functions.
3755
3756The parameter ABI treatment attributes are aspects of the function type.
3757A function type which applies an ABI treatment attribute to a
3758parameter is a different type from an otherwise-identical function type
3759that does not.  A single parameter may not have multiple ABI treatment
3760attributes.
3761
3762Support for this feature is target-dependent, although it should be
3763supported on every target that Swift supports.  Query for this support
3764with ``__has_attribute(swiftcall)``.  This implies support for the
3765``swift_context``, ``swift_error_result``, and ``swift_indirect_result``
3766attributes.
3767  }];
3768}
3769
3770def SwiftContextDocs : Documentation {
3771  let Category = DocCatVariable;
3772  let Content = [{
3773The ``swift_context`` attribute marks a parameter of a ``swiftcall``
3774function as having the special context-parameter ABI treatment.
3775
3776This treatment generally passes the context value in a special register
3777which is normally callee-preserved.
3778
3779A ``swift_context`` parameter must either be the last parameter or must be
3780followed by a ``swift_error_result`` parameter (which itself must always be
3781the last parameter).
3782
3783A context parameter must have pointer or reference type.
3784  }];
3785}
3786
3787def SwiftErrorResultDocs : Documentation {
3788  let Category = DocCatVariable;
3789  let Content = [{
3790The ``swift_error_result`` attribute marks a parameter of a ``swiftcall``
3791function as having the special error-result ABI treatment.
3792
3793This treatment generally passes the underlying error value in and out of
3794the function through a special register which is normally callee-preserved.
3795This is modeled in C by pretending that the register is addressable memory:
3796
3797- The caller appears to pass the address of a variable of pointer type.
3798  The current value of this variable is copied into the register before
3799  the call; if the call returns normally, the value is copied back into the
3800  variable.
3801
3802- The callee appears to receive the address of a variable.  This address
3803  is actually a hidden location in its own stack, initialized with the
3804  value of the register upon entry.  When the function returns normally,
3805  the value in that hidden location is written back to the register.
3806
3807A ``swift_error_result`` parameter must be the last parameter, and it must be
3808preceded by a ``swift_context`` parameter.
3809
3810A ``swift_error_result`` parameter must have type ``T**`` or ``T*&`` for some
3811type T.  Note that no qualifiers are permitted on the intermediate level.
3812
3813It is undefined behavior if the caller does not pass a pointer or
3814reference to a valid object.
3815
3816The standard convention is that the error value itself (that is, the
3817value stored in the apparent argument) will be null upon function entry,
3818but this is not enforced by the ABI.
3819  }];
3820}
3821
3822def SwiftIndirectResultDocs : Documentation {
3823  let Category = DocCatVariable;
3824  let Content = [{
3825The ``swift_indirect_result`` attribute marks a parameter of a ``swiftcall``
3826function as having the special indirect-result ABI treatment.
3827
3828This treatment gives the parameter the target's normal indirect-result
3829ABI treatment, which may involve passing it differently from an ordinary
3830parameter.  However, only the first indirect result will receive this
3831treatment.  Furthermore, low-level lowering may decide that a direct result
3832must be returned indirectly; if so, this will take priority over the
3833``swift_indirect_result`` parameters.
3834
3835A ``swift_indirect_result`` parameter must either be the first parameter or
3836follow another ``swift_indirect_result`` parameter.
3837
3838A ``swift_indirect_result`` parameter must have type ``T*`` or ``T&`` for
3839some object type ``T``.  If ``T`` is a complete type at the point of
3840definition of a function, it is undefined behavior if the argument
3841value does not point to storage of adequate size and alignment for a
3842value of type ``T``.
3843
3844Making indirect results explicit in the signature allows C functions to
3845directly construct objects into them without relying on language
3846optimizations like C++'s named return value optimization (NRVO).
3847  }];
3848}
3849
3850def SuppressDocs : Documentation {
3851  let Category = DocCatStmt;
3852  let Content = [{
3853The ``[[gsl::suppress]]`` attribute suppresses specific
3854clang-tidy diagnostics for rules of the `C++ Core Guidelines`_ in a portable
3855way. The attribute can be attached to declarations, statements, and at
3856namespace scope.
3857
3858.. code-block:: c++
3859
3860  [[gsl::suppress("Rh-public")]]
3861  void f_() {
3862    int *p;
3863    [[gsl::suppress("type")]] {
3864      p = reinterpret_cast<int*>(7);
3865    }
3866  }
3867  namespace N {
3868    [[clang::suppress("type", "bounds")]];
3869    ...
3870  }
3871
3872.. _`C++ Core Guidelines`: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#inforce-enforcement
3873  }];
3874}
3875
3876def AbiTagsDocs : Documentation {
3877  let Category = DocCatFunction;
3878  let Content = [{
3879The ``abi_tag`` attribute can be applied to a function, variable, class or
3880inline namespace declaration to modify the mangled name of the entity. It gives
3881the ability to distinguish between different versions of the same entity but
3882with different ABI versions supported. For example, a newer version of a class
3883could have a different set of data members and thus have a different size. Using
3884the ``abi_tag`` attribute, it is possible to have different mangled names for
3885a global variable of the class type. Therefore, the old code could keep using
3886the old mangled name and the new code will use the new mangled name with tags.
3887  }];
3888}
3889
3890def PreserveMostDocs : Documentation {
3891  let Category = DocCatCallingConvs;
3892  let Content = [{
3893On X86-64 and AArch64 targets, this attribute changes the calling convention of
3894a function. The ``preserve_most`` calling convention attempts to make the code
3895in the caller as unintrusive as possible. This convention behaves identically
3896to the ``C`` calling convention on how arguments and return values are passed,
3897but it uses a different set of caller/callee-saved registers. This alleviates
3898the burden of saving and recovering a large register set before and after the
3899call in the caller. If the arguments are passed in callee-saved registers,
3900then they will be preserved by the callee across the call. This doesn't
3901apply for values returned in callee-saved registers.
3902
3903- On X86-64 the callee preserves all general purpose registers, except for
3904  R11. R11 can be used as a scratch register. Floating-point registers
3905  (XMMs/YMMs) are not preserved and need to be saved by the caller.
3906
3907The idea behind this convention is to support calls to runtime functions
3908that have a hot path and a cold path. The hot path is usually a small piece
3909of code that doesn't use many registers. The cold path might need to call out to
3910another function and therefore only needs to preserve the caller-saved
3911registers, which haven't already been saved by the caller. The
3912``preserve_most`` calling convention is very similar to the ``cold`` calling
3913convention in terms of caller/callee-saved registers, but they are used for
3914different types of function calls. ``coldcc`` is for function calls that are
3915rarely executed, whereas ``preserve_most`` function calls are intended to be
3916on the hot path and definitely executed a lot. Furthermore ``preserve_most``
3917doesn't prevent the inliner from inlining the function call.
3918
3919This calling convention will be used by a future version of the Objective-C
3920runtime and should therefore still be considered experimental at this time.
3921Although this convention was created to optimize certain runtime calls to
3922the Objective-C runtime, it is not limited to this runtime and might be used
3923by other runtimes in the future too. The current implementation only
3924supports X86-64 and AArch64, but the intention is to support more architectures
3925in the future.
3926  }];
3927}
3928
3929def PreserveAllDocs : Documentation {
3930  let Category = DocCatCallingConvs;
3931  let Content = [{
3932On X86-64 and AArch64 targets, this attribute changes the calling convention of
3933a function. The ``preserve_all`` calling convention attempts to make the code
3934in the caller even less intrusive than the ``preserve_most`` calling convention.
3935This calling convention also behaves identical to the ``C`` calling convention
3936on how arguments and return values are passed, but it uses a different set of
3937caller/callee-saved registers. This removes the burden of saving and
3938recovering a large register set before and after the call in the caller. If
3939the arguments are passed in callee-saved registers, then they will be
3940preserved by the callee across the call. This doesn't apply for values
3941returned in callee-saved registers.
3942
3943- On X86-64 the callee preserves all general purpose registers, except for
3944  R11. R11 can be used as a scratch register. Furthermore it also preserves
3945  all floating-point registers (XMMs/YMMs).
3946
3947The idea behind this convention is to support calls to runtime functions
3948that don't need to call out to any other functions.
3949
3950This calling convention, like the ``preserve_most`` calling convention, will be
3951used by a future version of the Objective-C runtime and should be considered
3952experimental at this time.
3953  }];
3954}
3955
3956def DeprecatedDocs : Documentation {
3957  let Category = DocCatDecl;
3958  let Content = [{
3959The ``deprecated`` attribute can be applied to a function, a variable, or a
3960type. This is useful when identifying functions, variables, or types that are
3961expected to be removed in a future version of a program.
3962
3963Consider the function declaration for a hypothetical function ``f``:
3964
3965.. code-block:: c++
3966
3967  void f(void) __attribute__((deprecated("message", "replacement")));
3968
3969When spelled as ``__attribute__((deprecated))``, the deprecated attribute can have
3970two optional string arguments. The first one is the message to display when
3971emitting the warning; the second one enables the compiler to provide a Fix-It
3972to replace the deprecated name with a new name. Otherwise, when spelled as
3973``[[gnu::deprecated]]`` or ``[[deprecated]]``, the attribute can have one optional
3974string argument which is the message to display when emitting the warning.
3975  }];
3976}
3977
3978def IFuncDocs : Documentation {
3979  let Category = DocCatFunction;
3980  let Content = [{
3981``__attribute__((ifunc("resolver")))`` is used to mark that the address of a declaration should be resolved at runtime by calling a resolver function.
3982
3983The 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.
3984
3985The ``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.
3986
3987Not 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.
3988  }];
3989}
3990
3991def LTOVisibilityDocs : Documentation {
3992  let Category = DocCatDecl;
3993  let Content = [{
3994See :doc:`LTOVisibility`.
3995  }];
3996}
3997
3998def RenderScriptKernelAttributeDocs : Documentation {
3999  let Category = DocCatFunction;
4000  let Content = [{
4001``__attribute__((kernel))`` is used to mark a ``kernel`` function in
4002RenderScript.
4003
4004In RenderScript, ``kernel`` functions are used to express data-parallel
4005computations.  The RenderScript runtime efficiently parallelizes ``kernel``
4006functions to run on computational resources such as multi-core CPUs and GPUs.
4007See the RenderScript_ documentation for more information.
4008
4009.. _RenderScript: https://developer.android.com/guide/topics/renderscript/compute.html
4010  }];
4011}
4012
4013def XRayDocs : Documentation {
4014  let Category = DocCatFunction;
4015  let Heading = "xray_always_instrument, xray_never_instrument, xray_log_args";
4016  let Content = [{
4017``__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.
4018
4019Conversely, ``__attribute__((xray_never_instrument))`` or ``[[clang::xray_never_instrument]]`` will inhibit the insertion of these instrumentation points.
4020
4021If 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.
4022
4023``__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.
4024  }];
4025}
4026
4027def PatchableFunctionEntryDocs : Documentation {
4028  let Category = DocCatFunction;
4029  let Content = [{
4030``__attribute__((patchable_function_entry(N,M)))`` is used to generate M NOPs
4031before the function entry and N-M NOPs after the function entry. This attribute
4032takes precedence over the command line option ``-fpatchable-function-entry=N,M``.
4033``M`` defaults to 0 if omitted.
4034}];
4035}
4036
4037def TransparentUnionDocs : Documentation {
4038  let Category = DocCatDecl;
4039  let Content = [{
4040This attribute can be applied to a union to change the behavior of calls to
4041functions that have an argument with a transparent union type. The compiler
4042behavior is changed in the following manner:
4043
4044- A value whose type is any member of the transparent union can be passed as an
4045  argument without the need to cast that value.
4046
4047- The argument is passed to the function using the calling convention of the
4048  first member of the transparent union. Consequently, all the members of the
4049  transparent union should have the same calling convention as its first member.
4050
4051Transparent unions are not supported in C++.
4052  }];
4053}
4054
4055def ObjCSubclassingRestrictedDocs : Documentation {
4056  let Category = DocCatDecl;
4057  let Content = [{
4058This attribute can be added to an Objective-C ``@interface`` declaration to
4059ensure that this class cannot be subclassed.
4060  }];
4061}
4062
4063def ObjCNonLazyClassDocs : Documentation {
4064  let Category = DocCatDecl;
4065  let Content = [{
4066This attribute can be added to an Objective-C ``@interface`` or
4067``@implementation`` declaration to add the class to the list of non-lazily
4068initialized classes. A non-lazy class will be initialized eagerly when the
4069Objective-C runtime is loaded. This is required for certain system classes which
4070have instances allocated in non-standard ways, such as the classes for blocks
4071and constant strings. Adding this attribute is essentially equivalent to
4072providing a trivial ``+load`` method but avoids the (fairly small) load-time
4073overheads associated with defining and calling such a method.
4074  }];
4075}
4076
4077def ObjCDirectDocs : Documentation {
4078  let Category = DocCatDecl;
4079  let Content = [{
4080The ``objc_direct`` attribute can be used to mark an Objective-C method as
4081being *direct*.  A direct method is treated statically like an ordinary method,
4082but dynamically it behaves more like a C function.  This lowers some of the costs
4083associated with the method but also sacrifices some of the ordinary capabilities
4084of Objective-C methods.
4085
4086A message send of a direct method calls the implementation directly, as if it
4087were a C function, rather than using ordinary Objective-C method dispatch. This
4088is substantially faster and potentially allows the implementation to be inlined,
4089but it also means the method cannot be overridden in subclasses or replaced
4090dynamically, as ordinary Objective-C methods can.
4091
4092Furthermore, a direct method is not listed in the class's method lists. This
4093substantially reduces the code-size overhead of the method but also means it
4094cannot be called dynamically using ordinary Objective-C method dispatch at all;
4095in particular, this means that it cannot override a superclass method or satisfy
4096a protocol requirement.
4097
4098Because a direct method cannot be overridden, it is an error to perform
4099a ``super`` message send of one.
4100
4101Although a message send of a direct method causes the method to be called
4102directly as if it were a C function, it still obeys Objective-C semantics in other
4103ways:
4104
4105- If the receiver is ``nil``, the message send does nothing and returns the zero value
4106  for the return type.
4107
4108- A message send of a direct class method will cause the class to be initialized,
4109  including calling the ``+initialize`` method if present.
4110
4111- The implicit ``_cmd`` parameter containing the method's selector is still defined.
4112  In order to minimize code-size costs, the implementation will not emit a reference
4113  to the selector if the parameter is unused within the method.
4114
4115Symbols for direct method implementations are implicitly given hidden
4116visibility, meaning that they can only be called within the same linkage unit.
4117
4118It is an error to do any of the following:
4119
4120- declare a direct method in a protocol,
4121- declare an override of a direct method with a method in a subclass,
4122- declare an override of a non-direct method with a direct method in a subclass,
4123- declare a method with different directness in different class interfaces, or
4124- implement a non-direct method (as declared in any class interface) with a direct method.
4125
4126If any of these rules would be violated if every method defined in an
4127``@implementation`` within a single linkage unit were declared in an
4128appropriate class interface, the program is ill-formed with no diagnostic
4129required.  If a violation of this rule is not diagnosed, behavior remains
4130well-defined; this paragraph is simply reserving the right to diagnose such
4131conflicts in the future, not to treat them as undefined behavior.
4132
4133Additionally, Clang will warn about any ``@selector`` expression that
4134names a selector that is only known to be used for direct methods.
4135
4136For the purpose of these rules, a "class interface" includes a class's primary
4137``@interface`` block, its class extensions, its categories, its declared protocols,
4138and all the class interfaces of its superclasses.
4139
4140An Objective-C property can be declared with the ``direct`` property
4141attribute.  If a direct property declaration causes an implicit declaration of
4142a getter or setter method (that is, if the given method is not explicitly
4143declared elsewhere), the method is declared to be direct.
4144
4145Some programmers may wish to make many methods direct at once.  In order
4146to simplify this, the ``objc_direct_members`` attribute is provided; see its
4147documentation for more information.
4148  }];
4149}
4150
4151def ObjCDirectMembersDocs : Documentation {
4152  let Category = DocCatDecl;
4153  let Content = [{
4154The ``objc_direct_members`` attribute can be placed on an Objective-C
4155``@interface`` or ``@implementation`` to mark that methods declared
4156therein should be considered direct by default.  See the documentation
4157for ``objc_direct`` for more information about direct methods.
4158
4159When ``objc_direct_members`` is placed on an ``@interface`` block, every
4160method in the block is considered to be declared as direct.  This includes any
4161implicit method declarations introduced by property declarations.  If the method
4162redeclares a non-direct method, the declaration is ill-formed, exactly as if the
4163method was annotated with the ``objc_direct`` attribute.
4164
4165When ``objc_direct_members`` is placed on an ``@implementation`` block,
4166methods defined in the block are considered to be declared as direct unless
4167they have been previously declared as non-direct in any interface of the class.
4168This includes the implicit method definitions introduced by synthesized
4169properties, including auto-synthesized properties.
4170  }];
4171}
4172
4173def SelectAnyDocs : Documentation {
4174  let Category = DocCatDecl;
4175  let Content = [{
4176This attribute appertains to a global symbol, causing it to have a weak
4177definition (
4178`linkonce <https://llvm.org/docs/LangRef.html#linkage-types>`_
4179), allowing the linker to select any definition.
4180
4181For more information see
4182`gcc documentation <https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Microsoft-Windows-Variable-Attributes.html>`_
4183or `msvc documentation <https://docs.microsoft.com/pl-pl/cpp/cpp/selectany>`_.
4184}]; }
4185
4186def WebAssemblyExportNameDocs : Documentation {
4187  let Category = DocCatFunction;
4188  let Content = [{
4189Clang supports the ``__attribute__((export_name(<name>)))``
4190attribute for the WebAssembly target. This attribute may be attached to a
4191function declaration, where it modifies how the symbol is to be exported
4192from the linked WebAssembly.
4193
4194WebAssembly functions are exported via string name. By default when a symbol
4195is exported, the export name for C/C++ symbols are the same as their C/C++
4196symbol names. This attribute can be used to override the default behavior, and
4197request a specific string name be used instead.
4198  }];
4199}
4200
4201def WebAssemblyImportModuleDocs : Documentation {
4202  let Category = DocCatFunction;
4203  let Content = [{
4204Clang supports the ``__attribute__((import_module(<module_name>)))``
4205attribute for the WebAssembly target. This attribute may be attached to a
4206function declaration, where it modifies how the symbol is to be imported
4207within the WebAssembly linking environment.
4208
4209WebAssembly imports use a two-level namespace scheme, consisting of a module
4210name, which typically identifies a module from which to import, and a field
4211name, which typically identifies a field from that module to import. By
4212default, module names for C/C++ symbols are assigned automatically by the
4213linker. This attribute can be used to override the default behavior, and
4214request a specific module name be used instead.
4215  }];
4216}
4217
4218def WebAssemblyImportNameDocs : Documentation {
4219  let Category = DocCatFunction;
4220  let Content = [{
4221Clang supports the ``__attribute__((import_name(<name>)))``
4222attribute for the WebAssembly target. This attribute may be attached to a
4223function declaration, where it modifies how the symbol is to be imported
4224within the WebAssembly linking environment.
4225
4226WebAssembly imports use a two-level namespace scheme, consisting of a module
4227name, which typically identifies a module from which to import, and a field
4228name, which typically identifies a field from that module to import. By
4229default, field names for C/C++ symbols are the same as their C/C++ symbol
4230names. This attribute can be used to override the default behavior, and
4231request a specific field name be used instead.
4232  }];
4233}
4234
4235def ArtificialDocs : Documentation {
4236  let Category = DocCatFunction;
4237  let Content = [{
4238The ``artificial`` attribute can be applied to an inline function. If such a
4239function is inlined, the attribute indicates that debuggers should associate
4240the resulting instructions with the call site, rather than with the
4241corresponding line within the inlined callee.
4242  }];
4243}
4244
4245def NoDerefDocs : Documentation {
4246  let Category = DocCatType;
4247  let Content = [{
4248The ``noderef`` attribute causes clang to diagnose dereferences of annotated pointer types.
4249This is ideally used with pointers that point to special memory which cannot be read
4250from or written to, but allowing for the pointer to be used in pointer arithmetic.
4251The following are examples of valid expressions where dereferences are diagnosed:
4252
4253.. code-block:: c
4254
4255  int __attribute__((noderef)) *p;
4256  int x = *p;  // warning
4257
4258  int __attribute__((noderef)) **p2;
4259  x = **p2;  // warning
4260
4261  int * __attribute__((noderef)) *p3;
4262  p = *p3;  // warning
4263
4264  struct S {
4265    int a;
4266  };
4267  struct S __attribute__((noderef)) *s;
4268  x = s->a;    // warning
4269  x = (*s).a;  // warning
4270
4271Not all dereferences may diagnose a warning if the value directed by the pointer may not be
4272accessed. The following are examples of valid expressions where may not be diagnosed:
4273
4274.. code-block:: c
4275
4276  int *q;
4277  int __attribute__((noderef)) *p;
4278  q = &*p;
4279  q = *&p;
4280
4281  struct S {
4282    int a;
4283  };
4284  struct S __attribute__((noderef)) *s;
4285  p = &s->a;
4286  p = &(*s).a;
4287
4288``noderef`` is currently only supported for pointers and arrays and not usable for
4289references or Objective-C object pointers.
4290
4291.. code-block: c++
4292
4293  int x = 2;
4294  int __attribute__((noderef)) &y = x;  // warning: 'noderef' can only be used on an array or pointer type
4295
4296.. code-block: objc
4297
4298  id __attribute__((noderef)) obj = [NSObject new]; // warning: 'noderef' can only be used on an array or pointer type
4299}];
4300}
4301
4302def ReinitializesDocs : Documentation {
4303  let Category = DocCatFunction;
4304  let Content = [{
4305The ``reinitializes`` attribute can be applied to a non-static, non-const C++
4306member function to indicate that this member function reinitializes the entire
4307object to a known state, independent of the previous state of the object.
4308
4309This attribute can be interpreted by static analyzers that warn about uses of an
4310object that has been left in an indeterminate state by a move operation. If a
4311member function marked with the ``reinitializes`` attribute is called on a
4312moved-from object, the analyzer can conclude that the object is no longer in an
4313indeterminate state.
4314
4315A typical example where this attribute would be used is on functions that clear
4316a container class:
4317
4318.. code-block:: c++
4319
4320  template <class T>
4321  class Container {
4322  public:
4323    ...
4324    [[clang::reinitializes]] void Clear();
4325    ...
4326  };
4327  }];
4328}
4329
4330def AlwaysDestroyDocs : Documentation {
4331  let Category = DocCatVariable;
4332  let Content = [{
4333The ``always_destroy`` attribute specifies that a variable with static or thread
4334storage duration should have its exit-time destructor run. This attribute is the
4335default unless clang was invoked with -fno-c++-static-destructors.
4336  }];
4337}
4338
4339def NoDestroyDocs : Documentation {
4340  let Category = DocCatVariable;
4341  let Content = [{
4342The ``no_destroy`` attribute specifies that a variable with static or thread
4343storage duration shouldn't have its exit-time destructor run. Annotating every
4344static and thread duration variable with this attribute is equivalent to
4345invoking clang with -fno-c++-static-destructors.
4346
4347If a variable is declared with this attribute, clang doesn't access check or
4348generate the type's destructor. If you have a type that you only want to be
4349annotated with ``no_destroy``, you can therefore declare the destructor private:
4350
4351.. code-block:: c++
4352
4353  struct only_no_destroy {
4354    only_no_destroy();
4355  private:
4356    ~only_no_destroy();
4357  };
4358
4359  [[clang::no_destroy]] only_no_destroy global; // fine!
4360
4361Note that destructors are still required for subobjects of aggregates annotated
4362with this attribute. This is because previously constructed subobjects need to
4363be destroyed if an exception gets thrown before the initialization of the
4364complete object is complete. For instance:
4365
4366.. code-block:: c++
4367
4368  void f() {
4369    try {
4370      [[clang::no_destroy]]
4371      static only_no_destroy array[10]; // error, only_no_destroy has a private destructor.
4372    } catch (...) {
4373      // Handle the error
4374    }
4375  }
4376
4377Here, if the construction of ``array[9]`` fails with an exception, ``array[0..8]``
4378will be destroyed, so the element's destructor needs to be accessible.
4379  }];
4380}
4381
4382def UninitializedDocs : Documentation {
4383  let Category = DocCatVariable;
4384  let Content = [{
4385The command-line parameter ``-ftrivial-auto-var-init=*`` can be used to
4386initialize trivial automatic stack variables. By default, trivial automatic
4387stack variables are uninitialized. This attribute is used to override the
4388command-line parameter, forcing variables to remain uninitialized. It has no
4389semantic meaning in that using uninitialized values is undefined behavior,
4390it rather documents the programmer's intent.
4391  }];
4392}
4393
4394def LoaderUninitializedDocs : Documentation {
4395  let Category = DocCatVariable;
4396  let Content = [{
4397The ``loader_uninitialized`` attribute can be placed on global variables to
4398indicate that the variable does not need to be zero initialized by the loader.
4399On most targets, zero-initialization does not incur any additional cost.
4400For example, most general purpose operating systems deliberately ensure
4401that all memory is properly initialized in order to avoid leaking privileged
4402information from the kernel or other programs. However, some targets
4403do not make this guarantee, and on these targets, avoiding an unnecessary
4404zero-initialization can have a significant impact on load times and/or code
4405size.
4406
4407A declaration with this attribute is a non-tentative definition just as if it
4408provided an initializer. Variables with this attribute are considered to be
4409uninitialized in the same sense as a local variable, and the programs must
4410write to them before reading from them. If the variable's type is a C++ class
4411type with a non-trivial default constructor, or an array thereof, this attribute
4412only suppresses the static zero-initialization of the variable, not the dynamic
4413initialization provided by executing the default constructor.
4414  }];
4415}
4416
4417def CallbackDocs : Documentation {
4418  let Category = DocCatFunction;
4419  let Content = [{
4420The ``callback`` attribute specifies that the annotated function may invoke the
4421specified callback zero or more times. The callback, as well as the passed
4422arguments, are identified by their parameter name or position (starting with
44231!) in the annotated function. The first position in the attribute identifies
4424the callback callee, the following positions declare describe its arguments.
4425The callback callee is required to be callable with the number, and order, of
4426the specified arguments. The index ``0``, or the identifier ``this``, is used to
4427represent an implicit "this" pointer in class methods. If there is no implicit
4428"this" pointer it shall not be referenced. The index '-1', or the name "__",
4429represents an unknown callback callee argument. This can be a value which is
4430not present in the declared parameter list, or one that is, but is potentially
4431inspected, captured, or modified. Parameter names and indices can be mixed in
4432the callback attribute.
4433
4434The ``callback`` attribute, which is directly translated to ``callback``
4435metadata <http://llvm.org/docs/LangRef.html#callback-metadata>, make the
4436connection between the call to the annotated function and the callback callee.
4437This can enable interprocedural optimizations which were otherwise impossible.
4438If a function parameter is mentioned in the ``callback`` attribute, through its
4439position, it is undefined if that parameter is used for anything other than the
4440actual callback. Inspected, captured, or modified parameters shall not be
4441listed in the ``callback`` metadata.
4442
4443Example encodings for the callback performed by ``pthread_create`` are shown
4444below. The explicit attribute annotation indicates that the third parameter
4445(``start_routine``) is called zero or more times by the ``pthread_create`` function,
4446and that the fourth parameter (``arg``) is passed along. Note that the callback
4447behavior of ``pthread_create`` is automatically recognized by Clang. In addition,
4448the declarations of ``__kmpc_fork_teams`` and ``__kmpc_fork_call``, generated for
4449``#pragma omp target teams`` and ``#pragma omp parallel``, respectively, are also
4450automatically recognized as broker functions. Further functions might be added
4451in the future.
4452
4453  .. code-block:: c
4454
4455    __attribute__((callback (start_routine, arg)))
4456    int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
4457                       void *(*start_routine) (void *), void *arg);
4458
4459    __attribute__((callback (3, 4)))
4460    int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
4461                       void *(*start_routine) (void *), void *arg);
4462
4463  }];
4464}
4465
4466def GnuInlineDocs : Documentation {
4467  let Category = DocCatFunction;
4468  let Content = [{
4469The ``gnu_inline`` changes the meaning of ``extern inline`` to use GNU inline
4470semantics, meaning:
4471
4472* If any declaration that is declared ``inline`` is not declared ``extern``,
4473  then the ``inline`` keyword is just a hint. In particular, an out-of-line
4474  definition is still emitted for a function with external linkage, even if all
4475  call sites are inlined, unlike in C99 and C++ inline semantics.
4476
4477* If all declarations that are declared ``inline`` are also declared
4478  ``extern``, then the function body is present only for inlining and no
4479  out-of-line version is emitted.
4480
4481Some important consequences: ``static inline`` emits an out-of-line
4482version if needed, a plain ``inline`` definition emits an out-of-line version
4483always, and an ``extern inline`` definition (in a header) followed by a
4484(non-``extern``) ``inline`` declaration in a source file emits an out-of-line
4485version of the function in that source file but provides the function body for
4486inlining to all includers of the header.
4487
4488Either ``__GNUC_GNU_INLINE__`` (GNU inline semantics) or
4489``__GNUC_STDC_INLINE__`` (C99 semantics) will be defined (they are mutually
4490exclusive). If ``__GNUC_STDC_INLINE__`` is defined, then the ``gnu_inline``
4491function attribute can be used to get GNU inline semantics on a per function
4492basis. If ``__GNUC_GNU_INLINE__`` is defined, then the translation unit is
4493already being compiled with GNU inline semantics as the implied default. It is
4494unspecified which macro is defined in a C++ compilation.
4495
4496GNU inline semantics are the default behavior with ``-std=gnu89``,
4497``-std=c89``, ``-std=c94``, or ``-fgnu89-inline``.
4498  }];
4499}
4500
4501def SpeculativeLoadHardeningDocs : Documentation {
4502  let Category = DocCatFunction;
4503  let Content = [{
4504  This attribute can be applied to a function declaration in order to indicate
4505  that `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
4506  should be enabled for the function body. This can also be applied to a method
4507  in Objective C. This attribute will take precedence over the command line flag in
4508  the case where `-mno-speculative-load-hardening <https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mspeculative-load-hardening>`_ is specified.
4509
4510  Speculative Load Hardening is a best-effort mitigation against
4511  information leak attacks that make use of control flow
4512  miss-speculation - specifically miss-speculation of whether a branch
4513  is taken or not. Typically vulnerabilities enabling such attacks are
4514  classified as "Spectre variant #1". Notably, this does not attempt to
4515  mitigate against miss-speculation of branch target, classified as
4516  "Spectre variant #2" vulnerabilities.
4517
4518  When inlining, the attribute is sticky. Inlining a function that
4519  carries this attribute will cause the caller to gain the
4520  attribute. This is intended to provide a maximally conservative model
4521  where the code in a function annotated with this attribute will always
4522  (even after inlining) end up hardened.
4523  }];
4524}
4525
4526def NoSpeculativeLoadHardeningDocs : Documentation {
4527  let Category = DocCatFunction;
4528  let Content = [{
4529  This attribute can be applied to a function declaration in order to indicate
4530  that `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
4531  is *not* needed for the function body. This can also be applied to a method
4532  in Objective C. This attribute will take precedence over the command line flag in
4533  the case where `-mspeculative-load-hardening <https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mspeculative-load-hardening>`_ is specified.
4534
4535  Warning: This attribute may not prevent Speculative Load Hardening from being
4536  enabled for a function which inlines a function that has the
4537  'speculative_load_hardening' attribute. This is intended to provide a
4538  maximally conservative model where the code that is marked with the
4539  'speculative_load_hardening' attribute will always (even when inlined)
4540  be hardened. A user of this attribute may want to mark functions called by
4541  a function they do not want to be hardened with the 'noinline' attribute.
4542
4543  For example:
4544
4545  .. code-block:: c
4546
4547    __attribute__((speculative_load_hardening))
4548    int foo(int i) {
4549      return i;
4550    }
4551
4552    // Note: bar() may still have speculative load hardening enabled if
4553    // foo() is inlined into bar(). Mark foo() with __attribute__((noinline))
4554    // to avoid this situation.
4555    __attribute__((no_speculative_load_hardening))
4556    int bar(int i) {
4557      return foo(i);
4558    }
4559  }];
4560}
4561
4562def ObjCExternallyRetainedDocs : Documentation {
4563  let Category = DocCatVariable;
4564  let Content = [{
4565The ``objc_externally_retained`` attribute can be applied to strong local
4566variables, functions, methods, or blocks to opt into
4567`externally-retained semantics
4568<https://clang.llvm.org/docs/AutomaticReferenceCounting.html#externally-retained-variables>`_.
4569
4570When applied to the definition of a function, method, or block, every parameter
4571of the function with implicit strong retainable object pointer type is
4572considered externally-retained, and becomes ``const``. By explicitly annotating
4573a parameter with ``__strong``, you can opt back into the default
4574non-externally-retained behavior for that parameter. For instance,
4575``first_param`` is externally-retained below, but not ``second_param``:
4576
4577.. code-block:: objc
4578
4579  __attribute__((objc_externally_retained))
4580  void f(NSArray *first_param, __strong NSArray *second_param) {
4581    // ...
4582  }
4583
4584Likewise, when applied to a strong local variable, that variable becomes
4585``const`` and is considered externally-retained.
4586
4587When compiled without ``-fobjc-arc``, this attribute is ignored.
4588}]; }
4589
4590def MIGConventionDocs : Documentation {
4591  let Category = DocCatFunction;
4592  let Content = [{
4593  The Mach Interface Generator release-on-success convention dictates
4594functions that follow it to only release arguments passed to them when they
4595return "success" (a ``kern_return_t`` error code that indicates that
4596no errors have occurred). Otherwise the release is performed by the MIG client
4597that called the function. The annotation ``__attribute__((mig_server_routine))``
4598is applied in order to specify which functions are expected to follow the
4599convention. This allows the Static Analyzer to find bugs caused by violations of
4600that convention. The attribute would normally appear on the forward declaration
4601of the actual server routine in the MIG server header, but it may also be
4602added to arbitrary functions that need to follow the same convention - for
4603example, a user can add them to auxiliary functions called by the server routine
4604that have their return value of type ``kern_return_t`` unconditionally returned
4605from the routine. The attribute can be applied to C++ methods, and in this case
4606it will be automatically applied to overrides if the method is virtual. The
4607attribute can also be written using C++11 syntax: ``[[mig::server_routine]]``.
4608}];
4609}
4610
4611def MSAllocatorDocs : Documentation {
4612  let Category = DocCatFunction;
4613  let Content = [{
4614The ``__declspec(allocator)`` attribute is applied to functions that allocate
4615memory, such as operator new in C++. When CodeView debug information is emitted
4616(enabled by ``clang -gcodeview`` or ``clang-cl /Z7``), Clang will attempt to
4617record the code offset of heap allocation call sites in the debug info. It will
4618also record the type being allocated using some local heuristics. The Visual
4619Studio debugger uses this information to `profile memory usage`_.
4620
4621.. _profile memory usage: https://docs.microsoft.com/en-us/visualstudio/profiling/memory-usage
4622
4623This attribute does not affect optimizations in any way, unlike GCC's
4624``__attribute__((malloc))``.
4625}];
4626}
4627
4628def CFGuardDocs : Documentation {
4629  let Category = DocCatFunction;
4630  let Content = [{
4631Code can indicate CFG checks are not wanted with the ``__declspec(guard(nocf))``
4632attribute. This directs the compiler to not insert any CFG checks for the entire
4633function. This approach is typically used only sparingly in specific situations
4634where the programmer has manually inserted "CFG-equivalent" protection. The
4635programmer knows that they are calling through some read-only function table
4636whose address is obtained through read-only memory references and for which the
4637index is masked to the function table limit. This approach may also be applied
4638to small wrapper functions that are not inlined and that do nothing more than
4639make a call through a function pointer. Since incorrect usage of this directive
4640can compromise the security of CFG, the programmer must be very careful using
4641the directive. Typically, this usage is limited to very small functions that
4642only call one function.
4643
4644`Control Flow Guard documentation <https://docs.microsoft.com/en-us/windows/win32/secbp/pe-metadata>`
4645}];
4646}
4647
4648def CUDADeviceBuiltinSurfaceTypeDocs : Documentation {
4649  let Category = DocCatType;
4650  let Content = [{
4651The ``device_builtin_surface_type`` attribute can be applied to a class
4652template when declaring the surface reference. A surface reference variable
4653could be accessed on the host side and, on the device side, might be translated
4654into an internal surface object, which is established through surface bind and
4655unbind runtime APIs.
4656  }];
4657}
4658
4659def CUDADeviceBuiltinTextureTypeDocs : Documentation {
4660  let Category = DocCatType;
4661  let Content = [{
4662The ``device_builtin_texture_type`` attribute can be applied to a class
4663template when declaring the texture reference. A texture reference variable
4664could be accessed on the host side and, on the device side, might be translated
4665into an internal texture object, which is established through texture bind and
4666unbind runtime APIs.
4667  }];
4668}
4669
4670def LifetimeOwnerDocs : Documentation {
4671  let Category = DocCatDecl;
4672  let Content = [{
4673.. Note:: This attribute is experimental and its effect on analysis is subject to change in
4674  a future version of clang.
4675
4676The attribute ``[[gsl::Owner(T)]]`` applies to structs and classes that own an
4677object of type ``T``:
4678
4679.. code::
4680
4681  class [[gsl::Owner(int)]] IntOwner {
4682  private:
4683    int value;
4684  public:
4685    int *getInt() { return &value; }
4686  };
4687
4688The argument ``T`` is optional and is ignored.
4689This attribute may be used by analysis tools and has no effect on code
4690generation. A ``void`` argument means that the class can own any type.
4691
4692See Pointer_ for an example.
4693}];
4694}
4695
4696def LifetimePointerDocs : Documentation {
4697  let Category = DocCatDecl;
4698  let Content = [{
4699.. Note:: This attribute is experimental and its effect on analysis is subject to change in
4700  a future version of clang.
4701
4702The attribute ``[[gsl::Pointer(T)]]`` applies to structs and classes that behave
4703like pointers to an object of type ``T``:
4704
4705.. code::
4706
4707  class [[gsl::Pointer(int)]] IntPointer {
4708  private:
4709    int *valuePointer;
4710  public:
4711    int *getInt() { return &valuePointer; }
4712  };
4713
4714The argument ``T`` is optional and is ignored.
4715This attribute may be used by analysis tools and has no effect on code
4716generation. A ``void`` argument means that the pointer can point to any type.
4717
4718Example:
4719When constructing an instance of a class annotated like this (a Pointer) from
4720an instance of a class annotated with ``[[gsl::Owner]]`` (an Owner),
4721then the analysis will consider the Pointer to point inside the Owner.
4722When the Owner's lifetime ends, it will consider the Pointer to be dangling.
4723
4724.. code-block:: c++
4725
4726  int f() {
4727    IntPointer P;
4728    if (true) {
4729      IntOwner O(7);
4730      P = IntPointer(O); // P "points into" O
4731    } // P is dangling
4732    return P.get(); // error: Using a dangling Pointer.
4733  }
4734
4735}];
4736}
4737
4738def ArmBuiltinAliasDocs : Documentation {
4739  let Category = DocCatFunction;
4740  let Content = [{
4741This attribute is used in the implementation of the ACLE intrinsics.
4742It allows the intrinsic functions to
4743be declared using the names defined in ACLE, and still be recognized
4744as clang builtins equivalent to the underlying name. For example,
4745``arm_mve.h`` declares the function ``vaddq_u32`` with
4746``__attribute__((__clang_arm_mve_alias(__builtin_arm_mve_vaddq_u32)))``,
4747and similarly, one of the type-overloaded declarations of ``vaddq``
4748will have the same attribute. This ensures that both functions are
4749recognized as that clang builtin, and in the latter case, the choice
4750of which builtin to identify the function as can be deferred until
4751after overload resolution.
4752
4753This attribute can only be used to set up the aliases for certain Arm
4754intrinsic functions; it is intended for use only inside ``arm_*.h``
4755and is not a general mechanism for declaring arbitrary aliases for
4756clang builtin functions.
4757  }];
4758}
4759
4760def NoBuiltinDocs : Documentation {
4761  let Category = DocCatFunction;
4762  let Content = [{
4763.. Note:: This attribute is not yet fully implemented, it is validated but has
4764          no effect on the generated code.
4765
4766The ``__attribute__((no_builtin))`` is similar to the ``-fno-builtin`` flag
4767except it is specific to the body of a function. The attribute may also be
4768applied to a virtual function but has no effect on the behavior of overriding
4769functions in a derived class.
4770
4771It accepts one or more strings corresponding to the specific names of the
4772builtins to disable (e.g. "memcpy", "memset").
4773If the attribute is used without parameters it will disable all buitins at
4774once.
4775
4776.. code-block:: c++
4777
4778  // The compiler is not allowed to add any builtin to foo's body.
4779  void foo(char* data, size_t count) __attribute__((no_builtin)) {
4780    // The compiler is not allowed to convert the loop into
4781    // `__builtin_memset(data, 0xFE, count);`.
4782    for (size_t i = 0; i < count; ++i)
4783      data[i] = 0xFE;
4784  }
4785
4786  // The compiler is not allowed to add the `memcpy` builtin to bar's body.
4787  void bar(char* data, size_t count) __attribute__((no_builtin("memcpy"))) {
4788    // The compiler is allowed to convert the loop into
4789    // `__builtin_memset(data, 0xFE, count);` but cannot generate any
4790    // `__builtin_memcpy`
4791    for (size_t i = 0; i < count; ++i)
4792      data[i] = 0xFE;
4793  }
4794  }];
4795}
4796
4797def HandleDocs : DocumentationCategory<"Handle Attributes"> {
4798  let Content = [{
4799Handles are a way to identify resources like files, sockets, and processes.
4800They are more opaque than pointers and widely used in system programming. They
4801have similar risks such as never releasing a resource associated with a handle,
4802attempting to use a handle that was already released, or trying to release a
4803handle twice. Using the annotations below it is possible to make the ownership
4804of the handles clear: whose responsibility is to release them. They can also
4805aid static analysis tools to find bugs.
4806  }];
4807}
4808
4809def AcquireHandleDocs : Documentation {
4810  let Category = HandleDocs;
4811  let Content = [{
4812If this annotation is on a function or a function type it is assumed to return
4813a new handle. In case this annotation is on an output parameter,
4814the function is assumed to fill the corresponding argument with a new
4815handle.
4816
4817.. code-block:: c++
4818
4819  // Output arguments from Zircon.
4820  zx_status_t zx_socket_create(uint32_t options,
4821                               zx_handle_t __attribute__((acquire_handle)) * out0,
4822                               zx_handle_t* out1 [[clang::acquire_handle]]);
4823
4824
4825  // Returned handle.
4826  [[clang::acquire_handle]] int open(const char *path, int oflag, ... );
4827  int open(const char *path, int oflag, ... ) __attribute__((acquire_handle));
4828  }];
4829}
4830
4831def UseHandleDocs : Documentation {
4832  let Category = HandleDocs;
4833  let Content = [{
4834A function taking a handle by value might close the handle. If a function
4835parameter is annotated with ``use_handle`` it is assumed to not to change
4836the state of the handle. It is also assumed to require an open handle to work with.
4837
4838.. code-block:: c++
4839
4840  zx_status_t zx_port_wait(zx_handle_t handle [[clang::use_handle]],
4841                           zx_time_t deadline,
4842                           zx_port_packet_t* packet);
4843  }];
4844}
4845
4846def ReleaseHandleDocs : Documentation {
4847  let Category = HandleDocs;
4848  let Content = [{
4849If a function parameter is annotated with ``release_handle`` it is assumed to
4850close the handle. It is also assumed to require an open handle to work with.
4851
4852.. code-block:: c++
4853
4854  zx_status_t zx_handle_close(zx_handle_t handle [[clang::release_handle]]);
4855  }];
4856}
4857
4858def ArmMveStrictPolymorphismDocs : Documentation {
4859    let Category = DocCatType;
4860    let Content = [{
4861This attribute is used in the implementation of the ACLE intrinsics for the Arm
4862MVE instruction set. It is used to define the vector types used by the MVE
4863intrinsics.
4864
4865Its effect is to modify the behavior of a vector type with respect to function
4866overloading. If a candidate function for overload resolution has a parameter
4867type with this attribute, then the selection of that candidate function will be
4868disallowed if the actual argument can only be converted via a lax vector
4869conversion. The aim is to prevent spurious ambiguity in ARM MVE polymorphic
4870intrinsics.
4871
4872.. code-block:: c++
4873
4874  void overloaded(uint16x8_t vector, uint16_t scalar);
4875  void overloaded(int32x4_t vector, int32_t scalar);
4876  uint16x8_t myVector;
4877  uint16_t myScalar;
4878
4879  // myScalar is promoted to int32_t as a side effect of the addition,
4880  // so if lax vector conversions are considered for myVector, then
4881  // the two overloads are equally good (one argument conversion
4882  // each). But if the vector has the __clang_arm_mve_strict_polymorphism
4883  // attribute, only the uint16x8_t,uint16_t overload will match.
4884  overloaded(myVector, myScalar + 1);
4885
4886However, this attribute does not prohibit lax vector conversions in contexts
4887other than overloading.
4888
4889.. code-block:: c++
4890
4891  uint16x8_t function();
4892
4893  // This is still permitted with lax vector conversion enabled, even
4894  // if the vector types have __clang_arm_mve_strict_polymorphism
4895  int32x4_t result = function();
4896
4897    }];
4898}
4899
4900def ArmCmseNSCallDocs : Documentation {
4901  let Category = DocCatType;
4902  let Content = [{
4903This attribute declares a non-secure function type.  When compiling for secure
4904state, a call to such a function would switch from secure to non-secure state.
4905All non-secure function calls must happen only through a function pointer, and
4906a non-secure function type should only be used as a base type of a pointer.
4907See `ARMv8-M Security Extensions: Requirements on Development
4908Tools - Engineering Specification Documentation
4909<https://developer.arm.com/docs/ecm0359818/latest/>`_ for more information.
4910  }];
4911}
4912
4913def ArmCmseNSEntryDocs : Documentation {
4914  let Category = DocCatFunction;
4915  let Content = [{
4916This attribute declares a function that can be called from non-secure state, or
4917from secure state. Entering from and returning to non-secure state would switch
4918to and from secure state, respectively, and prevent flow of information
4919to non-secure state, except via return values. See `ARMv8-M Security Extensions:
4920Requirements on Development Tools - Engineering Specification Documentation
4921<https://developer.arm.com/docs/ecm0359818/latest/>`_ for more information.
4922  }];
4923}
4924