Coverage Report

Created: 2018-11-16 02:38

/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
648M
    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
79
80
665M
    static inline ::clang::Type *getFromVoidPointer(void *P) {
81
665M
      return static_cast< ::clang::Type*>(P);
82
665M
    }
83
84
    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
85
  };
86
87
  template<>
88
  struct PointerLikeTypeTraits< ::clang::ExtQuals*> {
89
448k
    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
90
91
1.45M
    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
92
1.45M
      return static_cast< ::clang::ExtQuals*>(P);
93
1.45M
    }
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
867
202
867
    Qualifiers Q;
203
867
    unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
204
867
    Q.addCVRQualifiers(CommonCRV);
205
867
    L.removeCVRQualifiers(CommonCRV);
206
867
    R.removeCVRQualifiers(CommonCRV);
207
867
208
867
    if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
209
859
      Q.setObjCGCAttr(L.getObjCGCAttr());
210
859
      L.removeObjCGCAttr();
211
859
      R.removeObjCGCAttr();
212
859
    }
213
867
214
867
    if (L.getObjCLifetime() == R.getObjCLifetime()) {
215
715
      Q.setObjCLifetime(L.getObjCLifetime());
216
715
      L.removeObjCLifetime();
217
715
      R.removeObjCLifetime();
218
715
    }
219
867
220
867
    if (L.getAddressSpace() == R.getAddressSpace()) {
221
165
      Q.setAddressSpace(L.getAddressSpace());
222
165
      L.removeAddressSpace();
223
165
      R.removeAddressSpace();
224
165
    }
225
867
    return Q;
226
867
  }
227
228
35.3M
  static Qualifiers fromFastMask(unsigned Mask) {
229
35.3M
    Qualifiers Qs;
230
35.3M
    Qs.addFastQualifiers(Mask);
231
35.3M
    return Qs;
232
35.3M
  }
233
234
7.20M
  static Qualifiers fromCVRMask(unsigned CVR) {
235
7.20M
    Qualifiers Qs;
236
7.20M
    Qs.addCVRQualifiers(CVR);
237
7.20M
    return Qs;
238
7.20M
  }
239
240
6.92M
  static Qualifiers fromCVRUMask(unsigned CVRU) {
241
6.92M
    Qualifiers Qs;
242
6.92M
    Qs.addCVRUQualifiers(CVRU);
243
6.92M
    return Qs;
244
6.92M
  }
245
246
  // Deserialize qualifiers from an opaque representation.
247
429
  static Qualifiers fromOpaqueValue(unsigned opaque) {
248
429
    Qualifiers Qs;
249
429
    Qs.Mask = opaque;
250
429
    return Qs;
251
429
  }
252
253
  // Serialize these qualifiers into an opaque representation.
254
841k
  unsigned getAsOpaqueValue() const {
255
841k
    return Mask;
256
841k
  }
257
258
3.05M
  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.10M
  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.77M
  bool hasRestrict() const { return Mask & Restrict; }
273
  void setRestrict(bool flag) {
274
    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
275
  }
276
693k
  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
3.50M
  void removeCVRQualifiers(unsigned mask) {
286
3.50M
    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
287
3.50M
    Mask &= ~mask;
288
3.50M
  }
289
1.66M
  void removeCVRQualifiers() {
290
1.66M
    removeCVRQualifiers(CVRMask);
291
1.66M
  }
292
7.83M
  void addCVRQualifiers(unsigned mask) {
293
7.83M
    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
294
7.83M
    Mask |= mask;
295
7.83M
  }
296
6.92M
  void addCVRUQualifiers(unsigned mask) {
297
6.92M
    assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits");
298
6.92M
    Mask |= mask;
299
6.92M
  }
300
301
12.1M
  bool hasUnaligned() const { return Mask & UMask; }
302
2.68M
  void setUnaligned(bool flag) {
303
2.68M
    Mask = (Mask & ~UMask) | (flag ? 
UMask142
:
02.68M
);
304
2.68M
  }
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.5M
  void setObjCGCAttr(GC type) {
311
13.5M
    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
312
13.5M
  }
313
4.22M
  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
314
255
  void addObjCGCAttr(GC type) {
315
255
    assert(type);
316
255
    setObjCGCAttr(type);
317
255
  }
318
204
  Qualifiers withoutObjCGCAttr() const {
319
204
    Qualifiers qs = *this;
320
204
    qs.removeObjCGCAttr();
321
204
    return qs;
322
204
  }
323
333
  Qualifiers withoutObjCLifetime() const {
324
333
    Qualifiers qs = *this;
325
333
    qs.removeObjCLifetime();
326
333
    return qs;
327
333
  }
328
329
14.7M
  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
330
54.2M
  ObjCLifetime getObjCLifetime() const {
331
54.2M
    return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
332
54.2M
  }
333
289k
  void setObjCLifetime(ObjCLifetime type) {
334
289k
    Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
335
289k
  }
336
286k
  void removeObjCLifetime() { setObjCLifetime(OCL_None); }
337
6.78k
  void addObjCLifetime(ObjCLifetime type) {
338
6.78k
    assert(type);
339
6.78k
    assert(!hasObjCLifetime());
340
6.78k
    Mask |= (type << LifetimeShift);
341
6.78k
  }
342
343
  /// True if the lifetime is neither None or ExplicitNone.
344
4.33M
  bool hasNonTrivialObjCLifetime() const {
345
4.33M
    ObjCLifetime lifetime = getObjCLifetime();
346
4.33M
    return (lifetime > OCL_ExplicitNone);
347
4.33M
  }
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.2M
  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
356
74.9M
  LangAS getAddressSpace() const {
357
74.9M
    return static_cast<LangAS>(Mask >> AddressSpaceShift);
358
74.9M
  }
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
470k
  void setAddressSpace(LangAS space) {
377
470k
    assert((unsigned)space <= MaxAddressSpace);
378
470k
    Mask = (Mask & ~AddressSpaceMask)
379
470k
         | (((uint32_t) space) << AddressSpaceShift);
380
470k
  }
381
1.44k
  void removeAddressSpace() { setAddressSpace(LangAS::Default); }
382
402k
  void addAddressSpace(LangAS space) {
383
402k
    assert(space != LangAS::Default);
384
402k
    setAddressSpace(space);
385
402k
  }
386
387
  // Fast qualifiers are those that can be allocated directly
388
  // on a QualType object.
389
  bool hasFastQualifiers() const { return getFastQualifiers(); }
390
42.2M
  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
430k
  void removeFastQualifiers(unsigned mask) {
396
430k
    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
397
430k
    Mask &= ~mask;
398
430k
  }
399
430k
  void removeFastQualifiers() {
400
430k
    removeFastQualifiers(FastMask);
401
430k
  }
402
476M
  void addFastQualifiers(unsigned mask) {
403
476M
    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
404
476M
    Mask |= mask;
405
476M
  }
406
407
  /// Return true if the set contains any qualifiers which require an ExtQuals
408
  /// node to be allocated.
409
41.8M
  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.20M
  bool empty() const { return !Mask; }
419
420
  /// Add the qualifiers from the given set to this set.
421
3.46M
  void addQualifiers(Qualifiers Q) {
422
3.46M
    // If the other set doesn't have any non-boolean qualifiers, just
423
3.46M
    // bit-or it in.
424
3.46M
    if (!(Q.Mask & ~CVRMask))
425
3.46M
      Mask |= Q.Mask;
426
961
    else {
427
961
      Mask |= (Q.Mask & CVRMask);
428
961
      if (Q.hasAddressSpace())
429
698
        addAddressSpace(Q.getAddressSpace());
430
961
      if (Q.hasObjCGCAttr())
431
38
        addObjCGCAttr(Q.getObjCGCAttr());
432
961
      if (Q.hasObjCLifetime())
433
221
        addObjCLifetime(Q.getObjCLifetime());
434
961
    }
435
3.46M
  }
436
437
  /// Remove the qualifiers from the given set from this set.
438
28.2k
  void removeQualifiers(Qualifiers Q) {
439
28.2k
    // If the other set doesn't have any non-boolean qualifiers, just
440
28.2k
    // bit-and the inverse in.
441
28.2k
    if (!(Q.Mask & ~CVRMask))
442
28.2k
      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
28.2k
  }
453
454
  /// Add the qualifiers from the given set to this set, given that
455
  /// they don't conflict.
456
1.07M
  void addConsistentQualifiers(Qualifiers qs) {
457
1.07M
    assert(getAddressSpace() == qs.getAddressSpace() ||
458
1.07M
           !hasAddressSpace() || !qs.hasAddressSpace());
459
1.07M
    assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
460
1.07M
           !hasObjCGCAttr() || !qs.hasObjCGCAttr());
461
1.07M
    assert(getObjCLifetime() == qs.getObjCLifetime() ||
462
1.07M
           !hasObjCLifetime() || !qs.hasObjCLifetime());
463
1.07M
    Mask |= qs.Mask;
464
1.07M
  }
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.31M
  bool isAddressSpaceSupersetOf(Qualifiers other) const {
474
5.31M
    return
475
5.31M
        // Address spaces must match exactly.
476
5.31M
        getAddressSpace() == other.getAddressSpace() ||
477
5.31M
        // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
478
5.31M
        // for __constant can be used as __generic.
479
5.31M
        
(1.37k
getAddressSpace() == LangAS::opencl_generic1.37k
&&
480
1.37k
         
other.getAddressSpace() != LangAS::opencl_constant440
);
481
5.31M
  }
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.84M
  bool compatiblyIncludes(Qualifiers other) const {
487
3.84M
    return isAddressSpaceSupersetOf(other) &&
488
3.84M
           // ObjC GC qualifiers can match, be added, or be removed, but can't
489
3.84M
           // be changed.
490
3.84M
           
(3.84M
getObjCGCAttr() == other.getObjCGCAttr()3.84M
||
!hasObjCGCAttr()18
||
491
3.84M
            
!other.hasObjCGCAttr()15
) &&
492
3.84M
           // ObjC lifetime qualifiers must match exactly.
493
3.84M
           
getObjCLifetime() == other.getObjCLifetime()3.84M
&&
494
3.84M
           // CVR qualifiers may subset.
495
3.84M
           
(((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask))3.84M
&&
496
3.84M
           // U qualifier may superset.
497
3.84M
           
(3.23M
!other.hasUnaligned()3.23M
||
hasUnaligned()35
);
498
3.84M
  }
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.7M
  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
526
527
17.6M
  explicit operator bool() const { return hasQualifiers(); }
528
529
3.46M
  Qualifiers &operator+=(Qualifiers R) {
530
3.46M
    addQualifiers(R);
531
3.46M
    return *this;
532
3.46M
  }
533
534
  // Union two qualifier sets.  If an enumerated qualifier appears
535
  // in both sets, use the one from the right.
536
1.98M
  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
537
1.98M
    L += R;
538
1.98M
    return L;
539
1.98M
  }
540
541
28.2k
  Qualifiers &operator-=(Qualifiers R) {
542
28.2k
    removeQualifiers(R);
543
28.2k
    return *this;
544
28.2k
  }
545
546
  /// Compute the difference between two qualifier sets.
547
23.7k
  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
548
23.7k
    L -= R;
549
23.7k
    return L;
550
23.7k
  }
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.11M
  void Profile(llvm::FoldingSetNodeID &ID) const {
560
1.11M
    ID.AddInteger(Mask);
561
1.11M
  }
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
60.0M
  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.3k
  friend bool operator!=(SplitQualType a, SplitQualType b) {
602
11.3k
    return a.Ty != b.Ty || 
a.Quals != b.Quals10.2k
;
603
11.3k
  }
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.45M
  const ExtQuals *getExtQualsUnsafe() const {
650
1.45M
    return Value.getPointer().get<const ExtQuals*>();
651
1.45M
  }
652
653
74.6M
  const Type *getTypePtrUnsafe() const {
654
74.6M
    return Value.getPointer().get<const Type*>();
655
74.6M
  }
656
657
10.3G
  const ExtQualsTypeCommonBase *getCommonPtr() const {
658
10.3G
    assert(!isNull() && "Cannot retrieve a NULL type pointer");
659
10.3G
    auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
660
10.3G
    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
661
10.3G
    return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
662
10.3G
  }
663
664
public:
665
3.41G
  QualType() = default;
666
646M
  QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
667
448k
  QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
668
669
2.39G
  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.88G
  static QualType getFromOpaquePtr(const void *Ptr) {
690
1.88G
    QualType T;
691
1.88G
    T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
692
1.88G
    return T;
693
1.88G
  }
694
695
4.09M
  const Type &operator*() const {
696
4.09M
    return *getTypePtr();
697
4.09M
  }
698
699
4.13G
  const Type *operator->() const {
700
4.13G
    return getTypePtr();
701
4.13G
  }
702
703
  bool isCanonical() const;
704
  bool isCanonicalAsParam() const;
705
706
  /// Return true if this QualType doesn't point to a type yet.
707
587M
  bool isNull() const {
708
587M
    return Value.getPointer().isNull();
709
587M
  }
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.5M
  bool isLocalConstQualified() const {
715
74.5M
    return (getLocalFastQualifiers() & Qualifiers::Const);
716
74.5M
  }
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.75M
  bool isLocalRestrictQualified() const {
725
1.75M
    return (getLocalFastQualifiers() & Qualifiers::Restrict);
726
1.75M
  }
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.2M
  bool isLocalVolatileQualified() const {
735
46.2M
    return (getLocalFastQualifiers() & Qualifiers::Volatile);
736
46.2M
  }
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.03G
  bool hasLocalQualifiers() const {
745
1.03G
    return getLocalFastQualifiers() || 
hasLocalNonFastQualifiers()1.00G
;
746
1.03G
  }
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.32G
  bool hasLocalNonFastQualifiers() const {
755
1.32G
    return Value.getPointer().is<const ExtQuals*>();
756
1.32G
  }
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.1M
  unsigned getLocalCVRQualifiers() const {
770
30.1M
    return getLocalFastQualifiers();
771
30.1M
  }
772
773
  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
774
  /// applied to this type.
775
  unsigned getCVRQualifiers() const;
776
777
713k
  bool isConstant(const ASTContext& Ctx) const {
778
713k
    return QualType::isConstant(*this, Ctx);
779
713k
  }
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.26M
  void addConst() {
812
2.26M
    addFastQualifiers(Qualifiers::Const);
813
2.26M
  }
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.31M
  QualType withCVRQualifiers(unsigned CVR) const {
835
3.31M
    return withFastQualifiers(CVR);
836
3.31M
  }
837
838
781M
  void addFastQualifiers(unsigned TQs) {
839
781M
    assert(!(TQs & ~Qualifiers::FastMask)
840
781M
           && "non-fast qualifier bits set in mask!");
841
781M
    Value.setInt(Value.getInt() | TQs);
842
781M
  }
843
844
  void removeLocalConst();
845
  void removeLocalVolatile();
846
  void removeLocalRestrict();
847
  void removeLocalCVRQualifiers(unsigned Mask);
848
849
1.84M
  void removeLocalFastQualifiers() { Value.setInt(0); }
850
7.60k
  void removeLocalFastQualifiers(unsigned Mask) {
851
7.60k
    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
852
7.60k
    Value.setInt(Value.getInt() & ~Mask);
853
7.60k
  }
854
855
  // Creates a type with the given qualifiers in addition to any
856
  // qualifiers already on this type.
857
779M
  QualType withFastQualifiers(unsigned TQs) const {
858
779M
    QualType T = *this;
859
779M
    T.addFastQualifiers(TQs);
860
779M
    return T;
861
779M
  }
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
79
  QualType withoutLocalFastQualifiers() const {
871
79
    QualType T = *this;
872
79
    T.removeLocalFastQualifiers();
873
79
    return T;
874
79
  }
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
68.9k
  QualType getDesugaredType(const ASTContext &Context) const {
943
68.9k
    return getDesugaredType(*this, Context);
944
68.9k
  }
945
946
24.5M
  SplitQualType getSplitDesugaredType() const {
947
24.5M
    return getSplitDesugaredType(*this);
948
24.5M
  }
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
715
  QualType getSingleStepDesugaredType(const ASTContext &Context) const {
956
715
    return getSingleStepDesugaredTypeImpl(*this, Context);
957
715
  }
958
959
  /// Returns the specified type after dropping any
960
  /// outer-level parentheses.
961
8.69k
  QualType IgnoreParens() const {
962
8.69k
    if (isa<ParenType>(*this))
963
6
      return QualType::IgnoreParens(*this);
964
8.68k
    return *this;
965
8.68k
  }
966
967
  /// Indicate whether the specified types and qualifiers are identical.
968
652M
  friend bool operator==(const QualType &LHS, const QualType &RHS) {
969
652M
    return LHS.Value == RHS.Value;
970
652M
  }
971
59.6M
  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
972
59.6M
    return LHS.Value != RHS.Value;
973
59.6M
  }
974
975
  static std::string getAsString(SplitQualType split,
976
39.9k
                                 const PrintingPolicy &Policy) {
977
39.9k
    return getAsString(split.Ty, split.Quals, Policy);
978
39.9k
  }
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
167k
                           const PrintingPolicy &Policy) const {
1004
167k
    return getAsStringInternal(split(), Str, Policy);
1005
167k
  }
1006
1007
  static void getAsStringInternal(SplitQualType split, std::string &out,
1008
167k
                                  const PrintingPolicy &policy) {
1009
167k
    return getAsStringInternal(split.Ty, split.Quals, out, policy);
1010
167k
  }
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.19M
  bool isObjCGCWeak() const {
1057
4.19M
    return getObjCGCAttr() == Qualifiers::Weak;
1058
4.19M
  }
1059
1060
  /// true when Type is objc's strong.
1061
1.98M
  bool isObjCGCStrong() const {
1062
1.98M
    return getObjCGCAttr() == Qualifiers::Strong;
1063
1.98M
  }
1064
1065
  /// Returns lifetime attribute of this type.
1066
28.4M
  Qualifiers::ObjCLifetime getObjCLifetime() const {
1067
28.4M
    return getQualifiers().getObjCLifetime();
1068
28.4M
  }
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.71M
  DestructionKind isDestructedType() const {
1161
5.71M
    return isDestructedTypeImpl(*this);
1162
5.71M
  }
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
4.10G
  static SimpleType getSimplifiedValue(::clang::QualType Val) {
1248
4.10G
    return Val.getTypePtr();
1249
4.10G
  }
1250
};
1251
1252
// Teach SmallPtrSet that QualType is "basically a pointer".
1253
template<>
1254
struct PointerLikeTypeTraits<clang::QualType> {
1255
30.7M
  static inline void *getAsVoidPointer(clang::QualType P) {
1256
30.7M
    return P.getAsOpaquePtr();
1257
30.7M
  }
1258
1259
38.8M
  static inline clang::QualType getFromVoidPointer(void *P) {
1260
38.8M
    return clang::QualType::getFromOpaquePtr(P);
1261
38.8M
  }
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
44.1M
      : 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
18.2k
  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
30.8k
        Quals(quals) {
1328
30.8k
    assert(Quals.hasNonFastQualifiers()
1329
30.8k
           && "ExtQuals created with no fast qualifiers");
1330
30.8k
    assert(!Quals.hasFastQualifiers()
1331
30.8k
           && "ExtQuals created with fast qualifiers");
1332
30.8k
  }
1333
1334
1.45M
  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
795k
  const Type *getBaseType() const { return BaseType; }
1348
1349
public:
1350
681k
  void Profile(llvm::FoldingSetNodeID &ID) const {
1351
681k
    Profile(ID, getBaseType(), Quals);
1352
681k
  }
1353
1354
  static void Profile(llvm::FoldingSetNodeID &ID,
1355
                      const Type *BaseType,
1356
1.11M
                      Qualifiers Quals) {
1357
1.11M
    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1358
1.11M
    ID.AddPointer(BaseType);
1359
1.11M
    Quals.Profile(ID);
1360
1.11M
  }
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.18M
    bool isCacheValid() const {
1462
9.18M
      return CacheValid;
1463
9.18M
    }
1464
1465
7.78M
    Linkage getLinkage() const {
1466
7.78M
      assert(isCacheValid() && "getting linkage from invalid cache");
1467
7.78M
      return static_cast<Linkage>(CachedLinkage);
1468
7.78M
    }
1469
1470
3.29M
    bool hasLocalOrUnnamedType() const {
1471
3.29M
      assert(isCacheValid() && "getting linkage from invalid cache");
1472
3.29M
      return CachedLocalOrUnnamed;
1473
3.29M
    }
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
  /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
1506
  /// Only common bits are stored here. Additional uncommon bits are stored
1507
  /// in a trailing object after FunctionProtoType.
1508
  class FunctionTypeBitfields {
1509
    friend class FunctionProtoType;
1510
    friend class FunctionType;
1511
1512
    unsigned : NumTypeBits;
1513
1514
    /// Extra information which affects how the function is called, like
1515
    /// regparm and the calling convention.
1516
    unsigned ExtInfo : 12;
1517
1518
    /// The ref-qualifier associated with a \c FunctionProtoType.
1519
    ///
1520
    /// This is a value of type \c RefQualifierKind.
1521
    unsigned RefQualifier : 2;
1522
1523
    /// Used only by FunctionProtoType, put here to pack with the
1524
    /// other bitfields.
1525
    /// The qualifiers are part of FunctionProtoType because...
1526
    ///
1527
    /// C++ 8.3.5p4: The return type, the parameter type list and the
1528
    /// cv-qualifier-seq, [...], are part of the function type.
1529
    unsigned TypeQuals : 4;
1530
1531
    /// The number of parameters this function has, not counting '...'.
1532
    /// According to [implimits] 8 bits should be enough here but this is
1533
    /// somewhat easy to exceed with metaprogramming and so we would like to
1534
    /// keep NumParams as wide as reasonably possible.
1535
    unsigned NumParams : 16;
1536
1537
    /// The type of exception specification this function has.
1538
    unsigned ExceptionSpecType : 4;
1539
1540
    /// Whether this function has extended parameter information.
1541
    unsigned HasExtParameterInfos : 1;
1542
1543
    /// Whether the function is variadic.
1544
    unsigned Variadic : 1;
1545
1546
    /// Whether this function has a trailing return type.
1547
    unsigned HasTrailingReturn : 1;
1548
  };
1549
1550
  class ObjCObjectTypeBitfields {
1551
    friend class ObjCObjectType;
1552
1553
    unsigned : NumTypeBits;
1554
1555
    /// The number of type arguments stored directly on this object type.
1556
    unsigned NumTypeArgs : 7;
1557
1558
    /// The number of protocols stored directly on this object type.
1559
    unsigned NumProtocols : 6;
1560
1561
    /// Whether this is a "kindof" type.
1562
    unsigned IsKindOf : 1;
1563
  };
1564
1565
  class ReferenceTypeBitfields {
1566
    friend class ReferenceType;
1567
1568
    unsigned : NumTypeBits;
1569
1570
    /// True if the type was originally spelled with an lvalue sigil.
1571
    /// This is never true of rvalue references but can also be false
1572
    /// on lvalue references because of C++0x [dcl.typedef]p9,
1573
    /// as follows:
1574
    ///
1575
    ///   typedef int &ref;    // lvalue, spelled lvalue
1576
    ///   typedef int &&rvref; // rvalue
1577
    ///   ref &a;              // lvalue, inner ref, spelled lvalue
1578
    ///   ref &&a;             // lvalue, inner ref
1579
    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
1580
    ///   rvref &&a;           // rvalue, inner ref
1581
    unsigned SpelledAsLValue : 1;
1582
1583
    /// True if the inner type is a reference type.  This only happens
1584
    /// in non-canonical forms.
1585
    unsigned InnerRef : 1;
1586
  };
1587
1588
  class TypeWithKeywordBitfields {
1589
    friend class TypeWithKeyword;
1590
1591
    unsigned : NumTypeBits;
1592
1593
    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
1594
    unsigned Keyword : 8;
1595
  };
1596
1597
  enum { NumTypeWithKeywordBits = 8 };
1598
1599
  class ElaboratedTypeBitfields {
1600
    friend class ElaboratedType;
1601
1602
    unsigned : NumTypeBits;
1603
    unsigned : NumTypeWithKeywordBits;
1604
1605
    /// Whether the ElaboratedType has a trailing OwnedTagDecl.
1606
    unsigned HasOwnedTagDecl : 1;
1607
  };
1608
1609
  class VectorTypeBitfields {
1610
    friend class VectorType;
1611
    friend class DependentVectorType;
1612
1613
    unsigned : NumTypeBits;
1614
1615
    /// The kind of vector, either a generic vector type or some
1616
    /// target-specific vector type such as for AltiVec or Neon.
1617
    unsigned VecKind : 3;
1618
1619
    /// The number of elements in the vector.
1620
    unsigned NumElements : 29 - NumTypeBits;
1621
1622
    enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 };
1623
  };
