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