1 //==--- AttrDocs.td - Attribute documentation ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===---------------------------------------------------------------------===//
10 def GlobalDocumentation {
12 -------------------------------------------------------------------
13 NOTE: This file is automatically generated by running clang-tblgen
14 -gen-attr-docs. Do not edit this file by hand!!
15 -------------------------------------------------------------------
26 This page lists the attributes currently supported by Clang.
30 def SectionDocs : Documentation {
31 let Category = DocCatVariable;
33 The ``section`` attribute allows you to specify a specific section a
34 global variable or function should be in after translation.
36 let Heading = "section (gnu::section, __declspec(allocate))";
39 def InitSegDocs : Documentation {
40 let Category = DocCatVariable;
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.
51 .. _init_seg: http://msdn.microsoft.com/en-us/library/7977wcck(v=vs.110).aspx
55 def TLSModelDocs : Documentation {
56 let Category = DocCatVariable;
58 The ``tls_model`` attribute allows you to specify which thread-local storage
59 model to use. It accepts the following strings:
66 TLS models are mutually exclusive.
70 def ThreadDocs : Documentation {
71 let Category = DocCatVariable;
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.
77 .. _`__declspec(thread)`: http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx
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.
87 def CarriesDependencyDocs : Documentation {
88 let Category = DocCatFunction;
90 The ``carries_dependency`` attribute specifies dependency propagation into and
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.
99 Note, this attribute does not change the meaning of the program, but may result
100 in generation of more efficient code.
104 def C11NoReturnDocs : Documentation {
105 let Category = DocCatFunction;
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.
113 def CXX11NoReturnDocs : Documentation {
114 let Category = DocCatFunction;
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.
122 def AssertCapabilityDocs : Documentation {
123 let Category = DocCatFunction;
124 let Heading = "assert_capability (assert_shared_capability, clang::assert_capability, clang::assert_shared_capability)";
126 Marks a function that dynamically tests whether a capability is held, and halts
127 the program if it is not held.
131 def AcquireCapabilityDocs : Documentation {
132 let Category = DocCatFunction;
133 let Heading = "acquire_capability (acquire_shared_capability, clang::acquire_capability, clang::acquire_shared_capability)";
135 Marks a function as acquiring a capability.
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)";
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).
150 def ReleaseCapabilityDocs : Documentation {
151 let Category = DocCatFunction;
152 let Heading = "release_capability (release_shared_capability, clang::release_capability, clang::release_shared_capability)";
154 Marks a function as releasing a capability.
158 def AssumeAlignedDocs : Documentation {
159 let Category = DocCatFunction;
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.
168 // The returned pointer value has 32-byte alignment.
169 void *a() __attribute__((assume_aligned (32)));
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)));
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.
181 def EnableIfDocs : Documentation {
182 let Category = DocCatFunction;
184 The ``enable_if`` attribute can be placed on function declarations to control
185 which overload is selected based on the values of the function's arguments.
186 When combined with the ``overloadable`` attribute, this feature is also
192 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")));
197 isdigit(-10); // results in a compile-time error.
200 The enable_if attribute takes two arguments, the first is an expression written
201 in terms of the function parameters, the second is a string explaining why this
202 overload candidate could not be selected to be displayed in diagnostics. The
203 expression is part of the function signature for the purposes of determining
204 whether it is a redeclaration (following the rules used when determining
205 whether a C++ template specialization is ODR-equivalent), but is not part of
208 The enable_if expression is evaluated as if it were the body of a
209 bool-returning constexpr function declared with the arguments of the function
210 it is being applied to, then called with the parameters at the call site. If the
211 result is false or could not be determined through constant expression
212 evaluation, then this overload will not be chosen and the provided string may
213 be used in a diagnostic if the compile fails as a result.
215 Because the enable_if expression is an unevaluated context, there are no global
216 state changes, nor the ability to pass information from the enable_if
217 expression to the function body. For example, suppose we want calls to
218 strnlen(strbuf, maxlen) to resolve to strnlen_chk(strbuf, maxlen, size of
219 strbuf) only if the size of strbuf can be determined:
223 __attribute__((always_inline))
224 static inline size_t strnlen(const char *s, size_t maxlen)
225 __attribute__((overloadable))
226 __attribute__((enable_if(__builtin_object_size(s, 0) != -1))),
227 "chosen when the buffer size is known but 'maxlen' is not")))
229 return strnlen_chk(s, maxlen, __builtin_object_size(s, 0));
232 Multiple enable_if attributes may be applied to a single declaration. In this
233 case, the enable_if expressions are evaluated from left to right in the
234 following manner. First, the candidates whose enable_if expressions evaluate to
235 false or cannot be evaluated are discarded. If the remaining candidates do not
236 share ODR-equivalent enable_if expressions, the overload resolution is
237 ambiguous. Otherwise, enable_if overload resolution continues with the next
238 enable_if attribute on the candidates that have not been discarded and have
239 remaining enable_if attributes. In this way, we pick the most specific
240 overload out of a number of viable overloads using enable_if.
244 void f() __attribute__((enable_if(true, ""))); // #1
245 void f() __attribute__((enable_if(true, ""))) __attribute__((enable_if(true, ""))); // #2
247 void g(int i, int j) __attribute__((enable_if(i, ""))); // #1
248 void g(int i, int j) __attribute__((enable_if(j, ""))) __attribute__((enable_if(true))); // #2
250 In this example, a call to f() is always resolved to #2, as the first enable_if
251 expression is ODR-equivalent for both declarations, but #1 does not have another
252 enable_if expression to continue evaluating, so the next round of evaluation has
253 only a single candidate. In a call to g(1, 1), the call is ambiguous even though
254 #2 has more enable_if attributes, because the first enable_if expressions are
257 Query for this feature with ``__has_attribute(enable_if)``.
261 def OverloadableDocs : Documentation {
262 let Category = DocCatFunction;
264 Clang provides support for C++ function overloading in C. Function overloading
265 in C is introduced using the ``overloadable`` attribute. For example, one
266 might provide several overloaded versions of a ``tgsin`` function that invokes
267 the appropriate standard function computing the sine of a value with ``float``,
268 ``double``, or ``long double`` precision:
273 float __attribute__((overloadable)) tgsin(float x) { return sinf(x); }
274 double __attribute__((overloadable)) tgsin(double x) { return sin(x); }
275 long double __attribute__((overloadable)) tgsin(long double x) { return sinl(x); }
277 Given these declarations, one can call ``tgsin`` with a ``float`` value to
278 receive a ``float`` result, with a ``double`` to receive a ``double`` result,
279 etc. Function overloading in C follows the rules of C++ function overloading
280 to pick the best overload given the call arguments, with a few C-specific
283 * Conversion from ``float`` or ``double`` to ``long double`` is ranked as a
284 floating-point promotion (per C99) rather than as a floating-point conversion
287 * A conversion from a pointer of type ``T*`` to a pointer of type ``U*`` is
288 considered a pointer conversion (with conversion rank) if ``T`` and ``U`` are
291 * A conversion from type ``T`` to a value of type ``U`` is permitted if ``T``
292 and ``U`` are compatible types. This conversion is given "conversion" rank.
294 The declaration of ``overloadable`` functions is restricted to function
295 declarations and definitions. Most importantly, if any function with a given
296 name is given the ``overloadable`` attribute, then all function declarations
297 and definitions with that name (and in that scope) must have the
298 ``overloadable`` attribute. This rule even applies to redeclarations of
299 functions whose original declaration had the ``overloadable`` attribute, e.g.,
303 int f(int) __attribute__((overloadable));
304 float f(float); // error: declaration of "f" must have the "overloadable" attribute
306 int g(int) __attribute__((overloadable));
307 int g(int) { } // error: redeclaration of "g" must also have the "overloadable" attribute
309 Functions marked ``overloadable`` must have prototypes. Therefore, the
310 following code is ill-formed:
314 int h() __attribute__((overloadable)); // error: h does not have a prototype
316 However, ``overloadable`` functions are allowed to use a ellipsis even if there
317 are no named parameters (as is permitted in C++). This feature is particularly
318 useful when combined with the ``unavailable`` attribute:
322 void honeypot(...) __attribute__((overloadable, unavailable)); // calling me is an error
324 Functions declared with the ``overloadable`` attribute have their names mangled
325 according to the same rules as C++ function names. For example, the three
326 ``tgsin`` functions in our motivating example get the mangled names
327 ``_Z5tgsinf``, ``_Z5tgsind``, and ``_Z5tgsine``, respectively. There are two
328 caveats to this use of name mangling:
330 * Future versions of Clang may change the name mangling of functions overloaded
331 in C, so you should not depend on an specific mangling. To be completely
332 safe, we strongly urge the use of ``static inline`` with ``overloadable``
335 * The ``overloadable`` attribute has almost no meaning when used in C++,
336 because names will already be mangled and functions are already overloadable.
337 However, when an ``overloadable`` function occurs within an ``extern "C"``
338 linkage specification, it's name *will* be mangled in the same way as it
341 Query for this feature with ``__has_extension(attribute_overloadable)``.
345 def ObjCMethodFamilyDocs : Documentation {
346 let Category = DocCatFunction;
348 Many methods in Objective-C have conventional meanings determined by their
349 selectors. It is sometimes useful to be able to mark a method as having a
350 particular conventional meaning despite not having the right selector, or as
351 not having the conventional meaning that its selector would suggest. For these
352 use cases, we provide an attribute to specifically describe the "method family"
353 that a method belongs to.
355 **Usage**: ``__attribute__((objc_method_family(X)))``, where ``X`` is one of
356 ``none``, ``alloc``, ``copy``, ``init``, ``mutableCopy``, or ``new``. This
357 attribute can only be placed at the end of a method declaration:
361 - (NSString *)initMyStringValue __attribute__((objc_method_family(none)));
363 Users who do not wish to change the conventional meaning of a method, and who
364 merely want to document its non-standard retain and release semantics, should
365 use the retaining behavior attributes (``ns_returns_retained``,
366 ``ns_returns_not_retained``, etc).
368 Query for this feature with ``__has_attribute(objc_method_family)``.
372 def NoDuplicateDocs : Documentation {
373 let Category = DocCatFunction;
375 The ``noduplicate`` attribute can be placed on function declarations to control
376 whether function calls to this function can be duplicated or not as a result of
377 optimizations. This is required for the implementation of functions with
378 certain special requirements, like the OpenCL "barrier" function, that might
379 need to be run concurrently by all the threads that are executing in lockstep
380 on the hardware. For example this attribute applied on the function
381 "nodupfunc" in the code below avoids that:
385 void nodupfunc() __attribute__((noduplicate));
386 // Setting it as a C++11 attribute is also valid
387 // void nodupfunc() [[clang::noduplicate]];
398 gets possibly modified by some optimizations into code similar to this:
410 where the call to "nodupfunc" is duplicated and sunk into the two branches
415 def NoSplitStackDocs : Documentation {
416 let Category = DocCatFunction;
418 The ``no_split_stack`` attribute disables the emission of the split stack
419 preamble for a particular function. It has no effect if ``-fsplit-stack``
424 def ObjCRequiresSuperDocs : Documentation {
425 let Category = DocCatFunction;
427 Some Objective-C classes allow a subclass to override a particular method in a
428 parent class but expect that the overriding method also calls the overridden
429 method in the parent class. For these cases, we provide an attribute to
430 designate that a method requires a "call to ``super``" in the overriding
431 method in the subclass.
433 **Usage**: ``__attribute__((objc_requires_super))``. This attribute can only
434 be placed at the end of a method declaration:
438 - (void)foo __attribute__((objc_requires_super));
440 This attribute can only be applied the method declarations within a class, and
441 not a protocol. Currently this attribute does not enforce any placement of
442 where the call occurs in the overriding method (such as in the case of
443 ``-dealloc`` where the call must appear at the end). It checks only that it
446 Note that on both OS X and iOS that the Foundation framework provides a
447 convenience macro ``NS_REQUIRES_SUPER`` that provides syntactic sugar for this
452 - (void)foo NS_REQUIRES_SUPER;
454 This macro is conditionally defined depending on the compiler's support for
455 this attribute. If the compiler does not support the attribute the macro
458 Operationally, when a method has this annotation the compiler will warn if the
459 implementation of an override in a subclass does not call super. For example:
463 warning: method possibly missing a [super AnnotMeth] call
464 - (void) AnnotMeth{};
469 def ObjCRuntimeNameDocs : Documentation {
470 let Category = DocCatFunction;
472 By default, the Objective-C interface or protocol identifier is used
473 in the metadata name for that object. The `objc_runtime_name`
474 attribute allows annotated interfaces or protocols to use the
475 specified string argument in the object's metadata name instead of the
478 **Usage**: ``__attribute__((objc_runtime_name("MyLocalName")))``. This attribute
479 can only be placed before an @protocol or @interface declaration:
483 __attribute__((objc_runtime_name("MyLocalName")))
490 def AvailabilityDocs : Documentation {
491 let Category = DocCatFunction;
493 The ``availability`` attribute can be placed on declarations to describe the
494 lifecycle of that declaration relative to operating system versions. Consider
495 the function declaration for a hypothetical function ``f``:
499 void f(void) __attribute__((availability(macosx,introduced=10.4,deprecated=10.6,obsoleted=10.7)));
501 The availability attribute states that ``f`` was introduced in Mac OS X 10.4,
502 deprecated in Mac OS X 10.6, and obsoleted in Mac OS X 10.7. This information
503 is used by Clang to determine when it is safe to use ``f``: for example, if
504 Clang is instructed to compile code for Mac OS X 10.5, a call to ``f()``
505 succeeds. If Clang is instructed to compile code for Mac OS X 10.6, the call
506 succeeds but Clang emits a warning specifying that the function is deprecated.
507 Finally, if Clang is instructed to compile code for Mac OS X 10.7, the call
508 fails because ``f()`` is no longer available.
510 The availability attribute is a comma-separated list starting with the
511 platform name and then including clauses specifying important milestones in the
512 declaration's lifetime (in any order) along with additional information. Those
515 introduced=\ *version*
516 The first version in which this declaration was introduced.
518 deprecated=\ *version*
519 The first version in which this declaration was deprecated, meaning that
520 users should migrate away from this API.
522 obsoleted=\ *version*
523 The first version in which this declaration was obsoleted, meaning that it
524 was removed completely and can no longer be used.
527 This declaration is never available on this platform.
529 message=\ *string-literal*
530 Additional message text that Clang will provide when emitting a warning or
531 error about use of a deprecated or obsoleted declaration. Useful to direct
532 users to replacement APIs.
534 Multiple availability attributes can be placed on a declaration, which may
535 correspond to different platforms. Only the availability attribute with the
536 platform corresponding to the target platform will be used; any others will be
537 ignored. If no availability attribute specifies availability for the current
538 target platform, the availability attributes are ignored. Supported platforms
542 Apple's iOS operating system. The minimum deployment target is specified by
543 the ``-mios-version-min=*version*`` or ``-miphoneos-version-min=*version*``
544 command-line arguments.
547 Apple's Mac OS X operating system. The minimum deployment target is
548 specified by the ``-mmacosx-version-min=*version*`` command-line argument.
550 A declaration can be used even when deploying back to a platform version prior
551 to when the declaration was introduced. When this happens, the declaration is
553 <https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html>`_,
554 as if the ``weak_import`` attribute were added to the declaration. A
555 weakly-linked declaration may or may not be present a run-time, and a program
556 can determine whether the declaration is present by checking whether the
557 address of that declaration is non-NULL.
559 If there are multiple declarations of the same entity, the availability
560 attributes must either match on a per-platform basis or later
561 declarations must not have availability attributes for that
562 platform. For example:
566 void g(void) __attribute__((availability(macosx,introduced=10.4)));
567 void g(void) __attribute__((availability(macosx,introduced=10.4))); // okay, matches
568 void g(void) __attribute__((availability(ios,introduced=4.0))); // okay, adds a new platform
569 void g(void); // okay, inherits both macosx and ios availability from above.
570 void g(void) __attribute__((availability(macosx,introduced=10.5))); // error: mismatch
572 When one method overrides another, the overriding method can be more widely available than the overridden method, e.g.,:
577 - (id)method __attribute__((availability(macosx,introduced=10.4)));
578 - (id)method2 __attribute__((availability(macosx,introduced=10.4)));
582 - (id)method __attribute__((availability(macosx,introduced=10.3))); // okay: method moved into base class later
583 - (id)method __attribute__((availability(macosx,introduced=10.5))); // error: this method was available via the base class in 10.4
588 def FallthroughDocs : Documentation {
589 let Category = DocCatStmt;
591 The ``clang::fallthrough`` attribute is used along with the
592 ``-Wimplicit-fallthrough`` argument to annotate intentional fall-through
593 between switch labels. It can only be applied to a null statement placed at a
594 point of execution between any statement and the next switch label. It is
595 common to mark these places with a specific comment, but this attribute is
596 meant to replace comments with a more strict annotation, which can be checked
597 by the compiler. This attribute doesn't change semantics of the code and can
598 be used wherever an intended fall-through occurs. It is designed to mimic
599 control-flow statements like ``break;``, so it can be placed in most places
600 where ``break;`` can, but only if there are no statements on the execution path
601 between it and the next switch label.
607 // compile with -Wimplicit-fallthrough
610 case 33: // no warning: no statements between case labels
612 case 44: // warning: unannotated fall-through
614 [[clang::fallthrough]];
615 case 55: // no warning
622 [[clang::fallthrough]];
624 case 66: // no warning
626 [[clang::fallthrough]]; // warning: fallthrough annotation does not
627 // directly precede case label
629 case 77: // warning: unannotated fall-through
635 def ARMInterruptDocs : Documentation {
636 let Category = DocCatFunction;
638 Clang supports the GNU style ``__attribute__((interrupt("TYPE")))`` attribute on
639 ARM targets. This attribute may be attached to a function definition and
640 instructs the backend to generate appropriate function entry/exit code so that
641 it can be used directly as an interrupt service routine.
643 The parameter passed to the interrupt attribute is optional, but if
644 provided it must be a string literal with one of the following values: "IRQ",
645 "FIQ", "SWI", "ABORT", "UNDEF".
647 The semantics are as follows:
649 - If the function is AAPCS, Clang instructs the backend to realign the stack to
650 8 bytes on entry. This is a general requirement of the AAPCS at public
651 interfaces, but may not hold when an exception is taken. Doing this allows
652 other AAPCS functions to be called.
653 - If the CPU is M-class this is all that needs to be done since the architecture
654 itself is designed in such a way that functions obeying the normal AAPCS ABI
655 constraints are valid exception handlers.
656 - If the CPU is not M-class, the prologue and epilogue are modified to save all
657 non-banked registers that are used, so that upon return the user-mode state
658 will not be corrupted. Note that to avoid unnecessary overhead, only
659 general-purpose (integer) registers are saved in this way. If VFP operations
660 are needed, that state must be saved manually.
662 Specifically, interrupt kinds other than "FIQ" will save all core registers
663 except "lr" and "sp". "FIQ" interrupts will save r0-r7.
664 - If the CPU is not M-class, the return instruction is changed to one of the
665 canonical sequences permitted by the architecture for exception return. Where
666 possible the function itself will make the necessary "lr" adjustments so that
667 the "preferred return address" is selected.
669 Unfortunately the compiler is unable to make this guarantee for an "UNDEF"
670 handler, where the offset from "lr" to the preferred return address depends on
671 the execution state of the code which generated the exception. In this case
672 a sequence equivalent to "movs pc, lr" will be used.
676 def DocCatAMDGPURegisterAttributes :
677 DocumentationCategory<"AMD GPU Register Attributes"> {
679 Clang supports attributes for controlling register usage on AMD GPU
680 targets. These attributes may be attached to a kernel function
681 definition and is an optimization hint to the backend for the maximum
682 number of registers to use. This is useful in cases where register
683 limited occupancy is known to be an important factor for the
684 performance for the kernel.
686 The semantics are as follows:
688 - The backend will attempt to limit the number of used registers to
689 the specified value, but the exact number used is not
690 guaranteed. The number used may be rounded up to satisfy the
691 allocation requirements or ABI constraints of the subtarget. For
692 example, on Southern Islands VGPRs may only be allocated in
693 increments of 4, so requesting a limit of 39 VGPRs will really
694 attempt to use up to 40. Requesting more registers than the
695 subtarget supports will truncate to the maximum allowed. The backend
696 may also use fewer registers than requested whenever possible.
698 - 0 implies the default no limit on register usage.
700 - Ignored on older VLIW subtargets which did not have separate scalar
701 and vector registers, R600 through Northern Islands.
707 def AMDGPUNumVGPRDocs : Documentation {
708 let Category = DocCatAMDGPURegisterAttributes;
711 ``__attribute__((amdgpu_num_vgpr(<num_registers>)))`` attribute on AMD
712 Southern Islands GPUs and later for controlling the number of vector
713 registers. A typical value would be between 4 and 256 in increments
718 def AMDGPUNumSGPRDocs : Documentation {
719 let Category = DocCatAMDGPURegisterAttributes;
723 ``__attribute__((amdgpu_num_sgpr(<num_registers>)))`` attribute on AMD
724 Southern Islands GPUs and later for controlling the number of scalar
725 registers. A typical value would be between 8 and 104 in increments of
728 Due to common instruction constraints, an additional 2-4 SGPRs are
729 typically required for internal use depending on features used. This
730 value is a hint for the total number of SGPRs to use, and not the
731 number of user SGPRs, so no special consideration needs to be given
736 def DocCatCallingConvs : DocumentationCategory<"Calling Conventions"> {
738 Clang supports several different calling conventions, depending on the target
739 platform and architecture. The calling convention used for a function determines
740 how parameters are passed, how results are returned to the caller, and other
741 low-level details of calling a function.
745 def PcsDocs : Documentation {
746 let Category = DocCatCallingConvs;
748 On ARM targets, this attribute can be used to select calling conventions
749 similar to ``stdcall`` on x86. Valid parameter values are "aapcs" and
754 def RegparmDocs : Documentation {
755 let Category = DocCatCallingConvs;
757 On 32-bit x86 targets, the regparm attribute causes the compiler to pass
758 the first three integer parameters in EAX, EDX, and ECX instead of on the
759 stack. This attribute has no effect on variadic functions, and all parameters
760 are passed via the stack as normal.
764 def SysVABIDocs : Documentation {
765 let Category = DocCatCallingConvs;
767 On Windows x86_64 targets, this attribute changes the calling convention of a
768 function to match the default convention used on Sys V targets such as Linux,
769 Mac, and BSD. This attribute has no effect on other targets.
773 def MSABIDocs : Documentation {
774 let Category = DocCatCallingConvs;
776 On non-Windows x86_64 targets, this attribute changes the calling convention of
777 a function to match the default convention used on Windows x86_64. This
778 attribute has no effect on Windows targets or non-x86_64 targets.
782 def StdCallDocs : Documentation {
783 let Category = DocCatCallingConvs;
785 On 32-bit x86 targets, this attribute changes the calling convention of a
786 function to clear parameters off of the stack on return. This convention does
787 not support variadic calls or unprototyped functions in C, and has no effect on
788 x86_64 targets. This calling convention is used widely by the Windows API and
789 COM applications. See the documentation for `__stdcall`_ on MSDN.
791 .. _`__stdcall`: http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx
795 def FastCallDocs : Documentation {
796 let Category = DocCatCallingConvs;
798 On 32-bit x86 targets, this attribute changes the calling convention of a
799 function to use ECX and EDX as register parameters and clear parameters off of
800 the stack on return. This convention does not support variadic calls or
801 unprototyped functions in C, and has no effect on x86_64 targets. This calling
802 convention is supported primarily for compatibility with existing code. Users
803 seeking register parameters should use the ``regparm`` attribute, which does
804 not require callee-cleanup. See the documentation for `__fastcall`_ on MSDN.
806 .. _`__fastcall`: http://msdn.microsoft.com/en-us/library/6xa169sk.aspx
810 def ThisCallDocs : Documentation {
811 let Category = DocCatCallingConvs;
813 On 32-bit x86 targets, this attribute changes the calling convention of a
814 function to use ECX for the first parameter (typically the implicit ``this``
815 parameter of C++ methods) and clear parameters off of the stack on return. This
816 convention does not support variadic calls or unprototyped functions in C, and
817 has no effect on x86_64 targets. See the documentation for `__thiscall`_ on
820 .. _`__thiscall`: http://msdn.microsoft.com/en-us/library/ek8tkfbw.aspx
824 def VectorCallDocs : Documentation {
825 let Category = DocCatCallingConvs;
827 On 32-bit x86 *and* x86_64 targets, this attribute changes the calling
828 convention of a function to pass vector parameters in SSE registers.
830 On 32-bit x86 targets, this calling convention is similar to ``__fastcall``.
831 The first two integer parameters are passed in ECX and EDX. Subsequent integer
832 parameters are passed in memory, and callee clears the stack. On x86_64
833 targets, the callee does *not* clear the stack, and integer parameters are
834 passed in RCX, RDX, R8, and R9 as is done for the default Windows x64 calling
837 On both 32-bit x86 and x86_64 targets, vector and floating point arguments are
838 passed in XMM0-XMM5. Homogenous vector aggregates of up to four elements are
839 passed in sequential SSE registers if enough are available. If AVX is enabled,
840 256 bit vectors are passed in YMM0-YMM5. Any vector or aggregate type that
841 cannot be passed in registers for any reason is passed by reference, which
842 allows the caller to align the parameter memory.
844 See the documentation for `__vectorcall`_ on MSDN for more details.
846 .. _`__vectorcall`: http://msdn.microsoft.com/en-us/library/dn375768.aspx
850 def DocCatConsumed : DocumentationCategory<"Consumed Annotation Checking"> {
852 Clang supports additional attributes for checking basic resource management
853 properties, specifically for unique objects that have a single owning reference.
854 The following attributes are currently supported, although **the implementation
855 for these annotations is currently in development and are subject to change.**
859 def SetTypestateDocs : Documentation {
860 let Category = DocCatConsumed;
862 Annotate methods that transition an object into a new state with
863 ``__attribute__((set_typestate(new_state)))``. The new state must be
864 unconsumed, consumed, or unknown.
868 def CallableWhenDocs : Documentation {
869 let Category = DocCatConsumed;
871 Use ``__attribute__((callable_when(...)))`` to indicate what states a method
872 may be called in. Valid states are unconsumed, consumed, or unknown. Each
873 argument to this attribute must be a quoted string. E.g.:
875 ``__attribute__((callable_when("unconsumed", "unknown")))``
879 def TestTypestateDocs : Documentation {
880 let Category = DocCatConsumed;
882 Use ``__attribute__((test_typestate(tested_state)))`` to indicate that a method
883 returns true if the object is in the specified state..
887 def ParamTypestateDocs : Documentation {
888 let Category = DocCatConsumed;
890 This attribute specifies expectations about function parameters. Calls to an
891 function with annotated parameters will issue a warning if the corresponding
892 argument isn't in the expected state. The attribute is also used to set the
893 initial state of the parameter when analyzing the function's body.
897 def ReturnTypestateDocs : Documentation {
898 let Category = DocCatConsumed;
900 The ``return_typestate`` attribute can be applied to functions or parameters.
901 When applied to a function the attribute specifies the state of the returned
902 value. The function's body is checked to ensure that it always returns a value
903 in the specified state. On the caller side, values returned by the annotated
904 function are initialized to the given state.
906 When applied to a function parameter it modifies the state of an argument after
907 a call to the function returns. The function's body is checked to ensure that
908 the parameter is in the expected state before returning.
912 def ConsumableDocs : Documentation {
913 let Category = DocCatConsumed;
915 Each ``class`` that uses any of the typestate annotations must first be marked
916 using the ``consumable`` attribute. Failure to do so will result in a warning.
918 This attribute accepts a single parameter that must be one of the following:
919 ``unknown``, ``consumed``, or ``unconsumed``.
923 def NoSanitizeDocs : Documentation {
924 let Category = DocCatFunction;
926 Use the ``no_sanitize`` attribute on a function declaration to specify
927 that a particular instrumentation or set of instrumentations should not be
928 applied to that function. The attribute takes a list of string literals,
929 which have the same meaning as values accepted by the ``-fno-sanitize=``
930 flag. For example, ``__attribute__((no_sanitize("address", "thread")))``
931 specifies that AddressSanitizer and ThreadSanitizer should not be applied
934 See :ref:`Controlling Code Generation <controlling-code-generation>` for a
935 full list of supported sanitizer flags.
939 def NoSanitizeAddressDocs : Documentation {
940 let Category = DocCatFunction;
941 // This function has multiple distinct spellings, and so it requires a custom
942 // heading to be specified. The most common spelling is sufficient.
943 let Heading = "no_sanitize_address (no_address_safety_analysis, gnu::no_address_safety_analysis, gnu::no_sanitize_address)";
945 .. _langext-address_sanitizer:
947 Use ``__attribute__((no_sanitize_address))`` on a function declaration to
948 specify that address safety instrumentation (e.g. AddressSanitizer) should
949 not be applied to that function.
953 def NoSanitizeThreadDocs : Documentation {
954 let Category = DocCatFunction;
955 let Heading = "no_sanitize_thread";
957 .. _langext-thread_sanitizer:
959 Use ``__attribute__((no_sanitize_thread))`` on a function declaration to
960 specify that checks for data races on plain (non-atomic) memory accesses should
961 not be inserted by ThreadSanitizer. The function is still instrumented by the
962 tool to avoid false positives and provide meaningful stack traces.
966 def NoSanitizeMemoryDocs : Documentation {
967 let Category = DocCatFunction;
968 let Heading = "no_sanitize_memory";
970 .. _langext-memory_sanitizer:
972 Use ``__attribute__((no_sanitize_memory))`` on a function declaration to
973 specify that checks for uninitialized memory should not be inserted
974 (e.g. by MemorySanitizer). The function may still be instrumented by the tool
975 to avoid false positives in other places.
979 def DocCatTypeSafety : DocumentationCategory<"Type Safety Checking"> {
981 Clang supports additional attributes to enable checking type safety properties
982 that can't be enforced by the C type system. Use cases include:
984 * MPI library implementations, where these attributes enable checking that
985 the buffer type matches the passed ``MPI_Datatype``;
986 * for HDF5 library there is a similar use case to MPI;
987 * checking types of variadic functions' arguments for functions like
988 ``fcntl()`` and ``ioctl()``.
990 You can detect support for these attributes with ``__has_attribute()``. For
995 #if defined(__has_attribute)
996 # if __has_attribute(argument_with_type_tag) && \
997 __has_attribute(pointer_with_type_tag) && \
998 __has_attribute(type_tag_for_datatype)
999 # define ATTR_MPI_PWT(buffer_idx, type_idx) __attribute__((pointer_with_type_tag(mpi,buffer_idx,type_idx)))
1000 /* ... other macros ... */
1004 #if !defined(ATTR_MPI_PWT)
1005 # define ATTR_MPI_PWT(buffer_idx, type_idx)
1008 int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */)
1013 def ArgumentWithTypeTagDocs : Documentation {
1014 let Category = DocCatTypeSafety;
1015 let Heading = "argument_with_type_tag";
1017 Use ``__attribute__((argument_with_type_tag(arg_kind, arg_idx,
1018 type_tag_idx)))`` on a function declaration to specify that the function
1019 accepts a type tag that determines the type of some other argument.
1020 ``arg_kind`` is an identifier that should be used when annotating all
1021 applicable type tags.
1023 This attribute is primarily useful for checking arguments of variadic functions
1024 (``pointer_with_type_tag`` can be used in most non-variadic cases).
1030 int fcntl(int fd, int cmd, ...)
1031 __attribute__(( argument_with_type_tag(fcntl,3,2) ));
1035 def PointerWithTypeTagDocs : Documentation {
1036 let Category = DocCatTypeSafety;
1037 let Heading = "pointer_with_type_tag";
1039 Use ``__attribute__((pointer_with_type_tag(ptr_kind, ptr_idx, type_tag_idx)))``
1040 on a function declaration to specify that the function accepts a type tag that
1041 determines the pointee type of some other pointer argument.
1047 int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */)
1048 __attribute__(( pointer_with_type_tag(mpi,1,3) ));
1052 def TypeTagForDatatypeDocs : Documentation {
1053 let Category = DocCatTypeSafety;
1055 Clang supports annotating type tags of two forms.
1057 * **Type tag that is an expression containing a reference to some declared
1058 identifier.** Use ``__attribute__((type_tag_for_datatype(kind, type)))`` on a
1059 declaration with that identifier:
1063 extern struct mpi_datatype mpi_datatype_int
1064 __attribute__(( type_tag_for_datatype(mpi,int) ));
1065 #define MPI_INT ((MPI_Datatype) &mpi_datatype_int)
1067 * **Type tag that is an integral literal.** Introduce a ``static const``
1068 variable with a corresponding initializer value and attach
1069 ``__attribute__((type_tag_for_datatype(kind, type)))`` on that declaration,
1074 #define MPI_INT ((MPI_Datatype) 42)
1075 static const MPI_Datatype mpi_datatype_int
1076 __attribute__(( type_tag_for_datatype(mpi,int) )) = 42
1078 The attribute also accepts an optional third argument that determines how the
1079 expression is compared to the type tag. There are two supported flags:
1081 * ``layout_compatible`` will cause types to be compared according to
1082 layout-compatibility rules (C++11 [class.mem] p 17, 18). This is
1083 implemented to support annotating types like ``MPI_DOUBLE_INT``.
1090 struct internal_mpi_double_int { double d; int i; };
1091 extern struct mpi_datatype mpi_datatype_double_int
1092 __attribute__(( type_tag_for_datatype(mpi, struct internal_mpi_double_int, layout_compatible) ));
1094 #define MPI_DOUBLE_INT ((MPI_Datatype) &mpi_datatype_double_int)
1097 struct my_pair { double a; int b; };
1098 struct my_pair *buffer;
1099 MPI_Send(buffer, 1, MPI_DOUBLE_INT /*, ... */); // no warning
1101 struct my_int_pair { int a; int b; }
1102 struct my_int_pair *buffer2;
1103 MPI_Send(buffer2, 1, MPI_DOUBLE_INT /*, ... */); // warning: actual buffer element
1104 // type 'struct my_int_pair'
1105 // doesn't match specified MPI_Datatype
1107 * ``must_be_null`` specifies that the expression should be a null pointer
1108 constant, for example:
1113 extern struct mpi_datatype mpi_datatype_null
1114 __attribute__(( type_tag_for_datatype(mpi, void, must_be_null) ));
1116 #define MPI_DATATYPE_NULL ((MPI_Datatype) &mpi_datatype_null)
1119 MPI_Send(buffer, 1, MPI_DATATYPE_NULL /*, ... */); // warning: MPI_DATATYPE_NULL
1120 // was specified but buffer
1121 // is not a null pointer
1125 def FlattenDocs : Documentation {
1126 let Category = DocCatFunction;
1128 The ``flatten`` attribute causes calls within the attributed function to
1129 be inlined unless it is impossible to do so, for example if the body of the
1130 callee is unavailable or if the callee has the ``noinline`` attribute.
1134 def FormatDocs : Documentation {
1135 let Category = DocCatFunction;
1138 Clang supports the ``format`` attribute, which indicates that the function
1139 accepts a ``printf`` or ``scanf``-like format string and corresponding
1140 arguments or a ``va_list`` that contains these arguments.
1142 Please see `GCC documentation about format attribute
1143 <http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>`_ to find details
1144 about attribute syntax.
1146 Clang implements two kinds of checks with this attribute.
1148 #. Clang checks that the function with the ``format`` attribute is called with
1149 a format string that uses format specifiers that are allowed, and that
1150 arguments match the format string. This is the ``-Wformat`` warning, it is
1153 #. Clang checks that the format string argument is a literal string. This is
1154 the ``-Wformat-nonliteral`` warning, it is off by default.
1156 Clang implements this mostly the same way as GCC, but there is a difference
1157 for functions that accept a ``va_list`` argument (for example, ``vprintf``).
1158 GCC does not emit ``-Wformat-nonliteral`` warning for calls to such
1159 functions. Clang does not warn if the format string comes from a function
1160 parameter, where the function is annotated with a compatible attribute,
1161 otherwise it warns. For example:
1165 __attribute__((__format__ (__scanf__, 1, 3)))
1166 void foo(const char* s, char *buf, ...) {
1170 vprintf(s, ap); // warning: format string is not a string literal
1173 In this case we warn because ``s`` contains a format string for a
1174 ``scanf``-like function, but it is passed to a ``printf``-like function.
1176 If the attribute is removed, clang still warns, because the format string is
1177 not a string literal.
1183 __attribute__((__format__ (__printf__, 1, 3)))
1184 void foo(const char* s, char *buf, ...) {
1188 vprintf(s, ap); // warning
1191 In this case Clang does not warn because the format string ``s`` and
1192 the corresponding arguments are annotated. If the arguments are
1193 incorrect, the caller of ``foo`` will receive a warning.
1197 def AlignValueDocs : Documentation {
1198 let Category = DocCatType;
1200 The align_value attribute can be added to the typedef of a pointer type or the
1201 declaration of a variable of pointer or reference type. It specifies that the
1202 pointer will point to, or the reference will bind to, only objects with at
1203 least the provided alignment. This alignment value must be some positive power
1208 typedef double * aligned_double_ptr __attribute__((align_value(64)));
1209 void foo(double & x __attribute__((align_value(128)),
1210 aligned_double_ptr y) { ... }
1212 If the pointer value does not have the specified alignment at runtime, the
1213 behavior of the program is undefined.
1217 def FlagEnumDocs : Documentation {
1218 let Category = DocCatType;
1220 This attribute can be added to an enumerator to signal to the compiler that it
1221 is intended to be used as a flag type. This will cause the compiler to assume
1222 that the range of the type includes all of the values that you can get by
1223 manipulating bits of the enumerator when issuing warnings.
1227 def MSInheritanceDocs : Documentation {
1228 let Category = DocCatType;
1229 let Heading = "__single_inhertiance, __multiple_inheritance, __virtual_inheritance";
1231 This collection of keywords is enabled under ``-fms-extensions`` and controls
1232 the pointer-to-member representation used on ``*-*-win32`` targets.
1234 The ``*-*-win32`` targets utilize a pointer-to-member representation which
1235 varies in size and alignment depending on the definition of the underlying
1238 However, this is problematic when a forward declaration is only available and
1239 no definition has been made yet. In such cases, Clang is forced to utilize the
1240 most general representation that is available to it.
1242 These keywords make it possible to use a pointer-to-member representation other
1243 than the most general one regardless of whether or not the definition will ever
1244 be present in the current translation unit.
1246 This family of keywords belong between the ``class-key`` and ``class-name``:
1250 struct __single_inheritance S;
1254 This keyword can be applied to class templates but only has an effect when used
1255 on full specializations:
1259 template <typename T, typename U> struct __single_inheritance A; // warning: inheritance model ignored on primary template
1260 template <typename T> struct __multiple_inheritance A<T, T>; // warning: inheritance model ignored on partial specialization
1261 template <> struct __single_inheritance A<int, float>;
1263 Note that choosing an inheritance model less general than strictly necessary is
1268 struct __multiple_inheritance S; // error: inheritance model does not match definition
1274 def MSNoVTableDocs : Documentation {
1275 let Category = DocCatType;
1277 This attribute can be added to a class declaration or definition to signal to
1278 the compiler that constructors and destructors will not reference the virtual
1283 def OptnoneDocs : Documentation {
1284 let Category = DocCatFunction;
1286 The ``optnone`` attribute suppresses essentially all optimizations
1287 on a function or method, regardless of the optimization level applied to
1288 the compilation unit as a whole. This is particularly useful when you
1289 need to debug a particular function, but it is infeasible to build the
1290 entire application without optimization. Avoiding optimization on the
1291 specified function can improve the quality of the debugging information
1294 This attribute is incompatible with the ``always_inline`` and ``minsize``
1299 def LoopHintDocs : Documentation {
1300 let Category = DocCatStmt;
1301 let Heading = "#pragma clang loop";
1303 The ``#pragma clang loop`` directive allows loop optimization hints to be
1304 specified for the subsequent loop. The directive allows vectorization,
1305 interleaving, and unrolling to be enabled or disabled. Vector width as well
1306 as interleave and unrolling count can be manually specified. See
1307 `language extensions
1308 <http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations>`_
1313 def UnrollHintDocs : Documentation {
1314 let Category = DocCatStmt;
1315 let Heading = "#pragma unroll, #pragma nounroll";
1317 Loop unrolling optimization hints can be specified with ``#pragma unroll`` and
1318 ``#pragma nounroll``. The pragma is placed immediately before a for, while,
1319 do-while, or c++11 range-based for loop.
1321 Specifying ``#pragma unroll`` without a parameter directs the loop unroller to
1322 attempt to fully unroll the loop if the trip count is known at compile time:
1331 Specifying the optional parameter, ``#pragma unroll _value_``, directs the
1332 unroller to unroll the loop ``_value_`` times. The parameter may optionally be
1333 enclosed in parentheses:
1347 Specifying ``#pragma nounroll`` indicates that the loop should not be unrolled:
1356 ``#pragma unroll`` and ``#pragma unroll _value_`` have identical semantics to
1357 ``#pragma clang loop unroll(full)`` and
1358 ``#pragma clang loop unroll_count(_value_)`` respectively. ``#pragma nounroll``
1359 is equivalent to ``#pragma clang loop unroll(disable)``. See
1360 `language extensions
1361 <http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations>`_
1362 for further details including limitations of the unroll hints.
1366 def DocOpenCLAddressSpaces : DocumentationCategory<"OpenCL Address Spaces"> {
1368 The address space qualifier may be used to specify the region of memory that is
1369 used to allocate the object. OpenCL supports the following address spaces:
1370 __generic(generic), __global(global), __local(local), __private(private),
1371 __constant(constant).
1375 __constant int c = ...;
1377 __generic int* foo(global int* g) {
1384 More details can be found in the OpenCL C language Spec v2.0, Section 6.5.
1388 def OpenCLAddressSpaceGenericDocs : Documentation {
1389 let Category = DocOpenCLAddressSpaces;
1390 let Heading = "__generic(generic)";
1392 The generic address space attribute is only available with OpenCL v2.0 and later.
1393 It can be used with pointer types. Variables in global and local scope and
1394 function parameters in non-kernel functions can have the generic address space
1395 type attribute. It is intended to be a placeholder for any other address space
1396 except for '__constant' in OpenCL code which can be used with multiple address
1401 def OpenCLAddressSpaceConstantDocs : Documentation {
1402 let Category = DocOpenCLAddressSpaces;
1403 let Heading = "__constant(constant)";
1405 The constant address space attribute signals that an object is located in
1406 a constant (non-modifiable) memory region. It is available to all work items.
1407 Any type can be annotated with the constant address space attribute. Objects
1408 with the constant address space qualifier can be declared in any scope and must
1409 have an initializer.
1413 def OpenCLAddressSpaceGlobalDocs : Documentation {
1414 let Category = DocOpenCLAddressSpaces;
1415 let Heading = "__global(global)";
1417 The global address space attribute specifies that an object is allocated in
1418 global memory, which is accessible by all work items. The content stored in this
1419 memory area persists between kernel executions. Pointer types to the global
1420 address space are allowed as function parameters or local variables. Starting
1421 with OpenCL v2.0, the global address space can be used with global (program
1422 scope) variables and static local variable as well.
1426 def OpenCLAddressSpaceLocalDocs : Documentation {
1427 let Category = DocOpenCLAddressSpaces;
1428 let Heading = "__local(local)";
1430 The local address space specifies that an object is allocated in the local (work
1431 group) memory area, which is accessible to all work items in the same work
1432 group. The content stored in this memory region is not accessible after
1433 the kernel execution ends. In a kernel function scope, any variable can be in
1434 the local address space. In other scopes, only pointer types to the local address
1435 space are allowed. Local address space variables cannot have an initializer.
1439 def OpenCLAddressSpacePrivateDocs : Documentation {
1440 let Category = DocOpenCLAddressSpaces;
1441 let Heading = "__private(private)";
1443 The private address space specifies that an object is allocated in the private
1444 (work item) memory. Other work items cannot access the same memory area and its
1445 content is destroyed after work item execution ends. Local variables can be
1446 declared in the private address space. Function arguments are always in the
1447 private address space. Kernel function arguments of a pointer or an array type
1448 cannot point to the private address space.