Coverage Report

Created: 2022-07-16 07:03

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