1////////////////////////////////////////////////////////////////////////////////
2// Note: This file is a work in progress. Please do not apply non-trivial
3// updates unless you have talked to Sean Hunt <rideau3@gmail.com> prior.
4// Merely adding a new attribute is a trivial update.
5////////////////////////////////////////////////////////////////////////////////
6
7// An attribute's subject is whatever it appertains to. In this file, it is
8// more accurately a list of things that an attribute can appertain to. All
9// Decls and Stmts are possibly AttrSubjects (even though the syntax may not
10// allow attributes on a given Decl or Stmt).
11class AttrSubject;
12
13include "clang/Basic/DeclNodes.td"
14include "clang/Basic/StmtNodes.td"
15
16// A subset-subject is an AttrSubject constrained to operate only on some subset
17// of that subject.
18//
19// The description is used in output messages to specify what the subject
20// represents. FIXME: Deal with translation issues.
21//
22// The code fragment is a boolean expression that will confirm that the subject
23// meets the requirements; the subject will have the name S, and will have the
24// type specified by the base. It should be a simple boolean expression.
25class SubsetSubject<AttrSubject base, string description, code check>
26    : AttrSubject {
27  AttrSubject Base = base;
28  string Description = description;
29  code CheckCode = check;
30}
31
32// This is the type of a variable which C++11 allows alignas(...) to appertain
33// to.
34def NormalVar : SubsetSubject<Var, "non-register, non-parameter variable",
35                              [{S->getStorageClass() != VarDecl::Register &&
36                                S->getKind() != Decl::ImplicitParam &&
37                                S->getKind() != Decl::ParmVar &&
38                                S->getKind() != Decl::NonTypeTemplateParm}]>;
39def CXXVirtualMethod : SubsetSubject<CXXRecord, "virtual member function",
40                                     [{S->isVirtual()}]>;
41def NonBitField : SubsetSubject<Field, "non-bit field",
42                                [{!S->isBitField()}]>;
43
44// A single argument to an attribute
45class Argument<string name> {
46  string Name = name;
47}
48
49class BoolArgument<string name> : Argument<name>;
50class IdentifierArgument<string name> : Argument<name>;
51class IntArgument<string name> : Argument<name>;
52class StringArgument<string name> : Argument<name>;
53class ExprArgument<string name> : Argument<name>;
54class FunctionArgument<string name> : Argument<name>;
55class TypeArgument<string name> : Argument<name>;
56class UnsignedArgument<string name> : Argument<name>;
57class SourceLocArgument<string name> : Argument<name>;
58class VariadicUnsignedArgument<string name> : Argument<name>;
59class VariadicExprArgument<string name> : Argument<name>;
60
61// A version of the form major.minor[.subminor].
62class VersionArgument<string name> : Argument<name>;
63
64// This one's a doozy, so it gets its own special type
65// It can be an unsigned integer, or a type. Either can
66// be dependent.
67class AlignedArgument<string name> : Argument<name>;
68
69// An integer argument with a default value
70class DefaultIntArgument<string name, int default> : IntArgument<name> {
71  int Default = default;
72}
73
74// This argument is more complex, it includes the enumerator type name,
75// a list of strings to accept, and a list of enumerators to map them to.
76class EnumArgument<string name, string type, list<string> values,
77                         list<string> enums> : Argument<name> {
78  string Type = type;
79  list<string> Values = values;
80  list<string> Enums = enums;
81}
82
83// This handles one spelling of an attribute.
84class Spelling<string name, string variety> {
85  string Name = name;
86  string Variety = variety;
87}
88
89class GNU<string name> : Spelling<name, "GNU">;
90class Declspec<string name> : Spelling<name, "Declspec">;
91class CXX11<string namespace, string name> : Spelling<name, "CXX11"> {
92  string Namespace = namespace;
93}
94class Keyword<string name> : Spelling<name, "Keyword">;
95
96class Accessor<string name, list<Spelling> spellings> {
97  string Name = name;
98  list<Spelling> Spellings = spellings;
99}
100
101class Attr {
102  // The various ways in which an attribute can be spelled in source
103  list<Spelling> Spellings;
104  // The things to which an attribute can appertain
105  list<AttrSubject> Subjects;
106  // The arguments allowed on an attribute
107  list<Argument> Args = [];
108  // Accessors which should be generated for the attribute.
109  list<Accessor> Accessors = [];
110  // Set to true for attributes with arguments which require delayed parsing.
111  bit LateParsed = 0;
112  // Set to false to prevent an attribute from being propagated from a template
113  // to the instantiation.
114  bit Clone = 1;
115  // Set to true for attributes which must be instantiated within templates
116  bit TemplateDependent = 0;
117  // Set to true for attributes that have a corresponding AST node.
118  bit ASTNode = 1;
119  // Set to true for attributes which have handler in Sema.
120  bit SemaHandler = 1;
121  // Set to true for attributes that are completely ignored.
122  bit Ignored = 0;
123  // Set to true if each of the spellings is a distinct attribute.
124  bit DistinctSpellings = 0;
125  // Any additional text that should be included verbatim in the class.
126  code AdditionalMembers = [{}];
127}
128
129/// A type attribute is not processed on a declaration or a statement.
130class TypeAttr : Attr {
131  let ASTNode = 0;
132}
133
134/// An inheritable attribute is inherited by later redeclarations.
135class InheritableAttr : Attr;
136
137/// A target-specific attribute that is meant to be processed via
138/// TargetAttributesSema::ProcessDeclAttribute.  This class is meant to be used
139/// as a mixin with InheritableAttr or Attr depending on the attribute's needs.
140class TargetSpecificAttr;
141
142/// An inheritable parameter attribute is inherited by later
143/// redeclarations, even when it's written on a parameter.
144class InheritableParamAttr : InheritableAttr;
145
146/// An ignored attribute, which we parse but discard with no checking.
147class IgnoredAttr : Attr {
148  let Ignored = 1;
149  let ASTNode = 0;
150  let SemaHandler = 0;
151}
152
153//
154// Attributes begin here
155//
156
157def AddressSpace : TypeAttr {
158  let Spellings = [GNU<"address_space">];
159  let Args = [IntArgument<"AddressSpace">];
160}
161
162def Alias : InheritableAttr {
163  let Spellings = [GNU<"alias">, CXX11<"gnu", "alias">];
164  let Args = [StringArgument<"Aliasee">];
165}
166
167def Aligned : InheritableAttr {
168  let Spellings = [GNU<"aligned">, Declspec<"align">, CXX11<"gnu", "aligned">,
169                   Keyword<"alignas">, Keyword<"_Alignas">];
170  let Subjects = [NonBitField, NormalVar, Tag];
171  let Args = [AlignedArgument<"Alignment">];
172  let Accessors = [Accessor<"isGNU", [GNU<"aligned">, CXX11<"gnu","aligned">]>,
173                   Accessor<"isC11", [Keyword<"_Alignas">]>,
174                   Accessor<"isAlignas", [Keyword<"alignas">,
175                                          Keyword<"_Alignas">]>,
176                   Accessor<"isDeclspec",[Declspec<"align">]>];
177}
178
179def AlignMac68k : InheritableAttr {
180  let Spellings = [];
181  let SemaHandler = 0;
182}
183
184def AllocSize : InheritableAttr {
185  let Spellings = [GNU<"alloc_size">, CXX11<"gnu", "alloc_size">];
186  let Args = [VariadicUnsignedArgument<"Args">];
187}
188
189def AlwaysInline : InheritableAttr {
190  let Spellings = [GNU<"always_inline">, CXX11<"gnu", "always_inline">];
191}
192
193def TLSModel : InheritableAttr {
194  let Spellings = [GNU<"tls_model">, CXX11<"gnu", "tls_model">];
195  let Subjects = [Var];
196  let Args = [StringArgument<"Model">];
197}
198
199def AnalyzerNoReturn : InheritableAttr {
200  let Spellings = [GNU<"analyzer_noreturn">];
201}
202
203def Annotate : InheritableParamAttr {
204  let Spellings = [GNU<"annotate">];
205  let Args = [StringArgument<"Annotation">];
206}
207
208def AsmLabel : InheritableAttr {
209  let Spellings = [];
210  let Args = [StringArgument<"Label">];
211  let SemaHandler = 0;
212}
213
214def Availability : InheritableAttr {
215  let Spellings = [GNU<"availability">];
216  let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
217              VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
218              BoolArgument<"unavailable">, StringArgument<"message">];
219  let AdditionalMembers =
220[{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
221    return llvm::StringSwitch<llvm::StringRef>(Platform)
222             .Case("ios", "iOS")
223             .Case("macosx", "OS X")
224             .Default(llvm::StringRef());
225} }];
226}
227
228def Blocks : InheritableAttr {
229  let Spellings = [GNU<"blocks">];
230  let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
231}
232
233def Bounded : IgnoredAttr {
234  let Spellings = [GNU<"bounded">];
235}
236
237def CarriesDependency : InheritableParamAttr {
238  let Spellings = [GNU<"carries_dependency">, CXX11<"","carries_dependency">,
239                   CXX11<"std","carries_dependency">];
240  let Subjects = [ParmVar, Function];
241}
242
243def CDecl : InheritableAttr {
244  let Spellings = [GNU<"cdecl">, CXX11<"gnu", "cdecl">, Keyword<"__cdecl">,
245                   Keyword<"_cdecl">];
246}
247
248// cf_audited_transfer indicates that the given function has been
249// audited and has been marked with the appropriate cf_consumed and
250// cf_returns_retained attributes.  It is generally applied by
251// '#pragma clang arc_cf_code_audited' rather than explicitly.
252def CFAuditedTransfer : InheritableAttr {
253  let Spellings = [GNU<"cf_audited_transfer">];
254  let Subjects = [Function];
255}
256
257// cf_unknown_transfer is an explicit opt-out of cf_audited_transfer.
258// It indicates that the function has unknown or unautomatable
259// transfer semantics.
260def CFUnknownTransfer : InheritableAttr {
261  let Spellings = [GNU<"cf_unknown_transfer">];
262  let Subjects = [Function];
263}
264
265def CFReturnsRetained : InheritableAttr {
266  let Spellings = [GNU<"cf_returns_retained">];
267  let Subjects = [ObjCMethod, Function];
268}
269
270def CFReturnsNotRetained : InheritableAttr {
271  let Spellings = [GNU<"cf_returns_not_retained">];
272  let Subjects = [ObjCMethod, Function];
273}
274
275def CFConsumed : InheritableParamAttr {
276  let Spellings = [GNU<"cf_consumed">];
277  let Subjects = [ParmVar];
278}
279
280def Cleanup : InheritableAttr {
281  let Spellings = [GNU<"cleanup">, CXX11<"gnu", "cleanup">];
282  let Args = [FunctionArgument<"FunctionDecl">];
283}
284
285def Cold : InheritableAttr {
286  let Spellings = [GNU<"cold">, CXX11<"gnu", "cold">];
287}
288
289def Common : InheritableAttr {
290  let Spellings = [GNU<"common">, CXX11<"gnu", "common">];
291}
292
293def Const : InheritableAttr {
294  let Spellings = [GNU<"const">, GNU<"__const">, CXX11<"gnu", "const">];
295}
296
297def Constructor : InheritableAttr {
298  let Spellings = [GNU<"constructor">, CXX11<"gnu", "constructor">];
299  let Args = [IntArgument<"Priority">];
300}
301
302def CUDAConstant : InheritableAttr {
303  let Spellings = [GNU<"constant">];
304}
305
306def CUDADevice : InheritableAttr {
307  let Spellings = [GNU<"device">];
308}
309
310def CUDAGlobal : InheritableAttr {
311  let Spellings = [GNU<"global">];
312}
313
314def CUDAHost : InheritableAttr {
315  let Spellings = [GNU<"host">];
316}
317
318def CUDALaunchBounds : InheritableAttr {
319  let Spellings = [GNU<"launch_bounds">];
320  let Args = [IntArgument<"MaxThreads">, DefaultIntArgument<"MinBlocks", 0>];
321}
322
323def CUDAShared : InheritableAttr {
324  let Spellings = [GNU<"shared">];
325}
326
327def C11NoReturn : InheritableAttr {
328  let Spellings = [Keyword<"_Noreturn">];
329  let Subjects = [Function];
330  let SemaHandler = 0;
331}
332
333def CXX11NoReturn : InheritableAttr {
334  let Spellings = [CXX11<"","noreturn">, CXX11<"std","noreturn">];
335  let Subjects = [Function];
336}
337
338def OpenCLKernel : InheritableAttr {
339  let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
340}
341
342def OpenCLImageAccess : Attr {
343  let Spellings = [GNU<"opencl_image_access">];
344  let Args = [IntArgument<"Access">];
345}
346
347def Kernel : Attr {
348  let Spellings = [GNU<"kernel">];
349}
350
351def Deprecated : InheritableAttr {
352  let Spellings = [GNU<"deprecated">, CXX11<"gnu", "deprecated">];
353  let Args = [StringArgument<"Message">];
354}
355
356def Destructor : InheritableAttr {
357  let Spellings = [GNU<"destructor">, CXX11<"gnu", "destructor">];
358  let Args = [IntArgument<"Priority">];
359}
360
361def ExtVectorType : Attr {
362  let Spellings = [GNU<"ext_vector_type">];
363  let Args = [ExprArgument<"NumElements">];
364  let ASTNode = 0;
365}
366
367def FallThrough : Attr {
368  let Spellings = [CXX11<"clang", "fallthrough">];
369  let Subjects = [NullStmt];
370}
371
372def FastCall : InheritableAttr {
373  let Spellings = [GNU<"fastcall">, CXX11<"gnu", "fastcall">,
374                   Keyword<"__fastcall">, Keyword<"_fastcall">];
375}
376
377def Final : InheritableAttr {
378  let Spellings = [];
379  let SemaHandler = 0;
380}
381
382def MinSize : InheritableAttr {
383  let Spellings = [GNU<"minsize">];
384  let Subjects = [Function];
385}
386
387def Format : InheritableAttr {
388  let Spellings = [GNU<"format">, CXX11<"gnu", "format">];
389  let Args = [StringArgument<"Type">, IntArgument<"FormatIdx">,
390              IntArgument<"FirstArg">];
391}
392
393def FormatArg : InheritableAttr {
394  let Spellings = [GNU<"format_arg">, CXX11<"gnu", "format_arg">];
395  let Args = [IntArgument<"FormatIdx">];
396}
397
398def GNUInline : InheritableAttr {
399  let Spellings = [GNU<"gnu_inline">, CXX11<"gnu", "gnu_inline">];
400}
401
402def Hot : InheritableAttr {
403  let Spellings = [GNU<"hot">, CXX11<"gnu", "hot">];
404}
405
406def IBAction : InheritableAttr {
407  let Spellings = [GNU<"ibaction">];
408}
409
410def IBOutlet : InheritableAttr {
411  let Spellings = [GNU<"iboutlet">];
412}
413
414def IBOutletCollection : InheritableAttr {
415  let Spellings = [GNU<"iboutletcollection">];
416  let Args = [TypeArgument<"Interface">, SourceLocArgument<"InterfaceLoc">];
417}
418
419def Malloc : InheritableAttr {
420  let Spellings = [GNU<"malloc">, CXX11<"gnu", "malloc">];
421}
422
423def MaxFieldAlignment : InheritableAttr {
424  let Spellings = [];
425  let Args = [UnsignedArgument<"Alignment">];
426  let SemaHandler = 0;
427}
428
429def MayAlias : InheritableAttr {
430  let Spellings = [GNU<"may_alias">, CXX11<"gnu", "may_alias">];
431}
432
433def MSP430Interrupt : InheritableAttr, TargetSpecificAttr {
434  let Spellings = [];
435  let Args = [UnsignedArgument<"Number">];
436  let SemaHandler = 0;
437}
438
439def Mips16 : InheritableAttr, TargetSpecificAttr {
440  let Spellings = [GNU<"mips16">, CXX11<"gnu", "mips16">];
441  let Subjects = [Function];
442}
443
444def Mode : Attr {
445  let Spellings = [GNU<"mode">, CXX11<"gnu", "mode">];
446  let Args = [IdentifierArgument<"Mode">];
447}
448
449def Naked : InheritableAttr {
450  let Spellings = [GNU<"naked">, CXX11<"gnu", "naked">];
451}
452
453def NeonPolyVectorType : TypeAttr {
454  let Spellings = [GNU<"neon_polyvector_type">];
455  let Args = [IntArgument<"NumElements">];
456}
457
458def NeonVectorType : TypeAttr {
459  let Spellings = [GNU<"neon_vector_type">];
460  let Args = [IntArgument<"NumElements">];
461}
462
463def ReturnsTwice : InheritableAttr {
464  let Spellings = [GNU<"returns_twice">, CXX11<"gnu", "returns_twice">];
465}
466
467def NoCommon : InheritableAttr {
468  let Spellings = [GNU<"nocommon">, CXX11<"gnu", "nocommon">];
469}
470
471def NoDebug : InheritableAttr {
472  let Spellings = [GNU<"nodebug">];
473}
474
475def NoInline : InheritableAttr {
476  let Spellings = [GNU<"noinline">, CXX11<"gnu", "noinline">];
477}
478
479def NoMips16 : InheritableAttr, TargetSpecificAttr {
480  let Spellings = [GNU<"nomips16">, CXX11<"gnu", "nomips16">];
481  let Subjects = [Function];
482}
483
484def NonNull : InheritableAttr {
485  let Spellings = [GNU<"nonnull">, CXX11<"gnu", "nonnull">];
486  let Args = [VariadicUnsignedArgument<"Args">];
487  let AdditionalMembers =
488[{bool isNonNull(unsigned idx) const {
489    for (args_iterator i = args_begin(), e = args_end();
490         i != e; ++i)
491      if (*i == idx)
492        return true;
493    return false;
494  } }];
495}
496
497def NoReturn : InheritableAttr {
498  let Spellings = [GNU<"noreturn">, CXX11<"gnu", "noreturn">];
499  // FIXME: Does GCC allow this on the function instead?
500  let Subjects = [Function];
501}
502
503def NoInstrumentFunction : InheritableAttr {
504  let Spellings = [GNU<"no_instrument_function">,
505                   CXX11<"gnu", "no_instrument_function">];
506  let Subjects = [Function];
507}
508
509def NoThrow : InheritableAttr {
510  let Spellings = [GNU<"nothrow">, CXX11<"gnu", "nothrow">];
511}
512
513def NSBridged : InheritableAttr {
514  let Spellings = [GNU<"ns_bridged">];
515  let Subjects = [Record];
516  let Args = [IdentifierArgument<"BridgedType">];
517}
518
519def NSReturnsRetained : InheritableAttr {
520  let Spellings = [GNU<"ns_returns_retained">];
521  let Subjects = [ObjCMethod, Function];
522}
523
524def NSReturnsNotRetained : InheritableAttr {
525  let Spellings = [GNU<"ns_returns_not_retained">];
526  let Subjects = [ObjCMethod, Function];
527}
528
529def NSReturnsAutoreleased : InheritableAttr {
530  let Spellings = [GNU<"ns_returns_autoreleased">];
531  let Subjects = [ObjCMethod, Function];
532}
533
534def NSConsumesSelf : InheritableAttr {
535  let Spellings = [GNU<"ns_consumes_self">];
536  let Subjects = [ObjCMethod];
537}
538
539def NSConsumed : InheritableParamAttr {
540  let Spellings = [GNU<"ns_consumed">];
541  let Subjects = [ParmVar];
542}
543
544def ObjCException : InheritableAttr {
545  let Spellings = [GNU<"objc_exception">];
546}
547
548def ObjCMethodFamily : InheritableAttr {
549  let Spellings = [GNU<"objc_method_family">];
550  let Subjects = [ObjCMethod];
551  let Args = [EnumArgument<"Family", "FamilyKind",
552               ["none", "alloc", "copy", "init", "mutableCopy", "new"],
553               ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
554                "OMF_mutableCopy", "OMF_new"]>];
555}
556
557def ObjCNSObject : InheritableAttr {
558  let Spellings = [GNU<"NSObject">];
559}
560
561def ObjCPreciseLifetime : InheritableAttr {
562  let Spellings = [GNU<"objc_precise_lifetime">];
563  let Subjects = [Var];
564}
565
566def ObjCReturnsInnerPointer : InheritableAttr {
567  let Spellings = [GNU<"objc_returns_inner_pointer">];
568  let Subjects = [ObjCMethod];
569}
570
571def ObjCRequiresSuper : InheritableAttr {
572  let Spellings = [GNU<"objc_requires_super">];
573  let Subjects = [ObjCMethod];
574}
575
576def ObjCRootClass : InheritableAttr {
577  let Spellings = [GNU<"objc_root_class">];
578  let Subjects = [ObjCInterface];
579}
580
581def Overloadable : Attr {
582  let Spellings = [GNU<"overloadable">];
583}
584
585def Override : InheritableAttr { 
586  let Spellings = [];
587  let SemaHandler = 0;
588}
589
590def Ownership : InheritableAttr {
591  let Spellings = [GNU<"ownership_holds">, GNU<"ownership_returns">,
592                   GNU<"ownership_takes">];
593  let DistinctSpellings = 1;
594  let Args = [EnumArgument<"OwnKind", "OwnershipKind",
595                    ["ownership_holds", "ownership_returns", "ownership_takes"],
596                    ["Holds", "Returns", "Takes"]>,
597              StringArgument<"Module">, VariadicUnsignedArgument<"Args">];
598}
599
600def Packed : InheritableAttr {
601  let Spellings = [GNU<"packed">, CXX11<"gnu", "packed">];
602}
603
604def PnaclCall : InheritableAttr {
605  let Spellings = [GNU<"pnaclcall">];
606}
607
608def IntelOclBicc : InheritableAttr {
609  let Spellings = [GNU<"intel_ocl_bicc">];
610}
611
612def Pcs : InheritableAttr {
613  let Spellings = [GNU<"pcs">, CXX11<"gnu", "pcs">];
614  let Args = [EnumArgument<"PCS", "PCSType",
615                           ["aapcs", "aapcs-vfp"],
616                           ["AAPCS", "AAPCS_VFP"]>];
617}
618
619def Pure : InheritableAttr {
620  let Spellings = [GNU<"pure">, CXX11<"gnu", "pure">];
621}
622
623def Regparm : InheritableAttr {
624  let Spellings = [GNU<"regparm">, CXX11<"gnu", "regparm">];
625  let Args = [UnsignedArgument<"NumParams">];
626}
627
628def ReqdWorkGroupSize : InheritableAttr {
629  let Spellings = [GNU<"reqd_work_group_size">];
630  let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
631              UnsignedArgument<"ZDim">];
632}
633
634def Endian : InheritableAttr {
635  let Spellings = [GNU<"endian">];
636  let Args = [IdentifierArgument<"platform">];
637}
638
639def WorkGroupSizeHint :  InheritableAttr {
640  let Spellings = [GNU<"work_group_size_hint">];
641  let Args = [UnsignedArgument<"XDim">, 
642              UnsignedArgument<"YDim">,
643              UnsignedArgument<"ZDim">];
644}
645
646def InitPriority : InheritableAttr {
647  let Spellings = [GNU<"init_priority">];
648  let Args = [UnsignedArgument<"Priority">];
649}
650
651def Section : InheritableAttr {
652  let Spellings = [GNU<"section">, CXX11<"gnu", "section">];
653  let Args = [StringArgument<"Name">];
654}
655
656def Sentinel : InheritableAttr {
657  let Spellings = [GNU<"sentinel">, CXX11<"gnu", "sentinel">];
658  let Args = [DefaultIntArgument<"Sentinel", 0>,
659              DefaultIntArgument<"NullPos", 0>];
660}
661
662def StdCall : InheritableAttr {
663  let Spellings = [GNU<"stdcall">, CXX11<"gnu", "stdcall">,
664                   Keyword<"__stdcall">, Keyword<"_stdcall">];
665}
666
667def ThisCall : InheritableAttr {
668  let Spellings = [GNU<"thiscall">, CXX11<"gnu", "thiscall">,
669                   Keyword<"__thiscall">, Keyword<"_thiscall">];
670}
671
672def Pascal : InheritableAttr {
673  let Spellings = [GNU<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
674}
675
676def TransparentUnion : InheritableAttr {
677  let Spellings = [GNU<"transparent_union">, CXX11<"gnu", "transparent_union">];
678}
679
680def Unavailable : InheritableAttr {
681  let Spellings = [GNU<"unavailable">];
682  let Args = [StringArgument<"Message">];
683}
684
685def ArcWeakrefUnavailable : InheritableAttr {
686  let Spellings = [GNU<"objc_arc_weak_reference_unavailable">];
687  let Subjects = [ObjCInterface];
688}
689
690def ObjCGC : TypeAttr {
691  let Spellings = [GNU<"objc_gc">];
692  let Args = [IdentifierArgument<"Kind">];
693}
694
695def ObjCOwnership : InheritableAttr {
696  let Spellings = [GNU<"objc_ownership">];
697  let Args = [IdentifierArgument<"Kind">];
698  let ASTNode = 0;
699}
700
701def ObjCRequiresPropertyDefs : InheritableAttr {
702  let Spellings = [GNU<"objc_requires_property_definitions">];
703  let Subjects = [ObjCInterface];
704}
705
706def Unused : InheritableAttr {
707  let Spellings = [GNU<"unused">, CXX11<"gnu", "unused">];
708}
709
710def Used : InheritableAttr {
711  let Spellings = [GNU<"used">, CXX11<"gnu", "used">];
712}
713
714def Uuid : InheritableAttr {
715  let Spellings = [GNU<"uuid">];
716  let Args = [StringArgument<"Guid">];
717  let Subjects = [CXXRecord];
718}
719
720def VectorSize : TypeAttr {
721  let Spellings = [GNU<"vector_size">, CXX11<"gnu", "vector_size">];
722  let Args = [ExprArgument<"NumBytes">];
723}
724
725def VecTypeHint : InheritableAttr {
726  let Spellings = [GNU<"vec_type_hint">];
727  let Args = [TypeArgument<"TypeHint">, SourceLocArgument<"TypeLoc">];
728}
729
730def Visibility : InheritableAttr {
731  let Clone = 0;
732  let Spellings = [GNU<"visibility">, CXX11<"gnu", "visibility">];
733  let Args = [EnumArgument<"Visibility", "VisibilityType",
734                           ["default", "hidden", "internal", "protected"],
735                           ["Default", "Hidden", "Hidden", "Protected"]>];
736}
737
738def TypeVisibility : InheritableAttr {
739  let Clone = 0;
740  let Spellings = [GNU<"type_visibility">, CXX11<"clang", "type_visibility">];
741  let Args = [EnumArgument<"Visibility", "VisibilityType",
742                           ["default", "hidden", "internal", "protected"],
743                           ["Default", "Hidden", "Hidden", "Protected"]>];
744}
745
746def VecReturn : InheritableAttr {
747  let Spellings = [GNU<"vecreturn">];
748  let Subjects = [CXXRecord];
749}
750
751def WarnUnused : InheritableAttr {
752  let Spellings = [GNU<"warn_unused">, CXX11<"gnu", "warn_unused">];
753  let Subjects = [Record];
754}
755
756def WarnUnusedResult : InheritableAttr {
757  let Spellings = [GNU<"warn_unused_result">,
758                   CXX11<"clang", "warn_unused_result">,
759                   CXX11<"gnu", "warn_unused_result">];
760}
761
762def Weak : InheritableAttr {
763  let Spellings = [GNU<"weak">, CXX11<"gnu", "weak">];
764}
765
766def WeakImport : InheritableAttr {
767  let Spellings = [GNU<"weak_import">];
768}
769
770def WeakRef : InheritableAttr {
771  let Spellings = [GNU<"weakref">, CXX11<"gnu", "weakref">];
772}
773
774def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr {
775  let Spellings = [];
776}
777
778// Attribute to disable AddressSanitizer (or equivalent) checks.
779def NoSanitizeAddress : InheritableAttr {
780  let Spellings = [GNU<"no_address_safety_analysis">,
781                   GNU<"no_sanitize_address">];
782}
783
784// Attribute to disable ThreadSanitizer checks.
785def NoSanitizeThread : InheritableAttr {
786  let Spellings = [GNU<"no_sanitize_thread">];
787}
788
789// Attribute to disable MemorySanitizer checks.
790def NoSanitizeMemory : InheritableAttr {
791  let Spellings = [GNU<"no_sanitize_memory">];
792}
793
794// C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
795
796def GuardedVar : InheritableAttr {
797  let Spellings = [GNU<"guarded_var">];
798}
799
800def PtGuardedVar : InheritableAttr {
801  let Spellings = [GNU<"pt_guarded_var">];
802}
803
804def Lockable : InheritableAttr {
805  let Spellings = [GNU<"lockable">];
806}
807
808def ScopedLockable : InheritableAttr {
809  let Spellings = [GNU<"scoped_lockable">];
810}
811
812def NoThreadSafetyAnalysis : InheritableAttr {
813  let Spellings = [GNU<"no_thread_safety_analysis">];
814}
815
816def GuardedBy : InheritableAttr {
817  let Spellings = [GNU<"guarded_by">];
818  let Args = [ExprArgument<"Arg">];
819  let LateParsed = 1;
820  let TemplateDependent = 1;
821}
822
823def PtGuardedBy : InheritableAttr {
824  let Spellings = [GNU<"pt_guarded_by">];
825  let Args = [ExprArgument<"Arg">];
826  let LateParsed = 1;
827  let TemplateDependent = 1;
828}
829
830def AcquiredAfter : InheritableAttr {
831  let Spellings = [GNU<"acquired_after">];
832  let Args = [VariadicExprArgument<"Args">];
833  let LateParsed = 1;
834  let TemplateDependent = 1;
835}
836
837def AcquiredBefore : InheritableAttr {
838  let Spellings = [GNU<"acquired_before">];
839  let Args = [VariadicExprArgument<"Args">];
840  let LateParsed = 1;
841  let TemplateDependent = 1;
842}
843
844def ExclusiveLockFunction : InheritableAttr {
845  let Spellings = [GNU<"exclusive_lock_function">];
846  let Args = [VariadicExprArgument<"Args">];
847  let LateParsed = 1;
848  let TemplateDependent = 1;
849}
850
851def SharedLockFunction : InheritableAttr {
852  let Spellings = [GNU<"shared_lock_function">];
853  let Args = [VariadicExprArgument<"Args">];
854  let LateParsed = 1;
855  let TemplateDependent = 1;
856}
857
858def AssertExclusiveLock : InheritableAttr {
859  let Spellings = [GNU<"assert_exclusive_lock">];
860  let Args = [VariadicExprArgument<"Args">];
861  let LateParsed = 1;
862  let TemplateDependent = 1;
863}
864
865def AssertSharedLock : InheritableAttr {
866  let Spellings = [GNU<"assert_shared_lock">];
867  let Args = [VariadicExprArgument<"Args">];
868  let LateParsed = 1;
869  let TemplateDependent = 1;
870}
871
872// The first argument is an integer or boolean value specifying the return value
873// of a successful lock acquisition.
874def ExclusiveTrylockFunction : InheritableAttr {
875  let Spellings = [GNU<"exclusive_trylock_function">];
876  let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
877  let LateParsed = 1;
878  let TemplateDependent = 1;
879}
880
881// The first argument is an integer or boolean value specifying the return value
882// of a successful lock acquisition.
883def SharedTrylockFunction : InheritableAttr {
884  let Spellings = [GNU<"shared_trylock_function">];
885  let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
886  let LateParsed = 1;
887  let TemplateDependent = 1;
888}
889
890def UnlockFunction : InheritableAttr {
891  let Spellings = [GNU<"unlock_function">];
892  let Args = [VariadicExprArgument<"Args">];
893  let LateParsed = 1;
894  let TemplateDependent = 1;
895}
896
897def LockReturned : InheritableAttr {
898  let Spellings = [GNU<"lock_returned">];
899  let Args = [ExprArgument<"Arg">];
900  let LateParsed = 1;
901  let TemplateDependent = 1;
902}
903
904def LocksExcluded : InheritableAttr {
905  let Spellings = [GNU<"locks_excluded">];
906  let Args = [VariadicExprArgument<"Args">];
907  let LateParsed = 1;
908  let TemplateDependent = 1;
909}
910
911def ExclusiveLocksRequired : InheritableAttr {
912  let Spellings = [GNU<"exclusive_locks_required">];
913  let Args = [VariadicExprArgument<"Args">];
914  let LateParsed = 1;
915  let TemplateDependent = 1;
916}
917
918def SharedLocksRequired : InheritableAttr {
919  let Spellings = [GNU<"shared_locks_required">];
920  let Args = [VariadicExprArgument<"Args">];
921  let LateParsed = 1;
922  let TemplateDependent = 1;
923}
924
925// Type safety attributes for `void *' pointers and type tags.
926
927def ArgumentWithTypeTag : InheritableAttr {
928  let Spellings = [GNU<"argument_with_type_tag">,
929                   GNU<"pointer_with_type_tag">];
930  let Args = [IdentifierArgument<"ArgumentKind">,
931              UnsignedArgument<"ArgumentIdx">,
932              UnsignedArgument<"TypeTagIdx">,
933              BoolArgument<"IsPointer">];
934  let Subjects = [Function];
935}
936
937def TypeTagForDatatype : InheritableAttr {
938  let Spellings = [GNU<"type_tag_for_datatype">];
939  let Args = [IdentifierArgument<"ArgumentKind">,
940              TypeArgument<"MatchingCType">,
941              BoolArgument<"LayoutCompatible">,
942              BoolArgument<"MustBeNull">];
943  let Subjects = [Var];
944}
945
946// Microsoft-related attributes
947
948def MsProperty : Attr {
949  let Spellings = [Declspec<"property">];
950}
951
952def MsStruct : InheritableAttr {
953  let Spellings = [Declspec<"ms_struct">];
954}
955
956def DLLExport : InheritableAttr, TargetSpecificAttr {
957  let Spellings = [Declspec<"dllexport">];
958}
959
960def DLLImport : InheritableAttr, TargetSpecificAttr {
961  let Spellings = [Declspec<"dllimport">];
962}
963
964def ForceInline : InheritableAttr {
965  let Spellings = [Keyword<"__forceinline">];
966}
967
968def SelectAny : InheritableAttr {
969  let Spellings = [Declspec<"selectany">];
970}
971
972def Win64 : InheritableAttr {
973  let Spellings = [Keyword<"__w64">];
974}
975
976def Ptr32 : TypeAttr {
977  let Spellings = [Keyword<"__ptr32">];
978}
979
980def Ptr64 : TypeAttr {
981  let Spellings = [Keyword<"__ptr64">];
982}
983
984def SPtr : TypeAttr {
985  let Spellings = [Keyword<"__sptr">];
986}
987
988def UPtr : TypeAttr {
989  let Spellings = [Keyword<"__uptr">];
990}
991
992class MSInheritanceAttr : InheritableAttr;
993
994def SingleInheritance : MSInheritanceAttr {
995  let Spellings = [Keyword<"__single_inheritance">];
996}
997
998def MultipleInheritance : MSInheritanceAttr {
999  let Spellings = [Keyword<"__multiple_inheritance">];
1000}
1001
1002def VirtualInheritance : MSInheritanceAttr {
1003  let Spellings = [Keyword<"__virtual_inheritance">];
1004}
1005
1006// This attribute doesn't have any spellings, but we can apply it implicitly to
1007// incomplete types that lack any of the other attributes.
1008def UnspecifiedInheritance : MSInheritanceAttr {
1009  let Spellings = [];
1010}
1011
1012def Unaligned : IgnoredAttr {
1013  let Spellings = [Keyword<"__unaligned">];
1014}
1015