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">;
124 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
125 // type to be a class, not a definition. This makes it impossible to create an
126 // attribute subject which accepts a Decl. Normally, this is not a problem,
127 // because the attribute can have no Subjects clause to accomplish this. But in
128 // the case of a SubsetSubject, there's no way to express it without this hack.
129 def DeclBase : AttrSubject;
130 def FunctionLike : SubsetSubject<DeclBase,
131 [{S->getFunctionType(false) != nullptr}],
132 "functions, function pointers">;
134 def OpenCLKernelFunction
135 : SubsetSubject<Function, [{S->hasAttr<OpenCLKernelAttr>()}],
138 // HasFunctionProto is a more strict version of FunctionLike, so it should
139 // never be specified in a Subjects list along with FunctionLike (due to the
140 // inclusive nature of subject testing).
141 def HasFunctionProto : SubsetSubject<DeclBase,
142 [{(S->getFunctionType(true) != nullptr &&
143 isa<FunctionProtoType>(S->getFunctionType())) ||
144 isa<ObjCMethodDecl>(S) ||
146 "non-K&R-style functions">;
148 // A subject that matches the implicit object parameter of a non-static member
149 // function. Accepted as a function type attribute on the type of such a
151 // FIXME: This does not actually ever match currently.
152 def ImplicitObjectParameter
153 : SubsetSubject<Function, [{static_cast<void>(S), false}],
154 "implicit object parameters">;
156 // A single argument to an attribute
157 class Argument<string name, bit optional, bit fake = 0> {
159 bit Optional = optional;
161 /// A fake argument is used to store and serialize additional information
162 /// in an attribute without actually changing its parsing or pretty-printing.
166 class BoolArgument<string name, bit opt = 0, bit fake = 0> : Argument<name, opt,
168 class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
169 class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
170 class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
171 class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
172 class FunctionArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
175 class NamedArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
178 class TypeArgument<string name, bit opt = 0> : Argument<name, opt>;
179 class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
180 class VariadicUnsignedArgument<string name> : Argument<name, 1>;
181 class VariadicExprArgument<string name> : Argument<name, 1>;
182 class VariadicStringArgument<string name> : Argument<name, 1>;
183 class VariadicIdentifierArgument<string name> : Argument<name, 1>;
185 // Like VariadicUnsignedArgument except values are ParamIdx.
186 class VariadicParamIdxArgument<string name> : Argument<name, 1>;
188 // A list of identifiers matching parameters or ParamIdx indices.
189 class VariadicParamOrParamIdxArgument<string name> : Argument<name, 1>;
191 // Like VariadicParamIdxArgument but for a single function parameter index.
192 class ParamIdxArgument<string name, bit opt = 0> : Argument<name, opt>;
194 // A version of the form major.minor[.subminor].
195 class VersionArgument<string name, bit opt = 0> : Argument<name, opt>;
197 // This one's a doozy, so it gets its own special type
198 // It can be an unsigned integer, or a type. Either can
200 class AlignedArgument<string name, bit opt = 0> : Argument<name, opt>;
202 // A bool argument with a default value
203 class DefaultBoolArgument<string name, bit default, bit fake = 0>
204 : BoolArgument<name, 1, fake> {
205 bit Default = default;
208 // An integer argument with a default value
209 class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
210 int Default = default;
213 // This argument is more complex, it includes the enumerator type name,
214 // a list of strings to accept, and a list of enumerators to map them to.
215 class EnumArgument<string name, string type, list<string> values,
216 list<string> enums, bit opt = 0, bit fake = 0>
217 : Argument<name, opt, fake> {
219 list<string> Values = values;
220 list<string> Enums = enums;
223 // FIXME: There should be a VariadicArgument type that takes any other type
224 // of argument and generates the appropriate type.
225 class VariadicEnumArgument<string name, string type, list<string> values,
226 list<string> enums> : Argument<name, 1> {
228 list<string> Values = values;
229 list<string> Enums = enums;
232 // This handles one spelling of an attribute.
233 class Spelling<string name, string variety> {
235 string Variety = variety;
239 class GNU<string name> : Spelling<name, "GNU">;
240 class Declspec<string name> : Spelling<name, "Declspec">;
241 class Microsoft<string name> : Spelling<name, "Microsoft">;
242 class CXX11<string namespace, string name, int version = 1>
243 : Spelling<name, "CXX11"> {
244 string Namespace = namespace;
245 int Version = version;
247 class C2x<string namespace, string name> : Spelling<name, "C2x"> {
248 string Namespace = namespace;
251 class Keyword<string name> : Spelling<name, "Keyword">;
252 class Pragma<string namespace, string name> : Spelling<name, "Pragma"> {
253 string Namespace = namespace;
256 // The GCC spelling implies GNU<name> and CXX11<"gnu", name> and also sets
257 // KnownToGCC to 1. This spelling should be used for any GCC-compatible
259 class GCC<string name> : Spelling<name, "GCC"> {
263 // The Clang spelling implies GNU<name>, CXX11<"clang", name>, and optionally,
264 // C2x<"clang", name>. This spelling should be used for any Clang-specific
266 class Clang<string name, bit allowInC = 1> : Spelling<name, "Clang"> {
267 bit AllowInC = allowInC;
270 class Accessor<string name, list<Spelling> spellings> {
272 list<Spelling> Spellings = spellings;
275 class SubjectDiag<bit warn> {
278 def WarnDiag : SubjectDiag<1>;
279 def ErrorDiag : SubjectDiag<0>;
281 class SubjectList<list<AttrSubject> subjects, SubjectDiag diag = WarnDiag,
282 string customDiag = ""> {
283 list<AttrSubject> Subjects = subjects;
284 SubjectDiag Diag = diag;
285 string CustomDiag = customDiag;
288 class LangOpt<string name, code customCode = [{}]> {
291 // A custom predicate, written as an expression evaluated in a context with
293 code CustomCode = customCode;
295 def MicrosoftExt : LangOpt<"MicrosoftExt">;
296 def Borland : LangOpt<"Borland">;
297 def CUDA : LangOpt<"CUDA">;
298 def HIP : LangOpt<"HIP">;
299 def COnly : LangOpt<"COnly", "!LangOpts.CPlusPlus">;
300 def CPlusPlus : LangOpt<"CPlusPlus">;
301 def OpenCL : LangOpt<"OpenCL">;
302 def RenderScript : LangOpt<"RenderScript">;
303 def ObjC : LangOpt<"ObjC">;
304 def BlocksSupported : LangOpt<"Blocks">;
305 def ObjCAutoRefCount : LangOpt<"ObjCAutoRefCount">;
306 def ObjCNonFragileRuntime : LangOpt<"ObjCNonFragileRuntime",
307 "LangOpts.ObjCRuntime.allowsClassStubs()">;
309 // Language option for CMSE extensions
310 def Cmse : LangOpt<"Cmse">;
312 // Defines targets for target-specific attributes. Empty lists are unchecked.
314 // Specifies Architectures for which the target applies, based off the
315 // ArchType enumeration in Triple.h.
316 list<string> Arches = [];
317 // Specifies Operating Systems for which the target applies, based off the
318 // OSType enumeration in Triple.h
320 // Specifies Object Formats for which the target applies, based off the
321 // ObjectFormatType enumeration in Triple.h
322 list<string> ObjectFormats;
323 // A custom predicate, written as an expression evaluated in a context
324 // with the following declarations in scope:
325 // const clang::TargetInfo &Target;
326 // const llvm::Triple &T = Target.getTriple();
327 code CustomCode = [{}];
330 class TargetArch<list<string> arches> : TargetSpec {
333 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
334 def TargetAVR : TargetArch<["avr"]>;
335 def TargetMips32 : TargetArch<["mips", "mipsel"]>;
336 def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
337 def TargetMSP430 : TargetArch<["msp430"]>;
338 def TargetRISCV : TargetArch<["riscv32", "riscv64"]>;
339 def TargetX86 : TargetArch<["x86"]>;
340 def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
341 def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>;
342 def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb", "aarch64"]> {
343 let OSes = ["Win32"];
345 def TargetItaniumCXXABI : TargetSpec {
346 let CustomCode = [{ Target.getCXXABI().isItaniumFamily() }];
348 def TargetMicrosoftCXXABI : TargetArch<["x86", "x86_64", "arm", "thumb", "aarch64"]> {
349 let CustomCode = [{ Target.getCXXABI().isMicrosoft() }];
351 def TargetELF : TargetSpec {
352 let ObjectFormats = ["ELF"];
355 // Attribute subject match rules that are used for #pragma clang attribute.
357 // A instance of AttrSubjectMatcherRule represents an individual match rule.
358 // An individual match rule can correspond to a number of different attribute
359 // subjects, e.g. "record" matching rule corresponds to the Record and
360 // CXXRecord attribute subjects.
362 // Match rules are used in the subject list of the #pragma clang attribute.
363 // Match rules can have sub-match rules that are instances of
364 // AttrSubjectMatcherSubRule. A sub-match rule can correspond to a number
365 // of different attribute subjects, and it can have a negated spelling as well.
366 // For example, "variable(unless(is_parameter))" matching rule corresponds to
367 // the NonParmVar attribute subject.
368 class AttrSubjectMatcherSubRule<string name, list<AttrSubject> subjects,
371 list<AttrSubject> Subjects = subjects;
372 bit Negated = negated;
373 // Lists language options, one of which is required to be true for the
374 // attribute to be applicable. If empty, the language options are taken
375 // from the parent matcher rule.
376 list<LangOpt> LangOpts = [];
378 class AttrSubjectMatcherRule<string name, list<AttrSubject> subjects,
379 list<AttrSubjectMatcherSubRule> subrules = []> {
381 list<AttrSubject> Subjects = subjects;
382 list<AttrSubjectMatcherSubRule> Constraints = subrules;
383 // Lists language options, one of which is required to be true for the
384 // attribute to be applicable. If empty, no language options are required.
385 list<LangOpt> LangOpts = [];
388 // function(is_member)
389 def SubRuleForCXXMethod : AttrSubjectMatcherSubRule<"is_member", [CXXMethod]> {
390 let LangOpts = [CPlusPlus];
392 def SubjectMatcherForFunction : AttrSubjectMatcherRule<"function", [Function], [
395 // hasType is abstract, it should be used with one of the sub-rules.
396 def SubjectMatcherForType : AttrSubjectMatcherRule<"hasType", [], [
397 AttrSubjectMatcherSubRule<"functionType", [FunctionLike]>
399 // FIXME: There's a matcher ambiguity with objc methods and blocks since
400 // functionType excludes them but functionProtoType includes them.
401 // AttrSubjectMatcherSubRule<"functionProtoType", [HasFunctionProto]>
403 def SubjectMatcherForTypedef : AttrSubjectMatcherRule<"type_alias",
405 def SubjectMatcherForRecord : AttrSubjectMatcherRule<"record", [Record,
408 AttrSubjectMatcherSubRule<"is_union", [Struct], 1>
410 def SubjectMatcherForEnum : AttrSubjectMatcherRule<"enum", [Enum]>;
411 def SubjectMatcherForEnumConstant : AttrSubjectMatcherRule<"enum_constant",
413 def SubjectMatcherForVar : AttrSubjectMatcherRule<"variable", [Var], [
414 AttrSubjectMatcherSubRule<"is_thread_local", [TLSVar]>,
415 AttrSubjectMatcherSubRule<"is_global", [GlobalVar]>,
416 AttrSubjectMatcherSubRule<"is_parameter", [ParmVar]>,
417 // unless(is_parameter)
418 AttrSubjectMatcherSubRule<"is_parameter", [NonParmVar], 1>
420 def SubjectMatcherForField : AttrSubjectMatcherRule<"field", [Field]>;
421 def SubjectMatcherForNamespace : AttrSubjectMatcherRule<"namespace",
423 let LangOpts = [CPlusPlus];
425 def SubjectMatcherForObjCInterface : AttrSubjectMatcherRule<"objc_interface",
427 let LangOpts = [ObjC];
429 def SubjectMatcherForObjCProtocol : AttrSubjectMatcherRule<"objc_protocol",
431 let LangOpts = [ObjC];
433 def SubjectMatcherForObjCCategory : AttrSubjectMatcherRule<"objc_category",
435 let LangOpts = [ObjC];
437 def SubjectMatcherForObjCImplementation :
438 AttrSubjectMatcherRule<"objc_implementation", [ObjCImpl]> {
439 let LangOpts = [ObjC];
441 def SubjectMatcherForObjCMethod : AttrSubjectMatcherRule<"objc_method",
443 AttrSubjectMatcherSubRule<"is_instance", [ObjCInstanceMethod]>
445 let LangOpts = [ObjC];
447 def SubjectMatcherForObjCProperty : AttrSubjectMatcherRule<"objc_property",
449 let LangOpts = [ObjC];
451 def SubjectMatcherForBlock : AttrSubjectMatcherRule<"block", [Block]> {
452 let LangOpts = [BlocksSupported];
455 // Aggregate attribute subject match rules are abstract match rules that can't
456 // be used directly in #pragma clang attribute. Instead, users have to use
457 // subject match rules that correspond to attribute subjects that derive from
458 // the specified subject.
459 class AttrSubjectMatcherAggregateRule<AttrSubject subject> {
460 AttrSubject Subject = subject;
463 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule<Named>;
466 // The various ways in which an attribute can be spelled in source
467 list<Spelling> Spellings;
468 // The things to which an attribute can appertain
469 SubjectList Subjects;
470 // The arguments allowed on an attribute
471 list<Argument> Args = [];
472 // Accessors which should be generated for the attribute.
473 list<Accessor> Accessors = [];
474 // Set to true for attributes with arguments which require delayed parsing.
476 // Set to false to prevent an attribute from being propagated from a template
477 // to the instantiation.
479 // Set to true for attributes which must be instantiated within templates
480 bit TemplateDependent = 0;
481 // Set to true for attributes that have a corresponding AST node.
483 // Set to true for attributes which have handler in Sema.
485 // Set to true for attributes that are completely ignored.
487 // Set to true if the attribute's parsing does not match its semantic
488 // content. Eg) It parses 3 args, but semantically takes 4 args. Opts out of
489 // common attribute error checking.
490 bit HasCustomParsing = 0;
491 // Set to true if all of the attribute's arguments should be parsed in an
492 // unevaluated context.
493 bit ParseArgumentsAsUnevaluated = 0;
494 // Set to true if this attribute meaningful when applied to or inherited
495 // in a class template definition.
496 bit MeaningfulToClassTemplateDefinition = 0;
497 // Set to true if this attribute can be used with '#pragma clang attribute'.
498 // By default, an attribute is supported by the '#pragma clang attribute'
500 // - It has a subject list whose subjects can be represented using subject
502 // - It has GNU/CXX11 spelling and doesn't require delayed parsing.
503 bit PragmaAttributeSupport;
504 // Lists language options, one of which is required to be true for the
505 // attribute to be applicable. If empty, no language options are required.
506 list<LangOpt> LangOpts = [];
507 // Any additional text that should be included verbatim in the class.
508 // Note: Any additional data members will leak and should be constructed
509 // externally on the ASTContext.
510 code AdditionalMembers = [{}];
511 // Any documentation that should be associated with the attribute. Since an
512 // attribute may be documented under multiple categories, more than one
513 // Documentation entry may be listed.
514 list<Documentation> Documentation;
517 /// A type attribute is not processed on a declaration or a statement.
518 class TypeAttr : Attr;
520 /// A stmt attribute is not processed on a declaration or a type.
521 class StmtAttr : Attr;
523 /// An inheritable attribute is inherited by later redeclarations.
524 class InheritableAttr : Attr {
525 // Set to true if this attribute can be duplicated on a subject when inheriting
526 // attributes from prior declarations.
527 bit InheritEvenIfAlreadyPresent = 0;
530 /// Some attributes, like calling conventions, can appear in either the
531 /// declaration or the type position. These attributes are morally type
532 /// attributes, but have historically been written on declarations.
533 class DeclOrTypeAttr : InheritableAttr;
535 /// A target-specific attribute. This class is meant to be used as a mixin
536 /// with InheritableAttr or Attr depending on the attribute's needs.
537 class TargetSpecificAttr<TargetSpec target> {
538 TargetSpec Target = target;
539 // Attributes are generally required to have unique spellings for their names
540 // so that the parser can determine what kind of attribute it has parsed.
541 // However, target-specific attributes are special in that the attribute only
542 // "exists" for a given target. So two target-specific attributes can share
543 // the same name when they exist in different targets. To support this, a
544 // Kind can be explicitly specified for a target-specific attribute. This
545 // corresponds to the ParsedAttr::AT_* enum that is generated and it
546 // should contain a shared value between the attributes.
548 // Target-specific attributes which use this feature should ensure that the
549 // spellings match exactly between the attributes, and if the arguments or
550 // subjects differ, should specify HasCustomParsing = 1 and implement their
551 // own parsing and semantic handling requirements as-needed.
555 /// An inheritable parameter attribute is inherited by later
556 /// redeclarations, even when it's written on a parameter.
557 class InheritableParamAttr : InheritableAttr;
559 /// An attribute which changes the ABI rules for a specific parameter.
560 class ParameterABIAttr : InheritableParamAttr {
561 let Subjects = SubjectList<[ParmVar]>;
564 /// An ignored attribute, which we parse but discard with no checking.
565 class IgnoredAttr : Attr {
569 let Documentation = [Undocumented];
573 // Attributes begin here
577 let Spellings = [GCC<"abi_tag">];
578 let Args = [VariadicStringArgument<"Tags">];
579 let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag>;
580 let MeaningfulToClassTemplateDefinition = 1;
581 let Documentation = [AbiTagsDocs];
584 def AddressSpace : TypeAttr {
585 let Spellings = [Clang<"address_space">];
586 let Args = [IntArgument<"AddressSpace">];
587 let Documentation = [Undocumented];
591 let Spellings = [GCC<"alias">];
592 let Args = [StringArgument<"Aliasee">];
593 let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;
594 let Documentation = [Undocumented];
597 def Aligned : InheritableAttr {
598 let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
599 Keyword<"_Alignas">];
600 let Args = [AlignedArgument<"Alignment", 1>];
601 let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
602 Accessor<"isC11", [Keyword<"_Alignas">]>,
603 Accessor<"isAlignas", [Keyword<"alignas">,
604 Keyword<"_Alignas">]>,
605 Accessor<"isDeclspec",[Declspec<"align">]>];
606 let Documentation = [Undocumented];
609 def AlignValue : Attr {
611 // Unfortunately, this is semantically an assertion, not a directive
612 // (something else must ensure the alignment), so aligned_value is a
613 // probably a better name. We might want to add an aligned_value spelling in
614 // the future (and a corresponding C++ attribute), but this can be done
615 // later once we decide if we also want them to have slightly-different
616 // semantics than Intel's align_value.
618 // Does not get a [[]] spelling because the attribute is not exposed as such
621 // Intel's compiler on Windows also supports:
622 // , Declspec<"align_value">
624 let Args = [ExprArgument<"Alignment">];
625 let Subjects = SubjectList<[Var, TypedefName]>;
626 let Documentation = [AlignValueDocs];
629 def AlignMac68k : InheritableAttr {
630 // This attribute has no spellings as it is only ever created implicitly.
633 let Documentation = [Undocumented];
636 def AlwaysInline : InheritableAttr {
637 let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
638 let Subjects = SubjectList<[Function]>;
639 let Documentation = [Undocumented];
642 def Artificial : InheritableAttr {
643 let Spellings = [GCC<"artificial">];
644 let Subjects = SubjectList<[InlineFunction], WarnDiag>;
645 let Documentation = [ArtificialDocs];
648 def XRayInstrument : InheritableAttr {
649 let Spellings = [Clang<"xray_always_instrument">,
650 Clang<"xray_never_instrument">];
651 let Subjects = SubjectList<[Function, ObjCMethod]>;
652 let Accessors = [Accessor<"alwaysXRayInstrument",
653 [Clang<"xray_always_instrument">]>,
654 Accessor<"neverXRayInstrument",
655 [Clang<"xray_never_instrument">]>];
656 let Documentation = [XRayDocs];
659 def XRayLogArgs : InheritableAttr {
660 let Spellings = [Clang<"xray_log_args">];
661 let Subjects = SubjectList<[Function, ObjCMethod]>;
662 // This argument is a count not an index, so it has the same encoding (base
663 // 1 including C++ implicit this parameter) at the source and LLVM levels of
664 // representation, so ParamIdxArgument is inappropriate. It is never used
665 // at the AST level of representation, so it never needs to be adjusted not
666 // to include any C++ implicit this parameter. Thus, we just store it and
667 // use it as an unsigned that never needs adjustment.
668 let Args = [UnsignedArgument<"ArgumentCount">];
669 let Documentation = [XRayDocs];
672 def TLSModel : InheritableAttr {
673 let Spellings = [GCC<"tls_model">];
674 let Subjects = SubjectList<[TLSVar], ErrorDiag>;
675 let Args = [StringArgument<"Model">];
676 let Documentation = [TLSModelDocs];
679 def AnalyzerNoReturn : InheritableAttr {
680 // TODO: should this attribute be exposed with a [[]] spelling under the clang
681 // vendor namespace, or should it use a vendor namespace specific to the
683 let Spellings = [GNU<"analyzer_noreturn">];
684 // TODO: Add subject list.
685 let Documentation = [Undocumented];
688 def Annotate : InheritableParamAttr {
689 let Spellings = [Clang<"annotate">];
690 let Args = [StringArgument<"Annotation">];
691 // Ensure that the annotate attribute can be used with
692 // '#pragma clang attribute' even though it has no subject list.
693 let PragmaAttributeSupport = 1;
694 let Documentation = [Undocumented];
697 def ARMInterrupt : InheritableAttr, TargetSpecificAttr<TargetARM> {
698 // NOTE: If you add any additional spellings, MSP430Interrupt's,
699 // MipsInterrupt's and AnyX86Interrupt's spellings must match.
700 let Spellings = [GCC<"interrupt">];
701 let Args = [EnumArgument<"Interrupt", "InterruptType",
702 ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
703 ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
705 let ParseKind = "Interrupt";
706 let HasCustomParsing = 1;
707 let Documentation = [ARMInterruptDocs];
710 def AVRInterrupt : InheritableAttr, TargetSpecificAttr<TargetAVR> {
711 let Spellings = [GCC<"interrupt">];
712 let Subjects = SubjectList<[Function]>;
713 let ParseKind = "Interrupt";
714 let Documentation = [AVRInterruptDocs];
717 def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
718 let Spellings = [GCC<"signal">];
719 let Subjects = SubjectList<[Function]>;
720 let Documentation = [AVRSignalDocs];
723 def AsmLabel : InheritableAttr {
724 let Spellings = [Keyword<"asm">, Keyword<"__asm__">];
726 // Label specifies the mangled name for the decl.
727 StringArgument<"Label">,
729 // IsLiteralLabel specifies whether the label is literal (i.e. suppresses
730 // the global C symbol prefix) or not. If not, the mangle-suppression prefix
731 // ('\01') is omitted from the decl name at the LLVM IR level.
733 // Non-literal labels are used by some external AST sources like LLDB.
734 BoolArgument<"IsLiteralLabel", /*optional=*/0, /*fake=*/1>
737 let Documentation = [AsmLabelDocs];
738 let AdditionalMembers =
740 bool isEquivalent(AsmLabelAttr *Other) const {
741 return getLabel() == Other->getLabel() && getIsLiteralLabel() == Other->getIsLiteralLabel();
746 def Availability : InheritableAttr {
747 let Spellings = [Clang<"availability">];
748 let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
749 VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
750 BoolArgument<"unavailable">, StringArgument<"message">,
751 BoolArgument<"strict">, StringArgument<"replacement">,
752 IntArgument<"priority">];
753 let AdditionalMembers =
754 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
755 return llvm::StringSwitch<llvm::StringRef>(Platform)
756 .Case("android", "Android")
758 .Case("macos", "macOS")
759 .Case("tvos", "tvOS")
760 .Case("watchos", "watchOS")
761 .Case("ios_app_extension", "iOS (App Extension)")
762 .Case("macos_app_extension", "macOS (App Extension)")
763 .Case("tvos_app_extension", "tvOS (App Extension)")
764 .Case("watchos_app_extension", "watchOS (App Extension)")
765 .Case("swift", "Swift")
766 .Default(llvm::StringRef());
768 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
769 return llvm::StringSwitch<llvm::StringRef>(Platform)
771 .Case("macos", "macOS")
772 .Case("tvos", "tvOS")
773 .Case("watchos", "watchOS")
774 .Case("ios_app_extension", "iOSApplicationExtension")
775 .Case("macos_app_extension", "macOSApplicationExtension")
776 .Case("tvos_app_extension", "tvOSApplicationExtension")
777 .Case("watchos_app_extension", "watchOSApplicationExtension")
780 static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
781 return llvm::StringSwitch<llvm::StringRef>(Platform)
783 .Case("macOS", "macos")
784 .Case("tvOS", "tvos")
785 .Case("watchOS", "watchos")
786 .Case("iOSApplicationExtension", "ios_app_extension")
787 .Case("macOSApplicationExtension", "macos_app_extension")
788 .Case("tvOSApplicationExtension", "tvos_app_extension")
789 .Case("watchOSApplicationExtension", "watchos_app_extension")
792 let HasCustomParsing = 1;
793 let InheritEvenIfAlreadyPresent = 1;
794 let Subjects = SubjectList<[Named]>;
795 let Documentation = [AvailabilityDocs];
798 def ExternalSourceSymbol : InheritableAttr {
799 let Spellings = [Clang<"external_source_symbol">];
800 let Args = [StringArgument<"language", 1>,
801 StringArgument<"definedIn", 1>,
802 BoolArgument<"generatedDeclaration", 1>];
803 let HasCustomParsing = 1;
804 let Subjects = SubjectList<[Named]>;
805 let Documentation = [ExternalSourceSymbolDocs];
808 def Blocks : InheritableAttr {
809 let Spellings = [Clang<"blocks">];
810 let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
811 let Documentation = [Undocumented];
814 def Bounded : IgnoredAttr {
815 // Does not have a [[]] spelling because the attribute is ignored.
816 let Spellings = [GNU<"bounded">];
819 def CarriesDependency : InheritableParamAttr {
820 let Spellings = [GNU<"carries_dependency">,
821 CXX11<"","carries_dependency", 200809>];
822 let Subjects = SubjectList<[ParmVar, ObjCMethod, Function], ErrorDiag>;
823 let Documentation = [CarriesDependencyDocs];
826 def CDecl : DeclOrTypeAttr {
827 let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
828 // let Subjects = [Function, ObjCMethod];
829 let Documentation = [Undocumented];
832 // cf_audited_transfer indicates that the given function has been
833 // audited and has been marked with the appropriate cf_consumed and
834 // cf_returns_retained attributes. It is generally applied by
835 // '#pragma clang arc_cf_code_audited' rather than explicitly.
836 def CFAuditedTransfer : InheritableAttr {
837 let Spellings = [Clang<"cf_audited_transfer">];
838 let Subjects = SubjectList<[Function], ErrorDiag>;
839 let Documentation = [Undocumented];
842 // cf_unknown_transfer is an explicit opt-out of cf_audited_transfer.
843 // It indicates that the function has unknown or unautomatable
844 // transfer semantics.
845 def CFUnknownTransfer : InheritableAttr {
846 let Spellings = [Clang<"cf_unknown_transfer">];
847 let Subjects = SubjectList<[Function], ErrorDiag>;
848 let Documentation = [Undocumented];
851 def CFReturnsRetained : InheritableAttr {
852 let Spellings = [Clang<"cf_returns_retained">];
853 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
854 let Documentation = [RetainBehaviorDocs];
857 def CFReturnsNotRetained : InheritableAttr {
858 let Spellings = [Clang<"cf_returns_not_retained">];
859 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
860 let Documentation = [RetainBehaviorDocs];
863 def CFConsumed : InheritableParamAttr {
864 let Spellings = [Clang<"cf_consumed">];
865 let Subjects = SubjectList<[ParmVar]>;
866 let Documentation = [RetainBehaviorDocs];
869 // OSObject-based attributes.
870 def OSConsumed : InheritableParamAttr {
871 let Spellings = [Clang<"os_consumed">];
872 let Subjects = SubjectList<[ParmVar]>;
873 let Documentation = [RetainBehaviorDocs];
876 def OSReturnsRetained : InheritableAttr {
877 let Spellings = [Clang<"os_returns_retained">];
878 let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty, ParmVar]>;
879 let Documentation = [RetainBehaviorDocs];
882 def OSReturnsNotRetained : InheritableAttr {
883 let Spellings = [Clang<"os_returns_not_retained">];
884 let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty, ParmVar]>;
885 let Documentation = [RetainBehaviorDocs];
888 def OSReturnsRetainedOnZero : InheritableAttr {
889 let Spellings = [Clang<"os_returns_retained_on_zero">];
890 let Subjects = SubjectList<[ParmVar]>;
891 let Documentation = [RetainBehaviorDocs];
894 def OSReturnsRetainedOnNonZero : InheritableAttr {
895 let Spellings = [Clang<"os_returns_retained_on_non_zero">];
896 let Subjects = SubjectList<[ParmVar]>;
897 let Documentation = [RetainBehaviorDocs];
900 def OSConsumesThis : InheritableAttr {
901 let Spellings = [Clang<"os_consumes_this">];
902 let Subjects = SubjectList<[NonStaticCXXMethod]>;
903 let Documentation = [RetainBehaviorDocs];
906 def Cleanup : InheritableAttr {
907 let Spellings = [GCC<"cleanup">];
908 let Args = [FunctionArgument<"FunctionDecl">];
909 let Subjects = SubjectList<[LocalVar]>;
910 let Documentation = [Undocumented];
913 def Cold : InheritableAttr {
914 let Spellings = [GCC<"cold">];
915 let Subjects = SubjectList<[Function]>;
916 let Documentation = [Undocumented];
919 def Common : InheritableAttr {
920 let Spellings = [GCC<"common">];
921 let Subjects = SubjectList<[Var]>;
922 let Documentation = [Undocumented];
925 def Const : InheritableAttr {
926 let Spellings = [GCC<"const">, GCC<"__const">];
927 let Documentation = [Undocumented];
930 def ConstInit : InheritableAttr {
931 // This attribute does not have a C [[]] spelling because it requires the
932 // CPlusPlus language option.
933 let Spellings = [Keyword<"constinit">,
934 Clang<"require_constant_initialization", 0>];
935 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
936 let Accessors = [Accessor<"isConstinit", [Keyword<"constinit">]>];
937 let Documentation = [ConstInitDocs];
938 let LangOpts = [CPlusPlus];
941 def Constructor : InheritableAttr {
942 let Spellings = [GCC<"constructor">];
943 let Args = [DefaultIntArgument<"Priority", 65535>];
944 let Subjects = SubjectList<[Function]>;
945 let Documentation = [Undocumented];
948 def CPUSpecific : InheritableAttr {
949 let Spellings = [Clang<"cpu_specific">, Declspec<"cpu_specific">];
950 let Args = [VariadicIdentifierArgument<"Cpus">];
951 let Subjects = SubjectList<[Function]>;
952 let Documentation = [CPUSpecificCPUDispatchDocs];
953 let AdditionalMembers = [{
954 IdentifierInfo *getCPUName(unsigned Index) const {
955 return *(cpus_begin() + Index);
960 def CPUDispatch : InheritableAttr {
961 let Spellings = [Clang<"cpu_dispatch">, Declspec<"cpu_dispatch">];
962 let Args = [VariadicIdentifierArgument<"Cpus">];
963 let Subjects = SubjectList<[Function]>;
964 let Documentation = [CPUSpecificCPUDispatchDocs];
967 // CUDA attributes are spelled __attribute__((attr)) or __declspec(__attr__),
968 // and they do not receive a [[]] spelling.
969 def CUDAConstant : InheritableAttr {
970 let Spellings = [GNU<"constant">, Declspec<"__constant__">];
971 let Subjects = SubjectList<[Var]>;
972 let LangOpts = [CUDA];
973 let Documentation = [Undocumented];
976 def CUDACudartBuiltin : IgnoredAttr {
977 let Spellings = [GNU<"cudart_builtin">, Declspec<"__cudart_builtin__">];
978 let LangOpts = [CUDA];
981 def CUDADevice : InheritableAttr {
982 let Spellings = [GNU<"device">, Declspec<"__device__">];
983 let Subjects = SubjectList<[Function, Var]>;
984 let LangOpts = [CUDA];
985 let Documentation = [Undocumented];
988 def HIPPinnedShadow : InheritableAttr {
989 let Spellings = [GNU<"hip_pinned_shadow">, Declspec<"__hip_pinned_shadow__">];
990 let Subjects = SubjectList<[Var]>;
991 let LangOpts = [HIP];
992 let Documentation = [HIPPinnedShadowDocs];
995 def CUDADeviceBuiltin : IgnoredAttr {
996 let Spellings = [GNU<"device_builtin">, Declspec<"__device_builtin__">];
997 let LangOpts = [CUDA];
1000 def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
1001 let Spellings = [GNU<"device_builtin_surface_type">,
1002 Declspec<"__device_builtin_surface_type__">];
1003 let LangOpts = [CUDA];
1006 def CUDADeviceBuiltinTextureType : IgnoredAttr {
1007 let Spellings = [GNU<"device_builtin_texture_type">,
1008 Declspec<"__device_builtin_texture_type__">];
1009 let LangOpts = [CUDA];
1012 def CUDAGlobal : InheritableAttr {
1013 let Spellings = [GNU<"global">, Declspec<"__global__">];
1014 let Subjects = SubjectList<[Function]>;
1015 let LangOpts = [CUDA];
1016 let Documentation = [Undocumented];
1019 def CUDAHost : InheritableAttr {
1020 let Spellings = [GNU<"host">, Declspec<"__host__">];
1021 let Subjects = SubjectList<[Function]>;
1022 let LangOpts = [CUDA];
1023 let Documentation = [Undocumented];
1026 def CUDAInvalidTarget : InheritableAttr {
1028 let Subjects = SubjectList<[Function]>;
1029 let LangOpts = [CUDA];
1030 let Documentation = [Undocumented];
1033 def CUDALaunchBounds : InheritableAttr {
1034 let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
1035 let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
1036 let LangOpts = [CUDA];
1037 let Subjects = SubjectList<[ObjCMethod, FunctionLike]>;
1038 // An AST node is created for this attribute, but is not used by other parts
1039 // of the compiler. However, this node needs to exist in the AST because
1040 // non-LLVM backends may be relying on the attribute's presence.
1041 let Documentation = [Undocumented];
1044 def CUDAShared : InheritableAttr {
1045 let Spellings = [GNU<"shared">, Declspec<"__shared__">];
1046 let Subjects = SubjectList<[Var]>;
1047 let LangOpts = [CUDA];
1048 let Documentation = [Undocumented];
1051 def C11NoReturn : InheritableAttr {
1052 let Spellings = [Keyword<"_Noreturn">];
1053 let Subjects = SubjectList<[Function], ErrorDiag>;
1054 let SemaHandler = 0;
1055 let Documentation = [C11NoReturnDocs];
1058 def CXX11NoReturn : InheritableAttr {
1059 let Spellings = [CXX11<"", "noreturn", 200809>];
1060 let Subjects = SubjectList<[Function], ErrorDiag>;
1061 let Documentation = [CXX11NoReturnDocs];
1064 // Similar to CUDA, OpenCL attributes do not receive a [[]] spelling because
1065 // the specification does not expose them with one currently.
1066 def OpenCLKernel : InheritableAttr {
1067 let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
1068 let Subjects = SubjectList<[Function], ErrorDiag>;
1069 let Documentation = [Undocumented];
1072 def OpenCLUnrollHint : InheritableAttr {
1073 let Spellings = [GNU<"opencl_unroll_hint">];
1074 let Args = [UnsignedArgument<"UnrollHint">];
1075 let Documentation = [OpenCLUnrollHintDocs];
1078 def OpenCLIntelReqdSubGroupSize: InheritableAttr {
1079 let Spellings = [GNU<"intel_reqd_sub_group_size">];
1080 let Args = [UnsignedArgument<"SubGroupSize">];
1081 let Subjects = SubjectList<[Function], ErrorDiag>;
1082 let Documentation = [OpenCLIntelReqdSubGroupSizeDocs];
1085 // This attribute is both a type attribute, and a declaration attribute (for
1086 // parameter variables).
1087 def OpenCLAccess : Attr {
1088 let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
1089 Keyword<"__write_only">, Keyword<"write_only">,
1090 Keyword<"__read_write">, Keyword<"read_write">];
1091 let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag>;
1092 let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
1093 Keyword<"read_only">]>,
1094 Accessor<"isReadWrite", [Keyword<"__read_write">,
1095 Keyword<"read_write">]>,
1096 Accessor<"isWriteOnly", [Keyword<"__write_only">,
1097 Keyword<"write_only">]>];
1098 let Documentation = [OpenCLAccessDocs];
1101 def OpenCLPrivateAddressSpace : TypeAttr {
1102 let Spellings = [Keyword<"__private">, Keyword<"private">];
1103 let Documentation = [OpenCLAddressSpacePrivateDocs];
1106 def OpenCLGlobalAddressSpace : TypeAttr {
1107 let Spellings = [Keyword<"__global">, Keyword<"global">];
1108 let Documentation = [OpenCLAddressSpaceGlobalDocs];
1111 def OpenCLLocalAddressSpace : TypeAttr {
1112 let Spellings = [Keyword<"__local">, Keyword<"local">];
1113 let Documentation = [OpenCLAddressSpaceLocalDocs];
1116 def OpenCLConstantAddressSpace : TypeAttr {
1117 let Spellings = [Keyword<"__constant">, Keyword<"constant">];
1118 let Documentation = [OpenCLAddressSpaceConstantDocs];
1121 def OpenCLGenericAddressSpace : TypeAttr {
1122 let Spellings = [Keyword<"__generic">, Keyword<"generic">];
1123 let Documentation = [OpenCLAddressSpaceGenericDocs];
1126 def OpenCLNoSVM : Attr {
1127 let Spellings = [GNU<"nosvm">];
1128 let Subjects = SubjectList<[Var]>;
1129 let Documentation = [OpenCLNoSVMDocs];
1130 let LangOpts = [OpenCL];
1134 def RenderScriptKernel : Attr {
1135 let Spellings = [GNU<"kernel">];
1136 let Subjects = SubjectList<[Function]>;
1137 let Documentation = [RenderScriptKernelAttributeDocs];
1138 let LangOpts = [RenderScript];
1141 def Deprecated : InheritableAttr {
1142 let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
1143 CXX11<"","deprecated", 201309>, C2x<"", "deprecated">];
1144 let Args = [StringArgument<"Message", 1>,
1145 // An optional string argument that enables us to provide a
1147 StringArgument<"Replacement", 1>];
1148 let MeaningfulToClassTemplateDefinition = 1;
1149 let Documentation = [DeprecatedDocs];
1152 def Destructor : InheritableAttr {
1153 let Spellings = [GCC<"destructor">];
1154 let Args = [DefaultIntArgument<"Priority", 65535>];
1155 let Subjects = SubjectList<[Function]>;
1156 let Documentation = [Undocumented];
1159 def EmptyBases : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1160 let Spellings = [Declspec<"empty_bases">];
1161 let Subjects = SubjectList<[CXXRecord]>;
1162 let Documentation = [EmptyBasesDocs];
1165 def AllocSize : InheritableAttr {
1166 let Spellings = [GCC<"alloc_size">];
1167 let Subjects = SubjectList<[Function]>;
1168 let Args = [ParamIdxArgument<"ElemSizeParam">,
1169 ParamIdxArgument<"NumElemsParam", /*opt*/ 1>];
1170 let TemplateDependent = 1;
1171 let Documentation = [AllocSizeDocs];
1174 def EnableIf : InheritableAttr {
1175 // Does not have a [[]] spelling because this attribute requires the ability
1176 // to parse function arguments but the attribute is not written in the type
1178 let Spellings = [GNU<"enable_if">];
1179 let Subjects = SubjectList<[Function]>;
1180 let Args = [ExprArgument<"Cond">, StringArgument<"Message">];
1181 let TemplateDependent = 1;
1182 let Documentation = [EnableIfDocs];
1185 def ExtVectorType : Attr {
1186 // This is an OpenCL-related attribute and does not receive a [[]] spelling.
1187 let Spellings = [GNU<"ext_vector_type">];
1188 // FIXME: This subject list is wrong; this is a type attribute.
1189 let Subjects = SubjectList<[TypedefName], ErrorDiag>;
1190 let Args = [ExprArgument<"NumElements">];
1192 let Documentation = [Undocumented];
1193 // This is a type attribute with an incorrect subject list, so should not be
1194 // permitted by #pragma clang attribute.
1195 let PragmaAttributeSupport = 0;
1198 def FallThrough : StmtAttr {
1199 let Spellings = [CXX11<"", "fallthrough", 201603>, C2x<"", "fallthrough">,
1200 CXX11<"clang", "fallthrough">, GCC<"fallthrough">];
1201 // let Subjects = [NullStmt];
1202 let Documentation = [FallthroughDocs];
1205 def FastCall : DeclOrTypeAttr {
1206 let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
1207 Keyword<"_fastcall">];
1208 // let Subjects = [Function, ObjCMethod];
1209 let Documentation = [FastCallDocs];
1212 def RegCall : DeclOrTypeAttr {
1213 let Spellings = [GCC<"regcall">, Keyword<"__regcall">];
1214 let Documentation = [RegCallDocs];
1217 def Final : InheritableAttr {
1218 let Spellings = [Keyword<"final">, Keyword<"sealed">];
1219 let Accessors = [Accessor<"isSpelledAsSealed", [Keyword<"sealed">]>];
1220 let SemaHandler = 0;
1221 let Documentation = [Undocumented];
1224 def MinSize : InheritableAttr {
1225 let Spellings = [Clang<"minsize">];
1226 let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
1227 let Documentation = [Undocumented];
1230 def FlagEnum : InheritableAttr {
1231 let Spellings = [Clang<"flag_enum">];
1232 let Subjects = SubjectList<[Enum]>;
1233 let Documentation = [FlagEnumDocs];
1236 def EnumExtensibility : InheritableAttr {
1237 let Spellings = [Clang<"enum_extensibility">];
1238 let Subjects = SubjectList<[Enum]>;
1239 let Args = [EnumArgument<"Extensibility", "Kind",
1240 ["closed", "open"], ["Closed", "Open"]>];
1241 let Documentation = [EnumExtensibilityDocs];
1244 def Flatten : InheritableAttr {
1245 let Spellings = [GCC<"flatten">];
1246 let Subjects = SubjectList<[Function], ErrorDiag>;
1247 let Documentation = [FlattenDocs];
1250 def Format : InheritableAttr {
1251 let Spellings = [GCC<"format">];
1252 let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">,
1253 IntArgument<"FirstArg">];
1254 let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto]>;
1255 let Documentation = [FormatDocs];
1258 def FormatArg : InheritableAttr {
1259 let Spellings = [GCC<"format_arg">];
1260 let Args = [ParamIdxArgument<"FormatIdx">];
1261 let Subjects = SubjectList<[ObjCMethod, HasFunctionProto]>;
1262 let Documentation = [Undocumented];
1265 def Callback : InheritableAttr {
1266 let Spellings = [Clang<"callback">];
1267 let Args = [VariadicParamOrParamIdxArgument<"Encoding">];
1268 let Subjects = SubjectList<[Function]>;
1269 let Documentation = [CallbackDocs];
1272 def GNUInline : InheritableAttr {
1273 let Spellings = [GCC<"gnu_inline">];
1274 let Subjects = SubjectList<[Function]>;
1275 let Documentation = [GnuInlineDocs];
1278 def Hot : InheritableAttr {
1279 let Spellings = [GCC<"hot">];
1280 let Subjects = SubjectList<[Function]>;
1281 // An AST node is created for this attribute, but not actually used beyond
1282 // semantic checking for mutual exclusion with the Cold attribute.
1283 let Documentation = [Undocumented];
1286 def IBAction : InheritableAttr {
1287 let Spellings = [Clang<"ibaction">];
1288 let Subjects = SubjectList<[ObjCInstanceMethod]>;
1289 // An AST node is created for this attribute, but is not used by other parts
1290 // of the compiler. However, this node needs to exist in the AST because
1291 // external tools rely on it.
1292 let Documentation = [Undocumented];
1295 def IBOutlet : InheritableAttr {
1296 let Spellings = [Clang<"iboutlet">];
1297 // let Subjects = [ObjCIvar, ObjCProperty];
1298 let Documentation = [Undocumented];
1301 def IBOutletCollection : InheritableAttr {
1302 let Spellings = [Clang<"iboutletcollection">];
1303 let Args = [TypeArgument<"Interface", 1>];
1304 // let Subjects = [ObjCIvar, ObjCProperty];
1305 let Documentation = [Undocumented];
1308 def IFunc : Attr, TargetSpecificAttr<TargetELF> {
1309 let Spellings = [GCC<"ifunc">];
1310 let Args = [StringArgument<"Resolver">];
1311 let Subjects = SubjectList<[Function]>;
1312 let Documentation = [IFuncDocs];
1315 def Restrict : InheritableAttr {
1316 let Spellings = [Declspec<"restrict">, GCC<"malloc">];
1317 let Subjects = SubjectList<[Function]>;
1318 let Documentation = [Undocumented];
1321 def LayoutVersion : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1322 let Spellings = [Declspec<"layout_version">];
1323 let Args = [UnsignedArgument<"Version">];
1324 let Subjects = SubjectList<[CXXRecord]>;
1325 let Documentation = [LayoutVersionDocs];
1328 def LifetimeBound : DeclOrTypeAttr {
1329 let Spellings = [Clang<"lifetimebound", 0>];
1330 let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
1331 let Documentation = [LifetimeBoundDocs];
1332 let LangOpts = [CPlusPlus];
1335 def TrivialABI : InheritableAttr {
1336 // This attribute does not have a C [[]] spelling because it requires the
1337 // CPlusPlus language option.
1338 let Spellings = [Clang<"trivial_abi", 0>];
1339 let Subjects = SubjectList<[CXXRecord]>;
1340 let Documentation = [TrivialABIDocs];
1341 let LangOpts = [CPlusPlus];
1344 def MaxFieldAlignment : InheritableAttr {
1345 // This attribute has no spellings as it is only ever created implicitly.
1347 let Args = [UnsignedArgument<"Alignment">];
1348 let SemaHandler = 0;
1349 let Documentation = [Undocumented];
1352 def MayAlias : InheritableAttr {
1353 // FIXME: this is a type attribute in GCC, but a declaration attribute here.
1354 let Spellings = [GCC<"may_alias">];
1355 let Documentation = [Undocumented];
1358 def MIGServerRoutine : InheritableAttr {
1359 let Spellings = [Clang<"mig_server_routine">];
1360 let Subjects = SubjectList<[Function, ObjCMethod, Block]>;
1361 let Documentation = [MIGConventionDocs];
1364 def MSABI : DeclOrTypeAttr {
1365 let Spellings = [GCC<"ms_abi">];
1366 // let Subjects = [Function, ObjCMethod];
1367 let Documentation = [MSABIDocs];
1370 def MSP430Interrupt : InheritableAttr, TargetSpecificAttr<TargetMSP430> {
1371 // NOTE: If you add any additional spellings, ARMInterrupt's, MipsInterrupt's
1372 // and AnyX86Interrupt's spellings must match.
1373 let Spellings = [GCC<"interrupt">];
1374 let Args = [UnsignedArgument<"Number">];
1375 let ParseKind = "Interrupt";
1376 let HasCustomParsing = 1;
1377 let Documentation = [Undocumented];
1380 def Mips16 : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1381 let Spellings = [GCC<"mips16">];
1382 let Subjects = SubjectList<[Function], ErrorDiag>;
1383 let Documentation = [Undocumented];
1386 def MipsInterrupt : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1387 // NOTE: If you add any additional spellings, ARMInterrupt's,
1388 // MSP430Interrupt's and AnyX86Interrupt's spellings must match.
1389 let Spellings = [GCC<"interrupt">];
1390 let Subjects = SubjectList<[Function]>;
1391 let Args = [EnumArgument<"Interrupt", "InterruptType",
1392 ["vector=sw0", "vector=sw1", "vector=hw0",
1393 "vector=hw1", "vector=hw2", "vector=hw3",
1394 "vector=hw4", "vector=hw5", "eic", ""],
1395 ["sw0", "sw1", "hw0", "hw1", "hw2", "hw3",
1396 "hw4", "hw5", "eic", "eic"]
1398 let ParseKind = "Interrupt";
1399 let Documentation = [MipsInterruptDocs];
1402 def MicroMips : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1403 let Spellings = [GCC<"micromips">];
1404 let Subjects = SubjectList<[Function], ErrorDiag>;
1405 let Documentation = [MicroMipsDocs];
1408 def MipsLongCall : InheritableAttr, TargetSpecificAttr<TargetAnyMips> {
1409 let Spellings = [GCC<"long_call">, GCC<"far">];
1410 let Subjects = SubjectList<[Function]>;
1411 let Documentation = [MipsLongCallStyleDocs];
1414 def MipsShortCall : InheritableAttr, TargetSpecificAttr<TargetAnyMips> {
1415 let Spellings = [GCC<"short_call">, GCC<"near">];
1416 let Subjects = SubjectList<[Function]>;
1417 let Documentation = [MipsShortCallStyleDocs];
1421 let Spellings = [GCC<"mode">];
1422 let Subjects = SubjectList<[Var, Enum, TypedefName, Field], ErrorDiag>;
1423 let Args = [IdentifierArgument<"Mode">];
1424 let Documentation = [Undocumented];
1425 // This is notionally a type attribute, which #pragma clang attribute
1426 // generally does not support.
1427 let PragmaAttributeSupport = 0;
1430 def Naked : InheritableAttr {
1431 let Spellings = [GCC<"naked">, Declspec<"naked">];
1432 let Subjects = SubjectList<[Function]>;
1433 let Documentation = [Undocumented];
1436 def NeonPolyVectorType : TypeAttr {
1437 let Spellings = [Clang<"neon_polyvector_type">];
1438 let Args = [IntArgument<"NumElements">];
1439 let Documentation = [Undocumented];
1440 // Represented as VectorType instead.
1444 def NeonVectorType : TypeAttr {
1445 let Spellings = [Clang<"neon_vector_type">];
1446 let Args = [IntArgument<"NumElements">];
1447 let Documentation = [Undocumented];
1448 // Represented as VectorType instead.
1452 def NoUniqueAddress : InheritableAttr, TargetSpecificAttr<TargetItaniumCXXABI> {
1453 let Spellings = [CXX11<"", "no_unique_address", 201803>];
1454 let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1455 let Documentation = [NoUniqueAddressDocs];
1458 def ReturnsTwice : InheritableAttr {
1459 let Spellings = [GCC<"returns_twice">];
1460 let Subjects = SubjectList<[Function]>;
1461 let Documentation = [Undocumented];
1464 def DisableTailCalls : InheritableAttr {
1465 let Spellings = [Clang<"disable_tail_calls">];
1466 let Subjects = SubjectList<[Function, ObjCMethod]>;
1467 let Documentation = [DisableTailCallsDocs];
1470 def NoAlias : InheritableAttr {
1471 let Spellings = [Declspec<"noalias">];
1472 let Subjects = SubjectList<[Function]>;
1473 let Documentation = [NoAliasDocs];
1476 def NoCommon : InheritableAttr {
1477 let Spellings = [GCC<"nocommon">];
1478 let Subjects = SubjectList<[Var]>;
1479 let Documentation = [Undocumented];
1482 def NoDebug : InheritableAttr {
1483 let Spellings = [GCC<"nodebug">];
1484 let Subjects = SubjectList<[TypedefName, FunctionLike, ObjCMethod, NonParmVar]>;
1485 let Documentation = [NoDebugDocs];
1488 def NoDuplicate : InheritableAttr {
1489 let Spellings = [Clang<"noduplicate">];
1490 let Subjects = SubjectList<[Function]>;
1491 let Documentation = [NoDuplicateDocs];
1494 def Convergent : InheritableAttr {
1495 let Spellings = [Clang<"convergent">];
1496 let Subjects = SubjectList<[Function]>;
1497 let Documentation = [ConvergentDocs];
1500 def NoInline : InheritableAttr {
1501 let Spellings = [GCC<"noinline">, Declspec<"noinline">];
1502 let Subjects = SubjectList<[Function]>;
1503 let Documentation = [Undocumented];
1506 def NoMips16 : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1507 let Spellings = [GCC<"nomips16">];
1508 let Subjects = SubjectList<[Function], ErrorDiag>;
1509 let Documentation = [Undocumented];
1512 def NoMicroMips : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1513 let Spellings = [GCC<"nomicromips">];
1514 let Subjects = SubjectList<[Function], ErrorDiag>;
1515 let Documentation = [MicroMipsDocs];
1518 def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
1519 let Spellings = [GCC<"interrupt">];
1520 let Subjects = SubjectList<[Function]>;
1521 let Args = [EnumArgument<"Interrupt", "InterruptType",
1522 ["user", "supervisor", "machine"],
1523 ["user", "supervisor", "machine"],
1525 let ParseKind = "Interrupt";
1526 let Documentation = [RISCVInterruptDocs];
1529 // This is not a TargetSpecificAttr so that is silently accepted and
1530 // ignored on other targets as encouraged by the OpenCL spec.
1532 // See OpenCL 1.2 6.11.5: "It is our intention that a particular
1533 // implementation of OpenCL be free to ignore all attributes and the
1534 // resulting executable binary will produce the same result."
1536 // However, only AMD GPU targets will emit the corresponding IR
1539 // FIXME: This provides a sub-optimal error message if you attempt to
1540 // use this in CUDA, since CUDA does not use the same terminology.
1542 // FIXME: SubjectList should be for OpenCLKernelFunction, but is not to
1543 // workaround needing to see kernel attribute before others to know if
1544 // this should be rejected on non-kernels.
1546 def AMDGPUFlatWorkGroupSize : InheritableAttr {
1547 let Spellings = [Clang<"amdgpu_flat_work_group_size", 0>];
1548 let Args = [ExprArgument<"Min">, ExprArgument<"Max">];
1549 let Documentation = [AMDGPUFlatWorkGroupSizeDocs];
1550 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1553 def AMDGPUWavesPerEU : InheritableAttr {
1554 let Spellings = [Clang<"amdgpu_waves_per_eu", 0>];
1555 let Args = [ExprArgument<"Min">, ExprArgument<"Max", 1>];
1556 let Documentation = [AMDGPUWavesPerEUDocs];
1557 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1560 def AMDGPUNumSGPR : InheritableAttr {
1561 let Spellings = [Clang<"amdgpu_num_sgpr", 0>];
1562 let Args = [UnsignedArgument<"NumSGPR">];
1563 let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1564 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1567 def AMDGPUNumVGPR : InheritableAttr {
1568 let Spellings = [Clang<"amdgpu_num_vgpr", 0>];
1569 let Args = [UnsignedArgument<"NumVGPR">];
1570 let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1571 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1574 def WebAssemblyImportModule : InheritableAttr,
1575 TargetSpecificAttr<TargetWebAssembly> {
1576 let Spellings = [Clang<"import_module">];
1577 let Args = [StringArgument<"ImportModule">];
1578 let Documentation = [WebAssemblyImportModuleDocs];
1579 let Subjects = SubjectList<[Function], ErrorDiag>;
1582 def WebAssemblyImportName : InheritableAttr,
1583 TargetSpecificAttr<TargetWebAssembly> {
1584 let Spellings = [Clang<"import_name">];
1585 let Args = [StringArgument<"ImportName">];
1586 let Documentation = [WebAssemblyImportNameDocs];
1587 let Subjects = SubjectList<[Function], ErrorDiag>;
1590 def NoSplitStack : InheritableAttr {
1591 let Spellings = [GCC<"no_split_stack">];
1592 let Subjects = SubjectList<[Function], ErrorDiag>;
1593 let Documentation = [NoSplitStackDocs];
1596 def NonNull : InheritableParamAttr {
1597 let Spellings = [GCC<"nonnull">];
1598 let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
1599 "functions, methods, and parameters">;
1600 let Args = [VariadicParamIdxArgument<"Args">];
1601 let AdditionalMembers = [{
1602 bool isNonNull(unsigned IdxAST) const {
1605 return args_end() != std::find_if(
1606 args_begin(), args_end(),
1607 [=](const ParamIdx &Idx) { return Idx.getASTIndex() == IdxAST; });
1610 // FIXME: We should merge duplicates into a single nonnull attribute.
1611 let InheritEvenIfAlreadyPresent = 1;
1612 let Documentation = [NonNullDocs];
1615 def ReturnsNonNull : InheritableAttr {
1616 let Spellings = [GCC<"returns_nonnull">];
1617 let Subjects = SubjectList<[ObjCMethod, Function]>;
1618 let Documentation = [ReturnsNonNullDocs];
1621 // pass_object_size(N) indicates that the parameter should have
1622 // __builtin_object_size with Type=N evaluated on the parameter at the callsite.
1623 def PassObjectSize : InheritableParamAttr {
1624 let Spellings = [Clang<"pass_object_size">,
1625 Clang<"pass_dynamic_object_size">];
1626 let Accessors = [Accessor<"isDynamic", [Clang<"pass_dynamic_object_size">]>];
1627 let Args = [IntArgument<"Type">];
1628 let Subjects = SubjectList<[ParmVar]>;
1629 let Documentation = [PassObjectSizeDocs];
1632 // Nullability type attributes.
1633 def TypeNonNull : TypeAttr {
1634 let Spellings = [Keyword<"_Nonnull">];
1635 let Documentation = [TypeNonNullDocs];
1638 def TypeNullable : TypeAttr {
1639 let Spellings = [Keyword<"_Nullable">];
1640 let Documentation = [TypeNullableDocs];
1643 def TypeNullUnspecified : TypeAttr {
1644 let Spellings = [Keyword<"_Null_unspecified">];
1645 let Documentation = [TypeNullUnspecifiedDocs];
1648 // This is a marker used to indicate that an __unsafe_unretained qualifier was
1649 // ignored because ARC is not enabled. The usual representation for this
1650 // qualifier is as an ObjCOwnership attribute with Kind == "none".
1651 def ObjCInertUnsafeUnretained : TypeAttr {
1652 let Spellings = [Keyword<"__unsafe_unretained">];
1653 let Documentation = [Undocumented];
1656 def ObjCKindOf : TypeAttr {
1657 let Spellings = [Keyword<"__kindof">];
1658 let Documentation = [Undocumented];
1661 def NoEscape : Attr {
1662 let Spellings = [Clang<"noescape">];
1663 let Subjects = SubjectList<[ParmVar]>;
1664 let Documentation = [NoEscapeDocs];
1667 def AssumeAligned : InheritableAttr {
1668 let Spellings = [GCC<"assume_aligned">];
1669 let Subjects = SubjectList<[ObjCMethod, Function]>;
1670 let Args = [ExprArgument<"Alignment">, ExprArgument<"Offset", 1>];
1671 let Documentation = [AssumeAlignedDocs];
1674 def AllocAlign : InheritableAttr {
1675 let Spellings = [GCC<"alloc_align">];
1676 let Subjects = SubjectList<[HasFunctionProto]>;
1677 let Args = [ParamIdxArgument<"ParamIndex">];
1678 let Documentation = [AllocAlignDocs];
1681 def NoReturn : InheritableAttr {
1682 let Spellings = [GCC<"noreturn">, Declspec<"noreturn">];
1683 // FIXME: Does GCC allow this on the function instead?
1684 let Documentation = [Undocumented];
1687 def NoInstrumentFunction : InheritableAttr {
1688 let Spellings = [GCC<"no_instrument_function">];
1689 let Subjects = SubjectList<[Function]>;
1690 let Documentation = [Undocumented];
1693 def NotTailCalled : InheritableAttr {
1694 let Spellings = [Clang<"not_tail_called">];
1695 let Subjects = SubjectList<[Function]>;
1696 let Documentation = [NotTailCalledDocs];
1699 def NoStackProtector : InheritableAttr {
1700 let Spellings = [Clang<"no_stack_protector">];
1701 let Subjects = SubjectList<[Function]>;
1702 let Documentation = [NoStackProtectorDocs];
1705 def NoThrow : InheritableAttr {
1706 let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
1707 let Subjects = SubjectList<[FunctionLike]>;
1708 let Documentation = [NoThrowDocs];
1711 def NvWeak : IgnoredAttr {
1712 // No Declspec spelling of this attribute; the CUDA headers use
1713 // __attribute__((nv_weak)) unconditionally. Does not receive an [[]]
1714 // spelling because it is a CUDA attribute.
1715 let Spellings = [GNU<"nv_weak">];
1716 let LangOpts = [CUDA];
1719 def ObjCBridge : InheritableAttr {
1720 let Spellings = [Clang<"objc_bridge">];
1721 let Subjects = SubjectList<[Record, TypedefName], ErrorDiag>;
1722 let Args = [IdentifierArgument<"BridgedType">];
1723 let Documentation = [Undocumented];
1726 def ObjCBridgeMutable : InheritableAttr {
1727 let Spellings = [Clang<"objc_bridge_mutable">];
1728 let Subjects = SubjectList<[Record], ErrorDiag>;
1729 let Args = [IdentifierArgument<"BridgedType">];
1730 let Documentation = [Undocumented];
1733 def ObjCBridgeRelated : InheritableAttr {
1734 let Spellings = [Clang<"objc_bridge_related">];
1735 let Subjects = SubjectList<[Record], ErrorDiag>;
1736 let Args = [IdentifierArgument<"RelatedClass">,
1737 IdentifierArgument<"ClassMethod">,
1738 IdentifierArgument<"InstanceMethod">];
1739 let HasCustomParsing = 1;
1740 let Documentation = [Undocumented];
1743 def NSReturnsRetained : DeclOrTypeAttr {
1744 let Spellings = [Clang<"ns_returns_retained">];
1745 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1746 let Documentation = [RetainBehaviorDocs];
1749 def NSReturnsNotRetained : InheritableAttr {
1750 let Spellings = [Clang<"ns_returns_not_retained">];
1751 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1752 let Documentation = [RetainBehaviorDocs];
1755 def NSReturnsAutoreleased : InheritableAttr {
1756 let Spellings = [Clang<"ns_returns_autoreleased">];
1757 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1758 let Documentation = [RetainBehaviorDocs];
1761 def NSConsumesSelf : InheritableAttr {
1762 let Spellings = [Clang<"ns_consumes_self">];
1763 let Subjects = SubjectList<[ObjCMethod]>;
1764 let Documentation = [RetainBehaviorDocs];
1767 def NSConsumed : InheritableParamAttr {
1768 let Spellings = [Clang<"ns_consumed">];
1769 let Subjects = SubjectList<[ParmVar]>;
1770 let Documentation = [RetainBehaviorDocs];
1773 def ObjCException : InheritableAttr {
1774 let Spellings = [Clang<"objc_exception">];
1775 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1776 let Documentation = [Undocumented];
1779 def ObjCMethodFamily : InheritableAttr {
1780 let Spellings = [Clang<"objc_method_family">];
1781 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1782 let Args = [EnumArgument<"Family", "FamilyKind",
1783 ["none", "alloc", "copy", "init", "mutableCopy", "new"],
1784 ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
1785 "OMF_mutableCopy", "OMF_new"]>];
1786 let Documentation = [ObjCMethodFamilyDocs];
1789 def ObjCNSObject : InheritableAttr {
1790 let Spellings = [Clang<"NSObject">];
1791 let Documentation = [Undocumented];
1794 def ObjCIndependentClass : InheritableAttr {
1795 let Spellings = [Clang<"objc_independent_class">];
1796 let Documentation = [Undocumented];
1799 def ObjCPreciseLifetime : InheritableAttr {
1800 let Spellings = [Clang<"objc_precise_lifetime">];
1801 let Subjects = SubjectList<[Var], ErrorDiag>;
1802 let Documentation = [Undocumented];
1805 def ObjCReturnsInnerPointer : InheritableAttr {
1806 let Spellings = [Clang<"objc_returns_inner_pointer">];
1807 let Subjects = SubjectList<[ObjCMethod, ObjCProperty], ErrorDiag>;
1808 let Documentation = [Undocumented];
1811 def ObjCRequiresSuper : InheritableAttr {
1812 let Spellings = [Clang<"objc_requires_super">];
1813 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1814 let Documentation = [ObjCRequiresSuperDocs];
1817 def ObjCRootClass : InheritableAttr {
1818 let Spellings = [Clang<"objc_root_class">];
1819 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1820 let Documentation = [Undocumented];
1823 def ObjCNonLazyClass : Attr {
1824 let Spellings = [Clang<"objc_nonlazy_class">];
1825 let Subjects = SubjectList<[ObjCInterface, ObjCImpl], ErrorDiag>;
1826 let LangOpts = [ObjC];
1827 let Documentation = [ObjCNonLazyClassDocs];
1830 def ObjCSubclassingRestricted : InheritableAttr {
1831 let Spellings = [Clang<"objc_subclassing_restricted">];
1832 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1833 let Documentation = [ObjCSubclassingRestrictedDocs];
1836 def ObjCExplicitProtocolImpl : InheritableAttr {
1837 let Spellings = [Clang<"objc_protocol_requires_explicit_implementation">];
1838 let Subjects = SubjectList<[ObjCProtocol], ErrorDiag>;
1839 let Documentation = [Undocumented];
1842 def ObjCDesignatedInitializer : Attr {
1843 let Spellings = [Clang<"objc_designated_initializer">];
1844 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1845 let Documentation = [Undocumented];
1848 def ObjCRuntimeName : Attr {
1849 let Spellings = [Clang<"objc_runtime_name">];
1850 let Subjects = SubjectList<[ObjCInterface, ObjCProtocol], ErrorDiag>;
1851 let Args = [StringArgument<"MetadataName">];
1852 let Documentation = [ObjCRuntimeNameDocs];
1855 def ObjCRuntimeVisible : Attr {
1856 let Spellings = [Clang<"objc_runtime_visible">];
1857 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1858 let Documentation = [ObjCRuntimeVisibleDocs];
1861 def ObjCClassStub : Attr {
1862 let Spellings = [Clang<"objc_class_stub">];
1863 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1864 let Documentation = [ObjCClassStubDocs];
1865 let LangOpts = [ObjCNonFragileRuntime];
1868 def ObjCBoxable : Attr {
1869 let Spellings = [Clang<"objc_boxable">];
1870 let Subjects = SubjectList<[Record], ErrorDiag>;
1871 let Documentation = [ObjCBoxableDocs];
1874 def OptimizeNone : InheritableAttr {
1875 let Spellings = [Clang<"optnone">];
1876 let Subjects = SubjectList<[Function, ObjCMethod]>;
1877 let Documentation = [OptnoneDocs];
1880 def Overloadable : Attr {
1881 let Spellings = [Clang<"overloadable">];
1882 let Subjects = SubjectList<[Function], ErrorDiag>;
1883 let Documentation = [OverloadableDocs];
1886 def Override : InheritableAttr {
1887 let Spellings = [Keyword<"override">];
1888 let SemaHandler = 0;
1889 let Documentation = [Undocumented];
1892 def Ownership : InheritableAttr {
1893 let Spellings = [Clang<"ownership_holds">, Clang<"ownership_returns">,
1894 Clang<"ownership_takes">];
1895 let Accessors = [Accessor<"isHolds", [Clang<"ownership_holds">]>,
1896 Accessor<"isReturns", [Clang<"ownership_returns">]>,
1897 Accessor<"isTakes", [Clang<"ownership_takes">]>];
1898 let AdditionalMembers = [{
1899 enum OwnershipKind { Holds, Returns, Takes };
1900 OwnershipKind getOwnKind() const {
1901 return isHolds() ? Holds :
1906 let Args = [IdentifierArgument<"Module">,
1907 VariadicParamIdxArgument<"Args">];
1908 let Subjects = SubjectList<[HasFunctionProto]>;
1909 let Documentation = [Undocumented];
1912 def Packed : InheritableAttr {
1913 let Spellings = [GCC<"packed">];
1914 // let Subjects = [Tag, Field];
1915 let Documentation = [Undocumented];
1918 def IntelOclBicc : DeclOrTypeAttr {
1919 let Spellings = [Clang<"intel_ocl_bicc", 0>];
1920 // let Subjects = [Function, ObjCMethod];
1921 let Documentation = [Undocumented];
1924 def Pcs : DeclOrTypeAttr {
1925 let Spellings = [GCC<"pcs">];
1926 let Args = [EnumArgument<"PCS", "PCSType",
1927 ["aapcs", "aapcs-vfp"],
1928 ["AAPCS", "AAPCS_VFP"]>];
1929 // let Subjects = [Function, ObjCMethod];
1930 let Documentation = [PcsDocs];
1933 def AArch64VectorPcs: DeclOrTypeAttr {
1934 let Spellings = [Clang<"aarch64_vector_pcs">];
1935 let Documentation = [AArch64VectorPcsDocs];
1938 def Pure : InheritableAttr {
1939 let Spellings = [GCC<"pure">];
1940 let Documentation = [Undocumented];
1943 def Regparm : TypeAttr {
1944 let Spellings = [GCC<"regparm">];
1945 let Args = [UnsignedArgument<"NumParams">];
1946 let Documentation = [RegparmDocs];
1947 // Represented as part of the enclosing function type.
1951 def NoDeref : TypeAttr {
1952 let Spellings = [Clang<"noderef">];
1953 let Documentation = [NoDerefDocs];
1956 def ReqdWorkGroupSize : InheritableAttr {
1957 // Does not have a [[]] spelling because it is an OpenCL-related attribute.
1958 let Spellings = [GNU<"reqd_work_group_size">];
1959 let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
1960 UnsignedArgument<"ZDim">];
1961 let Subjects = SubjectList<[Function], ErrorDiag>;
1962 let Documentation = [Undocumented];
1965 def WorkGroupSizeHint : InheritableAttr {
1966 // Does not have a [[]] spelling because it is an OpenCL-related attribute.
1967 let Spellings = [GNU<"work_group_size_hint">];
1968 let Args = [UnsignedArgument<"XDim">,
1969 UnsignedArgument<"YDim">,
1970 UnsignedArgument<"ZDim">];
1971 let Subjects = SubjectList<[Function], ErrorDiag>;
1972 let Documentation = [Undocumented];
1975 def InitPriority : InheritableAttr {
1976 let Spellings = [GCC<"init_priority">];
1977 let Args = [UnsignedArgument<"Priority">];
1978 let Subjects = SubjectList<[Var], ErrorDiag>;
1979 let Documentation = [Undocumented];
1982 def Section : InheritableAttr {
1983 let Spellings = [GCC<"section">, Declspec<"allocate">];
1984 let Args = [StringArgument<"Name">];
1986 SubjectList<[ Function, GlobalVar, ObjCMethod, ObjCProperty ], ErrorDiag>;
1987 let Documentation = [SectionDocs];
1990 // This is used for `__declspec(code_seg("segname"))`, but not for
1991 // `#pragma code_seg("segname")`.
1992 def CodeSeg : InheritableAttr {
1993 let Spellings = [Declspec<"code_seg">];
1994 let Args = [StringArgument<"Name">];
1995 let Subjects = SubjectList<[Function, CXXRecord], ErrorDiag>;
1996 let Documentation = [CodeSegDocs];
1999 def PragmaClangBSSSection : InheritableAttr {
2000 // This attribute has no spellings as it is only ever created implicitly.
2002 let Args = [StringArgument<"Name">];
2003 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2004 let Documentation = [Undocumented];
2007 def PragmaClangDataSection : InheritableAttr {
2008 // This attribute has no spellings as it is only ever created implicitly.
2010 let Args = [StringArgument<"Name">];
2011 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2012 let Documentation = [Undocumented];
2015 def PragmaClangRodataSection : InheritableAttr {
2016 // This attribute has no spellings as it is only ever created implicitly.
2018 let Args = [StringArgument<"Name">];
2019 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2020 let Documentation = [Undocumented];
2023 def PragmaClangRelroSection : InheritableAttr {
2024 // This attribute has no spellings as it is only ever created implicitly.
2026 let Args = [StringArgument<"Name">];
2027 let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2028 let Documentation = [Undocumented];
2031 def PragmaClangTextSection : InheritableAttr {
2032 // This attribute has no spellings as it is only ever created implicitly.
2034 let Args = [StringArgument<"Name">];
2035 let Subjects = SubjectList<[Function], ErrorDiag>;
2036 let Documentation = [Undocumented];
2039 def Sentinel : InheritableAttr {
2040 let Spellings = [GCC<"sentinel">];
2041 let Args = [DefaultIntArgument<"Sentinel", 0>,
2042 DefaultIntArgument<"NullPos", 0>];
2043 // let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>;
2044 let Documentation = [Undocumented];
2047 def StdCall : DeclOrTypeAttr {
2048 let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
2049 // let Subjects = [Function, ObjCMethod];
2050 let Documentation = [StdCallDocs];
2053 def SwiftCall : DeclOrTypeAttr {
2054 let Spellings = [Clang<"swiftcall">];
2055 // let Subjects = SubjectList<[Function]>;
2056 let Documentation = [SwiftCallDocs];
2059 def SwiftContext : ParameterABIAttr {
2060 let Spellings = [Clang<"swift_context">];
2061 let Documentation = [SwiftContextDocs];
2064 def SwiftErrorResult : ParameterABIAttr {
2065 let Spellings = [Clang<"swift_error_result">];
2066 let Documentation = [SwiftErrorResultDocs];
2069 def SwiftIndirectResult : ParameterABIAttr {
2070 let Spellings = [Clang<"swift_indirect_result">];
2071 let Documentation = [SwiftIndirectResultDocs];
2074 def Suppress : StmtAttr {
2075 let Spellings = [CXX11<"gsl", "suppress">];
2076 let Args = [VariadicStringArgument<"DiagnosticIdentifiers">];
2077 let Documentation = [SuppressDocs];
2080 def SysVABI : DeclOrTypeAttr {
2081 let Spellings = [GCC<"sysv_abi">];
2082 // let Subjects = [Function, ObjCMethod];
2083 let Documentation = [Undocumented];
2086 def ThisCall : DeclOrTypeAttr {
2087 let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
2088 Keyword<"_thiscall">];
2089 // let Subjects = [Function, ObjCMethod];
2090 let Documentation = [ThisCallDocs];
2093 def VectorCall : DeclOrTypeAttr {
2094 let Spellings = [Clang<"vectorcall">, Keyword<"__vectorcall">,
2095 Keyword<"_vectorcall">];
2096 // let Subjects = [Function, ObjCMethod];
2097 let Documentation = [VectorCallDocs];
2100 def Pascal : DeclOrTypeAttr {
2101 let Spellings = [Clang<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
2102 // let Subjects = [Function, ObjCMethod];
2103 let Documentation = [Undocumented];
2106 def PreserveMost : DeclOrTypeAttr {
2107 let Spellings = [Clang<"preserve_most">];
2108 let Documentation = [PreserveMostDocs];
2111 def PreserveAll : DeclOrTypeAttr {
2112 let Spellings = [Clang<"preserve_all">];
2113 let Documentation = [PreserveAllDocs];
2116 def Target : InheritableAttr {
2117 let Spellings = [GCC<"target">];
2118 let Args = [StringArgument<"featuresStr">];
2119 let Subjects = SubjectList<[Function], ErrorDiag>;
2120 let Documentation = [TargetDocs];
2121 let AdditionalMembers = [{
2122 struct ParsedTargetAttr {
2123 std::vector<std::string> Features;
2124 StringRef Architecture;
2125 bool DuplicateArchitecture = false;
2126 bool operator ==(const ParsedTargetAttr &Other) const {
2127 return DuplicateArchitecture == Other.DuplicateArchitecture &&
2128 Architecture == Other.Architecture && Features == Other.Features;
2131 ParsedTargetAttr parse() const {
2132 return parse(getFeaturesStr());
2135 StringRef getArchitecture() const {
2136 StringRef Features = getFeaturesStr();
2137 if (Features == "default") return {};
2139 SmallVector<StringRef, 1> AttrFeatures;
2140 Features.split(AttrFeatures, ",");
2142 for (auto &Feature : AttrFeatures) {
2143 Feature = Feature.trim();
2144 if (Feature.startswith("arch="))
2145 return Feature.drop_front(sizeof("arch=") - 1);
2150 // Gets the list of features as simple string-refs with no +/- or 'no-'.
2151 // Only adds the items to 'Out' that are additions.
2152 void getAddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
2153 StringRef Features = getFeaturesStr();
2154 if (Features == "default") return;
2156 SmallVector<StringRef, 1> AttrFeatures;
2157 Features.split(AttrFeatures, ",");
2159 for (auto &Feature : AttrFeatures) {
2160 Feature = Feature.trim();
2162 if (!Feature.startswith("no-") && !Feature.startswith("arch=") &&
2163 !Feature.startswith("fpmath=") && !Feature.startswith("tune="))
2164 Out.push_back(Feature);
2168 template<class Compare>
2169 ParsedTargetAttr parse(Compare cmp) const {
2170 ParsedTargetAttr Attrs = parse();
2171 llvm::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp);
2175 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
2177 static ParsedTargetAttr parse(StringRef Features) {
2178 ParsedTargetAttr Ret;
2179 if (Features == "default") return Ret;
2180 SmallVector<StringRef, 1> AttrFeatures;
2181 Features.split(AttrFeatures, ",");
2183 // Grab the various features and prepend a "+" to turn on the feature to
2184 // the backend and add them to our existing set of features.
2185 for (auto &Feature : AttrFeatures) {
2186 // Go ahead and trim whitespace rather than either erroring or
2187 // accepting it weirdly.
2188 Feature = Feature.trim();
2190 // We don't support cpu tuning this way currently.
2191 // TODO: Support the fpmath option. It will require checking
2192 // overall feature validity for the function with the rest of the
2193 // attributes on the function.
2194 if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
2197 // While we're here iterating check for a different target cpu.
2198 if (Feature.startswith("arch=")) {
2199 if (!Ret.Architecture.empty())
2200 Ret.DuplicateArchitecture = true;
2202 Ret.Architecture = Feature.split("=").second.trim();
2203 } else if (Feature.startswith("no-"))
2204 Ret.Features.push_back("-" + Feature.split("-").second.str());
2206 Ret.Features.push_back("+" + Feature.str());
2213 def MinVectorWidth : InheritableAttr {
2214 let Spellings = [Clang<"min_vector_width">];
2215 let Args = [UnsignedArgument<"VectorWidth">];
2216 let Subjects = SubjectList<[Function], ErrorDiag>;
2217 let Documentation = [MinVectorWidthDocs];
2220 def TransparentUnion : InheritableAttr {
2221 let Spellings = [GCC<"transparent_union">];
2222 // let Subjects = SubjectList<[Record, TypedefName]>;
2223 let Documentation = [TransparentUnionDocs];
2224 let LangOpts = [COnly];
2227 def Unavailable : InheritableAttr {
2228 let Spellings = [Clang<"unavailable">];
2229 let Args = [StringArgument<"Message", 1>,
2230 EnumArgument<"ImplicitReason", "ImplicitReason",
2233 "IR_ARCForbiddenType",
2235 "IR_ARCForbiddenConversion",
2236 "IR_ARCInitReturnsUnrelated",
2237 "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
2238 let Documentation = [Undocumented];
2241 def DiagnoseIf : InheritableAttr {
2242 // Does not have a [[]] spelling because this attribute requires the ability
2243 // to parse function arguments but the attribute is not written in the type
2245 let Spellings = [GNU<"diagnose_if">];
2246 let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
2247 let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
2248 EnumArgument<"DiagnosticType",
2250 ["error", "warning"],
2251 ["DT_Error", "DT_Warning"]>,
2252 BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
2253 NamedArgument<"Parent", 0, /*fake*/ 1>];
2254 let InheritEvenIfAlreadyPresent = 1;
2256 let AdditionalMembers = [{
2257 bool isError() const { return diagnosticType == DT_Error; }
2258 bool isWarning() const { return diagnosticType == DT_Warning; }
2260 let TemplateDependent = 1;
2261 let Documentation = [DiagnoseIfDocs];
2264 def ArcWeakrefUnavailable : InheritableAttr {
2265 let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
2266 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2267 let Documentation = [Undocumented];
2270 def ObjCGC : TypeAttr {
2271 let Spellings = [Clang<"objc_gc">];
2272 let Args = [IdentifierArgument<"Kind">];
2273 let Documentation = [Undocumented];
2276 def ObjCOwnership : DeclOrTypeAttr {
2277 let Spellings = [Clang<"objc_ownership">];
2278 let Args = [IdentifierArgument<"Kind">];
2279 let Documentation = [Undocumented];
2282 def ObjCRequiresPropertyDefs : InheritableAttr {
2283 let Spellings = [Clang<"objc_requires_property_definitions">];
2284 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2285 let Documentation = [Undocumented];
2288 def Unused : InheritableAttr {
2289 let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">,
2290 C2x<"", "maybe_unused">];
2291 let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
2292 Field, ObjCMethod, FunctionLike]>;
2293 let Documentation = [WarnMaybeUnusedDocs];
2296 def Used : InheritableAttr {
2297 let Spellings = [GCC<"used">];
2298 let Subjects = SubjectList<[NonLocalVar, Function, ObjCMethod]>;
2299 let Documentation = [Undocumented];
2302 def Uuid : InheritableAttr {
2303 let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
2304 let Args = [StringArgument<"Guid">];
2305 let Subjects = SubjectList<[Record, Enum]>;
2306 // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
2307 // CPlusPlus && (MicrosoftExt || Borland)
2308 let LangOpts = [MicrosoftExt, Borland];
2309 let Documentation = [Undocumented];
2312 def VectorSize : TypeAttr {
2313 let Spellings = [GCC<"vector_size">];
2314 let Args = [ExprArgument<"NumBytes">];
2315 let Documentation = [Undocumented];
2316 // Represented as VectorType instead.
2320 def VecTypeHint : InheritableAttr {
2321 // Does not have a [[]] spelling because it is an OpenCL-related attribute.
2322 let Spellings = [GNU<"vec_type_hint">];
2323 let Args = [TypeArgument<"TypeHint">];
2324 let Subjects = SubjectList<[Function], ErrorDiag>;
2325 let Documentation = [Undocumented];
2328 def Visibility : InheritableAttr {
2330 let Spellings = [GCC<"visibility">];
2331 let Args = [EnumArgument<"Visibility", "VisibilityType",
2332 ["default", "hidden", "internal", "protected"],
2333 ["Default", "Hidden", "Hidden", "Protected"]>];
2334 let MeaningfulToClassTemplateDefinition = 1;
2335 let Documentation = [Undocumented];
2338 def TypeVisibility : InheritableAttr {
2340 let Spellings = [Clang<"type_visibility">];
2341 let Args = [EnumArgument<"Visibility", "VisibilityType",
2342 ["default", "hidden", "internal", "protected"],
2343 ["Default", "Hidden", "Hidden", "Protected"]>];
2344 // let Subjects = [Tag, ObjCInterface, Namespace];
2345 let Documentation = [Undocumented];
2348 def VecReturn : InheritableAttr {
2349 // This attribute does not have a C [[]] spelling because it only appertains
2350 // to C++ struct/class/union.
2351 // FIXME: should this attribute have a CPlusPlus language option?
2352 let Spellings = [Clang<"vecreturn", 0>];
2353 let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
2354 let Documentation = [Undocumented];
2357 def WarnUnused : InheritableAttr {
2358 let Spellings = [GCC<"warn_unused">];
2359 let Subjects = SubjectList<[Record]>;
2360 let Documentation = [Undocumented];
2363 def WarnUnusedResult : InheritableAttr {
2364 let Spellings = [CXX11<"", "nodiscard", 201907>, C2x<"", "nodiscard">,
2365 CXX11<"clang", "warn_unused_result">,
2366 GCC<"warn_unused_result">];
2367 let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike]>;
2368 let Args = [StringArgument<"Message", 1>];
2369 let Documentation = [WarnUnusedResultsDocs];
2370 let AdditionalMembers = [{
2371 // Check whether this the C++11 nodiscard version, even in non C++11
2373 bool IsCXX11NoDiscard() const {
2374 return this->getSemanticSpelling() == CXX11_nodiscard;
2379 def Weak : InheritableAttr {
2380 let Spellings = [GCC<"weak">];
2381 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
2382 let Documentation = [Undocumented];
2385 def WeakImport : InheritableAttr {
2386 let Spellings = [Clang<"weak_import">];
2387 let Documentation = [Undocumented];
2390 def WeakRef : InheritableAttr {
2391 let Spellings = [GCC<"weakref">];
2392 // A WeakRef that has an argument is treated as being an AliasAttr
2393 let Args = [StringArgument<"Aliasee", 1>];
2394 let Subjects = SubjectList<[Var, Function], ErrorDiag>;
2395 let Documentation = [Undocumented];
2398 def LTOVisibilityPublic : InheritableAttr {
2399 let Spellings = [Clang<"lto_visibility_public">];
2400 let Subjects = SubjectList<[Record]>;
2401 let Documentation = [LTOVisibilityDocs];
2404 def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
2405 // NOTE: If you add any additional spellings, ARMInterrupt's,
2406 // MSP430Interrupt's and MipsInterrupt's spellings must match.
2407 let Spellings = [GCC<"interrupt">];
2408 let Subjects = SubjectList<[HasFunctionProto]>;
2409 let ParseKind = "Interrupt";
2410 let HasCustomParsing = 1;
2411 let Documentation = [Undocumented];
2414 def AnyX86NoCallerSavedRegisters : InheritableAttr,
2415 TargetSpecificAttr<TargetAnyX86> {
2416 let Spellings = [GCC<"no_caller_saved_registers">];
2417 let Documentation = [AnyX86NoCallerSavedRegistersDocs];
2420 def AnyX86NoCfCheck : DeclOrTypeAttr, TargetSpecificAttr<TargetAnyX86>{
2421 let Spellings = [GCC<"nocf_check">];
2422 let Subjects = SubjectList<[FunctionLike]>;
2423 let Documentation = [AnyX86NoCfCheckDocs];
2426 def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
2427 let Spellings = [GCC<"force_align_arg_pointer">];
2428 // Technically, this appertains to a FunctionDecl, but the target-specific
2429 // code silently allows anything function-like (such as typedefs or function
2430 // pointers), but does not apply the attribute to them.
2431 let Documentation = [X86ForceAlignArgPointerDocs];
2434 def NoSanitize : InheritableAttr {
2435 let Spellings = [Clang<"no_sanitize">];
2436 let Args = [VariadicStringArgument<"Sanitizers">];
2437 let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag>;
2438 let Documentation = [NoSanitizeDocs];
2439 let AdditionalMembers = [{
2440 SanitizerMask getMask() const {
2442 for (auto SanitizerName : sanitizers()) {
2443 SanitizerMask ParsedMask =
2444 parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
2445 Mask |= expandSanitizerGroups(ParsedMask);
2452 // Attributes to disable a specific sanitizer. No new sanitizers should be added
2453 // to this list; the no_sanitize attribute should be extended instead.
2454 def NoSanitizeSpecific : InheritableAttr {
2455 let Spellings = [GCC<"no_address_safety_analysis">,
2456 GCC<"no_sanitize_address">,
2457 GCC<"no_sanitize_thread">,
2458 Clang<"no_sanitize_memory">];
2459 let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;
2460 let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
2461 NoSanitizeMemoryDocs];
2465 def CFICanonicalJumpTable : InheritableAttr {
2466 let Spellings = [Clang<"cfi_canonical_jump_table">];
2467 let Subjects = SubjectList<[Function], ErrorDiag>;
2468 let Documentation = [CFICanonicalJumpTableDocs];
2471 // C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
2472 // Not all of these attributes will be given a [[]] spelling. The attributes
2473 // which require access to function parameter names cannot use the [[]] spelling
2474 // because they are not written in the type position. Some attributes are given
2475 // an updated captability-based name and the older name will only be supported
2476 // under the GNU-style spelling.
2477 def GuardedVar : InheritableAttr {
2478 let Spellings = [Clang<"guarded_var", 0>];
2479 let Subjects = SubjectList<[Field, SharedVar]>;
2480 let Documentation = [Undocumented];
2483 def PtGuardedVar : InheritableAttr {
2484 let Spellings = [Clang<"pt_guarded_var", 0>];
2485 let Subjects = SubjectList<[Field, SharedVar]>;
2486 let Documentation = [Undocumented];
2489 def Lockable : InheritableAttr {
2490 let Spellings = [GNU<"lockable">];
2491 let Subjects = SubjectList<[Record]>;
2492 let Documentation = [Undocumented];
2493 let ASTNode = 0; // Replaced by Capability
2496 def ScopedLockable : InheritableAttr {
2497 let Spellings = [Clang<"scoped_lockable", 0>];
2498 let Subjects = SubjectList<[Record]>;
2499 let Documentation = [Undocumented];
2502 def Capability : InheritableAttr {
2503 let Spellings = [Clang<"capability", 0>, Clang<"shared_capability", 0>];
2504 let Subjects = SubjectList<[Record, TypedefName], ErrorDiag>;
2505 let Args = [StringArgument<"Name">];
2506 let Accessors = [Accessor<"isShared",
2507 [Clang<"shared_capability", 0>]>];
2508 let Documentation = [Undocumented];
2509 let AdditionalMembers = [{
2510 bool isMutex() const { return getName().equals_lower("mutex"); }
2511 bool isRole() const { return getName().equals_lower("role"); }
2515 def AssertCapability : InheritableAttr {
2516 let Spellings = [Clang<"assert_capability", 0>,
2517 Clang<"assert_shared_capability", 0>];
2518 let Subjects = SubjectList<[Function]>;
2520 let TemplateDependent = 1;
2521 let ParseArgumentsAsUnevaluated = 1;
2522 let InheritEvenIfAlreadyPresent = 1;
2523 let Args = [VariadicExprArgument<"Args">];
2524 let Accessors = [Accessor<"isShared",
2525 [Clang<"assert_shared_capability", 0>]>];
2526 let Documentation = [AssertCapabilityDocs];
2529 def AcquireCapability : InheritableAttr {
2530 let Spellings = [Clang<"acquire_capability", 0>,
2531 Clang<"acquire_shared_capability", 0>,
2532 GNU<"exclusive_lock_function">,
2533 GNU<"shared_lock_function">];
2534 let Subjects = SubjectList<[Function]>;
2536 let TemplateDependent = 1;
2537 let ParseArgumentsAsUnevaluated = 1;
2538 let InheritEvenIfAlreadyPresent = 1;
2539 let Args = [VariadicExprArgument<"Args">];
2540 let Accessors = [Accessor<"isShared",
2541 [Clang<"acquire_shared_capability", 0>,
2542 GNU<"shared_lock_function">]>];
2543 let Documentation = [AcquireCapabilityDocs];
2546 def TryAcquireCapability : InheritableAttr {
2547 let Spellings = [Clang<"try_acquire_capability", 0>,
2548 Clang<"try_acquire_shared_capability", 0>];
2549 let Subjects = SubjectList<[Function],
2552 let TemplateDependent = 1;
2553 let ParseArgumentsAsUnevaluated = 1;
2554 let InheritEvenIfAlreadyPresent = 1;
2555 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2556 let Accessors = [Accessor<"isShared",
2557 [Clang<"try_acquire_shared_capability", 0>]>];
2558 let Documentation = [TryAcquireCapabilityDocs];
2561 def ReleaseCapability : InheritableAttr {
2562 let Spellings = [Clang<"release_capability", 0>,
2563 Clang<"release_shared_capability", 0>,
2564 Clang<"release_generic_capability", 0>,
2565 Clang<"unlock_function", 0>];
2566 let Subjects = SubjectList<[Function]>;
2568 let TemplateDependent = 1;
2569 let ParseArgumentsAsUnevaluated = 1;
2570 let InheritEvenIfAlreadyPresent = 1;
2571 let Args = [VariadicExprArgument<"Args">];
2572 let Accessors = [Accessor<"isShared",
2573 [Clang<"release_shared_capability", 0>]>,
2574 Accessor<"isGeneric",
2575 [Clang<"release_generic_capability", 0>,
2576 Clang<"unlock_function", 0>]>];
2577 let Documentation = [ReleaseCapabilityDocs];
2580 def RequiresCapability : InheritableAttr {
2581 let Spellings = [Clang<"requires_capability", 0>,
2582 Clang<"exclusive_locks_required", 0>,
2583 Clang<"requires_shared_capability", 0>,
2584 Clang<"shared_locks_required", 0>];
2585 let Args = [VariadicExprArgument<"Args">];
2587 let TemplateDependent = 1;
2588 let ParseArgumentsAsUnevaluated = 1;
2589 let InheritEvenIfAlreadyPresent = 1;
2590 let Subjects = SubjectList<[Function]>;
2591 let Accessors = [Accessor<"isShared", [Clang<"requires_shared_capability", 0>,
2592 Clang<"shared_locks_required", 0>]>];
2593 let Documentation = [Undocumented];
2596 def NoThreadSafetyAnalysis : InheritableAttr {
2597 let Spellings = [Clang<"no_thread_safety_analysis">];
2598 let Subjects = SubjectList<[Function]>;
2599 let Documentation = [Undocumented];
2602 def GuardedBy : InheritableAttr {
2603 let Spellings = [GNU<"guarded_by">];
2604 let Args = [ExprArgument<"Arg">];
2606 let TemplateDependent = 1;
2607 let ParseArgumentsAsUnevaluated = 1;
2608 let InheritEvenIfAlreadyPresent = 1;
2609 let Subjects = SubjectList<[Field, SharedVar]>;
2610 let Documentation = [Undocumented];
2613 def PtGuardedBy : InheritableAttr {
2614 let Spellings = [GNU<"pt_guarded_by">];
2615 let Args = [ExprArgument<"Arg">];
2617 let TemplateDependent = 1;
2618 let ParseArgumentsAsUnevaluated = 1;
2619 let InheritEvenIfAlreadyPresent = 1;
2620 let Subjects = SubjectList<[Field, SharedVar]>;
2621 let Documentation = [Undocumented];
2624 def AcquiredAfter : InheritableAttr {
2625 let Spellings = [GNU<"acquired_after">];
2626 let Args = [VariadicExprArgument<"Args">];
2628 let TemplateDependent = 1;
2629 let ParseArgumentsAsUnevaluated = 1;
2630 let InheritEvenIfAlreadyPresent = 1;
2631 let Subjects = SubjectList<[Field, SharedVar]>;
2632 let Documentation = [Undocumented];
2635 def AcquiredBefore : InheritableAttr {
2636 let Spellings = [GNU<"acquired_before">];
2637 let Args = [VariadicExprArgument<"Args">];
2639 let TemplateDependent = 1;
2640 let ParseArgumentsAsUnevaluated = 1;
2641 let InheritEvenIfAlreadyPresent = 1;
2642 let Subjects = SubjectList<[Field, SharedVar]>;
2643 let Documentation = [Undocumented];
2646 def AssertExclusiveLock : InheritableAttr {
2647 let Spellings = [GNU<"assert_exclusive_lock">];
2648 let Args = [VariadicExprArgument<"Args">];
2650 let TemplateDependent = 1;
2651 let ParseArgumentsAsUnevaluated = 1;
2652 let InheritEvenIfAlreadyPresent = 1;
2653 let Subjects = SubjectList<[Function]>;
2654 let Documentation = [Undocumented];
2657 def AssertSharedLock : InheritableAttr {
2658 let Spellings = [GNU<"assert_shared_lock">];
2659 let Args = [VariadicExprArgument<"Args">];
2661 let TemplateDependent = 1;
2662 let ParseArgumentsAsUnevaluated = 1;
2663 let InheritEvenIfAlreadyPresent = 1;
2664 let Subjects = SubjectList<[Function]>;
2665 let Documentation = [Undocumented];
2668 // The first argument is an integer or boolean value specifying the return value
2669 // of a successful lock acquisition.
2670 def ExclusiveTrylockFunction : InheritableAttr {
2671 let Spellings = [GNU<"exclusive_trylock_function">];
2672 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2674 let TemplateDependent = 1;
2675 let ParseArgumentsAsUnevaluated = 1;
2676 let InheritEvenIfAlreadyPresent = 1;
2677 let Subjects = SubjectList<[Function]>;
2678 let Documentation = [Undocumented];
2681 // The first argument is an integer or boolean value specifying the return value
2682 // of a successful lock acquisition.
2683 def SharedTrylockFunction : InheritableAttr {
2684 let Spellings = [GNU<"shared_trylock_function">];
2685 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2687 let TemplateDependent = 1;
2688 let ParseArgumentsAsUnevaluated = 1;
2689 let InheritEvenIfAlreadyPresent = 1;
2690 let Subjects = SubjectList<[Function]>;
2691 let Documentation = [Undocumented];
2694 def LockReturned : InheritableAttr {
2695 let Spellings = [GNU<"lock_returned">];
2696 let Args = [ExprArgument<"Arg">];
2698 let TemplateDependent = 1;
2699 let ParseArgumentsAsUnevaluated = 1;
2700 let Subjects = SubjectList<[Function]>;
2701 let Documentation = [Undocumented];
2704 def LocksExcluded : InheritableAttr {
2705 let Spellings = [GNU<"locks_excluded">];
2706 let Args = [VariadicExprArgument<"Args">];
2708 let TemplateDependent = 1;
2709 let ParseArgumentsAsUnevaluated = 1;
2710 let InheritEvenIfAlreadyPresent = 1;
2711 let Subjects = SubjectList<[Function]>;
2712 let Documentation = [Undocumented];
2715 // C/C++ consumed attributes.
2717 def Consumable : InheritableAttr {
2718 // This attribute does not have a C [[]] spelling because it only appertains
2719 // to C++ struct/class/union.
2720 // FIXME: should this attribute have a CPlusPlus language option?
2721 let Spellings = [Clang<"consumable", 0>];
2722 let Subjects = SubjectList<[CXXRecord]>;
2723 let Args = [EnumArgument<"DefaultState", "ConsumedState",
2724 ["unknown", "consumed", "unconsumed"],
2725 ["Unknown", "Consumed", "Unconsumed"]>];
2726 let Documentation = [ConsumableDocs];
2729 def ConsumableAutoCast : InheritableAttr {
2730 // This attribute does not have a C [[]] spelling because it only appertains
2731 // to C++ struct/class/union.
2732 // FIXME: should this attribute have a CPlusPlus language option?
2733 let Spellings = [Clang<"consumable_auto_cast_state", 0>];
2734 let Subjects = SubjectList<[CXXRecord]>;
2735 let Documentation = [Undocumented];
2738 def ConsumableSetOnRead : InheritableAttr {
2739 // This attribute does not have a C [[]] spelling because it only appertains
2740 // to C++ struct/class/union.
2741 // FIXME: should this attribute have a CPlusPlus language option?
2742 let Spellings = [Clang<"consumable_set_state_on_read", 0>];
2743 let Subjects = SubjectList<[CXXRecord]>;
2744 let Documentation = [Undocumented];
2747 def CallableWhen : InheritableAttr {
2748 // This attribute does not have a C [[]] spelling because it only appertains
2749 // to C++ function (but doesn't require it to be a member function).
2750 // FIXME: should this attribute have a CPlusPlus language option?
2751 let Spellings = [Clang<"callable_when", 0>];
2752 let Subjects = SubjectList<[CXXMethod]>;
2753 let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
2754 ["unknown", "consumed", "unconsumed"],
2755 ["Unknown", "Consumed", "Unconsumed"]>];
2756 let Documentation = [CallableWhenDocs];
2759 def ParamTypestate : InheritableAttr {
2760 // This attribute does not have a C [[]] spelling because it only appertains
2761 // to a parameter whose type is a consumable C++ class.
2762 // FIXME: should this attribute have a CPlusPlus language option?
2763 let Spellings = [Clang<"param_typestate", 0>];
2764 let Subjects = SubjectList<[ParmVar]>;
2765 let Args = [EnumArgument<"ParamState", "ConsumedState",
2766 ["unknown", "consumed", "unconsumed"],
2767 ["Unknown", "Consumed", "Unconsumed"]>];
2768 let Documentation = [ParamTypestateDocs];
2771 def ReturnTypestate : InheritableAttr {
2772 // This attribute does not have a C [[]] spelling because it only appertains
2773 // to a parameter or function return type that is a consumable C++ class.
2774 // FIXME: should this attribute have a CPlusPlus language option?
2775 let Spellings = [Clang<"return_typestate", 0>];
2776 let Subjects = SubjectList<[Function, ParmVar]>;
2777 let Args = [EnumArgument<"State", "ConsumedState",
2778 ["unknown", "consumed", "unconsumed"],
2779 ["Unknown", "Consumed", "Unconsumed"]>];
2780 let Documentation = [ReturnTypestateDocs];
2783 def SetTypestate : InheritableAttr {
2784 // This attribute does not have a C [[]] spelling because it only appertains
2785 // to C++ function (but doesn't require it to be a member function).
2786 // FIXME: should this attribute have a CPlusPlus language option?
2787 let Spellings = [Clang<"set_typestate", 0>];
2788 let Subjects = SubjectList<[CXXMethod]>;
2789 let Args = [EnumArgument<"NewState", "ConsumedState",
2790 ["unknown", "consumed", "unconsumed"],
2791 ["Unknown", "Consumed", "Unconsumed"]>];
2792 let Documentation = [SetTypestateDocs];
2795 def TestTypestate : InheritableAttr {
2796 // This attribute does not have a C [[]] spelling because it only appertains
2797 // to C++ function (but doesn't require it to be a member function).
2798 // FIXME: should this attribute have a CPlusPlus language option?
2799 let Spellings = [Clang<"test_typestate", 0>];
2800 let Subjects = SubjectList<[CXXMethod]>;
2801 let Args = [EnumArgument<"TestState", "ConsumedState",
2802 ["consumed", "unconsumed"],
2803 ["Consumed", "Unconsumed"]>];
2804 let Documentation = [TestTypestateDocs];
2807 // Type safety attributes for `void *' pointers and type tags.
2809 def ArgumentWithTypeTag : InheritableAttr {
2810 let Spellings = [Clang<"argument_with_type_tag">,
2811 Clang<"pointer_with_type_tag">];
2812 let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>;
2813 let Args = [IdentifierArgument<"ArgumentKind">,
2814 ParamIdxArgument<"ArgumentIdx">,
2815 ParamIdxArgument<"TypeTagIdx">,
2816 BoolArgument<"IsPointer", /*opt*/0, /*fake*/1>];
2817 let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
2820 def TypeTagForDatatype : InheritableAttr {
2821 let Spellings = [Clang<"type_tag_for_datatype">];
2822 let Args = [IdentifierArgument<"ArgumentKind">,
2823 TypeArgument<"MatchingCType">,
2824 BoolArgument<"LayoutCompatible">,
2825 BoolArgument<"MustBeNull">];
2826 // let Subjects = SubjectList<[Var], ErrorDiag>;
2827 let HasCustomParsing = 1;
2828 let Documentation = [TypeTagForDatatypeDocs];
2831 def Owner : InheritableAttr {
2832 let Spellings = [CXX11<"gsl", "Owner">];
2833 let Subjects = SubjectList<[Struct]>;
2834 let Args = [TypeArgument<"DerefType", /*opt=*/1>];
2835 let Documentation = [LifetimeOwnerDocs];
2838 def Pointer : InheritableAttr {
2839 let Spellings = [CXX11<"gsl", "Pointer">];
2840 let Subjects = SubjectList<[Struct]>;
2841 let Args = [TypeArgument<"DerefType", /*opt=*/1>];
2842 let Documentation = [LifetimePointerDocs];
2845 // Microsoft-related attributes
2847 def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
2848 let Spellings = [Declspec<"novtable">];
2849 let Subjects = SubjectList<[CXXRecord]>;
2850 let Documentation = [MSNoVTableDocs];
2854 let Spellings = [Declspec<"property">];
2857 def MSAllocator : InheritableAttr {
2858 let Spellings = [Declspec<"allocator">];
2859 let Subjects = SubjectList<[Function]>;
2860 let Documentation = [MSAllocatorDocs];
2863 def MSStruct : InheritableAttr {
2864 let Spellings = [GCC<"ms_struct">];
2865 let Subjects = SubjectList<[Record]>;
2866 let Documentation = [Undocumented];
2869 def DLLExport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2870 let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
2871 let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2872 let Documentation = [DLLExportDocs];
2875 def DLLExportStaticLocal : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2876 // This attribute is used internally only when -fno-dllexport-inlines is
2877 // passed. This attribute is added to inline function of class having
2878 // dllexport attribute. And if the function has static local variables, this
2879 // attribute is used to whether the variables are exported or not. Also if
2880 // function has local static variables, the function is dllexported too.
2882 let Subjects = SubjectList<[Function]>;
2883 let Documentation = [Undocumented];
2886 def DLLImport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2887 let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
2888 let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2889 let Documentation = [DLLImportDocs];
2892 let AdditionalMembers = [{
2894 bool PropagatedToBaseTemplate = false;
2897 void setPropagatedToBaseTemplate() { PropagatedToBaseTemplate = true; }
2898 bool wasPropagatedToBaseTemplate() { return PropagatedToBaseTemplate; }
2902 def DLLImportStaticLocal : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2903 // This attribute is used internally only when -fno-dllexport-inlines is
2904 // passed. This attribute is added to inline function of class having
2905 // dllimport attribute. And if the function has static local variables, this
2906 // attribute is used to whether the variables are imported or not.
2908 let Subjects = SubjectList<[Function]>;
2909 let Documentation = [Undocumented];
2912 def SelectAny : InheritableAttr {
2913 let Spellings = [Declspec<"selectany">, GCC<"selectany">];
2914 let Documentation = [SelectAnyDocs];
2918 let Spellings = [Declspec<"thread">];
2919 let LangOpts = [MicrosoftExt];
2920 let Documentation = [ThreadDocs];
2921 let Subjects = SubjectList<[Var]>;
2924 def Win64 : IgnoredAttr {
2925 let Spellings = [Keyword<"__w64">];
2926 let LangOpts = [MicrosoftExt];
2929 def Ptr32 : TypeAttr {
2930 let Spellings = [Keyword<"__ptr32">];
2931 let Documentation = [Undocumented];
2934 def Ptr64 : TypeAttr {
2935 let Spellings = [Keyword<"__ptr64">];
2936 let Documentation = [Undocumented];
2939 def SPtr : TypeAttr {
2940 let Spellings = [Keyword<"__sptr">];
2941 let Documentation = [Undocumented];
2944 def UPtr : TypeAttr {
2945 let Spellings = [Keyword<"__uptr">];
2946 let Documentation = [Undocumented];
2949 def MSInheritance : InheritableAttr {
2950 let LangOpts = [MicrosoftExt];
2951 let Args = [DefaultBoolArgument<"BestCase", /*default*/1, /*fake*/1>];
2952 let Spellings = [Keyword<"__single_inheritance">,
2953 Keyword<"__multiple_inheritance">,
2954 Keyword<"__virtual_inheritance">,
2955 Keyword<"__unspecified_inheritance">];
2956 let AdditionalMembers = [{
2957 static bool hasVBPtrOffsetField(Spelling Inheritance) {
2958 return Inheritance == Keyword_unspecified_inheritance;
2961 // Only member pointers to functions need a this adjustment, since it can be
2962 // combined with the field offset for data pointers.
2963 static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) {
2964 return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance;
2967 static bool hasVBTableOffsetField(Spelling Inheritance) {
2968 return Inheritance >= Keyword_virtual_inheritance;
2971 static bool hasOnlyOneField(bool IsMemberFunction,
2972 Spelling Inheritance) {
2973 if (IsMemberFunction)
2974 return Inheritance <= Keyword_single_inheritance;
2975 return Inheritance <= Keyword_multiple_inheritance;
2978 let Documentation = [MSInheritanceDocs];
2981 def MSVtorDisp : InheritableAttr {
2982 // This attribute has no spellings as it is only ever created implicitly.
2984 let Args = [UnsignedArgument<"vdm">];
2985 let SemaHandler = 0;
2987 let AdditionalMembers = [{
2994 Mode getVtorDispMode() const { return Mode(vdm); }
2996 let Documentation = [Undocumented];
2999 def InitSeg : Attr {
3000 let Spellings = [Pragma<"", "init_seg">];
3001 let Args = [StringArgument<"Section">];
3002 let SemaHandler = 0;
3003 let Documentation = [InitSegDocs];
3004 let AdditionalMembers = [{
3005 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3006 OS << " (" << getSection() << ')';
3011 def LoopHint : Attr {
3012 /// #pragma clang loop <option> directive
3013 /// vectorize: vectorizes loop operations if State == Enable.
3014 /// vectorize_width: vectorize loop operations with width 'Value'.
3015 /// interleave: interleave multiple loop iterations if State == Enable.
3016 /// interleave_count: interleaves 'Value' loop iterations.
3017 /// unroll: fully unroll loop if State == Enable.
3018 /// unroll_count: unrolls loop 'Value' times.
3019 /// unroll_and_jam: attempt to unroll and jam loop if State == Enable.
3020 /// unroll_and_jam_count: unroll and jams loop 'Value' times.
3021 /// distribute: attempt to distribute loop if State == Enable.
3022 /// pipeline: disable pipelining loop if State == Disable.
3023 /// pipeline_initiation_interval: create loop schedule with initiation interval equal to 'Value'.
3025 /// #pragma unroll <argument> directive
3026 /// <no arg>: fully unrolls loop.
3027 /// boolean: fully unrolls loop if State == Enable.
3028 /// expression: unrolls loop 'Value' times.
3030 let Spellings = [Pragma<"clang", "loop">, Pragma<"", "unroll">,
3031 Pragma<"", "nounroll">, Pragma<"", "unroll_and_jam">,
3032 Pragma<"", "nounroll_and_jam">];
3034 /// State of the loop optimization specified by the spelling.
3035 let Args = [EnumArgument<"Option", "OptionType",
3036 ["vectorize", "vectorize_width", "interleave", "interleave_count",
3037 "unroll", "unroll_count", "unroll_and_jam", "unroll_and_jam_count",
3038 "pipeline", "pipeline_initiation_interval", "distribute",
3039 "vectorize_predicate"],
3040 ["Vectorize", "VectorizeWidth", "Interleave", "InterleaveCount",
3041 "Unroll", "UnrollCount", "UnrollAndJam", "UnrollAndJamCount",
3042 "PipelineDisabled", "PipelineInitiationInterval", "Distribute",
3043 "VectorizePredicate"]>,
3044 EnumArgument<"State", "LoopHintState",
3045 ["enable", "disable", "numeric", "assume_safety", "full"],
3046 ["Enable", "Disable", "Numeric", "AssumeSafety", "Full"]>,
3047 ExprArgument<"Value">];
3049 let AdditionalMembers = [{
3050 static const char *getOptionName(int Option) {
3052 case Vectorize: return "vectorize";
3053 case VectorizeWidth: return "vectorize_width";
3054 case Interleave: return "interleave";
3055 case InterleaveCount: return "interleave_count";
3056 case Unroll: return "unroll";
3057 case UnrollCount: return "unroll_count";
3058 case UnrollAndJam: return "unroll_and_jam";
3059 case UnrollAndJamCount: return "unroll_and_jam_count";
3060 case PipelineDisabled: return "pipeline";
3061 case PipelineInitiationInterval: return "pipeline_initiation_interval";
3062 case Distribute: return "distribute";
3063 case VectorizePredicate: return "vectorize_predicate";
3065 llvm_unreachable("Unhandled LoopHint option.");
3068 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3069 unsigned SpellingIndex = getAttributeSpellingListIndex();
3070 // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
3071 // "nounroll" is already emitted as the pragma name.
3072 if (SpellingIndex == Pragma_nounroll || SpellingIndex == Pragma_nounroll_and_jam)
3074 else if (SpellingIndex == Pragma_unroll || SpellingIndex == Pragma_unroll_and_jam) {
3075 OS << ' ' << getValueString(Policy);
3079 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
3080 OS << ' ' << getOptionName(option) << getValueString(Policy);
3083 // Return a string containing the loop hint argument including the
3084 // enclosing parentheses.
3085 std::string getValueString(const PrintingPolicy &Policy) const {
3086 std::string ValueName;
3087 llvm::raw_string_ostream OS(ValueName);
3089 if (state == Numeric)
3090 value->printPretty(OS, nullptr, Policy);
3091 else if (state == Enable)
3093 else if (state == Full)
3095 else if (state == AssumeSafety)
3096 OS << "assume_safety";
3103 // Return a string suitable for identifying this attribute in diagnostics.
3104 std::string getDiagnosticName(const PrintingPolicy &Policy) const {
3105 unsigned SpellingIndex = getAttributeSpellingListIndex();
3106 if (SpellingIndex == Pragma_nounroll)
3107 return "#pragma nounroll";
3108 else if (SpellingIndex == Pragma_unroll)
3109 return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
3110 else if (SpellingIndex == Pragma_nounroll_and_jam)
3111 return "#pragma nounroll_and_jam";
3112 else if (SpellingIndex == Pragma_unroll_and_jam)
3113 return "#pragma unroll_and_jam" +
3114 (option == UnrollAndJamCount ? getValueString(Policy) : "");
3116 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
3117 return getOptionName(option) + getValueString(Policy);
3121 let Documentation = [LoopHintDocs, UnrollHintDocs];
3124 def CapturedRecord : InheritableAttr {
3125 // This attribute has no spellings as it is only ever created implicitly.
3127 let SemaHandler = 0;
3128 let Documentation = [Undocumented];
3131 def OMPThreadPrivateDecl : InheritableAttr {
3132 // This attribute has no spellings as it is only ever created implicitly.
3134 let SemaHandler = 0;
3135 let Documentation = [Undocumented];
3138 def OMPCaptureNoInit : InheritableAttr {
3139 // This attribute has no spellings as it is only ever created implicitly.
3141 let SemaHandler = 0;
3142 let Documentation = [Undocumented];
3145 def OMPCaptureKind : Attr {
3146 // This attribute has no spellings as it is only ever created implicitly.
3148 let SemaHandler = 0;
3149 let Args = [UnsignedArgument<"CaptureKind">];
3150 let Documentation = [Undocumented];
3153 def OMPReferencedVar : Attr {
3154 // This attribute has no spellings as it is only ever created implicitly.
3156 let SemaHandler = 0;
3157 let Args = [ExprArgument<"Ref">];
3158 let Documentation = [Undocumented];
3161 def OMPDeclareSimdDecl : Attr {
3162 let Spellings = [Pragma<"omp", "declare simd">];
3163 let Subjects = SubjectList<[Function]>;
3164 let SemaHandler = 0;
3165 let HasCustomParsing = 1;
3166 let Documentation = [OMPDeclareSimdDocs];
3168 EnumArgument<"BranchState", "BranchStateTy",
3169 [ "", "inbranch", "notinbranch" ],
3170 [ "BS_Undefined", "BS_Inbranch", "BS_Notinbranch" ]>,
3171 ExprArgument<"Simdlen">, VariadicExprArgument<"Uniforms">,
3172 VariadicExprArgument<"Aligneds">, VariadicExprArgument<"Alignments">,
3173 VariadicExprArgument<"Linears">, VariadicUnsignedArgument<"Modifiers">,
3174 VariadicExprArgument<"Steps">
3176 let AdditionalMembers = [{
3177 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
3179 if (getBranchState() != BS_Undefined)
3180 OS << ' ' << ConvertBranchStateTyToStr(getBranchState());
3181 if (auto *E = getSimdlen()) {
3183 E->printPretty(OS, nullptr, Policy);
3186 if (uniforms_size() > 0) {
3188 StringRef Sep = "(";
3189 for (auto *E : uniforms()) {
3191 E->printPretty(OS, nullptr, Policy);
3196 alignments_iterator NI = alignments_begin();
3197 for (auto *E : aligneds()) {
3199 E->printPretty(OS, nullptr, Policy);
3202 (*NI)->printPretty(OS, nullptr, Policy);
3207 steps_iterator I = steps_begin();
3208 modifiers_iterator MI = modifiers_begin();
3209 for (auto *E : linears()) {
3211 if (*MI != OMPC_LINEAR_unknown)
3212 OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
3213 E->printPretty(OS, nullptr, Policy);
3214 if (*MI != OMPC_LINEAR_unknown)
3218 (*I)->printPretty(OS, nullptr, Policy);
3228 def OMPDeclareTargetDecl : InheritableAttr {
3229 let Spellings = [Pragma<"omp", "declare target">];
3230 let SemaHandler = 0;
3231 let Subjects = SubjectList<[Function, SharedVar]>;
3232 let Documentation = [OMPDeclareTargetDocs];
3234 EnumArgument<"MapType", "MapTypeTy",
3236 [ "MT_To", "MT_Link" ]>,
3237 EnumArgument<"DevType", "DevTypeTy",
3238 [ "host", "nohost", "any" ],
3239 [ "DT_Host", "DT_NoHost", "DT_Any" ]>
3241 let AdditionalMembers = [{
3242 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3243 // Use fake syntax because it is for testing and debugging purpose only.
3244 if (getDevType() != DT_Any)
3245 OS << " device_type(" << ConvertDevTypeTyToStr(getDevType()) << ")";
3246 if (getMapType() != MT_To)
3247 OS << ' ' << ConvertMapTypeTyToStr(getMapType());
3249 static llvm::Optional<MapTypeTy>
3250 isDeclareTargetDeclaration(const ValueDecl *VD) {
3251 if (!VD->hasAttrs())
3253 if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>())
3254 return Attr->getMapType();
3258 static llvm::Optional<DevTypeTy> getDeviceType(const ValueDecl *VD) {
3259 if (!VD->hasAttrs())
3261 if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>())
3262 return Attr->getDevType();
3269 def OMPAllocateDecl : InheritableAttr {
3270 // This attribute has no spellings as it is only ever created implicitly.
3272 let SemaHandler = 0;
3274 EnumArgument<"AllocatorType", "AllocatorTypeTy",
3276 "omp_default_mem_alloc", "omp_large_cap_mem_alloc",
3277 "omp_const_mem_alloc", "omp_high_bw_mem_alloc",
3278 "omp_low_lat_mem_alloc", "omp_cgroup_mem_alloc",
3279 "omp_pteam_mem_alloc", "omp_thread_mem_alloc", ""
3282 "OMPDefaultMemAlloc", "OMPLargeCapMemAlloc",
3283 "OMPConstMemAlloc", "OMPHighBWMemAlloc", "OMPLowLatMemAlloc",
3284 "OMPCGroupMemAlloc", "OMPPTeamMemAlloc", "OMPThreadMemAlloc",
3285 "OMPUserDefinedMemAlloc"
3287 ExprArgument<"Allocator">
3289 let Documentation = [Undocumented];
3292 def OMPDeclareVariant : InheritableAttr {
3293 let Spellings = [Pragma<"omp", "declare variant">];
3294 let Subjects = SubjectList<[Function]>;
3295 let SemaHandler = 0;
3296 let HasCustomParsing = 1;
3297 let InheritEvenIfAlreadyPresent = 1;
3298 let Documentation = [OMPDeclareVariantDocs];
3300 ExprArgument<"VariantFuncRef">,
3301 ExprArgument<"Score">,
3302 EnumArgument<"CtxSelectorSet", "CtxSelectorSetType",
3303 [ "", "implementation"
3306 "CtxSetUnknown", "CtxSetImplementation"
3308 EnumArgument<"CtxScore", "ScoreType",
3312 "ScoreUnknown", "ScoreSpecified"
3314 EnumArgument<"CtxSelector", "CtxSelectorType",
3318 "CtxUnknown", "CtxVendor"
3320 VariadicStringArgument<"ImplVendors">
3322 let AdditionalMembers = [{
3323 void printScore(raw_ostream & OS, const PrintingPolicy &Policy) const {
3324 if (const Expr *E = getScore()) {
3326 E->printPretty(OS, nullptr, Policy);
3330 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
3332 assert(getCtxSelectorSet() != CtxSetUnknown &&
3333 getCtxSelector() != CtxUnknown && "Unknown context selector.");
3334 if (const Expr *E = getVariantFuncRef()) {
3336 E->printPretty(OS, nullptr, Policy);
3339 // TODO: add printing of real context selectors.
3341 switch (getCtxSelectorSet()) {
3342 case CtxSetImplementation:
3343 OS << "implementation={";
3344 switch (getCtxSelector()) {
3347 printScore(OS, Policy);
3348 if (implVendors_size() > 0) {
3349 OS << *implVendors(). begin();
3350 for (StringRef VendorName : llvm::drop_begin(implVendors(), 1))
3351 OS << ", " << VendorName;
3356 llvm_unreachable("Unknown context selector.");
3361 llvm_unreachable("Unknown context selector set.");
3368 def InternalLinkage : InheritableAttr {
3369 let Spellings = [Clang<"internal_linkage">];
3370 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
3371 let Documentation = [InternalLinkageDocs];
3374 def ExcludeFromExplicitInstantiation : InheritableAttr {
3375 let Spellings = [Clang<"exclude_from_explicit_instantiation">];
3376 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
3377 let Documentation = [ExcludeFromExplicitInstantiationDocs];
3378 let MeaningfulToClassTemplateDefinition = 1;
3381 def Reinitializes : InheritableAttr {
3382 let Spellings = [Clang<"reinitializes", 0>];
3383 let Subjects = SubjectList<[NonStaticNonConstCXXMethod], ErrorDiag>;
3384 let Documentation = [ReinitializesDocs];
3387 def NoDestroy : InheritableAttr {
3388 let Spellings = [Clang<"no_destroy", 0>];
3389 let Subjects = SubjectList<[Var]>;
3390 let Documentation = [NoDestroyDocs];
3393 def AlwaysDestroy : InheritableAttr {
3394 let Spellings = [Clang<"always_destroy", 0>];
3395 let Subjects = SubjectList<[Var]>;
3396 let Documentation = [AlwaysDestroyDocs];
3399 def SpeculativeLoadHardening : InheritableAttr {
3400 let Spellings = [Clang<"speculative_load_hardening">];
3401 let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
3402 let Documentation = [SpeculativeLoadHardeningDocs];
3405 def NoSpeculativeLoadHardening : InheritableAttr {
3406 let Spellings = [Clang<"no_speculative_load_hardening">];
3407 let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
3408 let Documentation = [NoSpeculativeLoadHardeningDocs];
3411 def Uninitialized : InheritableAttr {
3412 let Spellings = [Clang<"uninitialized", 0>];
3413 let Subjects = SubjectList<[LocalVar]>;
3414 let Documentation = [UninitializedDocs];
3417 def ObjCExternallyRetained : InheritableAttr {
3418 let LangOpts = [ObjCAutoRefCount];
3419 let Spellings = [Clang<"objc_externally_retained">];
3420 let Subjects = SubjectList<[NonParmVar, Function, Block, ObjCMethod]>;
3421 let Documentation = [ObjCExternallyRetainedDocs];