1624
1625
  class AttributedTypeBitfields {
1626
    friend class AttributedType;
1627
1628
    unsigned : NumTypeBits;
1629
1630
    /// An AttributedType::Kind
1631
    unsigned AttrKind : 32 - NumTypeBits;
1632
  };
1633
1634
  class AutoTypeBitfields {
1635
    friend class AutoType;
1636
1637
    unsigned : NumTypeBits;
1638
1639
    /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
1640
    /// or '__auto_type'?  AutoTypeKeyword value.
1641
    unsigned Keyword : 2;
1642
  };
1643
1644
  class SubstTemplateTypeParmPackTypeBitfields {
1645
    friend class SubstTemplateTypeParmPackType;
1646
1647
    unsigned : NumTypeBits;
1648
1649
    /// The number of template arguments in \c Arguments, which is
1650
    /// expected to be able to hold at least 1024 according to [implimits].
1651
    /// However as this limit is somewhat easy to hit with template
1652
    /// metaprogramming we'd prefer to keep it as large as possible.
1653
    /// At the moment it has been left as a non-bitfield since this type
1654
    /// safely fits in 64 bits as an unsigned, so there is no reason to
1655
    /// introduce the performance impact of a bitfield.
1656
    unsigned NumArgs;
1657
  };
1658
1659
  class TemplateSpecializationTypeBitfields {
1660
    friend class TemplateSpecializationType;
1661
1662
    unsigned : NumTypeBits;
1663
1664
    /// Whether this template specialization type is a substituted type alias.
1665
    unsigned TypeAlias : 1;
1666
1667
    /// The number of template arguments named in this class template
1668
    /// specialization, which is expected to be able to hold at least 1024
1669
    /// according to [implimits]. However, as this limit is somewhat easy to
1670
    /// hit with template metaprogramming we'd prefer to keep it as large
1671
    /// as possible. At the moment it has been left as a non-bitfield since
1672
    /// this type safely fits in 64 bits as an unsigned, so there is no reason
1673
    /// to introduce the performance impact of a bitfield.
1674
    unsigned NumArgs;
1675
  };
1676
1677
  class DependentTemplateSpecializationTypeBitfields {
1678
    friend class DependentTemplateSpecializationType;
1679
1680
    unsigned : NumTypeBits;
1681
    unsigned : NumTypeWithKeywordBits;
1682
1683
    /// The number of template arguments named in this class template
1684
    /// specialization, which is expected to be able to hold at least 1024
1685
    /// according to [implimits]. However, as this limit is somewhat easy to
1686
    /// hit with template metaprogramming we'd prefer to keep it as large
1687
    /// as possible. At the moment it has been left as a non-bitfield since
1688
    /// this type safely fits in 64 bits as an unsigned, so there is no reason
1689
    /// to introduce the performance impact of a bitfield.
1690
    unsigned NumArgs;
1691
  };
1692
1693
  class PackExpansionTypeBitfields {
1694
    friend class PackExpansionType;
1695
1696
    unsigned : NumTypeBits;
1697
1698
    /// The number of expansions that this pack expansion will
1699
    /// generate when substituted (+1), which is expected to be able to
1700
    /// hold at least 1024 according to [implimits]. However, as this limit
1701
    /// is somewhat easy to hit with template metaprogramming we'd prefer to
1702
    /// keep it as large as possible. At the moment it has been left as a
1703
    /// non-bitfield since this type safely fits in 64 bits as an unsigned, so
1704
    /// there is no reason to introduce the performance impact of a bitfield.
1705
    ///
1706
    /// This field will only have a non-zero value when some of the parameter
1707
    /// packs that occur within the pattern have been substituted but others
1708
    /// have not.
1709
    unsigned NumExpansions;
1710
  };
1711
1712
  union {
1713
    TypeBitfields TypeBits;
1714
    ArrayTypeBitfields ArrayTypeBits;
1715
    AttributedTypeBitfields AttributedTypeBits;
1716
    AutoTypeBitfields AutoTypeBits;
1717
    BuiltinTypeBitfields BuiltinTypeBits;
1718
    FunctionTypeBitfields FunctionTypeBits;
1719
    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1720
    ReferenceTypeBitfields ReferenceTypeBits;
1721
    TypeWithKeywordBitfields TypeWithKeywordBits;
1722
    ElaboratedTypeBitfields ElaboratedTypeBits;
1723
    VectorTypeBitfields VectorTypeBits;
1724
    SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits;
1725
    TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits;
1726
    DependentTemplateSpecializationTypeBitfields
1727
      DependentTemplateSpecializationTypeBits;
1728
    PackExpansionTypeBitfields PackExpansionTypeBits;
1729
1730
    static_assert(sizeof(TypeBitfields) <= 8,
1731
                  "TypeBitfields is larger than 8 bytes!");
1732
    static_assert(sizeof(ArrayTypeBitfields) <= 8,
1733
                  "ArrayTypeBitfields is larger than 8 bytes!");
1734
    static_assert(sizeof(AttributedTypeBitfields) <= 8,
1735
                  "AttributedTypeBitfields is larger than 8 bytes!");
1736
    static_assert(sizeof(AutoTypeBitfields) <= 8,
1737
                  "AutoTypeBitfields is larger than 8 bytes!");
1738
    static_assert(sizeof(BuiltinTypeBitfields) <= 8,
1739
                  "BuiltinTypeBitfields is larger than 8 bytes!");
1740
    static_assert(sizeof(FunctionTypeBitfields) <= 8,
1741
                  "FunctionTypeBitfields is larger than 8 bytes!");
1742
    static_assert(sizeof(ObjCObjectTypeBitfields) <= 8,
1743
                  "ObjCObjectTypeBitfields is larger than 8 bytes!");
1744
    static_assert(sizeof(ReferenceTypeBitfields) <= 8,
1745
                  "ReferenceTypeBitfields is larger than 8 bytes!");
1746
    static_assert(sizeof(TypeWithKeywordBitfields) <= 8,
1747
                  "TypeWithKeywordBitfields is larger than 8 bytes!");
1748
    static_assert(sizeof(ElaboratedTypeBitfields) <= 8,
1749
                  "ElaboratedTypeBitfields is larger than 8 bytes!");
1750
    static_assert(sizeof(VectorTypeBitfields) <= 8,
1751
                  "VectorTypeBitfields is larger than 8 bytes!");
1752
    static_assert(sizeof(SubstTemplateTypeParmPackTypeBitfields) <= 8,
1753
                  "SubstTemplateTypeParmPackTypeBitfields is larger"
1754
                  " than 8 bytes!");
1755
    static_assert(sizeof(TemplateSpecializationTypeBitfields) <= 8,
1756
                  "TemplateSpecializationTypeBitfields is larger"
1757
                  " than 8 bytes!");
1758
    static_assert(sizeof(DependentTemplateSpecializationTypeBitfields) <= 8,
1759
                  "DependentTemplateSpecializationTypeBitfields is larger"
1760
                  " than 8 bytes!");
1761
    static_assert(sizeof(PackExpansionTypeBitfields) <= 8,
1762
                  "PackExpansionTypeBitfields is larger than 8 bytes");
1763
  };
1764
1765
private:
1766
  template <class T> friend class TypePropertyCache;
1767
1768
  /// Set whether this type comes from an AST file.
1769
145k
  void setFromAST(bool V = true) const {
1770
145k
    TypeBits.FromAST = V;
1771
145k
  }
1772
1773
protected:
1774
  friend class ASTContext;
1775
1776
  Type(TypeClass tc, QualType canon, bool Dependent,
1777
       bool InstantiationDependent, bool VariablyModified,
1778
       bool ContainsUnexpandedParameterPack)
1779
      : ExtQualsTypeCommonBase(this,
1780
44.0M
                               canon.isNull() ? QualType(this_(), 0) : canon) {
1781
44.0M
    TypeBits.TC = tc;
1782
44.0M
    TypeBits.Dependent = Dependent;
1783
44.0M
    TypeBits.InstantiationDependent = Dependent || 
InstantiationDependent26.4M
;
1784
44.0M
    TypeBits.VariablyModified = VariablyModified;
1785
44.0M
    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
1786
44.0M
    TypeBits.CacheValid = false;
1787
44.0M
    TypeBits.CachedLocalOrUnnamed = false;
1788
44.0M
    TypeBits.CachedLinkage = NoLinkage;
1789
44.0M
    TypeBits.FromAST = false;
1790
44.0M
  }
1791
1792
  // silence VC++ warning C4355: 'this' : used in base member initializer list
1793
11.9M
  Type *this_() { return this; }
1794
1795
4.28M
  void setDependent(bool D = true) {
1796
4.28M
    TypeBits.Dependent = D;
1797
4.28M
    if (D)
1798
4.24M
      TypeBits.InstantiationDependent = true;
1799
4.28M
  }
1800
1801
7.43M
  void setInstantiationDependent(bool D = true) {
1802
7.43M
    TypeBits.InstantiationDependent = D; }
1803
1804
0
  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
1805
1806
58.8k
  void setContainsUnexpandedParameterPack(bool PP = true) {
1807
58.8k
    TypeBits.ContainsUnexpandedParameterPack = PP;
1808
58.8k
  }
1809
1810
public:
1811
  friend class ASTReader;
1812
  friend class ASTWriter;
1813
1814
  Type(const Type &) = delete;
1815
  Type &operator=(const Type &) = delete;
1816
1817
7.50G
  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
1818
1819
  /// Whether this type comes from an AST file.
1820
996
  bool isFromAST() const { return TypeBits.FromAST; }
1821
1822
  /// Whether this type is or contains an unexpanded parameter
1823
  /// pack, used to support C++0x variadic templates.
1824
  ///
1825
  /// A type that contains a parameter pack shall be expanded by the
1826
  /// ellipsis operator at some point. For example, the typedef in the
1827
  /// following example contains an unexpanded parameter pack 'T':
1828
  ///
1829
  /// \code
1830
  /// template<typename ...T>
1831
  /// struct X {
1832
  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1833
  /// };
1834
  /// \endcode
1835
  ///
1836
  /// Note that this routine does not specify which
1837
74.7M
  bool containsUnexpandedParameterPack() const {
1838
74.7M
    return TypeBits.ContainsUnexpandedParameterPack;
1839
74.7M
  }
1840
1841
  /// Determines if this type would be canonical if it had no further
1842
  /// qualification.
1843
85.1M
  bool isCanonicalUnqualified() const {
1844
85.1M
    return CanonicalType == QualType(this, 0);
1845
85.1M
  }
1846
1847
  /// Pull a single level of sugar off of this locally-unqualified type.
1848
  /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
1849
  /// or QualType::getSingleStepDesugaredType(const ASTContext&).
1850
  QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
1851
1852
  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
1853
  /// object types, function types, and incomplete types.
1854
1855
  /// Return true if this is an incomplete type.
1856
  /// A type that can describe objects, but which lacks information needed to
1857
  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
1858
  /// routine will need to determine if the size is actually required.
1859
  ///
1860
  /// Def If non-null, and the type refers to some kind of declaration
1861
  /// that can be completed (such as a C struct, C++ class, or Objective-C
1862
  /// class), will be set to the declaration.
1863
  bool isIncompleteType(NamedDecl **Def = nullptr) const;
1864
1865
  /// Return true if this is an incomplete or object
1866
  /// type, in other words, not a function type.
1867
573k
  bool isIncompleteOrObjectType() const {
1868
573k
    return !isFunctionType();
1869
573k
  }
1870
1871
  /// Determine whether this type is an object type.
1872
455k
  bool isObjectType() const {
1873
455k
    // C++ [basic.types]p8:
1874
455k
    //   An object type is a (possibly cv-qualified) type that is not a
1875
455k
    //   function type, not a reference type, and not a void type.
1876
455k
    return !isReferenceType() && 
!isFunctionType()441k
&&
!isVoidType()294k
;
1877
455k
  }
1878
1879
  /// Return true if this is a literal type
1880
  /// (C++11 [basic.types]p10)
1881
  bool isLiteralType(const ASTContext &Ctx) const;
1882
1883
  /// Test if this type is a standard-layout type.
1884
  /// (C++0x [basic.type]p9)
1885
  bool isStandardLayoutType() const;
1886
1887
  /// Helper methods to distinguish type categories. All type predicates
1888
  /// operate on the canonical type, ignoring typedefs and qualifiers.
1889
1890
  /// Returns true if the type is a builtin type.
1891
  bool isBuiltinType() const;
1892
1893
  /// Test for a particular builtin type.
1894
  bool isSpecificBuiltinType(unsigned K) const;
1895
1896
  /// Test for a type which does not represent an actual type-system type but
1897
  /// is instead used as a placeholder for various convenient purposes within
1898
  /// Clang.  All such types are BuiltinTypes.
1899
  bool isPlaceholderType() const;
1900
  const BuiltinType *getAsPlaceholderType() const;
1901
1902
  /// Test for a specific placeholder type.
1903
  bool isSpecificPlaceholderType(unsigned K) const;
1904
1905
  /// Test for a placeholder type other than Overload; see
1906
  /// BuiltinType::isNonOverloadPlaceholderType.
1907
  bool isNonOverloadPlaceholderType() const;
1908
1909
  /// isIntegerType() does *not* include complex integers (a GCC extension).
1910
  /// isComplexIntegerType() can be used to test for complex integers.
1911
  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
1912
  bool isEnumeralType() const;
1913
1914
  /// Determine whether this type is a scoped enumeration type.
1915
  bool isScopedEnumeralType() const;
1916
  bool isBooleanType() const;
1917
  bool isCharType() const;
1918
  bool isWideCharType() const;
1919
  bool isChar8Type() const;
1920
  bool isChar16Type() const;
1921
  bool isChar32Type() const;
1922
  bool isAnyCharacterType() const;
1923
  bool isIntegralType(const ASTContext &Ctx) const;
1924
1925
  /// Determine whether this type is an integral or enumeration type.
1926
  bool isIntegralOrEnumerationType() const;
1927
1928
  /// Determine whether this type is an integral or unscoped enumeration type.
1929
  bool isIntegralOrUnscopedEnumerationType() const;
1930
1931
  /// Floating point categories.
1932
  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
1933
  /// isComplexType() does *not* include complex integers (a GCC extension).
1934
  /// isComplexIntegerType() can be used to test for complex integers.
1935
  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1936
  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
1937
  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
1938
  bool isHalfType() const;         // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
1939
  bool isFloat16Type() const;      // C11 extension ISO/IEC TS 18661
1940
  bool isFloat128Type() const;
1941
  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
1942
  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1943
  bool isVoidType() const;         // C99 6.2.5p19
1944
  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1945
  bool isAggregateType() const;
1946
  bool isFundamentalType() const;
1947
  bool isCompoundType() const;
1948
1949
  // Type Predicates: Check to see if this type is structurally the specified
1950
  // type, ignoring typedefs and qualifiers.
1951
  bool isFunctionType() const;
1952
  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1953
30.2M
  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1954
  bool isPointerType() const;
1955
  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
1956
  bool isBlockPointerType() const;
1957
  bool isVoidPointerType() const;
1958
  bool isReferenceType() const;
1959
  bool isLValueReferenceType() const;
1960
  bool isRValueReferenceType() const;
1961
  bool isFunctionPointerType() const;
1962
  bool isMemberPointerType() const;
1963
  bool isMemberFunctionPointerType() const;
1964
  bool isMemberDataPointerType() const;
1965
  bool isArrayType() const;
1966
  bool isConstantArrayType() const;
1967
  bool isIncompleteArrayType() const;
1968
  bool isVariableArrayType() const;
1969
  bool isDependentSizedArrayType() const;
1970
  bool isRecordType() const;
1971
  bool isClassType() const;
1972
  bool isStructureType() const;
1973
  bool isObjCBoxableRecordType() const;
1974
  bool isInterfaceType() const;
1975
  bool isStructureOrClassType() const;
1976
  bool isUnionType() const;
1977
  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1978
  bool isVectorType() const;                    // GCC vector type.
1979
  bool isExtVectorType() const;                 // Extended vector type.
1980
  bool isDependentAddressSpaceType() const;     // value-dependent address space qualifier
1981
  bool isObjCObjectPointerType() const;         // pointer to ObjC object
1982
  bool isObjCRetainableType() const;            // ObjC object or block pointer
1983
  bool isObjCLifetimeType() const;              // (array of)* retainable type
1984
  bool isObjCIndirectLifetimeType() const;      // (pointer to)* lifetime type
1985
  bool isObjCNSObjectType() const;              // __attribute__((NSObject))
1986
  bool isObjCIndependentClassType() const;      // __attribute__((objc_independent_class))
1987
  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
1988
  // for the common case.
1989
  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1990
  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1991
  bool isObjCQualifiedIdType() const;           // id<foo>
1992
  bool isObjCQualifiedClassType() const;        // Class<foo>
1993
  bool isObjCObjectOrInterfaceType() const;
1994
  bool isObjCIdType() const;                    // id
1995
1996
  /// Was this type written with the special inert-in-ARC __unsafe_unretained
1997
  /// qualifier?
1998
  ///
1999
  /// This approximates the answer to the following question: if this
2000
  /// translation unit were compiled in ARC, would this type be qualified
2001
  /// with __unsafe_unretained?
2002
319
  bool isObjCInertUnsafeUnretainedType() const {
2003
319
    return hasAttr(attr::ObjCInertUnsafeUnretained);
2004
319
  }
2005
2006
  /// Whether the type is Objective-C 'id' or a __kindof type of an
2007
  /// object type, e.g., __kindof NSView * or __kindof id
2008
  /// <NSCopying>.
2009
  ///
2010
  /// \param bound Will be set to the bound on non-id subtype types,
2011
  /// which will be (possibly specialized) Objective-C class type, or
2012
  /// null for 'id.
2013
  bool isObjCIdOrObjectKindOfType(const ASTContext &ctx,
2014
                                  const ObjCObjectType *&bound) const;
2015
2016
  bool isObjCClassType() const;                 // Class
2017
2018
  /// Whether the type is Objective-C 'Class' or a __kindof type of an
2019
  /// Class type, e.g., __kindof Class <NSCopying>.
2020
  ///
2021
  /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound
2022
  /// here because Objective-C's type system cannot express "a class
2023
  /// object for a subclass of NSFoo".
2024
  bool isObjCClassOrClassKindOfType() const;
2025
2026
  bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const;
2027
  bool isObjCSelType() const;                 // Class
2028
  bool isObjCBuiltinType() const;               // 'id' or 'Class'
2029
  bool isObjCARCBridgableType() const;
2030
  bool isCARCBridgableType() const;
2031
  bool isTemplateTypeParmType() const;          // C++ template type parameter
2032
  bool isNullPtrType() const;                   // C++11 std::nullptr_t
2033
  bool isAlignValT() const;                     // C++17 std::align_val_t
2034
  bool isStdByteType() const;                   // C++17 std::byte
2035
  bool isAtomicType() const;                    // C11 _Atomic()
2036
2037
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2038
  bool is##Id##Type() const;
2039
#include "clang/Basic/OpenCLImageTypes.def"
2040
2041
  bool isImageType() const;                     // Any OpenCL image type
2042
2043
  bool isSamplerT() const;                      // OpenCL sampler_t
2044
  bool isEventT() const;                        // OpenCL event_t
2045
  bool isClkEventT() const;                     // OpenCL clk_event_t
2046
  bool isQueueT() const;                        // OpenCL queue_t
2047
  bool isReserveIDT() const;                    // OpenCL reserve_id_t
2048
2049
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2050
  bool is##Id##Type() const;
2051
#include "clang/Basic/OpenCLExtensionTypes.def"
2052
  // Type defined in cl_intel_device_side_avc_motion_estimation OpenCL extension
2053
  bool isOCLIntelSubgroupAVCType() const;
2054
  bool isOCLExtOpaqueType() const;              // Any OpenCL extension type
2055
2056
  bool isPipeType() const;                      // OpenCL pipe type
2057
  bool isOpenCLSpecificType() const;            // Any OpenCL specific type
2058
2059
  /// Determines if this type, which must satisfy
2060
  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
2061
  /// than implicitly __strong.
2062
  bool isObjCARCImplicitlyUnretainedType() const;
2063
2064
  /// Return the implicit lifetime for this type, which must not be dependent.
2065
  Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
2066
2067
  enum ScalarTypeKind {
2068
    STK_CPointer,
2069
    STK_BlockPointer,
2070
    STK_ObjCObjectPointer,
2071
    STK_MemberPointer,
2072
    STK_Bool,
2073
    STK_Integral,
2074
    STK_Floating,
2075
    STK_IntegralComplex,
2076
    STK_FloatingComplex,
2077
    STK_FixedPoint
2078
  };
2079
2080
  /// Given that this is a scalar type, classify it.
2081
  ScalarTypeKind getScalarTypeKind() const;
2082
2083
  /// Whether this type is a dependent type, meaning that its definition
2084
  /// somehow depends on a template parameter (C++ [temp.dep.type]).
2085
326M
  bool isDependentType() const { return TypeBits.Dependent; }
2086
2087
  /// Determine whether this type is an instantiation-dependent type,
2088
  /// meaning that the type involves a template parameter (even if the
2089
  /// definition does not actually depend on the type substituted for that
2090
  /// template parameter).
2091
135M
  bool isInstantiationDependentType() const {
2092
135M
    return TypeBits.InstantiationDependent;
2093
135M
  }
