Coverage Report

Created: 2019-02-23 12:57

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