Coverage Report

Created: 2020-09-22 08:39

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Sema/ParsedAttr.h
Line
Count
Source (jump to first uncovered line)
1
//======- ParsedAttr.h - Parsed attribute sets ------------------*- C++ -*-===//
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
// This file defines the ParsedAttr class, which is used to collect
10
// parsed attributes.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_SEMA_ATTRIBUTELIST_H
15
#define LLVM_CLANG_SEMA_ATTRIBUTELIST_H
16
17
#include "clang/Basic/AttrSubjectMatchRules.h"
18
#include "clang/Basic/AttributeCommonInfo.h"
19
#include "clang/Basic/Diagnostic.h"
20
#include "clang/Basic/SourceLocation.h"
21
#include "clang/Sema/Ownership.h"
22
#include "llvm/ADT/PointerUnion.h"
23
#include "llvm/ADT/SmallVector.h"
24
#include "llvm/ADT/TinyPtrVector.h"
25
#include "llvm/Support/Allocator.h"
26
#include "llvm/Support/Registry.h"
27
#include "llvm/Support/VersionTuple.h"
28
#include <cassert>
29
#include <cstddef>
30
#include <cstring>
31
#include <utility>
32
33
namespace clang {
34
35
class ASTContext;
36
class Decl;
37
class Expr;
38
class IdentifierInfo;
39
class LangOptions;
40
class ParsedAttr;
41
class Sema;
42
class TargetInfo;
43
44
struct ParsedAttrInfo {
45
  /// Corresponds to the Kind enum.
46
  unsigned AttrKind : 16;
47
  /// The number of required arguments of this attribute.
48
  unsigned NumArgs : 4;
49
  /// The number of optional arguments of this attributes.
50
  unsigned OptArgs : 4;
51
  /// True if the parsing does not match the semantic content.
52
  unsigned HasCustomParsing : 1;
53
  /// True if this attribute is only available for certain targets.
54
  unsigned IsTargetSpecific : 1;
55
  /// True if this attribute applies to types.
56
  unsigned IsType : 1;
57
  /// True if this attribute applies to statements.
58
  unsigned IsStmt : 1;
59
  /// True if this attribute has any spellings that are known to gcc.
60
  unsigned IsKnownToGCC : 1;
61
  /// True if this attribute is supported by #pragma clang attribute.
62
  unsigned IsSupportedByPragmaAttribute : 1;
63
  /// The syntaxes supported by this attribute and how they're spelled.
64
  struct Spelling {
65
    AttributeCommonInfo::Syntax Syntax;
66
    const char *NormalizedFullName;
67
  };
68
  ArrayRef<Spelling> Spellings;
69
70
  ParsedAttrInfo(AttributeCommonInfo::Kind AttrKind =
71
                     AttributeCommonInfo::NoSemaHandlerAttribute)
72
      : AttrKind(AttrKind), NumArgs(0), OptArgs(0), HasCustomParsing(0),
73
        IsTargetSpecific(0), IsType(0), IsStmt(0), IsKnownToGCC(0),
74
20.9M
        IsSupportedByPragmaAttribute(0) {}
75
76
20.9M
  virtual ~ParsedAttrInfo() = default;
77
78
  /// Check if this attribute appertains to D, and issue a diagnostic if not.
79
  virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
80
5.05M
                                    const Decl *D) const {
81
5.05M
    return true;
82
5.05M
  }
83
  /// Check if this attribute is allowed by the language we are compiling, and
84
  /// issue a diagnostic if not.
85
47.8M
  virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
86
47.8M
    return true;
87
47.8M
  }
88
  /// Check if this attribute is allowed when compiling for the given target.
89
72.5M
  virtual bool existsInTarget(const TargetInfo &Target) const {
90
72.5M
    return true;
91
72.5M
  }
92
  /// Convert the spelling index of Attr to a semantic spelling enum value.
93
  virtual unsigned
94
0
  spellingIndexToSemanticSpelling(const ParsedAttr &Attr) const {
95
0
    return UINT_MAX;
96
0
  }
97
  /// Populate Rules with the match rules of this attribute.
98
  virtual void getPragmaAttributeMatchRules(
99
      llvm::SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool>> &Rules,
100
91
      const LangOptions &LangOpts) const {
101
91
  }
102
  enum AttrHandling {
103
    NotHandled,
104
    AttributeApplied,
105
    AttributeNotApplied
106
  };
107
  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to this
108
  /// Decl then do so and return either AttributeApplied if it was applied or
109
  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
110
  virtual AttrHandling handleDeclAttribute(Sema &S, Decl *D,
111
2.84M
                                           const ParsedAttr &Attr) const {
112
2.84M
    return NotHandled;
113
2.84M
  }
114
115
  static const ParsedAttrInfo &get(const AttributeCommonInfo &A);
