Coverage Report

Created: 2019-07-24 05:18

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