2094
2095
  /// Determine whether this type is an undeduced type, meaning that
2096
  /// it somehow involves a C++11 'auto' type or similar which has not yet been
2097
  /// deduced.
2098
  bool isUndeducedType() const;
2099
2100
  /// Whether this type is a variably-modified type (C99 6.7.5).
2101
94.1M
  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
2102
2103
  /// Whether this type involves a variable-length array type
2104
  /// with a definite size.
2105
  bool hasSizedVLAType() const;
2106
2107
  /// Whether this type is or contains a local or unnamed type.
2108
  bool hasUnnamedOrLocalType() const;
2109
2110
  bool isOverloadableType() const;
2111
2112
  /// Determine wither this type is a C++ elaborated-type-specifier.
2113
  bool isElaboratedTypeSpecifier() const;
2114
2115
  bool canDecayToPointerType() const;
2116
2117
  /// Whether this type is represented natively as a pointer.  This includes
2118
  /// pointers, references, block pointers, and Objective-C interface,
2119
  /// qualified id, and qualified interface types, as well as nullptr_t.
2120
  bool hasPointerRepresentation() const;
2121
2122
  /// Whether this type can represent an objective pointer type for the
2123
  /// purpose of GC'ability
2124
  bool hasObjCPointerRepresentation() const;
2125
2126
  /// Determine whether this type has an integer representation
2127
  /// of some sort, e.g., it is an integer type or a vector.
2128
  bool hasIntegerRepresentation() const;
2129
2130
  /// Determine whether this type has an signed integer representation
2131
  /// of some sort, e.g., it is an signed integer type or a vector.
2132
  bool hasSignedIntegerRepresentation() const;
2133
2134
  /// Determine whether this type has an unsigned integer representation
2135
  /// of some sort, e.g., it is an unsigned integer type or a vector.
2136
  bool hasUnsignedIntegerRepresentation() const;
2137
2138
  /// Determine whether this type has a floating-point representation
2139
  /// of some sort, e.g., it is a floating-point type or a vector thereof.
2140
  bool hasFloatingRepresentation() const;
2141
2142
  // Type Checking Functions: Check to see if this type is structurally the
2143
  // specified type, ignoring typedefs and qualifiers, and return a pointer to
2144
  // the best type we can.
2145
  const RecordType *getAsStructureType() const;
2146
  /// NOTE: getAs*ArrayType are methods on ASTContext.
2147
  const RecordType *getAsUnionType() const;
2148
  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
2149
  const ObjCObjectType *getAsObjCInterfaceType() const;
2150
2151
  // The following is a convenience method that returns an ObjCObjectPointerType
2152
  // for object declared using an interface.
2153
  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
2154
  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
2155
  const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
2156
  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
2157
2158
  /// Retrieves the CXXRecordDecl that this type refers to, either
2159
  /// because the type is a RecordType or because it is the injected-class-name
2160
  /// type of a class template or class template partial specialization.
2161
  CXXRecordDecl *getAsCXXRecordDecl() const;
2162
2163
  /// Retrieves the RecordDecl this type refers to.
2164
  RecordDecl *getAsRecordDecl() const;
2165
2166
  /// Retrieves the TagDecl that this type refers to, either
2167
  /// because the type is a TagType or because it is the injected-class-name
2168
  /// type of a class template or class template partial specialization.
2169
  TagDecl *getAsTagDecl() const;
2170
2171
  /// If this is a pointer or reference to a RecordType, return the
2172
  /// CXXRecordDecl that the type refers to.
2173
  ///
2174
  /// If this is not a pointer or reference, or the type being pointed to does
2175
  /// not refer to a CXXRecordDecl, returns NULL.
2176
  const CXXRecordDecl *getPointeeCXXRecordDecl() const;
2177
2178
  /// Get the DeducedType whose type will be deduced for a variable with
2179
  /// an initializer of this type. This looks through declarators like pointer
2180
  /// types, but not through decltype or typedefs.
2181
  DeducedType *getContainedDeducedType() const;
2182
2183
  /// Get the AutoType whose type will be deduced for a variable with
2184
  /// an initializer of this type. This looks through declarators like pointer
2185
  /// types, but not through decltype or typedefs.
2186
995k
  AutoType *getContainedAutoType() const {
2187
995k
    return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2188
995k
  }
2189
2190
  /// Determine whether this type was written with a leading 'auto'
2191
  /// corresponding to a trailing return type (possibly for a nested
2192
  /// function type within a pointer to function type or similar).
2193
  bool hasAutoForTrailingReturnType() const;
2194
2195
  /// Member-template getAs<specific type>'.  Look through sugar for
2196
  /// an instance of \<specific type>.   This scheme will eventually
2197
  /// replace the specific getAsXXXX methods above.
2198
  ///
2199
  /// There are some specializations of this member template listed
2200
  /// immediately following this class.
2201
  template <typename T> const T *getAs() const;
2202
2203
  /// Member-template getAsAdjusted<specific type>. Look through specific kinds
2204
  /// of sugar (parens, attributes, etc) for an instance of \<specific type>.
2205
  /// This is used when you need to walk over sugar nodes that represent some
2206
  /// kind of type adjustment from a type that was written as a \<specific type>
2207
  /// to another type that is still canonically a \<specific type>.
2208
  template <typename T> const T *getAsAdjusted() const;
2209
2210
  /// A variant of getAs<> for array types which silently discards
2211
  /// qualifiers from the outermost type.
2212
  const ArrayType *getAsArrayTypeUnsafe() const;
2213
2214
  /// Member-template castAs<specific type>.  Look through sugar for
2215
  /// the underlying instance of \<specific type>.
2216
  ///
2217
  /// This method has the same relationship to getAs<T> as cast<T> has
2218
  /// to dyn_cast<T>; which is to say, the underlying type *must*
2219
  /// have the intended type, and this method will never return null.
2220
  template <typename T> const T *castAs() const;
2221
2222
  /// A variant of castAs<> for array type which silently discards
2223
  /// qualifiers from the outermost type.
2224
  const ArrayType *castAsArrayTypeUnsafe() const;
2225
2226
  /// Determine whether this type had the specified attribute applied to it
2227
  /// (looking through top-level type sugar).
2228
  bool hasAttr(attr::Kind AK) const;
2229
2230
  /// Get the base element type of this type, potentially discarding type
2231
  /// qualifiers.  This should never be used when type qualifiers
2232
  /// are meaningful.
2233
  const Type *getBaseElementTypeUnsafe() const;
2234
2235
  /// If this is an array type, return the element type of the array,
2236
  /// potentially with type qualifiers missing.
2237
  /// This should never be used when type qualifiers are meaningful.
2238
  const Type *getArrayElementTypeNoTypeQual() const;
2239
2240
  /// If this is a pointer type, return the pointee type.
2241
  /// If this is an array type, return the array element type.
2242
  /// This should never be used when type qualifiers are meaningful.
2243
  const Type *getPointeeOrArrayElementType() const;
2244
2245
  /// If this is a pointer, ObjC object pointer, or block
2246
  /// pointer, this returns the respective pointee.
2247
  QualType getPointeeType() const;
2248
2249
  /// Return the specified type with any "sugar" removed from the type,
2250
  /// removing any typedefs, typeofs, etc., as well as any qualifiers.
2251
  const Type *getUnqualifiedDesugaredType() const;
2252
2253
  /// More type predicates useful for type checking/promotion
2254
  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
2255
2256
  /// Return true if this is an integer type that is
2257
  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2258
  /// or an enum decl which has a signed representation.
2259
  bool isSignedIntegerType() const;
2260
2261
  /// Return true if this is an integer type that is
2262
  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
2263
  /// or an enum decl which has an unsigned representation.
2264
  bool isUnsignedIntegerType() const;
2265
2266
  /// Determines whether this is an integer type that is signed or an
2267
  /// enumeration types whose underlying type is a signed integer type.
2268
  bool isSignedIntegerOrEnumerationType() const;
2269
2270
  /// Determines whether this is an integer type that is unsigned or an
2271
  /// enumeration types whose underlying type is a unsigned integer type.
2272
  bool isUnsignedIntegerOrEnumerationType() const;
2273
2274
  /// Return true if this is a fixed point type according to
2275
  /// ISO/IEC JTC1 SC22 WG14 N1169.
2276
  bool isFixedPointType() const;
2277
2278
  /// Return true if this is a saturated fixed point type according to
2279
  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2280
  bool isSaturatedFixedPointType() const;
2281
2282
  /// Return true if this is a saturated fixed point type according to
2283
  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2284
  bool isUnsaturatedFixedPointType() const;
2285
2286
  /// Return true if this is a fixed point type that is signed according
2287
  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2288
  bool isSignedFixedPointType() const;
2289
2290
  /// Return true if this is a fixed point type that is unsigned according
2291
  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2292
  bool isUnsignedFixedPointType() const;
2293
2294
  /// Return true if this is not a variable sized type,
2295
  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
2296
  /// incomplete types.
2297
  bool isConstantSizeType() const;
2298
2299
  /// Returns true if this type can be represented by some
2300
  /// set of type specifiers.
2301
  bool isSpecifierType() const;
2302
2303
  /// Determine the linkage of this type.
2304
  Linkage getLinkage() const;
2305
2306
  /// Determine the visibility of this type.
2307
4.83k
  Visibility getVisibility() const {
2308
4.83k
    return getLinkageAndVisibility().getVisibility();
2309
4.83k
  }
2310
2311
  /// Return true if the visibility was explicitly set is the code.
2312
  bool isVisibilityExplicit() const {
2313
    return getLinkageAndVisibility().isVisibilityExplicit();
2314
  }
2315
2316
  /// Determine the linkage and visibility of this type.
2317
  LinkageInfo getLinkageAndVisibility() const;
2318
2319
  /// True if the computed linkage is valid. Used for consistency
2320
  /// checking. Should always return true.
2321
  bool isLinkageValid() const;
2322
2323
  /// Determine the nullability of the given type.
2324
  ///
2325
  /// Note that nullability is only captured as sugar within the type
2326
  /// system, not as part of the canonical type, so nullability will
2327
  /// be lost by canonicalization and desugaring.
2328
  Optional<NullabilityKind> getNullability(const ASTContext &context) const;
2329
2330
  /// Determine whether the given type can have a nullability
2331
  /// specifier applied to it, i.e., if it is any kind of pointer type.
2332
  ///
2333
  /// \param ResultIfUnknown The value to return if we don't yet know whether
2334
  ///        this type can have nullability because it is dependent.
2335
  bool canHaveNullability(bool ResultIfUnknown = true) const;
2336
2337
  /// Retrieve the set of substitutions required when accessing a member
2338
  /// of the Objective-C receiver type that is declared in the given context.
2339
  ///
2340
  /// \c *this is the type of the object we're operating on, e.g., the
2341
  /// receiver for a message send or the base of a property access, and is
2342
  /// expected to be of some object or object pointer type.
2343
  ///
2344
  /// \param dc The declaration context for which we are building up a
2345
  /// substitution mapping, which should be an Objective-C class, extension,
2346
  /// category, or method within.
2347
  ///
2348
  /// \returns an array of type arguments that can be substituted for
2349
  /// the type parameters of the given declaration context in any type described
2350
  /// within that context, or an empty optional to indicate that no
2351
  /// substitution is required.
2352
  Optional<ArrayRef<QualType>>
2353
  getObjCSubstitutions(const DeclContext *dc) const;
2354
2355
  /// Determines if this is an ObjC interface type that may accept type
2356
  /// parameters.
2357
  bool acceptsObjCTypeParams() const;
2358
2359
  const char *getTypeClassName() const;
2360
2361
390M
  QualType getCanonicalTypeInternal() const {
2362
390M
    return CanonicalType;
2363
390M
  }
2364
2365
  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
2366
  void dump() const;
2367
  void dump(llvm::raw_ostream &OS) const;
2368
};
2369
2370
/// This will check for a TypedefType by removing any existing sugar
2371
/// until it reaches a TypedefType or a non-sugared type.
2372
template <> const TypedefType *Type::getAs() const;
2373
2374
/// This will check for a TemplateSpecializationType by removing any
2375
/// existing sugar until it reaches a TemplateSpecializationType or a
2376
/// non-sugared type.
2377
template <> const TemplateSpecializationType *Type::getAs() const;
2378
2379
/// This will check for an AttributedType by removing any existing sugar
2380
/// until it reaches an AttributedType or a non-sugared type.
2381
template <> const AttributedType *Type::getAs() const;
2382
2383
// We can do canonical leaf types faster, because we don't have to
2384
// worry about preserving child type decoration.
2385
#define TYPE(Class, Base)
2386
#define LEAF_TYPE(Class) \
2387
662M
template <> inline const Class##Type *Type::getAs() const { \
2388
662M
  return dyn_cast<Class##Type>(CanonicalType); \
2389
662M
} \
clang::RecordType const* clang::Type::getAs<clang::RecordType>() const
Line
Count
Source
2387
60.8M
template <> inline const Class##Type *Type::getAs() const { \
2388
60.8M
  return dyn_cast<Class##Type>(CanonicalType); \
2389
60.8M
} \
clang::EnumType const* clang::Type::getAs<clang::EnumType>() const
Line
Count
Source
2387
76.5M
template <> inline const Class##Type *Type::getAs() const { \
2388
76.5M
  return dyn_cast<Class##Type>(CanonicalType); \
2389
76.5M
} \
clang::BuiltinType const* clang::Type::getAs<clang::BuiltinType>() const
Line
Count
Source
2387
443M
template <> inline const Class##Type *Type::getAs() const { \
2388
443M
  return dyn_cast<Class##Type>(CanonicalType); \
2389
443M
} \
clang::InjectedClassNameType const* clang::Type::getAs<clang::InjectedClassNameType>() const
Line
Count
Source
2387
31.9M
template <> inline const Class##Type *Type::getAs() const { \
2388
31.9M
  return dyn_cast<Class##Type>(CanonicalType); \
2389
31.9M
} \
clang::ObjCInterfaceType const* clang::Type::getAs<clang::ObjCInterfaceType>() const
Line
Count
Source
2387
15.6M
template <> inline const Class##Type *Type::getAs() const { \
2388
15.6M
  return dyn_cast<Class##Type>(CanonicalType); \
2389
15.6M
} \
clang::TemplateTypeParmType const* clang::Type::getAs<clang::TemplateTypeParmType>() const
Line
Count
Source
2387
33.6M
template <> inline const Class##Type *Type::getAs() const { \
2388
33.6M
  return dyn_cast<Class##Type>(CanonicalType); \
2389
33.6M
} \
2390
118M
template <> inline const Class##Type *Type::castAs() const { \
2391
118M
  return cast<Class##Type>(CanonicalType); \
2392
118M
}
clang::EnumType const* clang::Type::castAs<clang::EnumType>() const
Line
Count
Source
2390
9
template <> inline const Class##Type *Type::castAs() const { \
2391
9
  return cast<Class##Type>(CanonicalType); \
2392
9
}
clang::BuiltinType const* clang::Type::castAs<clang::BuiltinType>() const
Line
Count
Source
2390
359k
template <> inline const Class##Type *Type::castAs() const { \
2391
359k
  return cast<Class##Type>(CanonicalType); \
2392
359k
}
clang::RecordType const* clang::Type::castAs<clang::RecordType>() const
Line
Count
Source
2390
7.03M
template <> inline const Class##Type *Type::castAs() const { \
2391
7.03M
  return cast<Class##Type>(CanonicalType); \
2392
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
2390
10.0k
template <> inline const Class##Type *Type::castAs() const { \
2391
10.0k
  return cast<Class##Type>(CanonicalType); \
2392
10.0k
}
clang::TemplateTypeParmType const* clang::Type::castAs<clang::TemplateTypeParmType>() const
Line
Count
Source
2390
110M
template <> inline const Class##Type *Type::castAs() const { \
2391
110M
  return cast<Class##Type>(CanonicalType); \
2392
110M
}
2393
#include "clang/AST/TypeNodes.def"
2394
2395
/// This class is used for builtin types like 'int'.  Builtin
2396
/// types are always canonical and have a literal name field.
2397
class BuiltinType : public Type {
2398
public:
2399
  enum Kind {
2400
// OpenCL image types
2401
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2402
#include "clang/Basic/OpenCLImageTypes.def"
2403
// OpenCL extension types
2404
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id,
2405
#include "clang/Basic/OpenCLExtensionTypes.def"
2406
// All other builtin types
2407
#define BUILTIN_TYPE(Id, SingletonId) Id,
2408
#define LAST_BUILTIN_TYPE(Id) LastKind = Id
2409
#include "clang/AST/BuiltinTypes.def"
2410
  };
2411
2412
private:
2413
  friend class ASTContext; // ASTContext creates these.
2414
2415
  BuiltinType(Kind K)
2416
      : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
2417
             /*InstantiationDependent=*/(K == Dependent),
2418
             /*VariablyModified=*/false,
2419
2.28M
             /*Unexpanded parameter pack=*/false) {
2420
2.28M
    BuiltinTypeBits.Kind = K;
2421
2.28M
  }
2422
2423
public:
2424
968M
  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
2425
  StringRef getName(const PrintingPolicy &Policy) const;
2426
2427
2.81k
  const char *getNameAsCString(const PrintingPolicy &Policy) const {
2428
2.81k
    // The StringRef is null-terminated.
2429
2.81k
    StringRef str = getName(Policy);
2430
2.81k
    assert(!str.empty() && str.data()[str.size()] == '\0');
2431
2.81k
    return str.data();
2432
2.81k
  }
2433
2434
41.6M
  bool isSugared() const { return false; }
2435
0
  QualType desugar() const { return QualType(this, 0); }
2436
2437
1.56M
  bool isInteger() const {
2438
1.56M
    return getKind() >= Bool && getKind() <= Int128;
2439
1.56M
  }
2440
2441
  bool isSignedInteger() const {
2442
    return getKind() >= Char_S && getKind() <= Int128;
2443
  }
2444
2445
2.80M
  bool isUnsignedInteger() const {
2446
2.80M
    return getKind() >= Bool && getKind() <= UInt128;
2447
2.80M
  }
2448
2449
12.6M
  bool isFloatingPoint() const {
2450
12.6M
    return getKind() >= Half && 
getKind() <= Float1286.92M
;
2451
12.6M
  }
2452
2453
  /// Determines whether the given kind corresponds to a placeholder type.
2454
47.1M
  static bool isPlaceholderTypeKind(Kind K) {
2455
47.1M
    return K >= Overload;
2456
47.1M
  }
2457
2458
  /// Determines whether this type is a placeholder type, i.e. a type
2459
  /// which cannot appear in arbitrary positions in a fully-formed
2460
  /// expression.
2461
47.1M
  bool isPlaceholderType() const {
2462
47.1M
    return isPlaceholderTypeKind(getKind());
2463
47.1M
  }
2464
2465
  /// Determines whether this type is a placeholder type other than
2466
  /// Overload.  Most placeholder types require only syntactic
2467
  /// information about their context in order to be resolved (e.g.
2468
  /// whether it is a call expression), which means they can (and
2469
  /// should) be resolved in an earlier "phase" of analysis.
2470
  /// Overload expressions sometimes pick up further information
2471
  /// from their context, like whether the context expects a
2472
  /// specific function-pointer type, and so frequently need
2473
  /// special treatment.
2474
7.22M
  bool isNonOverloadPlaceholderType() const {
2475
7.22M
    return getKind() > Overload;
2476
7.22M
  }
2477
2478
1.10G
  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
2479
};
2480
2481
/// Complex values, per C99 6.2.5p11.  This supports the C99 complex
2482
/// types (_Complex float etc) as well as the GCC integer complex extensions.
2483
class ComplexType : public Type, public llvm::FoldingSetNode {
2484
  friend class ASTContext; // ASTContext creates these.
2485
2486
  QualType ElementType;
2487
2488
  ComplexType(QualType Element, QualType CanonicalPtr)
2489
      : Type(Complex, CanonicalPtr, Element->isDependentType(),
2490
             Element->isInstantiationDependentType(),
2491
             Element->isVariablyModifiedType(),
2492
             Element->containsUnexpandedParameterPack()),
2493
152k
        ElementType(Element) {}
2494
2495
public:
2496
46.2k
  QualType getElementType() const { return ElementType; }
2497
2498
10.2k
  bool isSugared() const { return false; }
2499
0
  QualType desugar() const { return QualType(this, 0); }
2500
2501
19.8k
  void Profile(llvm::FoldingSetNodeID &ID) {
2502
19.8k
    Profile(ID, getElementType());
2503
19.8k
  }
2504
2505
188k
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
2506
188k
    ID.AddPointer(Element.getAsOpaquePtr());
2507
188k
  }
2508
2509
100M
  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
2510
};
2511
2512
/// Sugar for parentheses used when specifying types.
2513
class ParenType : public Type, public llvm::FoldingSetNode {
2514
  friend class ASTContext; // ASTContext creates these.
2515
2516
  QualType Inner;
2517
2518
  ParenType(QualType InnerType, QualType CanonType)
2519
      : Type(Paren, CanonType, InnerType->isDependentType(),
2520
             InnerType->isInstantiationDependentType(),
2521
             InnerType->isVariablyModifiedType(),
2522
             InnerType->containsUnexpandedParameterPack()),
2523
132k
        Inner(InnerType) {}
2524
2525
public:
2526
1.85M
  QualType getInnerType() const { return Inner; }
2527
2528
366k
  bool isSugared() const { return true; }
2529
367k
  QualType desugar() const { return getInnerType(); }
2530
2531
273k
  void Profile(llvm::FoldingSetNodeID &ID) {
2532
273k
    Profile(ID, getInnerType());
2533
273k
  }
2534
2535
502k
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
2536
502k
    Inner.Profile(ID);
2537
502k
  }
2538
2539
11.3M
  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
2540
};
2541
2542
/// PointerType - C99 6.7.5.1 - Pointer Declarators.
2543
class PointerType : public Type, public llvm::FoldingSetNode {
2544
  friend class ASTContext; // ASTContext creates these.
2545
2546
  QualType PointeeType;
2547
2548
  PointerType(QualType Pointee, QualType CanonicalPtr)
2549
      : Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
2550
             Pointee->isInstantiationDependentType(),
2551
             Pointee->isVariablyModifiedType(),
2552
             Pointee->containsUnexpandedParameterPack()),
2553
3.05M
        PointeeType(Pointee) {}
2554
2555
public:
2556
103M
  QualType getPointeeType() const { return PointeeType; }
2557
2558
  /// Returns true if address spaces of pointers overlap.
2559
  /// OpenCL v2.0 defines conversion rules for pointers to different
2560
  /// address spaces (OpenCLC v2.0 s6.5.5) and notion of overlapping
2561
  /// address spaces.
2562
  /// CL1.1 or CL1.2:
2563
  ///   address spaces overlap iff they are they same.
2564
  /// CL2.0 adds:
2565
  ///   __generic overlaps with any address space except for __constant.