116
};
117
118
typedef llvm::Registry<ParsedAttrInfo> ParsedAttrInfoRegistry;
119
120
/// Represents information about a change in availability for
121
/// an entity, which is part of the encoding of the 'availability'
122
/// attribute.
123
struct AvailabilityChange {
124
  /// The location of the keyword indicating the kind of change.
125
  SourceLocation KeywordLoc;
126
127
  /// The version number at which the change occurred.
128
  VersionTuple Version;
129
130
  /// The source range covering the version number.
131
  SourceRange VersionRange;
132
133
  /// Determine whether this availability change is valid.
134
83.6k
  bool isValid() const { return !Version.empty(); }
135
};
136
137
namespace detail {
138
enum AvailabilitySlot {
139
  IntroducedSlot, DeprecatedSlot, ObsoletedSlot, NumAvailabilitySlots
140
};
141
142
/// Describes the trailing object for Availability attribute in ParsedAttr.
143
struct AvailabilityData {
144
  AvailabilityChange Changes[NumAvailabilitySlots];
145
  SourceLocation StrictLoc;
146
  const Expr *Replacement;
147
148
  AvailabilityData(const AvailabilityChange &Introduced,
149
                   const AvailabilityChange &Deprecated,
150
                   const AvailabilityChange &Obsoleted,
151
                   SourceLocation Strict, const Expr *ReplaceExpr)
152
7.71M
    : StrictLoc(Strict), Replacement(ReplaceExpr) {
153
7.71M
    Changes[IntroducedSlot] = Introduced;
154
7.71M
    Changes[DeprecatedSlot] = Deprecated;
155
7.71M
    Changes[ObsoletedSlot] = Obsoleted;
156
7.71M
  }
157
};
158
159
struct TypeTagForDatatypeData {
160
  ParsedType MatchingCType;
161
  unsigned LayoutCompatible : 1;
162
  unsigned MustBeNull : 1;
163
};
164
struct PropertyData {
165
  IdentifierInfo *GetterId, *SetterId;
166
167
  PropertyData(IdentifierInfo *getterId, IdentifierInfo *setterId)
168
101
      : GetterId(getterId), SetterId(setterId) {}
169
};
170
171
} // namespace
172
173
/// Wraps an identifier and optional source location for the identifier.
174
struct IdentifierLoc {
175
  SourceLocation Loc;
176
  IdentifierInfo *Ident;
177
178
  static IdentifierLoc *create(ASTContext &Ctx, SourceLocation Loc,
179
                               IdentifierInfo *Ident);
180
};
181
182
/// A union of the various pointer types that can be passed to an
183
/// ParsedAttr as an argument.
184
using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;
185
using ArgsVector = llvm::SmallVector<ArgsUnion, 12U>;
186
187
/// ParsedAttr - Represents a syntactic attribute.
188
///
189
/// For a GNU attribute, there are four forms of this construct:
190
///
191
/// 1: __attribute__(( const )). ParmName/Args/NumArgs will all be unused.
192
/// 2: __attribute__(( mode(byte) )). ParmName used, Args/NumArgs unused.
193
/// 3: __attribute__(( format(printf, 1, 2) )). ParmName/Args/NumArgs all used.
194
/// 4: __attribute__(( aligned(16) )). ParmName is unused, Args/Num used.
195
///
196
class ParsedAttr final
197
    : public AttributeCommonInfo,
198
      private llvm::TrailingObjects<
199
          ParsedAttr, ArgsUnion, detail::AvailabilityData,
200
          detail::TypeTagForDatatypeData, ParsedType, detail::PropertyData> {
201
  friend TrailingObjects;
202
203
46.9M
  size_t numTrailingObjects(OverloadToken<ArgsUnion>) const { return NumArgs; }
204
1.08k
  size_t numTrailingObjects(OverloadToken<detail::AvailabilityData>) const {
205
1.08k
    return IsAvailability;
206
1.08k
  }
207
  size_t
208
421
      numTrailingObjects(OverloadToken<detail::TypeTagForDatatypeData>) const {
209
421
    return IsTypeTagForDatatype;
210
421
  }
211
293
  size_t numTrailingObjects(OverloadToken<ParsedType>) const {
212
293
    return HasParsedType;
213
293
  }
214
0
  size_t numTrailingObjects(OverloadToken<detail::PropertyData>) const {
215
0
    return IsProperty;
216
0
  }
217
218
private:
219
  IdentifierInfo *MacroII = nullptr;
220
  SourceLocation MacroExpansionLoc;
221
  SourceLocation EllipsisLoc;
222
223
  /// The number of expression arguments this attribute has.
224
  /// The expressions themselves are stored after the object.
225
  unsigned NumArgs : 16;
226
227
  /// True if already diagnosed as invalid.
228
  mutable unsigned Invalid : 1;
229
230
  /// True if this attribute was used as a type attribute.
231
  mutable unsigned UsedAsTypeAttr : 1;
232
233
  /// True if this has the extra information associated with an
234
  /// availability attribute.
235
  unsigned IsAvailability : 1;
236
237
  /// True if this has extra information associated with a
238
  /// type_tag_for_datatype attribute.
239
  unsigned IsTypeTagForDatatype : 1;
240
241
  /// True if this has extra information associated with a
242
  /// Microsoft __delcspec(property) attribute.
243
  unsigned IsProperty : 1;
244
245
  /// True if this has a ParsedType
246
  unsigned HasParsedType : 1;
247
248
  /// True if the processing cache is valid.
249
  mutable unsigned HasProcessingCache : 1;
250
251
  /// A cached value.
252
  mutable unsigned ProcessingCache : 8;
253
254
  /// True if the attribute is specified using '#pragma clang attribute'.
255
  mutable unsigned IsPragmaClangAttribute : 1;
256
257
  /// The location of the 'unavailable' keyword in an
258
  /// availability attribute.
259
  SourceLocation UnavailableLoc;
260
261
  const Expr *MessageExpr;
262
263
  const ParsedAttrInfo &Info;
264
265
19.5M
  ArgsUnion *getArgsBuffer() { return getTrailingObjects<ArgsUnion>(); }
266
30.4M
  ArgsUnion const *getArgsBuffer() const {
267
30.4M
    return getTrailingObjects<ArgsUnion>();
268
30.4M
  }
269
270
7.71M
  detail::AvailabilityData *getAvailabilityData() {
271
7.71M
    return getTrailingObjects<detail::AvailabilityData>();
272
7.71M
  }
273
39.1M
  const detail::AvailabilityData *getAvailabilityData() const {
274
39.1M
    return getTrailingObjects<detail::AvailabilityData>();
275
39.1M
  }
276
277
private:
278
  friend class AttributeFactory;
279
  friend class AttributePool;
280
281
  /// Constructor for attributes with expression arguments.
282
  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
283
             IdentifierInfo *scopeName, SourceLocation scopeLoc,
284
             ArgsUnion *args, unsigned numArgs, Syntax syntaxUsed,
285
             SourceLocation ellipsisLoc)
286
      : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc,
287
                            syntaxUsed),
288
        EllipsisLoc(ellipsisLoc), NumArgs(numArgs), Invalid(false),
289
        UsedAsTypeAttr(false), IsAvailability(false),
290
        IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
291
        HasProcessingCache(false), IsPragmaClangAttribute(false),
