1//==--- Attr.td - attribute definitions -----------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// The documentation is organized by category. Attributes can have category-
11// specific documentation that is collated within the larger document.
12class DocumentationCategory<string name> {
13  string Name = name;
14  code Content = [{}];
15}
16def DocCatFunction : DocumentationCategory<"Function Attributes">;
17def DocCatVariable : DocumentationCategory<"Variable Attributes">;
18def DocCatType : DocumentationCategory<"Type Attributes">;
19def 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.
23def DocCatUndocumented : DocumentationCategory<"Undocumented">;
24
25class 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;
30}
31
32// Specifies the documentation to be associated with the given category.
33class Documentation {
34  DocumentationCategory Category;
35  code Content;
36
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.
42  string Heading = "";
43
44  // When set, specifies that the attribute is deprecated and can optionally
45  // specify a replacement attribute.
46  DocDeprecated Deprecated;
47}
48
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.
52def Undocumented : Documentation {
53  let Category = DocCatUndocumented;
54}
55
56include "clang/Basic/AttrDocs.td"
57
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).
62class AttrSubject;
63
64include "clang/Basic/DeclNodes.td"
65include "clang/Basic/StmtNodes.td"
66
67// A subset-subject is an AttrSubject constrained to operate only on some subset
68// of that subject.
69//
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.
73class SubsetSubject<AttrSubject base, code check> : AttrSubject {
74  AttrSubject Base = base;
75  code CheckCode = check;
76}
77
78// This is the type of a variable which C++11 allows alignas(...) to appertain
79// to.
80def NormalVar : SubsetSubject<Var,
81                              [{S->getStorageClass() != VarDecl::Register &&
82                                S->getKind() != Decl::ImplicitParam &&
83                                S->getKind() != Decl::ParmVar &&
84                                S->getKind() != Decl::NonTypeTemplateParm}]>;
85def NonBitField : SubsetSubject<Field,
86                                [{!S->isBitField()}]>;
87
88def ObjCInstanceMethod : SubsetSubject<ObjCMethod,
89                                       [{S->isInstanceMethod()}]>;
90
91def ObjCInterfaceDeclInitMethod : SubsetSubject<ObjCMethod,
92                               [{S->getMethodFamily() == OMF_init &&
93                                 (isa<ObjCInterfaceDecl>(S->getDeclContext()) ||
94                                  (isa<ObjCCategoryDecl>(S->getDeclContext()) &&
95            cast<ObjCCategoryDecl>(S->getDeclContext())->IsClassExtension()))}]>;
96
97def Struct : SubsetSubject<Record,
98                           [{!S->isUnion()}]>;
99
100def TLSVar : SubsetSubject<Var,
101                           [{S->getTLSKind() != 0}]>;
102
103def SharedVar : SubsetSubject<Var,
104                              [{S->hasGlobalStorage() && !S->getTLSKind()}]>;
105
106def GlobalVar : SubsetSubject<Var,
107                             [{S->hasGlobalStorage()}]>;
108
109// FIXME: this hack is needed because DeclNodes.td defines the base Decl node
110// type to be a class, not a definition. This makes it impossible to create an
111// attribute subject which accepts a Decl. Normally, this is not a problem,
112// because the attribute can have no Subjects clause to accomplish this. But in
113// the case of a SubsetSubject, there's no way to express it without this hack.
114def DeclBase : AttrSubject;
115def FunctionLike : SubsetSubject<DeclBase,
116                                  [{S->getFunctionType(false) != nullptr}]>;
117
118def OpenCLKernelFunction : SubsetSubject<Function, [{
119  S->hasAttr<OpenCLKernelAttr>()
120}]>;
121
122// HasFunctionProto is a more strict version of FunctionLike, so it should
123// never be specified in a Subjects list along with FunctionLike (due to the
124// inclusive nature of subject testing).
125def HasFunctionProto : SubsetSubject<DeclBase,
126                                     [{(S->getFunctionType(true) != nullptr &&
127                              isa<FunctionProtoType>(S->getFunctionType())) ||
128                                       isa<ObjCMethodDecl>(S) ||
129                                       isa<BlockDecl>(S)}]>;
130
131// A single argument to an attribute
132class Argument<string name, bit optional, bit fake = 0> {
133  string Name = name;
134  bit Optional = optional;
135
136  /// A fake argument is used to store and serialize additional information
137  /// in an attribute without actually changing its parsing or pretty-printing.
138  bit Fake = fake;
139}
140
141class BoolArgument<string name, bit opt = 0> : Argument<name, opt>;
142class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
143class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
144class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
145class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
146class FunctionArgument<string name, bit opt = 0> : Argument<name, opt>;
147class TypeArgument<string name, bit opt = 0> : Argument<name, opt>;
148class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
149class VariadicUnsignedArgument<string name> : Argument<name, 1>;
150class VariadicExprArgument<string name> : Argument<name, 1>;
151class VariadicStringArgument<string name> : Argument<name, 1>;
152
153// A version of the form major.minor[.subminor].
154class VersionArgument<string name, bit opt = 0> : Argument<name, opt>;
155
156// This one's a doozy, so it gets its own special type
157// It can be an unsigned integer, or a type. Either can
158// be dependent.
159class AlignedArgument<string name, bit opt = 0> : Argument<name, opt>;
160
161// A bool argument with a default value
162class DefaultBoolArgument<string name, bit default> : BoolArgument<name, 1> {
163  bit Default = default;
164}
165
166// An integer argument with a default value
167class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
168  int Default = default;
169}
170
171// This argument is more complex, it includes the enumerator type name,
172// a list of strings to accept, and a list of enumerators to map them to.
173class EnumArgument<string name, string type, list<string> values,
174                   list<string> enums, bit opt = 0, bit fake = 0>
175    : Argument<name, opt, fake> {
176  string Type = type;
177  list<string> Values = values;
178  list<string> Enums = enums;
179}
180
181// FIXME: There should be a VariadicArgument type that takes any other type
182//        of argument and generates the appropriate type.
183class VariadicEnumArgument<string name, string type, list<string> values,
184                           list<string> enums> : Argument<name, 1>  {
185  string Type = type;
186  list<string> Values = values;
187  list<string> Enums = enums;
188}
189
190// This handles one spelling of an attribute.
191class Spelling<string name, string variety> {
192  string Name = name;
193  string Variety = variety;
194  bit KnownToGCC;
195}
196
197class GNU<string name> : Spelling<name, "GNU">;
198class Declspec<string name> : Spelling<name, "Declspec">;
199class CXX11<string namespace, string name, int version = 1>
200    : Spelling<name, "CXX11"> {
201  string Namespace = namespace;
202  int Version = version;
203}
204class Keyword<string name> : Spelling<name, "Keyword">;
205class Pragma<string namespace, string name> : Spelling<name, "Pragma"> {
206  string Namespace = namespace;
207}
208
209// The GCC spelling implies GNU<name, "GNU"> and CXX11<"gnu", name> and also
210// sets KnownToGCC to 1. This spelling should be used for any GCC-compatible
211// attributes.
212class GCC<string name> : Spelling<name, "GCC"> {
213  let KnownToGCC = 1;
214}
215
216class Accessor<string name, list<Spelling> spellings> {
217  string Name = name;
218  list<Spelling> Spellings = spellings;
219}
220
221class SubjectDiag<bit warn> {
222  bit Warn = warn;
223}
224def WarnDiag : SubjectDiag<1>;
225def ErrorDiag : SubjectDiag<0>;
226
227class SubjectList<list<AttrSubject> subjects, SubjectDiag diag = WarnDiag,
228                  string customDiag = ""> {
229  list<AttrSubject> Subjects = subjects;
230  SubjectDiag Diag = diag;
231  string CustomDiag = customDiag;
232}
233
234class LangOpt<string name, bit negated = 0> {
235  string Name = name;
236  bit Negated = negated;
237}
238def MicrosoftExt : LangOpt<"MicrosoftExt">;
239def Borland : LangOpt<"Borland">;
240def CUDA : LangOpt<"CUDA">;
241def COnly : LangOpt<"CPlusPlus", 1>;
242
243// Defines targets for target-specific attributes. The list of strings should
244// specify architectures for which the target applies, based off the ArchType
245// enumeration in Triple.h.
246class TargetArch<list<string> arches> {
247  list<string> Arches = arches;
248  list<string> OSes;
249  list<string> CXXABIs;
250}
251def TargetARM : TargetArch<["arm", "thumb"]>;
252def TargetMips : TargetArch<["mips", "mipsel"]>;
253def TargetMSP430 : TargetArch<["msp430"]>;
254def TargetX86 : TargetArch<["x86"]>;
255def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
256  let OSes = ["Win32"];
257}
258def TargetMicrosoftCXXABI : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
259  let CXXABIs = ["Microsoft"];
260}
261
262class Attr {
263  // The various ways in which an attribute can be spelled in source
264  list<Spelling> Spellings;
265  // The things to which an attribute can appertain
266  SubjectList Subjects;
267  // The arguments allowed on an attribute
268  list<Argument> Args = [];
269  // Accessors which should be generated for the attribute.
270  list<Accessor> Accessors = [];
271  // Set to true for attributes with arguments which require delayed parsing.
272  bit LateParsed = 0;
273  // Set to false to prevent an attribute from being propagated from a template
274  // to the instantiation.
275  bit Clone = 1;
276  // Set to true for attributes which must be instantiated within templates
277  bit TemplateDependent = 0;
278  // Set to true for attributes that have a corresponding AST node.
279  bit ASTNode = 1;
280  // Set to true for attributes which have handler in Sema.
281  bit SemaHandler = 1;
282  // Set to true for attributes that are completely ignored.
283  bit Ignored = 0;
284  // Set to true if the attribute's parsing does not match its semantic
285  // content. Eg) It parses 3 args, but semantically takes 4 args.  Opts out of
286  // common attribute error checking.
287  bit HasCustomParsing = 0;
288  // Set to true if all of the attribute's arguments should be parsed in an
289  // unevaluated context.
290  bit ParseArgumentsAsUnevaluated = 0;
291  // Set to true if this attribute can be duplicated on a subject when merging
292  // attributes. By default, attributes are not merged.
293  bit DuplicatesAllowedWhileMerging = 0;
294  // Lists language options, one of which is required to be true for the
295  // attribute to be applicable. If empty, no language options are required.
296  list<LangOpt> LangOpts = [];
297  // Any additional text that should be included verbatim in the class.
298  // Note: Any additional data members will leak and should be constructed
299  // externally on the ASTContext.
300  code AdditionalMembers = [{}];
301  // Any documentation that should be associated with the attribute. Since an
302  // attribute may be documented under multiple categories, more than one
303  // Documentation entry may be listed.
304  list<Documentation> Documentation;
305}
306
307/// A type attribute is not processed on a declaration or a statement.
308class TypeAttr : Attr {
309  // By default, type attributes do not get an AST node.
310  let ASTNode = 0;
311}
312
313/// An inheritable attribute is inherited by later redeclarations.
314class InheritableAttr : Attr;
315
316/// A target-specific attribute.  This class is meant to be used as a mixin
317/// with InheritableAttr or Attr depending on the attribute's needs.
318class TargetSpecificAttr<TargetArch target> {
319  TargetArch Target = target;
320  // Attributes are generally required to have unique spellings for their names
321  // so that the parser can determine what kind of attribute it has parsed.
322  // However, target-specific attributes are special in that the attribute only
323  // "exists" for a given target. So two target-specific attributes can share
324  // the same name when they exist in different targets. To support this, a
325  // Kind can be explicitly specified for a target-specific attribute. This
326  // corresponds to the AttributeList::AT_* enum that is generated and it
327  // should contain a shared value between the attributes.
328  //
329  // Target-specific attributes which use this feature should ensure that the
330  // spellings match exactly betweeen the attributes, and if the arguments or
331  // subjects differ, should specify HasCustomParsing = 1 and implement their
332  // own parsing and semantic handling requirements as-needed.
333  string ParseKind;
334}
335
336/// An inheritable parameter attribute is inherited by later
337/// redeclarations, even when it's written on a parameter.
338class InheritableParamAttr : InheritableAttr;
339
340/// An ignored attribute, which we parse but discard with no checking.
341class IgnoredAttr : Attr {
342  let Ignored = 1;
343  let ASTNode = 0;
344  let SemaHandler = 0;
345  let Documentation = [Undocumented];
346}
347
348//
349// Attributes begin here
350//
351
352def AddressSpace : TypeAttr {
353  let Spellings = [GNU<"address_space">];
354  let Args = [IntArgument<"AddressSpace">];
355  let Documentation = [Undocumented];
356}
357
358def Alias : Attr {
359  let Spellings = [GCC<"alias">];
360  let Args = [StringArgument<"Aliasee">];
361  let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
362                             "ExpectedFunctionGlobalVarMethodOrProperty">;
363  let Documentation = [Undocumented];
364}
365
366def Aligned : InheritableAttr {
367  let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
368                   Keyword<"_Alignas">];
369//  let Subjects = SubjectList<[NonBitField, NormalVar, Tag]>;
370  let Args = [AlignedArgument<"Alignment", 1>];
371  let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
372                   Accessor<"isC11", [Keyword<"_Alignas">]>,
373                   Accessor<"isAlignas", [Keyword<"alignas">,
374                                          Keyword<"_Alignas">]>,
375                   Accessor<"isDeclspec",[Declspec<"align">]>];
376  let Documentation = [Undocumented];
377}
378
379def AlignValue : Attr {
380  let Spellings = [
381    // Unfortunately, this is semantically an assertion, not a directive
382    // (something else must ensure the alignment), so aligned_value is a
383    // probably a better name. We might want to add an aligned_value spelling in
384    // the future (and a corresponding C++ attribute), but this can be done
385    // later once we decide if we also want them to have slightly-different
386    // semantics than Intel's align_value.
387    GNU<"align_value">
388    // Intel's compiler on Windows also supports:
389    // , Declspec<"align_value">
390  ];
391  let Args = [ExprArgument<"Alignment">];
392  let Subjects = SubjectList<[Var, TypedefName], WarnDiag,
393                             "ExpectedVariableOrTypedef">;
394  let Documentation = [AlignValueDocs];
395}
396
397def AlignMac68k : InheritableAttr {
398  // This attribute has no spellings as it is only ever created implicitly.
399  let Spellings = [];
400  let SemaHandler = 0;
401  let Documentation = [Undocumented];
402}
403
404def AlwaysInline : InheritableAttr {
405  let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
406  let Subjects = SubjectList<[Function]>;
407  let Documentation = [Undocumented];
408}
409
410def TLSModel : InheritableAttr {
411  let Spellings = [GCC<"tls_model">];
412  let Subjects = SubjectList<[TLSVar], ErrorDiag, "ExpectedTLSVar">;
413  let Args = [StringArgument<"Model">];
414  let Documentation = [TLSModelDocs];
415}
416
417def AnalyzerNoReturn : InheritableAttr {
418  let Spellings = [GNU<"analyzer_noreturn">];
419  let Documentation = [Undocumented];
420}
421
422def Annotate : InheritableParamAttr {
423  let Spellings = [GNU<"annotate">];
424  let Args = [StringArgument<"Annotation">];
425  let Documentation = [Undocumented];
426}
427
428def ARMInterrupt : InheritableAttr, TargetSpecificAttr<TargetARM> {
429  // NOTE: If you add any additional spellings, MSP430Interrupt's and
430  // MipsInterrupt's spellings must match.
431  let Spellings = [GNU<"interrupt">];
432  let Args = [EnumArgument<"Interrupt", "InterruptType",
433                           ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
434                           ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
435                           1>];
436  let ParseKind = "Interrupt";
437  let HasCustomParsing = 1;
438  let Documentation = [ARMInterruptDocs];
439}
440
441def AsmLabel : InheritableAttr {
442  let Spellings = [Keyword<"asm">, Keyword<"__asm__">];
443  let Args = [StringArgument<"Label">];
444  let SemaHandler = 0;
445  let Documentation = [Undocumented];
446}
447
448def Availability : InheritableAttr {
449  let Spellings = [GNU<"availability">];
450  let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
451              VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
452              BoolArgument<"unavailable">, StringArgument<"message">];
453  let AdditionalMembers =
454[{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
455    return llvm::StringSwitch<llvm::StringRef>(Platform)
456             .Case("android", "Android")
457             .Case("ios", "iOS")
458             .Case("macosx", "OS X")
459             .Case("tvos", "tvOS")
460             .Case("watchos", "watchOS")
461             .Case("ios_app_extension", "iOS (App Extension)")
462             .Case("macosx_app_extension", "OS X (App Extension)")
463             .Case("tvos_app_extension", "tvOS (App Extension)")
464             .Case("watchos_app_extension", "watchOS (App Extension)")
465             .Default(llvm::StringRef());
466} }];
467  let HasCustomParsing = 1;
468  let DuplicatesAllowedWhileMerging = 1;
469//  let Subjects = SubjectList<[Named]>;
470  let Documentation = [AvailabilityDocs];
471}
472
473def Blocks : InheritableAttr {
474  let Spellings = [GNU<"blocks">];
475  let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
476  let Documentation = [Undocumented];
477}
478
479def Bounded : IgnoredAttr {
480  let Spellings = [GNU<"bounded">];
481}
482
483def CarriesDependency : InheritableParamAttr {
484  let Spellings = [GNU<"carries_dependency">,
485                   CXX11<"","carries_dependency", 200809>];
486  let Subjects = SubjectList<[ParmVar, ObjCMethod, Function], ErrorDiag>;
487  let Documentation = [CarriesDependencyDocs];
488}
489
490def CDecl : InheritableAttr {
491  let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
492//  let Subjects = [Function, ObjCMethod];
493  let Documentation = [Undocumented];
494}
495
496// cf_audited_transfer indicates that the given function has been
497// audited and has been marked with the appropriate cf_consumed and
498// cf_returns_retained attributes.  It is generally applied by
499// '#pragma clang arc_cf_code_audited' rather than explicitly.
500def CFAuditedTransfer : InheritableAttr {
501  let Spellings = [GNU<"cf_audited_transfer">];
502  let Subjects = SubjectList<[Function], ErrorDiag>;
503  let Documentation = [Undocumented];
504}
505
506// cf_unknown_transfer is an explicit opt-out of cf_audited_transfer.
507// It indicates that the function has unknown or unautomatable
508// transfer semantics.
509def CFUnknownTransfer : InheritableAttr {
510  let Spellings = [GNU<"cf_unknown_transfer">];
511  let Subjects = SubjectList<[Function], ErrorDiag>;
512  let Documentation = [Undocumented];
513}
514
515def CFReturnsRetained : InheritableAttr {
516  let Spellings = [GNU<"cf_returns_retained">];
517//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
518  let Documentation = [Undocumented];
519}
520
521def CFReturnsNotRetained : InheritableAttr {
522  let Spellings = [GNU<"cf_returns_not_retained">];
523//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
524  let Documentation = [Undocumented];
525}
526
527def CFConsumed : InheritableParamAttr {
528  let Spellings = [GNU<"cf_consumed">];
529  let Subjects = SubjectList<[ParmVar]>;
530  let Documentation = [Undocumented];
531}
532
533def Cleanup : InheritableAttr {
534  let Spellings = [GCC<"cleanup">];
535  let Args = [FunctionArgument<"FunctionDecl">];
536  let Subjects = SubjectList<[Var]>;
537  let Documentation = [Undocumented];
538}
539
540def Cold : InheritableAttr {
541  let Spellings = [GCC<"cold">];
542  let Subjects = SubjectList<[Function]>;
543  let Documentation = [Undocumented];
544}
545
546def Common : InheritableAttr {
547  let Spellings = [GCC<"common">];
548  let Subjects = SubjectList<[Var]>;
549  let Documentation = [Undocumented];
550}
551
552def Const : InheritableAttr {
553  let Spellings = [GCC<"const">, GCC<"__const">];
554  let Documentation = [Undocumented];
555}
556
557def Constructor : InheritableAttr {
558  let Spellings = [GCC<"constructor">];
559  let Args = [DefaultIntArgument<"Priority", 65535>];
560  let Subjects = SubjectList<[Function]>;
561  let Documentation = [Undocumented];
562}
563
564def CUDAConstant : InheritableAttr {
565  let Spellings = [GNU<"constant">];
566  let Subjects = SubjectList<[Var]>;
567  let LangOpts = [CUDA];
568  let Documentation = [Undocumented];
569}
570
571def CUDACudartBuiltin : IgnoredAttr {
572  let Spellings = [GNU<"cudart_builtin">];
573  let LangOpts = [CUDA];
574}
575
576def CUDADevice : InheritableAttr {
577  let Spellings = [GNU<"device">];
578  let Subjects = SubjectList<[Function, Var]>;
579  let LangOpts = [CUDA];
580  let Documentation = [Undocumented];
581}
582
583def CUDADeviceBuiltin : IgnoredAttr {
584  let Spellings = [GNU<"device_builtin">];
585  let LangOpts = [CUDA];
586}
587
588def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
589  let Spellings = [GNU<"device_builtin_surface_type">];
590  let LangOpts = [CUDA];
591}
592
593def CUDADeviceBuiltinTextureType : IgnoredAttr {
594  let Spellings = [GNU<"device_builtin_texture_type">];
595  let LangOpts = [CUDA];
596}
597
598def CUDAGlobal : InheritableAttr {
599  let Spellings = [GNU<"global">];
600  let Subjects = SubjectList<[Function]>;
601  let LangOpts = [CUDA];
602  let Documentation = [Undocumented];
603}
604
605def CUDAHost : InheritableAttr {
606  let Spellings = [GNU<"host">];
607  let Subjects = SubjectList<[Function]>;
608  let LangOpts = [CUDA];
609  let Documentation = [Undocumented];
610}
611
612def CUDAInvalidTarget : InheritableAttr {
613  let Spellings = [];
614  let Subjects = SubjectList<[Function]>;
615  let LangOpts = [CUDA];
616  let Documentation = [Undocumented];
617}
618
619def CUDALaunchBounds : InheritableAttr {
620  let Spellings = [GNU<"launch_bounds">];
621  let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
622  let LangOpts = [CUDA];
623  let Subjects = SubjectList<[ObjCMethod, FunctionLike], WarnDiag,
624                             "ExpectedFunctionOrMethod">;
625  // An AST node is created for this attribute, but is not used by other parts
626  // of the compiler. However, this node needs to exist in the AST because
627  // non-LLVM backends may be relying on the attribute's presence.
628  let Documentation = [Undocumented];
629}
630
631def CUDAShared : InheritableAttr {
632  let Spellings = [GNU<"shared">];
633  let Subjects = SubjectList<[Var]>;
634  let LangOpts = [CUDA];
635  let Documentation = [Undocumented];
636}
637
638def C11NoReturn : InheritableAttr {
639  let Spellings = [Keyword<"_Noreturn">];
640  let Subjects = SubjectList<[Function], ErrorDiag>;
641  let SemaHandler = 0;
642  let Documentation = [C11NoReturnDocs];
643}
644
645def CXX11NoReturn : InheritableAttr {
646  let Spellings = [CXX11<"","noreturn", 200809>];
647  let Subjects = SubjectList<[Function], ErrorDiag>;
648  let Documentation = [CXX11NoReturnDocs];
649}
650
651def OpenCLKernel : InheritableAttr {
652  let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
653  let Subjects = SubjectList<[Function], ErrorDiag>;
654  let Documentation = [Undocumented];
655}
656
657// This attribute is both a type attribute, and a declaration attribute (for
658// parameter variables).
659def OpenCLImageAccess : Attr {
660  let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
661                   Keyword<"__write_only">, Keyword<"write_only">,
662                   Keyword<"__read_write">, Keyword<"read_write">];
663  let Subjects = SubjectList<[ParmVar], ErrorDiag>;
664  let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
665                                           Keyword<"read_only">]>,
666                   Accessor<"isReadWrite", [Keyword<"__read_write">,
667                                            Keyword<"read_write">]>,
668                   Accessor<"isWriteOnly", [Keyword<"__write_only">,
669                                            Keyword<"write_only">]>];
670  let Documentation = [Undocumented];
671}
672
673def OpenCLPrivateAddressSpace : TypeAttr {
674  let Spellings = [Keyword<"__private">, Keyword<"private">];
675  let Documentation = [OpenCLAddressSpacePrivateDocs];
676}
677
678def OpenCLGlobalAddressSpace : TypeAttr {
679  let Spellings = [Keyword<"__global">, Keyword<"global">];
680  let Documentation = [OpenCLAddressSpaceGlobalDocs];
681}
682
683def OpenCLLocalAddressSpace : TypeAttr {
684  let Spellings = [Keyword<"__local">, Keyword<"local">];
685  let Documentation = [OpenCLAddressSpaceLocalDocs];
686}
687
688def OpenCLConstantAddressSpace : TypeAttr {
689  let Spellings = [Keyword<"__constant">, Keyword<"constant">];
690  let Documentation = [OpenCLAddressSpaceConstantDocs];
691}
692
693def OpenCLGenericAddressSpace : TypeAttr {
694  let Spellings = [Keyword<"__generic">, Keyword<"generic">];
695  let Documentation = [OpenCLAddressSpaceGenericDocs];
696}
697
698def Kernel : Attr {
699  let Spellings = [GNU<"kernel">];
700  let Args = [StringArgument<"KernelKind", 1>];
701  let Subjects = SubjectList<[Function]>;
702  let Documentation = [Undocumented];
703}
704
705def Deprecated : InheritableAttr {
706  let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
707                   CXX11<"","deprecated", 201309>];
708  let Args = [StringArgument<"Message", 1>];
709  let Documentation = [Undocumented];
710}
711
712def Destructor : InheritableAttr {
713  let Spellings = [GCC<"destructor">];
714  let Args = [DefaultIntArgument<"Priority", 65535>];
715  let Subjects = SubjectList<[Function]>;
716  let Documentation = [Undocumented];
717}
718
719def EnableIf : InheritableAttr {
720  let Spellings = [GNU<"enable_if">];
721  let Subjects = SubjectList<[Function]>;
722  let Args = [ExprArgument<"Cond">, StringArgument<"Message">];
723  let TemplateDependent = 1;
724  let Documentation = [EnableIfDocs];
725}
726
727def ExtVectorType : Attr {
728  let Spellings = [GNU<"ext_vector_type">];
729  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
730  let Args = [ExprArgument<"NumElements">];
731  let ASTNode = 0;
732  let Documentation = [Undocumented];
733}
734
735def FallThrough : Attr {
736  let Spellings = [CXX11<"clang", "fallthrough">];
737//  let Subjects = [NullStmt];
738  let Documentation = [FallthroughDocs];
739}
740
741def FastCall : InheritableAttr {
742  let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
743                   Keyword<"_fastcall">];
744//  let Subjects = [Function, ObjCMethod];
745  let Documentation = [FastCallDocs];
746}
747
748def Final : InheritableAttr {
749  let Spellings = [Keyword<"final">, Keyword<"sealed">];
750  let Accessors = [Accessor<"isSpelledAsSealed", [Keyword<"sealed">]>];
751  let SemaHandler = 0;
752  let Documentation = [Undocumented];
753}
754
755def MinSize : InheritableAttr {
756  let Spellings = [GNU<"minsize">];
757  let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
758  let Documentation = [Undocumented];
759}
760
761def FlagEnum : InheritableAttr {
762  let Spellings = [GNU<"flag_enum">];
763  let Subjects = SubjectList<[Enum]>;
764  let Documentation = [FlagEnumDocs];
765  let LangOpts = [COnly];
766}
767
768def Flatten : InheritableAttr {
769  let Spellings = [GCC<"flatten">];
770  let Subjects = SubjectList<[Function], ErrorDiag>;
771  let Documentation = [FlattenDocs];
772}
773
774def Format : InheritableAttr {
775  let Spellings = [GCC<"format">];
776  let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">,
777              IntArgument<"FirstArg">];
778  let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto], WarnDiag,
779                             "ExpectedFunctionWithProtoType">;
780  let Documentation = [FormatDocs];
781}
782
783def FormatArg : InheritableAttr {
784  let Spellings = [GCC<"format_arg">];
785  let Args = [IntArgument<"FormatIdx">];
786  let Subjects = SubjectList<[ObjCMethod, HasFunctionProto], WarnDiag,
787                             "ExpectedFunctionWithProtoType">;
788  let Documentation = [Undocumented];
789}
790
791def GNUInline : InheritableAttr {
792  let Spellings = [GCC<"gnu_inline">];
793  let Subjects = SubjectList<[Function]>;
794  let Documentation = [Undocumented];
795}
796
797def Hot : InheritableAttr {
798  let Spellings = [GCC<"hot">];
799  let Subjects = SubjectList<[Function]>;
800  // An AST node is created for this attribute, but not actually used beyond
801  // semantic checking for mutual exclusion with the Cold attribute.
802  let Documentation = [Undocumented];
803}
804
805def IBAction : InheritableAttr {
806  let Spellings = [GNU<"ibaction">];
807  let Subjects = SubjectList<[ObjCInstanceMethod], WarnDiag,
808                             "ExpectedObjCInstanceMethod">;
809  // An AST node is created for this attribute, but is not used by other parts
810  // of the compiler. However, this node needs to exist in the AST because
811  // external tools rely on it.
812  let Documentation = [Undocumented];
813}
814
815def IBOutlet : InheritableAttr {
816  let Spellings = [GNU<"iboutlet">];
817//  let Subjects = [ObjCIvar, ObjCProperty];
818  let Documentation = [Undocumented];
819}
820
821def IBOutletCollection : InheritableAttr {
822  let Spellings = [GNU<"iboutletcollection">];
823  let Args = [TypeArgument<"Interface", 1>];
824//  let Subjects = [ObjCIvar, ObjCProperty];
825  let Documentation = [Undocumented];
826}
827
828def Restrict : InheritableAttr {
829  let Spellings = [Declspec<"restrict">, GCC<"malloc">];
830  let Subjects = SubjectList<[Function]>;
831  let Documentation = [Undocumented];
832}
833
834def MaxFieldAlignment : InheritableAttr {
835  // This attribute has no spellings as it is only ever created implicitly.
836  let Spellings = [];
837  let Args = [UnsignedArgument<"Alignment">];
838  let SemaHandler = 0;
839  let Documentation = [Undocumented];
840}
841
842def MayAlias : InheritableAttr {
843  // FIXME: this is a type attribute in GCC, but a declaration attribute here.
844  let Spellings = [GCC<"may_alias">];
845  let Documentation = [Undocumented];
846}
847
848def MSABI : InheritableAttr {
849  let Spellings = [GCC<"ms_abi">];
850//  let Subjects = [Function, ObjCMethod];
851  let Documentation = [MSABIDocs];
852}
853
854def MSP430Interrupt : InheritableAttr, TargetSpecificAttr<TargetMSP430> {
855  // NOTE: If you add any additional spellings, ARMInterrupt's and
856  // MipsInterrupt's spellings must match.
857  let Spellings = [GNU<"interrupt">];
858  let Args = [UnsignedArgument<"Number">];
859  let ParseKind = "Interrupt";
860  let HasCustomParsing = 1;
861  let Documentation = [Undocumented];
862}
863
864def Mips16 : InheritableAttr, TargetSpecificAttr<TargetMips> {
865  let Spellings = [GCC<"mips16">];
866  let Subjects = SubjectList<[Function], ErrorDiag>;
867  let Documentation = [Undocumented];
868}
869
870def MipsInterrupt : InheritableAttr, TargetSpecificAttr<TargetMips> {
871  // NOTE: If you add any additional spellings, ARMInterrupt's and
872  // MSP430Interrupt's spellings must match.
873  let Spellings = [GNU<"interrupt">];
874  let Subjects = SubjectList<[Function]>;
875  let Args = [EnumArgument<"Interrupt", "InterruptType",
876                           ["vector=sw0", "vector=sw1", "vector=hw0",
877                            "vector=hw1", "vector=hw2", "vector=hw3",
878                            "vector=hw4", "vector=hw5", "eic", ""],
879                           ["sw0", "sw1", "hw0", "hw1", "hw2", "hw3",
880                            "hw4", "hw5", "eic", "eic"]
881                           >];
882  let ParseKind = "Interrupt";
883  let Documentation = [MipsInterruptDocs];
884}
885
886def Mode : Attr {
887  let Spellings = [GCC<"mode">];
888  let Args = [IdentifierArgument<"Mode">];
889  let Documentation = [Undocumented];
890}
891
892def Naked : InheritableAttr {
893  let Spellings = [GCC<"naked">, Declspec<"naked">];
894  let Subjects = SubjectList<[Function]>;
895  let Documentation = [Undocumented];
896}
897
898def NeonPolyVectorType : TypeAttr {
899  let Spellings = [GNU<"neon_polyvector_type">];
900  let Args = [IntArgument<"NumElements">];
901  let Documentation = [Undocumented];
902}
903
904def NeonVectorType : TypeAttr {
905  let Spellings = [GNU<"neon_vector_type">];
906  let Args = [IntArgument<"NumElements">];
907  let Documentation = [Undocumented];
908}
909
910def ReturnsTwice : InheritableAttr {
911  let Spellings = [GCC<"returns_twice">];
912  let Subjects = SubjectList<[Function]>;
913  let Documentation = [Undocumented];
914}
915
916def DisableTailCalls : InheritableAttr {
917  let Spellings = [GNU<"disable_tail_calls">,
918                   CXX11<"clang", "disable_tail_calls">];
919  let Subjects = SubjectList<[Function, ObjCMethod]>;
920  let Documentation = [DisableTailCallsDocs];
921}
922
923def NoAlias : InheritableAttr {
924  let Spellings = [Declspec<"noalias">];
925  let Subjects = SubjectList<[Function]>;
926  let Documentation = [NoAliasDocs];
927}
928
929def NoCommon : InheritableAttr {
930  let Spellings = [GCC<"nocommon">];
931  let Subjects = SubjectList<[Var]>;
932  let Documentation = [Undocumented];
933}
934
935def NoDebug : InheritableAttr {
936  let Spellings = [GCC<"nodebug">];
937  let Documentation = [Undocumented];
938}
939
940def NoDuplicate : InheritableAttr {
941  let Spellings = [GNU<"noduplicate">, CXX11<"clang", "noduplicate">];
942  let Subjects = SubjectList<[Function]>;
943  let Documentation = [NoDuplicateDocs];
944}
945
946def NoInline : InheritableAttr {
947  let Spellings = [GCC<"noinline">, Declspec<"noinline">];
948  let Subjects = SubjectList<[Function]>;
949  let Documentation = [Undocumented];
950}
951
952def NoMips16 : InheritableAttr, TargetSpecificAttr<TargetMips> {
953  let Spellings = [GCC<"nomips16">];
954  let Subjects = SubjectList<[Function], ErrorDiag>;
955  let Documentation = [Undocumented];
956}
957
958// This is not a TargetSpecificAttr so that is silently accepted and
959// ignored on other targets as encouraged by the OpenCL spec.
960//
961// See OpenCL 1.2 6.11.5: "It is our intention that a particular
962// implementation of OpenCL be free to ignore all attributes and the
963// resulting executable binary will produce the same result."
964//
965// However, only AMD GPU targets will emit the corresponding IR
966// attribute.
967//
968// FIXME: This provides a sub-optimal error message if you attempt to
969// use this in CUDA, since CUDA does not use the same terminology.
970def AMDGPUNumVGPR : InheritableAttr {
971  let Spellings = [GNU<"amdgpu_num_vgpr">];
972  let Args = [UnsignedArgument<"NumVGPR">];
973  let Documentation = [AMDGPUNumVGPRDocs];
974
975// FIXME: This should be for OpenCLKernelFunction, but is not to
976// workaround needing to see kernel attribute before others to know if
977// this should be rejected on non-kernels.
978  let Subjects = SubjectList<[Function], ErrorDiag,
979                             "ExpectedKernelFunction">;
980}
981
982def AMDGPUNumSGPR : InheritableAttr {
983  let Spellings = [GNU<"amdgpu_num_sgpr">];
984  let Args = [UnsignedArgument<"NumSGPR">];
985  let Documentation = [AMDGPUNumSGPRDocs];
986  let Subjects = SubjectList<[Function], ErrorDiag,
987                              "ExpectedKernelFunction">;
988}
989
990def NoSplitStack : InheritableAttr {
991  let Spellings = [GCC<"no_split_stack">];
992  let Subjects = SubjectList<[Function], ErrorDiag>;
993  let Documentation = [NoSplitStackDocs];
994}
995
996def NonNull : InheritableAttr {
997  let Spellings = [GCC<"nonnull">];
998  let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
999                             "ExpectedFunctionMethodOrParameter">;
1000  let Args = [VariadicUnsignedArgument<"Args">];
1001  let AdditionalMembers =
1002[{bool isNonNull(unsigned idx) const {
1003    if (!args_size())
1004      return true;
1005    for (const auto &V : args())
1006      if (V == idx)
1007        return true;
1008    return false;
1009  } }];
1010  // FIXME: We should merge duplicates into a single nonnull attribute.
1011  let DuplicatesAllowedWhileMerging = 1;
1012  let Documentation = [NonNullDocs];
1013}
1014
1015def ReturnsNonNull : InheritableAttr {
1016  let Spellings = [GCC<"returns_nonnull">];
1017  let Subjects = SubjectList<[ObjCMethod, Function], WarnDiag,
1018                             "ExpectedFunctionOrMethod">;
1019  let Documentation = [ReturnsNonNullDocs];
1020}
1021
1022// pass_object_size(N) indicates that the parameter should have
1023// __builtin_object_size with Type=N evaluated on the parameter at the callsite.
1024def PassObjectSize : InheritableParamAttr {
1025  let Spellings = [GNU<"pass_object_size">];
1026  let Args = [IntArgument<"Type">];
1027  let Subjects = SubjectList<[ParmVar]>;
1028  let Documentation = [PassObjectSizeDocs];
1029}
1030
1031// Nullability type attributes.
1032def TypeNonNull : TypeAttr {
1033  let Spellings = [Keyword<"_Nonnull">];
1034  let Documentation = [TypeNonNullDocs];
1035}
1036
1037def TypeNullable : TypeAttr {
1038  let Spellings = [Keyword<"_Nullable">];
1039  let Documentation = [TypeNullableDocs];
1040}
1041
1042def TypeNullUnspecified : TypeAttr {
1043  let Spellings = [Keyword<"_Null_unspecified">];
1044  let Documentation = [TypeNullUnspecifiedDocs];
1045}
1046
1047def ObjCKindOf : TypeAttr {
1048  let Spellings = [Keyword<"__kindof">];
1049  let Documentation = [Undocumented];
1050}
1051
1052def AssumeAligned : InheritableAttr {
1053  let Spellings = [GCC<"assume_aligned">];
1054  let Subjects = SubjectList<[ObjCMethod, Function]>;
1055  let Args = [ExprArgument<"Alignment">, ExprArgument<"Offset", 1>];
1056  let Documentation = [AssumeAlignedDocs];
1057}
1058
1059def NoReturn : InheritableAttr {
1060  let Spellings = [GCC<"noreturn">, Declspec<"noreturn">];
1061  // FIXME: Does GCC allow this on the function instead?
1062  let Documentation = [Undocumented];
1063}
1064
1065def NoInstrumentFunction : InheritableAttr {
1066  let Spellings = [GCC<"no_instrument_function">];
1067  let Subjects = SubjectList<[Function]>;
1068  let Documentation = [Undocumented];
1069}
1070
1071def NotTailCalled : InheritableAttr {
1072  let Spellings = [GNU<"not_tail_called">, CXX11<"clang", "not_tail_called">];
1073  let Subjects = SubjectList<[Function]>;
1074  let Documentation = [NotTailCalledDocs];
1075}
1076
1077def NoThrow : InheritableAttr {
1078  let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
1079  let Documentation = [Undocumented];
1080}
1081
1082def NvWeak : IgnoredAttr {
1083  let Spellings = [GNU<"nv_weak">];
1084  let LangOpts = [CUDA];
1085}
1086
1087def ObjCBridge : InheritableAttr {
1088  let Spellings = [GNU<"objc_bridge">];
1089  let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
1090                             "ExpectedStructOrUnionOrTypedef">;
1091  let Args = [IdentifierArgument<"BridgedType">];
1092  let Documentation = [Undocumented];
1093}
1094
1095def ObjCBridgeMutable : InheritableAttr {
1096  let Spellings = [GNU<"objc_bridge_mutable">];
1097  let Subjects = SubjectList<[Record], ErrorDiag>;
1098  let Args = [IdentifierArgument<"BridgedType">];
1099  let Documentation = [Undocumented];
1100}
1101
1102def ObjCBridgeRelated : InheritableAttr {
1103  let Spellings = [GNU<"objc_bridge_related">];
1104  let Subjects = SubjectList<[Record], ErrorDiag>;
1105  let Args = [IdentifierArgument<"RelatedClass">,
1106          IdentifierArgument<"ClassMethod", 1>,
1107          IdentifierArgument<"InstanceMethod", 1>];
1108  let HasCustomParsing = 1;
1109  let Documentation = [Undocumented];
1110}
1111
1112def NSReturnsRetained : InheritableAttr {
1113  let Spellings = [GNU<"ns_returns_retained">];
1114//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1115  let Documentation = [Undocumented];
1116}
1117
1118def NSReturnsNotRetained : InheritableAttr {
1119  let Spellings = [GNU<"ns_returns_not_retained">];
1120//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1121  let Documentation = [Undocumented];
1122}
1123
1124def NSReturnsAutoreleased : InheritableAttr {
1125  let Spellings = [GNU<"ns_returns_autoreleased">];
1126//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1127  let Documentation = [Undocumented];
1128}
1129
1130def NSConsumesSelf : InheritableAttr {
1131  let Spellings = [GNU<"ns_consumes_self">];
1132  let Subjects = SubjectList<[ObjCMethod]>;
1133  let Documentation = [Undocumented];
1134}
1135
1136def NSConsumed : InheritableParamAttr {
1137  let Spellings = [GNU<"ns_consumed">];
1138  let Subjects = SubjectList<[ParmVar]>;
1139  let Documentation = [Undocumented];
1140}
1141
1142def ObjCException : InheritableAttr {
1143  let Spellings = [GNU<"objc_exception">];
1144  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1145  let Documentation = [Undocumented];
1146}
1147
1148def ObjCMethodFamily : InheritableAttr {
1149  let Spellings = [GNU<"objc_method_family">];
1150  let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1151  let Args = [EnumArgument<"Family", "FamilyKind",
1152               ["none", "alloc", "copy", "init", "mutableCopy", "new"],
1153               ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
1154                "OMF_mutableCopy", "OMF_new"]>];
1155  let Documentation = [ObjCMethodFamilyDocs];
1156}
1157
1158def ObjCNSObject : InheritableAttr {
1159  let Spellings = [GNU<"NSObject">];
1160  let Documentation = [Undocumented];
1161}
1162
1163def ObjCIndependentClass : InheritableAttr {
1164  let Spellings = [GNU<"objc_independent_class">];
1165  let Documentation = [Undocumented];
1166}
1167
1168def ObjCPreciseLifetime : InheritableAttr {
1169  let Spellings = [GNU<"objc_precise_lifetime">];
1170  let Subjects = SubjectList<[Var], ErrorDiag>;
1171  let Documentation = [Undocumented];
1172}
1173
1174def ObjCReturnsInnerPointer : InheritableAttr {
1175  let Spellings = [GNU<"objc_returns_inner_pointer">];
1176  let Subjects = SubjectList<[ObjCMethod, ObjCProperty], ErrorDiag>;
1177  let Documentation = [Undocumented];
1178}
1179
1180def ObjCRequiresSuper : InheritableAttr {
1181  let Spellings = [GNU<"objc_requires_super">];
1182  let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1183  let Documentation = [ObjCRequiresSuperDocs];
1184}
1185
1186def ObjCRootClass : InheritableAttr {
1187  let Spellings = [GNU<"objc_root_class">];
1188  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1189  let Documentation = [Undocumented];
1190}
1191
1192def ObjCExplicitProtocolImpl : InheritableAttr {
1193  let Spellings = [GNU<"objc_protocol_requires_explicit_implementation">];
1194  let Subjects = SubjectList<[ObjCProtocol], ErrorDiag>;
1195  let Documentation = [Undocumented];
1196}
1197
1198def ObjCDesignatedInitializer : Attr {
1199  let Spellings = [GNU<"objc_designated_initializer">];
1200  let Subjects = SubjectList<[ObjCInterfaceDeclInitMethod], ErrorDiag,
1201                             "ExpectedObjCInterfaceDeclInitMethod">;
1202  let Documentation = [Undocumented];
1203}
1204
1205def ObjCRuntimeName : Attr {
1206  let Spellings = [GNU<"objc_runtime_name">];
1207  let Subjects = SubjectList<[ObjCInterface, ObjCProtocol], ErrorDiag>;
1208  let Args = [StringArgument<"MetadataName">];
1209  let Documentation = [ObjCRuntimeNameDocs];
1210}
1211
1212def ObjCBoxable : Attr {
1213  let Spellings = [GNU<"objc_boxable">];
1214  let Subjects = SubjectList<[Record], ErrorDiag, "ExpectedStructOrUnion">;
1215  let Documentation = [ObjCBoxableDocs];
1216}
1217
1218def OptimizeNone : InheritableAttr {
1219  let Spellings = [GNU<"optnone">, CXX11<"clang", "optnone">];
1220  let Subjects = SubjectList<[Function, ObjCMethod]>;
1221  let Documentation = [OptnoneDocs];
1222}
1223
1224def Overloadable : Attr {
1225  let Spellings = [GNU<"overloadable">];
1226  let Subjects = SubjectList<[Function], ErrorDiag>;
1227  let Documentation = [OverloadableDocs];
1228}
1229
1230def Override : InheritableAttr {
1231  let Spellings = [Keyword<"override">];
1232  let SemaHandler = 0;
1233  let Documentation = [Undocumented];
1234}
1235
1236def Ownership : InheritableAttr {
1237  let Spellings = [GNU<"ownership_holds">, GNU<"ownership_returns">,
1238                   GNU<"ownership_takes">];
1239  let Accessors = [Accessor<"isHolds", [GNU<"ownership_holds">]>,
1240                   Accessor<"isReturns", [GNU<"ownership_returns">]>,
1241                   Accessor<"isTakes", [GNU<"ownership_takes">]>];
1242  let AdditionalMembers = [{
1243    enum OwnershipKind { Holds, Returns, Takes };
1244    OwnershipKind getOwnKind() const {
1245      return isHolds() ? Holds :
1246             isTakes() ? Takes :
1247             Returns;
1248    }
1249  }];
1250  let Args = [IdentifierArgument<"Module">, VariadicUnsignedArgument<"Args">];
1251  let Subjects = SubjectList<[HasFunctionProto], WarnDiag,
1252                             "ExpectedFunctionWithProtoType">;
1253  let Documentation = [Undocumented];
1254}
1255
1256def Packed : InheritableAttr {
1257  let Spellings = [GCC<"packed">];
1258//  let Subjects = [Tag, Field];
1259  let Documentation = [Undocumented];
1260}
1261
1262def IntelOclBicc : InheritableAttr {
1263  let Spellings = [GNU<"intel_ocl_bicc">];
1264//  let Subjects = [Function, ObjCMethod];
1265  let Documentation = [Undocumented];
1266}
1267
1268def Pcs : InheritableAttr {
1269  let Spellings = [GCC<"pcs">];
1270  let Args = [EnumArgument<"PCS", "PCSType",
1271                           ["aapcs", "aapcs-vfp"],
1272                           ["AAPCS", "AAPCS_VFP"]>];
1273//  let Subjects = [Function, ObjCMethod];
1274  let Documentation = [PcsDocs];
1275}
1276
1277def Pure : InheritableAttr {
1278  let Spellings = [GCC<"pure">];
1279  let Documentation = [Undocumented];
1280}
1281
1282def Regparm : TypeAttr {
1283  let Spellings = [GCC<"regparm">];
1284  let Args = [UnsignedArgument<"NumParams">];
1285  let Documentation = [RegparmDocs];
1286}
1287
1288def ReqdWorkGroupSize : InheritableAttr {
1289  let Spellings = [GNU<"reqd_work_group_size">];
1290  let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
1291              UnsignedArgument<"ZDim">];
1292  let Subjects = SubjectList<[Function], ErrorDiag>;
1293  let Documentation = [Undocumented];
1294}
1295
1296def WorkGroupSizeHint :  InheritableAttr {
1297  let Spellings = [GNU<"work_group_size_hint">];
1298  let Args = [UnsignedArgument<"XDim">,
1299              UnsignedArgument<"YDim">,
1300              UnsignedArgument<"ZDim">];
1301  let Subjects = SubjectList<[Function], ErrorDiag>;
1302  let Documentation = [Undocumented];
1303}
1304
1305def InitPriority : InheritableAttr {
1306  let Spellings = [GNU<"init_priority">];
1307  let Args = [UnsignedArgument<"Priority">];
1308  let Subjects = SubjectList<[Var], ErrorDiag>;
1309  let Documentation = [Undocumented];
1310}
1311
1312def Section : InheritableAttr {
1313  let Spellings = [GCC<"section">, Declspec<"allocate">];
1314  let Args = [StringArgument<"Name">];
1315  let Subjects = SubjectList<[Function, GlobalVar,
1316                              ObjCMethod, ObjCProperty], ErrorDiag,
1317                             "ExpectedFunctionGlobalVarMethodOrProperty">;
1318  let Documentation = [SectionDocs];
1319}
1320
1321def Sentinel : InheritableAttr {
1322  let Spellings = [GCC<"sentinel">];
1323  let Args = [DefaultIntArgument<"Sentinel", 0>,
1324              DefaultIntArgument<"NullPos", 0>];
1325//  let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>;
1326  let Documentation = [Undocumented];
1327}
1328
1329def StdCall : InheritableAttr {
1330  let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
1331//  let Subjects = [Function, ObjCMethod];
1332  let Documentation = [StdCallDocs];
1333}
1334
1335def SysVABI : InheritableAttr {
1336  let Spellings = [GCC<"sysv_abi">];
1337//  let Subjects = [Function, ObjCMethod];
1338  let Documentation = [Undocumented];
1339}
1340
1341def ThisCall : InheritableAttr {
1342  let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
1343                   Keyword<"_thiscall">];
1344//  let Subjects = [Function, ObjCMethod];
1345  let Documentation = [ThisCallDocs];
1346}
1347
1348def VectorCall : InheritableAttr {
1349  let Spellings = [GNU<"vectorcall">, Keyword<"__vectorcall">,
1350                   Keyword<"_vectorcall">];
1351//  let Subjects = [Function, ObjCMethod];
1352  let Documentation = [VectorCallDocs];
1353}
1354
1355def Pascal : InheritableAttr {
1356  let Spellings = [GNU<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
1357//  let Subjects = [Function, ObjCMethod];
1358  let Documentation = [Undocumented];
1359}
1360
1361def Target : InheritableAttr {
1362  let Spellings = [GCC<"target">];
1363  let Args = [StringArgument<"featuresStr">];
1364  let Subjects = SubjectList<[Function], ErrorDiag>;
1365  let Documentation = [TargetDocs];
1366  let AdditionalMembers = [{
1367    typedef std::pair<std::vector<std::string>, StringRef> ParsedTargetAttr;
1368    ParsedTargetAttr parse() const {
1369      ParsedTargetAttr Ret;
1370      SmallVector<StringRef, 1> AttrFeatures;
1371      getFeaturesStr().split(AttrFeatures, ",");
1372
1373      // Grab the various features and prepend a "+" to turn on the feature to
1374      // the backend and add them to our existing set of features.
1375      for (auto &Feature : AttrFeatures) {
1376        // Go ahead and trim whitespace rather than either erroring or
1377        // accepting it weirdly.
1378        Feature = Feature.trim();
1379
1380        // We don't support cpu tuning this way currently.
1381        // TODO: Support the fpmath option. It will require checking
1382        // overall feature validity for the function with the rest of the
1383        // attributes on the function.
1384        if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
1385	  continue;
1386
1387        // While we're here iterating check for a different target cpu.
1388        if (Feature.startswith("arch="))
1389          Ret.second = Feature.split("=").second.trim();
1390        else if (Feature.startswith("no-"))
1391          Ret.first.push_back("-" + Feature.split("-").second.str());
1392        else
1393          Ret.first.push_back("+" + Feature.str());
1394      }
1395      return Ret;
1396    }
1397  }];
1398}
1399
1400def TransparentUnion : InheritableAttr {
1401  let Spellings = [GCC<"transparent_union">];
1402//  let Subjects = SubjectList<[Record, TypedefName]>;
1403  let Documentation = [Undocumented];
1404}
1405
1406def Unavailable : InheritableAttr {
1407  let Spellings = [GNU<"unavailable">];
1408  let Args = [StringArgument<"Message", 1>,
1409              EnumArgument<"ImplicitReason", "ImplicitReason",
1410                ["", "", "", ""],
1411                ["IR_None",
1412                 "IR_ARCForbiddenType",
1413                 "IR_ForbiddenWeak",
1414                 "IR_ARCForbiddenConversion",
1415                 "IR_ARCInitReturnsUnrelated",
1416                 "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
1417  let Documentation = [Undocumented];
1418}
1419
1420def ArcWeakrefUnavailable : InheritableAttr {
1421  let Spellings = [GNU<"objc_arc_weak_reference_unavailable">];
1422  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1423  let Documentation = [Undocumented];
1424}
1425
1426def ObjCGC : TypeAttr {
1427  let Spellings = [GNU<"objc_gc">];
1428  let Args = [IdentifierArgument<"Kind">];
1429  let Documentation = [Undocumented];
1430}
1431
1432def ObjCOwnership : InheritableAttr {
1433  let Spellings = [GNU<"objc_ownership">];
1434  let Args = [IdentifierArgument<"Kind">];
1435  let ASTNode = 0;
1436  let Documentation = [Undocumented];
1437}
1438
1439def ObjCRequiresPropertyDefs : InheritableAttr {
1440  let Spellings = [GNU<"objc_requires_property_definitions">];
1441  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1442  let Documentation = [Undocumented];
1443}
1444
1445def Unused : InheritableAttr {
1446  let Spellings = [GCC<"unused">];
1447  let Subjects = SubjectList<[Var, ObjCIvar, Type, Label, Field, ObjCMethod,
1448                              FunctionLike], WarnDiag,
1449                             "ExpectedVariableFunctionOrLabel">;
1450  let Documentation = [Undocumented];
1451}
1452
1453def Used : InheritableAttr {
1454  let Spellings = [GCC<"used">];
1455  let Documentation = [Undocumented];
1456}
1457
1458def Uuid : InheritableAttr {
1459  let Spellings = [Declspec<"uuid">];
1460  let Args = [StringArgument<"Guid">];
1461//  let Subjects = SubjectList<[CXXRecord]>;
1462  let LangOpts = [MicrosoftExt, Borland];
1463  let Documentation = [Undocumented];
1464}
1465
1466def VectorSize : TypeAttr {
1467  let Spellings = [GCC<"vector_size">];
1468  let Args = [ExprArgument<"NumBytes">];
1469  let Documentation = [Undocumented];
1470}
1471
1472def VecTypeHint : InheritableAttr {
1473  let Spellings = [GNU<"vec_type_hint">];
1474  let Args = [TypeArgument<"TypeHint">];
1475  let Subjects = SubjectList<[Function], ErrorDiag>;
1476  let Documentation = [Undocumented];
1477}
1478
1479def Visibility : InheritableAttr {
1480  let Clone = 0;
1481  let Spellings = [GCC<"visibility">];
1482  let Args = [EnumArgument<"Visibility", "VisibilityType",
1483                           ["default", "hidden", "internal", "protected"],
1484                           ["Default", "Hidden", "Hidden", "Protected"]>];
1485  let Documentation = [Undocumented];
1486}
1487
1488def TypeVisibility : InheritableAttr {
1489  let Clone = 0;
1490  let Spellings = [GNU<"type_visibility">, CXX11<"clang", "type_visibility">];
1491  let Args = [EnumArgument<"Visibility", "VisibilityType",
1492                           ["default", "hidden", "internal", "protected"],
1493                           ["Default", "Hidden", "Hidden", "Protected"]>];
1494//  let Subjects = [Tag, ObjCInterface, Namespace];
1495  let Documentation = [Undocumented];
1496}
1497
1498def VecReturn : InheritableAttr {
1499  let Spellings = [GNU<"vecreturn">];
1500  let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
1501  let Documentation = [Undocumented];
1502}
1503
1504def WarnUnused : InheritableAttr {
1505  let Spellings = [GNU<"warn_unused">];
1506  let Subjects = SubjectList<[Record]>;
1507  let Documentation = [Undocumented];
1508}
1509
1510def WarnUnusedResult : InheritableAttr {
1511  let Spellings = [GCC<"warn_unused_result">,
1512                   CXX11<"clang", "warn_unused_result">];
1513  let Subjects = SubjectList<[ObjCMethod, CXXRecord, FunctionLike], WarnDiag,
1514                             "ExpectedFunctionMethodOrClass">;
1515  let Documentation = [Undocumented];
1516}
1517
1518def Weak : InheritableAttr {
1519  let Spellings = [GCC<"weak">];
1520  let Subjects = SubjectList<[Var, Function, CXXRecord]>;
1521  let Documentation = [Undocumented];
1522}
1523
1524def WeakImport : InheritableAttr {
1525  let Spellings = [GNU<"weak_import">];
1526  let Documentation = [Undocumented];
1527}
1528
1529def WeakRef : InheritableAttr {
1530  let Spellings = [GCC<"weakref">];
1531  // A WeakRef that has an argument is treated as being an AliasAttr
1532  let Args = [StringArgument<"Aliasee", 1>];
1533  let Subjects = SubjectList<[Var, Function], ErrorDiag>;
1534  let Documentation = [Undocumented];
1535}
1536
1537def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetX86> {
1538  let Spellings = [GNU<"force_align_arg_pointer">];
1539  // Technically, this appertains to a FunctionDecl, but the target-specific
1540  // code silently allows anything function-like (such as typedefs or function
1541  // pointers), but does not apply the attribute to them.
1542  let Documentation = [Undocumented];
1543}
1544
1545def NoSanitize : InheritableAttr {
1546  let Spellings = [GNU<"no_sanitize">, CXX11<"clang", "no_sanitize">];
1547  let Args = [VariadicStringArgument<"Sanitizers">];
1548  let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
1549  let Documentation = [NoSanitizeDocs];
1550  let AdditionalMembers = [{
1551    SanitizerMask getMask() const {
1552      SanitizerMask Mask = 0;
1553      for (auto SanitizerName : sanitizers()) {
1554        SanitizerMask ParsedMask =
1555            parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
1556        Mask |= expandSanitizerGroups(ParsedMask);
1557      }
1558      return Mask;
1559    }
1560  }];
1561}
1562
1563// Attributes to disable a specific sanitizer. No new sanitizers should be added
1564// to this list; the no_sanitize attribute should be extended instead.
1565def NoSanitizeSpecific : InheritableAttr {
1566  let Spellings = [GCC<"no_address_safety_analysis">,
1567                   GCC<"no_sanitize_address">,
1568                   GCC<"no_sanitize_thread">,
1569                   GNU<"no_sanitize_memory">];
1570  let Subjects = SubjectList<[Function], ErrorDiag>;
1571  let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
1572                       NoSanitizeMemoryDocs];
1573  let ASTNode = 0;
1574}
1575
1576// C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
1577
1578def GuardedVar : InheritableAttr {
1579  let Spellings = [GNU<"guarded_var">];
1580  let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1581                             "ExpectedFieldOrGlobalVar">;
1582  let Documentation = [Undocumented];
1583}
1584
1585def PtGuardedVar : InheritableAttr {
1586  let Spellings = [GNU<"pt_guarded_var">];
1587  let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1588                             "ExpectedFieldOrGlobalVar">;
1589  let Documentation = [Undocumented];
1590}
1591
1592def Lockable : InheritableAttr {
1593  let Spellings = [GNU<"lockable">];
1594  let Subjects = SubjectList<[Record]>;
1595  let Documentation = [Undocumented];
1596  let ASTNode = 0;  // Replaced by Capability
1597}
1598
1599def ScopedLockable : InheritableAttr {
1600  let Spellings = [GNU<"scoped_lockable">];
1601  let Subjects = SubjectList<[Record]>;
1602  let Documentation = [Undocumented];
1603}
1604
1605def Capability : InheritableAttr {
1606  let Spellings = [GNU<"capability">, CXX11<"clang", "capability">,
1607                   GNU<"shared_capability">,
1608                   CXX11<"clang", "shared_capability">];
1609  let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
1610                             "ExpectedStructOrUnionOrTypedef">;
1611  let Args = [StringArgument<"Name">];
1612  let Accessors = [Accessor<"isShared",
1613                    [GNU<"shared_capability">,
1614                     CXX11<"clang","shared_capability">]>];
1615  let Documentation = [Undocumented];
1616  let AdditionalMembers = [{
1617    bool isMutex() const { return getName().equals_lower("mutex"); }
1618    bool isRole() const { return getName().equals_lower("role"); }
1619  }];
1620}
1621
1622def AssertCapability : InheritableAttr {
1623  let Spellings = [GNU<"assert_capability">,
1624                   CXX11<"clang", "assert_capability">,
1625                   GNU<"assert_shared_capability">,
1626                   CXX11<"clang", "assert_shared_capability">];
1627  let Subjects = SubjectList<[Function]>;
1628  let LateParsed = 1;
1629  let TemplateDependent = 1;
1630  let ParseArgumentsAsUnevaluated = 1;
1631  let DuplicatesAllowedWhileMerging = 1;
1632  let Args = [ExprArgument<"Expr">];
1633  let Accessors = [Accessor<"isShared",
1634                    [GNU<"assert_shared_capability">,
1635                     CXX11<"clang", "assert_shared_capability">]>];
1636  let Documentation = [AssertCapabilityDocs];
1637}
1638
1639def AcquireCapability : InheritableAttr {
1640  let Spellings = [GNU<"acquire_capability">,
1641                   CXX11<"clang", "acquire_capability">,
1642                   GNU<"acquire_shared_capability">,
1643                   CXX11<"clang", "acquire_shared_capability">,
1644                   GNU<"exclusive_lock_function">,
1645                   GNU<"shared_lock_function">];
1646  let Subjects = SubjectList<[Function]>;
1647  let LateParsed = 1;
1648  let TemplateDependent = 1;
1649  let ParseArgumentsAsUnevaluated = 1;
1650  let DuplicatesAllowedWhileMerging = 1;
1651  let Args = [VariadicExprArgument<"Args">];
1652  let Accessors = [Accessor<"isShared",
1653                    [GNU<"acquire_shared_capability">,
1654                     CXX11<"clang", "acquire_shared_capability">,
1655                     GNU<"shared_lock_function">]>];
1656  let Documentation = [AcquireCapabilityDocs];
1657}
1658
1659def TryAcquireCapability : InheritableAttr {
1660  let Spellings = [GNU<"try_acquire_capability">,
1661                   CXX11<"clang", "try_acquire_capability">,
1662                   GNU<"try_acquire_shared_capability">,
1663                   CXX11<"clang", "try_acquire_shared_capability">];
1664  let Subjects = SubjectList<[Function],
1665                             ErrorDiag>;
1666  let LateParsed = 1;
1667  let TemplateDependent = 1;
1668  let ParseArgumentsAsUnevaluated = 1;
1669  let DuplicatesAllowedWhileMerging = 1;
1670  let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
1671  let Accessors = [Accessor<"isShared",
1672                    [GNU<"try_acquire_shared_capability">,
1673                     CXX11<"clang", "try_acquire_shared_capability">]>];
1674  let Documentation = [TryAcquireCapabilityDocs];
1675}
1676
1677def ReleaseCapability : InheritableAttr {
1678  let Spellings = [GNU<"release_capability">,
1679                   CXX11<"clang", "release_capability">,
1680                   GNU<"release_shared_capability">,
1681                   CXX11<"clang", "release_shared_capability">,
1682                   GNU<"release_generic_capability">,
1683                   CXX11<"clang", "release_generic_capability">,
1684                   GNU<"unlock_function">];
1685  let Subjects = SubjectList<[Function]>;
1686  let LateParsed = 1;
1687  let TemplateDependent = 1;
1688  let ParseArgumentsAsUnevaluated = 1;
1689  let DuplicatesAllowedWhileMerging = 1;
1690  let Args = [VariadicExprArgument<"Args">];
1691  let Accessors = [Accessor<"isShared",
1692                    [GNU<"release_shared_capability">,
1693                     CXX11<"clang", "release_shared_capability">]>,
1694                   Accessor<"isGeneric",
1695                     [GNU<"release_generic_capability">,
1696                      CXX11<"clang", "release_generic_capability">,
1697                      GNU<"unlock_function">]>];
1698  let Documentation = [ReleaseCapabilityDocs];
1699}
1700
1701def RequiresCapability : InheritableAttr {
1702  let Spellings = [GNU<"requires_capability">,
1703                   CXX11<"clang", "requires_capability">,
1704                   GNU<"exclusive_locks_required">,
1705                   GNU<"requires_shared_capability">,
1706                   CXX11<"clang", "requires_shared_capability">,
1707                   GNU<"shared_locks_required">];
1708  let Args = [VariadicExprArgument<"Args">];
1709  let LateParsed = 1;
1710  let TemplateDependent = 1;
1711  let ParseArgumentsAsUnevaluated = 1;
1712  let DuplicatesAllowedWhileMerging = 1;
1713  let Subjects = SubjectList<[Function]>;
1714  let Accessors = [Accessor<"isShared", [GNU<"requires_shared_capability">,
1715                                         GNU<"shared_locks_required">,
1716                                CXX11<"clang","requires_shared_capability">]>];
1717  let Documentation = [Undocumented];
1718}
1719
1720def NoThreadSafetyAnalysis : InheritableAttr {
1721  let Spellings = [GNU<"no_thread_safety_analysis">];
1722  let Subjects = SubjectList<[Function]>;
1723  let Documentation = [Undocumented];
1724}
1725
1726def GuardedBy : InheritableAttr {
1727  let Spellings = [GNU<"guarded_by">];
1728  let Args = [ExprArgument<"Arg">];
1729  let LateParsed = 1;
1730  let TemplateDependent = 1;
1731  let ParseArgumentsAsUnevaluated = 1;
1732  let DuplicatesAllowedWhileMerging = 1;
1733  let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1734                             "ExpectedFieldOrGlobalVar">;
1735  let Documentation = [Undocumented];
1736}
1737
1738def PtGuardedBy : InheritableAttr {
1739  let Spellings = [GNU<"pt_guarded_by">];
1740  let Args = [ExprArgument<"Arg">];
1741  let LateParsed = 1;
1742  let TemplateDependent = 1;
1743  let ParseArgumentsAsUnevaluated = 1;
1744  let DuplicatesAllowedWhileMerging = 1;
1745  let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1746                             "ExpectedFieldOrGlobalVar">;
1747  let Documentation = [Undocumented];
1748}
1749
1750def AcquiredAfter : InheritableAttr {
1751  let Spellings = [GNU<"acquired_after">];
1752  let Args = [VariadicExprArgument<"Args">];
1753  let LateParsed = 1;
1754  let TemplateDependent = 1;
1755  let ParseArgumentsAsUnevaluated = 1;
1756  let DuplicatesAllowedWhileMerging = 1;
1757  let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1758                             "ExpectedFieldOrGlobalVar">;
1759  let Documentation = [Undocumented];
1760}
1761
1762def AcquiredBefore : InheritableAttr {
1763  let Spellings = [GNU<"acquired_before">];
1764  let Args = [VariadicExprArgument<"Args">];
1765  let LateParsed = 1;
1766  let TemplateDependent = 1;
1767  let ParseArgumentsAsUnevaluated = 1;
1768  let DuplicatesAllowedWhileMerging = 1;
1769  let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
1770                             "ExpectedFieldOrGlobalVar">;
1771  let Documentation = [Undocumented];
1772}
1773
1774def AssertExclusiveLock : InheritableAttr {
1775  let Spellings = [GNU<"assert_exclusive_lock">];
1776  let Args = [VariadicExprArgument<"Args">];
1777  let LateParsed = 1;
1778  let TemplateDependent = 1;
1779  let ParseArgumentsAsUnevaluated = 1;
1780  let DuplicatesAllowedWhileMerging = 1;
1781  let Subjects = SubjectList<[Function]>;
1782  let Documentation = [Undocumented];
1783}
1784
1785def AssertSharedLock : InheritableAttr {
1786  let Spellings = [GNU<"assert_shared_lock">];
1787  let Args = [VariadicExprArgument<"Args">];
1788  let LateParsed = 1;
1789  let TemplateDependent = 1;
1790  let ParseArgumentsAsUnevaluated = 1;
1791  let DuplicatesAllowedWhileMerging = 1;
1792  let Subjects = SubjectList<[Function]>;
1793  let Documentation = [Undocumented];
1794}
1795
1796// The first argument is an integer or boolean value specifying the return value
1797// of a successful lock acquisition.
1798def ExclusiveTrylockFunction : InheritableAttr {
1799  let Spellings = [GNU<"exclusive_trylock_function">];
1800  let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
1801  let LateParsed = 1;
1802  let TemplateDependent = 1;
1803  let ParseArgumentsAsUnevaluated = 1;
1804  let DuplicatesAllowedWhileMerging = 1;
1805  let Subjects = SubjectList<[Function]>;
1806  let Documentation = [Undocumented];
1807}
1808
1809// The first argument is an integer or boolean value specifying the return value
1810// of a successful lock acquisition.
1811def SharedTrylockFunction : InheritableAttr {
1812  let Spellings = [GNU<"shared_trylock_function">];
1813  let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
1814  let LateParsed = 1;
1815  let TemplateDependent = 1;
1816  let ParseArgumentsAsUnevaluated = 1;
1817  let DuplicatesAllowedWhileMerging = 1;
1818  let Subjects = SubjectList<[Function]>;
1819  let Documentation = [Undocumented];
1820}
1821
1822def LockReturned : InheritableAttr {
1823  let Spellings = [GNU<"lock_returned">];
1824  let Args = [ExprArgument<"Arg">];
1825  let LateParsed = 1;
1826  let TemplateDependent = 1;
1827  let ParseArgumentsAsUnevaluated = 1;
1828  let Subjects = SubjectList<[Function]>;
1829  let Documentation = [Undocumented];
1830}
1831
1832def LocksExcluded : InheritableAttr {
1833  let Spellings = [GNU<"locks_excluded">];
1834  let Args = [VariadicExprArgument<"Args">];
1835  let LateParsed = 1;
1836  let TemplateDependent = 1;
1837  let ParseArgumentsAsUnevaluated = 1;
1838  let DuplicatesAllowedWhileMerging = 1;
1839  let Subjects = SubjectList<[Function]>;
1840  let Documentation = [Undocumented];
1841}
1842
1843// C/C++ consumed attributes.
1844
1845def Consumable : InheritableAttr {
1846  let Spellings = [GNU<"consumable">];
1847  let Subjects = SubjectList<[CXXRecord]>;
1848  let Args = [EnumArgument<"DefaultState", "ConsumedState",
1849                           ["unknown", "consumed", "unconsumed"],
1850                           ["Unknown", "Consumed", "Unconsumed"]>];
1851  let Documentation = [ConsumableDocs];
1852}
1853
1854def ConsumableAutoCast : InheritableAttr {
1855  let Spellings = [GNU<"consumable_auto_cast_state">];
1856  let Subjects = SubjectList<[CXXRecord]>;
1857  let Documentation = [Undocumented];
1858}
1859
1860def ConsumableSetOnRead : InheritableAttr {
1861  let Spellings = [GNU<"consumable_set_state_on_read">];
1862  let Subjects = SubjectList<[CXXRecord]>;
1863  let Documentation = [Undocumented];
1864}
1865
1866def CallableWhen : InheritableAttr {
1867  let Spellings = [GNU<"callable_when">];
1868  let Subjects = SubjectList<[CXXMethod]>;
1869  let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
1870                                   ["unknown", "consumed", "unconsumed"],
1871                                   ["Unknown", "Consumed", "Unconsumed"]>];
1872  let Documentation = [CallableWhenDocs];
1873}
1874
1875def ParamTypestate : InheritableAttr {
1876  let Spellings = [GNU<"param_typestate">];
1877  let Subjects = SubjectList<[ParmVar]>;
1878  let Args = [EnumArgument<"ParamState", "ConsumedState",
1879                           ["unknown", "consumed", "unconsumed"],
1880                           ["Unknown", "Consumed", "Unconsumed"]>];
1881  let Documentation = [ParamTypestateDocs];
1882}
1883
1884def ReturnTypestate : InheritableAttr {
1885  let Spellings = [GNU<"return_typestate">];
1886  let Subjects = SubjectList<[Function, ParmVar]>;
1887  let Args = [EnumArgument<"State", "ConsumedState",
1888                           ["unknown", "consumed", "unconsumed"],
1889                           ["Unknown", "Consumed", "Unconsumed"]>];
1890  let Documentation = [ReturnTypestateDocs];
1891}
1892
1893def SetTypestate : InheritableAttr {
1894  let Spellings = [GNU<"set_typestate">];
1895  let Subjects = SubjectList<[CXXMethod]>;
1896  let Args = [EnumArgument<"NewState", "ConsumedState",
1897                           ["unknown", "consumed", "unconsumed"],
1898                           ["Unknown", "Consumed", "Unconsumed"]>];
1899  let Documentation = [SetTypestateDocs];
1900}
1901
1902def TestTypestate : InheritableAttr {
1903  let Spellings = [GNU<"test_typestate">];
1904  let Subjects = SubjectList<[CXXMethod]>;
1905  let Args = [EnumArgument<"TestState", "ConsumedState",
1906                           ["consumed", "unconsumed"],
1907                           ["Consumed", "Unconsumed"]>];
1908  let Documentation = [TestTypestateDocs];
1909}
1910
1911// Type safety attributes for `void *' pointers and type tags.
1912
1913def ArgumentWithTypeTag : InheritableAttr {
1914  let Spellings = [GNU<"argument_with_type_tag">,
1915                   GNU<"pointer_with_type_tag">];
1916  let Args = [IdentifierArgument<"ArgumentKind">,
1917              UnsignedArgument<"ArgumentIdx">,
1918              UnsignedArgument<"TypeTagIdx">,
1919              BoolArgument<"IsPointer">];
1920  let HasCustomParsing = 1;
1921  let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
1922}
1923
1924def TypeTagForDatatype : InheritableAttr {
1925  let Spellings = [GNU<"type_tag_for_datatype">];
1926  let Args = [IdentifierArgument<"ArgumentKind">,
1927              TypeArgument<"MatchingCType">,
1928              BoolArgument<"LayoutCompatible">,
1929              BoolArgument<"MustBeNull">];
1930//  let Subjects = SubjectList<[Var], ErrorDiag>;
1931  let HasCustomParsing = 1;
1932  let Documentation = [TypeTagForDatatypeDocs];
1933}
1934
1935// Microsoft-related attributes
1936
1937def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1938  let Spellings = [Declspec<"novtable">];
1939  let Subjects = SubjectList<[CXXRecord]>;
1940  let Documentation = [MSNoVTableDocs];
1941}
1942
1943def : IgnoredAttr {
1944  let Spellings = [Declspec<"property">];
1945}
1946
1947def MSStruct : InheritableAttr {
1948  let Spellings = [GCC<"ms_struct">];
1949  let Subjects = SubjectList<[Record]>;
1950  let Documentation = [Undocumented];
1951}
1952
1953def DLLExport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
1954  let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
1955  let Subjects = SubjectList<[Function, Var, CXXRecord]>;
1956  let Documentation = [Undocumented];
1957}
1958
1959def DLLImport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
1960  let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
1961  let Subjects = SubjectList<[Function, Var, CXXRecord]>;
1962  let Documentation = [Undocumented];
1963}
1964
1965def SelectAny : InheritableAttr {
1966  let Spellings = [Declspec<"selectany">];
1967  let LangOpts = [MicrosoftExt];
1968  let Documentation = [Undocumented];
1969}
1970
1971def Thread : Attr {
1972  let Spellings = [Declspec<"thread">];
1973  let LangOpts = [MicrosoftExt];
1974  let Documentation = [ThreadDocs];
1975  let Subjects = SubjectList<[Var]>;
1976}
1977
1978def Win64 : IgnoredAttr {
1979  let Spellings = [Keyword<"__w64">];
1980  let LangOpts = [MicrosoftExt];
1981}
1982
1983def Ptr32 : TypeAttr {
1984  let Spellings = [Keyword<"__ptr32">];
1985  let Documentation = [Undocumented];
1986}
1987
1988def Ptr64 : TypeAttr {
1989  let Spellings = [Keyword<"__ptr64">];
1990  let Documentation = [Undocumented];
1991}
1992
1993def SPtr : TypeAttr {
1994  let Spellings = [Keyword<"__sptr">];
1995  let Documentation = [Undocumented];
1996}
1997
1998def UPtr : TypeAttr {
1999  let Spellings = [Keyword<"__uptr">];
2000  let Documentation = [Undocumented];
2001}
2002
2003def MSInheritance : InheritableAttr {
2004  let LangOpts = [MicrosoftExt];
2005  let Args = [DefaultBoolArgument<"BestCase", 1>];
2006  let Spellings = [Keyword<"__single_inheritance">,
2007                   Keyword<"__multiple_inheritance">,
2008                   Keyword<"__virtual_inheritance">,
2009                   Keyword<"__unspecified_inheritance">];
2010  let AdditionalMembers = [{
2011  static bool hasVBPtrOffsetField(Spelling Inheritance) {
2012    return Inheritance == Keyword_unspecified_inheritance;
2013  }
2014
2015  // Only member pointers to functions need a this adjustment, since it can be
2016  // combined with the field offset for data pointers.
2017  static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) {
2018    return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance;
2019  }
2020
2021  static bool hasVBTableOffsetField(Spelling Inheritance) {
2022    return Inheritance >= Keyword_virtual_inheritance;
2023  }
2024
2025  static bool hasOnlyOneField(bool IsMemberFunction,
2026                              Spelling Inheritance) {
2027    if (IsMemberFunction)
2028      return Inheritance <= Keyword_single_inheritance;
2029    return Inheritance <= Keyword_multiple_inheritance;
2030  }
2031  }];
2032  let Documentation = [MSInheritanceDocs];
2033}
2034
2035def MSVtorDisp : InheritableAttr {
2036  // This attribute has no spellings as it is only ever created implicitly.
2037  let Spellings = [];
2038  let Args = [UnsignedArgument<"vdm">];
2039  let SemaHandler = 0;
2040
2041  let AdditionalMembers = [{
2042  enum Mode {
2043    Never,
2044    ForVBaseOverride,
2045    ForVFTable
2046  };
2047
2048  Mode getVtorDispMode() const { return Mode(vdm); }
2049  }];
2050  let Documentation = [Undocumented];
2051}
2052
2053def InitSeg : Attr {
2054  let Spellings = [Pragma<"", "init_seg">];
2055  let Args = [StringArgument<"Section">];
2056  let SemaHandler = 0;
2057  let Documentation = [InitSegDocs];
2058  let AdditionalMembers = [{
2059  void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2060    OS << '(' << getSection() << ')';
2061  }
2062  }];
2063}
2064
2065def Unaligned : IgnoredAttr {
2066  let Spellings = [Keyword<"__unaligned">];
2067}
2068
2069def LoopHint : Attr {
2070  /// #pragma clang loop <option> directive
2071  /// vectorize: vectorizes loop operations if State == Enable.
2072  /// vectorize_width: vectorize loop operations with width 'Value'.
2073  /// interleave: interleave multiple loop iterations if State == Enable.
2074  /// interleave_count: interleaves 'Value' loop interations.
2075  /// unroll: fully unroll loop if State == Enable.
2076  /// unroll_count: unrolls loop 'Value' times.
2077
2078  /// #pragma unroll <argument> directive
2079  /// <no arg>: fully unrolls loop.
2080  /// boolean: fully unrolls loop if State == Enable.
2081  /// expression: unrolls loop 'Value' times.
2082
2083  let Spellings = [Pragma<"clang", "loop">, Pragma<"", "unroll">,
2084                   Pragma<"", "nounroll">];
2085
2086  /// State of the loop optimization specified by the spelling.
2087  let Args = [EnumArgument<"Option", "OptionType",
2088                          ["vectorize", "vectorize_width", "interleave", "interleave_count",
2089                           "unroll", "unroll_count"],
2090                          ["Vectorize", "VectorizeWidth", "Interleave", "InterleaveCount",
2091                           "Unroll", "UnrollCount"]>,
2092              EnumArgument<"State", "LoopHintState",
2093                           ["enable", "disable", "numeric", "assume_safety", "full"],
2094                           ["Enable", "Disable", "Numeric", "AssumeSafety", "Full"]>,
2095              ExprArgument<"Value">];
2096
2097  let AdditionalMembers = [{
2098  static const char *getOptionName(int Option) {
2099    switch(Option) {
2100    case Vectorize: return "vectorize";
2101    case VectorizeWidth: return "vectorize_width";
2102    case Interleave: return "interleave";
2103    case InterleaveCount: return "interleave_count";
2104    case Unroll: return "unroll";
2105    case UnrollCount: return "unroll_count";
2106    }
2107    llvm_unreachable("Unhandled LoopHint option.");
2108  }
2109
2110  void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2111    unsigned SpellingIndex = getSpellingListIndex();
2112    // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
2113    // "nounroll" is already emitted as the pragma name.
2114    if (SpellingIndex == Pragma_nounroll)
2115      return;
2116    else if (SpellingIndex == Pragma_unroll) {
2117      OS << getValueString(Policy);
2118      return;
2119    }
2120
2121    assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2122    OS << getOptionName(option) << getValueString(Policy);
2123  }
2124
2125  // Return a string containing the loop hint argument including the
2126  // enclosing parentheses.
2127  std::string getValueString(const PrintingPolicy &Policy) const {
2128    std::string ValueName;
2129    llvm::raw_string_ostream OS(ValueName);
2130    OS << "(";
2131    if (state == Numeric)
2132      value->printPretty(OS, nullptr, Policy);
2133    else if (state == Enable)
2134      OS << "enable";
2135    else if (state == Full)
2136      OS << "full";
2137    else if (state == AssumeSafety)
2138      OS << "assume_safety";
2139    else
2140      OS << "disable";
2141    OS << ")";
2142    return OS.str();
2143  }
2144
2145  // Return a string suitable for identifying this attribute in diagnostics.
2146  std::string getDiagnosticName(const PrintingPolicy &Policy) const {
2147    unsigned SpellingIndex = getSpellingListIndex();
2148    if (SpellingIndex == Pragma_nounroll)
2149      return "#pragma nounroll";
2150    else if (SpellingIndex == Pragma_unroll)
2151      return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
2152
2153    assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2154    return getOptionName(option) + getValueString(Policy);
2155  }
2156  }];
2157
2158  let Documentation = [LoopHintDocs, UnrollHintDocs];
2159}
2160
2161def CapturedRecord : InheritableAttr {
2162  // This attribute has no spellings as it is only ever created implicitly.
2163  let Spellings = [];
2164  let SemaHandler = 0;
2165  let Documentation = [Undocumented];
2166}
2167
2168def OMPThreadPrivateDecl : InheritableAttr {
2169  // This attribute has no spellings as it is only ever created implicitly.
2170  let Spellings = [];
2171  let SemaHandler = 0;
2172  let Documentation = [Undocumented];
2173}
2174
2175def InternalLinkage : InheritableAttr {
2176  let Spellings = [GNU<"internal_linkage">, CXX11<"clang", "internal_linkage">];
2177  let Subjects = SubjectList<[Var, Function, CXXRecord]>;
2178  let Documentation = [InternalLinkageDocs];
2179}
2180