2566
410
  bool isAddressSpaceOverlapping(const PointerType &other) const {
2567
410
    Qualifiers thisQuals = PointeeType.getQualifiers();
2568
410
    Qualifiers otherQuals = other.getPointeeType().getQualifiers();
2569
410
    // Address spaces overlap if at least one of them is a superset of another
2570
410
    return thisQuals.isAddressSpaceSupersetOf(otherQuals) ||
2571
410
           
otherQuals.isAddressSpaceSupersetOf(thisQuals)206
;
2572
410
  }
2573
2574
12.0M
  bool isSugared() const { return false; }
2575
0
  QualType desugar() const { return QualType(this, 0); }
2576
2577
39.6M
  void Profile(llvm::FoldingSetNodeID &ID) {
2578
39.6M
    Profile(ID, getPointeeType());
2579
39.6M
  }
2580
2581
65.5M
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2582
65.5M
    ID.AddPointer(Pointee.getAsOpaquePtr());
2583
65.5M
  }
2584
2585
197M
  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
2586
};
2587
2588
/// Represents a type which was implicitly adjusted by the semantic
2589
/// engine for arbitrary reasons.  For example, array and function types can
2590
/// decay, and function types can have their calling conventions adjusted.
2591
class AdjustedType : public Type, public llvm::FoldingSetNode {
2592
  QualType OriginalTy;
2593
  QualType AdjustedTy;
2594
2595
protected:
2596
  friend class ASTContext; // ASTContext creates these.
2597
2598
  AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
2599
               QualType CanonicalPtr)
2600
      : Type(TC, CanonicalPtr, OriginalTy->isDependentType(),
2601
             OriginalTy->isInstantiationDependentType(),
2602
             OriginalTy->isVariablyModifiedType(),
2603
             OriginalTy->containsUnexpandedParameterPack()),
2604
19.6k
        OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2605
2606
public:
2607
5.03k
  QualType getOriginalType() const { return OriginalTy; }
2608
2.20k
  QualType getAdjustedType() const { return AdjustedTy; }
2609
2610
100k
  bool isSugared() const { return true; }
2611
100k
  QualType desugar() const { return AdjustedTy; }
2612
2613
33.2k
  void Profile(llvm::FoldingSetNodeID &ID) {
2614
33.2k
    Profile(ID, OriginalTy, AdjustedTy);
2615
33.2k
  }
2616
2617
83.7k
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) {
2618
83.7k
    ID.AddPointer(Orig.getAsOpaquePtr());
2619
83.7k
    ID.AddPointer(New.getAsOpaquePtr());
2620
83.7k
  }
2621
2622
17.6M
  static bool classof(const Type *T) {
2623
17.6M
    return T->getTypeClass() == Adjusted || 
T->getTypeClass() == Decayed17.6M
;
2624
17.6M
  }
2625
};
2626
2627
/// Represents a pointer type decayed from an array or function type.
2628
class DecayedType : public AdjustedType {
2629
  friend class ASTContext; // ASTContext creates these.
2630
2631
  inline
2632
  DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical);
2633
2634
public:
2635
176
  QualType getDecayedType() const { return getAdjustedType(); }
2636
2637
  inline QualType getPointeeType() const;
2638
2639
8.18M
  static bool classof(const Type *T) { return T->getTypeClass() == Decayed; }
2640
};
2641
2642
/// Pointer to a block type.
2643
/// This type is to represent types syntactically represented as
2644
/// "void (^)(int)", etc. Pointee is required to always be a function type.
2645
class BlockPointerType : public Type, public llvm::FoldingSetNode {
2646
  friend class ASTContext; // ASTContext creates these.
2647
2648
  // Block is some kind of pointer type
2649
  QualType PointeeType;
2650
2651
  BlockPointerType(QualType Pointee, QualType CanonicalCls)
2652
      : Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
2653
             Pointee->isInstantiationDependentType(),
2654
             Pointee->isVariablyModifiedType(),
2655
             Pointee->containsUnexpandedParameterPack()),
2656
15.3k
        PointeeType(Pointee) {}
2657
2658
public:
2659
  // Get the pointee type. Pointee is required to always be a function type.
2660
121k
  QualType getPointeeType() const { return PointeeType; }
2661
2662
43.3k
  bool isSugared() const { return false; }
2663
0
  QualType desugar() const { return QualType(this, 0); }
2664
2665
20.6k
  void Profile(llvm::FoldingSetNodeID &ID) {
2666
20.6k
      Profile(ID, getPointeeType());
2667
20.6k
  }
2668
2669
49.3k
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2670
49.3k
      ID.AddPointer(Pointee.getAsOpaquePtr());
2671
49.3k
  }
2672
2673
76.7M
  static bool classof(const Type *T) {
2674
76.7M
    return T->getTypeClass() == BlockPointer;
2675
76.7M
  }
2676
};
2677
2678
/// Base for LValueReferenceType and RValueReferenceType
2679
class ReferenceType : public Type, public llvm::FoldingSetNode {
2680
  QualType PointeeType;
2681
2682
protected:
2683
  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
2684
                bool SpelledAsLValue)
2685
      : Type(tc, CanonicalRef, Referencee->isDependentType(),
2686
             Referencee->isInstantiationDependentType(),
2687
             Referencee->isVariablyModifiedType(),
2688
             Referencee->containsUnexpandedParameterPack()),
2689
1.94M
        PointeeType(Referencee) {
2690
1.94M
    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
2691
1.94M
    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
2692
1.94M
  }
2693
2694
public:
2695
18.7M
  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
2696
21.5M
  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
2697
2698
18.2M
  QualType getPointeeTypeAsWritten() const { return PointeeType; }
2699
2700
21.3M
  QualType getPointeeType() const {
2701
21.3M
    // FIXME: this might strip inner qualifiers; okay?
2702
21.3M
    const ReferenceType *T = this;
2703
21.5M
    while (T->isInnerRef())
2704
183k
      T = T->PointeeType->castAs<ReferenceType>();
2705
21.3M
    return T->PointeeType;
2706
21.3M
  }
2707
2708
17.6M
  void Profile(llvm::FoldingSetNodeID &ID) {
2709
17.6M
    Profile(ID, PointeeType, isSpelledAsLValue());
2710
17.6M
  }
2711
2712
  static void Profile(llvm::FoldingSetNodeID &ID,
2713
                      QualType Referencee,
2714
27.5M
                      bool SpelledAsLValue) {
2715
27.5M
    ID.AddPointer(Referencee.getAsOpaquePtr());
2716
27.5M
    ID.AddBoolean(SpelledAsLValue);
2717
27.5M
  }
2718
2719
333M
  static bool classof(const Type *T) {
2720
333M
    return T->getTypeClass() == LValueReference ||
2721
333M
           
T->getTypeClass() == RValueReference306M
;
2722
333M
  }
2723
};
2724
2725
/// An lvalue reference type, per C++11 [dcl.ref].
2726
class LValueReferenceType : public ReferenceType {
2727
  friend class ASTContext; // ASTContext creates these
2728
2729
  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
2730
                      bool SpelledAsLValue)
2731
      : ReferenceType(LValueReference, Referencee, CanonicalRef,
2732
1.49M
                      SpelledAsLValue) {}
2733
2734
public:
2735
2.05M
  bool isSugared() const { return false; }
2736
0
  QualType desugar() const { return QualType(this, 0); }
2737
2738
9.61M
  static bool classof(const Type *T) {
2739
9.61M
    return T->getTypeClass() == LValueReference;
2740
9.61M
  }
2741
};
2742
2743
/// An rvalue reference type, per C++11 [dcl.ref].
2744
class RValueReferenceType : public ReferenceType {
2745
  friend class ASTContext; // ASTContext creates these
2746
2747
  RValueReferenceType(QualType Referencee, QualType CanonicalRef)
2748
446k
       : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {}
2749
2750
public:
2751
330k
  bool isSugared() const { return false; }
2752
0
  QualType desugar() const { return QualType(this, 0); }
2753
2754
14.0M
  static bool classof(const Type *T) {
2755
14.0M
    return T->getTypeClass() == RValueReference;
2756
14.0M
  }
2757
};
2758
2759
/// A pointer to member type per C++ 8.3.3 - Pointers to members.
2760
///
2761
/// This includes both pointers to data members and pointer to member functions.
2762
class MemberPointerType : public Type, public llvm::FoldingSetNode {
2763
  friend class ASTContext; // ASTContext creates these.
2764
2765
  QualType PointeeType;
2766
2767
  /// The class of which the pointee is a member. Must ultimately be a
2768
  /// RecordType, but could be a typedef or a template parameter too.
2769
  const Type *Class;
2770
2771
  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
2772
      : Type(MemberPointer, CanonicalPtr,
2773
             Cls->isDependentType() || Pointee->isDependentType(),
2774
             (Cls->isInstantiationDependentType() ||
2775
              Pointee->isInstantiationDependentType()),
2776
             Pointee->isVariablyModifiedType(),
2777
             (Cls->containsUnexpandedParameterPack() ||
2778
              Pointee->containsUnexpandedParameterPack())),
2779
54.5k
             PointeeType(Pointee), Class(Cls) {}
2780
2781
public:
2782
646k
  QualType getPointeeType() const { return PointeeType; }
2783
2784
  /// Returns true if the member type (i.e. the pointee type) is a
2785
  /// function type rather than a data-member type.
2786
4.83k
  bool isMemberFunctionPointer() const {
2787
4.83k
    return PointeeType->isFunctionProtoType();
2788
4.83k
  }
2789
2790
  /// Returns true if the member type (i.e. the pointee type) is a
2791
  /// data type rather than a function type.
2792
984
  bool isMemberDataPointer() const {
2793
984
    return !PointeeType->isFunctionProtoType();
2794
984
  }
2795
2796
230k
  const Type *getClass() const { return Class; }
2797
  CXXRecordDecl *getMostRecentCXXRecordDecl() const;
2798
2799
35.8k
  bool isSugared() const { return false; }
2800
0
  QualType desugar() const { return QualType(this, 0); }
2801
2802
74.3k
  void Profile(llvm::FoldingSetNodeID &ID) {
2803
74.3k
    Profile(ID, getPointeeType(), getClass());
2804
74.3k
  }
2805
2806
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
2807
144k
                      const Type *Class) {
2808
144k
    ID.AddPointer(Pointee.getAsOpaquePtr());
2809
144k
    ID.AddPointer(Class);
2810
144k
  }
2811
2812
228M
  static bool classof(const Type *T) {
2813
228M
    return T->getTypeClass() == MemberPointer;
2814
228M
  }
2815
};
2816
2817
/// Represents an array type, per C99 6.7.5.2 - Array Declarators.
2818
class ArrayType : public Type, public llvm::FoldingSetNode {
2819
public:
2820
  /// Capture whether this is a normal array (e.g. int X[4])
2821
  /// an array with a static size (e.g. int X[static 4]), or an array
2822
  /// with a star size (e.g. int X[*]).
2823
  /// 'static' is only allowed on function parameters.
2824
  enum ArraySizeModifier {
2825
    Normal, Static, Star
2826
  };
2827
2828
private:
2829
  /// The element type of the array.
2830
  QualType ElementType;
2831
2832
protected:
2833
  friend class ASTContext; // ASTContext creates these.
2834
2835
  // C++ [temp.dep.type]p1:
2836
  //   A type is dependent if it is...
2837
  //     - an array type constructed from any dependent type or whose
2838
  //       size is specified by a constant expression that is
2839
  //       value-dependent,
2840
  ArrayType(TypeClass tc, QualType et, QualType can,
2841
            ArraySizeModifier sm, unsigned tq,
2842
            bool ContainsUnexpandedParameterPack)
2843
      : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2844
             et->isInstantiationDependentType() || tc == DependentSizedArray,
2845
             (tc == VariableArray || et->isVariablyModifiedType()),
2846
             ContainsUnexpandedParameterPack),
2847
608k
        ElementType(et) {
2848
608k
    ArrayTypeBits.IndexTypeQuals = tq;
2849
608k
    ArrayTypeBits.SizeModifier = sm;
2850
608k
  }
2851
2852
public:
2853
15.0M
  QualType getElementType() const { return ElementType; }
2854
2855
5.18M
  ArraySizeModifier getSizeModifier() const {
2856
5.18M
    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
2857
5.18M
  }
2858
2859
1.47M
  Qualifiers getIndexTypeQualifiers() const {
2860
1.47M
    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
2861
1.47M
  }
2862
2863
6.61M
  unsigned getIndexTypeCVRQualifiers() const {
2864
6.61M
    return ArrayTypeBits.IndexTypeQuals;
2865
6.61M
  }
2866
2867
349M
  static bool classof(const Type *T) {
2868
349M
    return T->getTypeClass() == ConstantArray ||
2869
349M
           
T->getTypeClass() == VariableArray341M
||
2870
349M
           
T->getTypeClass() == IncompleteArray341M
||
2871
349M
           
T->getTypeClass() == DependentSizedArray339M
;
2872
349M
  }
2873
};
2874
2875
/// Represents the canonical version of C arrays with a specified constant size.
2876
/// For example, the canonical type for 'int A[4 + 4*100]' is a
2877
/// ConstantArrayType where the element type is 'int' and the size is 404.
2878
class ConstantArrayType : public ArrayType {
2879
  llvm::APInt Size; // Allows us to unique the type.
2880
2881
  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
2882
                    ArraySizeModifier sm, unsigned tq)
2883
      : ArrayType(ConstantArray, et, can, sm, tq,
2884
                  et->containsUnexpandedParameterPack()),
2885
519k
        Size(size) {}
2886
2887
protected:
2888
  friend class ASTContext; // ASTContext creates these.
2889
2890
  ConstantArrayType(TypeClass tc, QualType et, QualType can,
2891
                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
2892
      : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2893
        Size(size) {}
2894
2895
public:
2896
6.62M
  const llvm::APInt &getSize() const { return Size; }
2897
3.84M
  bool isSugared() const { return false; }
2898
0
  QualType desugar() const { return QualType(this, 0); }
2899
2900
  /// Determine the number of bits required to address a member of
2901
  // an array with the given element type and number of elements.
2902
  static unsigned getNumAddressingBits(const ASTContext &Context,
2903
                                       QualType ElementType,
2904
                                       const llvm::APInt &NumElements);
2905
2906
  /// Determine the maximum number of active bits that an array's size
2907
  /// can require, which limits the maximum size of the array.
2908
  static unsigned getMaxSizeBits(const ASTContext &Context);
2909
2910
4.96M
  void Profile(llvm::FoldingSetNodeID &ID) {
2911
4.96M
    Profile(ID, getElementType(), getSize(),
2912
4.96M
            getSizeModifier(), getIndexTypeCVRQualifiers());
2913
4.96M
  }
2914
2915
  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2916
                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
2917
8.26M
                      unsigned TypeQuals) {
2918
8.26M
    ID.AddPointer(ET.getAsOpaquePtr());
2919
8.26M
    ID.AddInteger(ArraySize.getZExtValue());
2920
8.26M
    ID.AddInteger(SizeMod);
2921
8.26M
    ID.AddInteger(TypeQuals);
2922
8.26M
  }
2923
2924
9.94M
  static bool classof(const Type *T) {
2925
9.94M
    return T->getTypeClass() == ConstantArray;
2926
9.94M
  }
2927
};
2928
2929
/// Represents a C array with an unspecified size.  For example 'int A[]' has
2930
/// an IncompleteArrayType where the element type is 'int' and the size is
2931
/// unspecified.
2932
class IncompleteArrayType : public ArrayType {
2933
  friend class ASTContext; // ASTContext creates these.
2934
2935
  IncompleteArrayType(QualType et, QualType can,
2936
                      ArraySizeModifier sm, unsigned tq)
2937
      : ArrayType(IncompleteArray, et, can, sm, tq,
2938
39.2k
                  et->containsUnexpandedParameterPack()) {}
2939
2940
public:
2941
  friend class StmtIteratorBase;
2942
2943
74.1k
  bool isSugared() const { return false; }
2944
0
  QualType desugar() const { return QualType(this, 0); }
2945
2946
25.2M
  static bool classof(const Type *T) {
2947
25.2M
    return T->getTypeClass() == IncompleteArray;
2948
25.2M
  }
2949
2950
34.1k
  void Profile(llvm::FoldingSetNodeID &ID) {
2951
34.1k
    Profile(ID, getElementType(), getSizeModifier(),
2952
34.1k
            getIndexTypeCVRQualifiers());
2953
34.1k
  }
2954
2955
  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2956
100k
                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
2957
100k
    ID.AddPointer(ET.getAsOpaquePtr());
2958
100k
    ID.AddInteger(SizeMod);
2959
100k
    ID.AddInteger(TypeQuals);
2960
100k
  }
2961
};
2962
2963
/// Represents a C array with a specified size that is not an
2964
/// integer-constant-expression.  For example, 'int s[x+foo()]'.
2965
/// Since the size expression is an arbitrary expression, we store it as such.
2966
///
2967
/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2968
/// should not be: two lexically equivalent variable array types could mean
2969
/// different things, for example, these variables do not have the same type
2970
/// dynamically:
2971
///
2972
/// void foo(int x) {
2973
///   int Y[x];
2974
///   ++x;
2975
///   int Z[x];
2976
/// }
2977
class VariableArrayType : public ArrayType {
2978
  friend class ASTContext; // ASTContext creates these.
2979
2980
  /// An assignment-expression. VLA's are only permitted within
2981
  /// a function block.
2982
  Stmt *SizeExpr;
2983
2984
  /// The range spanned by the left and right array brackets.
2985
  SourceRange Brackets;
2986
2987
  VariableArrayType(QualType et, QualType can, Expr *e,
2988
                    ArraySizeModifier sm, unsigned tq,
2989
                    SourceRange brackets)
2990
      : ArrayType(VariableArray, et, can, sm, tq,
2991
                  et->containsUnexpandedParameterPack()),
2992
8.04k
        SizeExpr((Stmt*) e), Brackets(brackets) {}
2993
2994
public:
2995
  friend class StmtIteratorBase;
2996
2997
39.7k
  Expr *getSizeExpr() const {
2998
39.7k
    // We use C-style casts instead of cast<> here because we do not wish
2999
39.7k
    // to have a dependency of Type.h on Stmt.h/Expr.h.
3000
39.7k
    return (Expr*) SizeExpr;
3001
39.7k
  }
3002
3003
186
  SourceRange getBracketsRange() const { return Brackets; }
3004
973
  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3005
973
  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3006
3007
53.2k
  bool isSugared() const { return false; }
3008
33
  QualType desugar() const { return QualType(this, 0); }
3009
3010
26.2M
  static bool classof(const Type *T) {
3011
26.2M
    return T->getTypeClass() == VariableArray;
3012
26.2M
  }
3013
3014
  void Profile(llvm::FoldingSetNodeID &ID) {
3015
    llvm_unreachable("Cannot unique VariableArrayTypes.");
3016
  }
3017
};
3018
3019
/// Represents an array type in C++ whose size is a value-dependent expression.
3020
///
3021
/// For example:
3022
/// \code
3023
/// template<typename T, int Size>
3024
/// class array {
3025
///   T data[Size];
3026
/// };
3027
/// \endcode
3028
///
3029
/// For these types, we won't actually know what the array bound is
3030
/// until template instantiation occurs, at which point this will
3031
/// become either a ConstantArrayType or a VariableArrayType.
3032
class DependentSizedArrayType : public ArrayType {
3033
  friend class ASTContext; // ASTContext creates these.
3034
3035
  const ASTContext &Context;
3036
3037
  /// An assignment expression that will instantiate to the
3038
  /// size of the array.
3039
  ///
3040
  /// The expression itself might be null, in which case the array
3041
  /// type will have its size deduced from an initializer.
3042
  Stmt *SizeExpr;
3043
3044
  /// The range spanned by the left and right array brackets.
3045
  SourceRange Brackets;
3046
3047
  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
3048
                          Expr *e, ArraySizeModifier sm, unsigned tq,
3049
                          SourceRange brackets);
3050
3051
public:
3052
  friend class StmtIteratorBase;
3053
3054
51.9k
  Expr *getSizeExpr() const {
3055
51.9k
    // We use C-style casts instead of cast<> here because we do not wish
3056
51.9k
    // to have a dependency of Type.h on Stmt.h/Expr.h.
3057
51.9k
    return (Expr*) SizeExpr;
3058
51.9k
  }
3059
3060
717
  SourceRange getBracketsRange() const { return Brackets; }
3061
0
  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3062
0
  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3063
3064
71.7k
  bool isSugared() const { return false; }
3065
0
  QualType desugar() const { return QualType(this, 0); }
3066
3067
1.24k
  static bool classof(const Type *T) {
3068
1.24k
    return T->getTypeClass() == DependentSizedArray;
3069
1.24k
  }
3070
3071
12.7k
  void Profile(llvm::FoldingSetNodeID &ID) {
3072
12.7k
    Profile(ID, Context, getElementType(),
3073
12.7k
            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3074
12.7k
  }
3075
3076
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3077
                      QualType ET, ArraySizeModifier SizeMod,
3078
                      unsigned TypeQuals, Expr *E);
3079
};
3080
3081
/// Represents an extended address space qualifier where the input address space
3082
/// value is dependent. Non-dependent address spaces are not represented with a
3083
/// special Type subclass; they are stored on an ExtQuals node as part of a QualType.
3084
///
3085
/// For example:
3086
/// \code
3087
/// template<typename T, int AddrSpace>
3088
/// class AddressSpace {
3089
///   typedef T __attribute__((address_space(AddrSpace))) type;
3090
/// }
3091
/// \endcode
3092
class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
3093
  friend class ASTContext;
3094
3095
  const ASTContext &Context;
3096
  Expr *AddrSpaceExpr;
3097
  QualType PointeeType;
3098
  SourceLocation loc;
3099
3100
  DependentAddressSpaceType(const ASTContext &Context, QualType PointeeType,
3101
                            QualType can, Expr *AddrSpaceExpr,
3102
                            SourceLocation loc);
3103
3104
public:
3105
254
  Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; }
3106
684
  QualType getPointeeType() const { return PointeeType; }
3107
56
  SourceLocation getAttributeLoc() const { return loc; }
3108
3109
9
  bool isSugared() const { return false; }
3110
0
  QualType desugar() const { return QualType(this, 0); }
3111
3112
21.9M
  static bool classof(const Type *T) {
3113
21.9M
    return T->getTypeClass() == DependentAddressSpace;
3114
21.9M
  }
3115
3116
16
  void Profile(llvm::FoldingSetNodeID &ID) {
3117
16
    Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3118
16
  }
3119
3120
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3121
                      QualType PointeeType, Expr *AddrSpaceExpr);
3122
};
3123
3124
/// Represents an extended vector type where either the type or size is
3125
/// dependent.
3126
///
3127
/// For example:
3128
/// \code
3129
/// template<typename T, int Size>
3130
/// class vector {
3131
///   typedef T __attribute__((ext_vector_type(Size))) type;
3132
/// }
3133
/// \endcode
3134
class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
3135
  friend class ASTContext;
3136
3137
  const ASTContext &Context;
3138
  Expr *SizeExpr;
3139
3140
  /// The element type of the array.
3141
  QualType ElementType;
3142
3143
  SourceLocation loc;
3144
3145
  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
