Coverage Report

Created: 2022-05-17 06:19

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