From: patrick Date: Wed, 28 Apr 2021 12:49:07 +0000 (+0000) Subject: Merge LLVM 11.1.0. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=adae0cfddad1cb50e512c3edbc993eee4037999b;p=openbsd Merge LLVM 11.1.0. --- diff --git a/gnu/llvm/clang/.arcconfig b/gnu/llvm/clang/.arcconfig deleted file mode 100644 index b258e7a34c4..00000000000 --- a/gnu/llvm/clang/.arcconfig +++ /dev/null @@ -1,4 +0,0 @@ -{ - "repository.callsign" : "C", - "conduit_uri" : "https://reviews.llvm.org/" -} diff --git a/gnu/llvm/clang/docs/AttributeReference.rst b/gnu/llvm/clang/docs/AttributeReference.rst deleted file mode 100644 index 273bbb1f90c..00000000000 --- a/gnu/llvm/clang/docs/AttributeReference.rst +++ /dev/null @@ -1,6187 +0,0 @@ -.. - ------------------------------------------------------------------- - NOTE: This file is automatically generated by running clang-tblgen - -gen-attr-docs. Do not edit this file by hand!! - ------------------------------------------------------------------- - -=================== -Attributes in Clang -=================== -.. contents:: - :local: - -.. |br| raw:: html - -
- -Introduction -============ - -This page lists the attributes currently supported by Clang. - -Function Attributes -=================== - - -#pragma omp declare simd ------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","","``omp declare simd``","" - -The `declare simd` construct can be applied to a function to enable the creation -of one or more versions that can process multiple arguments using SIMD -instructions from a single invocation in a SIMD loop. The `declare simd` -directive is a declarative directive. There may be multiple `declare simd` -directives for a function. The use of a `declare simd` construct on a function -enables the creation of SIMD versions of the associated function that can be -used to process multiple arguments from a single invocation from a SIMD loop -concurrently. -The syntax of the `declare simd` construct is as follows: - - .. code-block:: none - - #pragma omp declare simd [clause[[,] clause] ...] new-line - [#pragma omp declare simd [clause[[,] clause] ...] new-line] - [...] - function definition or declaration - -where clause is one of the following: - - .. code-block:: none - - simdlen(length) - linear(argument-list[:constant-linear-step]) - aligned(argument-list[:alignment]) - uniform(argument-list) - inbranch - notinbranch - - -#pragma omp declare target --------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","","``omp declare target``","" - -The `declare target` directive specifies that variables and functions are mapped -to a device for OpenMP offload mechanism. - -The syntax of the declare target directive is as follows: - - .. code-block:: c - - #pragma omp declare target new-line - declarations-definition-seq - #pragma omp end declare target new-line - -or - - .. code-block:: c - - #pragma omp declare target (extended-list) new-line - -or - - .. code-block:: c - - #pragma omp declare target clause[ [,] clause ... ] new-line - -where clause is one of the following: - - - .. code-block:: c - - to(extended-list) - link(list) - device_type(host | nohost | any) - - -#pragma omp declare variant ---------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","","``omp declare variant``","" - -The `declare variant` directive declares a specialized variant of a base - function and specifies the context in which that specialized variant is used. - The declare variant directive is a declarative directive. -The syntax of the `declare variant` construct is as follows: - - .. code-block:: none - - #pragma omp declare variant(variant-func-id) clause new-line - [#pragma omp declare variant(variant-func-id) clause new-line] - [...] - function definition or declaration - -where clause is one of the following: - - .. code-block:: none - - match(context-selector-specification) - -and where `variant-func-id` is the name of a function variant that is either a - base language identifier or, for C++, a template-id. - - -_Noreturn ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``_Noreturn``","","" - -A function declared as ``_Noreturn`` shall not return to its caller. The -compiler will generate a diagnostic for a function declared as ``_Noreturn`` -that appears to be capable of returning to its caller. Despite being a type -specifier, the ``_Noreturn`` attribute cannot be specified on a function -pointer type. - - -abi_tag -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``abi_tag``","``gnu::abi_tag``","","","","","Yes" - -The ``abi_tag`` attribute can be applied to a function, variable, class or -inline namespace declaration to modify the mangled name of the entity. It gives -the ability to distinguish between different versions of the same entity but -with different ABI versions supported. For example, a newer version of a class -could have a different set of data members and thus have a different size. Using -the ``abi_tag`` attribute, it is possible to have different mangled names for -a global variable of the class type. Therefore, the old code could keep using -the old manged name and the new code will use the new mangled name with tags. - - -acquire_capability, acquire_shared_capability ---------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``acquire_capability`` |br| ``acquire_shared_capability`` |br| ``exclusive_lock_function`` |br| ``shared_lock_function``","``clang::acquire_capability`` |br| ``clang::acquire_shared_capability``","","","","","" - -Marks a function as acquiring a capability. - - -alloc_align ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``alloc_align``","``gnu::alloc_align``","","","","","" - -Use ``__attribute__((alloc_align())`` on a function -declaration to specify that the return value of the function (which must be a -pointer type) is at least as aligned as the value of the indicated parameter. The -parameter is given by its index in the list of formal parameters; the first -parameter has index 1 unless the function is a C++ non-static member function, -in which case the first parameter has index 2 to account for the implicit ``this`` -parameter. - -.. code-block:: c++ - - // The returned pointer has the alignment specified by the first parameter. - void *a(size_t align) __attribute__((alloc_align(1))); - - // The returned pointer has the alignment specified by the second parameter. - void *b(void *v, size_t align) __attribute__((alloc_align(2))); - - // The returned pointer has the alignment specified by the second visible - // parameter, however it must be adjusted for the implicit 'this' parameter. - void *Foo::b(void *v, size_t align) __attribute__((alloc_align(3))); - -Note that this attribute merely informs the compiler that a function always -returns a sufficiently aligned pointer. It does not cause the compiler to -emit code to enforce that alignment. The behavior is undefined if the returned -poitner is not sufficiently aligned. - - -alloc_size ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``alloc_size``","``gnu::alloc_size``","","","","","Yes" - -The ``alloc_size`` attribute can be placed on functions that return pointers in -order to hint to the compiler how many bytes of memory will be available at the -returned pointer. ``alloc_size`` takes one or two arguments. - -- ``alloc_size(N)`` implies that argument number N equals the number of - available bytes at the returned pointer. -- ``alloc_size(N, M)`` implies that the product of argument number N and - argument number M equals the number of available bytes at the returned - pointer. - -Argument numbers are 1-based. - -An example of how to use ``alloc_size`` - -.. code-block:: c - - void *my_malloc(int a) __attribute__((alloc_size(1))); - void *my_calloc(int a, int b) __attribute__((alloc_size(1, 2))); - - int main() { - void *const p = my_malloc(100); - assert(__builtin_object_size(p, 0) == 100); - void *const a = my_calloc(20, 5); - assert(__builtin_object_size(a, 0) == 100); - } - -.. Note:: This attribute works differently in clang than it does in GCC. - Specifically, clang will only trace ``const`` pointers (as above); we give up - on pointers that are not marked as ``const``. In the vast majority of cases, - this is unimportant, because LLVM has support for the ``alloc_size`` - attribute. However, this may cause mildly unintuitive behavior when used with - other attributes, such as ``enable_if``. - - -allocator ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","``allocator``","","","" - -The ``__declspec(allocator)`` attribute is applied to functions that allocate -memory, such as operator new in C++. When CodeView debug information is emitted -(enabled by ``clang -gcodeview`` or ``clang-cl /Z7``), Clang will attempt to -record the code offset of heap allocation call sites in the debug info. It will -also record the type being allocated using some local heuristics. The Visual -Studio debugger uses this information to `profile memory usage`_. - -.. _profile memory usage: https://docs.microsoft.com/en-us/visualstudio/profiling/memory-usage - -This attribute does not affect optimizations in any way, unlike GCC's -``__attribute__((malloc))``. - - -artificial ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``artificial``","``gnu::artificial``","","","","","" - -The ``artificial`` attribute can be applied to an inline function. If such a -function is inlined, the attribute indicates that debuggers should associate -the resulting instructions with the call site, rather than with the -corresponding line within the inlined callee. - - -assert_capability, assert_shared_capability -------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``assert_capability`` |br| ``assert_shared_capability``","``clang::assert_capability`` |br| ``clang::assert_shared_capability``","","","","","" - -Marks a function that dynamically tests whether a capability is held, and halts -the program if it is not held. - - -assume_aligned --------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``assume_aligned``","``gnu::assume_aligned``","","","","","Yes" - -Use ``__attribute__((assume_aligned([,]))`` on a function -declaration to specify that the return value of the function (which must be a -pointer type) has the specified offset, in bytes, from an address with the -specified alignment. The offset is taken to be zero if omitted. - -.. code-block:: c++ - - // The returned pointer value has 32-byte alignment. - void *a() __attribute__((assume_aligned (32))); - - // The returned pointer value is 4 bytes greater than an address having - // 32-byte alignment. - void *b() __attribute__((assume_aligned (32, 4))); - -Note that this attribute provides information to the compiler regarding a -condition that the code already ensures is true. It does not cause the compiler -to enforce the provided alignment assumption. - - -availability ------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``availability``","``clang::availability``","``clang::availability``","","","","Yes" - -The ``availability`` attribute can be placed on declarations to describe the -lifecycle of that declaration relative to operating system versions. Consider -the function declaration for a hypothetical function ``f``: - -.. code-block:: c++ - - void f(void) __attribute__((availability(macos,introduced=10.4,deprecated=10.6,obsoleted=10.7))); - -The availability attribute states that ``f`` was introduced in macOS 10.4, -deprecated in macOS 10.6, and obsoleted in macOS 10.7. This information -is used by Clang to determine when it is safe to use ``f``: for example, if -Clang is instructed to compile code for macOS 10.5, a call to ``f()`` -succeeds. If Clang is instructed to compile code for macOS 10.6, the call -succeeds but Clang emits a warning specifying that the function is deprecated. -Finally, if Clang is instructed to compile code for macOS 10.7, the call -fails because ``f()`` is no longer available. - -The availability attribute is a comma-separated list starting with the -platform name and then including clauses specifying important milestones in the -declaration's lifetime (in any order) along with additional information. Those -clauses can be: - -introduced=\ *version* - The first version in which this declaration was introduced. - -deprecated=\ *version* - The first version in which this declaration was deprecated, meaning that - users should migrate away from this API. - -obsoleted=\ *version* - The first version in which this declaration was obsoleted, meaning that it - was removed completely and can no longer be used. - -unavailable - This declaration is never available on this platform. - -message=\ *string-literal* - Additional message text that Clang will provide when emitting a warning or - error about use of a deprecated or obsoleted declaration. Useful to direct - users to replacement APIs. - -replacement=\ *string-literal* - Additional message text that Clang will use to provide Fix-It when emitting - a warning about use of a deprecated declaration. The Fix-It will replace - the deprecated declaration with the new declaration specified. - -Multiple availability attributes can be placed on a declaration, which may -correspond to different platforms. For most platforms, the availability -attribute with the platform corresponding to the target platform will be used; -any others will be ignored. However, the availability for ``watchOS`` and -``tvOS`` can be implicitly inferred from an ``iOS`` availability attribute. -Any explicit availability attributes for those platforms are still prefered over -the implicitly inferred availability attributes. If no availability attribute -specifies availability for the current target platform, the availability -attributes are ignored. Supported platforms are: - -``ios`` - Apple's iOS operating system. The minimum deployment target is specified by - the ``-mios-version-min=*version*`` or ``-miphoneos-version-min=*version*`` - command-line arguments. - -``macos`` - Apple's macOS operating system. The minimum deployment target is - specified by the ``-mmacosx-version-min=*version*`` command-line argument. - ``macosx`` is supported for backward-compatibility reasons, but it is - deprecated. - -``tvos`` - Apple's tvOS operating system. The minimum deployment target is specified by - the ``-mtvos-version-min=*version*`` command-line argument. - -``watchos`` - Apple's watchOS operating system. The minimum deployment target is specified by - the ``-mwatchos-version-min=*version*`` command-line argument. - -A declaration can typically be used even when deploying back to a platform -version prior to when the declaration was introduced. When this happens, the -declaration is `weakly linked -`_, -as if the ``weak_import`` attribute were added to the declaration. A -weakly-linked declaration may or may not be present a run-time, and a program -can determine whether the declaration is present by checking whether the -address of that declaration is non-NULL. - -The flag ``strict`` disallows using API when deploying back to a -platform version prior to when the declaration was introduced. An -attempt to use such API before its introduction causes a hard error. -Weakly-linking is almost always a better API choice, since it allows -users to query availability at runtime. - -If there are multiple declarations of the same entity, the availability -attributes must either match on a per-platform basis or later -declarations must not have availability attributes for that -platform. For example: - -.. code-block:: c - - void g(void) __attribute__((availability(macos,introduced=10.4))); - void g(void) __attribute__((availability(macos,introduced=10.4))); // okay, matches - void g(void) __attribute__((availability(ios,introduced=4.0))); // okay, adds a new platform - void g(void); // okay, inherits both macos and ios availability from above. - void g(void) __attribute__((availability(macos,introduced=10.5))); // error: mismatch - -When one method overrides another, the overriding method can be more widely available than the overridden method, e.g.,: - -.. code-block:: objc - - @interface A - - (id)method __attribute__((availability(macos,introduced=10.4))); - - (id)method2 __attribute__((availability(macos,introduced=10.4))); - @end - - @interface B : A - - (id)method __attribute__((availability(macos,introduced=10.3))); // okay: method moved into base class later - - (id)method __attribute__((availability(macos,introduced=10.5))); // error: this method was available via the base class in 10.4 - @end - -Starting with the macOS 10.12 SDK, the ``API_AVAILABLE`` macro from -```` can simplify the spelling: - -.. code-block:: objc - - @interface A - - (id)method API_AVAILABLE(macos(10.11))); - - (id)otherMethod API_AVAILABLE(macos(10.11), ios(11.0)); - @end - -Availability attributes can also be applied using a ``#pragma clang attribute``. -Any explicit availability attribute whose platform corresponds to the target -platform is applied to a declaration regardless of the availability attributes -specified in the pragma. For example, in the code below, -``hasExplicitAvailabilityAttribute`` will use the ``macOS`` availability -attribute that is specified with the declaration, whereas -``getsThePragmaAvailabilityAttribute`` will use the ``macOS`` availability -attribute that is applied by the pragma. - -.. code-block:: c - - #pragma clang attribute push (__attribute__((availability(macOS, introduced=10.12))), apply_to=function) - void getsThePragmaAvailabilityAttribute(void); - void hasExplicitAvailabilityAttribute(void) __attribute__((availability(macos,introduced=10.4))); - #pragma clang attribute pop - -For platforms like ``watchOS`` and ``tvOS``, whose availability attributes can -be implicitly inferred from an ``iOS`` availability attribute, the logic is -slightly more complex. The explicit and the pragma-applied availability -attributes whose platform corresponds to the target platform are applied as -described in the previous paragraph. However, the implicitly inferred attributes -are applied to a declaration only when there is no explicit or pragma-applied -availability attribute whose platform corresponds to the target platform. For -example, the function below will receive the ``tvOS`` availability from the -pragma rather than using the inferred ``iOS`` availability from the declaration: - -.. code-block:: c - - #pragma clang attribute push (__attribute__((availability(tvOS, introduced=12.0))), apply_to=function) - void getsThePragmaTVOSAvailabilityAttribute(void) __attribute__((availability(iOS,introduced=11.0))); - #pragma clang attribute pop - -The compiler is also able to apply implicly inferred attributes from a pragma -as well. For example, when targeting ``tvOS``, the function below will receive -a ``tvOS`` availability attribute that is implicitly inferred from the ``iOS`` -availability attribute applied by the pragma: - -.. code-block:: c - - #pragma clang attribute push (__attribute__((availability(iOS, introduced=12.0))), apply_to=function) - void infersTVOSAvailabilityFromPragma(void); - #pragma clang attribute pop - -The implicit attributes that are inferred from explicitly specified attributes -whose platform corresponds to the target platform are applied to the declaration -even if there is an availability attribute that can be inferred from a pragma. -For example, the function below will receive the ``tvOS, introduced=11.0`` -availability that is inferred from the attribute on the declaration rather than -inferring availability from the pragma: - -.. code-block:: c - - #pragma clang attribute push (__attribute__((availability(iOS, unavailable))), apply_to=function) - void infersTVOSAvailabilityFromAttributeNextToDeclaration(void) - __attribute__((availability(iOS,introduced=11.0))); - #pragma clang attribute pop - -Also see the documentation for `@available -`_ - - -callback --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``callback``","``clang::callback``","``clang::callback``","","","","Yes" - -The ``callback`` attribute specifies that the annotated function may invoke the -specified callback zero or more times. The callback, as well as the passed -arguments, are identified by their parameter name or position (starting with -1!) in the annotated function. The first position in the attribute identifies -the callback callee, the following positions declare describe its arguments. -The callback callee is required to be callable with the number, and order, of -the specified arguments. The index `0`, or the identifier `this`, is used to -represent an implicit "this" pointer in class methods. If there is no implicit -"this" pointer it shall not be referenced. The index '-1', or the name "__", -represents an unknown callback callee argument. This can be a value which is -not present in the declared parameter list, or one that is, but is potentially -inspected, captured, or modified. Parameter names and indices can be mixed in -the callback attribute. - -The ``callback`` attribute, which is directly translated to ``callback`` -metadata , make the -connection between the call to the annotated function and the callback callee. -This can enable interprocedural optimizations which were otherwise impossible. -If a function parameter is mentioned in the ``callback`` attribute, through its -position, it is undefined if that parameter is used for anything other than the -actual callback. Inspected, captured, or modified parameters shall not be -listed in the ``callback`` metadata. - -Example encodings for the callback performed by `pthread_create` are shown -below. The explicit attribute annotation indicates that the third parameter -(`start_routine`) is called zero or more times by the `pthread_create` function, -and that the fourth parameter (`arg`) is passed along. Note that the callback -behavior of `pthread_create` is automatically recognized by Clang. In addition, -the declarations of `__kmpc_fork_teams` and `__kmpc_fork_call`, generated for -`#pragma omp target teams` and `#pragma omp parallel`, respectively, are also -automatically recognized as broker functions. Further functions might be added -in the future. - - .. code-block:: c - - __attribute__((callback (start_routine, arg))) - int pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg); - - __attribute__((callback (3, 4))) - int pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg); - - -carries_dependency ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``carries_dependency``","``carries_dependency``","","","","","Yes" - -The ``carries_dependency`` attribute specifies dependency propagation into and -out of functions. - -When specified on a function or Objective-C method, the ``carries_dependency`` -attribute means that the return value carries a dependency out of the function, -so that the implementation need not constrain ordering upon return from that -function. Implementations of the function and its caller may choose to preserve -dependencies instead of emitting memory ordering instructions such as fences. - -Note, this attribute does not change the meaning of the program, but may result -in generation of more efficient code. - - -cf_consumed ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``cf_consumed``","``clang::cf_consumed``","``clang::cf_consumed``","","","","Yes" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -cf_returns_not_retained ------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``cf_returns_not_retained``","``clang::cf_returns_not_retained``","``clang::cf_returns_not_retained``","","","","" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -cf_returns_retained -------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``cf_returns_retained``","``clang::cf_returns_retained``","``clang::cf_returns_retained``","","","","" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -cfi_canonical_jump_table ------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``cfi_canonical_jump_table``","``clang::cfi_canonical_jump_table``","``clang::cfi_canonical_jump_table``","","","","Yes" - -.. _langext-cfi_canonical_jump_table: - -Use ``__attribute__((cfi_canonical_jump_table))`` on a function declaration to -make the function's CFI jump table canonical. See :ref:`the CFI documentation -` for more details. - - -clang_arm_mve_alias -------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``__clang_arm_mve_alias``","``clang::__clang_arm_mve_alias``","``clang::__clang_arm_mve_alias``","","","","Yes" - -This attribute is used in the implementation of the ACLE intrinsics -for the Arm MVE instruction set. It allows the intrinsic functions to -be declared using the names defined in ACLE, and still be recognized -as clang builtins equivalent to the underlying name. For example, -``arm_mve.h`` declares the function ``vaddq_u32`` with -``__attribute__((__clang_arm_mve_alias(__builtin_arm_mve_vaddq_u32)))``, -and similarly, one of the type-overloaded declarations of ``vaddq`` -will have the same attribute. This ensures that both functions are -recognized as that clang builtin, and in the latter case, the choice -of which builtin to identify the function as can be deferred until -after overload resolution. - -This attribute can only be used to set up the aliases for the MVE -intrinsic functions; it is intended for use only inside ``arm_mve.h``, -and is not a general mechanism for declaring arbitrary aliases for -clang builtin functions. - - -code_seg --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","``code_seg``","","","" - -The ``__declspec(code_seg)`` attribute enables the placement of code into separate -named segments that can be paged or locked in memory individually. This attribute -is used to control the placement of instantiated templates and compiler-generated -code. See the documentation for `__declspec(code_seg)`_ on MSDN. - -.. _`__declspec(code_seg)`: http://msdn.microsoft.com/en-us/library/dn636922.aspx - - -convergent ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``convergent``","``clang::convergent``","``clang::convergent``","","","","Yes" - -The ``convergent`` attribute can be placed on a function declaration. It is -translated into the LLVM ``convergent`` attribute, which indicates that the call -instructions of a function with this attribute cannot be made control-dependent -on any additional values. - -In languages designed for SPMD/SIMT programming model, e.g. OpenCL or CUDA, -the call instructions of a function with this attribute must be executed by -all work items or threads in a work group or sub group. - -This attribute is different from ``noduplicate`` because it allows duplicating -function calls if it can be proved that the duplicated function calls are -not made control-dependent on any additional values, e.g., unrolling a loop -executed by all work items. - -Sample usage: -.. code-block:: c - - void convfunc(void) __attribute__((convergent)); - // Setting it as a C++11 attribute is also valid in a C++ program. - // void convfunc(void) [[clang::convergent]]; - - -cpu_dispatch ------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``cpu_dispatch``","``clang::cpu_dispatch``","``clang::cpu_dispatch``","``cpu_dispatch``","","","Yes" - -The ``cpu_specific`` and ``cpu_dispatch`` attributes are used to define and -resolve multiversioned functions. This form of multiversioning provides a -mechanism for declaring versions across translation units and manually -specifying the resolved function list. A specified CPU defines a set of minimum -features that are required for the function to be called. The result of this is -that future processors execute the most restrictive version of the function the -new processor can execute. - -Function versions are defined with ``cpu_specific``, which takes one or more CPU -names as a parameter. For example: - -.. code-block:: c - - // Declares and defines the ivybridge version of single_cpu. - __attribute__((cpu_specific(ivybridge))) - void single_cpu(void){} - - // Declares and defines the atom version of single_cpu. - __attribute__((cpu_specific(atom))) - void single_cpu(void){} - - // Declares and defines both the ivybridge and atom version of multi_cpu. - __attribute__((cpu_specific(ivybridge, atom))) - void multi_cpu(void){} - -A dispatching (or resolving) function can be declared anywhere in a project's -source code with ``cpu_dispatch``. This attribute takes one or more CPU names -as a parameter (like ``cpu_specific``). Functions marked with ``cpu_dispatch`` -are not expected to be defined, only declared. If such a marked function has a -definition, any side effects of the function are ignored; trivial function -bodies are permissible for ICC compatibility. - -.. code-block:: c - - // Creates a resolver for single_cpu above. - __attribute__((cpu_dispatch(ivybridge, atom))) - void single_cpu(void){} - - // Creates a resolver for multi_cpu, but adds a 3rd version defined in another - // translation unit. - __attribute__((cpu_dispatch(ivybridge, atom, sandybridge))) - void multi_cpu(void){} - -Note that it is possible to have a resolving function that dispatches based on -more or fewer options than are present in the program. Specifying fewer will -result in the omitted options not being considered during resolution. Specifying -a version for resolution that isn't defined in the program will result in a -linking failure. - -It is also possible to specify a CPU name of ``generic`` which will be resolved -if the executing processor doesn't satisfy the features required in the CPU -name. The behavior of a program executing on a processor that doesn't satisfy -any option of a multiversioned function is undefined. - - -cpu_specific ------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``cpu_specific``","``clang::cpu_specific``","``clang::cpu_specific``","``cpu_specific``","","","Yes" - -The ``cpu_specific`` and ``cpu_dispatch`` attributes are used to define and -resolve multiversioned functions. This form of multiversioning provides a -mechanism for declaring versions across translation units and manually -specifying the resolved function list. A specified CPU defines a set of minimum -features that are required for the function to be called. The result of this is -that future processors execute the most restrictive version of the function the -new processor can execute. - -Function versions are defined with ``cpu_specific``, which takes one or more CPU -names as a parameter. For example: - -.. code-block:: c - - // Declares and defines the ivybridge version of single_cpu. - __attribute__((cpu_specific(ivybridge))) - void single_cpu(void){} - - // Declares and defines the atom version of single_cpu. - __attribute__((cpu_specific(atom))) - void single_cpu(void){} - - // Declares and defines both the ivybridge and atom version of multi_cpu. - __attribute__((cpu_specific(ivybridge, atom))) - void multi_cpu(void){} - -A dispatching (or resolving) function can be declared anywhere in a project's -source code with ``cpu_dispatch``. This attribute takes one or more CPU names -as a parameter (like ``cpu_specific``). Functions marked with ``cpu_dispatch`` -are not expected to be defined, only declared. If such a marked function has a -definition, any side effects of the function are ignored; trivial function -bodies are permissible for ICC compatibility. - -.. code-block:: c - - // Creates a resolver for single_cpu above. - __attribute__((cpu_dispatch(ivybridge, atom))) - void single_cpu(void){} - - // Creates a resolver for multi_cpu, but adds a 3rd version defined in another - // translation unit. - __attribute__((cpu_dispatch(ivybridge, atom, sandybridge))) - void multi_cpu(void){} - -Note that it is possible to have a resolving function that dispatches based on -more or fewer options than are present in the program. Specifying fewer will -result in the omitted options not being considered during resolution. Specifying -a version for resolution that isn't defined in the program will result in a -linking failure. - -It is also possible to specify a CPU name of ``generic`` which will be resolved -if the executing processor doesn't satisfy the features required in the CPU -name. The behavior of a program executing on a processor that doesn't satisfy -any option of a multiversioned function is undefined. - - -diagnose_if ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``diagnose_if``","","","","","","" - -The ``diagnose_if`` attribute can be placed on function declarations to emit -warnings or errors at compile-time if calls to the attributed function meet -certain user-defined criteria. For example: - -.. code-block:: c - - int abs(int a) - __attribute__((diagnose_if(a >= 0, "Redundant abs call", "warning"))); - int must_abs(int a) - __attribute__((diagnose_if(a >= 0, "Redundant abs call", "error"))); - - int val = abs(1); // warning: Redundant abs call - int val2 = must_abs(1); // error: Redundant abs call - int val3 = abs(val); - int val4 = must_abs(val); // Because run-time checks are not emitted for - // diagnose_if attributes, this executes without - // issue. - - -``diagnose_if`` is closely related to ``enable_if``, with a few key differences: - -* Overload resolution is not aware of ``diagnose_if`` attributes: they're - considered only after we select the best candidate from a given candidate set. -* Function declarations that differ only in their ``diagnose_if`` attributes are - considered to be redeclarations of the same function (not overloads). -* If the condition provided to ``diagnose_if`` cannot be evaluated, no - diagnostic will be emitted. - -Otherwise, ``diagnose_if`` is essentially the logical negation of ``enable_if``. - -As a result of bullet number two, ``diagnose_if`` attributes will stack on the -same function. For example: - -.. code-block:: c - - int foo() __attribute__((diagnose_if(1, "diag1", "warning"))); - int foo() __attribute__((diagnose_if(1, "diag2", "warning"))); - - int bar = foo(); // warning: diag1 - // warning: diag2 - int (*fooptr)(void) = foo; // warning: diag1 - // warning: diag2 - - constexpr int supportsAPILevel(int N) { return N < 5; } - int baz(int a) - __attribute__((diagnose_if(!supportsAPILevel(10), - "Upgrade to API level 10 to use baz", "error"))); - int baz(int a) - __attribute__((diagnose_if(!a, "0 is not recommended.", "warning"))); - - int (*bazptr)(int) = baz; // error: Upgrade to API level 10 to use baz - int v = baz(0); // error: Upgrade to API level 10 to use baz - -Query for this feature with ``__has_attribute(diagnose_if)``. - - -disable_tail_calls ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``disable_tail_calls``","``clang::disable_tail_calls``","``clang::disable_tail_calls``","","","","Yes" - -The ``disable_tail_calls`` attribute instructs the backend to not perform tail call optimization inside the marked function. - -For example: - - .. code-block:: c - - int callee(int); - - int foo(int a) __attribute__((disable_tail_calls)) { - return callee(a); // This call is not tail-call optimized. - } - -Marking virtual functions as ``disable_tail_calls`` is legal. - - .. code-block:: c++ - - int callee(int); - - class Base { - public: - [[clang::disable_tail_calls]] virtual int foo1() { - return callee(); // This call is not tail-call optimized. - } - }; - - class Derived1 : public Base { - public: - int foo1() override { - return callee(); // This call is tail-call optimized. - } - }; - - -enable_if ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``enable_if``","","","","","","Yes" - -.. Note:: Some features of this attribute are experimental. The meaning of - multiple enable_if attributes on a single declaration is subject to change in - a future version of clang. Also, the ABI is not standardized and the name - mangling may change in future versions. To avoid that, use asm labels. - -The ``enable_if`` attribute can be placed on function declarations to control -which overload is selected based on the values of the function's arguments. -When combined with the ``overloadable`` attribute, this feature is also -available in C. - -.. code-block:: c++ - - int isdigit(int c); - 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"))); - - void foo(char c) { - isdigit(c); - isdigit(10); - isdigit(-10); // results in a compile-time error. - } - -The enable_if attribute takes two arguments, the first is an expression written -in terms of the function parameters, the second is a string explaining why this -overload candidate could not be selected to be displayed in diagnostics. The -expression is part of the function signature for the purposes of determining -whether it is a redeclaration (following the rules used when determining -whether a C++ template specialization is ODR-equivalent), but is not part of -the type. - -The enable_if expression is evaluated as if it were the body of a -bool-returning constexpr function declared with the arguments of the function -it is being applied to, then called with the parameters at the call site. If the -result is false or could not be determined through constant expression -evaluation, then this overload will not be chosen and the provided string may -be used in a diagnostic if the compile fails as a result. - -Because the enable_if expression is an unevaluated context, there are no global -state changes, nor the ability to pass information from the enable_if -expression to the function body. For example, suppose we want calls to -strnlen(strbuf, maxlen) to resolve to strnlen_chk(strbuf, maxlen, size of -strbuf) only if the size of strbuf can be determined: - -.. code-block:: c++ - - __attribute__((always_inline)) - static inline size_t strnlen(const char *s, size_t maxlen) - __attribute__((overloadable)) - __attribute__((enable_if(__builtin_object_size(s, 0) != -1))), - "chosen when the buffer size is known but 'maxlen' is not"))) - { - return strnlen_chk(s, maxlen, __builtin_object_size(s, 0)); - } - -Multiple enable_if attributes may be applied to a single declaration. In this -case, the enable_if expressions are evaluated from left to right in the -following manner. First, the candidates whose enable_if expressions evaluate to -false or cannot be evaluated are discarded. If the remaining candidates do not -share ODR-equivalent enable_if expressions, the overload resolution is -ambiguous. Otherwise, enable_if overload resolution continues with the next -enable_if attribute on the candidates that have not been discarded and have -remaining enable_if attributes. In this way, we pick the most specific -overload out of a number of viable overloads using enable_if. - -.. code-block:: c++ - - void f() __attribute__((enable_if(true, ""))); // #1 - void f() __attribute__((enable_if(true, ""))) __attribute__((enable_if(true, ""))); // #2 - - void g(int i, int j) __attribute__((enable_if(i, ""))); // #1 - void g(int i, int j) __attribute__((enable_if(j, ""))) __attribute__((enable_if(true))); // #2 - -In this example, a call to f() is always resolved to #2, as the first enable_if -expression is ODR-equivalent for both declarations, but #1 does not have another -enable_if expression to continue evaluating, so the next round of evaluation has -only a single candidate. In a call to g(1, 1), the call is ambiguous even though -#2 has more enable_if attributes, because the first enable_if expressions are -not ODR-equivalent. - -Query for this feature with ``__has_attribute(enable_if)``. - -Note that functions with one or more ``enable_if`` attributes may not have -their address taken, unless all of the conditions specified by said -``enable_if`` are constants that evaluate to ``true``. For example: - -.. code-block:: c - - const int TrueConstant = 1; - const int FalseConstant = 0; - int f(int a) __attribute__((enable_if(a > 0, ""))); - int g(int a) __attribute__((enable_if(a == 0 || a != 0, ""))); - int h(int a) __attribute__((enable_if(1, ""))); - int i(int a) __attribute__((enable_if(TrueConstant, ""))); - int j(int a) __attribute__((enable_if(FalseConstant, ""))); - - void fn() { - int (*ptr)(int); - ptr = &f; // error: 'a > 0' is not always true - ptr = &g; // error: 'a == 0 || a != 0' is not a truthy constant - ptr = &h; // OK: 1 is a truthy constant - ptr = &i; // OK: 'TrueConstant' is a truthy constant - ptr = &j; // error: 'FalseConstant' is a constant, but not truthy - } - -Because ``enable_if`` evaluation happens during overload resolution, -``enable_if`` may give unintuitive results when used with templates, depending -on when overloads are resolved. In the example below, clang will emit a -diagnostic about no viable overloads for ``foo`` in ``bar``, but not in ``baz``: - -.. code-block:: c++ - - double foo(int i) __attribute__((enable_if(i > 0, ""))); - void *foo(int i) __attribute__((enable_if(i <= 0, ""))); - template - auto bar() { return foo(I); } - - template - auto baz() { return foo(T::number); } - - struct WithNumber { constexpr static int number = 1; }; - void callThem() { - bar(); - baz(); - } - -This is because, in ``bar``, ``foo`` is resolved prior to template -instantiation, so the value for ``I`` isn't known (thus, both ``enable_if`` -conditions for ``foo`` fail). However, in ``baz``, ``foo`` is resolved during -template instantiation, so the value for ``T::number`` is known. - - -exclude_from_explicit_instantiation ------------------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``exclude_from_explicit_instantiation``","``clang::exclude_from_explicit_instantiation``","``clang::exclude_from_explicit_instantiation``","","","","Yes" - -The ``exclude_from_explicit_instantiation`` attribute opts-out a member of a -class template from being part of explicit template instantiations of that -class template. This means that an explicit instantiation will not instantiate -members of the class template marked with the attribute, but also that code -where an extern template declaration of the enclosing class template is visible -will not take for granted that an external instantiation of the class template -would provide those members (which would otherwise be a link error, since the -explicit instantiation won't provide those members). For example, let's say we -don't want the ``data()`` method to be part of libc++'s ABI. To make sure it -is not exported from the dylib, we give it hidden visibility: - - .. code-block:: c++ - - // in - template - class basic_string { - public: - __attribute__((__visibility__("hidden"))) - const value_type* data() const noexcept { ... } - }; - - template class basic_string; - -Since an explicit template instantiation declaration for ``basic_string`` -is provided, the compiler is free to assume that ``basic_string::data()`` -will be provided by another translation unit, and it is free to produce an -external call to this function. However, since ``data()`` has hidden visibility -and the explicit template instantiation is provided in a shared library (as -opposed to simply another translation unit), ``basic_string::data()`` -won't be found and a link error will ensue. This happens because the compiler -assumes that ``basic_string::data()`` is part of the explicit template -instantiation declaration, when it really isn't. To tell the compiler that -``data()`` is not part of the explicit template instantiation declaration, the -``exclude_from_explicit_instantiation`` attribute can be used: - - .. code-block:: c++ - - // in - template - class basic_string { - public: - __attribute__((__visibility__("hidden"))) - __attribute__((exclude_from_explicit_instantiation)) - const value_type* data() const noexcept { ... } - }; - - template class basic_string; - -Now, the compiler won't assume that ``basic_string::data()`` is provided -externally despite there being an explicit template instantiation declaration: -the compiler will implicitly instantiate ``basic_string::data()`` in the -TUs where it is used. - -This attribute can be used on static and non-static member functions of class -templates, static data members of class templates and member classes of class -templates. - - -export_name ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``export_name``","``clang::export_name``","``clang::export_name``","","","","Yes" - -Clang supports the ``__attribute__((export_name()))`` -attribute for the WebAssembly target. This attribute may be attached to a -function declaration, where it modifies how the symbol is to be exported -from the linked WebAssembly. - -WebAssembly functions are exported via string name. By default when a symbol -is exported, the export name for C/C++ symbols are the same as their C/C++ -symbol names. This attribute can be used to override the default behavior, and -request a specific string name be used instead. - - -flatten -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``flatten``","``gnu::flatten``","","","","","Yes" - -The ``flatten`` attribute causes calls within the attributed function to -be inlined unless it is impossible to do so, for example if the body of the -callee is unavailable or if the callee has the ``noinline`` attribute. - - -force_align_arg_pointer ------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``force_align_arg_pointer``","``gnu::force_align_arg_pointer``","","","","","" - -Use this attribute to force stack alignment. - -Legacy x86 code uses 4-byte stack alignment. Newer aligned SSE instructions -(like 'movaps') that work with the stack require operands to be 16-byte aligned. -This attribute realigns the stack in the function prologue to make sure the -stack can be used with SSE instructions. - -Note that the x86_64 ABI forces 16-byte stack alignment at the call site. -Because of this, 'force_align_arg_pointer' is not needed on x86_64, except in -rare cases where the caller does not align the stack properly (e.g. flow -jumps from i386 arch code). - - .. code-block:: c - - __attribute__ ((force_align_arg_pointer)) - void f () { - ... - } - - -format ------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``format``","``gnu::format``","","","","","" - -Clang supports the ``format`` attribute, which indicates that the function -accepts a ``printf`` or ``scanf``-like format string and corresponding -arguments or a ``va_list`` that contains these arguments. - -Please see `GCC documentation about format attribute -`_ to find details -about attribute syntax. - -Clang implements two kinds of checks with this attribute. - -#. Clang checks that the function with the ``format`` attribute is called with - a format string that uses format specifiers that are allowed, and that - arguments match the format string. This is the ``-Wformat`` warning, it is - on by default. - -#. Clang checks that the format string argument is a literal string. This is - the ``-Wformat-nonliteral`` warning, it is off by default. - - Clang implements this mostly the same way as GCC, but there is a difference - for functions that accept a ``va_list`` argument (for example, ``vprintf``). - GCC does not emit ``-Wformat-nonliteral`` warning for calls to such - functions. Clang does not warn if the format string comes from a function - parameter, where the function is annotated with a compatible attribute, - otherwise it warns. For example: - - .. code-block:: c - - __attribute__((__format__ (__scanf__, 1, 3))) - void foo(const char* s, char *buf, ...) { - va_list ap; - va_start(ap, buf); - - vprintf(s, ap); // warning: format string is not a string literal - } - - In this case we warn because ``s`` contains a format string for a - ``scanf``-like function, but it is passed to a ``printf``-like function. - - If the attribute is removed, clang still warns, because the format string is - not a string literal. - - Another example: - - .. code-block:: c - - __attribute__((__format__ (__printf__, 1, 3))) - void foo(const char* s, char *buf, ...) { - va_list ap; - va_start(ap, buf); - - vprintf(s, ap); // warning - } - - In this case Clang does not warn because the format string ``s`` and - the corresponding arguments are annotated. If the arguments are - incorrect, the caller of ``foo`` will receive a warning. - - -gnu_inline ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``gnu_inline``","``gnu::gnu_inline``","","","","","Yes" - -The ``gnu_inline`` changes the meaning of ``extern inline`` to use GNU inline -semantics, meaning: - -* If any declaration that is declared ``inline`` is not declared ``extern``, - then the ``inline`` keyword is just a hint. In particular, an out-of-line - definition is still emitted for a function with external linkage, even if all - call sites are inlined, unlike in C99 and C++ inline semantics. - -* If all declarations that are declared ``inline`` are also declared - ``extern``, then the function body is present only for inlining and no - out-of-line version is emitted. - -Some important consequences: ``static inline`` emits an out-of-line -version if needed, a plain ``inline`` definition emits an out-of-line version -always, and an ``extern inline`` definition (in a header) followed by a -(non-``extern``) ``inline`` declaration in a source file emits an out-of-line -version of the function in that source file but provides the function body for -inlining to all includers of the header. - -Either ``__GNUC_GNU_INLINE__`` (GNU inline semantics) or -``__GNUC_STDC_INLINE__`` (C99 semantics) will be defined (they are mutually -exclusive). If ``__GNUC_STDC_INLINE__`` is defined, then the ``gnu_inline`` -function attribute can be used to get GNU inline semantics on a per function -basis. If ``__GNUC_GNU_INLINE__`` is defined, then the translation unit is -already being compiled with GNU inline semantics as the implied default. It is -unspecified which macro is defined in a C++ compilation. - -GNU inline semantics are the default behavior with ``-std=gnu89``, -``-std=c89``, ``-std=c94``, or ``-fgnu89-inline``. - - -guard ------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","``guard``","","","" - -Code can indicate CFG checks are not wanted with the ``__declspec(guard(nocf))`` -attribute. This directs the compiler to not insert any CFG checks for the entire -function. This approach is typically used only sparingly in specific situations -where the programmer has manually inserted "CFG-equivalent" protection. The -programmer knows that they are calling through some read-only function table -whose address is obtained through read-only memory references and for which the -index is masked to the function table limit. This approach may also be applied -to small wrapper functions that are not inlined and that do nothing more than -make a call through a function pointer. Since incorrect usage of this directive -can compromise the security of CFG, the programmer must be very careful using -the directive. Typically, this usage is limited to very small functions that -only call one function. - -`Control Flow Guard documentation ` - - -ifunc ------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``ifunc``","``gnu::ifunc``","","","","","Yes" - -``__attribute__((ifunc("resolver")))`` is used to mark that the address of a declaration should be resolved at runtime by calling a resolver function. - -The symbol name of the resolver function is given in quotes. A function with this name (after mangling) must be defined in the current translation unit; it may be ``static``. The resolver function should return a pointer. - -The ``ifunc`` attribute may only be used on a function declaration. A function declaration with an ``ifunc`` attribute is considered to be a definition of the declared entity. The entity must not have weak linkage; for example, in C++, it cannot be applied to a declaration if a definition at that location would be considered inline. - -Not all targets support this attribute. ELF target support depends on both the linker and runtime linker, and is available in at least lld 4.0 and later, binutils 2.20.1 and later, glibc v2.11.1 and later, and FreeBSD 9.1 and later. Non-ELF targets currently do not support this attribute. - - -import_module -------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``import_module``","``clang::import_module``","``clang::import_module``","","","","Yes" - -Clang supports the ``__attribute__((import_module()))`` -attribute for the WebAssembly target. This attribute may be attached to a -function declaration, where it modifies how the symbol is to be imported -within the WebAssembly linking environment. - -WebAssembly imports use a two-level namespace scheme, consisting of a module -name, which typically identifies a module from which to import, and a field -name, which typically identifies a field from that module to import. By -default, module names for C/C++ symbols are assigned automatically by the -linker. This attribute can be used to override the default behavior, and -request a specific module name be used instead. - - -import_name ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``import_name``","``clang::import_name``","``clang::import_name``","","","","Yes" - -Clang supports the ``__attribute__((import_name()))`` -attribute for the WebAssembly target. This attribute may be attached to a -function declaration, where it modifies how the symbol is to be imported -within the WebAssembly linking environment. - -WebAssembly imports use a two-level namespace scheme, consisting of a module -name, which typically identifies a module from which to import, and a field -name, which typically identifies a field from that module to import. By -default, field names for C/C++ symbols are the same as their C/C++ symbol -names. This attribute can be used to override the default behavior, and -request a specific field name be used instead. - - -internal_linkage ----------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``internal_linkage``","``clang::internal_linkage``","``clang::internal_linkage``","","","","Yes" - -The ``internal_linkage`` attribute changes the linkage type of the declaration to internal. -This is similar to C-style ``static``, but can be used on classes and class methods. When applied to a class definition, -this attribute affects all methods and static data members of that class. -This can be used to contain the ABI of a C++ library by excluding unwanted class methods from the export tables. - - -interrupt (ARM) ---------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``interrupt``","``gnu::interrupt``","","","","","" - -Clang supports the GNU style ``__attribute__((interrupt("TYPE")))`` attribute on -ARM targets. This attribute may be attached to a function definition and -instructs the backend to generate appropriate function entry/exit code so that -it can be used directly as an interrupt service routine. - -The parameter passed to the interrupt attribute is optional, but if -provided it must be a string literal with one of the following values: "IRQ", -"FIQ", "SWI", "ABORT", "UNDEF". - -The semantics are as follows: - -- If the function is AAPCS, Clang instructs the backend to realign the stack to - 8 bytes on entry. This is a general requirement of the AAPCS at public - interfaces, but may not hold when an exception is taken. Doing this allows - other AAPCS functions to be called. -- If the CPU is M-class this is all that needs to be done since the architecture - itself is designed in such a way that functions obeying the normal AAPCS ABI - constraints are valid exception handlers. -- If the CPU is not M-class, the prologue and epilogue are modified to save all - non-banked registers that are used, so that upon return the user-mode state - will not be corrupted. Note that to avoid unnecessary overhead, only - general-purpose (integer) registers are saved in this way. If VFP operations - are needed, that state must be saved manually. - - Specifically, interrupt kinds other than "FIQ" will save all core registers - except "lr" and "sp". "FIQ" interrupts will save r0-r7. -- If the CPU is not M-class, the return instruction is changed to one of the - canonical sequences permitted by the architecture for exception return. Where - possible the function itself will make the necessary "lr" adjustments so that - the "preferred return address" is selected. - - Unfortunately the compiler is unable to make this guarantee for an "UNDEF" - handler, where the offset from "lr" to the preferred return address depends on - the execution state of the code which generated the exception. In this case - a sequence equivalent to "movs pc, lr" will be used. - - -interrupt (AVR) ---------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``interrupt``","``gnu::interrupt``","","","","","Yes" - -Clang supports the GNU style ``__attribute__((interrupt))`` attribute on -AVR targets. This attribute may be attached to a function definition and instructs -the backend to generate appropriate function entry/exit code so that it can be used -directly as an interrupt service routine. - -On the AVR, the hardware globally disables interrupts when an interrupt is executed. -The first instruction of an interrupt handler declared with this attribute is a SEI -instruction to re-enable interrupts. See also the signal attribute that -does not insert a SEI instruction. - - -interrupt (MIPS) ----------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``interrupt``","``gnu::interrupt``","","","","","Yes" - -Clang supports the GNU style ``__attribute__((interrupt("ARGUMENT")))`` attribute on -MIPS targets. This attribute may be attached to a function definition and instructs -the backend to generate appropriate function entry/exit code so that it can be used -directly as an interrupt service routine. - -By default, the compiler will produce a function prologue and epilogue suitable for -an interrupt service routine that handles an External Interrupt Controller (eic) -generated interrupt. This behaviour can be explicitly requested with the "eic" -argument. - -Otherwise, for use with vectored interrupt mode, the argument passed should be -of the form "vector=LEVEL" where LEVEL is one of the following values: -"sw0", "sw1", "hw0", "hw1", "hw2", "hw3", "hw4", "hw5". The compiler will -then set the interrupt mask to the corresponding level which will mask all -interrupts up to and including the argument. - -The semantics are as follows: - -- The prologue is modified so that the Exception Program Counter (EPC) and - Status coprocessor registers are saved to the stack. The interrupt mask is - set so that the function can only be interrupted by a higher priority - interrupt. The epilogue will restore the previous values of EPC and Status. - -- The prologue and epilogue are modified to save and restore all non-kernel - registers as necessary. - -- The FPU is disabled in the prologue, as the floating pointer registers are not - spilled to the stack. - -- The function return sequence is changed to use an exception return instruction. - -- The parameter sets the interrupt mask for the function corresponding to the - interrupt level specified. If no mask is specified the interrupt mask - defaults to "eic". - - -interrupt (RISCV) ------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``interrupt``","``gnu::interrupt``","","","","","Yes" - -Clang supports the GNU style ``__attribute__((interrupt))`` attribute on RISCV -targets. This attribute may be attached to a function definition and instructs -the backend to generate appropriate function entry/exit code so that it can be -used directly as an interrupt service routine. - -Permissible values for this parameter are ``user``, ``supervisor``, -and ``machine``. If there is no parameter, then it defaults to machine. - -Repeated interrupt attribute on the same declaration will cause a warning -to be emitted. In case of repeated declarations, the last one prevails. - -Refer to: -https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Function-Attributes.html -https://riscv.org/specifications/privileged-isa/ -The RISC-V Instruction Set Manual Volume II: Privileged Architecture -Version 1.10. - - -kernel ------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``kernel``","","","","","","Yes" - -``__attribute__((kernel))`` is used to mark a ``kernel`` function in -RenderScript. - -In RenderScript, ``kernel`` functions are used to express data-parallel -computations. The RenderScript runtime efficiently parallelizes ``kernel`` -functions to run on computational resources such as multi-core CPUs and GPUs. -See the RenderScript_ documentation for more information. - -.. _RenderScript: https://developer.android.com/guide/topics/renderscript/compute.html - - -lifetimebound -------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``lifetimebound``","``clang::lifetimebound``","","","","","" - -The ``lifetimebound`` attribute indicates that a resource owned by -a function parameter or implicit object parameter -is retained by the return value of the annotated function -(or, for a parameter of a constructor, in the value of the constructed object). -It is only supported in C++. - -This attribute provides an experimental implementation of the facility -described in the C++ committee paper `P0936R0 `_, -and is subject to change as the design of the corresponding functionality -changes. - - -long_call, far --------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``long_call`` |br| ``far``","``gnu::long_call`` |br| ``gnu::far``","","","","","Yes" - -Clang supports the ``__attribute__((long_call))``, ``__attribute__((far))``, -and ``__attribute__((near))`` attributes on MIPS targets. These attributes may -only be added to function declarations and change the code generated -by the compiler when directly calling the function. The ``near`` attribute -allows calls to the function to be made using the ``jal`` instruction, which -requires the function to be located in the same naturally aligned 256MB -segment as the caller. The ``long_call`` and ``far`` attributes are synonyms -and require the use of a different call sequence that works regardless -of the distance between the functions. - -These attributes have no effect for position-independent code. - -These attributes take priority over command line switches such -as ``-mlong-calls`` and ``-mno-long-calls``. - - -micromips ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``micromips``","``gnu::micromips``","","","","","Yes" - -Clang supports the GNU style ``__attribute__((micromips))`` and -``__attribute__((nomicromips))`` attributes on MIPS targets. These attributes -may be attached to a function definition and instructs the backend to generate -or not to generate microMIPS code for that function. - -These attributes override the `-mmicromips` and `-mno-micromips` options -on the command line. - - -mig_server_routine ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``mig_server_routine``","``clang::mig_server_routine``","``clang::mig_server_routine``","","","","Yes" - -The Mach Interface Generator release-on-success convention dictates -functions that follow it to only release arguments passed to them when they -return "success" (a ``kern_return_t`` error code that indicates that -no errors have occured). Otherwise the release is performed by the MIG client -that called the function. The annotation ``__attribute__((mig_server_routine))`` -is applied in order to specify which functions are expected to follow the -convention. This allows the Static Analyzer to find bugs caused by violations of -that convention. The attribute would normally appear on the forward declaration -of the actual server routine in the MIG server header, but it may also be -added to arbitrary functions that need to follow the same convention - for -example, a user can add them to auxiliary functions called by the server routine -that have their return value of type ``kern_return_t`` unconditionally returned -from the routine. The attribute can be applied to C++ methods, and in this case -it will be automatically applied to overrides if the method is virtual. The -attribute can also be written using C++11 syntax: ``[[mig::server_routine]]``. - - -min_vector_width ----------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``min_vector_width``","``clang::min_vector_width``","``clang::min_vector_width``","","","","Yes" - -Clang supports the ``__attribute__((min_vector_width(width)))`` attribute. This -attribute may be attached to a function and informs the backend that this -function desires vectors of at least this width to be generated. Target-specific -maximum vector widths still apply. This means even if you ask for something -larger than the target supports, you will only get what the target supports. -This attribute is meant to be a hint to control target heuristics that may -generate narrower vectors than what the target hardware supports. - -This is currently used by the X86 target to allow some CPUs that support 512-bit -vectors to be limited to using 256-bit vectors to avoid frequency penalties. -This is currently enabled with the ``-prefer-vector-width=256`` command line -option. The ``min_vector_width`` attribute can be used to prevent the backend -from trying to split vector operations to match the ``prefer-vector-width``. All -X86 vector intrinsics from x86intrin.h already set this attribute. Additionally, -use of any of the X86-specific vector builtins will implicitly set this -attribute on the calling function. The intent is that explicitly writing vector -code using the X86 intrinsics will prevent ``prefer-vector-width`` from -affecting the code. - - -no_builtin ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_builtin``","``clang::no_builtin``","``clang::no_builtin``","","","","Yes" - -.. Note:: This attribute is not yet fully implemented, it is validated but has -no effect on the generated code. - -The ``__attribute__((no_builtin))`` is similar to the ``-fno-builtin`` flag -except it is specific to the body of a function. The attribute may also be -applied to a virtual function but has no effect on the behavior of overriding -functions in a derived class. - -It accepts one or more strings corresponding to the specific names of the -builtins to disable (e.g. "memcpy", "memset"). -If the attribute is used without parameters it will disable all buitins at -once. - -.. code-block:: c++ - - // The compiler is not allowed to add any builtin to foo's body. - void foo(char* data, size_t count) __attribute__((no_builtin)) { - // The compiler is not allowed to convert the loop into - // `__builtin_memset(data, 0xFE, count);`. - for (size_t i = 0; i < count; ++i) - data[i] = 0xFE; - } - - // The compiler is not allowed to add the `memcpy` builtin to bar's body. - void bar(char* data, size_t count) __attribute__((no_builtin("memcpy"))) { - // The compiler is allowed to convert the loop into - // `__builtin_memset(data, 0xFE, count);` but cannot generate any - // `__builtin_memcpy` - for (size_t i = 0; i < count; ++i) - data[i] = 0xFE; - } - - -no_caller_saved_registers -------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_caller_saved_registers``","``gnu::no_caller_saved_registers``","","","","","" - -Use this attribute to indicate that the specified function has no -caller-saved registers. That is, all registers are callee-saved except for -registers used for passing parameters to the function or returning parameters -from the function. -The compiler saves and restores any modified registers that were not used for -passing or returning arguments to the function. - -The user can call functions specified with the 'no_caller_saved_registers' -attribute from an interrupt handler without saving and restoring all -call-clobbered registers. - -Note that 'no_caller_saved_registers' attribute is not a calling convention. -In fact, it only overrides the decision of which registers should be saved by -the caller, but not how the parameters are passed from the caller to the callee. - -For example: - - .. code-block:: c - - __attribute__ ((no_caller_saved_registers, fastcall)) - void f (int arg1, int arg2) { - ... - } - - In this case parameters 'arg1' and 'arg2' will be passed in registers. - In this case, on 32-bit x86 targets, the function 'f' will use ECX and EDX as - register parameters. However, it will not assume any scratch registers and - should save and restore any modified registers except for ECX and EDX. - - -no_sanitize ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_sanitize``","``clang::no_sanitize``","``clang::no_sanitize``","","","","Yes" - -Use the ``no_sanitize`` attribute on a function or a global variable -declaration to specify that a particular instrumentation or set of -instrumentations should not be applied. The attribute takes a list of -string literals, which have the same meaning as values accepted by the -``-fno-sanitize=`` flag. For example, -``__attribute__((no_sanitize("address", "thread")))`` specifies that -AddressSanitizer and ThreadSanitizer should not be applied to the -function or variable. - -See :ref:`Controlling Code Generation ` for a -full list of supported sanitizer flags. - - -no_sanitize_address, no_address_safety_analysis ------------------------------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_address_safety_analysis`` |br| ``no_sanitize_address`` |br| ``no_sanitize_thread`` |br| ``no_sanitize_memory``","``gnu::no_address_safety_analysis`` |br| ``gnu::no_sanitize_address`` |br| ``gnu::no_sanitize_thread`` |br| ``clang::no_sanitize_memory``","``clang::no_sanitize_memory``","","","","Yes" - -.. _langext-address_sanitizer: - -Use ``__attribute__((no_sanitize_address))`` on a function or a global -variable declaration to specify that address safety instrumentation -(e.g. AddressSanitizer) should not be applied. - - -no_sanitize_memory ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_address_safety_analysis`` |br| ``no_sanitize_address`` |br| ``no_sanitize_thread`` |br| ``no_sanitize_memory``","``gnu::no_address_safety_analysis`` |br| ``gnu::no_sanitize_address`` |br| ``gnu::no_sanitize_thread`` |br| ``clang::no_sanitize_memory``","``clang::no_sanitize_memory``","","","","Yes" - -.. _langext-memory_sanitizer: - -Use ``__attribute__((no_sanitize_memory))`` on a function declaration to -specify that checks for uninitialized memory should not be inserted -(e.g. by MemorySanitizer). The function may still be instrumented by the tool -to avoid false positives in other places. - - -no_sanitize_thread ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_address_safety_analysis`` |br| ``no_sanitize_address`` |br| ``no_sanitize_thread`` |br| ``no_sanitize_memory``","``gnu::no_address_safety_analysis`` |br| ``gnu::no_sanitize_address`` |br| ``gnu::no_sanitize_thread`` |br| ``clang::no_sanitize_memory``","``clang::no_sanitize_memory``","","","","Yes" - -.. _langext-thread_sanitizer: - -Use ``__attribute__((no_sanitize_thread))`` on a function declaration to -specify that checks for data races on plain (non-atomic) memory accesses should -not be inserted by ThreadSanitizer. The function is still instrumented by the -tool to avoid false positives and provide meaningful stack traces. - - -no_speculative_load_hardening ------------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_speculative_load_hardening``","``clang::no_speculative_load_hardening``","``clang::no_speculative_load_hardening``","","","","Yes" - -This attribute can be applied to a function declaration in order to indicate - that `Speculative Load Hardening `_ - is *not* needed for the function body. This can also be applied to a method - in Objective C. This attribute will take precedence over the command line flag in - the case where `-mspeculative-load-hardening `_ is specified. - - Warning: This attribute may not prevent Speculative Load Hardening from being - enabled for a function which inlines a function that has the - 'speculative_load_hardening' attribute. This is intended to provide a - maximally conservative model where the code that is marked with the - 'speculative_load_hardening' attribute will always (even when inlined) - be hardened. A user of this attribute may want to mark functions called by - a function they do not want to be hardened with the 'noinline' attribute. - - For example: - - .. code-block:: c - - __attribute__((speculative_load_hardening)) - int foo(int i) { - return i; - } - - // Note: bar() may still have speculative load hardening enabled if - // foo() is inlined into bar(). Mark foo() with __attribute__((noinline)) - // to avoid this situation. - __attribute__((no_speculative_load_hardening)) - int bar(int i) { - return foo(i); - } - - -no_split_stack --------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_split_stack``","``gnu::no_split_stack``","","","","","Yes" - -The ``no_split_stack`` attribute disables the emission of the split stack -preamble for a particular function. It has no effect if ``-fsplit-stack`` -is not specified. - - -no_stack_protector ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_stack_protector``","``clang::no_stack_protector``","``clang::no_stack_protector``","","","","Yes" - -Clang supports the ``__attribute__((no_stack_protector))`` attribute which disables -the stack protector on the specified function. This attribute is useful for -selectively disabling the stack protector on some functions when building with -``-fstack-protector`` compiler option. - -For example, it disables the stack protector for the function ``foo`` but function -``bar`` will still be built with the stack protector with the ``-fstack-protector`` -option. - -.. code-block:: c - - int __attribute__((no_stack_protector)) - foo (int x); // stack protection will be disabled for foo. - - int bar(int y); // bar can be built with the stack protector. - - -noalias -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","``noalias``","","","" - -The ``noalias`` attribute indicates that the only memory accesses inside -function are loads and stores from objects pointed to by its pointer-typed -arguments, with arbitrary offsets. - - -nocf_check ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``nocf_check``","``gnu::nocf_check``","","","","","Yes" - -Jump Oriented Programming attacks rely on tampering with addresses used by -indirect call / jmp, e.g. redirect control-flow to non-programmer -intended bytes in the binary. -X86 Supports Indirect Branch Tracking (IBT) as part of Control-Flow -Enforcement Technology (CET). IBT instruments ENDBR instructions used to -specify valid targets of indirect call / jmp. -The ``nocf_check`` attribute has two roles: -1. Appertains to a function - do not add ENDBR instruction at the beginning of -the function. -2. Appertains to a function pointer - do not track the target function of this -pointer (by adding nocf_check prefix to the indirect-call instruction). - - -nodiscard, warn_unused_result ------------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``warn_unused_result``","``nodiscard`` |br| ``clang::warn_unused_result`` |br| ``gnu::warn_unused_result``","``nodiscard``","","","","Yes" - -Clang supports the ability to diagnose when the results of a function call -expression are discarded under suspicious circumstances. A diagnostic is -generated when a function or its return type is marked with ``[[nodiscard]]`` -(or ``__attribute__((warn_unused_result))``) and the function call appears as a -potentially-evaluated discarded-value expression that is not explicitly cast to -`void`. - -A string literal may optionally be provided to the attribute, which will be -reproduced in any resulting diagnostics. Redeclarations using different forms -of the attribute (with or without the string literal or with different string -literal contents) are allowed. If there are redeclarations of the entity with -differing string literals, it is unspecified which one will be used by Clang -in any resulting diagnostics. - -.. code-block: c++ - struct [[nodiscard]] error_info { /*...*/ }; - error_info enable_missile_safety_mode(); - - void launch_missiles(); - void test_missiles() { - enable_missile_safety_mode(); // diagnoses - launch_missiles(); - } - error_info &foo(); - void f() { foo(); } // Does not diagnose, error_info is a reference. - -Additionally, discarded temporaries resulting from a call to a constructor -marked with ``[[nodiscard]]`` or a constructor of a type marked -``[[nodiscard]]`` will also diagnose. This also applies to type conversions that -use the annotated ``[[nodiscard]]`` constructor or result in an annotated type. - -.. code-block: c++ - struct [[nodiscard]] marked_type {/*..*/ }; - struct marked_ctor { - [[nodiscard]] marked_ctor(); - marked_ctor(int); - }; - - struct S { - operator marked_type() const; - [[nodiscard]] operator int() const; - }; - - void usages() { - marked_type(); // diagnoses. - marked_ctor(); // diagnoses. - marked_ctor(3); // Does not diagnose, int constructor isn't marked nodiscard. - - S s; - static_cast(s); // diagnoses - (int)s; // diagnoses - } - - -noduplicate ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``noduplicate``","``clang::noduplicate``","``clang::noduplicate``","","","","Yes" - -The ``noduplicate`` attribute can be placed on function declarations to control -whether function calls to this function can be duplicated or not as a result of -optimizations. This is required for the implementation of functions with -certain special requirements, like the OpenCL "barrier" function, that might -need to be run concurrently by all the threads that are executing in lockstep -on the hardware. For example this attribute applied on the function -"nodupfunc" in the code below avoids that: - -.. code-block:: c - - void nodupfunc() __attribute__((noduplicate)); - // Setting it as a C++11 attribute is also valid - // void nodupfunc() [[clang::noduplicate]]; - void foo(); - void bar(); - - nodupfunc(); - if (a > n) { - foo(); - } else { - bar(); - } - -gets possibly modified by some optimizations into code similar to this: - -.. code-block:: c - - if (a > n) { - nodupfunc(); - foo(); - } else { - nodupfunc(); - bar(); - } - -where the call to "nodupfunc" is duplicated and sunk into the two branches -of the condition. - - -nomicromips ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``nomicromips``","``gnu::nomicromips``","","","","","Yes" - -Clang supports the GNU style ``__attribute__((micromips))`` and -``__attribute__((nomicromips))`` attributes on MIPS targets. These attributes -may be attached to a function definition and instructs the backend to generate -or not to generate microMIPS code for that function. - -These attributes override the `-mmicromips` and `-mno-micromips` options -on the command line. - - -noreturn --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","``noreturn``","","","","","Yes" - -A function declared as ``[[noreturn]]`` shall not return to its caller. The -compiler will generate a diagnostic for a function declared as ``[[noreturn]]`` -that appears to be capable of returning to its caller. - - -not_tail_called ---------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``not_tail_called``","``clang::not_tail_called``","``clang::not_tail_called``","","","","Yes" - -The ``not_tail_called`` attribute prevents tail-call optimization on statically bound calls. It has no effect on indirect calls. Virtual functions, objective-c methods, and functions marked as ``always_inline`` cannot be marked as ``not_tail_called``. - -For example, it prevents tail-call optimization in the following case: - - .. code-block:: c - - int __attribute__((not_tail_called)) foo1(int); - - int foo2(int a) { - return foo1(a); // No tail-call optimization on direct calls. - } - -However, it doesn't prevent tail-call optimization in this case: - - .. code-block:: c - - int __attribute__((not_tail_called)) foo1(int); - - int foo2(int a) { - int (*fn)(int) = &foo1; - - // not_tail_called has no effect on an indirect call even if the call can be - // resolved at compile time. - return (*fn)(a); - } - -Marking virtual functions as ``not_tail_called`` is an error: - - .. code-block:: c++ - - class Base { - public: - // not_tail_called on a virtual function is an error. - [[clang::not_tail_called]] virtual int foo1(); - - virtual int foo2(); - - // Non-virtual functions can be marked ``not_tail_called``. - [[clang::not_tail_called]] int foo3(); - }; - - class Derived1 : public Base { - public: - int foo1() override; - - // not_tail_called on a virtual function is an error. - [[clang::not_tail_called]] int foo2() override; - }; - - -nothrow -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``nothrow``","``gnu::nothrow``","","``nothrow``","","","Yes" - -Clang supports the GNU style ``__attribute__((nothrow))`` and Microsoft style -``__declspec(nothrow)`` attribute as an equivalent of `noexcept` on function -declarations. This attribute informs the compiler that the annotated function -does not throw an exception. This prevents exception-unwinding. This attribute -is particularly useful on functions in the C Standard Library that are -guaranteed to not throw an exception. - - -ns_consumed ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``ns_consumed``","``clang::ns_consumed``","``clang::ns_consumed``","","","","Yes" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -ns_consumes_self ----------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``ns_consumes_self``","``clang::ns_consumes_self``","``clang::ns_consumes_self``","","","","Yes" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -ns_returns_autoreleased ------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``ns_returns_autoreleased``","``clang::ns_returns_autoreleased``","``clang::ns_returns_autoreleased``","","","","" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -ns_returns_not_retained ------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``ns_returns_not_retained``","``clang::ns_returns_not_retained``","``clang::ns_returns_not_retained``","","","","" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -ns_returns_retained -------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``ns_returns_retained``","``clang::ns_returns_retained``","``clang::ns_returns_retained``","","","","" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -objc_method_family ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_method_family``","``clang::objc_method_family``","``clang::objc_method_family``","","","","Yes" - -Many methods in Objective-C have conventional meanings determined by their -selectors. It is sometimes useful to be able to mark a method as having a -particular conventional meaning despite not having the right selector, or as -not having the conventional meaning that its selector would suggest. For these -use cases, we provide an attribute to specifically describe the "method family" -that a method belongs to. - -**Usage**: ``__attribute__((objc_method_family(X)))``, where ``X`` is one of -``none``, ``alloc``, ``copy``, ``init``, ``mutableCopy``, or ``new``. This -attribute can only be placed at the end of a method declaration: - -.. code-block:: objc - - - (NSString *)initMyStringValue __attribute__((objc_method_family(none))); - -Users who do not wish to change the conventional meaning of a method, and who -merely want to document its non-standard retain and release semantics, should -use the retaining behavior attributes (``ns_returns_retained``, -``ns_returns_not_retained``, etc). - -Query for this feature with ``__has_attribute(objc_method_family)``. - - -objc_requires_super -------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_requires_super``","``clang::objc_requires_super``","``clang::objc_requires_super``","","","","Yes" - -Some Objective-C classes allow a subclass to override a particular method in a -parent class but expect that the overriding method also calls the overridden -method in the parent class. For these cases, we provide an attribute to -designate that a method requires a "call to ``super``" in the overriding -method in the subclass. - -**Usage**: ``__attribute__((objc_requires_super))``. This attribute can only -be placed at the end of a method declaration: - -.. code-block:: objc - - - (void)foo __attribute__((objc_requires_super)); - -This attribute can only be applied the method declarations within a class, and -not a protocol. Currently this attribute does not enforce any placement of -where the call occurs in the overriding method (such as in the case of -``-dealloc`` where the call must appear at the end). It checks only that it -exists. - -Note that on both OS X and iOS that the Foundation framework provides a -convenience macro ``NS_REQUIRES_SUPER`` that provides syntactic sugar for this -attribute: - -.. code-block:: objc - - - (void)foo NS_REQUIRES_SUPER; - -This macro is conditionally defined depending on the compiler's support for -this attribute. If the compiler does not support the attribute the macro -expands to nothing. - -Operationally, when a method has this annotation the compiler will warn if the -implementation of an override in a subclass does not call super. For example: - -.. code-block:: objc - - warning: method possibly missing a [super AnnotMeth] call - - (void) AnnotMeth{}; - ^ - - -optnone -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``optnone``","``clang::optnone``","``clang::optnone``","","","","Yes" - -The ``optnone`` attribute suppresses essentially all optimizations -on a function or method, regardless of the optimization level applied to -the compilation unit as a whole. This is particularly useful when you -need to debug a particular function, but it is infeasible to build the -entire application without optimization. Avoiding optimization on the -specified function can improve the quality of the debugging information -for that function. - -This attribute is incompatible with the ``always_inline`` and ``minsize`` -attributes. - - -os_consumed ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``os_consumed``","``clang::os_consumed``","``clang::os_consumed``","","","","Yes" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -os_consumes_this ----------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``os_consumes_this``","``clang::os_consumes_this``","``clang::os_consumes_this``","","","","" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -os_returns_not_retained ------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``os_returns_not_retained``","``clang::os_returns_not_retained``","``clang::os_returns_not_retained``","","","","Yes" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -os_returns_retained -------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``os_returns_retained``","``clang::os_returns_retained``","``clang::os_returns_retained``","","","","Yes" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -os_returns_retained_on_non_zero -------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``os_returns_retained_on_non_zero``","``clang::os_returns_retained_on_non_zero``","``clang::os_returns_retained_on_non_zero``","","","","Yes" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -os_returns_retained_on_zero ---------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``os_returns_retained_on_zero``","``clang::os_returns_retained_on_zero``","``clang::os_returns_retained_on_zero``","","","","Yes" - -The behavior of a function with respect to reference counting for Foundation -(Objective-C), CoreFoundation (C) and OSObject (C++) is determined by a naming -convention (e.g. functions starting with "get" are assumed to return at -``+0``). - -It can be overriden using a family of the following attributes. In -Objective-C, the annotation ``__attribute__((ns_returns_retained))`` applied to -a function communicates that the object is returned at ``+1``, and the caller -is responsible for freeing it. -Similiarly, the annotation ``__attribute__((ns_returns_not_retained))`` -specifies that the object is returned at ``+0`` and the ownership remains with -the callee. -The annotation ``__attribute__((ns_consumes_self))`` specifies that -the Objective-C method call consumes the reference to ``self``, e.g. by -attaching it to a supplied parameter. -Additionally, parameters can have an annotation -``__attribute__((ns_consumed))``, which specifies that passing an owned object -as that parameter effectively transfers the ownership, and the caller is no -longer responsible for it. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -In C programs using CoreFoundation, a similar set of attributes: -``__attribute__((cf_returns_not_retained))``, -``__attribute__((cf_returns_retained))`` and ``__attribute__((cf_consumed))`` -have the same respective semantics when applied to CoreFoundation objects. -These attributes affect code generation when interacting with ARC code, and -they are used by the Clang Static Analyzer. - -Finally, in C++ interacting with XNU kernel (objects inheriting from OSObject), -the same attribute family is present: -``__attribute__((os_returns_not_retained))``, -``__attribute__((os_returns_retained))`` and ``__attribute__((os_consumed))``, -with the same respective semantics. -Similar to ``__attribute__((ns_consumes_self))``, -``__attribute__((os_consumes_this))`` specifies that the method call consumes -the reference to "this" (e.g., when attaching it to a different object supplied -as a parameter). -Out parameters (parameters the function is meant to write into, -either via pointers-to-pointers or references-to-pointers) -may be annotated with ``__attribute__((os_returns_retained))`` -or ``__attribute__((os_returns_not_retained))`` which specifies that the object -written into the out parameter should (or respectively should not) be released -after use. -Since often out parameters may or may not be written depending on the exit -code of the function, -annotations ``__attribute__((os_returns_retained_on_zero))`` -and ``__attribute__((os_returns_retained_on_non_zero))`` specify that -an out parameter at ``+1`` is written if and only if the function returns a zero -(respectively non-zero) error code. -Observe that return-code-dependent out parameter annotations are only -available for retained out parameters, as non-retained object do not have to be -released by the callee. -These attributes are only used by the Clang Static Analyzer. - -The family of attributes ``X_returns_X_retained`` can be added to functions, -C++ methods, and Objective-C methods and properties. -Attributes ``X_consumed`` can be added to parameters of methods, functions, -and Objective-C methods. - - -overloadable ------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``overloadable``","``clang::overloadable``","``clang::overloadable``","","","","Yes" - -Clang provides support for C++ function overloading in C. Function overloading -in C is introduced using the ``overloadable`` attribute. For example, one -might provide several overloaded versions of a ``tgsin`` function that invokes -the appropriate standard function computing the sine of a value with ``float``, -``double``, or ``long double`` precision: - -.. code-block:: c - - #include - float __attribute__((overloadable)) tgsin(float x) { return sinf(x); } - double __attribute__((overloadable)) tgsin(double x) { return sin(x); } - long double __attribute__((overloadable)) tgsin(long double x) { return sinl(x); } - -Given these declarations, one can call ``tgsin`` with a ``float`` value to -receive a ``float`` result, with a ``double`` to receive a ``double`` result, -etc. Function overloading in C follows the rules of C++ function overloading -to pick the best overload given the call arguments, with a few C-specific -semantics: - -* Conversion from ``float`` or ``double`` to ``long double`` is ranked as a - floating-point promotion (per C99) rather than as a floating-point conversion - (as in C++). - -* A conversion from a pointer of type ``T*`` to a pointer of type ``U*`` is - considered a pointer conversion (with conversion rank) if ``T`` and ``U`` are - compatible types. - -* A conversion from type ``T`` to a value of type ``U`` is permitted if ``T`` - and ``U`` are compatible types. This conversion is given "conversion" rank. - -* If no viable candidates are otherwise available, we allow a conversion from a - pointer of type ``T*`` to a pointer of type ``U*``, where ``T`` and ``U`` are - incompatible. This conversion is ranked below all other types of conversions. - Please note: ``U`` lacking qualifiers that are present on ``T`` is sufficient - for ``T`` and ``U`` to be incompatible. - -The declaration of ``overloadable`` functions is restricted to function -declarations and definitions. If a function is marked with the ``overloadable`` -attribute, then all declarations and definitions of functions with that name, -except for at most one (see the note below about unmarked overloads), must have -the ``overloadable`` attribute. In addition, redeclarations of a function with -the ``overloadable`` attribute must have the ``overloadable`` attribute, and -redeclarations of a function without the ``overloadable`` attribute must *not* -have the ``overloadable`` attribute. e.g., - -.. code-block:: c - - int f(int) __attribute__((overloadable)); - float f(float); // error: declaration of "f" must have the "overloadable" attribute - int f(int); // error: redeclaration of "f" must have the "overloadable" attribute - - int g(int) __attribute__((overloadable)); - int g(int) { } // error: redeclaration of "g" must also have the "overloadable" attribute - - int h(int); - int h(int) __attribute__((overloadable)); // error: declaration of "h" must not - // have the "overloadable" attribute - -Functions marked ``overloadable`` must have prototypes. Therefore, the -following code is ill-formed: - -.. code-block:: c - - int h() __attribute__((overloadable)); // error: h does not have a prototype - -However, ``overloadable`` functions are allowed to use a ellipsis even if there -are no named parameters (as is permitted in C++). This feature is particularly -useful when combined with the ``unavailable`` attribute: - -.. code-block:: c++ - - void honeypot(...) __attribute__((overloadable, unavailable)); // calling me is an error - -Functions declared with the ``overloadable`` attribute have their names mangled -according to the same rules as C++ function names. For example, the three -``tgsin`` functions in our motivating example get the mangled names -``_Z5tgsinf``, ``_Z5tgsind``, and ``_Z5tgsine``, respectively. There are two -caveats to this use of name mangling: - -* Future versions of Clang may change the name mangling of functions overloaded - in C, so you should not depend on an specific mangling. To be completely - safe, we strongly urge the use of ``static inline`` with ``overloadable`` - functions. - -* The ``overloadable`` attribute has almost no meaning when used in C++, - because names will already be mangled and functions are already overloadable. - However, when an ``overloadable`` function occurs within an ``extern "C"`` - linkage specification, it's name *will* be mangled in the same way as it - would in C. - -For the purpose of backwards compatibility, at most one function with the same -name as other ``overloadable`` functions may omit the ``overloadable`` -attribute. In this case, the function without the ``overloadable`` attribute -will not have its name mangled. - -For example: - -.. code-block:: c - - // Notes with mangled names assume Itanium mangling. - int f(int); - int f(double) __attribute__((overloadable)); - void foo() { - f(5); // Emits a call to f (not _Z1fi, as it would with an overload that - // was marked with overloadable). - f(1.0); // Emits a call to _Z1fd. - } - -Support for unmarked overloads is not present in some versions of clang. You may -query for it using ``__has_extension(overloadable_unmarked)``. - -Query for this attribute with ``__has_attribute(overloadable)``. - - -patchable_function_entry ------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``patchable_function_entry``","``gnu::patchable_function_entry``","","","","","Yes" - -``__attribute__((patchable_function_entry(N,M)))`` is used to generate M NOPs -before the function entry and N-M NOPs after the function entry. This attribute -takes precedence over the command line option ``-fpatchable-function-entry=N,M``. -``M`` defaults to 0 if omitted. - - -preserve_access_index ---------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``preserve_access_index``","``clang::preserve_access_index``","``clang::preserve_access_index``","","","","Yes" - -Clang supports the ``__attribute__((preserve_access_index))`` -attribute for the BPF target. This attribute may be attached to a -struct or union declaration, where if -g is specified, it enables -preserving struct or union member access debuginfo indicies of this -struct or union, similar to clang ``__builtin_preserve_acceess_index()``. - - -reinitializes -------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``reinitializes``","``clang::reinitializes``","","","","","" - -The ``reinitializes`` attribute can be applied to a non-static, non-const C++ -member function to indicate that this member function reinitializes the entire -object to a known state, independent of the previous state of the object. - -This attribute can be interpreted by static analyzers that warn about uses of an -object that has been left in an indeterminate state by a move operation. If a -member function marked with the ``reinitializes`` attribute is called on a -moved-from object, the analyzer can conclude that the object is no longer in an -indeterminate state. - -A typical example where this attribute would be used is on functions that clear -a container class: - -.. code-block:: c++ - - template - class Container { - public: - ... - [[clang::reinitializes]] void Clear(); - ... - }; - - -release_capability, release_shared_capability ---------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``release_capability`` |br| ``release_shared_capability`` |br| ``release_generic_capability`` |br| ``unlock_function``","``clang::release_capability`` |br| ``clang::release_shared_capability`` |br| ``clang::release_generic_capability`` |br| ``clang::unlock_function``","","","","","" - -Marks a function as releasing a capability. - - -short_call, near ----------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``short_call`` |br| ``near``","``gnu::short_call`` |br| ``gnu::near``","","","","","Yes" - -Clang supports the ``__attribute__((long_call))``, ``__attribute__((far))``, -``__attribute__((short__call))``, and ``__attribute__((near))`` attributes -on MIPS targets. These attributes may only be added to function declarations -and change the code generated by the compiler when directly calling -the function. The ``short_call`` and ``near`` attributes are synonyms and -allow calls to the function to be made using the ``jal`` instruction, which -requires the function to be located in the same naturally aligned 256MB segment -as the caller. The ``long_call`` and ``far`` attributes are synonyms and -require the use of a different call sequence that works regardless -of the distance between the functions. - -These attributes have no effect for position-independent code. - -These attributes take priority over command line switches such -as ``-mlong-calls`` and ``-mno-long-calls``. - - -signal ------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``signal``","``gnu::signal``","","","","","Yes" - -Clang supports the GNU style ``__attribute__((signal))`` attribute on -AVR targets. This attribute may be attached to a function definition and instructs -the backend to generate appropriate function entry/exit code so that it can be used -directly as an interrupt service routine. - -Interrupt handler functions defined with the signal attribute do not re-enable interrupts. - - -speculative_load_hardening --------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``speculative_load_hardening``","``clang::speculative_load_hardening``","``clang::speculative_load_hardening``","","","","Yes" - -This attribute can be applied to a function declaration in order to indicate - that `Speculative Load Hardening `_ - should be enabled for the function body. This can also be applied to a method - in Objective C. This attribute will take precedence over the command line flag in - the case where `-mno-speculative-load-hardening `_ is specified. - - Speculative Load Hardening is a best-effort mitigation against - information leak attacks that make use of control flow - miss-speculation - specifically miss-speculation of whether a branch - is taken or not. Typically vulnerabilities enabling such attacks are - classified as "Spectre variant #1". Notably, this does not attempt to - mitigate against miss-speculation of branch target, classified as - "Spectre variant #2" vulnerabilities. - - When inlining, the attribute is sticky. Inlining a function that - carries this attribute will cause the caller to gain the - attribute. This is intended to provide a maximally conservative model - where the code in a function annotated with this attribute will always - (even after inlining) end up hardened. - - -sycl_kernel ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``sycl_kernel``","``clang::sycl_kernel``","``clang::sycl_kernel``","","","","" - -The ``sycl_kernel`` attribute specifies that a function template will be used -to outline device code and to generate an OpenCL kernel. -Here is a code example of the SYCL program, which demonstrates the compiler's -outlining job: -.. code-block:: c++ - - int foo(int x) { return ++x; } - - using namespace cl::sycl; - queue Q; - buffer a(range<1>{1024}); - Q.submit([&](handler& cgh) { - auto A = a.get_access(cgh); - cgh.parallel_for(range<1>{1024}, [=](id<1> index) { - A[index] = index[0] + foo(42); - }); - } - -A C++ function object passed to the ``parallel_for`` is called a "SYCL kernel". -A SYCL kernel defines the entry point to the "device part" of the code. The -compiler will emit all symbols accessible from a "kernel". In this code -example, the compiler will emit "foo" function. More details about the -compilation of functions for the device part can be found in the SYCL 1.2.1 -specification Section 6.4. -To show to the compiler entry point to the "device part" of the code, the SYCL -runtime can use the ``sycl_kernel`` attribute in the following way: -.. code-block:: c++ -namespace cl { -namespace sycl { -class handler { - template - __attribute__((sycl_kernel)) void sycl_kernel_function(KernelType KernelFuncObj) { - // ... - KernelFuncObj(); - } - - template - void parallel_for(range NumWorkItems, KernelType KernelFunc) { -#ifdef __SYCL_DEVICE_ONLY__ - sycl_kernel_function(KernelFunc); -#else - // Host implementation -#endif - } -}; -} // namespace sycl -} // namespace cl - -The compiler will also generate an OpenCL kernel using the function marked with -the ``sycl_kernel`` attribute. -Here is the list of SYCL device compiler expectations with regard to the -function marked with the ``sycl_kernel`` attribute: - -- The function must be a template with at least two type template parameters. - The compiler generates an OpenCL kernel and uses the first template parameter - as a unique name for the generated OpenCL kernel. The host application uses - this unique name to invoke the OpenCL kernel generated for the SYCL kernel - specialized by this name and second template parameter ``KernelType`` (which - might be an unnamed function object type). -- The function must have at least one parameter. The first parameter is - required to be a function object type (named or unnamed i.e. lambda). The - compiler uses function object type fields to generate OpenCL kernel - parameters. -- The function must return void. The compiler reuses the body of marked functions to - generate the OpenCL kernel body, and the OpenCL kernel must return `void`. - -The SYCL kernel in the previous code sample meets these expectations. - - -target ------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``target``","``gnu::target``","","","","","Yes" - -Clang supports the GNU style ``__attribute__((target("OPTIONS")))`` attribute. -This attribute may be attached to a function definition and instructs -the backend to use different code generation options than were passed on the -command line. - -The current set of options correspond to the existing "subtarget features" for -the target with or without a "-mno-" in front corresponding to the absence -of the feature, as well as ``arch="CPU"`` which will change the default "CPU" -for the function. - -For AArch64, the attribute also allows the "branch-protection=" option, -where the permissible arguments and their effect on code generation are the same -as for the command-line option ``-mbranch-protection``. - -Example "subtarget features" from the x86 backend include: "mmx", "sse", "sse4.2", -"avx", "xop" and largely correspond to the machine specific options handled by -the front end. - -Additionally, this attribute supports function multiversioning for ELF based -x86/x86-64 targets, which can be used to create multiple implementations of the -same function that will be resolved at runtime based on the priority of their -``target`` attribute strings. A function is considered a multiversioned function -if either two declarations of the function have different ``target`` attribute -strings, or if it has a ``target`` attribute string of ``default``. For -example: - - .. code-block:: c++ - - __attribute__((target("arch=atom"))) - void foo() {} // will be called on 'atom' processors. - __attribute__((target("default"))) - void foo() {} // will be called on any other processors. - -All multiversioned functions must contain a ``default`` (fallback) -implementation, otherwise usages of the function are considered invalid. -Additionally, a function may not become multiversioned after its first use. - - -try_acquire_capability, try_acquire_shared_capability ------------------------------------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``try_acquire_capability`` |br| ``try_acquire_shared_capability``","``clang::try_acquire_capability`` |br| ``clang::try_acquire_shared_capability``","","","","","" - -Marks a function that attempts to acquire a capability. This function may fail to -actually acquire the capability; they accept a Boolean value determining -whether acquiring the capability means success (true), or failing to acquire -the capability means success (false). - - -xray_always_instrument, xray_never_instrument, xray_log_args ------------------------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``xray_always_instrument`` |br| ``xray_never_instrument``","``clang::xray_always_instrument`` |br| ``clang::xray_never_instrument``","``clang::xray_always_instrument`` |br| ``clang::xray_never_instrument``","","","","Yes" - -``__attribute__((xray_always_instrument))`` or ``[[clang::xray_always_instrument]]`` is used to mark member functions (in C++), methods (in Objective C), and free functions (in C, C++, and Objective C) to be instrumented with XRay. This will cause the function to always have space at the beginning and exit points to allow for runtime patching. - -Conversely, ``__attribute__((xray_never_instrument))`` or ``[[clang::xray_never_instrument]]`` will inhibit the insertion of these instrumentation points. - -If a function has neither of these attributes, they become subject to the XRay heuristics used to determine whether a function should be instrumented or otherwise. - -``__attribute__((xray_log_args(N)))`` or ``[[clang::xray_log_args(N)]]`` is used to preserve N function arguments for the logging function. Currently, only N==1 is supported. - - -xray_always_instrument, xray_never_instrument, xray_log_args ------------------------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``xray_log_args``","``clang::xray_log_args``","``clang::xray_log_args``","","","","Yes" - -``__attribute__((xray_always_instrument))`` or ``[[clang::xray_always_instrument]]`` is used to mark member functions (in C++), methods (in Objective C), and free functions (in C, C++, and Objective C) to be instrumented with XRay. This will cause the function to always have space at the beginning and exit points to allow for runtime patching. - -Conversely, ``__attribute__((xray_never_instrument))`` or ``[[clang::xray_never_instrument]]`` will inhibit the insertion of these instrumentation points. - -If a function has neither of these attributes, they become subject to the XRay heuristics used to determine whether a function should be instrumented or otherwise. - -``__attribute__((xray_log_args(N)))`` or ``[[clang::xray_log_args(N)]]`` is used to preserve N function arguments for the logging function. Currently, only N==1 is supported. - - -Variable Attributes -=================== - - -always_destroy --------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``always_destroy``","``clang::always_destroy``","","","","","Yes" - -The ``always_destroy`` attribute specifies that a variable with static or thread -storage duration should have its exit-time destructor run. This attribute is the -default unless clang was invoked with -fno-c++-static-destructors. - - -dllexport ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``dllexport``","``gnu::dllexport``","","``dllexport``","","","Yes" - -The ``__declspec(dllexport)`` attribute declares a variable, function, or -Objective-C interface to be exported from the module. It is available under the -``-fdeclspec`` flag for compatibility with various compilers. The primary use -is for COFF object files which explicitly specify what interfaces are available -for external use. See the dllexport_ documentation on MSDN for more -information. - -.. _dllexport: https://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx - - -dllimport ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``dllimport``","``gnu::dllimport``","","``dllimport``","","","Yes" - -The ``__declspec(dllimport)`` attribute declares a variable, function, or -Objective-C interface to be imported from an external module. It is available -under the ``-fdeclspec`` flag for compatibility with various compilers. The -primary use is for COFF object files which explicitly specify what interfaces -are imported from external modules. See the dllimport_ documentation on MSDN -for more information. - -.. _dllimport: https://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx - - -init_seg --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","","``init_seg``","" - -The attribute applied by ``pragma init_seg()`` controls the section into -which global initialization function pointers are emitted. It is only -available with ``-fms-extensions``. Typically, this function pointer is -emitted into ``.CRT$XCU`` on Windows. The user can change the order of -initialization by using a different section name with the same -``.CRT$XC`` prefix and a suffix that sorts lexicographically before or -after the standard ``.CRT$XCU`` sections. See the init_seg_ -documentation on MSDN for more information. - -.. _init_seg: http://msdn.microsoft.com/en-us/library/7977wcck(v=vs.110).aspx - - -maybe_unused, unused --------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``unused``","``maybe_unused`` |br| ``gnu::unused``","``maybe_unused``","","","","" - -When passing the ``-Wunused`` flag to Clang, entities that are unused by the -program may be diagnosed. The ``[[maybe_unused]]`` (or -``__attribute__((unused))``) attribute can be used to silence such diagnostics -when the entity cannot be removed. For instance, a local variable may exist -solely for use in an ``assert()`` statement, which makes the local variable -unused when ``NDEBUG`` is defined. - -The attribute may be applied to the declaration of a class, a typedef, a -variable, a function or method, a function parameter, an enumeration, an -enumerator, a non-static data member, or a label. - -.. code-block: c++ - #include - - [[maybe_unused]] void f([[maybe_unused]] bool thing1, - [[maybe_unused]] bool thing2) { - [[maybe_unused]] bool b = thing1 && thing2; - assert(b); - } - - -no_destroy ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``no_destroy``","``clang::no_destroy``","","","","","Yes" - -The ``no_destroy`` attribute specifies that a variable with static or thread -storage duration shouldn't have its exit-time destructor run. Annotating every -static and thread duration variable with this attribute is equivalent to -invoking clang with -fno-c++-static-destructors. - -If a variable is declared with this attribute, clang doesn't access check or -generate the type's destructor. If you have a type that you only want to be -annotated with ``no_destroy``, you can therefore declare the destructor private: - -.. code-block:: c++ - - struct only_no_destroy { - only_no_destroy(); - private: - ~only_no_destroy(); - }; - - [[clang::no_destroy]] only_no_destroy global; // fine! - -Note that destructors are still required for subobjects of aggregates annotated -with this attribute. This is because previously constructed subobjects need to -be destroyed if an exception gets thrown before the initialization of the -complete object is complete. For instance: - -.. code-block::c++ - - void f() { - try { - [[clang::no_destroy]] - static only_no_destroy array[10]; // error, only_no_destroy has a private destructor. - } catch (...) { - // Handle the error - } - } - -Here, if the construction of `array[9]` fails with an exception, `array[0..8]` -will be destroyed, so the element's destructor needs to be accessible. - - -nodebug -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``nodebug``","``gnu::nodebug``","","","","","Yes" - -The ``nodebug`` attribute allows you to suppress debugging information for a -function or method, or for a variable that is not a parameter or a non-static -data member. - - -noescape --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``noescape``","``clang::noescape``","``clang::noescape``","","","","Yes" - -``noescape`` placed on a function parameter of a pointer type is used to inform -the compiler that the pointer cannot escape: that is, no reference to the object -the pointer points to that is derived from the parameter value will survive -after the function returns. Users are responsible for making sure parameters -annotated with ``noescape`` do not actuallly escape. - -For example: - -.. code-block:: c - - int *gp; - - void nonescapingFunc(__attribute__((noescape)) int *p) { - *p += 100; // OK. - } - - void escapingFunc(__attribute__((noescape)) int *p) { - gp = p; // Not OK. - } - -Additionally, when the parameter is a `block pointer -`, the same restriction -applies to copies of the block. For example: - -.. code-block:: c - - typedef void (^BlockTy)(); - BlockTy g0, g1; - - void nonescapingFunc(__attribute__((noescape)) BlockTy block) { - block(); // OK. - } - - void escapingFunc(__attribute__((noescape)) BlockTy block) { - g0 = block; // Not OK. - g1 = Block_copy(block); // Not OK either. - } - - -nosvm ------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``nosvm``","","","","","","Yes" - -OpenCL 2.0 supports the optional ``__attribute__((nosvm))`` qualifier for -pointer variable. It informs the compiler that the pointer does not refer -to a shared virtual memory region. See OpenCL v2.0 s6.7.2 for details. - -Since it is not widely used and has been removed from OpenCL 2.1, it is ignored -by Clang. - - -objc_externally_retained ------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_externally_retained``","``clang::objc_externally_retained``","``clang::objc_externally_retained``","","","","Yes" - -The ``objc_externally_retained`` attribute can be applied to strong local -variables, functions, methods, or blocks to opt into -`externally-retained semantics -`_. - -When applied to the definition of a function, method, or block, every parameter -of the function with implicit strong retainable object pointer type is -considered externally-retained, and becomes ``const``. By explicitly annotating -a parameter with ``__strong``, you can opt back into the default -non-externally-retained behaviour for that parameter. For instance, -``first_param`` is externally-retained below, but not ``second_param``: - -.. code-block:: objc - - __attribute__((objc_externally_retained)) - void f(NSArray *first_param, __strong NSArray *second_param) { - // ... - } - -Likewise, when applied to a strong local variable, that variable becomes -``const`` and is considered externally-retained. - -When compiled without ``-fobjc-arc``, this attribute is ignored. - - -pass_object_size, pass_dynamic_object_size ------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``pass_object_size`` |br| ``pass_dynamic_object_size``","``clang::pass_object_size`` |br| ``clang::pass_dynamic_object_size``","``clang::pass_object_size`` |br| ``clang::pass_dynamic_object_size``","","","","Yes" - -.. Note:: The mangling of functions with parameters that are annotated with - ``pass_object_size`` is subject to change. You can get around this by - using ``__asm__("foo")`` to explicitly name your functions, thus preserving - your ABI; also, non-overloadable C functions with ``pass_object_size`` are - not mangled. - -The ``pass_object_size(Type)`` attribute can be placed on function parameters to -instruct clang to call ``__builtin_object_size(param, Type)`` at each callsite -of said function, and implicitly pass the result of this call in as an invisible -argument of type ``size_t`` directly after the parameter annotated with -``pass_object_size``. Clang will also replace any calls to -``__builtin_object_size(param, Type)`` in the function by said implicit -parameter. - -Example usage: - -.. code-block:: c - - int bzero1(char *const p __attribute__((pass_object_size(0)))) - __attribute__((noinline)) { - int i = 0; - for (/**/; i < (int)__builtin_object_size(p, 0); ++i) { - p[i] = 0; - } - return i; - } - - int main() { - char chars[100]; - int n = bzero1(&chars[0]); - assert(n == sizeof(chars)); - return 0; - } - -If successfully evaluating ``__builtin_object_size(param, Type)`` at the -callsite is not possible, then the "failed" value is passed in. So, using the -definition of ``bzero1`` from above, the following code would exit cleanly: - -.. code-block:: c - - int main2(int argc, char *argv[]) { - int n = bzero1(argv); - assert(n == -1); - return 0; - } - -``pass_object_size`` plays a part in overload resolution. If two overload -candidates are otherwise equally good, then the overload with one or more -parameters with ``pass_object_size`` is preferred. This implies that the choice -between two identical overloads both with ``pass_object_size`` on one or more -parameters will always be ambiguous; for this reason, having two such overloads -is illegal. For example: - -.. code-block:: c++ - - #define PS(N) __attribute__((pass_object_size(N))) - // OK - void Foo(char *a, char *b); // Overload A - // OK -- overload A has no parameters with pass_object_size. - void Foo(char *a PS(0), char *b PS(0)); // Overload B - // Error -- Same signature (sans pass_object_size) as overload B, and both - // overloads have one or more parameters with the pass_object_size attribute. - void Foo(void *a PS(0), void *b); - - // OK - void Bar(void *a PS(0)); // Overload C - // OK - void Bar(char *c PS(1)); // Overload D - - void main() { - char known[10], *unknown; - Foo(unknown, unknown); // Calls overload B - Foo(known, unknown); // Calls overload B - Foo(unknown, known); // Calls overload B - Foo(known, known); // Calls overload B - - Bar(known); // Calls overload D - Bar(unknown); // Calls overload D - } - -Currently, ``pass_object_size`` is a bit restricted in terms of its usage: - -* Only one use of ``pass_object_size`` is allowed per parameter. - -* It is an error to take the address of a function with ``pass_object_size`` on - any of its parameters. If you wish to do this, you can create an overload - without ``pass_object_size`` on any parameters. - -* It is an error to apply the ``pass_object_size`` attribute to parameters that - are not pointers. Additionally, any parameter that ``pass_object_size`` is - applied to must be marked ``const`` at its function's definition. - -Clang also supports the ``pass_dynamic_object_size`` attribute, which behaves -identically to ``pass_object_size``, but evaluates a call to -``__builtin_dynamic_object_size`` at the callee instead of -``__builtin_object_size``. ``__builtin_dynamic_object_size`` provides some extra -runtime checks when the object size can't be determined at compile-time. You can -read more about ``__builtin_dynamic_object_size`` `here -`_. - - -require_constant_initialization, constinit (C++20) --------------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``require_constant_initialization``","``clang::require_constant_initialization``","","","``constinit``","","Yes" - -This attribute specifies that the variable to which it is attached is intended -to have a `constant initializer `_ -according to the rules of [basic.start.static]. The variable is required to -have static or thread storage duration. If the initialization of the variable -is not a constant initializer an error will be produced. This attribute may -only be used in C++; the ``constinit`` spelling is only accepted in C++20 -onwards. - -Note that in C++03 strict constant expression checking is not done. Instead -the attribute reports if Clang can emit the variable as a constant, even if it's -not technically a 'constant initializer'. This behavior is non-portable. - -Static storage duration variables with constant initializers avoid hard-to-find -bugs caused by the indeterminate order of dynamic initialization. They can also -be safely used during dynamic initialization across translation units. - -This attribute acts as a compile time assertion that the requirements -for constant initialization have been met. Since these requirements change -between dialects and have subtle pitfalls it's important to fail fast instead -of silently falling back on dynamic initialization. - -The first use of the attribute on a variable must be part of, or precede, the -initializing declaration of the variable. C++20 requires the ``constinit`` -spelling of the attribute to be present on the initializing declaration if it -is used anywhere. The other spellings can be specified on a forward declaration -and omitted on a later initializing declaration. - -.. code-block:: c++ - - // -std=c++14 - #define SAFE_STATIC [[clang::require_constant_initialization]] - struct T { - constexpr T(int) {} - ~T(); // non-trivial - }; - SAFE_STATIC T x = {42}; // Initialization OK. Doesn't check destructor. - SAFE_STATIC T y = 42; // error: variable does not have a constant initializer - // copy initialization is not a constant expression on a non-literal type. - - -section, __declspec(allocate) ------------------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``section``","``gnu::section``","","``allocate``","","","Yes" - -The ``section`` attribute allows you to specify a specific section a -global variable or function should be in after translation. - - -swift_context -------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``swift_context``","``clang::swift_context``","``clang::swift_context``","","","","Yes" - -The ``swift_context`` attribute marks a parameter of a ``swiftcall`` -function as having the special context-parameter ABI treatment. - -This treatment generally passes the context value in a special register -which is normally callee-preserved. - -A ``swift_context`` parameter must either be the last parameter or must be -followed by a ``swift_error_result`` parameter (which itself must always be -the last parameter). - -A context parameter must have pointer or reference type. - - -swift_error_result ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``swift_error_result``","``clang::swift_error_result``","``clang::swift_error_result``","","","","Yes" - -The ``swift_error_result`` attribute marks a parameter of a ``swiftcall`` -function as having the special error-result ABI treatment. - -This treatment generally passes the underlying error value in and out of -the function through a special register which is normally callee-preserved. -This is modeled in C by pretending that the register is addressable memory: - -- The caller appears to pass the address of a variable of pointer type. - The current value of this variable is copied into the register before - the call; if the call returns normally, the value is copied back into the - variable. - -- The callee appears to receive the address of a variable. This address - is actually a hidden location in its own stack, initialized with the - value of the register upon entry. When the function returns normally, - the value in that hidden location is written back to the register. - -A ``swift_error_result`` parameter must be the last parameter, and it must be -preceded by a ``swift_context`` parameter. - -A ``swift_error_result`` parameter must have type ``T**`` or ``T*&`` for some -type T. Note that no qualifiers are permitted on the intermediate level. - -It is undefined behavior if the caller does not pass a pointer or -reference to a valid object. - -The standard convention is that the error value itself (that is, the -value stored in the apparent argument) will be null upon function entry, -but this is not enforced by the ABI. - - -swift_indirect_result ---------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``swift_indirect_result``","``clang::swift_indirect_result``","``clang::swift_indirect_result``","","","","Yes" - -The ``swift_indirect_result`` attribute marks a parameter of a ``swiftcall`` -function as having the special indirect-result ABI treatment. - -This treatment gives the parameter the target's normal indirect-result -ABI treatment, which may involve passing it differently from an ordinary -parameter. However, only the first indirect result will receive this -treatment. Furthermore, low-level lowering may decide that a direct result -must be returned indirectly; if so, this will take priority over the -``swift_indirect_result`` parameters. - -A ``swift_indirect_result`` parameter must either be the first parameter or -follow another ``swift_indirect_result`` parameter. - -A ``swift_indirect_result`` parameter must have type ``T*`` or ``T&`` for -some object type ``T``. If ``T`` is a complete type at the point of -definition of a function, it is undefined behavior if the argument -value does not point to storage of adequate size and alignment for a -value of type ``T``. - -Making indirect results explicit in the signature allows C functions to -directly construct objects into them without relying on language -optimizations like C++'s named return value optimization (NRVO). - - -swiftcall ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``swiftcall``","``clang::swiftcall``","``clang::swiftcall``","","","","" - -The ``swiftcall`` attribute indicates that a function should be called -using the Swift calling convention for a function or function pointer. - -The lowering for the Swift calling convention, as described by the Swift -ABI documentation, occurs in multiple phases. The first, "high-level" -phase breaks down the formal parameters and results into innately direct -and indirect components, adds implicit paraameters for the generic -signature, and assigns the context and error ABI treatments to parameters -where applicable. The second phase breaks down the direct parameters -and results from the first phase and assigns them to registers or the -stack. The ``swiftcall`` convention only handles this second phase of -lowering; the C function type must accurately reflect the results -of the first phase, as follows: - -- Results classified as indirect by high-level lowering should be - represented as parameters with the ``swift_indirect_result`` attribute. - -- Results classified as direct by high-level lowering should be represented - as follows: - - - First, remove any empty direct results. - - - If there are no direct results, the C result type should be ``void``. - - - If there is one direct result, the C result type should be a type with - the exact layout of that result type. - - - If there are a multiple direct results, the C result type should be - a struct type with the exact layout of a tuple of those results. - -- Parameters classified as indirect by high-level lowering should be - represented as parameters of pointer type. - -- Parameters classified as direct by high-level lowering should be - omitted if they are empty types; otherwise, they should be represented - as a parameter type with a layout exactly matching the layout of the - Swift parameter type. - -- The context parameter, if present, should be represented as a trailing - parameter with the ``swift_context`` attribute. - -- The error result parameter, if present, should be represented as a - trailing parameter (always following a context parameter) with the - ``swift_error_result`` attribute. - -``swiftcall`` does not support variadic arguments or unprototyped functions. - -The parameter ABI treatment attributes are aspects of the function type. -A function type which which applies an ABI treatment attribute to a -parameter is a different type from an otherwise-identical function type -that does not. A single parameter may not have multiple ABI treatment -attributes. - -Support for this feature is target-dependent, although it should be -supported on every target that Swift supports. Query for this support -with ``__has_attribute(swiftcall)``. This implies support for the -``swift_context``, ``swift_error_result``, and ``swift_indirect_result`` -attributes. - - -thread ------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","``thread``","","","" - -The ``__declspec(thread)`` attribute declares a variable with thread local -storage. It is available under the ``-fms-extensions`` flag for MSVC -compatibility. See the documentation for `__declspec(thread)`_ on MSDN. - -.. _`__declspec(thread)`: http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx - -In Clang, ``__declspec(thread)`` is generally equivalent in functionality to the -GNU ``__thread`` keyword. The variable must not have a destructor and must have -a constant initializer, if any. The attribute only applies to variables -declared with static storage duration, such as globals, class static data -members, and static locals. - - -tls_model ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``tls_model``","``gnu::tls_model``","","","","","Yes" - -The ``tls_model`` attribute allows you to specify which thread-local storage -model to use. It accepts the following strings: - -* global-dynamic -* local-dynamic -* initial-exec -* local-exec - -TLS models are mutually exclusive. - - -uninitialized -------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``uninitialized``","``clang::uninitialized``","","","","","" - -The command-line parameter ``-ftrivial-auto-var-init=*`` can be used to -initialize trivial automatic stack variables. By default, trivial automatic -stack variables are uninitialized. This attribute is used to override the -command-line parameter, forcing variables to remain uninitialized. It has no -semantic meaning in that using uninitialized values is undefined behavior, -it rather documents the programmer's intent. - - -Field Attributes -================ - - -no_unique_address ------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","``no_unique_address``","","","","","" - -The ``no_unique_address`` attribute allows tail padding in a non-static data -member to overlap other members of the enclosing class (and in the special -case when the type is empty, permits it to fully overlap other members). -The field is laid out as if a base class were encountered at the corresponding -point within the class (except that it does not share a vptr with the enclosing -object). - -Example usage: - -.. code-block:: c++ - - template struct my_vector { - T *p; - [[no_unique_address]] Alloc alloc; - // ... - }; - static_assert(sizeof(my_vector>) == sizeof(int*)); - -``[[no_unique_address]]`` is a standard C++20 attribute. Clang supports its use -in C++11 onwards. - - -Type Attributes -=============== - - -__ptr32 -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``__ptr32``","","" - -The ``__ptr32`` qualifier represents a native pointer on a 32-bit system. On a -64-bit system, a pointer with ``__ptr32`` is extended to a 64-bit pointer. The -``__sptr`` and ``__uptr`` qualifiers can be used to specify whether the pointer -is sign extended or zero extended. This qualifier is enabled under -``-fms-extensions``. - - -__ptr64 -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``__ptr64``","","" - -The ``__ptr64`` qualifier represents a native pointer on a 64-bit system. On a -32-bit system, a ``__ptr64`` pointer is truncated to a 32-bit pointer. This -qualifier is enabled under ``-fms-extensions``. - - -__sptr ------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``__sptr``","","" - -The ``__sptr`` qualifier specifies that a 32-bit pointer should be sign -extended when converted to a 64-bit pointer. - - -__uptr ------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``__uptr``","","" - -The ``__uptr`` qualifier specifies that a 32-bit pointer should be zero -extended when converted to a 64-bit pointer. - - -align_value ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``align_value``","","","","","","Yes" - -The align_value attribute can be added to the typedef of a pointer type or the -declaration of a variable of pointer or reference type. It specifies that the -pointer will point to, or the reference will bind to, only objects with at -least the provided alignment. This alignment value must be some positive power -of 2. - - .. code-block:: c - - typedef double * aligned_double_ptr __attribute__((align_value(64))); - void foo(double & x __attribute__((align_value(128)), - aligned_double_ptr y) { ... } - -If the pointer value does not have the specified alignment at runtime, the -behavior of the program is undefined. - - -hip_pinned_shadow ------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``hip_pinned_shadow``","","","``__hip_pinned_shadow__``","","","Yes" - -The GNU style attribute __attribute__((hip_pinned_shadow)) or MSVC style attribute -__declspec(hip_pinned_shadow) can be added to the definition of a global variable -to indicate it is a HIP pinned shadow variable. A HIP pinned shadow variable can -be accessed on both device side and host side. It has external linkage and is -not initialized on device side. It has internal linkage and is initialized by -the initializer on host side. - - -noderef -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``noderef``","``clang::noderef``","``clang::noderef``","","","","" - -The ``noderef`` attribute causes clang to diagnose dereferences of annotated pointer types. -This is ideally used with pointers that point to special memory which cannot be read -from or written to, but allowing for the pointer to be used in pointer arithmetic. -The following are examples of valid expressions where dereferences are diagnosed: - -.. code-block:: c - - int __attribute__((noderef)) *p; - int x = *p; // warning - - int __attribute__((noderef)) **p2; - x = **p2; // warning - - int * __attribute__((noderef)) *p3; - p = *p3; // warning - - struct S { - int a; - }; - struct S __attribute__((noderef)) *s; - x = s->a; // warning - x = (*s).a; // warning - -Not all dereferences may diagnose a warning if the value directed by the pointer may not be -accessed. The following are examples of valid expressions where may not be diagnosed: - -.. code-block:: c - - int *q; - int __attribute__((noderef)) *p; - q = &*p; - q = *&p; - - struct S { - int a; - }; - struct S __attribute__((noderef)) *s; - p = &s->a; - p = &(*s).a; - -``noderef`` is currently only supported for pointers and arrays and not usable for -references or Objective-C object pointers. - -.. code-block: c++ - - int x = 2; - int __attribute__((noderef)) &y = x; // warning: 'noderef' can only be used on an array or pointer type - -.. code-block: objc - - id __attribute__((noderef)) obj = [NSObject new]; // warning: 'noderef' can only be used on an array or pointer type - - -objc_class_stub ---------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_class_stub``","``clang::objc_class_stub``","``clang::objc_class_stub``","","","","Yes" - -This attribute specifies that the Objective-C class to which it applies is -instantiated at runtime. - -Unlike ``__attribute__((objc_runtime_visible))``, a class having this attribute -still has a "class stub" that is visible to the linker. This allows categories -to be defined. Static message sends with the class as a receiver use a special -access pattern to ensure the class is lazily instantiated from the class stub. - -Classes annotated with this attribute cannot be subclassed and cannot have -implementations defined for them. This attribute is intended for use in -Swift-generated headers for classes defined in Swift. - -Adding or removing this attribute to a class is an ABI-breaking change. - - -Statement Attributes -==================== - - -#pragma clang loop ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","","``clang loop`` |br| ``unroll`` |br| ``nounroll`` |br| ``unroll_and_jam`` |br| ``nounroll_and_jam``","" - -The ``#pragma clang loop`` directive allows loop optimization hints to be -specified for the subsequent loop. The directive allows pipelining to be -disabled, or vectorization, vector predication, interleaving, and unrolling to -be enabled or disabled. Vector width, vector predication, interleave count, -unrolling count, and the initiation interval for pipelining can be explicitly -specified. See `language extensions -`_ -for details. - - -#pragma unroll, #pragma nounroll --------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","","``clang loop`` |br| ``unroll`` |br| ``nounroll`` |br| ``unroll_and_jam`` |br| ``nounroll_and_jam``","" - -Loop unrolling optimization hints can be specified with ``#pragma unroll`` and -``#pragma nounroll``. The pragma is placed immediately before a for, while, -do-while, or c++11 range-based for loop. - -Specifying ``#pragma unroll`` without a parameter directs the loop unroller to -attempt to fully unroll the loop if the trip count is known at compile time and -attempt to partially unroll the loop if the trip count is not known at compile -time: - -.. code-block:: c++ - - #pragma unroll - for (...) { - ... - } - -Specifying the optional parameter, ``#pragma unroll _value_``, directs the -unroller to unroll the loop ``_value_`` times. The parameter may optionally be -enclosed in parentheses: - -.. code-block:: c++ - - #pragma unroll 16 - for (...) { - ... - } - - #pragma unroll(16) - for (...) { - ... - } - -Specifying ``#pragma nounroll`` indicates that the loop should not be unrolled: - -.. code-block:: c++ - - #pragma nounroll - for (...) { - ... - } - -``#pragma unroll`` and ``#pragma unroll _value_`` have identical semantics to -``#pragma clang loop unroll(full)`` and -``#pragma clang loop unroll_count(_value_)`` respectively. ``#pragma nounroll`` -is equivalent to ``#pragma clang loop unroll(disable)``. See -`language extensions -`_ -for further details including limitations of the unroll hints. - - -__read_only, __write_only, __read_write (read_only, write_only, read_write) ---------------------------------------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``__read_only`` |br| ``read_only`` |br| ``__write_only`` |br| ``write_only`` |br| ``__read_write`` |br| ``read_write``","","" - -The access qualifiers must be used with image object arguments or pipe arguments -to declare if they are being read or written by a kernel or function. - -The read_only/__read_only, write_only/__write_only and read_write/__read_write -names are reserved for use as access qualifiers and shall not be used otherwise. - -.. code-block:: c - - kernel void - foo (read_only image2d_t imageA, - write_only image2d_t imageB) { - ... - } - -In the above example imageA is a read-only 2D image object, and imageB is a -write-only 2D image object. - -The read_write (or __read_write) qualifier can not be used with pipe. - -More details can be found in the OpenCL C language Spec v2.0, Section 6.6. - - -fallthrough ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``fallthrough``","``fallthrough`` |br| ``clang::fallthrough`` |br| ``gnu::fallthrough``","``fallthrough``","","","","" - -The ``fallthrough`` (or ``clang::fallthrough``) attribute is used -to annotate intentional fall-through -between switch labels. It can only be applied to a null statement placed at a -point of execution between any statement and the next switch label. It is -common to mark these places with a specific comment, but this attribute is -meant to replace comments with a more strict annotation, which can be checked -by the compiler. This attribute doesn't change semantics of the code and can -be used wherever an intended fall-through occurs. It is designed to mimic -control-flow statements like ``break;``, so it can be placed in most places -where ``break;`` can, but only if there are no statements on the execution path -between it and the next switch label. - -By default, Clang does not warn on unannotated fallthrough from one ``switch`` -case to another. Diagnostics on fallthrough without a corresponding annotation -can be enabled with the ``-Wimplicit-fallthrough`` argument. - -Here is an example: - -.. code-block:: c++ - - // compile with -Wimplicit-fallthrough - switch (n) { - case 22: - case 33: // no warning: no statements between case labels - f(); - case 44: // warning: unannotated fall-through - g(); - [[clang::fallthrough]]; - case 55: // no warning - if (x) { - h(); - break; - } - else { - i(); - [[clang::fallthrough]]; - } - case 66: // no warning - p(); - [[clang::fallthrough]]; // warning: fallthrough annotation does not - // directly precede case label - q(); - case 77: // warning: unannotated fall-through - r(); - } - - -intel_reqd_sub_group_size -------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``intel_reqd_sub_group_size``","","","","","","Yes" - -The optional attribute intel_reqd_sub_group_size can be used to indicate that -the kernel must be compiled and executed with the specified subgroup size. When -this attribute is present, get_max_sub_group_size() is guaranteed to return the -specified integer value. This is important for the correctness of many subgroup -algorithms, and in some cases may be used by the compiler to generate more optimal -code. See `cl_intel_required_subgroup_size -` -for details. - - -opencl_unroll_hint ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``opencl_unroll_hint``","","","","","","" - -The opencl_unroll_hint attribute qualifier can be used to specify that a loop -(for, while and do loops) can be unrolled. This attribute qualifier can be -used to specify full unrolling or partial unrolling by a specified amount. -This is a compiler hint and the compiler may ignore this directive. See -`OpenCL v2.0 `_ -s6.11.5 for details. - - -suppress --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","``gsl::suppress``","","","","","" - -The ``[[gsl::suppress]]`` attribute suppresses specific -clang-tidy diagnostics for rules of the `C++ Core Guidelines`_ in a portable -way. The attribute can be attached to declarations, statements, and at -namespace scope. - -.. code-block:: c++ - - [[gsl::suppress("Rh-public")]] - void f_() { - int *p; - [[gsl::suppress("type")]] { - p = reinterpret_cast(7); - } - } - namespace N { - [[clang::suppress("type", "bounds")]]; - ... - } - -.. _`C++ Core Guidelines`: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#inforce-enforcement - - -Declaration Attributes -====================== - - -Owner ------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","``gsl::Owner``","","","","","Yes" - -.. Note:: This attribute is experimental and its effect on analysis is subject to change in - a future version of clang. - -The attribute ``[[gsl::Owner(T)]]`` applies to structs and classes that own an -object of type ``T``: - -.. code-block:: c++ - - class [[gsl::Owner(int)]] IntOwner { - private: - int value; - public: - int *getInt() { return &value; } - }; - -The argument ``T`` is optional and is ignored. -This attribute may be used by analysis tools and has no effect on code -generation. A ``void`` argument means that the class can own any type. - -See Pointer_ for an example. - - -Pointer -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","``gsl::Pointer``","","","","","Yes" - -.. Note:: This attribute is experimental and its effect on analysis is subject to change in - a future version of clang. - -The attribute ``[[gsl::Pointer(T)]]`` applies to structs and classes that behave -like pointers to an object of type ``T``: - -.. code-block:: c++ - - class [[gsl::Pointer(int)]] IntPointer { - private: - int *valuePointer; - public: - int *getInt() { return &valuePointer; } - }; - -The argument ``T`` is optional and is ignored. -This attribute may be used by analysis tools and has no effect on code -generation. A ``void`` argument means that the pointer can point to any type. - -Example: -When constructing an instance of a class annotated like this (a Pointer) from -an instance of a class annotated with ``[[gsl::Owner]]`` (an Owner), -then the analysis will consider the Pointer to point inside the Owner. -When the Owner's lifetime ends, it will consider the Pointer to be dangling. - -.. code-block:: c++ - - int f() { - IntPointer P; - if (true) { - IntOwner O(7); - P = IntPointer(O); // P "points into" O - } // P is dangling - return P.get(); // error: Using a dangling Pointer. - } - - -__single_inhertiance, __multiple_inheritance, __virtual_inheritance -------------------------------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``__single_inheritance`` |br| ``__multiple_inheritance`` |br| ``__virtual_inheritance`` |br| ``__unspecified_inheritance``","","" - -This collection of keywords is enabled under ``-fms-extensions`` and controls -the pointer-to-member representation used on ``*-*-win32`` targets. - -The ``*-*-win32`` targets utilize a pointer-to-member representation which -varies in size and alignment depending on the definition of the underlying -class. - -However, this is problematic when a forward declaration is only available and -no definition has been made yet. In such cases, Clang is forced to utilize the -most general representation that is available to it. - -These keywords make it possible to use a pointer-to-member representation other -than the most general one regardless of whether or not the definition will ever -be present in the current translation unit. - -This family of keywords belong between the ``class-key`` and ``class-name``: - -.. code-block:: c++ - - struct __single_inheritance S; - int S::*i; - struct S {}; - -This keyword can be applied to class templates but only has an effect when used -on full specializations: - -.. code-block:: c++ - - template struct __single_inheritance A; // warning: inheritance model ignored on primary template - template struct __multiple_inheritance A; // warning: inheritance model ignored on partial specialization - template <> struct __single_inheritance A; - -Note that choosing an inheritance model less general than strictly necessary is -an error: - -.. code-block:: c++ - - struct __multiple_inheritance S; // error: inheritance model does not match definition - int S::*i; - struct S {}; - - -asm ---- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``asm`` |br| ``__asm__``","","" - -This attribute can be used on a function or variable to specify its symbol name. - -On some targets, all C symbols are prefixed by default with a single character, typically ``_``. This was done historically to distinguish them from symbols used by other languages. (This prefix is also added to the standard Itanium C++ ABI prefix on "mangled" symbol names, so that e.g. on such targets the true symbol name for a C++ variable declared as ``int cppvar;`` would be ``__Z6cppvar``; note the two underscores.) This prefix is *not* added to the symbol names specified by the ``asm`` attribute; programmers wishing to match a C symbol name must compensate for this. - -For example, consider the following C code: - -.. code-block:: c - - int var1 asm("altvar") = 1; // "altvar" in symbol table. - int var2 = 1; // "_var2" in symbol table. - - void func1(void) asm("altfunc"); - void func1(void) {} // "altfunc" in symbol table. - void func2(void) {} // "_func2" in symbol table. - -Clang's implementation of this attribute is compatible with GCC's, `documented here `_. - -While it is possible to use this attribute to name a special symbol used internally by the compiler, such as an LLVM intrinsic, this is neither recommended nor supported and may cause the compiler to crash or miscompile. Users who wish to gain access to intrinsic behavior are strongly encouraged to request new builtin functions. - - -deprecated ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``deprecated``","``gnu::deprecated`` |br| ``deprecated``","``deprecated``","``deprecated``","","","" - -The ``deprecated`` attribute can be applied to a function, a variable, or a -type. This is useful when identifying functions, variables, or types that are -expected to be removed in a future version of a program. - -Consider the function declaration for a hypothetical function ``f``: - -.. code-block:: c++ - - void f(void) __attribute__((deprecated("message", "replacement"))); - -When spelled as `__attribute__((deprecated))`, the deprecated attribute can have -two optional string arguments. The first one is the message to display when -emitting the warning; the second one enables the compiler to provide a Fix-It -to replace the deprecated name with a new name. Otherwise, when spelled as -`[[gnu::deprecated]] or [[deprecated]]`, the attribute can have one optional -string argument which is the message to display when emitting the warning. - - -empty_bases ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","``empty_bases``","","","" - -The empty_bases attribute permits the compiler to utilize the -empty-base-optimization more frequently. -This attribute only applies to struct, class, and union types. -It is only supported when using the Microsoft C++ ABI. - - -enum_extensibility ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``enum_extensibility``","``clang::enum_extensibility``","``clang::enum_extensibility``","","","","Yes" - -Attribute ``enum_extensibility`` is used to distinguish between enum definitions -that are extensible and those that are not. The attribute can take either -``closed`` or ``open`` as an argument. ``closed`` indicates a variable of the -enum type takes a value that corresponds to one of the enumerators listed in the -enum definition or, when the enum is annotated with ``flag_enum``, a value that -can be constructed using values corresponding to the enumerators. ``open`` -indicates a variable of the enum type can take any values allowed by the -standard and instructs clang to be more lenient when issuing warnings. - -.. code-block:: c - - enum __attribute__((enum_extensibility(closed))) ClosedEnum { - A0, A1 - }; - - enum __attribute__((enum_extensibility(open))) OpenEnum { - B0, B1 - }; - - enum __attribute__((enum_extensibility(closed),flag_enum)) ClosedFlagEnum { - C0 = 1 << 0, C1 = 1 << 1 - }; - - enum __attribute__((enum_extensibility(open),flag_enum)) OpenFlagEnum { - D0 = 1 << 0, D1 = 1 << 1 - }; - - void foo1() { - enum ClosedEnum ce; - enum OpenEnum oe; - enum ClosedFlagEnum cfe; - enum OpenFlagEnum ofe; - - ce = A1; // no warnings - ce = 100; // warning issued - oe = B1; // no warnings - oe = 100; // no warnings - cfe = C0 | C1; // no warnings - cfe = C0 | C1 | 4; // warning issued - ofe = D0 | D1; // no warnings - ofe = D0 | D1 | 4; // no warnings - } - - -external_source_symbol ----------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``external_source_symbol``","``clang::external_source_symbol``","``clang::external_source_symbol``","","","","Yes" - -The ``external_source_symbol`` attribute specifies that a declaration originates -from an external source and describes the nature of that source. - -The fact that Clang is capable of recognizing declarations that were defined -externally can be used to provide better tooling support for mixed-language -projects or projects that rely on auto-generated code. For instance, an IDE that -uses Clang and that supports mixed-language projects can use this attribute to -provide a correct 'jump-to-definition' feature. For a concrete example, -consider a protocol that's defined in a Swift file: - -.. code-block:: swift - - @objc public protocol SwiftProtocol { - func method() - } - -This protocol can be used from Objective-C code by including a header file that -was generated by the Swift compiler. The declarations in that header can use -the ``external_source_symbol`` attribute to make Clang aware of the fact -that ``SwiftProtocol`` actually originates from a Swift module: - -.. code-block:: objc - - __attribute__((external_source_symbol(language="Swift",defined_in="module"))) - @protocol SwiftProtocol - @required - - (void) method; - @end - -Consequently, when 'jump-to-definition' is performed at a location that -references ``SwiftProtocol``, the IDE can jump to the original definition in -the Swift source file rather than jumping to the Objective-C declaration in the -auto-generated header file. - -The ``external_source_symbol`` attribute is a comma-separated list that includes -clauses that describe the origin and the nature of the particular declaration. -Those clauses can be: - -language=\ *string-literal* - The name of the source language in which this declaration was defined. - -defined_in=\ *string-literal* - The name of the source container in which the declaration was defined. The - exact definition of source container is language-specific, e.g. Swift's - source containers are modules, so ``defined_in`` should specify the Swift - module name. - -generated_declaration - This declaration was automatically generated by some tool. - -The clauses can be specified in any order. The clauses that are listed above are -all optional, but the attribute has to have at least one clause. - - -flag_enum ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``flag_enum``","``clang::flag_enum``","``clang::flag_enum``","","","","Yes" - -This attribute can be added to an enumerator to signal to the compiler that it -is intended to be used as a flag type. This will cause the compiler to assume -that the range of the type includes all of the values that you can get by -manipulating bits of the enumerator when issuing warnings. - - -layout_version --------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","``layout_version``","","","" - -The layout_version attribute requests that the compiler utilize the class -layout rules of a particular compiler version. -This attribute only applies to struct, class, and union types. -It is only supported when using the Microsoft C++ ABI. - - -lto_visibility_public ---------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``lto_visibility_public``","``clang::lto_visibility_public``","``clang::lto_visibility_public``","","","","Yes" - -See :doc:`LTOVisibility`. - - -novtable --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","``novtable``","","","" - -This attribute can be added to a class declaration or definition to signal to -the compiler that constructors and destructors will not reference the virtual -function table. It is only supported when using the Microsoft C++ ABI. - - -objc_boxable ------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_boxable``","``clang::objc_boxable``","``clang::objc_boxable``","","","","Yes" - -Structs and unions marked with the ``objc_boxable`` attribute can be used -with the Objective-C boxed expression syntax, ``@(...)``. - -**Usage**: ``__attribute__((objc_boxable))``. This attribute -can only be placed on a declaration of a trivially-copyable struct or union: - -.. code-block:: objc - - struct __attribute__((objc_boxable)) some_struct { - int i; - }; - union __attribute__((objc_boxable)) some_union { - int i; - float f; - }; - typedef struct __attribute__((objc_boxable)) _some_struct some_struct; - - // ... - - some_struct ss; - NSValue *boxed = @(ss); - - -objc_direct ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_direct``","``clang::objc_direct``","``clang::objc_direct``","","","","Yes" - -The ``objc_direct`` attribute can be used to mark an Objective-C method as -being *direct*. A direct method is treated statically like an ordinary method, -but dynamically it behaves more like a C function. This lowers some of the costs -associated with the method but also sacrifices some of the ordinary capabilities -of Objective-C methods. - -A message send of a direct method calls the implementation directly, as if it -were a C function, rather than using ordinary Objective-C method dispatch. This -is substantially faster and potentially allows the implementation to be inlined, -but it also means the method cannot be overridden in subclasses or replaced -dynamically, as ordinary Objective-C methods can. - -Furthermore, a direct method is not listed in the class's method lists. This -substantially reduces the code-size overhead of the method but also means it -cannot be called dynamically using ordinary Objective-C method dispatch at all; -in particular, this means that it cannot override a superclass method or satisfy -a protocol requirement. - -Because a direct method cannot be overridden, it is an error to perform -a ``super`` message send of one. - -Although a message send of a direct method causes the method to be called -directly as if it were a C function, it still obeys Objective-C semantics in other -ways: - -- If the receiver is ``nil``, the message send does nothing and returns the zero value - for the return type. - -- A message send of a direct class method will cause the class to be initialized, - including calling the ``+initialize`` method if present. - -- The implicit ``_cmd`` parameter containing the method's selector is still defined. - In order to minimize code-size costs, the implementation will not emit a reference - to the selector if the parameter is unused within the method. - -Symbols for direct method implementations are implicitly given hidden -visibility, meaning that they can only be called within the same linkage unit. - -It is an error to do any of the following: - -- declare a direct method in a protocol, -- declare an override of a direct method with a method in a subclass, -- declare an override of a non-direct method with a direct method in a subclass, -- declare a method with different directness in different class interfaces, or -- implement a non-direct method (as declared in any class interface) with a direct method. - -If any of these rules would be violated if every method defined in an -``@implementation`` within a single linkage unit were declared in an -appropriate class interface, the program is ill-formed with no diagnostic -required. If a violation of this rule is not diagnosed, behavior remains -well-defined; this paragraph is simply reserving the right to diagnose such -conflicts in the future, not to treat them as undefined behavior. - -Additionally, Clang will warn about any ``@selector`` expression that -names a selector that is only known to be used for direct methods. - -For the purpose of these rules, a "class interface" includes a class's primary -``@interface`` block, its class extensions, its categories, its declared protocols, -and all the class interfaces of its superclasses. - -An Objective-C property can be declared with the ``direct`` property -attribute. If a direct property declaration causes an implicit declaration of -a getter or setter method (that is, if the given method is not explicitly -declared elsewhere), the method is declared to be direct. - -Some programmers may wish to make many methods direct at once. In order -to simplify this, the ``objc_direct_members`` attribute is provided; see its -documentation for more information. - - -objc_direct_members -------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_direct_members``","``clang::objc_direct_members``","``clang::objc_direct_members``","","","","Yes" - -The ``objc_direct_members`` attribute can be placed on an Objective-C -``@interface`` or ``@implementation`` to mark that methods declared -therein should be considered direct by default. See the documentation -for ``objc_direct`` for more information about direct methods. - -When ``objc_direct_members`` is placed on an ``@interface`` block, every -method in the block is considered to be declared as direct. This includes any -implicit method declarations introduced by property declarations. If the method -redeclares a non-direct method, the declaration is ill-formed, exactly as if the -method was annotated with the ``objc_direct`` attribute. ``objc_direct_members`` -cannot be placed on the primary interface of a class, only on category or class -extension interfaces. - -When ``objc_direct_members`` is placed on an ``@implementation`` block, -methods defined in the block are considered to be declared as direct unless -they have been previously declared as non-direct in any interface of the class. -This includes the implicit method definitions introduced by synthesized -properties, including auto-synthesized properties. - - -objc_nonlazy_class ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_nonlazy_class``","``clang::objc_nonlazy_class``","``clang::objc_nonlazy_class``","","","","Yes" - -This attribute can be added to an Objective-C ``@interface`` or -``@implementation`` declaration to add the class to the list of non-lazily -initialized classes. A non-lazy class will be initialized eagerly when the -Objective-C runtime is loaded. This is required for certain system classes which -have instances allocated in non-standard ways, such as the classes for blocks -and constant strings. Adding this attribute is essentially equivalent to -providing a trivial `+load` method but avoids the (fairly small) load-time -overheads associated with defining and calling such a method. - - -objc_runtime_name ------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_runtime_name``","``clang::objc_runtime_name``","``clang::objc_runtime_name``","","","","Yes" - -By default, the Objective-C interface or protocol identifier is used -in the metadata name for that object. The `objc_runtime_name` -attribute allows annotated interfaces or protocols to use the -specified string argument in the object's metadata name instead of the -default name. - -**Usage**: ``__attribute__((objc_runtime_name("MyLocalName")))``. This attribute -can only be placed before an @protocol or @interface declaration: - -.. code-block:: objc - - __attribute__((objc_runtime_name("MyLocalName"))) - @interface Message - @end - - -objc_runtime_visible --------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_runtime_visible``","``clang::objc_runtime_visible``","``clang::objc_runtime_visible``","","","","Yes" - -This attribute specifies that the Objective-C class to which it applies is -visible to the Objective-C runtime but not to the linker. Classes annotated -with this attribute cannot be subclassed and cannot have categories defined for -them. - - -objc_subclassing_restricted ---------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``objc_subclassing_restricted``","``clang::objc_subclassing_restricted``","``clang::objc_subclassing_restricted``","","","","Yes" - -This attribute can be added to an Objective-C ``@interface`` declaration to -ensure that this class cannot be subclassed. - - -selectany ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``selectany``","``gnu::selectany``","","``selectany``","","","" - -This attribute appertains to a global symbol, causing it to have a weak -definition ( -`linkonce `_ -), allowing the linker to select any definition. - -For more information see -`gcc documentation `_ -or `msvc documentation `_. - - -transparent_union ------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``transparent_union``","``gnu::transparent_union``","","","","","" - -This attribute can be applied to a union to change the behaviour of calls to -functions that have an argument with a transparent union type. The compiler -behaviour is changed in the following manner: - -- A value whose type is any member of the transparent union can be passed as an - argument without the need to cast that value. - -- The argument is passed to the function using the calling convention of the - first member of the transparent union. Consequently, all the members of the - transparent union should have the same calling convention as its first member. - -Transparent unions are not supported in C++. - - -trivial_abi ------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``trivial_abi``","``clang::trivial_abi``","","","","","Yes" - -The ``trivial_abi`` attribute can be applied to a C++ class, struct, or union. -It instructs the compiler to pass and return the type using the C ABI for the -underlying type when the type would otherwise be considered non-trivial for the -purpose of calls. -A class annotated with `trivial_abi` can have non-trivial destructors or copy/move constructors without automatically becoming non-trivial for the purposes of calls. For example: - - .. code-block:: c++ - - // A is trivial for the purposes of calls because `trivial_abi` makes the - // user-provided special functions trivial. - struct __attribute__((trivial_abi)) A { - ~A(); - A(const A &); - A(A &&); - int x; - }; - - // B's destructor and copy/move constructor are considered trivial for the - // purpose of calls because A is trivial. - struct B { - A a; - }; - -If a type is trivial for the purposes of calls, has a non-trivial destructor, -and is passed as an argument by value, the convention is that the callee will -destroy the object before returning. - -Attribute ``trivial_abi`` has no effect in the following cases: - -- The class directly declares a virtual base or virtual methods. -- The class has a base class that is non-trivial for the purposes of calls. -- The class has a non-static data member whose type is non-trivial for the purposes of calls, which includes: - - - classes that are non-trivial for the purposes of calls - - __weak-qualified types in Objective-C++ - - arrays of any of the above - - -AMD GPU Attributes -================== - - -amdgpu_flat_work_group_size ---------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``amdgpu_flat_work_group_size``","``clang::amdgpu_flat_work_group_size``","","","","","Yes" - -The flat work-group size is the number of work-items in the work-group size -specified when the kernel is dispatched. It is the product of the sizes of the -x, y, and z dimension of the work-group. - -Clang supports the -``__attribute__((amdgpu_flat_work_group_size(, )))`` attribute for the -AMDGPU target. This attribute may be attached to a kernel function definition -and is an optimization hint. - -```` parameter specifies the minimum flat work-group size, and ```` -parameter specifies the maximum flat work-group size (must be greater than -````) to which all dispatches of the kernel will conform. Passing ``0, 0`` -as ``, `` implies the default behavior (``128, 256``). - -If specified, the AMDGPU target backend might be able to produce better machine -code for barriers and perform scratch promotion by estimating available group -segment size. - -An error will be given if: - - Specified values violate subtarget specifications; - - Specified values are not compatible with values provided through other - attributes. - - -amdgpu_num_sgpr ---------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``amdgpu_num_sgpr``","``clang::amdgpu_num_sgpr``","","","","","Yes" - -Clang supports the ``__attribute__((amdgpu_num_sgpr()))`` and -``__attribute__((amdgpu_num_vgpr()))`` attributes for the AMDGPU -target. These attributes may be attached to a kernel function definition and are -an optimization hint. - -If these attributes are specified, then the AMDGPU target backend will attempt -to limit the number of SGPRs and/or VGPRs used to the specified value(s). The -number of used SGPRs and/or VGPRs may further be rounded up to satisfy the -allocation requirements or constraints of the subtarget. Passing ``0`` as -``num_sgpr`` and/or ``num_vgpr`` implies the default behavior (no limits). - -These attributes can be used to test the AMDGPU target backend. It is -recommended that the ``amdgpu_waves_per_eu`` attribute be used to control -resources such as SGPRs and VGPRs since it is aware of the limits for different -subtargets. - -An error will be given if: - - Specified values violate subtarget specifications; - - Specified values are not compatible with values provided through other - attributes; - - The AMDGPU target backend is unable to create machine code that can meet the - request. - - -amdgpu_num_vgpr ---------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``amdgpu_num_vgpr``","``clang::amdgpu_num_vgpr``","","","","","Yes" - -Clang supports the ``__attribute__((amdgpu_num_sgpr()))`` and -``__attribute__((amdgpu_num_vgpr()))`` attributes for the AMDGPU -target. These attributes may be attached to a kernel function definition and are -an optimization hint. - -If these attributes are specified, then the AMDGPU target backend will attempt -to limit the number of SGPRs and/or VGPRs used to the specified value(s). The -number of used SGPRs and/or VGPRs may further be rounded up to satisfy the -allocation requirements or constraints of the subtarget. Passing ``0`` as -``num_sgpr`` and/or ``num_vgpr`` implies the default behavior (no limits). - -These attributes can be used to test the AMDGPU target backend. It is -recommended that the ``amdgpu_waves_per_eu`` attribute be used to control -resources such as SGPRs and VGPRs since it is aware of the limits for different -subtargets. - -An error will be given if: - - Specified values violate subtarget specifications; - - Specified values are not compatible with values provided through other - attributes; - - The AMDGPU target backend is unable to create machine code that can meet the - request. - - -amdgpu_waves_per_eu -------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``amdgpu_waves_per_eu``","``clang::amdgpu_waves_per_eu``","","","","","Yes" - -A compute unit (CU) is responsible for executing the wavefronts of a work-group. -It is composed of one or more execution units (EU), which are responsible for -executing the wavefronts. An EU can have enough resources to maintain the state -of more than one executing wavefront. This allows an EU to hide latency by -switching between wavefronts in a similar way to symmetric multithreading on a -CPU. In order to allow the state for multiple wavefronts to fit on an EU, the -resources used by a single wavefront have to be limited. For example, the number -of SGPRs and VGPRs. Limiting such resources can allow greater latency hiding, -but can result in having to spill some register state to memory. - -Clang supports the ``__attribute__((amdgpu_waves_per_eu([, ])))`` -attribute for the AMDGPU target. This attribute may be attached to a kernel -function definition and is an optimization hint. - -```` parameter specifies the requested minimum number of waves per EU, and -*optional* ```` parameter specifies the requested maximum number of waves -per EU (must be greater than ```` if specified). If ```` is omitted, -then there is no restriction on the maximum number of waves per EU other than -the one dictated by the hardware for which the kernel is compiled. Passing -``0, 0`` as ``, `` implies the default behavior (no limits). - -If specified, this attribute allows an advanced developer to tune the number of -wavefronts that are capable of fitting within the resources of an EU. The AMDGPU -target backend can use this information to limit resources, such as number of -SGPRs, number of VGPRs, size of available group and private memory segments, in -such a way that guarantees that at least ```` wavefronts and at most -```` wavefronts are able to fit within the resources of an EU. Requesting -more wavefronts can hide memory latency but limits available registers which -can result in spilling. Requesting fewer wavefronts can help reduce cache -thrashing, but can reduce memory latency hiding. - -This attribute controls the machine code generated by the AMDGPU target backend -to ensure it is capable of meeting the requested values. However, when the -kernel is executed, there may be other reasons that prevent meeting the request, -for example, there may be wavefronts from other kernels executing on the EU. - -An error will be given if: - - Specified values violate subtarget specifications; - - Specified values are not compatible with values provided through other - attributes; - - The AMDGPU target backend is unable to create machine code that can meet the - request. - - -Calling Conventions -=================== -Clang supports several different calling conventions, depending on the target -platform and architecture. The calling convention used for a function determines -how parameters are passed, how results are returned to the caller, and other -low-level details of calling a function. - -aarch64_vector_pcs ------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``aarch64_vector_pcs``","``clang::aarch64_vector_pcs``","``clang::aarch64_vector_pcs``","","","","" - -On AArch64 targets, this attribute changes the calling convention of a -function to preserve additional floating-point and Advanced SIMD registers -relative to the default calling convention used for AArch64. - -This means it is more efficient to call such functions from code that performs -extensive floating-point and vector calculations, because fewer live SIMD and FP -registers need to be saved. This property makes it well-suited for e.g. -floating-point or vector math library functions, which are typically leaf -functions that require a small number of registers. - -However, using this attribute also means that it is more expensive to call -a function that adheres to the default calling convention from within such -a function. Therefore, it is recommended that this attribute is only used -for leaf functions. - -For more information, see the documentation for `aarch64_vector_pcs`_ on -the Arm Developer website. - -.. _`aarch64_vector_pcs`: https://developer.arm.com/products/software-development-tools/hpc/arm-compiler-for-hpc/vector-function-abi - - -fastcall --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``fastcall``","``gnu::fastcall``","","","``__fastcall`` |br| ``_fastcall``","","" - -On 32-bit x86 targets, this attribute changes the calling convention of a -function to use ECX and EDX as register parameters and clear parameters off of -the stack on return. This convention does not support variadic calls or -unprototyped functions in C, and has no effect on x86_64 targets. This calling -convention is supported primarily for compatibility with existing code. Users -seeking register parameters should use the ``regparm`` attribute, which does -not require callee-cleanup. See the documentation for `__fastcall`_ on MSDN. - -.. _`__fastcall`: http://msdn.microsoft.com/en-us/library/6xa169sk.aspx - - -ms_abi ------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``ms_abi``","``gnu::ms_abi``","","","","","" - -On non-Windows x86_64 targets, this attribute changes the calling convention of -a function to match the default convention used on Windows x86_64. This -attribute has no effect on Windows targets or non-x86_64 targets. - - -pcs ---- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``pcs``","``gnu::pcs``","","","","","" - -On ARM targets, this attribute can be used to select calling conventions -similar to ``stdcall`` on x86. Valid parameter values are "aapcs" and -"aapcs-vfp". - - -preserve_all ------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``preserve_all``","``clang::preserve_all``","``clang::preserve_all``","","","","" - -On X86-64 and AArch64 targets, this attribute changes the calling convention of -a function. The ``preserve_all`` calling convention attempts to make the code -in the caller even less intrusive than the ``preserve_most`` calling convention. -This calling convention also behaves identical to the ``C`` calling convention -on how arguments and return values are passed, but it uses a different set of -caller/callee-saved registers. This removes the burden of saving and -recovering a large register set before and after the call in the caller. If -the arguments are passed in callee-saved registers, then they will be -preserved by the callee across the call. This doesn't apply for values -returned in callee-saved registers. - -- On X86-64 the callee preserves all general purpose registers, except for - R11. R11 can be used as a scratch register. Furthermore it also preserves - all floating-point registers (XMMs/YMMs). - -The idea behind this convention is to support calls to runtime functions -that don't need to call out to any other functions. - -This calling convention, like the ``preserve_most`` calling convention, will be -used by a future version of the Objective-C runtime and should be considered -experimental at this time. - - -preserve_most -------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``preserve_most``","``clang::preserve_most``","``clang::preserve_most``","","","","" - -On X86-64 and AArch64 targets, this attribute changes the calling convention of -a function. The ``preserve_most`` calling convention attempts to make the code -in the caller as unintrusive as possible. This convention behaves identically -to the ``C`` calling convention on how arguments and return values are passed, -but it uses a different set of caller/callee-saved registers. This alleviates -the burden of saving and recovering a large register set before and after the -call in the caller. If the arguments are passed in callee-saved registers, -then they will be preserved by the callee across the call. This doesn't -apply for values returned in callee-saved registers. - -- On X86-64 the callee preserves all general purpose registers, except for - R11. R11 can be used as a scratch register. Floating-point registers - (XMMs/YMMs) are not preserved and need to be saved by the caller. - -The idea behind this convention is to support calls to runtime functions -that have a hot path and a cold path. The hot path is usually a small piece -of code that doesn't use many registers. The cold path might need to call out to -another function and therefore only needs to preserve the caller-saved -registers, which haven't already been saved by the caller. The -`preserve_most` calling convention is very similar to the ``cold`` calling -convention in terms of caller/callee-saved registers, but they are used for -different types of function calls. ``coldcc`` is for function calls that are -rarely executed, whereas `preserve_most` function calls are intended to be -on the hot path and definitely executed a lot. Furthermore ``preserve_most`` -doesn't prevent the inliner from inlining the function call. - -This calling convention will be used by a future version of the Objective-C -runtime and should therefore still be considered experimental at this time. -Although this convention was created to optimize certain runtime calls to -the Objective-C runtime, it is not limited to this runtime and might be used -by other runtimes in the future too. The current implementation only -supports X86-64 and AArch64, but the intention is to support more architectures -in the future. - - -regcall -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``regcall``","``gnu::regcall``","","","``__regcall``","","" - -On x86 targets, this attribute changes the calling convention to -`__regcall`_ convention. This convention aims to pass as many arguments -as possible in registers. It also tries to utilize registers for the -return value whenever it is possible. - -.. _`__regcall`: https://software.intel.com/en-us/node/693069 - - -regparm -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``regparm``","``gnu::regparm``","","","","","" - -On 32-bit x86 targets, the regparm attribute causes the compiler to pass -the first three integer parameters in EAX, EDX, and ECX instead of on the -stack. This attribute has no effect on variadic functions, and all parameters -are passed via the stack as normal. - - -stdcall -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``stdcall``","``gnu::stdcall``","","","``__stdcall`` |br| ``_stdcall``","","" - -On 32-bit x86 targets, this attribute changes the calling convention of a -function to clear parameters off of the stack on return. This convention does -not support variadic calls or unprototyped functions in C, and has no effect on -x86_64 targets. This calling convention is used widely by the Windows API and -COM applications. See the documentation for `__stdcall`_ on MSDN. - -.. _`__stdcall`: http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx - - -thiscall --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``thiscall``","``gnu::thiscall``","","","``__thiscall`` |br| ``_thiscall``","","" - -On 32-bit x86 targets, this attribute changes the calling convention of a -function to use ECX for the first parameter (typically the implicit ``this`` -parameter of C++ methods) and clear parameters off of the stack on return. This -convention does not support variadic calls or unprototyped functions in C, and -has no effect on x86_64 targets. See the documentation for `__thiscall`_ on -MSDN. - -.. _`__thiscall`: http://msdn.microsoft.com/en-us/library/ek8tkfbw.aspx - - -vectorcall ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``vectorcall``","``clang::vectorcall``","``clang::vectorcall``","","``__vectorcall`` |br| ``_vectorcall``","","" - -On 32-bit x86 *and* x86_64 targets, this attribute changes the calling -convention of a function to pass vector parameters in SSE registers. - -On 32-bit x86 targets, this calling convention is similar to ``__fastcall``. -The first two integer parameters are passed in ECX and EDX. Subsequent integer -parameters are passed in memory, and callee clears the stack. On x86_64 -targets, the callee does *not* clear the stack, and integer parameters are -passed in RCX, RDX, R8, and R9 as is done for the default Windows x64 calling -convention. - -On both 32-bit x86 and x86_64 targets, vector and floating point arguments are -passed in XMM0-XMM5. Homogeneous vector aggregates of up to four elements are -passed in sequential SSE registers if enough are available. If AVX is enabled, -256 bit vectors are passed in YMM0-YMM5. Any vector or aggregate type that -cannot be passed in registers for any reason is passed by reference, which -allows the caller to align the parameter memory. - -See the documentation for `__vectorcall`_ on MSDN for more details. - -.. _`__vectorcall`: http://msdn.microsoft.com/en-us/library/dn375768.aspx - - -Consumed Annotation Checking -============================ -Clang supports additional attributes for checking basic resource management -properties, specifically for unique objects that have a single owning reference. -The following attributes are currently supported, although **the implementation -for these annotations is currently in development and are subject to change.** - -callable_when -------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``callable_when``","``clang::callable_when``","","","","","Yes" - -Use ``__attribute__((callable_when(...)))`` to indicate what states a method -may be called in. Valid states are unconsumed, consumed, or unknown. Each -argument to this attribute must be a quoted string. E.g.: - -``__attribute__((callable_when("unconsumed", "unknown")))`` - - -consumable ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``consumable``","``clang::consumable``","","","","","Yes" - -Each ``class`` that uses any of the typestate annotations must first be marked -using the ``consumable`` attribute. Failure to do so will result in a warning. - -This attribute accepts a single parameter that must be one of the following: -``unknown``, ``consumed``, or ``unconsumed``. - - -param_typestate ---------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``param_typestate``","``clang::param_typestate``","","","","","Yes" - -This attribute specifies expectations about function parameters. Calls to an -function with annotated parameters will issue a warning if the corresponding -argument isn't in the expected state. The attribute is also used to set the -initial state of the parameter when analyzing the function's body. - - -return_typestate ----------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``return_typestate``","``clang::return_typestate``","","","","","Yes" - -The ``return_typestate`` attribute can be applied to functions or parameters. -When applied to a function the attribute specifies the state of the returned -value. The function's body is checked to ensure that it always returns a value -in the specified state. On the caller side, values returned by the annotated -function are initialized to the given state. - -When applied to a function parameter it modifies the state of an argument after -a call to the function returns. The function's body is checked to ensure that -the parameter is in the expected state before returning. - - -set_typestate -------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``set_typestate``","``clang::set_typestate``","","","","","Yes" - -Annotate methods that transition an object into a new state with -``__attribute__((set_typestate(new_state)))``. The new state must be -unconsumed, consumed, or unknown. - - -test_typestate --------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``test_typestate``","``clang::test_typestate``","","","","","Yes" - -Use ``__attribute__((test_typestate(tested_state)))`` to indicate that a method -returns true if the object is in the specified state.. - - -Type Safety Checking -==================== -Clang supports additional attributes to enable checking type safety properties -that can't be enforced by the C type system. To see warnings produced by these -checks, ensure that -Wtype-safety is enabled. Use cases include: - -* MPI library implementations, where these attributes enable checking that - the buffer type matches the passed ``MPI_Datatype``; -* for HDF5 library there is a similar use case to MPI; -* checking types of variadic functions' arguments for functions like - ``fcntl()`` and ``ioctl()``. - -You can detect support for these attributes with ``__has_attribute()``. For -example: - -.. code-block:: c++ - - #if defined(__has_attribute) - # if __has_attribute(argument_with_type_tag) && \ - __has_attribute(pointer_with_type_tag) && \ - __has_attribute(type_tag_for_datatype) - # define ATTR_MPI_PWT(buffer_idx, type_idx) __attribute__((pointer_with_type_tag(mpi,buffer_idx,type_idx))) - /* ... other macros ... */ - # endif - #endif - - #if !defined(ATTR_MPI_PWT) - # define ATTR_MPI_PWT(buffer_idx, type_idx) - #endif - - int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */) - ATTR_MPI_PWT(1,3); - -argument_with_type_tag ----------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``argument_with_type_tag`` |br| ``pointer_with_type_tag``","``clang::argument_with_type_tag`` |br| ``clang::pointer_with_type_tag``","``clang::argument_with_type_tag`` |br| ``clang::pointer_with_type_tag``","","","","" - -Use ``__attribute__((argument_with_type_tag(arg_kind, arg_idx, -type_tag_idx)))`` on a function declaration to specify that the function -accepts a type tag that determines the type of some other argument. - -This attribute is primarily useful for checking arguments of variadic functions -(``pointer_with_type_tag`` can be used in most non-variadic cases). - -In the attribute prototype above: - * ``arg_kind`` is an identifier that should be used when annotating all - applicable type tags. - * ``arg_idx`` provides the position of a function argument. The expected type of - this function argument will be determined by the function argument specified - by ``type_tag_idx``. In the code example below, "3" means that the type of the - function's third argument will be determined by ``type_tag_idx``. - * ``type_tag_idx`` provides the position of a function argument. This function - argument will be a type tag. The type tag will determine the expected type of - the argument specified by ``arg_idx``. In the code example below, "2" means - that the type tag associated with the function's second argument should agree - with the type of the argument specified by ``arg_idx``. - -For example: - -.. code-block:: c++ - - int fcntl(int fd, int cmd, ...) - __attribute__(( argument_with_type_tag(fcntl,3,2) )); - // The function's second argument will be a type tag; this type tag will - // determine the expected type of the function's third argument. - - -pointer_with_type_tag ---------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``argument_with_type_tag`` |br| ``pointer_with_type_tag``","``clang::argument_with_type_tag`` |br| ``clang::pointer_with_type_tag``","``clang::argument_with_type_tag`` |br| ``clang::pointer_with_type_tag``","","","","" - -Use ``__attribute__((pointer_with_type_tag(ptr_kind, ptr_idx, type_tag_idx)))`` -on a function declaration to specify that the function accepts a type tag that -determines the pointee type of some other pointer argument. - -In the attribute prototype above: - * ``ptr_kind`` is an identifier that should be used when annotating all - applicable type tags. - * ``ptr_idx`` provides the position of a function argument; this function - argument will have a pointer type. The expected pointee type of this pointer - type will be determined by the function argument specified by - ``type_tag_idx``. In the code example below, "1" means that the pointee type - of the function's first argument will be determined by ``type_tag_idx``. - * ``type_tag_idx`` provides the position of a function argument; this function - argument will be a type tag. The type tag will determine the expected pointee - type of the pointer argument specified by ``ptr_idx``. In the code example - below, "3" means that the type tag associated with the function's third - argument should agree with the pointee type of the pointer argument specified - by ``ptr_idx``. - -For example: - -.. code-block:: c++ - - typedef int MPI_Datatype; - int MPI_Send(void *buf, int count, MPI_Datatype datatype /*, other args omitted */) - __attribute__(( pointer_with_type_tag(mpi,1,3) )); - // The function's 3rd argument will be a type tag; this type tag will - // determine the expected pointee type of the function's 1st argument. - - -type_tag_for_datatype ---------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``type_tag_for_datatype``","``clang::type_tag_for_datatype``","``clang::type_tag_for_datatype``","","","","" - -When declaring a variable, use -``__attribute__((type_tag_for_datatype(kind, type)))`` to create a type tag that -is tied to the ``type`` argument given to the attribute. - -In the attribute prototype above: - * ``kind`` is an identifier that should be used when annotating all applicable - type tags. - * ``type`` indicates the name of the type. - -Clang supports annotating type tags of two forms. - - * **Type tag that is a reference to a declared identifier.** - Use ``__attribute__((type_tag_for_datatype(kind, type)))`` when declaring that - identifier: - - .. code-block:: c++ - - typedef int MPI_Datatype; - extern struct mpi_datatype mpi_datatype_int - __attribute__(( type_tag_for_datatype(mpi,int) )); - #define MPI_INT ((MPI_Datatype) &mpi_datatype_int) - // &mpi_datatype_int is a type tag. It is tied to type "int". - - * **Type tag that is an integral literal.** - Declare a ``static const`` variable with an initializer value and attach - ``__attribute__((type_tag_for_datatype(kind, type)))`` on that declaration: - - .. code-block:: c++ - - typedef int MPI_Datatype; - static const MPI_Datatype mpi_datatype_int - __attribute__(( type_tag_for_datatype(mpi,int) )) = 42; - #define MPI_INT ((MPI_Datatype) 42) - // The number 42 is a type tag. It is tied to type "int". - - -The ``type_tag_for_datatype`` attribute also accepts an optional third argument -that determines how the type of the function argument specified by either -``arg_idx`` or ``ptr_idx`` is compared against the type associated with the type -tag. (Recall that for the ``argument_with_type_tag`` attribute, the type of the -function argument specified by ``arg_idx`` is compared against the type -associated with the type tag. Also recall that for the ``pointer_with_type_tag`` -attribute, the pointee type of the function argument specified by ``ptr_idx`` is -compared against the type associated with the type tag.) There are two supported -values for this optional third argument: - - * ``layout_compatible`` will cause types to be compared according to - layout-compatibility rules (In C++11 [class.mem] p 17, 18, see the - layout-compatibility rules for two standard-layout struct types and for two - standard-layout union types). This is useful when creating a type tag - associated with a struct or union type. For example: - - .. code-block:: c++ - - /* In mpi.h */ - typedef int MPI_Datatype; - struct internal_mpi_double_int { double d; int i; }; - extern struct mpi_datatype mpi_datatype_double_int - __attribute__(( type_tag_for_datatype(mpi, - struct internal_mpi_double_int, layout_compatible) )); - - #define MPI_DOUBLE_INT ((MPI_Datatype) &mpi_datatype_double_int) - - int MPI_Send(void *buf, int count, MPI_Datatype datatype, ...) - __attribute__(( pointer_with_type_tag(mpi,1,3) )); - - /* In user code */ - struct my_pair { double a; int b; }; - struct my_pair *buffer; - MPI_Send(buffer, 1, MPI_DOUBLE_INT /*, ... */); // no warning because the - // layout of my_pair is - // compatible with that of - // internal_mpi_double_int - - struct my_int_pair { int a; int b; } - struct my_int_pair *buffer2; - MPI_Send(buffer2, 1, MPI_DOUBLE_INT /*, ... */); // warning because the - // layout of my_int_pair - // does not match that of - // internal_mpi_double_int - - * ``must_be_null`` specifies that the function argument specified by either - ``arg_idx`` (for the ``argument_with_type_tag`` attribute) or ``ptr_idx`` (for - the ``pointer_with_type_tag`` attribute) should be a null pointer constant. - The second argument to the ``type_tag_for_datatype`` attribute is ignored. For - example: - - .. code-block:: c++ - - /* In mpi.h */ - typedef int MPI_Datatype; - extern struct mpi_datatype mpi_datatype_null - __attribute__(( type_tag_for_datatype(mpi, void, must_be_null) )); - - #define MPI_DATATYPE_NULL ((MPI_Datatype) &mpi_datatype_null) - int MPI_Send(void *buf, int count, MPI_Datatype datatype, ...) - __attribute__(( pointer_with_type_tag(mpi,1,3) )); - - /* In user code */ - struct my_pair { double a; int b; }; - struct my_pair *buffer; - MPI_Send(buffer, 1, MPI_DATATYPE_NULL /*, ... */); // warning: MPI_DATATYPE_NULL - // was specified but buffer - // is not a null pointer - - -OpenCL Address Spaces -===================== -The address space qualifier may be used to specify the region of memory that is -used to allocate the object. OpenCL supports the following address spaces: -__generic(generic), __global(global), __local(local), __private(private), -__constant(constant). - - .. code-block:: c - - __constant int c = ...; - - __generic int* foo(global int* g) { - __local int* l; - private int p; - ... - return l; - } - -More details can be found in the OpenCL C language Spec v2.0, Section 6.5. - -__constant, constant, [[clang::opencl_constant]] ------------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``opencl_constant``","``clang::opencl_constant``","``clang::opencl_constant``","","``__constant`` |br| ``constant``","","" - -The constant address space attribute signals that an object is located in -a constant (non-modifiable) memory region. It is available to all work items. -Any type can be annotated with the constant address space attribute. Objects -with the constant address space qualifier can be declared in any scope and must -have an initializer. - - -__generic, generic, [[clang::opencl_generic]] ---------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``opencl_generic``","``clang::opencl_generic``","``clang::opencl_generic``","","``__generic`` |br| ``generic``","","" - -The generic address space attribute is only available with OpenCL v2.0 and later. -It can be used with pointer types. Variables in global and local scope and -function parameters in non-kernel functions can have the generic address space -type attribute. It is intended to be a placeholder for any other address space -except for '__constant' in OpenCL code which can be used with multiple address -spaces. - - -__global, global, [[clang::opencl_global]] ------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``opencl_global``","``clang::opencl_global``","``clang::opencl_global``","","``__global`` |br| ``global``","","" - -The global address space attribute specifies that an object is allocated in -global memory, which is accessible by all work items. The content stored in this -memory area persists between kernel executions. Pointer types to the global -address space are allowed as function parameters or local variables. Starting -with OpenCL v2.0, the global address space can be used with global (program -scope) variables and static local variable as well. - - -__local, local, [[clang::opencl_local]] ---------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``opencl_local``","``clang::opencl_local``","``clang::opencl_local``","","``__local`` |br| ``local``","","" - -The local address space specifies that an object is allocated in the local (work -group) memory area, which is accessible to all work items in the same work -group. The content stored in this memory region is not accessible after -the kernel execution ends. In a kernel function scope, any variable can be in -the local address space. In other scopes, only pointer types to the local address -space are allowed. Local address space variables cannot have an initializer. - - -__private, private, [[clang::opencl_private]] ---------------------------------------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``opencl_private``","``clang::opencl_private``","``clang::opencl_private``","","``__private`` |br| ``private``","","" - -The private address space specifies that an object is allocated in the private -(work item) memory. Other work items cannot access the same memory area and its -content is destroyed after work item execution ends. Local variables can be -declared in the private address space. Function arguments are always in the -private address space. Kernel function arguments of a pointer or an array type -cannot point to the private address space. - - -Nullability Attributes -====================== -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``). - -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: - - .. code-block:: c - - // No meaningful result when 'ptr' is null (here, it happens to be undefined behavior). - int fetch(int * _Nonnull ptr) { return *ptr; } - - // 'ptr' may be null. - int fetch_or_zero(int * _Nullable ptr) { - return ptr ? *ptr : 0; - } - - // A nullable pointer to non-null pointers to const characters. - const char *join_strings(const char * _Nonnull * _Nullable strings, unsigned n); - -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: - - .. code-block:: objective-c - - @interface NSView : NSResponder - - (nullable NSView *)ancestorSharedWithView:(nonnull NSView *)aView; - @property (assign, nullable) NSView *superview; - @property (readonly, nonnull) NSArray *subviews; - @end - -_Nonnull --------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``_Nonnull``","","" - -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: - - .. code-block:: c - - int fetch(int * _Nonnull ptr); - -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. - - -_Null_unspecified ------------------ -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``_Null_unspecified``","","" - -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. - - -_Nullable ---------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "","","","","``_Nullable``","","" - -The ``_Nullable`` nullability qualifier indicates that a value of the ``_Nullable`` pointer type can be null. For example, given: - - .. code-block:: c - - int fetch_or_zero(int * _Nullable ptr); - -a caller of ``fetch_or_zero`` can provide null. - - -nonnull -------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``nonnull``","``gnu::nonnull``","","","","","" - -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 `_) 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: - - .. code-block:: c - - extern void * my_memcpy (void *dest, const void *src, size_t len) - __attribute__((nonnull (1, 2))); - -Here, the ``nonnull`` attribute indicates that parameters 1 and 2 -cannot have a null value. Omitting the parenthesized list of parameter indices means that all parameters of pointer type cannot be null: - - .. code-block:: c - - extern void * my_memcpy (void *dest, const void *src, size_t len) - __attribute__((nonnull)); - -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: - - .. code-block:: c - - extern void * my_memcpy (void *dest __attribute__((nonnull)), - const void *src __attribute__((nonnull)), size_t len); - -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. - - -returns_nonnull ---------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``returns_nonnull``","``gnu::returns_nonnull``","","","","","Yes" - -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: - - .. code-block:: c - - extern void * malloc (size_t size) __attribute__((returns_nonnull)); - -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 - - -Handle Attributes -================= -Handles are a way to identify resources like files, sockets, and processes. -They are more opaque than pointers and widely used in system programming. They -have similar risks such as never releasing a resource associated with a handle, -attempting to use a handle that was already released, or trying to release a -handle twice. Using the annotations below it is possible to make the ownership -of the handles clear: whose responsibility is to release them. They can also -aid static analysis tools to find bugs. - -acquire_handle --------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``acquire_handle``","``clang::acquire_handle``","``clang::acquire_handle``","","","","Yes" - -If this annotation is on a function or a function type it is assumed to return -a new handle. In case this annotation is on an output parameter, -the function is assumed to fill the corresponding argument with a new -handle. - -.. code-block:: c++ - - // Output arguments from Zircon. - zx_status_t zx_socket_create(uint32_t options, - zx_handle_t __attribute__((acquire_handle)) * out0, - zx_handle_t* out1 [[clang::acquire_handle]]); - - - // Returned handle. - [[clang::acquire_handle]] int open(const char *path, int oflag, ... ); - int open(const char *path, int oflag, ... ) __attribute__((acquire_handle)); - - -release_handle --------------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``release_handle``","``clang::release_handle``","``clang::release_handle``","","","","Yes" - -If a function parameter is annotated with `release_handle` it is assumed to -close the handle. It is also assumed to require an open handle to work with. - -.. code-block:: c++ - - zx_status_t zx_handle_close(zx_handle_t handle [[clang::release_handle]]); - - -use_handle ----------- -.. csv-table:: Supported Syntaxes - :header: "GNU", "C++11", "C2x", "``__declspec``", "Keyword", "``#pragma``", "``#pragma clang attribute``" - - "``use_handle``","``clang::use_handle``","``clang::use_handle``","","","","Yes" - -A function taking a handle by value might close the handle. If a function -parameter is annotated with `use_handle` it is assumed to not to change -the state of the handle. It is also assumed to require an open handle to work with. - -.. code-block:: c++ - - zx_status_t zx_port_wait(zx_handle_t handle [[clang::use_handle]], - zx_time_t deadline, - zx_port_packet_t* packet); - - diff --git a/gnu/llvm/clang/docs/ClangCommandLineReference.rst b/gnu/llvm/clang/docs/ClangCommandLineReference.rst index c59412b0b45..1613c8e4531 100644 --- a/gnu/llvm/clang/docs/ClangCommandLineReference.rst +++ b/gnu/llvm/clang/docs/ClangCommandLineReference.rst @@ -56,6 +56,18 @@ Pass the comma separated arguments in to the assembler .. option:: -Xarch\_ +.. program:: clang1 +.. option:: -Xarch\_device +.. program:: clang + +Pass to the CUDA/HIP device compilation + +.. program:: clang2 +.. option:: -Xarch\_host +.. program:: clang + +Pass to the CUDA/HIP host compilation + .. option:: -Xcuda-fatbinary Pass to fatbinary invocation @@ -142,10 +154,6 @@ Compile CUDA code for both host and device (default). Has no effect on non-CUDA Compile CUDA code for device only -.. option:: --cuda-gpu-arch=, --no-cuda-gpu-arch= - -CUDA GPU architecture (e.g. sm\_35). May be specified more than once. - .. option:: --cuda-host-only Compile CUDA code for host only. Has no effect on non-CUDA compilations. @@ -200,36 +208,16 @@ Trivial automatic variable initialization to zero is only here for benchmarks, i .. option:: -faligned-new= -.. option:: -fcuda-approx-transcendentals, -fno-cuda-approx-transcendentals - -Use approximate transcendental functions - .. option:: -fcuda-flush-denormals-to-zero, -fno-cuda-flush-denormals-to-zero Flush denormal floating point values to zero in CUDA device mode. -.. option:: -fcuda-short-ptr, -fno-cuda-short-ptr - -Use 32-bit pointers for accessing const/local/shared address spaces. - .. option:: -ffixed-r19 Reserve register r19 (Hexagon only) -.. option:: -fgpu-allow-device-init, -fno-gpu-allow-device-init - -Allow device side init function in HIP - -.. option:: -fgpu-rdc, -fcuda-rdc, -fno-gpu-rdc - -Generate relocatable device code, also known as separate compilation mode. - .. option:: -fheinous-gnu-extensions -.. option:: -fhip-new-launch-api, -fno-hip-new-launch-api - -Use new kernel launching API for HIP. - .. option:: -flat\_namespace .. option:: -fopenmp-targets=,... @@ -256,6 +244,10 @@ Add -rpath with architecture-specific resource directory to the linker flags Path to system blacklist file for sanitizers +.. option:: -fsystem-module + +Build this module as a system module. Only used with -emit-module + .. option:: --gcc-toolchain=, -gcc-toolchain Use the gcc toolchain at the given directory @@ -288,6 +280,10 @@ Display help for hidden options Link clang-offload-bundler bundles for HIP +.. option:: -ibuiltininc + +Enable builtin #include directories even when -nostdinc is used before or after -ibuiltininc. Using -nobuiltininc after the option disables it + .. option:: -image\_base .. option:: -index-header-map @@ -356,12 +352,12 @@ Don't error out if the detected version of the CUDA install is too low for the r Disable builtin #include directories -.. option:: -nocudainc - .. option:: -nodefaultlibs .. option:: -nofixprebinding +.. option:: -nogpuinc, -nocudainc + .. option:: -nogpulib, -nocudalib Do not link device library for CUDA/HIP device compilation @@ -466,6 +462,10 @@ Only modify files with a filename contained in the provided directory path .. option:: -object +.. option:: --offload-arch=, --cuda-gpu-arch=, --no-offload-arch= + +CUDA/HIP offloading device architecture (e.g. sm\_35, gfx906). May be specified more than once. + .. option:: -p, --profile .. option:: -pagezero\_size @@ -526,6 +526,10 @@ Print the paths used for finding libraries and programs Print the normalized target triple +.. option:: -print-targets, --print-targets + +Print the registered targets + .. option:: -private\_bundle .. option:: -pthread, -no-pthread @@ -810,10 +814,6 @@ Print source range spans in numeric form Discard value names in LLVM IR -.. option:: -fexperimental-isel, -fno-experimental-isel - -Enables the experimental global instruction selector - .. option:: -fexperimental-new-pass-manager, -fno-experimental-new-pass-manager Enables an experimental new pass manager in LLVM. @@ -826,6 +826,10 @@ Enables the use of non-default rounding modes and non-default exception handling Use separate accesses for consecutive bitfield runs with legal widths and alignments. +.. option:: -fglobal-isel, -fexperimental-isel, -fno-global-isel + +Enables the global instruction selector + .. option:: -finline-functions, -fno-inline-functions Inline suitable functions @@ -882,6 +886,14 @@ Enable control flow integrity (CFI) checks for cross-DSO calls. Generalize pointers in CFI indirect call type signature checks +.. option:: -fsanitize-coverage-allowlist= + +Restrict sanitizer coverage instrumentation exclusively to modules and functions that match the provided special case list, except the blocked ones + +.. option:: -fsanitize-coverage-blocklist= + +Disable sanitizer coverage instrumentation for modules and functions that match the provided special case list, even the allowed ones + .. option:: -fsanitize-coverage=,..., -fno-sanitize-coverage=,... Specify the type of coverage instrumentation for Sanitizers @@ -910,11 +922,7 @@ Enable use-after-destroy detection in MemorySanitizer .. option:: -fsanitize-minimal-runtime, -fno-sanitize-minimal-runtime -.. option:: -fsanitize-recover, -fno-sanitize-recover - -.. program:: clang1 -.. option:: -fsanitize-recover=,..., -fno-sanitize-recover=,... -.. program:: clang +.. option:: -fsanitize-recover=,..., -fno-sanitize-recover=,..., -fsanitize-recover (equivalent to -fsanitize-recover=all) Enable recovery for specified sanitizers @@ -934,7 +942,7 @@ Enable function entry/exit instrumentation in ThreadSanitizer (default) Enable memory access instrumentation in ThreadSanitizer (default) -.. option:: -fsanitize-trap=,..., -fno-sanitize-trap=,... +.. option:: -fsanitize-trap=,..., -fno-sanitize-trap=,..., -fsanitize-trap (equivalent to -fsanitize-trap=all), -fsanitize-undefined-trap-on-error (equivalent to -fsanitize-trap=undefined) Enable trapping for specified sanitizers @@ -942,8 +950,6 @@ Enable trapping for specified sanitizers Strip (or keep only, if negative) a given number of path components when emitting check metadata. -.. option:: -fsanitize-undefined-trap-on-error, -fno-sanitize-undefined-trap-on-error - .. option:: -fsanitize=,..., -fno-sanitize=,... Turn on runtime checks for various forms of undefined or suspicious behavior. See user manual for available checks @@ -1140,6 +1146,10 @@ Path to libomptarget-nvptx libraries Path to ptxas (used for compiling CUDA code) +.. option:: --rocm-path= + +ROCm installation path, used for finding and automatically linking required bitcode libraries. + .. program:: clang1 .. option:: -stdlib++-isystem .. program:: clang @@ -1263,8 +1273,6 @@ Target-independent compilation options .. option:: -fPIE, -fno-PIE -.. option:: -faccess-control, -fno-access-control - .. option:: -faddrsig, -fno-addrsig Emit an address-significance table @@ -1327,6 +1335,10 @@ Restrict code to those available for App Extensions .. option:: -fautolink, -fno-autolink +.. option:: -fbasic-block-sections= + +Generate labels for each basic block or place each basic block or a subset of basic blocks in its own section. + .. option:: -fblocks, -fno-blocks Enable the 'blocks' language feature @@ -1347,8 +1359,6 @@ Load the clang builtins module map file. .. option:: -fc++-static-destructors, -fno-c++-static-destructors -Enable C++ static destructor registration (the default) - .. option:: -fcaret-diagnostics, -fno-caret-diagnostics .. option:: -fcf-protection=, -fcf-protection (equivalent to -fcf-protection=full) @@ -1365,10 +1375,12 @@ Enable C++ builtin type char8\_t .. option:: -fcolor-diagnostics, -fno-color-diagnostics -Use colors in diagnostics +Enable colors in diagnostics .. option:: -fcommon, -fno-common +Place uninitialized global variables in a common block + .. option:: -fcompile-resource=, --resource , --resource= .. option:: -fconstant-cfstrings, -fno-constant-cfstrings @@ -1405,6 +1417,14 @@ Generate instrumented code to collect context sensitive execution counts into de Generate instrumented code to collect context sensitive execution counts into /default.profraw (overridden by LLVM\_PROFILE\_FILE env var) +.. option:: -fcuda-approx-transcendentals, -fno-cuda-approx-transcendentals + +Use approximate transcendental functions + +.. option:: -fcuda-short-ptr, -fno-cuda-short-ptr + +Use 32-bit pointers for accessing const/local/shared address spaces + .. option:: -fcxx-exceptions, -fno-cxx-exceptions Enable C++ exceptions @@ -1413,7 +1433,7 @@ Enable C++ exceptions .. option:: -fdata-sections, -fno-data-sections -Place each data in its own section (ELF Only) +Place each data in its own section .. option:: -fdebug-compilation-dir , -fdebug-compilation-dir= @@ -1425,7 +1445,7 @@ Default DWARF version to use, if a -g option caused DWARF debug info to be produ .. option:: -fdebug-info-for-profiling, -fno-debug-info-for-profiling -Emit extra debug info to make sample profile more accurate. +Emit extra debug info to make sample profile more accurate .. option:: -fdebug-macro, -fno-debug-macro @@ -1441,7 +1461,7 @@ remap file source paths in debug info .. option:: -fdebug-ranges-base-address, -fno-debug-ranges-base-address -Use DWARF base address selection entries in debug\_ranges +Use DWARF base address selection entries in .debug\_ranges .. option:: -fdebug-types-section, -fno-debug-types-section @@ -1453,7 +1473,7 @@ Parse templated function definitions at the end of the translation unit .. option:: -fdelete-null-pointer-checks, -fno-delete-null-pointer-checks -Treat usage of null pointers as undefined behavior. +Treat usage of null pointers as undefined behavior (default) .. option:: -fdenormal-fp-math= @@ -1521,6 +1541,10 @@ Emit all declarations, even if unused Use emutls functions to access thread\_local variables +.. option:: -fenable-matrix + +Enable matrix data type and related builtin functions + .. option:: -fencoding=, --encoding , --encoding= .. option:: -ferror-limit= @@ -1537,6 +1561,10 @@ Enable support for exception handling Enable the experimental new constant interpreter +.. option:: -fexperimental-relative-c++-abi-vtables, -fno-experimental-relative-c++-abi-vtables + +Use the experimental C++ class ABI for classes with virtual tables + .. option:: -fextdirs=, --extdirs , --extdirs= .. option:: -ffast-math, -fno-fast-math @@ -1585,7 +1613,7 @@ Assert that the compilation takes place in a freestanding environment .. option:: -ffunction-sections, -fno-function-sections -Place each function in its own section (ELF Only) +Place each function in its own section .. option:: -fgnu-inline-asm, -fno-gnu-inline-asm @@ -1605,12 +1633,28 @@ Use the gnu89 inline semantics Sets various macros to claim compatibility with the given GCC version (default is 4.2.1) +.. option:: -fgpu-allow-device-init, -fno-gpu-allow-device-init + +Allow device side init function in HIP + +.. option:: -fgpu-rdc, -fcuda-rdc, -fno-gpu-rdc + +Generate relocatable device code, also known as separate compilation mode + +.. option:: -fhip-new-launch-api, -fno-hip-new-launch-api + +Use new kernel launching API for HIP + .. option:: -fhonor-infinities, -fhonor-infinites, -fno-honor-infinities .. option:: -fhonor-nans, -fno-honor-nans .. option:: -fhosted +.. option:: -fignore-exceptions + +Enable support for ignoring exception handling constructs + .. option:: -fimplicit-module-maps, -fmodule-maps, -fno-implicit-module-maps Implicitly search the file system for module map files. @@ -1641,9 +1685,11 @@ Run cc1 in-process .. option:: -fjump-tables, -fno-jump-tables -.. option:: -fkeep-static-consts +Use jump tables for lowering switches -Keep static const variables even if unused +.. option:: -fkeep-static-consts, -fno-keep-static-consts + +Keep static const variables if unused .. option:: -flax-vector-conversions=, -flax-vector-conversions (equivalent to -flax-vector-conversions=integer), -fno-lax-vector-conversions (equivalent to -flax-vector-conversions=none) @@ -1671,6 +1717,10 @@ Set LTO mode to either 'full' or 'thin' Require math functions to indicate errors by setting errno +.. option:: -fmax-tokens= + +Max total number of preprocessed tokens for -Wmax-tokens. + .. option:: -fmax-type-align= Specify the maximum alignment to enforce on pointers lacking an explicit alignment @@ -1681,6 +1731,8 @@ Allow merging of constants .. option:: -fmessage-length= +Format message diagnostics so that they fit within N columns + .. option:: -fmodule-file-deps, -fno-module-file-deps .. option:: -fmodule-map-file= @@ -1751,6 +1803,8 @@ Specifies the largest alignment guaranteed by '::operator new(size\_t)' .. option:: -fnext-runtime +.. option:: -fno-access-control, -fno-no-access-control + .. option:: -fno-builtin- Disable implicit builtin knowledge of a specific function @@ -1765,18 +1819,12 @@ Do not elide types when printing diagnostics Do not treat C++ operator name keywords as synonyms for operators -.. option:: -fno-rtti-data - -Control emission of RTTI data - .. option:: -fno-strict-modules-decluse .. option:: -fno-temp-file Directly create compilation output files. This may lead to incorrect incremental builds if the compiler crashes -.. option:: -fno-virtual-function\_elimination - .. option:: -fno-working-directory .. option:: -fno\_modules-validate-input-files-content @@ -1785,6 +1833,10 @@ Directly create compilation output files. This may lead to incorrect incremental .. option:: -fno\_pch-validate-input-files-content .. program:: clang +.. option:: -fnostack-clash-protection + +Disable stack clash protection + .. option:: -fnoxray-link-deps .. option:: -fobjc-abi-version= @@ -1893,8 +1945,6 @@ Validate PCH input files based on content if mtime differs .. option:: -fplt, -fno-plt -Use the PLT to make function calls - .. option:: -fplugin= Load the named plugin (dynamic shared object) @@ -2000,12 +2050,18 @@ Turn on loop reroller .. option:: -fropi, -fno-ropi +Generate read-only position independent code (ARM only) + .. option:: -frounding-math, -fno-rounding-math .. option:: -frtti, -fno-rtti +.. option:: -frtti-data, -fno-rtti-data + .. option:: -frwpi, -fno-rwpi +Generate read-write position independent code (ARM only) + .. option:: -fsave-optimization-record, -fno-save-optimization-record Generate a YAML optimization record file @@ -2020,6 +2076,8 @@ Generate an optimization record file in a specific format Use SEH style exceptions +.. option:: -fsemantic-interposition, -fno-semantic-interposition + .. option:: -fshort-enums, -fno-short-enums Allocate to an enum type only as many bytes as it needs for the declared range of possible values @@ -2042,6 +2100,8 @@ Which overload candidates to show when overload resolution fails: best\|all; def .. option:: -fsigned-char, -fno-signed-char, --signed-char +char is signed + .. option:: -fsigned-zeros, -fno-signed-zeros .. option:: -fsized-deallocation, -fno-sized-deallocation @@ -2066,10 +2126,14 @@ Provide minimal debug info in the object/executable to facilitate online symboli .. option:: -fsplit-lto-unit, -fno-split-lto-unit -Enables splitting of the LTO unit. +Enables splitting of the LTO unit .. option:: -fsplit-stack +.. option:: -fstack-clash-protection + +Enable stack clash protection + .. option:: -fstack-protector, -fno-stack-protector Enable stack protectors for some functions vulnerable to stack smashing. This uses a loose heuristic which considers functions vulnerable if they contain a char (or 8bit integer) array or constant sized calls to alloca, which are of greater size than ssp-buffer-size (default: 8 bytes). All variable sized calls to alloca are considered vulnerable @@ -2104,8 +2168,6 @@ Assume that overflowing float-to-int casts are undefined (default) .. option:: -fstrict-return, -fno-strict-return -Always treat control flow paths that fall off the end of a non-void function as unreachable - .. option:: -fstrict-vtable-pointers, -fno-strict-vtable-pointers Enable optimizations based on the strict rules for overwriting polymorphic C++ objects @@ -2122,7 +2184,7 @@ Enable optimizations based on the strict rules for overwriting polymorphic C++ o .. option:: -ftemplate-depth= -.. option:: -ftest-coverage +.. option:: -ftest-coverage, -fno-test-coverage .. option:: -fthin-link-bitcode= @@ -2171,13 +2233,23 @@ Specify the function to be called on overflow Process trigraph sequences +.. option:: -ftrivial-auto-var-init-stop-after= + +Stop initializing trivial automatic stack variables after the specified number of instances + .. option:: -ftrivial-auto-var-init= Initialize trivial automatic stack variables: uninitialized (default) \| pattern -.. option:: -funique-section-names, -fno-unique-section-names +.. option:: -funique-basic-block-section-names, -fno-unique-basic-block-section-names + +Use unique names for basic block sections (ELF Only) -Use unique names for text and data sections (ELF Only) +.. option:: -funique-internal-linkage-names, -fno-unique-internal-linkage-names + +Uniqueify Internal Linkage Symbol Names by appending the MD5 hash of the module path + +.. option:: -funique-section-names, -fno-unique-section-names .. option:: -funit-at-a-time, -fno-unit-at-a-time @@ -2197,12 +2269,12 @@ Turn on loop unroller .. option:: -fuse-init-array, -fno-use-init-array -Use .init\_array instead of .ctors - .. option:: -fuse-ld= .. option:: -fuse-line-directives, -fno-use-line-directives +Use #line in preprocessed output + .. option:: -fvalidate-ast-input-files-content Compute and store the hash of input files used to build an AST. Files with mismatching mtime's are considered valid if both contents is identical @@ -2217,7 +2289,9 @@ Enable the loop vectorization passes .. option:: -fverbose-asm, -dA, -fno-verbose-asm -.. option:: -fvirtual-function-elimination +Generate verbose assembly output + +.. option:: -fvirtual-function-elimination, -fno-virtual-function-elimination Enables dead virtual function elimination optimization. Requires -flto=full @@ -2255,11 +2329,11 @@ Store string literals as writable data .. option:: -fxray-always-emit-customevents, -fno-xray-always-emit-customevents -Determine whether to always emit \_\_xray\_customevent(...) calls even if the function it appears in is not always instrumented. +Always emit \_\_xray\_customevent(...) calls even if the containing function is not always instrumented .. option:: -fxray-always-emit-typedevents, -fno-xray-always-emit-typedevents -Determine whether to always emit \_\_xray\_typedevent(...) calls even if the function it appears in is not always instrumented. +Always emit \_\_xray\_typedevent(...) calls even if the containing function is not always instrumented .. option:: -fxray-always-instrument= @@ -2269,6 +2343,12 @@ DEPRECATED: Filename defining the whitelist for imbuing the 'always instrument' Filename defining the list of functions/types for imbuing XRay attributes. +.. option:: -fxray-function-index, -fno-xray-function-index + +.. option:: -fxray-ignore-loops, -fno-xray-ignore-loops + +Don't instrument functions with loops unless they also meet the minimum function size + .. option:: -fxray-instruction-threshold .. program:: clang1 @@ -2283,7 +2363,7 @@ Generate XRay instrumentation sleds on function entry and exit .. option:: -fxray-instrumentation-bundle= -Select which XRay instrumentation points to emit. Options: all, none, function, custom. Default is 'all'. +Select which XRay instrumentation points to emit. Options: all, none, function-entry, function-exit, function, custom. Default is 'all'. 'function' includes both 'function-entry' and 'function-exit'. .. option:: -fxray-link-deps @@ -2361,135 +2441,145 @@ OpenCL only. Defines that the global work-size be a multiple of the work-group s OpenCL only. Allow unsafe floating-point optimizations. Also implies -cl-no-signed-zeros and -cl-mad-enable. +SYCL flags +---------- +.. option:: -fsycl, -fno-sycl + +Enable SYCL kernels compilation for device + +.. option:: -sycl-std= + +SYCL language standard to compile for. + Target-dependent compilation options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. option:: -G, -G=, -msmall-data-threshold= +.. option:: -G, -G=, -msmall-data-limit=, -msmall-data-threshold= Put objects of at most bytes into small data section (MIPS / Hexagon) .. option:: -ffixed-x1 -Reserve the 1 register (AArch64/RISC-V only) +Reserve the x1 register (AArch64/RISC-V only) .. option:: -ffixed-x10 -Reserve the 10 register (AArch64/RISC-V only) +Reserve the x10 register (AArch64/RISC-V only) .. option:: -ffixed-x11 -Reserve the 11 register (AArch64/RISC-V only) +Reserve the x11 register (AArch64/RISC-V only) .. option:: -ffixed-x12 -Reserve the 12 register (AArch64/RISC-V only) +Reserve the x12 register (AArch64/RISC-V only) .. option:: -ffixed-x13 -Reserve the 13 register (AArch64/RISC-V only) +Reserve the x13 register (AArch64/RISC-V only) .. option:: -ffixed-x14 -Reserve the 14 register (AArch64/RISC-V only) +Reserve the x14 register (AArch64/RISC-V only) .. option:: -ffixed-x15 -Reserve the 15 register (AArch64/RISC-V only) +Reserve the x15 register (AArch64/RISC-V only) .. option:: -ffixed-x16 -Reserve the 16 register (AArch64/RISC-V only) +Reserve the x16 register (AArch64/RISC-V only) .. option:: -ffixed-x17 -Reserve the 17 register (AArch64/RISC-V only) +Reserve the x17 register (AArch64/RISC-V only) .. option:: -ffixed-x18 -Reserve the 18 register (AArch64/RISC-V only) +Reserve the x18 register (AArch64/RISC-V only) .. option:: -ffixed-x19 -Reserve the 19 register (AArch64/RISC-V only) +Reserve the x19 register (AArch64/RISC-V only) .. option:: -ffixed-x2 -Reserve the 2 register (AArch64/RISC-V only) +Reserve the x2 register (AArch64/RISC-V only) .. option:: -ffixed-x20 -Reserve the 20 register (AArch64/RISC-V only) +Reserve the x20 register (AArch64/RISC-V only) .. option:: -ffixed-x21 -Reserve the 21 register (AArch64/RISC-V only) +Reserve the x21 register (AArch64/RISC-V only) .. option:: -ffixed-x22 -Reserve the 22 register (AArch64/RISC-V only) +Reserve the x22 register (AArch64/RISC-V only) .. option:: -ffixed-x23 -Reserve the 23 register (AArch64/RISC-V only) +Reserve the x23 register (AArch64/RISC-V only) .. option:: -ffixed-x24 -Reserve the 24 register (AArch64/RISC-V only) +Reserve the x24 register (AArch64/RISC-V only) .. option:: -ffixed-x25 -Reserve the 25 register (AArch64/RISC-V only) +Reserve the x25 register (AArch64/RISC-V only) .. option:: -ffixed-x26 -Reserve the 26 register (AArch64/RISC-V only) +Reserve the x26 register (AArch64/RISC-V only) .. option:: -ffixed-x27 -Reserve the 27 register (AArch64/RISC-V only) +Reserve the x27 register (AArch64/RISC-V only) .. option:: -ffixed-x28 -Reserve the 28 register (AArch64/RISC-V only) +Reserve the x28 register (AArch64/RISC-V only) .. option:: -ffixed-x29 -Reserve the 29 register (AArch64/RISC-V only) +Reserve the x29 register (AArch64/RISC-V only) .. option:: -ffixed-x3 -Reserve the 3 register (AArch64/RISC-V only) +Reserve the x3 register (AArch64/RISC-V only) .. option:: -ffixed-x30 -Reserve the 30 register (AArch64/RISC-V only) +Reserve the x30 register (AArch64/RISC-V only) .. option:: -ffixed-x31 -Reserve the 31 register (AArch64/RISC-V only) +Reserve the x31 register (AArch64/RISC-V only) .. option:: -ffixed-x4 -Reserve the 4 register (AArch64/RISC-V only) +Reserve the x4 register (AArch64/RISC-V only) .. option:: -ffixed-x5 -Reserve the 5 register (AArch64/RISC-V only) +Reserve the x5 register (AArch64/RISC-V only) .. option:: -ffixed-x6 -Reserve the 6 register (AArch64/RISC-V only) +Reserve the x6 register (AArch64/RISC-V only) .. option:: -ffixed-x7 -Reserve the 7 register (AArch64/RISC-V only) +Reserve the x7 register (AArch64/RISC-V only) .. option:: -ffixed-x8 -Reserve the 8 register (AArch64/RISC-V only) +Reserve the x8 register (AArch64/RISC-V only) .. option:: -ffixed-x9 -Reserve the 9 register (AArch64/RISC-V only) +Reserve the x9 register (AArch64/RISC-V only) .. option:: -m16 @@ -2499,12 +2589,18 @@ Reserve the 9 register (AArch64/RISC-V only) .. option:: -mabi= +.. option:: -maix-struct-return + +Return all structs in memory (PPC32 only) + .. option:: -malign-branch-boundary= -.. option:: -malign-branch-prefix-size= +Specify the boundary's size to align branches .. option:: -malign-branch=,... +Specify types of branches to align + .. option:: -malign-double Align doubles to two words in structs (x86 only) @@ -2519,12 +2615,14 @@ Link stack frames through backchain on System Z .. option:: -mbranches-within-32B-boundaries +Align selected branches (fused, jcc, jmp) within 32-byte boundary + .. option:: -mcmodel=, -mcmodel=medany (equivalent to -mcmodel=medium), -mcmodel=medlow (equivalent to -mcmodel=small) .. option:: -mconsole .. program:: clang1 -.. option:: -mcpu=, -mv5 (equivalent to -mcpu=hexagonv5), -mv55 (equivalent to -mcpu=hexagonv55), -mv60 (equivalent to -mcpu=hexagonv60), -mv62 (equivalent to -mcpu=hexagonv62), -mv65 (equivalent to -mcpu=hexagonv65), -mv66 (equivalent to -mcpu=hexagonv66) +.. option:: -mcpu=, -mv5 (equivalent to -mcpu=hexagonv5), -mv55 (equivalent to -mcpu=hexagonv55), -mv60 (equivalent to -mcpu=hexagonv60), -mv62 (equivalent to -mcpu=hexagonv62), -mv65 (equivalent to -mcpu=hexagonv65), -mv66 (equivalent to -mcpu=hexagonv66), -mv67 (equivalent to -mcpu=hexagonv67), -mv67t (equivalent to -mcpu=hexagonv67t) .. program:: clang .. option:: -mcrc, -mno-crc @@ -2535,12 +2633,20 @@ Allow use of CRC instructions (ARM/Mips only) .. option:: -mdll +.. option:: -mdouble= + +Force double to be 32 bits or 64 bits + .. option:: -mdynamic-no-pic .. option:: -meabi Set EABI type, e.g. 4, 5 or gnu (default depends on triple) +.. option:: -menable-experimental-extensions + +Enable use of experimental RISC-V extensions. + .. option:: -mfentry Insert calls to fentry at function entry (x86/SystemZ only) @@ -2585,6 +2691,10 @@ Generate branches with extended addressability, usually via indirect jumps. Enable only control-flow mitigations for Load Value Injection (LVI) +.. option:: -mlvi-hardening, -mno-lvi-hardening + +Enable all mitigations for Load Value Injection (LVI) + .. option:: -mmacosx-version-min=, -mmacos-version-min= Set Mac OS X deployment target @@ -2609,6 +2719,10 @@ Omit frame pointer setup for leaf functions Use packed stack layout (SystemZ only). +.. option:: -mpad-max-prefix-size= + +Specify maximum number of prefixes to use for padding + .. option:: -mpie-copy-relocations, -mno-pie-copy-relocations Use copy relocations support for PIE builds @@ -2645,6 +2759,10 @@ Generate a \_\_mcount\_loc section entry for each \_\_fentry\_\_ call. Make StdCall calling convention the default +.. option:: -mseses, -mno-seses + +Enable speculative execution side effect suppression (SESES). Includes LVI control flow integrity mitigations + .. option:: -msign-return-address= Select return address signing scope @@ -2671,6 +2789,10 @@ Set the stack probe size Force realign the stack at entry to every function +.. option:: -msvr4-struct-return + +Return small structs in registers (PPC32 only) + .. option:: -mthread-model The thread model to use, e.g. posix, single (posix by default) @@ -2691,6 +2813,8 @@ Specify bit size of immediate TLS offsets (AArch64 ELF only): 12 (for 4KB) \| 24 .. option:: -mtune= .. program:: clang +Accepted for compatibility with GCC. Currently has no effect. + .. option:: -mtvos-version-min=, -mappletvos-version-min= .. option:: -municode @@ -2775,6 +2899,10 @@ Enable XNACK (AMDGPU only) ARM --- +.. option:: -fAAPCSBitfieldLoad + +Follows the AAPCS standard that all volatile bit-field write generates at least one load. (ARM only). + .. option:: -ffixed-r9 Reserve the r9 register (ARM only) @@ -2949,8 +3077,12 @@ PowerPC .. option:: -mmfocrf, -mmfcrf, -mno-mfocrf +.. option:: -mpcrel, -mno-pcrel + .. option:: -mpopcntd, -mno-popcntd +.. option:: -mpower10-vector, -mno-power10-vector + .. option:: -mpower8-vector, -mno-power8-vector .. option:: -mpower9-vector, -mno-power9-vector @@ -2987,6 +3119,12 @@ WebAssembly .. option:: -munimplemented-simd128, -mno-unimplemented-simd128 +WebAssembly Driver +------------------ +.. option:: -mexec-model= + +Execution model (WebAssembly only) + X86 --- .. option:: -m3dnow, -mno-3dnow @@ -2997,6 +3135,12 @@ X86 .. option:: -maes, -mno-aes +.. option:: -mamx-bf16, -mno-amx-bf16 + +.. option:: -mamx-int8, -mno-amx-int8 + +.. option:: -mamx-tile, -mno-amx-tile + .. option:: -mavx, -mno-avx .. option:: -mavx2, -mno-avx2 @@ -3101,6 +3245,8 @@ X86 .. option:: -msahf, -mno-sahf +.. option:: -mserialize, -mno-serialize + .. option:: -msgx, -mno-sgx .. option:: -msha, -mno-sha @@ -3125,6 +3271,8 @@ X86 .. option:: -mtbm, -mno-tbm +.. option:: -mtsxldtrk, -mno-tsxldtrk + .. option:: -mvaes, -mno-vaes .. option:: -mvpclmulqdq, -mno-vpclmulqdq @@ -3178,7 +3326,7 @@ Optimization level Flags controlling how much optimization should be performed. -.. option:: -O, -O (equivalent to -O2), --optimize, --optimize= +.. option:: -O, -O (equivalent to -O1), --optimize, --optimize= .. option:: -Ofast @@ -3489,7 +3637,7 @@ Pass to the linker .. option:: --hip-device-lib-path= -HIP device library path +HIP device library path. Alternative to rocm-path. .. option:: --hip-device-lib= diff --git a/gnu/llvm/clang/docs/CommandGuide/clang.rst b/gnu/llvm/clang/docs/CommandGuide/clang.rst index 2dfeafd1817..f7f2032e61d 100644 --- a/gnu/llvm/clang/docs/CommandGuide/clang.rst +++ b/gnu/llvm/clang/docs/CommandGuide/clang.rst @@ -1,5 +1,5 @@ -clang - the Clang C, C++, and Objective-C compiler -================================================== +clang, clang++, clang-cpp - the Clang C, C++, and Objective-C compiler +====================================================================== SYNOPSIS -------- @@ -663,4 +663,4 @@ output of the compiler, along with information to reproduce. SEE ALSO -------- -:manpage:`as(1)`, :manpage:`ld(1)` +:manpage:`as(1)`, :manpage:`clang-local(1)`, :manpage:`ld(1)` diff --git a/gnu/llvm/clang/include/clang/AST/FormatString.h b/gnu/llvm/clang/include/clang/AST/FormatString.h index 8c944451f79..231ff6a116e 100644 --- a/gnu/llvm/clang/include/clang/AST/FormatString.h +++ b/gnu/llvm/clang/include/clang/AST/FormatString.h @@ -227,8 +227,10 @@ public: bool isIntArg() const { return (kind >= IntArgBeg && kind <= IntArgEnd) || kind == FreeBSDrArg || kind == FreeBSDyArg; } - bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; } - bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; } + bool isUIntArg() const { return (kind >= UIntArgBeg && kind <= UIntArgEnd) || + kind == FreeBSDbArg; } + bool isAnyIntArg() const { return (kind >= IntArgBeg && kind <= UIntArgEnd) || + kind == FreeBSDbArg; } bool isDoubleArg() const { return kind >= DoubleArgBeg && kind <= DoubleArgEnd; } diff --git a/gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def b/gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def index 776ad6117e0..4c8748829a5 100644 --- a/gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def +++ b/gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def @@ -39,15 +39,15 @@ CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe CODEGENOPT(Backchain , 1, 0) ///< -mbackchain CODEGENOPT(ControlFlowGuardNoChecks , 1, 0) ///< -cfguard-no-checks CODEGENOPT(ControlFlowGuard , 1, 0) ///< -cfguard -CODEGENOPT(CoverageExtraChecksum, 1, 0) ///< Whether we need a second checksum for functions in GCNO files. -CODEGENOPT(CoverageNoFunctionNamesInData, 1, 0) ///< Do not include function names in GCDA files. -CODEGENOPT(CoverageExitBlockBeforeBody, 1, 0) ///< Whether to emit the exit block before the body blocks in GCNO files. CODEGENOPT(CXAAtExit , 1, 1) ///< Use __cxa_atexit for calling destructors. CODEGENOPT(RegisterGlobalDtorsWithAtExit, 1, 1) ///< Use atexit or __cxa_atexit to register global destructors. CODEGENOPT(CXXCtorDtorAliases, 1, 0) ///< Emit complete ctors/dtors as linker ///< aliases to base ctors when possible. CODEGENOPT(DataSections , 1, 0) ///< Set when -fdata-sections is enabled. CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names. +CODEGENOPT(UniqueBasicBlockSectionNames, 1, 1) ///< Set for -funique-basic-block-section-names, + ///< Produce unique section names with + ///< basic block sections. ENUM_CODEGENOPT(FramePointer, FramePointerKind, 2, FramePointerKind::None) /// frame-pointer: all,non-leaf,none CODEGENOPT(DisableFree , 1, 0) ///< Don't free memory. @@ -65,7 +65,8 @@ CODEGENOPT(ExperimentalNewPassManager, 1, 0) ///< Enables the new, experimental CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new ///< pass manager. CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled. -CODEGENOPT(EnableDebugEntryValues, 1, 0) ///< Emit call site parameter dbg info +CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of + ///< '-g' + 'O>0' level. CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs ///< is specified. CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls. @@ -108,6 +109,13 @@ CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0) ///< Set when -fxray-always-emit-typedevents is enabled. CODEGENOPT(XRayAlwaysEmitTypedEvents , 1, 0) +///< Set when -fxray-ignore-loops is enabled. +CODEGENOPT(XRayIgnoreLoops , 1, 0) + +///< Set with -fno-xray-function-index to omit the index section. +CODEGENOPT(XRayOmitFunctionIndex , 1, 0) + + ///< Set the minimum number of instructions in a function to determine selective ///< XRay instrumentation. VALUE_CODEGENOPT(XRayInstructionThreshold , 32, 200) @@ -148,16 +156,11 @@ CODEGENOPT(NoWarn , 1, 0) ///< Set when -Wa,--no-warn is enabled. CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled. CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain ///< inline line tables. +CODEGENOPT(StackClashProtector, 1, 0) ///< Set when -fstack-clash-protection is enabled. CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled. -CODEGENOPT(NoInfsFPMath , 1, 0) ///< Assume FP arguments, results not +-Inf. -CODEGENOPT(NoSignedZeros , 1, 0) ///< Allow ignoring the signedness of FP zero CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is defined. -CODEGENOPT(Reassociate , 1, 0) ///< Allow reassociation of FP math ops -CODEGENOPT(ReciprocalMath , 1, 0) ///< Allow FP divisions to be reassociated. -CODEGENOPT(NoTrappingMath , 1, 0) ///< Set when -fno-trapping-math is enabled. -CODEGENOPT(NoNaNsFPMath , 1, 0) ///< Assume FP arguments, results not NaN. -CODEGENOPT(FlushDenorm , 1, 0) ///< Allow FP denorm numbers to be flushed to zero CODEGENOPT(CorrectlyRoundedDivSqrt, 1, 0) ///< -cl-fp32-correctly-rounded-divide-sqrt +CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names. /// When false, this attempts to generate code as if the result of an /// overflowing conversion matches the overflowing behavior of a target's native @@ -229,6 +232,7 @@ CODEGENOPT(SanitizeCoverageTracePC, 1, 0) ///< Enable PC tracing CODEGENOPT(SanitizeCoverageTracePCGuard, 1, 0) ///< Enable PC tracing with guard ///< in sanitizer coverage. CODEGENOPT(SanitizeCoverageInline8bitCounters, 1, 0) ///< Use inline 8bit counters. +CODEGENOPT(SanitizeCoverageInlineBoolFlag, 1, 0) ///< Use inline bool flag. CODEGENOPT(SanitizeCoveragePCTable, 1, 0) ///< Create a PC Table. CODEGENOPT(SanitizeCoverageNoPrune, 1, 0) ///< Disable coverage pruning. CODEGENOPT(SanitizeCoverageStackDepth, 1, 0) ///< Enable max stack depth tracing @@ -246,7 +250,6 @@ VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500) ///< Minimum time granularity (i CODEGENOPT(UnrollLoops , 1, 0) ///< Control whether loops are unrolled. CODEGENOPT(RerollLoops , 1, 0) ///< Control whether loops are rerolled. CODEGENOPT(NoUseJumpTables , 1, 0) ///< Set when -fno-jump-tables is enabled. -CODEGENOPT(UnsafeFPMath , 1, 0) ///< Allow unsafe floating point optzns. CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer. CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer. @@ -303,6 +306,9 @@ CODEGENOPT(LTOVisibilityPublicStd, 1, 0) /// or 0 if unspecified. VALUE_CODEGENOPT(NumRegisterParameters, 32, 0) +/// The threshold to put data into small data section. +VALUE_CODEGENOPT(SmallDataLimit, 32, 0) + /// The lower bound for a buffer to be considered for stack protection. VALUE_CODEGENOPT(SSPBufferSize, 32, 0) @@ -383,14 +389,12 @@ CODEGENOPT(ForceEmitVTables, 1, 0) /// Whether to emit an address-significance table into the object file. CODEGENOPT(Addrsig, 1, 0) -ENUM_CODEGENOPT(SignReturnAddress, SignReturnAddressScope, 2, SignReturnAddressScope::None) -ENUM_CODEGENOPT(SignReturnAddressKey, SignReturnAddressKeyValue, 1, SignReturnAddressKeyValue::AKey) -CODEGENOPT(BranchTargetEnforcement, 1, 0) - /// Whether to emit unused static constants. CODEGENOPT(KeepStaticConsts, 1, 0) +/// Whether to not follow the AAPCS that enforce at least one read before storing to a volatile bitfield +CODEGENOPT(ForceAAPCSBitfieldLoad, 1, 0) + #undef CODEGENOPT #undef ENUM_CODEGENOPT #undef VALUE_CODEGENOPT - diff --git a/gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td index e46069a3204..b202d2abffa 100644 --- a/gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -67,6 +67,7 @@ def note_fe_backend_invalid_loc : Note<"could " "not determine the original source location for %0:%1:%2">, BackendInfo; def err_fe_backend_unsupported : Error<"%0">, BackendInfo; +def warn_fe_backend_unsupported : Warning<"%0">, BackendInfo; def err_fe_invalid_code_complete_file : Error< "cannot locate code-completion file %0">, DefaultFatal; @@ -115,12 +116,18 @@ def warn_fe_concepts_ts_flag : Warning< "-fconcepts-ts is deprecated - use '-std=c++20' for Concepts support">, InGroup; +def err_fe_unable_to_load_basic_block_sections_file : Error< + "unable to load basic block sections function list: '%0'">; + def warn_fe_serialized_diag_merge_failure : Warning< "unable to merge a subprocess's serialized diagnostics">, InGroup; def warn_fe_serialized_diag_failure : Warning< "unable to open file %0 for serializing diagnostics (%1)">, InGroup; +def warn_fe_serialized_diag_failure_during_finalisation : Warning< + "Received warning after diagnostic serialization teardown was underway: %0">, + InGroup; def err_verify_missing_line : Error< "missing or invalid line number following '@' in expected %0">; @@ -242,6 +249,12 @@ def err_function_needs_feature : Error< "always_inline function %1 requires target feature '%2', but would " "be inlined into function %0 that is compiled without support for '%2'">; +def warn_avx_calling_convention + : Warning<"AVX vector %select{return|argument}0 of type %1 without '%2' " + "enabled changes the ABI">, + InGroup>; +def err_avx_calling_convention : Error; + def err_alias_to_undefined : Error< "%select{alias|ifunc}0 must point to a defined " "%select{variable or |}1function">; diff --git a/gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td b/gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td index e4233c85043..1e829be4028 100644 --- a/gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td +++ b/gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td @@ -60,6 +60,7 @@ def UndefinedBoolConversion : DiagGroup<"undefined-bool-conversion">; def BoolConversion : DiagGroup<"bool-conversion", [PointerBoolConversion, UndefinedBoolConversion]>; def IntConversion : DiagGroup<"int-conversion">; +def ClassConversion: DiagGroup<"class-conversion">; def DeprecatedEnumCompareConditional : DiagGroup<"deprecated-enum-compare-conditional">; def EnumCompareConditional : DiagGroup<"enum-compare-conditional", @@ -85,7 +86,9 @@ def ObjCSignedCharBoolImplicitIntConversion : DiagGroup<"objc-signed-char-bool-implicit-int-conversion">; def ImplicitIntConversion : DiagGroup<"implicit-int-conversion", [ObjCSignedCharBoolImplicitIntConversion]>; -def ImplicitIntFloatConversion : DiagGroup<"implicit-int-float-conversion">; +def ImplicitConstIntFloatConversion : DiagGroup<"implicit-const-int-float-conversion">; +def ImplicitIntFloatConversion : DiagGroup<"implicit-int-float-conversion", + [ImplicitConstIntFloatConversion]>; def ObjCSignedCharBoolImplicitFloatConversion : DiagGroup<"objc-signed-char-bool-implicit-float-conversion">; def ImplicitFloatConversion : DiagGroup<"implicit-float-conversion", @@ -99,6 +102,7 @@ def FloatConversion : DiagGroup<"float-conversion", [FloatOverflowConversion, FloatZeroConversion]>; +def FrameAddress : DiagGroup<"frame-address">; def DoublePromotion : DiagGroup<"double-promotion">; def EnumTooLarge : DiagGroup<"enum-too-large">; def UnsupportedNan : DiagGroup<"unsupported-nan">; @@ -193,6 +197,7 @@ def CXX20Designator : DiagGroup<"c++20-designator">; // designators (including the warning controlled by -Wc++20-designator). def C99Designator : DiagGroup<"c99-designator", [CXX20Designator]>; def GNUDesignator : DiagGroup<"gnu-designator">; +def DtorName : DiagGroup<"dtor-name">; def DynamicExceptionSpec : DiagGroup<"dynamic-exception-spec", [DeprecatedDynamicExceptionSpec]>; @@ -275,9 +280,12 @@ def CXX98CompatPedantic : DiagGroup<"c++98-compat-pedantic", def CXX11Narrowing : DiagGroup<"c++11-narrowing">; -def CXX11WarnOverrideDestructor : +def CXX11WarnInconsistentOverrideDestructor : DiagGroup<"inconsistent-missing-destructor-override">; -def CXX11WarnOverrideMethod : DiagGroup<"inconsistent-missing-override">; +def CXX11WarnInconsistentOverrideMethod : + DiagGroup<"inconsistent-missing-override">; +def CXX11WarnSuggestOverrideDestructor : DiagGroup<"suggest-destructor-override">; +def CXX11WarnSuggestOverride : DiagGroup<"suggest-override">; // Original name of this warning in Clang def : DiagGroup<"c++0x-narrowing", [CXX11Narrowing]>; @@ -347,6 +355,7 @@ def Dangling : DiagGroup<"dangling", [DanglingField, DanglingGsl, ReturnStackAddress]>; def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; +def ExcessInitializers : DiagGroup<"excess-initializers">; def ExpansionToDefined : DiagGroup<"expansion-to-defined">; def FlagEnum : DiagGroup<"flag-enum">; def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>; @@ -377,6 +386,8 @@ def IncompleteModule : DiagGroup<"incomplete-module", def PrivateModule : DiagGroup<"private-module">; def CXX11InlineNamespace : DiagGroup<"c++11-inline-namespace">; +def InlineNamespaceReopenedNoninline + : DiagGroup<"inline-namespace-reopened-noninline">; def InvalidNoreturn : DiagGroup<"invalid-noreturn">; def InvalidSourceEncoding : DiagGroup<"invalid-source-encoding">; def KNRPromotedParameter : DiagGroup<"knr-promoted-parameter">; @@ -620,8 +631,10 @@ def Unicode : DiagGroup<"unicode">; def UninitializedMaybe : DiagGroup<"conditional-uninitialized">; def UninitializedSometimes : DiagGroup<"sometimes-uninitialized">; def UninitializedStaticSelfInit : DiagGroup<"static-self-init">; +def UninitializedConstReference : DiagGroup<"uninitialized-const-reference">; def Uninitialized : DiagGroup<"uninitialized", [UninitializedSometimes, - UninitializedStaticSelfInit]>; + UninitializedStaticSelfInit, + UninitializedConstReference]>; def IgnoredPragmaIntrinsic : DiagGroup<"ignored-pragma-intrinsic">; // #pragma optimize is often used to avoid to work around MSVC codegen bugs or // to disable inlining. It's not completely clear what alternative to suggest @@ -838,6 +851,13 @@ def IncompatibleExceptionSpec : DiagGroup<"incompatible-exception-spec">; def IntToVoidPointerCast : DiagGroup<"int-to-void-pointer-cast">; def IntToPointerCast : DiagGroup<"int-to-pointer-cast", [IntToVoidPointerCast]>; +def VoidPointerToEnumCast : DiagGroup<"void-pointer-to-enum-cast">; +def VoidPointerToIntCast : DiagGroup<"void-pointer-to-int-cast", + [VoidPointerToEnumCast]>; +def PointerToEnumCast : DiagGroup<"pointer-to-enum-cast", + [VoidPointerToEnumCast]>; +def PointerToIntCast : DiagGroup<"pointer-to-int-cast", + [PointerToEnumCast, VoidPointerToIntCast]>; def Move : DiagGroup<"move", [ PessimizingMove, @@ -865,6 +885,7 @@ def Most : DiagGroup<"most", [ DeleteNonVirtualDtor, Format, ForLoopAnalysis, + FrameAddress, Implicit, InfiniteRecursion, IntInBoolContext, @@ -976,6 +997,9 @@ def C11 : DiagGroup<"c11-extensions">; // A warning group for warnings about using C99 features as extensions. def C99 : DiagGroup<"c99-extensions", [C99Designator]>; +// A warning group for warnings about using C2x features as extensions. +def C2x : DiagGroup<"c2x-extensions">; + // A warning group for warnings about GCC extensions. def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType, @@ -1079,11 +1103,15 @@ def ObjCSignedCharBool : DiagGroup<"objc-signed-char-bool", ObjCBoolConstantConversion, TautologicalObjCBoolCompare]>; +def ObjCPotentiallyDirectSelector : DiagGroup<"potentially-direct-selector">; +def ObjCStrictPotentiallyDirectSelector : + DiagGroup<"strict-potentially-direct-selector", + [ObjCPotentiallyDirectSelector]>; + // Inline ASM warnings. def ASMOperandWidths : DiagGroup<"asm-operand-widths">; -def ASMIgnoredQualifier : DiagGroup<"asm-ignored-qualifier">; def ASM : DiagGroup<"asm", [ - ASMOperandWidths, ASMIgnoredQualifier + ASMOperandWidths ]>; // OpenMP warnings. @@ -1146,8 +1174,8 @@ def UnknownArgument : DiagGroup<"unknown-argument">; // compiling OpenCL C/C++ but which is not compatible with the SPIR spec. def SpirCompat : DiagGroup<"spir-compat">; -// Warning for the experimental-isel options. -def ExperimentalISel : DiagGroup<"experimental-isel">; +// Warning for the GlobalISel options. +def GlobalISel : DiagGroup<"global-isel">; // A warning group specifically for warnings related to function // multiversioning. @@ -1161,3 +1189,37 @@ def CrossTU : DiagGroup<"ctu">; def CTADMaybeUnsupported : DiagGroup<"ctad-maybe-unsupported">; def FortifySource : DiagGroup<"fortify-source">; + +def MaxTokens : DiagGroup<"max-tokens"> { + code Documentation = [{ +The warning is issued if the number of pre-processor tokens exceeds +the token limit, which can be set in three ways: + +1. As a limit at a specific point in a file, using the ``clang max_tokens_here`` + pragma: + + .. code-block: c++ + #pragma clang max_tokens_here 1234 + +2. As a per-translation unit limit, using the ``-fmax-tokens=`` command-line + flag: + + .. code-block: console + clang -c a.cpp -fmax-tokens=1234 + +3. As a per-translation unit limit using the ``clang max_tokens_total`` pragma, + which works like and overrides the ``-fmax-tokens=`` flag: + + .. code-block: c++ + #pragma clang max_tokens_total 1234 + +These limits can be helpful in limiting code growth through included files. + +Setting a token limit of zero means no limit. + +Note that the warning is disabled by default, so -Wmax-tokens must be used +in addition with the pragmas or -fmax-tokens flag to get any warnings. +}]; +} + +def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">; diff --git a/gnu/llvm/clang/include/clang/Basic/DiagnosticSemaKinds.td b/gnu/llvm/clang/include/clang/Basic/DiagnosticSemaKinds.td index 941f2cafc37..cd23dd38ca2 100644 --- a/gnu/llvm/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/gnu/llvm/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6440,7 +6440,7 @@ def warn_pointer_indirection_from_incompatible_type : Warning< InGroup, DefaultIgnore; def warn_taking_address_of_packed_member : Warning< "taking address of packed member %0 of class or structure %q1 may result in an unaligned pointer value">, - InGroup>; + InGroup>, DefaultIgnore; def err_objc_object_assignment : Error< "cannot assign to class object (%0 invalid)">; @@ -7607,7 +7607,7 @@ def ext_typecheck_convert_incompatible_pointer_sign : ExtWarn< "sending to parameter of different type}0,1" "|%diff{casting $ to type $|casting between types}0,1}2" " converts between pointers to integer types with different sign">, - InGroup>; + InGroup>, DefaultIgnore; def err_typecheck_convert_incompatible_pointer_sign : Error< "%select{%diff{assigning to $ from $|assigning to different types}0,1" "|%diff{passing $ to parameter of type $|" diff --git a/gnu/llvm/clang/include/clang/Basic/LangOptions.def b/gnu/llvm/clang/include/clang/Basic/LangOptions.def index 42f759322ab..70f68d664bb 100644 --- a/gnu/llvm/clang/include/clang/Basic/LangOptions.def +++ b/gnu/llvm/clang/include/clang/Basic/LangOptions.def @@ -91,7 +91,7 @@ LANGOPT(CPlusPlus , 1, 0, "C++") LANGOPT(CPlusPlus11 , 1, 0, "C++11") LANGOPT(CPlusPlus14 , 1, 0, "C++14") LANGOPT(CPlusPlus17 , 1, 0, "C++17") -LANGOPT(CPlusPlus2a , 1, 0, "C++2a") +LANGOPT(CPlusPlus20 , 1, 0, "C++20") LANGOPT(ObjC , 1, 0, "Objective-C") BENIGN_LANGOPT(ObjCDefaultSynthProperties , 1, 0, "Objective-C auto-synthesized properties") @@ -132,6 +132,7 @@ LANGOPT(DWARFExceptions , 1, 0, "dwarf exception handling") LANGOPT(SjLjExceptions , 1, 0, "setjmp-longjump exception handling") LANGOPT(SEHExceptions , 1, 0, "SEH .xdata exception handling") LANGOPT(WasmExceptions , 1, 0, "WebAssembly exception handling") +LANGOPT(IgnoreExceptions , 1, 0, "ignore exceptions") LANGOPT(ExternCNoUnwind , 1, 0, "Assume extern C functions don't unwind") LANGOPT(TraditionalCPP , 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") @@ -147,6 +148,9 @@ LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template t LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes") +COMPATIBLE_LANGOPT(RecoveryAST, 1, 0, "Preserve expressions in AST when encountering errors") +COMPATIBLE_LANGOPT(RecoveryASTType, 1, 0, "Preserve the type in recovery expressions") + BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers") LANGOPT(POSIXThreads , 1, 0, "POSIX thread support") LANGOPT(Blocks , 1, 0, "blocks extension to C") @@ -161,6 +165,7 @@ BENIGN_ENUM_LANGOPT(CompilingModule, CompilingModuleKind, 2, CMK_None, BENIGN_LANGOPT(CompilingPCH, 1, 0, "building a pch") BENIGN_LANGOPT(BuildingPCHWithObjectFile, 1, 0, "building a pch which has a corresponding object file") BENIGN_LANGOPT(CacheGeneratedPCH, 1, 0, "cache generated PCH files in memory") +BENIGN_LANGOPT(PCHInstantiateTemplates, 1, 0, "instantiate templates while building a PCH") COMPATIBLE_LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module uses") BENIGN_LANGOPT(ModulesSearchAll , 1, 1, "searching even non-imported modules to find unresolved references") COMPATIBLE_LANGOPT(ModulesStrictDeclUse, 1, 0, "requiring declaration of module uses and all headers to be in modules") @@ -175,6 +180,7 @@ VALUE_LANGOPT(PackStruct , 32, 0, VALUE_LANGOPT(MaxTypeAlign , 32, 0, "default maximum alignment for types") VALUE_LANGOPT(AlignDouble , 1, 0, "Controls if doubles should be aligned to 8 bytes (x86 only)") +VALUE_LANGOPT(DoubleSize , 32, 0, "width of double") VALUE_LANGOPT(LongDoubleSize , 32, 0, "width of long double") LANGOPT(PPCIEEELongDouble , 1, 0, "use IEEE 754 quadruple-precision for long double") COMPATIBLE_VALUE_LANGOPT(PICLevel , 2, 0, "__PIC__ level") @@ -187,6 +193,12 @@ COMPATIBLE_LANGOPT(Deprecated , 1, 0, "__DEPRECATED predefined macro") COMPATIBLE_LANGOPT(FastMath , 1, 0, "fast FP math optimizations, and __FAST_MATH__ predefined macro") COMPATIBLE_LANGOPT(FiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined macro") COMPATIBLE_LANGOPT(UnsafeFPMath , 1, 0, "Unsafe Floating Point Math") +BENIGN_LANGOPT(AllowFPReassoc , 1, 0, "Permit Floating Point reassociation") +BENIGN_LANGOPT(NoHonorNaNs , 1, 0, "Permit Floating Point optimization without regard to NaN") +BENIGN_LANGOPT(NoHonorInfs , 1, 0, "Permit Floating Point optimization without regard to infinities") +BENIGN_LANGOPT(NoSignedZero , 1, 0, "Permit Floating Point optimization without regard to signed zeros") +BENIGN_LANGOPT(AllowRecip , 1, 0, "Permit Floating Point reciprocal") +BENIGN_LANGOPT(ApproxFunc , 1, 0, "Permit Floating Point approximation") BENIGN_LANGOPT(ObjCGCBitmapPrint , 1, 0, "printing of GC's bitmap layout for __weak/__strong ivars") @@ -219,6 +231,7 @@ LANGOPT(OpenMPCUDANumSMs , 32, 0, "Number of SMs for CUDA devices.") LANGOPT(OpenMPCUDABlocksPerSM , 32, 0, "Number of blocks per SM for CUDA devices.") LANGOPT(OpenMPCUDAReductionBufNum , 32, 1024, "Number of the reduction records in the intermediate reduction buffer used for the teams reductions.") LANGOPT(OpenMPOptimisticCollapse , 1, 0, "Use at most 32 bits to represent the collapsed loop nest counter.") +LANGOPT(OpenMPCUDATargetParallel, 1, 0, "Support parallel execution of target region on Cuda-based devices.") LANGOPT(RenderScript , 1, 0, "RenderScript") LANGOPT(CUDAIsDevice , 1, 0, "compiling for CUDA device") @@ -227,9 +240,11 @@ LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating unattributed constexpr function LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate transcendental functions") LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code") LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions for HIP") -LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for kernel launch bounds for HIP") +LANGOPT(GPUMaxThreadsPerBlock, 32, 1024, "default max threads per block for kernel launch bounds for HIP") +LANGOPT(SYCL , 1, 0, "SYCL") LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device") +LANGOPT(SYCLVersion , 32, 0, "Version of the SYCL standard used") LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP") @@ -237,7 +252,7 @@ LANGOPT(SizedDeallocation , 1, 0, "sized deallocation") LANGOPT(AlignedAllocation , 1, 0, "aligned allocation") LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are unavailable") LANGOPT(NewAlignOverride , 32, 0, "maximum alignment guaranteed by '::operator new(size_t)'") -LANGOPT(ConceptSatisfactionCaching , 1, 1, "enable satisfaction caching for C++2a Concepts") +LANGOPT(ConceptSatisfactionCaching , 1, 1, "enable satisfaction caching for C++20 Concepts") BENIGN_LANGOPT(ModulesCodegen , 1, 0, "Modules code generation") BENIGN_LANGOPT(ModulesDebugInfo , 1, 0, "Modules debug info") BENIGN_LANGOPT(ElideConstructors , 1, 1, "C++ copy constructor elision") @@ -256,16 +271,19 @@ BENIGN_LANGOPT(SpellChecking , 1, 1, "spell-checking") LANGOPT(SinglePrecisionConstants , 1, 0, "treating double-precision floating point constants as single precision constants") LANGOPT(FastRelaxedMath , 1, 0, "OpenCL fast relaxed math") /// FP_CONTRACT mode (on/off/fast). -ENUM_LANGOPT(DefaultFPContractMode, FPContractModeKind, 2, FPC_Off, "FP contraction type") +BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contraction type") COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point") -ENUM_LANGOPT(FPRoundingMode, FPRoundingModeKind, 3, FPR_ToNearest, "FP Rounding Mode type") -ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Ignore, "FP Exception Behavior Mode type") +BENIGN_ENUM_LANGOPT(FPRoundingMode, RoundingMode, 3, RoundingMode::NearestTiesToEven, "FP Rounding Mode type") +BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Ignore, "FP Exception Behavior Mode type") LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment") LANGOPT(HexagonQdsp6Compat , 1, 0, "hexagon-qdsp6 backward compatibility") LANGOPT(ObjCAutoRefCount , 1, 0, "Objective-C automated reference counting") LANGOPT(ObjCWeakRuntime , 1, 0, "__weak support in the ARC runtime") LANGOPT(ObjCWeak , 1, 0, "Objective-C __weak in ARC and MRC files") LANGOPT(ObjCSubscriptingLegacyRuntime , 1, 0, "Subscripting support in legacy ObjectiveC runtime") +BENIGN_LANGOPT(CompatibilityQualifiedIdBlockParamTypeChecking, 1, 0, + "compatibility mode for type checking block parameters " + "involving qualified id types") LANGOPT(CFProtectionBranch , 1, 0, "Control-Flow Branch Protection enabled") LANGOPT(FakeAddressSpaceMap , 1, 0, "OpenCL fake address space map") ENUM_LANGOPT(AddressSpaceMapMangling , AddrSpaceMapMangling, 2, ASMM_Target, "OpenCL address space map mangling mode") @@ -285,10 +303,14 @@ ENUM_LANGOPT(TypeVisibilityMode, Visibility, 3, DefaultVisibility, "default visibility for types [-ftype-visibility]") LANGOPT(SetVisibilityForExternDecls, 1, 0, "apply global symbol visibility to external declarations without an explicit visibility") +BENIGN_LANGOPT(SemanticInterposition , 1, 0, "semantic interposition") +BENIGN_LANGOPT(ExplicitNoSemanticInterposition, 1, 0, "explicitly no semantic interposition") ENUM_LANGOPT(StackProtector, StackProtectorMode, 2, SSPOff, "stack protector mode") ENUM_LANGOPT(TrivialAutoVarInit, TrivialAutoVarInitKind, 2, TrivialAutoVarInitKind::Uninitialized, "trivial automatic variable initialization") +VALUE_LANGOPT(TrivialAutoVarInitStopAfter, 32, 0, + "stop trivial automatic variable initialization after the specified number of instances. Must be greater than 0.") ENUM_LANGOPT(SignedOverflowBehavior, SignedOverflowBehaviorTy, 2, SOB_Undefined, "signed integer overflow handling") @@ -345,6 +367,21 @@ LANGOPT(PaddingOnUnsignedFixedPoint, 1, 0, LANGOPT(RegisterStaticDestructors, 1, 1, "Register C++ static destructors") +LANGOPT(MatrixTypes, 1, 0, "Enable or disable the builtin matrix type") + +COMPATIBLE_VALUE_LANGOPT(MaxTokens, 32, 0, "Max number of tokens per TU or 0") + +ENUM_LANGOPT(SignReturnAddressScope, SignReturnAddressScopeKind, 2, SignReturnAddressScopeKind::None, + "Scope of return address signing") +ENUM_LANGOPT(SignReturnAddressKey, SignReturnAddressKeyKind, 1, SignReturnAddressKeyKind::AKey, + "Key used for return address signing") +LANGOPT(BranchTargetEnforcement, 1, 0, "Branch-target enforcement enabled") + +LANGOPT(SpeculativeLoadHardening, 1, 0, "Speculative load hardening enabled") + +LANGOPT(RelativeCXXABIVTables, 1, 0, + "Use an ABI-incompatible v-table layout that uses relative references") + #undef LANGOPT #undef COMPATIBLE_LANGOPT #undef BENIGN_LANGOPT diff --git a/gnu/llvm/clang/include/clang/Basic/TargetInfo.h b/gnu/llvm/clang/include/clang/Basic/TargetInfo.h index 6a6804a21ca..2ee3b165963 100644 --- a/gnu/llvm/clang/include/clang/Basic/TargetInfo.h +++ b/gnu/llvm/clang/include/clang/Basic/TargetInfo.h @@ -15,8 +15,9 @@ #define LLVM_CLANG_BASIC_TARGETINFO_H #include "clang/Basic/AddressSpaces.h" -#include "clang/Basic/LLVM.h" #include "clang/Basic/CodeGenOptions.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" #include "clang/Basic/Specifiers.h" #include "clang/Basic/TargetCXXABI.h" #include "clang/Basic/TargetOptions.h" @@ -29,6 +30,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" +#include "llvm/Frontend/OpenMP/OMPGridValues.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/VersionTuple.h" #include @@ -59,6 +61,7 @@ struct TransferrableTargetInfo { unsigned char BoolWidth, BoolAlign; unsigned char IntWidth, IntAlign; unsigned char HalfWidth, HalfAlign; + unsigned char BFloat16Width, BFloat16Align; unsigned char FloatWidth, FloatAlign; unsigned char DoubleWidth, DoubleAlign; unsigned char LongDoubleWidth, LongDoubleAlign, Float128Align; @@ -100,8 +103,8 @@ struct TransferrableTargetInfo { unsigned short MaxVectorAlign; unsigned short MaxTLSAlign; - const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat, - *LongDoubleFormat, *Float128Format; + const llvm::fltSemantics *HalfFormat, *BFloat16Format, *FloatFormat, + *DoubleFormat, *LongDoubleFormat, *Float128Format; ///===---- Target Data Type Query Methods -------------------------------===// enum IntType { @@ -159,6 +162,18 @@ protected: unsigned ZeroLengthBitfieldBoundary; }; +/// OpenCL type kinds. +enum OpenCLTypeKind : uint8_t { + OCLTK_Default, + OCLTK_ClkEvent, + OCLTK_Event, + OCLTK_Image, + OCLTK_Pipe, + OCLTK_Queue, + OCLTK_ReserveID, + OCLTK_Sampler, +}; + /// Exposes information about the current target. /// class TargetInfo : public virtual TransferrableTargetInfo, @@ -176,6 +191,7 @@ protected: // LLVM IR type. bool HasFloat128; bool HasFloat16; + bool HasBFloat16; bool HasStrictFP; unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth; @@ -185,6 +201,9 @@ protected: unsigned char RegParmMax, SSERegParmMax; TargetCXXABI TheCXXABI; const LangASMap *AddrSpaceMap; + const unsigned *GridValues = + nullptr; // Array of target-specific GPU grid values that must be + // consistent between host RTL (plugin), device RTL, and clang. mutable StringRef PlatformName; mutable VersionTuple PlatformMinVersion; @@ -199,6 +218,10 @@ protected: unsigned HasAArch64SVETypes : 1; + unsigned ARMCDECoprocMask : 8; + + unsigned MaxOpenCLWorkGroupSize; + // TargetInfo Constructor. Default initializes all fields. TargetInfo(const llvm::Triple &T); @@ -260,7 +283,14 @@ public: // void *__overflow_arg_area; // void *__reg_save_area; // } va_list[1]; - SystemZBuiltinVaList + SystemZBuiltinVaList, + + // typedef struct __va_list_tag { + // void *__current_saved_reg_area_pointer; + // void *__saved_reg_area_end_pointer; + // void *__overflow_area_pointer; + //} va_list; + HexagonBuiltinVaList }; protected: @@ -346,8 +376,13 @@ public: virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const; - /// Return floating point type with specified width. - RealType getRealTypeByWidth(unsigned BitWidth) const; + /// Return floating point type with specified width. On PPC, there are + /// three possible types for 128-bit floating point: "PPC double-double", + /// IEEE 754R quad precision, and "long double" (which under the covers + /// is represented as one of those two). At this time, there is no support + /// for an explicit "PPC double-double" type (i.e. __ibm128) so we only + /// need to differentiate between "long double" and IEEE quad precision. + RealType getRealTypeByWidth(unsigned BitWidth, bool ExplicitIEEE) const; /// Return the alignment (in bits) of the specified integer type enum. /// @@ -525,6 +560,12 @@ public: return (getPointerWidth(0) >= 64) || getTargetOpts().ForceEnableInt128; } // FIXME + /// Determine whether the _ExtInt type is supported on this target. This + /// limitation is put into place for ABI reasons. + virtual bool hasExtIntType() const { + return false; + } + /// Determine whether _Float16 is supported on this target. virtual bool hasLegalHalfType() const { return HasLegalHalfType; } @@ -534,6 +575,9 @@ public: /// Determine whether the _Float16 type is supported on this target. virtual bool hasFloat16Type() const { return HasFloat16; } + /// Determine whether the _BFloat16 type is supported on this target. + virtual bool hasBFloat16Type() const { return HasBFloat16; } + /// Determine whether constrained floating point is supported on this target. virtual bool hasStrictFP() const { return HasStrictFP; } @@ -585,6 +629,11 @@ public: unsigned getFloatAlign() const { return FloatAlign; } const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; } + /// getBFloat16Width/Align/Format - Return the size/align/format of '__bf16'. + unsigned getBFloat16Width() const { return BFloat16Width; } + unsigned getBFloat16Align() const { return BFloat16Align; } + const llvm::fltSemantics &getBFloat16Format() const { return *BFloat16Format; } + /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'. unsigned getDoubleWidth() const { return DoubleWidth; } unsigned getDoubleAlign() const { return DoubleAlign; } @@ -612,6 +661,11 @@ public: /// Return the mangled code of __float128. virtual const char *getFloat128Mangling() const { return "g"; } + /// Return the mangled code of bfloat. + virtual const char *getBFloat16Mangling() const { + llvm_unreachable("bfloat not implemented on this target"); + } + /// Return the value for the C99 FLT_EVAL_METHOD macro. virtual unsigned getFloatEvalMethod() const { return 0; } @@ -646,6 +700,8 @@ public: /// types for the given target. unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; } + unsigned getMaxOpenCLWorkGroupSize() const { return MaxOpenCLWorkGroupSize; } + /// Return the alignment (in bits) of the thrown exception object. This is /// only meaningful for targets that allocate C++ exceptions in a system /// runtime, such as those using the Itanium C++ ABI. @@ -800,6 +856,10 @@ public: /// available on this target. bool hasAArch64SVETypes() const { return HasAArch64SVETypes; } + /// For ARM targets returns a mask defining which coprocessors are configured + /// as Custom Datapath. + uint32_t getARMCDECoprocMask() const { return ARMCDECoprocMask; } + /// Returns whether the passed in string is a valid clobber in an /// inline asm statement. /// @@ -820,6 +880,8 @@ public: StringRef getNormalizedGCCRegisterName(StringRef Name, bool ReturnCanonical = false) const; + virtual bool isSPRegName(StringRef) const { return false; } + /// Extracts a register from the passed constraint (if it is a /// single-register constraint) and the asm label expression related to a /// variable in the input or output list of an inline asm statement. @@ -1111,10 +1173,10 @@ public: } struct BranchProtectionInfo { - CodeGenOptions::SignReturnAddressScope SignReturnAddr = - CodeGenOptions::SignReturnAddressScope::None; - CodeGenOptions::SignReturnAddressKeyValue SignKey = - CodeGenOptions::SignReturnAddressKeyValue::AKey; + LangOptions::SignReturnAddressScopeKind SignReturnAddr = + LangOptions::SignReturnAddressScopeKind::None; + LangOptions::SignReturnAddressKeyKind SignKey = + LangOptions::SignReturnAddressKeyKind::AKey; bool BranchTargetEnforcement = false; }; @@ -1190,6 +1252,10 @@ public: "cpu_specific Multiversioning not implemented on this target"); } + // Get the cache line size of a given cpu. This method switches over + // the given cpu and returns "None" if the CPU is not found. + virtual Optional getCPUCacheLineSize() const { return None; } + // Returns maximal number of args passed in registers. unsigned getRegParmMax() const { assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle"); @@ -1264,6 +1330,12 @@ public: return LangAS::Default; } + /// Return a target-specific GPU grid value based on the GVIDX enum \p gv + unsigned getGridValue(llvm::omp::GVIDX gv) const { + assert(GridValues != nullptr && "GridValues not initialized"); + return GridValues[gv]; + } + /// Retrieve the name of the platform as it is used in the /// availability attribute. StringRef getPlatformName() const { return PlatformName; } @@ -1349,17 +1421,6 @@ public: return getTargetOpts().SupportedOpenCLOptions; } - enum OpenCLTypeKind { - OCLTK_Default, - OCLTK_ClkEvent, - OCLTK_Event, - OCLTK_Image, - OCLTK_Pipe, - OCLTK_Queue, - OCLTK_ReserveID, - OCLTK_Sampler, - }; - /// Get address space for OpenCL type. virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const; diff --git a/gnu/llvm/clang/include/clang/Driver/CC1Options.td b/gnu/llvm/clang/include/clang/Driver/CC1Options.td deleted file mode 100644 index 275a33823de..00000000000 --- a/gnu/llvm/clang/include/clang/Driver/CC1Options.td +++ /dev/null @@ -1,933 +0,0 @@ -//===--- CC1Options.td - Options for clang -cc1 ---------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file defines the options accepted by clang -cc1 and clang -cc1as. -// -//===----------------------------------------------------------------------===// - -let Flags = [CC1Option, NoDriverOption] in { - -//===----------------------------------------------------------------------===// -// Target Options -//===----------------------------------------------------------------------===// - -let Flags = [CC1Option, CC1AsOption, NoDriverOption] in { - -def target_cpu : Separate<["-"], "target-cpu">, - HelpText<"Target a specific cpu type">; -def target_feature : Separate<["-"], "target-feature">, - HelpText<"Target specific attributes">; -def triple : Separate<["-"], "triple">, - HelpText<"Specify target triple (e.g. i686-apple-darwin9)">; -def target_abi : Separate<["-"], "target-abi">, - HelpText<"Target a particular ABI type">; -def target_sdk_version_EQ : Joined<["-"], "target-sdk-version=">, - HelpText<"The version of target SDK used for compilation">; - -} - -def target_linker_version : Separate<["-"], "target-linker-version">, - HelpText<"Target linker version">; -def triple_EQ : Joined<["-"], "triple=">, Alias; -def mfpmath : Separate<["-"], "mfpmath">, - HelpText<"Which unit to use for fp math">; - -def fpadding_on_unsigned_fixed_point : Flag<["-"], "fpadding-on-unsigned-fixed-point">, - HelpText<"Force each unsigned fixed point type to have an extra bit of padding to align their scales with those of signed fixed point types">; -def fno_padding_on_unsigned_fixed_point : Flag<["-"], "fno-padding-on-unsigned-fixed-point">; - -//===----------------------------------------------------------------------===// -// Analyzer Options -//===----------------------------------------------------------------------===// - -def analysis_UnoptimizedCFG : Flag<["-"], "unoptimized-cfg">, - HelpText<"Generate unoptimized CFGs for all analyses">; -def analysis_CFGAddImplicitDtors : Flag<["-"], "cfg-add-implicit-dtors">, - HelpText<"Add C++ implicit destructors to CFGs for all analyses">; - -def analyzer_store : Separate<["-"], "analyzer-store">, - HelpText<"Source Code Analysis - Abstract Memory Store Models">; -def analyzer_store_EQ : Joined<["-"], "analyzer-store=">, Alias; - -def analyzer_constraints : Separate<["-"], "analyzer-constraints">, - HelpText<"Source Code Analysis - Symbolic Constraint Engines">; -def analyzer_constraints_EQ : Joined<["-"], "analyzer-constraints=">, - Alias; - -def analyzer_output : Separate<["-"], "analyzer-output">, - HelpText<"Source Code Analysis - Output Options">; -def analyzer_output_EQ : Joined<["-"], "analyzer-output=">, - Alias; - -def analyzer_purge : Separate<["-"], "analyzer-purge">, - HelpText<"Source Code Analysis - Dead Symbol Removal Frequency">; -def analyzer_purge_EQ : Joined<["-"], "analyzer-purge=">, Alias; - -def analyzer_opt_analyze_headers : Flag<["-"], "analyzer-opt-analyze-headers">, - HelpText<"Force the static analyzer to analyze functions defined in header files">; -def analyzer_opt_analyze_nested_blocks : Flag<["-"], "analyzer-opt-analyze-nested-blocks">, - HelpText<"Analyze the definitions of blocks in addition to functions">; -def analyzer_display_progress : Flag<["-"], "analyzer-display-progress">, - HelpText<"Emit verbose output about the analyzer's progress">; -def analyze_function : Separate<["-"], "analyze-function">, - HelpText<"Run analysis on specific function (for C++ include parameters in name)">; -def analyze_function_EQ : Joined<["-"], "analyze-function=">, Alias; -def trim_egraph : Flag<["-"], "trim-egraph">, - HelpText<"Only show error-related paths in the analysis graph">; -def analyzer_viz_egraph_graphviz : Flag<["-"], "analyzer-viz-egraph-graphviz">, - HelpText<"Display exploded graph using GraphViz">; -def analyzer_dump_egraph : Separate<["-"], "analyzer-dump-egraph">, - HelpText<"Dump exploded graph to the specified file">; -def analyzer_dump_egraph_EQ : Joined<["-"], "analyzer-dump-egraph=">, Alias; - -def analyzer_inline_max_stack_depth : Separate<["-"], "analyzer-inline-max-stack-depth">, - HelpText<"Bound on stack depth while inlining (4 by default)">; -def analyzer_inline_max_stack_depth_EQ : Joined<["-"], "analyzer-inline-max-stack-depth=">, - Alias; - -def analyzer_inlining_mode : Separate<["-"], "analyzer-inlining-mode">, - HelpText<"Specify the function selection heuristic used during inlining">; -def analyzer_inlining_mode_EQ : Joined<["-"], "analyzer-inlining-mode=">, Alias; - -def analyzer_disable_retry_exhausted : Flag<["-"], "analyzer-disable-retry-exhausted">, - HelpText<"Do not re-analyze paths leading to exhausted nodes with a different strategy (may decrease code coverage)">; - -def analyzer_max_loop : Separate<["-"], "analyzer-max-loop">, - HelpText<"The maximum number of times the analyzer will go through a loop">; -def analyzer_stats : Flag<["-"], "analyzer-stats">, - HelpText<"Print internal analyzer statistics.">; - -def analyzer_checker : Separate<["-"], "analyzer-checker">, - HelpText<"Choose analyzer checkers to enable">, - ValuesCode<[{ - const char *Values = - #define GET_CHECKERS - #define CHECKER(FULLNAME, CLASS, HT, DOC_URI, IS_HIDDEN) FULLNAME "," - #include "clang/StaticAnalyzer/Checkers/Checkers.inc" - #undef GET_CHECKERS - #define GET_PACKAGES - #define PACKAGE(FULLNAME) FULLNAME "," - #include "clang/StaticAnalyzer/Checkers/Checkers.inc" - #undef GET_PACKAGES - ; - }]>; -def analyzer_checker_EQ : Joined<["-"], "analyzer-checker=">, - Alias; - -def analyzer_disable_checker : Separate<["-"], "analyzer-disable-checker">, - HelpText<"Choose analyzer checkers to disable">; -def analyzer_disable_checker_EQ : Joined<["-"], "analyzer-disable-checker=">, - Alias; - -def analyzer_disable_all_checks : Flag<["-"], "analyzer-disable-all-checks">, - HelpText<"Disable all static analyzer checks">; - -def analyzer_checker_help : Flag<["-"], "analyzer-checker-help">, - HelpText<"Display the list of analyzer checkers that are available">; - -def analyzer_checker_help_alpha : Flag<["-"], "analyzer-checker-help-alpha">, - HelpText<"Display the list of in development analyzer checkers. These " - "are NOT considered safe, they are unstable and will emit incorrect " - "reports. Enable ONLY FOR DEVELOPMENT purposes">; - -def analyzer_checker_help_developer : Flag<["-"], "analyzer-checker-help-developer">, - HelpText<"Display the list of developer-only checkers such as modeling " - "and debug checkers">; - -def analyzer_config_help : Flag<["-"], "analyzer-config-help">, - HelpText<"Display the list of -analyzer-config options. These are meant for " - "development purposes only!">; - -def analyzer_list_enabled_checkers : Flag<["-"], "analyzer-list-enabled-checkers">, - HelpText<"Display the list of enabled analyzer checkers">; - -def analyzer_config : Separate<["-"], "analyzer-config">, - HelpText<"Choose analyzer options to enable">; - -def analyzer_checker_option_help : Flag<["-"], "analyzer-checker-option-help">, - HelpText<"Display the list of checker and package options">; - -def analyzer_checker_option_help_alpha : Flag<["-"], "analyzer-checker-option-help-alpha">, - HelpText<"Display the list of in development checker and package options. " - "These are NOT considered safe, they are unstable and will emit " - "incorrect reports. Enable ONLY FOR DEVELOPMENT purposes">; - -def analyzer_checker_option_help_developer : Flag<["-"], "analyzer-checker-option-help-developer">, - HelpText<"Display the list of checker and package options meant for " - "development purposes only">; - -def analyzer_config_compatibility_mode : Separate<["-"], "analyzer-config-compatibility-mode">, - HelpText<"Don't emit errors on invalid analyzer-config inputs">; - -def analyzer_config_compatibility_mode_EQ : Joined<["-"], "analyzer-config-compatibility-mode=">, - Alias; - -def analyzer_werror : Flag<["-"], "analyzer-werror">, - HelpText<"Emit analyzer results as errors rather than warnings">; - -//===----------------------------------------------------------------------===// -// Migrator Options -//===----------------------------------------------------------------------===// -def migrator_no_nsalloc_error : Flag<["-"], "no-ns-alloc-error">, - HelpText<"Do not error on use of NSAllocateCollectable/NSReallocateCollectable">; - -def migrator_no_finalize_removal : Flag<["-"], "no-finalize-removal">, - HelpText<"Do not remove finalize method in gc mode">; - -//===----------------------------------------------------------------------===// -// CodeGen Options -//===----------------------------------------------------------------------===// - -let Flags = [CC1Option, CC1AsOption, NoDriverOption] in { -def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">; -def debug_info_macro : Flag<["-"], "debug-info-macro">, - HelpText<"Emit macro debug information">; -def default_function_attr : Separate<["-"], "default-function-attr">, - HelpText<"Apply given attribute to all functions">; -def dwarf_version_EQ : Joined<["-"], "dwarf-version=">; -def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">; -def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">, - HelpText<"The string to embed in the Dwarf debug flags record.">; -def record_command_line : Separate<["-"], "record-command-line">, - HelpText<"The string to embed in the .LLVM.command.line section.">; -def compress_debug_sections : Flag<["-", "--"], "compress-debug-sections">, - HelpText<"DWARF debug sections compression">; -def compress_debug_sections_EQ : Joined<["-", "--"], "compress-debug-sections=">, - HelpText<"DWARF debug sections compression type">; -def mno_exec_stack : Flag<["-"], "mnoexecstack">, - HelpText<"Mark the file as not needing an executable stack">; -def massembler_no_warn : Flag<["-"], "massembler-no-warn">, - HelpText<"Make assembler not emit warnings">; -def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">, - HelpText<"Make assembler warnings fatal">; -def mrelax_relocations : Flag<["--"], "mrelax-relocations">, - HelpText<"Use relaxable elf relocations">; -def msave_temp_labels : Flag<["-"], "msave-temp-labels">, - HelpText<"Save temporary labels in the symbol table. " - "Note this may change .s semantics and shouldn't generally be used " - "on compiler-generated code.">; -def mrelocation_model : Separate<["-"], "mrelocation-model">, - HelpText<"The relocation model to use">, Values<"static,pic,ropi,rwpi,ropi-rwpi,dynamic-no-pic">; -def fno_math_builtin : Flag<["-"], "fno-math-builtin">, - HelpText<"Disable implicit builtin knowledge of math functions">; -} - -def disable_llvm_verifier : Flag<["-"], "disable-llvm-verifier">, - HelpText<"Don't run the LLVM IR verifier pass">; -def disable_llvm_passes : Flag<["-"], "disable-llvm-passes">, - HelpText<"Use together with -emit-llvm to get pristine LLVM IR from the " - "frontend by not running any LLVM passes at all">; -def disable_llvm_optzns : Flag<["-"], "disable-llvm-optzns">, - Alias; -def disable_lifetimemarkers : Flag<["-"], "disable-lifetime-markers">, - HelpText<"Disable lifetime-markers emission even when optimizations are " - "enabled">; -def disable_O0_optnone : Flag<["-"], "disable-O0-optnone">, - HelpText<"Disable adding the optnone attribute to functions at O0">; -def disable_red_zone : Flag<["-"], "disable-red-zone">, - HelpText<"Do not emit code that uses the red zone.">; -def dwarf_column_info : Flag<["-"], "dwarf-column-info">, - HelpText<"Turn on column location information.">; -def dwarf_ext_refs : Flag<["-"], "dwarf-ext-refs">, - HelpText<"Generate debug info with external references to clang modules" - " or precompiled headers">; -def dwarf_explicit_import : Flag<["-"], "dwarf-explicit-import">, - HelpText<"Generate explicit import from anonymous namespace to containing" - " scope">; -def debug_forward_template_params : Flag<["-"], "debug-forward-template-params">, - HelpText<"Emit complete descriptions of template parameters in forward" - " declarations">; -def fforbid_guard_variables : Flag<["-"], "fforbid-guard-variables">, - HelpText<"Emit an error if a C++ static local initializer would need a guard variable">; -def no_implicit_float : Flag<["-"], "no-implicit-float">, - HelpText<"Don't generate implicit floating point instructions">; -def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">, - HelpText<"Dump the layouts of all vtables that will be emitted in a translation unit">; -def fmerge_functions : Flag<["-"], "fmerge-functions">, - HelpText<"Permit merging of identical functions when optimizing.">; -def femit_coverage_notes : Flag<["-"], "femit-coverage-notes">, - HelpText<"Emit a gcov coverage notes file when compiling.">; -def femit_coverage_data: Flag<["-"], "femit-coverage-data">, - HelpText<"Instrument the program to emit gcov coverage data when run.">; -def coverage_data_file : Separate<["-"], "coverage-data-file">, - HelpText<"Emit coverage data to this filename.">; -def coverage_data_file_EQ : Joined<["-"], "coverage-data-file=">, - Alias; -def coverage_notes_file : Separate<["-"], "coverage-notes-file">, - HelpText<"Emit coverage notes to this filename.">; -def coverage_notes_file_EQ : Joined<["-"], "coverage-notes-file=">, - Alias; -def coverage_cfg_checksum : Flag<["-"], "coverage-cfg-checksum">, - HelpText<"Emit CFG checksum for functions in .gcno files.">; -def coverage_no_function_names_in_data : Flag<["-"], "coverage-no-function-names-in-data">, - HelpText<"Emit function names in .gcda files.">; -def coverage_exit_block_before_body : Flag<["-"], "coverage-exit-block-before-body">, - HelpText<"Emit the exit block before the body blocks in .gcno files.">; -def coverage_version_EQ : Joined<["-"], "coverage-version=">, - HelpText<"Four-byte version string for gcov files.">; -def test_coverage : Flag<["-"], "test-coverage">, - HelpText<"Do not generate coverage files or remove coverage changes from IR">; -def dump_coverage_mapping : Flag<["-"], "dump-coverage-mapping">, - HelpText<"Dump the coverage mapping records, for testing">; -def fuse_register_sized_bitfield_access: Flag<["-"], "fuse-register-sized-bitfield-access">, - HelpText<"Use register sized accesses to bit-fields, when possible.">; -def relaxed_aliasing : Flag<["-"], "relaxed-aliasing">, - HelpText<"Turn off Type Based Alias Analysis">; -def no_struct_path_tbaa : Flag<["-"], "no-struct-path-tbaa">, - HelpText<"Turn off struct-path aware Type Based Alias Analysis">; -def new_struct_path_tbaa : Flag<["-"], "new-struct-path-tbaa">, - HelpText<"Enable enhanced struct-path aware Type Based Alias Analysis">; -def masm_verbose : Flag<["-"], "masm-verbose">, - HelpText<"Generate verbose assembly output">; -def mcode_model : Separate<["-"], "mcode-model">, - HelpText<"The code model to use">, Values<"tiny,small,kernel,medium,large">; -def mdebug_pass : Separate<["-"], "mdebug-pass">, - HelpText<"Enable additional debug output">; -def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">, - HelpText<"Specify which frame pointers to retain (all, non-leaf, none).">, Values<"all,non-leaf,none">; -def mdisable_tail_calls : Flag<["-"], "mdisable-tail-calls">, - HelpText<"Disable tail call optimization, keeping the call stack accurate">; -def menable_no_infinities : Flag<["-"], "menable-no-infs">, - HelpText<"Allow optimization to assume there are no infinities.">; -def menable_no_nans : Flag<["-"], "menable-no-nans">, - HelpText<"Allow optimization to assume there are no NaNs.">; -def menable_unsafe_fp_math : Flag<["-"], "menable-unsafe-fp-math">, - HelpText<"Allow unsafe floating-point math optimizations which may decrease " - "precision">; -def mreassociate : Flag<["-"], "mreassociate">, - HelpText<"Allow reassociation transformations for floating-point instructions">; -def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">, - HelpText<"Use IEEE 754 quadruple-precision for long double">; -def mfloat_abi : Separate<["-"], "mfloat-abi">, - HelpText<"The float ABI to use">; -def mtp : Separate<["-"], "mtp">, - HelpText<"Mode for reading thread pointer">; -def mlimit_float_precision : Separate<["-"], "mlimit-float-precision">, - HelpText<"Limit float precision to the given value">; -def split_stacks : Flag<["-"], "split-stacks">, - HelpText<"Try to use a split stack if possible.">; -def mno_zero_initialized_in_bss : Flag<["-"], "mno-zero-initialized-in-bss">, - HelpText<"Do not put zero initialized data in the BSS">; -def mregparm : Separate<["-"], "mregparm">, - HelpText<"Limit the number of registers available for integer arguments">; -def munwind_tables : Flag<["-"], "munwind-tables">, - HelpText<"Generate unwinding tables for all functions">; -def mconstructor_aliases : Flag<["-"], "mconstructor-aliases">, - HelpText<"Emit complete constructors and destructors as aliases when possible">; -def mlink_bitcode_file : Separate<["-"], "mlink-bitcode-file">, - HelpText<"Link the given bitcode file before performing optimizations.">; -def mlink_builtin_bitcode : Separate<["-"], "mlink-builtin-bitcode">, - HelpText<"Link and internalize needed symbols from the given bitcode file " - "before performing optimizations.">; -def mlink_cuda_bitcode : Separate<["-"], "mlink-cuda-bitcode">, - Alias; -def vectorize_loops : Flag<["-"], "vectorize-loops">, - HelpText<"Run the Loop vectorization passes">; -def vectorize_slp : Flag<["-"], "vectorize-slp">, - HelpText<"Run the SLP vectorization passes">; -def dependent_lib : Joined<["--"], "dependent-lib=">, - HelpText<"Add dependent library">; -def linker_option : Joined<["--"], "linker-option=">, - HelpText<"Add linker option">; -def fsanitize_coverage_type : Joined<["-"], "fsanitize-coverage-type=">, - HelpText<"Sanitizer coverage type">; -def fsanitize_coverage_indirect_calls - : Flag<["-"], "fsanitize-coverage-indirect-calls">, - HelpText<"Enable sanitizer coverage for indirect calls">; -def fsanitize_coverage_trace_bb - : Flag<["-"], "fsanitize-coverage-trace-bb">, - HelpText<"Enable basic block tracing in sanitizer coverage">; -def fsanitize_coverage_trace_cmp - : Flag<["-"], "fsanitize-coverage-trace-cmp">, - HelpText<"Enable cmp instruction tracing in sanitizer coverage">; -def fsanitize_coverage_trace_div - : Flag<["-"], "fsanitize-coverage-trace-div">, - HelpText<"Enable div instruction tracing in sanitizer coverage">; -def fsanitize_coverage_trace_gep - : Flag<["-"], "fsanitize-coverage-trace-gep">, - HelpText<"Enable gep instruction tracing in sanitizer coverage">; -def fsanitize_coverage_8bit_counters - : Flag<["-"], "fsanitize-coverage-8bit-counters">, - HelpText<"Enable frequency counters in sanitizer coverage">; -def fsanitize_coverage_inline_8bit_counters - : Flag<["-"], "fsanitize-coverage-inline-8bit-counters">, - HelpText<"Enable inline 8-bit counters in sanitizer coverage">; -def fsanitize_coverage_pc_table - : Flag<["-"], "fsanitize-coverage-pc-table">, - HelpText<"Create a table of coverage-instrumented PCs">; -def fsanitize_coverage_trace_pc - : Flag<["-"], "fsanitize-coverage-trace-pc">, - HelpText<"Enable PC tracing in sanitizer coverage">; -def fsanitize_coverage_trace_pc_guard - : Flag<["-"], "fsanitize-coverage-trace-pc-guard">, - HelpText<"Enable PC tracing with guard in sanitizer coverage">; -def fsanitize_coverage_no_prune - : Flag<["-"], "fsanitize-coverage-no-prune">, - HelpText<"Disable coverage pruning (i.e. instrument all blocks/edges)">; -def fsanitize_coverage_stack_depth - : Flag<["-"], "fsanitize-coverage-stack-depth">, - HelpText<"Enable max stack depth tracing">; -def fpatchable_function_entry_offset_EQ - : Joined<["-"], "fpatchable-function-entry-offset=">, MetaVarName<"">, - HelpText<"Generate M NOPs before function entry">; -def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">, - HelpText<"Enable PGO instrumentation. The accepted value is clang, llvm, " - "or none">, Values<"none,clang,llvm">; -def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">, - HelpText<"Generate instrumented code to collect execution counts into " - " (overridden by LLVM_PROFILE_FILE env var)">; -def fprofile_instrument_use_path_EQ : - Joined<["-"], "fprofile-instrument-use-path=">, - HelpText<"Specify the profile path in PGO use compilation">; -def flto_visibility_public_std: - Flag<["-"], "flto-visibility-public-std">, - HelpText<"Use public LTO visibility for classes in std and stdext namespaces">; -def flto_unit: Flag<["-"], "flto-unit">, - HelpText<"Emit IR to support LTO unit features (CFI, whole program vtable opt)">; -def fno_lto_unit: Flag<["-"], "fno-lto-unit">; -def femit_debug_entry_values : Flag<["-"], "femit-debug-entry-values">, - HelpText<"Enables debug info about call site parameter's entry values">; -def fdebug_pass_manager : Flag<["-"], "fdebug-pass-manager">, - HelpText<"Prints debug information for the new pass manager">; -def fno_debug_pass_manager : Flag<["-"], "fno-debug-pass-manager">, - HelpText<"Disables debug printing for the new pass manager">; -// The driver option takes the key as a parameter to the -msign-return-address= -// and -mbranch-protection= options, but CC1 has a separate option so we -// don't have to parse the parameter twice. -def msign_return_address_key_EQ : Joined<["-"], "msign-return-address-key=">, - Values<"a_key,b_key">; -def mbranch_target_enforce : Flag<["-"], "mbranch-target-enforce">; -def fno_dllexport_inlines : Flag<["-"], "fno-dllexport-inlines">; -def cfguard_no_checks : Flag<["-"], "cfguard-no-checks">, - HelpText<"Emit Windows Control Flow Guard tables only (no checks)">; -def cfguard : Flag<["-"], "cfguard">, - HelpText<"Emit Windows Control Flow Guard tables and checks">; - -//===----------------------------------------------------------------------===// -// Dependency Output Options -//===----------------------------------------------------------------------===// - -def sys_header_deps : Flag<["-"], "sys-header-deps">, - HelpText<"Include system headers in dependency output">; -def module_file_deps : Flag<["-"], "module-file-deps">, - HelpText<"Include module files in dependency output">; -def header_include_file : Separate<["-"], "header-include-file">, - HelpText<"Filename (or -) to write header include output to">; -def show_includes : Flag<["--"], "show-includes">, - HelpText<"Print cl.exe style /showIncludes to stdout">; - -//===----------------------------------------------------------------------===// -// Diagnostic Options -//===----------------------------------------------------------------------===// - -def diagnostic_log_file : Separate<["-"], "diagnostic-log-file">, - HelpText<"Filename (or -) to log diagnostics to">; -def diagnostic_serialized_file : Separate<["-"], "serialize-diagnostic-file">, - MetaVarName<"">, - HelpText<"File for serializing diagnostics in a binary format">; - -def fdiagnostics_format : Separate<["-"], "fdiagnostics-format">, - HelpText<"Change diagnostic formatting to match IDE and command line tools">, Values<"clang,msvc,msvc-fallback,vi">; -def fdiagnostics_show_category : Separate<["-"], "fdiagnostics-show-category">, - HelpText<"Print diagnostic category">, Values<"none,id,name">; -def fno_diagnostics_use_presumed_location : Flag<["-"], "fno-diagnostics-use-presumed-location">, - HelpText<"Ignore #line directives when displaying diagnostic locations">; -def ftabstop : Separate<["-"], "ftabstop">, MetaVarName<"">, - HelpText<"Set the tab stop distance.">; -def ferror_limit : Separate<["-"], "ferror-limit">, MetaVarName<"">, - HelpText<"Set the maximum number of errors to emit before stopping (0 = no limit).">; -def fmacro_backtrace_limit : Separate<["-"], "fmacro-backtrace-limit">, MetaVarName<"">, - HelpText<"Set the maximum number of entries to print in a macro expansion backtrace (0 = no limit).">; -def ftemplate_backtrace_limit : Separate<["-"], "ftemplate-backtrace-limit">, MetaVarName<"">, - HelpText<"Set the maximum number of entries to print in a template instantiation backtrace (0 = no limit).">; -def fconstexpr_backtrace_limit : Separate<["-"], "fconstexpr-backtrace-limit">, MetaVarName<"">, - HelpText<"Set the maximum number of entries to print in a constexpr evaluation backtrace (0 = no limit).">; -def fspell_checking_limit : Separate<["-"], "fspell-checking-limit">, MetaVarName<"">, - HelpText<"Set the maximum number of times to perform spell checking on unrecognized identifiers (0 = no limit).">; -def fcaret_diagnostics_max_lines : - Separate<["-"], "fcaret-diagnostics-max-lines">, MetaVarName<"">, - HelpText<"Set the maximum number of source lines to show in a caret diagnostic">; -def fmessage_length : Separate<["-"], "fmessage-length">, MetaVarName<"">, - HelpText<"Format message diagnostics so that they fit within N columns or fewer, when possible.">; -def verify_EQ : CommaJoined<["-"], "verify=">, - MetaVarName<"">, - HelpText<"Verify diagnostic output using comment directives that start with" - " prefixes in the comma-separated sequence ">; -def verify : Flag<["-"], "verify">, - HelpText<"Equivalent to -verify=expected">; -def verify_ignore_unexpected : Flag<["-"], "verify-ignore-unexpected">, - HelpText<"Ignore unexpected diagnostic messages">; -def verify_ignore_unexpected_EQ : CommaJoined<["-"], "verify-ignore-unexpected=">, - HelpText<"Ignore unexpected diagnostic messages">; -def Wno_rewrite_macros : Flag<["-"], "Wno-rewrite-macros">, - HelpText<"Silence ObjC rewriting warnings">; - -//===----------------------------------------------------------------------===// -// Frontend Options -//===----------------------------------------------------------------------===// - -// This isn't normally used, it is just here so we can parse a -// CompilerInvocation out of a driver-derived argument vector. -def cc1 : Flag<["-"], "cc1">; -def cc1as : Flag<["-"], "cc1as">; - -def ast_merge : Separate<["-"], "ast-merge">, - MetaVarName<"">, - HelpText<"Merge the given AST file into the translation unit being compiled.">; -def aux_triple : Separate<["-"], "aux-triple">, - HelpText<"Auxiliary target triple.">; -def code_completion_at : Separate<["-"], "code-completion-at">, - MetaVarName<"::">, - HelpText<"Dump code-completion information at a location">; -def remap_file : Separate<["-"], "remap-file">, - MetaVarName<";">, - HelpText<"Replace the contents of the file with the contents of the file">; -def code_completion_at_EQ : Joined<["-"], "code-completion-at=">, - Alias; -def code_completion_macros : Flag<["-"], "code-completion-macros">, - HelpText<"Include macros in code-completion results">; -def code_completion_patterns : Flag<["-"], "code-completion-patterns">, - HelpText<"Include code patterns in code-completion results">; -def no_code_completion_globals : Flag<["-"], "no-code-completion-globals">, - HelpText<"Do not include global declarations in code-completion results.">; -def no_code_completion_ns_level_decls : Flag<["-"], "no-code-completion-ns-level-decls">, - HelpText<"Do not include declarations inside namespaces (incl. global namespace) in the code-completion results.">; -def code_completion_brief_comments : Flag<["-"], "code-completion-brief-comments">, - HelpText<"Include brief documentation comments in code-completion results.">; -def code_completion_with_fixits : Flag<["-"], "code-completion-with-fixits">, - HelpText<"Include code completion results which require small fix-its.">; -def disable_free : Flag<["-"], "disable-free">, - HelpText<"Disable freeing of memory on exit">; -def discard_value_names : Flag<["-"], "discard-value-names">, - HelpText<"Discard value names in LLVM IR">; -def load : Separate<["-"], "load">, MetaVarName<"">, - HelpText<"Load the named plugin (dynamic shared object)">; -def plugin : Separate<["-"], "plugin">, MetaVarName<"">, - HelpText<"Use the named plugin action instead of the default action (use \"help\" to list available options)">; -def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">, - MetaVarName<" ">, - HelpText<"Pass to plugin ">; -def add_plugin : Separate<["-"], "add-plugin">, MetaVarName<"">, - HelpText<"Use the named plugin action in addition to the default action">; -def ast_dump_filter : Separate<["-"], "ast-dump-filter">, - MetaVarName<"">, - HelpText<"Use with -ast-dump or -ast-print to dump/print only AST declaration" - " nodes having a certain substring in a qualified name. Use" - " -ast-list to list all filterable declaration node names.">; -def fno_modules_global_index : Flag<["-"], "fno-modules-global-index">, - HelpText<"Do not automatically generate or update the global module index">; -def fno_modules_error_recovery : Flag<["-"], "fno-modules-error-recovery">, - HelpText<"Do not automatically import modules for error recovery">; -def fmodule_map_file_home_is_cwd : Flag<["-"], "fmodule-map-file-home-is-cwd">, - HelpText<"Use the current working directory as the home directory of " - "module maps specified by -fmodule-map-file=">; -def fmodule_feature : Separate<["-"], "fmodule-feature">, - MetaVarName<"">, - HelpText<"Enable in module map requires declarations">; -def fmodules_embed_file_EQ : Joined<["-"], "fmodules-embed-file=">, - MetaVarName<"">, - HelpText<"Embed the contents of the specified file into the module file " - "being compiled.">; -def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">, - HelpText<"Embed the contents of all files read by this compilation into " - "the produced module file.">; -def fmodules_local_submodule_visibility : - Flag<["-"], "fmodules-local-submodule-visibility">, - HelpText<"Enforce name visibility rules across submodules of the same " - "top-level module.">; -def fmodules_codegen : - Flag<["-"], "fmodules-codegen">, - HelpText<"Generate code for uses of this module that assumes an explicit " - "object file will be built for the module">; -def fmodules_debuginfo : - Flag<["-"], "fmodules-debuginfo">, - HelpText<"Generate debug info for types in an object file built from this " - "module and do not generate them elsewhere">; -def fmodule_format_EQ : Joined<["-"], "fmodule-format=">, - HelpText<"Select the container format for clang modules and PCH. " - "Supported options are 'raw' and 'obj'.">; -def ftest_module_file_extension_EQ : - Joined<["-"], "ftest-module-file-extension=">, - HelpText<"introduce a module file extension for testing purposes. " - "The argument is parsed as blockname:major:minor:hashed:user info">; -def fconcepts_ts : Flag<["-"], "fconcepts-ts">, - HelpText<"Enable C++ Extensions for Concepts. (deprecated - use -std=c++2a)">; -def fno_concept_satisfaction_caching : Flag<["-"], - "fno-concept-satisfaction-caching">, - HelpText<"Disable satisfaction caching for C++2a Concepts.">; - -let Group = Action_Group in { - -def Eonly : Flag<["-"], "Eonly">, - HelpText<"Just run preprocessor, no output (for timings)">; -def dump_raw_tokens : Flag<["-"], "dump-raw-tokens">, - HelpText<"Lex file in raw mode and dump raw tokens">; -def analyze : Flag<["-"], "analyze">, - HelpText<"Run static analysis engine">; -def dump_tokens : Flag<["-"], "dump-tokens">, - HelpText<"Run preprocessor, dump internal rep of tokens">; -def init_only : Flag<["-"], "init-only">, - HelpText<"Only execute frontend initialization">; -def fixit : Flag<["-"], "fixit">, - HelpText<"Apply fix-it advice to the input source">; -def fixit_EQ : Joined<["-"], "fixit=">, - HelpText<"Apply fix-it advice creating a file with the given suffix">; -def print_preamble : Flag<["-"], "print-preamble">, - HelpText<"Print the \"preamble\" of a file, which is a candidate for implicit" - " precompiled headers.">; -def emit_html : Flag<["-"], "emit-html">, - HelpText<"Output input source as HTML">; -def ast_print : Flag<["-"], "ast-print">, - HelpText<"Build ASTs and then pretty-print them">; -def ast_list : Flag<["-"], "ast-list">, - HelpText<"Build ASTs and print the list of declaration node qualified names">; -def ast_dump : Flag<["-"], "ast-dump">, - HelpText<"Build ASTs and then debug dump them">; -def ast_dump_EQ : Joined<["-"], "ast-dump=">, - HelpText<"Build ASTs and then debug dump them in the specified format. " - "Supported formats include: default, json">; -def ast_dump_all : Flag<["-"], "ast-dump-all">, - HelpText<"Build ASTs and then debug dump them, forcing deserialization">; -def ast_dump_all_EQ : Joined<["-"], "ast-dump-all=">, - HelpText<"Build ASTs and then debug dump them in the specified format, " - "forcing deserialization. Supported formats include: default, json">; -def templight_dump : Flag<["-"], "templight-dump">, - HelpText<"Dump templight information to stdout">; -def ast_dump_lookups : Flag<["-"], "ast-dump-lookups">, - HelpText<"Build ASTs and then debug dump their name lookup tables">; -def ast_view : Flag<["-"], "ast-view">, - HelpText<"Build ASTs and view them with GraphViz">; -def emit_module : Flag<["-"], "emit-module">, - HelpText<"Generate pre-compiled module file from a module map">; -def emit_module_interface : Flag<["-"], "emit-module-interface">, - HelpText<"Generate pre-compiled module file from a C++ module interface">; -def emit_header_module : Flag<["-"], "emit-header-module">, - HelpText<"Generate pre-compiled module file from a set of header files">; -def emit_pch : Flag<["-"], "emit-pch">, - HelpText<"Generate pre-compiled header file">; -def emit_llvm_bc : Flag<["-"], "emit-llvm-bc">, - HelpText<"Build ASTs then convert to LLVM, emit .bc file">; -def emit_llvm_only : Flag<["-"], "emit-llvm-only">, - HelpText<"Build ASTs and convert to LLVM, discarding output">; -def emit_codegen_only : Flag<["-"], "emit-codegen-only">, - HelpText<"Generate machine code, but discard output">; -def emit_obj : Flag<["-"], "emit-obj">, - HelpText<"Emit native object files">; -def rewrite_test : Flag<["-"], "rewrite-test">, - HelpText<"Rewriter playground">; -def rewrite_macros : Flag<["-"], "rewrite-macros">, - HelpText<"Expand macros without full preprocessing">; -def migrate : Flag<["-"], "migrate">, - HelpText<"Migrate source code">; -def compiler_options_dump : Flag<["-"], "compiler-options-dump">, - HelpText<"Dump the compiler configuration options">; -def print_dependency_directives_minimized_source : Flag<["-"], - "print-dependency-directives-minimized-source">, - HelpText<"Print the output of the dependency directives source minimizer">; -} - -def emit_llvm_uselists : Flag<["-"], "emit-llvm-uselists">, - HelpText<"Preserve order of LLVM use-lists when serializing">; -def no_emit_llvm_uselists : Flag<["-"], "no-emit-llvm-uselists">, - HelpText<"Don't preserve order of LLVM use-lists when serializing">; - -def mt_migrate_directory : Separate<["-"], "mt-migrate-directory">, - HelpText<"Directory for temporary files produced during ARC or ObjC migration">; -def arcmt_check : Flag<["-"], "arcmt-check">, - HelpText<"Check for ARC migration issues that need manual handling">; -def arcmt_modify : Flag<["-"], "arcmt-modify">, - HelpText<"Apply modifications to files to conform to ARC">; -def arcmt_migrate : Flag<["-"], "arcmt-migrate">, - HelpText<"Apply modifications and produces temporary files that conform to ARC">; - -def opt_record_file : Separate<["-"], "opt-record-file">, - HelpText<"File name to use for YAML optimization record output">; -def opt_record_passes : Separate<["-"], "opt-record-passes">, - HelpText<"Only record remark information for passes whose names match the given regular expression">; -def opt_record_format : Separate<["-"], "opt-record-format">, - HelpText<"The format used for serializing remarks (default: YAML)">; - -def print_stats : Flag<["-"], "print-stats">, - HelpText<"Print performance metrics and statistics">; -def stats_file : Joined<["-"], "stats-file=">, - HelpText<"Filename to write statistics to">; -def fdump_record_layouts : Flag<["-"], "fdump-record-layouts">, - HelpText<"Dump record layout information">; -def fdump_record_layouts_simple : Flag<["-"], "fdump-record-layouts-simple">, - HelpText<"Dump record layout information in a simple form used for testing">; -def fix_what_you_can : Flag<["-"], "fix-what-you-can">, - HelpText<"Apply fix-it advice even in the presence of unfixable errors">; -def fix_only_warnings : Flag<["-"], "fix-only-warnings">, - HelpText<"Apply fix-it advice only for warnings, not errors">; -def fixit_recompile : Flag<["-"], "fixit-recompile">, - HelpText<"Apply fix-it changes and recompile">; -def fixit_to_temp : Flag<["-"], "fixit-to-temporary">, - HelpText<"Apply fix-it changes to temporary files">; - -def foverride_record_layout_EQ : Joined<["-"], "foverride-record-layout=">, - HelpText<"Override record layouts with those in the given file">; -def pch_through_header_EQ : Joined<["-"], "pch-through-header=">, - HelpText<"Stop PCH generation after including this file. When using a PCH, " - "skip tokens until after this file is included.">; -def pch_through_hdrstop_create : Flag<["-"], "pch-through-hdrstop-create">, - HelpText<"When creating a PCH, stop PCH generation after #pragma hdrstop.">; -def pch_through_hdrstop_use : Flag<["-"], "pch-through-hdrstop-use">, - HelpText<"When using a PCH, skip tokens until after a #pragma hdrstop.">; -def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">, - HelpText<"Disable inclusion of timestamp in precompiled headers">; -def building_pch_with_obj : Flag<["-"], "building-pch-with-obj">, - HelpText<"This compilation is part of building a PCH with corresponding object file.">; - -def aligned_alloc_unavailable : Flag<["-"], "faligned-alloc-unavailable">, - HelpText<"Aligned allocation/deallocation functions are unavailable">; - -//===----------------------------------------------------------------------===// -// Language Options -//===----------------------------------------------------------------------===// - -let Flags = [CC1Option, CC1AsOption, NoDriverOption] in { - -def version : Flag<["-"], "version">, - HelpText<"Print the compiler version">; -def main_file_name : Separate<["-"], "main-file-name">, - HelpText<"Main file name to use for debug info and source if missing">; -def split_dwarf_output : Separate<["-"], "split-dwarf-output">, - HelpText<"File name to use for split dwarf debug info output">; - -} - -def fblocks_runtime_optional : Flag<["-"], "fblocks-runtime-optional">, - HelpText<"Weakly link in the blocks runtime">; -def fexternc_nounwind : Flag<["-"], "fexternc-nounwind">, - HelpText<"Assume all functions with C linkage do not unwind">; -def split_dwarf_file : Separate<["-"], "split-dwarf-file">, - HelpText<"Name of the split dwarf debug info file to encode in the object file">; -def fno_wchar : Flag<["-"], "fno-wchar">, - HelpText<"Disable C++ builtin type wchar_t">; -def fconstant_string_class : Separate<["-"], "fconstant-string-class">, - MetaVarName<"">, - HelpText<"Specify the class to use for constant Objective-C string objects.">; -def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">, - HelpText<"Objective-C++ Automatic Reference Counting standard library kind">, Values<"libc++,libstdc++,none">; -def fobjc_runtime_has_weak : Flag<["-"], "fobjc-runtime-has-weak">, - HelpText<"The target Objective-C runtime supports ARC weak operations">; -def fobjc_dispatch_method_EQ : Joined<["-"], "fobjc-dispatch-method=">, - HelpText<"Objective-C dispatch method to use">, Values<"legacy,non-legacy,mixed">; -def disable_objc_default_synthesize_properties : Flag<["-"], "disable-objc-default-synthesize-properties">, - HelpText<"disable the default synthesis of Objective-C properties">; -def fencode_extended_block_signature : Flag<["-"], "fencode-extended-block-signature">, - HelpText<"enable extended encoding of block type signature">; -def function_alignment : Separate<["-"], "function-alignment">, - HelpText<"default alignment for functions">; -def pic_level : Separate<["-"], "pic-level">, - HelpText<"Value for __PIC__">; -def pic_is_pie : Flag<["-"], "pic-is-pie">, - HelpText<"File is for a position independent executable">; -def fno_validate_pch : Flag<["-"], "fno-validate-pch">, - HelpText<"Disable validation of precompiled headers">; -def fallow_pch_with_errors : Flag<["-"], "fallow-pch-with-compiler-errors">, - HelpText<"Accept a PCH file that was created with compiler errors">; -def dump_deserialized_pch_decls : Flag<["-"], "dump-deserialized-decls">, - HelpText<"Dump declarations that are deserialized from PCH, for testing">; -def error_on_deserialized_pch_decl : Separate<["-"], "error-on-deserialized-decl">, - HelpText<"Emit error if a specific declaration is deserialized from PCH, for testing">; -def error_on_deserialized_pch_decl_EQ : Joined<["-"], "error-on-deserialized-decl=">, - Alias; -def static_define : Flag<["-"], "static-define">, - HelpText<"Should __STATIC__ be defined">; -def stack_protector : Separate<["-"], "stack-protector">, - HelpText<"Enable stack protectors">; -def stack_protector_buffer_size : Separate<["-"], "stack-protector-buffer-size">, - HelpText<"Lower bound for a buffer to be considered for stack protection">; -def ret_protector : Flag<["-"], "ret-protector">, - HelpText<"Enable Return Protectors">; -def fvisibility : Separate<["-"], "fvisibility">, - HelpText<"Default type and symbol visibility">; -def ftype_visibility : Separate<["-"], "ftype-visibility">, - HelpText<"Default type visibility">; -def fapply_global_visibility_to_externs : Flag<["-"], "fapply-global-visibility-to-externs">, - HelpText<"Apply global symbol visibility to external declarations without an explicit visibility">; -def ftemplate_depth : Separate<["-"], "ftemplate-depth">, - HelpText<"Maximum depth of recursive template instantiation">; -def foperator_arrow_depth : Separate<["-"], "foperator-arrow-depth">, - HelpText<"Maximum number of 'operator->'s to call for a member access">; -def fconstexpr_depth : Separate<["-"], "fconstexpr-depth">, - HelpText<"Maximum depth of recursive constexpr function calls">; -def fconstexpr_steps : Separate<["-"], "fconstexpr-steps">, - HelpText<"Maximum number of steps in constexpr function evaluation">; -def fbracket_depth : Separate<["-"], "fbracket-depth">, - HelpText<"Maximum nesting level for parentheses, brackets, and braces">; -def fconst_strings : Flag<["-"], "fconst-strings">, - HelpText<"Use a const qualified type for string literals in C and ObjC">; -def fno_const_strings : Flag<["-"], "fno-const-strings">, - HelpText<"Don't use a const qualified type for string literals in C and ObjC">; -def fno_bitfield_type_align : Flag<["-"], "fno-bitfield-type-align">, - HelpText<"Ignore bit-field types when aligning structures">; -def ffake_address_space_map : Flag<["-"], "ffake-address-space-map">, - HelpText<"Use a fake address space map; OpenCL testing purposes only">; -def faddress_space_map_mangling_EQ : Joined<["-"], "faddress-space-map-mangling=">, MetaVarName<"">, - HelpText<"Set the mode for address space map based mangling; OpenCL testing purposes only">; -def funknown_anytype : Flag<["-"], "funknown-anytype">, - HelpText<"Enable parser support for the __unknown_anytype type; for testing purposes only">; -def fdebugger_support : Flag<["-"], "fdebugger-support">, - HelpText<"Enable special debugger support behavior">; -def fdebugger_cast_result_to_id : Flag<["-"], "fdebugger-cast-result-to-id">, - HelpText<"Enable casting unknown expression results to id">; -def fdebugger_objc_literal : Flag<["-"], "fdebugger-objc-literal">, - HelpText<"Enable special debugger support for Objective-C subscripting and literals">; -def fdeprecated_macro : Flag<["-"], "fdeprecated-macro">, - HelpText<"Defines the __DEPRECATED macro">; -def fno_deprecated_macro : Flag<["-"], "fno-deprecated-macro">, - HelpText<"Undefines the __DEPRECATED macro">; -def fobjc_subscripting_legacy_runtime : Flag<["-"], "fobjc-subscripting-legacy-runtime">, - HelpText<"Allow Objective-C array and dictionary subscripting in legacy runtime">; -def vtordisp_mode_EQ : Joined<["-"], "vtordisp-mode=">, - HelpText<"Control vtordisp placement on win32 targets">; -def fnative_half_type: Flag<["-"], "fnative-half-type">, - HelpText<"Use the native half type for __fp16 instead of promoting to float">; -def fnative_half_arguments_and_returns : Flag<["-"], "fnative-half-arguments-and-returns">, - HelpText<"Use the native __fp16 type for arguments and returns (and skip ABI-specific lowering)">; -def fallow_half_arguments_and_returns : Flag<["-"], "fallow-half-arguments-and-returns">, - HelpText<"Allow function arguments and returns of type half">; -def fdefault_calling_conv_EQ : Joined<["-"], "fdefault-calling-conv=">, - HelpText<"Set default calling convention">, Values<"cdecl,fastcall,stdcall,vectorcall,regcall">; -def finclude_default_header : Flag<["-"], "finclude-default-header">, - HelpText<"Include default header file for OpenCL">; -def fdeclare_opencl_builtins : Flag<["-"], "fdeclare-opencl-builtins">, - HelpText<"Add OpenCL builtin function declarations (experimental)">; -def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">, - HelpText<"Preserve 3-component vector type">; -def fwchar_type_EQ : Joined<["-"], "fwchar-type=">, - HelpText<"Select underlying type for wchar_t">, Values<"char,short,int">; -def fsigned_wchar : Flag<["-"], "fsigned-wchar">, - HelpText<"Use a signed type for wchar_t">; -def fno_signed_wchar : Flag<["-"], "fno-signed-wchar">, - HelpText<"Use an unsigned type for wchar_t">; - -// FIXME: Remove these entirely once functionality/tests have been excised. -def fobjc_gc_only : Flag<["-"], "fobjc-gc-only">, Group, - HelpText<"Use GC exclusively for Objective-C related memory management">; -def fobjc_gc : Flag<["-"], "fobjc-gc">, Group, - HelpText<"Enable Objective-C garbage collection">; - -//===----------------------------------------------------------------------===// -// Header Search Options -//===----------------------------------------------------------------------===// - -def nostdsysteminc : Flag<["-"], "nostdsysteminc">, - HelpText<"Disable standard system #include directories">; -def fdisable_module_hash : Flag<["-"], "fdisable-module-hash">, - HelpText<"Disable the module hash">; -def fmodules_hash_content : Flag<["-"], "fmodules-hash-content">, - HelpText<"Enable hashing the content of a module file">; -def fmodules_strict_context_hash : Flag<["-"], "fmodules-strict-context-hash">, - HelpText<"Enable hashing of all compiler options that could impact the " - "semantics of a module in an implicit build">; -def c_isystem : JoinedOrSeparate<["-"], "c-isystem">, MetaVarName<"">, - HelpText<"Add directory to the C SYSTEM include search path">; -def objc_isystem : JoinedOrSeparate<["-"], "objc-isystem">, - MetaVarName<"">, - HelpText<"Add directory to the ObjC SYSTEM include search path">; -def objcxx_isystem : JoinedOrSeparate<["-"], "objcxx-isystem">, - MetaVarName<"">, - HelpText<"Add directory to the ObjC++ SYSTEM include search path">; -def internal_isystem : JoinedOrSeparate<["-"], "internal-isystem">, - MetaVarName<"">, - HelpText<"Add directory to the internal system include search path; these " - "are assumed to not be user-provided and are used to model system " - "and standard headers' paths.">; -def internal_externc_isystem : JoinedOrSeparate<["-"], "internal-externc-isystem">, - MetaVarName<"">, - HelpText<"Add directory to the internal system include search path with " - "implicit extern \"C\" semantics; these are assumed to not be " - "user-provided and are used to model system and standard headers' " - "paths.">; - -//===----------------------------------------------------------------------===// -// Preprocessor Options -//===----------------------------------------------------------------------===// - -def chain_include : Separate<["-"], "chain-include">, MetaVarName<"">, - HelpText<"Include and chain a header file after turning it into PCH">; -def preamble_bytes_EQ : Joined<["-"], "preamble-bytes=">, - HelpText<"Assume that the precompiled header is a precompiled preamble " - "covering the first N bytes of the main file">; -def detailed_preprocessing_record : Flag<["-"], "detailed-preprocessing-record">, - HelpText<"include a detailed record of preprocessing actions">; -def setup_static_analyzer : Flag<["-"], "setup-static-analyzer">, - HelpText<"Set up preprocessor for static analyzer (done automatically when static analyzer is run).">; -def disable_pragma_debug_crash : Flag<["-"], "disable-pragma-debug-crash">, - HelpText<"Disable any #pragma clang __debug that can lead to crashing behavior. This is meant for testing.">; - -//===----------------------------------------------------------------------===// -// OpenCL Options -//===----------------------------------------------------------------------===// - -def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, - HelpText<"OpenCL only. Enable or disable OpenCL extensions. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.">; - -//===----------------------------------------------------------------------===// -// CUDA Options -//===----------------------------------------------------------------------===// - -def fcuda_is_device : Flag<["-"], "fcuda-is-device">, - HelpText<"Generate code for CUDA device">; -def fcuda_include_gpubinary : Separate<["-"], "fcuda-include-gpubinary">, - HelpText<"Incorporate CUDA device-side binary into host object file.">; -def fcuda_allow_variadic_functions : Flag<["-"], "fcuda-allow-variadic-functions">, - HelpText<"Allow variadic functions in CUDA device code.">; -def fno_cuda_host_device_constexpr : Flag<["-"], "fno-cuda-host-device-constexpr">, - HelpText<"Don't treat unattributed constexpr functions as __host__ __device__.">; - -//===----------------------------------------------------------------------===// -// OpenMP Options -//===----------------------------------------------------------------------===// - -def fopenmp_is_device : Flag<["-"], "fopenmp-is-device">, - HelpText<"Generate code only for an OpenMP target device.">; -def fopenmp_host_ir_file_path : Separate<["-"], "fopenmp-host-ir-file-path">, - HelpText<"Path to the IR file produced by the frontend for the host.">; - -//===----------------------------------------------------------------------===// -// SYCL Options -//===----------------------------------------------------------------------===// - -def fsycl_is_device : Flag<["-"], "fsycl-is-device">, - HelpText<"Generate code for SYCL device.">; - -} // let Flags = [CC1Option] - -//===----------------------------------------------------------------------===// -// cc1as-only Options -//===----------------------------------------------------------------------===// - -let Flags = [CC1AsOption, NoDriverOption] in { - -// Language Options -def n : Flag<["-"], "n">, - HelpText<"Don't automatically start assembly file with a text section">; - -// Frontend Options -def filetype : Separate<["-"], "filetype">, - HelpText<"Specify the output file type ('asm', 'null', or 'obj')">; - -// Transliterate Options -def output_asm_variant : Separate<["-"], "output-asm-variant">, - HelpText<"Select the asm variant index to use for output">; -def show_encoding : Flag<["-"], "show-encoding">, - HelpText<"Show instruction encoding information in transliterate mode">; -def show_inst : Flag<["-"], "show-inst">, - HelpText<"Show internal instruction representation in transliterate mode">; - -// Assemble Options -def dwarf_debug_producer : Separate<["-"], "dwarf-debug-producer">, - HelpText<"The string to embed in the Dwarf debug AT_producer record.">; - -def defsym : Separate<["-"], "defsym">, - HelpText<"Define a value for a symbol">; -} // let Flags = [CC1AsOption] diff --git a/gnu/llvm/clang/include/clang/Driver/CLCompatOptions.td b/gnu/llvm/clang/include/clang/Driver/CLCompatOptions.td deleted file mode 100644 index 50d4622009c..00000000000 --- a/gnu/llvm/clang/include/clang/Driver/CLCompatOptions.td +++ /dev/null @@ -1,466 +0,0 @@ -//===--- CLCompatOptions.td - Options for clang-cl ------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file defines the options accepted by clang-cl. -// -//===----------------------------------------------------------------------===// - -def cl_Group : OptionGroup<"">, Flags<[CLOption]>, - HelpText<"CL.EXE COMPATIBILITY OPTIONS">; - -def cl_compile_Group : OptionGroup<"">, - Group; - -def cl_ignored_Group : OptionGroup<"">, - Group; - -class CLFlag : Option<["/", "-"], name, KIND_FLAG>, - Group, Flags<[CLOption, DriverOption]>; - -class CLCompileFlag : Option<["/", "-"], name, KIND_FLAG>, - Group, Flags<[CLOption, DriverOption]>; - -class CLIgnoredFlag : Option<["/", "-"], name, KIND_FLAG>, - Group, Flags<[CLOption, DriverOption]>; - -class CLJoined : Option<["/", "-"], name, KIND_JOINED>, - Group, Flags<[CLOption, DriverOption]>; - -class CLCompileJoined : Option<["/", "-"], name, KIND_JOINED>, - Group, Flags<[CLOption, DriverOption]>; - -class CLIgnoredJoined : Option<["/", "-"], name, KIND_JOINED>, - Group, Flags<[CLOption, DriverOption, HelpHidden]>; - -class CLJoinedOrSeparate : Option<["/", "-"], name, - KIND_JOINED_OR_SEPARATE>, Group, Flags<[CLOption, DriverOption]>; - -class CLCompileJoinedOrSeparate : Option<["/", "-"], name, - KIND_JOINED_OR_SEPARATE>, Group, - Flags<[CLOption, DriverOption]>; - -class CLRemainingArgsJoined : Option<["/", "-"], name, - KIND_REMAINING_ARGS_JOINED>, Group, Flags<[CLOption, DriverOption]>; - -// Aliases: -// (We don't put any of these in cl_compile_Group as the options they alias are -// already in the right group.) - -def _SLASH_Brepro : CLFlag<"Brepro">, - HelpText<"Do not write current time into COFF output (breaks link.exe /incremental)">, - Alias; -def _SLASH_Brepro_ : CLFlag<"Brepro-">, - HelpText<"Write current time into COFF output (default)">, - Alias; -def _SLASH_C : CLFlag<"C">, - HelpText<"Do not discard comments when preprocessing">, Alias; -def _SLASH_c : CLFlag<"c">, HelpText<"Compile only">, Alias; -def _SLASH_d1PP : CLFlag<"d1PP">, - HelpText<"Retain macro definitions in /E mode">, Alias
; -def _SLASH_d1reportAllClassLayout : CLFlag<"d1reportAllClassLayout">, - HelpText<"Dump record layout information">, - Alias, AliasArgs<["-fdump-record-layouts"]>; -def _SLASH_diagnostics_caret : CLFlag<"diagnostics:caret">, - HelpText<"Enable caret and column diagnostics (default)">; -def _SLASH_diagnostics_column : CLFlag<"diagnostics:column">, - HelpText<"Disable caret diagnostics but keep column info">; -def _SLASH_diagnostics_classic : CLFlag<"diagnostics:classic">, - HelpText<"Disable column and caret diagnostics">; -def _SLASH_D : CLJoinedOrSeparate<"D">, HelpText<"Define macro">, - MetaVarName<"">, Alias; -def _SLASH_E : CLFlag<"E">, HelpText<"Preprocess to stdout">, Alias; -def _SLASH_fp_except : CLFlag<"fp:except">, HelpText<"">, Alias; -def _SLASH_fp_except_ : CLFlag<"fp:except-">, - HelpText<"">, Alias; -def _SLASH_fp_fast : CLFlag<"fp:fast">, HelpText<"">, Alias; -def _SLASH_fp_precise : CLFlag<"fp:precise">, - HelpText<"">, Alias; -def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias; -def _SLASH_GA : CLFlag<"GA">, Alias, AliasArgs<["local-exec"]>, - HelpText<"Assume thread-local variables are defined in the executable">; -def _SLASH_GR : CLFlag<"GR">, HelpText<"Emit RTTI data (default)">; -def _SLASH_GR_ : CLFlag<"GR-">, HelpText<"Do not emit RTTI data">; -def _SLASH_GF : CLIgnoredFlag<"GF">, - HelpText<"Enable string pooling (default)">; -def _SLASH_GF_ : CLFlag<"GF-">, HelpText<"Disable string pooling">, - Alias; -def _SLASH_GS : CLFlag<"GS">, - HelpText<"Enable buffer security check (default)">; -def _SLASH_GS_ : CLFlag<"GS-">, HelpText<"Disable buffer security check">; -def : CLFlag<"Gs">, HelpText<"Use stack probes (default)">, - Alias, AliasArgs<["4096"]>; -def _SLASH_Gs : CLJoined<"Gs">, - HelpText<"Set stack probe size (default 4096)">, Alias; -def _SLASH_Gy : CLFlag<"Gy">, HelpText<"Put each function in its own section">, - Alias; -def _SLASH_Gy_ : CLFlag<"Gy-">, - HelpText<"Do not put each function in its own section (default)">, - Alias; -def _SLASH_Gw : CLFlag<"Gw">, HelpText<"Put each data item in its own section">, - Alias; -def _SLASH_Gw_ : CLFlag<"Gw-">, - HelpText<"Do not put each data item in its own section (default)">, - Alias; -def _SLASH_help : CLFlag<"help">, Alias, - HelpText<"Display available options">; -def _SLASH_HELP : CLFlag<"HELP">, Alias; -def _SLASH_I : CLJoinedOrSeparate<"I">, - HelpText<"Add directory to include search path">, MetaVarName<"">, - Alias; -def _SLASH_J : CLFlag<"J">, HelpText<"Make char type unsigned">, - Alias; - -// The _SLASH_O option handles all the /O flags, but we also provide separate -// aliased options to provide separate help messages. -def _SLASH_O : CLJoined<"O">, - HelpText<"Set multiple /O flags at once; e.g. '/O2y-' for '/O2 /Oy-'">, - MetaVarName<"">; -def : CLFlag<"O1">, Alias<_SLASH_O>, AliasArgs<["1"]>, - HelpText<"Optimize for size (like /Og /Os /Oy /Ob2 /GF /Gy)">; -def : CLFlag<"O2">, Alias<_SLASH_O>, AliasArgs<["2"]>, - HelpText<"Optimize for speed (like /Og /Oi /Ot /Oy /Ob2 /GF /Gy)">; -def : CLFlag<"Ob0">, Alias<_SLASH_O>, AliasArgs<["b0"]>, - HelpText<"Disable function inlining">; -def : CLFlag<"Ob1">, Alias<_SLASH_O>, AliasArgs<["b1"]>, - HelpText<"Only inline functions explicitly or implicitly marked inline">; -def : CLFlag<"Ob2">, Alias<_SLASH_O>, AliasArgs<["b2"]>, - HelpText<"Inline functions as deemed beneficial by the compiler">; -def : CLFlag<"Od">, Alias<_SLASH_O>, AliasArgs<["d"]>, - HelpText<"Disable optimization">; -def : CLFlag<"Og">, Alias<_SLASH_O>, AliasArgs<["g"]>, - HelpText<"No effect">; -def : CLFlag<"Oi">, Alias<_SLASH_O>, AliasArgs<["i"]>, - HelpText<"Enable use of builtin functions">; -def : CLFlag<"Oi-">, Alias<_SLASH_O>, AliasArgs<["i-"]>, - HelpText<"Disable use of builtin functions">; -def : CLFlag<"Os">, Alias<_SLASH_O>, AliasArgs<["s"]>, - HelpText<"Optimize for size">; -def : CLFlag<"Ot">, Alias<_SLASH_O>, AliasArgs<["t"]>, - HelpText<"Optimize for speed">; -def : CLFlag<"Ox">, Alias<_SLASH_O>, AliasArgs<["x"]>, - HelpText<"Deprecated (like /Og /Oi /Ot /Oy /Ob2); use /O2">; -def : CLFlag<"Oy">, Alias<_SLASH_O>, AliasArgs<["y"]>, - HelpText<"Enable frame pointer omission (x86 only)">; -def : CLFlag<"Oy-">, Alias<_SLASH_O>, AliasArgs<["y-"]>, - HelpText<"Disable frame pointer omission (x86 only, default)">; - -def _SLASH_QUESTION : CLFlag<"?">, Alias, - HelpText<"Display available options">; -def _SLASH_Qvec : CLFlag<"Qvec">, - HelpText<"Enable the loop vectorization passes">, Alias; -def _SLASH_Qvec_ : CLFlag<"Qvec-">, - HelpText<"Disable the loop vectorization passes">, Alias; -def _SLASH_showIncludes : CLFlag<"showIncludes">, - HelpText<"Print info about included files to stderr">, - Alias; -def _SLASH_showFilenames : CLFlag<"showFilenames">, - HelpText<"Print the name of each compiled file">; -def _SLASH_showFilenames_ : CLFlag<"showFilenames-">, - HelpText<"Do not print the name of each compiled file (default)">; -def _SLASH_source_charset : CLCompileJoined<"source-charset:">, - HelpText<"Set source encoding, supports only UTF-8">, - Alias; -def _SLASH_execution_charset : CLCompileJoined<"execution-charset:">, - HelpText<"Set runtime encoding, supports only UTF-8">, - Alias; -def _SLASH_std : CLCompileJoined<"std:">, - HelpText<"Set C++ version (c++14,c++17,c++latest)">; -def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">, - MetaVarName<"">, Alias; -def _SLASH_validate_charset : CLFlag<"validate-charset">, - Alias, AliasArgs<["invalid-source-encoding"]>; -def _SLASH_validate_charset_ : CLFlag<"validate-charset-">, - Alias, AliasArgs<["no-invalid-source-encoding"]>; -def _SLASH_W0 : CLFlag<"W0">, HelpText<"Disable all warnings">, Alias; -def _SLASH_W1 : CLFlag<"W1">, HelpText<"Enable -Wall">, Alias; -def _SLASH_W2 : CLFlag<"W2">, HelpText<"Enable -Wall">, Alias; -def _SLASH_W3 : CLFlag<"W3">, HelpText<"Enable -Wall">, Alias; -def _SLASH_W4 : CLFlag<"W4">, HelpText<"Enable -Wall and -Wextra">, Alias; -def _SLASH_Wall : CLFlag<"Wall">, HelpText<"Enable -Weverything">, - Alias, AliasArgs<["everything"]>; -def _SLASH_WX : CLFlag<"WX">, HelpText<"Treat warnings as errors">, - Alias, AliasArgs<["error"]>; -def _SLASH_WX_ : CLFlag<"WX-">, - HelpText<"Do not treat warnings as errors (default)">, - Alias, AliasArgs<["no-error"]>; -def _SLASH_w_flag : CLFlag<"w">, HelpText<"Disable all warnings">, Alias; -def _SLASH_wd4005 : CLFlag<"wd4005">, Alias, - AliasArgs<["no-macro-redefined"]>; -def _SLASH_wd4018 : CLFlag<"wd4018">, Alias, - AliasArgs<["no-sign-compare"]>; -def _SLASH_wd4100 : CLFlag<"wd4100">, Alias, - AliasArgs<["no-unused-parameter"]>; -def _SLASH_wd4910 : CLFlag<"wd4910">, Alias, - AliasArgs<["no-dllexport-explicit-instantiation-decl"]>; -def _SLASH_wd4996 : CLFlag<"wd4996">, Alias, - AliasArgs<["no-deprecated-declarations"]>; -def _SLASH_vd : CLJoined<"vd">, HelpText<"Control vtordisp placement">, - Alias; -def _SLASH_X : CLFlag<"X">, - HelpText<"Do not add %INCLUDE% to include search path">, Alias; -def _SLASH_Zc_sizedDealloc : CLFlag<"Zc:sizedDealloc">, - HelpText<"Enable C++14 sized global deallocation functions">, - Alias; -def _SLASH_Zc_sizedDealloc_ : CLFlag<"Zc:sizedDealloc-">, - HelpText<"Disable C++14 sized global deallocation functions">, - Alias; -def _SLASH_Zc_alignedNew : CLFlag<"Zc:alignedNew">, - HelpText<"Enable C++17 aligned allocation functions">, - Alias; -def _SLASH_Zc_alignedNew_ : CLFlag<"Zc:alignedNew-">, - HelpText<"Disable C++17 aligned allocation functions">, - Alias; -def _SLASH_Zc_char8_t : CLFlag<"Zc:char8_t">, - HelpText<"Enable char8_t from C++2a">, - Alias; -def _SLASH_Zc_char8_t_ : CLFlag<"Zc:char8_t-">, - HelpText<"Disable char8_t from c++2a">, - Alias; -def _SLASH_Zc_strictStrings : CLFlag<"Zc:strictStrings">, - HelpText<"Treat string literals as const">, Alias, - AliasArgs<["error=c++11-compat-deprecated-writable-strings"]>; -def _SLASH_Zc_threadSafeInit : CLFlag<"Zc:threadSafeInit">, - HelpText<"Enable thread-safe initialization of static variables">, - Alias; -def _SLASH_Zc_threadSafeInit_ : CLFlag<"Zc:threadSafeInit-">, - HelpText<"Disable thread-safe initialization of static variables">, - Alias; -def _SLASH_Zc_trigraphs : CLFlag<"Zc:trigraphs">, - HelpText<"Enable trigraphs">, Alias; -def _SLASH_Zc_trigraphs_off : CLFlag<"Zc:trigraphs-">, - HelpText<"Disable trigraphs (default)">, Alias; -def _SLASH_Zc_twoPhase : CLFlag<"Zc:twoPhase">, - HelpText<"Enable two-phase name lookup in templates">, - Alias; -def _SLASH_Zc_twoPhase_ : CLFlag<"Zc:twoPhase-">, - HelpText<"Disable two-phase name lookup in templates (default)">, - Alias; -def _SLASH_Z7 : CLFlag<"Z7">, - HelpText<"Enable CodeView debug information in object files">; -def _SLASH_Zd : CLFlag<"Zd">, - HelpText<"Emit debug line number tables only">; -def _SLASH_Zi : CLFlag<"Zi">, Alias<_SLASH_Z7>, - HelpText<"Like /Z7">; -def _SLASH_Zp : CLJoined<"Zp">, - HelpText<"Set default maximum struct packing alignment">, - Alias; -def _SLASH_Zp_flag : CLFlag<"Zp">, - HelpText<"Set default maximum struct packing alignment to 1">, - Alias, AliasArgs<["1"]>; -def _SLASH_Zs : CLFlag<"Zs">, HelpText<"Syntax-check only">, - Alias; -def _SLASH_openmp_ : CLFlag<"openmp-">, - HelpText<"Disable OpenMP support">, Alias; -def _SLASH_openmp : CLFlag<"openmp">, HelpText<"Enable OpenMP support">, - Alias; -def _SLASH_openmp_experimental : CLFlag<"openmp:experimental">, - HelpText<"Enable OpenMP support with experimental SIMD support">, - Alias; - -// Non-aliases: - -def _SLASH_arch : CLCompileJoined<"arch:">, - HelpText<"Set architecture for code generation">; - -def _SLASH_M_Group : OptionGroup<"">, Group; -def _SLASH_volatile_Group : OptionGroup<"">, - Group; - -def _SLASH_EH : CLJoined<"EH">, HelpText<"Set exception handling model">; -def _SLASH_EP : CLFlag<"EP">, - HelpText<"Disable linemarker output and preprocess to stdout">; -def _SLASH_FA : CLFlag<"FA">, - HelpText<"Output assembly code file during compilation">; -def _SLASH_Fa : CLJoined<"Fa">, - HelpText<"Set assembly output file name (with /FA)">, - MetaVarName<"">; -def _SLASH_fallback : CLCompileFlag<"fallback">, - HelpText<"Fall back to cl.exe if clang-cl fails to compile">; -def _SLASH_FI : CLJoinedOrSeparate<"FI">, - HelpText<"Include file before parsing">, Alias; -def _SLASH_Fe : CLJoined<"Fe">, - HelpText<"Set output executable file name">, - MetaVarName<"">; -def _SLASH_Fi : CLCompileJoined<"Fi">, - HelpText<"Set preprocess output file name (with /P)">, - MetaVarName<"">; -def _SLASH_Fo : CLCompileJoined<"Fo">, - HelpText<"Set output object file (with /c)">, - MetaVarName<"">; -def _SLASH_guard : CLJoined<"guard:">, - HelpText<"Enable Control Flow Guard with /guard:cf, or only the table with /guard:cf,nochecks">; -def _SLASH_GX : CLFlag<"GX">, - HelpText<"Deprecated; use /EHsc">; -def _SLASH_GX_ : CLFlag<"GX-">, - HelpText<"Deprecated (like not passing /EH)">; -def _SLASH_imsvc : CLJoinedOrSeparate<"imsvc">, - HelpText<"Add to system include search path, as if in %INCLUDE%">, - MetaVarName<"">; -def _SLASH_LD : CLFlag<"LD">, HelpText<"Create DLL">; -def _SLASH_LDd : CLFlag<"LDd">, HelpText<"Create debug DLL">; -def _SLASH_link : CLRemainingArgsJoined<"link">, - HelpText<"Forward options to the linker">, MetaVarName<"">; -def _SLASH_MD : Option<["/", "-"], "MD", KIND_FLAG>, Group<_SLASH_M_Group>, - Flags<[CLOption, DriverOption]>, HelpText<"Use DLL run-time">; -def _SLASH_MDd : Option<["/", "-"], "MDd", KIND_FLAG>, Group<_SLASH_M_Group>, - Flags<[CLOption, DriverOption]>, HelpText<"Use DLL debug run-time">; -def _SLASH_MT : Option<["/", "-"], "MT", KIND_FLAG>, Group<_SLASH_M_Group>, - Flags<[CLOption, DriverOption]>, HelpText<"Use static run-time">; -def _SLASH_MTd : Option<["/", "-"], "MTd", KIND_FLAG>, Group<_SLASH_M_Group>, - Flags<[CLOption, DriverOption]>, HelpText<"Use static debug run-time">; -def _SLASH_o : CLJoinedOrSeparate<"o">, - HelpText<"Deprecated (set output file name); use /Fe or /Fe">, - MetaVarName<"">; -def _SLASH_P : CLFlag<"P">, HelpText<"Preprocess to file">; -def _SLASH_Tc : CLCompileJoinedOrSeparate<"Tc">, - HelpText<"Treat as C source file">, MetaVarName<"">; -def _SLASH_TC : CLCompileFlag<"TC">, HelpText<"Treat all source files as C">; -def _SLASH_Tp : CLCompileJoinedOrSeparate<"Tp">, - HelpText<"Treat as C++ source file">, MetaVarName<"">; -def _SLASH_TP : CLCompileFlag<"TP">, HelpText<"Treat all source files as C++">; -def _SLASH_volatile_iso : Option<["/", "-"], "volatile:iso", KIND_FLAG>, - Group<_SLASH_volatile_Group>, Flags<[CLOption, DriverOption]>, - HelpText<"Volatile loads and stores have standard semantics">; -def _SLASH_vmb : CLFlag<"vmb">, - HelpText<"Use a best-case representation method for member pointers">; -def _SLASH_vmg : CLFlag<"vmg">, - HelpText<"Use a most-general representation for member pointers">; -def _SLASH_vms : CLFlag<"vms">, - HelpText<"Set the default most-general representation to single inheritance">; -def _SLASH_vmm : CLFlag<"vmm">, - HelpText<"Set the default most-general representation to " - "multiple inheritance">; -def _SLASH_vmv : CLFlag<"vmv">, - HelpText<"Set the default most-general representation to " - "virtual inheritance">; -def _SLASH_volatile_ms : Option<["/", "-"], "volatile:ms", KIND_FLAG>, - Group<_SLASH_volatile_Group>, Flags<[CLOption, DriverOption]>, - HelpText<"Volatile loads and stores have acquire and release semantics">; -def _SLASH_clang : CLJoined<"clang:">, - HelpText<"Pass to the clang driver">, MetaVarName<"">; -def _SLASH_Zl : CLFlag<"Zl">, - HelpText<"Do not let object file auto-link default libraries">; - -def _SLASH_Yc : CLJoined<"Yc">, - HelpText<"Generate a pch file for all code up to and including ">, - MetaVarName<"">; -def _SLASH_Yu : CLJoined<"Yu">, - HelpText<"Load a pch file and use it instead of all code up to " - "and including ">, - MetaVarName<"">; -def _SLASH_Y_ : CLFlag<"Y-">, - HelpText<"Disable precompiled headers, overrides /Yc and /Yu">; -def _SLASH_Zc_dllexportInlines : CLFlag<"Zc:dllexportInlines">, - HelpText<"dllexport/dllimport inline member functions of dllexport/import classes (default)">; -def _SLASH_Zc_dllexportInlines_ : CLFlag<"Zc:dllexportInlines-">, - HelpText<"Do not dllexport/dllimport inline member functions of dllexport/import classes">; -def _SLASH_Fp : CLJoined<"Fp">, - HelpText<"Set pch file name (with /Yc and /Yu)">, MetaVarName<"">; - -def _SLASH_Gd : CLFlag<"Gd">, - HelpText<"Set __cdecl as a default calling convention">; -def _SLASH_Gr : CLFlag<"Gr">, - HelpText<"Set __fastcall as a default calling convention">; -def _SLASH_Gz : CLFlag<"Gz">, - HelpText<"Set __stdcall as a default calling convention">; -def _SLASH_Gv : CLFlag<"Gv">, - HelpText<"Set __vectorcall as a default calling convention">; -def _SLASH_Gregcall : CLFlag<"Gregcall">, - HelpText<"Set __regcall as a default calling convention">; - -// Ignored: - -def _SLASH_analyze_ : CLIgnoredFlag<"analyze-">; -def _SLASH_bigobj : CLIgnoredFlag<"bigobj">; -def _SLASH_cgthreads : CLIgnoredJoined<"cgthreads">; -def _SLASH_d2FastFail : CLIgnoredFlag<"d2FastFail">; -def _SLASH_d2Zi_PLUS : CLIgnoredFlag<"d2Zi+">; -def _SLASH_errorReport : CLIgnoredJoined<"errorReport">; -def _SLASH_FC : CLIgnoredFlag<"FC">; -def _SLASH_Fd : CLIgnoredJoined<"Fd">; -def _SLASH_FS : CLIgnoredFlag<"FS">; -def _SLASH_JMC : CLIgnoredFlag<"JMC">; -def _SLASH_kernel_ : CLIgnoredFlag<"kernel-">; -def _SLASH_nologo : CLIgnoredFlag<"nologo">; -def _SLASH_permissive_ : CLIgnoredFlag<"permissive-">; -def _SLASH_RTC : CLIgnoredJoined<"RTC">; -def _SLASH_sdl : CLIgnoredFlag<"sdl">; -def _SLASH_sdl_ : CLIgnoredFlag<"sdl-">; -def _SLASH_utf8 : CLIgnoredFlag<"utf-8">, - HelpText<"Set source and runtime encoding to UTF-8 (default)">; -def _SLASH_w : CLIgnoredJoined<"w">; -def _SLASH_Zc___cplusplus : CLIgnoredFlag<"Zc:__cplusplus">; -def _SLASH_Zc_auto : CLIgnoredFlag<"Zc:auto">; -def _SLASH_Zc_forScope : CLIgnoredFlag<"Zc:forScope">; -def _SLASH_Zc_inline : CLIgnoredFlag<"Zc:inline">; -def _SLASH_Zc_rvalueCast : CLIgnoredFlag<"Zc:rvalueCast">; -def _SLASH_Zc_ternary : CLIgnoredFlag<"Zc:ternary">; -def _SLASH_Zc_wchar_t : CLIgnoredFlag<"Zc:wchar_t">; -def _SLASH_ZH_MD5 : CLIgnoredFlag<"ZH:MD5">; -def _SLASH_ZH_SHA1 : CLIgnoredFlag<"ZH:SHA1">; -def _SLASH_ZH_SHA_256 : CLIgnoredFlag<"ZH:SHA_256">; -def _SLASH_Zm : CLIgnoredJoined<"Zm">; -def _SLASH_Zo : CLIgnoredFlag<"Zo">; -def _SLASH_Zo_ : CLIgnoredFlag<"Zo-">; - - -// Unsupported: - -def _SLASH_await : CLFlag<"await">; -def _SLASH_constexpr : CLJoined<"constexpr:">; -def _SLASH_AI : CLJoinedOrSeparate<"AI">; -def _SLASH_Bt : CLFlag<"Bt">; -def _SLASH_Bt_plus : CLFlag<"Bt+">; -def _SLASH_clr : CLJoined<"clr">; -def _SLASH_d2 : CLJoined<"d2">; -def _SLASH_doc : CLJoined<"doc">; -def _SLASH_FA_joined : CLJoined<"FA">; -def _SLASH_favor : CLJoined<"favor">; -def _SLASH_F : CLJoinedOrSeparate<"F">; -def _SLASH_Fm : CLJoined<"Fm">; -def _SLASH_Fr : CLJoined<"Fr">; -def _SLASH_FR : CLJoined<"FR">; -def _SLASH_FU : CLJoinedOrSeparate<"FU">; -def _SLASH_Fx : CLFlag<"Fx">; -def _SLASH_G1 : CLFlag<"G1">; -def _SLASH_G2 : CLFlag<"G2">; -def _SLASH_Ge : CLFlag<"Ge">; -def _SLASH_Gh : CLFlag<"Gh">; -def _SLASH_GH : CLFlag<"GH">; -def _SLASH_GL : CLFlag<"GL">; -def _SLASH_GL_ : CLFlag<"GL-">; -def _SLASH_Gm : CLFlag<"Gm">; -def _SLASH_Gm_ : CLFlag<"Gm-">; -def _SLASH_GT : CLFlag<"GT">; -def _SLASH_GZ : CLFlag<"GZ">; -def _SLASH_H : CLFlag<"H">; -def _SLASH_homeparams : CLFlag<"homeparams">; -def _SLASH_hotpatch : CLFlag<"hotpatch">; -def _SLASH_kernel : CLFlag<"kernel">; -def _SLASH_LN : CLFlag<"LN">; -def _SLASH_MP : CLJoined<"MP">; -def _SLASH_Qfast_transcendentals : CLFlag<"Qfast_transcendentals">; -def _SLASH_QIfist : CLFlag<"QIfist">; -def _SLASH_Qimprecise_fwaits : CLFlag<"Qimprecise_fwaits">; -def _SLASH_Qpar : CLFlag<"Qpar">; -def _SLASH_Qpar_report : CLJoined<"Qpar-report">; -def _SLASH_Qsafe_fp_loads : CLFlag<"Qsafe_fp_loads">; -def _SLASH_Qspectre : CLFlag<"Qspectre">; -def _SLASH_Qvec_report : CLJoined<"Qvec-report">; -def _SLASH_u : CLFlag<"u">; -def _SLASH_V : CLFlag<"V">; -def _SLASH_WL : CLFlag<"WL">; -def _SLASH_Wp64 : CLFlag<"Wp64">; -def _SLASH_Yd : CLFlag<"Yd">; -def _SLASH_Yl : CLJoined<"Yl">; -def _SLASH_Za : CLFlag<"Za">; -def _SLASH_Zc : CLJoined<"Zc:">; -def _SLASH_Ze : CLFlag<"Ze">; -def _SLASH_Zg : CLFlag<"Zg">; -def _SLASH_ZI : CLFlag<"ZI">; -def _SLASH_ZW : CLJoined<"ZW">; diff --git a/gnu/llvm/clang/include/clang/Driver/Options.td b/gnu/llvm/clang/include/clang/Driver/Options.td index a370a522e84..356cfb0ae9e 100644 --- a/gnu/llvm/clang/include/clang/Driver/Options.td +++ b/gnu/llvm/clang/include/clang/Driver/Options.td @@ -124,6 +124,9 @@ def pedantic_Group : OptionGroup<"">, Group, def opencl_Group : OptionGroup<"">, Group, DocName<"OpenCL flags">; +def sycl_Group : OptionGroup<"">, Group, + DocName<"SYCL flags">; + def m_Group : OptionGroup<"">, Group, DocName<"Target-dependent compilation options">; @@ -148,6 +151,10 @@ def m_ppc_Features_Group : OptionGroup<"">, Group, DocName<"PowerPC">; def m_wasm_Features_Group : OptionGroup<"">, Group, DocName<"WebAssembly">; +// The features added by this group will not be added to target features. +// These are explicitly handled. +def m_wasm_Features_Driver_Group : OptionGroup<"">, + Group, DocName<"WebAssembly Driver">; def m_x86_Features_Group : OptionGroup<"">, Group, Flags<[CoreOption]>, DocName<"X86">; def m_riscv_Features_Group : OptionGroup<"">, @@ -219,6 +226,27 @@ def mno_mpx : Flag<["-"], "mno-mpx">, Group; def clang_ignored_gcc_optimization_f_Group : OptionGroup< "">, Group, Flags<[Ignored]>; +// A boolean option which is opt-in in CC1. The positive option exists in CC1 and +// Args.hasArg(OPT_ffoo) is used to check that the flag is enabled. +// This is useful if the option is usually disabled. +multiclass OptInFFlag flags=[]> { + def f#NAME : Flag<["-"], "f"#name>, Flags, + Group, HelpText; + def fno_#NAME : Flag<["-"], "fno-"#name>, Flags, + Group, HelpText; +} + +// A boolean option which is opt-out in CC1. The negative option exists in CC1 and +// Args.hasArg(OPT_fno_foo) is used to check that the flag is disabled. +multiclass OptOutFFlag flags=[]> { + def f#NAME : Flag<["-"], "f"#name>, Flags, + Group, HelpText; + def fno_#NAME : Flag<["-"], "fno-"#name>, Flags, + Group, HelpText; +} + ///////// // Options @@ -397,7 +425,7 @@ def ObjCXX : Flag<["-"], "ObjC++">, Flags<[DriverOption]>, def ObjC : Flag<["-"], "ObjC">, Flags<[DriverOption]>, HelpText<"Treat source input files as Objective-C inputs">; def O : Joined<["-"], "O">, Group, Flags<[CC1Option]>; -def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, Alias, AliasArgs<["2"]>; +def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, Alias, AliasArgs<["1"]>; def Ofast : Joined<["-"], "Ofast">, Group, Flags<[CC1Option]>; def P : Flag<["-"], "P">, Flags<[CC1Option]>, Group, HelpText<"Disable linemarker output in -E mode">; @@ -455,6 +483,9 @@ def Wnonportable_cfstrings : Joined<["-"], "Wnonportable-cfstrings">, Group, HelpText<"Pass the comma separated arguments in to the preprocessor">, MetaVarName<"">, Group; +def Wundef_prefix_EQ : CommaJoined<["-"], "Wundef-prefix=">, Group, + Flags<[CC1Option, CoreOption, HelpHidden]>, MetaVarName<"">, + HelpText<"Enable warnings for undefined macros with a prefix in the comma separated list ">; def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, Flags<[CC1Option, HelpHidden]>; def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, Flags<[CC1Option, HelpHidden]>; def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, CoreOption]>, @@ -463,6 +494,10 @@ def Xanalyzer : Separate<["-"], "Xanalyzer">, HelpText<"Pass to the static analyzer">, MetaVarName<"">, Group; def Xarch__ : JoinedAndSeparate<["-"], "Xarch_">, Flags<[DriverOption]>; +def Xarch_host : Separate<["-"], "Xarch_host">, Flags<[DriverOption]>, + HelpText<"Pass to the CUDA/HIP host compilation">, MetaVarName<"">; +def Xarch_device : Separate<["-"], "Xarch_device">, Flags<[DriverOption]>, + HelpText<"Pass to the CUDA/HIP device compilation">, MetaVarName<"">; def Xassembler : Separate<["-"], "Xassembler">, HelpText<"Pass to the assembler">, MetaVarName<"">, Group; @@ -523,7 +558,7 @@ def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, Group, HelpText<"OpenCL only. Allow use of less precise no signed zeros computations in the generated binary.">; def cl_std_EQ : Joined<["-"], "cl-std=">, Group, Flags<[CC1Option]>, HelpText<"OpenCL language standard to compile for.">, Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,clc++,CLC++">; -def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, Group, Flags<[CC1Option]>, +def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, Group, HelpText<"OpenCL only. Allow denormals to be flushed to zero.">; def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], "cl-fp32-correctly-rounded-divide-sqrt">, Group, Flags<[CC1Option]>, HelpText<"OpenCL only. Specify that single precision floating-point divide and sqrt used in the program source are correctly rounded.">; @@ -549,6 +584,9 @@ def c : Flag<["-"], "c">, Flags<[DriverOption]>, Group, def fconvergent_functions : Flag<["-"], "fconvergent-functions">, Group, Flags<[CC1Option]>, HelpText<"Assume functions may be convergent">; +def gpu_use_aux_triple_only : Flag<["--"], "gpu-use-aux-triple-only">, + InternalDriverOpt, HelpText<"Prepare '-aux-triple' only without populating " + "'-aux-target-cpu' and '-aux-target-feature'.">; def cuda_device_only : Flag<["--"], "cuda-device-only">, HelpText<"Compile CUDA code for device only">; def cuda_host_only : Flag<["--"], "cuda-host-only">, @@ -561,13 +599,19 @@ def cuda_include_ptx_EQ : Joined<["--"], "cuda-include-ptx=">, Flags<[DriverOpti HelpText<"Include PTX for the following GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.">; def no_cuda_include_ptx_EQ : Joined<["--"], "no-cuda-include-ptx=">, Flags<[DriverOption]>, HelpText<"Do not include PTX for the following GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.">; +def offload_arch_EQ : Joined<["--"], "offload-arch=">, Flags<[DriverOption]>, + HelpText<"CUDA/HIP offloading device architecture (e.g. sm_35, gfx906). May be specified more than once.">; def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[DriverOption]>, - HelpText<"CUDA GPU architecture (e.g. sm_35). May be specified more than once.">; + Alias; def hip_link : Flag<["--"], "hip-link">, HelpText<"Link clang-offload-bundler bundles for HIP">; -def no_cuda_gpu_arch_EQ : Joined<["--"], "no-cuda-gpu-arch=">, Flags<[DriverOption]>, - HelpText<"Remove GPU architecture (e.g. sm_35) from the list of GPUs to compile for. " +def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">, Flags<[DriverOption]>, + HelpText<"Remove CUDA/HIP offloading device architecture (e.g. sm_35, gfx906) from the list of devices to compile for. " "'all' resets the list to its default value.">; +def emit_static_lib : Flag<["--"], "emit-static-lib">, + HelpText<"Enable linker job to emit a static library.">; +def no_cuda_gpu_arch_EQ : Joined<["--"], "no-cuda-gpu-arch=">, Flags<[DriverOption]>, + Alias; def cuda_noopt_device_debug : Flag<["--"], "cuda-noopt-device-debug">, HelpText<"Enable device-side debug info generation. Disables ptxas optimizations.">; def no_cuda_version_check : Flag<["--"], "no-cuda-version-check">, @@ -581,31 +625,31 @@ def cuda_path_ignore_env : Flag<["--"], "cuda-path-ignore-env">, Group, def ptxas_path_EQ : Joined<["--"], "ptxas-path=">, Group, HelpText<"Path to ptxas (used for compiling CUDA code)">; def fcuda_flush_denormals_to_zero : Flag<["-"], "fcuda-flush-denormals-to-zero">, - Flags<[CC1Option]>, HelpText<"Flush denormal floating point values to zero in CUDA device mode.">; + HelpText<"Flush denormal floating point values to zero in CUDA device mode.">; def fno_cuda_flush_denormals_to_zero : Flag<["-"], "fno-cuda-flush-denormals-to-zero">; -def fcuda_approx_transcendentals : Flag<["-"], "fcuda-approx-transcendentals">, - Flags<[CC1Option]>, HelpText<"Use approximate transcendental functions">; -def fno_cuda_approx_transcendentals : Flag<["-"], "fno-cuda-approx-transcendentals">; -def fgpu_rdc : Flag<["-"], "fgpu-rdc">, Flags<[CC1Option]>, - HelpText<"Generate relocatable device code, also known as separate compilation mode.">; -def fno_gpu_rdc : Flag<["-"], "fno-gpu-rdc">; +defm cuda_approx_transcendentals : OptInFFlag<"cuda-approx-transcendentals", "Use", "Don't use", + " approximate transcendental functions">; +defm gpu_rdc : OptInFFlag<"gpu-rdc", + "Generate relocatable device code, also known as separate compilation mode", "", "">; def : Flag<["-"], "fcuda-rdc">, Alias; def : Flag<["-"], "fno-cuda-rdc">, Alias; -def fcuda_short_ptr : Flag<["-"], "fcuda-short-ptr">, Flags<[CC1Option]>, - HelpText<"Use 32-bit pointers for accessing const/local/shared address spaces.">; -def fno_cuda_short_ptr : Flag<["-"], "fno-cuda-short-ptr">; -def hip_device_lib_path_EQ : Joined<["--"], "hip-device-lib-path=">, Group, - HelpText<"HIP device library path">; +defm cuda_short_ptr : OptInFFlag<"cuda-short-ptr", + "Use 32-bit pointers for accessing const/local/shared address spaces">; +def rocm_path_EQ : Joined<["--"], "rocm-path=">, Group, + HelpText<"ROCm installation path, used for finding and automatically linking required bitcode libraries.">; +def rocm_device_lib_path_EQ : Joined<["--"], "rocm-device-lib-path=">, Group, + HelpText<"ROCm device library path. Alternative to rocm-path.">; +def : Joined<["--"], "hip-device-lib-path=">, Alias; def hip_device_lib_EQ : Joined<["--"], "hip-device-lib=">, Group, HelpText<"HIP device library">; +def hip_version_EQ : Joined<["--"], "hip-version=">, + HelpText<"HIP version in the format of major.minor.patch">; def fhip_dump_offload_linker_script : Flag<["-"], "fhip-dump-offload-linker-script">, Group, Flags<[NoArgumentUnused, HelpHidden]>; -def fhip_new_launch_api : Flag<["-"], "fhip-new-launch-api">, - Flags<[CC1Option]>, HelpText<"Use new kernel launching API for HIP.">; -def fno_hip_new_launch_api : Flag<["-"], "fno-hip-new-launch-api">; -def fgpu_allow_device_init : Flag<["-"], "fgpu-allow-device-init">, - Flags<[CC1Option]>, HelpText<"Allow device side init function in HIP">; -def fno_gpu_allow_device_init : Flag<["-"], "fno-gpu-allow-device-init">; +defm hip_new_launch_api : OptInFFlag<"hip-new-launch-api", + "Use", "Don't use", " new kernel launching API for HIP">; +defm gpu_allow_device_init : OptInFFlag<"gpu-allow-device-init", + "Allow", "Don't allow", " device side init function in HIP">; def gpu_max_threads_per_block_EQ : Joined<["--"], "gpu-max-threads-per-block=">, Flags<[CC1Option]>, HelpText<"Default max threads per block for kernel launch bounds for HIP">; @@ -646,14 +690,17 @@ def emit_merged_ifs : Flag<["-"], "emit-merged-ifs">, def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Flags<[CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; def e : JoinedOrSeparate<["-"], "e">, Group; +def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group, Flags<[CC1Option]>, + HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">; def fPIC : Flag<["-"], "fPIC">, Group; def fno_PIC : Flag<["-"], "fno-PIC">, Group; def fPIE : Flag<["-"], "fPIE">, Group; def fno_PIE : Flag<["-"], "fno-PIE">, Group; -def faccess_control : Flag<["-"], "faccess-control">, Group; +defm access_control : OptOutFFlag<"no-access-control", "", "Disable C++ access control">; def falign_functions : Flag<["-"], "falign-functions">, Group; def falign_functions_EQ : Joined<["-"], "falign-functions=">, Group; def fno_align_functions: Flag<["-"], "fno-align-functions">, Group; +defm allow_editor_placeholders : OptInFFlag<"allow-editor-placeholders", "Treat editor placeholders as valid source code">; def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group; def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]>, HelpText<"Use Apple's kernel extensions ABI">; @@ -666,8 +713,7 @@ def static_libsan : Flag<["-"], "static-libsan">, def : Flag<["-"], "shared-libasan">, Alias; def fasm : Flag<["-"], "fasm">, Group; -def fasm_blocks : Flag<["-"], "fasm-blocks">, Group, Flags<[CC1Option]>; -def fno_asm_blocks : Flag<["-"], "fno-asm-blocks">, Group; +defm asm_blocks : OptInFFlag<"asm-blocks", "">; def fassume_sane_operator_new : Flag<["-"], "fassume-sane-operator-new">, Group; def fastcp : Flag<["-"], "fastcp">, Group; @@ -682,17 +728,10 @@ def fno_double_square_bracket_attributes : Flag<[ "-" ], "fno-double-square-brac Group, Flags<[DriverOption, CC1Option]>, HelpText<"Disable '[[]]' attributes in all C and C++ language modes">; -def fautolink : Flag <["-"], "fautolink">, Group; -def fno_autolink : Flag <["-"], "fno-autolink">, Group, - Flags<[DriverOption, CC1Option]>, - HelpText<"Disable generation of linker directives for automatic library linking">; +defm autolink : OptOutFFlag<"autolink", "", "Disable generation of linker directives for automatic library linking">; // C++ Coroutines TS -def fcoroutines_ts : Flag <["-"], "fcoroutines-ts">, Group, - Flags<[DriverOption, CC1Option]>, - HelpText<"Enable support for the C++ Coroutines TS">; -def fno_coroutines_ts : Flag <["-"], "fno-coroutines-ts">, Group, - Flags<[DriverOption]>; +defm coroutines_ts : OptInFFlag<"coroutines-ts", "Enable support for the C++ Coroutines TS">; def fembed_bitcode_EQ : Joined<["-"], "fembed-bitcode=">, Group, Flags<[DriverOption, CC1Option, CC1AsOption]>, MetaVarName<"