3146
                              QualType can, Expr *SizeExpr, SourceLocation loc);
3147
3148
public:
3149
54
  Expr *getSizeExpr() const { return SizeExpr; }
3150
103
  QualType getElementType() const { return ElementType; }
3151
23
  SourceLocation getAttributeLoc() const { return loc; }
3152
3153
0
  bool isSugared() const { return false; }
3154
0
  QualType desugar() const { return QualType(this, 0); }
3155
3156
22
  static bool classof(const Type *T) {
3157
22
    return T->getTypeClass() == DependentSizedExtVector;
3158
22
  }
3159
3160
8
  void Profile(llvm::FoldingSetNodeID &ID) {
3161
8
    Profile(ID, Context, getElementType(), getSizeExpr());
3162
8
  }
3163
3164
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3165
                      QualType ElementType, Expr *SizeExpr);
3166
};
3167
3168
3169
/// Represents a GCC generic vector type. This type is created using
3170
/// __attribute__((vector_size(n)), where "n" specifies the vector size in
3171
/// bytes; or from an Altivec __vector or vector declaration.
3172
/// Since the constructor takes the number of vector elements, the
3173
/// client is responsible for converting the size into the number of elements.
3174
class VectorType : public Type, public llvm::FoldingSetNode {
3175
public:
3176
  enum VectorKind {
3177
    /// not a target-specific vector type
3178
    GenericVector,
3179
3180
    /// is AltiVec vector
3181
    AltiVecVector,
3182
3183
    /// is AltiVec 'vector Pixel'
3184
    AltiVecPixel,
3185
3186
    /// is AltiVec 'vector bool ...'
3187
    AltiVecBool,
3188
3189
    /// is ARM Neon vector
3190
    NeonVector,
3191
3192
    /// is ARM Neon polynomial vector
3193
    NeonPolyVector
3194
  };
3195
3196
protected:
3197
  friend class ASTContext; // ASTContext creates these.
3198
3199
  /// The element type of the vector.
3200
  QualType ElementType;
3201
3202
  VectorType(QualType vecType, unsigned nElements, QualType canonType,
3203
             VectorKind vecKind);
3204
3205
  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
3206
             QualType canonType, VectorKind vecKind);
3207
3208
public:
3209
10.9M
  QualType getElementType() const { return ElementType; }
3210
11.9M
  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
3211
3212
11.7k
  static bool isVectorSizeTooLarge(unsigned NumElements) {
3213
11.7k
    return NumElements > VectorTypeBitfields::MaxNumElements;
3214
11.7k
  }
3215
3216
11.7M
  bool isSugared() const { return false; }
3217
0
  QualType desugar() const { return QualType(this, 0); }
3218
3219
7.48M
  VectorKind getVectorKind() const {
3220
7.48M
    return VectorKind(VectorTypeBits.VecKind);
3221
7.48M
  }
3222
3223
3.54M
  void Profile(llvm::FoldingSetNodeID &ID) {
3224
3.54M
    Profile(ID, getElementType(), getNumElements(),
3225
3.54M
            getTypeClass(), getVectorKind());
3226
3.54M
  }
3227
3228
  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
3229
                      unsigned NumElements, TypeClass TypeClass,
3230
6.15M
                      VectorKind VecKind) {
3231
6.15M
    ID.AddPointer(ElementType.getAsOpaquePtr());
3232
6.15M
    ID.AddInteger(NumElements);
3233
6.15M
    ID.AddInteger(TypeClass);
3234
6.15M
    ID.AddInteger(VecKind);
3235
6.15M
  }
3236
3237
105M
  static bool classof(const Type *T) {
3238
105M
    return T->getTypeClass() == Vector || 
T->getTypeClass() == ExtVector84.7M
;
3239
105M
  }
3240
};
3241
3242
/// Represents a vector type where either the type or size is dependent.
3243
////
3244
/// For example:
3245
/// \code
3246
/// template<typename T, int Size>
3247
/// class vector {
3248
///   typedef T __attribute__((vector_size(Size))) type;
3249
/// }
3250
/// \endcode
3251
class DependentVectorType : public Type, public llvm::FoldingSetNode {
3252
  friend class ASTContext;
3253
3254
  const ASTContext &Context;
3255
  QualType ElementType;
3256
  Expr *SizeExpr;
3257
  SourceLocation Loc;
3258
3259
  DependentVectorType(const ASTContext &Context, QualType ElementType,
3260
                           QualType CanonType, Expr *SizeExpr,
3261
                           SourceLocation Loc, VectorType::VectorKind vecKind);
3262
3263
public:
3264
39
  Expr *getSizeExpr() const { return SizeExpr; }
3265
78
  QualType getElementType() const { return ElementType; }
3266
39
  SourceLocation getAttributeLoc() const { return Loc; }
3267
39
  VectorType::VectorKind getVectorKind() const {
3268
39
    return VectorType::VectorKind(VectorTypeBits.VecKind);
3269
39
  }
3270
3271
0
  bool isSugared() const { return false; }
3272
0
  QualType desugar() const { return QualType(this, 0); }
3273
3274
15
  static bool classof(const Type *T) {
3275
15
    return T->getTypeClass() == DependentVector;
3276
15
  }
3277
3278
0
  void Profile(llvm::FoldingSetNodeID &ID) {
3279
0
    Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
3280
0
  }
3281
3282
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3283
                      QualType ElementType, const Expr *SizeExpr,
3284
                      VectorType::VectorKind VecKind);
3285
};
3286
3287
/// ExtVectorType - Extended vector type. This type is created using
3288
/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
3289
/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
3290
/// class enables syntactic extensions, like Vector Components for accessing
3291
/// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
3292
/// Shading Language).
3293
class ExtVectorType : public VectorType {
3294
  friend class ASTContext; // ASTContext creates these.
3295
3296
  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
3297
3.15k
      : VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
3298
3299
public:
3300
1.38k
  static int getPointAccessorIdx(char c) {
3301
1.38k
    switch (c) {
3302
1.38k
    
default: return -16
;
3303
1.38k
    
case 'x': 652
case 'r': return 0652
;
3304
652
    
case 'y': 498
case 'g': return 1498
;
3305
498
    
case 'z': 133
case 'b': return 2133
;
3306
133
    
case 'w': 94
case 'a': return 394
;
3307
1.38k
    }
3308
1.38k
  }
3309
3310
90
  static int getNumericAccessorIdx(char c) {
3311
90
    switch (c) {
3312
90
      
default: return -120
;
3313
90
      
case '0': return 016
;
3314
90
      
case '1': return 111
;
3315
90
      
case '2': return 24
;
3316
90
      
case '3': return 34
;
3317
90
      
case '4': return 46
;
3318
90
      
case '5': return 50
;
3319
90
      
case '6': return 64
;
3320
90
      
case '7': return 70
;
3321
90
      
case '8': return 80
;
3322
90
      
case '9': return 90
;
3323
90
      case 'A':
3324
3
      case 'a': return 10;
3325
8
      case 'B':
3326
8
      case 'b': return 11;
3327
8
      case 'C':
3328
3
      case 'c': return 12;
3329
3
      case 'D':
3330
3
      case 'd': return 13;
3331
3
      case 'E':
3332
0
      case 'e': return 14;
3333
8
      case 'F':
3334
8
      case 'f': return 15;
3335
90
    }
3336
90
  }
3337
3338
872
  static int getAccessorIdx(char c, bool isNumericAccessor) {
3339
872
    if (isNumericAccessor)
3340
37
      return getNumericAccessorIdx(c);
3341
835
    else
3342
835
      return getPointAccessorIdx(c);
3343
872
  }
3344
3345
549
  bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
3346
549
    if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
3347
549
      return unsigned(idx-1) < getNumElements();
3348
0
    return false;
3349
0
  }
3350
3351
432k
  bool isSugared() const { return false; }
3352
0
  QualType desugar() const { return QualType(this, 0); }
3353
3354
5.45M
  static bool classof(const Type *T) {
3355
5.45M
    return T->getTypeClass() == ExtVector;
3356
5.45M
  }
3357
};
3358
3359
/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
3360
/// class of FunctionNoProtoType and FunctionProtoType.
3361
class FunctionType : public Type {
3362
  // The type returned by the function.
3363
  QualType ResultType;
3364
3365
public:
3366
  /// Interesting information about a specific parameter that can't simply
3367
  /// be reflected in parameter's type. This is only used by FunctionProtoType
3368
  /// but is in FunctionType to make this class available during the
3369
  /// specification of the bases of FunctionProtoType.
3370
  ///
3371
  /// It makes sense to model language features this way when there's some
3372
  /// sort of parameter-specific override (such as an attribute) that
3373
  /// affects how the function is called.  For example, the ARC ns_consumed
3374
  /// attribute changes whether a parameter is passed at +0 (the default)
3375
  /// or +1 (ns_consumed).  This must be reflected in the function type,
3376
  /// but isn't really a change to the parameter type.
3377
  ///
3378
  /// One serious disadvantage of modelling language features this way is
3379
  /// that they generally do not work with language features that attempt
3380
  /// to destructure types.  For example, template argument deduction will
3381
  /// not be able to match a parameter declared as
3382
  ///   T (*)(U)
3383
  /// against an argument of type
3384
  ///   void (*)(__attribute__((ns_consumed)) id)
3385
  /// because the substitution of T=void, U=id into the former will
3386
  /// not produce the latter.
3387
  class ExtParameterInfo {
3388
    enum {
3389
      ABIMask = 0x0F,
3390
      IsConsumed = 0x10,
3391
      HasPassObjSize = 0x20,
3392
      IsNoEscape = 0x40,
3393
    };
3394
    unsigned char Data = 0;
3395
3396
  public:
3397
18.3M
    ExtParameterInfo() = default;
3398
3399
    /// Return the ABI treatment of this parameter.
3400
4.58M
    ParameterABI getABI() const { return ParameterABI(Data & ABIMask); }
3401
160
    ExtParameterInfo withABI(ParameterABI kind) const {
3402
160
      ExtParameterInfo copy = *this;
3403
160
      copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
3404
160
      return copy;
3405
160
    }
3406
3407
    /// Is this parameter considered "consumed" by Objective-C ARC?
3408
    /// Consumed parameters must have retainable object type.
3409
12.7k
    bool isConsumed() const { return (Data & IsConsumed); }
3410
78
    ExtParameterInfo withIsConsumed(bool consumed) const {
3411
78
      ExtParameterInfo copy = *this;
3412
78
      if (consumed)
3413
78
        copy.Data |= IsConsumed;
3414
0
      else
3415
0
        copy.Data &= ~IsConsumed;
3416
78
      return copy;
3417
78
    }
3418
3419
3.49k
    bool hasPassObjectSize() const { return Data & HasPassObjSize; }
3420
106
    ExtParameterInfo withHasPassObjectSize() const {
3421
106
      ExtParameterInfo Copy = *this;
3422
106
      Copy.Data |= HasPassObjSize;
3423
106
      return Copy;
3424
106
    }
3425
3426
8.00M
    bool isNoEscape() const { return Data & IsNoEscape; }
3427
2.54k
    ExtParameterInfo withIsNoEscape(bool NoEscape) const {
3428
2.54k
      ExtParameterInfo Copy = *this;
3429
2.54k
      if (NoEscape)
3430
644
        Copy.Data |= IsNoEscape;
3431
1.90k
      else
3432
1.90k
        Copy.Data &= ~IsNoEscape;
3433
2.54k
      return Copy;
3434
2.54k
    }
3435
3436
34.3k
    unsigned char getOpaqueValue() const { return Data; }
3437
2
    static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
3438
2
      ExtParameterInfo result;
3439
2
      result.Data = data;
3440
2
      return result;
3441
2
    }
3442
3443
80
    friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs) {
3444
80
      return lhs.Data == rhs.Data;
3445
80
    }
3446
3447
192
    friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs) {
3448
192
      return lhs.Data != rhs.Data;
3449
192
    }
3450
  };
3451
3452
  /// A class which abstracts out some details necessary for
3453
  /// making a call.
3454
  ///
3455
  /// It is not actually used directly for storing this information in
3456
  /// a FunctionType, although FunctionType does currently use the
3457
  /// same bit-pattern.
3458
  ///
3459
  // If you add a field (say Foo), other than the obvious places (both,
3460
  // constructors, compile failures), what you need to update is
3461
  // * Operator==
3462
  // * getFoo
3463
  // * withFoo
3464
  // * functionType. Add Foo, getFoo.
3465
  // * ASTContext::getFooType
3466
  // * ASTContext::mergeFunctionTypes
3467
  // * FunctionNoProtoType::Profile
3468
  // * FunctionProtoType::Profile
3469
  // * TypePrinter::PrintFunctionProto
3470
  // * AST read and write
3471
  // * Codegen
3472
0
  class ExtInfo {
3473
    friend class FunctionType;
3474
3475
    // Feel free to rearrange or add bits, but if you go over 12,
3476
    // you'll need to adjust both the Bits field below and
3477
    // Type::FunctionTypeBitfields.
3478
3479
    //   |  CC  |noreturn|produces|nocallersavedregs|regparm|nocfcheck|
3480
    //   |0 .. 4|   5    |    6   |       7         |8 .. 10|    11   |
3481
    //
3482
    // regparm is either 0 (no regparm attribute) or the regparm value+1.
3483
    enum { CallConvMask = 0x1F };
3484
    enum { NoReturnMask = 0x20 };
3485
    enum { ProducesResultMask = 0x40 };
3486
    enum { NoCallerSavedRegsMask = 0x80 };
3487
    enum { NoCfCheckMask = 0x800 };
3488
    enum {
3489
      RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask |
3490
                      NoCallerSavedRegsMask | NoCfCheckMask),
3491
      RegParmOffset = 8
3492
    }; // Assumed to be the last field
3493
    uint16_t Bits = CC_C;
3494
3495
57.2M
    ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
3496
3497
   public:
3498
     // Constructor with no defaults. Use this when you know that you
3499
     // have all the elements (when reading an AST file for example).
3500
     ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
3501
17.6k
             bool producesResult, bool noCallerSavedRegs, bool NoCfCheck) {
3502
17.6k
       assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
3503
17.6k
       Bits = ((unsigned)cc) | (noReturn ? 
NoReturnMask4
:
017.6k
) |
3504
17.6k
              (producesResult ? 
ProducesResultMask0
: 0) |
3505
17.6k
              (noCallerSavedRegs ? 
NoCallerSavedRegsMask0
: 0) |
3506
17.6k
              (hasRegParm ? 
((regParm + 1) << RegParmOffset)0
: 0) |
3507
17.6k
              (NoCfCheck ? 
NoCfCheckMask0
: 0);
3508
17.6k
    }
3509
3510
    // Constructor with all defaults. Use when for example creating a
3511
    // function known to use defaults.
3512
46.4M
    ExtInfo() = default;
3513
3514
    // Constructor with just the calling convention, which is an important part
3515
    // of the canonical type.
3516
7.72M
    ExtInfo(CallingConv CC) : Bits(CC) {}
3517
3518
11.7M
    bool getNoReturn() const { return Bits & NoReturnMask; }
3519
5.68M
    bool getProducesResult() const { return Bits & ProducesResultMask; }
3520
4.26M
    bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
3521
3.18M
    bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
3522
4.28M
    bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
3523
3524
4.30M
    unsigned getRegParm() const {
3525
4.30M
      unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
3526
4.30M
      if (RegParm > 0)
3527
176
        --RegParm;
3528
4.30M
      return RegParm;
3529
4.30M
    }
3530
3531
8.60M
    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
3532
3533
1.66M
    bool operator==(ExtInfo Other) const {
3534
1.66M
      return Bits == Other.Bits;
3535
1.66M
    }
3536
387
    bool operator!=(ExtInfo Other) const {
3537
387
      return Bits != Other.Bits;
3538
387
    }
3539
3540
    // Note that we don't have setters. That is by design, use
3541
    // the following with methods instead of mutating these objects.
3542
3543
41.1k
    ExtInfo withNoReturn(bool noReturn) const {
3544
41.1k
      if (noReturn)
3545
36.4k
        return ExtInfo(Bits | NoReturnMask);
3546
4.68k
      else
3547
4.68k
        return ExtInfo(Bits & ~NoReturnMask);
3548
41.1k
    }
3549
3550
335
    ExtInfo withProducesResult(bool producesResult) const {
3551
335
      if (producesResult)
3552
335
        return ExtInfo(Bits | ProducesResultMask);
3553
0
      else
3554
0
        return ExtInfo(Bits & ~ProducesResultMask);
3555
335
    }
3556
3557
14
    ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
3558
14
      if (noCallerSavedRegs)
3559
14
        return ExtInfo(Bits | NoCallerSavedRegsMask);
3560
0
      else
3561
0
        return ExtInfo(Bits & ~NoCallerSavedRegsMask);
3562
14
    }
3563
3564
6
    ExtInfo withNoCfCheck(bool noCfCheck) const {
3565
6
      if (noCfCheck)
3566
6
        return ExtInfo(Bits | NoCfCheckMask);
3567
0
      else
3568
0
        return ExtInfo(Bits & ~NoCfCheckMask);
3569
6
    }
3570
3571
73
    ExtInfo withRegParm(unsigned RegParm) const {
3572
73
      assert(RegParm < 7 && "Invalid regparm value");
3573
73
      return ExtInfo((Bits & ~RegParmMask) |
3574
73
                     ((RegParm + 1) << RegParmOffset));
3575
73
    }
3576
3577
570k
    ExtInfo withCallingConv(CallingConv cc) const {
3578
570k
      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
3579
570k
    }
3580
3581
49.9M
    void Profile(llvm::FoldingSetNodeID &ID) const {
3582
49.9M
      ID.AddInteger(Bits);
3583
49.9M
    }
3584
  };
3585
3586
  /// A simple holder for a QualType representing a type in an
3587
  /// exception specification. Unfortunately needed by FunctionProtoType
3588
  /// because TrailingObjects cannot handle repeated types.
3589
  struct ExceptionType { QualType Type; };
3590
3591
  /// A simple holder for various uncommon bits which do not fit in
3592
  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
3593
  /// alignment of subsequent objects in TrailingObjects. You must update
3594
  /// hasExtraBitfields in FunctionProtoType after adding extra data here.
3595
  struct alignas(void *) FunctionTypeExtraBitfields {
3596
    /// The number of types in the exception specification.
3597
    /// A whole unsigned is not needed here and according to
3598
    /// [implimits] 8 bits would be enough here.
3599
    unsigned NumExceptionType;
3600
  };
3601
3602
protected:
3603
  FunctionType(TypeClass tc, QualType res,
3604
               QualType Canonical, bool Dependent,
3605
               bool InstantiationDependent,
3606
               bool VariablyModified, bool ContainsUnexpandedParameterPack,
3607
               ExtInfo Info)
3608
      : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3609
             ContainsUnexpandedParameterPack),
3610
7.57M
        ResultType(res) {
3611
7.57M
    FunctionTypeBits.ExtInfo = Info.Bits;
3612
7.57M
  }
3613
3614
50.6M
  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
3615
3616
public:
3617
129M
  QualType getReturnType() const { return ResultType; }
3618
3619
120
  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
3620
10
  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
3621
3622
  /// Determine whether this function type includes the GNU noreturn
3623
  /// attribute. The C++11 [[noreturn]] attribute does not affect the function
3624
  /// type.
3625
6.53M
  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
3626
3627
3.64M
  CallingConv getCallConv() const { return getExtInfo().getCC(); }
3628
56.6M
  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
3629
31.3k
  bool isConst() const { return getTypeQuals() & Qualifiers::Const; }
3630
17.5k
  bool isVolatile() const { return getTypeQuals() & Qualifiers::Volatile; }
3631
5.10k
  bool isRestrict() const { return getTypeQuals() & Qualifiers::Restrict; }
3632
3633
  /// Determine the type of an expression that calls a function of
3634
  /// this type.
3635
2.83M
  QualType getCallResultType(const ASTContext &Context) const {
3636
2.83M
    return getReturnType().getNonLValueExprType(Context);
3637
2.83M
  }
3638
3639
  static StringRef getNameForCallConv(CallingConv CC);
3640
3641
246M
  static bool classof(const Type *T) {
3642
246M
    return T->getTypeClass() == FunctionNoProto ||
3643
246M
           
T->getTypeClass() == FunctionProto245M
;
3644
246M
  }
3645
};
3646
3647
/// Represents a K&R-style 'int foo()' function, which has
3648
/// no information available about its arguments.
3649
class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
3650
  friend class ASTContext; // ASTContext creates these.
3651
3652
  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
3653
      : FunctionType(FunctionNoProto, Result, Canonical,
3654
                     /*Dependent=*/false, /*InstantiationDependent=*/false,
3655
                     Result->isVariablyModifiedType(),
3656
10.5k
                     /*ContainsUnexpandedParameterPack=*/false, Info) {}
3657
3658
public:
3659
  // No additional state past what FunctionType provides.
3660
3661
14.1k
  bool isSugared() const { return false; }
3662
0
  QualType desugar() const { return QualType(this, 0); }
3663
3664
119k
  void Profile(llvm::FoldingSetNodeID &ID) {
3665
119k
    Profile(ID, getReturnType(), getExtInfo());
3666
119k
  }
3667
3668
  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
3669
248k
                      ExtInfo Info) {
3670
248k
    Info.Profile(ID);
3671
248k
    ID.AddPointer(ResultType.getAsOpaquePtr());
3672
248k
  }
3673
3674
63.2M
  static bool classof(const Type *T) {
3675
63.2M
    return T->getTypeClass() == FunctionNoProto;
3676
63.2M
  }
3677
};
3678
3679
/// Represents a prototype with parameter type info, e.g.
3680
/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
3681
/// parameters, not as having a single void parameter. Such a type can have
3682
/// an exception specification, but this specification is not part of the
3683
/// canonical type. FunctionProtoType has several trailing objects, some of
3684
/// which optional. For more information about the trailing objects see
3685
/// the first comment inside FunctionProtoType.
3686
class FunctionProtoType final
3687
    : public FunctionType,
3688
      public llvm::FoldingSetNode,
3689
      private llvm::TrailingObjects<
3690
          FunctionProtoType, QualType, FunctionType::FunctionTypeExtraBitfields,
3691
          FunctionType::ExceptionType, Expr *, FunctionDecl *,
