1 //==--- Attr.td - attribute definitions -----------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // The documentation is organized by category. Attributes can have category-
10 // specific documentation that is collated within the larger document.
11 class DocumentationCategory<string name> {
15 def DocCatFunction : DocumentationCategory<"Function Attributes">;
16 def DocCatVariable : DocumentationCategory<"Variable Attributes">;
17 def DocCatField : DocumentationCategory<"Field Attributes">;
18 def DocCatType : DocumentationCategory<"Type Attributes">;
19 def DocCatStmt : DocumentationCategory<"Statement Attributes">;
20 def DocCatDecl : DocumentationCategory<"Declaration Attributes">;
22 // Attributes listed under the Undocumented category do not generate any public
23 // documentation. Ideally, this category should be used for internal-only
24 // attributes which contain no spellings.
25 def DocCatUndocumented : DocumentationCategory<"Undocumented">;
27 class DocDeprecated<string replacement = ""> {
28 // If the Replacement field is empty, no replacement will be listed with the
29 // documentation. Otherwise, the documentation will specify the attribute has
30 // been superseded by this replacement.
31 string Replacement = replacement;
34 // Specifies the documentation to be associated with the given category.
36 DocumentationCategory Category;
39 // If the heading is empty, one may be picked automatically. If the attribute
40 // only has one spelling, no heading is required as the attribute's sole
41 // spelling is sufficient. If all spellings are semantically common, the
42 // heading will be the semantic spelling. If the spellings are not
43 // semantically common and no heading is provided, an error will be emitted.
46 // When set, specifies that the attribute is deprecated and can optionally
47 // specify a replacement attribute.
48 DocDeprecated Deprecated;
51 // Specifies that the attribute is explicitly undocumented. This can be a
52 // helpful placeholder for the attribute while working on the implementation,
53 // but should not be used once feature work has been completed.
54 def Undocumented : Documentation {
55 let Category = DocCatUndocumented;
58 include "clang/Basic/AttrDocs.td"
60 // An attribute's subject is whatever it appertains to. In this file, it is
61 // more accurately a list of things that an attribute can appertain to. All
62 // Decls and Stmts are possibly AttrSubjects (even though the syntax may not
63 // allow attributes on a given Decl or Stmt).
66 include "clang/Basic/DeclNodes.td"
67 include "clang/Basic/StmtNodes.td"
69 // A subset-subject is an AttrSubject constrained to operate only on some subset
72 // The code fragment is a boolean expression that will confirm that the subject
73 // meets the requirements; the subject will have the name S, and will have the
74 // type specified by the base. It should be a simple boolean expression. The
75 // diagnostic string should be a comma-separated list of subject names.
76 class SubsetSubject<AttrSubject base, code check, string diag> : AttrSubject {
77 AttrSubject Base = base;
78 code CheckCode = check;
79 string DiagSpelling = diag;
82 def LocalVar : SubsetSubject<Var,
83 [{S->hasLocalStorage() && !isa<ParmVarDecl>(S)}],
85 def NonParmVar : SubsetSubject<Var,
86 [{S->getKind() != Decl::ParmVar}],
88 def NonLocalVar : SubsetSubject<Var,
89 [{!S->hasLocalStorage()}],
90 "variables with non-local storage">;
91 def NonBitField : SubsetSubject<Field,
93 "non-bit-field non-static data members">;
95 def NonStaticCXXMethod : SubsetSubject<CXXMethod,
97 "non-static member functions">;
99 def NonStaticNonConstCXXMethod
100 : SubsetSubject<CXXMethod,
101 [{!S->isStatic() && !S->isConst()}],
102 "non-static non-const member functions">;
104 def ObjCInstanceMethod : SubsetSubject<ObjCMethod,
105 [{S->isInstanceMethod()}],
106 "Objective-C instance methods">;
108 def Struct : SubsetSubject<Record,
109 [{!S->isUnion()}], "structs">;
111 def TLSVar : SubsetSubject<Var,
112 [{S->getTLSKind() != 0}], "thread-local variables">;
114 def SharedVar : SubsetSubject<Var,
115 [{S->hasGlobalStorage() && !S->getTLSKind()}],
118 def GlobalVar : SubsetSubject<Var,
119 [{S->hasGlobalStorage()}], "global variables">;
121 def InlineFunction : SubsetSubject<Function,
122 [{S->isInlineSpecified()}], "inline functions">;
125 : SubsetSubject<Function, [{S->getTemplatedKind() ==
126 FunctionDecl::TK_FunctionTemplate}],
127 "function templates">;
129 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
130 // type to be a class, not a definition. This makes it impossible to create an
131 // attribute subject which accepts a Decl. Normally, this is not a problem,
132 // because the attribute can have no Subjects clause to accomplish this. But in
133 // the case of a SubsetSubject, there's no way to express it without this hack.
134 def DeclBase : AttrSubject;
135 def FunctionLike : SubsetSubject<DeclBase,
136 [{S->getFunctionType(false) != nullptr}],
137 "functions, function pointers">;
139 def OpenCLKernelFunction
140 : SubsetSubject<Function, [{S->hasAttr<OpenCLKernelAttr>()}],
143 // HasFunctionProto is a more strict version of FunctionLike, so it should
144 // never be specified in a Subjects list along with FunctionLike (due to the
145 // inclusive nature of subject testing).
146 def HasFunctionProto : SubsetSubject<DeclBase,
147 [{(S->getFunctionType(true) != nullptr &&
148 isa<FunctionProtoType>(S->getFunctionType())) ||
149 isa<ObjCMethodDecl>(S) ||
151 "non-K&R-style functions">;
153 // A subject that matches the implicit object parameter of a non-static member
154 // function. Accepted as a function type attribute on the type of such a
156 // FIXME: This does not actually ever match currently.
157 def ImplicitObjectParameter
158 : SubsetSubject<Function, [{static_cast<void>(S), false}],
159 "implicit object parameters">;
161 // A single argument to an attribute
162 class Argument<string name, bit optional, bit fake = 0> {
164 bit Optional = optional;
166 /// A fake argument is used to store and serialize additional information
167 /// in an attribute without actually changing its parsing or pretty-printing.
171 class BoolArgument<string name, bit opt = 0, bit fake = 0> : Argument<name, opt,
173 class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
174 class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
175 class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
176 class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
177 class FunctionArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
180 class NamedArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
183 class TypeArgument<string name, bit opt = 0> : Argument<name, opt>;
184 class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
185 class VariadicUnsignedArgument<string name> : Argument<name, 1>;
186 class VariadicExprArgument<string name> : Argument<name, 1>;
187 class VariadicStringArgument<string name> : Argument<name, 1>;
188 class VariadicIdentifierArgument<string name> : Argument<name, 1>;
190 // Like VariadicUnsignedArgument except values are ParamIdx.
191 class VariadicParamIdxArgument<string name> : Argument<name, 1>;
193 // A list of identifiers matching parameters or ParamIdx indices.
194 class VariadicParamOrParamIdxArgument<string name> : Argument<name, 1>;
196 // Like VariadicParamIdxArgument but for a single function parameter index.
197 class ParamIdxArgument<string name, bit opt = 0> : Argument<name, opt>;
199 // A version of the form major.minor[.subminor].
200 class VersionArgument<string name, bit opt = 0> : Argument<name, opt>;
202 // This one's a doozy, so it gets its own special type
203 // It can be an unsigned integer, or a type. Either can
205 class AlignedArgument<string name, bit opt = 0> : Argument<name, opt>;
207 // A bool argument with a default value
208 class DefaultBoolArgument<string name, bit default, bit fake = 0>
209 : BoolArgument<name, 1, fake> {
210 bit Default = default;
213 // An integer argument with a default value
214 class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
215 int Default = default;
218 // This argument is more complex, it includes the enumerator type name,
219 // a list of strings to accept, and a list of enumerators to map them to.
220 class EnumArgument<string name, string type, list<string> values,
221 list<string> enums, bit opt = 0, bit fake = 0>
222 : Argument<name, opt, fake> {
224 list<string> Values = values;
225 list<string> Enums = enums;
228 // FIXME: There should be a VariadicArgument type that takes any other type
229 // of argument and generates the appropriate type.
230 class VariadicEnumArgument<string name, string type, list<string> values,
231 list<string> enums> : Argument<name, 1> {
233 list<string> Values = values;
234 list<string> Enums = enums;
237 // This handles one spelling of an attribute.
238 class Spelling<string name, string variety> {
240 string Variety = variety;
244 class GNU<string name> : Spelling<name, "GNU">;
245 class Declspec<string name> : Spelling<name, "Declspec">;
246 class Microsoft<string name> : Spelling<name, "Microsoft">;
247 class CXX11<string namespace, string name, int version = 1>
248 : Spelling<name, "CXX11"> {
249 string Namespace = namespace;
250 int Version = version;
252 class C2x<string namespace, string name> : Spelling<name, "C2x"> {
253 string Namespace = namespace;
256 class Keyword<string name> : Spelling<name, "Keyword">;
257 class Pragma<string namespace, string name> : Spelling<name, "Pragma"> {
258 string Namespace = namespace;
261 // The GCC spelling implies GNU<name> and CXX11<"gnu", name> and also sets
262 // KnownToGCC to 1. This spelling should be used for any GCC-compatible
264 class GCC<string name> : Spelling<name, "GCC"> {
268 // The Clang spelling implies GNU<name>, CXX11<"clang", name>, and optionally,
269 // C2x<"clang", name>. This spelling should be used for any Clang-specific
271 class Clang<string name, bit allowInC = 1> : Spelling<name, "Clang"> {
272 bit AllowInC = allowInC;
275 class Accessor<string name, list<Spelling> spellings> {
277 list<Spelling> Spellings = spellings;
280 class SubjectDiag<bit warn> {
283 def WarnDiag : SubjectDiag<1>;
284 def ErrorDiag : SubjectDiag<0>;
286 class SubjectList<list<AttrSubject> subjects, SubjectDiag diag = WarnDiag,
287 string customDiag = ""> {
288 list<AttrSubject> Subjects = subjects;
289 SubjectDiag Diag = diag;
290 string CustomDiag = customDiag;
293 class LangOpt<string name, code customCode = [{}]> {
296 // A custom predicate, written as an expression evaluated in a context with
298 code CustomCode = customCode;
300 def MicrosoftExt : LangOpt<"MicrosoftExt">;
301 def Borland : LangOpt<"Borland">;
302 def CUDA : LangOpt<"CUDA">;
303 def HIP : LangOpt<"HIP">;
304 def SYCL : LangOpt<"SYCLIsDevice">;
305 def COnly : LangOpt<"COnly", "!LangOpts.CPlusPlus">;
306 def CPlusPlus : LangOpt<"CPlusPlus">;
307 def OpenCL : LangOpt<"OpenCL">;
308 def RenderScript : LangOpt<"RenderScript">;
309 def ObjC : LangOpt<"ObjC">;
310 def BlocksSupported : LangOpt<"Blocks">;
311 def ObjCAutoRefCount : LangOpt<"ObjCAutoRefCount">;
312 def ObjCNonFragileRuntime : LangOpt<"ObjCNonFragileRuntime",
313 "LangOpts.ObjCRuntime.allowsClassStubs()">;
315 // Language option for CMSE extensions
316 def Cmse : LangOpt<"Cmse">;
318 // Defines targets for target-specific attributes. Empty lists are unchecked.
320 // Specifies Architectures for which the target applies, based off the
321 // ArchType enumeration in Triple.h.
322 list<string> Arches = [];
323 // Specifies Operating Systems for which the target applies, based off the
324 // OSType enumeration in Triple.h
326 // Specifies Object Formats for which the target applies, based off the
327 // ObjectFormatType enumeration in Triple.h
328 list<string> ObjectFormats;
329 // A custom predicate, written as an expression evaluated in a context
330 // with the following declarations in scope:
331 // const clang::TargetInfo &Target;
332 // const llvm::Triple &T = Target.getTriple();
333 code CustomCode = [{}];
336 class TargetArch<list<string> arches> : TargetSpec {
339 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
340 def TargetAVR : TargetArch<["avr"]>;
341 def TargetBPF : TargetArch<["bpfel", "bpfeb"]>;
342 def TargetMips32 : TargetArch<["mips", "mipsel"]>;
343 def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
344 def TargetMSP430 : TargetArch<["msp430"]>;
345 def TargetRISCV : TargetArch<["riscv32", "riscv64"]>;
346 def TargetX86 : TargetArch<["x86"]>;
347 def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
348 def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>;
349 def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb", "aarch64"]> {
350 let OSes = ["Win32"];
352 def TargetItaniumCXXABI : TargetSpec {
353 let CustomCode = [{ Target.getCXXABI().isItaniumFamily() }];
355 def TargetMicrosoftCXXABI : TargetArch<["x86", "x86_64", "arm", "thumb", "aarch64"]> {
356 let CustomCode = [{ Target.getCXXABI().isMicrosoft() }];
358 def TargetELF : TargetSpec {
359 let ObjectFormats = ["ELF"];
362 // Attribute subject match rules that are used for #pragma clang attribute.
364 // A instance of AttrSubjectMatcherRule represents an individual match rule.
365 // An individual match rule can correspond to a number of different attribute
366 // subjects, e.g. "record" matching rule corresponds to the Record and
367 // CXXRecord attribute subjects.
369 // Match rules are used in the subject list of the #pragma clang attribute.
370 // Match rules can have sub-match rules that are instances of
371 // AttrSubjectMatcherSubRule. A sub-match rule can correspond to a number
372 // of different attribute subjects, and it can have a negated spelling as well.
373 // For example, "variable(unless(is_parameter))" matching rule corresponds to
374 // the NonParmVar attribute subject.
375 class AttrSubjectMatcherSubRule<string name, list<AttrSubject> subjects,
378 list<AttrSubject> Subjects = subjects;
379 bit Negated = negated;
380 // Lists language options, one of which is required to be true for the
381 // attribute to be applicable. If empty, the language options are taken
382 // from the parent matcher rule.
383 list<LangOpt> LangOpts = [];
385 class AttrSubjectMatcherRule<string name, list<AttrSubject> subjects,
386 list<AttrSubjectMatcherSubRule> subrules = []> {
388 list<AttrSubject> Subjects = subjects;
389 list<AttrSubjectMatcherSubRule> Constraints = subrules;
390 // Lists language options, one of which is required to be true for the
391 // attribute to be applicable. If empty, no language options are required.
392 list<LangOpt> LangOpts = [];
395 // function(is_member)
396 def SubRuleForCXXMethod : AttrSubjectMatcherSubRule<"is_member", [CXXMethod]> {
397 let LangOpts = [CPlusPlus];
399 def SubjectMatcherForFunction : AttrSubjectMatcherRule<"function", [Function], [
402 // hasType is abstract, it should be used with one of the sub-rules.
403 def SubjectMatcherForType : AttrSubjectMatcherRule<"hasType", [], [
404 AttrSubjectMatcherSubRule<"functionType", [FunctionLike]>
406 // FIXME: There's a matcher ambiguity with objc methods and blocks since
407 // functionType excludes them but functionProtoType includes them.
408 // AttrSubjectMatcherSubRule<"functionProtoType", [HasFunctionProto]>
410 def SubjectMatcherForTypedef : AttrSubjectMatcherRule<"type_alias",
412 def SubjectMatcherForRecord : AttrSubjectMatcherRule<"record", [Record,
415 AttrSubjectMatcherSubRule<"is_union", [Struct], 1>
417 def SubjectMatcherForEnum : AttrSubjectMatcherRule<"enum", [Enum]>;
418 def SubjectMatcherForEnumConstant : AttrSubjectMatcherRule<"enum_constant",
420 def SubjectMatcherForVar : AttrSubjectMatcherRule<"variable", [Var], [
421 AttrSubjectMatcherSubRule<"is_thread_local", [TLSVar]>,
422 AttrSubjectMatcherSubRule<"is_global", [GlobalVar]>,
423 AttrSubjectMatcherSubRule<"is_parameter", [ParmVar]>,
424 // unless(is_parameter)
425 AttrSubjectMatcherSubRule<"is_parameter", [NonParmVar], 1>
427 def SubjectMatcherForField : AttrSubjectMatcherRule<"field", [Field]>;
428 def SubjectMatcherForNamespace : AttrSubjectMatcherRule<"namespace",
430 let LangOpts = [CPlusPlus];
432 def SubjectMatcherForObjCInterface : AttrSubjectMatcherRule<"objc_interface",
434 let LangOpts = [ObjC];
436 def SubjectMatcherForObjCProtocol : AttrSubjectMatcherRule<"objc_protocol",
438 let LangOpts = [ObjC];
440 def SubjectMatcherForObjCCategory : AttrSubjectMatcherRule<"objc_category",
442 let LangOpts = [ObjC];
444 def SubjectMatcherForObjCImplementation :
445 AttrSubjectMatcherRule<"objc_implementation", [ObjCImpl]> {
446 let LangOpts = [ObjC];
448 def SubjectMatcherForObjCMethod : AttrSubjectMatcherRule<"objc_method",
450 AttrSubjectMatcherSubRule<"is_instance", [ObjCInstanceMethod]>
452 let LangOpts = [ObjC];
454 def SubjectMatcherForObjCProperty : AttrSubjectMatcherRule<"objc_property",
456 let LangOpts = [ObjC];
458 def SubjectMatcherForBlock : AttrSubjectMatcherRule<"block", [Block]> {
459 let LangOpts = [BlocksSupported];
462 // Aggregate attribute subject match rules are abstract match rules that can't
463 // be used directly in #pragma clang attribute. Instead, users have to use
464 // subject match rules that correspond to attribute subjects that derive from
465 // the specified subject.
466 class AttrSubjectMatcherAggregateRule<AttrSubject subject> {
467 AttrSubject Subject = subject;
470 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule<Named>;
473 // The various ways in which an attribute can be spelled in source
474 list<Spelling> Spellings;
475 // The things to which an attribute can appertain
476 SubjectList Subjects;
477 // The arguments allowed on an attribute
478 list<Argument> Args = [];
479 // Accessors which should be generated for the attribute.
480 list<Accessor> Accessors = [];
481 // Set to true for attributes with arguments which require delayed parsing.
483 // Set to false to prevent an attribute from being propagated from a template
484 // to the instantiation.
486 // Set to true for attributes which must be instantiated within templates
487 bit TemplateDependent = 0;
488 // Set to true for attributes that have a corresponding AST node.
490 // Set to true for attributes which have handler in Sema.
492 // Set to true for attributes that are completely ignored.
494 // Set to true if the attribute's parsing does not match its semantic
495 // content. Eg) It parses 3 args, but semantically takes 4 args. Opts out of
496 // common attribute error checking.
497 bit HasCustomParsing = 0;
498 // Set to true if all of the attribute's arguments should be parsed in an
499 // unevaluated context.
500 bit ParseArgumentsAsUnevaluated = 0;
501 // Set to true if this attribute meaningful when applied to or inherited
502 // in a class template definition.
503 bit MeaningfulToClassTemplateDefinition = 0;
504 // Set to true if this attribute can be used with '#pragma clang attribute'.
505 // By default, an attribute is supported by the '#pragma clang attribute'
507 // - It has a subject list whose subjects can be represented using subject
509 // - It has GNU/CXX11 spelling and doesn't require delayed parsing.
510 bit PragmaAttributeSupport;
511 // Lists language options, one of which is required to be true for the
512 // attribute to be applicable. If empty, no language options are required.
513 list<LangOpt> LangOpts = [];
514 // Any additional text that should be included verbatim in the class.
515 // Note: Any additional data members will leak and should be constructed
516 // externally on the ASTContext.
517 code AdditionalMembers = [{}];
518 // Any documentation that should be associated with the attribute. Since an
519 // attribute may be documented under multiple categories, more than one
520 // Documentation entry may be listed.
521 list<Documentation> Documentation;
524 /// A type attribute is not processed on a declaration or a statement.
525 class TypeAttr : Attr;
527 /// A stmt attribute is not processed on a declaration or a type.
528 class StmtAttr : Attr;
530 /// An inheritable attribute is inherited by later redeclarations.
531 class InheritableAttr : Attr {
532 // Set to true if this attribute can be duplicated on a subject when inheriting
533 // attributes from prior declarations.
534 bit InheritEvenIfAlreadyPresent = 0;
537 /// Some attributes, like calling conventions, can appear in either the
538 /// declaration or the type position. These attributes are morally type
539 /// attributes, but have historically been written on declarations.
540 class DeclOrTypeAttr : InheritableAttr;
542 /// A target-specific attribute. This class is meant to be used as a mixin
543 /// with InheritableAttr or Attr depending on the attribute's needs.
544 class TargetSpecificAttr<TargetSpec target> {
545 TargetSpec Target = target;
546 // Attributes are generally required to have unique spellings for their names
547 // so that the parser can determine what kind of attribute it has parsed.
548 // However, target-specific attributes are special in that the attribute only
549 // "exists" for a given target. So two target-specific attributes can share
550 // the same name when they exist in different targets. To support this, a
551 // Kind can be explicitly specified for a target-specific attribute. This
552 // corresponds to the ParsedAttr::AT_* enum that is generated and it
553 // should contain a shared value between the attributes.
555 // Target-specific attributes which use this feature should ensure that the
556 // spellings match exactly between the attributes, and if the arguments or
557 // subjects differ, should specify HasCustomParsing = 1 and implement their
558 // own parsing and semantic handling requirements as-needed.
562 /// An inheritable parameter attribute is inherited by later
563 /// redeclarations, even when it's written on a parameter.
564 class InheritableParamAttr : InheritableAttr;
566 /// An attribute which changes the ABI rules for a specific parameter.
567 class ParameterABIAttr : InheritableParamAttr {
568 let Subjects = SubjectList<[ParmVar]>;
571 /// An ignored attribute, which we parse but discard with no checking.
572 class IgnoredAttr : Attr {
576 let Documentation = [Undocumented];
580 // Attributes begin here
584 let Spellings = [GCC<"abi_tag">];
585 let Args = [VariadicStringArgument<"Tags">];
586 let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag>;
587 let MeaningfulToClassTemplateDefinition = 1;
588 let Documentation = [AbiTagsDocs];
591 def AddressSpace : TypeAttr {
592 let Spellings = [Clang<"address_space">];
593 let Args = [IntArgument<"AddressSpace">];
594 let Documentation = [Undocumented];
598 let Spellings = [GCC<"alias">];
599 let Args = [StringArgument<"Aliasee">];
600 let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;
601 let Documentation = [Undocumented];
604 def ArmMveAlias : InheritableAttr, TargetSpecificAttr<TargetARM> {
605 let Spellings = [Clang<"__clang_arm_mve_alias">];
606 let Args = [IdentifierArgument<"BuiltinName">];
607 let Subjects = SubjectList<[Function], ErrorDiag>;
608 let Documentation = [ArmMveAliasDocs];
611 def Aligned : InheritableAttr {
612 let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
613 Keyword<"_Alignas">];
614 let Args = [AlignedArgument<"Alignment", 1>];
615 let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
616 Accessor<"isC11", [Keyword<"_Alignas">]>,
617 Accessor<"isAlignas", [Keyword<"alignas">,
618 Keyword<"_Alignas">]>,
619 Accessor<"isDeclspec",[Declspec<"align">]>];
620 let Documentation = [Undocumented];
623 def AlignValue : Attr {
625 // Unfortunately, this is semantically an assertion, not a directive
626 // (something else must ensure the alignment), so aligned_value is a
627 // probably a better name. We might want to add an aligned_value spelling in
628 // the future (and a corresponding C++ attribute), but this can be done
629 // later once we decide if we also want them to have slightly-different
630 // semantics than Intel's align_value.
632 // Does not get a [[]] spelling because the attribute is not exposed as such
635 // Intel's compiler on Windows also supports:
636 // , Declspec<"align_value">
638 let Args = [ExprArgument<"Alignment">];
639 let Subjects = SubjectList<[Var, TypedefName]>;
640 let Documentation = [AlignValueDocs];
643 def AlignMac68k : InheritableAttr {
644 // This attribute has no spellings as it is only ever created implicitly.
647 let Documentation = [Undocumented];
650 def AlwaysInline : InheritableAttr {
651 let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
652 let Subjects = SubjectList<[Function]>;
653 let Documentation = [Undocumented];
656 def Artificial : InheritableAttr {
657 let Spellings = [GCC<"artificial">];
658 let Subjects = SubjectList<[InlineFunction], WarnDiag>;
659 let Documentation = [ArtificialDocs];
662 def XRayInstrument : InheritableAttr {
663 let Spellings = [Clang<"xray_always_instrument">,
664 Clang<"xray_never_instrument">];
665 let Subjects = SubjectList<[Function, ObjCMethod]>;
666 let Accessors = [Accessor<"alwaysXRayInstrument",
667 [Clang<"xray_always_instrument">]>,
668 Accessor<"neverXRayInstrument",
669 [Clang<"xray_never_instrument">]>];
670 let Documentation = [XRayDocs];
673 def XRayLogArgs : InheritableAttr {
674 let Spellings = [Clang<"xray_log_args">];
675 let Subjects = SubjectList<[Function, ObjCMethod]>;
676 // This argument is a count not an index, so it has the same encoding (base
677 // 1 including C++ implicit this parameter) at the source and LLVM levels of
678 // representation, so ParamIdxArgument is inappropriate. It is never used
679 // at the AST level of representation, so it never needs to be adjusted not
680 // to include any C++ implicit this parameter. Thus, we just store it and
681 // use it as an unsigned that never needs adjustment.
682 let Args = [UnsignedArgument<"ArgumentCount">];
683 let Documentation = [XRayDocs];
686 def PatchableFunctionEntry
688 TargetSpecificAttr<TargetArch<["aarch64", "aarch64_be", "x86", "x86_64"]>> {
689 let Spellings = [GCC<"patchable_function_entry">];
690 let Subjects = SubjectList<[Function, ObjCMethod]>;
691 let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];
692 let Documentation = [PatchableFunctionEntryDocs];
695 def TLSModel : InheritableAttr {
696 let Spellings = [GCC<"tls_model">];
697 let Subjects = SubjectList<[TLSVar], ErrorDiag>;
698 let Args = [StringArgument<"Model">];
699 let Documentation = [TLSModelDocs];
702 def AnalyzerNoReturn : InheritableAttr {
703 // TODO: should this attribute be exposed with a [[]] spelling under the clang
704 // vendor namespace, or should it use a vendor namespace specific to the
706 let Spellings = [GNU<"analyzer_noreturn">];
707 // TODO: Add subject list.
708 let Documentation = [Undocumented];
711 def Annotate : InheritableParamAttr {
712 let Spellings = [Clang<"annotate">];
713 let Args = [StringArgument<"Annotation">];
714 // Ensure that the annotate attribute can be used with
715 // '#pragma clang attribute' even though it has no subject list.
716 let PragmaAttributeSupport = 1;
717 let Documentation = [Undocumented];
720 def ARMInterrupt : InheritableAttr, TargetSpecificAttr<TargetARM> {
721 // NOTE: If you add any additional spellings, MSP430Interrupt's,
722 // MipsInterrupt's and AnyX86Interrupt's spellings must match.
723 let Spellings = [GCC<"interrupt">];
724 let Args = [EnumArgument<"Interrupt", "InterruptType",
725 ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
726 ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
728 let ParseKind = "Interrupt";
729 let HasCustomParsing = 1;
730 let Documentation = [ARMInterruptDocs];
733 def AVRInterrupt : InheritableAttr, TargetSpecificAttr<TargetAVR> {
734 let Spellings = [GCC<"interrupt">];
735 let Subjects = SubjectList<[Function]>;
736 let ParseKind = "Interrupt";
737 let Documentation = [AVRInterruptDocs];
740 def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
741 let Spellings = [GCC<"signal">];
742 let Subjects = SubjectList<[Function]>;
743 let Documentation = [AVRSignalDocs];
746 def AsmLabel : InheritableAttr {
747 let Spellings = [Keyword<"asm">, Keyword<"__asm__">];
749 // Label specifies the mangled name for the decl.
750 StringArgument<"Label">,
752 // IsLiteralLabel specifies whether the label is literal (i.e. suppresses
753 // the global C symbol prefix) or not. If not, the mangle-suppression prefix
754 // ('\01') is omitted from the decl name at the LLVM IR level.
756 // Non-literal labels are used by some external AST sources like LLDB.
757 BoolArgument<"IsLiteralLabel", /*optional=*/0, /*fake=*/1>
760 let Documentation = [AsmLabelDocs];
761 let AdditionalMembers =
763 bool isEquivalent(AsmLabelAttr *Other) const {
764 return getLabel() == Other->getLabel() && getIsLiteralLabel() == Other->getIsLiteralLabel();
769 def Availability : InheritableAttr {
770 let Spellings = [Clang<"availability">];
771 let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
772 VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
773 BoolArgument<"unavailable">, StringArgument<"message">,
774 BoolArgument<"strict">, StringArgument<"replacement">,
775 IntArgument<"priority">];
776 let AdditionalMembers =
777 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
778 return llvm::StringSwitch<llvm::StringRef>(Platform)
779 .Case("android", "Android")
781 .Case("macos", "macOS")
782 .Case("tvos", "tvOS")
783 .Case("watchos", "watchOS")
784 .Case("ios_app_extension", "iOS (App Extension)")
785 .Case("macos_app_extension", "macOS (App Extension)")
786 .Case("tvos_app_extension", "tvOS (App Extension)")
787 .Case("watchos_app_extension", "watchOS (App Extension)")
788 .Case("swift", "Swift")
789 .Default(llvm::StringRef());
791 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
792 return llvm::StringSwitch<llvm::StringRef>(Platform)
794 .Case("macos", "macOS")
795 .Case("tvos", "tvOS")
796 .Case("watchos", "watchOS")
797 .Case("ios_app_extension", "iOSApplicationExtension")
798 .Case("macos_app_extension", "macOSApplicationExtension")
799 .Case("tvos_app_extension", "tvOSApplicationExtension")
800 .Case("watchos_app_extension", "watchOSApplicationExtension")
803 static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
804 return llvm::StringSwitch<llvm::StringRef>(Platform)
806 .Case("macOS", "macos")
807 .Case("tvOS", "tvos")
808 .Case("watchOS", "watchos")
809 .Case("iOSApplicationExtension", "ios_app_extension")
810 .Case("macOSApplicationExtension", "macos_app_extension")
811 .Case("tvOSApplicationExtension", "tvos_app_extension")
812 .Case("watchOSApplicationExtension", "watchos_app_extension")
815 let HasCustomParsing = 1;
816 let InheritEvenIfAlreadyPresent = 1;
817 let Subjects = SubjectList<[Named]>;
818 let Documentation = [AvailabilityDocs];
821 def ExternalSourceSymbol : InheritableAttr {
822 let Spellings = [Clang<"external_source_symbol">];
823 let Args = [StringArgument<"language", 1>,
824 StringArgument<"definedIn", 1>,
825 BoolArgument<"generatedDeclaration", 1>];
826 let HasCustomParsing = 1;
827 let Subjects = SubjectList<[Named]>;
828 let Documentation = [ExternalSourceSymbolDocs];
831 def Blocks : InheritableAttr {
832 let Spellings = [Clang<"blocks">];
833 let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
834 let Documentation = [Undocumented];
837 def Bounded : IgnoredAttr {
838 // Does not have a [[]] spelling because the attribute is ignored.
839 let Spellings = [GNU<"bounded">];
842 def CarriesDependency : InheritableParamAttr {
843 let Spellings = [GNU<"carries_dependency">,
844 CXX11<"","carries_dependency", 200809>];
845 let Subjects = SubjectList<[ParmVar, ObjCMethod, Function], ErrorDiag>;
846 let Documentation = [CarriesDependencyDocs];
849 def CDecl : DeclOrTypeAttr {
850 let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
851 // let Subjects = [Function, ObjCMethod];
852 let Documentation = [Undocumented];
855 // cf_audited_transfer indicates that the given function has been
856 // audited and has been marked with the appropriate cf_consumed and
857 // cf_returns_retained attributes. It is generally applied by
858 // '#pragma clang arc_cf_code_audited' rather than explicitly.
859 def CFAuditedTransfer : InheritableAttr {
860 let Spellings = [Clang<"cf_audited_transfer">];
861 let Subjects = SubjectList<[Function], ErrorDiag>;
862 let Documentation = [Undocumented];
865 // cf_unknown_transfer is an explicit opt-out of cf_audited_transfer.
866 // It indicates that the function has unknown or unautomatable
867 // transfer semantics.
868 def CFUnknownTransfer : InheritableAttr {
869 let Spellings = [Clang<"cf_unknown_transfer">];
870 let Subjects = SubjectList<[Function], ErrorDiag>;
871 let Documentation = [Undocumented];
874 def CFReturnsRetained : InheritableAttr {
875 let Spellings = [Clang<"cf_returns_retained">];
876 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
877 let Documentation = [RetainBehaviorDocs];
880 def CFReturnsNotRetained : InheritableAttr {
881 let Spellings = [Clang<"cf_returns_not_retained">];
882 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
883 let Documentation = [RetainBehaviorDocs];
886 def CFConsumed : InheritableParamAttr {
887 let Spellings = [Clang<"cf_consumed">];
888 let Subjects = SubjectList<[ParmVar]>;
889 let Documentation = [RetainBehaviorDocs];
892 // OSObject-based attributes.
893 def OSConsumed : InheritableParamAttr {
894 let Spellings = [Clang<"os_consumed">];
895 let Subjects = SubjectList<[ParmVar]>;
896 let Documentation = [RetainBehaviorDocs];
899 def OSReturnsRetained : InheritableAttr {
900 let Spellings = [Clang<"os_returns_retained">];
901 let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty, ParmVar]>;
902 let Documentation = [RetainBehaviorDocs];
905 def OSReturnsNotRetained : InheritableAttr {
906 let Spellings = [Clang<"os_returns_not_retained">];
907 let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty, ParmVar]>;
908 let Documentation = [RetainBehaviorDocs];
911 def OSReturnsRetainedOnZero : InheritableAttr {
912 let Spellings = [Clang<"os_returns_retained_on_zero">];
913 let Subjects = SubjectList<[ParmVar]>;
914 let Documentation = [RetainBehaviorDocs];
917 def OSReturnsRetainedOnNonZero : InheritableAttr {
918 let Spellings = [Clang<"os_returns_retained_on_non_zero">];
919 let Subjects = SubjectList<[ParmVar]>;
920 let Documentation = [RetainBehaviorDocs];
923 def OSConsumesThis : InheritableAttr {
924 let Spellings = [Clang<"os_consumes_this">];
925 let Subjects = SubjectList<[NonStaticCXXMethod]>;
926 let Documentation = [RetainBehaviorDocs];
929 def Cleanup : InheritableAttr {
930 let Spellings = [GCC<"cleanup">];
931 let Args = [FunctionArgument<"FunctionDecl">];
932 let Subjects = SubjectList<[LocalVar]>;
933 let Documentation = [Undocumented];
936 def Cold : InheritableAttr {
937 let Spellings = [GCC<"cold">];
938 let Subjects = SubjectList<[Function]>;
939 let Documentation = [Undocumented];
942 def Common : InheritableAttr {
943 let Spellings = [GCC<"common">];
944 let Subjects = SubjectList<[Var]>;
945 let Documentation = [Undocumented];
948 def Const : InheritableAttr {
949 let Spellings = [GCC<"const">, GCC<"__const">];
950 let Documentation = [Undocumented];
953 def ConstInit : InheritableAttr {
954 // This attribute does not have a C [[]] spelling because it requires the
955 // CPlusPlus language option.
956 let Spellings = [Keyword<"constinit">,
957 Clang<"require_constant_initialization", 0>];
958 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
959 let Accessors = [Accessor<"isConstinit", [Keyword<"constinit">]>];
960 let Documentation = [ConstInitDocs];
961 let LangOpts = [CPlusPlus];
964 def Constructor : InheritableAttr {
965 let Spellings = [GCC<"constructor">];
966 let Args = [DefaultIntArgument<"Priority", 65535>];
967 let Subjects = SubjectList<[Function]>;
968 let Documentation = [Undocumented];
971 def CPUSpecific : InheritableAttr {
972 let Spellings = [Clang<"cpu_specific">, Declspec<"cpu_specific">];
973 let Args = [VariadicIdentifierArgument<"Cpus">];
974 let Subjects = SubjectList<[Function]>;
975 let Documentation = [CPUSpecificCPUDispatchDocs];
976 let AdditionalMembers = [{
977 IdentifierInfo *getCPUName(unsigned Index) const {
978 return *(cpus_begin() + Index);
983 def CPUDispatch : InheritableAttr {
984 let Spellings = [Clang<"cpu_dispatch">, Declspec<"cpu_dispatch">];
985 let Args = [VariadicIdentifierArgument<"Cpus">];
986 let Subjects = SubjectList<[Function]>;
987 let Documentation = [CPUSpecificCPUDispatchDocs];
990 // CUDA attributes are spelled __attribute__((attr)) or __declspec(__attr__),
991 // and they do not receive a [[]] spelling.
992 def CUDAConstant : InheritableAttr {
993 let Spellings = [GNU<"constant">, Declspec<"__constant__">];
994 let Subjects = SubjectList<[Var]>;
995 let LangOpts = [CUDA];
996 let Documentation = [Undocumented];
999 def CUDACudartBuiltin : IgnoredAttr {
1000 let Spellings = [GNU<"cudart_builtin">, Declspec<"__cudart_builtin__">];
1001 let LangOpts = [CUDA];
1004 def CUDADevice : InheritableAttr {
1005 let Spellings = [GNU<"device">, Declspec<"__device__">];
1006 let Subjects = SubjectList<[Function, Var]>;
1007 let LangOpts = [CUDA];
1008 let Documentation = [Undocumented];
1011 def HIPPinnedShadow : InheritableAttr {
1012 let Spellings = [GNU<"hip_pinned_shadow">, Declspec<"__hip_pinned_shadow__">];
1013 let Subjects = SubjectList<[Var]>;
1014 let LangOpts = [HIP];
1015 let Documentation = [HIPPinnedShadowDocs];
1018 def CUDADeviceBuiltin : IgnoredAttr {
1019 let Spellings = [GNU<"device_builtin">, Declspec<"__device_builtin__">];
1020 let LangOpts = [CUDA];
1023 def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
1024 let Spellings = [GNU<"device_builtin_surface_type">,
1025 Declspec<"__device_builtin_surface_type__">];
1026 let LangOpts = [CUDA];
1029 def CUDADeviceBuiltinTextureType : IgnoredAttr {
1030 let Spellings = [GNU<"device_builtin_texture_type">,
1031 Declspec<"__device_builtin_texture_type__">];
1032 let LangOpts = [CUDA];
1035 def CUDAGlobal : InheritableAttr {
1036 let Spellings = [GNU<"global">, Declspec<"__global__">];
1037 let Subjects = SubjectList<[Function]>;
1038 let LangOpts = [CUDA];
1039 let Documentation = [Undocumented];
1042 def CUDAHost : InheritableAttr {
1043 let Spellings = [GNU<"host">, Declspec<"__host__">];
1044 let Subjects = SubjectList<[Function]>;
1045 let LangOpts = [CUDA];
1046 let Documentation = [Undocumented];
1049 def CUDAInvalidTarget : InheritableAttr {
1051 let Subjects = SubjectList<[Function]>;
1052 let LangOpts = [CUDA];
1053 let Documentation = [Undocumented];
1056 def CUDALaunchBounds : InheritableAttr {
1057 let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
1058 let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
1059 let LangOpts = [CUDA];
1060 let Subjects = SubjectList<[ObjCMethod, FunctionLike]>;
1061 // An AST node is created for this attribute, but is not used by other parts
1062 // of the compiler. However, this node needs to exist in the AST because
1063 // non-LLVM backends may be relying on the attribute's presence.
1064 let Documentation = [Undocumented];
1067 def CUDAShared : InheritableAttr {
1068 let Spellings = [GNU<"shared">, Declspec<"__shared__">];
1069 let Subjects = SubjectList<[Var]>;
1070 let LangOpts = [CUDA];
1071 let Documentation = [Undocumented];
1074 def SYCLKernel : InheritableAttr {
1075 let Spellings = [Clang<"sycl_kernel">];
1076 let Subjects = SubjectList<[FunctionTmpl]>;
1077 let LangOpts = [SYCL];
1078 let Documentation = [SYCLKernelDocs];
1081 def C11NoReturn : InheritableAttr {
1082 let Spellings = [Keyword<"_Noreturn">];
1083 let Subjects = SubjectList<[Function], ErrorDiag>;
1084 let SemaHandler = 0;
1085 let Documentation = [C11NoReturnDocs];
1088 def CXX11NoReturn : InheritableAttr {
1089 let Spellings = [CXX11<"", "noreturn", 200809>];
1090 let Subjects = SubjectList<[Function], ErrorDiag>;
1091 let Documentation = [CXX11NoReturnDocs];
1094 // Similar to CUDA, OpenCL attributes do not receive a [[]] spelling because
1095 // the specification does not expose them with one currently.
1096 def OpenCLKernel : InheritableAttr {
1097 let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
1098 let Subjects = SubjectList<[Function], ErrorDiag>;
1099 let Documentation = [Undocumented];
1102 def OpenCLUnrollHint : InheritableAttr {
1103 let Spellings = [GNU<"opencl_unroll_hint">];
1104 let Args = [UnsignedArgument<"UnrollHint">];
1105 let Documentation = [OpenCLUnrollHintDocs];
1108 def OpenCLIntelReqdSubGroupSize: InheritableAttr {
1109 let Spellings = [GNU<"intel_reqd_sub_group_size">];
1110 let Args = [UnsignedArgument<"SubGroupSize">];
1111 let Subjects = SubjectList<[Function], ErrorDiag>;
1112 let Documentation = [OpenCLIntelReqdSubGroupSizeDocs];
1115 // This attribute is both a type attribute, and a declaration attribute (for
1116 // parameter variables).
1117 def OpenCLAccess : Attr {
1118 let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
1119 Keyword<"__write_only">, Keyword<"write_only">,
1120 Keyword<"__read_write">, Keyword<"read_write">];
1121 let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag>;
1122 let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
1123 Keyword<"read_only">]>,
1124 Accessor<"isReadWrite", [Keyword<"__read_write">,
1125 Keyword<"read_write">]>,
1126 Accessor<"isWriteOnly", [Keyword<"__write_only">,
1127 Keyword<"write_only">]>];
1128 let Documentation = [OpenCLAccessDocs];
1131 def OpenCLPrivateAddressSpace : TypeAttr {
1132 let Spellings = [Keyword<"__private">, Keyword<"private">, Clang<"opencl_private">];
1133 let Documentation = [OpenCLAddressSpacePrivateDocs];
1136 def OpenCLGlobalAddressSpace : TypeAttr {
1137 let Spellings = [Keyword<"__global">, Keyword<"global">, Clang<"opencl_global">];
1138 let Documentation = [OpenCLAddressSpaceGlobalDocs];
1141 def OpenCLLocalAddressSpace : TypeAttr {
1142 let Spellings = [Keyword<"__local">, Keyword<"local">, Clang<"opencl_local">];
1143 let Documentation = [OpenCLAddressSpaceLocalDocs];
1146 def OpenCLConstantAddressSpace : TypeAttr {
1147 let Spellings = [Keyword<"__constant">, Keyword<"constant">, Clang<"opencl_constant">];
1148 let Documentation = [OpenCLAddressSpaceConstantDocs];
1151 def OpenCLGenericAddressSpace : TypeAttr {
1152 let Spellings = [Keyword<"__generic">, Keyword<"generic">, Clang<"opencl_generic">];
1153 let Documentation = [OpenCLAddressSpaceGenericDocs];
1156 def OpenCLNoSVM : Attr {
1157 let Spellings = [GNU<"nosvm">];
1158 let Subjects = SubjectList<[Var]>;
1159 let Documentation = [OpenCLNoSVMDocs];
1160 let LangOpts = [OpenCL];
1164 def RenderScriptKernel : Attr {
1165 let Spellings = [GNU<"kernel">];
1166 let Subjects = SubjectList<[Function]>;
1167 let Documentation = [RenderScriptKernelAttributeDocs];
1168 let LangOpts = [RenderScript];
1171 def Deprecated : InheritableAttr {
1172 let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
1173 CXX11<"","deprecated", 201309>, C2x<"", "deprecated">];
1174 let Args = [StringArgument<"Message", 1>,
1175 // An optional string argument that enables us to provide a
1177 StringArgument<"Replacement", 1>];
1178 let MeaningfulToClassTemplateDefinition = 1;
1179 let Documentation = [DeprecatedDocs];
1182 def Destructor : InheritableAttr {
1183 let Spellings = [GCC<"destructor">];
1184 let Args = [DefaultIntArgument<"Priority", 65535>];
1185 let Subjects = SubjectList<[Function]>;
1186 let Documentation = [Undocumented];
1189 def EmptyBases : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1190 let Spellings = [Declspec<"empty_bases">];
1191 let Subjects = SubjectList<[CXXRecord]>;
1192 let Documentation = [EmptyBasesDocs];
1195 def AllocSize : InheritableAttr {
1196 let Spellings = [GCC<"alloc_size">];
1197 let Subjects = SubjectList<[Function]>;
1198 let Args = [ParamIdxArgument<"ElemSizeParam">,
1199 ParamIdxArgument<"NumElemsParam", /*opt*/ 1>];
1200 let TemplateDependent = 1;
1201 let Documentation = [AllocSizeDocs];
1204 def EnableIf : InheritableAttr {
1205 // Does not have a [[]] spelling because this attribute requires the ability
1206 // to parse function arguments but the attribute is not written in the type
1208 let Spellings = [GNU<"enable_if">];
1209 let Subjects = SubjectList<[Function]>;
1210 let Args = [ExprArgument<"Cond">, StringArgument<"Message">];
1211 let TemplateDependent = 1;
1212 let Documentation = [EnableIfDocs];
1215 def ExtVectorType : Attr {
1216 // This is an OpenCL-related attribute and does not receive a [[]] spelling.
1217 let Spellings = [GNU<"ext_vector_type">];
1218 // FIXME: This subject list is wrong; this is a type attribute.
1219 let Subjects = SubjectList<[TypedefName], ErrorDiag>;
1220 let Args = [ExprArgument<"NumElements">];
1222 let Documentation = [Undocumented];
1223 // This is a type attribute with an incorrect subject list, so should not be
1224 // permitted by #pragma clang attribute.
1225 let PragmaAttributeSupport = 0;
1228 def FallThrough : StmtAttr {
1229 let Spellings = [CXX11<"", "fallthrough", 201603>, C2x<"", "fallthrough">,
1230 CXX11<"clang", "fallthrough">, GCC<"fallthrough">];
1231 // let Subjects = [NullStmt];
1232 let Documentation = [FallthroughDocs];
1235 def FastCall : DeclOrTypeAttr {
1236 let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
1237 Keyword<"_fastcall">];
1238 // let Subjects = [Function, ObjCMethod];
1239 let Documentation = [FastCallDocs];
1242 def RegCall : DeclOrTypeAttr {
1243 let Spellings = [GCC<"regcall">, Keyword<"__regcall">];
1244 let Documentation = [RegCallDocs];
1247 def Final : InheritableAttr {
1248 let Spellings = [Keyword<"final">, Keyword<"sealed">];
1249 let Accessors = [Accessor<"isSpelledAsSealed", [Keyword<"sealed">]>];
1250 let SemaHandler = 0;
1251 let Documentation = [Undocumented];
1254 def MinSize : InheritableAttr {
1255 let Spellings = [Clang<"minsize">];
1256 let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
1257 let Documentation = [Undocumented];
1260 def FlagEnum : InheritableAttr {
1261 let Spellings = [Clang<"flag_enum">];
1262 let Subjects = SubjectList<[Enum]>;
1263 let Documentation = [FlagEnumDocs];
1266 def EnumExtensibility : InheritableAttr {
1267 let Spellings = [Clang<"enum_extensibility">];
1268 let Subjects = SubjectList<[Enum]>;
1269 let Args = [EnumArgument<"Extensibility", "Kind",
1270 ["closed", "open"], ["Closed", "Open"]>];
1271 let Documentation = [EnumExtensibilityDocs];
1274 def Flatten : InheritableAttr {
1275 let Spellings = [GCC<"flatten">];
1276 let Subjects = SubjectList<[Function], ErrorDiag>;
1277 let Documentation = [FlattenDocs];
1280 def Format : InheritableAttr {
1281 let Spellings = [GCC<"format">];
1282 let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">,
1283 IntArgument<"FirstArg">];
1284 let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto]>;
1285 let Documentation = [FormatDocs];
1288 def FormatArg : InheritableAttr {
1289 let Spellings = [GCC<"format_arg">];
1290 let Args = [ParamIdxArgument<"FormatIdx">];
1291 let Subjects = SubjectList<[ObjCMethod, HasFunctionProto]>;
1292 let Documentation = [Undocumented];
1295 def Callback : InheritableAttr {
1296 let Spellings = [Clang<"callback">];
1297 let Args = [VariadicParamOrParamIdxArgument<"Encoding">];
1298 let Subjects = SubjectList<[Function]>;
1299 let Documentation = [CallbackDocs];
1302 def GNUInline : InheritableAttr {
1303 let Spellings = [GCC<"gnu_inline">];
1304 let Subjects = SubjectList<[Function]>;
1305 let Documentation = [GnuInlineDocs];
1308 def Hot : InheritableAttr {
1309 let Spellings = [GCC<"hot">];
1310 let Subjects = SubjectList<[Function]>;
1311 // An AST node is created for this attribute, but not actually used beyond
1312 // semantic checking for mutual exclusion with the Cold attribute.
1313 let Documentation = [Undocumented];
1316 def IBAction : InheritableAttr {
1317 let Spellings = [Clang<"ibaction">];
1318 let Subjects = SubjectList<[ObjCInstanceMethod]>;
1319 // An AST node is created for this attribute, but is not used by other parts
1320 // of the compiler. However, this node needs to exist in the AST because
1321 // external tools rely on it.
1322 let Documentation = [Undocumented];
1325 def IBOutlet : InheritableAttr {
1326 let Spellings = [Clang<"iboutlet">];
1327 // let Subjects = [ObjCIvar, ObjCProperty];
1328 let Documentation = [Undocumented];
1331 def IBOutletCollection : InheritableAttr {
1332 let Spellings = [Clang<"iboutletcollection">];
1333 let Args = [TypeArgument<"Interface", 1>];
1334 // let Subjects = [ObjCIvar, ObjCProperty];
1335 let Documentation = [Undocumented];
1338 def IFunc : Attr, TargetSpecificAttr<TargetELF> {
1339 let Spellings = [GCC<"ifunc">];
1340 let Args = [StringArgument<"Resolver">];
1341 let Subjects = SubjectList<[Function]>;
1342 let Documentation = [IFuncDocs];
1345 def Restrict : InheritableAttr {
1346 let Spellings = [Declspec<"restrict">, GCC<"malloc">];
1347 let Subjects = SubjectList<[Function]>;
1348 let Documentation = [Undocumented];
1351 def LayoutVersion : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1352 let Spellings = [Declspec<"layout_version">];
1353 let Args = [UnsignedArgument<"Version">];
1354 let Subjects = SubjectList<[CXXRecord]>;
1355 let Documentation = [LayoutVersionDocs];
1358 def LifetimeBound : DeclOrTypeAttr {
1359 let Spellings = [Clang<"lifetimebound", 0>];
1360 let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
1361 let Documentation = [LifetimeBoundDocs];
1362 let LangOpts = [CPlusPlus];
1365 def TrivialABI : InheritableAttr {
1366 // This attribute does not have a C [[]] spelling because it requires the
1367 // CPlusPlus language option.
1368 let Spellings = [Clang<"trivial_abi", 0>];
1369 let Subjects = SubjectList<[CXXRecord]>;
1370 let Documentation = [TrivialABIDocs];
1371 let LangOpts = [CPlusPlus];
1374 def MaxFieldAlignment : InheritableAttr {
1375 // This attribute has no spellings as it is only ever created implicitly.
1377 let Args = [UnsignedArgument<"Alignment">];
1378 let SemaHandler = 0;
1379 let Documentation = [Undocumented];
1382 def MayAlias : InheritableAttr {
1383 // FIXME: this is a type attribute in GCC, but a declaration attribute here.
1384 let Spellings = [GCC<"may_alias">];
1385 let Documentation = [Undocumented];
1388 def MIGServerRoutine : InheritableAttr {
1389 let Spellings = [Clang<"mig_server_routine">];
1390 let Subjects = SubjectList<[Function, ObjCMethod, Block]>;
1391 let Documentation = [MIGConventionDocs];
1394 def MSABI : DeclOrTypeAttr {
1395 let Spellings = [GCC<"ms_abi">];
1396 // let Subjects = [Function, ObjCMethod];
1397 let Documentation = [MSABIDocs];
1400 def MSP430Interrupt : InheritableAttr, TargetSpecificAttr<TargetMSP430> {
1401 // NOTE: If you add any additional spellings, ARMInterrupt's, MipsInterrupt's
1402 // and AnyX86Interrupt's spellings must match.
1403 let Spellings = [GCC<"interrupt">];
1404 let Args = [UnsignedArgument<"Number">];
1405 let ParseKind = "Interrupt";
1406 let HasCustomParsing = 1;
1407 let Documentation = [Undocumented];
1410 def Mips16 : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1411 let Spellings = [GCC<"mips16">];
1412 let Subjects = SubjectList<[Function], ErrorDiag>;
1413 let Documentation = [Undocumented];
1416 def MipsInterrupt : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1417 // NOTE: If you add any additional spellings, ARMInterrupt's,
1418 // MSP430Interrupt's and AnyX86Interrupt's spellings must match.
1419 let Spellings = [GCC<"interrupt">];
1420 let Subjects = SubjectList<[Function]>;
1421 let Args = [EnumArgument<"Interrupt", "InterruptType",
1422 ["vector=sw0", "vector=sw1", "vector=hw0",
1423 "vector=hw1", "vector=hw2", "vector=hw3",
1424 "vector=hw4", "vector=hw5", "eic", ""],
1425 ["sw0", "sw1", "hw0", "hw1", "hw2", "hw3",
1426 "hw4", "hw5", "eic", "eic"]
1428 let ParseKind = "Interrupt";
1429 let Documentation = [MipsInterruptDocs];
1432 def MicroMips : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1433 let Spellings = [GCC<"micromips">];
1434 let Subjects = SubjectList<[Function], ErrorDiag>;
1435 let Documentation = [MicroMipsDocs];
1438 def MipsLongCall : InheritableAttr, TargetSpecificAttr<TargetAnyMips> {
1439 let Spellings = [GCC<"long_call">, GCC<"far">];
1440 let Subjects = SubjectList<[Function]>;
1441 let Documentation = [MipsLongCallStyleDocs];
1444 def MipsShortCall : InheritableAttr, TargetSpecificAttr<TargetAnyMips> {
1445 let Spellings = [GCC<"short_call">, GCC<"near">];
1446 let Subjects = SubjectList<[Function]>;
1447 let Documentation = [MipsShortCallStyleDocs];
1451 let Spellings = [GCC<"mode">];
1452 let Subjects = SubjectList<[Var, Enum, TypedefName, Field], ErrorDiag>;
1453 let Args = [IdentifierArgument<"Mode">];
1454 let Documentation = [Undocumented];
1455 // This is notionally a type attribute, which #pragma clang attribute
1456 // generally does not support.
1457 let PragmaAttributeSupport = 0;
1460 def Naked : InheritableAttr {
1461 let Spellings = [GCC<"naked">, Declspec<"naked">];
1462 let Subjects = SubjectList<[Function]>;
1463 let Documentation = [Undocumented];
1466 def NeonPolyVectorType : TypeAttr {
1467 let Spellings = [Clang<"neon_polyvector_type">];
1468 let Args = [IntArgument<"NumElements">];
1469 let Documentation = [Undocumented];
1470 // Represented as VectorType instead.
1474 def NeonVectorType : TypeAttr {
1475 let Spellings = [Clang<"neon_vector_type">];
1476 let Args = [IntArgument<"NumElements">];
1477 let Documentation = [Undocumented];
1478 // Represented as VectorType instead.
1482 def NoUniqueAddress : InheritableAttr, TargetSpecificAttr<TargetItaniumCXXABI> {
1483 let Spellings = [CXX11<"", "no_unique_address", 201803>];
1484 let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1485 let Documentation = [NoUniqueAddressDocs];
1488 def ReturnsTwice : InheritableAttr {
1489 let Spellings = [GCC<"returns_twice">];
1490 let Subjects = SubjectList<[Function]>;
1491 let Documentation = [Undocumented];
1494 def DisableTailCalls : InheritableAttr {
1495 let Spellings = [Clang<"disable_tail_calls">];
1496 let Subjects = SubjectList<[Function, ObjCMethod]>;
1497 let Documentation = [DisableTailCallsDocs];
1500 def NoAlias : InheritableAttr {
1501 let Spellings = [Declspec<"noalias">];
1502 let Subjects = SubjectList<[Function]>;
1503 let Documentation = [NoAliasDocs];
1506 def NoCommon : InheritableAttr {
1507 let Spellings = [GCC<"nocommon">];
1508 let Subjects = SubjectList<[Var]>;
1509 let Documentation = [Undocumented];
1512 def NoDebug : InheritableAttr {
1513 let Spellings = [GCC<"nodebug">];
1514 let Subjects = SubjectList<[TypedefName, FunctionLike, ObjCMethod, NonParmVar]>;
1515 let Documentation = [NoDebugDocs];
1518 def NoDuplicate : InheritableAttr {
1519 let Spellings = [Clang<"noduplicate">];
1520 let Subjects = SubjectList<[Function]>;
1521 let Documentation = [NoDuplicateDocs];
1524 def Convergent : InheritableAttr {
1525 let Spellings = [Clang<"convergent">];
1526 let Subjects = SubjectList<[Function]>;
1527 let Documentation = [ConvergentDocs];
1530 def NoInline : InheritableAttr {
1531 let Spellings = [GCC<"noinline">, Declspec<"noinline">];
1532 let Subjects = SubjectList<[Function]>;
1533 let Documentation = [Undocumented];
1536 def NoMips16 : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1537 let Spellings = [GCC<"nomips16">];
1538 let Subjects = SubjectList<[Function], ErrorDiag>;
1539 let Documentation = [Undocumented];
1542 def NoMicroMips : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1543 let Spellings = [GCC<"nomicromips">];
1544 let Subjects = SubjectList<[Function], ErrorDiag>;
1545 let Documentation = [MicroMipsDocs];
1548 def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
1549 let Spellings = [GCC<"interrupt">];
1550 let Subjects = SubjectList<[Function]>;
1551 let Args = [EnumArgument<"Interrupt", "InterruptType",
1552 ["user", "supervisor", "machine"],
1553 ["user", "supervisor", "machine"],
1555 let ParseKind = "Interrupt";
1556 let Documentation = [RISCVInterruptDocs];
1559 // This is not a TargetSpecificAttr so that is silently accepted and
1560 // ignored on other targets as encouraged by the OpenCL spec.
1562 // See OpenCL 1.2 6.11.5: "It is our intention that a particular
1563 // implementation of OpenCL be free to ignore all attributes and the
1564 // resulting executable binary will produce the same result."
1566 // However, only AMD GPU targets will emit the corresponding IR
1569 // FIXME: This provides a sub-optimal error message if you attempt to
1570 // use this in CUDA, since CUDA does not use the same terminology.
1572 // FIXME: SubjectList should be for OpenCLKernelFunction, but is not to
1573 // workaround needing to see kernel attribute before others to know if
1574 // this should be rejected on non-kernels.
1576 def AMDGPUFlatWorkGroupSize : InheritableAttr {
1577 let Spellings = [Clang<"amdgpu_flat_work_group_size", 0>];
1578 let Args = [ExprArgument<"Min">, ExprArgument<"Max">];
1579 let Documentation = [AMDGPUFlatWorkGroupSizeDocs];
1580 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1583 def AMDGPUWavesPerEU : InheritableAttr {
1584 let Spellings = [Clang<"amdgpu_waves_per_eu", 0>];
1585 let Args = [ExprArgument<"Min">, ExprArgument<"Max", 1>];
1586 let Documentation = [AMDGPUWavesPerEUDocs];
1587 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1590 def AMDGPUNumSGPR : InheritableAttr {
1591 let Spellings = [Clang<"amdgpu_num_sgpr", 0>];
1592 let Args = [UnsignedArgument<"NumSGPR">];
1593 let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1594 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1597 def AMDGPUNumVGPR : InheritableAttr {
1598 let Spellings = [Clang<"amdgpu_num_vgpr", 0>];
1599 let Args = [UnsignedArgument<"NumVGPR">];
1600 let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1601 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1604 def BPFPreserveAccessIndex : InheritableAttr,
1605 TargetSpecificAttr<TargetBPF> {
1606 let Spellings = [Clang<"preserve_access_index">];
1607 let Subjects = SubjectList<[Record], ErrorDiag>;
1608 let Documentation = [BPFPreserveAccessIndexDocs];
1609 let LangOpts = [COnly];
1612 def WebAssemblyExportName : InheritableAttr,
1613 TargetSpecificAttr<TargetWebAssembly> {
1614 let Spellings = [Clang<"export_name">];
1615 let Args = [StringArgument<"ExportName">];
1616 let Documentation = [WebAssemblyExportNameDocs];
1617 let Subjects = SubjectList<[Function], ErrorDiag>;
1620 def WebAssemblyImportModule : InheritableAttr,
1621 TargetSpecificAttr<TargetWebAssembly> {
1622 let Spellings = [Clang<"import_module">];
1623 let Args = [StringArgument<"ImportModule">];
1624 let Documentation = [WebAssemblyImportModuleDocs];
1625 let Subjects = SubjectList<[Function], ErrorDiag>;
1628 def WebAssemblyImportName : InheritableAttr,
1629 TargetSpecificAttr<TargetWebAssembly> {
1630 let Spellings = [Clang<"import_name">];
1631 let Args = [StringArgument<"ImportName">];
1632 let Documentation = [WebAssemblyImportNameDocs];
1633 let Subjects = SubjectList<[Function], ErrorDiag>;
1636 def NoSplitStack : InheritableAttr {
1637 let Spellings = [GCC<"no_split_stack">];
1638 let Subjects = SubjectList<[Function], ErrorDiag>;
1639 let Documentation = [NoSplitStackDocs];
1642 def NonNull : InheritableParamAttr {
1643 let Spellings = [GCC<"nonnull">];
1644 let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
1645 "functions, methods, and parameters">;
1646 let Args = [VariadicParamIdxArgument<"Args">];
1647 let AdditionalMembers = [{
1648 bool isNonNull(unsigned IdxAST) const {
1651 return args_end() != std::find_if(
1652 args_begin(), args_end(),
1653 [=](const ParamIdx &Idx) { return Idx.getASTIndex() == IdxAST; });
1656 // FIXME: We should merge duplicates into a single nonnull attribute.
1657 let InheritEvenIfAlreadyPresent = 1;
1658 let Documentation = [NonNullDocs];
1661 def ReturnsNonNull : InheritableAttr {
1662 let Spellings = [GCC<"returns_nonnull">];
1663 let Subjects = SubjectList<[ObjCMethod, Function]>;
1664 let Documentation = [ReturnsNonNullDocs];
1667 // pass_object_size(N) indicates that the parameter should have
1668 // __builtin_object_size with Type=N evaluated on the parameter at the callsite.
1669 def PassObjectSize : InheritableParamAttr {
1670 let Spellings = [Clang<"pass_object_size">,
1671 Clang<"pass_dynamic_object_size">];
1672 let Accessors = [Accessor<"isDynamic", [Clang<"pass_dynamic_object_size">]>];
1673 let Args = [IntArgument<"Type">];
1674 let Subjects = SubjectList<[ParmVar]>;
1675 let Documentation = [PassObjectSizeDocs];
1678 // Nullability type attributes.
1679 def TypeNonNull : TypeAttr {
1680 let Spellings = [Keyword<"_Nonnull">];
1681 let Documentation = [TypeNonNullDocs];
1684 def TypeNullable : TypeAttr {
1685 let Spellings = [Keyword<"_Nullable">];
1686 let Documentation = [TypeNullableDocs];
1689 def TypeNullUnspecified : TypeAttr {
1690 let Spellings = [Keyword<"_Null_unspecified">];
1691 let Documentation = [TypeNullUnspecifiedDocs];
1694 // This is a marker used to indicate that an __unsafe_unretained qualifier was
1695 // ignored because ARC is not enabled. The usual representation for this
1696 // qualifier is as an ObjCOwnership attribute with Kind == "none".
1697 def ObjCInertUnsafeUnretained : TypeAttr {
1698 let Spellings = [Keyword<"__unsafe_unretained">];
1699 let Documentation = [Undocumented];
1702 def ObjCKindOf : TypeAttr {
1703 let Spellings = [Keyword<"__kindof">];
1704 let Documentation = [Undocumented];
1707 def NoEscape : Attr {
1708 let Spellings = [Clang<"noescape">];
1709 let Subjects = SubjectList<[ParmVar]>;
1710 let Documentation = [NoEscapeDocs];
1713 def AssumeAligned : InheritableAttr {
1714 let Spellings = [GCC<"assume_aligned">];
1715 let Subjects = SubjectList<[ObjCMethod, Function]>;
1716 let Args = [ExprArgument<"Alignment">, ExprArgument<"Offset", 1>];
1717 let Documentation = [AssumeAlignedDocs];
1720 def AllocAlign : InheritableAttr {
1721 let Spellings = [GCC<"alloc_align">];
1722 let Subjects = SubjectList<[HasFunctionProto]>;
1723 let Args = [ParamIdxArgument<"ParamIndex">];
1724 let Documentation = [AllocAlignDocs];
1727 def NoReturn : InheritableAttr {
1728 let Spellings = [GCC<"noreturn">, Declspec<"noreturn">];
1729 // FIXME: Does GCC allow this on the function instead?
1730 let Documentation = [Undocumented];
1733 def NoInstrumentFunction : InheritableAttr {
1734 let Spellings = [GCC<"no_instrument_function">];
1735 let Subjects = SubjectList<[Function]>;
1736 let Documentation = [Undocumented];
1739 def NotTailCalled : InheritableAttr {
1740 let Spellings = [Clang<"not_tail_called">];
1741 let Subjects = SubjectList<[Function]>;
1742 let Documentation = [NotTailCalledDocs];
1745 def NoStackProtector : InheritableAttr {
1746 let Spellings = [Clang<"no_stack_protector">];
1747 let Subjects = SubjectList<[Function]>;
1748 let Documentation = [NoStackProtectorDocs];
1751 def NoThrow : InheritableAttr {
1752 let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
1753 let Subjects = SubjectList<[FunctionLike]>;
1754 let Documentation = [NoThrowDocs];
1757 def NvWeak : IgnoredAttr {
1758 // No Declspec spelling of this attribute; the CUDA headers use
1759 // __attribute__((nv_weak)) unconditionally. Does not receive an [[]]
1760 // spelling because it is a CUDA attribute.
1761 let Spellings = [GNU<"nv_weak">];
1762 let LangOpts = [CUDA];
1765 def ObjCBridge : InheritableAttr {
1766 let Spellings = [Clang<"objc_bridge">];
1767 let Subjects = SubjectList<[Record, TypedefName], ErrorDiag>;
1768 let Args = [IdentifierArgument<"BridgedType">];
1769 let Documentation = [Undocumented];
1772 def ObjCBridgeMutable : InheritableAttr {
1773 let Spellings = [Clang<"objc_bridge_mutable">];
1774 let Subjects = SubjectList<[Record], ErrorDiag>;
1775 let Args = [IdentifierArgument<"BridgedType">];
1776 let Documentation = [Undocumented];
1779 def ObjCBridgeRelated : InheritableAttr {
1780 let Spellings = [Clang<"objc_bridge_related">];
1781 let Subjects = SubjectList<[Record], ErrorDiag>;
1782 let Args = [IdentifierArgument<"RelatedClass">,
1783 IdentifierArgument<"ClassMethod">,
1784 IdentifierArgument<"InstanceMethod">];
1785 let HasCustomParsing = 1;
1786 let Documentation = [Undocumented];
1789 def NSReturnsRetained : DeclOrTypeAttr {
1790 let Spellings = [Clang<"ns_returns_retained">];
1791 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1792 let Documentation = [RetainBehaviorDocs];
1795 def NSReturnsNotRetained : InheritableAttr {
1796 let Spellings = [Clang<"ns_returns_not_retained">];
1797 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1798 let Documentation = [RetainBehaviorDocs];
1801 def NSReturnsAutoreleased : InheritableAttr {
1802 let Spellings = [Clang<"ns_returns_autoreleased">];
1803 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1804 let Documentation = [RetainBehaviorDocs];
1807 def NSConsumesSelf : InheritableAttr {
1808 let Spellings = [Clang<"ns_consumes_self">];
1809 let Subjects = SubjectList<[ObjCMethod]>;
1810 let Documentation = [RetainBehaviorDocs];
1813 def NSConsumed : InheritableParamAttr {
1814 let Spellings = [Clang<"ns_consumed">];
1815 let Subjects = SubjectList<[ParmVar]>;
1816 let Documentation = [RetainBehaviorDocs];
1819 def ObjCException : InheritableAttr {
1820 let Spellings = [Clang<"objc_exception">];
1821 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1822 let Documentation = [Undocumented];
1825 def ObjCMethodFamily : InheritableAttr {
1826 let Spellings = [Clang<"objc_method_family">];
1827 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1828 let Args = [EnumArgument<"Family", "FamilyKind",
1829 ["none", "alloc", "copy", "init", "mutableCopy", "new"],
1830 ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
1831 "OMF_mutableCopy", "OMF_new"]>];
1832 let Documentation = [ObjCMethodFamilyDocs];
1835 def ObjCNSObject : InheritableAttr {
1836 let Spellings = [Clang<"NSObject">];
1837 let Documentation = [Undocumented];
1840 def ObjCIndependentClass : InheritableAttr {
1841 let Spellings = [Clang<"objc_independent_class">];
1842 let Documentation = [Undocumented];
1845 def ObjCPreciseLifetime : InheritableAttr {
1846 let Spellings = [Clang<"objc_precise_lifetime">];
1847 let Subjects = SubjectList<[Var], ErrorDiag>;
1848 let Documentation = [Undocumented];
1851 def ObjCReturnsInnerPointer : InheritableAttr {
1852 let Spellings = [Clang<"objc_returns_inner_pointer">];
1853 let Subjects = SubjectList<[ObjCMethod, ObjCProperty], ErrorDiag>;
1854 let Documentation = [Undocumented];
1857 def ObjCRequiresSuper : InheritableAttr {
1858 let Spellings = [Clang<"objc_requires_super">];
1859 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1860 let Documentation = [ObjCRequiresSuperDocs];
1863 def ObjCRootClass : InheritableAttr {
1864 let Spellings = [Clang<"objc_root_class">];
1865 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1866 let Documentation = [Undocumented];
1869 def ObjCNonLazyClass : Attr {
1870 let Spellings = [Clang<"objc_nonlazy_class">];
1871 let Subjects = SubjectList<[ObjCInterface, ObjCImpl], ErrorDiag>;
1872 let LangOpts = [ObjC];
1873 let Documentation = [ObjCNonLazyClassDocs];
1876 def ObjCSubclassingRestricted : InheritableAttr {
1877 let Spellings = [Clang<"objc_subclassing_restricted">];
1878 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1879 let Documentation = [ObjCSubclassingRestrictedDocs];
1882 def ObjCExplicitProtocolImpl : InheritableAttr {
1883 let Spellings = [Clang<"objc_protocol_requires_explicit_implementation">];
1884 let Subjects = SubjectList<[ObjCProtocol], ErrorDiag>;
1885 let Documentation = [Undocumented];
1888 def ObjCDesignatedInitializer : Attr {
1889 let Spellings = [Clang<"objc_designated_initializer">];
1890 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1891 let Documentation = [Undocumented];
1894 def ObjCDirect : Attr {
1895 let Spellings = [Clang<"objc_direct">];
1896 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1897 let LangOpts = [ObjC];
1898 let Documentation = [ObjCDirectDocs];
1901 def ObjCDirectMembers : Attr {
1902 let Spellings = [Clang<"objc_direct_members">];
1903 let Subjects = SubjectList<[ObjCImpl, ObjCCategory], ErrorDiag>;
1904 let LangOpts = [ObjC];
1905 let Documentation = [ObjCDirectMembersDocs];
1908 def ObjCRuntimeName : Attr {
1909 let Spellings = [Clang<"objc_runtime_name">];
1910 let Subjects = SubjectList<[ObjCInterface, ObjCProtocol], ErrorDiag>;
1911 let Args = [StringArgument<"MetadataName">];
1912 let Documentation = [ObjCRuntimeNameDocs];
1915 def ObjCRuntimeVisible : Attr {
1916 let Spellings = [Clang<"objc_runtime_visible">];
1917 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1918 let Documentation = [ObjCRuntimeVisibleDocs];
1921 def ObjCClassStub : Attr {
1922 let Spellings = [Clang<"objc_class_stub">];
1923 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1924 let Documentation = [ObjCClassStubDocs];
1925 let LangOpts = [ObjCNonFragileRuntime];
1928 def ObjCBoxable : Attr {
1929 let Spellings = [Clang<"objc_boxable">];
1930 let Subjects = SubjectList<[Record], ErrorDiag>;
1931 let Documentation = [ObjCBoxableDocs];
1934 def OptimizeNone : InheritableAttr {
1935 let Spellings = [Clang<"optnone">];
1936 let Subjects = SubjectList<[Function, ObjCMethod]>;
1937 let Documentation = [OptnoneDocs];
1940 def Overloadable : Attr {
1941 let Spellings = [Clang<"overloadable">];
1942 let Subjects = SubjectList<[Function], ErrorDiag>;
1943 let Documentation = [OverloadableDocs];
1946 def Override : InheritableAttr {
1947 let Spellings = [Keyword<"override">];
1948 let SemaHandler = 0;
1949 let Documentation = [Undocumented];
1952 def Ownership : InheritableAttr {
1953 let Spellings = [Clang<"ownership_holds">, Clang<"ownership_returns">,
1954 Clang<"ownership_takes">];
1955 let Accessors = [Accessor<"isHolds", [Clang<"ownership_holds">]>,
1956 Accessor<"isReturns", [Clang<"ownership_returns">]>,
1957 Accessor<"isTakes", [Clang<"ownership_takes">]>];
1958 let AdditionalMembers = [{
1959 enum OwnershipKind { Holds, Returns, Takes };
1960 OwnershipKind getOwnKind() const {
1961 return isHolds() ? Holds :
1966 let Args = [IdentifierArgument<"Module">,
1967 VariadicParamIdxArgument<"Args">];
1968 let Subjects = SubjectList<[HasFunctionProto]>;
1969 let Documentation = [Undocumented];
1972 def Packed : InheritableAttr {
1973 let Spellings = [GCC<"packed">];
1974 // let Subjects = [Tag, Field];
1975 let Documentation = [Undocumented];
1978 def IntelOclBicc : DeclOrTypeAttr {
1979 let Spellings = [Clang<"intel_ocl_bicc", 0>];
1980 // let Subjects = [Function, ObjCMethod];
1981 let Documentation = [Undocumented];
1984 def Pcs : DeclOrTypeAttr {
1985 let Spellings = [GCC<"pcs">];
1986 let Args = [EnumArgument<"PCS", "PCSType",
1987 ["aapcs", "aapcs-vfp"],
1988 ["AAPCS", "AAPCS_VFP"]>];
1989 // let Subjects = [Function, ObjCMethod];
1990 let Documentation = [PcsDocs];
1993 def AArch64VectorPcs: DeclOrTypeAttr {
1994 let Spellings = [Clang<"aarch64_vector_pcs">];
1995 let Documentation = [AArch64VectorPcsDocs];
1998 def Pure : InheritableAttr {
1999 let Spellings = [GCC<"pure">];
2000 let Documentation = [Undocumented];
2003 def Regparm : TypeAttr {
2004 let Spellings = [GCC<"regparm">];
2005 let Args = [UnsignedArgument<"NumParams">];
2006 let Documentation = [RegparmDocs];
2007 // Represented as part of the enclosing function type.
2011 def NoDeref : TypeAttr {
2012 let Spellings = [Clang<"noderef">];
2013 let Documentation = [NoDerefDocs];
2016 def ReqdWorkGroupSize : InheritableAttr {
2017 // Does not have a [[]] spelling because it is an OpenCL-related attribute.
2018 let Spellings = [GNU<"reqd_work_group_size">];
2019 let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
2020 UnsignedArgument<"ZDim">];
2021 let Subjects = SubjectList<[Function], ErrorDiag>;
2022 let Documentation = [Undocumented];
2025 def WorkGroupSizeHint : InheritableAttr {
2026 // Does not have a [[]] spelling because it is an OpenCL-related attribute.
2027 let Spellings = [GNU<"work_group_size_hint">];
2028 let Args = [UnsignedArgument<"XDim">,
2029 UnsignedArgument<"YDim">,
2030 UnsignedArgument<"ZDim">];
2031 let Subjects = SubjectList<[Function], ErrorDiag>;
2032 let Documentation = [Undocumented];
2035 def InitPriority : InheritableAttr {
2036 let Spellings = [GCC<"init_priority">];
2037 let Args = [UnsignedArgument<"Priority">];
2038 let Subjects = SubjectList<[Var], ErrorDiag>;
2039 let Documentation = [Undocumented];
2042 def Section : InheritableAttr {
2043 let Spellings = [GCC<"section">, Declspec<"allocate">];
2044 let Args = [StringArgument<"Name">];
2046 SubjectList<[ Function, GlobalVar, ObjCMethod, ObjCProperty ], ErrorDiag>;
2047 let Documentation = [SectionDocs];
2050 // This is used for `__declspec(code_seg("segname"))`, but not for
2051 // `#pragma code_seg("segname")`.
2052 def CodeSeg : InheritableAttr {
2053 let Spellings = [Declspec<"code_seg">];
2054 let Args = [StringArgument<"Name">];
2055 let Subjects = SubjectList<[Function, CXXRecord], ErrorDiag>;
2056 let Documentation = [CodeSegDocs];
2059 def PragmaClangBSSSection : InheritableAttr {
2060 // This attribute has no spellings as it is only ever created implicitly.
2062 let Args = [StringArgument<"Name">];
2063 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2064 let Documentation = [Undocumented];
2067 def PragmaClangDataSection : InheritableAttr {
2068 // This attribute has no spellings as it is only ever created implicitly.
2070 let Args = [StringArgument<"Name">];
2071 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2072 let Documentation = [Undocumented];
2075 def PragmaClangRodataSection : InheritableAttr {
2076 // This attribute has no spellings as it is only ever created implicitly.
2078 let Args = [StringArgument<"Name">];
2079 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2080 let Documentation = [Undocumented];
2083 def PragmaClangRelroSection : InheritableAttr {
2084 // This attribute has no spellings as it is only ever created implicitly.
2086 let Args = [StringArgument<"Name">];
2087 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2088 let Documentation = [Undocumented];
2091 def PragmaClangTextSection : InheritableAttr {
2092 // This attribute has no spellings as it is only ever created implicitly.
2094 let Args = [StringArgument<"Name">];
2095 let Subjects = SubjectList<[Function], ErrorDiag>;
2096 let Documentation = [Undocumented];
2099 def Sentinel : InheritableAttr {
2100 let Spellings = [GCC<"sentinel">];
2101 let Args = [DefaultIntArgument<"Sentinel", 0>,
2102 DefaultIntArgument<"NullPos", 0>];
2103 // let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>;
2104 let Documentation = [Undocumented];
2107 def StdCall : DeclOrTypeAttr {
2108 let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
2109 // let Subjects = [Function, ObjCMethod];
2110 let Documentation = [StdCallDocs];
2113 def SwiftCall : DeclOrTypeAttr {
2114 let Spellings = [Clang<"swiftcall">];
2115 // let Subjects = SubjectList<[Function]>;
2116 let Documentation = [SwiftCallDocs];
2119 def SwiftContext : ParameterABIAttr {
2120 let Spellings = [Clang<"swift_context">];
2121 let Documentation = [SwiftContextDocs];
2124 def SwiftErrorResult : ParameterABIAttr {
2125 let Spellings = [Clang<"swift_error_result">];
2126 let Documentation = [SwiftErrorResultDocs];
2129 def SwiftIndirectResult : ParameterABIAttr {
2130 let Spellings = [Clang<"swift_indirect_result">];
2131 let Documentation = [SwiftIndirectResultDocs];
2134 def Suppress : StmtAttr {
2135 let Spellings = [CXX11<"gsl", "suppress">];
2136 let Args = [VariadicStringArgument<"DiagnosticIdentifiers">];
2137 let Documentation = [SuppressDocs];
2140 def SysVABI : DeclOrTypeAttr {
2141 let Spellings = [GCC<"sysv_abi">];
2142 // let Subjects = [Function, ObjCMethod];
2143 let Documentation = [Undocumented];
2146 def ThisCall : DeclOrTypeAttr {
2147 let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
2148 Keyword<"_thiscall">];
2149 // let Subjects = [Function, ObjCMethod];
2150 let Documentation = [ThisCallDocs];
2153 def VectorCall : DeclOrTypeAttr {
2154 let Spellings = [Clang<"vectorcall">, Keyword<"__vectorcall">,
2155 Keyword<"_vectorcall">];
2156 // let Subjects = [Function, ObjCMethod];
2157 let Documentation = [VectorCallDocs];
2160 def Pascal : DeclOrTypeAttr {
2161 let Spellings = [Clang<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
2162 // let Subjects = [Function, ObjCMethod];
2163 let Documentation = [Undocumented];
2166 def PreserveMost : DeclOrTypeAttr {
2167 let Spellings = [Clang<"preserve_most">];
2168 let Documentation = [PreserveMostDocs];
2171 def PreserveAll : DeclOrTypeAttr {
2172 let Spellings = [Clang<"preserve_all">];
2173 let Documentation = [PreserveAllDocs];
2176 def Target : InheritableAttr {
2177 let Spellings = [GCC<"target">];
2178 let Args = [StringArgument<"featuresStr">];
2179 let Subjects = SubjectList<[Function], ErrorDiag>;
2180 let Documentation = [TargetDocs];
2181 let AdditionalMembers = [{
2182 ParsedTargetAttr parse() const {
2183 return parse(getFeaturesStr());
2186 StringRef getArchitecture() const {
2187 StringRef Features = getFeaturesStr();
2188 if (Features == "default") return {};
2190 SmallVector<StringRef, 1> AttrFeatures;
2191 Features.split(AttrFeatures, ",");
2193 for (auto &Feature : AttrFeatures) {
2194 Feature = Feature.trim();
2195 if (Feature.startswith("arch="))
2196 return Feature.drop_front(sizeof("arch=") - 1);
2201 // Gets the list of features as simple string-refs with no +/- or 'no-'.
2202 // Only adds the items to 'Out' that are additions.
2203 void getAddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
2204 StringRef Features = getFeaturesStr();
2205 if (Features == "default") return;
2207 SmallVector<StringRef, 1> AttrFeatures;
2208 Features.split(AttrFeatures, ",");
2210 for (auto &Feature : AttrFeatures) {
2211 Feature = Feature.trim();
2213 if (!Feature.startswith("no-") && !Feature.startswith("arch=") &&
2214 !Feature.startswith("fpmath=") && !Feature.startswith("tune="))
2215 Out.push_back(Feature);
2219 template<class Compare>
2220 ParsedTargetAttr parse(Compare cmp) const {
2221 ParsedTargetAttr Attrs = parse();
2222 llvm::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp);
2226 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
2228 static ParsedTargetAttr parse(StringRef Features) {
2229 ParsedTargetAttr Ret;
2230 if (Features == "default") return Ret;
2231 SmallVector<StringRef, 1> AttrFeatures;
2232 Features.split(AttrFeatures, ",");
2234 // Grab the various features and prepend a "+" to turn on the feature to
2235 // the backend and add them to our existing set of features.
2236 for (auto &Feature : AttrFeatures) {
2237 // Go ahead and trim whitespace rather than either erroring or
2238 // accepting it weirdly.
2239 Feature = Feature.trim();
2241 // We don't support cpu tuning this way currently.
2242 // TODO: Support the fpmath option. It will require checking
2243 // overall feature validity for the function with the rest of the
2244 // attributes on the function.
2245 if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
2248 if (Feature.startswith("branch-protection=")) {
2249 Ret.BranchProtection = Feature.split('=').second.trim();
2253 // While we're here iterating check for a different target cpu.
2254 if (Feature.startswith("arch=")) {
2255 if (!Ret.Architecture.empty())
2256 Ret.DuplicateArchitecture = true;
2258 Ret.Architecture = Feature.split("=").second.trim();
2259 } else if (Feature.startswith("no-"))
2260 Ret.Features.push_back("-" + Feature.split("-").second.str());
2262 Ret.Features.push_back("+" + Feature.str());
2269 def MinVectorWidth : InheritableAttr {
2270 let Spellings = [Clang<"min_vector_width">];
2271 let Args = [UnsignedArgument<"VectorWidth">];
2272 let Subjects = SubjectList<[Function], ErrorDiag>;
2273 let Documentation = [MinVectorWidthDocs];
2276 def TransparentUnion : InheritableAttr {
2277 let Spellings = [GCC<"transparent_union">];
2278 // let Subjects = SubjectList<[Record, TypedefName]>;
2279 let Documentation = [TransparentUnionDocs];
2280 let LangOpts = [COnly];
2283 def Unavailable : InheritableAttr {
2284 let Spellings = [Clang<"unavailable">];
2285 let Args = [StringArgument<"Message", 1>,
2286 EnumArgument<"ImplicitReason", "ImplicitReason",
2289 "IR_ARCForbiddenType",
2291 "IR_ARCForbiddenConversion",
2292 "IR_ARCInitReturnsUnrelated",
2293 "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
2294 let Documentation = [Undocumented];
2297 def DiagnoseIf : InheritableAttr {
2298 // Does not have a [[]] spelling because this attribute requires the ability
2299 // to parse function arguments but the attribute is not written in the type
2301 let Spellings = [GNU<"diagnose_if">];
2302 let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
2303 let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
2304 EnumArgument<"DiagnosticType",
2306 ["error", "warning"],
2307 ["DT_Error", "DT_Warning"]>,
2308 BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
2309 NamedArgument<"Parent", 0, /*fake*/ 1>];
2310 let InheritEvenIfAlreadyPresent = 1;
2312 let AdditionalMembers = [{
2313 bool isError() const { return diagnosticType == DT_Error; }
2314 bool isWarning() const { return diagnosticType == DT_Warning; }
2316 let TemplateDependent = 1;
2317 let Documentation = [DiagnoseIfDocs];
2320 def ArcWeakrefUnavailable : InheritableAttr {
2321 let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
2322 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2323 let Documentation = [Undocumented];
2326 def ObjCGC : TypeAttr {
2327 let Spellings = [Clang<"objc_gc">];
2328 let Args = [IdentifierArgument<"Kind">];
2329 let Documentation = [Undocumented];
2332 def ObjCOwnership : DeclOrTypeAttr {
2333 let Spellings = [Clang<"objc_ownership">];
2334 let Args = [IdentifierArgument<"Kind">];
2335 let Documentation = [Undocumented];
2338 def ObjCRequiresPropertyDefs : InheritableAttr {
2339 let Spellings = [Clang<"objc_requires_property_definitions">];
2340 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2341 let Documentation = [Undocumented];
2344 def Unused : InheritableAttr {
2345 let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">,
2346 C2x<"", "maybe_unused">];
2347 let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
2348 Field, ObjCMethod, FunctionLike]>;
2349 let Documentation = [WarnMaybeUnusedDocs];
2352 def Used : InheritableAttr {
2353 let Spellings = [GCC<"used">];
2354 let Subjects = SubjectList<[NonLocalVar, Function, ObjCMethod]>;
2355 let Documentation = [Undocumented];
2358 def Uuid : InheritableAttr {
2359 let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
2360 let Args = [StringArgument<"Guid">];
2361 let Subjects = SubjectList<[Record, Enum]>;
2362 // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
2363 // CPlusPlus && (MicrosoftExt || Borland)
2364 let LangOpts = [MicrosoftExt, Borland];
2365 let Documentation = [Undocumented];
2368 def VectorSize : TypeAttr {
2369 let Spellings = [GCC<"vector_size">];
2370 let Args = [ExprArgument<"NumBytes">];
2371 let Documentation = [Undocumented];
2372 // Represented as VectorType instead.
2376 def VecTypeHint : InheritableAttr {
2377 // Does not have a [[]] spelling because it is an OpenCL-related attribute.
2378 let Spellings = [GNU<"vec_type_hint">];
2379 let Args = [TypeArgument<"TypeHint">];
2380 let Subjects = SubjectList<[Function], ErrorDiag>;
2381 let Documentation = [Undocumented];
2384 def Visibility : InheritableAttr {
2386 let Spellings = [GCC<"visibility">];
2387 let Args = [EnumArgument<"Visibility", "VisibilityType",
2388 ["default", "hidden", "internal", "protected"],
2389 ["Default", "Hidden", "Hidden", "Protected"]>];
2390 let MeaningfulToClassTemplateDefinition = 1;
2391 let Documentation = [Undocumented];
2394 def TypeVisibility : InheritableAttr {
2396 let Spellings = [Clang<"type_visibility">];
2397 let Args = [EnumArgument<"Visibility", "VisibilityType",
2398 ["default", "hidden", "internal", "protected"],
2399 ["Default", "Hidden", "Hidden", "Protected"]>];
2400 // let Subjects = [Tag, ObjCInterface, Namespace];
2401 let Documentation = [Undocumented];
2404 def VecReturn : InheritableAttr {
2405 // This attribute does not have a C [[]] spelling because it only appertains
2406 // to C++ struct/class/union.
2407 // FIXME: should this attribute have a CPlusPlus language option?
2408 let Spellings = [Clang<"vecreturn", 0>];
2409 let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
2410 let Documentation = [Undocumented];
2413 def WarnUnused : InheritableAttr {
2414 let Spellings = [GCC<"warn_unused">];
2415 let Subjects = SubjectList<[Record]>;
2416 let Documentation = [Undocumented];
2419 def WarnUnusedResult : InheritableAttr {
2420 let Spellings = [CXX11<"", "nodiscard", 201907>, C2x<"", "nodiscard">,
2421 CXX11<"clang", "warn_unused_result">,
2422 GCC<"warn_unused_result">];
2423 let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike]>;
2424 let Args = [StringArgument<"Message", 1>];
2425 let Documentation = [WarnUnusedResultsDocs];
2426 let AdditionalMembers = [{
2427 // Check whether this the C++11 nodiscard version, even in non C++11
2429 bool IsCXX11NoDiscard() const {
2430 return this->getSemanticSpelling() == CXX11_nodiscard;
2435 def Weak : InheritableAttr {
2436 let Spellings = [GCC<"weak">];
2437 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
2438 let Documentation = [Undocumented];
2441 def WeakImport : InheritableAttr {
2442 let Spellings = [Clang<"weak_import">];
2443 let Documentation = [Undocumented];
2446 def WeakRef : InheritableAttr {
2447 let Spellings = [GCC<"weakref">];
2448 // A WeakRef that has an argument is treated as being an AliasAttr
2449 let Args = [StringArgument<"Aliasee", 1>];
2450 let Subjects = SubjectList<[Var, Function], ErrorDiag>;
2451 let Documentation = [Undocumented];
2454 def LTOVisibilityPublic : InheritableAttr {
2455 let Spellings = [Clang<"lto_visibility_public">];
2456 let Subjects = SubjectList<[Record]>;
2457 let Documentation = [LTOVisibilityDocs];
2460 def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
2461 // NOTE: If you add any additional spellings, ARMInterrupt's,
2462 // MSP430Interrupt's and MipsInterrupt's spellings must match.
2463 let Spellings = [GCC<"interrupt">];
2464 let Subjects = SubjectList<[HasFunctionProto]>;
2465 let ParseKind = "Interrupt";
2466 let HasCustomParsing = 1;
2467 let Documentation = [Undocumented];
2470 def AnyX86NoCallerSavedRegisters : InheritableAttr,
2471 TargetSpecificAttr<TargetAnyX86> {
2472 let Spellings = [GCC<"no_caller_saved_registers">];
2473 let Documentation = [AnyX86NoCallerSavedRegistersDocs];
2476 def AnyX86NoCfCheck : DeclOrTypeAttr, TargetSpecificAttr<TargetAnyX86>{
2477 let Spellings = [GCC<"nocf_check">];
2478 let Subjects = SubjectList<[FunctionLike]>;
2479 let Documentation = [AnyX86NoCfCheckDocs];
2482 def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
2483 let Spellings = [GCC<"force_align_arg_pointer">];
2484 // Technically, this appertains to a FunctionDecl, but the target-specific
2485 // code silently allows anything function-like (such as typedefs or function
2486 // pointers), but does not apply the attribute to them.
2487 let Documentation = [X86ForceAlignArgPointerDocs];
2490 def NoSanitize : InheritableAttr {
2491 let Spellings = [Clang<"no_sanitize">];
2492 let Args = [VariadicStringArgument<"Sanitizers">];
2493 let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag>;
2494 let Documentation = [NoSanitizeDocs];
2495 let AdditionalMembers = [{
2496 SanitizerMask getMask() const {
2498 for (auto SanitizerName : sanitizers()) {
2499 SanitizerMask ParsedMask =
2500 parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
2501 Mask |= expandSanitizerGroups(ParsedMask);
2508 // Attributes to disable a specific sanitizer. No new sanitizers should be added
2509 // to this list; the no_sanitize attribute should be extended instead.
2510 def NoSanitizeSpecific : InheritableAttr {
2511 let Spellings = [GCC<"no_address_safety_analysis">,
2512 GCC<"no_sanitize_address">,
2513 GCC<"no_sanitize_thread">,
2514 Clang<"no_sanitize_memory">];
2515 let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;
2516 let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
2517 NoSanitizeMemoryDocs];
2521 def CFICanonicalJumpTable : InheritableAttr {
2522 let Spellings = [Clang<"cfi_canonical_jump_table">];
2523 let Subjects = SubjectList<[Function], ErrorDiag>;
2524 let Documentation = [CFICanonicalJumpTableDocs];
2527 // C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
2528 // Not all of these attributes will be given a [[]] spelling. The attributes
2529 // which require access to function parameter names cannot use the [[]] spelling
2530 // because they are not written in the type position. Some attributes are given
2531 // an updated captability-based name and the older name will only be supported
2532 // under the GNU-style spelling.
2533 def GuardedVar : InheritableAttr {
2534 let Spellings = [Clang<"guarded_var", 0>];
2535 let Subjects = SubjectList<[Field, SharedVar]>;
2536 let Documentation = [Undocumented];
2539 def PtGuardedVar : InheritableAttr {
2540 let Spellings = [Clang<"pt_guarded_var", 0>];
2541 let Subjects = SubjectList<[Field, SharedVar]>;
2542 let Documentation = [Undocumented];
2545 def Lockable : InheritableAttr {
2546 let Spellings = [GNU<"lockable">];
2547 let Subjects = SubjectList<[Record]>;
2548 let Documentation = [Undocumented];
2549 let ASTNode = 0; // Replaced by Capability
2552 def ScopedLockable : InheritableAttr {
2553 let Spellings = [Clang<"scoped_lockable", 0>];
2554 let Subjects = SubjectList<[Record]>;
2555 let Documentation = [Undocumented];
2558 def Capability : InheritableAttr {
2559 let Spellings = [Clang<"capability", 0>, Clang<"shared_capability", 0>];
2560 let Subjects = SubjectList<[Record, TypedefName], ErrorDiag>;
2561 let Args = [StringArgument<"Name">];
2562 let Accessors = [Accessor<"isShared",
2563 [Clang<"shared_capability", 0>]>];
2564 let Documentation = [Undocumented];
2565 let AdditionalMembers = [{
2566 bool isMutex() const { return getName().equals_lower("mutex"); }
2567 bool isRole() const { return getName().equals_lower("role"); }
2571 def AssertCapability : InheritableAttr {
2572 let Spellings = [Clang<"assert_capability", 0>,
2573 Clang<"assert_shared_capability", 0>];
2574 let Subjects = SubjectList<[Function]>;
2576 let TemplateDependent = 1;
2577 let ParseArgumentsAsUnevaluated = 1;
2578 let InheritEvenIfAlreadyPresent = 1;
2579 let Args = [VariadicExprArgument<"Args">];
2580 let Accessors = [Accessor<"isShared",
2581 [Clang<"assert_shared_capability", 0>]>];
2582 let Documentation = [AssertCapabilityDocs];
2585 def AcquireCapability : InheritableAttr {
2586 let Spellings = [Clang<"acquire_capability", 0>,
2587 Clang<"acquire_shared_capability", 0>,
2588 GNU<"exclusive_lock_function">,
2589 GNU<"shared_lock_function">];
2590 let Subjects = SubjectList<[Function]>;
2592 let TemplateDependent = 1;
2593 let ParseArgumentsAsUnevaluated = 1;
2594 let InheritEvenIfAlreadyPresent = 1;
2595 let Args = [VariadicExprArgument<"Args">];
2596 let Accessors = [Accessor<"isShared",
2597 [Clang<"acquire_shared_capability", 0>,
2598 GNU<"shared_lock_function">]>];
2599 let Documentation = [AcquireCapabilityDocs];
2602 def TryAcquireCapability : InheritableAttr {
2603 let Spellings = [Clang<"try_acquire_capability", 0>,
2604 Clang<"try_acquire_shared_capability", 0>];
2605 let Subjects = SubjectList<[Function],
2608 let TemplateDependent = 1;
2609 let ParseArgumentsAsUnevaluated = 1;
2610 let InheritEvenIfAlreadyPresent = 1;
2611 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2612 let Accessors = [Accessor<"isShared",
2613 [Clang<"try_acquire_shared_capability", 0>]>];
2614 let Documentation = [TryAcquireCapabilityDocs];
2617 def ReleaseCapability : InheritableAttr {
2618 let Spellings = [Clang<"release_capability", 0>,
2619 Clang<"release_shared_capability", 0>,
2620 Clang<"release_generic_capability", 0>,
2621 Clang<"unlock_function", 0>];
2622 let Subjects = SubjectList<[Function]>;
2624 let TemplateDependent = 1;
2625 let ParseArgumentsAsUnevaluated = 1;
2626 let InheritEvenIfAlreadyPresent = 1;
2627 let Args = [VariadicExprArgument<"Args">];
2628 let Accessors = [Accessor<"isShared",
2629 [Clang<"release_shared_capability", 0>]>,
2630 Accessor<"isGeneric",
2631 [Clang<"release_generic_capability", 0>,
2632 Clang<"unlock_function", 0>]>];
2633 let Documentation = [ReleaseCapabilityDocs];
2636 def RequiresCapability : InheritableAttr {
2637 let Spellings = [Clang<"requires_capability", 0>,
2638 Clang<"exclusive_locks_required", 0>,
2639 Clang<"requires_shared_capability", 0>,
2640 Clang<"shared_locks_required", 0>];
2641 let Args = [VariadicExprArgument<"Args">];
2643 let TemplateDependent = 1;
2644 let ParseArgumentsAsUnevaluated = 1;
2645 let InheritEvenIfAlreadyPresent = 1;
2646 let Subjects = SubjectList<[Function]>;
2647 let Accessors = [Accessor<"isShared", [Clang<"requires_shared_capability", 0>,
2648 Clang<"shared_locks_required", 0>]>];
2649 let Documentation = [Undocumented];
2652 def NoThreadSafetyAnalysis : InheritableAttr {
2653 let Spellings = [Clang<"no_thread_safety_analysis">];
2654 let Subjects = SubjectList<[Function]>;
2655 let Documentation = [Undocumented];
2658 def GuardedBy : InheritableAttr {
2659 let Spellings = [GNU<"guarded_by">];
2660 let Args = [ExprArgument<"Arg">];
2662 let TemplateDependent = 1;
2663 let ParseArgumentsAsUnevaluated = 1;
2664 let InheritEvenIfAlreadyPresent = 1;
2665 let Subjects = SubjectList<[Field, SharedVar]>;
2666 let Documentation = [Undocumented];
2669 def PtGuardedBy : InheritableAttr {
2670 let Spellings = [GNU<"pt_guarded_by">];
2671 let Args = [ExprArgument<"Arg">];
2673 let TemplateDependent = 1;
2674 let ParseArgumentsAsUnevaluated = 1;
2675 let InheritEvenIfAlreadyPresent = 1;
2676 let Subjects = SubjectList<[Field, SharedVar]>;
2677 let Documentation = [Undocumented];
2680 def AcquiredAfter : InheritableAttr {
2681 let Spellings = [GNU<"acquired_after">];
2682 let Args = [VariadicExprArgument<"Args">];
2684 let TemplateDependent = 1;
2685 let ParseArgumentsAsUnevaluated = 1;
2686 let InheritEvenIfAlreadyPresent = 1;
2687 let Subjects = SubjectList<[Field, SharedVar]>;
2688 let Documentation = [Undocumented];
2691 def AcquiredBefore : InheritableAttr {
2692 let Spellings = [GNU<"acquired_before">];
2693 let Args = [VariadicExprArgument<"Args">];
2695 let TemplateDependent = 1;
2696 let ParseArgumentsAsUnevaluated = 1;
2697 let InheritEvenIfAlreadyPresent = 1;
2698 let Subjects = SubjectList<[Field, SharedVar]>;
2699 let Documentation = [Undocumented];
2702 def AssertExclusiveLock : InheritableAttr {
2703 let Spellings = [GNU<"assert_exclusive_lock">];
2704 let Args = [VariadicExprArgument<"Args">];
2706 let TemplateDependent = 1;
2707 let ParseArgumentsAsUnevaluated = 1;
2708 let InheritEvenIfAlreadyPresent = 1;
2709 let Subjects = SubjectList<[Function]>;
2710 let Documentation = [Undocumented];
2713 def AssertSharedLock : InheritableAttr {
2714 let Spellings = [GNU<"assert_shared_lock">];
2715 let Args = [VariadicExprArgument<"Args">];
2717 let TemplateDependent = 1;
2718 let ParseArgumentsAsUnevaluated = 1;
2719 let InheritEvenIfAlreadyPresent = 1;
2720 let Subjects = SubjectList<[Function]>;
2721 let Documentation = [Undocumented];
2724 // The first argument is an integer or boolean value specifying the return value
2725 // of a successful lock acquisition.
2726 def ExclusiveTrylockFunction : InheritableAttr {
2727 let Spellings = [GNU<"exclusive_trylock_function">];
2728 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2730 let TemplateDependent = 1;
2731 let ParseArgumentsAsUnevaluated = 1;
2732 let InheritEvenIfAlreadyPresent = 1;
2733 let Subjects = SubjectList<[Function]>;
2734 let Documentation = [Undocumented];
2737 // The first argument is an integer or boolean value specifying the return value
2738 // of a successful lock acquisition.
2739 def SharedTrylockFunction : InheritableAttr {
2740 let Spellings = [GNU<"shared_trylock_function">];
2741 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2743 let TemplateDependent = 1;
2744 let ParseArgumentsAsUnevaluated = 1;
2745 let InheritEvenIfAlreadyPresent = 1;
2746 let Subjects = SubjectList<[Function]>;
2747 let Documentation = [Undocumented];
2750 def LockReturned : InheritableAttr {
2751 let Spellings = [GNU<"lock_returned">];
2752 let Args = [ExprArgument<"Arg">];
2754 let TemplateDependent = 1;
2755 let ParseArgumentsAsUnevaluated = 1;
2756 let Subjects = SubjectList<[Function]>;
2757 let Documentation = [Undocumented];
2760 def LocksExcluded : InheritableAttr {
2761 let Spellings = [GNU<"locks_excluded">];
2762 let Args = [VariadicExprArgument<"Args">];
2764 let TemplateDependent = 1;
2765 let ParseArgumentsAsUnevaluated = 1;
2766 let InheritEvenIfAlreadyPresent = 1;
2767 let Subjects = SubjectList<[Function]>;
2768 let Documentation = [Undocumented];
2771 // C/C++ consumed attributes.
2773 def Consumable : InheritableAttr {
2774 // This attribute does not have a C [[]] spelling because it only appertains
2775 // to C++ struct/class/union.
2776 // FIXME: should this attribute have a CPlusPlus language option?
2777 let Spellings = [Clang<"consumable", 0>];
2778 let Subjects = SubjectList<[CXXRecord]>;
2779 let Args = [EnumArgument<"DefaultState", "ConsumedState",
2780 ["unknown", "consumed", "unconsumed"],
2781 ["Unknown", "Consumed", "Unconsumed"]>];
2782 let Documentation = [ConsumableDocs];
2785 def ConsumableAutoCast : InheritableAttr {
2786 // This attribute does not have a C [[]] spelling because it only appertains
2787 // to C++ struct/class/union.
2788 // FIXME: should this attribute have a CPlusPlus language option?
2789 let Spellings = [Clang<"consumable_auto_cast_state", 0>];
2790 let Subjects = SubjectList<[CXXRecord]>;
2791 let Documentation = [Undocumented];
2794 def ConsumableSetOnRead : InheritableAttr {
2795 // This attribute does not have a C [[]] spelling because it only appertains
2796 // to C++ struct/class/union.
2797 // FIXME: should this attribute have a CPlusPlus language option?
2798 let Spellings = [Clang<"consumable_set_state_on_read", 0>];
2799 let Subjects = SubjectList<[CXXRecord]>;
2800 let Documentation = [Undocumented];
2803 def CallableWhen : InheritableAttr {
2804 // This attribute does not have a C [[]] spelling because it only appertains
2805 // to C++ function (but doesn't require it to be a member function).
2806 // FIXME: should this attribute have a CPlusPlus language option?
2807 let Spellings = [Clang<"callable_when", 0>];
2808 let Subjects = SubjectList<[CXXMethod]>;
2809 let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
2810 ["unknown", "consumed", "unconsumed"],
2811 ["Unknown", "Consumed", "Unconsumed"]>];
2812 let Documentation = [CallableWhenDocs];
2815 def ParamTypestate : InheritableAttr {
2816 // This attribute does not have a C [[]] spelling because it only appertains
2817 // to a parameter whose type is a consumable C++ class.
2818 // FIXME: should this attribute have a CPlusPlus language option?
2819 let Spellings = [Clang<"param_typestate", 0>];
2820 let Subjects = SubjectList<[ParmVar]>;
2821 let Args = [EnumArgument<"ParamState", "ConsumedState",
2822 ["unknown", "consumed", "unconsumed"],
2823 ["Unknown", "Consumed", "Unconsumed"]>];
2824 let Documentation = [ParamTypestateDocs];
2827 def ReturnTypestate : InheritableAttr {
2828 // This attribute does not have a C [[]] spelling because it only appertains
2829 // to a parameter or function return type that is a consumable C++ class.
2830 // FIXME: should this attribute have a CPlusPlus language option?
2831 let Spellings = [Clang<"return_typestate", 0>];
2832 let Subjects = SubjectList<[Function, ParmVar]>;
2833 let Args = [EnumArgument<"State", "ConsumedState",
2834 ["unknown", "consumed", "unconsumed"],
2835 ["Unknown", "Consumed", "Unconsumed"]>];
2836 let Documentation = [ReturnTypestateDocs];
2839 def SetTypestate : InheritableAttr {
2840 // This attribute does not have a C [[]] spelling because it only appertains
2841 // to C++ function (but doesn't require it to be a member function).
2842 // FIXME: should this attribute have a CPlusPlus language option?
2843 let Spellings = [Clang<"set_typestate", 0>];
2844 let Subjects = SubjectList<[CXXMethod]>;
2845 let Args = [EnumArgument<"NewState", "ConsumedState",
2846 ["unknown", "consumed", "unconsumed"],
2847 ["Unknown", "Consumed", "Unconsumed"]>];
2848 let Documentation = [SetTypestateDocs];
2851 def TestTypestate : InheritableAttr {
2852 // This attribute does not have a C [[]] spelling because it only appertains
2853 // to C++ function (but doesn't require it to be a member function).
2854 // FIXME: should this attribute have a CPlusPlus language option?
2855 let Spellings = [Clang<"test_typestate", 0>];
2856 let Subjects = SubjectList<[CXXMethod]>;
2857 let Args = [EnumArgument<"TestState", "ConsumedState",
2858 ["consumed", "unconsumed"],
2859 ["Consumed", "Unconsumed"]>];
2860 let Documentation = [TestTypestateDocs];
2863 // Type safety attributes for `void *' pointers and type tags.
2865 def ArgumentWithTypeTag : InheritableAttr {
2866 let Spellings = [Clang<"argument_with_type_tag">,
2867 Clang<"pointer_with_type_tag">];
2868 let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>;
2869 let Args = [IdentifierArgument<"ArgumentKind">,
2870 ParamIdxArgument<"ArgumentIdx">,
2871 ParamIdxArgument<"TypeTagIdx">,
2872 BoolArgument<"IsPointer", /*opt*/0, /*fake*/1>];
2873 let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
2876 def TypeTagForDatatype : InheritableAttr {
2877 let Spellings = [Clang<"type_tag_for_datatype">];
2878 let Args = [IdentifierArgument<"ArgumentKind">,
2879 TypeArgument<"MatchingCType">,
2880 BoolArgument<"LayoutCompatible">,
2881 BoolArgument<"MustBeNull">];
2882 // let Subjects = SubjectList<[Var], ErrorDiag>;
2883 let HasCustomParsing = 1;
2884 let Documentation = [TypeTagForDatatypeDocs];
2887 def Owner : InheritableAttr {
2888 let Spellings = [CXX11<"gsl", "Owner">];
2889 let Subjects = SubjectList<[Struct]>;
2890 let Args = [TypeArgument<"DerefType", /*opt=*/1>];
2891 let Documentation = [LifetimeOwnerDocs];
2894 def Pointer : InheritableAttr {
2895 let Spellings = [CXX11<"gsl", "Pointer">];
2896 let Subjects = SubjectList<[Struct]>;
2897 let Args = [TypeArgument<"DerefType", /*opt=*/1>];
2898 let Documentation = [LifetimePointerDocs];
2901 // Microsoft-related attributes
2903 def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
2904 let Spellings = [Declspec<"novtable">];
2905 let Subjects = SubjectList<[CXXRecord]>;
2906 let Documentation = [MSNoVTableDocs];
2910 let Spellings = [Declspec<"property">];
2913 def MSAllocator : InheritableAttr {
2914 let Spellings = [Declspec<"allocator">];
2915 let Subjects = SubjectList<[Function]>;
2916 let Documentation = [MSAllocatorDocs];
2919 def CFGuard : InheritableAttr {
2920 // Currently only the __declspec(guard(nocf)) modifier is supported. In future
2921 // we might also want to support __declspec(guard(suppress)).
2922 let Spellings = [Declspec<"guard">];
2923 let Subjects = SubjectList<[Function]>;
2924 let Args = [EnumArgument<"Guard", "GuardArg", ["nocf"], ["nocf"]>];
2925 let Documentation = [CFGuardDocs];
2928 def MSStruct : InheritableAttr {
2929 let Spellings = [GCC<"ms_struct">];
2930 let Subjects = SubjectList<[Record]>;
2931 let Documentation = [Undocumented];
2934 def DLLExport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2935 let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
2936 let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2937 let Documentation = [DLLExportDocs];
2940 def DLLExportStaticLocal : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2941 // This attribute is used internally only when -fno-dllexport-inlines is
2942 // passed. This attribute is added to inline function of class having
2943 // dllexport attribute. And if the function has static local variables, this
2944 // attribute is used to whether the variables are exported or not. Also if
2945 // function has local static variables, the function is dllexported too.
2947 let Subjects = SubjectList<[Function]>;
2948 let Documentation = [Undocumented];
2951 def DLLImport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2952 let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
2953 let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2954 let Documentation = [DLLImportDocs];
2957 let AdditionalMembers = [{
2959 bool PropagatedToBaseTemplate = false;
2962 void setPropagatedToBaseTemplate() { PropagatedToBaseTemplate = true; }
2963 bool wasPropagatedToBaseTemplate() { return PropagatedToBaseTemplate; }
2967 def DLLImportStaticLocal : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2968 // This attribute is used internally only when -fno-dllexport-inlines is
2969 // passed. This attribute is added to inline function of class having
2970 // dllimport attribute. And if the function has static local variables, this
2971 // attribute is used to whether the variables are imported or not.
2973 let Subjects = SubjectList<[Function]>;
2974 let Documentation = [Undocumented];
2977 def SelectAny : InheritableAttr {
2978 let Spellings = [Declspec<"selectany">, GCC<"selectany">];
2979 let Documentation = [SelectAnyDocs];
2983 let Spellings = [Declspec<"thread">];
2984 let LangOpts = [MicrosoftExt];
2985 let Documentation = [ThreadDocs];
2986 let Subjects = SubjectList<[Var]>;
2989 def Win64 : IgnoredAttr {
2990 let Spellings = [Keyword<"__w64">];
2991 let LangOpts = [MicrosoftExt];
2994 def Ptr32 : TypeAttr {
2995 let Spellings = [Keyword<"__ptr32">];
2996 let Documentation = [Ptr32Docs];
2999 def Ptr64 : TypeAttr {
3000 let Spellings = [Keyword<"__ptr64">];
3001 let Documentation = [Ptr64Docs];
3004 def SPtr : TypeAttr {
3005 let Spellings = [Keyword<"__sptr">];
3006 let Documentation = [SPtrDocs];
3009 def UPtr : TypeAttr {
3010 let Spellings = [Keyword<"__uptr">];
3011 let Documentation = [UPtrDocs];
3014 def MSInheritance : InheritableAttr {
3015 let LangOpts = [MicrosoftExt];
3016 let Args = [DefaultBoolArgument<"BestCase", /*default*/1, /*fake*/1>];
3017 let Spellings = [Keyword<"__single_inheritance">,
3018 Keyword<"__multiple_inheritance">,
3019 Keyword<"__virtual_inheritance">,
3020 Keyword<"__unspecified_inheritance">];
3021 let AdditionalMembers = [{
3022 MSInheritanceModel getInheritanceModel() const {
3023 // The spelling enum should agree with MSInheritanceModel.
3024 return MSInheritanceModel(getSemanticSpelling());
3027 let Documentation = [MSInheritanceDocs];
3030 def MSVtorDisp : InheritableAttr {
3031 // This attribute has no spellings as it is only ever created implicitly.
3033 let Args = [UnsignedArgument<"vdm">];
3034 let SemaHandler = 0;
3036 let AdditionalMembers = [{
3037 MSVtorDispMode getVtorDispMode() const { return MSVtorDispMode(vdm); }
3039 let Documentation = [Undocumented];
3042 def InitSeg : Attr {
3043 let Spellings = [Pragma<"", "init_seg">];
3044 let Args = [StringArgument<"Section">];
3045 let SemaHandler = 0;
3046 let Documentation = [InitSegDocs];
3047 let AdditionalMembers = [{
3048 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3049 OS << " (" << getSection() << ')';
3054 def LoopHint : Attr {
3055 /// #pragma clang loop <option> directive
3056 /// vectorize: vectorizes loop operations if State == Enable.
3057 /// vectorize_width: vectorize loop operations with width 'Value'.
3058 /// interleave: interleave multiple loop iterations if State == Enable.
3059 /// interleave_count: interleaves 'Value' loop iterations.
3060 /// unroll: fully unroll loop if State == Enable.
3061 /// unroll_count: unrolls loop 'Value' times.
3062 /// unroll_and_jam: attempt to unroll and jam loop if State == Enable.
3063 /// unroll_and_jam_count: unroll and jams loop 'Value' times.
3064 /// distribute: attempt to distribute loop if State == Enable.
3065 /// pipeline: disable pipelining loop if State == Disable.
3066 /// pipeline_initiation_interval: create loop schedule with initiation interval equal to 'Value'.
3068 /// #pragma unroll <argument> directive
3069 /// <no arg>: fully unrolls loop.
3070 /// boolean: fully unrolls loop if State == Enable.
3071 /// expression: unrolls loop 'Value' times.
3073 let Spellings = [Pragma<"clang", "loop">, Pragma<"", "unroll">,
3074 Pragma<"", "nounroll">, Pragma<"", "unroll_and_jam">,
3075 Pragma<"", "nounroll_and_jam">];
3077 /// State of the loop optimization specified by the spelling.
3078 let Args = [EnumArgument<"Option", "OptionType",
3079 ["vectorize", "vectorize_width", "interleave", "interleave_count",
3080 "unroll", "unroll_count", "unroll_and_jam", "unroll_and_jam_count",
3081 "pipeline", "pipeline_initiation_interval", "distribute",
3082 "vectorize_predicate"],
3083 ["Vectorize", "VectorizeWidth", "Interleave", "InterleaveCount",
3084 "Unroll", "UnrollCount", "UnrollAndJam", "UnrollAndJamCount",
3085 "PipelineDisabled", "PipelineInitiationInterval", "Distribute",
3086 "VectorizePredicate"]>,
3087 EnumArgument<"State", "LoopHintState",
3088 ["enable", "disable", "numeric", "assume_safety", "full"],
3089 ["Enable", "Disable", "Numeric", "AssumeSafety", "Full"]>,
3090 ExprArgument<"Value">];
3092 let AdditionalMembers = [{
3093 static const char *getOptionName(int Option) {
3095 case Vectorize: return "vectorize";
3096 case VectorizeWidth: return "vectorize_width";
3097 case Interleave: return "interleave";
3098 case InterleaveCount: return "interleave_count";
3099 case Unroll: return "unroll";
3100 case UnrollCount: return "unroll_count";
3101 case UnrollAndJam: return "unroll_and_jam";
3102 case UnrollAndJamCount: return "unroll_and_jam_count";
3103 case PipelineDisabled: return "pipeline";
3104 case PipelineInitiationInterval: return "pipeline_initiation_interval";
3105 case Distribute: return "distribute";
3106 case VectorizePredicate: return "vectorize_predicate";
3108 llvm_unreachable("Unhandled LoopHint option.");
3111 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3112 unsigned SpellingIndex = getAttributeSpellingListIndex();
3113 // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
3114 // "nounroll" is already emitted as the pragma name.
3115 if (SpellingIndex == Pragma_nounroll || SpellingIndex == Pragma_nounroll_and_jam)
3117 else if (SpellingIndex == Pragma_unroll || SpellingIndex == Pragma_unroll_and_jam) {
3118 OS << ' ' << getValueString(Policy);
3122 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
3123 OS << ' ' << getOptionName(option) << getValueString(Policy);
3126 // Return a string containing the loop hint argument including the
3127 // enclosing parentheses.
3128 std::string getValueString(const PrintingPolicy &Policy) const {
3129 std::string ValueName;
3130 llvm::raw_string_ostream OS(ValueName);
3132 if (state == Numeric)
3133 value->printPretty(OS, nullptr, Policy);
3134 else if (state == Enable)
3136 else if (state == Full)
3138 else if (state == AssumeSafety)
3139 OS << "assume_safety";
3146 // Return a string suitable for identifying this attribute in diagnostics.
3147 std::string getDiagnosticName(const PrintingPolicy &Policy) const {
3148 unsigned SpellingIndex = getAttributeSpellingListIndex();
3149 if (SpellingIndex == Pragma_nounroll)
3150 return "#pragma nounroll";
3151 else if (SpellingIndex == Pragma_unroll)
3152 return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
3153 else if (SpellingIndex == Pragma_nounroll_and_jam)
3154 return "#pragma nounroll_and_jam";
3155 else if (SpellingIndex == Pragma_unroll_and_jam)
3156 return "#pragma unroll_and_jam" +
3157 (option == UnrollAndJamCount ? getValueString(Policy) : "");
3159 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
3160 return getOptionName(option) + getValueString(Policy);
3164 let Documentation = [LoopHintDocs, UnrollHintDocs];
3167 def CapturedRecord : InheritableAttr {
3168 // This attribute has no spellings as it is only ever created implicitly.
3170 let SemaHandler = 0;
3171 let Documentation = [Undocumented];
3174 def OMPThreadPrivateDecl : InheritableAttr {
3175 // This attribute has no spellings as it is only ever created implicitly.
3177 let SemaHandler = 0;
3178 let Documentation = [Undocumented];
3181 def OMPCaptureNoInit : InheritableAttr {
3182 // This attribute has no spellings as it is only ever created implicitly.
3184 let SemaHandler = 0;
3185 let Documentation = [Undocumented];
3188 def OMPCaptureKind : Attr {
3189 // This attribute has no spellings as it is only ever created implicitly.
3191 let SemaHandler = 0;
3192 let Args = [UnsignedArgument<"CaptureKind">];
3193 let Documentation = [Undocumented];
3196 def OMPReferencedVar : Attr {
3197 // This attribute has no spellings as it is only ever created implicitly.
3199 let SemaHandler = 0;
3200 let Args = [ExprArgument<"Ref">];
3201 let Documentation = [Undocumented];
3204 def OMPDeclareSimdDecl : Attr {
3205 let Spellings = [Pragma<"omp", "declare simd">];
3206 let Subjects = SubjectList<[Function]>;
3207 let SemaHandler = 0;
3208 let HasCustomParsing = 1;
3209 let Documentation = [OMPDeclareSimdDocs];
3211 EnumArgument<"BranchState", "BranchStateTy",
3212 [ "", "inbranch", "notinbranch" ],
3213 [ "BS_Undefined", "BS_Inbranch", "BS_Notinbranch" ]>,
3214 ExprArgument<"Simdlen">, VariadicExprArgument<"Uniforms">,
3215 VariadicExprArgument<"Aligneds">, VariadicExprArgument<"Alignments">,
3216 VariadicExprArgument<"Linears">, VariadicUnsignedArgument<"Modifiers">,
3217 VariadicExprArgument<"Steps">
3219 let AdditionalMembers = [{
3220 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
3222 if (getBranchState() != BS_Undefined)
3223 OS << ' ' << ConvertBranchStateTyToStr(getBranchState());
3224 if (auto *E = getSimdlen()) {
3226 E->printPretty(OS, nullptr, Policy);
3229 if (uniforms_size() > 0) {
3231 StringRef Sep = "(";
3232 for (auto *E : uniforms()) {
3234 E->printPretty(OS, nullptr, Policy);
3239 alignments_iterator NI = alignments_begin();
3240 for (auto *E : aligneds()) {
3242 E->printPretty(OS, nullptr, Policy);
3245 (*NI)->printPretty(OS, nullptr, Policy);
3250 steps_iterator I = steps_begin();
3251 modifiers_iterator MI = modifiers_begin();
3252 for (auto *E : linears()) {
3254 if (*MI != OMPC_LINEAR_unknown)
3255 OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
3256 E->printPretty(OS, nullptr, Policy);
3257 if (*MI != OMPC_LINEAR_unknown)
3261 (*I)->printPretty(OS, nullptr, Policy);
3271 def OMPDeclareTargetDecl : InheritableAttr {
3272 let Spellings = [Pragma<"omp", "declare target">];
3273 let SemaHandler = 0;
3274 let Subjects = SubjectList<[Function, SharedVar]>;
3275 let Documentation = [OMPDeclareTargetDocs];
3277 EnumArgument<"MapType", "MapTypeTy",
3279 [ "MT_To", "MT_Link" ]>,
3280 EnumArgument<"DevType", "DevTypeTy",
3281 [ "host", "nohost", "any" ],
3282 [ "DT_Host", "DT_NoHost", "DT_Any" ]>
3284 let AdditionalMembers = [{
3285 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3286 // Use fake syntax because it is for testing and debugging purpose only.
3287 if (getDevType() != DT_Any)
3288 OS << " device_type(" << ConvertDevTypeTyToStr(getDevType()) << ")";
3289 if (getMapType() != MT_To)
3290 OS << ' ' << ConvertMapTypeTyToStr(getMapType());
3292 static llvm::Optional<MapTypeTy>
3293 isDeclareTargetDeclaration(const ValueDecl *VD) {
3294 if (!VD->hasAttrs())
3296 if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>())
3297 return Attr->getMapType();
3301 static llvm::Optional<DevTypeTy> getDeviceType(const ValueDecl *VD) {
3302 if (!VD->hasAttrs())
3304 if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>())
3305 return Attr->getDevType();
3312 def OMPAllocateDecl : InheritableAttr {
3313 // This attribute has no spellings as it is only ever created implicitly.
3315 let SemaHandler = 0;
3317 EnumArgument<"AllocatorType", "AllocatorTypeTy",
3319 "omp_default_mem_alloc", "omp_large_cap_mem_alloc",
3320 "omp_const_mem_alloc", "omp_high_bw_mem_alloc",
3321 "omp_low_lat_mem_alloc", "omp_cgroup_mem_alloc",
3322 "omp_pteam_mem_alloc", "omp_thread_mem_alloc", ""
3325 "OMPDefaultMemAlloc", "OMPLargeCapMemAlloc",
3326 "OMPConstMemAlloc", "OMPHighBWMemAlloc", "OMPLowLatMemAlloc",
3327 "OMPCGroupMemAlloc", "OMPPTeamMemAlloc", "OMPThreadMemAlloc",
3328 "OMPUserDefinedMemAlloc"
3330 ExprArgument<"Allocator">
3332 let Documentation = [Undocumented];
3335 def OMPDeclareVariant : InheritableAttr {
3336 let Spellings = [Pragma<"omp", "declare variant">];
3337 let Subjects = SubjectList<[Function]>;
3338 let SemaHandler = 0;
3339 let HasCustomParsing = 1;
3340 let InheritEvenIfAlreadyPresent = 1;
3341 let Documentation = [OMPDeclareVariantDocs];
3343 ExprArgument<"VariantFuncRef">,
3344 VariadicExprArgument<"Scores">,
3345 VariadicUnsignedArgument<"CtxSelectorSets">,
3346 VariadicUnsignedArgument<"CtxSelectors">,
3347 VariadicStringArgument<"ImplVendors">,
3348 VariadicStringArgument<"DeviceKinds">
3350 let AdditionalMembers = [{
3351 void printScore(raw_ostream & OS, const PrintingPolicy &Policy, unsigned I) const {
3352 if (const Expr *E = *std::next(scores_begin(), I)) {
3354 E->printPretty(OS, nullptr, Policy);
3358 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
3360 if (const Expr *E = getVariantFuncRef()) {
3362 E->printPretty(OS, nullptr, Policy);
3365 // TODO: add printing of real context selectors.
3367 int Used[OMP_CTX_SET_unknown] = {0};
3368 for (unsigned I = 0, E = ctxSelectorSets_size(); I < E; ++I) {
3369 auto CtxSet = static_cast<OpenMPContextSelectorSetKind>(
3370 *std::next(ctxSelectorSets_begin(), I));
3376 case OMP_CTX_SET_implementation:
3377 OS << "implementation={";
3379 case OMP_CTX_SET_device:
3382 case OMP_CTX_SET_unknown:
3383 llvm_unreachable("Unknown context selector set.");
3386 for (unsigned K = I, EK = ctxSelectors_size(); K < EK; ++K) {
3387 auto CtxSetK = static_cast<OpenMPContextSelectorSetKind>(
3388 *std::next(ctxSelectorSets_begin(), K));
3389 if (CtxSet != CtxSetK)
3393 auto Ctx = static_cast<OpenMPContextSelectorKind>(
3394 *std::next(ctxSelectors_begin(), K));
3396 case OMP_CTX_vendor:
3397 assert(CtxSet == OMP_CTX_SET_implementation &&
3398 "Expected implementation context selector set.");
3400 printScore(OS, Policy, K);
3401 if (implVendors_size() > 0) {
3402 OS << *implVendors(). begin();
3403 for (StringRef VendorName : llvm::drop_begin(implVendors(), 1))
3404 OS << ", " << VendorName;
3409 assert(CtxSet == OMP_CTX_SET_device &&
3410 "Expected device context selector set.");
3412 if (deviceKinds_size() > 0) {
3413 OS << *deviceKinds().begin();
3414 for (StringRef KindName : llvm::drop_begin(deviceKinds(), 1))
3415 OS << ", " << KindName;
3419 case OMP_CTX_unknown:
3420 llvm_unreachable("Unknown context selector.");
3430 def InternalLinkage : InheritableAttr {
3431 let Spellings = [Clang<"internal_linkage">];
3432 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
3433 let Documentation = [InternalLinkageDocs];
3436 def ExcludeFromExplicitInstantiation : InheritableAttr {
3437 let Spellings = [Clang<"exclude_from_explicit_instantiation">];
3438 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
3439 let Documentation = [ExcludeFromExplicitInstantiationDocs];
3440 let MeaningfulToClassTemplateDefinition = 1;
3443 def Reinitializes : InheritableAttr {
3444 let Spellings = [Clang<"reinitializes", 0>];
3445 let Subjects = SubjectList<[NonStaticNonConstCXXMethod], ErrorDiag>;
3446 let Documentation = [ReinitializesDocs];
3449 def NoDestroy : InheritableAttr {
3450 let Spellings = [Clang<"no_destroy", 0>];
3451 let Subjects = SubjectList<[Var]>;
3452 let Documentation = [NoDestroyDocs];
3455 def AlwaysDestroy : InheritableAttr {
3456 let Spellings = [Clang<"always_destroy", 0>];
3457 let Subjects = SubjectList<[Var]>;
3458 let Documentation = [AlwaysDestroyDocs];
3461 def SpeculativeLoadHardening : InheritableAttr {
3462 let Spellings = [Clang<"speculative_load_hardening">];
3463 let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
3464 let Documentation = [SpeculativeLoadHardeningDocs];
3467 def NoSpeculativeLoadHardening : InheritableAttr {
3468 let Spellings = [Clang<"no_speculative_load_hardening">];
3469 let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
3470 let Documentation = [NoSpeculativeLoadHardeningDocs];
3473 def Uninitialized : InheritableAttr {
3474 let Spellings = [Clang<"uninitialized", 0>];
3475 let Subjects = SubjectList<[LocalVar]>;
3476 let Documentation = [UninitializedDocs];
3479 def ObjCExternallyRetained : InheritableAttr {
3480 let LangOpts = [ObjCAutoRefCount];
3481 let Spellings = [Clang<"objc_externally_retained">];
3482 let Subjects = SubjectList<[NonParmVar, Function, Block, ObjCMethod]>;
3483 let Documentation = [ObjCExternallyRetainedDocs];
3486 def NoBuiltin : Attr {
3487 let Spellings = [Clang<"no_builtin">];
3488 let Args = [VariadicStringArgument<"BuiltinNames">];
3489 let Subjects = SubjectList<[Function]>;
3490 let Documentation = [NoBuiltinDocs];
3493 // FIXME: This attribute is not inheritable, it will not be propagated to
3494 // redecls. [[clang::lifetimebound]] has the same problems. This should be
3495 // fixed in TableGen (by probably adding a new inheritable flag).
3496 def AcquireHandle : DeclOrTypeAttr {
3497 let Spellings = [Clang<"acquire_handle">];
3498 let Args = [StringArgument<"HandleType">];
3499 let Subjects = SubjectList<[Function, TypedefName, ParmVar]>;
3500 let Documentation = [AcquireHandleDocs];
3503 def UseHandle : InheritableParamAttr {
3504 let Spellings = [Clang<"use_handle">];
3505 let Args = [StringArgument<"HandleType">];
3506 let Subjects = SubjectList<[ParmVar]>;
3507 let Documentation = [UseHandleDocs];
3510 def ReleaseHandle : InheritableParamAttr {
3511 let Spellings = [Clang<"release_handle">];
3512 let Args = [StringArgument<"HandleType">];
3513 let Subjects = SubjectList<[ParmVar]>;
3514 let Documentation = [ReleaseHandleDocs];