Coverage Report

Created: 2018-09-23 03:40

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/Type.h
Line
Count
Source (jump to first uncovered line)
1
//===- Type.h - C Language Family Type Representation -----------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
/// \file
11
/// C Language Family Type Representation
12
///
13
/// This file defines the clang::Type interface and subclasses, used to
14
/// represent types for languages in the C family.
15
//
16
//===----------------------------------------------------------------------===//
17
18
#ifndef LLVM_CLANG_AST_TYPE_H
19
#define LLVM_CLANG_AST_TYPE_H
20
21
#include "clang/AST/NestedNameSpecifier.h"
22
#include "clang/AST/TemplateName.h"
23
#include "clang/Basic/AddressSpaces.h"
24
#include "clang/Basic/AttrKinds.h"
25
#include "clang/Basic/Diagnostic.h"
26
#include "clang/Basic/ExceptionSpecificationType.h"
27
#include "clang/Basic/LLVM.h"
28
#include "clang/Basic/Linkage.h"
29
#include "clang/Basic/PartialDiagnostic.h"
30
#include "clang/Basic/SourceLocation.h"
31
#include "clang/Basic/Specifiers.h"
32
#include "clang/Basic/Visibility.h"
33
#include "llvm/ADT/APInt.h"
34
#include "llvm/ADT/APSInt.h"
35
#include "llvm/ADT/ArrayRef.h"
36
#include "llvm/ADT/FoldingSet.h"
37
#include "llvm/ADT/None.h"
38
#include "llvm/ADT/Optional.h"
39
#include "llvm/ADT/PointerIntPair.h"
40
#include "llvm/ADT/PointerUnion.h"
41
#include "llvm/ADT/StringRef.h"
42
#include "llvm/ADT/Twine.h"
43
#include "llvm/ADT/iterator_range.h"
44
#include "llvm/Support/Casting.h"
45
#include "llvm/Support/Compiler.h"
46
#include "llvm/Support/ErrorHandling.h"
47
#include "llvm/Support/PointerLikeTypeTraits.h"
48
#include "llvm/Support/type_traits.h"
49
#include "llvm/Support/TrailingObjects.h"
50
#include <cassert>
51
#include <cstddef>
52
#include <cstdint>
53
#include <cstring>
54
#include <string>
55
#include <type_traits>
56
#include <utility>
57
58
namespace clang {
59
60
class ExtQuals;
61
class QualType;
62
class TagDecl;
63
class Type;
64
65
enum {
66
  TypeAlignmentInBits = 4,
67
  TypeAlignment = 1 << TypeAlignmentInBits
68
};
69
70
} // namespace clang
71
72
namespace llvm {
73
74
  template <typename T>
75
  struct PointerLikeTypeTraits;
76
  template<>
77
  struct PointerLikeTypeTraits< ::clang::Type*> {
78
644M
    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
79
80
660M
    static inline ::clang::Type *getFromVoidPointer(void *P) {
81
660M
      return static_cast< ::clang::Type*>(P);
82
660M
    }
83
84
    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
85
  };
86
87
  template<>
88
  struct PointerLikeTypeTraits< ::clang::ExtQuals*> {
89
402k
    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
90
91
1.32M
    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
92
1.32M
      return static_cast< ::clang::ExtQuals*>(P);
93
1.32M
    }
94
95
    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
96
  };
97
98
  template <>
99
  struct isPodLike<clang::QualType> { static const bool value = true; };
100
101
} // namespace llvm
102
103
namespace clang {
104
105
class ASTContext;
106
template <typename> class CanQual;
107
class CXXRecordDecl;
108
class DeclContext;
109
class EnumDecl;
110
class Expr;
111
class ExtQualsTypeCommonBase;
112
class FunctionDecl;
113
class IdentifierInfo;
114
class NamedDecl;
115
class ObjCInterfaceDecl;
116
class ObjCProtocolDecl;
117
class ObjCTypeParamDecl;
118
struct PrintingPolicy;
119
class RecordDecl;
120
class Stmt;
121
class TagDecl;
122
class TemplateArgument;
123
class TemplateArgumentListInfo;
124
class TemplateArgumentLoc;
125
class TemplateTypeParmDecl;
126
class TypedefNameDecl;
127
class UnresolvedUsingTypenameDecl;
128
129
using CanQualType = CanQual<Type>;
130
131
// Provide forward declarations for all of the *Type classes.
132
#define TYPE(Class, Base) class Class##Type;
133
#include "clang/AST/TypeNodes.def"
134
135
/// The collection of all-type qualifiers we support.
136
/// Clang supports five independent qualifiers:
137
/// * C99: const, volatile, and restrict
138
/// * MS: __unaligned
139
/// * Embedded C (TR18037): address spaces
140
/// * Objective C: the GC attributes (none, weak, or strong)
141
0
class Qualifiers {
142
public:
143
  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
144
    Const    = 0x1,
145
    Restrict = 0x2,
146
    Volatile = 0x4,
147
    CVRMask = Const | Volatile | Restrict
148
  };
149
150
  enum GC {
151
    GCNone = 0,
152
    Weak,
153
    Strong
154
  };
155
156
  enum ObjCLifetime {
157
    /// There is no lifetime qualification on this type.
158
    OCL_None,
159
160
    /// This object can be modified without requiring retains or
161
    /// releases.
162
    OCL_ExplicitNone,
163
164
    /// Assigning into this object requires the old value to be
165
    /// released and the new value to be retained.  The timing of the
166
    /// release of the old value is inexact: it may be moved to
167
    /// immediately after the last known point where the value is
168
    /// live.
169
    OCL_Strong,
170
171
    /// Reading or writing from this object requires a barrier call.
172
    OCL_Weak,
173
174
    /// Assigning into this object requires a lifetime extension.
175
    OCL_Autoreleasing
176
  };
177
178
  enum {
179
    /// The maximum supported address space number.
180
    /// 23 bits should be enough for anyone.
181
    MaxAddressSpace = 0x7fffffu,
182
183
    /// The width of the "fast" qualifier mask.
184
    FastWidth = 3,
185
186
    /// The fast qualifier mask.
187
    FastMask = (1 << FastWidth) - 1
188
  };
189
190
  /// Returns the common set of qualifiers while removing them from
191
  /// the given sets.
192
457k
  static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) {
193
457k
    // If both are only CVR-qualified, bit operations are sufficient.
194
457k
    if (!(L.Mask & ~CVRMask) && 
!(R.Mask & ~CVRMask)457k
) {
195
456k
      Qualifiers Q;
196
456k
      Q.Mask = L.Mask & R.Mask;
197
456k
      L.Mask &= ~Q.Mask;
198
456k
      R.Mask &= ~Q.Mask;
199
456k
      return Q;
200
456k
    }
201
859
202
859
    Qualifiers Q;
203
859
    unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
204
859
    Q.addCVRQualifiers(CommonCRV);
205
859
    L.removeCVRQualifiers(CommonCRV);
206
859
    R.removeCVRQualifiers(CommonCRV);
207
859
208
859
    if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
209
851
      Q.setObjCGCAttr(L.getObjCGCAttr());
210
851
      L.removeObjCGCAttr();
211
851
      R.removeObjCGCAttr();
212
851
    }
213
859
214
859
    if (L.getObjCLifetime() == R.getObjCLifetime()) {
215
707
      Q.setObjCLifetime(L.getObjCLifetime());
216
707
      L.removeObjCLifetime();
217
707
      R.removeObjCLifetime();
218
707
    }
219
859
220
859
    if (L.getAddressSpace() == R.getAddressSpace()) {
221
165
      Q.setAddressSpace(L.getAddressSpace());
222
165
      L.removeAddressSpace();
223
165
      R.removeAddressSpace();
224
165
    }
225
859
    return Q;
226
859
  }
227
228
34.0M
  static Qualifiers fromFastMask(unsigned Mask) {
229
34.0M
    Qualifiers Qs;
230
34.0M
    Qs.addFastQualifiers(Mask);
231
34.0M
    return Qs;
232
34.0M
  }
233
234
7.17M
  static Qualifiers fromCVRMask(unsigned CVR) {
235
7.17M
    Qualifiers Qs;
236
7.17M
    Qs.addCVRQualifiers(CVR);
237
7.17M
    return Qs;
238
7.17M
  }
239
240
6.90M
  static Qualifiers fromCVRUMask(unsigned CVRU) {
241
6.90M
    Qualifiers Qs;
242
6.90M
    Qs.addCVRUQualifiers(CVRU);
243
6.90M
    return Qs;
244
6.90M
  }
245
246
  // Deserialize qualifiers from an opaque representation.
247
367
  static Qualifiers fromOpaqueValue(unsigned opaque) {
248
367
    Qualifiers Qs;
249
367
    Qs.Mask = opaque;
250
367
    return Qs;
251
367
  }
252
253
  // Serialize these qualifiers into an opaque representation.
254
836k
  unsigned getAsOpaqueValue() const {
255
836k
    return Mask;
256
836k
  }
257
258
3.04M
  bool hasConst() const { return Mask & Const; }
259
  void setConst(bool flag) {
260
    Mask = (Mask & ~Const) | (flag ? Const : 0);
261
  }
262
20.3k
  void removeConst() { Mask &= ~Const; }
263
332k
  void addConst() { Mask |= Const; }
264
265
9.06M
  bool hasVolatile() const { return Mask & Volatile; }
266
5
  void setVolatile(bool flag) {
267
5
    Mask = (Mask & ~Volatile) | (flag ? Volatile : 
00
);
268
5
  }
269
98
  void removeVolatile() { Mask &= ~Volatile; }
270
265k
  void addVolatile() { Mask |= Volatile; }
271
272
4.76M
  bool hasRestrict() const { return Mask & Restrict; }
273
  void setRestrict(bool flag) {
274
    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
275
  }
276
691k
  void removeRestrict() { Mask &= ~Restrict; }
277
265k
  void addRestrict() { Mask |= Restrict; }
278
279
10
  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
280
11.7M
  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
281
1.11M
  void setCVRQualifiers(unsigned mask) {
282
1.11M
    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
283
1.11M
    Mask = (Mask & ~CVRMask) | mask;
284
1.11M
  }
285
2.29M
  void removeCVRQualifiers(unsigned mask) {
286
2.29M
    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
287
2.29M
    Mask &= ~mask;
288
2.29M
  }
289
450k
  void removeCVRQualifiers() {
290
450k
    removeCVRQualifiers(CVRMask);
291
450k
  }
292
7.81M
  void addCVRQualifiers(unsigned mask) {
293
7.81M
    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
294
7.81M
    Mask |= mask;
295
7.81M
  }
296
6.90M
  void addCVRUQualifiers(unsigned mask) {
297
6.90M
    assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits");
298
6.90M
    Mask |= mask;
299
6.90M
  }
300
301
12.1M
  bool hasUnaligned() const { return Mask & UMask; }
302
2.67M
  void setUnaligned(bool flag) {
303
2.67M
    Mask = (Mask & ~UMask) | (flag ? 
UMask142
:
02.67M
);
304
2.67M
  }
305
3.63M
  void removeUnaligned() { Mask &= ~UMask; }
306
  void addUnaligned() { Mask |= UMask; }
307
308
1.84M
  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
309
19.8M
  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
310
13.4M
  void setObjCGCAttr(GC type) {
311
13.4M
    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
312
13.4M
  }
313
4.20M
  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
314
255
  void addObjCGCAttr(GC type) {
315
255
    assert(type);
316
255
    setObjCGCAttr(type);
317
255
  }
318
202
  Qualifiers withoutObjCGCAttr() const {
319
202
    Qualifiers qs = *this;
320
202
    qs.removeObjCGCAttr();
321
202
    return qs;
322
202
  }
323
326
  Qualifiers withoutObjCLifetime() const {
324
326
    Qualifiers qs = *this;
325
326
    qs.removeObjCLifetime();
326
326
    return qs;
327
326
  }
328
329
14.6M
  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
330
53.9M
  ObjCLifetime getObjCLifetime() const {
331
53.9M
    return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
332
53.9M
  }
333
289k
  void setObjCLifetime(ObjCLifetime type) {
334
289k
    Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
335
289k
  }
336
286k
  void removeObjCLifetime() { setObjCLifetime(OCL_None); }
337
6.76k
  void addObjCLifetime(ObjCLifetime type) {
338
6.76k
    assert(type);
339
6.76k
    assert(!hasObjCLifetime());
340
6.76k
    Mask |= (type << LifetimeShift);
341
6.76k
  }
342
343
  /// True if the lifetime is neither None or ExplicitNone.
344
4.32M
  bool hasNonTrivialObjCLifetime() const {
345
4.32M
    ObjCLifetime lifetime = getObjCLifetime();
346
4.32M
    return (lifetime > OCL_ExplicitNone);
347
4.32M
  }
348
349
  /// True if the lifetime is either strong or weak.
350
423
  bool hasStrongOrWeakObjCLifetime() const {
351
423
    ObjCLifetime lifetime = getObjCLifetime();
352
423
    return (lifetime == OCL_Strong || 
lifetime == OCL_Weak421
);
353
423
  }
354
355
22.1M
  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
356
74.5M
  LangAS getAddressSpace() const {
357
74.5M
    return static_cast<LangAS>(Mask >> AddressSpaceShift);
358
74.5M
  }
359
  bool hasTargetSpecificAddressSpace() const {
360
    return isTargetAddressSpace(getAddressSpace());
361
  }
362
  /// Get the address space attribute value to be printed by diagnostics.
363
10
  unsigned getAddressSpaceAttributePrintValue() const {
364
10
    auto Addr = getAddressSpace();
365
10
    // This function is not supposed to be used with language specific
366
10
    // address spaces. If that happens, the diagnostic message should consider
367
10
    // printing the QualType instead of the address space value.
368
10
    assert(Addr == LangAS::Default || hasTargetSpecificAddressSpace());
369
10
    if (Addr != LangAS::Default)
370
10
      return toTargetAddressSpace(Addr);
371
0
    // TODO: The diagnostic messages where Addr may be 0 should be fixed
372
0
    // since it cannot differentiate the situation where 0 denotes the default
373
0
    // address space or user specified __attribute__((address_space(0))).
374
0
    return 0;
375
0
  }
376
427k
  void setAddressSpace(LangAS space) {
377
427k
    assert((unsigned)space <= MaxAddressSpace);
378
427k
    Mask = (Mask & ~AddressSpaceMask)
379
427k
         | (((uint32_t) space) << AddressSpaceShift);
380
427k
  }
381
1.41k
  void removeAddressSpace() { setAddressSpace(LangAS::Default); }
382
359k
  void addAddressSpace(LangAS space) {
383
359k
    assert(space != LangAS::Default);
384
359k
    setAddressSpace(space);
385
359k
  }
386
387
  // Fast qualifiers are those that can be allocated directly
388
  // on a QualType object.
389
  bool hasFastQualifiers() const { return getFastQualifiers(); }
390
42.1M
  unsigned getFastQualifiers() const { return Mask & FastMask; }
391
  void setFastQualifiers(unsigned mask) {
392
    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
393
    Mask = (Mask & ~FastMask) | mask;
394
  }
395
385k
  void removeFastQualifiers(unsigned mask) {
396
385k
    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
397
385k
    Mask &= ~mask;
398
385k
  }
399
385k
  void removeFastQualifiers() {
400
385k
    removeFastQualifiers(FastMask);
401
385k
  }
402
473M
  void addFastQualifiers(unsigned mask) {
403
473M
    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
404
473M
    Mask |= mask;
405
473M
  }
406
407
  /// Return true if the set contains any qualifiers which require an ExtQuals
408
  /// node to be allocated.
409
41.7M
  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
410
  Qualifiers getNonFastQualifiers() const {
411
    Qualifiers Quals = *this;
412
    Quals.setFastQualifiers(0);
413
    return Quals;
414
  }
415
416
  /// Return true if the set contains any qualifiers.
417
17.6M
  bool hasQualifiers() const { return Mask; }
418
1.19M
  bool empty() const { return !Mask; }
419
420
  /// Add the qualifiers from the given set to this set.
421
3.45M
  void addQualifiers(Qualifiers Q) {
422
3.45M
    // If the other set doesn't have any non-boolean qualifiers, just
423
3.45M
    // bit-or it in.
424
3.45M
    if (!(Q.Mask & ~CVRMask))
425
3.45M
      Mask |= Q.Mask;
426
953
    else {
427
953
      Mask |= (Q.Mask & CVRMask);
428
953
      if (Q.hasAddressSpace())
429
690
        addAddressSpace(Q.getAddressSpace());
430
953
      if (Q.hasObjCGCAttr())
431
38
        addObjCGCAttr(Q.getObjCGCAttr());
432
953
      if (Q.hasObjCLifetime())
433
221
        addObjCLifetime(Q.getObjCLifetime());
434
953
    }
435
3.45M
  }
436
437
  /// Remove the qualifiers from the given set from this set.
438
24.5k
  void removeQualifiers(Qualifiers Q) {
439
24.5k
    // If the other set doesn't have any non-boolean qualifiers, just
440
24.5k
    // bit-and the inverse in.
441
24.5k
    if (!(Q.Mask & ~CVRMask))
442
24.5k
      Mask &= ~Q.Mask;
443
4
    else {
444
4
      Mask &= ~(Q.Mask & CVRMask);
445
4
      if (getObjCGCAttr() == Q.getObjCGCAttr())
446
4
        removeObjCGCAttr();
447
4
      if (getObjCLifetime() == Q.getObjCLifetime())
448
4
        removeObjCLifetime();
449
4
      if (getAddressSpace() == Q.getAddressSpace())
450
0
        removeAddressSpace();
451
4
    }
452
24.5k
  }
453
454
  /// Add the qualifiers from the given set to this set, given that
455
  /// they don't conflict.
456
1.06M
  void addConsistentQualifiers(Qualifiers qs) {
457
1.06M
    assert(getAddressSpace() == qs.getAddressSpace() ||
458
1.06M
           !hasAddressSpace() || !qs.hasAddressSpace());
459
1.06M
    assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
460
1.06M
           !hasObjCGCAttr() || !qs.hasObjCGCAttr());
461
1.06M
    assert(getObjCLifetime() == qs.getObjCLifetime() ||
462
1.06M
           !hasObjCLifetime() || !qs.hasObjCLifetime());
463
1.06M
    Mask |= qs.Mask;
464
1.06M
  }
465
466
  /// Returns true if this address space is a superset of the other one.
467
  /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of
468
  /// overlapping address spaces.
469
  /// CL1.1 or CL1.2:
470
  ///   every address space is a superset of itself.
471
  /// CL2.0 adds:
472
  ///   __generic is a superset of any address space except for __constant.
473
5.29M
  bool isAddressSpaceSupersetOf(Qualifiers other) const {
474
5.29M
    return
475
5.29M
        // Address spaces must match exactly.
476
5.29M
        getAddressSpace() == other.getAddressSpace() ||
477
5.29M
        // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
478
5.29M
        // for __constant can be used as __generic.
479
5.29M
        
(995
getAddressSpace() == LangAS::opencl_generic995
&&
480
995
         
other.getAddressSpace() != LangAS::opencl_constant351
);
481
5.29M
  }
482
483
  /// Determines if these qualifiers compatibly include another set.
484
  /// Generally this answers the question of whether an object with the other
485
  /// qualifiers can be safely used as an object with these qualifiers.
486
3.83M
  bool compatiblyIncludes(Qualifiers other) const {
487
3.83M
    return isAddressSpaceSupersetOf(other) &&
488
3.83M
           // ObjC GC qualifiers can match, be added, or be removed, but can't
489
3.83M
           // be changed.
490
3.83M
           
(3.83M
getObjCGCAttr() == other.getObjCGCAttr()3.83M
||
!hasObjCGCAttr()18
||
491
3.83M
            
!other.hasObjCGCAttr()15
) &&
492
3.83M
           // ObjC lifetime qualifiers must match exactly.
493
3.83M
           
getObjCLifetime() == other.getObjCLifetime()3.83M
&&
494
3.83M
           // CVR qualifiers may subset.
495
3.83M
           
(((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask))3.83M
&&
496
3.83M
           // U qualifier may superset.
497
3.83M
           
(3.23M
!other.hasUnaligned()3.23M
||
hasUnaligned()35
);
498
3.83M
  }
499
500
  /// Determines if these qualifiers compatibly include another set of
501
  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
502
  ///
503
  /// One set of Objective-C lifetime qualifiers compatibly includes the other
504
  /// if the lifetime qualifiers match, or if both are non-__weak and the
505
  /// including set also contains the 'const' qualifier, or both are non-__weak
506
  /// and one is None (which can only happen in non-ARC modes).
507
474
  bool compatiblyIncludesObjCLifetime(Qualifiers other) const {
508
474
    if (getObjCLifetime() == other.getObjCLifetime())
509
240
      return true;
510
234
511
234
    if (getObjCLifetime() == OCL_Weak || 
other.getObjCLifetime() == OCL_Weak184
)
512
113
      return false;
513
121
514
121
    if (getObjCLifetime() == OCL_None || 
other.getObjCLifetime() == OCL_None93
)
515
55
      return true;
516
66
517
66
    return hasConst();
518
66
  }
519
520
  /// Determine whether this set of qualifiers is a strict superset of
521
  /// another set of qualifiers, not considering qualifier compatibility.
522
  bool isStrictSupersetOf(Qualifiers Other) const;
523
524
3.00M
  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
525
37.0M
  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
526
527
17.6M
  explicit operator bool() const { return hasQualifiers(); }
528
529
3.45M
  Qualifiers &operator+=(Qualifiers R) {
530
3.45M
    addQualifiers(R);
531
3.45M
    return *this;
532
3.45M
  }
533
534
  // Union two qualifier sets.  If an enumerated qualifier appears
535
  // in both sets, use the one from the right.
536
1.97M
  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
537
1.97M
    L += R;
538
1.97M
    return L;
539
1.97M
  }
540
541
24.5k
  Qualifiers &operator-=(Qualifiers R) {
542
24.5k
    removeQualifiers(R);
543
24.5k
    return *this;
544
24.5k
  }
545
546
  /// Compute the difference between two qualifier sets.
547
20.0k
  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
548
20.0k
    L -= R;
549
20.0k
    return L;
550
20.0k
  }
551
552
  std::string getAsString() const;
553
  std::string getAsString(const PrintingPolicy &Policy) const;
554
555
  bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
556
  void print(raw_ostream &OS, const PrintingPolicy &Policy,
557
             bool appendSpaceIfNonEmpty = false) const;
558
559
1.00M
  void Profile(llvm::FoldingSetNodeID &ID) const {
560
1.00M
    ID.AddInteger(Mask);
561
1.00M
  }
562
563
private:
564
  // bits:     |0 1 2|3|4 .. 5|6  ..  8|9   ...   31|
565
  //           |C R V|U|GCAttr|Lifetime|AddressSpace|
566
  uint32_t Mask = 0;
567
568
  static const uint32_t UMask = 0x8;
569
  static const uint32_t UShift = 3;
570
  static const uint32_t GCAttrMask = 0x30;
571
  static const uint32_t GCAttrShift = 4;
572
  static const uint32_t LifetimeMask = 0x1C0;
573
  static const uint32_t LifetimeShift = 6;
574
  static const uint32_t AddressSpaceMask =
575
      ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
576
  static const uint32_t AddressSpaceShift = 9;