292
41.3M
        Info(ParsedAttrInfo::get(*this)) {
293
41.3M
    if (numArgs)
294
11.8M
      memcpy(getArgsBuffer(), args, numArgs * sizeof(ArgsUnion));
295
41.3M
  }
296
297
  /// Constructor for availability attributes.
298
  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
299
             IdentifierInfo *scopeName, SourceLocation scopeLoc,
300
             IdentifierLoc *Parm, const AvailabilityChange &introduced,
301
             const AvailabilityChange &deprecated,
302
             const AvailabilityChange &obsoleted, SourceLocation unavailable,
303
             const Expr *messageExpr, Syntax syntaxUsed, SourceLocation strict,
304
             const Expr *replacementExpr)
305
      : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc,
306
                            syntaxUsed),
307
        NumArgs(1), Invalid(false), UsedAsTypeAttr(false), IsAvailability(true),
308
        IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
309
        HasProcessingCache(false), IsPragmaClangAttribute(false),
310
        UnavailableLoc(unavailable), MessageExpr(messageExpr),
311
7.71M
        Info(ParsedAttrInfo::get(*this)) {
312
7.71M
    ArgsUnion PVal(Parm);
313
7.71M
    memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion));
314
7.71M
    new (getAvailabilityData()) detail::AvailabilityData(
315
7.71M
        introduced, deprecated, obsoleted, strict, replacementExpr);
316
7.71M
  }
317
318
  /// Constructor for objc_bridge_related attributes.
319
  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
320
             IdentifierInfo *scopeName, SourceLocation scopeLoc,
321
             IdentifierLoc *Parm1, IdentifierLoc *Parm2, IdentifierLoc *Parm3,
322
             Syntax syntaxUsed)
323
      : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc,
324
                            syntaxUsed),
325
        NumArgs(3), Invalid(false), UsedAsTypeAttr(false),
326
        IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false),
327
        HasParsedType(false), HasProcessingCache(false),
328
613
        IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
329
613
    ArgsUnion *Args = getArgsBuffer();
330
613
    Args[0] = Parm1;
331
613
    Args[1] = Parm2;
332
613
    Args[2] = Parm3;
333
613
  }
334
335
  /// Constructor for type_tag_for_datatype attribute.
336
  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
337
             IdentifierInfo *scopeName, SourceLocation scopeLoc,
338
             IdentifierLoc *ArgKind, ParsedType matchingCType,
339
             bool layoutCompatible, bool mustBeNull, Syntax syntaxUsed)
340
      : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc,
341
                            syntaxUsed),
342
        NumArgs(1), Invalid(false), UsedAsTypeAttr(false),
343
        IsAvailability(false), IsTypeTagForDatatype(true), IsProperty(false),
344
        HasParsedType(false), HasProcessingCache(false),
345
168
        IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
346
168
    ArgsUnion PVal(ArgKind);
347
168
    memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion));
348
168
    detail::TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot();
349
168
    new (&ExtraData.MatchingCType) ParsedType(matchingCType);
350
168
    ExtraData.LayoutCompatible = layoutCompatible;
351
168
    ExtraData.MustBeNull = mustBeNull;
352
168
  }
353
354
  /// Constructor for attributes with a single type argument.
355
  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
356
             IdentifierInfo *scopeName, SourceLocation scopeLoc,
357
             ParsedType typeArg, Syntax syntaxUsed)
358
      : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc,
359
                            syntaxUsed),
360
        NumArgs(0), Invalid(false), UsedAsTypeAttr(false),
361
        IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false),
362
        HasParsedType(true), HasProcessingCache(false),
363
67
        IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
364
67
    new (&getTypeBuffer()) ParsedType(typeArg);
365
67
  }
366
367
  /// Constructor for microsoft __declspec(property) attribute.
368
  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
369
             IdentifierInfo *scopeName, SourceLocation scopeLoc,
370
             IdentifierInfo *getterId, IdentifierInfo *setterId,
371
             Syntax syntaxUsed)
372
      : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc,
373
                            syntaxUsed),
374
        NumArgs(0), Invalid(false), UsedAsTypeAttr(false),
375
        IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(true),
376
        HasParsedType(false), HasProcessingCache(false),
377
101
        IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
378
101
    new (&getPropertyDataBuffer()) detail::PropertyData(getterId, setterId);
379
101
  }
380
381
  /// Type tag information is stored immediately following the arguments, if
382
  /// any, at the end of the object.  They are mutually exclusive with
383
  /// availability slots.
384
168
  detail::TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
385
168
    return *getTrailingObjects<detail::TypeTagForDatatypeData>();
386
168
  }
387
495
  const detail::TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() const {
388
495
    return *getTrailingObjects<detail::TypeTagForDatatypeData>();
389
495
  }
390
391
  /// The type buffer immediately follows the object and are mutually exclusive
392
  /// with arguments.
393
67
  ParsedType &getTypeBuffer() { return *getTrailingObjects<ParsedType>(); }
394
61
  const ParsedType &getTypeBuffer() const {
395
61
    return *getTrailingObjects<ParsedType>();
396
61
  }
397
398
  /// The property data immediately follows the object is is mutually exclusive
399
  /// with arguments.
400
101
  detail::PropertyData &getPropertyDataBuffer() {
401
101
    assert(IsProperty);
402
101
    return *getTrailingObjects<detail::PropertyData>();
403
101
  }
404
192
  const detail::PropertyData &getPropertyDataBuffer() const {
405
192
    assert(IsProperty);
406
192
    return *getTrailingObjects<detail::PropertyData>();
407
192
  }
408
409
  size_t allocated_size() const;
410
411
public:
412
  ParsedAttr(const ParsedAttr &) = delete;
413
  ParsedAttr(ParsedAttr &&) = delete;
414
  ParsedAttr &operator=(const ParsedAttr &) = delete;
415
  ParsedAttr &operator=(ParsedAttr &&) = delete;
416
  ~ParsedAttr() = delete;
417
418
  void operator delete(void *) = delete;
419
420
47.8M
  bool hasParsedType() const { return HasParsedType; }
421
422
  /// Is this the Microsoft __declspec(property) attribute?
