]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/Attr.td
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r304149, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Basic / Attr.td
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.
12 class DocumentationCategory<string name> {
13   string Name = name;
14   code Content = [{}];
15 }
16 def DocCatFunction : DocumentationCategory<"Function Attributes">;
17 def DocCatVariable : DocumentationCategory<"Variable Attributes">;
18 def DocCatType : DocumentationCategory<"Type Attributes">;
19 def DocCatStmt : DocumentationCategory<"Statement Attributes">;
20 // Attributes listed under the Undocumented category do not generate any public
21 // documentation. Ideally, this category should be used for internal-only
22 // attributes which contain no spellings.
23 def DocCatUndocumented : DocumentationCategory<"Undocumented">;
24
25 class DocDeprecated<string replacement = ""> {
26   // If the Replacement field is empty, no replacement will be listed with the
27   // documentation. Otherwise, the documentation will specify the attribute has
28   // been superseded by this replacement.
29   string Replacement = replacement;
30 }
31
32 // Specifies the documentation to be associated with the given category.
33 class 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.
52 def Undocumented : Documentation {
53   let Category = DocCatUndocumented;
54 }
55
56 include "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).
62 class AttrSubject;
63
64 include "clang/Basic/DeclNodes.td"
65 include "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.
73 class 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.
80 def NormalVar : SubsetSubject<Var,
81                               [{S->getStorageClass() != VarDecl::Register &&
82                                 S->getKind() != Decl::ImplicitParam &&
83                                 S->getKind() != Decl::ParmVar &&
84                                 S->getKind() != Decl::NonTypeTemplateParm}]>;
85 def NonParmVar : SubsetSubject<Var,
86                                [{S->getKind() != Decl::ParmVar}]>;
87 def NonBitField : SubsetSubject<Field,
88                                 [{!S->isBitField()}]>;
89
90 def ObjCInstanceMethod : SubsetSubject<ObjCMethod,
91                                        [{S->isInstanceMethod()}]>;
92
93 def ObjCInterfaceDeclInitMethod : SubsetSubject<ObjCMethod,
94                                [{S->getMethodFamily() == OMF_init &&
95                                  (isa<ObjCInterfaceDecl>(S->getDeclContext()) ||
96                                   (isa<ObjCCategoryDecl>(S->getDeclContext()) &&
97             cast<ObjCCategoryDecl>(S->getDeclContext())->IsClassExtension()))}]>;
98
99 def Struct : SubsetSubject<Record,
100                            [{!S->isUnion()}]>;
101
102 def TLSVar : SubsetSubject<Var,
103                            [{S->getTLSKind() != 0}]>;
104
105 def SharedVar : SubsetSubject<Var,
106                               [{S->hasGlobalStorage() && !S->getTLSKind()}]>;
107
108 def GlobalVar : SubsetSubject<Var,
109                              [{S->hasGlobalStorage()}]>;
110
111 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
112 // type to be a class, not a definition. This makes it impossible to create an
113 // attribute subject which accepts a Decl. Normally, this is not a problem,
114 // because the attribute can have no Subjects clause to accomplish this. But in
115 // the case of a SubsetSubject, there's no way to express it without this hack.
116 def DeclBase : AttrSubject;
117 def FunctionLike : SubsetSubject<DeclBase,
118                                   [{S->getFunctionType(false) != nullptr}]>;
119
120 def OpenCLKernelFunction : SubsetSubject<Function, [{
121   S->hasAttr<OpenCLKernelAttr>()
122 }]>;
123
124 // HasFunctionProto is a more strict version of FunctionLike, so it should
125 // never be specified in a Subjects list along with FunctionLike (due to the
126 // inclusive nature of subject testing).
127 def HasFunctionProto : SubsetSubject<DeclBase,
128                                      [{(S->getFunctionType(true) != nullptr &&
129                               isa<FunctionProtoType>(S->getFunctionType())) ||
130                                        isa<ObjCMethodDecl>(S) ||
131                                        isa<BlockDecl>(S)}]>;
132
133 // A single argument to an attribute
134 class Argument<string name, bit optional, bit fake = 0> {
135   string Name = name;
136   bit Optional = optional;
137
138   /// A fake argument is used to store and serialize additional information
139   /// in an attribute without actually changing its parsing or pretty-printing.
140   bit Fake = fake;
141 }
142
143 class BoolArgument<string name, bit opt = 0, bit fake = 0> : Argument<name, opt,
144                                                                       fake>;
145 class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
146 class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
147 class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
148 class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
149 class FunctionArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
150                                                                           opt,
151                                                                           fake>;
152 class NamedArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
153                                                                           opt,
154                                                                           fake>;
155 class TypeArgument<string name, bit opt = 0> : Argument<name, opt>;
156 class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
157 class VariadicUnsignedArgument<string name> : Argument<name, 1>;
158 class VariadicExprArgument<string name> : Argument<name, 1>;
159 class VariadicStringArgument<string name> : Argument<name, 1>;
160
161 // A version of the form major.minor[.subminor].
162 class VersionArgument<string name, bit opt = 0> : Argument<name, opt>;
163
164 // This one's a doozy, so it gets its own special type
165 // It can be an unsigned integer, or a type. Either can
166 // be dependent.
167 class AlignedArgument<string name, bit opt = 0> : Argument<name, opt>;
168
169 // A bool argument with a default value
170 class DefaultBoolArgument<string name, bit default> : BoolArgument<name, 1> {
171   bit Default = default;
172 }
173
174 // An integer argument with a default value
175 class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
176   int Default = default;
177 }
178
179 // This argument is more complex, it includes the enumerator type name,
180 // a list of strings to accept, and a list of enumerators to map them to.
181 class EnumArgument<string name, string type, list<string> values,
182                    list<string> enums, bit opt = 0, bit fake = 0>
183     : Argument<name, opt, fake> {
184   string Type = type;
185   list<string> Values = values;
186   list<string> Enums = enums;
187 }
188
189 // FIXME: There should be a VariadicArgument type that takes any other type
190 //        of argument and generates the appropriate type.
191 class VariadicEnumArgument<string name, string type, list<string> values,
192                            list<string> enums> : Argument<name, 1>  {
193   string Type = type;
194   list<string> Values = values;
195   list<string> Enums = enums;
196 }
197
198 // This handles one spelling of an attribute.
199 class Spelling<string name, string variety> {
200   string Name = name;
201   string Variety = variety;
202   bit KnownToGCC;
203 }
204
205 class GNU<string name> : Spelling<name, "GNU">;
206 class Declspec<string name> : Spelling<name, "Declspec">;
207 class Microsoft<string name> : Spelling<name, "Microsoft">;
208 class CXX11<string namespace, string name, int version = 1>
209     : Spelling<name, "CXX11"> {
210   string Namespace = namespace;
211   int Version = version;
212 }
213 class Keyword<string name> : Spelling<name, "Keyword">;
214 class Pragma<string namespace, string name> : Spelling<name, "Pragma"> {
215   string Namespace = namespace;
216 }
217
218 // The GCC spelling implies GNU<name, "GNU"> and CXX11<"gnu", name> and also
219 // sets KnownToGCC to 1. This spelling should be used for any GCC-compatible
220 // attributes.
221 class GCC<string name> : Spelling<name, "GCC"> {
222   let KnownToGCC = 1;
223 }
224
225 class Accessor<string name, list<Spelling> spellings> {
226   string Name = name;
227   list<Spelling> Spellings = spellings;
228 }
229
230 class SubjectDiag<bit warn> {
231   bit Warn = warn;
232 }
233 def WarnDiag : SubjectDiag<1>;
234 def ErrorDiag : SubjectDiag<0>;
235
236 class SubjectList<list<AttrSubject> subjects, SubjectDiag diag = WarnDiag,
237                   string customDiag = ""> {
238   list<AttrSubject> Subjects = subjects;
239   SubjectDiag Diag = diag;
240   string CustomDiag = customDiag;
241 }
242
243 class LangOpt<string name, bit negated = 0> {
244   string Name = name;
245   bit Negated = negated;
246 }
247 def MicrosoftExt : LangOpt<"MicrosoftExt">;
248 def Borland : LangOpt<"Borland">;
249 def CUDA : LangOpt<"CUDA">;
250 def COnly : LangOpt<"CPlusPlus", 1>;
251 def CPlusPlus : LangOpt<"CPlusPlus">;
252 def OpenCL : LangOpt<"OpenCL">;
253 def RenderScript : LangOpt<"RenderScript">;
254 def ObjC : LangOpt<"ObjC1">;
255 def BlocksSupported : LangOpt<"Blocks">;
256
257 // Defines targets for target-specific attributes. The list of strings should
258 // specify architectures for which the target applies, based off the ArchType
259 // enumeration in Triple.h.
260 class TargetArch<list<string> arches> {
261   list<string> Arches = arches;
262   list<string> OSes;
263   list<string> CXXABIs;
264 }
265 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
266 def TargetAVR : TargetArch<["avr"]>;
267 def TargetMips : TargetArch<["mips", "mipsel"]>;
268 def TargetMSP430 : TargetArch<["msp430"]>;
269 def TargetX86 : TargetArch<["x86"]>;
270 def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
271 def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
272   let OSes = ["Win32"];
273 }
274 def TargetMicrosoftCXXABI : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
275   let CXXABIs = ["Microsoft"];
276 }
277
278 // Attribute subject match rules that are used for #pragma clang attribute.
279 //
280 // A instance of AttrSubjectMatcherRule represents an individual match rule.
281 // An individual match rule can correspond to a number of different attribute
282 // subjects, e.g. "record" matching rule corresponds to the Record and
283 // CXXRecord attribute subjects.
284 //
285 // Match rules are used in the subject list of the #pragma clang attribute.
286 // Match rules can have sub-match rules that are instances of
287 // AttrSubjectMatcherSubRule. A sub-match rule can correspond to a number
288 // of different attribute subjects, and it can have a negated spelling as well.
289 // For example, "variable(unless(is_parameter))" matching rule corresponds to
290 // the NonParmVar attribute subject.
291 class AttrSubjectMatcherSubRule<string name, list<AttrSubject> subjects,
292                                 bit negated = 0> {
293   string Name = name;
294   list<AttrSubject> Subjects = subjects;
295   bit Negated = negated;
296   // Lists language options, one of which is required to be true for the
297   // attribute to be applicable. If empty, the language options are taken
298   // from the parent matcher rule.
299   list<LangOpt> LangOpts = [];
300 }
301 class AttrSubjectMatcherRule<string name, list<AttrSubject> subjects,
302                              list<AttrSubjectMatcherSubRule> subrules = []> {
303   string Name = name;
304   list<AttrSubject> Subjects = subjects;
305   list<AttrSubjectMatcherSubRule> Constraints = subrules;
306   // Lists language options, one of which is required to be true for the
307   // attribute to be applicable. If empty, no language options are required.
308   list<LangOpt> LangOpts = [];
309 }
310
311 // function(is_member)
312 def SubRuleForCXXMethod : AttrSubjectMatcherSubRule<"is_member", [CXXMethod]> {
313   let LangOpts = [CPlusPlus];
314 }
315 def SubjectMatcherForFunction : AttrSubjectMatcherRule<"function", [Function], [
316   SubRuleForCXXMethod
317 ]>;
318 // hasType is abstract, it should be used with one of the sub-rules.
319 def SubjectMatcherForType : AttrSubjectMatcherRule<"hasType", [], [
320   AttrSubjectMatcherSubRule<"functionType", [FunctionLike]>
321
322   // FIXME: There's a matcher ambiguity with objc methods and blocks since
323   // functionType excludes them but functionProtoType includes them.
324   // AttrSubjectMatcherSubRule<"functionProtoType", [HasFunctionProto]>
325 ]>;
326 def SubjectMatcherForTypedef : AttrSubjectMatcherRule<"type_alias",
327                                                       [TypedefName]>;
328 def SubjectMatcherForRecord : AttrSubjectMatcherRule<"record", [Record,
329                                                                 CXXRecord], [
330   // unless(is_union)
331   AttrSubjectMatcherSubRule<"is_union", [Struct], 1>
332 ]>;
333 def SubjectMatcherForEnum : AttrSubjectMatcherRule<"enum", [Enum]>;
334 def SubjectMatcherForEnumConstant : AttrSubjectMatcherRule<"enum_constant",
335                                                            [EnumConstant]>;
336 def SubjectMatcherForVar : AttrSubjectMatcherRule<"variable", [Var], [
337   AttrSubjectMatcherSubRule<"is_thread_local", [TLSVar]>,
338   AttrSubjectMatcherSubRule<"is_global", [GlobalVar]>,
339   AttrSubjectMatcherSubRule<"is_parameter", [ParmVar]>,
340   // unless(is_parameter)
341   AttrSubjectMatcherSubRule<"is_parameter", [NonParmVar], 1>
342 ]>;
343 def SubjectMatcherForField : AttrSubjectMatcherRule<"field", [Field]>;
344 def SubjectMatcherForNamespace : AttrSubjectMatcherRule<"namespace",
345                                                         [Namespace]> {
346   let LangOpts = [CPlusPlus];
347 }
348 def SubjectMatcherForObjCInterface : AttrSubjectMatcherRule<"objc_interface",
349                                                             [ObjCInterface]> {
350   let LangOpts = [ObjC];
351 }
352 def SubjectMatcherForObjCProtocol : AttrSubjectMatcherRule<"objc_protocol",
353                                                            [ObjCProtocol]> {
354   let LangOpts = [ObjC];
355 }
356 def SubjectMatcherForObjCCategory : AttrSubjectMatcherRule<"objc_category",
357                                                            [ObjCCategory]> {
358   let LangOpts = [ObjC];
359 }
360 def SubjectMatcherForObjCMethod : AttrSubjectMatcherRule<"objc_method",
361                                                          [ObjCMethod], [
362   AttrSubjectMatcherSubRule<"is_instance", [ObjCInstanceMethod]>
363 ]> {
364   let LangOpts = [ObjC];
365 }
366 def SubjectMatcherForObjCProperty : AttrSubjectMatcherRule<"objc_property",
367                                                            [ObjCProperty]> {
368   let LangOpts = [ObjC];
369 }
370 def SubjectMatcherForBlock : AttrSubjectMatcherRule<"block", [Block]> {
371   let LangOpts = [BlocksSupported];
372 }
373
374 // Aggregate attribute subject match rules are abstract match rules that can't
375 // be used directly in #pragma clang attribute. Instead, users have to use
376 // subject match rules that correspond to attribute subjects that derive from
377 // the specified subject.
378 class AttrSubjectMatcherAggregateRule<AttrSubject subject> {
379   AttrSubject Subject = subject;
380 }
381
382 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule<Named>;
383
384 class Attr {
385   // The various ways in which an attribute can be spelled in source
386   list<Spelling> Spellings;
387   // The things to which an attribute can appertain
388   SubjectList Subjects;
389   // The arguments allowed on an attribute
390   list<Argument> Args = [];
391   // Accessors which should be generated for the attribute.
392   list<Accessor> Accessors = [];
393   // Set to true for attributes with arguments which require delayed parsing.
394   bit LateParsed = 0;
395   // Set to false to prevent an attribute from being propagated from a template
396   // to the instantiation.
397   bit Clone = 1;
398   // Set to true for attributes which must be instantiated within templates
399   bit TemplateDependent = 0;
400   // Set to true for attributes that have a corresponding AST node.
401   bit ASTNode = 1;
402   // Set to true for attributes which have handler in Sema.
403   bit SemaHandler = 1;
404   // Set to true for attributes that are completely ignored.
405   bit Ignored = 0;
406   // Set to true if the attribute's parsing does not match its semantic
407   // content. Eg) It parses 3 args, but semantically takes 4 args.  Opts out of
408   // common attribute error checking.
409   bit HasCustomParsing = 0;
410   // Set to true if all of the attribute's arguments should be parsed in an
411   // unevaluated context.
412   bit ParseArgumentsAsUnevaluated = 0;
413   // Set to true if this attribute can be duplicated on a subject when merging
414   // attributes. By default, attributes are not merged.
415   bit DuplicatesAllowedWhileMerging = 0;
416   // Set to true if this attribute meaningful when applied to or inherited 
417   // in a class template definition.
418   bit MeaningfulToClassTemplateDefinition = 0;
419   // Set to true if this attribute can be used with '#pragma clang attribute'.
420   // By default, when this value is false, an attribute is supported by the
421   // '#pragma clang attribute' only when:
422   // - It has documentation.
423   // - It has a subject list whose subjects can be represented using subject
424   //   match rules.
425   // - It has GNU/CXX11 spelling and doesn't require delayed parsing.
426   bit ForcePragmaAttributeSupport = 0;
427   // Lists language options, one of which is required to be true for the
428   // attribute to be applicable. If empty, no language options are required.
429   list<LangOpt> LangOpts = [];
430   // Any additional text that should be included verbatim in the class.
431   // Note: Any additional data members will leak and should be constructed
432   // externally on the ASTContext.
433   code AdditionalMembers = [{}];
434   // Any documentation that should be associated with the attribute. Since an
435   // attribute may be documented under multiple categories, more than one
436   // Documentation entry may be listed.
437   list<Documentation> Documentation;
438 }
439
440 /// A type attribute is not processed on a declaration or a statement.
441 class TypeAttr : Attr {
442   // By default, type attributes do not get an AST node.
443   let ASTNode = 0;
444 }
445
446 /// A stmt attribute is not processed on a declaration or a type.
447 class StmtAttr : Attr;
448
449 /// An inheritable attribute is inherited by later redeclarations.
450 class InheritableAttr : Attr;
451
452 /// A target-specific attribute.  This class is meant to be used as a mixin
453 /// with InheritableAttr or Attr depending on the attribute's needs.
454 class TargetSpecificAttr<TargetArch target> {
455   TargetArch Target = target;
456   // Attributes are generally required to have unique spellings for their names
457   // so that the parser can determine what kind of attribute it has parsed.
458   // However, target-specific attributes are special in that the attribute only
459   // "exists" for a given target. So two target-specific attributes can share
460   // the same name when they exist in different targets. To support this, a
461   // Kind can be explicitly specified for a target-specific attribute. This
462   // corresponds to the AttributeList::AT_* enum that is generated and it
463   // should contain a shared value between the attributes.
464   //
465   // Target-specific attributes which use this feature should ensure that the
466   // spellings match exactly between the attributes, and if the arguments or
467   // subjects differ, should specify HasCustomParsing = 1 and implement their
468   // own parsing and semantic handling requirements as-needed.
469   string ParseKind;
470 }
471
472 /// An inheritable parameter attribute is inherited by later
473 /// redeclarations, even when it's written on a parameter.
474 class InheritableParamAttr : InheritableAttr;
475
476 /// An attribute which changes the ABI rules for a specific parameter.
477 class ParameterABIAttr : InheritableParamAttr {
478   let Subjects = SubjectList<[ParmVar]>;
479 }
480
481 /// An ignored attribute, which we parse but discard with no checking.
482 class IgnoredAttr : Attr {
483   let Ignored = 1;
484   let ASTNode = 0;
485   let SemaHandler = 0;
486   let Documentation = [Undocumented];
487 }
488
489 //
490 // Attributes begin here
491 //
492
493 def AbiTag : Attr {
494   let Spellings = [GCC<"abi_tag">];
495   let Args = [VariadicStringArgument<"Tags">];
496   let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag,
497       "ExpectedStructClassVariableFunctionOrInlineNamespace">;
498   let MeaningfulToClassTemplateDefinition = 1;
499   let Documentation = [AbiTagsDocs];
500 }
501
502 def AddressSpace : TypeAttr {
503   let Spellings = [GNU<"address_space">];
504   let Args = [IntArgument<"AddressSpace">];
505   let Documentation = [Undocumented];
506 }
507
508 def Alias : Attr {
509   let Spellings = [GCC<"alias">];
510   let Args = [StringArgument<"Aliasee">];
511   let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
512                              "ExpectedFunctionOrGlobalVar">;
513   let Documentation = [Undocumented];
514 }
515
516 def Aligned : InheritableAttr {
517   let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
518                    Keyword<"_Alignas">];
519 //  let Subjects = SubjectList<[NonBitField, NormalVar, Tag]>;
520   let Args = [AlignedArgument<"Alignment", 1>];
521   let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
522                    Accessor<"isC11", [Keyword<"_Alignas">]>,
523                    Accessor<"isAlignas", [Keyword<"alignas">,
524                                           Keyword<"_Alignas">]>,
525                    Accessor<"isDeclspec",[Declspec<"align">]>];
526   let Documentation = [Undocumented];
527 }
528
529 def AlignValue : Attr {
530   let Spellings = [
531     // Unfortunately, this is semantically an assertion, not a directive
532     // (something else must ensure the alignment), so aligned_value is a
533     // probably a better name. We might want to add an aligned_value spelling in
534     // the future (and a corresponding C++ attribute), but this can be done
535     // later once we decide if we also want them to have slightly-different
536     // semantics than Intel's align_value.
537     GNU<"align_value">
538     // Intel's compiler on Windows also supports:
539     // , Declspec<"align_value">
540   ];
541   let Args = [ExprArgument<"Alignment">];
542   let Subjects = SubjectList<[Var, TypedefName], WarnDiag,
543                              "ExpectedVariableOrTypedef">;
544   let Documentation = [AlignValueDocs];
545 }
546
547 def AlignMac68k : InheritableAttr {
548   // This attribute has no spellings as it is only ever created implicitly.
549   let Spellings = [];
550   let SemaHandler = 0;
551   let Documentation = [Undocumented];
552 }
553
554 def AlwaysInline : InheritableAttr {
555   let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
556   let Subjects = SubjectList<[Function]>;
557   let Documentation = [Undocumented];
558 }
559
560 def XRayInstrument : InheritableAttr {
561   let Spellings = [GNU<"xray_always_instrument">,
562                    CXX11<"clang", "xray_always_instrument">,
563                    GNU<"xray_never_instrument">,
564                    CXX11<"clang", "xray_never_instrument">];
565   let Subjects = SubjectList<[CXXMethod, ObjCMethod, Function], WarnDiag,
566                               "ExpectedFunctionOrMethod">;
567   let Accessors = [Accessor<"alwaysXRayInstrument",
568                      [GNU<"xray_always_instrument">,
569                       CXX11<"clang", "xray_always_instrument">]>,
570                    Accessor<"neverXRayInstrument",
571                      [GNU<"xray_never_instrument">,
572                       CXX11<"clang", "xray_never_instrument">]>];
573   let Documentation = [XRayDocs];
574 }
575
576 def XRayLogArgs : InheritableAttr {
577   let Spellings = [GNU<"xray_log_args">, CXX11<"clang", "xray_log_args">];
578   let Subjects = SubjectList<
579       [CXXMethod, ObjCMethod, Function], WarnDiag, "ExpectedFunctionOrMethod"
580   >;
581   let Args = [UnsignedArgument<"ArgumentCount">];
582   let Documentation = [XRayDocs];
583 }
584
585 def TLSModel : InheritableAttr {
586   let Spellings = [GCC<"tls_model">];
587   let Subjects = SubjectList<[TLSVar], ErrorDiag, "ExpectedTLSVar">;
588   let Args = [StringArgument<"Model">];
589   let Documentation = [TLSModelDocs];
590 }
591
592 def AnalyzerNoReturn : InheritableAttr {
593   let Spellings = [GNU<"analyzer_noreturn">];
594   let Documentation = [Undocumented];
595 }
596
597 def Annotate : InheritableParamAttr {
598   let Spellings = [GNU<"annotate">];
599   let Args = [StringArgument<"Annotation">];
600   // Ensure that the annotate attribute can be used with
601   // '#pragma clang attribute' even though it has no subject list.
602   let ForcePragmaAttributeSupport = 1;
603   let Documentation = [Undocumented];
604 }
605
606 def ARMInterrupt : InheritableAttr, TargetSpecificAttr<TargetARM> {
607   // NOTE: If you add any additional spellings, MSP430Interrupt's,
608   // MipsInterrupt's and AnyX86Interrupt's spellings must match.
609   let Spellings = [GNU<"interrupt">];
610   let Args = [EnumArgument<"Interrupt", "InterruptType",
611                            ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
612                            ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
613                            1>];
614   let ParseKind = "Interrupt";
615   let HasCustomParsing = 1;
616   let Documentation = [ARMInterruptDocs];
617 }
618
619 def AVRInterrupt : InheritableAttr, TargetSpecificAttr<TargetAVR> {
620   let Spellings = [GNU<"interrupt">];
621   let Subjects = SubjectList<[Function]>;
622   let ParseKind = "Interrupt";
623   let Documentation = [AVRInterruptDocs];
624 }
625
626 def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
627   let Spellings = [GNU<"signal">];
628   let Subjects = SubjectList<[Function]>;
629   let Documentation = [AVRSignalDocs];
630 }
631
632 def AsmLabel : InheritableAttr {
633   let Spellings = [Keyword<"asm">, Keyword<"__asm__">];
634   let Args = [StringArgument<"Label">];
635   let SemaHandler = 0;
636   let Documentation = [Undocumented];
637 }
638
639 def Availability : InheritableAttr {
640   let Spellings = [GNU<"availability">];
641   let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
642               VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
643               BoolArgument<"unavailable">, StringArgument<"message">,
644               BoolArgument<"strict">, StringArgument<"replacement">];
645   let AdditionalMembers =
646 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
647     return llvm::StringSwitch<llvm::StringRef>(Platform)
648              .Case("android", "Android")
649              .Case("ios", "iOS")
650              .Case("macos", "macOS")
651              .Case("tvos", "tvOS")
652              .Case("watchos", "watchOS")
653              .Case("ios_app_extension", "iOS (App Extension)")
654              .Case("macos_app_extension", "macOS (App Extension)")
655              .Case("tvos_app_extension", "tvOS (App Extension)")
656              .Case("watchos_app_extension", "watchOS (App Extension)")
657              .Default(llvm::StringRef());
658 }
659 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
660     return llvm::StringSwitch<llvm::StringRef>(Platform)
661              .Case("ios", "iOS")
662              .Case("macos", "macOS")
663              .Case("tvos", "tvOS")
664              .Case("watchos", "watchOS")
665              .Case("ios_app_extension", "iOSApplicationExtension")
666              .Case("macos_app_extension", "macOSApplicationExtension")
667              .Case("tvos_app_extension", "tvOSApplicationExtension")
668              .Case("watchos_app_extension", "watchOSApplicationExtension")
669              .Default(Platform);
670 }
671 static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
672     return llvm::StringSwitch<llvm::StringRef>(Platform)
673              .Case("iOS", "ios")
674              .Case("macOS", "macos")
675              .Case("tvOS", "tvos")
676              .Case("watchOS", "watchos")
677              .Case("iOSApplicationExtension", "ios_app_extension")
678              .Case("macOSApplicationExtension", "macos_app_extension")
679              .Case("tvOSApplicationExtension", "tvos_app_extension")
680              .Case("watchOSApplicationExtension", "watchos_app_extension")
681              .Default(Platform);
682 } }];
683   let HasCustomParsing = 1;
684   let DuplicatesAllowedWhileMerging = 1;
685   let Subjects = SubjectList<[Named]>;
686   let Documentation = [AvailabilityDocs];
687 }
688
689 def ExternalSourceSymbol : InheritableAttr {
690   let Spellings = [GNU<"external_source_symbol">,
691                    CXX11<"clang", "external_source_symbol">];
692   let Args = [StringArgument<"language", 1>,
693               StringArgument<"definedIn", 1>,
694               BoolArgument<"generatedDeclaration", 1>];
695   let HasCustomParsing = 1;
696   let Subjects = SubjectList<[Named]>;
697   let Documentation = [ExternalSourceSymbolDocs];
698 }
699
700 def Blocks : InheritableAttr {
701   let Spellings = [GNU<"blocks">];
702   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
703   let Documentation = [Undocumented];
704 }
705
706 def Bounded : IgnoredAttr {
707   let Spellings = [GNU<"bounded">];
708 }
709
710 def CarriesDependency : InheritableParamAttr {
711   let Spellings = [GNU<"carries_dependency">,
712                    CXX11<"","carries_dependency", 200809>];
713   let Subjects = SubjectList<[ParmVar, ObjCMethod, Function], ErrorDiag>;
714   let Documentation = [CarriesDependencyDocs];
715 }
716
717 def CDecl : InheritableAttr {
718   let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
719 //  let Subjects = [Function, ObjCMethod];
720   let Documentation = [Undocumented];
721 }
722
723 // cf_audited_transfer indicates that the given function has been
724 // audited and has been marked with the appropriate cf_consumed and
725 // cf_returns_retained attributes.  It is generally applied by
726 // '#pragma clang arc_cf_code_audited' rather than explicitly.
727 def CFAuditedTransfer : InheritableAttr {
728   let Spellings = [GNU<"cf_audited_transfer">];
729   let Subjects = SubjectList<[Function], ErrorDiag>;
730   let Documentation = [Undocumented];
731 }
732
733 // cf_unknown_transfer is an explicit opt-out of cf_audited_transfer.
734 // It indicates that the function has unknown or unautomatable
735 // transfer semantics.
736 def CFUnknownTransfer : InheritableAttr {
737   let Spellings = [GNU<"cf_unknown_transfer">];
738   let Subjects = SubjectList<[Function], ErrorDiag>;
739   let Documentation = [Undocumented];
740 }
741
742 def CFReturnsRetained : InheritableAttr {
743   let Spellings = [GNU<"cf_returns_retained">];
744 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
745   let Documentation = [Undocumented];
746 }
747
748 def CFReturnsNotRetained : InheritableAttr {
749   let Spellings = [GNU<"cf_returns_not_retained">];
750 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
751   let Documentation = [Undocumented];
752 }
753
754 def CFConsumed : InheritableParamAttr {
755   let Spellings = [GNU<"cf_consumed">];
756   let Subjects = SubjectList<[ParmVar]>;
757   let Documentation = [Undocumented];
758 }
759
760 def Cleanup : InheritableAttr {
761   let Spellings = [GCC<"cleanup">];
762   let Args = [FunctionArgument<"FunctionDecl">];
763   let Subjects = SubjectList<[Var]>;
764   let Documentation = [Undocumented];
765 }
766
767 def Cold : InheritableAttr {
768   let Spellings = [GCC<"cold">];
769   let Subjects = SubjectList<[Function]>;
770   let Documentation = [Undocumented];
771 }
772
773 def Common : InheritableAttr {
774   let Spellings = [GCC<"common">];
775   let Subjects = SubjectList<[Var]>;
776   let Documentation = [Undocumented];
777 }
778
779 def Const : InheritableAttr {
780   let Spellings = [GCC<"const">, GCC<"__const">];
781   let Documentation = [Undocumented];
782 }
783
784 def Constructor : InheritableAttr {
785   let Spellings = [GCC<"constructor">];
786   let Args = [DefaultIntArgument<"Priority", 65535>];
787   let Subjects = SubjectList<[Function]>;
788   let Documentation = [Undocumented];
789 }
790
791 // CUDA attributes are spelled __attribute__((attr)) or __declspec(__attr__).
792
793 def CUDAConstant : InheritableAttr {
794   let Spellings = [GNU<"constant">, Declspec<"__constant__">];
795   let Subjects = SubjectList<[Var]>;
796   let LangOpts = [CUDA];
797   let Documentation = [Undocumented];
798 }
799
800 def CUDACudartBuiltin : IgnoredAttr {
801   let Spellings = [GNU<"cudart_builtin">, Declspec<"__cudart_builtin__">];
802   let LangOpts = [CUDA];
803 }
804
805 def CUDADevice : InheritableAttr {
806   let Spellings = [GNU<"device">, Declspec<"__device__">];
807   let Subjects = SubjectList<[Function, Var]>;
808   let LangOpts = [CUDA];
809   let Documentation = [Undocumented];
810 }
811
812 def CUDADeviceBuiltin : IgnoredAttr {
813   let Spellings = [GNU<"device_builtin">, Declspec<"__device_builtin__">];
814   let LangOpts = [CUDA];
815 }
816
817 def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
818   let Spellings = [GNU<"device_builtin_surface_type">,
819                    Declspec<"__device_builtin_surface_type__">];
820   let LangOpts = [CUDA];
821 }
822
823 def CUDADeviceBuiltinTextureType : IgnoredAttr {
824   let Spellings = [GNU<"device_builtin_texture_type">,
825                    Declspec<"__device_builtin_texture_type__">];
826   let LangOpts = [CUDA];
827 }
828
829 def CUDAGlobal : InheritableAttr {
830   let Spellings = [GNU<"global">, Declspec<"__global__">];
831   let Subjects = SubjectList<[Function]>;
832   let LangOpts = [CUDA];
833   let Documentation = [Undocumented];
834 }
835
836 def CUDAHost : InheritableAttr {
837   let Spellings = [GNU<"host">, Declspec<"__host__">];
838   let Subjects = SubjectList<[Function]>;
839   let LangOpts = [CUDA];
840   let Documentation = [Undocumented];
841 }
842
843 def CUDAInvalidTarget : InheritableAttr {
844   let Spellings = [];
845   let Subjects = SubjectList<[Function]>;
846   let LangOpts = [CUDA];
847   let Documentation = [Undocumented];
848 }
849
850 def CUDALaunchBounds : InheritableAttr {
851   let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
852   let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
853   let LangOpts = [CUDA];
854   let Subjects = SubjectList<[ObjCMethod, FunctionLike], WarnDiag,
855                              "ExpectedFunctionOrMethod">;
856   // An AST node is created for this attribute, but is not used by other parts
857   // of the compiler. However, this node needs to exist in the AST because
858   // non-LLVM backends may be relying on the attribute's presence.
859   let Documentation = [Undocumented];
860 }
861
862 def CUDAShared : InheritableAttr {
863   let Spellings = [GNU<"shared">, Declspec<"__shared__">];
864   let Subjects = SubjectList<[Var]>;
865   let LangOpts = [CUDA];
866   let Documentation = [Undocumented];
867 }
868
869 def C11NoReturn : InheritableAttr {
870   let Spellings = [Keyword<"_Noreturn">];
871   let Subjects = SubjectList<[Function], ErrorDiag>;
872   let SemaHandler = 0;
873   let Documentation = [C11NoReturnDocs];
874 }
875
876 def CXX11NoReturn : InheritableAttr {
877   let Spellings = [CXX11<"","noreturn", 200809>];
878   let Subjects = SubjectList<[Function], ErrorDiag>;
879   let Documentation = [CXX11NoReturnDocs];
880 }
881
882 def OpenCLKernel : InheritableAttr {
883   let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
884   let Subjects = SubjectList<[Function], ErrorDiag>;
885   let Documentation = [Undocumented];
886 }
887
888 def OpenCLUnrollHint : InheritableAttr {
889   let Spellings = [GNU<"opencl_unroll_hint">];
890   let Args = [UnsignedArgument<"UnrollHint">];
891   let Documentation = [OpenCLUnrollHintDocs];
892 }
893
894 def OpenCLIntelReqdSubGroupSize: InheritableAttr {
895   let Spellings = [GNU<"intel_reqd_sub_group_size">];
896   let Args = [UnsignedArgument<"SubGroupSize">];
897   let Subjects = SubjectList<[Function], ErrorDiag>;
898   let Documentation = [OpenCLIntelReqdSubGroupSizeDocs];
899 }
900
901 // This attribute is both a type attribute, and a declaration attribute (for
902 // parameter variables).
903 def OpenCLAccess : Attr {
904   let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
905                    Keyword<"__write_only">, Keyword<"write_only">,
906                    Keyword<"__read_write">, Keyword<"read_write">];
907   let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag,
908                              "ExpectedParameterOrTypedef">;
909   let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
910                                            Keyword<"read_only">]>,
911                    Accessor<"isReadWrite", [Keyword<"__read_write">,
912                                             Keyword<"read_write">]>,
913                    Accessor<"isWriteOnly", [Keyword<"__write_only">,
914                                             Keyword<"write_only">]>];
915   let Documentation = [OpenCLAccessDocs];
916 }
917
918 def OpenCLPrivateAddressSpace : TypeAttr {
919   let Spellings = [Keyword<"__private">, Keyword<"private">];
920   let Documentation = [OpenCLAddressSpacePrivateDocs];
921 }
922
923 def OpenCLGlobalAddressSpace : TypeAttr {
924   let Spellings = [Keyword<"__global">, Keyword<"global">];
925   let Documentation = [OpenCLAddressSpaceGlobalDocs];
926 }
927
928 def OpenCLLocalAddressSpace : TypeAttr {
929   let Spellings = [Keyword<"__local">, Keyword<"local">];
930   let Documentation = [OpenCLAddressSpaceLocalDocs];
931 }
932
933 def OpenCLConstantAddressSpace : TypeAttr {
934   let Spellings = [Keyword<"__constant">, Keyword<"constant">];
935   let Documentation = [OpenCLAddressSpaceConstantDocs];
936 }
937
938 def OpenCLGenericAddressSpace : TypeAttr {
939   let Spellings = [Keyword<"__generic">, Keyword<"generic">];
940   let Documentation = [OpenCLAddressSpaceGenericDocs];
941 }
942
943 def OpenCLNoSVM : Attr {
944   let Spellings = [GNU<"nosvm">];
945   let Subjects = SubjectList<[Var]>;
946   let Documentation = [OpenCLNoSVMDocs];
947   let LangOpts = [OpenCL];
948   let ASTNode = 0;
949 }
950
951 def RenderScriptKernel : Attr {
952   let Spellings = [GNU<"kernel">];
953   let Subjects = SubjectList<[Function]>;
954   let Documentation = [RenderScriptKernelAttributeDocs];
955   let LangOpts = [RenderScript];
956 }
957
958 def Deprecated : InheritableAttr {
959   let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
960                    CXX11<"","deprecated", 201309>];
961   let Args = [StringArgument<"Message", 1>,
962               // An optional string argument that enables us to provide a
963               // Fix-It.
964               StringArgument<"Replacement", 1>];
965   let MeaningfulToClassTemplateDefinition = 1;
966   let Documentation = [DeprecatedDocs];
967 }
968
969 def Destructor : InheritableAttr {
970   let Spellings = [GCC<"destructor">];
971   let Args = [DefaultIntArgument<"Priority", 65535>];
972   let Subjects = SubjectList<[Function]>;
973   let Documentation = [Undocumented];
974 }
975
976 def EmptyBases : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
977   let Spellings = [Declspec<"empty_bases">];
978   let Subjects = SubjectList<[CXXRecord]>;
979   let Documentation = [EmptyBasesDocs];
980 }
981
982 def AllocSize : InheritableAttr {
983   let Spellings = [GCC<"alloc_size">];
984   let Subjects = SubjectList<[Function]>;
985   let Args = [IntArgument<"ElemSizeParam">, IntArgument<"NumElemsParam", 1>];
986   let TemplateDependent = 1;
987   let Documentation = [AllocSizeDocs];
988 }
989
990 def EnableIf : InheritableAttr {
991   let Spellings = [GNU<"enable_if">];
992   let Subjects = SubjectList<[Function]>;
993   let Args = [ExprArgument<"Cond">, StringArgument<"Message">];
994   let TemplateDependent = 1;
995   let Documentation = [EnableIfDocs];
996 }
997
998 def ExtVectorType : Attr {
999   let Spellings = [GNU<"ext_vector_type">];
1000   let Subjects = SubjectList<[TypedefName], ErrorDiag>;
1001   let Args = [ExprArgument<"NumElements">];
1002   let ASTNode = 0;
1003   let Documentation = [Undocumented];
1004 }
1005
1006 def FallThrough : StmtAttr {
1007   let Spellings = [CXX11<"", "fallthrough", 201603>,
1008                    CXX11<"clang", "fallthrough">];
1009 //  let Subjects = [NullStmt];
1010   let Documentation = [FallthroughDocs];
1011 }
1012
1013 def FastCall : InheritableAttr {
1014   let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
1015                    Keyword<"_fastcall">];
1016 //  let Subjects = [Function, ObjCMethod];
1017   let Documentation = [FastCallDocs];
1018 }
1019
1020 def RegCall : InheritableAttr {
1021   let Spellings = [GCC<"regcall">, Keyword<"__regcall">];
1022   let Documentation = [RegCallDocs];
1023 }
1024
1025 def Final : InheritableAttr {
1026   let Spellings = [Keyword<"final">, Keyword<"sealed">];
1027   let Accessors = [Accessor<"isSpelledAsSealed", [Keyword<"sealed">]>];
1028   let SemaHandler = 0;
1029   let Documentation = [Undocumented];
1030 }
1031
1032 def MinSize : InheritableAttr {
1033   let Spellings = [GNU<"minsize">];
1034   let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
1035   let Documentation = [Undocumented];
1036 }
1037
1038 def FlagEnum : InheritableAttr {
1039   let Spellings = [GNU<"flag_enum">];
1040   let Subjects = SubjectList<[Enum]>;
1041   let Documentation = [FlagEnumDocs];
1042 }
1043
1044 def EnumExtensibility : InheritableAttr {
1045   let Spellings = [GNU<"enum_extensibility">,
1046                    CXX11<"clang", "enum_extensibility">];
1047   let Subjects = SubjectList<[Enum]>;
1048   let Args = [EnumArgument<"Extensibility", "Kind",
1049               ["closed", "open"], ["Closed", "Open"]>];
1050   let Documentation = [EnumExtensibilityDocs];
1051 }
1052
1053 def Flatten : InheritableAttr {
1054   let Spellings = [GCC<"flatten">];
1055   let Subjects = SubjectList<[Function], ErrorDiag>;
1056   let Documentation = [FlattenDocs];
1057 }
1058
1059 def Format : InheritableAttr {
1060   let Spellings = [GCC<"format">];
1061   let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">,
1062               IntArgument<"FirstArg">];
1063   let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto], WarnDiag,
1064                              "ExpectedFunctionWithProtoType">;
1065   let Documentation = [FormatDocs];
1066 }
1067
1068 def FormatArg : InheritableAttr {
1069   let Spellings = [GCC<"format_arg">];
1070   let Args = [IntArgument<"FormatIdx">];
1071   let Subjects = SubjectList<[ObjCMethod, HasFunctionProto], WarnDiag,
1072                              "ExpectedFunctionWithProtoType">;
1073   let Documentation = [Undocumented];
1074 }
1075
1076 def GNUInline : InheritableAttr {
1077   let Spellings = [GCC<"gnu_inline">];
1078   let Subjects = SubjectList<[Function]>;
1079   let Documentation = [Undocumented];
1080 }
1081
1082 def Hot : InheritableAttr {
1083   let Spellings = [GCC<"hot">];
1084   let Subjects = SubjectList<[Function]>;
1085   // An AST node is created for this attribute, but not actually used beyond
1086   // semantic checking for mutual exclusion with the Cold attribute.
1087   let Documentation = [Undocumented];
1088 }
1089
1090 def IBAction : InheritableAttr {
1091   let Spellings = [GNU<"ibaction">];
1092   let Subjects = SubjectList<[ObjCInstanceMethod], WarnDiag,
1093                              "ExpectedObjCInstanceMethod">;
1094   // An AST node is created for this attribute, but is not used by other parts
1095   // of the compiler. However, this node needs to exist in the AST because
1096   // external tools rely on it.
1097   let Documentation = [Undocumented];
1098 }
1099
1100 def IBOutlet : InheritableAttr {
1101   let Spellings = [GNU<"iboutlet">];
1102 //  let Subjects = [ObjCIvar, ObjCProperty];
1103   let Documentation = [Undocumented];
1104 }
1105
1106 def IBOutletCollection : InheritableAttr {
1107   let Spellings = [GNU<"iboutletcollection">];
1108   let Args = [TypeArgument<"Interface", 1>];
1109 //  let Subjects = [ObjCIvar, ObjCProperty];
1110   let Documentation = [Undocumented];
1111 }
1112
1113 def IFunc : Attr {
1114   let Spellings = [GCC<"ifunc">];
1115   let Args = [StringArgument<"Resolver">];
1116   let Subjects = SubjectList<[Function]>;
1117   let Documentation = [IFuncDocs];
1118 }
1119
1120 def Restrict : InheritableAttr {
1121   let Spellings = [Declspec<"restrict">, GCC<"malloc">];
1122   let Subjects = SubjectList<[Function]>;
1123   let Documentation = [Undocumented];
1124 }
1125
1126 def LayoutVersion : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1127   let Spellings = [Declspec<"layout_version">];
1128   let Args = [UnsignedArgument<"Version">];
1129   let Subjects = SubjectList<[CXXRecord]>;
1130   let Documentation = [LayoutVersionDocs];
1131 }
1132
1133 def MaxFieldAlignment : InheritableAttr {
1134   // This attribute has no spellings as it is only ever created implicitly.
1135   let Spellings = [];
1136   let Args = [UnsignedArgument<"Alignment">];
1137   let SemaHandler = 0;
1138   let Documentation = [Undocumented];
1139 }
1140
1141 def MayAlias : InheritableAttr {
1142   // FIXME: this is a type attribute in GCC, but a declaration attribute here.
1143   let Spellings = [GCC<"may_alias">];
1144   let Documentation = [Undocumented];
1145 }
1146
1147 def MSABI : InheritableAttr {
1148   let Spellings = [GCC<"ms_abi">];
1149 //  let Subjects = [Function, ObjCMethod];
1150   let Documentation = [MSABIDocs];
1151 }
1152
1153 def MSP430Interrupt : InheritableAttr, TargetSpecificAttr<TargetMSP430> {
1154   // NOTE: If you add any additional spellings, ARMInterrupt's, MipsInterrupt's
1155   // and AnyX86Interrupt's spellings must match.
1156   let Spellings = [GNU<"interrupt">];
1157   let Args = [UnsignedArgument<"Number">];
1158   let ParseKind = "Interrupt";
1159   let HasCustomParsing = 1;
1160   let Documentation = [Undocumented];
1161 }
1162
1163 def Mips16 : InheritableAttr, TargetSpecificAttr<TargetMips> {
1164   let Spellings = [GCC<"mips16">];
1165   let Subjects = SubjectList<[Function], ErrorDiag>;
1166   let Documentation = [Undocumented];
1167 }
1168
1169 def MipsInterrupt : InheritableAttr, TargetSpecificAttr<TargetMips> {
1170   // NOTE: If you add any additional spellings, ARMInterrupt's,
1171   // MSP430Interrupt's and AnyX86Interrupt's spellings must match.
1172   let Spellings = [GNU<"interrupt">];
1173   let Subjects = SubjectList<[Function]>;
1174   let Args = [EnumArgument<"Interrupt", "InterruptType",
1175                            ["vector=sw0", "vector=sw1", "vector=hw0",
1176                             "vector=hw1", "vector=hw2", "vector=hw3",
1177                             "vector=hw4", "vector=hw5", "eic", ""],
1178                            ["sw0", "sw1", "hw0", "hw1", "hw2", "hw3",
1179                             "hw4", "hw5", "eic", "eic"]
1180                            >];
1181   let ParseKind = "Interrupt";
1182   let Documentation = [MipsInterruptDocs];
1183 }
1184
1185 def MicroMips : InheritableAttr, TargetSpecificAttr<TargetMips> {
1186   let Spellings = [GCC<"micromips">];
1187   let Subjects = SubjectList<[Function], ErrorDiag>;
1188   let Documentation = [MicroMipsDocs];
1189 }
1190
1191 def Mode : Attr {
1192   let Spellings = [GCC<"mode">];
1193   let Subjects = SubjectList<[Var, Enum, TypedefName, Field], ErrorDiag,
1194                              "ExpectedVariableEnumFieldOrTypedef">;
1195   let Args = [IdentifierArgument<"Mode">];
1196   let Documentation = [Undocumented];
1197 }
1198
1199 def Naked : InheritableAttr {
1200   let Spellings = [GCC<"naked">, Declspec<"naked">];
1201   let Subjects = SubjectList<[Function]>;
1202   let Documentation = [Undocumented];
1203 }
1204
1205 def NeonPolyVectorType : TypeAttr {
1206   let Spellings = [GNU<"neon_polyvector_type">];
1207   let Args = [IntArgument<"NumElements">];
1208   let Documentation = [Undocumented];
1209 }
1210
1211 def NeonVectorType : TypeAttr {
1212   let Spellings = [GNU<"neon_vector_type">];
1213   let Args = [IntArgument<"NumElements">];
1214   let Documentation = [Undocumented];
1215 }
1216
1217 def ReturnsTwice : InheritableAttr {
1218   let Spellings = [GCC<"returns_twice">];
1219   let Subjects = SubjectList<[Function]>;
1220   let Documentation = [Undocumented];
1221 }
1222
1223 def DisableTailCalls : InheritableAttr {
1224   let Spellings = [GNU<"disable_tail_calls">,
1225                    CXX11<"clang", "disable_tail_calls">];
1226   let Subjects = SubjectList<[Function, ObjCMethod]>;
1227   let Documentation = [DisableTailCallsDocs];
1228 }
1229
1230 def NoAlias : InheritableAttr {
1231   let Spellings = [Declspec<"noalias">];
1232   let Subjects = SubjectList<[Function]>;
1233   let Documentation = [NoAliasDocs];
1234 }
1235
1236 def NoCommon : InheritableAttr {
1237   let Spellings = [GCC<"nocommon">];
1238   let Subjects = SubjectList<[Var]>;
1239   let Documentation = [Undocumented];
1240 }
1241
1242 def NoDebug : InheritableAttr {
1243   let Spellings = [GCC<"nodebug">];
1244   let Subjects = SubjectList<[FunctionLike, ObjCMethod, NonParmVar], WarnDiag,
1245                               "ExpectedVariableOrFunction">;
1246   let Documentation = [NoDebugDocs];
1247 }
1248
1249 def NoDuplicate : InheritableAttr {
1250   let Spellings = [GNU<"noduplicate">, CXX11<"clang", "noduplicate">];
1251   let Subjects = SubjectList<[Function]>;
1252   let Documentation = [NoDuplicateDocs];
1253 }
1254
1255 def Convergent : InheritableAttr {
1256   let Spellings = [GNU<"convergent">, CXX11<"clang", "convergent">];
1257   let Subjects = SubjectList<[Function]>;
1258   let Documentation = [ConvergentDocs];
1259 }
1260
1261 def NoInline : InheritableAttr {
1262   let Spellings = [GCC<"noinline">, Declspec<"noinline">];
1263   let Subjects = SubjectList<[Function]>;
1264   let Documentation = [Undocumented];
1265 }
1266
1267 def NoMips16 : InheritableAttr, TargetSpecificAttr<TargetMips> {
1268   let Spellings = [GCC<"nomips16">];
1269   let Subjects = SubjectList<[Function], ErrorDiag>;
1270   let Documentation = [Undocumented];
1271 }
1272
1273 def NoMicroMips : InheritableAttr, TargetSpecificAttr<TargetMips> {
1274   let Spellings = [GCC<"nomicromips">];
1275   let Subjects = SubjectList<[Function], ErrorDiag>;
1276   let Documentation = [MicroMipsDocs];
1277 }
1278
1279 // This is not a TargetSpecificAttr so that is silently accepted and
1280 // ignored on other targets as encouraged by the OpenCL spec.
1281 //
1282 // See OpenCL 1.2 6.11.5: "It is our intention that a particular
1283 // implementation of OpenCL be free to ignore all attributes and the
1284 // resulting executable binary will produce the same result."
1285 //
1286 // However, only AMD GPU targets will emit the corresponding IR
1287 // attribute.
1288 //
1289 // FIXME: This provides a sub-optimal error message if you attempt to
1290 // use this in CUDA, since CUDA does not use the same terminology.
1291 //
1292 // FIXME: SubjectList should be for OpenCLKernelFunction, but is not to
1293 // workaround needing to see kernel attribute before others to know if
1294 // this should be rejected on non-kernels.
1295
1296 def AMDGPUFlatWorkGroupSize : InheritableAttr {
1297   let Spellings = [GNU<"amdgpu_flat_work_group_size">];
1298   let Args = [UnsignedArgument<"Min">, UnsignedArgument<"Max">];
1299   let Documentation = [AMDGPUFlatWorkGroupSizeDocs];
1300   let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1301 }
1302
1303 def AMDGPUWavesPerEU : InheritableAttr {
1304   let Spellings = [GNU<"amdgpu_waves_per_eu">];
1305   let Args = [UnsignedArgument<"Min">, UnsignedArgument<"Max", 1>];
1306   let Documentation = [AMDGPUWavesPerEUDocs];
1307   let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1308 }
1309
1310 def AMDGPUNumSGPR : InheritableAttr {
1311   let Spellings = [GNU<"amdgpu_num_sgpr">];
1312   let Args = [UnsignedArgument<"NumSGPR">];
1313   let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1314   let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1315 }
1316
1317 def AMDGPUNumVGPR : InheritableAttr {
1318   let Spellings = [GNU<"amdgpu_num_vgpr">];
1319   let Args = [UnsignedArgument<"NumVGPR">];
1320   let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1321   let Subjects = SubjectList<[Function], ErrorDiag, "ExpectedKernelFunction">;
1322 }
1323
1324 def NoSplitStack : InheritableAttr {
1325   let Spellings = [GCC<"no_split_stack">];
1326   let Subjects = SubjectList<[Function], ErrorDiag>;
1327   let Documentation = [NoSplitStackDocs];
1328 }
1329
1330 def NonNull : InheritableParamAttr {
1331   let Spellings = [GCC<"nonnull">];
1332   let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
1333                              "ExpectedFunctionMethodOrParameter">;
1334   let Args = [VariadicUnsignedArgument<"Args">];
1335   let AdditionalMembers =
1336 [{bool isNonNull(unsigned idx) const {
1337     if (!args_size())
1338       return true;
1339     for (const auto &V : args())
1340       if (V == idx)
1341         return true;
1342     return false;
1343   } }];
1344   // FIXME: We should merge duplicates into a single nonnull attribute.
1345   let DuplicatesAllowedWhileMerging = 1;
1346   let Documentation = [NonNullDocs];
1347 }
1348
1349 def ReturnsNonNull : InheritableAttr {
1350   let Spellings = [GCC<"returns_nonnull">];
1351   let Subjects = SubjectList<[ObjCMethod, Function], WarnDiag,
1352                              "ExpectedFunctionOrMethod">;
1353   let Documentation = [ReturnsNonNullDocs];
1354 }
1355
1356 // pass_object_size(N) indicates that the parameter should have
1357 // __builtin_object_size with Type=N evaluated on the parameter at the callsite.
1358 def PassObjectSize : InheritableParamAttr {
1359   let Spellings = [GNU<"pass_object_size">];
1360   let Args = [IntArgument<"Type">];
1361   let Subjects = SubjectList<[ParmVar]>;
1362   let Documentation = [PassObjectSizeDocs];
1363 }
1364
1365 // Nullability type attributes.
1366 def TypeNonNull : TypeAttr {
1367   let Spellings = [Keyword<"_Nonnull">];
1368   let Documentation = [TypeNonNullDocs];
1369 }
1370
1371 def TypeNullable : TypeAttr {
1372   let Spellings = [Keyword<"_Nullable">];
1373   let Documentation = [TypeNullableDocs];
1374 }
1375
1376 def TypeNullUnspecified : TypeAttr {
1377   let Spellings = [Keyword<"_Null_unspecified">];
1378   let Documentation = [TypeNullUnspecifiedDocs];
1379 }
1380
1381 def ObjCKindOf : TypeAttr {
1382   let Spellings = [Keyword<"__kindof">];
1383   let Documentation = [Undocumented];
1384 }
1385
1386 def AssumeAligned : InheritableAttr {
1387   let Spellings = [GCC<"assume_aligned">];
1388   let Subjects = SubjectList<[ObjCMethod, Function]>;
1389   let Args = [ExprArgument<"Alignment">, ExprArgument<"Offset", 1>];
1390   let Documentation = [AssumeAlignedDocs];
1391 }
1392
1393 def AllocAlign : InheritableAttr {
1394   let Spellings = [GCC<"alloc_align">];
1395   let Subjects = SubjectList<[HasFunctionProto], WarnDiag,
1396                              "ExpectedFunctionWithProtoType">;
1397   let Args = [IntArgument<"ParamIndex">];
1398   let Documentation = [AllocAlignDocs];
1399 }
1400
1401 def NoReturn : InheritableAttr {
1402   let Spellings = [GCC<"noreturn">, Declspec<"noreturn">];
1403   // FIXME: Does GCC allow this on the function instead?
1404   let Documentation = [Undocumented];
1405 }
1406
1407 def NoInstrumentFunction : InheritableAttr {
1408   let Spellings = [GCC<"no_instrument_function">];
1409   let Subjects = SubjectList<[Function]>;
1410   let Documentation = [Undocumented];
1411 }
1412
1413 def NotTailCalled : InheritableAttr {
1414   let Spellings = [GNU<"not_tail_called">, CXX11<"clang", "not_tail_called">];
1415   let Subjects = SubjectList<[Function]>;
1416   let Documentation = [NotTailCalledDocs];
1417 }
1418
1419 def NoThrow : InheritableAttr {
1420   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
1421   let Documentation = [Undocumented];
1422 }
1423
1424 def NvWeak : IgnoredAttr {
1425   // No Declspec spelling of this attribute; the CUDA headers use
1426   // __attribute__((nv_weak)) unconditionally.
1427   let Spellings = [GNU<"nv_weak">];
1428   let LangOpts = [CUDA];
1429 }
1430
1431 def ObjCBridge : InheritableAttr {
1432   let Spellings = [GNU<"objc_bridge">];
1433   let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
1434                              "ExpectedStructOrUnionOrTypedef">;
1435   let Args = [IdentifierArgument<"BridgedType">];
1436   let Documentation = [Undocumented];
1437 }
1438
1439 def ObjCBridgeMutable : InheritableAttr {
1440   let Spellings = [GNU<"objc_bridge_mutable">];
1441   let Subjects = SubjectList<[Record], ErrorDiag>;
1442   let Args = [IdentifierArgument<"BridgedType">];
1443   let Documentation = [Undocumented];
1444 }
1445
1446 def ObjCBridgeRelated : InheritableAttr {
1447   let Spellings = [GNU<"objc_bridge_related">];
1448   let Subjects = SubjectList<[Record], ErrorDiag>;
1449   let Args = [IdentifierArgument<"RelatedClass">,
1450           IdentifierArgument<"ClassMethod", 1>,
1451           IdentifierArgument<"InstanceMethod", 1>];
1452   let HasCustomParsing = 1;
1453   let Documentation = [Undocumented];
1454 }
1455
1456 def NSReturnsRetained : InheritableAttr {
1457   let Spellings = [GNU<"ns_returns_retained">];
1458 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1459   let Documentation = [Undocumented];
1460 }
1461
1462 def NSReturnsNotRetained : InheritableAttr {
1463   let Spellings = [GNU<"ns_returns_not_retained">];
1464 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1465   let Documentation = [Undocumented];
1466 }
1467
1468 def NSReturnsAutoreleased : InheritableAttr {
1469   let Spellings = [GNU<"ns_returns_autoreleased">];
1470 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1471   let Documentation = [Undocumented];
1472 }
1473
1474 def NSConsumesSelf : InheritableAttr {
1475   let Spellings = [GNU<"ns_consumes_self">];
1476   let Subjects = SubjectList<[ObjCMethod]>;
1477   let Documentation = [Undocumented];
1478 }
1479
1480 def NSConsumed : InheritableParamAttr {
1481   let Spellings = [GNU<"ns_consumed">];
1482   let Subjects = SubjectList<[ParmVar]>;
1483   let Documentation = [Undocumented];
1484 }
1485
1486 def ObjCException : InheritableAttr {
1487   let Spellings = [GNU<"objc_exception">];
1488   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1489   let Documentation = [Undocumented];
1490 }
1491
1492 def ObjCMethodFamily : InheritableAttr {
1493   let Spellings = [GNU<"objc_method_family">];
1494   let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1495   let Args = [EnumArgument<"Family", "FamilyKind",
1496                ["none", "alloc", "copy", "init", "mutableCopy", "new"],
1497                ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
1498                 "OMF_mutableCopy", "OMF_new"]>];
1499   let Documentation = [ObjCMethodFamilyDocs];
1500 }
1501
1502 def ObjCNSObject : InheritableAttr {
1503   let Spellings = [GNU<"NSObject">];
1504   let Documentation = [Undocumented];
1505 }
1506
1507 def ObjCIndependentClass : InheritableAttr {
1508   let Spellings = [GNU<"objc_independent_class">];
1509   let Documentation = [Undocumented];
1510 }
1511
1512 def ObjCPreciseLifetime : InheritableAttr {
1513   let Spellings = [GNU<"objc_precise_lifetime">];
1514   let Subjects = SubjectList<[Var], ErrorDiag>;
1515   let Documentation = [Undocumented];
1516 }
1517
1518 def ObjCReturnsInnerPointer : InheritableAttr {
1519   let Spellings = [GNU<"objc_returns_inner_pointer">];
1520   let Subjects = SubjectList<[ObjCMethod, ObjCProperty], ErrorDiag>;
1521   let Documentation = [Undocumented];
1522 }
1523
1524 def ObjCRequiresSuper : InheritableAttr {
1525   let Spellings = [GNU<"objc_requires_super">];
1526   let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
1527   let Documentation = [ObjCRequiresSuperDocs];
1528 }
1529
1530 def ObjCRootClass : InheritableAttr {
1531   let Spellings = [GNU<"objc_root_class">];
1532   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1533   let Documentation = [Undocumented];
1534 }
1535
1536 def ObjCSubclassingRestricted : InheritableAttr {
1537   let Spellings = [GNU<"objc_subclassing_restricted">];
1538   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1539   let Documentation = [ObjCSubclassingRestrictedDocs];
1540 }
1541
1542 def ObjCExplicitProtocolImpl : InheritableAttr {
1543   let Spellings = [GNU<"objc_protocol_requires_explicit_implementation">];
1544   let Subjects = SubjectList<[ObjCProtocol], ErrorDiag>;
1545   let Documentation = [Undocumented];
1546 }
1547
1548 def ObjCDesignatedInitializer : Attr {
1549   let Spellings = [GNU<"objc_designated_initializer">];
1550   let Subjects = SubjectList<[ObjCInterfaceDeclInitMethod], ErrorDiag,
1551                              "ExpectedObjCInterfaceDeclInitMethod">;
1552   let Documentation = [Undocumented];
1553 }
1554
1555 def ObjCRuntimeName : Attr {
1556   let Spellings = [GNU<"objc_runtime_name">];
1557   let Subjects = SubjectList<[ObjCInterface, ObjCProtocol], ErrorDiag>;
1558   let Args = [StringArgument<"MetadataName">];
1559   let Documentation = [ObjCRuntimeNameDocs];
1560 }
1561
1562 def ObjCRuntimeVisible : Attr {
1563   let Spellings = [GNU<"objc_runtime_visible">];
1564   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1565   let Documentation = [ObjCRuntimeVisibleDocs];
1566 }
1567
1568 def ObjCBoxable : Attr {
1569   let Spellings = [GNU<"objc_boxable">];
1570   let Subjects = SubjectList<[Record], ErrorDiag, "ExpectedStructOrUnion">;
1571   let Documentation = [ObjCBoxableDocs];
1572 }
1573
1574 def OptimizeNone : InheritableAttr {
1575   let Spellings = [GNU<"optnone">, CXX11<"clang", "optnone">];
1576   let Subjects = SubjectList<[Function, ObjCMethod]>;
1577   let Documentation = [OptnoneDocs];
1578 }
1579
1580 def Overloadable : Attr {
1581   let Spellings = [GNU<"overloadable">];
1582   let Subjects = SubjectList<[Function], ErrorDiag>;
1583   let Documentation = [OverloadableDocs];
1584 }
1585
1586 def Override : InheritableAttr { 
1587   let Spellings = [Keyword<"override">];
1588   let SemaHandler = 0;
1589   let Documentation = [Undocumented];
1590 }
1591
1592 def Ownership : InheritableAttr {
1593   let Spellings = [GNU<"ownership_holds">, GNU<"ownership_returns">,
1594                    GNU<"ownership_takes">];
1595   let Accessors = [Accessor<"isHolds", [GNU<"ownership_holds">]>,
1596                    Accessor<"isReturns", [GNU<"ownership_returns">]>,
1597                    Accessor<"isTakes", [GNU<"ownership_takes">]>];
1598   let AdditionalMembers = [{
1599     enum OwnershipKind { Holds, Returns, Takes };
1600     OwnershipKind getOwnKind() const {
1601       return isHolds() ? Holds :
1602              isTakes() ? Takes :
1603              Returns;
1604     }
1605   }];
1606   let Args = [IdentifierArgument<"Module">, VariadicUnsignedArgument<"Args">];
1607   let Subjects = SubjectList<[HasFunctionProto], WarnDiag,
1608                              "ExpectedFunctionWithProtoType">;
1609   let Documentation = [Undocumented];
1610 }
1611
1612 def Packed : InheritableAttr {
1613   let Spellings = [GCC<"packed">];
1614 //  let Subjects = [Tag, Field];
1615   let Documentation = [Undocumented];
1616 }
1617
1618 def IntelOclBicc : InheritableAttr {
1619   let Spellings = [GNU<"intel_ocl_bicc">];
1620 //  let Subjects = [Function, ObjCMethod];
1621   let Documentation = [Undocumented];
1622 }
1623
1624 def Pcs : InheritableAttr {
1625   let Spellings = [GCC<"pcs">];
1626   let Args = [EnumArgument<"PCS", "PCSType",
1627                            ["aapcs", "aapcs-vfp"],
1628                            ["AAPCS", "AAPCS_VFP"]>];
1629 //  let Subjects = [Function, ObjCMethod];
1630   let Documentation = [PcsDocs];
1631 }
1632
1633 def Pure : InheritableAttr {
1634   let Spellings = [GCC<"pure">];
1635   let Documentation = [Undocumented];
1636 }
1637
1638 def Regparm : TypeAttr {
1639   let Spellings = [GCC<"regparm">];
1640   let Args = [UnsignedArgument<"NumParams">];
1641   let Documentation = [RegparmDocs];
1642 }
1643
1644 def ReqdWorkGroupSize : InheritableAttr {
1645   let Spellings = [GNU<"reqd_work_group_size">];
1646   let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
1647               UnsignedArgument<"ZDim">];
1648   let Subjects = SubjectList<[Function], ErrorDiag>;
1649   let Documentation = [Undocumented];
1650 }
1651
1652 def RequireConstantInit : InheritableAttr {
1653   let Spellings = [GNU<"require_constant_initialization">,
1654                    CXX11<"clang", "require_constant_initialization">];
1655   let Subjects = SubjectList<[GlobalVar], ErrorDiag,
1656                               "ExpectedStaticOrTLSVar">;
1657   let Documentation = [RequireConstantInitDocs];
1658   let LangOpts = [CPlusPlus];
1659 }
1660
1661 def WorkGroupSizeHint :  InheritableAttr {
1662   let Spellings = [GNU<"work_group_size_hint">];
1663   let Args = [UnsignedArgument<"XDim">, 
1664               UnsignedArgument<"YDim">,
1665               UnsignedArgument<"ZDim">];
1666   let Subjects = SubjectList<[Function], ErrorDiag>;
1667   let Documentation = [Undocumented];
1668 }
1669
1670 def InitPriority : InheritableAttr {
1671   let Spellings = [GNU<"init_priority">];
1672   let Args = [UnsignedArgument<"Priority">];
1673   let Subjects = SubjectList<[Var], ErrorDiag>;
1674   let Documentation = [Undocumented];
1675 }
1676
1677 def Section : InheritableAttr {
1678   let Spellings = [GCC<"section">, Declspec<"allocate">];
1679   let Args = [StringArgument<"Name">];
1680   let Subjects = SubjectList<[Function, GlobalVar,
1681                               ObjCMethod, ObjCProperty], ErrorDiag,
1682                              "ExpectedFunctionGlobalVarMethodOrProperty">;
1683   let Documentation = [SectionDocs];
1684 }
1685
1686 def Sentinel : InheritableAttr {
1687   let Spellings = [GCC<"sentinel">];
1688   let Args = [DefaultIntArgument<"Sentinel", 0>,
1689               DefaultIntArgument<"NullPos", 0>];
1690 //  let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>;
1691   let Documentation = [Undocumented];
1692 }
1693
1694 def StdCall : InheritableAttr {
1695   let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
1696 //  let Subjects = [Function, ObjCMethod];
1697   let Documentation = [StdCallDocs];
1698 }
1699
1700 def SwiftCall : InheritableAttr {
1701   let Spellings = [GCC<"swiftcall">];
1702 //  let Subjects = SubjectList<[Function]>;
1703   let Documentation = [SwiftCallDocs];
1704 }
1705
1706 def SwiftContext : ParameterABIAttr {
1707   let Spellings = [GCC<"swift_context">];
1708   let Documentation = [SwiftContextDocs];
1709 }
1710
1711 def SwiftErrorResult : ParameterABIAttr {
1712   let Spellings = [GCC<"swift_error_result">];
1713   let Documentation = [SwiftErrorResultDocs];
1714 }
1715
1716 def SwiftIndirectResult : ParameterABIAttr {
1717   let Spellings = [GCC<"swift_indirect_result">];
1718   let Documentation = [SwiftIndirectResultDocs];
1719 }
1720
1721 def Suppress : StmtAttr {
1722   let Spellings = [CXX11<"gsl", "suppress">];
1723   let Args = [VariadicStringArgument<"DiagnosticIdentifiers">];
1724   let Documentation = [SuppressDocs];
1725 }
1726
1727 def SysVABI : InheritableAttr {
1728   let Spellings = [GCC<"sysv_abi">];
1729 //  let Subjects = [Function, ObjCMethod];
1730   let Documentation = [Undocumented];
1731 }
1732
1733 def ThisCall : InheritableAttr {
1734   let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
1735                    Keyword<"_thiscall">];
1736 //  let Subjects = [Function, ObjCMethod];
1737   let Documentation = [ThisCallDocs];
1738 }
1739
1740 def VectorCall : InheritableAttr {
1741   let Spellings = [GNU<"vectorcall">, Keyword<"__vectorcall">,
1742                    Keyword<"_vectorcall">];
1743 //  let Subjects = [Function, ObjCMethod];
1744   let Documentation = [VectorCallDocs];
1745 }
1746
1747 def Pascal : InheritableAttr {
1748   let Spellings = [GNU<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
1749 //  let Subjects = [Function, ObjCMethod];
1750   let Documentation = [Undocumented];
1751 }
1752
1753 def PreserveMost : InheritableAttr {
1754   let Spellings = [GNU<"preserve_most">];
1755   let Documentation = [PreserveMostDocs];
1756 }
1757
1758 def PreserveAll : InheritableAttr {
1759   let Spellings = [GNU<"preserve_all">];
1760   let Documentation = [PreserveAllDocs];
1761 }
1762
1763 def Target : InheritableAttr {
1764   let Spellings = [GCC<"target">];
1765   let Args = [StringArgument<"featuresStr">];
1766   let Subjects = SubjectList<[Function], ErrorDiag>;
1767   let Documentation = [TargetDocs];
1768   let AdditionalMembers = [{
1769     typedef std::pair<std::vector<std::string>, StringRef> ParsedTargetAttr;
1770     ParsedTargetAttr parse() const {
1771       ParsedTargetAttr Ret;
1772       SmallVector<StringRef, 1> AttrFeatures;
1773       getFeaturesStr().split(AttrFeatures, ",");
1774
1775       // Grab the various features and prepend a "+" to turn on the feature to
1776       // the backend and add them to our existing set of features.
1777       for (auto &Feature : AttrFeatures) {
1778         // Go ahead and trim whitespace rather than either erroring or
1779         // accepting it weirdly.
1780         Feature = Feature.trim();
1781
1782         // We don't support cpu tuning this way currently.
1783         // TODO: Support the fpmath option. It will require checking
1784         // overall feature validity for the function with the rest of the
1785         // attributes on the function.
1786         if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
1787           continue;
1788
1789         // While we're here iterating check for a different target cpu.
1790         if (Feature.startswith("arch="))
1791           Ret.second = Feature.split("=").second.trim();
1792         else if (Feature.startswith("no-"))
1793           Ret.first.push_back("-" + Feature.split("-").second.str());
1794         else
1795           Ret.first.push_back("+" + Feature.str());
1796       }
1797       return Ret;
1798     }
1799   }];
1800 }
1801
1802 def TransparentUnion : InheritableAttr {
1803   let Spellings = [GCC<"transparent_union">];
1804 //  let Subjects = SubjectList<[Record, TypedefName]>;
1805   let Documentation = [TransparentUnionDocs];
1806   let LangOpts = [COnly];
1807 }
1808
1809 def Unavailable : InheritableAttr {
1810   let Spellings = [GNU<"unavailable">];
1811   let Args = [StringArgument<"Message", 1>,
1812               EnumArgument<"ImplicitReason", "ImplicitReason",
1813                 ["", "", "", ""],
1814                 ["IR_None",
1815                  "IR_ARCForbiddenType",
1816                  "IR_ForbiddenWeak",
1817                  "IR_ARCForbiddenConversion",
1818                  "IR_ARCInitReturnsUnrelated",
1819                  "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
1820   let Documentation = [Undocumented];
1821 }
1822
1823 def DiagnoseIf : InheritableAttr {
1824   let Spellings = [GNU<"diagnose_if">];
1825   let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
1826   let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
1827               EnumArgument<"DiagnosticType",
1828                            "DiagnosticType",
1829                            ["error", "warning"],
1830                            ["DT_Error", "DT_Warning"]>,
1831               BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
1832               NamedArgument<"Parent", 0, /*fake*/ 1>];
1833   let DuplicatesAllowedWhileMerging = 1;
1834   let LateParsed = 1;
1835   let AdditionalMembers = [{
1836     bool isError() const { return diagnosticType == DT_Error; }
1837     bool isWarning() const { return diagnosticType == DT_Warning; }
1838   }];
1839   let TemplateDependent = 1;
1840   let Documentation = [DiagnoseIfDocs];
1841 }
1842
1843 def ArcWeakrefUnavailable : InheritableAttr {
1844   let Spellings = [GNU<"objc_arc_weak_reference_unavailable">];
1845   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1846   let Documentation = [Undocumented];
1847 }
1848
1849 def ObjCGC : TypeAttr {
1850   let Spellings = [GNU<"objc_gc">];
1851   let Args = [IdentifierArgument<"Kind">];
1852   let Documentation = [Undocumented];
1853 }
1854
1855 def ObjCOwnership : InheritableAttr {
1856   let Spellings = [GNU<"objc_ownership">];
1857   let Args = [IdentifierArgument<"Kind">];
1858   let ASTNode = 0;
1859   let Documentation = [Undocumented];
1860 }
1861
1862 def ObjCRequiresPropertyDefs : InheritableAttr {
1863   let Spellings = [GNU<"objc_requires_property_definitions">];
1864   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1865   let Documentation = [Undocumented];
1866 }
1867
1868 def Unused : InheritableAttr {
1869   let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">];
1870   let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
1871                               Field, ObjCMethod, FunctionLike], WarnDiag,
1872                              "ExpectedForMaybeUnused">;
1873   let Documentation = [WarnMaybeUnusedDocs];
1874 }
1875
1876 def Used : InheritableAttr {
1877   let Spellings = [GCC<"used">];
1878   let Documentation = [Undocumented];
1879 }
1880
1881 def Uuid : InheritableAttr {
1882   let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
1883   let Args = [StringArgument<"Guid">];
1884   let Subjects = SubjectList<[Record, Enum], WarnDiag, "ExpectedEnumOrClass">;
1885   // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
1886   // CPlusPlus && (MicrosoftExt || Borland)
1887   let LangOpts = [MicrosoftExt, Borland];
1888   let Documentation = [Undocumented];
1889 }
1890
1891 def VectorSize : TypeAttr {
1892   let Spellings = [GCC<"vector_size">];
1893   let Args = [ExprArgument<"NumBytes">];
1894   let Documentation = [Undocumented];
1895 }
1896
1897 def VecTypeHint : InheritableAttr {
1898   let Spellings = [GNU<"vec_type_hint">];
1899   let Args = [TypeArgument<"TypeHint">];
1900   let Subjects = SubjectList<[Function], ErrorDiag>;
1901   let Documentation = [Undocumented];
1902 }
1903
1904 def Visibility : InheritableAttr {
1905   let Clone = 0;
1906   let Spellings = [GCC<"visibility">];
1907   let Args = [EnumArgument<"Visibility", "VisibilityType",
1908                            ["default", "hidden", "internal", "protected"],
1909                            ["Default", "Hidden", "Hidden", "Protected"]>];
1910   let MeaningfulToClassTemplateDefinition = 1;
1911   let Documentation = [Undocumented];
1912 }
1913
1914 def TypeVisibility : InheritableAttr {
1915   let Clone = 0;
1916   let Spellings = [GNU<"type_visibility">, CXX11<"clang", "type_visibility">];
1917   let Args = [EnumArgument<"Visibility", "VisibilityType",
1918                            ["default", "hidden", "internal", "protected"],
1919                            ["Default", "Hidden", "Hidden", "Protected"]>];
1920 //  let Subjects = [Tag, ObjCInterface, Namespace];
1921   let Documentation = [Undocumented];
1922 }
1923
1924 def VecReturn : InheritableAttr {
1925   let Spellings = [GNU<"vecreturn">];
1926   let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
1927   let Documentation = [Undocumented];
1928 }
1929
1930 def WarnUnused : InheritableAttr {
1931   let Spellings = [GNU<"warn_unused">];
1932   let Subjects = SubjectList<[Record]>;
1933   let Documentation = [Undocumented];
1934 }
1935
1936 def WarnUnusedResult : InheritableAttr {
1937   let Spellings = [CXX11<"", "nodiscard", 201603>,
1938                    CXX11<"clang", "warn_unused_result">,
1939                    GCC<"warn_unused_result">];
1940   let Subjects = SubjectList<[ObjCMethod, Enum, CXXRecord, FunctionLike],
1941                              WarnDiag, "ExpectedFunctionMethodEnumOrClass">;
1942   let Documentation = [WarnUnusedResultsDocs];
1943 }
1944
1945 def Weak : InheritableAttr {
1946   let Spellings = [GCC<"weak">];
1947   let Subjects = SubjectList<[Var, Function, CXXRecord]>;
1948   let Documentation = [Undocumented];
1949 }
1950
1951 def WeakImport : InheritableAttr {
1952   let Spellings = [GNU<"weak_import">];
1953   let Documentation = [Undocumented];
1954 }
1955
1956 def WeakRef : InheritableAttr {
1957   let Spellings = [GCC<"weakref">];
1958   // A WeakRef that has an argument is treated as being an AliasAttr
1959   let Args = [StringArgument<"Aliasee", 1>];
1960   let Subjects = SubjectList<[Var, Function], ErrorDiag>;
1961   let Documentation = [Undocumented];
1962 }
1963
1964 def LTOVisibilityPublic : InheritableAttr {
1965   let Spellings = [CXX11<"clang", "lto_visibility_public">];
1966   let Subjects = SubjectList<[Record]>;
1967   let Documentation = [LTOVisibilityDocs];
1968 }
1969
1970 def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
1971   // NOTE: If you add any additional spellings, ARMInterrupt's,
1972   // MSP430Interrupt's and MipsInterrupt's spellings must match.
1973   let Spellings = [GNU<"interrupt">];
1974   let Subjects = SubjectList<[HasFunctionProto]>;
1975   let ParseKind = "Interrupt";
1976   let HasCustomParsing = 1;
1977   let Documentation = [AnyX86InterruptDocs];
1978 }
1979
1980 def AnyX86NoCallerSavedRegisters : InheritableAttr,
1981                                    TargetSpecificAttr<TargetAnyX86> {
1982   let Spellings = [GCC<"no_caller_saved_registers">];
1983   let Documentation = [AnyX86NoCallerSavedRegistersDocs];
1984 }
1985
1986 def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetX86> {
1987   let Spellings = [GNU<"force_align_arg_pointer">];
1988   // Technically, this appertains to a FunctionDecl, but the target-specific
1989   // code silently allows anything function-like (such as typedefs or function
1990   // pointers), but does not apply the attribute to them.
1991   let Documentation = [Undocumented];
1992 }
1993
1994 def NoSanitize : InheritableAttr {
1995   let Spellings = [GNU<"no_sanitize">, CXX11<"clang", "no_sanitize">];
1996   let Args = [VariadicStringArgument<"Sanitizers">];
1997   let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag,
1998     "ExpectedFunctionMethodOrGlobalVar">;
1999   let Documentation = [NoSanitizeDocs];
2000   let AdditionalMembers = [{
2001     SanitizerMask getMask() const {
2002       SanitizerMask Mask = 0;
2003       for (auto SanitizerName : sanitizers()) {
2004         SanitizerMask ParsedMask =
2005             parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
2006         Mask |= expandSanitizerGroups(ParsedMask);
2007       }
2008       return Mask;
2009     }
2010   }];
2011 }
2012
2013 // Attributes to disable a specific sanitizer. No new sanitizers should be added
2014 // to this list; the no_sanitize attribute should be extended instead.
2015 def NoSanitizeSpecific : InheritableAttr {
2016   let Spellings = [GCC<"no_address_safety_analysis">,
2017                    GCC<"no_sanitize_address">,
2018                    GCC<"no_sanitize_thread">,
2019                    GNU<"no_sanitize_memory">];
2020   let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
2021         "ExpectedFunctionOrGlobalVar">;
2022   let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
2023                        NoSanitizeMemoryDocs];
2024   let ASTNode = 0;
2025 }
2026
2027 // C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
2028
2029 def GuardedVar : InheritableAttr {
2030   let Spellings = [GNU<"guarded_var">];
2031   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2032                              "ExpectedFieldOrGlobalVar">;
2033   let Documentation = [Undocumented];
2034 }
2035
2036 def PtGuardedVar : InheritableAttr {
2037   let Spellings = [GNU<"pt_guarded_var">];
2038   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2039                              "ExpectedFieldOrGlobalVar">;
2040   let Documentation = [Undocumented];
2041 }
2042
2043 def Lockable : InheritableAttr {
2044   let Spellings = [GNU<"lockable">];
2045   let Subjects = SubjectList<[Record]>;
2046   let Documentation = [Undocumented];
2047   let ASTNode = 0;  // Replaced by Capability
2048 }
2049
2050 def ScopedLockable : InheritableAttr {
2051   let Spellings = [GNU<"scoped_lockable">];
2052   let Subjects = SubjectList<[Record]>;
2053   let Documentation = [Undocumented];
2054 }
2055
2056 def Capability : InheritableAttr {
2057   let Spellings = [GNU<"capability">, CXX11<"clang", "capability">,
2058                    GNU<"shared_capability">,
2059                    CXX11<"clang", "shared_capability">];
2060   let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
2061                              "ExpectedStructOrUnionOrTypedef">;
2062   let Args = [StringArgument<"Name">];
2063   let Accessors = [Accessor<"isShared",
2064                     [GNU<"shared_capability">,
2065                      CXX11<"clang","shared_capability">]>];
2066   let Documentation = [Undocumented];
2067   let AdditionalMembers = [{
2068     bool isMutex() const { return getName().equals_lower("mutex"); }
2069     bool isRole() const { return getName().equals_lower("role"); }
2070   }];
2071 }
2072
2073 def AssertCapability : InheritableAttr {
2074   let Spellings = [GNU<"assert_capability">,
2075                    CXX11<"clang", "assert_capability">,
2076                    GNU<"assert_shared_capability">,
2077                    CXX11<"clang", "assert_shared_capability">];
2078   let Subjects = SubjectList<[Function]>;
2079   let LateParsed = 1;
2080   let TemplateDependent = 1;
2081   let ParseArgumentsAsUnevaluated = 1;
2082   let DuplicatesAllowedWhileMerging = 1;
2083   let Args = [ExprArgument<"Expr">];
2084   let Accessors = [Accessor<"isShared",
2085                     [GNU<"assert_shared_capability">,
2086                      CXX11<"clang", "assert_shared_capability">]>];
2087   let Documentation = [AssertCapabilityDocs];
2088 }
2089
2090 def AcquireCapability : InheritableAttr {
2091   let Spellings = [GNU<"acquire_capability">,
2092                    CXX11<"clang", "acquire_capability">,
2093                    GNU<"acquire_shared_capability">,
2094                    CXX11<"clang", "acquire_shared_capability">,
2095                    GNU<"exclusive_lock_function">,
2096                    GNU<"shared_lock_function">];
2097   let Subjects = SubjectList<[Function]>;
2098   let LateParsed = 1;
2099   let TemplateDependent = 1;
2100   let ParseArgumentsAsUnevaluated = 1;
2101   let DuplicatesAllowedWhileMerging = 1;
2102   let Args = [VariadicExprArgument<"Args">];
2103   let Accessors = [Accessor<"isShared",
2104                     [GNU<"acquire_shared_capability">,
2105                      CXX11<"clang", "acquire_shared_capability">,
2106                      GNU<"shared_lock_function">]>];
2107   let Documentation = [AcquireCapabilityDocs];
2108 }
2109
2110 def TryAcquireCapability : InheritableAttr {
2111   let Spellings = [GNU<"try_acquire_capability">,
2112                    CXX11<"clang", "try_acquire_capability">,
2113                    GNU<"try_acquire_shared_capability">,
2114                    CXX11<"clang", "try_acquire_shared_capability">];
2115   let Subjects = SubjectList<[Function],
2116                              ErrorDiag>;
2117   let LateParsed = 1;
2118   let TemplateDependent = 1;
2119   let ParseArgumentsAsUnevaluated = 1;
2120   let DuplicatesAllowedWhileMerging = 1;
2121   let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2122   let Accessors = [Accessor<"isShared",
2123                     [GNU<"try_acquire_shared_capability">,
2124                      CXX11<"clang", "try_acquire_shared_capability">]>];
2125   let Documentation = [TryAcquireCapabilityDocs];
2126 }
2127
2128 def ReleaseCapability : InheritableAttr {
2129   let Spellings = [GNU<"release_capability">,
2130                    CXX11<"clang", "release_capability">,
2131                    GNU<"release_shared_capability">,
2132                    CXX11<"clang", "release_shared_capability">,
2133                    GNU<"release_generic_capability">,
2134                    CXX11<"clang", "release_generic_capability">,
2135                    GNU<"unlock_function">];
2136   let Subjects = SubjectList<[Function]>;
2137   let LateParsed = 1;
2138   let TemplateDependent = 1;
2139   let ParseArgumentsAsUnevaluated = 1;
2140   let DuplicatesAllowedWhileMerging = 1;
2141   let Args = [VariadicExprArgument<"Args">];
2142   let Accessors = [Accessor<"isShared",
2143                     [GNU<"release_shared_capability">,
2144                      CXX11<"clang", "release_shared_capability">]>,
2145                    Accessor<"isGeneric",
2146                      [GNU<"release_generic_capability">,
2147                       CXX11<"clang", "release_generic_capability">,
2148                       GNU<"unlock_function">]>];
2149   let Documentation = [ReleaseCapabilityDocs];
2150 }
2151
2152 def RequiresCapability : InheritableAttr {
2153   let Spellings = [GNU<"requires_capability">,
2154                    CXX11<"clang", "requires_capability">,
2155                    GNU<"exclusive_locks_required">,
2156                    GNU<"requires_shared_capability">,
2157                    CXX11<"clang", "requires_shared_capability">,
2158                    GNU<"shared_locks_required">];
2159   let Args = [VariadicExprArgument<"Args">];
2160   let LateParsed = 1;
2161   let TemplateDependent = 1;
2162   let ParseArgumentsAsUnevaluated = 1;
2163   let DuplicatesAllowedWhileMerging = 1;
2164   let Subjects = SubjectList<[Function]>;
2165   let Accessors = [Accessor<"isShared", [GNU<"requires_shared_capability">,
2166                                          GNU<"shared_locks_required">,
2167                                 CXX11<"clang","requires_shared_capability">]>];
2168   let Documentation = [Undocumented];
2169 }
2170
2171 def NoThreadSafetyAnalysis : InheritableAttr {
2172   let Spellings = [GNU<"no_thread_safety_analysis">];
2173   let Subjects = SubjectList<[Function]>;
2174   let Documentation = [Undocumented];
2175 }
2176
2177 def GuardedBy : InheritableAttr {
2178   let Spellings = [GNU<"guarded_by">];
2179   let Args = [ExprArgument<"Arg">];
2180   let LateParsed = 1;
2181   let TemplateDependent = 1;
2182   let ParseArgumentsAsUnevaluated = 1;
2183   let DuplicatesAllowedWhileMerging = 1;
2184   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2185                              "ExpectedFieldOrGlobalVar">;
2186   let Documentation = [Undocumented];
2187 }
2188
2189 def PtGuardedBy : InheritableAttr {
2190   let Spellings = [GNU<"pt_guarded_by">];
2191   let Args = [ExprArgument<"Arg">];
2192   let LateParsed = 1;
2193   let TemplateDependent = 1;
2194   let ParseArgumentsAsUnevaluated = 1;
2195   let DuplicatesAllowedWhileMerging = 1;
2196   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2197                              "ExpectedFieldOrGlobalVar">;
2198   let Documentation = [Undocumented];
2199 }
2200
2201 def AcquiredAfter : InheritableAttr {
2202   let Spellings = [GNU<"acquired_after">];
2203   let Args = [VariadicExprArgument<"Args">];
2204   let LateParsed = 1;
2205   let TemplateDependent = 1;
2206   let ParseArgumentsAsUnevaluated = 1;
2207   let DuplicatesAllowedWhileMerging = 1;
2208   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2209                              "ExpectedFieldOrGlobalVar">;
2210   let Documentation = [Undocumented];
2211 }
2212
2213 def AcquiredBefore : InheritableAttr {
2214   let Spellings = [GNU<"acquired_before">];
2215   let Args = [VariadicExprArgument<"Args">];
2216   let LateParsed = 1;
2217   let TemplateDependent = 1;
2218   let ParseArgumentsAsUnevaluated = 1;
2219   let DuplicatesAllowedWhileMerging = 1;
2220   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2221                              "ExpectedFieldOrGlobalVar">;
2222   let Documentation = [Undocumented];
2223 }
2224
2225 def AssertExclusiveLock : InheritableAttr {
2226   let Spellings = [GNU<"assert_exclusive_lock">];
2227   let Args = [VariadicExprArgument<"Args">];
2228   let LateParsed = 1;
2229   let TemplateDependent = 1;
2230   let ParseArgumentsAsUnevaluated = 1;
2231   let DuplicatesAllowedWhileMerging = 1;
2232   let Subjects = SubjectList<[Function]>;
2233   let Documentation = [Undocumented];
2234 }
2235
2236 def AssertSharedLock : InheritableAttr {
2237   let Spellings = [GNU<"assert_shared_lock">];
2238   let Args = [VariadicExprArgument<"Args">];
2239   let LateParsed = 1;
2240   let TemplateDependent = 1;
2241   let ParseArgumentsAsUnevaluated = 1;
2242   let DuplicatesAllowedWhileMerging = 1;
2243   let Subjects = SubjectList<[Function]>;
2244   let Documentation = [Undocumented];
2245 }
2246
2247 // The first argument is an integer or boolean value specifying the return value
2248 // of a successful lock acquisition.
2249 def ExclusiveTrylockFunction : InheritableAttr {
2250   let Spellings = [GNU<"exclusive_trylock_function">];
2251   let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2252   let LateParsed = 1;
2253   let TemplateDependent = 1;
2254   let ParseArgumentsAsUnevaluated = 1;
2255   let DuplicatesAllowedWhileMerging = 1;
2256   let Subjects = SubjectList<[Function]>;
2257   let Documentation = [Undocumented];
2258 }
2259
2260 // The first argument is an integer or boolean value specifying the return value
2261 // of a successful lock acquisition.
2262 def SharedTrylockFunction : InheritableAttr {
2263   let Spellings = [GNU<"shared_trylock_function">];
2264   let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2265   let LateParsed = 1;
2266   let TemplateDependent = 1;
2267   let ParseArgumentsAsUnevaluated = 1;
2268   let DuplicatesAllowedWhileMerging = 1;
2269   let Subjects = SubjectList<[Function]>;
2270   let Documentation = [Undocumented];
2271 }
2272
2273 def LockReturned : InheritableAttr {
2274   let Spellings = [GNU<"lock_returned">];
2275   let Args = [ExprArgument<"Arg">];
2276   let LateParsed = 1;
2277   let TemplateDependent = 1;
2278   let ParseArgumentsAsUnevaluated = 1;
2279   let Subjects = SubjectList<[Function]>;
2280   let Documentation = [Undocumented];
2281 }
2282
2283 def LocksExcluded : InheritableAttr {
2284   let Spellings = [GNU<"locks_excluded">];
2285   let Args = [VariadicExprArgument<"Args">];
2286   let LateParsed = 1;
2287   let TemplateDependent = 1;
2288   let ParseArgumentsAsUnevaluated = 1;
2289   let DuplicatesAllowedWhileMerging = 1;
2290   let Subjects = SubjectList<[Function]>;
2291   let Documentation = [Undocumented];
2292 }
2293
2294 // C/C++ consumed attributes.
2295
2296 def Consumable : InheritableAttr {
2297   let Spellings = [GNU<"consumable">];
2298   let Subjects = SubjectList<[CXXRecord]>;
2299   let Args = [EnumArgument<"DefaultState", "ConsumedState",
2300                            ["unknown", "consumed", "unconsumed"],
2301                            ["Unknown", "Consumed", "Unconsumed"]>];
2302   let Documentation = [ConsumableDocs];
2303 }
2304
2305 def ConsumableAutoCast : InheritableAttr {
2306   let Spellings = [GNU<"consumable_auto_cast_state">];
2307   let Subjects = SubjectList<[CXXRecord]>;
2308   let Documentation = [Undocumented];
2309 }
2310
2311 def ConsumableSetOnRead : InheritableAttr {
2312   let Spellings = [GNU<"consumable_set_state_on_read">];
2313   let Subjects = SubjectList<[CXXRecord]>;
2314   let Documentation = [Undocumented];
2315 }
2316
2317 def CallableWhen : InheritableAttr {
2318   let Spellings = [GNU<"callable_when">];
2319   let Subjects = SubjectList<[CXXMethod]>;
2320   let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
2321                                    ["unknown", "consumed", "unconsumed"],
2322                                    ["Unknown", "Consumed", "Unconsumed"]>];
2323   let Documentation = [CallableWhenDocs];
2324 }
2325
2326 def ParamTypestate : InheritableAttr {
2327   let Spellings = [GNU<"param_typestate">];
2328   let Subjects = SubjectList<[ParmVar]>;
2329   let Args = [EnumArgument<"ParamState", "ConsumedState",
2330                            ["unknown", "consumed", "unconsumed"],
2331                            ["Unknown", "Consumed", "Unconsumed"]>];
2332   let Documentation = [ParamTypestateDocs];
2333 }
2334
2335 def ReturnTypestate : InheritableAttr {
2336   let Spellings = [GNU<"return_typestate">];
2337   let Subjects = SubjectList<[Function, ParmVar]>;
2338   let Args = [EnumArgument<"State", "ConsumedState",
2339                            ["unknown", "consumed", "unconsumed"],
2340                            ["Unknown", "Consumed", "Unconsumed"]>];
2341   let Documentation = [ReturnTypestateDocs];
2342 }
2343
2344 def SetTypestate : InheritableAttr {
2345   let Spellings = [GNU<"set_typestate">];
2346   let Subjects = SubjectList<[CXXMethod]>;
2347   let Args = [EnumArgument<"NewState", "ConsumedState",
2348                            ["unknown", "consumed", "unconsumed"],
2349                            ["Unknown", "Consumed", "Unconsumed"]>];
2350   let Documentation = [SetTypestateDocs];
2351 }
2352
2353 def TestTypestate : InheritableAttr {
2354   let Spellings = [GNU<"test_typestate">];
2355   let Subjects = SubjectList<[CXXMethod]>;
2356   let Args = [EnumArgument<"TestState", "ConsumedState",
2357                            ["consumed", "unconsumed"],
2358                            ["Consumed", "Unconsumed"]>];
2359   let Documentation = [TestTypestateDocs];
2360 }
2361
2362 // Type safety attributes for `void *' pointers and type tags.
2363
2364 def ArgumentWithTypeTag : InheritableAttr {
2365   let Spellings = [GNU<"argument_with_type_tag">,
2366                    GNU<"pointer_with_type_tag">];
2367   let Args = [IdentifierArgument<"ArgumentKind">,
2368               UnsignedArgument<"ArgumentIdx">,
2369               UnsignedArgument<"TypeTagIdx">,
2370               BoolArgument<"IsPointer">];
2371   let HasCustomParsing = 1;
2372   let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
2373 }
2374
2375 def TypeTagForDatatype : InheritableAttr {
2376   let Spellings = [GNU<"type_tag_for_datatype">];
2377   let Args = [IdentifierArgument<"ArgumentKind">,
2378               TypeArgument<"MatchingCType">,
2379               BoolArgument<"LayoutCompatible">,
2380               BoolArgument<"MustBeNull">];
2381 //  let Subjects = SubjectList<[Var], ErrorDiag>;
2382   let HasCustomParsing = 1;
2383   let Documentation = [TypeTagForDatatypeDocs];
2384 }
2385
2386 // Microsoft-related attributes
2387
2388 def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
2389   let Spellings = [Declspec<"novtable">];
2390   let Subjects = SubjectList<[CXXRecord]>;
2391   let Documentation = [MSNoVTableDocs];
2392 }
2393
2394 def : IgnoredAttr {
2395   let Spellings = [Declspec<"property">];
2396 }
2397
2398 def MSStruct : InheritableAttr {
2399   let Spellings = [GCC<"ms_struct">];
2400   let Subjects = SubjectList<[Record]>;
2401   let Documentation = [Undocumented];
2402 }
2403
2404 def DLLExport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2405   let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
2406   let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2407   let Documentation = [DLLExportDocs];
2408 }
2409
2410 def DLLImport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2411   let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
2412   let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2413   let Documentation = [DLLImportDocs];
2414 }
2415
2416 def SelectAny : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2417   let Spellings = [Declspec<"selectany">, GCC<"selectany">];
2418   let Documentation = [Undocumented];
2419 }
2420
2421 def Thread : Attr {
2422   let Spellings = [Declspec<"thread">];
2423   let LangOpts = [MicrosoftExt];
2424   let Documentation = [ThreadDocs];
2425   let Subjects = SubjectList<[Var]>;
2426 }
2427
2428 def Win64 : IgnoredAttr {
2429   let Spellings = [Keyword<"__w64">];
2430   let LangOpts = [MicrosoftExt];
2431 }
2432
2433 def Ptr32 : TypeAttr {
2434   let Spellings = [Keyword<"__ptr32">];
2435   let Documentation = [Undocumented];
2436 }
2437
2438 def Ptr64 : TypeAttr {
2439   let Spellings = [Keyword<"__ptr64">];
2440   let Documentation = [Undocumented];
2441 }
2442
2443 def SPtr : TypeAttr {
2444   let Spellings = [Keyword<"__sptr">];
2445   let Documentation = [Undocumented];
2446 }
2447
2448 def UPtr : TypeAttr {
2449   let Spellings = [Keyword<"__uptr">];
2450   let Documentation = [Undocumented];
2451 }
2452
2453 def MSInheritance : InheritableAttr {
2454   let LangOpts = [MicrosoftExt];
2455   let Args = [DefaultBoolArgument<"BestCase", 1>];
2456   let Spellings = [Keyword<"__single_inheritance">,
2457                    Keyword<"__multiple_inheritance">,
2458                    Keyword<"__virtual_inheritance">,
2459                    Keyword<"__unspecified_inheritance">];
2460   let AdditionalMembers = [{
2461   static bool hasVBPtrOffsetField(Spelling Inheritance) {
2462     return Inheritance == Keyword_unspecified_inheritance;
2463   }
2464
2465   // Only member pointers to functions need a this adjustment, since it can be
2466   // combined with the field offset for data pointers.
2467   static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) {
2468     return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance;
2469   }
2470
2471   static bool hasVBTableOffsetField(Spelling Inheritance) {
2472     return Inheritance >= Keyword_virtual_inheritance;
2473   }
2474
2475   static bool hasOnlyOneField(bool IsMemberFunction,
2476                               Spelling Inheritance) {
2477     if (IsMemberFunction)
2478       return Inheritance <= Keyword_single_inheritance;
2479     return Inheritance <= Keyword_multiple_inheritance;
2480   }
2481   }];
2482   let Documentation = [MSInheritanceDocs];
2483 }
2484
2485 def MSVtorDisp : InheritableAttr {
2486   // This attribute has no spellings as it is only ever created implicitly.
2487   let Spellings = [];
2488   let Args = [UnsignedArgument<"vdm">];
2489   let SemaHandler = 0;
2490
2491   let AdditionalMembers = [{
2492   enum Mode {
2493     Never,
2494     ForVBaseOverride,
2495     ForVFTable
2496   };
2497
2498   Mode getVtorDispMode() const { return Mode(vdm); }
2499   }];
2500   let Documentation = [Undocumented];
2501 }
2502
2503 def InitSeg : Attr {
2504   let Spellings = [Pragma<"", "init_seg">];
2505   let Args = [StringArgument<"Section">];
2506   let SemaHandler = 0;
2507   let Documentation = [InitSegDocs];
2508   let AdditionalMembers = [{
2509   void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2510     OS << '(' << getSection() << ')';
2511   }
2512   }];
2513 }
2514
2515 def LoopHint : Attr {
2516   /// #pragma clang loop <option> directive
2517   /// vectorize: vectorizes loop operations if State == Enable.
2518   /// vectorize_width: vectorize loop operations with width 'Value'.
2519   /// interleave: interleave multiple loop iterations if State == Enable.
2520   /// interleave_count: interleaves 'Value' loop interations.
2521   /// unroll: fully unroll loop if State == Enable.
2522   /// unroll_count: unrolls loop 'Value' times.
2523   /// distribute: attempt to distribute loop if State == Enable
2524
2525   /// #pragma unroll <argument> directive
2526   /// <no arg>: fully unrolls loop.
2527   /// boolean: fully unrolls loop if State == Enable.
2528   /// expression: unrolls loop 'Value' times.
2529
2530   let Spellings = [Pragma<"clang", "loop">, Pragma<"", "unroll">,
2531                    Pragma<"", "nounroll">];
2532
2533   /// State of the loop optimization specified by the spelling.
2534   let Args = [EnumArgument<"Option", "OptionType",
2535                           ["vectorize", "vectorize_width", "interleave", "interleave_count",
2536                            "unroll", "unroll_count", "distribute"],
2537                           ["Vectorize", "VectorizeWidth", "Interleave", "InterleaveCount",
2538                            "Unroll", "UnrollCount", "Distribute"]>,
2539               EnumArgument<"State", "LoopHintState",
2540                            ["enable", "disable", "numeric", "assume_safety", "full"],
2541                            ["Enable", "Disable", "Numeric", "AssumeSafety", "Full"]>,
2542               ExprArgument<"Value">];
2543
2544   let AdditionalMembers = [{
2545   static const char *getOptionName(int Option) {
2546     switch(Option) {
2547     case Vectorize: return "vectorize";
2548     case VectorizeWidth: return "vectorize_width";
2549     case Interleave: return "interleave";
2550     case InterleaveCount: return "interleave_count";
2551     case Unroll: return "unroll";
2552     case UnrollCount: return "unroll_count";
2553     case Distribute: return "distribute";
2554     }
2555     llvm_unreachable("Unhandled LoopHint option.");
2556   }
2557
2558   void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2559     unsigned SpellingIndex = getSpellingListIndex();
2560     // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
2561     // "nounroll" is already emitted as the pragma name.
2562     if (SpellingIndex == Pragma_nounroll)
2563       return;
2564     else if (SpellingIndex == Pragma_unroll) {
2565       OS << getValueString(Policy);
2566       return;
2567     }
2568
2569     assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2570     OS << getOptionName(option) << getValueString(Policy);
2571   }
2572
2573   // Return a string containing the loop hint argument including the
2574   // enclosing parentheses.
2575   std::string getValueString(const PrintingPolicy &Policy) const {
2576     std::string ValueName;
2577     llvm::raw_string_ostream OS(ValueName);
2578     OS << "(";
2579     if (state == Numeric)
2580       value->printPretty(OS, nullptr, Policy);
2581     else if (state == Enable)
2582       OS << "enable";
2583     else if (state == Full)
2584       OS << "full";
2585     else if (state == AssumeSafety)
2586       OS << "assume_safety";
2587     else
2588       OS << "disable";
2589     OS << ")";
2590     return OS.str();
2591   }
2592
2593   // Return a string suitable for identifying this attribute in diagnostics.
2594   std::string getDiagnosticName(const PrintingPolicy &Policy) const {
2595     unsigned SpellingIndex = getSpellingListIndex();
2596     if (SpellingIndex == Pragma_nounroll)
2597       return "#pragma nounroll";
2598     else if (SpellingIndex == Pragma_unroll)
2599       return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
2600
2601     assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2602     return getOptionName(option) + getValueString(Policy);
2603   }
2604   }];
2605
2606   let Documentation = [LoopHintDocs, UnrollHintDocs];
2607 }
2608
2609 def CapturedRecord : InheritableAttr {
2610   // This attribute has no spellings as it is only ever created implicitly.
2611   let Spellings = [];
2612   let SemaHandler = 0;
2613   let Documentation = [Undocumented];
2614 }
2615
2616 def OMPThreadPrivateDecl : InheritableAttr {
2617   // This attribute has no spellings as it is only ever created implicitly.
2618   let Spellings = [];
2619   let SemaHandler = 0;
2620   let Documentation = [Undocumented];
2621 }
2622
2623 def OMPCaptureNoInit : InheritableAttr {
2624   // This attribute has no spellings as it is only ever created implicitly.
2625   let Spellings = [];
2626   let SemaHandler = 0;
2627   let Documentation = [Undocumented];
2628 }
2629
2630 def OMPDeclareSimdDecl : Attr {
2631   let Spellings = [Pragma<"omp", "declare simd">];
2632   let Subjects = SubjectList<[Function]>;
2633   let SemaHandler = 0;
2634   let HasCustomParsing = 1;
2635   let Documentation = [OMPDeclareSimdDocs];
2636   let Args = [
2637     EnumArgument<"BranchState", "BranchStateTy",
2638                  [ "", "inbranch", "notinbranch" ],
2639                  [ "BS_Undefined", "BS_Inbranch", "BS_Notinbranch" ]>,
2640     ExprArgument<"Simdlen">, VariadicExprArgument<"Uniforms">,
2641     VariadicExprArgument<"Aligneds">, VariadicExprArgument<"Alignments">,
2642     VariadicExprArgument<"Linears">, VariadicUnsignedArgument<"Modifiers">,
2643     VariadicExprArgument<"Steps">
2644   ];
2645   let AdditionalMembers = [{
2646     void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
2647         const {
2648       if (getBranchState() != BS_Undefined)
2649         OS << ConvertBranchStateTyToStr(getBranchState()) << " ";
2650       if (auto *E = getSimdlen()) {
2651         OS << "simdlen(";
2652         E->printPretty(OS, nullptr, Policy);
2653         OS << ") ";
2654       }
2655       if (uniforms_size() > 0) {
2656         OS << "uniform";
2657         StringRef Sep = "(";
2658         for (auto *E : uniforms()) {
2659           OS << Sep;
2660           E->printPretty(OS, nullptr, Policy);
2661           Sep = ", ";
2662         }
2663         OS << ") ";
2664       }
2665       alignments_iterator NI = alignments_begin();
2666       for (auto *E : aligneds()) {
2667         OS << "aligned(";
2668         E->printPretty(OS, nullptr, Policy);
2669         if (*NI) {
2670           OS << ": ";
2671           (*NI)->printPretty(OS, nullptr, Policy);
2672         }
2673         OS << ") ";
2674         ++NI;
2675       }
2676       steps_iterator I = steps_begin();
2677       modifiers_iterator MI = modifiers_begin();
2678       for (auto *E : linears()) {
2679         OS << "linear(";
2680         if (*MI != OMPC_LINEAR_unknown)
2681           OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
2682         E->printPretty(OS, nullptr, Policy);
2683         if (*MI != OMPC_LINEAR_unknown)
2684           OS << ")";
2685         if (*I) {
2686           OS << ": ";
2687           (*I)->printPretty(OS, nullptr, Policy);
2688         }
2689         OS << ") ";
2690         ++I;
2691         ++MI;
2692       }
2693     }
2694   }];
2695 }
2696
2697 def OMPDeclareTargetDecl : Attr {
2698   let Spellings = [Pragma<"omp", "declare target">];
2699   let SemaHandler = 0;
2700   let Documentation = [OMPDeclareTargetDocs];
2701   let Args = [
2702     EnumArgument<"MapType", "MapTypeTy",
2703                  [ "to", "link" ],
2704                  [ "MT_To", "MT_Link" ]>
2705   ];
2706   let AdditionalMembers = [{
2707     void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2708       // Use fake syntax because it is for testing and debugging purpose only.
2709       if (getMapType() != MT_To)
2710         OS << ConvertMapTypeTyToStr(getMapType()) << " ";
2711     }
2712   }];
2713 }
2714
2715 def InternalLinkage : InheritableAttr {
2716   let Spellings = [GNU<"internal_linkage">, CXX11<"clang", "internal_linkage">];
2717   let Subjects = SubjectList<[Var, Function, CXXRecord]>;
2718   let Documentation = [InternalLinkageDocs];
2719 }