577
};
578
579
/// A std::pair-like structure for storing a qualified type split
580
/// into its local qualifiers and its locally-unqualified type.
581
struct SplitQualType {
582
  /// The locally-unqualified type.
583
  const Type *Ty = nullptr;
584
585
  /// The local qualifiers.
586
  Qualifiers Quals;
587
588
  SplitQualType() = default;
589
58.7M
  SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
590
591
  SplitQualType getSingleStepDesugaredType() const; // end of this file
592
593
  // Make std::tie work.
594
517k
  std::pair<const Type *,Qualifiers> asPair() const {
595
517k
    return std::pair<const Type *, Qualifiers>(Ty, Quals);
596
517k
  }
597
598
0
  friend bool operator==(SplitQualType a, SplitQualType b) {
599
0
    return a.Ty == b.Ty && a.Quals == b.Quals;
600
0
  }
601
11.1k
  friend bool operator!=(SplitQualType a, SplitQualType b) {
602
11.1k
    return a.Ty != b.Ty || 
a.Quals != b.Quals10.0k
;
603
11.1k
  }
604
};
605
606
/// The kind of type we are substituting Objective-C type arguments into.
607
///
608
/// The kind of substitution affects the replacement of type parameters when
609
/// no concrete type information is provided, e.g., when dealing with an
610
/// unspecialized type.
611
enum class ObjCSubstitutionContext {
612
  /// An ordinary type.
613
  Ordinary,
614
615
  /// The result type of a method or function.
616
  Result,
617
618
  /// The parameter type of a method or function.
619
  Parameter,
620
621
  /// The type of a property.
622
  Property,
623
624
  /// The superclass of a type.
625
  Superclass,
626
};
627
628
/// A (possibly-)qualified type.
629
///
630
/// For efficiency, we don't store CV-qualified types as nodes on their
631
/// own: instead each reference to a type stores the qualifiers.  This
632
/// greatly reduces the number of nodes we need to allocate for types (for
633
/// example we only need one for 'int', 'const int', 'volatile int',
634
/// 'const volatile int', etc).
635
///
636
/// As an added efficiency bonus, instead of making this a pair, we
637
/// just store the two bits we care about in the low bits of the
638
/// pointer.  To handle the packing/unpacking, we make QualType be a
639
/// simple wrapper class that acts like a smart pointer.  A third bit
640
/// indicates whether there are extended qualifiers present, in which
641
/// case the pointer points to a special structure.
642
0
class QualType {
Unexecuted instantiation: clang::QualType::operator=(clang::QualType const&)
Unexecuted instantiation: clang::QualType::operator=(clang::QualType&&)
643
  friend class QualifierCollector;
644
645
  // Thankfully, these are efficiently composable.
646
  llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
647
                       Qualifiers::FastWidth> Value;
648
649
1.32M
  const ExtQuals *getExtQualsUnsafe() const {
650
1.32M
    return Value.getPointer().get<const ExtQuals*>();
651
1.32M
  }
652
653
73.2M
  const Type *getTypePtrUnsafe() const {
654
73.2M
    return Value.getPointer().get<const Type*>();
655
73.2M
  }
656
657
10.1G
  const ExtQualsTypeCommonBase *getCommonPtr() const {
658
10.1G
    assert(!isNull() && "Cannot retrieve a NULL type pointer");
659
10.1G
    auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
660
10.1G
    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
661
10.1G
    return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
662
10.1G
  }
663
664
public:
665
3.39G
  QualType() = default;
666
642M
  QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
667
402k
  QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
668
669
2.37G
  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
670
0
  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
671
672
  /// Retrieves a pointer to the underlying (unqualified) type.
673
  ///
674
  /// This function requires that the type not be NULL. If the type might be
675
  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
676
  const Type *getTypePtr() const;
677
678
  const Type *getTypePtrOrNull() const;
679
680
  /// Retrieves a pointer to the name of the base type.
681
  const IdentifierInfo *getBaseTypeIdentifier() const;
682
683
  /// Divides a QualType into its unqualified type and a set of local
684
  /// qualifiers.
685
  SplitQualType split() const;
686
687
1.07G
  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
688
689
1.87G
  static QualType getFromOpaquePtr(const void *Ptr) {
690
1.87G
    QualType T;
691
1.87G
    T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
692
1.87G
    return T;
693
1.87G
  }
694
695
4.07M
  const Type &operator*() const {
696
4.07M
    return *getTypePtr();
697
4.07M
  }
698
699
4.09G
  const Type *operator->() const {
700
4.09G
    return getTypePtr();
701
4.09G
  }
702
703
  bool isCanonical() const;
704
  bool isCanonicalAsParam() const;
705
706
  /// Return true if this QualType doesn't point to a type yet.
707
583M
  bool isNull() const {
708
583M
    return Value.getPointer().isNull();
709
583M
  }
710
711
  /// Determine whether this particular QualType instance has the
712
  /// "const" qualifier set, without looking through typedefs that may have
713
  /// added "const" at a different level.
714
74.3M
  bool isLocalConstQualified() const {
715
74.3M
    return (getLocalFastQualifiers() & Qualifiers::Const);
716
74.3M
  }
717
718
  /// Determine whether this type is const-qualified.
719
  bool isConstQualified() const;
720
721
  /// Determine whether this particular QualType instance has the
722
  /// "restrict" qualifier set, without looking through typedefs that may have
723
  /// added "restrict" at a different level.
724
1.74M
  bool isLocalRestrictQualified() const {
725
1.74M
    return (getLocalFastQualifiers() & Qualifiers::Restrict);
726
1.74M
  }
727
728
  /// Determine whether this type is restrict-qualified.
729
  bool isRestrictQualified() const;
730
731
  /// Determine whether this particular QualType instance has the
732
  /// "volatile" qualifier set, without looking through typedefs that may have
733
  /// added "volatile" at a different level.
734
46.1M
  bool isLocalVolatileQualified() const {
735
46.1M
    return (getLocalFastQualifiers() & Qualifiers::Volatile);
736
46.1M
  }
737
738
  /// Determine whether this type is volatile-qualified.
739
  bool isVolatileQualified() const;
740
741
  /// Determine whether this particular QualType instance has any
742
  /// qualifiers, without looking through any typedefs that might add
743
  /// qualifiers at a different level.
744
1.02G
  bool hasLocalQualifiers() const {
745
1.02G
    return getLocalFastQualifiers() || 
hasLocalNonFastQualifiers()1.00G
;
746
1.02G
  }
747
748
  /// Determine whether this type has any qualifiers.
749
  bool hasQualifiers() const;
750
751
  /// Determine whether this particular QualType instance has any
752
  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
753
  /// instance.
754
1.31G
  bool hasLocalNonFastQualifiers() const {
755
1.31G
    return Value.getPointer().is<const ExtQuals*>();
756
1.31G
  }
757
758
  /// Retrieve the set of qualifiers local to this particular QualType
759
  /// instance, not including any qualifiers acquired through typedefs or
760
  /// other sugar.
761
  Qualifiers getLocalQualifiers() const;
762
763
  /// Retrieve the set of qualifiers applied to this type.
764
  Qualifiers getQualifiers() const;
765
766
  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
767
  /// local to this particular QualType instance, not including any qualifiers
768
  /// acquired through typedefs or other sugar.
769
30.0M
  unsigned getLocalCVRQualifiers() const {
770
30.0M
    return getLocalFastQualifiers();
771
30.0M
  }
772
773
  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
774
  /// applied to this type.
775
  unsigned getCVRQualifiers() const;
776
777
693k
  bool isConstant(const ASTContext& Ctx) const {
778
693k
    return QualType::isConstant(*this, Ctx);
779
693k
  }
780
781
  /// Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
782
  bool isPODType(const ASTContext &Context) const;
783
784
  /// Return true if this is a POD type according to the rules of the C++98
785
  /// standard, regardless of the current compilation's language.
786
  bool isCXX98PODType(const ASTContext &Context) const;
787
788
  /// Return true if this is a POD type according to the more relaxed rules
789
  /// of the C++11 standard, regardless of the current compilation's language.
790
  /// (C++0x [basic.types]p9). Note that, unlike
791
  /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account.
792
  bool isCXX11PODType(const ASTContext &Context) const;
793
794
  /// Return true if this is a trivial type per (C++0x [basic.types]p9)
795
  bool isTrivialType(const ASTContext &Context) const;
796
797
  /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
798
  bool isTriviallyCopyableType(const ASTContext &Context) const;
799
800
801
  /// Returns true if it is a class and it might be dynamic.
802
  bool mayBeDynamicClass() const;
803
804
  /// Returns true if it is not a class or if the class might not be dynamic.
805
  bool mayBeNotDynamicClass() const;
806
807
  // Don't promise in the API that anything besides 'const' can be
808
  // easily added.
809
810
  /// Add the `const` type qualifier to this QualType.
811
2.23M
  void addConst() {
812
2.23M
    addFastQualifiers(Qualifiers::Const);
813
2.23M
  }
814
1.43M
  QualType withConst() const {
815
1.43M
    return withFastQualifiers(Qualifiers::Const);
816
1.43M
  }
817
818
  /// Add the `volatile` type qualifier to this QualType.
819
36
  void addVolatile() {
820
36
    addFastQualifiers(Qualifiers::Volatile);
821
36
  }
822
248
  QualType withVolatile() const {
823
248
    return withFastQualifiers(Qualifiers::Volatile);
824
248
  }
825
826
  /// Add the `restrict` qualifier to this QualType.
827
0
  void addRestrict() {
828
0
    addFastQualifiers(Qualifiers::Restrict);
829
0
  }
830
624k
  QualType withRestrict() const {
831
624k
    return withFastQualifiers(Qualifiers::Restrict);
832
624k
  }
833
834
3.29M
  QualType withCVRQualifiers(unsigned CVR) const {
835
3.29M
    return withFastQualifiers(CVR);
836
3.29M
  }
837
838
774M
  void addFastQualifiers(unsigned TQs) {
839
774M
    assert(!(TQs & ~Qualifiers::FastMask)
840
774M
           && "non-fast qualifier bits set in mask!");
841
774M
    Value.setInt(Value.getInt() | TQs);
842
774M
  }
843
844
  void removeLocalConst();
845
  void removeLocalVolatile();
846
  void removeLocalRestrict();
847
  void removeLocalCVRQualifiers(unsigned Mask);
848
849
1.81M
  void removeLocalFastQualifiers() { Value.setInt(0); }
850
8.62k
  void removeLocalFastQualifiers(unsigned Mask) {
851
8.62k
    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
852
8.62k
    Value.setInt(Value.getInt() & ~Mask);
853
8.62k
  }
854
855
  // Creates a type with the given qualifiers in addition to any
856
  // qualifiers already on this type.
857
771M
  QualType withFastQualifiers(unsigned TQs) const {
858
771M
    QualType T = *this;
859
771M
    T.addFastQualifiers(TQs);
860
771M
    return T;
861
771M
  }
862
863
  // Creates a type with exactly the given fast qualifiers, removing
864
  // any existing fast qualifiers.
865
0
  QualType withExactLocalFastQualifiers(unsigned TQs) const {
866
0
    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
867
0
  }
868
869
  // Removes fast qualifiers, but leaves any extended qualifiers in place.
870
83
  QualType withoutLocalFastQualifiers() const {
871
83
    QualType T = *this;
872
83
    T.removeLocalFastQualifiers();
873
83
    return T;
874
83
  }
875
876
  QualType getCanonicalType() const;
877
878
  /// Return this type with all of the instance-specific qualifiers
879
  /// removed, but without removing any qualifiers that may have been applied
880
  /// through typedefs.
881
107M
  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
882
883
  /// Retrieve the unqualified variant of the given type,
884
  /// removing as little sugar as possible.
885
  ///
886
  /// This routine looks through various kinds of sugar to find the
887
  /// least-desugared type that is unqualified. For example, given:
888
  ///
889
  /// \code
890
  /// typedef int Integer;
891
  /// typedef const Integer CInteger;
892
  /// typedef CInteger DifferenceType;
893
  /// \endcode
894
  ///
895
  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
896
  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
897
  ///
898
  /// The resulting type might still be qualified if it's sugar for an array
899
  /// type.  To strip qualifiers even from within a sugared array type, use
900
  /// ASTContext::getUnqualifiedArrayType.
901
  inline QualType getUnqualifiedType() const;
902
903
  /// Retrieve the unqualified variant of the given type, removing as little
904
  /// sugar as possible.
905
  ///
906
  /// Like getUnqualifiedType(), but also returns the set of
907
  /// qualifiers that were built up.
908
  ///
909
  /// The resulting type might still be qualified if it's sugar for an array
910
  /// type.  To strip qualifiers even from within a sugared array type, use
911
  /// ASTContext::getUnqualifiedArrayType.
912
  inline SplitQualType getSplitUnqualifiedType() const;
913
914
  /// Determine whether this type is more qualified than the other
915
  /// given type, requiring exact equality for non-CVR qualifiers.
916
  bool isMoreQualifiedThan(QualType Other) const;
917
918
  /// Determine whether this type is at least as qualified as the other
919
  /// given type, requiring exact equality for non-CVR qualifiers.
920
  bool isAtLeastAsQualifiedAs(QualType Other) const;
921
922
  QualType getNonReferenceType() const;
923
924
  /// Determine the type of a (typically non-lvalue) expression with the
925
  /// specified result type.
926
  ///
927
  /// This routine should be used for expressions for which the return type is
928
  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
929
  /// an lvalue. It removes a top-level reference (since there are no
930
  /// expressions of reference type) and deletes top-level cvr-qualifiers
931
  /// from non-class types (in C++) or all types (in C).
932
  QualType getNonLValueExprType(const ASTContext &Context) const;
933
934
  /// Return the specified type with any "sugar" removed from
935
  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
936
  /// the type is already concrete, it returns it unmodified.  This is similar
937
  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
938
  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
939
  /// concrete.
940
  ///
941
  /// Qualifiers are left in place.
942
67.9k
  QualType getDesugaredType(const ASTContext &Context) const {
943
67.9k
    return getDesugaredType(*this, Context);
944
67.9k
  }
945
946
24.4M
  SplitQualType getSplitDesugaredType() const {
947
24.4M
    return getSplitDesugaredType(*this);
948
24.4M
  }
949
950
  /// Return the specified type with one level of "sugar" removed from
951
  /// the type.
952
  ///
953
  /// This routine takes off the first typedef, typeof, etc. If the outer level
954
  /// of the type is already concrete, it returns it unmodified.
955
705
  QualType getSingleStepDesugaredType(const ASTContext &Context) const {
956
705
    return getSingleStepDesugaredTypeImpl(*this, Context);
957
705
  }
958
959
  /// Returns the specified type after dropping any
960
  /// outer-level parentheses.
961
6.20k
  QualType IgnoreParens() const {
962
6.20k
    if (isa<ParenType>(*this))
963
6
      return QualType::IgnoreParens(*this);
964
6.20k
    return *this;
965
6.20k
  }
966
967
  /// Indicate whether the specified types and qualifiers are identical.
968
650M
  friend bool operator==(const QualType &LHS, const QualType &RHS) {
969
650M
    return LHS.Value == RHS.Value;
970
650M
  }
971
58.7M
  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
972
58.7M
    return LHS.Value != RHS.Value;
973
58.7M
  }
974
975
  static std::string getAsString(SplitQualType split,
976
40.7k
                                 const PrintingPolicy &Policy) {
977
40.7k
    return getAsString(split.Ty, split.Quals, Policy);
978
40.7k
  }
979
  static std::string getAsString(const Type *ty, Qualifiers qs,
980
                                 const PrintingPolicy &Policy);
981
982
  std::string getAsString() const;
983
  std::string getAsString(const PrintingPolicy &Policy) const;
984
985
  void print(raw_ostream &OS, const PrintingPolicy &Policy,
986
             const Twine &PlaceHolder = Twine(),
987
432k
             unsigned Indentation = 0) const {
988
432k
    print(split(), OS, Policy, PlaceHolder, Indentation);
989
432k
  }
990
991
  static void print(SplitQualType split, raw_ostream &OS,
992
                    const PrintingPolicy &policy, const Twine &PlaceHolder,
993
432k
                    unsigned Indentation = 0) {
994
432k
    return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation);
995
432k
  }
996
997
  static void print(const Type *ty, Qualifiers qs,
998
                    raw_ostream &OS, const PrintingPolicy &policy,
999
                    const Twine &PlaceHolder,
1000
                    unsigned Indentation = 0);
1001
1002
  void getAsStringInternal(std::string &Str,
1003
164k
                           const PrintingPolicy &Policy) const {
1004
164k
    return getAsStringInternal(split(), Str, Policy);
1005
164k
  }
1006
1007
  static void getAsStringInternal(SplitQualType split, std::string &out,
1008
164k
                                  const PrintingPolicy &policy) {
1009
164k
    return getAsStringInternal(split.Ty, split.Quals, out, policy);
1010
164k
  }
1011
1012
  static void getAsStringInternal(const Type *ty, Qualifiers qs,
1013
                                  std::string &out,
1014
                                  const PrintingPolicy &policy);
1015
1016
  class StreamedQualTypeHelper {
1017
    const QualType &T;
1018
    const PrintingPolicy &Policy;
1019
    const Twine &PlaceHolder;
1020
    unsigned Indentation;
1021
1022
  public:
1023
    StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy,
1024
                           const Twine &PlaceHolder, unsigned Indentation)
1025
        : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1026
2.06k
          Indentation(Indentation) {}
1027
1028
    friend raw_ostream &operator<<(raw_ostream &OS,
1029
2.06k
                                   const StreamedQualTypeHelper &SQT) {
1030
2.06k
      SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1031
2.06k
      return OS;
1032
2.06k
    }
1033
  };
1034
1035
  StreamedQualTypeHelper stream(const PrintingPolicy &Policy,
1036
                                const Twine &PlaceHolder = Twine(),
1037
2.06k
                                unsigned Indentation = 0) const {
1038
2.06k
    return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation);
1039
2.06k
  }
1040
1041
  void dump(const char *s) const;
1042
  void dump() const;
1043
  void dump(llvm::raw_ostream &OS) const;
1044
1045
32.7M
  void Profile(llvm::FoldingSetNodeID &ID) const {
1046
32.7M
    ID.AddPointer(getAsOpaquePtr());
1047
32.7M
  }
1048
1049
  /// Return the address space of this type.
1050
  inline LangAS getAddressSpace() const;
1051
1052
  /// Returns gc attribute of this type.
1053
  inline Qualifiers::GC getObjCGCAttr() const;
1054
1055
  /// true when Type is objc's weak.
1056
4.17M
  bool isObjCGCWeak() const {
1057
4.17M
    return getObjCGCAttr() == Qualifiers::Weak;
1058
4.17M
  }
1059
1060
  /// true when Type is objc's strong.
1061
1.99M
  bool isObjCGCStrong() const {
1062
1.99M
    return getObjCGCAttr() == Qualifiers::Strong;
1063
1.99M
  }
1064
1065
  /// Returns lifetime attribute of this type.
1066
28.1M
  Qualifiers::ObjCLifetime getObjCLifetime() const {
1067
28.1M
    return getQualifiers().getObjCLifetime();
1068
28.1M
  }
1069
1070
4.31M
  bool hasNonTrivialObjCLifetime() const {
1071
4.31M
    return getQualifiers().hasNonTrivialObjCLifetime();
1072
4.31M
  }
1073
1074
423
  bool hasStrongOrWeakObjCLifetime() const {
1075
423
    return getQualifiers().hasStrongOrWeakObjCLifetime();
1076
423
  }
1077
1078
  // true when Type is objc's weak and weak is enabled but ARC isn't.
1079
  bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
1080
1081
  enum PrimitiveDefaultInitializeKind {
1082
    /// The type does not fall into any of the following categories. Note that
1083
    /// this case is zero-valued so that values of this enum can be used as a
1084
    /// boolean condition for non-triviality.
1085
    PDIK_Trivial,
1086
1087
    /// The type is an Objective-C retainable pointer type that is qualified
1088
    /// with the ARC __strong qualifier.
1089
    PDIK_ARCStrong,
1090
1091
    /// The type is an Objective-C retainable pointer type that is qualified
1092
    /// with the ARC __weak qualifier.
1093
    PDIK_ARCWeak,
1094
1095
    /// The type is a struct containing a field whose type is not PCK_Trivial.
1096
    PDIK_Struct
1097
  };
1098
1099
  /// Functions to query basic properties of non-trivial C struct types.
1100
1101
  /// Check if this is a non-trivial type that would cause a C struct
1102
  /// transitively containing this type to be non-trivial to default initialize
1103
  /// and return the kind.
1104
  PrimitiveDefaultInitializeKind
1105
  isNonTrivialToPrimitiveDefaultInitialize() const;
1106
1107
  enum PrimitiveCopyKind {
1108
    /// The type does not fall into any of the following categories. Note that
1109
    /// this case is zero-valued so that values of this enum can be used as a
1110
    /// boolean condition for non-triviality.
1111
    PCK_Trivial,
1112
1113
    /// The type would be trivial except that it is volatile-qualified. Types
1114
    /// that fall into one of the other non-trivial cases may additionally be
1115
    /// volatile-qualified.
1116
    PCK_VolatileTrivial,
1117
1118
    /// The type is an Objective-C retainable pointer type that is qualified
1119
    /// with the ARC __strong qualifier.
1120
    PCK_ARCStrong,
1121
1122
    /// The type is an Objective-C retainable pointer type that is qualified
1123
    /// with the ARC __weak qualifier.
1124
    PCK_ARCWeak,
1125
1126
    /// The type is a struct containing a field whose type is neither
1127
    /// PCK_Trivial nor PCK_VolatileTrivial.
1128
    /// Note that a C++ struct type does not necessarily match this; C++ copying
1129
    /// semantics are too complex to express here, in part because they depend
1130
    /// on the exact constructor or assignment operator that is chosen by
1131
    /// overload resolution to do the copy.
1132
    PCK_Struct
1133
  };
1134
1135
  /// Check if this is a non-trivial type that would cause a C struct
1136
  /// transitively containing this type to be non-trivial to copy and return the
1137
  /// kind.
1138
  PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const;
1139
1140
  /// Check if this is a non-trivial type that would cause a C struct
1141
  /// transitively containing this type to be non-trivial to destructively
1142
  /// move and return the kind. Destructive move in this context is a C++-style
1143
  /// move in which the source object is placed in a valid but unspecified state
1144
  /// after it is moved, as opposed to a truly destructive move in which the
1145
  /// source object is placed in an uninitialized state.
1146
  PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const;
1147
1148
  enum DestructionKind {
1149
    DK_none,
1150
    DK_cxx_destructor,
1151
    DK_objc_strong_lifetime,
1152
    DK_objc_weak_lifetime,
1153
    DK_nontrivial_c_struct
1154
  };
1155
1156
  /// Returns a nonzero value if objects of this type require
1157
  /// non-trivial work to clean up after.  Non-zero because it's
1158
  /// conceivable that qualifiers (objc_gc(weak)?) could make
1159
  /// something require destruction.
1160
5.69M
  DestructionKind isDestructedType() const {
1161
5.69M
    return isDestructedTypeImpl(*this);
1162
5.69M
  }
1163
1164
  /// Determine whether expressions of the given type are forbidden
1165
  /// from being lvalues in C.
1166
  ///
1167
  /// The expression types that are forbidden to be lvalues are:
1168
  ///   - 'void', but not qualified void
1169
  ///   - function types
1170
  ///
1171
  /// The exact rule here is C99 6.3.2.1:
1172
  ///   An lvalue is an expression with an object type or an incomplete
1173
  ///   type other than void.
1174
  bool isCForbiddenLValueType() const;
1175
1176
  /// Substitute type arguments for the Objective-C type parameters used in the
1177
  /// subject type.
1178
  ///
1179
  /// \param ctx ASTContext in which the type exists.
1180
  ///
1181
  /// \param typeArgs The type arguments that will be substituted for the
1182
  /// Objective-C type parameters in the subject type, which are generally
1183
  /// computed via \c Type::getObjCSubstitutions. If empty, the type
1184
  /// parameters will be replaced with their bounds or id/Class, as appropriate
1185
  /// for the context.
1186
  ///
1187
  /// \param context The context in which the subject type was written.
1188
  ///
1189
  /// \returns the resulting type.
1190
  QualType substObjCTypeArgs(ASTContext &ctx,
1191
                             ArrayRef<QualType> typeArgs,
1192
                             ObjCSubstitutionContext context) const;
1193
1194
  /// Substitute type arguments from an object type for the Objective-C type
1195
  /// parameters used in the subject type.
1196
  ///
1197
  /// This operation combines the computation of type arguments for
1198
  /// substitution (\c Type::getObjCSubstitutions) with the actual process of
1199
  /// substitution (\c QualType::substObjCTypeArgs) for the convenience of
1200
  /// callers that need to perform a single substitution in isolation.
1201
  ///
1202
  /// \param objectType The type of the object whose member type we're
1203
  /// substituting into. For example, this might be the receiver of a message
1204
  /// or the base of a property access.
1205
  ///
1206
  /// \param dc The declaration context from which the subject type was
1207
  /// retrieved, which indicates (for example) which type parameters should
1208
  /// be substituted.
1209
  ///
1210
  /// \param context The context in which the subject type was written.
1211
  ///
1212
  /// \returns the subject type after replacing all of the Objective-C type
1213
  /// parameters with their corresponding arguments.
1214
  QualType substObjCMemberType(QualType objectType,
1215
                               const DeclContext *dc,
1216
                               ObjCSubstitutionContext context) const;
1217
1218
  /// Strip Objective-C "__kindof" types from the given type.
1219
  QualType stripObjCKindOfType(const ASTContext &ctx) const;
1220
1221
  /// Remove all qualifiers including _Atomic.
1222
  QualType getAtomicUnqualifiedType() const;
1223
1224
private:
1225
  // These methods are implemented in a separate translation unit;
1226
  // "static"-ize them to avoid creating temporary QualTypes in the
1227
  // caller.
1228
  static bool isConstant(QualType T, const ASTContext& Ctx);
1229
  static QualType getDesugaredType(QualType T, const ASTContext &Context);
1230
  static SplitQualType getSplitDesugaredType(QualType T);
1231
  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
1232
  static QualType getSingleStepDesugaredTypeImpl(QualType type,
1233
                                                 const ASTContext &C);
1234
  static QualType IgnoreParens(QualType T);
1235
  static DestructionKind isDestructedTypeImpl(QualType type);
