]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/Basic/AttrDocs.td
Vendor import of clang trunk r242221:
[FreeBSD/FreeBSD.git] / include / clang / Basic / AttrDocs.td
1 //==--- AttrDocs.td - Attribute documentation ----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===---------------------------------------------------------------------===//
9
10 def GlobalDocumentation {
11   code Intro =[{..
12   -------------------------------------------------------------------
13   NOTE: This file is automatically generated by running clang-tblgen
14   -gen-attr-docs. Do not edit this file by hand!!
15   -------------------------------------------------------------------
16
17 ===================
18 Attributes in Clang
19 ===================
20 .. contents::
21    :local:
22
23 Introduction
24 ============
25
26 This page lists the attributes currently supported by Clang.
27 }];
28 }
29
30 def SectionDocs : Documentation {
31   let Category = DocCatVariable;
32   let Content = [{
33 The ``section`` attribute allows you to specify a specific section a
34 global variable or function should be in after translation.
35   }];
36   let Heading = "section (gnu::section, __declspec(allocate))";
37 }
38
39 def InitSegDocs : Documentation {
40   let Category = DocCatVariable;
41   let Content = [{
42 The attribute applied by ``pragma init_seg()`` controls the section into
43 which global initialization function pointers are emitted.  It is only
44 available with ``-fms-extensions``.  Typically, this function pointer is
45 emitted into ``.CRT$XCU`` on Windows.  The user can change the order of
46 initialization by using a different section name with the same
47 ``.CRT$XC`` prefix and a suffix that sorts lexicographically before or
48 after the standard ``.CRT$XCU`` sections.  See the init_seg_
49 documentation on MSDN for more information.
50
51 .. _init_seg: http://msdn.microsoft.com/en-us/library/7977wcck(v=vs.110).aspx
52   }];
53 }
54
55 def TLSModelDocs : Documentation {
56   let Category = DocCatVariable;
57   let Content = [{
58 The ``tls_model`` attribute allows you to specify which thread-local storage
59 model to use. It accepts the following strings:
60
61 * global-dynamic
62 * local-dynamic
63 * initial-exec
64 * local-exec
65
66 TLS models are mutually exclusive.
67   }];
68 }
69
70 def ThreadDocs : Documentation {
71   let Category = DocCatVariable;
72   let Content = [{
73 The ``__declspec(thread)`` attribute declares a variable with thread local
74 storage.  It is available under the ``-fms-extensions`` flag for MSVC
75 compatibility.  See the documentation for `__declspec(thread)`_ on MSDN.
76
77 .. _`__declspec(thread)`: http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx
78
79 In Clang, ``__declspec(thread)`` is generally equivalent in functionality to the
80 GNU ``__thread`` keyword.  The variable must not have a destructor and must have
81 a constant initializer, if any.  The attribute only applies to variables
82 declared with static storage duration, such as globals, class static data
83 members, and static locals.
84   }];
85 }
86
87 def CarriesDependencyDocs : Documentation {
88   let Category = DocCatFunction;
89   let Content = [{
90 The ``carries_dependency`` attribute specifies dependency propagation into and
91 out of functions.
92
93 When specified on a function or Objective-C method, the ``carries_dependency``
94 attribute means that the return value carries a dependency out of the function, 
95 so that the implementation need not constrain ordering upon return from that
96 function. Implementations of the function and its caller may choose to preserve
97 dependencies instead of emitting memory ordering instructions such as fences.
98
99 Note, this attribute does not change the meaning of the program, but may result
100 in generation of more efficient code.
101   }];
102 }
103
104 def C11NoReturnDocs : Documentation {
105   let Category = DocCatFunction;
106   let Content = [{
107 A function declared as ``_Noreturn`` shall not return to its caller. The
108 compiler will generate a diagnostic for a function declared as ``_Noreturn``
109 that appears to be capable of returning to its caller.
110   }];
111 }
112
113 def CXX11NoReturnDocs : Documentation {
114   let Category = DocCatFunction;
115   let Content = [{
116 A function declared as ``[[noreturn]]`` shall not return to its caller. The
117 compiler will generate a diagnostic for a function declared as ``[[noreturn]]``
118 that appears to be capable of returning to its caller.
119   }];
120 }
121
122 def AssertCapabilityDocs : Documentation {
123   let Category = DocCatFunction;
124   let Heading = "assert_capability (assert_shared_capability, clang::assert_capability, clang::assert_shared_capability)";
125   let Content = [{
126 Marks a function that dynamically tests whether a capability is held, and halts
127 the program if it is not held.
128   }];
129 }
130
131 def AcquireCapabilityDocs : Documentation {
132   let Category = DocCatFunction;
133   let Heading = "acquire_capability (acquire_shared_capability, clang::acquire_capability, clang::acquire_shared_capability)";
134   let Content = [{
135 Marks a function as acquiring a capability.
136   }];
137 }
138
139 def TryAcquireCapabilityDocs : Documentation {
140   let Category = DocCatFunction;
141   let Heading = "try_acquire_capability (try_acquire_shared_capability, clang::try_acquire_capability, clang::try_acquire_shared_capability)";
142   let Content = [{
143 Marks a function that attempts to acquire a capability. This function may fail to
144 actually acquire the capability; they accept a Boolean value determining
145 whether acquiring the capability means success (true), or failing to acquire
146 the capability means success (false).
147   }];
148 }
149
150 def ReleaseCapabilityDocs : Documentation {
151   let Category = DocCatFunction;
152   let Heading = "release_capability (release_shared_capability, clang::release_capability, clang::release_shared_capability)";
153   let Content = [{
154 Marks a function as releasing a capability.
155   }];
156 }
157
158 def AssumeAlignedDocs : Documentation {
159   let Category = DocCatFunction;
160   let Content = [{
161 Use ``__attribute__((assume_aligned(<alignment>[,<offset>]))`` on a function
162 declaration to specify that the return value of the function (which must be a
163 pointer type) has the specified offset, in bytes, from an address with the
164 specified alignment. The offset is taken to be zero if omitted.
165
166 .. code-block:: c++
167
168   // The returned pointer value has 32-byte alignment.
169   void *a() __attribute__((assume_aligned (32)));
170
171   // The returned pointer value is 4 bytes greater than an address having
172   // 32-byte alignment.
173   void *b() __attribute__((assume_aligned (32, 4)));
174
175 Note that this attribute provides information to the compiler regarding a
176 condition that the code already ensures is true. It does not cause the compiler
177 to enforce the provided alignment assumption.
178   }];
179 }
180
181 def EnableIfDocs : Documentation {
182   let Category = DocCatFunction;
183   let Content = [{
184 .. Note:: Some features of this attribute are experimental. The meaning of\r
185   multiple enable_if attributes on a single declaration is subject to change in\r
186   a future version of clang. Also, the ABI is not standardized and the name\r
187   mangling may change in future versions. To avoid that, use asm labels.
188
189 The ``enable_if`` attribute can be placed on function declarations to control
190 which overload is selected based on the values of the function's arguments.
191 When combined with the ``overloadable`` attribute, this feature is also
192 available in C.
193
194 .. code-block:: c++
195
196   int isdigit(int c);
197   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")));
198   
199   void foo(char c) {
200     isdigit(c);
201     isdigit(10);
202     isdigit(-10);  // results in a compile-time error.
203   }
204
205 The enable_if attribute takes two arguments, the first is an expression written
206 in terms of the function parameters, the second is a string explaining why this
207 overload candidate could not be selected to be displayed in diagnostics. The
208 expression is part of the function signature for the purposes of determining
209 whether it is a redeclaration (following the rules used when determining
210 whether a C++ template specialization is ODR-equivalent), but is not part of
211 the type.
212
213 The enable_if expression is evaluated as if it were the body of a
214 bool-returning constexpr function declared with the arguments of the function
215 it is being applied to, then called with the parameters at the call site. If the
216 result is false or could not be determined through constant expression
217 evaluation, then this overload will not be chosen and the provided string may
218 be used in a diagnostic if the compile fails as a result.
219
220 Because the enable_if expression is an unevaluated context, there are no global
221 state changes, nor the ability to pass information from the enable_if
222 expression to the function body. For example, suppose we want calls to
223 strnlen(strbuf, maxlen) to resolve to strnlen_chk(strbuf, maxlen, size of
224 strbuf) only if the size of strbuf can be determined:
225
226 .. code-block:: c++
227
228   __attribute__((always_inline))
229   static inline size_t strnlen(const char *s, size_t maxlen)
230     __attribute__((overloadable))
231     __attribute__((enable_if(__builtin_object_size(s, 0) != -1))),
232                              "chosen when the buffer size is known but 'maxlen' is not")))
233   {
234     return strnlen_chk(s, maxlen, __builtin_object_size(s, 0));
235   }
236
237 Multiple enable_if attributes may be applied to a single declaration. In this
238 case, the enable_if expressions are evaluated from left to right in the
239 following manner. First, the candidates whose enable_if expressions evaluate to
240 false or cannot be evaluated are discarded. If the remaining candidates do not
241 share ODR-equivalent enable_if expressions, the overload resolution is
242 ambiguous. Otherwise, enable_if overload resolution continues with the next
243 enable_if attribute on the candidates that have not been discarded and have
244 remaining enable_if attributes. In this way, we pick the most specific
245 overload out of a number of viable overloads using enable_if.
246
247 .. code-block:: c++
248
249   void f() __attribute__((enable_if(true, "")));  // #1
250   void f() __attribute__((enable_if(true, ""))) __attribute__((enable_if(true, "")));  // #2
251   
252   void g(int i, int j) __attribute__((enable_if(i, "")));  // #1
253   void g(int i, int j) __attribute__((enable_if(j, ""))) __attribute__((enable_if(true)));  // #2
254
255 In this example, a call to f() is always resolved to #2, as the first enable_if
256 expression is ODR-equivalent for both declarations, but #1 does not have another
257 enable_if expression to continue evaluating, so the next round of evaluation has
258 only a single candidate. In a call to g(1, 1), the call is ambiguous even though
259 #2 has more enable_if attributes, because the first enable_if expressions are
260 not ODR-equivalent.
261
262 Query for this feature with ``__has_attribute(enable_if)``.
263   }];
264 }
265
266 def OverloadableDocs : Documentation {
267   let Category = DocCatFunction;
268   let Content = [{
269 Clang provides support for C++ function overloading in C.  Function overloading
270 in C is introduced using the ``overloadable`` attribute.  For example, one
271 might provide several overloaded versions of a ``tgsin`` function that invokes
272 the appropriate standard function computing the sine of a value with ``float``,
273 ``double``, or ``long double`` precision:
274
275 .. code-block:: c
276
277   #include <math.h>
278   float __attribute__((overloadable)) tgsin(float x) { return sinf(x); }
279   double __attribute__((overloadable)) tgsin(double x) { return sin(x); }
280   long double __attribute__((overloadable)) tgsin(long double x) { return sinl(x); }
281
282 Given these declarations, one can call ``tgsin`` with a ``float`` value to
283 receive a ``float`` result, with a ``double`` to receive a ``double`` result,
284 etc.  Function overloading in C follows the rules of C++ function overloading
285 to pick the best overload given the call arguments, with a few C-specific
286 semantics:
287
288 * Conversion from ``float`` or ``double`` to ``long double`` is ranked as a
289   floating-point promotion (per C99) rather than as a floating-point conversion
290   (as in C++).
291
292 * A conversion from a pointer of type ``T*`` to a pointer of type ``U*`` is
293   considered a pointer conversion (with conversion rank) if ``T`` and ``U`` are
294   compatible types.
295
296 * A conversion from type ``T`` to a value of type ``U`` is permitted if ``T``
297   and ``U`` are compatible types.  This conversion is given "conversion" rank.
298
299 The declaration of ``overloadable`` functions is restricted to function
300 declarations and definitions.  Most importantly, if any function with a given
301 name is given the ``overloadable`` attribute, then all function declarations
302 and definitions with that name (and in that scope) must have the
303 ``overloadable`` attribute.  This rule even applies to redeclarations of
304 functions whose original declaration had the ``overloadable`` attribute, e.g.,
305
306 .. code-block:: c
307
308   int f(int) __attribute__((overloadable));
309   float f(float); // error: declaration of "f" must have the "overloadable" attribute
310
311   int g(int) __attribute__((overloadable));
312   int g(int) { } // error: redeclaration of "g" must also have the "overloadable" attribute
313
314 Functions marked ``overloadable`` must have prototypes.  Therefore, the
315 following code is ill-formed:
316
317 .. code-block:: c
318
319   int h() __attribute__((overloadable)); // error: h does not have a prototype
320
321 However, ``overloadable`` functions are allowed to use a ellipsis even if there
322 are no named parameters (as is permitted in C++).  This feature is particularly
323 useful when combined with the ``unavailable`` attribute:
324
325 .. code-block:: c++
326
327   void honeypot(...) __attribute__((overloadable, unavailable)); // calling me is an error
328
329 Functions declared with the ``overloadable`` attribute have their names mangled
330 according to the same rules as C++ function names.  For example, the three
331 ``tgsin`` functions in our motivating example get the mangled names
332 ``_Z5tgsinf``, ``_Z5tgsind``, and ``_Z5tgsine``, respectively.  There are two
333 caveats to this use of name mangling:
334
335 * Future versions of Clang may change the name mangling of functions overloaded
336   in C, so you should not depend on an specific mangling.  To be completely
337   safe, we strongly urge the use of ``static inline`` with ``overloadable``
338   functions.
339
340 * The ``overloadable`` attribute has almost no meaning when used in C++,
341   because names will already be mangled and functions are already overloadable.
342   However, when an ``overloadable`` function occurs within an ``extern "C"``
343   linkage specification, it's name *will* be mangled in the same way as it
344   would in C.
345
346 Query for this feature with ``__has_extension(attribute_overloadable)``.
347   }];
348 }
349
350 def ObjCMethodFamilyDocs : Documentation {
351   let Category = DocCatFunction;
352   let Content = [{
353 Many methods in Objective-C have conventional meanings determined by their
354 selectors. It is sometimes useful to be able to mark a method as having a
355 particular conventional meaning despite not having the right selector, or as
356 not having the conventional meaning that its selector would suggest. For these
357 use cases, we provide an attribute to specifically describe the "method family"
358 that a method belongs to.
359
360 **Usage**: ``__attribute__((objc_method_family(X)))``, where ``X`` is one of
361 ``none``, ``alloc``, ``copy``, ``init``, ``mutableCopy``, or ``new``.  This
362 attribute can only be placed at the end of a method declaration:
363
364 .. code-block:: objc
365
366   - (NSString *)initMyStringValue __attribute__((objc_method_family(none)));
367
368 Users who do not wish to change the conventional meaning of a method, and who
369 merely want to document its non-standard retain and release semantics, should
370 use the retaining behavior attributes (``ns_returns_retained``,
371 ``ns_returns_not_retained``, etc).
372
373 Query for this feature with ``__has_attribute(objc_method_family)``.
374   }];
375 }
376
377 def NoDuplicateDocs : Documentation {
378   let Category = DocCatFunction;
379   let Content = [{
380 The ``noduplicate`` attribute can be placed on function declarations to control
381 whether function calls to this function can be duplicated or not as a result of
382 optimizations. This is required for the implementation of functions with
383 certain special requirements, like the OpenCL "barrier" function, that might
384 need to be run concurrently by all the threads that are executing in lockstep
385 on the hardware. For example this attribute applied on the function
386 "nodupfunc" in the code below avoids that:
387
388 .. code-block:: c
389
390   void nodupfunc() __attribute__((noduplicate));
391   // Setting it as a C++11 attribute is also valid
392   // void nodupfunc() [[clang::noduplicate]];
393   void foo();
394   void bar();
395
396   nodupfunc();
397   if (a > n) {
398     foo();
399   } else {
400     bar();
401   }
402
403 gets possibly modified by some optimizations into code similar to this:
404
405 .. code-block:: c
406
407   if (a > n) {
408     nodupfunc();
409     foo();
410   } else {
411     nodupfunc();
412     bar();
413   }
414
415 where the call to "nodupfunc" is duplicated and sunk into the two branches
416 of the condition.
417   }];
418 }
419
420 def NoSplitStackDocs : Documentation {
421   let Category = DocCatFunction;
422   let Content = [{
423 The ``no_split_stack`` attribute disables the emission of the split stack
424 preamble for a particular function. It has no effect if ``-fsplit-stack``
425 is not specified.
426   }];
427 }
428
429 def ObjCRequiresSuperDocs : Documentation {
430   let Category = DocCatFunction;
431   let Content = [{
432 Some Objective-C classes allow a subclass to override a particular method in a
433 parent class but expect that the overriding method also calls the overridden
434 method in the parent class. For these cases, we provide an attribute to
435 designate that a method requires a "call to ``super``" in the overriding
436 method in the subclass.
437
438 **Usage**: ``__attribute__((objc_requires_super))``.  This attribute can only
439 be placed at the end of a method declaration:
440
441 .. code-block:: objc
442
443   - (void)foo __attribute__((objc_requires_super));
444
445 This attribute can only be applied the method declarations within a class, and
446 not a protocol.  Currently this attribute does not enforce any placement of
447 where the call occurs in the overriding method (such as in the case of
448 ``-dealloc`` where the call must appear at the end).  It checks only that it
449 exists.
450
451 Note that on both OS X and iOS that the Foundation framework provides a
452 convenience macro ``NS_REQUIRES_SUPER`` that provides syntactic sugar for this
453 attribute:
454
455 .. code-block:: objc
456
457   - (void)foo NS_REQUIRES_SUPER;
458
459 This macro is conditionally defined depending on the compiler's support for
460 this attribute.  If the compiler does not support the attribute the macro
461 expands to nothing.
462
463 Operationally, when a method has this annotation the compiler will warn if the
464 implementation of an override in a subclass does not call super.  For example:
465
466 .. code-block:: objc
467
468    warning: method possibly missing a [super AnnotMeth] call
469    - (void) AnnotMeth{};
470                       ^
471   }];
472 }
473
474 def ObjCRuntimeNameDocs : Documentation {
475     let Category = DocCatFunction;
476     let Content = [{
477 By default, the Objective-C interface or protocol identifier is used
478 in the metadata name for that object. The `objc_runtime_name`
479 attribute allows annotated interfaces or protocols to use the
480 specified string argument in the object's metadata name instead of the
481 default name.
482         
483 **Usage**: ``__attribute__((objc_runtime_name("MyLocalName")))``.  This attribute
484 can only be placed before an @protocol or @interface declaration:
485         
486 .. code-block:: objc
487         
488   __attribute__((objc_runtime_name("MyLocalName")))
489   @interface Message
490   @end
491         
492     }];
493 }
494
495 def AvailabilityDocs : Documentation {
496   let Category = DocCatFunction;
497   let Content = [{
498 The ``availability`` attribute can be placed on declarations to describe the
499 lifecycle of that declaration relative to operating system versions.  Consider
500 the function declaration for a hypothetical function ``f``:
501
502 .. code-block:: c++
503
504   void f(void) __attribute__((availability(macosx,introduced=10.4,deprecated=10.6,obsoleted=10.7)));
505
506 The availability attribute states that ``f`` was introduced in Mac OS X 10.4,
507 deprecated in Mac OS X 10.6, and obsoleted in Mac OS X 10.7.  This information
508 is used by Clang to determine when it is safe to use ``f``: for example, if
509 Clang is instructed to compile code for Mac OS X 10.5, a call to ``f()``
510 succeeds.  If Clang is instructed to compile code for Mac OS X 10.6, the call
511 succeeds but Clang emits a warning specifying that the function is deprecated.
512 Finally, if Clang is instructed to compile code for Mac OS X 10.7, the call
513 fails because ``f()`` is no longer available.
514
515 The availability attribute is a comma-separated list starting with the
516 platform name and then including clauses specifying important milestones in the
517 declaration's lifetime (in any order) along with additional information.  Those
518 clauses can be:
519
520 introduced=\ *version*
521   The first version in which this declaration was introduced.
522
523 deprecated=\ *version*
524   The first version in which this declaration was deprecated, meaning that
525   users should migrate away from this API.
526
527 obsoleted=\ *version*
528   The first version in which this declaration was obsoleted, meaning that it
529   was removed completely and can no longer be used.
530
531 unavailable
532   This declaration is never available on this platform.
533
534 message=\ *string-literal*
535   Additional message text that Clang will provide when emitting a warning or
536   error about use of a deprecated or obsoleted declaration.  Useful to direct
537   users to replacement APIs.
538
539 Multiple availability attributes can be placed on a declaration, which may
540 correspond to different platforms.  Only the availability attribute with the
541 platform corresponding to the target platform will be used; any others will be
542 ignored.  If no availability attribute specifies availability for the current
543 target platform, the availability attributes are ignored.  Supported platforms
544 are:
545
546 ``ios``
547   Apple's iOS operating system.  The minimum deployment target is specified by
548   the ``-mios-version-min=*version*`` or ``-miphoneos-version-min=*version*``
549   command-line arguments.
550
551 ``macosx``
552   Apple's Mac OS X operating system.  The minimum deployment target is
553   specified by the ``-mmacosx-version-min=*version*`` command-line argument.
554
555 A declaration can be used even when deploying back to a platform version prior
556 to when the declaration was introduced.  When this happens, the declaration is
557 `weakly linked
558 <https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html>`_,
559 as if the ``weak_import`` attribute were added to the declaration.  A
560 weakly-linked declaration may or may not be present a run-time, and a program
561 can determine whether the declaration is present by checking whether the
562 address of that declaration is non-NULL.
563
564 If there are multiple declarations of the same entity, the availability
565 attributes must either match on a per-platform basis or later
566 declarations must not have availability attributes for that
567 platform. For example:
568
569 .. code-block:: c
570
571   void g(void) __attribute__((availability(macosx,introduced=10.4)));
572   void g(void) __attribute__((availability(macosx,introduced=10.4))); // okay, matches
573   void g(void) __attribute__((availability(ios,introduced=4.0))); // okay, adds a new platform
574   void g(void); // okay, inherits both macosx and ios availability from above.
575   void g(void) __attribute__((availability(macosx,introduced=10.5))); // error: mismatch
576
577 When one method overrides another, the overriding method can be more widely available than the overridden method, e.g.,:
578
579 .. code-block:: objc
580
581   @interface A
582   - (id)method __attribute__((availability(macosx,introduced=10.4)));
583   - (id)method2 __attribute__((availability(macosx,introduced=10.4)));
584   @end
585
586   @interface B : A
587   - (id)method __attribute__((availability(macosx,introduced=10.3))); // okay: method moved into base class later
588   - (id)method __attribute__((availability(macosx,introduced=10.5))); // error: this method was available via the base class in 10.4
589   @end
590   }];
591 }
592
593 def FallthroughDocs : Documentation {
594   let Category = DocCatStmt;
595   let Content = [{
596 The ``clang::fallthrough`` attribute is used along with the
597 ``-Wimplicit-fallthrough`` argument to annotate intentional fall-through
598 between switch labels.  It can only be applied to a null statement placed at a
599 point of execution between any statement and the next switch label.  It is
600 common to mark these places with a specific comment, but this attribute is
601 meant to replace comments with a more strict annotation, which can be checked
602 by the compiler.  This attribute doesn't change semantics of the code and can
603 be used wherever an intended fall-through occurs.  It is designed to mimic
604 control-flow statements like ``break;``, so it can be placed in most places
605 where ``break;`` can, but only if there are no statements on the execution path
606 between it and the next switch label.
607
608 Here is an example:
609
610 .. code-block:: c++
611
612   // compile with -Wimplicit-fallthrough
613   switch (n) {
614   case 22:
615   case 33:  // no warning: no statements between case labels
616     f();
617   case 44:  // warning: unannotated fall-through
618     g();
619     [[clang::fallthrough]];
620   case 55:  // no warning
621     if (x) {
622       h();
623       break;
624     }
625     else {
626       i();
627       [[clang::fallthrough]];
628     }
629   case 66:  // no warning
630     p();
631     [[clang::fallthrough]]; // warning: fallthrough annotation does not
632                             //          directly precede case label
633     q();
634   case 77:  // warning: unannotated fall-through
635     r();
636   }
637   }];
638 }
639
640 def ARMInterruptDocs : Documentation {
641   let Category = DocCatFunction;
642   let Content = [{
643 Clang supports the GNU style ``__attribute__((interrupt("TYPE")))`` attribute on
644 ARM targets. This attribute may be attached to a function definition and
645 instructs the backend to generate appropriate function entry/exit code so that
646 it can be used directly as an interrupt service routine.
647
648 The parameter passed to the interrupt attribute is optional, but if
649 provided it must be a string literal with one of the following values: "IRQ",
650 "FIQ", "SWI", "ABORT", "UNDEF".
651
652 The semantics are as follows:
653
654 - If the function is AAPCS, Clang instructs the backend to realign the stack to
655   8 bytes on entry. This is a general requirement of the AAPCS at public
656   interfaces, but may not hold when an exception is taken. Doing this allows
657   other AAPCS functions to be called.
658 - If the CPU is M-class this is all that needs to be done since the architecture
659   itself is designed in such a way that functions obeying the normal AAPCS ABI
660   constraints are valid exception handlers.
661 - If the CPU is not M-class, the prologue and epilogue are modified to save all
662   non-banked registers that are used, so that upon return the user-mode state
663   will not be corrupted. Note that to avoid unnecessary overhead, only
664   general-purpose (integer) registers are saved in this way. If VFP operations
665   are needed, that state must be saved manually.
666
667   Specifically, interrupt kinds other than "FIQ" will save all core registers
668   except "lr" and "sp". "FIQ" interrupts will save r0-r7.
669 - If the CPU is not M-class, the return instruction is changed to one of the
670   canonical sequences permitted by the architecture for exception return. Where
671   possible the function itself will make the necessary "lr" adjustments so that
672   the "preferred return address" is selected.
673
674   Unfortunately the compiler is unable to make this guarantee for an "UNDEF"
675   handler, where the offset from "lr" to the preferred return address depends on
676   the execution state of the code which generated the exception. In this case
677   a sequence equivalent to "movs pc, lr" will be used.
678   }];
679 }
680
681 def TargetDocs : Documentation {
682   let Category = DocCatFunction;
683   let Content = [{
684 Clang supports the GNU style ``__attribute__((target("OPTIONS")))`` attribute.
685 This attribute may be attached to a function definition and instructs
686 the backend to use different code generation options than were passed on the
687 command line.
688
689 The current set of options correspond to the existing "subtarget features" for
690 the target with or without a "-mno-" in front corresponding to the absence
691 of the feature, as well as ``arch="CPU"`` which will change the default "CPU"
692 for the function.
693
694 Example "subtarget features" from the x86 backend include: "mmx", "sse", "sse4.2",
695 "avx", "xop" and largely correspond to the machine specific options handled by
696 the front end.
697 }];
698 }
699
700 def DocCatAMDGPURegisterAttributes :
701   DocumentationCategory<"AMD GPU Register Attributes"> {
702   let Content = [{
703 Clang supports attributes for controlling register usage on AMD GPU
704 targets. These attributes may be attached to a kernel function
705 definition and is an optimization hint to the backend for the maximum
706 number of registers to use. This is useful in cases where register
707 limited occupancy is known to be an important factor for the
708 performance for the kernel.
709
710 The semantics are as follows:
711
712 - The backend will attempt to limit the number of used registers to
713   the specified value, but the exact number used is not
714   guaranteed. The number used may be rounded up to satisfy the
715   allocation requirements or ABI constraints of the subtarget. For
716   example, on Southern Islands VGPRs may only be allocated in
717   increments of 4, so requesting a limit of 39 VGPRs will really
718   attempt to use up to 40. Requesting more registers than the
719   subtarget supports will truncate to the maximum allowed. The backend
720   may also use fewer registers than requested whenever possible.
721
722 - 0 implies the default no limit on register usage.
723
724 - Ignored on older VLIW subtargets which did not have separate scalar
725   and vector registers, R600 through Northern Islands.
726
727 }];
728 }
729
730
731 def AMDGPUNumVGPRDocs : Documentation {
732   let Category = DocCatAMDGPURegisterAttributes;
733   let Content = [{
734 Clang supports the
735 ``__attribute__((amdgpu_num_vgpr(<num_registers>)))`` attribute on AMD
736 Southern Islands GPUs and later for controlling the number of vector
737 registers. A typical value would be between 4 and 256 in increments
738 of 4.
739 }];
740 }
741
742 def AMDGPUNumSGPRDocs : Documentation {
743   let Category = DocCatAMDGPURegisterAttributes;
744   let Content = [{
745
746 Clang supports the
747 ``__attribute__((amdgpu_num_sgpr(<num_registers>)))`` attribute on AMD
748 Southern Islands GPUs and later for controlling the number of scalar
749 registers. A typical value would be between 8 and 104 in increments of
750 8.
751
752 Due to common instruction constraints, an additional 2-4 SGPRs are
753 typically required for internal use depending on features used. This
754 value is a hint for the total number of SGPRs to use, and not the
755 number of user SGPRs, so no special consideration needs to be given
756 for these.
757 }];
758 }
759
760 def DocCatCallingConvs : DocumentationCategory<"Calling Conventions"> {
761   let Content = [{
762 Clang supports several different calling conventions, depending on the target
763 platform and architecture. The calling convention used for a function determines
764 how parameters are passed, how results are returned to the caller, and other
765 low-level details of calling a function.
766   }];
767 }
768
769 def PcsDocs : Documentation {
770   let Category = DocCatCallingConvs;
771   let Content = [{
772 On ARM targets, this attribute can be used to select calling conventions
773 similar to ``stdcall`` on x86. Valid parameter values are "aapcs" and
774 "aapcs-vfp".
775   }];
776 }
777
778 def RegparmDocs : Documentation {
779   let Category = DocCatCallingConvs;
780   let Content = [{
781 On 32-bit x86 targets, the regparm attribute causes the compiler to pass
782 the first three integer parameters in EAX, EDX, and ECX instead of on the
783 stack. This attribute has no effect on variadic functions, and all parameters
784 are passed via the stack as normal.
785   }];
786 }
787
788 def SysVABIDocs : Documentation {
789   let Category = DocCatCallingConvs;
790   let Content = [{
791 On Windows x86_64 targets, this attribute changes the calling convention of a
792 function to match the default convention used on Sys V targets such as Linux,
793 Mac, and BSD. This attribute has no effect on other targets.
794   }];
795 }
796
797 def MSABIDocs : Documentation {
798   let Category = DocCatCallingConvs;
799   let Content = [{
800 On non-Windows x86_64 targets, this attribute changes the calling convention of
801 a function to match the default convention used on Windows x86_64. This
802 attribute has no effect on Windows targets or non-x86_64 targets.
803   }];
804 }
805
806 def StdCallDocs : Documentation {
807   let Category = DocCatCallingConvs;
808   let Content = [{
809 On 32-bit x86 targets, this attribute changes the calling convention of a
810 function to clear parameters off of the stack on return. This convention does
811 not support variadic calls or unprototyped functions in C, and has no effect on
812 x86_64 targets. This calling convention is used widely by the Windows API and
813 COM applications.  See the documentation for `__stdcall`_ on MSDN.
814
815 .. _`__stdcall`: http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx
816   }];
817 }
818
819 def FastCallDocs : Documentation {
820   let Category = DocCatCallingConvs;
821   let Content = [{
822 On 32-bit x86 targets, this attribute changes the calling convention of a
823 function to use ECX and EDX as register parameters and clear parameters off of
824 the stack on return. This convention does not support variadic calls or
825 unprototyped functions in C, and has no effect on x86_64 targets. This calling
826 convention is supported primarily for compatibility with existing code. Users
827 seeking register parameters should use the ``regparm`` attribute, which does
828 not require callee-cleanup.  See the documentation for `__fastcall`_ on MSDN.
829
830 .. _`__fastcall`: http://msdn.microsoft.com/en-us/library/6xa169sk.aspx
831   }];
832 }
833
834 def ThisCallDocs : Documentation {
835   let Category = DocCatCallingConvs;
836   let Content = [{
837 On 32-bit x86 targets, this attribute changes the calling convention of a
838 function to use ECX for the first parameter (typically the implicit ``this``
839 parameter of C++ methods) and clear parameters off of the stack on return. This
840 convention does not support variadic calls or unprototyped functions in C, and
841 has no effect on x86_64 targets. See the documentation for `__thiscall`_ on
842 MSDN.
843
844 .. _`__thiscall`: http://msdn.microsoft.com/en-us/library/ek8tkfbw.aspx
845   }];
846 }
847
848 def VectorCallDocs : Documentation {
849   let Category = DocCatCallingConvs;
850   let Content = [{
851 On 32-bit x86 *and* x86_64 targets, this attribute changes the calling
852 convention of a function to pass vector parameters in SSE registers.
853
854 On 32-bit x86 targets, this calling convention is similar to ``__fastcall``.
855 The first two integer parameters are passed in ECX and EDX. Subsequent integer
856 parameters are passed in memory, and callee clears the stack.  On x86_64
857 targets, the callee does *not* clear the stack, and integer parameters are
858 passed in RCX, RDX, R8, and R9 as is done for the default Windows x64 calling
859 convention.
860
861 On both 32-bit x86 and x86_64 targets, vector and floating point arguments are
862 passed in XMM0-XMM5. Homogenous vector aggregates of up to four elements are
863 passed in sequential SSE registers if enough are available. If AVX is enabled,
864 256 bit vectors are passed in YMM0-YMM5. Any vector or aggregate type that
865 cannot be passed in registers for any reason is passed by reference, which
866 allows the caller to align the parameter memory.
867
868 See the documentation for `__vectorcall`_ on MSDN for more details.
869
870 .. _`__vectorcall`: http://msdn.microsoft.com/en-us/library/dn375768.aspx
871   }];
872 }
873
874 def DocCatConsumed : DocumentationCategory<"Consumed Annotation Checking"> {
875   let Content = [{
876 Clang supports additional attributes for checking basic resource management
877 properties, specifically for unique objects that have a single owning reference.
878 The following attributes are currently supported, although **the implementation
879 for these annotations is currently in development and are subject to change.**
880   }];
881 }
882
883 def SetTypestateDocs : Documentation {
884   let Category = DocCatConsumed;
885   let Content = [{
886 Annotate methods that transition an object into a new state with
887 ``__attribute__((set_typestate(new_state)))``.  The new state must be
888 unconsumed, consumed, or unknown.
889   }];
890 }
891
892 def CallableWhenDocs : Documentation {
893   let Category = DocCatConsumed;
894   let Content = [{
895 Use ``__attribute__((callable_when(...)))`` to indicate what states a method
896 may be called in.  Valid states are unconsumed, consumed, or unknown.  Each
897 argument to this attribute must be a quoted string.  E.g.:
898
899 ``__attribute__((callable_when("unconsumed", "unknown")))``
900   }];
901 }
902
903 def TestTypestateDocs : Documentation {
904   let Category = DocCatConsumed;
905   let Content = [{
906 Use ``__attribute__((test_typestate(tested_state)))`` to indicate that a method
907 returns true if the object is in the specified state..
908   }];
909 }
910
911 def ParamTypestateDocs : Documentation {
912   let Category = DocCatConsumed;
913   let Content = [{
914 This attribute specifies expectations about function parameters.  Calls to an
915 function with annotated parameters will issue a warning if the corresponding
916 argument isn't in the expected state.  The attribute is also used to set the
917 initial state of the parameter when analyzing the function's body.
918   }];
919 }
920
921 def ReturnTypestateDocs : Documentation {
922   let Category = DocCatConsumed;
923   let Content = [{
924 The ``return_typestate`` attribute can be applied to functions or parameters.
925 When applied to a function the attribute specifies the state of the returned
926 value.  The function's body is checked to ensure that it always returns a value
927 in the specified state.  On the caller side, values returned by the annotated
928 function are initialized to the given state.
929
930 When applied to a function parameter it modifies the state of an argument after
931 a call to the function returns.  The function's body is checked to ensure that
932 the parameter is in the expected state before returning.
933   }];
934 }
935
936 def ConsumableDocs : Documentation {
937   let Category = DocCatConsumed;
938   let Content = [{
939 Each ``class`` that uses any of the typestate annotations must first be marked
940 using the ``consumable`` attribute.  Failure to do so will result in a warning.
941
942 This attribute accepts a single parameter that must be one of the following:
943 ``unknown``, ``consumed``, or ``unconsumed``.
944   }];
945 }
946
947 def NoSanitizeDocs : Documentation {
948   let Category = DocCatFunction;
949   let Content = [{
950 Use the ``no_sanitize`` attribute on a function declaration to specify
951 that a particular instrumentation or set of instrumentations should not be
952 applied to that function. The attribute takes a list of string literals,
953 which have the same meaning as values accepted by the ``-fno-sanitize=``
954 flag. For example, ``__attribute__((no_sanitize("address", "thread")))``
955 specifies that AddressSanitizer and ThreadSanitizer should not be applied
956 to the function.
957
958 See :ref:`Controlling Code Generation <controlling-code-generation>` for a
959 full list of supported sanitizer flags.
960   }];
961 }
962
963 def NoSanitizeAddressDocs : Documentation {
964   let Category = DocCatFunction;
965   // This function has multiple distinct spellings, and so it requires a custom
966   // heading to be specified. The most common spelling is sufficient.
967   let Heading = "no_sanitize_address (no_address_safety_analysis, gnu::no_address_safety_analysis, gnu::no_sanitize_address)";
968   let Content = [{
969 .. _langext-address_sanitizer:
970
971 Use ``__attribute__((no_sanitize_address))`` on a function declaration to
972 specify that address safety instrumentation (e.g. AddressSanitizer) should
973 not be applied to that function.
974   }];
975 }
976
977 def NoSanitizeThreadDocs : Documentation {
978   let Category = DocCatFunction;
979   let Heading = "no_sanitize_thread";
980   let Content = [{
981 .. _langext-thread_sanitizer:
982
983 Use ``__attribute__((no_sanitize_thread))`` on a function declaration to
984 specify that checks for data races on plain (non-atomic) memory accesses should
985 not be inserted by ThreadSanitizer. The function is still instrumented by the
986 tool to avoid false positives and provide meaningful stack traces.
987   }];
988 }
989
990 def NoSanitizeMemoryDocs : Documentation {
991   let Category = DocCatFunction;
992   let Heading = "no_sanitize_memory";
993   let Content = [{
994 .. _langext-memory_sanitizer:
995
996 Use ``__attribute__((no_sanitize_memory))`` on a function declaration to
997 specify that checks for uninitialized memory should not be inserted 
998 (e.g. by MemorySanitizer). The function may still be instrumented by the tool
999 to avoid false positives in other places.
1000   }];
1001 }
1002
1003 def DocCatTypeSafety : DocumentationCategory<"Type Safety Checking"> {
1004   let Content = [{
1005 Clang supports additional attributes to enable checking type safety properties
1006 that can't be enforced by the C type system.  Use cases include:
1007
1008 * MPI library implementations, where these attributes enable checking that
1009   the buffer type matches the passed ``MPI_Datatype``;
1010 * for HDF5 library there is a similar use case to MPI;
1011 * checking types of variadic functions' arguments for functions like
1012   ``fcntl()`` and ``ioctl()``.
1013
1014 You can detect support for these attributes with ``__has_attribute()``.  For
1015 example:
1016
1017 .. code-block:: c++
1018
1019   #if defined(__has_attribute)
1020   #  if __has_attribute(argument_with_type_tag) && \
1021         __has_attribute(pointer_with_type_tag) && \
1022         __has_attribute(type_tag_for_datatype)
1023   #    define ATTR_MPI_PWT(buffer_idx, type_idx) __attribute__((pointer_with_type_tag(mpi,buffer_idx,type_idx)))
1024   /* ... other macros ...  */
1025   #  endif
1026   #endif
1027
1028   #if !defined(ATTR_MPI_PWT)
1029   # define ATTR_MPI_PWT(buffer_idx, type_idx)
1030   #endif
1031
1032   int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */)
1033       ATTR_MPI_PWT(1,3);
1034   }];
1035 }
1036
1037 def ArgumentWithTypeTagDocs : Documentation {
1038   let Category = DocCatTypeSafety;
1039   let Heading = "argument_with_type_tag";
1040   let Content = [{
1041 Use ``__attribute__((argument_with_type_tag(arg_kind, arg_idx,
1042 type_tag_idx)))`` on a function declaration to specify that the function
1043 accepts a type tag that determines the type of some other argument.
1044 ``arg_kind`` is an identifier that should be used when annotating all
1045 applicable type tags.
1046
1047 This attribute is primarily useful for checking arguments of variadic functions
1048 (``pointer_with_type_tag`` can be used in most non-variadic cases).
1049
1050 For example:
1051
1052 .. code-block:: c++
1053
1054   int fcntl(int fd, int cmd, ...)
1055       __attribute__(( argument_with_type_tag(fcntl,3,2) ));
1056   }];
1057 }
1058
1059 def PointerWithTypeTagDocs : Documentation {
1060   let Category = DocCatTypeSafety;
1061   let Heading = "pointer_with_type_tag";
1062   let Content = [{
1063 Use ``__attribute__((pointer_with_type_tag(ptr_kind, ptr_idx, type_tag_idx)))``
1064 on a function declaration to specify that the function accepts a type tag that
1065 determines the pointee type of some other pointer argument.
1066
1067 For example:
1068
1069 .. code-block:: c++
1070
1071   int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */)
1072       __attribute__(( pointer_with_type_tag(mpi,1,3) ));
1073   }];
1074 }
1075
1076 def TypeTagForDatatypeDocs : Documentation {
1077   let Category = DocCatTypeSafety;
1078   let Content = [{
1079 Clang supports annotating type tags of two forms.
1080
1081 * **Type tag that is an expression containing a reference to some declared
1082   identifier.** Use ``__attribute__((type_tag_for_datatype(kind, type)))`` on a
1083   declaration with that identifier:
1084
1085   .. code-block:: c++
1086
1087     extern struct mpi_datatype mpi_datatype_int
1088         __attribute__(( type_tag_for_datatype(mpi,int) ));
1089     #define MPI_INT ((MPI_Datatype) &mpi_datatype_int)
1090
1091 * **Type tag that is an integral literal.** Introduce a ``static const``
1092   variable with a corresponding initializer value and attach
1093   ``__attribute__((type_tag_for_datatype(kind, type)))`` on that declaration,
1094   for example:
1095
1096   .. code-block:: c++
1097
1098     #define MPI_INT ((MPI_Datatype) 42)
1099     static const MPI_Datatype mpi_datatype_int
1100         __attribute__(( type_tag_for_datatype(mpi,int) )) = 42
1101
1102 The attribute also accepts an optional third argument that determines how the
1103 expression is compared to the type tag.  There are two supported flags:
1104
1105 * ``layout_compatible`` will cause types to be compared according to
1106   layout-compatibility rules (C++11 [class.mem] p 17, 18).  This is
1107   implemented to support annotating types like ``MPI_DOUBLE_INT``.
1108
1109   For example:
1110
1111   .. code-block:: c++
1112
1113     /* In mpi.h */
1114     struct internal_mpi_double_int { double d; int i; };
1115     extern struct mpi_datatype mpi_datatype_double_int
1116         __attribute__(( type_tag_for_datatype(mpi, struct internal_mpi_double_int, layout_compatible) ));
1117
1118     #define MPI_DOUBLE_INT ((MPI_Datatype) &mpi_datatype_double_int)
1119
1120     /* In user code */
1121     struct my_pair { double a; int b; };
1122     struct my_pair *buffer;
1123     MPI_Send(buffer, 1, MPI_DOUBLE_INT /*, ...  */); // no warning
1124
1125     struct my_int_pair { int a; int b; }
1126     struct my_int_pair *buffer2;
1127     MPI_Send(buffer2, 1, MPI_DOUBLE_INT /*, ...  */); // warning: actual buffer element
1128                                                       // type 'struct my_int_pair'
1129                                                       // doesn't match specified MPI_Datatype
1130
1131 * ``must_be_null`` specifies that the expression should be a null pointer
1132   constant, for example:
1133
1134   .. code-block:: c++
1135
1136     /* In mpi.h */
1137     extern struct mpi_datatype mpi_datatype_null
1138         __attribute__(( type_tag_for_datatype(mpi, void, must_be_null) ));
1139
1140     #define MPI_DATATYPE_NULL ((MPI_Datatype) &mpi_datatype_null)
1141
1142     /* In user code */
1143     MPI_Send(buffer, 1, MPI_DATATYPE_NULL /*, ...  */); // warning: MPI_DATATYPE_NULL
1144                                                         // was specified but buffer
1145                                                         // is not a null pointer
1146   }];
1147 }
1148
1149 def FlattenDocs : Documentation {
1150   let Category = DocCatFunction;
1151   let Content = [{
1152 The ``flatten`` attribute causes calls within the attributed function to
1153 be inlined unless it is impossible to do so, for example if the body of the
1154 callee is unavailable or if the callee has the ``noinline`` attribute.
1155   }];
1156 }
1157
1158 def FormatDocs : Documentation {
1159   let Category = DocCatFunction;
1160   let Content = [{
1161
1162 Clang supports the ``format`` attribute, which indicates that the function
1163 accepts a ``printf`` or ``scanf``-like format string and corresponding
1164 arguments or a ``va_list`` that contains these arguments.
1165
1166 Please see `GCC documentation about format attribute
1167 <http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>`_ to find details
1168 about attribute syntax.
1169
1170 Clang implements two kinds of checks with this attribute.
1171
1172 #. Clang checks that the function with the ``format`` attribute is called with
1173    a format string that uses format specifiers that are allowed, and that
1174    arguments match the format string.  This is the ``-Wformat`` warning, it is
1175    on by default.
1176
1177 #. Clang checks that the format string argument is a literal string.  This is
1178    the ``-Wformat-nonliteral`` warning, it is off by default.
1179
1180    Clang implements this mostly the same way as GCC, but there is a difference
1181    for functions that accept a ``va_list`` argument (for example, ``vprintf``).
1182    GCC does not emit ``-Wformat-nonliteral`` warning for calls to such
1183    functions.  Clang does not warn if the format string comes from a function
1184    parameter, where the function is annotated with a compatible attribute,
1185    otherwise it warns.  For example:
1186
1187    .. code-block:: c
1188
1189      __attribute__((__format__ (__scanf__, 1, 3)))
1190      void foo(const char* s, char *buf, ...) {
1191        va_list ap;
1192        va_start(ap, buf);
1193
1194        vprintf(s, ap); // warning: format string is not a string literal
1195      }
1196
1197    In this case we warn because ``s`` contains a format string for a
1198    ``scanf``-like function, but it is passed to a ``printf``-like function.
1199
1200    If the attribute is removed, clang still warns, because the format string is
1201    not a string literal.
1202
1203    Another example:
1204
1205    .. code-block:: c
1206
1207      __attribute__((__format__ (__printf__, 1, 3)))
1208      void foo(const char* s, char *buf, ...) {
1209        va_list ap;
1210        va_start(ap, buf);
1211
1212        vprintf(s, ap); // warning
1213      }
1214
1215    In this case Clang does not warn because the format string ``s`` and
1216    the corresponding arguments are annotated.  If the arguments are
1217    incorrect, the caller of ``foo`` will receive a warning.
1218   }];
1219 }
1220
1221 def AlignValueDocs : Documentation {
1222   let Category = DocCatType;
1223   let Content = [{
1224 The align_value attribute can be added to the typedef of a pointer type or the
1225 declaration of a variable of pointer or reference type. It specifies that the
1226 pointer will point to, or the reference will bind to, only objects with at
1227 least the provided alignment. This alignment value must be some positive power
1228 of 2.
1229
1230    .. code-block:: c
1231
1232      typedef double * aligned_double_ptr __attribute__((align_value(64)));
1233      void foo(double & x  __attribute__((align_value(128)),
1234               aligned_double_ptr y) { ... }
1235
1236 If the pointer value does not have the specified alignment at runtime, the
1237 behavior of the program is undefined.
1238   }];
1239 }
1240
1241 def FlagEnumDocs : Documentation {
1242   let Category = DocCatType;
1243   let Content = [{
1244 This attribute can be added to an enumerator to signal to the compiler that it
1245 is intended to be used as a flag type. This will cause the compiler to assume
1246 that the range of the type includes all of the values that you can get by
1247 manipulating bits of the enumerator when issuing warnings.
1248   }];
1249 }
1250
1251 def MSInheritanceDocs : Documentation {
1252   let Category = DocCatType;
1253   let Heading = "__single_inhertiance, __multiple_inheritance, __virtual_inheritance";
1254   let Content = [{
1255 This collection of keywords is enabled under ``-fms-extensions`` and controls
1256 the pointer-to-member representation used on ``*-*-win32`` targets.
1257
1258 The ``*-*-win32`` targets utilize a pointer-to-member representation which
1259 varies in size and alignment depending on the definition of the underlying
1260 class.
1261
1262 However, this is problematic when a forward declaration is only available and
1263 no definition has been made yet.  In such cases, Clang is forced to utilize the
1264 most general representation that is available to it.
1265
1266 These keywords make it possible to use a pointer-to-member representation other
1267 than the most general one regardless of whether or not the definition will ever
1268 be present in the current translation unit.
1269
1270 This family of keywords belong between the ``class-key`` and ``class-name``:
1271
1272 .. code-block:: c++
1273
1274   struct __single_inheritance S;
1275   int S::*i;
1276   struct S {};
1277
1278 This keyword can be applied to class templates but only has an effect when used
1279 on full specializations:
1280
1281 .. code-block:: c++
1282
1283   template <typename T, typename U> struct __single_inheritance A; // warning: inheritance model ignored on primary template
1284   template <typename T> struct __multiple_inheritance A<T, T>; // warning: inheritance model ignored on partial specialization
1285   template <> struct __single_inheritance A<int, float>;
1286
1287 Note that choosing an inheritance model less general than strictly necessary is
1288 an error:
1289
1290 .. code-block:: c++
1291
1292   struct __multiple_inheritance S; // error: inheritance model does not match definition
1293   int S::*i;
1294   struct S {};
1295 }];
1296 }
1297
1298 def MSNoVTableDocs : Documentation {
1299   let Category = DocCatType;
1300   let Content = [{
1301 This attribute can be added to a class declaration or definition to signal to
1302 the compiler that constructors and destructors will not reference the virtual
1303 function table.
1304   }];
1305 }
1306
1307 def OptnoneDocs : Documentation {
1308   let Category = DocCatFunction;
1309   let Content = [{
1310 The ``optnone`` attribute suppresses essentially all optimizations
1311 on a function or method, regardless of the optimization level applied to
1312 the compilation unit as a whole.  This is particularly useful when you
1313 need to debug a particular function, but it is infeasible to build the
1314 entire application without optimization.  Avoiding optimization on the
1315 specified function can improve the quality of the debugging information
1316 for that function.
1317
1318 This attribute is incompatible with the ``always_inline`` and ``minsize``
1319 attributes.
1320   }];
1321 }
1322
1323 def LoopHintDocs : Documentation {
1324   let Category = DocCatStmt;
1325   let Heading = "#pragma clang loop";
1326   let Content = [{
1327 The ``#pragma clang loop`` directive allows loop optimization hints to be
1328 specified for the subsequent loop. The directive allows vectorization,
1329 interleaving, and unrolling to be enabled or disabled. Vector width as well
1330 as interleave and unrolling count can be manually specified. See
1331 `language extensions
1332 <http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations>`_
1333 for details.
1334   }];
1335 }
1336
1337 def UnrollHintDocs : Documentation {
1338   let Category = DocCatStmt;
1339   let Heading = "#pragma unroll, #pragma nounroll";
1340   let Content = [{
1341 Loop unrolling optimization hints can be specified with ``#pragma unroll`` and
1342 ``#pragma nounroll``. The pragma is placed immediately before a for, while,
1343 do-while, or c++11 range-based for loop.
1344
1345 Specifying ``#pragma unroll`` without a parameter directs the loop unroller to
1346 attempt to fully unroll the loop if the trip count is known at compile time:
1347
1348 .. code-block:: c++
1349
1350   #pragma unroll
1351   for (...) {
1352     ...
1353   }
1354
1355 Specifying the optional parameter, ``#pragma unroll _value_``, directs the
1356 unroller to unroll the loop ``_value_`` times.  The parameter may optionally be
1357 enclosed in parentheses:
1358
1359 .. code-block:: c++
1360
1361   #pragma unroll 16
1362   for (...) {
1363     ...
1364   }
1365
1366   #pragma unroll(16)
1367   for (...) {
1368     ...
1369   }
1370
1371 Specifying ``#pragma nounroll`` indicates that the loop should not be unrolled:
1372
1373 .. code-block:: c++
1374
1375   #pragma nounroll
1376   for (...) {
1377     ...
1378   }
1379
1380 ``#pragma unroll`` and ``#pragma unroll _value_`` have identical semantics to
1381 ``#pragma clang loop unroll(full)`` and
1382 ``#pragma clang loop unroll_count(_value_)`` respectively. ``#pragma nounroll``
1383 is equivalent to ``#pragma clang loop unroll(disable)``.  See
1384 `language extensions
1385 <http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations>`_
1386 for further details including limitations of the unroll hints.
1387   }];
1388 }
1389
1390 def DocOpenCLAddressSpaces : DocumentationCategory<"OpenCL Address Spaces"> {
1391   let Content = [{
1392 The address space qualifier may be used to specify the region of memory that is
1393 used to allocate the object. OpenCL supports the following address spaces:
1394 __generic(generic), __global(global), __local(local), __private(private),
1395 __constant(constant).
1396
1397   .. code-block:: c
1398
1399     __constant int c = ...;
1400
1401     __generic int* foo(global int* g) {
1402       __local int* l;
1403       private int p;
1404       ...
1405       return l;
1406     }
1407
1408 More details can be found in the OpenCL C language Spec v2.0, Section 6.5.
1409   }];
1410 }
1411
1412 def OpenCLAddressSpaceGenericDocs : Documentation {
1413   let Category = DocOpenCLAddressSpaces;
1414   let Heading = "__generic(generic)";
1415   let Content = [{
1416 The generic address space attribute is only available with OpenCL v2.0 and later.
1417 It can be used with pointer types. Variables in global and local scope and
1418 function parameters in non-kernel functions can have the generic address space
1419 type attribute. It is intended to be a placeholder for any other address space
1420 except for '__constant' in OpenCL code which can be used with multiple address
1421 spaces.
1422   }];
1423 }
1424
1425 def OpenCLAddressSpaceConstantDocs : Documentation {
1426   let Category = DocOpenCLAddressSpaces;
1427   let Heading = "__constant(constant)";
1428   let Content = [{
1429 The constant address space attribute signals that an object is located in
1430 a constant (non-modifiable) memory region. It is available to all work items.
1431 Any type can be annotated with the constant address space attribute. Objects
1432 with the constant address space qualifier can be declared in any scope and must
1433 have an initializer.
1434   }];
1435 }
1436
1437 def OpenCLAddressSpaceGlobalDocs : Documentation {
1438   let Category = DocOpenCLAddressSpaces;
1439   let Heading = "__global(global)";
1440   let Content = [{
1441 The global address space attribute specifies that an object is allocated in
1442 global memory, which is accessible by all work items. The content stored in this
1443 memory area persists between kernel executions. Pointer types to the global
1444 address space are allowed as function parameters or local variables. Starting
1445 with OpenCL v2.0, the global address space can be used with global (program
1446 scope) variables and static local variable as well.
1447   }];
1448 }
1449
1450 def OpenCLAddressSpaceLocalDocs : Documentation {
1451   let Category = DocOpenCLAddressSpaces;
1452   let Heading = "__local(local)";
1453   let Content = [{
1454 The local address space specifies that an object is allocated in the local (work
1455 group) memory area, which is accessible to all work items in the same work
1456 group. The content stored in this memory region is not accessible after
1457 the kernel execution ends. In a kernel function scope, any variable can be in
1458 the local address space. In other scopes, only pointer types to the local address
1459 space are allowed. Local address space variables cannot have an initializer.
1460   }];
1461 }
1462
1463 def OpenCLAddressSpacePrivateDocs : Documentation {
1464   let Category = DocOpenCLAddressSpaces;
1465   let Heading = "__private(private)";
1466   let Content = [{
1467 The private address space specifies that an object is allocated in the private
1468 (work item) memory. Other work items cannot access the same memory area and its
1469 content is destroyed after work item execution ends. Local variables can be
1470 declared in the private address space. Function arguments are always in the
1471 private address space. Kernel function arguments of a pointer or an array type
1472 cannot point to the private address space.
1473   }];
1474 }
1475
1476 def NullabilityDocs : DocumentationCategory<"Nullability Attributes"> {
1477   let Content = [{
1478 Whether a particular pointer may be "null" is an important concern when working with pointers in the C family of languages. The various nullability attributes indicate whether a particular pointer can be null or not, which makes APIs more expressive and can help static analysis tools identify bugs involving null pointers. Clang supports several kinds of nullability attributes: the ``nonnull`` and ``returns_nonnull`` attributes indicate which function or method parameters and result types can never be null, while nullability type qualifiers indicate which pointer types can be null (``_Nullable``) or cannot be null (``_Nonnull``). 
1479
1480 The nullability (type) qualifiers express whether a value of a given pointer type can be null (the ``_Nullable`` qualifier), doesn't have a defined meaning for null (the ``_Nonnull`` qualifier), or for which the purpose of null is unclear (the ``_Null_unspecified`` qualifier). Because nullability qualifiers are expressed within the type system, they are more general than the ``nonnull`` and ``returns_nonnull`` attributes, allowing one to express (for example) a nullable pointer to an array of nonnull pointers. Nullability qualifiers are written to the right of the pointer to which they apply. For example:
1481
1482   .. code-block:: c
1483
1484     // No meaningful result when 'ptr' is null (here, it happens to be undefined behavior).
1485     int fetch(int * _Nonnull ptr) { return *ptr; }
1486
1487     // 'ptr' may be null.
1488     int fetch_or_zero(int * _Nullable ptr) {
1489       return ptr ? *ptr : 0;
1490     }
1491
1492     // A nullable pointer to non-null pointers to const characters.
1493     const char *join_strings(const char * _Nonnull * _Nullable strings, unsigned n);
1494
1495 In Objective-C, there is an alternate spelling for the nullability qualifiers that can be used in Objective-C methods and properties using context-sensitive, non-underscored keywords. For example:
1496
1497   .. code-block:: objective-c
1498
1499     @interface NSView : NSResponder
1500       - (nullable NSView *)ancestorSharedWithView:(nonnull NSView *)aView;
1501       @property (assign, nullable) NSView *superview;
1502       @property (readonly, nonnull) NSArray *subviews;
1503     @end
1504   }];
1505 }
1506
1507 def TypeNonNullDocs : Documentation {
1508   let Category = NullabilityDocs;
1509   let Heading = "_Nonnull";
1510   let Content = [{
1511 The ``_Nonnull`` nullability qualifier indicates that null is not a meaningful value for a value of the ``_Nonnull`` pointer type. For example, given a declaration such as:
1512
1513   .. code-block:: c
1514
1515     int fetch(int * _Nonnull ptr);
1516
1517 a caller of ``fetch`` should not provide a null value, and the compiler will produce a warning if it sees a literal null value passed to ``fetch``. Note that, unlike the declaration attribute ``nonnull``, the presence of ``_Nonnull`` does not imply that passing null is undefined behavior: ``fetch`` is free to consider null undefined behavior or (perhaps for backward-compatibility reasons) defensively handle null.
1518   }];
1519 }
1520
1521 def TypeNullableDocs : Documentation {
1522   let Category = NullabilityDocs;
1523   let Heading = "_Nullable";
1524   let Content = [{
1525 The ``_Nullable`` nullability qualifier indicates that a value of the ``_Nullable`` pointer type can be null. For example, given:
1526
1527   .. code-block:: c
1528
1529     int fetch_or_zero(int * _Nullable ptr);
1530
1531 a caller of ``fetch_or_zero`` can provide null. 
1532   }];
1533 }
1534
1535 def TypeNullUnspecifiedDocs : Documentation {
1536   let Category = NullabilityDocs;
1537   let Heading = "_Null_unspecified";
1538   let Content = [{
1539 The ``_Null_unspecified`` nullability qualifier indicates that neither the ``_Nonnull`` nor ``_Nullable`` qualifiers make sense for a particular pointer type. It is used primarily to indicate that the role of null with specific pointers in a nullability-annotated header is unclear, e.g., due to overly-complex implementations or historical factors with a long-lived API.
1540   }];
1541 }
1542
1543 def NonNullDocs : Documentation {
1544   let Category = NullabilityDocs;
1545   let Heading = "nonnull";
1546   let Content = [{
1547 The ``nonnull`` attribute indicates that some function parameters must not be null, and can be used in several different ways. It's original usage (`from GCC <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes>`_) is as a function (or Objective-C method) attribute that specifies which parameters of the function are nonnull in a comma-separated list. For example:
1548
1549   .. code-block:: c
1550
1551     extern void * my_memcpy (void *dest, const void *src, size_t len)
1552                     __attribute__((nonnull (1, 2)));
1553
1554 Here, the ``nonnull`` attribute indicates that parameters 1 and 2
1555 cannot have a null value. Omitting the parenthesized list of parameter indices means that all parameters of pointer type cannot be null:
1556
1557   .. code-block:: c
1558
1559     extern void * my_memcpy (void *dest, const void *src, size_t len)
1560                     __attribute__((nonnull));
1561
1562 Clang also allows the ``nonnull`` attribute to be placed directly on a function (or Objective-C method) parameter, eliminating the need to specify the parameter index ahead of type. For example:
1563
1564   .. code-block:: c
1565
1566     extern void * my_memcpy (void *dest __attribute__((nonnull)),
1567                              const void *src __attribute__((nonnull)), size_t len);
1568
1569 Note that the ``nonnull`` attribute indicates that passing null to a non-null parameter is undefined behavior, which the optimizer may take advantage of to, e.g., remove null checks. The ``_Nonnull`` type qualifier indicates that a pointer cannot be null in a more general manner (because it is part of the type system) and does not imply undefined behavior, making it more widely applicable.
1570   }];
1571 }
1572
1573 def ReturnsNonNullDocs : Documentation {
1574   let Category = NullabilityDocs;
1575   let Heading = "returns_nonnull";
1576   let Content = [{
1577 The ``returns_nonnull`` attribute indicates that a particular function (or Objective-C method) always returns a non-null pointer. For example, a particular system ``malloc`` might be defined to terminate a process when memory is not available rather than returning a null pointer:
1578
1579   .. code-block:: c
1580
1581     extern void * malloc (size_t size) __attribute__((returns_nonnull));
1582
1583 The ``returns_nonnull`` attribute implies that returning a null pointer is undefined behavior, which the optimizer may take advantage of. The ``_Nonnull`` type qualifier indicates that a pointer cannot be null in a more general manner (because it is part of the type system) and does not imply undefined behavior, making it more widely applicable
1584 }];
1585 }