Coverage Report

Created: 2018-07-19 20:53

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