1236
};
1237
1238
} // namespace clang
1239
1240
namespace llvm {
1241
1242
/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1243
/// to a specific Type class.
1244
template<> struct simplify_type< ::clang::QualType> {
1245
  using SimpleType = const ::clang::Type *;
1246
1247
3.95G
  static SimpleType getSimplifiedValue(::clang::QualType Val) {
1248
3.95G
    return Val.getTypePtr();
1249
3.95G
  }
1250
};
1251
1252
// Teach SmallPtrSet that QualType is "basically a pointer".
1253
template<>
1254
struct PointerLikeTypeTraits<clang::QualType> {
1255
30.4M
  static inline void *getAsVoidPointer(clang::QualType P) {
1256
30.4M
    return P.getAsOpaquePtr();
1257
30.4M
  }
1258
1259
38.6M
  static inline clang::QualType getFromVoidPointer(void *P) {
1260
38.6M
    return clang::QualType::getFromOpaquePtr(P);
1261
38.6M
  }
1262
1263
  // Various qualifiers go in low bits.
1264
  enum { NumLowBitsAvailable = 0 };
1265
};
1266
1267
} // namespace llvm
1268
1269
namespace clang {
1270
1271
/// Base class that is common to both the \c ExtQuals and \c Type
1272
/// classes, which allows \c QualType to access the common fields between the
1273
/// two.
1274
class ExtQualsTypeCommonBase {
1275
  friend class ExtQuals;
1276
  friend class QualType;
1277
  friend class Type;
1278
1279
  /// The "base" type of an extended qualifiers type (\c ExtQuals) or
1280
  /// a self-referential pointer (for \c Type).
1281
  ///
1282
  /// This pointer allows an efficient mapping from a QualType to its
1283
  /// underlying type pointer.
1284
  const Type *const BaseType;
1285
1286
  /// The canonical type of this type.  A QualType.
1287
  QualType CanonicalType;
1288
1289
  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
1290
43.8M
      : BaseType(baseType), CanonicalType(canon) {}
1291
};
1292
1293
/// We can encode up to four bits in the low bits of a
1294
/// type pointer, but there are many more type qualifiers that we want
1295
/// to be able to apply to an arbitrary type.  Therefore we have this
1296
/// struct, intended to be heap-allocated and used by QualType to
1297
/// store qualifiers.
1298
///
1299
/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
1300
/// in three low bits on the QualType pointer; a fourth bit records whether
1301
/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
1302
/// Objective-C GC attributes) are much more rare.
1303
class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
1304
  // NOTE: changing the fast qualifiers should be straightforward as
1305
  // long as you don't make 'const' non-fast.
1306
  // 1. Qualifiers:
1307
  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
1308
  //       Fast qualifiers must occupy the low-order bits.
1309
  //    b) Update Qualifiers::FastWidth and FastMask.
1310
  // 2. QualType:
1311
  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
1312
  //    b) Update remove{Volatile,Restrict}, defined near the end of
1313
  //       this header.
1314
  // 3. ASTContext:
1315
  //    a) Update get{Volatile,Restrict}Type.
1316
1317
  /// The immutable set of qualifiers applied by this node. Always contains
1318
  /// extended qualifiers.
1319
  Qualifiers Quals;
1320
1321
16.7k
  ExtQuals *this_() { return this; }
1322
1323
public:
1324
  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
1325
      : ExtQualsTypeCommonBase(baseType,
1326
                               canon.isNull() ? QualType(this_(), 0) : canon),
1327
28.2k
        Quals(quals) {
1328
28.2k
    assert(Quals.hasNonFastQualifiers()
1329
28.2k
           && "ExtQuals created with no fast qualifiers");
1330
28.2k
    assert(!Quals.hasFastQualifiers()
1331
28.2k
           && "ExtQuals created with fast qualifiers");
1332
28.2k
  }
1333
1334
1.32M
  Qualifiers getQualifiers() const { return Quals; }
1335
1336
  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
1337
  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
1338
1339
  bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1340
  Qualifiers::ObjCLifetime getObjCLifetime() const {
1341
    return Quals.getObjCLifetime();
1342
  }
1343
1344
  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
1345
  LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
1346
1347
725k
  const Type *getBaseType() const { return BaseType; }
1348
1349
public:
1350
617k
  void Profile(llvm::FoldingSetNodeID &ID) const {
1351
617k
    Profile(ID, getBaseType(), Quals);
1352
617k
  }
1353
1354
  static void Profile(llvm::FoldingSetNodeID &ID,
1355
                      const Type *BaseType,
1356
1.00M
                      Qualifiers Quals) {
1357
1.00M
    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1358
1.00M
    ID.AddPointer(BaseType);
1359
1.00M
    Quals.Profile(ID);
1360
1.00M
  }
1361
};
1362
1363
/// The kind of C++11 ref-qualifier associated with a function type.
1364
/// This determines whether a member function's "this" object can be an
1365
/// lvalue, rvalue, or neither.
1366
enum RefQualifierKind {
1367
  /// No ref-qualifier was provided.
1368
  RQ_None = 0,
1369
1370
  /// An lvalue ref-qualifier was provided (\c &).
1371
  RQ_LValue,
1372
1373
  /// An rvalue ref-qualifier was provided (\c &&).
1374
  RQ_RValue
1375
};
1376
1377
/// Which keyword(s) were used to create an AutoType.
1378
enum class AutoTypeKeyword {
1379
  /// auto
1380
  Auto,
1381
1382
  /// decltype(auto)
1383
  DecltypeAuto,
1384
1385
  /// __auto_type (GNU extension)
1386
  GNUAutoType
1387
};
1388
1389
/// The base class of the type hierarchy.
1390
///
1391
/// A central concept with types is that each type always has a canonical
1392
/// type.  A canonical type is the type with any typedef names stripped out
1393
/// of it or the types it references.  For example, consider:
1394
///
1395
///  typedef int  foo;
1396
///  typedef foo* bar;
1397
///    'int *'    'foo *'    'bar'
1398
///
1399
/// There will be a Type object created for 'int'.  Since int is canonical, its
1400
/// CanonicalType pointer points to itself.  There is also a Type for 'foo' (a
1401
/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
1402
/// there is a PointerType that represents 'int*', which, like 'int', is
1403
/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
1404
/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
1405
/// is also 'int*'.
1406
///
1407
/// Non-canonical types are useful for emitting diagnostics, without losing
1408
/// information about typedefs being used.  Canonical types are useful for type
1409
/// comparisons (they allow by-pointer equality tests) and useful for reasoning
1410
/// about whether something has a particular form (e.g. is a function type),
1411
/// because they implicitly, recursively, strip all typedefs out of a type.
1412
///
1413
/// Types, once created, are immutable.
1414
///
1415
class Type : public ExtQualsTypeCommonBase {
1416
public:
1417
  enum TypeClass {
1418
#define TYPE(Class, Base) Class,
1419
#define LAST_TYPE(Class) TypeLast = Class,
1420
#define ABSTRACT_TYPE(Class, Base)
1421
#include "clang/AST/TypeNodes.def"
1422
    TagFirst = Record, TagLast = Enum
1423
  };
1424
1425
private:
1426
  /// Bitfields required by the Type class.
1427
  class TypeBitfields {
1428
    friend class Type;
1429
    template <class T> friend class TypePropertyCache;
1430
1431
    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1432
    unsigned TC : 8;
1433
1434
    /// Whether this type is a dependent type (C++ [temp.dep.type]).
1435
    unsigned Dependent : 1;
1436
1437
    /// Whether this type somehow involves a template parameter, even
1438
    /// if the resolution of the type does not depend on a template parameter.
1439
    unsigned InstantiationDependent : 1;
1440
1441
    /// Whether this type is a variably-modified type (C99 6.7.5).
1442
    unsigned VariablyModified : 1;
1443
1444
    /// Whether this type contains an unexpanded parameter pack
1445
    /// (for C++11 variadic templates).
1446
    unsigned ContainsUnexpandedParameterPack : 1;
1447
1448
    /// True if the cache (i.e. the bitfields here starting with
1449
    /// 'Cache') is valid.
1450
    mutable unsigned CacheValid : 1;
1451
1452
    /// Linkage of this type.
1453
    mutable unsigned CachedLinkage : 3;
1454
1455
    /// Whether this type involves and local or unnamed types.
1456
    mutable unsigned CachedLocalOrUnnamed : 1;
1457
1458
    /// Whether this type comes from an AST file.
1459
    mutable unsigned FromAST : 1;
1460
1461
9.13M
    bool isCacheValid() const {
1462
9.13M
      return CacheValid;
1463
9.13M
    }
1464
1465
7.74M
    Linkage getLinkage() const {
1466
7.74M
      assert(isCacheValid() && "getting linkage from invalid cache");
1467
7.74M
      return static_cast<Linkage>(CachedLinkage);
1468
7.74M
    }
1469
1470
3.27M
    bool hasLocalOrUnnamedType() const {
1471
3.27M
      assert(isCacheValid() && "getting linkage from invalid cache");
1472
3.27M
      return CachedLocalOrUnnamed;
1473
3.27M
    }
1474
  };
1475
  enum { NumTypeBits = 18 };
1476
1477
protected:
1478
  // These classes allow subclasses to somewhat cleanly pack bitfields
1479
  // into Type.
1480
1481
  class ArrayTypeBitfields {
1482
    friend class ArrayType;
1483
1484
    unsigned : NumTypeBits;
1485
1486
    /// CVR qualifiers from declarations like
1487
    /// 'int X[static restrict 4]'. For function parameters only.
1488
    unsigned IndexTypeQuals : 3;
1489
1490
    /// Storage class qualifiers from declarations like
1491
    /// 'int X[static restrict 4]'. For function parameters only.
1492
    /// Actually an ArrayType::ArraySizeModifier.
1493
    unsigned SizeModifier : 3;
1494
  };
1495
1496
  class BuiltinTypeBitfields {
1497
    friend class BuiltinType;
1498
1499
    unsigned : NumTypeBits;
1500
1501
    /// The kind (BuiltinType::Kind) of builtin type this is.
1502
    unsigned Kind : 8;
1503
  };
1504
1505
  class FunctionTypeBitfields {
1506
    friend class FunctionProtoType;
1507
    friend class FunctionType;
1508
1509
    unsigned : NumTypeBits;
1510
1511
    /// Extra information which affects how the function is called, like
1512
    /// regparm and the calling convention.
1513
    unsigned ExtInfo : 12;
1514
1515
    /// Used only by FunctionProtoType, put here to pack with the
1516
    /// other bitfields.
1517
    /// The qualifiers are part of FunctionProtoType because...
1518
    ///
1519
    /// C++ 8.3.5p4: The return type, the parameter type list and the
1520
    /// cv-qualifier-seq, [...], are part of the function type.
1521
    unsigned TypeQuals : 4;
1522
1523
    /// The ref-qualifier associated with a \c FunctionProtoType.
1524
    ///
1525
    /// This is a value of type \c RefQualifierKind.
1526
    unsigned RefQualifier : 2;
1527
  };
1528
1529
  class ObjCObjectTypeBitfields {
1530
    friend class ObjCObjectType;
1531
1532
    unsigned : NumTypeBits;
1533
1534
    /// The number of type arguments stored directly on this object type.
1535
    unsigned NumTypeArgs : 7;
1536
1537
    /// The number of protocols stored directly on this object type.
1538
    unsigned NumProtocols : 6;
1539
1540
    /// Whether this is a "kindof" type.
1541
    unsigned IsKindOf : 1;
1542
  };
1543
1544
  class ReferenceTypeBitfields {
1545
    friend class ReferenceType;
1546
1547
    unsigned : NumTypeBits;
1548
1549
    /// True if the type was originally spelled with an lvalue sigil.
1550
    /// This is never true of rvalue references but can also be false
1551
    /// on lvalue references because of C++0x [dcl.typedef]p9,
1552
    /// as follows:
1553
    ///
1554
    ///   typedef int &ref;    // lvalue, spelled lvalue
1555
    ///   typedef int &&rvref; // rvalue
1556
    ///   ref &a;              // lvalue, inner ref, spelled lvalue
1557
    ///   ref &&a;             // lvalue, inner ref
1558
    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
1559
    ///   rvref &&a;           // rvalue, inner ref
1560
    unsigned SpelledAsLValue : 1;
1561
1562
    /// True if the inner type is a reference type.  This only happens
1563
    /// in non-canonical forms.
1564
    unsigned InnerRef : 1;
1565
  };
1566
1567
  class TypeWithKeywordBitfields {
1568
    friend class TypeWithKeyword;
1569
1570
    unsigned : NumTypeBits;
1571
1572
    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
1573
    unsigned Keyword : 8;
1574
  };
1575
1576
  enum { NumTypeWithKeywordBits = 8 };
1577
1578
  class ElaboratedTypeBitfields {
1579
    friend class ElaboratedType;
1580
1581
    unsigned : NumTypeBits;
1582
    unsigned : NumTypeWithKeywordBits;
1583
1584
    /// Whether the ElaboratedType has a trailing OwnedTagDecl.
1585
    unsigned HasOwnedTagDecl : 1;
1586
  };
1587
1588
  class VectorTypeBitfields {
1589
    friend class VectorType;
1590
    friend class DependentVectorType;
1591
1592
    unsigned : NumTypeBits;
1593
1594
    /// The kind of vector, either a generic vector type or some
1595
    /// target-specific vector type such as for AltiVec or Neon.
1596
    unsigned VecKind : 3;
1597
1598
    /// The number of elements in the vector.
1599
    unsigned NumElements : 29 - NumTypeBits;
1600
1601
    enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 };
1602
  };
1603
1604
  class AttributedTypeBitfields {
1605
    friend class AttributedType;
1606
1607
    unsigned : NumTypeBits;
1608
1609
    /// An AttributedType::Kind
1610
    unsigned AttrKind : 32 - NumTypeBits;
1611
  };
1612
1613
  class AutoTypeBitfields {
1614
    friend class AutoType;
1615
1616
    unsigned : NumTypeBits;
1617
1618
    /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
1619
    /// or '__auto_type'?  AutoTypeKeyword value.
1620
    unsigned Keyword : 2;
1621
  };
1622
1623
  class SubstTemplateTypeParmPackTypeBitfields {
1624
    friend class SubstTemplateTypeParmPackType;
1625
1626
    unsigned : NumTypeBits;
1627
1628
    /// The number of template arguments in \c Arguments, which is
1629
    /// expected to be able to hold at least 1024 according to [implimits].
1630
    /// However as this limit is somewhat easy to hit with template
1631
    /// metaprogramming we'd prefer to keep it as large as possible.
1632
    /// At the moment it has been left as a non-bitfield since this type
1633
    /// safely fits in 64 bits as an unsigned, so there is no reason to
1634
    /// introduce the performance impact of a bitfield.
1635
    unsigned NumArgs;
1636
  };
1637
1638
  class TemplateSpecializationTypeBitfields {
1639
    friend class TemplateSpecializationType;
1640
1641
    unsigned : NumTypeBits;
1642
1643
    /// Whether this template specialization type is a substituted type alias.
1644
    unsigned TypeAlias : 1;
1645
1646
    /// The number of template arguments named in this class template
1647
    /// specialization, which is expected to be able to hold at least 1024
1648
    /// according to [implimits]. However, as this limit is somewhat easy to
1649
    /// hit with template metaprogramming we'd prefer to keep it as large
1650
    /// as possible. At the moment it has been left as a non-bitfield since
1651
    /// this type safely fits in 64 bits as an unsigned, so there is no reason
1652
    /// to introduce the performance impact of a bitfield.
1653
    unsigned NumArgs;
1654
  };
1655
1656
  class DependentTemplateSpecializationTypeBitfields {
1657
    friend class DependentTemplateSpecializationType;
1658
1659
    unsigned : NumTypeBits;
1660
    unsigned : NumTypeWithKeywordBits;
1661
1662
    /// The number of template arguments named in this class template
1663
    /// specialization, which is expected to be able to hold at least 1024
1664
    /// according to [implimits]. However, as this limit is somewhat easy to
1665
    /// hit with template metaprogramming we'd prefer to keep it as large
1666
    /// as possible. At the moment it has been left as a non-bitfield since
1667
    /// this type safely fits in 64 bits as an unsigned, so there is no reason
1668
    /// to introduce the performance impact of a bitfield.
1669
    unsigned NumArgs;
1670
  };
1671
1672
  class PackExpansionTypeBitfields {
1673
    friend class PackExpansionType;
1674
1675
    unsigned : NumTypeBits;
1676
1677
    /// The number of expansions that this pack expansion will
1678
    /// generate when substituted (+1), which is expected to be able to
1679
    /// hold at least 1024 according to [implimits]. However, as this limit
1680
    /// is somewhat easy to hit with template metaprogramming we'd prefer to
1681
    /// keep it as large as possible. At the moment it has been left as a
1682
    /// non-bitfield since this type safely fits in 64 bits as an unsigned, so
1683
    /// there is no reason to introduce the performance impact of a bitfield.
1684
    ///
1685
    /// This field will only have a non-zero value when some of the parameter
1686
    /// packs that occur within the pattern have been substituted but others
1687
    /// have not.
1688
    unsigned NumExpansions;
1689
  };
1690
1691
  union {
1692
    TypeBitfields TypeBits;
1693
    ArrayTypeBitfields ArrayTypeBits;
1694
    AttributedTypeBitfields AttributedTypeBits;
1695
    AutoTypeBitfields AutoTypeBits;
1696
    BuiltinTypeBitfields BuiltinTypeBits;
1697
    FunctionTypeBitfields FunctionTypeBits;
1698
    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1699
    ReferenceTypeBitfields ReferenceTypeBits;
1700
    TypeWithKeywordBitfields TypeWithKeywordBits;
1701
    ElaboratedTypeBitfields ElaboratedTypeBits;
1702
    VectorTypeBitfields VectorTypeBits;
1703
    SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits;
1704
    TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits;
1705
    DependentTemplateSpecializationTypeBitfields
1706
      DependentTemplateSpecializationTypeBits;
1707
    PackExpansionTypeBitfields PackExpansionTypeBits;
1708
1709
    static_assert(sizeof(TypeBitfields) <= 8,
1710
                  "TypeBitfields is larger than 8 bytes!");
1711
    static_assert(sizeof(ArrayTypeBitfields) <= 8,
1712
                  "ArrayTypeBitfields is larger than 8 bytes!");
1713
    static_assert(sizeof(AttributedTypeBitfields) <= 8,
1714
                  "AttributedTypeBitfields is larger than 8 bytes!");
1715
    static_assert(sizeof(AutoTypeBitfields) <= 8,
1716
                  "AutoTypeBitfields is larger than 8 bytes!");
1717
    static_assert(sizeof(BuiltinTypeBitfields) <= 8,
1718
                  "BuiltinTypeBitfields is larger than 8 bytes!");
1719
    static_assert(sizeof(FunctionTypeBitfields) <= 8,
1720
                  "FunctionTypeBitfields is larger than 8 bytes!");
1721
    static_assert(sizeof(ObjCObjectTypeBitfields) <= 8,
1722
                  "ObjCObjectTypeBitfields is larger than 8 bytes!");
1723
    static_assert(sizeof(ReferenceTypeBitfields) <= 8,
1724
                  "ReferenceTypeBitfields is larger than 8 bytes!");
1725
    static_assert(sizeof(TypeWithKeywordBitfields) <= 8,
1726
                  "TypeWithKeywordBitfields is larger than 8 bytes!");
1727
    static_assert(sizeof(ElaboratedTypeBitfields) <= 8,
1728
                  "ElaboratedTypeBitfields is larger than 8 bytes!");
1729
    static_assert(sizeof(VectorTypeBitfields) <= 8,
1730
                  "VectorTypeBitfields is larger than 8 bytes!");
1731
    static_assert(sizeof(SubstTemplateTypeParmPackTypeBitfields) <= 8,
1732
                  "SubstTemplateTypeParmPackTypeBitfields is larger"
1733
                  " than 8 bytes!");
1734
    static_assert(sizeof(TemplateSpecializationTypeBitfields) <= 8,
1735
                  "TemplateSpecializationTypeBitfields is larger"
1736
                  " than 8 bytes!");
1737
    static_assert(sizeof(DependentTemplateSpecializationTypeBitfields) <= 8,
1738
                  "DependentTemplateSpecializationTypeBitfields is larger"
1739
                  " than 8 bytes!");
1740
    static_assert(sizeof(PackExpansionTypeBitfields) <= 8,
1741
                  "PackExpansionTypeBitfields is larger than 8 bytes");
1742
  };
1743
1744
private:
1745
  template <class T> friend class TypePropertyCache;
1746
1747
  /// Set whether this type comes from an AST file.
1748
144k
  void setFromAST(bool V = true) const {
1749
144k
    TypeBits.FromAST = V;
1750
144k
  }
1751
1752
protected:
1753
  friend class ASTContext;
1754
1755
  Type(TypeClass tc, QualType canon, bool Dependent,
1756
       bool InstantiationDependent, bool VariablyModified,
1757
       bool ContainsUnexpandedParameterPack)
1758
      : ExtQualsTypeCommonBase(this,
1759
43.8M
                               canon.isNull() ? QualType(this_(), 0) : canon) {
1760
43.8M
    TypeBits.TC = tc;
1761
43.8M
    TypeBits.Dependent = Dependent;
1762
43.8M
    TypeBits.InstantiationDependent = Dependent || 
InstantiationDependent26.3M
;
1763
43.8M
    TypeBits.VariablyModified = VariablyModified;
1764
43.8M
    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
1765
43.8M
    TypeBits.CacheValid = false;
1766
43.8M
    TypeBits.CachedLocalOrUnnamed = false;
1767
43.8M
    TypeBits.CachedLinkage = NoLinkage;
1768
43.8M
    TypeBits.FromAST = false;
1769
43.8M
  }
1770
1771
  // silence VC++ warning C4355: 'this' : used in base member initializer list
1772
11.9M
  Type *this_() { return this; }
1773
1774
4.26M
  void setDependent(bool D = true) {
1775
4.26M
    TypeBits.Dependent = D;
1776
4.26M
    if (D)
1777
4.22M
      TypeBits.InstantiationDependent = true;
1778
4.26M
  }
1779
1780
7.40M
  void setInstantiationDependent(bool D = true) {
1781
7.40M
    TypeBits.InstantiationDependent = D; }
1782
1783
0
  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
1784
1785
58.8k
  void setContainsUnexpandedParameterPack(bool PP = true) {
1786
58.8k
    TypeBits.ContainsUnexpandedParameterPack = PP;
1787
58.8k
  }
1788
1789
public:
1790
  friend class ASTReader;
1791
  friend class ASTWriter;
1792
1793
  Type(const Type &) = delete;
1794
  Type &operator=(const Type &) = delete;
1795
1796
7.35G
  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
1797
1798
  /// Whether this type comes from an AST file.
1799
970
  bool isFromAST() const { return TypeBits.FromAST; }
1800
1801
  /// Whether this type is or contains an unexpanded parameter
1802
  /// pack, used to support C++0x variadic templates.
1803
  ///
1804
  /// A type that contains a parameter pack shall be expanded by the
1805
  /// ellipsis operator at some point. For example, the typedef in the
1806
  /// following example contains an unexpanded parameter pack 'T':
1807
  ///
1808
  /// \code
1809
  /// template<typename ...T>
1810
  /// struct X {
1811
  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1812
  /// };
1813
  /// \endcode
1814
  ///
1815
  /// Note that this routine does not specify which
1816
74.3M
  bool containsUnexpandedParameterPack() const {
1817
74.3M
    return TypeBits.ContainsUnexpandedParameterPack;
1818
74.3M
  }
1819
1820
  /// Determines if this type would be canonical if it had no further
1821
  /// qualification.
1822
84.8M
  bool isCanonicalUnqualified() const {
1823
84.8M
    return CanonicalType == QualType(this, 0);
1824
84.8M
  }
1825
1826
  /// Pull a single level of sugar off of this locally-unqualified type.
1827
  /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
1828
  /// or QualType::getSingleStepDesugaredType(const ASTContext&).
1829
  QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
1830
1831
  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
1832
  /// object types, function types, and incomplete types.
1833
1834
  /// Return true if this is an incomplete type.
1835
  /// A type that can describe objects, but which lacks information needed to
1836
  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
1837
  /// routine will need to determine if the size is actually required.
1838
  ///
1839
  /// Def If non-null, and the type refers to some kind of declaration
1840
  /// that can be completed (such as a C struct, C++ class, or Objective-C
1841
  /// class), will be set to the declaration.
1842
  bool isIncompleteType(NamedDecl **Def = nullptr) const;
1843
1844
  /// Return true if this is an incomplete or object
1845
  /// type, in other words, not a function type.
1846
572k
  bool isIncompleteOrObjectType() const {
1847
572k
    return !isFunctionType();
1848
572k
  }
1849
1850
  /// Determine whether this type is an object type.
1851
455k
  bool isObjectType() const {
1852
455k
    // C++ [basic.types]p8:
1853
455k
    //   An object type is a (possibly cv-qualified) type that is not a
1854
455k
    //   function type, not a reference type, and not a void type.
1855
455k
    return !isReferenceType() && 
!isFunctionType()441k
&&
!isVoidType()294k
;
1856
455k
  }
1857
1858
  /// Return true if this is a literal type
1859
  /// (C++11 [basic.types]p10)
1860
  bool isLiteralType(const ASTContext &Ctx) const;
1861
1862
  /// Test if this type is a standard-layout type.
1863
  /// (C++0x [basic.type]p9)
1864
  bool isStandardLayoutType() const;
1865
1866
  /// Helper methods to distinguish type categories. All type predicates
1867
  /// operate on the canonical type, ignoring typedefs and qualifiers.
1868
1869
  /// Returns true if the type is a builtin type.
1870
  bool isBuiltinType() const;
1871
1872
  /// Test for a particular builtin type.
1873
  bool isSpecificBuiltinType(unsigned K) const;
1874
1875
  /// Test for a type which does not represent an actual type-system type but
1876
  /// is instead used as a placeholder for various convenient purposes within
1877
  /// Clang.  All such types are BuiltinTypes.
1878
  bool isPlaceholderType() const;
1879
  const BuiltinType *getAsPlaceholderType() const;
1880
1881
  /// Test for a specific placeholder type.
1882
  bool isSpecificPlaceholderType(unsigned K) const;
1883
1884
  /// Test for a placeholder type other than Overload; see
1885
  /// BuiltinType::isNonOverloadPlaceholderType.
1886
  bool isNonOverloadPlaceholderType() const;
1887
1888
  /// isIntegerType() does *not* include complex integers (a GCC extension).
1889
  /// isComplexIntegerType() can be used to test for complex integers.
1890
  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
1891
  bool isEnumeralType() const;
1892
1893
  /// Determine whether this type is a scoped enumeration type.
1894
  bool isScopedEnumeralType() const;
1895
  bool isBooleanType() const;
1896
  bool isCharType() const;
1897
  bool isWideCharType() const;
1898
  bool isChar8Type() const;
1899
  bool isChar16Type() const;
1900
  bool isChar32Type() const;
1901
  bool isAnyCharacterType() const;
1902
  bool isIntegralType(const ASTContext &Ctx) const;
1903
1904
  /// Determine whether this type is an integral or enumeration type.
1905
  bool isIntegralOrEnumerationType() const;
1906
1907
  /// Determine whether this type is an integral or unscoped enumeration type.
1908
  bool isIntegralOrUnscopedEnumerationType() const;
1909
1910
  /// Floating point categories.
1911
  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
1912
  /// isComplexType() does *not* include complex integers (a GCC extension).
1913
  /// isComplexIntegerType() can be used to test for complex integers.
1914
  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1915
  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
1916
  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
1917
  bool isHalfType() const;         // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
1918
  bool isFloat16Type() const;      // C11 extension ISO/IEC TS 18661
1919
  bool isFloat128Type() const;
1920
  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
1921
  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1922
  bool isVoidType() const;         // C99 6.2.5p19
1923
  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1924
  bool isAggregateType() const;
1925
  bool isFundamentalType() const;
1926
  bool isCompoundType() const;
1927
1928
  // Type Predicates: Check to see if this type is structurally the specified
1929
  // type, ignoring typedefs and qualifiers.
1930
  bool isFunctionType() const;
1931
  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1932
30.0M
  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1933
  bool isPointerType() const;
1934
  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
1935
  bool isBlockPointerType() const;
1936
  bool isVoidPointerType() const;
1937
  bool isReferenceType() const;
1938
  bool isLValueReferenceType() const;
1939
  bool isRValueReferenceType() const;
1940
  bool isFunctionPointerType() const;
1941
  bool isMemberPointerType() const;
1942
  bool isMemberFunctionPointerType() const;
1943
  bool isMemberDataPointerType() const;
1944
  bool isArrayType() const;
1945
  bool isConstantArrayType() const;
1946
  bool isIncompleteArrayType() const;
1947
  bool isVariableArrayType() const;
1948
  bool isDependentSizedArrayType() const;
1949
  bool isRecordType() const;
1950
  bool isClassType() const;
1951
  bool isStructureType() const;
1952
  bool isObjCBoxableRecordType() const;
1953
  bool isInterfaceType() const;
1954
  bool isStructureOrClassType() const;
1955
  bool isUnionType() const;
1956
  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1957
  bool isVectorType() const;                    // GCC vector type.
1958
  bool isExtVectorType() const;                 // Extended vector type.
1959
  bool isDependentAddressSpaceType() const;     // value-dependent address space qualifier
1960
  bool isObjCObjectPointerType() const;         // pointer to ObjC object
1961
  bool isObjCRetainableType() const;            // ObjC object or block pointer
1962
  bool isObjCLifetimeType() const;              // (array of)* retainable type
1963
  bool isObjCIndirectLifetimeType() const;      // (pointer to)* lifetime type
1964
  bool isObjCNSObjectType() const;              // __attribute__((NSObject))
1965
  bool isObjCIndependentClassType() const;      // __attribute__((objc_independent_class))
1966
  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
1967
  // for the common case.
1968
  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1969
  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1970
  bool isObjCQualifiedIdType() const;           // id<foo>
1971
  bool isObjCQualifiedClassType() const;        // Class<foo>
1972
  bool isObjCObjectOrInterfaceType() const;
1973
  bool isObjCIdType() const;                    // id
1974
1975
  /// Was this type written with the special inert-in-ARC __unsafe_unretained
1976
  /// qualifier?
1977
  ///
1978
  /// This approximates the answer to the following question: if this
1979
  /// translation unit were compiled in ARC, would this type be qualified
1980
  /// with __unsafe_unretained?
1981
319
  bool isObjCInertUnsafeUnretainedType() const {
1982
319
    return hasAttr(attr::ObjCInertUnsafeUnretained);
1983
319
  }
1984
1985
  /// Whether the type is Objective-C 'id' or a __kindof type of an
1986
  /// object type, e.g., __kindof NSView * or __kindof id
1987
  /// <NSCopying>.
1988
  ///
1989
  /// \param bound Will be set to the bound on non-id subtype types,
1990
  /// which will be (possibly specialized) Objective-C class type, or
1991
  /// null for 'id.
1992
  bool isObjCIdOrObjectKindOfType(const ASTContext &ctx,
1993
                                  const ObjCObjectType *&bound) const;
1994
1995
  bool isObjCClassType() const;                 // Class
1996
1997
  /// Whether the type is Objective-C 'Class' or a __kindof type of an
1998
  /// Class type, e.g., __kindof Class <NSCopying>.
1999
  ///
2000
  /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound
2001
  /// here because Objective-C's type system cannot express "a class
2002
  /// object for a subclass of NSFoo".
2003
  bool isObjCClassOrClassKindOfType() const;
2004
2005
  bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const;
2006
  bool isObjCSelType() const;                 // Class
2007
  bool isObjCBuiltinType() const;               // 'id' or 'Class'
2008
  bool isObjCARCBridgableType() const;
2009
  bool isCARCBridgableType() const;
2010
  bool isTemplateTypeParmType() const;          // C++ template type parameter
2011
  bool isNullPtrType() const;                   // C++11 std::nullptr_t
2012
  bool isAlignValT() const;                     // C++17 std::align_val_t
2013
  bool isStdByteType() const;                   // C++17 std::byte
2014
  bool isAtomicType() const;                    // C11 _Atomic()
2015
2016
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2017
  bool is##Id##Type() const;
2018
#include "clang/Basic/OpenCLImageTypes.def"
2019
2020
  bool isImageType() const;                     // Any OpenCL image type
2021
2022
  bool isSamplerT() const;                      // OpenCL sampler_t
2023
  bool isEventT() const;                        // OpenCL event_t
2024
  bool isClkEventT() const;                     // OpenCL clk_event_t
2025
  bool isQueueT() const;                        // OpenCL queue_t
2026
  bool isReserveIDT() const;                    // OpenCL reserve_id_t
2027
2028
  bool isPipeType() const;                      // OpenCL pipe type
2029
  bool isOpenCLSpecificType() const;            // Any OpenCL specific type
2030
2031
  /// Determines if this type, which must satisfy
2032
  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
2033
  /// than implicitly __strong.
2034
  bool isObjCARCImplicitlyUnretainedType() const;
2035
2036
  /// Return the implicit lifetime for this type, which must not be dependent.
2037
  Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
2038
2039
  enum ScalarTypeKind {
2040
    STK_CPointer,
2041
    STK_BlockPointer,
2042
    STK_ObjCObjectPointer,
2043
    STK_MemberPointer,
2044
    STK_Bool,
2045
    STK_Integral,
2046
    STK_Floating,
2047
    STK_IntegralComplex,
2048
    STK_FloatingComplex
2049
  };
2050
2051
  /// Given that this is a scalar type, classify it.
2052
  ScalarTypeKind getScalarTypeKind() const;
2053
2054
  /// Whether this type is a dependent type, meaning that its definition
2055
  /// somehow depends on a template parameter (C++ [temp.dep.type]).
2056
325M
  bool isDependentType() const { return TypeBits.Dependent; }
2057
2058
  /// Determine whether this type is an instantiation-dependent type,
2059
  /// meaning that the type involves a template parameter (even if the
2060
  /// definition does not actually depend on the type substituted for that
2061
  /// template parameter).
2062
134M
  bool isInstantiationDependentType() const {
2063
134M
    return TypeBits.InstantiationDependent;
2064
134M
  }
2065
2066
  /// Determine whether this type is an undeduced type, meaning that
2067
  /// it somehow involves a C++11 'auto' type or similar which has not yet been
2068
  /// deduced.
2069
  bool isUndeducedType() const;