3692
          FunctionType::ExtParameterInfo> {
3693
  friend class ASTContext; // ASTContext creates these.
3694
  friend TrailingObjects;
3695
3696
  // FunctionProtoType is followed by several trailing objects, some of
3697
  // which optional. They are in order:
3698
  //
3699
  // * An array of getNumParams() QualType holding the parameter types.
3700
  //   Always present. Note that for the vast majority of FunctionProtoType,
3701
  //   these will be the only trailing objects.
3702
  //
3703
  // * Optionally if some extra data is stored in FunctionTypeExtraBitfields
3704
  //   (see FunctionTypeExtraBitfields and FunctionTypeBitfields):
3705
  //   a single FunctionTypeExtraBitfields. Present if and only if
3706
  //   hasExtraBitfields() is true.
3707
  //
3708
  // * Optionally exactly one of:
3709
  //   * an array of getNumExceptions() ExceptionType,
3710
  //   * a single Expr *,
3711
  //   * a pair of FunctionDecl *,
3712
  //   * a single FunctionDecl *
3713
  //   used to store information about the various types of exception
3714
  //   specification. See getExceptionSpecSize for the details.
3715
  //
3716
  // * Optionally an array of getNumParams() ExtParameterInfo holding
3717
  //   an ExtParameterInfo for each of the parameters. Present if and
3718
  //   only if hasExtParameterInfos() is true.
3719
  //
3720
  // The optional FunctionTypeExtraBitfields has to be before the data
3721
  // related to the exception specification since it contains the number
3722
  // of exception types.
3723
  //
3724
  // We put the ExtParameterInfos last.  If all were equal, it would make
3725
  // more sense to put these before the exception specification, because
3726
  // it's much easier to skip past them compared to the elaborate switch
3727
  // required to skip the exception specification.  However, all is not
3728
  // equal; ExtParameterInfos are used to model very uncommon features,
3729
  // and it's better not to burden the more common paths.
3730
3731
public:
3732
  /// Holds information about the various types of exception specification.
3733
  /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is
3734
  /// used to group together the various bits of information about the
3735
  /// exception specification.
3736
0
  struct ExceptionSpecInfo {
3737
    /// The kind of exception specification this is.
3738
    ExceptionSpecificationType Type = EST_None;
3739
3740
    /// Explicitly-specified list of exception types.
3741
    ArrayRef<QualType> Exceptions;
3742
3743
    /// Noexcept expression, if this is a computed noexcept specification.
3744
    Expr *NoexceptExpr = nullptr;
3745
3746
    /// The function whose exception specification this is, for
3747
    /// EST_Unevaluated and EST_Uninstantiated.
3748
    FunctionDecl *SourceDecl = nullptr;
3749
3750
    /// The function template whose exception specification this is instantiated
3751
    /// from, for EST_Uninstantiated.
3752
    FunctionDecl *SourceTemplate = nullptr;
3753
3754
48.2M
    ExceptionSpecInfo() = default;
3755
3756
8.56k
    ExceptionSpecInfo(ExceptionSpecificationType EST) : Type(EST) {}
3757
  };
3758
3759
  /// Extra information about a function prototype. ExtProtoInfo is not
3760
  /// stored as such in FunctionProtoType but is used to group together
3761
  /// the various bits of extra information about a function prototype.
3762
  struct ExtProtoInfo {
3763
    FunctionType::ExtInfo ExtInfo;
3764
    bool Variadic : 1;
3765
    bool HasTrailingReturn : 1;
3766
    unsigned char TypeQuals = 0;
3767
    RefQualifierKind RefQualifier = RQ_None;
3768
    ExceptionSpecInfo ExceptionSpec;
3769
    const ExtParameterInfo *ExtParameterInfos = nullptr;
3770
3771
46.3M
    ExtProtoInfo() : Variadic(false), HasTrailingReturn(false) {}
3772
3773
    ExtProtoInfo(CallingConv CC)
3774
118k
        : ExtInfo(CC), Variadic(false), HasTrailingReturn(false) {}
3775
3776
681k
    ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI) {
3777
681k
      ExtProtoInfo Result(*this);
3778
681k
      Result.ExceptionSpec = ESI;
3779
681k
      return Result;
3780
681k
    }
3781
  };
3782
3783
private:
3784
4.03M
  unsigned numTrailingObjects(OverloadToken<QualType>) const {
3785
4.03M
    return getNumParams();
3786
4.03M
  }
3787
3788
4.02M
  unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const {
3789
4.02M
    return hasExtraBitfields();
3790
4.02M
  }
3791
3792
3.74M
  unsigned numTrailingObjects(OverloadToken<ExceptionType>) const {
3793
3.74M
    return getExceptionSpecSize().NumExceptionType;
3794
3.74M
  }
3795
3796
2.89M
  unsigned numTrailingObjects(OverloadToken<Expr *>) const {
3797
2.89M
    return getExceptionSpecSize().NumExprPtr;
3798
2.89M
  }
3799
3800
7.62k
  unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const {
3801
7.62k
    return getExceptionSpecSize().NumFunctionDeclPtr;
3802
7.62k
  }
3803
3804
0
  unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
3805
0
    return hasExtParameterInfos() ? getNumParams() : 0;
3806
0
  }
3807
3808
  /// Determine whether there are any argument types that
3809
  /// contain an unexpanded parameter pack.
3810
  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
3811
0
                                                 unsigned numArgs) {
3812
0
    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
3813
0
      if (ArgArray[Idx]->containsUnexpandedParameterPack())
3814
0
        return true;
3815
0
3816
0
    return false;
3817
0
  }
3818
3819
  FunctionProtoType(QualType result, ArrayRef<QualType> params,
3820
                    QualType canonical, const ExtProtoInfo &epi);
3821
3822
  /// This struct is returned by getExceptionSpecSize and is used to
3823
  /// translate an ExceptionSpecificationType to the number and kind
3824
  /// of trailing objects related to the exception specification.
3825
  struct ExceptionSpecSizeHolder {
3826
    unsigned NumExceptionType;
3827
    unsigned NumExprPtr;
3828
    unsigned NumFunctionDeclPtr;
3829
  };
3830
3831
  /// Return the number and kind of trailing objects
3832
  /// related to the exception specification.
3833
  static ExceptionSpecSizeHolder
3834
14.2M
  getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) {
3835
14.2M
    switch (EST) {
3836
14.2M
    case EST_None:
3837
6.79M
    case EST_DynamicNone:
3838
6.79M
    case EST_MSAny:
3839
6.79M
    case EST_BasicNoexcept:
3840
6.79M
    case EST_Unparsed:
3841
6.79M
      return {0, 0, 0};
3842
6.79M
3843
6.79M
    case EST_Dynamic:
3844
862
      return {NumExceptions, 0, 0};
3845
6.79M
3846
6.79M
    case EST_DependentNoexcept:
3847
966k
    case EST_NoexceptFalse:
3848
966k
    case EST_NoexceptTrue:
3849
966k
      return {0, 1, 0};
3850
966k
3851
966k
    case EST_Uninstantiated:
3852
466k
      return {0, 0, 2};
3853
966k
3854
5.99M
    case EST_Unevaluated:
3855
5.99M
      return {0, 0, 1};
3856
0
    }
3857
0
    llvm_unreachable("bad exception specification kind");
3858
0
  }
3859
3860
  /// Return the number and kind of trailing objects
3861
  /// related to the exception specification.
3862
6.65M
  ExceptionSpecSizeHolder getExceptionSpecSize() const {
3863
6.65M
    return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
3864
6.65M
  }
3865
3866
  /// Whether the trailing FunctionTypeExtraBitfields is present.
3867
19.1M
  static bool hasExtraBitfields(ExceptionSpecificationType EST) {
3868
19.1M
    // If the exception spec type is EST_Dynamic then we have > 0 exception
3869
19.1M
    // types and the exact number is stored in FunctionTypeExtraBitfields.
3870
19.1M
    return EST == EST_Dynamic;
3871
19.1M
  }
3872
3873
  /// Whether the trailing FunctionTypeExtraBitfields is present.
3874
4.02M
  bool hasExtraBitfields() const {
3875
4.02M
    return hasExtraBitfields(getExceptionSpecType());
3876
4.02M
  }
3877
3878
public:
3879
230M
  unsigned getNumParams() const { return FunctionTypeBits.NumParams; }
3880
3881
13.4M
  QualType getParamType(unsigned i) const {
3882
13.4M
    assert(i < getNumParams() && "invalid parameter index");
3883
13.4M
    return param_type_begin()[i];
3884
13.4M
  }
3885
3886
1.35M
  ArrayRef<QualType> getParamTypes() const {
3887
1.35M
    return llvm::makeArrayRef(param_type_begin(), param_type_end());
3888
1.35M
  }
3889
3890
38.2M
  ExtProtoInfo getExtProtoInfo() const {
3891
38.2M
    ExtProtoInfo EPI;
3892
38.2M
    EPI.ExtInfo = getExtInfo();
3893
38.2M
    EPI.Variadic = isVariadic();
3894
38.2M
    EPI.HasTrailingReturn = hasTrailingReturn();
3895
38.2M
    EPI.ExceptionSpec.Type = getExceptionSpecType();
3896
38.2M
    EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
3897
38.2M
    EPI.RefQualifier = getRefQualifier();
3898
38.2M
    if (EPI.ExceptionSpec.Type == EST_Dynamic) {
3899
3.38k
      EPI.ExceptionSpec.Exceptions = exceptions();
3900
38.2M
    } else if (isComputedNoexcept(EPI.ExceptionSpec.Type)) {
3901
720k
      EPI.ExceptionSpec.NoexceptExpr = getNoexceptExpr();
3902
37.4M
    } else if (EPI.ExceptionSpec.Type == EST_Uninstantiated) {
3903
78.7k
      EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl();
3904
78.7k
      EPI.ExceptionSpec.SourceTemplate = getExceptionSpecTemplate();
3905
37.4M
    } else if (EPI.ExceptionSpec.Type == EST_Unevaluated) {
3906
1.80M
      EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl();
3907
1.80M
    }
3908
38.2M
    EPI.ExtParameterInfos = getExtParameterInfosOrNull();
3909
38.2M
    return EPI;
3910
38.2M
  }
3911
3912
  /// Get the kind of exception specification on this function.
3913
162M
  ExceptionSpecificationType getExceptionSpecType() const {
3914
162M
    return static_cast<ExceptionSpecificationType>(
3915
162M
        FunctionTypeBits.ExceptionSpecType);
3916
162M
  }
3917
3918
  /// Return whether this function has any kind of exception spec.
3919
38.0M
  bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; }
3920
3921
  /// Return whether this function has a dynamic (throw) exception spec.
3922
18.4k
  bool hasDynamicExceptionSpec() const {
3923
18.4k
    return isDynamicExceptionSpec(getExceptionSpecType());
3924
18.4k
  }
3925
3926
  /// Return whether this function has a noexcept exception spec.
3927
0
  bool hasNoexceptExceptionSpec() const {
3928
0
    return isNoexceptExceptionSpec(getExceptionSpecType());
3929
0
  }
3930
3931
  /// Return whether this function has a dependent exception spec.
3932
  bool hasDependentExceptionSpec() const;
3933
3934
  /// Return whether this function has an instantiation-dependent exception
3935
  /// spec.
3936
  bool hasInstantiationDependentExceptionSpec() const;
3937
3938
  /// Return the number of types in the exception specification.
3939
6.79M
  unsigned getNumExceptions() const {
3940
6.79M
    return getExceptionSpecType() == EST_Dynamic
3941
6.79M
               ? getTrailingObjects<FunctionTypeExtraBitfields>()
3942
5.53k
                     ->NumExceptionType
3943
6.79M
               : 
06.78M
;
3944
6.79M
  }
3945
3946
  /// Return the ith exception type, where 0 <= i < getNumExceptions().
3947
1.19k
  QualType getExceptionType(unsigned i) const {
3948
1.19k
    assert(i < getNumExceptions() && "Invalid exception number!");
3949
1.19k
    return exception_begin()[i];
3950
1.19k
  }
3951
3952
  /// Return the expression inside noexcept(expression), or a null pointer
3953
  /// if there is none (because the exception spec is not of this form).
3954
930k
  Expr *getNoexceptExpr() const {
3955
930k
    if (!isComputedNoexcept(getExceptionSpecType()))
3956
199k
      return nullptr;
3957
730k
    return *getTrailingObjects<Expr *>();
3958
730k
  }
3959
3960
  /// If this function type has an exception specification which hasn't
3961
  /// been determined yet (either because it has not been evaluated or because
3962
  /// it has not been instantiated), this is the function whose exception
3963
  /// specification is represented by this type.
3964
2.12M
  FunctionDecl *getExceptionSpecDecl() const {
3965
2.12M
    if (getExceptionSpecType() != EST_Uninstantiated &&
3966
2.12M
        
getExceptionSpecType() != EST_Unevaluated2.04M
)
3967
0
      return nullptr;
3968
2.12M
    return getTrailingObjects<FunctionDecl *>()[0];
3969
2.12M
  }
3970
3971
  /// If this function type has an uninstantiated exception
3972
  /// specification, this is the function whose exception specification
3973
  /// should be instantiated to find the exception specification for
3974
  /// this type.
3975
85.8k
  FunctionDecl *getExceptionSpecTemplate() const {
3976
85.8k
    if (getExceptionSpecType() != EST_Uninstantiated)
3977
0
      return nullptr;
3978
85.8k
    return getTrailingObjects<FunctionDecl *>()[1];
3979
85.8k
  }
3980
3981
  /// Determine whether this function type has a non-throwing exception
3982
  /// specification.
3983
  CanThrowResult canThrow() const;
3984
3985
  /// Determine whether this function type has a non-throwing exception
3986
  /// specification. If this depends on template arguments, returns
3987
  /// \c ResultIfDependent.
3988
2.32M
  bool isNothrow(bool ResultIfDependent = false) const {
3989
2.32M
    return ResultIfDependent ? 
canThrow() != CT_Can5.34k
:
canThrow() == CT_Cannot2.31M
;
3990
2.32M
  }
3991
3992
  /// Whether this function prototype is variadic.
3993
70.5M
  bool isVariadic() const { return FunctionTypeBits.Variadic; }
3994
3995
  /// Determines whether this function prototype contains a
3996
  /// parameter pack at the end.
3997
  ///
3998
  /// A function template whose last parameter is a parameter pack can be
3999
  /// called with an arbitrary number of arguments, much like a variadic
4000
  /// function.
4001
  bool isTemplateVariadic() const;
4002
4003
  /// Whether this function prototype has a trailing return type.
4004
44.8M
  bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
4005
4006
50.6M
  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
4007
4008
  /// Retrieve the ref-qualifier associated with this function type.
4009
47.1M
  RefQualifierKind getRefQualifier() const {
4010
47.1M
    return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
4011
47.1M
  }
4012
4013
  using param_type_iterator = const QualType *;
4014
  using param_type_range = llvm::iterator_range<param_type_iterator>;
4015
4016
6.78M
  param_type_range param_types() const {
4017
6.78M
    return param_type_range(param_type_begin(), param_type_end());
4018
6.78M
  }
4019
4020
97.1M
  param_type_iterator param_type_begin() const {
4021
97.1M
    return getTrailingObjects<QualType>();
4022
97.1M
  }
4023
4024
19.3M
  param_type_iterator param_type_end() const {
4025
19.3M
    return param_type_begin() + getNumParams();
4026
19.3M
  }
4027
4028
  using exception_iterator = const QualType *;
4029
4030
138k
  ArrayRef<QualType> exceptions() const {
4031
138k
    return llvm::makeArrayRef(exception_begin(), exception_end());
4032
138k
  }
4033
4034
278k
  exception_iterator exception_begin() const {
4035
278k
    return reinterpret_cast<exception_iterator>(
4036
278k
        getTrailingObjects<ExceptionType>());
4037
278k
  }
4038
4039
138k
  exception_iterator exception_end() const {
4040
138k
    return exception_begin() + getNumExceptions();
4041
138k
  }
4042
4043
  /// Is there any interesting extra information for any of the parameters
4044
  /// of this function type?
4045
49.8M
  bool hasExtParameterInfos() const {
4046
49.8M
    return FunctionTypeBits.HasExtParameterInfos;
4047
49.8M
  }
4048
4049
1.82k
  ArrayRef<ExtParameterInfo> getExtParameterInfos() const {
4050
1.82k
    assert(hasExtParameterInfos());
4051
1.82k
    return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(),
4052
1.82k
                                      getNumParams());
4053
1.82k
  }
4054
4055
  /// Return a pointer to the beginning of the array of extra parameter
4056
  /// information, if present, or else null if none of the parameters
4057
  /// carry it.  This is equivalent to getExtProtoInfo().ExtParameterInfos.
4058
39.9M
  const ExtParameterInfo *getExtParameterInfosOrNull() const {
4059
39.9M
    if (!hasExtParameterInfos())
4060
39.9M
      return nullptr;
4061
3.71k
    return getTrailingObjects<ExtParameterInfo>();
4062
3.71k
  }
4063
4064
5.64M
  ExtParameterInfo getExtParameterInfo(unsigned I) const {
4065
5.64M
    assert(I < getNumParams() && "parameter index out of range");
4066
5.64M
    if (hasExtParameterInfos())
4067
889
      return getTrailingObjects<ExtParameterInfo>()[I];
4068
5.64M
    return ExtParameterInfo();
4069
5.64M
  }
4070
4071
0
  ParameterABI getParameterABI(unsigned I) const {
4072
0
    assert(I < getNumParams() && "parameter index out of range");
4073
0
    if (hasExtParameterInfos())
4074
0
      return getTrailingObjects<ExtParameterInfo>()[I].getABI();
4075
0
    return ParameterABI::Ordinary;
4076
0
  }
4077
4078
18.5k
  bool isParamConsumed(unsigned I) const {
4079
18.5k
    assert(I < getNumParams() && "parameter index out of range");
4080
18.5k
    if (hasExtParameterInfos())
4081
14
      return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
4082
18.5k
    return false;
4083
18.5k
  }
4084
4085
2.46M
  bool isSugared() const { return false; }
4086
27
  QualType desugar() const { return QualType(this, 0); }
4087
4088
  void printExceptionSpecification(raw_ostream &OS,
4089
                                   const PrintingPolicy &Policy) const;
4090
4091
342M
  static bool classof(const Type *T) {
4092
342M
    return T->getTypeClass() == FunctionProto;
4093
342M
  }
4094
4095
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
4096
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
4097
                      param_type_iterator ArgTys, unsigned NumArgs,
4098
                      const ExtProtoInfo &EPI, const ASTContext &Context,
4099
                      bool Canonical);
4100
};
4101
4102
/// Represents the dependent type named by a dependently-scoped
4103
/// typename using declaration, e.g.
4104
///   using typename Base<T>::foo;
4105
///
4106
/// Template instantiation turns these into the underlying type.
4107
class UnresolvedUsingType : public Type {
4108
  friend class ASTContext; // ASTContext creates these.
4109
4110
  UnresolvedUsingTypenameDecl *Decl;
4111
4112
  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
4113
      : Type(UnresolvedUsing, QualType(), true, true, false,
4114
             /*ContainsUnexpandedParameterPack=*/false),
4115
47
        Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
4116
4117
public:
4118
58
  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
4119
4120
100
  bool isSugared() const { return false; }
4121
0
  QualType desugar() const { return QualType(this, 0); }
4122
4123
302
  static bool classof(const Type *T) {
4124
302
    return T->getTypeClass() == UnresolvedUsing;
4125
302
  }
4126
4127
  void Profile(llvm::FoldingSetNodeID &ID) {
4128
    return Profile(ID, Decl);
4129
  }
4130
4131
  static void Profile(llvm::FoldingSetNodeID &ID,
4132
                      UnresolvedUsingTypenameDecl *D) {
4133
    ID.AddPointer(D);
4134
  }
4135
};
4136
4137
class TypedefType : public Type {
4138
  TypedefNameDecl *Decl;
4139
4140
protected:
4141
  friend class ASTContext; // ASTContext creates these.
4142
4143
  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
4144
      : Type(tc, can, can->isDependentType(),
4145
             can->isInstantiationDependentType(),
4146
             can->isVariablyModifiedType(),
4147
             /*ContainsUnexpandedParameterPack=*/false),
4148
1.41M
        Decl(const_cast<TypedefNameDecl*>(D)) {
4149
1.41M
    assert(!isa<TypedefType>(can) && "Invalid canonical type");
4150
1.41M
  }
4151
4152
public:
4153
44.0M
  TypedefNameDecl *getDecl() const { return Decl; }
4154
4155
31.3M
  bool isSugared() const { return true; }
4156
  QualType desugar() const;
4157
4158
18.6M
  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
4159
};
4160
4161
/// Represents a `typeof` (or __typeof__) expression (a GCC extension).
4162
class TypeOfExprType : public Type {
4163
  Expr *TOExpr;
4164
4165
protected:
4166
  friend class ASTContext; // ASTContext creates these.
4167
4168
  TypeOfExprType(Expr *E, QualType can = QualType());
4169
4170
public:
4171
11.2k
  Expr *getUnderlyingExpr() const { return TOExpr; }
4172
4173
  /// Remove a single level of sugar.
4174
  QualType desugar() const;
4175
4176
  /// Returns whether this type directly provides sugar.
4177
  bool isSugared() const;
4178
4179
117k
  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
4180
};
4181
4182
/// Internal representation of canonical, dependent
4183
/// `typeof(expr)` types.
4184
///
4185
/// This class is used internally by the ASTContext to manage
4186
/// canonical, dependent types, only. Clients will only see instances
4187
/// of this class via TypeOfExprType nodes.
4188
class DependentTypeOfExprType
4189
  : public TypeOfExprType, public llvm::FoldingSetNode {
4190
  const ASTContext &Context;
4191
4192
public:
4193
  DependentTypeOfExprType(const ASTContext &Context, Expr *E)
4194
126
      : TypeOfExprType(E), Context(Context) {}
4195
4196
614
  void Profile(llvm::FoldingSetNodeID &ID) {
4197
614
    Profile(ID, Context, getUnderlyingExpr());
4198
614
  }
4199
4200
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4201
                      Expr *E);
4202
};
4203
4204
/// Represents `typeof(type)`, a GCC extension.
4205
class TypeOfType : public Type {
4206
  friend class ASTContext; // ASTContext creates these.
4207
4208
  QualType TOType;
4209
4210
  TypeOfType(QualType T, QualType can)
4211
      : Type(TypeOf, can, T->isDependentType(),
4212
             T->isInstantiationDependentType(),
4213
             T->isVariablyModifiedType(),
4214
             T->containsUnexpandedParameterPack()),
4215
100
        TOType(T) {
4216
100
    assert(!isa<TypedefType>(can) && "Invalid canonical type");
4217
100
  }
4218
4219
public:
4220
503
  QualType getUnderlyingType() const { return TOType; }
4221
4222
  /// Remove a single level of sugar.
4223
458
  QualType desugar() const { return getUnderlyingType(); }
4224
4225
  /// Returns whether this type directly provides sugar.
4226
441
  bool isSugared() const { return true; }
4227
4228
47
  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
4229
};
4230
4231
/// Represents the type `decltype(expr)` (C++11).
4232
class DecltypeType : public Type {
4233
  Expr *E;
4234
  QualType UnderlyingType;
4235
4236
protected:
4237
  friend class ASTContext; // ASTContext creates these.
4238
4239
  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
4240
4241
public:
4242
204k
  Expr *getUnderlyingExpr() const { return E; }
4243
130k
  QualType getUnderlyingType() const { return UnderlyingType; }
4244
4245
  /// Remove a single level of sugar.
4246
  QualType desugar() const;
4247
4248
  /// Returns whether this type directly provides sugar.
4249
  bool isSugared() const;
4250
4251
1.77M
  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
4252
};
4253
4254
/// Internal representation of canonical, dependent
4255
/// decltype(expr) types.
4256
///
4257
/// This class is used internally by the ASTContext to manage
4258
/// canonical, dependent types, only. Clients will only see instances
4259
/// of this class via DecltypeType nodes.
4260
class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
4261
  const ASTContext &Context;
