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> : Argument<name, opt>;
144 class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
145 class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
146 class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
147 class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
148 class FunctionArgument<string name, bit opt = 0> : Argument<name, opt>;
149 class TypeArgument<string name, bit opt = 0> : Argument<name, opt>;
150 class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
151 class VariadicUnsignedArgument<string name> : Argument<name, 1>;
152 class VariadicExprArgument<string name> : Argument<name, 1>;
153 class VariadicStringArgument<string name> : Argument<name, 1>;
155 // A version of the form major.minor[.subminor].
156 class VersionArgument<string name, bit opt = 0> : Argument<name, opt>;
158 // This one's a doozy, so it gets its own special type
159 // It can be an unsigned integer, or a type. Either can
161 class AlignedArgument<string name, bit opt = 0> : Argument<name, opt>;
163 // A bool argument with a default value
164 class DefaultBoolArgument<string name, bit default> : BoolArgument<name, 1> {
165 bit Default = default;
168 // An integer argument with a default value
169 class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
170 int Default = default;
173 // This argument is more complex, it includes the enumerator type name,
174 // a list of strings to accept, and a list of enumerators to map them to.
175 class EnumArgument<string name, string type, list<string> values,
176 list<string> enums, bit opt = 0, bit fake = 0>
177 : Argument<name, opt, fake> {
179 list<string> Values = values;
180 list<string> Enums = enums;
183 // FIXME: There should be a VariadicArgument type that takes any other type
184 // of argument and generates the appropriate type.
185 class VariadicEnumArgument<string name, string type, list<string> values,
186 list<string> enums> : Argument<name, 1> {
188 list<string> Values = values;
189 list<string> Enums = enums;
192 // This handles one spelling of an attribute.
193 class Spelling<string name, string variety> {
195 string Variety = variety;
199 class GNU<string name> : Spelling<name, "GNU">;
200 class Declspec<string name> : Spelling<name, "Declspec">;
201 class Microsoft<string name> : Spelling<name, "Microsoft">;
202 class CXX11<string namespace, string name, int version = 1>
203 : Spelling<name, "CXX11"> {
204 string Namespace = namespace;
205 int Version = version;
207 class Keyword<string name> : Spelling<name, "Keyword">;
208 class Pragma<string namespace, string name> : Spelling<name, "Pragma"> {
209 string Namespace = namespace;
212 // The GCC spelling implies GNU<name, "GNU"> and CXX11<"gnu", name> and also
213 // sets KnownToGCC to 1. This spelling should be used for any GCC-compatible
215 class GCC<string name> : Spelling<name, "GCC"> {
219 class Accessor<string name, list<Spelling> spellings> {
221 list<Spelling> Spellings = spellings;
224 class SubjectDiag<bit warn> {
227 def WarnDiag : SubjectDiag<1>;
228 def ErrorDiag : SubjectDiag<0>;
230 class SubjectList<list<AttrSubject> subjects, SubjectDiag diag = WarnDiag,
231 string customDiag = ""> {
232 list<AttrSubject> Subjects = subjects;
233 SubjectDiag Diag = diag;
234 string CustomDiag = customDiag;
237 class LangOpt<string name, bit negated = 0> {
239 bit Negated = negated;
241 def MicrosoftExt : LangOpt<"MicrosoftExt">;
242 def Borland : LangOpt<"Borland">;
243 def CUDA : LangOpt<"CUDA">;
244 def COnly : LangOpt<"CPlusPlus", 1>;
245 def CPlusPlus : LangOpt<"CPlusPlus">;
246 def OpenCL : LangOpt<"OpenCL">;
247 def RenderScript : LangOpt<"RenderScript">;
249 // Defines targets for target-specific attributes. The list of strings should
250 // specify architectures for which the target applies, based off the ArchType
251 // enumeration in Triple.h.
252 class TargetArch<list<string> arches> {
253 list<string> Arches = arches;
255 list<string> CXXABIs;
257 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
258 def TargetMips : TargetArch<["mips", "mipsel"]>;
259 def TargetMSP430 : TargetArch<["msp430"]>;
260 def TargetX86 : TargetArch<["x86"]>;
261 def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
262 def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
263 let OSes = ["Win32"];
265 def TargetMicrosoftCXXABI : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
266 let CXXABIs = ["Microsoft"];
270 // The various ways in which an attribute can be spelled in source
271 list<Spelling> Spellings;
272 // The things to which an attribute can appertain
273 SubjectList Subjects;
274 // The arguments allowed on an attribute
275 list<Argument> Args = [];
276 // Accessors which should be generated for the attribute.
277 list<Accessor> Accessors = [];
278 // Set to true for attributes with arguments which require delayed parsing.
280 // Set to false to prevent an attribute from being propagated from a template
281 // to the instantiation.
283 // Set to true for attributes which must be instantiated within templates
284 bit TemplateDependent = 0;
285 // Set to true for attributes that have a corresponding AST node.
287 // Set to true for attributes which have handler in Sema.
289 // Set to true for attributes that are completely ignored.
291 // Set to true if the attribute's parsing does not match its semantic
292 // content. Eg) It parses 3 args, but semantically takes 4 args. Opts out of
293 // common attribute error checking.
294 bit HasCustomParsing = 0;
295 // Set to true if all of the attribute's arguments should be parsed in an
296 // unevaluated context.
297 bit ParseArgumentsAsUnevaluated = 0;
298 // Set to true if this attribute can be duplicated on a subject when merging
299 // attributes. By default, attributes are not merged.
300 bit DuplicatesAllowedWhileMerging = 0;
301 // Lists language options, one of which is required to be true for the
302 // attribute to be applicable. If empty, no language options are required.
303 list<LangOpt> LangOpts = [];
304 // Any additional text that should be included verbatim in the class.
305 // Note: Any additional data members will leak and should be constructed
306 // externally on the ASTContext.
307 code AdditionalMembers = [{}];
308 // Any documentation that should be associated with the attribute. Since an
309 // attribute may be documented under multiple categories, more than one
310 // Documentation entry may be listed.
311 list<Documentation> Documentation;
314 /// A type attribute is not processed on a declaration or a statement.
315 class TypeAttr : Attr {
316 // By default, type attributes do not get an AST node.
320 /// A stmt attribute is not processed on a declaration or a type.
321 class StmtAttr : Attr;
323 /// An inheritable attribute is inherited by later redeclarations.
324 class InheritableAttr : Attr;
326 /// A target-specific attribute. This class is meant to be used as a mixin
327 /// with InheritableAttr or Attr depending on the attribute's needs.
328 class TargetSpecificAttr<TargetArch target> {
329 TargetArch Target = target;
330 // Attributes are generally required to have unique spellings for their names
331 // so that the parser can determine what kind of attribute it has parsed.
332 // However, target-specific attributes are special in that the attribute only
333 // "exists" for a given target. So two target-specific attributes can share
334 // the same name when they exist in different targets. To support this, a
335 // Kind can be explicitly specified for a target-specific attribute. This
336 // corresponds to the AttributeList::AT_* enum that is generated and it
337 // should contain a shared value between the attributes.
339 // Target-specific attributes which use this feature should ensure that the
340 // spellings match exactly betweeen the attributes, and if the arguments or
341 // subjects differ, should specify HasCustomParsing = 1 and implement their
342 // own parsing and semantic handling requirements as-needed.
346 /// An inheritable parameter attribute is inherited by later
347 /// redeclarations, even when it's written on a parameter.
348 class InheritableParamAttr : InheritableAttr;
350 /// An attribute which changes the ABI rules for a specific parameter.
351 class ParameterABIAttr : InheritableParamAttr {
352 let Subjects = SubjectList<[ParmVar]>;
355 /// An ignored attribute, which we parse but discard with no checking.
356 class IgnoredAttr : Attr {
360 let Documentation = [Undocumented];
364 // Attributes begin here
368 let Spellings = [GCC<"abi_tag">];
369 let Args = [VariadicStringArgument<"Tags">];
370 let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag,
371 "ExpectedStructClassVariableFunctionOrInlineNamespace">;
372 let Documentation = [AbiTagsDocs];
375 def AddressSpace : TypeAttr {
376 let Spellings = [GNU<"address_space">];
377 let Args = [IntArgument<"AddressSpace">];
378 let Documentation = [Undocumented];
382 let Spellings = [GCC<"alias">];
383 let Args = [StringArgument<"Aliasee">];
384 let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
385 "ExpectedFunctionOrGlobalVar">;
386 let Documentation = [Undocumented];
389 def Aligned : InheritableAttr {
390 let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
391 Keyword<"_Alignas">];
392 // let Subjects = SubjectList<[NonBitField, NormalVar, Tag]>;
393 let Args = [AlignedArgument<"Alignment", 1>];
394 let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
395 Accessor<"isC11", [Keyword<"_Alignas">]>,
396 Accessor<"isAlignas", [Keyword<"alignas">,
397 Keyword<"_Alignas">]>,
398 Accessor<"isDeclspec",[Declspec<"align">]>];
399 let Documentation = [Undocumented];
402 def AlignValue : Attr {
404 // Unfortunately, this is semantically an assertion, not a directive
405 // (something else must ensure the alignment), so aligned_value is a
406 // probably a better name. We might want to add an aligned_value spelling in
407 // the future (and a corresponding C++ attribute), but this can be done
408 // later once we decide if we also want them to have slightly-different
409 // semantics than Intel's align_value.
411 // Intel's compiler on Windows also supports:
412 // , Declspec<"align_value">
414 let Args = [ExprArgument<"Alignment">];
415 let Subjects = SubjectList<[Var, TypedefName], WarnDiag,
416 "ExpectedVariableOrTypedef">;
417 let Documentation = [AlignValueDocs];
420 def AlignMac68k : InheritableAttr {
421 // This attribute has no spellings as it is only ever created implicitly.
424 let Documentation = [Undocumented];
427 def AlwaysInline : InheritableAttr {
428 let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
429 let Subjects = SubjectList<[Function]>;
430 let Documentation = [Undocumented];
433 def XRayInstrument : InheritableAttr {
434 let Spellings = [GNU<"xray_always_instrument">,
435 CXX11<"clang", "xray_always_instrument">,
436 GNU<"xray_never_instrument">,
437 CXX11<"clang", "xray_never_instrument">];
438 let Subjects = SubjectList<[CXXMethod, ObjCMethod, Function], WarnDiag,
439 "ExpectedFunctionOrMethod">;
440 let Accessors = [Accessor<"alwaysXRayInstrument",
441 [GNU<"xray_always_instrument">,
442 CXX11<"clang", "xray_always_instrument">]>,
443 Accessor<"neverXRayInstrument",
444 [GNU<"xray_never_instrument">,
445 CXX11<"clang", "xray_never_instrument">]>];
446 let Documentation = [XRayDocs];
449 def TLSModel : InheritableAttr {
450 let Spellings = [GCC<"tls_model">];
451 let Subjects = SubjectList<[TLSVar], ErrorDiag, "ExpectedTLSVar">;
452 let Args = [StringArgument<"Model">];
453 let Documentation = [TLSModelDocs];
456 def AnalyzerNoReturn : InheritableAttr {
457 let Spellings = [GNU<"analyzer_noreturn">];
458 let Documentation = [Undocumented];
461 def Annotate : InheritableParamAttr {
462 let Spellings = [GNU<"annotate">];
463 let Args = [StringArgument<"Annotation">];
464 let Documentation = [Undocumented];
467 def ARMInterrupt : InheritableAttr, TargetSpecificAttr<TargetARM> {
468 // NOTE: If you add any additional spellings, MSP430Interrupt's,
469 // MipsInterrupt's and AnyX86Interrupt's spellings must match.
470 let Spellings = [GNU<"interrupt">];
471 let Args = [EnumArgument<"Interrupt", "InterruptType",
472 ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
473 ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
475 let ParseKind = "Interrupt";
476 let HasCustomParsing = 1;
477 let Documentation = [ARMInterruptDocs];
480 def AsmLabel : InheritableAttr {
481 let Spellings = [Keyword<"asm">, Keyword<"__asm__">];
482 let Args = [StringArgument<"Label">];
484 let Documentation = [Undocumented];
487 def Availability : InheritableAttr {
488 let Spellings = [GNU<"availability">];
489 let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
490 VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
491 BoolArgument<"unavailable">, StringArgument<"message">,
492 BoolArgument<"strict">, StringArgument<"replacement">];
493 let AdditionalMembers =
494 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
495 return llvm::StringSwitch<llvm::StringRef>(Platform)
496 .Case("android", "Android")
498 .Case("macos", "macOS")
499 .Case("tvos", "tvOS")
500 .Case("watchos", "watchOS")
501 .Case("ios_app_extension", "iOS (App Extension)")
502 .Case("macos_app_extension", "macOS (App Extension)")
503 .Case("tvos_app_extension", "tvOS (App Extension)")
504 .Case("watchos_app_extension", "watchOS (App Extension)")
505 .Default(llvm::StringRef());
507 let HasCustomParsing = 1;
508 let DuplicatesAllowedWhileMerging = 1;
509 // let Subjects = SubjectList<[Named]>;
510 let Documentation = [AvailabilityDocs];
513 def Blocks : InheritableAttr {
514 let Spellings = [GNU<"blocks">];
515 let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
516 let Documentation = [Undocumented];
519 def Bounded : IgnoredAttr {
520 let Spellings = [GNU<"bounded">];
523 def CarriesDependency : InheritableParamAttr {
524 let Spellings = [GNU<"carries_dependency">,
525 CXX11<"","carries_dependency", 200809>];
526 let Subjects = SubjectList<[ParmVar, ObjCMethod, Function], ErrorDiag>;
527 let Documentation = [CarriesDependencyDocs];
530 def CDecl : InheritableAttr {
531 let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
532 // let Subjects = [Function, ObjCMethod];
533 let Documentation = [Undocumented];
536 // cf_audited_transfer indicates that the given function has been
537 // audited and has been marked with the appropriate cf_consumed and
538 // cf_returns_retained attributes. It is generally applied by
539 // '#pragma clang arc_cf_code_audited' rather than explicitly.
540 def CFAuditedTransfer : InheritableAttr {
541 let Spellings = [GNU<"cf_audited_transfer">];
542 let Subjects = SubjectList<[Function], ErrorDiag>;
543 let Documentation = [Undocumented];
546 // cf_unknown_transfer is an explicit opt-out of cf_audited_transfer.
547 // It indicates that the function has unknown or unautomatable
548 // transfer semantics.
549 def CFUnknownTransfer : InheritableAttr {
550 let Spellings = [GNU<"cf_unknown_transfer">];
551 let Subjects = SubjectList<[Function], ErrorDiag>;
552 let Documentation = [Undocumented];
555 def CFReturnsRetained : InheritableAttr {
556 let Spellings = [GNU<"cf_returns_retained">];
557 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
558 let Documentation = [Undocumented];
561 def CFReturnsNotRetained : InheritableAttr {
562 let Spellings = [GNU<"cf_returns_not_retained">];
563 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
564 let Documentation = [Undocumented];
567 def CFConsumed : InheritableParamAttr {
568 let Spellings = [GNU<"cf_consumed">];
569 let Subjects = SubjectList<[ParmVar]>;
570 let Documentation = [Undocumented];
573 def Cleanup : InheritableAttr {
574 let Spellings = [GCC<"cleanup">];
575 let Args = [FunctionArgument<"FunctionDecl">];
576 let Subjects = SubjectList<[Var]>;
577 let Documentation = [Undocumented];
580 def Cold : InheritableAttr {
581 let Spellings = [GCC<"cold">];
582 let Subjects = SubjectList<[Function]>;
583 let Documentation = [Undocumented];
586 def Common : InheritableAttr {
587 let Spellings = [GCC<"common">];
588 let Subjects = SubjectList<[Var]>;
589 let Documentation = [Undocumented];
592 def Const : InheritableAttr {
593 let Spellings = [GCC<"const">, GCC<"__const">];
594 let Documentation = [Undocumented];
597 def Constructor : InheritableAttr {
598 let Spellings = [GCC<"constructor">];
599 let Args = [DefaultIntArgument<"Priority", 65535>];
600 let Subjects = SubjectList<[Function]>;
601 let Documentation = [Undocumented];
604 // CUDA attributes are spelled __attribute__((attr)) or __declspec(__attr__).
606 def CUDAConstant : InheritableAttr {
607 let Spellings = [GNU<"constant">, Declspec<"__constant__">];
608 let Subjects = SubjectList<[Var]>;
609 let LangOpts = [CUDA];
610 let Documentation = [Undocumented];
613 def CUDACudartBuiltin : IgnoredAttr {
614 let Spellings = [GNU<"cudart_builtin">, Declspec<"__cudart_builtin__">];
615 let LangOpts = [CUDA];
618 def CUDADevice : InheritableAttr {
619 let Spellings = [GNU<"device">, Declspec<"__device__">];
620 let Subjects = SubjectList<[Function, Var]>;
621 let LangOpts = [CUDA];
622 let Documentation = [Undocumented];
625 def CUDADeviceBuiltin : IgnoredAttr {
626 let Spellings = [GNU<"device_builtin">, Declspec<"__device_builtin__">];
627 let LangOpts = [CUDA];
630 def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
631 let Spellings = [GNU<"device_builtin_surface_type">,
632 Declspec<"__device_builtin_surface_type__">];
633 let LangOpts = [CUDA];
636 def CUDADeviceBuiltinTextureType : IgnoredAttr {
637 let Spellings = [GNU<"device_builtin_texture_type">,
638 Declspec<"__device_builtin_texture_type__">];
639 let LangOpts = [CUDA];
642 def CUDAGlobal : InheritableAttr {
643 let Spellings = [GNU<"global">, Declspec<"__global__">];
644 let Subjects = SubjectList<[Function]>;
645 let LangOpts = [CUDA];
646 let Documentation = [Undocumented];
649 def CUDAHost : InheritableAttr {
650 let Spellings = [GNU<"host">, Declspec<"__host__">];
651 let Subjects = SubjectList<[Function]>;
652 let LangOpts = [CUDA];
653 let Documentation = [Undocumented];
656 def CUDAInvalidTarget : InheritableAttr {
658 let Subjects = SubjectList<[Function]>;
659 let LangOpts = [CUDA];
660 let Documentation = [Undocumented];
663 def CUDALaunchBounds : InheritableAttr {
664 let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
665 let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
666 let LangOpts = [CUDA];
667 let Subjects = SubjectList<[ObjCMethod, FunctionLike], WarnDiag,
668 "ExpectedFunctionOrMethod">;
669 // An AST node is created for this attribute, but is not used by other parts
670 // of the compiler. However, this node needs to exist in the AST because
671 // non-LLVM backends may be relying on the attribute's presence.
672 let Documentation = [Undocumented];
675 def CUDAShared : InheritableAttr {
676 let Spellings = [GNU<"shared">, Declspec<"__shared__">];
677 let Subjects = SubjectList<[Var]>;
678 let LangOpts = [CUDA];
679 let Documentation = [Undocumented];
682 def C11NoReturn : InheritableAttr {
683 let Spellings = [Keyword<"_Noreturn">];
684 let Subjects = SubjectList<[Function], ErrorDiag>;
686 let Documentation = [C11NoReturnDocs];
689 def CXX11NoReturn : InheritableAttr {
690 let Spellings = [CXX11<"","noreturn", 200809>];
691 let Subjects = SubjectList<[Function], ErrorDiag>;
692 let Documentation = [CXX11NoReturnDocs];
695 def OpenCLKernel : InheritableAttr {
696 let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
697 let Subjects = SubjectList<[Function], ErrorDiag>;
698 let Documentation = [Undocumented];
701 def OpenCLUnrollHint : InheritableAttr {
702 let Spellings = [GNU<"opencl_unroll_hint">];
703 let Args = [UnsignedArgument<"UnrollHint">];
704 let Documentation = [OpenCLUnrollHintDocs];
707 // This attribute is both a type attribute, and a declaration attribute (for
708 // parameter variables).
709 def OpenCLAccess : Attr {
710 let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
711 Keyword<"__write_only">, Keyword<"write_only">,
712 Keyword<"__read_write">, Keyword<"read_write">];
713 let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag,
714 "ExpectedParameterOrTypedef">;
715 let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
716 Keyword<"read_only">]>,
717 Accessor<"isReadWrite", [Keyword<"__read_write">,
718 Keyword<"read_write">]>,
719 Accessor<"isWriteOnly", [Keyword<"__write_only">,
720 Keyword<"write_only">]>];
721 let Documentation = [OpenCLAccessDocs];
724 def OpenCLPrivateAddressSpace : TypeAttr {
725 let Spellings = [Keyword<"__private">, Keyword<"private">];
726 let Documentation = [OpenCLAddressSpacePrivateDocs];
729 def OpenCLGlobalAddressSpace : TypeAttr {
730 let Spellings = [Keyword<"__global">, Keyword<"global">];
731 let Documentation = [OpenCLAddressSpaceGlobalDocs];
734 def OpenCLLocalAddressSpace : TypeAttr {
735 let Spellings = [Keyword<"__local">, Keyword<"local">];
736 let Documentation = [OpenCLAddressSpaceLocalDocs];
739 def OpenCLConstantAddressSpace : TypeAttr {
740 let Spellings = [Keyword<"__constant">, Keyword<"constant">];
741 let Documentation = [OpenCLAddressSpaceConstantDocs];
744 def OpenCLGenericAddressSpace : TypeAttr {
745 let Spellings = [Keyword<"__generic">, Keyword<"generic">];
746 let Documentation = [OpenCLAddressSpaceGenericDocs];
749 def OpenCLNoSVM : Attr {
750 let Spellings = [GNU<"nosvm">];
751 let Subjects = SubjectList<[Var]>;
752 let Documentation = [OpenCLNoSVMDocs];
753 let LangOpts = [OpenCL];
757 def RenderScriptKernel : Attr {
758 let Spellings = [GNU<"kernel">];
759 let Subjects = SubjectList<[Function]>;
760 let Documentation = [RenderScriptKernelAttributeDocs];
761 let LangOpts = [RenderScript];
764 def Deprecated : InheritableAttr {
765 let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
766 CXX11<"","deprecated", 201309>];
767 let Args = [StringArgument<"Message", 1>,
768 // An optional string argument that enables us to provide a
770 StringArgument<"Replacement", 1>];
771 let Documentation = [DeprecatedDocs];
774 def Destructor : InheritableAttr {
775 let Spellings = [GCC<"destructor">];
776 let Args = [DefaultIntArgument<"Priority", 65535>];
777 let Subjects = SubjectList<[Function]>;
778 let Documentation = [Undocumented];
781 def EmptyBases : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
782 let Spellings = [Declspec<"empty_bases">];
783 let Subjects = SubjectList<[CXXRecord]>;
784 let Documentation = [EmptyBasesDocs];
787 def AllocSize : InheritableAttr {
788 let Spellings = [GCC<"alloc_size">];
789 let Subjects = SubjectList<[Function]>;
790 let Args = [IntArgument<"ElemSizeParam">, IntArgument<"NumElemsParam", 1>];
791 let TemplateDependent = 1;
792 let Documentation = [AllocSizeDocs];
795 def EnableIf : InheritableAttr {
796 let Spellings = [GNU<"enable_if">];
797 let Subjects = SubjectList<[Function]>;
798 let Args = [ExprArgument<"Cond">, StringArgument<"Message">];
799 let TemplateDependent = 1;
800 let Documentation = [EnableIfDocs];
803 def ExtVectorType : Attr {
804 let Spellings = [GNU<"ext_vector_type">];
805 let Subjects = SubjectList<[TypedefName], ErrorDiag>;
806 let Args = [ExprArgument<"NumElements">];
808 let Documentation = [Undocumented];
811 def FallThrough : StmtAttr {
812 let Spellings = [CXX11<"", "fallthrough", 201603>,
813 CXX11<"clang", "fallthrough">];
814 // let Subjects = [NullStmt];
815 let Documentation = [FallthroughDocs];
818 def FastCall : InheritableAttr {
819 let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
820 Keyword<"_fastcall">];
821 // let Subjects = [Function, ObjCMethod];
822 let Documentation = [FastCallDocs];
825 def RegCall : InheritableAttr {
826 let Spellings = [GCC<"regcall">, Keyword<"__regcall">];
827 let Documentation = [RegCallDocs];
830 def Final : InheritableAttr {
831 let Spellings = [Keyword<"final">, Keyword<"sealed">];
832 let Accessors = [Accessor<"isSpelledAsSealed", [Keyword<"sealed">]>];
834 let Documentation = [Undocumented];
837 def MinSize : InheritableAttr {
838 let Spellings = [GNU<"minsize">];
839 let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
840 let Documentation = [Undocumented];
843 def FlagEnum : InheritableAttr {
844 let Spellings = [GNU<"flag_enum">];
845 let Subjects = SubjectList<[Enum]>;
846 let Documentation = [FlagEnumDocs];
847 let LangOpts = [COnly];
850 def Flatten : InheritableAttr {
851 let Spellings = [GCC<"flatten">];
852 let Subjects = SubjectList<[Function], ErrorDiag>;
853 let Documentation = [FlattenDocs];
856 def Format : InheritableAttr {
857 let Spellings = [GCC<"format">];
858 let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">,
859 IntArgument<"FirstArg">];
860 let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto], WarnDiag,
861 "ExpectedFunctionWithProtoType">;
862 let Documentation = [FormatDocs];
865 def FormatArg : InheritableAttr {
866 let Spellings = [GCC<"format_arg">];
867 let Args = [IntArgument<"FormatIdx">];
868 let Subjects = SubjectList<[ObjCMethod, HasFunctionProto], WarnDiag,
869 "ExpectedFunctionWithProtoType">;
870 let Documentation = [Undocumented];
873 def GNUInline : InheritableAttr {
874 let Spellings = [GCC<"gnu_inline">];
875 let Subjects = SubjectList<[Function]>;
876 let Documentation = [Undocumented];
879 def Hot : InheritableAttr {
880 let Spellings = [GCC<"hot">];
881 let Subjects = SubjectList<[Function]>;
882 // An AST node is created for this attribute, but not actually used beyond
883 // semantic checking for mutual exclusion with the Cold attribute.
884 let Documentation = [Undocumented];
887 def IBAction : InheritableAttr {
888 let Spellings = [GNU<"ibaction">];
889 let Subjects = SubjectList<[ObjCInstanceMethod], WarnDiag,
890 "ExpectedObjCInstanceMethod">;
891 // An AST node is created for this attribute, but is not used by other parts
892 // of the compiler. However, this node needs to exist in the AST because
893 // external tools rely on it.
894 let Documentation = [Undocumented];
897 def IBOutlet : InheritableAttr {
898 let Spellings = [GNU<"iboutlet">];
899 // let Subjects = [ObjCIvar, ObjCProperty];
900 let Documentation = [Undocumented];
903 def IBOutletCollection : InheritableAttr {
904 let Spellings = [GNU<"iboutletcollection">];
905 let Args = [TypeArgument<"Interface", 1>];
906 // let Subjects = [ObjCIvar, ObjCProperty];
907 let Documentation = [Undocumented];
911 let Spellings = [GCC<"ifunc">];
912 let Args = [StringArgument<"Resolver">];
913 let Subjects = SubjectList<[Function]>;
914 let Documentation = [IFuncDocs];
917 def Restrict : InheritableAttr {
918 let Spellings = [Declspec<"restrict">, GCC<"malloc">];
919 let Subjects = SubjectList<[Function]>;
920 let Documentation = [Undocumented];
923 def LayoutVersion : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
924 let Spellings = [Declspec<"layout_version">];
925 let Args = [UnsignedArgument<"Version">];
926 let Subjects = SubjectList<[CXXRecord]>;
927 let Documentation = [LayoutVersionDocs];
930 def MaxFieldAlignment : InheritableAttr {
931 // This attribute has no spellings as it is only ever created implicitly.
933 let Args = [UnsignedArgument<"Alignment">];
935 let Documentation = [Undocumented];
938 def MayAlias : InheritableAttr {
939 // FIXME: this is a type attribute in GCC, but a declaration attribute here.
940 let Spellings = [GCC<"may_alias">];
941 let Documentation = [Undocumented];
944 def MSABI : InheritableAttr {
945 let Spellings = [GCC<"ms_abi">];
946 // let Subjects = [Function, ObjCMethod];
947 let Documentation = [MSABIDocs];
950 def MSP430Interrupt : InheritableAttr, TargetSpecificAttr<TargetMSP430> {
951 // NOTE: If you add any additional spellings, ARMInterrupt's, MipsInterrupt's
952 // and AnyX86Interrupt's spellings must match.
953 let Spellings = [GNU<"interrupt">];
954 let Args = [UnsignedArgument<"Number">];
955 let ParseKind = "Interrupt";
956 let HasCustomParsing = 1;
957 let Documentation = [Undocumented];
960 def Mips16 : InheritableAttr, TargetSpecificAttr<TargetMips> {
961 let Spellings = [GCC<"mips16">];
962 let Subjects = SubjectList<[Function], ErrorDiag>;
963 let Documentation = [Undocumented];
966 def MipsInterrupt : InheritableAttr, TargetSpecificAttr<TargetMips> {
967 // NOTE: If you add any additional spellings, ARMInterrupt's,
968 // MSP430Interrupt's and AnyX86Interrupt's spellings must match.
969 let Spellings = [GNU<"interrupt">];
970 let Subjects = SubjectList<[Function]>;
971 let Args = [EnumArgument<"Interrupt", "InterruptType",
972 ["vector=sw0", "vector=sw1", "vector=hw0",
973 "vector=hw1", "vector=hw2", "vector=hw3",
974 "vector=hw4", "vector=hw5", "eic", ""],
975 ["sw0", "sw1", "hw0", "hw1", "hw2", "hw3",
976 "hw4", "hw5", "eic", "eic"]
978 let ParseKind = "Interrupt";
979 let Documentation = [MipsInterruptDocs];
983 let Spellings = [GCC<"mode">];
984 let Subjects = SubjectList<[Var, Enum, TypedefName, Field], ErrorDiag,
985 "ExpectedVariableEnumFieldOrTypedef">;
986 let Args = [IdentifierArgument<"Mode">];
987 let Documentation = [Undocumented];
990 def Naked : InheritableAttr {
991 let Spellings = [GCC<"naked">, Declspec<"naked">];
992 let Subjects = SubjectList<[Function]>;
993 let Documentation = [Undocumented];
996 def NeonPolyVectorType : TypeAttr {
997 let Spellings = [GNU<"neon_polyvector_type">];
998 let Args = [IntArgument<"NumElements">];
999 let Documentation = [Undocumented];
1002 def NeonVectorType : TypeAttr {
1003 let Spellings = [GNU<"neon_vector_type">];
1004 let Args = [IntArgument<"NumElements">];
1005 let Documentation = [Undocumented];
1008 def ReturnsTwice : InheritableAttr {
1009 let Spellings = [GCC<"returns_twice">];
1010 let Subjects = SubjectList<[Function]>;
1011 let Documentation = [Undocumented];
1014 def DisableTailCalls : InheritableAttr {
1015 let Spellings = [GNU<"disable_tail_calls">,
1016 CXX11<"clang", "disable_tail_calls">];
1017 let Subjects = SubjectList<[Function, ObjCMethod]>;
1018 let Documentation = [DisableTailCallsDocs];
1021 def NoAlias : InheritableAttr {
1022 let Spellings = [Declspec<"noalias">];
1023 let Subjects = SubjectList<[Function]>;
1024 let Documentation = [NoAliasDocs];
1027 def NoCommon : InheritableAttr {
1028 let Spellings = [GCC<"nocommon">];
1029 let Subjects = SubjectList<[Var]>;
1030 let Documentation = [Undocumented];
1033 def NoDebug : InheritableAttr {
1034 let Spellings = [GCC<"nodebug">];
1035 let Subjects = SubjectList<[FunctionLike, ObjCMethod, NonParmVar], WarnDiag,
1036 "ExpectedVariableOrFunction">;
1037 let Documentation = [NoDebugDocs];
1040 def NoDuplicate : InheritableAttr {
1041 let Spellings = [GNU<"noduplicate">, CXX11<"clang", "noduplicate">];
1042 let Subjects = SubjectList<[Function]>;
1043 let Documentation = [NoDuplicateDocs];
1046 def Convergent : InheritableAttr {
1047 let Spellings = [GNU<"convergent">, CXX11<"clang", "convergent">];
1048 let Subjects = SubjectList<[Function]>;
1049 let Documentation = [ConvergentDocs];
1052 def NoInline : InheritableAttr {
1053 let Spellings = [GCC<"noinline">, Declspec<"noinline">];
1054 let Subjects = SubjectList<[Function]>;
1055 let Documentation = [Undocumented];
1058 def NoMips16 : InheritableAttr, TargetSpecificAttr<TargetMips> {
1059 let Spellings = [GCC<"nomips16">];
1060 let Subjects = SubjectList<[Function], ErrorDiag>;
1061 let Documentation = [Undocumented];
1064 // This is not a TargetSpecificAttr so that is silently accepted and
1065 // ignored on other targets as encouraged by the OpenCL spec.
1067 // See OpenCL 1.2 6.11.5: "It is our intention that a particular
1068 // implementation of OpenCL be free to ignore all attributes and the
1069 // resulting executable binary will produce the same result."
1071 // However, only AMD GPU targets will emit the corresponding IR
1074 // FIXME: This provides a sub-optimal error message if you attempt to
1075 // use this in CUDA, since CUDA does not use the same terminology.
1077 // FIXME: SubjectList should be for OpenCLKernelFunction, but is not to
1078 // workaround needing to see kernel attribute before others to know if
1079 // this should be rejected on non-kernels.
1081 def AMDGPUFlatWorkGroupSize : InheritableAttr {
1082 let Spellings = [GNU<"amdgpu_flat_work_group_size">];
1083 let Args = [UnsignedArgument<"Min">, UnsignedArgument<"Max">];
1084 let Documentation = [AMDGPUFlatWorkGroupSizeDocs];
1085 let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1088 def AMDGPUWavesPerEU : InheritableAttr {
1089 let Spellings = [GNU<"amdgpu_waves_per_eu">];
1090 let Args = [UnsignedArgument<"Min">, UnsignedArgument<"Max", 1>];
1091 let Documentation = [AMDGPUWavesPerEUDocs];
1092 let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1095 def AMDGPUNumSGPR : InheritableAttr {
1096 let Spellings = [GNU<"amdgpu_num_sgpr">];
1097 let Args = [UnsignedArgument<"NumSGPR">];
1098 let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1099 let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1102 def AMDGPUNumVGPR : InheritableAttr {
1103 let Spellings = [GNU<"amdgpu_num_vgpr">];
1104 let Args = [UnsignedArgument<"NumVGPR">];
1105 let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1106 let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1109 def NoSplitStack : InheritableAttr {
1110 let Spellings = [GCC<"no_split_stack">];
1111 let Subjects = SubjectList<[Function], ErrorDiag>;
1112 let Documentation = [NoSplitStackDocs];
1115 def NonNull : InheritableAttr {
1116 let Spellings = [GCC<"nonnull">];
1117 let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
1118 "ExpectedFunctionMethodOrParameter">;
1119 let Args = [VariadicUnsignedArgument<"Args">];
1120 let AdditionalMembers =
1121 [{bool isNonNull(unsigned idx) const {
1124 for (const auto &V : args())
1129 // FIXME: We should merge duplicates into a single nonnull attribute.
1130 let DuplicatesAllowedWhileMerging = 1;
1131 let Documentation = [NonNullDocs];
1134 def ReturnsNonNull : InheritableAttr {
1135 let Spellings = [GCC<"returns_nonnull">];
1136 let Subjects = SubjectList<[ObjCMethod, Function], WarnDiag,
1137 "ExpectedFunctionOrMethod">;
1138 let Documentation = [ReturnsNonNullDocs];
1141 // pass_object_size(N) indicates that the parameter should have
1142 // __builtin_object_size with Type=N evaluated on the parameter at the callsite.
1143 def PassObjectSize : InheritableParamAttr {
1144 let Spellings = [GNU<"pass_object_size">];
1145 let Args = [IntArgument<"Type">];
1146 let Subjects = SubjectList<[ParmVar]>;
1147 let Documentation = [PassObjectSizeDocs];
1150 // Nullability type attributes.
1151 def TypeNonNull : TypeAttr {
1152 let Spellings = [Keyword<"_Nonnull">];
1153 let Documentation = [TypeNonNullDocs];
1156 def TypeNullable : TypeAttr {
1157 let Spellings = [Keyword<"_Nullable">];
1158 let Documentation = [TypeNullableDocs];
1161 def TypeNullUnspecified : TypeAttr {
1162 let Spellings = [Keyword<"_Null_unspecified">];
1163 let Documentation = [TypeNullUnspecifiedDocs];
1166 def ObjCKindOf : TypeAttr {
1167 let Spellings = [Keyword<"__kindof">];
1168 let Documentation = [Undocumented];
1171 def AssumeAligned : InheritableAttr {
1172 let Spellings = [GCC<"assume_aligned">];
1173 let Subjects = SubjectList<[ObjCMethod, Function]>;
1174 let Args = [ExprArgument<"Alignment">, ExprArgument<"Offset", 1>];
1175 let Documentation = [AssumeAlignedDocs];
1178 def NoReturn : InheritableAttr {
1179 let Spellings = [GCC<"noreturn">, Declspec<"noreturn">];
1180 // FIXME: Does GCC allow this on the function instead?
1181 let Documentation = [Undocumented];
1184 def NoInstrumentFunction : InheritableAttr {
1185 let Spellings = [GCC<"no_instrument_function">];
1186 let Subjects = SubjectList<[Function]>;
1187 let Documentation = [Undocumented];
1190 def NotTailCalled : InheritableAttr {
1191 let Spellings = [GNU<"not_tail_called">, CXX11<"clang", "not_tail_called">];
1192 let Subjects = SubjectList<[Function]>;
1193 let Documentation = [NotTailCalledDocs];
1196 def NoThrow : InheritableAttr {
1197 let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
1198 let Documentation = [Undocumented];
1201 def NvWeak : IgnoredAttr {
1202 // No Declspec spelling of this attribute; the CUDA headers use
1203 // __attribute__((nv_weak)) unconditionally.
1204 let Spellings = [GNU<"nv_weak">];
1205 let LangOpts = [CUDA];
1208 def ObjCBridge : InheritableAttr {
1209 let Spellings = [GNU<"objc_bridge">];
1210 let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
1211 "ExpectedStructOrUnionOrTypedef">;
1212 let Args = [IdentifierArgument<"BridgedType">];
1213 let Documentation = [Undocumented];
1216 def ObjCBridgeMutable : InheritableAttr {
1217 let Spellings = [GNU<"objc_bridge_mutable">];
1218 let Subjects = SubjectList<[Record], ErrorDiag>;
1219 let Args = [IdentifierArgument<"BridgedType">];
1220 let Documentation = [Undocumented];
1223 def ObjCBridgeRelated : InheritableAttr {
1224 let Spellings = [GNU<"objc_bridge_related">];
1225 let Subjects = SubjectList<[Record], ErrorDiag>;
1226 let Args = [IdentifierArgument<"RelatedClass">,
1227 IdentifierArgument<"ClassMethod", 1>,
1228 IdentifierArgument<"InstanceMethod", 1>];
1229 let HasCustomParsing = 1;
1230 let Documentation = [Undocumented];
1233 def NSReturnsRetained : InheritableAttr {
1234 let Spellings = [GNU<"ns_returns_retained">];
1235 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1236 let Documentation = [Undocumented];
1239 def NSReturnsNotRetained : InheritableAttr {
1240 let Spellings = [GNU<"ns_returns_not_retained">];
1241 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1242 let Documentation = [Undocumented];
1245 def NSReturnsAutoreleased : InheritableAttr {
1246 let Spellings = [GNU<"ns_returns_autoreleased">];
1247 // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1248 let Documentation = [Undocumented];
1251 def NSConsumesSelf : InheritableAttr {
1252 let Spellings = [GNU<"ns_consumes_self">];
1253 let Subjects = SubjectList<[ObjCMethod]>;
1254 let Documentation = [Undocumented];
1257 def NSConsumed : InheritableParamAttr {
1258 let Spellings = [GNU<"ns_consumed">];
1259 let Subjects = SubjectList<[ParmVar]>;
1260 let Documentation = [Undocumented];
1263 def ObjCException : InheritableAttr {
1264 let Spellings = [GNU<"objc_exception">];
1265 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1266 let Documentation = [Undocumented];
1269 def ObjCMethodFamily : InheritableAttr {
1270 let Spellings = [GNU<"objc_method_family">];
1271 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1272 let Args = [EnumArgument<"Family", "FamilyKind",
1273 ["none", "alloc", "copy", "init", "mutableCopy", "new"],
1274 ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
1275 "OMF_mutableCopy", "OMF_new"]>];
1276 let Documentation = [ObjCMethodFamilyDocs];
1279 def ObjCNSObject : InheritableAttr {
1280 let Spellings = [GNU<"NSObject">];
1281 let Documentation = [Undocumented];
1284 def ObjCIndependentClass : InheritableAttr {
1285 let Spellings = [GNU<"objc_independent_class">];
1286 let Documentation = [Undocumented];
1289 def ObjCPreciseLifetime : InheritableAttr {
1290 let Spellings = [GNU<"objc_precise_lifetime">];
1291 let Subjects = SubjectList<[Var], ErrorDiag>;
1292 let Documentation = [Undocumented];
1295 def ObjCReturnsInnerPointer : InheritableAttr {
1296 let Spellings = [GNU<"objc_returns_inner_pointer">];
1297 let Subjects = SubjectList<[ObjCMethod, ObjCProperty], ErrorDiag>;
1298 let Documentation = [Undocumented];
1301 def ObjCRequiresSuper : InheritableAttr {
1302 let Spellings = [GNU<"objc_requires_super">];
1303 let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1304 let Documentation = [ObjCRequiresSuperDocs];
1307 def ObjCRootClass : InheritableAttr {
1308 let Spellings = [GNU<"objc_root_class">];
1309 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1310 let Documentation = [Undocumented];
1313 def ObjCSubclassingRestricted : InheritableAttr {
1314 let Spellings = [GNU<"objc_subclassing_restricted">];
1315 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1316 let Documentation = [ObjCSubclassingRestrictedDocs];
1319 def ObjCExplicitProtocolImpl : InheritableAttr {
1320 let Spellings = [GNU<"objc_protocol_requires_explicit_implementation">];
1321 let Subjects = SubjectList<[ObjCProtocol], ErrorDiag>;
1322 let Documentation = [Undocumented];
1325 def ObjCDesignatedInitializer : Attr {
1326 let Spellings = [GNU<"objc_designated_initializer">];
1327 let Subjects = SubjectList<[ObjCInterfaceDeclInitMethod], ErrorDiag,
1328 "ExpectedObjCInterfaceDeclInitMethod">;
1329 let Documentation = [Undocumented];
1332 def ObjCRuntimeName : Attr {
1333 let Spellings = [GNU<"objc_runtime_name">];
1334 let Subjects = SubjectList<[ObjCInterface, ObjCProtocol], ErrorDiag>;
1335 let Args = [StringArgument<"MetadataName">];
1336 let Documentation = [ObjCRuntimeNameDocs];
1339 def ObjCRuntimeVisible : Attr {
1340 let Spellings = [GNU<"objc_runtime_visible">];
1341 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1342 let Documentation = [ObjCRuntimeVisibleDocs];
1345 def ObjCBoxable : Attr {
1346 let Spellings = [GNU<"objc_boxable">];
1347 let Subjects = SubjectList<[Record], ErrorDiag, "ExpectedStructOrUnion">;
1348 let Documentation = [ObjCBoxableDocs];
1351 def OptimizeNone : InheritableAttr {
1352 let Spellings = [GNU<"optnone">, CXX11<"clang", "optnone">];
1353 let Subjects = SubjectList<[Function, ObjCMethod]>;
1354 let Documentation = [OptnoneDocs];
1357 def Overloadable : Attr {
1358 let Spellings = [GNU<"overloadable">];
1359 let Subjects = SubjectList<[Function], ErrorDiag>;
1360 let Documentation = [OverloadableDocs];
1363 def Override : InheritableAttr {
1364 let Spellings = [Keyword<"override">];
1365 let SemaHandler = 0;
1366 let Documentation = [Undocumented];
1369 def Ownership : InheritableAttr {
1370 let Spellings = [GNU<"ownership_holds">, GNU<"ownership_returns">,
1371 GNU<"ownership_takes">];
1372 let Accessors = [Accessor<"isHolds", [GNU<"ownership_holds">]>,
1373 Accessor<"isReturns", [GNU<"ownership_returns">]>,
1374 Accessor<"isTakes", [GNU<"ownership_takes">]>];
1375 let AdditionalMembers = [{
1376 enum OwnershipKind { Holds, Returns, Takes };
1377 OwnershipKind getOwnKind() const {
1378 return isHolds() ? Holds :
1383 let Args = [IdentifierArgument<"Module">, VariadicUnsignedArgument<"Args">];
1384 let Subjects = SubjectList<[HasFunctionProto], WarnDiag,
1385 "ExpectedFunctionWithProtoType">;
1386 let Documentation = [Undocumented];
1389 def Packed : InheritableAttr {
1390 let Spellings = [GCC<"packed">];
1391 // let Subjects = [Tag, Field];
1392 let Documentation = [Undocumented];
1395 def IntelOclBicc : InheritableAttr {
1396 let Spellings = [GNU<"intel_ocl_bicc">];
1397 // let Subjects = [Function, ObjCMethod];
1398 let Documentation = [Undocumented];
1401 def Pcs : InheritableAttr {
1402 let Spellings = [GCC<"pcs">];
1403 let Args = [EnumArgument<"PCS", "PCSType",
1404 ["aapcs", "aapcs-vfp"],
1405 ["AAPCS", "AAPCS_VFP"]>];
1406 // let Subjects = [Function, ObjCMethod];
1407 let Documentation = [PcsDocs];
1410 def Pure : InheritableAttr {
1411 let Spellings = [GCC<"pure">];
1412 let Documentation = [Undocumented];
1415 def Regparm : TypeAttr {
1416 let Spellings = [GCC<"regparm">];
1417 let Args = [UnsignedArgument<"NumParams">];
1418 let Documentation = [RegparmDocs];
1421 def ReqdWorkGroupSize : InheritableAttr {
1422 let Spellings = [GNU<"reqd_work_group_size">];
1423 let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
1424 UnsignedArgument<"ZDim">];
1425 let Subjects = SubjectList<[Function], ErrorDiag>;
1426 let Documentation = [Undocumented];
1429 def RequireConstantInit : InheritableAttr {
1430 let Spellings = [GNU<"require_constant_initialization">,
1431 CXX11<"clang", "require_constant_initialization">];
1432 let Subjects = SubjectList<[GlobalVar], ErrorDiag,
1433 "ExpectedStaticOrTLSVar">;
1434 let Documentation = [RequireConstantInitDocs];
1435 let LangOpts = [CPlusPlus];
1438 def WorkGroupSizeHint : InheritableAttr {
1439 let Spellings = [GNU<"work_group_size_hint">];
1440 let Args = [UnsignedArgument<"XDim">,
1441 UnsignedArgument<"YDim">,
1442 UnsignedArgument<"ZDim">];
1443 let Subjects = SubjectList<[Function], ErrorDiag>;
1444 let Documentation = [Undocumented];
1447 def InitPriority : InheritableAttr {
1448 let Spellings = [GNU<"init_priority">];
1449 let Args = [UnsignedArgument<"Priority">];
1450 let Subjects = SubjectList<[Var], ErrorDiag>;
1451 let Documentation = [Undocumented];
1454 def Section : InheritableAttr {
1455 let Spellings = [GCC<"section">, Declspec<"allocate">];
1456 let Args = [StringArgument<"Name">];
1457 let Subjects = SubjectList<[Function, GlobalVar,
1458 ObjCMethod, ObjCProperty], ErrorDiag,
1459 "ExpectedFunctionGlobalVarMethodOrProperty">;
1460 let Documentation = [SectionDocs];
1463 def Sentinel : InheritableAttr {
1464 let Spellings = [GCC<"sentinel">];
1465 let Args = [DefaultIntArgument<"Sentinel", 0>,
1466 DefaultIntArgument<"NullPos", 0>];
1467 // let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>;
1468 let Documentation = [Undocumented];
1471 def StdCall : InheritableAttr {
1472 let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
1473 // let Subjects = [Function, ObjCMethod];
1474 let Documentation = [StdCallDocs];
1477 def SwiftCall : InheritableAttr {
1478 let Spellings = [GCC<"swiftcall">];
1479 // let Subjects = SubjectList<[Function]>;
1480 let Documentation = [SwiftCallDocs];
1483 def SwiftContext : ParameterABIAttr {
1484 let Spellings = [GCC<"swift_context">];
1485 let Documentation = [SwiftContextDocs];
1488 def SwiftErrorResult : ParameterABIAttr {
1489 let Spellings = [GCC<"swift_error_result">];
1490 let Documentation = [SwiftErrorResultDocs];
1493 def SwiftIndirectResult : ParameterABIAttr {
1494 let Spellings = [GCC<"swift_indirect_result">];
1495 let Documentation = [SwiftIndirectResultDocs];
1498 def SysVABI : InheritableAttr {
1499 let Spellings = [GCC<"sysv_abi">];
1500 // let Subjects = [Function, ObjCMethod];
1501 let Documentation = [Undocumented];
1504 def ThisCall : InheritableAttr {
1505 let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
1506 Keyword<"_thiscall">];
1507 // let Subjects = [Function, ObjCMethod];
1508 let Documentation = [ThisCallDocs];
1511 def VectorCall : InheritableAttr {
1512 let Spellings = [GNU<"vectorcall">, Keyword<"__vectorcall">,
1513 Keyword<"_vectorcall">];
1514 // let Subjects = [Function, ObjCMethod];
1515 let Documentation = [VectorCallDocs];
1518 def Pascal : InheritableAttr {
1519 let Spellings = [GNU<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
1520 // let Subjects = [Function, ObjCMethod];
1521 let Documentation = [Undocumented];
1524 def PreserveMost : InheritableAttr {
1525 let Spellings = [GNU<"preserve_most">];
1526 let Documentation = [PreserveMostDocs];
1529 def PreserveAll : InheritableAttr {
1530 let Spellings = [GNU<"preserve_all">];
1531 let Documentation = [PreserveAllDocs];
1534 def Target : InheritableAttr {
1535 let Spellings = [GCC<"target">];
1536 let Args = [StringArgument<"featuresStr">];
1537 let Subjects = SubjectList<[Function], ErrorDiag>;
1538 let Documentation = [TargetDocs];
1539 let AdditionalMembers = [{
1540 typedef std::pair<std::vector<std::string>, StringRef> ParsedTargetAttr;
1541 ParsedTargetAttr parse() const {
1542 ParsedTargetAttr Ret;
1543 SmallVector<StringRef, 1> AttrFeatures;
1544 getFeaturesStr().split(AttrFeatures, ",");
1546 // Grab the various features and prepend a "+" to turn on the feature to
1547 // the backend and add them to our existing set of features.
1548 for (auto &Feature : AttrFeatures) {
1549 // Go ahead and trim whitespace rather than either erroring or
1550 // accepting it weirdly.
1551 Feature = Feature.trim();
1553 // We don't support cpu tuning this way currently.
1554 // TODO: Support the fpmath option. It will require checking
1555 // overall feature validity for the function with the rest of the
1556 // attributes on the function.
1557 if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
1560 // While we're here iterating check for a different target cpu.
1561 if (Feature.startswith("arch="))
1562 Ret.second = Feature.split("=").second.trim();
1563 else if (Feature.startswith("no-"))
1564 Ret.first.push_back("-" + Feature.split("-").second.str());
1566 Ret.first.push_back("+" + Feature.str());
1573 def TransparentUnion : InheritableAttr {
1574 let Spellings = [GCC<"transparent_union">];
1575 // let Subjects = SubjectList<[Record, TypedefName]>;
1576 let Documentation = [TransparentUnionDocs];
1577 let LangOpts = [COnly];
1580 def Unavailable : InheritableAttr {
1581 let Spellings = [GNU<"unavailable">];
1582 let Args = [StringArgument<"Message", 1>,
1583 EnumArgument<"ImplicitReason", "ImplicitReason",
1586 "IR_ARCForbiddenType",
1588 "IR_ARCForbiddenConversion",
1589 "IR_ARCInitReturnsUnrelated",
1590 "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
1591 let Documentation = [Undocumented];
1594 def ArcWeakrefUnavailable : InheritableAttr {
1595 let Spellings = [GNU<"objc_arc_weak_reference_unavailable">];
1596 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1597 let Documentation = [Undocumented];
1600 def ObjCGC : TypeAttr {
1601 let Spellings = [GNU<"objc_gc">];
1602 let Args = [IdentifierArgument<"Kind">];
1603 let Documentation = [Undocumented];
1606 def ObjCOwnership : InheritableAttr {
1607 let Spellings = [GNU<"objc_ownership">];
1608 let Args = [IdentifierArgument<"Kind">];
1610 let Documentation = [Undocumented];
1613 def ObjCRequiresPropertyDefs : InheritableAttr {
1614 let Spellings = [GNU<"objc_requires_property_definitions">];
1615 let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1616 let Documentation = [Undocumented];
1619 def Unused : InheritableAttr {
1620 let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">];
1621 let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
1622 Field, ObjCMethod, FunctionLike], WarnDiag,
1623 "ExpectedForMaybeUnused">;
1624 let Documentation = [WarnMaybeUnusedDocs];
1627 def Used : InheritableAttr {
1628 let Spellings = [GCC<"used">];
1629 let Documentation = [Undocumented];
1632 def Uuid : InheritableAttr {
1633 let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
1634 let Args = [StringArgument<"Guid">];
1635 let Subjects = SubjectList<[Record, Enum], WarnDiag, "ExpectedEnumOrClass">;
1636 // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
1637 // CPlusPlus && (MicrosoftExt || Borland)
1638 let LangOpts = [MicrosoftExt, Borland];
1639 let Documentation = [Undocumented];
1642 def VectorSize : TypeAttr {
1643 let Spellings = [GCC<"vector_size">];
1644 let Args = [ExprArgument<"NumBytes">];
1645 let Documentation = [Undocumented];
1648 def VecTypeHint : InheritableAttr {
1649 let Spellings = [GNU<"vec_type_hint">];
1650 let Args = [TypeArgument<"TypeHint">];
1651 let Subjects = SubjectList<[Function], ErrorDiag>;
1652 let Documentation = [Undocumented];
1655 def Visibility : InheritableAttr {
1657 let Spellings = [GCC<"visibility">];
1658 let Args = [EnumArgument<"Visibility", "VisibilityType",
1659 ["default", "hidden", "internal", "protected"],
1660 ["Default", "Hidden", "Hidden", "Protected"]>];
1661 let Documentation = [Undocumented];
1664 def TypeVisibility : InheritableAttr {
1666 let Spellings = [GNU<"type_visibility">, CXX11<"clang", "type_visibility">];
1667 let Args = [EnumArgument<"Visibility", "VisibilityType",
1668 ["default", "hidden", "internal", "protected"],
1669 ["Default", "Hidden", "Hidden", "Protected"]>];
1670 // let Subjects = [Tag, ObjCInterface, Namespace];
1671 let Documentation = [Undocumented];
1674 def VecReturn : InheritableAttr {
1675 let Spellings = [GNU<"vecreturn">];
1676 let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
1677 let Documentation = [Undocumented];
1680 def WarnUnused : InheritableAttr {
1681 let Spellings = [GNU<"warn_unused">];
1682 let Subjects = SubjectList<[Record]>;
1683 let Documentation = [Undocumented];
1686 def WarnUnusedResult : InheritableAttr {
1687 let Spellings = [CXX11<"", "nodiscard", 201603>,
1688 CXX11<"clang", "warn_unused_result">,
1689 GCC<"warn_unused_result">];
1690 let Subjects = SubjectList<[ObjCMethod, Enum, CXXRecord, FunctionLike],
1691 WarnDiag, "ExpectedFunctionMethodEnumOrClass">;
1692 let Documentation = [WarnUnusedResultsDocs];
1695 def Weak : InheritableAttr {
1696 let Spellings = [GCC<"weak">];
1697 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
1698 let Documentation = [Undocumented];
1701 def WeakImport : InheritableAttr {
1702 let Spellings = [GNU<"weak_import">];
1703 let Documentation = [Undocumented];
1706 def WeakRef : InheritableAttr {
1707 let Spellings = [GCC<"weakref">];
1708 // A WeakRef that has an argument is treated as being an AliasAttr
1709 let Args = [StringArgument<"Aliasee", 1>];
1710 let Subjects = SubjectList<[Var, Function], ErrorDiag>;
1711 let Documentation = [Undocumented];
1714 def LTOVisibilityPublic : InheritableAttr {
1715 let Spellings = [CXX11<"clang", "lto_visibility_public">];
1716 let Subjects = SubjectList<[Record]>;
1717 let Documentation = [LTOVisibilityDocs];
1720 def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
1721 // NOTE: If you add any additional spellings, ARMInterrupt's,
1722 // MSP430Interrupt's and MipsInterrupt's spellings must match.
1723 let Spellings = [GNU<"interrupt">];
1724 let Subjects = SubjectList<[HasFunctionProto]>;
1725 let ParseKind = "Interrupt";
1726 let HasCustomParsing = 1;
1727 let Documentation = [AnyX86InterruptDocs];
1730 def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetX86> {
1731 let Spellings = [GNU<"force_align_arg_pointer">];
1732 // Technically, this appertains to a FunctionDecl, but the target-specific
1733 // code silently allows anything function-like (such as typedefs or function
1734 // pointers), but does not apply the attribute to them.
1735 let Documentation = [Undocumented];
1738 def NoSanitize : InheritableAttr {
1739 let Spellings = [GNU<"no_sanitize">, CXX11<"clang", "no_sanitize">];
1740 let Args = [VariadicStringArgument<"Sanitizers">];
1741 let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag,
1742 "ExpectedFunctionMethodOrGlobalVar">;
1743 let Documentation = [NoSanitizeDocs];
1744 let AdditionalMembers = [{
1745 SanitizerMask getMask() const {
1746 SanitizerMask Mask = 0;
1747 for (auto SanitizerName : sanitizers()) {
1748 SanitizerMask ParsedMask =
1749 parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
1750 Mask |= expandSanitizerGroups(ParsedMask);
1757 // Attributes to disable a specific sanitizer. No new sanitizers should be added
1758 // to this list; the no_sanitize attribute should be extended instead.
1759 def NoSanitizeSpecific : InheritableAttr {
1760 let Spellings = [GCC<"no_address_safety_analysis">,
1761 GCC<"no_sanitize_address">,
1762 GCC<"no_sanitize_thread">,
1763 GNU<"no_sanitize_memory">];
1764 let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
1765 "ExpectedFunctionOrGlobalVar">;
1766 let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
1767 NoSanitizeMemoryDocs];
1771 // C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
1773 def GuardedVar : InheritableAttr {
1774 let Spellings = [GNU<"guarded_var">];
1775 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1776 "ExpectedFieldOrGlobalVar">;
1777 let Documentation = [Undocumented];
1780 def PtGuardedVar : InheritableAttr {
1781 let Spellings = [GNU<"pt_guarded_var">];
1782 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1783 "ExpectedFieldOrGlobalVar">;
1784 let Documentation = [Undocumented];
1787 def Lockable : InheritableAttr {
1788 let Spellings = [GNU<"lockable">];
1789 let Subjects = SubjectList<[Record]>;
1790 let Documentation = [Undocumented];
1791 let ASTNode = 0; // Replaced by Capability
1794 def ScopedLockable : InheritableAttr {
1795 let Spellings = [GNU<"scoped_lockable">];
1796 let Subjects = SubjectList<[Record]>;
1797 let Documentation = [Undocumented];
1800 def Capability : InheritableAttr {
1801 let Spellings = [GNU<"capability">, CXX11<"clang", "capability">,
1802 GNU<"shared_capability">,
1803 CXX11<"clang", "shared_capability">];
1804 let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
1805 "ExpectedStructOrUnionOrTypedef">;
1806 let Args = [StringArgument<"Name">];
1807 let Accessors = [Accessor<"isShared",
1808 [GNU<"shared_capability">,
1809 CXX11<"clang","shared_capability">]>];
1810 let Documentation = [Undocumented];
1811 let AdditionalMembers = [{
1812 bool isMutex() const { return getName().equals_lower("mutex"); }
1813 bool isRole() const { return getName().equals_lower("role"); }
1817 def AssertCapability : InheritableAttr {
1818 let Spellings = [GNU<"assert_capability">,
1819 CXX11<"clang", "assert_capability">,
1820 GNU<"assert_shared_capability">,
1821 CXX11<"clang", "assert_shared_capability">];
1822 let Subjects = SubjectList<[Function]>;
1824 let TemplateDependent = 1;
1825 let ParseArgumentsAsUnevaluated = 1;
1826 let DuplicatesAllowedWhileMerging = 1;
1827 let Args = [ExprArgument<"Expr">];
1828 let Accessors = [Accessor<"isShared",
1829 [GNU<"assert_shared_capability">,
1830 CXX11<"clang", "assert_shared_capability">]>];
1831 let Documentation = [AssertCapabilityDocs];
1834 def AcquireCapability : InheritableAttr {
1835 let Spellings = [GNU<"acquire_capability">,
1836 CXX11<"clang", "acquire_capability">,
1837 GNU<"acquire_shared_capability">,
1838 CXX11<"clang", "acquire_shared_capability">,
1839 GNU<"exclusive_lock_function">,
1840 GNU<"shared_lock_function">];
1841 let Subjects = SubjectList<[Function]>;
1843 let TemplateDependent = 1;
1844 let ParseArgumentsAsUnevaluated = 1;
1845 let DuplicatesAllowedWhileMerging = 1;
1846 let Args = [VariadicExprArgument<"Args">];
1847 let Accessors = [Accessor<"isShared",
1848 [GNU<"acquire_shared_capability">,
1849 CXX11<"clang", "acquire_shared_capability">,
1850 GNU<"shared_lock_function">]>];
1851 let Documentation = [AcquireCapabilityDocs];
1854 def TryAcquireCapability : InheritableAttr {
1855 let Spellings = [GNU<"try_acquire_capability">,
1856 CXX11<"clang", "try_acquire_capability">,
1857 GNU<"try_acquire_shared_capability">,
1858 CXX11<"clang", "try_acquire_shared_capability">];
1859 let Subjects = SubjectList<[Function],
1862 let TemplateDependent = 1;
1863 let ParseArgumentsAsUnevaluated = 1;
1864 let DuplicatesAllowedWhileMerging = 1;
1865 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
1866 let Accessors = [Accessor<"isShared",
1867 [GNU<"try_acquire_shared_capability">,
1868 CXX11<"clang", "try_acquire_shared_capability">]>];
1869 let Documentation = [TryAcquireCapabilityDocs];
1872 def ReleaseCapability : InheritableAttr {
1873 let Spellings = [GNU<"release_capability">,
1874 CXX11<"clang", "release_capability">,
1875 GNU<"release_shared_capability">,
1876 CXX11<"clang", "release_shared_capability">,
1877 GNU<"release_generic_capability">,
1878 CXX11<"clang", "release_generic_capability">,
1879 GNU<"unlock_function">];
1880 let Subjects = SubjectList<[Function]>;
1882 let TemplateDependent = 1;
1883 let ParseArgumentsAsUnevaluated = 1;
1884 let DuplicatesAllowedWhileMerging = 1;
1885 let Args = [VariadicExprArgument<"Args">];
1886 let Accessors = [Accessor<"isShared",
1887 [GNU<"release_shared_capability">,
1888 CXX11<"clang", "release_shared_capability">]>,
1889 Accessor<"isGeneric",
1890 [GNU<"release_generic_capability">,
1891 CXX11<"clang", "release_generic_capability">,
1892 GNU<"unlock_function">]>];
1893 let Documentation = [ReleaseCapabilityDocs];
1896 def RequiresCapability : InheritableAttr {
1897 let Spellings = [GNU<"requires_capability">,
1898 CXX11<"clang", "requires_capability">,
1899 GNU<"exclusive_locks_required">,
1900 GNU<"requires_shared_capability">,
1901 CXX11<"clang", "requires_shared_capability">,
1902 GNU<"shared_locks_required">];
1903 let Args = [VariadicExprArgument<"Args">];
1905 let TemplateDependent = 1;
1906 let ParseArgumentsAsUnevaluated = 1;
1907 let DuplicatesAllowedWhileMerging = 1;
1908 let Subjects = SubjectList<[Function]>;
1909 let Accessors = [Accessor<"isShared", [GNU<"requires_shared_capability">,
1910 GNU<"shared_locks_required">,
1911 CXX11<"clang","requires_shared_capability">]>];
1912 let Documentation = [Undocumented];
1915 def NoThreadSafetyAnalysis : InheritableAttr {
1916 let Spellings = [GNU<"no_thread_safety_analysis">];
1917 let Subjects = SubjectList<[Function]>;
1918 let Documentation = [Undocumented];
1921 def GuardedBy : InheritableAttr {
1922 let Spellings = [GNU<"guarded_by">];
1923 let Args = [ExprArgument<"Arg">];
1925 let TemplateDependent = 1;
1926 let ParseArgumentsAsUnevaluated = 1;
1927 let DuplicatesAllowedWhileMerging = 1;
1928 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1929 "ExpectedFieldOrGlobalVar">;
1930 let Documentation = [Undocumented];
1933 def PtGuardedBy : InheritableAttr {
1934 let Spellings = [GNU<"pt_guarded_by">];
1935 let Args = [ExprArgument<"Arg">];
1937 let TemplateDependent = 1;
1938 let ParseArgumentsAsUnevaluated = 1;
1939 let DuplicatesAllowedWhileMerging = 1;
1940 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1941 "ExpectedFieldOrGlobalVar">;
1942 let Documentation = [Undocumented];
1945 def AcquiredAfter : InheritableAttr {
1946 let Spellings = [GNU<"acquired_after">];
1947 let Args = [VariadicExprArgument<"Args">];
1949 let TemplateDependent = 1;
1950 let ParseArgumentsAsUnevaluated = 1;
1951 let DuplicatesAllowedWhileMerging = 1;
1952 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1953 "ExpectedFieldOrGlobalVar">;
1954 let Documentation = [Undocumented];
1957 def AcquiredBefore : InheritableAttr {
1958 let Spellings = [GNU<"acquired_before">];
1959 let Args = [VariadicExprArgument<"Args">];
1961 let TemplateDependent = 1;
1962 let ParseArgumentsAsUnevaluated = 1;
1963 let DuplicatesAllowedWhileMerging = 1;
1964 let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1965 "ExpectedFieldOrGlobalVar">;
1966 let Documentation = [Undocumented];
1969 def AssertExclusiveLock : InheritableAttr {
1970 let Spellings = [GNU<"assert_exclusive_lock">];
1971 let Args = [VariadicExprArgument<"Args">];
1973 let TemplateDependent = 1;
1974 let ParseArgumentsAsUnevaluated = 1;
1975 let DuplicatesAllowedWhileMerging = 1;
1976 let Subjects = SubjectList<[Function]>;
1977 let Documentation = [Undocumented];
1980 def AssertSharedLock : InheritableAttr {
1981 let Spellings = [GNU<"assert_shared_lock">];
1982 let Args = [VariadicExprArgument<"Args">];
1984 let TemplateDependent = 1;
1985 let ParseArgumentsAsUnevaluated = 1;
1986 let DuplicatesAllowedWhileMerging = 1;
1987 let Subjects = SubjectList<[Function]>;
1988 let Documentation = [Undocumented];
1991 // The first argument is an integer or boolean value specifying the return value
1992 // of a successful lock acquisition.
1993 def ExclusiveTrylockFunction : InheritableAttr {
1994 let Spellings = [GNU<"exclusive_trylock_function">];
1995 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
1997 let TemplateDependent = 1;
1998 let ParseArgumentsAsUnevaluated = 1;
1999 let DuplicatesAllowedWhileMerging = 1;
2000 let Subjects = SubjectList<[Function]>;
2001 let Documentation = [Undocumented];
2004 // The first argument is an integer or boolean value specifying the return value
2005 // of a successful lock acquisition.
2006 def SharedTrylockFunction : InheritableAttr {
2007 let Spellings = [GNU<"shared_trylock_function">];
2008 let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2010 let TemplateDependent = 1;
2011 let ParseArgumentsAsUnevaluated = 1;
2012 let DuplicatesAllowedWhileMerging = 1;
2013 let Subjects = SubjectList<[Function]>;
2014 let Documentation = [Undocumented];
2017 def LockReturned : InheritableAttr {
2018 let Spellings = [GNU<"lock_returned">];
2019 let Args = [ExprArgument<"Arg">];
2021 let TemplateDependent = 1;
2022 let ParseArgumentsAsUnevaluated = 1;
2023 let Subjects = SubjectList<[Function]>;
2024 let Documentation = [Undocumented];
2027 def LocksExcluded : InheritableAttr {
2028 let Spellings = [GNU<"locks_excluded">];
2029 let Args = [VariadicExprArgument<"Args">];
2031 let TemplateDependent = 1;
2032 let ParseArgumentsAsUnevaluated = 1;
2033 let DuplicatesAllowedWhileMerging = 1;
2034 let Subjects = SubjectList<[Function]>;
2035 let Documentation = [Undocumented];
2038 // C/C++ consumed attributes.
2040 def Consumable : InheritableAttr {
2041 let Spellings = [GNU<"consumable">];
2042 let Subjects = SubjectList<[CXXRecord]>;
2043 let Args = [EnumArgument<"DefaultState", "ConsumedState",
2044 ["unknown", "consumed", "unconsumed"],
2045 ["Unknown", "Consumed", "Unconsumed"]>];
2046 let Documentation = [ConsumableDocs];
2049 def ConsumableAutoCast : InheritableAttr {
2050 let Spellings = [GNU<"consumable_auto_cast_state">];
2051 let Subjects = SubjectList<[CXXRecord]>;
2052 let Documentation = [Undocumented];
2055 def ConsumableSetOnRead : InheritableAttr {
2056 let Spellings = [GNU<"consumable_set_state_on_read">];
2057 let Subjects = SubjectList<[CXXRecord]>;
2058 let Documentation = [Undocumented];
2061 def CallableWhen : InheritableAttr {
2062 let Spellings = [GNU<"callable_when">];
2063 let Subjects = SubjectList<[CXXMethod]>;
2064 let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
2065 ["unknown", "consumed", "unconsumed"],
2066 ["Unknown", "Consumed", "Unconsumed"]>];
2067 let Documentation = [CallableWhenDocs];
2070 def ParamTypestate : InheritableAttr {
2071 let Spellings = [GNU<"param_typestate">];
2072 let Subjects = SubjectList<[ParmVar]>;
2073 let Args = [EnumArgument<"ParamState", "ConsumedState",
2074 ["unknown", "consumed", "unconsumed"],
2075 ["Unknown", "Consumed", "Unconsumed"]>];
2076 let Documentation = [ParamTypestateDocs];
2079 def ReturnTypestate : InheritableAttr {
2080 let Spellings = [GNU<"return_typestate">];
2081 let Subjects = SubjectList<[Function, ParmVar]>;
2082 let Args = [EnumArgument<"State", "ConsumedState",
2083 ["unknown", "consumed", "unconsumed"],
2084 ["Unknown", "Consumed", "Unconsumed"]>];
2085 let Documentation = [ReturnTypestateDocs];
2088 def SetTypestate : InheritableAttr {
2089 let Spellings = [GNU<"set_typestate">];
2090 let Subjects = SubjectList<[CXXMethod]>;
2091 let Args = [EnumArgument<"NewState", "ConsumedState",
2092 ["unknown", "consumed", "unconsumed"],
2093 ["Unknown", "Consumed", "Unconsumed"]>];
2094 let Documentation = [SetTypestateDocs];
2097 def TestTypestate : InheritableAttr {
2098 let Spellings = [GNU<"test_typestate">];
2099 let Subjects = SubjectList<[CXXMethod]>;
2100 let Args = [EnumArgument<"TestState", "ConsumedState",
2101 ["consumed", "unconsumed"],
2102 ["Consumed", "Unconsumed"]>];
2103 let Documentation = [TestTypestateDocs];
2106 // Type safety attributes for `void *' pointers and type tags.
2108 def ArgumentWithTypeTag : InheritableAttr {
2109 let Spellings = [GNU<"argument_with_type_tag">,
2110 GNU<"pointer_with_type_tag">];
2111 let Args = [IdentifierArgument<"ArgumentKind">,
2112 UnsignedArgument<"ArgumentIdx">,
2113 UnsignedArgument<"TypeTagIdx">,
2114 BoolArgument<"IsPointer">];
2115 let HasCustomParsing = 1;
2116 let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
2119 def TypeTagForDatatype : InheritableAttr {
2120 let Spellings = [GNU<"type_tag_for_datatype">];
2121 let Args = [IdentifierArgument<"ArgumentKind">,
2122 TypeArgument<"MatchingCType">,
2123 BoolArgument<"LayoutCompatible">,
2124 BoolArgument<"MustBeNull">];
2125 // let Subjects = SubjectList<[Var], ErrorDiag>;
2126 let HasCustomParsing = 1;
2127 let Documentation = [TypeTagForDatatypeDocs];
2130 // Microsoft-related attributes
2132 def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
2133 let Spellings = [Declspec<"novtable">];
2134 let Subjects = SubjectList<[CXXRecord]>;
2135 let Documentation = [MSNoVTableDocs];
2139 let Spellings = [Declspec<"property">];
2142 def MSStruct : InheritableAttr {
2143 let Spellings = [GCC<"ms_struct">];
2144 let Subjects = SubjectList<[Record]>;
2145 let Documentation = [Undocumented];
2148 def DLLExport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2149 let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
2150 let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2151 let Documentation = [DLLExportDocs];
2154 def DLLImport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2155 let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
2156 let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2157 let Documentation = [DLLImportDocs];
2160 def SelectAny : InheritableAttr {
2161 let Spellings = [Declspec<"selectany">];
2162 let LangOpts = [MicrosoftExt];
2163 let Documentation = [Undocumented];
2167 let Spellings = [Declspec<"thread">];
2168 let LangOpts = [MicrosoftExt];
2169 let Documentation = [ThreadDocs];
2170 let Subjects = SubjectList<[Var]>;
2173 def Win64 : IgnoredAttr {
2174 let Spellings = [Keyword<"__w64">];
2175 let LangOpts = [MicrosoftExt];
2178 def Ptr32 : TypeAttr {
2179 let Spellings = [Keyword<"__ptr32">];
2180 let Documentation = [Undocumented];
2183 def Ptr64 : TypeAttr {
2184 let Spellings = [Keyword<"__ptr64">];
2185 let Documentation = [Undocumented];
2188 def SPtr : TypeAttr {
2189 let Spellings = [Keyword<"__sptr">];
2190 let Documentation = [Undocumented];
2193 def UPtr : TypeAttr {
2194 let Spellings = [Keyword<"__uptr">];
2195 let Documentation = [Undocumented];
2198 def MSInheritance : InheritableAttr {
2199 let LangOpts = [MicrosoftExt];
2200 let Args = [DefaultBoolArgument<"BestCase", 1>];
2201 let Spellings = [Keyword<"__single_inheritance">,
2202 Keyword<"__multiple_inheritance">,
2203 Keyword<"__virtual_inheritance">,
2204 Keyword<"__unspecified_inheritance">];
2205 let AdditionalMembers = [{
2206 static bool hasVBPtrOffsetField(Spelling Inheritance) {
2207 return Inheritance == Keyword_unspecified_inheritance;
2210 // Only member pointers to functions need a this adjustment, since it can be
2211 // combined with the field offset for data pointers.
2212 static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) {
2213 return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance;
2216 static bool hasVBTableOffsetField(Spelling Inheritance) {
2217 return Inheritance >= Keyword_virtual_inheritance;
2220 static bool hasOnlyOneField(bool IsMemberFunction,
2221 Spelling Inheritance) {
2222 if (IsMemberFunction)
2223 return Inheritance <= Keyword_single_inheritance;
2224 return Inheritance <= Keyword_multiple_inheritance;
2227 let Documentation = [MSInheritanceDocs];
2230 def MSVtorDisp : InheritableAttr {
2231 // This attribute has no spellings as it is only ever created implicitly.
2233 let Args = [UnsignedArgument<"vdm">];
2234 let SemaHandler = 0;
2236 let AdditionalMembers = [{
2243 Mode getVtorDispMode() const { return Mode(vdm); }
2245 let Documentation = [Undocumented];
2248 def InitSeg : Attr {
2249 let Spellings = [Pragma<"", "init_seg">];
2250 let Args = [StringArgument<"Section">];
2251 let SemaHandler = 0;
2252 let Documentation = [InitSegDocs];
2253 let AdditionalMembers = [{
2254 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2255 OS << '(' << getSection() << ')';
2260 def LoopHint : Attr {
2261 /// #pragma clang loop <option> directive
2262 /// vectorize: vectorizes loop operations if State == Enable.
2263 /// vectorize_width: vectorize loop operations with width 'Value'.
2264 /// interleave: interleave multiple loop iterations if State == Enable.
2265 /// interleave_count: interleaves 'Value' loop interations.
2266 /// unroll: fully unroll loop if State == Enable.
2267 /// unroll_count: unrolls loop 'Value' times.
2268 /// distribute: attempt to distribute loop if State == Enable
2270 /// #pragma unroll <argument> directive
2271 /// <no arg>: fully unrolls loop.
2272 /// boolean: fully unrolls loop if State == Enable.
2273 /// expression: unrolls loop 'Value' times.
2275 let Spellings = [Pragma<"clang", "loop">, Pragma<"", "unroll">,
2276 Pragma<"", "nounroll">];
2278 /// State of the loop optimization specified by the spelling.
2279 let Args = [EnumArgument<"Option", "OptionType",
2280 ["vectorize", "vectorize_width", "interleave", "interleave_count",
2281 "unroll", "unroll_count", "distribute"],
2282 ["Vectorize", "VectorizeWidth", "Interleave", "InterleaveCount",
2283 "Unroll", "UnrollCount", "Distribute"]>,
2284 EnumArgument<"State", "LoopHintState",
2285 ["enable", "disable", "numeric", "assume_safety", "full"],
2286 ["Enable", "Disable", "Numeric", "AssumeSafety", "Full"]>,
2287 ExprArgument<"Value">];
2289 let AdditionalMembers = [{
2290 static const char *getOptionName(int Option) {
2292 case Vectorize: return "vectorize";
2293 case VectorizeWidth: return "vectorize_width";
2294 case Interleave: return "interleave";
2295 case InterleaveCount: return "interleave_count";
2296 case Unroll: return "unroll";
2297 case UnrollCount: return "unroll_count";
2298 case Distribute: return "distribute";
2300 llvm_unreachable("Unhandled LoopHint option.");
2303 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2304 unsigned SpellingIndex = getSpellingListIndex();
2305 // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
2306 // "nounroll" is already emitted as the pragma name.
2307 if (SpellingIndex == Pragma_nounroll)
2309 else if (SpellingIndex == Pragma_unroll) {
2310 OS << getValueString(Policy);
2314 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2315 OS << getOptionName(option) << getValueString(Policy);
2318 // Return a string containing the loop hint argument including the
2319 // enclosing parentheses.
2320 std::string getValueString(const PrintingPolicy &Policy) const {
2321 std::string ValueName;
2322 llvm::raw_string_ostream OS(ValueName);
2324 if (state == Numeric)
2325 value->printPretty(OS, nullptr, Policy);
2326 else if (state == Enable)
2328 else if (state == Full)
2330 else if (state == AssumeSafety)
2331 OS << "assume_safety";
2338 // Return a string suitable for identifying this attribute in diagnostics.
2339 std::string getDiagnosticName(const PrintingPolicy &Policy) const {
2340 unsigned SpellingIndex = getSpellingListIndex();
2341 if (SpellingIndex == Pragma_nounroll)
2342 return "#pragma nounroll";
2343 else if (SpellingIndex == Pragma_unroll)
2344 return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
2346 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2347 return getOptionName(option) + getValueString(Policy);
2351 let Documentation = [LoopHintDocs, UnrollHintDocs];
2354 def CapturedRecord : InheritableAttr {
2355 // This attribute has no spellings as it is only ever created implicitly.
2357 let SemaHandler = 0;
2358 let Documentation = [Undocumented];
2361 def OMPThreadPrivateDecl : InheritableAttr {
2362 // This attribute has no spellings as it is only ever created implicitly.
2364 let SemaHandler = 0;
2365 let Documentation = [Undocumented];
2368 def OMPCaptureNoInit : InheritableAttr {
2369 // This attribute has no spellings as it is only ever created implicitly.
2371 let SemaHandler = 0;
2372 let Documentation = [Undocumented];
2375 def OMPDeclareSimdDecl : Attr {
2376 let Spellings = [Pragma<"omp", "declare simd">];
2377 let Subjects = SubjectList<[Function]>;
2378 let SemaHandler = 0;
2379 let HasCustomParsing = 1;
2380 let Documentation = [OMPDeclareSimdDocs];
2382 EnumArgument<"BranchState", "BranchStateTy",
2383 [ "", "inbranch", "notinbranch" ],
2384 [ "BS_Undefined", "BS_Inbranch", "BS_Notinbranch" ]>,
2385 ExprArgument<"Simdlen">, VariadicExprArgument<"Uniforms">,
2386 VariadicExprArgument<"Aligneds">, VariadicExprArgument<"Alignments">,
2387 VariadicExprArgument<"Linears">, VariadicUnsignedArgument<"Modifiers">,
2388 VariadicExprArgument<"Steps">
2390 let AdditionalMembers = [{
2391 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
2393 if (getBranchState() != BS_Undefined)
2394 OS << ConvertBranchStateTyToStr(getBranchState()) << " ";
2395 if (auto *E = getSimdlen()) {
2397 E->printPretty(OS, nullptr, Policy);
2400 if (uniforms_size() > 0) {
2402 StringRef Sep = "(";
2403 for (auto *E : uniforms()) {
2405 E->printPretty(OS, nullptr, Policy);
2410 alignments_iterator NI = alignments_begin();
2411 for (auto *E : aligneds()) {
2413 E->printPretty(OS, nullptr, Policy);
2416 (*NI)->printPretty(OS, nullptr, Policy);
2421 steps_iterator I = steps_begin();
2422 modifiers_iterator MI = modifiers_begin();
2423 for (auto *E : linears()) {
2425 if (*MI != OMPC_LINEAR_unknown)
2426 OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
2427 E->printPretty(OS, nullptr, Policy);
2428 if (*MI != OMPC_LINEAR_unknown)
2432 (*I)->printPretty(OS, nullptr, Policy);
2442 def OMPDeclareTargetDecl : Attr {
2443 let Spellings = [Pragma<"omp", "declare target">];
2444 let SemaHandler = 0;
2445 let Documentation = [OMPDeclareTargetDocs];
2447 EnumArgument<"MapType", "MapTypeTy",
2449 [ "MT_To", "MT_Link" ]>
2451 let AdditionalMembers = [{
2452 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2453 // Use fake syntax because it is for testing and debugging purpose only.
2454 if (getMapType() != MT_To)
2455 OS << ConvertMapTypeTyToStr(getMapType()) << " ";
2460 def InternalLinkage : InheritableAttr {
2461 let Spellings = [GNU<"internal_linkage">, CXX11<"clang", "internal_linkage">];
2462 let Subjects = SubjectList<[Var, Function, CXXRecord]>;
2463 let Documentation = [InternalLinkageDocs];