2070
2071
  /// Whether this type is a variably-modified type (C99 6.7.5).
2072
93.8M
  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
2073
2074
  /// Whether this type involves a variable-length array type
2075
  /// with a definite size.
2076
  bool hasSizedVLAType() const;
2077
2078
  /// Whether this type is or contains a local or unnamed type.
2079
  bool hasUnnamedOrLocalType() const;
2080
2081
  bool isOverloadableType() const;
2082
2083
  /// Determine wither this type is a C++ elaborated-type-specifier.
2084
  bool isElaboratedTypeSpecifier() const;
2085
2086
  bool canDecayToPointerType() const;
2087
2088
  /// Whether this type is represented natively as a pointer.  This includes
2089
  /// pointers, references, block pointers, and Objective-C interface,
2090
  /// qualified id, and qualified interface types, as well as nullptr_t.
2091
  bool hasPointerRepresentation() const;
2092
2093
  /// Whether this type can represent an objective pointer type for the
2094
  /// purpose of GC'ability
2095
  bool hasObjCPointerRepresentation() const;
2096
2097
  /// Determine whether this type has an integer representation
2098
  /// of some sort, e.g., it is an integer type or a vector.
2099
  bool hasIntegerRepresentation() const;
2100
2101
  /// Determine whether this type has an signed integer representation
2102
  /// of some sort, e.g., it is an signed integer type or a vector.
2103
  bool hasSignedIntegerRepresentation() const;
2104
2105
  /// Determine whether this type has an unsigned integer representation
2106
  /// of some sort, e.g., it is an unsigned integer type or a vector.
2107
  bool hasUnsignedIntegerRepresentation() const;
2108
2109
  /// Determine whether this type has a floating-point representation
2110
  /// of some sort, e.g., it is a floating-point type or a vector thereof.
2111
  bool hasFloatingRepresentation() const;
2112
2113
  // Type Checking Functions: Check to see if this type is structurally the
2114
  // specified type, ignoring typedefs and qualifiers, and return a pointer to
2115
  // the best type we can.
2116
  const RecordType *getAsStructureType() const;
2117
  /// NOTE: getAs*ArrayType are methods on ASTContext.
2118
  const RecordType *getAsUnionType() const;
2119
  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
2120
  const ObjCObjectType *getAsObjCInterfaceType() const;
2121
2122
  // The following is a convenience method that returns an ObjCObjectPointerType
2123
  // for object declared using an interface.
2124
  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
2125
  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
2126
  const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
2127
  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
2128
2129
  /// Retrieves the CXXRecordDecl that this type refers to, either
2130
  /// because the type is a RecordType or because it is the injected-class-name
2131
  /// type of a class template or class template partial specialization.
2132
  CXXRecordDecl *getAsCXXRecordDecl() const;
2133
2134
  /// Retrieves the RecordDecl this type refers to.
2135
  RecordDecl *getAsRecordDecl() const;
2136
2137
  /// Retrieves the TagDecl that this type refers to, either
2138
  /// because the type is a TagType or because it is the injected-class-name
2139
  /// type of a class template or class template partial specialization.
2140
  TagDecl *getAsTagDecl() const;
2141
2142
  /// If this is a pointer or reference to a RecordType, return the
2143
  /// CXXRecordDecl that the type refers to.
2144
  ///
2145
  /// If this is not a pointer or reference, or the type being pointed to does
2146
  /// not refer to a CXXRecordDecl, returns NULL.
2147
  const CXXRecordDecl *getPointeeCXXRecordDecl() const;
2148
2149
  /// Get the DeducedType whose type will be deduced for a variable with
2150
  /// an initializer of this type. This looks through declarators like pointer
2151
  /// types, but not through decltype or typedefs.
2152
  DeducedType *getContainedDeducedType() const;
2153
2154
  /// Get the AutoType whose type will be deduced for a variable with
2155
  /// an initializer of this type. This looks through declarators like pointer
2156
  /// types, but not through decltype or typedefs.
2157
992k
  AutoType *getContainedAutoType() const {
2158
992k
    return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2159
992k
  }
2160
2161
  /// Determine whether this type was written with a leading 'auto'
2162
  /// corresponding to a trailing return type (possibly for a nested
2163
  /// function type within a pointer to function type or similar).
2164
  bool hasAutoForTrailingReturnType() const;
2165
2166
  /// Member-template getAs<specific type>'.  Look through sugar for
2167
  /// an instance of \<specific type>.   This scheme will eventually
2168
  /// replace the specific getAsXXXX methods above.
2169
  ///
2170
  /// There are some specializations of this member template listed
2171
  /// immediately following this class.
2172
  template <typename T> const T *getAs() const;
2173
2174
  /// Member-template getAsAdjusted<specific type>. Look through specific kinds
2175
  /// of sugar (parens, attributes, etc) for an instance of \<specific type>.
2176
  /// This is used when you need to walk over sugar nodes that represent some
2177
  /// kind of type adjustment from a type that was written as a \<specific type>
2178
  /// to another type that is still canonically a \<specific type>.
2179
  template <typename T> const T *getAsAdjusted() const;
2180
2181
  /// A variant of getAs<> for array types which silently discards
2182
  /// qualifiers from the outermost type.
2183
  const ArrayType *getAsArrayTypeUnsafe() const;
2184
2185
  /// Member-template castAs<specific type>.  Look through sugar for
2186
  /// the underlying instance of \<specific type>.
2187
  ///
2188
  /// This method has the same relationship to getAs<T> as cast<T> has
2189
  /// to dyn_cast<T>; which is to say, the underlying type *must*
2190
  /// have the intended type, and this method will never return null.
2191
  template <typename T> const T *castAs() const;
2192
2193
  /// A variant of castAs<> for array type which silently discards
2194
  /// qualifiers from the outermost type.
2195
  const ArrayType *castAsArrayTypeUnsafe() const;
2196
2197
  /// Determine whether this type had the specified attribute applied to it
2198
  /// (looking through top-level type sugar).
2199
  bool hasAttr(attr::Kind AK) const;
2200
2201
  /// Get the base element type of this type, potentially discarding type
2202
  /// qualifiers.  This should never be used when type qualifiers
2203
  /// are meaningful.
2204
  const Type *getBaseElementTypeUnsafe() const;
2205
2206
  /// If this is an array type, return the element type of the array,
2207
  /// potentially with type qualifiers missing.
2208
  /// This should never be used when type qualifiers are meaningful.
2209
  const Type *getArrayElementTypeNoTypeQual() const;
2210
2211
  /// If this is a pointer type, return the pointee type.
2212
  /// If this is an array type, return the array element type.
2213
  /// This should never be used when type qualifiers are meaningful.
2214
  const Type *getPointeeOrArrayElementType() const;
2215
2216
  /// If this is a pointer, ObjC object pointer, or block
2217
  /// pointer, this returns the respective pointee.
2218
  QualType getPointeeType() const;
2219
2220
  /// Return the specified type with any "sugar" removed from the type,
2221
  /// removing any typedefs, typeofs, etc., as well as any qualifiers.
2222
  const Type *getUnqualifiedDesugaredType() const;
2223
2224
  /// More type predicates useful for type checking/promotion
2225
  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
2226
2227
  /// Return true if this is an integer type that is
2228
  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2229
  /// or an enum decl which has a signed representation.
2230
  bool isSignedIntegerType() const;
2231
2232
  /// Return true if this is an integer type that is
2233
  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
2234
  /// or an enum decl which has an unsigned representation.
2235
  bool isUnsignedIntegerType() const;
2236
2237
  /// Determines whether this is an integer type that is signed or an
2238
  /// enumeration types whose underlying type is a signed integer type.
2239
  bool isSignedIntegerOrEnumerationType() const;
2240
2241
  /// Determines whether this is an integer type that is unsigned or an
2242
  /// enumeration types whose underlying type is a unsigned integer type.
2243
  bool isUnsignedIntegerOrEnumerationType() const;
2244
2245
  /// Return true if this is a fixed point type according to
2246
  /// ISO/IEC JTC1 SC22 WG14 N1169.
2247
  bool isFixedPointType() const;
2248
2249
  /// Return true if this is a saturated fixed point type according to
2250
  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2251
  bool isSaturatedFixedPointType() const;
2252
2253
  /// Return true if this is a saturated fixed point type according to
2254
  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2255
  bool isUnsaturatedFixedPointType() const;
2256
2257
  /// Return true if this is a fixed point type that is signed according
2258
  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2259
  bool isSignedFixedPointType() const;
2260
2261
  /// Return true if this is a fixed point type that is unsigned according
2262
  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2263
  bool isUnsignedFixedPointType() const;
2264
2265
  /// Return true if this is not a variable sized type,
2266
  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
2267
  /// incomplete types.
2268
  bool isConstantSizeType() const;
2269
2270
  /// Returns true if this type can be represented by some
2271
  /// set of type specifiers.
2272
  bool isSpecifierType() const;
2273
2274
  /// Determine the linkage of this type.
2275
  Linkage getLinkage() const;
2276
2277
  /// Determine the visibility of this type.
2278
4.82k
  Visibility getVisibility() const {
2279
4.82k
    return getLinkageAndVisibility().getVisibility();
2280
4.82k
  }
2281
2282
  /// Return true if the visibility was explicitly set is the code.
2283
  bool isVisibilityExplicit() const {
2284
    return getLinkageAndVisibility().isVisibilityExplicit();
2285
  }
2286
2287
  /// Determine the linkage and visibility of this type.
2288
  LinkageInfo getLinkageAndVisibility() const;
2289
2290
  /// True if the computed linkage is valid. Used for consistency
2291
  /// checking. Should always return true.
2292
  bool isLinkageValid() const;
2293
2294
  /// Determine the nullability of the given type.
2295
  ///
2296
  /// Note that nullability is only captured as sugar within the type
2297
  /// system, not as part of the canonical type, so nullability will
2298
  /// be lost by canonicalization and desugaring.
2299
  Optional<NullabilityKind> getNullability(const ASTContext &context) const;
2300
2301
  /// Determine whether the given type can have a nullability
2302
  /// specifier applied to it, i.e., if it is any kind of pointer type.
2303
  ///
2304
  /// \param ResultIfUnknown The value to return if we don't yet know whether
2305
  ///        this type can have nullability because it is dependent.
2306
  bool canHaveNullability(bool ResultIfUnknown = true) const;
2307
2308
  /// Retrieve the set of substitutions required when accessing a member
2309
  /// of the Objective-C receiver type that is declared in the given context.
2310
  ///
2311
  /// \c *this is the type of the object we're operating on, e.g., the
2312
  /// receiver for a message send or the base of a property access, and is
2313
  /// expected to be of some object or object pointer type.
2314
  ///
2315
  /// \param dc The declaration context for which we are building up a
2316
  /// substitution mapping, which should be an Objective-C class, extension,
2317
  /// category, or method within.
2318
  ///
2319
  /// \returns an array of type arguments that can be substituted for
2320
  /// the type parameters of the given declaration context in any type described
2321
  /// within that context, or an empty optional to indicate that no
2322
  /// substitution is required.
2323
  Optional<ArrayRef<QualType>>
2324
  getObjCSubstitutions(const DeclContext *dc) const;
2325
2326
  /// Determines if this is an ObjC interface type that may accept type
2327
  /// parameters.
2328
  bool acceptsObjCTypeParams() const;
2329
2330
  const char *getTypeClassName() const;
2331
2332
388M
  QualType getCanonicalTypeInternal() const {
2333
388M
    return CanonicalType;
2334
388M
  }
2335
2336
  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
2337
  void dump() const;
2338
  void dump(llvm::raw_ostream &OS) const;
2339
};
2340
2341
/// This will check for a TypedefType by removing any existing sugar
2342
/// until it reaches a TypedefType or a non-sugared type.
2343
template <> const TypedefType *Type::getAs() const;
2344
2345
/// This will check for a TemplateSpecializationType by removing any
2346
/// existing sugar until it reaches a TemplateSpecializationType or a
2347
/// non-sugared type.
2348
template <> const TemplateSpecializationType *Type::getAs() const;
2349
2350
/// This will check for an AttributedType by removing any existing sugar
2351
/// until it reaches an AttributedType or a non-sugared type.
2352
template <> const AttributedType *Type::getAs() const;
2353
2354
// We can do canonical leaf types faster, because we don't have to
2355
// worry about preserving child type decoration.
2356
#define TYPE(Class, Base)
2357
#define LEAF_TYPE(Class) \
2358
585M
template <> inline const Class##Type *Type::getAs() const { \
2359
585M
  return dyn_cast<Class##Type>(CanonicalType); \
2360
585M
} \
clang::RecordType const* clang::Type::getAs<clang::RecordType>() const
Line
Count
Source
2358
60.8M
template <> inline const Class##Type *Type::getAs() const { \
2359
60.8M
  return dyn_cast<Class##Type>(CanonicalType); \
2360
60.8M
} \
clang::EnumType const* clang::Type::getAs<clang::EnumType>() const
Line
Count
Source
2358
76.1M
template <> inline const Class##Type *Type::getAs() const { \
2359
76.1M
  return dyn_cast<Class##Type>(CanonicalType); \
2360
76.1M
} \
clang::BuiltinType const* clang::Type::getAs<clang::BuiltinType>() const
Line
Count
Source
2358
368M
template <> inline const Class##Type *Type::getAs() const { \
2359
368M
  return dyn_cast<Class##Type>(CanonicalType); \
2360
368M
} \
clang::InjectedClassNameType const* clang::Type::getAs<clang::InjectedClassNameType>() const
Line
Count
Source
2358
31.0M
template <> inline const Class##Type *Type::getAs() const { \
2359
31.0M
  return dyn_cast<Class##Type>(CanonicalType); \
2360
31.0M
} \
clang::ObjCInterfaceType const* clang::Type::getAs<clang::ObjCInterfaceType>() const
Line
Count
Source
2358
15.5M
template <> inline const Class##Type *Type::getAs() const { \
2359
15.5M
  return dyn_cast<Class##Type>(CanonicalType); \
2360
15.5M
} \
clang::TemplateTypeParmType const* clang::Type::getAs<clang::TemplateTypeParmType>() const
Line
Count
Source
2358
33.6M
template <> inline const Class##Type *Type::getAs() const { \
2359
33.6M
  return dyn_cast<Class##Type>(CanonicalType); \
2360
33.6M
} \
2361
118M
template <> inline const Class##Type *Type::castAs() const { \
2362
118M
  return cast<Class##Type>(CanonicalType); \
2363
118M
}
clang::EnumType const* clang::Type::castAs<clang::EnumType>() const
Line
Count
Source
2361
9
template <> inline const Class##Type *Type::castAs() const { \
2362
9
  return cast<Class##Type>(CanonicalType); \
2363
9
}
clang::BuiltinType const* clang::Type::castAs<clang::BuiltinType>() const
Line
Count
Source
2361
357k
template <> inline const Class##Type *Type::castAs() const { \
2362
357k
  return cast<Class##Type>(CanonicalType); \
2363
357k
}
clang::RecordType const* clang::Type::castAs<clang::RecordType>() const
Line
Count
Source
2361
7.03M
template <> inline const Class##Type *Type::castAs() const { \
2362
7.03M
  return cast<Class##Type>(CanonicalType); \
2363
7.03M
}
Unexecuted instantiation: clang::InjectedClassNameType const* clang::Type::castAs<clang::InjectedClassNameType>() const
clang::ObjCInterfaceType const* clang::Type::castAs<clang::ObjCInterfaceType>() const
Line
Count
Source
2361
10.0k
template <> inline const Class##Type *Type::castAs() const { \
2362
10.0k
  return cast<Class##Type>(CanonicalType); \
2363
10.0k
}
clang::TemplateTypeParmType const* clang::Type::castAs<clang::TemplateTypeParmType>() const
Line
Count
Source
2361
110M
template <> inline const Class##Type *Type::castAs() const { \
2362
110M
  return cast<Class##Type>(CanonicalType); \
2363
110M
}
2364
#include "clang/AST/TypeNodes.def"
2365
2366
/// This class is used for builtin types like 'int'.  Builtin
2367
/// types are always canonical and have a literal name field.
2368
class BuiltinType : public Type {
2369
public:
2370
  enum Kind {
2371
// OpenCL image types
2372
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2373
#include "clang/Basic/OpenCLImageTypes.def"
2374
// All other builtin types
2375
#define BUILTIN_TYPE(Id, SingletonId) Id,
2376
#define LAST_BUILTIN_TYPE(Id) LastKind = Id
2377
#include "clang/AST/BuiltinTypes.def"
2378
  };
2379
2380
private:
2381
  friend class ASTContext; // ASTContext creates these.
2382
2383
  BuiltinType(Kind K)
2384
      : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
2385
             /*InstantiationDependent=*/(K == Dependent),
2386
             /*VariablyModified=*/false,
2387
2.25M
             /*Unexpanded parameter pack=*/false) {
2388
2.25M
    BuiltinTypeBits.Kind = K;
2389
2.25M
  }
2390
2391
public:
2392
918M
  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
2393
  StringRef getName(const PrintingPolicy &Policy) const;
2394
2395
2.82k
  const char *getNameAsCString(const PrintingPolicy &Policy) const {
2396
2.82k
    // The StringRef is null-terminated.
2397
2.82k
    StringRef str = getName(Policy);
2398
2.82k
    assert(!str.empty() && str.data()[str.size()] == '\0');
2399
2.82k
    return str.data();
2400
2.82k
  }
2401
2402
41.1M
  bool isSugared() const { return false; }
2403
0
  QualType desugar() const { return QualType(this, 0); }
2404
2405
1.55M
  bool isInteger() const {
2406
1.55M
    return getKind() >= Bool && getKind() <= Int128;
2407
1.55M
  }
2408
2409
  bool isSignedInteger() const {
2410
    return getKind() >= Char_S && getKind() <= Int128;
2411
  }
2412
2413
2.76M
  bool isUnsignedInteger() const {
2414
2.76M
    return getKind() >= Bool && getKind() <= UInt128;
2415
2.76M
  }
2416
2417
12.4M
  bool isFloatingPoint() const {
2418
12.4M
    return getKind() >= Half && 
getKind() <= Float1286.90M
;
2419
12.4M
  }
2420
2421
  /// Determines whether the given kind corresponds to a placeholder type.
2422
46.3M
  static bool isPlaceholderTypeKind(Kind K) {
2423
46.3M
    return K >= Overload;
2424
46.3M
  }
2425
2426
  /// Determines whether this type is a placeholder type, i.e. a type
2427
  /// which cannot appear in arbitrary positions in a fully-formed
2428
  /// expression.
2429
46.3M
  bool isPlaceholderType() const {
2430
46.3M
    return isPlaceholderTypeKind(getKind());
2431
46.3M
  }
2432
2433
  /// Determines whether this type is a placeholder type other than
2434
  /// Overload.  Most placeholder types require only syntactic
2435
  /// information about their context in order to be resolved (e.g.
2436
  /// whether it is a call expression), which means they can (and
2437
  /// should) be resolved in an earlier "phase" of analysis.
2438
  /// Overload expressions sometimes pick up further information
2439
  /// from their context, like whether the context expects a
2440
  /// specific function-pointer type, and so frequently need
2441
  /// special treatment.
2442
7.19M
  bool isNonOverloadPlaceholderType() const {
2443
7.19M
    return getKind() > Overload;
2444
7.19M
  }
2445
2446
1.01G
  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
2447
};
2448
2449
/// Complex values, per C99 6.2.5p11.  This supports the C99 complex
2450
/// types (_Complex float etc) as well as the GCC integer complex extensions.
2451
class ComplexType : public Type, public llvm::FoldingSetNode {
2452
  friend class ASTContext; // ASTContext creates these.
2453
2454
  QualType ElementType;
2455
2456
  ComplexType(QualType Element, QualType CanonicalPtr)
2457
      : Type(Complex, CanonicalPtr, Element->isDependentType(),
2458
             Element->isInstantiationDependentType(),
2459
             Element->isVariablyModifiedType(),
2460
             Element->containsUnexpandedParameterPack()),
2461
150k
        ElementType(Element) {}
2462
2463
public:
2464
46.3k
  QualType getElementType() const { return ElementType; }
2465
2466
10.2k
  bool isSugared() const { return false; }
2467
0
  QualType desugar() const { return QualType(this, 0); }
2468
2469
19.9k
  void Profile(llvm::FoldingSetNodeID &ID) {
2470
19.9k
    Profile(ID, getElementType());
2471
19.9k
  }
2472
2473
186k
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
2474
186k
    ID.AddPointer(Element.getAsOpaquePtr());
2475
186k
  }
2476
2477
100M
  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
2478
};
2479
2480
/// Sugar for parentheses used when specifying types.
2481
class ParenType : public Type, public llvm::FoldingSetNode {
2482
  friend class ASTContext; // ASTContext creates these.
2483
2484
  QualType Inner;
2485
2486
  ParenType(QualType InnerType, QualType CanonType)
2487
      : Type(Paren, CanonType, InnerType->isDependentType(),
2488
             InnerType->isInstantiationDependentType(),
2489
             InnerType->isVariablyModifiedType(),
2490
             InnerType->containsUnexpandedParameterPack()),
2491
133k
        Inner(InnerType) {}
2492
2493
public:
2494
1.86M
  QualType getInnerType() const { return Inner; }
2495
2496
367k
  bool isSugared() const { return true; }
2497
368k
  QualType desugar() const { return getInnerType(); }
2498
2499
275k
  void Profile(llvm::FoldingSetNodeID &ID) {
2500
275k
    Profile(ID, getInnerType());
2501
275k
  }
2502
2503
506k
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
2504
506k
    Inner.Profile(ID);
2505
506k
  }
2506
2507
11.3M
  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
2508
};
2509
2510
/// PointerType - C99 6.7.5.1 - Pointer Declarators.
2511
class PointerType : public Type, public llvm::FoldingSetNode {
2512
  friend class ASTContext; // ASTContext creates these.
2513
2514
  QualType PointeeType;
2515
2516
  PointerType(QualType Pointee, QualType CanonicalPtr)
2517
      : Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
2518
             Pointee->isInstantiationDependentType(),
2519
             Pointee->isVariablyModifiedType(),
2520
             Pointee->containsUnexpandedParameterPack()),
2521
3.02M
        PointeeType(Pointee) {}
2522
2523
public:
2524
102M
  QualType getPointeeType() const { return PointeeType; }
2525
2526
  /// Returns true if address spaces of pointers overlap.
2527
  /// OpenCL v2.0 defines conversion rules for pointers to different
2528
  /// address spaces (OpenCLC v2.0 s6.5.5) and notion of overlapping
2529
  /// address spaces.
2530
  /// CL1.1 or CL1.2:
2531
  ///   address spaces overlap iff they are they same.
2532
  /// CL2.0 adds:
2533
  ///   __generic overlaps with any address space except for __constant.
2534
347
  bool isAddressSpaceOverlapping(const PointerType &other) const {
2535
347
    Qualifiers thisQuals = PointeeType.getQualifiers();
2536
347
    Qualifiers otherQuals = other.getPointeeType().getQualifiers();
2537
347
    // Address spaces overlap if at least one of them is a superset of another
2538
347
    return thisQuals.isAddressSpaceSupersetOf(otherQuals) ||
2539
347
           
otherQuals.isAddressSpaceSupersetOf(thisQuals)166
;
2540
347
  }
2541
2542
11.4M
  bool isSugared() const { return false; }
2543
0
  QualType desugar() const { return QualType(this, 0); }
2544
2545
39.5M
  void Profile(llvm::FoldingSetNodeID &ID) {
2546
39.5M
    Profile(ID, getPointeeType());
2547
39.5M
  }
2548
2549
65.4M
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2550
65.4M
    ID.AddPointer(Pointee.getAsOpaquePtr());
2551
65.4M
  }
2552
2553
195M
  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
2554
};
2555
2556
/// Represents a type which was implicitly adjusted by the semantic
2557
/// engine for arbitrary reasons.  For example, array and function types can
2558
/// decay, and function types can have their calling conventions adjusted.
2559
class AdjustedType : public Type, public llvm::FoldingSetNode {
2560
  QualType OriginalTy;
2561
  QualType AdjustedTy;
2562
2563
protected:
2564
  friend class ASTContext; // ASTContext creates these.
2565
2566
  AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
2567
               QualType CanonicalPtr)
2568
      : Type(TC, CanonicalPtr, OriginalTy->isDependentType(),
2569
             OriginalTy->isInstantiationDependentType(),
2570
             OriginalTy->isVariablyModifiedType(),
2571
             OriginalTy->containsUnexpandedParameterPack()),
2572
19.6k
        OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2573
2574
public:
2575
4.47k
  QualType getOriginalType() const { return OriginalTy; }
2576
2.20k
  QualType getAdjustedType() const { return AdjustedTy; }
2577
2578
99.4k
  bool isSugared() const { return true; }
2579
99.5k
  QualType desugar() const { return AdjustedTy; }
2580
2581
33.4k
  void Profile(llvm::FoldingSetNodeID &ID) {
2582
33.4k
    Profile(ID, OriginalTy, AdjustedTy);
2583
33.4k
  }
2584
2585
84.0k
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) {
2586
84.0k
    ID.AddPointer(Orig.getAsOpaquePtr());
2587
84.0k
    ID.AddPointer(New.getAsOpaquePtr());
2588
84.0k
  }
2589
2590
17.5M
  static bool classof(const Type *T) {
2591
17.5M
    return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed;
2592
17.5M
  }
2593
};
2594
2595
/// Represents a pointer type decayed from an array or function type.
2596
class DecayedType : public AdjustedType {
2597
  friend class ASTContext; // ASTContext creates these.
2598
2599
  inline
2600
  DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical);
2601
2602
public:
2603
176
  QualType getDecayedType() const { return getAdjustedType(); }
2604
2605
  inline QualType getPointeeType() const;
2606
2607
8.09M
  static bool classof(const Type *T) { return T->getTypeClass() == Decayed; }
2608
};
2609
2610
/// Pointer to a block type.
2611
/// This type is to represent types syntactically represented as
2612
/// "void (^)(int)", etc. Pointee is required to always be a function type.
2613
class BlockPointerType : public Type, public llvm::FoldingSetNode {
2614
  friend class ASTContext; // ASTContext creates these.
2615
2616
  // Block is some kind of pointer type
2617
  QualType PointeeType;
2618
2619
  BlockPointerType(QualType Pointee, QualType CanonicalCls)
2620
      : Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
2621
             Pointee->isInstantiationDependentType(),
2622
             Pointee->isVariablyModifiedType(),
2623
             Pointee->containsUnexpandedParameterPack()),
2624
15.3k
        PointeeType(Pointee) {}
2625
2626
public:
2627
  // Get the pointee type. Pointee is required to always be a function type.
2628
121k
  QualType getPointeeType() const { return PointeeType; }
2629
2630
43.3k
  bool isSugared() const { return false; }
2631
0
  QualType desugar() const { return QualType(this, 0); }
2632
2633
20.9k
  void Profile(llvm::FoldingSetNodeID &ID) {
2634
20.9k
      Profile(ID, getPointeeType());
2635
20.9k
  }
2636
2637
49.5k
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2638
49.5k
      ID.AddPointer(Pointee.getAsOpaquePtr());
2639
49.5k
  }
2640
2641
76.1M
  static bool classof(const Type *T) {
2642
76.1M
    return T->getTypeClass() == BlockPointer;
2643
76.1M
  }
2644
};
2645
2646
/// Base for LValueReferenceType and RValueReferenceType
2647
class ReferenceType : public Type, public llvm::FoldingSetNode {
2648
  QualType PointeeType;
2649
2650
protected:
2651
  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
2652
                bool SpelledAsLValue)
2653
      : Type(tc, CanonicalRef, Referencee->isDependentType(),
2654
             Referencee->isInstantiationDependentType(),
2655
             Referencee->isVariablyModifiedType(),
2656
             Referencee->containsUnexpandedParameterPack()),
2657
1.93M
        PointeeType(Referencee) {
2658
1.93M
    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
2659
1.93M
    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
2660
1.93M
  }
2661
2662
public:
2663
18.7M
  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