423
1.12M
  bool isDeclspecPropertyAttribute() const  {
424
1.12M
    return IsProperty;
425
1.12M
  }
426
427
93.1M
  bool isInvalid() const { return Invalid; }
428
432
  void setInvalid(bool b = true) const { Invalid = b; }
429
430
7.50k
  bool hasProcessingCache() const { return HasProcessingCache; }
431
432
2.41k
  unsigned getProcessingCache() const {
433
2.41k
    assert(hasProcessingCache());
434
2.41k
    return ProcessingCache;
435
2.41k
  }
436
437
2.64k
  void setProcessingCache(unsigned value) const {
438
2.64k
    ProcessingCache = value;
439
2.64k
    HasProcessingCache = true;
440
2.64k
  }
441
442
1.56M
  bool isUsedAsTypeAttr() const { return UsedAsTypeAttr; }
443
7.10M
  void setUsedAsTypeAttr(bool Used = true) { UsedAsTypeAttr = Used; }
444
445
  /// True if the attribute is specified using '#pragma clang attribute'.
446
8.03M
  bool isPragmaClangAttribute() const { return IsPragmaClangAttribute; }
447
448
1.47k
  void setIsPragmaClangAttribute() { IsPragmaClangAttribute = true; }
449
450
96.3k
  bool isPackExpansion() const { return EllipsisLoc.isValid(); }
451
1
  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
452
453
  /// getNumArgs - Return the number of actual arguments to this attribute.
454
48.1M
  unsigned getNumArgs() const { return NumArgs; }
455
456
  /// getArg - Return the specified argument.
457
30.4M
  ArgsUnion getArg(unsigned Arg) const {
458
30.4M
    assert(Arg < NumArgs && "Arg access out of range!");
459
30.4M
    return getArgsBuffer()[Arg];
460
30.4M
  }
461
462
53.6k
  bool isArgExpr(unsigned Arg) const {
463
53.6k
    return Arg < NumArgs && 
getArg(Arg).is<Expr*>()11.4k
;
464
53.6k
  }
465
466
4.08M
  Expr *getArgAsExpr(unsigned Arg) const {
467
4.08M
    return getArg(Arg).get<Expr*>();
468
4.08M
  }
469
470
10.6M
  bool isArgIdent(unsigned Arg) const {
471
10.6M
    return Arg < NumArgs && 
getArg(Arg).is<IdentifierLoc*>()10.6M
;
472
10.6M
  }
473
474
15.6M
  IdentifierLoc *getArgAsIdent(unsigned Arg) const {
475
15.6M
    return getArg(Arg).get<IdentifierLoc*>();
476
15.6M
  }
477
478
7.83M
  const AvailabilityChange &getAvailabilityIntroduced() const {
479
7.83M
    assert(getParsedKind() == AT_Availability &&
480
7.83M
           "Not an availability attribute");
481
7.83M
    return getAvailabilityData()->Changes[detail::IntroducedSlot];
482
7.83M
  }
483
484
7.83M
  const AvailabilityChange &getAvailabilityDeprecated() const {
485
7.83M
    assert(getParsedKind() == AT_Availability &&
486
7.83M
           "Not an availability attribute");
487
7.83M
    return getAvailabilityData()->Changes[detail::DeprecatedSlot];
488
7.83M
  }
489
490
7.83M
  const AvailabilityChange &getAvailabilityObsoleted() const {
491
7.83M
    assert(getParsedKind() == AT_Availability &&
492
7.83M
           "Not an availability attribute");
493
7.83M
    return getAvailabilityData()->Changes[detail::ObsoletedSlot];
494
7.83M
  }
495
496
7.83M
  SourceLocation getStrictLoc() const {
497
7.83M
    assert(getParsedKind() == AT_Availability &&
498
7.83M
           "Not an availability attribute");
499
7.83M
    return getAvailabilityData()->StrictLoc;
500
7.83M
  }
501
502
7.83M
  SourceLocation getUnavailableLoc() const {
503
7.83M
    assert(getParsedKind() == AT_Availability &&
504
7.83M
           "Not an availability attribute");
505
7.83M
    return UnavailableLoc;
506
7.83M
  }
507
508
7.83M
  const Expr * getMessageExpr() const {
509
7.83M
    assert(getParsedKind() == AT_Availability &&
510
7.83M
           "Not an availability attribute");
511
7.83M
    return MessageExpr;
512
7.83M
  }
513
514
7.83M
  const Expr *getReplacementExpr() const {
515
7.83M
    assert(getParsedKind() == AT_Availability &&
516
7.83M
           "Not an availability attribute");
517
7.83M
    return getAvailabilityData()->Replacement;
518
7.83M
  }
519
520
165
  const ParsedType &getMatchingCType() const {
521
165
    assert(getParsedKind() == AT_TypeTagForDatatype &&
522
165
           "Not a type_tag_for_datatype attribute");
523
165
    return getTypeTagForDatatypeDataSlot().MatchingCType;
524
165
  }
525
526
165
  bool getLayoutCompatible() const {
527
165
    assert(getParsedKind() == AT_TypeTagForDatatype &&
528
165
           "Not a type_tag_for_datatype attribute");
529
165
    return getTypeTagForDatatypeDataSlot().LayoutCompatible;
530
165
  }
531
532
165
  bool getMustBeNull() const {
533
165
    assert(getParsedKind() == AT_TypeTagForDatatype &&
534
165
           "Not a type_tag_for_datatype attribute");
535
165
    return getTypeTagForDatatypeDataSlot().MustBeNull;
536
165
  }
537
538
61
  const ParsedType &getTypeArg() const {
539
61
    assert(HasParsedType && "Not a type attribute");
540
61
    return getTypeBuffer();
541
61
  }
542
543
96
  IdentifierInfo *getPropertyDataGetter() const {
544
96
    assert(isDeclspecPropertyAttribute() &&
545
96
           "Not a __delcspec(property) attribute");
546
96
    return getPropertyDataBuffer().GetterId;
547
96
  }
548
549
96
  IdentifierInfo *getPropertyDataSetter() const {
550
96
    assert(isDeclspecPropertyAttribute() &&
551
96
           "Not a __delcspec(property) attribute");
552
96
    return getPropertyDataBuffer().SetterId;
553
96
  }
