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