2664
21.5M
  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
2665
2666
18.2M
  QualType getPointeeTypeAsWritten() const { return PointeeType; }
2667
2668
21.3M
  QualType getPointeeType() const {
2669
21.3M
    // FIXME: this might strip inner qualifiers; okay?
2670
21.3M
    const ReferenceType *T = this;
2671
21.5M
    while (T->isInnerRef())
2672
185k
      T = T->PointeeType->castAs<ReferenceType>();
2673
21.3M
    return T->PointeeType;
2674
21.3M
  }
2675
2676
17.5M
  void Profile(llvm::FoldingSetNodeID &ID) {
2677
17.5M
    Profile(ID, PointeeType, isSpelledAsLValue());
2678
17.5M
  }
2679
2680
  static void Profile(llvm::FoldingSetNodeID &ID,
2681
                      QualType Referencee,
2682
27.4M
                      bool SpelledAsLValue) {
2683
27.4M
    ID.AddPointer(Referencee.getAsOpaquePtr());
2684
27.4M
    ID.AddBoolean(SpelledAsLValue);
2685
27.4M
  }
2686
2687
330M
  static bool classof(const Type *T) {
2688
330M
    return T->getTypeClass() == LValueReference ||
2689
330M
           
T->getTypeClass() == RValueReference303M
;
2690
330M
  }
2691
};
2692
2693
/// An lvalue reference type, per C++11 [dcl.ref].
2694
class LValueReferenceType : public ReferenceType {
2695
  friend class ASTContext; // ASTContext creates these
2696
2697
  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
2698
                      bool SpelledAsLValue)
2699
      : ReferenceType(LValueReference, Referencee, CanonicalRef,
2700
1.49M
                      SpelledAsLValue) {}
2701
2702
public:
2703
2.05M
  bool isSugared() const { return false; }
2704
0
  QualType desugar() const { return QualType(this, 0); }
2705
2706
9.58M
  static bool classof(const Type *T) {
2707
9.58M
    return T->getTypeClass() == LValueReference;
2708
9.58M
  }
2709
};
2710
2711
/// An rvalue reference type, per C++11 [dcl.ref].
2712
class RValueReferenceType : public ReferenceType {
2713
  friend class ASTContext; // ASTContext creates these
2714
2715
  RValueReferenceType(QualType Referencee, QualType CanonicalRef)
2716
445k
       : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {}
2717
2718
public:
2719
329k
  bool isSugared() const { return false; }
2720
0
  QualType desugar() const { return QualType(this, 0); }
2721
2722
14.0M
  static bool classof(const Type *T) {
2723
14.0M
    return T->getTypeClass() == RValueReference;
2724
14.0M
  }
2725
};
2726
2727
/// A pointer to member type per C++ 8.3.3 - Pointers to members.
2728
///
2729
/// This includes both pointers to data members and pointer to member functions.
2730
class MemberPointerType : public Type, public llvm::FoldingSetNode {
2731
  friend class ASTContext; // ASTContext creates these.
2732
2733
  QualType PointeeType;
2734
2735
  /// The class of which the pointee is a member. Must ultimately be a
2736
  /// RecordType, but could be a typedef or a template parameter too.
2737
  const Type *Class;
2738
2739
  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
2740
      : Type(MemberPointer, CanonicalPtr,
2741
             Cls->isDependentType() || Pointee->isDependentType(),
2742
             (Cls->isInstantiationDependentType() ||
2743
              Pointee->isInstantiationDependentType()),
2744
             Pointee->isVariablyModifiedType(),
2745
             (Cls->containsUnexpandedParameterPack() ||
2746
              Pointee->containsUnexpandedParameterPack())),
2747
54.5k
             PointeeType(Pointee), Class(Cls) {}
2748
2749
public:
2750
647k
  QualType getPointeeType() const { return PointeeType; }
2751
2752
  /// Returns true if the member type (i.e. the pointee type) is a
2753
  /// function type rather than a data-member type.
2754
4.82k
  bool isMemberFunctionPointer() const {
2755
4.82k
    return PointeeType->isFunctionProtoType();
2756
4.82k
  }
2757
2758
  /// Returns true if the member type (i.e. the pointee type) is a
2759
  /// data type rather than a function type.
2760
984
  bool isMemberDataPointer() const {
2761
984
    return !PointeeType->isFunctionProtoType();
2762
984
  }
2763
2764
230k
  const Type *getClass() const { return Class; }
2765
  CXXRecordDecl *getMostRecentCXXRecordDecl() const;
2766
2767
35.7k
  bool isSugared() const { return false; }
2768
0
  QualType desugar() const { return QualType(this, 0); }
2769
2770
74.9k
  void Profile(llvm::FoldingSetNodeID &ID) {
2771
74.9k
    Profile(ID, getPointeeType(), getClass());
2772
74.9k
  }
2773
2774
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
2775
145k
                      const Type *Class) {
2776
145k
    ID.AddPointer(Pointee.getAsOpaquePtr());
2777
145k
    ID.AddPointer(Class);
2778
145k
  }
2779
2780
226M
  static bool classof(const Type *T) {
2781
226M
    return T->getTypeClass() == MemberPointer;
2782
226M
  }
2783
};
2784
2785
/// Represents an array type, per C99 6.7.5.2 - Array Declarators.
2786
class ArrayType : public Type, public llvm::FoldingSetNode {
2787
public:
2788
  /// Capture whether this is a normal array (e.g. int X[4])
2789
  /// an array with a static size (e.g. int X[static 4]), or an array
2790
  /// with a star size (e.g. int X[*]).
2791
  /// 'static' is only allowed on function parameters.
2792
  enum ArraySizeModifier {
2793
    Normal, Static, Star
2794
  };
2795
2796
private:
2797
  /// The element type of the array.
2798
  QualType ElementType;
2799
2800
protected:
2801
  friend class ASTContext; // ASTContext creates these.
2802
2803
  // C++ [temp.dep.type]p1:
2804
  //   A type is dependent if it is...
2805
  //     - an array type constructed from any dependent type or whose
2806
  //       size is specified by a constant expression that is
2807
  //       value-dependent,
2808
  ArrayType(TypeClass tc, QualType et, QualType can,
2809
            ArraySizeModifier sm, unsigned tq,
2810
            bool ContainsUnexpandedParameterPack)
2811
      : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2812
             et->isInstantiationDependentType() || tc == DependentSizedArray,
2813
             (tc == VariableArray || et->isVariablyModifiedType()),
2814
             ContainsUnexpandedParameterPack),
2815
602k
        ElementType(et) {
2816
602k
    ArrayTypeBits.IndexTypeQuals = tq;
2817
602k
    ArrayTypeBits.SizeModifier = sm;
2818
602k
  }
2819
2820
public:
2821
15.0M
  QualType getElementType() const { return ElementType; }
2822
2823
5.16M
  ArraySizeModifier getSizeModifier() const {
2824
5.16M
    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
2825
5.16M
  }
2826
2827
1.46M
  Qualifiers getIndexTypeQualifiers() const {
2828
1.46M
    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
2829
1.46M
  }
2830
2831
6.59M
  unsigned getIndexTypeCVRQualifiers() const {
2832
6.59M
    return ArrayTypeBits.IndexTypeQuals;
2833
6.59M
  }
2834
2835
344M
  static bool classof(const Type *T) {
2836
344M
    return T->getTypeClass() == ConstantArray ||
2837
344M
           
T->getTypeClass() == VariableArray336M
||
2838
344M
           
T->getTypeClass() == IncompleteArray336M
||
2839
344M
           
T->getTypeClass() == DependentSizedArray335M
;
2840
344M
  }
2841
};
2842
2843
/// Represents the canonical version of C arrays with a specified constant size.
2844
/// For example, the canonical type for 'int A[4 + 4*100]' is a
2845
/// ConstantArrayType where the element type is 'int' and the size is 404.
2846
class ConstantArrayType : public ArrayType {
2847
  llvm::APInt Size; // Allows us to unique the type.
2848
2849
  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
2850
                    ArraySizeModifier sm, unsigned tq)
2851
      : ArrayType(ConstantArray, et, can, sm, tq,
2852
                  et->containsUnexpandedParameterPack()),
2853
512k
        Size(size) {}
2854
2855
protected:
2856
  friend class ASTContext; // ASTContext creates these.
2857
2858
  ConstantArrayType(TypeClass tc, QualType et, QualType can,
2859
                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
2860
      : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2861
        Size(size) {}
2862
2863
public:
2864
6.60M
  const llvm::APInt &getSize() const { return Size; }
2865
3.83M
  bool isSugared() const { return false; }
2866
0
  QualType desugar() const { return QualType(this, 0); }
2867
2868
  /// Determine the number of bits required to address a member of
2869
  // an array with the given element type and number of elements.
2870
  static unsigned getNumAddressingBits(const ASTContext &Context,
2871
                                       QualType ElementType,
2872
                                       const llvm::APInt &NumElements);
2873
2874
  /// Determine the maximum number of active bits that an array's size
2875
  /// can require, which limits the maximum size of the array.
2876
  static unsigned getMaxSizeBits(const ASTContext &Context);
2877
2878
4.94M
  void Profile(llvm::FoldingSetNodeID &ID) {
2879
4.94M
    Profile(ID, getElementType(), getSize(),
2880
4.94M
            getSizeModifier(), getIndexTypeCVRQualifiers());
2881
4.94M
  }
2882
2883
  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2884
                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
2885
8.17M
                      unsigned TypeQuals) {
2886
8.17M
    ID.AddPointer(ET.getAsOpaquePtr());
2887
8.17M
    ID.AddInteger(ArraySize.getZExtValue());
2888
8.17M
    ID.AddInteger(SizeMod);
2889
8.17M
    ID.AddInteger(TypeQuals);
2890
8.17M
  }
2891
2892
9.98M
  static bool classof(const Type *T) {
2893
9.98M
    return T->getTypeClass() == ConstantArray;
2894
9.98M
  }
2895
};
2896
2897
/// Represents a C array with an unspecified size.  For example 'int A[]' has
2898
/// an IncompleteArrayType where the element type is 'int' and the size is
2899
/// unspecified.
2900
class IncompleteArrayType : public ArrayType {
2901
  friend class ASTContext; // ASTContext creates these.
2902
2903
  IncompleteArrayType(QualType et, QualType can,
2904
                      ArraySizeModifier sm, unsigned tq)
2905
      : ArrayType(IncompleteArray, et, can, sm, tq,
2906
39.1k
                  et->containsUnexpandedParameterPack()) {}
2907
2908
public:
2909
  friend class StmtIteratorBase;
2910
2911
73.9k
  bool isSugared() const { return false; }
2912
0
  QualType desugar() const { return QualType(this, 0); }
2913
2914
25.1M
  static bool classof(const Type *T) {
2915
25.1M
    return T->getTypeClass() == IncompleteArray;
2916
25.1M
  }
2917
2918
34.0k
  void Profile(llvm::FoldingSetNodeID &ID) {
2919
34.0k
    Profile(ID, getElementType(), getSizeModifier(),
2920
34.0k
            getIndexTypeCVRQualifiers());
2921
34.0k
  }
2922
2923
  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2924
100k
                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
2925
100k
    ID.AddPointer(ET.getAsOpaquePtr());
2926
100k
    ID.AddInteger(SizeMod);
2927
100k
    ID.AddInteger(TypeQuals);
2928
100k
  }
2929
};
2930
2931
/// Represents a C array with a specified size that is not an
2932
/// integer-constant-expression.  For example, 'int s[x+foo()]'.
2933
/// Since the size expression is an arbitrary expression, we store it as such.
2934
///
2935
/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2936
/// should not be: two lexically equivalent variable array types could mean
2937
/// different things, for example, these variables do not have the same type
2938
/// dynamically:
2939
///
2940
/// void foo(int x) {
2941
///   int Y[x];
2942
///   ++x;
2943
///   int Z[x];
2944
/// }
2945
class VariableArrayType : public ArrayType {
2946
  friend class ASTContext; // ASTContext creates these.
2947
2948
  /// An assignment-expression. VLA's are only permitted within
2949
  /// a function block.
2950
  Stmt *SizeExpr;
2951
2952
  /// The range spanned by the left and right array brackets.
2953
  SourceRange Brackets;
2954
2955
  VariableArrayType(QualType et, QualType can, Expr *e,
2956
                    ArraySizeModifier sm, unsigned tq,
2957
                    SourceRange brackets)
2958
      : ArrayType(VariableArray, et, can, sm, tq,
2959
                  et->containsUnexpandedParameterPack()),
2960
8.04k
        SizeExpr((Stmt*) e), Brackets(brackets) {}
2961
2962
public:
2963
  friend class StmtIteratorBase;
2964
2965
39.7k
  Expr *getSizeExpr() const {
2966
39.7k
    // We use C-style casts instead of cast<> here because we do not wish
2967
39.7k
    // to have a dependency of Type.h on Stmt.h/Expr.h.
2968
39.7k
    return (Expr*) SizeExpr;
2969
39.7k
  }
2970
2971
186
  SourceRange getBracketsRange() const { return Brackets; }
2972
973
  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
2973
973
  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
2974
2975
51.9k
  bool isSugared() const { return false; }
2976
33
  QualType desugar() const { return QualType(this, 0); }
2977
2978
25.8M
  static bool classof(const Type *T) {
2979
25.8M
    return T->getTypeClass() == VariableArray;
2980
25.8M
  }
2981
2982
  void Profile(llvm::FoldingSetNodeID &ID) {
2983
    llvm_unreachable("Cannot unique VariableArrayTypes.");
2984
  }
2985
};
2986
2987
/// Represents an array type in C++ whose size is a value-dependent expression.
2988
///
2989
/// For example:
2990
/// \code
2991
/// template<typename T, int Size>
2992
/// class array {
2993
///   T data[Size];
2994
/// };
2995
/// \endcode
2996
///
2997
/// For these types, we won't actually know what the array bound is
2998
/// until template instantiation occurs, at which point this will
2999
/// become either a ConstantArrayType or a VariableArrayType.
3000
class DependentSizedArrayType : public ArrayType {
3001
  friend class ASTContext; // ASTContext creates these.
3002
3003
  const ASTContext &Context;
3004
3005
  /// An assignment expression that will instantiate to the
3006
  /// size of the array.
3007
  ///
3008
  /// The expression itself might be null, in which case the array
3009
  /// type will have its size deduced from an initializer.
3010
  Stmt *SizeExpr;
3011
3012
  /// The range spanned by the left and right array brackets.
3013
  SourceRange Brackets;
3014
3015
  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
3016
                          Expr *e, ArraySizeModifier sm, unsigned tq,
3017
                          SourceRange brackets);
3018
3019
public:
3020
  friend class StmtIteratorBase;
3021
3022
52.0k
  Expr *getSizeExpr() const {
3023
52.0k
    // We use C-style casts instead of cast<> here because we do not wish
3024
52.0k
    // to have a dependency of Type.h on Stmt.h/Expr.h.
3025
52.0k
    return (Expr*) SizeExpr;
3026
52.0k
  }
3027
3028
717
  SourceRange getBracketsRange() const { return Brackets; }
3029
0
  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3030
0
  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3031
3032
71.7k
  bool isSugared() const { return false; }
3033
0
  QualType desugar() const { return QualType(this, 0); }
3034
3035
1.24k
  static bool classof(const Type *T) {
3036
1.24k
    return T->getTypeClass() == DependentSizedArray;
3037
1.24k
  }
3038
3039
12.8k
  void Profile(llvm::FoldingSetNodeID &ID) {
3040
12.8k
    Profile(ID, Context, getElementType(),
3041
12.8k
            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3042
12.8k
  }
3043
3044
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3045
                      QualType ET, ArraySizeModifier SizeMod,
3046
                      unsigned TypeQuals, Expr *E);
3047
};
3048
3049
/// Represents an extended address space qualifier where the input address space
3050
/// value is dependent. Non-dependent address spaces are not represented with a
3051
/// special Type subclass; they are stored on an ExtQuals node as part of a QualType.
3052
///
3053
/// For example:
3054
/// \code
3055
/// template<typename T, int AddrSpace>
3056
/// class AddressSpace {
3057
///   typedef T __attribute__((address_space(AddrSpace))) type;
3058
/// }
3059
/// \endcode
3060
class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
3061
  friend class ASTContext;
3062
3063
  const ASTContext &Context;
3064
  Expr *AddrSpaceExpr;
3065
  QualType PointeeType;
3066
  SourceLocation loc;
3067
3068
  DependentAddressSpaceType(const ASTContext &Context, QualType PointeeType,
3069
                            QualType can, Expr *AddrSpaceExpr,
3070
                            SourceLocation loc);
3071
3072
public:
3073
255
  Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; }
3074
685
  QualType getPointeeType() const { return PointeeType; }
3075
56
  SourceLocation getAttributeLoc() const { return loc; }
3076
3077
9
  bool isSugared() const { return false; }
3078
0
  QualType desugar() const { return QualType(this, 0); }
3079
3080
21.8M
  static bool classof(const Type *T) {
3081
21.8M
    return T->getTypeClass() == DependentAddressSpace;
3082
21.8M
  }
3083
3084
17
  void Profile(llvm::FoldingSetNodeID &ID) {
3085
17
    Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3086
17
  }
3087
3088
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3089
                      QualType PointeeType, Expr *AddrSpaceExpr);
3090
};
3091
3092
/// Represents an extended vector type where either the type or size is
3093
/// dependent.
3094
///
3095
/// For example:
3096
/// \code
3097
/// template<typename T, int Size>
3098
/// class vector {
3099
///   typedef T __attribute__((ext_vector_type(Size))) type;
3100
/// }
3101
/// \endcode
3102
class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
3103
  friend class ASTContext;
3104
3105
  const ASTContext &Context;
3106
  Expr *SizeExpr;
3107
3108
  /// The element type of the array.
3109
  QualType ElementType;
3110
3111
  SourceLocation loc;
3112
3113
  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
3114
                              QualType can, Expr *SizeExpr, SourceLocation loc);
3115
3116
public:
3117
56
  Expr *getSizeExpr() const { return SizeExpr; }
3118
105
  QualType getElementType() const { return ElementType; }
3119
23
  SourceLocation getAttributeLoc() const { return loc; }
3120
3121
0
  bool isSugared() const { return false; }
3122
0
  QualType desugar() const { return QualType(this, 0); }
3123
3124
22
  static bool classof(const Type *T) {
3125
22
    return T->getTypeClass() == DependentSizedExtVector;
3126
22
  }
3127
3128
10
  void Profile(llvm::FoldingSetNodeID &ID) {
3129
10
    Profile(ID, Context, getElementType(), getSizeExpr());
3130
10
  }
3131
3132
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3133
                      QualType ElementType, Expr *SizeExpr);
3134
};
3135
3136
3137
/// Represents a GCC generic vector type. This type is created using
3138
/// __attribute__((vector_size(n)), where "n" specifies the vector size in
3139
/// bytes; or from an Altivec __vector or vector declaration.
3140
/// Since the constructor takes the number of vector elements, the
3141
/// client is responsible for converting the size into the number of elements.
3142
class VectorType : public Type, public llvm::FoldingSetNode {
3143
public:
3144
  enum VectorKind {
3145
    /// not a target-specific vector type
3146
    GenericVector,
3147
3148
    /// is AltiVec vector
3149
    AltiVecVector,
3150
3151
    /// is AltiVec 'vector Pixel'
3152
    AltiVecPixel,
3153
3154
    /// is AltiVec 'vector bool ...'
3155
    AltiVecBool,
3156
3157
    /// is ARM Neon vector
3158
    NeonVector,
3159
3160
    /// is ARM Neon polynomial vector
3161
    NeonPolyVector
3162
  };
3163
3164
protected:
3165
  friend class ASTContext; // ASTContext creates these.
3166
3167
  /// The element type of the vector.
3168
  QualType ElementType;
3169
3170
  VectorType(QualType vecType, unsigned nElements, QualType canonType,
3171
             VectorKind vecKind);
3172
3173
  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
3174
             QualType canonType, VectorKind vecKind);
3175
3176
public:
3177
10.6M
  QualType getElementType() const { return ElementType; }
3178
10.5M
  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
3179
3180
11.4k
  static bool isVectorSizeTooLarge(unsigned NumElements) {
3181
11.4k
    return NumElements > VectorTypeBitfields::MaxNumElements;
3182
11.4k
  }
3183
3184
11.4M
  bool isSugared() const { return false; }
3185
0
  QualType desugar() const { return QualType(this, 0); }
3186
3187
7.30M
  VectorKind getVectorKind() const {
3188
7.30M
    return VectorKind(VectorTypeBits.VecKind);
3189
7.30M
  }
3190
3191
3.45M
  void Profile(llvm::FoldingSetNodeID &ID) {
3192
3.45M
    Profile(ID, getElementType(), getNumElements(),
3193
3.45M
            getTypeClass(), getVectorKind());
3194
3.45M
  }
3195
3196
  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
3197
                      unsigned NumElements, TypeClass TypeClass,
3198
6.04M
                      VectorKind VecKind) {
3199
6.04M
    ID.AddPointer(ElementType.getAsOpaquePtr());
3200
6.04M
    ID.AddInteger(NumElements);
3201
6.04M
    ID.AddInteger(TypeClass);
3202
6.04M
    ID.AddInteger(VecKind);
3203
6.04M
  }
3204
3205
102M
  static bool classof(const Type *T) {
3206
102M
    return T->getTypeClass() == Vector || 
T->getTypeClass() == ExtVector83.5M
;
3207
102M
  }
3208
};
3209
3210
/// Represents a vector type where either the type or size is dependent.
3211
////
3212
/// For example:
3213
/// \code
3214
/// template<typename T, int Size>
3215
/// class vector {
3216
///   typedef T __attribute__((vector_size(Size))) type;
3217
/// }
3218
/// \endcode
3219
class DependentVectorType : public Type, public llvm::FoldingSetNode {
3220
  friend class ASTContext;
3221
3222
  const ASTContext &Context;
3223
  QualType ElementType;
3224
  Expr *SizeExpr;
3225
  SourceLocation Loc;
3226
3227
  DependentVectorType(const ASTContext &Context, QualType ElementType,
3228
                           QualType CanonType, Expr *SizeExpr,
3229
                           SourceLocation Loc, VectorType::VectorKind vecKind);
3230
3231
public:
3232
39
  Expr *getSizeExpr() const { return SizeExpr; }
3233
78
  QualType getElementType() const { return ElementType; }
3234
39
  SourceLocation getAttributeLoc() const { return Loc; }
3235
39
  VectorType::VectorKind getVectorKind() const {
3236
39
    return VectorType::VectorKind(VectorTypeBits.VecKind);
3237
39
  }
3238
3239
0
  bool isSugared() const { return false; }
3240
0
  QualType desugar() const { return QualType(this, 0); }
3241
3242
15
  static bool classof(const Type *T) {
3243
15
    return T->getTypeClass() == DependentVector;
3244
15
  }
3245
3246
0
  void Profile(llvm::FoldingSetNodeID &ID) {
3247
0
    Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
3248
0
  }
3249
3250
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3251
                      QualType ElementType, const Expr *SizeExpr,
3252
                      VectorType::VectorKind VecKind);
3253
};
3254
3255
/// ExtVectorType - Extended vector type. This type is created using
3256
/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
3257
/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
3258
/// class enables syntactic extensions, like Vector Components for accessing
3259
/// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
3260
/// Shading Language).
3261
class ExtVectorType : public VectorType {
3262
  friend class ASTContext; // ASTContext creates these.
3263
3264
  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
3265
2.97k
      : VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
3266
3267
public:
3268
1.38k
  static int getPointAccessorIdx(char c) {
3269
1.38k
    switch (c) {
3270
1.38k
    
default: return -16
;
3271
1.38k
    
case 'x': 654
case 'r': return 0654
;
3272
654
    
case 'y': 498
case 'g': return 1498
;
3273
498
    
case 'z': 133
case 'b': return 2133
;
3274
133
    
case 'w': 94
case 'a': return 394
;
3275
1.38k
    }
3276
1.38k
  }
3277
3278
90
  static int getNumericAccessorIdx(char c) {
3279
90
    switch (c) {
3280
90
      
default: return -120
;
3281
90
      
case '0': return 016
;
3282
90
      
case '1': return 111
;
3283
90
      
case '2': return 24
;
3284
90
      
case '3': return 34
;
3285
90
      
case '4': return 46
;
3286
90
      
case '5': return 50
;
3287
90
      
case '6': return 64
;
3288
90
      
case '7': return 70
;
3289
90
      
case '8': return 80
;
3290
90
      
case '9': return 90
;
3291
90
      case 'A':
3292
3
      case 'a': return 10;
3293
8
      case 'B':
3294
8
      case 'b': return 11;
3295
8
      case 'C':
3296
3
      case 'c': return 12;
3297
3
      case 'D':
3298
3
      case 'd': return 13;
3299
3
      case 'E':
3300
0
      case 'e': return 14;
3301
8
      case 'F':
3302
8
      case 'f': return 15;
3303
90
    }
3304
90
  }
3305
3306
873
  static int getAccessorIdx(char c, bool isNumericAccessor) {
3307
873
    if (isNumericAccessor)
3308
37
      return getNumericAccessorIdx(c);
3309
836
    else
3310
836
      return getPointAccessorIdx(c);
3311
873
  }
3312
3313
550
  bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
3314
550
    if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
3315
550
      return unsigned(idx-1) < getNumElements();
3316
0
    return false;
3317
0
  }
3318
3319
390k
  bool isSugared() const { return false; }
3320
0
  QualType desugar() const { return QualType(this, 0); }
3321
3322
5.28M
  static bool classof(const Type *T) {
3323
5.28M
    return T->getTypeClass() == ExtVector;
3324
5.28M
  }
3325
};
3326
3327
/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
3328
/// class of FunctionNoProtoType and FunctionProtoType.
3329
class FunctionType : public Type {
3330
  // The type returned by the function.
3331
  QualType ResultType;
3332
3333
public:
3334
  /// A class which abstracts out some details necessary for
3335
  /// making a call.
3336
  ///
3337
  /// It is not actually used directly for storing this information in
3338
  /// a FunctionType, although FunctionType does currently use the
3339
  /// same bit-pattern.
3340
  ///
3341
  // If you add a field (say Foo), other than the obvious places (both,
3342
  // constructors, compile failures), what you need to update is
3343
  // * Operator==
3344
  // * getFoo
3345
  // * withFoo
3346
  // * functionType. Add Foo, getFoo.
3347
  // * ASTContext::getFooType
3348
  // * ASTContext::mergeFunctionTypes
3349
  // * FunctionNoProtoType::Profile
3350
  // * FunctionProtoType::Profile
3351
  // * TypePrinter::PrintFunctionProto
3352
  // * AST read and write
3353
  // * Codegen
3354
0
  class ExtInfo {
3355
    friend class FunctionType;
3356
3357
    // Feel free to rearrange or add bits, but if you go over 12,
3358
    // you'll need to adjust both the Bits field below and
3359
    // Type::FunctionTypeBitfields.
3360
3361
    //   |  CC  |noreturn|produces|nocallersavedregs|regparm|nocfcheck|
3362
    //   |0 .. 4|   5    |    6   |       7         |8 .. 10|    11   |
3363
    //
3364
    // regparm is either 0 (no regparm attribute) or the regparm value+1.
3365
    enum { CallConvMask = 0x1F };
3366
    enum { NoReturnMask = 0x20 };
3367
    enum { ProducesResultMask = 0x40 };
3368
    enum { NoCallerSavedRegsMask = 0x80 };
3369
    enum { NoCfCheckMask = 0x800 };
3370
    enum {
3371
      RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask |
3372
                      NoCallerSavedRegsMask | NoCfCheckMask),
3373
      RegParmOffset = 8
3374
    }; // Assumed to be the last field
3375
    uint16_t Bits = CC_C;
3376
3377
56.8M
    ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
3378
3379
   public:
3380
     // Constructor with no defaults. Use this when you know that you
3381
     // have all the elements (when reading an AST file for example).
3382
     ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
3383
17.1k
             bool producesResult, bool noCallerSavedRegs, bool NoCfCheck) {
3384
17.1k
       assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
3385
17.1k
       Bits = ((unsigned)cc) | (noReturn ? 
NoReturnMask4
:
017.1k
) |
3386
17.1k
              (producesResult ? 
ProducesResultMask0
: 0) |
3387
17.1k
              (noCallerSavedRegs ? 
NoCallerSavedRegsMask0
: 0) |
3388
17.1k
              (hasRegParm ? 
((regParm + 1) << RegParmOffset)0
: 0) |
3389
17.1k
              (NoCfCheck ? 
NoCfCheckMask0
: 0);
3390
17.1k
    }