4262
4263
public:
4264
  DependentDecltypeType(const ASTContext &Context, Expr *E);
4265
4266
19.5k
  void Profile(llvm::FoldingSetNodeID &ID) {
4267
19.5k
    Profile(ID, Context, getUnderlyingExpr());
4268
19.5k
  }
4269
4270
  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4271
                      Expr *E);
4272
};
4273
4274
/// A unary type transform, which is a type constructed from another.
4275
class UnaryTransformType : public Type {
4276
public:
4277
  enum UTTKind {
4278
    EnumUnderlyingType
4279
  };
4280
4281
private:
4282
  /// The untransformed type.
4283
  QualType BaseType;
4284
4285
  /// The transformed type if not dependent, otherwise the same as BaseType.
4286
  QualType UnderlyingType;
4287
4288
  UTTKind UKind;
4289
4290
protected:
4291
  friend class ASTContext;
4292
4293
  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
4294
                     QualType CanonicalTy);
4295
4296
public:
4297
158
  bool isSugared() const { return !isDependentType(); }
4298
153
  QualType desugar() const { return UnderlyingType; }
4299
4300
34
  QualType getUnderlyingType() const { return UnderlyingType; }
4301
50
  QualType getBaseType() const { return BaseType; }
4302
4303
41
  UTTKind getUTTKind() const { return UKind; }
4304
4305
0
  static bool classof(const Type *T) {
4306
0
    return T->getTypeClass() == UnaryTransform;
4307
0
  }
4308
};
4309
4310
/// Internal representation of canonical, dependent
4311
/// __underlying_type(type) types.
4312
///
4313
/// This class is used internally by the ASTContext to manage
4314
/// canonical, dependent types, only. Clients will only see instances
4315
/// of this class via UnaryTransformType nodes.
4316
class DependentUnaryTransformType : public UnaryTransformType,
4317
                                    public llvm::FoldingSetNode {
4318
public:
4319
  DependentUnaryTransformType(const ASTContext &C, QualType BaseType,
4320
                              UTTKind UKind);
4321
4322
6
  void Profile(llvm::FoldingSetNodeID &ID) {
4323
6
    Profile(ID, getBaseType(), getUTTKind());
4324
6
  }
4325
4326
  static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
4327
645
                      UTTKind UKind) {
4328
645
    ID.AddPointer(BaseType.getAsOpaquePtr());
4329
645
    ID.AddInteger((unsigned)UKind);
4330
645
  }
4331
};
4332
4333
class TagType : public Type {
4334
  friend class ASTReader;
4335
4336
  /// Stores the TagDecl associated with this type. The decl may point to any
4337
  /// TagDecl that declares the entity.
4338
  TagDecl *decl;
4339
4340
protected:
4341
  TagType(TypeClass TC, const TagDecl *D, QualType can);
4342
4343
public:
4344
  TagDecl *getDecl() const;
4345
4346
  /// Determines whether this type is in the process of being defined.
4347
  bool isBeingDefined() const;
4348
4349
190M
  static bool classof(const Type *T) {
4350
190M
    return T->getTypeClass() >= TagFirst && 
T->getTypeClass() <= TagLast56.6M
;
4351
190M
  }
4352
};
4353
4354
/// A helper class that allows the use of isa/cast/dyncast
4355
/// to detect TagType objects of structs/unions/classes.
4356
class RecordType : public TagType {
4357
protected:
4358
  friend class ASTContext; // ASTContext creates these.
4359
4360
  explicit RecordType(const RecordDecl *D)
4361
2.09M
      : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4362
  explicit RecordType(TypeClass TC, RecordDecl *D)
4363
      : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4364
4365
public:
4366
63.0M
  RecordDecl *getDecl() const {
4367
63.0M
    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
4368
63.0M
  }
4369
4370
  /// Recursively check all fields in the record for const-ness. If any field
4371
  /// is declared const, return true. Otherwise, return false.
4372
  bool hasConstFields() const;
4373
4374
21.7M
  bool isSugared() const { return false; }
4375
0
  QualType desugar() const { return QualType(this, 0); }
4376
4377
239M
  static bool classof(const Type *T) { return T->getTypeClass() == Record; }
4378
};
4379
4380
/// A helper class that allows the use of isa/cast/dyncast
4381
/// to detect TagType objects of enums.
4382
class EnumType : public TagType {
4383
  friend class ASTContext; // ASTContext creates these.
4384
4385
  explicit EnumType(const EnumDecl *D)
4386
52.6k
      : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4387
4388
public:
4389
133M
  EnumDecl *getDecl() const {
4390
133M
    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
4391
133M
  }
4392
4393
4.06M
  bool isSugared() const { return false; }
4394
0
  QualType desugar() const { return QualType(this, 0); }
4395
4396
175M
  static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
4397
};
4398
4399
/// An attributed type is a type to which a type attribute has been applied.
4400
///
4401
/// The "modified type" is the fully-sugared type to which the attributed
4402
/// type was applied; generally it is not canonically equivalent to the
4403
/// attributed type. The "equivalent type" is the minimally-desugared type
4404
/// which the type is canonically equivalent to.
4405
///
4406
/// For example, in the following attributed type:
4407
///     int32_t __attribute__((vector_size(16)))
4408
///   - the modified type is the TypedefType for int32_t
4409
///   - the equivalent type is VectorType(16, int32_t)
4410
///   - the canonical type is VectorType(16, int)
4411
class AttributedType : public Type, public llvm::FoldingSetNode {
4412
public:
4413
  using Kind = attr::Kind;
4414
4415
private:
4416
  friend class ASTContext; // ASTContext creates these
4417
4418
  QualType ModifiedType;
4419
  QualType EquivalentType;
4420
4421
  AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
4422
                 QualType equivalent)
4423
      : Type(Attributed, canon, equivalent->isDependentType(),
4424
             equivalent->isInstantiationDependentType(),
4425
             equivalent->isVariablyModifiedType(),
4426
             equivalent->containsUnexpandedParameterPack()),
4427
63.7k
        ModifiedType(modified), EquivalentType(equivalent) {
4428
63.7k
    AttributedTypeBits.AttrKind = attrKind;
4429
63.7k
  }
4430
4431
public:
4432
409k
  Kind getAttrKind() const {
4433
409k
    return static_cast<Kind>(AttributedTypeBits.AttrKind);
4434
409k
  }
4435
4436
1.22M
  QualType getModifiedType() const { return ModifiedType; }
4437
381k
  QualType getEquivalentType() const { return EquivalentType; }
4438
4439
371k
  bool isSugared() const { return true; }
4440
372k
  QualType desugar() const { return getEquivalentType(); }
4441
4442
  /// Does this attribute behave like a type qualifier?
4443
  ///
4444
  /// A type qualifier adjusts a type to provide specialized rules for
4445
  /// a specific object, like the standard const and volatile qualifiers.
4446
  /// This includes attributes controlling things like nullability,
4447
  /// address spaces, and ARC ownership.  The value of the object is still
4448
  /// largely described by the modified type.
4449
  ///
4450
  /// In contrast, many type attributes "rewrite" their modified type to
4451
  /// produce a fundamentally different type, not necessarily related in any
4452
  /// formalizable way to the original type.  For example, calling convention
4453
  /// and vector attributes are not simple type qualifiers.
4454
  ///
4455
  /// Type qualifiers are often, but not always, reflected in the canonical
4456
  /// type.
4457
  bool isQualifier() const;
4458
4459
  bool isMSTypeSpec() const;
4460
4461
  bool isCallingConv() const;
4462
4463
  llvm::Optional<NullabilityKind> getImmediateNullability() const;
4464
4465
  /// Retrieve the attribute kind corresponding to the given
4466
  /// nullability kind.
4467
1.68k
  static Kind getNullabilityAttrKind(NullabilityKind kind) {
4468
1.68k
    switch (kind) {
4469
1.68k
    case NullabilityKind::NonNull:
4470
1.06k
      return attr::TypeNonNull;
4471
1.68k
4472
1.68k
    case NullabilityKind::Nullable:
4473
618
      return attr::TypeNullable;
4474
1.68k
4475
1.68k
    case NullabilityKind::Unspecified:
4476
7
      return attr::TypeNullUnspecified;
4477
0
    }
4478
0
    llvm_unreachable("Unknown nullability kind.");
4479
0
  }
4480
4481
  /// Strip off the top-level nullability annotation on the given
4482
  /// type, if it's there.
4483
  ///
4484
  /// \param T The type to strip. If the type is exactly an
4485
  /// AttributedType specifying nullability (without looking through
4486
  /// type sugar), the nullability is returned and this type changed
4487
  /// to the underlying modified type.
4488
  ///
4489
  /// \returns the top-level nullability, if present.
4490
  static Optional<NullabilityKind> stripOuterNullability(QualType &T);
4491
4492
304k
  void Profile(llvm::FoldingSetNodeID &ID) {
4493
304k
    Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
4494
304k
  }
4495
4496
  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
4497
567k
                      QualType modified, QualType equivalent) {
4498
567k
    ID.AddInteger(attrKind);
4499
567k
    ID.AddPointer(modified.getAsOpaquePtr());
4500
567k
    ID.AddPointer(equivalent.getAsOpaquePtr());
4501
567k
  }
4502
4503
72.3M
  static bool classof(const Type *T) {
4504
72.3M
    return T->getTypeClass() == Attributed;
4505
72.3M
  }
4506
};
4507
4508
class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
4509
  friend class ASTContext; // ASTContext creates these
4510
4511
  // Helper data collector for canonical types.
4512
  struct CanonicalTTPTInfo {
4513
    unsigned Depth : 15;
4514
    unsigned ParameterPack : 1;
4515
    unsigned Index : 16;
4516
  };
4517
4518
  union {
4519
    // Info for the canonical type.
4520
    CanonicalTTPTInfo CanTTPTInfo;
4521
4522
    // Info for the non-canonical type.
4523
    TemplateTypeParmDecl *TTPDecl;
4524
  };
4525
4526
  /// Build a non-canonical type.
4527
  TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon)
4528
      : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
4529
             /*InstantiationDependent=*/true,
4530
             /*VariablyModified=*/false,
4531
             Canon->containsUnexpandedParameterPack()),
4532
2.36M
        TTPDecl(TTPDecl) {}
4533
4534
  /// Build the canonical type.
4535
  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
4536
      : Type(TemplateTypeParm, QualType(this, 0),
4537
             /*Dependent=*/true,
4538
             /*InstantiationDependent=*/true,
4539
31.1k
             /*VariablyModified=*/false, PP) {
4540
31.1k
    CanTTPTInfo.Depth = D;
4541
31.1k
    CanTTPTInfo.Index = I;
4542
31.1k
    CanTTPTInfo.ParameterPack = PP;
4543
31.1k
  }
4544
4545
110M
  const CanonicalTTPTInfo& getCanTTPTInfo() const {
4546
110M
    QualType Can = getCanonicalTypeInternal();
4547
110M
    return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
4548
110M
  }
4549
4550
public:
4551
35.9M
  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
4552
28.9M
  unsigned getIndex() const { return getCanTTPTInfo().Index; }
4553
45.6M
  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
4554
4555
14.8M
  TemplateTypeParmDecl *getDecl() const {
4556
14.8M
    return isCanonicalUnqualified() ? 
nullptr2.45M
:
TTPDecl12.4M
;
4557
14.8M
  }
4558
4559
  IdentifierInfo *getIdentifier() const;
4560
4561
1.22M
  bool isSugared() const { return false; }
4562
0
  QualType desugar() const { return QualType(this, 0); }
4563
4564
14.1M
  void Profile(llvm::FoldingSetNodeID &ID) {
4565
14.1M
    Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
4566
14.1M
  }
4567
4568
  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
4569
                      unsigned Index, bool ParameterPack,
4570
19.4M
                      TemplateTypeParmDecl *TTPDecl) {
4571
19.4M
    ID.AddInteger(Depth);
4572
19.4M
    ID.AddInteger(Index);
4573
19.4M
    ID.AddBoolean(ParameterPack);
4574
19.4M
    ID.AddPointer(TTPDecl);
4575
19.4M
  }
4576
4577
33.8M
  static bool classof(const Type *T) {
4578
33.8M
    return T->getTypeClass() == TemplateTypeParm;
4579
33.8M
  }
4580
};
4581
4582
/// Represents the result of substituting a type for a template
4583
/// type parameter.
4584
///
4585
/// Within an instantiated template, all template type parameters have
4586
/// been replaced with these.  They are used solely to record that a
4587
/// type was originally written as a template type parameter;
4588
/// therefore they are never canonical.
4589
class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
4590
  friend class ASTContext;
4591
4592
  // The original type parameter.
4593
  const TemplateTypeParmType *Replaced;
4594
4595
  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
4596
      : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
4597
             Canon->isInstantiationDependentType(),
4598
             Canon->isVariablyModifiedType(),
4599
             Canon->containsUnexpandedParameterPack()),
4600
1.51M
        Replaced(Param) {}
4601
4602
public:
4603
  /// Gets the template parameter that was substituted for.
4604
7.36M
  const TemplateTypeParmType *getReplacedParameter() const {
4605
7.36M
    return Replaced;
4606
7.36M
  }
4607
4608
  /// Gets the type that was substituted for the template
4609
  /// parameter.
4610
11.5M
  QualType getReplacementType() const {
4611
11.5M
    return getCanonicalTypeInternal();
4612
11.5M
  }
4613
4614
3.74M
  bool isSugared() const { return true; }
4615
3.74M
  QualType desugar() const { return getReplacementType(); }
4616
4617
7.35M
  void Profile(llvm::FoldingSetNodeID &ID) {
4618
7.35M
    Profile(ID, getReplacedParameter(), getReplacementType());
4619
7.35M
  }
4620
4621
  static void Profile(llvm::FoldingSetNodeID &ID,
4622
                      const TemplateTypeParmType *Replaced,
4623
11.7M
                      QualType Replacement) {
4624
11.7M
    ID.AddPointer(Replaced);
4625
11.7M
    ID.AddPointer(Replacement.getAsOpaquePtr());
4626
11.7M
  }
4627
4628
1.42M
  static bool classof(const Type *T) {
4629
1.42M
    return T->getTypeClass() == SubstTemplateTypeParm;
4630
1.42M
  }
4631
};
4632
4633
/// Represents the result of substituting a set of types for a template
4634
/// type parameter pack.
4635
///
4636
/// When a pack expansion in the source code contains multiple parameter packs
4637
/// and those parameter packs correspond to different levels of template
4638
/// parameter lists, this type node is used to represent a template type
4639
/// parameter pack from an outer level, which has already had its argument pack
4640
/// substituted but that still lives within a pack expansion that itself
4641
/// could not be instantiated. When actually performing a substitution into
4642
/// that pack expansion (e.g., when all template parameters have corresponding
4643
/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
4644
/// at the current pack substitution index.
4645
class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
4646
  friend class ASTContext;
4647
4648
  /// The original type parameter.
4649
  const TemplateTypeParmType *Replaced;
4650
4651
  /// A pointer to the set of template arguments that this
4652
  /// parameter pack is instantiated with.
4653
  const TemplateArgument *Arguments;
4654
4655
  SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
4656
                                QualType Canon,
4657
                                const TemplateArgument &ArgPack);
4658
4659
public:
4660
0
  IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
4661
4662
  /// Gets the template parameter that was substituted for.
4663
26.9k
  const TemplateTypeParmType *getReplacedParameter() const {
4664
26.9k
    return Replaced;
4665
26.9k
  }
4666
4667
46.8k
  unsigned getNumArgs() const {
4668
46.8k
    return SubstTemplateTypeParmPackTypeBits.NumArgs;
4669
46.8k
  }
4670
4671
11
  bool isSugared() const { return false; }
4672
0
  QualType desugar() const { return QualType(this, 0); }
4673
4674
  TemplateArgument getArgumentPack() const;
4675
4676
  void Profile(llvm::FoldingSetNodeID &ID);
4677
  static void Profile(llvm::FoldingSetNodeID &ID,
4678
                      const TemplateTypeParmType *Replaced,
4679
                      const TemplateArgument &ArgPack);
4680
4681
2.37M
  static bool classof(const Type *T) {
4682
2.37M
    return T->getTypeClass() == SubstTemplateTypeParmPack;
4683
2.37M
  }
4684
};
4685
4686
/// Common base class for placeholders for types that get replaced by
4687
/// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
4688
/// class template types, and (eventually) constrained type names from the C++
4689
/// Concepts TS.
4690
///
4691
/// These types are usually a placeholder for a deduced type. However, before
4692
/// the initializer is attached, or (usually) if the initializer is
4693
/// type-dependent, there is no deduced type and the type is canonical. In
4694
/// the latter case, it is also a dependent type.
4695
class DeducedType : public Type {
4696
protected:
4697
  DeducedType(TypeClass TC, QualType DeducedAsType, bool IsDependent,
4698
              bool IsInstantiationDependent, bool ContainsParameterPack)
4699
      : Type(TC,
4700
             // FIXME: Retain the sugared deduced type?
4701
             DeducedAsType.isNull() ? QualType(this, 0)
4702
                                    : DeducedAsType.getCanonicalType(),
4703
             IsDependent, IsInstantiationDependent,
4704
16.0k
             /*VariablyModified=*/false, ContainsParameterPack) {
4705
16.0k
    if (!DeducedAsType.isNull()) {
4706
11.4k
      if (DeducedAsType->isDependentType())
4707
34
        setDependent();
4708
11.4k
      if (DeducedAsType->isInstantiationDependentType())
4709
34
        setInstantiationDependent();
4710
11.4k
      if (DeducedAsType->containsUnexpandedParameterPack())
4711
0
        setContainsUnexpandedParameterPack();
4712
11.4k
    }
4713
16.0k
  }
4714
4715
public:
4716
152k
  bool isSugared() const { return !isCanonicalUnqualified(); }
4717
152k
  QualType desugar() const { return getCanonicalTypeInternal(); }
4718
4719
  /// Get the type deduced for this placeholder type, or null if it's
4720
  /// either not been deduced or was deduced to a dependent type.
4721
31.3k
  QualType getDeducedType() const {
4722
31.3k
    return !isCanonicalUnqualified() ? 
getCanonicalTypeInternal()19.8k
:
QualType()11.5k
;
4723
31.3k
  }
4724
64.5k
  bool isDeduced() const {
4725
64.5k
    return !isCanonicalUnqualified() || 
isDependentType()43.1k
;
4726
64.5k
  }
4727
4728
58.2M
  static bool classof(const Type *T) {
4729
58.2M
    return T->getTypeClass() == Auto ||
4730
58.2M
           
T->getTypeClass() == DeducedTemplateSpecialization58.2M
;
4731
58.2M
  }
4732
};
4733
4734
/// Represents a C++11 auto or C++14 decltype(auto) type.
4735
class AutoType : public DeducedType, public llvm::FoldingSetNode {
4736
  friend class ASTContext; // ASTContext creates these
4737
4738
  AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
4739
           bool IsDeducedAsDependent)
4740
      : DeducedType(Auto, DeducedAsType, IsDeducedAsDependent,
4741
15.7k
                    IsDeducedAsDependent, /*ContainsPack=*/false) {
4742
15.7k
    AutoTypeBits.Keyword = (unsigned)Keyword;
4743
15.7k
  }
4744
4745
public:
4746
45.8k
  bool isDecltypeAuto() const {
4747
45.8k
    return getKeyword() == AutoTypeKeyword::DecltypeAuto;
4748
45.8k
  }
4749
4750
142k
  AutoTypeKeyword getKeyword() const {
4751
142k
    return (AutoTypeKeyword)AutoTypeBits.Keyword;
4752
142k
  }
4753
4754
16.7k
  void Profile(llvm::FoldingSetNodeID &ID) {
4755
16.7k
    Profile(ID, getDeducedType(), getKeyword(), isDependentType());
4756
16.7k
  }
4757
4758
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Deduced,
4759
41.8k
                      AutoTypeKeyword Keyword, bool IsDependent) {
4760
41.8k
    ID.AddPointer(Deduced.getAsOpaquePtr());
4761
41.8k
    ID.AddInteger((unsigned)Keyword);
4762
41.8k
    ID.AddBoolean(IsDependent);
4763
41.8k
  }
4764
4765
4.13M
  static bool classof(const Type *T) {
4766
4.13M
    return T->getTypeClass() == Auto;
4767
4.13M
  }
4768
};
4769
4770
/// Represents a C++17 deduced template specialization type.
4771
class DeducedTemplateSpecializationType : public DeducedType,
4772
                                          public llvm::FoldingSetNode {
4773
  friend class ASTContext; // ASTContext creates these
4774
4775
  /// The name of the template whose arguments will be deduced.
4776
  TemplateName Template;
4777
4778
  DeducedTemplateSpecializationType(TemplateName Template,
4779
                                    QualType DeducedAsType,
4780
                                    bool IsDeducedAsDependent)
4781
      : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
4782
                    IsDeducedAsDependent || Template.isDependent(),
4783
                    IsDeducedAsDependent || Template.isInstantiationDependent(),
4784
                    Template.containsUnexpandedParameterPack()),
4785
296
        Template(Template) {}
4786
4787
public:
4788
  /// Retrieve the name of the template that we are deducing.
4789
1.59k
  TemplateName getTemplateName() const { return Template;}
4790
4791
966
  void Profile(llvm::FoldingSetNodeID &ID) {
4792
966
    Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
4793
966
  }
4794
4795
  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
4796
1.62k
                      QualType Deduced, bool IsDependent) {
4797
1.62k
    Template.Profile(ID);
4798
1.62k
    ID.AddPointer(Deduced.getAsOpaquePtr());
4799
1.62k
    ID.AddBoolean(IsDependent);
4800
1.62k
  }
4801
4802
49.9k
  static bool classof(const Type *T) {
4803
49.9k
    return T->getTypeClass() == DeducedTemplateSpecialization;
4804
49.9k
  }
4805
};
4806
4807
/// Represents a type template specialization; the template
4808
/// must be a class template, a type alias template, or a template
4809
/// template parameter.  A template which cannot be resolved to one of
4810
/// these, e.g. because it is written with a dependent scope
4811
/// specifier, is instead represented as a
4812
/// @c DependentTemplateSpecializationType.
4813
///
4814
/// A non-dependent template specialization type is always "sugar",
4815
/// typically for a \c RecordType.  For example, a class template
4816
/// specialization type of \c vector<int> will refer to a tag type for
4817
/// the instantiation \c std::vector<int, std::allocator<int>>
4818
///
4819
/// Template specializations are dependent if either the template or
4820
/// any of the template arguments are dependent, in which case the
4821
/// type may also be canonical.
4822
///
4823
/// Instances of this type are allocated with a trailing array of
4824
/// TemplateArguments, followed by a QualType representing the
4825
/// non-canonical aliased type when the template is a type alias
4826
/// template.
4827
class alignas(8) TemplateSpecializationType
4828
    : public Type,