554
555
  /// Set the macro identifier info object that this parsed attribute was
556
  /// declared in if it was declared in a macro. Also set the expansion location
557
  /// of the macro.
558
7.55M
  void setMacroIdentifier(IdentifierInfo *MacroName, SourceLocation Loc) {
559
7.55M
    MacroII = MacroName;
560
7.55M
    MacroExpansionLoc = Loc;
561
7.55M
  }
562
563
  /// Returns true if this attribute was declared in a macro.
564
4.92M
  bool hasMacroIdentifier() const { return MacroII != nullptr; }
565
566
  /// Return the macro identifier if this attribute was declared in a macro.
567
  /// nullptr is returned if it was not declared in a macro.
568
316k
  IdentifierInfo *getMacroIdentifier() const { return MacroII; }
569
570
316k
  SourceLocation getMacroExpansionLoc() const {
571
316k
    assert(hasMacroIdentifier() && "Can only get the macro expansion location "
572
316k
                                   "if this attribute has a macro identifier.");
573
316k
    return MacroExpansionLoc;
574
316k
  }
575
576
  bool isTargetSpecificAttr() const;
577
  bool isTypeAttr() const;
578
  bool isStmtAttr() const;
579
580
  bool hasCustomParsing() const;
581
  unsigned getMinArgs() const;
582
  unsigned getMaxArgs() const;
583
  bool hasVariadicArg() const;
584
  bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const;
585
  bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const;
586
  void getMatchRules(const LangOptions &LangOpts,
587
                     SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool>>
588
                         &MatchRules) const;
589
  bool diagnoseLangOpts(class Sema &S) const;
590
  bool existsInTarget(const TargetInfo &Target) const;
591
  bool isKnownToGCC() const;
592
  bool isSupportedByPragmaAttribute() const;
593
594
  /// If the parsed attribute has a semantic equivalent, and it would
595
  /// have a semantic Spelling enumeration (due to having semantically-distinct
596
  /// spelling variations), return the value of that semantic spelling. If the
597
  /// parsed attribute does not have a semantic equivalent, or would not have
598
  /// a Spelling enumeration, the value UINT_MAX is returned.
599
  unsigned getSemanticSpelling() const;
600
601
  /// If this is an OpenCL addr space attribute returns its representation
602
  /// in LangAS, otherwise returns default addr space.
603
33.8k
  LangAS asOpenCLLangAS() const {
604
33.8k
    switch (getParsedKind()) {
605
2.22k
    case ParsedAttr::AT_OpenCLConstantAddressSpace:
606
2.22k
      return LangAS::opencl_constant;
607
14.4k
    case ParsedAttr::AT_OpenCLGlobalAddressSpace:
608
14.4k
      return LangAS::opencl_global;
609
28
    case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
610
28
      return LangAS::opencl_global_device;
611
28
    case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
612
28
      return LangAS::opencl_global_host;
613
12.4k
    case ParsedAttr::AT_OpenCLLocalAddressSpace:
614
12.4k
      return LangAS::opencl_local;
615
4.22k
    case ParsedAttr::AT_OpenCLPrivateAddressSpace:
616
4.22k
      return LangAS::opencl_private;
617
530
    case ParsedAttr::AT_OpenCLGenericAddressSpace:
618
530
      return LangAS::opencl_generic;
619
0
    default:
620
0
      return LangAS::Default;
621
33.8k
    }
622
33.8k
  }
623
624
250M
  AttributeCommonInfo::Kind getKind() const {
625
250M
    return AttributeCommonInfo::Kind(Info.AttrKind);
626
250M
  }
627
409M
  const ParsedAttrInfo &getInfo() const { return Info; }
