Coverage Report

Created: 2021-09-21 08:58

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