3391
3392
    // Constructor with all defaults. Use when for example creating a
3393
    // function known to use defaults.
3394
46.1M
    ExtInfo() = default;
3395
3396
    // Constructor with just the calling convention, which is an important part
3397
    // of the canonical type.
3398
7.66M
    ExtInfo(CallingConv CC) : Bits(CC) {}
3399
3400
11.6M
    bool getNoReturn() const { return Bits & NoReturnMask; }
3401
5.67M
    bool getProducesResult() const { return Bits & ProducesResultMask; }
3402
4.24M
    bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
3403
3.17M
    bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
3404
4.26M
    bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
3405
3406
4.28M
    unsigned getRegParm() const {
3407
4.28M
      unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
3408
4.28M
      if (RegParm > 0)
3409
176
        --RegParm;
3410
4.28M
      return RegParm;
3411
4.28M
    }
3412
3413
8.53M
    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
3414
3415
1.66M
    bool operator==(ExtInfo Other) const {
3416
1.66M
      return Bits == Other.Bits;
3417
1.66M
    }
3418
387
    bool operator!=(ExtInfo Other) const {
3419
387
      return Bits != Other.Bits;
3420
387
    }
3421
3422
    // Note that we don't have setters. That is by design, use
3423
    // the following with methods instead of mutating these objects.
3424
3425
41.2k
    ExtInfo withNoReturn(bool noReturn) const {
3426
41.2k
      if (noReturn)
3427
36.5k
        return ExtInfo(Bits | NoReturnMask);
3428
4.68k
      else
3429
4.68k
        return ExtInfo(Bits & ~NoReturnMask);
3430
41.2k
    }
3431
3432
335
    ExtInfo withProducesResult(bool producesResult) const {
3433
335
      if (producesResult)
3434
335
        return ExtInfo(Bits | ProducesResultMask);
3435
0
      else
3436
0
        return ExtInfo(Bits & ~ProducesResultMask);
3437
335
    }
3438
3439
14
    ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
3440
14
      if (noCallerSavedRegs)
3441
14
        return ExtInfo(Bits | NoCallerSavedRegsMask);
3442
0
      else
3443
0
        return ExtInfo(Bits & ~NoCallerSavedRegsMask);
3444
14
    }
3445
3446
6
    ExtInfo withNoCfCheck(bool noCfCheck) const {
3447
6
      if (noCfCheck)
3448
6
        return ExtInfo(Bits | NoCfCheckMask);
3449
0
      else
3450
0
        return ExtInfo(Bits & ~NoCfCheckMask);
3451
6
    }
3452
3453
73
    ExtInfo withRegParm(unsigned RegParm) const {
3454
73
      assert(RegParm < 7 && "Invalid regparm value");
3455
73
      return ExtInfo((Bits & ~RegParmMask) |
3456
73
                     ((RegParm + 1) << RegParmOffset));
3457
73
    }
3458
3459
568k
    ExtInfo withCallingConv(CallingConv cc) const {
3460
568k
      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
3461
568k
    }
3462
3463
49.5M
    void Profile(llvm::FoldingSetNodeID &ID) const {
3464
49.5M
      ID.AddInteger(Bits);
3465
49.5M
    }
3466
  };
3467
3468
protected:
3469
  FunctionType(TypeClass tc, QualType res,
3470
               QualType Canonical, bool Dependent,
3471
               bool InstantiationDependent,
3472
               bool VariablyModified, bool ContainsUnexpandedParameterPack,
3473
               ExtInfo Info)
3474
      : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3475
             ContainsUnexpandedParameterPack),
3476
7.55M
        ResultType(res) {
3477
7.55M
    FunctionTypeBits.ExtInfo = Info.Bits;
3478
7.55M
  }
3479
3480
50.3M
  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
3481
3482
public:
3483
128M
  QualType getReturnType() const { return ResultType; }
3484
3485
120
  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
3486
10
  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
3487
3488
  /// Determine whether this function type includes the GNU noreturn
3489
  /// attribute. The C++11 [[noreturn]] attribute does not affect the function
3490
  /// type.
3491
6.49M
  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
3492
3493
3.60M
  CallingConv getCallConv() const { return getExtInfo().getCC(); }
3494
56.2M
  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
3495
31.2k
  bool isConst() const { return getTypeQuals() & Qualifiers::Const; }
3496
17.5k
  bool isVolatile() const { return getTypeQuals() & Qualifiers::Volatile; }
3497
5.10k
  bool isRestrict() const { return getTypeQuals() & Qualifiers::Restrict; }
3498
3499
  /// Determine the type of an expression that calls a function of
3500
  /// this type.
3501
2.81M
  QualType getCallResultType(const ASTContext &Context) const {
3502
2.81M
    return getReturnType().getNonLValueExprType(Context);
3503
2.81M
  }
3504
3505
  static StringRef getNameForCallConv(CallingConv CC);
3506
3507
244M
  static bool classof(const Type *T) {
3508
244M
    return T->getTypeClass() == FunctionNoProto ||
3509
244M
           
T->getTypeClass() == FunctionProto243M
;
3510
244M
  }
3511
};
3512
3513
/// Represents a K&R-style 'int foo()' function, which has
3514
/// no information available about its arguments.
3515
class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
3516
  friend class ASTContext; // ASTContext creates these.
3517
3518
  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
3519
      : FunctionType(FunctionNoProto, Result, Canonical,
3520
                     /*Dependent=*/false, /*InstantiationDependent=*/false,
3521
                     Result->isVariablyModifiedType(),
3522
10.5k
                     /*ContainsUnexpandedParameterPack=*/false, Info) {}
3523
3524
public:
3525
  // No additional state past what FunctionType provides.
3526
3527
13.9k
  bool isSugared() const { return false; }
3528
0
  QualType desugar() const { return QualType(this, 0); }
3529
3530
119k
  void Profile(llvm::FoldingSetNodeID &ID) {
3531
119k
    Profile(ID, getReturnType(), getExtInfo());
3532
119k
  }
3533
3534
  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
3535
247k
                      ExtInfo Info) {
3536
247k
    Info.Profile(ID);
3537
247k
    ID.AddPointer(ResultType.getAsOpaquePtr());
3538
247k
  }
3539
3540
62.2M
  static bool classof(const Type *T) {
3541
62.2M
    return T->getTypeClass() == FunctionNoProto;
3542
62.2M
  }
3543
};
3544
3545
/// Represents a prototype with parameter type info, e.g.
3546
/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
3547
/// parameters, not as having a single void parameter. Such a type can have an
3548
/// exception specification, but this specification is not part of the canonical
3549
/// type.
3550
class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
3551
public:
3552
  /// Interesting information about a specific parameter that can't simply
3553
  /// be reflected in parameter's type.
3554
  ///
3555
  /// It makes sense to model language features this way when there's some
3556
  /// sort of parameter-specific override (such as an attribute) that
3557
  /// affects how the function is called.  For example, the ARC ns_consumed
3558
  /// attribute changes whether a parameter is passed at +0 (the default)
3559
  /// or +1 (ns_consumed).  This must be reflected in the function type,
3560
  /// but isn't really a change to the parameter type.
3561
  ///
3562
  /// One serious disadvantage of modelling language features this way is
3563
  /// that they generally do not work with language features that attempt
3564
  /// to destructure types.  For example, template argument deduction will
3565
  /// not be able to match a parameter declared as
3566
  ///   T (*)(U)
3567
  /// against an argument of type
3568
  ///   void (*)(__attribute__((ns_consumed)) id)
3569
  /// because the substitution of T=void, U=id into the former will
3570
  /// not produce the latter.
3571
  class ExtParameterInfo {
3572
    enum {
3573
      ABIMask         = 0x0F,
3574
      IsConsumed      = 0x10,
3575
      HasPassObjSize  = 0x20,
3576
      IsNoEscape      = 0x40,
3577
    };
3578
    unsigned char Data = 0;
3579
3580
  public:
3581
18.2M
    ExtParameterInfo() = default;
3582
3583
    /// Return the ABI treatment of this parameter.
3584
4.56M
    ParameterABI getABI() const {
3585
4.56M
      return ParameterABI(Data & ABIMask);
3586
4.56M
    }
3587
160
    ExtParameterInfo withABI(ParameterABI kind) const {
3588
160
      ExtParameterInfo copy = *this;
3589
160
      copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
3590
160
      return copy;
3591
160
    }
3592
3593
    /// Is this parameter considered "consumed" by Objective-C ARC?
3594
    /// Consumed parameters must have retainable object type.
3595
12.7k
    bool isConsumed() const {
3596
12.7k
      return (Data & IsConsumed);
3597
12.7k
    }
3598
78
    ExtParameterInfo withIsConsumed(bool consumed) const {
3599
78
      ExtParameterInfo copy = *this;
3600
78
      if (consumed) {
3601
78
        copy.Data |= IsConsumed;
3602
78
      } else {
3603
0
        copy.Data &= ~IsConsumed;
3604
0
      }
3605
78
      return copy;
3606
78
    }
3607
3608
3.46k
    bool hasPassObjectSize() const {
3609
3.46k
      return Data & HasPassObjSize;
3610
3.46k
    }
3611
106
    ExtParameterInfo withHasPassObjectSize() const {
3612
106
      ExtParameterInfo Copy = *this;
3613
106
      Copy.Data |= HasPassObjSize;
3614
106
      return Copy;
3615
106
    }
3616
3617
7.95M
    bool isNoEscape() const {
3618
7.95M
      return Data & IsNoEscape;
3619
7.95M
    }
3620
3621
2.64k
    ExtParameterInfo withIsNoEscape(bool NoEscape) const {
3622
2.64k
      ExtParameterInfo Copy = *this;
3623
2.64k
      if (NoEscape)
3624
739
        Copy.Data |= IsNoEscape;
3625
1.90k
      else
3626
1.90k
        Copy.Data &= ~IsNoEscape;
3627
2.64k
      return Copy;
3628
2.64k
    }
3629
3630
36.9k
    unsigned char getOpaqueValue() const { return Data; }
3631
2
    static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
3632
2
      ExtParameterInfo result;
3633
2
      result.Data = data;
3634
2
      return result;
3635
2
    }
3636
3637
80
    friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs) {
3638
80
      return lhs.Data == rhs.Data;
3639
80
    }
3640
192
    friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs) {
3641
192
      return lhs.Data != rhs.Data;
3642
192
    }
3643
  };
3644
3645
0
  struct ExceptionSpecInfo {
3646
    /// The kind of exception specification this is.
3647
    ExceptionSpecificationType Type = EST_None;
3648
3649
    /// Explicitly-specified list of exception types.
3650
    ArrayRef<QualType> Exceptions;
3651
3652
    /// Noexcept expression, if this is a computed noexcept specification.
3653
    Expr *NoexceptExpr = nullptr;
3654
3655
    /// The function whose exception specification this is, for
3656
    /// EST_Unevaluated and EST_Uninstantiated.
3657
    FunctionDecl *SourceDecl = nullptr;
3658
3659
    /// The function template whose exception specification this is instantiated
3660
    /// from, for EST_Uninstantiated.
3661
    FunctionDecl *SourceTemplate = nullptr;
3662
3663
47.8M
    ExceptionSpecInfo() = default;
3664
3665
8.46k
    ExceptionSpecInfo(ExceptionSpecificationType EST) : Type(EST) {}
3666
  };
3667
3668
  /// Extra information about a function prototype.
3669
  struct ExtProtoInfo {
3670
    FunctionType::ExtInfo ExtInfo;
3671
    bool Variadic : 1;
3672
    bool HasTrailingReturn : 1;
3673
    unsigned char TypeQuals = 0;
3674
    RefQualifierKind RefQualifier = RQ_None;
3675
    ExceptionSpecInfo ExceptionSpec;
3676
    const ExtParameterInfo *ExtParameterInfos = nullptr;
3677
3678
    ExtProtoInfo()
3679
46.0M
        : Variadic(false), HasTrailingReturn(false) {}
3680
3681
    ExtProtoInfo(CallingConv CC)
3682
117k
        : ExtInfo(CC), Variadic(false), HasTrailingReturn(false) {}
3683
3684
673k
    ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &O) {
3685
673k
      ExtProtoInfo Result(*this);
3686
673k
      Result.ExceptionSpec = O;
3687
673k
      return Result;
3688
673k
    }
3689
  };
3690
3691
private:
3692
  friend class ASTContext; // ASTContext creates these.
3693
3694
  /// Determine whether there are any argument types that
3695
  /// contain an unexpanded parameter pack.
3696
  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
3697
0
                                                 unsigned numArgs) {
3698
0
    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
3699
0
      if (ArgArray[Idx]->containsUnexpandedParameterPack())
3700
0
        return true;
3701
0
3702
0
    return false;
3703
0
  }
3704
3705
  FunctionProtoType(QualType result, ArrayRef<QualType> params,
3706
                    QualType canonical, const ExtProtoInfo &epi);
3707
3708
  /// The number of parameters this function has, not counting '...'.
3709
  unsigned NumParams : 15;
3710
3711
  /// The number of types in the exception spec, if any.
3712
  unsigned NumExceptions : 9;
3713
3714
  /// The type of exception specification this function has.
3715
  unsigned ExceptionSpecType : 4;
3716
3717
  /// Whether this function has extended parameter information.
3718
  unsigned HasExtParameterInfos : 1;
3719
3720
  /// Whether the function is variadic.
3721
  unsigned Variadic : 1;
3722
3723
  /// Whether this function has a trailing return type.
3724
  unsigned HasTrailingReturn : 1;
3725
3726
  // ParamInfo - There is an variable size array after the class in memory that
3727
  // holds the parameter types.
3728
3729
  // Exceptions - There is another variable size array after ArgInfo that
3730
  // holds the exception types.
3731
3732
  // NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing
3733
  // to the expression in the noexcept() specifier.
3734
3735
  // ExceptionSpecDecl, ExceptionSpecTemplate - Instead of Exceptions, there may
3736
  // be a pair of FunctionDecl* pointing to the function which should be used to
3737
  // instantiate this function type's exception specification, and the function
3738
  // from which it should be instantiated.
3739
3740
  // ExtParameterInfos - A variable size array, following the exception
3741
  // specification and of length NumParams, holding an ExtParameterInfo
3742
  // for each of the parameters.  This only appears if HasExtParameterInfos
3743
  // is true.
3744
3745
8.25k
  const ExtParameterInfo *getExtParameterInfosBuffer() const {
3746
8.25k
    assert(hasExtParameterInfos());
3747
8.25k
3748
8.25k
    // Find the end of the exception specification.
3749
8.25k
    const auto *ptr = reinterpret_cast<const char *>(exception_begin());
3750
8.25k
    ptr += getExceptionSpecSize();
3751
8.25k
3752
8.25k
    return reinterpret_cast<const ExtParameterInfo *>(ptr);
3753
8.25k
  }
3754
3755
  static size_t getExceptionSpecSize(ExceptionSpecificationType EST,
3756
7.55M
                                     unsigned NumExceptions) {
3757
7.55M
    switch (EST) {
3758
7.55M
    case EST_None:
3759
6.76M
    case EST_DynamicNone:
3760
6.76M
    case EST_MSAny:
3761
6.76M
    case EST_BasicNoexcept:
3762
6.76M
    case EST_Unparsed:
3763
6.76M
      return 0;
3764
6.76M
3765
6.76M
    case EST_Dynamic:
3766
783
      return NumExceptions * sizeof(QualType);
3767
6.76M
3768
6.76M
    case EST_DependentNoexcept:
3769
118k
    case EST_NoexceptFalse:
3770
118k
    case EST_NoexceptTrue:
3771
118k
      return sizeof(Expr *);
3772
118k
3773
118k
    case EST_Uninstantiated:
3774
41.0k
      return 2 * sizeof(FunctionDecl *);
3775
118k
3776
632k
    case EST_Unevaluated:
3777
632k
      return sizeof(FunctionDecl *);
3778
0
    }
3779
0
    llvm_unreachable("bad exception specification kind");
3780
0
  }
3781
8.25k
  size_t getExceptionSpecSize() const {
3782
8.25k
    return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
3783
8.25k
  }
3784
3785
public:
3786
149M
  unsigned getNumParams() const { return NumParams; }
3787
3788
13.3M
  QualType getParamType(unsigned i) const {
3789
13.3M
    assert(i < NumParams && "invalid parameter index");
3790
13.3M
    return param_type_begin()[i];
3791
13.3M
  }
3792
3793
1.34M
  ArrayRef<QualType> getParamTypes() const {
3794
1.34M
    return llvm::makeArrayRef(param_type_begin(), param_type_end());
3795
1.34M
  }
3796
3797
37.9M
  ExtProtoInfo getExtProtoInfo() const {
3798
37.9M
    ExtProtoInfo EPI;
3799
37.9M
    EPI.ExtInfo = getExtInfo();
3800
37.9M
    EPI.Variadic = isVariadic();
3801
37.9M
    EPI.HasTrailingReturn = hasTrailingReturn();
3802
37.9M
    EPI.ExceptionSpec.Type = getExceptionSpecType();
3803
37.9M
    EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
3804
37.9M
    EPI.RefQualifier = getRefQualifier();
3805
37.9M
    if (EPI.ExceptionSpec.Type == EST_Dynamic) {
3806
2.86k
      EPI.ExceptionSpec.Exceptions = exceptions();
3807
37.9M
    } else if (isComputedNoexcept(EPI.ExceptionSpec.Type)) {
3808
724k
      EPI.ExceptionSpec.NoexceptExpr = getNoexceptExpr();
3809
37.2M
    } else if (EPI.ExceptionSpec.Type == EST_Uninstantiated) {
3810
78.3k
      EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl();
3811
78.3k
      EPI.ExceptionSpec.SourceTemplate = getExceptionSpecTemplate();
3812
37.1M
    } else if (EPI.ExceptionSpec.Type == EST_Unevaluated) {
3813
1.79M
      EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl();
3814
1.79M
    }
3815
37.9M
    if (hasExtParameterInfos())
3816
4.10k
      EPI.ExtParameterInfos = getExtParameterInfosBuffer();
3817
37.9M
    return EPI;
3818
37.9M
  }
3819
3820
  /// Get the kind of exception specification on this function.
3821
144M
  ExceptionSpecificationType getExceptionSpecType() const {
3822
144M
    return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
3823
144M
  }
3824
3825
  /// Return whether this function has any kind of exception spec.
3826
37.8M
  bool hasExceptionSpec() const {
3827
37.8M
    return getExceptionSpecType() != EST_None;
3828
37.8M
  }
3829
3830
  /// Return whether this function has a dynamic (throw) exception spec.
3831
18.4k
  bool hasDynamicExceptionSpec() const {
3832
18.4k
    return isDynamicExceptionSpec(getExceptionSpecType());
3833
18.4k
  }
3834
3835
  /// Return whether this function has a noexcept exception spec.
3836
0
  bool hasNoexceptExceptionSpec() const {
3837
0
    return isNoexceptExceptionSpec(getExceptionSpecType());
3838
0
  }
3839
3840
  /// Return whether this function has a dependent exception spec.
3841
  bool hasDependentExceptionSpec() const;
3842
3843
  /// Return whether this function has an instantiation-dependent exception
3844
  /// spec.
3845
  bool hasInstantiationDependentExceptionSpec() const;
3846
3847
8.54k
  unsigned getNumExceptions() const { return NumExceptions; }
3848
1.19k
  QualType getExceptionType(unsigned i) const {
3849
1.19k
    assert(i < NumExceptions && "Invalid exception number!");
3850
1.19k
    return exception_begin()[i];
3851
1.19k
  }
3852
924k
  Expr *getNoexceptExpr() const {
3853
924k
    if (!isComputedNoexcept(getExceptionSpecType()))
3854
189k
      return nullptr;
3855
734k
    // NoexceptExpr sits where the arguments end.
3856
734k
    return *reinterpret_cast<Expr *const *>(param_type_end());
3857
734k
  }
3858
3859
  /// If this function type has an exception specification which hasn't
3860
  /// been determined yet (either because it has not been evaluated or because
3861
  /// it has not been instantiated), this is the function whose exception
3862
  /// specification is represented by this type.
3863
2.11M
  FunctionDecl *getExceptionSpecDecl() const {
3864
2.11M
    if (getExceptionSpecType() != EST_Uninstantiated &&
3865
2.11M
        
getExceptionSpecType() != EST_Unevaluated2.02M
)
3866
0
      return nullptr;
3867
2.11M
    return reinterpret_cast<FunctionDecl *const *>(param_type_end())[0];
3868
2.11M
  }
3869
3870
  /// If this function type has an uninstantiated exception
3871
  /// specification, this is the function whose exception specification
3872
  /// should be instantiated to find the exception specification for
3873
  /// this type.
3874
85.5k
  FunctionDecl *getExceptionSpecTemplate() const {
3875
85.5k
    if (getExceptionSpecType() != EST_Uninstantiated)
3876
0
      return nullptr;
3877
85.5k
    return reinterpret_cast<FunctionDecl *const *>(param_type_end())[1];
3878
85.5k
  }
3879
3880
  /// Determine whether this function type has a non-throwing exception
3881
  /// specification.
3882
  CanThrowResult canThrow() const;
3883
3884
  /// Determine whether this function type has a non-throwing exception
3885
  /// specification. If this depends on template arguments, returns
3886
  /// \c ResultIfDependent.
3887
2.31M
  bool isNothrow(bool ResultIfDependent = false) const {
3888
2.31M
    return ResultIfDependent ? 
canThrow() != CT_Can5.31k
3889
2.31M
                             : 
canThrow() == CT_Cannot2.30M
;
3890
2.31M
  }
3891
3892
69.5M
  bool isVariadic() const { return Variadic; }
3893
3894
  /// Determines whether this function prototype contains a
3895
  /// parameter pack at the end.
3896
  ///
3897
  /// A function template whose last parameter is a parameter pack can be
3898
  /// called with an arbitrary number of arguments, much like a variadic
3899
  /// function.
3900
  bool isTemplateVariadic() const;
3901
3902
44.6M
  bool hasTrailingReturn() const { return HasTrailingReturn; }
3903
3904
50.3M
  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
3905
3906
  /// Retrieve the ref-qualifier associated with this function type.
3907
46.9M
  RefQualifierKind getRefQualifier() const {
3908
46.9M
    return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
3909
46.9M
  }
3910
3911
  using param_type_iterator = const QualType *;
3912
  using param_type_range = llvm::iterator_range<param_type_iterator>;
3913
3914
6.75M
  param_type_range param_types() const {
3915
6.75M
    return param_type_range(param_type_begin(), param_type_end());
3916
6.75M
  }
3917
3918
98.9M
  param_type_iterator param_type_begin() const {
3919
98.9M
    return reinterpret_cast<const QualType *>(this+1);
3920
98.9M
  }
3921
3922
22.1M
  param_type_iterator param_type_end() const {
3923
22.1M
    return param_type_begin() + NumParams;
3924
22.1M
  }
3925
3926
  using exception_iterator = const QualType *;
3927
3928
128k
  ArrayRef<QualType> exceptions() const {
3929
128k
    return llvm::makeArrayRef(exception_begin(), exception_end());
3930
128k
  }
3931
3932
266k
  exception_iterator exception_begin() const {
3933
266k
    // exceptions begin where arguments end
3934
266k
    return param_type_end();
3935
266k
  }
3936
3937
128k
  exception_iterator exception_end() const {
3938
128k
    if (getExceptionSpecType() != EST_Dynamic)
3939
124k
      return exception_begin();
3940
3.81k
    return exception_begin() + NumExceptions;
3941
3.81k
  }
3942
3943
  /// Is there any interesting extra information for any of the parameters
3944
  /// of this function type?
3945
49.5M
  bool hasExtParameterInfos() const { return HasExtParameterInfos; }
3946
1.80k
  ArrayRef<ExtParameterInfo> getExtParameterInfos() const {
3947
1.80k
    assert(hasExtParameterInfos());
3948
1.80k
    return ArrayRef<ExtParameterInfo>(getExtParameterInfosBuffer(),
3949
1.80k
                                      getNumParams());
3950
1.80k
  }
3951
3952
  /// Return a pointer to the beginning of the array of extra parameter
3953
  /// information, if present, or else null if none of the parameters
3954
  /// carry it.  This is equivalent to getExtProtoInfo().ExtParameterInfos.
3955
1.75M
  const ExtParameterInfo *getExtParameterInfosOrNull() const {
3956
1.75M
    if (!hasExtParameterInfos())
3957
1.75M
      return nullptr;
3958
83
    return getExtParameterInfosBuffer();
3959
83
  }
3960
3961
5.60M
  ExtParameterInfo getExtParameterInfo(unsigned I) const {
3962
5.60M
    assert(I < getNumParams() && "parameter index out of range");
3963
5.60M
    if (hasExtParameterInfos())
3964
864
      return getExtParameterInfosBuffer()[I];
3965
5.59M
    return ExtParameterInfo();
3966
5.59M
  }
3967
3968
0
  ParameterABI getParameterABI(unsigned I) const {
3969
0
    assert(I < getNumParams() && "parameter index out of range");
3970
0
    if (hasExtParameterInfos())
3971
0
      return getExtParameterInfosBuffer()[I].getABI();
3972
0
    return ParameterABI::Ordinary;
3973
0
  }
3974
3975
18.5k
  bool isParamConsumed(unsigned I) const {
3976
18.5k
    assert(I < getNumParams() && "parameter index out of range");
3977
18.5k
    if (hasExtParameterInfos())
3978
14
      return getExtParameterInfosBuffer()[I].isConsumed();
3979
18.5k
    return false;
3980
18.5k
  }
3981
3982
2.45M
  bool isSugared() const { return false; }
3983
27
  QualType desugar() const { return QualType(this, 0); }
3984
3985
  void printExceptionSpecification(raw_ostream &OS,
3986
                                   const PrintingPolicy &Policy) const;
3987
3988
340M
  static bool classof(const Type *T) {
3989
340M
    return T->getTypeClass() == FunctionProto;
3990
340M
  }
3991
3992
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
3993
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
3994
                      param_type_iterator ArgTys, unsigned NumArgs,
3995
                      const ExtProtoInfo &EPI, const ASTContext &Context,
3996
                      bool Canonical);
