1 //==--- Attr.td - attribute definitions -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // The documentation is organized by category. Attributes can have category-
11 // specific documentation that is collated within the larger document.
12 class DocumentationCategory<string name> {
16 def DocCatFunction : DocumentationCategory<"Function Attributes">;
17 def DocCatVariable : DocumentationCategory<"Variable Attributes">;
18 def DocCatType : DocumentationCategory<"Type Attributes">;
19 def DocCatStmt : DocumentationCategory<"Statement Attributes">;
20 // Attributes listed under the Undocumented category do not generate any public
21 // documentation. Ideally, this category should be used for internal-only
22 // attributes which contain no spellings.
23 def DocCatUndocumented : DocumentationCategory<"Undocumented">;
25 class DocDeprecated<string replacement = ""> {
26 // If the Replacement field is empty, no replacement will be listed with the
27 // documentation. Otherwise, the documentation will specify the attribute has
28 // been superseded by this replacement.
29 string Replacement = replacement;
32 // Specifies the documentation to be associated with the given category.
34 DocumentationCategory Category;
37 // If the heading is empty, one may be picked automatically. If the attribute
38 // only has one spelling, no heading is required as the attribute's sole
39 // spelling is sufficient. If all spellings are semantically common, the
40 // heading will be the semantic spelling. If the spellings are not
41 // semantically common and no heading is provided, an error will be emitted.
44 // When set, specifies that the attribute is deprecated and can optionally
45 // specify a replacement attribute.
46 DocDeprecated Deprecated;
49 // Specifies that the attribute is explicitly undocumented. This can be a
50 // helpful placeholder for the attribute while working on the implementation,
51 // but should not be used once feature work has been completed.
52 def Undocumented : Documentation {
53 let Category = DocCatUndocumented;
56 include "clang/Basic/AttrDocs.td"
58 // An attribute's subject is whatever it appertains to. In this file, it is
59 // more accurately a list of things that an attribute can appertain to. All
60 // Decls and Stmts are possibly AttrSubjects (even though the syntax may not
61 // allow attributes on a given Decl or Stmt).
64 include "clang/Basic/DeclNodes.td"
65 include "clang/Basic/StmtNodes.td"
67 // A subset-subject is an AttrSubject constrained to operate only on some subset
70 // The code fragment is a boolean expression that will confirm that the subject
71 // meets the requirements; the subject will have the name S, and will have the
72 // type specified by the base. It should be a simple boolean expression.
73 class SubsetSubject<AttrSubject base, code check> : AttrSubject {
74 AttrSubject Base = base;
75 code CheckCode = check;
78 // This is the type of a variable which C++11 allows alignas(...) to appertain
80 def NormalVar : SubsetSubject<Var,
81 [{S->getStorageClass() != VarDecl::Register &&
82 S->getKind() != Decl::ImplicitParam &&
83 S->getKind() != Decl::ParmVar &&
84 S->getKind() != Decl::NonTypeTemplateParm}]>;
85 def NonParmVar : SubsetSubject<Var,
86 [{S->getKind() != Decl::ParmVar}]>;
87 def NonBitField : SubsetSubject<Field,
88 [{!S->isBitField()}]>;
90 def ObjCInstanceMethod : SubsetSubject<ObjCMethod,
91 [{S->isInstanceMethod()}]>;
93 def ObjCInterfaceDeclInitMethod : SubsetSubject<ObjCMethod,
94 [{S->getMethodFamily() == OMF_init &&
95 (isa<ObjCInterfaceDecl>(S->getDeclContext()) ||
96 (isa<ObjCCategoryDecl>(S->getDeclContext()) &&
97 cast<ObjCCategoryDecl>(S->getDeclContext())->IsClassExtension()))}]>;
99 def Struct : SubsetSubject<Record,
102 def TLSVar : SubsetSubject<Var,
103 [{S->getTLSKind() != 0}]>;
105 def SharedVar : SubsetSubject<Var,
106 [{S->hasGlobalStorage() && !S->getTLSKind()}]>;
108 def GlobalVar : SubsetSubject<Var,
109 [{S->hasGlobalStorage()}]>;
111 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
112 // type to be a class, not a definition. This makes it impossible to create an
113 // attribute subject which accepts a Decl. Normally, this is not a problem,
114 // because the attribute can have no Subjects clause to accomplish this. But in
115 // the case of a SubsetSubject, there's no way to express it without this hack.
116 def DeclBase : AttrSubject;
117 def FunctionLike : SubsetSubject<DeclBase,
118 [{S->getFunctionType(false) != nullptr}]>;
120 def OpenCLKernelFunction : SubsetSubject<Function, [{
121 S->hasAttr<OpenCLKernelAttr>()
124 // HasFunctionProto is a more strict version of FunctionLike, so it should
125 // never be specified in a Subjects list along with FunctionLike (due to the
126 // inclusive nature of subject testing).
127 def HasFunctionProto : SubsetSubject<DeclBase,
128 [{(S->getFunctionType(true) != nullptr &&
129 isa<FunctionProtoType>(S->getFunctionType())) ||
130 isa<ObjCMethodDecl>(S) ||
131 isa<BlockDecl>(S)}]>;
133 // A single argument to an attribute
134 class Argument<string name, bit optional, bit fake = 0> {
136 bit Optional = optional;
138 /// A fake argument is used to store and serialize additional information
139 /// in an attribute without actually changing its parsing or pretty-printing.
143 class BoolArgument<string name, bit opt = 0, bit fake = 0> : Argument<name, opt,
145 class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
146 class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
147 class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
148 class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
149 class FunctionArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
152 class TypeArgument<string name, bit opt = 0> : Argument<name, opt>;
153 class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
154 class VariadicUnsignedArgument<string name> : Argument<name, 1>;
155 class VariadicExprArgument<string name> : Argument<name, 1>;
156 class VariadicStringArgument<string name> : Argument<name, 1>;
158 // A version of the form major.minor[.subminor].
159 class VersionArgument<string name, bit opt = 0> : Argument<name, opt>;
161 // This one's a doozy, so it gets its own special type
162 // It can be an unsigned integer, or a type. Either can
164 class AlignedArgument<string name, bit opt = 0> : Argument<name, opt>;
166 // A bool argument with a default value
167 class DefaultBoolArgument<string name, bit default> : BoolArgument<name, 1> {
168 bit Default = default;
171 // An integer argument with a default value
172 class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
173 int Default = default;
176 // This argument is more complex, it includes the enumerator type name,
177 // a list of strings to accept, and a list of enumerators to map them to.
178 class EnumArgument<string name, string type, list<string> values,
179 list<string> enums, bit opt = 0, bit fake = 0>
180 : Argument<name, opt, fake> {
182 list<string> Values = values;
183 list<string> Enums = enums;
186 // FIXME: There should be a VariadicArgument type that takes any other type
187 // of argument and generates the appropriate type.
188 class VariadicEnumArgument<string name, string type, list<string> values,
189 list<string> enums> : Argument<name, 1> {
191 list<string> Values = values;
192 list<string> Enums = enums;
195 // This handles one spelling of an attribute.
196 class Spelling<string name, string variety> {
198 string Variety = variety;
202 class GNU<string name> : Spelling<name, "GNU">;
203 class Declspec<string name> : Spelling<name, "Declspec">;
204 class Microsoft<string name> : Spelling<name, "Microsoft">;
205 class CXX11<string namespace, string name, int version = 1>
206 : Spelling<name, "CXX11"> {
207 string Namespace = namespace;
208 int Version = version;
210 class Keyword<string name> : Spelling<name, "Keyword">;
211 class Pragma<string namespace, string name> : Spelling<name, "Pragma"> {
212 string Namespace = namespace;
215 // The GCC spelling implies GNU<name, "GNU"> and CXX11<"gnu", name> and also
216 // sets KnownToGCC to 1. This spelling should be used for any GCC-compatible
218 class GCC<string name> : Spelling<name, "GCC"> {
222 class Accessor<string name, list<Spelling> spellings> {
224 list<Spelling> Spellings = spellings;
227 class SubjectDiag<bit warn> {
230 def WarnDiag : SubjectDiag<1>;
231 def ErrorDiag : SubjectDiag<0>;
233 class SubjectList<list<AttrSubject> subjects, SubjectDiag diag = WarnDiag,
234 string customDiag = ""> {
235 list<AttrSubject> Subjects = subjects;
236 SubjectDiag Diag = diag;
237 string CustomDiag = customDiag;
240 class LangOpt<string name, bit negated = 0> {
242 bit Negated = negated;
244 def MicrosoftExt : LangOpt<"MicrosoftExt">;
245 def Borland : LangOpt<"Borland">;
246 def CUDA : LangOpt<"CUDA">;
247 def COnly : LangOpt<"CPlusPlus", 1>;
248 def CPlusPlus : LangOpt<"CPlusPlus">;
249 def OpenCL : LangOpt<"OpenCL">;
250 def RenderScript : LangOpt<"RenderScript">;
252 // Defines targets for target-specific attributes. The list of strings should
253 // specify architectures for which the target applies, based off the ArchType
254 // enumeration in Triple.h.
255 class TargetArch<list<string> arches> {
256 list<string> Arches = arches;
258 list<string> CXXABIs;
260 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
261 def TargetMips : TargetArch<["mips", "mipsel"]>;
262 def TargetMSP430 : TargetArch<["msp430"]>;
263 def TargetX86 : TargetArch<["x86"]>;
264 def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
265 def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
266 let OSes = ["Win32"];
268 def TargetMicrosoftCXXABI : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
269 let CXXABIs = ["Microsoft"];
273 // The various ways in which an attribute can be spelled in source
274 list<Spelling> Spellings;
275 // The things to which an attribute can appertain
276 SubjectList Subjects;
277 // The arguments allowed on an attribute
278 list<Argument> Args = [];
279 // Accessors which should be generated for the attribute.
280 list<Accessor> Accessors = [];
281 // Set to true for attributes with arguments which require delayed parsing.
283 // Set to false to prevent an attribute from being propagated from a template
284 // to the instantiation.
286 // Set to true for attributes which must be instantiated within templates
287 bit TemplateDependent = 0;
288 // Set to true for attributes that have a corresponding AST node.
290 // Set to true for attributes which have handler in Sema.
292 // Set to true for attributes that are completely ignored.
294 // Set to true if the attribute's parsing does not match its semantic
295 // content. Eg) It parses 3 args, but semantically takes 4 args. Opts out of
296 // common attribute error checking.
297 bit HasCustomParsing = 0;
298 // Set to true if all of the attribute's arguments should be parsed in an
299 // unevaluated context.
300 bit ParseArgumentsAsUnevaluated = 0;
301 // Set to true if this attribute can be duplicated on a subject when merging
302 // attributes. By default, attributes are not merged.
303 bit DuplicatesAllowedWhileMerging = 0;
304 // Lists language options, one of which is required to be true for the
305 // attribute to be applicable. If empty, no language options are required.
306 list<LangOpt> LangOpts = [];
307 // Any additional text that should be included verbatim in the class.
308 // Note: Any additional data members will leak and should be constructed
309 // externally on the ASTContext.
310 code AdditionalMembers = [{}];
311 // Any documentation that should be associated with the attribute. Since an
312 // attribute may be documented under multiple categories, more than one
313 // Documentation entry may be listed.
314 list<Documentation> Documentation;
317 /// A type attribute is not processed on a declaration or a statement.
318 class TypeAttr : Attr {
319 // By default, type attributes do not get an AST node.
323 /// A stmt attribute is not processed on a declaration or a type.
324 class StmtAttr : Attr;
326 /// An inheritable attribute is inherited by later redeclarations.
327 class InheritableAttr : Attr;
329 /// A target-specific attribute. This class is meant to be used as a mixin
330 /// with InheritableAttr or Attr depending on the attribute's needs.
331 class TargetSpecificAttr<TargetArch target> {
332 TargetArch Target = target;
333 // Attributes are generally required to have unique spellings for their names
334 // so that the parser can determine what kind of attribute it has parsed.
335 // However, target-specific attributes are special in that the attribute only
336 // "exists" for a given target. So two target-specific attributes can share
337 // the same name when they exist in different targets. To support this, a
338 // Kind can be explicitly specified for a target-specific attribute. This
339 // corresponds to the AttributeList::AT_* enum that is generated and it
340 // should contain a shared value between the attributes.
342 // Target-specific attributes which use this feature should ensure that the
343 // spellings match exactly betweeen the attributes, and if the arguments or
344 // subjects differ, should specify HasCustomParsing = 1 and implement their
345 // own parsing and semantic handling requirements as-needed.
349 /// An inheritable parameter attribute is inherited by later
350 /// redeclarations, even when it's written on a parameter.
351 class InheritableParamAttr : InheritableAttr;
353 /// An attribute which changes the ABI rules for a specific parameter.
354 class ParameterABIAttr : InheritableParamAttr {
355 let Subjects = SubjectList<[ParmVar]>;
358 /// An ignored attribute, which we parse but discard with no checking.
359 class IgnoredAttr : Attr {
363 let Documentation = [Undocumented];
367 // Attributes begin here
371 let Spellings = [GCC<"abi_tag">];
372 let Args = [VariadicStringArgument<"Tags">];
373 let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag,
374 "ExpectedStructClassVariableFunctionOrInlineNamespace">;
375 let Documentation = [AbiTagsDocs];
378 def AddressSpace : TypeAttr {
379 let Spellings = [GNU<"address_space">];
380 let Args = [IntArgument<"AddressSpace">];
381 let Documentation = [Undocumented];
385 let Spellings = [GCC<"alias">];
386 let Args = [StringArgument<"Aliasee">];
387 let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
388 "ExpectedFunctionOrGlobalVar">;
389 let Documentation = [Undocumented];
392 def Aligned : InheritableAttr {
393 let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
394 Keyword<"_Alignas">];
395 // let Subjects = SubjectList<[NonBitField, NormalVar, Tag]>;
396 let Args = [AlignedArgument<"Alignment", 1>];
397 let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
398 Accessor<"isC11", [Keyword<"_Alignas">]>,
399 Accessor<"isAlignas", [Keyword<"alignas">,
400 Keyword<"_Alignas">]>,
401 Accessor<"isDeclspec",[Declspec<"align">]>];
402 let Documentation = [Undocumented];
405 def AlignValue : Attr {
407 // Unfortunately, this is semantically an assertion, not a directive
408 // (something else must ensure the alignment), so aligned_value is a
409 // probably a better name. We might want to add an aligned_value spelling in
410 // the future (and a corresponding C++ attribute), but this can be done
411 // later once we decide if we also want them to have slightly-different
412 // semantics than Intel's align_value.
414 // Intel's compiler on Windows also supports:
415 // , Declspec<"align_value">
417 let Args = [ExprArgument<"Alignment">];
418 let Subjects = SubjectList<[Var, TypedefName], WarnDiag,
419 "ExpectedVariableOrTypedef">;
420 let Documentation = [AlignValueDocs];
423 def AlignMac68k : InheritableAttr {
424 // This attribute has no spellings as it is only ever created implicitly.
427 let Documentation = [Undocumented];
430 def AlwaysInline : InheritableAttr {
431 let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
432 let Subjects = SubjectList<[Function]>;
433 let Documentation = [Undocumented];
436 def XRayInstrument : InheritableAttr {
437 let Spellings = [GNU<"xray_always_instrument">,
438 CXX11<"clang", "xray_always_instrument">,
439 GNU<"xray_never_instrument">,
440 CXX11<"clang", "xray_never_instrument">];
441 let Subjects = SubjectList<[CXXMethod, ObjCMethod, Function], WarnDiag,
442 "ExpectedFunctionOrMethod">;
443 let Accessors = [Accessor<"alwaysXRayInstrument",
444 [GNU<"xray_always_instrument">,
445 CXX11<"clang", "xray_always_instrument">]>,
446 Accessor<"neverXRayInstrument",
447 [GNU<"xray_never_instrument">,
448 CXX11<"clang", "xray_never_instrument">]>];
449 let Documentation = [XRayDocs];
452 def TLSModel : InheritableAttr {
453 let Spellings = [GCC<"tls_model">];
454 let Subjects = SubjectList<[TLSVar], ErrorDiag, "ExpectedTLSVar">;
455 let Args = [StringArgument<"Model">];
456 let Documentation = [TLSModelDocs];
459 def AnalyzerNoReturn : InheritableAttr {
460 let Spellings = [GNU<"analyzer_noreturn">];
461 let Documentation = [Undocumented];
464 def Annotate : InheritableParamAttr {
465 let Spellings = [GNU<"annotate">];
466 let Args = [StringArgument<"Annotation">];
467 let Documentation = [Undocumented];
470 def ARMInterrupt : InheritableAttr, TargetSpecificAttr<TargetARM> {
471 // NOTE: If you add any additional spellings, MSP430Interrupt's,
472 // MipsInterrupt's and AnyX86Interrupt's spellings must match.
473 let Spellings = [GNU<"interrupt">];
474 let Args = [EnumArgument<"Interrupt", "InterruptType",
475 ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
476 ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
478 let ParseKind = "Interrupt";
479 let HasCustomParsing = 1;
480 let Documentation = [ARMInterruptDocs];
483 def AsmLabel : InheritableAttr {
484 let Spellings = [Keyword<"asm">, Keyword<"__asm__">];
485 let Args = [StringArgument<"Label">];
487 let Documentation = [Undocumented];
490 def Availability : InheritableAttr {
491 let Spellings = [GNU<"availability">];
492 let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
493 VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
494 BoolArgument<"unavailable">, StringArgument<"message">,
495 BoolArgument<"strict">, StringArgument<"replacement">];
496 let AdditionalMembers =
497 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
498 return llvm::StringSwitch<llvm::StringRef>(Platform)
499 .Case("android", "Android")
501 .Case("macos", "macOS")
502 .Case("tvos", "tvOS")
503 .Case("watchos", "watchOS")
504 .Case("ios_app_extension", "iOS (App Extension)")
505 .Case("macos_app_extension", "macOS (App Extension)")
506 .Case("tvos_app_extension", "tvOS (App Extension)")
507 .Case("watchos_app_extension", "watchOS (App Extension)")
508 .Default(llvm::StringRef());
510 let HasCustomParsing = 1;
511 let DuplicatesAllowedWhileMerging = 1;
512 // let Subjects = SubjectList<[Named]>;
513 let Documentation = [AvailabilityDocs];
516 def Blocks : InheritableAttr {
517 let Spellings = [GNU<"blocks">];
518 let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
519 let Documentation = [Undocumented];
522 def Bounded : IgnoredAttr {
523 let Spellings = [GNU<"bounded">];
526 def CarriesDependency : InheritableParamAttr {
527 let Spellings = [GNU<"carries_dependency">,
528 CXX11<"","carries_dependency", 200809>];
529 let Subjects = SubjectList<[ParmVar, ObjCMethod, Function], ErrorDiag>;
530 let Documentation = [CarriesDependencyDocs];
533 def CDecl : InheritableAttr {
534 let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
535 // let Subjects = [Function, ObjCMethod];
536 let Documentation = [Undocumented];
539 // cf_audited_transfer indicates that the given function has been
540 // audited and has been marked with the appropriate cf_consumed and
541 // cf_returns_retained attributes. It is generally applied by
542 // '#pragma clang arc_cf_code_audited' rather than explicitly.
543 def CFAuditedTransfer : InheritableAttr {
544 let Spellings = [GNU<"cf_audited_transfer">];
545 let Subjects = SubjectList<[Function], ErrorDiag>;
546 let Documentation = [Undocumented];
549 // cf_unknown_transfer is an explicit opt-out of cf_audited_transfer.
550 // It indicates that the function has unknown or unautomatable
551 // transfer semantics.
552 def CFUnknownTransfer : InheritableAttr {
553 let Spellings = [GNU<"cf_unknown_transfer">];
554 let Subjects = SubjectList<[Function], ErrorDiag>;
555 let Documentation = [Undocumented];
558 def CFReturnsRetained : InheritableAttr {
559 let Spellings = [GNU<"cf_returns_retained">];
560 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
561 let Documentation = [Undocumented];
564 def CFReturnsNotRetained : InheritableAttr {
565 let Spellings = [GNU<"cf_returns_not_retained">];
566 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
567 let Documentation = [Undocumented];
570 def CFConsumed : InheritableParamAttr {
571 let Spellings = [GNU<"cf_consumed">];
572 let Subjects = SubjectList<[ParmVar]>;
573 let Documentation = [Undocumented];
576 def Cleanup : InheritableAttr {
577 let Spellings = [GCC<"cleanup">];
578 let Args = [FunctionArgument<"FunctionDecl">];
579 let Subjects = SubjectList<[Var]>;
580 let Documentation = [Undocumented];
583 def Cold : InheritableAttr {
584 let Spellings = [GCC<"cold">];
585 let Subjects = SubjectList<[Function]>;
586 let Documentation = [Undocumented];
589 def Common : InheritableAttr {
590 let Spellings = [GCC<"common">];
591 let Subjects = SubjectList<[Var]>;
592 let Documentation = [Undocumented];
595 def Const : InheritableAttr {
596 let Spellings = [GCC<"const">, GCC<"__const">];
597 let Documentation = [Undocumented];
600 def Constructor : InheritableAttr {
601 let Spellings = [GCC<"constructor">];
602 let Args = [DefaultIntArgument<"Priority", 65535>];
603 let Subjects = SubjectList<[Function]>;
604 let Documentation = [Undocumented];
607 // CUDA attributes are spelled __attribute__((attr)) or __declspec(__attr__).
609 def CUDAConstant : InheritableAttr {
610 let Spellings = [GNU<"constant">, Declspec<"__constant__">];
611 let Subjects = SubjectList<[Var]>;
612 let LangOpts = [CUDA];
613 let Documentation = [Undocumented];
616 def CUDACudartBuiltin : IgnoredAttr {
617 let Spellings = [GNU<"cudart_builtin">, Declspec<"__cudart_builtin__">];
618 let LangOpts = [CUDA];
621 def CUDADevice : InheritableAttr {
622 let Spellings = [GNU<"device">, Declspec<"__device__">];
623 let Subjects = SubjectList<[Function, Var]>;
624 let LangOpts = [CUDA];
625 let Documentation = [Undocumented];
628 def CUDADeviceBuiltin : IgnoredAttr {
629 let Spellings = [GNU<"device_builtin">, Declspec<"__device_builtin__">];
630 let LangOpts = [CUDA];
633 def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
634 let Spellings = [GNU<"device_builtin_surface_type">,
635 Declspec<"__device_builtin_surface_type__">];
636 let LangOpts = [CUDA];
639 def CUDADeviceBuiltinTextureType : IgnoredAttr {
640 let Spellings = [GNU<"device_builtin_texture_type">,
641 Declspec<"__device_builtin_texture_type__">];
642 let LangOpts = [CUDA];
645 def CUDAGlobal : InheritableAttr {
646 let Spellings = [GNU<"global">, Declspec<"__global__">];
647 let Subjects = SubjectList<[Function]>;
648 let LangOpts = [CUDA];
649 let Documentation = [Undocumented];
652 def CUDAHost : InheritableAttr {
653 let Spellings = [GNU<"host">, Declspec<"__host__">];
654 let Subjects = SubjectList<[Function]>;
655 let LangOpts = [CUDA];
656 let Documentation = [Undocumented];
659 def CUDAInvalidTarget : InheritableAttr {
661 let Subjects = SubjectList<[Function]>;
662 let LangOpts = [CUDA];
663 let Documentation = [Undocumented];
666 def CUDALaunchBounds : InheritableAttr {
667 let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
668 let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
669 let LangOpts = [CUDA];
670 let Subjects = SubjectList<[ObjCMethod, FunctionLike], WarnDiag,
671 "ExpectedFunctionOrMethod">;
672 // An AST node is created for this attribute, but is not used by other parts
673 // of the compiler. However, this node needs to exist in the AST because
674 // non-LLVM backends may be relying on the attribute's presence.
675 let Documentation = [Undocumented];
678 def CUDAShared : InheritableAttr {
679 let Spellings = [GNU<"shared">, Declspec<"__shared__">];
680 let Subjects = SubjectList<[Var]>;
681 let LangOpts = [CUDA];
682 let Documentation = [Undocumented];
685 def C11NoReturn : InheritableAttr {
686 let Spellings = [Keyword<"_Noreturn">];
687 let Subjects = SubjectList<[Function], ErrorDiag>;
689 let Documentation = [C11NoReturnDocs];
692 def CXX11NoReturn : InheritableAttr {
693 let Spellings = [CXX11<"","noreturn", 200809>];
694 let Subjects = SubjectList<[Function], ErrorDiag>;
695 let Documentation = [CXX11NoReturnDocs];
698 def OpenCLKernel : InheritableAttr {
699 let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
700 let Subjects = SubjectList<[Function], ErrorDiag>;
701 let Documentation = [Undocumented];
704 def OpenCLUnrollHint : InheritableAttr {
705 let Spellings = [GNU<"opencl_unroll_hint">];
706 let Args = [UnsignedArgument<"UnrollHint">];
707 let Documentation = [OpenCLUnrollHintDocs];
710 // This attribute is both a type attribute, and a declaration attribute (for
711 // parameter variables).
712 def OpenCLAccess : Attr {
713 let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
714 Keyword<"__write_only">, Keyword<"write_only">,
715 Keyword<"__read_write">, Keyword<"read_write">];
716 let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag,
717 "ExpectedParameterOrTypedef">;
718 let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
719 Keyword<"read_only">]>,
720 Accessor<"isReadWrite", [Keyword<"__read_write">,
721 Keyword<"read_write">]>,
722 Accessor<"isWriteOnly", [Keyword<"__write_only">,
723 Keyword<"write_only">]>];
724 let Documentation = [OpenCLAccessDocs];
727 def OpenCLPrivateAddressSpace : TypeAttr {
728 let Spellings = [Keyword<"__private">, Keyword<"private">];
729 let Documentation = [OpenCLAddressSpacePrivateDocs];
732 def OpenCLGlobalAddressSpace : TypeAttr {
733 let Spellings = [Keyword<"__global">, Keyword<"global">];
734 let Documentation = [OpenCLAddressSpaceGlobalDocs];
737 def OpenCLLocalAddressSpace : TypeAttr {
738 let Spellings = [Keyword<"__local">, Keyword<"local">];
739 let Documentation = [OpenCLAddressSpaceLocalDocs];
742 def OpenCLConstantAddressSpace : TypeAttr {
743 let Spellings = [Keyword<"__constant">, Keyword<"constant">];
744 let Documentation = [OpenCLAddressSpaceConstantDocs];
747 def OpenCLGenericAddressSpace : TypeAttr {
748 let Spellings = [Keyword<"__generic">, Keyword<"generic">];
749 let Documentation = [OpenCLAddressSpaceGenericDocs];
752 def OpenCLNoSVM : Attr {
753 let Spellings = [GNU<"nosvm">];
754 let Subjects = SubjectList<[Var]>;
755 let Documentation = [OpenCLNoSVMDocs];
756 let LangOpts = [OpenCL];
760 def RenderScriptKernel : Attr {
761 let Spellings = [GNU<"kernel">];
762 let Subjects = SubjectList<[Function]>;
763 let Documentation = [RenderScriptKernelAttributeDocs];
764 let LangOpts = [RenderScript];
767 def Deprecated : InheritableAttr {
768 let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
769 CXX11<"","deprecated", 201309>];
770 let Args = [StringArgument<"Message", 1>,
771 // An optional string argument that enables us to provide a
773 StringArgument<"Replacement", 1>];
774 let Documentation = [DeprecatedDocs];
777 def Destructor : InheritableAttr {
778 let Spellings = [GCC<"destructor">];
779 let Args = [DefaultIntArgument<"Priority", 65535>];
780 let Subjects = SubjectList<[Function]>;
781 let Documentation = [Undocumented];
784 def EmptyBases : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
785 let Spellings = [Declspec<"empty_bases">];
786 let Subjects = SubjectList<[CXXRecord]>;
787 let Documentation = [EmptyBasesDocs];
790 def AllocSize : InheritableAttr {
791 let Spellings = [GCC<"alloc_size">];
792 let Subjects = SubjectList<[Function]>;
793 let Args = [IntArgument<"ElemSizeParam">, IntArgument<"NumElemsParam", 1>];
794 let TemplateDependent = 1;
795 let Documentation = [AllocSizeDocs];
798 def EnableIf : InheritableAttr {
799 let Spellings = [GNU<"enable_if">];
800 let Subjects = SubjectList<[Function]>;
801 let Args = [ExprArgument<"Cond">, StringArgument<"Message">];
802 let TemplateDependent = 1;
803 let Documentation = [EnableIfDocs];
806 def ExtVectorType : Attr {
807 let Spellings = [GNU<"ext_vector_type">];
808 let Subjects = SubjectList<[TypedefName], ErrorDiag>;
809 let Args = [ExprArgument<"NumElements">];
811 let Documentation = [Undocumented];
814 def FallThrough : StmtAttr {
815 let Spellings = [CXX11<"", "fallthrough", 201603>,
816 CXX11<"clang", "fallthrough">];
817 // let Subjects = [NullStmt];
818 let Documentation = [FallthroughDocs];
821 def FastCall : InheritableAttr {
822 let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
823 Keyword<"_fastcall">];
824 // let Subjects = [Function, ObjCMethod];
825 let Documentation = [FastCallDocs];
828 def RegCall : InheritableAttr {
829 let Spellings = [GCC<"regcall">, Keyword<"__regcall">];
830 let Documentation = [RegCallDocs];
833 def Final : InheritableAttr {
834 let Spellings = [Keyword<"final">, Keyword<"sealed">];
835 let Accessors = [Accessor<"isSpelledAsSealed", [Keyword<"sealed">]>];
837 let Documentation = [Undocumented];
840 def MinSize : InheritableAttr {
841 let Spellings = [GNU<"minsize">];
842 let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
843 let Documentation = [Undocumented];
846 def FlagEnum : InheritableAttr {
847 let Spellings = [GNU<"flag_enum">];
848 let Subjects = SubjectList<[Enum]>;
849 let Documentation = [FlagEnumDocs];
850 let LangOpts = [COnly];
853 def Flatten : InheritableAttr {
854 let Spellings = [GCC<"flatten">];
855 let Subjects = SubjectList<[Function], ErrorDiag>;
856 let Documentation = [FlattenDocs];
859 def Format : InheritableAttr {
860 let Spellings = [GCC<"format">];
861 let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">,
862 IntArgument<"FirstArg">];
863 let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto], WarnDiag,
864 "ExpectedFunctionWithProtoType">;
865 let Documentation = [FormatDocs];
868 def FormatArg : InheritableAttr {
869 let Spellings = [GCC<"format_arg">];
870 let Args = [IntArgument<"FormatIdx">];
871 let Subjects = SubjectList<[ObjCMethod, HasFunctionProto], WarnDiag,
872 "ExpectedFunctionWithProtoType">;
873 let Documentation = [Undocumented];
876 def GNUInline : InheritableAttr {
877 let Spellings = [GCC<"gnu_inline">];
878 let Subjects = SubjectList<[Function]>;
879 let Documentation = [Undocumented];
882 def Hot : InheritableAttr {
883 let Spellings = [GCC<"hot">];
884 let Subjects = SubjectList<[Function]>;
885 // An AST node is created for this attribute, but not actually used beyond
886 // semantic checking for mutual exclusion with the Cold attribute.
887 let Documentation = [Undocumented];
890 def IBAction : InheritableAttr {
891 let Spellings = [GNU<"ibaction">];
892 let Subjects = SubjectList<[ObjCInstanceMethod], WarnDiag,
893 "ExpectedObjCInstanceMethod">;
894 // An AST node is created for this attribute, but is not used by other parts
895 // of the compiler. However, this node needs to exist in the AST because
896 // external tools rely on it.
897 let Documentation = [Undocumented];
900 def IBOutlet : InheritableAttr {
901 let Spellings = [GNU<"iboutlet">];
902 // let Subjects = [ObjCIvar, ObjCProperty];
903 let Documentation = [Undocumented];
906 def IBOutletCollection : InheritableAttr {
907 let Spellings = [GNU<"iboutletcollection">];
908 let Args = [TypeArgument<"Interface", 1>];
909 // let Subjects = [ObjCIvar, ObjCProperty];
910 let Documentation = [Undocumented];
914 let Spellings = [GCC<"ifunc">];
915 let Args = [StringArgument<"Resolver">];
916 let Subjects = SubjectList<[Function]>;
917 let Documentation = [IFuncDocs];
920 def Restrict : InheritableAttr {
921 let Spellings = [Declspec<"restrict">, GCC<"malloc">];
922 let Subjects = SubjectList<[Function]>;
923 let Documentation = [Undocumented];
926 def LayoutVersion : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
927 let Spellings = [Declspec<"layout_version">];
928 let Args = [UnsignedArgument<"Version">];
929 let Subjects = SubjectList<[CXXRecord]>;
930 let Documentation = [LayoutVersionDocs];
933 def MaxFieldAlignment : InheritableAttr {
934 // This attribute has no spellings as it is only ever created implicitly.
936 let Args = [UnsignedArgument<"Alignment">];
938 let Documentation = [Undocumented];
941 def MayAlias : InheritableAttr {
942 // FIXME: this is a type attribute in GCC, but a declaration attribute here.
943 let Spellings = [GCC<"may_alias">];
944 let Documentation = [Undocumented];
947 def MSABI : InheritableAttr {
948 let Spellings = [GCC<"ms_abi">];
949 // let Subjects = [Function, ObjCMethod];
950 let Documentation = [MSABIDocs];
953 def MSP430Interrupt : InheritableAttr, TargetSpecificAttr<TargetMSP430> {
954 // NOTE: If you add any additional spellings, ARMInterrupt's, MipsInterrupt's
955 // and AnyX86Interrupt's spellings must match.
956 let Spellings = [GNU<"interrupt">];
957 let Args = [UnsignedArgument<"Number">];
958 let ParseKind = "Interrupt";
959 let HasCustomParsing = 1;
960 let Documentation = [Undocumented];
963 def Mips16 : InheritableAttr, TargetSpecificAttr<TargetMips> {
964 let Spellings = [GCC<"mips16">];
965 let Subjects = SubjectList<[Function], ErrorDiag>;
966 let Documentation = [Undocumented];
969 def MipsInterrupt : InheritableAttr, TargetSpecificAttr<TargetMips> {
970 // NOTE: If you add any additional spellings, ARMInterrupt's,
971 // MSP430Interrupt's and AnyX86Interrupt's spellings must match.
972 let Spellings = [GNU<"interrupt">];
973 let Subjects = SubjectList<[Function]>;
974 let Args = [EnumArgument<"Interrupt", "InterruptType",
975 ["vector=sw0", "vector=sw1", "vector=hw0",
976 "vector=hw1", "vector=hw2", "vector=hw3",
977 "vector=hw4", "vector=hw5", "eic", ""],
978 ["sw0", "sw1", "hw0", "hw1", "hw2", "hw3",
979 "hw4", "hw5", "eic", "eic"]
981 let ParseKind = "Interrupt";
982 let Documentation = [MipsInterruptDocs];
986 let Spellings = [GCC<"mode">];
987 let Subjects = SubjectList<[Var, Enum, TypedefName, Field], ErrorDiag,
988 "ExpectedVariableEnumFieldOrTypedef">;
989 let Args = [IdentifierArgument<"Mode">];
990 let Documentation = [Undocumented];
993 def Naked : InheritableAttr {
994 let Spellings = [GCC<"naked">, Declspec<"naked">];
995 let Subjects = SubjectList<[Function]>;
996 let Documentation = [Undocumented];
999 def NeonPolyVectorType : TypeAttr {
1000 let Spellings = [GNU<"neon_polyvector_type">];
1001 let Args = [IntArgument<"NumElements">];
1002 let Documentation = [Undocumented];
1005 def NeonVectorType : TypeAttr {
1006 let Spellings = [GNU<"neon_vector_type">];
1007 let Args = [IntArgument<"NumElements">];
1008 let Documentation = [Undocumented];
1011 def ReturnsTwice : InheritableAttr {
1012 let Spellings = [GCC<"returns_twice">];
1013 let Subjects = SubjectList<[Function]>;
1014 let Documentation = [Undocumented];
1017 def DisableTailCalls : InheritableAttr {
1018 let Spellings = [GNU<"disable_tail_calls">,
1019 CXX11<"clang", "disable_tail_calls">];
1020 let Subjects = SubjectList<[Function, ObjCMethod]>;
1021 let Documentation = [DisableTailCallsDocs];
1024 def NoAlias : InheritableAttr {
1025 let Spellings = [Declspec<"noalias">];
1026 let Subjects = SubjectList<[Function]>;
1027 let Documentation = [NoAliasDocs];
1030 def NoCommon : InheritableAttr {
1031 let Spellings = [GCC<"nocommon">];
1032 let Subjects = SubjectList<[Var]>;
1033 let Documentation = [Undocumented];
1036 def NoDebug : InheritableAttr {
1037 let Spellings = [GCC<"nodebug">];
1038 let Subjects = SubjectList<[FunctionLike, ObjCMethod, NonParmVar], WarnDiag,
1039 "ExpectedVariableOrFunction">;
1040 let Documentation = [NoDebugDocs];
1043 def NoDuplicate : InheritableAttr {
1044 let Spellings = [GNU<"noduplicate">, CXX11<"clang", "noduplicate">];
1045 let Subjects = SubjectList<[Function]>;
1046 let Documentation = [NoDuplicateDocs];
1049 def Convergent : InheritableAttr {
1050 let Spellings = [GNU<"convergent">, CXX11<"clang", "convergent">];
1051 let Subjects = SubjectList<[Function]>;
1052 let Documentation = [ConvergentDocs];
1055 def NoInline : InheritableAttr {
1056 let Spellings = [GCC<"noinline">, Declspec<"noinline">];
1057 let Subjects = SubjectList<[Function]>;
1058 let Documentation = [Undocumented];
1061 def NoMips16 : InheritableAttr, TargetSpecificAttr<TargetMips> {
1062 let Spellings = [GCC<"nomips16">];
1063 let Subjects = SubjectList<[Function], ErrorDiag>;
1064 let Documentation = [Undocumented];
1067 // This is not a TargetSpecificAttr so that is silently accepted and
1068 // ignored on other targets as encouraged by the OpenCL spec.
1070 // See OpenCL 1.2 6.11.5: "It is our intention that a particular
1071 // implementation of OpenCL be free to ignore all attributes and the
1072 // resulting executable binary will produce the same result."
1074 // However, only AMD GPU targets will emit the corresponding IR
1077 // FIXME: This provides a sub-optimal error message if you attempt to
1078 // use this in CUDA, since CUDA does not use the same terminology.
1080 // FIXME: SubjectList should be for OpenCLKernelFunction, but is not to
1081 // workaround needing to see kernel attribute before others to know if
1082 // this should be rejected on non-kernels.
1084 def AMDGPUFlatWorkGroupSize : InheritableAttr {
1085 let Spellings = [GNU<"amdgpu_flat_work_group_size">];
1086 let Args = [UnsignedArgument<"Min">, UnsignedArgument<"Max">];
1087 let Documentation = [AMDGPUFlatWorkGroupSizeDocs];
1088 let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1091 def AMDGPUWavesPerEU : InheritableAttr {
1092 let Spellings = [GNU<"amdgpu_waves_per_eu">];
1093 let Args = [UnsignedArgument<"Min">, UnsignedArgument<"Max", 1>];
1094 let Documentation = [AMDGPUWavesPerEUDocs];
1095 let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1098 def AMDGPUNumSGPR : InheritableAttr {
1099 let Spellings = [GNU<"amdgpu_num_sgpr">];
1100 let Args = [UnsignedArgument<"NumSGPR">];
1101 let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1102 let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1105 def AMDGPUNumVGPR : InheritableAttr {
1106 let Spellings = [GNU<"amdgpu_num_vgpr">];
1107 let Args = [UnsignedArgument<"NumVGPR">];
1108 let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1109 let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1112 def NoSplitStack : InheritableAttr {
1113 let Spellings = [GCC<"no_split_stack">];
1114 let Subjects = SubjectList<[Function], ErrorDiag>;
1115 let Documentation = [NoSplitStackDocs];
1118 def NonNull : InheritableAttr {
1119 let Spellings = [GCC<"nonnull">];
1120 let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
1121 "ExpectedFunctionMethodOrParameter">;
1122 let Args = [VariadicUnsignedArgument<"Args">];
1123 let AdditionalMembers =
1124 [{bool isNonNull(unsigned idx) const {
1127 for (const auto &V : args())
1132 // FIXME: We should merge duplicates into a single nonnull attribute.
1133 let DuplicatesAllowedWhileMerging = 1;
1134 let Documentation = [NonNullDocs];
1137 def ReturnsNonNull : InheritableAttr {
1138 let Spellings = [GCC<"returns_nonnull">];
1139 let Subjects = SubjectList<[ObjCMethod, Function], WarnDiag,
1140 "ExpectedFunctionOrMethod">;
1141 let Documentation = [ReturnsNonNullDocs];
1144 // pass_object_size(N) indicates that the parameter should have
1145 // __builtin_object_size with Type=N evaluated on the parameter at the callsite.
1146 def PassObjectSize : InheritableParamAttr {
1147 let Spellings = [GNU<"pass_object_size">];
1148 let Args = [IntArgument<"Type">];
1149 let Subjects = SubjectList<[ParmVar]>;
1150 let Documentation = [PassObjectSizeDocs];
1153 // Nullability type attributes.
1154 def TypeNonNull : TypeAttr {
1155 let Spellings = [Keyword<"_Nonnull">];
1156 let Documentation = [TypeNonNullDocs];
1159 def TypeNullable : TypeAttr {
1160 let Spellings = [Keyword<"_Nullable">];
1161 let Documentation = [TypeNullableDocs];
1164 def TypeNullUnspecified : TypeAttr {
1165 let Spellings = [Keyword<"_Null_unspecified">];
1166 let Documentation = [TypeNullUnspecifiedDocs];
1169 def ObjCKindOf : TypeAttr {
1170 let Spellings = [Keyword<"__kindof">];
1171 let Documentation = [Undocumented];
1174 def AssumeAligned : InheritableAttr {
1175 let Spellings = [GCC<"assume_aligned">];
1176 let Subjects = SubjectList<[ObjCMethod, Function]>;
1177 let Args = [ExprArgument<"Alignment">, ExprArgument<"Offset", 1>];
1178 let Documentation = [AssumeAlignedDocs];
1181 def NoReturn : InheritableAttr {
1182 let Spellings = [GCC<"noreturn">, Declspec<"noreturn">];
1183 // FIXME: Does GCC allow this on the function instead?
1184 let Documentation = [Undocumented];
1187 def NoInstrumentFunction : InheritableAttr {
1188 let Spellings = [GCC<"no_instrument_function">];
1189 let Subjects = SubjectList<[Function]>;
1190 let Documentation = [Undocumented];
1193 def NotTailCalled : InheritableAttr {
1194 let Spellings = [GNU<"not_tail_called">, CXX11<"clang", "not_tail_called">];
1195 let Subjects = SubjectList<[Function]>;
1196 let Documentation = [NotTailCalledDocs];
1199 def NoThrow : InheritableAttr {
1200 let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
1201 let Documentation = [Undocumented];
1204 def NvWeak : IgnoredAttr {
1205 // No Declspec spelling of this attribute; the CUDA headers use
1206 // __attribute__((nv_weak)) unconditionally.
1207 let Spellings = [GNU<"nv_weak">];
1208 let LangOpts = [CUDA];
1211 def ObjCBridge : InheritableAttr {
1212 let Spellings = [GNU<"objc_bridge">];
1213 let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
1214 "ExpectedStructOrUnionOrTypedef">;
1215 let Args = [IdentifierArgument<"BridgedType">];
1216 let Documentation = [Undocumented];
1219 def ObjCBridgeMutable : InheritableAttr {
1220 let Spellings = [GNU<"objc_bridge_mutable">];
1221 let Subjects = SubjectList<[Record], ErrorDiag>;
1222 let Args = [IdentifierArgument<"BridgedType">];
1223 let Documentation = [Undocumented];
1226 def ObjCBridgeRelated : InheritableAttr {
1227 let Spellings = [GNU<"objc_bridge_related">];
1228 let Subjects = SubjectList<[Record], ErrorDiag>;
1229 let Args = [IdentifierArgument<"RelatedClass">,
1230 IdentifierArgument<"ClassMethod", 1>,
1231 IdentifierArgument<"InstanceMethod", 1>];
1232 let HasCustomParsing = 1;
1233 let Documentation = [Undocumented];
1236 def NSReturnsRetained : InheritableAttr {
1237 let Spellings = [GNU<"ns_returns_retained">];
1238 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1239 let Documentation = [Undocumented];
1242 def NSReturnsNotRetained : InheritableAttr {
1243 let Spellings = [GNU<"ns_returns_not_retained">];
1244 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1245 let Documentation = [Undocumented];
1248 def NSReturnsAutoreleased : InheritableAttr {
1249 let Spellings = [GNU<"ns_returns_autoreleased">];
1250 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1251 let Documentation = [Undocumented];
1254 def NSConsumesSelf : InheritableAttr {
1255 let Spellings = [GNU<"ns_consumes_self">];
1256 let Subjects = SubjectList<[ObjCMethod]>;
1257 let Documentation = [Undocumented];
1260 def NSConsumed : InheritableParamAttr {
1261 let Spellings = [GNU<"ns_consumed">];
1262 let Subjects = SubjectList<[ParmVar]>;
1263 let Documentation = [Undocumented];
1266 def ObjCException : InheritableAttr {
1267 let Spellings = [GNU<"objc_exception">];
1268 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1269 let Documentation = [Undocumented];
1272 def ObjCMethodFamily : InheritableAttr {
1273 let Spellings = [GNU<"objc_method_family">];
1274 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1275 let Args = [EnumArgument<"Family", "FamilyKind",
1276 ["none", "alloc", "copy", "init", "mutableCopy", "new"],
1277 ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
1278 "OMF_mutableCopy", "OMF_new"]>];
1279 let Documentation = [ObjCMethodFamilyDocs];
1282 def ObjCNSObject : InheritableAttr {
1283 let Spellings = [GNU<"NSObject">];
1284 let Documentation = [Undocumented];
1287 def ObjCIndependentClass : InheritableAttr {
1288 let Spellings = [GNU<"objc_independent_class">];
1289 let Documentation = [Undocumented];
1292 def ObjCPreciseLifetime : InheritableAttr {
1293 let Spellings = [GNU<"objc_precise_lifetime">];
1294 let Subjects = SubjectList<[Var], ErrorDiag>;
1295 let Documentation = [Undocumented];
1298 def ObjCReturnsInnerPointer : InheritableAttr {
1299 let Spellings = [GNU<"objc_returns_inner_pointer">];
1300 let Subjects = SubjectList<[ObjCMethod, ObjCProperty], ErrorDiag>;
1301 let Documentation = [Undocumented];
1304 def ObjCRequiresSuper : InheritableAttr {
1305 let Spellings = [GNU<"objc_requires_super">];
1306 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1307 let Documentation = [ObjCRequiresSuperDocs];
1310 def ObjCRootClass : InheritableAttr {
1311 let Spellings = [GNU<"objc_root_class">];
1312 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1313 let Documentation = [Undocumented];
1316 def ObjCSubclassingRestricted : InheritableAttr {
1317 let Spellings = [GNU<"objc_subclassing_restricted">];
1318 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1319 let Documentation = [ObjCSubclassingRestrictedDocs];
1322 def ObjCExplicitProtocolImpl : InheritableAttr {
1323 let Spellings = [GNU<"objc_protocol_requires_explicit_implementation">];
1324 let Subjects = SubjectList<[ObjCProtocol], ErrorDiag>;
1325 let Documentation = [Undocumented];
1328 def ObjCDesignatedInitializer : Attr {
1329 let Spellings = [GNU<"objc_designated_initializer">];
1330 let Subjects = SubjectList<[ObjCInterfaceDeclInitMethod], ErrorDiag,
1331 "ExpectedObjCInterfaceDeclInitMethod">;
1332 let Documentation = [Undocumented];
1335 def ObjCRuntimeName : Attr {
1336 let Spellings = [GNU<"objc_runtime_name">];
1337 let Subjects = SubjectList<[ObjCInterface, ObjCProtocol], ErrorDiag>;
1338 let Args = [StringArgument<"MetadataName">];
1339 let Documentation = [ObjCRuntimeNameDocs];
1342 def ObjCRuntimeVisible : Attr {
1343 let Spellings = [GNU<"objc_runtime_visible">];
1344 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1345 let Documentation = [ObjCRuntimeVisibleDocs];
1348 def ObjCBoxable : Attr {
1349 let Spellings = [GNU<"objc_boxable">];
1350 let Subjects = SubjectList<[Record], ErrorDiag, "ExpectedStructOrUnion">;
1351 let Documentation = [ObjCBoxableDocs];
1354 def OptimizeNone : InheritableAttr {
1355 let Spellings = [GNU<"optnone">, CXX11<"clang", "optnone">];
1356 let Subjects = SubjectList<[Function, ObjCMethod]>;
1357 let Documentation = [OptnoneDocs];
1360 def Overloadable : Attr {
1361 let Spellings = [GNU<"overloadable">];
1362 let Subjects = SubjectList<[Function], ErrorDiag>;
1363 let Documentation = [OverloadableDocs];
1366 def Override : InheritableAttr {
1367 let Spellings = [Keyword<"override">];
1368 let SemaHandler = 0;
1369 let Documentation = [Undocumented];
1372 def Ownership : InheritableAttr {
1373 let Spellings = [GNU<"ownership_holds">, GNU<"ownership_returns">,
1374 GNU<"ownership_takes">];
1375 let Accessors = [Accessor<"isHolds", [GNU<"ownership_holds">]>,
1376 Accessor<"isReturns", [GNU<"ownership_returns">]>,
1377 Accessor<"isTakes", [GNU<"ownership_takes">]>];
1378 let AdditionalMembers = [{
1379 enum OwnershipKind { Holds, Returns, Takes };
1380 OwnershipKind getOwnKind() const {
1381 return isHolds() ? Holds :
1386 let Args = [IdentifierArgument<"Module">, VariadicUnsignedArgument<"Args">];
1387 let Subjects = SubjectList<[HasFunctionProto], WarnDiag,
1388 "ExpectedFunctionWithProtoType">;
1389 let Documentation = [Undocumented];
1392 def Packed : InheritableAttr {
1393 let Spellings = [GCC<"packed">];
1394 // let Subjects = [Tag, Field];
1395 let Documentation = [Undocumented];
1398 def IntelOclBicc : InheritableAttr {
1399 let Spellings = [GNU<"intel_ocl_bicc">];
1400 // let Subjects = [Function, ObjCMethod];
1401 let Documentation = [Undocumented];
1404 def Pcs : InheritableAttr {
1405 let Spellings = [GCC<"pcs">];
1406 let Args = [EnumArgument<"PCS", "PCSType",
1407 ["aapcs", "aapcs-vfp"],
1408 ["AAPCS", "AAPCS_VFP"]>];
1409 // let Subjects = [Function, ObjCMethod];
1410 let Documentation = [PcsDocs];
1413 def Pure : InheritableAttr {
1414 let Spellings = [GCC<"pure">];
1415 let Documentation = [Undocumented];
1418 def Regparm : TypeAttr {
1419 let Spellings = [GCC<"regparm">];
1420 let Args = [UnsignedArgument<"NumParams">];
1421 let Documentation = [RegparmDocs];
1424 def ReqdWorkGroupSize : InheritableAttr {
1425 let Spellings = [GNU<"reqd_work_group_size">];
1426 let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
1427 UnsignedArgument<"ZDim">];
1428 let Subjects = SubjectList<[Function], ErrorDiag>;
1429 let Documentation = [Undocumented];
1432 def RequireConstantInit : InheritableAttr {
1433 let Spellings = [GNU<"require_constant_initialization">,
1434 CXX11<"clang", "require_constant_initialization">];
1435 let Subjects = SubjectList<[GlobalVar], ErrorDiag,
1436 "ExpectedStaticOrTLSVar">;
1437 let Documentation = [RequireConstantInitDocs];
1438 let LangOpts = [CPlusPlus];
1441 def WorkGroupSizeHint : InheritableAttr {
1442 let Spellings = [GNU<"work_group_size_hint">];
1443 let Args = [UnsignedArgument<"XDim">,
1444 UnsignedArgument<"YDim">,
1445 UnsignedArgument<"ZDim">];
1446 let Subjects = SubjectList<[Function], ErrorDiag>;
1447 let Documentation = [Undocumented];
1450 def InitPriority : InheritableAttr {
1451 let Spellings = [GNU<"init_priority">];
1452 let Args = [UnsignedArgument<"Priority">];
1453 let Subjects = SubjectList<[Var], ErrorDiag>;
1454 let Documentation = [Undocumented];
1457 def Section : InheritableAttr {
1458 let Spellings = [GCC<"section">, Declspec<"allocate">];
1459 let Args = [StringArgument<"Name">];
1460 let Subjects = SubjectList<[Function, GlobalVar,
1461 ObjCMethod, ObjCProperty], ErrorDiag,
1462 "ExpectedFunctionGlobalVarMethodOrProperty">;
1463 let Documentation = [SectionDocs];
1466 def Sentinel : InheritableAttr {
1467 let Spellings = [GCC<"sentinel">];
1468 let Args = [DefaultIntArgument<"Sentinel", 0>,
1469 DefaultIntArgument<"NullPos", 0>];
1470 // let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>;
1471 let Documentation = [Undocumented];
1474 def StdCall : InheritableAttr {
1475 let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
1476 // let Subjects = [Function, ObjCMethod];
1477 let Documentation = [StdCallDocs];
1480 def SwiftCall : InheritableAttr {
1481 let Spellings = [GCC<"swiftcall">];
1482 // let Subjects = SubjectList<[Function]>;
1483 let Documentation = [SwiftCallDocs];
1486 def SwiftContext : ParameterABIAttr {
1487 let Spellings = [GCC<"swift_context">];
1488 let Documentation = [SwiftContextDocs];
1491 def SwiftErrorResult : ParameterABIAttr {
1492 let Spellings = [GCC<"swift_error_result">];
1493 let Documentation = [SwiftErrorResultDocs];
1496 def SwiftIndirectResult : ParameterABIAttr {
1497 let Spellings = [GCC<"swift_indirect_result">];
1498 let Documentation = [SwiftIndirectResultDocs];
1501 def SysVABI : InheritableAttr {
1502 let Spellings = [GCC<"sysv_abi">];
1503 // let Subjects = [Function, ObjCMethod];
1504 let Documentation = [Undocumented];
1507 def ThisCall : InheritableAttr {
1508 let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
1509 Keyword<"_thiscall">];
1510 // let Subjects = [Function, ObjCMethod];
1511 let Documentation = [ThisCallDocs];
1514 def VectorCall : InheritableAttr {
1515 let Spellings = [GNU<"vectorcall">, Keyword<"__vectorcall">,
1516 Keyword<"_vectorcall">];
1517 // let Subjects = [Function, ObjCMethod];
1518 let Documentation = [VectorCallDocs];
1521 def Pascal : InheritableAttr {
1522 let Spellings = [GNU<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
1523 // let Subjects = [Function, ObjCMethod];
1524 let Documentation = [Undocumented];
1527 def PreserveMost : InheritableAttr {
1528 let Spellings = [GNU<"preserve_most">];
1529 let Documentation = [PreserveMostDocs];
1532 def PreserveAll : InheritableAttr {
1533 let Spellings = [GNU<"preserve_all">];
1534 let Documentation = [PreserveAllDocs];
1537 def Target : InheritableAttr {
1538 let Spellings = [GCC<"target">];
1539 let Args = [StringArgument<"featuresStr">];
1540 let Subjects = SubjectList<[Function], ErrorDiag>;
1541 let Documentation = [TargetDocs];
1542 let AdditionalMembers = [{
1543 typedef std::pair<std::vector<std::string>, StringRef> ParsedTargetAttr;
1544 ParsedTargetAttr parse() const {
1545 ParsedTargetAttr Ret;
1546 SmallVector<StringRef, 1> AttrFeatures;
1547 getFeaturesStr().split(AttrFeatures, ",");
1549 // Grab the various features and prepend a "+" to turn on the feature to
1550 // the backend and add them to our existing set of features.
1551 for (auto &Feature : AttrFeatures) {
1552 // Go ahead and trim whitespace rather than either erroring or
1553 // accepting it weirdly.
1554 Feature = Feature.trim();
1556 // We don't support cpu tuning this way currently.
1557 // TODO: Support the fpmath option. It will require checking
1558 // overall feature validity for the function with the rest of the
1559 // attributes on the function.
1560 if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
1563 // While we're here iterating check for a different target cpu.
1564 if (Feature.startswith("arch="))
1565 Ret.second = Feature.split("=").second.trim();
1566 else if (Feature.startswith("no-"))
1567 Ret.first.push_back("-" + Feature.split("-").second.str());
1569 Ret.first.push_back("+" + Feature.str());
1576 def TransparentUnion : InheritableAttr {
1577 let Spellings = [GCC<"transparent_union">];
1578 // let Subjects = SubjectList<[Record, TypedefName]>;
1579 let Documentation = [TransparentUnionDocs];
1580 let LangOpts = [COnly];
1583 def Unavailable : InheritableAttr {
1584 let Spellings = [GNU<"unavailable">];
1585 let Args = [StringArgument<"Message", 1>,
1586 EnumArgument<"ImplicitReason", "ImplicitReason",
1589 "IR_ARCForbiddenType",
1591 "IR_ARCForbiddenConversion",
1592 "IR_ARCInitReturnsUnrelated",
1593 "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
1594 let Documentation = [Undocumented];
1597 def DiagnoseIf : InheritableAttr {
1598 let Spellings = [GNU<"diagnose_if">];
1599 let Subjects = SubjectList<[Function]>;
1600 let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
1601 EnumArgument<"DiagnosticType",
1603 ["error", "warning"],
1604 ["DT_Error", "DT_Warning"]>,
1605 BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
1606 FunctionArgument<"Parent", 0, /*fake*/ 1>];
1607 let DuplicatesAllowedWhileMerging = 1;
1609 let AdditionalMembers = [{
1610 bool isError() const { return diagnosticType == DT_Error; }
1611 bool isWarning() const { return diagnosticType == DT_Warning; }
1613 let TemplateDependent = 1;
1614 let Documentation = [DiagnoseIfDocs];
1617 def ArcWeakrefUnavailable : InheritableAttr {
1618 let Spellings = [GNU<"objc_arc_weak_reference_unavailable">];
1619 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1620 let Documentation = [Undocumented];
1623 def ObjCGC : TypeAttr {
1624 let Spellings = [GNU<"objc_gc">];
1625 let Args = [IdentifierArgument<"Kind">];
1626 let Documentation = [Undocumented];
1629 def ObjCOwnership : InheritableAttr {
1630 let Spellings = [GNU<"objc_ownership">];
1631 let Args = [IdentifierArgument<"Kind">];
1633 let Documentation = [Undocumented];
1636 def ObjCRequiresPropertyDefs : InheritableAttr {
1637 let Spellings = [GNU<"objc_requires_property_definitions">];
1638 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1639 let Documentation = [Undocumented];
1642 def Unused : InheritableAttr {
1643 let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">];
1644 let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
1645 Field, ObjCMethod, FunctionLike], WarnDiag,
1646 "ExpectedForMaybeUnused">;
1647 let Documentation = [WarnMaybeUnusedDocs];
1650 def Used : InheritableAttr {
1651 let Spellings = [GCC<"used">];
1652 let Documentation = [Undocumented];
1655 def Uuid : InheritableAttr {
1656 let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
1657 let Args = [StringArgument<"Guid">];
1658 let Subjects = SubjectList<[Record, Enum], WarnDiag, "ExpectedEnumOrClass">;
1659 // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
1660 // CPlusPlus && (MicrosoftExt || Borland)
1661 let LangOpts = [MicrosoftExt, Borland];
1662 let Documentation = [Undocumented];
1665 def VectorSize : TypeAttr {
1666 let Spellings = [GCC<"vector_size">];
1667 let Args = [ExprArgument<"NumBytes">];
1668 let Documentation = [Undocumented];
1671 def VecTypeHint : InheritableAttr {
1672 let Spellings = [GNU<"vec_type_hint">];
1673 let Args = [TypeArgument<"TypeHint">];
1674 let Subjects = SubjectList<[Function], ErrorDiag>;
1675 let Documentation = [Undocumented];
1678 def Visibility : InheritableAttr {
1680 let Spellings = [GCC<"visibility">];
1681 let Args = [EnumArgument<"Visibility", "VisibilityType",
1682 ["default", "hidden", "internal", "protected"],
1683 ["Default", "Hidden", "Hidden", "Protected"]>];
1684 let Documentation = [Undocumented];
1687 def TypeVisibility : InheritableAttr {
1689 let Spellings = [GNU<"type_visibility">, CXX11<"clang", "type_visibility">];
1690 let Args = [EnumArgument<"Visibility", "VisibilityType",
1691 ["default", "hidden", "internal", "protected"],
1692 ["Default", "Hidden", "Hidden", "Protected"]>];
1693 // let Subjects = [Tag, ObjCInterface, Namespace];
1694 let Documentation = [Undocumented];
1697 def VecReturn : InheritableAttr {
1698 let Spellings = [GNU<"vecreturn">];
1699 let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
1700 let Documentation = [Undocumented];
1703 def WarnUnused : InheritableAttr {
1704 let Spellings = [GNU<"warn_unused">];
1705 let Subjects = SubjectList<[Record]>;
1706 let Documentation = [Undocumented];
1709 def WarnUnusedResult : InheritableAttr {
1710 let Spellings = [CXX11<"", "nodiscard", 201603>,
1711 CXX11<"clang", "warn_unused_result">,
1712 GCC<"warn_unused_result">];
1713 let Subjects = SubjectList<[ObjCMethod, Enum, CXXRecord, FunctionLike],
1714 WarnDiag, "ExpectedFunctionMethodEnumOrClass">;
1715 let Documentation = [WarnUnusedResultsDocs];
1718 def Weak : InheritableAttr {
1719 let Spellings = [GCC<"weak">];
1720 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
1721 let Documentation = [Undocumented];
1724 def WeakImport : InheritableAttr {
1725 let Spellings = [GNU<"weak_import">];
1726 let Documentation = [Undocumented];
1729 def WeakRef : InheritableAttr {
1730 let Spellings = [GCC<"weakref">];
1731 // A WeakRef that has an argument is treated as being an AliasAttr
1732 let Args = [StringArgument<"Aliasee", 1>];
1733 let Subjects = SubjectList<[Var, Function], ErrorDiag>;
1734 let Documentation = [Undocumented];
1737 def LTOVisibilityPublic : InheritableAttr {
1738 let Spellings = [CXX11<"clang", "lto_visibility_public">];
1739 let Subjects = SubjectList<[Record]>;
1740 let Documentation = [LTOVisibilityDocs];
1743 def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
1744 // NOTE: If you add any additional spellings, ARMInterrupt's,
1745 // MSP430Interrupt's and MipsInterrupt's spellings must match.
1746 let Spellings = [GNU<"interrupt">];
1747 let Subjects = SubjectList<[HasFunctionProto]>;
1748 let ParseKind = "Interrupt";
1749 let HasCustomParsing = 1;
1750 let Documentation = [AnyX86InterruptDocs];
1753 def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetX86> {
1754 let Spellings = [GNU<"force_align_arg_pointer">];
1755 // Technically, this appertains to a FunctionDecl, but the target-specific
1756 // code silently allows anything function-like (such as typedefs or function
1757 // pointers), but does not apply the attribute to them.
1758 let Documentation = [Undocumented];
1761 def NoSanitize : InheritableAttr {
1762 let Spellings = [GNU<"no_sanitize">, CXX11<"clang", "no_sanitize">];
1763 let Args = [VariadicStringArgument<"Sanitizers">];
1764 let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag,
1765 "ExpectedFunctionMethodOrGlobalVar">;
1766 let Documentation = [NoSanitizeDocs];
1767 let AdditionalMembers = [{
1768 SanitizerMask getMask() const {
1769 SanitizerMask Mask = 0;
1770 for (auto SanitizerName : sanitizers()) {
1771 SanitizerMask ParsedMask =
1772 parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
1773 Mask |= expandSanitizerGroups(ParsedMask);
1780 // Attributes to disable a specific sanitizer. No new sanitizers should be added
1781 // to this list; the no_sanitize attribute should be extended instead.
1782 def NoSanitizeSpecific : InheritableAttr {
1783 let Spellings = [GCC<"no_address_safety_analysis">,
1784 GCC<"no_sanitize_address">,
1785 GCC<"no_sanitize_thread">,
1786 GNU<"no_sanitize_memory">];
1787 let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
1788 "ExpectedFunctionOrGlobalVar">;
1789 let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
1790 NoSanitizeMemoryDocs];
1794 // C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
1796 def GuardedVar : InheritableAttr {
1797 let Spellings = [GNU<"guarded_var">];
1798 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1799 "ExpectedFieldOrGlobalVar">;
1800 let Documentation = [Undocumented];
1803 def PtGuardedVar : InheritableAttr {
1804 let Spellings = [GNU<"pt_guarded_var">];
1805 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1806 "ExpectedFieldOrGlobalVar">;
1807 let Documentation = [Undocumented];
1810 def Lockable : InheritableAttr {
1811 let Spellings = [GNU<"lockable">];
1812 let Subjects = SubjectList<[Record]>;
1813 let Documentation = [Undocumented];
1814 let ASTNode = 0; // Replaced by Capability
1817 def ScopedLockable : InheritableAttr {
1818 let Spellings = [GNU<"scoped_lockable">];
1819 let Subjects = SubjectList<[Record]>;
1820 let Documentation = [Undocumented];
1823 def Capability : InheritableAttr {
1824 let Spellings = [GNU<"capability">, CXX11<"clang", "capability">,
1825 GNU<"shared_capability">,
1826 CXX11<"clang", "shared_capability">];
1827 let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
1828 "ExpectedStructOrUnionOrTypedef">;
1829 let Args = [StringArgument<"Name">];
1830 let Accessors = [Accessor<"isShared",
1831 [GNU<"shared_capability">,
1832 CXX11<"clang","shared_capability">]>];
1833 let Documentation = [Undocumented];
1834 let AdditionalMembers = [{
1835 bool isMutex() const { return getName().equals_lower("mutex"); }
1836 bool isRole() const { return getName().equals_lower("role"); }
1840 def AssertCapability : InheritableAttr {
1841 let Spellings = [GNU<"assert_capability">,
1842 CXX11<"clang", "assert_capability">,
1843 GNU<"assert_shared_capability">,
1844 CXX11<"clang", "assert_shared_capability">];
1845 let Subjects = SubjectList<[Function]>;
1847 let TemplateDependent = 1;
1848 let ParseArgumentsAsUnevaluated = 1;
1849 let DuplicatesAllowedWhileMerging = 1;
1850 let Args = [ExprArgument<"Expr">];
1851 let Accessors = [Accessor<"isShared",
1852 [GNU<"assert_shared_capability">,
1853 CXX11<"clang", "assert_shared_capability">]>];
1854 let Documentation = [AssertCapabilityDocs];
1857 def AcquireCapability : InheritableAttr {
1858 let Spellings = [GNU<"acquire_capability">,
1859 CXX11<"clang", "acquire_capability">,
1860 GNU<"acquire_shared_capability">,
1861 CXX11<"clang", "acquire_shared_capability">,
1862 GNU<"exclusive_lock_function">,
1863 GNU<"shared_lock_function">];
1864 let Subjects = SubjectList<[Function]>;
1866 let TemplateDependent = 1;
1867 let ParseArgumentsAsUnevaluated = 1;
1868 let DuplicatesAllowedWhileMerging = 1;
1869 let Args = [VariadicExprArgument<"Args">];
1870 let Accessors = [Accessor<"isShared",
1871 [GNU<"acquire_shared_capability">,
1872 CXX11<"clang", "acquire_shared_capability">,
1873 GNU<"shared_lock_function">]>];
1874 let Documentation = [AcquireCapabilityDocs];
1877 def TryAcquireCapability : InheritableAttr {
1878 let Spellings = [GNU<"try_acquire_capability">,
1879 CXX11<"clang", "try_acquire_capability">,
1880 GNU<"try_acquire_shared_capability">,
1881 CXX11<"clang", "try_acquire_shared_capability">];
1882 let Subjects = SubjectList<[Function],
1885 let TemplateDependent = 1;
1886 let ParseArgumentsAsUnevaluated = 1;
1887 let DuplicatesAllowedWhileMerging = 1;
1888 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
1889 let Accessors = [Accessor<"isShared",
1890 [GNU<"try_acquire_shared_capability">,
1891 CXX11<"clang", "try_acquire_shared_capability">]>];
1892 let Documentation = [TryAcquireCapabilityDocs];
1895 def ReleaseCapability : InheritableAttr {
1896 let Spellings = [GNU<"release_capability">,
1897 CXX11<"clang", "release_capability">,
1898 GNU<"release_shared_capability">,
1899 CXX11<"clang", "release_shared_capability">,
1900 GNU<"release_generic_capability">,
1901 CXX11<"clang", "release_generic_capability">,
1902 GNU<"unlock_function">];
1903 let Subjects = SubjectList<[Function]>;
1905 let TemplateDependent = 1;
1906 let ParseArgumentsAsUnevaluated = 1;
1907 let DuplicatesAllowedWhileMerging = 1;
1908 let Args = [VariadicExprArgument<"Args">];
1909 let Accessors = [Accessor<"isShared",
1910 [GNU<"release_shared_capability">,
1911 CXX11<"clang", "release_shared_capability">]>,
1912 Accessor<"isGeneric",
1913 [GNU<"release_generic_capability">,
1914 CXX11<"clang", "release_generic_capability">,
1915 GNU<"unlock_function">]>];
1916 let Documentation = [ReleaseCapabilityDocs];
1919 def RequiresCapability : InheritableAttr {
1920 let Spellings = [GNU<"requires_capability">,
1921 CXX11<"clang", "requires_capability">,
1922 GNU<"exclusive_locks_required">,
1923 GNU<"requires_shared_capability">,
1924 CXX11<"clang", "requires_shared_capability">,
1925 GNU<"shared_locks_required">];
1926 let Args = [VariadicExprArgument<"Args">];
1928 let TemplateDependent = 1;
1929 let ParseArgumentsAsUnevaluated = 1;
1930 let DuplicatesAllowedWhileMerging = 1;
1931 let Subjects = SubjectList<[Function]>;
1932 let Accessors = [Accessor<"isShared", [GNU<"requires_shared_capability">,
1933 GNU<"shared_locks_required">,
1934 CXX11<"clang","requires_shared_capability">]>];
1935 let Documentation = [Undocumented];
1938 def NoThreadSafetyAnalysis : InheritableAttr {
1939 let Spellings = [GNU<"no_thread_safety_analysis">];
1940 let Subjects = SubjectList<[Function]>;
1941 let Documentation = [Undocumented];
1944 def GuardedBy : InheritableAttr {
1945 let Spellings = [GNU<"guarded_by">];
1946 let Args = [ExprArgument<"Arg">];
1948 let TemplateDependent = 1;
1949 let ParseArgumentsAsUnevaluated = 1;
1950 let DuplicatesAllowedWhileMerging = 1;
1951 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1952 "ExpectedFieldOrGlobalVar">;
1953 let Documentation = [Undocumented];
1956 def PtGuardedBy : InheritableAttr {
1957 let Spellings = [GNU<"pt_guarded_by">];
1958 let Args = [ExprArgument<"Arg">];
1960 let TemplateDependent = 1;
1961 let ParseArgumentsAsUnevaluated = 1;
1962 let DuplicatesAllowedWhileMerging = 1;
1963 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1964 "ExpectedFieldOrGlobalVar">;
1965 let Documentation = [Undocumented];
1968 def AcquiredAfter : InheritableAttr {
1969 let Spellings = [GNU<"acquired_after">];
1970 let Args = [VariadicExprArgument<"Args">];
1972 let TemplateDependent = 1;
1973 let ParseArgumentsAsUnevaluated = 1;
1974 let DuplicatesAllowedWhileMerging = 1;
1975 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1976 "ExpectedFieldOrGlobalVar">;
1977 let Documentation = [Undocumented];
1980 def AcquiredBefore : InheritableAttr {
1981 let Spellings = [GNU<"acquired_before">];
1982 let Args = [VariadicExprArgument<"Args">];
1984 let TemplateDependent = 1;
1985 let ParseArgumentsAsUnevaluated = 1;
1986 let DuplicatesAllowedWhileMerging = 1;
1987 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1988 "ExpectedFieldOrGlobalVar">;
1989 let Documentation = [Undocumented];
1992 def AssertExclusiveLock : InheritableAttr {
1993 let Spellings = [GNU<"assert_exclusive_lock">];
1994 let Args = [VariadicExprArgument<"Args">];
1996 let TemplateDependent = 1;
1997 let ParseArgumentsAsUnevaluated = 1;
1998 let DuplicatesAllowedWhileMerging = 1;
1999 let Subjects = SubjectList<[Function]>;
2000 let Documentation = [Undocumented];
2003 def AssertSharedLock : InheritableAttr {
2004 let Spellings = [GNU<"assert_shared_lock">];
2005 let Args = [VariadicExprArgument<"Args">];
2007 let TemplateDependent = 1;
2008 let ParseArgumentsAsUnevaluated = 1;
2009 let DuplicatesAllowedWhileMerging = 1;
2010 let Subjects = SubjectList<[Function]>;
2011 let Documentation = [Undocumented];
2014 // The first argument is an integer or boolean value specifying the return value
2015 // of a successful lock acquisition.
2016 def ExclusiveTrylockFunction : InheritableAttr {
2017 let Spellings = [GNU<"exclusive_trylock_function">];
2018 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2020 let TemplateDependent = 1;
2021 let ParseArgumentsAsUnevaluated = 1;
2022 let DuplicatesAllowedWhileMerging = 1;
2023 let Subjects = SubjectList<[Function]>;
2024 let Documentation = [Undocumented];
2027 // The first argument is an integer or boolean value specifying the return value
2028 // of a successful lock acquisition.
2029 def SharedTrylockFunction : InheritableAttr {
2030 let Spellings = [GNU<"shared_trylock_function">];
2031 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2033 let TemplateDependent = 1;
2034 let ParseArgumentsAsUnevaluated = 1;
2035 let DuplicatesAllowedWhileMerging = 1;
2036 let Subjects = SubjectList<[Function]>;
2037 let Documentation = [Undocumented];
2040 def LockReturned : InheritableAttr {
2041 let Spellings = [GNU<"lock_returned">];
2042 let Args = [ExprArgument<"Arg">];
2044 let TemplateDependent = 1;
2045 let ParseArgumentsAsUnevaluated = 1;
2046 let Subjects = SubjectList<[Function]>;
2047 let Documentation = [Undocumented];
2050 def LocksExcluded : InheritableAttr {
2051 let Spellings = [GNU<"locks_excluded">];
2052 let Args = [VariadicExprArgument<"Args">];
2054 let TemplateDependent = 1;
2055 let ParseArgumentsAsUnevaluated = 1;
2056 let DuplicatesAllowedWhileMerging = 1;
2057 let Subjects = SubjectList<[Function]>;
2058 let Documentation = [Undocumented];
2061 // C/C++ consumed attributes.
2063 def Consumable : InheritableAttr {
2064 let Spellings = [GNU<"consumable">];
2065 let Subjects = SubjectList<[CXXRecord]>;
2066 let Args = [EnumArgument<"DefaultState", "ConsumedState",
2067 ["unknown", "consumed", "unconsumed"],
2068 ["Unknown", "Consumed", "Unconsumed"]>];
2069 let Documentation = [ConsumableDocs];
2072 def ConsumableAutoCast : InheritableAttr {
2073 let Spellings = [GNU<"consumable_auto_cast_state">];
2074 let Subjects = SubjectList<[CXXRecord]>;
2075 let Documentation = [Undocumented];
2078 def ConsumableSetOnRead : InheritableAttr {
2079 let Spellings = [GNU<"consumable_set_state_on_read">];
2080 let Subjects = SubjectList<[CXXRecord]>;
2081 let Documentation = [Undocumented];
2084 def CallableWhen : InheritableAttr {
2085 let Spellings = [GNU<"callable_when">];
2086 let Subjects = SubjectList<[CXXMethod]>;
2087 let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
2088 ["unknown", "consumed", "unconsumed"],
2089 ["Unknown", "Consumed", "Unconsumed"]>];
2090 let Documentation = [CallableWhenDocs];
2093 def ParamTypestate : InheritableAttr {
2094 let Spellings = [GNU<"param_typestate">];
2095 let Subjects = SubjectList<[ParmVar]>;
2096 let Args = [EnumArgument<"ParamState", "ConsumedState",
2097 ["unknown", "consumed", "unconsumed"],
2098 ["Unknown", "Consumed", "Unconsumed"]>];
2099 let Documentation = [ParamTypestateDocs];
2102 def ReturnTypestate : InheritableAttr {
2103 let Spellings = [GNU<"return_typestate">];
2104 let Subjects = SubjectList<[Function, ParmVar]>;
2105 let Args = [EnumArgument<"State", "ConsumedState",
2106 ["unknown", "consumed", "unconsumed"],
2107 ["Unknown", "Consumed", "Unconsumed"]>];
2108 let Documentation = [ReturnTypestateDocs];
2111 def SetTypestate : InheritableAttr {
2112 let Spellings = [GNU<"set_typestate">];
2113 let Subjects = SubjectList<[CXXMethod]>;
2114 let Args = [EnumArgument<"NewState", "ConsumedState",
2115 ["unknown", "consumed", "unconsumed"],
2116 ["Unknown", "Consumed", "Unconsumed"]>];
2117 let Documentation = [SetTypestateDocs];
2120 def TestTypestate : InheritableAttr {
2121 let Spellings = [GNU<"test_typestate">];
2122 let Subjects = SubjectList<[CXXMethod]>;
2123 let Args = [EnumArgument<"TestState", "ConsumedState",
2124 ["consumed", "unconsumed"],
2125 ["Consumed", "Unconsumed"]>];
2126 let Documentation = [TestTypestateDocs];
2129 // Type safety attributes for `void *' pointers and type tags.
2131 def ArgumentWithTypeTag : InheritableAttr {
2132 let Spellings = [GNU<"argument_with_type_tag">,
2133 GNU<"pointer_with_type_tag">];
2134 let Args = [IdentifierArgument<"ArgumentKind">,
2135 UnsignedArgument<"ArgumentIdx">,
2136 UnsignedArgument<"TypeTagIdx">,
2137 BoolArgument<"IsPointer">];
2138 let HasCustomParsing = 1;
2139 let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
2142 def TypeTagForDatatype : InheritableAttr {
2143 let Spellings = [GNU<"type_tag_for_datatype">];
2144 let Args = [IdentifierArgument<"ArgumentKind">,
2145 TypeArgument<"MatchingCType">,
2146 BoolArgument<"LayoutCompatible">,
2147 BoolArgument<"MustBeNull">];
2148 // let Subjects = SubjectList<[Var], ErrorDiag>;
2149 let HasCustomParsing = 1;
2150 let Documentation = [TypeTagForDatatypeDocs];
2153 // Microsoft-related attributes
2155 def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
2156 let Spellings = [Declspec<"novtable">];
2157 let Subjects = SubjectList<[CXXRecord]>;
2158 let Documentation = [MSNoVTableDocs];
2162 let Spellings = [Declspec<"property">];
2165 def MSStruct : InheritableAttr {
2166 let Spellings = [GCC<"ms_struct">];
2167 let Subjects = SubjectList<[Record]>;
2168 let Documentation = [Undocumented];
2171 def DLLExport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2172 let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
2173 let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2174 let Documentation = [DLLExportDocs];
2177 def DLLImport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2178 let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
2179 let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2180 let Documentation = [DLLImportDocs];
2183 def SelectAny : InheritableAttr {
2184 let Spellings = [Declspec<"selectany">];
2185 let LangOpts = [MicrosoftExt];
2186 let Documentation = [Undocumented];
2190 let Spellings = [Declspec<"thread">];
2191 let LangOpts = [MicrosoftExt];
2192 let Documentation = [ThreadDocs];
2193 let Subjects = SubjectList<[Var]>;
2196 def Win64 : IgnoredAttr {
2197 let Spellings = [Keyword<"__w64">];
2198 let LangOpts = [MicrosoftExt];
2201 def Ptr32 : TypeAttr {
2202 let Spellings = [Keyword<"__ptr32">];
2203 let Documentation = [Undocumented];
2206 def Ptr64 : TypeAttr {
2207 let Spellings = [Keyword<"__ptr64">];
2208 let Documentation = [Undocumented];
2211 def SPtr : TypeAttr {
2212 let Spellings = [Keyword<"__sptr">];
2213 let Documentation = [Undocumented];
2216 def UPtr : TypeAttr {
2217 let Spellings = [Keyword<"__uptr">];
2218 let Documentation = [Undocumented];
2221 def MSInheritance : InheritableAttr {
2222 let LangOpts = [MicrosoftExt];
2223 let Args = [DefaultBoolArgument<"BestCase", 1>];
2224 let Spellings = [Keyword<"__single_inheritance">,
2225 Keyword<"__multiple_inheritance">,
2226 Keyword<"__virtual_inheritance">,
2227 Keyword<"__unspecified_inheritance">];
2228 let AdditionalMembers = [{
2229 static bool hasVBPtrOffsetField(Spelling Inheritance) {
2230 return Inheritance == Keyword_unspecified_inheritance;
2233 // Only member pointers to functions need a this adjustment, since it can be
2234 // combined with the field offset for data pointers.
2235 static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) {
2236 return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance;
2239 static bool hasVBTableOffsetField(Spelling Inheritance) {
2240 return Inheritance >= Keyword_virtual_inheritance;
2243 static bool hasOnlyOneField(bool IsMemberFunction,
2244 Spelling Inheritance) {
2245 if (IsMemberFunction)
2246 return Inheritance <= Keyword_single_inheritance;
2247 return Inheritance <= Keyword_multiple_inheritance;
2250 let Documentation = [MSInheritanceDocs];
2253 def MSVtorDisp : InheritableAttr {
2254 // This attribute has no spellings as it is only ever created implicitly.
2256 let Args = [UnsignedArgument<"vdm">];
2257 let SemaHandler = 0;
2259 let AdditionalMembers = [{
2266 Mode getVtorDispMode() const { return Mode(vdm); }
2268 let Documentation = [Undocumented];
2271 def InitSeg : Attr {
2272 let Spellings = [Pragma<"", "init_seg">];
2273 let Args = [StringArgument<"Section">];
2274 let SemaHandler = 0;
2275 let Documentation = [InitSegDocs];
2276 let AdditionalMembers = [{
2277 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2278 OS << '(' << getSection() << ')';
2283 def LoopHint : Attr {
2284 /// #pragma clang loop <option> directive
2285 /// vectorize: vectorizes loop operations if State == Enable.
2286 /// vectorize_width: vectorize loop operations with width 'Value'.
2287 /// interleave: interleave multiple loop iterations if State == Enable.
2288 /// interleave_count: interleaves 'Value' loop interations.
2289 /// unroll: fully unroll loop if State == Enable.
2290 /// unroll_count: unrolls loop 'Value' times.
2291 /// distribute: attempt to distribute loop if State == Enable
2293 /// #pragma unroll <argument> directive
2294 /// <no arg>: fully unrolls loop.
2295 /// boolean: fully unrolls loop if State == Enable.
2296 /// expression: unrolls loop 'Value' times.
2298 let Spellings = [Pragma<"clang", "loop">, Pragma<"", "unroll">,
2299 Pragma<"", "nounroll">];
2301 /// State of the loop optimization specified by the spelling.
2302 let Args = [EnumArgument<"Option", "OptionType",
2303 ["vectorize", "vectorize_width", "interleave", "interleave_count",
2304 "unroll", "unroll_count", "distribute"],
2305 ["Vectorize", "VectorizeWidth", "Interleave", "InterleaveCount",
2306 "Unroll", "UnrollCount", "Distribute"]>,
2307 EnumArgument<"State", "LoopHintState",
2308 ["enable", "disable", "numeric", "assume_safety", "full"],
2309 ["Enable", "Disable", "Numeric", "AssumeSafety", "Full"]>,
2310 ExprArgument<"Value">];
2312 let AdditionalMembers = [{
2313 static const char *getOptionName(int Option) {
2315 case Vectorize: return "vectorize";
2316 case VectorizeWidth: return "vectorize_width";
2317 case Interleave: return "interleave";
2318 case InterleaveCount: return "interleave_count";
2319 case Unroll: return "unroll";
2320 case UnrollCount: return "unroll_count";
2321 case Distribute: return "distribute";
2323 llvm_unreachable("Unhandled LoopHint option.");
2326 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2327 unsigned SpellingIndex = getSpellingListIndex();
2328 // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
2329 // "nounroll" is already emitted as the pragma name.
2330 if (SpellingIndex == Pragma_nounroll)
2332 else if (SpellingIndex == Pragma_unroll) {
2333 OS << getValueString(Policy);
2337 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2338 OS << getOptionName(option) << getValueString(Policy);
2341 // Return a string containing the loop hint argument including the
2342 // enclosing parentheses.
2343 std::string getValueString(const PrintingPolicy &Policy) const {
2344 std::string ValueName;
2345 llvm::raw_string_ostream OS(ValueName);
2347 if (state == Numeric)
2348 value->printPretty(OS, nullptr, Policy);
2349 else if (state == Enable)
2351 else if (state == Full)
2353 else if (state == AssumeSafety)
2354 OS << "assume_safety";
2361 // Return a string suitable for identifying this attribute in diagnostics.
2362 std::string getDiagnosticName(const PrintingPolicy &Policy) const {
2363 unsigned SpellingIndex = getSpellingListIndex();
2364 if (SpellingIndex == Pragma_nounroll)
2365 return "#pragma nounroll";
2366 else if (SpellingIndex == Pragma_unroll)
2367 return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
2369 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2370 return getOptionName(option) + getValueString(Policy);
2374 let Documentation = [LoopHintDocs, UnrollHintDocs];
2377 def CapturedRecord : InheritableAttr {
2378 // This attribute has no spellings as it is only ever created implicitly.
2380 let SemaHandler = 0;
2381 let Documentation = [Undocumented];
2384 def OMPThreadPrivateDecl : InheritableAttr {
2385 // This attribute has no spellings as it is only ever created implicitly.
2387 let SemaHandler = 0;
2388 let Documentation = [Undocumented];
2391 def OMPCaptureNoInit : InheritableAttr {
2392 // This attribute has no spellings as it is only ever created implicitly.
2394 let SemaHandler = 0;
2395 let Documentation = [Undocumented];
2398 def OMPDeclareSimdDecl : Attr {
2399 let Spellings = [Pragma<"omp", "declare simd">];
2400 let Subjects = SubjectList<[Function]>;
2401 let SemaHandler = 0;
2402 let HasCustomParsing = 1;
2403 let Documentation = [OMPDeclareSimdDocs];
2405 EnumArgument<"BranchState", "BranchStateTy",
2406 [ "", "inbranch", "notinbranch" ],
2407 [ "BS_Undefined", "BS_Inbranch", "BS_Notinbranch" ]>,
2408 ExprArgument<"Simdlen">, VariadicExprArgument<"Uniforms">,
2409 VariadicExprArgument<"Aligneds">, VariadicExprArgument<"Alignments">,
2410 VariadicExprArgument<"Linears">, VariadicUnsignedArgument<"Modifiers">,
2411 VariadicExprArgument<"Steps">
2413 let AdditionalMembers = [{
2414 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
2416 if (getBranchState() != BS_Undefined)
2417 OS << ConvertBranchStateTyToStr(getBranchState()) << " ";
2418 if (auto *E = getSimdlen()) {
2420 E->printPretty(OS, nullptr, Policy);
2423 if (uniforms_size() > 0) {
2425 StringRef Sep = "(";
2426 for (auto *E : uniforms()) {
2428 E->printPretty(OS, nullptr, Policy);
2433 alignments_iterator NI = alignments_begin();
2434 for (auto *E : aligneds()) {
2436 E->printPretty(OS, nullptr, Policy);
2439 (*NI)->printPretty(OS, nullptr, Policy);
2444 steps_iterator I = steps_begin();
2445 modifiers_iterator MI = modifiers_begin();
2446 for (auto *E : linears()) {
2448 if (*MI != OMPC_LINEAR_unknown)
2449 OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
2450 E->printPretty(OS, nullptr, Policy);
2451 if (*MI != OMPC_LINEAR_unknown)
2455 (*I)->printPretty(OS, nullptr, Policy);
2465 def OMPDeclareTargetDecl : Attr {
2466 let Spellings = [Pragma<"omp", "declare target">];
2467 let SemaHandler = 0;
2468 let Documentation = [OMPDeclareTargetDocs];
2470 EnumArgument<"MapType", "MapTypeTy",
2472 [ "MT_To", "MT_Link" ]>
2474 let AdditionalMembers = [{
2475 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2476 // Use fake syntax because it is for testing and debugging purpose only.
2477 if (getMapType() != MT_To)
2478 OS << ConvertMapTypeTyToStr(getMapType()) << " ";
2483 def InternalLinkage : InheritableAttr {
2484 let Spellings = [GNU<"internal_linkage">, CXX11<"clang", "internal_linkage">];
2485 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
2486 let Documentation = [InternalLinkageDocs];