1//==--- Attr.td - attribute definitions -----------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// The documentation is organized by category. Attributes can have category-
10// specific documentation that is collated within the larger document.
11class DocumentationCategory<string name> {
12  string Name = name;
13  code Content = [{}];
14}
15def DocCatFunction : DocumentationCategory<"Function Attributes">;
16def DocCatVariable : DocumentationCategory<"Variable Attributes">;
17def DocCatField : DocumentationCategory<"Field Attributes">;
18def DocCatType : DocumentationCategory<"Type Attributes">;
19def DocCatStmt : DocumentationCategory<"Statement Attributes">;
20def DocCatDecl : DocumentationCategory<"Declaration Attributes">;
21
22// This category is for attributes which have not yet been properly documented,
23// but should be.
24def DocCatUndocumented : DocumentationCategory<"Undocumented"> {
25  let Content = [{
26This section lists attributes which are recognized by Clang, but which are
27currently missing documentation.
28}];
29}
30
31// Attributes listed under the InternalOnly category do not generate any entry
32// in the documentation.  This category should be used only when we _want_
33// to not document the attribute, e.g. if the attribute has no spellings.
34def DocCatInternalOnly : DocumentationCategory<"InternalOnly">;
35
36class DocDeprecated<string replacement = ""> {
37  // If the Replacement field is empty, no replacement will be listed with the
38  // documentation. Otherwise, the documentation will specify the attribute has
39  // been superseded by this replacement.
40  string Replacement = replacement;
41}
42
43// Specifies the documentation to be associated with the given category.
44class Documentation {
45  DocumentationCategory Category;
46  code Content;
47
48  // If the heading is empty, one may be picked automatically. If the attribute
49  // only has one spelling, no heading is required as the attribute's sole
50  // spelling is sufficient. If all spellings are semantically common, the
51  // heading will be the semantic spelling. If the spellings are not
52  // semantically common and no heading is provided, an error will be emitted.
53  string Heading = "";
54
55  // When set, specifies that the attribute is deprecated and can optionally
56  // specify a replacement attribute.
57  DocDeprecated Deprecated;
58}
59
60// Specifies that the attribute is explicitly omitted from the documentation,
61// because it is not intended to be user-facing.
62def InternalOnly : Documentation {
63  let Category = DocCatInternalOnly;
64}
65
66// Specifies that the attribute is undocumented, but that it _should_ have
67// documentation.
68def Undocumented : Documentation {
69  let Category = DocCatUndocumented;
70  let Content = "No documentation.";
71}
72
73include "clang/Basic/AttrDocs.td"
74
75// An attribute's subject is whatever it appertains to. In this file, it is
76// more accurately a list of things that an attribute can appertain to. All
77// Decls and Stmts are possibly AttrSubjects (even though the syntax may not
78// allow attributes on a given Decl or Stmt).
79class AttrSubject;
80
81include "clang/Basic/DeclNodes.td"
82include "clang/Basic/StmtNodes.td"
83
84// A subset-subject is an AttrSubject constrained to operate only on some subset
85// of that subject.
86//
87// The code fragment is a boolean expression that will confirm that the subject
88// meets the requirements; the subject will have the name S, and will have the
89// type specified by the base. It should be a simple boolean expression. The
90// diagnostic string should be a comma-separated list of subject names.
91class SubsetSubject<AttrSubject base, code check, string diag> : AttrSubject {
92  AttrSubject Base = base;
93  code CheckCode = check;
94  string DiagSpelling = diag;
95}
96
97def LocalVar : SubsetSubject<Var,
98                              [{S->hasLocalStorage() && !isa<ParmVarDecl>(S)}],
99                              "local variables">;
100def NonParmVar : SubsetSubject<Var,
101                               [{S->getKind() != Decl::ParmVar}],
102                               "variables">;
103def NonLocalVar : SubsetSubject<Var,
104                                [{!S->hasLocalStorage()}],
105                                "variables with non-local storage">;
106def NonBitField : SubsetSubject<Field,
107                                [{!S->isBitField()}],
108                                "non-bit-field non-static data members">;
109
110def NonStaticCXXMethod : SubsetSubject<CXXMethod,
111                                       [{!S->isStatic()}],
112                                       "non-static member functions">;
113
114def NonStaticNonConstCXXMethod
115    : SubsetSubject<CXXMethod,
116                    [{!S->isStatic() && !S->isConst()}],
117                    "non-static non-const member functions">;
118
119def ObjCInstanceMethod : SubsetSubject<ObjCMethod,
120                                       [{S->isInstanceMethod()}],
121                                       "Objective-C instance methods">;
122
123def Struct : SubsetSubject<Record,
124                           [{!S->isUnion()}], "structs">;
125
126def TLSVar : SubsetSubject<Var,
127                           [{S->getTLSKind() != 0}], "thread-local variables">;
128
129def SharedVar : SubsetSubject<Var,
130                              [{S->hasGlobalStorage() && !S->getTLSKind()}],
131                              "global variables">;
132
133def GlobalVar : SubsetSubject<Var,
134                             [{S->hasGlobalStorage()}], "global variables">;
135
136def ExternalGlobalVar : SubsetSubject<Var,
137                             [{S->hasGlobalStorage() &&
138                               S->getStorageClass()!=StorageClass::SC_Static &&
139                               !S->isLocalExternDecl()}],
140                             "external global variables">;
141
142def InlineFunction : SubsetSubject<Function,
143                             [{S->isInlineSpecified()}], "inline functions">;
144
145def FunctionTmpl
146    : SubsetSubject<Function, [{S->getTemplatedKind() ==
147                                 FunctionDecl::TK_FunctionTemplate}],
148                    "function templates">;
149
150def HLSLEntry
151    : SubsetSubject<Function,
152                    [{S->isExternallyVisible() && !isa<CXXMethodDecl>(S)}],
153                    "global functions">;
154def HLSLBufferObj : SubsetSubject<HLSLBuffer,
155                    [{isa<HLSLBufferDecl>(S)}],
156                    "cbuffer/tbuffer">;
157
158def ClassTmpl : SubsetSubject<CXXRecord, [{S->getDescribedClassTemplate()}],
159                              "class templates">;
160
161// FIXME: this hack is needed because DeclNodes.td defines the base Decl node
162// type to be a class, not a definition. This makes it impossible to create an
163// attribute subject which accepts a Decl. Normally, this is not a problem,
164// because the attribute can have no Subjects clause to accomplish this. But in
165// the case of a SubsetSubject, there's no way to express it without this hack.
166def DeclBase : AttrSubject;
167def FunctionLike : SubsetSubject<DeclBase,
168                                 [{S->getFunctionType(false) != nullptr}],
169                                 "functions, function pointers">;
170
171def OpenCLKernelFunction
172    : SubsetSubject<Function, [{S->hasAttr<OpenCLKernelAttr>()}],
173                    "kernel functions">;
174
175// HasFunctionProto is a more strict version of FunctionLike, so it should
176// never be specified in a Subjects list along with FunctionLike (due to the
177// inclusive nature of subject testing).
178def HasFunctionProto : SubsetSubject<DeclBase,
179                                     [{(S->getFunctionType(true) != nullptr &&
180                              isa<FunctionProtoType>(S->getFunctionType())) ||
181                                       isa<ObjCMethodDecl>(S) ||
182                                       isa<BlockDecl>(S)}],
183                                     "non-K&R-style functions">;
184
185// A subject that matches the implicit object parameter of a non-static member
186// function. Accepted as a function type attribute on the type of such a
187// member function.
188// FIXME: This does not actually ever match currently.
189def ImplicitObjectParameter
190    : SubsetSubject<Function, [{static_cast<void>(S), false}],
191                    "implicit object parameters">;
192
193// A single argument to an attribute
194class Argument<string name, bit optional, bit fake = 0> {
195  string Name = name;
196  bit Optional = optional;
197
198  /// A fake argument is used to store and serialize additional information
199  /// in an attribute without actually changing its parsing or pretty-printing.
200  bit Fake = fake;
201}
202
203class BoolArgument<string name, bit opt = 0, bit fake = 0> : Argument<name, opt,
204                                                                      fake>;
205class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
206class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
207class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
208class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
209class DeclArgument<DeclNode kind, string name, bit opt = 0, bit fake = 0>
210    : Argument<name, opt, fake> {
211  DeclNode Kind = kind;
212}
213
214// An argument of a OMPDeclareVariantAttr that represents the `match`
215// clause of the declare variant by keeping the information (incl. nesting) in
216// an OMPTraitInfo object.
217//
218// With some exceptions, the `match(<context-selector>)` clause looks roughly
219// as follows:
220//   context-selector := list<selector-set>
221//       selector-set := <kind>={list<selector>}
222//           selector := <kind>([score(<const-expr>):] list<trait>)
223//              trait := <kind>
224//
225// The structure of an OMPTraitInfo object is a tree as defined below:
226//
227//   OMPTraitInfo     := {list<OMPTraitSet>}
228//   OMPTraitSet      := {Kind, list<OMPTraitSelector>}
229//   OMPTraitSelector := {Kind, Expr, list<OMPTraitProperty>}
230//   OMPTraitProperty := {Kind}
231//
232class OMPTraitInfoArgument<string name> : Argument<name, 0>;
233class VariadicOMPInteropInfoArgument<string name> : Argument<name, 0>;
234
235class TypeArgument<string name, bit opt = 0> : Argument<name, opt>;
236class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
237class VariadicUnsignedArgument<string name> : Argument<name, 1>;
238class VariadicExprArgument<string name> : Argument<name, 1>;
239class VariadicStringArgument<string name> : Argument<name, 1>;
240class VariadicIdentifierArgument<string name> : Argument<name, 1>;
241
242// Like VariadicUnsignedArgument except values are ParamIdx.
243class VariadicParamIdxArgument<string name> : Argument<name, 1>;
244
245// A list of identifiers matching parameters or ParamIdx indices.
246class VariadicParamOrParamIdxArgument<string name> : Argument<name, 1>;
247
248// Like VariadicParamIdxArgument but for a single function parameter index.
249class ParamIdxArgument<string name, bit opt = 0> : Argument<name, opt>;
250
251// A version of the form major.minor[.subminor].
252class VersionArgument<string name, bit opt = 0> : Argument<name, opt>;
253
254// This one's a doozy, so it gets its own special type
255// It can be an unsigned integer, or a type. Either can
256// be dependent.
257class AlignedArgument<string name, bit opt = 0> : Argument<name, opt>;
258
259// A bool argument with a default value
260class DefaultBoolArgument<string name, bit default, bit fake = 0>
261    : BoolArgument<name, 1, fake> {
262  bit Default = default;
263}
264
265// An integer argument with a default value
266class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
267  int Default = default;
268}
269
270// This argument is more complex, it includes the enumerator type name,
271// a list of strings to accept, and a list of enumerators to map them to.
272class EnumArgument<string name, string type, list<string> values,
273                   list<string> enums, bit opt = 0, bit fake = 0>
274    : Argument<name, opt, fake> {
275  string Type = type;
276  list<string> Values = values;
277  list<string> Enums = enums;
278}
279
280// FIXME: There should be a VariadicArgument type that takes any other type
281//        of argument and generates the appropriate type.
282class VariadicEnumArgument<string name, string type, list<string> values,
283                           list<string> enums> : Argument<name, 1>  {
284  string Type = type;
285  list<string> Values = values;
286  list<string> Enums = enums;
287}
288
289// This handles one spelling of an attribute.
290class Spelling<string name, string variety> {
291  string Name = name;
292  string Variety = variety;
293}
294
295class GNU<string name> : Spelling<name, "GNU">;
296class Declspec<string name> : Spelling<name, "Declspec">;
297class Microsoft<string name> : Spelling<name, "Microsoft">;
298class CXX11<string namespace, string name, int version = 1>
299    : Spelling<name, "CXX11"> {
300  string Namespace = namespace;
301  int Version = version;
302}
303class C2x<string namespace, string name, int version = 1>
304    : Spelling<name, "C2x"> {
305  string Namespace = namespace;
306  int Version = version;
307}
308
309class Keyword<string name> : Spelling<name, "Keyword">;
310class Pragma<string namespace, string name> : Spelling<name, "Pragma"> {
311  string Namespace = namespace;
312}
313
314// The GCC spelling implies GNU<name>, CXX11<"gnu", name>, and optionally,
315// C2x<"gnu", name>. This spelling should be used for any GCC-compatible
316// attributes.
317class GCC<string name, bit allowInC = 1> : Spelling<name, "GCC"> {
318  bit AllowInC = allowInC;
319}
320
321// The Clang spelling implies GNU<name>, CXX11<"clang", name>, and optionally,
322// C2x<"clang", name>. This spelling should be used for any Clang-specific
323// attributes.
324class Clang<string name, bit allowInC = 1> : Spelling<name, "Clang"> {
325  bit AllowInC = allowInC;
326}
327
328// HLSL Semantic spellings
329class HLSLSemantic<string name> : Spelling<name, "HLSLSemantic">;
330
331class Accessor<string name, list<Spelling> spellings> {
332  string Name = name;
333  list<Spelling> Spellings = spellings;
334}
335
336class SubjectDiag<bit warn> {
337  bit Warn = warn;
338}
339def WarnDiag : SubjectDiag<1>;
340def ErrorDiag : SubjectDiag<0>;
341
342class SubjectList<list<AttrSubject> subjects, SubjectDiag diag = WarnDiag,
343                  string customDiag = ""> {
344  list<AttrSubject> Subjects = subjects;
345  SubjectDiag Diag = diag;
346  string CustomDiag = customDiag;
347}
348
349class LangOpt<string name, code customCode = [{}]> {
350  // The language option to test; ignored when custom code is supplied.
351  string Name = name;
352
353  // A custom predicate, written as an expression evaluated in a context with
354  // "LangOpts" bound.
355  code CustomCode = customCode;
356}
357def MicrosoftExt : LangOpt<"MicrosoftExt">;
358def Borland : LangOpt<"Borland">;
359def CUDA : LangOpt<"CUDA">;
360def HIP : LangOpt<"HIP">;
361def SYCL : LangOpt<"SYCLIsDevice">;
362def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
363def CPlusPlus : LangOpt<"CPlusPlus">;
364def OpenCL : LangOpt<"OpenCL">;
365def RenderScript : LangOpt<"RenderScript">;
366def ObjC : LangOpt<"ObjC">;
367def BlocksSupported : LangOpt<"Blocks">;
368def ObjCAutoRefCount : LangOpt<"ObjCAutoRefCount">;
369def ObjCNonFragileRuntime
370    : LangOpt<"", "LangOpts.ObjCRuntime.allowsClassStubs()">;
371
372def HLSL : LangOpt<"HLSL">;
373
374// Language option for CMSE extensions
375def Cmse : LangOpt<"Cmse">;
376
377// Defines targets for target-specific attributes. Empty lists are unchecked.
378class TargetSpec {
379  // Specifies Architectures for which the target applies, based off the
380  // ArchType enumeration in Triple.h.
381  list<string> Arches = [];
382  // Specifies Operating Systems for which the target applies, based off the
383  // OSType enumeration in Triple.h
384  list<string> OSes;
385  // Specifies Object Formats for which the target applies, based off the
386  // ObjectFormatType enumeration in Triple.h
387  list<string> ObjectFormats;
388  // A custom predicate, written as an expression evaluated in a context
389  // with the following declarations in scope:
390  //   const clang::TargetInfo &Target;
391  //   const llvm::Triple &T = Target.getTriple();
392  code CustomCode = [{}];
393}
394
395class TargetArch<list<string> arches> : TargetSpec {
396  let Arches = arches;
397}
398def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
399def TargetAArch64 : TargetArch<["aarch64"]>;
400def TargetAnyArm : TargetArch<!listconcat(TargetARM.Arches, TargetAArch64.Arches)>;
401def TargetAVR : TargetArch<["avr"]>;
402def TargetBPF : TargetArch<["bpfel", "bpfeb"]>;
403def TargetMips32 : TargetArch<["mips", "mipsel"]>;
404def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
405def TargetMSP430 : TargetArch<["msp430"]>;
406def TargetM68k : TargetArch<["m68k"]>;
407def TargetRISCV : TargetArch<["riscv32", "riscv64"]>;
408def TargetX86 : TargetArch<["x86"]>;
409def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
410def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>;
411def TargetWindows : TargetSpec {
412  let OSes = ["Win32"];
413}
414def TargetHasDLLImportExport : TargetSpec {
415  let CustomCode = [{ Target.getTriple().hasDLLImportExport() }];
416}
417def TargetItaniumCXXABI : TargetSpec {
418  let CustomCode = [{ Target.getCXXABI().isItaniumFamily() }];
419}
420def TargetMicrosoftCXXABI : TargetArch<["x86", "x86_64", "arm", "thumb", "aarch64"]> {
421  let CustomCode = [{ Target.getCXXABI().isMicrosoft() }];
422}
423def TargetELF : TargetSpec {
424  let ObjectFormats = ["ELF"];
425}
426
427def TargetSupportsInitPriority : TargetSpec {
428  let CustomCode = [{ !Target.getTriple().isOSzOS() }];
429}
430// Attribute subject match rules that are used for #pragma clang attribute.
431//
432// A instance of AttrSubjectMatcherRule represents an individual match rule.
433// An individual match rule can correspond to a number of different attribute
434// subjects, e.g. "record" matching rule corresponds to the Record and
435// CXXRecord attribute subjects.
436//
437// Match rules are used in the subject list of the #pragma clang attribute.
438// Match rules can have sub-match rules that are instances of
439// AttrSubjectMatcherSubRule. A sub-match rule can correspond to a number
440// of different attribute subjects, and it can have a negated spelling as well.
441// For example, "variable(unless(is_parameter))" matching rule corresponds to
442// the NonParmVar attribute subject.
443class AttrSubjectMatcherSubRule<string name, list<AttrSubject> subjects,
444                                bit negated = 0> {
445  string Name = name;
446  list<AttrSubject> Subjects = subjects;
447  bit Negated = negated;
448  // Lists language options, one of which is required to be true for the
449  // attribute to be applicable. If empty, the language options are taken
450  // from the parent matcher rule.
451  list<LangOpt> LangOpts = [];
452}
453class AttrSubjectMatcherRule<string name, list<AttrSubject> subjects,
454                             list<AttrSubjectMatcherSubRule> subrules = []> {
455  string Name = name;
456  list<AttrSubject> Subjects = subjects;
457  list<AttrSubjectMatcherSubRule> Constraints = subrules;
458  // Lists language options, one of which is required to be true for the
459  // attribute to be applicable. If empty, no language options are required.
460  list<LangOpt> LangOpts = [];
461}
462
463// function(is_member)
464def SubRuleForCXXMethod : AttrSubjectMatcherSubRule<"is_member", [CXXMethod]> {
465  let LangOpts = [CPlusPlus];
466}
467def SubjectMatcherForFunction : AttrSubjectMatcherRule<"function", [Function], [
468  SubRuleForCXXMethod
469]>;
470// hasType is abstract, it should be used with one of the sub-rules.
471def SubjectMatcherForType : AttrSubjectMatcherRule<"hasType", [], [
472  AttrSubjectMatcherSubRule<"functionType", [FunctionLike]>
473
474  // FIXME: There's a matcher ambiguity with objc methods and blocks since
475  // functionType excludes them but functionProtoType includes them.
476  // AttrSubjectMatcherSubRule<"functionProtoType", [HasFunctionProto]>
477]>;
478def SubjectMatcherForTypedef : AttrSubjectMatcherRule<"type_alias",
479                                                      [TypedefName]>;
480def SubjectMatcherForRecord : AttrSubjectMatcherRule<"record", [Record,
481                                                                CXXRecord], [
482  // unless(is_union)
483  AttrSubjectMatcherSubRule<"is_union", [Struct], 1>
484]>;
485def SubjectMatcherForEnum : AttrSubjectMatcherRule<"enum", [Enum]>;
486def SubjectMatcherForEnumConstant : AttrSubjectMatcherRule<"enum_constant",
487                                                           [EnumConstant]>;
488def SubjectMatcherForVar : AttrSubjectMatcherRule<"variable", [Var], [
489  AttrSubjectMatcherSubRule<"is_thread_local", [TLSVar]>,
490  AttrSubjectMatcherSubRule<"is_global", [GlobalVar]>,
491  AttrSubjectMatcherSubRule<"is_local", [LocalVar]>,
492  AttrSubjectMatcherSubRule<"is_parameter", [ParmVar]>,
493  // unless(is_parameter)
494  AttrSubjectMatcherSubRule<"is_parameter", [NonParmVar], 1>
495]>;
496def SubjectMatcherForField : AttrSubjectMatcherRule<"field", [Field]>;
497def SubjectMatcherForNamespace : AttrSubjectMatcherRule<"namespace",
498                                                        [Namespace]> {
499  let LangOpts = [CPlusPlus];
500}
501def SubjectMatcherForObjCInterface : AttrSubjectMatcherRule<"objc_interface",
502                                                            [ObjCInterface]> {
503  let LangOpts = [ObjC];
504}
505def SubjectMatcherForObjCProtocol : AttrSubjectMatcherRule<"objc_protocol",
506                                                           [ObjCProtocol]> {
507  let LangOpts = [ObjC];
508}
509def SubjectMatcherForObjCCategory : AttrSubjectMatcherRule<"objc_category",
510                                                           [ObjCCategory]> {
511  let LangOpts = [ObjC];
512}
513def SubjectMatcherForObjCImplementation :
514    AttrSubjectMatcherRule<"objc_implementation", [ObjCImpl]> {
515  let LangOpts = [ObjC];
516}
517def SubjectMatcherForObjCMethod : AttrSubjectMatcherRule<"objc_method",
518                                                         [ObjCMethod], [
519  AttrSubjectMatcherSubRule<"is_instance", [ObjCInstanceMethod]>
520]> {
521  let LangOpts = [ObjC];
522}
523def SubjectMatcherForObjCProperty : AttrSubjectMatcherRule<"objc_property",
524                                                           [ObjCProperty]> {
525  let LangOpts = [ObjC];
526}
527def SubjectMatcherForBlock : AttrSubjectMatcherRule<"block", [Block]> {
528  let LangOpts = [BlocksSupported];
529}
530
531// Aggregate attribute subject match rules are abstract match rules that can't
532// be used directly in #pragma clang attribute. Instead, users have to use
533// subject match rules that correspond to attribute subjects that derive from
534// the specified subject.
535class AttrSubjectMatcherAggregateRule<AttrSubject subject> {
536  AttrSubject Subject = subject;
537}
538
539def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule<Named>;
540
541class Attr {
542  // The various ways in which an attribute can be spelled in source
543  list<Spelling> Spellings;
544  // The things to which an attribute can appertain
545  SubjectList Subjects;
546  // The arguments allowed on an attribute
547  list<Argument> Args = [];
548  // Accessors which should be generated for the attribute.
549  list<Accessor> Accessors = [];
550  // Set to true for attributes with arguments which require delayed parsing.
551  bit LateParsed = 0;
552  // Set to false to prevent an attribute from being propagated from a template
553  // to the instantiation.
554  bit Clone = 1;
555  // Set to true for attributes which must be instantiated within templates
556  bit TemplateDependent = 0;
557  // Set to true for attributes that have a corresponding AST node.
558  bit ASTNode = 1;
559  // Set to true for attributes which have handler in Sema.
560  bit SemaHandler = 1;
561  // Set to true if this attribute doesn't need custom handling in Sema.
562  bit SimpleHandler = 0;
563  // Set to true for attributes that are completely ignored.
564  bit Ignored = 0;
565  // Set to true if the attribute's parsing does not match its semantic
566  // content. Eg) It parses 3 args, but semantically takes 4 args.  Opts out of
567  // common attribute error checking.
568  bit HasCustomParsing = 0;
569  // Set to true if all of the attribute's arguments should be parsed in an
570  // unevaluated context.
571  bit ParseArgumentsAsUnevaluated = 0;
572  // Set to true if this attribute meaningful when applied to or inherited
573  // in a class template definition.
574  bit MeaningfulToClassTemplateDefinition = 0;
575  // Set to true if this attribute can be used with '#pragma clang attribute'.
576  // By default, an attribute is supported by the '#pragma clang attribute'
577  // only when:
578  // - It has a subject list whose subjects can be represented using subject
579  //   match rules.
580  // - It has GNU/CXX11 spelling and doesn't require delayed parsing.
581  bit PragmaAttributeSupport;
582  // Set to true if this attribute accepts parameter pack expansion expressions.
583  bit AcceptsExprPack = 0;
584  // Lists language options, one of which is required to be true for the
585  // attribute to be applicable. If empty, no language options are required.
586  list<LangOpt> LangOpts = [];
587  // Any additional text that should be included verbatim in the class.
588  // Note: Any additional data members will leak and should be constructed
589  // externally on the ASTContext.
590  code AdditionalMembers = [{}];
591  // Any documentation that should be associated with the attribute. Since an
592  // attribute may be documented under multiple categories, more than one
593  // Documentation entry may be listed.
594  list<Documentation> Documentation;
595}
596
597/// Used to define a set of mutually exclusive attributes.
598class MutualExclusions<list<Attr> Ex> {
599  list<Attr> Exclusions = Ex;
600}
601
602/// A type attribute is not processed on a declaration or a statement.
603class TypeAttr : Attr;
604
605/// A stmt attribute is not processed on a declaration or a type.
606class StmtAttr : Attr;
607
608/// An inheritable attribute is inherited by later redeclarations.
609class InheritableAttr : Attr {
610  // Set to true if this attribute can be duplicated on a subject when inheriting
611  // attributes from prior declarations.
612  bit InheritEvenIfAlreadyPresent = 0;
613}
614
615/// Some attributes, like calling conventions, can appear in either the
616/// declaration or the type position. These attributes are morally type
617/// attributes, but have historically been written on declarations.
618class DeclOrTypeAttr : InheritableAttr;
619
620/// A attribute is either a declaration attribute or a statement attribute.
621class DeclOrStmtAttr : InheritableAttr;
622
623/// An attribute class for HLSL Annotations.
624class HLSLAnnotationAttr : InheritableAttr;
625
626/// A target-specific attribute.  This class is meant to be used as a mixin
627/// with InheritableAttr or Attr depending on the attribute's needs.
628class TargetSpecificAttr<TargetSpec target> {
629  TargetSpec Target = target;
630  // Attributes are generally required to have unique spellings for their names
631  // so that the parser can determine what kind of attribute it has parsed.
632  // However, target-specific attributes are special in that the attribute only
633  // "exists" for a given target. So two target-specific attributes can share
634  // the same name when they exist in different targets. To support this, a
635  // Kind can be explicitly specified for a target-specific attribute. This
636  // corresponds to the ParsedAttr::AT_* enum that is generated and it
637  // should contain a shared value between the attributes.
638  //
639  // Target-specific attributes which use this feature should ensure that the
640  // spellings match exactly between the attributes, and if the arguments or
641  // subjects differ, should specify HasCustomParsing = 1 and implement their
642  // own parsing and semantic handling requirements as-needed.
643  string ParseKind;
644}
645
646/// An inheritable parameter attribute is inherited by later
647/// redeclarations, even when it's written on a parameter.
648class InheritableParamAttr : InheritableAttr;
649
650/// An attribute which changes the ABI rules for a specific parameter.
651class ParameterABIAttr : InheritableParamAttr {
652  let Subjects = SubjectList<[ParmVar]>;
653}
654
655/// An ignored attribute, which we parse but discard with no checking.
656class IgnoredAttr : Attr {
657  let Ignored = 1;
658  let ASTNode = 0;
659  let SemaHandler = 0;
660  let Documentation = [InternalOnly];
661}
662
663//
664// Attributes begin here
665//
666
667def AbiTag : Attr {
668  let Spellings = [GCC<"abi_tag", /*AllowInC*/0>];
669  let Args = [VariadicStringArgument<"Tags">];
670  let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag>;
671  let MeaningfulToClassTemplateDefinition = 1;
672  let Documentation = [AbiTagsDocs];
673}
674
675def AddressSpace : TypeAttr {
676  let Spellings = [Clang<"address_space">];
677  let Args = [IntArgument<"AddressSpace">];
678  let Documentation = [Undocumented];
679}
680
681def Alias : Attr {
682  let Spellings = [GCC<"alias">];
683  let Args = [StringArgument<"Aliasee">];
684  let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;
685  let Documentation = [Undocumented];
686}
687
688def BuiltinAlias : Attr {
689  let Spellings = [CXX11<"clang", "builtin_alias">,
690                   C2x<"clang", "builtin_alias">,
691                   GNU<"clang_builtin_alias">];
692  let Args = [IdentifierArgument<"BuiltinName">];
693  let Subjects = SubjectList<[Function], ErrorDiag>;
694  let Documentation = [BuiltinAliasDocs];
695}
696
697def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr<TargetAnyArm> {
698  let Spellings = [Clang<"__clang_arm_builtin_alias">];
699  let Args = [IdentifierArgument<"BuiltinName">];
700  let Subjects = SubjectList<[Function], ErrorDiag>;
701  let Documentation = [ArmBuiltinAliasDocs];
702}
703
704def Aligned : InheritableAttr {
705  let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
706                   Keyword<"_Alignas">];
707  let Args = [AlignedArgument<"Alignment", 1>];
708  let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
709                   Accessor<"isC11", [Keyword<"_Alignas">]>,
710                   Accessor<"isAlignas", [Keyword<"alignas">,
711                                          Keyword<"_Alignas">]>,
712                   Accessor<"isDeclspec",[Declspec<"align">]>];
713  let Documentation = [Undocumented];
714}
715
716def AlignValue : Attr {
717  let Spellings = [
718    // Unfortunately, this is semantically an assertion, not a directive
719    // (something else must ensure the alignment), so aligned_value is a
720    // probably a better name. We might want to add an aligned_value spelling in
721    // the future (and a corresponding C++ attribute), but this can be done
722    // later once we decide if we also want them to have slightly-different
723    // semantics than Intel's align_value.
724    //
725    // Does not get a [[]] spelling because the attribute is not exposed as such
726    // by Intel.
727    GNU<"align_value">
728    // Intel's compiler on Windows also supports:
729    // , Declspec<"align_value">
730  ];
731  let Args = [ExprArgument<"Alignment">];
732  let Subjects = SubjectList<[Var, TypedefName]>;
733  let Documentation = [AlignValueDocs];
734}
735
736def AlignMac68k : InheritableAttr {
737  // This attribute has no spellings as it is only ever created implicitly.
738  let Spellings = [];
739  let SemaHandler = 0;
740  let Documentation = [InternalOnly];
741}
742
743def AlignNatural : InheritableAttr {
744  // This attribute has no spellings as it is only ever created implicitly.
745  let Spellings = [];
746  let SemaHandler = 0;
747  let Documentation = [InternalOnly];
748}
749
750def AlwaysInline : DeclOrStmtAttr {
751  let Spellings = [GCC<"always_inline">, CXX11<"clang", "always_inline">,
752                   C2x<"clang", "always_inline">, Keyword<"__forceinline">];
753  let Accessors = [Accessor<"isClangAlwaysInline", [CXX11<"clang", "always_inline">,
754                                                    C2x<"clang", "always_inline">]>];
755  let Subjects = SubjectList<[Function, Stmt], WarnDiag,
756                             "functions and statements">;
757  let Documentation = [AlwaysInlineDocs];
758}
759
760def Artificial : InheritableAttr {
761  let Spellings = [GCC<"artificial">];
762  let Subjects = SubjectList<[InlineFunction]>;
763  let Documentation = [ArtificialDocs];
764  let SimpleHandler = 1;
765}
766
767def XRayInstrument : InheritableAttr {
768  let Spellings = [Clang<"xray_always_instrument">,
769                   Clang<"xray_never_instrument">];
770  let Subjects = SubjectList<[Function, ObjCMethod]>;
771  let Accessors = [Accessor<"alwaysXRayInstrument",
772                     [Clang<"xray_always_instrument">]>,
773                   Accessor<"neverXRayInstrument",
774                     [Clang<"xray_never_instrument">]>];
775  let Documentation = [XRayDocs];
776  let SimpleHandler = 1;
777}
778
779def XRayLogArgs : InheritableAttr {
780  let Spellings = [Clang<"xray_log_args">];
781  let Subjects = SubjectList<[Function, ObjCMethod]>;
782  // This argument is a count not an index, so it has the same encoding (base
783  // 1 including C++ implicit this parameter) at the source and LLVM levels of
784  // representation, so ParamIdxArgument is inappropriate.  It is never used
785  // at the AST level of representation, so it never needs to be adjusted not
786  // to include any C++ implicit this parameter.  Thus, we just store it and
787  // use it as an unsigned that never needs adjustment.
788  let Args = [UnsignedArgument<"ArgumentCount">];
789  let Documentation = [XRayDocs];
790}
791
792def PatchableFunctionEntry
793    : InheritableAttr,
794      TargetSpecificAttr<TargetArch<
795          ["aarch64", "aarch64_be", "riscv32", "riscv64", "x86", "x86_64"]>> {
796  let Spellings = [GCC<"patchable_function_entry">];
797  let Subjects = SubjectList<[Function, ObjCMethod]>;
798  let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];
799  let Documentation = [PatchableFunctionEntryDocs];
800}
801
802def TLSModel : InheritableAttr {
803  let Spellings = [GCC<"tls_model">];
804  let Subjects = SubjectList<[TLSVar], ErrorDiag>;
805  let Args = [StringArgument<"Model">];
806  let Documentation = [TLSModelDocs];
807}
808
809def AnalyzerNoReturn : InheritableAttr {
810  // TODO: should this attribute be exposed with a [[]] spelling under the clang
811  // vendor namespace, or should it use a vendor namespace specific to the
812  // analyzer?
813  let Spellings = [GNU<"analyzer_noreturn">];
814  // TODO: Add subject list.
815  let Documentation = [Undocumented];
816}
817
818def Annotate : InheritableParamAttr {
819  let Spellings = [Clang<"annotate">];
820  let Args = [StringArgument<"Annotation">, VariadicExprArgument<"Args">];
821  // Ensure that the annotate attribute can be used with
822  // '#pragma clang attribute' even though it has no subject list.
823  let AdditionalMembers = [{
824  static AnnotateAttr *Create(ASTContext &Ctx, llvm::StringRef Annotation, \
825              const AttributeCommonInfo &CommonInfo) {
826    return AnnotateAttr::Create(Ctx, Annotation, nullptr, 0, CommonInfo);
827  }
828  static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Annotation, \
829              const AttributeCommonInfo &CommonInfo = {SourceRange{}}) {
830    return AnnotateAttr::CreateImplicit(Ctx, Annotation, nullptr, 0, CommonInfo);
831  }
832  }];
833  let PragmaAttributeSupport = 1;
834  let AcceptsExprPack = 1;
835  let Documentation = [Undocumented];
836}
837
838def AnnotateType : TypeAttr {
839  let Spellings = [CXX11<"clang", "annotate_type">, C2x<"clang", "annotate_type">];
840  let Args = [StringArgument<"Annotation">, VariadicExprArgument<"Args">];
841  let HasCustomParsing = 1;
842  let AcceptsExprPack = 1;
843  let Documentation = [AnnotateTypeDocs];
844}
845
846def ARMInterrupt : InheritableAttr, TargetSpecificAttr<TargetARM> {
847  // NOTE: If you add any additional spellings, M68kInterrupt's,
848  // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings
849  // must match.
850  let Spellings = [GCC<"interrupt">];
851  let Args = [EnumArgument<"Interrupt", "InterruptType",
852                           ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
853                           ["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
854                           1>];
855  let ParseKind = "Interrupt";
856  let HasCustomParsing = 1;
857  let Documentation = [ARMInterruptDocs];
858}
859
860def AVRInterrupt : InheritableAttr, TargetSpecificAttr<TargetAVR> {
861  let Spellings = [GCC<"interrupt">];
862  let Subjects = SubjectList<[Function]>;
863  let ParseKind = "Interrupt";
864  let Documentation = [AVRInterruptDocs];
865}
866
867def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
868  let Spellings = [GCC<"signal">];
869  let Subjects = SubjectList<[Function]>;
870  let Documentation = [AVRSignalDocs];
871}
872
873def AsmLabel : InheritableAttr {
874  let Spellings = [Keyword<"asm">, Keyword<"__asm__">];
875  let Args = [
876    // Label specifies the mangled name for the decl.
877    StringArgument<"Label">,
878
879    // IsLiteralLabel specifies whether the label is literal (i.e. suppresses
880    // the global C symbol prefix) or not. If not, the mangle-suppression prefix
881    // ('\01') is omitted from the decl name at the LLVM IR level.
882    //
883    // Non-literal labels are used by some external AST sources like LLDB.
884    BoolArgument<"IsLiteralLabel", /*optional=*/0, /*fake=*/1>
885  ];
886  let SemaHandler = 0;
887  let Documentation = [AsmLabelDocs];
888  let AdditionalMembers =
889[{
890bool isEquivalent(AsmLabelAttr *Other) const {
891  return getLabel() == Other->getLabel() && getIsLiteralLabel() == Other->getIsLiteralLabel();
892}
893}];
894}
895
896def Availability : InheritableAttr {
897  let Spellings = [Clang<"availability">];
898  let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
899              VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
900              BoolArgument<"unavailable">, StringArgument<"message">,
901              BoolArgument<"strict">, StringArgument<"replacement">,
902              IntArgument<"priority">];
903  let AdditionalMembers =
904[{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
905    return llvm::StringSwitch<llvm::StringRef>(Platform)
906             .Case("android", "Android")
907             .Case("fuchsia", "Fuchsia")
908             .Case("ios", "iOS")
909             .Case("macos", "macOS")
910             .Case("tvos", "tvOS")
911             .Case("watchos", "watchOS")
912             .Case("driverkit", "DriverKit")
913             .Case("ios_app_extension", "iOS (App Extension)")
914             .Case("macos_app_extension", "macOS (App Extension)")
915             .Case("tvos_app_extension", "tvOS (App Extension)")
916             .Case("watchos_app_extension", "watchOS (App Extension)")
917             .Case("maccatalyst", "macCatalyst")
918             .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
919             .Case("swift", "Swift")
920             .Case("shadermodel", "HLSL ShaderModel")
921             .Default(llvm::StringRef());
922}
923static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
924    return llvm::StringSwitch<llvm::StringRef>(Platform)
925             .Case("ios", "iOS")
926             .Case("macos", "macOS")
927             .Case("tvos", "tvOS")
928             .Case("watchos", "watchOS")
929             .Case("ios_app_extension", "iOSApplicationExtension")
930             .Case("macos_app_extension", "macOSApplicationExtension")
931             .Case("tvos_app_extension", "tvOSApplicationExtension")
932             .Case("watchos_app_extension", "watchOSApplicationExtension")
933             .Case("maccatalyst", "macCatalyst")
934             .Case("maccatalyst_app_extension", "macCatalystApplicationExtension")
935             .Case("zos", "z/OS")
936             .Case("shadermodel", "ShaderModel")
937             .Default(Platform);
938}
939static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
940    return llvm::StringSwitch<llvm::StringRef>(Platform)
941             .Case("iOS", "ios")
942             .Case("macOS", "macos")
943             .Case("tvOS", "tvos")
944             .Case("watchOS", "watchos")
945             .Case("iOSApplicationExtension", "ios_app_extension")
946             .Case("macOSApplicationExtension", "macos_app_extension")
947             .Case("tvOSApplicationExtension", "tvos_app_extension")
948             .Case("watchOSApplicationExtension", "watchos_app_extension")
949             .Case("macCatalyst", "maccatalyst")
950             .Case("macCatalystApplicationExtension", "maccatalyst_app_extension")
951             .Case("ShaderModel", "shadermodel")
952             .Default(Platform);
953} }];
954  let HasCustomParsing = 1;
955  let InheritEvenIfAlreadyPresent = 1;
956  let Subjects = SubjectList<[Named]>;
957  let Documentation = [AvailabilityDocs];
958}
959
960def ExternalSourceSymbol : InheritableAttr {
961  let Spellings = [Clang<"external_source_symbol">];
962  let Args = [StringArgument<"language", 1>,
963              StringArgument<"definedIn", 1>,
964              BoolArgument<"generatedDeclaration", 1>];
965  let HasCustomParsing = 1;
966  let Subjects = SubjectList<[Named]>;
967  let Documentation = [ExternalSourceSymbolDocs];
968}
969
970def Blocks : InheritableAttr {
971  let Spellings = [Clang<"blocks">];
972  let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
973  let Documentation = [Undocumented];
974}
975
976def Bounded : IgnoredAttr {
977  // Does not have a [[]] spelling because the attribute is ignored.
978  let Spellings = [GNU<"bounded">];
979}
980
981def CarriesDependency : InheritableParamAttr {
982  let Spellings = [GNU<"carries_dependency">,
983                   CXX11<"","carries_dependency", 200809>];
984  let Subjects = SubjectList<[ParmVar, ObjCMethod, Function], ErrorDiag>;
985  let Documentation = [CarriesDependencyDocs];
986}
987
988def CDecl : DeclOrTypeAttr {
989  let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
990//  let Subjects = [Function, ObjCMethod];
991  let Documentation = [Undocumented];
992}
993
994// cf_audited_transfer indicates that the given function has been
995// audited and has been marked with the appropriate cf_consumed and
996// cf_returns_retained attributes.  It is generally applied by
997// '#pragma clang arc_cf_code_audited' rather than explicitly.
998def CFAuditedTransfer : InheritableAttr {
999  let Spellings = [Clang<"cf_audited_transfer">];
1000  let Subjects = SubjectList<[Function], ErrorDiag>;
1001  let Documentation = [Undocumented];
1002  let SimpleHandler = 1;
1003}
1004
1005// cf_unknown_transfer is an explicit opt-out of cf_audited_transfer.
1006// It indicates that the function has unknown or unautomatable
1007// transfer semantics.
1008def CFUnknownTransfer : InheritableAttr {
1009  let Spellings = [Clang<"cf_unknown_transfer">];
1010  let Subjects = SubjectList<[Function], ErrorDiag>;
1011  let Documentation = [Undocumented];
1012  let SimpleHandler = 1;
1013}
1014def : MutualExclusions<[CFAuditedTransfer, CFUnknownTransfer]>;
1015
1016def CFReturnsRetained : InheritableAttr {
1017  let Spellings = [Clang<"cf_returns_retained">];
1018//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1019  let Documentation = [RetainBehaviorDocs];
1020}
1021
1022def CFReturnsNotRetained : InheritableAttr {
1023  let Spellings = [Clang<"cf_returns_not_retained">];
1024//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
1025  let Documentation = [RetainBehaviorDocs];
1026}
1027
1028def CFConsumed : InheritableParamAttr {
1029  let Spellings = [Clang<"cf_consumed">];
1030  let Subjects = SubjectList<[ParmVar]>;
1031  let Documentation = [RetainBehaviorDocs];
1032}
1033
1034// OSObject-based attributes.
1035def OSConsumed : InheritableParamAttr {
1036  let Spellings = [Clang<"os_consumed">];
1037  let Subjects = SubjectList<[ParmVar]>;
1038  let Documentation = [RetainBehaviorDocs];
1039}
1040
1041def OSReturnsRetained : InheritableAttr {
1042  let Spellings = [Clang<"os_returns_retained">];
1043  let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty, ParmVar]>;
1044  let Documentation = [RetainBehaviorDocs];
1045}
1046
1047def OSReturnsNotRetained : InheritableAttr {
1048  let Spellings = [Clang<"os_returns_not_retained">];
1049  let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty, ParmVar]>;
1050  let Documentation = [RetainBehaviorDocs];
1051}
1052
1053def OSReturnsRetainedOnZero : InheritableAttr {
1054  let Spellings = [Clang<"os_returns_retained_on_zero">];
1055  let Subjects = SubjectList<[ParmVar]>;
1056  let Documentation = [RetainBehaviorDocs];
1057}
1058
1059def OSReturnsRetainedOnNonZero : InheritableAttr {
1060  let Spellings = [Clang<"os_returns_retained_on_non_zero">];
1061  let Subjects = SubjectList<[ParmVar]>;
1062  let Documentation = [RetainBehaviorDocs];
1063}
1064
1065def OSConsumesThis : InheritableAttr {
1066  let Spellings = [Clang<"os_consumes_this">];
1067  let Subjects = SubjectList<[NonStaticCXXMethod]>;
1068  let Documentation = [RetainBehaviorDocs];
1069  let SimpleHandler = 1;
1070}
1071
1072def Cleanup : InheritableAttr {
1073  let Spellings = [GCC<"cleanup">];
1074  let Args = [DeclArgument<Function, "FunctionDecl">];
1075  let Subjects = SubjectList<[LocalVar]>;
1076  let Documentation = [Undocumented];
1077}
1078
1079def CmseNSEntry : InheritableAttr, TargetSpecificAttr<TargetARM> {
1080  let Spellings = [GNU<"cmse_nonsecure_entry">];
1081  let Subjects = SubjectList<[Function]>;
1082  let LangOpts = [Cmse];
1083  let Documentation = [ArmCmseNSEntryDocs];
1084}
1085
1086def CmseNSCall : TypeAttr, TargetSpecificAttr<TargetARM> {
1087  let Spellings = [GNU<"cmse_nonsecure_call">];
1088  let LangOpts = [Cmse];
1089  let Documentation = [ArmCmseNSCallDocs];
1090}
1091
1092def Cold : InheritableAttr {
1093  let Spellings = [GCC<"cold">];
1094  let Subjects = SubjectList<[Function]>;
1095  let Documentation = [ColdFunctionEntryDocs];
1096  let SimpleHandler = 1;
1097}
1098
1099def Common : InheritableAttr {
1100  let Spellings = [GCC<"common">];
1101  let Subjects = SubjectList<[Var]>;
1102  let Documentation = [Undocumented];
1103}
1104
1105def Const : InheritableAttr {
1106  let Spellings = [GCC<"const">, GCC<"__const">];
1107  let Documentation = [Undocumented];
1108  let SimpleHandler = 1;
1109}
1110
1111def ConstInit : InheritableAttr {
1112  // This attribute does not have a C [[]] spelling because it requires the
1113  // CPlusPlus language option.
1114  let Spellings = [Keyword<"constinit">,
1115                   Clang<"require_constant_initialization", 0>];
1116  let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
1117  let Accessors = [Accessor<"isConstinit", [Keyword<"constinit">]>];
1118  let Documentation = [ConstInitDocs];
1119  let LangOpts = [CPlusPlus];
1120  let SimpleHandler = 1;
1121}
1122
1123def Constructor : InheritableAttr {
1124  let Spellings = [GCC<"constructor">];
1125  let Args = [DefaultIntArgument<"Priority", 65535>];
1126  let Subjects = SubjectList<[Function]>;
1127  let Documentation = [Undocumented];
1128}
1129
1130def CPUSpecific : InheritableAttr {
1131  let Spellings = [Clang<"cpu_specific">, Declspec<"cpu_specific">];
1132  let Args = [VariadicIdentifierArgument<"Cpus">];
1133  let Subjects = SubjectList<[Function]>;
1134  let Documentation = [CPUSpecificCPUDispatchDocs];
1135  let AdditionalMembers = [{
1136    IdentifierInfo *getCPUName(unsigned Index) const {
1137      return *(cpus_begin() + Index);
1138    }
1139  }];
1140}
1141
1142def CPUDispatch : InheritableAttr {
1143  let Spellings = [Clang<"cpu_dispatch">, Declspec<"cpu_dispatch">];
1144  let Args = [VariadicIdentifierArgument<"Cpus">];
1145  let Subjects = SubjectList<[Function]>;
1146  let Documentation = [CPUSpecificCPUDispatchDocs];
1147}
1148
1149// CUDA attributes are spelled __attribute__((attr)) or __declspec(__attr__),
1150// and they do not receive a [[]] spelling.
1151def CUDAConstant : InheritableAttr {
1152  let Spellings = [GNU<"constant">, Declspec<"__constant__">];
1153  let Subjects = SubjectList<[Var]>;
1154  let LangOpts = [CUDA];
1155  let Documentation = [Undocumented];
1156}
1157
1158def CUDACudartBuiltin : IgnoredAttr {
1159  let Spellings = [GNU<"cudart_builtin">, Declspec<"__cudart_builtin__">];
1160  let LangOpts = [CUDA];
1161}
1162
1163def CUDADevice : InheritableAttr {
1164  let Spellings = [GNU<"device">, Declspec<"__device__">];
1165  let Subjects = SubjectList<[Function, Var]>;
1166  let LangOpts = [CUDA];
1167  let Documentation = [Undocumented];
1168}
1169
1170def CUDADeviceBuiltin : IgnoredAttr {
1171  let Spellings = [GNU<"device_builtin">, Declspec<"__device_builtin__">];
1172  let LangOpts = [CUDA];
1173}
1174
1175def CUDADeviceBuiltinSurfaceType : InheritableAttr {
1176  let Spellings = [GNU<"device_builtin_surface_type">,
1177                   Declspec<"__device_builtin_surface_type__">];
1178  let LangOpts = [CUDA];
1179  let Subjects = SubjectList<[CXXRecord]>;
1180  let Documentation = [CUDADeviceBuiltinSurfaceTypeDocs];
1181  let MeaningfulToClassTemplateDefinition = 1;
1182  let SimpleHandler = 1;
1183}
1184
1185def CUDADeviceBuiltinTextureType : InheritableAttr {
1186  let Spellings = [GNU<"device_builtin_texture_type">,
1187                   Declspec<"__device_builtin_texture_type__">];
1188  let LangOpts = [CUDA];
1189  let Subjects = SubjectList<[CXXRecord]>;
1190  let Documentation = [CUDADeviceBuiltinTextureTypeDocs];
1191  let MeaningfulToClassTemplateDefinition = 1;
1192  let SimpleHandler = 1;
1193}
1194def : MutualExclusions<[CUDADeviceBuiltinSurfaceType,
1195                        CUDADeviceBuiltinTextureType]>;
1196
1197def CUDAGlobal : InheritableAttr {
1198  let Spellings = [GNU<"global">, Declspec<"__global__">];
1199  let Subjects = SubjectList<[Function]>;
1200  let LangOpts = [CUDA];
1201  let Documentation = [Undocumented];
1202}
1203def : MutualExclusions<[CUDADevice, CUDAGlobal]>;
1204
1205def CUDAHost : InheritableAttr {
1206  let Spellings = [GNU<"host">, Declspec<"__host__">];
1207  let Subjects = SubjectList<[Function]>;
1208  let LangOpts = [CUDA];
1209  let Documentation = [Undocumented];
1210  let SimpleHandler = 1;
1211}
1212def : MutualExclusions<[CUDAGlobal, CUDAHost]>;
1213
1214def HIPManaged : InheritableAttr {
1215  let Spellings = [GNU<"managed">, Declspec<"__managed__">];
1216  let Subjects = SubjectList<[Var]>;
1217  let LangOpts = [HIP];
1218  let Documentation = [HIPManagedAttrDocs];
1219}
1220
1221def CUDAInvalidTarget : InheritableAttr {
1222  let Spellings = [];
1223  let Subjects = SubjectList<[Function]>;
1224  let LangOpts = [CUDA];
1225  let Documentation = [InternalOnly];
1226}
1227
1228def CUDALaunchBounds : InheritableAttr {
1229  let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
1230  let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
1231  let LangOpts = [CUDA];
1232  let Subjects = SubjectList<[ObjCMethod, FunctionLike]>;
1233  // An AST node is created for this attribute, but is not used by other parts
1234  // of the compiler. However, this node needs to exist in the AST because
1235  // non-LLVM backends may be relying on the attribute's presence.
1236  let Documentation = [Undocumented];
1237}
1238
1239def CUDAShared : InheritableAttr {
1240  let Spellings = [GNU<"shared">, Declspec<"__shared__">];
1241  let Subjects = SubjectList<[Var]>;
1242  let LangOpts = [CUDA];
1243  let Documentation = [Undocumented];
1244}
1245def : MutualExclusions<[CUDAConstant, CUDAShared, HIPManaged]>;
1246
1247def SYCLKernel : InheritableAttr {
1248  let Spellings = [Clang<"sycl_kernel">];
1249  let Subjects = SubjectList<[FunctionTmpl]>;
1250  let LangOpts = [SYCL];
1251  let Documentation = [SYCLKernelDocs];
1252}
1253
1254def SYCLSpecialClass: InheritableAttr {
1255  let Spellings = [Clang<"sycl_special_class">];
1256  let Subjects = SubjectList<[CXXRecord]>;
1257  let LangOpts = [SYCL];
1258  let Documentation = [SYCLSpecialClassDocs];
1259}
1260
1261def C11NoReturn : InheritableAttr {
1262  let Spellings = [Keyword<"_Noreturn">];
1263  let Subjects = SubjectList<[Function], ErrorDiag>;
1264  let SemaHandler = 0;
1265  let Documentation = [C11NoReturnDocs];
1266}
1267
1268def CXX11NoReturn : InheritableAttr {
1269  let Spellings = [CXX11<"", "noreturn", 200809>,
1270                   C2x<"", "noreturn", 202202>, C2x<"", "_Noreturn", 202202>];
1271  let Subjects = SubjectList<[Function], ErrorDiag>;
1272  let Documentation = [CXX11NoReturnDocs];
1273}
1274
1275// Similar to CUDA, OpenCL attributes do not receive a [[]] spelling because
1276// the specification does not expose them with one currently.
1277def OpenCLKernel : InheritableAttr {
1278  let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
1279  let Subjects = SubjectList<[Function], ErrorDiag>;
1280  let Documentation = [Undocumented];
1281  let SimpleHandler = 1;
1282}
1283
1284def OpenCLUnrollHint : StmtAttr {
1285  let Spellings = [GNU<"opencl_unroll_hint">];
1286  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
1287                             ErrorDiag, "'for', 'while', and 'do' statements">;
1288  let Args = [UnsignedArgument<"UnrollHint", /*opt*/1>];
1289  let Documentation = [OpenCLUnrollHintDocs];
1290}
1291
1292def OpenCLIntelReqdSubGroupSize: InheritableAttr {
1293  let Spellings = [GNU<"intel_reqd_sub_group_size">];
1294  let Args = [UnsignedArgument<"SubGroupSize">];
1295  let Subjects = SubjectList<[Function], ErrorDiag>;
1296  let Documentation = [OpenCLIntelReqdSubGroupSizeDocs];
1297}
1298
1299// This attribute is both a type attribute, and a declaration attribute (for
1300// parameter variables).
1301def OpenCLAccess : Attr {
1302  let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
1303                   Keyword<"__write_only">, Keyword<"write_only">,
1304                   Keyword<"__read_write">, Keyword<"read_write">];
1305  let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag>;
1306  let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
1307                                           Keyword<"read_only">]>,
1308                   Accessor<"isReadWrite", [Keyword<"__read_write">,
1309                                            Keyword<"read_write">]>,
1310                   Accessor<"isWriteOnly", [Keyword<"__write_only">,
1311                                            Keyword<"write_only">]>];
1312  let Documentation = [OpenCLAccessDocs];
1313}
1314
1315def OpenCLPrivateAddressSpace : TypeAttr {
1316  let Spellings = [Keyword<"__private">, Keyword<"private">, Clang<"opencl_private">];
1317  let Documentation = [OpenCLAddressSpacePrivateDocs];
1318}
1319
1320def OpenCLGlobalAddressSpace : TypeAttr {
1321  let Spellings = [Keyword<"__global">, Keyword<"global">, Clang<"opencl_global">];
1322  let Documentation = [OpenCLAddressSpaceGlobalDocs];
1323}
1324
1325def OpenCLGlobalDeviceAddressSpace : TypeAttr {
1326  let Spellings = [Clang<"opencl_global_device">];
1327  let Documentation = [OpenCLAddressSpaceGlobalExtDocs];
1328}
1329
1330def OpenCLGlobalHostAddressSpace : TypeAttr {
1331  let Spellings = [Clang<"opencl_global_host">];
1332  let Documentation = [OpenCLAddressSpaceGlobalExtDocs];
1333}
1334
1335def OpenCLLocalAddressSpace : TypeAttr {
1336  let Spellings = [Keyword<"__local">, Keyword<"local">, Clang<"opencl_local">];
1337  let Documentation = [OpenCLAddressSpaceLocalDocs];
1338}
1339
1340def OpenCLConstantAddressSpace : TypeAttr {
1341  let Spellings = [Keyword<"__constant">, Keyword<"constant">, Clang<"opencl_constant">];
1342  let Documentation = [OpenCLAddressSpaceConstantDocs];
1343}
1344
1345def OpenCLGenericAddressSpace : TypeAttr {
1346  let Spellings = [Keyword<"__generic">, Keyword<"generic">, Clang<"opencl_generic">];
1347  let Documentation = [OpenCLAddressSpaceGenericDocs];
1348}
1349
1350def OpenCLNoSVM : Attr {
1351  let Spellings = [GNU<"nosvm">];
1352  let Subjects = SubjectList<[Var]>;
1353  let Documentation = [OpenCLNoSVMDocs];
1354  let LangOpts = [OpenCL];
1355  let ASTNode = 0;
1356}
1357
1358def RenderScriptKernel : Attr {
1359  let Spellings = [GNU<"kernel">];
1360  let Subjects = SubjectList<[Function]>;
1361  let Documentation = [RenderScriptKernelAttributeDocs];
1362  let LangOpts = [RenderScript];
1363  let SimpleHandler = 1;
1364}
1365
1366def Deprecated : InheritableAttr {
1367  let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
1368                   CXX11<"","deprecated", 201309>,
1369                   C2x<"", "deprecated", 201904>];
1370  let Args = [StringArgument<"Message", 1>,
1371              // An optional string argument that enables us to provide a
1372              // Fix-It.
1373              StringArgument<"Replacement", 1>];
1374  let MeaningfulToClassTemplateDefinition = 1;
1375  let Documentation = [DeprecatedDocs];
1376}
1377
1378def Destructor : InheritableAttr {
1379  let Spellings = [GCC<"destructor">];
1380  let Args = [DefaultIntArgument<"Priority", 65535>];
1381  let Subjects = SubjectList<[Function]>;
1382  let Documentation = [Undocumented];
1383}
1384
1385def EmptyBases : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1386  let Spellings = [Declspec<"empty_bases">];
1387  let Subjects = SubjectList<[CXXRecord]>;
1388  let Documentation = [EmptyBasesDocs];
1389  let SimpleHandler = 1;
1390}
1391
1392def AllocSize : InheritableAttr {
1393  let Spellings = [GCC<"alloc_size">];
1394  let Subjects = SubjectList<[HasFunctionProto]>;
1395  let Args = [ParamIdxArgument<"ElemSizeParam">,
1396              ParamIdxArgument<"NumElemsParam", /*opt*/ 1>];
1397  let TemplateDependent = 1;
1398  let Documentation = [AllocSizeDocs];
1399}
1400
1401def EnableIf : InheritableAttr {
1402  // Does not have a [[]] spelling because this attribute requires the ability
1403  // to parse function arguments but the attribute is not written in the type
1404  // position.
1405  let Spellings = [GNU<"enable_if">];
1406  let Subjects = SubjectList<[Function]>;
1407  let Args = [ExprArgument<"Cond">, StringArgument<"Message">];
1408  let TemplateDependent = 1;
1409  let Documentation = [EnableIfDocs];
1410}
1411
1412def ExtVectorType : Attr {
1413  // This is an OpenCL-related attribute and does not receive a [[]] spelling.
1414  let Spellings = [GNU<"ext_vector_type">];
1415  // FIXME: This subject list is wrong; this is a type attribute.
1416  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
1417  let Args = [ExprArgument<"NumElements">];
1418  let ASTNode = 0;
1419  let Documentation = [Undocumented];
1420  // This is a type attribute with an incorrect subject list, so should not be
1421  // permitted by #pragma clang attribute.
1422  let PragmaAttributeSupport = 0;
1423}
1424
1425def FallThrough : StmtAttr {
1426  let Spellings = [CXX11<"", "fallthrough", 201603>,
1427                   C2x<"", "fallthrough", 201910>,
1428                   CXX11<"clang", "fallthrough">, GCC<"fallthrough">];
1429  // The attribute only applies to a NullStmt, but we have special fix-it
1430  // behavior if applied to a case label.
1431  let Subjects = SubjectList<[NullStmt, SwitchCase], ErrorDiag,
1432                             "empty statements">;
1433  let Documentation = [FallthroughDocs];
1434}
1435
1436def Likely : StmtAttr {
1437  let Spellings = [CXX11<"", "likely", 201803>, C2x<"clang", "likely">];
1438  let Documentation = [LikelihoodDocs];
1439}
1440
1441def Unlikely : StmtAttr {
1442  let Spellings = [CXX11<"", "unlikely", 201803>, C2x<"clang", "unlikely">];
1443  let Documentation = [LikelihoodDocs];
1444}
1445def : MutualExclusions<[Likely, Unlikely]>;
1446
1447def NoMerge : DeclOrStmtAttr {
1448  let Spellings = [Clang<"nomerge">];
1449  let Documentation = [NoMergeDocs];
1450  let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
1451                             "functions and statements">;
1452  let SimpleHandler = 1;
1453}
1454
1455def MustTail : StmtAttr {
1456  let Spellings = [Clang<"musttail">];
1457  let Documentation = [MustTailDocs];
1458  let Subjects = SubjectList<[ReturnStmt], ErrorDiag, "return statements">;
1459}
1460
1461def FastCall : DeclOrTypeAttr {
1462  let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
1463                   Keyword<"_fastcall">];
1464//  let Subjects = [Function, ObjCMethod];
1465  let Documentation = [FastCallDocs];
1466}
1467
1468def RegCall : DeclOrTypeAttr {
1469  let Spellings = [GCC<"regcall">, Keyword<"__regcall">];
1470  let Documentation = [RegCallDocs];
1471}
1472
1473def Final : InheritableAttr {
1474  let Spellings = [Keyword<"final">, Keyword<"sealed">];
1475  let Accessors = [Accessor<"isSpelledAsSealed", [Keyword<"sealed">]>];
1476  let SemaHandler = 0;
1477  // Omitted from docs, since this is language syntax, not an attribute, as far
1478  // as users are concerned.
1479  let Documentation = [InternalOnly];
1480}
1481
1482def MinSize : InheritableAttr {
1483  let Spellings = [Clang<"minsize">];
1484  let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
1485  let Documentation = [MinSizeDocs];
1486}
1487
1488def FlagEnum : InheritableAttr {
1489  let Spellings = [Clang<"flag_enum">];
1490  let Subjects = SubjectList<[Enum]>;
1491  let Documentation = [FlagEnumDocs];
1492  let SimpleHandler = 1;
1493}
1494
1495def EnumExtensibility : InheritableAttr {
1496  let Spellings = [Clang<"enum_extensibility">];
1497  let Subjects = SubjectList<[Enum]>;
1498  let Args = [EnumArgument<"Extensibility", "Kind",
1499              ["closed", "open"], ["Closed", "Open"]>];
1500  let Documentation = [EnumExtensibilityDocs];
1501}
1502
1503def Flatten : InheritableAttr {
1504  let Spellings = [GCC<"flatten">];
1505  let Subjects = SubjectList<[Function], ErrorDiag>;
1506  let Documentation = [FlattenDocs];
1507  let SimpleHandler = 1;
1508}
1509
1510def Format : InheritableAttr {
1511  let Spellings = [GCC<"format">];
1512  let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">,
1513              IntArgument<"FirstArg">];
1514  let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto]>;
1515  let Documentation = [FormatDocs];
1516}
1517
1518def FormatArg : InheritableAttr {
1519  let Spellings = [GCC<"format_arg">];
1520  let Args = [ParamIdxArgument<"FormatIdx">];
1521  let Subjects = SubjectList<[ObjCMethod, HasFunctionProto]>;
1522  let Documentation = [Undocumented];
1523}
1524
1525def Callback : InheritableAttr {
1526  let Spellings = [Clang<"callback">];
1527  let Args = [VariadicParamOrParamIdxArgument<"Encoding">];
1528  let Subjects = SubjectList<[Function]>;
1529  let Documentation = [CallbackDocs];
1530}
1531
1532def GNUInline : InheritableAttr {
1533  let Spellings = [GCC<"gnu_inline">];
1534  let Subjects = SubjectList<[Function]>;
1535  let Documentation = [GnuInlineDocs];
1536}
1537
1538def Hot : InheritableAttr {
1539  let Spellings = [GCC<"hot">];
1540  let Subjects = SubjectList<[Function]>;
1541  let Documentation = [HotFunctionEntryDocs];
1542  let SimpleHandler = 1;
1543}
1544def : MutualExclusions<[Hot, Cold]>;
1545
1546def IBAction : InheritableAttr {
1547  let Spellings = [Clang<"ibaction">];
1548  let Subjects = SubjectList<[ObjCInstanceMethod]>;
1549  // An AST node is created for this attribute, but is not used by other parts
1550  // of the compiler. However, this node needs to exist in the AST because
1551  // external tools rely on it.
1552  let Documentation = [Undocumented];
1553  let SimpleHandler = 1;
1554}
1555
1556def IBOutlet : InheritableAttr {
1557  let Spellings = [Clang<"iboutlet">];
1558//  let Subjects = [ObjCIvar, ObjCProperty];
1559  let Documentation = [Undocumented];
1560}
1561
1562def IBOutletCollection : InheritableAttr {
1563  let Spellings = [Clang<"iboutletcollection">];
1564  let Args = [TypeArgument<"Interface", 1>];
1565//  let Subjects = [ObjCIvar, ObjCProperty];
1566  let Documentation = [Undocumented];
1567}
1568
1569def IFunc : Attr, TargetSpecificAttr<TargetELF> {
1570  let Spellings = [GCC<"ifunc">];
1571  let Args = [StringArgument<"Resolver">];
1572  let Subjects = SubjectList<[Function]>;
1573  let Documentation = [IFuncDocs];
1574}
1575
1576def Restrict : InheritableAttr {
1577  let Spellings = [Declspec<"restrict">, GCC<"malloc">];
1578  let Subjects = SubjectList<[Function]>;
1579  let Documentation = [RestrictDocs];
1580}
1581
1582def LayoutVersion : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1583  let Spellings = [Declspec<"layout_version">];
1584  let Args = [UnsignedArgument<"Version">];
1585  let Subjects = SubjectList<[CXXRecord]>;
1586  let Documentation = [LayoutVersionDocs];
1587}
1588
1589def Leaf : InheritableAttr {
1590  let Spellings = [GCC<"leaf">];
1591  let Subjects = SubjectList<[Function]>;
1592  let Documentation = [LeafDocs];
1593  let SimpleHandler = 1;
1594}
1595
1596def LifetimeBound : DeclOrTypeAttr {
1597  let Spellings = [Clang<"lifetimebound", 0>];
1598  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
1599  let Documentation = [LifetimeBoundDocs];
1600  let LangOpts = [CPlusPlus];
1601  let SimpleHandler = 1;
1602}
1603
1604def TrivialABI : InheritableAttr {
1605  // This attribute does not have a C [[]] spelling because it requires the
1606  // CPlusPlus language option.
1607  let Spellings = [Clang<"trivial_abi", 0>];
1608  let Subjects = SubjectList<[CXXRecord]>;
1609  let Documentation = [TrivialABIDocs];
1610  let LangOpts = [CPlusPlus];
1611  let SimpleHandler = 1;
1612}
1613
1614def MaxFieldAlignment : InheritableAttr {
1615  // This attribute has no spellings as it is only ever created implicitly.
1616  let Spellings = [];
1617  let Args = [UnsignedArgument<"Alignment">];
1618  let SemaHandler = 0;
1619  let Documentation = [InternalOnly];
1620}
1621
1622def MayAlias : InheritableAttr {
1623  // FIXME: this is a type attribute in GCC, but a declaration attribute here.
1624  let Spellings = [GCC<"may_alias">];
1625  let Documentation = [Undocumented];
1626  let SimpleHandler = 1;
1627}
1628
1629def MIGServerRoutine : InheritableAttr {
1630  let Spellings = [Clang<"mig_server_routine">];
1631  let Subjects = SubjectList<[Function, ObjCMethod, Block]>;
1632  let Documentation = [MIGConventionDocs];
1633}
1634
1635def MSABI : DeclOrTypeAttr {
1636  let Spellings = [GCC<"ms_abi">];
1637//  let Subjects = [Function, ObjCMethod];
1638  let Documentation = [MSABIDocs];
1639}
1640
1641def MSP430Interrupt : InheritableAttr, TargetSpecificAttr<TargetMSP430> {
1642  // NOTE: If you add any additional spellings, ARMInterrupt's, M68kInterrupt's,
1643  // MipsInterrupt's and AnyX86Interrupt's spellings must match.
1644  let Spellings = [GCC<"interrupt">];
1645  let Args = [UnsignedArgument<"Number">];
1646  let ParseKind = "Interrupt";
1647  let HasCustomParsing = 1;
1648  let Documentation = [Undocumented];
1649}
1650
1651def Mips16 : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1652  let Spellings = [GCC<"mips16">];
1653  let Subjects = SubjectList<[Function], ErrorDiag>;
1654  let Documentation = [Undocumented];
1655  let SimpleHandler = 1;
1656}
1657
1658def MipsInterrupt : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1659  // NOTE: If you add any additional spellings, ARMInterrupt's,
1660  // M68kInterrupt's, MSP430Interrupt's and AnyX86Interrupt's spellings
1661  // must match.
1662  let Spellings = [GCC<"interrupt">];
1663  let Subjects = SubjectList<[Function]>;
1664  let Args = [EnumArgument<"Interrupt", "InterruptType",
1665                           ["vector=sw0", "vector=sw1", "vector=hw0",
1666                            "vector=hw1", "vector=hw2", "vector=hw3",
1667                            "vector=hw4", "vector=hw5", "eic", ""],
1668                           ["sw0", "sw1", "hw0", "hw1", "hw2", "hw3",
1669                            "hw4", "hw5", "eic", "eic"]
1670                           >];
1671  let ParseKind = "Interrupt";
1672  let Documentation = [MipsInterruptDocs];
1673}
1674def : MutualExclusions<[Mips16, MipsInterrupt]>;
1675
1676def MicroMips : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1677  let Spellings = [GCC<"micromips">];
1678  let Subjects = SubjectList<[Function], ErrorDiag>;
1679  let Documentation = [MicroMipsDocs];
1680  let SimpleHandler = 1;
1681}
1682def : MutualExclusions<[Mips16, MicroMips]>;
1683
1684def MipsLongCall : InheritableAttr, TargetSpecificAttr<TargetAnyMips> {
1685  let Spellings = [GCC<"long_call">, GCC<"far">];
1686  let Subjects = SubjectList<[Function]>;
1687  let Documentation = [MipsLongCallStyleDocs];
1688  let SimpleHandler = 1;
1689}
1690
1691def MipsShortCall : InheritableAttr, TargetSpecificAttr<TargetAnyMips> {
1692  let Spellings = [GCC<"short_call">, GCC<"near">];
1693  let Subjects = SubjectList<[Function]>;
1694  let Documentation = [MipsShortCallStyleDocs];
1695  let SimpleHandler = 1;
1696}
1697def : MutualExclusions<[MipsLongCall, MipsShortCall]>;
1698
1699def M68kInterrupt : InheritableAttr, TargetSpecificAttr<TargetM68k> {
1700  // NOTE: If you add any additional spellings, ARMInterrupt's, MipsInterrupt's
1701  // MSP430Interrupt's and AnyX86Interrupt's spellings must match.
1702  let Spellings = [GNU<"interrupt">];
1703  let Args = [UnsignedArgument<"Number">];
1704  let ParseKind = "Interrupt";
1705  let HasCustomParsing = 1;
1706  let Documentation = [Undocumented];
1707}
1708
1709def Mode : Attr {
1710  let Spellings = [GCC<"mode">];
1711  let Subjects = SubjectList<[Var, Enum, TypedefName, Field], ErrorDiag>;
1712  let Args = [IdentifierArgument<"Mode">];
1713  let Documentation = [Undocumented];
1714  // This is notionally a type attribute, which #pragma clang attribute
1715  // generally does not support.
1716  let PragmaAttributeSupport = 0;
1717}
1718
1719def Naked : InheritableAttr {
1720  let Spellings = [GCC<"naked">, Declspec<"naked">];
1721  let Subjects = SubjectList<[Function]>;
1722  let Documentation = [Undocumented];
1723}
1724
1725def NeonPolyVectorType : TypeAttr {
1726  let Spellings = [Clang<"neon_polyvector_type">];
1727  let Args = [IntArgument<"NumElements">];
1728  let Documentation = [Undocumented];
1729  // Represented as VectorType instead.
1730  let ASTNode = 0;
1731}
1732
1733def NeonVectorType : TypeAttr {
1734  let Spellings = [Clang<"neon_vector_type">];
1735  let Args = [IntArgument<"NumElements">];
1736  let Documentation = [Undocumented];
1737  // Represented as VectorType instead.
1738  let ASTNode = 0;
1739}
1740
1741def ArmSveVectorBits : TypeAttr {
1742  let Spellings = [GNU<"arm_sve_vector_bits">];
1743  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
1744  let Args = [UnsignedArgument<"NumBits">];
1745  let Documentation = [ArmSveVectorBitsDocs];
1746  let PragmaAttributeSupport = 0;
1747  // Represented as VectorType instead.
1748  let ASTNode = 0;
1749}
1750
1751def ArmMveStrictPolymorphism : TypeAttr, TargetSpecificAttr<TargetARM> {
1752  let Spellings = [Clang<"__clang_arm_mve_strict_polymorphism">];
1753  let Documentation = [ArmMveStrictPolymorphismDocs];
1754}
1755
1756def NoUniqueAddress : InheritableAttr, TargetSpecificAttr<TargetItaniumCXXABI> {
1757  let Spellings = [CXX11<"", "no_unique_address", 201803>];
1758  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1759  let Documentation = [NoUniqueAddressDocs];
1760  let SimpleHandler = 1;
1761}
1762
1763def ReturnsTwice : InheritableAttr {
1764  let Spellings = [GCC<"returns_twice">];
1765  let Subjects = SubjectList<[Function]>;
1766  let Documentation = [Undocumented];
1767  let SimpleHandler = 1;
1768}
1769
1770def DisableTailCalls : InheritableAttr {
1771  let Spellings = [Clang<"disable_tail_calls">];
1772  let Subjects = SubjectList<[Function, ObjCMethod]>;
1773  let Documentation = [DisableTailCallsDocs];
1774  let SimpleHandler = 1;
1775}
1776def : MutualExclusions<[Naked, DisableTailCalls]>;
1777
1778def NoAlias : InheritableAttr {
1779  let Spellings = [Declspec<"noalias">];
1780  let Subjects = SubjectList<[Function]>;
1781  let Documentation = [NoAliasDocs];
1782  let SimpleHandler = 1;
1783}
1784
1785def NoCommon : InheritableAttr {
1786  let Spellings = [GCC<"nocommon">];
1787  let Subjects = SubjectList<[Var]>;
1788  let Documentation = [Undocumented];
1789  let SimpleHandler = 1;
1790}
1791
1792def NoDebug : InheritableAttr {
1793  let Spellings = [GCC<"nodebug">];
1794  let Subjects = SubjectList<[TypedefName, FunctionLike, ObjCMethod, NonParmVar]>;
1795  let Documentation = [NoDebugDocs];
1796}
1797
1798def StandaloneDebug : InheritableAttr {
1799  let Spellings = [Clang<"standalone_debug", /*allowInC =*/0>];
1800  let Subjects = SubjectList<[CXXRecord]>;
1801  let Documentation = [StandaloneDebugDocs];
1802  let SimpleHandler = 1;
1803  let LangOpts = [CPlusPlus];
1804}
1805
1806def NoDuplicate : InheritableAttr {
1807  let Spellings = [Clang<"noduplicate">];
1808  let Subjects = SubjectList<[Function]>;
1809  let Documentation = [NoDuplicateDocs];
1810  let SimpleHandler = 1;
1811}
1812
1813def Convergent : InheritableAttr {
1814  let Spellings = [Clang<"convergent">];
1815  let Subjects = SubjectList<[Function]>;
1816  let Documentation = [ConvergentDocs];
1817  let SimpleHandler = 1;
1818}
1819
1820def NoInline : DeclOrStmtAttr {
1821  let Spellings = [Keyword<"__noinline__">, GCC<"noinline">,
1822                   CXX11<"clang", "noinline">, C2x<"clang", "noinline">,
1823                   Declspec<"noinline">];
1824  let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
1825                                                C2x<"clang", "noinline">]>];
1826  let Documentation = [NoInlineDocs];
1827  let Subjects = SubjectList<[Function, Stmt], WarnDiag,
1828                             "functions and statements">;
1829  let SimpleHandler = 1;
1830}
1831
1832def NoMips16 : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1833  let Spellings = [GCC<"nomips16">];
1834  let Subjects = SubjectList<[Function], ErrorDiag>;
1835  let Documentation = [Undocumented];
1836  let SimpleHandler = 1;
1837}
1838
1839def NoMicroMips : InheritableAttr, TargetSpecificAttr<TargetMips32> {
1840  let Spellings = [GCC<"nomicromips">];
1841  let Subjects = SubjectList<[Function], ErrorDiag>;
1842  let Documentation = [MicroMipsDocs];
1843  let SimpleHandler = 1;
1844}
1845
1846def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
1847  let Spellings = [GCC<"interrupt">];
1848  let Subjects = SubjectList<[Function]>;
1849  let Args = [EnumArgument<"Interrupt", "InterruptType",
1850                           ["user", "supervisor", "machine"],
1851                           ["user", "supervisor", "machine"],
1852                           1>];
1853  let ParseKind = "Interrupt";
1854  let Documentation = [RISCVInterruptDocs];
1855}
1856
1857// This is not a TargetSpecificAttr so that is silently accepted and
1858// ignored on other targets as encouraged by the OpenCL spec.
1859//
1860// See OpenCL 1.2 6.11.5: "It is our intention that a particular
1861// implementation of OpenCL be free to ignore all attributes and the
1862// resulting executable binary will produce the same result."
1863//
1864// However, only AMD GPU targets will emit the corresponding IR
1865// attribute.
1866//
1867// FIXME: This provides a sub-optimal error message if you attempt to
1868// use this in CUDA, since CUDA does not use the same terminology.
1869//
1870// FIXME: SubjectList should be for OpenCLKernelFunction, but is not to
1871// workaround needing to see kernel attribute before others to know if
1872// this should be rejected on non-kernels.
1873
1874def AMDGPUFlatWorkGroupSize : InheritableAttr {
1875  let Spellings = [Clang<"amdgpu_flat_work_group_size", 0>];
1876  let Args = [ExprArgument<"Min">, ExprArgument<"Max">];
1877  let Documentation = [AMDGPUFlatWorkGroupSizeDocs];
1878  let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1879}
1880
1881def AMDGPUWavesPerEU : InheritableAttr {
1882  let Spellings = [Clang<"amdgpu_waves_per_eu", 0>];
1883  let Args = [ExprArgument<"Min">, ExprArgument<"Max", 1>];
1884  let Documentation = [AMDGPUWavesPerEUDocs];
1885  let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1886}
1887
1888def AMDGPUNumSGPR : InheritableAttr {
1889  let Spellings = [Clang<"amdgpu_num_sgpr", 0>];
1890  let Args = [UnsignedArgument<"NumSGPR">];
1891  let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1892  let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1893}
1894
1895def AMDGPUNumVGPR : InheritableAttr {
1896  let Spellings = [Clang<"amdgpu_num_vgpr", 0>];
1897  let Args = [UnsignedArgument<"NumVGPR">];
1898  let Documentation = [AMDGPUNumSGPRNumVGPRDocs];
1899  let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
1900}
1901
1902def AMDGPUKernelCall : DeclOrTypeAttr {
1903  let Spellings = [Clang<"amdgpu_kernel">];
1904  let Documentation = [Undocumented];
1905}
1906
1907def BPFPreserveAccessIndex : InheritableAttr,
1908                             TargetSpecificAttr<TargetBPF>  {
1909  let Spellings = [Clang<"preserve_access_index">];
1910  let Subjects = SubjectList<[Record], ErrorDiag>;
1911  let Documentation = [BPFPreserveAccessIndexDocs];
1912  let LangOpts = [COnly];
1913}
1914
1915def BTFDeclTag : InheritableAttr {
1916  let Spellings = [Clang<"btf_decl_tag">];
1917  let Args = [StringArgument<"BTFDeclTag">];
1918  let Subjects = SubjectList<[Var, Function, Record, Field, TypedefName],
1919                             ErrorDiag>;
1920  let Documentation = [BTFDeclTagDocs];
1921  let LangOpts = [COnly];
1922}
1923
1924def BTFTypeTag : TypeAttr {
1925  let Spellings = [Clang<"btf_type_tag">];
1926  let Args = [StringArgument<"BTFTypeTag">];
1927  let Documentation = [BTFTypeTagDocs];
1928  let LangOpts = [COnly];
1929}
1930
1931def WebAssemblyExportName : InheritableAttr,
1932                            TargetSpecificAttr<TargetWebAssembly> {
1933  let Spellings = [Clang<"export_name">];
1934  let Args = [StringArgument<"ExportName">];
1935  let Documentation = [WebAssemblyExportNameDocs];
1936  let Subjects = SubjectList<[Function], ErrorDiag>;
1937}
1938
1939def WebAssemblyImportModule : InheritableAttr,
1940                              TargetSpecificAttr<TargetWebAssembly> {
1941  let Spellings = [Clang<"import_module">];
1942  let Args = [StringArgument<"ImportModule">];
1943  let Documentation = [WebAssemblyImportModuleDocs];
1944  let Subjects = SubjectList<[Function], ErrorDiag>;
1945}
1946
1947def WebAssemblyImportName : InheritableAttr,
1948                            TargetSpecificAttr<TargetWebAssembly> {
1949  let Spellings = [Clang<"import_name">];
1950  let Args = [StringArgument<"ImportName">];
1951  let Documentation = [WebAssemblyImportNameDocs];
1952  let Subjects = SubjectList<[Function], ErrorDiag>;
1953}
1954
1955def NoSplitStack : InheritableAttr {
1956  let Spellings = [GCC<"no_split_stack">];
1957  let Subjects = SubjectList<[Function], ErrorDiag>;
1958  let Documentation = [NoSplitStackDocs];
1959  let SimpleHandler = 1;
1960}
1961
1962def NonNull : InheritableParamAttr {
1963  let Spellings = [GCC<"nonnull">];
1964  let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
1965                             "functions, methods, and parameters">;
1966  let Args = [VariadicParamIdxArgument<"Args">];
1967  let AdditionalMembers = [{
1968    bool isNonNull(unsigned IdxAST) const {
1969      if (!args_size())
1970        return true;
1971      return llvm::any_of(args(), [=](const ParamIdx &Idx) {
1972        return Idx.getASTIndex() == IdxAST;
1973      });
1974    }
1975  }];
1976  // FIXME: We should merge duplicates into a single nonnull attribute.
1977  let InheritEvenIfAlreadyPresent = 1;
1978  let Documentation = [NonNullDocs];
1979}
1980
1981def ReturnsNonNull : InheritableAttr {
1982  let Spellings = [GCC<"returns_nonnull">];
1983  let Subjects = SubjectList<[ObjCMethod, Function]>;
1984  let Documentation = [ReturnsNonNullDocs];
1985}
1986
1987def CalledOnce : Attr {
1988  let Spellings = [Clang<"called_once">];
1989  let Subjects = SubjectList<[ParmVar]>;
1990  let LangOpts = [ObjC];
1991  let Documentation = [CalledOnceDocs];
1992}
1993
1994// pass_object_size(N) indicates that the parameter should have
1995// __builtin_object_size with Type=N evaluated on the parameter at the callsite.
1996def PassObjectSize : InheritableParamAttr {
1997  let Spellings = [Clang<"pass_object_size">,
1998                   Clang<"pass_dynamic_object_size">];
1999  let Accessors = [Accessor<"isDynamic", [Clang<"pass_dynamic_object_size">]>];
2000  let Args = [IntArgument<"Type">];
2001  let Subjects = SubjectList<[ParmVar]>;
2002  let Documentation = [PassObjectSizeDocs];
2003}
2004
2005// Nullability type attributes.
2006def TypeNonNull : TypeAttr {
2007  let Spellings = [Keyword<"_Nonnull">];
2008  let Documentation = [TypeNonNullDocs];
2009}
2010
2011def TypeNullable : TypeAttr {
2012  let Spellings = [Keyword<"_Nullable">];
2013  let Documentation = [TypeNullableDocs];
2014}
2015
2016def TypeNullableResult : TypeAttr {
2017  let Spellings = [Keyword<"_Nullable_result">];
2018  let Documentation = [TypeNullableResultDocs];
2019}
2020
2021def TypeNullUnspecified : TypeAttr {
2022  let Spellings = [Keyword<"_Null_unspecified">];
2023  let Documentation = [TypeNullUnspecifiedDocs];
2024}
2025
2026// This is a marker used to indicate that an __unsafe_unretained qualifier was
2027// ignored because ARC is not enabled. The usual representation for this
2028// qualifier is as an ObjCOwnership attribute with Kind == "none".
2029def ObjCInertUnsafeUnretained : TypeAttr {
2030  let Spellings = [Keyword<"__unsafe_unretained">];
2031  let Documentation = [InternalOnly];
2032}
2033
2034def ObjCKindOf : TypeAttr {
2035  let Spellings = [Keyword<"__kindof">];
2036  let Documentation = [Undocumented];
2037}
2038
2039def NoEscape : Attr {
2040  let Spellings = [Clang<"noescape">];
2041  let Subjects = SubjectList<[ParmVar]>;
2042  let Documentation = [NoEscapeDocs];
2043}
2044
2045def MaybeUndef : InheritableAttr {
2046  let Spellings = [Clang<"maybe_undef">];
2047  let Subjects = SubjectList<[ParmVar]>;
2048  let Documentation = [MaybeUndefDocs];
2049  let SimpleHandler = 1;
2050}
2051
2052def AssumeAligned : InheritableAttr {
2053  let Spellings = [GCC<"assume_aligned">];
2054  let Subjects = SubjectList<[ObjCMethod, Function]>;
2055  let Args = [ExprArgument<"Alignment">, ExprArgument<"Offset", 1>];
2056  let Documentation = [AssumeAlignedDocs];
2057}
2058
2059def AllocAlign : InheritableAttr {
2060  let Spellings = [GCC<"alloc_align">];
2061  let Subjects = SubjectList<[HasFunctionProto]>;
2062  let Args = [ParamIdxArgument<"ParamIndex">];
2063  let Documentation = [AllocAlignDocs];
2064}
2065
2066def NoReturn : InheritableAttr {
2067  let Spellings = [GCC<"noreturn">, Declspec<"noreturn">];
2068  // FIXME: Does GCC allow this on the function instead?
2069  let Documentation = [Undocumented];
2070}
2071
2072def NoInstrumentFunction : InheritableAttr {
2073  let Spellings = [GCC<"no_instrument_function">];
2074  let Subjects = SubjectList<[Function, ObjCMethod]>;
2075  let Documentation = [Undocumented];
2076  let SimpleHandler = 1;
2077}
2078
2079def NoProfileFunction : InheritableAttr {
2080  let Spellings = [GCC<"no_profile_instrument_function">];
2081  let Subjects = SubjectList<[Function]>;
2082  let Documentation = [NoProfileInstrumentFunctionDocs];
2083  let SimpleHandler = 1;
2084}
2085
2086def NotTailCalled : InheritableAttr {
2087  let Spellings = [Clang<"not_tail_called">];
2088  let Subjects = SubjectList<[Function]>;
2089  let Documentation = [NotTailCalledDocs];
2090  let SimpleHandler = 1;
2091}
2092def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
2093
2094def NoStackProtector : InheritableAttr {
2095  let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
2096  let Subjects = SubjectList<[Function]>;
2097  let Documentation = [NoStackProtectorDocs];
2098  let SimpleHandler = 1;
2099}
2100
2101def StrictGuardStackCheck : InheritableAttr {
2102  let Spellings = [Declspec<"strict_gs_check">];
2103  let Subjects = SubjectList<[Function]>;
2104  let Documentation = [StrictGuardStackCheckDocs];
2105  let SimpleHandler = 1;
2106}
2107
2108def NoThrow : InheritableAttr {
2109  let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
2110  let Subjects = SubjectList<[FunctionLike]>;
2111  let Documentation = [NoThrowDocs];
2112}
2113
2114def NoUwtable : InheritableAttr {
2115  let Spellings = [Clang<"nouwtable">];
2116  let Subjects = SubjectList<[FunctionLike]>;
2117  let Documentation = [NoUwtableDocs];
2118  let SimpleHandler = 1;
2119}
2120
2121def NvWeak : IgnoredAttr {
2122  // No Declspec spelling of this attribute; the CUDA headers use
2123  // __attribute__((nv_weak)) unconditionally. Does not receive an [[]]
2124  // spelling because it is a CUDA attribute.
2125  let Spellings = [GNU<"nv_weak">];
2126  let LangOpts = [CUDA];
2127}
2128
2129def ObjCBridge : InheritableAttr {
2130  let Spellings = [Clang<"objc_bridge">];
2131  let Subjects = SubjectList<[Record, TypedefName], ErrorDiag>;
2132  let Args = [IdentifierArgument<"BridgedType">];
2133  let Documentation = [Undocumented];
2134}
2135
2136def ObjCBridgeMutable : InheritableAttr {
2137  let Spellings = [Clang<"objc_bridge_mutable">];
2138  let Subjects = SubjectList<[Record], ErrorDiag>;
2139  let Args = [IdentifierArgument<"BridgedType">];
2140  let Documentation = [Undocumented];
2141}
2142
2143def ObjCBridgeRelated : InheritableAttr {
2144  let Spellings = [Clang<"objc_bridge_related">];
2145  let Subjects = SubjectList<[Record], ErrorDiag>;
2146  let Args = [IdentifierArgument<"RelatedClass">,
2147          IdentifierArgument<"ClassMethod">,
2148          IdentifierArgument<"InstanceMethod">];
2149  let HasCustomParsing = 1;
2150  let Documentation = [Undocumented];
2151}
2152
2153def NSErrorDomain : InheritableAttr {
2154  let Spellings = [GNU<"ns_error_domain">];
2155  let Subjects = SubjectList<[Enum], ErrorDiag>;
2156  let Args = [DeclArgument<Var, "ErrorDomain">];
2157  let Documentation = [NSErrorDomainDocs];
2158}
2159
2160def NSReturnsRetained : DeclOrTypeAttr {
2161  let Spellings = [Clang<"ns_returns_retained">];
2162//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
2163  let Documentation = [RetainBehaviorDocs];
2164}
2165
2166def NSReturnsNotRetained : InheritableAttr {
2167  let Spellings = [Clang<"ns_returns_not_retained">];
2168//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
2169  let Documentation = [RetainBehaviorDocs];
2170}
2171
2172def NSReturnsAutoreleased : InheritableAttr {
2173  let Spellings = [Clang<"ns_returns_autoreleased">];
2174//  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
2175  let Documentation = [RetainBehaviorDocs];
2176}
2177
2178def NSConsumesSelf : InheritableAttr {
2179  let Spellings = [Clang<"ns_consumes_self">];
2180  let Subjects = SubjectList<[ObjCMethod]>;
2181  let Documentation = [RetainBehaviorDocs];
2182  let SimpleHandler = 1;
2183}
2184
2185def NSConsumed : InheritableParamAttr {
2186  let Spellings = [Clang<"ns_consumed">];
2187  let Subjects = SubjectList<[ParmVar]>;
2188  let Documentation = [RetainBehaviorDocs];
2189}
2190
2191def ObjCException : InheritableAttr {
2192  let Spellings = [Clang<"objc_exception">];
2193  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2194  let Documentation = [Undocumented];
2195  let SimpleHandler = 1;
2196}
2197
2198def ObjCMethodFamily : InheritableAttr {
2199  let Spellings = [Clang<"objc_method_family">];
2200  let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
2201  let Args = [EnumArgument<"Family", "FamilyKind",
2202               ["none", "alloc", "copy", "init", "mutableCopy", "new"],
2203               ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
2204                "OMF_mutableCopy", "OMF_new"]>];
2205  let Documentation = [ObjCMethodFamilyDocs];
2206}
2207
2208def ObjCNSObject : InheritableAttr {
2209  let Spellings = [Clang<"NSObject">];
2210  let Documentation = [Undocumented];
2211}
2212
2213def ObjCIndependentClass : InheritableAttr {
2214  let Spellings = [Clang<"objc_independent_class">];
2215  let Documentation = [Undocumented];
2216}
2217
2218def ObjCPreciseLifetime : InheritableAttr {
2219  let Spellings = [Clang<"objc_precise_lifetime">];
2220  let Subjects = SubjectList<[Var], ErrorDiag>;
2221  let Documentation = [Undocumented];
2222}
2223
2224def ObjCReturnsInnerPointer : InheritableAttr {
2225  let Spellings = [Clang<"objc_returns_inner_pointer">];
2226  let Subjects = SubjectList<[ObjCMethod, ObjCProperty], ErrorDiag>;
2227  let Documentation = [Undocumented];
2228}
2229
2230def ObjCRequiresSuper : InheritableAttr {
2231  let Spellings = [Clang<"objc_requires_super">];
2232  let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
2233  let Documentation = [ObjCRequiresSuperDocs];
2234}
2235
2236def ObjCRootClass : InheritableAttr {
2237  let Spellings = [Clang<"objc_root_class">];
2238  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2239  let Documentation = [Undocumented];
2240  let SimpleHandler = 1;
2241}
2242
2243def ObjCNonLazyClass : Attr {
2244  let Spellings = [Clang<"objc_nonlazy_class">];
2245  let Subjects = SubjectList<[ObjCInterface, ObjCImpl], ErrorDiag>;
2246  let LangOpts = [ObjC];
2247  let Documentation = [ObjCNonLazyClassDocs];
2248  let SimpleHandler = 1;
2249}
2250
2251def ObjCSubclassingRestricted : InheritableAttr {
2252  let Spellings = [Clang<"objc_subclassing_restricted">];
2253  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2254  let Documentation = [ObjCSubclassingRestrictedDocs];
2255  let SimpleHandler = 1;
2256}
2257
2258def ObjCExplicitProtocolImpl : InheritableAttr {
2259  let Spellings = [Clang<"objc_protocol_requires_explicit_implementation">];
2260  let Subjects = SubjectList<[ObjCProtocol], ErrorDiag>;
2261  let Documentation = [Undocumented];
2262}
2263
2264def ObjCDesignatedInitializer : Attr {
2265  let Spellings = [Clang<"objc_designated_initializer">];
2266  let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
2267  let Documentation = [Undocumented];
2268}
2269
2270def ObjCDirect : Attr {
2271  let Spellings = [Clang<"objc_direct">];
2272  let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
2273  let LangOpts = [ObjC];
2274  let Documentation = [ObjCDirectDocs];
2275}
2276
2277def ObjCDirectMembers : Attr {
2278  let Spellings = [Clang<"objc_direct_members">];
2279  let Subjects = SubjectList<[ObjCImpl, ObjCInterface, ObjCCategory], ErrorDiag>;
2280  let LangOpts = [ObjC];
2281  let Documentation = [ObjCDirectMembersDocs];
2282}
2283
2284def ObjCNonRuntimeProtocol : Attr {
2285  let Spellings = [Clang<"objc_non_runtime_protocol">];
2286  let Subjects = SubjectList<[ObjCProtocol], ErrorDiag>;
2287  let LangOpts = [ObjC];
2288  let Documentation = [ObjCNonRuntimeProtocolDocs];
2289  let SimpleHandler = 1;
2290}
2291
2292def ObjCRuntimeName : Attr {
2293  let Spellings = [Clang<"objc_runtime_name">];
2294  let Subjects = SubjectList<[ObjCInterface, ObjCProtocol], ErrorDiag>;
2295  let Args = [StringArgument<"MetadataName">];
2296  let Documentation = [ObjCRuntimeNameDocs];
2297}
2298
2299def ObjCRuntimeVisible : Attr {
2300  let Spellings = [Clang<"objc_runtime_visible">];
2301  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2302  let Documentation = [ObjCRuntimeVisibleDocs];
2303  let SimpleHandler = 1;
2304}
2305
2306def ObjCClassStub : Attr {
2307  let Spellings = [Clang<"objc_class_stub">];
2308  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2309  let Documentation = [ObjCClassStubDocs];
2310  let LangOpts = [ObjCNonFragileRuntime];
2311  let SimpleHandler = 1;
2312}
2313
2314def ObjCBoxable : Attr {
2315  let Spellings = [Clang<"objc_boxable">];
2316  let Subjects = SubjectList<[Record], ErrorDiag>;
2317  let Documentation = [ObjCBoxableDocs];
2318}
2319
2320def OptimizeNone : InheritableAttr {
2321  let Spellings = [Clang<"optnone">];
2322  let Subjects = SubjectList<[Function, ObjCMethod]>;
2323  let Documentation = [OptnoneDocs];
2324}
2325
2326def Overloadable : Attr {
2327  let Spellings = [Clang<"overloadable">];
2328  let Subjects = SubjectList<[Function], ErrorDiag>;
2329  let Documentation = [OverloadableDocs];
2330  let SimpleHandler = 1;
2331}
2332
2333def Override : InheritableAttr {
2334  let Spellings = [Keyword<"override">];
2335  let SemaHandler = 0;
2336  // Omitted from docs, since this is language syntax, not an attribute, as far
2337  // as users are concerned.
2338  let Documentation = [InternalOnly];
2339}
2340
2341def Ownership : InheritableAttr {
2342  let Spellings = [Clang<"ownership_holds">, Clang<"ownership_returns">,
2343                   Clang<"ownership_takes">];
2344  let Accessors = [Accessor<"isHolds", [Clang<"ownership_holds">]>,
2345                   Accessor<"isReturns", [Clang<"ownership_returns">]>,
2346                   Accessor<"isTakes", [Clang<"ownership_takes">]>];
2347  let AdditionalMembers = [{
2348    enum OwnershipKind { Holds, Returns, Takes };
2349    OwnershipKind getOwnKind() const {
2350      return isHolds() ? Holds :
2351             isTakes() ? Takes :
2352             Returns;
2353    }
2354  }];
2355  let Args = [IdentifierArgument<"Module">,
2356              VariadicParamIdxArgument<"Args">];
2357  let Subjects = SubjectList<[HasFunctionProto]>;
2358  let Documentation = [Undocumented];
2359}
2360
2361def Packed : InheritableAttr {
2362  let Spellings = [GCC<"packed">];
2363//  let Subjects = [Tag, Field];
2364  let Documentation = [Undocumented];
2365}
2366
2367def IntelOclBicc : DeclOrTypeAttr {
2368  let Spellings = [Clang<"intel_ocl_bicc", 0>];
2369//  let Subjects = [Function, ObjCMethod];
2370  let Documentation = [Undocumented];
2371}
2372
2373def Pcs : DeclOrTypeAttr {
2374  let Spellings = [GCC<"pcs">];
2375  let Args = [EnumArgument<"PCS", "PCSType",
2376                           ["aapcs", "aapcs-vfp"],
2377                           ["AAPCS", "AAPCS_VFP"]>];
2378//  let Subjects = [Function, ObjCMethod];
2379  let Documentation = [PcsDocs];
2380}
2381
2382def AArch64VectorPcs: DeclOrTypeAttr {
2383  let Spellings = [Clang<"aarch64_vector_pcs">];
2384  let Documentation = [AArch64VectorPcsDocs];
2385}
2386
2387def AArch64SVEPcs: DeclOrTypeAttr {
2388  let Spellings = [Clang<"aarch64_sve_pcs">];
2389  let Documentation = [AArch64SVEPcsDocs];
2390}
2391
2392def Pure : InheritableAttr {
2393  let Spellings = [GCC<"pure">];
2394  let Documentation = [Undocumented];
2395  let SimpleHandler = 1;
2396}
2397
2398def Regparm : TypeAttr {
2399  let Spellings = [GCC<"regparm">];
2400  let Args = [UnsignedArgument<"NumParams">];
2401  let Documentation = [RegparmDocs];
2402  // Represented as part of the enclosing function type.
2403  let ASTNode = 0;
2404}
2405
2406def SwiftAsyncName : InheritableAttr {
2407  let Spellings = [GNU<"swift_async_name">];
2408  let Args = [StringArgument<"Name">];
2409  let Subjects = SubjectList<[ObjCMethod, Function], ErrorDiag>;
2410  let Documentation = [SwiftAsyncNameDocs];
2411}
2412
2413def SwiftAttr : InheritableAttr {
2414  let Spellings = [GNU<"swift_attr">];
2415  let Args = [StringArgument<"Attribute">];
2416  let Documentation = [SwiftAttrDocs];
2417  let PragmaAttributeSupport = 1;
2418}
2419
2420def SwiftBridge : InheritableAttr {
2421  let Spellings = [GNU<"swift_bridge">];
2422  let Args = [StringArgument<"SwiftType">];
2423  let Subjects = SubjectList<[Tag, TypedefName, ObjCInterface, ObjCProtocol],
2424                             ErrorDiag>;
2425  let Documentation = [SwiftBridgeDocs];
2426}
2427
2428def SwiftBridgedTypedef : InheritableAttr {
2429  let Spellings = [GNU<"swift_bridged_typedef">];
2430  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
2431  let Documentation = [SwiftBridgedTypedefDocs];
2432  let SimpleHandler = 1;
2433}
2434
2435def SwiftObjCMembers : Attr {
2436  let Spellings = [GNU<"swift_objc_members">];
2437  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2438  let Documentation = [SwiftObjCMembersDocs];
2439  let SimpleHandler = 1;
2440}
2441
2442def SwiftError : InheritableAttr {
2443  let Spellings = [GNU<"swift_error">];
2444  let Args = [
2445      EnumArgument<"Convention", "ConventionKind",
2446                   ["none", "nonnull_error", "null_result", "zero_result", "nonzero_result"],
2447                   ["None", "NonNullError", "NullResult", "ZeroResult", "NonZeroResult"]>
2448  ];
2449  let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
2450  let Documentation = [SwiftErrorDocs];
2451}
2452
2453def SwiftName : InheritableAttr {
2454  let Spellings = [GNU<"swift_name">];
2455  let Args = [StringArgument<"Name">];
2456  let Documentation = [SwiftNameDocs];
2457}
2458
2459def SwiftNewType : InheritableAttr {
2460  let Spellings = [GNU<"swift_newtype">, GNU<"swift_wrapper">];
2461  let Args = [EnumArgument<"NewtypeKind", "NewtypeKind",
2462                           ["struct", "enum"], ["NK_Struct", "NK_Enum"]>];
2463  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
2464  let Documentation = [SwiftNewTypeDocs];
2465  let HasCustomParsing = 1;
2466}
2467
2468def SwiftPrivate : InheritableAttr {
2469  let Spellings = [GNU<"swift_private">];
2470  let Documentation = [SwiftPrivateDocs];
2471  let SimpleHandler = 1;
2472}
2473
2474def NoDeref : TypeAttr {
2475  let Spellings = [Clang<"noderef">];
2476  let Documentation = [NoDerefDocs];
2477}
2478
2479def ReqdWorkGroupSize : InheritableAttr {
2480  // Does not have a [[]] spelling because it is an OpenCL-related attribute.
2481  let Spellings = [GNU<"reqd_work_group_size">];
2482  let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
2483              UnsignedArgument<"ZDim">];
2484  let Subjects = SubjectList<[Function], ErrorDiag>;
2485  let Documentation = [Undocumented];
2486}
2487
2488def WorkGroupSizeHint :  InheritableAttr {
2489  // Does not have a [[]] spelling because it is an OpenCL-related attribute.
2490  let Spellings = [GNU<"work_group_size_hint">];
2491  let Args = [UnsignedArgument<"XDim">,
2492              UnsignedArgument<"YDim">,
2493              UnsignedArgument<"ZDim">];
2494  let Subjects = SubjectList<[Function], ErrorDiag>;
2495  let Documentation = [Undocumented];
2496}
2497
2498def InitPriority : InheritableAttr, TargetSpecificAttr<TargetSupportsInitPriority> {
2499  let Spellings = [GCC<"init_priority", /*AllowInC*/0>];
2500  let Args = [UnsignedArgument<"Priority">];
2501  let Subjects = SubjectList<[Var], ErrorDiag>;
2502  let Documentation = [InitPriorityDocs];
2503}
2504
2505def Section : InheritableAttr {
2506  let Spellings = [GCC<"section">, Declspec<"allocate">];
2507  let Args = [StringArgument<"Name">];
2508  let Subjects =
2509      SubjectList<[ Function, GlobalVar, ObjCMethod, ObjCProperty ], ErrorDiag>;
2510  let Documentation = [SectionDocs];
2511}
2512
2513// This is used for `__declspec(code_seg("segname"))`, but not for
2514// `#pragma code_seg("segname")`.
2515def CodeSeg : InheritableAttr {
2516  let Spellings = [Declspec<"code_seg">];
2517  let Args = [StringArgument<"Name">];
2518  let Subjects = SubjectList<[Function, CXXRecord], ErrorDiag>;
2519  let Documentation = [CodeSegDocs];
2520}
2521
2522def PragmaClangBSSSection : InheritableAttr {
2523  // This attribute has no spellings as it is only ever created implicitly.
2524  let Spellings = [];
2525  let Args = [StringArgument<"Name">];
2526  let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2527  let Documentation = [InternalOnly];
2528}
2529
2530def PragmaClangDataSection : InheritableAttr {
2531  // This attribute has no spellings as it is only ever created implicitly.
2532  let Spellings = [];
2533  let Args = [StringArgument<"Name">];
2534  let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2535  let Documentation = [InternalOnly];
2536}
2537
2538def PragmaClangRodataSection : InheritableAttr {
2539  // This attribute has no spellings as it is only ever created implicitly.
2540  let Spellings = [];
2541  let Args = [StringArgument<"Name">];
2542  let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2543  let Documentation = [InternalOnly];
2544}
2545
2546def PragmaClangRelroSection : InheritableAttr {
2547  // This attribute has no spellings as it is only ever created implicitly.
2548  let Spellings = [];
2549  let Args = [StringArgument<"Name">];
2550  let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
2551  let Documentation = [InternalOnly];
2552}
2553
2554def StrictFP : InheritableAttr {
2555  // This attribute has no spellings as it is only ever created implicitly.
2556  // Function uses strict floating point operations.
2557  let Spellings = [];
2558  let Subjects = SubjectList<[Function]>;
2559  let Documentation = [InternalOnly];
2560}
2561
2562def PragmaClangTextSection : InheritableAttr {
2563  // This attribute has no spellings as it is only ever created implicitly.
2564  let Spellings = [];
2565  let Args = [StringArgument<"Name">];
2566  let Subjects = SubjectList<[Function], ErrorDiag>;
2567  let Documentation = [InternalOnly];
2568}
2569
2570def Sentinel : InheritableAttr {
2571  let Spellings = [GCC<"sentinel">];
2572  let Args = [DefaultIntArgument<"Sentinel", 0>,
2573              DefaultIntArgument<"NullPos", 0>];
2574//  let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>;
2575  let Documentation = [Undocumented];
2576}
2577
2578def StdCall : DeclOrTypeAttr {
2579  let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
2580//  let Subjects = [Function, ObjCMethod];
2581  let Documentation = [StdCallDocs];
2582}
2583
2584def SwiftCall : DeclOrTypeAttr {
2585  let Spellings = [Clang<"swiftcall">];
2586//  let Subjects = SubjectList<[Function]>;
2587  let Documentation = [SwiftCallDocs];
2588}
2589
2590def SwiftAsyncCall : DeclOrTypeAttr {
2591  let Spellings = [Clang<"swiftasynccall">];
2592  let Documentation = [SwiftAsyncCallDocs];
2593}
2594
2595def SwiftContext : ParameterABIAttr {
2596  let Spellings = [Clang<"swift_context">];
2597  let Documentation = [SwiftContextDocs];
2598}
2599
2600def SwiftAsyncContext : ParameterABIAttr {
2601  let Spellings = [Clang<"swift_async_context">];
2602  let Documentation = [SwiftAsyncContextDocs];
2603}
2604
2605def SwiftErrorResult : ParameterABIAttr {
2606  let Spellings = [Clang<"swift_error_result">];
2607  let Documentation = [SwiftErrorResultDocs];
2608}
2609
2610def SwiftIndirectResult : ParameterABIAttr {
2611  let Spellings = [Clang<"swift_indirect_result">];
2612  let Documentation = [SwiftIndirectResultDocs];
2613}
2614
2615def SwiftAsync : InheritableAttr {
2616  let Spellings = [Clang<"swift_async">];
2617  let Subjects = SubjectList<[Function, ObjCMethod]>;
2618  let Args = [EnumArgument<"Kind", "Kind",
2619                ["none", "swift_private", "not_swift_private"],
2620                ["None", "SwiftPrivate", "NotSwiftPrivate"]>,
2621              ParamIdxArgument<"CompletionHandlerIndex", /*opt=*/1>];
2622  let Documentation = [SwiftAsyncDocs];
2623}
2624
2625def SwiftAsyncError : InheritableAttr {
2626  let Spellings = [Clang<"swift_async_error">];
2627  let Subjects = SubjectList<[Function, ObjCMethod]>;
2628  let Args = [EnumArgument<"Convention", "ConventionKind",
2629              ["none", "nonnull_error", "zero_argument", "nonzero_argument"],
2630              ["None", "NonNullError", "ZeroArgument", "NonZeroArgument"]>,
2631              UnsignedArgument<"HandlerParamIdx", /*opt=*/1>];
2632  let Documentation = [SwiftAsyncErrorDocs];
2633}
2634
2635def Suppress : StmtAttr {
2636  let Spellings = [CXX11<"gsl", "suppress">];
2637  let Args = [VariadicStringArgument<"DiagnosticIdentifiers">];
2638  let Documentation = [SuppressDocs];
2639}
2640
2641def SysVABI : DeclOrTypeAttr {
2642  let Spellings = [GCC<"sysv_abi">];
2643//  let Subjects = [Function, ObjCMethod];
2644  let Documentation = [Undocumented];
2645}
2646
2647def ThisCall : DeclOrTypeAttr {
2648  let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
2649                   Keyword<"_thiscall">];
2650//  let Subjects = [Function, ObjCMethod];
2651  let Documentation = [ThisCallDocs];
2652}
2653
2654def VectorCall : DeclOrTypeAttr {
2655  let Spellings = [Clang<"vectorcall">, Keyword<"__vectorcall">,
2656                   Keyword<"_vectorcall">];
2657//  let Subjects = [Function, ObjCMethod];
2658  let Documentation = [VectorCallDocs];
2659}
2660
2661def ZeroCallUsedRegs : InheritableAttr {
2662  let Spellings = [GCC<"zero_call_used_regs">];
2663  let Subjects = SubjectList<[Function], ErrorDiag>;
2664  let Args = [
2665    EnumArgument<"ZeroCallUsedRegs", "ZeroCallUsedRegsKind",
2666                 ["skip", "used-gpr-arg", "used-gpr", "used-arg", "used",
2667                  "all-gpr-arg", "all-gpr", "all-arg", "all"],
2668                 ["Skip", "UsedGPRArg", "UsedGPR", "UsedArg", "Used",
2669                  "AllGPRArg", "AllGPR", "AllArg", "All"]>
2670  ];
2671  let Documentation = [ZeroCallUsedRegsDocs];
2672}
2673
2674def Pascal : DeclOrTypeAttr {
2675  let Spellings = [Clang<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
2676//  let Subjects = [Function, ObjCMethod];
2677  let Documentation = [Undocumented];
2678}
2679
2680def PreferredName : InheritableAttr {
2681  let Spellings = [Clang<"preferred_name", /*AllowInC*/0>];
2682  let Subjects = SubjectList<[ClassTmpl]>;
2683  let Args = [TypeArgument<"TypedefType">];
2684  let Documentation = [PreferredNameDocs];
2685  let InheritEvenIfAlreadyPresent = 1;
2686  let MeaningfulToClassTemplateDefinition = 1;
2687  let TemplateDependent = 1;
2688}
2689
2690def PreserveMost : DeclOrTypeAttr {
2691  let Spellings = [Clang<"preserve_most">];
2692  let Documentation = [PreserveMostDocs];
2693}
2694
2695def PreserveAll : DeclOrTypeAttr {
2696  let Spellings = [Clang<"preserve_all">];
2697  let Documentation = [PreserveAllDocs];
2698}
2699
2700def Target : InheritableAttr {
2701  let Spellings = [GCC<"target">];
2702  let Args = [StringArgument<"featuresStr">];
2703  let Subjects = SubjectList<[Function], ErrorDiag>;
2704  let Documentation = [TargetDocs];
2705  let AdditionalMembers = [{
2706    StringRef getArchitecture() const {
2707      StringRef Features = getFeaturesStr();
2708      if (Features == "default") return {};
2709
2710      SmallVector<StringRef, 1> AttrFeatures;
2711      Features.split(AttrFeatures, ",");
2712
2713      for (auto &Feature : AttrFeatures) {
2714        Feature = Feature.trim();
2715        if (Feature.startswith("arch="))
2716          return Feature.drop_front(sizeof("arch=") - 1);
2717      }
2718      return "";
2719    }
2720
2721    // Gets the list of features as simple string-refs with no +/- or 'no-'.
2722    // Only adds the items to 'Out' that are additions.
2723    void getAddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
2724      StringRef Features = getFeaturesStr();
2725      if (Features == "default") return;
2726
2727      SmallVector<StringRef, 1> AttrFeatures;
2728      Features.split(AttrFeatures, ",");
2729
2730      for (auto &Feature : AttrFeatures) {
2731        Feature = Feature.trim();
2732
2733        if (!Feature.startswith("no-") && !Feature.startswith("arch=") &&
2734            !Feature.startswith("fpmath=") && !Feature.startswith("tune="))
2735          Out.push_back(Feature);
2736      }
2737    }
2738
2739    bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
2740  }];
2741}
2742
2743def TargetVersion : InheritableAttr {
2744  let Spellings = [GCC<"target_version">];
2745  let Args = [StringArgument<"NamesStr">];
2746  let Subjects = SubjectList<[Function], ErrorDiag>;
2747  let Documentation = [TargetVersionDocs];
2748  let AdditionalMembers = [{
2749    StringRef getName() const { return getNamesStr().trim(); }
2750    bool isDefaultVersion() const {
2751      return getName() == "default";
2752    }
2753    void getFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
2754      if (isDefaultVersion()) return;
2755      StringRef Features = getName();
2756
2757      SmallVector<StringRef, 8> AttrFeatures;
2758      Features.split(AttrFeatures, "+");
2759
2760      for (auto &Feature : AttrFeatures) {
2761        Feature = Feature.trim();
2762        Out.push_back(Feature);
2763      }
2764    }
2765  }];
2766}
2767
2768def TargetClones : InheritableAttr {
2769  let Spellings = [GCC<"target_clones">];
2770  let Args = [VariadicStringArgument<"featuresStrs">];
2771  let Documentation = [TargetClonesDocs];
2772  let Subjects = SubjectList<[Function], ErrorDiag>;
2773  let AdditionalMembers = [{
2774    StringRef getFeatureStr(unsigned Index) const {
2775      return *(featuresStrs_begin() + Index);
2776    }
2777    // Given an index into the 'featuresStrs' sequence, compute a unique
2778    // ID to be used with function name mangling for the associated variant.
2779    // This mapping is necessary due to a requirement that the mangling ID
2780    // used for the "default" variant be the largest mangling ID in the
2781    // variant set. Duplicate variants present in 'featuresStrs' are also
2782    // assigned their own unique ID (the mapping is bijective).
2783    unsigned getMangledIndex(unsigned Index) const {
2784      if (getFeatureStr(Index) == "default")
2785        return std::count_if(featuresStrs_begin(), featuresStrs_end(),
2786                              [](StringRef S) { return S != "default"; });
2787
2788      return std::count_if(featuresStrs_begin(), featuresStrs_begin() + Index,
2789                           [](StringRef S) { return S != "default"; });
2790    }
2791
2792    // Given an index into the 'featuresStrs' sequence, determine if the
2793    // index corresponds to the first instance of the named variant. This
2794    // is used to skip over duplicate variant instances when iterating over
2795    // 'featuresStrs'.
2796    bool isFirstOfVersion(unsigned Index) const {
2797      StringRef FeatureStr(getFeatureStr(Index));
2798      return 0 == std::count_if(
2799                      featuresStrs_begin(), featuresStrs_begin() + Index,
2800                      [FeatureStr](StringRef S) { return S == FeatureStr; });
2801
2802    }
2803  }];
2804}
2805
2806def : MutualExclusions<[TargetClones, TargetVersion, Target, CPUDispatch, CPUSpecific]>;
2807
2808def MinVectorWidth : InheritableAttr {
2809  let Spellings = [Clang<"min_vector_width">];
2810  let Args = [UnsignedArgument<"VectorWidth">];
2811  let Subjects = SubjectList<[Function], ErrorDiag>;
2812  let Documentation = [MinVectorWidthDocs];
2813}
2814
2815def TransparentUnion : InheritableAttr {
2816  let Spellings = [GCC<"transparent_union">];
2817//  let Subjects = SubjectList<[Record, TypedefName]>;
2818  let Documentation = [TransparentUnionDocs];
2819  let LangOpts = [COnly];
2820}
2821
2822def Unavailable : InheritableAttr {
2823  let Spellings = [Clang<"unavailable">];
2824  let Args = [StringArgument<"Message", 1>,
2825              EnumArgument<"ImplicitReason", "ImplicitReason",
2826                ["", "", "", ""],
2827                ["IR_None",
2828                 "IR_ARCForbiddenType",
2829                 "IR_ForbiddenWeak",
2830                 "IR_ARCForbiddenConversion",
2831                 "IR_ARCInitReturnsUnrelated",
2832                 "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
2833  let Documentation = [Undocumented];
2834}
2835
2836def DiagnoseIf : InheritableAttr {
2837  // Does not have a [[]] spelling because this attribute requires the ability
2838  // to parse function arguments but the attribute is not written in the type
2839  // position.
2840  let Spellings = [GNU<"diagnose_if">];
2841  let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
2842  let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
2843              EnumArgument<"DiagnosticType",
2844                           "DiagnosticType",
2845                           ["error", "warning"],
2846                           ["DT_Error", "DT_Warning"]>,
2847              BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
2848              DeclArgument<Named, "Parent", 0, /*fake*/ 1>];
2849  let InheritEvenIfAlreadyPresent = 1;
2850  let LateParsed = 1;
2851  let AdditionalMembers = [{
2852    bool isError() const { return diagnosticType == DT_Error; }
2853    bool isWarning() const { return diagnosticType == DT_Warning; }
2854  }];
2855  let TemplateDependent = 1;
2856  let Documentation = [DiagnoseIfDocs];
2857}
2858
2859def ArcWeakrefUnavailable : InheritableAttr {
2860  let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
2861  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2862  let Documentation = [Undocumented];
2863  let SimpleHandler = 1;
2864}
2865
2866def ObjCGC : TypeAttr {
2867  let Spellings = [Clang<"objc_gc">];
2868  let Args = [IdentifierArgument<"Kind">];
2869  let Documentation = [Undocumented];
2870}
2871
2872def ObjCOwnership : DeclOrTypeAttr {
2873  let Spellings = [Clang<"objc_ownership">];
2874  let Args = [IdentifierArgument<"Kind">];
2875  let Documentation = [Undocumented];
2876}
2877
2878def ObjCRequiresPropertyDefs : InheritableAttr {
2879  let Spellings = [Clang<"objc_requires_property_definitions">];
2880  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
2881  let Documentation = [Undocumented];
2882  let SimpleHandler = 1;
2883}
2884
2885def Unused : InheritableAttr {
2886  let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">,
2887                   C2x<"", "maybe_unused", 202106>];
2888  let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
2889                              Field, ObjCMethod, FunctionLike]>;
2890  let Documentation = [WarnMaybeUnusedDocs];
2891}
2892
2893def Used : InheritableAttr {
2894  let Spellings = [GCC<"used">];
2895  let Subjects = SubjectList<[NonLocalVar, Function, ObjCMethod]>;
2896  let Documentation = [UsedDocs];
2897  let SimpleHandler = 1;
2898}
2899
2900def Retain : InheritableAttr {
2901  let Spellings = [GCC<"retain">];
2902  let Subjects = SubjectList<[NonLocalVar, Function, ObjCMethod]>;
2903  let Documentation = [RetainDocs];
2904  let SimpleHandler = 1;
2905}
2906
2907def Uuid : InheritableAttr {
2908  let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
2909  let Args = [StringArgument<"Guid">,
2910              DeclArgument<MSGuid, "GuidDecl", 0, /*fake=*/1>];
2911  let Subjects = SubjectList<[Record, Enum]>;
2912  // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
2913  // CPlusPlus && (MicrosoftExt || Borland)
2914  let LangOpts = [MicrosoftExt, Borland];
2915  let Documentation = [Undocumented];
2916}
2917
2918def VectorSize : TypeAttr {
2919  let Spellings = [GCC<"vector_size">];
2920  let Args = [ExprArgument<"NumBytes">];
2921  let Documentation = [Undocumented];
2922  // Represented as VectorType instead.
2923  let ASTNode = 0;
2924}
2925
2926def VecTypeHint : InheritableAttr {
2927  // Does not have a [[]] spelling because it is an OpenCL-related attribute.
2928  let Spellings = [GNU<"vec_type_hint">];
2929  let Args = [TypeArgument<"TypeHint">];
2930  let Subjects = SubjectList<[Function], ErrorDiag>;
2931  let Documentation = [Undocumented];
2932}
2933
2934def MatrixType : TypeAttr {
2935  let Spellings = [Clang<"matrix_type">];
2936  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
2937  let Args = [ExprArgument<"NumRows">, ExprArgument<"NumColumns">];
2938  let Documentation = [Undocumented];
2939  let ASTNode = 0;
2940  let PragmaAttributeSupport = 0;
2941}
2942
2943def Visibility : InheritableAttr {
2944  let Clone = 0;
2945  let Spellings = [GCC<"visibility">];
2946  let Args = [EnumArgument<"Visibility", "VisibilityType",
2947                           ["default", "hidden", "internal", "protected"],
2948                           ["Default", "Hidden", "Hidden", "Protected"]>];
2949  let MeaningfulToClassTemplateDefinition = 1;
2950  let Documentation = [Undocumented];
2951}
2952
2953def TypeVisibility : InheritableAttr {
2954  let Clone = 0;
2955  let Spellings = [Clang<"type_visibility">];
2956  let Args = [EnumArgument<"Visibility", "VisibilityType",
2957                           ["default", "hidden", "internal", "protected"],
2958                           ["Default", "Hidden", "Hidden", "Protected"]>];
2959//  let Subjects = [Tag, ObjCInterface, Namespace];
2960  let Documentation = [Undocumented];
2961}
2962
2963def VecReturn : InheritableAttr {
2964  // This attribute does not have a C [[]] spelling because it only appertains
2965  // to C++ struct/class/union.
2966  // FIXME: should this attribute have a CPlusPlus language option?
2967  let Spellings = [Clang<"vecreturn", 0>];
2968  let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
2969  let Documentation = [Undocumented];
2970}
2971
2972def WarnUnused : InheritableAttr {
2973  let Spellings = [GCC<"warn_unused">];
2974  let Subjects = SubjectList<[Record]>;
2975  let Documentation = [Undocumented];
2976  let SimpleHandler = 1;
2977}
2978
2979def WarnUnusedResult : InheritableAttr {
2980  let Spellings = [CXX11<"", "nodiscard", 201907>,
2981                   C2x<"", "nodiscard", 202003>,
2982                   CXX11<"clang", "warn_unused_result">,
2983                   GCC<"warn_unused_result">];
2984  let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike, TypedefName]>;
2985  let Args = [StringArgument<"Message", 1>];
2986  let Documentation = [WarnUnusedResultsDocs];
2987  let AdditionalMembers = [{
2988    // Check whether this the C++11 nodiscard version, even in non C++11
2989    // spellings.
2990    bool IsCXX11NoDiscard() const {
2991      return this->getSemanticSpelling() == CXX11_nodiscard;
2992    }
2993  }];
2994}
2995
2996def Weak : InheritableAttr {
2997  let Spellings = [GCC<"weak">];
2998  let Subjects = SubjectList<[Var, Function, CXXRecord]>;
2999  let Documentation = [WeakDocs];
3000  let SimpleHandler = 1;
3001}
3002
3003def WeakImport : InheritableAttr {
3004  let Spellings = [Clang<"weak_import">];
3005  let Documentation = [Undocumented];
3006}
3007
3008def WeakRef : InheritableAttr {
3009  let Spellings = [GCC<"weakref">];
3010  // A WeakRef that has an argument is treated as being an AliasAttr
3011  let Args = [StringArgument<"Aliasee", 1>];
3012  let Subjects = SubjectList<[Var, Function], ErrorDiag>;
3013  let Documentation = [Undocumented];
3014}
3015
3016def LTOVisibilityPublic : InheritableAttr {
3017  let Spellings = [Clang<"lto_visibility_public">];
3018  let Subjects = SubjectList<[Record]>;
3019  let Documentation = [LTOVisibilityDocs];
3020  let SimpleHandler = 1;
3021}
3022
3023def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
3024  // NOTE: If you add any additional spellings, ARMInterrupt's,
3025  // M68kInterrupt's, MSP430Interrupt's and MipsInterrupt's spellings must match.
3026  let Spellings = [GCC<"interrupt">];
3027  let Subjects = SubjectList<[HasFunctionProto]>;
3028  let ParseKind = "Interrupt";
3029  let HasCustomParsing = 1;
3030  let Documentation = [Undocumented];
3031}
3032
3033def AnyX86NoCallerSavedRegisters : InheritableAttr,
3034                                   TargetSpecificAttr<TargetAnyX86> {
3035  let Spellings = [GCC<"no_caller_saved_registers">];
3036  let Documentation = [AnyX86NoCallerSavedRegistersDocs];
3037  let SimpleHandler = 1;
3038}
3039
3040def AnyX86NoCfCheck : DeclOrTypeAttr, TargetSpecificAttr<TargetAnyX86>{
3041  let Spellings = [GCC<"nocf_check">];
3042  let Subjects = SubjectList<[FunctionLike]>;
3043  let Documentation = [AnyX86NoCfCheckDocs];
3044}
3045
3046def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
3047  let Spellings = [GCC<"force_align_arg_pointer">];
3048  // Technically, this appertains to a FunctionDecl, but the target-specific
3049  // code silently allows anything function-like (such as typedefs or function
3050  // pointers), but does not apply the attribute to them.
3051  let Documentation = [X86ForceAlignArgPointerDocs];
3052}
3053
3054def NoSanitize : InheritableAttr {
3055  let Spellings = [Clang<"no_sanitize">];
3056  let Args = [VariadicStringArgument<"Sanitizers">];
3057  let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag>;
3058  let Documentation = [NoSanitizeDocs];
3059  let AdditionalMembers = [{
3060    SanitizerMask getMask() const {
3061      SanitizerMask Mask;
3062      for (auto SanitizerName : sanitizers()) {
3063        SanitizerMask ParsedMask =
3064            parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
3065        Mask |= expandSanitizerGroups(ParsedMask);
3066      }
3067      return Mask;
3068    }
3069
3070    bool hasCoverage() const {
3071      return llvm::is_contained(sanitizers(), "coverage");
3072    }
3073  }];
3074}
3075
3076// Attributes to disable a specific sanitizer. No new sanitizers should be added
3077// to this list; the no_sanitize attribute should be extended instead.
3078def NoSanitizeSpecific : InheritableAttr {
3079  let Spellings = [GCC<"no_address_safety_analysis">,
3080                   GCC<"no_sanitize_address">,
3081                   GCC<"no_sanitize_thread">,
3082                   Clang<"no_sanitize_memory">];
3083  let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;
3084  let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
3085                       NoSanitizeMemoryDocs];
3086  let ASTNode = 0;
3087}
3088
3089def DisableSanitizerInstrumentation : InheritableAttr {
3090  let Spellings = [Clang<"disable_sanitizer_instrumentation">];
3091  let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar]>;
3092  let Documentation = [DisableSanitizerInstrumentationDocs];
3093  let SimpleHandler = 1;
3094}
3095
3096def CFICanonicalJumpTable : InheritableAttr {
3097  let Spellings = [Clang<"cfi_canonical_jump_table">];
3098  let Subjects = SubjectList<[Function], ErrorDiag>;
3099  let Documentation = [CFICanonicalJumpTableDocs];
3100  let SimpleHandler = 1;
3101}
3102
3103// C/C++ Thread safety attributes (e.g. for deadlock, data race checking)
3104// Not all of these attributes will be given a [[]] spelling. The attributes
3105// which require access to function parameter names cannot use the [[]] spelling
3106// because they are not written in the type position. Some attributes are given
3107// an updated captability-based name and the older name will only be supported
3108// under the GNU-style spelling.
3109def GuardedVar : InheritableAttr {
3110  let Spellings = [Clang<"guarded_var", 0>];
3111  let Subjects = SubjectList<[Field, SharedVar]>;
3112  let Documentation = [Undocumented];
3113  let SimpleHandler = 1;
3114}
3115
3116def PtGuardedVar : InheritableAttr {
3117  let Spellings = [Clang<"pt_guarded_var", 0>];
3118  let Subjects = SubjectList<[Field, SharedVar]>;
3119  let Documentation = [Undocumented];
3120}
3121
3122def Lockable : InheritableAttr {
3123  let Spellings = [GNU<"lockable">];
3124  let Subjects = SubjectList<[Record]>;
3125  let Documentation = [Undocumented];
3126  let ASTNode = 0;  // Replaced by Capability
3127}
3128
3129def ScopedLockable : InheritableAttr {
3130  let Spellings = [Clang<"scoped_lockable", 0>];
3131  let Subjects = SubjectList<[Record]>;
3132  let Documentation = [Undocumented];
3133  let SimpleHandler = 1;
3134}
3135
3136def Capability : InheritableAttr {
3137  let Spellings = [Clang<"capability", 0>, Clang<"shared_capability", 0>];
3138  let Subjects = SubjectList<[Record, TypedefName], ErrorDiag>;
3139  let Args = [StringArgument<"Name">];
3140  let Accessors = [Accessor<"isShared",
3141                    [Clang<"shared_capability", 0>]>];
3142  let Documentation = [Undocumented];
3143}
3144
3145def AssertCapability : InheritableAttr {
3146  let Spellings = [Clang<"assert_capability", 0>,
3147                   Clang<"assert_shared_capability", 0>];
3148  let Subjects = SubjectList<[Function]>;
3149  let LateParsed = 1;
3150  let TemplateDependent = 1;
3151  let ParseArgumentsAsUnevaluated = 1;
3152  let InheritEvenIfAlreadyPresent = 1;
3153  let Args = [VariadicExprArgument<"Args">];
3154  let Accessors = [Accessor<"isShared",
3155                    [Clang<"assert_shared_capability", 0>]>];
3156  let Documentation = [AssertCapabilityDocs];
3157}
3158
3159def AcquireCapability : InheritableAttr {
3160  let Spellings = [Clang<"acquire_capability", 0>,
3161                   Clang<"acquire_shared_capability", 0>,
3162                   GNU<"exclusive_lock_function">,
3163                   GNU<"shared_lock_function">];
3164  let Subjects = SubjectList<[Function]>;
3165  let LateParsed = 1;
3166  let TemplateDependent = 1;
3167  let ParseArgumentsAsUnevaluated = 1;
3168  let InheritEvenIfAlreadyPresent = 1;
3169  let Args = [VariadicExprArgument<"Args">];
3170  let Accessors = [Accessor<"isShared",
3171                    [Clang<"acquire_shared_capability", 0>,
3172                     GNU<"shared_lock_function">]>];
3173  let Documentation = [AcquireCapabilityDocs];
3174}
3175
3176def TryAcquireCapability : InheritableAttr {
3177  let Spellings = [Clang<"try_acquire_capability", 0>,
3178                   Clang<"try_acquire_shared_capability", 0>];
3179  let Subjects = SubjectList<[Function],
3180                             ErrorDiag>;
3181  let LateParsed = 1;
3182  let TemplateDependent = 1;
3183  let ParseArgumentsAsUnevaluated = 1;
3184  let InheritEvenIfAlreadyPresent = 1;
3185  let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
3186  let Accessors = [Accessor<"isShared",
3187                    [Clang<"try_acquire_shared_capability", 0>]>];
3188  let Documentation = [TryAcquireCapabilityDocs];
3189}
3190
3191def ReleaseCapability : InheritableAttr {
3192  let Spellings = [Clang<"release_capability", 0>,
3193                   Clang<"release_shared_capability", 0>,
3194                   Clang<"release_generic_capability", 0>,
3195                   Clang<"unlock_function", 0>];
3196  let Subjects = SubjectList<[Function]>;
3197  let LateParsed = 1;
3198  let TemplateDependent = 1;
3199  let ParseArgumentsAsUnevaluated = 1;
3200  let InheritEvenIfAlreadyPresent = 1;
3201  let Args = [VariadicExprArgument<"Args">];
3202  let Accessors = [Accessor<"isShared",
3203                    [Clang<"release_shared_capability", 0>]>,
3204                   Accessor<"isGeneric",
3205                     [Clang<"release_generic_capability", 0>,
3206                      Clang<"unlock_function", 0>]>];
3207  let Documentation = [ReleaseCapabilityDocs];
3208}
3209
3210def RequiresCapability : InheritableAttr {
3211  let Spellings = [Clang<"requires_capability", 0>,
3212                   Clang<"exclusive_locks_required", 0>,
3213                   Clang<"requires_shared_capability", 0>,
3214                   Clang<"shared_locks_required", 0>];
3215  let Args = [VariadicExprArgument<"Args">];
3216  let LateParsed = 1;
3217  let TemplateDependent = 1;
3218  let ParseArgumentsAsUnevaluated = 1;
3219  let InheritEvenIfAlreadyPresent = 1;
3220  let Subjects = SubjectList<[Function]>;
3221  let Accessors = [Accessor<"isShared", [Clang<"requires_shared_capability", 0>,
3222                                         Clang<"shared_locks_required", 0>]>];
3223  let Documentation = [Undocumented];
3224}
3225
3226def NoThreadSafetyAnalysis : InheritableAttr {
3227  let Spellings = [Clang<"no_thread_safety_analysis">];
3228  let Subjects = SubjectList<[Function]>;
3229  let Documentation = [Undocumented];
3230  let SimpleHandler = 1;
3231}
3232
3233def GuardedBy : InheritableAttr {
3234  let Spellings = [GNU<"guarded_by">];
3235  let Args = [ExprArgument<"Arg">];
3236  let LateParsed = 1;
3237  let TemplateDependent = 1;
3238  let ParseArgumentsAsUnevaluated = 1;
3239  let InheritEvenIfAlreadyPresent = 1;
3240  let Subjects = SubjectList<[Field, SharedVar]>;
3241  let Documentation = [Undocumented];
3242}
3243
3244def PtGuardedBy : InheritableAttr {
3245  let Spellings = [GNU<"pt_guarded_by">];
3246  let Args = [ExprArgument<"Arg">];
3247  let LateParsed = 1;
3248  let TemplateDependent = 1;
3249  let ParseArgumentsAsUnevaluated = 1;
3250  let InheritEvenIfAlreadyPresent = 1;
3251  let Subjects = SubjectList<[Field, SharedVar]>;
3252  let Documentation = [Undocumented];
3253}
3254
3255def AcquiredAfter : InheritableAttr {
3256  let Spellings = [GNU<"acquired_after">];
3257  let Args = [VariadicExprArgument<"Args">];
3258  let LateParsed = 1;
3259  let TemplateDependent = 1;
3260  let ParseArgumentsAsUnevaluated = 1;
3261  let InheritEvenIfAlreadyPresent = 1;
3262  let Subjects = SubjectList<[Field, SharedVar]>;
3263  let Documentation = [Undocumented];
3264}
3265
3266def AcquiredBefore : InheritableAttr {
3267  let Spellings = [GNU<"acquired_before">];
3268  let Args = [VariadicExprArgument<"Args">];
3269  let LateParsed = 1;
3270  let TemplateDependent = 1;
3271  let ParseArgumentsAsUnevaluated = 1;
3272  let InheritEvenIfAlreadyPresent = 1;
3273  let Subjects = SubjectList<[Field, SharedVar]>;
3274  let Documentation = [Undocumented];
3275}
3276
3277def AssertExclusiveLock : InheritableAttr {
3278  let Spellings = [GNU<"assert_exclusive_lock">];
3279  let Args = [VariadicExprArgument<"Args">];
3280  let LateParsed = 1;
3281  let TemplateDependent = 1;
3282  let ParseArgumentsAsUnevaluated = 1;
3283  let InheritEvenIfAlreadyPresent = 1;
3284  let Subjects = SubjectList<[Function]>;
3285  let Documentation = [Undocumented];
3286}
3287
3288def AssertSharedLock : InheritableAttr {
3289  let Spellings = [GNU<"assert_shared_lock">];
3290  let Args = [VariadicExprArgument<"Args">];
3291  let LateParsed = 1;
3292  let TemplateDependent = 1;
3293  let ParseArgumentsAsUnevaluated = 1;
3294  let InheritEvenIfAlreadyPresent = 1;
3295  let Subjects = SubjectList<[Function]>;
3296  let Documentation = [Undocumented];
3297}
3298
3299// The first argument is an integer or boolean value specifying the return value
3300// of a successful lock acquisition.
3301def ExclusiveTrylockFunction : InheritableAttr {
3302  let Spellings = [GNU<"exclusive_trylock_function">];
3303  let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
3304  let LateParsed = 1;
3305  let TemplateDependent = 1;
3306  let ParseArgumentsAsUnevaluated = 1;
3307  let InheritEvenIfAlreadyPresent = 1;
3308  let Subjects = SubjectList<[Function]>;
3309  let Documentation = [Undocumented];
3310}
3311
3312// The first argument is an integer or boolean value specifying the return value
3313// of a successful lock acquisition.
3314def SharedTrylockFunction : InheritableAttr {
3315  let Spellings = [GNU<"shared_trylock_function">];
3316  let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
3317  let LateParsed = 1;
3318  let TemplateDependent = 1;
3319  let ParseArgumentsAsUnevaluated = 1;
3320  let InheritEvenIfAlreadyPresent = 1;
3321  let Subjects = SubjectList<[Function]>;
3322  let Documentation = [Undocumented];
3323}
3324
3325def LockReturned : InheritableAttr {
3326  let Spellings = [GNU<"lock_returned">];
3327  let Args = [ExprArgument<"Arg">];
3328  let LateParsed = 1;
3329  let TemplateDependent = 1;
3330  let ParseArgumentsAsUnevaluated = 1;
3331  let Subjects = SubjectList<[Function]>;
3332  let Documentation = [Undocumented];
3333}
3334
3335def LocksExcluded : InheritableAttr {
3336  let Spellings = [GNU<"locks_excluded">];
3337  let Args = [VariadicExprArgument<"Args">];
3338  let LateParsed = 1;
3339  let TemplateDependent = 1;
3340  let ParseArgumentsAsUnevaluated = 1;
3341  let InheritEvenIfAlreadyPresent = 1;
3342  let Subjects = SubjectList<[Function]>;
3343  let Documentation = [Undocumented];
3344}
3345
3346// C/C++ consumed attributes.
3347
3348def Consumable : InheritableAttr {
3349  // This attribute does not have a C [[]] spelling because it only appertains
3350  // to C++ struct/class/union.
3351  // FIXME: should this attribute have a CPlusPlus language option?
3352  let Spellings = [Clang<"consumable", 0>];
3353  let Subjects = SubjectList<[CXXRecord]>;
3354  let Args = [EnumArgument<"DefaultState", "ConsumedState",
3355                           ["unknown", "consumed", "unconsumed"],
3356                           ["Unknown", "Consumed", "Unconsumed"]>];
3357  let Documentation = [ConsumableDocs];
3358}
3359
3360def ConsumableAutoCast : InheritableAttr {
3361  // This attribute does not have a C [[]] spelling because it only appertains
3362  // to C++ struct/class/union.
3363  // FIXME: should this attribute have a CPlusPlus language option?
3364  let Spellings = [Clang<"consumable_auto_cast_state", 0>];
3365  let Subjects = SubjectList<[CXXRecord]>;
3366  let Documentation = [Undocumented];
3367  let SimpleHandler = 1;
3368}
3369
3370def ConsumableSetOnRead : InheritableAttr {
3371  // This attribute does not have a C [[]] spelling because it only appertains
3372  // to C++ struct/class/union.
3373  // FIXME: should this attribute have a CPlusPlus language option?
3374  let Spellings = [Clang<"consumable_set_state_on_read", 0>];
3375  let Subjects = SubjectList<[CXXRecord]>;
3376  let Documentation = [Undocumented];
3377  let SimpleHandler = 1;
3378}
3379
3380def CallableWhen : InheritableAttr {
3381  // This attribute does not have a C [[]] spelling because it only appertains
3382  // to C++ function (but doesn't require it to be a member function).
3383  // FIXME: should this attribute have a CPlusPlus language option?
3384  let Spellings = [Clang<"callable_when", 0>];
3385  let Subjects = SubjectList<[CXXMethod]>;
3386  let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
3387                                   ["unknown", "consumed", "unconsumed"],
3388                                   ["Unknown", "Consumed", "Unconsumed"]>];
3389  let Documentation = [CallableWhenDocs];
3390}
3391
3392def ParamTypestate : InheritableAttr {
3393  // This attribute does not have a C [[]] spelling because it only appertains
3394  // to a parameter whose type is a consumable C++ class.
3395  // FIXME: should this attribute have a CPlusPlus language option?
3396  let Spellings = [Clang<"param_typestate", 0>];
3397  let Subjects = SubjectList<[ParmVar]>;
3398  let Args = [EnumArgument<"ParamState", "ConsumedState",
3399                           ["unknown", "consumed", "unconsumed"],
3400                           ["Unknown", "Consumed", "Unconsumed"]>];
3401  let Documentation = [ParamTypestateDocs];
3402}
3403
3404def ReturnTypestate : InheritableAttr {
3405  // This attribute does not have a C [[]] spelling because it only appertains
3406  // to a parameter or function return type that is a consumable C++ class.
3407  // FIXME: should this attribute have a CPlusPlus language option?
3408  let Spellings = [Clang<"return_typestate", 0>];
3409  let Subjects = SubjectList<[Function, ParmVar]>;
3410  let Args = [EnumArgument<"State", "ConsumedState",
3411                           ["unknown", "consumed", "unconsumed"],
3412                           ["Unknown", "Consumed", "Unconsumed"]>];
3413  let Documentation = [ReturnTypestateDocs];
3414}
3415
3416def SetTypestate : InheritableAttr {
3417  // This attribute does not have a C [[]] spelling because it only appertains
3418  // to C++ function (but doesn't require it to be a member function).
3419  // FIXME: should this attribute have a CPlusPlus language option?
3420  let Spellings = [Clang<"set_typestate", 0>];
3421  let Subjects = SubjectList<[CXXMethod]>;
3422  let Args = [EnumArgument<"NewState", "ConsumedState",
3423                           ["unknown", "consumed", "unconsumed"],
3424                           ["Unknown", "Consumed", "Unconsumed"]>];
3425  let Documentation = [SetTypestateDocs];
3426}
3427
3428def TestTypestate : InheritableAttr {
3429  // This attribute does not have a C [[]] spelling because it only appertains
3430  // to C++ function (but doesn't require it to be a member function).
3431  // FIXME: should this attribute have a CPlusPlus language option?
3432  let Spellings = [Clang<"test_typestate", 0>];
3433  let Subjects = SubjectList<[CXXMethod]>;
3434  let Args = [EnumArgument<"TestState", "ConsumedState",
3435                           ["consumed", "unconsumed"],
3436                           ["Consumed", "Unconsumed"]>];
3437  let Documentation = [TestTypestateDocs];
3438}
3439
3440// Type safety attributes for `void *' pointers and type tags.
3441
3442def ArgumentWithTypeTag : InheritableAttr {
3443  let Spellings = [Clang<"argument_with_type_tag">,
3444                   Clang<"pointer_with_type_tag">];
3445  let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>;
3446  let Args = [IdentifierArgument<"ArgumentKind">,
3447              ParamIdxArgument<"ArgumentIdx">,
3448              ParamIdxArgument<"TypeTagIdx">,
3449              BoolArgument<"IsPointer", /*opt*/0, /*fake*/1>];
3450  let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
3451}
3452
3453def TypeTagForDatatype : InheritableAttr {
3454  let Spellings = [Clang<"type_tag_for_datatype">];
3455  let Args = [IdentifierArgument<"ArgumentKind">,
3456              TypeArgument<"MatchingCType">,
3457              BoolArgument<"LayoutCompatible">,
3458              BoolArgument<"MustBeNull">];
3459//  let Subjects = SubjectList<[Var], ErrorDiag>;
3460  let HasCustomParsing = 1;
3461  let Documentation = [TypeTagForDatatypeDocs];
3462}
3463
3464def Owner : InheritableAttr {
3465  let Spellings = [CXX11<"gsl", "Owner">];
3466  let Subjects = SubjectList<[Struct]>;
3467  let Args = [TypeArgument<"DerefType", /*opt=*/1>];
3468  let Documentation = [LifetimeOwnerDocs];
3469}
3470
3471def Pointer : InheritableAttr {
3472  let Spellings = [CXX11<"gsl", "Pointer">];
3473  let Subjects = SubjectList<[Struct]>;
3474  let Args = [TypeArgument<"DerefType", /*opt=*/1>];
3475  let Documentation = [LifetimePointerDocs];
3476}
3477def : MutualExclusions<[Owner, Pointer]>;
3478
3479// Microsoft-related attributes
3480
3481def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
3482  let Spellings = [Declspec<"novtable">];
3483  let Subjects = SubjectList<[CXXRecord]>;
3484  let Documentation = [MSNoVTableDocs];
3485  let SimpleHandler = 1;
3486}
3487
3488def : IgnoredAttr {
3489  let Spellings = [Declspec<"property">];
3490}
3491
3492def MSAllocator : InheritableAttr {
3493  let Spellings = [Declspec<"allocator">];
3494  let Subjects = SubjectList<[Function]>;
3495  let Documentation = [MSAllocatorDocs];
3496}
3497
3498def CFGuard : InheritableAttr, TargetSpecificAttr<TargetWindows> {
3499  // Currently only the __declspec(guard(nocf)) modifier is supported. In future
3500  // we might also want to support __declspec(guard(suppress)).
3501  let Spellings = [Declspec<"guard">, Clang<"guard">];
3502  let Subjects = SubjectList<[Function]>;
3503  let Args = [EnumArgument<"Guard", "GuardArg", ["nocf"], ["nocf"]>];
3504  let Documentation = [CFGuardDocs];
3505}
3506
3507def MSStruct : InheritableAttr {
3508  let Spellings = [GCC<"ms_struct">];
3509  let Subjects = SubjectList<[Record]>;
3510  let Documentation = [Undocumented];
3511  let SimpleHandler = 1;
3512}
3513
3514def DLLExport : InheritableAttr, TargetSpecificAttr<TargetHasDLLImportExport> {
3515  let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
3516  let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
3517  let Documentation = [DLLExportDocs];
3518}
3519
3520def DLLExportStaticLocal : InheritableAttr, TargetSpecificAttr<TargetHasDLLImportExport> {
3521  // This attribute is used internally only when -fno-dllexport-inlines is
3522  // passed. This attribute is added to inline functions of a class having the
3523  // dllexport attribute. If the function has static local variables, this
3524  // attribute is used to determine whether the variables are exported or not. If
3525  // the function has local static variables, the function is dllexported too.
3526  let Spellings = [];
3527  let Subjects = SubjectList<[Function]>;
3528  let Documentation = [InternalOnly];
3529}
3530
3531def DLLImport : InheritableAttr, TargetSpecificAttr<TargetHasDLLImportExport> {
3532  let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
3533  let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
3534  let Documentation = [DLLImportDocs];
3535
3536
3537  let AdditionalMembers = [{
3538private:
3539  bool PropagatedToBaseTemplate = false;
3540
3541public:
3542  void setPropagatedToBaseTemplate() { PropagatedToBaseTemplate = true; }
3543  bool wasPropagatedToBaseTemplate() { return PropagatedToBaseTemplate; }
3544  }];
3545}
3546
3547def DLLImportStaticLocal : InheritableAttr, TargetSpecificAttr<TargetHasDLLImportExport> {
3548  // This attribute is used internally only when -fno-dllexport-inlines is
3549  // passed. This attribute is added to inline functions of a class having the
3550  // dllimport attribute. If the function has static local variables, this
3551  // attribute is used to determine whether the variables are imported or not.
3552  let Spellings = [];
3553  let Subjects = SubjectList<[Function]>;
3554  let Documentation = [InternalOnly];
3555}
3556
3557def SelectAny : InheritableAttr {
3558  let Spellings = [Declspec<"selectany">, GCC<"selectany">];
3559  let Documentation = [SelectAnyDocs];
3560  let SimpleHandler = 1;
3561}
3562
3563def Thread : Attr {
3564  let Spellings = [Declspec<"thread">];
3565  let LangOpts = [MicrosoftExt];
3566  let Documentation = [ThreadDocs];
3567  let Subjects = SubjectList<[Var]>;
3568}
3569
3570def Win64 : IgnoredAttr {
3571  let Spellings = [Keyword<"__w64">];
3572  let LangOpts = [MicrosoftExt];
3573}
3574
3575def Ptr32 : TypeAttr {
3576  let Spellings = [Keyword<"__ptr32">];
3577  let Documentation = [Ptr32Docs];
3578}
3579
3580def Ptr64 : TypeAttr {
3581  let Spellings = [Keyword<"__ptr64">];
3582  let Documentation = [Ptr64Docs];
3583}
3584
3585def SPtr : TypeAttr {
3586  let Spellings = [Keyword<"__sptr">];
3587  let Documentation = [SPtrDocs];
3588}
3589
3590def UPtr : TypeAttr {
3591  let Spellings = [Keyword<"__uptr">];
3592  let Documentation = [UPtrDocs];
3593}
3594
3595def MSInheritance : InheritableAttr {
3596  let LangOpts = [MicrosoftExt];
3597  let Args = [DefaultBoolArgument<"BestCase", /*default*/1, /*fake*/1>];
3598  let Spellings = [Keyword<"__single_inheritance">,
3599                   Keyword<"__multiple_inheritance">,
3600                   Keyword<"__virtual_inheritance">,
3601                   Keyword<"__unspecified_inheritance">];
3602  let AdditionalMembers = [{
3603  MSInheritanceModel getInheritanceModel() const {
3604    // The spelling enum should agree with MSInheritanceModel.
3605    return MSInheritanceModel(getSemanticSpelling());
3606  }
3607  }];
3608  let Documentation = [MSInheritanceDocs];
3609}
3610
3611def MSVtorDisp : InheritableAttr {
3612  // This attribute has no spellings as it is only ever created implicitly.
3613  let Spellings = [];
3614  let Args = [UnsignedArgument<"vdm">];
3615  let SemaHandler = 0;
3616
3617  let AdditionalMembers = [{
3618  MSVtorDispMode getVtorDispMode() const { return MSVtorDispMode(vdm); }
3619  }];
3620  let Documentation = [InternalOnly];
3621}
3622
3623def InitSeg : Attr {
3624  let Spellings = [Pragma<"", "init_seg">];
3625  let Args = [StringArgument<"Section">];
3626  let SemaHandler = 0;
3627  let Documentation = [InitSegDocs];
3628  let AdditionalMembers = [{
3629  void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3630    OS << " (" << getSection() << ')';
3631  }
3632  }];
3633}
3634
3635def LoopHint : Attr {
3636  /// #pragma clang loop <option> directive
3637  /// vectorize: vectorizes loop operations if State == Enable.
3638  /// vectorize_width: vectorize loop operations with width 'Value'.
3639  /// interleave: interleave multiple loop iterations if State == Enable.
3640  /// interleave_count: interleaves 'Value' loop iterations.
3641  /// unroll: fully unroll loop if State == Enable.
3642  /// unroll_count: unrolls loop 'Value' times.
3643  /// unroll_and_jam: attempt to unroll and jam loop if State == Enable.
3644  /// unroll_and_jam_count: unroll and jams loop 'Value' times.
3645  /// distribute: attempt to distribute loop if State == Enable.
3646  /// pipeline: disable pipelining loop if State == Disable.
3647  /// pipeline_initiation_interval: create loop schedule with initiation interval equal to 'Value'.
3648
3649  /// #pragma unroll <argument> directive
3650  /// <no arg>: fully unrolls loop.
3651  /// boolean: fully unrolls loop if State == Enable.
3652  /// expression: unrolls loop 'Value' times.
3653
3654  let Spellings = [Pragma<"clang", "loop">, Pragma<"", "unroll">,
3655                   Pragma<"", "nounroll">, Pragma<"", "unroll_and_jam">,
3656                   Pragma<"", "nounroll_and_jam">];
3657
3658  /// State of the loop optimization specified by the spelling.
3659  let Args = [EnumArgument<"Option", "OptionType",
3660                          ["vectorize", "vectorize_width", "interleave", "interleave_count",
3661                           "unroll", "unroll_count", "unroll_and_jam", "unroll_and_jam_count",
3662                           "pipeline", "pipeline_initiation_interval", "distribute",
3663                           "vectorize_predicate"],
3664                          ["Vectorize", "VectorizeWidth", "Interleave", "InterleaveCount",
3665                           "Unroll", "UnrollCount", "UnrollAndJam", "UnrollAndJamCount",
3666                           "PipelineDisabled", "PipelineInitiationInterval", "Distribute",
3667                           "VectorizePredicate"]>,
3668              EnumArgument<"State", "LoopHintState",
3669                           ["enable", "disable", "numeric", "fixed_width",
3670                            "scalable_width", "assume_safety", "full"],
3671                           ["Enable", "Disable", "Numeric", "FixedWidth",
3672                            "ScalableWidth", "AssumeSafety", "Full"]>,
3673              ExprArgument<"Value">];
3674
3675  let AdditionalMembers = [{
3676  static const char *getOptionName(int Option) {
3677    switch(Option) {
3678    case Vectorize: return "vectorize";
3679    case VectorizeWidth: return "vectorize_width";
3680    case Interleave: return "interleave";
3681    case InterleaveCount: return "interleave_count";
3682    case Unroll: return "unroll";
3683    case UnrollCount: return "unroll_count";
3684    case UnrollAndJam: return "unroll_and_jam";
3685    case UnrollAndJamCount: return "unroll_and_jam_count";
3686    case PipelineDisabled: return "pipeline";
3687    case PipelineInitiationInterval: return "pipeline_initiation_interval";
3688    case Distribute: return "distribute";
3689    case VectorizePredicate: return "vectorize_predicate";
3690    }
3691    llvm_unreachable("Unhandled LoopHint option.");
3692  }
3693
3694  void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const;
3695
3696  // Return a string containing the loop hint argument including the
3697  // enclosing parentheses.
3698  std::string getValueString(const PrintingPolicy &Policy) const;
3699
3700  // Return a string suitable for identifying this attribute in diagnostics.
3701  std::string getDiagnosticName(const PrintingPolicy &Policy) const;
3702  }];
3703
3704  let Documentation = [LoopHintDocs, UnrollHintDocs];
3705  let HasCustomParsing = 1;
3706}
3707
3708def CapturedRecord : InheritableAttr {
3709  // This attribute has no spellings as it is only ever created implicitly.
3710  let Spellings = [];
3711  let SemaHandler = 0;
3712  let Documentation = [InternalOnly];
3713}
3714
3715def OMPThreadPrivateDecl : InheritableAttr {
3716  // This attribute has no spellings as it is only ever created implicitly.
3717  let Spellings = [];
3718  let SemaHandler = 0;
3719  let Documentation = [InternalOnly];
3720}
3721
3722def OMPCaptureNoInit : InheritableAttr {
3723  // This attribute has no spellings as it is only ever created implicitly.
3724  let Spellings = [];
3725  let SemaHandler = 0;
3726  let Documentation = [InternalOnly];
3727}
3728
3729def OMPCaptureKind : Attr {
3730  // This attribute has no spellings as it is only ever created implicitly.
3731  let Spellings = [];
3732  let SemaHandler = 0;
3733  let Args = [UnsignedArgument<"CaptureKindVal">];
3734  let Documentation = [InternalOnly];
3735  let AdditionalMembers = [{
3736    llvm::omp::Clause getCaptureKind() const {
3737      return static_cast<llvm::omp::Clause>(getCaptureKindVal());
3738    }
3739  }];
3740}
3741
3742def OMPReferencedVar : Attr {
3743  // This attribute has no spellings as it is only ever created implicitly.
3744  let Spellings = [];
3745  let SemaHandler = 0;
3746  let Args = [ExprArgument<"Ref">];
3747  let Documentation = [InternalOnly];
3748}
3749
3750def OMPDeclareSimdDecl : Attr {
3751  let Spellings = [Pragma<"omp", "declare simd">];
3752  let Subjects = SubjectList<[Function]>;
3753  let SemaHandler = 0;
3754  let HasCustomParsing = 1;
3755  let Documentation = [OMPDeclareSimdDocs];
3756  let Args = [
3757    EnumArgument<"BranchState", "BranchStateTy",
3758                 [ "", "inbranch", "notinbranch" ],
3759                 [ "BS_Undefined", "BS_Inbranch", "BS_Notinbranch" ]>,
3760    ExprArgument<"Simdlen">, VariadicExprArgument<"Uniforms">,
3761    VariadicExprArgument<"Aligneds">, VariadicExprArgument<"Alignments">,
3762    VariadicExprArgument<"Linears">, VariadicUnsignedArgument<"Modifiers">,
3763    VariadicExprArgument<"Steps">
3764  ];
3765  let AdditionalMembers = [{
3766    void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
3767        const;
3768  }];
3769}
3770
3771def OMPDeclareTargetDecl : InheritableAttr {
3772  let Spellings = [Pragma<"omp", "declare target">];
3773  let SemaHandler = 0;
3774  let Subjects = SubjectList<[Function, SharedVar]>;
3775  let Documentation = [OMPDeclareTargetDocs];
3776  let Args = [
3777    EnumArgument<"MapType", "MapTypeTy",
3778                 [ "to", "enter", "link" ],
3779                 [ "MT_To", "MT_Enter", "MT_Link" ]>,
3780    EnumArgument<"DevType", "DevTypeTy",
3781                 [ "host", "nohost", "any" ],
3782                 [ "DT_Host", "DT_NoHost", "DT_Any" ]>,
3783    ExprArgument<"IndirectExpr">,
3784    BoolArgument<"Indirect">,
3785    UnsignedArgument<"Level">
3786  ];
3787  let AdditionalMembers = [{
3788    void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const;
3789    static std::optional<MapTypeTy>
3790    isDeclareTargetDeclaration(const ValueDecl *VD);
3791    static std::optional<OMPDeclareTargetDeclAttr*> getActiveAttr(const ValueDecl *VD);
3792    static std::optional<DevTypeTy> getDeviceType(const ValueDecl *VD);
3793    static std::optional<SourceLocation> getLocation(const ValueDecl *VD);
3794  }];
3795}
3796
3797def OMPAllocateDecl : InheritableAttr {
3798  // This attribute has no spellings as it is only ever created implicitly.
3799  let Spellings = [];
3800  let SemaHandler = 0;
3801  let Args = [
3802    EnumArgument<"AllocatorType", "AllocatorTypeTy",
3803                 [
3804                   "omp_null_allocator", "omp_default_mem_alloc",
3805                   "omp_large_cap_mem_alloc", "omp_const_mem_alloc",
3806                   "omp_high_bw_mem_alloc", "omp_low_lat_mem_alloc",
3807                   "omp_cgroup_mem_alloc", "omp_pteam_mem_alloc",
3808                   "omp_thread_mem_alloc", ""
3809                 ],
3810                 [
3811                   "OMPNullMemAlloc", "OMPDefaultMemAlloc",
3812                   "OMPLargeCapMemAlloc", "OMPConstMemAlloc",
3813                   "OMPHighBWMemAlloc", "OMPLowLatMemAlloc",
3814                   "OMPCGroupMemAlloc", "OMPPTeamMemAlloc", "OMPThreadMemAlloc",
3815                   "OMPUserDefinedMemAlloc"
3816                 ]>,
3817    ExprArgument<"Allocator">,
3818    ExprArgument<"Alignment">
3819  ];
3820  let Documentation = [InternalOnly];
3821}
3822
3823def OMPDeclareVariant : InheritableAttr {
3824  let Spellings = [Pragma<"omp", "declare variant">];
3825  let Subjects = SubjectList<[Function]>;
3826  let SemaHandler = 0;
3827  let HasCustomParsing = 1;
3828  let InheritEvenIfAlreadyPresent = 1;
3829  let Documentation = [OMPDeclareVariantDocs];
3830  let Args = [
3831    ExprArgument<"VariantFuncRef">,
3832    OMPTraitInfoArgument<"TraitInfos">,
3833    VariadicExprArgument<"AdjustArgsNothing">,
3834    VariadicExprArgument<"AdjustArgsNeedDevicePtr">,
3835    VariadicOMPInteropInfoArgument<"AppendArgs">,
3836  ];
3837  let AdditionalMembers = [{
3838    OMPTraitInfo &getTraitInfo() { return *traitInfos; }
3839    void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
3840        const;
3841    static StringRef getInteropTypeString(const OMPInteropInfo *I) {
3842      if (I->IsTarget && I->IsTargetSync)
3843        return "target,targetsync";
3844      if (I->IsTarget)
3845        return "target";
3846      return "targetsync";
3847    }
3848  }];
3849}
3850
3851def Assumption : InheritableAttr {
3852  let Spellings = [Clang<"assume">];
3853  let Subjects = SubjectList<[Function, ObjCMethod]>;
3854  let InheritEvenIfAlreadyPresent = 1;
3855  let Documentation = [AssumptionDocs];
3856  let Args = [StringArgument<"Assumption">];
3857}
3858
3859def InternalLinkage : InheritableAttr {
3860  let Spellings = [Clang<"internal_linkage">];
3861  let Subjects = SubjectList<[Var, Function, CXXRecord]>;
3862  let Documentation = [InternalLinkageDocs];
3863}
3864def : MutualExclusions<[Common, InternalLinkage]>;
3865
3866def ExcludeFromExplicitInstantiation : InheritableAttr {
3867  let Spellings = [Clang<"exclude_from_explicit_instantiation">];
3868  let Subjects = SubjectList<[Var, Function, CXXRecord]>;
3869  let Documentation = [ExcludeFromExplicitInstantiationDocs];
3870  let MeaningfulToClassTemplateDefinition = 1;
3871  let SimpleHandler = 1;
3872}
3873
3874def Reinitializes : InheritableAttr {
3875  let Spellings = [Clang<"reinitializes", 0>];
3876  let Subjects = SubjectList<[NonStaticNonConstCXXMethod], ErrorDiag>;
3877  let Documentation = [ReinitializesDocs];
3878  let SimpleHandler = 1;
3879}
3880
3881def NoDestroy : InheritableAttr {
3882  let Spellings = [Clang<"no_destroy", 0>];
3883  let Subjects = SubjectList<[Var]>;
3884  let Documentation = [NoDestroyDocs];
3885}
3886
3887def AlwaysDestroy : InheritableAttr {
3888  let Spellings = [Clang<"always_destroy", 0>];
3889  let Subjects = SubjectList<[Var]>;
3890  let Documentation = [AlwaysDestroyDocs];
3891}
3892def : MutualExclusions<[NoDestroy, AlwaysDestroy]>;
3893
3894def SpeculativeLoadHardening : InheritableAttr {
3895  let Spellings = [Clang<"speculative_load_hardening">];
3896  let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
3897  let Documentation = [SpeculativeLoadHardeningDocs];
3898  let SimpleHandler = 1;
3899}
3900
3901def NoSpeculativeLoadHardening : InheritableAttr {
3902  let Spellings = [Clang<"no_speculative_load_hardening">];
3903  let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
3904  let Documentation = [NoSpeculativeLoadHardeningDocs];
3905  let SimpleHandler = 1;
3906}
3907def : MutualExclusions<[SpeculativeLoadHardening, NoSpeculativeLoadHardening]>;
3908
3909def Uninitialized : InheritableAttr {
3910  let Spellings = [Clang<"uninitialized", 0>];
3911  let Subjects = SubjectList<[LocalVar]>;
3912  let PragmaAttributeSupport = 1;
3913  let Documentation = [UninitializedDocs];
3914}
3915
3916def LoaderUninitialized : Attr {
3917  let Spellings = [Clang<"loader_uninitialized">];
3918  let Subjects = SubjectList<[GlobalVar]>;
3919  let Documentation = [LoaderUninitializedDocs];
3920  let SimpleHandler = 1;
3921}
3922
3923def ObjCExternallyRetained : InheritableAttr {
3924  let LangOpts = [ObjCAutoRefCount];
3925  let Spellings = [Clang<"objc_externally_retained">];
3926  let Subjects = SubjectList<[NonParmVar, Function, Block, ObjCMethod]>;
3927  let Documentation = [ObjCExternallyRetainedDocs];
3928}
3929
3930def NoBuiltin : Attr {
3931  let Spellings = [Clang<"no_builtin">];
3932  let Args = [VariadicStringArgument<"BuiltinNames">];
3933  let Subjects = SubjectList<[Function]>;
3934  let Documentation = [NoBuiltinDocs];
3935}
3936
3937def UsingIfExists : InheritableAttr {
3938  let Spellings = [Clang<"using_if_exists", 0>];
3939  let Subjects = SubjectList<[Using,
3940                              UnresolvedUsingTypename,
3941                              UnresolvedUsingValue], ErrorDiag>;
3942  let Documentation = [UsingIfExistsDocs];
3943}
3944
3945// FIXME: This attribute is not inheritable, it will not be propagated to
3946// redecls. [[clang::lifetimebound]] has the same problems. This should be
3947// fixed in TableGen (by probably adding a new inheritable flag).
3948def AcquireHandle : DeclOrTypeAttr {
3949  let Spellings = [Clang<"acquire_handle">];
3950  let Args = [StringArgument<"HandleType">];
3951  let Subjects = SubjectList<[Function, TypedefName, ParmVar]>;
3952  let Documentation = [AcquireHandleDocs];
3953}
3954
3955def UseHandle : InheritableParamAttr {
3956  let Spellings = [Clang<"use_handle">];
3957  let Args = [StringArgument<"HandleType">];
3958  let Subjects = SubjectList<[ParmVar]>;
3959  let Documentation = [UseHandleDocs];
3960}
3961
3962def ReleaseHandle : InheritableParamAttr {
3963  let Spellings = [Clang<"release_handle">];
3964  let Args = [StringArgument<"HandleType">];
3965  let Subjects = SubjectList<[ParmVar]>;
3966  let Documentation = [ReleaseHandleDocs];
3967}
3968
3969def DiagnoseAsBuiltin : InheritableAttr {
3970  let Spellings = [Clang<"diagnose_as_builtin">];
3971  let Args = [DeclArgument<Function, "Function">,
3972              VariadicUnsignedArgument<"ArgIndices">];
3973  let Subjects = SubjectList<[Function]>;
3974  let Documentation = [DiagnoseAsBuiltinDocs];
3975}
3976
3977def Builtin : InheritableAttr {
3978  let Spellings = [];
3979  let Args = [UnsignedArgument<"ID">];
3980  let Subjects = SubjectList<[Function]>;
3981  let SemaHandler = 0;
3982  let Documentation = [InternalOnly];
3983}
3984
3985def EnforceTCB : InheritableAttr {
3986  let Spellings = [Clang<"enforce_tcb">];
3987  let Subjects = SubjectList<[Function, ObjCMethod]>;
3988  let Args = [StringArgument<"TCBName">];
3989  let Documentation = [EnforceTCBDocs];
3990  bit InheritEvenIfAlreadyPresent = 1;
3991}
3992
3993def EnforceTCBLeaf : InheritableAttr {
3994  let Spellings = [Clang<"enforce_tcb_leaf">];
3995  let Subjects = SubjectList<[Function, ObjCMethod]>;
3996  let Args = [StringArgument<"TCBName">];
3997  let Documentation = [EnforceTCBLeafDocs];
3998  bit InheritEvenIfAlreadyPresent = 1;
3999}
4000
4001def Error : InheritableAttr {
4002  let Spellings = [GCC<"error">, GCC<"warning">];
4003  let Accessors = [Accessor<"isError", [GCC<"error">]>,
4004                   Accessor<"isWarning", [GCC<"warning">]>];
4005  let Args = [StringArgument<"UserDiagnostic">];
4006  let Subjects = SubjectList<[Function], ErrorDiag>;
4007  let Documentation = [ErrorAttrDocs];
4008}
4009
4010def HLSLNumThreads: InheritableAttr {
4011  let Spellings = [Microsoft<"numthreads">];
4012  let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
4013  let Subjects = SubjectList<[HLSLEntry]>;
4014  let LangOpts = [HLSL];
4015  let Documentation = [NumThreadsDocs];
4016}
4017
4018def HLSLSV_GroupIndex: HLSLAnnotationAttr {
4019  let Spellings = [HLSLSemantic<"SV_GroupIndex">];
4020  let Subjects = SubjectList<[ParmVar, GlobalVar]>;
4021  let LangOpts = [HLSL];
4022  let Documentation = [HLSLSV_GroupIndexDocs];
4023}
4024
4025def HLSLResourceBinding: InheritableAttr {
4026  let Spellings = [HLSLSemantic<"register">];
4027  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
4028  let LangOpts = [HLSL];
4029  let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
4030  let Documentation = [HLSLResourceBindingDocs];
4031}
4032
4033def HLSLSV_DispatchThreadID: HLSLAnnotationAttr {
4034  let Spellings = [HLSLSemantic<"SV_DispatchThreadID">];
4035  let Subjects = SubjectList<[ParmVar, Field]>;
4036  let LangOpts = [HLSL];
4037  let Documentation = [HLSLSV_DispatchThreadIDDocs];
4038}
4039
4040def HLSLShader : InheritableAttr {
4041  let Spellings = [Microsoft<"shader">];
4042  let Subjects = SubjectList<[HLSLEntry]>;
4043  let LangOpts = [HLSL];
4044  // NOTE:
4045  // order for the enum should match order in llvm::Triple::EnvironmentType.
4046  // ShaderType will be converted to llvm::Triple::EnvironmentType like
4047  //   (llvm::Triple::EnvironmentType)((uint32_t)ShaderType +
4048  //      (uint32_t)llvm::Triple::EnvironmentType::Pixel).
4049  // This will avoid update code for convert when new shader type is added.
4050  let Args = [
4051    EnumArgument<"Type", "ShaderType",
4052                 [
4053                   "pixel", "vertex", "geometry", "hull", "domain", "compute",
4054                   "library", "raygeneration", "intersection", "anyHit",
4055                   "closestHit", "miss", "callable", "mesh", "amplification"
4056                 ],
4057                 [
4058                   "Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute",
4059                   "Library", "RayGeneration", "Intersection", "AnyHit",
4060                   "ClosestHit", "Miss", "Callable", "Mesh", "Amplification"
4061                 ]>
4062  ];
4063  let Documentation = [HLSLSV_ShaderTypeAttrDocs];
4064}
4065
4066def HLSLResource : InheritableAttr {
4067  let Spellings = [];
4068  let Subjects = SubjectList<[Struct]>;
4069  let LangOpts = [HLSL];
4070  let Args = [EnumArgument<"ResourceType", "ResourceClass",
4071                           ["SRV", "UAV", "CBuffer", "Sampler"],
4072                           ["SRV", "UAV", "CBuffer", "Sampler"]
4073                           >,
4074              EnumArgument<"ResourceShape", "ResourceKind",
4075                           ["Texture1D", "Texture2D", "Texture2DMS",
4076                            "Texture3D", "TextureCube", "Texture1DArray",
4077                            "Texture2DArray", "Texture2DMSArray",
4078                            "TextureCubeArray", "TypedBuffer", "RawBuffer",
4079                            "StructuredBuffer", "CBufferKind", "SamplerKind",
4080                            "TBuffer", "RTAccelerationStructure", "FeedbackTexture2D",
4081                            "FeedbackTexture2DArray"],
4082                           ["Texture1D", "Texture2D", "Texture2DMS",
4083                            "Texture3D", "TextureCube", "Texture1DArray",
4084                            "Texture2DArray", "Texture2DMSArray",
4085                            "TextureCubeArray", "TypedBuffer", "RawBuffer",
4086                            "StructuredBuffer", "CBufferKind", "SamplerKind",
4087                            "TBuffer", "RTAccelerationStructure", "FeedbackTexture2D",
4088                            "FeedbackTexture2DArray"]
4089                            >
4090              ];
4091  let Documentation = [InternalOnly];
4092}
4093
4094def HLSLGroupSharedAddressSpace : TypeAttr {
4095  let Spellings = [Keyword<"groupshared">];
4096  let Subjects = SubjectList<[Var]>;
4097  let Documentation = [HLSLGroupSharedAddressSpaceDocs];
4098}
4099
4100def RandomizeLayout : InheritableAttr {
4101  let Spellings = [GCC<"randomize_layout">];
4102  let Subjects = SubjectList<[Record]>;
4103  let Documentation = [ClangRandomizeLayoutDocs];
4104  let LangOpts = [COnly];
4105}
4106
4107def NoRandomizeLayout : InheritableAttr {
4108  let Spellings = [GCC<"no_randomize_layout">];
4109  let Subjects = SubjectList<[Record]>;
4110  let Documentation = [ClangRandomizeLayoutDocs];
4111  let LangOpts = [COnly];
4112}
4113def : MutualExclusions<[RandomizeLayout, NoRandomizeLayout]>;
4114
4115def FunctionReturnThunks : InheritableAttr,
4116    TargetSpecificAttr<TargetAnyX86> {
4117  let Spellings = [GCC<"function_return">];
4118  let Args = [EnumArgument<"ThunkType", "Kind",
4119    ["keep", "thunk-extern"],
4120    ["Keep", "Extern"]
4121  >];
4122  let Subjects = SubjectList<[Function]>;
4123  let Documentation = [FunctionReturnThunksDocs];
4124}
4125def ReadOnlyPlacement : InheritableAttr {
4126  let Spellings = [Clang<"enforce_read_only_placement">];
4127  let Subjects = SubjectList<[Record]>;
4128  let Documentation = [ReadOnlyPlacementDocs];
4129}
4130