3997
};
3998
3999
/// Represents the dependent type named by a dependently-scoped
4000
/// typename using declaration, e.g.
4001
///   using typename Base<T>::foo;
4002
///
4003
/// Template instantiation turns these into the underlying type.
4004
class UnresolvedUsingType : public Type {
4005
  friend class ASTContext; // ASTContext creates these.
4006
4007
  UnresolvedUsingTypenameDecl *Decl;
4008
4009
  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
4010
      : Type(UnresolvedUsing, QualType(), true, true, false,
4011
             /*ContainsUnexpandedParameterPack=*/false),
4012
47
        Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
4013
4014
public:
4015
59
  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
4016
4017
100
  bool isSugared() const { return false; }
4018
0
  QualType desugar() const { return QualType(this, 0); }
4019
4020
302
  static bool classof(const Type *T) {
4021
302
    return T->getTypeClass() == UnresolvedUsing;
4022
302
  }
4023
4024
  void Profile(llvm::FoldingSetNodeID &ID) {
4025
    return Profile(ID, Decl);
4026
  }
4027
4028
  static void Profile(llvm::FoldingSetNodeID &ID,
4029
                      UnresolvedUsingTypenameDecl *D) {
4030
    ID.AddPointer(D);
4031
  }
4032
};
4033
4034
class TypedefType : public Type {
4035
  TypedefNameDecl *Decl;
4036
4037
protected:
4038
  friend class ASTContext; // ASTContext creates these.
4039
4040
  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
4041
      : Type(tc, can, can->isDependentType(),
4042
             can->isInstantiationDependentType(),
4043
             can->isVariablyModifiedType(),
4044
             /*ContainsUnexpandedParameterPack=*/false),
4045
1.41M
        Decl(const_cast<TypedefNameDecl*>(D)) {
4046
1.41M
    assert(!isa<TypedefType>(can) && "Invalid canonical type");
4047
1.41M
  }
4048
4049
public:
4050
43.8M
  TypedefNameDecl *getDecl() const { return Decl; }
4051
4052
31.1M
  bool isSugared() const { return true; }
4053
  QualType desugar() const;
4054
4055
18.5M
  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
4056
};
4057
4058
/// Represents a `typeof` (or __typeof__) expression (a GCC extension).
4059
class TypeOfExprType : public Type {
4060
  Expr *TOExpr;
4061
4062
protected:
4063
  friend class ASTContext; // ASTContext creates these.
4064
4065
  TypeOfExprType(Expr *E, QualType can = QualType());
4066
4067
public:
4068
10.6k
  Expr *getUnderlyingExpr() const { return TOExpr; }
4069
4070
  /// Remove a single level of sugar.
4071
  QualType desugar() const;
4072
4073
  /// Returns whether this type directly provides sugar.
4074
  bool isSugared() const;
4075
4076
115k
  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
4077
};
4078
4079
/// Internal representation of canonical, dependent
4080
/// `typeof(expr)` types.
4081
///
4082
/// This class is used internally by the ASTContext to manage
4083
/// canonical, dependent types, only. Clients will only see instances
4084
/// of this class via TypeOfExprType nodes.
4085
class DependentTypeOfExprType
4086
  : public TypeOfExprType, public llvm::FoldingSetNode {
4087
  const ASTContext &Context;
4088
4089
public:
4090
  DependentTypeOfExprType(const ASTContext &Context, Expr *E)
4091
114
      : TypeOfExprType(E), Context(Context) {}
4092
4093
530
  void Profile(llvm::FoldingSetNodeID &ID) {
4094
530
    Profile(ID, Context, getUnderlyingExpr());
4095
530
  }
4096
4097
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4098
                      Expr *E);
4099
};
4100
4101
/// Represents `typeof(type)`, a GCC extension.
4102
class TypeOfType : public Type {
4103
  friend class ASTContext; // ASTContext creates these.
4104
4105
  QualType TOType;
4106
4107
  TypeOfType(QualType T, QualType can)
4108
      : Type(TypeOf, can, T->isDependentType(),
4109
             T->isInstantiationDependentType(),
4110
             T->isVariablyModifiedType(),
4111
             T->containsUnexpandedParameterPack()),
4112
96
        TOType(T) {
4113
96
    assert(!isa<TypedefType>(can) && "Invalid canonical type");
4114
96
  }
4115
4116
public:
4117
509
  QualType getUnderlyingType() const { return TOType; }
4118
4119
  /// Remove a single level of sugar.
4120
464
  QualType desugar() const { return getUnderlyingType(); }
4121
4122
  /// Returns whether this type directly provides sugar.
4123
451
  bool isSugared() const { return true; }
4124
4125
47
  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
4126
};
4127
4128
/// Represents the type `decltype(expr)` (C++11).
4129
class DecltypeType : public Type {
4130
  Expr *E;
4131
  QualType UnderlyingType;
4132
4133
protected:
4134
  friend class ASTContext; // ASTContext creates these.
4135
4136
  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
4137
4138
public:
4139
209k
  Expr *getUnderlyingExpr() const { return E; }
4140
130k
  QualType getUnderlyingType() const { return UnderlyingType; }
4141
4142
  /// Remove a single level of sugar.
4143
  QualType desugar() const;
4144
4145
  /// Returns whether this type directly provides sugar.
4146
  bool isSugared() const;
4147
4148
1.77M
  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
4149
};
4150
4151
/// Internal representation of canonical, dependent
4152
/// decltype(expr) types.
4153
///
4154
/// This class is used internally by the ASTContext to manage
4155
/// canonical, dependent types, only. Clients will only see instances
4156
/// of this class via DecltypeType nodes.
4157
class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
4158
  const ASTContext &Context;
4159
4160
public:
4161
  DependentDecltypeType(const ASTContext &Context, Expr *E);
4162
4163
19.3k
  void Profile(llvm::FoldingSetNodeID &ID) {
4164
19.3k
    Profile(ID, Context, getUnderlyingExpr());
4165
19.3k
  }
4166
4167
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4168
                      Expr *E);
4169
};
4170
4171
/// A unary type transform, which is a type constructed from another.
4172
class UnaryTransformType : public Type {
4173
public:
4174
  enum UTTKind {
4175
    EnumUnderlyingType
4176
  };
4177
4178
private:
4179
  /// The untransformed type.
4180
  QualType BaseType;
4181
4182
  /// The transformed type if not dependent, otherwise the same as BaseType.
4183
  QualType UnderlyingType;
4184
4185
  UTTKind UKind;
4186
4187
protected:
4188
  friend class ASTContext;
4189
4190
  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
4191
                     QualType CanonicalTy);
4192
4193
public:
4194
158
  bool isSugared() const { return !isDependentType(); }
4195
153
  QualType desugar() const { return UnderlyingType; }
4196
4197
34
  QualType getUnderlyingType() const { return UnderlyingType; }
4198
50
  QualType getBaseType() const { return BaseType; }
4199
4200
41
  UTTKind getUTTKind() const { return UKind; }
4201
4202
0
  static bool classof(const Type *T) {
4203
0
    return T->getTypeClass() == UnaryTransform;
4204
0
  }
4205
};
4206
4207
/// Internal representation of canonical, dependent
4208
/// __underlying_type(type) types.
4209
///
4210
/// This class is used internally by the ASTContext to manage
4211
/// canonical, dependent types, only. Clients will only see instances
4212
/// of this class via UnaryTransformType nodes.
4213
class DependentUnaryTransformType : public UnaryTransformType,
4214
                                    public llvm::FoldingSetNode {
4215
public:
4216
  DependentUnaryTransformType(const ASTContext &C, QualType BaseType,
4217
                              UTTKind UKind);
4218
4219
6
  void Profile(llvm::FoldingSetNodeID &ID) {
4220
6
    Profile(ID, getBaseType(), getUTTKind());
4221
6
  }
4222
4223
  static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
4224
645
                      UTTKind UKind) {
4225
645
    ID.AddPointer(BaseType.getAsOpaquePtr());
4226
645
    ID.AddInteger((unsigned)UKind);
4227
645
  }
4228
};
4229
4230
class TagType : public Type {
4231
  friend class ASTReader;
4232
4233
  /// Stores the TagDecl associated with this type. The decl may point to any
4234
  /// TagDecl that declares the entity.
4235
  TagDecl *decl;
4236
4237
protected:
4238
  TagType(TypeClass TC, const TagDecl *D, QualType can);
4239
4240
public:
4241
  TagDecl *getDecl() const;
4242
4243
  /// Determines whether this type is in the process of being defined.
4244
  bool isBeingDefined() const;
4245
4246
188M
  static bool classof(const Type *T) {
4247
188M
    return T->getTypeClass() >= TagFirst && 
T->getTypeClass() <= TagLast56.2M
;
4248
188M
  }
4249
};
4250
4251
/// A helper class that allows the use of isa/cast/dyncast
4252
/// to detect TagType objects of structs/unions/classes.
4253
class RecordType : public TagType {
4254
protected:
4255
  friend class ASTContext; // ASTContext creates these.
4256
4257
  explicit RecordType(const RecordDecl *D)
4258
2.08M
      : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4259
  explicit RecordType(TypeClass TC, RecordDecl *D)
4260
      : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4261
4262
public:
4263
63.0M
  RecordDecl *getDecl() const {
4264
63.0M
    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
4265
63.0M
  }
4266
4267
  /// Recursively check all fields in the record for const-ness. If any field
4268
  /// is declared const, return true. Otherwise, return false.
4269
  bool hasConstFields() const;
4270
4271
21.6M
  bool isSugared() const { return false; }
4272
0
  QualType desugar() const { return QualType(this, 0); }
4273
4274
238M
  static bool classof(const Type *T) { return T->getTypeClass() == Record; }
4275
};
4276
4277
/// A helper class that allows the use of isa/cast/dyncast
4278
/// to detect TagType objects of enums.
4279
class EnumType : public TagType {
4280
  friend class ASTContext; // ASTContext creates these.
4281
4282
  explicit EnumType(const EnumDecl *D)
4283
53.1k
      : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4284
4285
public:
4286
133M
  EnumDecl *getDecl() const {
4287
133M
    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
4288
133M
  }
4289
4290
4.04M
  bool isSugared() const { return false; }
4291
0
  QualType desugar() const { return QualType(this, 0); }
4292
4293
174M
  static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
4294
};
4295
4296
/// An attributed type is a type to which a type attribute has been applied.
4297
///
4298
/// The "modified type" is the fully-sugared type to which the attributed
4299
/// type was applied; generally it is not canonically equivalent to the
4300
/// attributed type. The "equivalent type" is the minimally-desugared type
4301
/// which the type is canonically equivalent to.
4302
///
4303
/// For example, in the following attributed type:
4304
///     int32_t __attribute__((vector_size(16)))
4305
///   - the modified type is the TypedefType for int32_t
4306
///   - the equivalent type is VectorType(16, int32_t)
4307
///   - the canonical type is VectorType(16, int)
4308
class AttributedType : public Type, public llvm::FoldingSetNode {
4309
public:
4310
  using Kind = attr::Kind;
4311
4312
private:
4313
  friend class ASTContext; // ASTContext creates these
4314
4315
  QualType ModifiedType;
4316
  QualType EquivalentType;
4317
4318
  AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
4319
                 QualType equivalent)
4320
      : Type(Attributed, canon, equivalent->isDependentType(),
4321
             equivalent->isInstantiationDependentType(),
4322
             equivalent->isVariablyModifiedType(),
4323
             equivalent->containsUnexpandedParameterPack()),
4324
63.8k
        ModifiedType(modified), EquivalentType(equivalent) {
4325
63.8k
    AttributedTypeBits.AttrKind = attrKind;
4326
63.8k
  }
4327
4328
public:
4329
411k
  Kind getAttrKind() const {
4330
411k
    return static_cast<Kind>(AttributedTypeBits.AttrKind);
4331
411k
  }
4332
4333
1.22M
  QualType getModifiedType() const { return ModifiedType; }
4334
381k
  QualType getEquivalentType() const { return EquivalentType; }
4335
4336
371k
  bool isSugared() const { return true; }
4337
372k
  QualType desugar() const { return getEquivalentType(); }
4338
4339
  /// Does this attribute behave like a type qualifier?
4340
  ///
4341
  /// A type qualifier adjusts a type to provide specialized rules for
4342
  /// a specific object, like the standard const and volatile qualifiers.
4343
  /// This includes attributes controlling things like nullability,
4344
  /// address spaces, and ARC ownership.  The value of the object is still
4345
  /// largely described by the modified type.
4346
  ///
4347
  /// In contrast, many type attributes "rewrite" their modified type to
4348
  /// produce a fundamentally different type, not necessarily related in any
4349
  /// formalizable way to the original type.  For example, calling convention
4350
  /// and vector attributes are not simple type qualifiers.
4351
  ///
4352
  /// Type qualifiers are often, but not always, reflected in the canonical
4353
  /// type.
4354
  bool isQualifier() const;
4355
4356
  bool isMSTypeSpec() const;
4357
4358
  bool isCallingConv() const;
4359
4360
  llvm::Optional<NullabilityKind> getImmediateNullability() const;
4361
4362
  /// Retrieve the attribute kind corresponding to the given
4363
  /// nullability kind.
4364
1.69k
  static Kind getNullabilityAttrKind(NullabilityKind kind) {
4365
1.69k
    switch (kind) {
4366
1.69k
    case NullabilityKind::NonNull:
4367
1.06k
      return attr::TypeNonNull;
4368
1.69k
4369
1.69k
    case NullabilityKind::Nullable:
4370
618
      return attr::TypeNullable;
4371
1.69k
4372
1.69k
    case NullabilityKind::Unspecified:
4373
7
      return attr::TypeNullUnspecified;
4374
0
    }
4375
0
    llvm_unreachable("Unknown nullability kind.");
4376
0
  }
4377
4378
  /// Strip off the top-level nullability annotation on the given
4379
  /// type, if it's there.
4380
  ///
4381
  /// \param T The type to strip. If the type is exactly an
4382
  /// AttributedType specifying nullability (without looking through
4383
  /// type sugar), the nullability is returned and this type changed
4384
  /// to the underlying modified type.
4385
  ///
4386
  /// \returns the top-level nullability, if present.
4387
  static Optional<NullabilityKind> stripOuterNullability(QualType &T);
4388
4389
306k
  void Profile(llvm::FoldingSetNodeID &ID) {
4390
306k
    Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
4391
306k
  }
4392
4393
  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
4394
570k
                      QualType modified, QualType equivalent) {
4395
570k
    ID.AddInteger(attrKind);
4396
570k
    ID.AddPointer(modified.getAsOpaquePtr());
4397
570k
    ID.AddPointer(equivalent.getAsOpaquePtr());
4398
570k
  }
4399
4400
71.9M
  static bool classof(const Type *T) {
4401
71.9M
    return T->getTypeClass() == Attributed;
4402
71.9M
  }
4403
};
4404
4405
class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
4406
  friend class ASTContext; // ASTContext creates these
4407
4408
  // Helper data collector for canonical types.
4409
  struct CanonicalTTPTInfo {
4410
    unsigned Depth : 15;
4411
    unsigned ParameterPack : 1;
4412
    unsigned Index : 16;
4413
  };
4414
4415
  union {
4416
    // Info for the canonical type.
4417
    CanonicalTTPTInfo CanTTPTInfo;
4418
4419
    // Info for the non-canonical type.
4420
    TemplateTypeParmDecl *TTPDecl;
4421
  };
4422
4423
  /// Build a non-canonical type.
4424
  TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon)
4425
      : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
4426
             /*InstantiationDependent=*/true,
4427
             /*VariablyModified=*/false,
4428
             Canon->containsUnexpandedParameterPack()),
4429
2.35M
        TTPDecl(TTPDecl) {}
4430
4431
  /// Build the canonical type.
4432
  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
4433
      : Type(TemplateTypeParm, QualType(this, 0),
4434
             /*Dependent=*/true,
4435
             /*InstantiationDependent=*/true,
4436
30.9k
             /*VariablyModified=*/false, PP) {
4437
30.9k
    CanTTPTInfo.Depth = D;
4438
30.9k
    CanTTPTInfo.Index = I;
4439
30.9k
    CanTTPTInfo.ParameterPack = PP;
4440
30.9k
  }
4441
4442
110M
  const CanonicalTTPTInfo& getCanTTPTInfo() const {
4443
110M
    QualType Can = getCanonicalTypeInternal();
4444
110M
    return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
4445
110M
  }
4446
4447
public:
4448
36.0M
  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
4449
29.0M
  unsigned getIndex() const { return getCanTTPTInfo().Index; }
4450
45.7M
  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
4451
4452
14.9M
  TemplateTypeParmDecl *getDecl() const {
4453
14.9M
    return isCanonicalUnqualified() ? 
nullptr2.45M
:
TTPDecl12.4M
;
4454
14.9M
  }
4455
4456
  IdentifierInfo *getIdentifier() const;
4457
4458
1.22M
  bool isSugared() const { return false; }
4459
0
  QualType desugar() const { return QualType(this, 0); }
4460
4461
14.2M
  void Profile(llvm::FoldingSetNodeID &ID) {
4462
14.2M
    Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
4463
14.2M
  }
4464
4465
  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
4466
                      unsigned Index, bool ParameterPack,
4467
19.4M
                      TemplateTypeParmDecl *TTPDecl) {
4468
19.4M
    ID.AddInteger(Depth);
4469
19.4M
    ID.AddInteger(Index);
4470
19.4M
    ID.AddBoolean(ParameterPack);
4471
19.4M
    ID.AddPointer(TTPDecl);
4472
19.4M
  }
4473
4474
33.7M
  static bool classof(const Type *T) {
4475
33.7M
    return T->getTypeClass() == TemplateTypeParm;
4476
33.7M
  }
4477
};
4478
4479
/// Represents the result of substituting a type for a template
4480
/// type parameter.
4481
///
4482
/// Within an instantiated template, all template type parameters have
4483
/// been replaced with these.  They are used solely to record that a
4484
/// type was originally written as a template type parameter;
4485
/// therefore they are never canonical.
4486
class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
4487
  friend class ASTContext;
4488
4489
  // The original type parameter.
4490
  const TemplateTypeParmType *Replaced;
4491
4492
  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
4493
      : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
4494
             Canon->isInstantiationDependentType(),
4495
             Canon->isVariablyModifiedType(),
4496
             Canon->containsUnexpandedParameterPack()),
4497
1.51M
        Replaced(Param) {}
4498
4499
public:
4500
  /// Gets the template parameter that was substituted for.
4501
7.37M
  const TemplateTypeParmType *getReplacedParameter() const {
4502
7.37M
    return Replaced;
4503
7.37M
  }
4504
4505
  /// Gets the type that was substituted for the template
4506
  /// parameter.
4507
11.5M
  QualType getReplacementType() const {
4508
11.5M
    return getCanonicalTypeInternal();
4509
11.5M
  }
4510
4511
3.70M
  bool isSugared() const { return true; }
4512
3.71M
  QualType desugar() const { return getReplacementType(); }
4513
4514
7.37M
  void Profile(llvm::FoldingSetNodeID &ID) {
4515
7.37M
    Profile(ID, getReplacedParameter(), getReplacementType());
4516
7.37M
  }
4517
4518
  static void Profile(llvm::FoldingSetNodeID &ID,
4519
                      const TemplateTypeParmType *Replaced,
4520
11.7M
                      QualType Replacement) {
4521
11.7M
    ID.AddPointer(Replaced);
4522
11.7M
    ID.AddPointer(Replacement.getAsOpaquePtr());
4523
11.7M
  }
4524
4525
1.41M
  static bool classof(const Type *T) {
4526
1.41M
    return T->getTypeClass() == SubstTemplateTypeParm;
4527
1.41M
  }
4528
};
4529
4530
/// Represents the result of substituting a set of types for a template
4531
/// type parameter pack.
4532
///
4533
/// When a pack expansion in the source code contains multiple parameter packs
4534
/// and those parameter packs correspond to different levels of template
4535
/// parameter lists, this type node is used to represent a template type
4536
/// parameter pack from an outer level, which has already had its argument pack
4537
/// substituted but that still lives within a pack expansion that itself
4538
/// could not be instantiated. When actually performing a substitution into
4539
/// that pack expansion (e.g., when all template parameters have corresponding
4540
/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
4541
/// at the current pack substitution index.
4542
class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
4543
  friend class ASTContext;
4544
4545
  /// The original type parameter.
4546
  const TemplateTypeParmType *Replaced;
4547
4548
  /// A pointer to the set of template arguments that this
4549
  /// parameter pack is instantiated with.
4550
  const TemplateArgument *Arguments;
4551
4552
  SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
4553
                                QualType Canon,
4554
                                const TemplateArgument &ArgPack);
4555
4556
public:
4557
0
  IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
4558
4559
  /// Gets the template parameter that was substituted for.
4560
26.0k
  const TemplateTypeParmType *getReplacedParameter() const {
4561
26.0k
    return Replaced;
4562
26.0k
  }
4563
4564
45.7k
  unsigned getNumArgs() const {
4565
45.7k
    return SubstTemplateTypeParmPackTypeBits.NumArgs;
4566
45.7k
  }
4567
4568
11
  bool isSugared() const { return false; }
4569
0
  QualType desugar() const { return QualType(this, 0); }
4570
4571
  TemplateArgument getArgumentPack() const;
4572
4573
  void Profile(llvm::FoldingSetNodeID &ID);
4574
  static void Profile(llvm::FoldingSetNodeID &ID,
4575
                      const TemplateTypeParmType *Replaced,
4576
                      const TemplateArgument &ArgPack);
4577
4578
2.37M
  static bool classof(const Type *T) {
4579
2.37M
    return T->getTypeClass() == SubstTemplateTypeParmPack;
4580
2.37M
  }
4581
};
4582
4583
/// Common base class for placeholders for types that get replaced by
4584
/// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
4585
/// class template types, and (eventually) constrained type names from the C++
4586
/// Concepts TS.
4587
///
4588
/// These types are usually a placeholder for a deduced type. However, before
4589
/// the initializer is attached, or (usually) if the initializer is
4590
/// type-dependent, there is no deduced type and the type is canonical. In
4591
/// the latter case, it is also a dependent type.
4592
class DeducedType : public Type {
4593
protected:
4594
  DeducedType(TypeClass TC, QualType DeducedAsType, bool IsDependent,
4595
              bool IsInstantiationDependent, bool ContainsParameterPack)
4596
      : Type(TC,
4597
             // FIXME: Retain the sugared deduced type?
4598
             DeducedAsType.isNull() ? QualType(this, 0)
4599
                                    : DeducedAsType.getCanonicalType(),
4600
             IsDependent, IsInstantiationDependent,
4601
15.9k
             /*VariablyModified=*/false, ContainsParameterPack) {
4602
15.9k
    if (!DeducedAsType.isNull()) {
4603
11.3k
      if (DeducedAsType->isDependentType())
4604
34
        setDependent();
4605
11.3k
      if (DeducedAsType->isInstantiationDependentType())
4606
34
        setInstantiationDependent();
4607
11.3k
      if (DeducedAsType->containsUnexpandedParameterPack())
4608
0
        setContainsUnexpandedParameterPack();
4609
11.3k
    }
4610
15.9k
  }
4611
4612
public:
4613
150k
  bool isSugared() const { return !isCanonicalUnqualified(); }
4614
150k
  QualType desugar() const { return getCanonicalTypeInternal(); }
4615
4616
  /// Get the type deduced for this placeholder type, or null if it's
4617
  /// either not been deduced or was deduced to a dependent type.
4618
32.8k
  QualType getDeducedType() const {
4619
32.8k
    return !isCanonicalUnqualified() ? 
getCanonicalTypeInternal()20.7k
:
QualType()12.1k
;
4620
32.8k
  }
4621
65.9k
  bool isDeduced() const {
4622
65.9k
    return !isCanonicalUnqualified() || 
isDependentType()44.7k
;
4623
65.9k
  }
4624
4625
57.9M
  static bool classof(const Type *T) {
4626
57.9M
    return T->getTypeClass() == Auto ||
4627
57.9M
           
T->getTypeClass() == DeducedTemplateSpecialization57.8M
;
4628
57.9M
  }
4629
};
4630
4631
/// Represents a C++11 auto or C++14 decltype(auto) type.
4632
class AutoType : public DeducedType, public llvm::FoldingSetNode {
4633
  friend class ASTContext; // ASTContext creates these
4634
4635
  AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
4636
           bool IsDeducedAsDependent)
4637
      : DeducedType(Auto, DeducedAsType, IsDeducedAsDependent,
4638
15.6k
                    IsDeducedAsDependent, /*ContainsPack=*/false) {
4639
15.6k
    AutoTypeBits.Keyword = (unsigned)Keyword;
4640
15.6k
  }
4641
4642
public:
4643
46.2k
  bool isDecltypeAuto() const {
4644
46.2k
    return getKeyword() == AutoTypeKeyword::DecltypeAuto;
4645
46.2k
  }
4646
4647
145k
  AutoTypeKeyword getKeyword() const {
4648
145k
    return (AutoTypeKeyword)AutoTypeBits.Keyword;
4649
145k
  }
4650
4651
18.4k
  void Profile(llvm::FoldingSetNodeID &ID) {
4652
18.4k
    Profile(ID, getDeducedType(), getKeyword(), isDependentType());
4653
18.4k
  }
4654
4655
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Deduced,
4656
43.9k
                      AutoTypeKeyword Keyword, bool IsDependent) {
4657
43.9k
    ID.AddPointer(Deduced.getAsOpaquePtr());
4658
43.9k
    ID.AddInteger((unsigned)Keyword);
4659
43.9k
    ID.AddBoolean(IsDependent);
4660
43.9k
  }
4661
4662
4.12M
  static bool classof(const Type *T) {
4663
4.12M
    return T->getTypeClass() == Auto;
4664
4.12M
  }
4665
};
4666
4667
/// Represents a C++17 deduced template specialization type.
4668
class DeducedTemplateSpecializationType : public DeducedType,
4669
                                          public llvm::FoldingSetNode {
4670
  friend class ASTContext; // ASTContext creates these
4671
4672
  /// The name of the template whose arguments will be deduced.
4673
  TemplateName Template;
4674
4675
  DeducedTemplateSpecializationType(TemplateName Template,
4676
                                    QualType DeducedAsType,
4677
                                    bool IsDeducedAsDependent)
4678
      : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
4679
                    IsDeducedAsDependent || Template.isDependent(),
4680
                    IsDeducedAsDependent || Template.isInstantiationDependent(),
4681
                    Template.containsUnexpandedParameterPack()),
4682
289
        Template(Template) {}
4683
4684
public:
4685
  /// Retrieve the name of the template that we are deducing.
4686
1.55k
  TemplateName getTemplateName() const { return Template;}
4687
4688
939
  void Profile(llvm::FoldingSetNodeID &ID) {
4689
939
    Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
4690
939
  }
4691
4692
  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
4693
1.58k
                      QualType Deduced, bool IsDependent) {
4694
1.58k
    Template.Profile(ID);
4695
1.58k
    ID.AddPointer(Deduced.getAsOpaquePtr());
4696
1.58k
    ID.AddBoolean(IsDependent);
4697
1.58k
  }
4698
4699
50.2k
  static bool classof(const Type *T) {
4700
50.2k
    return T->getTypeClass() == DeducedTemplateSpecialization;
4701
50.2k
  }
4702
};
4703
4704
/// Represents a type template specialization; the template
4705
/// must be a class template, a type alias template, or a template
4706
/// template parameter.  A template which cannot be resolved to one of
4707
/// these, e.g. because it is written with a dependent scope
4708
/// specifier, is instead represented as a
4709
/// @c DependentTemplateSpecializationType.
4710
///
4711
/// A non-dependent template specialization type is always "sugar",
4712
/// typically for a \c RecordType.  For example, a class template
4713
/// specialization type of \c vector<int> will refer to a tag type for
4714
/// the instantiation \c std::vector<int, std::allocator<int>>
4715
///
4716
/// Template specializations are dependent if either the template or
4717
/// any of the template arguments are dependent, in which case the
4718
/// type may also be canonical.
4719
///
4720
/// Instances of this type are allocated with a trailing array of
4721
/// TemplateArguments, followed by a QualType representing the
4722
/// non-canonical aliased type when the template is a type alias
4723
/// template.
4724
class alignas(8) TemplateSpecializationType
4725
    : public Type,
4726
      public llvm::FoldingSetNode {
4727
  friend class ASTContext; // ASTContext creates these
4728
4729
  /// The name of the template being specialized.  This is
4730
  /// either a TemplateName::Template (in which case it is a
4731
  /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
4732
  /// TypeAliasTemplateDecl*), a
4733
  /// TemplateName::SubstTemplateTemplateParmPack, or a
4734
  /// TemplateName::SubstTemplateTemplateParm (in which case the
4735
  /// replacement must, recursively, be one of these).
4736
  TemplateName Template;
4737
4738
  TemplateSpecializationType(TemplateName T,
4739
                             ArrayRef<TemplateArgument> Args,
4740
                             QualType Canon,
4741
                             QualType Aliased);
4742
4743
public:
4744
  /// Determine whether any of the given template arguments are dependent.
4745
  static bool anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
4746
                                            bool &InstantiationDependent);
4747
4748
  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
4749
                                            bool &InstantiationDependent);
4750
4751
  /// True if this template specialization type matches a current
4752
  /// instantiation in the context in which it is found.
4753
1.11M
  bool isCurrentInstantiation() const {
4754
1.11M
    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
4755
1.11M
  }
