]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/Attr.td
Upgrade our copies of clang, llvm, lldb and compiler-rt to r312293 from
[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 PragmaClangBSSSection : InheritableAttr {
1687   // This attribute has no spellings as it is only ever created implicitly.
1688   let Spellings = [];
1689   let Args = [StringArgument<"Name">];
1690   let Subjects = SubjectList<[GlobalVar], ErrorDiag,
1691                              "ExpectedFunctionMethodOrGlobalVar">;
1692   let Documentation = [Undocumented];
1693 }
1694
1695 def PragmaClangDataSection : InheritableAttr {
1696   // This attribute has no spellings as it is only ever created implicitly.
1697   let Spellings = [];
1698   let Args = [StringArgument<"Name">];
1699   let Subjects = SubjectList<[GlobalVar], ErrorDiag,
1700                              "ExpectedFunctionMethodOrGlobalVar">;
1701   let Documentation = [Undocumented];
1702 }
1703
1704 def PragmaClangRodataSection : InheritableAttr {
1705   // This attribute has no spellings as it is only ever created implicitly.
1706   let Spellings = [];
1707   let Args = [StringArgument<"Name">];
1708   let Subjects = SubjectList<[GlobalVar], ErrorDiag,
1709                              "ExpectedFunctionMethodOrGlobalVar">;
1710   let Documentation = [Undocumented];
1711 }
1712
1713 def PragmaClangTextSection : InheritableAttr {
1714   // This attribute has no spellings as it is only ever created implicitly.
1715   let Spellings = [];
1716   let Args = [StringArgument<"Name">];
1717   let Subjects = SubjectList<[Function], ErrorDiag,
1718                              "ExpectedFunctionMethodOrGlobalVar">;
1719   let Documentation = [Undocumented];
1720 }
1721
1722 def Sentinel : InheritableAttr {
1723   let Spellings = [GCC<"sentinel">];
1724   let Args = [DefaultIntArgument<"Sentinel", 0>,
1725               DefaultIntArgument<"NullPos", 0>];
1726 //  let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>;
1727   let Documentation = [Undocumented];
1728 }
1729
1730 def StdCall : InheritableAttr {
1731   let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
1732 //  let Subjects = [Function, ObjCMethod];
1733   let Documentation = [StdCallDocs];
1734 }
1735
1736 def SwiftCall : InheritableAttr {
1737   let Spellings = [GCC<"swiftcall">];
1738 //  let Subjects = SubjectList<[Function]>;
1739   let Documentation = [SwiftCallDocs];
1740 }
1741
1742 def SwiftContext : ParameterABIAttr {
1743   let Spellings = [GCC<"swift_context">];
1744   let Documentation = [SwiftContextDocs];
1745 }
1746
1747 def SwiftErrorResult : ParameterABIAttr {
1748   let Spellings = [GCC<"swift_error_result">];
1749   let Documentation = [SwiftErrorResultDocs];
1750 }
1751
1752 def SwiftIndirectResult : ParameterABIAttr {
1753   let Spellings = [GCC<"swift_indirect_result">];
1754   let Documentation = [SwiftIndirectResultDocs];
1755 }
1756
1757 def Suppress : StmtAttr {
1758   let Spellings = [CXX11<"gsl", "suppress">];
1759   let Args = [VariadicStringArgument<"DiagnosticIdentifiers">];
1760   let Documentation = [SuppressDocs];
1761 }
1762
1763 def SysVABI : InheritableAttr {
1764   let Spellings = [GCC<"sysv_abi">];
1765 //  let Subjects = [Function, ObjCMethod];
1766   let Documentation = [Undocumented];
1767 }
1768
1769 def ThisCall : InheritableAttr {
1770   let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
1771                    Keyword<"_thiscall">];
1772 //  let Subjects = [Function, ObjCMethod];
1773   let Documentation = [ThisCallDocs];
1774 }
1775
1776 def VectorCall : InheritableAttr {
1777   let Spellings = [GNU<"vectorcall">, Keyword<"__vectorcall">,
1778                    Keyword<"_vectorcall">];
1779 //  let Subjects = [Function, ObjCMethod];
1780   let Documentation = [VectorCallDocs];
1781 }
1782
1783 def Pascal : InheritableAttr {
1784   let Spellings = [GNU<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
1785 //  let Subjects = [Function, ObjCMethod];
1786   let Documentation = [Undocumented];
1787 }
1788
1789 def PreserveMost : InheritableAttr {
1790   let Spellings = [GNU<"preserve_most">];
1791   let Documentation = [PreserveMostDocs];
1792 }
1793
1794 def PreserveAll : InheritableAttr {
1795   let Spellings = [GNU<"preserve_all">];
1796   let Documentation = [PreserveAllDocs];
1797 }
1798
1799 def Target : InheritableAttr {
1800   let Spellings = [GCC<"target">];
1801   let Args = [StringArgument<"featuresStr">];
1802   let Subjects = SubjectList<[Function], ErrorDiag>;
1803   let Documentation = [TargetDocs];
1804   let AdditionalMembers = [{
1805     struct ParsedTargetAttr {
1806       std::vector<std::string> Features;
1807       StringRef Architecture;
1808       bool DuplicateArchitecture = false;
1809     };
1810     ParsedTargetAttr parse() const {
1811       return parse(getFeaturesStr());
1812     }
1813     static ParsedTargetAttr parse(StringRef Features) {
1814       ParsedTargetAttr Ret;
1815       SmallVector<StringRef, 1> AttrFeatures;
1816       Features.split(AttrFeatures, ",");
1817
1818       // Grab the various features and prepend a "+" to turn on the feature to
1819       // the backend and add them to our existing set of features.
1820       for (auto &Feature : AttrFeatures) {
1821         // Go ahead and trim whitespace rather than either erroring or
1822         // accepting it weirdly.
1823         Feature = Feature.trim();
1824
1825         // We don't support cpu tuning this way currently.
1826         // TODO: Support the fpmath option. It will require checking
1827         // overall feature validity for the function with the rest of the
1828         // attributes on the function.
1829         if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
1830           continue;
1831
1832         // While we're here iterating check for a different target cpu.
1833         if (Feature.startswith("arch=")) {
1834           if (!Ret.Architecture.empty())
1835             Ret.DuplicateArchitecture = true;
1836           else
1837             Ret.Architecture = Feature.split("=").second.trim();
1838         } else if (Feature.startswith("no-"))
1839           Ret.Features.push_back("-" + Feature.split("-").second.str());
1840         else
1841           Ret.Features.push_back("+" + Feature.str());
1842       }
1843       return Ret;
1844     }
1845   }];
1846 }
1847
1848 def TransparentUnion : InheritableAttr {
1849   let Spellings = [GCC<"transparent_union">];
1850 //  let Subjects = SubjectList<[Record, TypedefName]>;
1851   let Documentation = [TransparentUnionDocs];
1852   let LangOpts = [COnly];
1853 }
1854
1855 def Unavailable : InheritableAttr {
1856   let Spellings = [GNU<"unavailable">];
1857   let Args = [StringArgument<"Message", 1>,
1858               EnumArgument<"ImplicitReason", "ImplicitReason",
1859                 ["", "", "", ""],
1860                 ["IR_None",
1861                  "IR_ARCForbiddenType",
1862                  "IR_ForbiddenWeak",
1863                  "IR_ARCForbiddenConversion",
1864                  "IR_ARCInitReturnsUnrelated",
1865                  "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
1866   let Documentation = [Undocumented];
1867 }
1868
1869 def DiagnoseIf : InheritableAttr {
1870   let Spellings = [GNU<"diagnose_if">];
1871   let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
1872   let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
1873               EnumArgument<"DiagnosticType",
1874                            "DiagnosticType",
1875                            ["error", "warning"],
1876                            ["DT_Error", "DT_Warning"]>,
1877               BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
1878               NamedArgument<"Parent", 0, /*fake*/ 1>];
1879   let DuplicatesAllowedWhileMerging = 1;
1880   let LateParsed = 1;
1881   let AdditionalMembers = [{
1882     bool isError() const { return diagnosticType == DT_Error; }
1883     bool isWarning() const { return diagnosticType == DT_Warning; }
1884   }];
1885   let TemplateDependent = 1;
1886   let Documentation = [DiagnoseIfDocs];
1887 }
1888
1889 def ArcWeakrefUnavailable : InheritableAttr {
1890   let Spellings = [GNU<"objc_arc_weak_reference_unavailable">];
1891   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1892   let Documentation = [Undocumented];
1893 }
1894
1895 def ObjCGC : TypeAttr {
1896   let Spellings = [GNU<"objc_gc">];
1897   let Args = [IdentifierArgument<"Kind">];
1898   let Documentation = [Undocumented];
1899 }
1900
1901 def ObjCOwnership : InheritableAttr {
1902   let Spellings = [GNU<"objc_ownership">];
1903   let Args = [IdentifierArgument<"Kind">];
1904   let ASTNode = 0;
1905   let Documentation = [Undocumented];
1906 }
1907
1908 def ObjCRequiresPropertyDefs : InheritableAttr {
1909   let Spellings = [GNU<"objc_requires_property_definitions">];
1910   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
1911   let Documentation = [Undocumented];
1912 }
1913
1914 def Unused : InheritableAttr {
1915   let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">];
1916   let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
1917                               Field, ObjCMethod, FunctionLike], WarnDiag,
1918                              "ExpectedForMaybeUnused">;
1919   let Documentation = [WarnMaybeUnusedDocs];
1920 }
1921
1922 def Used : InheritableAttr {
1923   let Spellings = [GCC<"used">];
1924   let Documentation = [Undocumented];
1925 }
1926
1927 def Uuid : InheritableAttr {
1928   let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
1929   let Args = [StringArgument<"Guid">];
1930   let Subjects = SubjectList<[Record, Enum], WarnDiag, "ExpectedEnumOrClass">;
1931   // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
1932   // CPlusPlus && (MicrosoftExt || Borland)
1933   let LangOpts = [MicrosoftExt, Borland];
1934   let Documentation = [Undocumented];
1935 }
1936
1937 def VectorSize : TypeAttr {
1938   let Spellings = [GCC<"vector_size">];
1939   let Args = [ExprArgument<"NumBytes">];
1940   let Documentation = [Undocumented];
1941 }
1942
1943 def VecTypeHint : InheritableAttr {
1944   let Spellings = [GNU<"vec_type_hint">];
1945   let Args = [TypeArgument<"TypeHint">];
1946   let Subjects = SubjectList<[Function], ErrorDiag>;
1947   let Documentation = [Undocumented];
1948 }
1949
1950 def Visibility : InheritableAttr {
1951   let Clone = 0;
1952   let Spellings = [GCC<"visibility">];
1953   let Args = [EnumArgument<"Visibility", "VisibilityType",
1954                            ["default", "hidden", "internal", "protected"],
1955                            ["Default", "Hidden", "Hidden", "Protected"]>];
1956   let MeaningfulToClassTemplateDefinition = 1;
1957   let Documentation = [Undocumented];
1958 }
1959
1960 def TypeVisibility : InheritableAttr {
1961   let Clone = 0;
1962   let Spellings = [GNU<"type_visibility">, CXX11<"clang", "type_visibility">];
1963   let Args = [EnumArgument<"Visibility", "VisibilityType",
1964                            ["default", "hidden", "internal", "protected"],
1965                            ["Default", "Hidden", "Hidden", "Protected"]>];
1966 //  let Subjects = [Tag, ObjCInterface, Namespace];
1967   let Documentation = [Undocumented];
1968 }
1969
1970 def VecReturn : InheritableAttr {
1971   let Spellings = [GNU<"vecreturn">];
1972   let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
1973   let Documentation = [Undocumented];
1974 }
1975
1976 def WarnUnused : InheritableAttr {
1977   let Spellings = [GNU<"warn_unused">];
1978   let Subjects = SubjectList<[Record]>;
1979   let Documentation = [Undocumented];
1980 }
1981
1982 def WarnUnusedResult : InheritableAttr {
1983   let Spellings = [CXX11<"", "nodiscard", 201603>,
1984                    CXX11<"clang", "warn_unused_result">,
1985                    GCC<"warn_unused_result">];
1986   let Subjects = SubjectList<[ObjCMethod, Enum, CXXRecord, FunctionLike],
1987                              WarnDiag, "ExpectedFunctionMethodEnumOrClass">;
1988   let Documentation = [WarnUnusedResultsDocs];
1989 }
1990
1991 def Weak : InheritableAttr {
1992   let Spellings = [GCC<"weak">];
1993   let Subjects = SubjectList<[Var, Function, CXXRecord]>;
1994   let Documentation = [Undocumented];
1995 }
1996
1997 def WeakImport : InheritableAttr {
1998   let Spellings = [GNU<"weak_import">];
1999   let Documentation = [Undocumented];
2000 }
2001
2002 def WeakRef : InheritableAttr {
2003   let Spellings = [GCC<"weakref">];
2004   // A WeakRef that has an argument is treated as being an AliasAttr
2005   let Args = [StringArgument<"Aliasee", 1>];
2006   let Subjects = SubjectList<[Var, Function], ErrorDiag>;
2007   let Documentation = [Undocumented];
2008 }
2009
2010 def LTOVisibilityPublic : InheritableAttr {
2011   let Spellings = [CXX11<"clang", "lto_visibility_public">];
2012   let Subjects = SubjectList<[Record]>;
2013   let Documentation = [LTOVisibilityDocs];
2014 }
2015
2016 def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
2017   // NOTE: If you add any additional spellings, ARMInterrupt's,
2018   // MSP430Interrupt's and MipsInterrupt's spellings must match.
2019   let Spellings = [GNU<"interrupt">];
2020   let Subjects = SubjectList<[HasFunctionProto]>;
2021   let ParseKind = "Interrupt";
2022   let HasCustomParsing = 1;
2023   let Documentation = [AnyX86InterruptDocs];
2024 }
2025
2026 def AnyX86NoCallerSavedRegisters : InheritableAttr,
2027                                    TargetSpecificAttr<TargetAnyX86> {
2028   let Spellings = [GCC<"no_caller_saved_registers">];
2029   let Documentation = [AnyX86NoCallerSavedRegistersDocs];
2030 }
2031
2032 def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetX86> {
2033   let Spellings = [GNU<"force_align_arg_pointer">];
2034   // Technically, this appertains to a FunctionDecl, but the target-specific
2035   // code silently allows anything function-like (such as typedefs or function
2036   // pointers), but does not apply the attribute to them.
2037   let Documentation = [Undocumented];
2038 }
2039
2040 def NoSanitize : InheritableAttr {
2041   let Spellings = [GNU<"no_sanitize">, CXX11<"clang", "no_sanitize">];
2042   let Args = [VariadicStringArgument<"Sanitizers">];
2043   let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag,
2044     "ExpectedFunctionMethodOrGlobalVar">;
2045   let Documentation = [NoSanitizeDocs];
2046   let AdditionalMembers = [{
2047     SanitizerMask getMask() const {
2048       SanitizerMask Mask = 0;
2049       for (auto SanitizerName : sanitizers()) {
2050         SanitizerMask ParsedMask =
2051             parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
2052         Mask |= expandSanitizerGroups(ParsedMask);
2053       }
2054       return Mask;
2055     }
2056   }];
2057 }
2058
2059 // Attributes to disable a specific sanitizer. No new sanitizers should be added
2060 // to this list; the no_sanitize attribute should be extended instead.
2061 def NoSanitizeSpecific : InheritableAttr {
2062   let Spellings = [GCC<"no_address_safety_analysis">,
2063                    GCC<"no_sanitize_address">,
2064                    GCC<"no_sanitize_thread">,
2065                    GNU<"no_sanitize_memory">];
2066   let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
2067         "ExpectedFunctionOrGlobalVar">;
2068   let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
2069                        NoSanitizeMemoryDocs];
2070   let ASTNode = 0;
2071 }
2072
2073 // C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
2074
2075 def GuardedVar : InheritableAttr {
2076   let Spellings = [GNU<"guarded_var">];
2077   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2078                              "ExpectedFieldOrGlobalVar">;
2079   let Documentation = [Undocumented];
2080 }
2081
2082 def PtGuardedVar : InheritableAttr {
2083   let Spellings = [GNU<"pt_guarded_var">];
2084   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2085                              "ExpectedFieldOrGlobalVar">;
2086   let Documentation = [Undocumented];
2087 }
2088
2089 def Lockable : InheritableAttr {
2090   let Spellings = [GNU<"lockable">];
2091   let Subjects = SubjectList<[Record]>;
2092   let Documentation = [Undocumented];
2093   let ASTNode = 0;  // Replaced by Capability
2094 }
2095
2096 def ScopedLockable : InheritableAttr {
2097   let Spellings = [GNU<"scoped_lockable">];
2098   let Subjects = SubjectList<[Record]>;
2099   let Documentation = [Undocumented];
2100 }
2101
2102 def Capability : InheritableAttr {
2103   let Spellings = [GNU<"capability">, CXX11<"clang", "capability">,
2104                    GNU<"shared_capability">,
2105                    CXX11<"clang", "shared_capability">];
2106   let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
2107                              "ExpectedStructOrUnionOrTypedef">;
2108   let Args = [StringArgument<"Name">];
2109   let Accessors = [Accessor<"isShared",
2110                     [GNU<"shared_capability">,
2111                      CXX11<"clang","shared_capability">]>];
2112   let Documentation = [Undocumented];
2113   let AdditionalMembers = [{
2114     bool isMutex() const { return getName().equals_lower("mutex"); }
2115     bool isRole() const { return getName().equals_lower("role"); }
2116   }];
2117 }
2118
2119 def AssertCapability : InheritableAttr {
2120   let Spellings = [GNU<"assert_capability">,
2121                    CXX11<"clang", "assert_capability">,
2122                    GNU<"assert_shared_capability">,
2123                    CXX11<"clang", "assert_shared_capability">];
2124   let Subjects = SubjectList<[Function]>;
2125   let LateParsed = 1;
2126   let TemplateDependent = 1;
2127   let ParseArgumentsAsUnevaluated = 1;
2128   let DuplicatesAllowedWhileMerging = 1;
2129   let Args = [ExprArgument<"Expr">];
2130   let Accessors = [Accessor<"isShared",
2131                     [GNU<"assert_shared_capability">,
2132                      CXX11<"clang", "assert_shared_capability">]>];
2133   let Documentation = [AssertCapabilityDocs];
2134 }
2135
2136 def AcquireCapability : InheritableAttr {
2137   let Spellings = [GNU<"acquire_capability">,
2138                    CXX11<"clang", "acquire_capability">,
2139                    GNU<"acquire_shared_capability">,
2140                    CXX11<"clang", "acquire_shared_capability">,
2141                    GNU<"exclusive_lock_function">,
2142                    GNU<"shared_lock_function">];
2143   let Subjects = SubjectList<[Function]>;
2144   let LateParsed = 1;
2145   let TemplateDependent = 1;
2146   let ParseArgumentsAsUnevaluated = 1;
2147   let DuplicatesAllowedWhileMerging = 1;
2148   let Args = [VariadicExprArgument<"Args">];
2149   let Accessors = [Accessor<"isShared",
2150                     [GNU<"acquire_shared_capability">,
2151                      CXX11<"clang", "acquire_shared_capability">,
2152                      GNU<"shared_lock_function">]>];
2153   let Documentation = [AcquireCapabilityDocs];
2154 }
2155
2156 def TryAcquireCapability : InheritableAttr {
2157   let Spellings = [GNU<"try_acquire_capability">,
2158                    CXX11<"clang", "try_acquire_capability">,
2159                    GNU<"try_acquire_shared_capability">,
2160                    CXX11<"clang", "try_acquire_shared_capability">];
2161   let Subjects = SubjectList<[Function],
2162                              ErrorDiag>;
2163   let LateParsed = 1;
2164   let TemplateDependent = 1;
2165   let ParseArgumentsAsUnevaluated = 1;
2166   let DuplicatesAllowedWhileMerging = 1;
2167   let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2168   let Accessors = [Accessor<"isShared",
2169                     [GNU<"try_acquire_shared_capability">,
2170                      CXX11<"clang", "try_acquire_shared_capability">]>];
2171   let Documentation = [TryAcquireCapabilityDocs];
2172 }
2173
2174 def ReleaseCapability : InheritableAttr {
2175   let Spellings = [GNU<"release_capability">,
2176                    CXX11<"clang", "release_capability">,
2177                    GNU<"release_shared_capability">,
2178                    CXX11<"clang", "release_shared_capability">,
2179                    GNU<"release_generic_capability">,
2180                    CXX11<"clang", "release_generic_capability">,
2181                    GNU<"unlock_function">];
2182   let Subjects = SubjectList<[Function]>;
2183   let LateParsed = 1;
2184   let TemplateDependent = 1;
2185   let ParseArgumentsAsUnevaluated = 1;
2186   let DuplicatesAllowedWhileMerging = 1;
2187   let Args = [VariadicExprArgument<"Args">];
2188   let Accessors = [Accessor<"isShared",
2189                     [GNU<"release_shared_capability">,
2190                      CXX11<"clang", "release_shared_capability">]>,
2191                    Accessor<"isGeneric",
2192                      [GNU<"release_generic_capability">,
2193                       CXX11<"clang", "release_generic_capability">,
2194                       GNU<"unlock_function">]>];
2195   let Documentation = [ReleaseCapabilityDocs];
2196 }
2197
2198 def RequiresCapability : InheritableAttr {
2199   let Spellings = [GNU<"requires_capability">,
2200                    CXX11<"clang", "requires_capability">,
2201                    GNU<"exclusive_locks_required">,
2202                    GNU<"requires_shared_capability">,
2203                    CXX11<"clang", "requires_shared_capability">,
2204                    GNU<"shared_locks_required">];
2205   let Args = [VariadicExprArgument<"Args">];
2206   let LateParsed = 1;
2207   let TemplateDependent = 1;
2208   let ParseArgumentsAsUnevaluated = 1;
2209   let DuplicatesAllowedWhileMerging = 1;
2210   let Subjects = SubjectList<[Function]>;
2211   let Accessors = [Accessor<"isShared", [GNU<"requires_shared_capability">,
2212                                          GNU<"shared_locks_required">,
2213                                 CXX11<"clang","requires_shared_capability">]>];
2214   let Documentation = [Undocumented];
2215 }
2216
2217 def NoThreadSafetyAnalysis : InheritableAttr {
2218   let Spellings = [GNU<"no_thread_safety_analysis">];
2219   let Subjects = SubjectList<[Function]>;
2220   let Documentation = [Undocumented];
2221 }
2222
2223 def GuardedBy : InheritableAttr {
2224   let Spellings = [GNU<"guarded_by">];
2225   let Args = [ExprArgument<"Arg">];
2226   let LateParsed = 1;
2227   let TemplateDependent = 1;
2228   let ParseArgumentsAsUnevaluated = 1;
2229   let DuplicatesAllowedWhileMerging = 1;
2230   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2231                              "ExpectedFieldOrGlobalVar">;
2232   let Documentation = [Undocumented];
2233 }
2234
2235 def PtGuardedBy : InheritableAttr {
2236   let Spellings = [GNU<"pt_guarded_by">];
2237   let Args = [ExprArgument<"Arg">];
2238   let LateParsed = 1;
2239   let TemplateDependent = 1;
2240   let ParseArgumentsAsUnevaluated = 1;
2241   let DuplicatesAllowedWhileMerging = 1;
2242   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2243                              "ExpectedFieldOrGlobalVar">;
2244   let Documentation = [Undocumented];
2245 }
2246
2247 def AcquiredAfter : InheritableAttr {
2248   let Spellings = [GNU<"acquired_after">];
2249   let Args = [VariadicExprArgument<"Args">];
2250   let LateParsed = 1;
2251   let TemplateDependent = 1;
2252   let ParseArgumentsAsUnevaluated = 1;
2253   let DuplicatesAllowedWhileMerging = 1;
2254   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2255                              "ExpectedFieldOrGlobalVar">;
2256   let Documentation = [Undocumented];
2257 }
2258
2259 def AcquiredBefore : InheritableAttr {
2260   let Spellings = [GNU<"acquired_before">];
2261   let Args = [VariadicExprArgument<"Args">];
2262   let LateParsed = 1;
2263   let TemplateDependent = 1;
2264   let ParseArgumentsAsUnevaluated = 1;
2265   let DuplicatesAllowedWhileMerging = 1;
2266   let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
2267                              "ExpectedFieldOrGlobalVar">;
2268   let Documentation = [Undocumented];
2269 }
2270
2271 def AssertExclusiveLock : InheritableAttr {
2272   let Spellings = [GNU<"assert_exclusive_lock">];
2273   let Args = [VariadicExprArgument<"Args">];
2274   let LateParsed = 1;
2275   let TemplateDependent = 1;
2276   let ParseArgumentsAsUnevaluated = 1;
2277   let DuplicatesAllowedWhileMerging = 1;
2278   let Subjects = SubjectList<[Function]>;
2279   let Documentation = [Undocumented];
2280 }
2281
2282 def AssertSharedLock : InheritableAttr {
2283   let Spellings = [GNU<"assert_shared_lock">];
2284   let Args = [VariadicExprArgument<"Args">];
2285   let LateParsed = 1;
2286   let TemplateDependent = 1;
2287   let ParseArgumentsAsUnevaluated = 1;
2288   let DuplicatesAllowedWhileMerging = 1;
2289   let Subjects = SubjectList<[Function]>;
2290   let Documentation = [Undocumented];
2291 }
2292
2293 // The first argument is an integer or boolean value specifying the return value
2294 // of a successful lock acquisition.
2295 def ExclusiveTrylockFunction : InheritableAttr {
2296   let Spellings = [GNU<"exclusive_trylock_function">];
2297   let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2298   let LateParsed = 1;
2299   let TemplateDependent = 1;
2300   let ParseArgumentsAsUnevaluated = 1;
2301   let DuplicatesAllowedWhileMerging = 1;
2302   let Subjects = SubjectList<[Function]>;
2303   let Documentation = [Undocumented];
2304 }
2305
2306 // The first argument is an integer or boolean value specifying the return value
2307 // of a successful lock acquisition.
2308 def SharedTrylockFunction : InheritableAttr {
2309   let Spellings = [GNU<"shared_trylock_function">];
2310   let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
2311   let LateParsed = 1;
2312   let TemplateDependent = 1;
2313   let ParseArgumentsAsUnevaluated = 1;
2314   let DuplicatesAllowedWhileMerging = 1;
2315   let Subjects = SubjectList<[Function]>;
2316   let Documentation = [Undocumented];
2317 }
2318
2319 def LockReturned : InheritableAttr {
2320   let Spellings = [GNU<"lock_returned">];
2321   let Args = [ExprArgument<"Arg">];
2322   let LateParsed = 1;
2323   let TemplateDependent = 1;
2324   let ParseArgumentsAsUnevaluated = 1;
2325   let Subjects = SubjectList<[Function]>;
2326   let Documentation = [Undocumented];
2327 }
2328
2329 def LocksExcluded : InheritableAttr {
2330   let Spellings = [GNU<"locks_excluded">];
2331   let Args = [VariadicExprArgument<"Args">];
2332   let LateParsed = 1;
2333   let TemplateDependent = 1;
2334   let ParseArgumentsAsUnevaluated = 1;
2335   let DuplicatesAllowedWhileMerging = 1;
2336   let Subjects = SubjectList<[Function]>;
2337   let Documentation = [Undocumented];
2338 }
2339
2340 // C/C++ consumed attributes.
2341
2342 def Consumable : InheritableAttr {
2343   let Spellings = [GNU<"consumable">];
2344   let Subjects = SubjectList<[CXXRecord]>;
2345   let Args = [EnumArgument<"DefaultState", "ConsumedState",
2346                            ["unknown", "consumed", "unconsumed"],
2347                            ["Unknown", "Consumed", "Unconsumed"]>];
2348   let Documentation = [ConsumableDocs];
2349 }
2350
2351 def ConsumableAutoCast : InheritableAttr {
2352   let Spellings = [GNU<"consumable_auto_cast_state">];
2353   let Subjects = SubjectList<[CXXRecord]>;
2354   let Documentation = [Undocumented];
2355 }
2356
2357 def ConsumableSetOnRead : InheritableAttr {
2358   let Spellings = [GNU<"consumable_set_state_on_read">];
2359   let Subjects = SubjectList<[CXXRecord]>;
2360   let Documentation = [Undocumented];
2361 }
2362
2363 def CallableWhen : InheritableAttr {
2364   let Spellings = [GNU<"callable_when">];
2365   let Subjects = SubjectList<[CXXMethod]>;
2366   let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
2367                                    ["unknown", "consumed", "unconsumed"],
2368                                    ["Unknown", "Consumed", "Unconsumed"]>];
2369   let Documentation = [CallableWhenDocs];
2370 }
2371
2372 def ParamTypestate : InheritableAttr {
2373   let Spellings = [GNU<"param_typestate">];
2374   let Subjects = SubjectList<[ParmVar]>;
2375   let Args = [EnumArgument<"ParamState", "ConsumedState",
2376                            ["unknown", "consumed", "unconsumed"],
2377                            ["Unknown", "Consumed", "Unconsumed"]>];
2378   let Documentation = [ParamTypestateDocs];
2379 }
2380
2381 def ReturnTypestate : InheritableAttr {
2382   let Spellings = [GNU<"return_typestate">];
2383   let Subjects = SubjectList<[Function, ParmVar]>;
2384   let Args = [EnumArgument<"State", "ConsumedState",
2385                            ["unknown", "consumed", "unconsumed"],
2386                            ["Unknown", "Consumed", "Unconsumed"]>];
2387   let Documentation = [ReturnTypestateDocs];
2388 }
2389
2390 def SetTypestate : InheritableAttr {
2391   let Spellings = [GNU<"set_typestate">];
2392   let Subjects = SubjectList<[CXXMethod]>;
2393   let Args = [EnumArgument<"NewState", "ConsumedState",
2394                            ["unknown", "consumed", "unconsumed"],
2395                            ["Unknown", "Consumed", "Unconsumed"]>];
2396   let Documentation = [SetTypestateDocs];
2397 }
2398
2399 def TestTypestate : InheritableAttr {
2400   let Spellings = [GNU<"test_typestate">];
2401   let Subjects = SubjectList<[CXXMethod]>;
2402   let Args = [EnumArgument<"TestState", "ConsumedState",
2403                            ["consumed", "unconsumed"],
2404                            ["Consumed", "Unconsumed"]>];
2405   let Documentation = [TestTypestateDocs];
2406 }
2407
2408 // Type safety attributes for `void *' pointers and type tags.
2409
2410 def ArgumentWithTypeTag : InheritableAttr {
2411   let Spellings = [GNU<"argument_with_type_tag">,
2412                    GNU<"pointer_with_type_tag">];
2413   let Args = [IdentifierArgument<"ArgumentKind">,
2414               UnsignedArgument<"ArgumentIdx">,
2415               UnsignedArgument<"TypeTagIdx">,
2416               BoolArgument<"IsPointer">];
2417   let HasCustomParsing = 1;
2418   let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
2419 }
2420
2421 def TypeTagForDatatype : InheritableAttr {
2422   let Spellings = [GNU<"type_tag_for_datatype">];
2423   let Args = [IdentifierArgument<"ArgumentKind">,
2424               TypeArgument<"MatchingCType">,
2425               BoolArgument<"LayoutCompatible">,
2426               BoolArgument<"MustBeNull">];
2427 //  let Subjects = SubjectList<[Var], ErrorDiag>;
2428   let HasCustomParsing = 1;
2429   let Documentation = [TypeTagForDatatypeDocs];
2430 }
2431
2432 // Microsoft-related attributes
2433
2434 def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
2435   let Spellings = [Declspec<"novtable">];
2436   let Subjects = SubjectList<[CXXRecord]>;
2437   let Documentation = [MSNoVTableDocs];
2438 }
2439
2440 def : IgnoredAttr {
2441   let Spellings = [Declspec<"property">];
2442 }
2443
2444 def MSStruct : InheritableAttr {
2445   let Spellings = [GCC<"ms_struct">];
2446   let Subjects = SubjectList<[Record]>;
2447   let Documentation = [Undocumented];
2448 }
2449
2450 def DLLExport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2451   let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
2452   let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2453   let Documentation = [DLLExportDocs];
2454 }
2455
2456 def DLLImport : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2457   let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
2458   let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
2459   let Documentation = [DLLImportDocs];
2460 }
2461
2462 def SelectAny : InheritableAttr, TargetSpecificAttr<TargetWindows> {
2463   let Spellings = [Declspec<"selectany">, GCC<"selectany">];
2464   let Documentation = [Undocumented];
2465 }
2466
2467 def Thread : Attr {
2468   let Spellings = [Declspec<"thread">];
2469   let LangOpts = [MicrosoftExt];
2470   let Documentation = [ThreadDocs];
2471   let Subjects = SubjectList<[Var]>;
2472 }
2473
2474 def Win64 : IgnoredAttr {
2475   let Spellings = [Keyword<"__w64">];
2476   let LangOpts = [MicrosoftExt];
2477 }
2478
2479 def Ptr32 : TypeAttr {
2480   let Spellings = [Keyword<"__ptr32">];
2481   let Documentation = [Undocumented];
2482 }
2483
2484 def Ptr64 : TypeAttr {
2485   let Spellings = [Keyword<"__ptr64">];
2486   let Documentation = [Undocumented];
2487 }
2488
2489 def SPtr : TypeAttr {
2490   let Spellings = [Keyword<"__sptr">];
2491   let Documentation = [Undocumented];
2492 }
2493
2494 def UPtr : TypeAttr {
2495   let Spellings = [Keyword<"__uptr">];
2496   let Documentation = [Undocumented];
2497 }
2498
2499 def MSInheritance : InheritableAttr {
2500   let LangOpts = [MicrosoftExt];
2501   let Args = [DefaultBoolArgument<"BestCase", 1>];
2502   let Spellings = [Keyword<"__single_inheritance">,
2503                    Keyword<"__multiple_inheritance">,
2504                    Keyword<"__virtual_inheritance">,
2505                    Keyword<"__unspecified_inheritance">];
2506   let AdditionalMembers = [{
2507   static bool hasVBPtrOffsetField(Spelling Inheritance) {
2508     return Inheritance == Keyword_unspecified_inheritance;
2509   }
2510
2511   // Only member pointers to functions need a this adjustment, since it can be
2512   // combined with the field offset for data pointers.
2513   static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) {
2514     return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance;
2515   }
2516
2517   static bool hasVBTableOffsetField(Spelling Inheritance) {
2518     return Inheritance >= Keyword_virtual_inheritance;
2519   }
2520
2521   static bool hasOnlyOneField(bool IsMemberFunction,
2522                               Spelling Inheritance) {
2523     if (IsMemberFunction)
2524       return Inheritance <= Keyword_single_inheritance;
2525     return Inheritance <= Keyword_multiple_inheritance;
2526   }
2527   }];
2528   let Documentation = [MSInheritanceDocs];
2529 }
2530
2531 def MSVtorDisp : InheritableAttr {
2532   // This attribute has no spellings as it is only ever created implicitly.
2533   let Spellings = [];
2534   let Args = [UnsignedArgument<"vdm">];
2535   let SemaHandler = 0;
2536
2537   let AdditionalMembers = [{
2538   enum Mode {
2539     Never,
2540     ForVBaseOverride,
2541     ForVFTable
2542   };
2543
2544   Mode getVtorDispMode() const { return Mode(vdm); }
2545   }];
2546   let Documentation = [Undocumented];
2547 }
2548
2549 def InitSeg : Attr {
2550   let Spellings = [Pragma<"", "init_seg">];
2551   let Args = [StringArgument<"Section">];
2552   let SemaHandler = 0;
2553   let Documentation = [InitSegDocs];
2554   let AdditionalMembers = [{
2555   void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2556     OS << '(' << getSection() << ')';
2557   }
2558   }];
2559 }
2560
2561 def LoopHint : Attr {
2562   /// #pragma clang loop <option> directive
2563   /// vectorize: vectorizes loop operations if State == Enable.
2564   /// vectorize_width: vectorize loop operations with width 'Value'.
2565   /// interleave: interleave multiple loop iterations if State == Enable.
2566   /// interleave_count: interleaves 'Value' loop interations.
2567   /// unroll: fully unroll loop if State == Enable.
2568   /// unroll_count: unrolls loop 'Value' times.
2569   /// distribute: attempt to distribute loop if State == Enable
2570
2571   /// #pragma unroll <argument> directive
2572   /// <no arg>: fully unrolls loop.
2573   /// boolean: fully unrolls loop if State == Enable.
2574   /// expression: unrolls loop 'Value' times.
2575
2576   let Spellings = [Pragma<"clang", "loop">, Pragma<"", "unroll">,
2577                    Pragma<"", "nounroll">];
2578
2579   /// State of the loop optimization specified by the spelling.
2580   let Args = [EnumArgument<"Option", "OptionType",
2581                           ["vectorize", "vectorize_width", "interleave", "interleave_count",
2582                            "unroll", "unroll_count", "distribute"],
2583                           ["Vectorize", "VectorizeWidth", "Interleave", "InterleaveCount",
2584                            "Unroll", "UnrollCount", "Distribute"]>,
2585               EnumArgument<"State", "LoopHintState",
2586                            ["enable", "disable", "numeric", "assume_safety", "full"],
2587                            ["Enable", "Disable", "Numeric", "AssumeSafety", "Full"]>,
2588               ExprArgument<"Value">];
2589
2590   let AdditionalMembers = [{
2591   static const char *getOptionName(int Option) {
2592     switch(Option) {
2593     case Vectorize: return "vectorize";
2594     case VectorizeWidth: return "vectorize_width";
2595     case Interleave: return "interleave";
2596     case InterleaveCount: return "interleave_count";
2597     case Unroll: return "unroll";
2598     case UnrollCount: return "unroll_count";
2599     case Distribute: return "distribute";
2600     }
2601     llvm_unreachable("Unhandled LoopHint option.");
2602   }
2603
2604   void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2605     unsigned SpellingIndex = getSpellingListIndex();
2606     // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
2607     // "nounroll" is already emitted as the pragma name.
2608     if (SpellingIndex == Pragma_nounroll)
2609       return;
2610     else if (SpellingIndex == Pragma_unroll) {
2611       OS << getValueString(Policy);
2612       return;
2613     }
2614
2615     assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2616     OS << getOptionName(option) << getValueString(Policy);
2617   }
2618
2619   // Return a string containing the loop hint argument including the
2620   // enclosing parentheses.
2621   std::string getValueString(const PrintingPolicy &Policy) const {
2622     std::string ValueName;
2623     llvm::raw_string_ostream OS(ValueName);
2624     OS << "(";
2625     if (state == Numeric)
2626       value->printPretty(OS, nullptr, Policy);
2627     else if (state == Enable)
2628       OS << "enable";
2629     else if (state == Full)
2630       OS << "full";
2631     else if (state == AssumeSafety)
2632       OS << "assume_safety";
2633     else
2634       OS << "disable";
2635     OS << ")";
2636     return OS.str();
2637   }
2638
2639   // Return a string suitable for identifying this attribute in diagnostics.
2640   std::string getDiagnosticName(const PrintingPolicy &Policy) const {
2641     unsigned SpellingIndex = getSpellingListIndex();
2642     if (SpellingIndex == Pragma_nounroll)
2643       return "#pragma nounroll";
2644     else if (SpellingIndex == Pragma_unroll)
2645       return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
2646
2647     assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
2648     return getOptionName(option) + getValueString(Policy);
2649   }
2650   }];
2651
2652   let Documentation = [LoopHintDocs, UnrollHintDocs];
2653 }
2654
2655 def CapturedRecord : InheritableAttr {
2656   // This attribute has no spellings as it is only ever created implicitly.
2657   let Spellings = [];
2658   let SemaHandler = 0;
2659   let Documentation = [Undocumented];
2660 }
2661
2662 def OMPThreadPrivateDecl : InheritableAttr {
2663   // This attribute has no spellings as it is only ever created implicitly.
2664   let Spellings = [];
2665   let SemaHandler = 0;
2666   let Documentation = [Undocumented];
2667 }
2668
2669 def OMPCaptureNoInit : InheritableAttr {
2670   // This attribute has no spellings as it is only ever created implicitly.
2671   let Spellings = [];
2672   let SemaHandler = 0;
2673   let Documentation = [Undocumented];
2674 }
2675
2676 def OMPDeclareSimdDecl : Attr {
2677   let Spellings = [Pragma<"omp", "declare simd">];
2678   let Subjects = SubjectList<[Function]>;
2679   let SemaHandler = 0;
2680   let HasCustomParsing = 1;
2681   let Documentation = [OMPDeclareSimdDocs];
2682   let Args = [
2683     EnumArgument<"BranchState", "BranchStateTy",
2684                  [ "", "inbranch", "notinbranch" ],
2685                  [ "BS_Undefined", "BS_Inbranch", "BS_Notinbranch" ]>,
2686     ExprArgument<"Simdlen">, VariadicExprArgument<"Uniforms">,
2687     VariadicExprArgument<"Aligneds">, VariadicExprArgument<"Alignments">,
2688     VariadicExprArgument<"Linears">, VariadicUnsignedArgument<"Modifiers">,
2689     VariadicExprArgument<"Steps">
2690   ];
2691   let AdditionalMembers = [{
2692     void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
2693         const {
2694       if (getBranchState() != BS_Undefined)
2695         OS << ConvertBranchStateTyToStr(getBranchState()) << " ";
2696       if (auto *E = getSimdlen()) {
2697         OS << "simdlen(";
2698         E->printPretty(OS, nullptr, Policy);
2699         OS << ") ";
2700       }
2701       if (uniforms_size() > 0) {
2702         OS << "uniform";
2703         StringRef Sep = "(";
2704         for (auto *E : uniforms()) {
2705           OS << Sep;
2706           E->printPretty(OS, nullptr, Policy);
2707           Sep = ", ";
2708         }
2709         OS << ") ";
2710       }
2711       alignments_iterator NI = alignments_begin();
2712       for (auto *E : aligneds()) {
2713         OS << "aligned(";
2714         E->printPretty(OS, nullptr, Policy);
2715         if (*NI) {
2716           OS << ": ";
2717           (*NI)->printPretty(OS, nullptr, Policy);
2718         }
2719         OS << ") ";
2720         ++NI;
2721       }
2722       steps_iterator I = steps_begin();
2723       modifiers_iterator MI = modifiers_begin();
2724       for (auto *E : linears()) {
2725         OS << "linear(";
2726         if (*MI != OMPC_LINEAR_unknown)
2727           OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
2728         E->printPretty(OS, nullptr, Policy);
2729         if (*MI != OMPC_LINEAR_unknown)
2730           OS << ")";
2731         if (*I) {
2732           OS << ": ";
2733           (*I)->printPretty(OS, nullptr, Policy);
2734         }
2735         OS << ") ";
2736         ++I;
2737         ++MI;
2738       }
2739     }
2740   }];
2741 }
2742
2743 def OMPDeclareTargetDecl : Attr {
2744   let Spellings = [Pragma<"omp", "declare target">];
2745   let SemaHandler = 0;
2746   let Documentation = [OMPDeclareTargetDocs];
2747   let Args = [
2748     EnumArgument<"MapType", "MapTypeTy",
2749                  [ "to", "link" ],
2750                  [ "MT_To", "MT_Link" ]>
2751   ];
2752   let AdditionalMembers = [{
2753     void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
2754       // Use fake syntax because it is for testing and debugging purpose only.
2755       if (getMapType() != MT_To)
2756         OS << ConvertMapTypeTyToStr(getMapType()) << " ";
2757     }
2758   }];
2759 }
2760
2761 def InternalLinkage : InheritableAttr {
2762   let Spellings = [GNU<"internal_linkage">, CXX11<"clang", "internal_linkage">];
2763   let Subjects = SubjectList<[Var, Function, CXXRecord]>;
2764   let Documentation = [InternalLinkageDocs];
2765 }