4829
      public llvm::FoldingSetNode {
4830
  friend class ASTContext; // ASTContext creates these
4831
4832
  /// The name of the template being specialized.  This is
4833
  /// either a TemplateName::Template (in which case it is a
4834
  /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
4835
  /// TypeAliasTemplateDecl*), a
4836
  /// TemplateName::SubstTemplateTemplateParmPack, or a
4837
  /// TemplateName::SubstTemplateTemplateParm (in which case the
4838
  /// replacement must, recursively, be one of these).
4839
  TemplateName Template;
4840
4841
  TemplateSpecializationType(TemplateName T,
4842
                             ArrayRef<TemplateArgument> Args,
4843
                             QualType Canon,
4844
                             QualType Aliased);
4845
4846
public:
4847
  /// Determine whether any of the given template arguments are dependent.
4848
  static bool anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
4849
                                            bool &InstantiationDependent);
4850
4851
  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
4852
                                            bool &InstantiationDependent);
4853
4854
  /// True if this template specialization type matches a current
4855
  /// instantiation in the context in which it is found.
4856
1.11M
  bool isCurrentInstantiation() const {
4857
1.11M
    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
4858
1.11M
  }
4859
4860
  /// Determine if this template specialization type is for a type alias
4861
  /// template that has been substituted.
4862
  ///
4863
  /// Nearly every template specialization type whose template is an alias
4864
  /// template will be substituted. However, this is not the case when
4865
  /// the specialization contains a pack expansion but the template alias
4866
  /// does not have a corresponding parameter pack, e.g.,
4867
  ///
4868
  /// \code
4869
  /// template<typename T, typename U, typename V> struct S;
4870
  /// template<typename T, typename U> using A = S<T, int, U>;
4871
  /// template<typename... Ts> struct X {
4872
  ///   typedef A<Ts...> type; // not a type alias
4873
  /// };
4874
  /// \endcode
4875
20.5M
  bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
4876
4877
  /// Get the aliased type, if this is a specialization of a type alias
4878
  /// template.
4879
119k
  QualType getAliasedType() const {
4880
119k
    assert(isTypeAlias() && "not a type alias template specialization");
4881
119k
    return *reinterpret_cast<const QualType*>(end());
4882
119k
  }
4883
4884
  using iterator = const TemplateArgument *;
4885
4886
10.1k
  iterator begin() const { return getArgs(); }
4887
  iterator end() const; // defined inline in TemplateBase.h
4888
4889
  /// Retrieve the name of the template that we are specializing.
4890
8.79M
  TemplateName getTemplateName() const { return Template; }
4891
4892
  /// Retrieve the template arguments.
4893
16.8M
  const TemplateArgument *getArgs() const {
4894
16.8M
    return reinterpret_cast<const TemplateArgument *>(this + 1);
4895
16.8M
  }
4896
4897
  /// Retrieve the number of template arguments.
4898
24.4M
  unsigned getNumArgs() const {
4899
24.4M
    return TemplateSpecializationTypeBits.NumArgs;
4900
24.4M
  }
4901
4902
  /// Retrieve a specific template argument as a type.
4903
  /// \pre \c isArgType(Arg)
4904
  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
4905
4906
8.72M
  ArrayRef<TemplateArgument> template_arguments() const {
4907
8.72M
    return {getArgs(), getNumArgs()};
4908
8.72M
  }
4909
4910
6.88M
  bool isSugared() const {
4911
6.88M
    return !isDependentType() || 
isCurrentInstantiation()1.11M
||
isTypeAlias()1.11M
;
4912
6.88M
  }
4913
4914
5.82M
  QualType desugar() const {
4915
5.82M
    return isTypeAlias() ? 
getAliasedType()119k
:
getCanonicalTypeInternal()5.70M
;
4916
5.82M
  }
4917
4918
6.22M
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
4919
6.22M
    Profile(ID, Template, template_arguments(), Ctx);
4920
6.22M
    if (isTypeAlias())
4921
0
      getAliasedType().Profile(ID);
4922
6.22M
  }
4923
4924
  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
4925
                      ArrayRef<TemplateArgument> Args,
4926
                      const ASTContext &Context);
4927
4928
7.40M
  static bool classof(const Type *T) {
4929
7.40M
    return T->getTypeClass() == TemplateSpecialization;
4930
7.40M
  }
4931
};
4932
4933
/// Print a template argument list, including the '<' and '>'
4934
/// enclosing the template arguments.
4935
void printTemplateArgumentList(raw_ostream &OS,
4936
                               ArrayRef<TemplateArgument> Args,
4937
                               const PrintingPolicy &Policy);
4938
4939
void printTemplateArgumentList(raw_ostream &OS,
4940
                               ArrayRef<TemplateArgumentLoc> Args,
4941
                               const PrintingPolicy &Policy);
4942
4943
void printTemplateArgumentList(raw_ostream &OS,
4944
                               const TemplateArgumentListInfo &Args,
4945
                               const PrintingPolicy &Policy);
4946
4947
/// The injected class name of a C++ class template or class
4948
/// template partial specialization.  Used to record that a type was
4949
/// spelled with a bare identifier rather than as a template-id; the
4950
/// equivalent for non-templated classes is just RecordType.
4951
///
4952
/// Injected class name types are always dependent.  Template
4953
/// instantiation turns these into RecordTypes.
4954
///
4955
/// Injected class name types are always canonical.  This works
4956
/// because it is impossible to compare an injected class name type
4957
/// with the corresponding non-injected template type, for the same
4958
/// reason that it is impossible to directly compare template
4959
/// parameters from different dependent contexts: injected class name
4960
/// types can only occur within the scope of a particular templated
4961
/// declaration, and within that scope every template specialization
4962
/// will canonicalize to the injected class name (when appropriate
4963
/// according to the rules of the language).
4964
class InjectedClassNameType : public Type {
4965
  friend class ASTContext; // ASTContext creates these.
4966
  friend class ASTNodeImporter;
4967
  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
4968
                          // currently suitable for AST reading, too much
4969
                          // interdependencies.
4970
4971
  CXXRecordDecl *Decl;
4972
4973
  /// The template specialization which this type represents.
4974
  /// For example, in
4975
  ///   template <class T> class A { ... };
4976
  /// this is A<T>, whereas in
4977
  ///   template <class X, class Y> class A<B<X,Y> > { ... };
4978
  /// this is A<B<X,Y> >.
4979
  ///
4980
  /// It is always unqualified, always a template specialization type,
4981
  /// and always dependent.
4982
  QualType InjectedType;
4983
4984
  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
4985
      : Type(InjectedClassName, QualType(), /*Dependent=*/true,
4986
             /*InstantiationDependent=*/true,
4987
             /*VariablyModified=*/false,
4988
             /*ContainsUnexpandedParameterPack=*/false),
4989
433k
        Decl(D), InjectedType(TST) {
4990
433k
    assert(isa<TemplateSpecializationType>(TST));
4991
433k
    assert(!TST.hasQualifiers());
4992
433k
    assert(TST->isDependentType());
4993
433k
  }
4994
4995
public:
4996
1.76M
  QualType getInjectedSpecializationType() const { return InjectedType; }
4997
4998
725
  const TemplateSpecializationType *getInjectedTST() const {
4999
725
    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
5000
725
  }
5001
5002
1
  TemplateName getTemplateName() const {
5003
1
    return getInjectedTST()->getTemplateName();
5004
1
  }
5005
5006
  CXXRecordDecl *getDecl() const;
5007
5008
51.6k
  bool isSugared() const { return false; }
5009
0
  QualType desugar() const { return QualType(this, 0); }
5010
5011
41.7M
  static bool classof(const Type *T) {
5012
41.7M
    return T->getTypeClass() == InjectedClassName;
5013
41.7M
  }
5014
};
5015
5016
/// The kind of a tag type.
5017
enum TagTypeKind {
5018
  /// The "struct" keyword.
5019
  TTK_Struct,
5020
5021
  /// The "__interface" keyword.
5022
  TTK_Interface,
5023
5024
  /// The "union" keyword.
5025
  TTK_Union,
5026
5027
  /// The "class" keyword.
5028
  TTK_Class,
5029
5030
  /// The "enum" keyword.
5031
  TTK_Enum
5032
};
5033
5034
/// The elaboration keyword that precedes a qualified type name or
5035
/// introduces an elaborated-type-specifier.
5036
enum ElaboratedTypeKeyword {
5037
  /// The "struct" keyword introduces the elaborated-type-specifier.
5038
  ETK_Struct,
5039
5040
  /// The "__interface" keyword introduces the elaborated-type-specifier.
5041
  ETK_Interface,
5042
5043
  /// The "union" keyword introduces the elaborated-type-specifier.
5044
  ETK_Union,
5045
5046
  /// The "class" keyword introduces the elaborated-type-specifier.
5047
  ETK_Class,
5048
5049
  /// The "enum" keyword introduces the elaborated-type-specifier.
5050
  ETK_Enum,
5051
5052
  /// The "typename" keyword precedes the qualified type name, e.g.,
5053
  /// \c typename T::type.
5054
  ETK_Typename,
5055
5056
  /// No keyword precedes the qualified type name.
5057
  ETK_None
5058
};
5059
5060
/// A helper class for Type nodes having an ElaboratedTypeKeyword.
5061
/// The keyword in stored in the free bits of the base class.
5062
/// Also provides a few static helpers for converting and printing
5063
/// elaborated type keyword and tag type kind enumerations.
5064
class TypeWithKeyword : public Type {
5065
protected:
5066
  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
5067
                  QualType Canonical, bool Dependent,
5068
                  bool InstantiationDependent, bool VariablyModified,
5069
                  bool ContainsUnexpandedParameterPack)
5070
      : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
5071
2.47M
             ContainsUnexpandedParameterPack) {
5072
2.47M
    TypeWithKeywordBits.Keyword = Keyword;
5073
2.47M
  }
5074
5075
public:
5076
10.7M
  ElaboratedTypeKeyword getKeyword() const {
5077
10.7M
    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
5078
10.7M
  }
5079
5080
  /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
5081
  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
5082
5083
  /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
5084
  /// It is an error to provide a type specifier which *isn't* a tag kind here.
5085
  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
5086
5087
  /// Converts a TagTypeKind into an elaborated type keyword.
5088
  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
5089
5090
  /// Converts an elaborated type keyword into a TagTypeKind.
5091
  /// It is an error to provide an elaborated type keyword
5092
  /// which *isn't* a tag kind here.
5093
  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
5094
5095
  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
5096
5097
  static StringRef getKeywordName(ElaboratedTypeKeyword Keyword);
5098
5099
142k
  static StringRef getTagTypeKindName(TagTypeKind Kind) {
5100
142k
    return getKeywordName(getKeywordForTagTypeKind(Kind));
5101
142k
  }
5102
5103
  class CannotCastToThisType {};
5104
  static CannotCastToThisType classof(const Type *);
5105
};
5106
5107
/// Represents a type that was referred to using an elaborated type
5108
/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
5109
/// or both.
5110
///
5111
/// This type is used to keep track of a type name as written in the
5112
/// source code, including tag keywords and any nested-name-specifiers.
5113
/// The type itself is always "sugar", used to express what was written
5114
/// in the source code but containing no additional semantic information.
5115
class ElaboratedType final
5116
    : public TypeWithKeyword,
5117
      public llvm::FoldingSetNode,
5118
      private llvm::TrailingObjects<ElaboratedType, TagDecl *> {
5119
  friend class ASTContext; // ASTContext creates these
5120
  friend TrailingObjects;
5121
5122
  /// The nested name specifier containing the qualifier.
5123
  NestedNameSpecifier *NNS;
5124
5125
  /// The type that this qualified name refers to.
5126
  QualType NamedType;
5127
5128
  /// The (re)declaration of this tag type owned by this occurrence is stored
5129
  /// as a trailing object if there is one. Use getOwnedTagDecl to obtain
5130
  /// it, or obtain a null pointer if there is none.
5131
5132
  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
5133
                 QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
5134
      : TypeWithKeyword(Keyword, Elaborated, CanonType,
5135
                        NamedType->isDependentType(),
5136
                        NamedType->isInstantiationDependentType(),
5137
                        NamedType->isVariablyModifiedType(),
5138
                        NamedType->containsUnexpandedParameterPack()),
5139
1.27M
        NNS(NNS), NamedType(NamedType) {
5140
1.27M
    ElaboratedTypeBits.HasOwnedTagDecl = false;
5141
1.27M
    if (OwnedTagDecl) {
5142
191k
      ElaboratedTypeBits.HasOwnedTagDecl = true;
5143
191k
      *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
5144
191k
    }
5145
1.27M
    assert(!(Keyword == ETK_None && NNS == nullptr) &&
5146
1.27M
           "ElaboratedType cannot have elaborated type keyword "
5147
1.27M
           "and name qualifier both null.");
5148
1.27M
  }
5149
5150
public:
5151
  /// Retrieve the qualification on this type.
5152
1.56M
  NestedNameSpecifier *getQualifier() const { return NNS; }
5153
5154
  /// Retrieve the type named by the qualified-id.
5155
19.0M
  QualType getNamedType() const { return NamedType; }
5156
5157
  /// Remove a single level of sugar.
5158
8.58M
  QualType desugar() const { return getNamedType(); }
5159
5160
  /// Returns whether this type directly provides sugar.
5161
8.57M
  bool isSugared() const { return true; }
5162
5163
  /// Return the (re)declaration of this type owned by this occurrence of this
5164
  /// type, or nullptr if there is none.
5165
5.06M
  TagDecl *getOwnedTagDecl() const {
5166
5.06M
    return ElaboratedTypeBits.HasOwnedTagDecl ? 
*getTrailingObjects<TagDecl *>()337k
5167
5.06M
                                              : 
nullptr4.72M
;
5168
5.06M
  }
5169
5170
5.06M
  void Profile(llvm::FoldingSetNodeID &ID) {
5171
5.06M
    Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl());
5172
5.06M
  }
5173
5174
  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
5175
                      NestedNameSpecifier *NNS, QualType NamedType,
5176
7.12M
                      TagDecl *OwnedTagDecl) {
5177
7.12M
    ID.AddInteger(Keyword);
5178
7.12M
    ID.AddPointer(NNS);
5179
7.12M
    NamedType.Profile(ID);
5180
7.12M
    ID.AddPointer(OwnedTagDecl);
5181
7.12M
  }
5182
5183
9.51M
  static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
5184
};
5185
5186
/// Represents a qualified type name for which the type name is
5187
/// dependent.
5188
///
5189
/// DependentNameType represents a class of dependent types that involve a
5190
/// possibly dependent nested-name-specifier (e.g., "T::") followed by a
5191
/// name of a type. The DependentNameType may start with a "typename" (for a
5192
/// typename-specifier), "class", "struct", "union", or "enum" (for a
5193
/// dependent elaborated-type-specifier), or nothing (in contexts where we
5194
/// know that we must be referring to a type, e.g., in a base class specifier).
5195
/// Typically the nested-name-specifier is dependent, but in MSVC compatibility
5196
/// mode, this type is used with non-dependent names to delay name lookup until
5197
/// instantiation.
5198
class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
5199
  friend class ASTContext; // ASTContext creates these
5200
5201
  /// The nested name specifier containing the qualifier.
5202
  NestedNameSpecifier *NNS;
5203
5204
  /// The type that this typename specifier refers to.
5205
  const IdentifierInfo *Name;
5206
5207
  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
5208
                    const IdentifierInfo *Name, QualType CanonType)
5209
      : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
5210
                        /*InstantiationDependent=*/true,
5211
                        /*VariablyModified=*/false,
5212
                        NNS->containsUnexpandedParameterPack()),
5213
1.18M
        NNS(NNS), Name(Name) {}
5214
5215
public:
5216
  /// Retrieve the qualification on this type.
5217
2.13M
  NestedNameSpecifier *getQualifier() const { return NNS; }
5218
5219
  /// Retrieve the type named by the typename specifier as an identifier.
5220
  ///
5221
  /// This routine will return a non-NULL identifier pointer when the
5222
  /// form of the original typename was terminated by an identifier,
5223
  /// e.g., "typename T::type".
5224
1.43M
  const IdentifierInfo *getIdentifier() const {
5225
1.43M
    return Name;
5226
1.43M
  }
5227
5228
216k
  bool isSugared() const { return false; }
5229
0
  QualType desugar() const { return QualType(this, 0); }
5230
5231
4.13M
  void Profile(llvm::FoldingSetNodeID &ID) {
5232
4.13M
    Profile(ID, getKeyword(), NNS, Name);
5233
4.13M
  }
5234
5235
  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
5236
6.06M
                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
5237
6.06M
    ID.AddInteger(Keyword);
5238
6.06M
    ID.AddPointer(NNS);
5239
6.06M
    ID.AddPointer(Name);
5240
6.06M
  }
5241
5242
8.97M
  static bool classof(const Type *T) {
5243
8.97M
    return T->getTypeClass() == DependentName;
5244
8.97M
  }
5245
};
5246
5247
/// Represents a template specialization type whose template cannot be
5248
/// resolved, e.g.
5249
///   A<T>::template B<T>
5250
class alignas(8) DependentTemplateSpecializationType
5251
    : public TypeWithKeyword,
5252
      public llvm::FoldingSetNode {
5253
  friend class ASTContext; // ASTContext creates these
5254
5255
  /// The nested name specifier containing the qualifier.
5256
  NestedNameSpecifier *NNS;
5257
5258
  /// The identifier of the template.
5259
  const IdentifierInfo *Name;
5260
5261
  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
5262
                                      NestedNameSpecifier *NNS,
5263
                                      const IdentifierInfo *Name,
5264
                                      ArrayRef<TemplateArgument> Args,
5265
                                      QualType Canon);
5266
5267
33.2k
  const TemplateArgument *getArgBuffer() const {
5268
33.2k
    return reinterpret_cast<const TemplateArgument*>(this+1);
5269
33.2k
  }
5270
5271
13.8k
  TemplateArgument *getArgBuffer() {
5272
13.8k
    return reinterpret_cast<TemplateArgument*>(this+1);
5273
13.8k
  }
5274
5275
public:
5276
61.3k
  NestedNameSpecifier *getQualifier() const { return NNS; }
5277
19.2k
  const IdentifierInfo *getIdentifier() const { return Name; }
5278
5279
  /// Retrieve the template arguments.
5280
33.2k
  const TemplateArgument *getArgs() const {
5281
33.2k
    return getArgBuffer();
5282
33.2k
  }
5283
5284
  /// Retrieve the number of template arguments.
5285
69.3k
  unsigned getNumArgs() const {
5286
69.3k
    return DependentTemplateSpecializationTypeBits.NumArgs;
5287
69.3k
  }
5288
5289
  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
5290
5291
28
  ArrayRef<TemplateArgument> template_arguments() const {
5292
28
    return {getArgs(), getNumArgs()};
5293
28
  }
5294
5295
  using iterator = const TemplateArgument *;
5296
5297
7
  iterator begin() const { return getArgs(); }
5298
  iterator end() const; // inline in TemplateBase.h
5299
5300
143
  bool isSugared() const { return false; }
5301
0
  QualType desugar() const { return QualType(this, 0); }
5302
5303
11.8k
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5304
11.8k
    Profile(ID, Context, getKeyword(), NNS, Name, {getArgs(), getNumArgs()});
5305
11.8k
  }
5306
5307
  static void Profile(llvm::FoldingSetNodeID &ID,
5308
                      const ASTContext &Context,
5309
                      ElaboratedTypeKeyword Keyword,
5310
                      NestedNameSpecifier *Qualifier,
5311
                      const IdentifierInfo *Name,
5312
                      ArrayRef<TemplateArgument> Args);
5313
5314
3.93M
  static bool classof(const Type *T) {
5315
3.93M
    return T->getTypeClass() == DependentTemplateSpecialization;
5316
3.93M
  }
5317
};
5318
5319
/// Represents a pack expansion of types.
5320
///
5321
/// Pack expansions are part of C++11 variadic templates. A pack
5322
/// expansion contains a pattern, which itself contains one or more
5323
/// "unexpanded" parameter packs. When instantiated, a pack expansion
5324
/// produces a series of types, each instantiated from the pattern of
5325
/// the expansion, where the Ith instantiation of the pattern uses the
5326
/// Ith arguments bound to each of the unexpanded parameter packs. The
5327
/// pack expansion is considered to "expand" these unexpanded
5328
/// parameter packs.
5329
///
5330
/// \code
5331
/// template<typename ...Types> struct tuple;
5332
///
5333
/// template<typename ...Types>
5334
/// struct tuple_of_references {
5335
///   typedef tuple<Types&...> type;
5336
/// };
5337
/// \endcode
5338
///
5339
/// Here, the pack expansion \c Types&... is represented via a
5340
/// PackExpansionType whose pattern is Types&.
5341
class PackExpansionType : public Type, public llvm::FoldingSetNode {
5342
  friend class ASTContext; // ASTContext creates these
5343
5344
  /// The pattern of the pack expansion.
5345
  QualType Pattern;
5346
5347
  PackExpansionType(QualType Pattern, QualType Canon,
5348
                    Optional<unsigned> NumExpansions)
5349
      : Type(PackExpansion, Canon, /*Dependent=*/Pattern->isDependentType(),
5350
             /*InstantiationDependent=*/true,
5351
             /*VariablyModified=*/Pattern->isVariablyModifiedType(),
5352
             /*ContainsUnexpandedParameterPack=*/false),
5353
166k
        Pattern(Pattern) {
5354
166k
    PackExpansionTypeBits.NumExpansions =
5355
166k
        NumExpansions ? 
*NumExpansions + 168
:
0166k
;
5356
166k
  }
5357
5358
public:
5359
  /// Retrieve the pattern of this pack expansion, which is the
5360
  /// type that will be repeatedly instantiated when instantiating the
5361
  /// pack expansion itself.
5362
2.68M
  QualType getPattern() const { return Pattern; }
5363
5364
  /// Retrieve the number of expansions that this pack expansion will
5365
  /// generate, if known.
5366
1.09M
  Optional<unsigned> getNumExpansions() const {
5367
1.09M
    if (PackExpansionTypeBits.NumExpansions)
5368
110
      return PackExpansionTypeBits.NumExpansions - 1;
5369
1.09M
    return None;
5370
1.09M
  }
5371
5372
43.0k
  bool isSugared() const { return !Pattern->isDependentType(); }
5373
39
  QualType desugar() const { return isSugared() ? Pattern : 
QualType(this, 0)0
; }
5374
5375
916k
  void Profile(llvm::FoldingSetNodeID &ID) {
5376
916k
    Profile(ID, getPattern(), getNumExpansions());
5377
916k
  }
5378
5379
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
5380
1.31M
                      Optional<unsigned> NumExpansions) {
5381
1.31M
    ID.AddPointer(Pattern.getAsOpaquePtr());
5382
1.31M
    ID.AddBoolean(NumExpansions.hasValue());
5383
1.31M
    if (NumExpansions)
5384
157
      ID.AddInteger(*NumExpansions);
5385
1.31M
  }
5386
5387
103M
  static