628
};
629
630
class AttributePool;
631
/// A factory, from which one makes pools, from which one creates
632
/// individual attributes which are deallocated with the pool.
633
///
634
/// Note that it's tolerably cheap to create and destroy one of
635
/// these as long as you don't actually allocate anything in it.
636
class AttributeFactory {
637
public:
638
  enum {
639
    AvailabilityAllocSize =
640
        ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
641
                                     detail::TypeTagForDatatypeData, ParsedType,
642
                                     detail::PropertyData>(1, 1, 0, 0, 0),
643
    TypeTagForDatatypeAllocSize =
644
        ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
645
                                     detail::TypeTagForDatatypeData, ParsedType,
646
                                     detail::PropertyData>(1, 0, 1, 0, 0),
647
    PropertyAllocSize =
648
        ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
649
                                     detail::TypeTagForDatatypeData, ParsedType,
650
                                     detail::PropertyData>(0, 0, 0, 0, 1),
651
  };
652
653
private:
654
  enum {
655
    /// The number of free lists we want to be sure to support
656
    /// inline.  This is just enough that availability attributes
657
    /// don't surpass it.  It's actually very unlikely we'll see an
658
    /// attribute that needs more than that; on x86-64 you'd need 10
659
    /// expression arguments, and on i386 you'd need 19.
660
    InlineFreeListsCapacity =
661
        1 + (AvailabilityAllocSize - sizeof(ParsedAttr)) / sizeof(void *)
662
  };
663
664
  llvm::BumpPtrAllocator Alloc;
665
666
  /// Free lists.  The index is determined by the following formula:
667
  ///   (size - sizeof(ParsedAttr)) / sizeof(void*)
668
  SmallVector<SmallVector<ParsedAttr *, 8>, InlineFreeListsCapacity> FreeLists;
669
670
  // The following are the private interface used by AttributePool.
671
  friend class AttributePool;
672
673
  /// Allocate an attribute of the given size.
674
  void *allocate(size_t size);
675
676
  void deallocate(ParsedAttr *AL);
677
678
  /// Reclaim all the attributes in the given pool chain, which is
679
  /// non-empty.  Note that the current implementation is safe
680
  /// against reclaiming things which were not actually allocated
681
  /// with the allocator, although of course it's important to make
682
  /// sure that their allocator lives at least as long as this one.
683
  void reclaimPool(AttributePool &head);
684
685
public:
686
  AttributeFactory();
687
  ~AttributeFactory();
688
};
689
690
class AttributePool {
691
  friend class AttributeFactory;
692
  friend class ParsedAttributes;
693
  AttributeFactory &Factory;
694
  llvm::TinyPtrVector<ParsedAttr *> Attrs;
695
696
49.0M
  void *allocate(size_t size) {
697
49.0M
    return Factory.allocate(size);
698
49.0M
  }
699
700
49.0M
  ParsedAttr *add(ParsedAttr *attr) {
701
49.0M
    Attrs.push_back(attr);
702
49.0M
    return attr;
703
49.0M
  }
704
705
11
  void remove(ParsedAttr *attr) {
706
11
    assert(llvm::is_contained(Attrs, attr) &&
707
11
           "Can't take attribute from a pool that doesn't own it!");
708
11
    Attrs.erase(llvm::find(Attrs, attr));
709
11
  }
710
711
  void takePool(AttributePool &pool);
712
713
public:
714
  /// Create a new pool for a factory.
715
313M
  AttributePool(AttributeFactory &factory) : Factory(factory) {}
716
717
  AttributePool(const AttributePool &) = delete;
718
719
313M
  ~AttributePool() { Factory.reclaimPool(*this); }
720
721
  /// Move the given pool's allocations to this pool.
722
  AttributePool(AttributePool &&pool) = default;
723
724
69.1M
  AttributeFactory &getFactory() const { return Factory; }
725
726
69.2M
  void clear() {
727
69.2M
    Factory.reclaimPool(*this);
728
69.2M
    Attrs.clear();
729
69.2M
  }
730
731
  /// Take the given pool's allocations and add them to this pool.
732
87.5M
  void takeAllFrom(AttributePool &pool) {
733
87.5M
    takePool(pool);
734
87.5M
    pool.Attrs.clear();
735
87.5M
  }
736
737
  ParsedAttr *create(IdentifierInfo *attrName, SourceRange attrRange,
738
                     IdentifierInfo *scopeName, SourceLocation scopeLoc,
739
                     ArgsUnion *args, unsigned numArgs,
740
                     ParsedAttr::Syntax syntax,
741
41.3M
                     SourceLocation ellipsisLoc = SourceLocation()) {
742
41.3M
    size_t temp =
743
41.3M
        ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
744
41.3M
                                     detail::TypeTagForDatatypeData, ParsedType,
745
41.3M
                                     detail::PropertyData>(numArgs, 0, 0, 0, 0);
746
41.3M
    (void)temp;
747
41.3M
    void *memory = allocate(
748
41.3M
        ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
749
41.3M
                                     detail::TypeTagForDatatypeData, ParsedType,
750
41.3M
                                     detail::PropertyData>(numArgs, 0, 0, 0,
751
41.3M
                                                           0));
752
41.3M
    return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
753
41.3M
                                       args, numArgs, syntax, ellipsisLoc));
754
41.3M
  }
755
756
  ParsedAttr *create(IdentifierInfo *attrName, SourceRange attrRange,
757
                     IdentifierInfo *scopeName, SourceLocation scopeLoc,
758
                     IdentifierLoc *Param, const AvailabilityChange &introduced,
759
                     const AvailabilityChange &deprecated,
760
                     const AvailabilityChange &obsoleted,
761
                     SourceLocation unavailable, const Expr *MessageExpr,
762
                     ParsedAttr::Syntax syntax, SourceLocation strict,
763
7.71M
                     const Expr *ReplacementExpr) {
764
7.71M
    void *memory = allocate(AttributeFactory::AvailabilityAllocSize);
765
7.71M
    return add(new (memory) ParsedAttr(
766
7.71M
        attrName, attrRange, scopeName, scopeLoc, Param, introduced, deprecated,
767
7.71M
        obsoleted, unavailable, MessageExpr, syntax, strict, ReplacementExpr));
768
7.71M
  }
769
770
  ParsedAttr *create(IdentifierInfo *attrName, SourceRange attrRange,
771
                     IdentifierInfo *scopeName, SourceLocation scopeLoc,
772
                     IdentifierLoc *Param1, IdentifierLoc *Param2,
773
613
                     IdentifierLoc *Param3, ParsedAttr::Syntax syntax) {
774
613
    void *memory = allocate(
775
613
        ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
776
613
                                     detail::TypeTagForDatatypeData, ParsedType,
777
613
                                     detail::PropertyData>(3, 0, 0, 0, 0));
778
613
    return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
779
613
                                       Param1, Param2, Param3, syntax));
780
613
  }
781
782
  ParsedAttr *
783
  createTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange,
784
                           IdentifierInfo *scopeName, SourceLocation scopeLoc,
785
                           IdentifierLoc *argumentKind,
786
                           ParsedType matchingCType, bool layoutCompatible,
787
168
                           bool mustBeNull, ParsedAttr::Syntax syntax) {
788
168
    void *memory = allocate(AttributeFactory::TypeTagForDatatypeAllocSize);
789
168
    return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
790
168
                                       argumentKind, matchingCType,
791
168
                                       layoutCompatible, mustBeNull, syntax));
792
168
  }
793
794
  ParsedAttr *createTypeAttribute(IdentifierInfo *attrName,
795
                                  SourceRange attrRange,
796
                                  IdentifierInfo *scopeName,
797
                                  SourceLocation scopeLoc, ParsedType typeArg,
798
67
                                  ParsedAttr::Syntax syntaxUsed) {
799
67
    void *memory = allocate(
800
67
        ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
801
67
                                     detail::TypeTagForDatatypeData, ParsedType,
802
67
                                     detail::PropertyData>(0, 0, 0, 1, 0));
803
67
    return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
804
67
                                       typeArg, syntaxUsed));
805
67
  }
806
807
  ParsedAttr *
808
  createPropertyAttribute(IdentifierInfo *attrName, SourceRange attrRange,
809
                          IdentifierInfo *scopeName, SourceLocation scopeLoc,
810
                          IdentifierInfo *getterId, IdentifierInfo *setterId,
811
101
                          ParsedAttr::Syntax syntaxUsed) {
812
101
    void *memory = allocate(AttributeFactory::PropertyAllocSize);
813
101
    return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
814
101
                                       getterId, setterId, syntaxUsed));