4756
4757
  /// Determine if this template specialization type is for a type alias
4758
  /// template that has been substituted.
4759
  ///
4760
  /// Nearly every template specialization type whose template is an alias
4761
  /// template will be substituted. However, this is not the case when
4762
  /// the specialization contains a pack expansion but the template alias
4763
  /// does not have a corresponding parameter pack, e.g.,
4764
  ///
4765
  /// \code
4766
  /// template<typename T, typename U, typename V> struct S;
4767
  /// template<typename T, typename U> using A = S<T, int, U>;
4768
  /// template<typename... Ts> struct X {
4769
  ///   typedef A<Ts...> type; // not a type alias
4770
  /// };
4771
  /// \endcode
4772
14.6M
  bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
4773
4774
  /// Get the aliased type, if this is a specialization of a type alias
4775
  /// template.
4776
92
  QualType getAliasedType() const {
4777
92
    assert(isTypeAlias() && "not a type alias template specialization");
4778
92
    return *reinterpret_cast<const QualType*>(end());
4779
92
  }
4780
4781
  using iterator = const TemplateArgument *;
4782
4783
10.1k
  iterator begin() const { return getArgs(); }
4784
  iterator end() const; // defined inline in TemplateBase.h
4785
4786
  /// Retrieve the name of the template that we are specializing.
4787
8.78M
  TemplateName getTemplateName() const { return Template; }
4788
4789
  /// Retrieve the template arguments.
4790
16.6M
  const TemplateArgument *getArgs() const {
4791
16.6M
    return reinterpret_cast<const TemplateArgument *>(this + 1);
4792
16.6M
  }
4793
4794
  /// Retrieve the number of template arguments.
4795
24.2M
  unsigned getNumArgs() const {
4796
24.2M
    return TemplateSpecializationTypeBits.NumArgs;
4797
24.2M
  }
4798
4799
  /// Retrieve a specific template argument as a type.
4800
  /// \pre \c isArgType(Arg)
4801
  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
4802
4803
8.69M
  ArrayRef<TemplateArgument> template_arguments() const {
4804
8.69M
    return {getArgs(), getNumArgs()};
4805
8.69M
  }
4806
4807
6.80M
  bool isSugared() const {
4808
6.80M
    return !isDependentType() || 
isCurrentInstantiation()1.11M
||
isTypeAlias()1.11M
;
4809
6.80M
  }
4810
4811
5.74M
  QualType desugar() const { return getCanonicalTypeInternal(); }
4812
4813
6.19M
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
4814
6.19M
    Profile(ID, Template, template_arguments(), Ctx);
4815
6.19M
    if (isTypeAlias())
4816
0
      getAliasedType().Profile(ID);
4817
6.19M
  }
4818
4819
  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
4820
                      ArrayRef<TemplateArgument> Args,
4821
                      const ASTContext &Context);
4822
4823
7.38M
  static bool classof(const Type *T) {
4824
7.38M
    return T->getTypeClass() == TemplateSpecialization;
4825
7.38M
  }
4826
};
4827
4828
/// Print a template argument list, including the '<' and '>'
4829
/// enclosing the template arguments.
4830
void printTemplateArgumentList(raw_ostream &OS,
4831
                               ArrayRef<TemplateArgument> Args,
4832
                               const PrintingPolicy &Policy);
4833
4834
void printTemplateArgumentList(raw_ostream &OS,
4835
                               ArrayRef<TemplateArgumentLoc> Args,
4836
                               const PrintingPolicy &Policy);
4837
4838
void printTemplateArgumentList(raw_ostream &OS,
4839
                               const TemplateArgumentListInfo &Args,
4840
                               const PrintingPolicy &Policy);
4841
4842
/// The injected class name of a C++ class template or class
4843
/// template partial specialization.  Used to record that a type was
4844
/// spelled with a bare identifier rather than as a template-id; the
4845
/// equivalent for non-templated classes is just RecordType.
4846
///
4847
/// Injected class name types are always dependent.  Template
4848
/// instantiation turns these into RecordTypes.
4849
///
4850
/// Injected class name types are always canonical.  This works
4851
/// because it is impossible to compare an injected class name type
4852
/// with the corresponding non-injected template type, for the same
4853
/// reason that it is impossible to directly compare template
4854
/// parameters from different dependent contexts: injected class name
4855
/// types can only occur within the scope of a particular templated
4856
/// declaration, and within that scope every template specialization
4857
/// will canonicalize to the injected class name (when appropriate
4858
/// according to the rules of the language).
4859
class InjectedClassNameType : public Type {
4860
  friend class ASTContext; // ASTContext creates these.
4861
  friend class ASTNodeImporter;
4862
  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
4863
                          // currently suitable for AST reading, too much
4864
                          // interdependencies.
4865
4866
  CXXRecordDecl *Decl;
4867
4868
  /// The template specialization which this type represents.
4869
  /// For example, in
4870
  ///   template <class T> class A { ... };
4871
  /// this is A<T>, whereas in
4872
  ///   template <class X, class Y> class A<B<X,Y> > { ... };
4873
  /// this is A<B<X,Y> >.
4874
  ///
4875
  /// It is always unqualified, always a template specialization type,
4876
  /// and always dependent.
4877
  QualType InjectedType;
4878
4879
  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
4880
      : Type(InjectedClassName, QualType(), /*Dependent=*/true,
4881
             /*InstantiationDependent=*/true,
4882
             /*VariablyModified=*/false,
4883
             /*ContainsUnexpandedParameterPack=*/false),
4884
431k
        Decl(D), InjectedType(TST) {
4885
431k
    assert(isa<TemplateSpecializationType>(TST));
4886
431k
    assert(!TST.hasQualifiers());
4887
431k
    assert(TST->isDependentType());
4888
431k
  }
4889
4890
public:
4891
1.76M
  QualType getInjectedSpecializationType() const { return InjectedType; }
4892
4893
725
  const TemplateSpecializationType *getInjectedTST() const {
4894
725
    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
4895
725
  }
4896
4897
1
  TemplateName getTemplateName() const {
4898
1
    return getInjectedTST()->getTemplateName();
4899
1
  }
4900
4901
  CXXRecordDecl *getDecl() const;
4902
4903
51.4k
  bool isSugared() const { return false; }
4904
0
  QualType desugar() const { return QualType(this, 0); }
4905
4906
40.8M
  static bool classof(const Type *T) {
4907
40.8M
    return T->getTypeClass() == InjectedClassName;
4908
40.8M
  }
4909
};
4910
4911
/// The kind of a tag type.
4912
enum TagTypeKind {
4913
  /// The "struct" keyword.
4914
  TTK_Struct,
4915
4916
  /// The "__interface" keyword.
4917
  TTK_Interface,
4918
4919
  /// The "union" keyword.
4920
  TTK_Union,
4921
4922
  /// The "class" keyword.
4923
  TTK_Class,
4924
4925
  /// The "enum" keyword.
4926
  TTK_Enum
4927
};
4928
4929
/// The elaboration keyword that precedes a qualified type name or
4930
/// introduces an elaborated-type-specifier.
4931
enum ElaboratedTypeKeyword {
4932
  /// The "struct" keyword introduces the elaborated-type-specifier.
4933
  ETK_Struct,
4934
4935
  /// The "__interface" keyword introduces the elaborated-type-specifier.
4936
  ETK_Interface,
4937
4938
  /// The "union" keyword introduces the elaborated-type-specifier.
4939
  ETK_Union,
4940
4941
  /// The "class" keyword introduces the elaborated-type-specifier.
4942
  ETK_Class,
4943
4944
  /// The "enum" keyword introduces the elaborated-type-specifier.
4945
  ETK_Enum,
4946
4947
  /// The "typename" keyword precedes the qualified type name, e.g.,
4948
  /// \c typename T::type.
4949
  ETK_Typename,
4950
4951
  /// No keyword precedes the qualified type name.
4952
  ETK_None
4953
};
4954
4955
/// A helper class for Type nodes having an ElaboratedTypeKeyword.
4956
/// The keyword in stored in the free bits of the base class.
4957
/// Also provides a few static helpers for converting and printing
4958
/// elaborated type keyword and tag type kind enumerations.
4959
class TypeWithKeyword : public Type {
4960
protected:
4961
  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
4962
                  QualType Canonical, bool Dependent,
4963
                  bool InstantiationDependent, bool VariablyModified,
4964
                  bool ContainsUnexpandedParameterPack)
4965
      : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
4966
2.45M
             ContainsUnexpandedParameterPack) {
4967
2.45M
    TypeWithKeywordBits.Keyword = Keyword;
4968
2.45M
  }
4969
4970
public:
4971
10.6M
  ElaboratedTypeKeyword getKeyword() const {
4972
10.6M
    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
4973
10.6M
  }
4974
4975
  /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
4976
  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
4977
4978
  /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
4979
  /// It is an error to provide a type specifier which *isn't* a tag kind here.
4980
  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
4981
4982
  /// Converts a TagTypeKind into an elaborated type keyword.
4983
  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
4984
4985
  /// Converts an elaborated type keyword into a TagTypeKind.
4986
  /// It is an error to provide an elaborated type keyword
4987
  /// which *isn't* a tag kind here.
4988
  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
4989
4990
  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
4991
4992
  static StringRef getKeywordName(ElaboratedTypeKeyword Keyword);
4993
4994
142k
  static StringRef getTagTypeKindName(TagTypeKind Kind) {
4995
142k
    return getKeywordName(getKeywordForTagTypeKind(Kind));
4996
142k
  }
4997
4998
  class CannotCastToThisType {};
4999
  static CannotCastToThisType classof(const Type *);
5000
};
5001
5002
/// Represents a type that was referred to using an elaborated type
5003
/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
5004
/// or both.
5005
///
5006
/// This type is used to keep track of a type name as written in the
5007
/// source code, including tag keywords and any nested-name-specifiers.
5008
/// The type itself is always "sugar", used to express what was written
5009
/// in the source code but containing no additional semantic information.
5010
class ElaboratedType final
5011
    : public TypeWithKeyword,
5012
      public llvm::FoldingSetNode,
5013
      private llvm::TrailingObjects<ElaboratedType, TagDecl *> {
5014
  friend class ASTContext; // ASTContext creates these
5015
  friend TrailingObjects;
5016
5017
  /// The nested name specifier containing the qualifier.
5018
  NestedNameSpecifier *NNS;
5019
5020
  /// The type that this qualified name refers to.
5021
  QualType NamedType;
5022
5023
  /// The (re)declaration of this tag type owned by this occurrence is stored
5024
  /// as a trailing object if there is one. Use getOwnedTagDecl to obtain
5025
  /// it, or obtain a null pointer if there is none.
5026
5027
  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
5028
                 QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
5029
      : TypeWithKeyword(Keyword, Elaborated, CanonType,
5030
                        NamedType->isDependentType(),
5031
                        NamedType->isInstantiationDependentType(),
5032
                        NamedType->isVariablyModifiedType(),
5033
                        NamedType->containsUnexpandedParameterPack()),
5034
1.27M
        NNS(NNS), NamedType(NamedType) {
5035
1.27M
    ElaboratedTypeBits.HasOwnedTagDecl = false;
5036
1.27M
    if (OwnedTagDecl) {
5037
193k
      ElaboratedTypeBits.HasOwnedTagDecl = true;
5038
193k
      *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
5039
193k
    }
5040
1.27M
    assert(!(Keyword == ETK_None && NNS == nullptr) &&
5041
1.27M
           "ElaboratedType cannot have elaborated type keyword "
5042
1.27M
           "and name qualifier both null.");
5043
1.27M
  }
5044
5045
public:
5046
  /// Retrieve the qualification on this type.
5047
1.60M
  NestedNameSpecifier *getQualifier() const { return NNS; }
5048
5049
  /// Retrieve the type named by the qualified-id.
5050
18.8M
  QualType getNamedType() const { return NamedType; }
5051
5052
  /// Remove a single level of sugar.
5053
8.47M
  QualType desugar() const { return getNamedType(); }
5054
5055
  /// Returns whether this type directly provides sugar.
5056
8.47M
  bool isSugared() const { return true; }
5057
5058
  /// Return the (re)declaration of this type owned by this occurrence of this
5059
  /// type, or nullptr if there is none.
5060
5.01M
  TagDecl *getOwnedTagDecl() const {
5061
5.01M
    return ElaboratedTypeBits.HasOwnedTagDecl ? 
*getTrailingObjects<TagDecl *>()339k
5062
5.01M
                                              : 
nullptr4.67M
;
5063
5.01M
  }
5064
5065
5.01M
  void Profile(llvm::FoldingSetNodeID &ID) {
5066
5.01M
    Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl());
5067
5.01M
  }
5068
5069
  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
5070
                      NestedNameSpecifier *NNS, QualType NamedType,
5071
7.05M
                      TagDecl *OwnedTagDecl) {
5072
7.05M
    ID.AddInteger(Keyword);
5073
7.05M
    ID.AddPointer(NNS);
5074
7.05M
    NamedType.Profile(ID);
5075
7.05M
    ID.AddPointer(OwnedTagDecl);
5076
7.05M
  }
5077
5078
9.43M
  static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
5079
};
5080
5081
/// Represents a qualified type name for which the type name is
5082
/// dependent.
5083
///
5084
/// DependentNameType represents a class of dependent types that involve a
5085
/// possibly dependent nested-name-specifier (e.g., "T::") followed by a
5086
/// name of a type. The DependentNameType may start with a "typename" (for a
5087
/// typename-specifier), "class", "struct", "union", or "enum" (for a
5088
/// dependent elaborated-type-specifier), or nothing (in contexts where we
5089
/// know that we must be referring to a type, e.g., in a base class specifier).
5090
/// Typically the nested-name-specifier is dependent, but in MSVC compatibility
5091
/// mode, this type is used with non-dependent names to delay name lookup until
5092
/// instantiation.
5093
class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
5094
  friend class ASTContext; // ASTContext creates these
5095
5096
  /// The nested name specifier containing the qualifier.
5097
  NestedNameSpecifier *NNS;
5098
5099
  /// The type that this typename specifier refers to.
5100
  const IdentifierInfo *Name;
5101
5102
  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
5103
                    const IdentifierInfo *Name, QualType CanonType)
5104
      : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
5105
                        /*InstantiationDependent=*/true,
5106
                        /*VariablyModified=*/false,
5107
                        NNS->containsUnexpandedParameterPack()),
5108
1.17M
        NNS(NNS), Name(Name) {}
5109
5110
public:
5111
  /// Retrieve the qualification on this type.
5112
2.12M
  NestedNameSpecifier *getQualifier() const { return NNS; }
5113
5114
  /// Retrieve the type named by the typename specifier as an identifier.
5115
  ///
5116
  /// This routine will return a non-NULL identifier pointer when the
5117
  /// form of the original typename was terminated by an identifier,
5118
  /// e.g., "typename T::type".
5119
1.42M
  const IdentifierInfo *getIdentifier() const {
5120
1.42M
    return Name;
5121
1.42M
  }
5122
5123
216k
  bool isSugared() const { return false; }
5124
0
  QualType desugar() const { return QualType(this, 0); }
5125
5126
4.09M
  void Profile(llvm::FoldingSetNodeID &ID) {
5127
4.09M
    Profile(ID, getKeyword(), NNS, Name);
5128
4.09M
  }
5129
5130
  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
5131
6.00M
                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
5132
6.00M
    ID.AddInteger(Keyword);
5133
6.00M
    ID.AddPointer(NNS);
5134
6.00M
    ID.AddPointer(Name);
5135
6.00M
  }
5136
5137
8.94M
  static bool classof(const Type *T) {
5138
8.94M
    return T->getTypeClass() == DependentName;
5139
8.94M
  }
5140
};
5141
5142
/// Represents a template specialization type whose template cannot be
5143
/// resolved, e.g.
5144
///   A<T>::template B<T>
5145
class alignas(8) DependentTemplateSpecializationType
5146
    : public TypeWithKeyword,
5147
      public llvm::FoldingSetNode {
5148
  friend class ASTContext; // ASTContext creates these
5149
5150
  /// The nested name specifier containing the qualifier.
5151
  NestedNameSpecifier *NNS;
5152
5153
  /// The identifier of the template.
5154
  const IdentifierInfo *Name;
5155
5156
  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
5157
                                      NestedNameSpecifier *NNS,
5158
                                      const IdentifierInfo *Name,
5159
                                      ArrayRef<TemplateArgument> Args,
5160
                                      QualType Canon);
5161
5162
33.4k
  const TemplateArgument *getArgBuffer() const {
5163
33.4k
    return reinterpret_cast<const TemplateArgument*>(this+1);
5164
33.4k
  }
5165
5166
13.8k
  TemplateArgument *getArgBuffer() {
5167
13.8k
    return reinterpret_cast<TemplateArgument*>(this+1);
5168
13.8k
  }
5169
5170
public:
5171
61.4k
  NestedNameSpecifier *getQualifier() const { return NNS; }
5172
19.2k
  const IdentifierInfo *getIdentifier() const { return Name; }
5173
5174
  /// Retrieve the template arguments.
5175
33.4k
  const TemplateArgument *getArgs() const {
5176
33.4k
    return getArgBuffer();
5177
33.4k
  }
5178
5179
  /// Retrieve the number of template arguments.
5180
69.5k
  unsigned getNumArgs() const {
5181
69.5k
    return DependentTemplateSpecializationTypeBits.NumArgs;
5182
69.5k
  }
5183
5184
  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
5185
5186
28
  ArrayRef<TemplateArgument> template_arguments() const {
5187
28
    return {getArgs(), getNumArgs()};
5188
28
  }
5189
5190
  using iterator = const TemplateArgument *;
5191
5192
7
  iterator begin() const { return getArgs(); }
5193
  iterator end() const; // inline in TemplateBase.h
5194
5195
143
  bool isSugared() const { return false; }
5196
0
  QualType desugar() const { return QualType(this, 0); }
5197
5198
12.0k
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5199
12.0k
    Profile(ID, Context, getKeyword(), NNS, Name, {getArgs(), getNumArgs()});
5200
12.0k
  }
5201
5202
  static void Profile(llvm::FoldingSetNodeID &ID,
5203
                      const ASTContext &Context,
5204
                      ElaboratedTypeKeyword Keyword,
5205
                      NestedNameSpecifier *Qualifier,
5206
                      const IdentifierInfo *Name,
5207
                      ArrayRef<TemplateArgument> Args);
5208
5209
3.92M
  static bool classof(const Type *T) {
5210
3.92M
    return T->getTypeClass() == DependentTemplateSpecialization;
5211
3.92M
  }
5212
};
5213
5214
/// Represents a pack expansion of types.
5215
///
5216
/// Pack expansions are part of C++11 variadic templates. A pack
5217
/// expansion contains a pattern, which itself contains one or more
5218
/// "unexpanded" parameter packs. When instantiated, a pack expansion
5219
/// produces a series of types, each instantiated from the pattern of
5220
/// the expansion, where the Ith instantiation of the pattern uses the
5221
/// Ith arguments bound to each of the unexpanded parameter packs. The
5222
/// pack expansion is considered to "expand" these unexpanded
5223
/// parameter packs.
5224
///
5225
/// \code
5226
/// template<typename ...Types> struct tuple;
5227
///
5228
/// template<typename ...Types>
5229
/// struct tuple_of_references {
5230
///   typedef tuple<Types&...> type;
5231
/// };
5232
/// \endcode
5233
///
5234
/// Here, the pack expansion \c Types&... is represented via a
5235
/// PackExpansionType whose pattern is Types&.
5236
class PackExpansionType : public Type, public llvm::FoldingSetNode {
5237
  friend class ASTContext; // ASTContext creates these
5238
5239
  /// The pattern of the pack expansion.
5240
  QualType Pattern;
5241
5242
  PackExpansionType(QualType Pattern, QualType Canon,
5243
                    Optional<unsigned> NumExpansions)
5244
      : Type(PackExpansion, Canon, /*Dependent=*/Pattern->isDependentType(),
5245
             /*InstantiationDependent=*/true,
5246
             /*VariablyModified=*/Pattern->isVariablyModifiedType(),
5247
             /*ContainsUnexpandedParameterPack=*/false),
5248
166k
        Pattern(Pattern) {
5249
166k
    PackExpansionTypeBits.NumExpansions =
5250
166k
        NumExpansions ? 
*NumExpansions + 168
:
0166k
;
5251
166k
  }
5252
5253
public:
5254
  /// Retrieve the pattern of this pack expansion, which is the
5255
  /// type that will be repeatedly instantiated when instantiating the
5256
  /// pack expansion itself.
5257
2.68M
  QualType getPattern() const { return Pattern; }
5258
5259
  /// Retrieve the number of expansions that this pack expansion will
5260
  /// generate, if known.
5261
1.09M
  Optional<unsigned> getNumExpansions() const {
5262
1.09M
    if (PackExpansionTypeBits.NumExpansions)
5263
118
      return PackExpansionTypeBits.NumExpansions - 1;
5264
1.09M
    return None;
5265
1.09M
  }
5266
5267
43.0k
  bool isSugared() const { return !Pattern->isDependentType(); }
5268
39
  QualType desugar() const { return isSugared() ? Pattern : 
QualType(this, 0)0
; }
5269
5270
917k
  void Profile(llvm::FoldingSetNodeID &ID) {
5271
917k
    Profile(ID, getPattern(), getNumExpansions());
5272
917k
  }
5273
5274
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
5275
1.31M
                      Optional<unsigned> NumExpansions) {
5276
1.31M
    ID.AddPointer(Pattern.getAsOpaquePtr());
5277
1.31M
    ID.AddBoolean(NumExpansions.hasValue());
5278
1.31M
    if (NumExpansions)
5279
165
      ID.AddInteger(*NumExpansions);
5280
1.31M
  }
5281
5282
102M
  static bool classof(const Type *T) {
5283
102M
    return T->getTypeClass() == PackExpansion;
5284
102M
  }
5285
};
5286
5287
/// This class wraps the list of protocol qualifiers. For types that can
5288
/// take ObjC protocol qualifers, they can subclass this class.
5289
template <class T>
5290
class ObjCProtocolQualifiers {
5291
protected:
5292
  ObjCProtocolQualifiers() = default;
5293
5294
42.6k
  ObjCProtocolDecl * const *getProtocolStorage() const {
5295
42.6k
    return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
5296
42.6k
  }
clang::ObjCProtocolQualifiers<clang::ObjCObjectType>::getProtocolStorage() const
Line
Count
Source
5294
37.9k
  ObjCProtocolDecl * const *getProtocolStorage() const {
5295
37.9k
    return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
5296
37.9k
  }
clang::ObjCProtocolQualifiers<clang::ObjCTypeParamType>::getProtocolStorage() const
Line
Count
Source
5294
4.63k
  ObjCProtocolDecl * const *getProtocolStorage() const {
5295
4.63k
    return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
5296
4.63k
  }
5297
5298
44.1k
  ObjCProtocolDecl **getProtocolStorage() {
5299
44.1k
    return static_cast<T*>(this)->getProtocolStorageImpl();
5300
44.1k
  }
clang::ObjCProtocolQualifiers<clang::ObjCObjectType>::getProtocolStorage()
Line
Count
Source
5298
39.4k
  ObjCProtocolDecl **getProtocolStorage() {
5299
39.4k
    return static_cast<T*>(this)->getProtocolStorageImpl();
5300
39.4k
  }
clang::ObjCProtocolQualifiers<clang::ObjCTypeParamType>::getProtocolStorage()
Line
Count
Source
5298
4.73k
  ObjCProtocolDecl **getProtocolStorage() {
5299
4.73k
    return static_cast<T*>(this)->getProtocolStorageImpl();
5300
4.73k
  }
5301
5302
22.5k
  void setNumProtocols(unsigned N) {
5303
22.5k
    static_cast<T*>(this)->setNumProtocolsImpl(N);
5304
22.5k
  }
clang::ObjCProtocolQualifiers<clang::ObjCTypeParamType>::setNumProtocols(unsigned int)
Line
Count
Source
5302
2.89k
  void setNumProtocols(unsigned N) {
5303
2.89k
    static_cast<T*>(this)->setNumProtocolsImpl(N);
5304
2.89k
  }
clang::ObjCProtocolQualifiers<clang::ObjCObjectType>::setNumProtocols(unsigned int)
Line
Count
Source
5302
19.6k
  void setNumProtocols(unsigned N) {
5303
19.6k
    static_cast<T*>(this)->setNumProtocolsImpl(N);
5304
19.6k
  }
5305
5306
22.5k
  void initialize(ArrayRef<ObjCProtocolDecl *> protocols) {
5307
22.5k
    setNumProtocols(protocols.size());
5308
22.5k
    assert(getNumProtocols() == protocols.size() &&
5309
22.5k
           "bitfield overflow in protocol count");
5310
22.5k
    if (!protocols.empty())
5311
1.55k
      memcpy(getProtocolStorage(), protocols.data(),
5312
1.55k
             protocols.size() * sizeof(ObjCProtocolDecl*));
5313
22.5k
  }
clang::ObjCProtocolQualifiers<clang::ObjCTypeParamType>::initialize(llvm::ArrayRef<clang::ObjCProtocolDecl*>)
Line
Count
Source
5306
2.89k
  void initialize(ArrayRef<ObjCProtocolDecl *> protocols) {
5307
2.89k
    setNumProtocols(protocols.size());
5308
2.89k
    assert(getNumProtocols() == protocols.size() &&
5309
2.89k
           "bitfield overflow in protocol count");
5310
2.89k
    if (!protocols.empty())
5311
94
      memcpy(getProtocolStorage(), protocols.data(),
5312
94
             protocols.size() * sizeof(ObjCProtocolDecl*));
5313
2.89k
  }
clang::ObjCProtocolQualifiers<clang::ObjCObjectType>::initialize(llvm::ArrayRef<clang::ObjCProtocolDecl*>)
Line
Count
Source
5306
19.6k
  void initialize(ArrayRef<ObjCProtocolDecl *> protocols) {
5307
19.6k
    setNumProtocols(protocols.size());
5308
19.6k
    assert(getNumProtocols() == protocols.size() &&
5309
19.6k
           "bitfield overflow in protocol count");
5310
19.6k
    if (!protocols.empty())
5311
1.45k
      memcpy(getProtocolStorage(), protocols.data(),
5312
1.45k
             protocols.size() * sizeof(ObjCProtocolDecl*));
5313
19.6k
  }
5314
5315
public:
5316
  using qual_iterator = ObjCProtocolDecl * const *;
5317
  using qual_range = llvm::iterator_range<qual_iterator>;
5318
5319
5.92k
  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
clang::ObjCProtocolQualifiers<clang::ObjCTypeParamType>::quals() const
Line
Count
Source
5319
24
  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
clang::ObjCProtocolQualifiers<clang::ObjCObjectType>::quals() const
Line
Count
Source
5319
5.90k
  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
5320
42.6k
  qual_iterator qual_begin() const { return getProtocolStorage(); }
clang::ObjCProtocolQualifiers<clang::ObjCObjectType>::qual_begin() const
Line
Count
Source
5320
37.9k
  qual_iterator qual_begin() const { return getProtocolStorage(); }
clang::ObjCProtocolQualifiers<clang::ObjCTypeParamType>::qual_begin() const
Line
Count
Source
5320
4.63k
  qual_iterator qual_begin() const { return getProtocolStorage(); }
5321
8.76k
  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
clang::ObjCProtocolQualifiers<clang::ObjCTypeParamType>::qual_end() const
Line
Count
Source
5321
25
  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
clang::ObjCProtocolQualifiers<clang::ObjCObjectType>::qual_end() const
Line
Count
Source
5321
8.74k
  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
5322
5323
242k
  bool qual_empty() const { return getNumProtocols() == 0; }
clang::ObjCProtocolQualifiers<clang::ObjCObjectType>::qual_empty() const
Line
Count
Source
5323
242k
  bool qual_empty() const { return getNumProtocols() == 0; }
clang::ObjCProtocolQualifiers<clang::ObjCTypeParamType>::qual_empty() const
Line
Count
Source
5323
307
  bool qual_empty() const { return getNumProtocols() == 0; }