Coverage Report

Created: 2020-02-25 14:32

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