815
101
  }
816
};
817
818
class ParsedAttributesView {
819
  using VecTy = llvm::TinyPtrVector<ParsedAttr *>;
820
  using SizeType = decltype(std::declval<VecTy>().size());
821
822
public:
823
253M
  bool empty() const { return AttrList.empty(); }
824
53.3M
  SizeType size() const { return AttrList.size(); }
825
7.55M
  ParsedAttr &operator[](SizeType pos) { return *AttrList[pos]; }
826
0
  const ParsedAttr &operator[](SizeType pos) const { return *AttrList[pos]; }
827
828
49.4M
  void addAtEnd(ParsedAttr *newAttr) {
829
49.4M
    assert(newAttr);
830
49.4M
    AttrList.push_back(newAttr);
831
49.4M
  }
832
833
92.3k
  void remove(ParsedAttr *ToBeRemoved) {
834
92.3k
    assert(is_contained(AttrList, ToBeRemoved) &&
835
92.3k
           "Cannot remove attribute that isn't in the list");
836
92.3k
    AttrList.erase(llvm::find(AttrList, ToBeRemoved));
837
92.3k
  }
838
839
129M
  void clearListOnly() { AttrList.clear(); }
840
841
  struct iterator : llvm::iterator_adaptor_base<iterator, VecTy::iterator,
842
                                                std::random_access_iterator_tag,
843
                                                ParsedAttr> {
844
0
    iterator() : iterator_adaptor_base(nullptr) {}
845
515M
    iterator(VecTy::iterator I) : iterator_adaptor_base(I) {}
846
52.4M
    reference operator*() { return **I; }
847
    friend class ParsedAttributesView;
848
  };
849
  struct const_iterator
850
      : llvm::iterator_adaptor_base<const_iterator, VecTy::const_iterator,
851
                                    std::random_access_iterator_tag,
852
                                    ParsedAttr> {
853
0
    const_iterator() : iterator_adaptor_base(nullptr) {}
854
138M
    const_iterator(VecTy::const_iterator I) : iterator_adaptor_base(I) {}
855
856
51.3M
    reference operator*() const { return **I; }
857
    friend class ParsedAttributesView;
858
  };
859
860
85.9M
  void addAll(iterator B, iterator E) {
861
85.9M
    AttrList.insert(AttrList.begin(), B.I, E.I);
862
85.9M
  }
863
864
0
  void addAll(const_iterator B, const_iterator E) {
865
0
    AttrList.insert(AttrList.begin(), B.I, E.I);
866
0
  }
867
868
0
  void addAllAtEnd(iterator B, iterator E) {
869
0
    AttrList.insert(AttrList.end(), B.I, E.I);
870
0
  }
871
872
0
  void addAllAtEnd(const_iterator B, const_iterator E) {
873
0
    AttrList.insert(AttrList.end(), B.I, E.I);
874
0
  }
875
876
257M
  iterator begin() { return iterator(AttrList.begin()); }
877
67.8M
  const_iterator begin() const { return const_iterator(AttrList.begin()); }
878
257M
  iterator end() { return iterator(AttrList.end()); }
879
70.2M
  const_iterator end() const { return const_iterator(AttrList.end()); }
880
881
0
  ParsedAttr &front() {
882
0
    assert(!empty());
883
0
    return *AttrList.front();
884
0
  }
885
0
  const ParsedAttr &front() const {
886
0
    assert(!empty());
887
0
    return *AttrList.front();
888
0
  }
889
52
  ParsedAttr &back() {
890
52
    assert(!empty());
891
52
    return *AttrList.back();
892
52
  }
893
0
  const ParsedAttr &back() const {
894
0
    assert(!empty());
895
0
    return *AttrList.back();
896
0
  }
897
898
154M
  bool hasAttribute(ParsedAttr::Kind K) const {
899
77.1M
    return llvm::any_of(AttrList, [K](const ParsedAttr *AL) {
900
77.1M
      return AL->getParsedKind() == K;
901
77.1M
    });
902
154M
  }
903
904
private:
905
  VecTy AttrList;
906
};
907
908
/// ParsedAttributes - A collection of parsed attributes.  Currently
909
/// we don't differentiate between the various attribute syntaxes,
910
/// which is basically silly.
911
///
912
/// Right now this is a very lightweight container, but the expectation
913
/// is that this will become significantly more serious.
914
class ParsedAttributes : public ParsedAttributesView {
915
public:
916
313M
  ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
917
  ParsedAttributes(const ParsedAttributes &) = delete;
918
919
132M
  AttributePool &getPool() const { return pool; }
920
921
60.6M
  void takeAllFrom(ParsedAttributes &attrs) {
922
60.6M
    addAll(attrs.begin(), attrs.end());
923
60.6M
    attrs.clearListOnly();
924
60.6M
    pool.takeAllFrom(attrs.pool);
925
60.6M
  }
926
927
11
  void takeOneFrom(ParsedAttributes &Attrs, ParsedAttr *PA) {
928
11
    Attrs.getPool().remove(PA);
929
11
    Attrs.remove(PA);
930
11
    getPool().add(PA);
931
11
    addAtEnd(PA);
932
11
  }
933
934
69.2M
  void clear() {
935
69.2M
    clearListOnly();
936
69.2M
    pool.clear();
937
69.2M
  }
938
939
  /// Add attribute with expression arguments.
940
  ParsedAttr *addNew(IdentifierInfo *attrName, SourceRange attrRange,
941
                     IdentifierInfo *scopeName, SourceLocation scopeLoc,
942
                     ArgsUnion *args, unsigned numArgs,
943
                     ParsedAttr::Syntax syntax,
944
37.9M
                     SourceLocation ellipsisLoc = SourceLocation()) {
945
37.9M
    ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc,
946
37.9M
                                   args, numArgs, syntax, ellipsisLoc);
947
37.9M
    addAtEnd(attr);
948
37.9M
    return attr;
949
37.9M
  }
950
951
  /// Add availability attribute.
952
  ParsedAttr *addNew(IdentifierInfo *attrName, SourceRange attrRange,
953
                     IdentifierInfo *scopeName, SourceLocation scopeLoc,
954
                     IdentifierLoc *Param, const AvailabilityChange &introduced,
955
                     const AvailabilityChange &deprecated,
956
                     const AvailabilityChange &obsoleted,
957
                     SourceLocation unavailable, const Expr *MessageExpr,
958
                     ParsedAttr::Syntax syntax, SourceLocation strict,
959
7.71M
                     const Expr *ReplacementExpr) {
960
7.71M
    ParsedAttr *attr = pool.create(
961
7.71M
        attrName, attrRange, scopeName, scopeLoc, Param, introduced, deprecated,
962
7.71M
        obsoleted, unavailable, MessageExpr, syntax, strict, ReplacementExpr);
963
7.71M
    addAtEnd(attr);
964
7.71M
    return attr;
965
7.71M
  }
966
967
  /// Add objc_bridge_related attribute.
968
  ParsedAttr *addNew(IdentifierInfo *attrName, SourceRange attrRange,
969
                     IdentifierInfo *scopeName, SourceLocation scopeLoc,
970
                     IdentifierLoc *Param1, IdentifierLoc *Param2,
971
613
                     IdentifierLoc *Param3, ParsedAttr::Syntax syntax) {
972
613
    ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc,
973
613
                                   Param1, Param2, Param3, syntax);
974
613
    addAtEnd(attr);
975
613
    return attr;
976
613
  }
977
978
  /// Add type_tag_for_datatype attribute.
979
  ParsedAttr *
980
  addNewTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange,
981
                           IdentifierInfo *scopeName, SourceLocation scopeLoc,
982
                           IdentifierLoc *argumentKind,
983
                           ParsedType matchingCType, bool layoutCompatible,
984
168
                           bool mustBeNull, ParsedAttr::Syntax syntax) {
985
168
    ParsedAttr *attr = pool.createTypeTagForDatatype(
986
168
        attrName, attrRange, scopeName, scopeLoc, argumentKind, matchingCType,
987
168
        layoutCompatible, mustBeNull, syntax);
988
168
    addAtEnd(attr);
989
168
    return attr;
990
168
  }
991
992
  /// Add an attribute with a single type argument.
993
  ParsedAttr *addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange,
994
                             IdentifierInfo *scopeName, SourceLocation scopeLoc,
995
                             ParsedType typeArg,
996
67
                             ParsedAttr::Syntax syntaxUsed) {
997
67
    ParsedAttr *attr = pool.createTypeAttribute(attrName, attrRange, scopeName,
998
67
                                                scopeLoc, typeArg, syntaxUsed);
999
67
    addAtEnd(attr);
1000
67
    return attr;
1001
67
  }
1002
1003
  /// Add microsoft __delspec(property) attribute.
1004
  ParsedAttr *
1005
  addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange,
1006
                     IdentifierInfo *scopeName, SourceLocation scopeLoc,
1007
                     IdentifierInfo *getterId, IdentifierInfo *setterId,
1008
101
                     ParsedAttr::Syntax syntaxUsed) {
1009
101
    ParsedAttr *attr =
1010
101
        pool.createPropertyAttribute(attrName, attrRange, scopeName, scopeLoc,
1011
101
                                     getterId, setterId, syntaxUsed);
1012
101
    addAtEnd(attr);
1013
101
    return attr;
1014
101
  }
1015
1016
private:
1017
  mutable AttributePool pool;
1018
};
1019
1020
/// These constants match the enumerated choices of
1021
/// err_attribute_argument_n_type and err_attribute_argument_type.
1022
enum AttributeArgumentNType {
1023
  AANT_ArgumentIntOrBool,
1024
  AANT_ArgumentIntegerConstant,
1025
  AANT_ArgumentString,
1026
  AANT_ArgumentIdentifier
1027
};
1028
1029
/// These constants match the enumerated choices of
1030
/// warn_attribute_wrong_decl_type and err_attribute_wrong_decl_type.
1031
enum AttributeDeclKind {
1032
  ExpectedFunction,
1033
  ExpectedUnion,
1034
  ExpectedVariableOrFunction,
1035
  ExpectedFunctionOrMethod,
1036
  ExpectedFunctionMethodOrBlock,
1037
  ExpectedFunctionMethodOrParameter,
1038
  ExpectedVariable,
1039
  ExpectedVariableOrField,
1040
  ExpectedVariableFieldOrTag,
1041
  ExpectedTypeOrNamespace,
1042
  ExpectedFunctionVariableOrClass,
1043
  ExpectedKernelFunction,
1044
  ExpectedFunctionWithProtoType,
1045
};
1046
1047
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1048
10.6k
                                           const ParsedAttr &At) {
1049
10.6k
  DB.AddTaggedVal(reinterpret_cast<intptr_t>(At.getAttrName()),
1050
10.6k
                  DiagnosticsEngine::ak_identifierinfo);
1051
10.6k
  return DB;
1052
10.6k
}
1053
1054
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
1055
0
                                           const ParsedAttr &At) {
1056
0
  PD.AddTaggedVal(reinterpret_cast<intptr_t>(At.getAttrName()),
1057
0
                  DiagnosticsEngine::ak_identifierinfo);
1058
0
  return PD;
1059
0
}
1060
1061
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1062
72
                                           const ParsedAttr *At) {
1063
72
  DB.AddTaggedVal(reinterpret_cast<intptr_t>(At->getAttrName()),
1064
72
                  DiagnosticsEngine::ak_identifierinfo);
1065
72
  return DB;
1066
72
}
1067
1068
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
1069
0
                                           const ParsedAttr *At) {
1070
0
  PD.AddTaggedVal(reinterpret_cast<intptr_t>(At->getAttrName()),
1071
0
                  DiagnosticsEngine::ak_identifierinfo);
1072
0
  return PD;
1073
0
}
1074
1075
} // namespace clang
1076
1077
#endif // LLVM_CLANG_SEMA_ATTRIBUTELIST_H